aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Blumenstingl <martin.blumenstingl@googlemail.com>2018-04-18 15:39:48 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-04-22 09:01:30 -0400
commitf0e36d478faf37fb26413b2530d04e6b30af3834 (patch)
treeb8c7650c4f07cd85fc1daaf1397bf07cc052df22
parent63cb03f5c11eef2c08b5812f4533ba87cf778fa8 (diff)
usb: core: use phy_exit during suspend if wake up is not supported
If the USB controller can wake up the system (which is the case for example with the Mediatek USB3 IP) then we must not call phy_exit during suspend to ensure that the USB controller doesn't have to re-enumerate the devices during resume. However, if the USB controller cannot wake up the system (which is the case for example on various TI platforms using a dwc3 controller) then we must call phy_exit during suspend. Otherwise the PHY driver keeps the clocks enabled, which prevents the system from reaching the lowest power levels in the suspend state. Solve this by introducing two new functions in the PHY wrapper which are dedicated to the suspend and resume handling. If the controller can wake up the system the new usb_phy_roothub_suspend function will simply call usb_phy_roothub_power_off. However, if wake up is not supported by the controller it will also call usb_phy_roothub_exit. The also new usb_phy_roothub_resume function takes care of calling usb_phy_roothub_init (if the controller can't wake up the system) in addition to usb_phy_roothub_power_on. Fixes: 07dbff0ddbd86c ("usb: core: add a wrapper for the USB PHYs on the HCD") Fixes: 178a0bce05cbc1 ("usb: core: hcd: integrate the PHY wrapper into the HCD core") Reported-by: Roger Quadros <rogerq@ti.com> Suggested-by: Roger Quadros <rogerq@ti.com> Suggested-by: Chunfeng Yun <chunfeng.yun@mediatek.com> Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com> Tested-by: Chunfeng Yun <chunfeng.yun@mediatek.com> Reviewed-by: Roger Quadros <rogerq@ti.com> Tested-by: Keerthy <j-keerthy@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/usb/core/hcd.c8
-rw-r--r--drivers/usb/core/phy.c35
-rw-r--r--drivers/usb/core/phy.h5
3 files changed, 45 insertions, 3 deletions
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index f0e5f4d875d8..0a42c5df3c0f 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -2262,7 +2262,8 @@ int hcd_bus_suspend(struct usb_device *rhdev, pm_message_t msg)
2262 hcd->state = HC_STATE_SUSPENDED; 2262 hcd->state = HC_STATE_SUSPENDED;
2263 2263
2264 if (!PMSG_IS_AUTO(msg)) 2264 if (!PMSG_IS_AUTO(msg))
2265 usb_phy_roothub_power_off(hcd->phy_roothub); 2265 usb_phy_roothub_suspend(hcd->self.sysdev,
2266 hcd->phy_roothub);
2266 2267
2267 /* Did we race with a root-hub wakeup event? */ 2268 /* Did we race with a root-hub wakeup event? */
2268 if (rhdev->do_remote_wakeup) { 2269 if (rhdev->do_remote_wakeup) {
@@ -2302,7 +2303,8 @@ int hcd_bus_resume(struct usb_device *rhdev, pm_message_t msg)
2302 } 2303 }
2303 2304
2304 if (!PMSG_IS_AUTO(msg)) { 2305 if (!PMSG_IS_AUTO(msg)) {
2305 status = usb_phy_roothub_power_on(hcd->phy_roothub); 2306 status = usb_phy_roothub_resume(hcd->self.sysdev,
2307 hcd->phy_roothub);
2306 if (status) 2308 if (status)
2307 return status; 2309 return status;
2308 } 2310 }
@@ -2344,7 +2346,7 @@ int hcd_bus_resume(struct usb_device *rhdev, pm_message_t msg)
2344 } 2346 }
2345 } else { 2347 } else {
2346 hcd->state = old_state; 2348 hcd->state = old_state;
2347 usb_phy_roothub_power_off(hcd->phy_roothub); 2349 usb_phy_roothub_suspend(hcd->self.sysdev, hcd->phy_roothub);
2348 dev_dbg(&rhdev->dev, "bus %s fail, err %d\n", 2350 dev_dbg(&rhdev->dev, "bus %s fail, err %d\n",
2349 "resume", status); 2351 "resume", status);
2350 if (status != -ESHUTDOWN) 2352 if (status != -ESHUTDOWN)
diff --git a/drivers/usb/core/phy.c b/drivers/usb/core/phy.c
index 44f008cda7a8..a39d9bb26a4f 100644
--- a/drivers/usb/core/phy.c
+++ b/drivers/usb/core/phy.c
@@ -157,3 +157,38 @@ void usb_phy_roothub_power_off(struct usb_phy_roothub *phy_roothub)
157 phy_power_off(roothub_entry->phy); 157 phy_power_off(roothub_entry->phy);
158} 158}
159EXPORT_SYMBOL_GPL(usb_phy_roothub_power_off); 159EXPORT_SYMBOL_GPL(usb_phy_roothub_power_off);
160
161int usb_phy_roothub_suspend(struct device *controller_dev,
162 struct usb_phy_roothub *phy_roothub)
163{
164 usb_phy_roothub_power_off(phy_roothub);
165
166 /* keep the PHYs initialized so the device can wake up the system */
167 if (device_may_wakeup(controller_dev))
168 return 0;
169
170 return usb_phy_roothub_exit(phy_roothub);
171}
172EXPORT_SYMBOL_GPL(usb_phy_roothub_suspend);
173
174int usb_phy_roothub_resume(struct device *controller_dev,
175 struct usb_phy_roothub *phy_roothub)
176{
177 int err;
178
179 /* if the device can't wake up the system _exit was called */
180 if (!device_may_wakeup(controller_dev)) {
181 err = usb_phy_roothub_init(phy_roothub);
182 if (err)
183 return err;
184 }
185
186 err = usb_phy_roothub_power_on(phy_roothub);
187
188 /* undo _init if _power_on failed */
189 if (err && !device_may_wakeup(controller_dev))
190 usb_phy_roothub_exit(phy_roothub);
191
192 return err;
193}
194EXPORT_SYMBOL_GPL(usb_phy_roothub_resume);
diff --git a/drivers/usb/core/phy.h b/drivers/usb/core/phy.h
index eb31253201ad..605555901d44 100644
--- a/drivers/usb/core/phy.h
+++ b/drivers/usb/core/phy.h
@@ -7,3 +7,8 @@ int usb_phy_roothub_exit(struct usb_phy_roothub *phy_roothub);
7 7
8int usb_phy_roothub_power_on(struct usb_phy_roothub *phy_roothub); 8int usb_phy_roothub_power_on(struct usb_phy_roothub *phy_roothub);
9void usb_phy_roothub_power_off(struct usb_phy_roothub *phy_roothub); 9void usb_phy_roothub_power_off(struct usb_phy_roothub *phy_roothub);
10
11int usb_phy_roothub_suspend(struct device *controller_dev,
12 struct usb_phy_roothub *phy_roothub);
13int usb_phy_roothub_resume(struct device *controller_dev,
14 struct usb_phy_roothub *phy_roothub);