diff mbox series

[v2,1/5] iio: light: vcnl4000 use word writes instead of byte writes

Message ID 20190317154802.15174-2-angus@akkea.ca (mailing list archive)
State New, archived
Headers show
Series Add a VCNL4040 light and proximity driver | expand

Commit Message

Angus Ainslie March 17, 2019, 3:47 p.m. UTC
The VCNL4200 datasheet says that word read and writes should be used
to access the registers.

Signed-off-by: Angus Ainslie (Purism) <angus@akkea.ca>
---
 drivers/iio/light/vcnl4000.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Tomas Novotny March 20, 2019, 2:53 p.m. UTC | #1
Hi Angus,

On Sun, 17 Mar 2019 08:47:58 -0700
"Angus Ainslie (Purism)" <angus@akkea.ca> wrote:

> The VCNL4200 datasheet says that word read and writes should be used
> to access the registers.
> 
> Signed-off-by: Angus Ainslie (Purism) <angus@akkea.ca>
> ---
>  drivers/iio/light/vcnl4000.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/light/vcnl4000.c b/drivers/iio/light/vcnl4000.c
> index 04fd0d4b6f19..5295330b65e2 100644
> --- a/drivers/iio/light/vcnl4000.c
> +++ b/drivers/iio/light/vcnl4000.c
> @@ -140,10 +140,10 @@ static int vcnl4200_init(struct vcnl4000_data *data)
>  	data->rev = (ret >> 8) & 0xf;
>  
>  	/* Set defaults and enable both channels */
> -	ret = i2c_smbus_write_byte_data(data->client, VCNL4200_AL_CONF, 0x00);
> +	ret = i2c_smbus_write_word_data(data->client, VCNL4200_AL_CONF, 0x00);

minor note: the 0x00 looks like a byte. 0 or 0x0000 would be slightly better?
The same below.

>  	if (ret < 0)
>  		return ret;
> -	ret = i2c_smbus_write_byte_data(data->client, VCNL4200_PS_CONF1, 0x00);
> +	ret = i2c_smbus_write_word_data(data->client, VCNL4200_PS_CONF1, 0x00);

The VCNL4200_PS_CONF1 definition is a bit misleading with word write. Because
PS_CONF1 is only a low byte of command code 0x03. The high byte of 0x03 is
PS_CONF2. I would rename it.

>  	if (ret < 0)
>  		return ret;

Anyway, the main point is that I've tested this patch on VCNL4200 and it
works, so:
Tested-by: Tomas Novotny <tomas@novotny.cz>

T.
Angus Ainslie March 20, 2019, 8:21 p.m. UTC | #2
Hi Tomas,

On 2019-03-20 07:53, Tomas Novotny wrote:
> Hi Angus,
> 
> On Sun, 17 Mar 2019 08:47:58 -0700
> "Angus Ainslie (Purism)" <angus@akkea.ca> wrote:
> 
>> The VCNL4200 datasheet says that word read and writes should be used
>> to access the registers.
>> 
>> Signed-off-by: Angus Ainslie (Purism) <angus@akkea.ca>
>> ---
>>  drivers/iio/light/vcnl4000.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>> 
>> diff --git a/drivers/iio/light/vcnl4000.c 
>> b/drivers/iio/light/vcnl4000.c
>> index 04fd0d4b6f19..5295330b65e2 100644
>> --- a/drivers/iio/light/vcnl4000.c
>> +++ b/drivers/iio/light/vcnl4000.c
>> @@ -140,10 +140,10 @@ static int vcnl4200_init(struct vcnl4000_data 
>> *data)
>>  	data->rev = (ret >> 8) & 0xf;
>> 
>>  	/* Set defaults and enable both channels */
>> -	ret = i2c_smbus_write_byte_data(data->client, VCNL4200_AL_CONF, 
>> 0x00);
>> +	ret = i2c_smbus_write_word_data(data->client, VCNL4200_AL_CONF, 
>> 0x00);
> 
> minor note: the 0x00 looks like a byte. 0 or 0x0000 would be slightly 
> better?
> The same below.
> 
>>  	if (ret < 0)
>>  		return ret;
>> -	ret = i2c_smbus_write_byte_data(data->client, VCNL4200_PS_CONF1, 
>> 0x00);
>> +	ret = i2c_smbus_write_word_data(data->client, VCNL4200_PS_CONF1, 
>> 0x00);
> 
> The VCNL4200_PS_CONF1 definition is a bit misleading with word write. 
> Because
> PS_CONF1 is only a low byte of command code 0x03. The high byte of 0x03 
> is
> PS_CONF2. I would rename it.
> 

As far as a base address for the register that is correct based on the 
names in the datasheet. I suppose I could add something like:

