14 #include <linux/kernel.h>
15 #include <linux/module.h>
16 #include <linux/slab.h>
17 #include <linux/rtc.h>
19 #define DRIVER_NAME "mc13xxx-rtc"
21 #define MC13XXX_RTCTOD 20
22 #define MC13XXX_RTCTODA 21
23 #define MC13XXX_RTCDAY 22
24 #define MC13XXX_RTCDAYA 23
32 static int mc13xxx_rtc_irq_enable_unlocked(
struct device *
dev,
45 static int mc13xxx_rtc_irq_enable(
struct device *
dev,
53 ret = mc13xxx_rtc_irq_enable_unlocked(dev, enabled, irq);
63 unsigned int seconds, days1, days2;
89 if (days2 == days1 + 1) {
90 if (seconds >= 86400 / 2)
99 s1970 = days1 * 86400 +
seconds;
106 static int mc13xxx_rtc_set_mmss(
struct device *dev,
unsigned long secs)
110 unsigned int alarmseconds;
113 seconds = secs % 86400;
126 if (alarmseconds < 86400) {
150 if (alarmseconds < 86400) {
183 if (seconds >= 86400) {
204 s1970 = days * 86400 +
seconds;
207 dev_dbg(dev,
"%s: %lu\n", __func__, s1970);
212 static int mc13xxx_rtc_set_alarm(
struct device *dev,
struct rtc_wkalrm *alarm)
234 dev_dbg(dev,
"%s: o%2.s %lu\n", __func__, alarm->
enabled ?
"n" :
"ff",
237 ret = mc13xxx_rtc_irq_enable_unlocked(dev, alarm->
enabled,
242 seconds = s1970 % 86400;
243 days = s1970 / 86400;
257 static irqreturn_t mc13xxx_rtc_alarm_handler(
int irq,
void *dev)
285 static int mc13xxx_rtc_alarm_irq_enable(
struct device *dev,
286 unsigned int enabled)
292 .read_time = mc13xxx_rtc_read_time,
293 .set_mmss = mc13xxx_rtc_set_mmss,
294 .read_alarm = mc13xxx_rtc_read_alarm,
295 .set_alarm = mc13xxx_rtc_set_alarm,
296 .alarm_irq_enable = mc13xxx_rtc_alarm_irq_enable,
299 static irqreturn_t mc13xxx_rtc_reset_handler(
int irq,
void *dev)
326 platform_set_drvdata(pdev, priv);
333 goto err_reset_irq_request;
336 NULL, &rtcrst_pending);
338 goto err_reset_irq_status;
340 priv->
valid = !rtcrst_pending;
345 goto err_update_irq_request;
350 goto err_alarm_irq_request;
356 if (IS_ERR(priv->
rtc)) {
357 ret = PTR_ERR(priv->
rtc);
362 err_alarm_irq_request:
365 err_update_irq_request:
367 err_reset_irq_status:
370 err_reset_irq_request:
374 platform_set_drvdata(pdev,
NULL);
383 struct mc13xxx_rtc *priv = platform_get_drvdata(pdev);
395 platform_set_drvdata(pdev,
NULL);
404 .name =
"mc13783-rtc",
406 .name =
"mc13892-rtc",
408 .name =
"mc34708-rtc",
415 .id_table = mc13xxx_rtc_idtable,
416 .remove =
__exit_p(mc13xxx_rtc_remove),
423 static int __init mc13xxx_rtc_init(
void)
429 static void __exit mc13xxx_rtc_exit(
void)