mini2440 dm9000网卡驱动移植

时间:2022-10-14 17:12:33

内核版本:linux-2.6.32.2        实验平台:mini2440

1. 添加平台设备支持
首先需要在mach-mini2440.c中包含头文件<linux/dm9000.h>,dm9000平台设备定义如下:

/* DM9000AEP 10/100 ethernet controller */
#define MACH_MINI2440_DM9000_BASE (S3C2410_CS4 + 0x300)

static struct resource mini2440_dm9000_resource[] = {
[0] = {
.start = MACH_MINI2440_DM9000_BASE,
.end = MACH_MINI2440_DM9000_BASE + 3,
.flags = IORESOURCE_MEM,
},
[1] = {
.start = MACH_MINI2440_DM9000_BASE + 4,
.end = MACH_MINI2440_DM9000_BASE + 7,
.flags = IORESOURCE_MEM,
},
[2] = {
.start = IRQ_EINT7,
.end = IRQ_EINT7,
.flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
},
};

/*
* The DM9000 has no eeprom, and it's MAC address is set by
* the bootloader before starting the kernel.
*/
static struct dm9000_plat_data mini2440_dm9000_platdata = {
.flags = (DM9000_PLATF_16BITONLY | DM9000_PLATF_NO_EEPROM),
};

static struct platform_device mini2440_device_eth = {
.name = "dm9000",
.id = -1,
.num_resources = ARRAY_SIZE(mini2440_dm9000_resource),
.resource = mini2440_dm9000_resource,
.dev = {
.platform_data = &mini2440_dm9000_platdata,
},
};
最后需要将dm9000这个平台设备添加到mini2440_devices这个平台设备数组里面,这样才能完成平台设备的注册。
static struct platform_device *mini2440_devices[] __initdata = {        /* ... */        &mini2440_device_eth,};


2. dm9000驱动修改
drivers/net/dm9000.c这个驱动并不是为mini2440做准备的,需要做一些修改。
包含相关头文件:

#if defined(CONFIG_ARCH_S3C2410)
#include <mach/regs-mem.h>
#endif
修改dm9000片选总线时序:
static int __initdm9000_init(void){#if defined(CONFIG_ARCH_S3C2410)        unsigned int oldval_bwscon = *(volatile unsigned int *)S3C2410_BWSCON;        unsigned int oldval_bankcon4 = *(volatile unsigned int *)S3C2410_BANKCON4;        *((volatile unsigned int *)S3C2410_BWSCON) =                        (oldval_bwscon & ~(3<<16)) | S3C2410_BWSCON_DW4_16 | S3C2410_BWSCON_WS4 | S3C2410_BWSCON_ST4;        *((volatile unsigned int *)S3C2410_BANKCON4) = 0x1f7c;#endif	/* ... */}

在dm9000_probe函数中还需要给dm9000设置一个mac地址。

static int __devinit
dm9000_probe(struct platform_device *pdev)
{
/* ... */
memcpy(ndev->dev_addr, "\x08\x90\x90\x90\x90\x90", 6);

if (!is_valid_ether_addr(ndev->dev_addr))
dev_warn(db->dev, "%s: Invalid ethernet MAC address. Please "
"set using ifconfig\n", ndev->name);
/* ... */
}


3. 配置内核

    Device Drivers  --->
[*] Network device support  --->
[*]   Ethernet (10 or 100Mbit)  --->
<*>   DM9000 support
(4)     DM9000 maximum debug level


4. 启动网络设备
内核配置好之后,需要手动启动网络设备,使用如下命令:

ifconfig eth0 192.168.1.109 netmask 255.255.255.0 up

或者将上面的命令写入到启动脚本中,还可以使用ifconfig命令来停止网络设备:

ifconfig eth0 down

输入ifconfig命令得到如下结果:

eth0      Link encap:Ethernet  HWaddr 08:90:90:90:90:90  
          inet addr:192.168.1.109  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:21 errors:0 dropped:0 overruns:0 frame:0
          TX packets:4 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:2455 (2.3 KiB)  TX bytes:280 (280.0 B)
          Interrupt:51 Base address:0x8300