diff mbox series

[u-boot-marvell,09/11] net: mvneta: add PHY support

Message ID 20200419154850.25868-10-marek.behun@nic.cz
State New
Delegated to: Stefan Roese
Headers show
Series Armada 37xx: port comphy to generic-phys (PLEASE TEST) | expand

Commit Message

Marek Behun April 19, 2020, 3:48 p.m. UTC
Use generic-phy API to power on comphy in mvneta driver.

Signed-off-by: Marek BehĂșn <marek.behun@nic.cz>
---
 drivers/net/mvneta.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

Comments

Marek Behun April 20, 2020, 9:36 a.m. UTC | #1
There is some code repetition in patches 7, 8, and 9.

I am thinking about perhaps creating a helper function

generic_phy_begin() which would call
	generic_phy_init()
	generic_phy_set_mode()
	generic_phy_power_on()

and

generic_phy_end()
	generic_phy_power_off()
	generic_phy_exit()
diff mbox series

Patch

diff --git a/drivers/net/mvneta.c b/drivers/net/mvneta.c
index d737400a20..31548445d7 100644
--- a/drivers/net/mvneta.c
+++ b/drivers/net/mvneta.c
@@ -22,6 +22,7 @@ 
 #include <asm/io.h>
 #include <dm/device_compat.h>
 #include <dm/devres.h>
+#include <generic-phy.h>
 #include <linux/errno.h>
 #include <phy.h>
 #include <miiphy.h>
@@ -274,6 +275,7 @@  struct mvneta_port {
 	unsigned int link;
 	unsigned int duplex;
 	unsigned int speed;
+	struct phy comphy;
 
 	int init;
 	int phyaddr;
@@ -1150,8 +1152,22 @@  static int mvneta_setup_txqs(struct mvneta_port *pp)
 	return 0;
 }
 
+static int mvneta_comphy_init(struct mvneta_port *pp)
+{
+	int ret;
+
+	ret = generic_phy_set_mode(&pp->comphy, PHY_MODE_ETHERNET,
+				   pp->phy_interface);
+	if (ret)
+		return ret;
+
+	return generic_phy_power_on(&pp->comphy);
+}
+
 static void mvneta_start_dev(struct mvneta_port *pp)
 {
+	mvneta_comphy_init(pp);
+
 	/* start the Rx/Tx activity */
 	mvneta_port_enable(pp);
 }
@@ -1723,6 +1739,12 @@  static int mvneta_probe(struct udevice *dev)
 	else
 		mvneta_conf_mbus_windows(pp);
 
+	ret = generic_phy_get_by_index(dev, 0, &pp->comphy);
+	if (ret && ret != -ENOENT) {
+		printf("cannot get comphy in mvneta\n");
+		return ret;
+	}
+
 	/* PHY interface is already decoded in mvneta_ofdata_to_platdata() */
 	pp->phy_interface = pdata->phy_interface;
 
@@ -1776,6 +1798,7 @@  static void mvneta_stop(struct udevice *dev)
 
 	mvneta_port_down(pp);
 	mvneta_port_disable(pp);
+	generic_phy_power_off(&pp->comphy);
 }
 
 static const struct eth_ops mvneta_ops = {