17 #include <linux/module.h>
18 #include <linux/i2c.h>
20 #include <linux/rtc.h>
24 #define RV3029C2_ONOFF_CTRL 0x00
25 #define RV3029C2_IRQ_CTRL 0x01
26 #define RV3029C2_IRQ_CTRL_AIE (1 << 0)
27 #define RV3029C2_IRQ_FLAGS 0x02
28 #define RV3029C2_IRQ_FLAGS_AF (1 << 0)
29 #define RV3029C2_STATUS 0x03
30 #define RV3029C2_STATUS_VLOW1 (1 << 2)
31 #define RV3029C2_STATUS_VLOW2 (1 << 3)
32 #define RV3029C2_STATUS_SR (1 << 4)
33 #define RV3029C2_STATUS_PON (1 << 5)
34 #define RV3029C2_STATUS_EEBUSY (1 << 7)
35 #define RV3029C2_RST_CTRL 0x04
36 #define RV3029C2_CONTROL_SECTION_LEN 0x05
39 #define RV3029C2_W_SEC 0x08
40 #define RV3029C2_W_MINUTES 0x09
41 #define RV3029C2_W_HOURS 0x0A
42 #define RV3029C2_REG_HR_12_24 (1<<6)
43 #define RV3029C2_REG_HR_PM (1<<5)
44 #define RV3029C2_W_DATE 0x0B
45 #define RV3029C2_W_DAYS 0x0C
46 #define RV3029C2_W_MONTHS 0x0D
47 #define RV3029C2_W_YEARS 0x0E
48 #define RV3029C2_WATCH_SECTION_LEN 0x07
51 #define RV3029C2_A_SC 0x10
52 #define RV3029C2_A_MN 0x11
53 #define RV3029C2_A_HR 0x12
54 #define RV3029C2_A_DT 0x13
55 #define RV3029C2_A_DW 0x14
56 #define RV3029C2_A_MO 0x15
57 #define RV3029C2_A_YR 0x16
58 #define RV3029C2_ALARM_SECTION_LEN 0x07
61 #define RV3029C2_TIMER_LOW 0x18
62 #define RV3029C2_TIMER_HIGH 0x19
65 #define RV3029C2_TEMP_PAGE 0x20
68 #define RV3029C2_E2P_EEDATA1 0x28
69 #define RV3029C2_E2P_EEDATA2 0x29
72 #define RV3029C2_CONTROL_E2P_EECTRL 0x30
73 #define RV3029C2_TRICKLE_1K (1<<0)
74 #define RV3029C2_TRICKLE_5K (1<<1)
75 #define RV3029C2_TRICKLE_20K (1<<2)
76 #define RV3029C2_TRICKLE_80K (1<<3)
77 #define RV3029C2_CONTROL_E2P_XTALOFFSET 0x31
78 #define RV3029C2_CONTROL_E2P_QCOEF 0x32
79 #define RV3029C2_CONTROL_E2P_TURNOVER 0x33
82 #define RV3029C2_USR1_RAM_PAGE 0x38
83 #define RV3029C2_USR1_SECTION_LEN 0x04
84 #define RV3029C2_USR2_RAM_PAGE 0x3C
85 #define RV3029C2_USR2_SECTION_LEN 0x04
123 dev_dbg(&client->
dev,
"status = 0x%.2x (%d)\n", buf[0], buf[0]);
135 dev_dbg(&client->
dev,
"status = 0x%.2x (%d)\n", buf[0], buf[0]);
148 ret = rv3029c2_i2c_get_sr(client, buf);
150 dev_err(&client->
dev,
"%s: reading SR failed\n", __func__);
157 dev_err(&client->
dev,
"%s: reading RTC section failed\n",
197 ret = rv3029c2_i2c_get_sr(client, regs);
199 dev_err(&client->
dev,
"%s: reading SR failed\n", __func__);
207 dev_err(&client->
dev,
"%s: reading alarm section failed\n",
229 static int rv3029c2_rtc_i2c_alarm_set_irq(
struct i2c_client *client,
238 dev_err(&client->
dev,
"can't read INT reg\n");
255 static int rv3029c2_rtc_i2c_set_alarm(
struct i2c_client *client,
270 ret = rv3029c2_i2c_get_sr(client, regs);
272 dev_err(&client->
dev,
"%s: reading SR failed\n", __func__);
295 dev_err(&client->
dev,
"can't read alarm flag\n");
302 dev_err(&client->
dev,
"can't set alarm flag\n");
306 ret = rv3029c2_rtc_i2c_alarm_set_irq(client, 1);
313 ret = rv3029c2_rtc_i2c_alarm_set_irq(client, 1);
317 dev_dbg(&client->
dev,
"alarm IRQ disabled\n");
323 static int rv3029c2_rtc_set_alarm(
struct device *dev,
struct rtc_wkalrm *alarm)
325 return rv3029c2_rtc_i2c_set_alarm(
to_i2c_client(dev), alarm);
355 ret = rv3029c2_i2c_get_sr(client, regs);
357 dev_err(&client->
dev,
"%s: reading SR failed\n", __func__);
363 dev_err(&client->
dev,
"%s: reading SR failed\n", __func__);
370 static int rv3029c2_rtc_set_time(
struct device *dev,
struct rtc_time *tm)
376 .read_time = rv3029c2_rtc_read_time,
377 .set_time = rv3029c2_rtc_set_time,
378 .read_alarm = rv3029c2_rtc_read_alarm,
379 .set_alarm = rv3029c2_rtc_set_alarm,
399 &client->
dev, &rv3029c2_rtc_ops,
405 i2c_set_clientdata(client, rtc);
407 rc = rv3029c2_i2c_get_sr(client, buf);
409 dev_err(&client->
dev,
"reading status failed\n");
410 goto exit_unregister;
423 struct rtc_device *rtc = i2c_get_clientdata(client);
432 .name =
"rtc-rv3029c2",
434 .probe = rv3029c2_probe,
436 .id_table = rv3029c2_id,