19 #include <linux/kernel.h>
23 #include <linux/rtc.h>
26 #include <linux/module.h>
28 #define DRV_VERSION "0.6"
51 #define DS1511_BLF1 0x80
52 #define DS1511_BLF2 0x40
53 #define DS1511_PRS 0x20
54 #define DS1511_PAB 0x10
55 #define DS1511_TDF 0x08
56 #define DS1511_KSF 0x04
57 #define DS1511_WDF 0x02
58 #define DS1511_IRQF 0x01
59 #define DS1511_TE 0x80
60 #define DS1511_CS 0x40
61 #define DS1511_BME 0x20
62 #define DS1511_TPE 0x10
63 #define DS1511_TIE 0x08
64 #define DS1511_KIE 0x04
65 #define DS1511_WDE 0x02
66 #define DS1511_WDS 0x01
67 #define DS1511_RAM_MAX 0xff
69 #define RTC_CMD DS1511_CONTROL_B
70 #define RTC_CMD1 DS1511_CONTROL_A
72 #define RTC_ALARM_SEC DS1511_AM1_SEC
73 #define RTC_ALARM_MIN DS1511_AM2_MIN
74 #define RTC_ALARM_HOUR DS1511_AM3_HOUR
75 #define RTC_ALARM_DATE DS1511_AM4_DATE
77 #define RTC_SEC DS1511_SEC
78 #define RTC_MIN DS1511_MIN
79 #define RTC_HOUR DS1511_HOUR
80 #define RTC_DOW DS1511_DOW
81 #define RTC_DOM DS1511_DOM
82 #define RTC_MON DS1511_MONTH
83 #define RTC_YEAR DS1511_YEAR
84 #define RTC_CENTURY DS1511_CENTURY
86 #define RTC_TIE DS1511_TIE
87 #define RTC_TE DS1511_TE
104 static __iomem char *ds1511_base;
105 static u32 reg_spacing = 1;
110 writeb(val, ds1511_base + (reg * reg_spacing));
122 return readb(ds1511_base + (reg * reg_spacing));
126 rtc_disable_update(
void)
132 rtc_enable_update(
void)
143 #ifdef DS1511_WDOG_RESET_SUPPORT
149 ds1511_wdog_set(
unsigned long deciseconds)
154 deciseconds %= 10000;
167 ds1511_wdog_disable(
void)
210 if ((mon > 12) || (day == 0)) {
218 if ((hrs >= 24) || (min >= 60) || (sec >= 60)) {
234 rtc_disable_update();
244 spin_unlock_irqrestore(&ds1511_lock, flags);
249 static int ds1511_rtc_read_time(
struct device *dev,
struct rtc_time *rtc_tm)
251 unsigned int century;
255 rtc_disable_update();
267 spin_unlock_irqrestore(&ds1511_lock, flags);
276 century =
bcd2bin(century) * 100;
283 rtc_tm->
tm_year = century - 1900;
288 dev_err(dev,
"retrieved date/time is not valid.\n");
322 spin_unlock_irqrestore(&pdata->
lock, flags);
341 ds1511_rtc_update_alarm(pdata);
369 spin_lock(&pdata->
lock);
382 spin_unlock(&pdata->
lock);
386 static int ds1511_rtc_alarm_irq_enable(
struct device *dev,
unsigned int enabled)
397 ds1511_rtc_update_alarm(pdata);
402 .read_time = ds1511_rtc_read_time,
403 .set_time = ds1511_rtc_set_time,
404 .read_alarm = ds1511_rtc_read_alarm,
405 .set_alarm = ds1511_rtc_set_alarm,
406 .alarm_irq_enable = ds1511_rtc_alarm_irq_enable,
410 ds1511_nvram_read(
struct file *filp,
struct kobject *kobj,
430 for (count = 0; size > 0; count++, size--) {
440 ds1511_nvram_write(
struct file *filp,
struct kobject *kobj,
442 char *buf, loff_t pos,
size_t size)
460 for (count = 0; size > 0; count++, size--) {
475 .read = ds1511_nvram_read,
476 .write = ds1511_nvram_write,
494 pdata->
size = resource_size(res);
501 pdata->
ioaddr = ds1511_base;
527 platform_set_drvdata(pdev, pdata);
532 if (pdata->
irq > 0) {
534 if (devm_request_irq(&pdev->
dev, pdata->
irq, ds1511_interrupt,
537 dev_warn(&pdev->
dev,
"interrupt not available.\n");
561 if (pdata->
irq > 0) {
575 .probe = ds1511_rtc_probe,