diff mbox series

[v2,14/20] mfd: intel_soc_pmic_chtwc: Add intel_cht_wc_get_model() helper function

Message ID 20211114170335.66994-15-hdegoede@redhat.com (mailing list archive)
State Not Applicable, archived
Headers show
Series power-suppy/i2c/extcon: Fix charger setup on Xiaomi Mi Pad 2 and Lenovo Yogabook | expand

Commit Message

Hans de Goede Nov. 14, 2021, 5:03 p.m. UTC
Tablet / laptop designs using an Intel Cherry Trail x86 main SoC with
an Intel Whiskey Cove PMIC do not use a single standard setup for
the charger, fuel-gauge and other chips surrounding the PMIC /
charging+data USB port.

Unlike what is normal on X86 this diversity in designs is not handled
by the ACPI tables. On 2 of the 3 known designs there are no standard
(PNP0C0A) ACPI battery devices and on the 3th design the ACPI battery
device does not work under Linux due to it requiring non-standard
and undocumented ACPI behavior.

So to make things work under Linux we use native charger and fuel-gauge
drivers on these devices, re-using the native drivers used on ARM boards
with the same charger / fuel-gauge ICs.

This requires various MFD-cell drivers for the CHT-WC PMIC cells to
know which model they are exactly running on so that they can e.g.
instantiate an I2C-client for the right model charger-IC (the charger
is connected to an I2C-controller which is part of the PMIC).

Rather then duplicating DMI-id matching to check which model we are
running on in each MFD-cell driver add a helper function for this
and make this id all 3 known models:

1. The GPD Win and GPD Pocket mini-laptops, these are really 2 models
but the Pocket re-uses the GPD Win's design in a different housing:

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 Xiaomi Mi Pad 2:

The WC PMIC is connected to a TI BQ25890 charger, paired with
a TI BQ27520 fuelgauge, using the TI BQ25890 for BC1.2 charger type
detection, for a USB-2 only Type-C port without PD.

3. The Lenovo Yoga Book YB1-X90 / Lenovo Yoga Book YB1-X91 series:

The WC PMIC is connected to a TI BQ25892 charger, paired with
a TI BQ27542 fuelgauge, using the WC PMIC for BC1.2 charger type
detection and using the BQ25892's Mediatek Pump Express+ (1.0)
support to enable charging with up to 12V through a micro-USB port.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/mfd/intel_soc_pmic_chtwc.c | 46 ++++++++++++++++++++++++++++++
 include/linux/mfd/intel_soc_pmic.h |  9 ++++++
 2 files changed, 55 insertions(+)

Comments

Andy Shevchenko Nov. 16, 2021, 11:18 a.m. UTC | #1
On Sun, Nov 14, 2021 at 7:04 PM Hans de Goede <hdegoede@redhat.com> wrote:
>
> Tablet / laptop designs using an Intel Cherry Trail x86 main SoC with
> an Intel Whiskey Cove PMIC do not use a single standard setup for

does not

> the charger, fuel-gauge and other chips surrounding the PMIC /
> charging+data USB port.
>
> Unlike what is normal on X86 this diversity in designs is not handled
> by the ACPI tables. On 2 of the 3 known designs there are no standard
> (PNP0C0A) ACPI battery devices and on the 3th design the ACPI battery
> device does not work under Linux due to it requiring non-standard
> and undocumented ACPI behavior.
>
> So to make things work under Linux we use native charger and fuel-gauge
> drivers on these devices, re-using the native drivers used on ARM boards
> with the same charger / fuel-gauge ICs.
>
> This requires various MFD-cell drivers for the CHT-WC PMIC cells to
> know which model they are exactly running on so that they can e.g.
> instantiate an I2C-client for the right model charger-IC (the charger
> is connected to an I2C-controller which is part of the PMIC).
>
> Rather then duplicating DMI-id matching to check which model we are
> running on in each MFD-cell driver add a helper function for this
> and make this id all 3 known models:
>
> 1. The GPD Win and GPD Pocket mini-laptops, these are really 2 models
> but the Pocket re-uses the GPD Win's design in a different housing:
>
> 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 Xiaomi Mi Pad 2:
>
> The WC PMIC is connected to a TI BQ25890 charger, paired with
> a TI BQ27520 fuelgauge, using the TI BQ25890 for BC1.2 charger type
> detection, for a USB-2 only Type-C port without PD.
>
> 3. The Lenovo Yoga Book YB1-X90 / Lenovo Yoga Book YB1-X91 series:
>
> The WC PMIC is connected to a TI BQ25892 charger, paired with
> a TI BQ27542 fuelgauge, using the WC PMIC for BC1.2 charger type
> detection and using the BQ25892's Mediatek Pump Express+ (1.0)
> support to enable charging with up to 12V through a micro-USB port.

