[Feature][ZXW-267]phy driver support for Marvell_88q1110

    Only Configure :No
    Affected branch: master
    Affected module: Ethernet
    Is it affected on both ZXIC and MTK:only ZXIC
    Self-test: Yes
    Doc Update: No

Change-Id: I41792073035f45ef2e3ced7caf45b4dca867cb2e
diff --git a/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/arch/arm/boot/dts/zx297520v3-vehicle_dc_ref.dts b/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/arch/arm/boot/dts/zx297520v3-vehicle_dc_ref.dts
index b9638e6..4f4e580 100755
--- a/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/arch/arm/boot/dts/zx297520v3-vehicle_dc_ref.dts
+++ b/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/arch/arm/boot/dts/zx297520v3-vehicle_dc_ref.dts
@@ -164,9 +164,11 @@
 &gmac {
     port-nums = <1>;
     rmii-ports = <1>;
-	
+//zw.wang phy driver support for Marvell_88q1110 on 20240417 start
     gpios = <&bgpio 83 GPIO_ACTIVE_HIGH>,
-            <&bgpio 63 GPIO_ACTIVE_HIGH>;
+            <&bgpio 63 GPIO_ACTIVE_HIGH>,
+            <&bgpio 51 GPIO_ACTIVE_HIGH>;
+//zw.wang phy driver support for Marvell_88q1110 on 20240417 end
     status = "okay";
 };	
 
diff --git a/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/arch/arm/boot/dts/zx297520v3.dtsi b/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/arch/arm/boot/dts/zx297520v3.dtsi
index b4124b6..92e4177 100755
--- a/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/arch/arm/boot/dts/zx297520v3.dtsi
+++ b/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/arch/arm/boot/dts/zx297520v3.dtsi
@@ -529,10 +529,12 @@
 			interrupts = <GIC_SPI GMAC_INT IRQ_TYPE_LEVEL_HIGH>;
 			phy-mode = "rmii";
 			port-mask = <0x00000000>;
-                        pinctrl-names = "default", "sleep";
+			//zw.wang phy driver support for Marvell_88q1110 on 20240417 start
+                        pinctrl-names = "default", "sleep", "state0";
                         pinctrl-0 = <&rmii_active>;
                         pinctrl-1 = <&rmii_sleep>;
-			
+                        pinctrl-2 = <&rmii_clki_pins>;
+			//zw.wang phy driver support for Marvell_88q1110 on 20240417 end
                         status = "disabled";
 		};
 		
diff --git a/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/drivers/net/ethernet/zte/zx29_gmac.c b/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/drivers/net/ethernet/zte/zx29_gmac.c
old mode 100755
new mode 100644
index 9312efe..5dc69f5
--- a/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/drivers/net/ethernet/zte/zx29_gmac.c
+++ b/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/drivers/net/ethernet/zte/zx29_gmac.c
@@ -491,33 +491,33 @@
 	struct mdio_device *mdio_dev = NULL;

 	int ret = 0;

 

-	//zw.wang Without phy, gmac's gpio output power is removed on 20240328 start
-	int i = 0;
-	for(i = 0;i <= 5;i++)
-	{
-		if (priv->nports == 1) {
-			p = phy_find_first(priv->mii.bus);
-		} else if (priv->rmii_port < PHY_MAX_ADDR) {
-			mdio_dev = priv->mii.bus->mdio_map[priv->rmii_port];
-			p = container_of(mdio_dev, struct phy_device, mdio);
-		}
-
-		if (!p) {
-			if(i == 5){
-				gpio_direction_output(priv->gpio_power[0], 0);
-#ifdef CONFIG_MDIO_C45
-				gpio_direction_output(priv->gpio_power[1], 0);
-#endif
-			}
-			else
-				continue;
-			printk("%s: no PHY found\n", dev->name);
-			return -ENODEV;
-		}
-		else
-			break;
-	}
-	//zw.wang Without phy, gmac's gpio output power is removed on 20240328 end
+	//zw.wang Without phy, gmac's gpio output power is removed on 20240328 start

+	int i = 0;

+	for(i = 0;i <= 5;i++)

+	{

+		if (priv->nports == 1) {

+			p = phy_find_first(priv->mii.bus);

+		} else if (priv->rmii_port < PHY_MAX_ADDR) {

+			mdio_dev = priv->mii.bus->mdio_map[priv->rmii_port];

+			p = container_of(mdio_dev, struct phy_device, mdio);

+		}

+

+		if (!p) {

+			if(i == 5){

+				gpio_direction_output(priv->gpio_power[0], 0);

+#ifdef CONFIG_MDIO_C45

+				gpio_direction_output(priv->gpio_power[1], 0);

+#endif

+			}

+			else

+				continue;

+			printk("%s: no PHY found\n", dev->name);

+			return -ENODEV;

+		}

+		else

+			break;

+	}

