rtc: Add NXP PCF8523 support
PATCH RESEND 1/1 rtc: Add NXP PCF8523 support
This commit adds an RTC driver for PCF8523 chips by NXP Semiconductors. No support is currently provided for the alarm and interrupt functions. Only the time and date functionality is implemented.
---
Hi Andrew,
I'm resending this to you since I just read somewhere else that you're apparently taking RTC patches now.
Thierry
drivers/rtc/Kconfig | 9 ++ drivers/rtc/Makefile | 1 + drivers/rtc/rtc-pcf8523.c | 307 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 317 insertions(+) create mode 100644 drivers/rtc/rtc-pcf8523.c
drivers/rtc/Kconfig +9 -0
@@ -269,6 +269,15 @@ config RTC_DRV_X1205 This driver can also be built as a module. If so, the module will be called rtc-x1205. +config RTC_DRV_PCF8523 + tristate "NXP PCF8523" + help + If you say yes here you get support for the NXP PCF8523 RTC + chips. + + This driver can also be built as a module. If so, the module + will be called rtc-pcf8523. + config RTC_DRV_PCF8563 tristate "Philips PCF8563/Epson RTC8564" help
drivers/rtc/Makefile +1 -0
@@ -76,6 +76,7 @@ obj-$(CONFIG_RTC_DRV_MV) += rtc-mv.o obj-$(CONFIG_RTC_DRV_NUC900) += rtc-nuc900.o obj-$(CONFIG_RTC_DRV_OMAP) += rtc-omap.o obj-$(CONFIG_RTC_DRV_PCAP) += rtc-pcap.o +obj-$(CONFIG_RTC_DRV_PCF8523) += rtc-pcf8523.o obj-$(CONFIG_RTC_DRV_PCF8563) += rtc-pcf8563.o obj-$(CONFIG_RTC_DRV_PCF8583) += rtc-pcf8583.o obj-$(CONFIG_RTC_DRV_PCF2123) += rtc-pcf2123.o
drivers/rtc/rtc-pcf8523.c new file +307 -0
307 lines not on this page · raw message
Signature · 1 line
1.8.0
Quoted 21 lines · On Fri, 23 Nov 2012 16:17:37 +0100 Thierry Reding…
This commit adds an RTC driver for PCF8523 chips by NXP Semiconductors. No support is currently provided for the alarm and interrupt functions. Only the time and date functionality is implemented.
...
drivers/rtc/rtc-pcf8523.c new file +15
-0+static int pcf8523_rtc_read_time (struct device *dev,struct rtc_time *tm) +{ +struct i2c_client *client =to_i2c_client (dev); +u8 start =REG_SECONDS , regs[7 ]; +struct i2c_msg msgs[2 ]; +int err; + + msgs[0 ].addr = client->addr; + msgs[0 ].flags =0 ; + msgs[0 ].len =1 ; + msgs[0 ].buf = &start; + + msgs[1 ].addr = client->addr; + msgs[1 ].flags =I2C_M_RD ; + msgs[1 ].len =sizeof (regs);
drivers/rtc/rtc-pcf8523.c line 183
Quoted 10 lines
drivers/rtc/rtc-pcf8523.c new file +10
-0+ msgs[1 ].buf = regs; + + err =i2c_transfer (client->adapter, msgs,ARRAY_SIZE (msgs)); +if (err <0 ) +return err; + +if (regs[0 ] ®_SECONDS_OS ) { +dev_dbg (dev,"clock integrity is not guaranteed\n" ); + +/* try to clear the flag */
The comment explains the "what", which was pretty obvious from the code.
But readers want to know "why".
Quoted 36 lines
drivers/rtc/rtc-pcf8523.c new file +36
-0+ regs[0 ] &= ~REG_SECONDS_OS ; + + err =pcf8523_write (client,REG_SECONDS , regs[0 ]); +if (err <0 ) +return err; + } + + tm->tm_sec =bcd2bin (regs[0 ] &0x7f ); + tm->tm_min =bcd2bin (regs[1 ] &0x7f ); + tm->tm_hour =bcd2bin (regs[2 ] &0x3f ); + tm->tm_mday =bcd2bin (regs[3 ] &0x3f ); + tm->tm_wday = regs[4 ] &0x7 ; + tm->tm_mon =bcd2bin (regs[5 ] &0x1f ); + tm->tm_year =bcd2bin (regs[6 ]) +100 ; + +return rtc_valid_tm (tm); +} + +static int pcf8523_rtc_set_time (struct device *dev,struct rtc_time *tm) +{ +struct i2c_client *client =to_i2c_client (dev); +struct i2c_msg msg; +u8 regs[8 ]; +int err; + + err =pcf8523_stop_rtc (client); +if (err <0 ) +return err; + + regs[0 ] =REG_SECONDS ; + regs[1 ] =bin2bcd (tm->tm_sec); + regs[2 ] =bin2bcd (tm->tm_min); + regs[3 ] =bin2bcd (tm->tm_hour); + regs[4 ] =bin2bcd (tm->tm_mday); + regs[5 ] = tm->tm_wday; + regs[6 ] =bin2bcd (tm->tm_mon);
drivers/rtc/rtc-pcf8523.c line 229
Quoted 10 lines
drivers/rtc/rtc-pcf8523.c new file +10
-0+ regs[7 ] =bin2bcd (tm->tm_year -100 ); + + msg.addr = client->addr; + msg.flags =0 ; + msg.len =sizeof (regs); + msg.buf = regs; + + err =i2c_transfer (client->adapter, &msg,1 ); +if (err <0 ) +return err;
Should we restart the rtc if the transfer failed?
Quoted 5 lines
drivers/rtc/rtc-pcf8523.c new file +2
-0+return pcf8523_start_rtc (client); +}