当前位置:网站首页>The connection of imx6 network port is unstable after power on

The connection of imx6 network port is unstable after power on

2022-04-23 18:15:00 Talent、me

chip :LAN8720A

problem : Network instability , After inserting the network cable , repeated link up,link down

fec 2188000.ethernet eth0: Link is Up - 100Mbps/Full - flow control rx/tx
IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
fec 2188000.ethernet eth0: Link is Down
IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
fec 2188000.ethernet eth0: Link is Up - 100Mbps/Full - flow control rx/tx
IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
fec 2188000.ethernet eth0: Link is Down
IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready

General solution :
1、 If using CPU The internal clock is provided to LAN8720 Chip work , In the face of the above problems , It can be supplied to... By changing to an external crystal oscillator LAN8720.

2、 Adjust the power on timing of the reset pin , from fec_main.c In the document static void fec_reset_phy(struct platform_device *pdev) The function interface , Default delay 1ms,
On the Internet, most people say that the delay time can be increased .( I tested , The situation I encountered this time is not good )

 From the device tree fec Add the following parameters to the network interface node :
phy-reset-gpios = <&gpio3 16 GPIO_ACTIVE_LOW>;
phy-reset-duration = <1>;
static void fec_reset_phy(struct platform_device *pdev)
{
    
	int err;
	int phy_reset;
	int msec = 1;
	struct device_node *np = pdev->dev.of_node;

	if (!np)
		return;

	err = of_property_read_u32(np, "phy-reset-duration", &msec);
	/* A sane reset duration should not be longer than 1s */
	if (!err && msec > 1000)
		msec = 1;

	phy_reset = of_get_named_gpio(np, "phy-reset-gpios", 0);
	if (!gpio_is_valid(phy_reset))
		return;

	err = devm_gpio_request_one(&pdev->dev, phy_reset,
				    GPIOF_OUT_INIT_LOW, "phy-reset");
	if (err) {
    
		dev_err(&pdev->dev, "failed to get phy-reset-gpios: %d\n", err);
		return;
	}
	
	msleep(msec);
	gpio_set_value(phy_reset, 1);
}

3、 Through the test with the hardware engineer , After the system is fully up , Put the chip reset The pin is pulled down again , Reset the hardware , Then it can run normally . So by printing information , Locate where you need to add a reset function .

static int fec_enet_mii_probe(struct net_device *ndev)

Add the following code

static void fec_enet_hyb_reset(void)
{
    
	printk("%s:%d\n",__FUNCTION__,phy_reset);
	msleep(1);
	gpio_set_value(phy_reset, 0);
	msleep(30);
	gpio_set_value(phy_reset, 1);
}
static int resetCnt = 0;// Define a static global variable 
static int fec_enet_mii_probe(struct net_device *ndev)
{
    
	.......
	if (resetCnt == 0) {
     // Hardware reset only once 
			resetCnt++;
			fec_enet_hyb_reset();
	}
	.......
}

版权声明
本文为[Talent、me]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210610470997.html