* [PATCH 1/2] hwmon/tmp401: use smb word operations instead of 2 smb byte operations @ 2017-01-09 16:47 jeroen.de_wachter.ext 2017-01-09 16:47 ` [PATCH 2/2] hwmon/tmp401: Fix some checkstyle warnings jeroen.de_wachter.ext ` (2 more replies) 0 siblings, 3 replies; 6+ messages in thread From: jeroen.de_wachter.ext @ 2017-01-09 16:47 UTC (permalink / raw) To: linux, jdelvare; +Cc: linux-hwmon, linux-kernel, Jeroen De Wachter From: Jeroen De Wachter <jeroen.de_wachter.ext@nokia.com> tmp401 separately read/wrote high and low bytes of temperature values while the hardware supports reading/writing those values in one operation. Driver has been modified to use word operations where possible. Tested with a tmp432 sensor on a mips64 platform. Signed-off-by: Jeroen De Wachter <jeroen.de_wachter.ext@nokia.com> --- drivers/hwmon/tmp401.c | 48 +++++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/drivers/hwmon/tmp401.c b/drivers/hwmon/tmp401.c index eeeed2c..88b17e4 100644 --- a/drivers/hwmon/tmp401.c +++ b/drivers/hwmon/tmp401.c @@ -213,25 +213,29 @@ static int tmp401_update_device_reg16(struct i2c_client *client, for (i = 0; i < num_sensors; i++) { /* local / r1 / r2 */ for (j = 0; j < num_regs; j++) { /* temp / low / ... */ u8 regaddr; - /* - * High byte must be read first immediately followed - * by the low byte - */ + regaddr = data->kind == tmp432 ? TMP432_TEMP_MSB_READ[j][i] : TMP401_TEMP_MSB_READ[j][i]; - val = i2c_smbus_read_byte_data(client, regaddr); - if (val < 0) - return val; - data->temp[j][i] = val << 8; - if (j == 3) /* crit is msb only */ - continue; - regaddr = data->kind == tmp432 ? TMP432_TEMP_LSB[j][i] - : TMP401_TEMP_LSB[j][i]; - val = i2c_smbus_read_byte_data(client, regaddr); + if (j == 3) { /* crit is msb only */ + val = i2c_smbus_read_byte_data(client, regaddr); + } else { + /* + * Hardware provides big endian data. However, + * the smbus protocol expects the LSB first in + * I2C_SMBUS_WORD_DATA operations. + * i2c_smbus_read_word_swapped swaps the bytes + * in the value it receives from + * i2c_smbus_read_word_data before returning the + * data, so we get the correct value. + */ + val = i2c_smbus_read_word_swapped(client, + regaddr); + } if (val < 0) return val; - data->temp[j][i] |= val; + + data->temp[j][i] = j == 3 ? val << 8 : val; } } return 0; @@ -373,11 +377,17 @@ static ssize_t store_temp(struct device *dev, struct device_attribute *devattr, regaddr = data->kind == tmp432 ? TMP432_TEMP_MSB_WRITE[nr][index] : TMP401_TEMP_MSB_WRITE[nr][index]; - i2c_smbus_write_byte_data(client, regaddr, reg >> 8); - if (nr != 3) { - regaddr = data->kind == tmp432 ? TMP432_TEMP_LSB[nr][index] - : TMP401_TEMP_LSB[nr][index]; - i2c_smbus_write_byte_data(client, regaddr, reg & 0xFF); + if (nr == 3) { /* crit is msb only */ + i2c_smbus_write_byte_data(client, regaddr, reg >> 8); + } else { + /* + * Hardware expects big endian data. However, the smbus protocol + * puts the LSB first in I2C_SMBUS_WORD_DATA operations. + * i2c_smbus_write_word_data_swapped will swap the bytes before + * passing them to i2c_smbus_write_word_data, so the hardware + * will receive the MSB first, as expected. + */ + i2c_smbus_write_word_swapped(client, regaddr, reg); } data->temp[nr][index] = reg; -- 1.8.3.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] hwmon/tmp401: Fix some checkstyle warnings 2017-01-09 16:47 [PATCH 1/2] hwmon/tmp401: use smb word operations instead of 2 smb byte operations jeroen.de_wachter.ext @ 2017-01-09 16:47 ` jeroen.de_wachter.ext 2017-01-09 17:11 ` Guenter Roeck 2017-01-09 17:09 ` [PATCH 1/2] hwmon/tmp401: use smb word operations instead of 2 smb byte operations Guenter Roeck 2017-01-09 17:55 ` [PATCH v2] " jeroen.de_wachter.ext 2 siblings, 1 reply; 6+ messages in thread From: jeroen.de_wachter.ext @ 2017-01-09 16:47 UTC (permalink / raw) To: linux, jdelvare; +Cc: linux-hwmon, linux-kernel, Jeroen De Wachter From: Jeroen De Wachter <jeroen.de_wachter.ext@nokia.com> Signed-off-by: Jeroen De Wachter <jeroen.de_wachter.ext@nokia.com> --- drivers/hwmon/tmp401.c | 66 +++++++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/drivers/hwmon/tmp401.c b/drivers/hwmon/tmp401.c index 88b17e4..853056d 100644 --- a/drivers/hwmon/tmp401.c +++ b/drivers/hwmon/tmp401.c @@ -498,40 +498,40 @@ static ssize_t set_update_interval(struct device *dev, return count; } -static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0); -static SENSOR_DEVICE_ATTR_2(temp1_min, S_IWUSR | S_IRUGO, show_temp, +static SENSOR_DEVICE_ATTR_2(temp1_input, 0444, show_temp, NULL, 0, 0); +static SENSOR_DEVICE_ATTR_2(temp1_min, 0644, show_temp, store_temp, 1, 0); -static SENSOR_DEVICE_ATTR_2(temp1_max, S_IWUSR | S_IRUGO, show_temp, +static SENSOR_DEVICE_ATTR_2(temp1_max, 0644, show_temp, store_temp, 2, 0); -static SENSOR_DEVICE_ATTR_2(temp1_crit, S_IWUSR | S_IRUGO, show_temp, +static SENSOR_DEVICE_ATTR_2(temp1_crit, 0644, show_temp, store_temp, 3, 0); -static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, +static SENSOR_DEVICE_ATTR(temp1_crit_hyst, 0644, show_temp_crit_hyst, store_temp_crit_hyst, 0); -static SENSOR_DEVICE_ATTR_2(temp1_min_alarm, S_IRUGO, show_status, NULL, +static SENSOR_DEVICE_ATTR_2(temp1_min_alarm, 0444, show_status, NULL, 1, TMP432_STATUS_LOCAL); -static SENSOR_DEVICE_ATTR_2(temp1_max_alarm, S_IRUGO, show_status, NULL, +static SENSOR_DEVICE_ATTR_2(temp1_max_alarm, 0444, show_status, NULL, 2, TMP432_STATUS_LOCAL); -static SENSOR_DEVICE_ATTR_2(temp1_crit_alarm, S_IRUGO, show_status, NULL, +static SENSOR_DEVICE_ATTR_2(temp1_crit_alarm, 0444, show_status, NULL, 3, TMP432_STATUS_LOCAL); -static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 0, 1); -static SENSOR_DEVICE_ATTR_2(temp2_min, S_IWUSR | S_IRUGO, show_temp, +static SENSOR_DEVICE_ATTR_2(temp2_input, 0444, show_temp, NULL, 0, 1); +static SENSOR_DEVICE_ATTR_2(temp2_min, 0644, show_temp, store_temp, 1, 1); -static SENSOR_DEVICE_ATTR_2(temp2_max, S_IWUSR | S_IRUGO, show_temp, +static SENSOR_DEVICE_ATTR_2(temp2_max, 0644, show_temp, store_temp, 2, 1); -static SENSOR_DEVICE_ATTR_2(temp2_crit, S_IWUSR | S_IRUGO, show_temp, +static SENSOR_DEVICE_ATTR_2(temp2_crit, 0644, show_temp, store_temp, 3, 1); -static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, show_temp_crit_hyst, +static SENSOR_DEVICE_ATTR(temp2_crit_hyst, 0444, show_temp_crit_hyst, NULL, 1); -static SENSOR_DEVICE_ATTR_2(temp2_fault, S_IRUGO, show_status, NULL, +static SENSOR_DEVICE_ATTR_2(temp2_fault, 0444, show_status, NULL, 0, TMP432_STATUS_REMOTE1); -static SENSOR_DEVICE_ATTR_2(temp2_min_alarm, S_IRUGO, show_status, NULL, +static SENSOR_DEVICE_ATTR_2(temp2_min_alarm, 0444, show_status, NULL, 1, TMP432_STATUS_REMOTE1); -static SENSOR_DEVICE_ATTR_2(temp2_max_alarm, S_IRUGO, show_status, NULL, +static SENSOR_DEVICE_ATTR_2(temp2_max_alarm, 0444, show_status, NULL, 2, TMP432_STATUS_REMOTE1); -static SENSOR_DEVICE_ATTR_2(temp2_crit_alarm, S_IRUGO, show_status, NULL, +static SENSOR_DEVICE_ATTR_2(temp2_crit_alarm, 0444, show_status, NULL, 3, TMP432_STATUS_REMOTE1); -static DEVICE_ATTR(update_interval, S_IRUGO | S_IWUSR, show_update_interval, +static DEVICE_ATTR(update_interval, 0644, show_update_interval, set_update_interval); static struct attribute *tmp401_attributes[] = { @@ -570,11 +570,11 @@ static DEVICE_ATTR(update_interval, S_IRUGO | S_IWUSR, show_update_interval, * minimum and maximum register reset for both the local * and remote channels. */ -static SENSOR_DEVICE_ATTR_2(temp1_lowest, S_IRUGO, show_temp, NULL, 4, 0); -static SENSOR_DEVICE_ATTR_2(temp1_highest, S_IRUGO, show_temp, NULL, 5, 0); -static SENSOR_DEVICE_ATTR_2(temp2_lowest, S_IRUGO, show_temp, NULL, 4, 1); -static SENSOR_DEVICE_ATTR_2(temp2_highest, S_IRUGO, show_temp, NULL, 5, 1); -static SENSOR_DEVICE_ATTR(temp_reset_history, S_IWUSR, NULL, reset_temp_history, +static SENSOR_DEVICE_ATTR_2(temp1_lowest, 0444, show_temp, NULL, 4, 0); +static SENSOR_DEVICE_ATTR_2(temp1_highest, 0444, show_temp, NULL, 5, 0); +static SENSOR_DEVICE_ATTR_2(temp2_lowest, 0444, show_temp, NULL, 4, 1); +static SENSOR_DEVICE_ATTR_2(temp2_highest, 0444, show_temp, NULL, 5, 1); +static SENSOR_DEVICE_ATTR(temp_reset_history, 0200, NULL, reset_temp_history, 0); static struct attribute *tmp411_attributes[] = { @@ -590,22 +590,22 @@ static SENSOR_DEVICE_ATTR(temp_reset_history, S_IWUSR, NULL, reset_temp_history, .attrs = tmp411_attributes, }; -static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 0, 2); -static SENSOR_DEVICE_ATTR_2(temp3_min, S_IWUSR | S_IRUGO, show_temp, +static SENSOR_DEVICE_ATTR_2(temp3_input, 0444, show_temp, NULL, 0, 2); +static SENSOR_DEVICE_ATTR_2(temp3_min, 0644, show_temp, store_temp, 1, 2); -static SENSOR_DEVICE_ATTR_2(temp3_max, S_IWUSR | S_IRUGO, show_temp, +static SENSOR_DEVICE_ATTR_2(temp3_max, 0644, show_temp, store_temp, 2, 2); -static SENSOR_DEVICE_ATTR_2(temp3_crit, S_IWUSR | S_IRUGO, show_temp, +static SENSOR_DEVICE_ATTR_2(temp3_crit, 0644, show_temp, store_temp, 3, 2); -static SENSOR_DEVICE_ATTR(temp3_crit_hyst, S_IRUGO, show_temp_crit_hyst, +static SENSOR_DEVICE_ATTR(temp3_crit_hyst, 0444, show_temp_crit_hyst, NULL, 2); -static SENSOR_DEVICE_ATTR_2(temp3_fault, S_IRUGO, show_status, NULL, +static SENSOR_DEVICE_ATTR_2(temp3_fault, 0444, show_status, NULL, 0, TMP432_STATUS_REMOTE2); -static SENSOR_DEVICE_ATTR_2(temp3_min_alarm, S_IRUGO, show_status, NULL, +static SENSOR_DEVICE_ATTR_2(temp3_min_alarm, 0444, show_status, NULL, 1, TMP432_STATUS_REMOTE2); -static SENSOR_DEVICE_ATTR_2(temp3_max_alarm, S_IRUGO, show_status, NULL, +static SENSOR_DEVICE_ATTR_2(temp3_max_alarm, 0444, show_status, NULL, 2, TMP432_STATUS_REMOTE2); -static SENSOR_DEVICE_ATTR_2(temp3_crit_alarm, S_IRUGO, show_status, NULL, +static SENSOR_DEVICE_ATTR_2(temp3_crit_alarm, 0444, show_status, NULL, 3, TMP432_STATUS_REMOTE2); static struct attribute *tmp432_attributes[] = { @@ -630,7 +630,7 @@ static SENSOR_DEVICE_ATTR_2(temp3_crit_alarm, S_IRUGO, show_status, NULL, * Additional features of the TMP461 chip. * The TMP461 temperature offset for the remote channel. */ -static SENSOR_DEVICE_ATTR_2(temp2_offset, S_IWUSR | S_IRUGO, show_temp, +static SENSOR_DEVICE_ATTR_2(temp2_offset, 0644, show_temp, store_temp, 6, 1); static struct attribute *tmp461_attributes[] = { -- 1.8.3.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] hwmon/tmp401: Fix some checkstyle warnings 2017-01-09 16:47 ` [PATCH 2/2] hwmon/tmp401: Fix some checkstyle warnings jeroen.de_wachter.ext @ 2017-01-09 17:11 ` Guenter Roeck 0 siblings, 0 replies; 6+ messages in thread From: Guenter Roeck @ 2017-01-09 17:11 UTC (permalink / raw) To: jeroen.de_wachter.ext; +Cc: jdelvare, linux-hwmon, linux-kernel On Mon, Jan 09, 2017 at 05:47:38PM +0100, jeroen.de_wachter.ext@nokia.com wrote: > From: Jeroen De Wachter <jeroen.de_wachter.ext@nokia.com> > > Signed-off-by: Jeroen De Wachter <jeroen.de_wachter.ext@nokia.com> > --- > drivers/hwmon/tmp401.c | 66 +++++++++++++++++++++++++------------------------- > 1 file changed, 33 insertions(+), 33 deletions(-) > > diff --git a/drivers/hwmon/tmp401.c b/drivers/hwmon/tmp401.c > index 88b17e4..853056d 100644 > --- a/drivers/hwmon/tmp401.c > +++ b/drivers/hwmon/tmp401.c > @@ -498,40 +498,40 @@ static ssize_t set_update_interval(struct device *dev, > return count; > } > > -static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0); > -static SENSOR_DEVICE_ATTR_2(temp1_min, S_IWUSR | S_IRUGO, show_temp, > +static SENSOR_DEVICE_ATTR_2(temp1_input, 0444, show_temp, NULL, 0, 0); > +static SENSOR_DEVICE_ATTR_2(temp1_min, 0644, show_temp, I hate this change :-(. Please don't bother. I have a coccinelle driven series in the works which makes those changes automatically for all drivers (and, along the line, simplifies the SENSOR_DEVICE_ATTR[_2] macros). Thanks, Guenter ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] hwmon/tmp401: use smb word operations instead of 2 smb byte operations 2017-01-09 16:47 [PATCH 1/2] hwmon/tmp401: use smb word operations instead of 2 smb byte operations jeroen.de_wachter.ext 2017-01-09 16:47 ` [PATCH 2/2] hwmon/tmp401: Fix some checkstyle warnings jeroen.de_wachter.ext @ 2017-01-09 17:09 ` Guenter Roeck 2017-01-09 17:55 ` [PATCH v2] " jeroen.de_wachter.ext 2 siblings, 0 replies; 6+ messages in thread From: Guenter Roeck @ 2017-01-09 17:09 UTC (permalink / raw) To: jeroen.de_wachter.ext; +Cc: jdelvare, linux-hwmon, linux-kernel On Mon, Jan 09, 2017 at 05:47:37PM +0100, jeroen.de_wachter.ext@nokia.com wrote: > From: Jeroen De Wachter <jeroen.de_wachter.ext@nokia.com> > > tmp401 separately read/wrote high and low bytes of temperature values while > the hardware supports reading/writing those values in one operation. Driver > has been modified to use word operations where possible. > > Tested with a tmp432 sensor on a mips64 platform. > > Signed-off-by: Jeroen De Wachter <jeroen.de_wachter.ext@nokia.com> > --- > drivers/hwmon/tmp401.c | 48 +++++++++++++++++++++++++++++------------------- > 1 file changed, 29 insertions(+), 19 deletions(-) > > diff --git a/drivers/hwmon/tmp401.c b/drivers/hwmon/tmp401.c > index eeeed2c..88b17e4 100644 > --- a/drivers/hwmon/tmp401.c > +++ b/drivers/hwmon/tmp401.c > @@ -213,25 +213,29 @@ static int tmp401_update_device_reg16(struct i2c_client *client, > for (i = 0; i < num_sensors; i++) { /* local / r1 / r2 */ > for (j = 0; j < num_regs; j++) { /* temp / low / ... */ > u8 regaddr; > - /* > - * High byte must be read first immediately followed > - * by the low byte > - */ > + > regaddr = data->kind == tmp432 ? > TMP432_TEMP_MSB_READ[j][i] : > TMP401_TEMP_MSB_READ[j][i]; > - val = i2c_smbus_read_byte_data(client, regaddr); > - if (val < 0) > - return val; > - data->temp[j][i] = val << 8; > - if (j == 3) /* crit is msb only */ > - continue; > - regaddr = data->kind == tmp432 ? TMP432_TEMP_LSB[j][i] > - : TMP401_TEMP_LSB[j][i]; > - val = i2c_smbus_read_byte_data(client, regaddr); > + if (j == 3) { /* crit is msb only */ > + val = i2c_smbus_read_byte_data(client, regaddr); > + } else { > + /* > + * Hardware provides big endian data. However, > + * the smbus protocol expects the LSB first in > + * I2C_SMBUS_WORD_DATA operations. > + * i2c_smbus_read_word_swapped swaps the bytes > + * in the value it receives from > + * i2c_smbus_read_word_data before returning the > + * data, so we get the correct value. > + */ Please drop the comment or make it shorter (such as "Hardware provides big endian data"). > + val = i2c_smbus_read_word_swapped(client, > + regaddr); > + } > if (val < 0) > return val; > - data->temp[j][i] |= val; > + > + data->temp[j][i] = j == 3 ? val << 8 : val; > } > } > return 0; > @@ -373,11 +377,17 @@ static ssize_t store_temp(struct device *dev, struct device_attribute *devattr, > > regaddr = data->kind == tmp432 ? TMP432_TEMP_MSB_WRITE[nr][index] > : TMP401_TEMP_MSB_WRITE[nr][index]; > - i2c_smbus_write_byte_data(client, regaddr, reg >> 8); > - if (nr != 3) { > - regaddr = data->kind == tmp432 ? TMP432_TEMP_LSB[nr][index] > - : TMP401_TEMP_LSB[nr][index]; > - i2c_smbus_write_byte_data(client, regaddr, reg & 0xFF); > + if (nr == 3) { /* crit is msb only */ > + i2c_smbus_write_byte_data(client, regaddr, reg >> 8); > + } else { > + /* > + * Hardware expects big endian data. However, the smbus protocol > + * puts the LSB first in I2C_SMBUS_WORD_DATA operations. > + * i2c_smbus_write_word_data_swapped will swap the bytes before > + * passing them to i2c_smbus_write_word_data, so the hardware > + * will receive the MSB first, as expected. Comment in one place is enough. Unless I am missing something, TMP432_TEMP_LSB and TMP401_TEMP_LSB are now unused and can be removed. Thanks, Guenter > + */ > + i2c_smbus_write_word_swapped(client, regaddr, reg); > } > data->temp[nr][index] = reg; > > -- > 1.8.3.1 > ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2] hwmon/tmp401: use smb word operations instead of 2 smb byte operations 2017-01-09 16:47 [PATCH 1/2] hwmon/tmp401: use smb word operations instead of 2 smb byte operations jeroen.de_wachter.ext 2017-01-09 16:47 ` [PATCH 2/2] hwmon/tmp401: Fix some checkstyle warnings jeroen.de_wachter.ext 2017-01-09 17:09 ` [PATCH 1/2] hwmon/tmp401: use smb word operations instead of 2 smb byte operations Guenter Roeck @ 2017-01-09 17:55 ` jeroen.de_wachter.ext 2017-01-10 17:03 ` [v2] " Guenter Roeck 2 siblings, 1 reply; 6+ messages in thread From: jeroen.de_wachter.ext @ 2017-01-09 17:55 UTC (permalink / raw) To: linux, jdelvare; +Cc: linux-hwmon, linux-kernel, Jeroen De Wachter From: Jeroen De Wachter <jeroen.de_wachter.ext@nokia.com> tmp401 separately read/wrote high and low bytes of temperature values while the hardware supports reading/writing those values in one operation. Driver has been modified to use word operations where possible. Tested with a tmp432 sensor on a mips64 platform. Signed-off-by: Jeroen De Wachter <jeroen.de_wachter.ext@nokia.com> --- drivers/hwmon/tmp401.c | 49 ++++++++++++++----------------------------------- 1 file changed, 14 insertions(+), 35 deletions(-) diff --git a/drivers/hwmon/tmp401.c b/drivers/hwmon/tmp401.c index eeeed2c..0af6b86 100644 --- a/drivers/hwmon/tmp401.c +++ b/drivers/hwmon/tmp401.c @@ -82,16 +82,6 @@ { 0, 0x11 }, /* offset */ }; -static const u8 TMP401_TEMP_LSB[7][2] = { - { 0x15, 0x10 }, /* temp */ - { 0x17, 0x14 }, /* low limit */ - { 0x16, 0x13 }, /* high limit */ - { 0, 0 }, /* therm (crit) limit (unused) */ - { 0x31, 0x35 }, /* lowest */ - { 0x33, 0x37 }, /* highest */ - { 0, 0x12 }, /* offset */ -}; - static const u8 TMP432_TEMP_MSB_READ[4][3] = { { 0x00, 0x01, 0x23 }, /* temp */ { 0x06, 0x08, 0x16 }, /* low limit */ @@ -106,12 +96,6 @@ { 0x20, 0x19, 0x1A }, /* therm (crit) limit */ }; -static const u8 TMP432_TEMP_LSB[3][3] = { - { 0x29, 0x10, 0x24 }, /* temp */ - { 0x3E, 0x14, 0x18 }, /* low limit */ - { 0x3D, 0x13, 0x17 }, /* high limit */ -}; - /* [0] = fault, [1] = low, [2] = high, [3] = therm/crit */ static const u8 TMP432_STATUS_REG[] = { 0x1b, 0x36, 0x35, 0x37 }; @@ -213,25 +197,20 @@ static int tmp401_update_device_reg16(struct i2c_client *client, for (i = 0; i < num_sensors; i++) { /* local / r1 / r2 */ for (j = 0; j < num_regs; j++) { /* temp / low / ... */ u8 regaddr; - /* - * High byte must be read first immediately followed - * by the low byte - */ + regaddr = data->kind == tmp432 ? TMP432_TEMP_MSB_READ[j][i] : TMP401_TEMP_MSB_READ[j][i]; - val = i2c_smbus_read_byte_data(client, regaddr); - if (val < 0) - return val; - data->temp[j][i] = val << 8; - if (j == 3) /* crit is msb only */ - continue; - regaddr = data->kind == tmp432 ? TMP432_TEMP_LSB[j][i] - : TMP401_TEMP_LSB[j][i]; - val = i2c_smbus_read_byte_data(client, regaddr); + if (j == 3) { /* crit is msb only */ + val = i2c_smbus_read_byte_data(client, regaddr); + } else { + val = i2c_smbus_read_word_swapped(client, + regaddr); + } if (val < 0) return val; - data->temp[j][i] |= val; + + data->temp[j][i] = j == 3 ? val << 8 : val; } } return 0; @@ -373,11 +352,11 @@ static ssize_t store_temp(struct device *dev, struct device_attribute *devattr, regaddr = data->kind == tmp432 ? TMP432_TEMP_MSB_WRITE[nr][index] : TMP401_TEMP_MSB_WRITE[nr][index]; - i2c_smbus_write_byte_data(client, regaddr, reg >> 8); - if (nr != 3) { - regaddr = data->kind == tmp432 ? TMP432_TEMP_LSB[nr][index] - : TMP401_TEMP_LSB[nr][index]; - i2c_smbus_write_byte_data(client, regaddr, reg & 0xFF); + if (nr == 3) { /* crit is msb only */ + i2c_smbus_write_byte_data(client, regaddr, reg >> 8); + } else { + /* Hardware expects big endian data --> use _swapped */ + i2c_smbus_write_word_swapped(client, regaddr, reg); } data->temp[nr][index] = reg; -- 1.8.3.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [v2] hwmon/tmp401: use smb word operations instead of 2 smb byte operations 2017-01-09 17:55 ` [PATCH v2] " jeroen.de_wachter.ext @ 2017-01-10 17:03 ` Guenter Roeck 0 siblings, 0 replies; 6+ messages in thread From: Guenter Roeck @ 2017-01-10 17:03 UTC (permalink / raw) To: jeroen.de_wachter.ext; +Cc: jdelvare, linux-hwmon, linux-kernel On Mon, Jan 09, 2017 at 06:55:00PM +0100, jeroen.de_wachter.ext@nokia.com wrote: > From: Jeroen De Wachter <jeroen.de_wachter.ext@nokia.com> > > tmp401 separately read/wrote high and low bytes of temperature values while > the hardware supports reading/writing those values in one operation. Driver > has been modified to use word operations where possible. > > Tested with a tmp432 sensor on a mips64 platform. > > Signed-off-by: Jeroen De Wachter <jeroen.de_wachter.ext@nokia.com> Applied to -next. Thanks, Guenter > --- > drivers/hwmon/tmp401.c | 49 ++++++++++++++----------------------------------- > 1 file changed, 14 insertions(+), 35 deletions(-) > > diff --git a/drivers/hwmon/tmp401.c b/drivers/hwmon/tmp401.c > index eeeed2c..0af6b86 100644 > --- a/drivers/hwmon/tmp401.c > +++ b/drivers/hwmon/tmp401.c > @@ -82,16 +82,6 @@ > { 0, 0x11 }, /* offset */ > }; > > -static const u8 TMP401_TEMP_LSB[7][2] = { > - { 0x15, 0x10 }, /* temp */ > - { 0x17, 0x14 }, /* low limit */ > - { 0x16, 0x13 }, /* high limit */ > - { 0, 0 }, /* therm (crit) limit (unused) */ > - { 0x31, 0x35 }, /* lowest */ > - { 0x33, 0x37 }, /* highest */ > - { 0, 0x12 }, /* offset */ > -}; > - > static const u8 TMP432_TEMP_MSB_READ[4][3] = { > { 0x00, 0x01, 0x23 }, /* temp */ > { 0x06, 0x08, 0x16 }, /* low limit */ > @@ -106,12 +96,6 @@ > { 0x20, 0x19, 0x1A }, /* therm (crit) limit */ > }; > > -static const u8 TMP432_TEMP_LSB[3][3] = { > - { 0x29, 0x10, 0x24 }, /* temp */ > - { 0x3E, 0x14, 0x18 }, /* low limit */ > - { 0x3D, 0x13, 0x17 }, /* high limit */ > -}; > - > /* [0] = fault, [1] = low, [2] = high, [3] = therm/crit */ > static const u8 TMP432_STATUS_REG[] = { > 0x1b, 0x36, 0x35, 0x37 }; > @@ -213,25 +197,20 @@ static int tmp401_update_device_reg16(struct i2c_client *client, > for (i = 0; i < num_sensors; i++) { /* local / r1 / r2 */ > for (j = 0; j < num_regs; j++) { /* temp / low / ... */ > u8 regaddr; > - /* > - * High byte must be read first immediately followed > - * by the low byte > - */ > + > regaddr = data->kind == tmp432 ? > TMP432_TEMP_MSB_READ[j][i] : > TMP401_TEMP_MSB_READ[j][i]; > - val = i2c_smbus_read_byte_data(client, regaddr); > - if (val < 0) > - return val; > - data->temp[j][i] = val << 8; > - if (j == 3) /* crit is msb only */ > - continue; > - regaddr = data->kind == tmp432 ? TMP432_TEMP_LSB[j][i] > - : TMP401_TEMP_LSB[j][i]; > - val = i2c_smbus_read_byte_data(client, regaddr); > + if (j == 3) { /* crit is msb only */ > + val = i2c_smbus_read_byte_data(client, regaddr); > + } else { > + val = i2c_smbus_read_word_swapped(client, > + regaddr); > + } > if (val < 0) > return val; > - data->temp[j][i] |= val; > + > + data->temp[j][i] = j == 3 ? val << 8 : val; > } > } > return 0; > @@ -373,11 +352,11 @@ static ssize_t store_temp(struct device *dev, struct device_attribute *devattr, > > regaddr = data->kind == tmp432 ? TMP432_TEMP_MSB_WRITE[nr][index] > : TMP401_TEMP_MSB_WRITE[nr][index]; > - i2c_smbus_write_byte_data(client, regaddr, reg >> 8); > - if (nr != 3) { > - regaddr = data->kind == tmp432 ? TMP432_TEMP_LSB[nr][index] > - : TMP401_TEMP_LSB[nr][index]; > - i2c_smbus_write_byte_data(client, regaddr, reg & 0xFF); > + if (nr == 3) { /* crit is msb only */ > + i2c_smbus_write_byte_data(client, regaddr, reg >> 8); > + } else { > + /* Hardware expects big endian data --> use _swapped */ > + i2c_smbus_write_word_swapped(client, regaddr, reg); > } > data->temp[nr][index] = reg; > ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2017-01-10 17:03 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2017-01-09 16:47 [PATCH 1/2] hwmon/tmp401: use smb word operations instead of 2 smb byte operations jeroen.de_wachter.ext 2017-01-09 16:47 ` [PATCH 2/2] hwmon/tmp401: Fix some checkstyle warnings jeroen.de_wachter.ext 2017-01-09 17:11 ` Guenter Roeck 2017-01-09 17:09 ` [PATCH 1/2] hwmon/tmp401: use smb word operations instead of 2 smb byte operations Guenter Roeck 2017-01-09 17:55 ` [PATCH v2] " jeroen.de_wachter.ext 2017-01-10 17:03 ` [v2] " Guenter Roeck
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).