+	//zw.wang Without phy, gmac's gpio output power is removed on 20240328 end

 

 	ret = phy_connect_direct(dev, p, zx29_gmac_adjust_link, PHY_INTERFACE_MODE_RMII);  /*  phy_start_machine */

 	  /* supported and advertising */

@@ -879,8 +879,9 @@
 static void zx29_gmac_tx_timeout(struct net_device *ndev, unsigned int txqueue)

 {

 	struct zx29_gmac_dev *priv = (struct zx29_gmac_dev *)netdev_priv(ndev);

-

-//	genphy_update_link(priv->phydev);

+#ifdef CONFIG_MARVELL_88Q1110 //zw.wang phy driver support for Marvell_88q1110 on 20240417 

+	genphy_update_link(priv->phydev);

+#endif

 	priv->link.isup = priv->phydev->link;

 

 	if (0 == priv->link.isup) {

@@ -1159,16 +1160,21 @@
 #endif

 		

 		printk("[%s] netif_running\n", __func__);

-		

-					

+#ifdef CONFIG_MARVELL_88Q1110 //zw.wang phy driver support for Marvell_88q1110 on 20240417 

+		gpio_direction_output(priv->gpio_power[0], 0);

+		gmac_stop((void*)ndev->base_addr);

+#else

 		gmac_stop((void*)ndev->base_addr); 

 		gpio_direction_output(priv->gpio_power[0], 0);

+#endif

 		spin_unlock_irqrestore(&priv->lock, flag);

 

 #endif

     	}

     }

+#ifndef CONFIG_MARVELL_88Q1110 //zw.wang phy driver support for Marvell_88q1110 on 20240417 

     pinctrl_pm_select_sleep_state(&pdev->dev);

+#endif

     return 0;

 }

 

@@ -1182,8 +1188,10 @@
 	void __iomem *base = NULL;

 	gmac = (unsigned *)ndev->base_addr;

     unsigned long flag = 0;

-

+	

+#ifndef CONFIG_MARVELL_88Q1110 //zw.wang phy driver support for Marvell_88q1110 on 20240417 

     pinctrl_pm_select_default_state(&pdev->dev);

