On Dec 12, 2007 8:23 AM, Andrew Morton <[email protected]> wrote:
> On Thu, 6 Dec 2007 22:10:27 +0000 Byron Bradley <[email protected]> wrote:
>
> > 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.
>
> > +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.
> Could you review and runtime test this please?
>
> --- a/drivers/rtc/rtc-s35390a.c~rtc-add-support-for-the-s-35390a-rtc-chip-fix
> +++ a/drivers/rtc/rtc-s35390a.c
> @@ -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 s35390a
> return 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]);
> _
The above patch works as expected.
Thanks,
--
Byron Bradley
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[Index of Archives]
[Kernel Newbies]
[Netfilter]
[Bugtraq]
[Photo]
[Stuff]
[Gimp]
[Yosemite News]
[MIPS Linux]
[ARM Linux]
[Linux Security]
[Linux RAID]
[Video 4 Linux]
[Linux for the blind]
[Linux Resources]