From patchwork Mon Jun 26 07:29:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: JuenKit Yip X-Patchwork-Id: 13292432 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 2EF24EB64D7 for ; Mon, 26 Jun 2023 07:30:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229509AbjFZHaG (ORCPT ); Mon, 26 Jun 2023 03:30:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229454AbjFZHaG (ORCPT ); Mon, 26 Jun 2023 03:30:06 -0400 Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04olkn2020.outbound.protection.outlook.com [40.92.74.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B762E0; Mon, 26 Jun 2023 00:30:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WfPcIlgHBMLUiOWWax5WYlrDAkRu/WAra6Sp+B59UOUu0KlFWeYikXKmiuY7pPzIjrk0ALkDp1xFRNGKej0JWpKs82i7PGYwAGJ0IrJrz10XuYacc+kEe/vakczP/QdR3bQ0GRPm8UJCgNvGIeZe7U/b4AOQGeMVQ01r1uktYW+Dh+dsGsPluBMhHqloOHjEzYig2mg+Uqj5y/SZwksn4J6Ffcfzk+jWvZZDTmd7d35FNzR/LedMHgfjd+aKQ+b7jus0JEC1rKx34DiuxyheUGNKhguQhw/gKx66lN7LDO2kJcylwfs88XcKWilP9L6BUlClvL6O+DwZwer2yIpYPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=0O5NSon+OIh8MH2auHdzlANyMBfix9VHVhBDQZ2tMlM=; b=kBlBXrJrsXpgE5z102tgmOLJS8/CszJkrvul5cY5Yp1FWGwwHTf5bmbiHXvM/hP5d/TtI52CotVdco24iXjHZ5SnGmRbvYpoy5dMEx2+5oDRyO6Tx7LaXRNqkf3z9Z2Dm6i6wObZWthathpJckIA+TCloWuLFQyozD1F7KUvNTRUsEyvxyr/zwks2e0/5APdPu15Yt+8hIm7uSMyK2ZWFD/T9XLIoRvOVAAN2WG013uZgJlT4OQolL0xv10iKWhtCnSteQX0v3GzZyXkL7DPj+8eLa5ne0C/Hp5QPk12J3aJtmf80ZeA4l5lPpttg5CdL5ZBeM0zHUn60FV84c2QGA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0O5NSon+OIh8MH2auHdzlANyMBfix9VHVhBDQZ2tMlM=; b=urLjJK3u/bDSE2TGwy0Iv9CLa8ToaKiyJd/mA9UaQ+pQQDzBR2UIdlDjr1MoE24oLzhysQNNaOYWaZK/CsOrSnoL7aVy7TtSJBALyQTEscSV+vmAKz3lUBygSkuAeDQdarJcS8Gw3fYBp2Q7LXNbhkTYZQwE4suFH9btgGi+spg0F7Rjz1xjVFyObcI1dx0XEo+lVxCTOJbZVJ4hLlf4JHjq2aYpe+krWc5Ls8aDjsyf+Hc9Bug8zA59MEgE6a4Ns/UdByym2XcVq9XKJZoT6aIMlh5Lc1icHGbDuhktl8MS0VwdZylh+ouUbRojWd/TcycjkysfTDMhqhqn99MFEA== Received: from DB4PR10MB6261.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:10:383::21) by AS8PR10MB7858.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:631::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.26; Mon, 26 Jun 2023 07:30:01 +0000 Received: from DB4PR10MB6261.EURPRD10.PROD.OUTLOOK.COM ([fe80::628a:d617:46f:2a88]) by DB4PR10MB6261.EURPRD10.PROD.OUTLOOK.COM ([fe80::628a:d617:46f:2a88%7]) with mapi id 15.20.6521.024; Mon, 26 Jun 2023 07:30:01 +0000 From: JuenKit_Yip@hotmail.com To: jdelvare@suse.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, corbet@lwn.net Cc: linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org, linux-doc@vger.kernel.org, JuenKit Yip Subject: [PATCH v1 1/3] hwmon: (sht3x) convert some of sysfs interface to hwmon Date: Mon, 26 Jun 2023 15:29:21 +0800 Message-ID: X-Mailer: git-send-email 2.30.2 X-TMN: [EyGS9BttCGbheCJ6nzcgzGru0Vv0BZQg] X-ClientProxiedBy: TYCPR01CA0167.jpnprd01.prod.outlook.com (2603:1096:400:2b2::7) To DB4PR10MB6261.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:10:383::21) X-Microsoft-Original-Message-ID: <20230626072923.340544-1-JuenKit_Yip@hotmail.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB4PR10MB6261:EE_|AS8PR10MB7858:EE_ X-MS-Office365-Filtering-Correlation-Id: 32748e14-f9ef-4ac8-9b3f-08db7617267b X-MS-Exchange-SLBlob-MailProps: 70qbaZjg4mtkMlMwcfBWW/BIsvQGdiItrg8zNDemJluqpg8aIs1s/6QRKDvRDy1do4vqVvmh1NKqRXuML1rJ/8uuGmN8qOzhU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HqiBHyfySGsb0i0dIA0fpNdUtSd9+xBUaVbdBQ9fTdzqKQVFFkSicTKh6MxsvnM4R0yCoDqEIiWJ7xRxx3ug1yvlacGfjV5flIufUAOBhQ32U7a1tqlJglDfufpkdNNay8zNvz555N0QktxUBO0bqurNGUP2hSOHrkIvoPhWfhy4PQkhYz49z75+1P5DhIFI7+psZpeQyDBXYx4xP032qnZcYPmAGOwtXQyU9s/kT6zvTjXltYPX4YJ26tkPvdBU5xxNjQaNdSY3QT2ubJ/HcEyrPO1KCF5CkMr1qzE14MiPJMXuunvYifW/xbDz2CkqbwgMtMXrErh40S5gWZhNl1OapDiEvxKOoeGagWtHA9MXz12MVh04ZOVwzbSz8RMnnoZpYOgwBCnT4wxK7JxisZPHrbs4CF+URqKT49xOiyab6ksht6EVRv8gR9m0JmJbY1bDroj8YY3pFsReUnm7TeCKM8fCtn8Bj5AOs3pHRiA96h/Shz/zxHuJvU4= X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-6b909.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: 32748e14-f9ef-4ac8-9b3f-08db7617267b X-MS-Exchange-CrossTenant-AuthSource: DB4PR10MB6261.EURPRD10.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jun 2023 07:30:01.0813 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR10MB7858 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org From: JuenKit Yip update_interval, temperature/humidity max/min and hyst were moved to new hwmon interface, and only heater and repeatability were reserved as non-stardard sysfs interface. Signed-off-by: JuenKit Yip --- v1: - remove forward declearations - fix switch statement about "return 0" and "break" for consistency - convert type of "val" from string to numeric value Documentation/hwmon/sht3x.rst | 21 +- drivers/hwmon/sht3x.c | 389 ++++++++++++++++++++++------------ 2 files changed, 254 insertions(+), 156 deletions(-) diff --git a/Documentation/hwmon/sht3x.rst b/Documentation/hwmon/sht3x.rst index 87864ffd1777..572df2be1689 100644 --- a/Documentation/hwmon/sht3x.rst +++ b/Documentation/hwmon/sht3x.rst @@ -52,32 +52,15 @@ When the temperature and humidity readings move back between the hysteresis values, the alert bit is set to 0 and the alert pin on the sensor is set to low. -sysfs-Interface ---------------- +non-standard sysfs-Interface +---------------------------- =================== ============================================================ -temp1_input: temperature input -humidity1_input: humidity input -temp1_max: temperature max value -temp1_max_hyst: temperature hysteresis value for max limit -humidity1_max: humidity max value -humidity1_max_hyst: humidity hysteresis value for max limit -temp1_min: temperature min value -temp1_min_hyst: temperature hysteresis value for min limit -humidity1_min: humidity min value -humidity1_min_hyst: humidity hysteresis value for min limit -temp1_alarm: alarm flag is set to 1 if the temperature is outside the - configured limits. Alarm only works in periodic measure mode -humidity1_alarm: alarm flag is set to 1 if the humidity is outside the - configured limits. Alarm only works in periodic measure mode heater_enable: heater enable, heating element removes excess humidity from sensor: - 0: turned off - 1: turned on -update_interval: update interval, 0 for single shot, interval in msec - for periodic measurement. If the interval is not supported - by the sensor, the next faster interval is chosen repeatability: write or read repeatability, higher repeatability means longer measurement duration, lower noise level and larger energy consumption: diff --git a/drivers/hwmon/sht3x.c b/drivers/hwmon/sht3x.c index bf18630619e0..bd483af1c5ab 100644 --- a/drivers/hwmon/sht3x.c +++ b/drivers/hwmon/sht3x.c @@ -147,8 +147,20 @@ static const u16 mode_to_update_interval[] = { 100, }; +static const struct hwmon_channel_info * const sht3x_channel_info[] = { + HWMON_CHANNEL_INFO(chip, HWMON_C_UPDATE_INTERVAL), + HWMON_CHANNEL_INFO(temp, HWMON_T_INPUT | HWMON_T_MIN | + HWMON_T_MIN_HYST | HWMON_T_MAX | + HWMON_T_MAX_HYST | HWMON_T_ALARM), + HWMON_CHANNEL_INFO(humidity, HWMON_H_INPUT | HWMON_H_MIN | + HWMON_H_MIN_HYST | HWMON_H_MAX | + HWMON_H_MAX_HYST | HWMON_H_ALARM), + NULL, +}; + struct sht3x_data { struct i2c_client *client; + enum sht3x_chips chip_info; struct mutex i2c_lock; /* lock for sending i2c commands */ struct mutex data_lock; /* lock for updating driver data */ @@ -276,27 +288,24 @@ static struct sht3x_data *sht3x_update_client(struct device *dev) return data; } -/* sysfs attributes */ -static ssize_t temp1_input_show(struct device *dev, - struct device_attribute *attr, char *buf) +static int temp1_input_read(struct device *dev) { struct sht3x_data *data = sht3x_update_client(dev); if (IS_ERR(data)) return PTR_ERR(data); - return sprintf(buf, "%d\n", data->temperature); + return data->temperature; } -static ssize_t humidity1_input_show(struct device *dev, - struct device_attribute *attr, char *buf) +static int humidity1_input_read(struct device *dev) { struct sht3x_data *data = sht3x_update_client(dev); if (IS_ERR(data)) return PTR_ERR(data); - return sprintf(buf, "%u\n", data->humidity); + return data->humidity; } /* @@ -332,33 +341,24 @@ static int limits_update(struct sht3x_data *data) return ret; } -static ssize_t temp1_limit_show(struct device *dev, - struct device_attribute *attr, - char *buf) +static int temp1_limit_read(struct device *dev, int index) { struct sht3x_data *data = dev_get_drvdata(dev); - u8 index = to_sensor_dev_attr(attr)->index; - int temperature_limit = data->temperature_limits[index]; - return sysfs_emit(buf, "%d\n", temperature_limit); + return data->temperature_limits[index]; } -static ssize_t humidity1_limit_show(struct device *dev, - struct device_attribute *attr, - char *buf) +static int humidity1_limit_read(struct device *dev, int index) { struct sht3x_data *data = dev_get_drvdata(dev); - u8 index = to_sensor_dev_attr(attr)->index; - u32 humidity_limit = data->humidity_limits[index]; - return sysfs_emit(buf, "%u\n", humidity_limit); + return data->humidity_limits[index]; } /* - * limit_store must only be called with data_lock held + * limit_write must only be called with data_lock held */ -static size_t limit_store(struct device *dev, - size_t count, +static size_t limit_write(struct device *dev, u8 index, int temperature, u32 humidity) @@ -379,7 +379,7 @@ static size_t limit_store(struct device *dev, * ST = (T + 45) / 175 * 2^16 * SRH = RH / 100 * 2^16 * adapted for fixed point arithmetic and packed the same as - * in limit_show() + * in limit_read() */ raw = ((u32)(temperature + 45000) * 24543) >> (16 + 7); raw |= ((humidity * 42950) >> 16) & 0xfe00; @@ -400,50 +400,35 @@ static size_t limit_store(struct device *dev, data->temperature_limits[index] = temperature; data->humidity_limits[index] = humidity; - return count; + + return 0; } -static ssize_t temp1_limit_store(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t count) +static int temp1_limit_write(struct device *dev, int index, int val) { int temperature; int ret; struct sht3x_data *data = dev_get_drvdata(dev); - u8 index = to_sensor_dev_attr(attr)->index; - ret = kstrtoint(buf, 0, &temperature); - if (ret) - return ret; - - temperature = clamp_val(temperature, SHT3X_MIN_TEMPERATURE, + temperature = clamp_val(val, SHT3X_MIN_TEMPERATURE, SHT3X_MAX_TEMPERATURE); mutex_lock(&data->data_lock); - ret = limit_store(dev, count, index, temperature, + ret = limit_write(dev, index, temperature, data->humidity_limits[index]); mutex_unlock(&data->data_lock); return ret; } -static ssize_t humidity1_limit_store(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t count) +static int humidity1_limit_write(struct device *dev, int index, int val) { - u32 humidity; + int humidity; int ret; struct sht3x_data *data = dev_get_drvdata(dev); - u8 index = to_sensor_dev_attr(attr)->index; - ret = kstrtou32(buf, 0, &humidity); - if (ret) - return ret; - - humidity = clamp_val(humidity, SHT3X_MIN_HUMIDITY, SHT3X_MAX_HUMIDITY); + humidity = clamp_val(val, SHT3X_MIN_HUMIDITY, SHT3X_MAX_HUMIDITY); mutex_lock(&data->data_lock); - ret = limit_store(dev, count, index, data->temperature_limits[index], + ret = limit_write(dev, index, data->temperature_limits[index], humidity); mutex_unlock(&data->data_lock); @@ -474,7 +459,6 @@ static void sht3x_select_command(struct sht3x_data *data) } static int status_register_read(struct device *dev, - struct device_attribute *attr, char *buffer, int length) { int ret; @@ -487,34 +471,30 @@ static int status_register_read(struct device *dev, return ret; } -static ssize_t temp1_alarm_show(struct device *dev, - struct device_attribute *attr, - char *buf) +static int temp1_alarm_read(struct device *dev) { char buffer[SHT3X_WORD_LEN + SHT3X_CRC8_LEN]; int ret; - ret = status_register_read(dev, attr, buffer, + ret = status_register_read(dev, buffer, SHT3X_WORD_LEN + SHT3X_CRC8_LEN); if (ret) return ret; - return sysfs_emit(buf, "%d\n", !!(buffer[0] & 0x04)); + return !!(buffer[0] & 0x04); } -static ssize_t humidity1_alarm_show(struct device *dev, - struct device_attribute *attr, - char *buf) +static int humidity1_alarm_read(struct device *dev) { char buffer[SHT3X_WORD_LEN + SHT3X_CRC8_LEN]; int ret; - ret = status_register_read(dev, attr, buffer, + ret = status_register_read(dev, buffer, SHT3X_WORD_LEN + SHT3X_CRC8_LEN); if (ret) return ret; - return sysfs_emit(buf, "%d\n", !!(buffer[0] & 0x08)); + return !!(buffer[0] & 0x08); } static ssize_t heater_enable_show(struct device *dev, @@ -524,7 +504,7 @@ static ssize_t heater_enable_show(struct device *dev, char buffer[SHT3X_WORD_LEN + SHT3X_CRC8_LEN]; int ret; - ret = status_register_read(dev, attr, buffer, + ret = status_register_read(dev, buffer, SHT3X_WORD_LEN + SHT3X_CRC8_LEN); if (ret) return ret; @@ -560,39 +540,28 @@ static ssize_t heater_enable_store(struct device *dev, return ret; } -static ssize_t update_interval_show(struct device *dev, - struct device_attribute *attr, - char *buf) +static int update_interval_read(struct device *dev) { struct sht3x_data *data = dev_get_drvdata(dev); - return sysfs_emit(buf, "%u\n", - mode_to_update_interval[data->mode]); + return mode_to_update_interval[data->mode]; } -static ssize_t update_interval_store(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t count) +static int update_interval_write(struct device *dev, u16 val) { - u16 update_interval; u8 mode; int ret; const char *command; struct sht3x_data *data = dev_get_drvdata(dev); struct i2c_client *client = data->client; - ret = kstrtou16(buf, 0, &update_interval); - if (ret) - return ret; - - mode = get_mode_from_update_interval(update_interval); + mode = get_mode_from_update_interval(val); mutex_lock(&data->data_lock); /* mode did not change */ if (mode == data->mode) { mutex_unlock(&data->data_lock); - return count; + return 0; } mutex_lock(&data->i2c_lock); @@ -634,7 +603,7 @@ static ssize_t update_interval_store(struct device *dev, if (ret != SHT3X_CMD_LENGTH) return ret < 0 ? ret : -EIO; - return count; + return 0; } static ssize_t repeatability_show(struct device *dev, @@ -668,60 +637,219 @@ static ssize_t repeatability_store(struct device *dev, return count; } -static SENSOR_DEVICE_ATTR_RO(temp1_input, temp1_input, 0); -static SENSOR_DEVICE_ATTR_RO(humidity1_input, humidity1_input, 0); -static SENSOR_DEVICE_ATTR_RW(temp1_max, temp1_limit, limit_max); -static SENSOR_DEVICE_ATTR_RW(humidity1_max, humidity1_limit, limit_max); -static SENSOR_DEVICE_ATTR_RW(temp1_max_hyst, temp1_limit, limit_max_hyst); -static SENSOR_DEVICE_ATTR_RW(humidity1_max_hyst, humidity1_limit, - limit_max_hyst); -static SENSOR_DEVICE_ATTR_RW(temp1_min, temp1_limit, limit_min); -static SENSOR_DEVICE_ATTR_RW(humidity1_min, humidity1_limit, limit_min); -static SENSOR_DEVICE_ATTR_RW(temp1_min_hyst, temp1_limit, limit_min_hyst); -static SENSOR_DEVICE_ATTR_RW(humidity1_min_hyst, humidity1_limit, - limit_min_hyst); -static SENSOR_DEVICE_ATTR_RO(temp1_alarm, temp1_alarm, 0); -static SENSOR_DEVICE_ATTR_RO(humidity1_alarm, humidity1_alarm, 0); static SENSOR_DEVICE_ATTR_RW(heater_enable, heater_enable, 0); -static SENSOR_DEVICE_ATTR_RW(update_interval, update_interval, 0); static SENSOR_DEVICE_ATTR_RW(repeatability, repeatability, 0); static struct attribute *sht3x_attrs[] = { - &sensor_dev_attr_temp1_input.dev_attr.attr, - &sensor_dev_attr_humidity1_input.dev_attr.attr, - &sensor_dev_attr_temp1_max.dev_attr.attr, - &sensor_dev_attr_temp1_max_hyst.dev_attr.attr, - &sensor_dev_attr_humidity1_max.dev_attr.attr, - &sensor_dev_attr_humidity1_max_hyst.dev_attr.attr, - &sensor_dev_attr_temp1_min.dev_attr.attr, - &sensor_dev_attr_temp1_min_hyst.dev_attr.attr, - &sensor_dev_attr_humidity1_min.dev_attr.attr, - &sensor_dev_attr_humidity1_min_hyst.dev_attr.attr, - &sensor_dev_attr_temp1_alarm.dev_attr.attr, - &sensor_dev_attr_humidity1_alarm.dev_attr.attr, &sensor_dev_attr_heater_enable.dev_attr.attr, - &sensor_dev_attr_update_interval.dev_attr.attr, &sensor_dev_attr_repeatability.dev_attr.attr, NULL }; -static struct attribute *sts3x_attrs[] = { - &sensor_dev_attr_temp1_input.dev_attr.attr, - &sensor_dev_attr_temp1_max.dev_attr.attr, - &sensor_dev_attr_temp1_max_hyst.dev_attr.attr, - &sensor_dev_attr_temp1_min.dev_attr.attr, - &sensor_dev_attr_temp1_min_hyst.dev_attr.attr, - &sensor_dev_attr_temp1_alarm.dev_attr.attr, - &sensor_dev_attr_heater_enable.dev_attr.attr, - &sensor_dev_attr_update_interval.dev_attr.attr, - &sensor_dev_attr_repeatability.dev_attr.attr, - NULL +ATTRIBUTE_GROUPS(sht3x); + +static umode_t sht3x_is_visible(const void *data, enum hwmon_sensor_types type, + u32 attr, int channel) +{ + const struct sht3x_data *chip_data = data; + + switch (type) { + case hwmon_chip: + switch (attr) { + case hwmon_chip_update_interval: + return 0644; + default: + break; + } + break; + case hwmon_temp: + switch (attr) { + case hwmon_temp_input: + case hwmon_temp_alarm: + return 0444; + case hwmon_temp_max: + case hwmon_temp_max_hyst: + case hwmon_temp_min: + case hwmon_temp_min_hyst: + return 0644; + default: + break; + } + break; + case hwmon_humidity: + if (chip_data->chip_info == sts3x) + break; + switch (attr) { + case hwmon_humidity_input: + case hwmon_humidity_alarm: + return 0444; + case hwmon_humidity_max: + case hwmon_humidity_max_hyst: + case hwmon_humidity_min: + case hwmon_humidity_min_hyst: + return 0644; + default: + break; + } + break; + default: + break; + } + + return 0; +} + +static int sht3x_read(struct device *dev, enum hwmon_sensor_types type, + u32 attr, int channel, long *val) +{ + enum sht3x_limits index; + + switch (type) { + case hwmon_chip: + switch (attr) { + case hwmon_chip_update_interval: + *val = update_interval_read(dev); + break; + default: + return -EOPNOTSUPP; + } + break; + case hwmon_temp: + switch (attr) { + case hwmon_temp_input: + *val = temp1_input_read(dev); + break; + case hwmon_temp_alarm: + *val = temp1_alarm_read(dev); + break; + case hwmon_temp_max: + index = limit_max; + *val = temp1_limit_read(dev, index); + break; + case hwmon_temp_max_hyst: + index = limit_max_hyst; + *val = temp1_limit_read(dev, index); + break; + case hwmon_temp_min: + index = limit_min; + *val = temp1_limit_read(dev, index); + break; + case hwmon_temp_min_hyst: + index = limit_min_hyst; + *val = temp1_limit_read(dev, index); + break; + default: + return -EOPNOTSUPP; + } + break; + case hwmon_humidity: + switch (attr) { + case hwmon_humidity_input: + *val = humidity1_input_read(dev); + break; + case hwmon_humidity_alarm: + *val = humidity1_alarm_read(dev); + break; + case hwmon_humidity_max: + index = limit_max; + *val = humidity1_limit_read(dev, index); + break; + case hwmon_humidity_max_hyst: + index = limit_max_hyst; + *val = humidity1_limit_read(dev, index); + break; + case hwmon_humidity_min: + index = limit_min; + *val = humidity1_limit_read(dev, index); + break; + case hwmon_humidity_min_hyst: + index = limit_min_hyst; + *val = humidity1_limit_read(dev, index); + break; + default: + return -EOPNOTSUPP; + } + break; + default: + return -EOPNOTSUPP; + } + + return 0; +} + +static int sht3x_write(struct device *dev, enum hwmon_sensor_types type, + u32 attr, int channel, long val) +{ + enum sht3x_limits index; + + switch (type) { + case hwmon_chip: + switch (attr) { + case hwmon_chip_update_interval: + return update_interval_write(dev, val); + default: + return -EOPNOTSUPP; + } + case hwmon_temp: + switch (attr) { + case hwmon_temp_max: + index = limit_max; + break; + case hwmon_temp_max_hyst: + index = limit_max_hyst; + break; + case hwmon_temp_min: + index = limit_min; + break; + case hwmon_temp_min_hyst: + index = limit_min_hyst; + break; + default: + return -EOPNOTSUPP; + } + return temp1_limit_write(dev, index, val); + case hwmon_humidity: + switch (attr) { + case hwmon_humidity_max: + index = limit_max; + break; + case hwmon_humidity_max_hyst: + index = limit_max_hyst; + break; + case hwmon_humidity_min: + index = limit_min; + break; + case hwmon_humidity_min_hyst: + index = limit_min_hyst; + break; + default: + return -EOPNOTSUPP; + } + return humidity1_limit_write(dev, index, val); + default: + return -EOPNOTSUPP; + } +} + +static const struct hwmon_ops sht3x_ops = { + .is_visible = sht3x_is_visible, + .read = sht3x_read, + .write = sht3x_write, }; -ATTRIBUTE_GROUPS(sht3x); -ATTRIBUTE_GROUPS(sts3x); +static const struct hwmon_chip_info sht3x_chip_info = { + .ops = &sht3x_ops, + .info = sht3x_channel_info, +}; + +/* device ID table */ +static const struct i2c_device_id sht3x_ids[] = { + {"sht3x", sht3x}, + {"sts3x", sts3x}, + {} +}; -static const struct i2c_device_id sht3x_ids[]; +MODULE_DEVICE_TABLE(i2c, sht3x_ids); static int sht3x_probe(struct i2c_client *client) { @@ -730,7 +858,6 @@ static int sht3x_probe(struct i2c_client *client) struct device *hwmon_dev; struct i2c_adapter *adap = client->adapter; struct device *dev = &client->dev; - const struct attribute_group **attribute_groups; /* * we require full i2c support since the sht3x uses multi-byte read and @@ -753,6 +880,7 @@ static int sht3x_probe(struct i2c_client *client) data->mode = 0; data->last_update = jiffies - msecs_to_jiffies(3000); data->client = client; + data->chip_info = i2c_match_id(sht3x_ids, client)->driver_data; crc8_populate_msb(sht3x_crc8_table, SHT3X_CRC8_POLYNOMIAL); sht3x_select_command(data); @@ -771,15 +899,11 @@ static int sht3x_probe(struct i2c_client *client) if (ret) return ret; - if (i2c_match_id(sht3x_ids, client)->driver_data == sts3x) - attribute_groups = sts3x_groups; - else - attribute_groups = sht3x_groups; - - hwmon_dev = devm_hwmon_device_register_with_groups(dev, - client->name, - data, - attribute_groups); + hwmon_dev = devm_hwmon_device_register_with_info(dev, + client->name, + data, + &sht3x_chip_info, + sht3x_groups); if (IS_ERR(hwmon_dev)) dev_dbg(dev, "unable to register hwmon device\n"); @@ -787,15 +911,6 @@ static int sht3x_probe(struct i2c_client *client) return PTR_ERR_OR_ZERO(hwmon_dev); } -/* device ID table */ -static const struct i2c_device_id sht3x_ids[] = { - {"sht3x", sht3x}, - {"sts3x", sts3x}, - {} -}; - -MODULE_DEVICE_TABLE(i2c, sht3x_ids); - static struct i2c_driver sht3x_i2c_driver = { .driver.name = "sht3x", .probe = sht3x_probe, From patchwork Mon Jun 26 07:29:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: JuenKit Yip X-Patchwork-Id: 13292433 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 B36BDEB64DA for ; Mon, 26 Jun 2023 07:30:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229816AbjFZHaK (ORCPT ); Mon, 26 Jun 2023 03:30:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229454AbjFZHaI (ORCPT ); Mon, 26 Jun 2023 03:30:08 -0400 Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03olkn2060.outbound.protection.outlook.com [40.92.58.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD8E5E0; Mon, 26 Jun 2023 00:30:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nHEjHg2GHrFb8t6VJx5Zt6HSWn6bWYmH5SdgLdVVZulx6e6YLMgxdE/uGFqT0DjBXRBWzHYPZtlJtlIN4J9cVVETbvMCwZG+v6Kir5JVRfxXi/R6FRiLOg2392MFpWpVel6rivFvawrxGAZ2LWXa/3j3ojaDVYvlBtvkWpSns6TQID1biZec7fC3tM/63vuWN0QUzxJT+ywaTCMjqbXe3y9eyVkDgJ63hJakbEuhIS5QPjGi7giAETL/sooZyvRIxZDBtHpZfuVxNlz2AllBdpfJxja/AAljxttlPdlaMSk2nFc9AGVSzEM8VFLPhS0v60KzFpt6S4q25aEzNYASUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=2TIMv/J22r6cNoRW8Aee8JzK9G9u0MewxudOg21/GlU=; b=SIJnNmsNLqPvma03UL8/W1WMNiavZ3nvCyzUfviT4mDoYoE9TyjLrWrXXXhGEdB1AyuElP8AWwHCIIOH6BfF3H8VNOAwLRaU6mD/4aI5dZlthfx52HLVq+Bhp0w4PSFq8VEp+29+6OeVVAeQ6zIfqYGJ6FArQGjuA18Hid9VMWwOXy6Bcoz2vLJKy+vQ6YMgLb4UPor/qjyn++M/SOhroZbX0EdOr1X5zNWATjfzpAF8yzrjRNowq9GrIiwcKld7G6meJ7rQiYLvBo8fjf3u5dap6QzAWUegttGAUXCWU+6zj4apHGUOLTQIwGOAMp5NxGKeQ6iJ52+sb6rbzVYI9Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2TIMv/J22r6cNoRW8Aee8JzK9G9u0MewxudOg21/GlU=; b=KQPdd0f5C/K2vhXcaEhRDaZTaJPsLmZfmqFhO99vwNdF60dZRggo32+ELafopsgf5GmbFDGdeud9W3oSLRAMwzEIb+jVeeMaFVFXTK6JhqQq+71k3we4MHxdGqz23YqPrysjImIVZWLKjB5LNn8BSTLZynQVCieKLpFpal6qEjLERRtk4BGoLaxjXLe1sifgs7Fl81FTKt5FbHtfKWQQ9kwCAMzUMzjKJM+OxpGMgFeck8ipW2skl7/r+z9vT+3A3bQbe0ZvOyEOhErdyX1Y0ecN0dmJhvKU1CKvTPN0YfubijT3b75XOYlOG+9JO6/Nhfz6a1vLfixrsLwMYlHXnQ== Received: from DB4PR10MB6261.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:10:383::21) by AS8PR10MB7858.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:631::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.26; Mon, 26 Jun 2023 07:30:05 +0000 Received: from DB4PR10MB6261.EURPRD10.PROD.OUTLOOK.COM ([fe80::628a:d617:46f:2a88]) by DB4PR10MB6261.EURPRD10.PROD.OUTLOOK.COM ([fe80::628a:d617:46f:2a88%7]) with mapi id 15.20.6521.024; Mon, 26 Jun 2023 07:30:05 +0000 From: JuenKit_Yip@hotmail.com To: jdelvare@suse.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, corbet@lwn.net Cc: linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org, linux-doc@vger.kernel.org, JuenKit Yip Subject: [PATCH v1 2/3] hwmon: (sht3x) add devicetree support Date: Mon, 26 Jun 2023 15:29:22 +0800 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230626072923.340544-1-JuenKit_Yip@hotmail.com> References: <20230626072923.340544-1-JuenKit_Yip@hotmail.com> X-TMN: [QQ/NGHhaxWXKSr0HyQDcEAt8euCQwfEi] X-ClientProxiedBy: TYCPR01CA0167.jpnprd01.prod.outlook.com (2603:1096:400:2b2::7) To DB4PR10MB6261.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:10:383::21) X-Microsoft-Original-Message-ID: <20230626072923.340544-2-JuenKit_Yip@hotmail.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB4PR10MB6261:EE_|AS8PR10MB7858:EE_ X-MS-Office365-Filtering-Correlation-Id: 78214b27-2787-421f-ba01-08db76172965 X-MS-Exchange-SLBlob-MailProps: EgT5Wr3QDKzYk8yevgJIT5SRqgxOIeQcAffxd68fClywQnsm7DRsjTDWjnDcTd8tBs+7r7imWCriaNAcrrjOubShov0ce4a3yXAQ0Ls2vaDaDnBjU2tPjikC0CewQYOoggGYcl0zhHSgXBQ6YJNd4tP9jmzOzYtRClSVf1rZfH1dmVvAsET+QOwycII1H3Hvpj3zeH0rsZDo2jxogG6rDsAhjUiqabiF8wPlY9bAj1DiNb7OF6jkaZTNJnKi3VhoD8CiblJSttUF8EnJbper0HbYBdzZCKJoYLPEj+VaptNNsd67WXitUDdX4oX3pFuvN++GoBaYMCHbRyau/ZwuPZblGyIxHHbqa47505T6bLG8nmN/EumsCK8zhbY4CvFSnM/b1obDY+2W4G396npxVzMmukh50/nWvDzZU5lNjuFQcjWSDXh0qlBSa+OyrpNdumUhJvjRYWtx7IpEomOQnY4iL/P02E3O8nv1a5CbpWfuisvUfMQ/U1gjeDMvBkcS2ZiKMyEGfEaefyZIFGXiLoW75kgRKUBqkQk8iPMwX1TwgGAUuB4ul7y+ThlcGJfxje6gdanjt4jcZUR1+kyL+/D9gNfnhD95Wxr4rTFIzH/qEe5vScrkiwSOqpp4aiOMs54oxcYgGcAWtfsMNG8zGcVIYsJJwohJ6CMyvmzFDclF7tWTL+8mGnyUrQ3xjQdcE23VaFH1x9hWmbuRZtnGNPykFqx6G9ZM4IHBakQxz80= X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TG6nNgFZD18ctlioIZyPFm0VQbDmuLQwOu53MTmpDtw0BM5qzGjv7IDwb+8k85Wa8BgGzdXo/U066yzY+1Aril5Lrvp0yU9yb0Y5korO70EtHOAenDI3aOFap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fIOEbR5XLw4Lb7Vh+XKofOtfkYwYq8BRDbxdNWJQ8tht82W6HclBT62v7rkmoPKvufjwtkb2KLXt1H3QUB9XKUUIurrrBHeOLq03h/+mGHqdelCXGz3KPhmAWQcioYUKlegoFDdKdC7mWPizDjZ93RUCDlPqLWrOZB748g1oBhFTp+53sogTbwNz1cdjo9g5FDV//5N2oLB8oS6Z0pz0wvLFtkm0tBm699SQr9mC6nBSDHV547oembBOCQBx/iXou+8wQHlI8ER4i5ImugVUBcaqKLypH+7SyhZMrnNPCSOwfeEYKKBe7il3kQTTwa9pvGRiIt7O6oUAsB+nG8d4f/8M+UKoSs3VhAPdwoR1wSM3wkYF5KZdT48GMcgkM9oW+7bjvFAEZhEgt5UmjyJAwrWZ+5W2gu+38I/2e9HpwspYxLzk6DzLnKl4HLylSfEKEQ9wtpPwBJNUrZ6+faRAAfVtb1hfTeH0FZhk+wxW3X0GlOlJI4CzlVfvSK1JooiHJmXmjjZMMahK2/ylyJyhSkrW65rZGt53XMOjvdOBpYodRIKJLTL15PO3fU3X0zb3sZYA57RRmAA8jCYJ4hzOfCyMDpWFiVsKHGjTajLlJZp7s+1m8N5a6b7DSdFGrCJLqNDQPKXB9IosZ5PGou7kemQ6nbeEe6ruO936BJLKNmg8ILtqvTK7NuYSP98p0+CpEiWGNJUcYcHLjm/D4ccOTESd0JOnjGEYKtysPI= X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-6b909.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: 78214b27-2787-421f-ba01-08db76172965 X-MS-Exchange-CrossTenant-AuthSource: DB4PR10MB6261.EURPRD10.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jun 2023 07:30:05.8662 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR10MB7858 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org From: JuenKit Yip add "compatible" property for supporting devicetree Signed-off-by: JuenKit Yip --- v1: - add MODULE_DEVICE_TABLE(of, sht3x_of_match) - drop of_match_ptr drivers/hwmon/sht3x.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/sht3x.c b/drivers/hwmon/sht3x.c index bd483af1c5ab..46b0a0231b06 100644 --- a/drivers/hwmon/sht3x.c +++ b/drivers/hwmon/sht3x.c @@ -911,8 +911,19 @@ static int sht3x_probe(struct i2c_client *client) return PTR_ERR_OR_ZERO(hwmon_dev); } +/* devicetree ID table */ +static const struct of_device_id sht3x_of_match[] = { + { .compatible = "sensirion,sht3x" }, + { .compatible = "sensirion,sts3x" }, + {}, +}; +MODULE_DEVICE_TABLE(of, sht3x_of_match); + static struct i2c_driver sht3x_i2c_driver = { - .driver.name = "sht3x", + .driver = { + .name = "sht3x", + .of_match_table = sht3x_of_match, + }, .probe = sht3x_probe, .id_table = sht3x_ids, }; From patchwork Mon Jun 26 07:29:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: JuenKit Yip X-Patchwork-Id: 13292434 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 8AFD6EB64D7 for ; Mon, 26 Jun 2023 07:30:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229829AbjFZHaQ (ORCPT ); Mon, 26 Jun 2023 03:30:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229454AbjFZHaP (ORCPT ); Mon, 26 Jun 2023 03:30:15 -0400 Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04olkn2098.outbound.protection.outlook.com [40.92.74.98]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C686EE; Mon, 26 Jun 2023 00:30:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AnqMTJ6z2Iekd5ywtxyZBptF9KFHjRFU9bnujmueyhAnrjWk6fEG7pmXoDw7fh4g4Kl/siiMjDbHhtx2wxlNVLd+x4CHJIpPG+5KGSATjkKsnzpN0nw2WOZ01OmVJJUelfldQzblm8TmflVVun8U3isK2c1aut8fudp/6xZJTBsv7Lv/+o+U7Uq9l87GbXMGzKJ9WNm6WMnJ5pBCfA8apYttYMjDmVBtckYVjyhHBYfHhFBNnat3zbrxqbWbXdptn+K1Z9X+kgFmKMz1L7G3VFXSjk894u+3RDqt/EB9l09DGB0bcV2a8ltZL20AZU+0/ND6Q4XRbbgT02VJZSdGDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Fb23gxmD/ygOGVCCSLcPDFuCUZWSKS88xPNJ2d0aFek=; b=GBBlhj+p+JFsB1AgBKRIH0d62DuLhMh4nyfAi7ljVlursVCoKURHDwt21h5D5irD2tyoXczGCtHHj6BUQ7dGQiiX65lQS9i3shsnqcdoJ9R+hh+Qpf5gDxq9OhwjawNfWqjCV1ILiDCfEzdNlZUVLpluzbK72b4BREYm/kzN0U9S/+V2VWhr+c8JInSS4OhuFdkNVad6OxPSujL29jt/0vqOzHxdil5/8s8RRPPbdqtFQaARJjknVxCaGrno3oA7eGDlc7KXygr8xIRQg02fjSkDnALg+qZs1j4fbWrl9atpINcUHPdH/j8ZwPLjSkUDHXIbATmi7FLI5YSOm0WGzg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Fb23gxmD/ygOGVCCSLcPDFuCUZWSKS88xPNJ2d0aFek=; b=TAtpVKseS3EshHGLVcJLHozt/e5vZMGBCyUSM5yrfAAsVYW1F2n7wcabLh55o+ipUgRYdxS7XZ7gXjzd3UgdIbyRyDKdLx+K6WhmS1xQGg0t6lYyFwDMxuETDFoO7bLOXiU1wpk7+c0DQM8WruL7vV1Kw9Hch9PjdyNucXzL0A3KmeYPxF2iMQxRihbQEEKZP66QEjb3EWRFV95P623nBxOgTFrWh6AsF15C1lHwGTn/vffDa661IcI70Rr1nK/B+A+4U7FpbRPU6wqf/wCLACf+d2aXEBvqIb5xsImpsbtyES3rlztVMKRVORVlF+63WeJII2xjOI+Ize/tPeAl0A== Received: from DB4PR10MB6261.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:10:383::21) by AS8PR10MB7858.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:631::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.26; Mon, 26 Jun 2023 07:30:10 +0000 Received: from DB4PR10MB6261.EURPRD10.PROD.OUTLOOK.COM ([fe80::628a:d617:46f:2a88]) by DB4PR10MB6261.EURPRD10.PROD.OUTLOOK.COM ([fe80::628a:d617:46f:2a88%7]) with mapi id 15.20.6521.024; Mon, 26 Jun 2023 07:30:10 +0000 From: JuenKit_Yip@hotmail.com To: jdelvare@suse.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, corbet@lwn.net Cc: linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org, linux-doc@vger.kernel.org, JuenKit Yip Subject: [PATCH v1 3/3] dt-bindings: hwmon: add sht3x devicetree binding Date: Mon, 26 Jun 2023 15:29:23 +0800 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230626072923.340544-1-JuenKit_Yip@hotmail.com> References: <20230626072923.340544-1-JuenKit_Yip@hotmail.com> X-TMN: [6yPhPoc4Dq5X9ZAqiDulGJ/CWar5OvZj] X-ClientProxiedBy: TYCPR01CA0167.jpnprd01.prod.outlook.com (2603:1096:400:2b2::7) To DB4PR10MB6261.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:10:383::21) X-Microsoft-Original-Message-ID: <20230626072923.340544-3-JuenKit_Yip@hotmail.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB4PR10MB6261:EE_|AS8PR10MB7858:EE_ X-MS-Office365-Filtering-Correlation-Id: 2699ffb8-33ba-4492-ea2a-08db76172c62 X-MS-Exchange-SLBlob-MailProps: AZnQBsB9XmoK1BMhJ23Kz5QNzC6tLv1kWwKgcoOJfubRRY38zbChyi0uOr1OVFmSSHEV1/d1rjRWic/3GB/dCF9bBr/WlfcVIwddPvBgY9xMwmtPZR7SK7SECbNbYHbJC7RL14iYx5F1CIyIMloJEX1mtGdrzDrDXRs1ggRUbAkZ3E0l8m6Js3jYyY/ToUvmj9QwvFma/I4v1pLEd5ltGECW5lVSy6Jlyn4ERNsXCY4I5KuNrAh2M6mV+SJS46qdvIJsV66nAqndOABPfjTooqeryFHh7iaQARxYhJ4Oi3vA499H+6Z2L9rVc7FexPie9/QnRCgSdiffI8ssMU6QHAhvCNVoE/3So+vhsN8q3cv5qn1WIzyV9OIdEa+t2q+CJIiPQBJyf30cMjGlujq93Vr9nFwNHRBjOM71KP0qRI0yvxDxHy5ZKn+zSVIcCBJq6UhOHNs+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ePIcBMqnt5j+GoJfMG9QLKs9VsuoDumqcG6Ib+2PcI2Xjr3TKauNupUNsw5b8zETh4ewJC+n52a7VWvOpTlFhKT5bvRfBCu+hIMW7eUS7wloHcrTeygMYaWbYw/TV9dg2BK3wUYzLHd8Q1lirfCI4wWFjXBG/utp/+rfdYaZgB/0BwEn5AjTVh7ebNK8Vxywk= X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-6b909.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: 2699ffb8-33ba-4492-ea2a-08db76172c62 X-MS-Exchange-CrossTenant-AuthSource: DB4PR10MB6261.EURPRD10.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jun 2023 07:30:10.5842 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR10MB7858 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org From: JuenKit Yip add sht3x devicetree binding files Signed-off-by: JuenKit Yip --- v1: - fix semantics error .../bindings/hwmon/sensirion,sht3x.yaml | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Documentation/devicetree/bindings/hwmon/sensirion,sht3x.yaml diff --git a/Documentation/devicetree/bindings/hwmon/sensirion,sht3x.yaml b/Documentation/devicetree/bindings/hwmon/sensirion,sht3x.yaml new file mode 100644 index 000000000000..71a50bd57af2 --- /dev/null +++ b/Documentation/devicetree/bindings/hwmon/sensirion,sht3x.yaml @@ -0,0 +1,35 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/hwmon/sensirion,sht3x.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Sensirion SHT3x-DIS humidity and temperature sensor + +maintainers: + - JuenKit Yip + +properties: + compatible: + enum: + - sensirion,sht3x + - sensirion,sts3x + reg: + maxItems: 1 + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + sensor@4a { + compatible = "sensirion,sht3x"; + reg = <0x4a>; + }; + };