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
;
330 int year
= tm
->tm_year
- 100;
332 dev_dbg(dev
, "s3c_rtc_setalarm: %d, %04d.%02d.%02d %02d:%02d:%02d\n",
334 1900 + tm
->tm_year
, tm
->tm_mon
+ 1, tm
->tm_mday
,
335 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
337 ret
= s3c_rtc_enable_clk(info
);
341 alrm_en
= readb(info
->base
+ S3C2410_RTCALM
) & S3C2410_RTCALM_ALMEN
;
342 writeb(0x00, info
->base
+ S3C2410_RTCALM
);
344 if (tm
->tm_sec
< 60 && tm
->tm_sec
>= 0) {
345 alrm_en
|= S3C2410_RTCALM_SECEN
;
346 writeb(bin2bcd(tm
->tm_sec
), info
->base
+ S3C2410_ALMSEC
);
349 if (tm
->tm_min
< 60 && tm
->tm_min
>= 0) {
350 alrm_en
|= S3C2410_RTCALM_MINEN
;
351 writeb(bin2bcd(tm
->tm_min
), info
->base
+ S3C2410_ALMMIN
);
354 if (tm
->tm_hour
< 24 && tm
->tm_hour
>= 0) {
355 alrm_en
|= S3C2410_RTCALM_HOUREN
;
356 writeb(bin2bcd(tm
->tm_hour
), info
->base
+ S3C2410_ALMHOUR
);
359 if (year
< 100 && year
>= 0) {
360 alrm_en
|= S3C2410_RTCALM_YEAREN
;
361 writeb(bin2bcd(year
), info
->base
+ S3C2410_ALMYEAR
);
364 if (tm
->tm_mon
< 12 && tm
->tm_mon
>= 0) {
365 alrm_en
|= S3C2410_RTCALM_MONEN
;
366 writeb(bin2bcd(tm
->tm_mon
+ 1), info
->base
+ S3C2410_ALMMON
);
369 if (tm
->tm_mday
<= 31 && tm
->tm_mday
>= 1) {
370 alrm_en
|= S3C2410_RTCALM_DAYEN
;
371 writeb(bin2bcd(tm
->tm_mday
), info
->base
+ S3C2410_ALMDATE
);
374 dev_dbg(dev
, "setting S3C2410_RTCALM to %08x\n", alrm_en
);
376 writeb(alrm_en
, info
->base
+ S3C2410_RTCALM
);
378 s3c_rtc_disable_clk(info
);
380 s3c_rtc_setaie(dev
, alrm
->enabled
);
385 static int s3c_rtc_proc(struct device
*dev
, struct seq_file
*seq
)
387 struct s3c_rtc
*info
= dev_get_drvdata(dev
);
390 ret
= s3c_rtc_enable_clk(info
);
394 if (info
->data
->enable_tick
)
395 info
->data
->enable_tick(info
, seq
);
397 s3c_rtc_disable_clk(info
);
402 static const struct rtc_class_ops s3c_rtcops
= {
403 .read_time
= s3c_rtc_gettime
,
404 .set_time
= s3c_rtc_settime
,
405 .read_alarm
= s3c_rtc_getalarm
,
406 .set_alarm
= s3c_rtc_setalarm
,
407 .proc
= s3c_rtc_proc
,
408 .alarm_irq_enable
= s3c_rtc_setaie
,
411 static void s3c24xx_rtc_enable(struct s3c_rtc
*info
)
413 unsigned int con
, tmp
;
415 con
= readw(info
->base
+ S3C2410_RTCCON
);
416 /* re-enable the device, and check it is ok */
417 if ((con
& S3C2410_RTCCON_RTCEN
) == 0) {
418 dev_info(info
->dev
, "rtc disabled, re-enabling\n");
420 tmp
= readw(info
->base
+ S3C2410_RTCCON
);
421 writew(tmp
| S3C2410_RTCCON_RTCEN
, info
->base
+ S3C2410_RTCCON
);
424 if (con
& S3C2410_RTCCON_CNTSEL
) {
425 dev_info(info
->dev
, "removing RTCCON_CNTSEL\n");
427 tmp
= readw(info
->base
+ S3C2410_RTCCON
);
428 writew(tmp
& ~S3C2410_RTCCON_CNTSEL
,
429 info
->base
+ S3C2410_RTCCON
);
432 if (con
& S3C2410_RTCCON_CLKRST
) {
433 dev_info(info
->dev
, "removing RTCCON_CLKRST\n");
435 tmp
= readw(info
->base
+ S3C2410_RTCCON
);
436 writew(tmp
& ~S3C2410_RTCCON_CLKRST
,
437 info
->base
+ S3C2410_RTCCON
);
441 static void s3c24xx_rtc_disable(struct s3c_rtc
*info
)
445 con
= readw(info
->base
+ S3C2410_RTCCON
);
446 con
&= ~S3C2410_RTCCON_RTCEN
;
447 writew(con
, info
->base
+ S3C2410_RTCCON
);
449 con
= readb(info
->base
+ S3C2410_TICNT
);
450 con
&= ~S3C2410_TICNT_ENABLE
;
451 writeb(con
, info
->base
+ S3C2410_TICNT
);
454 static void s3c6410_rtc_disable(struct s3c_rtc
*info
)
458 con
= readw(info
->base
+ S3C2410_RTCCON
);
459 con
&= ~S3C64XX_RTCCON_TICEN
;
460 con
&= ~S3C2410_RTCCON_RTCEN
;
461 writew(con
, info
->base
+ S3C2410_RTCCON
);
464 static int s3c_rtc_remove(struct platform_device
*pdev
)
466 struct s3c_rtc
*info
= platform_get_drvdata(pdev
);
468 s3c_rtc_setaie(info
->dev
, 0);
470 if (info
->data
->needs_src_clk
)
471 clk_unprepare(info
->rtc_src_clk
);
472 clk_unprepare(info
->rtc_clk
);
477 static const struct of_device_id s3c_rtc_dt_match
[];
479 static const struct s3c_rtc_data
*s3c_rtc_get_data(struct platform_device
*pdev
)
481 const struct of_device_id
*match
;
483 match
= of_match_node(s3c_rtc_dt_match
, pdev
->dev
.of_node
);
487 static int s3c_rtc_probe(struct platform_device
*pdev
)
489 struct s3c_rtc
*info
= NULL
;
490 struct rtc_time rtc_tm
;
491 struct resource
*res
;
494 info
= devm_kzalloc(&pdev
->dev
, sizeof(*info
), GFP_KERNEL
);
499 info
->irq_tick
= platform_get_irq(pdev
, 1);
500 if (info
->irq_tick
< 0) {
501 dev_err(&pdev
->dev
, "no irq for rtc tick\n");
502 return info
->irq_tick
;
505 info
->dev
= &pdev
->dev
;
506 info
->data
= s3c_rtc_get_data(pdev
);
508 dev_err(&pdev
->dev
, "failed getting s3c_rtc_data\n");
511 spin_lock_init(&info
->pie_lock
);
512 spin_lock_init(&info
->alarm_clk_lock
);
514 platform_set_drvdata(pdev
, info
);
516 info
->irq_alarm
= platform_get_irq(pdev
, 0);
517 if (info
->irq_alarm
< 0) {
518 dev_err(&pdev
->dev
, "no irq for alarm\n");
519 return info
->irq_alarm
;
522 dev_dbg(&pdev
->dev
, "s3c2410_rtc: tick irq %d, alarm irq %d\n",
523 info
->irq_tick
, info
->irq_alarm
);
525 /* get the memory region */
526 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
527 info
->base
= devm_ioremap_resource(&pdev
->dev
, res
);
528 if (IS_ERR(info
->base
))
529 return PTR_ERR(info
->base
);
531 info
->rtc_clk
= devm_clk_get(&pdev
->dev
, "rtc");
532 if (IS_ERR(info
->rtc_clk
)) {
533 ret
= PTR_ERR(info
->rtc_clk
);
534 if (ret
!= -EPROBE_DEFER
)
535 dev_err(&pdev
->dev
, "failed to find rtc clock\n");
537 dev_dbg(&pdev
->dev
, "probe deferred due to missing rtc clk\n");
540 ret
= clk_prepare_enable(info
->rtc_clk
);
544 if (info
->data
->needs_src_clk
) {
545 info
->rtc_src_clk
= devm_clk_get(&pdev
->dev
, "rtc_src");
546 if (IS_ERR(info
->rtc_src_clk
)) {
547 ret
= PTR_ERR(info
->rtc_src_clk
);
548 if (ret
!= -EPROBE_DEFER
)
550 "failed to find rtc source clock\n");
553 "probe deferred due to missing rtc src clk\n");
556 ret
= clk_prepare_enable(info
->rtc_src_clk
);
561 /* check to see if everything is setup correctly */
562 if (info
->data
->enable
)
563 info
->data
->enable(info
);
565 dev_dbg(&pdev
->dev
, "s3c2410_rtc: RTCCON=%02x\n",
566 readw(info
->base
+ S3C2410_RTCCON
));
568 device_init_wakeup(&pdev
->dev
, 1);
571 if (s3c_rtc_gettime(&pdev
->dev
, &rtc_tm
)) {
572 rtc_tm
.tm_year
= 100;
579 s3c_rtc_settime(&pdev
->dev
, &rtc_tm
);
581 dev_warn(&pdev
->dev
, "warning: invalid RTC value so initializing it\n");
584 /* register RTC and exit */
585 info
->rtc
= devm_rtc_device_register(&pdev
->dev
, "s3c", &s3c_rtcops
,
587 if (IS_ERR(info
->rtc
)) {
588 dev_err(&pdev
->dev
, "cannot attach rtc\n");
589 ret
= PTR_ERR(info
->rtc
);
593 ret
= devm_request_irq(&pdev
->dev
, info
->irq_alarm
, s3c_rtc_alarmirq
,
594 0, "s3c2410-rtc alarm", info
);
596 dev_err(&pdev
->dev
, "IRQ%d error %d\n", info
->irq_alarm
, ret
);
600 ret
= devm_request_irq(&pdev
->dev
, info
->irq_tick
, s3c_rtc_tickirq
,
601 0, "s3c2410-rtc tick", info
);
603 dev_err(&pdev
->dev
, "IRQ%d error %d\n", info
->irq_tick
, ret
);
607 if (info
->data
->select_tick_clk
)
608 info
->data
->select_tick_clk(info
);
610 s3c_rtc_setfreq(info
, 1);
615 if (info
->data
->disable
)
616 info
->data
->disable(info
);
618 if (info
->data
->needs_src_clk
)
619 clk_disable_unprepare(info
->rtc_src_clk
);
621 clk_disable_unprepare(info
->rtc_clk
);
626 #ifdef CONFIG_PM_SLEEP
628 static int s3c_rtc_suspend(struct device
*dev
)
630 struct s3c_rtc
*info
= dev_get_drvdata(dev
);
633 ret
= s3c_rtc_enable_clk(info
);
637 /* save TICNT for anyone using periodic interrupts */
638 if (info
->data
->save_tick_cnt
)
639 info
->data
->save_tick_cnt(info
);
641 if (info
->data
->disable
)
642 info
->data
->disable(info
);
644 if (device_may_wakeup(dev
) && !info
->wake_en
) {
645 if (enable_irq_wake(info
->irq_alarm
) == 0)
646 info
->wake_en
= true;
648 dev_err(dev
, "enable_irq_wake failed\n");
654 static int s3c_rtc_resume(struct device
*dev
)
656 struct s3c_rtc
*info
= dev_get_drvdata(dev
);
658 if (info
->data
->enable
)
659 info
->data
->enable(info
);
661 if (info
->data
->restore_tick_cnt
)
662 info
->data
->restore_tick_cnt(info
);
664 s3c_rtc_disable_clk(info
);
666 if (device_may_wakeup(dev
) && info
->wake_en
) {
667 disable_irq_wake(info
->irq_alarm
);
668 info
->wake_en
= false;
674 static SIMPLE_DEV_PM_OPS(s3c_rtc_pm_ops
, s3c_rtc_suspend
, s3c_rtc_resume
);
676 static void s3c24xx_rtc_irq(struct s3c_rtc
*info
, int mask
)
678 rtc_update_irq(info
->rtc
, 1, RTC_AF
| RTC_IRQF
);
681 static void s3c6410_rtc_irq(struct s3c_rtc
*info
, int mask
)
683 rtc_update_irq(info
->rtc
, 1, RTC_AF
| RTC_IRQF
);
684 writeb(mask
, info
->base
+ S3C2410_INTP
);
687 static void s3c2410_rtc_setfreq(struct s3c_rtc
*info
, int freq
)
689 unsigned int tmp
= 0;
692 tmp
= readb(info
->base
+ S3C2410_TICNT
);
693 tmp
&= S3C2410_TICNT_ENABLE
;
695 val
= (info
->rtc
->max_user_freq
/ freq
) - 1;
698 writel(tmp
, info
->base
+ S3C2410_TICNT
);
701 static void s3c2416_rtc_setfreq(struct s3c_rtc
*info
, int freq
)
703 unsigned int tmp
= 0;
706 tmp
= readb(info
->base
+ S3C2410_TICNT
);
707 tmp
&= S3C2410_TICNT_ENABLE
;
709 val
= (info
->rtc
->max_user_freq
/ freq
) - 1;
711 tmp
|= S3C2443_TICNT_PART(val
);
712 writel(S3C2443_TICNT1_PART(val
), info
->base
+ S3C2443_TICNT1
);
714 writel(S3C2416_TICNT2_PART(val
), info
->base
+ S3C2416_TICNT2
);
716 writel(tmp
, info
->base
+ S3C2410_TICNT
);
719 static void s3c2443_rtc_setfreq(struct s3c_rtc
*info
, int freq
)
721 unsigned int tmp
= 0;
724 tmp
= readb(info
->base
+ S3C2410_TICNT
);
725 tmp
&= S3C2410_TICNT_ENABLE
;
727 val
= (info
->rtc
->max_user_freq
/ freq
) - 1;
729 tmp
|= S3C2443_TICNT_PART(val
);
730 writel(S3C2443_TICNT1_PART(val
), info
->base
+ S3C2443_TICNT1
);
732 writel(tmp
, info
->base
+ S3C2410_TICNT
);
735 static void s3c6410_rtc_setfreq(struct s3c_rtc
*info
, int freq
)
739 val
= (info
->rtc
->max_user_freq
/ freq
) - 1;
740 writel(val
, info
->base
+ S3C2410_TICNT
);
743 static void s3c24xx_rtc_enable_tick(struct s3c_rtc
*info
, struct seq_file
*seq
)
747 ticnt
= readb(info
->base
+ S3C2410_TICNT
);
748 ticnt
&= S3C2410_TICNT_ENABLE
;
750 seq_printf(seq
, "periodic_IRQ\t: %s\n", ticnt
? "yes" : "no");
753 static void s3c2416_rtc_select_tick_clk(struct s3c_rtc
*info
)
757 con
= readw(info
->base
+ S3C2410_RTCCON
);
758 con
|= S3C2443_RTCCON_TICSEL
;
759 writew(con
, info
->base
+ S3C2410_RTCCON
);
762 static void s3c6410_rtc_enable_tick(struct s3c_rtc
*info
, struct seq_file
*seq
)
766 ticnt
= readw(info
->base
+ S3C2410_RTCCON
);
767 ticnt
&= S3C64XX_RTCCON_TICEN
;
769 seq_printf(seq
, "periodic_IRQ\t: %s\n", ticnt
? "yes" : "no");
772 static void s3c24xx_rtc_save_tick_cnt(struct s3c_rtc
*info
)
774 info
->ticnt_save
= readb(info
->base
+ S3C2410_TICNT
);
777 static void s3c24xx_rtc_restore_tick_cnt(struct s3c_rtc
*info
)
779 writeb(info
->ticnt_save
, info
->base
+ S3C2410_TICNT
);
782 static void s3c6410_rtc_save_tick_cnt(struct s3c_rtc
*info
)
784 info
->ticnt_en_save
= readw(info
->base
+ S3C2410_RTCCON
);
785 info
->ticnt_en_save
&= S3C64XX_RTCCON_TICEN
;
786 info
->ticnt_save
= readl(info
->base
+ S3C2410_TICNT
);
789 static void s3c6410_rtc_restore_tick_cnt(struct s3c_rtc
*info
)
793 writel(info
->ticnt_save
, info
->base
+ S3C2410_TICNT
);
794 if (info
->ticnt_en_save
) {
795 con
= readw(info
->base
+ S3C2410_RTCCON
);
796 writew(con
| info
->ticnt_en_save
, info
->base
+ S3C2410_RTCCON
);
800 static struct s3c_rtc_data
const s3c2410_rtc_data
= {
801 .max_user_freq
= 128,
802 .irq_handler
= s3c24xx_rtc_irq
,
803 .set_freq
= s3c2410_rtc_setfreq
,
804 .enable_tick
= s3c24xx_rtc_enable_tick
,
805 .save_tick_cnt
= s3c24xx_rtc_save_tick_cnt
,
806 .restore_tick_cnt
= s3c24xx_rtc_restore_tick_cnt
,
807 .enable
= s3c24xx_rtc_enable
,
808 .disable
= s3c24xx_rtc_disable
,
811 static struct s3c_rtc_data
const s3c2416_rtc_data
= {
812 .max_user_freq
= 32768,
813 .irq_handler
= s3c24xx_rtc_irq
,
814 .set_freq
= s3c2416_rtc_setfreq
,
815 .enable_tick
= s3c24xx_rtc_enable_tick
,
816 .select_tick_clk
= s3c2416_rtc_select_tick_clk
,
817 .save_tick_cnt
= s3c24xx_rtc_save_tick_cnt
,
818 .restore_tick_cnt
= s3c24xx_rtc_restore_tick_cnt
,
819 .enable
= s3c24xx_rtc_enable
,
820 .disable
= s3c24xx_rtc_disable
,
823 static struct s3c_rtc_data
const s3c2443_rtc_data
= {
824 .max_user_freq
= 32768,
825 .irq_handler
= s3c24xx_rtc_irq
,
826 .set_freq
= s3c2443_rtc_setfreq
,
827 .enable_tick
= s3c24xx_rtc_enable_tick
,
828 .select_tick_clk
= s3c2416_rtc_select_tick_clk
,
829 .save_tick_cnt
= s3c24xx_rtc_save_tick_cnt
,
830 .restore_tick_cnt
= s3c24xx_rtc_restore_tick_cnt
,
831 .enable
= s3c24xx_rtc_enable
,
832 .disable
= s3c24xx_rtc_disable
,
835 static struct s3c_rtc_data
const s3c6410_rtc_data
= {
836 .max_user_freq
= 32768,
837 .needs_src_clk
= true,
838 .irq_handler
= s3c6410_rtc_irq
,
839 .set_freq
= s3c6410_rtc_setfreq
,
840 .enable_tick
= s3c6410_rtc_enable_tick
,
841 .save_tick_cnt
= s3c6410_rtc_save_tick_cnt
,
842 .restore_tick_cnt
= s3c6410_rtc_restore_tick_cnt
,
843 .enable
= s3c24xx_rtc_enable
,
844 .disable
= s3c6410_rtc_disable
,
847 static const struct of_device_id s3c_rtc_dt_match
[] = {
849 .compatible
= "samsung,s3c2410-rtc",
850 .data
= &s3c2410_rtc_data
,
852 .compatible
= "samsung,s3c2416-rtc",
853 .data
= &s3c2416_rtc_data
,
855 .compatible
= "samsung,s3c2443-rtc",
856 .data
= &s3c2443_rtc_data
,
858 .compatible
= "samsung,s3c6410-rtc",
859 .data
= &s3c6410_rtc_data
,
861 .compatible
= "samsung,exynos3250-rtc",
862 .data
= &s3c6410_rtc_data
,
866 MODULE_DEVICE_TABLE(of
, s3c_rtc_dt_match
);
868 static struct platform_driver s3c_rtc_driver
= {
869 .probe
= s3c_rtc_probe
,
870 .remove
= s3c_rtc_remove
,
873 .pm
= &s3c_rtc_pm_ops
,
874 .of_match_table
= of_match_ptr(s3c_rtc_dt_match
),
877 module_platform_driver(s3c_rtc_driver
);
879 MODULE_DESCRIPTION("Samsung S3C RTC Driver");
880 MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
881 MODULE_LICENSE("GPL");
882 MODULE_ALIAS("platform:s3c2410-rtc");