13 #include <linux/kernel.h>
14 #include <linux/module.h>
17 #include <linux/device.h>
19 #include <linux/rtc.h>
22 #include <linux/slab.h>
28 #define M48T59_READ(reg) (pdata->read_byte(dev, pdata->offset + reg))
29 #define M48T59_WRITE(val, reg) \
30 (pdata->write_byte(dev, pdata->offset + reg, val))
32 #define M48T59_SET_BITS(mask, reg) \
33 M48T59_WRITE((M48T59_READ(reg) | (mask)), (reg))
34 #define M48T59_CLEAR_BITS(mask, reg) \
35 M48T59_WRITE((M48T59_READ(reg) & ~(mask)), (reg))
88 dev_dbg(dev,
"Century bit is enabled\n");
103 spin_unlock_irqrestore(&m48t59->
lock, flags);
105 dev_dbg(dev,
"RTC read time %04d-%02d-%02d %02d/%02d/%02d\n",
111 static int m48t59_rtc_set_time(
struct device *dev,
struct rtc_time *tm)
125 dev_dbg(dev,
"RTC set time %04d-%02d-%02d %02d/%02d/%02d\n",
151 spin_unlock_irqrestore(&m48t59->
lock, flags);
158 static int m48t59_rtc_readalarm(
struct device *dev,
struct rtc_wkalrm *alrm)
184 if ((val & M48T59_WDAY_CEB) && (val & M48T59_WDAY_CB))
194 spin_unlock_irqrestore(&m48t59->
lock, flags);
196 dev_dbg(dev,
"RTC read alarm time %04d-%02d-%02d %02d/%02d/%02d\n",
231 mday = (mday >= 1 && mday <= 31) ?
bin2bcd(mday) : 0xff;
236 hour = (hour < 24) ?
bin2bcd(hour) : 0x00;
239 min = (min < 60) ?
bin2bcd(min) : 0x00;
242 sec = (sec < 60) ?
bin2bcd(sec) : 0x00;
255 spin_unlock_irqrestore(&m48t59->
lock, flags);
257 dev_dbg(dev,
"RTC set alarm time %04d-%02d-%02d %02d/%02d/%02d\n",
266 static int m48t59_rtc_alarm_irq_enable(
struct device *dev,
unsigned int enabled)
278 spin_unlock_irqrestore(&m48t59->
lock, flags);
283 static int m48t59_rtc_proc(
struct device *dev,
struct seq_file *seq)
293 spin_unlock_irqrestore(&m48t59->
lock, flags);
311 spin_lock(&m48t59->
lock);
313 spin_unlock(&m48t59->
lock);
324 .read_time = m48t59_rtc_read_time,
325 .set_time = m48t59_rtc_set_time,
326 .read_alarm = m48t59_rtc_readalarm,
327 .set_alarm = m48t59_rtc_setalarm,
328 .proc = m48t59_rtc_proc,
329 .alarm_irq_enable = m48t59_rtc_alarm_irq_enable,
333 .read_time = m48t59_rtc_read_time,
334 .set_time = m48t59_rtc_set_time,
348 for (; size > 0 && pos < pdata->
offset; cnt++, size--) {
351 spin_unlock_irqrestore(&m48t59->
lock, flags);
359 char *buf, loff_t pos,
size_t size)
368 for (; size > 0 && pos < pdata->
offset; cnt++, size--) {
371 spin_unlock_irqrestore(&m48t59->
lock, flags);
382 .read = m48t59_nvram_read,
383 .write = m48t59_nvram_write,
428 m48t59 = kzalloc(
sizeof(*m48t59),
GFP_KERNEL);
445 if (m48t59->
irq <= 0)
454 switch (pdata->
type) {
457 ops = &m48t59_rtc_ops;
462 ops = &m48t02_rtc_ops;
467 ops = &m48t02_rtc_ops;
477 platform_set_drvdata(pdev, m48t59);
480 if (IS_ERR(m48t59->
rtc)) {
481 ret = PTR_ERR(m48t59->
rtc);
510 if (!IS_ERR(m48t59->
rtc))
516 platform_set_drvdata(pdev,
NULL);
526 .name =
"rtc-m48t59",
529 .probe = m48t59_rtc_probe,