Lines Matching +full:100 +full:base +full:- +full:t

4  * SPDX-License-Identifier: Apache-2.0
18 * +---------------------+ +-----------------+
19 * LFCLK --->| T0 Prescale Counter |-+->| 16-Bit T0 Timer |--------> T0 Timer
21 * +---------------------+ | +-----------------+
22 * +---------------------------------+
24 * | +-------------------+ +-----------------+
25 * +--->| Watchdog Prescale |--->| 8-Bit Watchdog |-----> Watchdog Event/Reset
27 * +-------------------+ +-----------------+
49 * Maximum watchdog window time. Since the watchdog counter is 8-bits, maximum
58 #define NPCX_WDT_MIN_WND_TIME 100UL
68 /* wdt controller base address */
69 uintptr_t base; member
70 /* t0 timer wake-up input source configuration */
89 #define HAL_INSTANCE(dev) ((struct twd_reg *)((const struct wdt_npcx_config *)(dev)->config)->base)
98 inst->T0CSR = (inst->T0CSR & ~BIT(NPCX_T0CSR_WDRST_STS)) | in wdt_t0out_reload()
102 while (IS_BIT_SET(inst->T0CSR, NPCX_T0CSR_RST)) { in wdt_t0out_reload()
103 if (k_uptime_get() - st > NPCX_T0CSR_RST_TIMEOUT) { in wdt_t0out_reload()
105 if (IS_BIT_SET(inst->T0CSR, NPCX_T0CSR_RST)) { in wdt_t0out_reload()
107 return -ETIMEDOUT; in wdt_t0out_reload()
122 while (IS_BIT_SET(inst->T0CSR, NPCX_T0CSR_WD_RUN)) { in wdt_wait_stopped()
123 if (k_uptime_get() - st > NPCX_WATCHDOG_STOP_TIMEOUT) { in wdt_wait_stopped()
125 if (IS_BIT_SET(inst->T0CSR, NPCX_T0CSR_WD_RUN)) { in wdt_wait_stopped()
127 return -ETIMEDOUT; in wdt_wait_stopped()
138 struct wdt_npcx_data *const data = dev->data; in wdt_t0out_isr()
142 CONFIG_WDT_NPCX_DELAY_CYCLES, wui->table, wui->group, wui->bit); in wdt_t0out_isr()
145 if (data->cb) { in wdt_t0out_isr()
146 data->cb(dev, 0); in wdt_t0out_isr()
152 const struct wdt_npcx_config *const config = dev->config; in wdt_config_t0out_interrupt()
155 npcx_miwu_init_dev_callback(&miwu_cb, &config->t0out, wdt_t0out_isr, in wdt_config_t0out_interrupt()
160 * Configure the T0 wake-up event triggered from a rising edge in wdt_config_t0out_interrupt()
163 npcx_miwu_interrupt_configure(&config->t0out, in wdt_config_t0out_interrupt()
171 struct wdt_npcx_data *const data = dev->data; in wdt_npcx_install_timeout()
175 if (IS_BIT_SET(inst->T0CSR, NPCX_T0CSR_WD_RUN)) { in wdt_npcx_install_timeout()
176 return -EBUSY; in wdt_npcx_install_timeout()
180 if (cfg->window.min != 0) { in wdt_npcx_install_timeout()
181 data->timeout_installed = false; in wdt_npcx_install_timeout()
182 return -EINVAL; in wdt_npcx_install_timeout()
186 * Since the watchdog counter in npcx series is 8-bits, maximum time in wdt_npcx_install_timeout()
188 * allowed range of 1-8000 in milliseconds. Check if the provided value in wdt_npcx_install_timeout()
191 if (cfg->window.max > NPCX_WDT_MAX_WND_TIME || cfg->window.max == 0) { in wdt_npcx_install_timeout()
192 data->timeout_installed = false; in wdt_npcx_install_timeout()
193 return -EINVAL; in wdt_npcx_install_timeout()
197 data->timeout = cfg->window.max; in wdt_npcx_install_timeout()
200 data->cb = cfg->callback; in wdt_npcx_install_timeout()
201 data->timeout_installed = true; in wdt_npcx_install_timeout()
209 const struct wdt_npcx_config *const config = dev->config; in wdt_npcx_setup()
210 struct wdt_npcx_data *const data = dev->data; in wdt_npcx_setup()
213 /* Disable irq of t0-out expired event first */ in wdt_npcx_setup()
214 npcx_miwu_irq_disable(&config->t0out); in wdt_npcx_setup()
216 if (!data->timeout_installed) { in wdt_npcx_setup()
218 return -EINVAL; in wdt_npcx_setup()
221 if (IS_BIT_SET(inst->T0CSR, NPCX_T0CSR_WD_RUN)) { in wdt_npcx_setup()
223 return -EBUSY; in wdt_npcx_setup()
228 return -ENOTSUP; in wdt_npcx_setup()
240 * Then the counter value is timeout/0.976 - 1. in wdt_npcx_setup()
242 inst->TWDT0 = MAX(DIV_ROUND_UP(data->timeout * NPCX_WDT_CLK, in wdt_npcx_setup()
243 32 * 1000) - 1, 1); in wdt_npcx_setup()
245 /* Configure 8-bit watchdog counter */ in wdt_npcx_setup()
246 inst->WDCNT = MIN(DIV_ROUND_UP(data->timeout, 32) + in wdt_npcx_setup()
249 LOG_DBG("WDT setup: TWDT0, WDCNT are %d, %d", inst->TWDT0, inst->WDCNT); in wdt_npcx_setup()
257 /* Enable irq of t0-out expired event */ in wdt_npcx_setup()
258 npcx_miwu_irq_enable(&config->t0out); in wdt_npcx_setup()
265 const struct wdt_npcx_config *const config = dev->config; in wdt_npcx_disable()
266 struct wdt_npcx_data *const data = dev->data; in wdt_npcx_disable()
273 while (k_uptime_get() - data->last_watchdog_touch < NPCX_WDT_MIN_WND_TIME) { in wdt_npcx_disable()
281 inst->WDSDM = 0x87; in wdt_npcx_disable()
282 inst->WDSDM = 0x61; in wdt_npcx_disable()
283 inst->WDSDM = 0x63; in wdt_npcx_disable()
285 /* Disable irq of t0-out expired event and mark it uninstalled */ in wdt_npcx_disable()
286 npcx_miwu_irq_disable(&config->t0out); in wdt_npcx_disable()
287 data->timeout_installed = false; in wdt_npcx_disable()
296 struct wdt_npcx_data *const data = dev->data; in wdt_npcx_feed()
300 inst->WDSDM = 0x5C; in wdt_npcx_feed()
301 data->last_watchdog_touch = k_uptime_get(); in wdt_npcx_feed()
325 * [7:6]- Reserved = 0 in wdt_npcx_init()
326 * [5] - WDSDME = 1: Feed watchdog by writing 5Ch to WDSDM in wdt_npcx_init()
327 * [4] - WDCT0I = 1: Select T0IN as watchdog prescaler clock in wdt_npcx_init()
328 * [3] - LWDCNT = 0: Don't lock WDCNT register in wdt_npcx_init()
329 * [2] - LTWDT0 = 0: Don't lock TWDT0 register in wdt_npcx_init()
330 * [1] - LTWCP = 0: Don't lock TWCP register in wdt_npcx_init()
331 * [0] - LTWCFG = 0: Don't lock TWCFG register in wdt_npcx_init()
333 inst->TWCFG = BIT(NPCX_TWCFG_WDSDME) | BIT(NPCX_TWCFG_WDCT0I); in wdt_npcx_init()
336 inst->T0CSR = (inst->T0CSR & ~BIT(NPCX_T0CSR_WDRST_STS)) | in wdt_npcx_init()
340 * - T0 Timer freq is LFCLK/32 Hz in wdt_npcx_init()
341 * - Watchdog freq is T0CLK/32 Hz (ie. LFCLK/1024 Hz) in wdt_npcx_init()
343 inst->WDCP = 0x05; /* Prescaler is 32 in Watchdog Timer */ in wdt_npcx_init()
344 inst->TWCP = 0x05; /* Prescaler is 32 in T0 Timer */ in wdt_npcx_init()
350 .base = DT_INST_REG_ADDR(0),