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

net: stmmac: dwmac-rk: Use standard devicetree property for phy regulator

Currently, dwmac-rk uses a custom propety "phy_regulator" to get the name of the
right regulator to use to power on or power off the phy. This commit converts the
driver to use phy-supply devicetree property and the corresponding API, it cleans
the code a bit and make it simpler to maintain. This also replaces the property
phy_regulator by the standard property phy-supply in rk3288-evb-rk808.dts.

Signed-off-by: Romain Perier <romain.perier@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Romain Perier and committed by
David S. Miller
2e12f536 68c3a884

+22 -43
+1 -1
arch/arm/boot/dts/rk3288-evb-rk808.dts
··· 161 161 }; 162 162 163 163 &gmac { 164 - phy_regulator = "vcc_phy"; 164 + phy-supply = <&vcc_phy>; 165 165 phy-mode = "rgmii"; 166 166 clock_in_out = "input"; 167 167 snps,reset-gpio = <&gpio4 7 0>;
+21 -42
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
··· 32 32 struct rk_priv_data { 33 33 struct platform_device *pdev; 34 34 int phy_iface; 35 - char regulator[32]; 35 + struct regulator *regulator; 36 36 37 37 bool clk_enabled; 38 38 bool clock_input; ··· 287 287 288 288 static int phy_power_on(struct rk_priv_data *bsp_priv, bool enable) 289 289 { 290 - struct regulator *ldo; 291 - char *ldostr = bsp_priv->regulator; 290 + struct regulator *ldo = bsp_priv->regulator; 292 291 int ret; 293 292 struct device *dev = &bsp_priv->pdev->dev; 294 293 295 - if (!ldostr) { 296 - dev_err(dev, "%s: no ldo found\n", __func__); 294 + if (!ldo) { 295 + dev_err(dev, "%s: no regulator found\n", __func__); 297 296 return -1; 298 297 } 299 298 300 - ldo = regulator_get(NULL, ldostr); 301 - if (!ldo) { 302 - dev_err(dev, "\n%s get ldo %s failed\n", __func__, ldostr); 299 + if (enable) { 300 + ret = regulator_enable(ldo); 301 + if (ret) 302 + dev_err(dev, "%s: fail to enable phy-supply\n", 303 + __func__); 303 304 } else { 304 - if (enable) { 305 - if (!regulator_is_enabled(ldo)) { 306 - ret = regulator_enable(ldo); 307 - if (ret != 0) 308 - dev_err(dev, "%s: fail to enable %s\n", 309 - __func__, ldostr); 310 - else 311 - dev_info(dev, "turn on ldo done.\n"); 312 - } else { 313 - dev_warn(dev, "%s is enabled before enable", 314 - ldostr); 315 - } 316 - } else { 317 - if (regulator_is_enabled(ldo)) { 318 - ret = regulator_disable(ldo); 319 - if (ret != 0) 320 - dev_err(dev, "%s: fail to disable %s\n", 321 - __func__, ldostr); 322 - else 323 - dev_info(dev, "turn off ldo done.\n"); 324 - } else { 325 - dev_warn(dev, "%s is disabled before disable", 326 - ldostr); 327 - } 328 - } 329 - regulator_put(ldo); 305 + ret = regulator_disable(ldo); 306 + if (ret) 307 + dev_err(dev, "%s: fail to disable phy-supply\n", 308 + __func__); 330 309 } 331 310 332 311 return 0; ··· 325 346 326 347 bsp_priv->phy_iface = of_get_phy_mode(dev->of_node); 327 348 328 - ret = of_property_read_string(dev->of_node, "phy_regulator", &strings); 329 - if (ret) { 330 - dev_warn(dev, "%s: Can not read property: phy_regulator.\n", 331 - __func__); 332 - } else { 333 - dev_info(dev, "%s: PHY power controlled by regulator(%s).\n", 334 - __func__, strings); 335 - strcpy(bsp_priv->regulator, strings); 349 + bsp_priv->regulator = devm_regulator_get_optional(dev, "phy"); 350 + if (IS_ERR(bsp_priv->regulator)) { 351 + if (PTR_ERR(bsp_priv->regulator) == -EPROBE_DEFER) { 352 + dev_err(dev, "phy regulator is not available yet, deferred probing\n"); 353 + return ERR_PTR(-EPROBE_DEFER); 354 + } 355 + dev_err(dev, "no regulator found\n"); 356 + bsp_priv->regulator = NULL; 336 357 } 337 358 338 359 ret = of_property_read_string(dev->of_node, "clock_in_out", &strings);