Add support for the S-35390A RTC chip.
PATCH 1/1 Add support for the S-35390A RTC chip.
This adds basic get/set time support for the Seiko Instruments S-35390A. This chip communicates using I2C and is used on the QNAP TS-109/TS-209 NAS devices.
--- drivers/rtc/Kconfig | 9 ++ drivers/rtc/Makefile | 1 + drivers/rtc/rtc-s35390a.c | 302 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 312 insertions(+), 0 deletions(-) create mode 100644 drivers/rtc/rtc-s35390a.c
drivers/rtc/Kconfig +9 -0
@@ -246,6 +246,15 @@ config RTC_DRV_TWL92330 platforms. The support is integrated with the rest of the Menelaus driver; it's not separate module. +config RTC_DRV_S35390A + tristate "Seiko Instruments S-35390A" + help + If you say yes here you will get support for the Seiko + Instruments S-35390A. + + This driver can also be built as a module. If so the module + will be called rtc-s35390a. + endif # I2C comment "SPI RTC drivers"
drivers/rtc/Makefile +1 -0
@@ -41,6 +41,7 @@ obj-$(CONFIG_RTC_DRV_PL031) += rtc-pl031.o obj-$(CONFIG_RTC_DRV_RS5C313) += rtc-rs5c313.o obj-$(CONFIG_RTC_DRV_RS5C348) += rtc-rs5c348.o obj-$(CONFIG_RTC_DRV_RS5C372) += rtc-rs5c372.o +obj-$(CONFIG_RTC_DRV_S35390A) += rtc-s35390a.o obj-$(CONFIG_RTC_DRV_S3C) += rtc-s3c.o obj-$(CONFIG_RTC_DRV_SA1100) += rtc-sa1100.o obj-$(CONFIG_RTC_DRV_SH) += rtc-sh.o
drivers/rtc/rtc-s35390a.c new file +302 -0
302 lines not on this page · raw message
Signature · 1 line
1.5.3.5
Quoted 4 lines · On Thu, 6 Dec 2007 22:10:27 +0000 Byron Bradley <[email protected]>…
This adds basic get/set time support for the Seiko Instruments S-35390A. This chip communicates using I2C and is used on the QNAP TS-109/TS-209 NAS devices.
A nice looking little driver.
Review
Quoted 6 lines
(quoted diff) +6
-0+static inline char reverse(char x) +{ + x = ((x >> 1) & 0x55) | ((x << 1) & 0xaa); + x = ((x >> 2) & 0x33) | ((x << 2) & 0xcc); + return (x >> 4) | (x << 4); +}
Please take a peek in include/linux/bitrev.h ;)
(I worry about the handling of right-shift-of-negative-values in your version, too).
Could you review and runtime test this please?
drivers/rtc/rtc-s35390a.c renamed from drivers/rtc/rtc-s35390a.c~rtc-add-support-for-the-s-35390a-rtc-chip-fix +3 -9
@@ -12,6 +12,7 @@#include <linux/module.h> #include <linux/rtc.h> #include <linux/i2c.h> +#include <linux/bitrev.h> #include <linux/bcd.h> #define S35390A_CMD_STATUS1 0
@@ -121,13 +122,6 @@ static int s35390a_reg2hr(struct s35390areturn hour; } -static inline char reverse (char x) -{ - x = ((x >>1 ) &0x55 ) | ((x <<1 ) &0xaa ); - x = ((x >>2 ) &0x33 ) | ((x <<2 ) &0xcc ); -return (x >>4 ) | (x <<4 ); -} -static int s35390a_set_datetime (struct i2c_client *client,struct rtc_time *tm) {struct s35390a *s35390a =i2c_get_clientdata (client);
@@ -149,7 +143,7 @@ static int s35390a_set_datetime(struct i/* This chip expects the bits of each byte to be in reverse order */ for (i =0 ; i <7 ; ++i) - buf[i] =reverse (buf[i]); + buf[i] =bitrev8 (buf[i]); err =s35390a_set_reg (s35390a,S35390A_CMD_TIME1 , buf,sizeof (buf));
@@ -168,7 +162,7 @@ static int s35390a_get_datetime(struct i/* This chip returns the bits of each byte in reverse order */ for (i =0 ; i <7 ; ++i) - buf[i] =reverse (buf[i]); + buf[i] =bitrev8 (buf[i]); tm->tm_sec =BCD2BIN (buf[S35390A_BYTE_SECS ]); tm->tm_min =BCD2BIN (buf[S35390A_BYTE_MINS ]);
_
Quoted 9 lines · Andrew Morton
Quoted 4 lines · On Thu, 6 Dec 2007 22:10:27 +0000 Byron Bradley <[email protected]>…
This adds basic get/set time support for the Seiko Instruments S-35390A. This chip communicates using I2C and is used on the QNAP TS-109/TS-209 NAS devices.
A nice looking little driver.
Quoted 8 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+static inline char reverse(char x) +{ + x = ((x >> 1) & 0x55) | ((x << 1) & 0xaa); + x = ((x >> 2) & 0x33) | ((x << 2) & 0xcc); + return (x >> 4) | (x << 4); +}Please take a peek in
include/linux/bitrev.h;)
Thanks Andrew, I knew there must have been a function to do this somewhere but all I could find were the swab functions.
Quoted 44 lines
Could you review and runtime test this please?
drivers/rtc/rtc-s35390a.c renamed from drivers/rtc/rtc-s35390a.c~rtc-add-support-for-the-s-35390a-rtc-chip-fix +3
-9@@ -12,6 +12,7 @@#include <linux/module.h> #include <linux/rtc.h> #include <linux/i2c.h> +#include <linux/bitrev.h> #include <linux/bcd.h> #define S35390A_CMD_STATUS1 0@@ -121,13 +122,6 @@ static int s35390a_reg2hr(struct s35390areturn hour; } -static inline char reverse (char x) -{ - x = ((x >>1 ) &0x55 ) | ((x <<1 ) &0xaa ); - x = ((x >>2 ) &0x33 ) | ((x <<2 ) &0xcc ); -return (x >>4 ) | (x <<4 ); -} -static int s35390a_set_datetime (struct i2c_client *client,struct rtc_time *tm) {struct s35390a *s35390a =i2c_get_clientdata (client);@@ -149,7 +143,7 @@ static int s35390a_set_datetime(struct i/* This chip expects the bits of each byte to be in reverse order */ for (i =0 ; i <7 ; ++i) - buf[i] =reverse (buf[i]); + buf[i] =bitrev8 (buf[i]); err =s35390a_set_reg (s35390a,S35390A_CMD_TIME1 , buf,sizeof (buf));@@ -168,7 +162,7 @@ static int s35390a_get_datetime(struct i/* This chip returns the bits of each byte in reverse order */ for (i =0 ; i <7 ; ++i) - buf[i] =reverse (buf[i]); + buf[i] =bitrev8 (buf[i]); tm->tm_sec =BCD2BIN (buf[S35390A_BYTE_SECS ]); tm->tm_min =BCD2BIN (buf[S35390A_BYTE_MINS ]);
Quoted 1 line
_
The above patch works as expected.
Thanks,
Signature · 1 line
Byron Bradley