本来想移植DM9000网卡的驱动,无奈硬件出了点问题,通过杜邦线链接开发板和DM9000网卡模块,系统上电,还没加载网卡驱动就直接崩溃了,找不到原因。。。刚好手上有一个enc28j60的网卡模块,于是就着手移植enc28j60的驱动。

其实移植enc28j60的驱动也十分简单,网上有现成的,只需要分配一些硬件资源即可。

由于我的内核版本老到掉牙,没有自带enc28j60的驱动,只能在网上找一个:

enc28j60.c

http://git.ti.com/ti-linux-kernel/ti-linux-kernel/blobs/7dac6f8df607929e51f4fd598d80bd009c45a9f8/drivers/net/enc28j60.c

enc28j60_hw.h

http://git.ti.com/ti-linux-kernel/ti-linux-kernel/blobs/7dac6f8df607929e51f4fd598d80bd009c45a9f8/drivers/net/enc28j60_hw.h

由于这个驱动是支持较新的内核,移植到2.6.22.6,只要改动3个地方好了。

 ... ...

 static int enc28j60_set_hw_macaddr(struct net_device *ndev)
{
... ... if (!priv->hw_enable) {
if (netif_msg_drv(priv)) {
/* [cgw]: 屏蔽一下几行 */
//DECLARE_MAC_BUF(mac);
//printk(KERN_INFO DRV_NAME
// ": %s: Setting MAC address to %s\n",
// ndev->name, print_mac(mac, ndev->dev_addr));
}
} ... ...
} ... ... static void dump_packet(const char *msg, int len, const char *data)
{
printk(KERN_DEBUG DRV_NAME ": %s - packet len:%d\n", msg, len);
/* [cgw]: 屏蔽一下几行 */
//print_hex_dump(KERN_DEBUG, "pk data: ", DUMP_PREFIX_OFFSET, 16, 1,
// data, len, true);
} ... ... static int enc28j60_net_open(struct net_device *dev)
{
... ... if (!is_valid_ether_addr(dev->dev_addr)) {
if (netif_msg_ifup(priv)) {
/* [cgw]: 屏蔽一下几行 */
//DECLARE_MAC_BUF(mac);
//dev_err(&dev->dev, "invalid MAC address %s\n",
// print_mac(mac, dev->dev_addr));
}
return -EADDRNOTAVAIL;
} ... ...
} ... ...

都是些打印相关的东西,屏蔽掉就好。

spi的框架可以参考这里:http://www.cnblogs.com/hackfun/p/6082489.html

这里只列出配置spi硬件资源的代码,只需要写一个spi_platform_dev.c文件就行了。模拟spi的模式下,spi_platform_dev.c和http://www.cnblogs.com/hackfun/p/6082489.html这里的spi_platform_dev.c文件相似,只需要增加一个外部中断入口给enc28j60用于接收中断,和更改spi的模式等。

模拟spi的模式下的spi_platform_dev.c

 #include <linux/module.h>
