Mulin Chao | 84d90e4 | 2020-08-13 18:15:25 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2020 Nuvoton Technology Corporation. |
| 3 | * |
| 4 | * SPDX-License-Identifier: Apache-2.0 |
| 5 | */ |
| 6 | |
| 7 | #define DT_DRV_COMPAT nuvoton_npcx_miwu |
| 8 | |
| 9 | /** |
| 10 | * @file |
| 11 | * @brief Nuvoton NPCX MIWU driver |
| 12 | * |
| 13 | * The device Multi-Input Wake-Up Unit (MIWU) supports the Nuvoton embedded |
| 14 | * controller (EC) to exit 'Sleep' or 'Deep Sleep' power state which allows chip |
| 15 | * has better power consumption. Also, it provides signal conditioning such as |
| 16 | * 'Level' and 'Edge' trigger type and grouping of external interrupt sources |
| 17 | * of NVIC. The NPCX series has three identical MIWU modules: MIWU0, MIWU1, |
| 18 | * MIWU2. Together, they support a total of over 140 internal and/or external |
| 19 | * wake-up input (WUI) sources. |
| 20 | * |
Nazar Kazakov | 9713f0d | 2022-02-24 12:00:55 +0000 | [diff] [blame] | 21 | * This driver uses device tree files to present the relationship between |
Mulin Chao | 84d90e4 | 2020-08-13 18:15:25 +0800 | [diff] [blame] | 22 | * MIWU and the other devices in different npcx series. For npcx7 series, |
| 23 | * it include: |
| 24 | * 1. npcxn-miwus-wui-map.dtsi: it presents relationship between wake-up inputs |
| 25 | * (WUI) and its source device such as gpio, timer, eSPI VWs and so on. |
Mulin Chao | a8a217f | 2021-04-26 01:28:21 -0700 | [diff] [blame] | 26 | * 2. npcxn-miwus-int-map.dtsi: it presents relationship between MIWU group |
| 27 | * and NVIC interrupt in npcx series. Please notice it isn't 1-to-1 mapping. |
Mulin Chao | 84d90e4 | 2020-08-13 18:15:25 +0800 | [diff] [blame] | 28 | * For example, here is the mapping between miwu0's group a & d and IRQ7: |
| 29 | * |
| 30 | * map_miwu0_groups: { |
| 31 | * parent = <&miwu0>; |
| 32 | * group_ad0: group_ad0_map { |
| 33 | * irq = <7>; |
| 34 | * group_mask = <0x09>; |
| 35 | * }; |
| 36 | * ... |
| 37 | * }; |
| 38 | * |
| 39 | * It will connect IRQ 7 and intc_miwu_isr0() with the argument, group_mask, |
| 40 | * by IRQ_CONNECT() during driver initialization function. With group_mask, |
| 41 | * 0x09, the driver checks the pending bits of group a and group d in ISR. |
| 42 | * Then it will execute related callback functions if they have been |
| 43 | * registered properly. |
| 44 | * |
| 45 | * INCLUDE FILES: soc_miwu.h |
| 46 | * |
| 47 | */ |
| 48 | |
Gerard Marull-Paretas | fb60aab | 2022-05-06 10:25:46 +0200 | [diff] [blame] | 49 | #include <zephyr/device.h> |
| 50 | #include <zephyr/kernel.h> |
Mulin Chao | 84d90e4 | 2020-08-13 18:15:25 +0800 | [diff] [blame] | 51 | #include <soc.h> |
Gerard Marull-Paretas | fb60aab | 2022-05-06 10:25:46 +0200 | [diff] [blame] | 52 | #include <zephyr/sys/__assert.h> |
| 53 | #include <zephyr/irq_nextlevel.h> |
| 54 | #include <zephyr/drivers/gpio.h> |
Mulin Chao | 84d90e4 | 2020-08-13 18:15:25 +0800 | [diff] [blame] | 55 | |
| 56 | #include "soc_miwu.h" |
Mulin Chao | 6deb68a | 2020-08-13 18:53:09 +0800 | [diff] [blame] | 57 | #include "soc_gpio.h" |
Mulin Chao | 84d90e4 | 2020-08-13 18:15:25 +0800 | [diff] [blame] | 58 | |
Gerard Marull-Paretas | fb60aab | 2022-05-06 10:25:46 +0200 | [diff] [blame] | 59 | #include <zephyr/logging/log.h> |
Mulin Chao | 84d90e4 | 2020-08-13 18:15:25 +0800 | [diff] [blame] | 60 | LOG_MODULE_REGISTER(intc_miwu, LOG_LEVEL_ERR); |
| 61 | |
| 62 | /* MIWU module instances forward declaration */ |
Tomasz Bursztyka | e18fcbb | 2020-04-30 20:33:38 +0200 | [diff] [blame] | 63 | static const struct device *miwu_devs[]; |
Mulin Chao | 84d90e4 | 2020-08-13 18:15:25 +0800 | [diff] [blame] | 64 | |
| 65 | /* Driver config */ |
| 66 | struct intc_miwu_config { |
| 67 | /* miwu controller base address */ |
| 68 | uintptr_t base; |
| 69 | /* index of miwu controller */ |
| 70 | uint8_t index; |
| 71 | }; |
| 72 | |
| 73 | /* Callback functions list for GPIO wake-up inputs */ |
| 74 | sys_slist_t cb_list_gpio; |
| 75 | |
| 76 | /* |
| 77 | * Callback functions list for the generic hardware modules wake-up inputs |
| 78 | * such as timer, uart, i2c, host interface and so on. |
| 79 | */ |
| 80 | sys_slist_t cb_list_generic; |
| 81 | |
Mulin Chao | 84d90e4 | 2020-08-13 18:15:25 +0800 | [diff] [blame] | 82 | BUILD_ASSERT(sizeof(struct miwu_io_callback) == sizeof(struct gpio_callback), |
| 83 | "Size of struct miwu_io_callback must equal to struct gpio_callback"); |
| 84 | |
| 85 | BUILD_ASSERT(sizeof(struct miwu_io_params) == sizeof(gpio_port_pins_t), |
| 86 | "Size of struct miwu_io_params must equal to struct gpio_port_pins_t"); |
| 87 | |
| 88 | /* MIWU local functions */ |
| 89 | static void intc_miwu_dispatch_gpio_isr(uint8_t wui_table, |
| 90 | uint8_t wui_group, uint8_t wui_bit) |
| 91 | { |
| 92 | struct miwu_io_callback *cb, *tmp; |
| 93 | |
| 94 | SYS_SLIST_FOR_EACH_CONTAINER_SAFE(&cb_list_gpio, cb, tmp, node) { |
Mulin Chao | 6deb68a | 2020-08-13 18:53:09 +0800 | [diff] [blame] | 95 | /* Pending bit, group and table match the wui item in list */ |
| 96 | if (cb->params.wui.table == wui_table |
| 97 | && cb->params.wui.group == wui_group |
| 98 | && cb->params.wui.bit == wui_bit) { |
| 99 | __ASSERT(cb->handler, "No GPIO callback handler!"); |
| 100 | /* |
| 101 | * Execute GPIO callback and the other callback might |
| 102 | * match the same wui item. |
| 103 | */ |
Mulin Chao | d55aa5a | 2020-10-21 14:10:26 +0800 | [diff] [blame] | 104 | cb->handler(npcx_get_gpio_dev(cb->params.gpio_port), |
Mulin Chao | 6deb68a | 2020-08-13 18:53:09 +0800 | [diff] [blame] | 105 | (struct gpio_callback *)cb, |
| 106 | cb->params.pin_mask); |
| 107 | } |
Mulin Chao | 84d90e4 | 2020-08-13 18:15:25 +0800 | [diff] [blame] | 108 | } |
| 109 | } |
| 110 | |
| 111 | static void intc_miwu_dispatch_generic_isr(uint8_t wui_table, |
| 112 | uint8_t wui_group, uint8_t wui_bit) |
| 113 | { |
| 114 | struct miwu_dev_callback *cb, *tmp; |
| 115 | |
| 116 | SYS_SLIST_FOR_EACH_CONTAINER_SAFE(&cb_list_generic, cb, tmp, node) { |
| 117 | /* Pending bit, group and table match the wui item in list */ |
| 118 | if (cb->wui.table == wui_table |
| 119 | && cb->wui.group == wui_group |
| 120 | && cb->wui.bit == wui_bit) { |
| 121 | __ASSERT(cb->handler, "No Generic callback handler!"); |
| 122 | /* |
| 123 | * Execute generic callback and the other callback might |
| 124 | * match the same wui item. |
| 125 | */ |
| 126 | cb->handler(cb->source, &cb->wui); |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | static void intc_miwu_isr_pri(int wui_table, int wui_group) |
| 132 | { |
| 133 | int wui_bit; |
Wealian Liao | 6d6c5e1 | 2022-01-21 15:24:08 +0800 | [diff] [blame] | 134 | const struct intc_miwu_config *config = miwu_devs[wui_table]->config; |
| 135 | const uint32_t base = config->base; |
Mulin Chao | 84d90e4 | 2020-08-13 18:15:25 +0800 | [diff] [blame] | 136 | uint8_t mask = NPCX_WKPND(base, wui_group) & NPCX_WKEN(base, wui_group); |
| 137 | |
| 138 | /* Clear pending bits before dispatch ISR */ |
Anas Nashif | 49b36ea | 2022-07-06 07:34:50 -0400 | [diff] [blame] | 139 | if (mask) { |
Mulin Chao | 84d90e4 | 2020-08-13 18:15:25 +0800 | [diff] [blame] | 140 | NPCX_WKPCL(base, wui_group) = mask; |
Anas Nashif | 49b36ea | 2022-07-06 07:34:50 -0400 | [diff] [blame] | 141 | } |
Mulin Chao | 84d90e4 | 2020-08-13 18:15:25 +0800 | [diff] [blame] | 142 | |
| 143 | for (wui_bit = 0; wui_bit < 8; wui_bit++) { |
| 144 | if (mask & BIT(wui_bit)) { |
| 145 | LOG_DBG("miwu_isr %d %d %d!\n", wui_table, |
| 146 | wui_group, wui_bit); |
Nazar Kazakov | 9713f0d | 2022-02-24 12:00:55 +0000 | [diff] [blame] | 147 | /* Dispatch registered gpio and generic isrs */ |
Mulin Chao | 84d90e4 | 2020-08-13 18:15:25 +0800 | [diff] [blame] | 148 | intc_miwu_dispatch_gpio_isr(wui_table, |
| 149 | wui_group, wui_bit); |
| 150 | intc_miwu_dispatch_generic_isr(wui_table, |
| 151 | wui_group, wui_bit); |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | |
Mulin Chao | d55aa5a | 2020-10-21 14:10:26 +0800 | [diff] [blame] | 156 | /* Platform specific MIWU functions */ |
| 157 | void npcx_miwu_irq_enable(const struct npcx_wui *wui) |
Mulin Chao | 84d90e4 | 2020-08-13 18:15:25 +0800 | [diff] [blame] | 158 | { |
Wealian Liao | 6d6c5e1 | 2022-01-21 15:24:08 +0800 | [diff] [blame] | 159 | const struct intc_miwu_config *config = miwu_devs[wui->table]->config; |
| 160 | const uint32_t base = config->base; |
Mulin Chao | 84d90e4 | 2020-08-13 18:15:25 +0800 | [diff] [blame] | 161 | |
| 162 | NPCX_WKEN(base, wui->group) |= BIT(wui->bit); |
| 163 | } |
| 164 | |
Mulin Chao | d55aa5a | 2020-10-21 14:10:26 +0800 | [diff] [blame] | 165 | void npcx_miwu_irq_disable(const struct npcx_wui *wui) |
Mulin Chao | 84d90e4 | 2020-08-13 18:15:25 +0800 | [diff] [blame] | 166 | { |
Wealian Liao | 6d6c5e1 | 2022-01-21 15:24:08 +0800 | [diff] [blame] | 167 | const struct intc_miwu_config *config = miwu_devs[wui->table]->config; |
| 168 | const uint32_t base = config->base; |
Mulin Chao | 84d90e4 | 2020-08-13 18:15:25 +0800 | [diff] [blame] | 169 | |
| 170 | NPCX_WKEN(base, wui->group) &= ~BIT(wui->bit); |
| 171 | } |
| 172 | |
Mulin Chao | 1cc7307 | 2021-04-22 01:45:23 -0700 | [diff] [blame] | 173 | void npcx_miwu_io_enable(const struct npcx_wui *wui) |
| 174 | { |
Wealian Liao | 6d6c5e1 | 2022-01-21 15:24:08 +0800 | [diff] [blame] | 175 | const struct intc_miwu_config *config = miwu_devs[wui->table]->config; |
| 176 | const uint32_t base = config->base; |
Mulin Chao | 1cc7307 | 2021-04-22 01:45:23 -0700 | [diff] [blame] | 177 | |
| 178 | NPCX_WKINEN(base, wui->group) |= BIT(wui->bit); |
| 179 | } |
| 180 | |
| 181 | void npcx_miwu_io_disable(const struct npcx_wui *wui) |
| 182 | { |
Wealian Liao | 6d6c5e1 | 2022-01-21 15:24:08 +0800 | [diff] [blame] | 183 | const struct intc_miwu_config *config = miwu_devs[wui->table]->config; |
| 184 | const uint32_t base = config->base; |
Mulin Chao | 1cc7307 | 2021-04-22 01:45:23 -0700 | [diff] [blame] | 185 | |
| 186 | NPCX_WKINEN(base, wui->group) &= ~BIT(wui->bit); |
| 187 | } |
| 188 | |
Mulin Chao | ea00ff3 | 2021-02-04 18:09:20 -0800 | [diff] [blame] | 189 | bool npcx_miwu_irq_get_state(const struct npcx_wui *wui) |
Mulin Chao | 84d90e4 | 2020-08-13 18:15:25 +0800 | [diff] [blame] | 190 | { |
Wealian Liao | 6d6c5e1 | 2022-01-21 15:24:08 +0800 | [diff] [blame] | 191 | const struct intc_miwu_config *config = miwu_devs[wui->table]->config; |
| 192 | const uint32_t base = config->base; |
Mulin Chao | 84d90e4 | 2020-08-13 18:15:25 +0800 | [diff] [blame] | 193 | |
Mulin Chao | ea00ff3 | 2021-02-04 18:09:20 -0800 | [diff] [blame] | 194 | return IS_BIT_SET(NPCX_WKEN(base, wui->group), wui->bit); |
Mulin Chao | 84d90e4 | 2020-08-13 18:15:25 +0800 | [diff] [blame] | 195 | } |
| 196 | |
Wealian Liao | abb94b1 | 2021-04-19 15:31:51 +0800 | [diff] [blame] | 197 | bool npcx_miwu_irq_get_and_clear_pending(const struct npcx_wui *wui) |
| 198 | { |
Wealian Liao | 6d6c5e1 | 2022-01-21 15:24:08 +0800 | [diff] [blame] | 199 | const struct intc_miwu_config *config = miwu_devs[wui->table]->config; |
| 200 | const uint32_t base = config->base; |
Wealian Liao | abb94b1 | 2021-04-19 15:31:51 +0800 | [diff] [blame] | 201 | bool pending = IS_BIT_SET(NPCX_WKPND(base, wui->group), wui->bit); |
| 202 | |
| 203 | if (pending) { |
| 204 | NPCX_WKPCL(base, wui->group) = BIT(wui->bit); |
| 205 | } |
| 206 | |
| 207 | return pending; |
| 208 | } |
| 209 | |
Mulin Chao | d55aa5a | 2020-10-21 14:10:26 +0800 | [diff] [blame] | 210 | int npcx_miwu_interrupt_configure(const struct npcx_wui *wui, |
Mulin Chao | 84d90e4 | 2020-08-13 18:15:25 +0800 | [diff] [blame] | 211 | enum miwu_int_mode mode, enum miwu_int_trig trig) |
| 212 | { |
Wealian Liao | 6d6c5e1 | 2022-01-21 15:24:08 +0800 | [diff] [blame] | 213 | const struct intc_miwu_config *config = miwu_devs[wui->table]->config; |
| 214 | const uint32_t base = config->base; |
Mulin Chao | 84d90e4 | 2020-08-13 18:15:25 +0800 | [diff] [blame] | 215 | uint8_t pmask = BIT(wui->bit); |
| 216 | |
Mulin Chao | ea00ff3 | 2021-02-04 18:09:20 -0800 | [diff] [blame] | 217 | /* Disable interrupt of wake-up input source before configuring it */ |
| 218 | npcx_miwu_irq_disable(wui); |
| 219 | |
| 220 | /* Handle interrupt for level trigger */ |
| 221 | if (mode == NPCX_MIWU_MODE_LEVEL) { |
| 222 | /* Set detection mode to level */ |
| 223 | NPCX_WKMOD(base, wui->group) |= pmask; |
| 224 | switch (trig) { |
| 225 | /* Enable interrupting on level high */ |
| 226 | case NPCX_MIWU_TRIG_HIGH: |
| 227 | NPCX_WKEDG(base, wui->group) &= ~pmask; |
| 228 | break; |
| 229 | /* Enable interrupting on level low */ |
| 230 | case NPCX_MIWU_TRIG_LOW: |
| 231 | NPCX_WKEDG(base, wui->group) |= pmask; |
| 232 | break; |
| 233 | default: |
| 234 | return -EINVAL; |
Mulin Chao | 84d90e4 | 2020-08-13 18:15:25 +0800 | [diff] [blame] | 235 | } |
Mulin Chao | ea00ff3 | 2021-02-04 18:09:20 -0800 | [diff] [blame] | 236 | /* Handle interrupt for edge trigger */ |
| 237 | } else { |
| 238 | /* Set detection mode to edge */ |
| 239 | NPCX_WKMOD(base, wui->group) &= ~pmask; |
| 240 | switch (trig) { |
| 241 | /* Handle interrupting on falling edge */ |
| 242 | case NPCX_MIWU_TRIG_LOW: |
| 243 | NPCX_WKAEDG(base, wui->group) &= ~pmask; |
| 244 | NPCX_WKEDG(base, wui->group) |= pmask; |
| 245 | break; |
| 246 | /* Handle interrupting on rising edge */ |
| 247 | case NPCX_MIWU_TRIG_HIGH: |
| 248 | NPCX_WKAEDG(base, wui->group) &= ~pmask; |
| 249 | NPCX_WKEDG(base, wui->group) &= ~pmask; |
| 250 | break; |
| 251 | /* Handle interrupting on both edges */ |
| 252 | case NPCX_MIWU_TRIG_BOTH: |
| 253 | /* Enable any edge */ |
| 254 | NPCX_WKAEDG(base, wui->group) |= pmask; |
| 255 | break; |
| 256 | default: |
| 257 | return -EINVAL; |
| 258 | } |
Mulin Chao | 84d90e4 | 2020-08-13 18:15:25 +0800 | [diff] [blame] | 259 | } |
| 260 | |
Mulin Chao | ea00ff3 | 2021-02-04 18:09:20 -0800 | [diff] [blame] | 261 | /* Enable wake-up input sources */ |
| 262 | NPCX_WKINEN(base, wui->group) |= pmask; |
| 263 | |
| 264 | /* |
| 265 | * Clear pending bit since it might be set if WKINEN bit is |
| 266 | * changed. |
| 267 | */ |
| 268 | NPCX_WKPCL(base, wui->group) |= pmask; |
| 269 | |
Mulin Chao | 84d90e4 | 2020-08-13 18:15:25 +0800 | [diff] [blame] | 270 | return 0; |
| 271 | } |
| 272 | |
Mulin Chao | d55aa5a | 2020-10-21 14:10:26 +0800 | [diff] [blame] | 273 | void npcx_miwu_init_gpio_callback(struct miwu_io_callback *callback, |
Mulin Chao | 84d90e4 | 2020-08-13 18:15:25 +0800 | [diff] [blame] | 274 | const struct npcx_wui *io_wui, int port) |
| 275 | { |
| 276 | /* Initialize WUI and GPIO settings in unused bits field */ |
| 277 | callback->params.wui.table = io_wui->table; |
| 278 | callback->params.wui.group = io_wui->group; |
| 279 | callback->params.wui.bit = io_wui->bit; |
| 280 | callback->params.gpio_port = port; |
| 281 | } |
| 282 | |
Mulin Chao | d55aa5a | 2020-10-21 14:10:26 +0800 | [diff] [blame] | 283 | void npcx_miwu_init_dev_callback(struct miwu_dev_callback *callback, |
Mulin Chao | 84d90e4 | 2020-08-13 18:15:25 +0800 | [diff] [blame] | 284 | const struct npcx_wui *dev_wui, |
| 285 | miwu_dev_callback_handler_t handler, |
Tomasz Bursztyka | e18fcbb | 2020-04-30 20:33:38 +0200 | [diff] [blame] | 286 | const struct device *source) |
Mulin Chao | 84d90e4 | 2020-08-13 18:15:25 +0800 | [diff] [blame] | 287 | { |
| 288 | /* Initialize WUI and input device settings */ |
| 289 | callback->wui.table = dev_wui->table; |
| 290 | callback->wui.group = dev_wui->group; |
| 291 | callback->wui.bit = dev_wui->bit; |
| 292 | callback->handler = handler; |
| 293 | callback->source = source; |
| 294 | } |
| 295 | |
Mulin Chao | d55aa5a | 2020-10-21 14:10:26 +0800 | [diff] [blame] | 296 | int npcx_miwu_manage_gpio_callback(struct miwu_io_callback *cb, bool set) |
Mulin Chao | 84d90e4 | 2020-08-13 18:15:25 +0800 | [diff] [blame] | 297 | { |
| 298 | if (!sys_slist_is_empty(&cb_list_gpio)) { |
| 299 | if (!sys_slist_find_and_remove(&cb_list_gpio, &cb->node)) { |
| 300 | if (!set) { |
| 301 | return -EINVAL; |
| 302 | } |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | if (set) { |
| 307 | sys_slist_prepend(&cb_list_gpio, &cb->node); |
| 308 | } |
| 309 | |
| 310 | return 0; |
| 311 | } |
| 312 | |
Mulin Chao | d55aa5a | 2020-10-21 14:10:26 +0800 | [diff] [blame] | 313 | int npcx_miwu_manage_dev_callback(struct miwu_dev_callback *cb, bool set) |
Mulin Chao | 84d90e4 | 2020-08-13 18:15:25 +0800 | [diff] [blame] | 314 | { |
| 315 | if (!sys_slist_is_empty(&cb_list_generic)) { |
| 316 | if (!sys_slist_find_and_remove(&cb_list_generic, &cb->node)) { |
| 317 | if (!set) { |
| 318 | return -EINVAL; |
| 319 | } |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | if (set) { |
| 324 | sys_slist_prepend(&cb_list_generic, &cb->node); |
| 325 | } |
| 326 | |
| 327 | return 0; |
| 328 | } |
| 329 | |
| 330 | /* MIWU driver registration */ |
| 331 | #define NPCX_MIWU_ISR_FUNC(index) _CONCAT(intc_miwu_isr, index) |
| 332 | #define NPCX_MIWU_INIT_FUNC(inst) _CONCAT(intc_miwu_init, inst) |
| 333 | #define NPCX_MIWU_INIT_FUNC_DECL(inst) \ |
Peter Bigot | 478577e | 2020-09-02 09:47:49 -0500 | [diff] [blame] | 334 | static int intc_miwu_init##inst(const struct device *dev) |
Mulin Chao | 84d90e4 | 2020-08-13 18:15:25 +0800 | [diff] [blame] | 335 | |
| 336 | /* MIWU ISR implementation */ |
| 337 | #define NPCX_MIWU_ISR_FUNC_IMPL(inst) \ |
| 338 | static void intc_miwu_isr##inst(void *arg) \ |
| 339 | { \ |
| 340 | uint8_t grp_mask = (uint32_t)arg; \ |
| 341 | int group = 0; \ |
| 342 | \ |
| 343 | /* Check all MIWU groups belong to the same irq */ \ |
| 344 | do { \ |
| 345 | if (grp_mask & 0x01) \ |
| 346 | intc_miwu_isr_pri(inst, group); \ |
| 347 | group++; \ |
| 348 | grp_mask = grp_mask >> 1; \ |
| 349 | \ |
| 350 | } while (grp_mask != 0); \ |
| 351 | } |
| 352 | |
| 353 | /* MIWU init function implementation */ |
| 354 | #define NPCX_MIWU_INIT_FUNC_IMPL(inst) \ |
Peter Bigot | 478577e | 2020-09-02 09:47:49 -0500 | [diff] [blame] | 355 | static int intc_miwu_init##inst(const struct device *dev) \ |
Mulin Chao | 84d90e4 | 2020-08-13 18:15:25 +0800 | [diff] [blame] | 356 | { \ |
| 357 | int i; \ |
Wealian Liao | 6d6c5e1 | 2022-01-21 15:24:08 +0800 | [diff] [blame] | 358 | const struct intc_miwu_config *config = dev->config; \ |
| 359 | const uint32_t base = config->base; \ |
Mulin Chao | 84d90e4 | 2020-08-13 18:15:25 +0800 | [diff] [blame] | 360 | \ |
| 361 | /* Clear all MIWUs' pending and enable bits of MIWU device */ \ |
| 362 | for (i = 0; i < NPCX_MIWU_GROUP_COUNT; i++) { \ |
Mulin Chao | 84d90e4 | 2020-08-13 18:15:25 +0800 | [diff] [blame] | 363 | NPCX_WKEN(base, i) = 0; \ |
Mulin Chao | ea00ff3 | 2021-02-04 18:09:20 -0800 | [diff] [blame] | 364 | NPCX_WKPCL(base, i) = 0xFF; \ |
Mulin Chao | 84d90e4 | 2020-08-13 18:15:25 +0800 | [diff] [blame] | 365 | } \ |
| 366 | \ |
| 367 | /* Config IRQ and MWIU group directly */ \ |
Mulin Chao | daa48da | 2020-12-06 23:41:07 -0800 | [diff] [blame] | 368 | DT_FOREACH_CHILD(NPCX_DT_NODE_FROM_MIWU_MAP(inst), \ |
| 369 | NPCX_DT_MIWU_IRQ_CONNECT_IMPL_CHILD_FUNC) \ |
Mulin Chao | 84d90e4 | 2020-08-13 18:15:25 +0800 | [diff] [blame] | 370 | return 0; \ |
| 371 | } \ |
| 372 | |
| 373 | #define NPCX_MIWU_INIT(inst) \ |
| 374 | NPCX_MIWU_INIT_FUNC_DECL(inst); \ |
| 375 | \ |
| 376 | static const struct intc_miwu_config miwu_config_##inst = { \ |
| 377 | .base = DT_REG_ADDR(DT_NODELABEL(miwu##inst)), \ |
| 378 | .index = DT_PROP(DT_NODELABEL(miwu##inst), index), \ |
| 379 | }; \ |
| 380 | \ |
Kumar Gala | 2d75433 | 2020-12-17 11:14:17 -0600 | [diff] [blame] | 381 | DEVICE_DT_INST_DEFINE(inst, \ |
Mulin Chao | 84d90e4 | 2020-08-13 18:15:25 +0800 | [diff] [blame] | 382 | NPCX_MIWU_INIT_FUNC(inst), \ |
Gerard Marull-Paretas | e6170a4 | 2021-04-28 11:06:54 +0200 | [diff] [blame] | 383 | NULL, \ |
Mulin Chao | 84d90e4 | 2020-08-13 18:15:25 +0800 | [diff] [blame] | 384 | NULL, &miwu_config_##inst, \ |
| 385 | PRE_KERNEL_1, \ |
Maureen Helm | 41634c8 | 2022-03-11 16:25:41 -0600 | [diff] [blame] | 386 | CONFIG_INTC_INIT_PRIORITY, NULL); \ |
Mulin Chao | 84d90e4 | 2020-08-13 18:15:25 +0800 | [diff] [blame] | 387 | \ |
| 388 | NPCX_MIWU_ISR_FUNC_IMPL(inst) \ |
| 389 | \ |
| 390 | NPCX_MIWU_INIT_FUNC_IMPL(inst) |
| 391 | |
| 392 | DT_INST_FOREACH_STATUS_OKAY(NPCX_MIWU_INIT) |
| 393 | |
| 394 | /* MIWU module instances */ |
Kumar Gala | 2d75433 | 2020-12-17 11:14:17 -0600 | [diff] [blame] | 395 | #define NPCX_MIWU_DEV(inst) DEVICE_DT_INST_GET(inst), |
Mulin Chao | 84d90e4 | 2020-08-13 18:15:25 +0800 | [diff] [blame] | 396 | |
Tomasz Bursztyka | e18fcbb | 2020-04-30 20:33:38 +0200 | [diff] [blame] | 397 | static const struct device *miwu_devs[] = { |
Mulin Chao | 84d90e4 | 2020-08-13 18:15:25 +0800 | [diff] [blame] | 398 | DT_INST_FOREACH_STATUS_OKAY(NPCX_MIWU_DEV) |
| 399 | }; |
| 400 | |
| 401 | BUILD_ASSERT(ARRAY_SIZE(miwu_devs) == NPCX_MIWU_TABLE_COUNT, |
| 402 | "Size of miwu_devs array must equal to NPCX_MIWU_TABLE_COUNT"); |