Skip to content

Commit 02c4ee5

Browse files
committed
purge all direct gpio access, the code is now purely libgpio based
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
1 parent 5a56f4d commit 02c4ee5

File tree

1 file changed

+25
-41
lines changed

1 file changed

+25
-41
lines changed

drivers/staging/lirc/lirc_rpi.c

Lines changed: 25 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,6 @@
6767
/* clears bits which are 1 ignores bits which are 0 */
6868
#define GPIO_CLEAR_PIN(g) gpiochip->set(gpiochip,g,0)
6969
/* Clear GPIO interrupt on the pin we use */
70-
#define GPIO_INT_CLEAR(g) *(gpio+16) = (*(gpio+16) | (1<<g));
71-
/* GPREN0 GPIO Pin Rising Edge Detect Enable/Disable */
72-
#define GPIO_INT_RISING(g,v) *(gpio+19) = v ? (*(gpio+19) | (1<<g)) : (*(gpio+19) ^ (1<<g))
73-
/* GPFEN0 GPIO Pin Falling Edge Detect Enable/Disable */
74-
#define GPIO_INT_FALLING(g,v) *(gpio+22) = v ? (*(gpio+22) | (1<<g)) : (*(gpio+22) ^ (1<<g))
7570
#define GPIO_IRQ(g) gpiochip->to_irq(gpiochip,g)
7671

7772
#ifndef MAX_UDELAY_MS
@@ -101,6 +96,8 @@ static int sense = -1;
10196
static int softcarrier = 1;
10297

10398
struct gpio_chip *gpiochip;
99+
struct irq_chip *irqchip;
100+
struct irq_data* irqdata;
104101

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

113-
volatile unsigned *gpio;
114-
115110
static struct platform_device *lirc_rpi_dev;
116111
static struct timeval lasttv = {0, 0};
117112
static struct lirc_buffer rbuf;
@@ -270,7 +265,8 @@ static irqreturn_t irq_handler(int i, void *blah, struct pt_regs *regs)
270265
signal = GPIO_READ_PIN(gpio_in_pin);
271266

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

275271
if (sense != -1) {
276272
/* get current time */
@@ -321,22 +317,8 @@ int is_right_chip(struct gpio_chip *chip, void *data) {
321317
}
322318
static int init_port(void)
323319
{
324-
int i, nlow, nhigh, ret;
325-
326-
/* reserve GPIO memory region. */
327-
if (request_mem_region(GPIO_BASE, SZ_4K, LIRC_DRIVER_NAME) == NULL) {
328-
printk(KERN_ERR LIRC_DRIVER_NAME
329-
": unable to obtain GPIO I/O memory address\n");
330-
return -EBUSY;
331-
}
320+
int i, nlow, nhigh, ret, irq;
332321

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

341+
irq = gpiochip->to_irq(gpiochip,gpio_in_pin);
342+
printk(KERN_ALERT " to_irq %d\n",irq);
343+
irqdata = irq_get_irq_data(irq);
344+
if (irqdata && irqdata->chip) {
345+
irqchip = irqdata->chip;
346+
} else {
347+
ret = -ENODEV;
348+
goto error4;
349+
}
350+
359351
/* if pin is high, then this must be an active low receiver. */
360352
if (sense == -1) {
361353
/* wait 1/2 sec for the power supply */
@@ -384,15 +376,15 @@ static int init_port(void)
384376
sense ? "low" : "high", gpio_in_pin);
385377
}
386378
return 0;
379+
error4:
380+
gpio_free(gpio_in_pin);
387381
error3:
388382
gpio_free(gpio_out_pin);
389383
error2:
390-
iounmap(gpio);
391-
error1:
392-
release_mem_region(GPIO_BASE, SZ_4K);
393384
return ret;
394385
}
395386

387+
// called when the character device is opened
396388
static int set_use_inc(void *data)
397389
{
398390
int result;
@@ -403,7 +395,7 @@ static int set_use_inc(void *data)
403395

404396
result = request_irq(GPIO_IRQ(gpio_in_pin), (irq_handler_t)
405397
irq_handler, 0,
406-
LIRC_DRIVER_NAME, (void*) gpio);
398+
LIRC_DRIVER_NAME, (void*) 0);
407399

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

428420
/* GPREN0 GPIO Pin Rising Edge Detect Enable */
429-
GPIO_INT_RISING(gpio_in_pin, 1);
430-
431421
/* GPFEN0 GPIO Pin Falling Edge Detect Enable */
432-
GPIO_INT_FALLING(gpio_in_pin, 1);
422+
irqchip->irq_set_type(irqdata,IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING);
433423

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

437428
spin_unlock_irqrestore(&lock, flags);
438429

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

448439
/* GPREN0 GPIO Pin Rising Edge Detect Disable */
449-
GPIO_INT_RISING(gpio_in_pin, 0);
450-
451440
/* GPFEN0 GPIO Pin Falling Edge Detect Disable */
452-
GPIO_INT_FALLING(gpio_in_pin, 0);
441+
irqchip->irq_set_type(irqdata,0);
442+
irqchip->irq_mask(irqdata);
453443

454444
spin_unlock_irqrestore(&lock, flags);
455445

456-
free_irq(GPIO_IRQ(gpio_in_pin), (void *) gpio);
446+
free_irq(GPIO_IRQ(gpio_in_pin), (void *) 0);
457447

458448
dprintk(KERN_INFO LIRC_DRIVER_NAME
459449
": freed IRQ %04x\n", GPIO_IRQ(gpio_in_pin));
@@ -679,12 +669,6 @@ static void __exit lirc_rpi_exit_module(void)
679669
{
680670
lirc_rpi_exit();
681671

682-
/* release mapped memory and allocated region */
683-
if(gpio != NULL) {
684-
iounmap(gpio);
685-
release_mem_region(GPIO_BASE, SZ_4K);
686-
}
687-
688672
lirc_unregister_driver(driver.minor);
689673
printk(KERN_INFO LIRC_DRIVER_NAME ": cleaned up module\n");
690674
}

0 commit comments

Comments
 (0)