Commit 497ddafe authored by André Draszik's avatar André Draszik Committed by Vinod Koul

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: default avatarAndré Draszik <andre.draszik@linaro.org>
Tested-by: default avatarWill McVicker <willmcvicker@google.com>
Reviewed-by: default avatarPeter Griffin <peter.griffin@linaro.org>
Tested-by: default avatarPeter Griffin <peter.griffin@linaro.org>
Link: https://lore.kernel.org/r/20240617-usb-phy-gs101-v3-5-b66de9ae7424@linaro.orgSigned-off-by: default avatarVinod Koul <vkoul@kernel.org>
parent 26ba3261
...@@ -189,6 +189,8 @@ struct exynos5_usbdrd_phy_drvdata { ...@@ -189,6 +189,8 @@ struct exynos5_usbdrd_phy_drvdata {
int n_clks; int n_clks;
const char * const *core_clk_names; const char * const *core_clk_names;
int n_core_clks; int n_core_clks;
const char * const *regulator_names;
int n_regulators;
u32 pmu_offset_usbdrd0_phy; u32 pmu_offset_usbdrd0_phy;
u32 pmu_offset_usbdrd0_phy_ss; u32 pmu_offset_usbdrd0_phy_ss;
u32 pmu_offset_usbdrd1_phy; u32 pmu_offset_usbdrd1_phy;
...@@ -205,8 +207,7 @@ struct exynos5_usbdrd_phy_drvdata { ...@@ -205,8 +207,7 @@ struct exynos5_usbdrd_phy_drvdata {
* instances each with its 'phy' and 'phy_cfg'. * instances each with its 'phy' and 'phy_cfg'.
* @extrefclk: frequency select settings when using 'separate * @extrefclk: frequency select settings when using 'separate
* reference clocks' for SS and HS operations * reference clocks' for SS and HS operations
* @vbus: VBUS regulator for phy * @regulators: regulators for phy
* @vbus_boost: Boost regulator for VBUS present on few Exynos boards
*/ */
struct exynos5_usbdrd_phy { struct exynos5_usbdrd_phy {
struct device *dev; struct device *dev;
...@@ -222,8 +223,7 @@ struct exynos5_usbdrd_phy { ...@@ -222,8 +223,7 @@ struct exynos5_usbdrd_phy {
const struct exynos5_usbdrd_phy_config *phy_cfg; const struct exynos5_usbdrd_phy_config *phy_cfg;
} phys[EXYNOS5_DRDPHYS_NUM]; } phys[EXYNOS5_DRDPHYS_NUM];
u32 extrefclk; u32 extrefclk;
struct regulator *vbus; struct regulator_bulk_data *regulators;
struct regulator *vbus_boost;
}; };
static inline static inline
...@@ -507,21 +507,11 @@ static int exynos5_usbdrd_phy_power_on(struct phy *phy) ...@@ -507,21 +507,11 @@ static int exynos5_usbdrd_phy_power_on(struct phy *phy)
return ret; return ret;
/* Enable VBUS supply */ /* Enable VBUS supply */
if (phy_drd->vbus_boost) { ret = regulator_bulk_enable(phy_drd->drv_data->n_regulators,
ret = regulator_enable(phy_drd->vbus_boost); phy_drd->regulators);
if (ret) { if (ret) {
dev_err(phy_drd->dev, dev_err(phy_drd->dev, "Failed to enable PHY regulator(s)\n");
"Failed to enable VBUS boost supply\n"); goto fail_vbus;
goto fail_vbus;
}
}
if (phy_drd->vbus) {
ret = regulator_enable(phy_drd->vbus);
if (ret) {
dev_err(phy_drd->dev, "Failed to enable VBUS supply\n");
goto fail_vbus_boost;
}
} }
/* Power-on PHY */ /* Power-on PHY */
...@@ -529,10 +519,6 @@ static int exynos5_usbdrd_phy_power_on(struct phy *phy) ...@@ -529,10 +519,6 @@ static int exynos5_usbdrd_phy_power_on(struct phy *phy)
return 0; return 0;
fail_vbus_boost:
if (phy_drd->vbus_boost)
regulator_disable(phy_drd->vbus_boost);
fail_vbus: fail_vbus:
clk_bulk_disable_unprepare(phy_drd->drv_data->n_core_clks, clk_bulk_disable_unprepare(phy_drd->drv_data->n_core_clks,
phy_drd->core_clks); phy_drd->core_clks);
...@@ -551,10 +537,8 @@ static int exynos5_usbdrd_phy_power_off(struct phy *phy) ...@@ -551,10 +537,8 @@ static int exynos5_usbdrd_phy_power_off(struct phy *phy)
inst->phy_cfg->phy_isol(inst, true); inst->phy_cfg->phy_isol(inst, true);
/* Disable VBUS supply */ /* Disable VBUS supply */
if (phy_drd->vbus) regulator_bulk_disable(phy_drd->drv_data->n_regulators,
regulator_disable(phy_drd->vbus); phy_drd->regulators);
if (phy_drd->vbus_boost)
regulator_disable(phy_drd->vbus_boost);
clk_bulk_disable_unprepare(phy_drd->drv_data->n_core_clks, clk_bulk_disable_unprepare(phy_drd->drv_data->n_core_clks,
phy_drd->core_clks); phy_drd->core_clks);
...@@ -961,6 +945,10 @@ static const char * const exynos5433_core_clk_names[] = { ...@@ -961,6 +945,10 @@ static const char * const exynos5433_core_clk_names[] = {
"ref", "phy_pipe", "phy_utmi", "itp", "ref", "phy_pipe", "phy_utmi", "itp",
}; };
static const char * const exynos5_regulator_names[] = {
"vbus", "vbus-boost",
};
static const struct exynos5_usbdrd_phy_drvdata exynos5420_usbdrd_phy = { static const struct exynos5_usbdrd_phy_drvdata exynos5420_usbdrd_phy = {
.phy_cfg = phy_cfg_exynos5, .phy_cfg = phy_cfg_exynos5,
.phy_ops = &exynos5_usbdrd_phy_ops, .phy_ops = &exynos5_usbdrd_phy_ops,
...@@ -970,6 +958,8 @@ static const struct exynos5_usbdrd_phy_drvdata exynos5420_usbdrd_phy = { ...@@ -970,6 +958,8 @@ static const struct exynos5_usbdrd_phy_drvdata exynos5420_usbdrd_phy = {
.n_clks = ARRAY_SIZE(exynos5_clk_names), .n_clks = ARRAY_SIZE(exynos5_clk_names),
.core_clk_names = exynos5_core_clk_names, .core_clk_names = exynos5_core_clk_names,
.n_core_clks = ARRAY_SIZE(exynos5_core_clk_names), .n_core_clks = ARRAY_SIZE(exynos5_core_clk_names),
.regulator_names = exynos5_regulator_names,
.n_regulators = ARRAY_SIZE(exynos5_regulator_names),
}; };
static const struct exynos5_usbdrd_phy_drvdata exynos5250_usbdrd_phy = { static const struct exynos5_usbdrd_phy_drvdata exynos5250_usbdrd_phy = {
...@@ -980,6 +970,8 @@ static const struct exynos5_usbdrd_phy_drvdata exynos5250_usbdrd_phy = { ...@@ -980,6 +970,8 @@ static const struct exynos5_usbdrd_phy_drvdata exynos5250_usbdrd_phy = {
.n_clks = ARRAY_SIZE(exynos5_clk_names), .n_clks = ARRAY_SIZE(exynos5_clk_names),
.core_clk_names = exynos5_core_clk_names, .core_clk_names = exynos5_core_clk_names,
.n_core_clks = ARRAY_SIZE(exynos5_core_clk_names), .n_core_clks = ARRAY_SIZE(exynos5_core_clk_names),
.regulator_names = exynos5_regulator_names,
.n_regulators = ARRAY_SIZE(exynos5_regulator_names),
}; };
static const struct exynos5_usbdrd_phy_drvdata exynos5433_usbdrd_phy = { static const struct exynos5_usbdrd_phy_drvdata exynos5433_usbdrd_phy = {
...@@ -991,6 +983,8 @@ static const struct exynos5_usbdrd_phy_drvdata exynos5433_usbdrd_phy = { ...@@ -991,6 +983,8 @@ static const struct exynos5_usbdrd_phy_drvdata exynos5433_usbdrd_phy = {
.n_clks = ARRAY_SIZE(exynos5_clk_names), .n_clks = ARRAY_SIZE(exynos5_clk_names),
.core_clk_names = exynos5433_core_clk_names, .core_clk_names = exynos5433_core_clk_names,
.n_core_clks = ARRAY_SIZE(exynos5433_core_clk_names), .n_core_clks = ARRAY_SIZE(exynos5433_core_clk_names),
.regulator_names = exynos5_regulator_names,
.n_regulators = ARRAY_SIZE(exynos5_regulator_names),
}; };
static const struct exynos5_usbdrd_phy_drvdata exynos7_usbdrd_phy = { static const struct exynos5_usbdrd_phy_drvdata exynos7_usbdrd_phy = {
...@@ -1001,6 +995,8 @@ static const struct exynos5_usbdrd_phy_drvdata exynos7_usbdrd_phy = { ...@@ -1001,6 +995,8 @@ static const struct exynos5_usbdrd_phy_drvdata exynos7_usbdrd_phy = {
.n_clks = ARRAY_SIZE(exynos5_clk_names), .n_clks = ARRAY_SIZE(exynos5_clk_names),
.core_clk_names = exynos5433_core_clk_names, .core_clk_names = exynos5433_core_clk_names,
.n_core_clks = ARRAY_SIZE(exynos5433_core_clk_names), .n_core_clks = ARRAY_SIZE(exynos5433_core_clk_names),
.regulator_names = exynos5_regulator_names,
.n_regulators = ARRAY_SIZE(exynos5_regulator_names),
}; };
static const struct exynos5_usbdrd_phy_drvdata exynos850_usbdrd_phy = { static const struct exynos5_usbdrd_phy_drvdata exynos850_usbdrd_phy = {
...@@ -1011,6 +1007,8 @@ static const struct exynos5_usbdrd_phy_drvdata exynos850_usbdrd_phy = { ...@@ -1011,6 +1007,8 @@ static const struct exynos5_usbdrd_phy_drvdata exynos850_usbdrd_phy = {
.n_clks = ARRAY_SIZE(exynos5_clk_names), .n_clks = ARRAY_SIZE(exynos5_clk_names),
.core_clk_names = exynos5_core_clk_names, .core_clk_names = exynos5_core_clk_names,
.n_core_clks = ARRAY_SIZE(exynos5_core_clk_names), .n_core_clks = ARRAY_SIZE(exynos5_core_clk_names),
.regulator_names = exynos5_regulator_names,
.n_regulators = ARRAY_SIZE(exynos5_regulator_names),
}; };
static const struct of_device_id exynos5_usbdrd_phy_of_match[] = { static const struct of_device_id exynos5_usbdrd_phy_of_match[] = {
...@@ -1083,26 +1081,20 @@ static int exynos5_usbdrd_phy_probe(struct platform_device *pdev) ...@@ -1083,26 +1081,20 @@ static int exynos5_usbdrd_phy_probe(struct platform_device *pdev)
if (channel < 0) if (channel < 0)
dev_dbg(dev, "Not a multi-controller usbdrd phy\n"); dev_dbg(dev, "Not a multi-controller usbdrd phy\n");
/* Get Vbus regulators */ /* Get regulators */
phy_drd->vbus = devm_regulator_get(dev, "vbus"); phy_drd->regulators = devm_kcalloc(dev,
if (IS_ERR(phy_drd->vbus)) { drv_data->n_regulators,
ret = PTR_ERR(phy_drd->vbus); sizeof(*phy_drd->regulators),
if (ret == -EPROBE_DEFER) GFP_KERNEL);
return ret; if (!phy_drd->regulators)
return ENOMEM;
dev_warn(dev, "Failed to get VBUS supply regulator\n"); regulator_bulk_set_supply_names(phy_drd->regulators,
phy_drd->vbus = NULL; drv_data->regulator_names,
} drv_data->n_regulators);
ret = devm_regulator_bulk_get(dev, drv_data->n_regulators,
phy_drd->vbus_boost = devm_regulator_get(dev, "vbus-boost"); phy_drd->regulators);
if (IS_ERR(phy_drd->vbus_boost)) { if (ret)
ret = PTR_ERR(phy_drd->vbus_boost); return dev_err_probe(dev, ret, "failed to get regulators\n");
if (ret == -EPROBE_DEFER)
return ret;
dev_warn(dev, "Failed to get VBUS boost supply regulator\n");
phy_drd->vbus_boost = NULL;
}
dev_vdbg(dev, "Creating usbdrd_phy phy\n"); dev_vdbg(dev, "Creating usbdrd_phy phy\n");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment