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>
55 struct usb_phy phy;
71 #define phy_to_omapusb(x) container_of((x), struct omap_usb, phy)
93 * omap_usb2_set_comparator() - links the comparator present in the system with this phy
95 * @comparator: the companion phy(comparator) for this phy
97 * The phy companion driver should call this API passing the phy_companion
98 * filled with set_vbus and start_srp to be used by usb phy.
100 * For use by phy companion driver
104 struct omap_usb *phy;
110 phy = phy_to_omapusb(x);
111 phy->comparator = comparator;
118 struct omap_usb *phy = phy_to_omapusb(otg->usb_phy);
120 if (!phy->comparator || !phy->comparator->set_vbus)
123 return phy->comparator->set_vbus(phy->comparator, enabled);
128 struct omap_usb *phy = phy_to_omapusb(otg->usb_phy);
130 if (!phy->comparator || !phy->comparator->start_srp)
133 return phy->comparator->start_srp(phy->comparator);
155 static int omap_usb_phy_power(struct omap_usb *phy, int on)
160 if (!phy->syscon_phy_power) {
161 omap_control_phy_power(phy->control_dev, on);
166 val = phy->power_on;
168 val = phy->power_off;
170 ret = regmap_update_bits(phy->syscon_phy_power, phy->power_reg,
171 phy->mask, val);
175 static int omap_usb_power_off(struct phy *x)
177 struct omap_usb *phy = phy_get_drvdata(x);
179 return omap_usb_phy_power(phy, false);
182 static int omap_usb_power_on(struct phy *x)
184 struct omap_usb *phy = phy_get_drvdata(x);
186 return omap_usb_phy_power(phy, true);
189 static int omap_usb2_disable_clocks(struct omap_usb *phy)
191 clk_disable_unprepare(phy->wkupclk);
192 if (!IS_ERR(phy->optclk))
193 clk_disable_unprepare(phy->optclk);
198 static int omap_usb2_enable_clocks(struct omap_usb *phy)
202 ret = clk_prepare_enable(phy->wkupclk);
204 dev_err(phy->dev, "Failed to enable wkupclk %d\n", ret);
208 if (!IS_ERR(phy->optclk)) {
209 ret = clk_prepare_enable(phy->optclk);
211 dev_err(phy->dev, "Failed to enable optclk %d\n", ret);
219 clk_disable_unprepare(phy->wkupclk);
225 static int omap_usb_init(struct phy *x)
227 struct omap_usb *phy = phy_get_drvdata(x);
230 omap_usb2_enable_clocks(phy);
232 if (phy->flags & OMAP_USB2_CALIBRATE_FALSE_DISCONNECT) {
235 * Reduce the sensitivity of internal PHY by enabling the
241 val = omap_usb_readl(phy->phy_base, USB2PHY_ANA_CONFIG1);
243 omap_usb_writel(phy->phy_base, USB2PHY_ANA_CONFIG1, val);
246 if (phy->flags & OMAP_USB2_DISABLE_CHRG_DET) {
247 val = omap_usb_readl(phy->phy_base, USB2PHY_CHRG_DET);
250 omap_usb_writel(phy->phy_base, USB2PHY_CHRG_DET, val);
256 static int omap_usb_exit(struct phy *x)
258 struct omap_usb *phy = phy_get_drvdata(x);
260 return omap_usb2_disable_clocks(phy);
346 static void omap_usb2_init_errata(struct omap_usb *phy)
363 phy->flags |= OMAP_USB2_DISABLE_CHRG_DET;
368 struct omap_usb *phy;
369 struct phy *generic_phy;
381 phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL);
382 if (!phy)
389 phy->dev = &pdev->dev;
391 phy->phy.dev = phy->dev;
392 phy->phy.label = phy_data->label;
393 phy->phy.otg = otg;
394 phy->phy.type = USB_PHY_TYPE_USB2;
395 phy->mask = phy_data->mask;
396 phy->power_on = phy_data->power_on;
397 phy->power_off = phy_data->power_off;
398 phy->flags = phy_data->flags;
400 omap_usb2_init_errata(phy);
402 phy->phy_base = devm_platform_ioremap_resource(pdev, 0);
403 if (IS_ERR(phy->phy_base))
404 return PTR_ERR(phy->phy_base);
406 phy->syscon_phy_power = syscon_regmap_lookup_by_phandle(node,
407 "syscon-phy-power");
408 if (IS_ERR(phy->syscon_phy_power)) {
410 "can't get syscon-phy-power, using control device\n");
411 phy->syscon_phy_power = NULL;
425 phy->control_dev = &control_pdev->dev;
428 "syscon-phy-power", 1,
429 &phy->power_reg)) {
436 phy->wkupclk = devm_clk_get(phy->dev, "wkupclk");
437 if (IS_ERR(phy->wkupclk)) {
438 if (PTR_ERR(phy->wkupclk) == -EPROBE_DEFER)
442 PTR_ERR(phy->wkupclk));
443 phy->wkupclk = devm_clk_get(phy->dev, "usb_phy_cm_clk32k");
445 if (IS_ERR(phy->wkupclk))
446 return dev_err_probe(&pdev->dev, PTR_ERR(phy->wkupclk),
453 phy->optclk = devm_clk_get(phy->dev, "refclk");
454 if (IS_ERR(phy->optclk)) {
455 if (PTR_ERR(phy->optclk) == -EPROBE_DEFER)
459 phy->optclk = devm_clk_get(phy->dev, "usb_otg_ss_refclk960m");
461 if (IS_ERR(phy->optclk)) {
462 if (PTR_ERR(phy->optclk) != -EPROBE_DEFER) {
478 otg->usb_phy = &phy->phy;
480 platform_set_drvdata(pdev, phy);
481 pm_runtime_enable(phy->dev);
483 generic_phy = devm_phy_create(phy->dev, NULL, &ops);
485 pm_runtime_disable(phy->dev);
489 phy_set_drvdata(generic_phy, phy);
492 phy_provider = devm_of_phy_provider_register(phy->dev,
495 pm_runtime_disable(phy->dev);
499 usb_add_phy_dev(&phy->phy);
506 struct omap_usb *phy = platform_get_drvdata(pdev);
508 usb_remove_phy(&phy->phy);
509 pm_runtime_disable(phy->dev);
525 MODULE_DESCRIPTION("OMAP USB2 phy driver");