From patchwork Wed Jul 26 05:16:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: werneazc X-Patchwork-Id: 13327498 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 60813C001DE for ; Wed, 26 Jul 2023 05:17:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229939AbjGZFRH (ORCPT ); Wed, 26 Jul 2023 01:17:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230221AbjGZFRG (ORCPT ); Wed, 26 Jul 2023 01:17:06 -0400 Received: from mail-io1-xd44.google.com (mail-io1-xd44.google.com [IPv6:2607:f8b0:4864:20::d44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6648C1FF2; Tue, 25 Jul 2023 22:17:05 -0700 (PDT) Received: by mail-io1-xd44.google.com with SMTP id ca18e2360f4ac-785cbc5bfd2so316303039f.2; Tue, 25 Jul 2023 22:17:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690348625; x=1690953425; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PPYKx33gkKK6ihReNB0YWeTCKH/1xjgrNd1OWQ9D+48=; b=F8f18zSUxUJvKX5dCgBjqUC0AmlalXOJQ68FrUH6OTt9AEgk44T9q+3eUr5N2yhvXh tgHFGzcjSS3/t1j1zyKdT2naI0nqFCO2CUtMD0sDDgWJ9jTHBWyp4XH4FHNZkoi8iFz6 PyKd9MwReFq/iPBRbeWYFL8x8Wp0m5PAjr5JRhUvKJHpw0skMVM+LVMlZvgmN0b0BQGI hW5jpFByXxZHkE3lBIca/7XQVyYfdg/pp1yS67tICSW07tYldC6nV8e4jr48rLH+0HbJ 1Buu6lQy9lZOffh1OSLSlz2hjdSEeTfKvarZ2nOuZJU1Afnvt0ekFZ2uu8O2d6SHkpjN DnMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690348625; x=1690953425; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PPYKx33gkKK6ihReNB0YWeTCKH/1xjgrNd1OWQ9D+48=; b=EZWtWKxmju/V9J0Yl0AsN4nt4Le5ijZZJd3D+K9U0mTJdhw+UsGPxweN7YURp+4GU9 kEIAbsuEohZ0gQoVyxtlzMjjS9IxKqOxnPwUgwMzy1K0ionzAdAtK/nXzYxReKLgHIhK JIsVhjbxPLZZjWghAIRFhT7PM/kiKZ4rEkRYcYSVix/Zj58TWtKEe+kC99ysFZT9uXMR QXdVdzRhYUZ1OjHh+bZaEsIQE0QohOoSNK0zGqgT1INz+BuPc7TP9r5JrzEd8QCW/Z0R IVwWgK0PiZLnRn41VPtnsKEr7fwPDMualw9J7r+BB0jXgPoN19LqltfdU+xA19AssrA5 EKrQ== X-Gm-Message-State: ABy/qLY8l9ZhNJIjzVm9XfmGVRP4k0ljgtDINdpCvQsEuYaSIWH4PKdS AazWH+y7Fq1LnMQTRiE6S4AnVgitBRQy+Q== X-Google-Smtp-Source: APBJJlEBHJpiCadpe6EljDY03VDLIRzVXuOI8kJ+Nj02QPZWynQi9qEIQHmZXaklTyGVl3jFRaBTMg== X-Received: by 2002:a5e:a801:0:b0:785:d28f:1526 with SMTP id c1-20020a5ea801000000b00785d28f1526mr1010201ioa.3.1690348624786; Tue, 25 Jul 2023 22:17:04 -0700 (PDT) Received: from ws-565760.systec.local ([212.185.67.148]) by smtp.gmail.com with ESMTPSA id q13-20020a5ea60d000000b007836c7e8dccsm4493949ioi.17.2023.07.25.22.17.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jul 2023 22:17:04 -0700 (PDT) From: werneazc@gmail.com X-Google-Original-From: andre.werner@systec-electronic.com To: jdelvare@suse.com, linux@roeck-us.net, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, robh+dt@kernel.org Cc: linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Andre Werner , Krzysztof Kozlowski Subject: [PATCH v4 1/2] dt-bindings: hwmon: Add description for new hwmon sensor hs3001 Date: Wed, 26 Jul 2023 07:16:34 +0200 Message-ID: <20230726051635.9778-1-andre.werner@systec-electronic.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <0f32155b-bcc1-4d9e-bba9-058d63194abc@roeck-us.net> References: <0f32155b-bcc1-4d9e-bba9-058d63194abc@roeck-us.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org From: Andre Werner Add binding for Renesas HS3001 Temperature and Relative Humidity Sensor. Signed-off-by: Andre Werner Acked-by: Krzysztof Kozlowski --- v1: Using separate dt-binding hs300x.yaml v2: Reviewer recommends documentation of driver dt-binding in trivial-devices.yaml because the driver has no special properties to describe. v3: Simplify description of sensors compatible v4: Change patch description Signed-off-by: Andre Werner --- Documentation/devicetree/bindings/trivial-devices.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/devicetree/bindings/trivial-devices.yaml b/Documentation/devicetree/bindings/trivial-devices.yaml index ba2bfb547909..96eb59e56eb7 100644 --- a/Documentation/devicetree/bindings/trivial-devices.yaml +++ b/Documentation/devicetree/bindings/trivial-devices.yaml @@ -315,6 +315,8 @@ properties: - plx,pex8648 # Pulsedlight LIDAR range-finding sensor - pulsedlight,lidar-lite-v2 + # Renesas HS3001 Temperature and Relative Humidity Sensors + - renesas,hs3001 # Renesas ISL29501 time-of-flight sensor - renesas,isl29501 # Rohm DH2228FV From patchwork Tue Jul 25 04:22:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: werneazc X-Patchwork-Id: 13325871 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 66157C0015E for ; Tue, 25 Jul 2023 04:26:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231846AbjGYE0z (ORCPT ); Tue, 25 Jul 2023 00:26:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229612AbjGYEZD (ORCPT ); Tue, 25 Jul 2023 00:25:03 -0400 Received: from mail-io1-xd42.google.com (mail-io1-xd42.google.com [IPv6:2607:f8b0:4864:20::d42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3484A1BD3; Mon, 24 Jul 2023 21:22:24 -0700 (PDT) Received: by mail-io1-xd42.google.com with SMTP id ca18e2360f4ac-78358268d1bso223292439f.3; Mon, 24 Jul 2023 21:22:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690258944; x=1690863744; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=K6FSHlMG4hmeV4KqxZQH6dTrFkGsb4u8j1c5B5f5uhA=; b=Re/oUyGbjhsf56iJUknS/eL070udIzPsMClY/pYpK9guwE3RBR1O7kDKiNaHa99ulV gZb0AimVQg+dY2YmB/ejQDhUpHlYrtWofbRwto9CgSQKB4mQO+uR9/8sKcOW0rt/2Q92 4duETKla/BPruCHRJn5BR5AVzidsiYf0mxMfo9xgEHQTix12h2grK4aBLrSI/Kag3ZMA mULZRDFICszhc8BFquQB8iAOGbWEvkP/pqaRGjfCxX2bpQ0punkj+1XXAHRwucVz02Ow TSuTHbTuhQOhcwC24qmvKHPWtxfAMrih7ffHpQytQhDgEks+k5QE6k3M06bs6tL+zfnq kt0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690258944; x=1690863744; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=K6FSHlMG4hmeV4KqxZQH6dTrFkGsb4u8j1c5B5f5uhA=; b=dVL4TN6fNdAJy/f54edm8qg7wKQvhMLR1/ScZcGouIvD0Jlv5JEDRquSUnBvkNXezn 5U7MeAjTEGCL9aZu7it0dShIfeDbWIU7zvfRL0tzqzW8H0ze5re3tBZqgK8oYN2dIv68 erOP6avxCgZ+t2dqyJrAkcC2dCJ6SmycaxNWk4GUpl4sKk4Rc+F6yRAY06j8QVt6Lo0/ 57vJ1IgwBriyZU8G/ubO+CPzwkt1JAzjPMTOv1yrIzQimZb3tIM1/gQwszJyKHXIOWV0 OZBg7H0q/hsFvMh2Mdznrvp/6R19gaf6Thv7dZ3wnSPm4iccrU7g8F1H+hUGjDxgStIC D/7Q== X-Gm-Message-State: ABy/qLZ47BtF4DAelse7pdg+pBNqlFlnYcBjFICVPYyu05nd5qqDXSrO XcGMP5Xi+66ShvJqgOM1Ui8= X-Google-Smtp-Source: APBJJlHVZ5iRInAPuhN/ZbWyYj+EAtKdd7g2G70JfNVfpUK1ufr9Tro3Aq8a7DyJH0wSAMnnLFUlYA== X-Received: by 2002:a6b:7618:0:b0:783:62d0:88c with SMTP id g24-20020a6b7618000000b0078362d0088cmr1617776iom.19.1690258944065; Mon, 24 Jul 2023 21:22:24 -0700 (PDT) Received: from ws-565760.systec.local ([212.185.67.148]) by smtp.gmail.com with ESMTPSA id h21-20020a056638063500b0042bb296863asm3299535jar.56.2023.07.24.21.22.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jul 2023 21:22:23 -0700 (PDT) From: werneazc@gmail.com X-Google-Original-From: andre.werner@systec-electronic.com To: jdelvare@suse.com, linux@roeck-us.net, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, robh+dt@kernel.org Cc: linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Andre Werner Subject: [PATCH v6 2/2] hwmon: (hs3001) Add driver for Renesas HS3001 Date: Tue, 25 Jul 2023 06:22:07 +0200 Message-ID: <20230725042207.22310-2-andre.werner@systec-electronic.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <0f32155b-bcc1-4d9e-bba9-058d63194abc@roeck-us.net> References: <0f32155b-bcc1-4d9e-bba9-058d63194abc@roeck-us.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org From: Andre Werner Add base support for Renesas HS3001 temperature and humidity sensors and its compatibles HS3002, HS3003 and HS3004. The sensor 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 Reviewed-by: Guenter Roeck --- Changelog: v1: Initial version v2: Extensive refactoring following recommendations of reviewers: - Delete unused defines and device properties. These are added in the initial version because the device supports a programming mode, but I was not able to implement it, because the custom board was not able to control the power supply of the device and so I cannot enter the programming mode of the device. - Correct misunderstanding comments for defines. - Delete mutexes for data and I2C bus accesses. - Replace attributes with recommended chip-info structure. In the initial version I followed the sth3x.c implementation that uses files and attributes in sysfs. The show functions are replaced by is_visible and read callbacks from the HWMON ABI. I also delete pointless function argument checks. - Correct Yoda programming. - Refactor probe function and delete sleep and measurement of humidity and temperature in probe function. I kept an initial I2C communication to ensure that the device is accessible during probe. - Reduce the number of attributes to humidity and temperature input. v3: Delete chip data because it is unused. v4: Refactor driver as follows: - Delete further unused defines - Replace masks and operations with GENMASK and FIELD_GET macros - Add mutex to protect chip wakeup and data transfer operations on bus - Reformat driver as requested - Make hs3001_is_visible and hs3001_read function static v5: Drop i2c access in probe; Correct precession lost in conversion function for physical values v6: Correct mutex unlock in case of early function return. Correct typo. Delete unnecessary comments. --- Documentation/hwmon/hs3001.rst | 37 +++++ MAINTAINERS | 6 + drivers/hwmon/Kconfig | 10 ++ drivers/hwmon/Makefile | 1 + drivers/hwmon/hs3001.c | 243 +++++++++++++++++++++++++++++++++ 5 files changed, 297 insertions(+) create mode 100644 Documentation/hwmon/hs3001.rst create mode 100644 drivers/hwmon/hs3001.c diff --git a/Documentation/hwmon/hs3001.rst b/Documentation/hwmon/hs3001.rst new file mode 100644 index 000000000000..703fb9c45313 --- /dev/null +++ b/Documentation/hwmon/hs3001.rst @@ -0,0 +1,37 @@ +.. SPDX-License-Identifier: GPL-2.0-or-later + +Kernel driver HS3001 +=================== + +Supported chips: + + * Renesas HS3001, HS3002, HS3003, HS3004 + + Prefix: 'hs3001' + + Addresses scanned: - + + Datasheet: https://www.renesas.com/us/en/document/dst/hs300x-datasheet?r=417401 + +Author: + + - Andre Werner + +Description +----------- + +This driver implements support for the Renesas HS3001 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 have the I2C +address 0x44 by default. + +sysfs-Interface +--------------- + +=============================================================================== +temp1_input: temperature input +humidity1_input: humidity input +=============================================================================== diff --git a/MAINTAINERS b/MAINTAINERS index d516295978a4..46c97769eb05 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -9496,6 +9496,12 @@ S: Maintained W: http://artax.karlin.mff.cuni.cz/~mikulas/vyplody/hpfs/index-e.cgi F: fs/hpfs/ +HS3001 Hardware Temperature and Humidity Sensor +M: Andre Werner +L: linux-hwmon@vger.kernel.org +S: Maintained +F: drivers/hwmon/hs3001.c + HSI SUBSYSTEM M: Sebastian Reichel S: Maintained diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index 307477b8a371..ca6be5a23271 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig @@ -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_HS3001 + tristate "Renesas HS3001 humidity and temperature sensors" + depends on I2C + help + If you say yes here you get support for the Renesas HS3001, + to HS3004 humidity and temperature sensors. + + This driver can also be built as a module. If so, the module + will be called hs3001. + config SENSORS_IBMAEM tristate "IBM Active Energy Manager temperature/power sensors and control" select IPMI_SI diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile index 3f4b0fda0998..cdae4e1fc919 100644 --- a/drivers/hwmon/Makefile +++ b/drivers/hwmon/Makefile @@ -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_HS3001) += hs3001.o obj-$(CONFIG_SENSORS_ULTRA45) += ultra45_env.o obj-$(CONFIG_SENSORS_I5500) += i5500_temp.o obj-$(CONFIG_SENSORS_I5K_AMB) += i5k_amb.o diff --git a/drivers/hwmon/hs3001.c b/drivers/hwmon/hs3001.c new file mode 100644 index 000000000000..17c3455922eb --- /dev/null +++ b/drivers/hwmon/hs3001.c @@ -0,0 +1,243 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * This is a non-complete driver implementation for the + * HS3001 humidity and temperature sensor and compatibles. It does not include + * the configuration possibilities, where it needs to be set to 'programming mode' + * during power-up. + * + * + * Copyright (C) 2023 SYS TEC electronic AG + * Author: Andre Werner + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* Measurement times */ +#define HS3001_WAKEUP_TIME 100 /* us */ +#define HS3001_8BIT_RESOLUTION 550 /* us */ +#define HS3001_10BIT_RESOLUTION 1310 /* us */ +#define HS3001_12BIT_RESOLUTION 4500 /* us */ +#define HS3001_14BIT_RESOLUTION 16900 /* us */ + +#define HS3001_RESPONSE_LENGTH 4 + +#define HS3001_FIXPOINT_ARITH 1000U + +#define HS3001_MASK_HUMIDITY_0X3FFF GENMASK(13, 0) +#define HS3001_MASK_STATUS_0XC0 GENMASK(7, 6) + +/* Definitions for Status Bits of A/D Data */ +#define HS3001_DATA_VALID 0x00 /* Valid Data */ +#define HS3001_DATA_STALE 0x01 /* Stale Data */ + +struct hs3001_data { + struct i2c_client *client; + struct mutex i2c_lock; /* lock for sending i2c commands */ + u32 wait_time; /* in us */ + int temperature; /* in milli degree */ + u32 humidity; /* in milli % */ +}; + +static int hs3001_extract_temperature(u16 raw) +{ + /* fixpoint arithmetic 1 digit */ + u32 temp = (raw >> 2) * HS3001_FIXPOINT_ARITH * 165; + + temp /= (1 << 14) - 1; + + return (int)temp - 40 * HS3001_FIXPOINT_ARITH; +} + +static u32 hs3001_extract_humidity(u16 raw) +{ + u32 hum = (raw & HS3001_MASK_HUMIDITY_0X3FFF) * HS3001_FIXPOINT_ARITH * 100; + + return hum /= (1 << 14) - 1; +} + +static int hs3001_data_fetch_command(struct i2c_client *client, + struct hs3001_data *data) +{ + int ret; + u8 buf[HS3001_RESPONSE_LENGTH]; + u8 hs3001_status; + + ret = i2c_master_recv(client, buf, HS3001_RESPONSE_LENGTH); + if (ret != HS3001_RESPONSE_LENGTH) { + ret = ret < 0 ? ret : -EIO; + dev_dbg(&client->dev, + "Error in i2c communication. Error code: %d.\n", ret); + return ret; + } + + hs3001_status = FIELD_GET(HS3001_MASK_STATUS_0XC0, buf[0]); + if (hs3001_status == HS3001_DATA_STALE) { + dev_dbg(&client->dev, "Sensor busy.\n"); + return -EBUSY; + } + if (hs3001_status != HS3001_DATA_VALID) { + dev_dbg(&client->dev, "Data invalid.\n"); + return -EIO; + } + + data->humidity = + hs3001_extract_humidity(be16_to_cpup((__be16 *)&buf[0])); + data->temperature = + hs3001_extract_temperature(be16_to_cpup((__be16 *)&buf[2])); + + return 0; +} + +static umode_t hs3001_is_visible(const void *data, enum hwmon_sensor_types type, + u32 attr, int channel) +{ + /* Both, humidity and temperature can only be read. */ + return 0444; +} + +static int hs3001_read(struct device *dev, enum hwmon_sensor_types type, + u32 attr, int channel, long *val) +{ + struct hs3001_data *data = dev_get_drvdata(dev); + struct i2c_client *client = data->client; + int ret; + + mutex_lock(&data->i2c_lock); + ret = i2c_master_send(client, NULL, 0); + if (ret < 0) { + mutex_unlock(&data->i2c_lock); + return ret; + } + + /* + * Sensor needs some time to process measurement depending on + * resolution (ref. datasheet) + */ + fsleep(data->wait_time); + + ret = hs3001_data_fetch_command(client, data); + mutex_unlock(&data->i2c_lock); + + if (ret < 0) + return ret; + + switch (type) { + case hwmon_temp: + switch (attr) { + case hwmon_temp_input: + *val = data->temperature; + break; + default: + return -EINVAL; + } + break; + case hwmon_humidity: + switch (attr) { + case hwmon_humidity_input: + *val = data->humidity; + break; + default: + return -EINVAL; + } + break; + default: + return -EINVAL; + } + + return 0; +} + +static const struct hwmon_channel_info *hs3001_info[] = { + HWMON_CHANNEL_INFO(temp, HWMON_T_INPUT), + HWMON_CHANNEL_INFO(humidity, HWMON_H_INPUT), + NULL +}; + +static const struct hwmon_ops hs3001_hwmon_ops = { + .is_visible = hs3001_is_visible, + .read = hs3001_read, +}; + +static const struct hwmon_chip_info hs3001_chip_info = { + .ops = &hs3001_hwmon_ops, + .info = hs3001_info, +}; + +/* device ID table */ +static const struct i2c_device_id hs3001_ids[] = { + { "hs3001", 0 }, + { }, +}; + +MODULE_DEVICE_TABLE(i2c, hs3001_ids); + +static const struct of_device_id hs3001_of_match[] = { + {.compatible = "renesas,hs3001"}, + { }, +}; + +MODULE_DEVICE_TABLE(of, hs3001_of_match); + +static int hs3001_probe(struct i2c_client *client) +{ + struct hs3001_data *data; + struct device *hwmon_dev; + struct device *dev = &client->dev; + int ret; + + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) + return -EOPNOTSUPP; + + data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + data->client = client; + + /* + * Measurement time = wake-up time + measurement time temperature + * + measurement time humidity. This is currently static, because + * enabling programming mode is not supported, yet. + */ + data->wait_time = (HS3001_WAKEUP_TIME + HS3001_14BIT_RESOLUTION + + HS3001_14BIT_RESOLUTION); + + mutex_init(&data->i2c_lock); + + hwmon_dev = devm_hwmon_device_register_with_info(dev, + client->name, + data, + &hs3001_chip_info, + NULL); + + if (IS_ERR(hwmon_dev)) + return dev_err_probe(dev, PTR_ERR(hwmon_dev), + "Unable to register hwmon device.\n"); + + return 0; +} + +static struct i2c_driver hs3001_i2c_driver = { + .driver = { + .name = "hs3001", + .of_match_table = hs3001_of_match, + }, + .probe_new = hs3001_probe, + .id_table = hs3001_ids, +}; + +module_i2c_driver(hs3001_i2c_driver); + +MODULE_AUTHOR("Andre Werner "); +MODULE_DESCRIPTION("HS3001 humidity and temperature sensor base driver"); +MODULE_LICENSE("GPL");