diff options
author | Michal Simek <michal.simek@xilinx.com> | 2014-02-12 08:34:34 -0500 |
---|---|---|
committer | Wim Van Sebroeck <wim@iguana.be> | 2014-03-31 07:29:04 -0400 |
commit | f06cdfd184d845e1f01df7f636c0e3b5c5cc8d18 (patch) | |
tree | eeaf7275f2c54cc3ae7273e6eecfd6ee55f211e4 /drivers/watchdog | |
parent | 5cf4e69d39f6a31a5305d01690c1607356b1483b (diff) |
watchdog: xilinx: Simplify probe and remove functions
Use devm_ helper function to simplify probe and error path.
Move ioremap to the beginning of probe function.
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
Diffstat (limited to 'drivers/watchdog')
-rw-r--r-- | drivers/watchdog/of_xilinx_wdt.c | 41 |
1 files changed, 9 insertions, 32 deletions
diff --git a/drivers/watchdog/of_xilinx_wdt.c b/drivers/watchdog/of_xilinx_wdt.c index 9cab3fd4f14c..39e61e15f723 100644 --- a/drivers/watchdog/of_xilinx_wdt.c +++ b/drivers/watchdog/of_xilinx_wdt.c | |||
@@ -12,6 +12,7 @@ | |||
12 | 12 | ||
13 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | 13 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
14 | 14 | ||
15 | #include <linux/err.h> | ||
15 | #include <linux/module.h> | 16 | #include <linux/module.h> |
16 | #include <linux/types.h> | 17 | #include <linux/types.h> |
17 | #include <linux/kernel.h> | 18 | #include <linux/kernel.h> |
@@ -43,7 +44,6 @@ | |||
43 | #define PFX WATCHDOG_NAME ": " | 44 | #define PFX WATCHDOG_NAME ": " |
44 | 45 | ||
45 | struct xwdt_device { | 46 | struct xwdt_device { |
46 | struct resource res; | ||
47 | void __iomem *base; | 47 | void __iomem *base; |
48 | u32 wdt_interval; | 48 | u32 wdt_interval; |
49 | }; | 49 | }; |
@@ -158,9 +158,15 @@ static int xwdt_probe(struct platform_device *pdev) | |||
158 | int rc; | 158 | int rc; |
159 | u32 *tmptr; | 159 | u32 *tmptr; |
160 | u32 *pfreq; | 160 | u32 *pfreq; |
161 | struct resource *res; | ||
161 | 162 | ||
162 | no_timeout = 0; | 163 | no_timeout = 0; |
163 | 164 | ||
165 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
166 | xdev.base = devm_ioremap_resource(&pdev->dev, res); | ||
167 | if (IS_ERR(xdev.base)) | ||
168 | return PTR_ERR(xdev.base); | ||
169 | |||
164 | pfreq = (u32 *)of_get_property(pdev->dev.of_node, | 170 | pfreq = (u32 *)of_get_property(pdev->dev.of_node, |
165 | "clock-frequency", NULL); | 171 | "clock-frequency", NULL); |
166 | 172 | ||
@@ -169,12 +175,6 @@ static int xwdt_probe(struct platform_device *pdev) | |||
169 | no_timeout = 1; | 175 | no_timeout = 1; |
170 | } | 176 | } |
171 | 177 | ||
172 | rc = of_address_to_resource(pdev->dev.of_node, 0, &xdev.res); | ||
173 | if (rc) { | ||
174 | pr_warn("invalid address!\n"); | ||
175 | return rc; | ||
176 | } | ||
177 | |||
178 | tmptr = (u32 *)of_get_property(pdev->dev.of_node, | 178 | tmptr = (u32 *)of_get_property(pdev->dev.of_node, |
179 | "xlnx,wdt-interval", NULL); | 179 | "xlnx,wdt-interval", NULL); |
180 | if (tmptr == NULL) { | 180 | if (tmptr == NULL) { |
@@ -198,50 +198,27 @@ static int xwdt_probe(struct platform_device *pdev) | |||
198 | if (!no_timeout) | 198 | if (!no_timeout) |
199 | timeout = 2 * ((1<<xdev.wdt_interval) / *pfreq); | 199 | timeout = 2 * ((1<<xdev.wdt_interval) / *pfreq); |
200 | 200 | ||
201 | if (!request_mem_region(xdev.res.start, | ||
202 | xdev.res.end - xdev.res.start + 1, WATCHDOG_NAME)) { | ||
203 | rc = -ENXIO; | ||
204 | pr_err("memory request failure!\n"); | ||
205 | goto err_out; | ||
206 | } | ||
207 | |||
208 | xdev.base = ioremap(xdev.res.start, xdev.res.end - xdev.res.start + 1); | ||
209 | if (xdev.base == NULL) { | ||
210 | rc = -ENOMEM; | ||
211 | pr_err("ioremap failure!\n"); | ||
212 | goto release_mem; | ||
213 | } | ||
214 | |||
215 | rc = xwdt_selftest(); | 201 | rc = xwdt_selftest(); |
216 | if (rc == XWT_TIMER_FAILED) { | 202 | if (rc == XWT_TIMER_FAILED) { |
217 | pr_err("SelfTest routine error!\n"); | 203 | pr_err("SelfTest routine error!\n"); |
218 | goto unmap_io; | 204 | return rc; |
219 | } | 205 | } |
220 | 206 | ||
221 | rc = watchdog_register_device(&xilinx_wdt_wdd); | 207 | rc = watchdog_register_device(&xilinx_wdt_wdd); |
222 | if (rc) { | 208 | if (rc) { |
223 | pr_err("cannot register watchdog (err=%d)\n", rc); | 209 | pr_err("cannot register watchdog (err=%d)\n", rc); |
224 | goto unmap_io; | 210 | return rc; |
225 | } | 211 | } |
226 | 212 | ||
227 | dev_info(&pdev->dev, "Xilinx Watchdog Timer at %p with timeout %ds\n", | 213 | dev_info(&pdev->dev, "Xilinx Watchdog Timer at %p with timeout %ds\n", |
228 | xdev.base, timeout); | 214 | xdev.base, timeout); |
229 | 215 | ||
230 | return 0; | 216 | return 0; |
231 | |||
232 | unmap_io: | ||
233 | iounmap(xdev.base); | ||
234 | release_mem: | ||
235 | release_mem_region(xdev.res.start, resource_size(&xdev.res)); | ||
236 | err_out: | ||
237 | return rc; | ||
238 | } | 217 | } |
239 | 218 | ||
240 | static int xwdt_remove(struct platform_device *dev) | 219 | static int xwdt_remove(struct platform_device *dev) |
241 | { | 220 | { |
242 | watchdog_unregister_device(&xilinx_wdt_wdd); | 221 | watchdog_unregister_device(&xilinx_wdt_wdd); |
243 | iounmap(xdev.base); | ||
244 | release_mem_region(xdev.res.start, resource_size(&xdev.res)); | ||
245 | 222 | ||
246 | return 0; | 223 | return 0; |
247 | } | 224 | } |