From patchwork Sun Oct 31 16:24:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 12595295 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A531C433F5 for ; Sun, 31 Oct 2021 16:25:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DE8B460F58 for ; Sun, 31 Oct 2021 16:25:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230377AbhJaQ1a (ORCPT ); Sun, 31 Oct 2021 12:27:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:24506 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230120AbhJaQ1P (ORCPT ); Sun, 31 Oct 2021 12:27:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635697483; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FN7A1ujpQU/zFOX8EqwJrJMl7Y0oOgtAm3LGtcEJ7Ko=; b=YX3mbcNX0SsC8apBaCcOZikWE33SfwSUflA0euzPOojDieLIIkXPSxMGfmZIk706UgbzfU aIUJT53xIZ6ExH74s1IgyirnlhxslcFKQEBXPzR9iKWnrzMcExwZ1D3W/QAgAxQOsNj2lY AEq7Rr628qX5n22+KGR0Q+J7pq2gllc= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-303-LN3JFnwcPSeZLLd5YiDyLw-1; Sun, 31 Oct 2021 12:24:39 -0400 X-MC-Unique: LN3JFnwcPSeZLLd5YiDyLw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1EA8F8018AC; Sun, 31 Oct 2021 16:24:37 +0000 (UTC) Received: from x1.localdomain.com (unknown [10.39.192.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9F30B1017CE8; Sun, 31 Oct 2021 16:24:33 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Mika Westerberg , Mark Gross , Andy Shevchenko , Wolfram Sang , Sebastian Reichel , MyungJoo Ham , Chanwoo Choi , Ard Biesheuvel Cc: Hans de Goede , Len Brown , linux-acpi@vger.kernel.org, Yauhen Kharuzhy , Tsuchiya Yuto , platform-driver-x86@vger.kernel.org, linux-i2c@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [RFC 1/5] ACPI / x86: Add 3 devices on the Xiaomi Mi Pad 2 to the always_present list Date: Sun, 31 Oct 2021 17:24:24 +0100 Message-Id: <20211031162428.22368-2-hdegoede@redhat.com> In-Reply-To: <20211031162428.22368-1-hdegoede@redhat.com> References: <20211031162428.22368-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The Xiaomi Mi Pad 2 ships in both Windows and Android variants and the BIOS detects the OS by looking at the EFI executable the efibootmgr entry points to. If this executable is not the original Android bootloader (signed with Xiaomi's own keys) it detects the OS as Windows and sets the OSID variable used in the DSDT to "1". This causes the following problems when running Linux: 1. Like many other CHT based tablets the Xiaomi Mi Pad 2 does not have a properly working ACPI battery interface instead we need to load a native driver for the fuel-gauge, but the TXN27520 ACPI device for the fuel-gauge gets hidden when OSID == "1". 2. There are backlit LEDs behind the capacitive menu, home, back buttons below the screen which are controlled by the second PWM controller of the CHT SoC, this gets hidden when OSID == "1". 3. There is an I2C attached KTD2026 RGB LED controller for the notification LED, this gets hidden when OSID != "4". Add always_present_ids table entries for these devices so that they are always seen as present independent of the OSID value. Note the TXN27520 ACPI device does not have a UID set, so add support for matching devices with no UID. Signed-off-by: Hans de Goede --- drivers/acpi/x86/utils.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/drivers/acpi/x86/utils.c b/drivers/acpi/x86/utils.c index f22f23933063..831949fda492 100644 --- a/drivers/acpi/x86/utils.c +++ b/drivers/acpi/x86/utils.c @@ -58,6 +58,11 @@ static const struct always_present_id always_present_ids[] = { ENTRY("80862289", "2", X86_MATCH(ATOM_AIRMONT), { DMI_MATCH(DMI_PRODUCT_NAME, "Lenovo YB1-X9"), }), + /* The Xiaomi Mi Pad 2 uses PWM2 for touchkeys backlight control */ + ENTRY("80862289", "2", X86_MATCH(ATOM_AIRMONT), { + DMI_MATCH(DMI_SYS_VENDOR, "Xiaomi Inc"), + DMI_MATCH(DMI_PRODUCT_NAME, "Mipad2"), + }), /* * The INT0002 device is necessary to clear wakeup interrupt sources * on Cherry Trail devices, without it we get nobody cared IRQ msgs. @@ -107,6 +112,24 @@ static const struct always_present_id always_present_ids[] = { DMI_MATCH(DMI_PRODUCT_NAME, "Default string"), DMI_MATCH(DMI_BIOS_DATE, "05/25/2017") }), + /* + * The Xiaomi Mi Pad 2 does not use the ACPI battery interface + * instead we need to load a native driver for the fuel-gauge, + * but if the BIOS thinks we are Windows rather then Android, + * the fuel-gauge ACPI device is hidden. + */ + ENTRY("TXN27520", NULL, X86_MATCH(ATOM_AIRMONT), { + DMI_MATCH(DMI_SYS_VENDOR, "Xiaomi Inc"), + DMI_MATCH(DMI_PRODUCT_NAME, "Mipad2"), + }), + /* + * The Xiaomi Mi Pad 2 has a RGB LED controller for its notifcation + * LED which is hidden when the BIOS thinks we are Windows, unhide it. + */ + ENTRY("KTD20260", "1", X86_MATCH(ATOM_AIRMONT), { + DMI_MATCH(DMI_SYS_VENDOR, "Xiaomi Inc"), + DMI_MATCH(DMI_PRODUCT_NAME, "Mipad2"), + }), }; bool acpi_device_always_present(struct acpi_device *adev) @@ -118,8 +141,8 @@ bool acpi_device_always_present(struct acpi_device *adev) if (acpi_match_device_ids(adev, always_present_ids[i].hid)) continue; - if (!adev->pnp.unique_id || - strcmp(adev->pnp.unique_id, always_present_ids[i].uid)) + if (always_present_ids[i].uid && (!adev->pnp.unique_id || + strcmp(adev->pnp.unique_id, always_present_ids[i].uid))) continue; if (!x86_match_cpu(always_present_ids[i].cpu_ids)) From patchwork Sun Oct 31 16:24:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 12595297 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 52EABC433F5 for ; Sun, 31 Oct 2021 16:25:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3BE7E60EE3 for ; Sun, 31 Oct 2021 16:25:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230468AbhJaQ1d (ORCPT ); Sun, 31 Oct 2021 12:27:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:33208 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230145AbhJaQ1U (ORCPT ); Sun, 31 Oct 2021 12:27:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635697486; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hnwM/VxBeSUArrlRw7RqLce8E045sD/TjiPL5pXvtrU=; b=Q9OgevKTo1F/m+uYF2q9RUwid93vAaYAMqyVmfXBV6KMz+YroWko4aFQx/UpVyRg+Xhf2o VokRph4Q07RYuVVX0JIuUL7LxFnBhGBDeEQw9vSRpgog63BrNfwEGHZmb8BVJH50JNZ2Se JMiG0ku5EYPwVx3lByYDhfQUXnOuMd0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-386-tPQqVU_6PMyu-Uijlapnhg-1; Sun, 31 Oct 2021 12:24:43 -0400 X-MC-Unique: tPQqVU_6PMyu-Uijlapnhg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B3DA910A8E00; Sun, 31 Oct 2021 16:24:40 +0000 (UTC) Received: from x1.localdomain.com (unknown [10.39.192.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id 64D6510190A7; Sun, 31 Oct 2021 16:24:37 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Mika Westerberg , Mark Gross , Andy Shevchenko , Wolfram Sang , Sebastian Reichel , MyungJoo Ham , Chanwoo Choi , Ard Biesheuvel Cc: Hans de Goede , Len Brown , linux-acpi@vger.kernel.org, Yauhen Kharuzhy , Tsuchiya Yuto , platform-driver-x86@vger.kernel.org, linux-i2c@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [RFC 2/5] gpiolib: acpi: Make acpi_gpio_in_ignore_list() more generic Date: Sun, 31 Oct 2021 17:24:25 +0100 Message-Id: <20211031162428.22368-3-hdegoede@redhat.com> In-Reply-To: <20211031162428.22368-1-hdegoede@redhat.com> References: <20211031162428.22368-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Pass the ignore list to parse into acpi_gpio_in_ignore_list() instead of hardcoding it to the ignore_wake module-param. This is a preparation patch for adding support to fully ignore some _AEI entries. Signed-off-by: Hans de Goede --- drivers/gpio/gpiolib-acpi.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c index 47712b6903b5..342219a58a32 100644 --- a/drivers/gpio/gpiolib-acpi.c +++ b/drivers/gpio/gpiolib-acpi.c @@ -320,13 +320,15 @@ static struct gpio_desc *acpi_request_own_gpiod(struct gpio_chip *chip, return desc; } -static bool acpi_gpio_in_ignore_list(const char *controller_in, int pin_in) +static bool acpi_gpio_in_ignore_list(const char *ignore_list, + const char *controller_in, + int pin_in) { const char *controller, *pin_str; int len, pin; char *endp; - controller = ignore_wake; + controller = ignore_list; while (controller) { pin_str = strchr(controller, '@'); if (!pin_str) @@ -350,8 +352,8 @@ static bool acpi_gpio_in_ignore_list(const char *controller_in, int pin_in) return false; err: - pr_err_once("Error invalid value for gpiolib_acpi.ignore_wake: %s\n", - ignore_wake); + pr_err_once("Error invalid value for gpiolib_acpi.ignore_xxx: %s\n", + ignore_list); return false; } @@ -363,7 +365,7 @@ static bool acpi_gpio_irq_is_wake(struct device *parent, if (agpio->wake_capable != ACPI_WAKE_CAPABLE) return false; - if (acpi_gpio_in_ignore_list(dev_name(parent), pin)) { + if (acpi_gpio_in_ignore_list(ignore_wake, dev_name(parent), pin)) { dev_info(parent, "Ignoring wakeup on pin %d\n", pin); return false; } From patchwork Sun Oct 31 16:24:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 12595299 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77692C433EF for ; Sun, 31 Oct 2021 16:25:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5FD4960FC1 for ; Sun, 31 Oct 2021 16:25:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230222AbhJaQ1i (ORCPT ); Sun, 31 Oct 2021 12:27:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:55320 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230197AbhJaQ1U (ORCPT ); Sun, 31 Oct 2021 12:27:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635697488; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rErM9mU4rrqY2HhIkpXGYB44QeGVz2mXY7yCgAHfu74=; b=hy+7LMMb3pG1Kjk5GbTRN4TZIz1mLJ8oi+opGMl+aqIT9z4XXcVMEKLXFzBtP0AkycDtRv bWGKFqebAwXaOegwmleZNtblEWX8OhcqgTi0sdJecHfhWO8IohT3jLVCheAuF3TRzjsN5V 5i3vbmQT8qCJuYKe60JafrQdVE72yVo= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-29-SYnxvPuaMduoLH7jKyRtvw-1; Sun, 31 Oct 2021 12:24:46 -0400 X-MC-Unique: SYnxvPuaMduoLH7jKyRtvw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 570D41006AA3; Sun, 31 Oct 2021 16:24:44 +0000 (UTC) Received: from x1.localdomain.com (unknown [10.39.192.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id 053DC100763D; Sun, 31 Oct 2021 16:24:40 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Mika Westerberg , Mark Gross , Andy Shevchenko , Wolfram Sang , Sebastian Reichel , MyungJoo Ham , Chanwoo Choi , Ard Biesheuvel Cc: Hans de Goede , Len Brown , linux-acpi@vger.kernel.org, Yauhen Kharuzhy , Tsuchiya Yuto , platform-driver-x86@vger.kernel.org, linux-i2c@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [RFC 3/5] gpiolib: acpi: Add a new "ignore" module option Date: Sun, 31 Oct 2021 17:24:26 +0100 Message-Id: <20211031162428.22368-4-hdegoede@redhat.com> In-Reply-To: <20211031162428.22368-1-hdegoede@redhat.com> References: <20211031162428.22368-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Add a new "ignore" module option to completely ignore controller@pin combos from _AEI lists. And add a DMI quirk to ignore the interrupt of the BQ27520 fuel-gauge IC on the Xiaomi Mi Pad 2. On this device we use native charger + fuel-gauge drivers because of issues with the ACPI battery implementation. The _AEI listing of the fuel-gauge IRQ is intended for use with the unused ACPI battery implementation and is blocking the bq27xxx fuel-gauge driver from binding. Signed-off-by: Hans de Goede --- drivers/gpio/gpiolib-acpi.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c index 342219a58a32..2d08f33a22a6 100644 --- a/drivers/gpio/gpiolib-acpi.c +++ b/drivers/gpio/gpiolib-acpi.c @@ -32,9 +32,16 @@ MODULE_PARM_DESC(ignore_wake, "controller@pin combos on which to ignore the ACPI wake flag " "ignore_wake=controller@pin[,controller@pin[,...]]"); +static char *ignore; +module_param(ignore, charp, 0444); +MODULE_PARM_DESC(ignore, + "controller@pin combos which are to be ignored from _AEI lists " + "ignore=controller@pin[,controller@pin[,...]]"); + struct acpi_gpiolib_dmi_quirk { bool no_edge_events_on_boot; char *ignore_wake; + char *ignore; }; /** @@ -407,6 +414,11 @@ static acpi_status acpi_gpiochip_alloc_event(struct acpi_resource *ares, if (!handler) return AE_OK; + if (acpi_gpio_in_ignore_list(ignore, dev_name(chip->parent), pin)) { + dev_info(chip->parent, "Ignoring _AEI entry for pin %d\n", pin); + return AE_OK; + } + desc = acpi_request_own_gpiod(chip, agpio, 0, "ACPI:Event"); if (IS_ERR(desc)) { dev_err(chip->parent, @@ -1565,6 +1577,19 @@ static const struct dmi_system_id gpiolib_acpi_quirks[] __initconst = { .ignore_wake = "INT33FF:01@0", }, }, + { + /* + * On the Xiaomi Mi Pad 2 we use native battery drivers, disable + * the _AEI entry for the fuel-gauge IRQ. + */ + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Xiaomi Inc"), + DMI_MATCH(DMI_PRODUCT_NAME, "Mipad2"), + }, + .driver_data = &(struct acpi_gpiolib_dmi_quirk) { + .ignore = "INT33FF:03@52", + }, + }, {} /* Terminating entry */ }; @@ -1587,6 +1612,9 @@ static int __init acpi_gpio_setup_params(void) if (ignore_wake == NULL && quirk && quirk->ignore_wake) ignore_wake = quirk->ignore_wake; + if (ignore == NULL && quirk && quirk->ignore) + ignore = quirk->ignore; + return 0; } From patchwork Sun Oct 31 16:24:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 12595301 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49AEBC4332F for ; Sun, 31 Oct 2021 16:25:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3401960EE3 for ; Sun, 31 Oct 2021 16:25:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230106AbhJaQ1q (ORCPT ); Sun, 31 Oct 2021 12:27:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:42848 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230320AbhJaQ12 (ORCPT ); Sun, 31 Oct 2021 12:27:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635697495; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fPOEwjI1K1hO+z9xpZRtE63xzqb/sG/Qd2WRtIRCf0M=; b=HOp/vxAohmSwK5gTgcSAhsxh3K+ixCeodwfsDzzn/x3kVIkBKH62dRuMRoNattun3drsjF Z+eXjoARmNwR6WOWZmYWJtwyDMUJYMAHMky7RTUz/95M1w8nhSx4m83ftrM3xxrlj+Cbhd THLmRtcIOJOf8tIIGGJR6vBjxE+uIsc= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-577-m8dTSM8mMaaylGzLBFFztA-1; Sun, 31 Oct 2021 12:24:50 -0400 X-MC-Unique: m8dTSM8mMaaylGzLBFFztA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EDB4A362F9; Sun, 31 Oct 2021 16:24:47 +0000 (UTC) Received: from x1.localdomain.com (unknown [10.39.192.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9BE3F100763D; Sun, 31 Oct 2021 16:24:44 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Mika Westerberg , Mark Gross , Andy Shevchenko , Wolfram Sang , Sebastian Reichel , MyungJoo Ham , Chanwoo Choi , Ard Biesheuvel Cc: Hans de Goede , Len Brown , linux-acpi@vger.kernel.org, Yauhen Kharuzhy , Tsuchiya Yuto , platform-driver-x86@vger.kernel.org, linux-i2c@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [RFC 4/5] power: supply: bq27xxx: Add dev helper variable to bq27xxx_battery_i2c_probe() Date: Sun, 31 Oct 2021 17:24:27 +0100 Message-Id: <20211031162428.22368-5-hdegoede@redhat.com> In-Reply-To: <20211031162428.22368-1-hdegoede@redhat.com> References: <20211031162428.22368-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Add a dev local variable to the bq27xxx_battery_i2c_probe(), to replace "&client->dev" in various places. Note the resulting cleanup is somewhat minimal, this is mostly a preparation for adding ACPI enumeration support which will use the new "dev" variable more. Signed-off-by: Hans de Goede --- drivers/power/supply/bq27xxx_battery_i2c.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/power/supply/bq27xxx_battery_i2c.c b/drivers/power/supply/bq27xxx_battery_i2c.c index cf38cbfe13e9..0a1b922389e1 100644 --- a/drivers/power/supply/bq27xxx_battery_i2c.c +++ b/drivers/power/supply/bq27xxx_battery_i2c.c @@ -139,6 +139,7 @@ static int bq27xxx_battery_i2c_bulk_write(struct bq27xxx_device_info *di, static int bq27xxx_battery_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) { + struct device *dev = &client->dev; struct bq27xxx_device_info *di; int ret; char *name; @@ -151,16 +152,16 @@ static int bq27xxx_battery_i2c_probe(struct i2c_client *client, if (num < 0) return num; - name = devm_kasprintf(&client->dev, GFP_KERNEL, "%s-%d", id->name, num); + name = devm_kasprintf(dev, GFP_KERNEL, "%s-%d", id->name, num); if (!name) goto err_mem; - di = devm_kzalloc(&client->dev, sizeof(*di), GFP_KERNEL); + di = devm_kzalloc(dev, sizeof(*di), GFP_KERNEL); if (!di) goto err_mem; di->id = num; - di->dev = &client->dev; + di->dev = dev; di->chip = id->driver_data; di->name = name; @@ -179,13 +180,12 @@ static int bq27xxx_battery_i2c_probe(struct i2c_client *client, i2c_set_clientdata(client, di); if (client->irq) { - ret = devm_request_threaded_irq(&client->dev, client->irq, + ret = devm_request_threaded_irq(dev, client->irq, NULL, bq27xxx_battery_irq_handler_thread, IRQF_ONESHOT, di->name, di); if (ret) { - dev_err(&client->dev, - "Unable to register IRQ %d error %d\n", + dev_err(dev, "Unable to register IRQ %d error %d\n", client->irq, ret); bq27xxx_battery_teardown(di); goto err_failed; From patchwork Sun Oct 31 16:24:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 12595303 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB471C433EF for ; Sun, 31 Oct 2021 16:25:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B43D860EE3 for ; Sun, 31 Oct 2021 16:25:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231539AbhJaQ1u (ORCPT ); Sun, 31 Oct 2021 12:27:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:26042 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230120AbhJaQ1b (ORCPT ); Sun, 31 Oct 2021 12:27:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635697499; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=43RHVcXzgVdUhw+/pZf5mkYqD1b97Ig5TszqYmG6xeA=; b=N+ZNmz4mNxIhiY5QghL4lBZBcoRiCwuRthcUmATn3IUce57xxozFXS9NXY7b9xDg8/ICte RRgEgITktsHnORqSrm8KuudDsqrwfYruPTfOkW6sKAk5XMeJ0DNekQz9ElgKRyjULImNJH L8WWcWKdEf1q95a5uimIJmKIYEhtlOE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-299-jSV6xw2DNWecYeYNoZm9ug-1; Sun, 31 Oct 2021 12:24:54 -0400 X-MC-Unique: jSV6xw2DNWecYeYNoZm9ug-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8FDF210A8E00; Sun, 31 Oct 2021 16:24:51 +0000 (UTC) Received: from x1.localdomain.com (unknown [10.39.192.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id 446AB100763D; Sun, 31 Oct 2021 16:24:48 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Mika Westerberg , Mark Gross , Andy Shevchenko , Wolfram Sang , Sebastian Reichel , MyungJoo Ham , Chanwoo Choi , Ard Biesheuvel Cc: Hans de Goede , Len Brown , linux-acpi@vger.kernel.org, Yauhen Kharuzhy , Tsuchiya Yuto , platform-driver-x86@vger.kernel.org, linux-i2c@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [RFC 5/5] power: supply: bq27xxx: Add support for ACPI enumeration Date: Sun, 31 Oct 2021 17:24:28 +0100 Message-Id: <20211031162428.22368-6-hdegoede@redhat.com> In-Reply-To: <20211031162428.22368-1-hdegoede@redhat.com> References: <20211031162428.22368-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Some x86/ACPI devices with a bq27xxx fuel-gauge do not use the standard ACPI battery API for battery monitoring. Instead they have an ACPI device describing the actual fuel-gauge IC and expect the OS to have a native driver for the fuel-gauge. Add support for such ACPI enumerated bq27xxx fuel-gauges. To get the fuel-gauge to work properly on ACPI devs 3 changes are needed: 1. Add an acpi_match_table and set di->chip based on this, note the new "if (id) check also fixes a NULL pointer deref when someone tries to manually bind the driver from sysfs. 2. When the charger IC has external power applied or removed, the psy-core should call bq27xxx_external_power_changed(). This requires a valid consumer<->supplier link between the charger and the fuel-gauge power-supplies. For ACPI enumerated fuel-gauges this link is missing. The charger-ICs used on these devices already contain a special power_supply_config.supplied_to default set to "main-battery". This commit makes use of this by setting the power-supply's name to "main-battery" when enumerated by ACPI, to establish the missing consumer<->supplier link. 3. Sometimes the irqflags in the ACPI tables are no good, override them. Signed-off-by: Hans de Goede --- drivers/power/supply/bq27xxx_battery_i2c.c | 38 ++++++++++++++++++---- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/drivers/power/supply/bq27xxx_battery_i2c.c b/drivers/power/supply/bq27xxx_battery_i2c.c index 0a1b922389e1..c3fe1e4b08bd 100644 --- a/drivers/power/supply/bq27xxx_battery_i2c.c +++ b/drivers/power/supply/bq27xxx_battery_i2c.c @@ -6,6 +6,7 @@ * Andrew F. Davis */ +#include #include #include #include @@ -139,8 +140,10 @@ static int bq27xxx_battery_i2c_bulk_write(struct bq27xxx_device_info *di, static int bq27xxx_battery_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) { + const struct acpi_device_id *acpi_id = NULL; struct device *dev = &client->dev; struct bq27xxx_device_info *di; + unsigned long irqflags = 0; int ret; char *name; int num; @@ -152,17 +155,31 @@ static int bq27xxx_battery_i2c_probe(struct i2c_client *client, if (num < 0) return num; - name = devm_kasprintf(dev, GFP_KERNEL, "%s-%d", id->name, num); - if (!name) - goto err_mem; - di = devm_kzalloc(dev, sizeof(*di), GFP_KERNEL); if (!di) goto err_mem; + if (id) { + di->chip = id->driver_data; + } else { + acpi_id = acpi_match_device(dev->driver->acpi_match_table, dev); + if (!acpi_id) + return -ENODEV; + + irqflags = IRQF_TRIGGER_RISING; + di->chip = acpi_id->driver_data; + } + + if (acpi_id && num == 0) { + name = "main-battery"; + } else { + name = devm_kasprintf(dev, GFP_KERNEL, "%s-%d", id->name, num); + if (!name) + goto err_mem; + } + di->id = num; di->dev = dev; - di->chip = id->driver_data; di->name = name; di->bus.read = bq27xxx_battery_i2c_read; @@ -182,7 +199,7 @@ static int bq27xxx_battery_i2c_probe(struct i2c_client *client, if (client->irq) { ret = devm_request_threaded_irq(dev, client->irq, NULL, bq27xxx_battery_irq_handler_thread, - IRQF_ONESHOT, + irqflags | IRQF_ONESHOT, di->name, di); if (ret) { dev_err(dev, "Unable to register IRQ %d error %d\n", @@ -292,10 +309,19 @@ static const struct of_device_id bq27xxx_battery_i2c_of_match_table[] = { MODULE_DEVICE_TABLE(of, bq27xxx_battery_i2c_of_match_table); #endif +#ifdef CONFIG_ACPI +static const struct acpi_device_id bq27xxx_acpi_match[] = { + { "TXN27520", BQ2752X }, + { } +}; +MODULE_DEVICE_TABLE(acpi, bq27xxx_acpi_match); +#endif + static struct i2c_driver bq27xxx_battery_i2c_driver = { .driver = { .name = "bq27xxx-battery", .of_match_table = of_match_ptr(bq27xxx_battery_i2c_of_match_table), + .acpi_match_table = ACPI_PTR(bq27xxx_acpi_match), }, .probe = bq27xxx_battery_i2c_probe, .remove = bq27xxx_battery_i2c_remove,