Skip to content

Commit f17ca45

Browse files
dlechrkhuangtao
authored andcommitted
UPSTREAM: phy: Add set_mode callback
The initial use for this is for PHYs that have a mode related to USB OTG. There are several SoCs (e.g. TI OMAP and DA8xx) that have a mode setting in the USB PHY to override OTG VBUS and ID signals. Of course, the enum can be expaned in the future to include modes for other types of PHYs as well. Change-Id: Iebc730d7e41c2910fa1be98cbf275d2c73358050 Suggested-by: Kishon Vijay Abraham I <kishon@ti.com> Signed-off-by: David Lechner <david@lechnology.com> Signed-off-by: Huang, Tao <huangtao@rock-chips.com> (cherry picked from commit 300eb01)
1 parent c0a875c commit f17ca45

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

drivers/phy/phy-core.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,21 @@ int phy_power_off(struct phy *phy)
342342
}
343343
EXPORT_SYMBOL_GPL(phy_power_off);
344344

345+
int phy_set_mode(struct phy *phy, enum phy_mode mode)
346+
{
347+
int ret;
348+
349+
if (!phy || !phy->ops->set_mode)
350+
return 0;
351+
352+
mutex_lock(&phy->mutex);
353+
ret = phy->ops->set_mode(phy, mode);
354+
mutex_unlock(&phy->mutex);
355+
356+
return ret;
357+
}
358+
EXPORT_SYMBOL_GPL(phy_set_mode);
359+
345360
/**
346361
* _of_phy_get() - lookup and obtain a reference to a phy by phandle
347362
* @np: device_node for which to get the phy

include/linux/phy/phy.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,28 @@
2222

2323
struct phy;
2424

25+
enum phy_mode {
26+
PHY_MODE_INVALID,
27+
PHY_MODE_USB_HOST,
28+
PHY_MODE_USB_DEVICE,
29+
PHY_MODE_USB_OTG,
30+
};
31+
2532
/**
2633
* struct phy_ops - set of function pointers for performing phy operations
2734
* @init: operation to be performed for initializing phy
2835
* @exit: operation to be performed while exiting
2936
* @power_on: powering on the phy
3037
* @power_off: powering off the phy
38+
* @set_mode: set the mode of the phy
3139
* @owner: the module owner containing the ops
3240
*/
3341
struct phy_ops {
3442
int (*init)(struct phy *phy);
3543
int (*exit)(struct phy *phy);
3644
int (*power_on)(struct phy *phy);
3745
int (*power_off)(struct phy *phy);
46+
int (*set_mode)(struct phy *phy, enum phy_mode mode);
3847
struct module *owner;
3948
};
4049

@@ -119,6 +128,7 @@ int phy_init(struct phy *phy);
119128
int phy_exit(struct phy *phy);
120129
int phy_power_on(struct phy *phy);
121130
int phy_power_off(struct phy *phy);
131+
int phy_set_mode(struct phy *phy, enum phy_mode mode);
122132
static inline int phy_get_bus_width(struct phy *phy)
123133
{
124134
return phy->attrs.bus_width;
@@ -224,6 +234,13 @@ static inline int phy_power_off(struct phy *phy)
224234
return -ENOSYS;
225235
}
226236

237+
static inline int phy_set_mode(struct phy *phy, enum phy_mode mode)
238+
{
239+
if (!phy)
240+
return 0;
241+
return -ENOSYS;
242+
}
243+
227244
static inline int phy_get_bus_width(struct phy *phy)
228245
{
229246
return -ENOSYS;

0 commit comments

Comments
 (0)