diff --git a/drivers/usb/pd/policy_engine.c b/drivers/usb/pd/policy_engine.c index 99f271551ecc..2839abb1d86c 100644 --- a/drivers/usb/pd/policy_engine.c +++ b/drivers/usb/pd/policy_engine.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2016-2020, The Linux Foundation. All rights reserved. + * Copyright (c) 2022, Qualcomm Innovation Center, Inc. All rights reserved. */ #include @@ -3724,6 +3725,7 @@ static void psy_changed_notifier_work(struct work_struct *w) union power_supply_propval val; enum power_supply_typec_mode typec_mode; int ret; + int usb_extcon_state; ret = usbpd_get_psy_iio_property(pd, POWER_SUPPLY_PROP_TYPEC_MODE, &val); @@ -3794,8 +3796,28 @@ static void psy_changed_notifier_work(struct work_struct *w) return; } - if (pd->typec_mode == typec_mode) + if (pd->typec_mode == typec_mode) { + if (!((pd->current_dr == DR_NONE) || (pd->current_dr == DR_UFP))) + return; + + usb_extcon_state = extcon_get_state(pd->extcon, EXTCON_USB); + + if (usb_extcon_state == 0) { + ret = usbpd_get_psy_iio_property(pd, POWER_SUPPLY_PROP_REAL_TYPE, + &val); + if (ret) { + usbpd_err(&pd->dev, "Unable to read USB PROP_REAL_TYPE: %d\n", + ret); + return; + } + + if (val.intval == POWER_SUPPLY_TYPE_USB || + val.intval == POWER_SUPPLY_TYPE_USB_CDP || + val.intval == QTI_POWER_SUPPLY_TYPE_USB_FLOAT) + queue_work(pd->wq, &pd->start_periph_work); + } return; + } pd->typec_mode = typec_mode;