zjhsucceed_329的专栏

专注嵌入式Linux

使用OpenWrt开发嵌入式Linux(五):移植DM9000

本次在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。

制作补丁,使dm9000驱动能够识别时钟配置

make target/linux/{clean,prepare} QUILT=1
cd build_dir/target-arm_cortex-a8+vfpv3_musl_eabi/linux-samsung_s5pv210/linux-4.14.34/
quilt push -a
quilt new 002-dm9000-clk.patch
quilt edit drivers/net/ethernet/davicom/dm9000.c

这里使用quilt edit修改drivers/net/ethernet/davicom/dm9000.c,修改 如下

/*
 * Search DM9000 board, allocate space and register it
 */
static int
dm9000_probe(struct platform_device *pdev)
{
    ...
    bool inv_mac_addr = false;
    const char *clk_name;
    ...
    /* fill in parameters for net-dev structure */
    ndev->base_addr = (unsigned long)db->io_addr;

    /* 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\n", clk_name);
            ret = PTR_ERR(clk);
            goto out;
        }

        clk_prepare_enable(clk);
        dev_info(dev, "enable clock '%s'\n", clk_name);
    }

查看修改了什么

quilt diff

Index: linux-4.14.34/drivers/net/ethernet/davicom/dm9000.c
===================================================================
--- linux-4.14.34.orig/drivers/net/ethernet/davicom/dm9000.c
+++ linux-4.14.34/drivers/net/ethernet/davicom/dm9000.c
@@ -39,6 +39,7 @@
 #include <linux/regulator/consumer.h>
 #include <linux/gpio.h>
 #include <linux/of_gpio.h>
+#include <linux/clk.h>

 #include <asm/delay.h>
 #include <asm/irq.h>
@@ -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)) {
@@ -1576,6 +1578,19 @@ dm9000_probe(struct platform_device *pde
        /* fill in parameters for net-dev structure */
        ndev->base_addr = (unsigned long)db->io_addr;

+    /* 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\n", clk_name);
+            ret = PTR_ERR(clk);
+            goto out;
+        }
+        
+        clk_prepare_enable(clk);
+        dev_info(dev, "enable clock '%s'\n", clk_name);
+    }
+
        /* ensure at least we have a default set of IO routines */
        dm9000_set_io(db, iosize);

生成补丁

quilt refresh
cd -
make target/linux/update

配置内核,选中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)
阅读更多
想对作者说点什么? 我来说一句

网卡DM9000驱动移植

-

学院

1970年01月01日 08:00

没有更多推荐了,返回首页

不良信息举报

使用OpenWrt开发嵌入式Linux(五):移植DM9000

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