rtc: Add NXP PCF8523 support
PATCH v2 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.
---
Changes in v2:
- return an error if the OS flag cannot be cleared
- add comment as to why we clear the OS flag
- restart RTC if setting the time fails
drivers/rtc/Kconfig | 9 ++ drivers/rtc/Makefile | 1 + drivers/rtc/rtc-pcf8523.c | 326 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 336 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 +326 -0
326 lines not on this page · raw message
Signature · 1 line
1.8.0.1
drivers/rtc/rtc-pcf8523.c line 250
Quoted 12 lines · On Wed, 28 Nov 2012 20:21:26 +0100 Thierry Reding…
drivers/rtc/rtc-pcf8523.c new file +12
-0+ err =i2c_transfer (client->adapter, &msg,1 ); +if (err <0 ) { +/* +* If the time cannot be set, restart the RTC anyway. Note +* that errors are ignored if the RTC cannot be started so +* that we have a chance to propagate the original error. +*/ +pcf8523_start_rtc (client); +return err; + } + +return pcf8523_start_rtc (client);
hm, well, that is of course equivalent to
err = i2c_transfer(client->adapter, &msg, 1); pcf8523_start_rtc(client); return err;
but I suppose the code as proposed is clear, extensible, and not our worst-ever sin ;)
Quoted 18 lines · Andrew Morton
drivers/rtc/rtc-pcf8523.c line 250
Quoted 12 lines · On Wed, 28 Nov 2012 20:21:26 +0100 Thierry Reding…
drivers/rtc/rtc-pcf8523.c new file +12
-0+ err =i2c_transfer (client->adapter, &msg,1 ); +if (err <0 ) { +/* +* If the time cannot be set, restart the RTC anyway. Note +* that errors are ignored if the RTC cannot be started so +* that we have a chance to propagate the original error. +*/ +pcf8523_start_rtc (client); +return err; + } + +return pcf8523_start_rtc (client);hm, well, that is of course equivalent to
Quoted 3 lines
err = i2c_transfer(client->adapter, &msg, 1); pcf8523_start_rtc(client); return err;
At the risk of sounding pedantic, it isn't quite the same thing. There is a possibility that i2c_transfer() succeeds but pcf8523_start_rtc() still fails. So in fact we catch errors in i2c_transfer() and from starting the RTC in case the time was properly set. The only error we might loose if if the RTC fails to start after the time cannot be set but in that case there's probably not a whole lot we can do.
Quoted 2 lines
but I suppose the code as proposed is clear, extensible, and not our worst-ever sin ;)
Yes, this is one of the cases where the gain in clarity justifies the extra verbosity. =)
Thierry