From patchwork Thu Jan 5 14:19:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 39607 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp324365wrt; Thu, 5 Jan 2023 06:22:42 -0800 (PST) X-Google-Smtp-Source: AMrXdXvx6R3Lk2pL7zgaj6sVILsknNK0RXEJ5CG1kF9UR/J+dzN2qbVYYTuWXcQDkMHgMinIAdUg X-Received: by 2002:a17:902:f789:b0:192:ac33:7f91 with SMTP id q9-20020a170902f78900b00192ac337f91mr24206250pln.69.1672928562683; Thu, 05 Jan 2023 06:22:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672928562; cv=none; d=google.com; s=arc-20160816; b=UuS98NAfCtfG4jend6xUxjLAumWE+D1ngz6WLdDITNqd7UzGWF9ZFXvDEe8Smpy4l+ JMj55IPGgirtDzwXLtOKkbv6w2R4MleUcpJTX+XmkQnRjjCtlTkMyobU7RG4tz0okO1x 3Ezp/YUa/FEi2b+48VRyKlcOnHfK+m4yqbx4MlhrSeu95NUevePy7SInYUQTqKg/aX8v o74CnDa1F0uLjwk8ZEo+OW67AgD/NNIZhGhjUeeUScW5XafrsngAw1efnR+EcK5scI+M Lg5hOPWYbIhAVCjwiVGeIZgGDmfWAygov0CIGBTTJm0kaLMcBT0BbOooRF3HUgQPh4AL JQgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:ui-outboundreport:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=9kfRYYA0GuAq8qojKEdA5Nt2Co4buhUoG+Cp8Sau0Ik=; b=oRG7TciZhNjV5Ih55zGUA6dsTpJHa8tfPMuGhETHWwRYGxEyIX07DlhzQFgROzx1fV eavxH1yV4DO8cxEdOHj8AcTn+xfatE8QGecI9wwPU1jzViEhYIvySrdQkXeqO56lV8WY hhll9bV42GYgFC9RcLA875wpCNO/hVxngT/OKakQ7tzbDIc385nmtxVSyQ/xpvNd9KNa 2cvfK9uFpobB6vR8BuFjasKzUc8W7XFaRpbVfTtKTYOqGQzWD1IwnHgwiTKIcmfYqbw1 VfaZT40wmOMSsJmSHDUddywlhFW5MgQXWgYImWv3E6zfleMw4JCH8Ryp5mbIA3fPw+Mj pOlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=ggYfmxDM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t15-20020a170902e84f00b001898558457dsi39609110plg.123.2023.01.05.06.22.28; Thu, 05 Jan 2023 06:22:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=ggYfmxDM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231977AbjAEOTl (ORCPT + 99 others); Thu, 5 Jan 2023 09:19:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231361AbjAEOTi (ORCPT ); Thu, 5 Jan 2023 09:19:38 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78E2758304; Thu, 5 Jan 2023 06:19:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1672928360; bh=sF0cbtH+Hcn4OuIpkhZqzOz2WGnt+KmjYTWFjzqfdRs=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=ggYfmxDM03lw7Ry05tptwEBwMNfaLjJmWiZFeC8KAnq/p9ai4pW+Z5j8qlXi8dNrJ x1xkQ10C0hCDtQ6bmJMWcb61TLWkvW67YdpiXuwlVbIiGkNruVwz+DRrBOzxMWHxgB +Wn4KHUUHqcxpR76S9GpN5VWJBtSzQmF/9JThzbFy8VtArLsuZF0HJ4utHAo3tbbCB 29+8bye5G/eUaudpGVLjryWnuitX/x5PJQvcYyCVDkGY8S+8/GM5fGA/rrvcF1KiN/ Pj3sOnEbaWWfuUGd2zne72wwIgCHRzOVoh3dnJMIxw+C5j32P6BaDvWBVldOEXmfop q+02o2dE9kdPg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from esprimo-mx.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MD9X9-1p4wlF0eQr-009C2T; Thu, 05 Jan 2023 15:19:20 +0100 From: Armin Wolf To: jdelvare@suse.com, linux@roeck-us.net Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] hwmon: (ftsteutates) Convert to devm_hwmon_device_register_with_info() Date: Thu, 5 Jan 2023 15:19:09 +0100 Message-Id: <20230105141911.8040-2-W_Armin@gmx.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230105141911.8040-1-W_Armin@gmx.de> References: <20230105141911.8040-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:5zTmEGuu8GHGoD61c4NVRlPS50VVc/c2KL1Y1sLq39drIJ0cC9p 8pgv2h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xX6TaLHGXDN7rMkbc6 GeARyf+c5fAFhAA4+pxFvNuazq1hl4AzcKeR42hybLXyGRkUKXAZulFJKogkSXrmAJs0fynRC MlnXZq/gQNvBiNfdyIGBOn/6S/M= X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754192740342394003?= X-GMAIL-MSGID: =?utf-8?q?1754192740342394003?= Convert driver to use devm_hwmon_device_register_with_info() to reduce module size by ~30%. Tested on a Fujitsu DS3401-B1. Signed-off-by: Armin Wolf --- drivers/hwmon/ftsteutates.c | 532 ++++++++++++++---------------------- 1 file changed, 204 insertions(+), 328 deletions(-) -- 2.30.2 diff --git a/drivers/hwmon/ftsteutates.c b/drivers/hwmon/ftsteutates.c index e860924f90aa..23dc3a74f84b 100644 --- a/drivers/hwmon/ftsteutates.c +++ b/drivers/hwmon/ftsteutates.c @@ -17,7 +17,6 @@ #include #include #include -#include #include #define FTS_DEVICE_ID_REG 0x0000 @@ -340,376 +339,255 @@ static int fts_watchdog_init(struct fts_data *data) return devm_watchdog_register_device(&data->client->dev, &data->wdd); } -/*****************************************************************************/ -/* SysFS handler functions */ -/*****************************************************************************/ -static ssize_t in_value_show(struct device *dev, - struct device_attribute *devattr, char *buf) -{ - struct fts_data *data = dev_get_drvdata(dev); - int index = to_sensor_dev_attr(devattr)->index; - int value, err; - - err = fts_update_device(data); - if (err < 0) - return err; - - value = DIV_ROUND_CLOSEST(data->volt[index] * 3300, 255); - - return sprintf(buf, "%d\n", value); -} - -static ssize_t temp_value_show(struct device *dev, +static ssize_t fan_source_show(struct device *dev, struct device_attribute *devattr, char *buf) { struct fts_data *data = dev_get_drvdata(dev); int index = to_sensor_dev_attr(devattr)->index; - int value, err; + int err; err = fts_update_device(data); if (err < 0) return err; - value = (data->temp_input[index] - 64) * 1000; - - return sprintf(buf, "%d\n", value); + return sprintf(buf, "%u\n", data->fan_source[index]); } -static ssize_t temp_fault_show(struct device *dev, - struct device_attribute *devattr, char *buf) -{ - struct fts_data *data = dev_get_drvdata(dev); - int index = to_sensor_dev_attr(devattr)->index; - int err; +static SENSOR_DEVICE_ATTR_RO(fan1_source, fan_source, 0); +static SENSOR_DEVICE_ATTR_RO(fan2_source, fan_source, 1); +static SENSOR_DEVICE_ATTR_RO(fan3_source, fan_source, 2); +static SENSOR_DEVICE_ATTR_RO(fan4_source, fan_source, 3); +static SENSOR_DEVICE_ATTR_RO(fan5_source, fan_source, 4); +static SENSOR_DEVICE_ATTR_RO(fan6_source, fan_source, 5); +static SENSOR_DEVICE_ATTR_RO(fan7_source, fan_source, 6); +static SENSOR_DEVICE_ATTR_RO(fan8_source, fan_source, 7); - err = fts_update_device(data); - if (err < 0) - return err; +static struct attribute *fts_fan_attrs[] = { + &sensor_dev_attr_fan1_source.dev_attr.attr, + &sensor_dev_attr_fan2_source.dev_attr.attr, + &sensor_dev_attr_fan3_source.dev_attr.attr, + &sensor_dev_attr_fan4_source.dev_attr.attr, + &sensor_dev_attr_fan5_source.dev_attr.attr, + &sensor_dev_attr_fan6_source.dev_attr.attr, + &sensor_dev_attr_fan7_source.dev_attr.attr, + &sensor_dev_attr_fan8_source.dev_attr.attr, + NULL +}; - /* 00h Temperature = Sensor Error */ - return sprintf(buf, "%d\n", data->temp_input[index] == 0); -} +static const struct attribute_group fts_attr_group = { + .attrs = fts_fan_attrs +}; -static ssize_t temp_alarm_show(struct device *dev, - struct device_attribute *devattr, char *buf) -{ - struct fts_data *data = dev_get_drvdata(dev); - int index = to_sensor_dev_attr(devattr)->index; - int err; +static const struct attribute_group *fts_attr_groups[] = { + &fts_attr_group, + NULL +}; - err = fts_update_device(data); - if (err < 0) - return err; +static umode_t fts_is_visible(const void *devdata, enum hwmon_sensor_types type, u32 attr, + int channel) +{ + switch (type) { + case hwmon_temp: + switch (attr) { + case hwmon_temp_input: + case hwmon_temp_fault: + return 0444; + case hwmon_temp_alarm: + return 0644; + default: + break; + } + break; + case hwmon_fan: + switch (attr) { + case hwmon_fan_input: + return 0444; + case hwmon_fan_alarm: + return 0644; + default: + break; + } + break; + case hwmon_in: + return 0444; + default: + break; + } - return sprintf(buf, "%u\n", !!(data->temp_alarm & BIT(index))); + return 0; } -static ssize_t -temp_alarm_store(struct device *dev, struct device_attribute *devattr, - const char *buf, size_t count) +static int fts_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel, + long *val) { struct fts_data *data = dev_get_drvdata(dev); - int index = to_sensor_dev_attr(devattr)->index; - long ret; + int ret = fts_update_device(data); - ret = fts_update_device(data); if (ret < 0) return ret; - if (kstrtoul(buf, 10, &ret) || ret != 0) - return -EINVAL; - - mutex_lock(&data->update_lock); - ret = fts_read_byte(data->client, FTS_REG_TEMP_CONTROL(index)); - if (ret < 0) - goto error; - - ret = fts_write_byte(data->client, FTS_REG_TEMP_CONTROL(index), - ret | 0x1); - if (ret < 0) - goto error; - - data->valid = false; - ret = count; -error: - mutex_unlock(&data->update_lock); - return ret; -} - -static ssize_t fan_value_show(struct device *dev, - struct device_attribute *devattr, char *buf) -{ - struct fts_data *data = dev_get_drvdata(dev); - int index = to_sensor_dev_attr(devattr)->index; - int value, err; - - err = fts_update_device(data); - if (err < 0) - return err; - - value = data->fan_input[index] * 60; + switch (type) { + case hwmon_temp: + switch (attr) { + case hwmon_temp_input: + *val = (data->temp_input[channel] - 64) * 1000; - return sprintf(buf, "%d\n", value); -} + return 0; + case hwmon_temp_alarm: + *val = !!(data->temp_alarm & BIT(channel)); -static ssize_t fan_source_show(struct device *dev, - struct device_attribute *devattr, char *buf) -{ - struct fts_data *data = dev_get_drvdata(dev); - int index = to_sensor_dev_attr(devattr)->index; - int err; + return 0; + case hwmon_temp_fault: + /* 00h Temperature = Sensor Error */; + *val = (data->temp_input[channel] == 0); - err = fts_update_device(data); - if (err < 0) - return err; + return 0; + default: + break; + } + break; + case hwmon_fan: + switch (attr) { + case hwmon_fan_input: + *val = data->fan_input[channel] * 60; - return sprintf(buf, "%u\n", data->fan_source[index]); -} + return 0; + case hwmon_fan_alarm: + *val = !!(data->fan_alarm & BIT(channel)); -static ssize_t fan_alarm_show(struct device *dev, - struct device_attribute *devattr, char *buf) -{ - struct fts_data *data = dev_get_drvdata(dev); - int index = to_sensor_dev_attr(devattr)->index; - int err; + return 0; + default: + break; + } + break; + case hwmon_in: + switch (attr) { + case hwmon_in_input: + *val = DIV_ROUND_CLOSEST(data->volt[channel] * 3300, 255); - err = fts_update_device(data); - if (err < 0) - return err; + return 0; + default: + break; + } + break; + default: + break; + } - return sprintf(buf, "%d\n", !!(data->fan_alarm & BIT(index))); + return -EOPNOTSUPP; } -static ssize_t -fan_alarm_store(struct device *dev, struct device_attribute *devattr, - const char *buf, size_t count) +static int fts_write(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel, + long val) { struct fts_data *data = dev_get_drvdata(dev); - int index = to_sensor_dev_attr(devattr)->index; - long ret; + int ret = fts_update_device(data); - ret = fts_update_device(data); if (ret < 0) return ret; - if (kstrtoul(buf, 10, &ret) || ret != 0) - return -EINVAL; - - mutex_lock(&data->update_lock); - ret = fts_read_byte(data->client, FTS_REG_FAN_CONTROL(index)); - if (ret < 0) - goto error; - - ret = fts_write_byte(data->client, FTS_REG_FAN_CONTROL(index), - ret | 0x1); - if (ret < 0) - goto error; + switch (type) { + case hwmon_temp: + switch (attr) { + case hwmon_temp_alarm: + if (val) + return -EINVAL; + + mutex_lock(&data->update_lock); + ret = fts_read_byte(data->client, FTS_REG_TEMP_CONTROL(channel)); + if (ret >= 0) + ret = fts_write_byte(data->client, FTS_REG_TEMP_CONTROL(channel), + ret | 0x1); + if (ret >= 0) + data->valid = false; + + mutex_unlock(&data->update_lock); + if (ret < 0) + return ret; + + return 0; + default: + break; + } + break; + case hwmon_fan: + switch (attr) { + case hwmon_fan_alarm: + if (val) + return -EINVAL; + + mutex_lock(&data->update_lock); + ret = fts_read_byte(data->client, FTS_REG_FAN_CONTROL(channel)); + if (ret >= 0) + ret = fts_write_byte(data->client, FTS_REG_FAN_CONTROL(channel), + ret | 0x1); + if (ret >= 0) + data->valid = false; + + mutex_unlock(&data->update_lock); + if (ret < 0) + return ret; + + return 0; + default: + break; + } + break; + default: + break; + } - data->valid = false; - ret = count; -error: - mutex_unlock(&data->update_lock); - return ret; + return -EOPNOTSUPP; } -/*****************************************************************************/ -/* SysFS structs */ -/*****************************************************************************/ - -/* Temperature sensors */ -static SENSOR_DEVICE_ATTR_RO(temp1_input, temp_value, 0); -static SENSOR_DEVICE_ATTR_RO(temp2_input, temp_value, 1); -static SENSOR_DEVICE_ATTR_RO(temp3_input, temp_value, 2); -static SENSOR_DEVICE_ATTR_RO(temp4_input, temp_value, 3); -static SENSOR_DEVICE_ATTR_RO(temp5_input, temp_value, 4); -static SENSOR_DEVICE_ATTR_RO(temp6_input, temp_value, 5); -static SENSOR_DEVICE_ATTR_RO(temp7_input, temp_value, 6); -static SENSOR_DEVICE_ATTR_RO(temp8_input, temp_value, 7); -static SENSOR_DEVICE_ATTR_RO(temp9_input, temp_value, 8); -static SENSOR_DEVICE_ATTR_RO(temp10_input, temp_value, 9); -static SENSOR_DEVICE_ATTR_RO(temp11_input, temp_value, 10); -static SENSOR_DEVICE_ATTR_RO(temp12_input, temp_value, 11); -static SENSOR_DEVICE_ATTR_RO(temp13_input, temp_value, 12); -static SENSOR_DEVICE_ATTR_RO(temp14_input, temp_value, 13); -static SENSOR_DEVICE_ATTR_RO(temp15_input, temp_value, 14); -static SENSOR_DEVICE_ATTR_RO(temp16_input, temp_value, 15); - -static SENSOR_DEVICE_ATTR_RO(temp1_fault, temp_fault, 0); -static SENSOR_DEVICE_ATTR_RO(temp2_fault, temp_fault, 1); -static SENSOR_DEVICE_ATTR_RO(temp3_fault, temp_fault, 2); -static SENSOR_DEVICE_ATTR_RO(temp4_fault, temp_fault, 3); -static SENSOR_DEVICE_ATTR_RO(temp5_fault, temp_fault, 4); -static SENSOR_DEVICE_ATTR_RO(temp6_fault, temp_fault, 5); -static SENSOR_DEVICE_ATTR_RO(temp7_fault, temp_fault, 6); -static SENSOR_DEVICE_ATTR_RO(temp8_fault, temp_fault, 7); -static SENSOR_DEVICE_ATTR_RO(temp9_fault, temp_fault, 8); -static SENSOR_DEVICE_ATTR_RO(temp10_fault, temp_fault, 9); -static SENSOR_DEVICE_ATTR_RO(temp11_fault, temp_fault, 10); -static SENSOR_DEVICE_ATTR_RO(temp12_fault, temp_fault, 11); -static SENSOR_DEVICE_ATTR_RO(temp13_fault, temp_fault, 12); -static SENSOR_DEVICE_ATTR_RO(temp14_fault, temp_fault, 13); -static SENSOR_DEVICE_ATTR_RO(temp15_fault, temp_fault, 14); -static SENSOR_DEVICE_ATTR_RO(temp16_fault, temp_fault, 15); - -static SENSOR_DEVICE_ATTR_RW(temp1_alarm, temp_alarm, 0); -static SENSOR_DEVICE_ATTR_RW(temp2_alarm, temp_alarm, 1); -static SENSOR_DEVICE_ATTR_RW(temp3_alarm, temp_alarm, 2); -static SENSOR_DEVICE_ATTR_RW(temp4_alarm, temp_alarm, 3); -static SENSOR_DEVICE_ATTR_RW(temp5_alarm, temp_alarm, 4); -static SENSOR_DEVICE_ATTR_RW(temp6_alarm, temp_alarm, 5); -static SENSOR_DEVICE_ATTR_RW(temp7_alarm, temp_alarm, 6); -static SENSOR_DEVICE_ATTR_RW(temp8_alarm, temp_alarm, 7); -static SENSOR_DEVICE_ATTR_RW(temp9_alarm, temp_alarm, 8); -static SENSOR_DEVICE_ATTR_RW(temp10_alarm, temp_alarm, 9); -static SENSOR_DEVICE_ATTR_RW(temp11_alarm, temp_alarm, 10); -static SENSOR_DEVICE_ATTR_RW(temp12_alarm, temp_alarm, 11); -static SENSOR_DEVICE_ATTR_RW(temp13_alarm, temp_alarm, 12); -static SENSOR_DEVICE_ATTR_RW(temp14_alarm, temp_alarm, 13); -static SENSOR_DEVICE_ATTR_RW(temp15_alarm, temp_alarm, 14); -static SENSOR_DEVICE_ATTR_RW(temp16_alarm, temp_alarm, 15); - -static struct attribute *fts_temp_attrs[] = { - &sensor_dev_attr_temp1_input.dev_attr.attr, - &sensor_dev_attr_temp2_input.dev_attr.attr, - &sensor_dev_attr_temp3_input.dev_attr.attr, - &sensor_dev_attr_temp4_input.dev_attr.attr, - &sensor_dev_attr_temp5_input.dev_attr.attr, - &sensor_dev_attr_temp6_input.dev_attr.attr, - &sensor_dev_attr_temp7_input.dev_attr.attr, - &sensor_dev_attr_temp8_input.dev_attr.attr, - &sensor_dev_attr_temp9_input.dev_attr.attr, - &sensor_dev_attr_temp10_input.dev_attr.attr, - &sensor_dev_attr_temp11_input.dev_attr.attr, - &sensor_dev_attr_temp12_input.dev_attr.attr, - &sensor_dev_attr_temp13_input.dev_attr.attr, - &sensor_dev_attr_temp14_input.dev_attr.attr, - &sensor_dev_attr_temp15_input.dev_attr.attr, - &sensor_dev_attr_temp16_input.dev_attr.attr, - - &sensor_dev_attr_temp1_fault.dev_attr.attr, - &sensor_dev_attr_temp2_fault.dev_attr.attr, - &sensor_dev_attr_temp3_fault.dev_attr.attr, - &sensor_dev_attr_temp4_fault.dev_attr.attr, - &sensor_dev_attr_temp5_fault.dev_attr.attr, - &sensor_dev_attr_temp6_fault.dev_attr.attr, - &sensor_dev_attr_temp7_fault.dev_attr.attr, - &sensor_dev_attr_temp8_fault.dev_attr.attr, - &sensor_dev_attr_temp9_fault.dev_attr.attr, - &sensor_dev_attr_temp10_fault.dev_attr.attr, - &sensor_dev_attr_temp11_fault.dev_attr.attr, - &sensor_dev_attr_temp12_fault.dev_attr.attr, - &sensor_dev_attr_temp13_fault.dev_attr.attr, - &sensor_dev_attr_temp14_fault.dev_attr.attr, - &sensor_dev_attr_temp15_fault.dev_attr.attr, - &sensor_dev_attr_temp16_fault.dev_attr.attr, - - &sensor_dev_attr_temp1_alarm.dev_attr.attr, - &sensor_dev_attr_temp2_alarm.dev_attr.attr, - &sensor_dev_attr_temp3_alarm.dev_attr.attr, - &sensor_dev_attr_temp4_alarm.dev_attr.attr, - &sensor_dev_attr_temp5_alarm.dev_attr.attr, - &sensor_dev_attr_temp6_alarm.dev_attr.attr, - &sensor_dev_attr_temp7_alarm.dev_attr.attr, - &sensor_dev_attr_temp8_alarm.dev_attr.attr, - &sensor_dev_attr_temp9_alarm.dev_attr.attr, - &sensor_dev_attr_temp10_alarm.dev_attr.attr, - &sensor_dev_attr_temp11_alarm.dev_attr.attr, - &sensor_dev_attr_temp12_alarm.dev_attr.attr, - &sensor_dev_attr_temp13_alarm.dev_attr.attr, - &sensor_dev_attr_temp14_alarm.dev_attr.attr, - &sensor_dev_attr_temp15_alarm.dev_attr.attr, - &sensor_dev_attr_temp16_alarm.dev_attr.attr, - NULL +static const struct hwmon_ops fts_ops = { + .is_visible = fts_is_visible, + .read = fts_read, + .write = fts_write, }; -/* Fans */ -static SENSOR_DEVICE_ATTR_RO(fan1_input, fan_value, 0); -static SENSOR_DEVICE_ATTR_RO(fan2_input, fan_value, 1); -static SENSOR_DEVICE_ATTR_RO(fan3_input, fan_value, 2); -static SENSOR_DEVICE_ATTR_RO(fan4_input, fan_value, 3); -static SENSOR_DEVICE_ATTR_RO(fan5_input, fan_value, 4); -static SENSOR_DEVICE_ATTR_RO(fan6_input, fan_value, 5); -static SENSOR_DEVICE_ATTR_RO(fan7_input, fan_value, 6); -static SENSOR_DEVICE_ATTR_RO(fan8_input, fan_value, 7); - -static SENSOR_DEVICE_ATTR_RO(fan1_source, fan_source, 0); -static SENSOR_DEVICE_ATTR_RO(fan2_source, fan_source, 1); -static SENSOR_DEVICE_ATTR_RO(fan3_source, fan_source, 2); -static SENSOR_DEVICE_ATTR_RO(fan4_source, fan_source, 3); -static SENSOR_DEVICE_ATTR_RO(fan5_source, fan_source, 4); -static SENSOR_DEVICE_ATTR_RO(fan6_source, fan_source, 5); -static SENSOR_DEVICE_ATTR_RO(fan7_source, fan_source, 6); -static SENSOR_DEVICE_ATTR_RO(fan8_source, fan_source, 7); - -static SENSOR_DEVICE_ATTR_RW(fan1_alarm, fan_alarm, 0); -static SENSOR_DEVICE_ATTR_RW(fan2_alarm, fan_alarm, 1); -static SENSOR_DEVICE_ATTR_RW(fan3_alarm, fan_alarm, 2); -static SENSOR_DEVICE_ATTR_RW(fan4_alarm, fan_alarm, 3); -static SENSOR_DEVICE_ATTR_RW(fan5_alarm, fan_alarm, 4); -static SENSOR_DEVICE_ATTR_RW(fan6_alarm, fan_alarm, 5); -static SENSOR_DEVICE_ATTR_RW(fan7_alarm, fan_alarm, 6); -static SENSOR_DEVICE_ATTR_RW(fan8_alarm, fan_alarm, 7); - -static struct attribute *fts_fan_attrs[] = { - &sensor_dev_attr_fan1_input.dev_attr.attr, - &sensor_dev_attr_fan2_input.dev_attr.attr, - &sensor_dev_attr_fan3_input.dev_attr.attr, - &sensor_dev_attr_fan4_input.dev_attr.attr, - &sensor_dev_attr_fan5_input.dev_attr.attr, - &sensor_dev_attr_fan6_input.dev_attr.attr, - &sensor_dev_attr_fan7_input.dev_attr.attr, - &sensor_dev_attr_fan8_input.dev_attr.attr, - - &sensor_dev_attr_fan1_source.dev_attr.attr, - &sensor_dev_attr_fan2_source.dev_attr.attr, - &sensor_dev_attr_fan3_source.dev_attr.attr, - &sensor_dev_attr_fan4_source.dev_attr.attr, - &sensor_dev_attr_fan5_source.dev_attr.attr, - &sensor_dev_attr_fan6_source.dev_attr.attr, - &sensor_dev_attr_fan7_source.dev_attr.attr, - &sensor_dev_attr_fan8_source.dev_attr.attr, - - &sensor_dev_attr_fan1_alarm.dev_attr.attr, - &sensor_dev_attr_fan2_alarm.dev_attr.attr, - &sensor_dev_attr_fan3_alarm.dev_attr.attr, - &sensor_dev_attr_fan4_alarm.dev_attr.attr, - &sensor_dev_attr_fan5_alarm.dev_attr.attr, - &sensor_dev_attr_fan6_alarm.dev_attr.attr, - &sensor_dev_attr_fan7_alarm.dev_attr.attr, - &sensor_dev_attr_fan8_alarm.dev_attr.attr, +static const struct hwmon_channel_info *fts_info[] = { + HWMON_CHANNEL_INFO(chip, HWMON_C_REGISTER_TZ), + HWMON_CHANNEL_INFO(temp, + HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_FAULT, + HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_FAULT, + HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_FAULT, + HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_FAULT, + HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_FAULT, + HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_FAULT, + HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_FAULT, + HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_FAULT, + HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_FAULT, + HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_FAULT, + HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_FAULT, + HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_FAULT, + HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_FAULT, + HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_FAULT, + HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_FAULT, + HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_FAULT + ), + HWMON_CHANNEL_INFO(fan, + HWMON_F_INPUT | HWMON_F_ALARM, + HWMON_F_INPUT | HWMON_F_ALARM, + HWMON_F_INPUT | HWMON_F_ALARM, + HWMON_F_INPUT | HWMON_F_ALARM, + HWMON_F_INPUT | HWMON_F_ALARM, + HWMON_F_INPUT | HWMON_F_ALARM, + HWMON_F_INPUT | HWMON_F_ALARM, + HWMON_F_INPUT | HWMON_F_ALARM + ), + HWMON_CHANNEL_INFO(in, + HWMON_I_INPUT, + HWMON_I_INPUT, + HWMON_I_INPUT, + HWMON_I_INPUT + ), NULL }; -/* Voltages */ -static SENSOR_DEVICE_ATTR_RO(in1_input, in_value, 0); -static SENSOR_DEVICE_ATTR_RO(in2_input, in_value, 1); -static SENSOR_DEVICE_ATTR_RO(in3_input, in_value, 2); -static SENSOR_DEVICE_ATTR_RO(in4_input, in_value, 3); -static struct attribute *fts_voltage_attrs[] = { - &sensor_dev_attr_in1_input.dev_attr.attr, - &sensor_dev_attr_in2_input.dev_attr.attr, - &sensor_dev_attr_in3_input.dev_attr.attr, - &sensor_dev_attr_in4_input.dev_attr.attr, - NULL -}; - -static const struct attribute_group fts_voltage_attr_group = { - .attrs = fts_voltage_attrs -}; - -static const struct attribute_group fts_temp_attr_group = { - .attrs = fts_temp_attrs -}; - -static const struct attribute_group fts_fan_attr_group = { - .attrs = fts_fan_attrs -}; - -static const struct attribute_group *fts_attr_groups[] = { - &fts_voltage_attr_group, - &fts_temp_attr_group, - &fts_fan_attr_group, - NULL +static const struct hwmon_chip_info fts_chip_info = { + .ops = &fts_ops, + .info = fts_info, }; /*****************************************************************************/ @@ -793,10 +671,8 @@ static int fts_probe(struct i2c_client *client) return err; revision = err; - hwmon_dev = devm_hwmon_device_register_with_groups(&client->dev, - "ftsteutates", - data, - fts_attr_groups); + hwmon_dev = devm_hwmon_device_register_with_info(&client->dev, "ftsteutates", data, + &fts_chip_info, fts_attr_groups); if (IS_ERR(hwmon_dev)) return PTR_ERR(hwmon_dev); From patchwork Thu Jan 5 14:19:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 39609 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp324704wrt; Thu, 5 Jan 2023 06:23:33 -0800 (PST) X-Google-Smtp-Source: AMrXdXu9MW5hW/ePXEaNhkta28RheqRRe12c9HNDcslex9URq+TBNERRxDSZ69da/8OPP+p4l/FE X-Received: by 2002:a17:907:6d0c:b0:7c1:652:d109 with SMTP id sa12-20020a1709076d0c00b007c10652d109mr52201084ejc.35.1672928612864; Thu, 05 Jan 2023 06:23:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672928612; cv=none; d=google.com; s=arc-20160816; b=0Q19qZEYLT+24nfc3leAKa2WpsLtXNZRNz7Mp1/UGsY9T8TgOXCSN7cMFczk8PqnFo tfDLXtVV+ZSALv16ZA59LLOdWNttLmZ8njsHiV153JIVvhZknh3bz/kXk/gfyvsPxHJ7 ZS0VPrmipb+AQzdXHdC3OU7oIdW/WVlJi1eizKInl4XeQ3/VP1tYIg3FoMJ2n2RT3qah e9zi/0J8+hxp6Zl593NNUq8lZojCaZx2JfSOPcVDhFKoQLueZNmhyetbunJ04LF/hixg PbktBvIOtjSAGv/V/tgmiIkJqiMw3sj8cSofyGiVi1UQUJbfYEcbThEFi5NtXqKdlXEe ymdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:ui-outboundreport:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=o5Xy93OCUC6MuixC8jC80kz2igaEivv5DpBnbDRR8ao=; b=BzQoD9CtYQCnmNidIusYSneFFGNIgfYJEtXaFqlfUaA/ZnG+xu4qtiCcyKVqeuod9S EOquSuHsb9PHGlff4yQe4J/plgymTqcA0+U+gPeY2iV+c2Z0UKDYcSFPVJ4sQ7Ah0wvg FoTlaQJ5IiCCrXv3udBRCZVDsW3kvRiRP6LLoQRG7y7uQRs7xcsxFGf1kXJNqTF4E+UJ tebzSN38EHjIrXpCdTRMAqKXBtYVQt+g+pTMUbJz03iZ+UNG6gKNh4GwqGTCTMnZzG4c mwwUA5hrB1LtkK4zmvSNrHSpMMP7RO453gz6zqc4Ak3jkqWX7jdpWDCwln2fQdUEKeGs yczA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=dGdcS26g; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p20-20020a1709060dd400b007c173f57c88si24119035eji.811.2023.01.05.06.23.08; Thu, 05 Jan 2023 06:23:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=dGdcS26g; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232270AbjAEOTp (ORCPT + 99 others); Thu, 5 Jan 2023 09:19:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231520AbjAEOTi (ORCPT ); Thu, 5 Jan 2023 09:19:38 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24ED0D2D7; Thu, 5 Jan 2023 06:19:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1672928361; bh=RjBrwrzDF0HUQvM108jehXVM85PyLM9sDZAL/eCo9+M=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=dGdcS26gJuZZ2JM/TaqRQOhLZAgS1TuCf57XTUmX8pFkmv/FMWLqCntIG0gqsljr0 +CUM1VAN35giGtNP7GRLyuHqyrPc6dw4M4BI/bVLOj6WafjP1B0cEVcLwaMSdgee7s kK1zZPS0RXIXzrLiNlT1FP/m/ewwaQwLchhQhiMn+y8xsH88MRMw6yPquz8r8oyLHS VOibJwiOoqMw1SuVbHPO91hsToSWUn4lyAlnWL2lErsARXu09wD4ZINVMEJow97ScX t5xId2KmWgwehzO+hdkAvGKOgNzA9XBYeY0F5YVXUfsAyc5Vsal0aMoJxNb5fEA/lt bbhRz12AxklwQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from esprimo-mx.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MvK4f-1ovuIq1zWL-00rFUK; Thu, 05 Jan 2023 15:19:21 +0100 From: Armin Wolf To: jdelvare@suse.com, linux@roeck-us.net Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] hwmon: (ftsteutates) Replace fanX_source with pwmX_auto_channels_temp Date: Thu, 5 Jan 2023 15:19:10 +0100 Message-Id: <20230105141911.8040-3-W_Armin@gmx.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230105141911.8040-1-W_Armin@gmx.de> References: <20230105141911.8040-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:ru50W+qdfPb9At5rpiAcQ5PdK4qBfkTaf7yQw/v1zIQjyl4cADr amESEKh6KNh9AWnic4KBzSh/J0YYBr9YyUZNzSkt4jSxzwStaMrEfK6yAIzABnlrOPjydm4 Xqeg2bbhvgIG6GFMlsY1UjJbzHvo2UtS3sOqySgPn8dIakPgAPfsRz9xoiB5q8mt/cAUPC/ wKAYGdXOvQsFkR0AQSzWw== UI-OutboundReport: notjunk:1;M01:P0:PxaAWqHeM6g=;SWd6Qu6SZI1o6VOv1PHvj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_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754192792650311439?= X-GMAIL-MSGID: =?utf-8?q?1754192792650311439?= Replace the nonstandard fanX_source attributes with the standardized pwmX_auto_channels_temp attributes and document the special behaviour associated with those attributes. Tested on a Fujitsu DS3401-B1. Signed-off-by: Armin Wolf --- Documentation/hwmon/ftsteutates.rst | 5 ++ drivers/hwmon/ftsteutates.c | 77 +++++++++++------------------ 2 files changed, 33 insertions(+), 49 deletions(-) -- 2.30.2 diff --git a/Documentation/hwmon/ftsteutates.rst b/Documentation/hwmon/ftsteutates.rst index 198fa8e2819d..b3bfec36661d 100644 --- a/Documentation/hwmon/ftsteutates.rst +++ b/Documentation/hwmon/ftsteutates.rst @@ -22,6 +22,11 @@ enhancements. It can monitor up to 4 voltages, 16 temperatures and 8 fans. It also contains an integrated watchdog which is currently implemented in this driver. +The ``pwmX_auto_channels_temp`` attributes show which temperature sensor +is currently driving which fan channel. This value might dynamically change +during runtime depending on the temperature sensor selected by +the fan control circuit. + The 4 voltages require a board-specific multiplier, since the BMC can only measure voltages up to 3.3V and thus relies on voltage dividers. Consult your motherboard manual for details. diff --git a/drivers/hwmon/ftsteutates.c b/drivers/hwmon/ftsteutates.c index 23dc3a74f84b..0d8ab94250a9 100644 --- a/drivers/hwmon/ftsteutates.c +++ b/drivers/hwmon/ftsteutates.c @@ -6,9 +6,7 @@ * Thilo Cestonaro */ #include -#include #include -#include #include #include #include @@ -16,7 +14,6 @@ #include #include #include -#include #include #define FTS_DEVICE_ID_REG 0x0000 @@ -48,6 +45,8 @@ #define FTS_NO_TEMP_SENSORS 0x10 #define FTS_NO_VOLT_SENSORS 0x04 +#define FTS_FAN_SOURCE_INVALID 0xff + static const unsigned short normal_i2c[] = { 0x73, I2C_CLIENT_END }; static const struct i2c_device_id fts_id[] = { @@ -187,7 +186,7 @@ static int fts_update_device(struct fts_data *data) data->fan_source[i] = err; } else { data->fan_input[i] = 0; - data->fan_source[i] = 0; + data->fan_source[i] = FTS_FAN_SOURCE_INVALID; } } @@ -339,50 +338,6 @@ static int fts_watchdog_init(struct fts_data *data) return devm_watchdog_register_device(&data->client->dev, &data->wdd); } -static ssize_t fan_source_show(struct device *dev, - struct device_attribute *devattr, char *buf) -{ - struct fts_data *data = dev_get_drvdata(dev); - int index = to_sensor_dev_attr(devattr)->index; - int err; - - err = fts_update_device(data); - if (err < 0) - return err; - - return sprintf(buf, "%u\n", data->fan_source[index]); -} - -static SENSOR_DEVICE_ATTR_RO(fan1_source, fan_source, 0); -static SENSOR_DEVICE_ATTR_RO(fan2_source, fan_source, 1); -static SENSOR_DEVICE_ATTR_RO(fan3_source, fan_source, 2); -static SENSOR_DEVICE_ATTR_RO(fan4_source, fan_source, 3); -static SENSOR_DEVICE_ATTR_RO(fan5_source, fan_source, 4); -static SENSOR_DEVICE_ATTR_RO(fan6_source, fan_source, 5); -static SENSOR_DEVICE_ATTR_RO(fan7_source, fan_source, 6); -static SENSOR_DEVICE_ATTR_RO(fan8_source, fan_source, 7); - -static struct attribute *fts_fan_attrs[] = { - &sensor_dev_attr_fan1_source.dev_attr.attr, - &sensor_dev_attr_fan2_source.dev_attr.attr, - &sensor_dev_attr_fan3_source.dev_attr.attr, - &sensor_dev_attr_fan4_source.dev_attr.attr, - &sensor_dev_attr_fan5_source.dev_attr.attr, - &sensor_dev_attr_fan6_source.dev_attr.attr, - &sensor_dev_attr_fan7_source.dev_attr.attr, - &sensor_dev_attr_fan8_source.dev_attr.attr, - NULL -}; - -static const struct attribute_group fts_attr_group = { - .attrs = fts_fan_attrs -}; - -static const struct attribute_group *fts_attr_groups[] = { - &fts_attr_group, - NULL -}; - static umode_t fts_is_visible(const void *devdata, enum hwmon_sensor_types type, u32 attr, int channel) { @@ -408,6 +363,7 @@ static umode_t fts_is_visible(const void *devdata, enum hwmon_sensor_types type, break; } break; + case hwmon_pwm: case hwmon_in: return 0444; default: @@ -460,6 +416,19 @@ static int fts_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, break; } break; + case hwmon_pwm: + switch (attr) { + case hwmon_pwm_auto_channels_temp: + if (data->fan_source[channel] == FTS_FAN_SOURCE_INVALID) + *val = 0; + else + *val = BIT(data->fan_source[channel]); + + return 0; + default: + break; + } + break; case hwmon_in: switch (attr) { case hwmon_in_input: @@ -576,6 +545,16 @@ static const struct hwmon_channel_info *fts_info[] = { HWMON_F_INPUT | HWMON_F_ALARM, HWMON_F_INPUT | HWMON_F_ALARM ), + HWMON_CHANNEL_INFO(pwm, + HWMON_PWM_AUTO_CHANNELS_TEMP, + HWMON_PWM_AUTO_CHANNELS_TEMP, + HWMON_PWM_AUTO_CHANNELS_TEMP, + HWMON_PWM_AUTO_CHANNELS_TEMP, + HWMON_PWM_AUTO_CHANNELS_TEMP, + HWMON_PWM_AUTO_CHANNELS_TEMP, + HWMON_PWM_AUTO_CHANNELS_TEMP, + HWMON_PWM_AUTO_CHANNELS_TEMP + ), HWMON_CHANNEL_INFO(in, HWMON_I_INPUT, HWMON_I_INPUT, @@ -672,7 +651,7 @@ static int fts_probe(struct i2c_client *client) revision = err; hwmon_dev = devm_hwmon_device_register_with_info(&client->dev, "ftsteutates", data, - &fts_chip_info, fts_attr_groups); + &fts_chip_info, NULL); if (IS_ERR(hwmon_dev)) return PTR_ERR(hwmon_dev); From patchwork Thu Jan 5 14:19:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 39608 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp324528wrt; Thu, 5 Jan 2023 06:23:11 -0800 (PST) X-Google-Smtp-Source: AMrXdXvrBdoTzaPLvBnhs8u6GH/cjlk6b8kfa2l8Wn1guLbR1lQintQx+c8mcYmpUypM1ZEFFfIK X-Received: by 2002:a17:906:78c:b0:7ad:e52c:12e6 with SMTP id l12-20020a170906078c00b007ade52c12e6mr44231341ejc.41.1672928590716; Thu, 05 Jan 2023 06:23:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672928590; cv=none; d=google.com; s=arc-20160816; b=aCBUe9UE80pI20ESJaip3VVoy0rvLyyZ3C7ZlfwcYZGRQ+Ciyx3NCGuZe0f84ynnsb WtLvTMnaJ8xtB3rB3V+mb5NDNiVJUMCVvVuzQXxyDs6Js0KxE+iVQKJUY8dVMXZGEiLW fIREJeFgj8Lu6fHSbW87EHGCiiUlUfPQ+neV7oQ3Rfi0aGTn83cHOOfv1Y+RMF9alZsC l0UDQNkwkqr4Gx3KxWfrz2ruMugW7/fEjv7H+8zFVAdaFflj7GXIkBcYukiaR73xCMKk wSmNOcOQTDpxbgnkJ8jT74fOSMQPkPW59wEsbOKC0ZVrvzDb+yg1Q+/ZY25+wcRMLGcg cN9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:ui-outboundreport:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ReKwYiVMmlTd3p8LykovhdxYPBU4E1dGEfu5rb1D3B8=; b=p1yy5SZIWU5MPGjLf8wIlc9+QbBNWz7YETfpCR2I3Zy26pnqu1KPAaN6+VRewmr6C1 FFd4LS1ZpptehhssYgva7If9FP6EeNTDWG2Hi2p3ABMRSnmcxm0QZwW73EAN+jfB9QB9 FYl5h8iEv3V9diHBCcR1Jl7yCqJanbEii65LGfwypRUzqzZvzNe42WQUJQU7XxAjMizb zGns5t4625k9j526+gR6q/x73C6caDixF8rdRObe3hN+2AXYUt40dkpA7acfku1coL/6 I1zIrpbD2YBa3AHDn8r1taxD1MLRfz9nSUcxK+m7fAPCVeG8RtLx4BhpgxDebDWhkJsw KLvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=aWJVKi4k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id xa13-20020a170906fd8d00b007d161a8106csi24937227ejb.982.2023.01.05.06.22.46; Thu, 05 Jan 2023 06:23:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=aWJVKi4k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232670AbjAEOTt (ORCPT + 99 others); Thu, 5 Jan 2023 09:19:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231644AbjAEOTj (ORCPT ); Thu, 5 Jan 2023 09:19:39 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB55159309; Thu, 5 Jan 2023 06:19:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1672928363; bh=jGqmtBpJFhDWl3+/3Q4iGUyNOyvE0pOn9VoLM3cxvNw=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=aWJVKi4kKq3+bkujuqlXXDtH7qS4s3vkkFJEWa9769Jkh5Cf2ypqHSTrq/Pl6pJBl atVy7ORdW45o2dl+uSRizAjHeoj7JlPKYcslC3XdyE8VY+Rwrm6BB0csraFjJLegbG 4RbwWSq/kEl2BnAMv1h27+2SuCVkpG34zHwscQYJjvbvV7CqbZVhF+agn7Ob+jmMr/ od29xWBwuxH2rgBdsTJIiTxr9xJ8UqvoRk/vb5puVxY+RA2t+Z7paGoJ55sajSxtAD q465h8yKJstcaG0CvOV51DJWnWXm/Y9UXLxr+Sd92Til7sXtmqA05zAo0TzTcdtifJ LoPDh1olt4s8Q== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from esprimo-mx.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MiacH-1oYJBN3kzn-00fjNy; Thu, 05 Jan 2023 15:19:22 +0100 From: Armin Wolf To: jdelvare@suse.com, linux@roeck-us.net Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] hwmon: (ftsteutates) Add support for fanX_fault attributes Date: Thu, 5 Jan 2023 15:19:11 +0100 Message-Id: <20230105141911.8040-4-W_Armin@gmx.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230105141911.8040-1-W_Armin@gmx.de> References: <20230105141911.8040-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:Wr0zOroG7LIq3kzpUYWfHXGxFxEa/RaUBdqfrpGwrccgs0UGXXt HDhhPIXJEACq3foul9FLFSqXgc9ValFo4665jsijaQrhIQbAxzhrVmEV4HetlcKIQJ6IMG7 G+6YJBULJ16KHXVvBZGdSNLRU2oZY3oYHVd7d/S4i6Wg2Rfj+JgMsC3m3GMWute19CVHBPC XIJUTFWf/1z9qOo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No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754192769992613404?= X-GMAIL-MSGID: =?utf-8?q?1754192769992613404?= The driver knows internally when a fan is not connected, but does not export this knowledge to userspace. Use the standard fanX_fault attributes to notify userspace if a fan is not connected. Tested on a Fujitsu DS3401-B1. Signed-off-by: Armin Wolf --- drivers/hwmon/ftsteutates.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) -- 2.30.2 diff --git a/drivers/hwmon/ftsteutates.c b/drivers/hwmon/ftsteutates.c index 0d8ab94250a9..25afd9167a34 100644 --- a/drivers/hwmon/ftsteutates.c +++ b/drivers/hwmon/ftsteutates.c @@ -356,6 +356,7 @@ static umode_t fts_is_visible(const void *devdata, enum hwmon_sensor_types type, case hwmon_fan: switch (attr) { case hwmon_fan_input: + case hwmon_fan_fault: return 0444; case hwmon_fan_alarm: return 0644; @@ -411,6 +412,10 @@ static int fts_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, case hwmon_fan_alarm: *val = !!(data->fan_alarm & BIT(channel)); + return 0; + case hwmon_fan_fault: + *val = !(data->fan_present & BIT(channel)); + return 0; default: break; @@ -536,14 +541,14 @@ static const struct hwmon_channel_info *fts_info[] = { HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_FAULT ), HWMON_CHANNEL_INFO(fan, - HWMON_F_INPUT | HWMON_F_ALARM, - HWMON_F_INPUT | HWMON_F_ALARM, - HWMON_F_INPUT | HWMON_F_ALARM, - HWMON_F_INPUT | HWMON_F_ALARM, - HWMON_F_INPUT | HWMON_F_ALARM, - HWMON_F_INPUT | HWMON_F_ALARM, - HWMON_F_INPUT | HWMON_F_ALARM, - HWMON_F_INPUT | HWMON_F_ALARM + HWMON_F_INPUT | HWMON_F_ALARM | HWMON_F_FAULT, + HWMON_F_INPUT | HWMON_F_ALARM | HWMON_F_FAULT, + HWMON_F_INPUT | HWMON_F_ALARM | HWMON_F_FAULT, + HWMON_F_INPUT | HWMON_F_ALARM | HWMON_F_FAULT, + HWMON_F_INPUT | HWMON_F_ALARM | HWMON_F_FAULT, + HWMON_F_INPUT | HWMON_F_ALARM | HWMON_F_FAULT, + HWMON_F_INPUT | HWMON_F_ALARM | HWMON_F_FAULT, + HWMON_F_INPUT | HWMON_F_ALARM | HWMON_F_FAULT ), HWMON_CHANNEL_INFO(pwm, HWMON_PWM_AUTO_CHANNELS_TEMP,