Skip to content

Commit 7f73786

Browse files
tmlindsre
authored andcommitted
power: supply: cpcap-charger: Enable vbus boost voltage
We are currently not enabling VBUS boost for cpcap when in host mode. This means the VBUS is fed at the battery voltage level, which can cause flakeyness enumerating devices. Looks like the boost control for VBUS is CPCAP_BIT_VBUS_SWITCH that we must enable in the charger for nice 4.92 V VBUS output. And looks like we must not use the STBY pin enabling but must instead use manual VBUS control in phy-cpcap-usb. We want to do this in cpcap_charger_vbus_work() and also set a flag for feeding_vbus to avoid races between USB detection and charger detection, and disable charging if feeding_vbus is set. Cc: Jacopo Mondi <[email protected]> Cc: Kishon Vijay Abraham I <[email protected]> Cc: Marcel Partap <[email protected]> Cc: Merlijn Wajer <[email protected]> Cc: Michael Scott <[email protected]> Cc: NeKit <[email protected]> Cc: Pavel Machek <[email protected]> Cc: Sebastian Reichel <[email protected]> Signed-off-by: Tony Lindgren <[email protected]> Signed-off-by: Sebastian Reichel <[email protected]>
1 parent 7cfd33d commit 7f73786

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

drivers/phy/motorola/phy-cpcap-usb.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,16 +231,18 @@ static void cpcap_usb_detect(struct work_struct *work)
231231
goto out_err;
232232

233233
error = regmap_update_bits(ddata->reg, CPCAP_REG_USBC3,
234-
CPCAP_BIT_VBUSSTBY_EN,
235-
CPCAP_BIT_VBUSSTBY_EN);
234+
CPCAP_BIT_VBUSSTBY_EN |
235+
CPCAP_BIT_VBUSEN_SPI,
236+
CPCAP_BIT_VBUSEN_SPI);
236237
if (error)
237238
goto out_err;
238239

239240
return;
240241
}
241242

242243
error = regmap_update_bits(ddata->reg, CPCAP_REG_USBC3,
243-
CPCAP_BIT_VBUSSTBY_EN, 0);
244+
CPCAP_BIT_VBUSSTBY_EN |
245+
CPCAP_BIT_VBUSEN_SPI, 0);
244246
if (error)
245247
goto out_err;
246248

drivers/power/supply/cpcap-charger.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@
108108
#define CPCAP_REG_CRM_ICHRG_1A596 CPCAP_REG_CRM_ICHRG(0xe)
109109
#define CPCAP_REG_CRM_ICHRG_NO_LIMIT CPCAP_REG_CRM_ICHRG(0xf)
110110

111+
/* CPCAP_REG_VUSBC register bits needed for VBUS */
112+
#define CPCAP_BIT_VBUS_SWITCH BIT(0) /* VBUS boost to 5V */
113+
111114
enum {
112115
CPCAP_CHARGER_IIO_BATTDET,
113116
CPCAP_CHARGER_IIO_VOLTAGE,
@@ -130,7 +133,8 @@ struct cpcap_charger_ddata {
130133
struct power_supply *usb;
131134

132135
struct phy_companion comparator; /* For USB VBUS */
133-
bool vbus_enabled;
136+
unsigned int vbus_enabled:1;
137+
unsigned int feeding_vbus:1;
134138
atomic_t active;
135139

136140
int status;
@@ -325,7 +329,6 @@ static bool cpcap_charger_vbus_valid(struct cpcap_charger_ddata *ddata)
325329
}
326330

327331
/* VBUS control functions for the USB PHY companion */
328-
329332
static void cpcap_charger_vbus_work(struct work_struct *work)
330333
{
331334
struct cpcap_charger_ddata *ddata;
@@ -343,26 +346,39 @@ static void cpcap_charger_vbus_work(struct work_struct *work)
343346
return;
344347
}
345348

349+
ddata->feeding_vbus = true;
346350
cpcap_charger_set_cable_path(ddata, false);
347351
cpcap_charger_set_inductive_path(ddata, false);
348352

349353
error = cpcap_charger_set_state(ddata, 0, 0, 0);
350354
if (error)
351355
goto out_err;
352356

357+
error = regmap_update_bits(ddata->reg, CPCAP_REG_VUSBC,
358+
CPCAP_BIT_VBUS_SWITCH,
359+
CPCAP_BIT_VBUS_SWITCH);
360+
if (error)
361+
goto out_err;
362+
353363
error = regmap_update_bits(ddata->reg, CPCAP_REG_CRM,
354364
CPCAP_REG_CRM_RVRSMODE,
355365
CPCAP_REG_CRM_RVRSMODE);
356366
if (error)
357367
goto out_err;
358368
} else {
369+
error = regmap_update_bits(ddata->reg, CPCAP_REG_VUSBC,
370+
CPCAP_BIT_VBUS_SWITCH, 0);
371+
if (error)
372+
goto out_err;
373+
359374
error = regmap_update_bits(ddata->reg, CPCAP_REG_CRM,
360375
CPCAP_REG_CRM_RVRSMODE, 0);
361376
if (error)
362377
goto out_err;
363378

364379
cpcap_charger_set_cable_path(ddata, true);
365380
cpcap_charger_set_inductive_path(ddata, true);
381+
ddata->feeding_vbus = false;
366382
}
367383

368384
return;
@@ -431,7 +447,8 @@ static void cpcap_usb_detect(struct work_struct *work)
431447
if (error)
432448
return;
433449

434-
if (cpcap_charger_vbus_valid(ddata) && s.chrgcurr1) {
450+
if (!ddata->feeding_vbus && cpcap_charger_vbus_valid(ddata) &&
451+
s.chrgcurr1) {
435452
int max_current;
436453

437454
if (cpcap_charger_battery_found(ddata))

0 commit comments

Comments
 (0)