diff options
Diffstat (limited to 'drivers/rtc/rtc-jz4740.c')
-rw-r--r-- | drivers/rtc/rtc-jz4740.c | 68 |
1 files changed, 16 insertions, 52 deletions
diff --git a/drivers/rtc/rtc-jz4740.c b/drivers/rtc/rtc-jz4740.c index 1e48686ca6d2..1b126d2513de 100644 --- a/drivers/rtc/rtc-jz4740.c +++ b/drivers/rtc/rtc-jz4740.c | |||
@@ -14,6 +14,7 @@ | |||
14 | * | 14 | * |
15 | */ | 15 | */ |
16 | 16 | ||
17 | #include <linux/io.h> | ||
17 | #include <linux/kernel.h> | 18 | #include <linux/kernel.h> |
18 | #include <linux/module.h> | 19 | #include <linux/module.h> |
19 | #include <linux/platform_device.h> | 20 | #include <linux/platform_device.h> |
@@ -216,37 +217,34 @@ static int jz4740_rtc_probe(struct platform_device *pdev) | |||
216 | struct jz4740_rtc *rtc; | 217 | struct jz4740_rtc *rtc; |
217 | uint32_t scratchpad; | 218 | uint32_t scratchpad; |
218 | 219 | ||
219 | rtc = kzalloc(sizeof(*rtc), GFP_KERNEL); | 220 | rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); |
220 | if (!rtc) | 221 | if (!rtc) |
221 | return -ENOMEM; | 222 | return -ENOMEM; |
222 | 223 | ||
223 | rtc->irq = platform_get_irq(pdev, 0); | 224 | rtc->irq = platform_get_irq(pdev, 0); |
224 | if (rtc->irq < 0) { | 225 | if (rtc->irq < 0) { |
225 | ret = -ENOENT; | ||
226 | dev_err(&pdev->dev, "Failed to get platform irq\n"); | 226 | dev_err(&pdev->dev, "Failed to get platform irq\n"); |
227 | goto err_free; | 227 | return -ENOENT; |
228 | } | 228 | } |
229 | 229 | ||
230 | rtc->mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 230 | rtc->mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
231 | if (!rtc->mem) { | 231 | if (!rtc->mem) { |
232 | ret = -ENOENT; | ||
233 | dev_err(&pdev->dev, "Failed to get platform mmio memory\n"); | 232 | dev_err(&pdev->dev, "Failed to get platform mmio memory\n"); |
234 | goto err_free; | 233 | return -ENOENT; |
235 | } | 234 | } |
236 | 235 | ||
237 | rtc->mem = request_mem_region(rtc->mem->start, resource_size(rtc->mem), | 236 | rtc->mem = devm_request_mem_region(&pdev->dev, rtc->mem->start, |
238 | pdev->name); | 237 | resource_size(rtc->mem), pdev->name); |
239 | if (!rtc->mem) { | 238 | if (!rtc->mem) { |
240 | ret = -EBUSY; | ||
241 | dev_err(&pdev->dev, "Failed to request mmio memory region\n"); | 239 | dev_err(&pdev->dev, "Failed to request mmio memory region\n"); |
242 | goto err_free; | 240 | return -EBUSY; |
243 | } | 241 | } |
244 | 242 | ||
245 | rtc->base = ioremap_nocache(rtc->mem->start, resource_size(rtc->mem)); | 243 | rtc->base = devm_ioremap_nocache(&pdev->dev, rtc->mem->start, |
244 | resource_size(rtc->mem)); | ||
246 | if (!rtc->base) { | 245 | if (!rtc->base) { |
247 | ret = -EBUSY; | ||
248 | dev_err(&pdev->dev, "Failed to ioremap mmio memory\n"); | 246 | dev_err(&pdev->dev, "Failed to ioremap mmio memory\n"); |
249 | goto err_release_mem_region; | 247 | return -EBUSY; |
250 | } | 248 | } |
251 | 249 | ||
252 | spin_lock_init(&rtc->lock); | 250 | spin_lock_init(&rtc->lock); |
@@ -255,19 +253,19 @@ static int jz4740_rtc_probe(struct platform_device *pdev) | |||
255 | 253 | ||
256 | device_init_wakeup(&pdev->dev, 1); | 254 | device_init_wakeup(&pdev->dev, 1); |
257 | 255 | ||
258 | rtc->rtc = rtc_device_register(pdev->name, &pdev->dev, &jz4740_rtc_ops, | 256 | rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, |
259 | THIS_MODULE); | 257 | &jz4740_rtc_ops, THIS_MODULE); |
260 | if (IS_ERR(rtc->rtc)) { | 258 | if (IS_ERR(rtc->rtc)) { |
261 | ret = PTR_ERR(rtc->rtc); | 259 | ret = PTR_ERR(rtc->rtc); |
262 | dev_err(&pdev->dev, "Failed to register rtc device: %d\n", ret); | 260 | dev_err(&pdev->dev, "Failed to register rtc device: %d\n", ret); |
263 | goto err_iounmap; | 261 | return ret; |
264 | } | 262 | } |
265 | 263 | ||
266 | ret = request_irq(rtc->irq, jz4740_rtc_irq, 0, | 264 | ret = devm_request_irq(&pdev->dev, rtc->irq, jz4740_rtc_irq, 0, |
267 | pdev->name, rtc); | 265 | pdev->name, rtc); |
268 | if (ret) { | 266 | if (ret) { |
269 | dev_err(&pdev->dev, "Failed to request rtc irq: %d\n", ret); | 267 | dev_err(&pdev->dev, "Failed to request rtc irq: %d\n", ret); |
270 | goto err_unregister_rtc; | 268 | return ret; |
271 | } | 269 | } |
272 | 270 | ||
273 | scratchpad = jz4740_rtc_reg_read(rtc, JZ_REG_RTC_SCRATCHPAD); | 271 | scratchpad = jz4740_rtc_reg_read(rtc, JZ_REG_RTC_SCRATCHPAD); |
@@ -276,46 +274,13 @@ static int jz4740_rtc_probe(struct platform_device *pdev) | |||
276 | ret = jz4740_rtc_reg_write(rtc, JZ_REG_RTC_SEC, 0); | 274 | ret = jz4740_rtc_reg_write(rtc, JZ_REG_RTC_SEC, 0); |
277 | if (ret) { | 275 | if (ret) { |
278 | dev_err(&pdev->dev, "Could not write write to RTC registers\n"); | 276 | dev_err(&pdev->dev, "Could not write write to RTC registers\n"); |
279 | goto err_free_irq; | 277 | return ret; |
280 | } | 278 | } |
281 | } | 279 | } |
282 | 280 | ||
283 | return 0; | 281 | return 0; |
284 | |||
285 | err_free_irq: | ||
286 | free_irq(rtc->irq, rtc); | ||
287 | err_unregister_rtc: | ||
288 | rtc_device_unregister(rtc->rtc); | ||
289 | err_iounmap: | ||
290 | platform_set_drvdata(pdev, NULL); | ||
291 | iounmap(rtc->base); | ||
292 | err_release_mem_region: | ||
293 | release_mem_region(rtc->mem->start, resource_size(rtc->mem)); | ||
294 | err_free: | ||
295 | kfree(rtc); | ||
296 | |||
297 | return ret; | ||
298 | } | ||
299 | |||
300 | static int jz4740_rtc_remove(struct platform_device *pdev) | ||
301 | { | ||
302 | struct jz4740_rtc *rtc = platform_get_drvdata(pdev); | ||
303 | |||
304 | free_irq(rtc->irq, rtc); | ||
305 | |||
306 | rtc_device_unregister(rtc->rtc); | ||
307 | |||
308 | iounmap(rtc->base); | ||
309 | release_mem_region(rtc->mem->start, resource_size(rtc->mem)); | ||
310 | |||
311 | kfree(rtc); | ||
312 | |||
313 | platform_set_drvdata(pdev, NULL); | ||
314 | |||
315 | return 0; | ||
316 | } | 282 | } |
317 | 283 | ||
318 | |||
319 | #ifdef CONFIG_PM | 284 | #ifdef CONFIG_PM |
320 | static int jz4740_rtc_suspend(struct device *dev) | 285 | static int jz4740_rtc_suspend(struct device *dev) |
321 | { | 286 | { |
@@ -347,7 +312,6 @@ static const struct dev_pm_ops jz4740_pm_ops = { | |||
347 | 312 | ||
348 | static struct platform_driver jz4740_rtc_driver = { | 313 | static struct platform_driver jz4740_rtc_driver = { |
349 | .probe = jz4740_rtc_probe, | 314 | .probe = jz4740_rtc_probe, |
350 | .remove = jz4740_rtc_remove, | ||
351 | .driver = { | 315 | .driver = { |
352 | .name = "jz4740-rtc", | 316 | .name = "jz4740-rtc", |
353 | .owner = THIS_MODULE, | 317 | .owner = THIS_MODULE, |