...

> +               /*
> +                * Note this may not seem like a very unique match, but in the
> +                * 24000+ DMI decode dumps from linux-hardware.org only 42 have

Can you add https:// (or is it gopher? :)

> +                * 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 very few devices have both board_ and
> +                * product_name not set.
> +                */

...

> +enum intel_cht_wc_models intel_cht_wc_get_model(void)
> +{
> +       const struct dmi_system_id *id;
> +
> +       id = dmi_first_match(cht_wc_model_dmi_ids);
> +       if (!id)
> +               return INTEL_CHT_WC_UNKNOWN;
> +
> +       return (long)id->driver_data;

Why not proper casting, i.e. (enum intel_...)?

> +}
> +EXPORT_SYMBOL_GPL(intel_cht_wc_get_model);

Are you planning to use EXPORT_SYMBOL_GPL_NS()? If not, please consider it.
Hans de Goede Nov. 16, 2021, 11:43 a.m. UTC | #2
Hi,

On 11/16/21 12:18, Andy Shevchenko wrote:
> On Sun, Nov 14, 2021 at 7:04 PM Hans de Goede <hdegoede@redhat.com> wrote:
>>
>> Tablet / laptop designs using an Intel Cherry Trail x86 main SoC with
>> an Intel Whiskey Cove PMIC do not use a single standard setup for
> 
> does not
> 
>> the charger, fuel-gauge and other chips surrounding the PMIC /
>> charging+data USB port.
>>
>> Unlike what is normal on X86 this diversity in designs is not handled
>> by the ACPI tables. On 2 of the 3 known designs there are no standard
>> (PNP0C0A) ACPI battery devices and on the 3th design the ACPI battery
>> device does not work under Linux due to it requiring non-standard
>> and undocumented ACPI behavior.
>>
>> So to make things work under Linux we use native charger and fuel-gauge
>> drivers on these devices, re-using the native drivers used on ARM boards
>> with the same charger / fuel-gauge ICs.
>>
>> This requires various MFD-cell drivers for the CHT-WC PMIC cells to
>> know which model they are exactly running on so that they can e.g.
>> instantiate an I2C-client for the right model charger-IC (the charger
>> is connected to an I2C-controller which is part of the PMIC).
>>
>> Rather then duplicating DMI-id matching to check which model we are
>> running on in each MFD-cell driver add a helper function for this
>> and make this id all 3 known models:
>>
>> 1. The GPD Win and GPD Pocket mini-laptops, these are really 2 models
>> but the Pocket re-uses the GPD Win's design in a different housing:
>>
>> 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 Xiaomi Mi Pad 2:
>>
>> The WC PMIC is connected to a TI BQ25890 charger, paired with
>> a TI BQ27520 fuelgauge, using the TI BQ25890 for BC1.2 charger type
>> detection, for a USB-2 only Type-C port without PD.
>>
>> 3. The Lenovo Yoga Book YB1-X90 / Lenovo Yoga Book YB1-X91 series:
>>
>> The WC PMIC is connected to a TI BQ25892 charger, paired with
>> a TI BQ27542 fuelgauge, using the WC PMIC for BC1.2 charger type
>> detection and using the BQ25892's Mediatek Pump Express+ (1.0)
>> support to enable charging with up to 12V through a micro-USB port.
> 
> ...
> 
>> +               /*
>> +                * Note this may not seem like a very unique match, but in the
>> +                * 24000+ DMI decode dumps from linux-hardware.org only 42 have
> 
> Can you add https:// (or is it gopher? :)

linux-hardware.org is intended here as an identifier of the projects, not an
URL. The DMI decode database lives here:

https://github.com/linuxhw/DMI.git

But I don't believe that adding the exact URL in the comment is important,
esp. since that may change over time.

> 
>> +                * 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 very few devices have both board_ and
>> +                * product_name not set.
>> +                */
> 
> ...
> 
>> +enum intel_cht_wc_models intel_cht_wc_get_model(void)
>> +{
>> +       const struct dmi_system_id *id;
>> +
>> +       id = dmi_first_match(cht_wc_model_dmi_ids);
>> +       if (!id)
>> +               return INTEL_CHT_WC_UNKNOWN;
>> +
>> +       return (long)id->driver_data;
> 
> Why not proper casting, i.e. (enum intel_...)?

Because sizeof(enum) != sizeof(void *) so then the compiler will
complain. Where as sizeof(long) == sizeof(void *)

> 
>> +}
>> +EXPORT_SYMBOL_GPL(intel_cht_wc_get_model);
> 
> Are you planning to use EXPORT_SYMBOL_GPL_NS()? If not, please consider it.

