当前位置:网站首页>[i.mx6ul] u-boot migration (VI) network driver modification lan8720a

[i.mx6ul] u-boot migration (VI) network driver modification lan8720a

2022-06-25 02:28:00 Full stack programmer webmaster

Hello everyone , I meet you again , I'm your friend, Quan Jun .

I.MX6UL/ULL There is an Ethernet inside MAC peripherals , That is to say ENET, Need an external PHY Chip to realize network communication function , The inside MAC+ external PHY Chip scheme .

I.MX6UL/ULL There are two network interfaces ENET1 and ENET2,I.MX6U-ALPHA The development board provides these two network interfaces , among ENET1 and ENET2 All use LAN8720A As PHY chip .

NXP Official I.MX6ULL EVK Development board use KSZ8081 The star PHY chip ,LAN8720A comparison KSZ8081 Small size 、 Less peripheral devices 、 Advantages such as low price . Use it directly KSZ8081 Yes, of course , But we may not use it in actual products KSZ8081, Sometimes, in order to reduce costs, they choose other PHY chip . There is a problem at this time : Changed PHY What about the network driver after the chip ? So ,I.MX6U-ALPHA The development board will ENET1 and ENET2 Of PHY Instead of LAN8720A, In this way, we can explain the replacement PHY How to adjust the network driver after the chip , Make the network work properly .

I.MX6U-ALPHA Development board ENET1 Pin and NXP Official I.MX6ULL EVK The development board is basically the same , Only the reset pin is different . As can be seen from the figure ,I.MX6U-ALPHA Development board ENET1 Reset pin ENET1_RST Got it I.M6ULL Of SNVS_TAMPER7 On this pin .

LAN8720A There are registers inside ,I.MX6ULL Will read LAN8720 Internal register to determine the current physical link status 、 Connection speed (10M still 100M) And duplex status ( Half duplex or full duplex ). I.MX6ULL adopt MDIO Interface to read PHY The internal register of the chip ,MDIO The interface has two pins ,ENET_MDC and ENET_MDIO, ENET_MDC Provide clock ,ENET_MDIO Data transfer . One MIDO Interfaces can manage 32 individual PHY chip , The same MDIO These under the interface PHY Use different device addresses to distinguish ,MIDO The interface can access the corresponding device through different device addresses PHY chip .I.MX6U-ALPHA Development board ENET1 Connected to LAN8720A The device address is 0X0, So we have to modify ENET1 If the network is driven, the focus is on three points :

①、ENET1 Reset pin initialization . ENET1_RST –>SNVS_TAMPER7 ②、LAN8720A The device ID.0x0 ③、LAN8720 drive

modify ENET2 If the network is driven, the focus is on three points :

①、ENET1 Reset pin initialization . ENET1_RST –>SNVS_TAMPER8 ②、LAN8720A The device ID.0x1 ③、LAN8720 drive

Let's start to modify the file .

  1. The input terminal :gedit include/configs/mx6ull_mybsp_emmc.h

The following figure shows the modified :

  1. Delete uboot in 74LV595 Driver code for , because NXP official I.MX6ULL EVK Development board use 74LV595 To expand IO, The reset pins of the two networks are controlled by 74LV595 Controlled .I.MX6U-ALPHA The development board does not use 74LV595, So we delete the code .

The input terminal :gedit board/freescale/mx6ull_mybsp_emmc/mx6ull_mybsp_emmc.c

Before the change :

#define IOX_SDI IMX_GPIO_NR(5, 10)
#define IOX_STCP IMX_GPIO_NR(5, 7)
#define IOX_SHCP IMX_GPIO_NR(5, 11)
#define IOX_OE IMX_GPIO_NR(5, 8)

After modification :

#define ENET1_RESET IMX_GPIO_NR(5, 7)
#define ENET2_RESET IMX_GPIO_NR(5, 8)
  1. ENET1 The reset pin of is connected to SNVS_TAMPER7 On , Corresponding GPIO5_IO07,ENET2 The reset pin of is connected to Receive SNVS_TAMPER8 On , Corresponding GPIO5_IO08. Continue to mx6ull_mybsp_emmc.c Find the following code in , Delete all the structures :
static iomux_v3_cfg_t const iox_pads[] = { 
    
    /* IOX_SDI */ 
    MX6_PAD_BOOT_MODE0__GPIO5_IO10 | MUX_PAD_CTRL(NO_PAD_CTRL), 
    /* IOX_SHCP */ 
    MX6_PAD_BOOT_MODE1__GPIO5_IO11 | MUX_PAD_CTRL(NO_PAD_CTRL), 
    /* IOX_STCP */ 
    MX6_PAD_SNVS_TAMPER7__GPIO5_IO07 | MUX_PAD_CTRL(NO_PAD_CTRL), 
    /* IOX_nOE */ 
    MX6_PAD_SNVS_TAMPER8__GPIO5_IO08 | MUX_PAD_CTRL(NO_PAD_CTRL), 
}; 
  1. Continue to mx6ull_mybsp_emmc.c Function found in iox74lv_init and iox74lv_set, Delete both functions !
  2. stay mx6ull_mybsp_emmc.c Find board_init function , This function is the board initialization function , Will be board_init_r call .

