Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

phy: exynos5-usbdrd: convert Vbus supplies to regulator_bulk

Using the regulator_bulk APIs, the handling of power supplies becomes
much simpler. There is no need anymore to check if regulators have been
acquired or not, the bulk APIs will do all the work for us. We can also
drop the various handles to the individual power supplies in the driver
runtime data and instead simply treat them all as one thing. Error
cleanup also becomes much simpler.

Converting to the regulator_bulk APIs also makes it easier to add
support for those SoCs that have additional power supplies for the PHY.
Google Tensor gs101 is one example of such a SoC. Otherwise we'd have
to add all additional supplies individually via individual calls to
regulator_get() and enable/disable handle them all individually,
including complicated error handling. That doesn't scale and clutters
the code.

Just update the code to use the regulator_bulk APIs.

Signed-off-by: André Draszik <andre.draszik@linaro.org>
Tested-by: Will McVicker <willmcvicker@google.com>
Reviewed-by: Peter Griffin <peter.griffin@linaro.org>
Tested-by: Peter Griffin <peter.griffin@linaro.org>
Link: https://lore.kernel.org/r/20240617-usb-phy-gs101-v3-5-b66de9ae7424@linaro.org
Signed-off-by: Vinod Koul <vkoul@kernel.org>

authored by

André Draszik and committed by
Vinod Koul
497ddafe 26ba3261

