Lines Matching +full:clk +full:- +full:csr
1 // SPDX-License-Identifier: GPL-2.0-or-later
7 * Copyright (C) 2001 - 2012 Paul Mundt <lethal@linux-sh.org>
9 * 14-Dec-2001 Matt Domsch <Matt_Domsch@dell.com>
12 * 19-Apr-2002 Rob Radez <rob@osinvestor.com>
31 #include <linux/clk.h>
35 #define DRV_NAME "sh-wdt"
39 * values, consult the asm-sh/watchdog.h. Overload this at module load
43 * something quite higher than 100 (or we need a proper high-res timer
46 * the SH-4 and SH-5, this isn't necessarily that big of a problem, though
47 * for the SH-2 and SH-3, this isn't recommended unless the WDT is absolutely
65 #define next_ping_period(cks) (jiffies + msecs_to_jiffies(cks - 4))
75 struct clk *clk; member
85 u8 csr; in sh_wdt_start() local
87 pm_runtime_get_sync(wdt->dev); in sh_wdt_start()
88 clk_enable(wdt->clk); in sh_wdt_start()
90 spin_lock_irqsave(&wdt->lock, flags); in sh_wdt_start()
93 mod_timer(&wdt->timer, next_ping_period(clock_division_ratio)); in sh_wdt_start()
95 csr = sh_wdt_read_csr(); in sh_wdt_start()
96 csr |= WTCSR_WT | clock_division_ratio; in sh_wdt_start()
97 sh_wdt_write_csr(csr); in sh_wdt_start()
103 * process.. starting with SH-3, RSTS was moved to WTCSR, and the in sh_wdt_start()
106 * On the SH-2 however, in addition with bits being in different in sh_wdt_start()
109 csr = sh_wdt_read_csr(); in sh_wdt_start()
110 csr |= WTCSR_TME; in sh_wdt_start()
111 csr &= ~WTCSR_RSTS; in sh_wdt_start()
112 sh_wdt_write_csr(csr); in sh_wdt_start()
115 csr = sh_wdt_read_rstcsr(); in sh_wdt_start()
116 csr &= ~RSTCSR_RSTS; in sh_wdt_start()
117 sh_wdt_write_rstcsr(csr); in sh_wdt_start()
119 spin_unlock_irqrestore(&wdt->lock, flags); in sh_wdt_start()
128 u8 csr; in sh_wdt_stop() local
130 spin_lock_irqsave(&wdt->lock, flags); in sh_wdt_stop()
132 del_timer(&wdt->timer); in sh_wdt_stop()
134 csr = sh_wdt_read_csr(); in sh_wdt_stop()
135 csr &= ~WTCSR_TME; in sh_wdt_stop()
136 sh_wdt_write_csr(csr); in sh_wdt_stop()
138 spin_unlock_irqrestore(&wdt->lock, flags); in sh_wdt_stop()
140 clk_disable(wdt->clk); in sh_wdt_stop()
141 pm_runtime_put_sync(wdt->dev); in sh_wdt_stop()
151 spin_lock_irqsave(&wdt->lock, flags); in sh_wdt_keepalive()
153 spin_unlock_irqrestore(&wdt->lock, flags); in sh_wdt_keepalive()
164 return -EINVAL; in sh_wdt_set_heartbeat()
166 spin_lock_irqsave(&wdt->lock, flags); in sh_wdt_set_heartbeat()
168 wdt_dev->timeout = t; in sh_wdt_set_heartbeat()
169 spin_unlock_irqrestore(&wdt->lock, flags); in sh_wdt_set_heartbeat()
179 spin_lock_irqsave(&wdt->lock, flags); in sh_wdt_ping()
181 u8 csr; in sh_wdt_ping() local
183 csr = sh_wdt_read_csr(); in sh_wdt_ping()
184 csr &= ~WTCSR_IOVF; in sh_wdt_ping()
185 sh_wdt_write_csr(csr); in sh_wdt_ping()
189 mod_timer(&wdt->timer, next_ping_period(clock_division_ratio)); in sh_wdt_ping()
191 dev_warn(wdt->dev, "Heartbeat lost! Will not ping " in sh_wdt_ping()
193 spin_unlock_irqrestore(&wdt->lock, flags); in sh_wdt_ping()
223 * any attempts to register per-CPU watchdogs. in sh_wdt_probe()
225 if (pdev->id != -1) in sh_wdt_probe()
226 return -EINVAL; in sh_wdt_probe()
228 wdt = devm_kzalloc(&pdev->dev, sizeof(struct sh_wdt), GFP_KERNEL); in sh_wdt_probe()
230 return -ENOMEM; in sh_wdt_probe()
232 wdt->dev = &pdev->dev; in sh_wdt_probe()
234 wdt->clk = devm_clk_get(&pdev->dev, NULL); in sh_wdt_probe()
235 if (IS_ERR(wdt->clk)) { in sh_wdt_probe()
240 wdt->clk = NULL; in sh_wdt_probe()
243 wdt->base = devm_platform_ioremap_resource(pdev, 0); in sh_wdt_probe()
244 if (IS_ERR(wdt->base)) in sh_wdt_probe()
245 return PTR_ERR(wdt->base); in sh_wdt_probe()
249 sh_wdt_dev.parent = &pdev->dev; in sh_wdt_probe()
251 spin_lock_init(&wdt->lock); in sh_wdt_probe()
258 dev_warn(&pdev->dev, in sh_wdt_probe()
263 dev_info(&pdev->dev, "configured with heartbeat=%d sec (nowayout=%d)\n", in sh_wdt_probe()
268 dev_err(&pdev->dev, "Can't register watchdog (err=%d)\n", rc); in sh_wdt_probe()
272 timer_setup(&wdt->timer, sh_wdt_ping, 0); in sh_wdt_probe()
273 wdt->timer.expires = next_ping_period(clock_division_ratio); in sh_wdt_probe()
275 dev_info(&pdev->dev, "initialized.\n"); in sh_wdt_probe()
277 pm_runtime_enable(&pdev->dev); in sh_wdt_probe()
286 pm_runtime_disable(&pdev->dev); in sh_wdt_remove()
324 MODULE_AUTHOR("Paul Mundt <lethal@linux-sh.org>");