11 #include <linux/rtc.h>
14 #include <linux/module.h>
45 static int tx4939_rtc_set_mmss(
struct device *
dev,
unsigned long secs)
58 spin_lock_irq(&pdata->
lock);
60 for (i = 0; i < 6; i++)
62 ret = tx4939_rtc_cmd(rtcreg,
65 spin_unlock_irq(&pdata->
lock);
77 spin_lock_irq(&pdata->
lock);
78 ret = tx4939_rtc_cmd(rtcreg,
82 spin_unlock_irq(&pdata->
lock);
86 for (i = 2; i < 6; i++)
88 spin_unlock_irq(&pdata->
lock);
89 sec = (buf[5] << 24) | (buf[4] << 16) | (buf[3] << 8) | buf[2];
100 unsigned char buf[6];
102 if (alrm->
time.tm_sec < 0 ||
103 alrm->
time.tm_min < 0 ||
104 alrm->
time.tm_hour < 0 ||
105 alrm->
time.tm_mday < 0 ||
106 alrm->
time.tm_mon < 0 ||
107 alrm->
time.tm_year < 0)
116 spin_lock_irq(&pdata->
lock);
118 for (i = 0; i < 6; i++)
122 spin_unlock_irq(&pdata->
lock);
126 static int tx4939_rtc_read_alarm(
struct device *dev,
struct rtc_wkalrm *alrm)
132 unsigned char buf[6];
135 spin_lock_irq(&pdata->
lock);
136 ret = tx4939_rtc_cmd(rtcreg,
140 spin_unlock_irq(&pdata->
lock);
144 for (i = 2; i < 6; i++)
149 spin_unlock_irq(&pdata->
lock);
150 sec = (buf[5] << 24) | (buf[4] << 16) | (buf[3] << 8) | buf[2];
155 static int tx4939_rtc_alarm_irq_enable(
struct device *dev,
unsigned int enabled)
159 spin_lock_irq(&pdata->
lock);
160 tx4939_rtc_cmd(pdata->
rtcreg,
163 spin_unlock_irq(&pdata->
lock);
173 spin_lock(&pdata->
lock);
178 spin_unlock(&pdata->
lock);
185 .read_time = tx4939_rtc_read_time,
186 .read_alarm = tx4939_rtc_read_alarm,
187 .set_alarm = tx4939_rtc_set_alarm,
188 .set_mmss = tx4939_rtc_set_mmss,
189 .alarm_irq_enable = tx4939_rtc_alarm_irq_enable,
194 char *buf, loff_t
pos,
size_t size)
201 spin_lock_irq(&pdata->
lock);
207 spin_unlock_irq(&pdata->
lock);
213 char *buf, loff_t pos,
size_t size)
220 spin_lock_irq(&pdata->
lock);
226 spin_unlock_irq(&pdata->
lock);
236 .read = tx4939_rtc_nvram_read,
237 .write = tx4939_rtc_nvram_write,
256 platform_set_drvdata(pdev, pdata);
259 resource_size(res), pdev->
name))
268 if (devm_request_irq(&pdev->
dev, irq, tx4939_rtc_interrupt,
269 0, pdev->
name, &pdev->
dev) < 0)
288 spin_lock_irq(&pdata->
lock);
290 spin_unlock_irq(&pdata->
lock);
295 .remove =
__exit_p(tx4939_rtc_remove),
302 static int __init tx4939rtc_init(
void)
307 static void __exit tx4939rtc_exit(
void)