×
单片机 > 单片机程序设计 > 详情

驱动开发之 DM9000 (for mini2440)

发布时间:2024-06-29 发布时间:
|

内核版本:linux-2.6.32.2

实验平台:mini2440


1. 添加平台设备支持

首先需要在mach-mini2440.c中包含头文件,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,

},

};


38

最后需要将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

#endif


修改dm9000片选总线时序:

static int __init

dm9000_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, "x08x90x90x90x90x90", 6);

if (!is_valid_ether_addr(ndev->dev_addr))

dev_warn(db->dev, "%s: Invalid ethernet MAC address. Please "

"set using ifconfign", ndev->name);

/* ... */

}


3. 配置内核

Device Drivers --->

[*] Network device support --->

[*] Ethernet (10 or 100Mbit) --->

DM9000 support

(4) DM9000 maximum debug level


4. 编译下载,启动开发板

5. 启动网络设备

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

ifconfig eth0 172.20.11.41 netmask 255.255.255.0 up


如下图所示:

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


ifconfig eth0 down



『本文转载自网络,版权归原作者所有,如有侵权请联系删除』

热门文章 更多
STM32 TIMER2的使用