diff --git a/drivers/staging/lirc/lirc_rpi.c b/drivers/staging/lirc/lirc_rpi.c index 1706663141d403..800de838e26e9b 100644 --- a/drivers/staging/lirc/lirc_rpi.c +++ b/drivers/staging/lirc/lirc_rpi.c @@ -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<to_irq(gpiochip,g) #ifndef MAX_UDELAY_MS @@ -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); @@ -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; @@ -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 */ @@ -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")) { @@ -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 */ @@ -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; @@ -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: @@ -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); @@ -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)); @@ -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"); }