aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc/rtc-mv.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/rtc/rtc-mv.c')
-rw-r--r--drivers/rtc/rtc-mv.c51
1 files changed, 30 insertions, 21 deletions
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");