Lines Matching +full:omap +full:- +full:usb2

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * omap-usb2.c - USB PHY, talking to USB controller on TI SoCs.
5 * Copyright (C) 2012-2020 Texas Instruments Incorporated - http://www.ti.com
93 * omap_usb2_set_comparator() - links the comparator present in the system with this phy
108 return -ENODEV; in omap_usb2_set_comparator()
111 phy->comparator = comparator; in omap_usb2_set_comparator()
118 struct omap_usb *phy = phy_to_omapusb(otg->usb_phy); in omap_usb_set_vbus()
120 if (!phy->comparator || !phy->comparator->set_vbus) in omap_usb_set_vbus()
121 return -ENODEV; in omap_usb_set_vbus()
123 return phy->comparator->set_vbus(phy->comparator, enabled); in omap_usb_set_vbus()
128 struct omap_usb *phy = phy_to_omapusb(otg->usb_phy); in omap_usb_start_srp()
130 if (!phy->comparator || !phy->comparator->start_srp) in omap_usb_start_srp()
131 return -ENODEV; in omap_usb_start_srp()
133 return phy->comparator->start_srp(phy->comparator); in omap_usb_start_srp()
138 otg->host = host; in omap_usb_set_host()
140 otg->state = OTG_STATE_UNDEFINED; in omap_usb_set_host()
148 otg->gadget = gadget; in omap_usb_set_peripheral()
150 otg->state = OTG_STATE_UNDEFINED; in omap_usb_set_peripheral()
160 if (!phy->syscon_phy_power) { in omap_usb_phy_power()
161 omap_control_phy_power(phy->control_dev, on); in omap_usb_phy_power()
166 val = phy->power_on; in omap_usb_phy_power()
168 val = phy->power_off; in omap_usb_phy_power()
170 ret = regmap_update_bits(phy->syscon_phy_power, phy->power_reg, in omap_usb_phy_power()
171 phy->mask, val); in omap_usb_phy_power()
191 clk_disable_unprepare(phy->wkupclk); in omap_usb2_disable_clocks()
192 if (!IS_ERR(phy->optclk)) in omap_usb2_disable_clocks()
193 clk_disable_unprepare(phy->optclk); in omap_usb2_disable_clocks()
202 ret = clk_prepare_enable(phy->wkupclk); in omap_usb2_enable_clocks()
204 dev_err(phy->dev, "Failed to enable wkupclk %d\n", ret); in omap_usb2_enable_clocks()
208 if (!IS_ERR(phy->optclk)) { in omap_usb2_enable_clocks()
209 ret = clk_prepare_enable(phy->optclk); in omap_usb2_enable_clocks()
211 dev_err(phy->dev, "Failed to enable optclk %d\n", ret); in omap_usb2_enable_clocks()
219 clk_disable_unprepare(phy->wkupclk); in omap_usb2_enable_clocks()
232 if (phy->flags & OMAP_USB2_CALIBRATE_FALSE_DISCONNECT) { in omap_usb_init()
241 val = omap_usb_readl(phy->phy_base, USB2PHY_ANA_CONFIG1); in omap_usb_init()
243 omap_usb_writel(phy->phy_base, USB2PHY_ANA_CONFIG1, val); in omap_usb_init()
246 if (phy->flags & OMAP_USB2_DISABLE_CHRG_DET) { in omap_usb_init()
247 val = omap_usb_readl(phy->phy_base, USB2PHY_CHRG_DET); in omap_usb_init()
250 omap_usb_writel(phy->phy_base, USB2PHY_CHRG_DET, val); in omap_usb_init()
319 .compatible = "ti,omap-usb2",
323 .compatible = "ti,omap5-usb2",
327 .compatible = "ti,dra7x-usb2",
331 .compatible = "ti,dra7x-usb2-phy2",
335 .compatible = "ti,am437x-usb2",
339 .compatible = "ti,am654-usb2",
363 phy->flags |= OMAP_USB2_DISABLE_CHRG_DET; in omap_usb2_init_errata()
372 struct device_node *node = pdev->dev.of_node; in omap_usb2_probe()
377 phy_data = device_get_match_data(&pdev->dev); in omap_usb2_probe()
379 return -EINVAL; in omap_usb2_probe()
381 phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL); in omap_usb2_probe()
383 return -ENOMEM; in omap_usb2_probe()
385 otg = devm_kzalloc(&pdev->dev, sizeof(*otg), GFP_KERNEL); in omap_usb2_probe()
387 return -ENOMEM; in omap_usb2_probe()
389 phy->dev = &pdev->dev; in omap_usb2_probe()
391 phy->phy.dev = phy->dev; in omap_usb2_probe()
392 phy->phy.label = phy_data->label; in omap_usb2_probe()
393 phy->phy.otg = otg; in omap_usb2_probe()
394 phy->phy.type = USB_PHY_TYPE_USB2; in omap_usb2_probe()
395 phy->mask = phy_data->mask; in omap_usb2_probe()
396 phy->power_on = phy_data->power_on; in omap_usb2_probe()
397 phy->power_off = phy_data->power_off; in omap_usb2_probe()
398 phy->flags = phy_data->flags; in omap_usb2_probe()
402 phy->phy_base = devm_platform_ioremap_resource(pdev, 0); in omap_usb2_probe()
403 if (IS_ERR(phy->phy_base)) in omap_usb2_probe()
404 return PTR_ERR(phy->phy_base); in omap_usb2_probe()
406 phy->syscon_phy_power = syscon_regmap_lookup_by_phandle(node, in omap_usb2_probe()
407 "syscon-phy-power"); in omap_usb2_probe()
408 if (IS_ERR(phy->syscon_phy_power)) { in omap_usb2_probe()
409 dev_dbg(&pdev->dev, in omap_usb2_probe()
410 "can't get syscon-phy-power, using control device\n"); in omap_usb2_probe()
411 phy->syscon_phy_power = NULL; in omap_usb2_probe()
413 control_node = of_parse_phandle(node, "ctrl-module", 0); in omap_usb2_probe()
415 dev_err(&pdev->dev, in omap_usb2_probe()
417 return -EINVAL; in omap_usb2_probe()
422 dev_err(&pdev->dev, "Failed to get control device\n"); in omap_usb2_probe()
423 return -EINVAL; in omap_usb2_probe()
425 phy->control_dev = &control_pdev->dev; in omap_usb2_probe()
428 "syscon-phy-power", 1, in omap_usb2_probe()
429 &phy->power_reg)) { in omap_usb2_probe()
430 dev_err(&pdev->dev, in omap_usb2_probe()
432 return -EINVAL; in omap_usb2_probe()
436 phy->wkupclk = devm_clk_get(phy->dev, "wkupclk"); in omap_usb2_probe()
437 if (IS_ERR(phy->wkupclk)) { in omap_usb2_probe()
438 if (PTR_ERR(phy->wkupclk) == -EPROBE_DEFER) in omap_usb2_probe()
439 return -EPROBE_DEFER; in omap_usb2_probe()
441 dev_warn(&pdev->dev, "unable to get wkupclk %ld, trying old name\n", in omap_usb2_probe()
442 PTR_ERR(phy->wkupclk)); in omap_usb2_probe()
443 phy->wkupclk = devm_clk_get(phy->dev, "usb_phy_cm_clk32k"); in omap_usb2_probe()
445 if (IS_ERR(phy->wkupclk)) in omap_usb2_probe()
446 return dev_err_probe(&pdev->dev, PTR_ERR(phy->wkupclk), in omap_usb2_probe()
449 dev_warn(&pdev->dev, in omap_usb2_probe()
453 phy->optclk = devm_clk_get(phy->dev, "refclk"); in omap_usb2_probe()
454 if (IS_ERR(phy->optclk)) { in omap_usb2_probe()
455 if (PTR_ERR(phy->optclk) == -EPROBE_DEFER) in omap_usb2_probe()
456 return -EPROBE_DEFER; in omap_usb2_probe()
458 dev_dbg(&pdev->dev, "unable to get refclk, trying old name\n"); in omap_usb2_probe()
459 phy->optclk = devm_clk_get(phy->dev, "usb_otg_ss_refclk960m"); in omap_usb2_probe()
461 if (IS_ERR(phy->optclk)) { in omap_usb2_probe()
462 if (PTR_ERR(phy->optclk) != -EPROBE_DEFER) { in omap_usb2_probe()
463 dev_dbg(&pdev->dev, in omap_usb2_probe()
467 dev_warn(&pdev->dev, in omap_usb2_probe()
472 otg->set_host = omap_usb_set_host; in omap_usb2_probe()
473 otg->set_peripheral = omap_usb_set_peripheral; in omap_usb2_probe()
474 if (phy_data->flags & OMAP_USB2_HAS_SET_VBUS) in omap_usb2_probe()
475 otg->set_vbus = omap_usb_set_vbus; in omap_usb2_probe()
476 if (phy_data->flags & OMAP_USB2_HAS_START_SRP) in omap_usb2_probe()
477 otg->start_srp = omap_usb_start_srp; in omap_usb2_probe()
478 otg->usb_phy = &phy->phy; in omap_usb2_probe()
481 pm_runtime_enable(phy->dev); in omap_usb2_probe()
483 generic_phy = devm_phy_create(phy->dev, NULL, &ops); in omap_usb2_probe()
485 pm_runtime_disable(phy->dev); in omap_usb2_probe()
492 phy_provider = devm_of_phy_provider_register(phy->dev, in omap_usb2_probe()
495 pm_runtime_disable(phy->dev); in omap_usb2_probe()
499 usb_add_phy_dev(&phy->phy); in omap_usb2_probe()
508 usb_remove_phy(&phy->phy); in omap_usb2_remove()
509 pm_runtime_disable(phy->dev); in omap_usb2_remove()
516 .name = "omap-usb2",
525 MODULE_DESCRIPTION("OMAP USB2 phy driver");