2. 修改网络驱动 (1)修改LAN8720A的复位引脚驱动 修改设备树文件arch/arm/boot/dts/imx6ul-14x14-atk.dtsi,搜索 GPIO5_IO07、GPIO5_IO08,发现已被spi4使用,删除这两行后,代码如下: pinctrl_spi4: spi4grp {
fsl,pins = <
MX6ULL_PAD_BOOT_MODE0__GPIO5_IO10 0x70a1
MX6ULL_PAD_BOOT_MODE1__GPIO5_IO11 0x70a1
>;
};
接着再找到spi4,删除与这两个GPIO相关的代码,删除后如下: spi4 {
compatible = "spi-gpio";
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_spi4>;
status = "okay";
gpio-sck = <&gpio5 11 0>;
gpio-mosi = <&gpio5 10 0>;
num-chipselects = <1>;
#address-cells = <1>;
#size-cells = <0>;
gpio_spi: gpio_spi[url=home.php?mod=space&uid=2514928]@0[/url] {
compatible = "fairchild,74hc595";
gpio-controller;
#gpio-cells = <2>;
reg = <0>;
registers-number = <1>;
registers-default = /bits/ 8 <0x57>;
spi-max-frequency = <100000>;
};
};
接着将复位引脚加入到 pinctrl_enet1 节点的描述中: MX6UL_PAD_SNVS_TAMPER7__GPIO5_IO07 0x10b0
接着将复位引脚加入到 pinctrl_enet2 的代码中:
MX6UL_PAD_SNVS_TAMPER8__GPIO5_IO08 0x10b0
接着搜索fec1和fec2节点,添加网络驱动复位引脚使用,添加的代码如下:
phy-reset-gpios = <&gpio5 7 GPIO_ACTIVE_LOW>;
phy-reset-duration = <200>;
phy-reset-gpios = <&gpio5 8 GPIO_ACTIVE_LOW>;
phy-reset-duration = <200>;
(2)修改LAN8720的PHY地址 修改mdio节点中的地址:
至此,设备树修改完成。 (3)修改fec_main.c文件 修改drivers/net/ethernet/freescale/fec_main.c文件,找到函数fec_probe,在函数开头添加如下代码: void __iomem *IMX6U_ENET1_TX_CLK;
void __iomem *IMX6U_ENET2_TX_CLK;
IMX6U_ENET1_TX_CLK = ioremap(0X020E00DC, 4);
writel(0X14, IMX6U_ENET1_TX_CLK);
IMX6U_ENET2_TX_CLK = ioremap(0X020E00FC, 4);
writel(0X14, IMX6U_ENET2_TX_CLK);
fec_enet_get_queue_num(pdev, &num_tx_qs, &num_rx_qs);
(4)修改PHY驱动源码 修改drivers/net/phy/smsc.c文件,添加两个头文件: #include <linux/of_gpio.h>
#include <linux/io.h>
然后找到smsc_phy_reset函数,修改之后如下: tatic int smsc_phy_reset(struct phy_device *phydev)
{
int err, phy_reset;
int msec = 1;
struct device_node *np;
int timeout = 50000;
int rc;
if (phydev->mdio.addr == 0) {
np = of_find_node_by_path("/soc/aips-bus@02100000/ethernet@02188000");
} else if (phydev->mdio.addr == 1) {
np = of_find_node_by_path("/soc/aips-bus@02000000/ethernet@020b4000");
}
if (!np) {
return -1;
}
/* A sane reset duration should not be longer than 1s */
err = of_property_read_u32(np, "phy-reset-duration", &msec);
if (!err && msec > 1000)
msec = 1;
phy_reset = of_get_named_gpio(np, "phy-reset-gpios", 0);
if (!gpio_is_valid(phy_reset))
return -1;
gpio_direction_output(phy_reset, 0);
gpio_set_value(phy_reset, 0);
msleep(msec);
gpio_set_value(phy_reset, 1);
rc = phy_read(phydev, MII_LAN83C185_SPECIAL_MODES);
if (rc < 0)
return rc;
/* If the SMSC PHY is in power down mode, then set it
* in all capable mode before using it.
*/
if ((rc & MII_LAN83C185_MODE_MASK) == MII_LAN83C185_MODE_POWERDOWN) {
/* set "all capable" mode */
rc |= MII_LAN83C185_MODE_ALL;
phy_write(phydev, MII_LAN83C185_SPECIAL_MODES, rc);
}
phy_write(phydev, MII_BMCR, BMCR_RESET);
/* wait end of reset (max 500 ms) */
do {
udelay(10);
if (timeout-- == 0)
return -1;
rc = phy_read(phydev, MII_BMCR);
} while (rc & BMCR_RESET);
/* reset the phy */
return genphy_soft_reset(phydev);
}
此时编译内核可以通过。 (5)配置Linux内核,使能LAN8720驱动 使能Device Drivers\Network device support\ PHY Device support and infrastructure\Drivers for SMSC PHYs:
保存到.config,然后退出。 (6)编译测试 重新编译内核,使用新的内核和设备树启动,测试网络是否正常。
ping主机测试:
至此,网络驱动修改成功。
|