1 /* drivers/rtc/rtc-s3c.c
3 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com/
6 * Copyright (c) 2004,2006 Simtec Electronics
7 * Ben Dooks, <ben@simtec.co.uk>
8 * http://armlinux.simtec.co.uk/
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.
14 * S3C2410/S3C2440/S3C24XX Internal RTC Driver
17 #include <linux/module.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>
26 #include <linux/log2.h>
27 #include <linux/slab.h>
29 #include <linux/uaccess.h>
37 struct rtc_device
*rtc
;
41 struct clk
*rtc_src_clk
;
44 const struct s3c_rtc_data
*data
;
50 spinlock_t alarm_clk_lock
;
61 void (*irq_handler
) (struct s3c_rtc
*info
, int mask
);
62 void (*set_freq
) (struct s3c_rtc
*info
, int freq
);
63 void (*enable_tick
) (struct s3c_rtc
*info
, struct seq_file
*seq
);
64 void (*select_tick_clk
) (struct s3c_rtc
*info
);
65 void (*save_tick_cnt
) (struct s3c_rtc
*info
);
66 void (*restore_tick_cnt
) (struct s3c_rtc
*info
);
67 void (*enable
) (struct s3c_rtc
*info
);
68 void (*disable
) (struct s3c_rtc
*info
);
71 static int s3c_rtc_enable_clk(struct s3c_rtc
*info
)
73 unsigned long irq_flags
;
76 spin_lock_irqsave(&info
->alarm_clk_lock
, irq_flags
);
78 if (info
->clk_disabled
) {
79 ret
= clk_enable(info
->rtc_clk
);
83 if (info
->data
->needs_src_clk
) {
84 ret
= clk_enable(info
->rtc_src_clk
);
86 clk_disable(info
->rtc_clk
);
90 info
->clk_disabled
= false;
94 spin_unlock_irqrestore(&info
->alarm_clk_lock
, irq_flags
);
99 static void s3c_rtc_disable_clk(struct s3c_rtc
*info
)
101 unsigned long irq_flags
;
103 spin_lock_irqsave(&info
->alarm_clk_lock
, irq_flags
);
104 if (!info
->clk_disabled
) {
105 if (info
->data
->needs_src_clk
)
106 clk_disable(info
->rtc_src_clk
);
107 clk_disable(info
->rtc_clk
);
108 info
->clk_disabled
= true;
110 spin_unlock_irqrestore(&info
->alarm_clk_lock
, irq_flags
);
114 static irqreturn_t
s3c_rtc_tickirq(int irq
, void *id
)
116 struct s3c_rtc
*info
= (struct s3c_rtc
*)id
;
118 if (info
->data
->irq_handler
)
119 info
->data
->irq_handler(info
, S3C2410_INTP_TIC
);
124 static irqreturn_t
s3c_rtc_alarmirq(int irq
, void *id
)
126 struct s3c_rtc
*info
= (struct s3c_rtc
*)id
;
128 if (info
->data
->irq_handler
)
129 info
->data
->irq_handler(info
, S3C2410_INTP_ALM
);
134 /* Update control registers */
135 static int s3c_rtc_setaie(struct device
*dev
, unsigned int enabled
)
137 struct s3c_rtc
*info
= dev_get_drvdata(dev
);
141 dev_dbg(info
->dev
, "%s: aie=%d\n", __func__
, enabled
);
143 ret
= s3c_rtc_enable_clk(info
);
147 tmp
= readb(info
->base
+ S3C2410_RTCALM
) & ~S3C2410_RTCALM_ALMEN
;
150 tmp
|= S3C2410_RTCALM_ALMEN
;
152 writeb(tmp
, info
->base
+ S3C2410_RTCALM
);
154 s3c_rtc_disable_clk(info
);
157 ret
= s3c_rtc_enable_clk(info
);
161 s3c_rtc_disable_clk(info
);
167 /* Set RTC frequency */
168 static int s3c_rtc_setfreq(struct s3c_rtc
*info
, int freq
)
172 if (!is_power_of_2(freq
))
175 ret
= s3c_rtc_enable_clk(info
);
178 spin_lock_irq(&info
->pie_lock
);
180 if (info
->data
->set_freq
)
181 info
->data
->set_freq(info
, freq
);
183 spin_unlock_irq(&info
->pie_lock
);
184 s3c_rtc_disable_clk(info
);
189 /* Time read/write */
190 static int s3c_rtc_gettime(struct device
*dev
, struct rtc_time
*rtc_tm
)
192 struct s3c_rtc
*info
= dev_get_drvdata(dev
);
193 unsigned int have_retried
= 0;
196 ret
= s3c_rtc_enable_clk(info
);
201 rtc_tm
->tm_min
= readb(info
->base
+ S3C2410_RTCMIN
);
202 rtc_tm
->tm_hour
= readb(info
->base
+ S3C2410_RTCHOUR
);
203 rtc_tm
->tm_mday
= readb(info
->base
+ S3C2410_RTCDATE
);
204 rtc_tm
->tm_mon
= readb(info
->base
+ S3C2410_RTCMON
);
205 rtc_tm
->tm_year
= readb(info
->base
+ S3C2410_RTCYEAR
);
206 rtc_tm
->tm_sec
= readb(info
->base
+ S3C2410_RTCSEC
);
208 /* the only way to work out whether the system was mid-update
209 * when we read it is to check the second counter, and if it
210 * is zero, then we re-try the entire read
213 if (rtc_tm
->tm_sec
== 0 && !have_retried
) {
218 rtc_tm
->tm_sec
= bcd2bin(rtc_tm
->tm_sec
);
219 rtc_tm
->tm_min
= bcd2bin(rtc_tm
->tm_min
);
220 rtc_tm
->tm_hour
= bcd2bin(rtc_tm
->tm_hour
);
221 rtc_tm
->tm_mday
= bcd2bin(rtc_tm
->tm_mday
);
222 rtc_tm
->tm_mon
= bcd2bin(rtc_tm
->tm_mon
);
223 rtc_tm
->tm_year
= bcd2bin(rtc_tm
->tm_year
);
225 s3c_rtc_disable_clk(info
);
227 rtc_tm
->tm_year
+= 100;
229 dev_dbg(dev
, "read time %04d.%02d.%02d %02d:%02d:%02d\n",
230 1900 + rtc_tm
->tm_year
, rtc_tm
->tm_mon
, rtc_tm
->tm_mday
,
231 rtc_tm
->tm_hour
, rtc_tm
->tm_min
, rtc_tm
->tm_sec
);
238 static int s3c_rtc_settime(struct device
*dev
, struct rtc_time
*tm
)
240 struct s3c_rtc
*info
= dev_get_drvdata(dev
);
241 int year
= tm
->tm_year
- 100;
244 dev_dbg(dev
, "set time %04d.%02d.%02d %02d:%02d:%02d\n",
245 1900 + tm
->tm_year
, tm
->tm_mon
, tm
->tm_mday
,
246 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
248 /* we get around y2k by simply not supporting it */
250 if (year
< 0 || year
>= 100) {
251 dev_err(dev
, "rtc only supports 100 years\n");
255 ret
= s3c_rtc_enable_clk(info
);
259 writeb(bin2bcd(tm
->tm_sec
), info
->base
+ S3C2410_RTCSEC
);
260 writeb(bin2bcd(tm
->tm_min
), info
->base
+ S3C2410_RTCMIN
);
261 writeb(bin2bcd(tm
->tm_hour
), info
->base
+ S3C2410_RTCHOUR
);
262 writeb(bin2bcd(tm
->tm_mday
), info
->base
+ S3C2410_RTCDATE
);
263 writeb(bin2bcd(tm
->tm_mon
+ 1), info
->base
+ S3C2410_RTCMON
);
264 writeb(bin2bcd(year
), info
->base
+ S3C2410_RTCYEAR
);
266 s3c_rtc_disable_clk(info
);
271 static int s3c_rtc_getalarm(struct device
*dev
, struct rtc_wkalrm
*alrm
)
273 struct s3c_rtc
*info
= dev_get_drvdata(dev
);
274 struct rtc_time
*alm_tm
= &alrm
->time
;
278 ret
= s3c_rtc_enable_clk(info
);
282 alm_tm
->tm_sec
= readb(info
->base
+ S3C2410_ALMSEC
);
283 alm_tm
->tm_min
= readb(info
->base
+ S3C2410_ALMMIN
);
284 alm_tm
->tm_hour
= readb(info
->base
+ S3C2410_ALMHOUR
);
285 alm_tm
->tm_mon
= readb(info
->base
+ S3C2410_ALMMON
);
286 alm_tm
->tm_mday
= readb(info
->base
+ S3C2410_ALMDATE
);
287 alm_tm
->tm_year
= readb(info
->base
+ S3C2410_ALMYEAR
);
289 alm_en
= readb(info
->base
+ S3C2410_RTCALM
);
291 s3c_rtc_disable_clk(info
);
293 alrm
->enabled
= (alm_en
& S3C2410_RTCALM_ALMEN
) ? 1 : 0;
295 dev_dbg(dev
, "read alarm %d, %04d.%02d.%02d %02d:%02d:%02d\n",
297 1900 + alm_tm
->tm_year
, alm_tm
->tm_mon
, alm_tm
->tm_mday
,
298 alm_tm
->tm_hour
, alm_tm
->tm_min
, alm_tm
->tm_sec
);
300 /* decode the alarm enable field */
301 if (alm_en
& S3C2410_RTCALM_SECEN
)
302 alm_tm
->tm_sec
= bcd2bin(alm_tm
->tm_sec
);
304 if (alm_en
& S3C2410_RTCALM_MINEN
)
305 alm_tm
->tm_min
= bcd2bin(alm_tm
->tm_min
);
307 if (alm_en
& S3C2410_RTCALM_HOUREN
)
308 alm_tm
->tm_hour
= bcd2bin(alm_tm
->tm_hour
);
310 if (alm_en
& S3C2410_RTCALM_DAYEN
)
311 alm_tm
->tm_mday
= bcd2bin(alm_tm
->tm_mday
);
313 if (alm_en
& S3C2410_RTCALM_MONEN
) {
314 alm_tm
->tm_mon
= bcd2bin(alm_tm
->tm_mon
);
318 if (alm_en
& S3C2410_RTCALM_YEAREN
)
319 alm_tm
->tm_year
= bcd2bin(alm_tm
->tm_year
);
324 static int s3c_rtc_setalarm(struct device
*dev
, struct rtc_wkalrm
*alrm
)
326 struct s3c_rtc
*info
= dev_get_drvdata(dev
);
327 struct rtc_time
*tm
= &alrm
->time
;
328 unsigned int alrm_en
;
331 dev_dbg(dev
, "s3c_rtc_setalarm: %d, %04d.%02d.%02d %02d:%02d:%02d\n",
333 1900 + tm
->tm_year
, tm
->tm_mon
+ 1, tm
->tm_mday
,
334 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
336 ret
= s3c_rtc_enable_clk(info
);
340 alrm_en
= readb(info
->base
+ S3C2410_RTCALM
) & S3C2410_RTCALM_ALMEN
;
341 writeb(0x00, info
->base
+ S3C2410_RTCALM
);
343 if (tm
->tm_sec
< 60 && tm
->tm_sec
>= 0) {
344 alrm_en
|= S3C2410_RTCALM_SECEN
;
345 writeb(bin2bcd(tm
->tm_sec
), info
->base
+ S3C2410_ALMSEC
);
348 if (tm
->tm_min
< 60 && tm
->tm_min
>= 0) {
349 alrm_en
|= S3C2410_RTCALM_MINEN
;
350 writeb(bin2bcd(tm
->tm_min
), info
->base
+ S3C2410_ALMMIN
);
353 if (tm
->tm_hour
< 24 && tm
->tm_hour
>= 0) {
354 alrm_en
|= S3C2410_RTCALM_HOUREN
;
355 writeb(bin2bcd(tm
->tm_hour
), info
->base
+ S3C2410_ALMHOUR
);
358 if (tm
->tm_mon
< 12 && tm
->tm_mon
>= 0) {
359 alrm_en
|= S3C2410_RTCALM_MONEN
;
360 writeb(bin2bcd(tm
->tm_mon
+ 1), info
->base
+ S3C2410_ALMMON
);
363 if (tm
->tm_mday
<= 31 && tm
->tm_mday
>= 1) {
364 alrm_en
|= S3C2410_RTCALM_DAYEN
;
365 writeb(bin2bcd(tm
->tm_mday
), info
->base
+ S3C2410_ALMDATE
);
368 dev_dbg(dev
, "setting S3C2410_RTCALM to %08x\n", alrm_en
);
370 writeb(alrm_en
, info
->base
+ S3C2410_RTCALM
);
372 s3c_rtc_disable_clk(info
);
374 s3c_rtc_setaie(dev
, alrm
->enabled
);
379 static int s3c_rtc_proc(struct device
*dev
, struct seq_file
*seq
)
381 struct s3c_rtc
*info
= dev_get_drvdata(dev
);
384 ret
= s3c_rtc_enable_clk(info
);
388 if (info
->data
->enable_tick
)
389 info
->data
->enable_tick(info
, seq
);
391 s3c_rtc_disable_clk(info
);
396 static const struct rtc_class_ops s3c_rtcops
= {
397 .read_time
= s3c_rtc_gettime
,
398 .set_time
= s3c_rtc_settime
,
399 .read_alarm
= s3c_rtc_getalarm
,
400 .set_alarm
= s3c_rtc_setalarm
,
401 .proc
= s3c_rtc_proc
,
402 .alarm_irq_enable
= s3c_rtc_setaie
,
405 static void s3c24xx_rtc_enable(struct s3c_rtc
*info
)
407 unsigned int con
, tmp
;
409 con
= readw(info
->base
+ S3C2410_RTCCON
);
410 /* re-enable the device, and check it is ok */
411 if ((con
& S3C2410_RTCCON_RTCEN
) == 0) {
412 dev_info(info
->dev
, "rtc disabled, re-enabling\n");
414 tmp
= readw(info
->base
+ S3C2410_RTCCON
);
415 writew(tmp
| S3C2410_RTCCON_RTCEN
, info
->base
+ S3C2410_RTCCON
);
418 if (con
& S3C2410_RTCCON_CNTSEL
) {
419 dev_info(info
->dev
, "removing RTCCON_CNTSEL\n");
421 tmp
= readw(info
->base
+ S3C2410_RTCCON
);
422 writew(tmp
& ~S3C2410_RTCCON_CNTSEL
,
423 info
->base
+ S3C2410_RTCCON
);
426 if (con
& S3C2410_RTCCON_CLKRST
) {
427 dev_info(info
->dev
, "removing RTCCON_CLKRST\n");
429 tmp
= readw(info
->base
+ S3C2410_RTCCON
);
430 writew(tmp
& ~S3C2410_RTCCON_CLKRST
,
431 info
->base
+ S3C2410_RTCCON
);
435 static void s3c24xx_rtc_disable(struct s3c_rtc
*info
)
439 con
= readw(info
->base
+ S3C2410_RTCCON
);
440 con
&= ~S3C2410_RTCCON_RTCEN
;
441 writew(con
, info
->base
+ S3C2410_RTCCON
);
443 con
= readb(info
->base
+ S3C2410_TICNT
);
444 con
&= ~S3C2410_TICNT_ENABLE
;
445 writeb(con
, info
->base
+ S3C2410_TICNT
);
448 static void s3c6410_rtc_disable(struct s3c_rtc
*info
)
452 con
= readw(info
->base
+ S3C2410_RTCCON
);
453 con
&= ~S3C64XX_RTCCON_TICEN
;
454 con
&= ~S3C2410_RTCCON_RTCEN
;
455 writew(con
, info
->base
+ S3C2410_RTCCON
);
458 static int s3c_rtc_remove(struct platform_device
*pdev
)
460 struct s3c_rtc
*info
= platform_get_drvdata(pdev
);
462 s3c_rtc_setaie(info
->dev
, 0);
464 if (info
->data
->needs_src_clk
)
465 clk_unprepare(info
->rtc_src_clk
);
466 clk_unprepare(info
->rtc_clk
);
471 static const struct of_device_id s3c_rtc_dt_match
[];
473 static const struct s3c_rtc_data
*s3c_rtc_get_data(struct platform_device
*pdev
)
475 const struct of_device_id
*match
;
477 match
= of_match_node(s3c_rtc_dt_match
, pdev
->dev
.of_node
);
481 static int s3c_rtc_probe(struct platform_device
*pdev
)
483 struct s3c_rtc
*info
= NULL
;
484 struct rtc_time rtc_tm
;
485 struct resource
*res
;
488 info
= devm_kzalloc(&pdev
->dev
, sizeof(*info
), GFP_KERNEL
);
493 info
->irq_tick
= platform_get_irq(pdev
, 1);
494 if (info
->irq_tick
< 0) {
495 dev_err(&pdev
->dev
, "no irq for rtc tick\n");
496 return info
->irq_tick
;
499 info
->dev
= &pdev
->dev
;
500 info
->data
= s3c_rtc_get_data(pdev
);
502 dev_err(&pdev
->dev
, "failed getting s3c_rtc_data\n");
505 spin_lock_init(&info
->pie_lock
);
506 spin_lock_init(&info
->alarm_clk_lock
);
508 platform_set_drvdata(pdev
, info
);
510 info
->irq_alarm
= platform_get_irq(pdev
, 0);
511 if (info
->irq_alarm
< 0) {
512 dev_err(&pdev
->dev
, "no irq for alarm\n");
513 return info
->irq_alarm
;
516 dev_dbg(&pdev
->dev
, "s3c2410_rtc: tick irq %d, alarm irq %d\n",
517 info
->irq_tick
, info
->irq_alarm
);
519 /* get the memory region */
520 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
521 info
->base
= devm_ioremap_resource(&pdev
->dev
, res
);
522 if (IS_ERR(info
->base
))
523 return PTR_ERR(info
->base
);
525 info
->rtc_clk
= devm_clk_get(&pdev
->dev
, "rtc");
526 if (IS_ERR(info
->rtc_clk
)) {
527 ret
= PTR_ERR(info
->rtc_clk
);
528 if (ret
!= -EPROBE_DEFER
)
529 dev_err(&pdev
->dev
, "failed to find rtc clock\n");
531 dev_dbg(&pdev
->dev
, "probe deferred due to missing rtc clk\n");
534 ret
= clk_prepare_enable(info
->rtc_clk
);
538 if (info
->data
->needs_src_clk
) {
539 info
->rtc_src_clk
= devm_clk_get(&pdev
->dev
, "rtc_src");
540 if (IS_ERR(info
->rtc_src_clk
)) {
541 ret
= PTR_ERR(info
->rtc_src_clk
);
542 if (ret
!= -EPROBE_DEFER
)
544 "failed to find rtc source clock\n");
547 "probe deferred due to missing rtc src clk\n");
550 ret
= clk_prepare_enable(info
->rtc_src_clk
);
555 /* check to see if everything is setup correctly */
556 if (info
->data
->enable
)
557 info
->data
->enable(info
);
559 dev_dbg(&pdev
->dev
, "s3c2410_rtc: RTCCON=%02x\n",
560 readw(info
->base
+ S3C2410_RTCCON
));
562 device_init_wakeup(&pdev
->dev
, 1);
565 if (s3c_rtc_gettime(&pdev
->dev
, &rtc_tm
)) {
566 rtc_tm
.tm_year
= 100;
573 s3c_rtc_settime(&pdev
->dev
, &rtc_tm
);
575 dev_warn(&pdev
->dev
, "warning: invalid RTC value so initializing it\n");
578 /* register RTC and exit */
579 info
->rtc
= devm_rtc_device_register(&pdev
->dev
, "s3c", &s3c_rtcops
,
581 if (IS_ERR(info
->rtc
)) {
582 dev_err(&pdev
->dev
, "cannot attach rtc\n");
583 ret
= PTR_ERR(info
->rtc
);
587 ret
= devm_request_irq(&pdev
->dev
, info
->irq_alarm
, s3c_rtc_alarmirq
,
588 0, "s3c2410-rtc alarm", info
);
590 dev_err(&pdev
->dev
, "IRQ%d error %d\n", info
->irq_alarm
, ret
);
594 ret
= devm_request_irq(&pdev
->dev
, info
->irq_tick
, s3c_rtc_tickirq
,
595 0, "s3c2410-rtc tick", info
);
597 dev_err(&pdev
->dev
, "IRQ%d error %d\n", info
->irq_tick
, ret
);
601 if (info
->data
->select_tick_clk
)
602 info
->data
->select_tick_clk(info
);
604 s3c_rtc_setfreq(info
, 1);
609 if (info
->data
->disable
)
610 info
->data
->disable(info
);
612 if (info
->data
->needs_src_clk
)
613 clk_disable_unprepare(info
->rtc_src_clk
);
615 clk_disable_unprepare(info
->rtc_clk
);
620 #ifdef CONFIG_PM_SLEEP
622 static int s3c_rtc_suspend(struct device
*dev
)
624 struct s3c_rtc
*info
= dev_get_drvdata(dev
);
627 ret
= s3c_rtc_enable_clk(info
);
631 /* save TICNT for anyone using periodic interrupts */
632 if (info
->data
->save_tick_cnt
)
633 info
->data
->save_tick_cnt(info
);
635 if (info
->data
->disable
)
636 info
->data
->disable(info
);
638 if (device_may_wakeup(dev
) && !info
->wake_en
) {
639 if (enable_irq_wake(info
->irq_alarm
) == 0)
640 info
->wake_en
= true;
642 dev_err(dev
, "enable_irq_wake failed\n");
648 static int s3c_rtc_resume(struct device
*dev
)
650 struct s3c_rtc
*info
= dev_get_drvdata(dev
);
652 if (info
->data
->enable
)
653 info
->data
->enable(info
);
655 if (info
->data
->restore_tick_cnt
)
656 info
->data
->restore_tick_cnt(info
);
658 s3c_rtc_disable_clk(info
);
660 if (device_may_wakeup(dev
) && info
->wake_en
) {
661 disable_irq_wake(info
->irq_alarm
);
662 info
->wake_en
= false;
668 static SIMPLE_DEV_PM_OPS(s3c_rtc_pm_ops
, s3c_rtc_suspend
, s3c_rtc_resume
);
670 static void s3c24xx_rtc_irq(struct s3c_rtc
*info
, int mask
)
672 rtc_update_irq(info
->rtc
, 1, RTC_AF
| RTC_IRQF
);
675 static void s3c6410_rtc_irq(struct s3c_rtc
*info
, int mask
)
677 rtc_update_irq(info
->rtc
, 1, RTC_AF
| RTC_IRQF
);
678 writeb(mask
, info
->base
+ S3C2410_INTP
);
681 static void s3c2410_rtc_setfreq(struct s3c_rtc
*info
, int freq
)
683 unsigned int tmp
= 0;
686 tmp
= readb(info
->base
+ S3C2410_TICNT
);
687 tmp
&= S3C2410_TICNT_ENABLE
;
689 val
= (info
->rtc
->max_user_freq
/ freq
) - 1;
692 writel(tmp
, info
->base
+ S3C2410_TICNT
);
695 static void s3c2416_rtc_setfreq(struct s3c_rtc
*info
, int freq
)
697 unsigned int tmp
= 0;
700 tmp
= readb(info
->base
+ S3C2410_TICNT
);
701 tmp
&= S3C2410_TICNT_ENABLE
;
703 val
= (info
->rtc
->max_user_freq
/ freq
) - 1;
705 tmp
|= S3C2443_TICNT_PART(val
);
706 writel(S3C2443_TICNT1_PART(val
), info
->base
+ S3C2443_TICNT1
);
708 writel(S3C2416_TICNT2_PART(val
), info
->base
+ S3C2416_TICNT2
);
710 writel(tmp
, info
->base
+ S3C2410_TICNT
);
713 static void s3c2443_rtc_setfreq(struct s3c_rtc
*info
, int freq
)
715 unsigned int tmp
= 0;
718 tmp
= readb(info
->base
+ S3C2410_TICNT
);
719 tmp
&= S3C2410_TICNT_ENABLE
;
721 val
= (info
->rtc
->max_user_freq
/ freq
) - 1;
723 tmp
|= S3C2443_TICNT_PART(val
);
724 writel(S3C2443_TICNT1_PART(val
), info
->base
+ S3C2443_TICNT1
);
726 writel(tmp
, info
->base
+ S3C2410_TICNT
);
729 static void s3c6410_rtc_setfreq(struct s3c_rtc
*info
, int freq
)
733 val
= (info
->rtc
->max_user_freq
/ freq
) - 1;
734 writel(val
, info
->base
+ S3C2410_TICNT
);
737 static void s3c24xx_rtc_enable_tick(struct s3c_rtc
*info
, struct seq_file
*seq
)
741 ticnt
= readb(info
->base
+ S3C2410_TICNT
);
742 ticnt
&= S3C2410_TICNT_ENABLE
;
744 seq_printf(seq
, "periodic_IRQ\t: %s\n", ticnt
? "yes" : "no");
747 static void s3c2416_rtc_select_tick_clk(struct s3c_rtc
*info
)
751 con
= readw(info
->base
+ S3C2410_RTCCON
);
752 con
|= S3C2443_RTCCON_TICSEL
;
753 writew(con
, info
->base
+ S3C2410_RTCCON
);
756 static void s3c6410_rtc_enable_tick(struct s3c_rtc
*info
, struct seq_file
*seq
)
760 ticnt
= readw(info
->base
+ S3C2410_RTCCON
);
761 ticnt
&= S3C64XX_RTCCON_TICEN
;
763 seq_printf(seq
, "periodic_IRQ\t: %s\n", ticnt
? "yes" : "no");
766 static void s3c24xx_rtc_save_tick_cnt(struct s3c_rtc
*info
)
768 info
->ticnt_save
= readb(info
->base
+ S3C2410_TICNT
);
771 static void s3c24xx_rtc_restore_tick_cnt(struct s3c_rtc
*info
)
773 writeb(info
->ticnt_save
, info
->base
+ S3C2410_TICNT
);
776 static void s3c6410_rtc_save_tick_cnt(struct s3c_rtc
*info
)
778 info
->ticnt_en_save
= readw(info
->base
+ S3C2410_RTCCON
);
779 info
->ticnt_en_save
&= S3C64XX_RTCCON_TICEN
;
780 info
->ticnt_save
= readl(info
->base
+ S3C2410_TICNT
);
783 static void s3c6410_rtc_restore_tick_cnt(struct s3c_rtc
*info
)
787 writel(info
->ticnt_save
, info
->base
+ S3C2410_TICNT
);
788 if (info
->ticnt_en_save
) {
789 con
= readw(info
->base
+ S3C2410_RTCCON
);
790 writew(con
| info
->ticnt_en_save
, info
->base
+ S3C2410_RTCCON
);
794 static struct s3c_rtc_data
const s3c2410_rtc_data
= {
795 .max_user_freq
= 128,
796 .irq_handler
= s3c24xx_rtc_irq
,
797 .set_freq
= s3c2410_rtc_setfreq
,
798 .enable_tick
= s3c24xx_rtc_enable_tick
,
799 .save_tick_cnt
= s3c24xx_rtc_save_tick_cnt
,
800 .restore_tick_cnt
= s3c24xx_rtc_restore_tick_cnt
,
801 .enable
= s3c24xx_rtc_enable
,
802 .disable
= s3c24xx_rtc_disable
,
805 static struct s3c_rtc_data
const s3c2416_rtc_data
= {
806 .max_user_freq
= 32768,
807 .irq_handler
= s3c24xx_rtc_irq
,
808 .set_freq
= s3c2416_rtc_setfreq
,
809 .enable_tick
= s3c24xx_rtc_enable_tick
,
810 .select_tick_clk
= s3c2416_rtc_select_tick_clk
,
811 .save_tick_cnt
= s3c24xx_rtc_save_tick_cnt
,
812 .restore_tick_cnt
= s3c24xx_rtc_restore_tick_cnt
,
813 .enable
= s3c24xx_rtc_enable
,
814 .disable
= s3c24xx_rtc_disable
,
817 static struct s3c_rtc_data
const s3c2443_rtc_data
= {
818 .max_user_freq
= 32768,
819 .irq_handler
= s3c24xx_rtc_irq
,
820 .set_freq
= s3c2443_rtc_setfreq
,
821 .enable_tick
= s3c24xx_rtc_enable_tick
,
822 .select_tick_clk
= s3c2416_rtc_select_tick_clk
,
823 .save_tick_cnt
= s3c24xx_rtc_save_tick_cnt
,
824 .restore_tick_cnt
= s3c24xx_rtc_restore_tick_cnt
,
825 .enable
= s3c24xx_rtc_enable
,
826 .disable
= s3c24xx_rtc_disable
,
829 static struct s3c_rtc_data
const s3c6410_rtc_data
= {
830 .max_user_freq
= 32768,
831 .needs_src_clk
= true,
832 .irq_handler
= s3c6410_rtc_irq
,
833 .set_freq
= s3c6410_rtc_setfreq
,
834 .enable_tick
= s3c6410_rtc_enable_tick
,
835 .save_tick_cnt
= s3c6410_rtc_save_tick_cnt
,
836 .restore_tick_cnt
= s3c6410_rtc_restore_tick_cnt
,
837 .enable
= s3c24xx_rtc_enable
,
838 .disable
= s3c6410_rtc_disable
,
841 static const struct of_device_id s3c_rtc_dt_match
[] = {
843 .compatible
= "samsung,s3c2410-rtc",
844 .data
= &s3c2410_rtc_data
,
846 .compatible
= "samsung,s3c2416-rtc",
847 .data
= &s3c2416_rtc_data
,
849 .compatible
= "samsung,s3c2443-rtc",
850 .data
= &s3c2443_rtc_data
,
852 .compatible
= "samsung,s3c6410-rtc",
853 .data
= &s3c6410_rtc_data
,
855 .compatible
= "samsung,exynos3250-rtc",
856 .data
= &s3c6410_rtc_data
,
860 MODULE_DEVICE_TABLE(of
, s3c_rtc_dt_match
);
862 static struct platform_driver s3c_rtc_driver
= {
863 .probe
= s3c_rtc_probe
,
864 .remove
= s3c_rtc_remove
,
867 .pm
= &s3c_rtc_pm_ops
,
868 .of_match_table
= of_match_ptr(s3c_rtc_dt_match
),
871 module_platform_driver(s3c_rtc_driver
);
873 MODULE_DESCRIPTION("Samsung S3C RTC Driver");
874 MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
875 MODULE_LICENSE("GPL");
876 MODULE_ALIAS("platform:s3c2410-rtc");