Lines Matching +full:s3c6410 +full:- +full:rtc

1 // SPDX-License-Identifier: GPL-2.0-only
2 /* drivers/rtc/rtc-s3c.c
11 * S3C2410/S3C2440/S3C24XX Internal RTC Driver
20 #include <linux/rtc.h>
30 #include "rtc-s3c.h"
34 struct rtc_device *rtc; member
61 ret = clk_enable(info->rtc_clk); in s3c_rtc_enable_clk()
65 if (info->data->needs_src_clk) { in s3c_rtc_enable_clk()
66 ret = clk_enable(info->rtc_src_clk); in s3c_rtc_enable_clk()
68 clk_disable(info->rtc_clk); in s3c_rtc_enable_clk()
77 if (info->data->needs_src_clk) in s3c_rtc_disable_clk()
78 clk_disable(info->rtc_src_clk); in s3c_rtc_disable_clk()
79 clk_disable(info->rtc_clk); in s3c_rtc_disable_clk()
87 if (info->data->irq_handler) in s3c_rtc_alarmirq()
88 info->data->irq_handler(info, S3C2410_INTP_ALM); in s3c_rtc_alarmirq()
101 dev_dbg(info->dev, "%s: aie=%d\n", __func__, enabled); in s3c_rtc_setaie()
107 tmp = readb(info->base + S3C2410_RTCALM) & ~S3C2410_RTCALM_ALMEN; in s3c_rtc_setaie()
112 writeb(tmp, info->base + S3C2410_RTCALM); in s3c_rtc_setaie()
114 spin_lock_irqsave(&info->alarm_lock, flags); in s3c_rtc_setaie()
116 if (info->alarm_enabled && !enabled) in s3c_rtc_setaie()
118 else if (!info->alarm_enabled && enabled) in s3c_rtc_setaie()
121 info->alarm_enabled = enabled; in s3c_rtc_setaie()
122 spin_unlock_irqrestore(&info->alarm_lock, flags); in s3c_rtc_setaie()
129 /* Read time from RTC and convert it from BCD */
140 tm->tm_min = readb(info->base + S3C2410_RTCMIN); in s3c_rtc_read_time()
141 tm->tm_hour = readb(info->base + S3C2410_RTCHOUR); in s3c_rtc_read_time()
142 tm->tm_mday = readb(info->base + S3C2410_RTCDATE); in s3c_rtc_read_time()
143 tm->tm_mon = readb(info->base + S3C2410_RTCMON); in s3c_rtc_read_time()
144 tm->tm_year = readb(info->base + S3C2410_RTCYEAR); in s3c_rtc_read_time()
145 tm->tm_sec = readb(info->base + S3C2410_RTCSEC); in s3c_rtc_read_time()
148 * The only way to work out whether the system was mid-update in s3c_rtc_read_time()
150 * is zero, then we re-try the entire read in s3c_rtc_read_time()
152 if (tm->tm_sec == 0 && !have_retried) { in s3c_rtc_read_time()
159 tm->tm_sec = bcd2bin(tm->tm_sec); in s3c_rtc_read_time()
160 tm->tm_min = bcd2bin(tm->tm_min); in s3c_rtc_read_time()
161 tm->tm_hour = bcd2bin(tm->tm_hour); in s3c_rtc_read_time()
162 tm->tm_mday = bcd2bin(tm->tm_mday); in s3c_rtc_read_time()
163 tm->tm_mon = bcd2bin(tm->tm_mon); in s3c_rtc_read_time()
164 tm->tm_year = bcd2bin(tm->tm_year); in s3c_rtc_read_time()
169 /* Convert time to BCD and write it to RTC */
178 writeb(bin2bcd(tm->tm_sec), info->base + S3C2410_RTCSEC); in s3c_rtc_write_time()
179 writeb(bin2bcd(tm->tm_min), info->base + S3C2410_RTCMIN); in s3c_rtc_write_time()
180 writeb(bin2bcd(tm->tm_hour), info->base + S3C2410_RTCHOUR); in s3c_rtc_write_time()
181 writeb(bin2bcd(tm->tm_mday), info->base + S3C2410_RTCDATE); in s3c_rtc_write_time()
182 writeb(bin2bcd(tm->tm_mon), info->base + S3C2410_RTCMON); in s3c_rtc_write_time()
183 writeb(bin2bcd(tm->tm_year), info->base + S3C2410_RTCYEAR); in s3c_rtc_write_time()
200 tm->tm_year += 100; in s3c_rtc_gettime()
201 tm->tm_mon -= 1; in s3c_rtc_gettime()
218 rtc_tm.tm_year -= 100; in s3c_rtc_settime()
227 struct rtc_time *alm_tm = &alrm->time; in s3c_rtc_getalarm()
235 alm_tm->tm_sec = readb(info->base + S3C2410_ALMSEC); in s3c_rtc_getalarm()
236 alm_tm->tm_min = readb(info->base + S3C2410_ALMMIN); in s3c_rtc_getalarm()
237 alm_tm->tm_hour = readb(info->base + S3C2410_ALMHOUR); in s3c_rtc_getalarm()
238 alm_tm->tm_mon = readb(info->base + S3C2410_ALMMON); in s3c_rtc_getalarm()
239 alm_tm->tm_mday = readb(info->base + S3C2410_ALMDATE); in s3c_rtc_getalarm()
240 alm_tm->tm_year = readb(info->base + S3C2410_ALMYEAR); in s3c_rtc_getalarm()
242 alm_en = readb(info->base + S3C2410_RTCALM); in s3c_rtc_getalarm()
246 alrm->enabled = (alm_en & S3C2410_RTCALM_ALMEN) ? 1 : 0; in s3c_rtc_getalarm()
252 alm_tm->tm_sec = bcd2bin(alm_tm->tm_sec); in s3c_rtc_getalarm()
255 alm_tm->tm_min = bcd2bin(alm_tm->tm_min); in s3c_rtc_getalarm()
258 alm_tm->tm_hour = bcd2bin(alm_tm->tm_hour); in s3c_rtc_getalarm()
261 alm_tm->tm_mday = bcd2bin(alm_tm->tm_mday); in s3c_rtc_getalarm()
264 alm_tm->tm_mon = bcd2bin(alm_tm->tm_mon); in s3c_rtc_getalarm()
265 alm_tm->tm_mon -= 1; in s3c_rtc_getalarm()
269 alm_tm->tm_year = bcd2bin(alm_tm->tm_year); in s3c_rtc_getalarm()
277 struct rtc_time *tm = &alrm->time; in s3c_rtc_setalarm()
281 dev_dbg(dev, "s3c_rtc_setalarm: %d, %ptR\n", alrm->enabled, tm); in s3c_rtc_setalarm()
287 alrm_en = readb(info->base + S3C2410_RTCALM) & S3C2410_RTCALM_ALMEN; in s3c_rtc_setalarm()
288 writeb(0x00, info->base + S3C2410_RTCALM); in s3c_rtc_setalarm()
290 if (tm->tm_sec < 60 && tm->tm_sec >= 0) { in s3c_rtc_setalarm()
292 writeb(bin2bcd(tm->tm_sec), info->base + S3C2410_ALMSEC); in s3c_rtc_setalarm()
295 if (tm->tm_min < 60 && tm->tm_min >= 0) { in s3c_rtc_setalarm()
297 writeb(bin2bcd(tm->tm_min), info->base + S3C2410_ALMMIN); in s3c_rtc_setalarm()
300 if (tm->tm_hour < 24 && tm->tm_hour >= 0) { in s3c_rtc_setalarm()
302 writeb(bin2bcd(tm->tm_hour), info->base + S3C2410_ALMHOUR); in s3c_rtc_setalarm()
305 if (tm->tm_mon < 12 && tm->tm_mon >= 0) { in s3c_rtc_setalarm()
307 writeb(bin2bcd(tm->tm_mon + 1), info->base + S3C2410_ALMMON); in s3c_rtc_setalarm()
310 if (tm->tm_mday <= 31 && tm->tm_mday >= 1) { in s3c_rtc_setalarm()
312 writeb(bin2bcd(tm->tm_mday), info->base + S3C2410_ALMDATE); in s3c_rtc_setalarm()
317 writeb(alrm_en, info->base + S3C2410_RTCALM); in s3c_rtc_setalarm()
319 s3c_rtc_setaie(dev, alrm->enabled); in s3c_rtc_setalarm()
338 con = readw(info->base + S3C2410_RTCCON); in s3c24xx_rtc_enable()
339 /* re-enable the device, and check it is ok */ in s3c24xx_rtc_enable()
341 dev_info(info->dev, "rtc disabled, re-enabling\n"); in s3c24xx_rtc_enable()
343 tmp = readw(info->base + S3C2410_RTCCON); in s3c24xx_rtc_enable()
344 writew(tmp | S3C2410_RTCCON_RTCEN, info->base + S3C2410_RTCCON); in s3c24xx_rtc_enable()
348 dev_info(info->dev, "removing RTCCON_CNTSEL\n"); in s3c24xx_rtc_enable()
350 tmp = readw(info->base + S3C2410_RTCCON); in s3c24xx_rtc_enable()
352 info->base + S3C2410_RTCCON); in s3c24xx_rtc_enable()
356 dev_info(info->dev, "removing RTCCON_CLKRST\n"); in s3c24xx_rtc_enable()
358 tmp = readw(info->base + S3C2410_RTCCON); in s3c24xx_rtc_enable()
360 info->base + S3C2410_RTCCON); in s3c24xx_rtc_enable()
368 con = readw(info->base + S3C2410_RTCCON); in s3c24xx_rtc_disable()
370 writew(con, info->base + S3C2410_RTCCON); in s3c24xx_rtc_disable()
372 con = readb(info->base + S3C2410_TICNT); in s3c24xx_rtc_disable()
374 writeb(con, info->base + S3C2410_TICNT); in s3c24xx_rtc_disable()
381 con = readw(info->base + S3C2410_RTCCON); in s3c6410_rtc_disable()
384 writew(con, info->base + S3C2410_RTCCON); in s3c6410_rtc_disable()
391 s3c_rtc_setaie(info->dev, 0); in s3c_rtc_remove()
393 if (info->data->needs_src_clk) in s3c_rtc_remove()
394 clk_unprepare(info->rtc_src_clk); in s3c_rtc_remove()
395 clk_unprepare(info->rtc_clk); in s3c_rtc_remove()
403 info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); in s3c_rtc_probe()
405 return -ENOMEM; in s3c_rtc_probe()
407 info->dev = &pdev->dev; in s3c_rtc_probe()
408 info->data = of_device_get_match_data(&pdev->dev); in s3c_rtc_probe()
409 if (!info->data) { in s3c_rtc_probe()
410 dev_err(&pdev->dev, "failed getting s3c_rtc_data\n"); in s3c_rtc_probe()
411 return -EINVAL; in s3c_rtc_probe()
413 spin_lock_init(&info->alarm_lock); in s3c_rtc_probe()
417 info->irq_alarm = platform_get_irq(pdev, 0); in s3c_rtc_probe()
418 if (info->irq_alarm < 0) in s3c_rtc_probe()
419 return info->irq_alarm; in s3c_rtc_probe()
421 dev_dbg(&pdev->dev, "s3c2410_rtc: alarm irq %d\n", info->irq_alarm); in s3c_rtc_probe()
424 info->base = devm_platform_ioremap_resource(pdev, 0); in s3c_rtc_probe()
425 if (IS_ERR(info->base)) in s3c_rtc_probe()
426 return PTR_ERR(info->base); in s3c_rtc_probe()
428 info->rtc_clk = devm_clk_get(&pdev->dev, "rtc"); in s3c_rtc_probe()
429 if (IS_ERR(info->rtc_clk)) in s3c_rtc_probe()
430 return dev_err_probe(&pdev->dev, PTR_ERR(info->rtc_clk), in s3c_rtc_probe()
431 "failed to find rtc clock\n"); in s3c_rtc_probe()
432 ret = clk_prepare_enable(info->rtc_clk); in s3c_rtc_probe()
436 if (info->data->needs_src_clk) { in s3c_rtc_probe()
437 info->rtc_src_clk = devm_clk_get(&pdev->dev, "rtc_src"); in s3c_rtc_probe()
438 if (IS_ERR(info->rtc_src_clk)) { in s3c_rtc_probe()
439 ret = dev_err_probe(&pdev->dev, PTR_ERR(info->rtc_src_clk), in s3c_rtc_probe()
440 "failed to find rtc source clock\n"); in s3c_rtc_probe()
443 ret = clk_prepare_enable(info->rtc_src_clk); in s3c_rtc_probe()
448 /* disable RTC enable bits potentially set by the bootloader */ in s3c_rtc_probe()
449 if (info->data->disable) in s3c_rtc_probe()
450 info->data->disable(info); in s3c_rtc_probe()
453 if (info->data->enable) in s3c_rtc_probe()
454 info->data->enable(info); in s3c_rtc_probe()
456 dev_dbg(&pdev->dev, "s3c2410_rtc: RTCCON=%02x\n", in s3c_rtc_probe()
457 readw(info->base + S3C2410_RTCCON)); in s3c_rtc_probe()
459 device_init_wakeup(&pdev->dev, 1); in s3c_rtc_probe()
461 info->rtc = devm_rtc_allocate_device(&pdev->dev); in s3c_rtc_probe()
462 if (IS_ERR(info->rtc)) { in s3c_rtc_probe()
463 ret = PTR_ERR(info->rtc); in s3c_rtc_probe()
467 info->rtc->ops = &s3c_rtcops; in s3c_rtc_probe()
468 info->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; in s3c_rtc_probe()
469 info->rtc->range_max = RTC_TIMESTAMP_END_2099; in s3c_rtc_probe()
471 ret = devm_rtc_register_device(info->rtc); in s3c_rtc_probe()
475 ret = devm_request_irq(&pdev->dev, info->irq_alarm, s3c_rtc_alarmirq, in s3c_rtc_probe()
476 0, "s3c2410-rtc alarm", info); in s3c_rtc_probe()
478 dev_err(&pdev->dev, "IRQ%d error %d\n", info->irq_alarm, ret); in s3c_rtc_probe()
487 if (info->data->disable) in s3c_rtc_probe()
488 info->data->disable(info); in s3c_rtc_probe()
490 if (info->data->needs_src_clk) in s3c_rtc_probe()
491 clk_disable_unprepare(info->rtc_src_clk); in s3c_rtc_probe()
493 clk_disable_unprepare(info->rtc_clk); in s3c_rtc_probe()
509 if (info->data->disable) in s3c_rtc_suspend()
510 info->data->disable(info); in s3c_rtc_suspend()
512 if (device_may_wakeup(dev) && !info->wake_en) { in s3c_rtc_suspend()
513 if (enable_irq_wake(info->irq_alarm) == 0) in s3c_rtc_suspend()
514 info->wake_en = true; in s3c_rtc_suspend()
526 if (info->data->enable) in s3c_rtc_resume()
527 info->data->enable(info); in s3c_rtc_resume()
531 if (device_may_wakeup(dev) && info->wake_en) { in s3c_rtc_resume()
532 disable_irq_wake(info->irq_alarm); in s3c_rtc_resume()
533 info->wake_en = false; in s3c_rtc_resume()
543 rtc_update_irq(info->rtc, 1, RTC_AF | RTC_IRQF); in s3c24xx_rtc_irq()
548 rtc_update_irq(info->rtc, 1, RTC_AF | RTC_IRQF); in s3c6410_rtc_irq()
549 writeb(mask, info->base + S3C2410_INTP); in s3c6410_rtc_irq()
579 .compatible = "samsung,s3c2410-rtc",
582 .compatible = "samsung,s3c2416-rtc",
585 .compatible = "samsung,s3c2443-rtc",
588 .compatible = "samsung,s3c6410-rtc",
591 .compatible = "samsung,exynos3250-rtc",
602 .name = "s3c-rtc",
609 MODULE_DESCRIPTION("Samsung S3C RTC Driver");
612 MODULE_ALIAS("platform:s3c2410-rtc");