From patchwork Mon Sep 12 12:53:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 605319 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93412ECAAD5 for ; Mon, 12 Sep 2022 12:54:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229823AbiILMyB (ORCPT ); Mon, 12 Sep 2022 08:54:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229812AbiILMyA (ORCPT ); Mon, 12 Sep 2022 08:54:00 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD89C3869B; Mon, 12 Sep 2022 05:53:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1662987227; bh=XSwCs2/nfGyrdpEwoz6uFQ7g22hV+iNYaBeDGLIB9X4=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=XuVJ05IMBrXvd5LjEfyIBcFmMsgz4URHCk6HBpo29p4xr0Yd8V5wISfxB140FFMqN V/7M7C8mwYOhgK9Wcud3s6CxYg3FpV+tvw/YIHFY5DPHf5VGTDDGn8WArx4VJyJ9E+ 5CP6C2q58I5hgCqpyxyoLvYTW+7R+iVpejsT7wF4= 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 1MuUj2-1pOAq83BRa-00rc7V; Mon, 12 Sep 2022 14:53:46 +0200 From: Armin Wolf To: hdegoede@redhat.com, markgross@kernel.org Cc: rafael@kernel.org, lenb@kernel.org, hmh@hmh.eng.br, matan@svgalib.org, corentin.chary@gmail.com, jeremy@system76.com, productdev@system76.com, platform-driver-x86@vger.kernel.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/5] ACPI: battery: Do not unload battery hooks on single error Date: Mon, 12 Sep 2022 14:53:38 +0200 Message-Id: <20220912125342.7395-2-W_Armin@gmx.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220912125342.7395-1-W_Armin@gmx.de> References: <20220912125342.7395-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:opYKxNI6ldvV9CMPDs23nnkFLRX2RWCXenJp0Fy2cZzTkhBpHHL nYOJxT1/52Em+UtIES3UHRQJ2AOYeJc0+p16gvrPwNtsMt4fy2xMfYGtzz4miyINI963nV8 2vWpg8tfTlD1sLCUYlmrgKgh0G/U4iUzDnNgd0hVpIwBcbZYJPaI71L0BXmwWNmr2S0UF70 KNqsTvrMTRRgMwNz5Lg8w== X-UI-Out-Filterresults: notjunk:1;V03:K0:tRQ/ZT6ufDs=:9m9mqRTMKP/EHSjOI97MZG Ohw2vJbWzO8pVNOOjbB4dENDZgkEMGiPHy9E4F4ovG9czf5tK8NXR6D55GBQXdBb1Pg+K/EFF RlCtOPvcqMtuUS2VHlT9rTT6Ej9ioDqkamYVcaI00Z/Bri1yUGUSyUZA0n41aPI4Z1m5kCORX kpP8y1J8FvQsbVVylNWuAJ+o9LswQiUciHl/2w8TaJ6XJMxN6UwkfjXdORH6/nB2bonE/IF47 vW57FaESEUE600YOlkwONY3yUMZ8COhH7m5+1skvmTWmYpatPfEsMf9htT3Ix7/TzfRncY/Uh Rdfu/WIw6Hznm4WdpVlC21+04TaVYe6aftTmhcSgZ9rdNag15C3NkBaIsbGji0sLl1b6UE6jg 9f9uibxmj2XDXfDx2vcMQjhqyPFBElmdOkmSVHY2Ul6rv5SEhGulZzSXWZJTFZ/ykUmyZVsg1 /2aPLYi9wUGRzik3Cxzem8L3JVHp2szmF8q1kb3isdI/ktQ+Nkq6z1V0q10s27VJNbX5VtqeL J49nura+LmfNae16eC3tHtECTYmijmme7LbIH9SV/EnQN2Lh9rjWMX2yiNatvM01wk7A9DZUK e9oVJbLlCqS4vNRZAgIF2JSz/fdrETSwxWO7x1iP5OxdLFTvnz1uxNWtMES6/DedsN1hhf53F 6IUi9gixSIjIvTWZjtOYP5la3TUesZde7lzx8iILOIG3tECApBhr/okwzBa5W1S/9Po55VeiF xxiL3PGJUokUFVlesWoa5ltWDtPvEKe6+FXyuFC9qhOnkhnIga1oSEra2vzqgwkSh/IxUPz3O onjrkXIxLh88u/0v3qtRpurqTxdNz3liNA9YFadem33OknOaOj+2Yu0TrGGizlrf5J/bQqQ5K xXLWNnyp+qhES4D+xEuyE7jDJuWkZKww11kNimUbSAue0kPfiQG8UollzSI5kizJZGyEm6WlY C5sqzxaq56YLu6+AkKvID+RYUJD7TsFF8sohPG0dFs2yZdqK6Vn0aM3qRLZfBjHAXh3dbd9PL 3mytR6shGdcgupE4njkt21NfsEt3AeaJbo8zMOFv9DGqP3jE0eJHW15oUEluqfGMkUSfLyOu8 guUdqPnmF5rg5yJdL2dIHGr26M7hNdPzV2CtEgp32N7WGqrWuRd6pR92sxr88vQP4Sk4P1byu n6Utp9PcbF7TiR5Vybg52f60eT Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Currently, battery hooks are being unloaded if they return an error when adding a single battery. This however also causes the removal of successfully added hooks if they return -ENODEV for a single unsupported battery. Do not unload battery hooks in such cases since the hook handles any cleanup actions. Signed-off-by: Armin Wolf --- drivers/acpi/battery.c | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) -- 2.30.2 diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index 306513fec1e1..e59c261c7c59 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c @@ -724,20 +724,10 @@ void battery_hook_register(struct acpi_battery_hook *hook) * its attributes. */ list_for_each_entry(battery, &acpi_battery_list, list) { - if (hook->add_battery(battery->bat)) { - /* - * If a add-battery returns non-zero, - * the registration of the extension has failed, - * and we will not add it to the list of loaded - * hooks. - */ - pr_err("extension failed to load: %s", hook->name); - __battery_hook_unregister(hook, 0); - goto end; - } + hook->add_battery(battery->bat); } pr_info("new extension: %s\n", hook->name); -end: + mutex_unlock(&hook_mutex); } EXPORT_SYMBOL_GPL(battery_hook_register); @@ -762,15 +752,7 @@ static void battery_hook_add_battery(struct acpi_battery *battery) * during the battery module initialization. */ list_for_each_entry_safe(hook_node, tmp, &battery_hook_list, list) { - if (hook_node->add_battery(battery->bat)) { - /* - * The notification of the extensions has failed, to - * prevent further errors we will unload the extension. - */ - pr_err("error in extension, unloading: %s", - hook_node->name); - __battery_hook_unregister(hook_node, 0); - } + hook_node->add_battery(battery->bat); } mutex_unlock(&hook_mutex); } From patchwork Mon Sep 12 12:53:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 605031 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90699C6FA86 for ; Mon, 12 Sep 2022 12:54:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229828AbiILMyE (ORCPT ); Mon, 12 Sep 2022 08:54:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229741AbiILMyC (ORCPT ); Mon, 12 Sep 2022 08:54:02 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A26438698; Mon, 12 Sep 2022 05:54:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1662987228; bh=8ihrj8g25HP53F8+Sv7wcMhICOwnoHKS/foAdha3L/k=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=XwqIH7AC/JhJY8TfxPD98U/Lt30taTqlqGSp+PW6lgpKFYLFBf9GT9bkiDKOwJP9i xPzLPfLnXZxPJ0w3CNGn0YQhnOAmp1hRGuYWg2Gv7p6OF2E9dA6P94BLVMV2J2JBx+ kUcY+YoA96batW5k2kPn7YGezYmBpQkzb9zIQqJk= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from esprimo-mx.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MOREi-1oh9Vq349u-00Px5m; Mon, 12 Sep 2022 14:53:48 +0200 From: Armin Wolf To: hdegoede@redhat.com, markgross@kernel.org Cc: rafael@kernel.org, lenb@kernel.org, hmh@hmh.eng.br, matan@svgalib.org, corentin.chary@gmail.com, jeremy@system76.com, productdev@system76.com, platform-driver-x86@vger.kernel.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/5] ACPI: battery: Simplify battery_hook_unregister() Date: Mon, 12 Sep 2022 14:53:39 +0200 Message-Id: <20220912125342.7395-3-W_Armin@gmx.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220912125342.7395-1-W_Armin@gmx.de> References: <20220912125342.7395-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:IkLysIw5a5ESft6c54LstqzrkEw9rnzQD6ovCh2OdaLG3RhWnqr 7MGdkAoiphM/0RCommfQ1LhQRWpZaRMiWKVBjI4ocPuTn7srsBpB2op+GsX36UochwOeNbF YGpAUK0Nxn+obfSWfi9+TgzB1+ecADX+/WYTvrqW4Y+h616cp84IxG3Z0gr22Zg2ufyre/D /B7pKoHnkMoUQ6iXQz03g== X-UI-Out-Filterresults: notjunk:1;V03:K0:aOfctYAThQc=:1NwPC6V2Krz1yElDCswt+C BoXkpkK30ygh8LUILGzI5w6H+DnDgixwAq9PqtPgkzW/oEY9kui8pOS63Cpe7fJHfugjO3t7Q aBjJ/XpVFoGSci2aPF5gyoskHmXZRYxiiAbJdaIjmcJVwySn/rjgXiyZPtG7Us3uWoDF3ARTS TtlMS0AMkA9CTFJTLBWBAZFFAskVDAaQT3gk3nEB0XtUgZ9zK8Qc9Rxf//recqRsroOhh6/ik 9XpTZM/2BW3binq0u3Vbxkr7Xi8ZFJrvFPRlz3Kojd0NikDIlf3jjL8npn54w4N3PijwPLrZ+ B3ywve9XJUUe5V+DZDipMuFUIwhgfp5NISr6L3FAUrNgVY77O8xs3BqJnsuCAYsM+/H2aX/G2 4FL5j645Q0mhEDg2ApVVh3Of20BTtoWDYU0bBfvh0OewEQV5MFrkrnZxCVTqIH1SfiQX+s0Oz Ogr77VXKhVMMCTd2ZyyeCne6BsgQMfJTb6p46Al/yZUo3mtr5d1yeK02LRqC0HfDpVVUFbPL5 KNWqhdve+2OhNt1KF74WIQLHBnMTQ6krQjpR3qWFnh6D+3cvQwhdpPgEC3kepBCAM02+BitVW md5WmI7Jdkg2AODQu7khzr2gtmMgygfMQU/3x7OOSJIZLb4sw12KqGA2KK12c8oq9+Vud+Guz ub/baIstL62aTy6nj9Y/YcpWdk7vkVOzNIJPFmeK/6rVOS10d4UIfrZ5jqAoyCS3vyCeVMWw8 6OFuuLnop/U8G4s9XZCNOmtUqOQAYT5WuY1HyAbMg9Kv3VN2eZnJsM6FPptbvdlAW6zWHssaZ XaWXwBDq/JDikTbP6qnpUidHsXMQO1wwc4umlG2W3/Lq5C/g41V8Omtet1K745DEWKzL9In08 4A1dlrSMzrKPEaisNAEN2Z2L7vi0txu7Ql8qzE8qn8987dzQeEs6/PG/eOewA7P7oe2JETp83 N/wnY8SDOfQ4fbzi/CJqr/D7NHP+NfcRQhU+RBOlHe8j3KvcyaiPGYVK2C49SD4uPeYDTjyOI 5saV+Qh6frs9kOXAAlvN9xm5d44g66hZlCjyeddi8hTT2ulHQrA1ExIoLar/lvCcN0qpOPPLG OeONDdBH4CLmLlIgaUI7EvrI4If5mDRmu6IvLrmZQMTH4Dv/j1+kN80CDyaA61MoIySqdkj3q aoQ9MbD+Vvu/uB4LIFK3Xd6Avv Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Since __battery_hook_unregister() is always called with lock set to 1, remove the unneeded conditionals and merge it with battery_hook_unregister(). Signed-off-by: Armin Wolf Reviewed-by: Hans de Goede --- drivers/acpi/battery.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) -- 2.30.2 diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index e59c261c7c59..4aea65f3d8c3 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c @@ -686,27 +686,22 @@ static LIST_HEAD(acpi_battery_list); static LIST_HEAD(battery_hook_list); static DEFINE_MUTEX(hook_mutex); -static void __battery_hook_unregister(struct acpi_battery_hook *hook, int lock) +void battery_hook_unregister(struct acpi_battery_hook *hook) { struct acpi_battery *battery; /* * In order to remove a hook, we first need to * de-register all the batteries that are registered. */ - if (lock) - mutex_lock(&hook_mutex); + mutex_lock(&hook_mutex); + list_for_each_entry(battery, &acpi_battery_list, list) { hook->remove_battery(battery->bat); } list_del(&hook->list); - if (lock) - mutex_unlock(&hook_mutex); - pr_info("extension unregistered: %s\n", hook->name); -} -void battery_hook_unregister(struct acpi_battery_hook *hook) -{ - __battery_hook_unregister(hook, 1); + mutex_unlock(&hook_mutex); + pr_info("extension unregistered: %s\n", hook->name); } EXPORT_SYMBOL_GPL(battery_hook_unregister); @@ -784,7 +779,7 @@ static void __exit battery_hook_exit(void) * need to remove the hooks. */ list_for_each_entry_safe(hook, ptr, &battery_hook_list, list) { - __battery_hook_unregister(hook, 1); + battery_hook_unregister(hook); } mutex_destroy(&hook_mutex); } From patchwork Mon Sep 12 12:53:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 605030 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9742AC6FA8A for ; Mon, 12 Sep 2022 12:54:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229900AbiILMyV (ORCPT ); Mon, 12 Sep 2022 08:54:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229834AbiILMyF (ORCPT ); Mon, 12 Sep 2022 08:54:05 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 865D4386B3; Mon, 12 Sep 2022 05:54:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1662987230; bh=k9YDAppcKkq2ArgBg9pY+g/nuPhYMJY6cXdn4yJClEs=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=k0YKkh5qU1cs2dy+vXJddPmszGCj1TIYZCm78r6murV3spf/j6Dw5yuX4jtqydr/t ceFNVpasD4hluSzzBYG5B5TxbRK1DrkYJubcXA+MwLkTPA7DjGfGR5iP4ARaPPnvfj a2CiHbuqDa6f1RYo8ij6deAONRjC2hfTQnm01WgI= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from esprimo-mx.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1McpNo-1p6VSu1BYY-00Zx13; Mon, 12 Sep 2022 14:53:50 +0200 From: Armin Wolf To: hdegoede@redhat.com, markgross@kernel.org Cc: rafael@kernel.org, lenb@kernel.org, hmh@hmh.eng.br, matan@svgalib.org, corentin.chary@gmail.com, jeremy@system76.com, productdev@system76.com, platform-driver-x86@vger.kernel.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/5] ACPI: battery: Allow battery hooks to be registered multiple times. Date: Mon, 12 Sep 2022 14:53:40 +0200 Message-Id: <20220912125342.7395-4-W_Armin@gmx.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220912125342.7395-1-W_Armin@gmx.de> References: <20220912125342.7395-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:vntFRVjmTWKgpdc0xf7mZru17K6B4tMLwPKwGfWCecrzly2Ef6j ubroTEusCDQx2KHwGyP+UuPMXYJLtJKswDIWC8QxoKP+n3DHTSpXq0+XIAfHqE6jtjT1WPR sA3E4Xjmc7OBD5lHIjOv9fDxgggc703TMpPxeXvr6R9pOUdG38+CV61yKmJsaSYW/5qCwV+ LEDoDehU6DbOyscriA0dw== X-UI-Out-Filterresults: notjunk:1;V03:K0:Ow+eob142Wg=:RlZ6EFXhSuGcO2A23A/Bcj MVzgdRpmUfdjVvzsdLDKncPqI5KwDx2es51R2bCMfijXA8VlyEX7MCMX9nSacYZ3wxzns8O8p pg3reMDc8EEKiT2hHEu+0QuYyNDRRBSgfILGBNcDRpdh9HrF6oovYagJGov4z9xJyi/EZZv6k +Y0b/AYgz3KNqCD3SCIj/aIO5d0pmIi1K+MGYJTb+E45zMaCqcNt1KF1ZmPmQsUi3+m4jpG1m dFhdKK3jF4t+kOd6uQshIbZMv3V7BmSnKadC8uAZNWCek03Vpv8qMJU3Ljix7NbwjJCPa9M0V hJe9fU1HqtvY2jWQFgStSFx6q/pQSvSKQuVFhTVNeAz0J8mMoSLx0VWJn1oUaDNUaADEEL2Mn oBAG1CUwZhtvPtmflf20pBPI1r4XxRbRTtn6cW9NBNsX8q73Xo5wPYpws8FJRMFU4Hsj7RYJD zu+flPfrqTqwYXZ0J9vrweow8jhUNezcpyzgV5Iy1YaCiAgWC4+G7Al81GFBOwess7UiInCSQ iYW1jycrg2AbXQJ5DbaUaVYGS3ndt5JJ7gKXLRNtAS983Fj2DaVJ/aosOyWCin0Kq5PSNqh60 0gNHwpn1zui8gbgPmGuo11DG+WSHjNS3entRBC3HgiS1qNQuqNEGNBydvjiaS2CuBAjq8KZny 8ysB/LO9A+7n2Bu+VpS+GZOZ9+gZCapN2Z47JU9Aa6NhKh4cRUJdmV8oo5Pidtx+6WrkB72qn OOm3jK/of/pd4CwU/tuL2/MVMf24NtJ3ACs80YfIKQITfGS3UuYf+oFzOLfIsXj01M2b1h6so vyOA2hDHa9srX2C0Ds3ynDZ4b7NOf9zKHrGmC0bV2bqKWoVCz6ITODeemM8tBsFo1LZGjN0Wx vgb8/GE3+u5raEstzESx6OgT3LynzUh+L18q5JM0K2UEQUqGGWQb0+eHKZeXbFO8vxM9C2WCV zybfMYT3SIAmdKDVGg2ANf1DXgF37RmYRY7UX0u/EPKBuvo0sebEdio8ZB1v9Om1O6+XTy25/ C/qiP1PAP0CjEPChkYeEOPqlhcVGC8kmJ0oFWF371EfyPWPpYrzmIDcVAdBB6Djshqam23ayX r4kh9/L+pqG9YkfFDEU/dtiF4GpD5OYbPo4Tt00GZjpEBggskKzRbbKOEToNAYpHuvGGE/ksZ +aWqW08DykR0B6QRIAZoYQBTkT Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Registering multiple instances of a battery hook is beneficial for drivers which can be instantiated multiple times. Until now, this would mean that such a driver would have to implement some logic to manage battery hooks. Extend the battery hook handling instead. Signed-off-by: Armin Wolf --- drivers/acpi/battery.c | 21 ++++++++++++++++----- drivers/platform/x86/asus-wmi.c | 15 ++++++--------- drivers/platform/x86/huawei-wmi.c | 11 +++++++---- drivers/platform/x86/lg-laptop.c | 10 ++++++---- drivers/platform/x86/system76_acpi.c | 18 ++++++++++-------- drivers/platform/x86/thinkpad_acpi.c | 11 +++++++---- include/acpi/battery.h | 11 ++++++++--- 7 files changed, 60 insertions(+), 37 deletions(-) -- 2.30.2 diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index 4aea65f3d8c3..15bb5d868a56 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c @@ -696,19 +696,28 @@ void battery_hook_unregister(struct acpi_battery_hook *hook) mutex_lock(&hook_mutex); list_for_each_entry(battery, &acpi_battery_list, list) { - hook->remove_battery(battery->bat); + hook->ops->remove_battery(battery->bat); } list_del(&hook->list); mutex_unlock(&hook_mutex); pr_info("extension unregistered: %s\n", hook->name); + kfree(hook); } EXPORT_SYMBOL_GPL(battery_hook_unregister); -void battery_hook_register(struct acpi_battery_hook *hook) +struct acpi_battery_hook *battery_hook_register(const char *name, + const struct acpi_battery_hook_ops *ops) { + struct acpi_battery_hook *hook = kzalloc(sizeof(*hook), GFP_KERNEL); struct acpi_battery *battery; + if (!hook) + return ERR_PTR(-ENOMEM); + + hook->name = name; + hook->ops = ops; + mutex_lock(&hook_mutex); INIT_LIST_HEAD(&hook->list); list_add(&hook->list, &battery_hook_list); @@ -719,11 +728,13 @@ void battery_hook_register(struct acpi_battery_hook *hook) * its attributes. */ list_for_each_entry(battery, &acpi_battery_list, list) { - hook->add_battery(battery->bat); + hook->ops->add_battery(battery->bat); } pr_info("new extension: %s\n", hook->name); mutex_unlock(&hook_mutex); + + return hook; } EXPORT_SYMBOL_GPL(battery_hook_register); @@ -747,7 +758,7 @@ static void battery_hook_add_battery(struct acpi_battery *battery) * during the battery module initialization. */ list_for_each_entry_safe(hook_node, tmp, &battery_hook_list, list) { - hook_node->add_battery(battery->bat); + hook_node->ops->add_battery(battery->bat); } mutex_unlock(&hook_mutex); } @@ -762,7 +773,7 @@ static void battery_hook_remove_battery(struct acpi_battery *battery) * custom attributes from the battery. */ list_for_each_entry(hook, &battery_hook_list, list) { - hook->remove_battery(battery->bat); + hook->ops->remove_battery(battery->bat); } /* Then, just remove the battery from the list */ list_del(&battery->list); diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index d95170b7dba0..37d8649418f4 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -252,8 +252,8 @@ struct asus_wmi { struct platform_profile_handler platform_profile_handler; bool platform_profile_support; - // The RSOC controls the maximum charging percentage. - bool battery_rsoc_available; + // The RSOC battery hook controls the maximum charging percentage. + struct acpi_battery_hook *hook; bool panel_overdrive_available; @@ -916,25 +916,22 @@ static int asus_wmi_battery_remove(struct power_supply *battery) return 0; } -static struct acpi_battery_hook battery_hook = { +static const struct acpi_battery_hook_ops battery_hook_ops = { .add_battery = asus_wmi_battery_add, .remove_battery = asus_wmi_battery_remove, - .name = "ASUS Battery Extension", }; static void asus_wmi_battery_init(struct asus_wmi *asus) { - asus->battery_rsoc_available = false; if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_RSOC)) { - asus->battery_rsoc_available = true; - battery_hook_register(&battery_hook); + asus->hook = battery_hook_register("ASUS Battery Extension", &battery_hook_ops); } } static void asus_wmi_battery_exit(struct asus_wmi *asus) { - if (asus->battery_rsoc_available) - battery_hook_unregister(&battery_hook); + if (!IS_ERR_OR_NULL(asus->hook)) + battery_hook_unregister(asus->hook); } /* LEDs ***********************************************************************/ diff --git a/drivers/platform/x86/huawei-wmi.c b/drivers/platform/x86/huawei-wmi.c index eac3e6b4ea11..6fd02b25a97b 100644 --- a/drivers/platform/x86/huawei-wmi.c +++ b/drivers/platform/x86/huawei-wmi.c @@ -62,6 +62,7 @@ struct huawei_wmi { bool battery_available; bool fn_lock_available; + struct acpi_battery_hook *hook; struct huawei_wmi_debug debug; struct input_dev *idev[2]; struct led_classdev cdev; @@ -491,10 +492,9 @@ static int huawei_wmi_battery_remove(struct power_supply *battery) return 0; } -static struct acpi_battery_hook huawei_wmi_battery_hook = { +static const struct acpi_battery_hook_ops huawei_wmi_battery_hook_ops = { .add_battery = huawei_wmi_battery_add, .remove_battery = huawei_wmi_battery_remove, - .name = "Huawei Battery Extension" }; static void huawei_wmi_battery_setup(struct device *dev) @@ -507,7 +507,8 @@ static void huawei_wmi_battery_setup(struct device *dev) return; } - battery_hook_register(&huawei_wmi_battery_hook); + huawei->hook = battery_hook_register("Huawei Battery Extension", + &huawei_wmi_battery_hook_ops); device_create_file(dev, &dev_attr_charge_control_thresholds); } @@ -516,7 +517,9 @@ static void huawei_wmi_battery_exit(struct device *dev) struct huawei_wmi *huawei = dev_get_drvdata(dev); if (huawei->battery_available) { - battery_hook_unregister(&huawei_wmi_battery_hook); + if (!IS_ERR(huawei->hook)) + battery_hook_unregister(huawei->hook); + device_remove_file(dev, &dev_attr_charge_control_thresholds); } } diff --git a/drivers/platform/x86/lg-laptop.c b/drivers/platform/x86/lg-laptop.c index 332868b140ed..d8a61a07313e 100644 --- a/drivers/platform/x86/lg-laptop.c +++ b/drivers/platform/x86/lg-laptop.c @@ -73,6 +73,7 @@ static u32 inited; #define INIT_SPARSE_KEYMAP 0x80 static int battery_limit_use_wmbb; +static struct acpi_battery_hook *hook; static struct led_classdev kbd_backlight; static enum led_brightness get_kbd_backlight_level(void); @@ -562,10 +563,9 @@ static int lg_battery_remove(struct power_supply *battery) return 0; } -static struct acpi_battery_hook battery_hook = { +static const struct acpi_battery_hook_ops battery_hook_ops = { .add_battery = lg_battery_add, .remove_battery = lg_battery_remove, - .name = "LG Battery Extension", }; static struct attribute *dev_attributes[] = { @@ -750,7 +750,7 @@ static int acpi_add(struct acpi_device *device) led_classdev_register(&pf_device->dev, &tpad_led); wmi_input_setup(); - battery_hook_register(&battery_hook); + hook = battery_hook_register("LG Battery Extension", &battery_hook_ops); return 0; @@ -768,7 +768,9 @@ static int acpi_remove(struct acpi_device *device) led_classdev_unregister(&tpad_led); led_classdev_unregister(&kbd_backlight); - battery_hook_unregister(&battery_hook); + if (!IS_ERR(hook)) + battery_hook_unregister(hook); + wmi_input_destroy(); platform_device_unregister(pf_device); pf_device = NULL; diff --git a/drivers/platform/x86/system76_acpi.c b/drivers/platform/x86/system76_acpi.c index 958df41ad509..1ec22db32bd0 100644 --- a/drivers/platform/x86/system76_acpi.c +++ b/drivers/platform/x86/system76_acpi.c @@ -26,6 +26,7 @@ struct system76_data { struct acpi_device *acpi_dev; + struct acpi_battery_hook *hook; struct led_classdev ap_led; struct led_classdev kb_led; enum led_brightness kb_brightness; @@ -272,20 +273,21 @@ static int system76_battery_remove(struct power_supply *battery) return 0; } -static struct acpi_battery_hook system76_battery_hook = { +static const struct acpi_battery_hook_ops system76_battery_hook_ops = { .add_battery = system76_battery_add, .remove_battery = system76_battery_remove, - .name = "System76 Battery Extension", }; -static void system76_battery_init(void) +static void system76_battery_init(struct system76_data *data) { - battery_hook_register(&system76_battery_hook); + data->hook = battery_hook_register("System76 Battery Extension", + &system76_battery_hook_ops); } -static void system76_battery_exit(void) +static void system76_battery_exit(struct system76_data *data) { - battery_hook_unregister(&system76_battery_hook); + if (!IS_ERR(data->hook)) + battery_hook_unregister(data->hook); } // Get the airplane mode LED brightness @@ -730,7 +732,7 @@ static int system76_add(struct acpi_device *acpi_dev) if (err) goto error; - system76_battery_init(); + system76_battery_init(data); } return 0; @@ -751,7 +753,7 @@ static int system76_remove(struct acpi_device *acpi_dev) data = acpi_driver_data(acpi_dev); if (data->has_open_ec) { - system76_battery_exit(); + system76_battery_exit(data); kfree(data->nfan); kfree(data->ntmp); } diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c index 8fbe21ebcc52..8adafc3c31fa 100644 --- a/drivers/platform/x86/thinkpad_acpi.c +++ b/drivers/platform/x86/thinkpad_acpi.c @@ -9407,6 +9407,7 @@ struct tpacpi_battery_data { struct tpacpi_battery_driver_data { struct tpacpi_battery_data batteries[3]; + struct acpi_battery_hook *hook; int individual_addressing; }; @@ -9914,10 +9915,9 @@ static int tpacpi_battery_remove(struct power_supply *battery) return 0; } -static struct acpi_battery_hook battery_hook = { +static const struct acpi_battery_hook_ops battery_hook_ops = { .add_battery = tpacpi_battery_add, .remove_battery = tpacpi_battery_remove, - .name = "ThinkPad Battery Extension", }; /* Subdriver init/exit */ @@ -9943,13 +9943,16 @@ static int __init tpacpi_battery_init(struct ibm_init_struct *ibm) battery_quirk_table, ARRAY_SIZE(battery_quirk_table)); - battery_hook_register(&battery_hook); + battery_info.hook = battery_hook_register("ThinkPad Battery Extension", + &battery_hook_ops); + return 0; } static void tpacpi_battery_exit(void) { - battery_hook_unregister(&battery_hook); + if (!IS_ERR(battery_info.hook)) + battery_hook_unregister(battery_info.hook); } static struct ibm_struct battery_driver_data = { diff --git a/include/acpi/battery.h b/include/acpi/battery.h index b8d56b702c7a..b3c81abada1e 100644 --- a/include/acpi/battery.h +++ b/include/acpi/battery.h @@ -10,14 +10,19 @@ #define ACPI_BATTERY_NOTIFY_INFO 0x81 #define ACPI_BATTERY_NOTIFY_THRESHOLD 0x82 -struct acpi_battery_hook { - const char *name; +struct acpi_battery_hook_ops { int (*add_battery)(struct power_supply *battery); int (*remove_battery)(struct power_supply *battery); +}; + +struct acpi_battery_hook { + const char *name; + const struct acpi_battery_hook_ops *ops; struct list_head list; }; -void battery_hook_register(struct acpi_battery_hook *hook); +struct acpi_battery_hook *battery_hook_register(const char *name, + const struct acpi_battery_hook_ops *hook); void battery_hook_unregister(struct acpi_battery_hook *hook); #endif From patchwork Mon Sep 12 12:53:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 605318 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 778E1C6FA86 for ; Mon, 12 Sep 2022 12:54:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229882AbiILMyU (ORCPT ); Mon, 12 Sep 2022 08:54:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229831AbiILMyE (ORCPT ); Mon, 12 Sep 2022 08:54:04 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.17.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 608FB3869B; Mon, 12 Sep 2022 05:54:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1662987232; bh=sW1W68spZdQHzaw9zpfBQ/9ZrMwiIiIAA3+2wSWc8mI=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=id3fEoHXUHaIQbQI5THNG/+XlvV15NhAlr/yuLZ5IB2r3G7zJZ2G4L4+V8Gtb2g+M fDNT/qq19PEyXUh60LCb6CiASHDWYWF0W6gfsVWp7ilGxXT70eAbwD0GY32kXDJ3u/ cPZ+gLQ3gGVmQgLgGtcwwgpqjKhr+6OTcefdf85Y= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from esprimo-mx.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1N3bSt-1pWfAS3Kdv-010eB5; Mon, 12 Sep 2022 14:53:51 +0200 From: Armin Wolf To: hdegoede@redhat.com, markgross@kernel.org Cc: rafael@kernel.org, lenb@kernel.org, hmh@hmh.eng.br, matan@svgalib.org, corentin.chary@gmail.com, jeremy@system76.com, productdev@system76.com, platform-driver-x86@vger.kernel.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/5] ACPI: battery: Allow for passing data to battery hooks. Date: Mon, 12 Sep 2022 14:53:41 +0200 Message-Id: <20220912125342.7395-5-W_Armin@gmx.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220912125342.7395-1-W_Armin@gmx.de> References: <20220912125342.7395-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:qFkj93qtnUCTrPRR2vZjFev3kQ2zRpUqIyEpl3hJW6QjnFgAzWA 4qFAw4PN2lzM1ZHQ4O4LDHITVqkJRmGjL+MAnBxadebSQuPao3o7B/MoJmpJtNBm/KZDc0H psPg9q8pXuYcIsM1XfPn4lwhuSZJyJWqeGLydKI8YK/BrxNVXI5lRrsuB6NvPr5wHKS7dDh N9GS73VoubzuJ1Cib4H0w== X-UI-Out-Filterresults: notjunk:1;V03:K0:6ka7/eg1V6k=:2PZ8D5dUX4e4W8s/UrhXYj QPyQZXq/zCBqx5KiXtvLUKV5uoa0piSMwj8Qx/y6r8lbGyNb+l+7bvzKOtykbb37za7I2r6/d 9MZ54Li1D13MZeAV+11zp/ENfnxPCxh7ufvmqvswYhRcxAwmUsze6DbQ1bJJwIA64zHp8/YY3 Mgyq9N5SgZx1Wlm8Zddnr8h4A9wh/QCvT+l3bRHzqI9flTXPSwHUHTh608pyk80Tv7nhQ1uCg xNQFGLW1axGX7eRK+ENCGdu0lb8SFxWf/NCNwfbPDSfpedSgZWYLtdGGXoP4YJIhqYX6z1w2D qTZ8osRU4jPyCqJNZU0IiT3ZM6lH2S8BtvkZCeoOJ5c9Jjjmc9405VKTj+1XOqQNzNA6vXbuJ XACNjK86hVw13NeexZZ/g8Bkf1MIHeJWNGbeoIQpns8RmizBqWa6PbEKRF0f2zD1/OUpZTA/z TvA1NUqI+aYrr88xjagDCBGRpj3TqJdFkf1+vb+StIptaNuF19PhlxbGFeE7xppptnkQoiMqC lhOKeBN8glFEGgqz7VACby171VAKsjWQuOBCtgtEoAyFYOSd/ycdyUlisU3PRBPEnylHXryEC 1/KurzGffnIQb/4QPQgAZDz4uU1oLJ/5inm9ZxSjn1SP3C6qoDDoC40PL+6ilBID2Ioizi/DK a7fVE5zUi/cJJhjP/N5Ag1tvAMZbzflGH2lku2slti0BjI+pY2FPuIG8LrHmZB6kpUWa2s5MK p8mNpNm9n3MueA+JDRcIshuctMbaxhBcf/eJ5MVfKB4HpKBSBkr1FLsgSDnt+FvMWK6EG4TXl k4GrnyZbR2OJCjgQERXXJd4gAq9/P1PZtDSGlCnUP8NDgGBa/YwWZ6He20Qduhbyj44TOBvyC nt+HQqyBKkXiToGlvh5xnT4Cck5WFCXBmWoPZlbwxmGY/R017J6EI4h2pClp0qXGpaOrgCvv/ U3+RoqZBxSmaVkCv5bl+SB0pBWiiVHfv7BErxcK+7X+gPQEKJ2arIG4RXHTpLYadWaUdRD9ez IwhRQcNF8CrKg5QYp+HcEiEcGQ9Q72RbGYVcjFBuN+xDSWs07NxdTypipO3LqlC5KtHvWtCmN q6OjnMtADgxPEAs45e2iMY5ejlFEhVVLnwzGFhs9rtF58icxtYKK8uEL6VN45q6DFg/0j//s4 ZlE78YQ/vcDY0tdhBZqM+bbWku Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Since a driver may register multiple instances of a battery hook, passing data to each instance is convenient. Signed-off-by: Armin Wolf Reviewed-by: Hans de Goede --- drivers/acpi/battery.c | 11 ++++++----- drivers/platform/x86/asus-wmi.c | 7 ++++--- drivers/platform/x86/huawei-wmi.c | 6 +++--- drivers/platform/x86/lg-laptop.c | 6 +++--- drivers/platform/x86/system76_acpi.c | 6 +++--- drivers/platform/x86/thinkpad_acpi.c | 6 +++--- include/acpi/battery.h | 7 ++++--- 7 files changed, 26 insertions(+), 23 deletions(-) -- 2.30.2 diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index 15bb5d868a56..396a7324216c 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c @@ -696,7 +696,7 @@ void battery_hook_unregister(struct acpi_battery_hook *hook) mutex_lock(&hook_mutex); list_for_each_entry(battery, &acpi_battery_list, list) { - hook->ops->remove_battery(battery->bat); + hook->ops->remove_battery(hook->data, battery->bat); } list_del(&hook->list); @@ -706,7 +706,7 @@ void battery_hook_unregister(struct acpi_battery_hook *hook) } EXPORT_SYMBOL_GPL(battery_hook_unregister); -struct acpi_battery_hook *battery_hook_register(const char *name, +struct acpi_battery_hook *battery_hook_register(const char *name, void *data, const struct acpi_battery_hook_ops *ops) { struct acpi_battery_hook *hook = kzalloc(sizeof(*hook), GFP_KERNEL); @@ -716,6 +716,7 @@ struct acpi_battery_hook *battery_hook_register(const char *name, return ERR_PTR(-ENOMEM); hook->name = name; + hook->data = data; hook->ops = ops; mutex_lock(&hook_mutex); @@ -728,7 +729,7 @@ struct acpi_battery_hook *battery_hook_register(const char *name, * its attributes. */ list_for_each_entry(battery, &acpi_battery_list, list) { - hook->ops->add_battery(battery->bat); + hook->ops->add_battery(hook->data, battery->bat); } pr_info("new extension: %s\n", hook->name); @@ -758,7 +759,7 @@ static void battery_hook_add_battery(struct acpi_battery *battery) * during the battery module initialization. */ list_for_each_entry_safe(hook_node, tmp, &battery_hook_list, list) { - hook_node->ops->add_battery(battery->bat); + hook_node->ops->add_battery(hook_node->data, battery->bat); } mutex_unlock(&hook_mutex); } @@ -773,7 +774,7 @@ static void battery_hook_remove_battery(struct acpi_battery *battery) * custom attributes from the battery. */ list_for_each_entry(hook, &battery_hook_list, list) { - hook->ops->remove_battery(battery->bat); + hook->ops->remove_battery(hook->data, battery->bat); } /* Then, just remove the battery from the list */ list_del(&battery->list); diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index 37d8649418f4..18afcf38931f 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -882,7 +882,7 @@ static ssize_t charge_control_end_threshold_show(struct device *device, static DEVICE_ATTR_RW(charge_control_end_threshold); -static int asus_wmi_battery_add(struct power_supply *battery) +static int asus_wmi_battery_add(void *data, struct power_supply *battery) { /* The WMI method does not provide a way to specific a battery, so we * just assume it is the first battery. @@ -909,7 +909,7 @@ static int asus_wmi_battery_add(struct power_supply *battery) return 0; } -static int asus_wmi_battery_remove(struct power_supply *battery) +static int asus_wmi_battery_remove(void *data, struct power_supply *battery) { device_remove_file(&battery->dev, &dev_attr_charge_control_end_threshold); @@ -924,7 +924,8 @@ static const struct acpi_battery_hook_ops battery_hook_ops = { static void asus_wmi_battery_init(struct asus_wmi *asus) { if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_RSOC)) { - asus->hook = battery_hook_register("ASUS Battery Extension", &battery_hook_ops); + asus->hook = battery_hook_register("ASUS Battery Extension", NULL, + &battery_hook_ops); } } diff --git a/drivers/platform/x86/huawei-wmi.c b/drivers/platform/x86/huawei-wmi.c index 6fd02b25a97b..f23806299c1a 100644 --- a/drivers/platform/x86/huawei-wmi.c +++ b/drivers/platform/x86/huawei-wmi.c @@ -469,7 +469,7 @@ static DEVICE_ATTR_RW(charge_control_start_threshold); static DEVICE_ATTR_RW(charge_control_end_threshold); static DEVICE_ATTR_RW(charge_control_thresholds); -static int huawei_wmi_battery_add(struct power_supply *battery) +static int huawei_wmi_battery_add(void *data, struct power_supply *battery) { int err = 0; @@ -484,7 +484,7 @@ static int huawei_wmi_battery_add(struct power_supply *battery) return err; } -static int huawei_wmi_battery_remove(struct power_supply *battery) +static int huawei_wmi_battery_remove(void *data, struct power_supply *battery) { device_remove_file(&battery->dev, &dev_attr_charge_control_start_threshold); device_remove_file(&battery->dev, &dev_attr_charge_control_end_threshold); @@ -507,7 +507,7 @@ static void huawei_wmi_battery_setup(struct device *dev) return; } - huawei->hook = battery_hook_register("Huawei Battery Extension", + huawei->hook = battery_hook_register("Huawei Battery Extension", NULL, &huawei_wmi_battery_hook_ops); device_create_file(dev, &dev_attr_charge_control_thresholds); } diff --git a/drivers/platform/x86/lg-laptop.c b/drivers/platform/x86/lg-laptop.c index d8a61a07313e..f1abb1924150 100644 --- a/drivers/platform/x86/lg-laptop.c +++ b/drivers/platform/x86/lg-laptop.c @@ -547,7 +547,7 @@ static DEVICE_ATTR_RW(fn_lock); static DEVICE_ATTR_RW(charge_control_end_threshold); static DEVICE_ATTR_RW(battery_care_limit); -static int lg_battery_add(struct power_supply *battery) +static int lg_battery_add(void *data, struct power_supply *battery) { if (device_create_file(&battery->dev, &dev_attr_charge_control_end_threshold)) @@ -556,7 +556,7 @@ static int lg_battery_add(struct power_supply *battery) return 0; } -static int lg_battery_remove(struct power_supply *battery) +static int lg_battery_remove(void *data, struct power_supply *battery) { device_remove_file(&battery->dev, &dev_attr_charge_control_end_threshold); @@ -750,7 +750,7 @@ static int acpi_add(struct acpi_device *device) led_classdev_register(&pf_device->dev, &tpad_led); wmi_input_setup(); - hook = battery_hook_register("LG Battery Extension", &battery_hook_ops); + hook = battery_hook_register("LG Battery Extension", NULL, &battery_hook_ops); return 0; diff --git a/drivers/platform/x86/system76_acpi.c b/drivers/platform/x86/system76_acpi.c index 1ec22db32bd0..9414b9491806 100644 --- a/drivers/platform/x86/system76_acpi.c +++ b/drivers/platform/x86/system76_acpi.c @@ -255,7 +255,7 @@ static struct attribute *system76_battery_attrs[] = { ATTRIBUTE_GROUPS(system76_battery); -static int system76_battery_add(struct power_supply *battery) +static int system76_battery_add(void *data, struct power_supply *battery) { // System76 EC only supports 1 battery if (strcmp(battery->desc->name, "BAT0") != 0) @@ -267,7 +267,7 @@ static int system76_battery_add(struct power_supply *battery) return 0; } -static int system76_battery_remove(struct power_supply *battery) +static int system76_battery_remove(void *data, struct power_supply *battery) { device_remove_groups(&battery->dev, system76_battery_groups); return 0; @@ -280,7 +280,7 @@ static const struct acpi_battery_hook_ops system76_battery_hook_ops = { static void system76_battery_init(struct system76_data *data) { - data->hook = battery_hook_register("System76 Battery Extension", + data->hook = battery_hook_register("System76 Battery Extension", NULL, &system76_battery_hook_ops); } diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c index 8adafc3c31fa..6008d88e0727 100644 --- a/drivers/platform/x86/thinkpad_acpi.c +++ b/drivers/platform/x86/thinkpad_acpi.c @@ -9898,7 +9898,7 @@ ATTRIBUTE_GROUPS(tpacpi_battery); /* ACPI battery hooking */ -static int tpacpi_battery_add(struct power_supply *battery) +static int tpacpi_battery_add(void *data, struct power_supply *battery) { int batteryid = tpacpi_battery_get_id(battery->desc->name); @@ -9909,7 +9909,7 @@ static int tpacpi_battery_add(struct power_supply *battery) return 0; } -static int tpacpi_battery_remove(struct power_supply *battery) +static int tpacpi_battery_remove(void *data, struct power_supply *battery) { device_remove_groups(&battery->dev, tpacpi_battery_groups); return 0; @@ -9943,7 +9943,7 @@ static int __init tpacpi_battery_init(struct ibm_init_struct *ibm) battery_quirk_table, ARRAY_SIZE(battery_quirk_table)); - battery_info.hook = battery_hook_register("ThinkPad Battery Extension", + battery_info.hook = battery_hook_register("ThinkPad Battery Extension", NULL, &battery_hook_ops); return 0; diff --git a/include/acpi/battery.h b/include/acpi/battery.h index b3c81abada1e..cca401b793b2 100644 --- a/include/acpi/battery.h +++ b/include/acpi/battery.h @@ -11,17 +11,18 @@ #define ACPI_BATTERY_NOTIFY_THRESHOLD 0x82 struct acpi_battery_hook_ops { - int (*add_battery)(struct power_supply *battery); - int (*remove_battery)(struct power_supply *battery); + int (*add_battery)(void *data, struct power_supply *battery); + int (*remove_battery)(void *data, struct power_supply *battery); }; struct acpi_battery_hook { const char *name; const struct acpi_battery_hook_ops *ops; + void *data; struct list_head list; }; -struct acpi_battery_hook *battery_hook_register(const char *name, +struct acpi_battery_hook *battery_hook_register(const char *name, void *data, const struct acpi_battery_hook_ops *hook); void battery_hook_unregister(struct acpi_battery_hook *hook); From patchwork Mon Sep 12 12:53:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 605317 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6535EC6FA8D for ; Mon, 12 Sep 2022 12:54:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229845AbiILMyW (ORCPT ); Mon, 12 Sep 2022 08:54:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229873AbiILMyT (ORCPT ); Mon, 12 Sep 2022 08:54:19 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99E6F39B89; Mon, 12 Sep 2022 05:54:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1662987234; bh=hk5t2e+oj5yO3UwZJOPmpX0A2h5nxw6Irm3GZCkWWjU=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=HZWjZnyC8mmH39rZ70BLIu0Cim5NB0ZDJxvgLF2XA2+ZjU/HS6umYzThUSSCyUhu2 CzrGQuaulWf7Cg7ZHPFgfyXfX14qpYhrUPL3q6tBO/0tuVA1NWVXTln5W3OEzRObDB LUHCe8EFkba8Cq5SN2fs6ScYdGZbc4MPErYPY8tk= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from esprimo-mx.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MwQXN-1pNM1s3Em5-00sQDs; Mon, 12 Sep 2022 14:53:53 +0200 From: Armin Wolf To: hdegoede@redhat.com, markgross@kernel.org Cc: rafael@kernel.org, lenb@kernel.org, hmh@hmh.eng.br, matan@svgalib.org, corentin.chary@gmail.com, jeremy@system76.com, productdev@system76.com, platform-driver-x86@vger.kernel.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/5] platform/x86: dell: Add new dell-wmi-ddv driver Date: Mon, 12 Sep 2022 14:53:42 +0200 Message-Id: <20220912125342.7395-6-W_Armin@gmx.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220912125342.7395-1-W_Armin@gmx.de> References: <20220912125342.7395-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:KaVfppH25SNtBQGGAmEyAtS0NiHFH55eBR6zzMvq90fkEtS/DPR GOPZeJ8Sgpddz82XlGlApc+1btIcF6tZCxiXFlq/+W2ScyIDPmzYtX2OqqNccNGnr20z9Ir oGXVXh++sR3sN0MKOjnGY1HF4JNpZdareqocfjMZ8U9pPY/Gu3fB3aQ4UOKWXMYz2l9E21+ yJ69fKP0PxGjbuIIX6dgg== X-UI-Out-Filterresults: notjunk:1;V03:K0:RzHAru8r6rI=:JdiMj+2Ur3Qi89yC8XarXY P28XAeVcDLdAVGc+WXot5FlgU4sQNjm1uPnJ6m/8pgS5R792MZtVmpJe+Ox17msIE2ASxsSWW A/+TYktsBlOiz4b/AJ8EGpwDM1opE5kvi2/l/y+dbUWjAruc6YpzDXVNVjzE3LbxrYwocmi0g JYhN1o/uSjFfJChFq38X8HLY5jGaAzQnnC1t9iUsC78lgW1DwbO7iMHZLB7g7N+cN66G/d7Cb sJZUQ8qTPkIj5gW+Cya4BdVR4GaOuHdAnHzhgSyHbUsY7R4QZlEdXvd5zn39gLAPA9ezjRZoE Eg/XQ7RiR61NeMPvQbxEkPq2Y37VD3v7RYqNlAX3Mda2D1Kb0d1VohqtD8DCvc90rZ3iQxTL9 nYKGEHzcrkye8auHZpzguiYU+Bnl8aLRg7WLO9F2fei6MFCpYgES3ncmsEHv4b9pQBgz6vL19 vj6gckoiYgvGhWQkuZE5/ARb6PbzerHLK85aHxFluVnnTnbdnaE9su5KxzxsHrNwmD6JFE3kN Mv+49KQIYRkkpzPrp4rG2Cvd9ZpKR5yb+tfup6+0bpmrplOxXDDitTkE/HDhfpK11+Cs7aw96 7MC8OGs+avPUBJLoOLriRNrXro8BY57IISIjex9DWBRIyeAT39ShAyi80foHHeM4USJ/EoJkd Zz9VuewbsWoWdJIjMe5PaIDjbTjyOVqMsecseBbDY2mPe7n0VAT/dqXmwnKShwcOCsc/gSabl R0JHD4i3+6ttotCIshOxuslYmQt/MdDPYk2Y0omQ5L+vKprk5bIfrhq21WdNNRrmWQaTdVkn4 aIEu1TRiZKaIB9pM3JXQu09wBFV8Ql3mmba09Y5H3NslLKALyzfPZLZZoIfeEIqD/J/nqP6MG wcL/jwll7Rcj7LL0tR5weRqCe3MdHMiFv/zTLH0CHAGOGI0MlLEkU5YrtM2fDI+hiAEDOaDTd m3RPY+IB2zZUgM2dkkM5ECfS8du1duYwAva00aMzSnBL2q+BY6knqbm9zsJ1XspngWjTHEglA i4kJe1aO4ujL4h0SMEYVDTuola7RDhVILiKv/x5FM9lGJ/RJvB1C4e0WtEy7yIbsjj/Pj/qip WyoxpOBOtTf10EMFqob715c+Vxz22UdiuOK/sDEwvUkzWxlmOoZ+624s6p0ZZQm2BTexTALij APYx4XIjfdIYTHoX8QIC+1MasJ Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org The dell-wmi-ddv driver adds support for reading the current temperature and ePPID of ACPI batteries on supported Dell machines. Since the WMI interface used by this driver does not do any input validation and thus cannot be used for probing, the driver depends on the ACPI battery extension machanism to discover batteries. The driver also supports a debugfs interface for retrieving buffers containing fan and thermal sensor information. Since the meaing of the content of those buffers is currently unknown, the interface is meant for reverse-engineering and will likely be replaced with an hwmon interface once the meaning has been understood. The driver was tested on a Dell Inspiron 3505. Signed-off-by: Armin Wolf Reviewed-by: Hans de Goede --- .../ABI/testing/debugfs-dell-wmi-ddv | 21 + .../ABI/testing/sysfs-platform-dell-wmi-ddv | 16 + MAINTAINERS | 7 + drivers/platform/x86/dell/Kconfig | 13 + drivers/platform/x86/dell/Makefile | 1 + drivers/platform/x86/dell/dell-wmi-ddv.c | 365 ++++++++++++++++++ drivers/platform/x86/wmi.c | 1 + 7 files changed, 424 insertions(+) create mode 100644 Documentation/ABI/testing/debugfs-dell-wmi-ddv create mode 100644 Documentation/ABI/testing/sysfs-platform-dell-wmi-ddv create mode 100644 drivers/platform/x86/dell/dell-wmi-ddv.c -- 2.30.2 diff --git a/Documentation/ABI/testing/debugfs-dell-wmi-ddv b/Documentation/ABI/testing/debugfs-dell-wmi-ddv new file mode 100644 index 000000000000..fbcc5d6f7388 --- /dev/null +++ b/Documentation/ABI/testing/debugfs-dell-wmi-ddv @@ -0,0 +1,21 @@ +What: /sys/kernel/debug/dell-wmi-ddv-/fan_sensor_information +Date: September 2022 +KernelVersion: 6.1 +Contact: Armin Wolf +Description: + This file contains the contents of the fan sensor information buffer, + which contains fan sensor entries and a terminating character (0xFF). + + Each fan sensor entry consists of three bytes with an unknown meaning, + interested people may use this file for reverse-engineering. + +What: /sys/kernel/debug/dell-wmi-ddv-/thermal_sensor_information +Date: September 2022 +KernelVersion: 6.1 +Contact: Armin Wolf +Description: + This file contains the contents of the thermal sensor information buffer, + which contains thermal sensor entries and a terminating character (0xFF). + + Each thermal sensor entry consists of five bytes with an unknown meaning, + interested people may use this file for reverse-engineering. diff --git a/Documentation/ABI/testing/sysfs-platform-dell-wmi-ddv b/Documentation/ABI/testing/sysfs-platform-dell-wmi-ddv new file mode 100644 index 000000000000..98e0b8399d13 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-platform-dell-wmi-ddv @@ -0,0 +1,16 @@ +What: /sys/class/power_supply//temp +Date: September 2022 +KernelVersion: 6.1 +Contact: Armin Wolf +Description: + Reports the current ACPI battery temperature on supported Dell machines. + + Values are represented in 1/10 Degrees Celsius. + +What: /sys/class/power_supply//eppid +Date: September 2022 +KernelVersion: 6.1 +Contact: Armin Wolf +Description: + Reports the Dell ePPID (electronic Dell Piece Part Identification) + of the ACPI battery. diff --git a/MAINTAINERS b/MAINTAINERS index 6bb894ea4a77..d9fd4c9eebbc 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -5821,6 +5821,13 @@ L: Dell.Client.Kernel@dell.com S: Maintained F: drivers/platform/x86/dell/dell-wmi-descriptor.c +DELL WMI DDV DRIVER +M: Armin Wolf +S: Maintained +F: Documentation/ABI/testing/debugfs-dell-wmi-ddv +F: Documentation/ABI/testing/sysfs-platform-dell-wmi-ddv +F: drivers/platform/x86/dell/dell-wmi-ddv.c + DELL WMI SYSMAN DRIVER M: Divya Bharathi M: Prasanth Ksr diff --git a/drivers/platform/x86/dell/Kconfig b/drivers/platform/x86/dell/Kconfig index 25421e061c47..209e63e347e2 100644 --- a/drivers/platform/x86/dell/Kconfig +++ b/drivers/platform/x86/dell/Kconfig @@ -189,6 +189,19 @@ config DELL_WMI_DESCRIPTOR default n depends on ACPI_WMI +config DELL_WMI_DDV + tristate "Dell WMI sensors Support" + default m + depends on ACPI_BATTERY + depends on ACPI_WMI + help + This option adds support for WMI-based sensors like + battery temperature sensors found on some Dell notebooks. + It also supports reading of the batteries ePPID. + + To compile this drivers as a module, choose M here: the module will + be called dell-wmi-ddv. + config DELL_WMI_LED tristate "External LED on Dell Business Netbooks" default m diff --git a/drivers/platform/x86/dell/Makefile b/drivers/platform/x86/dell/Makefile index ddba1df71e80..1b8942426622 100644 --- a/drivers/platform/x86/dell/Makefile +++ b/drivers/platform/x86/dell/Makefile @@ -19,5 +19,6 @@ dell-wmi-objs := dell-wmi-base.o dell-wmi-$(CONFIG_DELL_WMI_PRIVACY) += dell-wmi-privacy.o obj-$(CONFIG_DELL_WMI_AIO) += dell-wmi-aio.o obj-$(CONFIG_DELL_WMI_DESCRIPTOR) += dell-wmi-descriptor.o +obj-$(CONFIG_DELL_WMI_DDV) += dell-wmi-ddv.o obj-$(CONFIG_DELL_WMI_LED) += dell-wmi-led.o obj-$(CONFIG_DELL_WMI_SYSMAN) += dell-wmi-sysman/ diff --git a/drivers/platform/x86/dell/dell-wmi-ddv.c b/drivers/platform/x86/dell/dell-wmi-ddv.c new file mode 100644 index 000000000000..6eef298f13eb --- /dev/null +++ b/drivers/platform/x86/dell/dell-wmi-ddv.c @@ -0,0 +1,365 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * dell-wmi-ddv.c -- Linux driver for WMI sensor information on Dell notebooks. + * + * Copyright (C) 2022 Armin Wolf + */ + +#define pr_format(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define DRIVER_NAME "dell-wmi-ddv" + +#define DELL_DDV_SUPPORTED_INTERFACE 2 +#define DELL_DDV_GUID "8A42EA14-4F2A-FD45-6422-0087F7A7E608" + +enum dell_ddv_method { + DELL_DDV_BATTERY_DESIGN_CAPACITY = 0x01, + DELL_DDV_BATTERY_FULL_CHARGE_CAPACITY = 0x02, + DELL_DDV_BATTERY_MANUFACTURE_NAME = 0x03, + DELL_DDV_BATTERY_MANUFACTURE_DATE = 0x04, + DELL_DDV_BATTERY_SERIAL_NUMBER = 0x05, + DELL_DDV_BATTERY_CHEMISTRY_VALUE = 0x06, + DELL_DDV_BATTERY_TEMPERATURE = 0x07, + DELL_DDV_BATTERY_CURRENT = 0x08, + DELL_DDV_BATTERY_VOLTAGE = 0x09, + DELL_DDV_BATTERY_MANUFACTURER_ACCESS = 0x0A, + DELL_DDV_BATTERY_RELATIVE_CHARGE_STATE = 0x0B, + DELL_DDV_BATTERY_CYCLE_COUNT = 0x0C, + DELL_DDV_BATTERY_EPPID = 0x0D, + DELL_DDV_BATTERY_RAW_ANALYTICS_START = 0x0E, + DELL_DDV_BATTERY_RAW_ANALYTICS = 0x0F, + DELL_DDV_BATTERY_DESIGN_VOLTAGE = 0x10, + + DELL_DDV_INTERFACE_VERSION = 0x12, + + DELL_DDV_FAN_SENSOR_INFORMATION = 0x20, + DELL_DDV_THERMAL_SENSOR_INFORMATION = 0x22, +}; + +struct dell_wmi_ddv_data { + struct device_attribute temp_attr, eppid_attr; + struct wmi_device *wdev; +}; + +static int dell_wmi_ddv_query_type(struct wmi_device *wdev, enum dell_ddv_method method, u32 arg, + union acpi_object **result, acpi_object_type type) +{ + struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL }; + const struct acpi_buffer in = { + .length = sizeof(arg), + .pointer = &arg, + }; + union acpi_object *obj; + acpi_status ret; + + ret = wmidev_evaluate_method(wdev, 0x0, method, &in, &out); + if (ACPI_FAILURE(ret)) + return -EIO; + + obj = out.pointer; + if (!obj) + return -ENODATA; + + if (obj->type != type) { + kfree(obj); + return -EIO; + } + + *result = obj; + + return 0; +} + +static int dell_wmi_ddv_query_integer(struct wmi_device *wdev, enum dell_ddv_method method, + u32 arg, u32 *res) +{ + union acpi_object *obj; + int ret; + + ret = dell_wmi_ddv_query_type(wdev, method, arg, &obj, ACPI_TYPE_INTEGER); + if (ret < 0) + return ret; + + if (obj->integer.value <= U32_MAX) + *res = (u32)obj->integer.value; + else + ret = -ERANGE; + + kfree(obj); + + return ret; +} + +static int dell_wmi_ddv_query_buffer(struct wmi_device *wdev, enum dell_ddv_method method, + u32 arg, union acpi_object **result) +{ + union acpi_object *obj; + u64 buffer_size; + int ret; + + ret = dell_wmi_ddv_query_type(wdev, method, arg, &obj, ACPI_TYPE_PACKAGE); + if (ret < 0) + return ret; + + if (obj->package.count != 2) + goto err_free; + + if (obj->package.elements[0].type != ACPI_TYPE_INTEGER) + goto err_free; + + buffer_size = obj->package.elements[0].integer.value; + + if (obj->package.elements[1].type != ACPI_TYPE_BUFFER) + goto err_free; + + if (buffer_size != obj->package.elements[1].buffer.length) { + dev_warn(&wdev->dev, + FW_WARN "ACPI buffer size (%llu) does not match WMI buffer size (%d)\n", + buffer_size, obj->package.elements[1].buffer.length); + + goto err_free; + } + + *result = obj; + + return 0; + +err_free: + kfree(obj); + + return -EIO; +} + +static int dell_wmi_ddv_query_string(struct wmi_device *wdev, enum dell_ddv_method method, + u32 arg, union acpi_object **result) +{ + return dell_wmi_ddv_query_type(wdev, method, arg, result, ACPI_TYPE_STRING); +} + +static int dell_wmi_ddv_battery_index(struct acpi_device *acpi_dev, u32 *index) +{ + const char *uid_str = acpi_device_uid(acpi_dev); + + if (!uid_str) + return -ENODEV; + + return kstrtou32(uid_str, 10, index); +} + +static ssize_t temp_show(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct dell_wmi_ddv_data *data = container_of(attr, struct dell_wmi_ddv_data, temp_attr); + u32 index, value; + int ret; + + ret = dell_wmi_ddv_battery_index(to_acpi_device(dev->parent), &index); + if (ret < 0) + return ret; + + ret = dell_wmi_ddv_query_integer(data->wdev, DELL_DDV_BATTERY_TEMPERATURE, index, &value); + if (ret < 0) + return ret; + + return sysfs_emit(buf, "%d\n", DIV_ROUND_CLOSEST(value, 10)); +} + +static ssize_t eppid_show(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct dell_wmi_ddv_data *data = container_of(attr, struct dell_wmi_ddv_data, eppid_attr); + union acpi_object *obj; + u32 index; + int ret; + + ret = dell_wmi_ddv_battery_index(to_acpi_device(dev->parent), &index); + if (ret < 0) + return ret; + + ret = dell_wmi_ddv_query_string(data->wdev, DELL_DDV_BATTERY_EPPID, index, &obj); + if (ret < 0) + return ret; + + ret = sysfs_emit(buf, "%s\n", obj->string.pointer); + + kfree(obj); + + return ret; +} + +static int dell_wmi_ddv_add_battery(void *drvdata, struct power_supply *battery) +{ + struct dell_wmi_ddv_data *data = drvdata; + u32 index; + int ret; + + ret = dell_wmi_ddv_battery_index(to_acpi_device(battery->dev.parent), &index); + if (ret < 0) + return ret; + + ret = device_create_file(&battery->dev, &data->temp_attr); + if (ret < 0) + return ret; + + ret = device_create_file(&battery->dev, &data->eppid_attr); + if (ret < 0) { + device_remove_file(&battery->dev, &data->temp_attr); + + return ret; + } + + return 0; +} + +static int dell_wmi_ddv_remove_battery(void *drvdata, struct power_supply *battery) +{ + struct dell_wmi_ddv_data *data = drvdata; + + device_remove_file(&battery->dev, &data->temp_attr); + device_remove_file(&battery->dev, &data->eppid_attr); + + return 0; +} + +static const struct acpi_battery_hook_ops dell_wmi_ddv_battery_hook_ops = { + .add_battery = dell_wmi_ddv_add_battery, + .remove_battery = dell_wmi_ddv_remove_battery, +}; + +static void dell_wmi_ddv_battery_remove(void *data) +{ + struct acpi_battery_hook *hook = data; + + battery_hook_unregister(hook); +} + +static int dell_wmi_ddv_battery_add(struct dell_wmi_ddv_data *data) +{ + struct acpi_battery_hook *hook; + + sysfs_attr_init(&data->temp_attr.attr); + data->temp_attr.attr.name = "temp"; + data->temp_attr.attr.mode = 0444; + data->temp_attr.show = temp_show; + + sysfs_attr_init(&data->eppid_attr.attr); + data->eppid_attr.attr.name = "eppid"; + data->eppid_attr.attr.mode = 0444; + data->eppid_attr.show = eppid_show; + + hook = battery_hook_register("DELL Battery Extension", data, + &dell_wmi_ddv_battery_hook_ops); + if (IS_ERR(hook)) + return PTR_ERR(hook); + + return devm_add_action_or_reset(&data->wdev->dev, dell_wmi_ddv_battery_remove, hook); +} + +static int dell_wmi_ddv_buffer_read(struct seq_file *seq, enum dell_ddv_method method) +{ + struct device *dev = seq->private; + struct dell_wmi_ddv_data *data = dev_get_drvdata(dev); + union acpi_object *obj; + union acpi_object buf; + int ret; + + ret = dell_wmi_ddv_query_buffer(data->wdev, method, 0, &obj); + if (ret < 0) + return ret; + + buf = obj->package.elements[1]; + ret = seq_write(seq, buf.buffer.pointer, buf.buffer.length); + kfree(obj); + + return ret; +} + +static int dell_wmi_ddv_fan_read(struct seq_file *seq, void *offset) +{ + return dell_wmi_ddv_buffer_read(seq, DELL_DDV_FAN_SENSOR_INFORMATION); +} + +static int dell_wmi_ddv_temp_read(struct seq_file *seq, void *offset) +{ + return dell_wmi_ddv_buffer_read(seq, DELL_DDV_THERMAL_SENSOR_INFORMATION); +} + +static void dell_wmi_ddv_debugfs_remove(void *data) +{ + struct dentry *entry = data; + + debugfs_remove(entry); +} + +static void dell_wmi_ddv_debugfs_init(struct wmi_device *wdev) +{ + struct dentry *entry; + char name[64]; + + scnprintf(name, ARRAY_SIZE(name), "%s-%s", DRIVER_NAME, dev_name(&wdev->dev)); + entry = debugfs_create_dir(name, NULL); + + debugfs_create_devm_seqfile(&wdev->dev, "fan_sensor_information", entry, + dell_wmi_ddv_fan_read); + debugfs_create_devm_seqfile(&wdev->dev, "thermal_sensor_information", entry, + dell_wmi_ddv_temp_read); + + devm_add_action_or_reset(&wdev->dev, dell_wmi_ddv_debugfs_remove, entry); +} + +static int dell_wmi_ddv_probe(struct wmi_device *wdev, const void *context) +{ + struct dell_wmi_ddv_data *data; + u32 version; + int ret; + + ret = dell_wmi_ddv_query_integer(wdev, DELL_DDV_INTERFACE_VERSION, 0, &version); + if (ret < 0) + return ret; + + dev_dbg(&wdev->dev, "WMI interface version: %d\n", version); + if (version != DELL_DDV_SUPPORTED_INTERFACE) + return -ENODEV; + + data = devm_kzalloc(&wdev->dev, sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + dev_set_drvdata(&wdev->dev, data); + data->wdev = wdev; + + dell_wmi_ddv_debugfs_init(wdev); + + return dell_wmi_ddv_battery_add(data); +} + +static const struct wmi_device_id dell_wmi_ddv_id_table[] = { + { DELL_DDV_GUID, NULL }, + { } +}; +MODULE_DEVICE_TABLE(wmi, dell_wmi_ddv_id_table); + +static struct wmi_driver dell_wmi_ddv_driver = { + .driver = { + .name = DRIVER_NAME, + }, + .id_table = dell_wmi_ddv_id_table, + .probe = dell_wmi_ddv_probe, +}; +module_wmi_driver(dell_wmi_ddv_driver); + +MODULE_AUTHOR("Armin Wolf "); +MODULE_DESCRIPTION("Dell WMI sensor driver"); +MODULE_LICENSE("GPL"); diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c index aff23309b5d3..f307d8c5c6c3 100644 --- a/drivers/platform/x86/wmi.c +++ b/drivers/platform/x86/wmi.c @@ -108,6 +108,7 @@ MODULE_DEVICE_TABLE(acpi, wmi_device_ids); /* allow duplicate GUIDs as these device drivers use struct wmi_driver */ static const char * const allow_duplicates[] = { "05901221-D566-11D1-B2F0-00A0C9062910", /* wmi-bmof */ + "8A42EA14-4F2A-FD45-6422-0087F7A7E608", /* dell-wmi-ddv */ NULL };