zynq-7000系列基於zynq-zed的MAC->MAC 的實現(fixed-link)

zynq-7000系列基於zynq-zed的MAC->MAC 的實現(fixed-link)

                             作者:盧浩  

                                     時間:2017.2.20

                                    轉載請註明出處

                                                                


前言:在項目實際使用中,我們有一些應用可以省去以太網phy芯片的,這裏我就拿zynq-zed開發板做評估測試。

在VIVADO工程中去掉以太網的MDIO MDC配置,這樣就無法讀取PHY狀態了,因爲mac->mac這種連接就是無phy模式下的通訊。

@@ -383,27 +383,37 @@ static int macb_mii_probe(struct net_device *dev
 	int phy_irq;
 	int ret;
 
-	phydev = phy_find_first(bp->mii_bus);
-	if (!phydev) {
-		netdev_err(dev, "no PHY found\n");
-		return -ENXIO;
-	}
+	if (bp->phy_node) {
+		phydev = of_phy_connect(dev, bp->phy_node,
+					&macb_handle_link_change, 0,
+					bp->phy_interface);
+		if (!phydev)
+			return -ENODEV;
+	} else {
+		phydev = phy_find_first(bp->mii_bus);
+		if (!phydev) {
+			netdev_err(dev, "no PHY found\n");
+			return -ENXIO;
+		}
 
-	pdata = dev_get_platdata(&bp->pdev->dev);
-	if (pdata && gpio_is_valid(pdata->phy_irq_pin)) {
-		ret = devm_gpio_request(&bp->pdev->dev, pdata->phy_irq_pin, "phy int");
-		if (!ret) {
-			phy_irq = gpio_to_irq(pdata->phy_irq_pin);
-			phydev->irq = (phy_irq < 0) ? PHY_POLL : phy_irq;
+		pdata = dev_get_platdata(&bp->pdev->dev);
+		if (pdata && gpio_is_valid(pdata->phy_irq_pin)) {
+			ret = devm_gpio_request(&bp->pdev->dev,
+						pdata->phy_irq_pin, "phy int");
+			if (!ret) {
+				phy_irq = gpio_to_irq(pdata->phy_irq_pin);
+				phydev->irq = (phy_irq < 0) ?
+					      PHY_POLL : phy_irq;
+			}
 		}
-	}
 
-	/* attach the mac to the phy */
-	ret = phy_connect_direct(dev, phydev, &macb_handle_link_change,
-				 bp->phy_interface);
-	if (ret) {
-		netdev_err(dev, "Could not attach to PHY\n");
-		return ret;
+		/* attach the mac to the phy */
+		ret = phy_connect_direct(dev, phydev, &macb_handle_link_change,
+					 bp->phy_interface);
+		if (ret) {
+			netdev_err(dev, "Could not attach to PHY\n");
+			return ret;
+		}
 	}
 
 	/* mask with MAC supported features */
 @@ -3461,14 +3471,21 @@ static int macb_probe(struct platform_device *pdev)
 		macb_get_hwaddr(bp);
 
 	/* Power up the PHY if there is a GPIO reset */
-	phy_node =  of_get_next_available_child(np, NULL);
-	if (phy_node) {
+	phy_node = of_parse_phandle(np, "phy-handle", 0);
+	if (!phy_node && of_phy_is_fixed_link(np)) {
+		err = of_phy_register_fixed_link(np);
+		if (err < 0) {
+			dev_err(&pdev->dev, "broken fixed-link specification");
+			goto failed_phy;
+		}
+		phy_node = of_node_get(np);
+		bp->phy_node = phy_node;
+	} else {
 		int gpio = of_get_named_gpio(phy_node, "reset-gpios", 0);
 		if (gpio_is_valid(gpio))
 			bp->reset_gpio = gpio_to_desc(gpio);
 		gpiod_set_value(bp->reset_gpio, GPIOD_OUT_HIGH);
 	}
-	of_node_put(phy_node);
 
 	err = of_get_phy_mode(np);
 	if (err < 0) {
 @@ -3518,6 +3535,9 @@ static int macb_probe(struct platform_device *pdev)
 err_out_free_netdev:
 	free_netdev(dev);
 
+failed_phy:
+	of_node_put(phy_node);
+
 err_disable_clocks:
 	clk_disable_unprepare(tx_clk);
 	clk_disable_unprepare(hclk);
 @@ -3547,6 +3567,7 @@ static int macb_remove(struct platform_device *pdev)
 		clk_disable_unprepare(bp->tx_clk);
 		clk_disable_unprepare(bp->hclk);
 		clk_disable_unprepare(bp->pclk);
+		of_node_put(bp->phy_node);
 		free_netdev(dev);
 	}
 



@@ -906,6 +906,7 @@ struct macb {
 	struct mii_bus		*mii_bus;
 	struct phy_device	*phy_dev;
+	struct device_node	*phy_node;
 	int 			link;
 	int 			speed;
 	int 			duplex;


在內核配置文件中添加如下配置:
CONFIG_ETHERNET
CONFIG_NET_CADENCE
CONFIG_MACB
CONFIG_NETDEVICES
CONFIG_HAS_DMA

在dts文件增加如下修改:
修改前:
 51 &gem0 {
 52         status = "okay";
 53         phy-mode = "rgmii-id";
 54         phy-handle = <&ethernet_phy>;
 55 
 56         ethernet_phy: ethernet-phy@0 {
 57                 reg = <0>;
 58         };
 59 };
修改後:
 55 &gem0 {
 56                   status = "okay";
 57                   phy-mode = "rgmii-id";
 58                   fixed-link {
 59                                speed = <1000>;
 60                                full-duplex;
 61                              };
 68   };

重新編譯內核和dts文件。
上電啓動zynq-zed開發板,對網卡進行測試,此時網卡被強制到1000M FULL模式。PHYADDR是0-31.









發佈了41 篇原創文章 · 獲贊 8 · 訪問量 19萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章