aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc
diff options
context:
space:
mode:
authorVenu Byravarasu <vbyravarasu@nvidia.com>2012-10-04 20:13:55 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-10-05 14:05:02 -0400
commit0e783980b84e7253ba98552d092d1f45ed262d66 (patch)
tree7cc402699e588484b76aae12b9758c23125eb4b1 /drivers/rtc
parent477d30d787b969e4c11fc958077cc7954805e236 (diff)
rtc: tps65910: add RTC driver for TPS65910 PMIC RTC
TPS65910 PMIC is a MFD with RTC as one of the device. Adding RTC driver for supporting RTC device present inside TPS65910 PMIC. Only support for RTC alarm is implemented as part of this patch. Signed-off-by: Venu Byravarasu <vbyravarasu@nvidia.com> Cc: Alessandro Zummo <a.zummo@towertech.it> Cc: Mark Brown <broonie@opensource.wolfsonmicro.com> Cc: Samuel Ortiz <sameo@linux.intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/rtc')
-rw-r--r--drivers/rtc/Kconfig10
-rw-r--r--drivers/rtc/Makefile1
-rw-r--r--drivers/rtc/rtc-tps65910.c352
3 files changed, 363 insertions, 0 deletions
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index f87bfea6718c..6309df4e2654 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -335,6 +335,16 @@ config RTC_DRV_TWL4030
335 This driver can also be built as a module. If so, the module 335 This driver can also be built as a module. If so, the module
336 will be called rtc-twl. 336 will be called rtc-twl.
337 337
338config RTC_DRV_TPS65910
339 tristate "TI TPS65910 RTC driver"
340 depends on RTC_CLASS && MFD_TPS65910
341 help
342 If you say yes here you get support for the RTC on the
343 TPS65910 chips.
344
345 This driver can also be built as a module. If so, the module
346 will be called rtc-tps65910.
347
338config RTC_DRV_S35390A 348config RTC_DRV_S35390A
339 tristate "Seiko Instruments S-35390A" 349 tristate "Seiko Instruments S-35390A"
340 select BITREVERSE 350 select BITREVERSE
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 6056f71033db..5c8f106237da 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -107,6 +107,7 @@ obj-$(CONFIG_RTC_DRV_TEGRA) += rtc-tegra.o
107obj-$(CONFIG_RTC_DRV_TEST) += rtc-test.o 107obj-$(CONFIG_RTC_DRV_TEST) += rtc-test.o
108obj-$(CONFIG_RTC_DRV_TILE) += rtc-tile.o 108obj-$(CONFIG_RTC_DRV_TILE) += rtc-tile.o
109obj-$(CONFIG_RTC_DRV_TWL4030) += rtc-twl.o 109obj-$(CONFIG_RTC_DRV_TWL4030) += rtc-twl.o
110obj-$(CONFIG_RTC_DRV_TPS65910) += rtc-tps65910.o
110obj-$(CONFIG_RTC_DRV_TX4939) += rtc-tx4939.o 111obj-$(CONFIG_RTC_DRV_TX4939) += rtc-tx4939.o
111obj-$(CONFIG_RTC_DRV_V3020) += rtc-v3020.o 112obj-$(CONFIG_RTC_DRV_V3020) += rtc-v3020.o
112obj-$(CONFIG_RTC_DRV_VR41XX) += rtc-vr41xx.o 113obj-$(CONFIG_RTC_DRV_VR41XX) += rtc-vr41xx.o
diff --git a/drivers/rtc/rtc-tps65910.c b/drivers/rtc/rtc-tps65910.c
new file mode 100644
index 000000000000..7c4ca8605741
--- /dev/null
+++ b/drivers/rtc/rtc-tps65910.c
@@ -0,0 +1,352 @@
1/*
2 * rtc-tps65910.c -- TPS65910 Real Time Clock interface
3 *
4 * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
5 * Author: Venu Byravarasu <vbyravarasu@nvidia.com>
6 *
7 * Based on original TI driver rtc-twl.c
8 * Copyright (C) 2007 MontaVista Software, Inc
9 * Author: Alexandre Rusev <source@mvista.com>
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version
14 * 2 of the License, or (at your option) any later version.
15 */
16
17#include <linux/kernel.h>
18#include <linux/errno.h>
19#include <linux/init.h>
20#include <linux/module.h>
21#include <linux/types.h>
22#include <linux/rtc.h>
23#include <linux/bcd.h>
24#include <linux/platform_device.h>
25#include <linux/interrupt.h>
26#include <linux/mfd/tps65910.h>
27
28struct tps65910_rtc {
29 struct rtc_device *rtc;
30 /* To store the list of enabled interrupts */
31 u32 irqstat;
32};
33
34/* Total number of RTC registers needed to set time*/
35#define NUM_TIME_REGS (TPS65910_YEARS - TPS65910_SECONDS + 1)
36
37static int tps65910_rtc_alarm_irq_enable(struct device *dev, unsigned enabled)
38{
39 struct tps65910 *tps = dev_get_drvdata(dev->parent);
40 u8 val = 0;
41
42 if (enabled)
43 val = TPS65910_RTC_INTERRUPTS_IT_ALARM;
44
45 return regmap_write(tps->regmap, TPS65910_RTC_INTERRUPTS, val);
46}
47
48/*
49 * Gets current tps65910 RTC time and date parameters.
50 *
51 * The RTC's time/alarm representation is not what gmtime(3) requires
52 * Linux to use:
53 *
54 * - Months are 1..12 vs Linux 0-11
55 * - Years are 0..99 vs Linux 1900..N (we assume 21st century)
56 */
57static int tps65910_rtc_read_time(struct device *dev, struct rtc_time *tm)
58{
59 unsigned char rtc_data[NUM_TIME_REGS];
60 struct tps65910 *tps = dev_get_drvdata(dev->parent);
61 int ret;
62
63 /* Copy RTC counting registers to static registers or latches */
64 ret = regmap_update_bits(tps->regmap, TPS65910_RTC_CTRL,
65 TPS65910_RTC_CTRL_GET_TIME, TPS65910_RTC_CTRL_GET_TIME);
66 if (ret < 0) {
67 dev_err(dev, "RTC CTRL reg update failed with err:%d\n", ret);
68 return ret;
69 }
70
71 ret = regmap_bulk_read(tps->regmap, TPS65910_SECONDS, rtc_data,
72 NUM_TIME_REGS);
73 if (ret < 0) {
74 dev_err(dev, "reading from RTC failed with err:%d\n", ret);
75 return ret;
76 }
77
78 tm->tm_sec = bcd2bin(rtc_data[0]);
79 tm->tm_min = bcd2bin(rtc_data[1]);
80 tm->tm_hour = bcd2bin(rtc_data[2]);
81 tm->tm_mday = bcd2bin(rtc_data[3]);
82 tm->tm_mon = bcd2bin(rtc_data[4]) - 1;
83 tm->tm_year = bcd2bin(rtc_data[5]) + 100;
84
85 return ret;
86}
87
88static int tps65910_rtc_set_time(struct device *dev, struct rtc_time *tm)
89{
90 unsigned char rtc_data[NUM_TIME_REGS];
91 struct tps65910 *tps = dev_get_drvdata(dev->parent);
92 int ret;
93
94 rtc_data[0] = bin2bcd(tm->tm_sec);
95 rtc_data[1] = bin2bcd(tm->tm_min);
96 rtc_data[2] = bin2bcd(tm->tm_hour);
97 rtc_data[3] = bin2bcd(tm->tm_mday);
98 rtc_data[4] = bin2bcd(tm->tm_mon + 1);
99 rtc_data[5] = bin2bcd(tm->tm_year - 100);
100
101 /* Stop RTC while updating the RTC time registers */
102 ret = regmap_update_bits(tps->regmap, TPS65910_RTC_CTRL,
103 TPS65910_RTC_CTRL_STOP_RTC, 0);
104 if (ret < 0) {
105 dev_err(dev, "RTC stop failed with err:%d\n", ret);
106 return ret;
107 }
108
109 /* update all the time registers in one shot */
110 ret = regmap_bulk_write(tps->regmap, TPS65910_SECONDS, rtc_data,
111 NUM_TIME_REGS);
112 if (ret < 0) {
113 dev_err(dev, "rtc_set_time error %d\n", ret);
114 return ret;
115 }
116
117 /* Start back RTC */
118 ret = regmap_update_bits(tps->regmap, TPS65910_RTC_CTRL,
119 TPS65910_RTC_CTRL_STOP_RTC, 1);
120 if (ret < 0)
121 dev_err(dev, "RTC start failed with err:%d\n", ret);
122
123 return ret;
124}
125
126/*
127 * Gets current tps65910 RTC alarm time.
128 */
129static int tps65910_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm)
130{
131 unsigned char alarm_data[NUM_TIME_REGS];
132 u32 int_val;
133 struct tps65910 *tps = dev_get_drvdata(dev->parent);
134 int ret;
135
136 ret = regmap_bulk_read(tps->regmap, TPS65910_SECONDS, alarm_data,
137 NUM_TIME_REGS);
138 if (ret < 0) {
139 dev_err(dev, "rtc_read_alarm error %d\n", ret);
140 return ret;
141 }
142
143 alm->time.tm_sec = bcd2bin(alarm_data[0]);
144 alm->time.tm_min = bcd2bin(alarm_data[1]);
145 alm->time.tm_hour = bcd2bin(alarm_data[2]);
146 alm->time.tm_mday = bcd2bin(alarm_data[3]);
147 alm->time.tm_mon = bcd2bin(alarm_data[4]) - 1;
148 alm->time.tm_year = bcd2bin(alarm_data[5]) + 100;
149
150 ret = regmap_read(tps->regmap, TPS65910_RTC_INTERRUPTS, &int_val);
151 if (ret < 0)
152 return ret;
153
154 if (int_val & TPS65910_RTC_INTERRUPTS_IT_ALARM)
155 alm->enabled = 1;
156
157 return ret;