aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/rtc')
-rw-r--r--drivers/rtc/Kconfig4
-rw-r--r--drivers/rtc/class.c70
-rw-r--r--drivers/rtc/rtc-88pm80x.c5
-rw-r--r--drivers/rtc/rtc-88pm860x.c29
-rw-r--r--drivers/rtc/rtc-ab3100.c21
-rw-r--r--drivers/rtc/rtc-ab8500.c18
-rw-r--r--drivers/rtc/rtc-at32ap700x.c39
-rw-r--r--drivers/rtc/rtc-at91rm9200.c50
-rw-r--r--drivers/rtc/rtc-at91sam9.c57
-rw-r--r--drivers/rtc/rtc-au1xxx.c18
-rw-r--r--drivers/rtc/rtc-bfin.c34
-rw-r--r--drivers/rtc/rtc-bq32k.c5
-rw-r--r--drivers/rtc/rtc-bq4802.c29
-rw-r--r--drivers/rtc/rtc-cmos.c4
-rw-r--r--drivers/rtc/rtc-coh901331.c42
-rw-r--r--drivers/rtc/rtc-da9052.c13
-rw-r--r--drivers/rtc/rtc-da9055.c5
-rw-r--r--drivers/rtc/rtc-davinci.c24
-rw-r--r--drivers/rtc/rtc-dm355evm.c7
-rw-r--r--drivers/rtc/rtc-ds1216.c44
-rw-r--r--drivers/rtc/rtc-ds1286.c49
-rw-r--r--drivers/rtc/rtc-ds1302.c22
-rw-r--r--drivers/rtc/rtc-ds1305.c35
-rw-r--r--drivers/rtc/rtc-ds1307.c74
-rw-r--r--drivers/rtc/rtc-ds1374.c35
-rw-r--r--drivers/rtc/rtc-ds1390.c15
-rw-r--r--drivers/rtc/rtc-ds1511.c8
-rw-r--r--drivers/rtc/rtc-ds1553.c6
-rw-r--r--drivers/rtc/rtc-ds1672.c8
-rw-r--r--drivers/rtc/rtc-ds1742.c8
-rw-r--r--drivers/rtc/rtc-ds2404.c12
-rw-r--r--drivers/rtc/rtc-ds3232.c25
-rw-r--r--drivers/rtc/rtc-ds3234.c9
-rw-r--r--drivers/rtc/rtc-efi.c19
-rw-r--r--drivers/rtc/rtc-em3027.c7
-rw-r--r--drivers/rtc/rtc-ep93xx.c11
-rw-r--r--drivers/rtc/rtc-fm3130.c11
-rw-r--r--drivers/rtc/rtc-generic.c21
-rw-r--r--drivers/rtc/rtc-hid-sensor-time.c7
-rw-r--r--drivers/rtc/rtc-imxdi.c23
-rw-r--r--drivers/rtc/rtc-isl12022.c30
-rw-r--r--drivers/rtc/rtc-lp8788.c5
-rw-r--r--drivers/rtc/rtc-lpc32xx.c5
-rw-r--r--drivers/rtc/rtc-ls1x.c5
-rw-r--r--drivers/rtc/rtc-m41t80.c16
-rw-r--r--drivers/rtc/rtc-m41t93.c11
-rw-r--r--drivers/rtc/rtc-m41t94.c11
-rw-r--r--drivers/rtc/rtc-m48t35.c42
-rw-r--r--drivers/rtc/rtc-m48t86.c11
-rw-r--r--drivers/rtc/rtc-max6900.c9
-rw-r--r--drivers/rtc/rtc-max6902.c29
-rw-r--r--drivers/rtc/rtc-max77686.c73
-rw-r--r--drivers/rtc/rtc-max8907.c20
-rw-r--r--drivers/rtc/rtc-max8925.c26
-rw-r--r--drivers/rtc/rtc-max8997.c19
-rw-r--r--drivers/rtc/rtc-max8998.c18
-rw-r--r--drivers/rtc/rtc-mc13xxx.c23
-rw-r--r--drivers/rtc/rtc-msm6242.c45
-rw-r--r--drivers/rtc/rtc-mv.c51
-rw-r--r--drivers/rtc/rtc-mxc.c15
-rw-r--r--drivers/rtc/rtc-nuc900.c72
-rw-r--r--drivers/rtc/rtc-omap.c81
-rw-r--r--drivers/rtc/rtc-palmas.c19
-rw-r--r--drivers/rtc/rtc-pcap.c53
-rw-r--r--drivers/rtc/rtc-pcf2123.c12
-rw-r--r--drivers/rtc/rtc-pcf50633.c15
-rw-r--r--drivers/rtc/rtc-pcf8523.c6
-rw-r--r--drivers/rtc/rtc-pcf8563.c28
-rw-r--r--drivers/rtc/rtc-pcf8583.c24
-rw-r--r--drivers/rtc/rtc-proc.c2
-rw-r--r--drivers/rtc/rtc-ps3.c16
-rw-r--r--drivers/rtc/rtc-puv3.c27
-rw-r--r--drivers/rtc/rtc-pxa.c24
-rw-r--r--drivers/rtc/rtc-r9701.c9
-rw-r--r--drivers/rtc/rtc-rc5t583.c19
-rw-r--r--drivers/rtc/rtc-rp5c01.c39
-rw-r--r--drivers/rtc/rtc-rs5c313.c6
-rw-r--r--drivers/rtc/rtc-rs5c348.c12
-rw-r--r--drivers/rtc/rtc-rs5c372.c35
-rw-r--r--drivers/rtc/rtc-rv3029c2.c16
-rw-r--r--drivers/rtc/rtc-rx4581.c9
-rw-r--r--drivers/rtc/rtc-rx8581.c8
-rw-r--r--drivers/rtc/rtc-s35390a.c14
-rw-r--r--drivers/rtc/rtc-s3c.c40
-rw-r--r--drivers/rtc/rtc-s3c.h70
-rw-r--r--drivers/rtc/rtc-sa1100.c29
-rw-r--r--drivers/rtc/rtc-sh.c22
-rw-r--r--drivers/rtc/rtc-snvs.c6
-rw-r--r--drivers/rtc/rtc-spear.c23
-rw-r--r--drivers/rtc/rtc-starfire.c23
-rw-r--r--drivers/rtc/rtc-stk17ta8.c6
-rw-r--r--drivers/rtc/rtc-stmp3xxx.c57
-rw-r--r--drivers/rtc/rtc-sun4v.c22
-rw-r--r--drivers/rtc/rtc-tegra.c64
-rw-r--r--drivers/rtc/rtc-test.c10
-rw-r--r--drivers/rtc/rtc-tile.c9
-rw-r--r--drivers/rtc/rtc-tps6586x.c14
-rw-r--r--drivers/rtc/rtc-tps65910.c13
-rw-r--r--drivers/rtc/rtc-tps80031.c11
-rw-r--r--drivers/rtc/rtc-twl.c16
-rw-r--r--drivers/rtc/rtc-tx4939.c19
-rw-r--r--drivers/rtc/rtc-v3020.c13
-rw-r--r--drivers/rtc/rtc-vt8500.c8
-rw-r--r--drivers/rtc/rtc-wm831x.c6
-rw-r--r--drivers/rtc/rtc-wm8350.c19
-rw-r--r--drivers/rtc/rtc-x1205.c14
106 files changed, 863 insertions, 1584 deletions
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 79fbe3832dfc..0c81915b1997 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -402,7 +402,7 @@ config RTC_DRV_TPS6586X
402 tristate "TI TPS6586X RTC driver" 402 tristate "TI TPS6586X RTC driver"
403 depends on MFD_TPS6586X 403 depends on MFD_TPS6586X
404 help 404 help
405 TI Power Managment IC TPS6586X supports RTC functionality 405 TI Power Management IC TPS6586X supports RTC functionality
406 along with alarm. This driver supports the RTC driver for 406 along with alarm. This driver supports the RTC driver for
407 the TPS6586X RTC module. 407 the TPS6586X RTC module.
408 408
@@ -420,7 +420,7 @@ config RTC_DRV_TPS80031
420 tristate "TI TPS80031/TPS80032 RTC driver" 420 tristate "TI TPS80031/TPS80032 RTC driver"
421 depends on MFD_TPS80031 421 depends on MFD_TPS80031
422 help 422 help
423 TI Power Managment IC TPS80031 supports RTC functionality 423 TI Power Management IC TPS80031 supports RTC functionality
424 along with alarm. This driver supports the RTC driver for 424 along with alarm. This driver supports the RTC driver for
425 the TPS80031 RTC module. 425 the TPS80031 RTC module.
426 426
diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
index 9b742d3ffb94..66385402d20e 100644
--- a/drivers/rtc/class.c
+++ b/drivers/rtc/class.c
@@ -259,6 +259,76 @@ void rtc_device_unregister(struct rtc_device *rtc)
259} 259}
260EXPORT_SYMBOL_GPL(rtc_device_unregister); 260EXPORT_SYMBOL_GPL(rtc_device_unregister);
261 261
262static void devm_rtc_device_release(struct device *dev, void *res)
263{
264 struct rtc_device *rtc = *(struct rtc_device **)res;
265
266 rtc_device_unregister(rtc);
267}
268
269static int devm_rtc_device_match(struct device *dev, void *res, void *data)
270{
271 struct rtc **r = res;
272
273 return *r == data;
274}
275
276/**
277 * devm_rtc_device_register - resource managed rtc_device_register()
278 * @dev: the device to register
279 * @name: the name of the device
280 * @ops: the rtc operations structure
281 * @owner: the module owner
282 *
283 * @return a struct rtc on success, or an ERR_PTR on error
284 *
285 * Managed rtc_device_register(). The rtc_device returned from this function
286 * are automatically freed on driver detach. See rtc_device_register()
287 * for more information.
288 */
289
290struct rtc_device *devm_rtc_device_register(struct device *dev,
291 const char *name,
292 const struct rtc_class_ops *ops,
293 struct module *owner)
294{
295 struct rtc_device **ptr, *rtc;
296
297 ptr = devres_alloc(devm_rtc_device_release, sizeof(*ptr), GFP_KERNEL);
298 if (!ptr)
299 return ERR_PTR(-ENOMEM);
300
301 rtc = rtc_device_register(name, dev, ops, owner);
302 if (!IS_ERR(rtc)) {
303 *ptr = rtc;
304 devres_add(dev, ptr);
305 } else {
306 devres_free(ptr);
307 }
308
309 return rtc;
310}
311EXPORT_SYMBOL_GPL(devm_rtc_device_register);
312
313/**
314 * devm_rtc_device_unregister - resource managed devm_rtc_device_unregister()
315 * @dev: the device to unregister
316 * @rtc: the RTC class device to unregister
317 *
318 * Deallocated a rtc allocated with devm_rtc_device_register(). Normally this
319 * function will not need to be called and the resource management code will
320 * ensure that the resource is freed.
321 */
322void devm_rtc_device_unregister(struct device *dev, struct rtc_device *rtc)
323{
324 int rc;
325
326 rc = devres_release(dev, devm_rtc_device_release,
327 devm_rtc_device_match, rtc);
328 WARN_ON(rc);
329}
330EXPORT_SYMBOL_GPL(devm_rtc_device_unregister);
331
262static int __init rtc_init(void) 332static int __init rtc_init(void)
263{ 333{
264 rtc_class = class_create(THIS_MODULE, "rtc"); 334 rtc_class = class_create(THIS_MODULE, "rtc");
diff --git a/drivers/rtc/rtc-88pm80x.c b/drivers/rtc/rtc-88pm80x.c
index 63b17ebe90e8..f3742f364eb8 100644
--- a/drivers/rtc/rtc-88pm80x.c
+++ b/drivers/rtc/rtc-88pm80x.c
@@ -234,7 +234,7 @@ static const struct rtc_class_ops pm80x_rtc_ops = {
234 .alarm_irq_enable = pm80x_rtc_alarm_irq_enable, 234 .alarm_irq_enable = pm80x_rtc_alarm_irq_enable,
235}; 235};
236 236
237#ifdef CONFIG_PM 237#ifdef CONFIG_PM_SLEEP
238static int pm80x_rtc_suspend(struct device *dev) 238static int pm80x_rtc_suspend(struct device *dev)
239{ 239{
240 return pm80x_dev_suspend(dev); 240 return pm80x_dev_suspend(dev);
@@ -312,7 +312,7 @@ static int pm80x_rtc_probe(struct platform_device *pdev)
312 } 312 }
313 rtc_tm_to_time(&tm, &ticks); 313 rtc_tm_to_time(&tm, &ticks);
314 314
315 info->rtc_dev = rtc_device_register("88pm80x-rtc", &pdev->dev, 315 info->rtc_dev = devm_rtc_device_register(&pdev->dev, "88pm80x-rtc",
316 &pm80x_rtc_ops, THIS_MODULE); 316 &pm80x_rtc_ops, THIS_MODULE);
317 if (IS_ERR(info->rtc_dev)) { 317 if (IS_ERR(info->rtc_dev)) {
318 ret = PTR_ERR(info->rtc_dev); 318 ret = PTR_ERR(info->rtc_dev);
@@ -346,7 +346,6 @@ static int pm80x_rtc_remove(struct platform_device *pdev)
346{ 346{
347 struct pm80x_rtc_info *info = platform_get_drvdata(pdev); 347 struct pm80x_rtc_info *info = platform_get_drvdata(pdev);
348 platform_set_drvdata(pdev, NULL); 348 platform_set_drvdata(pdev, NULL);
349 rtc_device_unregister(info->rtc_dev);
350 pm80x_free_irq(info->chip, info->irq, info); 349 pm80x_free_irq(info->chip, info->irq, info);
351 return 0; 350 return 0;
352} 351}
diff --git a/drivers/rtc/rtc-88pm860x.c b/drivers/rtc/rtc-88pm860x.c
index f663746f4603..0f2b91bfee37 100644
--- a/drivers/rtc/rtc-88pm860x.c
+++ b/drivers/rtc/rtc-88pm860x.c
@@ -318,14 +318,14 @@ static int pm860x_rtc_probe(struct platform_device *pdev)
318 318
319 pdata = pdev->dev.platform_data; 319 pdata = pdev->dev.platform_data;
320 320
321 info = kzalloc(sizeof(struct pm860x_rtc_info), GFP_KERNEL); 321 info = devm_kzalloc(&pdev->dev, sizeof(struct pm860x_rtc_info),
322 GFP_KERNEL);
322 if (!info) 323 if (!info)
323 return -ENOMEM; 324 return -ENOMEM;
324 info->irq = platform_get_irq(pdev, 0); 325 info->irq = platform_get_irq(pdev, 0);
325 if (info->irq < 0) { 326 if (info->irq < 0) {
326 dev_err(&pdev->dev, "No IRQ resource!\n"); 327 dev_err(&pdev->dev, "No IRQ resource!\n");
327 ret = -EINVAL; 328 return info->irq;
328 goto out;
329 } 329 }
330 330
331 info->chip = chip; 331 info->chip = chip;
@@ -333,12 +333,13 @@ static int pm860x_rtc_probe(struct platform_device *pdev)
333 info->dev = &pdev->dev; 333 info->dev = &pdev->dev;
334 dev_set_drvdata(&pdev->dev, info); 334 dev_set_drvdata(&pdev->dev, info);
335 335
336 ret = request_threaded_irq(info->irq, NULL, rtc_update_handler, 336 ret = devm_request_threaded_irq(&pdev->dev, info->irq, NULL,
337 IRQF_ONESHOT, "rtc", info); 337 rtc_update_handler, IRQF_ONESHOT, "rtc",
338 info);
338 if (ret < 0) { 339 if (ret < 0) {
339 dev_err(chip->dev, "Failed to request IRQ: #%d: %d\n", 340 dev_err(chip->dev, "Failed to request IRQ: #%d: %d\n",
340 info->irq, ret); 341 info->irq, ret);
341 goto out; 342 return ret;
342 } 343 }
343 344
344 /* set addresses of 32-bit base value for RTC time */ 345 /* set addresses of 32-bit base value for RTC time */
@@ -350,7 +351,7 @@ static int pm860x_rtc_probe(struct platform_device *pdev)
350 ret = pm860x_rtc_read_time(&pdev->dev, &tm); 351 ret = pm860x_rtc_read_time(&pdev->dev, &tm);
351 if (ret < 0) { 352 if (ret < 0) {
352 dev_err(&pdev->dev, "Failed to read initial time.\n"); 353 dev_err(&pdev->dev, "Failed to read initial time.\n");
353 goto out_rtc; 354 return ret;
354 } 355 }
355 if ((tm.tm_year < 70) || (tm.tm_year > 138)) { 356 if ((tm.tm_year < 70) || (tm.tm_year > 138)) {
356 tm.tm_year = 70; 357 tm.tm_year = 70;
@@ -362,7 +363,7 @@ static int pm860x_rtc_probe(struct platform_device *pdev)
362 ret = pm860x_rtc_set_time(&pdev->dev, &tm); 363 ret = pm860x_rtc_set_time(&pdev->dev, &tm);
363 if (ret < 0) { 364 if (ret < 0) {
364 dev_err(&pdev->dev, "Failed to set initial time.\n"); 365 dev_err(&pdev->dev, "Failed to set initial time.\n");
365 goto out_rtc; 366 return ret;
366 } 367 }
367 } 368 }
368 rtc_tm_to_time(&tm, &ticks); 369 rtc_tm_to_time(&tm, &ticks);
@@ -373,12 +374,12 @@ static int pm860x_rtc_probe(struct platform_device *pdev)
373 } 374 }
374 } 375 }
375 376
376 info->rtc_dev = rtc_device_register("88pm860x-rtc", &pdev->dev, 377 info->rtc_dev = devm_rtc_device_register(&pdev->dev, "88pm860x-rtc",
377 &pm860x_rtc_ops, THIS_MODULE); 378 &pm860x_rtc_ops, THIS_MODULE);
378 ret = PTR_ERR(info->rtc_dev); 379 ret = PTR_ERR(info->rtc_dev);
379 if (IS_ERR(info->rtc_dev)) { 380 if (IS_ERR(info->rtc_dev)) {
380 dev_err(&pdev->dev, "Failed to register RTC device: %d\n", ret); 381 dev_err(&pdev->dev, "Failed to register RTC device: %d\n", ret);
381 goto out_rtc; 382 return ret;
382 } 383 }
383 384
384 /* 385 /*
@@ -405,11 +406,6 @@ static int pm860x_rtc_probe(struct platform_device *pdev)
405 device_init_wakeup(&pdev->dev, 1); 406 device_init_wakeup(&pdev->dev, 1);
406 407
407 return 0; 408 return 0;
408out_rtc:
409 free_irq(info->irq, info);
410out:
411 kfree(info);
412 return ret;
413} 409}
414 410
415static int pm860x_rtc_remove(struct platform_device *pdev) 411static int pm860x_rtc_remove(struct platform_device *pdev)
@@ -423,9 +419,6 @@ static int pm860x_rtc_remove(struct platform_device *pdev)
423#endif /* VRTC_CALIBRATION */ 419#endif /* VRTC_CALIBRATION */
424 420
425 platform_set_drvdata(pdev, NULL); 421 platform_set_drvdata(pdev, NULL);
426 rtc_device_unregister(info->rtc_dev);
427 free_irq(info->irq, info);
428 kfree(info);
429 return 0; 422 return 0;
430} 423}
431 424
diff --git a/drivers/rtc/rtc-ab3100.c b/drivers/rtc/rtc-ab3100.c
index 261a07e0fb24..47a4f2c4d30e 100644
--- a/drivers/rtc/rtc-ab3100.c
+++ b/drivers/rtc/rtc-ab3100.c
@@ -229,8 +229,8 @@ static int __init ab3100_rtc_probe(struct platform_device *pdev)
229 /* Ignore any error on this write */ 229 /* Ignore any error on this write */
230 } 230 }
231 231
232 rtc = rtc_device_register("ab3100-rtc", &pdev->dev, &ab3100_rtc_ops, 232 rtc = devm_rtc_device_register(&pdev->dev, "ab3100-rtc",
233 THIS_MODULE); 233 &ab3100_rtc_ops, THIS_MODULE);
234 if (IS_ERR(rtc)) { 234 if (IS_ERR(rtc)) {
235 err = PTR_ERR(rtc); 235 err = PTR_ERR(rtc);
236 return err; 236 return err;
@@ -242,9 +242,6 @@ static int __init ab3100_rtc_probe(struct platform_device *pdev)
242 242
243static int __exit ab3100_rtc_remove(struct platform_device *pdev) 243static int __exit ab3100_rtc_remove(struct platform_device *pdev)
244{ 244{
245 struct rtc_device *rtc = platform_get_drvdata(pdev);
246
247 rtc_device_unregister(rtc);
248 platform_set_drvdata(pdev, NULL); 245 platform_set_drvdata(pdev, NULL);
249 return 0; 246 return 0;
250} 247}
@@ -257,19 +254,7 @@ static struct platform_driver ab3100_rtc_driver = {
257 .remove = __exit_p(ab3100_rtc_remove), 254 .remove = __exit_p(ab3100_rtc_remove),
258}; 255};
259 256
260static int __init ab3100_rtc_init(void) 257module_platform_driver_probe(ab3100_rtc_driver, ab3100_rtc_probe);
261{
262 return platform_driver_probe(&ab3100_rtc_driver,
263 ab3100_rtc_probe);
264}
265
266static void __exit ab3100_rtc_exit(void)
267{
268 platform_driver_unregister(&ab3100_rtc_driver);
269}
270
271module_init(ab3100_rtc_init);
272module_exit(ab3100_rtc_exit);
273 258
274MODULE_AUTHOR("Linus Walleij <linus.walleij@stericsson.com>"); 259MODULE_AUTHOR("Linus Walleij <linus.walleij@stericsson.com>");
275MODULE_DESCRIPTION("AB3100 RTC Driver"); 260MODULE_DESCRIPTION("AB3100 RTC Driver");
diff --git a/drivers/rtc/rtc-ab8500.c b/drivers/rtc/rtc-ab8500.c
index 57cde2b061e6..63cfa314a39f 100644
--- a/drivers/rtc/rtc-ab8500.c
+++ b/drivers/rtc/rtc-ab8500.c
@@ -422,20 +422,19 @@ static int ab8500_rtc_probe(struct platform_device *pdev)
422 422
423 device_init_wakeup(&pdev->dev, true); 423 device_init_wakeup(&pdev->dev, true);
424 424
425 rtc = rtc_device_register("ab8500-rtc", &pdev->dev, &ab8500_rtc_ops, 425 rtc = devm_rtc_device_register(&pdev->dev, "ab8500-rtc",
426 THIS_MODULE); 426 &ab8500_rtc_ops, THIS_MODULE);
427 if (IS_ERR(rtc)) { 427 if (IS_ERR(rtc)) {
428 dev_err(&pdev->dev, "Registration failed\n"); 428 dev_err(&pdev->dev, "Registration failed\n");
429 err = PTR_ERR(rtc); 429 err = PTR_ERR(rtc);
430 return err; 430 return err;
431 } 431 }
432 432
433 err = request_threaded_irq(irq, NULL, rtc_alarm_handler, 433 err = devm_request_threaded_irq(&pdev->dev, irq, NULL,
434 IRQF_NO_SUSPEND | IRQF_ONESHOT, "ab8500-rtc", rtc); 434 rtc_alarm_handler, IRQF_NO_SUSPEND | IRQF_ONESHOT,
435 if (err < 0) { 435 "ab8500-rtc", rtc);
436 rtc_device_unregister(rtc); 436 if (err < 0)
437 return err; 437 return err;
438 }
439 438
440 platform_set_drvdata(pdev, rtc); 439 platform_set_drvdata(pdev, rtc);
441 440
@@ -450,13 +449,8 @@ static int ab8500_rtc_probe(struct platform_device *pdev)
450 449
451static int ab8500_rtc_remove(struct platform_device *pdev) 450static int ab8500_rtc_remove(struct platform_device *pdev)
452{ 451{
453 struct rtc_device *rtc = platform_get_drvdata(pdev);
454 int irq = platform_get_irq_byname(pdev, "ALARM");
455
456 ab8500_sysfs_rtc_unregister(&pdev->dev); 452 ab8500_sysfs_rtc_unregister(&pdev->dev);
457 453
458 free_irq(irq, rtc);
459 rtc_device_unregister(rtc);
460 platform_set_drvdata(pdev, NULL); 454 platform_set_drvdata(pdev, NULL);
461 455
462 return 0; 456 return 0;
diff --git a/drivers/rtc/rtc-at32ap700x.c b/drivers/rtc/rtc-at32ap700x.c
index 8dd08305aae1..f47fbb5eee8b 100644
--- a/drivers/rtc/rtc-at32ap700x.c
+++ b/drivers/rtc/rtc-at32ap700x.c
@@ -202,7 +202,8 @@ static int __init at32_rtc_probe(struct platform_device *pdev)
202 int irq; 202 int irq;
203 int ret; 203 int ret;
204 204
205 rtc = kzalloc(sizeof(struct rtc_at32ap700x), GFP_KERNEL); 205 rtc = devm_kzalloc(&pdev->dev, sizeof(struct rtc_at32ap700x),
206 GFP_KERNEL);
206 if (!rtc) { 207 if (!rtc) {
207 dev_dbg(&pdev->dev, "out of memory\n"); 208 dev_dbg(&pdev->dev, "out of memory\n");
208 return -ENOMEM; 209 return -ENOMEM;
@@ -223,7 +224,7 @@ static int __init at32_rtc_probe(struct platform_device *pdev)
223 } 224 }
224 225
225 rtc->irq = irq; 226 rtc->irq = irq;
226 rtc->regs = ioremap(regs->start, resource_size(regs)); 227 rtc->regs = devm_ioremap(&pdev->dev, regs->start, resource_size(regs));
227 if (!rtc->regs) { 228 if (!rtc->regs) {
228 ret = -ENOMEM; 229 ret = -ENOMEM;
229 dev_dbg(&pdev->dev, "could not map I/O memory\n"); 230 dev_dbg(&pdev->dev, "could not map I/O memory\n");
@@ -244,20 +245,21 @@ static int __init at32_rtc_probe(struct platform_device *pdev)
244 | RTC_BIT(CTRL_EN)); 245 | RTC_BIT(CTRL_EN));
245 } 246 }
246 247
247 ret = request_irq(irq, at32_rtc_interrupt, IRQF_SHARED, "rtc", rtc); 248 ret = devm_request_irq(&pdev->dev, irq, at32_rtc_interrupt, IRQF_SHARED,
249 "rtc", rtc);
248 if (ret) { 250 if (ret) {
249 dev_dbg(&pdev->dev, "could not request irq %d\n", irq); 251 dev_dbg(&pdev->dev, "could not request irq %d\n", irq);
250 goto out_iounmap; 252 goto out;
251 } 253 }
252 254
253 platform_set_drvdata(pdev, rtc); 255 platform_set_drvdata(pdev, rtc);
254 256
255 rtc->rtc = rtc_device_register(pdev->name, &pdev->dev, 257 rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
256 &at32_rtc_ops, THIS_MODULE); 258 &at32_rtc_ops, THIS_MODULE);
257 if (IS_ERR(rtc->rtc)) { 259 if (IS_ERR(rtc->rtc)) {
258 dev_dbg(&pdev->dev, "could not register rtc device\n"); 260 dev_dbg(&pdev->dev, "could not register rtc device\n");
259 ret = PTR_ERR(rtc->rtc); 261 ret = PTR_ERR(rtc->rtc);
260 goto out_free_irq; 262 goto out;
261 } 263 }
262 264
263 device_init_wakeup(&pdev->dev, 1); 265 device_init_wakeup(&pdev->dev, 1);
@@ -267,26 +269,15 @@ static int __init at32_rtc_probe(struct platform_device *pdev)
267 269
268 return 0; 270 return 0;
269 271
270out_free_irq:
271 platform_set_drvdata(pdev, NULL);
272 free_irq(irq, rtc);
273out_iounmap:
274 iounmap(rtc->regs);
275out: 272out:
276 kfree(rtc); 273 platform_set_drvdata(pdev, NULL);
277 return ret; 274 return ret;
278} 275}
279 276
280static int __exit at32_rtc_remove(struct platform_device *pdev) 277static int __exit at32_rtc_remove(struct platform_device *pdev)
281{ 278{
282 struct rtc_at32ap700x *rtc = platform_get_drvdata(pdev);
283
284 device_init_wakeup(&pdev->dev, 0); 279 device_init_wakeup(&pdev->dev, 0);
285 280
286 free_irq(rtc->irq, rtc);
287 iounmap(rtc->regs);
288 rtc_device_unregister(rtc->rtc);
289 kfree(rtc);
290 platform_set_drvdata(pdev, NULL); 281 platform_set_drvdata(pdev, NULL);
291 282
292 return 0; 283 return 0;
@@ -302,17 +293,7 @@ static struct platform_driver at32_rtc_driver = {
302 }, 293 },
303}; 294};
304 295
305static int __init at32_rtc_init(void) 296module_platform_driver_probe(at32_rtc_driver, at32_rtc_probe);
306{
307 return platform_driver_probe(&at32_rtc_driver, at32_rtc_probe);
308}
309module_init(at32_rtc_init);
310
311static void __exit at32_rtc_exit(void)
312{
313 platform_driver_unregister(&at32_rtc_driver);
314}
315module_exit(at32_rtc_exit);
316 297
317MODULE_AUTHOR("Hans-Christian Egtvedt <hcegtvedt@atmel.com>"); 298MODULE_AUTHOR("Hans-Christian Egtvedt <hcegtvedt@atmel.com>");
318MODULE_DESCRIPTION("Real time clock for AVR32 AT32AP700x"); 299MODULE_DESCRIPTION("Real time clock for AVR32 AT32AP700x");
diff --git a/drivers/rtc/rtc-at91rm9200.c b/drivers/rtc/rtc-at91rm9200.c
index 434ebc3a99dc..0eab77b22340 100644
--- a/drivers/rtc/rtc-at91rm9200.c
+++ b/drivers/rtc/rtc-at91rm9200.c
@@ -28,6 +28,8 @@
28#include <linux/ioctl.h> 28#include <linux/ioctl.h>
29#include <linux/completion.h> 29#include <linux/completion.h>
30#include <linux/io.h> 30#include <linux/io.h>
31#include <linux/of.h>
32#include <linux/of_device.h>
31 33
32#include <asm/uaccess.h> 34#include <asm/uaccess.h>
33 35
@@ -297,7 +299,7 @@ static int __init at91_rtc_probe(struct platform_device *pdev)
297 "at91_rtc", pdev); 299 "at91_rtc", pdev);
298 if (ret) { 300 if (ret) {
299 dev_err(&pdev->dev, "IRQ %d already in use.\n", irq); 301 dev_err(&pdev->dev, "IRQ %d already in use.\n", irq);
300 return ret; 302 goto err_unmap;
301 } 303 }
302 304
303 /* cpu init code should really have flagged this device as 305 /* cpu init code should really have flagged this device as
@@ -309,13 +311,20 @@ static int __init at91_rtc_probe(struct platform_device *pdev)
309 rtc = rtc_device_register(pdev->name, &pdev->dev, 311 rtc = rtc_device_register(pdev->name, &pdev->dev,
310 &at91_rtc_ops, THIS_MODULE); 312 &at91_rtc_ops, THIS_MODULE);
311 if (IS_ERR(rtc)) { 313 if (IS_ERR(rtc)) {
312 free_irq(irq, pdev); 314 ret = PTR_ERR(rtc);
313 return PTR_ERR(rtc); 315 goto err_free_irq;
314 } 316 }
315 platform_set_drvdata(pdev, rtc); 317 platform_set_drvdata(pdev, rtc);
316 318
317 dev_info(&pdev->dev, "AT91 Real Time Clock driver.\n"); 319 dev_info(&pdev->dev, "AT91 Real Time Clock driver.\n");
318 return 0; 320 return 0;
321
322err_free_irq:
323 free_irq(irq, pdev);
324err_unmap:
325 iounmap(at91_rtc_regs);
326
327 return ret;
319} 328}
320 329
321/* 330/*
@@ -332,12 +341,13 @@ static int __exit at91_rtc_remove(struct platform_device *pdev)
332 free_irq(irq, pdev); 341 free_irq(irq, pdev);
333 342
334 rtc_device_unregister(rtc); 343 rtc_device_unregister(rtc);
344 iounmap(at91_rtc_regs);
335 platform_set_drvdata(pdev, NULL); 345 platform_set_drvdata(pdev, NULL);
336 346
337 return 0; 347 return 0;
338} 348}
339 349
340#ifdef CONFIG_PM 350#ifdef CONFIG_PM_SLEEP
341 351
342/* AT91RM9200 RTC Power management control */ 352/* AT91RM9200 RTC Power management control */
343 353
@@ -369,39 +379,27 @@ static int at91_rtc_resume(struct device *dev)
369 } 379 }
370 return 0; 380 return 0;
371} 381}
382#endif
372 383
373static const struct dev_pm_ops at91_rtc_pm = { 384static SIMPLE_DEV_PM_OPS(at91_rtc_pm_ops, at91_rtc_suspend, at91_rtc_resume);
374 .suspend = at91_rtc_suspend,
375 .resume = at91_rtc_resume,
376};
377
378#define at91_rtc_pm_ptr &at91_rtc_pm
379 385
380#else 386static const struct of_device_id at91_rtc_dt_ids[] = {
381#define at91_rtc_pm_ptr NULL 387 { .compatible = "atmel,at91rm9200-rtc" },
382#endif 388 { /* sentinel */ }
389};
390MODULE_DEVICE_TABLE(of, at91_rtc_dt_ids);
383 391
384static struct platform_driver at91_rtc_driver = { 392static struct platform_driver at91_rtc_driver = {
385 .remove = __exit_p(at91_rtc_remove), 393 .remove = __exit_p(at91_rtc_remove),
386 .driver = { 394 .driver = {
387 .name = "at91_rtc", 395 .name = "at91_rtc",
388 .owner = THIS_MODULE, 396 .owner = THIS_MODULE,
389 .pm = at91_rtc_pm_ptr, 397 .pm = &at91_rtc_pm_ops,
398 .of_match_table = of_match_ptr(at91_rtc_dt_ids),
390 }, 399 },
391}; 400};
392 401
393static int __init at91_rtc_init(void) 402module_platform_driver_probe(at91_rtc_driver, at91_rtc_probe);
394{
395 return platform_driver_probe(&at91_rtc_driver, at91_rtc_probe);
396}
397
398static void __exit at91_rtc_exit(void)
399{
400 platform_driver_unregister(&at91_rtc_driver);
401}
402
403module_init(at91_rtc_init);
404module_exit(at91_rtc_exit);
405 403
406MODULE_AUTHOR("Rick Bronson"); 404MODULE_AUTHOR("Rick Bronson");
407MODULE_DESCRIPTION("RTC driver for Atmel AT91RM9200"); 405MODULE_DESCRIPTION("RTC driver for Atmel AT91RM9200");
diff --git a/drivers/rtc/rtc-at91sam9.c b/drivers/rtc/rtc-at91sam9.c
index 39cfd2ee0042..b60a34cb145a 100644
--- a/drivers/rtc/rtc-at91sam9.c
+++ b/drivers/rtc/rtc-at91sam9.c
@@ -20,6 +20,7 @@
20#include <linux/ioctl.h> 20#include <linux/ioctl.h>
21#include <linux/slab.h> 21#include <linux/slab.h>
22#include <linux/platform_data/atmel.h> 22#include <linux/platform_data/atmel.h>
23#include <linux/io.h>
23 24
24#include <mach/at91_rtt.h> 25#include <mach/at91_rtt.h>
25#include <mach/cpu.h> 26#include <mach/cpu.h>
@@ -309,7 +310,7 @@ static int at91_rtc_probe(struct platform_device *pdev)
309 return irq; 310 return irq;
310 } 311 }
311 312
312 rtc = kzalloc(sizeof *rtc, GFP_KERNEL); 313 rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL);
313 if (!rtc) 314 if (!rtc)
314 return -ENOMEM; 315 return -ENOMEM;
315 316
@@ -320,18 +321,19 @@ static int at91_rtc_probe(struct platform_device *pdev)
320 device_init_wakeup(&pdev->dev, 1); 321 device_init_wakeup(&pdev->dev, 1);
321 322
322 platform_set_drvdata(pdev, rtc); 323 platform_set_drvdata(pdev, rtc);
323 rtc->rtt = ioremap(r->start, resource_size(r)); 324 rtc->rtt = devm_ioremap(&pdev->dev, r->start, resource_size(r));
324 if (!rtc->rtt) { 325 if (!rtc->rtt) {
325 dev_err(&pdev->dev, "failed to map registers, aborting.\n"); 326 dev_err(&pdev->dev, "failed to map registers, aborting.\n");
326 ret = -ENOMEM; 327 ret = -ENOMEM;
327 goto fail; 328 goto fail;
328 } 329 }
329 330
330 rtc->gpbr = ioremap(r_gpbr->start, resource_size(r_gpbr)); 331 rtc->gpbr = devm_ioremap(&pdev->dev, r_gpbr->start,
332 resource_size(r_gpbr));
331 if (!rtc->gpbr) { 333 if (!rtc->gpbr) {
332 dev_err(&pdev->dev, "failed to map gpbr registers, aborting.\n"); 334 dev_err(&pdev->dev, "failed to map gpbr registers, aborting.\n");
333 ret = -ENOMEM; 335 ret = -ENOMEM;
334 goto fail_gpbr; 336 goto fail;
335 } 337 }
336 338
337 mr = rtt_readl(rtc, MR); 339 mr = rtt_readl(rtc, MR);
@@ -346,20 +348,19 @@ static int at91_rtc_probe(struct platform_device *pdev)
346 mr &= ~(AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN); 348 mr &= ~(AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN);
347 rtt_writel(rtc, MR, mr); 349 rtt_writel(rtc, MR, mr);
348 350
349 rtc->rtcdev = rtc_device_register(pdev->name, &pdev->dev, 351 rtc->rtcdev = devm_rtc_device_register(&pdev->dev, pdev->name,
350 &at91_rtc_ops, THIS_MODULE); 352 &at91_rtc_ops, THIS_MODULE);
351 if (IS_ERR(rtc->rtcdev)) { 353 if (IS_ERR(rtc->rtcdev)) {
352 ret = PTR_ERR(rtc->rtcdev); 354 ret = PTR_ERR(rtc->rtcdev);
353 goto fail_register; 355 goto fail;
354 } 356 }
355 357
356 /* register irq handler after we know what name we'll use */ 358 /* register irq handler after we know what name we'll use */
357 ret = request_irq(rtc->irq, at91_rtc_interrupt, IRQF_SHARED, 359 ret = devm_request_irq(&pdev->dev, rtc->irq, at91_rtc_interrupt,
358 dev_name(&rtc->rtcdev->dev), rtc); 360 IRQF_SHARED, dev_name(&rtc->rtcdev->dev), rtc);
359 if (ret) { 361 if (ret) {
360 dev_dbg(&pdev->dev, "can't share IRQ %d?\n", rtc->irq); 362 dev_dbg(&pdev->dev, "can't share IRQ %d?\n", rtc->irq);
361 rtc_device_unregister(rtc->rtcdev); 363 goto fail;
362 goto fail_register;
363 } 364 }
364 365
365 /* NOTE: sam9260 rev A silicon has a ROM bug which resets the 366 /* NOTE: sam9260 rev A silicon has a ROM bug which resets the
@@ -374,13 +375,8 @@ static int at91_rtc_probe(struct platform_device *pdev)
374 375
375 return 0; 376 return 0;
376 377
377fail_register:
378 iounmap(rtc->gpbr);
379fail_gpbr:
380 iounmap(rtc->rtt);
381fail: 378fail:
382 platform_set_drvdata(pdev, NULL); 379 platform_set_drvdata(pdev, NULL);
383 kfree(rtc);
384 return ret; 380 return ret;
385} 381}
386 382
@@ -394,14 +390,8 @@ static int at91_rtc_remove(struct platform_device *pdev)
394 390
395 /* disable all interrupts */ 391 /* disable all interrupts */
396 rtt_writel(rtc, MR, mr & ~(AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN)); 392 rtt_writel(rtc, MR, mr & ~(AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN));
397 free_irq(rtc->irq, rtc);
398
399 rtc_device_unregister(rtc->rtcdev);
400 393
401 iounmap(rtc->gpbr);
402 iounmap(rtc->rtt);
403 platform_set_drvdata(pdev, NULL); 394 platform_set_drvdata(pdev, NULL);
404 kfree(rtc);
405 return 0; 395 return 0;
406} 396}
407 397
@@ -414,14 +404,13 @@ static void at91_rtc_shutdown(struct platform_device *pdev)
414 rtt_writel(rtc, MR, mr & ~rtc->imr); 404 rtt_writel(rtc, MR, mr & ~rtc->imr);
415} 405}
416 406
417#ifdef CONFIG_PM 407#ifdef CONFIG_PM_SLEEP
418 408
419/* AT91SAM9 RTC Power management control */ 409/* AT91SAM9 RTC Power management control */
420 410
421static int at91_rtc_suspend(struct platform_device *pdev, 411static int at91_rtc_suspend(struct device *dev)
422 pm_message_t state)
423{ 412{
424 struct sam9_rtc *rtc = platform_get_drvdata(pdev); 413 struct sam9_rtc *rtc = dev_get_drvdata(dev);
425 u32 mr = rtt_readl(rtc, MR); 414 u32 mr = rtt_readl(rtc, MR);
426 415
427 /* 416 /*
@@ -430,7 +419,7 @@ static int at91_rtc_suspend(struct platform_device *pdev,
430 */ 419 */
431 rtc->imr = mr & (AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN); 420 rtc->imr = mr & (AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN);
432 if (rtc->imr) { 421 if (rtc->imr) {
433 if (device_may_wakeup(&pdev->dev) && (mr & AT91_RTT_ALMIEN)) { 422 if (device_may_wakeup(dev) && (mr & AT91_RTT_ALMIEN)) {
434 enable_irq_wake(rtc->irq); 423 enable_irq_wake(rtc->irq);
435 /* don't let RTTINC cause wakeups */ 424 /* don't let RTTINC cause wakeups */
436 if (mr & AT91_RTT_RTTINCIEN) 425 if (mr & AT91_RTT_RTTINCIEN)
@@ -442,13 +431,13 @@ static int at91_rtc_suspend(struct platform_device *pdev,
442 return 0; 431 return 0;
443} 432}
444 433
445static int at91_rtc_resume(struct platform_device *pdev) 434static int at91_rtc_resume(struct device *dev)
446{ 435{
447 struct sam9_rtc *rtc = platform_get_drvdata(pdev); 436 struct sam9_rtc *rtc = dev_get_drvdata(dev);
448 u32 mr; 437 u32 mr;
449 438
450 if (rtc->imr) { 439 if (rtc->imr) {
451 if (device_may_wakeup(&pdev->dev)) 440 if (device_may_wakeup(dev))
452 disable_irq_wake(rtc->irq); 441 disable_irq_wake(rtc->irq);
453 mr = rtt_readl(rtc, MR); 442 mr = rtt_readl(rtc, MR);
454 rtt_writel(rtc, MR, mr | rtc->imr); 443 rtt_writel(rtc, MR, mr | rtc->imr);
@@ -456,20 +445,18 @@ static int at91_rtc_resume(struct platform_device *pdev)
456 445
457 return 0; 446 return 0;
458} 447}
459#else
460#define at91_rtc_suspend NULL
461#define at91_rtc_resume NULL
462#endif 448#endif
463 449
450static SIMPLE_DEV_PM_OPS(at91_rtc_pm_ops, at91_rtc_suspend, at91_rtc_resume);
451
464static struct platform_driver at91_rtc_driver = { 452static struct platform_driver at91_rtc_driver = {
465 .probe = at91_rtc_probe, 453 .probe = at91_rtc_probe,
466 .remove = at91_rtc_remove, 454 .remove = at91_rtc_remove,
467 .shutdown = at91_rtc_shutdown, 455 .shutdown = at91_rtc_shutdown,
468 .suspend = at91_rtc_suspend,
469 .resume = at91_rtc_resume,
470 .driver = { 456 .driver = {
471 .name = "rtc-at91sam9", 457 .name = "rtc-at91sam9",
472 .owner = THIS_MODULE, 458 .owner = THIS_MODULE,
459 .pm = &at91_rtc_pm_ops,
473 }, 460 },
474}; 461};
475 462
diff --git a/drivers/rtc/rtc-au1xxx.c b/drivers/rtc/rtc-au1xxx.c
index b309da4ec745..7995abc391fc 100644
--- a/drivers/rtc/rtc-au1xxx.c
+++ b/drivers/rtc/rtc-au1xxx.c
@@ -101,7 +101,7 @@ static int au1xtoy_rtc_probe(struct platform_device *pdev)
101 while (au_readl(SYS_COUNTER_CNTRL) & SYS_CNTRL_C0S) 101 while (au_readl(SYS_COUNTER_CNTRL) & SYS_CNTRL_C0S)
102 msleep(1); 102 msleep(1);
103 103
104 rtcdev = rtc_device_register("rtc-au1xxx", &pdev->dev, 104 rtcdev = devm_rtc_device_register(&pdev->dev, "rtc-au1xxx",
105 &au1xtoy_rtc_ops, THIS_MODULE); 105 &au1xtoy_rtc_ops, THIS_MODULE);
106 if (IS_ERR(rtcdev)) { 106 if (IS_ERR(rtcdev)) {
107 ret = PTR_ERR(rtcdev); 107 ret = PTR_ERR(rtcdev);
@@ -118,9 +118,6 @@ out_err:
118 118
119static int au1xtoy_rtc_remove(struct platform_device *pdev) 119static int au1xtoy_rtc_remove(struct platform_device *pdev)
120{ 120{
121 struct rtc_device *rtcdev = platform_get_drvdata(pdev);
122
123 rtc_device_unregister(rtcdev);
124 platform_set_drvdata(pdev, NULL); 121 platform_set_drvdata(pdev, NULL);
125 122
126 return 0; 123 return 0;
@@ -134,18 +131,7 @@ static struct platform_driver au1xrtc_driver = {
134 .remove = au1xtoy_rtc_remove, 131 .remove = au1xtoy_rtc_remove,
135}; 132};
136 133
137static int __init au1xtoy_rtc_init(void) 134module_platform_driver_probe(au1xrtc_driver, au1xtoy_rtc_probe);
138{
139 return platform_driver_probe(&au1xrtc_driver, au1xtoy_rtc_probe);
140}
141
142static void __exit au1xtoy_rtc_exit(void)
143{
144 platform_driver_unregister(&au1xrtc_driver);
145}
146
147module_init(au1xtoy_rtc_init);
148module_exit(au1xtoy_rtc_exit);
149 135
150MODULE_DESCRIPTION("Au1xxx TOY-counter-based RTC driver"); 136MODULE_DESCRIPTION("Au1xxx TOY-counter-based RTC driver");
151MODULE_AUTHOR("Manuel Lauss <manuel.lauss@gmail.com>"); 137MODULE_AUTHOR("Manuel Lauss <manuel.lauss@gmail.com>");
diff --git a/drivers/rtc/rtc-bfin.c b/drivers/rtc/rtc-bfin.c
index 4ec614b0954d..ad44ec5dc29a 100644
--- a/drivers/rtc/rtc-bfin.c
+++ b/drivers/rtc/rtc-bfin.c
@@ -352,14 +352,14 @@ static int bfin_rtc_probe(struct platform_device *pdev)
352 dev_dbg_stamp(dev); 352 dev_dbg_stamp(dev);
353 353
354 /* Allocate memory for our RTC struct */ 354 /* Allocate memory for our RTC struct */
355 rtc = kzalloc(sizeof(*rtc), GFP_KERNEL); 355 rtc = devm_kzalloc(dev, sizeof(*rtc), GFP_KERNEL);
356 if (unlikely(!rtc)) 356 if (unlikely(!rtc))
357 return -ENOMEM; 357 return -ENOMEM;
358 platform_set_drvdata(pdev, rtc); 358 platform_set_drvdata(pdev, rtc);
359 device_init_wakeup(dev, 1); 359 device_init_wakeup(dev, 1);
360 360
361 /* Register our RTC with the RTC framework */ 361 /* Register our RTC with the RTC framework */
362 rtc->rtc_dev = rtc_device_register(pdev->name, dev, &bfin_rtc_ops, 362 rtc->rtc_dev = devm_rtc_device_register(dev, pdev->name, &bfin_rtc_ops,
363 THIS_MODULE); 363 THIS_MODULE);
364 if (unlikely(IS_ERR(rtc->rtc_dev))) { 364 if (unlikely(IS_ERR(rtc->rtc_dev))) {
365 ret = PTR_ERR(rtc->rtc_dev); 365 ret = PTR_ERR(rtc->rtc_dev);
@@ -367,9 +367,10 @@ static int bfin_rtc_probe(struct platform_device *pdev)
367 } 367 }
368 368
369 /* Grab the IRQ and init the hardware */ 369 /* Grab the IRQ and init the hardware */
370 ret = request_irq(IRQ_RTC, bfin_rtc_interrupt, 0, pdev->name, dev); 370 ret = devm_request_irq(dev, IRQ_RTC, bfin_rtc_interrupt, 0,
371 pdev->name, dev);
371 if (unlikely(ret)) 372 if (unlikely(ret))
372 goto err_reg; 373 goto err;
373 /* sometimes the bootloader touched things, but the write complete was not 374 /* sometimes the bootloader touched things, but the write complete was not
374 * enabled, so let's just do a quick timeout here since the IRQ will not fire ... 375 * enabled, so let's just do a quick timeout here since the IRQ will not fire ...
375 */ 376 */
@@ -381,32 +382,23 @@ static int bfin_rtc_probe(struct platform_device *pdev)
381 382
382 return 0; 383 return 0;
383 384
384err_reg:
385 rtc_device_unregister(rtc->rtc_dev);
386err: 385err:
387 kfree(rtc);
388 return ret; 386 return ret;
389} 387}
390 388
391static int bfin_rtc_remove(struct platform_device *pdev) 389static int bfin_rtc_remove(struct platform_device *pdev)
392{ 390{
393 struct bfin_rtc *rtc = platform_get_drvdata(pdev);
394 struct device *dev = &pdev->dev; 391 struct device *dev = &pdev->dev;
395 392
396 bfin_rtc_reset(dev, 0); 393 bfin_rtc_reset(dev, 0);
397 free_irq(IRQ_RTC, dev);
398 rtc_device_unregister(rtc->rtc_dev);
399 platform_set_drvdata(pdev, NULL); 394 platform_set_drvdata(pdev, NULL);
400 kfree(rtc);
401 395
402 return 0; 396 return 0;
403} 397}
404 398
405#ifdef CONFIG_PM 399#ifdef CONFIG_PM_SLEEP
406static int bfin_rtc_suspend(struct platform_device *pdev, pm_message_t state) 400static int bfin_rtc_suspend(struct device *dev)
407{ 401{
408 struct device *dev = &pdev->dev;
409
410 dev_dbg_stamp(dev); 402 dev_dbg_stamp(dev);
411 403
412 if (device_may_wakeup(dev)) { 404 if (device_may_wakeup(dev)) {
@@ -418,10 +410,8 @@ static int bfin_rtc_suspend(struct platform_device *pdev, pm_message_t state)
418 return 0; 410 return 0;
419} 411}
420 412
421static int bfin_rtc_resume(struct platform_device *pdev) 413static int bfin_rtc_resume(struct device *dev)
422{ 414{
423 struct device *dev = &pdev->dev;
424
425 dev_dbg_stamp(dev); 415 dev_dbg_stamp(dev);
426 416
427 if (device_may_wakeup(dev)) 417 if (device_may_wakeup(dev))
@@ -440,20 +430,18 @@ static int bfin_rtc_resume(struct platform_device *pdev)
440 430
441 return 0; 431 return 0;
442} 432}
443#else
444# define bfin_rtc_suspend NULL
445# define bfin_rtc_resume NULL
446#endif 433#endif
447 434
435static SIMPLE_DEV_PM_OPS(bfin_rtc_pm_ops, bfin_rtc_suspend, bfin_rtc_resume);
436
448static struct platform_driver bfin_rtc_driver = { 437static struct platform_driver bfin_rtc_driver = {
449 .driver = { 438 .driver = {
450 .name = "rtc-bfin", 439 .name = "rtc-bfin",
451 .owner = THIS_MODULE, 440 .owner = THIS_MODULE,
441 .pm = &bfin_rtc_pm_ops,
452 }, 442 },
453 .probe = bfin_rtc_probe, 443 .probe = bfin_rtc_probe,
454 .remove = bfin_rtc_remove, 444 .remove = bfin_rtc_remove,
455 .suspend = bfin_rtc_suspend,
456 .resume = bfin_rtc_resume,
457}; 445};
458 446
459module_platform_driver(bfin_rtc_driver); 447module_platform_driver(bfin_rtc_driver);
diff --git a/drivers/rtc/rtc-bq32k.c b/drivers/rtc/rtc-bq32k.c
index 036cb89f8188..fea78bc713ca 100644
--- a/drivers/rtc/rtc-bq32k.c
+++ b/drivers/rtc/rtc-bq32k.c
@@ -153,7 +153,7 @@ static int bq32k_probe(struct i2c_client *client,
153 if (error) 153 if (error)
154 return error; 154 return error;
155 155
156 rtc = rtc_device_register(bq32k_driver.driver.name, &client->dev, 156 rtc = devm_rtc_device_register(&client->dev, bq32k_driver.driver.name,
157 &bq32k_rtc_ops, THIS_MODULE); 157 &bq32k_rtc_ops, THIS_MODULE);
158 if (IS_ERR(rtc)) 158 if (IS_ERR(rtc))
159 return PTR_ERR(rtc); 159 return PTR_ERR(rtc);
@@ -165,9 +165,6 @@ static int bq32k_probe(struct i2c_client *client,
165 165
166static int bq32k_remove(struct i2c_client *client) 166static int bq32k_remove(struct i2c_client *client)
167{ 167{
168 struct rtc_device *rtc = i2c_get_clientdata(client);
169
170 rtc_device_unregister(rtc);
171 return 0; 168 return 0;
172} 169}
173 170
diff --git a/drivers/rtc/rtc-bq4802.c b/drivers/rtc/rtc-bq4802.c
index 693be71b5b18..af2886784a7b 100644
--- a/drivers/rtc/rtc-bq4802.c
+++ b/drivers/rtc/rtc-bq4802.c
@@ -142,7 +142,7 @@ static const struct rtc_class_ops bq4802_ops = {
142 142
143static int bq4802_probe(struct platform_device *pdev) 143static int bq4802_probe(struct platform_device *pdev)
144{ 144{
145 struct bq4802 *p = kzalloc(sizeof(*p), GFP_KERNEL); 145 struct bq4802 *p = devm_kzalloc(&pdev->dev, sizeof(*p), GFP_KERNEL);
146 int err = -ENOMEM; 146 int err = -ENOMEM;
147 147
148 if (!p) 148 if (!p)
@@ -155,54 +155,41 @@ static int bq4802_probe(struct platform_device *pdev)
155 p->r = platform_get_resource(pdev, IORESOURCE_IO, 0); 155 p->r = platform_get_resource(pdev, IORESOURCE_IO, 0);
156 err = -EINVAL; 156 err = -EINVAL;
157 if (!p->r) 157 if (!p->r)
158 goto out_free; 158 goto out;
159 } 159 }
160 if (p->r->flags & IORESOURCE_IO) { 160 if (p->r->flags & IORESOURCE_IO) {
161 p->ioport = p->r->start; 161 p->ioport = p->r->start;
162 p->read = bq4802_read_io; 162 p->read = bq4802_read_io;
163 p->write = bq4802_write_io; 163 p->write = bq4802_write_io;
164 } else if (p->r->flags & IORESOURCE_MEM) { 164 } else if (p->r->flags & IORESOURCE_MEM) {
165 p->regs = ioremap(p->r->start, resource_size(p->r)); 165 p->regs = devm_ioremap(&pdev->dev, p->r->start,
166 resource_size(p->r));
166 p->read = bq4802_read_mem; 167 p->read = bq4802_read_mem;
167 p->write = bq4802_write_mem; 168 p->write = bq4802_write_mem;
168 } else { 169 } else {
169 err = -EINVAL; 170 err = -EINVAL;
170 goto out_free; 171 goto out;
171 } 172 }
172 173
173 platform_set_drvdata(pdev, p); 174 platform_set_drvdata(pdev, p);
174 175
175 p->rtc = rtc_device_register("bq4802", &pdev->dev, 176 p->rtc = devm_rtc_device_register(&pdev->dev, "bq4802",
176 &bq4802_ops, THIS_MODULE); 177 &bq4802_ops, THIS_MODULE);
177 if (IS_ERR(p->rtc)) { 178 if (IS_ERR(p->rtc)) {
178 err = PTR_ERR(p->rtc); 179 err = PTR_ERR(p->rtc);
179 goto out_iounmap; 180 goto out;
180 } 181 }
181 182
182 err = 0; 183 err = 0;
183out: 184out:
184 return err; 185 return err;
185 186
186out_iounmap:
187 if (p->r->flags & IORESOURCE_MEM)
188 iounmap(p->regs);
189out_free:
190 kfree(p);
191 goto out;
192} 187}
193 188
194static int bq4802_remove(struct platform_device *pdev) 189static int bq4802_remove(struct platform_device *pdev)
195{ 190{
196 struct bq4802 *p = platform_get_drvdata(pdev);
197
198 rtc_device_unregister(p->rtc);
199 if (p->r->flags & IORESOURCE_MEM)
200 iounmap(p->regs);
201
202 platform_set_drvdata(pdev, NULL); 191 platform_set_drvdata(pdev, NULL);
203 192
204 kfree(p);
205
206 return 0; 193 return 0;
207} 194}
208 195
diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
index af97c94e8a3a..cc5bea9c4b1c 100644
--- a/drivers/rtc/rtc-cmos.c
+++ b/drivers/rtc/rtc-cmos.c
@@ -804,9 +804,8 @@ static int cmos_suspend(struct device *dev)
804 mask = RTC_IRQMASK; 804 mask = RTC_IRQMASK;
805 tmp &= ~mask; 805 tmp &= ~mask;
806 CMOS_WRITE(tmp, RTC_CONTROL); 806 CMOS_WRITE(tmp, RTC_CONTROL);
807 hpet_mask_rtc_irq_bit(mask);
807 808
808 /* shut down hpet emulation - we don't need it for alarm */
809 hpet_mask_rtc_irq_bit(RTC_PIE|RTC_AIE|RTC_UIE);
810 cmos_checkintr(cmos, tmp); 809 cmos_checkintr(cmos, tmp);
811 } 810 }
812 spin_unlock_irq(&rtc_lock); 811 spin_unlock_irq(&rtc_lock);
@@ -870,6 +869,7 @@ static int cmos_resume(struct device *dev)
870 rtc_update_irq(cmos->rtc, 1, mask); 869 rtc_update_irq(cmos->rtc, 1, mask);
871 tmp &= ~RTC_AIE; 870 tmp &= ~RTC_AIE;
872 hpet_mask_rtc_irq_bit(RTC_AIE); 871 hpet_mask_rtc_irq_bit(RTC_AIE);
872 hpet_rtc_timer_init();
873 } while (mask & RTC_AIE); 873 } while (mask & RTC_AIE);
874 spin_unlock_irq(&rtc_lock); 874 spin_unlock_irq(&rtc_lock);
875 } 875 }
diff --git a/drivers/rtc/rtc-coh901331.c b/drivers/rtc/rtc-coh901331.c
index 2d28ec1aa1cd..93c06588ddca 100644
--- a/drivers/rtc/rtc-coh901331.c
+++ b/drivers/rtc/rtc-coh901331.c
@@ -47,7 +47,7 @@ struct coh901331_port {
47 u32 physize; 47 u32 physize;
48 void __iomem *virtbase; 48 void __iomem *virtbase;
49 int irq; 49 int irq;
50#ifdef CONFIG_PM 50#ifdef CONFIG_PM_SLEEP
51 u32 irqmaskstore; 51 u32 irqmaskstore;
52#endif 52#endif
53}; 53};
@@ -155,7 +155,6 @@ static int __exit coh901331_remove(struct platform_device *pdev)
155 struct coh901331_port *rtap = dev_get_drvdata(&pdev->dev); 155 struct coh901331_port *rtap = dev_get_drvdata(&pdev->dev);
156 156
157 if (rtap) { 157 if (rtap) {
158 rtc_device_unregister(rtap->rtc);
159 clk_unprepare(rtap->clk); 158 clk_unprepare(rtap->clk);
160 platform_set_drvdata(pdev, NULL); 159 platform_set_drvdata(pdev, NULL);
161 } 160 }
@@ -211,8 +210,8 @@ static int __init coh901331_probe(struct platform_device *pdev)
211 clk_disable(rtap->clk); 210 clk_disable(rtap->clk);
212 211
213 platform_set_drvdata(pdev, rtap); 212 platform_set_drvdata(pdev, rtap);
214 rtap->rtc = rtc_device_register("coh901331", &pdev->dev, &coh901331_ops, 213 rtap->rtc = devm_rtc_device_register(&pdev->dev, "coh901331",
215 THIS_MODULE); 214 &coh901331_ops, THIS_MODULE);
216 if (IS_ERR(rtap->rtc)) { 215 if (IS_ERR(rtap->rtc)) {
217 ret = PTR_ERR(rtap->rtc); 216 ret = PTR_ERR(rtap->rtc);
218 goto out_no_rtc; 217 goto out_no_rtc;
@@ -226,17 +225,17 @@ static int __init coh901331_probe(struct platform_device *pdev)
226 return ret; 225 return ret;
227} 226}
228 227
229#ifdef CONFIG_PM 228#ifdef CONFIG_PM_SLEEP
230static int coh901331_suspend(struct platform_device *pdev, pm_message_t state) 229static int coh901331_suspend(struct device *dev)
231{ 230{
232 struct coh901331_port *rtap = dev_get_drvdata(&pdev->dev); 231 struct coh901331_port *rtap = dev_get_drvdata(dev);
233 232
234 /* 233 /*
235 * If this RTC alarm will be used for waking the system up, 234 * If this RTC alarm will be used for waking the system up,
236 * don't disable it of course. Else we just disable the alarm 235 * don't disable it of course. Else we just disable the alarm
237 * and await suspension. 236 * and await suspension.
238 */ 237 */
239 if (device_may_wakeup(&pdev->dev)) { 238 if (device_may_wakeup(dev)) {
240 enable_irq_wake(rtap->irq); 239 enable_irq_wake(rtap->irq);
241 } else { 240 } else {
242 clk_enable(rtap->clk); 241 clk_enable(rtap->clk);
@@ -248,12 +247,12 @@ static int coh901331_suspend(struct platform_device *pdev, pm_message_t state)
248 return 0; 247 return 0;
249} 248}
250 249
251static int coh901331_resume(struct platform_device *pdev) 250static int coh901331_resume(struct device *dev)
252{ 251{
253 struct coh901331_port *rtap = dev_get_drvdata(&pdev->dev); 252 struct coh901331_port *rtap = dev_get_drvdata(dev);
254 253
255 clk_prepare(rtap->clk); 254 clk_prepare(rtap->clk);
256 if (device_may_wakeup(&pdev->dev)) { 255 if (device_may_wakeup(dev)) {
257 disable_irq_wake(rtap->irq); 256 disable_irq_wake(rtap->irq);
258 } else { 257 } else {
259 clk_enable(rtap->clk); 258 clk_enable(rtap->clk);
@@ -262,11 +261,10 @@ static int coh901331_resume(struct platform_device *pdev)
262 } 261 }
263 return 0; 262 return 0;
264} 263}
265#else
266#define coh901331_suspend NULL
267#define coh901331_resume NULL
268#endif 264#endif
269 265
266static SIMPLE_DEV_PM_OPS(coh901331_pm_ops, coh901331_suspend, coh901331_resume);
267
270static void coh901331_shutdown(struct platform_device *pdev) 268static void coh901331_shutdown(struct platform_device *pdev)
271{ 269{
272 struct coh901331_port *rtap = dev_get_drvdata(&pdev->dev); 270 struct coh901331_port *rtap = dev_get_drvdata(&pdev->dev);
@@ -280,25 +278,13 @@ static struct platform_driver coh901331_driver = {
280 .driver = { 278 .driver = {
281 .name = "rtc-coh901331", 279 .name = "rtc-coh901331",
282 .owner = THIS_MODULE, 280 .owner = THIS_MODULE,
281 .pm = &coh901331_pm_ops,
283 }, 282 },
284 .remove = __exit_p(coh901331_remove), 283 .remove = __exit_p(coh901331_remove),
285 .suspend = coh901331_suspend,
286 .resume = coh901331_resume,
287 .shutdown = coh901331_shutdown, 284 .shutdown = coh901331_shutdown,
288}; 285};
289 286
290static int __init coh901331_init(void) 287module_platform_driver_probe(coh901331_driver, coh901331_probe);
291{
292 return platform_driver_probe(&coh901331_driver, coh901331_probe);
293}
294
295static void __exit coh901331_exit(void)
296{
297 platform_driver_unregister(&coh901331_driver);
298}
299
300module_init(coh901331_init);
301module_exit(coh901331_exit);
302 288
303MODULE_AUTHOR("Linus Walleij <linus.walleij@stericsson.com>"); 289MODULE_AUTHOR("Linus Walleij <linus.walleij@stericsson.com>");
304MODULE_DESCRIPTION("ST-Ericsson AB COH 901 331 RTC Driver"); 290MODULE_DESCRIPTION("ST-Ericsson AB COH 901 331 RTC Driver");
diff --git a/drivers/rtc/rtc-da9052.c b/drivers/rtc/rtc-da9052.c
index 0dde688ca09b..7286b279cf2d 100644
--- a/drivers/rtc/rtc-da9052.c
+++ b/drivers/rtc/rtc-da9052.c
@@ -239,17 +239,15 @@ static int da9052_rtc_probe(struct platform_device *pdev)
239 239
240 rtc->da9052 = dev_get_drvdata(pdev->dev.parent); 240 rtc->da9052 = dev_get_drvdata(pdev->dev.parent);
241 platform_set_drvdata(pdev, rtc); 241 platform_set_drvdata(pdev, rtc);
242 rtc->irq = platform_get_irq_byname(pdev, "ALM"); 242 rtc->irq = DA9052_IRQ_ALARM;
243 ret = devm_request_threaded_irq(&pdev->dev, rtc->irq, NULL, 243 ret = da9052_request_irq(rtc->da9052, rtc->irq, "ALM",
244 da9052_rtc_irq, 244 da9052_rtc_irq, rtc);
245 IRQF_TRIGGER_LOW | IRQF_ONESHOT,
246 "ALM", rtc);
247 if (ret != 0) { 245 if (ret != 0) {
248 rtc_err(rtc->da9052, "irq registration failed: %d\n", ret); 246 rtc_err(rtc->da9052, "irq registration failed: %d\n", ret);
249 return ret; 247 return ret;
250 } 248 }
251 249
252 rtc->rtc = rtc_device_register(pdev->name, &pdev->dev, 250 rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
253 &da9052_rtc_ops, THIS_MODULE); 251 &da9052_rtc_ops, THIS_MODULE);
254 if (IS_ERR(rtc->rtc)) 252 if (IS_ERR(rtc->rtc))
255 return PTR_ERR(rtc->rtc); 253 return PTR_ERR(rtc->rtc);
@@ -259,9 +257,6 @@ static int da9052_rtc_probe(struct platform_device *pdev)
259 257
260static int da9052_rtc_remove(struct platform_device *pdev) 258static int da9052_rtc_remove(struct platform_device *pdev)
261{ 259{
262 struct da9052_rtc *rtc = pdev->dev.platform_data;
263
264 rtc_device_unregister(rtc->rtc);
265 platform_set_drvdata(pdev, NULL); 260 platform_set_drvdata(pdev, NULL);
266 261
267 return 0; 262 return 0;
diff --git a/drivers/rtc/rtc-da9055.c b/drivers/rtc/rtc-da9055.c
index 8f0dcfedb83c..73858ca9709a 100644
--- a/drivers/rtc/rtc-da9055.c
+++ b/drivers/rtc/rtc-da9055.c
@@ -294,7 +294,7 @@ static int da9055_rtc_probe(struct platform_device *pdev)
294 294
295 device_init_wakeup(&pdev->dev, 1); 295 device_init_wakeup(&pdev->dev, 1);
296 296
297 rtc->rtc = rtc_device_register(pdev->name, &pdev->dev, 297 rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
298 &da9055_rtc_ops, THIS_MODULE); 298 &da9055_rtc_ops, THIS_MODULE);
299 if (IS_ERR(rtc->rtc)) { 299 if (IS_ERR(rtc->rtc)) {
300 ret = PTR_ERR(rtc->rtc); 300 ret = PTR_ERR(rtc->rtc);
@@ -317,9 +317,6 @@ err_rtc:
317 317
318static int da9055_rtc_remove(struct platform_device *pdev) 318static int da9055_rtc_remove(struct platform_device *pdev)
319{ 319{
320 struct da9055_rtc *rtc = pdev->dev.platform_data;
321
322 rtc_device_unregister(rtc->rtc);
323 platform_set_drvdata(pdev, NULL); 320 platform_set_drvdata(pdev, NULL);
324 321
325 return 0; 322 return 0;
diff --git a/drivers/rtc/rtc-davinci.c b/drivers/rtc/rtc-davinci.c
index 56b73089bb29..a55048c3e26f 100644
--- a/drivers/rtc/rtc-davinci.c
+++ b/drivers/rtc/rtc-davinci.c
@@ -523,7 +523,7 @@ static int __init davinci_rtc_probe(struct platform_device *pdev)
523 523
524 platform_set_drvdata(pdev, davinci_rtc); 524 platform_set_drvdata(pdev, davinci_rtc);
525 525
526 davinci_rtc->rtc = rtc_device_register(pdev->name, &pdev->dev, 526 davinci_rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
527 &davinci_rtc_ops, THIS_MODULE); 527 &davinci_rtc_ops, THIS_MODULE);
528 if (IS_ERR(davinci_rtc->rtc)) { 528 if (IS_ERR(davinci_rtc->rtc)) {
529 ret = PTR_ERR(davinci_rtc->rtc); 529 ret = PTR_ERR(davinci_rtc->rtc);
@@ -543,7 +543,7 @@ static int __init davinci_rtc_probe(struct platform_device *pdev)
543 0, "davinci_rtc", davinci_rtc); 543 0, "davinci_rtc", davinci_rtc);
544 if (ret < 0) { 544 if (ret < 0) {
545 dev_err(dev, "unable to register davinci RTC interrupt\n"); 545 dev_err(dev, "unable to register davinci RTC interrupt\n");
546 goto fail2; 546 goto fail1;
547 } 547 }
548 548
549 /* Enable interrupts */ 549 /* Enable interrupts */
@@ -557,14 +557,12 @@ static int __init davinci_rtc_probe(struct platform_device *pdev)
557 557
558 return 0; 558 return 0;
559 559
560fail2:
561 rtc_device_unregister(davinci_rtc->rtc);
562fail1: 560fail1:
563 platform_set_drvdata(pdev, NULL); 561 platform_set_drvdata(pdev, NULL);
564 return ret; 562 return ret;
565} 563}
566 564
567static int davinci_rtc_remove(struct platform_device *pdev) 565static int __exit davinci_rtc_remove(struct platform_device *pdev)
568{ 566{
569 struct davinci_rtc *davinci_rtc = platform_get_drvdata(pdev); 567 struct davinci_rtc *davinci_rtc = platform_get_drvdata(pdev);
570 568
@@ -572,8 +570,6 @@ static int davinci_rtc_remove(struct platform_device *pdev)
572 570
573 rtcif_write(davinci_rtc, 0, PRTCIF_INTEN); 571 rtcif_write(davinci_rtc, 0, PRTCIF_INTEN);
574 572
575 rtc_device_unregister(davinci_rtc->rtc);
576
577 platform_set_drvdata(pdev, NULL); 573 platform_set_drvdata(pdev, NULL);
578 574
579 return 0; 575 return 0;
@@ -581,24 +577,14 @@ static int davinci_rtc_remove(struct platform_device *pdev)
581 577
582static struct platform_driver davinci_rtc_driver = { 578static struct platform_driver davinci_rtc_driver = {
583 .probe = davinci_rtc_probe, 579 .probe = davinci_rtc_probe,
584 .remove = davinci_rtc_remove, 580 .remove = __exit_p(davinci_rtc_remove),
585 .driver = { 581 .driver = {
586 .name = "rtc_davinci", 582 .name = "rtc_davinci",
587 .owner = THIS_MODULE, 583 .owner = THIS_MODULE,
588 }, 584 },
589}; 585};
590 586
591static int __init rtc_init(void) 587module_platform_driver_probe(davinci_rtc_driver, davinci_rtc_probe);
592{
593 return platform_driver_probe(&davinci_rtc_driver, davinci_rtc_probe);
594}
595module_init(rtc_init);
596
597static void __exit rtc_exit(void)
598{
599 platform_driver_unregister(&davinci_rtc_driver);
600}
601module_exit(rtc_exit);
602 588
603MODULE_AUTHOR("Miguel Aguilar <miguel.aguilar@ridgerun.com>"); 589MODULE_AUTHOR("Miguel Aguilar <miguel.aguilar@ridgerun.com>");
604MODULE_DESCRIPTION("Texas Instruments DaVinci PRTC Driver"); 590MODULE_DESCRIPTION("Texas Instruments DaVinci PRTC Driver");
diff --git a/drivers/rtc/rtc-dm355evm.c b/drivers/rtc/rtc-dm355evm.c
index b2ed2c94b081..1e1ca63d58a9 100644
--- a/drivers/rtc/rtc-dm355evm.c
+++ b/drivers/rtc/rtc-dm355evm.c
@@ -127,8 +127,8 @@ static int dm355evm_rtc_probe(struct platform_device *pdev)
127{ 127{
128 struct rtc_device *rtc; 128 struct rtc_device *rtc;
129 129
130 rtc = rtc_device_register(pdev->name, 130 rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
131 &pdev->dev, &dm355evm_rtc_ops, THIS_MODULE); 131 &dm355evm_rtc_ops, THIS_MODULE);
132 if (IS_ERR(rtc)) { 132 if (IS_ERR(rtc)) {
133 dev_err(&pdev->dev, "can't register RTC device, err %ld\n", 133 dev_err(&pdev->dev, "can't register RTC device, err %ld\n",
134 PTR_ERR(rtc)); 134 PTR_ERR(rtc));
@@ -141,9 +141,6 @@ static int dm355evm_rtc_probe(struct platform_device *pdev)
141 141
142static int dm355evm_rtc_remove(struct platform_device *pdev) 142static int dm355evm_rtc_remove(struct platform_device *pdev)
143{ 143{
144 struct rtc_device *rtc = platform_get_drvdata(pdev);
145
146 rtc_device_unregister(rtc);
147 platform_set_drvdata(pdev, NULL); 144 platform_set_drvdata(pdev, NULL);
148 return 0; 145 return 0;
149} 146}
diff --git a/drivers/rtc/rtc-ds1216.c b/drivers/rtc/rtc-ds1216.c
index 45cd8c9f5a39..c7702b7269f7 100644
--- a/drivers/rtc/rtc-ds1216.c
+++ b/drivers/rtc/rtc-ds1216.c
@@ -30,8 +30,6 @@ struct ds1216_regs {
30struct ds1216_priv { 30struct ds1216_priv {
31 struct rtc_device *rtc; 31 struct rtc_device *rtc;
32 void __iomem *ioaddr; 32 void __iomem *ioaddr;
33 size_t size;
34 unsigned long baseaddr;
35}; 33};
36 34
37static const u8 magic[] = { 35static const u8 magic[] = {
@@ -144,57 +142,33 @@ static int __init ds1216_rtc_probe(struct platform_device *pdev)
144{ 142{
145 struct resource *res; 143 struct resource *res;
146 struct ds1216_priv *priv; 144 struct ds1216_priv *priv;
147 int ret = 0;
148 u8 dummy[8]; 145 u8 dummy[8];
149 146
150 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 147 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
151 if (!res) 148 if (!res)
152 return -ENODEV; 149 return -ENODEV;
153 priv = kzalloc(sizeof *priv, GFP_KERNEL); 150 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
154 if (!priv) 151 if (!priv)
155 return -ENOMEM; 152 return -ENOMEM;
156 153
157 platform_set_drvdata(pdev, priv); 154 platform_set_drvdata(pdev, priv);
158 155
159 priv->size = resource_size(res); 156 priv->ioaddr = devm_ioremap_resource(&pdev->dev, res);
160 if (!request_mem_region(res->start, priv->size, pdev->name)) { 157 if (IS_ERR(priv->ioaddr))
161 ret = -EBUSY; 158 return PTR_ERR(priv->ioaddr);
162 goto out; 159
163 } 160 priv->rtc = devm_rtc_device_register(&pdev->dev, "ds1216",
164 priv->baseaddr = res->start; 161 &ds1216_rtc_ops, THIS_MODULE);
165 priv->ioaddr = ioremap(priv->baseaddr, priv->size); 162 if (IS_ERR(priv->rtc))
166 if (!priv->ioaddr) { 163 return PTR_ERR(priv->rtc);
167 ret = -ENOMEM;
168 goto out;
169 }
170 priv->rtc = rtc_device_register("ds1216", &pdev->dev,
171 &ds1216_rtc_ops, THIS_MODULE);
172 if (IS_ERR(priv->rtc)) {
173 ret = PTR_ERR(priv->rtc);
174 goto out;
175 }
176 164
177 /* dummy read to get clock into a known state */ 165 /* dummy read to get clock into a known state */
178 ds1216_read(priv->ioaddr, dummy); 166 ds1216_read(priv->ioaddr, dummy);
179 return 0; 167 return 0;
180
181out:
182 if (priv->ioaddr)
183 iounmap(priv->ioaddr);
184 if (priv->baseaddr)
185 release_mem_region(priv->baseaddr, priv->size);
186 kfree(priv);
187 return ret;
188} 168}
189 169
190static int __exit ds1216_rtc_remove(struct platform_device *pdev) 170static int __exit ds1216_rtc_remove(struct platform_device *pdev)
191{ 171{
192 struct ds1216_priv *priv = platform_get_drvdata(pdev);
193
194 rtc_device_unregister(priv->rtc);
195 iounmap(priv->ioaddr);
196 release_mem_region(priv->baseaddr, priv->size);
197 kfree(priv);
198 return 0; 172 return 0;
199} 173}
200 174
diff --git a/drivers/rtc/rtc-ds1286.c b/drivers/rtc/rtc-ds1286.c
index d989412a348a..398c96a98fc4 100644
--- a/drivers/rtc/rtc-ds1286.c
+++ b/drivers/rtc/rtc-ds1286.c
@@ -25,8 +25,6 @@
25struct ds1286_priv { 25struct ds1286_priv {
26 struct rtc_device *rtc; 26 struct rtc_device *rtc;
27 u32 __iomem *rtcregs; 27 u32 __iomem *rtcregs;
28 size_t size;
29 unsigned long baseaddr;
30 spinlock_t lock; 28 spinlock_t lock;
31}; 29};
32 30
@@ -270,7 +268,6 @@ static int ds1286_set_time(struct device *dev, struct rtc_time *tm)
270static int ds1286_read_alarm(struct device *dev, struct rtc_wkalrm *alm) 268static int ds1286_read_alarm(struct device *dev, struct rtc_wkalrm *alm)
271{ 269{
272 struct ds1286_priv *priv = dev_get_drvdata(dev); 270 struct ds1286_priv *priv = dev_get_drvdata(dev);
273 unsigned char cmd;
274 unsigned long flags; 271 unsigned long flags;
275 272
276 /* 273 /*
@@ -281,7 +278,7 @@ static int ds1286_read_alarm(struct device *dev, struct rtc_wkalrm *alm)
281 alm->time.tm_min = ds1286_rtc_read(priv, RTC_MINUTES_ALARM) & 0x7f; 278 alm->time.tm_min = ds1286_rtc_read(priv, RTC_MINUTES_ALARM) & 0x7f;
282 alm->time.tm_hour = ds1286_rtc_read(priv, RTC_HOURS_ALARM) & 0x1f; 279 alm->time.tm_hour = ds1286_rtc_read(priv, RTC_HOURS_ALARM) & 0x1f;
283 alm->time.tm_wday = ds1286_rtc_read(priv, RTC_DAY_ALARM) & 0x07; 280 alm->time.tm_wday = ds1286_rtc_read(priv, RTC_DAY_ALARM) & 0x07;
284 cmd = ds1286_rtc_read(priv, RTC_CMD); 281 ds1286_rtc_read(priv, RTC_CMD);
285 spin_unlock_irqrestore(&priv->lock, flags); 282 spin_unlock_irqrestore(&priv->lock, flags);
286 283
287 alm->time.tm_min = bcd2bin(alm->time.tm_min); 284 alm->time.tm_min = bcd2bin(alm->time.tm_min);
@@ -334,56 +331,30 @@ static int ds1286_probe(struct platform_device *pdev)
334 struct rtc_device *rtc; 331 struct rtc_device *rtc;
335 struct resource *res; 332 struct resource *res;
336 struct ds1286_priv *priv; 333 struct ds1286_priv *priv;
337 int ret = 0;
338 334
339 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 335 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
340 if (!res) 336 if (!res)
341 return -ENODEV; 337 return -ENODEV;
342 priv = kzalloc(sizeof(struct ds1286_priv), GFP_KERNEL); 338 priv = devm_kzalloc(&pdev->dev, sizeof(struct ds1286_priv), GFP_KERNEL);
343 if (!priv) 339 if (!priv)
344 return -ENOMEM; 340 return -ENOMEM;
345 341
346 priv->size = resource_size(res); 342 priv->rtcregs = devm_ioremap_resource(&pdev->dev, res);
347 if (!request_mem_region(res->start, priv->size, pdev->name)) { 343 if (IS_ERR(priv->rtcregs))
348 ret = -EBUSY; 344 return PTR_ERR(priv->rtcregs);
349 goto out; 345
350 }
351 priv->baseaddr = res->start;
352 priv->rtcregs = ioremap(priv->baseaddr, priv->size);
353 if (!priv->rtcregs) {
354 ret = -ENOMEM;
355 goto out;
356 }
357 spin_lock_init(&priv->lock); 346 spin_lock_init(&priv->lock);
358 platform_set_drvdata(pdev, priv); 347 platform_set_drvdata(pdev, priv);
359 rtc = rtc_device_register("ds1286", &pdev->dev, 348 rtc = devm_rtc_device_register(&pdev->dev, "ds1286", &ds1286_ops,
360 &ds1286_ops, THIS_MODULE); 349 THIS_MODULE);
361 if (IS_ERR(rtc)) { 350 if (IS_ERR(rtc))
362 ret = PTR_ERR(rtc); 351 return PTR_ERR(rtc);
363 goto out;
364 }
365 priv->rtc = rtc; 352 priv->rtc = rtc;
366 return 0; 353 return 0;
367
368out:
369 if (priv->rtc)
370 rtc_device_unregister(priv->rtc);
371 if (priv->rtcregs)
372 iounmap(priv->rtcregs);
373 if (priv->baseaddr)
374 release_mem_region(priv->baseaddr, priv->size);
375 kfree(priv);
376 return ret;
377} 354}
378 355
379static int ds1286_remove(struct platform_device *pdev) 356static int ds1286_remove(struct platform_device *pdev)
380{ 357{
381 struct ds1286_priv *priv = platform_get_drvdata(pdev);
382
383 rtc_device_unregister(priv->rtc);
384 iounmap(priv->rtcregs);
385 release_mem_region(priv->baseaddr, priv->size);
386 kfree(priv);
387 return 0; 358 return 0;
388} 359}
389 360
diff --git a/drivers/rtc/rtc-ds1302.c b/drivers/rtc/rtc-ds1302.c
index fdbcdb289d60..d13954346286 100644
--- a/drivers/rtc/rtc-ds1302.c
+++ b/drivers/rtc/rtc-ds1302.c
@@ -224,7 +224,7 @@ static int __init ds1302_rtc_probe(struct platform_device *pdev)
224 return -ENODEV; 224 return -ENODEV;
225 } 225 }
226 226
227 rtc = rtc_device_register("ds1302", &pdev->dev, 227 rtc = devm_rtc_device_register(&pdev->dev, "ds1302",
228 &ds1302_rtc_ops, THIS_MODULE); 228 &ds1302_rtc_ops, THIS_MODULE);
229 if (IS_ERR(rtc)) 229 if (IS_ERR(rtc))
230 return PTR_ERR(rtc); 230 return PTR_ERR(rtc);
@@ -234,11 +234,8 @@ static int __init ds1302_rtc_probe(struct platform_device *pdev)
234 return 0; 234 return 0;
235} 235}
236 236
237static int ds1302_rtc_remove(struct platform_device *pdev) 237static int __exit ds1302_rtc_remove(struct platform_device *pdev)
238{ 238{
239 struct rtc_device *rtc = platform_get_drvdata(pdev);
240
241 rtc_device_unregister(rtc);
242 platform_set_drvdata(pdev, NULL); 239 platform_set_drvdata(pdev, NULL);
243 240
244 return 0; 241 return 0;
@@ -249,21 +246,10 @@ static struct platform_driver ds1302_platform_driver = {
249 .name = DRV_NAME, 246 .name = DRV_NAME,
250 .owner = THIS_MODULE, 247 .owner = THIS_MODULE,
251 }, 248 },
252 .remove = ds1302_rtc_remove, 249 .remove = __exit_p(ds1302_rtc_remove),
253}; 250};
254 251
255static int __init ds1302_rtc_init(void) 252module_platform_driver_probe(ds1302_platform_driver, ds1302_rtc_probe);
256{
257 return platform_driver_probe(&ds1302_platform_driver, ds1302_rtc_probe);
258}
259
260static void __exit ds1302_rtc_exit(void)
261{
262 platform_driver_unregister(&ds1302_platform_driver);
263}
264
265module_init(ds1302_rtc_init);
266module_exit(ds1302_rtc_exit);
267 253
268MODULE_DESCRIPTION("Dallas DS1302 RTC driver"); 254MODULE_DESCRIPTION("Dallas DS1302 RTC driver");
269MODULE_VERSION(DRV_VERSION); 255MODULE_VERSION(DRV_VERSION);
diff --git a/drivers/rtc/rtc-ds1305.c b/drivers/rtc/rtc-ds1305.c
index b05a6dc96405..bb5f13f63630 100644
--- a/drivers/rtc/rtc-ds1305.c
+++ b/drivers/rtc/rtc-ds1305.c
@@ -619,7 +619,7 @@ static int ds1305_probe(struct spi_device *spi)
619 return -EINVAL; 619 return -EINVAL;
620 620
621 /* set up driver data */ 621 /* set up driver data */
622 ds1305 = kzalloc(sizeof *ds1305, GFP_KERNEL); 622 ds1305 = devm_kzalloc(&spi->dev, sizeof(*ds1305), GFP_KERNEL);
623 if (!ds1305) 623 if (!ds1305)
624 return -ENOMEM; 624 return -ENOMEM;
625 ds1305->spi = spi; 625 ds1305->spi = spi;
@@ -632,7 +632,7 @@ static int ds1305_probe(struct spi_device *spi)
632 if (status < 0) { 632 if (status < 0) {
633 dev_dbg(&spi->dev, "can't %s, %d\n", 633 dev_dbg(&spi->dev, "can't %s, %d\n",
634 "read", status); 634 "read", status);
635 goto fail0; 635 return status;
636 } 636 }
637 637
638 dev_dbg(&spi->dev, "ctrl %s: %3ph\n", "read", ds1305->ctrl); 638 dev_dbg(&spi->dev, "ctrl %s: %3ph\n", "read", ds1305->ctrl);
@@ -644,8 +644,7 @@ static int ds1305_probe(struct spi_device *spi)
644 */ 644 */
645 if ((ds1305->ctrl[0] & 0x38) != 0 || (ds1305->ctrl[1] & 0xfc) != 0) { 645 if ((ds1305->ctrl[0] & 0x38) != 0 || (ds1305->ctrl[1] & 0xfc) != 0) {
646 dev_dbg(&spi->dev, "RTC chip is not present\n"); 646 dev_dbg(&spi->dev, "RTC chip is not present\n");
647 status = -ENODEV; 647 return -ENODEV;
648 goto fail0;
649 } 648 }
650 if (ds1305->ctrl[2] == 0) 649 if (ds1305->ctrl[2] == 0)
651 dev_dbg(&spi->dev, "chip may not be present\n"); 650 dev_dbg(&spi->dev, "chip may not be present\n");
@@ -664,7 +663,7 @@ static int ds1305_probe(struct spi_device *spi)
664 663
665 dev_dbg(&spi->dev, "clear WP --> %d\n", status); 664 dev_dbg(&spi->dev, "clear WP --> %d\n", status);
666 if (status < 0) 665 if (status < 0)
667 goto fail0; 666 return status;
668 } 667 }
669 668
670 /* on DS1305, maybe start oscillator; like most low power 669 /* on DS1305, maybe start oscillator; like most low power
@@ -718,7 +717,7 @@ static int ds1305_probe(struct spi_device *spi)
718 if (status < 0) { 717 if (status < 0) {
719 dev_dbg(&spi->dev, "can't %s, %d\n", 718 dev_dbg(&spi->dev, "can't %s, %d\n",
720 "write", status); 719 "write", status);
721 goto fail0; 720 return status;
722 } 721 }
723 722
724 dev_dbg(&spi->dev, "ctrl %s: %3ph\n", "write", ds1305->ctrl); 723 dev_dbg(&spi->dev, "ctrl %s: %3ph\n", "write", ds1305->ctrl);
@@ -730,7 +729,7 @@ static int ds1305_probe(struct spi_device *spi)
730 &value, sizeof value); 729 &value, sizeof value);
731 if (status < 0) { 730 if (status < 0) {
732 dev_dbg(&spi->dev, "read HOUR --> %d\n", status); 731 dev_dbg(&spi->dev, "read HOUR --> %d\n", status);
733 goto fail0; 732 return status;
734 } 733 }
735 734
736 ds1305->hr12 = (DS1305_HR_12 & value) != 0; 735 ds1305->hr12 = (DS1305_HR_12 & value) != 0;
@@ -738,12 +737,12 @@ static int ds1305_probe(struct spi_device *spi)
738 dev_dbg(&spi->dev, "AM/PM\n"); 737 dev_dbg(&spi->dev, "AM/PM\n");
739 738
740 /* register RTC ... from here on, ds1305->ctrl needs locking */ 739 /* register RTC ... from here on, ds1305->ctrl needs locking */
741 ds1305->rtc = rtc_device_register("ds1305", &spi->dev, 740 ds1305->rtc = devm_rtc_device_register(&spi->dev, "ds1305",
742 &ds1305_ops, THIS_MODULE); 741 &ds1305_ops, THIS_MODULE);
743 if (IS_ERR(ds1305->rtc)) { 742 if (IS_ERR(ds1305->rtc)) {
744 status = PTR_ERR(ds1305->rtc); 743 status = PTR_ERR(ds1305->rtc);
745 dev_dbg(&spi->dev, "register rtc --> %d\n", status); 744 dev_dbg(&spi->dev, "register rtc --> %d\n", status);
746 goto fail0; 745 return status;
747 } 746 }
748 747
749 /* Maybe set up alarm IRQ; be ready to handle it triggering right 748 /* Maybe set up alarm IRQ; be ready to handle it triggering right
@@ -754,12 +753,12 @@ static int ds1305_probe(struct spi_device *spi)
754 */ 753 */
755 if (spi->irq) { 754 if (spi->irq) {
756 INIT_WORK(&ds1305->work, ds1305_work); 755 INIT_WORK(&ds1305->work, ds1305_work);
757 status = request_irq(spi->irq, ds1305_irq, 756 status = devm_request_irq(&spi->dev, spi->irq, ds1305_irq,
758 0, dev_name(&ds1305->rtc->dev), ds1305); 757 0, dev_name(&ds1305->rtc->dev), ds1305);
759 if (status < 0) { 758 if (status < 0) {
760 dev_dbg(&spi->dev, "request_irq %d --> %d\n", 759 dev_dbg(&spi->dev, "request_irq %d --> %d\n",
761 spi->irq, status); 760 spi->irq, status);
762 goto fail1; 761 return status;
763 } 762 }
764 763
765 device_set_wakeup_capable(&spi->dev, 1); 764 device_set_wakeup_capable(&spi->dev, 1);
@@ -769,18 +768,10 @@ static int ds1305_probe(struct spi_device *spi)
769 status = sysfs_create_bin_file(&spi->dev.kobj, &nvram); 768 status = sysfs_create_bin_file(&spi->dev.kobj, &nvram);
770 if (status < 0) { 769 if (status < 0) {
771 dev_dbg(&spi->dev, "register nvram --> %d\n", status); 770 dev_dbg(&spi->dev, "register nvram --> %d\n", status);
772 goto fail2; 771 return status;
773 } 772 }
774 773
775 return 0; 774 return 0;
776
777fail2:
778 free_irq(spi->irq, ds1305);
779fail1:
780 rtc_device_unregister(ds1305->rtc);
781fail0:
782 kfree(ds1305);
783 return status;
784} 775}
785 776
786static int ds1305_remove(struct spi_device *spi) 777static int ds1305_remove(struct spi_device *spi)
@@ -792,13 +783,11 @@ static int ds1305_remove(struct spi_device *spi)
792 /* carefully shut down irq and workqueue, if present */ 783 /* carefully shut down irq and workqueue, if present */
793 if (spi->irq) { 784 if (spi->irq) {
794 set_bit(FLAG_EXITING, &ds1305->flags); 785 set_bit(FLAG_EXITING, &ds1305->flags);
795 free_irq(spi->irq, ds1305); 786 devm_free_irq(&spi->dev, spi->irq, ds1305);
796 cancel_work_sync(&ds1305->work); 787 cancel_work_sync(&ds1305->work);
797 } 788 }
798 789
799 rtc_device_unregister(ds1305->rtc);
800 spi_set_drvdata(spi, NULL); 790 spi_set_drvdata(spi, NULL);
801 kfree(ds1305);
802 return 0; 791 return 0;
803} 792}
804 793
diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index 970a236b147a..b53992ab3090 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -4,6 +4,7 @@
4 * Copyright (C) 2005 James Chapman (ds1337 core) 4 * Copyright (C) 2005 James Chapman (ds1337 core)
5 * Copyright (C) 2006 David Brownell 5 * Copyright (C) 2006 David Brownell
6 * Copyright (C) 2009 Matthias Fuchs (rx8025 support) 6 * Copyright (C) 2009 Matthias Fuchs (rx8025 support)
7 * Copyright (C) 2012 Bertrand Achard (nvram access fixes)
7 * 8 *
8 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as 10 * it under the terms of the GNU General Public License version 2 as
@@ -196,7 +197,7 @@ static s32 ds1307_read_block_data_once(const struct i2c_client *client,
196static s32 ds1307_read_block_data(const struct i2c_client *client, u8 command, 197static s32 ds1307_read_block_data(const struct i2c_client *client, u8 command,
197 u8 length, u8 *values) 198 u8 length, u8 *values)
198{ 199{
199 u8 oldvalues[I2C_SMBUS_BLOCK_MAX]; 200 u8 oldvalues[255];
200 s32 ret; 201 s32 ret;
201 int tries = 0; 202 int tries = 0;
202 203
@@ -222,7 +223,7 @@ static s32 ds1307_read_block_data(const struct i2c_client *client, u8 command,
222static s32 ds1307_write_block_data(const struct i2c_client *client, u8 command, 223static s32 ds1307_write_block_data(const struct i2c_client *client, u8 command,
223 u8 length, const u8 *values) 224 u8 length, const u8 *values)
224{ 225{
225 u8 currvalues[I2C_SMBUS_BLOCK_MAX]; 226 u8 currvalues[255];
226 int tries = 0; 227 int tries = 0;
227 228
228 dev_dbg(&client->dev, "ds1307_write_block_data (length=%d)\n", length); 229 dev_dbg(&client->dev, "ds1307_write_block_data (length=%d)\n", length);
@@ -250,6 +251,57 @@ static s32 ds1307_write_block_data(const struct i2c_client *client, u8 command,
250 251
251/*----------------------------------------------------------------------*/ 252/*----------------------------------------------------------------------*/
252 253
254/* These RTC devices are not designed to be connected to a SMbus adapter.
255 SMbus limits block operations length to 32 bytes, whereas it's not
256 limited on I2C buses. As a result, accesses may exceed 32 bytes;
257 in that case, split them into smaller blocks */
258
259static s32 ds1307_native_smbus_write_block_data(const struct i2c_client *client,
260 u8 command, u8 length, const u8 *values)
261{
262 u8 suboffset = 0;
263
264 if (length <= I2C_SMBUS_BLOCK_MAX)
265 return i2c_smbus_write_i2c_block_data(client,
266 command, length, values);
267
268 while (suboffset < length) {
269 s32 retval = i2c_smbus_write_i2c_block_data(client,
270 command + suboffset,
271 min(I2C_SMBUS_BLOCK_MAX, length - suboffset),
272 values + suboffset);
273 if (retval < 0)
274 return retval;
275
276 suboffset += I2C_SMBUS_BLOCK_MAX;
277 }
278 return length;
279}
280
281static s32 ds1307_native_smbus_read_block_data(const struct i2c_client *client,
282 u8 command, u8 length, u8 *values)
283{
284 u8 suboffset = 0;
285
286 if (length <= I2C_SMBUS_BLOCK_MAX)
287 return i2c_smbus_read_i2c_block_data(client,
288 command, length, values);
289
290 while (suboffset < length) {
291 s32 retval = i2c_smbus_read_i2c_block_data(client,
292 command + suboffset,
293 min(I2C_SMBUS_BLOCK_MAX, length - suboffset),
294 values + suboffset);
295 if (retval < 0)
296 return retval;
297
298 suboffset += I2C_SMBUS_BLOCK_MAX;
299 }
300 return length;
301}
302
303/*----------------------------------------------------------------------*/
304
253/* 305/*
254 * The IRQ logic includes a "real" handler running in IRQ context just 306 * The IRQ logic includes a "real" handler running in IRQ context just
255 * long enough to schedule this workqueue entry. We need a task context 307 * long enough to schedule this workqueue entry. We need a task context
@@ -646,8 +698,8 @@ static int ds1307_probe(struct i2c_client *client,
646 698
647 buf = ds1307->regs; 699 buf = ds1307->regs;
648 if (i2c_check_functionality(adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) { 700 if (i2c_check_functionality(adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) {
649 ds1307->read_block_data = i2c_smbus_read_i2c_block_data; 701 ds1307->read_block_data = ds1307_native_smbus_read_block_data;
650 ds1307->write_block_data = i2c_smbus_write_i2c_block_data; 702 ds1307->write_block_data = ds1307_native_smbus_write_block_data;
651 } else { 703 } else {
652 ds1307->read_block_data = ds1307_read_block_data; 704 ds1307->read_block_data = ds1307_read_block_data;
653 ds1307->write_block_data = ds1307_write_block_data; 705 ds1307->write_block_data = ds1307_write_block_data;
@@ -661,7 +713,7 @@ static int ds1307_probe(struct i2c_client *client,
661 tmp = ds1307->read_block_data(ds1307->client, 713 tmp = ds1307->read_block_data(ds1307->client,
662 DS1337_REG_CONTROL, 2, buf); 714 DS1337_REG_CONTROL, 2, buf);
663 if (tmp != 2) { 715 if (tmp != 2) {
664 pr_debug("read error %d\n", tmp); 716 dev_dbg(&client->dev, "read error %d\n", tmp);
665 err = -EIO; 717 err = -EIO;
666 goto exit_free; 718 goto exit_free;
667 } 719 }
@@ -700,7 +752,7 @@ static int ds1307_probe(struct i2c_client *client,
700 tmp = i2c_smbus_read_i2c_block_data(ds1307->client, 752 tmp = i2c_smbus_read_i2c_block_data(ds1307->client,
701 RX8025_REG_CTRL1 << 4 | 0x08, 2, buf); 753 RX8025_REG_CTRL1 << 4 | 0x08, 2, buf);
702 if (tmp != 2) { 754 if (tmp != 2) {
703 pr_debug("read error %d\n", tmp); 755 dev_dbg(&client->dev, "read error %d\n", tmp);
704 err = -EIO; 756 err = -EIO;
705 goto exit_free; 757 goto exit_free;
706 } 758 }
@@ -744,7 +796,7 @@ static int ds1307_probe(struct i2c_client *client,
744 tmp = i2c_smbus_read_i2c_block_data(ds1307->client, 796 tmp = i2c_smbus_read_i2c_block_data(ds1307->client,
745 RX8025_REG_CTRL1 << 4 | 0x08, 2, buf); 797 RX8025_REG_CTRL1 << 4 | 0x08, 2, buf);
746 if (tmp != 2) { 798 if (tmp != 2) {
747 pr_debug("read error %d\n", tmp); 799 dev_dbg(&client->dev, "read error %d\n", tmp);
748 err = -EIO; 800 err = -EIO;
749 goto exit_free; 801 goto exit_free;
750 } 802 }
@@ -772,7 +824,7 @@ read_rtc:
772 /* read RTC registers */ 824 /* read RTC registers */
773 tmp = ds1307->read_block_data(ds1307->client, ds1307->offset, 8, buf); 825 tmp = ds1307->read_block_data(ds1307->client, ds1307->offset, 8, buf);
774 if (tmp != 8) { 826 if (tmp != 8) {
775 pr_debug("read error %d\n", tmp); 827 dev_dbg(&client->dev, "read error %d\n", tmp);
776 err = -EIO; 828 err = -EIO;
777 goto exit_free; 829 goto exit_free;
778 } 830 }
@@ -814,7 +866,7 @@ read_rtc:
814 866
815 tmp = i2c_smbus_read_byte_data(client, DS1340_REG_FLAG); 867 tmp = i2c_smbus_read_byte_data(client, DS1340_REG_FLAG);
816 if (tmp < 0) { 868 if (tmp < 0) {
817 pr_debug("read error %d\n", tmp); 869 dev_dbg(&client->dev, "read error %d\n", tmp);
818 err = -EIO; 870 err = -EIO;
819 goto exit_free; 871 goto exit_free;
820 } 872 }
@@ -908,8 +960,8 @@ read_rtc:
908 ds1307->nvram->attr.name = "nvram"; 960 ds1307->nvram->attr.name = "nvram";
909 ds1307->nvram->attr.mode = S_IRUGO | S_IWUSR; 961 ds1307->nvram->attr.mode = S_IRUGO | S_IWUSR;
910 sysfs_bin_attr_init(ds1307->nvram); 962 sysfs_bin_attr_init(ds1307->nvram);
911 ds1307->nvram->read = ds1307_nvram_read, 963 ds1307->nvram->read = ds1307_nvram_read;
912 ds1307->nvram->write = ds1307_nvram_write, 964 ds1307->nvram->write = ds1307_nvram_write;
913 ds1307->nvram->size = chip->nvram_size; 965 ds1307->nvram->size = chip->nvram_size;
914 ds1307->nvram_offset = chip->nvram_offset; 966 ds1307->nvram_offset = chip->nvram_offset;
915 err = sysfs_create_bin_file(&client->dev.kobj, ds1307->nvram); 967 err = sysfs_create_bin_file(&client->dev.kobj, ds1307->nvram);
diff --git a/drivers/rtc/rtc-ds1374.c b/drivers/rtc/rtc-ds1374.c
index fef76868aae0..94366e12f40f 100644
--- a/drivers/rtc/rtc-ds1374.c
+++ b/drivers/rtc/rtc-ds1374.c
@@ -347,7 +347,7 @@ static int ds1374_probe(struct i2c_client *client,
347 struct ds1374 *ds1374; 347 struct ds1374 *ds1374;
348 int ret; 348 int ret;
349 349
350 ds1374 = kzalloc(sizeof(struct ds1374), GFP_KERNEL); 350 ds1374 = devm_kzalloc(&client->dev, sizeof(struct ds1374), GFP_KERNEL);
351 if (!ds1374) 351 if (!ds1374)
352 return -ENOMEM; 352 return -ENOMEM;
353 353
@@ -359,36 +359,27 @@ static int ds1374_probe(struct i2c_client *client,
359 359
360 ret = ds1374_check_rtc_status(client); 360 ret = ds1374_check_rtc_status(client);
361 if (ret) 361 if (ret)
362 goto out_free; 362 return ret;
363 363
364 if (client->irq > 0) { 364 if (client->irq > 0) {
365 ret = request_irq(client->irq, ds1374_irq, 0, 365 ret = devm_request_irq(&client->dev, client->irq, ds1374_irq, 0,
366 "ds1374", client); 366 "ds1374", client);
367 if (ret) { 367 if (ret) {
368 dev_err(&client->dev, "unable to request IRQ\n"); 368 dev_err(&client->dev, "unable to request IRQ\n");
369 goto out_free; 369 return ret;
370 } 370 }
371 371
372 device_set_wakeup_capable(&client->dev, 1); 372 device_set_wakeup_capable(&client->dev, 1);
373 } 373 }
374 374
375 ds1374->rtc = rtc_device_register(client->name, &client->dev, 375 ds1374->rtc = devm_rtc_device_register(&client->dev, client->name,
376 &ds1374_rtc_ops, THIS_MODULE); 376 &ds1374_rtc_ops, THIS_MODULE);
377 if (IS_ERR(ds1374->rtc)) { 377 if (IS_ERR(ds1374->rtc)) {
378 ret = PTR_ERR(ds1374->rtc);
379 dev_err(&client->dev, "unable to register the class device\n"); 378 dev_err(&client->dev, "unable to register the class device\n");
380 goto out_irq; 379 return PTR_ERR(ds1374->rtc);
381 } 380 }
382 381
383 return 0; 382 return 0;
384
385out_irq:
386 if (client->irq > 0)
387 free_irq(client->irq, client);
388
389out_free:
390 kfree(ds1374);
391 return ret;
392} 383}
393 384
394static int ds1374_remove(struct i2c_client *client) 385static int ds1374_remove(struct i2c_client *client)
@@ -400,16 +391,14 @@ static int ds1374_remove(struct i2c_client *client)
400 ds1374->exiting = 1; 391 ds1374->exiting = 1;
401 mutex_unlock(&ds1374->mutex); 392 mutex_unlock(&ds1374->mutex);
402 393
403 free_irq(client->irq, client); 394 devm_free_irq(&client->dev, client->irq, client);
404 cancel_work_sync(&ds1374->work); 395 cancel_work_sync(&ds1374->work);
405 } 396 }
406 397
407 rtc_device_unregister(ds1374->rtc);
408 kfree(ds1374);
409 return 0; 398 return 0;
410} 399}
411 400
412#ifdef CONFIG_PM 401#ifdef CONFIG_PM_SLEEP
413static int ds1374_suspend(struct device *dev) 402static int ds1374_suspend(struct device *dev)
414{ 403{
415 struct i2c_client *client = to_i2c_client(dev); 404 struct i2c_client *client = to_i2c_client(dev);
@@ -427,19 +416,15 @@ static int ds1374_resume(struct device *dev)
427 disable_irq_wake(client->irq); 416 disable_irq_wake(client->irq);
428 return 0; 417 return 0;
429} 418}
419#endif
430 420
431static SIMPLE_DEV_PM_OPS(ds1374_pm, ds1374_suspend, ds1374_resume); 421static SIMPLE_DEV_PM_OPS(ds1374_pm, ds1374_suspend, ds1374_resume);
432 422
433#define DS1374_PM (&ds1374_pm)
434#else
435#define DS1374_PM NULL
436#endif
437
438static struct i2c_driver ds1374_driver = { 423static struct i2c_driver ds1374_driver = {
439 .driver = { 424 .driver = {
440 .name = "rtc-ds1374", 425 .name = "rtc-ds1374",
441 .owner = THIS_MODULE, 426 .owner = THIS_MODULE,
442 .pm = DS1374_PM, 427 .pm = &ds1374_pm,
443 }, 428 },
444 .probe = ds1374_probe, 429 .probe = ds1374_probe,
445 .remove = ds1374_remove, 430 .remove = ds1374_remove,
diff --git a/drivers/rtc/rtc-ds1390.c b/drivers/rtc/rtc-ds1390.c
index f994257981a0..289af419dff4 100644
--- a/drivers/rtc/rtc-ds1390.c
+++ b/drivers/rtc/rtc-ds1390.c
@@ -131,26 +131,24 @@ static int ds1390_probe(struct spi_device *spi)
131 spi->bits_per_word = 8; 131 spi->bits_per_word = 8;
132 spi_setup(spi); 132 spi_setup(spi);
133 133
134 chip = kzalloc(sizeof *chip, GFP_KERNEL); 134 chip = devm_kzalloc(&spi->dev, sizeof(*chip), GFP_KERNEL);
135 if (!chip) { 135 if (!chip) {
136 dev_err(&spi->dev, "unable to allocate device memory\n"); 136 dev_err(&spi->dev, "unable to allocate device memory\n");
137 return -ENOMEM; 137 return -ENOMEM;
138 } 138 }
139 dev_set_drvdata(&spi->dev, chip); 139 spi_set_drvdata(spi, chip);
140 140
141 res = ds1390_get_reg(&spi->dev, DS1390_REG_SECONDS, &tmp); 141 res = ds1390_get_reg(&spi->dev, DS1390_REG_SECONDS, &tmp);
142 if (res != 0) { 142 if (res != 0) {
143 dev_err(&spi->dev, "unable to read device\n"); 143 dev_err(&spi->dev, "unable to read device\n");
144 kfree(chip);
145 return res; 144 return res;
146 } 145 }
147 146
148 chip->rtc = rtc_device_register("ds1390", 147 chip->rtc = devm_rtc_device_register(&spi->dev, "ds1390",
149 &spi->dev, &ds1390_rtc_ops, THIS_MODULE); 148 &ds1390_rtc_ops, THIS_MODULE);
150 if (IS_ERR(chip->rtc)) { 149 if (IS_ERR(chip->rtc)) {
151 dev_err(&spi->dev, "unable to register device\n"); 150 dev_err(&spi->dev, "unable to register device\n");
152 res = PTR_ERR(chip->rtc); 151 res = PTR_ERR(chip->rtc);
153 kfree(chip);
154 } 152 }
155 153
156 return res; 154 return res;
@@ -158,11 +156,6 @@ static int ds1390_probe(struct spi_device *spi)
158 156
159static int ds1390_remove(struct spi_device *spi) 157static int ds1390_remove(struct spi_device *spi)
160{ 158{
161 struct ds1390 *chip = spi_get_drvdata(spi);
162
163 rtc_device_unregister(chip->rtc);
164 kfree(chip);
165
166 return 0; 159 return 0;
167} 160}
168 161
diff --git a/drivers/rtc/rtc-ds1511.c b/drivers/rtc/rtc-ds1511.c
index 6a3fcfe3b0e7..6ce8a997cf51 100644
--- a/drivers/rtc/rtc-ds1511.c
+++ b/drivers/rtc/rtc-ds1511.c
@@ -538,15 +538,14 @@ static int ds1511_rtc_probe(struct platform_device *pdev)
538 } 538 }
539 } 539 }
540 540
541 rtc = rtc_device_register(pdev->name, &pdev->dev, &ds1511_rtc_ops, 541 rtc = devm_rtc_device_register(&pdev->dev, pdev->name, &ds1511_rtc_ops,
542 THIS_MODULE); 542 THIS_MODULE);
543 if (IS_ERR(rtc)) 543 if (IS_ERR(rtc))
544 return PTR_ERR(rtc); 544 return PTR_ERR(rtc);
545 pdata->rtc = rtc; 545 pdata->rtc = rtc;
546 546
547 ret = sysfs_create_bin_file(&pdev->dev.kobj, &ds1511_nvram_attr); 547 ret = sysfs_create_bin_file(&pdev->dev.kobj, &ds1511_nvram_attr);
548 if (ret) 548
549 rtc_device_unregister(pdata->rtc);
550 return ret; 549 return ret;
551} 550}
552 551
@@ -555,7 +554,6 @@ static int ds1511_rtc_remove(struct platform_device *pdev)
555 struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 554 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
556 555
557 sysfs_remove_bin_file(&pdev->dev.kobj, &ds1511_nvram_attr); 556 sysfs_remove_bin_file(&pdev->dev.kobj, &ds1511_nvram_attr);
558 rtc_device_unregister(pdata->rtc);
559 if (pdata->irq > 0) { 557 if (pdata->irq > 0) {
560 /* 558 /*
561 * disable the alarm interrupt 559 * disable the alarm interrupt
diff --git a/drivers/rtc/rtc-ds1553.c b/drivers/rtc/rtc-ds1553.c
index 25ce0621ade9..8c6c952e90b1 100644
--- a/drivers/rtc/rtc-ds1553.c
+++ b/drivers/rtc/rtc-ds1553.c
@@ -326,15 +326,14 @@ static int ds1553_rtc_probe(struct platform_device *pdev)
326 } 326 }
327 } 327 }
328 328
329 rtc = rtc_device_register(pdev->name, &pdev->dev, 329 rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
330 &ds1553_rtc_ops, THIS_MODULE); 330 &ds1553_rtc_ops, THIS_MODULE);
331 if (IS_ERR(rtc)) 331 if (IS_ERR(rtc))
332 return PTR_ERR(rtc); 332 return PTR_ERR(rtc);
333 pdata->rtc = rtc; 333 pdata->rtc = rtc;
334 334
335 ret = sysfs_create_bin_file(&pdev->dev.kobj, &ds1553_nvram_attr); 335 ret = sysfs_create_bin_file(&pdev->dev.kobj, &ds1553_nvram_attr);
336 if (ret) 336
337 rtc_device_unregister(rtc);
338 return ret; 337 return ret;
339} 338}
340 339
@@ -343,7 +342,6 @@ static int ds1553_rtc_remove(struct platform_device *pdev)
343 struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 342 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
344 343
345 sysfs_remove_bin_file(&pdev->dev.kobj, &ds1553_nvram_attr); 344 sysfs_remove_bin_file(&pdev->dev.kobj, &ds1553_nvram_attr);
346 rtc_device_unregister(pdata->rtc);
347 if (pdata->irq > 0) 345 if (pdata->irq > 0)
348 writeb(0, pdata->ioaddr + RTC_INTERRUPTS); 346 writeb(0, pdata->ioaddr + RTC_INTERRUPTS);
349 return 0; 347 return 0;
diff --git a/drivers/rtc/rtc-ds1672.c b/drivers/rtc/rtc-ds1672.c
index 45d65c0b3a85..3fc2a4738027 100644
--- a/drivers/rtc/rtc-ds1672.c
+++ b/drivers/rtc/rtc-ds1672.c
@@ -155,11 +155,6 @@ static const struct rtc_class_ops ds1672_rtc_ops = {
155 155
156static int ds1672_remove(struct i2c_client *client) 156static int ds1672_remove(struct i2c_client *client)
157{ 157{
158 struct rtc_device *rtc = i2c_get_clientdata(client);
159
160 if (rtc)
161 rtc_device_unregister(rtc);
162
163 return 0; 158 return 0;
164} 159}
165 160
@@ -177,7 +172,7 @@ static int ds1672_probe(struct i2c_client *client,
177 172
178 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n"); 173 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n");
179 174
180 rtc = rtc_device_register(ds1672_driver.driver.name, &client->dev, 175 rtc = devm_rtc_device_register(&client->dev, ds1672_driver.driver.name,
181 &ds1672_rtc_ops, THIS_MODULE); 176 &ds1672_rtc_ops, THIS_MODULE);
182 177
183 if (IS_ERR(rtc)) 178 if (IS_ERR(rtc))
@@ -202,7 +197,6 @@ static int ds1672_probe(struct i2c_client *client,
202 return 0; 197 return 0;
203 198
204 exit_devreg: 199 exit_devreg:
205 rtc_device_unregister(rtc);
206 return err; 200 return err;
207} 201}
208 202
diff --git a/drivers/rtc/rtc-ds1742.c b/drivers/rtc/rtc-ds1742.c
index 609c870e2cc5..eccdc62ae1c0 100644
--- a/drivers/rtc/rtc-ds1742.c
+++ b/drivers/rtc/rtc-ds1742.c
@@ -208,17 +208,14 @@ static int ds1742_rtc_probe(struct platform_device *pdev)
208 208
209 pdata->last_jiffies = jiffies; 209 pdata->last_jiffies = jiffies;
210 platform_set_drvdata(pdev, pdata); 210 platform_set_drvdata(pdev, pdata);
211 rtc = rtc_device_register(pdev->name, &pdev->dev, 211 rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
212 &ds1742_rtc_ops, THIS_MODULE); 212 &ds1742_rtc_ops, THIS_MODULE);
213 if (IS_ERR(rtc)) 213 if (IS_ERR(rtc))
214 return PTR_ERR(rtc); 214 return PTR_ERR(rtc);
215 pdata->rtc = rtc; 215 pdata->rtc = rtc;
216 216
217 ret = sysfs_create_bin_file(&pdev->dev.kobj, &pdata->nvram_attr); 217 ret = sysfs_create_bin_file(&pdev->dev.kobj, &pdata->nvram_attr);
218 if (ret) { 218
219 dev_err(&pdev->dev, "creating nvram file in sysfs failed\n");
220 rtc_device_unregister(rtc);
221 }
222 return ret; 219 return ret;
223} 220}
224 221
@@ -227,7 +224,6 @@ static int ds1742_rtc_remove(struct platform_device *pdev)
227 struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 224 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
228 225
229 sysfs_remove_bin_file(&pdev->dev.kobj, &pdata->nvram_attr); 226 sysfs_remove_bin_file(&pdev->dev.kobj, &pdata->nvram_attr);
230 rtc_device_unregister(pdata->rtc);
231 return 0; 227 return 0;
232} 228}
233 229
diff --git a/drivers/rtc/rtc-ds2404.c b/drivers/rtc/rtc-ds2404.c
index b04fc4272fb3..2ca5a23aba8a 100644
--- a/drivers/rtc/rtc-ds2404.c
+++ b/drivers/rtc/rtc-ds2404.c
@@ -228,7 +228,7 @@ static int rtc_probe(struct platform_device *pdev)
228 struct ds2404 *chip; 228 struct ds2404 *chip;
229 int retval = -EBUSY; 229 int retval = -EBUSY;
230 230
231 chip = kzalloc(sizeof(struct ds2404), GFP_KERNEL); 231 chip = devm_kzalloc(&pdev->dev, sizeof(struct ds2404), GFP_KERNEL);
232 if (!chip) 232 if (!chip)
233 return -ENOMEM; 233 return -ENOMEM;
234 234
@@ -244,8 +244,8 @@ static int rtc_probe(struct platform_device *pdev)
244 244
245 platform_set_drvdata(pdev, chip); 245 platform_set_drvdata(pdev, chip);
246 246
247 chip->rtc = rtc_device_register("ds2404", 247 chip->rtc = devm_rtc_device_register(&pdev->dev, "ds2404",
248 &pdev->dev, &ds2404_rtc_ops, THIS_MODULE); 248 &ds2404_rtc_ops, THIS_MODULE);
249 if (IS_ERR(chip->rtc)) { 249 if (IS_ERR(chip->rtc)) {
250 retval = PTR_ERR(chip->rtc); 250 retval = PTR_ERR(chip->rtc);
251 goto err_io; 251 goto err_io;
@@ -257,20 +257,14 @@ static int rtc_probe(struct platform_device *pdev)
257err_io: 257err_io:
258 chip->ops->unmap_io(chip); 258 chip->ops->unmap_io(chip);
259err_chip: 259err_chip:
260 kfree(chip);
261 return retval; 260 return retval;
262} 261}
263 262
264static int rtc_remove(struct platform_device *dev) 263static int rtc_remove(struct platform_device *dev)
265{ 264{
266 struct ds2404 *chip = platform_get_drvdata(dev); 265 struct ds2404 *chip = platform_get_drvdata(dev);
267 struct rtc_device *rtc = chip->rtc;
268
269 if (rtc)
270 rtc_device_unregister(rtc);
271 266
272 chip->ops->unmap_io(chip); 267 chip->ops->unmap_io(chip);
273 kfree(chip);
274 268
275 return 0; 269 return 0;
276} 270}
diff --git a/drivers/rtc/rtc-ds3232.c b/drivers/rtc/rtc-ds3232.c
index db0ca08db315..b83bb5a527f8 100644
--- a/drivers/rtc/rtc-ds3232.c
+++ b/drivers/rtc/rtc-ds3232.c
@@ -397,7 +397,7 @@ static int ds3232_probe(struct i2c_client *client,
397 struct ds3232 *ds3232; 397 struct ds3232 *ds3232;
398 int ret; 398 int ret;
399 399
400 ds3232 = kzalloc(sizeof(struct ds3232), GFP_KERNEL); 400 ds3232 = devm_kzalloc(&client->dev, sizeof(struct ds3232), GFP_KERNEL);
401 if (!ds3232) 401 if (!ds3232)
402 return -ENOMEM; 402 return -ENOMEM;
403 403
@@ -409,34 +409,25 @@ static int ds3232_probe(struct i2c_client *client,
409 409
410 ret = ds3232_check_rtc_status(client); 410 ret = ds3232_check_rtc_status(client);
411 if (ret) 411 if (ret)
412 goto out_free; 412 return ret;
413 413
414 ds3232->rtc = rtc_device_register(client->name, &client->dev, 414 ds3232->rtc = devm_rtc_device_register(&client->dev, client->name,
415 &ds3232_rtc_ops, THIS_MODULE); 415 &ds3232_rtc_ops, THIS_MODULE);
416 if (IS_ERR(ds3232->rtc)) { 416 if (IS_ERR(ds3232->rtc)) {
417 ret = PTR_ERR(ds3232->rtc);
418 dev_err(&client->dev, "unable to register the class device\n"); 417 dev_err(&client->dev, "unable to register the class device\n");
419 goto out_irq; 418 return PTR_ERR(ds3232->rtc);
420 } 419 }
421 420
422 if (client->irq >= 0) { 421 if (client->irq >= 0) {
423 ret = request_irq(client->irq, ds3232_irq, 0, 422 ret = devm_request_irq(&client->dev, client->irq, ds3232_irq, 0,
424 "ds3232", client); 423 "ds3232", client);
425 if (ret) { 424 if (ret) {
426 dev_err(&client->dev, "unable to request IRQ\n"); 425 dev_err(&client->dev, "unable to request IRQ\n");
427 goto out_free; 426 return ret;
428 } 427 }
429 } 428 }
430 429
431 return 0; 430 return 0;
432
433out_irq:
434 if (client->irq >= 0)
435 free_irq(client->irq, client);
436
437out_free:
438 kfree(ds3232);
439 return ret;
440} 431}
441 432
442static int ds3232_remove(struct i2c_client *client) 433static int ds3232_remove(struct i2c_client *client)
@@ -448,12 +439,10 @@ static int ds3232_remove(struct i2c_client *client)
448 ds3232->exiting = 1; 439 ds3232->exiting = 1;
449 mutex_unlock(&ds3232->mutex); 440 mutex_unlock(&ds3232->mutex);
450 441
451 free_irq(client->irq, client); 442 devm_free_irq(&client->dev, client->irq, client);
452 cancel_work_sync(&ds3232->work); 443 cancel_work_sync(&ds3232->work);
453 } 444 }
454 445
455 rtc_device_unregister(ds3232->rtc);
456 kfree(ds3232);
457 return 0; 446 return 0;
458} 447}
459 448
diff --git a/drivers/rtc/rtc-ds3234.c b/drivers/rtc/rtc-ds3234.c
index 7a4495ef1c39..ba98c0e9580d 100644
--- a/drivers/rtc/rtc-ds3234.c
+++ b/drivers/rtc/rtc-ds3234.c
@@ -146,21 +146,18 @@ static int ds3234_probe(struct spi_device *spi)
146 ds3234_get_reg(&spi->dev, DS3234_REG_CONT_STAT, &tmp); 146 ds3234_get_reg(&spi->dev, DS3234_REG_CONT_STAT, &tmp);
147 dev_info(&spi->dev, "Ctrl/Stat Reg: 0x%02x\n", tmp); 147 dev_info(&spi->dev, "Ctrl/Stat Reg: 0x%02x\n", tmp);
148 148
149 rtc = rtc_device_register("ds3234", 149 rtc = devm_rtc_device_register(&spi->dev, "ds3234",
150 &spi->dev, &ds3234_rtc_ops, THIS_MODULE); 150 &ds3234_rtc_ops, THIS_MODULE);
151 if (IS_ERR(rtc)) 151 if (IS_ERR(rtc))
152 return PTR_ERR(rtc); 152 return PTR_ERR(rtc);
153 153
154 dev_set_drvdata(&spi->dev, rtc); 154 spi_set_drvdata(spi, rtc);
155 155
156 return 0; 156 return 0;
157} 157}
158 158
159static int ds3234_remove(struct spi_device *spi) 159static int ds3234_remove(struct spi_device *spi)
160{ 160{
161 struct rtc_device *rtc = spi_get_drvdata(spi);
162
163 rtc_device_unregister(rtc);
164 return 0; 161 return 0;
165} 162}
166 163
diff --git a/drivers/rtc/rtc-efi.c b/drivers/rtc/rtc-efi.c
index 1a0c37c9152b..b3c8c0b1709d 100644
--- a/drivers/rtc/rtc-efi.c
+++ b/drivers/rtc/rtc-efi.c
@@ -191,7 +191,7 @@ static int __init efi_rtc_probe(struct platform_device *dev)
191{ 191{
192 struct rtc_device *rtc; 192 struct rtc_device *rtc;
193 193
194 rtc = rtc_device_register("rtc-efi", &dev->dev, &efi_rtc_ops, 194 rtc = devm_rtc_device_register(&dev->dev, "rtc-efi", &efi_rtc_ops,
195 THIS_MODULE); 195 THIS_MODULE);
196 if (IS_ERR(rtc)) 196 if (IS_ERR(rtc))
197 return PTR_ERR(rtc); 197 return PTR_ERR(rtc);
@@ -203,10 +203,6 @@ static int __init efi_rtc_probe(struct platform_device *dev)
203 203
204static int __exit efi_rtc_remove(struct platform_device *dev) 204static int __exit efi_rtc_remove(struct platform_device *dev)
205{ 205{
206 struct rtc_device *rtc = platform_get_drvdata(dev);
207
208 rtc_device_unregister(rtc);
209
210 return 0; 206 return 0;
211} 207}
212 208
@@ -218,18 +214,7 @@ static struct platform_driver efi_rtc_driver = {
218 .remove = __exit_p(efi_rtc_remove), 214 .remove = __exit_p(efi_rtc_remove),
219}; 215};
220 216
221static int __init efi_rtc_init(void) 217module_platform_driver_probe(efi_rtc_driver, efi_rtc_probe);
222{
223 return platform_driver_probe(&efi_rtc_driver, efi_rtc_probe);
224}
225
226static void __exit efi_rtc_exit(void)
227{
228 platform_driver_unregister(&efi_rtc_driver);
229}
230
231module_init(efi_rtc_init);
232module_exit(efi_rtc_exit);
233 218
234MODULE_AUTHOR("dann frazier <dannf@hp.com>"); 219MODULE_AUTHOR("dann frazier <dannf@hp.com>");
235MODULE_LICENSE("GPL"); 220MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-em3027.c b/drivers/rtc/rtc-em3027.c
index f6c24ce35d36..3f9eb57d0486 100644
--- a/drivers/rtc/rtc-em3027.c
+++ b/drivers/rtc/rtc-em3027.c
@@ -121,7 +121,7 @@ static int em3027_probe(struct i2c_client *client,
121 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) 121 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
122 return -ENODEV; 122 return -ENODEV;
123 123
124 rtc = rtc_device_register(em3027_driver.driver.name, &client->dev, 124 rtc = devm_rtc_device_register(&client->dev, em3027_driver.driver.name,
125 &em3027_rtc_ops, THIS_MODULE); 125 &em3027_rtc_ops, THIS_MODULE);
126 if (IS_ERR(rtc)) 126 if (IS_ERR(rtc))
127 return PTR_ERR(rtc); 127 return PTR_ERR(rtc);
@@ -133,11 +133,6 @@ static int em3027_probe(struct i2c_client *client,
133 133
134static int em3027_remove(struct i2c_client *client) 134static int em3027_remove(struct i2c_client *client)
135{ 135{
136 struct rtc_device *rtc = i2c_get_clientdata(client);
137
138 if (rtc)
139 rtc_device_unregister(rtc);
140
141 return 0; 136 return 0;
142} 137}
143 138
diff --git a/drivers/rtc/rtc-ep93xx.c b/drivers/rtc/rtc-ep93xx.c
index 1a4e5e4a70cd..5807b77c444a 100644
--- a/drivers/rtc/rtc-ep93xx.c
+++ b/drivers/rtc/rtc-ep93xx.c
@@ -153,8 +153,8 @@ static int ep93xx_rtc_probe(struct platform_device *pdev)
153 pdev->dev.platform_data = ep93xx_rtc; 153 pdev->dev.platform_data = ep93xx_rtc;
154 platform_set_drvdata(pdev, ep93xx_rtc); 154 platform_set_drvdata(pdev, ep93xx_rtc);
155 155
156 ep93xx_rtc->rtc = rtc_device_register(pdev->name, 156 ep93xx_rtc->rtc = devm_rtc_device_register(&pdev->dev,
157 &pdev->dev, &ep93xx_rtc_ops, THIS_MODULE); 157 pdev->name, &ep93xx_rtc_ops, THIS_MODULE);
158 if (IS_ERR(ep93xx_rtc->rtc)) { 158 if (IS_ERR(ep93xx_rtc->rtc)) {
159 err = PTR_ERR(ep93xx_rtc->rtc); 159 err = PTR_ERR(ep93xx_rtc->rtc);
160 goto exit; 160 goto exit;
@@ -162,12 +162,10 @@ static int ep93xx_rtc_probe(struct platform_device *pdev)
162 162
163 err = sysfs_create_group(&pdev->dev.kobj, &ep93xx_rtc_sysfs_files); 163 err = sysfs_create_group(&pdev->dev.kobj, &ep93xx_rtc_sysfs_files);
164 if (err) 164 if (err)
165 goto fail; 165 goto exit;
166 166
167 return 0; 167 return 0;
168 168
169fail:
170 rtc_device_unregister(ep93xx_rtc->rtc);
171exit: 169exit:
172 platform_set_drvdata(pdev, NULL); 170 platform_set_drvdata(pdev, NULL);
173 pdev->dev.platform_data = NULL; 171 pdev->dev.platform_data = NULL;
@@ -176,11 +174,8 @@ exit:
176 174
177static int ep93xx_rtc_remove(struct platform_device *pdev) 175static int ep93xx_rtc_remove(struct platform_device *pdev)
178{ 176{
179 struct ep93xx_rtc *ep93xx_rtc = platform_get_drvdata(pdev);
180
181 sysfs_remove_group(&pdev->dev.kobj, &ep93xx_rtc_sysfs_files); 177 sysfs_remove_group(&pdev->dev.kobj, &ep93xx_rtc_sysfs_files);
182 platform_set_drvdata(pdev, NULL); 178 platform_set_drvdata(pdev, NULL);
183 rtc_device_unregister(ep93xx_rtc->rtc);
184 pdev->dev.platform_data = NULL; 179 pdev->dev.platform_data = NULL;
185 180
186 return 0; 181 return 0;
diff --git a/drivers/rtc/rtc-fm3130.c b/drivers/rtc/rtc-fm3130.c
index bff3cdc5140e..2835fb6c1965 100644
--- a/drivers/rtc/rtc-fm3130.c
+++ b/drivers/rtc/rtc-fm3130.c
@@ -358,7 +358,7 @@ static int fm3130_probe(struct i2c_client *client,
358 I2C_FUNC_I2C | I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) 358 I2C_FUNC_I2C | I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
359 return -EIO; 359 return -EIO;
360 360
361 fm3130 = kzalloc(sizeof(struct fm3130), GFP_KERNEL); 361 fm3130 = devm_kzalloc(&client->dev, sizeof(struct fm3130), GFP_KERNEL);
362 362
363 if (!fm3130) 363 if (!fm3130)
364 return -ENOMEM; 364 return -ENOMEM;
@@ -395,7 +395,7 @@ static int fm3130_probe(struct i2c_client *client,
395 395
396 tmp = i2c_transfer(adapter, fm3130->msg, 4); 396 tmp = i2c_transfer(adapter, fm3130->msg, 4);
397 if (tmp != 4) { 397 if (tmp != 4) {
398 pr_debug("read error %d\n", tmp); 398 dev_dbg(&client->dev, "read error %d\n", tmp);
399 err = -EIO; 399 err = -EIO;
400 goto exit_free; 400 goto exit_free;
401 } 401 }
@@ -507,7 +507,7 @@ bad_clock:
507 507
508 /* We won't bail out here because we just got invalid data. 508 /* We won't bail out here because we just got invalid data.
509 Time setting from u-boot doesn't work anyway */ 509 Time setting from u-boot doesn't work anyway */
510 fm3130->rtc = rtc_device_register(client->name, &client->dev, 510 fm3130->rtc = devm_rtc_device_register(&client->dev, client->name,
511 &fm3130_rtc_ops, THIS_MODULE); 511 &fm3130_rtc_ops, THIS_MODULE);
512 if (IS_ERR(fm3130->rtc)) { 512 if (IS_ERR(fm3130->rtc)) {
513 err = PTR_ERR(fm3130->rtc); 513 err = PTR_ERR(fm3130->rtc);
@@ -517,16 +517,11 @@ bad_clock:
517 } 517 }
518 return 0; 518 return 0;
519exit_free: 519exit_free:
520 kfree(fm3130);
521 return err; 520 return err;
522} 521}
523 522
524static int fm3130_remove(struct i2c_client *client) 523static int fm3130_remove(struct i2c_client *client)
525{ 524{
526 struct fm3130 *fm3130 = i2c_get_clientdata(client);
527
528 rtc_device_unregister(fm3130->rtc);
529 kfree(fm3130);
530 return 0; 525 return 0;
531} 526}
532 527
diff --git a/drivers/rtc/rtc-generic.c b/drivers/rtc/rtc-generic.c
index 98322004ad2e..06279ce6bff2 100644
--- a/drivers/rtc/rtc-generic.c
+++ b/drivers/rtc/rtc-generic.c
@@ -38,8 +38,8 @@ static int __init generic_rtc_probe(struct platform_device *dev)
38{ 38{
39 struct rtc_device *rtc; 39 struct rtc_device *rtc;
40 40
41 rtc = rtc_device_register("rtc-generic", &dev->dev, &generic_rtc_ops, 41 rtc = devm_rtc_device_register(&dev->dev, "rtc-generic",
42 THIS_MODULE); 42 &generic_rtc_ops, THIS_MODULE);
43 if (IS_ERR(rtc)) 43 if (IS_ERR(rtc))
44 return PTR_ERR(rtc); 44 return PTR_ERR(rtc);
45 45
@@ -50,10 +50,6 @@ static int __init generic_rtc_probe(struct platform_device *dev)
50 50
51static int __exit generic_rtc_remove(struct platform_device *dev) 51static int __exit generic_rtc_remove(struct platform_device *dev)
52{ 52{
53 struct rtc_device *rtc = platform_get_drvdata(dev);
54
55 rtc_device_unregister(rtc);
56
57 return 0; 53 return 0;
58} 54}
59 55
@@ -65,18 +61,7 @@ static struct platform_driver generic_rtc_driver = {
65 .remove = __exit_p(generic_rtc_remove), 61 .remove = __exit_p(generic_rtc_remove),
66}; 62};
67 63
68static int __init generic_rtc_init(void) 64module_platform_driver_probe(generic_rtc_driver, generic_rtc_probe);
69{
70 return platform_driver_probe(&generic_rtc_driver, generic_rtc_probe);
71}
72
73static void __exit generic_rtc_fini(void)
74{
75 platform_driver_unregister(&generic_rtc_driver);
76}
77
78module_init(generic_rtc_init);
79module_exit(generic_rtc_fini);
80 65
81MODULE_AUTHOR("Kyle McMartin <kyle@mcmartin.ca>"); 66MODULE_AUTHOR("Kyle McMartin <kyle@mcmartin.ca>");
82MODULE_LICENSE("GPL"); 67MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-hid-sensor-time.c b/drivers/rtc/rtc-hid-sensor-time.c
index 31c5728ef629..63024505dddc 100644
--- a/drivers/rtc/rtc-hid-sensor-time.c
+++ b/drivers/rtc/rtc-hid-sensor-time.c
@@ -255,8 +255,9 @@ static int hid_time_probe(struct platform_device *pdev)
255 return ret; 255 return ret;
256 } 256 }
257 257
258 time_state->rtc = rtc_device_register("hid-sensor-time", 258 time_state->rtc = devm_rtc_device_register(&pdev->dev,
259 &pdev->dev, &hid_time_rtc_ops, THIS_MODULE); 259 "hid-sensor-time", &hid_time_rtc_ops,
260 THIS_MODULE);
260 261
261 if (IS_ERR(time_state->rtc)) { 262 if (IS_ERR(time_state->rtc)) {
262 dev_err(&pdev->dev, "rtc device register failed!\n"); 263 dev_err(&pdev->dev, "rtc device register failed!\n");
@@ -269,9 +270,7 @@ static int hid_time_probe(struct platform_device *pdev)
269static int hid_time_remove(struct platform_device *pdev) 270static int hid_time_remove(struct platform_device *pdev)
270{ 271{
271 struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; 272 struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
272 struct hid_time_state *time_state = platform_get_drvdata(pdev);
273 273
274 rtc_device_unregister(time_state->rtc);
275 sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_TIME); 274 sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_TIME);
276 275
277 return 0; 276 return 0;
diff --git a/drivers/rtc/rtc-imxdi.c b/drivers/rtc/rtc-imxdi.c
index 82aad695979e..d3a8c8e255de 100644
--- a/drivers/rtc/rtc-imxdi.c
+++ b/drivers/rtc/rtc-imxdi.c
@@ -369,7 +369,7 @@ static void dryice_work(struct work_struct *work)
369/* 369/*
370 * probe for dryice rtc device 370 * probe for dryice rtc device
371 */ 371 */
372static int dryice_rtc_probe(struct platform_device *pdev) 372static int __init dryice_rtc_probe(struct platform_device *pdev)
373{ 373{
374 struct resource *res; 374 struct resource *res;
375 struct imxdi_dev *imxdi; 375 struct imxdi_dev *imxdi;
@@ -464,7 +464,7 @@ static int dryice_rtc_probe(struct platform_device *pdev)
464 } 464 }
465 465
466 platform_set_drvdata(pdev, imxdi); 466 platform_set_drvdata(pdev, imxdi);
467 imxdi->rtc = rtc_device_register(pdev->name, &pdev->dev, 467 imxdi->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
468 &dryice_rtc_ops, THIS_MODULE); 468 &dryice_rtc_ops, THIS_MODULE);
469 if (IS_ERR(imxdi->rtc)) { 469 if (IS_ERR(imxdi->rtc)) {
470 rc = PTR_ERR(imxdi->rtc); 470 rc = PTR_ERR(imxdi->rtc);
@@ -479,7 +479,7 @@ err:
479 return rc; 479 return rc;
480} 480}
481 481
482static int dryice_rtc_remove(struct platform_device *pdev) 482static int __exit dryice_rtc_remove(struct platform_device *pdev)
483{ 483{
484 struct imxdi_dev *imxdi = platform_get_drvdata(pdev); 484 struct imxdi_dev *imxdi = platform_get_drvdata(pdev);
485 485
@@ -488,8 +488,6 @@ static int dryice_rtc_remove(struct platform_device *pdev)
488 /* mask all interrupts */ 488 /* mask all interrupts */
489 __raw_writel(0, imxdi->ioaddr + DIER); 489 __raw_writel(0, imxdi->ioaddr + DIER);
490 490
491 rtc_device_unregister(imxdi->rtc);
492
493 clk_disable_unprepare(imxdi->clk); 491 clk_disable_unprepare(imxdi->clk);
494 492
495 return 0; 493 return 0;
@@ -510,21 +508,10 @@ static struct platform_driver dryice_rtc_driver = {
510 .owner = THIS_MODULE, 508 .owner = THIS_MODULE,
511 .of_match_table = of_match_ptr(dryice_dt_ids), 509 .of_match_table = of_match_ptr(dryice_dt_ids),
512 }, 510 },
513 .remove = dryice_rtc_remove, 511 .remove = __exit_p(dryice_rtc_remove),
514}; 512};
515 513
516static int __init dryice_rtc_init(void) 514module_platform_driver_probe(dryice_rtc_driver, dryice_rtc_probe);
517{
518 return platform_driver_probe(&dryice_rtc_driver, dryice_rtc_probe);
519}
520
521static void __exit dryice_rtc_exit(void)
522{
523 platform_driver_unregister(&dryice_rtc_driver);
524}
525
526module_init(dryice_rtc_init);
527module_exit(dryice_rtc_exit);
528 515
529MODULE_AUTHOR("Freescale Semiconductor, Inc."); 516MODULE_AUTHOR("Freescale Semiconductor, Inc.");
530MODULE_AUTHOR("Baruch Siach <baruch@tkos.co.il>"); 517MODULE_AUTHOR("Baruch Siach <baruch@tkos.co.il>");
diff --git a/drivers/rtc/rtc-isl12022.c b/drivers/rtc/rtc-isl12022.c
index 6b4298ea683d..a1bbbb8de029 100644
--- a/drivers/rtc/rtc-isl12022.c
+++ b/drivers/rtc/rtc-isl12022.c
@@ -252,12 +252,11 @@ static int isl12022_probe(struct i2c_client *client,
252{ 252{
253 struct isl12022 *isl12022; 253 struct isl12022 *isl12022;
254 254
255 int ret = 0;
256
257 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) 255 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
258 return -ENODEV; 256 return -ENODEV;
259 257
260 isl12022 = kzalloc(sizeof(struct isl12022), GFP_KERNEL); 258 isl12022 = devm_kzalloc(&client->dev, sizeof(struct isl12022),
259 GFP_KERNEL);
261 if (!isl12022) 260 if (!isl12022)
262 return -ENOMEM; 261 return -ENOMEM;
263 262
@@ -265,37 +264,22 @@ static int isl12022_probe(struct i2c_client *client,
265 264
266 i2c_set_clientdata(client, isl12022); 265 i2c_set_clientdata(client, isl12022);
267 266
268 isl12022->rtc = rtc_device_register(isl12022_driver.driver.name, 267 isl12022->rtc = devm_rtc_device_register(&client->dev,
269 &client->dev, 268 isl12022_driver.driver.name,
270 &isl12022_rtc_ops, 269 &isl12022_rtc_ops, THIS_MODULE);
271 THIS_MODULE); 270 if (IS_ERR(isl12022->rtc))
272 271 return PTR_ERR(isl12022->rtc);
273 if (IS_ERR(isl12022->rtc)) {
274 ret = PTR_ERR(isl12022->rtc);
275 goto exit_kfree;
276 }
277 272
278 return 0; 273 return 0;
279
280exit_kfree:
281 kfree(isl12022);
282
283 return ret;
284} 274}
285 275
286static int isl12022_remove(struct i2c_client *client) 276static int isl12022_remove(struct i2c_client *client)
287{ 277{
288 struct isl12022 *isl12022 = i2c_get_clientdata(client);
289
290 rtc_device_unregister(isl12022->rtc);
291 kfree(isl12022);
292
293 return 0; 278 return 0;
294} 279}
295 280
296static const struct i2c_device_id isl12022_id[] = { 281static const struct i2c_device_id isl12022_id[] = {
297 { "isl12022", 0 }, 282 { "isl12022", 0 },
298 { "rtc8564", 0 },
299 { } 283 { }
300}; 284};
301MODULE_DEVICE_TABLE(i2c, isl12022_id); 285MODULE_DEVICE_TABLE(i2c, isl12022_id);
diff --git a/drivers/rtc/rtc-lp8788.c b/drivers/rtc/rtc-lp8788.c
index 9a4631218f41..9853ac15b296 100644
--- a/drivers/rtc/rtc-lp8788.c
+++ b/drivers/rtc/rtc-lp8788.c
@@ -299,7 +299,7 @@ static int lp8788_rtc_probe(struct platform_device *pdev)
299 299
300 device_init_wakeup(dev, 1); 300 device_init_wakeup(dev, 1);
301 301
302 rtc->rdev = rtc_device_register("lp8788_rtc", dev, 302 rtc->rdev = devm_rtc_device_register(dev, "lp8788_rtc",
303 &lp8788_rtc_ops, THIS_MODULE); 303 &lp8788_rtc_ops, THIS_MODULE);
304 if (IS_ERR(rtc->rdev)) { 304 if (IS_ERR(rtc->rdev)) {
305 dev_err(dev, "can not register rtc device\n"); 305 dev_err(dev, "can not register rtc device\n");
@@ -314,9 +314,6 @@ static int lp8788_rtc_probe(struct platform_device *pdev)
314 314
315static int lp8788_rtc_remove(struct platform_device *pdev) 315static int lp8788_rtc_remove(struct platform_device *pdev)
316{ 316{
317 struct lp8788_rtc *rtc = platform_get_drvdata(pdev);
318
319 rtc_device_unregister(rtc->rdev);
320 platform_set_drvdata(pdev, NULL); 317 platform_set_drvdata(pdev, NULL);
321 318
322 return 0; 319 return 0;
diff --git a/drivers/rtc/rtc-lpc32xx.c b/drivers/rtc/rtc-lpc32xx.c
index 40a598332bac..787550d756e9 100644
--- a/drivers/rtc/rtc-lpc32xx.c
+++ b/drivers/rtc/rtc-lpc32xx.c
@@ -273,8 +273,8 @@ static int lpc32xx_rtc_probe(struct platform_device *pdev)
273 273
274 platform_set_drvdata(pdev, rtc); 274 platform_set_drvdata(pdev, rtc);
275 275
276 rtc->rtc = rtc_device_register(RTC_NAME, &pdev->dev, &lpc32xx_rtc_ops, 276 rtc->rtc = devm_rtc_device_register(&pdev->dev, RTC_NAME,
277 THIS_MODULE); 277 &lpc32xx_rtc_ops, THIS_MODULE);
278 if (IS_ERR(rtc->rtc)) { 278 if (IS_ERR(rtc->rtc)) {
279 dev_err(&pdev->dev, "Can't get RTC\n"); 279 dev_err(&pdev->dev, "Can't get RTC\n");
280 platform_set_drvdata(pdev, NULL); 280 platform_set_drvdata(pdev, NULL);
@@ -307,7 +307,6 @@ static int lpc32xx_rtc_remove(struct platform_device *pdev)
307 device_init_wakeup(&pdev->dev, 0); 307 device_init_wakeup(&pdev->dev, 0);
308 308
309 platform_set_drvdata(pdev, NULL); 309 platform_set_drvdata(pdev, NULL);
310 rtc_device_unregister(rtc->rtc);
311 310
312 return 0; 311 return 0;
313} 312}
diff --git a/drivers/rtc/rtc-ls1x.c b/drivers/rtc/rtc-ls1x.c
index f59b6349551a..db82f91f4562 100644
--- a/drivers/rtc/rtc-ls1x.c
+++ b/drivers/rtc/rtc-ls1x.c
@@ -172,7 +172,7 @@ static int ls1x_rtc_probe(struct platform_device *pdev)
172 while (readl(SYS_COUNTER_CNTRL) & SYS_CNTRL_TTS) 172 while (readl(SYS_COUNTER_CNTRL) & SYS_CNTRL_TTS)
173 usleep_range(1000, 3000); 173 usleep_range(1000, 3000);
174 174
175 rtcdev = rtc_device_register("ls1x-rtc", &pdev->dev, 175 rtcdev = devm_rtc_device_register(&pdev->dev, "ls1x-rtc",
176 &ls1x_rtc_ops , THIS_MODULE); 176 &ls1x_rtc_ops , THIS_MODULE);
177 if (IS_ERR(rtcdev)) { 177 if (IS_ERR(rtcdev)) {
178 ret = PTR_ERR(rtcdev); 178 ret = PTR_ERR(rtcdev);
@@ -187,9 +187,6 @@ err:
187 187
188static int ls1x_rtc_remove(struct platform_device *pdev) 188static int ls1x_rtc_remove(struct platform_device *pdev)
189{ 189{
190 struct rtc_device *rtcdev = platform_get_drvdata(pdev);
191
192 rtc_device_unregister(rtcdev);
193 platform_set_drvdata(pdev, NULL); 190 platform_set_drvdata(pdev, NULL);
194 191
195 return 0; 192 return 0;
diff --git a/drivers/rtc/rtc-m41t80.c b/drivers/rtc/rtc-m41t80.c
index b885bcd08908..89674b5e6efd 100644
--- a/drivers/rtc/rtc-m41t80.c
+++ b/drivers/rtc/rtc-m41t80.c
@@ -637,7 +637,8 @@ static int m41t80_probe(struct i2c_client *client,
637 dev_info(&client->dev, 637 dev_info(&client->dev,
638 "chip found, driver version " DRV_VERSION "\n"); 638 "chip found, driver version " DRV_VERSION "\n");
639 639
640 clientdata = kzalloc(sizeof(*clientdata), GFP_KERNEL); 640 clientdata = devm_kzalloc(&client->dev, sizeof(*clientdata),
641 GFP_KERNEL);
641 if (!clientdata) { 642 if (!clientdata) {
642 rc = -ENOMEM; 643 rc = -ENOMEM;
643 goto exit; 644 goto exit;
@@ -646,8 +647,8 @@ static int m41t80_probe(struct i2c_client *client,
646 clientdata->features = id->driver_data; 647 clientdata->features = id->driver_data;
647 i2c_set_clientdata(client, clientdata); 648 i2c_set_clientdata(client, clientdata);
648 649
649 rtc = rtc_device_register(client->name, &client->dev, 650 rtc = devm_rtc_device_register(&client->dev, client->name,
650 &m41t80_rtc_ops, THIS_MODULE); 651 &m41t80_rtc_ops, THIS_MODULE);
651 if (IS_ERR(rtc)) { 652 if (IS_ERR(rtc)) {
652 rc = PTR_ERR(rtc); 653 rc = PTR_ERR(rtc);
653 rtc = NULL; 654 rtc = NULL;
@@ -718,26 +719,19 @@ ht_err:
718 goto exit; 719 goto exit;
719 720
720exit: 721exit:
721 if (rtc)
722 rtc_device_unregister(rtc);
723 kfree(clientdata);
724 return rc; 722 return rc;
725} 723}
726 724
727static int m41t80_remove(struct i2c_client *client) 725static int m41t80_remove(struct i2c_client *client)
728{ 726{
727#ifdef CONFIG_RTC_DRV_M41T80_WDT
729 struct m41t80_data *clientdata = i2c_get_clientdata(client); 728 struct m41t80_data *clientdata = i2c_get_clientdata(client);
730 struct rtc_device *rtc = clientdata->rtc;
731 729
732#ifdef CONFIG_RTC_DRV_M41T80_WDT
733 if (clientdata->features & M41T80_FEATURE_HT) { 730 if (clientdata->features & M41T80_FEATURE_HT) {
734 misc_deregister(&wdt_dev); 731 misc_deregister(&wdt_dev);
735 unregister_reboot_notifier(&wdt_notifier); 732 unregister_reboot_notifier(&wdt_notifier);
736 } 733 }
737#endif 734#endif
738 if (rtc)
739 rtc_device_unregister(rtc);
740 kfree(clientdata);
741 735
742 return 0; 736 return 0;
743} 737}
diff --git a/drivers/rtc/rtc-m41t93.c b/drivers/rtc/rtc-m41t93.c
index 49169680786e..9707d36e8b15 100644
--- a/drivers/rtc/rtc-m41t93.c
+++ b/drivers/rtc/rtc-m41t93.c
@@ -184,12 +184,12 @@ static int m41t93_probe(struct spi_device *spi)
184 return -ENODEV; 184 return -ENODEV;
185 } 185 }
186 186
187 rtc = rtc_device_register(m41t93_driver.driver.name, 187 rtc = devm_rtc_device_register(&spi->dev, m41t93_driver.driver.name,
188 &spi->dev, &m41t93_rtc_ops, THIS_MODULE); 188 &m41t93_rtc_ops, THIS_MODULE);
189 if (IS_ERR(rtc)) 189 if (IS_ERR(rtc))
190 return PTR_ERR(rtc); 190 return PTR_ERR(rtc);
191 191
192 dev_set_drvdata(&spi->dev, rtc); 192 spi_set_drvdata(spi, rtc);
193 193
194 return 0; 194 return 0;
195} 195}
@@ -197,11 +197,6 @@ static int m41t93_probe(struct spi_device *spi)
197 197
198static int m41t93_remove(struct spi_device *spi) 198static int m41t93_remove(struct spi_device *spi)
199{ 199{
200 struct rtc_device *rtc = spi_get_drvdata(spi);
201
202 if (rtc)
203 rtc_device_unregister(rtc);
204
205 return 0; 200 return 0;
206} 201}
207 202
diff --git a/drivers/rtc/rtc-m41t94.c b/drivers/rtc/rtc-m41t94.c
index 89266c6764bc..7454ef0a4cfa 100644
--- a/drivers/rtc/rtc-m41t94.c
+++ b/drivers/rtc/rtc-m41t94.c
@@ -124,23 +124,18 @@ static int m41t94_probe(struct spi_device *spi)
124 return res; 124 return res;
125 } 125 }
126 126
127 rtc = rtc_device_register(m41t94_driver.driver.name, 127 rtc = devm_rtc_device_register(&spi->dev, m41t94_driver.driver.name,
128 &spi->dev, &m41t94_rtc_ops, THIS_MODULE); 128 &m41t94_rtc_ops, THIS_MODULE);
129 if (IS_ERR(rtc)) 129 if (IS_ERR(rtc))
130 return PTR_ERR(rtc); 130 return PTR_ERR(rtc);
131 131
132 dev_set_drvdata(&spi->dev, rtc); 132 spi_set_drvdata(spi, rtc);
133 133
134 return 0; 134 return 0;
135} 135}
136 136
137static int m41t94_remove(struct spi_device *spi) 137static int m41t94_remove(struct spi_device *spi)
138{ 138{
139 struct rtc_device *rtc = spi_get_drvdata(spi);
140
141 if (rtc)
142 rtc_device_unregister(rtc);
143
144 return 0; 139 return 0;
145} 140}
146 141
diff --git a/drivers/rtc/rtc-m48t35.c b/drivers/rtc/rtc-m48t35.c
index 31c9190a1fcb..37444246e5e4 100644
--- a/drivers/rtc/rtc-m48t35.c
+++ b/drivers/rtc/rtc-m48t35.c
@@ -145,12 +145,11 @@ static int m48t35_probe(struct platform_device *pdev)
145{ 145{
146 struct resource *res; 146 struct resource *res;
147 struct m48t35_priv *priv; 147 struct m48t35_priv *priv;
148 int ret = 0;
149 148
150 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 149 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
151 if (!res) 150 if (!res)
152 return -ENODEV; 151 return -ENODEV;
153 priv = kzalloc(sizeof(struct m48t35_priv), GFP_KERNEL); 152 priv = devm_kzalloc(&pdev->dev, sizeof(struct m48t35_priv), GFP_KERNEL);
154 if (!priv) 153 if (!priv)
155 return -ENOMEM; 154 return -ENOMEM;
156 155
@@ -160,50 +159,29 @@ static int m48t35_probe(struct platform_device *pdev)
160 * conflicts are resolved 159 * conflicts are resolved
161 */ 160 */
162#ifndef CONFIG_SGI_IP27 161#ifndef CONFIG_SGI_IP27
163 if (!request_mem_region(res->start, priv->size, pdev->name)) { 162 if (!devm_request_mem_region(&pdev->dev, res->start, priv->size,
164 ret = -EBUSY; 163 pdev->name))
165 goto out; 164 return -EBUSY;
166 }
167#endif 165#endif
168 priv->baseaddr = res->start; 166 priv->baseaddr = res->start;
169 priv->reg = ioremap(priv->baseaddr, priv->size); 167 priv->reg = devm_ioremap(&pdev->dev, priv->baseaddr, priv->size);
170 if (!priv->reg) { 168 if (!priv->reg)
171 ret = -ENOMEM; 169 return -ENOMEM;
172 goto out;
173 }
174 170
175 spin_lock_init(&priv->lock); 171 spin_lock_init(&priv->lock);
176 172
177 platform_set_drvdata(pdev, priv); 173 platform_set_drvdata(pdev, priv);
178 174
179 priv->rtc = rtc_device_register("m48t35", &pdev->dev, 175 priv->rtc = devm_rtc_device_register(&pdev->dev, "m48t35",
180 &m48t35_ops, THIS_MODULE); 176 &m48t35_ops, THIS_MODULE);
181 if (IS_ERR(priv->rtc)) { 177 if (IS_ERR(priv->rtc))
182 ret = PTR_ERR(priv->rtc); 178 return PTR_ERR(priv->rtc);
183 goto out;
184 }
185 179
186 return 0; 180 return 0;
187
188out:
189 if (priv->reg)
190 iounmap(priv->reg);
191 if (priv->baseaddr)
192 release_mem_region(priv->baseaddr, priv->size);
193 kfree(priv);
194 return ret;
195} 181}
196 182
197static int m48t35_remove(struct platform_device *pdev) 183static int m48t35_remove(struct platform_device *pdev)
198{ 184{
199 struct m48t35_priv *priv = platform_get_drvdata(pdev);
200
201 rtc_device_unregister(priv->rtc);
202 iounmap(priv->reg);
203#ifndef CONFIG_SGI_IP27
204 release_mem_region(priv->baseaddr, priv->size);
205#endif
206 kfree(priv);
207 return 0; 185 return 0;
208} 186}
209 187
diff --git a/drivers/rtc/rtc-m48t86.c b/drivers/rtc/rtc-m48t86.c
index 2ffbcacd2439..33a91c484533 100644
--- a/drivers/rtc/rtc-m48t86.c
+++ b/drivers/rtc/rtc-m48t86.c
@@ -148,8 +148,10 @@ static int m48t86_rtc_probe(struct platform_device *dev)
148{ 148{
149 unsigned char reg; 149 unsigned char reg;
150 struct m48t86_ops *ops = dev->dev.platform_data; 150 struct m48t86_ops *ops = dev->dev.platform_data;
151 struct rtc_device *rtc = rtc_device_register("m48t86", 151 struct rtc_device *rtc;
152 &dev->dev, &m48t86_rtc_ops, THIS_MODULE); 152
153 rtc = devm_rtc_device_register(&dev->dev, "m48t86",
154 &m48t86_rtc_ops, THIS_MODULE);
153 155
154 if (IS_ERR(rtc)) 156 if (IS_ERR(rtc))
155 return PTR_ERR(rtc); 157 return PTR_ERR(rtc);
@@ -166,11 +168,6 @@ static int m48t86_rtc_probe(struct platform_device *dev)
166 168
167static int m48t86_rtc_remove(struct platform_device *dev) 169static int m48t86_rtc_remove(struct platform_device *dev)
168{ 170{
169 struct rtc_device *rtc = platform_get_drvdata(dev);
170
171 if (rtc)
172 rtc_device_unregister(rtc);
173
174 platform_set_drvdata(dev, NULL); 171 platform_set_drvdata(dev, NULL);
175 172
176 return 0; 173 return 0;
diff --git a/drivers/rtc/rtc-max6900.c b/drivers/rtc/rtc-max6900.c
index a00e33204b91..8669d6d09a00 100644
--- a/drivers/rtc/rtc-max6900.c
+++ b/drivers/rtc/rtc-max6900.c
@@ -214,11 +214,6 @@ static int max6900_rtc_set_time(struct device *dev, struct rtc_time *tm)
214 214
215static int max6900_remove(struct i2c_client *client) 215static int max6900_remove(struct i2c_client *client)
216{ 216{
217 struct rtc_device *rtc = i2c_get_clientdata(client);
218
219 if (rtc)
220 rtc_device_unregister(rtc);
221
222 return 0; 217 return 0;
223} 218}
224 219
@@ -237,8 +232,8 @@ max6900_probe(struct i2c_client *client, const struct i2c_device_id *id)
237 232
238 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n"); 233 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n");
239 234
240 rtc = rtc_device_register(max6900_driver.driver.name, 235 rtc = devm_rtc_device_register(&client->dev, max6900_driver.driver.name,
241 &client->dev, &max6900_rtc_ops, THIS_MODULE); 236 &max6900_rtc_ops, THIS_MODULE);
242 if (IS_ERR(rtc)) 237 if (IS_ERR(rtc))
243 return PTR_ERR(rtc); 238 return PTR_ERR(rtc);
244 239
diff --git a/drivers/rtc/rtc-max6902.c b/drivers/rtc/rtc-max6902.c
index 7d0bf698b79e..e3aea00c3145 100644
--- a/drivers/rtc/rtc-max6902.c
+++ b/drivers/rtc/rtc-max6902.c
@@ -93,24 +93,24 @@ static int max6902_set_time(struct device *dev, struct rtc_time *dt)
93 dt->tm_year = dt->tm_year + 1900; 93 dt->tm_year = dt->tm_year + 1900;
94 94
95 /* Remove write protection */ 95 /* Remove write protection */
96 max6902_set_reg(dev, 0xF, 0); 96 max6902_set_reg(dev, MAX6902_REG_CONTROL, 0);
97 97
98 max6902_set_reg(dev, 0x01, bin2bcd(dt->tm_sec)); 98 max6902_set_reg(dev, MAX6902_REG_SECONDS, bin2bcd(dt->tm_sec));
99 max6902_set_reg(dev, 0x03, bin2bcd(dt->tm_min)); 99 max6902_set_reg(dev, MAX6902_REG_MINUTES, bin2bcd(dt->tm_min));
100 max6902_set_reg(dev, 0x05, bin2bcd(dt->tm_hour)); 100 max6902_set_reg(dev, MAX6902_REG_HOURS, bin2bcd(dt->tm_hour));
101 101
102 max6902_set_reg(dev, 0x07, bin2bcd(dt->tm_mday)); 102 max6902_set_reg(dev, MAX6902_REG_DATE, bin2bcd(dt->tm_mday));
103 max6902_set_reg(dev, 0x09, bin2bcd(dt->tm_mon + 1)); 103 max6902_set_reg(dev, MAX6902_REG_MONTH, bin2bcd(dt->tm_mon + 1));
104 max6902_set_reg(dev, 0x0B, bin2bcd(dt->tm_wday)); 104 max6902_set_reg(dev, MAX6902_REG_DAY, bin2bcd(dt->tm_wday));
105 max6902_set_reg(dev, 0x0D, bin2bcd(dt->tm_year % 100)); 105 max6902_set_reg(dev, MAX6902_REG_YEAR, bin2bcd(dt->tm_year % 100));
106 max6902_set_reg(dev, 0x13, bin2bcd(dt->tm_year / 100)); 106 max6902_set_reg(dev, MAX6902_REG_CENTURY, bin2bcd(dt->tm_year / 100));
107 107
108 /* Compulab used a delay here. However, the datasheet 108 /* Compulab used a delay here. However, the datasheet
109 * does not mention a delay being required anywhere... */ 109 * does not mention a delay being required anywhere... */
110 /* delay(2000); */ 110 /* delay(2000); */
111 111
112 /* Write protect */ 112 /* Write protect */
113 max6902_set_reg(dev, 0xF, 0x80); 113 max6902_set_reg(dev, MAX6902_REG_CONTROL, 0x80);
114 114
115 return 0; 115 return 0;
116} 116}
@@ -134,20 +134,17 @@ static int max6902_probe(struct spi_device *spi)
134 if (res != 0) 134 if (res != 0)
135 return res; 135 return res;
136 136
137 rtc = rtc_device_register("max6902", 137 rtc = devm_rtc_device_register(&spi->dev, "max6902",
138 &spi->dev, &max6902_rtc_ops, THIS_MODULE); 138 &max6902_rtc_ops, THIS_MODULE);
139 if (IS_ERR(rtc)) 139 if (IS_ERR(rtc))
140 return PTR_ERR(rtc); 140 return PTR_ERR(rtc);
141 141
142 dev_set_drvdata(&spi->dev, rtc); 142 spi_set_drvdata(spi, rtc);
143 return 0; 143 return 0;
144} 144}
145 145
146static int max6902_remove(struct spi_device *spi) 146static int max6902_remove(struct spi_device *spi)
147{ 147{
148 struct rtc_device *rtc = dev_get_drvdata(&spi->dev);
149
150 rtc_device_unregister(rtc);
151 return 0; 148 return 0;
152} 149}
153 150
diff --git a/drivers/rtc/rtc-max77686.c b/drivers/rtc/rtc-max77686.c
index 6b1337f9baf4..771812d62e6b 100644
--- a/drivers/rtc/rtc-max77686.c
+++ b/drivers/rtc/rtc-max77686.c
@@ -24,7 +24,7 @@
24 24
25/* RTC Control Register */ 25/* RTC Control Register */
26#define BCD_EN_SHIFT 0 26#define BCD_EN_SHIFT 0
27#define BCD_EN_MASK (1 << BCD_EN_SHIFT) 27#define BCD_EN_MASK (1 << BCD_EN_SHIFT)
28#define MODEL24_SHIFT 1 28#define MODEL24_SHIFT 1
29#define MODEL24_MASK (1 << MODEL24_SHIFT) 29#define MODEL24_MASK (1 << MODEL24_SHIFT)
30/* RTC Update Register1 */ 30/* RTC Update Register1 */
@@ -33,12 +33,12 @@
33#define RTC_RBUDR_SHIFT 4 33#define RTC_RBUDR_SHIFT 4
34#define RTC_RBUDR_MASK (1 << RTC_RBUDR_SHIFT) 34#define RTC_RBUDR_MASK (1 << RTC_RBUDR_SHIFT)
35/* WTSR and SMPL Register */ 35/* WTSR and SMPL Register */
36#define WTSRT_SHIFT 0 36#define WTSRT_SHIFT 0
37#define SMPLT_SHIFT 2 37#define SMPLT_SHIFT 2
38#define WTSR_EN_SHIFT 6 38#define WTSR_EN_SHIFT 6
39#define SMPL_EN_SHIFT 7 39#define SMPL_EN_SHIFT 7
40#define WTSRT_MASK (3 << WTSRT_SHIFT) 40#define WTSRT_MASK (3 << WTSRT_SHIFT)
41#define SMPLT_MASK (3 << SMPLT_SHIFT) 41#define SMPLT_MASK (3 << SMPLT_SHIFT)
42#define WTSR_EN_MASK (1 << WTSR_EN_SHIFT) 42#define WTSR_EN_MASK (1 << WTSR_EN_SHIFT)
43#define SMPL_EN_MASK (1 << SMPL_EN_SHIFT) 43#define SMPL_EN_MASK (1 << SMPL_EN_SHIFT)
44/* RTC Hour register */ 44/* RTC Hour register */
@@ -466,7 +466,7 @@ static void max77686_rtc_enable_smpl(struct max77686_rtc_info *info, bool enable
466 466
467 val = 0; 467 val = 0;
468 regmap_read(info->max77686->rtc_regmap, MAX77686_WTSR_SMPL_CNTL, &val); 468 regmap_read(info->max77686->rtc_regmap, MAX77686_WTSR_SMPL_CNTL, &val);
469 pr_info("%s: WTSR_SMPL(0x%02x)\n", __func__, val); 469 dev_info(info->dev, "%s: WTSR_SMPL(0x%02x)\n", __func__, val);
470} 470}
471#endif /* MAX77686_RTC_WTSR_SMPL */ 471#endif /* MAX77686_RTC_WTSR_SMPL */
472 472
@@ -505,7 +505,8 @@ static int max77686_rtc_probe(struct platform_device *pdev)
505 505
506 dev_info(&pdev->dev, "%s\n", __func__); 506 dev_info(&pdev->dev, "%s\n", __func__);
507 507
508 info = kzalloc(sizeof(struct max77686_rtc_info), GFP_KERNEL); 508 info = devm_kzalloc(&pdev->dev, sizeof(struct max77686_rtc_info),
509 GFP_KERNEL);
509 if (!info) 510 if (!info)
510 return -ENOMEM; 511 return -ENOMEM;
511 512
@@ -513,13 +514,12 @@ static int max77686_rtc_probe(struct platform_device *pdev)
513 info->dev = &pdev->dev; 514 info->dev = &pdev->dev;
514 info->max77686 = max77686; 515 info->max77686 = max77686;
515 info->rtc = max77686->rtc; 516 info->rtc = max77686->rtc;
516 info->max77686->rtc_regmap = regmap_init_i2c(info->max77686->rtc, 517 info->max77686->rtc_regmap = devm_regmap_init_i2c(info->max77686->rtc,
517 &max77686_rtc_regmap_config); 518 &max77686_rtc_regmap_config);
518 if (IS_ERR(info->max77686->rtc_regmap)) { 519 if (IS_ERR(info->max77686->rtc_regmap)) {
519 ret = PTR_ERR(info->max77686->rtc_regmap); 520 ret = PTR_ERR(info->max77686->rtc_regmap);
520 dev_err(info->max77686->dev, "Failed to allocate register map: %d\n", 521 dev_err(info->max77686->dev, "Failed to allocate register map: %d\n",
521 ret); 522 ret);
522 kfree(info);
523 return ret; 523 return ret;
524 } 524 }
525 platform_set_drvdata(pdev, info); 525 platform_set_drvdata(pdev, info);
@@ -538,8 +538,8 @@ static int max77686_rtc_probe(struct platform_device *pdev)
538 538
539 device_init_wakeup(&pdev->dev, 1); 539 device_init_wakeup(&pdev->dev, 1);
540 540
541 info->rtc_dev = rtc_device_register("max77686-rtc", &pdev->dev, 541 info->rtc_dev = devm_rtc_device_register(&pdev->dev, "max77686-rtc",
542 &max77686_rtc_ops, THIS_MODULE); 542 &max77686_rtc_ops, THIS_MODULE);
543 543
544 if (IS_ERR(info->rtc_dev)) { 544 if (IS_ERR(info->rtc_dev)) {
545 dev_info(&pdev->dev, "%s: fail\n", __func__); 545 dev_info(&pdev->dev, "%s: fail\n", __func__);
@@ -551,36 +551,24 @@ static int max77686_rtc_probe(struct platform_device *pdev)
551 goto err_rtc; 551 goto err_rtc;
552 } 552 }
553 virq = irq_create_mapping(max77686->irq_domain, MAX77686_RTCIRQ_RTCA1); 553 virq = irq_create_mapping(max77686->irq_domain, MAX77686_RTCIRQ_RTCA1);
554 if (!virq) 554 if (!virq) {
555 ret = -ENXIO;
555 goto err_rtc; 556 goto err_rtc;
557 }
556 info->virq = virq; 558 info->virq = virq;
557 559
558 ret = request_threaded_irq(virq, NULL, max77686_rtc_alarm_irq, 0, 560 ret = devm_request_threaded_irq(&pdev->dev, virq, NULL,
559 "rtc-alarm0", info); 561 max77686_rtc_alarm_irq, 0, "rtc-alarm0", info);
560 if (ret < 0) { 562 if (ret < 0)
561 dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n", 563 dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n",
562 info->virq, ret); 564 info->virq, ret);
563 goto err_rtc;
564 }
565 565
566 goto out;
567err_rtc: 566err_rtc:
568 kfree(info);
569 return ret;
570out:
571 return ret; 567 return ret;
572} 568}
573 569
574static int max77686_rtc_remove(struct platform_device *pdev) 570static int max77686_rtc_remove(struct platform_device *pdev)
575{ 571{
576 struct max77686_rtc_info *info = platform_get_drvdata(pdev);
577
578 if (info) {
579 free_irq(info->virq, info);
580 rtc_device_unregister(info->rtc_dev);
581 kfree(info);
582 }
583
584 return 0; 572 return 0;
585} 573}
586 574
@@ -594,11 +582,14 @@ static void max77686_rtc_shutdown(struct platform_device *pdev)
594 for (i = 0; i < 3; i++) { 582 for (i = 0; i < 3; i++) {
595 max77686_rtc_enable_wtsr(info, false); 583 max77686_rtc_enable_wtsr(info, false);
596 regmap_read(info->max77686->rtc_regmap, MAX77686_WTSR_SMPL_CNTL, &val); 584 regmap_read(info->max77686->rtc_regmap, MAX77686_WTSR_SMPL_CNTL, &val);
597 pr_info("%s: WTSR_SMPL reg(0x%02x)\n", __func__, val); 585 dev_info(info->dev, "%s: WTSR_SMPL reg(0x%02x)\n", __func__,
598 if (val & WTSR_EN_MASK) 586 val);
599 pr_emerg("%s: fail to disable WTSR\n", __func__); 587 if (val & WTSR_EN_MASK) {
600 else { 588 dev_emerg(info->dev, "%s: fail to disable WTSR\n",
601 pr_info("%s: success to disable WTSR\n", __func__); 589 __func__);
590 } else {
591 dev_info(info->dev, "%s: success to disable WTSR\n",
592 __func__);
602 break; 593 break;
603 } 594 }
604 } 595 }
@@ -624,18 +615,8 @@ static struct platform_driver max77686_rtc_driver = {
624 .id_table = rtc_id, 615 .id_table = rtc_id,
625}; 616};
626 617
627static int __init max77686_rtc_init(void) 618module_platform_driver(max77686_rtc_driver);
628{
629 return platform_driver_register(&max77686_rtc_driver);
630}
631module_init(max77686_rtc_init);
632
633static void __exit max77686_rtc_exit(void)
634{
635 platform_driver_unregister(&max77686_rtc_driver);
636}
637module_exit(max77686_rtc_exit);
638 619
639MODULE_DESCRIPTION("Maxim MAX77686 RTC driver"); 620MODULE_DESCRIPTION("Maxim MAX77686 RTC driver");
640MODULE_AUTHOR("<woong.byun@samsung.com>"); 621MODULE_AUTHOR("Chiwoong Byun <woong.byun@samsung.com>");
641MODULE_LICENSE("GPL"); 622MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-max8907.c b/drivers/rtc/rtc-max8907.c
index 31ca8faf9f05..86afb797125d 100644
--- a/drivers/rtc/rtc-max8907.c
+++ b/drivers/rtc/rtc-max8907.c
@@ -190,7 +190,7 @@ static int max8907_rtc_probe(struct platform_device *pdev)
190 rtc->max8907 = max8907; 190 rtc->max8907 = max8907;
191 rtc->regmap = max8907->regmap_rtc; 191 rtc->regmap = max8907->regmap_rtc;
192 192
193 rtc->rtc_dev = rtc_device_register("max8907-rtc", &pdev->dev, 193 rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, "max8907-rtc",
194 &max8907_rtc_ops, THIS_MODULE); 194 &max8907_rtc_ops, THIS_MODULE);
195 if (IS_ERR(rtc->rtc_dev)) { 195 if (IS_ERR(rtc->rtc_dev)) {
196 ret = PTR_ERR(rtc->rtc_dev); 196 ret = PTR_ERR(rtc->rtc_dev);
@@ -200,33 +200,21 @@ static int max8907_rtc_probe(struct platform_device *pdev)
200 200
201 rtc->irq = regmap_irq_get_virq(max8907->irqc_rtc, 201 rtc->irq = regmap_irq_get_virq(max8907->irqc_rtc,
202 MAX8907_IRQ_RTC_ALARM0); 202 MAX8907_IRQ_RTC_ALARM0);
203 if (rtc->irq < 0) { 203 if (rtc->irq < 0)
204 ret = rtc->irq; 204 return rtc->irq;
205 goto err_unregister;
206 }
207 205
208 ret = devm_request_threaded_irq(&pdev->dev, rtc->irq, NULL, 206 ret = devm_request_threaded_irq(&pdev->dev, rtc->irq, NULL,
209 max8907_irq_handler, 207 max8907_irq_handler,
210 IRQF_ONESHOT, "max8907-alarm0", rtc); 208 IRQF_ONESHOT, "max8907-alarm0", rtc);
211 if (ret < 0) { 209 if (ret < 0)
212 dev_err(&pdev->dev, "Failed to request IRQ%d: %d\n", 210 dev_err(&pdev->dev, "Failed to request IRQ%d: %d\n",
213 rtc->irq, ret); 211 rtc->irq, ret);
214 goto err_unregister;
215 }
216 212
217 return 0;
218
219err_unregister:
220 rtc_device_unregister(rtc->rtc_dev);
221 return ret; 213 return ret;
222} 214}
223 215
224static int max8907_rtc_remove(struct platform_device *pdev) 216static int max8907_rtc_remove(struct platform_device *pdev)
225{ 217{
226 struct max8907_rtc *rtc = platform_get_drvdata(pdev);
227
228 rtc_device_unregister(rtc->rtc_dev);
229
230 return 0; 218 return 0;
231} 219}
232 220
diff --git a/drivers/rtc/rtc-max8925.c b/drivers/rtc/rtc-max8925.c
index a0c8265646d2..7c90f4e45e27 100644
--- a/drivers/rtc/rtc-max8925.c
+++ b/drivers/rtc/rtc-max8925.c
@@ -253,7 +253,8 @@ static int max8925_rtc_probe(struct platform_device *pdev)
253 struct max8925_rtc_info *info; 253 struct max8925_rtc_info *info;
254 int ret; 254 int ret;
255 255
256 info = kzalloc(sizeof(struct max8925_rtc_info), GFP_KERNEL); 256 info = devm_kzalloc(&pdev->dev, sizeof(struct max8925_rtc_info),
257 GFP_KERNEL);
257 if (!info) 258 if (!info)
258 return -ENOMEM; 259 return -ENOMEM;
259 info->chip = chip; 260 info->chip = chip;
@@ -261,12 +262,13 @@ static int max8925_rtc_probe(struct platform_device *pdev)
261 info->dev = &pdev->dev; 262 info->dev = &pdev->dev;
262 info->irq = platform_get_irq(pdev, 0); 263 info->irq = platform_get_irq(pdev, 0);
263 264
264 ret = request_threaded_irq(info->irq, NULL, rtc_update_handler, 265 ret = devm_request_threaded_irq(&pdev->dev, info->irq, NULL,
265 IRQF_ONESHOT, "rtc-alarm0", info); 266 rtc_update_handler, IRQF_ONESHOT,
267 "rtc-alarm0", info);
266 if (ret < 0) { 268 if (ret < 0) {
267 dev_err(chip->dev, "Failed to request IRQ: #%d: %d\n", 269 dev_err(chip->dev, "Failed to request IRQ: #%d: %d\n",
268 info->irq, ret); 270 info->irq, ret);
269 goto out_irq; 271 goto err;
270 } 272 }
271 273
272 dev_set_drvdata(&pdev->dev, info); 274 dev_set_drvdata(&pdev->dev, info);
@@ -275,32 +277,22 @@ static int max8925_rtc_probe(struct platform_device *pdev)
275 277
276 device_init_wakeup(&pdev->dev, 1); 278 device_init_wakeup(&pdev->dev, 1);
277 279
278 info->rtc_dev = rtc_device_register("max8925-rtc", &pdev->dev, 280 info->rtc_dev = devm_rtc_device_register(&pdev->dev, "max8925-rtc",
279 &max8925_rtc_ops, THIS_MODULE); 281 &max8925_rtc_ops, THIS_MODULE);
280 ret = PTR_ERR(info->rtc_dev); 282 ret = PTR_ERR(info->rtc_dev);
281 if (IS_ERR(info->rtc_dev)) { 283 if (IS_ERR(info->rtc_dev)) {
282 dev_err(&pdev->dev, "Failed to register RTC device: %d\n", ret); 284 dev_err(&pdev->dev, "Failed to register RTC device: %d\n", ret);
283 goto out_rtc; 285 goto err;
284 } 286 }
285 287
286 return 0; 288 return 0;
287out_rtc: 289err:
288 platform_set_drvdata(pdev, NULL); 290 platform_set_drvdata(pdev, NULL);
289 free_irq(info->irq, info);
290out_irq:
291 kfree(info);
292 return ret; 291 return ret;
293} 292}
294 293
295static int max8925_rtc_remove(struct platform_device *pdev) 294static int max8925_rtc_remove(struct platform_device *pdev)
296{ 295{
297 struct max8925_rtc_info *info = platform_get_drvdata(pdev);
298
299 if (info) {
300 free_irq(info->irq, info);
301 rtc_device_unregister(info->rtc_dev);
302 kfree(info);
303 }
304 return 0; 296 return 0;
305} 297}
306 298
diff --git a/drivers/rtc/rtc-max8997.c b/drivers/rtc/rtc-max8997.c
index 00e505b6bee3..dacf48db7925 100644
--- a/drivers/rtc/rtc-max8997.c
+++ b/drivers/rtc/rtc-max8997.c
@@ -24,7 +24,7 @@
24/* Module parameter for WTSR function control */ 24/* Module parameter for WTSR function control */
25static int wtsr_en = 1; 25static int wtsr_en = 1;
26module_param(wtsr_en, int, 0444); 26module_param(wtsr_en, int, 0444);
27MODULE_PARM_DESC(wtsr_en, "Wachdog Timeout & Sofware Reset (default=on)"); 27MODULE_PARM_DESC(wtsr_en, "Watchdog Timeout & Software Reset (default=on)");
28/* Module parameter for SMPL function control */ 28/* Module parameter for SMPL function control */
29static int smpl_en = 1; 29static int smpl_en = 1;
30module_param(smpl_en, int, 0444); 30module_param(smpl_en, int, 0444);
@@ -479,8 +479,8 @@ static int max8997_rtc_probe(struct platform_device *pdev)
479 479
480 device_init_wakeup(&pdev->dev, 1); 480 device_init_wakeup(&pdev->dev, 1);
481 481
482 info->rtc_dev = rtc_device_register("max8997-rtc", &pdev->dev, 482 info->rtc_dev = devm_rtc_device_register(&pdev->dev, "max8997-rtc",
483 &max8997_rtc_ops, THIS_MODULE); 483 &max8997_rtc_ops, THIS_MODULE);
484 484
485 if (IS_ERR(info->rtc_dev)) { 485 if (IS_ERR(info->rtc_dev)) {
486 ret = PTR_ERR(info->rtc_dev); 486 ret = PTR_ERR(info->rtc_dev);
@@ -491,6 +491,7 @@ static int max8997_rtc_probe(struct platform_device *pdev)
491 virq = irq_create_mapping(max8997->irq_domain, MAX8997_PMICIRQ_RTCA1); 491 virq = irq_create_mapping(max8997->irq_domain, MAX8997_PMICIRQ_RTCA1);
492 if (!virq) { 492 if (!virq) {
493 dev_err(&pdev->dev, "Failed to create mapping alarm IRQ\n"); 493 dev_err(&pdev->dev, "Failed to create mapping alarm IRQ\n");
494 ret = -ENXIO;
494 goto err_out; 495 goto err_out;
495 } 496 }
496 info->virq = virq; 497 info->virq = virq;
@@ -498,26 +499,16 @@ static int max8997_rtc_probe(struct platform_device *pdev)
498 ret = devm_request_threaded_irq(&pdev->dev, virq, NULL, 499 ret = devm_request_threaded_irq(&pdev->dev, virq, NULL,
499 max8997_rtc_alarm_irq, 0, 500 max8997_rtc_alarm_irq, 0,
500 "rtc-alarm0", info); 501 "rtc-alarm0", info);
501 if (ret < 0) { 502 if (ret < 0)
502 dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n", 503 dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n",
503 info->virq, ret); 504 info->virq, ret);
504 goto err_out;
505 }
506
507 return ret;
508 505
509err_out: 506err_out:
510 rtc_device_unregister(info->rtc_dev);
511 return ret; 507 return ret;
512} 508}
513 509
514static int max8997_rtc_remove(struct platform_device *pdev) 510static int max8997_rtc_remove(struct platform_device *pdev)
515{ 511{
516 struct max8997_rtc_info *info = platform_get_drvdata(pdev);
517
518 if (info)
519 rtc_device_unregister(info->rtc_dev);
520
521 return 0; 512 return 0;
522} 513}
523 514
diff --git a/drivers/rtc/rtc-max8998.c b/drivers/rtc/rtc-max8998.c
index 8f234a075e8f..48b6612fae7f 100644
--- a/drivers/rtc/rtc-max8998.c
+++ b/drivers/rtc/rtc-max8998.c
@@ -256,7 +256,8 @@ static int max8998_rtc_probe(struct platform_device *pdev)
256 struct max8998_rtc_info *info; 256 struct max8998_rtc_info *info;
257 int ret; 257 int ret;
258 258
259 info = kzalloc(sizeof(struct max8998_rtc_info), GFP_KERNEL); 259 info = devm_kzalloc(&pdev->dev, sizeof(struct max8998_rtc_info),
260 GFP_KERNEL);
260 if (!info) 261 if (!info)
261 return -ENOMEM; 262 return -ENOMEM;
262 263
@@ -267,7 +268,7 @@ static int max8998_rtc_probe(struct platform_device *pdev)
267 268
268 platform_set_drvdata(pdev, info); 269 platform_set_drvdata(pdev, info);
269 270
270 info->rtc_dev = rtc_device_register("max8998-rtc", &pdev->dev, 271 info->rtc_dev = devm_rtc_device_register(&pdev->dev, "max8998-rtc",
271 &max8998_rtc_ops, THIS_MODULE); 272 &max8998_rtc_ops, THIS_MODULE);
272 273
273 if (IS_ERR(info->rtc_dev)) { 274 if (IS_ERR(info->rtc_dev)) {
@@ -276,8 +277,8 @@ static int max8998_rtc_probe(struct platform_device *pdev)
276 goto out_rtc; 277 goto out_rtc;
277 } 278 }
278 279
279 ret = request_threaded_irq(info->irq, NULL, max8998_rtc_alarm_irq, 0, 280 ret = devm_request_threaded_irq(&pdev->dev, info->irq, NULL,
280 "rtc-alarm0", info); 281 max8998_rtc_alarm_irq, 0, "rtc-alarm0", info);
281 282
282 if (ret < 0) 283 if (ret < 0)
283 dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n", 284 dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n",
@@ -294,20 +295,11 @@ static int max8998_rtc_probe(struct platform_device *pdev)
294 295
295out_rtc: 296out_rtc:
296 platform_set_drvdata(pdev, NULL); 297 platform_set_drvdata(pdev, NULL);
297 kfree(info);
298 return ret; 298 return ret;
299} 299}
300 300
301static int max8998_rtc_remove(struct platform_device *pdev) 301static int max8998_rtc_remove(struct platform_device *pdev)
302{ 302{
303 struct max8998_rtc_info *info = platform_get_drvdata(pdev);
304
305 if (info) {
306 free_irq(info->irq, info);
307 rtc_device_unregister(info->rtc_dev);
308 kfree(info);
309 }
310
311 return 0; 303 return 0;
312} 304}
313 305
diff --git a/drivers/rtc/rtc-mc13xxx.c b/drivers/rtc/rtc-mc13xxx.c
index 2643d8874925..7a8ed27a5f2e 100644
--- a/drivers/rtc/rtc-mc13xxx.c
+++ b/drivers/rtc/rtc-mc13xxx.c
@@ -316,7 +316,7 @@ static int __init mc13xxx_rtc_probe(struct platform_device *pdev)
316 struct mc13xxx *mc13xxx; 316 struct mc13xxx *mc13xxx;
317 int rtcrst_pending; 317 int rtcrst_pending;
318 318
319 priv = kzalloc(sizeof(*priv), GFP_KERNEL); 319 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
320 if (!priv) 320 if (!priv)
321 return -ENOMEM; 321 return -ENOMEM;
322 322
@@ -351,8 +351,8 @@ static int __init mc13xxx_rtc_probe(struct platform_device *pdev)
351 351
352 mc13xxx_unlock(mc13xxx); 352 mc13xxx_unlock(mc13xxx);
353 353
354 priv->rtc = rtc_device_register(pdev->name, 354 priv->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
355 &pdev->dev, &mc13xxx_rtc_ops, THIS_MODULE); 355 &mc13xxx_rtc_ops, THIS_MODULE);
356 if (IS_ERR(priv->rtc)) { 356 if (IS_ERR(priv->rtc)) {
357 ret = PTR_ERR(priv->rtc); 357 ret = PTR_ERR(priv->rtc);
358 358
@@ -372,7 +372,6 @@ err_reset_irq_request:
372 mc13xxx_unlock(mc13xxx); 372 mc13xxx_unlock(mc13xxx);
373 373
374 platform_set_drvdata(pdev, NULL); 374 platform_set_drvdata(pdev, NULL);
375 kfree(priv);
376 } 375 }
377 376
378 return ret; 377 return ret;
@@ -384,8 +383,6 @@ static int __exit mc13xxx_rtc_remove(struct platform_device *pdev)
384 383
385 mc13xxx_lock(priv->mc13xxx); 384 mc13xxx_lock(priv->mc13xxx);
386 385
387 rtc_device_unregister(priv->rtc);
388
389 mc13xxx_irq_free(priv->mc13xxx, MC13XXX_IRQ_TODA, priv); 386 mc13xxx_irq_free(priv->mc13xxx, MC13XXX_IRQ_TODA, priv);
390 mc13xxx_irq_free(priv->mc13xxx, MC13XXX_IRQ_1HZ, priv); 387 mc13xxx_irq_free(priv->mc13xxx, MC13XXX_IRQ_1HZ, priv);
391 mc13xxx_irq_free(priv->mc13xxx, MC13XXX_IRQ_RTCRST, priv); 388 mc13xxx_irq_free(priv->mc13xxx, MC13XXX_IRQ_RTCRST, priv);
@@ -394,8 +391,6 @@ static int __exit mc13xxx_rtc_remove(struct platform_device *pdev)
394 391
395 platform_set_drvdata(pdev, NULL); 392 platform_set_drvdata(pdev, NULL);
396 393
397 kfree(priv);
398
399 return 0; 394 return 0;
400} 395}
401 396
@@ -420,17 +415,7 @@ static struct platform_driver mc13xxx_rtc_driver = {
420 }, 415 },
421}; 416};
422 417
423static int __init mc13xxx_rtc_init(void) 418module_platform_driver_probe(mc13xxx_rtc_driver, &mc13xxx_rtc_probe);
424{
425 return platform_driver_probe(&mc13xxx_rtc_driver, &mc13xxx_rtc_probe);
426}
427module_init(mc13xxx_rtc_init);
428
429static void __exit mc13xxx_rtc_exit(void)
430{
431 platform_driver_unregister(&mc13xxx_rtc_driver);
432}
433module_exit(mc13xxx_rtc_exit);
434 419
435MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de>"); 420MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de>");
436MODULE_DESCRIPTION("RTC driver for Freescale MC13XXX PMIC"); 421MODULE_DESCRIPTION("RTC driver for Freescale MC13XXX PMIC");
diff --git a/drivers/rtc/rtc-msm6242.c b/drivers/rtc/rtc-msm6242.c
index fcb113c11122..771f86a05d14 100644
--- a/drivers/rtc/rtc-msm6242.c
+++ b/drivers/rtc/rtc-msm6242.c
@@ -194,30 +194,28 @@ static const struct rtc_class_ops msm6242_rtc_ops = {
194 .set_time = msm6242_set_time, 194 .set_time = msm6242_set_time,
195}; 195};
196 196
197static int __init msm6242_rtc_probe(struct platform_device *dev) 197static int __init msm6242_rtc_probe(struct platform_device *pdev)
198{ 198{
199 struct resource *res; 199 struct resource *res;
200 struct msm6242_priv *priv; 200 struct msm6242_priv *priv;
201 struct rtc_device *rtc; 201 struct rtc_device *rtc;
202 int error; 202 int error;
203 203
204 res = platform_get_resource(dev, IORESOURCE_MEM, 0); 204 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
205 if (!res) 205 if (!res)
206 return -ENODEV; 206 return -ENODEV;
207 207
208 priv = kzalloc(sizeof(*priv), GFP_KERNEL); 208 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
209 if (!priv) 209 if (!priv)
210 return -ENOMEM; 210 return -ENOMEM;
211 211
212 priv->regs = ioremap(res->start, resource_size(res)); 212 priv->regs = devm_ioremap(&pdev->dev, res->start, resource_size(res));
213 if (!priv->regs) { 213 if (!priv->regs)
214 error = -ENOMEM; 214 return -ENOMEM;
215 goto out_free_priv; 215 platform_set_drvdata(pdev, priv);
216 }
217 platform_set_drvdata(dev, priv);
218 216
219 rtc = rtc_device_register("rtc-msm6242", &dev->dev, &msm6242_rtc_ops, 217 rtc = devm_rtc_device_register(&pdev->dev, "rtc-msm6242",
220 THIS_MODULE); 218 &msm6242_rtc_ops, THIS_MODULE);
221 if (IS_ERR(rtc)) { 219 if (IS_ERR(rtc)) {
222 error = PTR_ERR(rtc); 220 error = PTR_ERR(rtc);
223 goto out_unmap; 221 goto out_unmap;
@@ -227,20 +225,12 @@ static int __init msm6242_rtc_probe(struct platform_device *dev)
227 return 0; 225 return 0;
228 226
229out_unmap: 227out_unmap:
230 platform_set_drvdata(dev, NULL); 228 platform_set_drvdata(pdev, NULL);
231 iounmap(priv->regs);
232out_free_priv:
233 kfree(priv);
234 return error; 229 return error;
235} 230}
236 231
237static int __exit msm6242_rtc_remove(struct platform_device *dev) 232static int __exit msm6242_rtc_remove(struct platform_device *pdev)
238{ 233{
239 struct msm6242_priv *priv = platform_get_drvdata(dev);
240
241 rtc_device_unregister(priv->rtc);
242 iounmap(priv->regs);
243 kfree(priv);
244 return 0; 234 return 0;
245} 235}
246 236
@@ -252,18 +242,7 @@ static struct platform_driver msm6242_rtc_driver = {
252 .remove = __exit_p(msm6242_rtc_remove), 242 .remove = __exit_p(msm6242_rtc_remove),
253}; 243};
254 244
255static int __init msm6242_rtc_init(void) 245module_platform_driver_probe(msm6242_rtc_driver, msm6242_rtc_probe);
256{
257 return platform_driver_probe(&msm6242_rtc_driver, msm6242_rtc_probe);
258}
259
260static void __exit msm6242_rtc_fini(void)
261{
262 platform_driver_unregister(&msm6242_rtc_driver);
263}
264
265module_init(msm6242_rtc_init);
266module_exit(msm6242_rtc_fini);
267 246
268MODULE_AUTHOR("Geert Uytterhoeven <geert@linux-m68k.org>"); 247MODULE_AUTHOR("Geert Uytterhoeven <geert@linux-m68k.org>");
269MODULE_LICENSE("GPL"); 248MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-mv.c b/drivers/rtc/rtc-mv.c
index 57233c885998..baab802f2153 100644
--- a/drivers/rtc/rtc-mv.c
+++ b/drivers/rtc/rtc-mv.c
@@ -14,6 +14,7 @@
14#include <linux/platform_device.h> 14#include <linux/platform_device.h>
15#include <linux/of.h> 15#include <linux/of.h>
16#include <linux/delay.h> 16#include <linux/delay.h>
17#include <linux/clk.h>
17#include <linux/gfp.h> 18#include <linux/gfp.h>
18#include <linux/module.h> 19#include <linux/module.h>
19 20
@@ -41,6 +42,7 @@ struct rtc_plat_data {
41 struct rtc_device *rtc; 42 struct rtc_device *rtc;
42 void __iomem *ioaddr; 43 void __iomem *ioaddr;
43 int irq; 44 int irq;
45 struct clk *clk;
44}; 46};
45 47
46static int mv_rtc_set_time(struct device *dev, struct rtc_time *tm) 48static int mv_rtc_set_time(struct device *dev, struct rtc_time *tm)
@@ -215,12 +217,13 @@ static const struct rtc_class_ops mv_rtc_alarm_ops = {
215 .alarm_irq_enable = mv_rtc_alarm_irq_enable, 217 .alarm_irq_enable = mv_rtc_alarm_irq_enable,
216}; 218};
217 219
218static int mv_rtc_probe(struct platform_device *pdev) 220static int __init mv_rtc_probe(struct platform_device *pdev)
219{ 221{
220 struct resource *res; 222 struct resource *res;
221 struct rtc_plat_data *pdata; 223 struct rtc_plat_data *pdata;
222 resource_size_t size; 224 resource_size_t size;
223 u32 rtc_time; 225 u32 rtc_time;
226 int ret = 0;
224 227
225 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 228 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
226 if (!res) 229 if (!res)
@@ -239,11 +242,17 @@ static int mv_rtc_probe(struct platform_device *pdev)
239 if (!pdata->ioaddr) 242 if (!pdata->ioaddr)
240 return -ENOMEM; 243 return -ENOMEM;
241 244
245 pdata->clk = devm_clk_get(&pdev->dev, NULL);
246 /* Not all SoCs require a clock.*/
247 if (!IS_ERR(pdata->clk))
248 clk_prepare_enable(pdata->clk);
249
242 /* make sure the 24 hours mode is enabled */ 250 /* make sure the 24 hours mode is enabled */
243 rtc_time = readl(pdata->ioaddr + RTC_TIME_REG_OFFS); 251 rtc_time = readl(pdata->ioaddr + RTC_TIME_REG_OFFS);
244 if (rtc_time & RTC_HOURS_12H_MODE) { 252 if (rtc_time & RTC_HOURS_12H_MODE) {
245 dev_err(&pdev->dev, "24 Hours mode not supported.\n"); 253 dev_err(&pdev->dev, "24 Hours mode not supported.\n");
246 return -EINVAL; 254 ret = -EINVAL;
255 goto out;
247 } 256 }
248 257
249 /* make sure it is actually functional */ 258 /* make sure it is actually functional */
@@ -252,7 +261,8 @@ static int mv_rtc_probe(struct platform_device *pdev)
252 rtc_time = readl(pdata->ioaddr + RTC_TIME_REG_OFFS); 261 rtc_time = readl(pdata->ioaddr + RTC_TIME_REG_OFFS);
253 if (rtc_time == 0x01000000) { 262 if (rtc_time == 0x01000000) {
254 dev_err(&pdev->dev, "internal RTC not ticking\n"); 263 dev_err(&pdev->dev, "internal RTC not ticking\n");
255 return -ENODEV; 264 ret = -ENODEV;
265 goto out;
256 } 266 }
257 } 267 }
258 268
@@ -262,14 +272,17 @@ static int mv_rtc_probe(struct platform_device *pdev)
262 272
263 if (pdata->irq >= 0) { 273 if (pdata->irq >= 0) {
264 device_init_wakeup(&pdev->dev, 1); 274 device_init_wakeup(&pdev->dev, 1);
265 pdata->rtc = rtc_device_register(pdev->name, &pdev->dev, 275 pdata->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
266 &mv_rtc_alarm_ops, 276 &mv_rtc_alarm_ops,
267 THIS_MODULE); 277 THIS_MODULE);
268 } else 278 } else {
269 pdata->rtc = rtc_device_register(pdev->name, &pdev->dev, 279 pdata->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
270 &mv_rtc_ops, THIS_MODULE); 280 &mv_rtc_ops, THIS_MODULE);
271 if (IS_ERR(pdata->rtc)) 281 }
272 return PTR_ERR(pdata->rtc); 282 if (IS_ERR(pdata->rtc)) {
283 ret = PTR_ERR(pdata->rtc);
284 goto out;
285 }
273 286
274 if (pdata->irq >= 0) { 287 if (pdata->irq >= 0) {
275 writel(0, pdata->ioaddr + RTC_ALARM_INTERRUPT_MASK_REG_OFFS); 288 writel(0, pdata->ioaddr + RTC_ALARM_INTERRUPT_MASK_REG_OFFS);
@@ -282,6 +295,11 @@ static int mv_rtc_probe(struct platform_device *pdev)
282 } 295 }
283 296
284 return 0; 297 return 0;
298out:
299 if (!IS_ERR(pdata->clk))
300 clk_disable_unprepare(pdata->clk);
301
302 return ret;
285} 303}
286 304
287static int __exit mv_rtc_remove(struct platform_device *pdev) 305static int __exit mv_rtc_remove(struct platform_device *pdev)
@@ -291,7 +309,9 @@ static int __exit mv_rtc_remove(struct platform_device *pdev)
291 if (pdata->irq >= 0) 309 if (pdata->irq >= 0)
292 device_init_wakeup(&pdev->dev, 0); 310 device_init_wakeup(&pdev->dev, 0);
293 311
294 rtc_device_unregister(pdata->rtc); 312 if (!IS_ERR(pdata->clk))
313 clk_disable_unprepare(pdata->clk);
314
295 return 0; 315 return 0;
296} 316}
297 317
@@ -311,18 +331,7 @@ static struct platform_driver mv_rtc_driver = {
311 }, 331 },
312}; 332};
313 333
314static __init int mv_init(void) 334module_platform_driver_probe(mv_rtc_driver, mv_rtc_probe);
315{
316 return platform_driver_probe(&mv_rtc_driver, mv_rtc_probe);
317}
318
319static __exit void mv_exit(void)
320{
321 platform_driver_unregister(&mv_rtc_driver);
322}
323
324module_init(mv_init);
325module_exit(mv_exit);
326 335
327MODULE_AUTHOR("Saeed Bishara <saeed@marvell.com>"); 336MODULE_AUTHOR("Saeed Bishara <saeed@marvell.com>");
328MODULE_DESCRIPTION("Marvell RTC driver"); 337MODULE_DESCRIPTION("Marvell RTC driver");
diff --git a/drivers/rtc/rtc-mxc.c b/drivers/rtc/rtc-mxc.c
index 1c3ef7289565..9a3895bc4f4d 100644
--- a/drivers/rtc/rtc-mxc.c
+++ b/drivers/rtc/rtc-mxc.c
@@ -439,7 +439,7 @@ static int mxc_rtc_probe(struct platform_device *pdev)
439 if (pdata->irq >=0) 439 if (pdata->irq >=0)
440 device_init_wakeup(&pdev->dev, 1); 440 device_init_wakeup(&pdev->dev, 1);
441 441
442 rtc = rtc_device_register(pdev->name, &pdev->dev, &mxc_rtc_ops, 442 rtc = devm_rtc_device_register(&pdev->dev, pdev->name, &mxc_rtc_ops,
443 THIS_MODULE); 443 THIS_MODULE);
444 if (IS_ERR(rtc)) { 444 if (IS_ERR(rtc)) {
445 ret = PTR_ERR(rtc); 445 ret = PTR_ERR(rtc);
@@ -464,15 +464,13 @@ static int mxc_rtc_remove(struct platform_device *pdev)
464{ 464{
465 struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 465 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
466 466
467 rtc_device_unregister(pdata->rtc);
468
469 clk_disable_unprepare(pdata->clk); 467 clk_disable_unprepare(pdata->clk);
470 platform_set_drvdata(pdev, NULL); 468 platform_set_drvdata(pdev, NULL);
471 469
472 return 0; 470 return 0;
473} 471}
474 472
475#ifdef CONFIG_PM 473#ifdef CONFIG_PM_SLEEP
476static int mxc_rtc_suspend(struct device *dev) 474static int mxc_rtc_suspend(struct device *dev)
477{ 475{
478 struct rtc_plat_data *pdata = dev_get_drvdata(dev); 476 struct rtc_plat_data *pdata = dev_get_drvdata(dev);
@@ -492,19 +490,14 @@ static int mxc_rtc_resume(struct device *dev)
492 490
493 return 0; 491 return 0;
494} 492}
495
496static struct dev_pm_ops mxc_rtc_pm_ops = {
497 .suspend = mxc_rtc_suspend,
498 .resume = mxc_rtc_resume,
499};
500#endif 493#endif
501 494
495static SIMPLE_DEV_PM_OPS(mxc_rtc_pm_ops, mxc_rtc_suspend, mxc_rtc_resume);
496
502static struct platform_driver mxc_rtc_driver = { 497static struct platform_driver mxc_rtc_driver = {
503 .driver = { 498 .driver = {
504 .name = "mxc_rtc", 499 .name = "mxc_rtc",
505#ifdef CONFIG_PM
506 .pm = &mxc_rtc_pm_ops, 500 .pm = &mxc_rtc_pm_ops,
507#endif
508 .owner = THIS_MODULE, 501 .owner = THIS_MODULE,
509 }, 502 },
510 .id_table = imx_rtc_devtype, 503 .id_table = imx_rtc_devtype,
diff --git a/drivers/rtc/rtc-nuc900.c b/drivers/rtc/rtc-nuc900.c
index a63680850fef..f5dfb6e5e7d9 100644
--- a/drivers/rtc/rtc-nuc900.c
+++ b/drivers/rtc/rtc-nuc900.c
@@ -222,13 +222,13 @@ static struct rtc_class_ops nuc900_rtc_ops = {
222 .alarm_irq_enable = nuc900_alarm_irq_enable, 222 .alarm_irq_enable = nuc900_alarm_irq_enable,
223}; 223};
224 224
225static int nuc900_rtc_probe(struct platform_device *pdev) 225static int __init nuc900_rtc_probe(struct platform_device *pdev)
226{ 226{
227 struct resource *res; 227 struct resource *res;
228 struct nuc900_rtc *nuc900_rtc; 228 struct nuc900_rtc *nuc900_rtc;
229 int err = 0;
230 229
231 nuc900_rtc = kzalloc(sizeof(struct nuc900_rtc), GFP_KERNEL); 230 nuc900_rtc = devm_kzalloc(&pdev->dev, sizeof(struct nuc900_rtc),
231 GFP_KERNEL);
232 if (!nuc900_rtc) { 232 if (!nuc900_rtc) {
233 dev_err(&pdev->dev, "kzalloc nuc900_rtc failed\n"); 233 dev_err(&pdev->dev, "kzalloc nuc900_rtc failed\n");
234 return -ENOMEM; 234 return -ENOMEM;
@@ -236,93 +236,51 @@ static int nuc900_rtc_probe(struct platform_device *pdev)
236 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 236 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
237 if (!res) { 237 if (!res) {
238 dev_err(&pdev->dev, "platform_get_resource failed\n"); 238 dev_err(&pdev->dev, "platform_get_resource failed\n");
239 err = -ENXIO; 239 return -ENXIO;
240 goto fail1;
241 } 240 }
242 241
243 if (!request_mem_region(res->start, resource_size(res), 242 nuc900_rtc->rtc_reg = devm_ioremap_resource(&pdev->dev, res);
244 pdev->name)) { 243 if (IS_ERR(nuc900_rtc->rtc_reg))
245 dev_err(&pdev->dev, "request_mem_region failed\n"); 244 return PTR_ERR(nuc900_rtc->rtc_reg);
246 err = -EBUSY;
247 goto fail1;
248 }
249
250 nuc900_rtc->rtc_reg = ioremap(res->start, resource_size(res));
251 if (!nuc900_rtc->rtc_reg) {
252 dev_err(&pdev->dev, "ioremap rtc_reg failed\n");
253 err = -ENOMEM;
254 goto fail2;
255 }
256 245
257 platform_set_drvdata(pdev, nuc900_rtc); 246 platform_set_drvdata(pdev, nuc900_rtc);
258 247
259 nuc900_rtc->rtcdev = rtc_device_register(pdev->name, &pdev->dev, 248 nuc900_rtc->rtcdev = devm_rtc_device_register(&pdev->dev, pdev->name,
260 &nuc900_rtc_ops, THIS_MODULE); 249 &nuc900_rtc_ops, THIS_MODULE);
261 if (IS_ERR(nuc900_rtc->rtcdev)) { 250 if (IS_ERR(nuc900_rtc->rtcdev)) {
262 dev_err(&pdev->dev, "rtc device register failed\n"); 251 dev_err(&pdev->dev, "rtc device register failed\n");
263 err = PTR_ERR(nuc900_rtc->rtcdev); 252 return PTR_ERR(nuc900_rtc->rtcdev);
264 goto fail3;
265 } 253 }
266 254
267 __raw_writel(__raw_readl(nuc900_rtc->rtc_reg + REG_RTC_TSSR) | MODE24, 255 __raw_writel(__raw_readl(nuc900_rtc->rtc_reg + REG_RTC_TSSR) | MODE24,
268 nuc900_rtc->rtc_reg + REG_RTC_TSSR); 256 nuc900_rtc->rtc_reg + REG_RTC_TSSR);
269 257
270 nuc900_rtc->irq_num = platform_get_irq(pdev, 0); 258 nuc900_rtc->irq_num = platform_get_irq(pdev, 0);
271 if (request_irq(nuc900_rtc->irq_num, nuc900_rtc_interrupt, 259 if (devm_request_irq(&pdev->dev, nuc900_rtc->irq_num,
272 0, "nuc900rtc", nuc900_rtc)) { 260 nuc900_rtc_interrupt, 0, "nuc900rtc", nuc900_rtc)) {
273 dev_err(&pdev->dev, "NUC900 RTC request irq failed\n"); 261 dev_err(&pdev->dev, "NUC900 RTC request irq failed\n");
274 err = -EBUSY; 262 return -EBUSY;
275 goto fail4;
276 } 263 }
277 264
278 return 0; 265 return 0;
279
280fail4: rtc_device_unregister(nuc900_rtc->rtcdev);
281fail3: iounmap(nuc900_rtc->rtc_reg);
282fail2: release_mem_region(res->start, resource_size(res));
283fail1: kfree(nuc900_rtc);
284 return err;
285} 266}
286 267
287static int nuc900_rtc_remove(struct platform_device *pdev) 268static int __exit nuc900_rtc_remove(struct platform_device *pdev)
288{ 269{
289 struct nuc900_rtc *nuc900_rtc = platform_get_drvdata(pdev);
290 struct resource *res;
291
292 free_irq(nuc900_rtc->irq_num, nuc900_rtc);
293 rtc_device_unregister(nuc900_rtc->rtcdev);
294 iounmap(nuc900_rtc->rtc_reg);
295
296 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
297 release_mem_region(res->start, resource_size(res));
298
299 kfree(nuc900_rtc);
300
301 platform_set_drvdata(pdev, NULL); 270 platform_set_drvdata(pdev, NULL);
302 271
303 return 0; 272 return 0;
304} 273}
305 274
306static struct platform_driver nuc900_rtc_driver = { 275static struct platform_driver nuc900_rtc_driver = {
307 .remove = nuc900_rtc_remove, 276 .remove = __exit_p(nuc900_rtc_remove),
308 .driver = { 277 .driver = {
309 .name = "nuc900-rtc", 278 .name = "nuc900-rtc",
310 .owner = THIS_MODULE, 279 .owner = THIS_MODULE,
311 }, 280 },
312}; 281};
313 282
314static int __init nuc900_rtc_init(void) 283module_platform_driver_probe(nuc900_rtc_driver, nuc900_rtc_probe);
315{
316 return platform_driver_probe(&nuc900_rtc_driver, nuc900_rtc_probe);
317}
318
319static void __exit nuc900_rtc_exit(void)
320{
321 platform_driver_unregister(&nuc900_rtc_driver);
322}
323
324module_init(nuc900_rtc_init);
325module_exit(nuc900_rtc_exit);
326 284
327MODULE_AUTHOR("Wan ZongShun <mcuos.com@gmail.com>"); 285MODULE_AUTHOR("Wan ZongShun <mcuos.com@gmail.com>");
328MODULE_DESCRIPTION("nuc910/nuc920 RTC driver"); 286MODULE_DESCRIPTION("nuc910/nuc920 RTC driver");
diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
index 600971407aac..4e1bdb832e37 100644
--- a/drivers/rtc/rtc-omap.c
+++ b/drivers/rtc/rtc-omap.c
@@ -324,7 +324,7 @@ MODULE_DEVICE_TABLE(of, omap_rtc_of_match);
324 324
325static int __init omap_rtc_probe(struct platform_device *pdev) 325static int __init omap_rtc_probe(struct platform_device *pdev)
326{ 326{
327 struct resource *res, *mem; 327 struct resource *res;
328 struct rtc_device *rtc; 328 struct rtc_device *rtc;
329 u8 reg, new_ctrl; 329 u8 reg, new_ctrl;
330 const struct platform_device_id *id_entry; 330 const struct platform_device_id *id_entry;
@@ -352,18 +352,9 @@ static int __init omap_rtc_probe(struct platform_device *pdev)
352 return -ENOENT; 352 return -ENOENT;
353 } 353 }
354 354
355 mem = request_mem_region(res->start, resource_size(res), pdev->name); 355 rtc_base = devm_ioremap_resource(&pdev->dev, res);
356 if (!mem) { 356 if (IS_ERR(rtc_base))
357 pr_debug("%s: RTC registers at %08x are not free\n", 357 return PTR_ERR(rtc_base);
358 pdev->name, res->start);
359 return -EBUSY;
360 }
361
362 rtc_base = ioremap(res->start, resource_size(res));
363 if (!rtc_base) {
364 pr_debug("%s: RTC registers can't be mapped\n", pdev->name);
365 goto fail;
366 }
367 358
368 /* Enable the clock/module so that we can access the registers */ 359 /* Enable the clock/module so that we can access the registers */
369 pm_runtime_enable(&pdev->dev); 360 pm_runtime_enable(&pdev->dev);
@@ -375,7 +366,7 @@ static int __init omap_rtc_probe(struct platform_device *pdev)
375 rtc_writel(KICK1_VALUE, OMAP_RTC_KICK1_REG); 366 rtc_writel(KICK1_VALUE, OMAP_RTC_KICK1_REG);
376 } 367 }
377 368
378 rtc = rtc_device_register(pdev->name, &pdev->dev, 369 rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
379 &omap_rtc_ops, THIS_MODULE); 370 &omap_rtc_ops, THIS_MODULE);
380 if (IS_ERR(rtc)) { 371 if (IS_ERR(rtc)) {
381 pr_debug("%s: can't register RTC device, err %ld\n", 372 pr_debug("%s: can't register RTC device, err %ld\n",
@@ -383,7 +374,6 @@ static int __init omap_rtc_probe(struct platform_device *pdev)
383 goto fail0; 374 goto fail0;
384 } 375 }
385 platform_set_drvdata(pdev, rtc); 376 platform_set_drvdata(pdev, rtc);
386 dev_set_drvdata(&rtc->dev, mem);
387 377
388 /* clear pending irqs, and set 1/second periodic, 378 /* clear pending irqs, and set 1/second periodic,
389 * which we'll use instead of update irqs 379 * which we'll use instead of update irqs
@@ -401,18 +391,18 @@ static int __init omap_rtc_probe(struct platform_device *pdev)
401 rtc_write(OMAP_RTC_STATUS_ALARM, OMAP_RTC_STATUS_REG); 391 rtc_write(OMAP_RTC_STATUS_ALARM, OMAP_RTC_STATUS_REG);
402 392
403 /* handle periodic and alarm irqs */ 393 /* handle periodic and alarm irqs */
404 if (request_irq(omap_rtc_timer, rtc_irq, 0, 394 if (devm_request_irq(&pdev->dev, omap_rtc_timer, rtc_irq, 0,
405 dev_name(&rtc->dev), rtc)) { 395 dev_name(&rtc->dev), rtc)) {
406 pr_debug("%s: RTC timer interrupt IRQ%d already claimed\n", 396 pr_debug("%s: RTC timer interrupt IRQ%d already claimed\n",
407 pdev->name, omap_rtc_timer); 397 pdev->name, omap_rtc_timer);
408 goto fail1; 398 goto fail0;
409 } 399 }
410 if ((omap_rtc_timer != omap_rtc_alarm) && 400 if ((omap_rtc_timer != omap_rtc_alarm) &&
411 (request_irq(omap_rtc_alarm, rtc_irq, 0, 401 (devm_request_irq(&pdev->dev, omap_rtc_alarm, rtc_irq, 0,
412 dev_name(&rtc->dev), rtc))) { 402 dev_name(&rtc->dev), rtc))) {
413 pr_debug("%s: RTC alarm interrupt IRQ%d already claimed\n", 403 pr_debug("%s: RTC alarm interrupt IRQ%d already claimed\n",
414 pdev->name, omap_rtc_alarm); 404 pdev->name, omap_rtc_alarm);
415 goto fail2; 405 goto fail0;
416 } 406 }
417 407
418 /* On boards with split power, RTC_ON_NOFF won't reset the RTC */ 408 /* On boards with split power, RTC_ON_NOFF won't reset the RTC */
@@ -446,25 +436,16 @@ static int __init omap_rtc_probe(struct platform_device *pdev)
446 436
447 return 0; 437 return 0;
448 438
449fail2:
450 free_irq(omap_rtc_timer, rtc);
451fail1:
452 rtc_device_unregister(rtc);
453fail0: 439fail0:
454 if (id_entry && (id_entry->driver_data & OMAP_RTC_HAS_KICKER)) 440 if (id_entry && (id_entry->driver_data & OMAP_RTC_HAS_KICKER))
455 rtc_writel(0, OMAP_RTC_KICK0_REG); 441 rtc_writel(0, OMAP_RTC_KICK0_REG);
456 pm_runtime_put_sync(&pdev->dev); 442 pm_runtime_put_sync(&pdev->dev);
457 pm_runtime_disable(&pdev->dev); 443 pm_runtime_disable(&pdev->dev);
458 iounmap(rtc_base);
459fail:
460 release_mem_region(mem->start, resource_size(mem));
461 return -EIO; 444 return -EIO;
462} 445}
463 446
464static int __exit omap_rtc_remove(struct platform_device *pdev) 447static int __exit omap_rtc_remove(struct platform_device *pdev)
465{ 448{
466 struct rtc_device *rtc = platform_get_drvdata(pdev);
467 struct resource *mem = dev_get_drvdata(&rtc->dev);
468 const struct platform_device_id *id_entry = 449 const struct platform_device_id *id_entry =
469 platform_get_device_id(pdev); 450 platform_get_device_id(pdev);
470 451
@@ -473,12 +454,6 @@ static int __exit omap_rtc_remove(struct platform_device *pdev)
473 /* leave rtc running, but disable irqs */ 454 /* leave rtc running, but disable irqs */
474 rtc_write(0, OMAP_RTC_INTERRUPTS_REG); 455 rtc_write(0, OMAP_RTC_INTERRUPTS_REG);
475 456
476 free_irq(omap_rtc_timer, rtc);
477
478 if (omap_rtc_timer != omap_rtc_alarm)
479 free_irq(omap_rtc_alarm, rtc);
480
481 rtc_device_unregister(rtc);
482 if (id_entry && (id_entry->driver_data & OMAP_RTC_HAS_KICKER)) 457 if (id_entry && (id_entry->driver_data & OMAP_RTC_HAS_KICKER))
483 rtc_writel(0, OMAP_RTC_KICK0_REG); 458 rtc_writel(0, OMAP_RTC_KICK0_REG);
484 459
@@ -486,16 +461,13 @@ static int __exit omap_rtc_remove(struct platform_device *pdev)
486 pm_runtime_put_sync(&pdev->dev); 461 pm_runtime_put_sync(&pdev->dev);
487 pm_runtime_disable(&pdev->dev); 462 pm_runtime_disable(&pdev->dev);
488 463
489 iounmap(rtc_base);
490 release_mem_region(mem->start, resource_size(mem));
491 return 0; 464 return 0;
492} 465}
493 466
494#ifdef CONFIG_PM 467#ifdef CONFIG_PM_SLEEP
495
496static u8 irqstat; 468static u8 irqstat;
497 469
498static int omap_rtc_suspend(struct platform_device *pdev, pm_message_t state) 470static int omap_rtc_suspend(struct device *dev)
499{ 471{
500 irqstat = rtc_read(OMAP_RTC_INTERRUPTS_REG); 472 irqstat = rtc_read(OMAP_RTC_INTERRUPTS_REG);
501 473
@@ -503,34 +475,32 @@ static int omap_rtc_suspend(struct platform_device *pdev, pm_message_t state)
503 * source, and in fact this enable() call is just saving a flag 475 * source, and in fact this enable() call is just saving a flag
504 * that's never used... 476 * that's never used...
505 */ 477 */
506 if (device_may_wakeup(&pdev->dev)) 478 if (device_may_wakeup(dev))
507 enable_irq_wake(omap_rtc_alarm); 479 enable_irq_wake(omap_rtc_alarm);
508 else 480 else
509 rtc_write(0, OMAP_RTC_INTERRUPTS_REG); 481 rtc_write(0, OMAP_RTC_INTERRUPTS_REG);
510 482
511 /* Disable the clock/module */ 483 /* Disable the clock/module */
512 pm_runtime_put_sync(&pdev->dev); 484 pm_runtime_put_sync(dev);
513 485
514 return 0; 486 return 0;
515} 487}
516 488
517static int omap_rtc_resume(struct platform_device *pdev) 489static int omap_rtc_resume(struct device *dev)
518{ 490{
519 /* Enable the clock/module so that we can access the registers */ 491 /* Enable the clock/module so that we can access the registers */
520 pm_runtime_get_sync(&pdev->dev); 492 pm_runtime_get_sync(dev);
521 493
522 if (device_may_wakeup(&pdev->dev)) 494 if (device_may_wakeup(dev))
523 disable_irq_wake(omap_rtc_alarm); 495 disable_irq_wake(omap_rtc_alarm);
524 else 496 else
525 rtc_write(irqstat, OMAP_RTC_INTERRUPTS_REG); 497 rtc_write(irqstat, OMAP_RTC_INTERRUPTS_REG);
526 return 0; 498 return 0;
527} 499}
528
529#else
530#define omap_rtc_suspend NULL
531#define omap_rtc_resume NULL
532#endif 500#endif
533 501
502static SIMPLE_DEV_PM_OPS(omap_rtc_pm_ops, omap_rtc_suspend, omap_rtc_resume);
503
534static void omap_rtc_shutdown(struct platform_device *pdev) 504static void omap_rtc_shutdown(struct platform_device *pdev)
535{ 505{
536 rtc_write(0, OMAP_RTC_INTERRUPTS_REG); 506 rtc_write(0, OMAP_RTC_INTERRUPTS_REG);
@@ -539,28 +509,17 @@ static void omap_rtc_shutdown(struct platform_device *pdev)
539MODULE_ALIAS("platform:omap_rtc"); 509MODULE_ALIAS("platform:omap_rtc");
540static struct platform_driver omap_rtc_driver = { 510static struct platform_driver omap_rtc_driver = {
541 .remove = __exit_p(omap_rtc_remove), 511 .remove = __exit_p(omap_rtc_remove),
542 .suspend = omap_rtc_suspend,
543 .resume = omap_rtc_resume,
544 .shutdown = omap_rtc_shutdown, 512 .shutdown = omap_rtc_shutdown,
545 .driver = { 513 .driver = {
546 .name = DRIVER_NAME, 514 .name = DRIVER_NAME,
547 .owner = THIS_MODULE, 515 .owner = THIS_MODULE,
516 .pm = &omap_rtc_pm_ops,
548 .of_match_table = of_match_ptr(omap_rtc_of_match), 517 .of_match_table = of_match_ptr(omap_rtc_of_match),
549 }, 518 },
550 .id_table = omap_rtc_devtype, 519 .id_table = omap_rtc_devtype,
551}; 520};
552 521
553static int __init rtc_init(void) 522module_platform_driver_probe(omap_rtc_driver, omap_rtc_probe);
554{
555 return platform_driver_probe(&omap_rtc_driver, omap_rtc_probe);
556}
557module_init(rtc_init);
558
559static void __exit rtc_exit(void)
560{
561 platform_driver_unregister(&omap_rtc_driver);
562}
563module_exit(rtc_exit);
564 523
565MODULE_AUTHOR("George G. Davis (and others)"); 524MODULE_AUTHOR("George G. Davis (and others)");
566MODULE_LICENSE("GPL"); 525MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-palmas.c b/drivers/rtc/rtc-palmas.c
index 59c42986254e..50204d474eb7 100644
--- a/drivers/rtc/rtc-palmas.c
+++ b/drivers/rtc/rtc-palmas.c
@@ -30,6 +30,7 @@
30#include <linux/kernel.h> 30#include <linux/kernel.h>
31#include <linux/mfd/palmas.h> 31#include <linux/mfd/palmas.h>
32#include <linux/module.h> 32#include <linux/module.h>
33#include <linux/of.h>
33#include <linux/rtc.h> 34#include <linux/rtc.h>
34#include <linux/types.h> 35#include <linux/types.h>
35#include <linux/platform_device.h> 36#include <linux/platform_device.h>
@@ -264,7 +265,7 @@ static int palmas_rtc_probe(struct platform_device *pdev)
264 265
265 palmas_rtc->irq = platform_get_irq(pdev, 0); 266 palmas_rtc->irq = platform_get_irq(pdev, 0);
266 267
267 palmas_rtc->rtc = rtc_device_register(pdev->name, &pdev->dev, 268 palmas_rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
268 &palmas_rtc_ops, THIS_MODULE); 269 &palmas_rtc_ops, THIS_MODULE);
269 if (IS_ERR(palmas_rtc->rtc)) { 270 if (IS_ERR(palmas_rtc->rtc)) {
270 ret = PTR_ERR(palmas_rtc->rtc); 271 ret = PTR_ERR(palmas_rtc->rtc);
@@ -272,14 +273,13 @@ static int palmas_rtc_probe(struct platform_device *pdev)
272 return ret; 273 return ret;
273 } 274 }
274 275
275 ret = request_threaded_irq(palmas_rtc->irq, NULL, 276 ret = devm_request_threaded_irq(&pdev->dev, palmas_rtc->irq, NULL,
276 palmas_rtc_interrupt, 277 palmas_rtc_interrupt,
277 IRQF_TRIGGER_LOW | IRQF_ONESHOT | 278 IRQF_TRIGGER_LOW | IRQF_ONESHOT |
278 IRQF_EARLY_RESUME, 279 IRQF_EARLY_RESUME,
279 dev_name(&pdev->dev), palmas_rtc); 280 dev_name(&pdev->dev), palmas_rtc);
280 if (ret < 0) { 281 if (ret < 0) {
281 dev_err(&pdev->dev, "IRQ request failed, err = %d\n", ret); 282 dev_err(&pdev->dev, "IRQ request failed, err = %d\n", ret);
282 rtc_device_unregister(palmas_rtc->rtc);
283 return ret; 283 return ret;
284 } 284 }
285 285
@@ -289,11 +289,7 @@ static int palmas_rtc_probe(struct platform_device *pdev)
289 289
290static int palmas_rtc_remove(struct platform_device *pdev) 290static int palmas_rtc_remove(struct platform_device *pdev)
291{ 291{
292 struct palmas_rtc *palmas_rtc = platform_get_drvdata(pdev);
293
294 palmas_rtc_alarm_irq_enable(&pdev->dev, 0); 292 palmas_rtc_alarm_irq_enable(&pdev->dev, 0);
295 free_irq(palmas_rtc->irq, palmas_rtc);
296 rtc_device_unregister(palmas_rtc->rtc);
297 return 0; 293 return 0;
298} 294}
299 295
@@ -321,6 +317,14 @@ static const struct dev_pm_ops palmas_rtc_pm_ops = {
321 SET_SYSTEM_SLEEP_PM_OPS(palmas_rtc_suspend, palmas_rtc_resume) 317 SET_SYSTEM_SLEEP_PM_OPS(palmas_rtc_suspend, palmas_rtc_resume)
322}; 318};
323 319
320#ifdef CONFIG_OF
321static struct of_device_id of_palmas_rtc_match[] = {
322 { .compatible = "ti,palmas-rtc"},
323 { },
324};
325MODULE_DEVICE_TABLE(of, of_palmas_rtc_match);
326#endif
327
324static struct platform_driver palmas_rtc_driver = { 328static struct platform_driver palmas_rtc_driver = {
325 .probe = palmas_rtc_probe, 329 .probe = palmas_rtc_probe,
326 .remove = palmas_rtc_remove, 330 .remove = palmas_rtc_remove,
@@ -328,6 +332,7 @@ static struct platform_driver palmas_rtc_driver = {
328 .owner = THIS_MODULE, 332 .owner = THIS_MODULE,
329 .name = "palmas-rtc", 333 .name = "palmas-rtc",
330 .pm = &palmas_rtc_pm_ops, 334 .pm = &palmas_rtc_pm_ops,
335 .of_match_table = of_match_ptr(of_palmas_rtc_match),
331 }, 336 },
332}; 337};
333 338
diff --git a/drivers/rtc/rtc-pcap.c b/drivers/rtc/rtc-pcap.c
index e0019cd0bf71..539a90b98bc5 100644
--- a/drivers/rtc/rtc-pcap.c
+++ b/drivers/rtc/rtc-pcap.c
@@ -139,13 +139,14 @@ static const struct rtc_class_ops pcap_rtc_ops = {
139 .alarm_irq_enable = pcap_rtc_alarm_irq_enable, 139 .alarm_irq_enable = pcap_rtc_alarm_irq_enable,
140}; 140};
141 141
142static int pcap_rtc_probe(struct platform_device *pdev) 142static int __init pcap_rtc_probe(struct platform_device *pdev)
143{ 143{
144 struct pcap_rtc *pcap_rtc; 144 struct pcap_rtc *pcap_rtc;
145 int timer_irq, alarm_irq; 145 int timer_irq, alarm_irq;
146 int err = -ENOMEM; 146 int err = -ENOMEM;
147 147
148 pcap_rtc = kmalloc(sizeof(struct pcap_rtc), GFP_KERNEL); 148 pcap_rtc = devm_kzalloc(&pdev->dev, sizeof(struct pcap_rtc),
149 GFP_KERNEL);
149 if (!pcap_rtc) 150 if (!pcap_rtc)
150 return err; 151 return err;
151 152
@@ -153,68 +154,46 @@ static int pcap_rtc_probe(struct platform_device *pdev)
153 154
154 platform_set_drvdata(pdev, pcap_rtc); 155 platform_set_drvdata(pdev, pcap_rtc);
155 156
156 pcap_rtc->rtc = rtc_device_register("pcap", &pdev->dev, 157 pcap_rtc->rtc = devm_rtc_device_register(&pdev->dev, "pcap",
157 &pcap_rtc_ops, THIS_MODULE); 158 &pcap_rtc_ops, THIS_MODULE);
158 if (IS_ERR(pcap_rtc->rtc)) { 159 if (IS_ERR(pcap_rtc->rtc)) {
159 err = PTR_ERR(pcap_rtc->rtc); 160 err = PTR_ERR(pcap_rtc->rtc);
160 goto fail_rtc; 161 goto fail;
161 } 162 }
162 163
163
164 timer_irq = pcap_to_irq(pcap_rtc->pcap, PCAP_IRQ_1HZ); 164 timer_irq = pcap_to_irq(pcap_rtc->pcap, PCAP_IRQ_1HZ);
165 alarm_irq = pcap_to_irq(pcap_rtc->pcap, PCAP_IRQ_TODA); 165 alarm_irq = pcap_to_irq(pcap_rtc->pcap, PCAP_IRQ_TODA);
166 166
167 err = request_irq(timer_irq, pcap_rtc_irq, 0, "RTC Timer", pcap_rtc); 167 err = devm_request_irq(&pdev->dev, timer_irq, pcap_rtc_irq, 0,
168 "RTC Timer", pcap_rtc);
168 if (err) 169 if (err)
169 goto fail_timer; 170 goto fail;
170 171
171 err = request_irq(alarm_irq, pcap_rtc_irq, 0, "RTC Alarm", pcap_rtc); 172 err = devm_request_irq(&pdev->dev, alarm_irq, pcap_rtc_irq, 0,
173 "RTC Alarm", pcap_rtc);
172 if (err) 174 if (err)
173 goto fail_alarm; 175 goto fail;
174 176
175 return 0; 177 return 0;
176fail_alarm: 178fail:
177 free_irq(timer_irq, pcap_rtc);
178fail_timer:
179 rtc_device_unregister(pcap_rtc->rtc);
180fail_rtc:
181 platform_set_drvdata(pdev, NULL); 179 platform_set_drvdata(pdev, NULL);
182 kfree(pcap_rtc);
183 return err; 180 return err;
184} 181}
185 182
186static int pcap_rtc_remove(struct platform_device *pdev) 183static int __exit pcap_rtc_remove(struct platform_device *pdev)
187{ 184{
188 struct pcap_rtc *pcap_rtc = platform_get_drvdata(pdev);
189
190 free_irq(pcap_to_irq(pcap_rtc->pcap, PCAP_IRQ_1HZ), pcap_rtc);
191 free_irq(pcap_to_irq(pcap_rtc->pcap, PCAP_IRQ_TODA), pcap_rtc);
192 rtc_device_unregister(pcap_rtc->rtc);
193 kfree(pcap_rtc);
194
195 return 0; 185 return 0;
196} 186}
197 187
198static struct platform_driver pcap_rtc_driver = { 188static struct platform_driver pcap_rtc_driver = {
199 .remove = pcap_rtc_remove, 189 .remove = __exit_p(pcap_rtc_remove),
200 .driver = { 190 .driver = {
201 .name = "pcap-rtc", 191 .name = "pcap-rtc",
202 .owner = THIS_MODULE, 192 .owner = THIS_MODULE,
203 }, 193 },
204}; 194};
205 195
206static int __init rtc_pcap_init(void) 196module_platform_driver_probe(pcap_rtc_driver, pcap_rtc_probe);
207{
208 return platform_driver_probe(&pcap_rtc_driver, pcap_rtc_probe);
209}
210
211static void __exit rtc_pcap_exit(void)
212{
213 platform_driver_unregister(&pcap_rtc_driver);
214}
215
216module_init(rtc_pcap_init);
217module_exit(rtc_pcap_exit);
218 197
219MODULE_DESCRIPTION("Motorola pcap rtc driver"); 198MODULE_DESCRIPTION("Motorola pcap rtc driver");
220MODULE_AUTHOR("guiming zhuo <gmzhuo@gmail.com>"); 199MODULE_AUTHOR("guiming zhuo <gmzhuo@gmail.com>");
diff --git a/drivers/rtc/rtc-pcf2123.c b/drivers/rtc/rtc-pcf2123.c
index 02b742afa761..796a6c5067dd 100644
--- a/drivers/rtc/rtc-pcf2123.c
+++ b/drivers/rtc/rtc-pcf2123.c
@@ -226,7 +226,8 @@ static int pcf2123_probe(struct spi_device *spi)
226 u8 txbuf[2], rxbuf[2]; 226 u8 txbuf[2], rxbuf[2];
227 int ret, i; 227 int ret, i;
228 228
229 pdata = kzalloc(sizeof(struct pcf2123_plat_data), GFP_KERNEL); 229 pdata = devm_kzalloc(&spi->dev, sizeof(struct pcf2123_plat_data),
230 GFP_KERNEL);
230 if (!pdata) 231 if (!pdata)
231 return -ENOMEM; 232 return -ENOMEM;
232 spi->dev.platform_data = pdata; 233 spi->dev.platform_data = pdata;
@@ -265,6 +266,7 @@ static int pcf2123_probe(struct spi_device *spi)
265 266
266 if (!(rxbuf[0] & 0x20)) { 267 if (!(rxbuf[0] & 0x20)) {
267 dev_err(&spi->dev, "chip not found\n"); 268 dev_err(&spi->dev, "chip not found\n");
269 ret = -ENODEV;
268 goto kfree_exit; 270 goto kfree_exit;
269 } 271 }
270 272
@@ -281,7 +283,7 @@ static int pcf2123_probe(struct spi_device *spi)
281 pcf2123_delay_trec(); 283 pcf2123_delay_trec();
282 284
283 /* Finalize the initialization */ 285 /* Finalize the initialization */
284 rtc = rtc_device_register(pcf2123_driver.driver.name, &spi->dev, 286 rtc = devm_rtc_device_register(&spi->dev, pcf2123_driver.driver.name,
285 &pcf2123_rtc_ops, THIS_MODULE); 287 &pcf2123_rtc_ops, THIS_MODULE);
286 288
287 if (IS_ERR(rtc)) { 289 if (IS_ERR(rtc)) {
@@ -314,7 +316,6 @@ sysfs_exit:
314 device_remove_file(&spi->dev, &pdata->regs[i].attr); 316 device_remove_file(&spi->dev, &pdata->regs[i].attr);
315 317
316kfree_exit: 318kfree_exit:
317 kfree(pdata);
318 spi->dev.platform_data = NULL; 319 spi->dev.platform_data = NULL;
319 return ret; 320 return ret;
320} 321}
@@ -325,15 +326,10 @@ static int pcf2123_remove(struct spi_device *spi)
325 int i; 326 int i;
326 327
327 if (pdata) { 328 if (pdata) {
328 struct rtc_device *rtc = pdata->rtc;
329
330 if (rtc)
331 rtc_device_unregister(rtc);
332 for (i = 0; i < 16; i++) 329 for (i = 0; i < 16; i++)
333 if (pdata->regs[i].name[0]) 330 if (pdata->regs[i].name[0])
334 device_remove_file(&spi->dev, 331 device_remove_file(&spi->dev,
335 &pdata->regs[i].attr); 332 &pdata->regs[i].attr);
336 kfree(pdata);
337 } 333 }
338 334
339 return 0; 335 return 0;
diff --git a/drivers/rtc/rtc-pcf50633.c b/drivers/rtc/rtc-pcf50633.c
index e9f3135d305f..e6b6911c8e05 100644
--- a/drivers/rtc/rtc-pcf50633.c
+++ b/drivers/rtc/rtc-pcf50633.c
@@ -252,20 +252,17 @@ static int pcf50633_rtc_probe(struct platform_device *pdev)
252{ 252{
253 struct pcf50633_rtc *rtc; 253 struct pcf50633_rtc *rtc;
254 254
255 rtc = kzalloc(sizeof(*rtc), GFP_KERNEL); 255 rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL);
256 if (!rtc) 256 if (!rtc)
257 return -ENOMEM; 257 return -ENOMEM;
258 258
259 rtc->pcf = dev_to_pcf50633(pdev->dev.parent); 259 rtc->pcf = dev_to_pcf50633(pdev->dev.parent);
260 platform_set_drvdata(pdev, rtc); 260 platform_set_drvdata(pdev, rtc);
261 rtc->rtc_dev = rtc_device_register("pcf50633-rtc", &pdev->dev, 261 rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, "pcf50633-rtc",
262 &pcf50633_rtc_ops, THIS_MODULE); 262 &pcf50633_rtc_ops, THIS_MODULE);
263 263
264 if (IS_ERR(rtc->rtc_dev)) { 264 if (IS_ERR(rtc->rtc_dev))
265 int ret = PTR_ERR(rtc->rtc_dev); 265 return PTR_ERR(rtc->rtc_dev);
266 kfree(rtc);
267 return ret;
268 }
269 266
270 pcf50633_register_irq(rtc->pcf, PCF50633_IRQ_ALARM, 267 pcf50633_register_irq(rtc->pcf, PCF50633_IRQ_ALARM,
271 pcf50633_rtc_irq, rtc); 268 pcf50633_rtc_irq, rtc);
@@ -277,12 +274,8 @@ static int pcf50633_rtc_remove(struct platform_device *pdev)
277 struct pcf50633_rtc *rtc; 274 struct pcf50633_rtc *rtc;
278 275
279 rtc = platform_get_drvdata(pdev); 276 rtc = platform_get_drvdata(pdev);
280
281 pcf50633_free_irq(rtc->pcf, PCF50633_IRQ_ALARM); 277 pcf50633_free_irq(rtc->pcf, PCF50633_IRQ_ALARM);
282 278
283 rtc_device_unregister(rtc->rtc_dev);
284 kfree(rtc);
285
286 return 0; 279 return 0;
287} 280}
288 281
diff --git a/drivers/rtc/rtc-pcf8523.c b/drivers/rtc/rtc-pcf8523.c
index 889e3160e701..305c9515e5bb 100644
--- a/drivers/rtc/rtc-pcf8523.c
+++ b/drivers/rtc/rtc-pcf8523.c
@@ -307,7 +307,7 @@ static int pcf8523_probe(struct i2c_client *client,
307 if (err < 0) 307 if (err < 0)
308 return err; 308 return err;
309 309
310 pcf->rtc = rtc_device_register(DRIVER_NAME, &client->dev, 310 pcf->rtc = devm_rtc_device_register(&client->dev, DRIVER_NAME,
311 &pcf8523_rtc_ops, THIS_MODULE); 311 &pcf8523_rtc_ops, THIS_MODULE);
312 if (IS_ERR(pcf->rtc)) 312 if (IS_ERR(pcf->rtc))
313 return PTR_ERR(pcf->rtc); 313 return PTR_ERR(pcf->rtc);
@@ -319,10 +319,6 @@ static int pcf8523_probe(struct i2c_client *client,
319 319
320static int pcf8523_remove(struct i2c_client *client) 320static int pcf8523_remove(struct i2c_client *client)
321{ 321{
322 struct pcf8523 *pcf = i2c_get_clientdata(client);
323
324 rtc_device_unregister(pcf->rtc);
325
326 return 0; 322 return 0;
327} 323}
328 324
diff --git a/drivers/rtc/rtc-pcf8563.c b/drivers/rtc/rtc-pcf8563.c
index f7daf18a112e..97b354a26a44 100644
--- a/drivers/rtc/rtc-pcf8563.c
+++ b/drivers/rtc/rtc-pcf8563.c
@@ -245,14 +245,13 @@ static int pcf8563_probe(struct i2c_client *client,
245{ 245{
246 struct pcf8563 *pcf8563; 246 struct pcf8563 *pcf8563;
247 247
248 int err = 0;
249
250 dev_dbg(&client->dev, "%s\n", __func__); 248 dev_dbg(&client->dev, "%s\n", __func__);
251 249
252 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) 250 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
253 return -ENODEV; 251 return -ENODEV;
254 252
255 pcf8563 = kzalloc(sizeof(struct pcf8563), GFP_KERNEL); 253 pcf8563 = devm_kzalloc(&client->dev, sizeof(struct pcf8563),
254 GFP_KERNEL);
256 if (!pcf8563) 255 if (!pcf8563)
257 return -ENOMEM; 256 return -ENOMEM;
258 257
@@ -260,31 +259,18 @@ static int pcf8563_probe(struct i2c_client *client,
260 259
261 i2c_set_clientdata(client, pcf8563); 260 i2c_set_clientdata(client, pcf8563);
262 261
263 pcf8563->rtc = rtc_device_register(pcf8563_driver.driver.name, 262 pcf8563->rtc = devm_rtc_device_register(&client->dev,
264 &client->dev, &pcf8563_rtc_ops, THIS_MODULE); 263 pcf8563_driver.driver.name,
264 &pcf8563_rtc_ops, THIS_MODULE);
265 265
266 if (IS_ERR(pcf8563->rtc)) { 266 if (IS_ERR(pcf8563->rtc))
267 err = PTR_ERR(pcf8563->rtc); 267 return PTR_ERR(pcf8563->rtc);
268 goto exit_kfree;
269 }
270 268
271 return 0; 269 return 0;
272
273exit_kfree:
274 kfree(pcf8563);
275
276 return err;
277} 270}
278 271
279static int pcf8563_remove(struct i2c_client *client) 272static int pcf8563_remove(struct i2c_client *client)
280{ 273{
281 struct pcf8563 *pcf8563 = i2c_get_clientdata(client);
282
283 if (pcf8563->rtc)
284 rtc_device_unregister(pcf8563->rtc);
285
286 kfree(pcf8563);
287
288 return 0; 274 return 0;
289} 275}
290 276
diff --git a/drivers/rtc/rtc-pcf8583.c b/drivers/rtc/rtc-pcf8583.c
index 5f97c61247d5..95886dcf4a39 100644
--- a/drivers/rtc/rtc-pcf8583.c
+++ b/drivers/rtc/rtc-pcf8583.c
@@ -268,39 +268,29 @@ static int pcf8583_probe(struct i2c_client *client,
268 const struct i2c_device_id *id) 268 const struct i2c_device_id *id)
269{ 269{
270 struct pcf8583 *pcf8583; 270 struct pcf8583 *pcf8583;
271 int err;
272 271
273 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) 272 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
274 return -ENODEV; 273 return -ENODEV;
275 274
276 pcf8583 = kzalloc(sizeof(struct pcf8583), GFP_KERNEL); 275 pcf8583 = devm_kzalloc(&client->dev, sizeof(struct pcf8583),
276 GFP_KERNEL);
277 if (!pcf8583) 277 if (!pcf8583)
278 return -ENOMEM; 278 return -ENOMEM;
279 279
280 i2c_set_clientdata(client, pcf8583); 280 i2c_set_clientdata(client, pcf8583);
281 281
282 pcf8583->rtc = rtc_device_register(pcf8583_driver.driver.name, 282 pcf8583->rtc = devm_rtc_device_register(&client->dev,
283 &client->dev, &pcf8583_rtc_ops, THIS_MODULE); 283 pcf8583_driver.driver.name,
284 &pcf8583_rtc_ops, THIS_MODULE);
284 285
285 if (IS_ERR(pcf8583->rtc)) { 286 if (IS_ERR(pcf8583->rtc))
286 err = PTR_ERR(pcf8583->rtc); 287 return PTR_ERR(pcf8583->rtc);
287 goto exit_kfree;
288 }
289 288
290 return 0; 289 return 0;
291
292exit_kfree:
293 kfree(pcf8583);
294 return err;
295} 290}
296 291
297static int pcf8583_remove(struct i2c_client *client) 292static int pcf8583_remove(struct i2c_client *client)
298{ 293{
299 struct pcf8583 *pcf8583 = i2c_get_clientdata(client);
300
301 if (pcf8583->rtc)
302 rtc_device_unregister(pcf8583->rtc);
303 kfree(pcf8583);
304 return 0; 294 return 0;
305} 295}
306 296
diff --git a/drivers/rtc/rtc-proc.c b/drivers/rtc/rtc-proc.c
index e96236ac2e78..ffa69e1c9245 100644
--- a/drivers/rtc/rtc-proc.c
+++ b/drivers/rtc/rtc-proc.c
@@ -110,7 +110,7 @@ static int rtc_proc_show(struct seq_file *seq, void *offset)
110static int rtc_proc_open(struct inode *inode, struct file *file) 110static int rtc_proc_open(struct inode *inode, struct file *file)
111{ 111{
112 int ret; 112 int ret;
113 struct rtc_device *rtc = PDE(inode)->data; 113 struct rtc_device *rtc = PDE_DATA(inode);
114 114
115 if (!try_module_get(THIS_MODULE)) 115 if (!try_module_get(THIS_MODULE))
116 return -ENODEV; 116 return -ENODEV;
diff --git a/drivers/rtc/rtc-ps3.c b/drivers/rtc/rtc-ps3.c
index 968133ce1ee8..4bb825bb5804 100644
--- a/drivers/rtc/rtc-ps3.c
+++ b/drivers/rtc/rtc-ps3.c
@@ -62,7 +62,7 @@ static int __init ps3_rtc_probe(struct platform_device *dev)
62{ 62{
63 struct rtc_device *rtc; 63 struct rtc_device *rtc;
64 64
65 rtc = rtc_device_register("rtc-ps3", &dev->dev, &ps3_rtc_ops, 65 rtc = devm_rtc_device_register(&dev->dev, "rtc-ps3", &ps3_rtc_ops,
66 THIS_MODULE); 66 THIS_MODULE);
67 if (IS_ERR(rtc)) 67 if (IS_ERR(rtc))
68 return PTR_ERR(rtc); 68 return PTR_ERR(rtc);
@@ -73,7 +73,6 @@ static int __init ps3_rtc_probe(struct platform_device *dev)
73 73
74static int __exit ps3_rtc_remove(struct platform_device *dev) 74static int __exit ps3_rtc_remove(struct platform_device *dev)
75{ 75{
76 rtc_device_unregister(platform_get_drvdata(dev));
77 return 0; 76 return 0;
78} 77}
79 78
@@ -85,18 +84,7 @@ static struct platform_driver ps3_rtc_driver = {
85 .remove = __exit_p(ps3_rtc_remove), 84 .remove = __exit_p(ps3_rtc_remove),
86}; 85};
87 86
88static int __init ps3_rtc_init(void) 87module_platform_driver_probe(ps3_rtc_driver, ps3_rtc_probe);
89{
90 return platform_driver_probe(&ps3_rtc_driver, ps3_rtc_probe);
91}
92
93static void __exit ps3_rtc_fini(void)
94{
95 platform_driver_unregister(&ps3_rtc_driver);
96}
97
98module_init(ps3_rtc_init);
99module_exit(ps3_rtc_fini);
100 88
101MODULE_AUTHOR("Sony Corporation"); 89MODULE_AUTHOR("Sony Corporation");
102MODULE_LICENSE("GPL"); 90MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-puv3.c b/drivers/rtc/rtc-puv3.c
index 0407e13d4de4..72f437170d2e 100644
--- a/drivers/rtc/rtc-puv3.c
+++ b/drivers/rtc/rtc-puv3.c
@@ -207,14 +207,14 @@ static const struct rtc_class_ops puv3_rtcops = {
207 .proc = puv3_rtc_proc, 207 .proc = puv3_rtc_proc,
208}; 208};
209 209
210static void puv3_rtc_enable(struct platform_device *pdev, int en) 210static void puv3_rtc_enable(struct device *dev, int en)
211{ 211{
212 if (!en) { 212 if (!en) {
213 writel(readl(RTC_RTSR) & ~RTC_RTSR_HZE, RTC_RTSR); 213 writel(readl(RTC_RTSR) & ~RTC_RTSR_HZE, RTC_RTSR);
214 } else { 214 } else {
215 /* re-enable the device, and check it is ok */ 215 /* re-enable the device, and check it is ok */
216 if ((readl(RTC_RTSR) & RTC_RTSR_HZE) == 0) { 216 if ((readl(RTC_RTSR) & RTC_RTSR_HZE) == 0) {
217 dev_info(&pdev->dev, "rtc disabled, re-enabling\n"); 217 dev_info(dev, "rtc disabled, re-enabling\n");
218 writel(readl(RTC_RTSR) | RTC_RTSR_HZE, RTC_RTSR); 218 writel(readl(RTC_RTSR) | RTC_RTSR_HZE, RTC_RTSR);
219 } 219 }
220 } 220 }
@@ -276,7 +276,7 @@ static int puv3_rtc_probe(struct platform_device *pdev)
276 goto err_nores; 276 goto err_nores;
277 } 277 }
278 278
279 puv3_rtc_enable(pdev, 1); 279 puv3_rtc_enable(&pdev->dev, 1);
280 280
281 /* register RTC and exit */ 281 /* register RTC and exit */
282 rtc = rtc_device_register("pkunity", &pdev->dev, &puv3_rtcops, 282 rtc = rtc_device_register("pkunity", &pdev->dev, &puv3_rtcops,
@@ -296,44 +296,41 @@ static int puv3_rtc_probe(struct platform_device *pdev)
296 return 0; 296 return 0;
297 297
298 err_nortc: 298 err_nortc:
299 puv3_rtc_enable(pdev, 0); 299 puv3_rtc_enable(&pdev->dev, 0);
300 release_resource(puv3_rtc_mem); 300 release_resource(puv3_rtc_mem);
301 301
302 err_nores: 302 err_nores:
303 return ret; 303 return ret;
304} 304}
305 305
306#ifdef CONFIG_PM 306#ifdef CONFIG_PM_SLEEP
307
308static int ticnt_save; 307static int ticnt_save;
309 308
310static int puv3_rtc_suspend(struct platform_device *pdev, pm_message_t state) 309static int puv3_rtc_suspend(struct device *dev)
311{ 310{
312 /* save RTAR for anyone using periodic interrupts */ 311 /* save RTAR for anyone using periodic interrupts */
313 ticnt_save = readl(RTC_RTAR); 312 ticnt_save = readl(RTC_RTAR);
314 puv3_rtc_enable(pdev, 0); 313 puv3_rtc_enable(dev, 0);
315 return 0; 314 return 0;
316} 315}
317 316
318static int puv3_rtc_resume(struct platform_device *pdev) 317static int puv3_rtc_resume(struct device *dev)
319{ 318{
320 puv3_rtc_enable(pdev, 1); 319 puv3_rtc_enable(dev, 1);
321 writel(ticnt_save, RTC_RTAR); 320 writel(ticnt_save, RTC_RTAR);
322 return 0; 321 return 0;
323} 322}
324#else
325#define puv3_rtc_suspend NULL
326#define puv3_rtc_resume NULL
327#endif 323#endif
328 324
325static SIMPLE_DEV_PM_OPS(puv3_rtc_pm_ops, puv3_rtc_suspend, puv3_rtc_resume);
326
329static struct platform_driver puv3_rtc_driver = { 327static struct platform_driver puv3_rtc_driver = {
330 .probe = puv3_rtc_probe, 328 .probe = puv3_rtc_probe,
331 .remove = puv3_rtc_remove, 329 .remove = puv3_rtc_remove,
332 .suspend = puv3_rtc_suspend,
333 .resume = puv3_rtc_resume,
334 .driver = { 330 .driver = {
335 .name = "PKUnity-v3-RTC", 331 .name = "PKUnity-v3-RTC",
336 .owner = THIS_MODULE, 332 .owner = THIS_MODULE,
333 .pm = &puv3_rtc_pm_ops,
337 } 334 }
338}; 335};
339 336
diff --git a/drivers/rtc/rtc-pxa.c b/drivers/rtc/rtc-pxa.c
index 03c85ee719a7..ed037ae91c5f 100644
--- a/drivers/rtc/rtc-pxa.c
+++ b/drivers/rtc/rtc-pxa.c
@@ -416,7 +416,7 @@ static struct of_device_id pxa_rtc_dt_ids[] = {
416MODULE_DEVICE_TABLE(of, pxa_rtc_dt_ids); 416MODULE_DEVICE_TABLE(of, pxa_rtc_dt_ids);
417#endif 417#endif
418 418
419#ifdef CONFIG_PM 419#ifdef CONFIG_PM_SLEEP
420static int pxa_rtc_suspend(struct device *dev) 420static int pxa_rtc_suspend(struct device *dev)
421{ 421{
422 struct pxa_rtc *pxa_rtc = dev_get_drvdata(dev); 422 struct pxa_rtc *pxa_rtc = dev_get_drvdata(dev);
@@ -434,36 +434,20 @@ static int pxa_rtc_resume(struct device *dev)
434 disable_irq_wake(pxa_rtc->irq_Alrm); 434 disable_irq_wake(pxa_rtc->irq_Alrm);
435 return 0; 435 return 0;
436} 436}
437
438static const struct dev_pm_ops pxa_rtc_pm_ops = {
439 .suspend = pxa_rtc_suspend,
440 .resume = pxa_rtc_resume,
441};
442#endif 437#endif
443 438
439static SIMPLE_DEV_PM_OPS(pxa_rtc_pm_ops, pxa_rtc_suspend, pxa_rtc_resume);
440
444static struct platform_driver pxa_rtc_driver = { 441static struct platform_driver pxa_rtc_driver = {
445 .remove = __exit_p(pxa_rtc_remove), 442 .remove = __exit_p(pxa_rtc_remove),
446 .driver = { 443 .driver = {
447 .name = "pxa-rtc", 444 .name = "pxa-rtc",
448 .of_match_table = of_match_ptr(pxa_rtc_dt_ids), 445 .of_match_table = of_match_ptr(pxa_rtc_dt_ids),
449#ifdef CONFIG_PM
450 .pm = &pxa_rtc_pm_ops, 446 .pm = &pxa_rtc_pm_ops,
451#endif
452 }, 447 },
453}; 448};
454 449
455static int __init pxa_rtc_init(void) 450module_platform_driver_probe(pxa_rtc_driver, pxa_rtc_probe);
456{
457 return platform_driver_probe(&pxa_rtc_driver, pxa_rtc_probe);
458}
459
460static void __exit pxa_rtc_exit(void)
461{
462 platform_driver_unregister(&pxa_rtc_driver);
463}
464
465module_init(pxa_rtc_init);
466module_exit(pxa_rtc_exit);
467 451
468MODULE_AUTHOR("Robert Jarzmik <robert.jarzmik@free.fr>"); 452MODULE_AUTHOR("Robert Jarzmik <robert.jarzmik@free.fr>");
469MODULE_DESCRIPTION("PXA27x/PXA3xx Realtime Clock Driver (RTC)"); 453MODULE_DESCRIPTION("PXA27x/PXA3xx Realtime Clock Driver (RTC)");
diff --git a/drivers/rtc/rtc-r9701.c b/drivers/rtc/rtc-r9701.c
index 7726f4a4f2d0..feeedbd82000 100644
--- a/drivers/rtc/rtc-r9701.c
+++ b/drivers/rtc/rtc-r9701.c
@@ -154,21 +154,18 @@ static int r9701_probe(struct spi_device *spi)
154 } 154 }
155 } 155 }
156 156
157 rtc = rtc_device_register("r9701", 157 rtc = devm_rtc_device_register(&spi->dev, "r9701",
158 &spi->dev, &r9701_rtc_ops, THIS_MODULE); 158 &r9701_rtc_ops, THIS_MODULE);
159 if (IS_ERR(rtc)) 159 if (IS_ERR(rtc))
160 return PTR_ERR(rtc); 160 return PTR_ERR(rtc);
161 161
162 dev_set_drvdata(&spi->dev, rtc); 162 spi_set_drvdata(spi, rtc);
163 163
164 return 0; 164 return 0;
165} 165}
166 166
167static int r9701_remove(struct spi_device *spi) 167static int r9701_remove(struct spi_device *spi)
168{ 168{
169 struct rtc_device *rtc = dev_get_drvdata(&spi->dev);
170
171 rtc_device_unregister(rtc);
172 return 0; 169 return 0;
173} 170}
174 171
diff --git a/drivers/rtc/rtc-rc5t583.c b/drivers/rtc/rtc-rc5t583.c
index eb3194d664a8..8eabcf51b35a 100644
--- a/drivers/rtc/rtc-rc5t583.c
+++ b/drivers/rtc/rtc-rc5t583.c
@@ -256,7 +256,7 @@ static int rc5t583_rtc_probe(struct platform_device *pdev)
256 } 256 }
257 device_init_wakeup(&pdev->dev, 1); 257 device_init_wakeup(&pdev->dev, 1);
258 258
259 ricoh_rtc->rtc = rtc_device_register(pdev->name, &pdev->dev, 259 ricoh_rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
260 &rc5t583_rtc_ops, THIS_MODULE); 260 &rc5t583_rtc_ops, THIS_MODULE);
261 if (IS_ERR(ricoh_rtc->rtc)) { 261 if (IS_ERR(ricoh_rtc->rtc)) {
262 ret = PTR_ERR(ricoh_rtc->rtc); 262 ret = PTR_ERR(ricoh_rtc->rtc);
@@ -276,13 +276,10 @@ static int rc5t583_rtc_remove(struct platform_device *pdev)
276 struct rc5t583_rtc *rc5t583_rtc = dev_get_drvdata(&pdev->dev); 276 struct rc5t583_rtc *rc5t583_rtc = dev_get_drvdata(&pdev->dev);
277 277
278 rc5t583_rtc_alarm_irq_enable(&rc5t583_rtc->rtc->dev, 0); 278 rc5t583_rtc_alarm_irq_enable(&rc5t583_rtc->rtc->dev, 0);
279
280 rtc_device_unregister(rc5t583_rtc->rtc);
281 return 0; 279 return 0;
282} 280}
283 281
284#ifdef CONFIG_PM_SLEEP 282#ifdef CONFIG_PM_SLEEP
285
286static int rc5t583_rtc_suspend(struct device *dev) 283static int rc5t583_rtc_suspend(struct device *dev)
287{ 284{
288 struct rc5t583 *rc5t583 = dev_get_drvdata(dev->parent); 285 struct rc5t583 *rc5t583 = dev_get_drvdata(dev->parent);
@@ -304,24 +301,18 @@ static int rc5t583_rtc_resume(struct device *dev)
304 return regmap_write(rc5t583->regmap, RC5T583_RTC_CTL1, 301 return regmap_write(rc5t583->regmap, RC5T583_RTC_CTL1,
305 rc5t583_rtc->irqen); 302 rc5t583_rtc->irqen);
306} 303}
307
308static const struct dev_pm_ops rc5t583_rtc_pm_ops = {
309 .suspend = rc5t583_rtc_suspend,
310 .resume = rc5t583_rtc_resume,
311};
312
313#define DEV_PM_OPS (&rc5t583_rtc_pm_ops)
314#else
315#define DEV_PM_OPS NULL
316#endif 304#endif
317 305
306static SIMPLE_DEV_PM_OPS(rc5t583_rtc_pm_ops, rc5t583_rtc_suspend,
307 rc5t583_rtc_resume);
308
318static struct platform_driver rc5t583_rtc_driver = { 309static struct platform_driver rc5t583_rtc_driver = {
319 .probe = rc5t583_rtc_probe, 310 .probe = rc5t583_rtc_probe,
320 .remove = rc5t583_rtc_remove, 311 .remove = rc5t583_rtc_remove,
321 .driver = { 312 .driver = {
322 .owner = THIS_MODULE, 313 .owner = THIS_MODULE,
323 .name = "rtc-rc5t583", 314 .name = "rtc-rc5t583",
324 .pm = DEV_PM_OPS, 315 .pm = &rc5t583_rtc_pm_ops,
325 }, 316 },
326}; 317};
327 318
diff --git a/drivers/rtc/rtc-rp5c01.c b/drivers/rtc/rtc-rp5c01.c
index 359da6d020b9..873c689f01c3 100644
--- a/drivers/rtc/rtc-rp5c01.c
+++ b/drivers/rtc/rtc-rp5c01.c
@@ -230,15 +230,13 @@ static int __init rp5c01_rtc_probe(struct platform_device *dev)
230 if (!res) 230 if (!res)
231 return -ENODEV; 231 return -ENODEV;
232 232
233 priv = kzalloc(sizeof(*priv), GFP_KERNEL); 233 priv = devm_kzalloc(&dev->dev, sizeof(*priv), GFP_KERNEL);
234 if (!priv) 234 if (!priv)
235 return -ENOMEM; 235 return -ENOMEM;
236 236
237 priv->regs = ioremap(res->start, resource_size(res)); 237 priv->regs = devm_ioremap(&dev->dev, res->start, resource_size(res));
238 if (!priv->regs) { 238 if (!priv->regs)
239 error = -ENOMEM; 239 return -ENOMEM;
240 goto out_free_priv;
241 }
242 240
243 sysfs_bin_attr_init(&priv->nvram_attr); 241 sysfs_bin_attr_init(&priv->nvram_attr);
244 priv->nvram_attr.attr.name = "nvram"; 242 priv->nvram_attr.attr.name = "nvram";
@@ -251,27 +249,22 @@ static int __init rp5c01_rtc_probe(struct platform_device *dev)
251 249
252 platform_set_drvdata(dev, priv); 250 platform_set_drvdata(dev, priv);
253 251
254 rtc = rtc_device_register("rtc-rp5c01", &dev->dev, &rp5c01_rtc_ops, 252 rtc = devm_rtc_device_register(&dev->dev, "rtc-rp5c01", &rp5c01_rtc_ops,
255 THIS_MODULE); 253 THIS_MODULE);
256 if (IS_ERR(rtc)) { 254 if (IS_ERR(rtc)) {
257 error = PTR_ERR(rtc); 255 error = PTR_ERR(rtc);
258 goto out_unmap; 256 goto out;
259 } 257 }
260 priv->rtc = rtc; 258 priv->rtc = rtc;
261 259
262 error = sysfs_create_bin_file(&dev->dev.kobj, &priv->nvram_attr); 260 error = sysfs_create_bin_file(&dev->dev.kobj, &priv->nvram_attr);
263 if (error) 261 if (error)
264 goto out_unregister; 262 goto out;
265 263
266 return 0; 264 return 0;
267 265
268out_unregister: 266out:
269 rtc_device_unregister(rtc);
270out_unmap:
271 platform_set_drvdata(dev, NULL); 267 platform_set_drvdata(dev, NULL);
272 iounmap(priv->regs);
273out_free_priv:
274 kfree(priv);
275 return error; 268 return error;
276} 269}
277 270
@@ -280,9 +273,6 @@ static int __exit rp5c01_rtc_remove(struct platform_device *dev)
280 struct rp5c01_priv *priv = platform_get_drvdata(dev); 273 struct rp5c01_priv *priv = platform_get_drvdata(dev);
281 274
282 sysfs_remove_bin_file(&dev->dev.kobj, &priv->nvram_attr); 275 sysfs_remove_bin_file(&dev->dev.kobj, &priv->nvram_attr);
283 rtc_device_unregister(priv->rtc);
284 iounmap(priv->regs);
285 kfree(priv);
286 return 0; 276 return 0;
287} 277}
288 278
@@ -294,18 +284,7 @@ static struct platform_driver rp5c01_rtc_driver = {
294 .remove = __exit_p(rp5c01_rtc_remove), 284 .remove = __exit_p(rp5c01_rtc_remove),
295}; 285};
296 286
297static int __init rp5c01_rtc_init(void) 287module_platform_driver_probe(rp5c01_rtc_driver, rp5c01_rtc_probe);
298{
299 return platform_driver_probe(&rp5c01_rtc_driver, rp5c01_rtc_probe);
300}
301
302static void __exit rp5c01_rtc_fini(void)
303{
304 platform_driver_unregister(&rp5c01_rtc_driver);
305}
306
307module_init(rp5c01_rtc_init);
308module_exit(rp5c01_rtc_fini);
309 288
310MODULE_AUTHOR("Geert Uytterhoeven <geert@linux-m68k.org>"); 289MODULE_AUTHOR("Geert Uytterhoeven <geert@linux-m68k.org>");
311MODULE_LICENSE("GPL"); 290MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-rs5c313.c b/drivers/rtc/rtc-rs5c313.c
index d98ea5b759c8..8089fc63e403 100644
--- a/drivers/rtc/rtc-rs5c313.c
+++ b/drivers/rtc/rtc-rs5c313.c
@@ -367,7 +367,7 @@ static const struct rtc_class_ops rs5c313_rtc_ops = {
367 367
368static int rs5c313_rtc_probe(struct platform_device *pdev) 368static int rs5c313_rtc_probe(struct platform_device *pdev)
369{ 369{
370 struct rtc_device *rtc = rtc_device_register("rs5c313", &pdev->dev, 370 struct rtc_device *rtc = devm_rtc_device_register(&pdev->dev, "rs5c313",
371 &rs5c313_rtc_ops, THIS_MODULE); 371 &rs5c313_rtc_ops, THIS_MODULE);
372 372
373 if (IS_ERR(rtc)) 373 if (IS_ERR(rtc))
@@ -380,10 +380,6 @@ static int rs5c313_rtc_probe(struct platform_device *pdev)
380 380
381static int rs5c313_rtc_remove(struct platform_device *pdev) 381static int rs5c313_rtc_remove(struct platform_device *pdev)
382{ 382{
383 struct rtc_device *rtc = platform_get_drvdata( pdev );
384
385 rtc_device_unregister(rtc);
386
387 return 0; 383 return 0;
388} 384}
389 385
diff --git a/drivers/rtc/rtc-rs5c348.c b/drivers/rtc/rtc-rs5c348.c
index 72ef10be8662..2c37df3586c7 100644
--- a/drivers/rtc/rtc-rs5c348.c
+++ b/drivers/rtc/rtc-rs5c348.c
@@ -158,7 +158,8 @@ static int rs5c348_probe(struct spi_device *spi)
158 struct rtc_device *rtc; 158 struct rtc_device *rtc;
159 struct rs5c348_plat_data *pdata; 159 struct rs5c348_plat_data *pdata;
160 160
161 pdata = kzalloc(sizeof(struct rs5c348_plat_data), GFP_KERNEL); 161 pdata = devm_kzalloc(&spi->dev, sizeof(struct rs5c348_plat_data),
162 GFP_KERNEL);
162 if (!pdata) 163 if (!pdata)
163 return -ENOMEM; 164 return -ENOMEM;
164 spi->dev.platform_data = pdata; 165 spi->dev.platform_data = pdata;
@@ -202,7 +203,7 @@ static int rs5c348_probe(struct spi_device *spi)
202 if (ret & RS5C348_BIT_24H) 203 if (ret & RS5C348_BIT_24H)
203 pdata->rtc_24h = 1; 204 pdata->rtc_24h = 1;
204 205
205 rtc = rtc_device_register(rs5c348_driver.driver.name, &spi->dev, 206 rtc = devm_rtc_device_register(&spi->dev, rs5c348_driver.driver.name,
206 &rs5c348_rtc_ops, THIS_MODULE); 207 &rs5c348_rtc_ops, THIS_MODULE);
207 208
208 if (IS_ERR(rtc)) { 209 if (IS_ERR(rtc)) {
@@ -214,18 +215,11 @@ static int rs5c348_probe(struct spi_device *spi)
214 215
215 return 0; 216 return 0;
216 kfree_exit: 217 kfree_exit:
217 kfree(pdata);
218 return ret; 218 return ret;
219} 219}
220 220
221static int rs5c348_remove(struct spi_device *spi) 221static int rs5c348_remove(struct spi_device *spi)
222{ 222{
223 struct rs5c348_plat_data *pdata = spi->dev.platform_data;
224 struct rtc_device *rtc = pdata->rtc;
225
226 if (rtc)
227 rtc_device_unregister(rtc);
228 kfree(pdata);
229 return 0; 223 return 0;
230} 224}
231 225
diff --git a/drivers/rtc/rtc-rs5c372.c b/drivers/rtc/rtc-rs5c372.c
index 581739f40097..ccf54f06396b 100644
--- a/drivers/rtc/rtc-rs5c372.c
+++ b/drivers/rtc/rtc-rs5c372.c
@@ -68,6 +68,7 @@
68enum rtc_type { 68enum rtc_type {
69 rtc_undef = 0, 69 rtc_undef = 0,
70 rtc_r2025sd, 70 rtc_r2025sd,
71 rtc_r2221tl,
71 rtc_rs5c372a, 72 rtc_rs5c372a,
72 rtc_rs5c372b, 73 rtc_rs5c372b,
73 rtc_rv5c386, 74 rtc_rv5c386,
@@ -76,6 +77,7 @@ enum rtc_type {
76 77
77static const struct i2c_device_id rs5c372_id[] = { 78static const struct i2c_device_id rs5c372_id[] = {
78 { "r2025sd", rtc_r2025sd }, 79 { "r2025sd", rtc_r2025sd },
80 { "r2221tl", rtc_r2221tl },
79 { "rs5c372a", rtc_rs5c372a }, 81 { "rs5c372a", rtc_rs5c372a },
80 { "rs5c372b", rtc_rs5c372b }, 82 { "rs5c372b", rtc_rs5c372b },
81 { "rv5c386", rtc_rv5c386 }, 83 { "rv5c386", rtc_rv5c386 },
@@ -529,6 +531,7 @@ static int rs5c_oscillator_setup(struct rs5c372 *rs5c372)
529 rs5c372->time24 = 1; 531 rs5c372->time24 = 1;
530 break; 532 break;
531 case rtc_r2025sd: 533 case rtc_r2025sd:
534 case rtc_r2221tl:
532 case rtc_rv5c386: 535 case rtc_rv5c386:
533 case rtc_rv5c387a: 536 case rtc_rv5c387a:
534 buf[0] |= RV5C387_CTRL1_24; 537 buf[0] |= RV5C387_CTRL1_24;
@@ -579,7 +582,9 @@ static int rs5c372_probe(struct i2c_client *client,
579 } 582 }
580 } 583 }
581 584
582 if (!(rs5c372 = kzalloc(sizeof(struct rs5c372), GFP_KERNEL))) { 585 rs5c372 = devm_kzalloc(&client->dev, sizeof(struct rs5c372),
586 GFP_KERNEL);
587 if (!rs5c372) {
583 err = -ENOMEM; 588 err = -ENOMEM;
584 goto exit; 589 goto exit;
585 } 590 }
@@ -594,7 +599,7 @@ static int rs5c372_probe(struct i2c_client *client,
594 599
595 err = rs5c_get_regs(rs5c372); 600 err = rs5c_get_regs(rs5c372);
596 if (err < 0) 601 if (err < 0)
597 goto exit_kfree; 602 goto exit;
598 603
599 /* clock may be set for am/pm or 24 hr time */ 604 /* clock may be set for am/pm or 24 hr time */
600 switch (rs5c372->type) { 605 switch (rs5c372->type) {
@@ -607,6 +612,7 @@ static int rs5c372_probe(struct i2c_client *client,
607 rs5c372->time24 = 1; 612 rs5c372->time24 = 1;
608 break; 613 break;
609 case rtc_r2025sd: 614 case rtc_r2025sd:
615 case rtc_r2221tl:
610 case rtc_rv5c386: 616 case rtc_rv5c386:
611 case rtc_rv5c387a: 617 case rtc_rv5c387a:
612 if (rs5c372->regs[RS5C_REG_CTRL1] & RV5C387_CTRL1_24) 618 if (rs5c372->regs[RS5C_REG_CTRL1] & RV5C387_CTRL1_24)
@@ -617,7 +623,7 @@ static int rs5c372_probe(struct i2c_client *client,
617 break; 623 break;
618 default: 624 default:
619 dev_err(&client->dev, "unknown RTC type\n"); 625 dev_err(&client->dev, "unknown RTC type\n");
620 goto exit_kfree; 626 goto exit;
621 } 627 }
622 628
623 /* if the oscillator lost power and no other software (like 629 /* if the oscillator lost power and no other software (like
@@ -629,7 +635,7 @@ static int rs5c372_probe(struct i2c_client *client,
629 err = rs5c_oscillator_setup(rs5c372); 635 err = rs5c_oscillator_setup(rs5c372);
630 if (unlikely(err < 0)) { 636 if (unlikely(err < 0)) {
631 dev_err(&client->dev, "setup error\n"); 637 dev_err(&client->dev, "setup error\n");
632 goto exit_kfree; 638 goto exit;
633 } 639 }
634 640
635 if (rs5c372_get_datetime(client, &tm) < 0) 641 if (rs5c372_get_datetime(client, &tm) < 0)
@@ -638,6 +644,7 @@ static int rs5c372_probe(struct i2c_client *client,
638 dev_info(&client->dev, "%s found, %s, driver version " DRV_VERSION "\n", 644 dev_info(&client->dev, "%s found, %s, driver version " DRV_VERSION "\n",
639 ({ char *s; switch (rs5c372->type) { 645 ({ char *s; switch (rs5c372->type) {
640 case rtc_r2025sd: s = "r2025sd"; break; 646 case rtc_r2025sd: s = "r2025sd"; break;
647 case rtc_r2221tl: s = "r2221tl"; break;
641 case rtc_rs5c372a: s = "rs5c372a"; break; 648 case rtc_rs5c372a: s = "rs5c372a"; break;
642 case rtc_rs5c372b: s = "rs5c372b"; break; 649 case rtc_rs5c372b: s = "rs5c372b"; break;
643 case rtc_rv5c386: s = "rv5c386"; break; 650 case rtc_rv5c386: s = "rv5c386"; break;
@@ -648,38 +655,28 @@ static int rs5c372_probe(struct i2c_client *client,
648 ); 655 );
649 656
650 /* REVISIT use client->irq to register alarm irq ... */ 657 /* REVISIT use client->irq to register alarm irq ... */
651 658 rs5c372->rtc = devm_rtc_device_register(&client->dev,
652 rs5c372->rtc = rtc_device_register(rs5c372_driver.driver.name, 659 rs5c372_driver.driver.name,
653 &client->dev, &rs5c372_rtc_ops, THIS_MODULE); 660 &rs5c372_rtc_ops, THIS_MODULE);
654 661
655 if (IS_ERR(rs5c372->rtc)) { 662 if (IS_ERR(rs5c372->rtc)) {
656 err = PTR_ERR(rs5c372->rtc); 663 err = PTR_ERR(rs5c372->rtc);
657 goto exit_kfree; 664 goto exit;
658 } 665 }
659 666
660 err = rs5c_sysfs_register(&client->dev); 667 err = rs5c_sysfs_register(&client->dev);
661 if (err) 668 if (err)
662 goto exit_devreg; 669 goto exit;
663 670
664 return 0; 671 return 0;
665 672
666exit_devreg:
667 rtc_device_unregister(rs5c372->rtc);
668
669exit_kfree:
670 kfree(rs5c372);
671
672exit: 673exit:
673 return err; 674 return err;
674} 675}
675 676
676static int rs5c372_remove(struct i2c_client *client) 677static int rs5c372_remove(struct i2c_client *client)
677{ 678{
678 struct rs5c372 *rs5c372 = i2c_get_clientdata(client);
679
680 rtc_device_unregister(rs5c372->rtc);
681 rs5c_sysfs_unregister(&client->dev); 679 rs5c_sysfs_unregister(&client->dev);
682 kfree(rs5c372);
683 return 0; 680 return 0;
684} 681}
685 682
diff --git a/drivers/rtc/rtc-rv3029c2.c b/drivers/rtc/rtc-rv3029c2.c
index f8ee8ad7825e..5032c24ec159 100644
--- a/drivers/rtc/rtc-rv3029c2.c
+++ b/drivers/rtc/rtc-rv3029c2.c
@@ -395,9 +395,8 @@ static int rv3029c2_probe(struct i2c_client *client,
395 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_EMUL)) 395 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_EMUL))
396 return -ENODEV; 396 return -ENODEV;
397 397
398 rtc = rtc_device_register(client->name, 398 rtc = devm_rtc_device_register(&client->dev, client->name,
399 &client->dev, &rv3029c2_rtc_ops, 399 &rv3029c2_rtc_ops, THIS_MODULE);
400 THIS_MODULE);
401 400
402 if (IS_ERR(rtc)) 401 if (IS_ERR(rtc))
403 return PTR_ERR(rtc); 402 return PTR_ERR(rtc);
@@ -407,23 +406,14 @@ static int rv3029c2_probe(struct i2c_client *client,
407 rc = rv3029c2_i2c_get_sr(client, buf); 406 rc = rv3029c2_i2c_get_sr(client, buf);
408 if (rc < 0) { 407 if (rc < 0) {
409 dev_err(&client->dev, "reading status failed\n"); 408 dev_err(&client->dev, "reading status failed\n");
410 goto exit_unregister; 409 return rc;
411 } 410 }
412 411
413 return 0; 412 return 0;
414
415exit_unregister:
416 rtc_device_unregister(rtc);
417
418 return rc;
419} 413}
420 414
421static int rv3029c2_remove(struct i2c_client *client) 415static int rv3029c2_remove(struct i2c_client *client)
422{ 416{
423 struct rtc_device *rtc = i2c_get_clientdata(client);
424
425 rtc_device_unregister(rtc);
426
427 return 0; 417 return 0;
428} 418}
429 419
diff --git a/drivers/rtc/rtc-rx4581.c b/drivers/rtc/rtc-rx4581.c
index 599ec73ec886..84eb08d65d30 100644
--- a/drivers/rtc/rtc-rx4581.c
+++ b/drivers/rtc/rtc-rx4581.c
@@ -273,20 +273,17 @@ static int rx4581_probe(struct spi_device *spi)
273 if (res != 0) 273 if (res != 0)
274 return res; 274 return res;
275 275
276 rtc = rtc_device_register("rx4581", 276 rtc = devm_rtc_device_register(&spi->dev, "rx4581",
277 &spi->dev, &rx4581_rtc_ops, THIS_MODULE); 277 &rx4581_rtc_ops, THIS_MODULE);
278 if (IS_ERR(rtc)) 278 if (IS_ERR(rtc))
279 return PTR_ERR(rtc); 279 return PTR_ERR(rtc);
280 280
281 dev_set_drvdata(&spi->dev, rtc); 281 spi_set_drvdata(spi, rtc);
282 return 0; 282 return 0;
283} 283}
284 284
285static int rx4581_remove(struct spi_device *spi) 285static int rx4581_remove(struct spi_device *spi)
286{ 286{
287 struct rtc_device *rtc = dev_get_drvdata(&spi->dev);
288
289 rtc_device_unregister(rtc);
290 return 0; 287 return 0;
291} 288}
292 289
diff --git a/drivers/rtc/rtc-rx8581.c b/drivers/rtc/rtc-rx8581.c
index b0c272658fa2..07f3037b18f4 100644
--- a/drivers/rtc/rtc-rx8581.c
+++ b/drivers/rtc/rtc-rx8581.c
@@ -240,8 +240,8 @@ static int rx8581_probe(struct i2c_client *client,
240 240
241 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n"); 241 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n");
242 242
243 rtc = rtc_device_register(rx8581_driver.driver.name, 243 rtc = devm_rtc_device_register(&client->dev, rx8581_driver.driver.name,
244 &client->dev, &rx8581_rtc_ops, THIS_MODULE); 244 &rx8581_rtc_ops, THIS_MODULE);
245 245
246 if (IS_ERR(rtc)) 246 if (IS_ERR(rtc))
247 return PTR_ERR(rtc); 247 return PTR_ERR(rtc);
@@ -253,10 +253,6 @@ static int rx8581_probe(struct i2c_client *client,
253 253
254static int rx8581_remove(struct i2c_client *client) 254static int rx8581_remove(struct i2c_client *client)
255{ 255{
256 struct rtc_device *rtc = i2c_get_clientdata(client);
257
258 rtc_device_unregister(rtc);
259
260 return 0; 256 return 0;
261} 257}
262 258
diff --git a/drivers/rtc/rtc-s35390a.c b/drivers/rtc/rtc-s35390a.c
index 8a092325188d..f40afdd0e5f5 100644
--- a/drivers/rtc/rtc-s35390a.c
+++ b/drivers/rtc/rtc-s35390a.c
@@ -338,7 +338,8 @@ static int s35390a_probe(struct i2c_client *client,
338 goto exit; 338 goto exit;
339 } 339 }
340 340
341 s35390a = kzalloc(sizeof(struct s35390a), GFP_KERNEL); 341 s35390a = devm_kzalloc(&client->dev, sizeof(struct s35390a),
342 GFP_KERNEL);
342 if (!s35390a) { 343 if (!s35390a) {
343 err = -ENOMEM; 344 err = -ENOMEM;
344 goto exit; 345 goto exit;
@@ -386,8 +387,9 @@ static int s35390a_probe(struct i2c_client *client,
386 387
387 device_set_wakeup_capable(&client->dev, 1); 388 device_set_wakeup_capable(&client->dev, 1);
388 389
389 s35390a->rtc = rtc_device_register(s35390a_driver.driver.name, 390 s35390a->rtc = devm_rtc_device_register(&client->dev,
390 &client->dev, &s35390a_rtc_ops, THIS_MODULE); 391 s35390a_driver.driver.name,
392 &s35390a_rtc_ops, THIS_MODULE);
391 393
392 if (IS_ERR(s35390a->rtc)) { 394 if (IS_ERR(s35390a->rtc)) {
393 err = PTR_ERR(s35390a->rtc); 395 err = PTR_ERR(s35390a->rtc);
@@ -399,7 +401,6 @@ exit_dummy:
399 for (i = 1; i < 8; ++i) 401 for (i = 1; i < 8; ++i)
400 if (s35390a->client[i]) 402 if (s35390a->client[i])
401 i2c_unregister_device(s35390a->client[i]); 403 i2c_unregister_device(s35390a->client[i]);
402 kfree(s35390a);
403 404
404exit: 405exit:
405 return err; 406 return err;
@@ -408,15 +409,12 @@ exit:
408static int s35390a_remove(struct i2c_client *client) 409static int s35390a_remove(struct i2c_client *client)
409{ 410{
410 unsigned int i; 411 unsigned int i;
411
412 struct s35390a *s35390a = i2c_get_clientdata(client); 412 struct s35390a *s35390a = i2c_get_clientdata(client);
413
413 for (i = 1; i < 8; ++i) 414 for (i = 1; i < 8; ++i)
414 if (s35390a->client[i]) 415 if (s35390a->client[i])
415 i2c_unregister_device(s35390a->client[i]); 416 i2c_unregister_device(s35390a->client[i]);
416 417
417 rtc_device_unregister(s35390a->rtc);
418 kfree(s35390a);
419
420 return 0; 418 return 0;
421} 419}
422 420
diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c
index fb994e9ddc15..14040b22888d 100644
--- a/drivers/rtc/rtc-s3c.c
+++ b/drivers/rtc/rtc-s3c.c
@@ -29,9 +29,8 @@
29#include <linux/uaccess.h> 29#include <linux/uaccess.h>
30#include <linux/io.h> 30#include <linux/io.h>
31 31
32#include <mach/hardware.h>
33#include <asm/irq.h> 32#include <asm/irq.h>
34#include <plat/regs-rtc.h> 33#include "rtc-s3c.h"
35 34
36enum s3c_cpu_type { 35enum s3c_cpu_type {
37 TYPE_S3C2410, 36 TYPE_S3C2410,
@@ -51,7 +50,6 @@ static struct clk *rtc_clk;
51static void __iomem *s3c_rtc_base; 50static void __iomem *s3c_rtc_base;
52static int s3c_rtc_alarmno = NO_IRQ; 51static int s3c_rtc_alarmno = NO_IRQ;
53static int s3c_rtc_tickno = NO_IRQ; 52static int s3c_rtc_tickno = NO_IRQ;
54static bool wake_en;
55static enum s3c_cpu_type s3c_rtc_cpu_type; 53static enum s3c_cpu_type s3c_rtc_cpu_type;
56 54
57static DEFINE_SPINLOCK(s3c_rtc_pie_lock); 55static DEFINE_SPINLOCK(s3c_rtc_pie_lock);
@@ -423,13 +421,11 @@ static void s3c_rtc_enable(struct platform_device *pdev, int en)
423 421
424static int s3c_rtc_remove(struct platform_device *dev) 422static int s3c_rtc_remove(struct platform_device *dev)
425{ 423{
426 struct rtc_device *rtc = platform_get_drvdata(dev);
427
428 platform_set_drvdata(dev, NULL); 424 platform_set_drvdata(dev, NULL);
429 rtc_device_unregister(rtc);
430 425
431 s3c_rtc_setaie(&dev->dev, 0); 426 s3c_rtc_setaie(&dev->dev, 0);
432 427
428 clk_unprepare(rtc_clk);
433 rtc_clk = NULL; 429 rtc_clk = NULL;
434 430
435 return 0; 431 return 0;
@@ -498,7 +494,7 @@ static int s3c_rtc_probe(struct platform_device *pdev)
498 return ret; 494 return ret;
499 } 495 }
500 496
501 clk_enable(rtc_clk); 497 clk_prepare_enable(rtc_clk);
502 498
503 /* check to see if everything is setup correctly */ 499 /* check to see if everything is setup correctly */
504 500
@@ -511,7 +507,7 @@ static int s3c_rtc_probe(struct platform_device *pdev)
511 507
512 /* register RTC and exit */ 508 /* register RTC and exit */
513 509
514 rtc = rtc_device_register("s3c", &pdev->dev, &s3c_rtcops, 510 rtc = devm_rtc_device_register(&pdev->dev, "s3c", &s3c_rtcops,
515 THIS_MODULE); 511 THIS_MODULE);
516 512
517 if (IS_ERR(rtc)) { 513 if (IS_ERR(rtc)) {
@@ -574,23 +570,24 @@ static int s3c_rtc_probe(struct platform_device *pdev)
574 570
575 err_alarm_irq: 571 err_alarm_irq:
576 platform_set_drvdata(pdev, NULL); 572 platform_set_drvdata(pdev, NULL);
577 rtc_device_unregister(rtc);
578 573
579 err_nortc: 574 err_nortc:
580 s3c_rtc_enable(pdev, 0); 575 s3c_rtc_enable(pdev, 0);
581 clk_disable(rtc_clk); 576 clk_disable_unprepare(rtc_clk);
582 577
583 return ret; 578 return ret;
584} 579}
585 580
586#ifdef CONFIG_PM 581#ifdef CONFIG_PM_SLEEP
587
588/* RTC Power management control */ 582/* RTC Power management control */
589 583
590static int ticnt_save, ticnt_en_save; 584static int ticnt_save, ticnt_en_save;
585static bool wake_en;
591 586
592static int s3c_rtc_suspend(struct platform_device *pdev, pm_message_t state) 587static int s3c_rtc_suspend(struct device *dev)
593{ 588{
589 struct platform_device *pdev = to_platform_device(dev);
590
594 clk_enable(rtc_clk); 591 clk_enable(rtc_clk);
595 /* save TICNT for anyone using periodic interrupts */ 592 /* save TICNT for anyone using periodic interrupts */
596 ticnt_save = readb(s3c_rtc_base + S3C2410_TICNT); 593 ticnt_save = readb(s3c_rtc_base + S3C2410_TICNT);
@@ -600,19 +597,20 @@ static int s3c_rtc_suspend(struct platform_device *pdev, pm_message_t state)
600 } 597 }
601 s3c_rtc_enable(pdev, 0); 598 s3c_rtc_enable(pdev, 0);
602 599
603 if (device_may_wakeup(&pdev->dev) && !wake_en) { 600 if (device_may_wakeup(dev) && !wake_en) {
604 if (enable_irq_wake(s3c_rtc_alarmno) == 0) 601 if (enable_irq_wake(s3c_rtc_alarmno) == 0)
605 wake_en = true; 602 wake_en = true;
606 else 603 else
607 dev_err(&pdev->dev, "enable_irq_wake failed\n"); 604 dev_err(dev, "enable_irq_wake failed\n");
608 } 605 }
609 clk_disable(rtc_clk); 606 clk_disable(rtc_clk);
610 607
611 return 0; 608 return 0;
612} 609}
613 610
614static int s3c_rtc_resume(struct platform_device *pdev) 611static int s3c_rtc_resume(struct device *dev)
615{ 612{
613 struct platform_device *pdev = to_platform_device(dev);
616 unsigned int tmp; 614 unsigned int tmp;
617 615
618 clk_enable(rtc_clk); 616 clk_enable(rtc_clk);
@@ -623,7 +621,7 @@ static int s3c_rtc_resume(struct platform_device *pdev)
623 writew(tmp | ticnt_en_save, s3c_rtc_base + S3C2410_RTCCON); 621 writew(tmp | ticnt_en_save, s3c_rtc_base + S3C2410_RTCCON);
624 } 622 }
625 623
626 if (device_may_wakeup(&pdev->dev) && wake_en) { 624 if (device_may_wakeup(dev) && wake_en) {
627 disable_irq_wake(s3c_rtc_alarmno); 625 disable_irq_wake(s3c_rtc_alarmno);
628 wake_en = false; 626 wake_en = false;
629 } 627 }
@@ -631,11 +629,10 @@ static int s3c_rtc_resume(struct platform_device *pdev)
631 629
632 return 0; 630 return 0;
633} 631}
634#else
635#define s3c_rtc_suspend NULL
636#define s3c_rtc_resume NULL
637#endif 632#endif
638 633
634static SIMPLE_DEV_PM_OPS(s3c_rtc_pm_ops, s3c_rtc_suspend, s3c_rtc_resume);
635
639#ifdef CONFIG_OF 636#ifdef CONFIG_OF
640static struct s3c_rtc_drv_data s3c_rtc_drv_data_array[] = { 637static struct s3c_rtc_drv_data s3c_rtc_drv_data_array[] = {
641 [TYPE_S3C2410] = { TYPE_S3C2410 }, 638 [TYPE_S3C2410] = { TYPE_S3C2410 },
@@ -685,12 +682,11 @@ MODULE_DEVICE_TABLE(platform, s3c_rtc_driver_ids);
685static struct platform_driver s3c_rtc_driver = { 682static struct platform_driver s3c_rtc_driver = {
686 .probe = s3c_rtc_probe, 683 .probe = s3c_rtc_probe,
687 .remove = s3c_rtc_remove, 684 .remove = s3c_rtc_remove,
688 .suspend = s3c_rtc_suspend,
689 .resume = s3c_rtc_resume,
690 .id_table = s3c_rtc_driver_ids, 685 .id_table = s3c_rtc_driver_ids,
691 .driver = { 686 .driver = {
692 .name = "s3c-rtc", 687 .name = "s3c-rtc",
693 .owner = THIS_MODULE, 688 .owner = THIS_MODULE,
689 .pm = &s3c_rtc_pm_ops,
694 .of_match_table = of_match_ptr(s3c_rtc_dt_match), 690 .of_match_table = of_match_ptr(s3c_rtc_dt_match),
695 }, 691 },
696}; 692};
diff --git a/drivers/rtc/rtc-s3c.h b/drivers/rtc/rtc-s3c.h
new file mode 100644
index 000000000000..004b61a8343f
--- /dev/null
+++ b/drivers/rtc/rtc-s3c.h
@@ -0,0 +1,70 @@
1/*
2 * Copyright (c) 2003 Simtec Electronics <linux@simtec.co.uk>
3 * http://www.simtec.co.uk/products/SWLINUX/
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 * S3C2410 Internal RTC register definition
10*/
11
12#ifndef __ASM_ARCH_REGS_RTC_H
13#define __ASM_ARCH_REGS_RTC_H __FILE__
14
15#define S3C2410_RTCREG(x) (x)
16#define S3C2410_INTP S3C2410_RTCREG(0x30)
17#define S3C2410_INTP_ALM (1 << 1)
18#define S3C2410_INTP_TIC (1 << 0)
19
20#define S3C2410_RTCCON S3C2410_RTCREG(0x40)
21#define S3C2410_RTCCON_RTCEN (1 << 0)
22#define S3C2410_RTCCON_CNTSEL (1 << 2)
23#define S3C2410_RTCCON_CLKRST (1 << 3)
24#define S3C2443_RTCCON_TICSEL (1 << 4)
25#define S3C64XX_RTCCON_TICEN (1 << 8)
26
27#define S3C2410_TICNT S3C2410_RTCREG(0x44)
28#define S3C2410_TICNT_ENABLE (1 << 7)
29
30/* S3C2443: tick count is 15 bit wide
31 * TICNT[6:0] contains upper 7 bits
32 * TICNT1[7:0] contains lower 8 bits
33 */
34#define S3C2443_TICNT_PART(x) ((x & 0x7f00) >> 8)
35#define S3C2443_TICNT1 S3C2410_RTCREG(0x4C)
36#define S3C2443_TICNT1_PART(x) (x & 0xff)
37
38/* S3C2416: tick count is 32 bit wide
39 * TICNT[6:0] contains bits [14:8]
40 * TICNT1[7:0] contains lower 8 bits
41 * TICNT2[16:0] contains upper 17 bits
42 */
43#define S3C2416_TICNT2 S3C2410_RTCREG(0x48)
44#define S3C2416_TICNT2_PART(x) ((x & 0xffff8000) >> 15)
45
46#define S3C2410_RTCALM S3C2410_RTCREG(0x50)
47#define S3C2410_RTCALM_ALMEN (1 << 6)
48#define S3C2410_RTCALM_YEAREN (1 << 5)
49#define S3C2410_RTCALM_MONEN (1 << 4)
50#define S3C2410_RTCALM_DAYEN (1 << 3)
51#define S3C2410_RTCALM_HOUREN (1 << 2)
52#define S3C2410_RTCALM_MINEN (1 << 1)
53#define S3C2410_RTCALM_SECEN (1 << 0)
54
55#define S3C2410_ALMSEC S3C2410_RTCREG(0x54)
56#define S3C2410_ALMMIN S3C2410_RTCREG(0x58)
57#define S3C2410_ALMHOUR S3C2410_RTCREG(0x5c)
58
59#define S3C2410_ALMDATE S3C2410_RTCREG(0x60)
60#define S3C2410_ALMMON S3C2410_RTCREG(0x64)
61#define S3C2410_ALMYEAR S3C2410_RTCREG(0x68)
62
63#define S3C2410_RTCSEC S3C2410_RTCREG(0x70)
64#define S3C2410_RTCMIN S3C2410_RTCREG(0x74)
65#define S3C2410_RTCHOUR S3C2410_RTCREG(0x78)
66#define S3C2410_RTCDATE S3C2410_RTCREG(0x7c)
67#define S3C2410_RTCMON S3C2410_RTCREG(0x84)
68#define S3C2410_RTCYEAR S3C2410_RTCREG(0x88)
69
70#endif /* __ASM_ARCH_REGS_RTC_H */
diff --git a/drivers/rtc/rtc-sa1100.c b/drivers/rtc/rtc-sa1100.c
index 5ec5036df0bc..00605601dbf7 100644
--- a/drivers/rtc/rtc-sa1100.c
+++ b/drivers/rtc/rtc-sa1100.c
@@ -234,14 +234,13 @@ static int sa1100_rtc_probe(struct platform_device *pdev)
234 if (irq_1hz < 0 || irq_alarm < 0) 234 if (irq_1hz < 0 || irq_alarm < 0)
235 return -ENODEV; 235 return -ENODEV;
236 236
237 info = kzalloc(sizeof(struct sa1100_rtc), GFP_KERNEL); 237 info = devm_kzalloc(&pdev->dev, sizeof(struct sa1100_rtc), GFP_KERNEL);
238 if (!info) 238 if (!info)
239 return -ENOMEM; 239 return -ENOMEM;
240 info->clk = clk_get(&pdev->dev, NULL); 240 info->clk = devm_clk_get(&pdev->dev, NULL);
241 if (IS_ERR(info->clk)) { 241 if (IS_ERR(info->clk)) {
242 dev_err(&pdev->dev, "failed to find rtc clock source\n"); 242 dev_err(&pdev->dev, "failed to find rtc clock source\n");
243 ret = PTR_ERR(info->clk); 243 return PTR_ERR(info->clk);
244 goto err_clk;
245 } 244 }
246 info->irq_1hz = irq_1hz; 245 info->irq_1hz = irq_1hz;
247 info->irq_alarm = irq_alarm; 246 info->irq_alarm = irq_alarm;
@@ -268,8 +267,8 @@ static int sa1100_rtc_probe(struct platform_device *pdev)
268 267
269 device_init_wakeup(&pdev->dev, 1); 268 device_init_wakeup(&pdev->dev, 1);
270 269
271 rtc = rtc_device_register(pdev->name, &pdev->dev, &sa1100_rtc_ops, 270 rtc = devm_rtc_device_register(&pdev->dev, pdev->name, &sa1100_rtc_ops,
272 THIS_MODULE); 271 THIS_MODULE);
273 272
274 if (IS_ERR(rtc)) { 273 if (IS_ERR(rtc)) {
275 ret = PTR_ERR(rtc); 274 ret = PTR_ERR(rtc);
@@ -306,9 +305,6 @@ err_dev:
306 clk_disable_unprepare(info->clk); 305 clk_disable_unprepare(info->clk);
307err_enable_clk: 306err_enable_clk:
308 platform_set_drvdata(pdev, NULL); 307 platform_set_drvdata(pdev, NULL);
309 clk_put(info->clk);
310err_clk:
311 kfree(info);
312 return ret; 308 return ret;
313} 309}
314 310
@@ -317,17 +313,14 @@ static int sa1100_rtc_remove(struct platform_device *pdev)
317 struct sa1100_rtc *info = platform_get_drvdata(pdev); 313 struct sa1100_rtc *info = platform_get_drvdata(pdev);
318 314
319 if (info) { 315 if (info) {
320 rtc_device_unregister(info->rtc);
321 clk_disable_unprepare(info->clk); 316 clk_disable_unprepare(info->clk);
322 clk_put(info->clk);
323 platform_set_drvdata(pdev, NULL); 317 platform_set_drvdata(pdev, NULL);
324 kfree(info);
325 } 318 }
326 319
327 return 0; 320 return 0;
328} 321}
329 322
330#ifdef CONFIG_PM 323#ifdef CONFIG_PM_SLEEP
331static int sa1100_rtc_suspend(struct device *dev) 324static int sa1100_rtc_suspend(struct device *dev)
332{ 325{
333 struct sa1100_rtc *info = dev_get_drvdata(dev); 326 struct sa1100_rtc *info = dev_get_drvdata(dev);
@@ -343,13 +336,11 @@ static int sa1100_rtc_resume(struct device *dev)
343 disable_irq_wake(info->irq_alarm); 336 disable_irq_wake(info->irq_alarm);
344 return 0; 337 return 0;
345} 338}
346
347static const struct dev_pm_ops sa1100_rtc_pm_ops = {
348 .suspend = sa1100_rtc_suspend,
349 .resume = sa1100_rtc_resume,
350};
351#endif 339#endif
352 340
341static SIMPLE_DEV_PM_OPS(sa1100_rtc_pm_ops, sa1100_rtc_suspend,
342 sa1100_rtc_resume);
343
353#ifdef CONFIG_OF 344#ifdef CONFIG_OF
354static struct of_device_id sa1100_rtc_dt_ids[] = { 345static struct of_device_id sa1100_rtc_dt_ids[] = {
355 { .compatible = "mrvl,sa1100-rtc", }, 346 { .compatible = "mrvl,sa1100-rtc", },
@@ -364,9 +355,7 @@ static struct platform_driver sa1100_rtc_driver = {
364 .remove = sa1100_rtc_remove, 355 .remove = sa1100_rtc_remove,
365 .driver = { 356 .driver = {
366 .name = "sa1100-rtc", 357 .name = "sa1100-rtc",
367#ifdef CONFIG_PM
368 .pm = &sa1100_rtc_pm_ops, 358 .pm = &sa1100_rtc_pm_ops,
369#endif
370 .of_match_table = of_match_ptr(sa1100_rtc_dt_ids), 359 .of_match_table = of_match_ptr(sa1100_rtc_dt_ids),
371 }, 360 },
372}; 361};
diff --git a/drivers/rtc/rtc-sh.c b/drivers/rtc/rtc-sh.c
index e55a7635ae5f..8d5bd2e36776 100644
--- a/drivers/rtc/rtc-sh.c
+++ b/drivers/rtc/rtc-sh.c
@@ -790,6 +790,7 @@ static void sh_rtc_set_irq_wake(struct device *dev, int enabled)
790 } 790 }
791} 791}
792 792
793#ifdef CONFIG_PM_SLEEP
793static int sh_rtc_suspend(struct device *dev) 794static int sh_rtc_suspend(struct device *dev)
794{ 795{
795 if (device_may_wakeup(dev)) 796 if (device_may_wakeup(dev))
@@ -805,33 +806,20 @@ static int sh_rtc_resume(struct device *dev)
805 806
806 return 0; 807 return 0;
807} 808}
809#endif
808 810
809static const struct dev_pm_ops sh_rtc_dev_pm_ops = { 811static SIMPLE_DEV_PM_OPS(sh_rtc_pm_ops, sh_rtc_suspend, sh_rtc_resume);
810 .suspend = sh_rtc_suspend,
811 .resume = sh_rtc_resume,
812};
813 812
814static struct platform_driver sh_rtc_platform_driver = { 813static struct platform_driver sh_rtc_platform_driver = {
815 .driver = { 814 .driver = {
816 .name = DRV_NAME, 815 .name = DRV_NAME,
817 .owner = THIS_MODULE, 816 .owner = THIS_MODULE,
818 .pm = &sh_rtc_dev_pm_ops, 817 .pm = &sh_rtc_pm_ops,
819 }, 818 },
820 .remove = __exit_p(sh_rtc_remove), 819 .remove = __exit_p(sh_rtc_remove),
821}; 820};
822 821
823static int __init sh_rtc_init(void) 822module_platform_driver_probe(sh_rtc_platform_driver, sh_rtc_probe);
824{
825 return platform_driver_probe(&sh_rtc_platform_driver, sh_rtc_probe);
826}
827
828static void __exit sh_rtc_exit(void)
829{
830 platform_driver_unregister(&sh_rtc_platform_driver);
831}
832
833module_init(sh_rtc_init);
834module_exit(sh_rtc_exit);
835 823
836MODULE_DESCRIPTION("SuperH on-chip RTC driver"); 824MODULE_DESCRIPTION("SuperH on-chip RTC driver");
837MODULE_VERSION(DRV_VERSION); 825MODULE_VERSION(DRV_VERSION);
diff --git a/drivers/rtc/rtc-snvs.c b/drivers/rtc/rtc-snvs.c
index f7d90703db5e..b04f09a1df2a 100644
--- a/drivers/rtc/rtc-snvs.c
+++ b/drivers/rtc/rtc-snvs.c
@@ -283,7 +283,7 @@ static int snvs_rtc_probe(struct platform_device *pdev)
283 return ret; 283 return ret;
284 } 284 }
285 285
286 data->rtc = rtc_device_register(pdev->name, &pdev->dev, 286 data->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
287 &snvs_rtc_ops, THIS_MODULE); 287 &snvs_rtc_ops, THIS_MODULE);
288 if (IS_ERR(data->rtc)) { 288 if (IS_ERR(data->rtc)) {
289 ret = PTR_ERR(data->rtc); 289 ret = PTR_ERR(data->rtc);
@@ -296,10 +296,6 @@ static int snvs_rtc_probe(struct platform_device *pdev)
296 296
297static int snvs_rtc_remove(struct platform_device *pdev) 297static int snvs_rtc_remove(struct platform_device *pdev)
298{ 298{
299 struct snvs_rtc_data *data = platform_get_drvdata(pdev);
300
301 rtc_device_unregister(data->rtc);
302
303 return 0; 299 return 0;
304} 300}
305 301
diff --git a/drivers/rtc/rtc-spear.c b/drivers/rtc/rtc-spear.c
index a18c3192ed40..574359c48f65 100644
--- a/drivers/rtc/rtc-spear.c
+++ b/drivers/rtc/rtc-spear.c
@@ -400,8 +400,8 @@ static int spear_rtc_probe(struct platform_device *pdev)
400 spin_lock_init(&config->lock); 400 spin_lock_init(&config->lock);
401 platform_set_drvdata(pdev, config); 401 platform_set_drvdata(pdev, config);
402 402
403 config->rtc = rtc_device_register(pdev->name, &pdev->dev, 403 config->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
404 &spear_rtc_ops, THIS_MODULE); 404 &spear_rtc_ops, THIS_MODULE);
405 if (IS_ERR(config->rtc)) { 405 if (IS_ERR(config->rtc)) {
406 dev_err(&pdev->dev, "can't register RTC device, err %ld\n", 406 dev_err(&pdev->dev, "can't register RTC device, err %ld\n",
407 PTR_ERR(config->rtc)); 407 PTR_ERR(config->rtc));
@@ -427,7 +427,6 @@ static int spear_rtc_remove(struct platform_device *pdev)
427{ 427{
428 struct spear_rtc_config *config = platform_get_drvdata(pdev); 428 struct spear_rtc_config *config = platform_get_drvdata(pdev);
429 429
430 rtc_device_unregister(config->rtc);
431 spear_rtc_disable_interrupt(config); 430 spear_rtc_disable_interrupt(config);
432 clk_disable_unprepare(config->clk); 431 clk_disable_unprepare(config->clk);
433 device_init_wakeup(&pdev->dev, 0); 432 device_init_wakeup(&pdev->dev, 0);
@@ -435,10 +434,10 @@ static int spear_rtc_remove(struct platform_device *pdev)
435 return 0; 434 return 0;
436} 435}
437 436
438#ifdef CONFIG_PM 437#ifdef CONFIG_PM_SLEEP
439 438static int spear_rtc_suspend(struct device *dev)
440static int spear_rtc_suspend(struct platform_device *pdev, pm_message_t state)
441{ 439{
440 struct platform_device *pdev = to_platform_device(dev);
442 struct spear_rtc_config *config = platform_get_drvdata(pdev); 441 struct spear_rtc_config *config = platform_get_drvdata(pdev);
443 int irq; 442 int irq;
444 443
@@ -454,8 +453,9 @@ static int spear_rtc_suspend(struct platform_device *pdev, pm_message_t state)
454 return 0; 453 return 0;
455} 454}
456 455
457static int spear_rtc_resume(struct platform_device *pdev) 456static int spear_rtc_resume(struct device *dev)
458{ 457{
458 struct platform_device *pdev = to_platform_device(dev);
459 struct spear_rtc_config *config = platform_get_drvdata(pdev); 459 struct spear_rtc_config *config = platform_get_drvdata(pdev);
460 int irq; 460 int irq;
461 461
@@ -473,12 +473,10 @@ static int spear_rtc_resume(struct platform_device *pdev)
473 473
474 return 0; 474 return 0;
475} 475}
476
477#else
478#define spear_rtc_suspend NULL
479#define spear_rtc_resume NULL
480#endif 476#endif
481 477
478static SIMPLE_DEV_PM_OPS(spear_rtc_pm_ops, spear_rtc_suspend, spear_rtc_resume);
479
482static void spear_rtc_shutdown(struct platform_device *pdev) 480static void spear_rtc_shutdown(struct platform_device *pdev)
483{ 481{
484 struct spear_rtc_config *config = platform_get_drvdata(pdev); 482 struct spear_rtc_config *config = platform_get_drvdata(pdev);
@@ -498,11 +496,10 @@ MODULE_DEVICE_TABLE(of, spear_rtc_id_table);
498static struct platform_driver spear_rtc_driver = { 496static struct platform_driver spear_rtc_driver = {
499 .probe = spear_rtc_probe, 497 .probe = spear_rtc_probe,
500 .remove = spear_rtc_remove, 498 .remove = spear_rtc_remove,
501 .suspend = spear_rtc_suspend,
502 .resume = spear_rtc_resume,
503 .shutdown = spear_rtc_shutdown, 499 .shutdown = spear_rtc_shutdown,
504 .driver = { 500 .driver = {
505 .name = "rtc-spear", 501 .name = "rtc-spear",
502 .pm = &spear_rtc_pm_ops,
506 .of_match_table = of_match_ptr(spear_rtc_id_table), 503 .of_match_table = of_match_ptr(spear_rtc_id_table),
507 }, 504 },
508}; 505};
diff --git a/drivers/rtc/rtc-starfire.c b/drivers/rtc/rtc-starfire.c
index 5be98bfd7ed3..987b5ec0ae56 100644
--- a/drivers/rtc/rtc-starfire.c
+++ b/drivers/rtc/rtc-starfire.c
@@ -39,8 +39,10 @@ static const struct rtc_class_ops starfire_rtc_ops = {
39 39
40static int __init starfire_rtc_probe(struct platform_device *pdev) 40static int __init starfire_rtc_probe(struct platform_device *pdev)
41{ 41{
42 struct rtc_device *rtc = rtc_device_register("starfire", &pdev->dev, 42 struct rtc_device *rtc;
43 &starfire_rtc_ops, THIS_MODULE); 43
44 rtc = devm_rtc_device_register(&pdev->dev, "starfire",
45 &starfire_rtc_ops, THIS_MODULE);
44 if (IS_ERR(rtc)) 46 if (IS_ERR(rtc))
45 return PTR_ERR(rtc); 47 return PTR_ERR(rtc);
46 48
@@ -51,10 +53,6 @@ static int __init starfire_rtc_probe(struct platform_device *pdev)
51 53
52static int __exit starfire_rtc_remove(struct platform_device *pdev) 54static int __exit starfire_rtc_remove(struct platform_device *pdev)
53{ 55{
54 struct rtc_device *rtc = platform_get_drvdata(pdev);
55
56 rtc_device_unregister(rtc);
57
58 return 0; 56 return 0;
59} 57}
60 58
@@ -66,15 +64,4 @@ static struct platform_driver starfire_rtc_driver = {
66 .remove = __exit_p(starfire_rtc_remove), 64 .remove = __exit_p(starfire_rtc_remove),
67}; 65};
68 66
69static int __init starfire_rtc_init(void) 67module_platform_driver_probe(starfire_rtc_driver, starfire_rtc_probe);
70{
71 return platform_driver_probe(&starfire_rtc_driver, starfire_rtc_probe);
72}
73
74static void __exit starfire_rtc_exit(void)
75{
76 platform_driver_unregister(&starfire_rtc_driver);
77}
78
79module_init(starfire_rtc_init);
80module_exit(starfire_rtc_exit);
diff --git a/drivers/rtc/rtc-stk17ta8.c b/drivers/rtc/rtc-stk17ta8.c
index 7e4a6f65cb91..af5e97e3f272 100644
--- a/drivers/rtc/rtc-stk17ta8.c
+++ b/drivers/rtc/rtc-stk17ta8.c
@@ -336,14 +336,13 @@ static int stk17ta8_rtc_probe(struct platform_device *pdev)
336 } 336 }
337 } 337 }
338 338
339 pdata->rtc = rtc_device_register(pdev->name, &pdev->dev, 339 pdata->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
340 &stk17ta8_rtc_ops, THIS_MODULE); 340 &stk17ta8_rtc_ops, THIS_MODULE);
341 if (IS_ERR(pdata->rtc)) 341 if (IS_ERR(pdata->rtc))
342 return PTR_ERR(pdata->rtc); 342 return PTR_ERR(pdata->rtc);
343 343
344 ret = sysfs_create_bin_file(&pdev->dev.kobj, &stk17ta8_nvram_attr); 344 ret = sysfs_create_bin_file(&pdev->dev.kobj, &stk17ta8_nvram_attr);
345 if (ret) 345
346 rtc_device_unregister(pdata->rtc);
347 return ret; 346 return ret;
348} 347}
349 348
@@ -352,7 +351,6 @@ static int stk17ta8_rtc_remove(struct platform_device *pdev)
352 struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 351 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
353 352
354 sysfs_remove_bin_file(&pdev->dev.kobj, &stk17ta8_nvram_attr); 353 sysfs_remove_bin_file(&pdev->dev.kobj, &stk17ta8_nvram_attr);
355 rtc_device_unregister(pdata->rtc);
356 if (pdata->irq > 0) 354 if (pdata->irq > 0)
357 writeb(0, pdata->ioaddr + RTC_INTERRUPTS); 355 writeb(0, pdata->ioaddr + RTC_INTERRUPTS);
358 return 0; 356 return 0;
diff --git a/drivers/rtc/rtc-stmp3xxx.c b/drivers/rtc/rtc-stmp3xxx.c
index 98f0d3c30738..483ce086990b 100644
--- a/drivers/rtc/rtc-stmp3xxx.c
+++ b/drivers/rtc/rtc-stmp3xxx.c
@@ -30,8 +30,6 @@
30#include <linux/stmp_device.h> 30#include <linux/stmp_device.h>
31#include <linux/stmp3xxx_rtc_wdt.h> 31#include <linux/stmp3xxx_rtc_wdt.h>
32 32
33#include <mach/common.h>
34
35#define STMP3XXX_RTC_CTRL 0x0 33#define STMP3XXX_RTC_CTRL 0x0
36#define STMP3XXX_RTC_CTRL_SET 0x4 34#define STMP3XXX_RTC_CTRL_SET 0x4
37#define STMP3XXX_RTC_CTRL_CLR 0x8 35#define STMP3XXX_RTC_CTRL_CLR 0x8
@@ -227,11 +225,7 @@ static int stmp3xxx_rtc_remove(struct platform_device *pdev)
227 225
228 writel(STMP3XXX_RTC_CTRL_ALARM_IRQ_EN, 226 writel(STMP3XXX_RTC_CTRL_ALARM_IRQ_EN,
229 rtc_data->io + STMP3XXX_RTC_CTRL_CLR); 227 rtc_data->io + STMP3XXX_RTC_CTRL_CLR);
230 free_irq(rtc_data->irq_alarm, &pdev->dev);
231 rtc_device_unregister(rtc_data->rtc);
232 platform_set_drvdata(pdev, NULL); 228 platform_set_drvdata(pdev, NULL);
233 iounmap(rtc_data->io);
234 kfree(rtc_data);
235 229
236 return 0; 230 return 0;
237} 231}
@@ -242,22 +236,20 @@ static int stmp3xxx_rtc_probe(struct platform_device *pdev)
242 struct resource *r; 236 struct resource *r;
243 int err; 237 int err;
244 238
245 rtc_data = kzalloc(sizeof *rtc_data, GFP_KERNEL); 239 rtc_data = devm_kzalloc(&pdev->dev, sizeof(*rtc_data), GFP_KERNEL);
246 if (!rtc_data) 240 if (!rtc_data)
247 return -ENOMEM; 241 return -ENOMEM;
248 242
249 r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 243 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
250 if (!r) { 244 if (!r) {
251 dev_err(&pdev->dev, "failed to get resource\n"); 245 dev_err(&pdev->dev, "failed to get resource\n");
252 err = -ENXIO; 246 return -ENXIO;
253 goto out_free;
254 } 247 }
255 248
256 rtc_data->io = ioremap(r->start, resource_size(r)); 249 rtc_data->io = devm_ioremap(&pdev->dev, r->start, resource_size(r));
257 if (!rtc_data->io) { 250 if (!rtc_data->io) {
258 dev_err(&pdev->dev, "ioremap failed\n"); 251 dev_err(&pdev->dev, "ioremap failed\n");
259 err = -EIO; 252 return -EIO;
260 goto out_free;
261 } 253 }
262 254
263 rtc_data->irq_alarm = platform_get_irq(pdev, 0); 255 rtc_data->irq_alarm = platform_get_irq(pdev, 0);
@@ -265,13 +257,12 @@ static int stmp3xxx_rtc_probe(struct platform_device *pdev)
265 if (!(readl(STMP3XXX_RTC_STAT + rtc_data->io) & 257 if (!(readl(STMP3XXX_RTC_STAT + rtc_data->io) &
266 STMP3XXX_RTC_STAT_RTC_PRESENT)) { 258 STMP3XXX_RTC_STAT_RTC_PRESENT)) {
267 dev_err(&pdev->dev, "no device onboard\n"); 259 dev_err(&pdev->dev, "no device onboard\n");
268 err = -ENODEV; 260 return -ENODEV;
269 goto out_remap;
270 } 261 }
271 262
272 platform_set_drvdata(pdev, rtc_data); 263 platform_set_drvdata(pdev, rtc_data);
273 264
274 mxs_reset_block(rtc_data->io); 265 stmp_reset_block(rtc_data->io);
275 writel(STMP3XXX_RTC_PERSISTENT0_ALARM_EN | 266 writel(STMP3XXX_RTC_PERSISTENT0_ALARM_EN |
276 STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE_EN | 267 STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE_EN |
277 STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE, 268 STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE,
@@ -281,56 +272,51 @@ static int stmp3xxx_rtc_probe(struct platform_device *pdev)
281 STMP3XXX_RTC_CTRL_ALARM_IRQ_EN, 272 STMP3XXX_RTC_CTRL_ALARM_IRQ_EN,
282 rtc_data->io + STMP3XXX_RTC_CTRL_CLR); 273 rtc_data->io + STMP3XXX_RTC_CTRL_CLR);
283 274
284 rtc_data->rtc = rtc_device_register(pdev->name, &pdev->dev, 275 rtc_data->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
285 &stmp3xxx_rtc_ops, THIS_MODULE); 276 &stmp3xxx_rtc_ops, THIS_MODULE);
286 if (IS_ERR(rtc_data->rtc)) { 277 if (IS_ERR(rtc_data->rtc)) {
287 err = PTR_ERR(rtc_data->rtc); 278 err = PTR_ERR(rtc_data->rtc);
288 goto out_remap; 279 goto out;
289 } 280 }
290 281
291 err = request_irq(rtc_data->irq_alarm, stmp3xxx_rtc_interrupt, 0, 282 err = devm_request_irq(&pdev->dev, rtc_data->irq_alarm,
292 "RTC alarm", &pdev->dev); 283 stmp3xxx_rtc_interrupt, 0, "RTC alarm", &pdev->dev);
293 if (err) { 284 if (err) {
294 dev_err(&pdev->dev, "Cannot claim IRQ%d\n", 285 dev_err(&pdev->dev, "Cannot claim IRQ%d\n",
295 rtc_data->irq_alarm); 286 rtc_data->irq_alarm);
296 goto out_irq_alarm; 287 goto out;
297 } 288 }
298 289
299 stmp3xxx_wdt_register(pdev); 290 stmp3xxx_wdt_register(pdev);
300 return 0; 291 return 0;
301 292
302out_irq_alarm: 293out:
303 rtc_device_unregister(rtc_data->rtc);
304out_remap:
305 platform_set_drvdata(pdev, NULL); 294 platform_set_drvdata(pdev, NULL);
306 iounmap(rtc_data->io);
307out_free:
308 kfree(rtc_data);
309 return err; 295 return err;
310} 296}
311 297
312#ifdef CONFIG_PM 298#ifdef CONFIG_PM_SLEEP
313static int stmp3xxx_rtc_suspend(struct platform_device *dev, pm_message_t state) 299static int stmp3xxx_rtc_suspend(struct device *dev)
314{ 300{
315 return 0; 301 return 0;
316} 302}
317 303
318static int stmp3xxx_rtc_resume(struct platform_device *dev) 304static int stmp3xxx_rtc_resume(struct device *dev)
319{ 305{
320 struct stmp3xxx_rtc_data *rtc_data = platform_get_drvdata(dev); 306 struct stmp3xxx_rtc_data *rtc_data = dev_get_drvdata(dev);
321 307
322 mxs_reset_block(rtc_data->io); 308 stmp_reset_block(rtc_data->io);
323 writel(STMP3XXX_RTC_PERSISTENT0_ALARM_EN | 309 writel(STMP3XXX_RTC_PERSISTENT0_ALARM_EN |
324 STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE_EN | 310 STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE_EN |
325 STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE, 311 STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE,
326 rtc_data->io + STMP3XXX_RTC_PERSISTENT0_CLR); 312 rtc_data->io + STMP3XXX_RTC_PERSISTENT0_CLR);
327 return 0; 313 return 0;
328} 314}
329#else
330#define stmp3xxx_rtc_suspend NULL
331#define stmp3xxx_rtc_resume NULL
332#endif 315#endif
333 316
317static SIMPLE_DEV_PM_OPS(stmp3xxx_rtc_pm_ops, stmp3xxx_rtc_suspend,
318 stmp3xxx_rtc_resume);
319
334static const struct of_device_id rtc_dt_ids[] = { 320static const struct of_device_id rtc_dt_ids[] = {
335 { .compatible = "fsl,stmp3xxx-rtc", }, 321 { .compatible = "fsl,stmp3xxx-rtc", },
336 { /* sentinel */ } 322 { /* sentinel */ }
@@ -340,11 +326,10 @@ MODULE_DEVICE_TABLE(of, rtc_dt_ids);
340static struct platform_driver stmp3xxx_rtcdrv = { 326static struct platform_driver stmp3xxx_rtcdrv = {
341 .probe = stmp3xxx_rtc_probe, 327 .probe = stmp3xxx_rtc_probe,
342 .remove = stmp3xxx_rtc_remove, 328 .remove = stmp3xxx_rtc_remove,
343 .suspend = stmp3xxx_rtc_suspend,
344 .resume = stmp3xxx_rtc_resume,
345 .driver = { 329 .driver = {
346 .name = "stmp3xxx-rtc", 330 .name = "stmp3xxx-rtc",
347 .owner = THIS_MODULE, 331 .owner = THIS_MODULE,
332 .pm = &stmp3xxx_rtc_pm_ops,
348 .of_match_table = of_match_ptr(rtc_dt_ids), 333 .of_match_table = of_match_ptr(rtc_dt_ids),
349 }, 334 },
350}; 335};
diff --git a/drivers/rtc/rtc-sun4v.c b/drivers/rtc/rtc-sun4v.c
index 59b5c2dcb58c..ce42e5fa9e09 100644
--- a/drivers/rtc/rtc-sun4v.c
+++ b/drivers/rtc/rtc-sun4v.c
@@ -81,8 +81,10 @@ static const struct rtc_class_ops sun4v_rtc_ops = {
81 81
82static int __init sun4v_rtc_probe(struct platform_device *pdev) 82static int __init sun4v_rtc_probe(struct platform_device *pdev)
83{ 83{
84 struct rtc_device *rtc = rtc_device_register("sun4v", &pdev->dev, 84 struct rtc_device *rtc;
85 &sun4v_rtc_ops, THIS_MODULE); 85
86 rtc = devm_rtc_device_register(&pdev->dev, "sun4v",
87 &sun4v_rtc_ops, THIS_MODULE);
86 if (IS_ERR(rtc)) 88 if (IS_ERR(rtc))
87 return PTR_ERR(rtc); 89 return PTR_ERR(rtc);
88 90
@@ -92,9 +94,6 @@ static int __init sun4v_rtc_probe(struct platform_device *pdev)
92 94
93static int __exit sun4v_rtc_remove(struct platform_device *pdev) 95static int __exit sun4v_rtc_remove(struct platform_device *pdev)
94{ 96{
95 struct rtc_device *rtc = platform_get_drvdata(pdev);
96
97 rtc_device_unregister(rtc);
98 return 0; 97 return 0;
99} 98}
100 99
@@ -106,18 +105,7 @@ static struct platform_driver sun4v_rtc_driver = {
106 .remove = __exit_p(sun4v_rtc_remove), 105 .remove = __exit_p(sun4v_rtc_remove),
107}; 106};
108 107
109static int __init sun4v_rtc_init(void) 108module_platform_driver_probe(sun4v_rtc_driver, sun4v_rtc_probe);
110{
111 return platform_driver_probe(&sun4v_rtc_driver, sun4v_rtc_probe);
112}
113
114static void __exit sun4v_rtc_exit(void)
115{
116 platform_driver_unregister(&sun4v_rtc_driver);
117}
118
119module_init(sun4v_rtc_init);
120module_exit(sun4v_rtc_exit);
121 109
122MODULE_AUTHOR("David S. Miller <davem@davemloft.net>"); 110MODULE_AUTHOR("David S. Miller <davem@davemloft.net>");
123MODULE_DESCRIPTION("SUN4V RTC driver"); 111MODULE_DESCRIPTION("SUN4V RTC driver");
diff --git a/drivers/rtc/rtc-tegra.c b/drivers/rtc/rtc-tegra.c
index 7c033756d6b5..a34315d25478 100644
--- a/drivers/rtc/rtc-tegra.c
+++ b/drivers/rtc/rtc-tegra.c
@@ -26,6 +26,7 @@
26#include <linux/delay.h> 26#include <linux/delay.h>
27#include <linux/rtc.h> 27#include <linux/rtc.h>
28#include <linux/platform_device.h> 28#include <linux/platform_device.h>
29#include <linux/pm.h>
29 30
30/* set to 1 = busy every eight 32kHz clocks during copy of sec+msec to AHB */ 31/* set to 1 = busy every eight 32kHz clocks during copy of sec+msec to AHB */
31#define TEGRA_RTC_REG_BUSY 0x004 32#define TEGRA_RTC_REG_BUSY 0x004
@@ -309,7 +310,7 @@ static const struct of_device_id tegra_rtc_dt_match[] = {
309}; 310};
310MODULE_DEVICE_TABLE(of, tegra_rtc_dt_match); 311MODULE_DEVICE_TABLE(of, tegra_rtc_dt_match);
311 312
312static int tegra_rtc_probe(struct platform_device *pdev) 313static int __init tegra_rtc_probe(struct platform_device *pdev)
313{ 314{
314 struct tegra_rtc_info *info; 315 struct tegra_rtc_info *info;
315 struct resource *res; 316 struct resource *res;
@@ -348,53 +349,35 @@ static int tegra_rtc_probe(struct platform_device *pdev)
348 349
349 device_init_wakeup(&pdev->dev, 1); 350 device_init_wakeup(&pdev->dev, 1);
350 351
351 info->rtc_dev = rtc_device_register( 352 info->rtc_dev = devm_rtc_device_register(&pdev->dev,
352 pdev->name, &pdev->dev, &tegra_rtc_ops, THIS_MODULE); 353 dev_name(&pdev->dev), &tegra_rtc_ops,
354 THIS_MODULE);
353 if (IS_ERR(info->rtc_dev)) { 355 if (IS_ERR(info->rtc_dev)) {
354 ret = PTR_ERR(info->rtc_dev); 356 ret = PTR_ERR(info->rtc_dev);
355 info->rtc_dev = NULL; 357 dev_err(&pdev->dev, "Unable to register device (err=%d).\n",
356 dev_err(&pdev->dev,
357 "Unable to register device (err=%d).\n",
358 ret); 358 ret);
359 return ret; 359 return ret;
360 } 360 }
361 361
362 ret = devm_request_irq(&pdev->dev, info->tegra_rtc_irq, 362 ret = devm_request_irq(&pdev->dev, info->tegra_rtc_irq,
363 tegra_rtc_irq_handler, IRQF_TRIGGER_HIGH, 363 tegra_rtc_irq_handler, IRQF_TRIGGER_HIGH,
364 "rtc alarm", &pdev->dev); 364 dev_name(&pdev->dev), &pdev->dev);
365 if (ret) { 365 if (ret) {
366 dev_err(&pdev->dev, 366 dev_err(&pdev->dev,
367 "Unable to request interrupt for device (err=%d).\n", 367 "Unable to request interrupt for device (err=%d).\n",
368 ret); 368 ret);
369 goto err_dev_unreg; 369 return ret;
370 } 370 }
371 371
372 dev_notice(&pdev->dev, "Tegra internal Real Time Clock\n"); 372 dev_notice(&pdev->dev, "Tegra internal Real Time Clock\n");
373 373
374 return 0; 374 return 0;
375
376err_dev_unreg:
377 rtc_device_unregister(info->rtc_dev);
378
379 return ret;
380} 375}
381 376
382static int tegra_rtc_remove(struct platform_device *pdev) 377#ifdef CONFIG_PM_SLEEP
378static int tegra_rtc_suspend(struct device *dev)
383{ 379{
384 struct tegra_rtc_info *info = platform_get_drvdata(pdev); 380 struct tegra_rtc_info *info = dev_get_drvdata(dev);
385
386 rtc_device_unregister(info->rtc_dev);
387
388 platform_set_drvdata(pdev, NULL);
389
390 return 0;
391}
392
393#ifdef CONFIG_PM
394static int tegra_rtc_suspend(struct platform_device *pdev, pm_message_t state)
395{
396 struct device *dev = &pdev->dev;
397 struct tegra_rtc_info *info = platform_get_drvdata(pdev);
398 381
399 tegra_rtc_wait_while_busy(dev); 382 tegra_rtc_wait_while_busy(dev);
400 383
@@ -416,10 +399,9 @@ static int tegra_rtc_suspend(struct platform_device *pdev, pm_message_t state)
416 return 0; 399 return 0;
417} 400}
418 401
419static int tegra_rtc_resume(struct platform_device *pdev) 402static int tegra_rtc_resume(struct device *dev)
420{ 403{
421 struct device *dev = &pdev->dev; 404 struct tegra_rtc_info *info = dev_get_drvdata(dev);
422 struct tegra_rtc_info *info = platform_get_drvdata(pdev);
423 405
424 dev_vdbg(dev, "Resume (device_may_wakeup=%d)\n", 406 dev_vdbg(dev, "Resume (device_may_wakeup=%d)\n",
425 device_may_wakeup(dev)); 407 device_may_wakeup(dev));
@@ -431,6 +413,8 @@ static int tegra_rtc_resume(struct platform_device *pdev)
431} 413}
432#endif 414#endif
433 415
416static SIMPLE_DEV_PM_OPS(tegra_rtc_pm_ops, tegra_rtc_suspend, tegra_rtc_resume);
417
434static void tegra_rtc_shutdown(struct platform_device *pdev) 418static void tegra_rtc_shutdown(struct platform_device *pdev)
435{ 419{
436 dev_vdbg(&pdev->dev, "disabling interrupts.\n"); 420 dev_vdbg(&pdev->dev, "disabling interrupts.\n");
@@ -439,30 +423,16 @@ static void tegra_rtc_shutdown(struct platform_device *pdev)
439 423
440MODULE_ALIAS("platform:tegra_rtc"); 424MODULE_ALIAS("platform:tegra_rtc");
441static struct platform_driver tegra_rtc_driver = { 425static struct platform_driver tegra_rtc_driver = {
442 .remove = tegra_rtc_remove,
443 .shutdown = tegra_rtc_shutdown, 426 .shutdown = tegra_rtc_shutdown,
444 .driver = { 427 .driver = {
445 .name = "tegra_rtc", 428 .name = "tegra_rtc",
446 .owner = THIS_MODULE, 429 .owner = THIS_MODULE,
447 .of_match_table = tegra_rtc_dt_match, 430 .of_match_table = tegra_rtc_dt_match,
431 .pm = &tegra_rtc_pm_ops,
448 }, 432 },
449#ifdef CONFIG_PM
450 .suspend = tegra_rtc_suspend,
451 .resume = tegra_rtc_resume,
452#endif
453}; 433};
454 434
455static int __init tegra_rtc_init(void) 435module_platform_driver_probe(tegra_rtc_driver, tegra_rtc_probe);
456{
457 return platform_driver_probe(&tegra_rtc_driver, tegra_rtc_probe);
458}
459module_init(tegra_rtc_init);
460
461static void __exit tegra_rtc_exit(void)
462{
463 platform_driver_unregister(&tegra_rtc_driver);
464}
465module_exit(tegra_rtc_exit);
466 436
467MODULE_AUTHOR("Jon Mayo <jmayo@nvidia.com>"); 437MODULE_AUTHOR("Jon Mayo <jmayo@nvidia.com>");
468MODULE_DESCRIPTION("driver for Tegra internal RTC"); 438MODULE_DESCRIPTION("driver for Tegra internal RTC");
diff --git a/drivers/rtc/rtc-test.c b/drivers/rtc/rtc-test.c
index b92e0f6383e6..7746e65b93f2 100644
--- a/drivers/rtc/rtc-test.c
+++ b/drivers/rtc/rtc-test.c
@@ -99,8 +99,10 @@ static DEVICE_ATTR(irq, S_IRUGO | S_IWUSR, test_irq_show, test_irq_store);
99static int test_probe(struct platform_device *plat_dev) 99static int test_probe(struct platform_device *plat_dev)
100{ 100{
101 int err; 101 int err;
102 struct rtc_device *rtc = rtc_device_register("test", &plat_dev->dev, 102 struct rtc_device *rtc;
103 &test_rtc_ops, THIS_MODULE); 103
104 rtc = devm_rtc_device_register(&plat_dev->dev, "test",
105 &test_rtc_ops, THIS_MODULE);
104 if (IS_ERR(rtc)) { 106 if (IS_ERR(rtc)) {
105 err = PTR_ERR(rtc); 107 err = PTR_ERR(rtc);
106 return err; 108 return err;
@@ -115,15 +117,11 @@ static int test_probe(struct platform_device *plat_dev)
115 return 0; 117 return 0;
116 118
117err: 119err:
118 rtc_device_unregister(rtc);
119 return err; 120 return err;
120} 121}
121 122
122static int test_remove(struct platform_device *plat_dev) 123static int test_remove(struct platform_device *plat_dev)
123{ 124{
124 struct rtc_device *rtc = platform_get_drvdata(plat_dev);
125
126 rtc_device_unregister(rtc);
127 device_remove_file(&plat_dev->dev, &dev_attr_irq); 125 device_remove_file(&plat_dev->dev, &dev_attr_irq);
128 126
129 return 0; 127 return 0;
diff --git a/drivers/rtc/rtc-tile.c b/drivers/rtc/rtc-tile.c
index 62db4841078b..249b6531f119 100644
--- a/drivers/rtc/rtc-tile.c
+++ b/drivers/rtc/rtc-tile.c
@@ -80,8 +80,8 @@ static int tile_rtc_probe(struct platform_device *dev)
80{ 80{
81 struct rtc_device *rtc; 81 struct rtc_device *rtc;
82 82
83 rtc = rtc_device_register("tile", 83 rtc = devm_rtc_device_register(&dev->dev, "tile",
84 &dev->dev, &tile_rtc_ops, THIS_MODULE); 84 &tile_rtc_ops, THIS_MODULE);
85 85
86 if (IS_ERR(rtc)) 86 if (IS_ERR(rtc))
87 return PTR_ERR(rtc); 87 return PTR_ERR(rtc);
@@ -96,11 +96,6 @@ static int tile_rtc_probe(struct platform_device *dev)
96 */ 96 */
97static int tile_rtc_remove(struct platform_device *dev) 97static int tile_rtc_remove(struct platform_device *dev)
98{ 98{
99 struct rtc_device *rtc = platform_get_drvdata(dev);
100
101 if (rtc)
102 rtc_device_unregister(rtc);
103
104 platform_set_drvdata(dev, NULL); 99 platform_set_drvdata(dev, NULL);
105 100
106 return 0; 101 return 0;
diff --git a/drivers/rtc/rtc-tps6586x.c b/drivers/rtc/rtc-tps6586x.c
index aab4e8c93622..459c2ffc95a6 100644
--- a/drivers/rtc/rtc-tps6586x.c
+++ b/drivers/rtc/rtc-tps6586x.c
@@ -274,7 +274,7 @@ static int tps6586x_rtc_probe(struct platform_device *pdev)
274 } 274 }
275 275
276 platform_set_drvdata(pdev, rtc); 276 platform_set_drvdata(pdev, rtc);
277 rtc->rtc = rtc_device_register(dev_name(&pdev->dev), &pdev->dev, 277 rtc->rtc = devm_rtc_device_register(&pdev->dev, dev_name(&pdev->dev),
278 &tps6586x_rtc_ops, THIS_MODULE); 278 &tps6586x_rtc_ops, THIS_MODULE);
279 if (IS_ERR(rtc->rtc)) { 279 if (IS_ERR(rtc->rtc)) {
280 ret = PTR_ERR(rtc->rtc); 280 ret = PTR_ERR(rtc->rtc);
@@ -289,15 +289,12 @@ static int tps6586x_rtc_probe(struct platform_device *pdev)
289 if (ret < 0) { 289 if (ret < 0) {
290 dev_err(&pdev->dev, "request IRQ(%d) failed with ret %d\n", 290 dev_err(&pdev->dev, "request IRQ(%d) failed with ret %d\n",
291 rtc->irq, ret); 291 rtc->irq, ret);
292 goto fail_req_irq; 292 goto fail_rtc_register;
293 } 293 }
294 disable_irq(rtc->irq); 294 disable_irq(rtc->irq);
295 device_set_wakeup_capable(&pdev->dev, 1); 295 device_set_wakeup_capable(&pdev->dev, 1);
296 return 0; 296 return 0;
297 297
298fail_req_irq:
299 rtc_device_unregister(rtc->rtc);
300
301fail_rtc_register: 298fail_rtc_register:
302 tps6586x_update(tps_dev, RTC_CTRL, 0, 299 tps6586x_update(tps_dev, RTC_CTRL, 0,
303 RTC_ENABLE | OSC_SRC_SEL | PRE_BYPASS | CL_SEL_MASK); 300 RTC_ENABLE | OSC_SRC_SEL | PRE_BYPASS | CL_SEL_MASK);
@@ -306,12 +303,10 @@ fail_rtc_register:
306 303
307static int tps6586x_rtc_remove(struct platform_device *pdev) 304static int tps6586x_rtc_remove(struct platform_device *pdev)
308{ 305{
309 struct tps6586x_rtc *rtc = platform_get_drvdata(pdev);
310 struct device *tps_dev = to_tps6586x_dev(&pdev->dev); 306 struct device *tps_dev = to_tps6586x_dev(&pdev->dev);
311 307
312 tps6586x_update(tps_dev, RTC_CTRL, 0, 308 tps6586x_update(tps_dev, RTC_CTRL, 0,
313 RTC_ENABLE | OSC_SRC_SEL | PRE_BYPASS | CL_SEL_MASK); 309 RTC_ENABLE | OSC_SRC_SEL | PRE_BYPASS | CL_SEL_MASK);
314 rtc_device_unregister(rtc->rtc);
315 return 0; 310 return 0;
316} 311}
317 312
@@ -335,9 +330,8 @@ static int tps6586x_rtc_resume(struct device *dev)
335} 330}
336#endif 331#endif
337 332
338static const struct dev_pm_ops tps6586x_pm_ops = { 333static SIMPLE_DEV_PM_OPS(tps6586x_pm_ops, tps6586x_rtc_suspend,
339 SET_SYSTEM_SLEEP_PM_OPS(tps6586x_rtc_suspend, tps6586x_rtc_resume) 334 tps6586x_rtc_resume);
340};
341 335
342static struct platform_driver tps6586x_rtc_driver = { 336static struct platform_driver tps6586x_rtc_driver = {
343 .driver = { 337 .driver = {
diff --git a/drivers/rtc/rtc-tps65910.c b/drivers/rtc/rtc-tps65910.c
index 8bd8115329b5..a9caf043b0ce 100644
--- a/drivers/rtc/rtc-tps65910.c
+++ b/drivers/rtc/rtc-tps65910.c
@@ -263,7 +263,7 @@ static int tps65910_rtc_probe(struct platform_device *pdev)
263 if (irq <= 0) { 263 if (irq <= 0) {
264 dev_warn(&pdev->dev, "Wake up is not possible as irq = %d\n", 264 dev_warn(&pdev->dev, "Wake up is not possible as irq = %d\n",
265 irq); 265 irq);
266 return ret; 266 return -ENXIO;
267 } 267 }
268 268
269 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, 269 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
@@ -276,7 +276,7 @@ static int tps65910_rtc_probe(struct platform_device *pdev)
276 tps_rtc->irq = irq; 276 tps_rtc->irq = irq;
277 device_set_wakeup_capable(&pdev->dev, 1); 277 device_set_wakeup_capable(&pdev->dev, 1);
278 278
279 tps_rtc->rtc = rtc_device_register(pdev->name, &pdev->dev, 279 tps_rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
280 &tps65910_rtc_ops, THIS_MODULE); 280 &tps65910_rtc_ops, THIS_MODULE);
281 if (IS_ERR(tps_rtc->rtc)) { 281 if (IS_ERR(tps_rtc->rtc)) {
282 ret = PTR_ERR(tps_rtc->rtc); 282 ret = PTR_ERR(tps_rtc->rtc);
@@ -295,12 +295,8 @@ static int tps65910_rtc_probe(struct platform_device *pdev)
295 */ 295 */
296static int tps65910_rtc_remove(struct platform_device *pdev) 296static int tps65910_rtc_remove(struct platform_device *pdev)
297{ 297{
298 /* leave rtc running, but disable irqs */
299 struct tps65910_rtc *tps_rtc = platform_get_drvdata(pdev);
300
301 tps65910_rtc_alarm_irq_enable(&pdev->dev, 0); 298 tps65910_rtc_alarm_irq_enable(&pdev->dev, 0);
302 299
303 rtc_device_unregister(tps_rtc->rtc);
304 return 0; 300 return 0;
305} 301}
306 302
@@ -324,9 +320,8 @@ static int tps65910_rtc_resume(struct device *dev)
324} 320}
325#endif 321#endif
326 322
327static const struct dev_pm_ops tps65910_rtc_pm_ops = { 323static SIMPLE_DEV_PM_OPS(tps65910_rtc_pm_ops, tps65910_rtc_suspend,
328 SET_SYSTEM_SLEEP_PM_OPS(tps65910_rtc_suspend, tps65910_rtc_resume) 324 tps65910_rtc_resume);
329};
330 325
331static struct platform_driver tps65910_rtc_driver = { 326static struct platform_driver tps65910_rtc_driver = {
332 .probe = tps65910_rtc_probe, 327 .probe = tps65910_rtc_probe,
diff --git a/drivers/rtc/rtc-tps80031.c b/drivers/rtc/rtc-tps80031.c
index 9aaf8aaebae9..72662eafb938 100644
--- a/drivers/rtc/rtc-tps80031.c
+++ b/drivers/rtc/rtc-tps80031.c
@@ -277,7 +277,7 @@ static int tps80031_rtc_probe(struct platform_device *pdev)
277 return ret; 277 return ret;
278 } 278 }
279 279
280 rtc->rtc = rtc_device_register(pdev->name, &pdev->dev, 280 rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
281 &tps80031_rtc_ops, THIS_MODULE); 281 &tps80031_rtc_ops, THIS_MODULE);
282 if (IS_ERR(rtc->rtc)) { 282 if (IS_ERR(rtc->rtc)) {
283 ret = PTR_ERR(rtc->rtc); 283 ret = PTR_ERR(rtc->rtc);
@@ -292,7 +292,6 @@ static int tps80031_rtc_probe(struct platform_device *pdev)
292 if (ret < 0) { 292 if (ret < 0) {
293 dev_err(&pdev->dev, "request IRQ:%d failed, err = %d\n", 293 dev_err(&pdev->dev, "request IRQ:%d failed, err = %d\n",
294 rtc->irq, ret); 294 rtc->irq, ret);
295 rtc_device_unregister(rtc->rtc);
296 return ret; 295 return ret;
297 } 296 }
298 device_set_wakeup_capable(&pdev->dev, 1); 297 device_set_wakeup_capable(&pdev->dev, 1);
@@ -301,9 +300,6 @@ static int tps80031_rtc_probe(struct platform_device *pdev)
301 300
302static int tps80031_rtc_remove(struct platform_device *pdev) 301static int tps80031_rtc_remove(struct platform_device *pdev)
303{ 302{
304 struct tps80031_rtc *rtc = platform_get_drvdata(pdev);
305
306 rtc_device_unregister(rtc->rtc);
307 return 0; 303 return 0;
308} 304}
309 305
@@ -327,9 +323,8 @@ static int tps80031_rtc_resume(struct device *dev)
327}; 323};
328#endif 324#endif
329 325
330static const struct dev_pm_ops tps80031_pm_ops = { 326static SIMPLE_DEV_PM_OPS(tps80031_pm_ops, tps80031_rtc_suspend,
331 SET_SYSTEM_SLEEP_PM_OPS(tps80031_rtc_suspend, tps80031_rtc_resume) 327 tps80031_rtc_resume);
332};
333 328
334static struct platform_driver tps80031_rtc_driver = { 329static struct platform_driver tps80031_rtc_driver = {
335 .driver = { 330 .driver = {
diff --git a/drivers/rtc/rtc-twl.c b/drivers/rtc/rtc-twl.c
index 8bc6c80b184c..8751a5240c99 100644
--- a/drivers/rtc/rtc-twl.c
+++ b/drivers/rtc/rtc-twl.c
@@ -566,11 +566,10 @@ static void twl_rtc_shutdown(struct platform_device *pdev)
566 mask_rtc_irq_bit(BIT_RTC_INTERRUPTS_REG_IT_TIMER_M); 566 mask_rtc_irq_bit(BIT_RTC_INTERRUPTS_REG_IT_TIMER_M);
567} 567}
568 568
569#ifdef CONFIG_PM 569#ifdef CONFIG_PM_SLEEP
570
571static unsigned char irqstat; 570static unsigned char irqstat;
572 571
573static int twl_rtc_suspend(struct platform_device *pdev, pm_message_t state) 572static int twl_rtc_suspend(struct device *dev)
574{ 573{
575 irqstat = rtc_irq_bits; 574 irqstat = rtc_irq_bits;
576 575
@@ -578,17 +577,15 @@ static int twl_rtc_suspend(struct platform_device *pdev, pm_message_t state)
578 return 0; 577 return 0;
579} 578}
580 579
581static int twl_rtc_resume(struct platform_device *pdev) 580static int twl_rtc_resume(struct device *dev)
582{ 581{
583 set_rtc_irq_bit(irqstat); 582 set_rtc_irq_bit(irqstat);
584 return 0; 583 return 0;
585} 584}
586
587#else
588#define twl_rtc_suspend NULL
589#define twl_rtc_resume NULL
590#endif 585#endif
591 586
587static SIMPLE_DEV_PM_OPS(twl_rtc_pm_ops, twl_rtc_suspend, twl_rtc_resume);
588
592#ifdef CONFIG_OF 589#ifdef CONFIG_OF
593static const struct of_device_id twl_rtc_of_match[] = { 590static const struct of_device_id twl_rtc_of_match[] = {
594 {.compatible = "ti,twl4030-rtc", }, 591 {.compatible = "ti,twl4030-rtc", },
@@ -603,11 +600,10 @@ static struct platform_driver twl4030rtc_driver = {
603 .probe = twl_rtc_probe, 600 .probe = twl_rtc_probe,
604 .remove = twl_rtc_remove, 601 .remove = twl_rtc_remove,
605 .shutdown = twl_rtc_shutdown, 602 .shutdown = twl_rtc_shutdown,
606 .suspend = twl_rtc_suspend,
607 .resume = twl_rtc_resume,
608 .driver = { 603 .driver = {
609 .owner = THIS_MODULE, 604 .owner = THIS_MODULE,
610 .name = "twl_rtc", 605 .name = "twl_rtc",
606 .pm = &twl_rtc_pm_ops,
611 .of_match_table = of_match_ptr(twl_rtc_of_match), 607 .of_match_table = of_match_ptr(twl_rtc_of_match),
612 }, 608 },
613}; 609};
diff --git a/drivers/rtc/rtc-tx4939.c b/drivers/rtc/rtc-tx4939.c
index a12bfac49d36..f9a0677e4e3b 100644
--- a/drivers/rtc/rtc-tx4939.c
+++ b/drivers/rtc/rtc-tx4939.c
@@ -268,14 +268,13 @@ static int __init tx4939_rtc_probe(struct platform_device *pdev)
268 if (devm_request_irq(&pdev->dev, irq, tx4939_rtc_interrupt, 268 if (devm_request_irq(&pdev->dev, irq, tx4939_rtc_interrupt,
269 0, pdev->name, &pdev->dev) < 0) 269 0, pdev->name, &pdev->dev) < 0)
270 return -EBUSY; 270 return -EBUSY;
271 rtc = rtc_device_register(pdev->name, &pdev->dev, 271 rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
272 &tx4939_rtc_ops, THIS_MODULE); 272 &tx4939_rtc_ops, THIS_MODULE);
273 if (IS_ERR(rtc)) 273 if (IS_ERR(rtc))
274 return PTR_ERR(rtc); 274 return PTR_ERR(rtc);
275 pdata->rtc = rtc; 275 pdata->rtc = rtc;
276 ret = sysfs_create_bin_file(&pdev->dev.kobj, &tx4939_rtc_nvram_attr); 276 ret = sysfs_create_bin_file(&pdev->dev.kobj, &tx4939_rtc_nvram_attr);
277 if (ret) 277
278 rtc_device_unregister(rtc);
279 return ret; 278 return ret;
280} 279}
281 280
@@ -284,7 +283,6 @@ static int __exit tx4939_rtc_remove(struct platform_device *pdev)
284 struct tx4939rtc_plat_data *pdata = platform_get_drvdata(pdev); 283 struct tx4939rtc_plat_data *pdata = platform_get_drvdata(pdev);
285 284
286 sysfs_remove_bin_file(&pdev->dev.kobj, &tx4939_rtc_nvram_attr); 285 sysfs_remove_bin_file(&pdev->dev.kobj, &tx4939_rtc_nvram_attr);
287 rtc_device_unregister(pdata->rtc);
288 spin_lock_irq(&pdata->lock); 286 spin_lock_irq(&pdata->lock);
289 tx4939_rtc_cmd(pdata->rtcreg, TX4939_RTCCTL_COMMAND_NOP); 287 tx4939_rtc_cmd(pdata->rtcreg, TX4939_RTCCTL_COMMAND_NOP);
290 spin_unlock_irq(&pdata->lock); 288 spin_unlock_irq(&pdata->lock);
@@ -299,18 +297,7 @@ static struct platform_driver tx4939_rtc_driver = {
299 }, 297 },
300}; 298};
301 299
302static int __init tx4939rtc_init(void) 300module_platform_driver_probe(tx4939_rtc_driver, tx4939_rtc_probe);
303{
304 return platform_driver_probe(&tx4939_rtc_driver, tx4939_rtc_probe);
305}
306
307static void __exit tx4939rtc_exit(void)
308{
309 platform_driver_unregister(&tx4939_rtc_driver);
310}
311
312module_init(tx4939rtc_init);
313module_exit(tx4939rtc_exit);
314 301
315MODULE_AUTHOR("Atsushi Nemoto <anemo@mba.ocn.ne.jp>"); 302MODULE_AUTHOR("Atsushi Nemoto <anemo@mba.ocn.ne.jp>");
316MODULE_DESCRIPTION("TX4939 internal RTC driver"); 303MODULE_DESCRIPTION("TX4939 internal RTC driver");
diff --git a/drivers/rtc/rtc-v3020.c b/drivers/rtc/rtc-v3020.c
index bca5d677bc85..6e0cba8f47d5 100644
--- a/drivers/rtc/rtc-v3020.c
+++ b/drivers/rtc/rtc-v3020.c
@@ -309,7 +309,7 @@ static int rtc_probe(struct platform_device *pdev)
309 int i; 309 int i;
310 int temp; 310 int temp;
311 311
312 chip = kzalloc(sizeof *chip, GFP_KERNEL); 312 chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL);
313 if (!chip) 313 if (!chip)
314 return -ENOMEM; 314 return -ENOMEM;
315 315
@@ -353,8 +353,8 @@ static int rtc_probe(struct platform_device *pdev)
353 353
354 platform_set_drvdata(pdev, chip); 354 platform_set_drvdata(pdev, chip);
355 355
356 chip->rtc = rtc_device_register("v3020", 356 chip->rtc = devm_rtc_device_register(&pdev->dev, "v3020",
357 &pdev->dev, &v3020_rtc_ops, THIS_MODULE); 357 &v3020_rtc_ops, THIS_MODULE);
358 if (IS_ERR(chip->rtc)) { 358 if (IS_ERR(chip->rtc)) {
359 retval = PTR_ERR(chip->rtc); 359 retval = PTR_ERR(chip->rtc);
360 goto err_io; 360 goto err_io;
@@ -365,21 +365,14 @@ static int rtc_probe(struct platform_device *pdev)
365err_io: 365err_io:
366 chip->ops->unmap_io(chip); 366 chip->ops->unmap_io(chip);
367err_chip: 367err_chip:
368 kfree(chip);
369
370 return retval; 368 return retval;
371} 369}
372 370
373static int rtc_remove(struct platform_device *dev) 371static int rtc_remove(struct platform_device *dev)
374{ 372{
375 struct v3020 *chip = platform_get_drvdata(dev); 373 struct v3020 *chip = platform_get_drvdata(dev);
376 struct rtc_device *rtc = chip->rtc;
377
378 if (rtc)
379 rtc_device_unregister(rtc);
380 374
381 chip->ops->unmap_io(chip); 375 chip->ops->unmap_io(chip);
382 kfree(chip);
383 376
384 return 0; 377 return 0;
385} 378}
diff --git a/drivers/rtc/rtc-vt8500.c b/drivers/rtc/rtc-vt8500.c
index a000bc0a8bff..d89efee6d29e 100644
--- a/drivers/rtc/rtc-vt8500.c
+++ b/drivers/rtc/rtc-vt8500.c
@@ -252,7 +252,7 @@ static int vt8500_rtc_probe(struct platform_device *pdev)
252 writel(VT8500_RTC_CR_ENABLE, 252 writel(VT8500_RTC_CR_ENABLE,
253 vt8500_rtc->regbase + VT8500_RTC_CR); 253 vt8500_rtc->regbase + VT8500_RTC_CR);
254 254
255 vt8500_rtc->rtc = rtc_device_register("vt8500-rtc", &pdev->dev, 255 vt8500_rtc->rtc = devm_rtc_device_register(&pdev->dev, "vt8500-rtc",
256 &vt8500_rtc_ops, THIS_MODULE); 256 &vt8500_rtc_ops, THIS_MODULE);
257 if (IS_ERR(vt8500_rtc->rtc)) { 257 if (IS_ERR(vt8500_rtc->rtc)) {
258 ret = PTR_ERR(vt8500_rtc->rtc); 258 ret = PTR_ERR(vt8500_rtc->rtc);
@@ -266,13 +266,11 @@ static int vt8500_rtc_probe(struct platform_device *pdev)
266 if (ret < 0) { 266 if (ret < 0) {
267 dev_err(&pdev->dev, "can't get irq %i, err %d\n", 267 dev_err(&pdev->dev, "can't get irq %i, err %d\n",
268 vt8500_rtc->irq_alarm, ret); 268 vt8500_rtc->irq_alarm, ret);
269 goto err_unreg; 269 goto err_return;
270 } 270 }
271 271
272 return 0; 272 return 0;
273 273
274err_unreg:
275 rtc_device_unregister(vt8500_rtc->rtc);
276err_return: 274err_return:
277 return ret; 275 return ret;
278} 276}
@@ -281,8 +279,6 @@ static int vt8500_rtc_remove(struct platform_device *pdev)
281{ 279{
282 struct vt8500_rtc *vt8500_rtc = platform_get_drvdata(pdev); 280 struct vt8500_rtc *vt8500_rtc = platform_get_drvdata(pdev);
283 281
284 rtc_device_unregister(vt8500_rtc->rtc);
285
286 /* Disable alarm matching */ 282 /* Disable alarm matching */
287 writel(0, vt8500_rtc->regbase + VT8500_RTC_IS); 283 writel(0, vt8500_rtc->regbase + VT8500_RTC_IS);
288 284
diff --git a/drivers/rtc/rtc-wm831x.c b/drivers/rtc/rtc-wm831x.c
index 2f0ac7b30a0c..8d65b94e5a7e 100644
--- a/drivers/rtc/rtc-wm831x.c
+++ b/drivers/rtc/rtc-wm831x.c
@@ -436,7 +436,7 @@ static int wm831x_rtc_probe(struct platform_device *pdev)
436 436
437 device_init_wakeup(&pdev->dev, 1); 437 device_init_wakeup(&pdev->dev, 1);
438 438
439 wm831x_rtc->rtc = rtc_device_register("wm831x", &pdev->dev, 439 wm831x_rtc->rtc = devm_rtc_device_register(&pdev->dev, "wm831x",
440 &wm831x_rtc_ops, THIS_MODULE); 440 &wm831x_rtc_ops, THIS_MODULE);
441 if (IS_ERR(wm831x_rtc->rtc)) { 441 if (IS_ERR(wm831x_rtc->rtc)) {
442 ret = PTR_ERR(wm831x_rtc->rtc); 442 ret = PTR_ERR(wm831x_rtc->rtc);
@@ -462,10 +462,6 @@ err:
462 462
463static int wm831x_rtc_remove(struct platform_device *pdev) 463static int wm831x_rtc_remove(struct platform_device *pdev)
464{ 464{
465 struct wm831x_rtc *wm831x_rtc = platform_get_drvdata(pdev);
466
467 rtc_device_unregister(wm831x_rtc->rtc);
468
469 return 0; 465 return 0;
470} 466}
471 467
diff --git a/drivers/rtc/rtc-wm8350.c b/drivers/rtc/rtc-wm8350.c
index 8ad86ae0d30f..fa247deb9cf4 100644
--- a/drivers/rtc/rtc-wm8350.c
+++ b/drivers/rtc/rtc-wm8350.c
@@ -339,7 +339,7 @@ static const struct rtc_class_ops wm8350_rtc_ops = {
339 .alarm_irq_enable = wm8350_rtc_alarm_irq_enable, 339 .alarm_irq_enable = wm8350_rtc_alarm_irq_enable,
340}; 340};
341 341
342#ifdef CONFIG_PM 342#ifdef CONFIG_PM_SLEEP
343static int wm8350_rtc_suspend(struct device *dev) 343static int wm8350_rtc_suspend(struct device *dev)
344{ 344{
345 struct platform_device *pdev = to_platform_device(dev); 345 struct platform_device *pdev = to_platform_device(dev);
@@ -375,10 +375,6 @@ static int wm8350_rtc_resume(struct device *dev)
375 375
376 return 0; 376 return 0;
377} 377}
378
379#else
380#define wm8350_rtc_suspend NULL
381#define wm8350_rtc_resume NULL
382#endif 378#endif
383 379
384static int wm8350_rtc_probe(struct platform_device *pdev) 380static int wm8350_rtc_probe(struct platform_device *pdev)
@@ -439,8 +435,8 @@ static int wm8350_rtc_probe(struct platform_device *pdev)
439 435
440 device_init_wakeup(&pdev->dev, 1); 436 device_init_wakeup(&pdev->dev, 1);
441 437
442 wm_rtc->rtc = rtc_device_register("wm8350", &pdev->dev, 438 wm_rtc->rtc = devm_rtc_device_register(&pdev->dev, "wm8350",
443 &wm8350_rtc_ops, THIS_MODULE); 439 &wm8350_rtc_ops, THIS_MODULE);
444 if (IS_ERR(wm_rtc->rtc)) { 440 if (IS_ERR(wm_rtc->rtc)) {
445 ret = PTR_ERR(wm_rtc->rtc); 441 ret = PTR_ERR(wm_rtc->rtc);
446 dev_err(&pdev->dev, "failed to register RTC: %d\n", ret); 442 dev_err(&pdev->dev, "failed to register RTC: %d\n", ret);
@@ -462,20 +458,15 @@ static int wm8350_rtc_probe(struct platform_device *pdev)
462static int wm8350_rtc_remove(struct platform_device *pdev) 458static int wm8350_rtc_remove(struct platform_device *pdev)
463{ 459{
464 struct wm8350 *wm8350 = platform_get_drvdata(pdev); 460 struct wm8350 *wm8350 = platform_get_drvdata(pdev);
465 struct wm8350_rtc *wm_rtc = &wm8350->rtc;
466 461
467 wm8350_free_irq(wm8350, WM8350_IRQ_RTC_SEC, wm8350); 462 wm8350_free_irq(wm8350, WM8350_IRQ_RTC_SEC, wm8350);
468 wm8350_free_irq(wm8350, WM8350_IRQ_RTC_ALM, wm8350); 463 wm8350_free_irq(wm8350, WM8350_IRQ_RTC_ALM, wm8350);
469 464
470 rtc_device_unregister(wm_rtc->rtc);
471
472 return 0; 465 return 0;
473} 466}
474 467
475static struct dev_pm_ops wm8350_rtc_pm_ops = { 468static SIMPLE_DEV_PM_OPS(wm8350_rtc_pm_ops, wm8350_rtc_suspend,
476 .suspend = wm8350_rtc_suspend, 469 wm8350_rtc_resume);
477 .resume = wm8350_rtc_resume,
478};
479 470
480static struct platform_driver wm8350_rtc_driver = { 471static struct platform_driver wm8350_rtc_driver = {
481 .probe = wm8350_rtc_probe, 472 .probe = wm8350_rtc_probe,
diff --git a/drivers/rtc/rtc-x1205.c b/drivers/rtc/rtc-x1205.c
index f36e59c6bc01..fa9b0679fb60 100644
--- a/drivers/rtc/rtc-x1205.c
+++ b/drivers/rtc/rtc-x1205.c
@@ -630,8 +630,8 @@ static int x1205_probe(struct i2c_client *client,
630 630
631 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n"); 631 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n");
632 632
633 rtc = rtc_device_register(x1205_driver.driver.name, &client->dev, 633 rtc = devm_rtc_device_register(&client->dev, x1205_driver.driver.name,
634 &x1205_rtc_ops, THIS_MODULE); 634 &x1205_rtc_ops, THIS_MODULE);
635 635
636 if (IS_ERR(rtc)) 636 if (IS_ERR(rtc))
637 return PTR_ERR(rtc); 637 return PTR_ERR(rtc);
@@ -653,21 +653,13 @@ static int x1205_probe(struct i2c_client *client,
653 653
654 err = x1205_sysfs_register(&client->dev); 654 err = x1205_sysfs_register(&client->dev);
655 if (err) 655 if (err)
656 goto exit_devreg; 656 return err;
657 657
658 return 0; 658 return 0;
659
660exit_devreg:
661 rtc_device_unregister(rtc);
662
663 return err;
664} 659}
665 660
666static int x1205_remove(struct i2c_client *client) 661static int x1205_remove(struct i2c_client *client)
667{ 662{
668 struct rtc_device *rtc = i2c_get_clientdata(client);
669
670 rtc_device_unregister(rtc);
671 x1205_sysfs_unregister(&client->dev); 663 x1205_sysfs_unregister(&client->dev);
672 return 0; 664 return 0;
673} 665}