linux enc28j60网卡驱动移植(硬件spi和模拟spi)

时间:2022-10-01 21:51:49

本来想移植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)

linux enc28j60网卡驱动移植(硬件spi和模拟spi)

linux enc28j60网卡驱动移植(硬件spi和模拟spi)

谢谢!

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

  1. linux网卡驱动移植

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

  2. 【Linux驱动】TQ2440 DM9000E网卡驱动移植(Linux-2&period;6&period;30&period;4)

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

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

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

  4. AM335x&lpar;TQ335x&rpar;学习笔记——Nand&amp&semi;&amp&semi;网卡驱动移植

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

  5. AM335x&lpar;TQ335x&rpar;学习笔记——Nand&amp&semi;amp&semi;&amp&semi;amp&semi;网卡驱动移植

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

  6. Linux Charger IC 驱动移植总结

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

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

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

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

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

  9. mini2440移植uboot-2008&period;10 &lpar;二&rpar; DM9000网卡驱动移植

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

随机推荐

  1. CAD二次开发---导入外部文件中的块并输出预览图形(五)

    思路: 1)首先要定义一个数据库对象来表示包含块的文件,改数据库对象会被加载到内存中,但不会被显示在CAD窗口中. 2)调用Database类的ReadDwgFile函数将外部文件DWG文件读入到新创 ...

  2. Android成长日记-数据存储之SQLite&lbrack;1&rsqb;

    [SQLite简介] SQLite是R.Richard Hipp用C语言编写的开源嵌入式数据库引擎.它支持大多数的SQL92标准,并且可以在所有主要的操作系统上运行 ---支持高达2TB大小的数据库: ...

  3. Sprint第三个冲刺(第二天)

    一.Sprint介绍 任务进度: 二.Sprint周期 看板: 燃尽图:

  4. Sybase ASE无响应的又一个情况

    昨天下午,客户那边的系统管理员给我电话,说有套系统的SYBASE数据库最近有点怪,总是时不时莫名其妙地就忽然卡死,有可能一下子就自动恢复了,也有可能后面一直卡住,只好重启.根据客户反映的状况,初步判断 ...

  5. Spring 定时任务 quartz的配置

    环境:我用的是spring3.2,其中引入了quartz-1.5.2.jar 先写一个任务类: package com.hlcg.common.task; public class TestJob { ...

  6. C&sol;C&plus;&plus;中constkeyword

    今天在做一个趋势笔试题的时候.才让我有了系统把constkeyword好好总结一下的冲动,由于这个关键词大大小小好多地方都出现过,出现频率很高,而每次仅仅是简短的把答案看了一下,没有真正将其整个使用方 ...

  7. Chapter 2 Open Book——14

    I backpedaled. "They seemed nice enough to me. I just noticed they keptto themselves. 我改口说道,他们看 ...

  8. python利用django实现简单的登录和注册,并利用session实现了链接数据库

    利用session实现与数据库链接,登录模块(在views.py) def login(request): # return HttpResponseRedirect('/') # 判断是否post方 ...

  9. 【一天一道LeetCode】&num;118&period; Pascal&&num;39&semi;s Triangle

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given n ...

  10. 初始FreeMake

    此文章是观看视频学习的,只是一点点基础还不太深 视频地址:http://www.icoolxue.com/play/5773 源码:码云:https://gitee.com/wmjGood/FreeM ...