Lines Matching full:usbphyc
138 struct stm32_usbphyc *usbphyc; member
169 static int stm32_usbphyc_regulators_enable(struct stm32_usbphyc *usbphyc) in stm32_usbphyc_regulators_enable() argument
173 ret = regulator_enable(usbphyc->vdda1v1); in stm32_usbphyc_regulators_enable()
177 ret = regulator_enable(usbphyc->vdda1v8); in stm32_usbphyc_regulators_enable()
184 regulator_disable(usbphyc->vdda1v1); in stm32_usbphyc_regulators_enable()
189 static int stm32_usbphyc_regulators_disable(struct stm32_usbphyc *usbphyc) in stm32_usbphyc_regulators_disable() argument
193 ret = regulator_disable(usbphyc->vdda1v8); in stm32_usbphyc_regulators_disable()
197 ret = regulator_disable(usbphyc->vdda1v1); in stm32_usbphyc_regulators_disable()
231 static int stm32_usbphyc_pll_init(struct stm32_usbphyc *usbphyc) in stm32_usbphyc_pll_init() argument
234 u32 clk_rate = clk_get_rate(usbphyc->clk); in stm32_usbphyc_pll_init()
240 dev_err(usbphyc->dev, "input clk freq (%dHz) out of range\n", in stm32_usbphyc_pll_init()
254 writel_relaxed(usbphyc_pll, usbphyc->base + STM32_USBPHYC_PLL); in stm32_usbphyc_pll_init()
256 dev_dbg(usbphyc->dev, "input clk freq=%dHz, ndiv=%lu, frac=%lu\n", in stm32_usbphyc_pll_init()
263 static int __stm32_usbphyc_pll_disable(struct stm32_usbphyc *usbphyc) in __stm32_usbphyc_pll_disable() argument
265 void __iomem *pll_reg = usbphyc->base + STM32_USBPHYC_PLL; in __stm32_usbphyc_pll_disable()
272 dev_err(usbphyc->dev, "PLL not reset\n"); in __stm32_usbphyc_pll_disable()
274 return stm32_usbphyc_regulators_disable(usbphyc); in __stm32_usbphyc_pll_disable()
277 static int stm32_usbphyc_pll_disable(struct stm32_usbphyc *usbphyc) in stm32_usbphyc_pll_disable() argument
280 if (atomic_dec_return(&usbphyc->n_pll_cons) > 0) in stm32_usbphyc_pll_disable()
283 return __stm32_usbphyc_pll_disable(usbphyc); in stm32_usbphyc_pll_disable()
286 static int stm32_usbphyc_pll_enable(struct stm32_usbphyc *usbphyc) in stm32_usbphyc_pll_enable() argument
288 void __iomem *pll_reg = usbphyc->base + STM32_USBPHYC_PLL; in stm32_usbphyc_pll_enable()
296 if (atomic_inc_return(&usbphyc->n_pll_cons) > 1 && pllen) in stm32_usbphyc_pll_enable()
304 dev_warn(usbphyc->dev, "PLL enabled without known consumers\n"); in stm32_usbphyc_pll_enable()
306 ret = __stm32_usbphyc_pll_disable(usbphyc); in stm32_usbphyc_pll_enable()
311 ret = stm32_usbphyc_regulators_enable(usbphyc); in stm32_usbphyc_pll_enable()
315 ret = stm32_usbphyc_pll_init(usbphyc); in stm32_usbphyc_pll_enable()
327 stm32_usbphyc_regulators_disable(usbphyc); in stm32_usbphyc_pll_enable()
330 atomic_dec(&usbphyc->n_pll_cons); in stm32_usbphyc_pll_enable()
338 struct stm32_usbphyc *usbphyc = usbphyc_phy->usbphyc; in stm32_usbphyc_phy_init() local
345 ret = stm32_usbphyc_pll_enable(usbphyc); in stm32_usbphyc_phy_init()
350 writel_relaxed(monsel, usbphyc->base + reg_mon); in stm32_usbphyc_phy_init()
351 ret = readl_relaxed_poll_timeout(usbphyc->base + reg_mon, monout, in stm32_usbphyc_phy_init()
355 dev_err(usbphyc->dev, "PLL Lock input to PHY is Low (val=%x)\n", in stm32_usbphyc_phy_init()
365 stm32_usbphyc_pll_disable(usbphyc); in stm32_usbphyc_phy_init()
373 struct stm32_usbphyc *usbphyc = usbphyc_phy->usbphyc; in stm32_usbphyc_phy_exit() local
377 return stm32_usbphyc_pll_disable(usbphyc); in stm32_usbphyc_phy_exit()
410 struct stm32_usbphyc *usbphyc = container_of(hw, struct stm32_usbphyc, clk48_hw); in stm32_usbphyc_clk48_prepare() local
412 return stm32_usbphyc_pll_enable(usbphyc); in stm32_usbphyc_clk48_prepare()
417 struct stm32_usbphyc *usbphyc = container_of(hw, struct stm32_usbphyc, clk48_hw); in stm32_usbphyc_clk48_unprepare() local
419 stm32_usbphyc_pll_disable(usbphyc); in stm32_usbphyc_clk48_unprepare()
435 struct stm32_usbphyc *usbphyc = data; in stm32_usbphyc_clk48_unregister() local
437 of_clk_del_provider(usbphyc->dev->of_node); in stm32_usbphyc_clk48_unregister()
438 clk_hw_unregister(&usbphyc->clk48_hw); in stm32_usbphyc_clk48_unregister()
441 static int stm32_usbphyc_clk48_register(struct stm32_usbphyc *usbphyc) in stm32_usbphyc_clk48_register() argument
443 struct device_node *node = usbphyc->dev->of_node; in stm32_usbphyc_clk48_register()
450 usbphyc->clk48_hw.init = &init; in stm32_usbphyc_clk48_register()
452 ret = clk_hw_register(usbphyc->dev, &usbphyc->clk48_hw); in stm32_usbphyc_clk48_register()
456 ret = of_clk_add_hw_provider(node, of_clk_hw_simple_get, &usbphyc->clk48_hw); in stm32_usbphyc_clk48_register()
458 clk_hw_unregister(&usbphyc->clk48_hw); in stm32_usbphyc_clk48_register()
463 static void stm32_usbphyc_phy_tuning(struct stm32_usbphyc *usbphyc, in stm32_usbphyc_phy_tuning() argument
466 struct stm32_usbphyc_phy *usbphyc_phy = usbphyc->phys[index]; in stm32_usbphyc_phy_tuning()
472 otpcomp = FIELD_GET(OTPCOMP, readl_relaxed(usbphyc->base + reg)); in stm32_usbphyc_phy_tuning()
480 dev_warn(usbphyc->dev, "phy%d: invalid st,current-boost-microamp\n", index); in stm32_usbphyc_phy_tuning()
500 dev_warn(usbphyc->dev, "phy%d: invalid st,tune-hs-dc-level\n", index); in stm32_usbphyc_phy_tuning()
515 dev_warn(usbphyc->dev, "phy%d: invalid st,trim-hs-current\n", index); in stm32_usbphyc_phy_tuning()
523 dev_warn(usbphyc->dev, "phy%d: invalid st,trim-hs-impedance\n", index); in stm32_usbphyc_phy_tuning()
531 dev_warn(usbphyc->dev, "phy%d: invalid st,tune-squelch\n", index); in stm32_usbphyc_phy_tuning()
542 dev_warn(usbphyc->dev, "phy%d: invalid st,tune-hs-rx-offset\n", index); in stm32_usbphyc_phy_tuning()
561 writel_relaxed(usbphyc_phy->tune, usbphyc->base + reg); in stm32_usbphyc_phy_tuning()
564 static void stm32_usbphyc_switch_setup(struct stm32_usbphyc *usbphyc, in stm32_usbphyc_switch_setup() argument
568 stm32_usbphyc_clr_bits(usbphyc->base + STM32_USBPHYC_MISC, in stm32_usbphyc_switch_setup()
571 stm32_usbphyc_set_bits(usbphyc->base + STM32_USBPHYC_MISC, in stm32_usbphyc_switch_setup()
573 usbphyc->switch_setup = utmi_switch; in stm32_usbphyc_switch_setup()
579 struct stm32_usbphyc *usbphyc = dev_get_drvdata(dev); in stm32_usbphyc_of_xlate() local
584 for (port = 0; port < usbphyc->nphys; port++) { in stm32_usbphyc_of_xlate()
585 if (phynode == usbphyc->phys[port]->phy->dev.of_node) { in stm32_usbphyc_of_xlate()
586 usbphyc_phy = usbphyc->phys[port]; in stm32_usbphyc_of_xlate()
604 if (usbphyc->switch_setup < 0) { in stm32_usbphyc_of_xlate()
605 stm32_usbphyc_switch_setup(usbphyc, args->args[0]); in stm32_usbphyc_of_xlate()
607 if (args->args[0] != usbphyc->switch_setup) { in stm32_usbphyc_of_xlate()
619 struct stm32_usbphyc *usbphyc; in stm32_usbphyc_probe() local
626 usbphyc = devm_kzalloc(dev, sizeof(*usbphyc), GFP_KERNEL); in stm32_usbphyc_probe()
627 if (!usbphyc) in stm32_usbphyc_probe()
629 usbphyc->dev = dev; in stm32_usbphyc_probe()
630 dev_set_drvdata(dev, usbphyc); in stm32_usbphyc_probe()
632 usbphyc->base = devm_platform_ioremap_resource(pdev, 0); in stm32_usbphyc_probe()
633 if (IS_ERR(usbphyc->base)) in stm32_usbphyc_probe()
634 return PTR_ERR(usbphyc->base); in stm32_usbphyc_probe()
636 usbphyc->clk = devm_clk_get(dev, NULL); in stm32_usbphyc_probe()
637 if (IS_ERR(usbphyc->clk)) in stm32_usbphyc_probe()
638 return dev_err_probe(dev, PTR_ERR(usbphyc->clk), "clk get_failed\n"); in stm32_usbphyc_probe()
640 ret = clk_prepare_enable(usbphyc->clk); in stm32_usbphyc_probe()
646 usbphyc->rst = devm_reset_control_get(dev, NULL); in stm32_usbphyc_probe()
647 if (!IS_ERR(usbphyc->rst)) { in stm32_usbphyc_probe()
648 reset_control_assert(usbphyc->rst); in stm32_usbphyc_probe()
650 reset_control_deassert(usbphyc->rst); in stm32_usbphyc_probe()
652 ret = PTR_ERR(usbphyc->rst); in stm32_usbphyc_probe()
656 stm32_usbphyc_clr_bits(usbphyc->base + STM32_USBPHYC_PLL, PLLEN); in stm32_usbphyc_probe()
663 if (readl_relaxed_poll_timeout(usbphyc->base + STM32_USBPHYC_PLL, in stm32_usbphyc_probe()
665 dev_warn(usbphyc->dev, "PLL not reset\n"); in stm32_usbphyc_probe()
670 usbphyc->switch_setup = -EINVAL; in stm32_usbphyc_probe()
671 usbphyc->nphys = of_get_child_count(np); in stm32_usbphyc_probe()
672 usbphyc->phys = devm_kcalloc(dev, usbphyc->nphys, in stm32_usbphyc_probe()
673 sizeof(*usbphyc->phys), GFP_KERNEL); in stm32_usbphyc_probe()
674 if (!usbphyc->phys) { in stm32_usbphyc_probe()
679 usbphyc->vdda1v1 = devm_regulator_get(dev, "vdda1v1"); in stm32_usbphyc_probe()
680 if (IS_ERR(usbphyc->vdda1v1)) { in stm32_usbphyc_probe()
681 ret = dev_err_probe(dev, PTR_ERR(usbphyc->vdda1v1), in stm32_usbphyc_probe()
686 usbphyc->vdda1v8 = devm_regulator_get(dev, "vdda1v8"); in stm32_usbphyc_probe()
687 if (IS_ERR(usbphyc->vdda1v8)) { in stm32_usbphyc_probe()
688 ret = dev_err_probe(dev, PTR_ERR(usbphyc->vdda1v8), in stm32_usbphyc_probe()
715 if (ret || index > usbphyc->nphys) { in stm32_usbphyc_probe()
722 usbphyc->phys[port] = usbphyc_phy; in stm32_usbphyc_probe()
726 usbphyc->phys[port]->phy = phy; in stm32_usbphyc_probe()
727 usbphyc->phys[port]->usbphyc = usbphyc; in stm32_usbphyc_probe()
728 usbphyc->phys[port]->index = index; in stm32_usbphyc_probe()
729 usbphyc->phys[port]->active = false; in stm32_usbphyc_probe()
731 usbphyc->phys[port]->vbus = devm_regulator_get_optional(&phy->dev, "vbus"); in stm32_usbphyc_probe()
732 if (IS_ERR(usbphyc->phys[port]->vbus)) { in stm32_usbphyc_probe()
733 ret = PTR_ERR(usbphyc->phys[port]->vbus); in stm32_usbphyc_probe()
736 usbphyc->phys[port]->vbus = NULL; in stm32_usbphyc_probe()
740 stm32_usbphyc_phy_tuning(usbphyc, child, index); in stm32_usbphyc_probe()
753 ret = stm32_usbphyc_clk48_register(usbphyc); in stm32_usbphyc_probe()
759 version = readl_relaxed(usbphyc->base + STM32_USBPHYC_VERSION); in stm32_usbphyc_probe()
768 clk_disable_unprepare(usbphyc->clk); in stm32_usbphyc_probe()
775 struct stm32_usbphyc *usbphyc = dev_get_drvdata(&pdev->dev); in stm32_usbphyc_remove() local
779 for (port = 0; port < usbphyc->nphys; port++) in stm32_usbphyc_remove()
780 if (usbphyc->phys[port]->active) in stm32_usbphyc_remove()
781 stm32_usbphyc_phy_exit(usbphyc->phys[port]->phy); in stm32_usbphyc_remove()
783 stm32_usbphyc_clk48_unregister(usbphyc); in stm32_usbphyc_remove()
785 clk_disable_unprepare(usbphyc->clk); in stm32_usbphyc_remove()
790 struct stm32_usbphyc *usbphyc = dev_get_drvdata(dev); in stm32_usbphyc_resume() local
794 if (usbphyc->switch_setup >= 0) in stm32_usbphyc_resume()
795 stm32_usbphyc_switch_setup(usbphyc, usbphyc->switch_setup); in stm32_usbphyc_resume()
797 for (port = 0; port < usbphyc->nphys; port++) { in stm32_usbphyc_resume()
798 usbphyc_phy = usbphyc->phys[port]; in stm32_usbphyc_resume()
799 writel_relaxed(usbphyc_phy->tune, usbphyc->base + STM32_USBPHYC_TUNE(port)); in stm32_usbphyc_resume()
808 { .compatible = "st,stm32mp1-usbphyc", },
818 .name = "stm32-usbphyc",
824 MODULE_DESCRIPTION("STMicroelectronics STM32 USBPHYC driver");