Lines Matching +full:syscon +full:- +full:phy +full:- +full:power
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
13 #include <linux/mfd/syscon.h>
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
64 unsigned int power_reg; /* power reg. index within syscon */
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
93 * 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
107 return -ENODEV; in omap_usb2_set_comparator()
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) in omap_usb_set_vbus()
120 return -ENODEV; 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) in omap_usb_start_srp()
130 return -ENODEV; in omap_usb_start_srp()
132 return phy->comparator->start_srp(phy->comparator); in omap_usb_start_srp()
137 otg->host = host; in omap_usb_set_host()
139 otg->state = OTG_STATE_UNDEFINED; in omap_usb_set_host()
147 otg->gadget = gadget; in omap_usb_set_peripheral()
149 otg->state = OTG_STATE_UNDEFINED; in omap_usb_set_peripheral()
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(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()
318 .compatible = "ti,omap-usb2",
322 .compatible = "ti,omap5-usb2",
326 .compatible = "ti,dra7x-usb2",
330 .compatible = "ti,dra7x-usb2-phy2",
334 .compatible = "ti,am437x-usb2",
338 .compatible = "ti,am654-usb2",
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()
372 struct device_node *node = pdev->dev.of_node; in omap_usb2_probe()
378 of_id = of_match_device(omap_usb2_id_table, &pdev->dev); in omap_usb2_probe()
381 return -EINVAL; in omap_usb2_probe()
383 phy_data = (struct usb_phy_data *)of_id->data; in omap_usb2_probe()
385 phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL); in omap_usb2_probe()
386 if (!phy) in omap_usb2_probe()
387 return -ENOMEM; in omap_usb2_probe()
389 otg = devm_kzalloc(&pdev->dev, sizeof(*otg), GFP_KERNEL); in omap_usb2_probe()
391 return -ENOMEM; in omap_usb2_probe()
393 phy->dev = &pdev->dev; in omap_usb2_probe()
395 phy->phy.dev = phy->dev; in omap_usb2_probe()
396 phy->phy.label = phy_data->label; in omap_usb2_probe()
397 phy->phy.otg = otg; in omap_usb2_probe()
398 phy->phy.type = USB_PHY_TYPE_USB2; in omap_usb2_probe()
399 phy->mask = phy_data->mask; in omap_usb2_probe()
400 phy->power_on = phy_data->power_on; in omap_usb2_probe()
401 phy->power_off = phy_data->power_off; in omap_usb2_probe()
402 phy->flags = phy_data->flags; in omap_usb2_probe()
404 omap_usb2_init_errata(phy); in omap_usb2_probe()
407 phy->phy_base = devm_ioremap_resource(&pdev->dev, res); in omap_usb2_probe()
408 if (IS_ERR(phy->phy_base)) in omap_usb2_probe()
409 return PTR_ERR(phy->phy_base); in omap_usb2_probe()
411 phy->syscon_phy_power = syscon_regmap_lookup_by_phandle(node, in omap_usb2_probe()
412 "syscon-phy-power"); in omap_usb2_probe()
413 if (IS_ERR(phy->syscon_phy_power)) { in omap_usb2_probe()
414 dev_dbg(&pdev->dev, in omap_usb2_probe()
415 "can't get syscon-phy-power, using control device\n"); in omap_usb2_probe()
416 phy->syscon_phy_power = NULL; in omap_usb2_probe()
418 control_node = of_parse_phandle(node, "ctrl-module", 0); in omap_usb2_probe()
420 dev_err(&pdev->dev, in omap_usb2_probe()
422 return -EINVAL; in omap_usb2_probe()
427 dev_err(&pdev->dev, "Failed to get control device\n"); in omap_usb2_probe()
428 return -EINVAL; in omap_usb2_probe()
430 phy->control_dev = &control_pdev->dev; in omap_usb2_probe()
433 "syscon-phy-power", 1, in omap_usb2_probe()
434 &phy->power_reg)) { in omap_usb2_probe()
435 dev_err(&pdev->dev, in omap_usb2_probe()
436 "couldn't get power reg. offset\n"); in omap_usb2_probe()
437 return -EINVAL; in omap_usb2_probe()
441 phy->wkupclk = devm_clk_get(phy->dev, "wkupclk"); in omap_usb2_probe()
442 if (IS_ERR(phy->wkupclk)) { in omap_usb2_probe()
443 if (PTR_ERR(phy->wkupclk) == -EPROBE_DEFER) in omap_usb2_probe()
444 return -EPROBE_DEFER; in omap_usb2_probe()
446 dev_warn(&pdev->dev, "unable to get wkupclk %ld, trying old name\n", in omap_usb2_probe()
447 PTR_ERR(phy->wkupclk)); in omap_usb2_probe()
448 phy->wkupclk = devm_clk_get(phy->dev, "usb_phy_cm_clk32k"); in omap_usb2_probe()
450 if (IS_ERR(phy->wkupclk)) { in omap_usb2_probe()
451 if (PTR_ERR(phy->wkupclk) != -EPROBE_DEFER) in omap_usb2_probe()
452 dev_err(&pdev->dev, "unable to get usb_phy_cm_clk32k\n"); in omap_usb2_probe()
453 return PTR_ERR(phy->wkupclk); in omap_usb2_probe()
456 dev_warn(&pdev->dev, in omap_usb2_probe()
460 phy->optclk = devm_clk_get(phy->dev, "refclk"); 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 return -EPROBE_DEFER; in omap_usb2_probe()
465 dev_dbg(&pdev->dev, "unable to get refclk, trying old name\n"); in omap_usb2_probe()
466 phy->optclk = devm_clk_get(phy->dev, "usb_otg_ss_refclk960m"); in omap_usb2_probe()
468 if (IS_ERR(phy->optclk)) { in omap_usb2_probe()
469 if (PTR_ERR(phy->optclk) != -EPROBE_DEFER) { in omap_usb2_probe()
470 dev_dbg(&pdev->dev, in omap_usb2_probe()
474 dev_warn(&pdev->dev, in omap_usb2_probe()
479 otg->set_host = omap_usb_set_host; in omap_usb2_probe()
480 otg->set_peripheral = omap_usb_set_peripheral; in omap_usb2_probe()
481 if (phy_data->flags & OMAP_USB2_HAS_SET_VBUS) in omap_usb2_probe()
482 otg->set_vbus = omap_usb_set_vbus; in omap_usb2_probe()
483 if (phy_data->flags & OMAP_USB2_HAS_START_SRP) in omap_usb2_probe()
484 otg->start_srp = omap_usb_start_srp; in omap_usb2_probe()
485 otg->usb_phy = &phy->phy; in omap_usb2_probe()
487 platform_set_drvdata(pdev, phy); in omap_usb2_probe()
488 pm_runtime_enable(phy->dev); in omap_usb2_probe()
490 generic_phy = devm_phy_create(phy->dev, NULL, &ops); in omap_usb2_probe()
492 pm_runtime_disable(phy->dev); in omap_usb2_probe()
496 phy_set_drvdata(generic_phy, phy); in omap_usb2_probe()
499 phy_provider = devm_of_phy_provider_register(phy->dev, in omap_usb2_probe()
502 pm_runtime_disable(phy->dev); in omap_usb2_probe()
506 usb_add_phy_dev(&phy->phy); in omap_usb2_probe()
513 struct omap_usb *phy = platform_get_drvdata(pdev); in omap_usb2_remove() local
515 usb_remove_phy(&phy->phy); in omap_usb2_remove()
516 pm_runtime_disable(phy->dev); in omap_usb2_remove()
525 .name = "omap-usb2",
534 MODULE_DESCRIPTION("OMAP USB2 phy driver");