Skip to content

Commit 055ec09

Browse files
committed
Reworked irq ops since we can't write on spi in atomic context
1 parent 00a5244 commit 055ec09

File tree

1 file changed

+44
-23
lines changed

1 file changed

+44
-23
lines changed

recipes-kernel/kernel-modules/x8h7/x8h7_gpio.c

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ struct x8h7_gpio_info {
6363
uint32_t gpio_dir;
6464
uint32_t gpio_val;
6565
uint32_t gpio_ien;
66+
uint8_t irq_conf;
6667
struct irq_domain *irq;
68+
struct mutex lock;
6769
};
6870

6971
// @TODO: add remaining gpios
@@ -298,17 +300,11 @@ static int x8h7_gpio_to_irq(struct gpio_chip *gc, unsigned offset)
298300
static void x8h7_gpio_irq_unmask(struct irq_data *d)
299301
{
300302
struct x8h7_gpio_info *inf = irq_data_get_irq_chip_data(d);
301-
uint8_t data[2];
302303
unsigned long irq;
303304

304305
irq = irqd_to_hwirq(d);
305306
inf->gpio_ien &= ~(1 << irq);
306307
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();
312308
}
313309

314310
static void x8h7_gpio_irq_mask(struct irq_data *d)
@@ -320,11 +316,6 @@ static void x8h7_gpio_irq_mask(struct irq_data *d)
320316
irq = irqd_to_hwirq(d);
321317
inf->gpio_ien |= (1 << irq);
322318
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();
328319
}
329320

330321
static void x8h7_gpio_irq_ack(struct irq_data *d)
@@ -342,38 +333,64 @@ static void x8h7_gpio_irq_ack(struct irq_data *d)
342333

343334
static int x8h7_gpio_irq_set_type(struct irq_data *d, unsigned int flow_type)
344335
{
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);
349337

350338
DBG_PRINT("irq %ld flow_type %d\n", irqd_to_hwirq(d), flow_type);
351339

352340
switch (flow_type) {
353341
case IRQ_TYPE_EDGE_RISING:
354-
data[1] = GPIO_MODE_IN_RE;
342+
inf->irq_conf = GPIO_MODE_IN_RE;
355343
break;
356344
case IRQ_TYPE_EDGE_FALLING:
357-
data[1] = GPIO_MODE_IN_FE;
358-
break;
345+
inf->irq_conf = GPIO_MODE_IN_FE;
359346
break;
360347
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;
362349
break;
363350
case IRQ_TYPE_LEVEL_HIGH:
364-
data[1] = GPIO_MODE_IN_AH;
351+
inf->irq_conf = GPIO_MODE_IN_AH;
365352
break;
366353
case IRQ_TYPE_LEVEL_LOW:
367-
data[1] = GPIO_MODE_IN_AL;
354+
inf->irq_conf = GPIO_MODE_IN_AL;
368355
break;
369356
default:
370357
return -EINVAL;
371358
}
372359

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;
374384
x8h7_pkt_enq(X8H7_GPIO_PERIPH, X8H7_GPIO_OC_IRQ_TYPE, 2, data);
375385
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);
377394
}
378395

379396
static struct irq_chip x8h7_gpio_irq_chip = {
@@ -382,6 +399,8 @@ static struct irq_chip x8h7_gpio_irq_chip = {
382399
.irq_mask = x8h7_gpio_irq_mask,
383400
.irq_ack = x8h7_gpio_irq_ack,
384401
.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,
385404
};
386405

387406
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)
524543
init_waitqueue_head(&inf->wait);
525544
inf->rx_cnt = 0;
526545

546+
mutex_init(&inf->lock);
547+
527548
/* Pinctrl_desc */
528549
inf->pinctrl_desc.name = "x8h7_gpio-pinctrl";
529550
inf->pinctrl_desc.pctlops = &x8h7_gpio_pinctrl_ops;

0 commit comments

Comments
 (0)