diff mbox series

[U-Boot,03/14] net: rockchip: Add integrated phy ops

Message ID 1517660196-21802-4-git-send-email-david.wu@rock-chips.com
State Changes Requested
Delegated to: Philipp Tomsich
Headers show
Series Add integrated phy support for rk322x and rk3328 | expand

Commit Message

David Wu Feb. 3, 2018, 12:16 p.m. UTC
Some rockchio Socs have integrated phy inside, to support it,
add the integrated phy ops.

Signed-off-by: David Wu <david.wu@rock-chips.com>
---

 drivers/net/gmac_rockchip.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

Comments

Philipp Tomsich Feb. 16, 2018, 5:12 p.m. UTC | #1
> Some rockchio Socs have integrated phy inside, to support it,
> add the integrated phy ops.
> 
> Signed-off-by: David Wu <david.wu@rock-chips.com>
> ---
> 
>  drivers/net/gmac_rockchip.c | 29 +++++++++++++++++++++++++++++
>  1 file changed, 29 insertions(+)
> 

Acked-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
diff mbox series

Patch

diff --git a/drivers/net/gmac_rockchip.c b/drivers/net/gmac_rockchip.c
index 5afc415..bca0a2a 100644
--- a/drivers/net/gmac_rockchip.c
+++ b/drivers/net/gmac_rockchip.c
@@ -10,6 +10,7 @@ 
 #include <dm.h>
 #include <clk.h>
 #include <phy.h>
+#include <reset.h>
 #include <syscon.h>
 #include <asm/io.h>
 #include <asm/arch/periph.h>
@@ -22,6 +23,7 @@ 
 #include <asm/arch/grf_rk3399.h>
 #include <asm/arch/grf_rv1108.h>
 #include <dm/pinctrl.h>
+#include <dm/of_access.h>
 #include <dt-bindings/clock/rk3288-cru.h>
 #include "designware.h"
 
@@ -35,6 +37,8 @@  DECLARE_GLOBAL_DATA_PTR;
 struct gmac_rockchip_platdata {
 	struct dw_eth_pdata dw_eth_pdata;
 	bool clock_input;
+	bool integrated_phy;
+	struct reset_ctl phy_reset;
 	int tx_delay;
 	int rx_delay;
 };
@@ -46,13 +50,16 @@  struct rk_gmac_ops {
 			       struct dw_eth_dev *priv);
 	void (*set_to_rmii)(struct gmac_rockchip_platdata *pdata);
 	void (*set_to_rgmii)(struct gmac_rockchip_platdata *pdata);
+	void (*integrated_phy_powerup)(struct gmac_rockchip_platdata *pdata);
 };
 
 
 static int gmac_rockchip_ofdata_to_platdata(struct udevice *dev)
 {
 	struct gmac_rockchip_platdata *pdata = dev_get_platdata(dev);
+	struct ofnode_phandle_args args;
 	const char *string;
+	int ret;
 
 	string = dev_read_string(dev, "clock_in_out");
 	if (!strcmp(string, "input"))
@@ -60,6 +67,25 @@  static int gmac_rockchip_ofdata_to_platdata(struct udevice *dev)
 	else
 		pdata->clock_input = false;
 
+	/* If phy-handle property is passed from DT, use it as the PHY */
+	ret = dev_read_phandle_with_args(dev, "phy-handle", NULL, 0, 0, &args);
+	if (ret) {
+		debug("Cannot get phy phandle: ret=%d\n", ret);
+		pdata->integrated_phy = dev_read_bool(dev, "phy-is-integrated");
+	} else {
+		debug("Found phy-handle subnode\n");
+		pdata->integrated_phy = ofnode_read_bool(args.node,
+							 "phy-is-integrated");
+	}
+
+	if (pdata->integrated_phy) {
+		ret = reset_get_by_name(dev, "mac-phy", &pdata->phy_reset);
+		if (ret) {
+			debug("No PHY reset control found: ret=%d\n", ret);
+			return ret;
+		}
+	}
+
 	/* Check the new naming-style first... */
 	pdata->tx_delay = dev_read_u32_default(dev, "tx_delay", -ENOENT);
 	pdata->rx_delay = dev_read_u32_default(dev, "rx_delay", -ENOENT);
@@ -572,6 +598,9 @@  static int gmac_rockchip_probe(struct udevice *dev)
 	if (ret)
 		return ret;
 
+	if (pdata->integrated_phy && ops->integrated_phy_powerup)
+		ops->integrated_phy_powerup(pdata);
+
 	switch (eth_pdata->phy_interface) {
 	case PHY_INTERFACE_MODE_RGMII:
 		/*