+#endif

     if(ndev) {

     	if(netif_running(ndev)) {

 //        	gmac_start((void*)ndev->base_addr);

@@ -1757,8 +1765,12 @@
 		pctrl = NULL;

 		goto errirq;

 	}

-	

+

+#ifdef CONFIG_MARVELL_88Q1110 //zw.wang phy driver support for Marvell_88q1110 on 20240417 

+	state0 = pinctrl_lookup_state(pctrl, "state0");

+#else

 	state0 = pinctrl_lookup_state(pctrl, "default");

+#endif

 	if (IS_ERR(state0)) {

 		dev_err(&pdev->dev, "TEST: missing state0\n");

 		goto pinctrl_init_end;

@@ -1768,7 +1780,14 @@
 		dev_err(&pdev->dev, "setting state0 failed\n");

 		goto pinctrl_init_end;

 	}

-    

+

+#ifdef CONFIG_MARVELL_88Q1110 //zw.wang phy driver support for Marvell_88q1110 on 20240417 

+	prv->gpio_power[2] = of_get_gpio_flags(pdev->dev.of_node, 2, &flags);

+	ret = gpio_request(prv->gpio_power[2], "phy_power"); /* gpio 51 */

+	gpio_direction_output(prv->gpio_power[2], 1);

+	mdelay(15);

+#endif

+

     prv->gpio_power[0] = of_get_gpio_flags(pdev->dev.of_node, 0, &flags);

 	ret = gpio_request(prv->gpio_power[0], "gmac_power"); /* gpio 83/124 */

 	gpio_direction_output(prv->gpio_power[0], 1);

@@ -1861,7 +1880,11 @@
 	base = devm_platform_ioremap_resource(pdev, 1);

 	gmac_phy_release();	

 	base_phy_release = base;

+#ifdef CONFIG_MARVELL_88Q1110 //zw.wang phy driver support for Marvell_88q1110 on 20240417 

+	mdelay(500);

+#else

 	mdelay(10); //zw.wang@20240306 modify. Here, the jl3103 is set as an example, and other phy peripherals need to be optimized according to different reset stability times

+#endif

 

 	ret = mdiobus_register(mb);

 	if (ret < 0) {

diff --git a/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/drivers/net/ethernet/zte/zx29_gmac.h b/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/drivers/net/ethernet/zte/zx29_gmac.h
index 46a87d3..d2abe1e 100755
--- a/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/drivers/net/ethernet/zte/zx29_gmac.h
+++ b/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/drivers/net/ethernet/zte/zx29_gmac.h
@@ -11,7 +11,11 @@
 #ifndef __ZX29_GMAC_

 #define __ZX29_GMAC_

 

-//#define GMAC_NO_INT

+//zw.wang phy driver support for Marvell_88q1110 on 20240417 start
+#ifdef CONFIG_MARVELL_88Q1110
+#define GMAC_NO_INT
+#endif
+//zw.wang phy driver support for Marvell_88q1110 on 20240417 end
 

 #ifdef GMAC_NO_INT

 #define GTIMER_INTERVAL  2000

diff --git a/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/drivers/net/phy/Kconfig b/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/drivers/net/phy/Kconfig
index a0bf99d..7795b72 100644
--- a/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/drivers/net/phy/Kconfig
+++ b/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/drivers/net/phy/Kconfig
@@ -321,6 +321,14 @@
 	help
 	  It is disabled by default. The value is C45 if yes, and C22 if N.
 # zw.wang Customer chooses phy c22/c45 issues on 20240301 end
+
+# zw.wang phy driver support for Marvell_88q1110 on 20240417 start
+config MARVELL_88Q1110
+	bool "phy driver support for Marvell_88q1110"
+	default n
+	help
+	  Phy driver support for Marvell_88q1110.
+# zw.wang phy driver support for Marvell_88q1110 on 20240417 end
 endif # PHYLIB
 
 config MICREL_KS8995MA
diff --git a/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/drivers/net/phy/phy_device.c b/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/drivers/net/phy/phy_device.c
index a868814..d9b53ba 100644
--- a/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/drivers/net/phy/phy_device.c
+++ b/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/drivers/net/phy/phy_device.c
@@ -120,6 +120,19 @@
 	ETHTOOL_LINK_MODE_10000baseT_Full_BIT,
 };
 
+//status = phy_read_cl(phydev, MII_BMSR);
+static int phy_read_cl(struct phy_device *phydev, u32 regnum)
+{
+	int val = 0;
+
+	mdiobus_write(phydev->mdio.bus, phydev->mdio.addr, 0x0d, 1);
+	mdiobus_write(phydev->mdio.bus, phydev->mdio.addr, 0x0e, regnum);
+	mdiobus_write(phydev->mdio.bus, phydev->mdio.addr, 0x0d, 0x4000 | 1);
+	val = mdiobus_read(phydev->mdio.bus, phydev->mdio.addr, 0x0e);
+
+	return val;
+}
+
 static void features_init(void)
 {
 	/* 10/100 half/full*/
@@ -2212,8 +2225,11 @@
 int genphy_update_link(struct phy_device *phydev)
 {
 	int status = 0, bmcr;
-
+#ifdef CONFIG_MARVELL_88Q1110 //zw.wang phy driver support for Marvell_88q1110 on 20240417 
+	bmcr = phy_read_cl(phydev, MII_BMCR);
+#else
 	bmcr = phy_read(phydev, MII_BMCR);
+#endif
 	if (bmcr < 0)
 		return bmcr;
 
@@ -2229,7 +2245,11 @@
 	 * the link was already down.
 	 */
 	if (!phy_polling_mode(phydev) || !phydev->link) {
+#ifdef CONFIG_MARVELL_88Q1110 //zw.wang phy driver support for Marvell_88q1110 on 20240417 
+		status = phy_read_cl(phydev, MII_BMSR);
+#else
 		status = phy_read(phydev, MII_BMSR);
+#endif
 		if (status < 0)
 			return status;
 		else if (status & BMSR_LSTATUS)
@@ -2237,7 +2257,11 @@
 	}
 
 	/* Read link and autonegotiation status */
+#ifdef CONFIG_MARVELL_88Q1110 //zw.wang phy driver support for Marvell_88q1110 on 20240417 
+	status = phy_read_cl(phydev, MII_BMSR);
+#else
 	status = phy_read(phydev, MII_BMSR);
+#endif
 	if (status < 0)
 		return status;
 done:
@@ -2310,7 +2334,11 @@
  */
 int genphy_read_status_fixed(struct phy_device *phydev)
 {
+#ifdef CONFIG_MARVELL_88Q1110 //zw.wang phy driver support for Marvell_88q1110 on 20240417 
+	int bmcr = phy_read_cl(phydev, MII_BMCR);
+#else
 	int bmcr = phy_read(phydev, MII_BMCR);
+#endif
 
 	if (bmcr < 0)
 		return bmcr;