Chinaunix首页 | 论坛 | 博客
  • 博客访问: 783477
  • 博文数量: 231
  • 博客积分: 3217
  • 博客等级: 中校
  • 技术积分: 2053
  • 用 户 组: 普通用户
  • 注册时间: 2011-07-04 12:01
文章分类

全部博文(231)

文章存档

2015年(1)

2013年(10)

2012年(92)

2011年(128)

分类:

2011-08-19 20:26:24

原文地址:DM9000 驱动的移植 作者:luozhiyong131

修改arch/arm/mach-s3c2440/mach-smdk2440.c 160 Platform_device 结构体中,加入:

&s3c_device_dm9000,

修改arch/arm/plat-s3c24xx/devs.c 在最前面38 行加入:

#include //别忘加这个头文件

 

/*DM9000*/

static struct resource s3c_dm9000_resource[] = {

      [0] = {

      .start = S3C2410_CS4,

      .end = S3C2410_CS4 + 3,

      .flags = IORESOURCE_MEM,

      },

      [1] = {

      .start = S3C2410_CS4 + 4,

      .end = S3C2410_CS4 + 4 + 3,

      .flags = IORESOURCE_MEM,

      },

      [2] = {

      .start = IRQ_EINT18, /*use eint18 GPG10*/

      .end = IRQ_EINT18,

      .flags = IORESOURCE_IRQ,

      }

};

 

static struct dm9000_plat_data s3c_dm9000_platdata = {

      .flags = DM9000_PLATF_16BITONLY,

};

 

static struct platform_device s3c_device_dm9000 = {

      .name = "dm9000",

      .id = 0,

      .num_resources = ARRAY_SIZE(s3c_dm9000_resource),

      .resource = s3c_dm9000_resource,

      .dev = {

           .platform_data = &s3c_dm9000_platdata,

      }

};

 

EXPORT_SYMBOL(s3c_device_dm9000);

 

arch/arm/plat-s3c/include/plat/devs.h 中加入一行:

extern struct platform_device s3c_device_dm9000;

 

编译时出现一个奇怪的错误:

arch/arm/plat-s3c24xx/devs.c:63: error: static declaration of's3c_device_dm9000' follows non-static declarationarch/arm/plat-s3c/include/plat/devs.h:27: error: previous declaration of's3c_device_dm9000' was here

s3c_device_dm9000 首先在devs.c 中定义,在devs.h 中声明,在mach-s3c2440.c中使用,看了好几遍代码,应该没什么问题查不到什么原因,我觉得是跟编译器有关,在devs.c 中做了一下修改,问题解决,编译时只出现一个warningdevs.c 中的这句:

static struct platform_device s3c_device_dm9000 = {

static 改成extern,就可以了

下面修改dm9000.c 源码,在drivers/net/dm9000.c

1. 添加头文件,在第43 行加入:

#if defined(CONFIG_ARCH_S3C2410)

#include

#endif

2. 指定注册时的中断触发方式,在第1019 行加入:

static int dm9000_open(struct net_device *dev)

{

…………

irqflags |= IRQF_SHARED;

 

#if defined (CONFIG_ARCH_S3C2410)

if(request_irq(dev->irq,&dm9000_interrupt,IRQF_SHARED|IRQF_TRIGGER_RSING,dev->name,dev))

#else

if(request_irq(dev->irq,&dm9000_interrupt,IRQF_SHARED,dev->name,dev))

#endif

//if (request_irq(dev->irq, &dm9000_interrupt, irqflags, dev->name,dev))

return -EAGAIN;

…………

}

3. 设置BANK4, 设置MAC 地址,在1215 行,dm9000_probe 函数中加入:

int ret = 0;

int iosize;

int i;

u32 id_val;

 

#if defined(CONFIG_ARCH_S3C2410)

unsigned int oldval_bwscon = *(volatile unsigned int *)S3C2410_BWSCON;

unsigned int oldval_bankcon4 = *(volatile unsigned int *)S3C2410_BANKCON4;

#endif

 

/* Init network device */

ndev = alloc_etherdev(sizeof(struct board_info));

if (!ndev) {

dev_err(&pdev->dev, "could not allocate device.\n");

return -ENOMEM;

}

1231 行加入:

SET_NETDEV_DEV(ndev, &pdev->dev);

dev_dbg(&pdev->dev, "dm9000_probe()\n");

#if defined(CONFIG_ARCH_S3C2410)

