blob: 0d9089228bb0681e77367f5bfab0f5df5bac0ab8 [file] [log] [blame]
Ben Dooks1add6782006-07-01 04:36:26 -07001/* drivers/rtc/rtc-s3c.c
2 *
Atul Dahiyae48add82010-07-20 12:19:14 +05303 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com/
5 *
Ben Dooks1add6782006-07-01 04:36:26 -07006 * Copyright (c) 2004,2006 Simtec Electronics
7 * Ben Dooks, <ben@simtec.co.uk>
8 * http://armlinux.simtec.co.uk/
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 *
14 * S3C2410/S3C2440/S3C24XX Internal RTC Driver
15*/
16
17#include <linux/module.h>
18#include <linux/fs.h>
19#include <linux/string.h>
20#include <linux/init.h>
21#include <linux/platform_device.h>
22#include <linux/interrupt.h>
23#include <linux/rtc.h>
24#include <linux/bcd.h>
25#include <linux/clk.h>
Robert P. J. Day9974b6e2008-02-06 01:38:42 -080026#include <linux/log2.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090027#include <linux/slab.h>
Thomas Abraham39ce4082011-10-24 14:49:04 +020028#include <linux/of.h>
Sachin Kamatdbd9acb2012-07-30 14:41:48 -070029#include <linux/uaccess.h>
30#include <linux/io.h>
Ben Dooks1add6782006-07-01 04:36:26 -070031
Ben Dooks1add6782006-07-01 04:36:26 -070032#include <asm/irq.h>
Arnd Bergmannb9d7c5d2013-03-05 12:04:37 +010033#include "rtc-s3c.h"
Ben Dooks1add6782006-07-01 04:36:26 -070034
Chanwoo Choi19be09f2014-10-13 15:52:28 -070035struct s3c_rtc {
36 struct device *dev;
37 struct rtc_device *rtc;
Ben Dooks1add6782006-07-01 04:36:26 -070038
Chanwoo Choi19be09f2014-10-13 15:52:28 -070039 void __iomem *base;
40 struct clk *rtc_clk;
41 bool enabled;
Ben Dooks1add6782006-07-01 04:36:26 -070042
Chanwoo Choiae05c952014-10-13 15:52:33 -070043 struct s3c_rtc_data *data;
Ben Dooks1add6782006-07-01 04:36:26 -070044
Chanwoo Choi19be09f2014-10-13 15:52:28 -070045 int irq_alarm;
46 int irq_tick;
47
48 spinlock_t pie_lock;
49 spinlock_t alarm_clk_lock;
50
51 int ticnt_save, ticnt_en_save;
52 bool wake_en;
53};
54
Chanwoo Choiae05c952014-10-13 15:52:33 -070055struct s3c_rtc_data {
56 int max_user_freq;
57
58 void (*irq_handler) (struct s3c_rtc *info, int mask);
59 void (*set_freq) (struct s3c_rtc *info, int freq);
60 void (*enable_tick) (struct s3c_rtc *info, struct seq_file *seq);
61 void (*select_tick_clk) (struct s3c_rtc *info);
62 void (*save_tick_cnt) (struct s3c_rtc *info);
63 void (*restore_tick_cnt) (struct s3c_rtc *info);
64 void (*enable) (struct s3c_rtc *info);
65 void (*disable) (struct s3c_rtc *info);
66};
67
Chanwoo Choi19be09f2014-10-13 15:52:28 -070068static void s3c_rtc_alarm_clk_enable(struct s3c_rtc *info, bool enable)
Donggeun Kim88cee8f2011-09-14 16:22:19 -070069{
Donggeun Kim88cee8f2011-09-14 16:22:19 -070070 unsigned long irq_flags;
71
Chanwoo Choi19be09f2014-10-13 15:52:28 -070072 spin_lock_irqsave(&info->alarm_clk_lock, irq_flags);
Donggeun Kim88cee8f2011-09-14 16:22:19 -070073 if (enable) {
Chanwoo Choi19be09f2014-10-13 15:52:28 -070074 if (!info->enabled) {
75 clk_enable(info->rtc_clk);
76 info->enabled = true;
Donggeun Kim88cee8f2011-09-14 16:22:19 -070077 }
78 } else {
Chanwoo Choi19be09f2014-10-13 15:52:28 -070079 if (info->enabled) {
80 clk_disable(info->rtc_clk);
81 info->enabled = false;
Donggeun Kim88cee8f2011-09-14 16:22:19 -070082 }
83 }
Chanwoo Choi19be09f2014-10-13 15:52:28 -070084 spin_unlock_irqrestore(&info->alarm_clk_lock, irq_flags);
Donggeun Kim88cee8f2011-09-14 16:22:19 -070085}
86
Ben Dooks1add6782006-07-01 04:36:26 -070087/* IRQ Handlers */
David Howells7d12e782006-10-05 14:55:46 +010088static irqreturn_t s3c_rtc_tickirq(int irq, void *id)
Ben Dooks1add6782006-07-01 04:36:26 -070089{
Chanwoo Choi19be09f2014-10-13 15:52:28 -070090 struct s3c_rtc *info = (struct s3c_rtc *)id;
Ben Dooks1add6782006-07-01 04:36:26 -070091
Chanwoo Choiae05c952014-10-13 15:52:33 -070092 if (info->data->irq_handler)
93 info->data->irq_handler(info, S3C2410_INTP_TIC);
Atul Dahiya2f3478f2010-07-20 16:02:51 +053094
Chanwoo Choiae05c952014-10-13 15:52:33 -070095 return IRQ_HANDLED;
96}
Atul Dahiya2f3478f2010-07-20 16:02:51 +053097
Chanwoo Choiae05c952014-10-13 15:52:33 -070098static irqreturn_t s3c_rtc_alarmirq(int irq, void *id)
99{
100 struct s3c_rtc *info = (struct s3c_rtc *)id;
101
102 if (info->data->irq_handler)
103 info->data->irq_handler(info, S3C2410_INTP_ALM);
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700104
Ben Dooks1add6782006-07-01 04:36:26 -0700105 return IRQ_HANDLED;
106}
107
108/* Update control registers */
Axel Lin2ec38a02011-03-04 17:36:19 -0800109static int s3c_rtc_setaie(struct device *dev, unsigned int enabled)
Ben Dooks1add6782006-07-01 04:36:26 -0700110{
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700111 struct s3c_rtc *info = dev_get_drvdata(dev);
Ben Dooks1add6782006-07-01 04:36:26 -0700112 unsigned int tmp;
113
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700114 dev_dbg(info->dev, "%s: aie=%d\n", __func__, enabled);
Ben Dooks1add6782006-07-01 04:36:26 -0700115
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700116 clk_enable(info->rtc_clk);
117 tmp = readb(info->base + S3C2410_RTCALM) & ~S3C2410_RTCALM_ALMEN;
Ben Dooks1add6782006-07-01 04:36:26 -0700118
Axel Lin2ec38a02011-03-04 17:36:19 -0800119 if (enabled)
Ben Dooks1add6782006-07-01 04:36:26 -0700120 tmp |= S3C2410_RTCALM_ALMEN;
121
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700122 writeb(tmp, info->base + S3C2410_RTCALM);
123 clk_disable(info->rtc_clk);
Axel Lin2ec38a02011-03-04 17:36:19 -0800124
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700125 s3c_rtc_alarm_clk_enable(info, enabled);
Donggeun Kim88cee8f2011-09-14 16:22:19 -0700126
Axel Lin2ec38a02011-03-04 17:36:19 -0800127 return 0;
Ben Dooks1add6782006-07-01 04:36:26 -0700128}
129
Chanwoo Choiae05c952014-10-13 15:52:33 -0700130/* Set RTC frequency */
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700131static int s3c_rtc_setfreq(struct s3c_rtc *info, int freq)
Ben Dooks1add6782006-07-01 04:36:26 -0700132{
Jonathan Cameron5d2a5032009-01-06 14:42:12 -0800133 if (!is_power_of_2(freq))
134 return -EINVAL;
135
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700136 clk_enable(info->rtc_clk);
137 spin_lock_irq(&info->pie_lock);
Ben Dooks773be7e2008-07-23 21:30:45 -0700138
Chanwoo Choiae05c952014-10-13 15:52:33 -0700139 if (info->data->set_freq)
140 info->data->set_freq(info, freq);
Maurus Cuelenaere9f4123b2010-05-24 14:33:43 -0700141
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700142 spin_unlock_irq(&info->pie_lock);
143 clk_disable(info->rtc_clk);
Ben Dooks773be7e2008-07-23 21:30:45 -0700144
145 return 0;
Ben Dooks1add6782006-07-01 04:36:26 -0700146}
147
148/* Time read/write */
Ben Dooks1add6782006-07-01 04:36:26 -0700149static int s3c_rtc_gettime(struct device *dev, struct rtc_time *rtc_tm)
150{
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700151 struct s3c_rtc *info = dev_get_drvdata(dev);
Ben Dooks1add6782006-07-01 04:36:26 -0700152 unsigned int have_retried = 0;
153
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700154 clk_enable(info->rtc_clk);
Ben Dooks1add6782006-07-01 04:36:26 -0700155 retry_get_time:
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700156 rtc_tm->tm_min = readb(info->base + S3C2410_RTCMIN);
157 rtc_tm->tm_hour = readb(info->base + S3C2410_RTCHOUR);
158 rtc_tm->tm_mday = readb(info->base + S3C2410_RTCDATE);
159 rtc_tm->tm_mon = readb(info->base + S3C2410_RTCMON);
160 rtc_tm->tm_year = readb(info->base + S3C2410_RTCYEAR);
161 rtc_tm->tm_sec = readb(info->base + S3C2410_RTCSEC);
Ben Dooks1add6782006-07-01 04:36:26 -0700162
Adam Buchbinder48fc7f72012-09-19 21:48:00 -0400163 /* the only way to work out whether the system was mid-update
Ben Dooks1add6782006-07-01 04:36:26 -0700164 * when we read it is to check the second counter, and if it
165 * is zero, then we re-try the entire read
166 */
167
168 if (rtc_tm->tm_sec == 0 && !have_retried) {
169 have_retried = 1;
170 goto retry_get_time;
171 }
172
Adrian Bunkfe20ba72008-10-18 20:28:41 -0700173 rtc_tm->tm_sec = bcd2bin(rtc_tm->tm_sec);
174 rtc_tm->tm_min = bcd2bin(rtc_tm->tm_min);
175 rtc_tm->tm_hour = bcd2bin(rtc_tm->tm_hour);
176 rtc_tm->tm_mday = bcd2bin(rtc_tm->tm_mday);
177 rtc_tm->tm_mon = bcd2bin(rtc_tm->tm_mon);
178 rtc_tm->tm_year = bcd2bin(rtc_tm->tm_year);
Ben Dooks1add6782006-07-01 04:36:26 -0700179
180 rtc_tm->tm_year += 100;
MyungJoo Ham4e8896c2011-08-25 15:59:22 -0700181
Jingoo Hand4a48c22013-02-21 16:45:06 -0800182 dev_dbg(dev, "read time %04d.%02d.%02d %02d:%02d:%02d\n",
MyungJoo Ham4e8896c2011-08-25 15:59:22 -0700183 1900 + rtc_tm->tm_year, rtc_tm->tm_mon, rtc_tm->tm_mday,
184 rtc_tm->tm_hour, rtc_tm->tm_min, rtc_tm->tm_sec);
185
Ben Dooks1add6782006-07-01 04:36:26 -0700186 rtc_tm->tm_mon -= 1;
187
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700188 clk_disable(info->rtc_clk);
189
Kukjin Kim5b3ffdd2010-10-27 15:33:11 -0700190 return rtc_valid_tm(rtc_tm);
Ben Dooks1add6782006-07-01 04:36:26 -0700191}
192
193static int s3c_rtc_settime(struct device *dev, struct rtc_time *tm)
194{
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700195 struct s3c_rtc *info = dev_get_drvdata(dev);
Ben Dooks641741e2006-08-27 01:23:27 -0700196 int year = tm->tm_year - 100;
Ben Dooks1add6782006-07-01 04:36:26 -0700197
Jingoo Hand4a48c22013-02-21 16:45:06 -0800198 dev_dbg(dev, "set time %04d.%02d.%02d %02d:%02d:%02d\n",
Kukjin Kim30ffc402010-10-27 15:33:09 -0700199 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday,
Ben Dooks9a654512006-08-27 01:23:22 -0700200 tm->tm_hour, tm->tm_min, tm->tm_sec);
201
Ben Dooks641741e2006-08-27 01:23:27 -0700202 /* we get around y2k by simply not supporting it */
203
204 if (year < 0 || year >= 100) {
205 dev_err(dev, "rtc only supports 100 years\n");
206 return -EINVAL;
207 }
208
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700209 clk_enable(info->rtc_clk);
210
211 writeb(bin2bcd(tm->tm_sec), info->base + S3C2410_RTCSEC);
212 writeb(bin2bcd(tm->tm_min), info->base + S3C2410_RTCMIN);
213 writeb(bin2bcd(tm->tm_hour), info->base + S3C2410_RTCHOUR);
214 writeb(bin2bcd(tm->tm_mday), info->base + S3C2410_RTCDATE);
215 writeb(bin2bcd(tm->tm_mon + 1), info->base + S3C2410_RTCMON);
216 writeb(bin2bcd(year), info->base + S3C2410_RTCYEAR);
217
218 clk_disable(info->rtc_clk);
Ben Dooks1add6782006-07-01 04:36:26 -0700219
220 return 0;
221}
222
223static int s3c_rtc_getalarm(struct device *dev, struct rtc_wkalrm *alrm)
224{
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700225 struct s3c_rtc *info = dev_get_drvdata(dev);
Ben Dooks1add6782006-07-01 04:36:26 -0700226 struct rtc_time *alm_tm = &alrm->time;
227 unsigned int alm_en;
228
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700229 clk_enable(info->rtc_clk);
230 alm_tm->tm_sec = readb(info->base + S3C2410_ALMSEC);
231 alm_tm->tm_min = readb(info->base + S3C2410_ALMMIN);
232 alm_tm->tm_hour = readb(info->base + S3C2410_ALMHOUR);
233 alm_tm->tm_mon = readb(info->base + S3C2410_ALMMON);
234 alm_tm->tm_mday = readb(info->base + S3C2410_ALMDATE);
235 alm_tm->tm_year = readb(info->base + S3C2410_ALMYEAR);
Ben Dooks1add6782006-07-01 04:36:26 -0700236
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700237 alm_en = readb(info->base + S3C2410_RTCALM);
Ben Dooks1add6782006-07-01 04:36:26 -0700238
David Brownella2db8df2006-12-13 00:35:08 -0800239 alrm->enabled = (alm_en & S3C2410_RTCALM_ALMEN) ? 1 : 0;
240
Jingoo Hand4a48c22013-02-21 16:45:06 -0800241 dev_dbg(dev, "read alarm %d, %04d.%02d.%02d %02d:%02d:%02d\n",
Ben Dooks1add6782006-07-01 04:36:26 -0700242 alm_en,
Kukjin Kim30ffc402010-10-27 15:33:09 -0700243 1900 + alm_tm->tm_year, alm_tm->tm_mon, alm_tm->tm_mday,
Ben Dooks1add6782006-07-01 04:36:26 -0700244 alm_tm->tm_hour, alm_tm->tm_min, alm_tm->tm_sec);
245
246
247 /* decode the alarm enable field */
248
249 if (alm_en & S3C2410_RTCALM_SECEN)
Adrian Bunkfe20ba72008-10-18 20:28:41 -0700250 alm_tm->tm_sec = bcd2bin(alm_tm->tm_sec);
Ben Dooks1add6782006-07-01 04:36:26 -0700251 else
Changhwan Youndd061d12010-10-27 15:33:08 -0700252 alm_tm->tm_sec = -1;
Ben Dooks1add6782006-07-01 04:36:26 -0700253
254 if (alm_en & S3C2410_RTCALM_MINEN)
Adrian Bunkfe20ba72008-10-18 20:28:41 -0700255 alm_tm->tm_min = bcd2bin(alm_tm->tm_min);
Ben Dooks1add6782006-07-01 04:36:26 -0700256 else
Changhwan Youndd061d12010-10-27 15:33:08 -0700257 alm_tm->tm_min = -1;
Ben Dooks1add6782006-07-01 04:36:26 -0700258
259 if (alm_en & S3C2410_RTCALM_HOUREN)
Adrian Bunkfe20ba72008-10-18 20:28:41 -0700260 alm_tm->tm_hour = bcd2bin(alm_tm->tm_hour);
Ben Dooks1add6782006-07-01 04:36:26 -0700261 else
Changhwan Youndd061d12010-10-27 15:33:08 -0700262 alm_tm->tm_hour = -1;
Ben Dooks1add6782006-07-01 04:36:26 -0700263
264 if (alm_en & S3C2410_RTCALM_DAYEN)
Adrian Bunkfe20ba72008-10-18 20:28:41 -0700265 alm_tm->tm_mday = bcd2bin(alm_tm->tm_mday);
Ben Dooks1add6782006-07-01 04:36:26 -0700266 else
Changhwan Youndd061d12010-10-27 15:33:08 -0700267 alm_tm->tm_mday = -1;
Ben Dooks1add6782006-07-01 04:36:26 -0700268
269 if (alm_en & S3C2410_RTCALM_MONEN) {
Adrian Bunkfe20ba72008-10-18 20:28:41 -0700270 alm_tm->tm_mon = bcd2bin(alm_tm->tm_mon);
Ben Dooks1add6782006-07-01 04:36:26 -0700271 alm_tm->tm_mon -= 1;
272 } else {
Changhwan Youndd061d12010-10-27 15:33:08 -0700273 alm_tm->tm_mon = -1;
Ben Dooks1add6782006-07-01 04:36:26 -0700274 }
275
276 if (alm_en & S3C2410_RTCALM_YEAREN)
Adrian Bunkfe20ba72008-10-18 20:28:41 -0700277 alm_tm->tm_year = bcd2bin(alm_tm->tm_year);
Ben Dooks1add6782006-07-01 04:36:26 -0700278 else
Changhwan Youndd061d12010-10-27 15:33:08 -0700279 alm_tm->tm_year = -1;
Ben Dooks1add6782006-07-01 04:36:26 -0700280
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700281 clk_disable(info->rtc_clk);
Ben Dooks1add6782006-07-01 04:36:26 -0700282 return 0;
283}
284
285static int s3c_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
286{
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700287 struct s3c_rtc *info = dev_get_drvdata(dev);
Ben Dooks1add6782006-07-01 04:36:26 -0700288 struct rtc_time *tm = &alrm->time;
289 unsigned int alrm_en;
290
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700291 clk_enable(info->rtc_clk);
Jingoo Hand4a48c22013-02-21 16:45:06 -0800292 dev_dbg(dev, "s3c_rtc_setalarm: %d, %04d.%02d.%02d %02d:%02d:%02d\n",
Ben Dooks1add6782006-07-01 04:36:26 -0700293 alrm->enabled,
MyungJoo Ham4e8896c2011-08-25 15:59:22 -0700294 1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday,
Kukjin Kim30ffc402010-10-27 15:33:09 -0700295 tm->tm_hour, tm->tm_min, tm->tm_sec);
Ben Dooks1add6782006-07-01 04:36:26 -0700296
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700297 alrm_en = readb(info->base + S3C2410_RTCALM) & S3C2410_RTCALM_ALMEN;
298 writeb(0x00, info->base + S3C2410_RTCALM);
Ben Dooks1add6782006-07-01 04:36:26 -0700299
300 if (tm->tm_sec < 60 && tm->tm_sec >= 0) {
301 alrm_en |= S3C2410_RTCALM_SECEN;
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700302 writeb(bin2bcd(tm->tm_sec), info->base + S3C2410_ALMSEC);
Ben Dooks1add6782006-07-01 04:36:26 -0700303 }
304
305 if (tm->tm_min < 60 && tm->tm_min >= 0) {
306 alrm_en |= S3C2410_RTCALM_MINEN;
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700307 writeb(bin2bcd(tm->tm_min), info->base + S3C2410_ALMMIN);
Ben Dooks1add6782006-07-01 04:36:26 -0700308 }
309
310 if (tm->tm_hour < 24 && tm->tm_hour >= 0) {
311 alrm_en |= S3C2410_RTCALM_HOUREN;
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700312 writeb(bin2bcd(tm->tm_hour), info->base + S3C2410_ALMHOUR);
Ben Dooks1add6782006-07-01 04:36:26 -0700313 }
314
Jingoo Hand4a48c22013-02-21 16:45:06 -0800315 dev_dbg(dev, "setting S3C2410_RTCALM to %08x\n", alrm_en);
Ben Dooks1add6782006-07-01 04:36:26 -0700316
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700317 writeb(alrm_en, info->base + S3C2410_RTCALM);
Ben Dooks1add6782006-07-01 04:36:26 -0700318
Axel Lin2ec38a02011-03-04 17:36:19 -0800319 s3c_rtc_setaie(dev, alrm->enabled);
Ben Dooks1add6782006-07-01 04:36:26 -0700320
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700321 clk_disable(info->rtc_clk);
322
Ben Dooks1add6782006-07-01 04:36:26 -0700323 return 0;
324}
325
Ben Dooks1add6782006-07-01 04:36:26 -0700326static int s3c_rtc_proc(struct device *dev, struct seq_file *seq)
327{
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700328 struct s3c_rtc *info = dev_get_drvdata(dev);
Ben Dooks1add6782006-07-01 04:36:26 -0700329
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700330 clk_enable(info->rtc_clk);
Maurus Cuelenaere9f4123b2010-05-24 14:33:43 -0700331
Chanwoo Choiae05c952014-10-13 15:52:33 -0700332 if (info->data->enable_tick)
333 info->data->enable_tick(info, seq);
334
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700335 clk_disable(info->rtc_clk);
Chanwoo Choiae05c952014-10-13 15:52:33 -0700336
Ben Dooks1add6782006-07-01 04:36:26 -0700337 return 0;
338}
339
David Brownellff8371a2006-09-30 23:28:17 -0700340static const struct rtc_class_ops s3c_rtcops = {
Ben Dooks1add6782006-07-01 04:36:26 -0700341 .read_time = s3c_rtc_gettime,
342 .set_time = s3c_rtc_settime,
343 .read_alarm = s3c_rtc_getalarm,
344 .set_alarm = s3c_rtc_setalarm,
Changhwan Youne6eb5242010-10-27 15:33:09 -0700345 .proc = s3c_rtc_proc,
346 .alarm_irq_enable = s3c_rtc_setaie,
Ben Dooks1add6782006-07-01 04:36:26 -0700347};
348
Chanwoo Choiae05c952014-10-13 15:52:33 -0700349static void s3c24xx_rtc_enable(struct s3c_rtc *info)
Ben Dooks1add6782006-07-01 04:36:26 -0700350{
Chanwoo Choid67288d2014-10-13 15:52:31 -0700351 unsigned int con, tmp;
Ben Dooks1add6782006-07-01 04:36:26 -0700352
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700353 clk_enable(info->rtc_clk);
Chanwoo Choid67288d2014-10-13 15:52:31 -0700354
355 con = readw(info->base + S3C2410_RTCCON);
Chanwoo Choiae05c952014-10-13 15:52:33 -0700356 /* re-enable the device, and check it is ok */
357 if ((con & S3C2410_RTCCON_RTCEN) == 0) {
358 dev_info(info->dev, "rtc disabled, re-enabling\n");
Ben Dooks1add6782006-07-01 04:36:26 -0700359
Chanwoo Choiae05c952014-10-13 15:52:33 -0700360 tmp = readw(info->base + S3C2410_RTCCON);
361 writew(tmp | S3C2410_RTCCON_RTCEN,
362 info->base + S3C2410_RTCCON);
Ben Dooks1add6782006-07-01 04:36:26 -0700363 }
Chanwoo Choiae05c952014-10-13 15:52:33 -0700364
365 if (con & S3C2410_RTCCON_CNTSEL) {
366 dev_info(info->dev, "removing RTCCON_CNTSEL\n");
367
368 tmp = readw(info->base + S3C2410_RTCCON);
369 writew(tmp & ~S3C2410_RTCCON_CNTSEL,
370 info->base + S3C2410_RTCCON);
371 }
372
373 if (con & S3C2410_RTCCON_CLKRST) {
374 dev_info(info->dev, "removing RTCCON_CLKRST\n");
375
376 tmp = readw(info->base + S3C2410_RTCCON);
377 writew(tmp & ~S3C2410_RTCCON_CLKRST,
378 info->base + S3C2410_RTCCON);
379 }
380
381 clk_disable(info->rtc_clk);
382}
383
384static void s3c24xx_rtc_disable(struct s3c_rtc *info)
385{
386 unsigned int con;
387
388 clk_enable(info->rtc_clk);
389
390 con = readw(info->base + S3C2410_RTCCON);
391 con &= ~S3C2410_RTCCON_RTCEN;
392 writew(con, info->base + S3C2410_RTCCON);
393
394 con = readb(info->base + S3C2410_TICNT);
395 con &= ~S3C2410_TICNT_ENABLE;
396 writeb(con, info->base + S3C2410_TICNT);
397
398 clk_disable(info->rtc_clk);
399}
400
401static void s3c6410_rtc_disable(struct s3c_rtc *info)
402{
403 unsigned int con;
404
405 clk_enable(info->rtc_clk);
406
407 con = readw(info->base + S3C2410_RTCCON);
408 con &= ~S3C64XX_RTCCON_TICEN;
409 con &= ~S3C2410_RTCCON_RTCEN;
410 writew(con, info->base + S3C2410_RTCCON);
411
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700412 clk_disable(info->rtc_clk);
Ben Dooks1add6782006-07-01 04:36:26 -0700413}
414
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700415static int s3c_rtc_remove(struct platform_device *pdev)
Ben Dooks1add6782006-07-01 04:36:26 -0700416{
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700417 struct s3c_rtc *info = platform_get_drvdata(pdev);
Ben Dooks1add6782006-07-01 04:36:26 -0700418
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700419 s3c_rtc_setaie(info->dev, 0);
420
421 clk_unprepare(info->rtc_clk);
422 info->rtc_clk = NULL;
Atul Dahiyae48add82010-07-20 12:19:14 +0530423
Ben Dooks1add6782006-07-01 04:36:26 -0700424 return 0;
425}
426
Heiko Stuebnerd2524ca2011-12-24 10:52:14 +0900427static const struct of_device_id s3c_rtc_dt_match[];
428
Chanwoo Choiae05c952014-10-13 15:52:33 -0700429static struct s3c_rtc_data *s3c_rtc_get_data(struct platform_device *pdev)
Heiko Stuebnerd2524ca2011-12-24 10:52:14 +0900430{
Chanwoo Choiae05c952014-10-13 15:52:33 -0700431 const struct of_device_id *match;
Chanwoo Choid67288d2014-10-13 15:52:31 -0700432
Chanwoo Choiae05c952014-10-13 15:52:33 -0700433 match = of_match_node(s3c_rtc_dt_match, pdev->dev.of_node);
434 return (struct s3c_rtc_data *)match->data;
Heiko Stuebnerd2524ca2011-12-24 10:52:14 +0900435}
436
Greg Kroah-Hartman5a167f42012-12-21 13:09:38 -0800437static int s3c_rtc_probe(struct platform_device *pdev)
Ben Dooks1add6782006-07-01 04:36:26 -0700438{
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700439 struct s3c_rtc *info = NULL;
Changhwan Youne1df9622010-10-27 15:33:10 -0700440 struct rtc_time rtc_tm;
Ben Dooks1add6782006-07-01 04:36:26 -0700441 struct resource *res;
442 int ret;
443
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700444 info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
445 if (!info)
446 return -ENOMEM;
Ben Dooks1add6782006-07-01 04:36:26 -0700447
448 /* find the IRQs */
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700449 info->irq_tick = platform_get_irq(pdev, 1);
450 if (info->irq_tick < 0) {
Ben Dooks1add6782006-07-01 04:36:26 -0700451 dev_err(&pdev->dev, "no irq for rtc tick\n");
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700452 return info->irq_tick;
Ben Dooks1add6782006-07-01 04:36:26 -0700453 }
454
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700455 info->dev = &pdev->dev;
Chanwoo Choiae05c952014-10-13 15:52:33 -0700456 info->data = s3c_rtc_get_data(pdev);
457 if (!info->data) {
458 dev_err(&pdev->dev, "failed getting s3c_rtc_data\n");
459 return -EINVAL;
460 }
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700461 spin_lock_init(&info->pie_lock);
462 spin_lock_init(&info->alarm_clk_lock);
463
464 platform_set_drvdata(pdev, info);
465
466 info->irq_alarm = platform_get_irq(pdev, 0);
467 if (info->irq_alarm < 0) {
Ben Dooks1add6782006-07-01 04:36:26 -0700468 dev_err(&pdev->dev, "no irq for alarm\n");
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700469 return info->irq_alarm;
Ben Dooks1add6782006-07-01 04:36:26 -0700470 }
471
Jingoo Hand4a48c22013-02-21 16:45:06 -0800472 dev_dbg(&pdev->dev, "s3c2410_rtc: tick irq %d, alarm irq %d\n",
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700473 info->irq_tick, info->irq_alarm);
Ben Dooks1add6782006-07-01 04:36:26 -0700474
475 /* get the memory region */
Ben Dooks1add6782006-07-01 04:36:26 -0700476 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700477 info->base = devm_ioremap_resource(&pdev->dev, res);
478 if (IS_ERR(info->base))
479 return PTR_ERR(info->base);
Ben Dooks1add6782006-07-01 04:36:26 -0700480
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700481 info->rtc_clk = devm_clk_get(&pdev->dev, "rtc");
482 if (IS_ERR(info->rtc_clk)) {
Atul Dahiyae48add82010-07-20 12:19:14 +0530483 dev_err(&pdev->dev, "failed to find rtc clock source\n");
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700484 return PTR_ERR(info->rtc_clk);
Atul Dahiyae48add82010-07-20 12:19:14 +0530485 }
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700486 clk_prepare_enable(info->rtc_clk);
Atul Dahiyae48add82010-07-20 12:19:14 +0530487
Ben Dooks1add6782006-07-01 04:36:26 -0700488 /* check to see if everything is setup correctly */
Chanwoo Choiae05c952014-10-13 15:52:33 -0700489 if (info->data->enable)
490 info->data->enable(info);
Ben Dooks1add6782006-07-01 04:36:26 -0700491
Jingoo Hand4a48c22013-02-21 16:45:06 -0800492 dev_dbg(&pdev->dev, "s3c2410_rtc: RTCCON=%02x\n",
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700493 readw(info->base + S3C2410_RTCCON));
Ben Dooks1add6782006-07-01 04:36:26 -0700494
Yauhen Kharuzhy51b76162008-10-29 14:01:16 -0700495 device_init_wakeup(&pdev->dev, 1);
496
Ben Dooks1add6782006-07-01 04:36:26 -0700497 /* register RTC and exit */
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700498 info->rtc = devm_rtc_device_register(&pdev->dev, "s3c", &s3c_rtcops,
Ben Dooks1add6782006-07-01 04:36:26 -0700499 THIS_MODULE);
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700500 if (IS_ERR(info->rtc)) {
Ben Dooks1add6782006-07-01 04:36:26 -0700501 dev_err(&pdev->dev, "cannot attach rtc\n");
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700502 ret = PTR_ERR(info->rtc);
Ben Dooks1add6782006-07-01 04:36:26 -0700503 goto err_nortc;
504 }
505
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700506 ret = devm_request_irq(&pdev->dev, info->irq_alarm, s3c_rtc_alarmirq,
507 0, "s3c2410-rtc alarm", info);
508 if (ret) {
509 dev_err(&pdev->dev, "IRQ%d error %d\n", info->irq_alarm, ret);
510 goto err_nortc;
511 }
512
513 ret = devm_request_irq(&pdev->dev, info->irq_tick, s3c_rtc_tickirq,
514 0, "s3c2410-rtc tick", info);
515 if (ret) {
516 dev_err(&pdev->dev, "IRQ%d error %d\n", info->irq_tick, ret);
517 goto err_nortc;
518 }
Maurus Cuelenaereeaa6e4d2010-06-04 14:14:46 -0700519
Taekgyun Ko051fe542010-07-29 13:00:42 +0900520 /* Check RTC Time */
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700521 s3c_rtc_gettime(&pdev->dev, &rtc_tm);
Taekgyun Ko051fe542010-07-29 13:00:42 +0900522
Changhwan Youne1df9622010-10-27 15:33:10 -0700523 if (rtc_valid_tm(&rtc_tm)) {
524 rtc_tm.tm_year = 100;
525 rtc_tm.tm_mon = 0;
526 rtc_tm.tm_mday = 1;
527 rtc_tm.tm_hour = 0;
528 rtc_tm.tm_min = 0;
529 rtc_tm.tm_sec = 0;
530
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700531 s3c_rtc_settime(&pdev->dev, &rtc_tm);
Changhwan Youne1df9622010-10-27 15:33:10 -0700532
533 dev_warn(&pdev->dev, "warning: invalid RTC value so initializing it\n");
Taekgyun Ko051fe542010-07-29 13:00:42 +0900534 }
535
Chanwoo Choiae05c952014-10-13 15:52:33 -0700536 if (info->data->select_tick_clk)
537 info->data->select_tick_clk(info);
Heiko Stuebner25c1a242011-12-24 10:52:19 +0900538
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700539 s3c_rtc_setfreq(info, 1);
Maurus Cuelenaeree893de52010-06-04 14:14:44 -0700540
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700541 clk_disable(info->rtc_clk);
Donggeun Kimcefe4fb2011-07-25 17:13:32 -0700542
Ben Dooks1add6782006-07-01 04:36:26 -0700543 return 0;
544
545 err_nortc:
Chanwoo Choiae05c952014-10-13 15:52:33 -0700546 if (info->data->disable)
547 info->data->disable(info);
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700548 clk_disable_unprepare(info->rtc_clk);
Atul Dahiyae48add82010-07-20 12:19:14 +0530549
Ben Dooks1add6782006-07-01 04:36:26 -0700550 return ret;
551}
552
Jingoo Han32e445a2013-04-29 16:19:27 -0700553#ifdef CONFIG_PM_SLEEP
Ben Dooks1add6782006-07-01 04:36:26 -0700554
Jingoo Han32e445a2013-04-29 16:19:27 -0700555static int s3c_rtc_suspend(struct device *dev)
Ben Dooks1add6782006-07-01 04:36:26 -0700556{
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700557 struct s3c_rtc *info = dev_get_drvdata(dev);
Jingoo Han32e445a2013-04-29 16:19:27 -0700558
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700559 clk_enable(info->rtc_clk);
Chanwoo Choiae05c952014-10-13 15:52:33 -0700560
Ben Dooks1add6782006-07-01 04:36:26 -0700561 /* save TICNT for anyone using periodic interrupts */
Chanwoo Choiae05c952014-10-13 15:52:33 -0700562 if (info->data->save_tick_cnt)
563 info->data->save_tick_cnt(info);
564
565 if (info->data->disable)
566 info->data->disable(info);
Vladimir Zapolskiyf501ed52010-09-22 13:05:13 -0700567
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700568 if (device_may_wakeup(dev) && !info->wake_en) {
569 if (enable_irq_wake(info->irq_alarm) == 0)
570 info->wake_en = true;
Ben Dooks52cd4e52011-05-11 15:13:28 -0700571 else
Jingoo Han32e445a2013-04-29 16:19:27 -0700572 dev_err(dev, "enable_irq_wake failed\n");
Ben Dooks52cd4e52011-05-11 15:13:28 -0700573 }
Chanwoo Choiae05c952014-10-13 15:52:33 -0700574
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700575 clk_disable(info->rtc_clk);
Vladimir Zapolskiyf501ed52010-09-22 13:05:13 -0700576
Ben Dooks1add6782006-07-01 04:36:26 -0700577 return 0;
578}
579
Jingoo Han32e445a2013-04-29 16:19:27 -0700580static int s3c_rtc_resume(struct device *dev)
Ben Dooks1add6782006-07-01 04:36:26 -0700581{
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700582 struct s3c_rtc *info = dev_get_drvdata(dev);
Maurus Cuelenaere9f4123b2010-05-24 14:33:43 -0700583
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700584 clk_enable(info->rtc_clk);
Chanwoo Choiae05c952014-10-13 15:52:33 -0700585
586 if (info->data->enable)
587 info->data->enable(info);
588
589 if (info->data->restore_tick_cnt)
590 info->data->restore_tick_cnt(info);
Vladimir Zapolskiyf501ed52010-09-22 13:05:13 -0700591
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700592 if (device_may_wakeup(dev) && info->wake_en) {
593 disable_irq_wake(info->irq_alarm);
594 info->wake_en = false;
Ben Dooks52cd4e52011-05-11 15:13:28 -0700595 }
Chanwoo Choiae05c952014-10-13 15:52:33 -0700596
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700597 clk_disable(info->rtc_clk);
Vladimir Zapolskiyf501ed52010-09-22 13:05:13 -0700598
Ben Dooks1add6782006-07-01 04:36:26 -0700599 return 0;
600}
Ben Dooks1add6782006-07-01 04:36:26 -0700601#endif
Jingoo Han32e445a2013-04-29 16:19:27 -0700602static SIMPLE_DEV_PM_OPS(s3c_rtc_pm_ops, s3c_rtc_suspend, s3c_rtc_resume);
603
Chanwoo Choiae05c952014-10-13 15:52:33 -0700604static void s3c24xx_rtc_irq(struct s3c_rtc *info, int mask)
605{
606 clk_enable(info->rtc_clk);
607 rtc_update_irq(info->rtc, 1, RTC_AF | RTC_IRQF);
608 clk_disable(info->rtc_clk);
609
610 s3c_rtc_alarm_clk_enable(info, false);
611}
612
613static void s3c6410_rtc_irq(struct s3c_rtc *info, int mask)
614{
615 clk_enable(info->rtc_clk);
616 rtc_update_irq(info->rtc, 1, RTC_AF | RTC_IRQF);
617 writeb(mask, info->base + S3C2410_INTP);
618 clk_disable(info->rtc_clk);
619
620 s3c_rtc_alarm_clk_enable(info, false);
621}
622
623static void s3c2410_rtc_setfreq(struct s3c_rtc *info, int freq)
624{
625 unsigned int tmp = 0;
626 int val;
627
628 tmp = readb(info->base + S3C2410_TICNT);
629 tmp &= S3C2410_TICNT_ENABLE;
630
631 val = (info->rtc->max_user_freq / freq) - 1;
632 tmp |= val;
633
634 writel(tmp, info->base + S3C2410_TICNT);
635}
636
637static void s3c2416_rtc_setfreq(struct s3c_rtc *info, int freq)
638{
639 unsigned int tmp = 0;
640 int val;
641
642 tmp = readb(info->base + S3C2410_TICNT);
643 tmp &= S3C2410_TICNT_ENABLE;
644
645 val = (info->rtc->max_user_freq / freq) - 1;
646
647 tmp |= S3C2443_TICNT_PART(val);
648 writel(S3C2443_TICNT1_PART(val), info->base + S3C2443_TICNT1);
649
650 writel(S3C2416_TICNT2_PART(val), info->base + S3C2416_TICNT2);
651
652 writel(tmp, info->base + S3C2410_TICNT);
653}
654
655static void s3c2443_rtc_setfreq(struct s3c_rtc *info, int freq)
656{
657 unsigned int tmp = 0;
658 int val;
659
660 tmp = readb(info->base + S3C2410_TICNT);
661 tmp &= S3C2410_TICNT_ENABLE;
662
663 val = (info->rtc->max_user_freq / freq) - 1;
664
665 tmp |= S3C2443_TICNT_PART(val);
666 writel(S3C2443_TICNT1_PART(val), info->base + S3C2443_TICNT1);
667
668 writel(tmp, info->base + S3C2410_TICNT);
669}
670
671static void s3c6410_rtc_setfreq(struct s3c_rtc *info, int freq)
672{
673 int val;
674
675 val = (info->rtc->max_user_freq / freq) - 1;
676 writel(val, info->base + S3C2410_TICNT);
677}
678
679static void s3c24xx_rtc_enable_tick(struct s3c_rtc *info, struct seq_file *seq)
680{
681 unsigned int ticnt;
682
683 ticnt = readb(info->base + S3C2410_TICNT);
684 ticnt &= S3C2410_TICNT_ENABLE;
685
686 seq_printf(seq, "periodic_IRQ\t: %s\n", ticnt ? "yes" : "no");
687}
688
689static void s3c2416_rtc_select_tick_clk(struct s3c_rtc *info)
690{
691 unsigned int con;
692
693 con = readw(info->base + S3C2410_RTCCON);
694 con |= S3C2443_RTCCON_TICSEL;
695 writew(con, info->base + S3C2410_RTCCON);
696}
697
698static void s3c6410_rtc_enable_tick(struct s3c_rtc *info, struct seq_file *seq)
699{
700 unsigned int ticnt;
701
702 ticnt = readw(info->base + S3C2410_RTCCON);
703 ticnt &= S3C64XX_RTCCON_TICEN;
704
705 seq_printf(seq, "periodic_IRQ\t: %s\n", ticnt ? "yes" : "no");
706}
707
708static void s3c24xx_rtc_save_tick_cnt(struct s3c_rtc *info)
709{
710 info->ticnt_save = readb(info->base + S3C2410_TICNT);
711}
712
713static void s3c24xx_rtc_restore_tick_cnt(struct s3c_rtc *info)
714{
715 writeb(info->ticnt_save, info->base + S3C2410_TICNT);
716}
717
718static void s3c6410_rtc_save_tick_cnt(struct s3c_rtc *info)
719{
720 info->ticnt_en_save = readw(info->base + S3C2410_RTCCON);
721 info->ticnt_en_save &= S3C64XX_RTCCON_TICEN;
722 info->ticnt_save = readl(info->base + S3C2410_TICNT);
723}
724
725static void s3c6410_rtc_restore_tick_cnt(struct s3c_rtc *info)
726{
727 unsigned int con;
728
729 writel(info->ticnt_save, info->base + S3C2410_TICNT);
730 if (info->ticnt_en_save) {
731 con = readw(info->base + S3C2410_RTCCON);
732 writew(con | info->ticnt_en_save,
733 info->base + S3C2410_RTCCON);
734 }
735}
736
737static struct s3c_rtc_data const s3c2410_rtc_data = {
738 .max_user_freq = 128,
739 .irq_handler = s3c24xx_rtc_irq,
740 .set_freq = s3c2410_rtc_setfreq,
741 .enable_tick = s3c24xx_rtc_enable_tick,
742 .save_tick_cnt = s3c24xx_rtc_save_tick_cnt,
743 .restore_tick_cnt = s3c24xx_rtc_restore_tick_cnt,
744 .enable = s3c24xx_rtc_enable,
745 .disable = s3c24xx_rtc_disable,
746};
747
748static struct s3c_rtc_data const s3c2416_rtc_data = {
749 .max_user_freq = 32768,
750 .irq_handler = s3c24xx_rtc_irq,
751 .set_freq = s3c2416_rtc_setfreq,
752 .enable_tick = s3c24xx_rtc_enable_tick,
753 .select_tick_clk = s3c2416_rtc_select_tick_clk,
754 .save_tick_cnt = s3c24xx_rtc_save_tick_cnt,
755 .restore_tick_cnt = s3c24xx_rtc_restore_tick_cnt,
756 .enable = s3c24xx_rtc_enable,
757 .disable = s3c24xx_rtc_disable,
758};
759
760static struct s3c_rtc_data const s3c2443_rtc_data = {
761 .max_user_freq = 32768,
762 .irq_handler = s3c24xx_rtc_irq,
763 .set_freq = s3c2443_rtc_setfreq,
764 .enable_tick = s3c24xx_rtc_enable_tick,
765 .select_tick_clk = s3c2416_rtc_select_tick_clk,
766 .save_tick_cnt = s3c24xx_rtc_save_tick_cnt,
767 .restore_tick_cnt = s3c24xx_rtc_restore_tick_cnt,
768 .enable = s3c24xx_rtc_enable,
769 .disable = s3c24xx_rtc_disable,
770};
771
772static struct s3c_rtc_data const s3c6410_rtc_data = {
773 .max_user_freq = 32768,
774 .irq_handler = s3c6410_rtc_irq,
775 .set_freq = s3c6410_rtc_setfreq,
776 .enable_tick = s3c6410_rtc_enable_tick,
777 .save_tick_cnt = s3c6410_rtc_save_tick_cnt,
778 .restore_tick_cnt = s3c6410_rtc_restore_tick_cnt,
779 .enable = s3c24xx_rtc_enable,
780 .disable = s3c6410_rtc_disable,
Tushar Beherac3cba922012-04-12 12:49:14 -0700781};
782
Thomas Abraham39ce4082011-10-24 14:49:04 +0200783static const struct of_device_id s3c_rtc_dt_match[] = {
Heiko Stuebnerd2524ca2011-12-24 10:52:14 +0900784 {
Tushar Beheracd1e6f92012-04-12 12:49:14 -0700785 .compatible = "samsung,s3c2410-rtc",
Chanwoo Choiae05c952014-10-13 15:52:33 -0700786 .data = (void *)&s3c2410_rtc_data,
Heiko Stuebnerd2524ca2011-12-24 10:52:14 +0900787 }, {
Tushar Beheracd1e6f92012-04-12 12:49:14 -0700788 .compatible = "samsung,s3c2416-rtc",
Chanwoo Choiae05c952014-10-13 15:52:33 -0700789 .data = (void *)&s3c2416_rtc_data,
Heiko Stuebner25c1a242011-12-24 10:52:19 +0900790 }, {
Tushar Beheracd1e6f92012-04-12 12:49:14 -0700791 .compatible = "samsung,s3c2443-rtc",
Chanwoo Choiae05c952014-10-13 15:52:33 -0700792 .data = (void *)&s3c2443_rtc_data,
Heiko Stuebner25c1a242011-12-24 10:52:19 +0900793 }, {
Tushar Beheracd1e6f92012-04-12 12:49:14 -0700794 .compatible = "samsung,s3c6410-rtc",
Chanwoo Choiae05c952014-10-13 15:52:33 -0700795 .data = (void *)&s3c6410_rtc_data,
Heiko Stuebnerd2524ca2011-12-24 10:52:14 +0900796 },
Chanwoo Choiae05c952014-10-13 15:52:33 -0700797 { /* sentinel */ },
Thomas Abraham39ce4082011-10-24 14:49:04 +0200798};
799MODULE_DEVICE_TABLE(of, s3c_rtc_dt_match);
Maurus Cuelenaere9f4123b2010-05-24 14:33:43 -0700800
801static struct platform_driver s3c_rtc_driver = {
Ben Dooks1add6782006-07-01 04:36:26 -0700802 .probe = s3c_rtc_probe,
Greg Kroah-Hartman5a167f42012-12-21 13:09:38 -0800803 .remove = s3c_rtc_remove,
Ben Dooks1add6782006-07-01 04:36:26 -0700804 .driver = {
Maurus Cuelenaere9f4123b2010-05-24 14:33:43 -0700805 .name = "s3c-rtc",
Ben Dooks1add6782006-07-01 04:36:26 -0700806 .owner = THIS_MODULE,
Jingoo Han32e445a2013-04-29 16:19:27 -0700807 .pm = &s3c_rtc_pm_ops,
Sachin Kamat04a373f2012-12-17 16:02:52 -0800808 .of_match_table = of_match_ptr(s3c_rtc_dt_match),
Ben Dooks1add6782006-07-01 04:36:26 -0700809 },
810};
Axel Lin0c4eae62012-01-10 15:10:48 -0800811module_platform_driver(s3c_rtc_driver);
Ben Dooks1add6782006-07-01 04:36:26 -0700812
813MODULE_DESCRIPTION("Samsung S3C RTC Driver");
814MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
815MODULE_LICENSE("GPL");
Kay Sieversad28a072008-04-10 21:29:25 -0700816MODULE_ALIAS("platform:s3c2410-rtc");