+39 -47
+39 -47
drivers/phy/samsung/phy-exynos5-usbdrd.c
··· 189 189 int n_clks; 190 190 const char * const *core_clk_names; 191 191 int n_core_clks; 192 + const char * const *regulator_names; 193 + int n_regulators; 192 194 u32 pmu_offset_usbdrd0_phy; 193 195 u32 pmu_offset_usbdrd0_phy_ss; 194 196 u32 pmu_offset_usbdrd1_phy; ··· 207 205 * instances each with its 'phy' and 'phy_cfg'. 208 206 * @extrefclk: frequency select settings when using 'separate 209 207 * reference clocks' for SS and HS operations 210 - * @vbus: VBUS regulator for phy 211 - * @vbus_boost: Boost regulator for VBUS present on few Exynos boards 208 + * @regulators: regulators for phy 212 209 */ 213 210 struct exynos5_usbdrd_phy { 214 211 struct device *dev; ··· 223 222 const struct exynos5_usbdrd_phy_config *phy_cfg; 224 223 } phys[EXYNOS5_DRDPHYS_NUM]; 225 224 u32 extrefclk; 226 - struct regulator *vbus; 227 - struct regulator *vbus_boost; 225 + struct regulator_bulk_data *regulators; 228 226 }; 229 227 230 228 static inline ··· 507 507 return ret; 508 508 509 509 /* Enable VBUS supply */ 510 - if (phy_drd->vbus_boost) { 511 - ret = regulator_enable(phy_drd->vbus_boost); 512 - if (ret) { 513 - dev_err(phy_drd->dev, 514 - "Failed to enable VBUS boost supply\n"); 515 - goto fail_vbus; 516 - } 517 - } 518 - 519 - if (phy_drd->vbus) { 520 - ret = regulator_enable(phy_drd->vbus); 521 - if (ret) { 522 - dev_err(phy_drd->dev, "Failed to enable VBUS supply\n"); 523 - goto fail_vbus_boost; 524 - } 510 + ret = regulator_bulk_enable(phy_drd->drv_data->n_regulators, 511 + phy_drd->regulators); 512 + if (ret) { 513 + dev_err(phy_drd->dev, "Failed to enable PHY regulator(s)\n"); 514 + goto fail_vbus; 525 515 } 526 516 527 517 /* Power-on PHY */ 528 518 inst->phy_cfg->phy_isol(inst, false); 529 519 530 520 return 0; 531 - 532 - fail_vbus_boost: 533 - if (phy_drd->vbus_boost) 534 - regulator_disable(phy_drd->vbus_boost); 535 521 536 522 fail_vbus: 537 523 clk_bulk_disable_unprepare(phy_drd->drv_data->n_core_clks, ··· 537 551 inst->phy_cfg->phy_isol(inst, true); 538 552 539 553 /* Disable VBUS supply */ 540 - if (phy_drd->vbus) 541 - regulator_disable(phy_drd->vbus); 542 - if (phy_drd->vbus_boost) 543 - regulator_disable(phy_drd->vbus_boost); 554 + regulator_bulk_disable(phy_drd->drv_data->n_regulators, 555 + phy_drd->regulators); 544 556 545 557 clk_bulk_disable_unprepare(phy_drd->drv_data->n_core_clks, 546 558 phy_drd->core_clks); ··· 945 961 "ref", "phy_pipe", "phy_utmi", "itp", 946 962 }; 947 963 964 + static const char * const exynos5_regulator_names[] = { 965 + "vbus", "vbus-boost", 966 + }; 967 + 948 968 static const struct exynos5_usbdrd_phy_drvdata exynos5420_usbdrd_phy = { 949 969 .phy_cfg = phy_cfg_exynos5, 950 970 .phy_ops = &exynos5_usbdrd_phy_ops, ··· 958 970 .n_clks = ARRAY_SIZE(exynos5_clk_names), 959 971 .core_clk_names = exynos5_core_clk_names, 960 972 .n_core_clks = ARRAY_SIZE(exynos5_core_clk_names), 973 + .regulator_names = exynos5_regulator_names, 974 + .n_regulators = ARRAY_SIZE(exynos5_regulator_names), 961 975 }; 962 976 963 977 static const struct exynos5_usbdrd_phy_drvdata exynos5250_usbdrd_phy = { ··· 970 980 .n_clks = ARRAY_SIZE(exynos5_clk_names), 971 981 .core_clk_names = exynos5_core_clk_names, 972 982 .n_core_clks = ARRAY_SIZE(exynos5_core_clk_names), 983 + .regulator_names = exynos5_regulator_names, 984 + .n_regulators = ARRAY_SIZE(exynos5_regulator_names), 973 985 }; 974 986 975 987 static const struct exynos5_usbdrd_phy_drvdata exynos5433_usbdrd_phy = { ··· 983 991 .n_clks = ARRAY_SIZE(exynos5_clk_names), 984 992 .core_clk_names = exynos5433_core_clk_names, 985 993 .n_core_clks = ARRAY_SIZE(exynos5433_core_clk_names), 994 + .regulator_names = exynos5_regulator_names, 995 + .n_regulators = ARRAY_SIZE(exynos5_regulator_names), 986 996 }; 987 997 988 998 static const struct exynos5_usbdrd_phy_drvdata exynos7_usbdrd_phy = { ··· 995 1001 .n_clks = ARRAY_SIZE(exynos5_clk_names), 996 1002 .core_clk_names = exynos5433_core_clk_names, 997 1003 .n_core_clks = ARRAY_SIZE(exynos5433_core_clk_names), 1004 + .regulator_names = exynos5_regulator_names, 1005 + .n_regulators = ARRAY_SIZE(exynos5_regulator_names), 998 1006 }; 999 1007 1000 1008 static const struct exynos5_usbdrd_phy_drvdata exynos850_usbdrd_phy = { ··· 1007 1011 .n_clks = ARRAY_SIZE(exynos5_clk_names), 1008 1012 .core_clk_names = exynos5_core_clk_names, 1009 1013 .n_core_clks = ARRAY_SIZE(exynos5_core_clk_names), 1014 + .regulator_names = exynos5_regulator_names, 1015 + .n_regulators = ARRAY_SIZE(exynos5_regulator_names), 1010 1016 }; 1011 1017 1012 1018 static const struct of_device_id exynos5_usbdrd_phy_of_match[] = { ··· 1081 1083 if (channel < 0) 1082 1084 dev_dbg(dev, "Not a multi-controller usbdrd phy\n"); 1083 1085 1084 - /* Get Vbus regulators */ 1085 - phy_drd->vbus = devm_regulator_get(dev, "vbus"); 1086 - if (IS_ERR(phy_drd->vbus)) { 1087 - ret = PTR_ERR(phy_drd->vbus); 1088 - if (ret == -EPROBE_DEFER) 1089 - return ret; 1090 - 1091 - dev_warn(dev, "Failed to get VBUS supply regulator\n"); 1092 - phy_drd->vbus = NULL; 1093 - } 1094 - 1095 - phy_drd->vbus_boost = devm_regulator_get(dev, "vbus-boost"); 1096 - if (IS_ERR(phy_drd->vbus_boost)) { 1097 - ret = PTR_ERR(phy_drd->vbus_boost); 1098 - if (ret == -EPROBE_DEFER) 1099 - return ret; 1100 - 1101 - dev_warn(dev, "Failed to get VBUS boost supply regulator\n"); 1102 - phy_drd->vbus_boost = NULL; 1103 - } 1086 + /* Get regulators */ 1087 + phy_drd->regulators = devm_kcalloc(dev, 1088 + drv_data->n_regulators, 1089 + sizeof(*phy_drd->regulators), 1090 + GFP_KERNEL); 1091 + if (!phy_drd->regulators) 1092 + return ENOMEM; 1093 + regulator_bulk_set_supply_names(phy_drd->regulators, 1094 + drv_data->regulator_names, 1095 + drv_data->n_regulators); 1096 + ret = devm_regulator_bulk_get(dev, drv_data->n_regulators, 1097 + phy_drd->regulators); 1098 + if (ret) 1099 + return dev_err_probe(dev, ret, "failed to get regulators\n"); 1104 1100 1105 1101 dev_vdbg(dev, "Creating usbdrd_phy phy\n"); 1106 1102