From patchwork Sat Oct 30 18:28:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 1548666 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=b7KBuAFq; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4HhSVF5x65z9sXS for ; Sun, 31 Oct 2021 05:28:37 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230348AbhJ3SbA (ORCPT ); Sat, 30 Oct 2021 14:31:00 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:56036 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230245AbhJ3Sa6 (ORCPT ); Sat, 30 Oct 2021 14:30:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635618508; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1cdF+sE/SLgTIc7hDDLi/Ba/YvIkdSSZy+iz0SwSwrw=; b=b7KBuAFq3I3dtLOuTcyNitlx+d/MsIRtSG5n6fPyJUJ8sw45BEILXtXz6Ih+kpzn6s0c9z 5LWhAAHoKdp2+4y2779q+YogiuAIm0v76CK7W1vMlUTvRDG/8jYON1FIv8LG+qvL07c/VM bWaxTeMTiA1qMH/FaRVCi+v2ecLZZ/w= 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-268-BkS4txVNN-GYa76GsBKkJQ-1; Sat, 30 Oct 2021 14:28:22 -0400 X-MC-Unique: BkS4txVNN-GYa76GsBKkJQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B5E4F362F9; Sat, 30 Oct 2021 18:28:20 +0000 (UTC) Received: from x1.localdomain (unknown [10.39.192.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id E95575F4E1; Sat, 30 Oct 2021 18:28:17 +0000 (UTC) From: Hans de Goede To: Mark Gross , Andy Shevchenko , Wolfram Sang , Sebastian Reichel , MyungJoo Ham , Chanwoo Choi , Ard Biesheuvel Cc: Hans de Goede , 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: [PATCH 01/13] platform/x86: Rename touchscreen_dmi to dmi_device_properties Date: Sat, 30 Oct 2021 20:28:01 +0200 Message-Id: <20211030182813.116672-2-hdegoede@redhat.com> In-Reply-To: <20211030182813.116672-1-hdegoede@redhat.com> References: <20211030182813.116672-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org The ability to attach device-properties to (I2C) devices based on a DMI + I2C device-name match to address the hw-description in some ACPI tables being incomplete is useful for more things then just touchscreens. Rename the Kconfig option and file to reflect this. The specific use-case triggering this change is describing the hardware surrounding the Whiskey Cove PMIC found on several Cherry Trail based devices. At least 3 configs are known: 1. The WC PMIC is connected to a TI BQ24292i charger, paired with a Maxim MAX17047 fuelgauge + a FUSB302 USB Type-C Controller + a PI3USB30532 USB switch, for a fully functional Type-C port 2. The WC PMIC is connected to a TI BQ25890 charger, paired with a TI BQ27520 fuelgauge, for a USB-2 only Type-C port without PD 3. The WC PMIC is connected to a TI BQ25890 charger, paired with a TI BQ27542 fuelgauge, for a micro-USB port And various drivers (extcon-intel-cht-wc.c, i2c-cht-wc.c, ...) need to know which config they are dealing with. Signed-off-by: Hans de Goede --- MAINTAINERS | 2 +- drivers/firmware/efi/embedded-firmware.c | 4 ++-- drivers/platform/x86/Kconfig | 20 ++++++++++--------- drivers/platform/x86/Makefile | 2 +- ...chscreen_dmi.c => dmi_device_properties.c} | 8 ++++---- include/linux/efi_embedded_fw.h | 2 +- 6 files changed, 20 insertions(+), 18 deletions(-) rename drivers/platform/x86/{touchscreen_dmi.c => dmi_device_properties.c} (99%) diff --git a/MAINTAINERS b/MAINTAINERS index 09abc1d84a7f..fe6a952c0232 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -17156,7 +17156,7 @@ L: linux-input@vger.kernel.org L: platform-driver-x86@vger.kernel.org S: Maintained F: drivers/input/touchscreen/silead.c -F: drivers/platform/x86/touchscreen_dmi.c +F: drivers/platform/x86/dmi_device_properties.c SILICON LABS WIRELESS DRIVERS (for WFxxx series) M: Jérôme Pouiller diff --git a/drivers/firmware/efi/embedded-firmware.c b/drivers/firmware/efi/embedded-firmware.c index f5be8e22305b..f8212af0ba5e 100644 --- a/drivers/firmware/efi/embedded-firmware.c +++ b/drivers/firmware/efi/embedded-firmware.c @@ -21,8 +21,8 @@ bool efi_embedded_fw_checked; EXPORT_SYMBOL_NS_GPL(efi_embedded_fw_checked, TEST_FIRMWARE); static const struct dmi_system_id * const embedded_fw_table[] = { -#ifdef CONFIG_TOUCHSCREEN_DMI - touchscreen_dmi_table, +#ifdef CONFIG_DMI_DEVICE_PROPERTIES + dmi_device_properties, #endif NULL }; diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig index b110a2e6b8f3..9cb8d33cc6e1 100644 --- a/drivers/platform/x86/Kconfig +++ b/drivers/platform/x86/Kconfig @@ -981,17 +981,19 @@ config MLX_PLATFORM If you have a Mellanox system, say Y or M here. -config TOUCHSCREEN_DMI - bool "DMI based touchscreen configuration info" - depends on ACPI && DMI && I2C=y && TOUCHSCREEN_SILEAD +config DMI_DEVICE_PROPERTIES + bool "DMI based extra device properties" + depends on ACPI && DMI && I2C=y select EFI_EMBEDDED_FIRMWARE if EFI help - Certain ACPI based tablets with e.g. Silead or Chipone touchscreens - do not have enough data in ACPI tables for the touchscreen driver to - handle the touchscreen properly, as OEMs expect the data to be baked - into the tablet model specific version of the driver shipped with the - the OS-image for the device. This option supplies the missing info. - Enable this for x86 tablets with Silead or Chipone touchscreens. + Sometimes ACPI based x86 devices do not have enough data in their ACPI + tables to fully describe the hardware. This option enables support for + supplying the missing info based on DMI (vendor & model string) + matching for devices where this info has been added to the + dmi-device-properties code. + + This option is often necessary for correct operation of x86 based + tablets and 2-in-1 devices. If in doubt, say Y here. config FW_ATTR_CLASS tristate diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile index 219478061683..3f610332b556 100644 --- a/drivers/platform/x86/Makefile +++ b/drivers/platform/x86/Makefile @@ -107,10 +107,10 @@ obj-$(CONFIG_SYSTEM76_ACPI) += system76_acpi.o obj-$(CONFIG_TOPSTAR_LAPTOP) += topstar-laptop.o # Platform drivers +obj-$(CONFIG_DMI_DEVICE_PROPERTIES) += dmi_device_properties.o obj-$(CONFIG_FW_ATTR_CLASS) += firmware_attributes_class.o obj-$(CONFIG_I2C_MULTI_INSTANTIATE) += i2c-multi-instantiate.o obj-$(CONFIG_MLX_PLATFORM) += mlx-platform.o -obj-$(CONFIG_TOUCHSCREEN_DMI) += touchscreen_dmi.o obj-$(CONFIG_WIRELESS_HOTKEY) += wireless-hotkey.o # Intel uncore drivers diff --git a/drivers/platform/x86/touchscreen_dmi.c b/drivers/platform/x86/dmi_device_properties.c similarity index 99% rename from drivers/platform/x86/touchscreen_dmi.c rename to drivers/platform/x86/dmi_device_properties.c index b5d007875423..1bcd14a0bc78 100644 --- a/drivers/platform/x86/touchscreen_dmi.c +++ b/drivers/platform/x86/dmi_device_properties.c @@ -1,8 +1,8 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* - * Touchscreen driver DMI based configuration code + * DMI based device-property addition (adding info missing from ACPI tables) * - * Copyright (c) 2017 Red Hat Inc. + * Copyright (c) 2017-2021 Red Hat Inc. * * Red Hat authors: * Hans de Goede @@ -979,7 +979,7 @@ static const struct ts_dmi_data vinga_twizzle_j116_data = { }; /* NOTE: Please keep this table sorted alphabetically */ -const struct dmi_system_id touchscreen_dmi_table[] = { +const struct dmi_system_id dmi_device_properties[] = { { /* Chuwi Hi8 */ .driver_data = (void *)&chuwi_hi8_data, @@ -1633,7 +1633,7 @@ static int __init ts_dmi_init(void) const struct dmi_system_id *dmi_id; int error; - dmi_id = dmi_first_match(touchscreen_dmi_table); + dmi_id = dmi_first_match(dmi_device_properties); if (!dmi_id) return 0; /* Not an error */ diff --git a/include/linux/efi_embedded_fw.h b/include/linux/efi_embedded_fw.h index a97a12bb2c9e..01105c38a309 100644 --- a/include/linux/efi_embedded_fw.h +++ b/include/linux/efi_embedded_fw.h @@ -34,7 +34,7 @@ struct efi_embedded_fw_desc { u8 sha256[32]; }; -extern const struct dmi_system_id touchscreen_dmi_table[]; +extern const struct dmi_system_id dmi_device_properties[]; int efi_get_embedded_fw(const char *name, const u8 **dat, size_t *sz); From patchwork Sat Oct 30 18:28:02 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: 1548667 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=gT5bK1xo; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4HhSVG17YBz9sfG for ; Sun, 31 Oct 2021 05:28:38 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231154AbhJ3SbB (ORCPT ); Sat, 30 Oct 2021 14:31:01 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:43901 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230131AbhJ3SbA (ORCPT ); Sat, 30 Oct 2021 14:31:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635618509; 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=XfAWTpqD6xHOwrNh8jWCx0PvwaLrx5zHt5cmNcz+EB4=; b=gT5bK1xoxhnJTlQ0XvieLU0azomyAtkwiY9MK0EDuhswm2gdFfY6lMeAE/T40Fz3fzyAy0 UfXCe92NCSzXtemn4wLALk/A9hdPoldQ1mMWgsC+BcbjhcK4TQKJWilkwGy7AR1s3q0uXf Mfd25SSuReKzMmu8PhPi3zgTwQhCGDQ= 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-389-0DSIdl-dOsOrGj5SanVZcw-1; Sat, 30 Oct 2021 14:28:25 -0400 X-MC-Unique: 0DSIdl-dOsOrGj5SanVZcw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CD15210055BC; Sat, 30 Oct 2021 18:28:23 +0000 (UTC) Received: from x1.localdomain (unknown [10.39.192.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 08E915F4E1; Sat, 30 Oct 2021 18:28:20 +0000 (UTC) From: Hans de Goede To: Mark Gross , Andy Shevchenko , Wolfram Sang , Sebastian Reichel , MyungJoo Ham , Chanwoo Choi , Ard Biesheuvel Cc: Hans de Goede , 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: [PATCH 02/13] platform/x86: dmi_device_properties: Add setup info for boards with a CHT Whiskey Cove PMIC Date: Sat, 30 Oct 2021 20:28:02 +0200 Message-Id: <20211030182813.116672-3-hdegoede@redhat.com> In-Reply-To: <20211030182813.116672-1-hdegoede@redhat.com> References: <20211030182813.116672-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Add a new "intel,cht-wc-setup" string property to the "INT34D3:00" i2c_client for the Whiskey Cove PMIC found on several Cherry Trail based devices. At least 3 setups are known: 1. The WC PMIC is connected to a TI BQ24292i charger, paired with a Maxim MAX17047 fuelgauge + a FUSB302 USB Type-C Controller + a PI3USB30532 USB switch, for a fully functional Type-C port 2. The WC PMIC is connected to a TI BQ25890 charger, paired with a TI BQ27520 fuelgauge, for a USB-2 only Type-C port without PD 3. The WC PMIC is connected to a TI BQ25890 charger, paired with a TI BQ27542 fuelgauge, for a micro-USB port Which setup is in use cannot be determined reliably from the ACPI tables and various drivers (extcon-intel-cht-wc.c, i2c-cht-wc.c, ...) need to know which setup they are dealing with. Signed-off-by: Hans de Goede --- drivers/platform/x86/dmi_device_properties.c | 46 ++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/drivers/platform/x86/dmi_device_properties.c b/drivers/platform/x86/dmi_device_properties.c index 1bcd14a0bc78..bd973afbde5f 100644 --- a/drivers/platform/x86/dmi_device_properties.c +++ b/drivers/platform/x86/dmi_device_properties.c @@ -387,6 +387,16 @@ static const struct ts_dmi_data gp_electronic_t701_data = { .properties = gp_electronic_t701_props, }; +static const struct property_entry gpd_win_pocket_props[] = { + PROPERTY_ENTRY_STRING("intel,cht-wc-setup", "bq24292i,max17047,fusb302,pi3usb30532"), + { } +}; + +static const struct ts_dmi_data gpd_win_pocket_data = { + .acpi_name = "INT34D3:00", + .properties = gpd_win_pocket_props, +}; + static const struct property_entry irbis_tw90_props[] = { PROPERTY_ENTRY_U32("touchscreen-size-x", 1720), PROPERTY_ENTRY_U32("touchscreen-size-y", 1138), @@ -978,6 +988,16 @@ static const struct ts_dmi_data vinga_twizzle_j116_data = { .properties = vinga_twizzle_j116_props, }; +static const struct property_entry xiaomi_mi_pad2_props[] = { + PROPERTY_ENTRY_STRING("intel,cht-wc-setup", "bq25890,bq27520"), + { } +}; + +static const struct ts_dmi_data xiaomi_mi_pad2_data = { + .acpi_name = "INT34D3:00", + .properties = xiaomi_mi_pad2_props, +}; + /* NOTE: Please keep this table sorted alphabetically */ const struct dmi_system_id dmi_device_properties[] = { { @@ -1166,6 +1186,24 @@ const struct dmi_system_id dmi_device_properties[] = { DMI_MATCH(DMI_BIOS_VERSION, "itWORKS.G.WI71C.JGBMRB"), }, }, + { + /* GPD win / GPD pocket mini laptops */ + .driver_data = (void *)&gpd_win_pocket_data, + /* + * Note this may not seem like a very unique match, but in the + * 24000+ DMI decode dumps from linux-hardware.org only 42 have + * a board_vendor value of "AMI Corporation" and of those 42 + * only 1 (the GPD win/pocket entry) has a board_name of + * "Default string". Also few devices have both board_ and + * product_name not set. + */ + .matches = { + DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"), + DMI_MATCH(DMI_BOARD_NAME, "Default string"), + DMI_MATCH(DMI_BOARD_SERIAL, "Default string"), + DMI_MATCH(DMI_PRODUCT_NAME, "Default string"), + }, + }, { /* Irbis TW90 */ .driver_data = (void *)&irbis_tw90_data, @@ -1578,6 +1616,14 @@ const struct dmi_system_id dmi_device_properties[] = { DMI_MATCH(DMI_PRODUCT_NAME, "TW700") }, }, + { + /* Xiaomi Mi Pad 2 */ + .driver_data = (void *)&xiaomi_mi_pad2_data, + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Xiaomi Inc"), + DMI_MATCH(DMI_PRODUCT_NAME, "Mipad2"), + }, + }, { /* Yours Y8W81, same case and touchscreen as Chuwi Vi8 */ .driver_data = (void *)&chuwi_vi8_data, From patchwork Sat Oct 30 18:28:03 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: 1548668 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=iSpbm5yv; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4HhSVR5dxKz9sXS for ; Sun, 31 Oct 2021 05:28:47 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231958AbhJ3SbI (ORCPT ); Sat, 30 Oct 2021 14:31:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:40507 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231485AbhJ3SbF (ORCPT ); Sat, 30 Oct 2021 14:31:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635618514; 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=vrrTuUxsrl1Oeg8B72TGUw5tNWzGAIZr3rniIiQjl/A=; b=iSpbm5yvUop7oJ/wniGze0fDflyvte08rOMtZ3eKilMHiH0M9+tF8JD0trex7jKZM0NmXn 98rslmH12aBxWv2RTlXiJc4SYQanG27BpYqoQq+52n3PXYYEc0Eqj5rJE451ZOATXIwAZU LuXn4zJEq7AYEgBahJeuowRPHw1Q6kg= 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-562-xUbbNizWM3WwSodiMeAfNA-1; Sat, 30 Oct 2021 14:28:29 -0400 X-MC-Unique: xUbbNizWM3WwSodiMeAfNA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E226D806689; Sat, 30 Oct 2021 18:28:26 +0000 (UTC) Received: from x1.localdomain (unknown [10.39.192.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 207DF5F4E1; Sat, 30 Oct 2021 18:28:23 +0000 (UTC) From: Hans de Goede To: Mark Gross , Andy Shevchenko , Wolfram Sang , Sebastian Reichel , MyungJoo Ham , Chanwoo Choi , Ard Biesheuvel Cc: Hans de Goede , 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: [PATCH 03/13] power: supply: bq25890: Fix race causing oops at boot Date: Sat, 30 Oct 2021 20:28:03 +0200 Message-Id: <20211030182813.116672-4-hdegoede@redhat.com> In-Reply-To: <20211030182813.116672-1-hdegoede@redhat.com> References: <20211030182813.116672-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Before this commit the driver was registering its interrupt handler before it registered the power_supply, causing bq->charger to potentially be NULL when the interrupt handler runs, triggering a NULL pointer exception in the interrupt handler: [ 21.213531] BUG: kernel NULL pointer dereference, address: 0000000000000680 ... [ 21.213573] Hardware name: Xiaomi Inc Mipad2/Mipad, BIOS MIPad-P4.X64.0043.R03.1603071414 03/07/2016 [ 21.213576] RIP: 0010:__lock_acquire+0x5c5/0x1de0 ... [ 21.213629] Call Trace: [ 21.213636] ? disable_irq_nosync+0x10/0x10 [ 21.213644] ? __mutex_unlock_slowpath+0x35/0x260 [ 21.213655] lock_acquire+0xb5/0x2b0 [ 21.213661] ? power_supply_changed+0x23/0x90 [ 21.213670] ? disable_irq_nosync+0x10/0x10 [ 21.213676] _raw_spin_lock_irqsave+0x48/0x60 [ 21.213682] ? power_supply_changed+0x23/0x90 [ 21.213687] power_supply_changed+0x23/0x90 [ 21.213697] __bq25890_handle_irq+0x5e/0xe0 [bq25890_charger] [ 21.213709] bq25890_irq_handler_thread+0x26/0x40 [bq25890_charger] [ 21.213718] irq_thread_fn+0x20/0x60 ... Fix this by moving the power_supply_register() call to above the request_threaded_irq() call. Note this fix includes making the following 2 (necessary) changes: 1. Switch to the devm version of power_supply_register() to avoid the need to make the error-handling in probe() more complicated. 2. Rename the "irq_fail" label to "err_unregister_usb_notifier" since the old name no longer makes sense after this fix. Signed-off-by: Hans de Goede --- drivers/power/supply/bq25890_charger.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index 945c3257ca93..491d36a3811a 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -734,8 +734,9 @@ static int bq25890_power_supply_init(struct bq25890_device *bq) psy_cfg.supplied_to = bq25890_charger_supplied_to; psy_cfg.num_supplicants = ARRAY_SIZE(bq25890_charger_supplied_to); - bq->charger = power_supply_register(bq->dev, &bq25890_power_supply_desc, - &psy_cfg); + bq->charger = devm_power_supply_register(bq->dev, + &bq25890_power_supply_desc, + &psy_cfg); return PTR_ERR_OR_ZERO(bq->charger); } @@ -985,22 +986,22 @@ static int bq25890_probe(struct i2c_client *client, usb_register_notifier(bq->usb_phy, &bq->usb_nb); } + ret = bq25890_power_supply_init(bq); + if (ret < 0) { + dev_err(dev, "Failed to register power supply\n"); + goto err_unregister_usb_notifier; + } + ret = devm_request_threaded_irq(dev, client->irq, NULL, bq25890_irq_handler_thread, IRQF_TRIGGER_FALLING | IRQF_ONESHOT, BQ25890_IRQ_PIN, bq); if (ret) - goto irq_fail; - - ret = bq25890_power_supply_init(bq); - if (ret < 0) { - dev_err(dev, "Failed to register power supply\n"); - goto irq_fail; - } + goto err_unregister_usb_notifier; return 0; -irq_fail: +err_unregister_usb_notifier: if (!IS_ERR_OR_NULL(bq->usb_phy)) usb_unregister_notifier(bq->usb_phy, &bq->usb_nb); @@ -1011,8 +1012,6 @@ static int bq25890_remove(struct i2c_client *client) { struct bq25890_device *bq = i2c_get_clientdata(client); - power_supply_unregister(bq->charger); - if (!IS_ERR_OR_NULL(bq->usb_phy)) usb_unregister_notifier(bq->usb_phy, &bq->usb_nb); From patchwork Sat Oct 30 18:28:04 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: 1548670 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=TSMvjqMz; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4HhSVS4f0vz9sXS for ; Sun, 31 Oct 2021 05:28:48 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231489AbhJ3SbR (ORCPT ); Sat, 30 Oct 2021 14:31:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:35766 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230512AbhJ3SbI (ORCPT ); Sat, 30 Oct 2021 14:31:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635618517; 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=n3Mgk88GftykavhRfevxmb2OnrvVoUttarFCvaInBLI=; b=TSMvjqMzpnVWzpYZuM0tuVw06wOYsN/1DmrNYrTWsWO8h34JYwRf7OP7fY8s1f6UBQrpiw rRchDiE+u3u4tUgovGE35wJ6P3essRV8Vi6CbKqdS63CWMxU8/rWwhLfd0ZQBnWhKVxGAV NXKPJR9oCM3JOttzrwwtbeIK/ETBy/w= 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-111-rdJLY_KoMXKy1ItcgdzG4w-1; Sat, 30 Oct 2021 14:28:32 -0400 X-MC-Unique: rdJLY_KoMXKy1ItcgdzG4w-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F1D248018AC; Sat, 30 Oct 2021 18:28:29 +0000 (UTC) Received: from x1.localdomain (unknown [10.39.192.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3419C5F4E1; Sat, 30 Oct 2021 18:28:27 +0000 (UTC) From: Hans de Goede To: Mark Gross , Andy Shevchenko , Wolfram Sang , Sebastian Reichel , MyungJoo Ham , Chanwoo Choi , Ard Biesheuvel Cc: Hans de Goede , 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: [PATCH 04/13] power: supply: bq25890: Fix initial setting of the F_CONV_RATE field Date: Sat, 30 Oct 2021 20:28:04 +0200 Message-Id: <20211030182813.116672-5-hdegoede@redhat.com> In-Reply-To: <20211030182813.116672-1-hdegoede@redhat.com> References: <20211030182813.116672-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org The code doing the initial setting of the F_CONV_RATE field based on the bq->state.online flag. In order for this to work properly, this must be done after the initial bq25890_get_chip_state() call. Signed-off-by: Hans de Goede --- drivers/power/supply/bq25890_charger.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index 491d36a3811a..99497fdc73da 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -682,16 +682,16 @@ static int bq25890_hw_init(struct bq25890_device *bq) } } - /* Configure ADC for continuous conversions when charging */ - ret = bq25890_field_write(bq, F_CONV_RATE, !!bq->state.online); + ret = bq25890_get_chip_state(bq, &bq->state); if (ret < 0) { - dev_dbg(bq->dev, "Config ADC failed %d\n", ret); + dev_dbg(bq->dev, "Get state failed %d\n", ret); return ret; } - ret = bq25890_get_chip_state(bq, &bq->state); + /* Configure ADC for continuous conversions when charging */ + ret = bq25890_field_write(bq, F_CONV_RATE, !!bq->state.online); if (ret < 0) { - dev_dbg(bq->dev, "Get state failed %d\n", ret); + dev_dbg(bq->dev, "Config ADC failed %d\n", ret); return ret; } From patchwork Sat Oct 30 18:28:05 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: 1548669 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=NVW0FtNa; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4HhSVS2KLcz9sfG for ; Sun, 31 Oct 2021 05:28:48 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231494AbhJ3SbN (ORCPT ); Sat, 30 Oct 2021 14:31:13 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:34001 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231902AbhJ3SbH (ORCPT ); Sat, 30 Oct 2021 14:31:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635618516; 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=r/bwpmZmTbHIA25Myaaf6s8nqlYCgZP1Wt0Gvd6AEOk=; b=NVW0FtNarZeHf1eEKkFCJp1nK/YYiHV75LKwVouxffwYXjFlzMitIeXEgL/8lBDqD7ZT36 sBAzWqKeRjXLfhtn65obVL1gcPFNHHcfJKKlNmWdA7XSLyoWirbRNMvQi643RT+YNuByss 0k5ALVmUPrPiYKPq7r2M+f2hmLgWk8U= 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-88-P_c01b4SMKGKPemjRXYHiA-1; Sat, 30 Oct 2021 14:28:35 -0400 X-MC-Unique: P_c01b4SMKGKPemjRXYHiA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0E205104ECE6; Sat, 30 Oct 2021 18:28:33 +0000 (UTC) Received: from x1.localdomain (unknown [10.39.192.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 44F235F4E9; Sat, 30 Oct 2021 18:28:30 +0000 (UTC) From: Hans de Goede To: Mark Gross , Andy Shevchenko , Wolfram Sang , Sebastian Reichel , MyungJoo Ham , Chanwoo Choi , Ard Biesheuvel Cc: Hans de Goede , 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: [PATCH 05/13] power: supply: bq25890: Add a bq25890_rw_init_data() helper Date: Sat, 30 Oct 2021 20:28:05 +0200 Message-Id: <20211030182813.116672-6-hdegoede@redhat.com> In-Reply-To: <20211030182813.116672-1-hdegoede@redhat.com> References: <20211030182813.116672-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org On most X86/ACPI devices there is no devicetree to supply the necessary init-data. Instead the firmware already fully initializes the bq25890 charger at boot. Factor out the current code to write all the init_data from devicetree into a new bq25890_rw_init_data() helper which can both write the data to the charger (the current behavior) as well as read it back from the charger into the init_data struct. This is a preparation patch for adding support for X86/ACPI device's where the init_data must be read back from the bq25890 charger. Signed-off-by: Hans de Goede --- drivers/power/supply/bq25890_charger.c | 62 +++++++++++++++++--------- 1 file changed, 40 insertions(+), 22 deletions(-) diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index 99497fdc73da..1ec93a565631 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -636,29 +636,52 @@ static int bq25890_chip_reset(struct bq25890_device *bq) return 0; } -static int bq25890_hw_init(struct bq25890_device *bq) +static int bq25890_rw_init_data(struct bq25890_device *bq) { + bool write = true; int ret; int i; const struct { enum bq25890_fields id; - u32 value; + u8 *value; } init_data[] = { - {F_ICHG, bq->init_data.ichg}, - {F_VREG, bq->init_data.vreg}, - {F_ITERM, bq->init_data.iterm}, - {F_IPRECHG, bq->init_data.iprechg}, - {F_SYSVMIN, bq->init_data.sysvmin}, - {F_BOOSTV, bq->init_data.boostv}, - {F_BOOSTI, bq->init_data.boosti}, - {F_BOOSTF, bq->init_data.boostf}, - {F_EN_ILIM, bq->init_data.ilim_en}, - {F_TREG, bq->init_data.treg}, - {F_BATCMP, bq->init_data.rbatcomp}, - {F_VCLAMP, bq->init_data.vclamp}, + {F_ICHG, &bq->init_data.ichg}, + {F_VREG, &bq->init_data.vreg}, + {F_ITERM, &bq->init_data.iterm}, + {F_IPRECHG, &bq->init_data.iprechg}, + {F_SYSVMIN, &bq->init_data.sysvmin}, + {F_BOOSTV, &bq->init_data.boostv}, + {F_BOOSTI, &bq->init_data.boosti}, + {F_BOOSTF, &bq->init_data.boostf}, + {F_EN_ILIM, &bq->init_data.ilim_en}, + {F_TREG, &bq->init_data.treg}, + {F_BATCMP, &bq->init_data.rbatcomp}, + {F_VCLAMP, &bq->init_data.vclamp}, }; + for (i = 0; i < ARRAY_SIZE(init_data); i++) { + if (write) { + ret = bq25890_field_write(bq, init_data[i].id, + *init_data[i].value); + } else { + ret = bq25890_field_read(bq, init_data[i].id); + if (ret >= 0) + *init_data[i].value = ret; + } + if (ret < 0) { + dev_dbg(bq->dev, "Accessing init data failed %d\n", ret); + return ret; + } + } + + return 0; +} + +static int bq25890_hw_init(struct bq25890_device *bq) +{ + int ret; + ret = bq25890_chip_reset(bq); if (ret < 0) { dev_dbg(bq->dev, "Reset failed %d\n", ret); @@ -673,14 +696,9 @@ static int bq25890_hw_init(struct bq25890_device *bq) } /* initialize currents/voltages and other parameters */ - for (i = 0; i < ARRAY_SIZE(init_data); i++) { - ret = bq25890_field_write(bq, init_data[i].id, - init_data[i].value); - if (ret < 0) { - dev_dbg(bq->dev, "Writing init data failed %d\n", ret); - return ret; - } - } + ret = bq25890_rw_init_data(bq); + if (ret) + return ret; ret = bq25890_get_chip_state(bq, &bq->state); if (ret < 0) { From patchwork Sat Oct 30 18:28:06 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: 1548671 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=bjA4gsM2; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4HhSVT3Lblz9sXS for ; Sun, 31 Oct 2021 05:28:49 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231475AbhJ3SbS (ORCPT ); Sat, 30 Oct 2021 14:31:18 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:32336 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232035AbhJ3SbM (ORCPT ); Sat, 30 Oct 2021 14:31:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635618521; 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=v+AVB+iQtmAvSP/G/6vABVHFG7BeK3k8Ncl4QBHM/dc=; b=bjA4gsM2HXcR674pkSI5MDHD/sovuLOHCqLdZ3Z2jA3tgRs2d7rWJB5BcWyxgdd6MXAA00 76xpaXeui4uA9rHwXDEfZ2SHfH+N+FgSw5jOjuPD8D7CIbx2vg5trL6AobyaLJQ83cbD88 KhCxK3CnW6uMfS4+omgC4x5z2LLfUJU= 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-271-OGzIgCvkO62ic-hRyno7HQ-1; Sat, 30 Oct 2021 14:28:38 -0400 X-MC-Unique: OGzIgCvkO62ic-hRyno7HQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1ED1B1808317; Sat, 30 Oct 2021 18:28:36 +0000 (UTC) Received: from x1.localdomain (unknown [10.39.192.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5736B5F4E1; Sat, 30 Oct 2021 18:28:33 +0000 (UTC) From: Hans de Goede To: Mark Gross , Andy Shevchenko , Wolfram Sang , Sebastian Reichel , MyungJoo Ham , Chanwoo Choi , Ard Biesheuvel Cc: Hans de Goede , 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: [PATCH 06/13] power: supply: bq25890: Add support for skipping initialization Date: Sat, 30 Oct 2021 20:28:06 +0200 Message-Id: <20211030182813.116672-7-hdegoede@redhat.com> In-Reply-To: <20211030182813.116672-1-hdegoede@redhat.com> References: <20211030182813.116672-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org On most X86/ACPI devices there is no devicetree to supply the necessary init-data. Instead the firmware already fully initializes the bq25890 charger at boot. At support for a new "ti,skip-init" boolean property to support this. So far this new property is only used on X86/ACPI (non devicetree) devs, IOW it is not used in actual devicetree files. The devicetree-bindings maintainers have requested properties like these to not be added to the devicetree-bindings, so the new property is deliberately not added to the existing devicetree-bindings. Signed-off-by: Hans de Goede --- drivers/power/supply/bq25890_charger.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index 1ec93a565631..280821a6a6c6 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -73,6 +73,7 @@ enum bq25890_fields { /* initial field values, converted to register values */ struct bq25890_init_data { + u8 write_cfg; /* write firmware cfg to chip? */ u8 ichg; /* charge current */ u8 vreg; /* regulation voltage */ u8 iterm; /* termination current */ @@ -638,7 +639,7 @@ static int bq25890_chip_reset(struct bq25890_device *bq) static int bq25890_rw_init_data(struct bq25890_device *bq) { - bool write = true; + bool write = bq->init_data.write_cfg; int ret; int i; @@ -682,10 +683,12 @@ static int bq25890_hw_init(struct bq25890_device *bq) { int ret; - ret = bq25890_chip_reset(bq); - if (ret < 0) { - dev_dbg(bq->dev, "Reset failed %d\n", ret); - return ret; + if (bq->init_data.write_cfg) { + ret = bq25890_chip_reset(bq); + if (ret < 0) { + dev_dbg(bq->dev, "Reset failed %d\n", ret); + return ret; + } } /* disable watchdog */ @@ -920,6 +923,10 @@ static int bq25890_fw_probe(struct bq25890_device *bq) int ret; struct bq25890_init_data *init = &bq->init_data; + init->write_cfg = !device_property_read_bool(bq->dev, "ti,skip-init"); + if (!init->write_cfg) + return 0; + ret = bq25890_fw_read_u32_props(bq); if (ret < 0) return ret; @@ -1033,8 +1040,10 @@ static int bq25890_remove(struct i2c_client *client) if (!IS_ERR_OR_NULL(bq->usb_phy)) usb_unregister_notifier(bq->usb_phy, &bq->usb_nb); - /* reset all registers to default values */ - bq25890_chip_reset(bq); + if (bq->init_data.write_cfg) { + /* reset all registers to default values */ + bq25890_chip_reset(bq); + } return 0; } From patchwork Sat Oct 30 18:28:07 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: 1548672 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=dKZmmpDf; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4HhSVT72l5z9sfG for ; Sun, 31 Oct 2021 05:28:49 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231985AbhJ3SbT (ORCPT ); Sat, 30 Oct 2021 14:31:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:52168 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232068AbhJ3SbP (ORCPT ); Sat, 30 Oct 2021 14:31:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635618524; 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=Y+Dng0wkC1+F0UUNHu8qdIK3Gm5IP43FdCxwyGpAGOg=; b=dKZmmpDfuRkMLKiGJ/VXoU/AaQKcbSdeQ4xjzHqJdvfhqyxElCrUuIKgPY7jlgrUTzRDXO AE2a9Z8DR4gNuBeHaNEICxuKsbRpSCB1fmzLUtdu0H+y6Apekgx1Pn4SL4wgA77KtWROV1 ABaVxK6/gStlmOjs96P0DxIYkKiYgXA= 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-279-inHHBM-PPKCA76gMm2xtcA-1; Sat, 30 Oct 2021 14:28:41 -0400 X-MC-Unique: inHHBM-PPKCA76gMm2xtcA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2C3E98018AC; Sat, 30 Oct 2021 18:28:39 +0000 (UTC) Received: from x1.localdomain (unknown [10.39.192.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 644605F4E1; Sat, 30 Oct 2021 18:28:36 +0000 (UTC) From: Hans de Goede To: Mark Gross , Andy Shevchenko , Wolfram Sang , Sebastian Reichel , MyungJoo Ham , Chanwoo Choi , Ard Biesheuvel Cc: Hans de Goede , 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: [PATCH 07/13] power: supply: bq25890: Enable charging on boards where we skip reset Date: Sat, 30 Oct 2021 20:28:07 +0200 Message-Id: <20211030182813.116672-8-hdegoede@redhat.com> In-Reply-To: <20211030182813.116672-1-hdegoede@redhat.com> References: <20211030182813.116672-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org On boards where the "ti,skip-init" boolean property is set we don't reset the charger; and on some boards where the fw takes care of initalizition F_CHG_CFG is set to 0 before handing control over to the OS. Explicitly set F_CHG_CFG to 1 on boards where we don't reset the charger, so that charging is always enabled on these boards, like it is always enabled on boards where we do reset the charger. Signed-off-by: Hans de Goede --- drivers/power/supply/bq25890_charger.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index 280821a6a6c6..aa4d04d20cdc 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -689,6 +689,17 @@ static int bq25890_hw_init(struct bq25890_device *bq) dev_dbg(bq->dev, "Reset failed %d\n", ret); return ret; } + } else { + /* + * Ensure charging is enabled, on some boards where the fw + * takes care of initalizition F_CHG_CFG is set to 0 before + * handing control over to the OS. + */ + ret = bq25890_field_write(bq, F_CHG_CFG, 1); + if (ret < 0) { + dev_dbg(bq->dev, "Enabling charging failed %d\n", ret); + return ret; + } } /* disable watchdog */ From patchwork Sat Oct 30 18:28:08 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: 1548673 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=jGN7UUyU; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4HhSVX5WR8z9sXS for ; Sun, 31 Oct 2021 05:28:52 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232025AbhJ3SbU (ORCPT ); Sat, 30 Oct 2021 14:31:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:49870 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231731AbhJ3SbS (ORCPT ); Sat, 30 Oct 2021 14:31:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635618528; 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=5I5u7rZgS0hlNCSBlHnDbyo/0DfFLenVV2CPz8MtkPA=; b=jGN7UUyUbh2YstNcAFaz1xV5grPqG976SetSWPyNImA/rrTKcXEQ4r0ia1pDmND8t35OTT OPR5is06mrnrUPZdschNa+fKiffcYSdbsAdO7Bx+TDbm6TZSiy9jeSqQSUa6tjyxgQxvGh BUXNhhiwDdxslQkzWz6eMWohHp9kqDo= 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-515-PsKouzDrOPGf4HO5oaye5Q-1; Sat, 30 Oct 2021 14:28:44 -0400 X-MC-Unique: PsKouzDrOPGf4HO5oaye5Q-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4284810066F3; Sat, 30 Oct 2021 18:28:42 +0000 (UTC) Received: from x1.localdomain (unknown [10.39.192.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 724FF5F4E1; Sat, 30 Oct 2021 18:28:39 +0000 (UTC) From: Hans de Goede To: Mark Gross , Andy Shevchenko , Wolfram Sang , Sebastian Reichel , MyungJoo Ham , Chanwoo Choi , Ard Biesheuvel Cc: Hans de Goede , 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: [PATCH 08/13] power: supply: bq25890: Drop dev->platform_data == NULL check Date: Sat, 30 Oct 2021 20:28:08 +0200 Message-Id: <20211030182813.116672-9-hdegoede@redhat.com> In-Reply-To: <20211030182813.116672-1-hdegoede@redhat.com> References: <20211030182813.116672-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Drop the "if (!dev->platform_data)" check, this seems to be an attempt for allowing loading the driver on devices without devicetree stemming from the initial commit of the driver (with the presumed intention being the "return -ENODEV" else branch getting replaced with something else). With the new "ti,skip-init" property the driver can actually supports devices without devicetree and this check no longer makes sense. Signed-off-by: Hans de Goede --- drivers/power/supply/bq25890_charger.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index aa4d04d20cdc..163ca5d761aa 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -990,14 +990,10 @@ static int bq25890_probe(struct i2c_client *client, return ret; } - if (!dev->platform_data) { - ret = bq25890_fw_probe(bq); - if (ret < 0) { - dev_err(dev, "Cannot read device properties.\n"); - return ret; - } - } else { - return -ENODEV; + ret = bq25890_fw_probe(bq); + if (ret < 0) { + dev_err(dev, "Cannot read device properties.\n"); + return ret; } ret = bq25890_hw_init(bq); From patchwork Sat Oct 30 18:28:09 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: 1548674 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ZrgvTVIR; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4HhSVm65Gwz9sXS for ; Sun, 31 Oct 2021 05:29:04 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232173AbhJ3Sbc (ORCPT ); Sat, 30 Oct 2021 14:31:32 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:30312 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232077AbhJ3SbW (ORCPT ); Sat, 30 Oct 2021 14:31:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635618530; 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=/bfr/J+hsxQ0Z01UTG2JJSH9Wj47Az2V8snWyLCXfIg=; b=ZrgvTVIRap9Ga8nqI011dodvQADRHGmCz7qmw10KBuSfDrE2xK9UEGrp16CulpwF55y7hX wlBZ1kVxJN4ziaAzt9uDCx0atm235lVN80Xn5qlAmWG5VBLa4G0FhuIUmYFPgkY0/9vsZx wuN3rN9/tj5YDg9bVM8x/n8oEOxXJ9E= 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-506--IRfLJ7hO1a66JEzzKlLJg-1; Sat, 30 Oct 2021 14:28:47 -0400 X-MC-Unique: -IRfLJ7hO1a66JEzzKlLJg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 579D710A8E07; Sat, 30 Oct 2021 18:28:45 +0000 (UTC) Received: from x1.localdomain (unknown [10.39.192.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 896A55F4E1; Sat, 30 Oct 2021 18:28:42 +0000 (UTC) From: Hans de Goede To: Mark Gross , Andy Shevchenko , Wolfram Sang , Sebastian Reichel , MyungJoo Ham , Chanwoo Choi , Ard Biesheuvel Cc: Hans de Goede , 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: [PATCH 09/13] power: supply: bq25890: Add bq25890_set_otg_cfg() helper Date: Sat, 30 Oct 2021 20:28:09 +0200 Message-Id: <20211030182813.116672-10-hdegoede@redhat.com> In-Reply-To: <20211030182813.116672-1-hdegoede@redhat.com> References: <20211030182813.116672-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Add a bq25890_set_otg_cfg() helper function, this is a preparation patch for adding regulator support. Signed-off-by: Hans de Goede --- drivers/power/supply/bq25890_charger.c | 28 ++++++++++++++------------ 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index 163ca5d761aa..7504e30f1e4d 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -773,6 +773,17 @@ static int bq25890_power_supply_init(struct bq25890_device *bq) return PTR_ERR_OR_ZERO(bq->charger); } +static int bq25890_set_otg_cfg(struct bq25890_device *bq, u8 val) +{ + int ret; + + ret = bq25890_field_write(bq, F_OTG_CFG, val); + if (ret < 0) + dev_err(bq->dev, "Error switching to boost/charger mode: %d\n", ret); + + return ret; +} + static void bq25890_usb_work(struct work_struct *data) { int ret; @@ -782,25 +793,16 @@ static void bq25890_usb_work(struct work_struct *data) switch (bq->usb_event) { case USB_EVENT_ID: /* Enable boost mode */ - ret = bq25890_field_write(bq, F_OTG_CFG, 1); - if (ret < 0) - goto error; + bq25890_set_otg_cfg(bq, 1); break; case USB_EVENT_NONE: /* Disable boost mode */ - ret = bq25890_field_write(bq, F_OTG_CFG, 0); - if (ret < 0) - goto error; - - power_supply_changed(bq->charger); + ret = bq25890_set_otg_cfg(bq, 0); + if (ret == 0) + power_supply_changed(bq->charger); break; } - - return; - -error: - dev_err(bq->dev, "Error switching to boost/charger mode.\n"); } static int bq25890_usb_notifier(struct notifier_block *nb, unsigned long val, From patchwork Sat Oct 30 18:28:10 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: 1548675 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=IRwfvNsr; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4HhSVz4LKmz9sXS for ; Sun, 31 Oct 2021 05:29:15 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232048AbhJ3Sbo (ORCPT ); Sat, 30 Oct 2021 14:31:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:47118 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232138AbhJ3Sb0 (ORCPT ); Sat, 30 Oct 2021 14:31:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635618535; 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=t8ehFW74+rnLZNypt0ZkCrhURw1z4RaFbmbqdkI9heM=; b=IRwfvNsriINm8UlhmMH5Jh58qFTK/EK5uofyPY5J7WGSQ4CPPHtuW5zAb6WF+i8YFa2acA W2bNr68NSqR7ggEcZgvcJ69tSCmuelaG9TXJv1icDDaltR4oLB4mjTICEOn6WgZYP1SmRs 0L0w8HLqDRr9WBJxWWvmOWMaKHGeZo4= 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-242-zGGXNK6_ODuxC9CQaVJyeQ-1; Sat, 30 Oct 2021 14:28:50 -0400 X-MC-Unique: zGGXNK6_ODuxC9CQaVJyeQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 704CA1006AA2; Sat, 30 Oct 2021 18:28:48 +0000 (UTC) Received: from x1.localdomain (unknown [10.39.192.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9E9CD5F4E1; Sat, 30 Oct 2021 18:28:45 +0000 (UTC) From: Hans de Goede To: Mark Gross , Andy Shevchenko , Wolfram Sang , Sebastian Reichel , MyungJoo Ham , Chanwoo Choi , Ard Biesheuvel Cc: Hans de Goede , 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: [PATCH 10/13] power: supply: bq25890: Add support for registering the Vbus boost converter as a regulator Date: Sat, 30 Oct 2021 20:28:10 +0200 Message-Id: <20211030182813.116672-11-hdegoede@redhat.com> In-Reply-To: <20211030182813.116672-1-hdegoede@redhat.com> References: <20211030182813.116672-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org The bq25890_charger code supports enabling/disabling the boost converter based on usb-phy notifications. But the usb-phy framework is not used on all boards/platforms. At support for registering the Vbus boost converter as a standard regulator when there is no usb-phy on the board. Also add support for providing regulator_init_data through platform_data for use on boards where device-tree is not used and the platform code must thus provide the regulator_init_data. Signed-off-by: Hans de Goede --- drivers/power/supply/bq25890_charger.c | 56 ++++++++++++++++++++++++++ include/linux/power/bq25890_charger.h | 15 +++++++ 2 files changed, 71 insertions(+) create mode 100644 include/linux/power/bq25890_charger.h diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index 7504e30f1e4d..eaadb7a82c67 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -8,7 +8,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -817,6 +819,45 @@ static int bq25890_usb_notifier(struct notifier_block *nb, unsigned long val, return NOTIFY_OK; } +#ifdef CONFIG_REGULATOR +static int bq25890_vbus_enable(struct regulator_dev *rdev) +{ + struct bq25890_device *bq = rdev_get_drvdata(rdev); + + return bq25890_set_otg_cfg(bq, 1); +} + +static int bq25890_vbus_disable(struct regulator_dev *rdev) +{ + struct bq25890_device *bq = rdev_get_drvdata(rdev); + + return bq25890_set_otg_cfg(bq, 0); +} + +static int bq25890_vbus_is_enabled(struct regulator_dev *rdev) +{ + struct bq25890_device *bq = rdev_get_drvdata(rdev); + + return bq25890_field_read(bq, F_OTG_CFG); +} + +static const struct regulator_ops bq25890_vbus_ops = { + .enable = bq25890_vbus_enable, + .disable = bq25890_vbus_disable, + .is_enabled = bq25890_vbus_is_enabled, +}; + +static const struct regulator_desc bq25890_vbus_desc = { + .name = "usb_otg_vbus", + .of_match = "usb-otg-vbus", + .type = REGULATOR_VOLTAGE, + .owner = THIS_MODULE, + .ops = &bq25890_vbus_ops, + .fixed_uV = 5000000, + .n_voltages = 1, +}; +#endif + static int bq25890_get_chip_version(struct bq25890_device *bq) { int id, rev; @@ -1018,6 +1059,21 @@ static int bq25890_probe(struct i2c_client *client, INIT_WORK(&bq->usb_work, bq25890_usb_work); bq->usb_nb.notifier_call = bq25890_usb_notifier; usb_register_notifier(bq->usb_phy, &bq->usb_nb); +#ifdef CONFIG_REGULATOR + } else { + struct bq25890_platform_data *pdata = dev_get_platdata(dev); + struct regulator_config cfg = { }; + struct regulator_dev *reg; + + cfg.dev = dev; + cfg.driver_data = bq; + if (pdata) + cfg.init_data = pdata->regulator_init_data; + + reg = devm_regulator_register(dev, &bq25890_vbus_desc, &cfg); + if (IS_ERR(reg)) + return dev_err_probe(dev, PTR_ERR(reg), "registering regulator"); +#endif } ret = bq25890_power_supply_init(bq); diff --git a/include/linux/power/bq25890_charger.h b/include/linux/power/bq25890_charger.h new file mode 100644 index 000000000000..8a36c0d787c7 --- /dev/null +++ b/include/linux/power/bq25890_charger.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Platform data for the TI bq25890 battery charger driver. + */ + +#ifndef _BQ25890_CHARGER_H_ +#define _BQ25890_CHARGER_H_ + +#include + +struct bq25890_platform_data { + const struct regulator_init_data *regulator_init_data; +}; + +#endif From patchwork Sat Oct 30 18:28:11 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: 1548676 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=RV14bmf9; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4HhSW14rtKz9sXS for ; Sun, 31 Oct 2021 05:29:17 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232223AbhJ3Sbq (ORCPT ); Sat, 30 Oct 2021 14:31:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:47401 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232149AbhJ3Sb2 (ORCPT ); Sat, 30 Oct 2021 14:31:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635618537; 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=EUspNMepzsV3gt9zAr51OvvfE1pc4mjqmhHE949y10A=; b=RV14bmf9MJp//z1Tkl25W9dFKbN5Oi2UQA3Vhei8pXiEkfZCTcIMtljjiETf1ijmWAUEGB ew9JcR2aJkwO0RR1FJRe8JgbwKqVhmiPv+2UqLDChfrZlvpfnPpyjXIiXoHaiQ0ioaODuK 3hCb50p+wsztwHZzx0Cm3HU3xMnpXdM= 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-209-bnG8VKYiNyujiy2At0-kPA-1; Sat, 30 Oct 2021 14:28:53 -0400 X-MC-Unique: bnG8VKYiNyujiy2At0-kPA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9B5048018AC; Sat, 30 Oct 2021 18:28:51 +0000 (UTC) Received: from x1.localdomain (unknown [10.39.192.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id B83845F4E1; Sat, 30 Oct 2021 18:28:48 +0000 (UTC) From: Hans de Goede To: Mark Gross , Andy Shevchenko , Wolfram Sang , Sebastian Reichel , MyungJoo Ham , Chanwoo Choi , Ard Biesheuvel Cc: Hans de Goede , 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: [PATCH 11/13] i2c: cht-wc: Add support for devices using a bq25890 charger Date: Sat, 30 Oct 2021 20:28:11 +0200 Message-Id: <20211030182813.116672-12-hdegoede@redhat.com> In-Reply-To: <20211030182813.116672-1-hdegoede@redhat.com> References: <20211030182813.116672-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org The i2c-controller on the Cherry Trail - Whiskey Cove PMIC is special in that it is always connected to the I2C charger IC of the board on which the PMIC is used; and the charger IC is not described in ACPI, so the i2c-cht-wc code needs to instantiate an i2c-client for it itself. So far there has been a rudimentary check to make sure the ACPI tables are at least somewhat as expected by checking for the presence of an INT33FE device and sofar the code has assumed that if this INT33FE device is present that the used charger then is a bq24290i. But some boards with an INT33FE device in their ACPI tables use a different charger IC and some boards don't have an INT33FE device at all. Since the information about the used charger + fuel-gauge + other chips is necessary in other places too, the kernel now adds a "intel,cht-wc-setup" string property to the Whiskey Cove PMIC i2c-client based on DMI matching, which reliably describes the board's setup of the PMIC. Switch to using the "intel,cht-wc-setup" property and add support for instantiating an i2c-client for either a bq24292i or a bq25890 charger. This has been tested on a GPD pocket (which uses the old bq24292i setup) and on a Xiaomi Mi Pad 2 with a bq25890 charger. Signed-off-by: Hans de Goede Acked-by: Wolfram Sang --- drivers/i2c/busses/i2c-cht-wc.c | 77 +++++++++++++++++++++++++-------- 1 file changed, 59 insertions(+), 18 deletions(-) diff --git a/drivers/i2c/busses/i2c-cht-wc.c b/drivers/i2c/busses/i2c-cht-wc.c index 1cf68f85b2e1..e7d62af6c39d 100644 --- a/drivers/i2c/busses/i2c-cht-wc.c +++ b/drivers/i2c/busses/i2c-cht-wc.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #define CHT_WC_I2C_CTRL 0x5e24 @@ -304,18 +305,55 @@ static struct bq24190_platform_data bq24190_pdata = { .regulator_init_data = &bq24190_vbus_init_data, }; +static struct i2c_board_info bq24190_board_info = { + .type = "bq24190", + .addr = 0x6b, + .dev_name = "bq24190", + .swnode = &bq24190_node, + .platform_data = &bq24190_pdata, +}; + +static struct regulator_consumer_supply bq25890_vbus_consumer = { + .supply = "vbus", + .dev_name = "cht_wcove_pwrsrc", +}; + +static const struct regulator_init_data bq25890_vbus_init_data = { + .constraints = { + .valid_ops_mask = REGULATOR_CHANGE_STATUS, + }, + .consumer_supplies = &bq25890_vbus_consumer, + .num_consumer_supplies = 1, +}; + +static struct bq25890_platform_data bq25890_pdata = { + .regulator_init_data = &bq25890_vbus_init_data, +}; + +static const struct property_entry bq25890_props[] = { + PROPERTY_ENTRY_BOOL("ti,skip-init"), + { } +}; + +static const struct software_node bq25890_node = { + .properties = bq25890_props, +}; + +static struct i2c_board_info bq25890_board_info = { + .type = "bq25890", + .addr = 0x6a, + .dev_name = "bq25890", + .swnode = &bq25890_node, + .platform_data = &bq25890_pdata, +}; + static int cht_wc_i2c_adap_i2c_probe(struct platform_device *pdev) { struct intel_soc_pmic *pmic = dev_get_drvdata(pdev->dev.parent); + struct i2c_board_info *board_info = NULL; struct cht_wc_i2c_adap *adap; - struct i2c_board_info board_info = { - .type = "bq24190", - .addr = 0x6b, - .dev_name = "bq24190", - .swnode = &bq24190_node, - .platform_data = &bq24190_pdata, - }; int ret, reg, irq; + const char *str; irq = platform_get_irq(pdev, 0); if (irq < 0) @@ -379,17 +417,20 @@ static int cht_wc_i2c_adap_i2c_probe(struct platform_device *pdev) if (ret) goto remove_irq_domain; - /* - * Normally the Whiskey Cove PMIC is paired with a TI bq24292i charger, - * connected to this i2c bus, and a max17047 fuel-gauge and a fusb302 - * USB Type-C controller connected to another i2c bus. In this setup - * the max17047 and fusb302 devices are enumerated through an INT33FE - * ACPI device. If this device is present register an i2c-client for - * the TI bq24292i charger. - */ - if (acpi_dev_present("INT33FE", NULL, -1)) { - board_info.irq = adap->client_irq; - adap->client = i2c_new_client_device(&adap->adapter, &board_info); + ret = device_property_read_string(pdev->dev.parent, "intel,cht-wc-setup", &str); + if (ret) + dev_warn(&pdev->dev, "intel,cht-wc-setup not set, not instantiating charger device\n"); + else if (!strcmp(str, "bq24292i,max17047,fusb302,pi3usb30532")) + board_info = &bq24190_board_info; + else if (!strcmp(str, "bq25890,bq27520")) + board_info = &bq25890_board_info; + else + dev_warn(&pdev->dev, "Unknown intel,cht-wc-setup value: '%s', not instantiating charger device\n", + str); + + if (board_info) { + board_info->irq = adap->client_irq; + adap->client = i2c_new_client_device(&adap->adapter, board_info); if (IS_ERR(adap->client)) { ret = PTR_ERR(adap->client); goto del_adapter; From patchwork Sat Oct 30 18:28:12 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: 1548677 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=RsArTDfH; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4HhSW26SRYz9sXS for ; Sun, 31 Oct 2021 05:29:18 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232156AbhJ3Sbs (ORCPT ); Sat, 30 Oct 2021 14:31:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:47330 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232166AbhJ3Sbb (ORCPT ); Sat, 30 Oct 2021 14:31:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635618540; 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=m6HmNT833c+9fVgs3GgWn5FyPC8j48ztpTXVuqbk+XU=; b=RsArTDfHqWII3qSLW1Dnw9pdLnin++92xEBMaEiEj7YOvMFUAjS3MptxnOm/KcJQfZKrln m4CATFu7fQ9iZqWkWT98Sl+5EHqWWVYsZ6nxz7bL7idR/Lss7f9TgB8yDLb9o7B7PnMWLf 09mtyivDySNPg3PK6KlLSVUPyYq43o4= 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-476-ws3MFhw3PN2RDUpf6G4_5A-1; Sat, 30 Oct 2021 14:28:56 -0400 X-MC-Unique: ws3MFhw3PN2RDUpf6G4_5A-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CC7D7806688; Sat, 30 Oct 2021 18:28:54 +0000 (UTC) Received: from x1.localdomain (unknown [10.39.192.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 09D6D5F4E1; Sat, 30 Oct 2021 18:28:51 +0000 (UTC) From: Hans de Goede To: Mark Gross , Andy Shevchenko , Wolfram Sang , Sebastian Reichel , MyungJoo Ham , Chanwoo Choi , Ard Biesheuvel Cc: Hans de Goede , 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: [PATCH 12/13] extcon: intel-cht-wc: Check new "intel,cht-wc-setup" device-property Date: Sat, 30 Oct 2021 20:28:12 +0200 Message-Id: <20211030182813.116672-13-hdegoede@redhat.com> In-Reply-To: <20211030182813.116672-1-hdegoede@redhat.com> References: <20211030182813.116672-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org The CHT_WC_VBUS_GPIO_CTLO GPIO actually driving an external 5V Vboost converter for Vbus depends on the board on which the Cherry Trail - Whiskey Cove PMIC is actually used. Since the information about the exact PMIC setup is necessary in other places too, the kernel now adds a "intel,cht-wc-setup" string property to the Whiskey Cove PMIC i2c-client based on DMI matching. Only poke the CHT_WC_VBUS_GPIO_CTLO GPIO if this new property has the "bq24292i,max17047,fusb302,pi3usb30532" value which indicates the Type-C (with PD and DP-altmode) setup used on the GPD pocket and GPD win; and on which this GPIO actually controls an external 5V Vboost converter. Signed-off-by: Hans de Goede --- drivers/extcon/extcon-intel-cht-wc.c | 38 ++++++++++++++++------------ 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/drivers/extcon/extcon-intel-cht-wc.c b/drivers/extcon/extcon-intel-cht-wc.c index 771f6f4cf92e..a7a6b43d699b 100644 --- a/drivers/extcon/extcon-intel-cht-wc.c +++ b/drivers/extcon/extcon-intel-cht-wc.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -338,8 +339,8 @@ static int cht_wc_extcon_probe(struct platform_device *pdev) struct intel_soc_pmic *pmic = dev_get_drvdata(pdev->dev.parent); struct cht_wc_extcon_data *ext; unsigned long mask = ~(CHT_WC_PWRSRC_VBUS | CHT_WC_PWRSRC_USBID_MASK); - int pwrsrc_sts, id; - int irq, ret; + int id, irq, pwrsrc_sts, ret; + const char *setup; irq = platform_get_irq(pdev, 0); if (irq < 0) @@ -358,20 +359,25 @@ static int cht_wc_extcon_probe(struct platform_device *pdev) if (IS_ERR(ext->edev)) return PTR_ERR(ext->edev); - /* - * When a host-cable is detected the BIOS enables an external 5v boost - * converter to power connected devices there are 2 problems with this: - * 1) This gets seen by the external battery charger as a valid Vbus - * supply and it then tries to feed Vsys from this creating a - * feedback loop which causes aprox. 300 mA extra battery drain - * (and unless we drive the external-charger-disable pin high it - * also tries to charge the battery causing even more feedback). - * 2) This gets seen by the pwrsrc block as a SDP USB Vbus supply - * Since the external battery charger has its own 5v boost converter - * which does not have these issues, we simply turn the separate - * external 5v boost converter off and leave it off entirely. - */ - cht_wc_extcon_set_5v_boost(ext, false); + ret = device_property_read_string(ext->dev->parent, "intel,cht-wc-setup", &setup); + if (ret) { + dev_warn(ext->dev, "intel,cht-wc-setup not set\n"); + } else if (!strcmp(setup, "bq24292i,max17047,fusb302,pi3usb30532")) { + /* + * When a host-cable is detected the BIOS enables an external 5v boost + * converter to power connected devices there are 2 problems with this: + * 1) This gets seen by the external battery charger as a valid Vbus + * supply and it then tries to feed Vsys from this creating a + * feedback loop which causes aprox. 300 mA extra battery drain + * (and unless we drive the external-charger-disable pin high it + * also tries to charge the battery causing even more feedback). + * 2) This gets seen by the pwrsrc block as a SDP USB Vbus supply + * Since the external battery charger has its own 5v boost converter + * which does not have these issues, we simply turn the separate + * external 5v boost converter off and leave it off entirely. + */ + cht_wc_extcon_set_5v_boost(ext, false); + } /* Enable sw control */ ret = cht_wc_extcon_sw_control(ext, true); From patchwork Sat Oct 30 18:28:13 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: 1548678 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=D9ClmcwX; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4HhSWC4PCRz9sXS for ; Sun, 31 Oct 2021 05:29:27 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232183AbhJ3Sb4 (ORCPT ); Sat, 30 Oct 2021 14:31:56 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:49398 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232193AbhJ3Sbe (ORCPT ); Sat, 30 Oct 2021 14:31:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635618544; 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=LUEju/CsoIc2q4rUI+8q7/o17IamENQRRYq/c3o9VcM=; b=D9ClmcwXx8RJGxWVH59mGqiU2zdTN9P2C7JXInwx4Bz/8MRtw+c1ENXoQuX9NTwul+rUGg Vm/PMKGzgpTrnCvZe100mOaearvOnqirIF5Xnb4W1FDBRO85tijf3p6ZOiJTqJc5iv0vPa KWxiZ5CVdz0rOmvuAXX8pih4agmTfNE= 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-327-E1K4M_LjOcGeJ06IU2lowg-1; Sat, 30 Oct 2021 14:29:00 -0400 X-MC-Unique: E1K4M_LjOcGeJ06IU2lowg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E691980668A; Sat, 30 Oct 2021 18:28:57 +0000 (UTC) Received: from x1.localdomain (unknown [10.39.192.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1F4445F4E9; Sat, 30 Oct 2021 18:28:54 +0000 (UTC) From: Hans de Goede To: Mark Gross , Andy Shevchenko , Wolfram Sang , Sebastian Reichel , MyungJoo Ham , Chanwoo Choi , Ard Biesheuvel Cc: Hans de Goede , 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: [PATCH 13/13] extcon: intel-cht-wc: Add support for devices with an USB-micro-B connector Date: Sat, 30 Oct 2021 20:28:13 +0200 Message-Id: <20211030182813.116672-14-hdegoede@redhat.com> In-Reply-To: <20211030182813.116672-1-hdegoede@redhat.com> References: <20211030182813.116672-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org So far the extcon-intel-cht-wc code has only been tested on devices with a Type-C connector with USB-PD, USB3 (superspeed) and DP-altmode support through a FUSB302 Type-C controller. Some devices with the intel-cht-wc PMIC however come with an USB-micro-B connector, or an USB-2 only Type-C connector without USB-PD. These device are identified by "intel,cht-wc-setup" = "bq25890,bq27520", since there is no Type-C controller on these devices the extcon code must control the Vbus 5V boost converter and the USB role switch depending on the detected cable-type. Signed-off-by: Hans de Goede --- drivers/extcon/extcon-intel-cht-wc.c | 81 ++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/drivers/extcon/extcon-intel-cht-wc.c b/drivers/extcon/extcon-intel-cht-wc.c index a7a6b43d699b..d8d0a69f4ddd 100644 --- a/drivers/extcon/extcon-intel-cht-wc.c +++ b/drivers/extcon/extcon-intel-cht-wc.c @@ -16,7 +16,9 @@ #include #include #include +#include #include +#include #include "extcon-intel.h" @@ -102,8 +104,11 @@ struct cht_wc_extcon_data { struct device *dev; struct regmap *regmap; struct extcon_dev *edev; + struct usb_role_switch *role_sw; + struct regulator *vbus_boost; unsigned int previous_cable; bool usb_host; + bool vbus_boost_enabled; }; static int cht_wc_extcon_get_id(struct cht_wc_extcon_data *ext, int pwrsrc_sts) @@ -217,6 +222,18 @@ static void cht_wc_extcon_set_otgmode(struct cht_wc_extcon_data *ext, CHT_WC_CHGRCTRL1_OTGMODE, val); if (ret) dev_err(ext->dev, "Error updating CHGRCTRL1 reg: %d\n", ret); + + if (ext->vbus_boost && ext->vbus_boost_enabled != enable) { + if (enable) + ret = regulator_enable(ext->vbus_boost); + else + ret = regulator_disable(ext->vbus_boost); + + if (ret == 0) + ext->vbus_boost_enabled = enable; + else + dev_err(ext->dev, "Error updating Vbus boost regulator: %d\n", ret); + } } static void cht_wc_extcon_enable_charging(struct cht_wc_extcon_data *ext, @@ -246,6 +263,7 @@ static void cht_wc_extcon_pwrsrc_event(struct cht_wc_extcon_data *ext) unsigned int cable = EXTCON_NONE; /* Ignore errors in host mode, as the 5v boost converter is on then */ bool ignore_get_charger_errors = ext->usb_host; + enum usb_role role; ret = regmap_read(ext->regmap, CHT_WC_PWRSRC_STS, &pwrsrc_sts); if (ret) { @@ -289,6 +307,18 @@ static void cht_wc_extcon_pwrsrc_event(struct cht_wc_extcon_data *ext) ext->usb_host = ((id == INTEL_USB_ID_GND) || (id == INTEL_USB_RID_A)); extcon_set_state_sync(ext->edev, EXTCON_USB_HOST, ext->usb_host); + + if (ext->usb_host) + role = USB_ROLE_HOST; + else if (pwrsrc_sts & CHT_WC_PWRSRC_VBUS) + role = USB_ROLE_DEVICE; + else + role = USB_ROLE_NONE; + + /* Note: this is a no-op when ext->role_sw is NULL */ + ret = usb_role_switch_set_role(ext->role_sw, role); + if (ret) + dev_err(ext->dev, "Error setting USB-role: %d\n", ret); } static irqreturn_t cht_wc_extcon_isr(int irq, void *data) @@ -334,6 +364,29 @@ static int cht_wc_extcon_sw_control(struct cht_wc_extcon_data *ext, bool enable) return ret; } +static int cht_wc_find_role_sw(struct cht_wc_extcon_data *ext) +{ + const struct software_node *swnode; + struct fwnode_handle *fwnode; + + swnode = software_node_find_by_name(NULL, "intel-xhci-usb-sw"); + if (!swnode) + return -EPROBE_DEFER; + + fwnode = software_node_fwnode(swnode); + ext->role_sw = usb_role_switch_find_by_fwnode(fwnode); + fwnode_handle_put(fwnode); + + return ext->role_sw ? 0 : -EPROBE_DEFER; +} + +static void cht_wc_put_role_sw(void *data) +{ + struct cht_wc_extcon_data *ext = data; + + usb_role_switch_put(ext->role_sw); +} + static int cht_wc_extcon_probe(struct platform_device *pdev) { struct intel_soc_pmic *pmic = dev_get_drvdata(pdev->dev.parent); @@ -377,6 +430,34 @@ static int cht_wc_extcon_probe(struct platform_device *pdev) * external 5v boost converter off and leave it off entirely. */ cht_wc_extcon_set_5v_boost(ext, false); + } else if (!strcmp(setup, "bq25890,bq27520")) { + /* + * Classic micro USB-B setup, this requires controling + * the role-sw and vbus based on the id-pin. + */ + ret = cht_wc_find_role_sw(ext); + if (ret) + return ret; + + ret = devm_add_action_or_reset(ext->dev, cht_wc_put_role_sw, ext); + if (ret) + return ret; + + /* + * On x86/ACPI platforms the regulator <-> consumer link is provided + * by platform_data passed to the regulator driver. This means that + * this info is not available before the regulator driver has bound. + * Use devm_regulator_get_optional() to avoid getting a dummy + * regulator and wait for the regulator to show up if necessary. + */ + ext->vbus_boost = devm_regulator_get_optional(ext->dev, "vbus"); + if (IS_ERR(ext->vbus_boost)) { + ret = PTR_ERR(ext->vbus_boost); + if (ret == -ENODEV) + ret = -EPROBE_DEFER; + + return dev_err_probe(ext->dev, ret, "getting vbus regulator"); + } } /* Enable sw control */