@@ -63,7 +63,9 @@ struct x8h7_gpio_info {
63
63
uint32_t gpio_dir ;
64
64
uint32_t gpio_val ;
65
65
uint32_t gpio_ien ;
66
+ uint8_t irq_conf ;
66
67
struct irq_domain * irq ;
68
+ struct mutex lock ;
67
69
};
68
70
69
71
// @TODO: add remaining gpios
@@ -298,17 +300,11 @@ static int x8h7_gpio_to_irq(struct gpio_chip *gc, unsigned offset)
298
300
static void x8h7_gpio_irq_unmask (struct irq_data * d )
299
301
{
300
302
struct x8h7_gpio_info * inf = irq_data_get_irq_chip_data (d );
301
- uint8_t data [2 ];
302
303
unsigned long irq ;
303
304
304
305
irq = irqd_to_hwirq (d );
305
306
inf -> gpio_ien &= ~(1 << irq );
306
307
DBG_PRINT ("irq %ld, ien %08Xld\n" , irq , inf -> gpio_ien );
307
-
308
- data [0 ] = irq ;
309
- data [1 ] = 1 ;
310
- x8h7_pkt_enq (X8H7_GPIO_PERIPH , X8H7_GPIO_OC_IEN , 2 , data );
311
- x8h7_pkt_send ();
312
308
}
313
309
314
310
static void x8h7_gpio_irq_mask (struct irq_data * d )
@@ -320,11 +316,6 @@ static void x8h7_gpio_irq_mask(struct irq_data *d)
320
316
irq = irqd_to_hwirq (d );
321
317
inf -> gpio_ien |= (1 << irq );
322
318
DBG_PRINT ("irq %ld, ien %08Xld\n" , irq , inf -> gpio_ien );
323
-
324
- data [0 ] = irq ;
325
- data [1 ] = 0 ;
326
- x8h7_pkt_enq (X8H7_GPIO_PERIPH , X8H7_GPIO_OC_IEN , 2 , data );
327
- x8h7_pkt_send ();
328
319
}
329
320
330
321
static void x8h7_gpio_irq_ack (struct irq_data * d )
@@ -342,38 +333,64 @@ static void x8h7_gpio_irq_ack(struct irq_data *d)
342
333
343
334
static int x8h7_gpio_irq_set_type (struct irq_data * d , unsigned int flow_type )
344
335
{
345
- //struct x8h7_gpio_info *inf = irq_data_get_irq_chip_data(d);
346
- uint8_t data [2 ];
347
- //struct gpio_chip *gc = &inf->gc;
348
- //unsigned long flags;
336
+ struct x8h7_gpio_info * inf = irq_data_get_irq_chip_data (d );
349
337
350
338
DBG_PRINT ("irq %ld flow_type %d\n" , irqd_to_hwirq (d ), flow_type );
351
339
352
340
switch (flow_type ) {
353
341
case IRQ_TYPE_EDGE_RISING :
354
- data [ 1 ] = GPIO_MODE_IN_RE ;
342
+ inf -> irq_conf = GPIO_MODE_IN_RE ;
355
343
break ;
356
344
case IRQ_TYPE_EDGE_FALLING :
357
- data [1 ] = GPIO_MODE_IN_FE ;
358
- break ;
345
+ inf -> irq_conf = GPIO_MODE_IN_FE ;
359
346
break ;
360
347
case IRQ_TYPE_EDGE_BOTH :
361
- data [ 1 ] = GPIO_MODE_IN_RE | GPIO_MODE_IN_FE ;
348
+ inf -> irq_conf = GPIO_MODE_IN_RE | GPIO_MODE_IN_FE ;
362
349
break ;
363
350
case IRQ_TYPE_LEVEL_HIGH :
364
- data [ 1 ] = GPIO_MODE_IN_AH ;
351
+ inf -> irq_conf = GPIO_MODE_IN_AH ;
365
352
break ;
366
353
case IRQ_TYPE_LEVEL_LOW :
367
- data [ 1 ] = GPIO_MODE_IN_AL ;
354
+ inf -> irq_conf = GPIO_MODE_IN_AL ;
368
355
break ;
369
356
default :
370
357
return - EINVAL ;
371
358
}
372
359
373
- data [0 ] = irqd_to_hwirq (d );
360
+ return 0 ;
361
+ }
362
+
363
+ static void x8h7_gpio_irq_bus_lock (struct irq_data * d )
364
+ {
365
+ struct x8h7_gpio_info * inf = irq_data_get_irq_chip_data (d );
366
+
367
+ DBG_PRINT ("\n" );
368
+ mutex_lock (& inf -> lock );
369
+ }
370
+
371
+ /* This is where we actually send spi packets to sync irq data */
372
+ static void x8h7_gpio_irq_bus_sync_unlock (struct irq_data * d )
373
+ {
374
+ struct x8h7_gpio_info * inf = irq_data_get_irq_chip_data (d );
375
+ uint8_t data [2 ];
376
+ unsigned long irq ;
377
+
378
+ DBG_PRINT ("\n" );
379
+ irq = irqd_to_hwirq (d );
380
+
381
+ // Send interrupt type
382
+ data [0 ] = irq ;
383
+ data [1 ] = inf -> irq_conf ;
374
384
x8h7_pkt_enq (X8H7_GPIO_PERIPH , X8H7_GPIO_OC_IRQ_TYPE , 2 , data );
375
385
x8h7_pkt_send ();
376
- return 0 ;
386
+
387
+ // Send mask
388
+ data [0 ] = irq ;
389
+ data [1 ] = inf -> gpio_ien ;
390
+ x8h7_pkt_enq (X8H7_GPIO_PERIPH , X8H7_GPIO_OC_IEN , 2 , data );
391
+ x8h7_pkt_send ();
392
+
393
+ mutex_unlock (& inf -> lock );
377
394
}
378
395
379
396
static struct irq_chip x8h7_gpio_irq_chip = {
@@ -382,6 +399,8 @@ static struct irq_chip x8h7_gpio_irq_chip = {
382
399
.irq_mask = x8h7_gpio_irq_mask ,
383
400
.irq_ack = x8h7_gpio_irq_ack ,
384
401
.irq_set_type = x8h7_gpio_irq_set_type ,
402
+ .irq_bus_lock = x8h7_gpio_irq_bus_lock ,
403
+ .irq_bus_sync_unlock = x8h7_gpio_irq_bus_sync_unlock ,
385
404
};
386
405
387
406
static int x8h7_gpio_irq_map (struct irq_domain * h , unsigned int irq ,
@@ -524,6 +543,8 @@ static int x8h7_gpio_probe(struct platform_device *pdev)
524
543
init_waitqueue_head (& inf -> wait );
525
544
inf -> rx_cnt = 0 ;
526
545
546
+ mutex_init (& inf -> lock );
547
+
527
548
/* Pinctrl_desc */
528
549
inf -> pinctrl_desc .name = "x8h7_gpio-pinctrl" ;
529
550
inf -> pinctrl_desc .pctlops = & x8h7_gpio_pinctrl_ops ;
0 commit comments