From patchwork Wed Jul 28 22:15:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 12406903 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0327BC4320A for ; Wed, 28 Jul 2021 22:16:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DB9806103C for ; Wed, 28 Jul 2021 22:16:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231982AbhG1WQU (ORCPT ); Wed, 28 Jul 2021 18:16:20 -0400 Received: from mout.gmx.net ([212.227.15.15]:52155 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232110AbhG1WQU (ORCPT ); Wed, 28 Jul 2021 18:16:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1627510561; bh=DhSFe+P3rPaWUNqUAqEdNMpsMXOakE4UTWSA3BpWl8A=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=TwtDo0ElqIIcoCOe1E1mCTvRnfIX7kWJHX1DQy/7SQ8icep5XxWCSuLb12wJCb0/g QNW7tj8A6HD5t7bvB8OW43IgQxL7yuc7QJwgcDIk5HT1jWWVw4v2eVWXQBdCLFSDrT TpSyvZNAFVk3a9HhjhEVGSbfvibhrNQLhtPRYVRw= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from esprimo-mx.fritz.box ([79.242.190.212]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1N8GQs-1nCfuD2IBE-014FfU; Thu, 29 Jul 2021 00:16:01 +0200 From: W_Armin@gmx.de To: pali@kernel.org Cc: linux@roeck-us.net, jdelvare@suse.com, linux-hwmon@vger.kernel.org Subject: [PATCH v7 1/6] hwmon: (dell-smm-hwmon) Use platform device Date: Thu, 29 Jul 2021 00:15:52 +0200 Message-Id: <20210728221557.8891-2-W_Armin@gmx.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210728221557.8891-1-W_Armin@gmx.de> References: <20210728221557.8891-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:aCWsbTmxBFo0PwNrHjMoCFnfcgZ/d97NpsrN4G/JONh5kzF31dV ShkU2W9R70RqkicQAJjimy71IHrB0pmAixKqxKkWndYMb+ju7bSz/ITLcJ5C5W+wqGndqfj VHrvYKCW58VxhiHHRW5WYs2EdFW7MuAXjgmMpaDnjrLmBM4pT+r2wXX0c0YMBvcKoDlJBgb 9aP/rsyrtPQNuFR47ocGw== X-UI-Out-Filterresults: notjunk:1;V03:K0:5CWntbjaHhs=:xt1Fz+utgq1OsBMSzMlmPS +8j7sl50LccYCsEoyAJncobbG28DfjsfWCHShMe5Dn8y+B5rkMS2T1n95OyPTrj83B/h2odx3 YLWPJnxyMRC2+n9f28vqWkMdzOzxr+NH5vvAM3qLQyvZ/nGhNg0916vUZlDAmy4TbXsAm5oQL zB49c0zjiAuepTavvVKXiGcT8Ugby56VWxr1ovSds1x5+tXtQeNrDAmSzVblsNi7kIKtJm2JU aNYhOO9bCxd+12oK4ap+UAc3XbPr6Y3BSCiDg3X5zikNaQrAX+sMaCGja8P51i0pbJQJGpyVn DjfCXcYRP/IHxr8qSrg/rEoNCBcab86alE1kAr56tdlAtoeoBcjn3VvDmweITyjmaqactMn/q IMpndy3VR69OFRdhmk+4M1gXx1Z8BZsDCoL7+b8QQW1D6HMYdUzEynW2QAtJairLKc7ybyCga 2lbBk/Z2BxKkqjRXrUUK0PJJuHS7NdDIa0eqXqw326r2aKaQfUN6goaESQs6guKpwKxPnLvDJ kVs6VLdclNChi4MY76NqTa2IDoMO3jvqOoVn6yLylgx5O6lSE901WMBdUsZHZOoPCRbi8j5PS HqP05qH1+snZqVqsodQzPVSaTbjN/eXuZiJ01ckv4QyLU1bOK6CNanWusTG5YrkhGtY5PFOTS yO96ojMfhDUspKrm9/s0zY7im2THlaiNrIh6FtxQPRQjn14sNL70vi45QtSoas0goLOIjZyTO diwj8+oSN/Ha+Xm/7bR7K01V3Q2Pg3iOPSoX74ehB3EZM86JJi7p7zBEIoaz5rWibPFmv/jqt qevGgGBnrV2Wnm+RY1nB/c/FjT8DqkaWOnZtuSx184CVoAPV9alp8fG7hVhhuFi8DL3gGnQYX E/3pguH2/7Drk/V+McBz2rc9K98JwSD+iH4AiVDs3EhDiRd3WycLJcZSIw8HPZFwTBpHT3u8I lI/5TQu3Q7PA3pWY0X9vokEWtW7pUtnri5hrH9Lc9QHchdwupDNH1tXZ6RZxsZlT/jTrokVij EDNf9KGiTjR6RXxsgnEyDTn8dl68cuQQ0UftTf8BYHIwa+9C+CFFwWwMiLyhpVfxiKtKMZkk4 J0xgDI2o3hKUTpydfr6meZ/V4tZosJpSLh1 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org From: Armin Wolf Register a platform device for usage with devm_hwmon_device_register_with_groups since the platform device is necessary for future changes. Also fix some checkpatch warnings. Signed-off-by: Armin Wolf --- drivers/hwmon/dell-smm-hwmon.c | 113 ++++++++++++++++++--------------- 1 file changed, 62 insertions(+), 51 deletions(-) -- 2.20.1 diff --git a/drivers/hwmon/dell-smm-hwmon.c b/drivers/hwmon/dell-smm-hwmon.c index f2221ca0aa7b..f06873413aea 100644 --- a/drivers/hwmon/dell-smm-hwmon.c +++ b/drivers/hwmon/dell-smm-hwmon.c @@ -14,7 +14,9 @@ #include #include +#include #include +#include #include #include #include @@ -896,7 +898,7 @@ static const struct attribute_group i8k_group = { }; __ATTRIBUTE_GROUPS(i8k); -static int __init i8k_init_hwmon(void) +static int __init dell_smm_init_hwmon(struct device *dev) { int err; @@ -956,15 +958,9 @@ static int __init i8k_init_hwmon(void) if (err >= 0) i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN3; - i8k_hwmon_dev = hwmon_device_register_with_groups(NULL, "dell_smm", - NULL, i8k_groups); - if (IS_ERR(i8k_hwmon_dev)) { - err = PTR_ERR(i8k_hwmon_dev); - i8k_hwmon_dev = NULL; - pr_err("hwmon registration failed (%d)\n", err); - return err; - } - return 0; + i8k_hwmon_dev = devm_hwmon_device_register_with_groups(dev, "dell_smm", NULL, i8k_groups); + + return PTR_ERR_OR_ZERO(i8k_hwmon_dev); } struct i8k_config_data { @@ -1221,28 +1217,11 @@ static struct dmi_system_id i8k_whitelist_fan_control[] __initdata = { { } }; -/* - * Probe for the presence of a supported laptop. - */ -static int __init i8k_probe(void) +static int __init dell_smm_probe(struct platform_device *pdev) { const struct dmi_system_id *id, *fan_control; int fan, ret; - /* - * Get DMI information - */ - if (!dmi_check_system(i8k_dmi_table)) { - if (!ignore_dmi && !force) - return -ENODEV; - - pr_info("not running on a supported Dell system.\n"); - pr_info("vendor=%s, model=%s, version=%s\n", - i8k_get_dmi_data(DMI_SYS_VENDOR), - i8k_get_dmi_data(DMI_PRODUCT_NAME), - i8k_get_dmi_data(DMI_BIOS_VERSION)); - } - if (dmi_check_system(i8k_blacklist_fan_support_dmi_table)) { pr_warn("broken Dell BIOS detected, disallow fan support\n"); if (!force) @@ -1255,21 +1234,11 @@ static int __init i8k_probe(void) disallow_fan_type_call = true; } - strlcpy(bios_version, i8k_get_dmi_data(DMI_BIOS_VERSION), + strscpy(bios_version, i8k_get_dmi_data(DMI_BIOS_VERSION), sizeof(bios_version)); - strlcpy(bios_machineid, i8k_get_dmi_data(DMI_PRODUCT_SERIAL), + strscpy(bios_machineid, i8k_get_dmi_data(DMI_PRODUCT_SERIAL), sizeof(bios_machineid)); - /* - * Get SMM Dell signature - */ - if (i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG1) && - i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG2)) { - pr_err("unable to get SMM Dell signature\n"); - if (!force) - return -ENODEV; - } - /* * Set fan multiplier and maximal fan speed from dmi config * Values specified in module parameters override values from dmi @@ -1277,6 +1246,7 @@ static int __init i8k_probe(void) id = dmi_first_match(i8k_dmi_table); if (id && id->driver_data) { const struct i8k_config_data *conf = id->driver_data; + if (!fan_mult && conf->fan_mult) fan_mult = conf->fan_mult; if (!fan_max && conf->fan_max) @@ -1313,29 +1283,70 @@ static int __init i8k_probe(void) i8k_fan_mult = fan_mult; } + ret = dell_smm_init_hwmon(&pdev->dev); + if (ret) + return ret; + + i8k_init_procfs(); + return 0; } +static int dell_smm_remove(struct platform_device *pdev) +{ + i8k_exit_procfs(); + + return 0; +} + +static struct platform_driver dell_smm_driver = { + .driver = { + .name = KBUILD_MODNAME, + }, + .remove = dell_smm_remove, +}; + +static struct platform_device *dell_smm_device; + +/* + * Probe for the presence of a supported laptop. + */ static int __init i8k_init(void) { - int err; + /* + * Get DMI information + */ + if (!dmi_check_system(i8k_dmi_table)) { + if (!ignore_dmi && !force) + return -ENODEV; - /* Are we running on an supported laptop? */ - if (i8k_probe()) - return -ENODEV; + pr_info("not running on a supported Dell system.\n"); + pr_info("vendor=%s, model=%s, version=%s\n", + i8k_get_dmi_data(DMI_SYS_VENDOR), + i8k_get_dmi_data(DMI_PRODUCT_NAME), + i8k_get_dmi_data(DMI_BIOS_VERSION)); + } - err = i8k_init_hwmon(); - if (err) - return err; + /* + * Get SMM Dell signature + */ + if (i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG1) && + i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG2)) { + pr_err("unable to get SMM Dell signature\n"); + if (!force) + return -ENODEV; + } - i8k_init_procfs(); - return 0; + dell_smm_device = platform_create_bundle(&dell_smm_driver, dell_smm_probe, NULL, 0, NULL, + 0); + + return PTR_ERR_OR_ZERO(dell_smm_device); } static void __exit i8k_exit(void) { - hwmon_device_unregister(i8k_hwmon_dev); - i8k_exit_procfs(); + platform_device_unregister(dell_smm_device); + platform_driver_unregister(&dell_smm_driver); } module_init(i8k_init); From patchwork Wed Jul 28 22:15:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 12406905 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4AEF1C4338F for ; Wed, 28 Jul 2021 22:16:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 309526103C for ; Wed, 28 Jul 2021 22:16:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232110AbhG1WQX (ORCPT ); Wed, 28 Jul 2021 18:16:23 -0400 Received: from mout.gmx.net ([212.227.15.18]:43563 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232075AbhG1WQW (ORCPT ); Wed, 28 Jul 2021 18:16:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1627510563; bh=Er6k5tLiUJPuW1WNmYTS1PUHAIWkMV1+c3yIe+8Tf8E=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=AVTqfH/7bOV18Pg34DB+GBaCWOCbIDaXLAkYr4PaBmtTgQPSFPXzfUlym8RXt5Bex gqQTOux6nxl+mebwF58gChp8MJMm3Dg79h9Hgmc4XPrBrtdS/XdUHxXubtAyeeUBYq kgP1GWI3lbMwMEmdnpT7y8ho9VM6xz57I0vp0OtY= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from esprimo-mx.fritz.box ([79.242.190.212]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MuDc7-1n2UEp3lwT-00udsx; Thu, 29 Jul 2021 00:16:03 +0200 From: W_Armin@gmx.de To: pali@kernel.org Cc: linux@roeck-us.net, jdelvare@suse.com, linux-hwmon@vger.kernel.org Subject: [PATCH v7 2/6] hwmon: (dell-smm-hwmon) Mark functions as __init Date: Thu, 29 Jul 2021 00:15:53 +0200 Message-Id: <20210728221557.8891-3-W_Armin@gmx.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210728221557.8891-1-W_Armin@gmx.de> References: <20210728221557.8891-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:S4ZdK8O5FNh7q7Z36yDNMTzq+PZEs+66RZ3u10mLL2WU0W0KMx9 QsV6eos9npOh0rNI4d2xjmdE/+mkP3/rkO4mN5Mu8fOlOPAjpb4VDcAE76B7MAWS4nORhiL xO6YnCjt/EuCdqmnWLK9UNz0hQCsW5eJDevrYyRCciFGUE+tMrWh0Xu4kFP/ICSndHh5hp7 sFXbf5/HEcq9acIitOs3g== X-UI-Out-Filterresults: notjunk:1;V03:K0:cEt6rXN2QYg=:uR6r5+4Y9On5C4/sb48Zqx v7R+7B884GtjdhsdPEkqSSLXZljRwcxgS+wmBd1Im75bu82VDkRNKWh5F1ysVZIEioOQBgAmq 4hPimpAtcfngMCuo15vQRY/A7FUzoceE/UOgQgyJyoa1fFRpLPA3wBBdYTz4wqdxa00d2bwlo Ho8Dn9Rl5bhsJVJMRSKRnb18H12RcgKzr4SF65V9W1KbtMaIO3mofqyUeOHzgIZg2UfudiCrN FdMuPLhaL/tGOr3uW99SQAkpCnlEPjFzLh/TY8vF+uhbyFJ5UjhkZLnmqlF9VE1aoSIgaERnd TlQT4nLe0IcyT4gkFMSzaDPrqwIO8V9LikU/maqIwThScI7PgZSPUFie5DtraDQ1J1zXPyFjk GeenOLvXJXUMDlRWzMwzpJ+fqJEIHx5yKNqd9Sz8wf5gcqdjNeboQvoBTOL0BvrOvlMoCz1SI WuEv4IB/1NI+cIS4ra4YkHPxuWI0m1FOCjqnoOQrJjKfWcjNMdCjX+Vq1orznKZASHAw9COfw LbSpwGuPhayPudPVpUvWx1LJiPW66gvm9xoHe5kKGLIHIFpPWBRTJo05fwzN97PrGFC7Oi4+G tty3QvOMVrPywTI9yCPy3Ks1Vpzq68XpiE7NvErJbSxYdxd7QpuQ1FaGaGMqPtKfYaDYfcXrz RT92qpDQCIVtIMlvzav4h5t+QO32t6tNxyj2Ybs5e/u1+cX9jt98/NaknelfUU95PNsri8dT9 cBC7U5moQNowx/5px9cYFhiATxBKKIJY5YoTUBrv3NVwAD/klpwVa2vCtBFY1nSdC0kUBxCGk UwXKrYeUBVhtHjHSM/txvlxwWosW7ar79RVcvPA3D/lGkEwBCFSepUkQk8s5XCeho0M52b4ig o4MrUWX3T+H2OObgn1oODIr361BQrZhfvNJsY3zjZDGxnFkIrK+A+HPxK+df6000Oqtlt2ezY /j0RNHFglCx1YpklWAZQe61tClqm/cjAXs6Beu95FkoZ0WpJAcWx/x2c/81XYgJeJlB2XIidD B0IwBQlOICd1D4N/9iSh2JTJP8V7Dy6bz8veZSNKcxnYaV//Zuj6cxgKv/eJZNfEe3Srmn+Rm /4RW1f2xQDRbOYk2FqVzMqg+P8+VViitI0L Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org From: Armin Wolf i8k_get_dmi_data() and i8k_get_dell_signature() are only called during module init and probe, which both are marked as __init. Also mark these function as __init to lower the runtime memory footprint. Signed-off-by: Armin Wolf Reviewed-by: Pali Rohár Tested-by: Pali Rohár --- drivers/hwmon/dell-smm-hwmon.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.20.1 diff --git a/drivers/hwmon/dell-smm-hwmon.c b/drivers/hwmon/dell-smm-hwmon.c index f06873413aea..c898d6bd6a18 100644 --- a/drivers/hwmon/dell-smm-hwmon.c +++ b/drivers/hwmon/dell-smm-hwmon.c @@ -128,7 +128,7 @@ struct smm_regs { unsigned int edi __packed; }; -static inline const char *i8k_get_dmi_data(int field) +static inline const char __init *i8k_get_dmi_data(int field) { const char *dmi_data = dmi_get_system_info(field); @@ -384,7 +384,7 @@ static int i8k_get_temp(int sensor) return temp; } -static int i8k_get_dell_signature(int req_fn) +static int __init i8k_get_dell_signature(int req_fn) { struct smm_regs regs = { .eax = req_fn, }; int rc; From patchwork Wed Jul 28 22:15:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 12406907 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A588C4320A for ; Wed, 28 Jul 2021 22:16:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7D63461040 for ; Wed, 28 Jul 2021 22:16:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232075AbhG1WQX (ORCPT ); Wed, 28 Jul 2021 18:16:23 -0400 Received: from mout.gmx.net ([212.227.15.15]:38239 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231998AbhG1WQX (ORCPT ); Wed, 28 Jul 2021 18:16:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1627510564; bh=fno1fA+0keQwzzK9v/Ru4/C9g+Om8P+dCHByA/X0ohM=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=R8e3YZXHzJZggMXIElxo2RYAaArqMRbD89Ek7M+3TMrNkbvzjWpMJVu/j6GA3Arom +EvDypXLzPpF/fI8tOdylS8HVuVGfsqQurUbGYOQJp5AL/5kySfPbOerV0Kz3Pxz7Q LCswRqB9CvLgbeFI/LsIc3aGIS+rMgEyzV6jXqPM= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from esprimo-mx.fritz.box ([79.242.190.212]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MKbkM-1mThaC1Ijc-00KzJ1; Thu, 29 Jul 2021 00:16:04 +0200 From: W_Armin@gmx.de To: pali@kernel.org Cc: linux@roeck-us.net, jdelvare@suse.com, linux-hwmon@vger.kernel.org Subject: [PATCH v7 3/6] hwmon: (dell-smm-hwmon) Use devm_add_action_or_reset() Date: Thu, 29 Jul 2021 00:15:54 +0200 Message-Id: <20210728221557.8891-4-W_Armin@gmx.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210728221557.8891-1-W_Armin@gmx.de> References: <20210728221557.8891-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:QX11wyHZy4g3YRyyieTeUmk2eR+NS82HJO6BdDSkwjkHakQ1RZC V/jbBDKYRSYZ4suLjku7aLNGb9Epe6ual9GPu9e3pQw+EHkL1xipMnfoJuLINgKhtUi8/1Q 5Bcji2tbKfOkD38UZtR2Le1i4xCl0yjrxDT4MKiffT8yqfxryH8UDzKF9+smynaRoRQY6qO OcVcUrBqu2Mo2JHRoYumA== X-UI-Out-Filterresults: notjunk:1;V03:K0:WMMRVC+D0dM=:MS1N02MWWS3ppq0CH196lL QMno5gr1ElZnFXXRsFHEMdDYscHGPxVy84o1lxWpCev+yB6vAPfkfEJxb056y0226R5sgQ6tp BqV9P+rnXYuNgt8g3rQt/v0PZY9+w9D+mIFQoIkIbLMXrhrlXxoMnOsl2AVzkOPOuFWsHZw4I TiS2n+inCoSlDn7lPAzwqjAX2BYCe3mEnV/hAxmEBRLGmrczNapGmR1hgiII81oIZAkQRF/pi MjU2olKcNeIEvZ1dZN0828LK1HP4v6xxWXEbPI60407MbJA812k0wvdIE73NOR6JwJDnF/p6t RwKp8S0qXcmwxO8aYAmvfvjCsK5F+kJSCEC3mYsbWCas+9KbZMUpi+Z+rwATxgipnpm2ZiZRB 3eHREF0/kBxtsAKuHf9GVVTQP0W/0/46aNf3bxeBaAsvrLjitpst4OPpJMzkKGg+2qxCJgBPh o7bxyAh9ynVZ8NLca5Cu3IkC43LKiLKzP29y1wijSwwz7ycZhNxO8Hv3/YAqhhfKS1LFzZcXd 1NvUSOlCnvqDMAKPei4fsD8P2yu055lDNkuiIZD6PFOsVOUzJjK3SaXFNsKwmYxpaj+mBWkMX RgRkJpmtxo4RpzxwhKVur2tTGi77l8ivozQUnlssXL04BP5iuqE2pnVJfnYaTIINA+57KrmXi hYO1usK8ngzh3XkRmrSYWjjIdjG2Izob/9sHIAJansMsUnIjSGB5TetfIx24PrpDSUtCib1Wg jDyZdw3xPcnqJDTJiLYWA8iiyK3ShDX45clvjXDrACdH3BcCKUw1RBUA3YMxnmCfjXbXLu6Rs U1bB2JfldAgw+qPkMg05Efgyf48fiFuqZIQBH9RAflYbGqjL7wUPeWP0aUxSjNk0D2LQ9oZ5H JorwTSy5r6zA51frUilZkozRL+WL7VnQR9QQhGzKsUVXhUM9OMZ5i4NvknyDnbzseZKGErpzL fIg4ABhWMaXC4N6jFCRvB7kUeR7jENj6/ZiY0XNqIRV7C086mcX8/riTNZ7mP216ddajAqpa3 6JROdDXXYIvrrcqE7+UgE6TTiHar/+qf+caBjTBhPtR7xZQ1KjO+wFG/0p3ZT/mIKQnxDBgJy zWl7a4QVFbV0yzWbuqFd6W7maEU/mT9aZe/ Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org From: Armin Wolf Use devm_add_action_or_reset() for calling i8k_exit_procfs() so the remove() function in dell_smm_driver can be omitted. Signed-off-by: Armin Wolf Reviewed-by: Pali Rohár Tested-by: Pali Rohár --- drivers/hwmon/dell-smm-hwmon.c | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) -- 2.20.1 diff --git a/drivers/hwmon/dell-smm-hwmon.c b/drivers/hwmon/dell-smm-hwmon.c index c898d6bd6a18..da7040f2442e 100644 --- a/drivers/hwmon/dell-smm-hwmon.c +++ b/drivers/hwmon/dell-smm-hwmon.c @@ -605,24 +605,22 @@ static const struct proc_ops i8k_proc_ops = { .proc_ioctl = i8k_ioctl, }; -static void __init i8k_init_procfs(void) +static void i8k_exit_procfs(void *param) { - /* Register the proc entry */ - proc_create("i8k", 0, NULL, &i8k_proc_ops); + remove_proc_entry("i8k", NULL); } -static void __exit i8k_exit_procfs(void) +static void __init i8k_init_procfs(struct device *dev) { - remove_proc_entry("i8k", NULL); + /* Register the proc entry */ + proc_create("i8k", 0, NULL, &i8k_proc_ops); + + devm_add_action_or_reset(dev, i8k_exit_procfs, NULL); } #else -static inline void __init i8k_init_procfs(void) -{ -} - -static inline void __exit i8k_exit_procfs(void) +static void __init i8k_init_procfs(struct device *dev) { } @@ -1287,14 +1285,7 @@ static int __init dell_smm_probe(struct platform_device *pdev) if (ret) return ret; - i8k_init_procfs(); - - return 0; -} - -static int dell_smm_remove(struct platform_device *pdev) -{ - i8k_exit_procfs(); + i8k_init_procfs(&pdev->dev); return 0; } @@ -1303,7 +1294,6 @@ static struct platform_driver dell_smm_driver = { .driver = { .name = KBUILD_MODNAME, }, - .remove = dell_smm_remove, }; static struct platform_device *dell_smm_device; From patchwork Wed Jul 28 22:15:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 12406909 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E0E4C4338F for ; Wed, 28 Jul 2021 22:16:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3FD5E603E9 for ; Wed, 28 Jul 2021 22:16:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232114AbhG1WQZ (ORCPT ); Wed, 28 Jul 2021 18:16:25 -0400 Received: from mout.gmx.net ([212.227.15.18]:41175 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231998AbhG1WQZ (ORCPT ); Wed, 28 Jul 2021 18:16:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1627510566; bh=oixciV1xo5MoHy9eeElEMgU+g7Dm3FkM0+yVGfMkbB4=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=Hji/aG6zxb2EA1nm4sIdBMN95uYg8k1ztyOdNR35vwiXLBNGBNthjNFcf1uqbSntB R0Yhhl/6hZt9F+HIWEBDfch6Tsk04TeIonAnxlYX5sS/aPDT570BoZVEl/JbMsNQ1X DXJrS8yOqcGx8GjgxePku8zpReUyboii+tms1NgY= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from esprimo-mx.fritz.box ([79.242.190.212]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MdNY2-1mhvc52tyi-00ZNwC; Thu, 29 Jul 2021 00:16:05 +0200 From: W_Armin@gmx.de To: pali@kernel.org Cc: linux@roeck-us.net, jdelvare@suse.com, linux-hwmon@vger.kernel.org Subject: [PATCH v7 4/6] hwmon: (dell-smm-hwmon) Move variables into a driver private data structure Date: Thu, 29 Jul 2021 00:15:55 +0200 Message-Id: <20210728221557.8891-5-W_Armin@gmx.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210728221557.8891-1-W_Armin@gmx.de> References: <20210728221557.8891-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:4rUzuq045CV1mfaHYD7/jqFcNdHecvh6KZFLRSKKeIVBykjLXWN xCv9xJwJbbcLcG276qAQTAsfj+3LZB/as05sw9qpFDDRN0IUzWqohCAJa18zp+YeRvdHvxx W1qYVjg0wv2WmuS1SNDw7QJxBgpLWynikuZVCInvWVbtIjADXtv/WcbKj8mr+aWBFjoGFVC dnGOifybwkuH3JxBBYiQg== X-UI-Out-Filterresults: notjunk:1;V03:K0:GUBRVPUWFlI=:3XSQfDXovlV8yZdmO7pI8x +foTKQWbxc8nQ1IWAoNVczHiRBRrDjpUTzR+pvP2zl1nMjHi5gybnZNkZ5GXSzNAoKbqjK/kO HfrmUfnzO3Gni+f71VFyTMWMyN34b0rj9uU/5aI2dSuqhfNk0AkzTJknAWTmS1v+YlVRcEqJJ rNY/UL+1G3QrFTXE5VxfzNgh7UV1Nr3o4lss2VskM0SSrkf6cT37LE7pdL+ITNC6MgSoNVcY7 fFvo+kR3fIuCrro780awpFJohT8gGFEmguA5kaRHEm57giBawun9dSN8b0yhEZtJu7ArMx9Ro z223hLIXATDVtlnpN7pkR/tq+uCh7aqwgr2iDeP2phGtjyi/CPYWYVq3PyZBChQJMNtwfnPwh RmNgABazHtoeyPgCWpaAYcMNjdizMxARx6e5Em3mXV8TyzjgJxME9UrMpGC0RsiiCBKGsEHQg 2Cs4pus2DrJQNlLmpVXkyePTKZ5hnS8akoZpDJyjaZBPcWlJMFT/9FWVWHnLS7vfCU2xZM69s dVr7q8M7+TLh8gkk6re2+07zb64wpPIhbf6NVk7NgZYBY35q7hjvuVkp7zFh36C3kEDMz4jN0 Z8hc3gKwqFfaeKd+VOfOpAvz/8Zvgcb3cmr1yEcFMswXTRIoFXdfT0OCL5FNRqeoDXoSXuNRy dLMMXOlLDXQOFeL9GtE8P4WIDJwSncn4KCVqxKIy/DT6Sxeje4b+Oeh3KvPc7GVmRG9ITpQSj a5bPFXmUaJoXTEoiJVZTu1NzQhzdojLNvHS1TAbG7etdy1fw9te7ErAxZB54BNnPQLffClhUb DDbZNxjrpdb4oPAmA8W5jdxmoXsKzRHd+2MmSzOJOwZUal1Ue8Gt2teCL1+W3OUcnRiYjLVPa VocIX1GZYotyySCYWtF42X/7aZlKR5cmbbNojxQ/j66Qa0TePGYL1uonlZg8MY5MXmhDPYpT9 qH1SjDtHrA4fmZJC4jikcgIi8sQkqekHtfyoGSIhUM/laQCgWNDqgkwumczx9rs8t+tw1qog0 HB917oPRpzOK1URtdB1b4TiT+ulX15Zz/qYJnCHXal5jQq/jAFwr9NvJiXLWYEdaSkpbLW/gH zUPIRbcUGCS0NnQ1ZQ2yYTAjo6g2mtscoSh Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org From: Armin Wolf Move Variables into a driver private data structure. Signed-off-by: Armin Wolf --- drivers/hwmon/dell-smm-hwmon.c | 277 ++++++++++++++++++--------------- 1 file changed, 152 insertions(+), 125 deletions(-) -- 2.20.1 diff --git a/drivers/hwmon/dell-smm-hwmon.c b/drivers/hwmon/dell-smm-hwmon.c index da7040f2442e..8841fc1e5872 100644 --- a/drivers/hwmon/dell-smm-hwmon.c +++ b/drivers/hwmon/dell-smm-hwmon.c @@ -60,18 +60,20 @@ #define I8K_POWER_AC 0x05 #define I8K_POWER_BATTERY 0x01 -static DEFINE_MUTEX(i8k_mutex); -static char bios_version[4]; -static char bios_machineid[16]; -static struct device *i8k_hwmon_dev; -static u32 i8k_hwmon_flags; -static uint i8k_fan_mult = I8K_FAN_MULT; -static uint i8k_pwm_mult; -static uint i8k_fan_max = I8K_FAN_HIGH; -static bool disallow_fan_type_call; -static bool disallow_fan_support; -static unsigned int manual_fan; -static unsigned int auto_fan; +struct dell_smm_data { + struct mutex i8k_mutex; /* lock for sensors writes */ + char bios_version[4]; + char bios_machineid[16]; + u32 i8k_hwmon_flags; + uint i8k_fan_mult; + uint i8k_pwm_mult; + uint i8k_fan_max; + bool disallow_fan_type_call; + bool disallow_fan_support; + unsigned int manual_fan; + unsigned int auto_fan; + int types[3]; +}; #define I8K_HWMON_HAVE_TEMP1 (1 << 0) #define I8K_HWMON_HAVE_TEMP2 (1 << 1) @@ -240,11 +242,11 @@ static int i8k_smm(struct smm_regs *regs) /* * Read the fan status. */ -static int i8k_get_fan_status(int fan) +static int i8k_get_fan_status(const struct dell_smm_data *data, int fan) { struct smm_regs regs = { .eax = I8K_SMM_GET_FAN, }; - if (disallow_fan_support) + if (data->disallow_fan_support) return -EINVAL; regs.ebx = fan & 0xff; @@ -254,84 +256,82 @@ static int i8k_get_fan_status(int fan) /* * Read the fan speed in RPM. */ -static int i8k_get_fan_speed(int fan) +static int i8k_get_fan_speed(const struct dell_smm_data *data, int fan) { struct smm_regs regs = { .eax = I8K_SMM_GET_SPEED, }; - if (disallow_fan_support) + if (data->disallow_fan_support) return -EINVAL; regs.ebx = fan & 0xff; - return i8k_smm(®s) ? : (regs.eax & 0xffff) * i8k_fan_mult; + return i8k_smm(®s) ? : (regs.eax & 0xffff) * data->i8k_fan_mult; } /* * Read the fan type. */ -static int _i8k_get_fan_type(int fan) +static int _i8k_get_fan_type(const struct dell_smm_data *data, int fan) { struct smm_regs regs = { .eax = I8K_SMM_GET_FAN_TYPE, }; - if (disallow_fan_support || disallow_fan_type_call) + if (data->disallow_fan_support || data->disallow_fan_type_call) return -EINVAL; regs.ebx = fan & 0xff; return i8k_smm(®s) ? : regs.eax & 0xff; } -static int i8k_get_fan_type(int fan) +static int i8k_get_fan_type(struct dell_smm_data *data, int fan) { /* I8K_SMM_GET_FAN_TYPE SMM call is expensive, so cache values */ - static int types[3] = { INT_MIN, INT_MIN, INT_MIN }; + if (data->types[fan] == INT_MIN) + data->types[fan] = _i8k_get_fan_type(data, fan); - if (types[fan] == INT_MIN) - types[fan] = _i8k_get_fan_type(fan); - - return types[fan]; + return data->types[fan]; } /* * Read the fan nominal rpm for specific fan speed. */ -static int i8k_get_fan_nominal_speed(int fan, int speed) +static int i8k_get_fan_nominal_speed(const struct dell_smm_data *data, int fan, int speed) { struct smm_regs regs = { .eax = I8K_SMM_GET_NOM_SPEED, }; - if (disallow_fan_support) + if (data->disallow_fan_support) return -EINVAL; regs.ebx = (fan & 0xff) | (speed << 8); - return i8k_smm(®s) ? : (regs.eax & 0xffff) * i8k_fan_mult; + return i8k_smm(®s) ? : (regs.eax & 0xffff) * data->i8k_fan_mult; } /* * Enable or disable automatic BIOS fan control support */ -static int i8k_enable_fan_auto_mode(bool enable) +static int i8k_enable_fan_auto_mode(const struct dell_smm_data *data, bool enable) { struct smm_regs regs = { }; - if (disallow_fan_support) + if (data->disallow_fan_support) return -EINVAL; - regs.eax = enable ? auto_fan : manual_fan; + regs.eax = enable ? data->auto_fan : data->manual_fan; return i8k_smm(®s); } /* * Set the fan speed (off, low, high). Returns the new fan status. */ -static int i8k_set_fan(int fan, int speed) +static int i8k_set_fan(const struct dell_smm_data *data, int fan, int speed) { struct smm_regs regs = { .eax = I8K_SMM_SET_FAN, }; - if (disallow_fan_support) + if (data->disallow_fan_support) return -EINVAL; - speed = (speed < 0) ? 0 : ((speed > i8k_fan_max) ? i8k_fan_max : speed); + speed = (speed < 0) ? 0 : ((speed > data->i8k_fan_max) ? data->i8k_fan_max : speed); regs.ebx = (fan & 0xff) | (speed << 8); - return i8k_smm(®s) ? : i8k_get_fan_status(fan); + return i8k_smm(®s) ? : i8k_get_fan_status(data, fan); } static int i8k_get_temp_type(int sensor) @@ -442,7 +442,7 @@ static int i8k_get_power_status(void) */ static int -i8k_ioctl_unlocked(struct file *fp, unsigned int cmd, unsigned long arg) +i8k_ioctl_unlocked(struct file *fp, struct dell_smm_data *data, unsigned int cmd, unsigned long arg) { int val = 0; int speed; @@ -454,12 +454,12 @@ i8k_ioctl_unlocked(struct file *fp, unsigned int cmd, unsigned long arg) switch (cmd) { case I8K_BIOS_VERSION: - if (!isdigit(bios_version[0]) || !isdigit(bios_version[1]) || - !isdigit(bios_version[2])) + if (!isdigit(data->bios_version[0]) || !isdigit(data->bios_version[1]) || + !isdigit(data->bios_version[2])) return -EINVAL; - val = (bios_version[0] << 16) | - (bios_version[1] << 8) | bios_version[2]; + val = (data->bios_version[0] << 16) | + (data->bios_version[1] << 8) | data->bios_version[2]; break; case I8K_MACHINE_ID: @@ -467,7 +467,7 @@ i8k_ioctl_unlocked(struct file *fp, unsigned int cmd, unsigned long arg) return -EPERM; memset(buff, 0, sizeof(buff)); - strlcpy(buff, bios_machineid, sizeof(buff)); + strscpy(buff, data->bios_machineid, sizeof(buff)); break; case I8K_FN_STATUS: @@ -486,14 +486,14 @@ i8k_ioctl_unlocked(struct file *fp, unsigned int cmd, unsigned long arg) if (copy_from_user(&val, argp, sizeof(int))) return -EFAULT; - val = i8k_get_fan_speed(val); + val = i8k_get_fan_speed(data, val); break; case I8K_GET_FAN: if (copy_from_user(&val, argp, sizeof(int))) return -EFAULT; - val = i8k_get_fan_status(val); + val = i8k_get_fan_status(data, val); break; case I8K_SET_FAN: @@ -506,7 +506,7 @@ i8k_ioctl_unlocked(struct file *fp, unsigned int cmd, unsigned long arg) if (copy_from_user(&speed, argp + 1, sizeof(int))) return -EFAULT; - val = i8k_set_fan(val, speed); + val = i8k_set_fan(data, val, speed); break; default: @@ -539,11 +539,12 @@ i8k_ioctl_unlocked(struct file *fp, unsigned int cmd, unsigned long arg) static long i8k_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) { + struct dell_smm_data *data = PDE_DATA(file_inode(fp)); long ret; - mutex_lock(&i8k_mutex); - ret = i8k_ioctl_unlocked(fp, cmd, arg); - mutex_unlock(&i8k_mutex); + mutex_lock(&data->i8k_mutex); + ret = i8k_ioctl_unlocked(fp, data, cmd, arg); + mutex_unlock(&data->i8k_mutex); return ret; } @@ -553,17 +554,18 @@ static long i8k_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) */ static int i8k_proc_show(struct seq_file *seq, void *offset) { + struct dell_smm_data *data = seq->private; int fn_key, cpu_temp, ac_power; int left_fan, right_fan, left_speed, right_speed; - cpu_temp = i8k_get_temp(0); /* 11100 µs */ - left_fan = i8k_get_fan_status(I8K_FAN_LEFT); /* 580 µs */ - right_fan = i8k_get_fan_status(I8K_FAN_RIGHT); /* 580 µs */ - left_speed = i8k_get_fan_speed(I8K_FAN_LEFT); /* 580 µs */ - right_speed = i8k_get_fan_speed(I8K_FAN_RIGHT); /* 580 µs */ - fn_key = i8k_get_fn_status(); /* 750 µs */ + cpu_temp = i8k_get_temp(0); /* 11100 µs */ + left_fan = i8k_get_fan_status(data, I8K_FAN_LEFT); /* 580 µs */ + right_fan = i8k_get_fan_status(data, I8K_FAN_RIGHT); /* 580 µs */ + left_speed = i8k_get_fan_speed(data, I8K_FAN_LEFT); /* 580 µs */ + right_speed = i8k_get_fan_speed(data, I8K_FAN_RIGHT); /* 580 µs */ + fn_key = i8k_get_fn_status(); /* 750 µs */ if (power_status) - ac_power = i8k_get_power_status(); /* 14700 µs */ + ac_power = i8k_get_power_status(); /* 14700 µs */ else ac_power = -1; @@ -583,8 +585,8 @@ static int i8k_proc_show(struct seq_file *seq, void *offset) */ seq_printf(seq, "%s %s %s %d %d %d %d %d %d %d\n", I8K_PROC_FMT, - bios_version, - (restricted && !capable(CAP_SYS_ADMIN)) ? "-1" : bios_machineid, + data->bios_version, + (restricted && !capable(CAP_SYS_ADMIN)) ? "-1" : data->bios_machineid, cpu_temp, left_fan, right_fan, left_speed, right_speed, ac_power, fn_key); @@ -594,7 +596,7 @@ static int i8k_proc_show(struct seq_file *seq, void *offset) static int i8k_open_fs(struct inode *inode, struct file *file) { - return single_open(file, i8k_proc_show, NULL); + return single_open(file, i8k_proc_show, PDE_DATA(inode)); } static const struct proc_ops i8k_proc_ops = { @@ -612,8 +614,10 @@ static void i8k_exit_procfs(void *param) static void __init i8k_init_procfs(struct device *dev) { + struct dell_smm_data *data = dev_get_drvdata(dev); + /* Register the proc entry */ - proc_create("i8k", 0, NULL, &i8k_proc_ops); + proc_create_data("i8k", 0, NULL, &i8k_proc_ops, data); devm_add_action_or_reset(dev, i8k_exit_procfs, NULL); } @@ -670,6 +674,7 @@ static ssize_t i8k_hwmon_fan_label_show(struct device *dev, struct device_attribute *devattr, char *buf) { + struct dell_smm_data *data = dev_get_drvdata(dev); static const char * const labels[] = { "Processor Fan", "Motherboard Fan", @@ -682,7 +687,7 @@ static ssize_t i8k_hwmon_fan_label_show(struct device *dev, bool dock = false; int type; - type = i8k_get_fan_type(index); + type = i8k_get_fan_type(data, index); if (type < 0) return type; @@ -700,10 +705,11 @@ static ssize_t i8k_hwmon_fan_label_show(struct device *dev, static ssize_t i8k_hwmon_fan_show(struct device *dev, struct device_attribute *devattr, char *buf) { + struct dell_smm_data *data = dev_get_drvdata(dev); int index = to_sensor_dev_attr(devattr)->index; int fan_speed; - fan_speed = i8k_get_fan_speed(index); + fan_speed = i8k_get_fan_speed(data, index); if (fan_speed < 0) return fan_speed; return sprintf(buf, "%d\n", fan_speed); @@ -712,19 +718,21 @@ static ssize_t i8k_hwmon_fan_show(struct device *dev, static ssize_t i8k_hwmon_pwm_show(struct device *dev, struct device_attribute *devattr, char *buf) { + struct dell_smm_data *data = dev_get_drvdata(dev); int index = to_sensor_dev_attr(devattr)->index; int status; - status = i8k_get_fan_status(index); + status = i8k_get_fan_status(data, index); if (status < 0) return -EIO; - return sprintf(buf, "%d\n", clamp_val(status * i8k_pwm_mult, 0, 255)); + return sprintf(buf, "%d\n", clamp_val(status * data->i8k_pwm_mult, 0, 255)); } static ssize_t i8k_hwmon_pwm_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { + struct dell_smm_data *data = dev_get_drvdata(dev); int index = to_sensor_dev_attr(attr)->index; unsigned long val; int err; @@ -732,11 +740,11 @@ static ssize_t i8k_hwmon_pwm_store(struct device *dev, err = kstrtoul(buf, 10, &val); if (err) return err; - val = clamp_val(DIV_ROUND_CLOSEST(val, i8k_pwm_mult), 0, i8k_fan_max); + val = clamp_val(DIV_ROUND_CLOSEST(val, data->i8k_pwm_mult), 0, data->i8k_fan_max); - mutex_lock(&i8k_mutex); - err = i8k_set_fan(index, val); - mutex_unlock(&i8k_mutex); + mutex_lock(&data->i8k_mutex); + err = i8k_set_fan(data, index, val); + mutex_unlock(&data->i8k_mutex); return err < 0 ? -EIO : count; } @@ -745,11 +753,12 @@ static ssize_t i8k_hwmon_pwm_enable_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { + struct dell_smm_data *data = dev_get_drvdata(dev); int err; bool enable; unsigned long val; - if (!auto_fan) + if (!data->auto_fan) return -ENODEV; err = kstrtoul(buf, 10, &val); @@ -763,9 +772,9 @@ static ssize_t i8k_hwmon_pwm_enable_store(struct device *dev, else return -EINVAL; - mutex_lock(&i8k_mutex); - err = i8k_enable_fan_auto_mode(enable); - mutex_unlock(&i8k_mutex); + mutex_lock(&data->i8k_mutex); + err = i8k_enable_fan_auto_mode(data, enable); + mutex_unlock(&data->i8k_mutex); return err ? err : count; } @@ -838,53 +847,56 @@ static struct attribute *i8k_attrs[] = { static umode_t i8k_is_visible(struct kobject *kobj, struct attribute *attr, int index) { - if (disallow_fan_support && index >= 20) + struct device *dev = kobj_to_dev(kobj); + struct dell_smm_data *data = dev_get_drvdata(dev); + + if (data->disallow_fan_support && index >= 20) return 0; - if (disallow_fan_type_call && + if (data->disallow_fan_type_call && (index == 21 || index == 25 || index == 28)) return 0; if (index >= 0 && index <= 1 && - !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP1)) + !(data->i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP1)) return 0; if (index >= 2 && index <= 3 && - !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP2)) + !(data->i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP2)) return 0; if (index >= 4 && index <= 5 && - !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP3)) + !(data->i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP3)) return 0; if (index >= 6 && index <= 7 && - !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP4)) + !(data->i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP4)) return 0; if (index >= 8 && index <= 9 && - !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP5)) + !(data->i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP5)) return 0; if (index >= 10 && index <= 11 && - !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP6)) + !(data->i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP6)) return 0; if (index >= 12 && index <= 13 && - !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP7)) + !(data->i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP7)) return 0; if (index >= 14 && index <= 15 && - !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP8)) + !(data->i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP8)) return 0; if (index >= 16 && index <= 17 && - !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP9)) + !(data->i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP9)) return 0; if (index >= 18 && index <= 19 && - !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP10)) + !(data->i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP10)) return 0; if (index >= 20 && index <= 23 && - !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN1)) + !(data->i8k_hwmon_flags & I8K_HWMON_HAVE_FAN1)) return 0; if (index >= 24 && index <= 26 && - !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN2)) + !(data->i8k_hwmon_flags & I8K_HWMON_HAVE_FAN2)) return 0; if (index >= 27 && index <= 29 && - !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN3)) + !(data->i8k_hwmon_flags & I8K_HWMON_HAVE_FAN3)) return 0; - if (index == 23 && !auto_fan) + if (index == 23 && !data->auto_fan) return 0; return attr->mode; @@ -898,65 +910,65 @@ __ATTRIBUTE_GROUPS(i8k); static int __init dell_smm_init_hwmon(struct device *dev) { + struct dell_smm_data *data = dev_get_drvdata(dev); + struct device *i8k_hwmon_dev; int err; - i8k_hwmon_flags = 0; - /* CPU temperature attributes, if temperature type is OK */ err = i8k_get_temp_type(0); if (err >= 0) - i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP1; + data->i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP1; /* check for additional temperature sensors */ err = i8k_get_temp_type(1); if (err >= 0) - i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP2; + data->i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP2; err = i8k_get_temp_type(2); if (err >= 0) - i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP3; + data->i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP3; err = i8k_get_temp_type(3); if (err >= 0) - i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP4; + data->i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP4; err = i8k_get_temp_type(4); if (err >= 0) - i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP5; + data->i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP5; err = i8k_get_temp_type(5); if (err >= 0) - i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP6; + data->i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP6; err = i8k_get_temp_type(6); if (err >= 0) - i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP7; + data->i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP7; err = i8k_get_temp_type(7); if (err >= 0) - i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP8; + data->i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP8; err = i8k_get_temp_type(8); if (err >= 0) - i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP9; + data->i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP9; err = i8k_get_temp_type(9); if (err >= 0) - i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP10; + data->i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP10; /* First fan attributes, if fan status or type is OK */ - err = i8k_get_fan_status(0); + err = i8k_get_fan_status(data, 0); if (err < 0) - err = i8k_get_fan_type(0); + err = i8k_get_fan_type(data, 0); if (err >= 0) - i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN1; + data->i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN1; /* Second fan attributes, if fan status or type is OK */ - err = i8k_get_fan_status(1); + err = i8k_get_fan_status(data, 1); if (err < 0) - err = i8k_get_fan_type(1); + err = i8k_get_fan_type(data, 1); if (err >= 0) - i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN2; + data->i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN2; /* Third fan attributes, if fan status or type is OK */ - err = i8k_get_fan_status(2); + err = i8k_get_fan_status(data, 2); if (err < 0) - err = i8k_get_fan_type(2); + err = i8k_get_fan_type(data, 2); if (err >= 0) - i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN3; + data->i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN3; - i8k_hwmon_dev = devm_hwmon_device_register_with_groups(dev, "dell_smm", NULL, i8k_groups); + i8k_hwmon_dev = devm_hwmon_device_register_with_groups(dev, "dell_smm", data, i8k_groups); return PTR_ERR_OR_ZERO(i8k_hwmon_dev); } @@ -1217,25 +1229,38 @@ static struct dmi_system_id i8k_whitelist_fan_control[] __initdata = { static int __init dell_smm_probe(struct platform_device *pdev) { + struct dell_smm_data *data; const struct dmi_system_id *id, *fan_control; int fan, ret; + data = devm_kzalloc(&pdev->dev, sizeof(struct dell_smm_data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + mutex_init(&data->i8k_mutex); + data->i8k_fan_mult = I8K_FAN_MULT; + data->i8k_fan_max = I8K_FAN_HIGH; + data->types[0] = INT_MIN; + data->types[1] = INT_MIN; + data->types[2] = INT_MIN; + platform_set_drvdata(pdev, data); + if (dmi_check_system(i8k_blacklist_fan_support_dmi_table)) { - pr_warn("broken Dell BIOS detected, disallow fan support\n"); + dev_warn(&pdev->dev, "broken Dell BIOS detected, disallow fan support\n"); if (!force) - disallow_fan_support = true; + data->disallow_fan_support = true; } if (dmi_check_system(i8k_blacklist_fan_type_dmi_table)) { - pr_warn("broken Dell BIOS detected, disallow fan type call\n"); + dev_warn(&pdev->dev, "broken Dell BIOS detected, disallow fan type call\n"); if (!force) - disallow_fan_type_call = true; + data->disallow_fan_type_call = true; } - strscpy(bios_version, i8k_get_dmi_data(DMI_BIOS_VERSION), - sizeof(bios_version)); - strscpy(bios_machineid, i8k_get_dmi_data(DMI_PRODUCT_SERIAL), - sizeof(bios_machineid)); + strscpy(data->bios_version, i8k_get_dmi_data(DMI_BIOS_VERSION), + sizeof(data->bios_version)); + strscpy(data->bios_machineid, i8k_get_dmi_data(DMI_PRODUCT_SERIAL), + sizeof(data->bios_machineid)); /* * Set fan multiplier and maximal fan speed from dmi config @@ -1247,20 +1272,21 @@ static int __init dell_smm_probe(struct platform_device *pdev) if (!fan_mult && conf->fan_mult) fan_mult = conf->fan_mult; + if (!fan_max && conf->fan_max) fan_max = conf->fan_max; } - i8k_fan_max = fan_max ? : I8K_FAN_HIGH; /* Must not be 0 */ - i8k_pwm_mult = DIV_ROUND_UP(255, i8k_fan_max); + data->i8k_fan_max = fan_max ? : I8K_FAN_HIGH; /* Must not be 0 */ + data->i8k_pwm_mult = DIV_ROUND_UP(255, data->i8k_fan_max); fan_control = dmi_first_match(i8k_whitelist_fan_control); if (fan_control && fan_control->driver_data) { - const struct i8k_fan_control_data *data = fan_control->driver_data; + const struct i8k_fan_control_data *control = fan_control->driver_data; - manual_fan = data->manual_fan; - auto_fan = data->auto_fan; - pr_info("enabling support for setting automatic/manual fan control\n"); + data->manual_fan = control->manual_fan; + data->auto_fan = control->auto_fan; + dev_info(&pdev->dev, "enabling support for setting automatic/manual fan control\n"); } if (!fan_mult) { @@ -1269,16 +1295,17 @@ static int __init dell_smm_probe(struct platform_device *pdev) * If fan reports rpm value too high then set multiplier to 1 */ for (fan = 0; fan < 2; ++fan) { - ret = i8k_get_fan_nominal_speed(fan, i8k_fan_max); + ret = i8k_get_fan_nominal_speed(data, fan, data->i8k_fan_max); if (ret < 0) continue; + if (ret > I8K_FAN_MAX_RPM) - i8k_fan_mult = 1; + data->i8k_fan_mult = 1; break; } } else { /* Fan multiplier was specified in module param or in dmi */ - i8k_fan_mult = fan_mult; + data->i8k_fan_mult = fan_mult; } ret = dell_smm_init_hwmon(&pdev->dev); From patchwork Wed Jul 28 22:15:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 12406911 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D95FDC4320A for ; Wed, 28 Jul 2021 22:16:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B63496103C for ; Wed, 28 Jul 2021 22:16:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232080AbhG1WQ1 (ORCPT ); Wed, 28 Jul 2021 18:16:27 -0400 Received: from mout.gmx.net ([212.227.15.15]:39281 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232116AbhG1WQ0 (ORCPT ); Wed, 28 Jul 2021 18:16:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1627510567; bh=SL6aGvxif8jrE8WA7JkCfFWZf+IaZtc2jh5+2Tvx50Y=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=gfnPIOWhejx+cJJWJED7j6roMfZbllMMSxhMy0YpowtdrinqZdQWHe8PxEAoNSeux BaIRBebw429YM+33eBTXUMnBe3jZLIS45IxQycp2e7OYCcwtUxRVpV7UyBGGhuSyyu 49n0xkXv0DidLdoSDOufpVCo0Yqpap/SrIzWgPzM= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from esprimo-mx.fritz.box ([79.242.190.212]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1Mdeb5-1mheUw0VOr-00Zdv0; Thu, 29 Jul 2021 00:16:07 +0200 From: W_Armin@gmx.de To: pali@kernel.org Cc: linux@roeck-us.net, jdelvare@suse.com, linux-hwmon@vger.kernel.org Subject: [PATCH v7 5/6] hwmon: (dell-smm-hwmon) Convert to devm_hwmon_device_register_with_info() Date: Thu, 29 Jul 2021 00:15:56 +0200 Message-Id: <20210728221557.8891-6-W_Armin@gmx.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210728221557.8891-1-W_Armin@gmx.de> References: <20210728221557.8891-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:BRR1aKmPpXTlJnjEWRPi+qIz/L+F+fNB52PQ8jRw2P35ESzMnfI CO1c8vRuimK8xD7VWnsjbPAoDA+te6ERYIe6aeTIvbwVYSmb1IzH0NmIJO+V99Cr6tOVVwO NCkz9bBpAt3Y6skafXRrQc7fk6Kgj762otOHsuAcxFtY2nduHEJeCAb1dNjLW8im1g/X04j 1CDfOiupUd7BU4t9uSxUg== X-UI-Out-Filterresults: notjunk:1;V03:K0:QDBOh1Bloeg=:bUt/pGcRSfOMuk2olij77+ gmz06fuKbW7BLD6/IZH4kOKfXGUCiD7oDsb/G3FYNC7R16RC/4z/Bq4abr/IaJchtSqS/3OXm nybEAon6MZca/nNN2C2f6At8yj883qbrxMI2RjutFWn99CAS0jqbWe5cI/Y06X0dcMN+5xIXA MOiUNC/aJ6oLOABec69t9kjMzW80XX0dkEtTMJ9/oh/MNx1FdEuPyBNQt5SSumjKE7oMVR46v FJvXwXWhH0SZAbmeENpJ9uK+sBaK5kNRIuHY6/pm1kvXxiSQSTFdlfDZ6rQfn4rsx2pj46LlM ITYYdxgiKTRarlOy4sgBg0GQXbQaGpvdq1k8dcvj5doSQINllweiUeCg4uReACA9pVAAWbWzV k6rZOJrLg0BmR0+B0KSKo7EkpN0a9iGf9q6GV+XOy+wh5DIjhDjhh0CPO4JEAfIHM/TK6FiVM ugD3gZ9x2S2BsFq0JfUgu5npPAnbfPSnvXlO5QDy9Bd+q4lRMwKuDn/noQL3au4fvbJWjHOvo sfGpFmWKmR1OTp2qPIhRml0pbGFwj90qBW5uBBCiW7zO2R5snxCCkJ1PpvBY7hg1wlLwjyJgM SLVVfvfWCuHywIfkZwzKWNssgdWaxaKVBppaEzsbQa7erg1VRav/SNWfUXekqm59rfVy2Gi7n zjszaVzBCTrrpgSi6rzFHEwYosX0XSFq5JlP5TKd2NB+WupN9U6hOXd2scKb81G6Y3z/+Q4qX JyDS1cI19eilbkr9Bk2ajsDfsVNfewpuaW69xiVVfKc9006THw7sq2L8s7mpfCMQtGpXBY9Se x7Rk1cJcXzbtdXaUf9kc8ICan92V1Of4Vqb1TmGrw08ECDM9lwTmfysxmJg+Bxbr1/I78T5Bg szG36pvMXOVVbfJY7vIlXQmkGpiV8DWBFbT903dKFvtwzdnbCUoeYx2UuyMufS/slXvq2zyFP K0fhJHWMEYfLkul6h+jFqjz9Pu40+WC/6G6XX/q5VdVRMa9K91C2a2nQzs4HTcucGw2HUTReN ZuhfRtCTKQ3S/1VCBwIaLpdn7YnXIKeO2U/JTIzVf8sDYftRPJd63nHn3NhC74nMF++5d4reI s7KbFkeWEw7634HaXoy6usWxzvTedOaOex+ Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org From: Armin Wolf Convert to new registration API to get rid of attribute magic numbers and reduce module size. Signed-off-by: Armin Wolf --- drivers/hwmon/dell-smm-hwmon.c | 589 ++++++++++++++++----------------- 1 file changed, 279 insertions(+), 310 deletions(-) -- 2.20.1 diff --git a/drivers/hwmon/dell-smm-hwmon.c b/drivers/hwmon/dell-smm-hwmon.c index 8841fc1e5872..aaf864dbe53a 100644 --- a/drivers/hwmon/dell-smm-hwmon.c +++ b/drivers/hwmon/dell-smm-hwmon.c @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include @@ -60,11 +59,13 @@ #define I8K_POWER_AC 0x05 #define I8K_POWER_BATTERY 0x01 +#define DELL_SMM_NO_TEMP 10 +#define DELL_SMM_NO_FANS 3 + struct dell_smm_data { struct mutex i8k_mutex; /* lock for sensors writes */ char bios_version[4]; char bios_machineid[16]; - u32 i8k_hwmon_flags; uint i8k_fan_mult; uint i8k_pwm_mult; uint i8k_fan_max; @@ -72,23 +73,11 @@ struct dell_smm_data { bool disallow_fan_support; unsigned int manual_fan; unsigned int auto_fan; - int types[3]; + int temp_type[DELL_SMM_NO_TEMP]; + bool fan[DELL_SMM_NO_FANS]; + int fan_type[DELL_SMM_NO_FANS]; }; -#define I8K_HWMON_HAVE_TEMP1 (1 << 0) -#define I8K_HWMON_HAVE_TEMP2 (1 << 1) -#define I8K_HWMON_HAVE_TEMP3 (1 << 2) -#define I8K_HWMON_HAVE_TEMP4 (1 << 3) -#define I8K_HWMON_HAVE_TEMP5 (1 << 4) -#define I8K_HWMON_HAVE_TEMP6 (1 << 5) -#define I8K_HWMON_HAVE_TEMP7 (1 << 6) -#define I8K_HWMON_HAVE_TEMP8 (1 << 7) -#define I8K_HWMON_HAVE_TEMP9 (1 << 8) -#define I8K_HWMON_HAVE_TEMP10 (1 << 9) -#define I8K_HWMON_HAVE_FAN1 (1 << 10) -#define I8K_HWMON_HAVE_FAN2 (1 << 11) -#define I8K_HWMON_HAVE_FAN3 (1 << 12) - MODULE_AUTHOR("Massimo Dal Zotto (dz@debian.org)"); MODULE_AUTHOR("Pali Rohár "); MODULE_DESCRIPTION("Dell laptop SMM BIOS hwmon driver"); @@ -130,6 +119,33 @@ struct smm_regs { unsigned int edi __packed; }; +static const char * const temp_labels[] = { + "CPU", + "GPU", + "SODIMM", + "Other", + "Ambient", + "Other", +}; + +static const char * const fan_labels[] = { + "Processor Fan", + "Motherboard Fan", + "Video Fan", + "Power Supply Fan", + "Chipset Fan", + "Other Fan", +}; + +static const char * const docking_labels[] = { + "Docking Processor Fan", + "Docking Motherboard Fan", + "Docking Video Fan", + "Docking Power Supply Fan", + "Docking Chipset Fan", + "Docking Other Fan", +}; + static inline const char __init *i8k_get_dmi_data(int field) { const char *dmi_data = dmi_get_system_info(field); @@ -284,10 +300,10 @@ static int _i8k_get_fan_type(const struct dell_smm_data *data, int fan) static int i8k_get_fan_type(struct dell_smm_data *data, int fan) { /* I8K_SMM_GET_FAN_TYPE SMM call is expensive, so cache values */ - if (data->types[fan] == INT_MIN) - data->types[fan] = _i8k_get_fan_type(data, fan); + if (data->fan_type[fan] == INT_MIN) + data->fan_type[fan] = _i8k_get_fan_type(data, fan); - return data->types[fan]; + return data->fan_type[fan]; } /* @@ -334,7 +350,7 @@ static int i8k_set_fan(const struct dell_smm_data *data, int fan, int speed) return i8k_smm(®s) ? : i8k_get_fan_status(data, fan); } -static int i8k_get_temp_type(int sensor) +static int __init i8k_get_temp_type(int sensor) { struct smm_regs regs = { .eax = I8K_SMM_GET_TEMP_TYPE, }; @@ -634,343 +650,299 @@ static void __init i8k_init_procfs(struct device *dev) * Hwmon interface */ -static ssize_t i8k_hwmon_temp_label_show(struct device *dev, - struct device_attribute *devattr, - char *buf) +static umode_t dell_smm_is_visible(const void *drvdata, enum hwmon_sensor_types type, u32 attr, + int channel) { - static const char * const labels[] = { - "CPU", - "GPU", - "SODIMM", - "Other", - "Ambient", - "Other", - }; - int index = to_sensor_dev_attr(devattr)->index; - int type; + const struct dell_smm_data *data = drvdata; - type = i8k_get_temp_type(index); - if (type < 0) - return type; - if (type >= ARRAY_SIZE(labels)) - type = ARRAY_SIZE(labels) - 1; - return sprintf(buf, "%s\n", labels[type]); + switch (type) { + case hwmon_temp: + switch (attr) { + case hwmon_temp_input: + case hwmon_temp_label: + if (data->temp_type[channel] >= 0) + return 0444; + + break; + default: + break; + } + break; + case hwmon_fan: + if (data->disallow_fan_support) + break; + + switch (attr) { + case hwmon_fan_input: + if (data->fan[channel]) + return 0444; + + break; + case hwmon_fan_label: + if (data->fan[channel] && !data->disallow_fan_type_call) + return 0444; + + break; + default: + break; + } + break; + case hwmon_pwm: + if (data->disallow_fan_support) + break; + + switch (attr) { + case hwmon_pwm_input: + if (data->fan[channel]) + return 0644; + + break; + case hwmon_pwm_enable: + if (data->auto_fan) + /* + * There is no command for retrieve the current status + * from BIOS, and userspace/firmware itself can change + * it. + * Thus we can only provide write-only access for now. + */ + return 0200; + + break; + default: + break; + } + break; + default: + break; + } + + return 0; } -static ssize_t i8k_hwmon_temp_show(struct device *dev, - struct device_attribute *devattr, - char *buf) +static int dell_smm_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel, + long *val) { - int index = to_sensor_dev_attr(devattr)->index; - int temp; + struct dell_smm_data *data = dev_get_drvdata(dev); + int ret; + + switch (type) { + case hwmon_temp: + switch (attr) { + case hwmon_temp_input: + ret = i8k_get_temp(channel); + if (ret < 0) + return ret; + + *val = ret * 1000; + + return 0; + default: + break; + } + break; + case hwmon_fan: + switch (attr) { + case hwmon_fan_input: + ret = i8k_get_fan_speed(data, channel); + if (ret < 0) + return ret; - temp = i8k_get_temp(index); - if (temp < 0) - return temp; - return sprintf(buf, "%d\n", temp * 1000); + *val = ret; + + return 0; + default: + break; + } + break; + case hwmon_pwm: + switch (attr) { + case hwmon_pwm_input: + ret = i8k_get_fan_status(data, channel); + if (ret < 0) + return ret; + + *val = clamp_val(ret * data->i8k_pwm_mult, 0, 255); + + return 0; + default: + break; + } + break; + default: + break; + } + + return -EOPNOTSUPP; } -static ssize_t i8k_hwmon_fan_label_show(struct device *dev, - struct device_attribute *devattr, - char *buf) +static const char *dell_smm_fan_label(struct dell_smm_data *data, int channel) { - struct dell_smm_data *data = dev_get_drvdata(dev); - static const char * const labels[] = { - "Processor Fan", - "Motherboard Fan", - "Video Fan", - "Power Supply Fan", - "Chipset Fan", - "Other Fan", - }; - int index = to_sensor_dev_attr(devattr)->index; bool dock = false; - int type; + int type = i8k_get_fan_type(data, channel); - type = i8k_get_fan_type(data, index); if (type < 0) - return type; + return ERR_PTR(type); if (type & 0x10) { dock = true; type &= 0x0F; } - if (type >= ARRAY_SIZE(labels)) - type = (ARRAY_SIZE(labels) - 1); + if (type >= ARRAY_SIZE(fan_labels)) + type = ARRAY_SIZE(fan_labels) - 1; - return sprintf(buf, "%s%s\n", (dock ? "Docking " : ""), labels[type]); + return dock ? docking_labels[type] : fan_labels[type]; } -static ssize_t i8k_hwmon_fan_show(struct device *dev, - struct device_attribute *devattr, char *buf) +static int dell_smm_read_string(struct device *dev, enum hwmon_sensor_types type, u32 attr, + int channel, const char **str) { struct dell_smm_data *data = dev_get_drvdata(dev); - int index = to_sensor_dev_attr(devattr)->index; - int fan_speed; - - fan_speed = i8k_get_fan_speed(data, index); - if (fan_speed < 0) - return fan_speed; - return sprintf(buf, "%d\n", fan_speed); -} -static ssize_t i8k_hwmon_pwm_show(struct device *dev, - struct device_attribute *devattr, char *buf) -{ - struct dell_smm_data *data = dev_get_drvdata(dev); - int index = to_sensor_dev_attr(devattr)->index; - int status; + switch (type) { + case hwmon_temp: + switch (attr) { + case hwmon_temp_label: + *str = temp_labels[data->temp_type[channel]]; + return 0; + default: + break; + } + break; + case hwmon_fan: + switch (attr) { + case hwmon_fan_label: + *str = dell_smm_fan_label(data, channel); + return PTR_ERR_OR_ZERO(*str); + default: + break; + } + break; + default: + break; + } - status = i8k_get_fan_status(data, index); - if (status < 0) - return -EIO; - return sprintf(buf, "%d\n", clamp_val(status * data->i8k_pwm_mult, 0, 255)); + return -EOPNOTSUPP; } -static ssize_t i8k_hwmon_pwm_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) +static int dell_smm_write(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel, + long val) { struct dell_smm_data *data = dev_get_drvdata(dev); - int index = to_sensor_dev_attr(attr)->index; - unsigned long val; + unsigned long pwm; + bool enable; int err; - err = kstrtoul(buf, 10, &val); - if (err) - return err; - val = clamp_val(DIV_ROUND_CLOSEST(val, data->i8k_pwm_mult), 0, data->i8k_fan_max); + switch (type) { + case hwmon_pwm: + switch (attr) { + case hwmon_pwm_input: + pwm = clamp_val(DIV_ROUND_CLOSEST(val, data->i8k_pwm_mult), 0, + data->i8k_fan_max); - mutex_lock(&data->i8k_mutex); - err = i8k_set_fan(data, index, val); - mutex_unlock(&data->i8k_mutex); + mutex_lock(&data->i8k_mutex); + err = i8k_set_fan(data, channel, pwm); + mutex_unlock(&data->i8k_mutex); - return err < 0 ? -EIO : count; -} + if (err < 0) + return err; -static ssize_t i8k_hwmon_pwm_enable_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) -{ - struct dell_smm_data *data = dev_get_drvdata(dev); - int err; - bool enable; - unsigned long val; + return 0; + case hwmon_pwm_enable: + if (!val) + return -EINVAL; - if (!data->auto_fan) - return -ENODEV; + if (val == 1) + enable = false; + else + enable = true; - err = kstrtoul(buf, 10, &val); - if (err) - return err; + mutex_lock(&data->i8k_mutex); + err = i8k_enable_fan_auto_mode(data, enable); + mutex_unlock(&data->i8k_mutex); - if (val == 1) - enable = false; - else if (val == 2) - enable = true; - else - return -EINVAL; + if (err < 0) + return err; - mutex_lock(&data->i8k_mutex); - err = i8k_enable_fan_auto_mode(data, enable); - mutex_unlock(&data->i8k_mutex); + return 0; + default: + break; + } + break; + default: + break; + } - return err ? err : count; + return -EOPNOTSUPP; } -static SENSOR_DEVICE_ATTR_RO(temp1_input, i8k_hwmon_temp, 0); -static SENSOR_DEVICE_ATTR_RO(temp1_label, i8k_hwmon_temp_label, 0); -static SENSOR_DEVICE_ATTR_RO(temp2_input, i8k_hwmon_temp, 1); -static SENSOR_DEVICE_ATTR_RO(temp2_label, i8k_hwmon_temp_label, 1); -static SENSOR_DEVICE_ATTR_RO(temp3_input, i8k_hwmon_temp, 2); -static SENSOR_DEVICE_ATTR_RO(temp3_label, i8k_hwmon_temp_label, 2); -static SENSOR_DEVICE_ATTR_RO(temp4_input, i8k_hwmon_temp, 3); -static SENSOR_DEVICE_ATTR_RO(temp4_label, i8k_hwmon_temp_label, 3); -static SENSOR_DEVICE_ATTR_RO(temp5_input, i8k_hwmon_temp, 4); -static SENSOR_DEVICE_ATTR_RO(temp5_label, i8k_hwmon_temp_label, 4); -static SENSOR_DEVICE_ATTR_RO(temp6_input, i8k_hwmon_temp, 5); -static SENSOR_DEVICE_ATTR_RO(temp6_label, i8k_hwmon_temp_label, 5); -static SENSOR_DEVICE_ATTR_RO(temp7_input, i8k_hwmon_temp, 6); -static SENSOR_DEVICE_ATTR_RO(temp7_label, i8k_hwmon_temp_label, 6); -static SENSOR_DEVICE_ATTR_RO(temp8_input, i8k_hwmon_temp, 7); -static SENSOR_DEVICE_ATTR_RO(temp8_label, i8k_hwmon_temp_label, 7); -static SENSOR_DEVICE_ATTR_RO(temp9_input, i8k_hwmon_temp, 8); -static SENSOR_DEVICE_ATTR_RO(temp9_label, i8k_hwmon_temp_label, 8); -static SENSOR_DEVICE_ATTR_RO(temp10_input, i8k_hwmon_temp, 9); -static SENSOR_DEVICE_ATTR_RO(temp10_label, i8k_hwmon_temp_label, 9); -static SENSOR_DEVICE_ATTR_RO(fan1_input, i8k_hwmon_fan, 0); -static SENSOR_DEVICE_ATTR_RO(fan1_label, i8k_hwmon_fan_label, 0); -static SENSOR_DEVICE_ATTR_RW(pwm1, i8k_hwmon_pwm, 0); -static SENSOR_DEVICE_ATTR_WO(pwm1_enable, i8k_hwmon_pwm_enable, 0); -static SENSOR_DEVICE_ATTR_RO(fan2_input, i8k_hwmon_fan, 1); -static SENSOR_DEVICE_ATTR_RO(fan2_label, i8k_hwmon_fan_label, 1); -static SENSOR_DEVICE_ATTR_RW(pwm2, i8k_hwmon_pwm, 1); -static SENSOR_DEVICE_ATTR_RO(fan3_input, i8k_hwmon_fan, 2); -static SENSOR_DEVICE_ATTR_RO(fan3_label, i8k_hwmon_fan_label, 2); -static SENSOR_DEVICE_ATTR_RW(pwm3, i8k_hwmon_pwm, 2); - -static struct attribute *i8k_attrs[] = { - &sensor_dev_attr_temp1_input.dev_attr.attr, /* 0 */ - &sensor_dev_attr_temp1_label.dev_attr.attr, /* 1 */ - &sensor_dev_attr_temp2_input.dev_attr.attr, /* 2 */ - &sensor_dev_attr_temp2_label.dev_attr.attr, /* 3 */ - &sensor_dev_attr_temp3_input.dev_attr.attr, /* 4 */ - &sensor_dev_attr_temp3_label.dev_attr.attr, /* 5 */ - &sensor_dev_attr_temp4_input.dev_attr.attr, /* 6 */ - &sensor_dev_attr_temp4_label.dev_attr.attr, /* 7 */ - &sensor_dev_attr_temp5_input.dev_attr.attr, /* 8 */ - &sensor_dev_attr_temp5_label.dev_attr.attr, /* 9 */ - &sensor_dev_attr_temp6_input.dev_attr.attr, /* 10 */ - &sensor_dev_attr_temp6_label.dev_attr.attr, /* 11 */ - &sensor_dev_attr_temp7_input.dev_attr.attr, /* 12 */ - &sensor_dev_attr_temp7_label.dev_attr.attr, /* 13 */ - &sensor_dev_attr_temp8_input.dev_attr.attr, /* 14 */ - &sensor_dev_attr_temp8_label.dev_attr.attr, /* 15 */ - &sensor_dev_attr_temp9_input.dev_attr.attr, /* 16 */ - &sensor_dev_attr_temp9_label.dev_attr.attr, /* 17 */ - &sensor_dev_attr_temp10_input.dev_attr.attr, /* 18 */ - &sensor_dev_attr_temp10_label.dev_attr.attr, /* 19 */ - &sensor_dev_attr_fan1_input.dev_attr.attr, /* 20 */ - &sensor_dev_attr_fan1_label.dev_attr.attr, /* 21 */ - &sensor_dev_attr_pwm1.dev_attr.attr, /* 22 */ - &sensor_dev_attr_pwm1_enable.dev_attr.attr, /* 23 */ - &sensor_dev_attr_fan2_input.dev_attr.attr, /* 24 */ - &sensor_dev_attr_fan2_label.dev_attr.attr, /* 25 */ - &sensor_dev_attr_pwm2.dev_attr.attr, /* 26 */ - &sensor_dev_attr_fan3_input.dev_attr.attr, /* 27 */ - &sensor_dev_attr_fan3_label.dev_attr.attr, /* 28 */ - &sensor_dev_attr_pwm3.dev_attr.attr, /* 29 */ +static const struct hwmon_ops dell_smm_ops = { + .is_visible = dell_smm_is_visible, + .read = dell_smm_read, + .read_string = dell_smm_read_string, + .write = dell_smm_write, +}; + +static const struct hwmon_channel_info *dell_smm_info[] = { + HWMON_CHANNEL_INFO(chip, HWMON_C_REGISTER_TZ), + HWMON_CHANNEL_INFO(temp, + HWMON_T_INPUT | HWMON_T_LABEL, + HWMON_T_INPUT | HWMON_T_LABEL, + HWMON_T_INPUT | HWMON_T_LABEL, + HWMON_T_INPUT | HWMON_T_LABEL, + HWMON_T_INPUT | HWMON_T_LABEL, + HWMON_T_INPUT | HWMON_T_LABEL, + HWMON_T_INPUT | HWMON_T_LABEL, + HWMON_T_INPUT | HWMON_T_LABEL, + HWMON_T_INPUT | HWMON_T_LABEL, + HWMON_T_INPUT | HWMON_T_LABEL + ), + HWMON_CHANNEL_INFO(fan, + HWMON_F_INPUT | HWMON_F_LABEL, + HWMON_F_INPUT | HWMON_F_LABEL, + HWMON_F_INPUT | HWMON_F_LABEL + ), + HWMON_CHANNEL_INFO(pwm, + HWMON_PWM_INPUT | HWMON_PWM_ENABLE, + HWMON_PWM_INPUT, + HWMON_PWM_INPUT + ), NULL }; -static umode_t i8k_is_visible(struct kobject *kobj, struct attribute *attr, - int index) +static const struct hwmon_chip_info dell_smm_chip_info = { + .ops = &dell_smm_ops, + .info = dell_smm_info, +}; + +static int __init dell_smm_init_hwmon(struct device *dev) { - struct device *dev = kobj_to_dev(kobj); struct dell_smm_data *data = dev_get_drvdata(dev); + struct device *dell_smm_hwmon_dev; + int i, err; - if (data->disallow_fan_support && index >= 20) - return 0; - if (data->disallow_fan_type_call && - (index == 21 || index == 25 || index == 28)) - return 0; - if (index >= 0 && index <= 1 && - !(data->i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP1)) - return 0; - if (index >= 2 && index <= 3 && - !(data->i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP2)) - return 0; - if (index >= 4 && index <= 5 && - !(data->i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP3)) - return 0; - if (index >= 6 && index <= 7 && - !(data->i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP4)) - return 0; - if (index >= 8 && index <= 9 && - !(data->i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP5)) - return 0; - if (index >= 10 && index <= 11 && - !(data->i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP6)) - return 0; - if (index >= 12 && index <= 13 && - !(data->i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP7)) - return 0; - if (index >= 14 && index <= 15 && - !(data->i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP8)) - return 0; - if (index >= 16 && index <= 17 && - !(data->i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP9)) - return 0; - if (index >= 18 && index <= 19 && - !(data->i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP10)) - return 0; - - if (index >= 20 && index <= 23 && - !(data->i8k_hwmon_flags & I8K_HWMON_HAVE_FAN1)) - return 0; - if (index >= 24 && index <= 26 && - !(data->i8k_hwmon_flags & I8K_HWMON_HAVE_FAN2)) - return 0; - if (index >= 27 && index <= 29 && - !(data->i8k_hwmon_flags & I8K_HWMON_HAVE_FAN3)) - return 0; - - if (index == 23 && !data->auto_fan) - return 0; + for (i = 0; i < DELL_SMM_NO_TEMP; i++) { + data->temp_type[i] = i8k_get_temp_type(i); + if (data->temp_type[i] < 0) + continue; - return attr->mode; -} + if (data->temp_type[i] >= ARRAY_SIZE(temp_labels)) + data->temp_type[i] = ARRAY_SIZE(temp_labels) - 1; + } -static const struct attribute_group i8k_group = { - .attrs = i8k_attrs, - .is_visible = i8k_is_visible, -}; -__ATTRIBUTE_GROUPS(i8k); + for (i = 0; i < DELL_SMM_NO_FANS; i++) { + data->fan_type[i] = INT_MIN; + err = i8k_get_fan_status(data, i); + if (err < 0) + err = i8k_get_fan_type(data, i); + if (err >= 0) + data->fan[i] = true; + } -static int __init dell_smm_init_hwmon(struct device *dev) -{ - struct dell_smm_data *data = dev_get_drvdata(dev); - struct device *i8k_hwmon_dev; - int err; + dell_smm_hwmon_dev = devm_hwmon_device_register_with_info(dev, "dell_smm", data, + &dell_smm_chip_info, NULL); - /* CPU temperature attributes, if temperature type is OK */ - err = i8k_get_temp_type(0); - if (err >= 0) - data->i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP1; - /* check for additional temperature sensors */ - err = i8k_get_temp_type(1); - if (err >= 0) - data->i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP2; - err = i8k_get_temp_type(2); - if (err >= 0) - data->i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP3; - err = i8k_get_temp_type(3); - if (err >= 0) - data->i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP4; - err = i8k_get_temp_type(4); - if (err >= 0) - data->i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP5; - err = i8k_get_temp_type(5); - if (err >= 0) - data->i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP6; - err = i8k_get_temp_type(6); - if (err >= 0) - data->i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP7; - err = i8k_get_temp_type(7); - if (err >= 0) - data->i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP8; - err = i8k_get_temp_type(8); - if (err >= 0) - data->i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP9; - err = i8k_get_temp_type(9); - if (err >= 0) - data->i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP10; - - /* First fan attributes, if fan status or type is OK */ - err = i8k_get_fan_status(data, 0); - if (err < 0) - err = i8k_get_fan_type(data, 0); - if (err >= 0) - data->i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN1; - - /* Second fan attributes, if fan status or type is OK */ - err = i8k_get_fan_status(data, 1); - if (err < 0) - err = i8k_get_fan_type(data, 1); - if (err >= 0) - data->i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN2; - - /* Third fan attributes, if fan status or type is OK */ - err = i8k_get_fan_status(data, 2); - if (err < 0) - err = i8k_get_fan_type(data, 2); - if (err >= 0) - data->i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN3; - - i8k_hwmon_dev = devm_hwmon_device_register_with_groups(dev, "dell_smm", data, i8k_groups); - - return PTR_ERR_OR_ZERO(i8k_hwmon_dev); + return PTR_ERR_OR_ZERO(dell_smm_hwmon_dev); } struct i8k_config_data { @@ -1240,9 +1212,6 @@ static int __init dell_smm_probe(struct platform_device *pdev) mutex_init(&data->i8k_mutex); data->i8k_fan_mult = I8K_FAN_MULT; data->i8k_fan_max = I8K_FAN_HIGH; - data->types[0] = INT_MIN; - data->types[1] = INT_MIN; - data->types[2] = INT_MIN; platform_set_drvdata(pdev, data); if (dmi_check_system(i8k_blacklist_fan_support_dmi_table)) { From patchwork Wed Jul 28 22:15:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 12406913 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1ADC7C432BE for ; Wed, 28 Jul 2021 22:16:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F0A916103C for ; Wed, 28 Jul 2021 22:16:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232116AbhG1WQ1 (ORCPT ); Wed, 28 Jul 2021 18:16:27 -0400 Received: from mout.gmx.net ([212.227.15.18]:49531 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231998AbhG1WQ1 (ORCPT ); Wed, 28 Jul 2021 18:16:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1627510568; bh=LtZsPMcj7ebFG5x1WMxNoobZwimgVbI1Y2Sss1Wjxa8=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=GwKQ3NkUMlRL8M2hqwRYmP3RyoBh9KKqwAVZwSoTe4FPnR4Gis1bd5wTPhe2eKMPp ADX2pFIfIWwXamimQQtE2VrIXjRXZUVC7vnDbpEIye0XJdT8QtHpOqYlnQSVVexYl9 dqitIaAO9P3Qmj+bAyxBcYlNLN6KXICgdrlswSTY= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from esprimo-mx.fritz.box ([79.242.190.212]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1Mi2Nv-1mm2Dh2wmP-00e2pS; Thu, 29 Jul 2021 00:16:08 +0200 From: W_Armin@gmx.de To: pali@kernel.org Cc: linux@roeck-us.net, jdelvare@suse.com, linux-hwmon@vger.kernel.org Subject: [PATCH v7 6/6] hwmon: (dell-smm-hwmon) Fix fan mutliplier detection for 3rd fan Date: Thu, 29 Jul 2021 00:15:57 +0200 Message-Id: <20210728221557.8891-7-W_Armin@gmx.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210728221557.8891-1-W_Armin@gmx.de> References: <20210728221557.8891-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:vggO6C1f3Y+VTrjRBtPuQOh2VPHjN8auJ+5JSzgRmh5UlxBH0Aa E8hk5ZW1EGGOoj4v80hOKsLrE1BIpWAObal+uBVu3mR1PQO7iDHFmb8TyNnH8x9+3ReD3wQ wVbr2kWPGYNOAY5g/sJr7k4Qia/z+1bfYzjKGrX+We+THjcaw4L8GpYz5OlVAh3am734uSs h90Q9VmKeOIn99gNiXN5A== X-UI-Out-Filterresults: notjunk:1;V03:K0:J8eouMIV8As=:Wi1sEHQdhx/bCpweM5Vyna j0NBxP9aZD5vww7QyUpXjG83+1iiIcYwDOlV7Y0QGI+RxWomWXcI6zRFbcu8iLvKDGDjjzzhv 0y3+Stgfoo+28um3AdY3PzefjNAYZ0DiBg9q++catIYtMFrCtXUQvDU9PXgVTXK3YiXeVvgbi l8BLFpl3gvRsJGNbckyfxkw56qLyhL+PQjVKCVY9LOVHv/AlyNyIWEqthcePVP+Xpo7UM//EU ycKcp7pIqueFEtm2GlbIjtn+1YrYNiA/6FuP8oFdhpYiLFy5YF8KtcaNL2z3oPdV9GiNVKXnB FLGc2/JgvkqTlpxOrPpHzv4CLYX6H/0sLQwVQYY/VEqQr7X5idbefuBGjgNiiPqqhV4GcHUaR /X6W5/ll4JR76X15pxnkj+GfaLmtnC8UStURL51HrnlBk1VkvWsgrcYLMymYQeeqN99alRYon wheexDUL2gBAoqbSHdHHfpYIg9ub7Wzbl4zJmEdYNNjt2iFcZJsa0jtDOp7df5WaY32Q/7C3o VoBuk34n89XhoxOwjw2wI20t5HoBh81QvAq8Snjg2zSwPSUlKBRQIONvjCLwkjXtWgs8wF6uk Rp83UmUDGXAvePtHPs2sZx0WmnfMRxB8Bi5uUbqjDnR/qji4X/FdZ47+M48UAr78qa2sXgOTl wi1ZI4ldp+QIl2NSnx9iSMu7qzpr3fUtDY131AuF7M3cZJlaxYhSyZVcBy56/AwxGg2Btafso qVtQwTuBdy6gTW6VaNbSMKHVnvRlAGl90m4t1bulJ2TYDsCraJBAn25aFmmrMKQrta35nDZ+C LsSEowR7rO537X9icC/hkPCp/Wt0wUkEN0UF20yi8R91fOkg3vqv1iJUmhwYb8PFDrY1guhpV gd4H5F3bKxDqrLadJEjJ8NYsPRiIKq4ZoYTZjDgWusfcgW4Bd5i8+8gnpwG57QKtY3myVgHFE HhrSik9d8GXdz1kk0RbDrCHx4mZ9bWTjsnIWKzoxQrsyGtAhbC776f2XyRyVYdZhf2X0rdHfd +elGzfbu1bam4XHXCkMiSF6laNOy9lt7gndDQYjC0bj9Z9Wo2D5BvBUn3/HQXuXgaPC4DnnUY elEAU3cEBEd7hDAmuMGrguzpspFfQyWnYG4 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org From: Armin Wolf There are up to three fans, but the detection omits the 3rd one. Fix that by using DELL_SMM_NO_FANS. Signed-off-by: Armin Wolf Fixes: 747bc8b063ae (hwmon: (dell-smm) Detect fan with index=2) --- drivers/hwmon/dell-smm-hwmon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.20.1 diff --git a/drivers/hwmon/dell-smm-hwmon.c b/drivers/hwmon/dell-smm-hwmon.c index aaf864dbe53a..206418405440 100644 --- a/drivers/hwmon/dell-smm-hwmon.c +++ b/drivers/hwmon/dell-smm-hwmon.c @@ -1263,7 +1263,7 @@ static int __init dell_smm_probe(struct platform_device *pdev) * Autodetect fan multiplier based on nominal rpm * If fan reports rpm value too high then set multiplier to 1 */ - for (fan = 0; fan < 2; ++fan) { + for (fan = 0; fan < DELL_SMM_NO_FANS; ++fan) { ret = i8k_get_fan_nominal_speed(data, fan, data->i8k_fan_max); if (ret < 0) continue;