Skip to content

Make gpio pullup configurable for lirc driver #665

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions arch/arm/mach-bcm2708/bcm2708_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <linux/spinlock.h>
#include <linux/module.h>
#include <linux/delay.h>
#include <linux/list.h>
#include <linux/io.h>
#include <linux/irq.h>
Expand All @@ -21,6 +22,8 @@
#include <linux/platform_device.h>
#include <mach/platform.h>

#include <linux/platform_data/bcm2708.h>

#define BCM_GPIO_DRIVER_NAME "bcm2708_gpio"
#define DRIVER_NAME BCM_GPIO_DRIVER_NAME
#define BCM_GPIO_USE_IRQ 1
Expand Down Expand Up @@ -131,6 +134,41 @@ static void bcm2708_gpio_set(struct gpio_chip *gc, unsigned offset, int value)
writel(1 << gpio_field_offset, gpio->base + GPIOCLR(gpio_bank));
}

/**********************
* extension to configure pullups
*/
int bcm2708_gpio_setpull(struct gpio_chip *gc, unsigned offset,
bcm2708_gpio_pull_t value)
{
struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
unsigned gpio_bank = offset / 32;
unsigned gpio_field_offset = (offset - 32 * gpio_bank);

if (offset >= BCM2708_NR_GPIOS)
return -EINVAL;

switch (value) {
case BCM2708_PULL_UP:
writel(2, gpio->base + GPIOUD(0));
break;
case BCM2708_PULL_DOWN:
writel(1, gpio->base + GPIOUD(0));
break;
case BCM2708_PULL_OFF:
writel(0, gpio->base + GPIOUD(0));
break;
}

udelay(5);
writel(1 << gpio_field_offset, gpio->base + GPIOUDCLK(gpio_bank));
udelay(5);
writel(0, gpio->base + GPIOUD(0));
writel(0 << gpio_field_offset, gpio->base + GPIOUDCLK(gpio_bank));

return 0;
}
EXPORT_SYMBOL(bcm2708_gpio_setpull);

/*************************************************************************************************************************
* bcm2708 GPIO IRQ
*/
Expand Down
9 changes: 9 additions & 0 deletions drivers/staging/media/lirc/lirc_rpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
#include <media/lirc_dev.h>
#include <linux/gpio.h>

#include <linux/platform_data/bcm2708.h>

#define LIRC_DRIVER_NAME "lirc_rpi"
#define RBUF_LEN 256
#define LIRC_TRANSMITTER_LATENCY 50
Expand All @@ -61,6 +63,8 @@

/* set the default GPIO input pin */
static int gpio_in_pin = 18;
/* set the default pull behaviour for input pin */
static int gpio_in_pull = BCM2708_PULL_DOWN;
/* set the default GPIO output pin */
static int gpio_out_pin = 17;
/* enable debugging messages */
Expand Down Expand Up @@ -320,6 +324,7 @@ static int init_port(void)
goto exit_gpio_free_out_pin;
}

bcm2708_gpio_setpull(gpiochip, gpio_in_pin, gpio_in_pull);
gpiochip->direction_input(gpiochip, gpio_in_pin);
gpiochip->direction_output(gpiochip, gpio_out_pin, 1);
gpiochip->set(gpiochip, gpio_out_pin, invert);
Expand Down Expand Up @@ -681,6 +686,10 @@ MODULE_PARM_DESC(gpio_in_pin, "GPIO input pin number of the BCM processor."
" Valid pin numbers are: 0, 1, 4, 8, 7, 9, 10, 11, 14, 15,"
" 17, 18, 21, 22, 23, 24, 25, default 18");

module_param(gpio_in_pull, int, S_IRUGO);
MODULE_PARM_DESC(gpio_in_pull, "GPIO input pin pull configuration."
" (0 = off, 1 = up, 2 = down, default down)");

module_param(sense, int, S_IRUGO);
MODULE_PARM_DESC(sense, "Override autodetection of IR receiver circuit"
" (0 = active high, 1 = active low )");
Expand Down
23 changes: 23 additions & 0 deletions include/linux/platform_data/bcm2708.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* include/linux/platform_data/bcm2708.h
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* (C) 2014 Julian Scheel <[email protected]>
*
*/
#ifndef __BCM2708_H_
#define __BCM2708_H_

typedef enum {
BCM2708_PULL_OFF,
BCM2708_PULL_UP,
BCM2708_PULL_DOWN
} bcm2708_gpio_pull_t;

extern int bcm2708_gpio_setpull(struct gpio_chip *gc, unsigned offset,
bcm2708_gpio_pull_t value)

#endif