aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/dwc2/platform.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/dwc2/platform.c')
-rw-r--r--drivers/usb/dwc2/platform.c81
1 files changed, 53 insertions, 28 deletions
diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c
index e61d773cf65e..39c1cbf0e75d 100644
--- a/drivers/usb/dwc2/platform.c
+++ b/drivers/usb/dwc2/platform.c
@@ -125,9 +125,11 @@ static int __dwc2_lowlevel_hw_enable(struct dwc2_hsotg *hsotg)
125 if (ret) 125 if (ret)
126 return ret; 126 return ret;
127 127
128 ret = clk_prepare_enable(hsotg->clk); 128 if (hsotg->clk) {
129 if (ret) 129 ret = clk_prepare_enable(hsotg->clk);
130 return ret; 130 if (ret)
131 return ret;
132 }
131 133
132 if (hsotg->uphy) 134 if (hsotg->uphy)
133 ret = usb_phy_init(hsotg->uphy); 135 ret = usb_phy_init(hsotg->uphy);
@@ -175,7 +177,8 @@ static int __dwc2_lowlevel_hw_disable(struct dwc2_hsotg *hsotg)
175 if (ret) 177 if (ret)
176 return ret; 178 return ret;
177 179
178 clk_disable_unprepare(hsotg->clk); 180 if (hsotg->clk)
181 clk_disable_unprepare(hsotg->clk);
179 182
180 ret = regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies), 183 ret = regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies),
181 hsotg->supplies); 184 hsotg->supplies);
@@ -212,14 +215,41 @@ static int dwc2_lowlevel_hw_init(struct dwc2_hsotg *hsotg)
212 */ 215 */
213 hsotg->phy = devm_phy_get(hsotg->dev, "usb2-phy"); 216 hsotg->phy = devm_phy_get(hsotg->dev, "usb2-phy");
214 if (IS_ERR(hsotg->phy)) { 217 if (IS_ERR(hsotg->phy)) {
215 hsotg->phy = NULL; 218 ret = PTR_ERR(hsotg->phy);
219 switch (ret) {
220 case -ENODEV:
221 case -ENOSYS:
222 hsotg->phy = NULL;
223 break;
224 case -EPROBE_DEFER:
225 return ret;
226 default:
227 dev_err(hsotg->dev, "error getting phy %d\n", ret);
228 return ret;
229 }
230 }
231
232 if (!hsotg->phy) {
216 hsotg->uphy = devm_usb_get_phy(hsotg->dev, USB_PHY_TYPE_USB2); 233 hsotg->uphy = devm_usb_get_phy(hsotg->dev, USB_PHY_TYPE_USB2);
217 if (IS_ERR(hsotg->uphy)) 234 if (IS_ERR(hsotg->uphy)) {
218 hsotg->uphy = NULL; 235 ret = PTR_ERR(hsotg->uphy);
219 else 236 switch (ret) {
220 hsotg->plat = dev_get_platdata(hsotg->dev); 237 case -ENODEV:
238 case -ENXIO:
239 hsotg->uphy = NULL;
240 break;
241 case -EPROBE_DEFER:
242 return ret;
243 default:
244 dev_err(hsotg->dev, "error getting usb phy %d\n",
245 ret);
246 return ret;
247 }
248 }
221 } 249 }
222 250
251 hsotg->plat = dev_get_platdata(hsotg->dev);
252
223 if (hsotg->phy) { 253 if (hsotg->phy) {
224 /* 254 /*
225 * If using the generic PHY framework, check if the PHY bus 255 * If using the generic PHY framework, check if the PHY bus
@@ -229,11 +259,6 @@ static int dwc2_lowlevel_hw_init(struct dwc2_hsotg *hsotg)
229 hsotg->phyif = GUSBCFG_PHYIF8; 259 hsotg->phyif = GUSBCFG_PHYIF8;
230 } 260 }
231 261
232 if (!hsotg->phy && !hsotg->uphy && !hsotg->plat) {
233 dev_err(hsotg->dev, "no platform data or transceiver defined\n");
234 return -EPROBE_DEFER;
235 }
236
237 /* Clock */ 262 /* Clock */
238 hsotg->clk = devm_clk_get(hsotg->dev, "otg"); 263 hsotg->clk = devm_clk_get(hsotg->dev, "otg");
239 if (IS_ERR(hsotg->clk)) { 264 if (IS_ERR(hsotg->clk)) {
@@ -342,20 +367,6 @@ static int dwc2_driver_probe(struct platform_device *dev)
342 if (retval) 367 if (retval)
343 return retval; 368 return retval;
344 369
345 irq = platform_get_irq(dev, 0);
346 if (irq < 0) {
347 dev_err(&dev->dev, "missing IRQ resource\n");
348 return irq;
349 }
350
351 dev_dbg(hsotg->dev, "registering common handler for irq%d\n",
352 irq);
353 retval = devm_request_irq(hsotg->dev, irq,
354 dwc2_handle_common_intr, IRQF_SHARED,
355 dev_name(hsotg->dev), hsotg);
356 if (retval)
357 return retval;
358
359 res = platform_get_resource(dev, IORESOURCE_MEM, 0); 370 res = platform_get_resource(dev, IORESOURCE_MEM, 0);
360 hsotg->regs = devm_ioremap_resource(&dev->dev, res); 371 hsotg->regs = devm_ioremap_resource(&dev->dev, res);
361 if (IS_ERR(hsotg->regs)) 372 if (IS_ERR(hsotg->regs))
@@ -390,6 +401,20 @@ static int dwc2_driver_probe(struct platform_device *dev)
390 401
391 dwc2_set_all_params(hsotg->core_params, -1); 402 dwc2_set_all_params(hsotg->core_params, -1);
392 403
404 irq = platform_get_irq(dev, 0);
405 if (irq < 0) {
406 dev_err(&dev->dev, "missing IRQ resource\n");
407 return irq;
408 }
409
410 dev_dbg(hsotg->dev, "registering common handler for irq%d\n",
411 irq);
412 retval = devm_request_irq(hsotg->dev, irq,
413 dwc2_handle_common_intr, IRQF_SHARED,
414 dev_name(hsotg->dev), hsotg);
415 if (retval)
416 return retval;
417
393 retval = dwc2_lowlevel_hw_enable(hsotg); 418 retval = dwc2_lowlevel_hw_enable(hsotg);
394 if (retval) 419 if (retval)
395 return retval; 420 return retval;