Skip to content

Commit

Permalink
intel_adsp: cavs: irq: simplify code
Browse files Browse the repository at this point in the history
Put duplicate snippet to get the device into a function.

Signed-off-by: Anas Nashif <[email protected]>
  • Loading branch information
nashif committed Aug 10, 2022
1 parent 1df711d commit 2241fb0
Showing 1 changed file with 31 additions and 63 deletions.
94 changes: 31 additions & 63 deletions soc/xtensa/intel_adsp/cavs/irq.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,119 +21,87 @@ LOG_MODULE_DECLARE(soc, CONFIG_SOC_LOG_LEVEL);

#define CAVS_INTC_NODE(n) DT_INST(n, intel_cavs_intc)

void z_soc_irq_enable(uint32_t irq)
static const struct device *_get_ictl_dev(uint32_t irq)
{
const struct device *dev_cavs;
const struct device *dev;

switch (XTENSA_IRQ_NUMBER(irq)) {
case DT_IRQN(CAVS_INTC_NODE(0)):
dev_cavs = DEVICE_DT_GET(CAVS_INTC_NODE(0));
dev = DEVICE_DT_GET(CAVS_INTC_NODE(0));
break;
case DT_IRQN(CAVS_INTC_NODE(1)):
dev_cavs = DEVICE_DT_GET(CAVS_INTC_NODE(1));
dev = DEVICE_DT_GET(CAVS_INTC_NODE(1));
break;
case DT_IRQN(CAVS_INTC_NODE(2)):
dev_cavs = DEVICE_DT_GET(CAVS_INTC_NODE(2));
dev = DEVICE_DT_GET(CAVS_INTC_NODE(2));
break;
case DT_IRQN(CAVS_INTC_NODE(3)):
dev_cavs = DEVICE_DT_GET(CAVS_INTC_NODE(3));
dev = DEVICE_DT_GET(CAVS_INTC_NODE(3));
break;
default:
/* regular interrupt */
z_xtensa_irq_enable(XTENSA_IRQ_NUMBER(irq));
return;
return NULL;
}

if (!device_is_ready(dev_cavs)) {
if (!device_is_ready(dev)) {
LOG_DBG("board: CAVS device is not ready");
return;
return NULL;
}

return dev;
}

void z_soc_irq_enable(uint32_t irq)
{
const struct device *dev;

dev = _get_ictl_dev(irq);
if (dev == NULL) {
return;
}
/*
* The specified interrupt is in CAVS interrupt controller.
* So enable core interrupt first.
*/
z_xtensa_irq_enable(XTENSA_IRQ_NUMBER(irq));

/* Then enable the interrupt in CAVS interrupt controller */
irq_enable_next_level(dev_cavs, CAVS_IRQ_NUMBER(irq));
irq_enable_next_level(dev, CAVS_IRQ_NUMBER(irq));
}

void z_soc_irq_disable(uint32_t irq)
{
const struct device *dev_cavs;

switch (XTENSA_IRQ_NUMBER(irq)) {
case DT_IRQN(CAVS_INTC_NODE(0)):
dev_cavs = DEVICE_DT_GET(CAVS_INTC_NODE(0));
break;
case DT_IRQN(CAVS_INTC_NODE(1)):
dev_cavs = DEVICE_DT_GET(CAVS_INTC_NODE(1));
break;
case DT_IRQN(CAVS_INTC_NODE(2)):
dev_cavs = DEVICE_DT_GET(CAVS_INTC_NODE(2));
break;
case DT_IRQN(CAVS_INTC_NODE(3)):
dev_cavs = DEVICE_DT_GET(CAVS_INTC_NODE(3));
break;
default:
/* regular interrupt */
z_xtensa_irq_disable(XTENSA_IRQ_NUMBER(irq));
return;
}
const struct device *dev;

if (!device_is_ready(dev_cavs)) {
LOG_DBG("board: CAVS device is not ready");
dev = _get_ictl_dev(irq);
if (dev == NULL) {
return;
}

/*
* The specified interrupt is in CAVS interrupt controller.
* So disable the interrupt in CAVS interrupt controller.
*/
irq_disable_next_level(dev_cavs, CAVS_IRQ_NUMBER(irq));
irq_disable_next_level(dev, CAVS_IRQ_NUMBER(irq));

/* Then disable the parent IRQ if all children are disabled */
if (!irq_is_enabled_next_level(dev_cavs)) {
if (!irq_is_enabled_next_level(dev)) {
z_xtensa_irq_disable(XTENSA_IRQ_NUMBER(irq));
}
}

int z_soc_irq_is_enabled(unsigned int irq)
{
const struct device *dev_cavs;
int ret = 0;
const struct device *dev;

switch (XTENSA_IRQ_NUMBER(irq)) {
case DT_IRQN(CAVS_INTC_NODE(0)):
dev_cavs = DEVICE_DT_GET(CAVS_INTC_NODE(0));
break;
case DT_IRQN(CAVS_INTC_NODE(1)):
dev_cavs = DEVICE_DT_GET(CAVS_INTC_NODE(1));
break;
case DT_IRQN(CAVS_INTC_NODE(2)):
dev_cavs = DEVICE_DT_GET(CAVS_INTC_NODE(2));
break;
case DT_IRQN(CAVS_INTC_NODE(3)):
dev_cavs = DEVICE_DT_GET(CAVS_INTC_NODE(3));
break;
default:
/* regular interrupt */
ret = z_xtensa_irq_is_enabled(XTENSA_IRQ_NUMBER(irq));
goto out;
}

if (!device_is_ready(dev_cavs)) {
LOG_DBG("board: CAVS device is not ready");
ret = -ENODEV;
goto out;
dev = _get_ictl_dev(irq);
if (dev == NULL) {
return -ENODEV;
}

/* Then check the interrupt in CAVS interrupt controller */
ret = irq_line_is_enabled_next_level(dev_cavs, CAVS_IRQ_NUMBER(irq));

out:
return ret;
return irq_line_is_enabled_next_level(dev, CAVS_IRQ_NUMBER(irq));
}

#ifdef CONFIG_DYNAMIC_INTERRUPTS
Expand Down

0 comments on commit 2241fb0

Please sign in to comment.