12 #include <linux/module.h>
13 #include <linux/i2c.h>
14 #include <linux/rtc.h>
16 #include <linux/slab.h>
18 #define FM3130_RTC_CONTROL (0x0)
19 #define FM3130_CAL_CONTROL (0x1)
20 #define FM3130_RTC_SECONDS (0x2)
21 #define FM3130_RTC_MINUTES (0x3)
22 #define FM3130_RTC_HOURS (0x4)
23 #define FM3130_RTC_DAY (0x5)
24 #define FM3130_RTC_DATE (0x6)
25 #define FM3130_RTC_MONTHS (0x7)
26 #define FM3130_RTC_YEARS (0x8)
28 #define FM3130_ALARM_SECONDS (0x9)
29 #define FM3130_ALARM_MINUTES (0xa)
30 #define FM3130_ALARM_HOURS (0xb)
31 #define FM3130_ALARM_DATE (0xc)
32 #define FM3130_ALARM_MONTHS (0xd)
33 #define FM3130_ALARM_WP_CONTROL (0xe)
35 #define FM3130_CAL_CONTROL_BIT_nOSCEN (1 << 7)
36 #define FM3130_RTC_CONTROL_BIT_LB (1 << 7)
37 #define FM3130_RTC_CONTROL_BIT_AF (1 << 6)
38 #define FM3130_RTC_CONTROL_BIT_CF (1 << 5)
39 #define FM3130_RTC_CONTROL_BIT_POR (1 << 4)
40 #define FM3130_RTC_CONTROL_BIT_AEN (1 << 3)
41 #define FM3130_RTC_CONTROL_BIT_CAL (1 << 2)
42 #define FM3130_RTC_CONTROL_BIT_WRITE (1 << 1)
43 #define FM3130_RTC_CONTROL_BIT_READ (1 << 0)
45 #define FM3130_CLOCK_REGS 7
46 #define FM3130_ALARM_REGS 5
64 #define FM3130_MODE_NORMAL 0
65 #define FM3130_MODE_WRITE 1
66 #define FM3130_MODE_READ 2
87 dev_dbg(dev,
"invalid mode %d\n", mode);
113 dev_err(dev,
"%s error %d\n",
"read", tmp);
119 dev_dbg(dev,
"%s: %02x %02x %02x %02x %02x %02x %02x %02x"
120 "%02x %02x %02x %02x %02x %02x %02x\n",
143 dev_dbg(dev,
"%s secs=%d, mins=%d, "
144 "hours=%d, mday=%d, mon=%d, year=%d, wday=%d\n",
154 static int fm3130_set_time(
struct device *dev,
struct rtc_time *t)
160 dev_dbg(dev,
"%s secs=%d, mins=%d, "
161 "hours=%d, mday=%d, mon=%d, year=%d, wday=%d\n",
178 dev_dbg(dev,
"%s: %02x %02x %02x %02x %02x %02x %02x"
179 "%02x %02x %02x %02x %02x %02x %02x %02x\n",
180 "write", buf[0], buf[1], buf[2], buf[3],
181 buf[4], buf[5], buf[6], buf[7],
182 buf[8], buf[9], buf[0xa], buf[0
xb],
183 buf[0
xc], buf[0xd], buf[0
xe]);
222 dev_err(dev,
"%s error %d\n",
"read", tmp);
225 dev_dbg(dev,
"alarm read %02x %02x %02x %02x %02x\n",
241 dev_dbg(dev,
"%s secs=%d, mins=%d, "
242 "hours=%d, mday=%d, mon=%d, year=%d, wday=%d\n",
266 dev_dbg(dev,
"%s secs=%d, mins=%d, "
267 "hours=%d, mday=%d, mon=%d, year=%d, wday=%d\n",
287 dev_dbg(dev,
"alarm write %02x %02x %02x %02x %02x\n",
322 static int fm3130_alarm_irq_enable(
struct device *dev,
unsigned int enabled)
330 dev_dbg(dev,
"alarm_irq_enable: enable=%d, FM3130_RTC_CONTROL=%02x\n",
355 .read_time = fm3130_get_time,
356 .set_time = fm3130_set_time,
357 .read_alarm = fm3130_read_alarm,
358 .set_alarm = fm3130_set_alarm,
359 .alarm_irq_enable = fm3130_alarm_irq_enable,
367 struct fm3130 *fm3130;
372 if (!i2c_check_functionality(adapter,
376 fm3130 = kzalloc(
sizeof(
struct fm3130),
GFP_KERNEL);
382 i2c_set_clientdata(client, fm3130);
387 fm3130->
msg[0].addr = client->
addr;
388 fm3130->
msg[0].flags = 0;
389 fm3130->
msg[0].len = 1;
392 fm3130->
msg[1].addr = client->
addr;
398 fm3130->
msg[2].addr = client->
addr;
399 fm3130->
msg[2].flags = 0;
400 fm3130->
msg[2].len = 1;
403 fm3130->
msg[3].addr = client->
addr;
427 ~(FM3130_RTC_CONTROL_BIT_CAL));
428 dev_warn(&client->
dev,
"Disabling calibration mode!\n");
436 ~(FM3130_RTC_CONTROL_BIT_READ |
438 dev_warn(&client->
dev,
"Disabling READ or WRITE mode!\n");
445 ~(FM3130_CAL_CONTROL_BIT_nOSCEN));
451 ~(FM3130_RTC_CONTROL_BIT_LB));
459 ~FM3130_RTC_CONTROL_BIT_POR);
479 if (tmp == 0 || tmp > 31)
483 if (tmp == 0 || tmp > 12)
504 if (tmp == 0 || tmp > 7)
508 if (tmp == 0 || tmp > 31)
512 if (tmp == 0 || tmp > 12)
521 "%s: %02x %02x %02x %02x %02x %02x %02x %02x"
522 "%02x %02x %02x %02x %02x %02x %02x\n",
537 if (IS_ERR(fm3130->
rtc)) {
538 err = PTR_ERR(fm3130->
rtc);
540 "unable to register the class device\n");
551 struct fm3130 *fm3130 = i2c_get_clientdata(client);
560 .name =
"rtc-fm3130",
563 .probe = fm3130_probe,
565 .id_table = fm3130_id,