[i2c] [PATCH] rtc: RTC class driver for the ds1374

Andrew Morton akpm at linux-foundation.org
Fri Sep 28 02:01:44 CEST 2007


On Thu, 27 Sep 2007 12:19:03 -0500
Scott Wood <scottwood at freescale.com> 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.
> 

I'm impressed by how many new rtc drivers we're getting, and how small and
neat they are, and how little trouble they seem to be causing.  That new
framework seems to have worked out well.

> +static int ds1374_read_rtc(struct i2c_client *client, u32 *time,
> +                           int reg, int nbytes)
> +{
> +	u8 buf[4];
> +	int ret;
> +	int i;
> +
> +	if (nbytes > 4) {
> +		WARN_ON(1);
> +		return -EINVAL;
> +	}
> +
> +	ret = i2c_smbus_read_i2c_block_data(client, reg, nbytes, buf);
> +
> +	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;
> +}

Are we sure that nbytes can never be negative here?

> +static int ds1374_write_rtc(struct i2c_client *client, u32 time,
> +                            int reg, int nbytes)
> +{
> +	u8 buf[4];
> +	int i;
> +
> +	if (nbytes > 4) {
> +		WARN_ON(1);
> +		return -EINVAL;
> +	}
> +
> +	for (i = 0; i < nbytes; i++) {
> +		buf[i] = time & 0xff;
> +		time >>= 8;
> +	}
> +
> +	return i2c_smbus_write_i2c_block_data(client, reg, nbytes, buf);
> +}

and here?




More information about the i2c mailing list