iio: humidity: hdc100x: use i2c_master_recv to read sensor data
PATCH 1/1 iio: humidity: hdc100x: use i2c_master_recv to read sensor data
Replace the i2c_smbus_read_byte commmands used to retrieve the sensor data with an i2c_master_recv command.
The smbus read byte method fails because the device does not expect a stop condition after sending the first byte. When we issue the second read, we are getting the first byte again. Net effect is that of the 14 bits used for the measurement, the 8 most significant bits are correct, the lower 6 are not.
None of the smbus read protocols follow the pattern this device requires (S Addr Rd [A] Data [A] Data NA P), hence the switch to an i2c receive transaction.
--- drivers/iio/humidity/hdc100x.c | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-)
drivers/iio/humidity/hdc100x.c +7 -20
@@ -142,7 +142,7 @@ static int hdc100x_get_measurement(struct hdc100x_data *data,struct i2c_client *client = data->client;int delay = data->adc_int_us[chan->address];int ret; -int val; +u8 buf[2 ];/* start measurement */ ret =i2c_smbus_write_byte (client, chan->address);
@@ -154,26 +154,13 @@ static int hdc100x_get_measurement(struct hdc100x_data *data,/* wait for integration time to pass */ usleep_range (delay, delay +1000 ); -/* -* i2c_smbus_read_word_data cannot() be used here due to the command -* value not being understood and causes NAKs preventing any reading -* from being accessed. -*/ - ret =i2c_smbus_read_byte (client); +/* read the 2 byte measurement */ + ret =i2c_master_recv (data->client, buf,2 );if (ret <0 ) { -dev_err (&client->dev,"cannot read high byte measurement" ); +dev_err (&client->dev,"cannot read sensor data\n" );return ret; } - val = ret <<8 ; - - ret =i2c_smbus_read_byte (client); -if (ret <0 ) { -dev_err (&client->dev,"cannot read low byte measurement" ); -return ret; - } - val |= ret; - -return val; +return (int )(buf[0 ] <<8 | buf[1 ]); }static int hdc100x_get_heater_status (struct hdc100x_data *data)
@@ -272,8 +259,8 @@ static int hdc100x_probe(struct i2c_client *client,struct iio_dev *indio_dev;struct hdc100x_data *data; -if (!i2c_check_functionality (client->adapter, -I2C_FUNC_SMBUS_WORD_DATA |I2C_FUNC_SMBUS_BYTE )) +if (!i2c_check_functionality (client->adapter,I2C_FUNC_SMBUS_WORD_DATA | +I2C_FUNC_SMBUS_BYTE |I2C_FUNC_I2C ))return -EOPNOTSUPP ; indio_dev =devm_iio_device_alloc (&client->dev,sizeof (*data));
Signature · 1 line
2.1.4
Quoted 50 lines · Alison Schofield
Replace the
i2c_smbus_read_bytecommmands used to retrieve the sensor data with ani2c_master_recvcommand.The smbus read byte method fails because the device does not expect a stop condition after sending the first byte. When we issue the second read, we are getting the first byte again. Net effect is that of the 14 bits used for the measurement, the 8 most significant bits are correct, the lower 6 are not.
None of the smbus read protocols follow the pattern this device requires (S Addr Rd [A] Data [A] Data NA P), hence the switch to an i2c receive transaction.
Signed-off-by Alison Schofield <[email protected]>Cc Daniel Baluta <[email protected]>--- drivers/iio/humidity/hdc100x.c | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-)drivers/iio/humidity/hdc100x.c +4
-9@@ -142,7 +142,7 @@ static int hdc100x_get_measurement(struct hdc100x_data *data,struct i2c_client *client = data->client;int delay = data->adc_int_us[chan->address];int ret; -int val; +u8 buf[2 ];/* start measurement */ ret =i2c_smbus_write_byte (client, chan->address);@@ -154,26 +154,13 @@ static int hdc100x_get_measurement(struct hdc100x_data *data,/* wait for integration time to pass */ usleep_range (delay, delay +1000 ); -/* -* i2c_smbus_read_word_data cannot() be used here due to the command -* value not being understood and causes NAKs preventing any reading -* from being accessed. -*/ - ret =i2c_smbus_read_byte (client); +/* read the 2 byte measurement */ + ret =i2c_master_recv (data->client, buf,2 );if (ret <0 ) { -dev_err (&client->dev,"cannot read high byte measurement" ); +dev_err (&client->dev,"cannot read sensor data\n" );return ret; } - val = ret <<8 ;
drivers/iio/humidity/hdc100x.c static int hdc100x_get_measurement(struct hdc100x_data *data, · line 163
Quoted 10 lines
drivers/iio/humidity/hdc100x.c +1
-9- - ret =i2c_smbus_read_byte (client); -if (ret <0 ) { -dev_err (&client->dev,"cannot read low byte measurement" ); -return ret; - } - val |= ret; - -return val; +return (int )(buf[0 ] <<8 | buf[1 ]);
Pretty sure you don't need to cast to int type here.
drivers/iio/humidity/hdc100x.c static int hdc100x_probe(struct i2c_client *client, · line 263
Quoted 11 lines
drivers/iio/humidity/hdc100x.c +2
-2}static int hdc100x_get_heater_status (struct hdc100x_data *data)@@ -272,8 +259,8 @@ static int hdc100x_probe(struct i2c_client *client,struct iio_dev *indio_dev;struct hdc100x_data *data; -if (!i2c_check_functionality (client->adapter, -I2C_FUNC_SMBUS_WORD_DATA |I2C_FUNC_SMBUS_BYTE )) +if (!i2c_check_functionality (client->adapter,I2C_FUNC_SMBUS_WORD_DATA | +I2C_FUNC_SMBUS_BYTE |I2C_FUNC_I2C ))
Not sure we want to kill smbus support for this device... iwe should have two read methods for i2c and smbus (see the PulsedLight LIDAR driver) in this case.
Ideally I wouldn't have written it with only smbus in mind, but can kill backwards compatibility unless we have a good reason.
Thanks,
Matt
Quoted 6 lines
drivers/iio/humidity/hdc100x.c +0
-1return -EOPNOTSUPP ; indio_dev =devm_iio_device_alloc (&client->dev,sizeof (*data)); --2.1.4
Quoted 20 lines
Quoted 20 lines
Replace the
i2c_smbus_read_bytecommmands used to retrieve the sensor data with ani2c_master_recvcommand.The smbus read byte method fails because the device does not expect a stop condition after sending the first byte. When we issue the second read, we are getting the first byte again. Net effect is that of the 14 bits used for the measurement, the 8 most significant bits are correct, the lower 6 are not.
None of the smbus read protocols follow the pattern this device requires (S Addr Rd [A] Data [A] Data NA P), hence the switch to an i2c receive transaction.
Signed-off-by Alison Schofield <[email protected]>Cc Daniel Baluta <[email protected]>--- drivers/iio/humidity/hdc100x.c | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-)
Quoted 10 lines
drivers/iio/humidity/hdc100x.c static int hdc100x_get_measurement(struct hdc100x_data *data, · line 145
Quoted 10 lines
drivers/iio/humidity/hdc100x.c +1
-1@@ -142,7 +142,7 @@ static int hdc100x_get_measurement(struct hdc100x_data *data,struct i2c_client *client = data->client;int delay = data->adc_int_us[chan->address];int ret; -int val; +u8 buf[2 ];
__le16 val;
Quoted 25 lines
Quoted 25 lines
drivers/iio/humidity/hdc100x.c +3
-12/* start measurement */ ret =i2c_smbus_write_byte (client, chan->address);@@ -154,26 +154,13 @@ static int hdc100x_get_measurement(struct hdc100x_data *data,/* wait for integration time to pass */ usleep_range (delay, delay +1000 ); -/* -* i2c_smbus_read_word_data cannot() be used here due to the command -* value not being understood and causes NAKs preventing any reading -* from being accessed. -*/ - ret =i2c_smbus_read_byte (client); +/* read the 2 byte measurement */ + ret =i2c_master_recv (data->client, buf,2 );if (ret <0 ) { -dev_err (&client->dev,"cannot read high byte measurement" ); +dev_err (&client->dev,"cannot read sensor data\n" );return ret; } - val = ret <<8 ; - - ret =i2c_smbus_read_byte (client); -if (ret <0 ) { -dev_err (&client->dev,"cannot read low byte measurement" );
Quoted 8 lines
drivers/iio/humidity/hdc100x.c static int hdc100x_get_measurement(struct hdc100x_data *data, · line 163
Quoted 6 lines
drivers/iio/humidity/hdc100x.c +1
-5-return ret; - } - val |= ret; - -return val; +return (int )(buf[0 ] <<8 | buf[1 ]);Pretty sure you don't need to cast to int type here.
return le16_to_cpu(val);
Quoted 31 lines
drivers/iio/humidity/hdc100x.c static int hdc100x_probe(struct i2c_client *client, · line 263
Quoted 12 lines
drivers/iio/humidity/hdc100x.c +2
-2}static int hdc100x_get_heater_status (struct hdc100x_data *data)@@ -272,8 +259,8 @@ static int hdc100x_probe(struct i2c_client *client,struct iio_dev *indio_dev;struct hdc100x_data *data; -if (!i2c_check_functionality (client->adapter, -I2C_FUNC_SMBUS_WORD_DATA |I2C_FUNC_SMBUS_BYTE )) +if (!i2c_check_functionality (client->adapter,I2C_FUNC_SMBUS_WORD_DATA | +I2C_FUNC_SMBUS_BYTE |I2C_FUNC_I2C ))Not sure we want to kill smbus support for this device... iwe should have two read methods for i2c and smbus (see the PulsedLight LIDAR driver) in this case.
Ideally I wouldn't have written it with only smbus in mind, but can kill backwards compatibility unless we have a good reason.
Thanks,
Matt
Quoted 6 lines
drivers/iio/humidity/hdc100x.c +0
-1return -EOPNOTSUPP ; indio_dev =devm_iio_device_alloc (&client->dev,sizeof (*data)); --2.1.4
Signature · 2 lines
Peter Meerwald-Stadler +43-664-2444418 (mobile)
Quoted 73 lines · Peter Meerwald-Stadler
Quoted 11 lines
Quoted 11 lines
Replace the
i2c_smbus_read_bytecommmands used to retrieve the sensor data with ani2c_master_recvcommand.The smbus read byte method fails because the device does not expect a stop condition after sending the first byte. When we issue the second read, we are getting the first byte again. Net effect is that of the 14 bits used for the measurement, the 8 most significant bits are correct, the lower 6 are not.
None of the smbus read protocols follow the pattern this device
requires
Quoted 10 lines
Review
Quoted 10 lines
(S Addr Rd [A] Data [A] Data NA P), hence the switch to an i2c receive transaction.
Signed-off-by Alison Schofield <[email protected]>Cc Daniel Baluta <[email protected]>--- drivers/iio/humidity/hdc100x.c | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-)(quoted diff) +0
-0
b/drivers/iio/humidity/hdc100x.cQuoted 4 lines
drivers/iio/humidity/hdc100x.c static int hdc100x_get_measurement(struct
Quoted 4 lines
index a03832a..643a42d 100644
drivers/iio/humidity/hdc100x.c +0
-0@@ -142,7 +142,7 @@ static int hdc100x_get_measurement(struct
hdc100x_data*data,Quoted 5 lines
drivers/iio/humidity/hdc100x.c static int hdc100x_get_measurement(struct hdc100x_data *data, · line 145
Quoted 5 lines
drivers/iio/humidity/hdc100x.c +1
-1struct i2c_client *client = data->client;int delay = data->adc_int_us[chan->address];int ret; -int val; +u8 buf[2 ];
__le16val;Quoted 4 lines
drivers/iio/humidity/hdc100x.c static int hdc100x_get_measurement(struct
Quoted 4 lines
drivers/iio/humidity/hdc100x.c +0
-0/* start measurement */ ret =i2c_smbus_write_byte (client, chan->address);@@ -154,26 +154,13 @@ static int hdc100x_get_measurement(struct
hdc100x_data*data,Quoted 5 lines
drivers/iio/humidity/hdc100x.c static int hdc100x_get_measurement(struct hdc100x_data *data,
Quoted 5 lines
drivers/iio/humidity/hdc100x.c +0
-2/* wait for integration time to pass */ usleep_range (delay, delay +1000 ); -/* -* i2c_smbus_read_word_data cannot() be used here due to the command
Quoted 1 line
drivers/iio/humidity/hdc100x.c static int hdc100x_get_measurement(struct · line 159
Quoted 1 line
drivers/iio/humidity/hdc100x.c +0
-1-* value not being understood and causes NAKs preventing any reading
Quoted 7 lines
drivers/iio/humidity/hdc100x.c static int hdc100x_get_measurement(struct hdc100x_data *data,
Quoted 7 lines
drivers/iio/humidity/hdc100x.c +2
-4-* from being accessed. -*/ - ret =i2c_smbus_read_byte (client); +/* read the 2 byte measurement */ + ret =i2c_master_recv (data->client, buf,2 );if (ret <0 ) { - dev_err(&client->dev, "cannot read high bytemeasurement");
Quoted 8 lines
drivers/iio/humidity/hdc100x.c static int hdc100x_get_measurement(struct hdc100x_data *data,
Quoted 8 lines
drivers/iio/humidity/hdc100x.c +1
-5+dev_err (&client->dev,"cannot read sensor data\n" );return ret; } - val = ret <<8 ; - - ret =i2c_smbus_read_byte (client); -if (ret <0 ) { - dev_err(&client->dev, "cannot read low bytemeasurement");
Quoted 7 lines
Quoted 6 lines
drivers/iio/humidity/hdc100x.c +1
-5-return ret; - } - val |= ret; - -return val; +return (int )(buf[0 ] <<8 | buf[1 ]);
Quoted 5 lines
Quoted 1 line
Pretty sure you don't need to cast to int type here.
return
le16_to_cpu(val);
You mean le16_to_cpu(&buf) I assume?
Quoted 40 lines
Quoted 10 lines
drivers/iio/humidity/hdc100x.c static int hdc100x_probe(struct i2c_client *client, · line 276
Quoted 10 lines
drivers/iio/humidity/hdc100x.c +0
-2}static int hdc100x_get_heater_status (struct hdc100x_data *data)@@ -272,8 +259,8 @@ static int hdc100x_probe(struct i2c_client *client,struct iio_dev *indio_dev;struct hdc100x_data *data; - if (!i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_WORD_DATA |
I2C_FUNC_SMBUS_BYTE))Quoted 1 line
drivers/iio/humidity/hdc100x.c static int hdc100x_probe(struct i2c_client *client, · line 262
Quoted 1 line
drivers/iio/humidity/hdc100x.c +1
-0+ if (!i2c_check_functionality(client->adapter,
I2C_FUNC_SMBUS_WORD_DATA|Quoted 1 line
drivers/iio/humidity/hdc100x.c static int hdc100x_probe(struct i2c_client *client, · line 263
Quoted 1 line
drivers/iio/humidity/hdc100x.c +1
-0+ I2C_FUNC_SMBUS_BYTE |
I2C_FUNC_I2C))Quoted 5 lines
Not sure we want to kill smbus support for this device... iwe should have two read methods for i2c and smbus (see the PulsedLight LIDAR driver) in this case.
Quoted 14 lines
Ideally I wouldn't have written it with only smbus in mind, but can kill backwards compatibility unless we have a good reason.
Thanks,
Matt
Quoted 6 lines
drivers/iio/humidity/hdc100x.c +0
-1return -EOPNOTSUPP ; indio_dev =devm_iio_device_alloc (&client->dev,sizeof (*data)); --2.1.4
--
Peter Meerwald-Stadler
+43-664-2444418 (mobile)
Quoted 76 lines · Matt Ranostay
Quoted 73 lines · Peter Meerwald-Stadler
Quoted 11 lines
Quoted 11 lines
Replace the
i2c_smbus_read_bytecommmands used to retrieve the sensor data with ani2c_master_recvcommand.The smbus read byte method fails because the device does not expect a stop condition after sending the first byte. When we issue the second read, we are getting the first byte again. Net effect is that of the 14 bits used for the measurement, the 8 most significant bits are correct, the lower 6 are not.
None of the smbus read protocols follow the pattern this device
requires
Quoted 10 lines
Review
Quoted 10 lines
(S Addr Rd [A] Data [A] Data NA P), hence the switch to an i2c receive transaction.
Signed-off-by Alison Schofield <[email protected]>Cc Daniel Baluta <[email protected]>--- drivers/iio/humidity/hdc100x.c | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-)(quoted diff) +0
-0
b/drivers/iio/humidity/hdc100x.cQuoted 4 lines
drivers/iio/humidity/hdc100x.c static int hdc100x_get_measurement(struct
Quoted 4 lines
index a03832a..643a42d 100644
drivers/iio/humidity/hdc100x.c +0
-0@@ -142,7 +142,7 @@ static int hdc100x_get_measurement(struct
hdc100x_data*data,Quoted 5 lines
drivers/iio/humidity/hdc100x.c static int hdc100x_get_measurement(struct hdc100x_data *data, · line 145
Quoted 5 lines
drivers/iio/humidity/hdc100x.c +1
-1struct i2c_client *client = data->client;int delay = data->adc_int_us[chan->address];int ret; -int val; +u8 buf[2 ];
__le16val;Quoted 4 lines
drivers/iio/humidity/hdc100x.c static int hdc100x_get_measurement(struct
Quoted 4 lines
drivers/iio/humidity/hdc100x.c +0
-0/* start measurement */ ret =i2c_smbus_write_byte (client, chan->address);@@ -154,26 +154,13 @@ static int hdc100x_get_measurement(struct
hdc100x_data*data,Quoted 5 lines
drivers/iio/humidity/hdc100x.c static int hdc100x_get_measurement(struct hdc100x_data *data,
Quoted 5 lines
drivers/iio/humidity/hdc100x.c +0
-2/* wait for integration time to pass */ usleep_range (delay, delay +1000 ); -/* -* i2c_smbus_read_word_data cannot() be used here due to the command
Quoted 1 line
drivers/iio/humidity/hdc100x.c static int hdc100x_get_measurement(struct · line 159
Quoted 1 line
drivers/iio/humidity/hdc100x.c +0
-1-* value not being understood and causes NAKs preventing any reading
Quoted 7 lines
drivers/iio/humidity/hdc100x.c static int hdc100x_get_measurement(struct hdc100x_data *data,
Quoted 7 lines
drivers/iio/humidity/hdc100x.c +2
-4-* from being accessed. -*/ - ret =i2c_smbus_read_byte (client); +/* read the 2 byte measurement */ + ret =i2c_master_recv (data->client, buf,2 );if (ret <0 ) { - dev_err(&client->dev, "cannot read high bytemeasurement");
Quoted 8 lines
drivers/iio/humidity/hdc100x.c static int hdc100x_get_measurement(struct hdc100x_data *data,
Quoted 8 lines
drivers/iio/humidity/hdc100x.c +1
-5+dev_err (&client->dev,"cannot read sensor data\n" );return ret; } - val = ret <<8 ; - - ret =i2c_smbus_read_byte (client); -if (ret <0 ) { - dev_err(&client->dev, "cannot read low bytemeasurement");
Quoted 7 lines
Quoted 6 lines
drivers/iio/humidity/hdc100x.c +1
-5-return ret; - } - val |= ret; - -return val; +return (int )(buf[0 ] <<8 | buf[1 ]);
Quoted 34 lines
Quoted 5 lines
Quoted 1 line
Pretty sure you don't need to cast to int type here.
return
le16_to_cpu(val);You mean
le16_to_cpu(&buf)I assume?Quoted 26 lines
Quoted 10 lines
drivers/iio/humidity/hdc100x.c static int hdc100x_probe(struct i2c_client *client, · line 276
Quoted 10 lines
drivers/iio/humidity/hdc100x.c +0
-2}static int hdc100x_get_heater_status (struct hdc100x_data *data)@@ -272,8 +259,8 @@ static int hdc100x_probe(struct i2c_client *client,struct iio_dev *indio_dev;struct hdc100x_data *data; - if (!i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_WORD_DATA |
I2C_FUNC_SMBUS_BYTE))Quoted 1 line
drivers/iio/humidity/hdc100x.c static int hdc100x_probe(struct i2c_client *client, · line 262
Quoted 1 line
drivers/iio/humidity/hdc100x.c +1
-0+ if (!i2c_check_functionality(client->adapter,
I2C_FUNC_SMBUS_WORD_DATA|Quoted 1 line
drivers/iio/humidity/hdc100x.c static int hdc100x_probe(struct i2c_client *client, · line 263
Quoted 1 line
drivers/iio/humidity/hdc100x.c +1
-0+ I2C_FUNC_SMBUS_BYTE |
I2C_FUNC_I2C))Quoted 11 lines
Not sure we want to kill smbus support for this device... iwe should have two read methods for i2c and smbus (see the PulsedLight LIDAR driver) in this case.
Ideally I wouldn't have written it with only smbus in mind, but can kill backwards compatibility unless we have a good reason.
Thanks,
Matt
Thanks for the reviews. Let me clarify:
This is a fix for a bug in the current driver. See the changelog.
The relationship between this patch and my triggered-buffer work is that I found this bug while trying to do just what you say above. I tried to have 2 methods for reading data - smbus and plain i2c. That's the point where I found that smbus reads do not work, never did.
I know we want to stay on the smbus, so I'm looking for suggestions. As I noted in changelog and my 'smbus help' email - every defined smbus read command fails.
alisons
Quoted 14 lines
Quoted 14 lines
Quoted 8 lines
Quoted 7 lines
drivers/iio/humidity/hdc100x.c +0
-1return -EOPNOTSUPP ; indio_dev =devm_iio_device_alloc (&client->dev,sizeof (*data)); --2.1.4
--
Peter Meerwald-Stadler
+43-664-2444418 (mobile)
Quoted 116 lines · Alison Schofield
Quoted 76 lines · Matt Ranostay
Quoted 73 lines · Peter Meerwald-Stadler
Quoted 11 lines
Quoted 11 lines
Replace the
i2c_smbus_read_bytecommmands used to retrieve the sensor data with ani2c_master_recvcommand.The smbus read byte method fails because the device does not expect a stop condition after sending the first byte. When we issue the second read, we are getting the first byte again. Net effect is that of the 14 bits used for the measurement, the 8 most significant bits are correct, the lower 6 are not.
None of the smbus read protocols follow the pattern this device
requires
Quoted 10 lines
Review
Quoted 10 lines
(S Addr Rd [A] Data [A] Data NA P), hence the switch to an i2c receive transaction.
Signed-off-by Alison Schofield <[email protected]>Cc Daniel Baluta <[email protected]>--- drivers/iio/humidity/hdc100x.c | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-)(quoted diff) +0
-0
b/drivers/iio/humidity/hdc100x.cQuoted 4 lines
drivers/iio/humidity/hdc100x.c static int hdc100x_get_measurement(struct
Quoted 4 lines
index a03832a..643a42d 100644
drivers/iio/humidity/hdc100x.c +0
-0@@ -142,7 +142,7 @@ static int hdc100x_get_measurement(struct
hdc100x_data*data,Quoted 5 lines
drivers/iio/humidity/hdc100x.c static int hdc100x_get_measurement(struct hdc100x_data *data, · line 145
Quoted 5 lines
drivers/iio/humidity/hdc100x.c +1
-1struct i2c_client *client = data->client;int delay = data->adc_int_us[chan->address];int ret; -int val; +u8 buf[2 ];
__le16val;Quoted 4 lines
drivers/iio/humidity/hdc100x.c static int hdc100x_get_measurement(struct
Quoted 4 lines
drivers/iio/humidity/hdc100x.c +0
-0/* start measurement */ ret =i2c_smbus_write_byte (client, chan->address);@@ -154,26 +154,13 @@ static int hdc100x_get_measurement(struct
hdc100x_data*data,Quoted 5 lines
drivers/iio/humidity/hdc100x.c static int hdc100x_get_measurement(struct hdc100x_data *data,
Quoted 5 lines
drivers/iio/humidity/hdc100x.c +0
-2/* wait for integration time to pass */ usleep_range (delay, delay +1000 ); -/* -* i2c_smbus_read_word_data cannot() be used here due to the command
Quoted 1 line
drivers/iio/humidity/hdc100x.c static int hdc100x_get_measurement(struct · line 159
Quoted 1 line
drivers/iio/humidity/hdc100x.c +0
-1-* value not being understood and causes NAKs preventing any reading
Quoted 7 lines
drivers/iio/humidity/hdc100x.c static int hdc100x_get_measurement(struct hdc100x_data *data,
Quoted 7 lines
drivers/iio/humidity/hdc100x.c +2
-4-* from being accessed. -*/ - ret =i2c_smbus_read_byte (client); +/* read the 2 byte measurement */ + ret =i2c_master_recv (data->client, buf,2 );if (ret <0 ) { - dev_err(&client->dev, "cannot read high bytemeasurement");
Quoted 8 lines
drivers/iio/humidity/hdc100x.c static int hdc100x_get_measurement(struct hdc100x_data *data,
Quoted 8 lines
drivers/iio/humidity/hdc100x.c +1
-5+dev_err (&client->dev,"cannot read sensor data\n" );return ret; } - val = ret <<8 ; - - ret =i2c_smbus_read_byte (client); -if (ret <0 ) { - dev_err(&client->dev, "cannot read low bytemeasurement");
Quoted 7 lines
Quoted 6 lines
drivers/iio/humidity/hdc100x.c +1
-5-return ret; - } - val |= ret; - -return val; +return (int )(buf[0 ] <<8 | buf[1 ]);Quoted 34 lines
Quoted 5 lines
Quoted 1 line
Pretty sure you don't need to cast to int type here.
return
le16_to_cpu(val);You mean
le16_to_cpu(&buf)I assume?Quoted 26 lines
Quoted 10 lines
drivers/iio/humidity/hdc100x.c static int hdc100x_probe(struct i2c_client *client, · line 276
Quoted 10 lines
drivers/iio/humidity/hdc100x.c +0
-2}static int hdc100x_get_heater_status (struct hdc100x_data *data)@@ -272,8 +259,8 @@ static int hdc100x_probe(struct i2c_client *client,struct iio_dev *indio_dev;struct hdc100x_data *data; - if (!i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_WORD_DATA |
I2C_FUNC_SMBUS_BYTE))Quoted 1 line
drivers/iio/humidity/hdc100x.c static int hdc100x_probe(struct i2c_client *client, · line 262
Quoted 1 line
drivers/iio/humidity/hdc100x.c +1
-0+ if (!i2c_check_functionality(client->adapter,
I2C_FUNC_SMBUS_WORD_DATA|Quoted 1 line
drivers/iio/humidity/hdc100x.c static int hdc100x_probe(struct i2c_client *client, · line 263
Quoted 1 line
drivers/iio/humidity/hdc100x.c +1
-0+ I2C_FUNC_SMBUS_BYTE |
I2C_FUNC_I2C))Quoted 11 lines
Not sure we want to kill smbus support for this device... iwe should have two read methods for i2c and smbus (see the PulsedLight LIDAR driver) in this case.
Ideally I wouldn't have written it with only smbus in mind, but can kill backwards compatibility unless we have a good reason.
Thanks,
Matt
Thanks for the reviews. Let me clarify:
This is a fix for a bug in the current driver. See the changelog.
Quoted 8 lines
The relationship between this patch and my triggered-buffer work is that I found this bug while trying to do just what you say above. I tried to have 2 methods for reading data - smbus and plain i2c. That's the point where I found that smbus reads do not work, never did.
I know we want to stay on the smbus, so I'm looking for suggestions. As I noted in changelog and my 'smbus help' email - every defined smbus read command fails.
Of course this depends on what dev board you are using and if the i2c controller supports both.
Ideally you check for i2c support first then point to that xfer transfer function for it, and then check for smbus support. Suspect you did something similar to ->
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c?id=refs/tags/v4.7#n274
, correct?
Thanks,
Matt
Quoted 17 lines
alisons
Quoted 14 lines
Quoted 14 lines
Quoted 8 lines
Quoted 7 lines
drivers/iio/humidity/hdc100x.c +0
-1return -EOPNOTSUPP ; indio_dev =devm_iio_device_alloc (&client->dev,sizeof (*data)); --2.1.4
--
Peter Meerwald-Stadler
+43-664-2444418 (mobile)
Quoted 126 lines · Matt Ranostay
Quoted 116 lines · Alison Schofield
Quoted 76 lines · Matt Ranostay
Quoted 73 lines · Peter Meerwald-Stadler
Quoted 11 lines
Quoted 11 lines
Replace the
i2c_smbus_read_bytecommmands used to retrieve the sensor data with ani2c_master_recvcommand.The smbus read byte method fails because the device does not expect a stop condition after sending the first byte. When we issue the second read, we are getting the first byte again. Net effect is that of the 14 bits used for the measurement, the 8 most significant bits are correct, the lower 6 are not.
None of the smbus read protocols follow the pattern this device
requires
Quoted 10 lines
Review
Quoted 10 lines
(S Addr Rd [A] Data [A] Data NA P), hence the switch to an i2c receive transaction.
Signed-off-by Alison Schofield <[email protected]>Cc Daniel Baluta <[email protected]>--- drivers/iio/humidity/hdc100x.c | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-)(quoted diff) +0
-0
b/drivers/iio/humidity/hdc100x.cQuoted 4 lines
drivers/iio/humidity/hdc100x.c static int hdc100x_get_measurement(struct
Quoted 4 lines
index a03832a..643a42d 100644
drivers/iio/humidity/hdc100x.c +0
-0@@ -142,7 +142,7 @@ static int hdc100x_get_measurement(struct
hdc100x_data*data,Quoted 5 lines
drivers/iio/humidity/hdc100x.c static int hdc100x_get_measurement(struct hdc100x_data *data, · line 145
Quoted 5 lines
drivers/iio/humidity/hdc100x.c +1
-1struct i2c_client *client = data->client;int delay = data->adc_int_us[chan->address];int ret; -int val; +u8 buf[2 ];
__le16val;Quoted 4 lines
drivers/iio/humidity/hdc100x.c static int hdc100x_get_measurement(struct
Quoted 4 lines
drivers/iio/humidity/hdc100x.c +0
-0/* start measurement */ ret =i2c_smbus_write_byte (client, chan->address);@@ -154,26 +154,13 @@ static int hdc100x_get_measurement(struct
hdc100x_data*data,Quoted 5 lines
drivers/iio/humidity/hdc100x.c static int hdc100x_get_measurement(struct hdc100x_data *data,
Quoted 5 lines
drivers/iio/humidity/hdc100x.c +0
-2/* wait for integration time to pass */ usleep_range (delay, delay +1000 ); -/* -* i2c_smbus_read_word_data cannot() be used here due to the command
Quoted 1 line
drivers/iio/humidity/hdc100x.c static int hdc100x_get_measurement(struct · line 159
Quoted 1 line
drivers/iio/humidity/hdc100x.c +0
-1-* value not being understood and causes NAKs preventing any reading
Quoted 7 lines
drivers/iio/humidity/hdc100x.c static int hdc100x_get_measurement(struct hdc100x_data *data,
Quoted 7 lines
drivers/iio/humidity/hdc100x.c +2
-4-* from being accessed. -*/ - ret =i2c_smbus_read_byte (client); +/* read the 2 byte measurement */ + ret =i2c_master_recv (data->client, buf,2 );if (ret <0 ) { - dev_err(&client->dev, "cannot read high bytemeasurement");
Quoted 8 lines
drivers/iio/humidity/hdc100x.c static int hdc100x_get_measurement(struct hdc100x_data *data,
Quoted 8 lines
drivers/iio/humidity/hdc100x.c +1
-5+dev_err (&client->dev,"cannot read sensor data\n" );return ret; } - val = ret <<8 ; - - ret =i2c_smbus_read_byte (client); -if (ret <0 ) { - dev_err(&client->dev, "cannot read low bytemeasurement");
Quoted 7 lines
Quoted 6 lines
drivers/iio/humidity/hdc100x.c +1
-5-return ret; - } - val |= ret; - -return val; +return (int )(buf[0 ] <<8 | buf[1 ]);Quoted 34 lines
Quoted 5 lines
Quoted 1 line
Pretty sure you don't need to cast to int type here.
return
le16_to_cpu(val);You mean
le16_to_cpu(&buf)I assume?Quoted 26 lines
Quoted 10 lines
drivers/iio/humidity/hdc100x.c static int hdc100x_probe(struct i2c_client *client, · line 276
Quoted 10 lines
drivers/iio/humidity/hdc100x.c +0
-2}static int hdc100x_get_heater_status (struct hdc100x_data *data)@@ -272,8 +259,8 @@ static int hdc100x_probe(struct i2c_client *client,struct iio_dev *indio_dev;struct hdc100x_data *data; - if (!i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_WORD_DATA |
I2C_FUNC_SMBUS_BYTE))Quoted 1 line
drivers/iio/humidity/hdc100x.c static int hdc100x_probe(struct i2c_client *client, · line 262
Quoted 1 line
drivers/iio/humidity/hdc100x.c +1
-0+ if (!i2c_check_functionality(client->adapter,
I2C_FUNC_SMBUS_WORD_DATA|Quoted 1 line
drivers/iio/humidity/hdc100x.c static int hdc100x_probe(struct i2c_client *client, · line 263
Quoted 1 line
drivers/iio/humidity/hdc100x.c +1
-0+ I2C_FUNC_SMBUS_BYTE |
I2C_FUNC_I2C))Quoted 11 lines
Not sure we want to kill smbus support for this device... iwe should have two read methods for i2c and smbus (see the PulsedLight LIDAR driver) in this case.
Ideally I wouldn't have written it with only smbus in mind, but can kill backwards compatibility unless we have a good reason.
Thanks,
Matt
Thanks for the reviews. Let me clarify:
This is a fix for a bug in the current driver. See the changelog.
Quoted 8 lines
The relationship between this patch and my triggered-buffer work is that I found this bug while trying to do just what you say above. I tried to have 2 methods for reading data - smbus and plain i2c. That's the point where I found that smbus reads do not work, never did.
I know we want to stay on the smbus, so I'm looking for suggestions. As I noted in changelog and my 'smbus help' email - every defined smbus read command fails.
Quoted 8 lines
Of course this depends on what dev board you are using and if the i2c controller supports both.
Ideally you check for i2c support first then point to that xfer transfer function for it, and then check for smbus support. Suspect you did something similar to ->
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c?id=refs/tags/v4.7#n274
, correct?
No, that's not what this bug & patch is about.
This patch is about the fact that we are reading the temp & humid data registers incorrectly in the current driver and we are exposing incorrect numbers via sysfs raw reads.
I have tried by testing and inspection each read protocol. It NAKs all of them - except for read_byte. Problem withread_byte is that we are always getting the MSB. We do 2
consecutive read_bytes, expecting MSB,LSB, but get MSB,MSB.
I have been doing msmts w this driver for quite awhile, and to my human eye they looked reasonable in integer format. But, once I started looking at the byte level, to test moving those bytes into buffers, I saw the unmistakable pattern:
MSB == LSB always.
Sorry to be the bearer of bad news. I still hold out hope that we can fix this with some smbus magic and not 'kill backward compatibility'.
Who's the resident SMBUS expert(s)?
I don't have a session logged, but I can set up and send a demo if wanted. Let me know.
alisons
Quoted 21 lines
Thanks,
Matt >
Quoted 17 lines
alisons
Quoted 14 lines
Quoted 14 lines
Quoted 8 lines
Quoted 7 lines
drivers/iio/humidity/hdc100x.c +0
-1return -EOPNOTSUPP ; indio_dev =devm_iio_device_alloc (&client->dev,sizeof (*data)); --2.1.4
--
Peter Meerwald-Stadler
+43-664-2444418 (mobile)
On 08/05/2016 01:37 AM, Alison Schofield wrote:
[...]
Quoted 18 lines
No, that's not what this bug & patch is about.
This patch is about the fact that we are reading the temp & humid data registers incorrectly in the current driver and we are exposing incorrect numbers via sysfs raw reads.
I have tried by testing and inspection each read protocol. It NAKs all of them - except for
read_byte. Problem withread_byteis that we are always getting the MSB. We do 2
consecutiveread_bytes, expecting MSB,LSB, but get MSB,MSB.I have been doing msmts w this driver for quite awhile, and to my human eye they looked reasonable in integer format. But, once I started looking at the byte level, to test moving those bytes into buffers, I saw the unmistakable pattern:
MSB == LSB always.
Quoted 3 lines
Sorry to be the bearer of bad news. I still hold out hope that we can fix this with some smbus magic and not 'kill backward compatibility'.
If the part is not SMBUS compatible I don't see a reason to try to force it. It's also not affecting backwards compatibility, the driver never worked correctly in the first place with SMBUS only, so there is no regression. After the patch it sill does not work.