#include <linux/version.h> #include <linux/init.h> #include <linux/kernel.h>
#include <linux/types.h>
#include <linux/interrupt.h>
#include <linux/list.h>
#include <linux/timer.h>
#include <linux/init.h>
#include <linux/serial_core.h>
#include <linux/platform_device.h>
#include <linux/irq.h> #include <asm/gpio.h>
#include <asm/io.h>
#include <asm/arch/regs-gpio.h> #include <linux/spi/spi.h>
#include <linux/spi/spi_bitbang.h> #include <asm/arch/regs-spi.h>
#include <asm/arch/spi.h>
#include <asm/arch/spi-gpio.h> static struct spi_board_info board_info[] = {
{
.modalias = "enc28j60", /* [cgw]: spi设备名,和设备驱动名对应 */
.bus_num = , /* [cgw]: spi总线号,即spi0 */
.chip_select = , /* [cgw]: spi总线上的设备号,即spi0.2 */
.max_speed_hz = , /* [cgw]: spi时钟 */
.mode = SPI_MODE_0, /* [cgw]: spi数据模式 */
.irq = IRQ_EINT2,
},
}; static void enc28j60_chip_select(struct s3c2410_spigpio_info *spi, int cs)
{
/* [cgw]: 选中设备号为2的spi设备 */
if (spi->board_info->chip_select == ) {
s3c2410_gpio_cfgpin(S3C2410_GPG2, S3C2410_GPIO_OUTPUT);
/* [cgw]: 选中设备 */
if (BITBANG_CS_ACTIVE == cs) {
s3c2410_gpio_setpin(S3C2410_GPG2, );
/* [cgw]: 释放设备 */
} else if (BITBANG_CS_INACTIVE == cs) {
s3c2410_gpio_setpin(S3C2410_GPG2, );
}
}
} /* [cgw]: */
static struct s3c2410_spigpio_info spi_dev = {
.pin_clk = S3C2410_GPG7,
.pin_mosi = S3C2410_GPG6,
.pin_miso = S3C2410_GPG5,
.board_size = , /* [cgw]: 设置板上spi接口数量为1 */
.board_info = &board_info[],
.chip_select = enc28j60_chip_select
}; static void spi_dev_release(struct device * dev)
{
printk("spi_dev_release! \n");
} /* [cgw]: 分配一个平台设备 */
static struct platform_device spi_platform_dev = {
.name = "s3c24xx-spi-gpio", /* [cgw]: 设置平台设备名,和平台驱动名对应 */
.id = -,
.dev = {
.release = spi_dev_release,
.platform_data = (void *)&spi_dev, /* [cgw]: 通过platform_data传递spi_dev给平台驱动
* 平台驱动可以访问spi_dev
*/
},
}; static int spi_dev_init(void)
{
s3c2410_gpio_cfgpin(S3C2410_GPF2, S3C2410_GPF2_EINT2); /* [cgw]: 注册spi_platform_dev平台设备 */
platform_device_register(&spi_platform_dev);
return ;
} static void spi_dev_exit(void)
{
/* [cgw]: 注销spi_platform_dev平台设备 */
platform_device_unregister(&spi_platform_dev);
} module_init(spi_dev_init);
module_exit(spi_dev_exit); MODULE_LICENSE("GPL");

makefile:

KERN_DIR = /work/system/linux-2.6.22.6

all:
make -C $(KERN_DIR) M=`pwd` modules clean:
make -C $(KERN_DIR) M=`pwd` modules clean
rm -rf modules.order obj-m += spi_platform_dev.o
obj-m += spi_s3c24xx_gpio.o
obj-m += spi_bitbang.o
obj-m += enc28j60.o

硬件spi的模式下的spi_platform_dev.c

 #include <linux/module.h>
#include <linux/version.h> #include <linux/init.h> #include <linux/kernel.h>
#include <linux/types.h>
#include <linux/interrupt.h>
#include <linux/list.h>
#include <linux/timer.h>
#include <linux/init.h>
#include <linux/serial_core.h>
#include <linux/platform_device.h>
#include <linux/irq.h> #include <asm/gpio.h>
#include <asm/io.h>
#include <asm/arch/regs-gpio.h> #include <linux/spi/spi.h>
#include <linux/spi/spi_bitbang.h> #include <asm/arch/regs-spi.h>
#include <asm/arch/spi.h>
#include <asm/arch/spi-gpio.h> /* SPI (1) */ static struct resource s3c_spi1_resource[] = {
[] = {
.start = S3C2410_PA_SPI + S3C2410_SPI1,
.end = S3C2410_PA_SPI + S3C2410_SPI1 + 0x1f,
.flags = IORESOURCE_MEM,
},
[] = {
.start = IRQ_SPI1,
.end = IRQ_SPI1,
.flags = IORESOURCE_IRQ,
} }; static struct spi_board_info board_info[] = {
{
.modalias = "enc28j60", /* [cgw]: spi设备名,和设备驱动名对应 */
.bus_num = , /* [cgw]: spi总线号,即spi0 */
.chip_select = , /* [cgw]: spi总线上的设备号,即spi0.2 */
.max_speed_hz = , /* [cgw]: spi时钟 */
.mode = SPI_MODE_0, /* [cgw]: spi数据模式 */
.irq = IRQ_EINT2,
},
}; static struct s3c2410_spi_info spi_info = {
.pin_cs = S3C2410_GPG2, /* simple gpio cs */
.board_size = ARRAY_SIZE(board_info),
.board_info = &board_info[],
.set_cs = NULL
}; static void spi_dev_release(struct device * dev)
{
printk("spi_dev_release! \n");
} /* [cgw]: 分配一个平台设备 */
static struct platform_device spi_platform_dev = {
.name = "s3c2410-spi", /* [cgw]: 设置平台设备名,和平台驱动名对应 */
.id = ,
.num_resources = ARRAY_SIZE(s3c_spi1_resource),
.resource = s3c_spi1_resource,
.dev = {
.release = spi_dev_release,
.platform_data = &spi_info,
//.dma_mask = &s3c_device_spi1_dmamask,
//.coherent_dma_mask = 0xffffffffUL
},
}; static int spi_dev_init(void)
{
/* [cgw]: 注册spi_platform_dev平台设备 */
platform_device_register(&spi_platform_dev);
return ;
} static void spi_dev_exit(void)
{
/* [cgw]: 注销spi_platform_dev平台设备 */
platform_device_unregister(&spi_platform_dev);
} module_init(spi_dev_init);
module_exit(spi_dev_exit); MODULE_LICENSE("GPL");

