本来想移植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(35)- Free :运算-Trampoline,say NO to StackOverflowError

    在前面几次讨论中我们介绍了Free是个产生Monad的最基本结构.它的原理是把一段程序(AST)一连串的运算指令(ADT)转化成数据结构存放在内存里,这个过程是个独立的功能描述过程.然后另一个独立运算 ...

  2. Fiddler (四) 实现手机的抓包

      Fiddler是我最喜爱的工具,几乎每天都用, 我已经用了8年了. 至今我也只学会其中大概50%的功能. Fiddler绝对称得上是"神器", 任何一个搞IT的人都得着的. 小 ...

  3. 如何解决CRUD操作中与业务无关的字段赋值

    提高效率一直是个永恒的话题,编程中有一项也是可以提到效率的,那就是专注做一件事情,让其它没有强紧密联系的与之分开.这里分享下我们做CRUD时遇到的常见数据处理场景: 数据库表字段全部设计为非空,即使这 ...

  4. scrollify.js 鼠标滚动

    在线实例 实例演示 使用方法 <! doctype html> <html> <head> <script> $(function() { $.scro ...

  5. Web 前沿——HTML5 Form Data 对象的使用

    XMLHttpRequest Level 2 添加了一个新的接口——FormData.利用 FormData 对象,我们可以通过 JavaScript 用一些键值对来模拟一系列表单控件,我们还可以使用 ...

  6. PHP插入header('content-type:text/html;charset="utf-8')和error_reporting()

    1.header PHP文件插入header("Content-type: text/html; charset=utf-8");相当于页面里面的<meta http-equ ...

  7. Snort - manual 笔记(一)

    Chapter 1 Snort Overview This manual is based on Writing Snort Rules by Martin Roesch and further wo ...

  8. CXF:通过WebService上传文件,包括大文件的处理

    参考网上文章,用CXF发布上传文件接口,并上传大文件的测试. 框架:spring3.1+cxf2.7.6 1.定义文件类实体 import javax.activation.DataHandler; ...

  9. 如何更好的通过Inflate layout的方式来实现自定义view

    本篇文章讲的是如何用现有控件产生一个组合控件的方法,十分简单实用.现在开始! 一.需求 我们要实现一个有红点和文字的按钮控件,就像下面这样: 二.实现 我的思路是让一个button和一个textvie ...

  10. CAGradientLayer的一些属性解析

    CAGradientLayer的一些属性解析 iOS中Layer的坐标系统: 效果: - (void)viewDidLoad { [super viewDidLoad]; CAGradientLaye ...