Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2216175pxb; Wed, 30 Mar 2022 19:37:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxS1jj/kcc14imGAQW03eF8km1z0NU25Y+QhZ3OVIcs8mzcJi57spUzFVEwgGtnop/1/tYm X-Received: by 2002:a17:90a:ee94:b0:1c6:4580:1e5 with SMTP id i20-20020a17090aee9400b001c6458001e5mr3386519pjz.47.1648694233856; Wed, 30 Mar 2022 19:37:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648694233; cv=none; d=google.com; s=arc-20160816; b=DoXpjY5sO61+3a+Y4baZ2/GPRfUMz7IaSbUzLhNYgptHtg9MlEQ2488JoBw1cTfFwo vO/WB4VUPCypAJTymfOg3Z++hcvYOArn1ia8Tn3QCFTdzcar807LPn7ERC7ipIv7h+cd SNhUTl+4oQbyNj6w5iHh3QD07SOx25CnRrnFTCoBkzCOH3Oi4TdkECnSm/F+kB7neG6d HkrvuDKFx0wYQn2gpsK9ULyp9NyY3dhx0rigOm6BsP4kNe0iPE2BNec9oHIh6ikrDean 8ZBDxW/PoC4dqIbwxlIL0qJg3DcKfKAiKVjtevoNg/cOZbjtYFSxe4P7qZkBeRqGW/aC WrpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=xS98xAgzk/akrtUXfTFr/aRk0V33ILecJzuYuGaders=; b=h4/aBn9gsGWKFi9lF8lvCEl/9csIKsrsZJi9eKR4x/mCGXzYjj/pTRTiXLgmEJVc4c Mf8C4Pzw41b/qIFgIDeoGxp8XYv+WPqMjt3+/TVw2+HBQu31evyS/GRmYNV0ri6bh8Si wsuFJ2PBAT4FejRVZlbdZCwvs5XifOnArquRB66tajsN0EyAezgjj12MYAjLKk+ag1jb UjNGY6H4wf9puQABn5+JvHzIXl9QobNU27dds6Pl6qNftwjp1aqJ8gpLdeP2ntifNP3Q 4tQo2WFrGBavDan+9Qy7j/1VDU8PNpPUuyXwpjdh06mqfEPdqc9iWv5zu/wv3S52KNCz dXZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.net header.s=badeba3b8450 header.b=LNkfa0re; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmx.de Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id ch22-20020a17090af41600b001c6841aa3e2si1971356pjb.37.2022.03.30.19.37.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 19:37:13 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.net header.s=badeba3b8450 header.b=LNkfa0re; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 02FC1986F7; Wed, 30 Mar 2022 19:32:07 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348835AbiC3Qfs (ORCPT + 99 others); Wed, 30 Mar 2022 12:35:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348711AbiC3Qfq (ORCPT ); Wed, 30 Mar 2022 12:35:46 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4ED15E2; Wed, 30 Mar 2022 09:34:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1648658021; bh=Aw52GudjzfV6DBA1f+n4H6s9lkEEzRPi45KdcBXLxZ0=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date; b=LNkfa0reL5HBrPFyXfSnVY+Aw2Bl3LXKaR5hv9nJ4c1sBBUxk/ni44ICmOMbHgAQT ll/vxykhy0Y2bfO9uTxDmEsuTbj9IosozgHiqKm7GmA4VTqR4PZwOJ7GiEikkc25CC txrSR15lgDefdi3dsU0wV9YC8nDi5Bh4eqlI8oes= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from esprimo-mx.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1Mj8qd-1oCFXN3IxR-00f9s0; Wed, 30 Mar 2022 18:33:40 +0200 From: Armin Wolf To: pali@kernel.org Cc: jdelvare@suse.com, linux@roeck-us.net, linux-hwmon@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] hwmon: (dell-smm) Add cooling device support Date: Wed, 30 Mar 2022 18:33:24 +0200 Message-Id: <20220330163324.572437-1-W_Armin@gmx.de> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:tbSqy/9T9ZBldJcHFKXCEAyFh5LU2EBIRmdONn/JNv3Z+98KbMw Izfpr/J+cJWyUOdsRgMG1s96WSJqu7tXUs+KJYpVBRnvfSYS+t9X9KMY+xf4UX43vJEOTWo BqeSxpbPmfKf0OdqDU7VQbdDNQQ0rJGM1guQ8CilLwHhd4zfnTXP5nbYuXpF+L5ghIrMT2Q BvjnI+P7WBuZ+sW6RI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20ixP+IFhXGZMb6/vpcORhDRAE12EUPyGxJWB TaQBYvjIYYgXxhqdwBtTM82j4+0nrE5kfCfTMyUUiPpMX7feZfdda69GD2l9ivAAF1ikBo9zw 27corAm0O1RiGA= X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 Until now, only the temperature sensors where exported thru the thermal subsystem. Export the fans as "dell-smm-fan[1-3]" too to make them available as cooling devices. Also update Documentation. Signed-off-by: Armin Wolf =2D-- Documentation/hwmon/dell-smm-hwmon.rst | 7 ++ drivers/hwmon/Kconfig | 1 + drivers/hwmon/dell-smm-hwmon.c | 94 +++++++++++++++++++++++++- 3 files changed, 99 insertions(+), 3 deletions(-) diff --git a/Documentation/hwmon/dell-smm-hwmon.rst b/Documentation/hwmon/= dell-smm-hwmon.rst index d3323a96665d..41839b7de2c1 100644 =2D-- a/Documentation/hwmon/dell-smm-hwmon.rst +++ b/Documentation/hwmon/dell-smm-hwmon.rst @@ -86,6 +86,13 @@ probe the BIOS on your machine and discover the appropr= iate codes. Again, when you find new codes, we'd be happy to have your patches! +``thermal`` interface +--------------------------- + +The driver also exports the fans as thermal cooling devices with +``type`` set to ``dell-smm-fan[1-3]``. This allows for easy fan control +using one of the thermal governors. + Module parameters ----------------- diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index 9ab4e9b3d27b..1175b8e38c45 100644 =2D-- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig @@ -498,6 +498,7 @@ config SENSORS_DS1621 config SENSORS_DELL_SMM tristate "Dell laptop SMM BIOS hwmon driver" depends on X86 + imply THERMAL help This hwmon driver adds support for reporting temperature of different sensors and controls the fans on Dell laptops via System Management diff --git a/drivers/hwmon/dell-smm-hwmon.c b/drivers/hwmon/dell-smm-hwmon= .c index 84cb1ede7bc0..0c29386f4bd3 100644 =2D-- a/drivers/hwmon/dell-smm-hwmon.c +++ b/drivers/hwmon/dell-smm-hwmon.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -29,6 +30,7 @@ #include #include #include +#include #include #include @@ -80,6 +82,11 @@ struct dell_smm_data { int *fan_nominal_speed[DELL_SMM_NO_FANS]; }; +struct dell_smm_cooling_data { + u8 fan_num; + struct dell_smm_data *data; +}; + MODULE_AUTHOR("Massimo Dal Zotto (dz@debian.org)"); MODULE_AUTHOR("Pali Roh=C3=A1r "); MODULE_DESCRIPTION("Dell laptop SMM BIOS hwmon driver"); @@ -638,9 +645,50 @@ static void __init i8k_init_procfs(struct device *dev= ) #endif -/* - * Hwmon interface - */ +static int dell_smm_get_max_state(struct thermal_cooling_device *dev, uns= igned long *state) +{ + struct dell_smm_cooling_data *cdata =3D dev->devdata; + + *state =3D cdata->data->i8k_fan_max; + + return 0; +} + +static int dell_smm_get_cur_state(struct thermal_cooling_device *dev, uns= igned long *state) +{ + struct dell_smm_cooling_data *cdata =3D dev->devdata; + int ret; + + ret =3D i8k_get_fan_status(cdata->data, cdata->fan_num); + if (ret < 0) + return ret; + + *state =3D ret; + + return 0; +} + +static int dell_smm_set_cur_state(struct thermal_cooling_device *dev, uns= igned long state) +{ + struct dell_smm_cooling_data *cdata =3D dev->devdata; + struct dell_smm_data *data =3D cdata->data; + int ret; + + if (state > data->i8k_fan_max) + return -EINVAL; + + mutex_lock(&data->i8k_mutex); + ret =3D i8k_set_fan(data, cdata->fan_num, (int)state); + mutex_unlock(&data->i8k_mutex); + + return ret; +} + +static const struct thermal_cooling_device_ops dell_smm_cooling_ops =3D { + .get_max_state =3D dell_smm_get_max_state, + .get_cur_state =3D dell_smm_get_cur_state, + .set_cur_state =3D dell_smm_set_cur_state, +}; static umode_t dell_smm_is_visible(const void *drvdata, enum hwmon_sensor= _types type, u32 attr, int channel) @@ -941,6 +989,37 @@ static const struct hwmon_chip_info dell_smm_chip_inf= o =3D { .info =3D dell_smm_info, }; +static int __init dell_smm_init_cdev(struct device *dev, u8 fan_num) +{ + struct dell_smm_data *data =3D dev_get_drvdata(dev); + struct thermal_cooling_device *cdev; + struct dell_smm_cooling_data *cdata; + int ret =3D 0; + char *name; + + name =3D kasprintf(GFP_KERNEL, "dell-smm-fan%u", fan_num + 1); + if (!name) + return -ENOMEM; + + cdata =3D devm_kmalloc(dev, sizeof(*cdata), GFP_KERNEL); + if (cdata) { + cdata->fan_num =3D fan_num; + cdata->data =3D data; + cdev =3D devm_thermal_of_cooling_device_register(dev, NULL, name, cdata= , + &dell_smm_cooling_ops); + if (IS_ERR(cdev)) { + devm_kfree(dev, cdata); + ret =3D PTR_ERR(cdev); + } + } else { + ret =3D -ENOMEM; + } + + kfree(name); + + return ret; +} + static int __init dell_smm_init_hwmon(struct device *dev) { struct dell_smm_data *data =3D dev_get_drvdata(dev); @@ -967,6 +1046,15 @@ static int __init dell_smm_init_hwmon(struct device = *dev) continue; data->fan[i] =3D true; + + /* the cooling device it not critical, ignore failures */ + if (IS_REACHABLE(CONFIG_THERMAL)) { + err =3D dell_smm_init_cdev(dev, i); + if (err < 0) + dev_err(dev, "Failed to register cooling device for fan %u\n", + i + 1); + } + data->fan_nominal_speed[i] =3D devm_kmalloc_array(dev, data->i8k_fan_ma= x + 1, sizeof(*data->fan_nominal_speed[i]), GFP_KERNEL); =2D- 2.30.2