No I was not planning on this and it seems overkill for just a single
exported symbol.

Regards,

Hans
Hans de Goede Nov. 28, 2021, 9:53 a.m. UTC | #3
Hi,

On 11/16/21 12:18, Andy Shevchenko wrote:
> On Sun, Nov 14, 2021 at 7:04 PM Hans de Goede <hdegoede@redhat.com> wrote:
>>
>> Tablet / laptop designs using an Intel Cherry Trail x86 main SoC with
>> an Intel Whiskey Cove PMIC do not use a single standard setup for
> 
> does not

designs ... do not. Design_s_ so more then one, so "do not" is correct.

<snip>

>> +}
>> +EXPORT_SYMBOL_GPL(intel_cht_wc_get_model);
> 
> Are you planning to use EXPORT_SYMBOL_GPL_NS()? If not, please consider it.

This will be gone in v3, since this info is now stored in struct intel_soc_pmic
as requested by Chanwoo.

Regards,

Hans
diff mbox series

Patch

diff --git a/drivers/mfd/intel_soc_pmic_chtwc.c b/drivers/mfd/intel_soc_pmic_chtwc.c
index 49c5f71664bc..3432bd18f5d0 100644
--- a/drivers/mfd/intel_soc_pmic_chtwc.c
+++ b/drivers/mfd/intel_soc_pmic_chtwc.c
@@ -10,6 +10,7 @@ 
 
 #include <linux/acpi.h>
 #include <linux/delay.h>
+#include <linux/dmi.h>
 #include <linux/err.h>
 #include <linux/i2c.h>
 #include <linux/interrupt.h>
@@ -134,6 +135,51 @@  static const struct regmap_irq_chip cht_wc_regmap_irq_chip = {
 	.num_regs = 1,
 };
 
+static const struct dmi_system_id cht_wc_model_dmi_ids[] = {
+	{	/* GPD win / GPD pocket mini laptops */
+		.driver_data = (void *)(long)INTEL_CHT_WC_GPD_WIN_POCKET,
+		/*
+		 * 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 very 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"),
+		},
+	}, {	/* Xiaomi Mi Pad 2 */
+		.driver_data = (void *)(long)INTEL_CHT_WC_XIAOMI_MIPAD2,
+		.matches = {
+			DMI_MATCH(DMI_SYS_VENDOR, "Xiaomi Inc"),
+			DMI_MATCH(DMI_PRODUCT_NAME, "Mipad2"),
+		},
+	}, {	/* Lenovo Yoga Book X90F / X91F / X91L */
+		.driver_data = (void *)(long)INTEL_CHT_WC_LENOVO_YOGABOOK1,
+		.matches = {
+		  /* Non exact match to match all versions */
+		  DMI_MATCH(DMI_PRODUCT_NAME, "Lenovo YB1-X9"),
+		},
+	},
+	{ } /* Terminating empty */
+};
+
+enum intel_cht_wc_models intel_cht_wc_get_model(void)
+{
+	const struct dmi_system_id *id;
+
+	id = dmi_first_match(cht_wc_model_dmi_ids);
+	if (!id)
+		return INTEL_CHT_WC_UNKNOWN;
+
+	return (long)id->driver_data;
+}
+EXPORT_SYMBOL_GPL(intel_cht_wc_get_model);
+
 static int cht_wc_probe(struct i2c_client *client)
 {
 	struct device *dev = &client->dev;
diff --git a/include/linux/mfd/intel_soc_pmic.h b/include/linux/mfd/intel_soc_pmic.h
index 6a88e34cb955..dd17d7f82434 100644
--- a/include/linux/mfd/intel_soc_pmic.h
+++ b/include/linux/mfd/intel_soc_pmic.h
@@ -41,7 +41,16 @@  struct intel_soc_pmic {
 	struct intel_scu_ipc_dev *scu;
 };
 
+enum intel_cht_wc_models {
+	INTEL_CHT_WC_UNKNOWN,
+	INTEL_CHT_WC_GPD_WIN_POCKET,
+	INTEL_CHT_WC_XIAOMI_MIPAD2,
+	INTEL_CHT_WC_LENOVO_YOGABOOK1,
+};
+
 int intel_soc_pmic_exec_mipi_pmic_seq_element(u16 i2c_address, u32 reg_address,
 					      u32 value, u32 mask);
 
+enum intel_cht_wc_models intel_cht_wc_get_model(void);
+
 #endif	/* __INTEL_SOC_PMIC_H__ */