Rajavardhan Gundi | e3f2fa4 | 2017-10-12 15:44:48 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 Intel Corporation |
| 3 | * |
| 4 | * SPDX-License-Identifier: Apache-2.0 |
| 5 | */ |
| 6 | |
Kumar Gala | f74ddd3 | 2020-03-27 05:46:12 -0500 | [diff] [blame] | 7 | #define DT_DRV_COMPAT snps_designware_intc |
| 8 | |
Rajavardhan Gundi | e3f2fa4 | 2017-10-12 15:44:48 +0530 | [diff] [blame] | 9 | /* This implementation supports only the regular irqs |
| 10 | * No support for priority filtering |
| 11 | * No support for vectored interrupts |
| 12 | * Firqs are also not supported |
| 13 | * This implementation works only when sw_isr_table is enabled in zephyr |
| 14 | */ |
| 15 | |
| 16 | #include <device.h> |
Rajavardhan Gundi | e3f2fa4 | 2017-10-12 15:44:48 +0530 | [diff] [blame] | 17 | #include <irq_nextlevel.h> |
Tomasz Bursztyka | c30600d | 2019-12-18 09:31:56 +0100 | [diff] [blame] | 18 | #include "intc_dw.h" |
Anas Nashif | 238b664 | 2018-11-01 16:24:48 -0400 | [diff] [blame] | 19 | #include <soc.h> |
Rajavardhan Gundi | e3f2fa4 | 2017-10-12 15:44:48 +0530 | [diff] [blame] | 20 | |
Kumar Gala | a1b77fd | 2020-05-27 11:26:57 -0500 | [diff] [blame] | 21 | static ALWAYS_INLINE void dw_ictl_dispatch_child_isrs(uint32_t intr_status, |
| 22 | uint32_t isr_base_offset) |
Rajavardhan Gundi | e3f2fa4 | 2017-10-12 15:44:48 +0530 | [diff] [blame] | 23 | { |
Kumar Gala | a1b77fd | 2020-05-27 11:26:57 -0500 | [diff] [blame] | 24 | uint32_t intr_bitpos, intr_offset; |
Rajavardhan Gundi | e3f2fa4 | 2017-10-12 15:44:48 +0530 | [diff] [blame] | 25 | |
| 26 | /* Dispatch lower level ISRs depending upon the bit set */ |
| 27 | while (intr_status) { |
| 28 | intr_bitpos = find_lsb_set(intr_status) - 1; |
| 29 | intr_status &= ~(1 << intr_bitpos); |
| 30 | intr_offset = isr_base_offset + intr_bitpos; |
| 31 | _sw_isr_table[intr_offset].isr( |
| 32 | _sw_isr_table[intr_offset].arg); |
| 33 | } |
| 34 | } |
| 35 | |
Tomasz Bursztyka | e18fcbb | 2020-04-30 20:33:38 +0200 | [diff] [blame] | 36 | static int dw_ictl_initialize(const struct device *dev) |
Rajavardhan Gundi | e3f2fa4 | 2017-10-12 15:44:48 +0530 | [diff] [blame] | 37 | { |
Tomasz Bursztyka | af6140c | 2020-05-28 20:44:16 +0200 | [diff] [blame] | 38 | const struct dw_ictl_config *config = dev->config; |
Rajavardhan Gundi | e3f2fa4 | 2017-10-12 15:44:48 +0530 | [diff] [blame] | 39 | volatile struct dw_ictl_registers * const regs = |
Tomasz Bursztyka | 2511415 | 2019-12-17 15:48:00 +0100 | [diff] [blame] | 40 | (struct dw_ictl_registers *)config->base_addr; |
Rajavardhan Gundi | e3f2fa4 | 2017-10-12 15:44:48 +0530 | [diff] [blame] | 41 | |
| 42 | /* disable all interrupts */ |
Patrik Flykt | 8ff96b5 | 2018-11-29 11:12:22 -0800 | [diff] [blame] | 43 | regs->irq_inten_l = 0U; |
| 44 | regs->irq_inten_h = 0U; |
Rajavardhan Gundi | e3f2fa4 | 2017-10-12 15:44:48 +0530 | [diff] [blame] | 45 | |
| 46 | return 0; |
| 47 | } |
| 48 | |
Tomasz Bursztyka | 4dcfb55 | 2020-06-17 14:58:56 +0200 | [diff] [blame] | 49 | static void dw_ictl_isr(const struct device *dev) |
Rajavardhan Gundi | e3f2fa4 | 2017-10-12 15:44:48 +0530 | [diff] [blame] | 50 | { |
Tomasz Bursztyka | af6140c | 2020-05-28 20:44:16 +0200 | [diff] [blame] | 51 | const struct dw_ictl_config *config = dev->config; |
Rajavardhan Gundi | e3f2fa4 | 2017-10-12 15:44:48 +0530 | [diff] [blame] | 52 | volatile struct dw_ictl_registers * const regs = |
Tomasz Bursztyka | 2511415 | 2019-12-17 15:48:00 +0100 | [diff] [blame] | 53 | (struct dw_ictl_registers *)config->base_addr; |
Rajavardhan Gundi | e3f2fa4 | 2017-10-12 15:44:48 +0530 | [diff] [blame] | 54 | |
Daniel Leung | 40138c9 | 2021-09-21 13:37:34 -0700 | [diff] [blame] | 55 | dw_ictl_dispatch_child_isrs(regs->irq_finalstatus_l, |
Tomasz Bursztyka | 4b94668 | 2019-12-17 15:30:09 +0100 | [diff] [blame] | 56 | config->isr_table_offset); |
Rajavardhan Gundi | e3f2fa4 | 2017-10-12 15:44:48 +0530 | [diff] [blame] | 57 | |
| 58 | if (config->numirqs > 32) { |
Daniel Leung | 40138c9 | 2021-09-21 13:37:34 -0700 | [diff] [blame] | 59 | dw_ictl_dispatch_child_isrs(regs->irq_finalstatus_h, |
Tomasz Bursztyka | 4b94668 | 2019-12-17 15:30:09 +0100 | [diff] [blame] | 60 | config->isr_table_offset + 32); |
Rajavardhan Gundi | e3f2fa4 | 2017-10-12 15:44:48 +0530 | [diff] [blame] | 61 | } |
| 62 | } |
| 63 | |
Tomasz Bursztyka | e18fcbb | 2020-04-30 20:33:38 +0200 | [diff] [blame] | 64 | static inline void dw_ictl_intr_enable(const struct device *dev, |
| 65 | unsigned int irq) |
Rajavardhan Gundi | e3f2fa4 | 2017-10-12 15:44:48 +0530 | [diff] [blame] | 66 | { |
Tomasz Bursztyka | af6140c | 2020-05-28 20:44:16 +0200 | [diff] [blame] | 67 | const struct dw_ictl_config *config = dev->config; |
Rajavardhan Gundi | e3f2fa4 | 2017-10-12 15:44:48 +0530 | [diff] [blame] | 68 | volatile struct dw_ictl_registers * const regs = |
Tomasz Bursztyka | 2511415 | 2019-12-17 15:48:00 +0100 | [diff] [blame] | 69 | (struct dw_ictl_registers *)config->base_addr; |
Rajavardhan Gundi | e3f2fa4 | 2017-10-12 15:44:48 +0530 | [diff] [blame] | 70 | |
| 71 | if (irq < 32) { |
| 72 | regs->irq_inten_l |= (1 << irq); |
| 73 | } else { |
| 74 | regs->irq_inten_h |= (1 << (irq - 32)); |
| 75 | } |
| 76 | } |
| 77 | |
Tomasz Bursztyka | e18fcbb | 2020-04-30 20:33:38 +0200 | [diff] [blame] | 78 | static inline void dw_ictl_intr_disable(const struct device *dev, |
| 79 | unsigned int irq) |
Rajavardhan Gundi | e3f2fa4 | 2017-10-12 15:44:48 +0530 | [diff] [blame] | 80 | { |
Tomasz Bursztyka | af6140c | 2020-05-28 20:44:16 +0200 | [diff] [blame] | 81 | const struct dw_ictl_config *config = dev->config; |
Rajavardhan Gundi | e3f2fa4 | 2017-10-12 15:44:48 +0530 | [diff] [blame] | 82 | volatile struct dw_ictl_registers * const regs = |
Tomasz Bursztyka | 2511415 | 2019-12-17 15:48:00 +0100 | [diff] [blame] | 83 | (struct dw_ictl_registers *)config->base_addr; |
Rajavardhan Gundi | e3f2fa4 | 2017-10-12 15:44:48 +0530 | [diff] [blame] | 84 | |
| 85 | if (irq < 32) { |
| 86 | regs->irq_inten_l &= ~(1 << irq); |
| 87 | } else { |
| 88 | regs->irq_inten_h &= ~(1 << (irq - 32)); |
| 89 | } |
| 90 | } |
| 91 | |
Tomasz Bursztyka | e18fcbb | 2020-04-30 20:33:38 +0200 | [diff] [blame] | 92 | static inline unsigned int dw_ictl_intr_get_state(const struct device *dev) |
Rajavardhan Gundi | e3f2fa4 | 2017-10-12 15:44:48 +0530 | [diff] [blame] | 93 | { |
Tomasz Bursztyka | af6140c | 2020-05-28 20:44:16 +0200 | [diff] [blame] | 94 | const struct dw_ictl_config *config = dev->config; |
Rajavardhan Gundi | e3f2fa4 | 2017-10-12 15:44:48 +0530 | [diff] [blame] | 95 | volatile struct dw_ictl_registers * const regs = |
Tomasz Bursztyka | 2511415 | 2019-12-17 15:48:00 +0100 | [diff] [blame] | 96 | (struct dw_ictl_registers *)config->base_addr; |
Rajavardhan Gundi | e3f2fa4 | 2017-10-12 15:44:48 +0530 | [diff] [blame] | 97 | |
| 98 | if (regs->irq_inten_l) { |
| 99 | return 1; |
| 100 | } |
| 101 | |
| 102 | if (config->numirqs > 32) { |
| 103 | if (regs->irq_inten_h) { |
| 104 | return 1; |
| 105 | } |
| 106 | } |
| 107 | return 0; |
| 108 | } |
| 109 | |
Tomasz Bursztyka | e18fcbb | 2020-04-30 20:33:38 +0200 | [diff] [blame] | 110 | static int dw_ictl_intr_get_line_state(const struct device *dev, |
| 111 | unsigned int irq) |
Daniel Leung | 635aadc | 2019-08-27 11:07:19 -0700 | [diff] [blame] | 112 | { |
Tomasz Bursztyka | af6140c | 2020-05-28 20:44:16 +0200 | [diff] [blame] | 113 | const struct dw_ictl_config *config = dev->config; |
Daniel Leung | 635aadc | 2019-08-27 11:07:19 -0700 | [diff] [blame] | 114 | volatile struct dw_ictl_registers * const regs = |
Tomasz Bursztyka | 2511415 | 2019-12-17 15:48:00 +0100 | [diff] [blame] | 115 | (struct dw_ictl_registers *)config->base_addr; |
Daniel Leung | 635aadc | 2019-08-27 11:07:19 -0700 | [diff] [blame] | 116 | |
| 117 | if (config->numirqs > 32) { |
| 118 | if ((regs->irq_inten_h & BIT(irq - 32)) != 0) { |
| 119 | return 1; |
| 120 | } |
| 121 | } else { |
| 122 | if ((regs->irq_inten_l & BIT(irq)) != 0) { |
| 123 | return 1; |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | return 0; |
| 128 | } |
| 129 | |
Tomasz Bursztyka | e18fcbb | 2020-04-30 20:33:38 +0200 | [diff] [blame] | 130 | static void dw_ictl_config_irq(const struct device *dev); |
Rajavardhan Gundi | e3f2fa4 | 2017-10-12 15:44:48 +0530 | [diff] [blame] | 131 | |
| 132 | static const struct dw_ictl_config dw_config = { |
Kumar Gala | f74ddd3 | 2020-03-27 05:46:12 -0500 | [diff] [blame] | 133 | .base_addr = DT_INST_REG_ADDR(0), |
| 134 | .numirqs = DT_INST_PROP(0, num_irqs), |
Rajavardhan Gundi | e3f2fa4 | 2017-10-12 15:44:48 +0530 | [diff] [blame] | 135 | .isr_table_offset = CONFIG_DW_ISR_TBL_OFFSET, |
| 136 | .config_func = dw_ictl_config_irq, |
| 137 | }; |
| 138 | |
Rajavardhan Gundi | e3f2fa4 | 2017-10-12 15:44:48 +0530 | [diff] [blame] | 139 | static const struct irq_next_level_api dw_ictl_apis = { |
| 140 | .intr_enable = dw_ictl_intr_enable, |
| 141 | .intr_disable = dw_ictl_intr_disable, |
| 142 | .intr_get_state = dw_ictl_intr_get_state, |
Daniel Leung | 635aadc | 2019-08-27 11:07:19 -0700 | [diff] [blame] | 143 | .intr_get_line_state = dw_ictl_intr_get_line_state, |
Rajavardhan Gundi | e3f2fa4 | 2017-10-12 15:44:48 +0530 | [diff] [blame] | 144 | }; |
| 145 | |
Gerard Marull-Paretas | e6170a4 | 2021-04-28 11:06:54 +0200 | [diff] [blame] | 146 | DEVICE_DT_INST_DEFINE(0, dw_ictl_initialize, NULL, |
Kumar Gala | 2d75433 | 2020-12-17 11:14:17 -0600 | [diff] [blame] | 147 | NULL, &dw_config, PRE_KERNEL_1, |
| 148 | CONFIG_DW_ICTL_INIT_PRIORITY, &dw_ictl_apis); |
Rajavardhan Gundi | e3f2fa4 | 2017-10-12 15:44:48 +0530 | [diff] [blame] | 149 | |
Tomasz Bursztyka | e18fcbb | 2020-04-30 20:33:38 +0200 | [diff] [blame] | 150 | static void dw_ictl_config_irq(const struct device *port) |
Rajavardhan Gundi | e3f2fa4 | 2017-10-12 15:44:48 +0530 | [diff] [blame] | 151 | { |
Kumar Gala | f74ddd3 | 2020-03-27 05:46:12 -0500 | [diff] [blame] | 152 | IRQ_CONNECT(DT_INST_IRQN(0), |
| 153 | DT_INST_IRQ(0, priority), |
Kumar Gala | e2d71c9 | 2020-02-13 14:13:51 -0600 | [diff] [blame] | 154 | dw_ictl_isr, |
Kumar Gala | 2d75433 | 2020-12-17 11:14:17 -0600 | [diff] [blame] | 155 | DEVICE_DT_INST_GET(0), |
Kumar Gala | f74ddd3 | 2020-03-27 05:46:12 -0500 | [diff] [blame] | 156 | DT_INST_IRQ(0, sense)); |
Rajavardhan Gundi | e3f2fa4 | 2017-10-12 15:44:48 +0530 | [diff] [blame] | 157 | } |