Skip to content

Commit 3be8812

Browse files
Roger Quadroskishon
authored andcommitted
phy: core: Support regulator supply for PHY power
Some PHYs can be powered by an external power regulator. e.g. USB_HS PHY on DRA7 SoC. Make the PHY core support a power regulator. Signed-off-by: Roger Quadros <rogerq@ti.com> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
1 parent 016e0d3 commit 3be8812

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

drivers/phy/phy-core.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <linux/phy/phy.h>
2222
#include <linux/idr.h>
2323
#include <linux/pm_runtime.h>
24+
#include <linux/regulator/consumer.h>
2425

2526
static struct class *phy_class;
2627
static DEFINE_MUTEX(phy_provider_mutex);
@@ -226,6 +227,12 @@ int phy_power_on(struct phy *phy)
226227
if (!phy)
227228
return 0;
228229

230+
if (phy->pwr) {
231+
ret = regulator_enable(phy->pwr);
232+
if (ret)
233+
return ret;
234+
}
235+
229236
ret = phy_pm_runtime_get_sync(phy);
230237
if (ret < 0 && ret != -ENOTSUPP)
231238
return ret;
@@ -247,6 +254,8 @@ int phy_power_on(struct phy *phy)
247254
out:
248255
mutex_unlock(&phy->mutex);
249256
phy_pm_runtime_put_sync(phy);
257+
if (phy->pwr)
258+
regulator_disable(phy->pwr);
250259

251260
return ret;
252261
}
@@ -272,6 +281,9 @@ int phy_power_off(struct phy *phy)
272281
mutex_unlock(&phy->mutex);
273282
phy_pm_runtime_put(phy);
274283

284+
if (phy->pwr)
285+
regulator_disable(phy->pwr);
286+
275287
return 0;
276288
}
277289
EXPORT_SYMBOL_GPL(phy_power_off);
@@ -588,6 +600,16 @@ struct phy *phy_create(struct device *dev, const struct phy_ops *ops,
588600
goto free_phy;
589601
}
590602

603+
/* phy-supply */
604+
phy->pwr = regulator_get_optional(dev, "phy");
605+
if (IS_ERR(phy->pwr)) {
606+
if (PTR_ERR(phy->pwr) == -EPROBE_DEFER) {
607+
ret = -EPROBE_DEFER;
608+
goto free_ida;
609+
}
610+
phy->pwr = NULL;
611+
}
612+
591613
device_initialize(&phy->dev);
592614
mutex_init(&phy->mutex);
593615

@@ -617,6 +639,9 @@ struct phy *phy_create(struct device *dev, const struct phy_ops *ops,
617639
put_device(&phy->dev); /* calls phy_release() which frees resources */
618640
return ERR_PTR(ret);
619641

642+
free_ida:
643+
ida_simple_remove(&phy_ida, phy->id);
644+
620645
free_phy:
621646
kfree(phy);
622647
return ERR_PTR(ret);
@@ -800,6 +825,7 @@ static void phy_release(struct device *dev)
800825

801826
phy = to_phy(dev);
802827
dev_vdbg(dev, "releasing '%s'\n", dev_name(dev));
828+
regulator_put(phy->pwr);
803829
ida_simple_remove(&phy_ida, phy->id);
804830
kfree(phy);
805831
}

include/linux/phy/phy.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/of.h>
1919
#include <linux/device.h>
2020
#include <linux/pm_runtime.h>
21+
#include <linux/regulator/consumer.h>
2122

2223
struct phy;
2324

@@ -65,6 +66,7 @@ struct phy {
6566
int init_count;
6667
int power_count;
6768
struct phy_attrs attrs;
69+
struct regulator *pwr;
6870
};
6971

7072
/**

0 commit comments

Comments
 (0)