enc28j60网卡驱动模块添加进Linux内核,Kconfig,Ma

这里是要把  中的enc28j60网卡驱动模块,添加到2.6.22.6内核中,这个模块代码不需要任何修改。只需要在内核目录下的相关配置脚本文件,如Makefile,Kconfig,.config等,修改某些配置就行。

enc28j60网卡驱动模块使用到的几个文件:

enc28j60.c

enc28j60_hw.h

spi_bitbang.c

spi_s3c24xx.c

spi_platform_dev.c

实际上spi_bitbang.c,spi_s3c24xx.c为内核原生文件,也不需要任何改动。在这个例子中,我的内核没有把这两个文件编译进去。因此需要手动把这两个文件加载进去。

在这里,我们在内核添加

enc28j60.c

enc28j60_hw.h

spi_platform_dev.c

这3个文件即可。

enc28j60.c,enc28j60_hw.h这两个文件,是与平台无关的网络驱动,因此把他们放到linux-2.6.22.6/drivers/net目录下。

spi_platform_dev.c是与平台硬件有直接关系,因此把它放到linux-2.6.22.6/arch/arm/plat-s3c24xx目录下。

1. 把spi模块添加进内核

a. 进入到linux-2.6.22.6源码目录下

make makeconfig

这样,就会在中端显示图形界面的内核配置菜单,找到SPI相关的配置:

Device Drivers  --->

SPI support  --->

[*] SPI support

[*] SPI Master Support

<*>  Bitbanging SPI master

<*>  Samsung S3C24XX series SPI

<M>  Samsung S3C24XX series SPI by GPIO

在[]或<>的条目按空格键,*号表示把相关的模块文件添加进内核,M表示把相关的文件编译成模块,不添加到内核,空格表示不配置:如

[*] SPI support  设置把linux-2.6.22.6\drivers\spi目录添加到上层drivers目录

[*] SPI Master Support  设置把spi.c添加进内核

<*>  Bitbanging SPI master  设置把spi_bitbang.c添加进内核

<*>  Samsung S3C24XX series SPI 设置把spi_s3c24xx.c添加内核,硬件SPI

<M>  Samsung S3C24XX series SPI by GPIO  设置把spi_s3c24xx_gpio.c生成模块,模拟SPI

b. 退出配置菜单,保存,会在linux-2.6.22.6源码目录下生成.config文件。

vi .config

找到SPI的相关配置:

# # SPI support # CONFIG_SPI=y # CONFIG_SPI_DEBUG is not set CONFIG_SPI_MASTER=y # # SPI Master Controller Drivers # CONFIG_SPI_BITBANG=y # CONFIG_SPI_BUTTERFLY is not set CONFIG_SPI_S3C24XX=y CONFIG_SPI_S3C24XX_GPIO=m # # SPI Protocol Masters # # CONFIG_SPI_AT25 is not set # CONFIG_SPI_SPIDEV is not set


对应关系:

[*] SPI support  对应生成配置CONFIG_SPI=y

[*] SPI Master Support 对应生成配置 CONFIG_SPI_MASTER=y

<*>  Bitbanging SPI master 对应生成配置 CONFIG_SPI_BITBANG=y

... ....

[]或<>里面是空格的,对应生成CONFIG_XXX is not set

也就是说如果不使用make menuconfig图形界面, 可以直接修改.config文件。

c. 在各层Kconfig和Makefile的配置关系

linux-2.6.22.6\drivers\Kconfig

... ... source "drivers/spi/Kconfig" ... ...

linux-2.6.22.6\drivers\Makefile

... ... obj-$(CONFIG_SPI) += spi/ ... ...

linux-2.6.22.6\drivers\spi\Kconfig,这个文件里的配置是用于make menuconfig里的菜单项显示,如make menuconfig之后。"config SPI"会在linux-2.6.22.6\.config生成CONFIG_SPI的宏,

make menuconfig中的[*] SPI support  对应生成配置CONFIG_SPI=y

... ... config SPI bool "SPI support" help The "Serial Peripheral Interface" is a low level synchronous protocol. Chips that support SPI can have data transfer rates up to several tens of Mbit/sec. Chips are addressed with a controller and a chipselect. Most SPI slaves don't support dynamic device discovery; some are even write-only or read-only. SPI is widely used by microcontrollers to talk with sensors, eeprom and flash memory, codecs and various other controller chips, analog to digital (and d-to-a) converters, and more. MMC and SD cards can be accessed using SPI protocol; and for DataFlash cards used in MMC sockets, SPI must always be used. SPI is one of a family of similar protocols using a four wire interface (select, clock, data in, data out) including Microwire (half duplex), SSP, SSI, and PSP. This driver framework should work with most such devices and controllers. ... ... config SPI_MASTER boolean "SPI Master Support" help If your system has an master-capable SPI controller (which provides the clock and chipselect), you can enable that controller and the protocol drivers for the SPI slave chips that are connected. ... ... config SPI_BITBANG tristate "Bitbanging SPI master" depends on SPI_MASTER && EXPERIMENTAL help With a few GPIO pins, your system can bitbang the SPI protocol. Select this to get SPI support through I/O pins (GPIO, parallel port, etc). Or, some systems' SPI master controller drivers use this code to manage the per-word or per-transfer accesses to the hardware shift registers. This is library code, and is automatically selected by drivers that need it. You only need to select this explicitly to support driver modules that aren't part of this kernel tree. ... ... config SPI_S3C24XX tristate "Samsung S3C24XX series SPI" depends on SPI_MASTER && ARCH_S3C2410 && EXPERIMENTAL help SPI driver for Samsung S3C24XX series ARM SoCs ... ... 

linux-2.6.22.6\drivers\spi\Makefile

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/247c813e5623e6739339ea78b9c054d9.html