67
67
/* clears bits which are 1 ignores bits which are 0 */
68
68
#define GPIO_CLEAR_PIN (g ) gpiochip->set(gpiochip,g,0)
69
69
/* 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))
75
70
#define GPIO_IRQ (g ) gpiochip->to_irq(gpiochip,g)
76
71
77
72
#ifndef MAX_UDELAY_MS
@@ -101,6 +96,8 @@ static int sense = -1;
101
96
static int softcarrier = 1 ;
102
97
103
98
struct gpio_chip * gpiochip ;
99
+ struct irq_chip * irqchip ;
100
+ struct irq_data * irqdata ;
104
101
105
102
/* forward declarations */
106
103
static long send_pulse (unsigned long length );
@@ -110,8 +107,6 @@ static void lirc_rpi_exit(void);
110
107
int valid_gpio_pins [] = { 0 , 1 , 4 , 8 , 7 , 9 , 10 , 11 , 14 , 15 , 17 , 18 , 21 , 22 , 23 ,
111
108
24 , 25 };
112
109
113
- volatile unsigned * gpio ;
114
-
115
110
static struct platform_device * lirc_rpi_dev ;
116
111
static struct timeval lasttv = {0 , 0 };
117
112
static struct lirc_buffer rbuf ;
@@ -270,7 +265,8 @@ static irqreturn_t irq_handler(int i, void *blah, struct pt_regs *regs)
270
265
signal = GPIO_READ_PIN (gpio_in_pin );
271
266
272
267
/* reset interrupt */
273
- GPIO_INT_CLEAR (gpio_in_pin );
268
+ // is this supposed to mask or unmask the irq?
269
+ irqchip -> irq_unmask (irqdata );
274
270
275
271
if (sense != -1 ) {
276
272
/* get current time */
@@ -321,22 +317,8 @@ int is_right_chip(struct gpio_chip *chip, void *data) {
321
317
}
322
318
static int init_port (void )
323
319
{
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 ;
332
321
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
- }
340
322
gpiochip = gpiochip_find ("bcm2708_gpio" ,is_right_chip );
341
323
if (!gpiochip ) return - ENODEV ;
342
324
if (gpio_request (gpio_out_pin ,"lirc_rpi" )) {
@@ -356,6 +338,16 @@ static int init_port(void)
356
338
GPIO_DIR_OUTPUT (gpio_out_pin );
357
339
GPIO_CLEAR_PIN (gpio_out_pin );
358
340
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
+
359
351
/* if pin is high, then this must be an active low receiver. */
360
352
if (sense == -1 ) {
361
353
/* wait 1/2 sec for the power supply */
@@ -384,15 +376,15 @@ static int init_port(void)
384
376
sense ? "low" : "high" , gpio_in_pin );
385
377
}
386
378
return 0 ;
379
+ error4 :
380
+ gpio_free (gpio_in_pin );
387
381
error3 :
388
382
gpio_free (gpio_out_pin );
389
383
error2 :
390
- iounmap (gpio );
391
- error1 :
392
- release_mem_region (GPIO_BASE , SZ_4K );
393
384
return ret ;
394
385
}
395
386
387
+ // called when the character device is opened
396
388
static int set_use_inc (void * data )
397
389
{
398
390
int result ;
@@ -403,7 +395,7 @@ static int set_use_inc(void *data)
403
395
404
396
result = request_irq (GPIO_IRQ (gpio_in_pin ), (irq_handler_t )
405
397
irq_handler , 0 ,
406
- LIRC_DRIVER_NAME , (void * ) gpio );
398
+ LIRC_DRIVER_NAME , (void * ) 0 );
407
399
408
400
switch (result ) {
409
401
case - EBUSY :
@@ -426,13 +418,12 @@ static int set_use_inc(void *data)
426
418
spin_lock_irqsave (& lock , flags );
427
419
428
420
/* GPREN0 GPIO Pin Rising Edge Detect Enable */
429
- GPIO_INT_RISING (gpio_in_pin , 1 );
430
-
431
421
/* 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 );
433
423
434
424
/* 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 );
436
427
437
428
spin_unlock_irqrestore (& lock , flags );
438
429
@@ -446,14 +437,13 @@ static void set_use_dec(void *data)
446
437
spin_lock_irqsave (& lock , flags );
447
438
448
439
/* GPREN0 GPIO Pin Rising Edge Detect Disable */
449
- GPIO_INT_RISING (gpio_in_pin , 0 );
450
-
451
440
/* 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 );
453
443
454
444
spin_unlock_irqrestore (& lock , flags );
455
445
456
- free_irq (GPIO_IRQ (gpio_in_pin ), (void * ) gpio );
446
+ free_irq (GPIO_IRQ (gpio_in_pin ), (void * ) 0 );
457
447
458
448
dprintk (KERN_INFO LIRC_DRIVER_NAME
459
449
": freed IRQ %04x\n" , GPIO_IRQ (gpio_in_pin ));
@@ -679,12 +669,6 @@ static void __exit lirc_rpi_exit_module(void)
679
669
{
680
670
lirc_rpi_exit ();
681
671
682
- /* release mapped memory and allocated region */
683
- if (gpio != NULL ) {
684
- iounmap (gpio );
685
- release_mem_region (GPIO_BASE , SZ_4K );
686
- }
687
-
688
672
lirc_unregister_driver (driver .minor );
689
673
printk (KERN_INFO LIRC_DRIVER_NAME ": cleaned up module\n" );
690
674
}
0 commit comments