[PATCH u-boot-marvell 01/11] phy: add support for setting phy mode

Marek Behún marek.behun at nic.cz
Sun Apr 19 17:48:40 CEST 2020


Import enum phy_mode from Linux and add .set_mode method to generic-phy
operations structure.

Signed-off-by: Marek Behún <marek.behun at nic.cz>
---
 drivers/phy/phy-uclass.c | 11 +++++++++
 include/generic-phy.h    | 51 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+)

diff --git a/drivers/phy/phy-uclass.c b/drivers/phy/phy-uclass.c
index e201a90c8c..fc88791a54 100644
--- a/drivers/phy/phy-uclass.c
+++ b/drivers/phy/phy-uclass.c
@@ -161,6 +161,17 @@ int generic_phy_power_off(struct phy *phy)
 	return ops->power_off ? ops->power_off(phy) : 0;
 }
 
+int generic_phy_set_mode(struct phy *phy, enum phy_mode mode, int submode)
+{
+	struct phy_ops const *ops;
+
+	if (!phy)
+		return 0;
+	ops = phy_dev_ops(phy->dev);
+
+	return ops->set_mode ? ops->set_mode(phy, mode, submode) : 0;
+}
+
 UCLASS_DRIVER(phy) = {
 	.id		= UCLASS_PHY,
 	.name		= "phy",
diff --git a/include/generic-phy.h b/include/generic-phy.h
index 95caf58341..696677ae16 100644
--- a/include/generic-phy.h
+++ b/include/generic-phy.h
@@ -9,6 +9,29 @@
 
 struct ofnode_phandle_args;
 
+enum phy_mode {
+	PHY_MODE_INVALID = 0, /* leave this as zero */
+	PHY_MODE_USB_HOST,
+	PHY_MODE_USB_HOST_LS,
+	PHY_MODE_USB_HOST_FS,
+	PHY_MODE_USB_HOST_HS,
+	PHY_MODE_USB_HOST_SS,
+	PHY_MODE_USB_DEVICE,
+	PHY_MODE_USB_DEVICE_LS,
+	PHY_MODE_USB_DEVICE_FS,
+	PHY_MODE_USB_DEVICE_HS,
+	PHY_MODE_USB_DEVICE_SS,
+	PHY_MODE_USB_OTG,
+	PHY_MODE_UFS_HS_A,
+	PHY_MODE_UFS_HS_B,
+	PHY_MODE_PCIE,
+	PHY_MODE_ETHERNET,
+	PHY_MODE_MIPI_DPHY,
+	PHY_MODE_SATA,
+	PHY_MODE_LVDS,
+	PHY_MODE_DP
+};
+
 /**
  * struct phy - A handle to (allowing control of) a single phy port.
  *
@@ -120,6 +143,19 @@ struct phy_ops {
 	* @return 0 if OK, or a negative error code
 	*/
 	int	(*power_off)(struct phy *phy);
+
+	/**
+	* set_mode - set mode on a PHY device
+	*
+	* @phy:		PHY port to be powered on
+	* @mode:	mode to which the PHY should be put to
+	* @submode:	submode of @mode
+	*
+	* Some PHYs need to be put into a specific mode to work correctly.
+	*
+	* @return 0 if OK, or a negative error code
+	*/
+	int	(*set_mode)(struct phy *phy, enum phy_mode mode, int submode);
 };
 
 #ifdef CONFIG_PHY
@@ -164,6 +200,15 @@ int generic_phy_power_on(struct phy *phy);
  */
 int generic_phy_power_off(struct phy *phy);
 
+/**
+ * generic_phy_set_mode() - set mode on a PHY device
+ *
+ * @phy:	PHY port to be powered off
+ * @mode:	mode to which the PHY should be put to
+ * @submode:	submode of @mode
+ * @return 0 if OK, or a negative error code
+ */
+int generic_phy_set_mode(struct phy *phy, enum phy_mode mode, int submode);
 
 /**
  * generic_phy_get_by_index() - Get a PHY device by integer index.
@@ -248,6 +293,12 @@ static inline int generic_phy_power_off(struct phy *phy)
 	return 0;
 }
 
+static inline int generic_phy_set_mode(struct phy *phy, enum phy_mode mode,
+				       int submode)
+{
+	return 0;
+}
+
 static inline int generic_phy_get_by_index(struct udevice *user, int index,
 			     struct phy *phy)
 {
-- 
2.24.1



More information about the U-Boot mailing list