Lines Matching full:phy
3 * omap-usb2.c - USB PHY, talking to USB controller on TI SoCs.
17 #include <linux/phy/omap_control_phy.h>
18 #include <linux/phy/omap_usb.h>
19 #include <linux/phy/phy.h>
54 struct usb_phy phy; member
70 #define phy_to_omapusb(x) container_of((x), struct omap_usb, phy)
92 * omap_usb2_set_comparator() - links the comparator present in the system with this phy
94 * @comparator: the companion phy(comparator) for this phy
96 * The phy companion driver should call this API passing the phy_companion
97 * filled with set_vbus and start_srp to be used by usb phy.
99 * For use by phy companion driver
103 struct omap_usb *phy; in omap_usb2_set_comparator() local
109 phy = phy_to_omapusb(x); in omap_usb2_set_comparator()
110 phy->comparator = comparator; in omap_usb2_set_comparator()
117 struct omap_usb *phy = phy_to_omapusb(otg->usb_phy); in omap_usb_set_vbus() local
119 if (!phy->comparator || !phy->comparator->set_vbus) in omap_usb_set_vbus()
122 return phy->comparator->set_vbus(phy->comparator, enabled); in omap_usb_set_vbus()
127 struct omap_usb *phy = phy_to_omapusb(otg->usb_phy); in omap_usb_start_srp() local
129 if (!phy->comparator || !phy->comparator->start_srp) in omap_usb_start_srp()
132 return phy->comparator->start_srp(phy->comparator); in omap_usb_start_srp()
154 static int omap_usb_phy_power(struct omap_usb *phy, int on) in omap_usb_phy_power() argument
159 if (!phy->syscon_phy_power) { in omap_usb_phy_power()
160 omap_control_phy_power(phy->control_dev, on); in omap_usb_phy_power()
165 val = phy->power_on; in omap_usb_phy_power()
167 val = phy->power_off; in omap_usb_phy_power()
169 ret = regmap_update_bits(phy->syscon_phy_power, phy->power_reg, in omap_usb_phy_power()
170 phy->mask, val); in omap_usb_phy_power()
174 static int omap_usb_power_off(struct phy *x) in omap_usb_power_off()
176 struct omap_usb *phy = phy_get_drvdata(x); in omap_usb_power_off() local
178 return omap_usb_phy_power(phy, false); in omap_usb_power_off()
181 static int omap_usb_power_on(struct phy *x) in omap_usb_power_on()
183 struct omap_usb *phy = phy_get_drvdata(x); in omap_usb_power_on() local
185 return omap_usb_phy_power(phy, true); in omap_usb_power_on()
188 static int omap_usb2_disable_clocks(struct omap_usb *phy) in omap_usb2_disable_clocks() argument
190 clk_disable_unprepare(phy->wkupclk); in omap_usb2_disable_clocks()
191 if (!IS_ERR(phy->optclk)) in omap_usb2_disable_clocks()
192 clk_disable_unprepare(phy->optclk); in omap_usb2_disable_clocks()
197 static int omap_usb2_enable_clocks(struct omap_usb *phy) in omap_usb2_enable_clocks() argument
201 ret = clk_prepare_enable(phy->wkupclk); in omap_usb2_enable_clocks()
203 dev_err(phy->dev, "Failed to enable wkupclk %d\n", ret); in omap_usb2_enable_clocks()
207 if (!IS_ERR(phy->optclk)) { in omap_usb2_enable_clocks()
208 ret = clk_prepare_enable(phy->optclk); in omap_usb2_enable_clocks()
210 dev_err(phy->dev, "Failed to enable optclk %d\n", ret); in omap_usb2_enable_clocks()
218 clk_disable_unprepare(phy->wkupclk); in omap_usb2_enable_clocks()
224 static int omap_usb_init(struct phy *x) in omap_usb_init()
226 struct omap_usb *phy = phy_get_drvdata(x); in omap_usb_init() local
229 omap_usb2_enable_clocks(phy); in omap_usb_init()
231 if (phy->flags & OMAP_USB2_CALIBRATE_FALSE_DISCONNECT) { in omap_usb_init()
234 * Reduce the sensitivity of internal PHY by enabling the in omap_usb_init()
240 val = omap_usb_readl(phy->phy_base, USB2PHY_ANA_CONFIG1); in omap_usb_init()
242 omap_usb_writel(phy->phy_base, USB2PHY_ANA_CONFIG1, val); in omap_usb_init()
245 if (phy->flags & OMAP_USB2_DISABLE_CHRG_DET) { in omap_usb_init()
246 val = omap_usb_readl(phy->phy_base, USB2PHY_CHRG_DET); in omap_usb_init()
249 omap_usb_writel(phy->phy_base, USB2PHY_CHRG_DET, val); in omap_usb_init()
255 static int omap_usb_exit(struct phy *x) in omap_usb_exit()
257 struct omap_usb *phy = phy_get_drvdata(x); in omap_usb_exit() local
259 return omap_usb2_disable_clocks(phy); in omap_usb_exit()
345 static void omap_usb2_init_errata(struct omap_usb *phy) in omap_usb2_init_errata() argument
362 phy->flags |= OMAP_USB2_DISABLE_CHRG_DET; in omap_usb2_init_errata()
367 struct omap_usb *phy; in omap_usb2_probe() local
368 struct phy *generic_phy; in omap_usb2_probe()
384 phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL); in omap_usb2_probe()
385 if (!phy) in omap_usb2_probe()
392 phy->dev = &pdev->dev; in omap_usb2_probe()
394 phy->phy.dev = phy->dev; in omap_usb2_probe()
395 phy->phy.label = phy_data->label; in omap_usb2_probe()
396 phy->phy.otg = otg; in omap_usb2_probe()
397 phy->phy.type = USB_PHY_TYPE_USB2; in omap_usb2_probe()
398 phy->mask = phy_data->mask; in omap_usb2_probe()
399 phy->power_on = phy_data->power_on; in omap_usb2_probe()
400 phy->power_off = phy_data->power_off; in omap_usb2_probe()
401 phy->flags = phy_data->flags; in omap_usb2_probe()
403 omap_usb2_init_errata(phy); in omap_usb2_probe()
405 phy->phy_base = devm_platform_ioremap_resource(pdev, 0); in omap_usb2_probe()
406 if (IS_ERR(phy->phy_base)) in omap_usb2_probe()
407 return PTR_ERR(phy->phy_base); in omap_usb2_probe()
409 phy->syscon_phy_power = syscon_regmap_lookup_by_phandle(node, in omap_usb2_probe()
410 "syscon-phy-power"); in omap_usb2_probe()
411 if (IS_ERR(phy->syscon_phy_power)) { in omap_usb2_probe()
413 "can't get syscon-phy-power, using control device\n"); in omap_usb2_probe()
414 phy->syscon_phy_power = NULL; in omap_usb2_probe()
428 phy->control_dev = &control_pdev->dev; in omap_usb2_probe()
431 "syscon-phy-power", 1, in omap_usb2_probe()
432 &phy->power_reg)) { in omap_usb2_probe()
439 phy->wkupclk = devm_clk_get(phy->dev, "wkupclk"); in omap_usb2_probe()
440 if (IS_ERR(phy->wkupclk)) { in omap_usb2_probe()
441 if (PTR_ERR(phy->wkupclk) == -EPROBE_DEFER) in omap_usb2_probe()
445 PTR_ERR(phy->wkupclk)); in omap_usb2_probe()
446 phy->wkupclk = devm_clk_get(phy->dev, "usb_phy_cm_clk32k"); in omap_usb2_probe()
448 if (IS_ERR(phy->wkupclk)) in omap_usb2_probe()
449 return dev_err_probe(&pdev->dev, PTR_ERR(phy->wkupclk), in omap_usb2_probe()
456 phy->optclk = devm_clk_get(phy->dev, "refclk"); in omap_usb2_probe()
457 if (IS_ERR(phy->optclk)) { in omap_usb2_probe()
458 if (PTR_ERR(phy->optclk) == -EPROBE_DEFER) in omap_usb2_probe()
462 phy->optclk = devm_clk_get(phy->dev, "usb_otg_ss_refclk960m"); in omap_usb2_probe()
464 if (IS_ERR(phy->optclk)) { in omap_usb2_probe()
465 if (PTR_ERR(phy->optclk) != -EPROBE_DEFER) { in omap_usb2_probe()
481 otg->usb_phy = &phy->phy; in omap_usb2_probe()
483 platform_set_drvdata(pdev, phy); in omap_usb2_probe()
484 pm_runtime_enable(phy->dev); in omap_usb2_probe()
486 generic_phy = devm_phy_create(phy->dev, NULL, &ops); in omap_usb2_probe()
488 pm_runtime_disable(phy->dev); in omap_usb2_probe()
492 phy_set_drvdata(generic_phy, phy); in omap_usb2_probe()
495 phy_provider = devm_of_phy_provider_register(phy->dev, in omap_usb2_probe()
498 pm_runtime_disable(phy->dev); in omap_usb2_probe()
502 usb_add_phy_dev(&phy->phy); in omap_usb2_probe()
509 struct omap_usb *phy = platform_get_drvdata(pdev); in omap_usb2_remove() local
511 usb_remove_phy(&phy->phy); in omap_usb2_remove()
512 pm_runtime_disable(phy->dev); in omap_usb2_remove()
528 MODULE_DESCRIPTION("OMAP USB2 phy driver");