Skip to contentSkip to conversation

extcon: Intel Cherry Trail Whiskey Cove PMIC and external charger tweaks

PATCH Applied Yauhen Kharuzhy 3 participants 5 messages Mar 3, 2019 – Mar 6, 2019 External connector subsystem (extcon)

lore
Share & tools
lore
#0 lore raw

v3 cover extcon: Intel Cherry Trail Whiskey Cove PMIC and external charger tweaks

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(-)
Signature · 1 line
2.20.1
#2 lore raw

PATCH v3 2/2 extcon intel-cht-wc: Enable external charger

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).

---
 drivers/extcon/extcon-intel-cht-wc.c | 34 +++++++++++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)
drivers/extcon/extcon-intel-cht-wc.c +33 -1
index 8d20e913536f..53b28ecc4ad1 100644
@@ -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);
Signature · 1 line
2.20.1
#1 lore raw

PATCH v3 1/2 extcon-intel-cht-wc: Make charger detection co-existed with OTG host mode

In reply to 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.

---
 drivers/extcon/extcon-intel-cht-wc.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)
drivers/extcon/extcon-intel-cht-wc.c +25 -1
index 5ef215297101..8d20e913536f 100644
@@ -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 */
Signature · 1 line
2.20.1
Reviewed-by Tested-by on the v3 series
#3 lore raw
In reply to Yauhen Kharuzhy

Hi,

Quoted 13 lines · 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].

Quoted 6 lines

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:

Regards,

Hans

maintainer Applied
#4 lore raw

Hi,

Quoted 27 lines · Hans de Goede

Hi,

Quoted 13 lines · 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].

Quoted 6 lines

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:

Quoted 7 lines

Regards,

Hans

Applied it. Thanks.

Signature · 3 lines
Best Regards,
Chanwoo Choi
Samsung Electronics