aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc/rtc-ab8500.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-07-03 20:12:13 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-07-03 20:12:13 -0400
commit7f0ef0267e20d62d45d527911a993b1e998f4968 (patch)
treede51abc7da5903f59d83e23937f22420164c9477 /drivers/rtc/rtc-ab8500.c
parent862f0012549110d6f2586bf54b52ed4540cbff3a (diff)
parent9307c29524502c21f0e8a6d96d850b2f5bc0bd9a (diff)
Merge branch 'akpm' (updates from Andrew Morton)
Merge first patch-bomb from Andrew Morton: - various misc bits - I'm been patchmonkeying ocfs2 for a while, as Joel and Mark have been distracted. There has been quite a bit of activity. - About half the MM queue - Some backlight bits - Various lib/ updates - checkpatch updates - zillions more little rtc patches - ptrace - signals - exec - procfs - rapidio - nbd - aoe - pps - memstick - tools/testing/selftests updates * emailed patches from Andrew Morton <akpm@linux-foundation.org>: (445 commits) tools/testing/selftests: don't assume the x bit is set on scripts selftests: add .gitignore for kcmp selftests: fix clean target in kcmp Makefile selftests: add .gitignore for vm selftests: add hugetlbfstest self-test: fix make clean selftests: exit 1 on failure kernel/resource.c: remove the unneeded assignment in function __find_resource aio: fix wrong comment in aio_complete() drivers/w1/slaves/w1_ds2408.c: add magic sequence to disable P0 test mode drivers/memstick/host/r592.c: convert to module_pci_driver drivers/memstick/host/jmb38x_ms: convert to module_pci_driver pps-gpio: add device-tree binding and support drivers/pps/clients/pps-gpio.c: convert to module_platform_driver drivers/pps/clients/pps-gpio.c: convert to devm_* helpers drivers/parport/share.c: use kzalloc Documentation/accounting/getdelays.c: avoid strncpy in accounting tool aoe: update internal version number to v83 aoe: update copyright date aoe: perform I/O completions in parallel ...
Diffstat (limited to 'drivers/rtc/rtc-ab8500.c')
-rw-r--r--drivers/rtc/rtc-ab8500.c65
1 files changed, 62 insertions, 3 deletions
diff --git a/drivers/rtc/rtc-ab8500.c b/drivers/rtc/rtc-ab8500.c
index 63cfa314a39f..727e2f5d14d9 100644
--- a/drivers/rtc/rtc-ab8500.c
+++ b/drivers/rtc/rtc-ab8500.c
@@ -35,6 +35,10 @@
35#define AB8500_RTC_FORCE_BKUP_REG 0x0D 35#define AB8500_RTC_FORCE_BKUP_REG 0x0D
36#define AB8500_RTC_CALIB_REG 0x0E 36#define AB8500_RTC_CALIB_REG 0x0E
37#define AB8500_RTC_SWITCH_STAT_REG 0x0F 37#define AB8500_RTC_SWITCH_STAT_REG 0x0F
38#define AB8540_RTC_ALRM_SEC 0x22
39#define AB8540_RTC_ALRM_MIN_LOW_REG 0x23
40#define AB8540_RTC_ALRM_MIN_MID_REG 0x24
41#define AB8540_RTC_ALRM_MIN_HI_REG 0x25
38 42
39/* RtcReadRequest bits */ 43/* RtcReadRequest bits */
40#define RTC_READ_REQUEST 0x01 44#define RTC_READ_REQUEST 0x01
@@ -58,6 +62,11 @@ static const u8 ab8500_rtc_alarm_regs[] = {
58 AB8500_RTC_ALRM_MIN_LOW_REG 62 AB8500_RTC_ALRM_MIN_LOW_REG
59}; 63};
60 64
65static const u8 ab8540_rtc_alarm_regs[] = {
66 AB8540_RTC_ALRM_MIN_HI_REG, AB8540_RTC_ALRM_MIN_MID_REG,
67 AB8540_RTC_ALRM_MIN_LOW_REG, AB8540_RTC_ALRM_SEC
68};
69
61/* Calculate the seconds from 1970 to 01-01-2000 00:00:00 */ 70/* Calculate the seconds from 1970 to 01-01-2000 00:00:00 */
62static unsigned long get_elapsed_seconds(int year) 71static unsigned long get_elapsed_seconds(int year)
63{ 72{
@@ -267,6 +276,42 @@ static int ab8500_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
267 return ab8500_rtc_irq_enable(dev, alarm->enabled); 276 return ab8500_rtc_irq_enable(dev, alarm->enabled);
268} 277}
269 278
279static int ab8540_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
280{
281 int retval, i;
282 unsigned char buf[ARRAY_SIZE(ab8540_rtc_alarm_regs)];
283 unsigned long mins, secs = 0;
284
285 if (alarm->time.tm_year < (AB8500_RTC_EPOCH - 1900)) {
286 dev_dbg(dev, "year should be equal to or greater than %d\n",
287 AB8500_RTC_EPOCH);
288 return -EINVAL;
289 }
290
291 /* Get the number of seconds since 1970 */
292 rtc_tm_to_time(&alarm->time, &secs);
293
294 /*
295 * Convert it to the number of seconds since 01-01-2000 00:00:00
296 */
297 secs -= get_elapsed_seconds(AB8500_RTC_EPOCH);
298 mins = secs / 60;
299
300 buf[3] = secs % 60;
301 buf[2] = mins & 0xFF;
302 buf[1] = (mins >> 8) & 0xFF;
303 buf[0] = (mins >> 16) & 0xFF;
304
305 /* Set the alarm time */
306 for (i = 0; i < ARRAY_SIZE(ab8540_rtc_alarm_regs); i++) {
307 retval = abx500_set_register_interruptible(dev, AB8500_RTC,
308 ab8540_rtc_alarm_regs[i], buf[i]);
309 if (retval < 0)
310 return retval;
311 }
312
313 return ab8500_rtc_irq_enable(dev, alarm->enabled);
314}
270 315
271static int ab8500_rtc_set_calibration(struct device *dev, int calibration) 316static int ab8500_rtc_set_calibration(struct device *dev, int calibration)
272{ 317{
@@ -389,8 +434,22 @@ static const struct rtc_class_ops ab8500_rtc_ops = {
389 .alarm_irq_enable = ab8500_rtc_irq_enable, 434 .alarm_irq_enable = ab8500_rtc_irq_enable,
390}; 435};
391 436
437static const struct rtc_class_ops ab8540_rtc_ops = {
438 .read_time = ab8500_rtc_read_time,
439 .set_time = ab8500_rtc_set_time,
440 .read_alarm = ab8500_rtc_read_alarm,
441 .set_alarm = ab8540_rtc_set_alarm,
442 .alarm_irq_enable = ab8500_rtc_irq_enable,
443};
444
445static struct platform_device_id ab85xx_rtc_ids[] = {
446 { "ab8500-rtc", (kernel_ulong_t)&ab8500_rtc_ops, },
447 { "ab8540-rtc", (kernel_ulong_t)&ab8540_rtc_ops, },
448};
449
392static int ab8500_rtc_probe(struct platform_device *pdev) 450static int ab8500_rtc_probe(struct platform_device *pdev)
393{ 451{
452 const struct platform_device_id *platid = platform_get_device_id(pdev);
394 int err; 453 int err;
395 struct rtc_device *rtc; 454 struct rtc_device *rtc;
396 u8 rtc_ctrl; 455 u8 rtc_ctrl;
@@ -423,7 +482,8 @@ static int ab8500_rtc_probe(struct platform_device *pdev)
423 device_init_wakeup(&pdev->dev, true); 482 device_init_wakeup(&pdev->dev, true);
424 483
425 rtc = devm_rtc_device_register(&pdev->dev, "ab8500-rtc", 484 rtc = devm_rtc_device_register(&pdev->dev, "ab8500-rtc",
426 &ab8500_rtc_ops, THIS_MODULE); 485 (struct rtc_class_ops *)platid->driver_data,
486 THIS_MODULE);
427 if (IS_ERR(rtc)) { 487 if (IS_ERR(rtc)) {
428 dev_err(&pdev->dev, "Registration failed\n"); 488 dev_err(&pdev->dev, "Registration failed\n");
429 err = PTR_ERR(rtc); 489 err = PTR_ERR(rtc);
@@ -451,8 +511,6 @@ static int ab8500_rtc_remove(struct platform_device *pdev)
451{ 511{
452 ab8500_sysfs_rtc_unregister(&pdev->dev); 512 ab8500_sysfs_rtc_unregister(&pdev->dev);
453 513
454 platform_set_drvdata(pdev, NULL);
455
456 return 0; 514 return 0;
457} 515}
458 516
@@ -463,6 +521,7 @@ static struct platform_driver ab8500_rtc_driver = {
463 }, 521 },
464 .probe = ab8500_rtc_probe, 522 .probe = ab8500_rtc_probe,
465 .remove = ab8500_rtc_remove, 523 .remove = ab8500_rtc_remove,
524 .id_table = ab85xx_rtc_ids,
466}; 525};
467 526
468module_platform_driver(ab8500_rtc_driver); 527module_platform_driver(ab8500_rtc_driver);