.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Watchdog driver for CSR Atlas7 |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (c) 2015 Cambridge Silicon Radio Limited, a CSR plc group company. |
---|
5 | | - * |
---|
6 | | - * Licensed under GPLv2. |
---|
7 | 6 | */ |
---|
8 | 7 | |
---|
9 | 8 | #include <linux/clk.h> |
---|
.. | .. |
---|
125 | 124 | {} |
---|
126 | 125 | }; |
---|
127 | 126 | |
---|
| 127 | +static void atlas7_clk_disable_unprepare(void *data) |
---|
| 128 | +{ |
---|
| 129 | + clk_disable_unprepare(data); |
---|
| 130 | +} |
---|
| 131 | + |
---|
128 | 132 | static int atlas7_wdt_probe(struct platform_device *pdev) |
---|
129 | 133 | { |
---|
130 | | - struct device_node *np = pdev->dev.of_node; |
---|
| 134 | + struct device *dev = &pdev->dev; |
---|
131 | 135 | struct atlas7_wdog *wdt; |
---|
132 | | - struct resource *res; |
---|
133 | 136 | struct clk *clk; |
---|
134 | 137 | int ret; |
---|
135 | 138 | |
---|
136 | | - wdt = devm_kzalloc(&pdev->dev, sizeof(*wdt), GFP_KERNEL); |
---|
| 139 | + wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL); |
---|
137 | 140 | if (!wdt) |
---|
138 | 141 | return -ENOMEM; |
---|
139 | | - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
---|
140 | | - wdt->base = devm_ioremap_resource(&pdev->dev, res); |
---|
| 142 | + wdt->base = devm_platform_ioremap_resource(pdev, 0); |
---|
141 | 143 | if (IS_ERR(wdt->base)) |
---|
142 | 144 | return PTR_ERR(wdt->base); |
---|
143 | 145 | |
---|
144 | | - clk = of_clk_get(np, 0); |
---|
| 146 | + clk = devm_clk_get(dev, NULL); |
---|
145 | 147 | if (IS_ERR(clk)) |
---|
146 | 148 | return PTR_ERR(clk); |
---|
147 | 149 | ret = clk_prepare_enable(clk); |
---|
148 | 150 | if (ret) { |
---|
149 | | - dev_err(&pdev->dev, "clk enable failed\n"); |
---|
150 | | - goto err; |
---|
| 151 | + dev_err(dev, "clk enable failed\n"); |
---|
| 152 | + return ret; |
---|
151 | 153 | } |
---|
| 154 | + ret = devm_add_action_or_reset(dev, atlas7_clk_disable_unprepare, clk); |
---|
| 155 | + if (ret) |
---|
| 156 | + return ret; |
---|
152 | 157 | |
---|
153 | 158 | /* disable watchdog hardware */ |
---|
154 | 159 | writel(0, wdt->base + ATLAS7_WDT_CNT_CTRL); |
---|
155 | 160 | |
---|
156 | 161 | wdt->tick_rate = clk_get_rate(clk); |
---|
157 | | - if (!wdt->tick_rate) { |
---|
158 | | - ret = -EINVAL; |
---|
159 | | - goto err1; |
---|
160 | | - } |
---|
| 162 | + if (!wdt->tick_rate) |
---|
| 163 | + return -EINVAL; |
---|
161 | 164 | |
---|
162 | 165 | wdt->clk = clk; |
---|
163 | 166 | atlas7_wdd.min_timeout = 1; |
---|
164 | 167 | atlas7_wdd.max_timeout = UINT_MAX / wdt->tick_rate; |
---|
165 | 168 | |
---|
166 | | - watchdog_init_timeout(&atlas7_wdd, 0, &pdev->dev); |
---|
| 169 | + watchdog_init_timeout(&atlas7_wdd, 0, dev); |
---|
167 | 170 | watchdog_set_nowayout(&atlas7_wdd, nowayout); |
---|
168 | 171 | |
---|
169 | 172 | watchdog_set_drvdata(&atlas7_wdd, wdt); |
---|
170 | 173 | platform_set_drvdata(pdev, &atlas7_wdd); |
---|
171 | 174 | |
---|
172 | | - ret = watchdog_register_device(&atlas7_wdd); |
---|
173 | | - if (ret) |
---|
174 | | - goto err1; |
---|
175 | | - |
---|
176 | | - return 0; |
---|
177 | | - |
---|
178 | | -err1: |
---|
179 | | - clk_disable_unprepare(clk); |
---|
180 | | -err: |
---|
181 | | - clk_put(clk); |
---|
182 | | - return ret; |
---|
183 | | -} |
---|
184 | | - |
---|
185 | | -static void atlas7_wdt_shutdown(struct platform_device *pdev) |
---|
186 | | -{ |
---|
187 | | - struct watchdog_device *wdd = platform_get_drvdata(pdev); |
---|
188 | | - struct atlas7_wdog *wdt = watchdog_get_drvdata(wdd); |
---|
189 | | - |
---|
190 | | - atlas7_wdt_disable(wdd); |
---|
191 | | - clk_disable_unprepare(wdt->clk); |
---|
192 | | -} |
---|
193 | | - |
---|
194 | | -static int atlas7_wdt_remove(struct platform_device *pdev) |
---|
195 | | -{ |
---|
196 | | - struct watchdog_device *wdd = platform_get_drvdata(pdev); |
---|
197 | | - struct atlas7_wdog *wdt = watchdog_get_drvdata(wdd); |
---|
198 | | - |
---|
199 | | - atlas7_wdt_shutdown(pdev); |
---|
200 | | - clk_put(wdt->clk); |
---|
201 | | - return 0; |
---|
| 175 | + watchdog_stop_on_reboot(&atlas7_wdd); |
---|
| 176 | + watchdog_stop_on_unregister(&atlas7_wdd); |
---|
| 177 | + return devm_watchdog_register_device(dev, &atlas7_wdd); |
---|
202 | 178 | } |
---|
203 | 179 | |
---|
204 | 180 | static int __maybe_unused atlas7_wdt_suspend(struct device *dev) |
---|
.. | .. |
---|
236 | 212 | .of_match_table = atlas7_wdt_ids, |
---|
237 | 213 | }, |
---|
238 | 214 | .probe = atlas7_wdt_probe, |
---|
239 | | - .remove = atlas7_wdt_remove, |
---|
240 | | - .shutdown = atlas7_wdt_shutdown, |
---|
241 | 215 | }; |
---|
242 | 216 | module_platform_driver(atlas7_wdt_driver); |
---|
243 | 217 | |
---|