Skip to content

Commit

Permalink
tcpci_max77759: Add retries for OVP reset
Browse files Browse the repository at this point in the history
Some chargers may delay its Vbus rampup time upto 1.5 second. Add the
retry mechanism to periodically check the Vbus every 250 ms for 8
times.

Bug: 238946074
Signed-off-by: Kyle Tso <[email protected]>
Change-Id: I3f263c0608bbdb0a01415d55590070e4a2e9182c
  • Loading branch information
kyletsoadl authored and TreeHugger Robot committed Jul 22, 2022
1 parent 4a2fcdc commit b6e2ec8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
24 changes: 18 additions & 6 deletions drivers/usb/typec/tcpm/google/tcpci_max77759.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@

#define PD_ACTIVITY_TIMEOUT_MS 10000
#define VSAFE0V_DEBOUNCE_MS 15
/* tCCDebounce max 200ms + tVbusON max 275ms */
#define VBUS_RAMPUP_TIMEOUT_MS 475
#define VBUS_RAMPUP_TIMEOUT_MS 250
#define VBUS_RAMPUP_MAX_RETRY 8

#define GBMS_MODE_VOTABLE "CHARGER_MODE"

Expand Down Expand Up @@ -988,8 +988,10 @@ static void process_power_status(struct max77759_plat *chip)
logbuffer_log(chip->log, "[%s]: vbus_present %d", __func__, chip->vbus_present);
tcpm_vbus_change(tcpci->port);

if (chip->quick_ramp_vbus_ovp && chip->vbus_present)
if (chip->quick_ramp_vbus_ovp && chip->vbus_present) {
kthread_cancel_delayed_work_sync(&chip->reset_ovp_work);
chip->reset_ovp_retry = 0;
}

/* TODO: remove this cc event b/211341677 */
if (!strncmp(boot_mode_string, "charger", strlen("charger")) && chip->vbus_present) {
Expand Down Expand Up @@ -1135,8 +1137,16 @@ static void reset_ovp_work(struct kthread_work *work)
gpio_set_value_cansleep(chip->in_switch_gpio, !chip->in_switch_gpio_active_high);
mdelay(10);
gpio_set_value_cansleep(chip->in_switch_gpio, chip->in_switch_gpio_active_high);
chip->reset_ovp_retry++;

logbuffer_log(chip->log, "ovp reset done [%d]", chip->reset_ovp_retry);

if (chip->reset_ovp_retry < VBUS_RAMPUP_MAX_RETRY)
kthread_mod_delayed_work(chip->wq, &chip->reset_ovp_work,
msecs_to_jiffies(VBUS_RAMPUP_TIMEOUT_MS));
else
chip->reset_ovp_retry = 0;

logbuffer_log(chip->log, "ovp reset done");
}

static enum typec_cc_status tcpci_to_typec_cc(unsigned int cc, bool sink)
Expand Down Expand Up @@ -1186,11 +1196,13 @@ static void max77759_cache_cc(struct max77759_plat *chip)
* is back to Open as we won't expect that Vbus is coming.
*/
if (chip->quick_ramp_vbus_ovp) {
if (cc_open_or_toggling(chip->cc1, chip->cc2) && port_is_sink(cc1, cc2))
if (cc_open_or_toggling(chip->cc1, chip->cc2) && port_is_sink(cc1, cc2)) {
kthread_mod_delayed_work(chip->wq, &chip->reset_ovp_work,
msecs_to_jiffies(VBUS_RAMPUP_TIMEOUT_MS));
else if (cc_open_or_toggling(cc1, cc2))
} else if (cc_open_or_toggling(cc1, cc2)) {
kthread_cancel_delayed_work_sync(&chip->reset_ovp_work);
chip->reset_ovp_retry = 0;
}
}

logbuffer_log(chip->log, "cc1: %u -> %u cc2: %u -> %u", chip->cc1, cc1, chip->cc2, cc2);
Expand Down
1 change: 1 addition & 0 deletions drivers/usb/typec/tcpm/google/tcpci_max77759.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ struct max77759_plat {
unsigned int limit_sink_current;
/* Indicate that the Vbus OVP is restricted to quick ramp-up time for incoming voltage. */
bool quick_ramp_vbus_ovp;
int reset_ovp_retry;
/* Set true to vote "limit_accessory_current" on USB ICL */
bool limit_accessory_enable;
/* uA */
Expand Down

0 comments on commit b6e2ec8

Please sign in to comment.