Re: [PATCH 2/2] rtc: add rtc-abx80x, a driver for the Abracon AB x80x i2c rtc

From: Alexandre Belloni
Date: Sat Mar 14 2015 - 14:09:21 EST


On 14/03/2015 at 13:44:41 +0100, Philippe De Muyter wrote :
> > + tm->tm_sec = bcd2bin(date[ABX8XX_REG_SC] & 0x7F);
> > + tm->tm_min = bcd2bin(date[ABX8XX_REG_MN] & 0x7F);
> > + tm->tm_hour = bcd2bin(date[ABX8XX_REG_HR] & 0x3F);
> > + tm->tm_wday = date[ABX8XX_REG_WD] & 0x7;
> > + tm->tm_mday = bcd2bin(date[ABX8XX_REG_DA] & 0x3F);
> > + tm->tm_mon = bcd2bin(date[ABX8XX_REG_MO] & 0x1F) - 1;
> > + tm->tm_year = bcd2bin(date[ABX8XX_REG_YR]);
> > + if (tm->tm_year < 70)
>
> Is that still useful for a driver written in 2015 ?
>

I'd say that this is actually the only correct way to do it. Only dates
before 01/01/1970 00:00 are considered invalid. So, unless adding a
check like:

if (tm->tm_year < 100)
return -EINVAL;

in abx80x_rtc_set_time, setting and then reading a date before 2000 will
fail silently. I'm open to add that check.

> > +static int abx80x_rtc_set_time(struct device *dev, struct rtc_time *tm)
> > +{
> > + struct i2c_client *client = to_i2c_client(dev);
> > + int data, err;
> > + unsigned char buf[8];
>
> The link is not clear between 8 above, the symbolic constants below, and 7
> in the call to i2c_smbus_write_i2c_block_data.
>

It is because I didn't bother writing the hundreth of seconds, I'll
change that and the other issues you pointed.


--
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/