Lines Matching refs:hsotg

48 #include <linux/platform_data/s3c-hsotg.h>
82 static int dwc2_get_dr_mode(struct dwc2_hsotg *hsotg)
86 hsotg->dr_mode = usb_get_dr_mode(hsotg->dev);
87 if (hsotg->dr_mode == USB_DR_MODE_UNKNOWN)
88 hsotg->dr_mode = USB_DR_MODE_OTG;
90 mode = hsotg->dr_mode;
92 if (dwc2_hw_is_device(hsotg)) {
94 dev_err(hsotg->dev,
99 } else if (dwc2_hw_is_host(hsotg)) {
101 dev_err(hsotg->dev,
113 if (mode != hsotg->dr_mode) {
114 dev_warn(hsotg->dev,
118 hsotg->dr_mode = mode;
124 static int __dwc2_lowlevel_hw_enable(struct dwc2_hsotg *hsotg)
126 struct platform_device *pdev = to_platform_device(hsotg->dev);
129 ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->supplies),
130 hsotg->supplies);
134 if (hsotg->clk) {
135 ret = clk_prepare_enable(hsotg->clk);
140 if (hsotg->uphy) {
141 ret = usb_phy_init(hsotg->uphy);
142 } else if (hsotg->plat && hsotg->plat->phy_init) {
143 ret = hsotg->plat->phy_init(pdev, hsotg->plat->phy_type);
145 ret = phy_init(hsotg->phy);
147 ret = phy_power_on(hsotg->phy);
155 * @hsotg: The driver state
160 int dwc2_lowlevel_hw_enable(struct dwc2_hsotg *hsotg)
162 int ret = __dwc2_lowlevel_hw_enable(hsotg);
165 hsotg->ll_hw_enabled = true;
169 static int __dwc2_lowlevel_hw_disable(struct dwc2_hsotg *hsotg)
171 struct platform_device *pdev = to_platform_device(hsotg->dev);
174 if (hsotg->uphy) {
175 usb_phy_shutdown(hsotg->uphy);
176 } else if (hsotg->plat && hsotg->plat->phy_exit) {
177 ret = hsotg->plat->phy_exit(pdev, hsotg->plat->phy_type);
179 ret = phy_power_off(hsotg->phy);
181 ret = phy_exit(hsotg->phy);
186 if (hsotg->clk)
187 clk_disable_unprepare(hsotg->clk);
189 return regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies), hsotg->supplies);
194 * @hsotg: The driver state
199 int dwc2_lowlevel_hw_disable(struct dwc2_hsotg *hsotg)
201 int ret = __dwc2_lowlevel_hw_disable(hsotg);
204 hsotg->ll_hw_enabled = false;
208 static int dwc2_lowlevel_hw_init(struct dwc2_hsotg *hsotg)
212 hsotg->reset = devm_reset_control_get_optional(hsotg->dev, "dwc2");
213 if (IS_ERR(hsotg->reset)) {
214 ret = PTR_ERR(hsotg->reset);
215 dev_err(hsotg->dev, "error getting reset control %d\n", ret);
219 reset_control_deassert(hsotg->reset);
221 hsotg->reset_ecc = devm_reset_control_get_optional(hsotg->dev, "dwc2-ecc");
222 if (IS_ERR(hsotg->reset_ecc)) {
223 ret = PTR_ERR(hsotg->reset_ecc);
224 dev_err(hsotg->dev, "error getting reset control for ecc %d\n", ret);
228 reset_control_deassert(hsotg->reset_ecc);
234 hsotg->phy = devm_phy_get(hsotg->dev, "usb2-phy");
235 if (IS_ERR(hsotg->phy)) {
236 ret = PTR_ERR(hsotg->phy);
240 hsotg->phy = NULL;
245 dev_err(hsotg->dev, "error getting phy %d\n", ret);
250 if (!hsotg->phy) {
251 hsotg->uphy = devm_usb_get_phy(hsotg->dev, USB_PHY_TYPE_USB2);
252 if (IS_ERR(hsotg->uphy)) {
253 ret = PTR_ERR(hsotg->uphy);
257 hsotg->uphy = NULL;
262 dev_err(hsotg->dev, "error getting usb phy %d\n",
269 hsotg->plat = dev_get_platdata(hsotg->dev);
272 hsotg->clk = devm_clk_get_optional(hsotg->dev, "otg");
273 if (IS_ERR(hsotg->clk)) {
274 dev_err(hsotg->dev, "cannot get otg clock\n");
275 return PTR_ERR(hsotg->clk);
279 for (i = 0; i < ARRAY_SIZE(hsotg->supplies); i++)
280 hsotg->supplies[i].supply = dwc2_hsotg_supply_names[i];
282 ret = devm_regulator_bulk_get(hsotg->dev, ARRAY_SIZE(hsotg->supplies),
283 hsotg->supplies);
286 dev_err(hsotg->dev, "failed to request supplies: %d\n",
306 struct dwc2_hsotg *hsotg = platform_get_drvdata(dev);
308 dwc2_debugfs_exit(hsotg);
309 if (hsotg->hcd_enabled)
310 dwc2_hcd_remove(hsotg);
311 if (hsotg->gadget_enabled)
312 dwc2_hsotg_remove(hsotg);
314 dwc2_drd_exit(hsotg);
316 if (hsotg->params.activate_stm_id_vb_detection)
317 regulator_disable(hsotg->usb33d);
319 if (hsotg->ll_hw_enabled)
320 dwc2_lowlevel_hw_disable(hsotg);
322 reset_control_assert(hsotg->reset);
323 reset_control_assert(hsotg->reset_ecc);
342 struct dwc2_hsotg *hsotg = platform_get_drvdata(dev);
344 dwc2_disable_global_interrupts(hsotg);
345 synchronize_irq(hsotg->irq);
351 * @hsotg: Programming view of the DWC_otg controller.
353 static bool dwc2_check_core_endianness(struct dwc2_hsotg *hsotg)
357 snpsid = ioread32(hsotg->regs + GSNPSID);
368 * @hsotg: Programming view of the DWC_otg controller
371 int dwc2_check_core_version(struct dwc2_hsotg *hsotg)
373 struct dwc2_hw_params *hw = &hsotg->hw_params;
381 hw->snpsid = dwc2_readl(hsotg, GSNPSID);
385 dev_err(hsotg->dev, "Bad value for GSNPSID: 0x%08x\n",
390 dev_dbg(hsotg->dev, "Core Release: %1x.%1x%1x%1x (snpsid=%x)\n",
410 struct dwc2_hsotg *hsotg;
414 hsotg = devm_kzalloc(&dev->dev, sizeof(*hsotg), GFP_KERNEL);
415 if (!hsotg)
418 hsotg->dev = &dev->dev;
431 hsotg->regs = devm_platform_get_and_ioremap_resource(dev, 0, &res);
432 if (IS_ERR(hsotg->regs))
433 return PTR_ERR(hsotg->regs);
436 (unsigned long)res->start, hsotg->regs);
438 retval = dwc2_lowlevel_hw_init(hsotg);
442 spin_lock_init(&hsotg->lock);
444 hsotg->irq = platform_get_irq(dev, 0);
445 if (hsotg->irq < 0)
446 return hsotg->irq;
448 dev_dbg(hsotg->dev, "registering common handler for irq%d\n",
449 hsotg->irq);
450 retval = devm_request_irq(hsotg->dev, hsotg->irq,
452 dev_name(hsotg->dev), hsotg);
456 hsotg->vbus_supply = devm_regulator_get_optional(hsotg->dev, "vbus");
457 if (IS_ERR(hsotg->vbus_supply)) {
458 retval = PTR_ERR(hsotg->vbus_supply);
459 hsotg->vbus_supply = NULL;
464 retval = dwc2_lowlevel_hw_enable(hsotg);
468 hsotg->needs_byte_swap = dwc2_check_core_endianness(hsotg);
470 retval = dwc2_get_dr_mode(hsotg);
474 hsotg->need_phy_for_wake =
482 retval = dwc2_check_core_version(hsotg);
490 retval = dwc2_core_reset(hsotg, false);
495 retval = dwc2_get_hwparams(hsotg);
504 dwc2_force_dr_mode(hsotg);
506 retval = dwc2_init_params(hsotg);
510 if (hsotg->params.activate_stm_id_vb_detection) {
513 hsotg->usb33d = devm_regulator_get(hsotg->dev, "usb33d");
514 if (IS_ERR(hsotg->usb33d)) {
515 retval = PTR_ERR(hsotg->usb33d);
517 dev_err(hsotg->dev,
522 retval = regulator_enable(hsotg->usb33d);
524 dev_err(hsotg->dev,
529 ggpio = dwc2_readl(hsotg, GGPIO);
532 dwc2_writel(hsotg, ggpio, GGPIO);
538 retval = dwc2_drd_init(hsotg);
541 dev_err(hsotg->dev, "failed to initialize dual-role\n");
545 if (hsotg->dr_mode != USB_DR_MODE_HOST) {
546 retval = dwc2_gadget_init(hsotg);
549 hsotg->gadget_enabled = 1;
557 if (hsotg->need_phy_for_wake)
560 hsotg->reset_phy_on_wake =
563 if (hsotg->reset_phy_on_wake && !hsotg->phy) {
564 dev_warn(hsotg->dev,
566 hsotg->reset_phy_on_wake = false;
569 if (hsotg->dr_mode != USB_DR_MODE_PERIPHERAL) {
570 retval = dwc2_hcd_init(hsotg);
572 if (hsotg->gadget_enabled)
573 dwc2_hsotg_remove(hsotg);
576 hsotg->hcd_enabled = 1;
579 platform_set_drvdata(dev, hsotg);
580 hsotg->hibernated = 0;
582 dwc2_debugfs_init(hsotg);
585 if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL)
586 dwc2_lowlevel_hw_disable(hsotg);
591 if (hsotg->gadget_enabled) {
592 retval = usb_add_gadget_udc(hsotg->dev, &hsotg->gadget);
594 hsotg->gadget.udc = NULL;
595 dwc2_hsotg_remove(hsotg);
605 dwc2_debugfs_exit(hsotg);
606 if (hsotg->hcd_enabled)
607 dwc2_hcd_remove(hsotg);
610 dwc2_drd_exit(hsotg);
613 if (hsotg->params.activate_stm_id_vb_detection)
614 regulator_disable(hsotg->usb33d);
616 if (hsotg->ll_hw_enabled)
617 dwc2_lowlevel_hw_disable(hsotg);