Lines Matching +full:vbus +full:- +full:boost +full:- +full:supply

1 // SPDX-License-Identifier: GPL-2.0
10 #include <linux/clk-provider.h>
138 struct regulator *vbus; member
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()
192 ret = regulator_disable(usbphyc->vdda1v8); in stm32_usbphyc_regulators_disable()
196 ret = regulator_disable(usbphyc->vdda1v1); in stm32_usbphyc_regulators_disable()
216 * <=> PLLFRACIN = ((FVCO / (INFF*2)) - PLLNDIV) * 2^16 in stm32_usbphyc_get_pll_params()
222 pll_params->ndiv = (u8)ndiv; in stm32_usbphyc_get_pll_params()
226 frac = frac - (ndiv * (1 << 16)); in stm32_usbphyc_get_pll_params()
227 pll_params->frac = (u16)frac; in stm32_usbphyc_get_pll_params()
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()
241 return -EINVAL; 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()
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()
279 if (atomic_dec_return(&usbphyc->n_pll_cons) > 0) in stm32_usbphyc_pll_disable()
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()
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()
335 u32 reg_mon = STM32_USBPHYC_MONITOR(usbphyc_phy->index); 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()
356 usbphyc_phy->active = true; in stm32_usbphyc_phy_init()
369 struct stm32_usbphyc *usbphyc = usbphyc_phy->usbphyc; in stm32_usbphyc_phy_exit()
371 usbphyc_phy->active = false; in stm32_usbphyc_phy_exit()
380 if (usbphyc_phy->vbus) in stm32_usbphyc_phy_power_on()
381 return regulator_enable(usbphyc_phy->vbus); in stm32_usbphyc_phy_power_on()
390 if (usbphyc_phy->vbus) in stm32_usbphyc_phy_power_off()
391 return regulator_disable(usbphyc_phy->vbus); in stm32_usbphyc_phy_power_off()
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()
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()
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()
470 ret = of_property_read_u32(np, "st,current-boost-microamp", &val); in stm32_usbphyc_phy_tuning()
471 if (ret != -EINVAL) { in stm32_usbphyc_phy_tuning()
474 usbphyc_phy->tune |= INCURREN | FIELD_PREP(INCURRINT, val); in stm32_usbphyc_phy_tuning()
476 dev_warn(usbphyc->dev, "phy%d: invalid st,current-boost-microamp\n", index); in stm32_usbphyc_phy_tuning()
480 if (!of_property_read_bool(np, "st,no-lsfs-fb-cap")) in stm32_usbphyc_phy_tuning()
481 usbphyc_phy->tune |= LFSCAPEN; in stm32_usbphyc_phy_tuning()
483 if (of_property_read_bool(np, "st,decrease-hs-slew-rate")) in stm32_usbphyc_phy_tuning()
484 usbphyc_phy->tune |= HSDRVSLEW; in stm32_usbphyc_phy_tuning()
486 ret = of_property_read_u32(np, "st,tune-hs-dc-level", &val); in stm32_usbphyc_phy_tuning()
487 if (ret != -EINVAL) { in stm32_usbphyc_phy_tuning()
490 usbphyc_phy->tune |= HSDRVDCCUR; in stm32_usbphyc_phy_tuning()
493 usbphyc_phy->tune |= HSDRVCURINCR | FIELD_PREP(HSDRVDCLEV, val); 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()
500 if (of_property_read_bool(np, "st,enable-fs-rftime-tuning")) in stm32_usbphyc_phy_tuning()
501 usbphyc_phy->tune |= FSDRVRFADJ; in stm32_usbphyc_phy_tuning()
503 if (of_property_read_bool(np, "st,enable-hs-rftime-reduction")) in stm32_usbphyc_phy_tuning()
504 usbphyc_phy->tune |= HSDRVRFRED; in stm32_usbphyc_phy_tuning()
506 ret = of_property_read_u32(np, "st,trim-hs-current", &val); in stm32_usbphyc_phy_tuning()
507 if (ret != -EINVAL) { in stm32_usbphyc_phy_tuning()
509 usbphyc_phy->tune |= FIELD_PREP(HSDRVCHKITRM, val); in stm32_usbphyc_phy_tuning()
511 dev_warn(usbphyc->dev, "phy%d: invalid st,trim-hs-current\n", index); in stm32_usbphyc_phy_tuning()
514 ret = of_property_read_u32(np, "st,trim-hs-impedance", &val); in stm32_usbphyc_phy_tuning()
515 if (ret != -EINVAL) { in stm32_usbphyc_phy_tuning()
517 usbphyc_phy->tune |= FIELD_PREP(HSDRVCHKZTRM, val); in stm32_usbphyc_phy_tuning()
519 dev_warn(usbphyc->dev, "phy%d: invalid st,trim-hs-impedance\n", index); in stm32_usbphyc_phy_tuning()
522 ret = of_property_read_u32(np, "st,tune-squelch-level", &val); in stm32_usbphyc_phy_tuning()
523 if (ret != -EINVAL) { in stm32_usbphyc_phy_tuning()
525 usbphyc_phy->tune |= FIELD_PREP(SQLCHCTL, val); in stm32_usbphyc_phy_tuning()
527 dev_warn(usbphyc->dev, "phy%d: invalid st,tune-squelch\n", index); in stm32_usbphyc_phy_tuning()
530 if (of_property_read_bool(np, "st,enable-hs-rx-gain-eq")) in stm32_usbphyc_phy_tuning()
531 usbphyc_phy->tune |= HDRXGNEQEN; in stm32_usbphyc_phy_tuning()
533 ret = of_property_read_u32(np, "st,tune-hs-rx-offset", &val); in stm32_usbphyc_phy_tuning()
534 if (ret != -EINVAL) { in stm32_usbphyc_phy_tuning()
536 usbphyc_phy->tune |= FIELD_PREP(HSRXOFF, val); 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()
541 if (of_property_read_bool(np, "st,no-hs-ftime-ctrl")) in stm32_usbphyc_phy_tuning()
542 usbphyc_phy->tune |= HSFALLPREEM; in stm32_usbphyc_phy_tuning()
544 if (!of_property_read_bool(np, "st,no-lsfs-sc")) in stm32_usbphyc_phy_tuning()
545 usbphyc_phy->tune |= SHTCCTCTLPROT; in stm32_usbphyc_phy_tuning()
547 if (of_property_read_bool(np, "st,enable-hs-tx-staggering")) in stm32_usbphyc_phy_tuning()
548 usbphyc_phy->tune |= STAGSEL; in stm32_usbphyc_phy_tuning()
551 usbphyc_phy->tune |= FIELD_PREP(OTPCOMP, otpcomp); in stm32_usbphyc_phy_tuning()
554 * By default, if no st,xxx tuning property is used, usbphyc_phy->tune is equal to in stm32_usbphyc_phy_tuning()
557 writel_relaxed(usbphyc_phy->tune, usbphyc->base + reg); in stm32_usbphyc_phy_tuning()
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()
577 struct device_node *phynode = args->np; in stm32_usbphyc_of_xlate()
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()
588 return ERR_PTR(-EINVAL); in stm32_usbphyc_of_xlate()
591 if (((usbphyc_phy->index == 0) && (args->args_count != 0)) || in stm32_usbphyc_of_xlate()
592 ((usbphyc_phy->index == 1) && (args->args_count != 1))) { in stm32_usbphyc_of_xlate()
594 usbphyc_phy->index); in stm32_usbphyc_of_xlate()
595 return ERR_PTR(-EINVAL); in stm32_usbphyc_of_xlate()
599 if (usbphyc_phy->index == 1) { 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()
605 return ERR_PTR(-EBUSY); in stm32_usbphyc_of_xlate()
610 return usbphyc_phy->phy; in stm32_usbphyc_of_xlate()
616 struct device *dev = &pdev->dev; in stm32_usbphyc_probe()
617 struct device_node *child, *np = dev->of_node; in stm32_usbphyc_probe()
624 return -ENOMEM; in stm32_usbphyc_probe()
625 usbphyc->dev = dev; 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()
649 if (ret == -EPROBE_DEFER) 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()
662 ret = -EPROBE_DEFER; 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()
671 ret = -ENOMEM; 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()
678 "failed to get vdda1v1 supply\n"); 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()
685 "failed to get vdda1v8 supply\n"); in stm32_usbphyc_probe()
697 if (ret != -EPROBE_DEFER) in stm32_usbphyc_probe()
706 ret = -ENOMEM; in stm32_usbphyc_probe()
711 if (ret || index > usbphyc->nphys) { in stm32_usbphyc_probe()
712 dev_err(&phy->dev, "invalid reg property: %d\n", ret); in stm32_usbphyc_probe()
714 ret = -EINVAL; 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()
730 if (ret == -EPROBE_DEFER) in stm32_usbphyc_probe()
732 usbphyc->phys[port]->vbus = NULL; 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()
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()
781 clk_disable_unprepare(usbphyc->clk); in stm32_usbphyc_remove()
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()
806 { .compatible = "st,stm32mp1-usbphyc", },
816 .name = "stm32-usbphyc",