Skip to content

Commit ce648f5

Browse files
wuliangfengrkhuangtao
authored andcommitted
phy: rockchip: rockchip-inno-usb2: check iddig upon resume
Because USB OTG id irq is disabled during system suspend and enabled after resume, so the usb2 phy doesn't notice any id status change upon resume. It may cause two issues: 1. Plug in OTG cable and USB device when system enter suspend, it will fail to detect the OTG cable and USB device after resume. 2. Plug out OTG cable and USB device when system enter suspend, and then connect USB to PC or USB charger after resume, it will fail to detect USB charge type. This patch restores the OTG id status before enter suspend, and check the id status upon resume, and set the extcon state and vbus if id status has changed. Change-Id: Iaca14841cc287e7d82e1cffd64ff18bba86d3ba4 Signed-off-by: William Wu <william.wu@rock-chips.com>
1 parent d08b1af commit ce648f5

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

drivers/phy/rockchip/phy-rockchip-inno-usb2.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ struct rockchip_usb2phy_cfg {
207207
* @port_id: flag for otg port or host port.
208208
* @low_power_en: enable enter low power when suspend.
209209
* @perip_connected: flag for periphyeral connect status.
210+
* @prev_iddig: previous otg port id pin status.
210211
* @suspended: phy suspended flag.
211212
* @utmi_avalid: utmi avalid status usage flag.
212213
* true - use avalid to get vbus status
@@ -236,6 +237,7 @@ struct rockchip_usb2phy_port {
236237
unsigned int port_id;
237238
bool low_power_en;
238239
bool perip_connected;
240+
bool prev_iddig;
239241
bool suspended;
240242
bool utmi_avalid;
241243
bool vbus_attached;
@@ -1546,6 +1548,7 @@ static int rockchip_usb2phy_otg_port_init(struct rockchip_usb2phy *rphy,
15461548
rport->vbus_attached = false;
15471549
rport->vbus_enabled = false;
15481550
rport->perip_connected = false;
1551+
rport->prev_iddig = true;
15491552

15501553
mutex_init(&rport->mutex);
15511554

@@ -2043,6 +2046,8 @@ static int rockchip_usb2phy_pm_suspend(struct device *dev)
20432046
if (rport->port_id == USB2PHY_PORT_OTG &&
20442047
rport->id_irq > 0) {
20452048
mutex_lock(&rport->mutex);
2049+
rport->prev_iddig = property_enabled(rphy,
2050+
&rport->port_cfg->utmi_iddig);
20462051
ret = rockchip_usb2phy_enable_id_irq(rphy, rport,
20472052
false);
20482053
mutex_unlock(&rport->mutex);
@@ -2074,6 +2079,7 @@ static int rockchip_usb2phy_pm_resume(struct device *dev)
20742079
struct rockchip_usb2phy *rphy = dev_get_drvdata(dev);
20752080
struct rockchip_usb2phy_port *rport;
20762081
unsigned int index;
2082+
bool iddig;
20772083
int ret = 0;
20782084

20792085
if (rphy->phy_cfg->phy_tuning)
@@ -2087,6 +2093,8 @@ static int rockchip_usb2phy_pm_resume(struct device *dev)
20872093
if (rport->port_id == USB2PHY_PORT_OTG &&
20882094
rport->id_irq > 0) {
20892095
mutex_lock(&rport->mutex);
2096+
iddig = property_enabled(rphy,
2097+
&rport->port_cfg->utmi_iddig);
20902098
ret = rockchip_usb2phy_enable_id_irq(rphy, rport,
20912099
true);
20922100
mutex_unlock(&rport->mutex);
@@ -2096,20 +2104,17 @@ static int rockchip_usb2phy_pm_resume(struct device *dev)
20962104
return ret;
20972105
}
20982106

2099-
if (!property_enabled(rphy,
2100-
&rport->port_cfg->utmi_iddig) &&
2101-
!extcon_get_cable_state_(rphy->edev,
2102-
EXTCON_USB_HOST)) {
2107+
if (iddig != rport->prev_iddig) {
21032108
dev_dbg(&rport->phy->dev,
2104-
"port power on when resume\n");
2109+
"iddig changed during resume\n");
2110+
rport->prev_iddig = iddig;
21052111
extcon_set_state_sync(rphy->edev,
21062112
EXTCON_USB_HOST,
2107-
true);
2108-
/* Enable VBUS supply */
2113+
!iddig);
21092114
extcon_set_state_sync(rphy->edev,
21102115
EXTCON_USB_VBUS_EN,
2111-
true);
2112-
ret = rockchip_set_vbus_power(rport, true);
2116+
!iddig);
2117+
ret = rockchip_set_vbus_power(rport, !iddig);
21132118
if (ret)
21142119
return ret;
21152120
}

0 commit comments

Comments
 (0)