Skip to content

Commit

Permalink
purge all direct gpio access, the code is now purely libgpio based
Browse files Browse the repository at this point in the history
some of the mask/unmask parts im not sure of, ive marked them with comments
everything seems to work, it can RX and TX normaly
  • Loading branch information
cleverca22 committed Oct 27, 2012
1 parent 5a56f4d commit 02c4ee5
Showing 1 changed file with 25 additions and 41 deletions.
66 changes: 25 additions & 41 deletions drivers/staging/lirc/lirc_rpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@
/* clears bits which are 1 ignores bits which are 0 */
#define GPIO_CLEAR_PIN(g) gpiochip->set(gpiochip,g,0)
/* Clear GPIO interrupt on the pin we use */
#define GPIO_INT_CLEAR(g) *(gpio+16) = (*(gpio+16) | (1<<g));
/* GPREN0 GPIO Pin Rising Edge Detect Enable/Disable */
#define GPIO_INT_RISING(g,v) *(gpio+19) = v ? (*(gpio+19) | (1<<g)) : (*(gpio+19) ^ (1<<g))
/* GPFEN0 GPIO Pin Falling Edge Detect Enable/Disable */
#define GPIO_INT_FALLING(g,v) *(gpio+22) = v ? (*(gpio+22) | (1<<g)) : (*(gpio+22) ^ (1<<g))
#define GPIO_IRQ(g) gpiochip->to_irq(gpiochip,g)

#ifndef MAX_UDELAY_MS
Expand Down Expand Up @@ -101,6 +96,8 @@ static int sense = -1;
static int softcarrier = 1;

struct gpio_chip *gpiochip;
struct irq_chip *irqchip;
struct irq_data* irqdata;

/* forward declarations */
static long send_pulse(unsigned long length);
Expand All @@ -110,8 +107,6 @@ static void lirc_rpi_exit(void);
int valid_gpio_pins[] = { 0, 1, 4, 8, 7, 9, 10, 11, 14, 15, 17, 18, 21, 22, 23,
24, 25 };

volatile unsigned *gpio;

static struct platform_device *lirc_rpi_dev;
static struct timeval lasttv = {0, 0};
static struct lirc_buffer rbuf;
Expand Down Expand Up @@ -270,7 +265,8 @@ static irqreturn_t irq_handler(int i, void *blah, struct pt_regs *regs)
signal = GPIO_READ_PIN(gpio_in_pin);

/* reset interrupt */
GPIO_INT_CLEAR(gpio_in_pin);
// is this supposed to mask or unmask the irq?
irqchip->irq_unmask(irqdata);

if (sense != -1) {
/* get current time */
Expand Down Expand Up @@ -321,22 +317,8 @@ int is_right_chip(struct gpio_chip *chip, void *data) {
}
static int init_port(void)
{
int i, nlow, nhigh, ret;

/* reserve GPIO memory region. */
if (request_mem_region(GPIO_BASE, SZ_4K, LIRC_DRIVER_NAME) == NULL) {
printk(KERN_ERR LIRC_DRIVER_NAME
": unable to obtain GPIO I/O memory address\n");
return -EBUSY;
}
int i, nlow, nhigh, ret, irq;

/* remap the GPIO memory */
if ((gpio = ioremap_nocache(GPIO_BASE, SZ_4K)) == NULL) {
printk(KERN_ERR LIRC_DRIVER_NAME
": failed to map GPIO I/O memory\n");
ret = -EBUSY;
goto error1;
}
gpiochip = gpiochip_find("bcm2708_gpio",is_right_chip);
if (!gpiochip) return -ENODEV;
if (gpio_request(gpio_out_pin,"lirc_rpi")) {
Expand All @@ -356,6 +338,16 @@ static int init_port(void)
GPIO_DIR_OUTPUT(gpio_out_pin);
GPIO_CLEAR_PIN(gpio_out_pin);

irq = gpiochip->to_irq(gpiochip,gpio_in_pin);
printk(KERN_ALERT " to_irq %d\n",irq);
irqdata = irq_get_irq_data(irq);
if (irqdata && irqdata->chip) {
irqchip = irqdata->chip;
} else {
ret = -ENODEV;
goto error4;
}

/* if pin is high, then this must be an active low receiver. */
if (sense == -1) {
/* wait 1/2 sec for the power supply */
Expand Down Expand Up @@ -384,15 +376,15 @@ static int init_port(void)
sense ? "low" : "high", gpio_in_pin);
}
return 0;
error4:
gpio_free(gpio_in_pin);
error3:
gpio_free(gpio_out_pin);
error2:
iounmap(gpio);
error1:
release_mem_region(GPIO_BASE, SZ_4K);
return ret;
}

// called when the character device is opened
static int set_use_inc(void *data)
{
int result;
Expand All @@ -403,7 +395,7 @@ static int set_use_inc(void *data)

result = request_irq(GPIO_IRQ(gpio_in_pin), (irq_handler_t)
irq_handler, 0,
LIRC_DRIVER_NAME, (void*) gpio);
LIRC_DRIVER_NAME, (void*) 0);

switch (result) {
case -EBUSY:
Expand All @@ -426,13 +418,12 @@ static int set_use_inc(void *data)
spin_lock_irqsave(&lock, flags);

/* GPREN0 GPIO Pin Rising Edge Detect Enable */
GPIO_INT_RISING(gpio_in_pin, 1);

/* GPFEN0 GPIO Pin Falling Edge Detect Enable */
GPIO_INT_FALLING(gpio_in_pin, 1);
irqchip->irq_set_type(irqdata,IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING);

/* clear interrupt flag */
GPIO_INT_CLEAR(gpio_in_pin);
// is this supposed to mask or unmask the irq?
irqchip->irq_unmask(irqdata);

spin_unlock_irqrestore(&lock, flags);

Expand All @@ -446,14 +437,13 @@ static void set_use_dec(void *data)
spin_lock_irqsave(&lock, flags);

/* GPREN0 GPIO Pin Rising Edge Detect Disable */
GPIO_INT_RISING(gpio_in_pin, 0);

/* GPFEN0 GPIO Pin Falling Edge Detect Disable */
GPIO_INT_FALLING(gpio_in_pin, 0);
irqchip->irq_set_type(irqdata,0);
irqchip->irq_mask(irqdata);

spin_unlock_irqrestore(&lock, flags);

free_irq(GPIO_IRQ(gpio_in_pin), (void *) gpio);
free_irq(GPIO_IRQ(gpio_in_pin), (void *) 0);

dprintk(KERN_INFO LIRC_DRIVER_NAME
": freed IRQ %04x\n", GPIO_IRQ(gpio_in_pin));
Expand Down Expand Up @@ -679,12 +669,6 @@ static void __exit lirc_rpi_exit_module(void)
{
lirc_rpi_exit();

/* release mapped memory and allocated region */
if(gpio != NULL) {
iounmap(gpio);
release_mem_region(GPIO_BASE, SZ_4K);
}

lirc_unregister_driver(driver.minor);
printk(KERN_INFO LIRC_DRIVER_NAME ": cleaned up module\n");
}
Expand Down

0 comments on commit 02c4ee5

Please sign in to comment.