2009-01-05 17:36:35

by Ed Swierk

[permalink] [raw]
Subject: [PATCH] rtc-ds1307: True SMBus compatibility

Following up to Sebastien Barre's recent patch, here I go one step
further, replacing i2c block transfers with SMBus byte transfers.
Sticking to pure SMBus makes the driver work on our board, which has an
nVidia SMBus controller driving a DS1339; nforce2 controllers
unfortunately don't support any flavor of i2c block transfer.

Reading or writing registers repeatedly until they stick is rather
nauseating but I'm aiming for correctness if not elegance. I would
appreciate any suggestions for improvement.

Signed-off-by: Ed Swierk <[email protected]>


Attachments:
rtc-ds1307-pure-smbus-compatibility.patch (5.29 kB)

2009-01-06 13:44:49

by BARRE Sebastien

[permalink] [raw]
Subject: RE: [PATCH] rtc-ds1307: True SMBus compatibility

Hello,

> -----Original Message-----
> From: Ed Swierk [mailto:[email protected]]
> Sent: Monday, January 05, 2009 6:36 PM
> To: [email protected]; David Brownell; Alessandro Zummo; linux-
> [email protected]; Andrew Morton; BARRE Sebastien
> Subject: [PATCH] rtc-ds1307: True SMBus compatibility
>
> Following up to Sebastien Barre's recent patch, here I go one step
> further, replacing i2c block transfers with SMBus byte transfers.
> Sticking to pure SMBus makes the driver work on our board, which has an
> nVidia SMBus controller driving a DS1339; nforce2 controllers
> unfortunately don't support any flavor of i2c block transfer.
>
> Reading or writing registers repeatedly until they stick is rather
> nauseating but I'm aiming for correctness if not elegance. I would
> appreciate any suggestions for improvement.
>
> Signed-off-by: Ed Swierk <[email protected]>

I've read your patch quicly, I will test it on my board as soon as possible.

> +static s32 ds1307_write_block_data(struct i2c_client *client, u8 command,
> + u8 length, const u8 *values)
> +{
> + u8 currvalues[I2C_SMBUS_BLOCK_MAX];
> + s32 ret;
> + pr_debug("ds1307_write_block_data (length=%d)\n", length);

You can delete the next 3 lines, they are not useful:

> + ret = ds1307_read_block_data_once(client, command, length, currvalues);
> + if (ret < 0)
> + return ret;

> + do {
> + s32 i, ret;
> + for (i = 0; i < length; i++) {
> + ret = i2c_smbus_write_byte_data(client, command + i,
> + *(values + i));
> + if (ret < 0)
> + return ret;
> + }
> + ret = ds1307_read_block_data_once(client, command, length, currvalues);
> + if (ret < 0)
> + return ret;
> + } while (memcmp(currvalues, values, length));
> + return length;
> +}

--
Sébastien Barré
Bureau d'étude - Développement
SDEL Contrôle Commande
D2A - Rue Nungesser et Coli
44860 Saint Aignan de Grand Lieu
FRANCE
Tél : +33(0)2 40 84 50 88
Fax : +33(0)2 40 84 51 10
????{.n?+???????+%?????ݶ??w??{.n?+????{??G?????{ay?ʇڙ?,j??f???h?????????z_??(?階?ݢj"???m??????G????????????&???~???iO???z??v?^?m???? ????????I?

2009-01-06 22:06:46

by Alessandro Zummo

[permalink] [raw]
Subject: Re: [PATCH] rtc-ds1307: True SMBus compatibility

On Tue, 6 Jan 2009 14:35:05 +0100
BARRE Sebastien <[email protected]> wrote:

> > Reading or writing registers repeatedly until they stick is rather
> > nauseating but I'm aiming for correctness if not elegance. I would
> > appreciate any suggestions for improvement.
> >
> > Signed-off-by: Ed Swierk <[email protected]>
>
> I've read your patch quicly, I will test it on my board as soon as possible.

Ok, I'll wait for a Tested-by before acking it.

--

Best regards,

Alessandro Zummo,
Tower Technologies - Torino, Italy

http://www.towertech.it

2009-01-06 22:25:59

by Ed Swierk

[permalink] [raw]
Subject: Re: [PATCH] rtc-ds1307: True SMBus compatibility

On Tue, Jan 6, 2009 at 5:35 AM, BARRE Sebastien <[email protected]> wrote:
> I've read your patch quicly, I will test it on my board as soon as possible.

Thanks.

> You can delete the next 3 lines, they are not useful:
>
>> + ret = ds1307_read_block_data_once(client, command, length, currvalues);
>> + if (ret < 0)
>> + return ret;

Oops! Here is an updated patch with these lines removed, and a minor formatting fix.

Signed-off-by: Ed Swierk <[email protected]>

--Ed


Attachments:
rtc-ds1307-pure-smbus-compatibility.patch (5.19 kB)

2009-01-07 14:23:38

by BARRE Sebastien

[permalink] [raw]
Subject: RE: [PATCH] rtc-ds1307: True SMBus compatibility

> -----Original Message-----
> From: Ed Swierk [mailto:[email protected]]
> Sent: Tuesday, January 06, 2009 11:14 PM
> To: BARRE Sebastien
> Cc: [email protected]; David Brownell; Alessandro Zummo; linux-
> [email protected]; Andrew Morton
> Subject: Re: [PATCH] rtc-ds1307: True SMBus compatibility
>
> On Tue, Jan 6, 2009 at 5:35 AM, BARRE Sebastien <[email protected]> wrote:
> > I've read your patch quicly, I will test it on my board as soon as
> possible.
>
> Thanks.
>
> > You can delete the next 3 lines, they are not useful:
> >
> >> + ret = ds1307_read_block_data_once(client, command, length,
> currvalues);
> >> + if (ret < 0)
> >> + return ret;
>
> Oops! Here is an updated patch with these lines removed, and a minor
> formatting fix.
>
> Signed-off-by: Ed Swierk <[email protected]>
>
> --Ed

I've tested the patch on my geode LX board with a DS1307 device.
It works well for me.

However I think writing the clock one byte at a time could cause strange behavior when using alarms on device like ds1337.

Tested-by: Sébastien Barré <[email protected]>

--
Sébastien Barré
Bureau d'étude - Développement
SDEL Contrôle Commande
D2A - Rue Nungesser et Coli
44860 Saint Aignan de Grand Lieu
FRANCE
Tél : +33(0)2 40 84 50 88
Fax : +33(0)2 40 84 51 10


????{.n?+???????+%?????ݶ??w??{.n?+????{??G?????{ay?ʇڙ?,j??f???h?????????z_??(?階?ݢj"???m??????G????????????&???~???iO???z??v?^?m???? ????????I?