[i2c] [PATCH v3] rtc: RTC class driver for the ds1374
Jean Delvare
khali at linux-fr.org
Wed Aug 15 18:27:43 CEST 2007
Hi Scott,
On Wed, 18 Jul 2007 17:28:18 -0500, Scott Wood wrote:
> This patch adds an RTC class driver for the Maxim/Dallas 1374 RTC chip,
> based on drivers/i2c/chips/ds1374.c. It supports alarm functionality.
>
> Signed-off-by: Scott Wood <scottwood at freescale.com>
Looks good, just one thing:
> +static int ds1374_read_rtc(struct i2c_client *client, u32 *time,
> + int reg, int nbytes)
> +{
> + u8 buf[4];
> + int ret = i2c_smbus_read_i2c_block_data(client, reg, 4, buf);
Shouldn't you read "nbytes" bytes here rather than hardcoding 4?
> + int i;
> +
> + if (ret < 0)
> + return ret;
> + if (ret < nbytes)
> + return -EIO;
> +
> + for (i = nbytes - 1, *time = 0; i >= 0; i--)
> + *time = (*time << 8) | buf[i];
> +
> + return 0;
> +}
> +
> +static int ds1374_write_rtc(struct i2c_client *client, u32 time,
> + int reg, int nbytes)
> +{
> + u8 buf[4];
> + int i;
> +
> + for (i = 0; i < nbytes; i++) {
> + buf[i] = time & 0xff;
> + time >>= 8;
> + }
> +
> + return i2c_smbus_write_i2c_block_data(client, reg, nbytes, buf);
> +}
--
Jean Delvare
More information about the i2c
mailing list