17 #include <linux/i2c.h>
19 #include <linux/rtc.h>
20 #include <linux/slab.h>
21 #include <linux/module.h>
24 #define DRV_VERSION "0.4.3"
26 #define PCF8563_REG_ST1 0x00
27 #define PCF8563_REG_ST2 0x01
29 #define PCF8563_REG_SC 0x02
30 #define PCF8563_REG_MN 0x03
31 #define PCF8563_REG_HR 0x04
32 #define PCF8563_REG_DM 0x05
33 #define PCF8563_REG_DW 0x06
34 #define PCF8563_REG_MO 0x07
35 #define PCF8563_REG_YR 0x08
37 #define PCF8563_REG_AMN 0x09
38 #define PCF8563_REG_AHR 0x0A
39 #define PCF8563_REG_ADM 0x0B
40 #define PCF8563_REG_ADW 0x0C
42 #define PCF8563_REG_CLKO 0x0D
43 #define PCF8563_REG_TMRC 0x0E
44 #define PCF8563_REG_TMR 0x0F
46 #define PCF8563_SC_LV 0x80
47 #define PCF8563_MO_C 0x80
96 dev_err(&client->
dev,
"%s: read error\n", __func__);
103 "low voltage detected, date/time is not reliable.\n");
107 "%s: raw data is st1=%02x, st2=%02x, sec=%02x, min=%02x, hr=%02x, "
108 "mday=%02x, wday=%02x, mon=%02x, year=%02x\n",
110 buf[0], buf[1], buf[2], buf[3],
111 buf[4], buf[5], buf[6], buf[7],
128 dev_dbg(&client->
dev,
"%s: tm is secs=%d, mins=%d, hours=%d, "
129 "mday=%d, mon=%d, year=%d, wday=%d\n",
138 dev_err(&client->
dev,
"retrieved date/time is not valid.\n");
145 struct pcf8563 *pcf8563 = i2c_get_clientdata(client);
147 unsigned char buf[9];
149 dev_dbg(&client->
dev,
"%s: secs=%d, mins=%d, hours=%d, "
150 "mday=%d, mon=%d, year=%d, wday=%d\n",
173 for (i = 0; i < 7; i++) {
178 if (err !=
sizeof(data)) {
180 "%s: err=%d addr=%02x, data=%02x\n",
181 __func__, err, data[0], data[1]);
189 #ifdef CONFIG_RTC_INTF_DEV
192 struct pcf8563 *pcf8563 = i2c_get_clientdata(
to_i2c_client(dev));
198 dev_info(dev,
"low voltage detected, date/time is not reliable.\n");
224 #define pcf8563_rtc_ioctl NULL
227 static int pcf8563_rtc_read_time(
struct device *dev,
struct rtc_time *tm)
232 static int pcf8563_rtc_set_time(
struct device *dev,
struct rtc_time *tm)
239 .read_time = pcf8563_rtc_read_time,
240 .set_time = pcf8563_rtc_set_time,
243 static int pcf8563_probe(
struct i2c_client *client,
246 struct pcf8563 *pcf8563;
255 pcf8563 = kzalloc(
sizeof(
struct pcf8563),
GFP_KERNEL);
261 i2c_set_clientdata(client, pcf8563);
266 if (IS_ERR(pcf8563->
rtc)) {
267 err = PTR_ERR(pcf8563->
rtc);
279 static int pcf8563_remove(
struct i2c_client *client)
281 struct pcf8563 *pcf8563 = i2c_get_clientdata(client);
300 { .compatible =
"nxp,pcf8563" },
308 .name =
"rtc-pcf8563",
312 .probe = pcf8563_probe,
313 .remove = pcf8563_remove,
314 .id_table = pcf8563_id,