board_init Would call imx_iomux_v3_setup_multiple_pads and iox74lv_init These two functions are used to initialize 74lv595 Of GPIO, Delete these two lines . thus ,mx6ull_mybsp_emmc.c About China 74LV595 Chip driver All the moving codes have been deleted .

add to I.MX6U-ALPHA Development board network reset pin driver

stay mx6ull_mybsp_emmc.c Keyword found in : ①static iomux_v3_cfg_t const fec1_pads[] ②static iomux_v3_cfg_t const fec2_pads[]

The following contents need to be added :

MX6_PAD_SNVS_TAMPER7__GPIO5_IO07 | MUX_PAD_CTRL(NO_PAD_CTRL),/*  initialization ETH1 RESET Pin  */
MX6_PAD_SNVS_TAMPER8__GPIO5_IO08 | MUX_PAD_CTRL(NO_PAD_CTRL),/*  initialization ETH2 RESET Pin  */

Continue in file mx6ull_mybsp_emmc.c Function found in setup_iomux_fec. Put these two IO Set to output and reset the hardware LAN8720A, This hardware reset is very important ! Otherwise, it may lead to uboot Can't recognize LAN8720A. Add the following :

static void setup_iomux_fec(int fec_id)
{ 
   
	if (fec_id == 0)
	{ 
   
		imx_iomux_v3_setup_multiple_pads(fec1_pads,
						 ARRAY_SIZE(fec1_pads));

		gpio_direction_output(ENET1_RESET, 1);
		gpio_set_value(ENET1_RESET, 0);
		mdelay(100);
		gpio_set_value(ENET1_RESET, 1);
	}
	else
	{ 
   
		imx_iomux_v3_setup_multiple_pads(fec2_pads,
						 ARRAY_SIZE(fec2_pads));
		gpio_direction_output(ENET2_RESET, 1);
		gpio_set_value(ENET2_RESET, 0);
		mdelay(100);
		gpio_set_value(ENET2_RESET, 1);
	}
}

uboot Medium LAN8720A There is a problem with the driver , Open file drivers/net/phy/phy.c, Find the function genphy_update_link, This is a universal PHY Driving functions , This function is used to update PHY Connection status and speed .

The input terminal :gedit drivers/net/phy/phy.c Search for keywords :genphy_update_link Revised as follows :

	/* LAN8720 must software*/
#ifdef CONFIG_PHY_SMSC
	static int lan8720_flag = 0;
	int bmcr_reg = 0;
	if (lan8720_flag == 0) { 
   
		bmcr_reg = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMCR);		/*  Read register BMCR The default value is  */
		phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, BMCR_RESET); 	/*  Software reset , Automatic reset  */
		while(phy_read(phydev, MDIO_DEVAD_NONE, MII_BMCR) & BMCR_RESET) { 
   
			udelay(100);			
		}
		phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, bmcr_reg); 	/* BMCR Write the original value  */
		lan8720_flag = 1;
	}
#endif

recompile uboot

./mx6ull_mybsp_emmc.sh or make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- mx6ull_mybsp_emmc_defconfig make V=1 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j16

Download burning verification :

chmod 777 imxdownload  

// To give  imxdownload  Executable rights  
./imxdownload u-boot.bin /dev/sdg 
 
// burning  u-boot.bin  To  SD  In the card 

After the burning is completed, the SD Card insertion I.MX6U-ALPHA Development board TF In the card slot , Finally, set the development board from SD Card activation . open SecureCRT, Set the serial port used by the development board and open it , Reset the development board .

stay uboot Set several environment variables before using the network in , The order is as follows :

setenv ipaddr 192.168.1.55  
// Development board  IP  Address  
setenv ethaddr 00:04:9f:04:d2:35  
// Development board network card  MAC  Address  
setenv gatewayip 192.168.1.1  
// Default gateway of development board  
setenv netmask 255.255.255.0 
// Development board subnet mask  
setenv serverip 192.168.1.250 
// Server address , That is to say  Ubuntu  Address  
saveenv  
// Save environment variables  

SecureCRT Of uboot Use in ping command .

ping 192.168.1.250 

Yes “host 192.168.1.250 is alive” This sentence , explain ping Host succeeded .

Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/151761.html Link to the original text :https://javaforall.cn

原网站

版权声明
本文为[Full stack programmer webmaster]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206242246018104.html