12 #include <linux/module.h>
13 #include <linux/i2c.h>
14 #include <linux/slab.h>
15 #include <linux/rtc.h>
30 #define MAX8925_RTC_SEC 0x00
31 #define MAX8925_RTC_MIN 0x01
32 #define MAX8925_RTC_HOUR 0x02
33 #define MAX8925_RTC_WEEKDAY 0x03
34 #define MAX8925_RTC_DATE 0x04
35 #define MAX8925_RTC_MONTH 0x05
36 #define MAX8925_RTC_YEAR1 0x06
37 #define MAX8925_RTC_YEAR2 0x07
38 #define MAX8925_ALARM0_SEC 0x08
39 #define MAX8925_ALARM0_MIN 0x09
40 #define MAX8925_ALARM0_HOUR 0x0a
41 #define MAX8925_ALARM0_WEEKDAY 0x0b
42 #define MAX8925_ALARM0_DATE 0x0c
43 #define MAX8925_ALARM0_MON 0x0d
44 #define MAX8925_ALARM0_YEAR1 0x0e
45 #define MAX8925_ALARM0_YEAR2 0x0f
46 #define MAX8925_ALARM1_SEC 0x10
47 #define MAX8925_ALARM1_MIN 0x11
48 #define MAX8925_ALARM1_HOUR 0x12
49 #define MAX8925_ALARM1_WEEKDAY 0x13
50 #define MAX8925_ALARM1_DATE 0x14
51 #define MAX8925_ALARM1_MON 0x15
52 #define MAX8925_ALARM1_YEAR1 0x16
53 #define MAX8925_ALARM1_YEAR2 0x17
54 #define MAX8925_RTC_CNTL 0x1b
55 #define MAX8925_RTC_STATUS 0x20
58 #define ALARM_1SEC (1 << 7)
59 #define HOUR_12 (1 << 7)
60 #define HOUR_AM_PM (1 << 5)
61 #define ALARM0_IRQ (1 << 3)
62 #define ALARM1_IRQ (1 << 2)
63 #define ALARM0_STATUS (1 << 2)
64 #define ALARM1_STATUS (1 << 1)
85 static int tm_calc(
struct rtc_time *
tm,
unsigned char *
buf,
int len)
114 static int data_calc(
unsigned char *buf,
struct rtc_time *tm,
int len)
121 high = (tm->
tm_year + 1900) / 1000;
122 low = (tm->
tm_year + 1900) / 100;
123 low = low - high * 10;
125 high = (tm->
tm_year + 1900) / 10;
127 low = low - high * 10;
128 high = high - (high / 10) * 10;
132 low = low - high * 10;
136 low = low - high * 10;
141 low = low - high * 10;
145 low = low - high * 10;
146 buf[
RTC_MIN] = (high << 4) + low;
149 low = low - high * 10;
150 buf[
RTC_SEC] = (high << 4) + low;
168 static int max8925_rtc_set_time(
struct device *dev,
struct rtc_time *tm)
182 static int max8925_rtc_read_alarm(
struct device *dev,
struct rtc_wkalrm *alrm)
220 static int max8925_rtc_set_alarm(
struct device *dev,
struct rtc_wkalrm *alrm)
244 .read_time = max8925_rtc_read_time,
245 .set_time = max8925_rtc_set_time,
246 .read_alarm = max8925_rtc_read_alarm,
247 .set_alarm = max8925_rtc_set_alarm,
267 dev_err(chip->
dev,
"Failed to request IRQ: #%d: %d\n",
274 platform_set_drvdata(pdev, info);
282 dev_err(&pdev->
dev,
"Failed to register RTC device: %d\n", ret);
288 platform_set_drvdata(pdev,
NULL);
307 #ifdef CONFIG_PM_SLEEP
308 static int max8925_rtc_suspend(
struct device *dev)
313 if (device_may_wakeup(dev))
317 static int max8925_rtc_resume(
struct device *dev)
322 if (device_may_wakeup(dev))
328 static SIMPLE_DEV_PM_OPS(max8925_rtc_pm_ops, max8925_rtc_suspend, max8925_rtc_resume);
332 .name =
"max8925-rtc",
334 .pm = &max8925_rtc_pm_ops,
336 .probe = max8925_rtc_probe,