#define VCNL4200_PS_CONF  VCNL4200_PS_CONF1

and change the reference here if you think that would be more clear.

>>  	if (ret < 0)
>>  		return ret;
> 
> Anyway, the main point is that I've tested this patch on VCNL4200 and 
> it
> works, so:
> Tested-by: Tomas Novotny <tomas@novotny.cz>
> 
> T.

Thanks for testing it
Angus
Tomas Novotny March 21, 2019, 2:28 p.m. UTC | #3
Hi Angus,

On Wed, 20 Mar 2019 13:21:58 -0700
Angus Ainslie <angus@akkea.ca> wrote:

> Hi Tomas,
> 
> On 2019-03-20 07:53, Tomas Novotny wrote:
> > Hi Angus,
> > 
> > On Sun, 17 Mar 2019 08:47:58 -0700
> > "Angus Ainslie (Purism)" <angus@akkea.ca> wrote:
> >   
> >> The VCNL4200 datasheet says that word read and writes should be used
> >> to access the registers.
> >> 
> >> Signed-off-by: Angus Ainslie (Purism) <angus@akkea.ca>
> >> ---
> >>  drivers/iio/light/vcnl4000.c | 4 ++--
> >>  1 file changed, 2 insertions(+), 2 deletions(-)
> >> 
> >> diff --git a/drivers/iio/light/vcnl4000.c 
> >> b/drivers/iio/light/vcnl4000.c
> >> index 04fd0d4b6f19..5295330b65e2 100644
> >> --- a/drivers/iio/light/vcnl4000.c
> >> +++ b/drivers/iio/light/vcnl4000.c
> >> @@ -140,10 +140,10 @@ static int vcnl4200_init(struct vcnl4000_data 
> >> *data)
> >>  	data->rev = (ret >> 8) & 0xf;
> >> 
> >>  	/* Set defaults and enable both channels */
> >> -	ret = i2c_smbus_write_byte_data(data->client, VCNL4200_AL_CONF, 
> >> 0x00);
> >> +	ret = i2c_smbus_write_word_data(data->client, VCNL4200_AL_CONF, 
> >> 0x00);  
> > 
> > minor note: the 0x00 looks like a byte. 0 or 0x0000 would be slightly 
> > better?
> > The same below.
> >   
> >>  	if (ret < 0)
> >>  		return ret;
> >> -	ret = i2c_smbus_write_byte_data(data->client, VCNL4200_PS_CONF1, 
> >> 0x00);
> >> +	ret = i2c_smbus_write_word_data(data->client, VCNL4200_PS_CONF1, 
> >> 0x00);  
> > 
> > The VCNL4200_PS_CONF1 definition is a bit misleading with word write. 
> > Because
> > PS_CONF1 is only a low byte of command code 0x03. The high byte of 0x03 
> > is
> > PS_CONF2. I would rename it.
> >   
> 
> As far as a base address for the register that is correct based on the 
> names in the datasheet. I suppose I could add something like:
> 
> #define VCNL4200_PS_CONF  VCNL4200_PS_CONF1
>
> and change the reference here if you think that would be more clear.

to be honest, I don't know the best practice. As there is also PS_CONF3, I
was thinking about PS_CONF1_2, but thinking again, your current name is good
enough maybe.

Tomas

> >>  	if (ret < 0)
> >>  		return ret;  
> > 
> > Anyway, the main point is that I've tested this patch on VCNL4200 and 
> > it
> > works, so:
> > Tested-by: Tomas Novotny <tomas@novotny.cz>
> > 
> > T.  
> 
> Thanks for testing it
> Angus
>
diff mbox series

Patch

diff --git a/drivers/iio/light/vcnl4000.c b/drivers/iio/light/vcnl4000.c
index 04fd0d4b6f19..5295330b65e2 100644
--- a/drivers/iio/light/vcnl4000.c
+++ b/drivers/iio/light/vcnl4000.c
@@ -140,10 +140,10 @@  static int vcnl4200_init(struct vcnl4000_data *data)
 	data->rev = (ret >> 8) & 0xf;
 
 	/* Set defaults and enable both channels */
-	ret = i2c_smbus_write_byte_data(data->client, VCNL4200_AL_CONF, 0x00);
+	ret = i2c_smbus_write_word_data(data->client, VCNL4200_AL_CONF, 0x00);
 	if (ret < 0)
 		return ret;
-	ret = i2c_smbus_write_byte_data(data->client, VCNL4200_PS_CONF1, 0x00);
+	ret = i2c_smbus_write_word_data(data->client, VCNL4200_PS_CONF1, 0x00);
 	if (ret < 0)
 		return ret;