hwmon: (aht10) Fix typos in comments
Subsystems (2)
PATCH 1/3 hwmon: (aht10) Fix typos in comments
Fix typos in the description of the return value section of the functions. The word 'succesfull' is incorrect, it should be 'successful'.
--- drivers/hwmon/aht10.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hwmon/aht10.c +2 -2
@@ -80,7 +80,7 @@ struct aht10_data {/** * aht10_init() - Initialize an AHT10 chip * @data: the data associated with this AHT10 chip -* Return: 0 if succesfull, 1 if not +* Return: 0 if successful, 1 if not */ static int aht10_init (struct aht10_data *data) {
@@ -124,7 +124,7 @@ static int aht10_polltime_expired(struct aht10_data *data)/** * aht10_read_values() - read and parse the raw data from the AHT10 * @data: the struct aht10_data to use for the lock -* Return: 0 if succesfull, 1 if not +* Return: 0 if successful, 1 if not */ static int aht10_read_values (struct aht10_data *data) {
Signature · 1 line
2.25.1
PATCH 2/3 hwmon: (aht10) Refactor aht10_read_values function
Exit from the function immediately if the poll time hasn't yet expired. Therefore the code after the check can be moved one tab to the left which improves readability.
--- drivers/hwmon/aht10.c | 67 ++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 32 deletions(-)
drivers/hwmon/aht10.c +35 -32
@@ -135,40 +135,43 @@ static int aht10_read_values(struct aht10_data *data)struct i2c_client *client = data->client;mutex_lock (&data->lock); -if (aht10_polltime_expired (data)) { - res =i2c_master_send (client, cmd_meas,sizeof (cmd_meas)); -if (res <0 ) { -mutex_unlock (&data->lock); +if (!aht10_polltime_expired (data)) { +mutex_unlock (&data->lock); +return 0 ; + } + + res =i2c_master_send (client, cmd_meas,sizeof (cmd_meas)); +if (res <0 ) { +mutex_unlock (&data->lock); +return res; + } + +usleep_range (AHT10_MEAS_DELAY ,AHT10_MEAS_DELAY +AHT10_DELAY_EXTRA ); + + res =i2c_master_recv (client, raw_data,AHT10_MEAS_SIZE ); +if (res !=AHT10_MEAS_SIZE ) { +mutex_unlock (&data->lock); +if (res >=0 ) +return -ENODATA ; +else return res; - } - -usleep_range (AHT10_MEAS_DELAY , -AHT10_MEAS_DELAY +AHT10_DELAY_EXTRA ); - - res =i2c_master_recv (client, raw_data,AHT10_MEAS_SIZE ); -if (res !=AHT10_MEAS_SIZE ) { -mutex_unlock (&data->lock); -if (res >=0 ) -return -ENODATA ; -else -return res; - } - - hum = ((u32 )raw_data[1 ] <<12u ) | - ((u32 )raw_data[2 ] <<4u ) | - ((raw_data[3 ] &0xF0u ) >>4u ); - - temp = ((u32)(raw_data[3 ] &0x0Fu ) <<16u ) | - ((u32 )raw_data[4 ] <<8u ) | - raw_data[5 ]; - - temp = ((temp *625 ) >>15u ) *10 ; - hum = ((hum *625 ) >>16u ) *10 ; - - data->temperature = (int )temp -50000 ; - data->humidity = hum; - data->previous_poll_time =ktime_get_boottime (); } + + hum = ((u32 )raw_data[1 ] <<12u ) | + ((u32 )raw_data[2 ] <<4u ) | + ((raw_data[3 ] &0xF0u ) >>4u ); + + temp = ((u32)(raw_data[3 ] &0x0Fu ) <<16u ) | + ((u32 )raw_data[4 ] <<8u ) | + raw_data[5 ]; + + temp = ((temp *625 ) >>15u ) *10 ; + hum = ((hum *625 ) >>16u ) *10 ; + + data->temperature = (int )temp -50000 ; + data->humidity = hum; + data->previous_poll_time =ktime_get_boottime (); +mutex_unlock (&data->lock);return 0 ; }
Signature · 1 line
2.25.1
Guenter Roeck
maintainerRe: [PATCH 2/3] hwmon: (aht10) Refactor aht10_read_values function
Quoted 31 lines · Kirill Yatsenko
Exit from the function immediately if the poll time hasn't yet expired. Therefore the code after the check can be moved one tab to the left which improves readability.
Signed-off-by Kirill Yatsenko <[email protected]>--- drivers/hwmon/aht10.c | 67 ++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 32 deletions(-)drivers/hwmon/aht10.c +10
-4@@ -135,40 +135,43 @@ static int aht10_read_values(struct aht10_data *data)struct i2c_client *client = data->client;mutex_lock (&data->lock); -if (aht10_polltime_expired (data)) { - res =i2c_master_send (client, cmd_meas,sizeof (cmd_meas)); -if (res <0 ) { -mutex_unlock (&data->lock); +if (!aht10_polltime_expired (data)) { +mutex_unlock (&data->lock); +return 0 ; + } + + res =i2c_master_send (client, cmd_meas,sizeof (cmd_meas)); +if (res <0 ) { +mutex_unlock (&data->lock); +return res; + }
drivers/hwmon/aht10.c static int aht10_read_values(struct aht10_data *data) · line 157
Quoted 10 lines
drivers/hwmon/aht10.c +9
-0+ +usleep_range (AHT10_MEAS_DELAY ,AHT10_MEAS_DELAY +AHT10_DELAY_EXTRA ); + + res =i2c_master_recv (client, raw_data,AHT10_MEAS_SIZE ); +if (res !=AHT10_MEAS_SIZE ) { +mutex_unlock (&data->lock); +if (res >=0 ) +return -ENODATA ; +else return res;
else after return is pointless (and static analyzers complain about it).
No need to resend (I see it is inherited from old code). I'll fix it up when applying the patch.
Guenter
Quoted 48 lines
drivers/hwmon/aht10.c +16
-28- } - -usleep_range (AHT10_MEAS_DELAY , -AHT10_MEAS_DELAY +AHT10_DELAY_EXTRA ); - - res =i2c_master_recv (client, raw_data,AHT10_MEAS_SIZE ); -if (res !=AHT10_MEAS_SIZE ) { -mutex_unlock (&data->lock); -if (res >=0 ) -return -ENODATA ; -else -return res; - } - - hum = ((u32 )raw_data[1 ] <<12u ) | - ((u32 )raw_data[2 ] <<4u ) | - ((raw_data[3 ] &0xF0u ) >>4u ); - - temp = ((u32)(raw_data[3 ] &0x0Fu ) <<16u ) | - ((u32 )raw_data[4 ] <<8u ) | - raw_data[5 ]; - - temp = ((temp *625 ) >>15u ) *10 ; - hum = ((hum *625 ) >>16u ) *10 ; - - data->temperature = (int )temp -50000 ; - data->humidity = hum; - data->previous_poll_time =ktime_get_boottime (); } + + hum = ((u32 )raw_data[1 ] <<12u ) | + ((u32 )raw_data[2 ] <<4u ) | + ((raw_data[3 ] &0xF0u ) >>4u ); + + temp = ((u32)(raw_data[3 ] &0x0Fu ) <<16u ) | + ((u32 )raw_data[4 ] <<8u ) | + raw_data[5 ]; + + temp = ((temp *625 ) >>15u ) *10 ; + hum = ((hum *625 ) >>16u ) *10 ; + + data->temperature = (int )temp -50000 ; + data->humidity = hum; + data->previous_poll_time =ktime_get_boottime (); +mutex_unlock (&data->lock);return 0 ; }
PATCH 3/3 hwmon: (aht10) Add support for compatible aht20
In reply to Kirill YatsenkoAdd support for compatible AHT20 temperature/humidity sensor. The only software difference between the two is that AHT20 has additional crc8 byte.
It seems like AHT15 is also supported by the driver but it wasn't verified and tested yet.
Tested on Beaglebone black rev C.
--- Documentation/hwmon/aht10.rst | 20 +++++++++---- drivers/hwmon/Kconfig | 11 +++++-- drivers/hwmon/aht10.c | 54 ++++++++++++++++++++++++++++------- 3 files changed, 68 insertions(+), 17 deletions(-)
Documentation/hwmon/aht10.rst +15 -5
@@ -5,32 +5,42 @@ Kernel driver aht10 Supported chips: - * Aosong AHT10 + * Aosong AHT10/AHT20 Prefix: 'aht10' Addresses scanned: None - Datasheet: + Datasheet(AHT10): Chinese: http://www.aosong.com/userfiles/files/media/AHT10%E4%BA%A7%E5%93%81%E6%89%8B%E5%86%8C%20A3%2020201210.pdf English: https://server4.eca.ir/eshop/AHT10/Aosong_AHT10_en_draft_0c.pdf + Datasheet(AHT20): + + English: http://www.aosong.com/userfiles/files/media/Data%20Sheet%20AHT20.pdf + Author: Johannes Cornelis Draaijer <[email protected]> Description ----------- -The AHT10 is a Temperature and Humidity sensor +The AHT10/AHT20 is a Temperature and Humidity sensor The address of this i2c device may only be 0x38 +Special Features +---------------- + +AHT20 has additional CRC8 support which is sent as the last byte of the sensor +values. + Usage Notes ----------- -This driver does not probe for AHT10 devices, as there is no reliable -way to determine if an i2c chip is or isn't an AHT10. The device has +This driver does not probe for AHT10/ATH20 devices, as there is no reliable +way to determine if an i2c chip is or isn't an AHT10/AHT20. The device has to be instantiated explicitly with the address 0x38. See Documentation/i2c/instantiating-devices.rst for details.
drivers/hwmon/Kconfig +9 -2
@@ -255,15 +255,22 @@ config SENSORS_ADT7475 will be called adt7475. config SENSORS_AHT10 - tristate "Aosong AHT10" + tristate "Aosong AHT10, AHT20" depends on I2C help - If you say yes here, you get support for the Aosong AHT10 + If you say yes here, you get support for the Aosong AHT10 and AHT20 temperature and humidity sensors This driver can also be built as a module. If so, the module will be called aht10. +config SENSORS_AHT20_CRC + bool "Aosong AHT20 crc8 check" + depends on SENSORS_AHT10 + select CRC8 + help + If you say yes here, you get support for the Aosong AHT20 CRC8 check + config SENSORS_AQUACOMPUTER_D5NEXT tristate "Aquacomputer D5 Next, Octo, Quadro, Farbwerk, Farbwerk 360, High Flow Next" depends on USB_HID
drivers/hwmon/aht10.c +44 -10
113 lines not on this page · raw message
Signature · 1 line
2.25.1
Guenter Roeck
maintainerRe: [PATCH 3/3] hwmon: (aht10) Add support for compatible aht20
Quoted 84 lines · Kirill Yatsenko
Add support for compatible AHT20 temperature/humidity sensor. The only software difference between the two is that AHT20 has additional crc8 byte.
It seems like AHT15 is also supported by the driver but it wasn't verified and tested yet.
Tested on Beaglebone black rev C.
Signed-off-by Kirill Yatsenko <[email protected]>--- Documentation/hwmon/aht10.rst | 20 +++++++++---- drivers/hwmon/Kconfig | 11 +++++-- drivers/hwmon/aht10.c | 54 ++++++++++++++++++++++++++++------- 3 files changed, 68 insertions(+), 17 deletions(-)Documentation/hwmon/aht10.rst +15
-5@@ -5,32 +5,42 @@ Kernel driver aht10 Supported chips: - * Aosong AHT10 + * Aosong AHT10/AHT20 Prefix: 'aht10' Addresses scanned: None - Datasheet: + Datasheet(AHT10): Chinese: http://www.aosong.com/userfiles/files/media/AHT10%E4%BA%A7%E5%93%81%E6%89%8B%E5%86%8C%20A3%2020201210.pdf English: https://server4.eca.ir/eshop/AHT10/Aosong_AHT10_en_draft_0c.pdf + Datasheet(AHT20): + + English: http://www.aosong.com/userfiles/files/media/Data%20Sheet%20AHT20.pdf + Author: Johannes Cornelis Draaijer <[email protected]> Description ----------- -The AHT10 is a Temperature and Humidity sensor +The AHT10/AHT20 is a Temperature and Humidity sensor The address of this i2c device may only be 0x38 +Special Features +---------------- + +AHT20 has additional CRC8 support which is sent as the last byte of the sensor +values. + Usage Notes ----------- -This driver does not probe for AHT10 devices, as there is no reliable -way to determine if an i2c chip is or isn't an AHT10. The device has +This driver does not probe for AHT10/ATH20 devices, as there is no reliable +way to determine if an i2c chip is or isn't an AHT10/AHT20. The device has to be instantiated explicitly with the address 0x38. See Documentation/i2c/instantiating-devices.rst for details.drivers/hwmon/Kconfig +2
-2@@ -255,15 +255,22 @@ config SENSORS_ADT7475 will be called adt7475. config SENSORS_AHT10 - tristate "Aosong AHT10" + tristate "Aosong AHT10, AHT20" depends on I2C help - If you say yes here, you get support for the Aosong AHT10 + If you say yes here, you get support for the Aosong AHT10 and AHT20 temperature and humidity sensors
drivers/hwmon/Kconfig config SENSORS_ADT7475 · line 273
Quoted 10 lines
drivers/hwmon/Kconfig +7
-0This driver can also be built as a module. If so, the module will be called aht10. +config SENSORS_AHT20_CRC + bool "Aosong AHT20 crc8 check" + depends on SENSORS_AHT10 + select CRC8 + help + If you say yes here, you get support for the Aosong AHT20 CRC8 check +
This is not an appropriate configuration flag. aht20 needs to be added to aht10_id, and the code needs to use a flag in driver data (struct aht10_data) to determine if the crc check needs to be applied or not. There must be no related ifdefs in the code.
Guenter
Quoted 4 lines · Kirill Yatsenko
Fix typos in the description of the return value section of the functions. The word 'succesfull' is incorrect, it should be 'successful'.
Signed-off-by Kirill Yatsenko <[email protected]>
Applied.
Thanks,
Guenter
Quoted 26 lines
--- drivers/hwmon/aht10.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/hwmon/aht10.c +2
-2@@ -80,7 +80,7 @@ struct aht10_data {/** * aht10_init() - Initialize an AHT10 chip * @data: the data associated with this AHT10 chip -* Return: 0 if succesfull, 1 if not +* Return: 0 if successful, 1 if not */ static int aht10_init (struct aht10_data *data) {@@ -124,7 +124,7 @@ static int aht10_polltime_expired(struct aht10_data *data)/** * aht10_read_values() - read and parse the raw data from the AHT10 * @data: the struct aht10_data to use for the lock -* Return: 0 if succesfull, 1 if not +* Return: 0 if successful, 1 if not */ static int aht10_read_values (struct aht10_data *data) {