Lines Matching refs:usbphyc

137 	struct stm32_usbphyc *usbphyc;  member
168 static int stm32_usbphyc_regulators_enable(struct stm32_usbphyc *usbphyc) in stm32_usbphyc_regulators_enable() argument
172 ret = regulator_enable(usbphyc->vdda1v1); in stm32_usbphyc_regulators_enable()
176 ret = regulator_enable(usbphyc->vdda1v8); in stm32_usbphyc_regulators_enable()
183 regulator_disable(usbphyc->vdda1v1); in stm32_usbphyc_regulators_enable()
188 static int stm32_usbphyc_regulators_disable(struct stm32_usbphyc *usbphyc) in stm32_usbphyc_regulators_disable() argument
192 ret = regulator_disable(usbphyc->vdda1v8); in stm32_usbphyc_regulators_disable()
196 ret = regulator_disable(usbphyc->vdda1v1); in stm32_usbphyc_regulators_disable()
230 static int stm32_usbphyc_pll_init(struct stm32_usbphyc *usbphyc) in stm32_usbphyc_pll_init() argument
233 u32 clk_rate = clk_get_rate(usbphyc->clk); in stm32_usbphyc_pll_init()
239 dev_err(usbphyc->dev, "input clk freq (%dHz) out of range\n", in stm32_usbphyc_pll_init()
253 writel_relaxed(usbphyc_pll, usbphyc->base + STM32_USBPHYC_PLL); in stm32_usbphyc_pll_init()
255 dev_dbg(usbphyc->dev, "input clk freq=%dHz, ndiv=%lu, frac=%lu\n", in stm32_usbphyc_pll_init()
262 static int __stm32_usbphyc_pll_disable(struct stm32_usbphyc *usbphyc) in __stm32_usbphyc_pll_disable() argument
264 void __iomem *pll_reg = usbphyc->base + STM32_USBPHYC_PLL; in __stm32_usbphyc_pll_disable()
271 dev_err(usbphyc->dev, "PLL not reset\n"); in __stm32_usbphyc_pll_disable()
273 return stm32_usbphyc_regulators_disable(usbphyc); in __stm32_usbphyc_pll_disable()
276 static int stm32_usbphyc_pll_disable(struct stm32_usbphyc *usbphyc) in stm32_usbphyc_pll_disable() argument
279 if (atomic_dec_return(&usbphyc->n_pll_cons) > 0) in stm32_usbphyc_pll_disable()
282 return __stm32_usbphyc_pll_disable(usbphyc); in stm32_usbphyc_pll_disable()
285 static int stm32_usbphyc_pll_enable(struct stm32_usbphyc *usbphyc) in stm32_usbphyc_pll_enable() argument
287 void __iomem *pll_reg = usbphyc->base + STM32_USBPHYC_PLL; in stm32_usbphyc_pll_enable()
295 if (atomic_inc_return(&usbphyc->n_pll_cons) > 1 && pllen) in stm32_usbphyc_pll_enable()
303 dev_warn(usbphyc->dev, "PLL enabled without known consumers\n"); in stm32_usbphyc_pll_enable()
305 ret = __stm32_usbphyc_pll_disable(usbphyc); in stm32_usbphyc_pll_enable()
310 ret = stm32_usbphyc_regulators_enable(usbphyc); in stm32_usbphyc_pll_enable()
314 ret = stm32_usbphyc_pll_init(usbphyc); in stm32_usbphyc_pll_enable()
323 stm32_usbphyc_regulators_disable(usbphyc); in stm32_usbphyc_pll_enable()
326 atomic_dec(&usbphyc->n_pll_cons); in stm32_usbphyc_pll_enable()
334 struct stm32_usbphyc *usbphyc = usbphyc_phy->usbphyc; in stm32_usbphyc_phy_init() local
341 ret = stm32_usbphyc_pll_enable(usbphyc); in stm32_usbphyc_phy_init()
346 writel_relaxed(monsel, usbphyc->base + reg_mon); in stm32_usbphyc_phy_init()
347 ret = readl_relaxed_poll_timeout(usbphyc->base + reg_mon, monout, in stm32_usbphyc_phy_init()
351 dev_err(usbphyc->dev, "PLL Lock input to PHY is Low (val=%x)\n", in stm32_usbphyc_phy_init()
361 stm32_usbphyc_pll_disable(usbphyc); in stm32_usbphyc_phy_init()
369 struct stm32_usbphyc *usbphyc = usbphyc_phy->usbphyc; in stm32_usbphyc_phy_exit() local
373 return stm32_usbphyc_pll_disable(usbphyc); in stm32_usbphyc_phy_exit()
406 struct stm32_usbphyc *usbphyc = container_of(hw, struct stm32_usbphyc, clk48_hw); in stm32_usbphyc_clk48_prepare() local
408 return stm32_usbphyc_pll_enable(usbphyc); in stm32_usbphyc_clk48_prepare()
413 struct stm32_usbphyc *usbphyc = container_of(hw, struct stm32_usbphyc, clk48_hw); in stm32_usbphyc_clk48_unprepare() local
415 stm32_usbphyc_pll_disable(usbphyc); in stm32_usbphyc_clk48_unprepare()
431 struct stm32_usbphyc *usbphyc = data; in stm32_usbphyc_clk48_unregister() local
433 of_clk_del_provider(usbphyc->dev->of_node); in stm32_usbphyc_clk48_unregister()
434 clk_hw_unregister(&usbphyc->clk48_hw); in stm32_usbphyc_clk48_unregister()
437 static int stm32_usbphyc_clk48_register(struct stm32_usbphyc *usbphyc) in stm32_usbphyc_clk48_register() argument
439 struct device_node *node = usbphyc->dev->of_node; in stm32_usbphyc_clk48_register()
446 usbphyc->clk48_hw.init = &init; in stm32_usbphyc_clk48_register()
448 ret = clk_hw_register(usbphyc->dev, &usbphyc->clk48_hw); in stm32_usbphyc_clk48_register()
452 ret = of_clk_add_hw_provider(node, of_clk_hw_simple_get, &usbphyc->clk48_hw); in stm32_usbphyc_clk48_register()
454 clk_hw_unregister(&usbphyc->clk48_hw); in stm32_usbphyc_clk48_register()
459 static void stm32_usbphyc_phy_tuning(struct stm32_usbphyc *usbphyc, in stm32_usbphyc_phy_tuning() argument
462 struct stm32_usbphyc_phy *usbphyc_phy = usbphyc->phys[index]; in stm32_usbphyc_phy_tuning()
468 otpcomp = FIELD_GET(OTPCOMP, readl_relaxed(usbphyc->base + reg)); in stm32_usbphyc_phy_tuning()
476 dev_warn(usbphyc->dev, "phy%d: invalid st,current-boost-microamp\n", index); in stm32_usbphyc_phy_tuning()
496 dev_warn(usbphyc->dev, "phy%d: invalid st,tune-hs-dc-level\n", index); in stm32_usbphyc_phy_tuning()
511 dev_warn(usbphyc->dev, "phy%d: invalid st,trim-hs-current\n", index); in stm32_usbphyc_phy_tuning()
519 dev_warn(usbphyc->dev, "phy%d: invalid st,trim-hs-impedance\n", index); in stm32_usbphyc_phy_tuning()
527 dev_warn(usbphyc->dev, "phy%d: invalid st,tune-squelch\n", index); in stm32_usbphyc_phy_tuning()
538 dev_warn(usbphyc->dev, "phy%d: invalid st,tune-hs-rx-offset\n", index); in stm32_usbphyc_phy_tuning()
557 writel_relaxed(usbphyc_phy->tune, usbphyc->base + reg); in stm32_usbphyc_phy_tuning()
560 static void stm32_usbphyc_switch_setup(struct stm32_usbphyc *usbphyc, in stm32_usbphyc_switch_setup() argument
564 stm32_usbphyc_clr_bits(usbphyc->base + STM32_USBPHYC_MISC, in stm32_usbphyc_switch_setup()
567 stm32_usbphyc_set_bits(usbphyc->base + STM32_USBPHYC_MISC, in stm32_usbphyc_switch_setup()
569 usbphyc->switch_setup = utmi_switch; in stm32_usbphyc_switch_setup()
575 struct stm32_usbphyc *usbphyc = dev_get_drvdata(dev); in stm32_usbphyc_of_xlate() local
580 for (port = 0; port < usbphyc->nphys; port++) { in stm32_usbphyc_of_xlate()
581 if (phynode == usbphyc->phys[port]->phy->dev.of_node) { in stm32_usbphyc_of_xlate()
582 usbphyc_phy = usbphyc->phys[port]; in stm32_usbphyc_of_xlate()
600 if (usbphyc->switch_setup < 0) { in stm32_usbphyc_of_xlate()
601 stm32_usbphyc_switch_setup(usbphyc, args->args[0]); in stm32_usbphyc_of_xlate()
603 if (args->args[0] != usbphyc->switch_setup) { in stm32_usbphyc_of_xlate()
615 struct stm32_usbphyc *usbphyc; in stm32_usbphyc_probe() local
622 usbphyc = devm_kzalloc(dev, sizeof(*usbphyc), GFP_KERNEL); in stm32_usbphyc_probe()
623 if (!usbphyc) in stm32_usbphyc_probe()
625 usbphyc->dev = dev; in stm32_usbphyc_probe()
626 dev_set_drvdata(dev, usbphyc); in stm32_usbphyc_probe()
628 usbphyc->base = devm_platform_ioremap_resource(pdev, 0); in stm32_usbphyc_probe()
629 if (IS_ERR(usbphyc->base)) in stm32_usbphyc_probe()
630 return PTR_ERR(usbphyc->base); in stm32_usbphyc_probe()
632 usbphyc->clk = devm_clk_get(dev, NULL); in stm32_usbphyc_probe()
633 if (IS_ERR(usbphyc->clk)) in stm32_usbphyc_probe()
634 return dev_err_probe(dev, PTR_ERR(usbphyc->clk), "clk get_failed\n"); in stm32_usbphyc_probe()
636 ret = clk_prepare_enable(usbphyc->clk); in stm32_usbphyc_probe()
642 usbphyc->rst = devm_reset_control_get(dev, NULL); in stm32_usbphyc_probe()
643 if (!IS_ERR(usbphyc->rst)) { in stm32_usbphyc_probe()
644 reset_control_assert(usbphyc->rst); in stm32_usbphyc_probe()
646 reset_control_deassert(usbphyc->rst); in stm32_usbphyc_probe()
648 ret = PTR_ERR(usbphyc->rst); in stm32_usbphyc_probe()
652 stm32_usbphyc_clr_bits(usbphyc->base + STM32_USBPHYC_PLL, PLLEN); in stm32_usbphyc_probe()
659 if (readl_relaxed_poll_timeout(usbphyc->base + STM32_USBPHYC_PLL, in stm32_usbphyc_probe()
661 dev_warn(usbphyc->dev, "PLL not reset\n"); in stm32_usbphyc_probe()
666 usbphyc->switch_setup = -EINVAL; in stm32_usbphyc_probe()
667 usbphyc->nphys = of_get_child_count(np); in stm32_usbphyc_probe()
668 usbphyc->phys = devm_kcalloc(dev, usbphyc->nphys, in stm32_usbphyc_probe()
669 sizeof(*usbphyc->phys), GFP_KERNEL); in stm32_usbphyc_probe()
670 if (!usbphyc->phys) { in stm32_usbphyc_probe()
675 usbphyc->vdda1v1 = devm_regulator_get(dev, "vdda1v1"); in stm32_usbphyc_probe()
676 if (IS_ERR(usbphyc->vdda1v1)) { in stm32_usbphyc_probe()
677 ret = dev_err_probe(dev, PTR_ERR(usbphyc->vdda1v1), in stm32_usbphyc_probe()
682 usbphyc->vdda1v8 = devm_regulator_get(dev, "vdda1v8"); in stm32_usbphyc_probe()
683 if (IS_ERR(usbphyc->vdda1v8)) { in stm32_usbphyc_probe()
684 ret = dev_err_probe(dev, PTR_ERR(usbphyc->vdda1v8), in stm32_usbphyc_probe()
711 if (ret || index > usbphyc->nphys) { in stm32_usbphyc_probe()
718 usbphyc->phys[port] = usbphyc_phy; in stm32_usbphyc_probe()
722 usbphyc->phys[port]->phy = phy; in stm32_usbphyc_probe()
723 usbphyc->phys[port]->usbphyc = usbphyc; in stm32_usbphyc_probe()
724 usbphyc->phys[port]->index = index; in stm32_usbphyc_probe()
725 usbphyc->phys[port]->active = false; in stm32_usbphyc_probe()
727 usbphyc->phys[port]->vbus = devm_regulator_get_optional(&phy->dev, "vbus"); in stm32_usbphyc_probe()
728 if (IS_ERR(usbphyc->phys[port]->vbus)) { in stm32_usbphyc_probe()
729 ret = PTR_ERR(usbphyc->phys[port]->vbus); in stm32_usbphyc_probe()
732 usbphyc->phys[port]->vbus = NULL; in stm32_usbphyc_probe()
736 stm32_usbphyc_phy_tuning(usbphyc, child, index); in stm32_usbphyc_probe()
749 ret = stm32_usbphyc_clk48_register(usbphyc); in stm32_usbphyc_probe()
755 version = readl_relaxed(usbphyc->base + STM32_USBPHYC_VERSION); in stm32_usbphyc_probe()
764 clk_disable_unprepare(usbphyc->clk); in stm32_usbphyc_probe()
771 struct stm32_usbphyc *usbphyc = dev_get_drvdata(&pdev->dev); in stm32_usbphyc_remove() local
775 for (port = 0; port < usbphyc->nphys; port++) in stm32_usbphyc_remove()
776 if (usbphyc->phys[port]->active) in stm32_usbphyc_remove()
777 stm32_usbphyc_phy_exit(usbphyc->phys[port]->phy); in stm32_usbphyc_remove()
779 stm32_usbphyc_clk48_unregister(usbphyc); in stm32_usbphyc_remove()
781 clk_disable_unprepare(usbphyc->clk); in stm32_usbphyc_remove()
788 struct stm32_usbphyc *usbphyc = dev_get_drvdata(dev); in stm32_usbphyc_resume() local
792 if (usbphyc->switch_setup >= 0) in stm32_usbphyc_resume()
793 stm32_usbphyc_switch_setup(usbphyc, usbphyc->switch_setup); in stm32_usbphyc_resume()
795 for (port = 0; port < usbphyc->nphys; port++) { in stm32_usbphyc_resume()
796 usbphyc_phy = usbphyc->phys[port]; in stm32_usbphyc_resume()
797 writel_relaxed(usbphyc_phy->tune, usbphyc->base + STM32_USBPHYC_TUNE(port)); in stm32_usbphyc_resume()