From patchwork Mon Jul 3 14:08:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: JuenKit Yip X-Patchwork-Id: 13300180 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 DB7B8EB64DD for ; Mon, 3 Jul 2023 14:09:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230134AbjGCOJB (ORCPT ); Mon, 3 Jul 2023 10:09:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230467AbjGCOIz (ORCPT ); Mon, 3 Jul 2023 10:08:55 -0400 Received: from EUR02-DB5-obe.outbound.protection.outlook.com (mail-db5eur02olkn2022.outbound.protection.outlook.com [40.92.50.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10C93E51; Mon, 3 Jul 2023 07:08:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nw9zEjyoZgY40sNNpMcOuKi3chnUdBr72aCIZ0w6z68kASMFoNleMcFwiYuY8GBSwYJ5PlZT5UHhf20RK4TO74J5/yDp9HyhS2o5bnGKhfdoLfl7S859+2VAcQ7UkMmUuIE85l7DC8Pjs4H8mVuZBeU+x7nz2GMSR2Dlo5DUdrXAGDkwDoPyVmlnwv0qQbA1y1KG4EnTQHrd19U57i1wTD60PMSpjueysk4AYctJKam2tZkbnQupqTvIbaIU9WhhBm3yZPj/qk8GCdazwP1OJKAiUGqvk2KLSl2JkXqeNqGW2O3m4xpt35qgti9DEKMJW9Kes4gkusNsrdX1J0MCNA== 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=MH4UASRDqFQ9DY4me5+MmlBWpQR4CnGo1y5RsW1RbPM=; b=hB/oXOuT5Gwhe04daBTOKot4NPMk8XHJm9DbhwXF34cj4FSJJu4kp8qwBNJKNc72lz8iWcVsA6V+qGe5LNtXuzhe/+ZFPRQE8hEe+qULKZQ0bhz8acc0DhVE1hl+3wHkQ87r1tPuoV75h8NRHd2Md9ypxbSqFdsb+GsBDki7SEKrKn4htMxbX453bNhDp0447kgK9xcC4hJzunZDH6QlnlCYsojxpExJAXX4BvB1xGpo9a/PTea5+W4GkL9LzertyZJfcU/8D1er62gEY5xG244Fps2zqPvZ0Az38J+BWuPsvYyWl0AnND6mIHbDkIFn3RuYnJh2OTfjO9XKUs/xcQ== 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=MH4UASRDqFQ9DY4me5+MmlBWpQR4CnGo1y5RsW1RbPM=; b=mZrnG7u6Jz7FBaTm9hVfvo1c7jGxar3l6Ly9Hp3S7JJKGJ5ezjFTK7cJtIpsPn0hyBXzYug4AFmG98N5O2JGd0C1ejKxlGTUZy9XoQsHYeOQdirx5N9jES7v5x/v6SmrmZO6M7qZcbC88MrP8n1jQfqURH9R87MsvPNHTFGTENqbWQ1kYAINpfx/+4hdxKG8WvcQXibJBA4GeZvPbc5LgMgqJ4KwZlpPJkGGEr59AnBLbPSPKSZL9Aw3cat/rA5cQnzCy/5rz8V3D1D/TDXFeaEZioIkO/Va8lvnX55n45jFSzD77TExgJbpkheKEwB39zIk7jm76lH/dyFsqX8DwQ== Received: from DB4PR10MB6261.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:10:383::21) by AM7PR10MB3891.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:178::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6544.24; Mon, 3 Jul 2023 14:08:48 +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.6544.024; Mon, 3 Jul 2023 14:08:48 +0000 From: JuenKit Yip To: jdelvare@suse.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, linux@roeck-us.net Cc: linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, JuenKit Yip Subject: [PATCH v3 1/3] hwmon: (sht3x) convert some of sysfs interface to hwmon Date: Mon, 3 Jul 2023 22:08:16 +0800 Message-ID: X-Mailer: git-send-email 2.39.2 X-TMN: [Eom2vxoQ2KQuIEMUiHlIZXI4g4Omz3SMU2pFpx/rb0cjb/AJGlGt0HcnfTZG/hYA] X-ClientProxiedBy: TYCP286CA0023.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:263::10) To DB4PR10MB6261.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:10:383::21) X-Microsoft-Original-Message-ID: <20230703140818.427403-1-JuenKit_Yip@hotmail.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB4PR10MB6261:EE_|AM7PR10MB3891:EE_ X-MS-Office365-Filtering-Correlation-Id: 85099b45-f119-44f1-b59c-08db7bcf0507 X-MS-Exchange-SLBlob-MailProps: AZnQBsB9XmqqpqVHbY8r+bVyFie8RCx7QcXdaLZxSqgR1+KYztYDyaucLvnC5WTizlrL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RCpSudMpDYVGqD717cSPseEY3VMq1z/l9zoln5k+Kh3iAbAGFz8FDcCLVlQO7Rq3mRIUK6sfuhG7mHIAZ+/OG1p9rr5ovG6K8tuK/svMkmn1/YttGg4dVLlaPx3CX/9c4xuHGPUHGb9nS3lusqJlBhF5k3VYlSloKRQL1N4NT9+l97+8GlDK01l1moA/0Zf3ifErsprQ+gheKXhmBEStVaaxfBBkXO6xhyIOqOSxRk/qFiQe/k4yhZQRzMThJrBL0TyVOpA5jGcOre5ZK5+iCcrXAnnuOO0fqBz4Kpxv+0DfdfRNen63Hlb9y6wgQh27wWi7Hyw3c7shPlYYwEJK5eLOnmlfqWDQTripXN1eAiVcFBykdgQc7BhmYRdU/Os7C6B2gYWyRnmiMvYAFiFe2FGEiWcv72NH9HeyreChBERLMN3HZGk3bx/5a2qKyIV2VuA0A4DA0rI8Xsb+2XFyC+iga4u96sPxsPM5Sm7EqLrxfLz0Ik1jLdrGYV7mx6gGxzID10aifPMRAwnWBoz9sMH6XCVftMdAG0nqAwxr7X9uEIpa8ukzZAkcc4VZzsMJJGkvwyLTZNJ3l+2418J5b1kuF3o9Kl81M4= X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-6b909.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: 85099b45-f119-44f1-b59c-08db7bcf0507 X-MS-Exchange-CrossTenant-AuthSource: DB4PR10MB6261.EURPRD10.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jul 2023 14:08:48.3792 (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: AM7PR10MB3891 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org 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 --- v2: - remove forward declearation - fix switch statement about "return 0" and "break" for consistency - convert type of "val" from string to numeric value - store chip type in struct sht3x_data v3: - restore original documention of sht3x - fix xxx_write prototype drivers/hwmon/sht3x.c | 387 +++++++++++++++++++++++++++--------------- 1 file changed, 251 insertions(+), 136 deletions(-) diff --git a/drivers/hwmon/sht3x.c b/drivers/hwmon/sht3x.c index bf18630619e0..79657910b79e 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_id; 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 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, int 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_id == 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_id = 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 Jul 3 14:08:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: JuenKit Yip X-Patchwork-Id: 13300181 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 0DCC6C001DB for ; Mon, 3 Jul 2023 14:09:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230429AbjGCOJB (ORCPT ); Mon, 3 Jul 2023 10:09:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230513AbjGCOI6 (ORCPT ); Mon, 3 Jul 2023 10:08:58 -0400 Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01olkn2106.outbound.protection.outlook.com [40.92.65.106]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D67D106; Mon, 3 Jul 2023 07:08:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QuBNbXDTkqDNaQcsC64Z4OKFsov+QoHbu4CDvYoUUqHv+ovEzMqNII4mZmIjChEZcuCIYj1n2S0kcnRjHdmDX+2w6VSBu7gKqrBMTa+2zN5ER7Tqhkydv83pyLim8mtRw8AsD0JY/CVaErrzdeKThHO/r618do9CFoGZh4sZFceYZa1csHqoTWKegS1CWY2NlklIP/7+QVW35vtKvqfdfMh/htTY/Mj5KqmxFb3HNSAlIKWjRQkeMvqzRTcHhLpla31cyl7NviNysuZQ+Rs1369wXJhlYGDB+B6Nd/3AY5G2aHQXVDm0KjTqeN3rljtWIl2b00ECRQkuvG6rqxP5TQ== 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=3o4vrPZZxBA3YbyvZ2e6l7Nv6AYaTFI9R/bVHAHCW90=; b=aQztKHbzUAkm/X9Tl2Ae3z2voarwFNfea8KVUhXxA9sWAiqqNUdQzQA0RvuxlYA3/yegnijWqusP3qW98WQF0QbLyHl0poM50qvmmazQNvzGPWIDSdCLsk106m+LZaWIT9V0v7g5HAwOliDx/fw9MacOT77d7NXY8bKyp2WYEXIsIhsqWKdC+HEV7e3OOW7KCw09+4dcv4wjeVrJ5seohHzspet5pvhxU7CZ3sWKzTBGiSI1FHn5yk3pbsjSq0V/Im8puKtdm40JPzbafuzZAAF08uof5CDTaB2FzfX7Q8KFER2zKn5+lVtENypiymPX0kq1xAr4Pl2W2lkCkDhkwA== 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=3o4vrPZZxBA3YbyvZ2e6l7Nv6AYaTFI9R/bVHAHCW90=; b=gSnhYl2RQta5Pg8JJrca5RwKgzFUnYOX5UbYUbpy5pQg+Dad/74O/d0SZSAVSZnQVRF7Dkx3DZvdOjCTtBQCXBNsqqsIJOpJH5qSL0u0vQyHIpVlGO33SgjRY2+WzigEF3MIlRacqPHYg0aqkriUrapnTQnf9LZUxgSSouFJSN4+R7JyjK26Cmim9dVMitTPt+6V8d3grVrWs+rGkr+uu9U4k+rBD/JJx15JWMynlp+Do1AP261uLhBQ9COCHD8AM+GqPOai1pZCdEwVIU+iPy7QXLX7iHyreq3h27PxWqNn44aEq2CygGEdxl9T8Gf9zFB1026Xu+XAlykdlNao5Q== Received: from DB4PR10MB6261.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:10:383::21) by AM7PR10MB3891.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:178::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6544.24; Mon, 3 Jul 2023 14:08:55 +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.6544.024; Mon, 3 Jul 2023 14:08:55 +0000 From: JuenKit Yip To: jdelvare@suse.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, linux@roeck-us.net Cc: linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, JuenKit Yip Subject: [PATCH v3 2/3] hwmon: (sht3x) add devicetree support Date: Mon, 3 Jul 2023 22:08:17 +0800 Message-ID: X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230703140818.427403-1-JuenKit_Yip@hotmail.com> References: <20230703140818.427403-1-JuenKit_Yip@hotmail.com> X-TMN: [i+9QzgfcsI/Ia8JV328O+M9WodjiKC0G5px+Ko3RhAkveJgS3sbLoNRH0Q6cgMyo] X-ClientProxiedBy: TYCP286CA0023.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:263::10) To DB4PR10MB6261.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:10:383::21) X-Microsoft-Original-Message-ID: <20230703140818.427403-2-JuenKit_Yip@hotmail.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB4PR10MB6261:EE_|AM7PR10MB3891:EE_ X-MS-Office365-Filtering-Correlation-Id: 1f960fe6-1086-4d95-c8db-08db7bcf093a X-MS-Exchange-SLBlob-MailProps: AZnQBsB9XmqqpqVHbY8r+bVyFie8RCx7fvT8zfkaX1SdFMNaZJtY+DXh6UBngZFEZNcSbQInbuCQADIZ9zURatVlL7Nc1HBuKhn5t/RufEmpDs9Ns7npmOgD5h0Ef0V9VHHORwxq3uPmx543zjSjZu7rfQSNVPLJQocravUb19fFLRdW8hKZPffG8xLDl21cNH1XSKvAjOf4REw5Geir99pEAGR2td6vFcxHxUVTo8iJ5J/MchVx45wyF2GMDd/sFlh0ZRpnyQTB7Zj3vGGjCX3OFdbnSSHcbjG/HCfFAzMoXJuOl8UA6SSKj8k2LKDln6K5Rug+9P6qpD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keKveDwor5QGg45XHYB3Y/Biemk35vjC/jLWtcVzseye2Wvnh/3/aJZk8pM+sKZgDIDedMNYuA+FOl/6cJ/LxCddReD7OMiRmI8ZEB7H1gxtH4PdGO9rynYFaSRBt772VauQpMWwEml2gvI1oWZXCmOJsG23yPRVBYZc/Mr9dkzP5NKtU3tljDsbA3Ti88siz5ufleqT2Z6WdTjrXbWDqdd26L7nKndY1hyv0S7KNrrWqPP64BbkBzdA9UP2DN7jwTHFKcNszX9Je/u+zkQx6BWrq4HK5QfG92G8Ny9rNGPn41APibz21q79SFpCdJ0L04CAOJDPe7wINDWMBuYb9XDU= X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-6b909.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: 1f960fe6-1086-4d95-c8db-08db7bcf093a X-MS-Exchange-CrossTenant-AuthSource: DB4PR10MB6261.EURPRD10.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jul 2023 14:08:55.0823 (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: AM7PR10MB3891 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org add "compatible" property for supporting devicetree Signed-off-by: JuenKit Yip --- v3: - fix wildcards problem drivers/hwmon/sht3x.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/sht3x.c b/drivers/hwmon/sht3x.c index 79657910b79e..bb8586233adc 100644 --- a/drivers/hwmon/sht3x.c +++ b/drivers/hwmon/sht3x.c @@ -911,8 +911,23 @@ 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,sht30" }, + { .compatible = "sensirion,sht31" }, + { .compatible = "sensirion,sht35" }, + { .compatible = "sensirion,sts30" }, + { .compatible = "sensirion,sts31" }, + { .compatible = "sensirion,sts35" }, + {}, +}; +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 Jul 3 14:08:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: JuenKit Yip X-Patchwork-Id: 13300182 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 66DF1EB64DC for ; Mon, 3 Jul 2023 14:09:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230041AbjGCOJe (ORCPT ); Mon, 3 Jul 2023 10:09:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230513AbjGCOJF (ORCPT ); Mon, 3 Jul 2023 10:09:05 -0400 Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01olkn2080.outbound.protection.outlook.com [40.92.65.80]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41C5FE51; Mon, 3 Jul 2023 07:09:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ARs+kX7hjJnGqC/ZGQ9sdJLBy/FNjKRHAXzcEycU3FG/1SWtMVHOpqHQQMkS0fkKOsmDtFD6MwNg5oRuhXR+jIWZxBaLUPoZsTB48N3NphL2+VzTk+dxKYNtBOGdvCXiTfYFR7URhGg1CEowGwB9lqlGq5ltP/yMcNKG0q0t0X+itkKKYAb86aruLDmEfxn90D87rezYCyQJn+2MvJEUu3+Rl/0t2K3y/00xkDRYiOXmJrxrFxBEGgZOlLDPDcxAN5zPVE/U0JA1/wTknBT8gvd4+4CeAd3lzmO276J3a86eg3utC/qjZixvQ+jXZyU+GgYr1xuIoKbauhbesAylMw== 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=sv2o6+vjhzW6qaV1JOzkZVGbSpstwXHterdeoFQmHBY=; b=KIG3tfFhBRvMByCYb9wsCoTE1rIT7jKy8eaGCwJVsnfXIjQUb9xwSfl/WkTwxfwrt283IJKtbLkOjJsonT09EOAzdbMk+6Y+tRf3yThqZgWnWrj3JnPfAEqnBdFVlr/1bvauNwXqaL7wL5zItLd+7kA+1JD4mCQEGFGv160SW30MZiWLCPEcTjv+mVLw9ZYW/vIFuIJD1S4sIhjs+7z//akojBt/vEYzIhEhIDWuLbxeB/K5nBeqDsCj+abC8WdJB6djAeFWfZfLJFKGx0lSMdq2lI4H6KGS/6Z8Y/YfBrqosNrJdUTEAiT8OFfsoLR/NzBzMhcLLnbDDDOHAhx+hA== 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=sv2o6+vjhzW6qaV1JOzkZVGbSpstwXHterdeoFQmHBY=; b=bxhS3yAZ3wr1lOqfgpDSArdVYcv0ZE3Nv6AU+MDGylJ+J0kGE1wjbs5AbJ0m4kVGA/skncshv/5xPgtey/05QkH7FvQTNlOOSvw9bcQXr3XHchyD5MIjCOtqsnbh4GKyRWIZNfQYn6v39i+JXHbz14igGoaX6gdEkLZmpwO0RtQ8UazeeA5Vwo+4lZ0XXADPUpPTmAkwWQXW3lkqfdyBY3YDTTCmeigvhtq61BuzCeBz/zSClcW4rYbU/IQtC/OiwPjkbvNc6CT9EH85MoYti2kZ/jnTEOZWSjphicjJ3DfvcKLIhukuGFjGV4mCRG5lwmt8GUnLcnOmEJBhVtDB3g== Received: from DB4PR10MB6261.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:10:383::21) by AM7PR10MB3891.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:178::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6544.24; Mon, 3 Jul 2023 14:09:02 +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.6544.024; Mon, 3 Jul 2023 14:09:02 +0000 From: JuenKit Yip To: jdelvare@suse.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, linux@roeck-us.net Cc: linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, JuenKit Yip Subject: [PATCH v3 3/3] dt-bindings: hwmon: add sht3x devicetree binding Date: Mon, 3 Jul 2023 22:08:18 +0800 Message-ID: X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230703140818.427403-1-JuenKit_Yip@hotmail.com> References: <20230703140818.427403-1-JuenKit_Yip@hotmail.com> X-TMN: [/ddmm/QR9sWj20GwZqie23rmJjUZLKm8Ob13MgHFT2xvFEa++P8AjNrO/8KP5INA] X-ClientProxiedBy: TYCP286CA0023.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:263::10) To DB4PR10MB6261.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:10:383::21) X-Microsoft-Original-Message-ID: <20230703140818.427403-3-JuenKit_Yip@hotmail.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB4PR10MB6261:EE_|AM7PR10MB3891:EE_ X-MS-Office365-Filtering-Correlation-Id: 85df2f39-12c2-4ab5-cc1e-08db7bcf0d5a X-MS-Exchange-SLBlob-MailProps: ZILSnhm0P3kEq9VXjGDAytWtg2idpaP2lvHrdBLMU6TPg+DoSr/BcBlxSPh5WIeSeH35jKzbkThEp+MqXj043GmRiXAmQODqd3AVcHk3dKMXsAPid2lH5qsekcZD8zl5C8RpLHhdBK48LyXcZ6ndMBPw0jJ0397tDRAmR786zDcKMvqGRz0qtf2587LycTmcWDi81oAppSXR6Bt4dsIYy53ZkYghhjSh7ttuGXI8aUInFXc01fyWPZGAjmLPdy6RwyhqjIvsF6KtlH4iO4FEUkWKW67FvLCDyBNApS+v8BT4KnvILDVbdwVcPCIbUCF5uLBcxzLSF/eTSnF8iaiHMT4orl3Z48obYpZDjbBQsXvlnC51W9Zk/fIYvViyvGYHrq6YkeH2Mk3aBjFJIxg8PhukdMIYH6S+5gz6873XRpIV8LZTtg8vA6zGGpYh+5gOi3fmT0nMFP5Ii0nrqo3HBYe91g6upyN7QZ0doKbqdtaQuuqNgnv/l4Zs6/yeoQ4wO99BolRydXuKJSaLYK8HOSwmYoMOAKzzlX43W/72QRk41uS+vef+mSD0igMReOz/H9kgtybUgwbM5Q3RjWfW8Vewuf1mV7HDrUoiTGKmGOOmpDSe5Fo9KBYTu5Xa6HqU/mYmzSlg1ZuHA8S/iAWByrwN/vxYMFpcI0EJChVe4nwh/GyMZCGuiQi3Ck33fXx1OEtPIZsKklmYzN5DVhWLIE9wZcPnsTW3YeQrZN/ZJ0jT6H9tA3YYE6U02PxsFbLPQJBGD8+WD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6b909.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: 85df2f39-12c2-4ab5-cc1e-08db7bcf0d5a X-MS-Exchange-CrossTenant-AuthSource: DB4PR10MB6261.EURPRD10.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jul 2023 14:09:01.9962 (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: AM7PR10MB3891 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org add sht3x devicetree binding files Signed-off-by: JuenKit Yip --- v3: - fix wildcards problem - add vdd-supply property .../bindings/hwmon/sensirion,sht3x.yaml | 45 +++++++++++++++++++ 1 file changed, 45 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..bef2eb492a47 --- /dev/null +++ b/Documentation/devicetree/bindings/hwmon/sensirion,sht3x.yaml @@ -0,0 +1,45 @@ +# 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,sht30 + - sensirion,sht31 + - sensirion,sht35 + - sensirion,sts30 + - sensirion,sts31 + - sensirion,sts35 + + reg: + maxItems: 1 + + vdd-supply: + description: regulator that drives the VDD pin + +required: + - compatible + - reg + - vdd-supply + +additionalProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + sensor@4a { + compatible = "sensirion,sht31"; + reg = <0x4a>; + vdd-supply = <®_sht31>; + }; + };