makefile:

KERN_DIR = /work/system/linux-2.6.22.6

all:
make -C $(KERN_DIR) M=`pwd` modules clean:
make -C $(KERN_DIR) M=`pwd` modules clean
rm -rf modules.order obj-m += spi_platform_dev.o
obj-m += spi_s3c24xx.o
obj-m += spi_bitbang.o
obj-m += enc28j60.o

加载spi平台设备时(platform_device),应注意模拟spi时应加载spi_s3c24xx_gpio.c,硬件spi时应加载spi_s3c24xx.c

如:

模拟spi:

 # insmod spi_bitbang.ko
# insmod spi_platform_dev.ko
# insmod spi_s3c24xx_gpio.ko
# insmod enc28j60.ko

硬件spi:

 # insmod spi_bitbang.ko
# insmod spi_platform_dev.ko
# insmod spi_s3c24xx.ko
# insmod enc28j60.ko

其中spi_bitbang.c , spi_s3c24xx_gpio.c , spi_s3c24xx.c为内核原生源文件,不需要改动。

硬件spi时,加载驱动的实例:

谢谢!

linux enc28j60网卡驱动移植(硬件spi和模拟spi)的更多相关文章

  1. linux网卡驱动移植

    这里重要的是物理层PHY receiver,MAC(media access control)层,这里与软件中的协议栈不同,在硬件上MAC是PHY的下一层.DM9000A将MAC和PHY做到一起,也可 ...

  2. 【Linux驱动】TQ2440 DM9000E网卡驱动移植(Linux-2.6.30.4)

    花了一天的时间研究了一下Linux-2.6.30.4版本号内核下关于TQ2440 DM9000E的网卡驱动移植.总结一下自己的收获. 事实上.在Linux-2.6.30.4版本号内核下有关于网卡驱动, ...

  3. Linux网卡驱动移植--Dm9000网卡驱动分析

    1. Linux网络体系结构由以下5部分组成 ① 系统调用接口: 位于Linux网络子系统的顶部,为应用程序提供访问内核网络子系统的方法,主要指socket系统调用. ② 协议无关接口: 实现一组基于 ...

  4. AM335x(TQ335x)学习笔记——Nand&&网卡驱动移植

    移植完成声卡驱动之后本想再接再励,移植网卡驱动,但没想到的是TI维护的内核太健壮,移植网卡驱动跟之前移植按键驱动一样简单,Nand驱动也是如此,于是,本人将Nand和网卡放在同一篇文章中介绍.介绍之前 ...

  5. AM335x(TQ335x)学习笔记——Nand&amp;&amp;网卡驱动移植

    移植完毕声卡驱动之后本想再接再励,移植网卡驱动,但没想到的是TI维护的内核太健壮,移植网卡驱动跟之前移植按键驱动一样简单,Nand驱动也是如此,于是,本人将Nand和网卡放在同一篇文章中介绍.介绍之前 ...

  6. Linux Charger IC 驱动移植总结

    Linux Charger IC 驱动移植总结 文章目录 Linux Charger IC 驱动移植总结 1 设备树的基本知识 设备树的概念 设备树的基本结构 compatible属性 举个栗子 2 ...

  7. linux4.1内核配置以及编译及千兆网卡dp83867网卡驱动移植

    一  内核配置编译 1首先解压内核 tar jxvf linux-at91-4.1.tar.bz2: 2下载编译链 在ubuntu命令行中输入sudo apt-get install gcc-arm- ...

  8. u-boot 移植 --->5、友善之臂Tiny210底板王网卡驱动移植

    网卡芯片的工作原理 DM9000AE具有以下主要性能: ①48管脚的LQFP封装,管脚少体积小: ②支持8/16位数据总线: ③适用于10Base-T和100Base-T,10/100M自适应,适应不 ...

  9. mini2440移植uboot-2008.10 (二) DM9000网卡驱动移植

    还是利用 mini2440移植uboot-2008.10 (一)  修改好的代码 通过观察可以发现,mini2400使用的网卡芯片是DM9000,在uboot-2008.10源码中已经支持该芯片的驱动 ...

