diff --git a/Documentation/devicetree/bindings/hwmon/sht3x.yaml b/Documentation/devicetree/bindings/hwmon/sht3x.yaml new file mode 100644 index 000000000000..89da68ba5772 --- /dev/null +++ b/Documentation/devicetree/bindings/hwmon/sht3x.yaml @@ -0,0 +1,39 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/hwmon/sht3x.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: SHT3x hwmon sensor + +maintainers: + - Artemis Tosini + +properties: + compatible: + enum: + - sensirion,sht3x + - sensirion,sts3x + + reg: + maxItems: 1 + + vs-supply: + description: phandle to the regulator supplying Vdd + +requred: + - compatible + - reg + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + sensor@44 { + compatible = "sensirion,sht3x"; + reg = <0x44>; + vs-supply = <&v3v3>; + }; + }; diff --git a/drivers/hwmon/sht3x.c b/drivers/hwmon/sht3x.c index 79657910b79e..ff8684875880 100644 --- a/drivers/hwmon/sht3x.c +++ b/drivers/hwmon/sht3x.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -851,6 +852,20 @@ static const struct i2c_device_id sht3x_ids[] = { MODULE_DEVICE_TABLE(i2c, sht3x_ids); +static const struct of_device_id sht3x_of_match[] = { + { + .compatible = "sensirion,sht3x", + .data = (void *)sht3x + }, + { + .compatible = "sensirion,sts3x", + .data = (void *)sts3x + }, + { }, +}; + +MODULE_DEVICE_TABLE(of, sht3x_of_match); + static int sht3x_probe(struct i2c_client *client) { int ret; @@ -880,7 +895,10 @@ static int sht3x_probe(struct i2c_client *client) data->mode = 0; data->last_update = jiffies - msecs_to_jiffies(3000); data->client = client; - data->chip_id = i2c_match_id(sht3x_ids, client)->driver_data; + if (client->dev.of_node) + data->chip_id = (uintptr_t)of_device_get_match_data(&client->dev); + else + data->chip_id = i2c_match_id(sht3x_ids, client)->driver_data; crc8_populate_msb(sht3x_crc8_table, SHT3X_CRC8_POLYNOMIAL); sht3x_select_command(data); @@ -912,7 +930,10 @@ static int sht3x_probe(struct i2c_client *client) } static struct i2c_driver sht3x_i2c_driver = { - .driver.name = "sht3x", + .driver = { + .name = "sht3x", + .of_match_table = of_match_ptr(sht3x_of_match) + }, .probe = sht3x_probe, .id_table = sht3x_ids, };