hwmon: (hs300x) Add driver for Renesas HS300x
Subsystems (3)
PATCH 1/2 hwmon: (hs300x) Add driver for Renesas HS300x
Add base support for Renesas HS300x temperature
and humidity sensors.
The sensors has a fix I2C address 0x44. The resolution is fixed to 14bit (ref. Missing feature).
Missing feature:
- Accessing non-volatile memory: Custom board has no possibility to control voltage supply of sensor. Thus, we cannot send the necessary control commands within the first 10ms after power-on.
--- Documentation/hwmon/hs300x.rst | 61 +++++ drivers/hwmon/Kconfig | 10 + drivers/hwmon/Makefile | 1 + drivers/hwmon/hs300x.c | 461 +++++++++++++++++++++++++++++++++ 4 files changed, 533 insertions(+) create mode 100644 Documentation/hwmon/hs300x.rst create mode 100644 drivers/hwmon/hs300x.c
Documentation/hwmon/hs300x.rst new file +61 -0
@@ -0,0 +1,61 @@ +.. SPDX-License-Identifier: GPL-2.0-or-later + +Kernel driver HS300x +=================== + +Supported chips: + + * Renesas HS3001, HS3002, HS3003, HS3004 + + Prefix: 'hs300x' + + Addresses scanned: - + + Datasheet: https://www.renesas.com/us/en/document/dst/hs300x-datasheet?r=417401 + +Author: + + - Andre Werner <[email protected]> + +Description +----------- + +This driver implements support for the Renesas HS300x chips, a humidity +and temperature family. Temperature is measured in degrees celsius, relative +humidity is expressed as a percentage. In the sysfs interface, all values are +scaled by 1000, i.e. the value for 31.5 degrees celsius is 31500. + +The device communicates with the I2C protocol. Sensors can have the I2C +address 0x44 by default. + +The driver does not support the sensor's configuration possibilities. + +The driver is able to be read out using lmsensors. + +sysfs-Interface +--------------- + +=============================================================================== +temp1_input: temperature input +humidity1_input: humidity input +temp1_max: temperature max value +humidity1_max: humidity max value +temp1_min: temperature min value +humidity1_min: humidity min value +measuretime: Measurement delay in usec +=============================================================================== + +Device Tree +----------- + +Required node properties: + + - compatible: must be set to "hs3001", "hs3002", "hs3003", "hs3004" + - reg: I2C address of the device (0x44) + +Example: + + humidity: hs3002@44 { + compatible = "hs3002"; + reg = <0x44>; + };
drivers/hwmon/Kconfig +10 -0
@@ -734,6 +734,16 @@ config SENSORS_HIH6130 This driver can also be built as a module. If so, the module will be called hih6130. +config SENSORS_HS300x + tristate "Renesas HS300x humidity and temperature sensors" + depends on I2C + help + If you say yes here you get support for the Renesas HS300x + humidity and temperature sensors. + + This driver can also be built as a module. If so, the module + will be called hs300x. + config SENSORS_IBMAEM tristate "IBM Active Energy Manager temperature/power sensors and control" select IPMI_SI
drivers/hwmon/Makefile +1 -0
@@ -86,6 +86,7 @@ obj-$(CONFIG_SENSORS_GSC) += gsc-hwmon.o obj-$(CONFIG_SENSORS_GPIO_FAN) += gpio-fan.o obj-$(CONFIG_SENSORS_GXP_FAN_CTRL) += gxp-fan-ctrl.o obj-$(CONFIG_SENSORS_HIH6130) += hih6130.o +obj-$(CONFIG_SENSORS_HS300x) += hs300x.o obj-$(CONFIG_SENSORS_ULTRA45) += ultra45_env.o obj-$(CONFIG_SENSORS_I5500) += i5500_temp.o obj-$(CONFIG_SENSORS_I5K_AMB) += i5k_amb.o
drivers/hwmon/hs300x.c new file +461 -0
461 lines not on this page · raw message
Signature · 1 line
2.41.0
PATCH 2/2 dt-bindings: hwmon: Add description for new hwmon driver hs300x
This is the initial description.
--- .../devicetree/bindings/hwmon/hs300x.yaml | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Documentation/devicetree/bindings/hwmon/hs300x.yaml
Documentation/devicetree/bindings/hwmon/hs300x.yaml new file +58 -0
@@ -0,0 +1,58 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- + +$id: http://devicetree.org/schemas/hwmon/hs300x.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Renesas HS300x humidity and temperature sensor + +maintainers: + - Andre Werner ([email protected]) + +description: | + This driver implements support for the Renesas HS300x chips, a humidity + and temperature family. Temperature is measured in degrees celsius, relative + humidity is expressed as a percentage. In the sysfs interface, all values are + scaled by 1000, i.e. the value for 31.5 degrees celsius is 31500. + + The device communicates with the I2C protocol. Sensors can have the I2C + address 0x44 by default. + + The driver does not support the sensor's configuration possibilities. + + The driver is able to be read out using lmsensors. + + Datasheets: + https://www.renesas.com/us/en/document/dst/hs300x-datasheet?r=417401 + + + +properties: + compatible: + enum: + - hs3001 + - hs3002 + - hs3003 + - hs3004 + + reg: + maxItems: 1 + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + humidity: hs3002@44 { + compatible = "hs3002"; + reg = <0x44>; + }; + };
Signature · 1 line
2.41.0
Re: [PATCH 2/2] dt-bindings: hwmon: Add description for new hwmon driver hs300x
Quoted 7 lines · Andre Werner
This is the initial description.
Signed-off-by Andre Werner <[email protected]>--- .../devicetree/bindings/hwmon/hs300x.yaml | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Documentation/devicetree/bindings/hwmon/hs300x.yaml
Please use scripts/get_maintainers.pl to get a list of necessary people and lists to CC. It might happen, that command when run on an older kernel, gives you outdated entries. Therefore please be sure you base your patches on recent Linux kernel.
You missed at least DT list (maybe more), so this won't be tested by automated tooling. Performing review on untested code might be a waste of time, thus I will skip this patch entirely till you follow the process allowing the patch to be tested.
Please kindly resend and include all necessary To/Cc entries.
Documentation/devicetree/bindings/hwmon/hs300x.yaml
Quoted 6 lines
Documentation/devicetree/bindings/hwmon/hs300x.yaml new file +0
-0
Filename like compatible
Documentation/devicetree/bindings/hwmon/hs300x.yaml line 4
Quoted 5 lines
Documentation/devicetree/bindings/hwmon/hs300x.yaml new file +4
-0@@ -0,0 +1,58 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +
Drop
Documentation/devicetree/bindings/hwmon/hs300x.yaml line 14
Quoted 10 lines
Documentation/devicetree/bindings/hwmon/hs300x.yaml new file +10
-0+$id: http://devicetree.org/schemas/hwmon/hs300x.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Renesas HS300x humidity and temperature sensor + +maintainers: + - Andre Werner ([email protected]) + +description: | + This driver implements support for the Renesas HS300x chips, a humidity
Bindings are for hardware, not drivers.
Documentation/devicetree/bindings/hwmon/hs300x.yaml line 17
Quoted 3 lines
Documentation/devicetree/bindings/hwmon/hs300x.yaml new file +3
-0+ and temperature family. Temperature is measured in degrees celsius, relative + humidity is expressed as a percentage. In the sysfs interface, all values are + scaled by 1000, i.e. the value for 31.5 degrees celsius is 31500.
sysfs is not hardware related, drop.
Documentation/devicetree/bindings/hwmon/hs300x.yaml line 29
Quoted 12 lines
Documentation/devicetree/bindings/hwmon/hs300x.yaml new file +12
-0+ + The device communicates with the I2C protocol. Sensors can have the I2C + address 0x44 by default. + + The driver does not support the sensor's configuration possibilities. + + The driver is able to be read out using lmsensors. + + Datasheets: + https://www.renesas.com/us/en/document/dst/hs300x-datasheet?r=417401 + +
Just one blank line.
Documentation/devicetree/bindings/hwmon/hs300x.yaml line 37
Quoted 8 lines
Documentation/devicetree/bindings/hwmon/hs300x.yaml new file +8
-0+ +properties: + compatible: + enum: + - hs3001 + - hs3002 + - hs3003 + - hs3004
Eh, so this was not tested... That's not correct compatible, missing vendor prefix.
Documentation/devicetree/bindings/hwmon/hs300x.yaml line 41
Quoted 4 lines
Documentation/devicetree/bindings/hwmon/hs300x.yaml new file +4
-0+ + reg: + maxItems: 1 +
Missing several properties.
Documentation/devicetree/bindings/hwmon/hs300x.yaml line 54
Quoted 13 lines
Documentation/devicetree/bindings/hwmon/hs300x.yaml new file +13
-0+required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + humidity: hs3002@44 {
Node names should be generic. See also an explanation and list of examples (not exhaustive) in DT specification:
https://devicetree-specification.readthedocs.io/en/latest/chapter2-devicetree-basics.html#generic-names-recommendation
Documentation/devicetree/bindings/hwmon/hs300x.yaml line 58
Quoted 4 lines
Documentation/devicetree/bindings/hwmon/hs300x.yaml new file +4
-0+ compatible = "hs3002"; + reg = <0x44>; + }; + };
Best regards,
Krzysztof
Guenter Roeck
maintainerRe: [PATCH 2/2] dt-bindings: hwmon: Add description for new hwmon driver hs300x
Quoted 14 lines · Krzysztof Kozlowski
Quoted 7 lines · Andre Werner
This is the initial description.
Signed-off-by Andre Werner <[email protected]>--- .../devicetree/bindings/hwmon/hs300x.yaml | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Documentation/devicetree/bindings/hwmon/hs300x.yamlPlease use
scripts/get_maintainers.plto get a list of necessary people and lists to CC. It might happen, that command when run on an older kernel, gives you outdated entries. Therefore please be sure you base your patches on recent Linux kernel.
Quoted 7 lines
You missed at least DT list (maybe more), so this won't be tested by automated tooling. Performing review on untested code might be a waste of time, thus I will skip this patch entirely till you follow the process allowing the patch to be tested.
Please kindly resend and include all necessary To/Cc entries.
The chips should just be added to trivial-devices.yaml.
Quoted 51 lines
Documentation/devicetree/bindings/hwmon/hs300x.yaml
Quoted 6 lines
Documentation/devicetree/bindings/hwmon/hs300x.yaml new file +0
-0Filename like compatible
Documentation/devicetree/bindings/hwmon/hs300x.yaml line 4
Quoted 5 lines
Documentation/devicetree/bindings/hwmon/hs300x.yaml new file +4
-0@@ -0,0 +1,58 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +Drop
Documentation/devicetree/bindings/hwmon/hs300x.yaml line 14
Quoted 10 lines
Documentation/devicetree/bindings/hwmon/hs300x.yaml new file +10
-0+$id: http://devicetree.org/schemas/hwmon/hs300x.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Renesas HS300x humidity and temperature sensor + +maintainers: + - Andre Werner ([email protected]) + +description: | + This driver implements support for the Renesas HS300x chips, a humidityBindings are for hardware, not drivers.
Documentation/devicetree/bindings/hwmon/hs300x.yaml line 17
Quoted 3 lines
Documentation/devicetree/bindings/hwmon/hs300x.yaml new file +3
-0+ and temperature family. Temperature is measured in degrees celsius, relative + humidity is expressed as a percentage. In the sysfs interface, all values are + scaled by 1000, i.e. the value for 31.5 degrees celsius is 31500.sysfs is not hardware related, drop.
Documentation/devicetree/bindings/hwmon/hs300x.yaml line 29
Quoted 12 lines
Documentation/devicetree/bindings/hwmon/hs300x.yaml new file +12
-0+ + The device communicates with the I2C protocol. Sensors can have the I2C + address 0x44 by default. + + The driver does not support the sensor's configuration possibilities. + + The driver is able to be read out using lmsensors. + + Datasheets: + https://www.renesas.com/us/en/document/dst/hs300x-datasheet?r=417401 + +Just one blank line.
Quoted 12 lines
Documentation/devicetree/bindings/hwmon/hs300x.yaml line 37
Quoted 8 lines
Documentation/devicetree/bindings/hwmon/hs300x.yaml new file +8
-0+ +properties: + compatible: + enum: + - hs3001 + - hs3002 + - hs3003 + - hs3004Eh, so this was not tested... That's not correct compatible, missing vendor prefix.
Also, from programming perspective, the chips are all the same.
Quoted 34 lines
Documentation/devicetree/bindings/hwmon/hs300x.yaml line 41
Quoted 4 lines
Documentation/devicetree/bindings/hwmon/hs300x.yaml new file +4
-0+ + reg: + maxItems: 1 +Missing several properties.
Documentation/devicetree/bindings/hwmon/hs300x.yaml line 54
Quoted 13 lines
Documentation/devicetree/bindings/hwmon/hs300x.yaml new file +13
-0+required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + humidity: hs3002@44 {Node names should be generic. See also an explanation and list of examples (not exhaustive) in DT specification:
https://devicetree-specification.readthedocs.io/en/latest/chapter2-devicetree-basics.html#generic-names-recommendationDocumentation/devicetree/bindings/hwmon/hs300x.yaml line 58
Quoted 4 lines
Documentation/devicetree/bindings/hwmon/hs300x.yaml new file +4
-0+ compatible = "hs3002"; + reg = <0x44>; + }; + };Best regards,
Krzysztof
Quoted 12 lines · Andre Werner
Add base support for Renesas HS300x temperature
and humidity sensors.The sensors has a fix I2C address
0x44. The resolution is fixed to 14bit (ref. Missing feature).Missing feature:
- Accessing non-volatile memory: Custom board has no possibility to control voltage supply of sensor. Thus, we cannot send the necessary control commands within the first 10ms after power-on.
Please use scripts/get_maintainers.pl to get a list of necessary people and lists to CC (and consider --no-git-fallback argument). It might happen, that command when run on an older kernel, gives you outdated entries. Therefore please be sure you base your patches on recent Linux kernel.
Quoted 172 lines
Signed-off-by Andre Werner <[email protected]>--- Documentation/hwmon/hs300x.rst | 61 +++++ drivers/hwmon/Kconfig | 10 + drivers/hwmon/Makefile | 1 + drivers/hwmon/hs300x.c | 461 +++++++++++++++++++++++++++++++++ 4 files changed, 533 insertions(+) create mode 100644 Documentation/hwmon/hs300x.rst create mode 100644 drivers/hwmon/hs300x.cDocumentation/hwmon/hs300x.rst new file +61
-0@@ -0,0 +1,61 @@ +.. SPDX-License-Identifier: GPL-2.0-or-later + +Kernel driver HS300x +=================== + +Supported chips: + + * Renesas HS3001, HS3002, HS3003, HS3004 + + Prefix: 'hs300x' + + Addresses scanned: - + + Datasheet: https://www.renesas.com/us/en/document/dst/hs300x-datasheet?r=417401 + +Author: + + - Andre Werner <[email protected]> + +Description +----------- + +This driver implements support for the Renesas HS300x chips, a humidity +and temperature family. Temperature is measured in degrees celsius, relative +humidity is expressed as a percentage. In the sysfs interface, all values are +scaled by 1000, i.e. the value for 31.5 degrees celsius is 31500. + +The device communicates with the I2C protocol. Sensors can have the I2C +address 0x44 by default. + +The driver does not support the sensor's configuration possibilities. + +The driver is able to be read out using lmsensors. + +sysfs-Interface +--------------- + +=============================================================================== +temp1_input: temperature input +humidity1_input: humidity input +temp1_max: temperature max value +humidity1_max: humidity max value +temp1_min: temperature min value +humidity1_min: humidity min value +measuretime: Measurement delay in usec +=============================================================================== + +Device Tree +----------- + +Required node properties: + + - compatible: must be set to "hs3001", "hs3002", "hs3003", "hs3004" + - reg: I2C address of the device (0x44) + +Example: + + humidity: hs3002@44 { + compatible = "hs3002"; + reg = <0x44>; + };drivers/hwmon/Kconfig +10
-0@@ -734,6 +734,16 @@ config SENSORS_HIH6130 This driver can also be built as a module. If so, the module will be called hih6130. +config SENSORS_HS300x + tristate "Renesas HS300x humidity and temperature sensors" + depends on I2C + help + If you say yes here you get support for the Renesas HS300x + humidity and temperature sensors. + + This driver can also be built as a module. If so, the module + will be called hs300x. + config SENSORS_IBMAEM tristate "IBM Active Energy Manager temperature/power sensors and control" select IPMI_SIdrivers/hwmon/Makefile +1
-0@@ -86,6 +86,7 @@ obj-$(CONFIG_SENSORS_GSC) += gsc-hwmon.o obj-$(CONFIG_SENSORS_GPIO_FAN) += gpio-fan.o obj-$(CONFIG_SENSORS_GXP_FAN_CTRL) += gxp-fan-ctrl.o obj-$(CONFIG_SENSORS_HIH6130) += hih6130.o +obj-$(CONFIG_SENSORS_HS300x) += hs300x.o obj-$(CONFIG_SENSORS_ULTRA45) += ultra45_env.o obj-$(CONFIG_SENSORS_I5500) += i5500_temp.o obj-$(CONFIG_SENSORS_I5K_AMB) += i5k_amb.odrivers/hwmon/hs300x.c new file +56
-0@@ -0,0 +1,461 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* This is a non-complete driver implementation for the +* HS300x humidity and temperature sensors. It does not include +* the configuration possibilities, because the hardware platform the IC is +* used does not control the power source for the IC. Thus, it cannot being +* set to 'programming mode' during power-up. +* +* +* Copyright (C) 2022 SYS TEC electronic AG +* Author: Andre Werner <[email protected]> +*/ + +#include <linux/types.h> +#include <linux/delay.h> +#include <linux/err.h> +#include <linux/hwmon.h> +#include <linux/hwmon-sysfs.h> +#include <linux/i2c.h> +#include <linux/init.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/of_device.h> + +/* Measurement times */ +#define HS300X_WAKEUP_TIME 100/* us */ +#define HS300X_UNUSED 0/* us */ +#define HS300X_8BIT_RESOLUTION 550/* us */ +#define HS300X_10BIT_RESOLUTION 1310/* us */ +#define HS300X_12BIT_RESOLUTION 4500/* us */ +#define HS300X_14BIT_RESOLUTION 16900/* us */ + +#define HS300X_CMD_OK 0 +#define HS300X_RESPONSE_LENGTH 4 + +#define HS300X_FIXPOINT_ARITH 1000 +#define HS300X_MIN_TEMPERATURE (-40 * HS300X_FIXPOINT_ARITH)/* 1000 degree */ +#define HS300X_MAX_TEMPERATURE (125 * HS300X_FIXPOINT_ARITH)/* 1000 degree */ +#define HS300X_MIN_HUMIDITY (0 * HS300X_FIXPOINT_ARITH)/* 1000 % */ +#define HS300X_MAX_HUMIDITY (100 * HS300X_FIXPOINT_ARITH)/* 1000 % */ + +#define HS300X_MASK_HUMIDITY_0X3FFF (0x3FFF) +#define HS300X_MASK_TEMPERATURE_0XFFFC (0xFFFC) +#define HS300X_MASK_STATUS_0XC0 (0xC0) +#define HS300X_STATUS_SHIFT (6) + +/* Definitions for Status Bits of A/D Data */ +#define HS300X_DATA_VALID (0x00)/* Valid Data */ +#define HS300X_DATA_STALE (0x01)/* Stale Data */ + +#define LIMIT_MAX 0 +#define LIMIT_MIN 1 + +enum hs300x_chips { + hs3001, + hs3002,
drivers/hwmon/hs300x.c line 66
Quoted 10 lines
drivers/hwmon/hs300x.c new file +10
-0+ hs3003, + hs3004, +}; + +struct hs300x_accurancy { +u32 hum_acc;/* accurancy of humidity in *1000 % */ +u32 temp_acc;/* accurancy of temperature in *1000 % */ +}; + +const struct hs300x_accurancy hs300x_accurancys[] = {
Missing statuc
drivers/hwmon/hs300x.c line 73
Quoted 7 lines
drivers/hwmon/hs300x.c new file +7
-0+ { 1500, 200 }, + { 1800, 200 }, + { 2500, 250 }, + { 3500, 300 }, +}; + +struct hs300x_data {
Don't mix declarations and definitions.
drivers/hwmon/hs300x.c line 75
Quoted 2 lines
drivers/hwmon/hs300x.c new file +2
-0+struct i2c_client *client; +struct mutex i2c_lock;/* lock for sending i2c commands */
Why? I think I2C device do not need to do it.
Quoted 8 lines
drivers/hwmon/hs300x.c new file +6
-0+struct mutex data_lock;/* lock for updating driver data */ +u32 wait_time;/* in us */ +int temperature;/* in *1000 degree */ +u32 humidity;/* in *1000 % */ +}; +
drivers/hwmon/hs300x.c
Quoted 10 lines
drivers/hwmon/hs300x.c new file +10
-0+ +static ssize_t humidity1_input_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct hs300x_data *data =dev_get_drvdata (dev); +struct i2c_client *client; +int ret; + +if (IS_ERR (data)) +return PTR_ERR (data);
How is it possible?
drivers/hwmon/hs300x.c line 201
Quoted 4 lines
drivers/hwmon/hs300x.c new file +4
-0+ + client = data->client; + +if (!client) {
How is this possible?
Both suggest you have some troubles in probe.
Quoted 7 lines
drivers/hwmon/hs300x.c new file +7
-0+dev_dbg (dev,"No valid I2C client available.\n" ); +return -ENODEV ; + } + + ret =hs300x_measure_command (client, data); +if (ret !=HS300X_CMD_OK ) +return ret;
...
drivers/hwmon/hs300x.c line 382
Quoted 11 lines
drivers/hwmon/hs300x.c new file +11
-0+#endif +if (!i2c_check_functionality (adap,I2C_FUNC_I2C )) +return -ENODEV ; + + data =devm_kzalloc (dev,sizeof (*data),GFP_KERNEL ); +if (!data) +return -ENOMEM ; + + data->client = client; +/* Measurement time = wake-up time + measurement time temperature +* measurment time humidity This is currently static, because
Fix typos. Remove weird indentation after *
Quoted 15 lines
drivers/hwmon/hs300x.c new file +15
-0+* enabling programming mode is not supported, yet. +*/ + data->wait_time = (HS300X_WAKEUP_TIME +HS300X_14BIT_RESOLUTION + +HS300X_14BIT_RESOLUTION ); +mutex_init (&data->i2c_lock); +mutex_init (&data->data_lock); + +if (i2c_match_id (hs300x_ids, client)->driver_data == hs3001) + attribute_groups = hs3001_groups; +else if (i2c_match_id (hs300x_ids, client)->driver_data == hs3002) + attribute_groups = hs3002_groups; +else if (i2c_match_id (hs300x_ids, client)->driver_data == hs3003) + attribute_groups = hs3003_groups; +else if (i2c_match_id (hs300x_ids, client)->driver_data == hs3004) + attribute_groups = hs3004_groups;
drivers/hwmon/hs300x.c line 407
Quoted 10 lines
drivers/hwmon/hs300x.c new file +10
-0+else { +dev_err (dev,"Unknwon device for HS300x driver\n" ); + goto error; + } + +/* Measure humidity and temperature to initialize values */ + ret =hs300x_measure_command (client, data); +if (ret) { + goto error; + }
Please run scripts/checkpatch.pl and fix reported warnings. Some warnings can be ignored, but the code here looks like it needs a fix. Feel free to get in touch if the warning is not clear.
drivers/hwmon/hs300x.c line 416
Quoted 9 lines
drivers/hwmon/hs300x.c new file +9
-0+ +/* Sensor needs some time to process measurement depending on +* resolution +*/ +fsleep (data->wait_time); + + ret =hs300x_data_fetch_command (client, data); +if (ret !=HS300X_CMD_OK ) { + goto error;
Please run scripts/checkpatch.pl and fix reported warnings. Some warnings can be ignored, but the code here looks like it needs a fix. Feel free to get in touch if the warning is not clear.
drivers/hwmon/hs300x.c line 419
Quoted 3 lines
drivers/hwmon/hs300x.c new file +3
-0+ } + + hwmon_dev =
Don't wrap.
drivers/hwmon/hs300x.c line 425
Quoted 6 lines
drivers/hwmon/hs300x.c new file +6
-0+devm_hwmon_device_register_with_groups (dev, client->name, data, + attribute_groups); + +if (IS_ERR (hwmon_dev)) { +dev_err (dev,"Unable to register hwmon device %s\n" , + client->name);
return dev_err_probe
drivers/hwmon/hs300x.c line 430
Quoted 5 lines
drivers/hwmon/hs300x.c new file +5
-0+ goto error; + } + +dev_info (dev,"Successfully probe %s: sensor '%s'\n" , +dev_name (hwmon_dev), client->name);
Nope, no prints like that.
drivers/hwmon/hs300x.c line 431
Quoted 1 line
drivers/hwmon/hs300x.c new file +1
-0+return PTR_ERR_OR_ZERO (hwmon_dev);
Blank line.
drivers/hwmon/hs300x.c line 433
Quoted 2 lines
drivers/hwmon/hs300x.c new file +2
-0+error: +devm_kfree (dev, data);
You did not test it. You have double free here. If you do not believe, please test it.
Quoted 8 lines
drivers/hwmon/hs300x.c new file +8
-0+return -ENODEV ; +} + +/* device ID table */ +static const struct i2c_device_id hs300x_ids[] = { + {"hs3001" , hs3001 }, + {"hs3002" , hs3002 }, + {"hs3003" , hs3003 },
drivers/hwmon/hs300x.c line 451
Quoted 10 lines
drivers/hwmon/hs300x.c new file +10
-0+ { "hs3004", hs3004 }, + { }, +}; + +MODULE_DEVICE_TABLE(i2c, hs300x_ids); + +static struct i2c_driver hs300x_i2c_driver = { + .driver = { + .name = "hs300x", + .of_match_table = of_match_ptr(hs300x_of_ids),
Drop of_match_ptr and all ifdefs for OF.
Best regards,
Krzysztof
Guenter Roeck
maintainerDocumentation/hwmon/hs300x.rst
Quoted 23 lines · Andre Werner
Add base support for Renesas HS300x temperature
and humidity sensors.The sensors has a fix I2C address
0x44. The resolution is fixed to 14bit (ref. Missing feature).Missing feature:
- Accessing non-volatile memory: Custom board has no possibility to control voltage supply of sensor. Thus, we cannot send the necessary control commands within the first 10ms after power-on.Signed-off-by Andre Werner <[email protected]>--- Documentation/hwmon/hs300x.rst | 61 +++++ drivers/hwmon/Kconfig | 10 + drivers/hwmon/Makefile | 1 + drivers/hwmon/hs300x.c | 461 +++++++++++++++++++++++++++++++++ 4 files changed, 533 insertions(+) create mode 100644 Documentation/hwmon/hs300x.rst create mode 100644 drivers/hwmon/hs300x.cDocumentation/hwmon/hs300x.rst +0
-0
Drop "x" from file names and use the first supported device instead. The driver does not support HS300{0,5...9}, and claiming that it does can only create confusion.
Quoted 24 lines
new file mode 100644
index 000000000000..2be05d0f00abDocumentation/hwmon/hs300x.rst new file +19
-0@@ -0,0 +1,61 @@ +.. SPDX-License-Identifier: GPL-2.0-or-later + +Kernel driver HS300x +=================== + +Supported chips: + + * Renesas HS3001, HS3002, HS3003, HS3004 + + Prefix: 'hs300x' + + Addresses scanned: - + + Datasheet: https://www.renesas.com/us/en/document/dst/hs300x-datasheet?r=417401 + +Author: + + - Andre Werner <[email protected]> +
Documentation/hwmon/hs300x.rst line 29
Quoted 10 lines
Documentation/hwmon/hs300x.rst new file +10
-0+Description +----------- + +This driver implements support for the Renesas HS300x chips, a humidity +and temperature family. Temperature is measured in degrees celsius, relative +humidity is expressed as a percentage. In the sysfs interface, all values are +scaled by 1000, i.e. the value for 31.5 degrees celsius is 31500. + +The device communicates with the I2C protocol. Sensors can have the I2C +address 0x44 by default.
Drop "can".
Documentation/hwmon/hs300x.rst line 33
Quoted 4 lines
Documentation/hwmon/hs300x.rst new file +4
-0+ +The driver does not support the sensor's configuration possibilities. + +The driver is able to be read out using lmsensors.
This sentence has no value since that is the case for all hardware monitoring drivers.
Documentation/hwmon/hs300x.rst line 45
Quoted 12 lines
Documentation/hwmon/hs300x.rst new file +12
-0+ +sysfs-Interface +--------------- + +=============================================================================== +temp1_input: temperature input +humidity1_input: humidity input +temp1_max: temperature max value +humidity1_max: humidity max value +temp1_min: temperature min value +humidity1_min: humidity min value +measuretime: Measurement delay in usec
Use standard attribute (update_interval).
Or, rather, drop it since setting it is not supported by the driver.
Quoted 6 lines
Documentation/hwmon/hs300x.rst new file +6
-0+=============================================================================== + +Device Tree +----------- + +Required node properties:
Documentation/hwmon/hs300x.rst line 61
Quoted 10 lines
Documentation/hwmon/hs300x.rst new file +10
-0+ + - compatible: must be set to "hs3001", "hs3002", "hs3003", "hs3004" + - reg: I2C address of the device (0x44) + +Example: + + humidity: hs3002@44 { + compatible = "hs3002"; + reg = <0x44>; + };
This information does not belong into this file.
Quoted 39 lines
drivers/hwmon/Kconfig +10
-0@@ -734,6 +734,16 @@ config SENSORS_HIH6130 This driver can also be built as a module. If so, the module will be called hih6130. +config SENSORS_HS300x + tristate "Renesas HS300x humidity and temperature sensors" + depends on I2C + help + If you say yes here you get support for the Renesas HS300x + humidity and temperature sensors. + + This driver can also be built as a module. If so, the module + will be called hs300x. + config SENSORS_IBMAEM tristate "IBM Active Energy Manager temperature/power sensors and control" select IPMI_SIdrivers/hwmon/Makefile +1
-0@@ -86,6 +86,7 @@ obj-$(CONFIG_SENSORS_GSC) += gsc-hwmon.o obj-$(CONFIG_SENSORS_GPIO_FAN) += gpio-fan.o obj-$(CONFIG_SENSORS_GXP_FAN_CTRL) += gxp-fan-ctrl.o obj-$(CONFIG_SENSORS_HIH6130) += hih6130.o +obj-$(CONFIG_SENSORS_HS300x) += hs300x.o obj-$(CONFIG_SENSORS_ULTRA45) += ultra45_env.o obj-$(CONFIG_SENSORS_I5500) += i5500_temp.o obj-$(CONFIG_SENSORS_I5K_AMB) += i5k_amb.odrivers/hwmon/hs300x.c new file +0
-0
drivers/hwmon/hs300x.c line 7
Quoted 7 lines
drivers/hwmon/hs300x.c new file +7
-0@@ -0,0 +1,461 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* This is a non-complete driver implementation for the +* HS300x humidity and temperature sensors. It does not include +* the configuration possibilities, because the hardware platform the IC is +* used does not control the power source for the IC. Thus, it cannot being +* set to 'programming mode' during power-up. +*
Not sure what that means, but it irrelevant for the driver. Just describe what it does.
Quoted 6 lines
drivers/hwmon/hs300x.c new file +6
-0+* +* Copyright (C) 2022 SYS TEC electronic AG +* Author: Andre Werner <[email protected]> +*/ + +#include <linux/types.h>
drivers/hwmon/hs300x.c line 23
Quoted 10 lines
drivers/hwmon/hs300x.c new file +10
-0+#include <linux/delay.h> +#include <linux/err.h> +#include <linux/hwmon.h> +#include <linux/hwmon-sysfs.h> +#include <linux/i2c.h> +#include <linux/init.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/of_device.h>
Alphabetic include file order, please.
drivers/hwmon/hs300x.c line 27
Quoted 4 lines
drivers/hwmon/hs300x.c new file +4
-0+ +/* Measurement times */ +#define HS300X_WAKEUP_TIME 100/* us */ +#define HS300X_UNUSED 0/* us */
I can kind of understand the other unused defines below, but this one doesn't make sense or add value. Please drop.
drivers/hwmon/hs300x.c line 31
Quoted 4 lines
drivers/hwmon/hs300x.c new file +4
-0+#define HS300X_8BIT_RESOLUTION 550/* us */ +#define HS300X_10BIT_RESOLUTION 1310/* us */ +#define HS300X_12BIT_RESOLUTION 4500/* us */ +#define HS300X_14BIT_RESOLUTION 16900/* us */
#define<space>NAME<tab>VALUE throughout, and align VALUE
drivers/hwmon/hs300x.c line 33
Quoted 2 lines
drivers/hwmon/hs300x.c new file +2
-0+ +#define HS300X_CMD_OK 0
Drop this define. Use 0 directly where needed. hs300x_measure_command() can return a positive value if needed.
drivers/hwmon/hs300x.c line 38
Quoted 5 lines
drivers/hwmon/hs300x.c new file +5
-0+#define HS300X_RESPONSE_LENGTH 4 + +#define HS300X_FIXPOINT_ARITH 1000 +#define HS300X_MIN_TEMPERATURE (-40 * HS300X_FIXPOINT_ARITH)/* 1000 degree */ +#define HS300X_MAX_TEMPERATURE (125 * HS300X_FIXPOINT_ARITH)/* 1000 degree */
1000 degree ? What is this supposed to mean ?
drivers/hwmon/hs300x.c line 40
Quoted 2 lines
drivers/hwmon/hs300x.c new file +2
-0+#define HS300X_MIN_HUMIDITY (0 * HS300X_FIXPOINT_ARITH)/* 1000 % */ +#define HS300X_MAX_HUMIDITY (100 * HS300X_FIXPOINT_ARITH)/* 1000 % */
What is 1000% ?
drivers/hwmon/hs300x.c line 45
Quoted 5 lines
drivers/hwmon/hs300x.c new file +5
-0+ +#define HS300X_MASK_HUMIDITY_0X3FFF (0x3FFF) +#define HS300X_MASK_TEMPERATURE_0XFFFC (0xFFFC) +#define HS300X_MASK_STATUS_0XC0 (0xC0) +#define HS300X_STATUS_SHIFT (6)
Unnecessary ( ) around constants
Quoted 6 lines
drivers/hwmon/hs300x.c new file +6
-0+ +/* Definitions for Status Bits of A/D Data */ +#define HS300X_DATA_VALID (0x00)/* Valid Data */ +#define HS300X_DATA_STALE (0x01)/* Stale Data */ + +#define LIMIT_MAX 0
drivers/hwmon/hs300x.c line 61
Quoted 10 lines
drivers/hwmon/hs300x.c new file +10
-0+#define LIMIT_MIN 1 + +enum hs300x_chips { + hs3001, + hs3002, + hs3003, + hs3004, +}; + +struct hs300x_accurancy {
accurancy
drivers/hwmon/hs300x.c line 66
Quoted 7 lines
drivers/hwmon/hs300x.c new file +5
-0+u32 hum_acc;/* accurancy of humidity in *1000 % */ +u32 temp_acc;/* accurancy of temperature in *1000 % */ +}; + +const struct hs300x_accurancy hs300x_accurancys[] = {
accuracies
drivers/hwmon/hs300x.c line 71
Quoted 5 lines
drivers/hwmon/hs300x.c new file +5
-0+ { 1500, 200 }, + { 1800, 200 }, + { 2500, 250 }, + { 3500, 300 }, +};
The above information is not used anywhere. Please drop.
drivers/hwmon/hs300x.c line 76
Quoted 5 lines
drivers/hwmon/hs300x.c new file +5
-0+ +struct hs300x_data { +struct i2c_client *client; +struct mutex i2c_lock;/* lock for sending i2c commands */ +struct mutex data_lock;/* lock for updating driver data */
Those locks are not really necessary.
drivers/hwmon/hs300x.c line 77
Quoted 1 line
drivers/hwmon/hs300x.c new file +1
-0+u32 wait_time;/* in us */
That can be a constant.
drivers/hwmon/hs300x.c line 90
Quoted 13 lines
drivers/hwmon/hs300x.c new file +13
-0+int temperature;/* in *1000 degree */ +u32 humidity;/* in *1000 % */ +}; + +static int hs300x_measure_command (struct i2c_client *client, +struct hs300x_data *data) +{ +int ret =0 ; +unsigned char buf[1 ] = {0x00 }; + +if (!data || !client) +return -EINVAL ; +
Pointless check.
drivers/hwmon/hs300x.c line 92
Quoted 2 lines
drivers/hwmon/hs300x.c new file +2
-0+mutex_lock (&data->i2c_lock); + ret =i2c_master_send (client, (const char *)buf,0 );
Pointless typecast
drivers/hwmon/hs300x.c
Quoted 1 line
drivers/hwmon/hs300x.c new file +1
-0+mutex_unlock (&data->i2c_lock);
That lock seems pointless. Please explain its value.
drivers/hwmon/hs300x.c
Quoted 2 lines
drivers/hwmon/hs300x.c new file +2
-0+ +if (0 > ret)
Please refrain from Yoda programming.
Quoted 7 lines
drivers/hwmon/hs300x.c new file +6
-0+dev_dbg (&client->dev, +"Error starting measurement. Errno: %d.\n" , ret); + else { + ret =HS300X_CMD_OK ; + } +
drivers/hwmon/hs300x.c line 111
Quoted 10 lines
drivers/hwmon/hs300x.c new file +10
-0+return ret; +} + +static int hs300x_extract_temperature (u16 raw) +{ +/* fixpoint arithmetic 1 digit */ +int temp = ((raw &HS300X_MASK_TEMPERATURE_0XFFFC ) >>2 ) * +HS300X_FIXPOINT_ARITH ; + + temp /= ((1 <<14 ) -1 );
Unnecessary outer ( ).
Quoted 1 line
+ > + return (temp * 165) - (40 *
HS300X_FIXPOINT_ARITH);
Unnecessary ( )
drivers/hwmon/hs300x.c line 122
Quoted 9 lines
drivers/hwmon/hs300x.c new file +9
-0+} + +static u32 hs300x_extract_humidity (u16 raw) +{ +int hum = (raw &HS300X_MASK_HUMIDITY_0X3FFF ) *HS300X_FIXPOINT_ARITH ; + + hum /= ((1 <<14 ) -1 ); + +return hum *100 ;
Not that it matters much, but this calculation unnecessarily reduces resolution to 1%.
drivers/hwmon/hs300x.c line 133
Quoted 11 lines
drivers/hwmon/hs300x.c new file +11
-0+} + +static int hs300x_data_fetch_command (struct i2c_client *client, +struct hs300x_data *data) +{ +int ret =HS300X_CMD_OK ; +u8 buf[HS300X_RESPONSE_LENGTH ]; +u8 hs300x_status; + +if (!client || !data) +return -EINVAL ;
Pointless.
drivers/hwmon/hs300x.c line 143
Quoted 10 lines
drivers/hwmon/hs300x.c new file +10
-0+ +mutex_lock (&data->i2c_lock); + ret =i2c_master_recv (client, buf,HS300X_RESPONSE_LENGTH ); +mutex_unlock (&data->i2c_lock); + +if (ret !=HS300X_RESPONSE_LENGTH ) { + ret = ret <0 ? ret : -EIO ; +dev_dbg (&client->dev, +"Error in i2c communication. Error code: %d.\n" , ret); + goto out;
Please no goto to return statements.
Quoted 10 lines
drivers/hwmon/hs300x.c new file +10
-0+ } + + hs300x_status = (buf[0 ] &HS300X_MASK_STATUS_0XC0 ) >> +HS300X_STATUS_SHIFT ; +if (hs300x_status ==HS300X_DATA_STALE ) { +dev_dbg (&client->dev,"Sensor busy.\n" ); + ret = -EBUSY ; + goto out; + }else if (hs300x_status !=HS300X_DATA_VALID ) { +dev_dbg (&client->dev,"Data invalid.\n" );
drivers/hwmon/hs300x.c line 163
Quoted 10 lines
drivers/hwmon/hs300x.c new file +10
-0+ ret = -EIO ; + goto out; + } + +mutex_lock (&data->data_lock); + data->humidity = +hs300x_extract_humidity (be16_to_cpup ((__be16 *) &buf[0 ])); + data->temperature = +hs300x_extract_temperature (be16_to_cpup ((__be16 *) &buf[2 ])); +mutex_unlock (&data->data_lock);
This lock is pointless since the caller may use the return value from a later measurement which happened after the lock was released. Also, since the caller does not acquire the lock prior to reading the value, data->humidity and data->temperature could still be inconsistent.
Overall, storing humidity and temperature in data does not ad any value. Just pass two pointers to store the returned values.
drivers/hwmon/hs300x.c
Quoted 2 lines
drivers/hwmon/hs300x.c new file +2
-0+ + ret =HS300X_CMD_OK ;
Just return 0; is sufficient.
Quoted 9 lines
drivers/hwmon/hs300x.c new file +9
-0+ +out: +return ret; +} + +/* sysfs attributes */ +static ssize_t measuretime_show (struct device *dev, +struct device_attribute *attr,char *buf) +{
drivers/hwmon/hs300x.c line 184
Quoted 10 lines
drivers/hwmon/hs300x.c new file +10
-0+struct hs300x_data *data =dev_get_drvdata (dev); +struct i2c_client *client; + +if (IS_ERR (data)) +return PTR_ERR (data); + + client = data->client; + +if (!client) +return -ENODEV ;
All those checks are pointless.
Quoted 10 lines
drivers/hwmon/hs300x.c new file +10
-0+ +return sprintf (buf,"%d\n" , data->wait_time); +} + +static ssize_t temp1_input_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct hs300x_data *data =dev_get_drvdata (dev); +struct i2c_client *client; +int ret;
drivers/hwmon/hs300x.c line 204
Quoted 10 lines
drivers/hwmon/hs300x.c new file +10
-0+ +if (IS_ERR (data)) +return PTR_ERR (data); + + client = data->client; + +if (!client) { +dev_dbg (dev,"No valid I2C client available.\n" ); +return -ENODEV ; + }
Really ? So how comes the driver is instantiated on one ?
drivers/hwmon/hs300x.c line 208
Quoted 4 lines
drivers/hwmon/hs300x.c new file +4
-0+ + ret =hs300x_measure_command (client, data); +if (ret !=HS300X_CMD_OK ) +return ret;
if (ret < 0)
drivers/hwmon/hs300x.c line 217
Quoted 9 lines
drivers/hwmon/hs300x.c new file +9
-0+ +/* Sensor needs some time to process measurement depending on +* resolution +*/ +fsleep (data->wait_time); + + ret =hs300x_data_fetch_command (client, data); +if (ret !=HS300X_CMD_OK ) +return ret;
ret < 0
Quoted 22 lines
drivers/hwmon/hs300x.c new file +22
-0+ +return sprintf (buf,"%d\n" , data->temperature); +} + +static ssize_t humidity1_input_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct hs300x_data *data =dev_get_drvdata (dev); +struct i2c_client *client; +int ret; + +if (IS_ERR (data)) +return PTR_ERR (data); + + client = data->client; + +if (!client) { +dev_dbg (dev,"No valid I2C client available.\n" ); +return -ENODEV ; + } + + ret =hs300x_measure_command (client, data);
drivers/hwmon/hs300x.c line 249
Quoted 10 lines
drivers/hwmon/hs300x.c new file +10
-0+if (ret !=HS300X_CMD_OK ) +return ret; + +/* Sensor needs some time to process measurement depending on +* resolution +*/ +fsleep (data->wait_time); + + ret =hs300x_data_fetch_command (client, data); +if (ret !=HS300X_CMD_OK )
ret < 0 (everywhere)
Quoted 7 lines
drivers/hwmon/hs300x.c new file +7
-0+return ret; + +return sprintf (buf,"%u\n" , data->humidity); +} + +static ssize_t temp1_limit_show (struct device *dev, +struct device_attribute *attr,char *buf)
drivers/hwmon/hs300x.c line 266
Quoted 10 lines
drivers/hwmon/hs300x.c new file +10
-0+{ +int temperature_limit; +u8 index; + + index =to_sensor_dev_attr (attr)->index; +if (LIMIT_MIN == index) + temperature_limit =HS300X_MIN_TEMPERATURE ; +else + temperature_limit =HS300X_MAX_TEMPERATURE ; +
Drop those attributes. They are pointless if not supported by hardware.
Quoted 5 lines
drivers/hwmon/hs300x.c new file +5
-0+return scnprintf (buf,PAGE_SIZE ,"%d\n" , temperature_limit); +} + +static ssize_t humidity1_limit_show (struct device *dev, +struct device_attribute *attr,char *buf)
drivers/hwmon/hs300x.c line 281
Quoted 10 lines
drivers/hwmon/hs300x.c new file +10
-0+{ +u32 humidity_limit; +u8 index; + + index =to_sensor_dev_attr (attr)->index; +if (LIMIT_MIN == index) + humidity_limit =HS300X_MIN_HUMIDITY ; +else + humidity_limit =HS300X_MAX_HUMIDITY ; +
Same as above. If the hardware does not support setting and reading limits, don't show them.
Quoted 57 lines
drivers/hwmon/hs300x.c new file +57
-0+return scnprintf (buf,PAGE_SIZE ,"%u\n" , humidity_limit); +} + +static SENSOR_DEVICE_ATTR_RO(temp1_input, temp1_input, 0); +static SENSOR_DEVICE_ATTR_RO(humidity1_input, humidity1_input, 0); +static SENSOR_DEVICE_ATTR_RO(measuretime, measuretime, 0); +static SENSOR_DEVICE_ATTR_RO(temp1_max, temp1_limit, LIMIT_MAX); +static SENSOR_DEVICE_ATTR_RO(humidity1_max, humidity1_limit, LIMIT_MAX); +static SENSOR_DEVICE_ATTR_RO(temp1_min, temp1_limit, LIMIT_MIN); +static SENSOR_DEVICE_ATTR_RO(humidity1_min, humidity1_limit, LIMIT_MIN); + +static struct attribute *hs3001_attrs[] = { + &sensor_dev_attr_temp1_input.dev_attr.attr, + &sensor_dev_attr_humidity1_input.dev_attr.attr, + &sensor_dev_attr_measuretime.dev_attr.attr, + &sensor_dev_attr_temp1_max.dev_attr.attr, + &sensor_dev_attr_humidity1_max.dev_attr.attr, + &sensor_dev_attr_temp1_min.dev_attr.attr, + &sensor_dev_attr_humidity1_min.dev_attr.attr, +NULL +}; + +static struct attribute *hs3002_attrs[] = { + &sensor_dev_attr_temp1_input.dev_attr.attr, + &sensor_dev_attr_humidity1_input.dev_attr.attr, + &sensor_dev_attr_measuretime.dev_attr.attr, + &sensor_dev_attr_temp1_max.dev_attr.attr, + &sensor_dev_attr_humidity1_max.dev_attr.attr, + &sensor_dev_attr_temp1_min.dev_attr.attr, + &sensor_dev_attr_humidity1_min.dev_attr.attr, +NULL +}; + +static struct attribute *hs3003_attrs[] = { + &sensor_dev_attr_temp1_input.dev_attr.attr, + &sensor_dev_attr_humidity1_input.dev_attr.attr, + &sensor_dev_attr_measuretime.dev_attr.attr, + &sensor_dev_attr_temp1_max.dev_attr.attr, + &sensor_dev_attr_humidity1_max.dev_attr.attr, + &sensor_dev_attr_temp1_min.dev_attr.attr, + &sensor_dev_attr_humidity1_min.dev_attr.attr, +NULL +}; + +static struct attribute *hs3004_attrs[] = { + &sensor_dev_attr_temp1_input.dev_attr.attr, + &sensor_dev_attr_humidity1_input.dev_attr.attr, + &sensor_dev_attr_measuretime.dev_attr.attr, + &sensor_dev_attr_temp1_max.dev_attr.attr, + &sensor_dev_attr_humidity1_max.dev_attr.attr, + &sensor_dev_attr_temp1_min.dev_attr.attr, + &sensor_dev_attr_humidity1_min.dev_attr.attr, +NULL +}; + +ATTRIBUTE_GROUPS (hs3001); +ATTRIBUTE_GROUPS (hs3002);
drivers/hwmon/hs300x.c line 348
Quoted 10 lines
drivers/hwmon/hs300x.c new file +10
-0+ATTRIBUTE_GROUPS (hs3003); +ATTRIBUTE_GROUPS (hs3004); + +static const struct i2c_device_id hs300x_ids[]; +#ifdef CONFIG_OF +static const struct of_device_id hs300x_of_ids[] = { + {.compatible ="hs3001" }, + {.compatible ="hs3002" }, + {.compatible ="hs3003" }, + {.compatible = "hs3004" },
This should be something like "renesas,hs3001" etc.
Quoted 12 lines
drivers/hwmon/hs300x.c new file +12
-0+ { }, +}; + +MODULE_DEVICE_TABLE (of, hs300x_of_ids); +#endif + +static int hs300x_probe (struct i2c_client *client) +{ +struct hs300x_data *data; +struct device *hwmon_dev; +struct i2c_adapter *adap = client->adapter; +struct device *dev = &client->dev;
drivers/hwmon/hs300x.c line 370
Quoted 10 lines
drivers/hwmon/hs300x.c new file +10
-0+const struct attribute_group **attribute_groups; +int ret; +#ifdef CONFIG_OF +const struct of_device_id *of_match; + + of_match =of_match_device (hs300x_of_ids, dev); +if (!of_match) { +dev_err (dev,"No match in DT compatibles.\n" ); +return -ENODEV ; + }
This is unnecessary since there is no difference between devices, and the driver won't be instantiated if there is no match.
drivers/hwmon/hs300x.c line 381
Quoted 11 lines
drivers/hwmon/hs300x.c new file +11
-0+ +#endif +if (!i2c_check_functionality (adap,I2C_FUNC_I2C )) +return -ENODEV ; + + data =devm_kzalloc (dev,sizeof (*data),GFP_KERNEL ); +if (!data) +return -ENOMEM ; + + data->client = client; +/* Measurement time = wake-up time + measurement time temperature
Standard multi-line comment, please.
drivers/hwmon/hs300x.c line 382
Quoted 1 line
drivers/hwmon/hs300x.c new file +1
-0+* measurment time humidity This is currently static, because
measurement. "." missing.
drivers/hwmon/hs300x.c
Quoted 2 lines
drivers/hwmon/hs300x.c new file +2
-0+* enabling programming mode is not supported, yet. +*/
Then drop the attribute and add it if/when setting it is suppported.
drivers/hwmon/hs300x.c line 397
Quoted 13 lines
drivers/hwmon/hs300x.c new file +13
-0+ data->wait_time = (HS300X_WAKEUP_TIME +HS300X_14BIT_RESOLUTION + +HS300X_14BIT_RESOLUTION ); +mutex_init (&data->i2c_lock); +mutex_init (&data->data_lock); + +if (i2c_match_id (hs300x_ids, client)->driver_data == hs3001) + attribute_groups = hs3001_groups; +else if (i2c_match_id (hs300x_ids, client)->driver_data == hs3002) + attribute_groups = hs3002_groups; +else if (i2c_match_id (hs300x_ids, client)->driver_data == hs3003) + attribute_groups = hs3003_groups; +else if (i2c_match_id (hs300x_ids, client)->driver_data == hs3004) + attribute_groups = hs3004_groups;
All this should be handled with the is_visible() callback.
Having said this, looking at the attributes again ... they are all the same. Either I am missing something ot that is completely pointless.
Besides, HS3002 and HS3004 were removed from the datasheet. Do those chips even exist ?
drivers/hwmon/hs300x.c line 403
Quoted 6 lines
drivers/hwmon/hs300x.c new file +6
-0+else { +dev_err (dev,"Unknwon device for HS300x driver\n" ); + goto error; + } + +/* Measure humidity and temperature to initialize values */
What for ? That unnecessarily delays booting significantly.
drivers/hwmon/hs300x.c line 407
Quoted 4 lines
drivers/hwmon/hs300x.c new file +4
-0+ ret =hs300x_measure_command (client, data); +if (ret) { + goto error; + }
Please run checkpatch --strict on your patches.
Quoted 4 lines
drivers/hwmon/hs300x.c new file +4
-0+ +/* Sensor needs some time to process measurement depending on +* resolution +*/
drivers/hwmon/hs300x.c line 421
Quoted 10 lines
drivers/hwmon/hs300x.c new file +10
-0+fsleep (data->wait_time); + + ret =hs300x_data_fetch_command (client, data); +if (ret !=HS300X_CMD_OK ) { + goto error; + } + + hwmon_dev = +devm_hwmon_device_register_with_groups (dev, client->name, data, + attribute_groups);
From Documentation/hwmon/hwmon-kernel-api.rst (with emphasis added):
devm_hwmon_device_register_with_info is similar to hwmon_device_register_with_info. However, it is device managed, meaning the hwmon device does not have to be removed explicitly by the removal function.
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv All other hardware monitoring device registration functions are deprecated and must not be used in new drivers. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
drivers/hwmon/hs300x.c line 426
Quoted 5 lines
drivers/hwmon/hs300x.c new file +5
-0+ +if (IS_ERR (hwmon_dev)) { +dev_err (dev,"Unable to register hwmon device %s\n" , + client->name); + goto error;
return PTR_ERR(hwmon_dev);
drivers/hwmon/hs300x.c line 430
Quoted 4 lines
drivers/hwmon/hs300x.c new file +4
-0+ } + +dev_info (dev,"Successfully probe %s: sensor '%s'\n" , +dev_name (hwmon_dev), client->name);
Please no such noise.
drivers/hwmon/hs300x.c line 433
Quoted 3 lines
drivers/hwmon/hs300x.c new file +3
-0+return PTR_ERR_OR_ZERO (hwmon_dev); +error: +devm_kfree (dev, data);
Pointless.
Quoted 8 lines
drivers/hwmon/hs300x.c new file +8
-0+return -ENODEV ; +} + +/* device ID table */ +static const struct i2c_device_id hs300x_ids[] = { + {"hs3001" , hs3001 }, + {"hs3002" , hs3002 }, + {"hs3003" , hs3003 },
drivers/hwmon/hs300x.c line 451
Quoted 10 lines
drivers/hwmon/hs300x.c new file +10
-0+ { "hs3004", hs3004 }, + { }, +}; + +MODULE_DEVICE_TABLE(i2c, hs300x_ids); + +static struct i2c_driver hs300x_i2c_driver = { + .driver = { + .name = "hs300x", + .of_match_table = of_match_ptr(hs300x_of_ids),
Drop
Quoted 13 lines
drivers/hwmon/hs300x.c new file +10
-0+ }, + .probe_new = hs300x_probe, + .id_table = hs300x_ids, +}; + +module_i2c_driver (hs300x_i2c_driver); + +MODULE_AUTHOR ("Andre Werner <[email protected]>" ); +MODULE_DESCRIPTION ("HS300x humidity and temperature sensor base driver" ); +MODULE_LICENSE ("GPL" );Signature · 1 line
2.41.0