diff mbox series

[v2,16/20] extcon: intel-cht-wc: Use new intel_cht_wc_get_model() helper

Message ID 20211114170335.66994-17-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
The CHT_WC_VBUS_GPIO_CTLO GPIO actually driving an external 5V Vboost
converter for Vbus depends on the board on which the Cherry Trail -
Whiskey Cove PMIC is actually used.

Since the information about the exact PMIC setup is necessary in other
places too, the drivers/mfd/intel_soc_pmic_chtwc.c code now has a new
intel_cht_wc_get_model() helper.

Only poke the CHT_WC_VBUS_GPIO_CTLO GPIO if this new helper returns
INTEL_CHT_WC_GPD_WIN_POCKET, which indicates the Type-C (with PD and
DP-altmode) setup used on the GPD pocket and GPD win; and on which
this GPIO actually controls an external 5V Vboost converter.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/extcon/extcon-intel-cht-wc.c | 35 +++++++++++++++++-----------
 1 file changed, 21 insertions(+), 14 deletions(-)

Comments

Chanwoo Choi Nov. 17, 2021, 6:47 a.m. UTC | #1
On 21. 11. 15. 오전 2:03, Hans de Goede wrote:
> The CHT_WC_VBUS_GPIO_CTLO GPIO actually driving an external 5V Vboost
> converter for Vbus depends on the board on which the Cherry Trail -
> Whiskey Cove PMIC is actually used.
> 
> Since the information about the exact PMIC setup is necessary in other
> places too, the drivers/mfd/intel_soc_pmic_chtwc.c code now has a new
> intel_cht_wc_get_model() helper.
> 
> Only poke the CHT_WC_VBUS_GPIO_CTLO GPIO if this new helper returns
> INTEL_CHT_WC_GPD_WIN_POCKET, which indicates the Type-C (with PD and
> DP-altmode) setup used on the GPD pocket and GPD win; and on which
> this GPIO actually controls an external 5V Vboost converter.
> 
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
>   drivers/extcon/extcon-intel-cht-wc.c | 35 +++++++++++++++++-----------
>   1 file changed, 21 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/extcon/extcon-intel-cht-wc.c b/drivers/extcon/extcon-intel-cht-wc.c
> index 771f6f4cf92e..a5aeeecc44fb 100644
> --- a/drivers/extcon/extcon-intel-cht-wc.c
> +++ b/drivers/extcon/extcon-intel-cht-wc.c
> @@ -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>
>   
> @@ -358,20 +359,26 @@ 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);
> +	switch (intel_cht_wc_get_model()) {

intel_cht_wc_get_model() is defined in driver/mfd/intel_soc_pmic_chtwc.c

Usually, mfd drivers share the data structure such as struct 
intel_soc_pmic. But, didn't call the exported function for only
specific driver between linux kernel framework (extcon vs. mfd).

So that I think that you better to update the mode information
to 'struct intel_soc_pmic' data structure and then use it
instead of using the exported function which may make the confusion.

> +	case INTEL_CHT_WC_GPD_WIN_POCKET:
> +		/*
> +		 * 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);
> +		break;
> +	default:
> +		break;
> +	}
>   
>   	/* Enable sw control */
>   	ret = cht_wc_extcon_sw_control(ext, true);
>
Hans de Goede Nov. 17, 2021, 10:28 p.m. UTC | #2
Hi,

On 11/17/21 07:47, Chanwoo Choi wrote:
> On 21. 11. 15. 오전 2:03, Hans de Goede wrote:
>> The CHT_WC_VBUS_GPIO_CTLO GPIO actually driving an external 5V Vboost
>> converter for Vbus depends on the board on which the Cherry Trail -
>> Whiskey Cove PMIC is actually used.
>>
>> Since the information about the exact PMIC setup is necessary in other
>> places too, the drivers/mfd/intel_soc_pmic_chtwc.c code now has a new
>> intel_cht_wc_get_model() helper.
>>
>> Only poke the CHT_WC_VBUS_GPIO_CTLO GPIO if this new helper returns
>> INTEL_CHT_WC_GPD_WIN_POCKET, which indicates the Type-C (with PD and
>> DP-altmode) setup used on the GPD pocket and GPD win; and on which
>> this GPIO actually controls an external 5V Vboost converter.
>>
>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>> ---
>>   drivers/extcon/extcon-intel-cht-wc.c | 35 +++++++++++++++++-----------
>>   1 file changed, 21 insertions(+), 14 deletions(-)
>>
>> diff --git a/drivers/extcon/extcon-intel-cht-wc.c b/drivers/extcon/extcon-intel-cht-wc.c
>> index 771f6f4cf92e..a5aeeecc44fb 100644
>> --- a/drivers/extcon/extcon-intel-cht-wc.c
>> +++ b/drivers/extcon/extcon-intel-cht-wc.c
>> @@ -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>
>>   @@ -358,20 +359,26 @@ 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);
>> +    switch (intel_cht_wc_get_model()) {
> 
> intel_cht_wc_get_model() is defined in driver/mfd/intel_soc_pmic_chtwc.c
> 
> Usually, mfd drivers share the data structure such as struct intel_soc_pmic. But, didn't call the exported function for only
> specific driver between linux kernel framework (extcon vs. mfd).
> 
> So that I think that you better to update the mode information
> to 'struct intel_soc_pmic' data structure and then use it
> instead of using the exported function which may make the confusion.

That is a good idea, thanks.

I've implemented this suggestion for the upcoming v3 of the patch-set.

Regards,

Hans


> 
>> +    case INTEL_CHT_WC_GPD_WIN_POCKET:
>> +        /*
>> +         * 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);
>> +        break;
>> +    default:
>> +        break;
>> +    }
>>         /* Enable sw control */
>>       ret = cht_wc_extcon_sw_control(ext, true);
>>
> 
>
diff mbox series

Patch

diff --git a/drivers/extcon/extcon-intel-cht-wc.c b/drivers/extcon/extcon-intel-cht-wc.c
index 771f6f4cf92e..a5aeeecc44fb 100644
--- a/drivers/extcon/extcon-intel-cht-wc.c
+++ b/drivers/extcon/extcon-intel-cht-wc.c
@@ -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>
 
@@ -358,20 +359,26 @@  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);
+	switch (intel_cht_wc_get_model()) {
+	case INTEL_CHT_WC_GPD_WIN_POCKET:
+		/*
+		 * 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);
+		break;
+	default:
+		break;
+	}
 
 	/* Enable sw control */
 	ret = cht_wc_extcon_sw_control(ext, true);