* [PATCH v3 0/2] extcon: Intel Cherry Trail Whiskey Cove PMIC and external charger tweaks
@ 2019-03-03 20:16 Yauhen Kharuzhy
2019-03-03 20:16 ` [PATCH v3 1/2] extcon-intel-cht-wc: Make charger detection co-existed with OTG host mode Yauhen Kharuzhy
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Yauhen Kharuzhy @ 2019-03-03 20:16 UTC (permalink / raw)
To: linux-kernel
Cc: MyungJoo Ham, Chanwoo Choi, Andy Shevchenko, Hans de Goede,
Yauhen Kharuzhy
At implementation of charging support for Lenovo Yoga Book (Intel Cherry
Trail based with Whiskey Cove PMIC), two pitfalls were found:
- for detection of charger type by PMIC, bit 6 in the CHGRCTRL1 register
should be set in 0 (and set to 1 for Host mode). Pick up its definition
and logic from from Intel code drop[1];
- "#CHARGE ENABLE" signal of external charger (bq25892) in Yoga Book is
connected to one of PMIC outputs controlled by CHGDISCTRL register.
Enable charging at driver initialization. Pick up this from Lenovo's code
drop[2,3].
v3 changes:
- Don't restore of initial state of CHGDISCTRL and CHGRCTRL0 at exit but
switch them into HW-controlled mode (as discussed in mailing list);
- Use regmap_update_bits() instead of regmap_readi()/regmap_write() in
the cht_wc_extcon_set_otgmode();
- Coding style and constant names changed as Andy and Hans recommended.
v2 changes:
- Disable HW control mode of CHGDISCTRL at driver probing and restore
initial state at exit.
- Switch CE output off if OTG host mode is enabled.
- Save and restore CHGRCTRL0 register also.
[1]. https://github.com/01org/ProductionKernelQuilts/uefi/cht-m1stable/patches/0001-power_supply-intel-pmic-ccsm-driver.patch
[2]. https://github.com/jekhor/yogabook-linux-android-kernel/blob/b7aa015ab794b516da7b6cb76e5e2d427e3b8b0c/drivers/power/bq2589x_charger.c#L2257
[3]. https://github.com/01org/ProductionKernelQuilts/uefi/cht-m1stable/patches/EM-Charger-Disable-battery-charging-in-S3-and-enable.patch
Yauhen Kharuzhy (2):
extcon-intel-cht-wc: Make charger detection co-existed with OTG host mode
extcon intel-cht-wc: Enable external charger
drivers/extcon/extcon-intel-cht-wc.c | 60 +++++++++++++++++++++++++++-
1 file changed, 58 insertions(+), 2 deletions(-)
--
2.20.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v3 1/2] extcon-intel-cht-wc: Make charger detection co-existed with OTG host mode
2019-03-03 20:16 [PATCH v3 0/2] extcon: Intel Cherry Trail Whiskey Cove PMIC and external charger tweaks Yauhen Kharuzhy
@ 2019-03-03 20:16 ` Yauhen Kharuzhy
2019-03-03 20:16 ` [PATCH v3 2/2] extcon intel-cht-wc: Enable external charger Yauhen Kharuzhy
2019-03-05 19:22 ` [PATCH v3 0/2] extcon: Intel Cherry Trail Whiskey Cove PMIC and external charger tweaks Hans de Goede
2 siblings, 0 replies; 5+ messages in thread
From: Yauhen Kharuzhy @ 2019-03-03 20:16 UTC (permalink / raw)
To: linux-kernel
Cc: MyungJoo Ham, Chanwoo Choi, Andy Shevchenko, Hans de Goede,
Yauhen Kharuzhy
Whiskey Cove Cherry Trail PMIC requires disabling OTG host mode before
of charger detection procedure. Do this by manipulationg of CHGRCTRL1
register.
Source: APCI DSDT code of Lenovo Yoga Book YB1-X91L and open-sourced
Intel's drivers.
Signed-off-by: Yauhen Kharuzhy <jekhor@gmail.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/extcon/extcon-intel-cht-wc.c | 26 +++++++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)
diff --git a/drivers/extcon/extcon-intel-cht-wc.c b/drivers/extcon/extcon-intel-cht-wc.c
index 5ef215297101..8d20e913536f 100644
--- a/drivers/extcon/extcon-intel-cht-wc.c
+++ b/drivers/extcon/extcon-intel-cht-wc.c
@@ -29,7 +29,15 @@
#define CHT_WC_CHGRCTRL0_DBPOFF BIT(6)
#define CHT_WC_CHGRCTRL0_CHR_WDT_NOKICK BIT(7)
-#define CHT_WC_CHGRCTRL1 0x5e17
+#define CHT_WC_CHGRCTRL1 0x5e17
+#define CHT_WC_CHGRCTRL1_FUSB_INLMT_100 BIT(0)
+#define CHT_WC_CHGRCTRL1_FUSB_INLMT_150 BIT(1)
+#define CHT_WC_CHGRCTRL1_FUSB_INLMT_500 BIT(2)
+#define CHT_WC_CHGRCTRL1_FUSB_INLMT_900 BIT(3)
+#define CHT_WC_CHGRCTRL1_FUSB_INLMT_1500 BIT(4)
+#define CHT_WC_CHGRCTRL1_FTEMP_EVENT BIT(5)
+#define CHT_WC_CHGRCTRL1_OTGMODE BIT(6)
+#define CHT_WC_CHGRCTRL1_DBPEN BIT(7)
#define CHT_WC_USBSRC 0x5e29
#define CHT_WC_USBSRC_STS_MASK GENMASK(1, 0)
@@ -198,6 +206,18 @@ static void cht_wc_extcon_set_5v_boost(struct cht_wc_extcon_data *ext,
dev_err(ext->dev, "Error writing Vbus GPIO CTLO: %d\n", ret);
}
+static void cht_wc_extcon_set_otgmode(struct cht_wc_extcon_data *ext,
+ bool enable)
+{
+ unsigned int val = enable ? CHT_WC_CHGRCTRL1_OTGMODE : 0;
+ int ret;
+
+ ret = regmap_update_bits(ext->regmap, CHT_WC_CHGRCTRL1,
+ CHT_WC_CHGRCTRL1_OTGMODE, val);
+ if (ret)
+ dev_err(ext->dev, "Error updating CHGRCTRL1 reg: %d\n", ret);
+}
+
/* Small helper to sync EXTCON_CHG_USB_SDP and EXTCON_USB state */
static void cht_wc_extcon_set_state(struct cht_wc_extcon_data *ext,
unsigned int cable, bool state)
@@ -222,10 +242,14 @@ static void cht_wc_extcon_pwrsrc_event(struct cht_wc_extcon_data *ext)
id = cht_wc_extcon_get_id(ext, pwrsrc_sts);
if (id == USB_ID_GND) {
+ cht_wc_extcon_set_otgmode(ext, true);
+
/* The 5v boost causes a false VBUS / SDP detect, skip */
goto charger_det_done;
}
+ cht_wc_extcon_set_otgmode(ext, false);
+
/* Plugged into a host/charger or not connected? */
if (!(pwrsrc_sts & CHT_WC_PWRSRC_VBUS)) {
/* Route D+ and D- to PMIC for future charger detection */
--
2.20.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v3 2/2] extcon intel-cht-wc: Enable external charger
2019-03-03 20:16 [PATCH v3 0/2] extcon: Intel Cherry Trail Whiskey Cove PMIC and external charger tweaks Yauhen Kharuzhy
2019-03-03 20:16 ` [PATCH v3 1/2] extcon-intel-cht-wc: Make charger detection co-existed with OTG host mode Yauhen Kharuzhy
@ 2019-03-03 20:16 ` Yauhen Kharuzhy
2019-03-05 19:22 ` [PATCH v3 0/2] extcon: Intel Cherry Trail Whiskey Cove PMIC and external charger tweaks Hans de Goede
2 siblings, 0 replies; 5+ messages in thread
From: Yauhen Kharuzhy @ 2019-03-03 20:16 UTC (permalink / raw)
To: linux-kernel
Cc: MyungJoo Ham, Chanwoo Choi, Andy Shevchenko, Hans de Goede,
Yauhen Kharuzhy
In some configuration external charger "#charge enable" signal is
connected to PMIC. Enable it at device probing to allow charging.
Save CHGRCTRL0 and CHGDISCTR registers at driver probing and restore
them at driver unbind to re-enable hardware charging control if it was
enabled before.
Tested at Lenovo Yoga Book (YB1-X91L).
Signed-off-by: Yauhen Kharuzhy <jekhor@gmail.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/extcon/extcon-intel-cht-wc.c | 34 +++++++++++++++++++++++++++-
1 file changed, 33 insertions(+), 1 deletion(-)
diff --git a/drivers/extcon/extcon-intel-cht-wc.c b/drivers/extcon/extcon-intel-cht-wc.c
index 8d20e913536f..53b28ecc4ad1 100644
--- a/drivers/extcon/extcon-intel-cht-wc.c
+++ b/drivers/extcon/extcon-intel-cht-wc.c
@@ -56,6 +56,13 @@
#define CHT_WC_USBSRC_TYPE_OTHER 8
#define CHT_WC_USBSRC_TYPE_DCP_EXTPHY 9
+#define CHT_WC_CHGDISCTRL 0x5e2f
+#define CHT_WC_CHGDISCTRL_OUT BIT(0)
+/* 0 - open drain, 1 - regular push-pull output */
+#define CHT_WC_CHGDISCTRL_DRV BIT(4)
+/* 0 - pin is controlled by SW, 1 - by HW */
+#define CHT_WC_CHGDISCTRL_FN BIT(6)
+
#define CHT_WC_PWRSRC_IRQ 0x6e03
#define CHT_WC_PWRSRC_IRQ_MASK 0x6e0f
#define CHT_WC_PWRSRC_STS 0x6e1e
@@ -218,6 +225,18 @@ static void cht_wc_extcon_set_otgmode(struct cht_wc_extcon_data *ext,
dev_err(ext->dev, "Error updating CHGRCTRL1 reg: %d\n", ret);
}
+static void cht_wc_extcon_enable_charging(struct cht_wc_extcon_data *ext,
+ bool enable)
+{
+ unsigned int val = enable ? 0 : CHT_WC_CHGDISCTRL_OUT;
+ int ret;
+
+ ret = regmap_update_bits(ext->regmap, CHT_WC_CHGDISCTRL,
+ CHT_WC_CHGDISCTRL_OUT, val);
+ if (ret)
+ dev_err(ext->dev, "Error updating CHGDISCTRL reg: %d\n", ret);
+}
+
/* Small helper to sync EXTCON_CHG_USB_SDP and EXTCON_USB state */
static void cht_wc_extcon_set_state(struct cht_wc_extcon_data *ext,
unsigned int cable, bool state)
@@ -242,6 +261,7 @@ static void cht_wc_extcon_pwrsrc_event(struct cht_wc_extcon_data *ext)
id = cht_wc_extcon_get_id(ext, pwrsrc_sts);
if (id == USB_ID_GND) {
+ cht_wc_extcon_enable_charging(ext, false);
cht_wc_extcon_set_otgmode(ext, true);
/* The 5v boost causes a false VBUS / SDP detect, skip */
@@ -249,6 +269,7 @@ static void cht_wc_extcon_pwrsrc_event(struct cht_wc_extcon_data *ext)
}
cht_wc_extcon_set_otgmode(ext, false);
+ cht_wc_extcon_enable_charging(ext, true);
/* Plugged into a host/charger or not connected? */
if (!(pwrsrc_sts & CHT_WC_PWRSRC_VBUS)) {
@@ -302,6 +323,14 @@ static int cht_wc_extcon_sw_control(struct cht_wc_extcon_data *ext, bool enable)
{
int ret, mask, val;
+ val = enable ? 0 : CHT_WC_CHGDISCTRL_FN;
+ ret = regmap_update_bits(ext->regmap, CHT_WC_CHGDISCTRL,
+ CHT_WC_CHGDISCTRL_FN, val);
+ if (ret)
+ dev_err(ext->dev,
+ "Error setting sw control for CHGDIS pin: %d\n",
+ ret);
+
mask = CHT_WC_CHGRCTRL0_SWCONTROL | CHT_WC_CHGRCTRL0_CCSM_OFF;
val = enable ? mask : 0;
ret = regmap_update_bits(ext->regmap, CHT_WC_CHGRCTRL0, mask, val);
@@ -353,7 +382,10 @@ static int cht_wc_extcon_probe(struct platform_device *pdev)
/* Enable sw control */
ret = cht_wc_extcon_sw_control(ext, true);
if (ret)
- return ret;
+ goto disable_sw_control;
+
+ /* Disable charging by external battery charger */
+ cht_wc_extcon_enable_charging(ext, false);
/* Register extcon device */
ret = devm_extcon_dev_register(ext->dev, ext->edev);
--
2.20.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v3 0/2] extcon: Intel Cherry Trail Whiskey Cove PMIC and external charger tweaks
2019-03-03 20:16 [PATCH v3 0/2] extcon: Intel Cherry Trail Whiskey Cove PMIC and external charger tweaks Yauhen Kharuzhy
2019-03-03 20:16 ` [PATCH v3 1/2] extcon-intel-cht-wc: Make charger detection co-existed with OTG host mode Yauhen Kharuzhy
2019-03-03 20:16 ` [PATCH v3 2/2] extcon intel-cht-wc: Enable external charger Yauhen Kharuzhy
@ 2019-03-05 19:22 ` Hans de Goede
2019-03-06 5:07 ` Chanwoo Choi
2 siblings, 1 reply; 5+ messages in thread
From: Hans de Goede @ 2019-03-05 19:22 UTC (permalink / raw)
To: Yauhen Kharuzhy, linux-kernel; +Cc: MyungJoo Ham, Chanwoo Choi, Andy Shevchenko
Hi,
On 03-03-19 21:16, Yauhen Kharuzhy wrote:
> At implementation of charging support for Lenovo Yoga Book (Intel Cherry
> Trail based with Whiskey Cove PMIC), two pitfalls were found:
>
> - for detection of charger type by PMIC, bit 6 in the CHGRCTRL1 register
> should be set in 0 (and set to 1 for Host mode). Pick up its definition
> and logic from from Intel code drop[1];
>
> - "#CHARGE ENABLE" signal of external charger (bq25892) in Yoga Book is
> connected to one of PMIC outputs controlled by CHGDISCTRL register.
> Enable charging at driver initialization. Pick up this from Lenovo's code
> drop[2,3].
>
>
> v3 changes:
> - Don't restore of initial state of CHGDISCTRL and CHGRCTRL0 at exit but
> switch them into HW-controlled mode (as discussed in mailing list);
> - Use regmap_update_bits() instead of regmap_readi()/regmap_write() in
> the cht_wc_extcon_set_otgmode();
> - Coding style and constant names changed as Andy and Hans recommended.
Series looks good to me now, and I've also tested that it does not
cause any charging or 5v boost related regressions on a GPD pocket
laptop, so for the series:
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Tested-by: Hans de Goede <hdegoede@redhat.com>
Regards,
Hans
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3 0/2] extcon: Intel Cherry Trail Whiskey Cove PMIC and external charger tweaks
2019-03-05 19:22 ` [PATCH v3 0/2] extcon: Intel Cherry Trail Whiskey Cove PMIC and external charger tweaks Hans de Goede
@ 2019-03-06 5:07 ` Chanwoo Choi
0 siblings, 0 replies; 5+ messages in thread
From: Chanwoo Choi @ 2019-03-06 5:07 UTC (permalink / raw)
To: Hans de Goede, Yauhen Kharuzhy, linux-kernel
Cc: MyungJoo Ham, Andy Shevchenko
Hi,
On 19. 3. 6. 오전 4:22, Hans de Goede wrote:
> Hi,
>
> On 03-03-19 21:16, Yauhen Kharuzhy wrote:
>> At implementation of charging support for Lenovo Yoga Book (Intel Cherry
>> Trail based with Whiskey Cove PMIC), two pitfalls were found:
>>
>> - for detection of charger type by PMIC, bit 6 in the CHGRCTRL1 register
>> should be set in 0 (and set to 1 for Host mode). Pick up its definition
>> and logic from from Intel code drop[1];
>>
>> - "#CHARGE ENABLE" signal of external charger (bq25892) in Yoga Book is
>> connected to one of PMIC outputs controlled by CHGDISCTRL register.
>> Enable charging at driver initialization. Pick up this from Lenovo's code
>> drop[2,3].
>>
>>
>> v3 changes:
>> - Don't restore of initial state of CHGDISCTRL and CHGRCTRL0 at exit but
>> switch them into HW-controlled mode (as discussed in mailing list);
>> - Use regmap_update_bits() instead of regmap_readi()/regmap_write() in
>> the cht_wc_extcon_set_otgmode();
>> - Coding style and constant names changed as Andy and Hans recommended.
>
> Series looks good to me now, and I've also tested that it does not
> cause any charging or 5v boost related regressions on a GPD pocket
> laptop, so for the series:
>
> Reviewed-by: Hans de Goede <hdegoede@redhat.com>
> Tested-by: Hans de Goede <hdegoede@redhat.com>
>
> Regards,
>
> Hans
>
Applied it. Thanks.
--
Best Regards,
Chanwoo Choi
Samsung Electronics
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-03-06 5:08 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-03 20:16 [PATCH v3 0/2] extcon: Intel Cherry Trail Whiskey Cove PMIC and external charger tweaks Yauhen Kharuzhy
2019-03-03 20:16 ` [PATCH v3 1/2] extcon-intel-cht-wc: Make charger detection co-existed with OTG host mode Yauhen Kharuzhy
2019-03-03 20:16 ` [PATCH v3 2/2] extcon intel-cht-wc: Enable external charger Yauhen Kharuzhy
2019-03-05 19:22 ` [PATCH v3 0/2] extcon: Intel Cherry Trail Whiskey Cove PMIC and external charger tweaks Hans de Goede
2019-03-06 5:07 ` Chanwoo Choi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).