Lines Matching +full:clock +full:- +full:presc
1 // SPDX-License-Identifier: GPL-2.0
89 u32 tout, presc, iwdg_rlr, iwdg_pr, iwdg_sr; in stm32_iwdg_start() local
92 dev_dbg(wdd->parent, "%s\n", __func__); in stm32_iwdg_start()
94 tout = clamp_t(unsigned int, wdd->timeout, in stm32_iwdg_start()
95 wdd->min_timeout, wdd->max_hw_heartbeat_ms / 1000); in stm32_iwdg_start()
97 presc = DIV_ROUND_UP(tout * wdt->rate, RLR_MAX + 1); in stm32_iwdg_start()
100 presc = roundup_pow_of_two(presc); in stm32_iwdg_start()
101 iwdg_pr = presc <= 1 << PR_SHIFT ? 0 : ilog2(presc) - PR_SHIFT; in stm32_iwdg_start()
102 iwdg_rlr = ((tout * wdt->rate) / presc) - 1; in stm32_iwdg_start()
105 reg_write(wdt->regs, IWDG_KR, KR_KEY_EWA); in stm32_iwdg_start()
108 reg_write(wdt->regs, IWDG_PR, iwdg_pr); in stm32_iwdg_start()
109 reg_write(wdt->regs, IWDG_RLR, iwdg_rlr); in stm32_iwdg_start()
110 reg_write(wdt->regs, IWDG_KR, KR_KEY_ENABLE); in stm32_iwdg_start()
113 ret = readl_relaxed_poll_timeout(wdt->regs + IWDG_SR, iwdg_sr, in stm32_iwdg_start()
117 dev_err(wdd->parent, "Fail to set prescaler, reload regs\n"); in stm32_iwdg_start()
122 reg_write(wdt->regs, IWDG_KR, KR_KEY_RELOAD); in stm32_iwdg_start()
131 dev_dbg(wdd->parent, "%s\n", __func__); in stm32_iwdg_ping()
134 reg_write(wdt->regs, IWDG_KR, KR_KEY_RELOAD); in stm32_iwdg_ping()
142 dev_dbg(wdd->parent, "%s timeout: %d sec\n", __func__, timeout); in stm32_iwdg_set_timeout()
144 wdd->timeout = timeout; in stm32_iwdg_set_timeout()
160 struct device *dev = &pdev->dev; in stm32_iwdg_clk_init()
163 wdt->clk_lsi = devm_clk_get(dev, "lsi"); in stm32_iwdg_clk_init()
164 if (IS_ERR(wdt->clk_lsi)) in stm32_iwdg_clk_init()
165 return dev_err_probe(dev, PTR_ERR(wdt->clk_lsi), "Unable to get lsi clock\n"); in stm32_iwdg_clk_init()
167 /* optional peripheral clock */ in stm32_iwdg_clk_init()
168 if (wdt->data->has_pclk) { in stm32_iwdg_clk_init()
169 wdt->clk_pclk = devm_clk_get(dev, "pclk"); in stm32_iwdg_clk_init()
170 if (IS_ERR(wdt->clk_pclk)) in stm32_iwdg_clk_init()
171 return dev_err_probe(dev, PTR_ERR(wdt->clk_pclk), in stm32_iwdg_clk_init()
172 "Unable to get pclk clock\n"); in stm32_iwdg_clk_init()
174 ret = clk_prepare_enable(wdt->clk_pclk); in stm32_iwdg_clk_init()
176 dev_err(dev, "Unable to prepare pclk clock\n"); in stm32_iwdg_clk_init()
181 wdt->clk_pclk); in stm32_iwdg_clk_init()
186 ret = clk_prepare_enable(wdt->clk_lsi); in stm32_iwdg_clk_init()
188 dev_err(dev, "Unable to prepare lsi clock\n"); in stm32_iwdg_clk_init()
192 wdt->clk_lsi); in stm32_iwdg_clk_init()
196 wdt->rate = clk_get_rate(wdt->clk_lsi); in stm32_iwdg_clk_init()
216 { .compatible = "st,stm32-iwdg", .data = &stm32_iwdg_data },
217 { .compatible = "st,stm32mp1-iwdg", .data = &stm32mp1_iwdg_data },
224 struct device *dev = &pdev->dev; in stm32_iwdg_probe()
231 return -ENOMEM; in stm32_iwdg_probe()
233 wdt->data = of_device_get_match_data(&pdev->dev); in stm32_iwdg_probe()
234 if (!wdt->data) in stm32_iwdg_probe()
235 return -ENODEV; in stm32_iwdg_probe()
238 wdt->regs = devm_platform_ioremap_resource(pdev, 0); in stm32_iwdg_probe()
239 if (IS_ERR(wdt->regs)) in stm32_iwdg_probe()
240 return PTR_ERR(wdt->regs); in stm32_iwdg_probe()
247 wdd = &wdt->wdd; in stm32_iwdg_probe()
248 wdd->parent = dev; in stm32_iwdg_probe()
249 wdd->info = &stm32_iwdg_info; in stm32_iwdg_probe()
250 wdd->ops = &stm32_iwdg_ops; in stm32_iwdg_probe()
251 wdd->min_timeout = DIV_ROUND_UP((RLR_MIN + 1) * PR_MIN, wdt->rate); in stm32_iwdg_probe()
252 wdd->max_hw_heartbeat_ms = ((RLR_MAX + 1) * wdt->data->max_prescaler * in stm32_iwdg_probe()
253 1000) / wdt->rate; in stm32_iwdg_probe()
261 * (Means U-Boot/bootloaders leaves the watchdog running) in stm32_iwdg_probe()
274 set_bit(WDOG_HW_RUNNING, &wdd->status); in stm32_iwdg_probe()