 *((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

 

1390 行加入:

db->mii.mdio_read = dm9000_phy_read;

db->mii.mdio_write = dm9000_phy_write;

 

#if defined(CONFIG_ARCH_S3C2410)

printk("Now use the default MAC address: 08:90:90:90:90:90 ");

mac_src = "http://luozhiyong131.cublog.cn/";

ndev->dev_addr[0] = 0x08;

ndev->dev_addr[1] = 0x90;

ndev->dev_addr[2] = 0x90;

ndev->dev_addr[3] = 0x90;

ndev->dev_addr[4] = 0x90;

ndev->dev_addr[5] = 0x90;

#else

 

mac_src = "eeprom";

 

/* try reading the node address from the attached EEPROM */

for (i = 0; i < 6; i += 2)

dm9000_read_eeprom(db, i / 2, ndev->dev_addr+i);

if (!is_valid_ether_addr(ndev->dev_addr) && pdata != NULL) {

mac_src = "platform data";

memcpy(ndev->dev_addr, pdata->dev_addr, 6);

}

 

if (!is_valid_ether_addr(ndev->dev_addr)) {

/* try reading from mac */

mac_src = "chip";

for (i = 0; i < 6; i++)

ndev->dev_addr[i] = ior(db, i+DM9000_PAR);

}

 

if (!is_valid_ether_addr(ndev->dev_addr))

dev_warn(db->dev, "%s: Invalid ethernet MAC address. Please " "set using ifconfig\n", ndev->name);

#endif

 

platform_set_drvdata(pdev, ndev);

ret = register_netdev(ndev);

 

if (ret == 0)

printk(KERN_INFO "%s: dm9000%c at %p,%p IRQ %d MAC: %pM (%s)\n",

ndev->name, dm9000_type_to_char(db->type),

db->io_addr, db->io_data, ndev->irq,

ndev->dev_addr, mac_src);

return 0;

 

out:

#if defined(CONFIG_ARCH_S3C2410)

*(volatile unsigned int *)S3C2410_BWSCON = oldval_bwscon;

*(volatile unsigned int *)S3C2410_BANKCON4 = oldval_bankcon4;

#endif

 

配置内核,支持网卡:

Device Drivers --->

[*] Network device support --->

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

<*> DM9000 support

(4) DM9000 maximum debug level

 

补丁文件

 

文件: linux-2.6.31.DM9000.rar
大小: 166KB
下载: 下载

 

启动时输出:

dm9000 Ethernet Driver, V1.31

Now use the default MAC address: 08:90:90:90:90:90

eth0: dm9000e at c881c000,c8820004 IRQ 62 MAC: 08:90:90:90:90:90

系统启动后,可能会出现这个错误:

ifconfig: SIOCSIFFLAGS: Cannot assign requested address

原因是MAC 地址没有设置或没有设置对,在启动脚本中加上:

ifconfig eth0 down

ifconfig eth0 hw ether XX:XX:XX:XX:XX:XX 􀃅MAC 地址,随便设

ifconfig eth0 up

一般问题可以解决,如果还提示有错,再改一下MAC 地址测试网卡的方法:连接好计算机和开发板之间的网线,如果网开发板网卡的灯亮起,说明已经连接到计算机;

可以在计算机的命令行窗口下(开始->运行->cmd)使用PING 命令测试网络:ping 192.168.1.10 􀃅开发板的IP 地址也可以在开发板的串口终端下PING 计算机的网卡

 

阅读(443) | 评论(0) | 转发(0) |
0

上一篇:LCD 驱动的移植

下一篇:RTC 驱动移植

给主人留下些什么吧!~~