blob: 4e95cca7615ce92abaa1422d010c5590113a6140 [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
Maurus Cuelenaere9f4123b2010-05-24 14:33:43 -070035enum s3c_cpu_type {
36 TYPE_S3C2410,
Heiko Stuebner25c1a242011-12-24 10:52:19 +090037 TYPE_S3C2416,
38 TYPE_S3C2443,
Maurus Cuelenaere9f4123b2010-05-24 14:33:43 -070039 TYPE_S3C64XX,
40};
41
Tushar Beherac3cba922012-04-12 12:49:14 -070042struct s3c_rtc_drv_data {
43 int cpu_type;
44};
45
Chanwoo Choi19be09f2014-10-13 15:52:28 -070046struct s3c_rtc {
47 struct device *dev;
48 struct rtc_device *rtc;
Ben Dooks1add6782006-07-01 04:36:26 -070049
Chanwoo Choi19be09f2014-10-13 15:52:28 -070050 void __iomem *base;
51 struct clk *rtc_clk;
52 bool enabled;
Ben Dooks1add6782006-07-01 04:36:26 -070053
Chanwoo Choi19be09f2014-10-13 15:52:28 -070054 enum s3c_cpu_type cpu_type;
Ben Dooks1add6782006-07-01 04:36:26 -070055
Chanwoo Choi19be09f2014-10-13 15:52:28 -070056 int irq_alarm;
57 int irq_tick;
58
59 spinlock_t pie_lock;
60 spinlock_t alarm_clk_lock;
61
62 int ticnt_save, ticnt_en_save;
63 bool wake_en;
64};
65
66static void s3c_rtc_alarm_clk_enable(struct s3c_rtc *info, bool enable)
Donggeun Kim88cee8f2011-09-14 16:22:19 -070067{
Donggeun Kim88cee8f2011-09-14 16:22:19 -070068 unsigned long irq_flags;
69
Chanwoo Choi19be09f2014-10-13 15:52:28 -070070 spin_lock_irqsave(&info->alarm_clk_lock, irq_flags);
Donggeun Kim88cee8f2011-09-14 16:22:19 -070071 if (enable) {
Chanwoo Choi19be09f2014-10-13 15:52:28 -070072 if (!info->enabled) {
73 clk_enable(info->rtc_clk);
74 info->enabled = true;
Donggeun Kim88cee8f2011-09-14 16:22:19 -070075 }
76 } else {
Chanwoo Choi19be09f2014-10-13 15:52:28 -070077 if (info->enabled) {
78 clk_disable(info->rtc_clk);
79 info->enabled = false;
Donggeun Kim88cee8f2011-09-14 16:22:19 -070080 }
81 }
Chanwoo Choi19be09f2014-10-13 15:52:28 -070082 spin_unlock_irqrestore(&info->alarm_clk_lock, irq_flags);
Donggeun Kim88cee8f2011-09-14 16:22:19 -070083}
84
Ben Dooks1add6782006-07-01 04:36:26 -070085/* IRQ Handlers */
David Howells7d12e782006-10-05 14:55:46 +010086static irqreturn_t s3c_rtc_alarmirq(int irq, void *id)
Ben Dooks1add6782006-07-01 04:36:26 -070087{
Chanwoo Choi19be09f2014-10-13 15:52:28 -070088 struct s3c_rtc *info = (struct s3c_rtc *)id;
Ben Dooks1add6782006-07-01 04:36:26 -070089
Chanwoo Choi19be09f2014-10-13 15:52:28 -070090 clk_enable(info->rtc_clk);
91 rtc_update_irq(info->rtc, 1, RTC_AF | RTC_IRQF);
Atul Dahiya2f3478f2010-07-20 16:02:51 +053092
Chanwoo Choi19be09f2014-10-13 15:52:28 -070093 if (info->cpu_type == TYPE_S3C64XX)
94 writeb(S3C2410_INTP_ALM, info->base + S3C2410_INTP);
Atul Dahiya2f3478f2010-07-20 16:02:51 +053095
Chanwoo Choi19be09f2014-10-13 15:52:28 -070096 clk_disable(info->rtc_clk);
Donggeun Kim88cee8f2011-09-14 16:22:19 -070097
Chanwoo Choi19be09f2014-10-13 15:52:28 -070098 s3c_rtc_alarm_clk_enable(info, false);
Donggeun Kim88cee8f2011-09-14 16:22:19 -070099
Ben Dooks1add6782006-07-01 04:36:26 -0700100 return IRQ_HANDLED;
101}
102
David Howells7d12e782006-10-05 14:55:46 +0100103static irqreturn_t s3c_rtc_tickirq(int irq, void *id)
Ben Dooks1add6782006-07-01 04:36:26 -0700104{
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700105 struct s3c_rtc *info = (struct s3c_rtc *)id;
Ben Dooks1add6782006-07-01 04:36:26 -0700106
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700107 clk_enable(info->rtc_clk);
108 rtc_update_irq(info->rtc, 1, RTC_PF | RTC_IRQF);
Atul Dahiya2f3478f2010-07-20 16:02:51 +0530109
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700110 if (info->cpu_type == TYPE_S3C64XX)
111 writeb(S3C2410_INTP_TIC, info->base + S3C2410_INTP);
Atul Dahiya2f3478f2010-07-20 16:02:51 +0530112
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700113 clk_disable(info->rtc_clk);
114
Ben Dooks1add6782006-07-01 04:36:26 -0700115 return IRQ_HANDLED;
116}
117
118/* Update control registers */
Axel Lin2ec38a02011-03-04 17:36:19 -0800119static int s3c_rtc_setaie(struct device *dev, unsigned int enabled)
Ben Dooks1add6782006-07-01 04:36:26 -0700120{
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700121 struct s3c_rtc *info = dev_get_drvdata(dev);
Ben Dooks1add6782006-07-01 04:36:26 -0700122 unsigned int tmp;
123
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700124 dev_dbg(info->dev, "%s: aie=%d\n", __func__, enabled);
Ben Dooks1add6782006-07-01 04:36:26 -0700125
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700126 clk_enable(info->rtc_clk);
127 tmp = readb(info->base + S3C2410_RTCALM) & ~S3C2410_RTCALM_ALMEN;
Ben Dooks1add6782006-07-01 04:36:26 -0700128
Axel Lin2ec38a02011-03-04 17:36:19 -0800129 if (enabled)
Ben Dooks1add6782006-07-01 04:36:26 -0700130 tmp |= S3C2410_RTCALM_ALMEN;
131
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700132 writeb(tmp, info->base + S3C2410_RTCALM);
133 clk_disable(info->rtc_clk);
Axel Lin2ec38a02011-03-04 17:36:19 -0800134
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700135 s3c_rtc_alarm_clk_enable(info, enabled);
Donggeun Kim88cee8f2011-09-14 16:22:19 -0700136
Axel Lin2ec38a02011-03-04 17:36:19 -0800137 return 0;
Ben Dooks1add6782006-07-01 04:36:26 -0700138}
139
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700140static int s3c_rtc_setfreq(struct s3c_rtc *info, int freq)
Ben Dooks1add6782006-07-01 04:36:26 -0700141{
Maurus Cuelenaere9f4123b2010-05-24 14:33:43 -0700142 unsigned int tmp = 0;
Heiko Stuebner25c1a242011-12-24 10:52:19 +0900143 int val;
Ben Dooks1add6782006-07-01 04:36:26 -0700144
Jonathan Cameron5d2a5032009-01-06 14:42:12 -0800145 if (!is_power_of_2(freq))
146 return -EINVAL;
147
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700148 clk_enable(info->rtc_clk);
149 spin_lock_irq(&info->pie_lock);
Ben Dooks773be7e2008-07-23 21:30:45 -0700150
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700151 if (info->cpu_type != TYPE_S3C64XX) {
152 tmp = readb(info->base + S3C2410_TICNT);
Maurus Cuelenaere9f4123b2010-05-24 14:33:43 -0700153 tmp &= S3C2410_TICNT_ENABLE;
154 }
155
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700156 val = (info->rtc->max_user_freq / freq) - 1;
Heiko Stuebner25c1a242011-12-24 10:52:19 +0900157
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700158 if (info->cpu_type == TYPE_S3C2416 || info->cpu_type == TYPE_S3C2443) {
Heiko Stuebner25c1a242011-12-24 10:52:19 +0900159 tmp |= S3C2443_TICNT_PART(val);
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700160 writel(S3C2443_TICNT1_PART(val), info->base + S3C2443_TICNT1);
Heiko Stuebner25c1a242011-12-24 10:52:19 +0900161
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700162 if (info->cpu_type == TYPE_S3C2416)
163 writel(S3C2416_TICNT2_PART(val),
164 info->base + S3C2416_TICNT2);
Heiko Stuebner25c1a242011-12-24 10:52:19 +0900165 } else {
166 tmp |= val;
167 }
Ben Dooks1add6782006-07-01 04:36:26 -0700168
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700169 writel(tmp, info->base + S3C2410_TICNT);
170 spin_unlock_irq(&info->pie_lock);
171 clk_disable(info->rtc_clk);
Ben Dooks773be7e2008-07-23 21:30:45 -0700172
173 return 0;
Ben Dooks1add6782006-07-01 04:36:26 -0700174}
175
176/* Time read/write */
177
178static int s3c_rtc_gettime(struct device *dev, struct rtc_time *rtc_tm)
179{
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700180 struct s3c_rtc *info = dev_get_drvdata(dev);
Ben Dooks1add6782006-07-01 04:36:26 -0700181 unsigned int have_retried = 0;
182
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700183 clk_enable(info->rtc_clk);
Ben Dooks1add6782006-07-01 04:36:26 -0700184 retry_get_time:
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700185 rtc_tm->tm_min = readb(info->base + S3C2410_RTCMIN);
186 rtc_tm->tm_hour = readb(info->base + S3C2410_RTCHOUR);
187 rtc_tm->tm_mday = readb(info->base + S3C2410_RTCDATE);
188 rtc_tm->tm_mon = readb(info->base + S3C2410_RTCMON);
189 rtc_tm->tm_year = readb(info->base + S3C2410_RTCYEAR);
190 rtc_tm->tm_sec = readb(info->base + S3C2410_RTCSEC);
Ben Dooks1add6782006-07-01 04:36:26 -0700191
Adam Buchbinder48fc7f72012-09-19 21:48:00 -0400192 /* the only way to work out whether the system was mid-update
Ben Dooks1add6782006-07-01 04:36:26 -0700193 * when we read it is to check the second counter, and if it
194 * is zero, then we re-try the entire read
195 */
196
197 if (rtc_tm->tm_sec == 0 && !have_retried) {
198 have_retried = 1;
199 goto retry_get_time;
200 }
201
Adrian Bunkfe20ba72008-10-18 20:28:41 -0700202 rtc_tm->tm_sec = bcd2bin(rtc_tm->tm_sec);
203 rtc_tm->tm_min = bcd2bin(rtc_tm->tm_min);
204 rtc_tm->tm_hour = bcd2bin(rtc_tm->tm_hour);
205 rtc_tm->tm_mday = bcd2bin(rtc_tm->tm_mday);
206 rtc_tm->tm_mon = bcd2bin(rtc_tm->tm_mon);
207 rtc_tm->tm_year = bcd2bin(rtc_tm->tm_year);
Ben Dooks1add6782006-07-01 04:36:26 -0700208
209 rtc_tm->tm_year += 100;
MyungJoo Ham4e8896c2011-08-25 15:59:22 -0700210
Jingoo Hand4a48c22013-02-21 16:45:06 -0800211 dev_dbg(dev, "read time %04d.%02d.%02d %02d:%02d:%02d\n",
MyungJoo Ham4e8896c2011-08-25 15:59:22 -0700212 1900 + rtc_tm->tm_year, rtc_tm->tm_mon, rtc_tm->tm_mday,
213 rtc_tm->tm_hour, rtc_tm->tm_min, rtc_tm->tm_sec);
214
Ben Dooks1add6782006-07-01 04:36:26 -0700215 rtc_tm->tm_mon -= 1;
216
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700217 clk_disable(info->rtc_clk);
218
Kukjin Kim5b3ffdd2010-10-27 15:33:11 -0700219 return rtc_valid_tm(rtc_tm);
Ben Dooks1add6782006-07-01 04:36:26 -0700220}
221
222static int s3c_rtc_settime(struct device *dev, struct rtc_time *tm)
223{
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700224 struct s3c_rtc *info = dev_get_drvdata(dev);
Ben Dooks641741e2006-08-27 01:23:27 -0700225 int year = tm->tm_year - 100;
Ben Dooks1add6782006-07-01 04:36:26 -0700226
Jingoo Hand4a48c22013-02-21 16:45:06 -0800227 dev_dbg(dev, "set time %04d.%02d.%02d %02d:%02d:%02d\n",
Kukjin Kim30ffc402010-10-27 15:33:09 -0700228 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday,
Ben Dooks9a654512006-08-27 01:23:22 -0700229 tm->tm_hour, tm->tm_min, tm->tm_sec);
230
Ben Dooks641741e2006-08-27 01:23:27 -0700231 /* we get around y2k by simply not supporting it */
232
233 if (year < 0 || year >= 100) {
234 dev_err(dev, "rtc only supports 100 years\n");
235 return -EINVAL;
236 }
237
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700238 clk_enable(info->rtc_clk);
239
240 writeb(bin2bcd(tm->tm_sec), info->base + S3C2410_RTCSEC);
241 writeb(bin2bcd(tm->tm_min), info->base + S3C2410_RTCMIN);
242 writeb(bin2bcd(tm->tm_hour), info->base + S3C2410_RTCHOUR);
243 writeb(bin2bcd(tm->tm_mday), info->base + S3C2410_RTCDATE);
244 writeb(bin2bcd(tm->tm_mon + 1), info->base + S3C2410_RTCMON);
245 writeb(bin2bcd(year), info->base + S3C2410_RTCYEAR);
246
247 clk_disable(info->rtc_clk);
Ben Dooks1add6782006-07-01 04:36:26 -0700248
249 return 0;
250}
251
252static int s3c_rtc_getalarm(struct device *dev, struct rtc_wkalrm *alrm)
253{
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700254 struct s3c_rtc *info = dev_get_drvdata(dev);
Ben Dooks1add6782006-07-01 04:36:26 -0700255 struct rtc_time *alm_tm = &alrm->time;
256 unsigned int alm_en;
257
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700258 clk_enable(info->rtc_clk);
259 alm_tm->tm_sec = readb(info->base + S3C2410_ALMSEC);
260 alm_tm->tm_min = readb(info->base + S3C2410_ALMMIN);
261 alm_tm->tm_hour = readb(info->base + S3C2410_ALMHOUR);
262 alm_tm->tm_mon = readb(info->base + S3C2410_ALMMON);
263 alm_tm->tm_mday = readb(info->base + S3C2410_ALMDATE);
264 alm_tm->tm_year = readb(info->base + S3C2410_ALMYEAR);
Ben Dooks1add6782006-07-01 04:36:26 -0700265
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700266 alm_en = readb(info->base + S3C2410_RTCALM);
Ben Dooks1add6782006-07-01 04:36:26 -0700267
David Brownella2db8df2006-12-13 00:35:08 -0800268 alrm->enabled = (alm_en & S3C2410_RTCALM_ALMEN) ? 1 : 0;
269
Jingoo Hand4a48c22013-02-21 16:45:06 -0800270 dev_dbg(dev, "read alarm %d, %04d.%02d.%02d %02d:%02d:%02d\n",
Ben Dooks1add6782006-07-01 04:36:26 -0700271 alm_en,
Kukjin Kim30ffc402010-10-27 15:33:09 -0700272 1900 + alm_tm->tm_year, alm_tm->tm_mon, alm_tm->tm_mday,
Ben Dooks1add6782006-07-01 04:36:26 -0700273 alm_tm->tm_hour, alm_tm->tm_min, alm_tm->tm_sec);
274
275
276 /* decode the alarm enable field */
277
278 if (alm_en & S3C2410_RTCALM_SECEN)
Adrian Bunkfe20ba72008-10-18 20:28:41 -0700279 alm_tm->tm_sec = bcd2bin(alm_tm->tm_sec);
Ben Dooks1add6782006-07-01 04:36:26 -0700280 else
Changhwan Youndd061d12010-10-27 15:33:08 -0700281 alm_tm->tm_sec = -1;
Ben Dooks1add6782006-07-01 04:36:26 -0700282
283 if (alm_en & S3C2410_RTCALM_MINEN)
Adrian Bunkfe20ba72008-10-18 20:28:41 -0700284 alm_tm->tm_min = bcd2bin(alm_tm->tm_min);
Ben Dooks1add6782006-07-01 04:36:26 -0700285 else
Changhwan Youndd061d12010-10-27 15:33:08 -0700286 alm_tm->tm_min = -1;
Ben Dooks1add6782006-07-01 04:36:26 -0700287
288 if (alm_en & S3C2410_RTCALM_HOUREN)
Adrian Bunkfe20ba72008-10-18 20:28:41 -0700289 alm_tm->tm_hour = bcd2bin(alm_tm->tm_hour);
Ben Dooks1add6782006-07-01 04:36:26 -0700290 else
Changhwan Youndd061d12010-10-27 15:33:08 -0700291 alm_tm->tm_hour = -1;
Ben Dooks1add6782006-07-01 04:36:26 -0700292
293 if (alm_en & S3C2410_RTCALM_DAYEN)
Adrian Bunkfe20ba72008-10-18 20:28:41 -0700294 alm_tm->tm_mday = bcd2bin(alm_tm->tm_mday);
Ben Dooks1add6782006-07-01 04:36:26 -0700295 else
Changhwan Youndd061d12010-10-27 15:33:08 -0700296 alm_tm->tm_mday = -1;
Ben Dooks1add6782006-07-01 04:36:26 -0700297
298 if (alm_en & S3C2410_RTCALM_MONEN) {
Adrian Bunkfe20ba72008-10-18 20:28:41 -0700299 alm_tm->tm_mon = bcd2bin(alm_tm->tm_mon);
Ben Dooks1add6782006-07-01 04:36:26 -0700300 alm_tm->tm_mon -= 1;
301 } else {
Changhwan Youndd061d12010-10-27 15:33:08 -0700302 alm_tm->tm_mon = -1;
Ben Dooks1add6782006-07-01 04:36:26 -0700303 }
304
305 if (alm_en & S3C2410_RTCALM_YEAREN)
Adrian Bunkfe20ba72008-10-18 20:28:41 -0700306 alm_tm->tm_year = bcd2bin(alm_tm->tm_year);
Ben Dooks1add6782006-07-01 04:36:26 -0700307 else
Changhwan Youndd061d12010-10-27 15:33:08 -0700308 alm_tm->tm_year = -1;
Ben Dooks1add6782006-07-01 04:36:26 -0700309
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700310 clk_disable(info->rtc_clk);
Ben Dooks1add6782006-07-01 04:36:26 -0700311 return 0;
312}
313
314static int s3c_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
315{
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700316 struct s3c_rtc *info = dev_get_drvdata(dev);
Ben Dooks1add6782006-07-01 04:36:26 -0700317 struct rtc_time *tm = &alrm->time;
318 unsigned int alrm_en;
319
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700320 clk_enable(info->rtc_clk);
Jingoo Hand4a48c22013-02-21 16:45:06 -0800321 dev_dbg(dev, "s3c_rtc_setalarm: %d, %04d.%02d.%02d %02d:%02d:%02d\n",
Ben Dooks1add6782006-07-01 04:36:26 -0700322 alrm->enabled,
MyungJoo Ham4e8896c2011-08-25 15:59:22 -0700323 1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday,
Kukjin Kim30ffc402010-10-27 15:33:09 -0700324 tm->tm_hour, tm->tm_min, tm->tm_sec);
Ben Dooks1add6782006-07-01 04:36:26 -0700325
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700326 alrm_en = readb(info->base + S3C2410_RTCALM) & S3C2410_RTCALM_ALMEN;
327 writeb(0x00, info->base + S3C2410_RTCALM);
Ben Dooks1add6782006-07-01 04:36:26 -0700328
329 if (tm->tm_sec < 60 && tm->tm_sec >= 0) {
330 alrm_en |= S3C2410_RTCALM_SECEN;
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700331 writeb(bin2bcd(tm->tm_sec), info->base + S3C2410_ALMSEC);
Ben Dooks1add6782006-07-01 04:36:26 -0700332 }
333
334 if (tm->tm_min < 60 && tm->tm_min >= 0) {
335 alrm_en |= S3C2410_RTCALM_MINEN;
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700336 writeb(bin2bcd(tm->tm_min), info->base + S3C2410_ALMMIN);
Ben Dooks1add6782006-07-01 04:36:26 -0700337 }
338
339 if (tm->tm_hour < 24 && tm->tm_hour >= 0) {
340 alrm_en |= S3C2410_RTCALM_HOUREN;
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700341 writeb(bin2bcd(tm->tm_hour), info->base + S3C2410_ALMHOUR);
Ben Dooks1add6782006-07-01 04:36:26 -0700342 }
343
Jingoo Hand4a48c22013-02-21 16:45:06 -0800344 dev_dbg(dev, "setting S3C2410_RTCALM to %08x\n", alrm_en);
Ben Dooks1add6782006-07-01 04:36:26 -0700345
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700346 writeb(alrm_en, info->base + S3C2410_RTCALM);
Ben Dooks1add6782006-07-01 04:36:26 -0700347
Axel Lin2ec38a02011-03-04 17:36:19 -0800348 s3c_rtc_setaie(dev, alrm->enabled);
Ben Dooks1add6782006-07-01 04:36:26 -0700349
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700350 clk_disable(info->rtc_clk);
351
Ben Dooks1add6782006-07-01 04:36:26 -0700352 return 0;
353}
354
Ben Dooks1add6782006-07-01 04:36:26 -0700355static int s3c_rtc_proc(struct device *dev, struct seq_file *seq)
356{
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700357 struct s3c_rtc *info = dev_get_drvdata(dev);
Maurus Cuelenaere9f4123b2010-05-24 14:33:43 -0700358 unsigned int ticnt;
Ben Dooks1add6782006-07-01 04:36:26 -0700359
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700360 clk_enable(info->rtc_clk);
361 if (info->cpu_type == TYPE_S3C64XX) {
362 ticnt = readw(info->base + S3C2410_RTCCON);
Maurus Cuelenaere9f4123b2010-05-24 14:33:43 -0700363 ticnt &= S3C64XX_RTCCON_TICEN;
364 } else {
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700365 ticnt = readb(info->base + S3C2410_TICNT);
Maurus Cuelenaere9f4123b2010-05-24 14:33:43 -0700366 ticnt &= S3C2410_TICNT_ENABLE;
367 }
368
369 seq_printf(seq, "periodic_IRQ\t: %s\n", ticnt ? "yes" : "no");
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700370 clk_disable(info->rtc_clk);
Ben Dooks1add6782006-07-01 04:36:26 -0700371 return 0;
372}
373
David Brownellff8371a2006-09-30 23:28:17 -0700374static const struct rtc_class_ops s3c_rtcops = {
Ben Dooks1add6782006-07-01 04:36:26 -0700375 .read_time = s3c_rtc_gettime,
376 .set_time = s3c_rtc_settime,
377 .read_alarm = s3c_rtc_getalarm,
378 .set_alarm = s3c_rtc_setalarm,
Changhwan Youne6eb5242010-10-27 15:33:09 -0700379 .proc = s3c_rtc_proc,
380 .alarm_irq_enable = s3c_rtc_setaie,
Ben Dooks1add6782006-07-01 04:36:26 -0700381};
382
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700383static void s3c_rtc_enable(struct s3c_rtc *info, int en)
Ben Dooks1add6782006-07-01 04:36:26 -0700384{
Chanwoo Choid67288d2014-10-13 15:52:31 -0700385 unsigned int con, tmp;
Ben Dooks1add6782006-07-01 04:36:26 -0700386
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700387 clk_enable(info->rtc_clk);
Chanwoo Choid67288d2014-10-13 15:52:31 -0700388
389 con = readw(info->base + S3C2410_RTCCON);
Ben Dooks1add6782006-07-01 04:36:26 -0700390 if (!en) {
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700391 if (info->cpu_type == TYPE_S3C64XX)
Chanwoo Choid67288d2014-10-13 15:52:31 -0700392 con &= ~S3C64XX_RTCCON_TICEN;
393 con &= ~S3C2410_RTCCON_RTCEN;
394 writew(con, info->base + S3C2410_RTCCON);
Ben Dooks1add6782006-07-01 04:36:26 -0700395
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700396 if (info->cpu_type != TYPE_S3C64XX) {
Chanwoo Choid67288d2014-10-13 15:52:31 -0700397 con = readb(info->base + S3C2410_TICNT);
398 con &= ~S3C2410_TICNT_ENABLE;
399 writeb(con, info->base + S3C2410_TICNT);
Maurus Cuelenaere9f4123b2010-05-24 14:33:43 -0700400 }
Ben Dooks1add6782006-07-01 04:36:26 -0700401 } else {
402 /* re-enable the device, and check it is ok */
Chanwoo Choid67288d2014-10-13 15:52:31 -0700403 if ((con & S3C2410_RTCCON_RTCEN) == 0) {
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700404 dev_info(info->dev, "rtc disabled, re-enabling\n");
Ben Dooks1add6782006-07-01 04:36:26 -0700405
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700406 tmp = readw(info->base + S3C2410_RTCCON);
Changhwan Younf61ae672010-10-27 15:33:06 -0700407 writew(tmp | S3C2410_RTCCON_RTCEN,
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700408 info->base + S3C2410_RTCCON);
Ben Dooks1add6782006-07-01 04:36:26 -0700409 }
410
Chanwoo Choid67288d2014-10-13 15:52:31 -0700411 if (con & S3C2410_RTCCON_CNTSEL) {
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700412 dev_info(info->dev, "removing RTCCON_CNTSEL\n");
Ben Dooks1add6782006-07-01 04:36:26 -0700413
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700414 tmp = readw(info->base + S3C2410_RTCCON);
Changhwan Younf61ae672010-10-27 15:33:06 -0700415 writew(tmp & ~S3C2410_RTCCON_CNTSEL,
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700416 info->base + S3C2410_RTCCON);
Ben Dooks1add6782006-07-01 04:36:26 -0700417 }
418
Chanwoo Choid67288d2014-10-13 15:52:31 -0700419 if (con & S3C2410_RTCCON_CLKRST) {
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700420 dev_info(info->dev, "removing RTCCON_CLKRST\n");
Ben Dooks1add6782006-07-01 04:36:26 -0700421
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700422 tmp = readw(info->base + S3C2410_RTCCON);
Changhwan Younf61ae672010-10-27 15:33:06 -0700423 writew(tmp & ~S3C2410_RTCCON_CLKRST,
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700424 info->base + S3C2410_RTCCON);
Ben Dooks1add6782006-07-01 04:36:26 -0700425 }
426 }
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700427 clk_disable(info->rtc_clk);
Ben Dooks1add6782006-07-01 04:36:26 -0700428}
429
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700430static int s3c_rtc_remove(struct platform_device *pdev)
Ben Dooks1add6782006-07-01 04:36:26 -0700431{
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700432 struct s3c_rtc *info = platform_get_drvdata(pdev);
Ben Dooks1add6782006-07-01 04:36:26 -0700433
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700434 s3c_rtc_setaie(info->dev, 0);
435
436 clk_unprepare(info->rtc_clk);
437 info->rtc_clk = NULL;
Atul Dahiyae48add82010-07-20 12:19:14 +0530438
Ben Dooks1add6782006-07-01 04:36:26 -0700439 return 0;
440}
441
Heiko Stuebnerd2524ca2011-12-24 10:52:14 +0900442static const struct of_device_id s3c_rtc_dt_match[];
443
444static inline int s3c_rtc_get_driver_data(struct platform_device *pdev)
445{
446#ifdef CONFIG_OF
Tushar Beherac3cba922012-04-12 12:49:14 -0700447 struct s3c_rtc_drv_data *data;
Chanwoo Choid67288d2014-10-13 15:52:31 -0700448
Heiko Stuebnerd2524ca2011-12-24 10:52:14 +0900449 if (pdev->dev.of_node) {
450 const struct of_device_id *match;
Chanwoo Choid67288d2014-10-13 15:52:31 -0700451
Heiko Stuebnerd2524ca2011-12-24 10:52:14 +0900452 match = of_match_node(s3c_rtc_dt_match, pdev->dev.of_node);
Tushar Beherac3cba922012-04-12 12:49:14 -0700453 data = (struct s3c_rtc_drv_data *) match->data;
454 return data->cpu_type;
Heiko Stuebnerd2524ca2011-12-24 10:52:14 +0900455 }
456#endif
457 return platform_get_device_id(pdev)->driver_data;
458}
459
Greg Kroah-Hartman5a167f42012-12-21 13:09:38 -0800460static int s3c_rtc_probe(struct platform_device *pdev)
Ben Dooks1add6782006-07-01 04:36:26 -0700461{
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700462 struct s3c_rtc *info = NULL;
Changhwan Youne1df9622010-10-27 15:33:10 -0700463 struct rtc_time rtc_tm;
Ben Dooks1add6782006-07-01 04:36:26 -0700464 struct resource *res;
465 int ret;
Heiko Stuebner25c1a242011-12-24 10:52:19 +0900466 int tmp;
Ben Dooks1add6782006-07-01 04:36:26 -0700467
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700468 info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
469 if (!info)
470 return -ENOMEM;
Ben Dooks1add6782006-07-01 04:36:26 -0700471
472 /* find the IRQs */
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700473 info->irq_tick = platform_get_irq(pdev, 1);
474 if (info->irq_tick < 0) {
Ben Dooks1add6782006-07-01 04:36:26 -0700475 dev_err(&pdev->dev, "no irq for rtc tick\n");
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700476 return info->irq_tick;
Ben Dooks1add6782006-07-01 04:36:26 -0700477 }
478
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700479 info->dev = &pdev->dev;
480 info->cpu_type = s3c_rtc_get_driver_data(pdev);
481 spin_lock_init(&info->pie_lock);
482 spin_lock_init(&info->alarm_clk_lock);
483
484 platform_set_drvdata(pdev, info);
485
486 info->irq_alarm = platform_get_irq(pdev, 0);
487 if (info->irq_alarm < 0) {
Ben Dooks1add6782006-07-01 04:36:26 -0700488 dev_err(&pdev->dev, "no irq for alarm\n");
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700489 return info->irq_alarm;
Ben Dooks1add6782006-07-01 04:36:26 -0700490 }
491
Jingoo Hand4a48c22013-02-21 16:45:06 -0800492 dev_dbg(&pdev->dev, "s3c2410_rtc: tick irq %d, alarm irq %d\n",
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700493 info->irq_tick, info->irq_alarm);
Ben Dooks1add6782006-07-01 04:36:26 -0700494
495 /* get the memory region */
Ben Dooks1add6782006-07-01 04:36:26 -0700496 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700497 info->base = devm_ioremap_resource(&pdev->dev, res);
498 if (IS_ERR(info->base))
499 return PTR_ERR(info->base);
Ben Dooks1add6782006-07-01 04:36:26 -0700500
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700501 info->rtc_clk = devm_clk_get(&pdev->dev, "rtc");
502 if (IS_ERR(info->rtc_clk)) {
Atul Dahiyae48add82010-07-20 12:19:14 +0530503 dev_err(&pdev->dev, "failed to find rtc clock source\n");
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700504 return PTR_ERR(info->rtc_clk);
Atul Dahiyae48add82010-07-20 12:19:14 +0530505 }
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700506 clk_prepare_enable(info->rtc_clk);
Atul Dahiyae48add82010-07-20 12:19:14 +0530507
Ben Dooks1add6782006-07-01 04:36:26 -0700508 /* check to see if everything is setup correctly */
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700509 s3c_rtc_enable(info, 1);
Ben Dooks1add6782006-07-01 04:36:26 -0700510
Jingoo Hand4a48c22013-02-21 16:45:06 -0800511 dev_dbg(&pdev->dev, "s3c2410_rtc: RTCCON=%02x\n",
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700512 readw(info->base + S3C2410_RTCCON));
Ben Dooks1add6782006-07-01 04:36:26 -0700513
Yauhen Kharuzhy51b76162008-10-29 14:01:16 -0700514 device_init_wakeup(&pdev->dev, 1);
515
Ben Dooks1add6782006-07-01 04:36:26 -0700516 /* register RTC and exit */
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700517 info->rtc = devm_rtc_device_register(&pdev->dev, "s3c", &s3c_rtcops,
Ben Dooks1add6782006-07-01 04:36:26 -0700518 THIS_MODULE);
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700519 if (IS_ERR(info->rtc)) {
Ben Dooks1add6782006-07-01 04:36:26 -0700520 dev_err(&pdev->dev, "cannot attach rtc\n");
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700521 ret = PTR_ERR(info->rtc);
Ben Dooks1add6782006-07-01 04:36:26 -0700522 goto err_nortc;
523 }
524
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700525 ret = devm_request_irq(&pdev->dev, info->irq_alarm, s3c_rtc_alarmirq,
526 0, "s3c2410-rtc alarm", info);
527 if (ret) {
528 dev_err(&pdev->dev, "IRQ%d error %d\n", info->irq_alarm, ret);
529 goto err_nortc;
530 }
531
532 ret = devm_request_irq(&pdev->dev, info->irq_tick, s3c_rtc_tickirq,
533 0, "s3c2410-rtc tick", info);
534 if (ret) {
535 dev_err(&pdev->dev, "IRQ%d error %d\n", info->irq_tick, ret);
536 goto err_nortc;
537 }
Maurus Cuelenaereeaa6e4d2010-06-04 14:14:46 -0700538
Taekgyun Ko051fe542010-07-29 13:00:42 +0900539 /* Check RTC Time */
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700540 s3c_rtc_gettime(&pdev->dev, &rtc_tm);
Taekgyun Ko051fe542010-07-29 13:00:42 +0900541
Changhwan Youne1df9622010-10-27 15:33:10 -0700542 if (rtc_valid_tm(&rtc_tm)) {
543 rtc_tm.tm_year = 100;
544 rtc_tm.tm_mon = 0;
545 rtc_tm.tm_mday = 1;
546 rtc_tm.tm_hour = 0;
547 rtc_tm.tm_min = 0;
548 rtc_tm.tm_sec = 0;
549
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700550 s3c_rtc_settime(&pdev->dev, &rtc_tm);
Changhwan Youne1df9622010-10-27 15:33:10 -0700551
552 dev_warn(&pdev->dev, "warning: invalid RTC value so initializing it\n");
Taekgyun Ko051fe542010-07-29 13:00:42 +0900553 }
554
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700555 if (info->cpu_type != TYPE_S3C2410)
556 info->rtc->max_user_freq = 32768;
Maurus Cuelenaere9f4123b2010-05-24 14:33:43 -0700557 else
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700558 info->rtc->max_user_freq = 128;
Maurus Cuelenaere9f4123b2010-05-24 14:33:43 -0700559
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700560 if (info->cpu_type == TYPE_S3C2416 || info->cpu_type == TYPE_S3C2443) {
561 tmp = readw(info->base + S3C2410_RTCCON);
Heiko Stuebner25c1a242011-12-24 10:52:19 +0900562 tmp |= S3C2443_RTCCON_TICSEL;
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700563 writew(tmp, info->base + S3C2410_RTCCON);
Heiko Stuebner25c1a242011-12-24 10:52:19 +0900564 }
565
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700566 s3c_rtc_setfreq(info, 1);
Maurus Cuelenaeree893de52010-06-04 14:14:44 -0700567
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700568 clk_disable(info->rtc_clk);
Donggeun Kimcefe4fb2011-07-25 17:13:32 -0700569
Ben Dooks1add6782006-07-01 04:36:26 -0700570 return 0;
571
572 err_nortc:
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700573 s3c_rtc_enable(info, 0);
574 clk_disable_unprepare(info->rtc_clk);
Atul Dahiyae48add82010-07-20 12:19:14 +0530575
Ben Dooks1add6782006-07-01 04:36:26 -0700576 return ret;
577}
578
Jingoo Han32e445a2013-04-29 16:19:27 -0700579#ifdef CONFIG_PM_SLEEP
Ben Dooks1add6782006-07-01 04:36:26 -0700580
Jingoo Han32e445a2013-04-29 16:19:27 -0700581static int s3c_rtc_suspend(struct device *dev)
Ben Dooks1add6782006-07-01 04:36:26 -0700582{
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700583 struct s3c_rtc *info = dev_get_drvdata(dev);
Jingoo Han32e445a2013-04-29 16:19:27 -0700584
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700585 clk_enable(info->rtc_clk);
Ben Dooks1add6782006-07-01 04:36:26 -0700586 /* save TICNT for anyone using periodic interrupts */
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700587 if (info->cpu_type == TYPE_S3C64XX) {
588 info->ticnt_en_save = readw(info->base + S3C2410_RTCCON);
589 info->ticnt_en_save &= S3C64XX_RTCCON_TICEN;
590 info->ticnt_save = readl(info->base + S3C2410_TICNT);
Vikas Sajjan40d2d962014-03-03 15:38:31 -0800591 } else {
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700592 info->ticnt_save = readb(info->base + S3C2410_TICNT);
Maurus Cuelenaere9f4123b2010-05-24 14:33:43 -0700593 }
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700594 s3c_rtc_enable(info, 0);
Vladimir Zapolskiyf501ed52010-09-22 13:05:13 -0700595
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700596 if (device_may_wakeup(dev) && !info->wake_en) {
597 if (enable_irq_wake(info->irq_alarm) == 0)
598 info->wake_en = true;
Ben Dooks52cd4e52011-05-11 15:13:28 -0700599 else
Jingoo Han32e445a2013-04-29 16:19:27 -0700600 dev_err(dev, "enable_irq_wake failed\n");
Ben Dooks52cd4e52011-05-11 15:13:28 -0700601 }
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700602 clk_disable(info->rtc_clk);
Vladimir Zapolskiyf501ed52010-09-22 13:05:13 -0700603
Ben Dooks1add6782006-07-01 04:36:26 -0700604 return 0;
605}
606
Jingoo Han32e445a2013-04-29 16:19:27 -0700607static int s3c_rtc_resume(struct device *dev)
Ben Dooks1add6782006-07-01 04:36:26 -0700608{
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700609 struct s3c_rtc *info = dev_get_drvdata(dev);
Maurus Cuelenaere9f4123b2010-05-24 14:33:43 -0700610 unsigned int tmp;
611
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700612 clk_enable(info->rtc_clk);
613 s3c_rtc_enable(info, 1);
614 if (info->cpu_type == TYPE_S3C64XX) {
615 writel(info->ticnt_save, info->base + S3C2410_TICNT);
616 if (info->ticnt_en_save) {
617 tmp = readw(info->base + S3C2410_RTCCON);
618 writew(tmp | info->ticnt_en_save,
619 info->base + S3C2410_RTCCON);
Vikas Sajjan40d2d962014-03-03 15:38:31 -0800620 }
621 } else {
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700622 writeb(info->ticnt_save, info->base + S3C2410_TICNT);
Maurus Cuelenaere9f4123b2010-05-24 14:33:43 -0700623 }
Vladimir Zapolskiyf501ed52010-09-22 13:05:13 -0700624
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700625 if (device_may_wakeup(dev) && info->wake_en) {
626 disable_irq_wake(info->irq_alarm);
627 info->wake_en = false;
Ben Dooks52cd4e52011-05-11 15:13:28 -0700628 }
Chanwoo Choi19be09f2014-10-13 15:52:28 -0700629 clk_disable(info->rtc_clk);
Vladimir Zapolskiyf501ed52010-09-22 13:05:13 -0700630
Ben Dooks1add6782006-07-01 04:36:26 -0700631 return 0;
632}
Ben Dooks1add6782006-07-01 04:36:26 -0700633#endif
Jingoo Han32e445a2013-04-29 16:19:27 -0700634static SIMPLE_DEV_PM_OPS(s3c_rtc_pm_ops, s3c_rtc_suspend, s3c_rtc_resume);
635
Sachin Kamatecb41a72012-05-29 15:07:40 -0700636#ifdef CONFIG_OF
Tushar Beherac3cba922012-04-12 12:49:14 -0700637static struct s3c_rtc_drv_data s3c_rtc_drv_data_array[] = {
638 [TYPE_S3C2410] = { TYPE_S3C2410 },
639 [TYPE_S3C2416] = { TYPE_S3C2416 },
640 [TYPE_S3C2443] = { TYPE_S3C2443 },
641 [TYPE_S3C64XX] = { TYPE_S3C64XX },
642};
643
Thomas Abraham39ce4082011-10-24 14:49:04 +0200644static const struct of_device_id s3c_rtc_dt_match[] = {
Heiko Stuebnerd2524ca2011-12-24 10:52:14 +0900645 {
Tushar Beheracd1e6f92012-04-12 12:49:14 -0700646 .compatible = "samsung,s3c2410-rtc",
Tushar Beherac3cba922012-04-12 12:49:14 -0700647 .data = &s3c_rtc_drv_data_array[TYPE_S3C2410],
Heiko Stuebnerd2524ca2011-12-24 10:52:14 +0900648 }, {
Tushar Beheracd1e6f92012-04-12 12:49:14 -0700649 .compatible = "samsung,s3c2416-rtc",
Tushar Beherac3cba922012-04-12 12:49:14 -0700650 .data = &s3c_rtc_drv_data_array[TYPE_S3C2416],
Heiko Stuebner25c1a242011-12-24 10:52:19 +0900651 }, {
Tushar Beheracd1e6f92012-04-12 12:49:14 -0700652 .compatible = "samsung,s3c2443-rtc",
Tushar Beherac3cba922012-04-12 12:49:14 -0700653 .data = &s3c_rtc_drv_data_array[TYPE_S3C2443],
Heiko Stuebner25c1a242011-12-24 10:52:19 +0900654 }, {
Tushar Beheracd1e6f92012-04-12 12:49:14 -0700655 .compatible = "samsung,s3c6410-rtc",
Tushar Beherac3cba922012-04-12 12:49:14 -0700656 .data = &s3c_rtc_drv_data_array[TYPE_S3C64XX],
Heiko Stuebnerd2524ca2011-12-24 10:52:14 +0900657 },
Thomas Abraham39ce4082011-10-24 14:49:04 +0200658 {},
659};
660MODULE_DEVICE_TABLE(of, s3c_rtc_dt_match);
Thomas Abraham39ce4082011-10-24 14:49:04 +0200661#endif
662
Maurus Cuelenaere9f4123b2010-05-24 14:33:43 -0700663static struct platform_device_id s3c_rtc_driver_ids[] = {
664 {
665 .name = "s3c2410-rtc",
666 .driver_data = TYPE_S3C2410,
667 }, {
Heiko Stuebner25c1a242011-12-24 10:52:19 +0900668 .name = "s3c2416-rtc",
669 .driver_data = TYPE_S3C2416,
670 }, {
671 .name = "s3c2443-rtc",
672 .driver_data = TYPE_S3C2443,
673 }, {
Maurus Cuelenaere9f4123b2010-05-24 14:33:43 -0700674 .name = "s3c64xx-rtc",
675 .driver_data = TYPE_S3C64XX,
676 },
677 { }
678};
679
680MODULE_DEVICE_TABLE(platform, s3c_rtc_driver_ids);
681
682static struct platform_driver s3c_rtc_driver = {
Ben Dooks1add6782006-07-01 04:36:26 -0700683 .probe = s3c_rtc_probe,
Greg Kroah-Hartman5a167f42012-12-21 13:09:38 -0800684 .remove = s3c_rtc_remove,
Maurus Cuelenaere9f4123b2010-05-24 14:33:43 -0700685 .id_table = s3c_rtc_driver_ids,
Ben Dooks1add6782006-07-01 04:36:26 -0700686 .driver = {
Maurus Cuelenaere9f4123b2010-05-24 14:33:43 -0700687 .name = "s3c-rtc",
Ben Dooks1add6782006-07-01 04:36:26 -0700688 .owner = THIS_MODULE,
Jingoo Han32e445a2013-04-29 16:19:27 -0700689 .pm = &s3c_rtc_pm_ops,
Sachin Kamat04a373f2012-12-17 16:02:52 -0800690 .of_match_table = of_match_ptr(s3c_rtc_dt_match),
Ben Dooks1add6782006-07-01 04:36:26 -0700691 },
692};
693
Axel Lin0c4eae62012-01-10 15:10:48 -0800694module_platform_driver(s3c_rtc_driver);
Ben Dooks1add6782006-07-01 04:36:26 -0700695
696MODULE_DESCRIPTION("Samsung S3C RTC Driver");
697MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
698MODULE_LICENSE("GPL");
Kay Sieversad28a072008-04-10 21:29:25 -0700699MODULE_ALIAS("platform:s3c2410-rtc");