使用OpenWrt开发嵌入式Linux(五):网卡DM9000

2019-07-13 05:06发布

本次在Linux-4.14上面移植DM9000,刚开始设备起不来,调试了很长时间,最终发现是因为没有使能S5Pv210的SROMC时钟。

参考DTS文件中DM9000配置

target/linux/samsung/dts/TQ210.dts / { model = "Embedsky TQ210 based on S5PV210"; compatible = "embedsky,tq210", "samsung,s5pv210"; chosen { bootargs = "console=ttySAC0,115200n8"; }; memory@20000000 { device_type = "memory"; reg = <0x20000000 0x40000000>; }; ethernet@88000000 { compatible = "davicom,dm9000"; reg = <0x88000000 0x2 0x88000004 0x2>; interrupt-parent = <&gph1>; interrupts = <2 IRQ_TYPE_LEVEL_HIGH>; local-mac-address = [00 00 de ad be ef]; davicom,no-eeprom; clocks = <&clocks CLK_SROMC>; clock-names = "sromc"; }; }; 使用外部中断10,对应GPH1的2号引脚。
配置时钟为sromc。

参考补丁:

target/linux/samsung/patches-4.14/002-dm9000-clk.patch --- a/drivers/net/ethernet/davicom/dm9000.c +++ b/drivers/net/ethernet/davicom/dm9000.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include @@ -1436,6 +1437,7 @@ dm9000_probe(struct platform_device *pde enum of_gpio_flags flags; struct regulator *power; bool inv_mac_addr = false; + const char *clk_name; power = devm_regulator_get(dev, "vcc"); if (IS_ERR(power)) { @@ -1573,6 +1575,18 @@ dm9000_probe(struct platform_device *pde goto out; } + /* Enable clock if specified */ + if (!of_property_read_string(dev->of_node, "clock-names", &clk_name)) { + struct clk *clk = devm_clk_get(dev, clk_name); + if (IS_ERR(clk)) { + dev_err(dev, "cannot get clock of %s ", clk_name); + ret = PTR_ERR(clk); + goto out; + } + clk_prepare_enable(clk); + dev_info(dev, "enable clock '%s' ", clk_name); + } + /* fill in parameters for net-dev structure */ ndev->base_addr = (unsigned long)db->io_addr;

配置内核,选中DM9000

make kernel_menuconfig Device Drivers ---> [*] Network device support ---> [*] Ethernet driver support ---> <*> DM9000 support

重新编译固件

make -j4

运行

[ 1.817735] 0x000000040000-0x000000340000 : "kernel" [ 1.820905] 0x000000340000-0x000040000000 : "rootfs" [ 1.836650] mtd: device 2 (rootfs) set to be root filesystem [ 1.836849] mtdsplit: no squashfs found in "rootfs" [ 1.839211] dm9000 88000000.ethernet: enable clock 'sromc' [ 1.841356] eth0: dm9000b at c085b000,c085d004 IRQ 144 MAC: 00:00:de:ad:be:ef (platform data) [ 1.857832] NET: Registered protocol family 10 [ 1.864500] Segment Routing with IPv6 root@OpenWrt:/# ifconfig br-lan Link encap:Ethernet HWaddr 00:00:DE:AD:BE:EF inet addr:192.168.1.1 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fda2:7349:db32::1/60 Scope:Global inet6 addr: fe80::200:deff:fead:beef/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:2571 errors:0 dropped:0 overruns:0 frame:0 TX packets:35 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:151319 (147.7 KiB) TX bytes:4011 (3.9 KiB) eth0 Link encap:Ethernet HWaddr 00:00:DE:AD:BE:EF UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:2571 errors:0 dropped:0 overruns:0 frame:0 TX packets:40 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:197597 (192.9 KiB) TX bytes:4437 (4.3 KiB) Interrupt:144 Base address:0xb000 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:188 errors:0 dropped:0 overruns:0 frame:0 TX packets:188 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:12840 (12.5 KiB) TX bytes:12840 (12.5 KiB)