power-suppy/i2c/extcon: Add support for cht-wc PMIC without USB-PD support
Subsystems (7)
cover power-suppy/i2c/extcon: Add support for cht-wc PMIC without USB-PD support
On many X86 devices with a Cherry Trail SoC the PMIC / battery charger support is not fully handled by ACPI. Instead we need to load native drivers for the PMIC and various chips surrounding the PMIC like the charger IC. So far we mostly support the AXP288 PMIC this way, as well as the Intel Whiskey Cove PMIC with a FUSB302 Type-C controller + other ICs for a USB-PD, USB-3 (superspeed) and DP-altmode capable Type-C connector, as found on the GPD win and GPD pocket mini laptops.
On the Xiaomi Mi Pad 2 tablet the Whiskey Cove PMIC is used in a different setup then on the GPD devices, supporting only USB-2 with BC1.2 spec charger detection on its USB connector.
This series adds support for the charger IC in this setup and for having the extcon-intel-cht-wc code control the 5V Vbus boost converter and the USB role-switch, which is done by the FUSB302 Type-C controller driver in the GPD case.
This fixes the tablet not charging under Linux, host-mode only working when booted in host-mode, as well as device-mode not working. Note device-mode still does not work when plugged into a CDP port. I have identified the cause for this and I plan to submit a fix later.
This series consists of the following parts:
Patch 1 + 2: Add a "intel,cht-wc-setup" device property to the Whiskey Cove i2c-client so that various WC drivers can use this to identify which setup they are dealing with.
Patch 3 + 4: bq25890 psy driver bug-fixes
Patch 5 - 8: bq25890 psy support for non-devicetree devices
Patch 9 + 10: bq25890 psy support for registering the builtin Vbus boost converter as a regulator
Patch 11: Add support to the i2c-cht-wc I2C-controller driver to instantiate an i2c-client for the attached bq25890 charger
Patch 12 + 13: extcon-intel-cht-wc add support for the USB-2 only with BC1.2 charger detection setup
Assuming everybody is ok with this series, we need to talk about how to merge this.
Patch 1 makes some very small changes (just a rename) to drivers/firmware/efi code, I would like to merging this + patch 2 through the pdx86 tree (where the real changes are). Ard, can I have your ack for this please ?
Patch 11 depends on a header file added by patch 10, since the i2c-cht-wc.c code otherwise sees very little changes I believe it makes sense for patch 11 to be merged into linux-power-supply.git/for-next together with patches 3-10. Wolfram can we have you ack for this?
Patch 12 + 13 can be merged through the extcon tree, these have no (compile time) dependencies on the other patches.
This is all 5.17 material, and I will make sure the pdx86 patches adding the new property will land in 5.17-rc1, hopefully the rest will land then too, but if other bits land later that is fine too, as long as the new property is there behavior won't change on the GPD win/pocket and we won't get any regressions.
Regards,
Hans
p.s.
Patch 3 and 4 are pure bq25890 bugfixes and should probably be picked up right away independent of the rest of the series.
Hans de Goede (13):
platform/x86: Rename touchscreen_dmi to dmi_device_properties platform/x86: dmi_device_properties: Add setup info for boards with a
CHT Whiskey Cove PMIC
power: supply: bq25890: Fix race causing oops at boot
power: supply: bq25890: Fix initial setting of the F_CONV_RATE field
power: supply: bq25890: Add a bq25890_rw_init_data() helper
power: supply: bq25890: Add support for skipping initialization
power: supply: bq25890: Enable charging on boards where we skip reset
power: supply: bq25890: Drop dev->platform_data == NULL check
power: supply: bq25890: Add bq25890_set_otg_cfg() helper
power: supply: bq25890: Add support for registering the Vbus boost
converter as a regulator
i2c: cht-wc: Add support for devices using a bq25890 charger
extcon: intel-cht-wc: Check new "intel,cht-wc-setup" device-property
extcon: intel-cht-wc: Add support for devices with an USB-micro-B
connector
MAINTAINERS | 2 +-
drivers/extcon/extcon-intel-cht-wc.c | 119 ++++++++--
drivers/firmware/efi/embedded-firmware.c | 4 +-
drivers/i2c/busses/i2c-cht-wc.c | 77 ++++--
drivers/platform/x86/Kconfig | 20 +-
drivers/platform/x86/Makefile | 2 +-
...chscreen_dmi.c => dmi_device_properties.c} | 54 ++++-
drivers/power/supply/bq25890_charger.c | 223 ++++++++++++------
include/linux/efi_embedded_fw.h | 2 +-
include/linux/power/bq25890_charger.h | 15 ++
10 files changed, 400 insertions(+), 118 deletions(-)
rename drivers/platform/x86/{touchscreen_dmi.c => dmi_device_properties.c} (96%)
create mode 100644 include/linux/power/bq25890_charger.hSignature · 1 line
2.31.1
PATCH 1/13 platform/x86: Rename touchscreen_dmi to dmi_device_properties
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.
---
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%)MAINTAINERS +1 -1
@@ -17156,7 +17156,7 @@ L: [email protected] L: [email protected] 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 <[email protected]>
drivers/firmware/efi/embedded-firmware.c +2 -2
@@ -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, #endifNULL };
drivers/platform/x86/Kconfig +11 -9
@@ -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
drivers/platform/x86/Makefile +1 -1
@@ -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
drivers/platform/x86/dmi_device_properties.c renamed from drivers/platform/x86/touchscreen_dmi.c +4 -4
@@ -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 <[email protected]>
@@ -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 */
include/linux/efi_embedded_fw.h +1 -1
@@ -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);
Signature · 1 line
2.31.1
Re: [PATCH 01/13] platform/x86: Rename touchscreen_dmi to dmi_device_properties
Hi--
drivers/platform/x86/Kconfig config MLX_PLATFORM · line 985
Quoted 13 lines · Hans de Goede
drivers/platform/x86/Kconfig +2
-3@@ -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"
DMI-based
drivers/platform/x86/Kconfig config MLX_PLATFORM · line 989
Quoted 10 lines
drivers/platform/x86/Kconfig +2
-6+ 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
ACPI-based
drivers/platform/x86/Kconfig config MLX_PLATFORM · line 995
Quoted 6 lines
drivers/platform/x86/Kconfig +6
-0+ 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
x86-based
Quoted 1 line
drivers/platform/x86/Kconfig +1
-0+ tablets and 2-in-1 devices. If in doubt, say Y here.
Signature · 1 line
~Randy
PATCH 2/13 platform/x86: dmi_device_properties: Add setup info for boards with a CHT Whiskey Cove PMIC
In reply to Hans de GoedeAdd 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.
--- drivers/platform/x86/dmi_device_properties.c | 46 ++++++++++++++++++++ 1 file changed, 46 insertions(+)
drivers/platform/x86/dmi_device_properties.c +46 -0
@@ -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,
Signature · 1 line
2.31.1
Re: [PATCH 02/13] platform/x86: dmi_device_properties: Add setup info for boards with a CHT Whiskey Cove PMIC
Quoted 12 lines · Hans de Goede
Add a new "intel,cht-wc-setup" string property to the "INT34D3:00"
i2c_clientfor 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
Quoted 6 lines
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.
If it's internal property only, I would rather expect it to start with 'linux,' as DWC3 does. And it's also USB related.
...
drivers/platform/x86/dmi_device_properties.c static const struct ts_dmi_data vinga_twizzle_j116_data = { · line 992
Quoted 3 lines
drivers/platform/x86/dmi_device_properties.c +2
-0+PROPERTY_ENTRY_STRING ("intel,cht-wc-setup" ,"bq24292i,max17047,fusb302,pi3usb30532" ), + PROPERTY_ENTRY_STRING("intel,cht-wc-setup", "bq25890,bq27520"),
Besides that I'm not sure about the name of the property, maybe
'linux,cht-wc-usb-chips' or alike? And since it's a list, can we make it a string array?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 02/13] platform/x86: dmi_device_properties: Add setup info for boards with a CHT Whiskey Cove PMIC
Hi Andy,
Thank you for your feedback.
Quoted 25 lines · Andy Shevchenko
Quoted 12 lines · Hans de Goede
Add a new "intel,cht-wc-setup" string property to the "INT34D3:00"
i2c_clientfor 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
Quoted 6 lines
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.If it's internal property only, I would rather expect it to start with 'linux,' as DWC3 does. And it's also USB related.
...
Quoted 8 lines
drivers/platform/x86/dmi_device_properties.c static const struct ts_dmi_data vinga_twizzle_j116_data = { · line 992
Quoted 3 lines
drivers/platform/x86/dmi_device_properties.c +2
-0+PROPERTY_ENTRY_STRING ("intel,cht-wc-setup" ,"bq24292i,max17047,fusb302,pi3usb30532" ), + PROPERTY_ENTRY_STRING("intel,cht-wc-setup", "bq25890,bq27520"),Besides that I'm not sure about the name of the property, maybe
'linux,cht-wc-usb-chips' or alike? And since it's a list, can we make it a string array?
So now that I also have a yogabook to test on it has become clear that we really need to treat each device-model/board with a cht-wc PMIC differently in the various cht-wc MFD cell drivers.
So instead of using device-properties (patch 1 + 2 from this series) I've chosen to add a intel_cht_wc_get_model( helper to:drivers/mfd/intel_soc_pmic_chtwc.c
Which uses DMI matching (in a shared place so that we need the DMI table only once) and returns an enum value which represents all known boards.
Regards,
Hans
PATCH 3/13 power: supply: bq25890: Fix race causing oops at boot
In reply to Hans de GoedeBefore 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.
--- drivers/power/supply/bq25890_charger.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-)
drivers/power/supply/bq25890_charger.c +11 -12
@@ -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);
Signature · 1 line
2.31.1
Re: [PATCH 03/13] power: supply: bq25890: Fix race causing oops at boot
Hi,
Quoted 29 lines · Hans de Goede
Before this commit the driver was registering its interrupt handler before it registered the
power_supply, causingbq->chargerto 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 therequest_threaded_irq()call.Note this fix includes making the following 2 (necessary) changes:
Quoted 8 lines
1. Switch to the devm version of
power_supply_register()to avoid the need to make the error-handling inprobe()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 <[email protected]>---
Thanks, queued.
-- Sebastian
Quoted 62 lines
drivers/power/supply/bq25890_charger.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-)drivers/power/supply/bq25890_charger.c +11
-12@@ -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);Signature · 1 line
2.31.1
PATCH 4/13 power: supply: bq25890: Fix initial setting of the F_CONV_RATE field
In reply to Hans de GoedeThe 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.
--- drivers/power/supply/bq25890_charger.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/power/supply/bq25890_charger.c +5 -5
@@ -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; }
Signature · 1 line
2.31.1
Re: [PATCH 04/13] power: supply: bq25890: Fix initial setting of the F_CONV_RATE field
Hi,
Quoted 6 lines · Hans de Goede
The code doing the initial setting of the
F_CONV_RATEfield based on thebq->state.onlineflag. In order for this to work properly, this must be done after the initialbq25890_get_chip_state()call.Signed-off-by Hans de Goede <[email protected]>---
Thanks, queued.
-- Sebastian
Quoted 32 lines
drivers/power/supply/bq25890_charger.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)drivers/power/supply/bq25890_charger.c +5
-5@@ -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; }Signature · 1 line
2.31.1
PATCH 5/13 power: supply: bq25890: Add a bq25890_rw_init_data() helper
In reply to Hans de GoedeOn 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.
--- drivers/power/supply/bq25890_charger.c | 62 +++++++++++++++++--------- 1 file changed, 40 insertions(+), 22 deletions(-)
drivers/power/supply/bq25890_charger.c +40 -22
@@ -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 ) {
Signature · 1 line
2.31.1
PATCH 6/13 power: supply: bq25890: Add support for skipping initialization
In reply to Hans de GoedeOn 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.
--- drivers/power/supply/bq25890_charger.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-)
drivers/power/supply/bq25890_charger.c +16 -7
@@ -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 ; }
Signature · 1 line
2.31.1
Re: [PATCH 06/13] power: supply: bq25890: Add support for skipping initialization
Quoted 11 lines · Hans de Goede
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.
With 'ti,' prefix it can be a potential collision in name space, for internal properties I would rather use 'linux,' one.
...
drivers/power/supply/bq25890_charger.c static int bq25890_fw_probe(struct bq25890_device *bq) · line 928
Quoted 3 lines
drivers/power/supply/bq25890_charger.c +3
-0+ init->write_cfg = !device_property_read_bool (bq->dev,"ti,skip-init" ); +if (!init->write_cfg) +return 0 ;
Why to have double negation here?
I would rather expect that you will have direct value in the structure and do a respective check in the functions.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 06/13] power: supply: bq25890: Add support for skipping initialization
Hi,
Quoted 13 lines · Andy Shevchenko
Quoted 11 lines · Hans de Goede
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.
Quoted 2 lines
With 'ti,' prefix it can be a potential collision in name space, for internal properties I would rather use 'linux,' one.
Good point, changed for v2.
Quoted 9 lines
...
drivers/power/supply/bq25890_charger.c static int bq25890_fw_probe(struct bq25890_device *bq) · line 928
Quoted 3 lines
drivers/power/supply/bq25890_charger.c +3
-0+ init->write_cfg = !device_property_read_bool (bq->dev,"ti,skip-init" ); +if (!init->write_cfg) +return 0 ;Why to have double negation here?
I would rather expect that you will have direct value in the structure and do a respective check in the functions.
Because in all places except this one we want to know if we need to write the cfg to the device, removing the double negation here would mean adding negation to a init->skip_init check in many places, so this is cleaner.
Regards,
Hans
PATCH 7/13 power: supply: bq25890: Enable charging on boards where we skip reset
In reply to Hans de GoedeOn 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.
--- drivers/power/supply/bq25890_charger.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/power/supply/bq25890_charger.c +11 -0
@@ -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 */
Signature · 1 line
2.31.1
Re: [PATCH 07/13] power: supply: bq25890: Enable charging on boards where we skip reset
Quoted 7 lines · Hans de Goede
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_CFGis set to 0 before handing control over to the OS.Explicitly set
F_CHG_CFGto 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.
We should check if an OTG host mode with powering of bus by bq25890 is not enabled before enable charging. If we boot with OTG device connected, this can cause troubles.
Quoted 31 lines
Signed-off-by Hans de Goede <[email protected]>--- drivers/power/supply/bq25890_charger.c | 11 +++++++++++ 1 file changed, 11 insertions(+)drivers/power/supply/bq25890_charger.c +11
-0@@ -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 */ Signature · 1 line
2.31.1
Signature · 1 line
Yauhen Kharuzhy
PATCH 8/13 power: supply: bq25890: Drop dev->platform_data == NULL check
In reply to Hans de GoedeDrop 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.
--- drivers/power/supply/bq25890_charger.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/power/supply/bq25890_charger.c +4 -8
@@ -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);
Signature · 1 line
2.31.1
PATCH 9/13 power: supply: bq25890: Add bq25890_set_otg_cfg() helper
In reply to Hans de GoedeAdd a bq25890_set_otg_cfg() helper function, this is a preparation patch for adding regulator support.
--- drivers/power/supply/bq25890_charger.c | 28 ++++++++++++++------------ 1 file changed, 15 insertions(+), 13 deletions(-)
drivers/power/supply/bq25890_charger.c +15 -13
@@ -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,
Signature · 1 line
2.31.1
Re: [PATCH 09/13] power: supply: bq25890: Add bq25890_set_otg_cfg() helper
Quoted 3 lines · Hans de Goede
Add a
bq25890_set_otg_cfg()helper function, this is a preparation patch for adding regulator support.
...
Quoted 11 lines
switch (bq->usb_event) { case USB_EVENT_ID: /* Enable boost mode */drivers/power/supply/bq25890_charger.c +1
-3- 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 */
drivers/power/supply/bq25890_charger.c static void bq25890_usb_work(struct work_struct *data) · line 805
Quoted 10 lines
drivers/power/supply/bq25890_charger.c +3
-5- 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 ; }
While at it,
default:
break;
?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 09/13] power: supply: bq25890: Add bq25890_set_otg_cfg() helper
Hi,
Quoted 29 lines · Andy Shevchenko
Quoted 3 lines · Hans de Goede
Add a
bq25890_set_otg_cfg()helper function, this is a preparation patch for adding regulator support....
Quoted 11 lines
switch (bq->usb_event) { case USB_EVENT_ID: /* Enable boost mode */drivers/power/supply/bq25890_charger.c +1
-3- 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 */ drivers/power/supply/bq25890_charger.c static void bq25890_usb_work(struct work_struct *data) · line 805
Quoted 10 lines
drivers/power/supply/bq25890_charger.c +3
-5- 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 ; }
Quoted 4 lines
While at it,
default:
break;
bq->usb_event is not an enum, so there is no need for this.
Regards,
Hans
Re: [PATCH 09/13] power: supply: bq25890: Add bq25890_set_otg_cfg() helper
In reply to Hans de GoedeQuoted 2 lines · Hans de Goede
Add a
bq25890_set_otg_cfg()helper function, this is a preparation patch for adding regulator support.
The same notice here: if we enabling the boost mode to supply USB OTG device, we should disable charging and vice versa. I don't remember if enabling of OTG with CHG enabled really caused issues but I avoided this in my Yoga Book work.
I made quick check — seems that charging can be enabled during of boost operation, there are no visible side effects in registers and no limitation in the datasheet, so your approach may be good.
Quoted 61 lines
Signed-off-by Hans de Goede <[email protected]>--- drivers/power/supply/bq25890_charger.c | 28 ++++++++++++++------------ 1 file changed, 15 insertions(+), 13 deletions(-)drivers/power/supply/bq25890_charger.c +15
-13@@ -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,Signature · 1 line
2.31.1
Signature · 1 line
Yauhen Kharuzhy
Re: [PATCH 09/13] power: supply: bq25890: Add bq25890_set_otg_cfg() helper
Hi,
Quoted 4 lines · Yauhen Kharuzhy
Quoted 2 lines · Hans de Goede
Add a
bq25890_set_otg_cfg()helper function, this is a preparation patch for adding regulator support.
Quoted 8 lines
The same notice here: if we enabling the boost mode to supply USB OTG device, we should disable charging and vice versa. I don't remember if enabling of OTG with CHG enabled really caused issues but I avoided this in my Yoga Book work.
I made quick check — seems that charging can be enabled during of boost operation, there are no visible side effects in registers and no limitation in the datasheet, so your approach may be good.
Right, the charging bit can simply be always on, if the OTG boost converter is enabled then the charger it will automatically stop charging (AFAIK it is partly re-using the same hw even).
I've no idea why the charging bit is being cleared by the BIOS, there really is no need for this, with the exception of either:
1. Using an external Vbus boost converter, because that can e.g. deliver more current, then charging does need to be disabled.
2. Disabling charging for battery health reasons
1. is not the case here; and 2. is something which we could export as something userspace can request but that is optional.
So for normal use there really is no reason to set the charging bit to 0 ever (and it is 1 on reset), so just setting it to 1 makes the behavior the same as on many ARM devices where this charger is also used and the same as how similar chargers like the bq2419x and bq2429x are used on other X86 devices.
Regards,
Hans
Quoted 63 lines
Quoted 62 lines
Signed-off-by Hans de Goede <[email protected]>--- drivers/power/supply/bq25890_charger.c | 28 ++++++++++++++------------ 1 file changed, 15 insertions(+), 13 deletions(-)drivers/power/supply/bq25890_charger.c +15
-13@@ -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,Signature · 1 line
2.31.1
PATCH 10/13 power: supply: bq25890: Add support for registering the Vbus boost converter as a regulator
In reply to Hans de GoedeThe 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.
--- 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
drivers/power/supply/bq25890_charger.c +56 -0
@@ -8,7 +8,9 @@#include <linux/module.h> #include <linux/i2c.h> #include <linux/power_supply.h> +#include <linux/power/bq25890_charger.h> #include <linux/regmap.h> +#include <linux/regulator/driver.h> #include <linux/types.h> #include <linux/gpio/consumer.h> #include <linux/interrupt.h>
@@ -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);
include/linux/power/bq25890_charger.h new file +15 -0
@@ -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 <linux/regulator/machine.h> + +struct bq25890_platform_data { +const struct regulator_init_data *regulator_init_data; +}; + +#endif
Signature · 1 line
2.31.1
Re: [PATCH 10/13] power: supply: bq25890: Add support for registering the Vbus boost converter as a regulator
Quoted 9 lines · Hans de Goede
The
bq25890_chargercode 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_datathroughplatform_datafor use on boards where device-tree is not used and the platform code must thus provide theregulator_init_data.
...
Quoted 10 lines
drivers/power/supply/bq25890_charger.c +6
-0@@ -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; +
drivers/power/supply/bq25890_charger.c static int bq25890_probe(struct i2c_client *client, · line 1077
Quoted 10 lines
drivers/power/supply/bq25890_charger.c +9
-0+ 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 }
}
#ifdef
else {
...
}
#endif
is a bit better to maintain (less error prone in case of new code).
...
include/linux/power/bq25890_charger.h line 9
Quoted 4 lines
include/linux/power/bq25890_charger.h new file +3
-0+#ifndef _BQ25890_CHARGER_H_ +#define _BQ25890_CHARGER_H_ +#include <linux/regulator/machine.h>
struct regulator_init_data;
should be sufficient, no header is needed.
Quoted 5 lines
include/linux/power/bq25890_charger.h new file +5
-0+struct bq25890_platform_data { +const struct regulator_init_data *regulator_init_data; +}; + +#endif
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 10/13] power: supply: bq25890: Add support for registering the Vbus boost converter as a regulator
Hi,
Quoted 45 lines · Andy Shevchenko
Quoted 9 lines · Hans de Goede
The
bq25890_chargercode 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_datathroughplatform_datafor use on boards where device-tree is not used and the platform code must thus provide theregulator_init_data....
Quoted 10 lines
drivers/power/supply/bq25890_charger.c +6
-0@@ -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; +drivers/power/supply/bq25890_charger.c static int bq25890_probe(struct i2c_client *client, · line 1077
Quoted 10 lines
drivers/power/supply/bq25890_charger.c +9
-0+ 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 }}
#ifdef
else {
...
}
#endifis a bit better to maintain (less error prone in case of new code).
...
Quoted 8 lines
include/linux/power/bq25890_charger.h line 9
Quoted 4 lines
include/linux/power/bq25890_charger.h new file +3
-0+#ifndef _BQ25890_CHARGER_H_ +#define _BQ25890_CHARGER_H_ +#include <linux/regulator/machine.h> struct
regulator_init_data;should be sufficient, no header is needed.
Thanks, I've fixed both for v2 of the patch-set.
Regards,
Hans
Quoted 7 lines
Quoted 6 lines
include/linux/power/bq25890_charger.h new file +5
-0+struct bq25890_platform_data { +const struct regulator_init_data *regulator_init_data; +}; + +#endif
PATCH 11/13 i2c: cht-wc: Add support for devices using a bq25890 charger
In reply to Hans de GoedeThe 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.
--- drivers/i2c/busses/i2c-cht-wc.c | 77 +++++++++++++++++++++++++-------- 1 file changed, 59 insertions(+), 18 deletions(-)
drivers/i2c/busses/i2c-cht-wc.c +59 -18
@@ -18,6 +18,7 @@#include <linux/module.h> #include <linux/platform_device.h> #include <linux/power/bq24190_charger.h> +#include <linux/power/bq25890_charger.h> #include <linux/slab.h> #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;
Signature · 1 line
2.31.1
Re: [PATCH 11/13] i2c: cht-wc: Add support for devices using a bq25890 charger
Quoted 18 lines · Hans de Goede
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.
Quoted 7 lines
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 <[email protected]>
In general, fine with me from the I2C side:
drivers/i2c/busses/i2c-cht-wc.c static int cht_wc_i2c_adap_i2c_probe(struct platform_device *pdev) · line 426
Quoted 4 lines
drivers/i2c/busses/i2c-cht-wc.c +4
-0+else if (!strcmp (str,"bq24292i,max17047,fusb302,pi3usb30532" )) + board_info = &bq24190_board_info; +else if (!strcmp (str,"bq25890,bq27520" )) + board_info = &bq25890_board_info;
Very minor nit: I prefer 'strcmp() == 0' because the above could be read as 'if not strcmp()' which is sadly misleading. But I am not strict with it.
Re: [PATCH 11/13] i2c: cht-wc: Add support for devices using a bq25890 charger
Hi,
Quoted 22 lines · Wolfram Sang
Quoted 21 lines · Hans de Goede
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.
Quoted 8 lines
Quoted 4 lines
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 <[email protected]>In general, fine with me from the I2C side:
Acked-by Wolfram Sang <[email protected]>
Thank you for v2 I've refactored things a bit, enough that I'm going to drop your Ack, sorry.
Quoted 8 lines
drivers/i2c/busses/i2c-cht-wc.c static int cht_wc_i2c_adap_i2c_probe(struct platform_device *pdev) · line 426
Quoted 4 lines
drivers/i2c/busses/i2c-cht-wc.c +4
-0+else if (!strcmp (str,"bq24292i,max17047,fusb302,pi3usb30532" )) + board_info = &bq24190_board_info; +else if (!strcmp (str,"bq25890,bq27520" )) + board_info = &bq25890_board_info;Very minor nit: I prefer '
strcmp()== 0' because the above could be read as 'if notstrcmp()' which is sadly misleading. But I am not strict with it.
All the strcmp-s are gone in the refactored version.
Regards,
Hans
Re: [PATCH 11/13] i2c: cht-wc: Add support for devices using a bq25890 charger
In reply to Hans de GoedeQuoted 64 lines · Hans de Goede
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 <[email protected]>--- drivers/i2c/busses/i2c-cht-wc.c | 77 +++++++++++++++++++++++++-------- 1 file changed, 59 insertions(+), 18 deletions(-)drivers/i2c/busses/i2c-cht-wc.c +20
-0@@ -18,6 +18,7 @@#include <linux/module.h> #include <linux/platform_device.h> #include <linux/power/bq24190_charger.h> +#include <linux/power/bq25890_charger.h> #include <linux/slab.h> #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 ,
drivers/i2c/busses/i2c-cht-wc.c static struct bq24190_platform_data bq24190_pdata = { · line 336
Quoted 10 lines
drivers/i2c/busses/i2c-cht-wc.c +10
-0+}; + +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" ), + { } +};
The Lenovo Yoga Book firmware set the IINLIM field to 500 mA at initialization, we need a way to pass maximum allowed current in the fast charging mode to driver. I have added 'ti,input-max-current' in my port, for example.
Quoted 65 lines
drivers/i2c/busses/i2c-cht-wc.c +29
-18+ +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;Signature · 1 line
2.31.1
Signature · 1 line
Yauhen Kharuzhy
Re: [PATCH 11/13] i2c: cht-wc: Add support for devices using a bq25890 charger
Quoted 72 lines · Yauhen Kharuzhy
Quoted 71 lines · Hans de Goede
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 <[email protected]>--- drivers/i2c/busses/i2c-cht-wc.c | 77 +++++++++++++++++++++++++-------- 1 file changed, 59 insertions(+), 18 deletions(-)drivers/i2c/busses/i2c-cht-wc.c +27
-0@@ -18,6 +18,7 @@#include <linux/module.h> #include <linux/platform_device.h> #include <linux/power/bq24190_charger.h> +#include <linux/power/bq25890_charger.h> #include <linux/slab.h> #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[] = {
Quoted 8 lines
drivers/i2c/busses/i2c-cht-wc.c static struct bq24190_platform_data bq24190_pdata = { · line 336
Quoted 3 lines
drivers/i2c/busses/i2c-cht-wc.c +3
-0+ PROPERTY_ENTRY_BOOL("ti,skip-init"), + { } +};The Lenovo Yoga Book firmware set the IINLIM field to 500 mA at initialization, we need a way to pass maximum allowed current in the fast charging mode to driver. I have added 'ti,input-max-current' in my port, for example.
ICHG (charging current limit) is too low also (2A versus 4A in Android sources for this device), so it should be set by properties.
Signature · 1 line
Yauhen Kharuzhy
Re: [PATCH 11/13] i2c: cht-wc: Add support for devices using a bq25890 charger
In reply to Yauhen KharuzhyHi,
Quoted 72 lines · Yauhen Kharuzhy
Quoted 71 lines · Hans de Goede
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 <[email protected]>--- drivers/i2c/busses/i2c-cht-wc.c | 77 +++++++++++++++++++++++++-------- 1 file changed, 59 insertions(+), 18 deletions(-)drivers/i2c/busses/i2c-cht-wc.c +27
-0@@ -18,6 +18,7 @@#include <linux/module.h> #include <linux/platform_device.h> #include <linux/power/bq24190_charger.h> +#include <linux/power/bq25890_charger.h> #include <linux/slab.h> #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[] = {
Quoted 8 lines
drivers/i2c/busses/i2c-cht-wc.c static struct bq24190_platform_data bq24190_pdata = { · line 336
Quoted 3 lines
drivers/i2c/busses/i2c-cht-wc.c +3
-0+ PROPERTY_ENTRY_BOOL("ti,skip-init"), + { } +};The Lenovo Yoga Book firmware set the IINLIM field to 500 mA at initialization, we need a way to pass maximum allowed current in the fast charging mode to driver. I have added 'ti,input-max-current' in my port, for example.
500 mA is fine, we will run BC1.2 spec charger-type detection in the PMIC extcon code and then pass the result of that to the charger-IC. This is not present in this version of the patch-set because I did not have a yogabook yet when I wrote this, v2 will take care of this.
I hope to post a v2 sometime the coming 2 weeks.
Regards,
Hans
Quoted 67 lines
Quoted 66 lines
drivers/i2c/busses/i2c-cht-wc.c +29
-18+ +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;Signature · 1 line
2.31.1
PATCH 12/13 extcon: intel-cht-wc: Check new "intel,cht-wc-setup" device-property
In reply to Hans de GoedeThe 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.
--- drivers/extcon/extcon-intel-cht-wc.c | 38 ++++++++++++++++------------ 1 file changed, 22 insertions(+), 16 deletions(-)
drivers/extcon/extcon-intel-cht-wc.c +22 -16
@@ -14,6 +14,7 @@#include <linux/module.h> #include <linux/mod_devicetable.h> #include <linux/platform_device.h> +#include <linux/property.h> #include <linux/regmap.h> #include <linux/slab.h>
@@ -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);
Signature · 1 line
2.31.1
PATCH 13/13 extcon: intel-cht-wc: Add support for devices with an USB-micro-B connector
In reply to Hans de GoedeSo 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.
--- drivers/extcon/extcon-intel-cht-wc.c | 81 ++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+)
drivers/extcon/extcon-intel-cht-wc.c +81 -0
@@ -16,7 +16,9 @@#include <linux/platform_device.h> #include <linux/property.h> #include <linux/regmap.h> +#include <linux/regulator/consumer.h> #include <linux/slab.h> +#include <linux/usb/role.h> #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 */
Signature · 1 line
2.31.1
kernel test robot
build botRe: [PATCH 13/13] extcon: intel-cht-wc: Add support for devices with an USB-micro-B connector
I love your patch! Perhaps something to improve:
Hi Hans,
I love your patch! Perhaps something to improve:
[auto build test WARNING on efi/next]
[also build test WARNING on chanwoo-extcon/extcon-next linus/master v5.15-rc7] [cannot apply to sre-power-supply/for-next next-20211029]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Hans-de-Goede/power-suppy-i2c-extcon-Add-support-for-cht-wc-PMIC-without-USB-PD-support/20211031-023017 base: https://git.kernel.org/pub/scm/linux/kernel/git/efi/efi.git next config: x86_64-randconfig-a005-20211031 (attached as .config) compiler: gcc-9 (Debian 9.3.0-22) 9.3.0 reproduce (this is a W=1 build): # https://github.com/0day-ci/linux/commit/8793768dfa9dd49d9355c4acf620c186a87ee3ee git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Hans-de-Goede/power-suppy-i2c-extcon-Add-support-for-cht-wc-PMIC-without-USB-PD-support/20211031-023017 git checkout 8793768dfa9dd49d9355c4acf620c186a87ee3ee # save the attached .config to linux build tree make W=1 ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
drivers/extcon/extcon-intel-cht-wc.c: In function 'cht_wc_find_role_sw':
drivers/extcon/extcon-intel-cht-wc.c:377:17: error: implicit declaration of function 'usb_role_switch_find_by_fwnode' [-Werror=implicit-function-declaration]
377 | ext->role_sw = usb_role_switch_find_by_fwnode(fwnode);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/extcon/extcon-intel-cht-wc.c:377:15: warning: assignment to 'struct usb_role_switch *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
377 | ext->role_sw = usb_role_switch_find_by_fwnode(fwnode);
| ^cc1: some warnings being treated as errors
vim +377 drivers/extcon/extcon-intel-cht-wc.c
366
367 static int cht_wc_find_role_sw(struct cht_wc_extcon_data *ext)
368 {
369 const struct software_node *swnode;
370 struct fwnode_handle *fwnode;
371
372 swnode = software_node_find_by_name(NULL, "intel-xhci-usb-sw");
373 if (!swnode)
374 return -EPROBE_DEFER;
375
376 fwnode = software_node_fwnode(swnode);
> 377 ext->role_sw = usb_role_switch_find_by_fwnode(fwnode);
378 fwnode_handle_put(fwnode);
379
380 return ext->role_sw ? 0 : -EPROBE_DEFER;
381 }
382
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kernel test robot
build botRe: [PATCH 13/13] extcon: intel-cht-wc: Add support for devices with an USB-micro-B connector
In reply to Hans de GoedeI love your patch! Yet something to improve:
Hi Hans,
I love your patch! Yet something to improve:
[auto build test ERROR on efi/next]
[also build test ERROR on chanwoo-extcon/extcon-next linus/master v5.15-rc7] [cannot apply to sre-power-supply/for-next next-20211029]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Hans-de-Goede/power-suppy-i2c-extcon-Add-support-for-cht-wc-PMIC-without-USB-PD-support/20211031-023017 base: https://git.kernel.org/pub/scm/linux/kernel/git/efi/efi.git next config: x86_64-randconfig-a005-20211031 (attached as .config) compiler: gcc-9 (Debian 9.3.0-22) 9.3.0 reproduce (this is a W=1 build): # https://github.com/0day-ci/linux/commit/8793768dfa9dd49d9355c4acf620c186a87ee3ee git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Hans-de-Goede/power-suppy-i2c-extcon-Add-support-for-cht-wc-PMIC-without-USB-PD-support/20211031-023017 git checkout 8793768dfa9dd49d9355c4acf620c186a87ee3ee # save the attached .config to linux build tree make W=1 ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
drivers/extcon/extcon-intel-cht-wc.c: In function 'cht_wc_find_role_sw':
>> drivers/extcon/extcon-intel-cht-wc.c:377:17: error: implicit declaration of function 'usb_role_switch_find_by_fwnode' [-Werror=implicit-function-declaration]
377 | ext->role_sw = usb_role_switch_find_by_fwnode(fwnode);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/extcon/extcon-intel-cht-wc.c:377:15: warning: assignment to 'struct usb_role_switch *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
377 | ext->role_sw = usb_role_switch_find_by_fwnode(fwnode);
| ^cc1: some warnings being treated as errors
vim +/usb_role_switch_find_by_fwnode +377 drivers/extcon/extcon-intel-cht-wc.c
366
367 static int cht_wc_find_role_sw(struct cht_wc_extcon_data *ext)
368 {
369 const struct software_node *swnode;
370 struct fwnode_handle *fwnode;
371
372 swnode = software_node_find_by_name(NULL, "intel-xhci-usb-sw");
373 if (!swnode)
374 return -EPROBE_DEFER;
375
376 fwnode = software_node_fwnode(swnode);
> 377 ext->role_sw = usb_role_switch_find_by_fwnode(fwnode);
378 fwnode_handle_put(fwnode);
379
380 return ext->role_sw ? 0 : -EPROBE_DEFER;
381 }
382
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Re: [PATCH 13/13] extcon: intel-cht-wc: Add support for devices with an USB-micro-B connector
In reply to Hans de GoedeQuoted 12 lines · Hans de Goede
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.
...
drivers/extcon/extcon-intel-cht-wc.c static void cht_wc_extcon_set_otgmode(struct cht_wc_extcon_data *ext,
Quoted 10 lines
drivers/extcon/extcon-intel-cht-wc.c +9
-0+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);
if (ret)
dev_err()
else
...
?
Quoted 1 line
+ }
...
drivers/extcon/extcon-intel-cht-wc.c static int cht_wc_extcon_probe(struct platform_device *pdev) · line 435
Quoted 2 lines
drivers/extcon/extcon-intel-cht-wc.c +2
-0+/* +* Classic micro USB-B setup, this requires controling
controlling
Quoted 2 lines
(quoted diff) +2
-0+ * the role-sw and vbus based on the id-pin. + */
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 13/13] extcon: intel-cht-wc: Add support for devices with an USB-micro-B connector
Hi,
Quoted 27 lines · Andy Shevchenko
Quoted 12 lines · Hans de Goede
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.
...
drivers/extcon/extcon-intel-cht-wc.c static void cht_wc_extcon_set_otgmode(struct cht_wc_extcon_data *ext,
Quoted 10 lines
drivers/extcon/extcon-intel-cht-wc.c +9
-0+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);
Quoted 6 lines
if (ret)
dev_err()
else
...?
When doing if-else branches around an error code I always put the success handling in the if branch and have the else branch deal with the error to me that feels as the most natural way to do it the error is the exception and thus the "else"
Quoted 10 lines
Quoted 2 lines
+ }
...
drivers/extcon/extcon-intel-cht-wc.c static int cht_wc_extcon_probe(struct platform_device *pdev) · line 435
Quoted 2 lines
drivers/extcon/extcon-intel-cht-wc.c +2
-0+/* +* Classic micro USB-B setup, this requires controling controlling
Fixed for the next version.
Thanks & Regards,
Hans
Quoted 4 lines
Quoted 3 lines
(quoted diff) +2
-0+ * the role-sw and vbus based on the id-pin. + */