硬件平台:FL2440(s3c2440)
内核版本:linux-3.0-rc4
主机平台:centos6.5
FL2440和DM9000的引脚链接图
1.修改devs.c
vi arch/arm/plat-s3c24xx/devs.c
1.1增加头文件
45 #if defined(CONFIG_DM9000)||defined(CONFIG_DM9000_MODULE)
46 #include <linux/dm9000.h>
47 #endif
1.2增加DM9000平台设备结构
增加如下代码:
static struct resource s3c_dm9000_resource[] = {
[0] = {
.start = S3C2410_CS4, /* ADDR2=0,发送地址时使用*/
.end = S3C2410_CS4+ 3,
.flags = IORESOURCE_MEM
},
[1]={
.start = S3C2410_CS4 + 4, /* ADDR2=1,传输数据时使用*/
.end = S3C2410_CS4 + 4 + 3,
.flags = IORESOURCE_MEM
},
[2] = {
.start = IRQ_EINT7, /* 中断为外部7号中断 */
.end = IRQ_EINT7, /* 中断为外部7号中断 */
.flags = IORESOURCE_IRQ /* 资源标志为中断资源 */
},
};
/* 定义平台数据 */
static struct dm9000_plat_data s3c_device_dm9000_platdata = {
.flags= DM9000_PLATF_16BITONLY,
};
/* 定义平台设备 */
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_device_dm9000_platdata, //定义平台数据
}
};
//导出函数符号,保存函数地址和名称
EXPORT_SYMBOL(s3c_device_dm9000);
1.3加入内核设备列表中
vi arch/arm/plat-s3c24xx/common-smdk.c
修改内容如下:
204 static struct platform_device __initdata *smdk_devs[] = {
205 &s3c_device_nand,
206 &s3c_device_dm9000, //added
207 &smdk_led4,
208 &smdk_led5,
209 &smdk_led6,
210 &smdk_led7,
211 };
此外,还要在devs.h添加声明
vi arch/arm/plat-samsung/include/plat/devs.h
添加如下:
142 extern struct platform_device s3c_device_dm9000;
2.修改dm9000.c
vim drivers/net/dm9000.c
2.1添加头文件
#if defined(CONFIG_ARCH_S3C2410)
#include <mach/regs-mem.h>
#endif
2.2设置存储控制器
函数dm9000_probe
1373 dev_dbg(&pdev->dev, "dm9000_probe()
");
1374
//added!!
1375 #if defined(CONFIG_ARCH_S3C2410)
1376 *((volatile unsigned int *)S3C2410_BWSCON) = (oldval_bwscon & ~(3<<16)) | S3C2410_BWSCON_DW4_16 | S3C2410_BWSCON _WS4 | S3C2410_BWSCON_ST4;
1377 *((volatile unsigned int *)S3C2410_BWSCON) = (oldval_bwscon & ~(3<<16)) | S3C2410_BWSCON_DW4_16 ;
1378 *((volatile unsigned int *)S3C2410_BANKCON4) = 0x1f7c;
1379 #endif
1380
/*********************************************/
1563 #if defined(CONFIG_ARCH_S3C2410)
1564 printk("Now use the default MAC address: 10:23:45:67:89:ab
");
1565 mac_src = "EmbedSky";
1566 ndev->dev_addr[0] = 0x10;
1567 ndev->dev_addr[1] = 0x23;
1568 ndev->dev_addr[2] = 0x45;
1569 ndev->dev_addr[3] = 0x67;
1570 ndev->dev_addr[4] = 0x89;
1571 ndev->dev_addr[5] = 0xab;
1572 #else
1573 mac_src = "eeprom";
1574 /* try reading the node address from the attached EEPROM */
1575 for (i = 0; i < 6; i += 2)
1576 dm9000_read_eeprom(db, i / 2, ndev->dev_addr+i);
1577
1578 if (!is_valid_ether_addr(ndev->dev_addr) && pdata != NULL) {
1579 mac_src = "platform data";
1580 memcpy(ndev->dev_addr, pdata->dev_addr, 6);
1581 }
1582
1583 if (!is_valid_ether_addr(ndev->dev_addr)) {
1584 /* try reading from mac */
1585
1586 mac_src = "chip";
1587 for (i = 0; i < 6; i++)
1588 ndev->dev_addr[i] = ior(db, i+DM9000_PAR);
1589 }
1590
1591 if (!is_valid_ether_addr(ndev->dev_addr))
1592 dev_warn(db->dev, "%s: Invalid ethernet MAC address. Please "
1593 "set using ifconfig
", ndev->name);
1594 #endif
/*********************************************/
1633 out:
1634 dev_err(db->dev, "not found (%d).
", ret);
1635
1636 #if defined(CONFIG_ARCH_S3C2410)
1637 *((volatile unsigned int *)S3C2410_BWSCON) = oldval_bwscon;
1638 *((volatile unsigned int *)S3C2410_BANKCON4) = oldval_bankcon4;
1639 #endif
1640
1641 dm9000_release_board(pdev, db);
1642 free_netdev(ndev);
1643
1644 return ret;
1645 }
2.3注册中断
在注册中断时,指定触发方式为上升沿触发。
函数dm9000_open()
1172 #if defined (CONFIG_ARCH_S3C2410)
1173 if(request_irq(dev->irq,&dm9000_interrupt,IRQF_SHARED|IRQF_TRIGGER_RISING,dev->name,dev))
1174 #else
1175 if(request_irq(dev->irq,&dm9000_interrupt,IRQF_SHARED,dev->name,dev))
1176 #endif
1177 //if (request_irq(dev->irq, dm9000_interrupt, irqflags, dev->name, dev))
1178 return -EAGAIN;
参考文献:
http://blog.chinaunix.net/uid-22561766-id-1772768.html
http://blog.csdn.net/geekcome/article/details/6609742#
http://www.cnblogs.com/xilentz/archive/2010/07/12/1775620.html