随机推荐

  1. Scalaz(6)- typeclass:Functor-just map

    Functor是范畴学(Category theory)里的概念.不过无须担心,我们在scala FP编程里并不需要先掌握范畴学知识的.在scalaz里,Functor就是一个普通的typeclass ...

  2. 泛函编程(4)-深入Scala函数类

    既然是泛函编程,多了解一下函数自然是免不了的了: 方法(Method)不等于函数(Function) 方法不是函数但可以转化成函数:可以手工转换或者由编译器(compiler)在适当的情况下自动转换. ...

  3. 使用maven profile实现多环境可移植构建(转自CSDN)

    使用maven profile实现多环境可移植构建 标签: maven profilemaven自动构建maven自动部署maven可移植构建持续集成 2014-04-25 23:37 26905人阅 ...

  4. 免费 PSD 下载: 20个精美的登录和注册表单

    注册表单有许多不同的形状和尺寸,有的只是单个的输入框,有的则需要多个步骤.登录表单的设计将定义网站的性质,因此它应进行针对性的设计.下面的列表提供了20个醒目的登录和注册表单设计为您提供灵感. 您可能 ...

  5. JavaScript_Html5_LocalStorage项目demo

    项目中localStorage实用 项目中h5本地存储的一个小实用,本意使用cookie,但发现chrome调试被禁用,便用了localStorage. 此需求是一贴吧搜索页,在新用户第一次点击搜索框 ...

  6. C#开源项目汇总

    Discuz nt: 一个开源的论坛项目.估计你现在逛过大大小小的论坛没有成百上千,也有几十个吧,其中是个论坛6个以上都是Discuz(以前大部分都是php版的),现 在官方也早就放出了DotNet( ...

  7. 从零开始,做一个NodeJS博客(三):API实现-加载网易云音乐听歌排行

    标签: NodeJS 0 研究了一天,翻遍了GitHub上各种网易云API库,也没有找到我想要的听歌排行API,可能这功能比较小众吧.但收获也不是没有,在 这里 明白了云音乐API加密的凶险,我等蒟蒻 ...

  8. 27款后台管理页面设计 DIV+CSS+JS

    -----------. 演示: http://www.websjy.com/club/websj ... _61040268/index.htm http://www.websjy.com/club ...

  9. 规划SharePoint2010的管理员密码更改

    规划自动密码更改 (SharePoint Server 2010) 为了简化密码管理,自动密码更改功能允许您更新和部署密码,而不必在多个帐户.服务和 Web 应用程序之间执行手动密码更新任务.您可以配 ...

  10. Revit如何模型导入到InfraWorks中

    Infraworks也就是以前的Autodesk Infrastructure Modeler(AIM)作为一款优秀的概念设计软件,能接收来自各种来源的数据,这篇介绍如何把revit中的建筑模型导入到 ...