原文网址:http://blog.chinaunix.net/uid-29589379-id-4708909.html
原文地址:linux内核移植和驱动添加(三) 作者:genehang
四,LED驱动的添加
1, 将led.c驱动文件拷贝到linux-3.1.4/drivers/char/目录下
root@char# pwd
/change/linux-3.1.4/drivers/char
root@char# cp /mnt/hgfs/fh/driver/my_driver/led.c ./
2, 修改当前目录下的配置文件,增加内核配置项
root@char# vim Kconfig
添加:
config ARCH_S3C2410_LED
tristate "s3c2410 led support"
default y
help
s3c2410 led support
3, 修改Makefile,添加内核配置
root@char# vim Makefile
obj-$(CONFIG_ARCH_S3C2410_LED) +=led.o
4, 配置板文件资源
1)struct resource smdk2410_myres[] = {
[0] = {
.start = 0x56000054,
.end = 0x56000054,
.flags = IORESOURCE_MEM,
}, //GPFDAT
[1] = {
.start = 0x56000050,
.end = 0x56000050,
.flags = IORESOURCE_MEM,
}, //GPFCON
};
2)struct platform_device smdk2410_platdev = {
.name ="led_driver",//驱动程序里面的设备名
.id = 0,
.num_resources = ARRAY_SIZE(smdk2410_myres),
.resource = smdk2410_myres,
};
3)static struct platform_device *smdk2410_devices[] __initdata = {
&smdk2410_platdev,
}
注:我这里用的是fs2410开发板上的D12号led灯,配置其他的led灯同理。
5, 配置内核
root@linux-3.1.4# make menuconfig
Device Drivers --->
Character devices --->
<*> s3c2410 led support (NEW)
6, 重新编译内核
Make zImage
五,蜂鸣器的驱动添加
蜂鸣器的驱动添加和led的驱动添加过程是一样的,过程如下:
1, root@char# cp /mnt/hgfs/fh/driver/my_driver/beep.c ./
2, 修改drivers/char/Kconfig,提供内核配置项
config ARCH_S3C2410_BEEP
tristate "s3c2410 beep support
default y
help
s3c2410 beep support
3, 修改Makefile
obj-$(CONFIG_ARCH_S3C2410_BEEP) += beep.o
4, 资源选配,和led的资源选配同理
5, 选配内核
root@linux-3.1.4# make menuconfig
Device Drivers --->
Character devices --->
<*> s3c2410 beep support (NEW)
6, 编译内核
root@linux-3.1.4# make zImage
六,LCD驱动的添加
在嵌入式系统中,lcd常作为交互使用,其移植步骤如下:
1, 在板文件arch/arm/mach-s3c2410/mach-smdk2310.c中添加下列的头文件
root@mach-s3c2410# vim mach-smdk2410.c
#include <mach/fb.h>
#include <mach/regs-lcd.h>
2, 添加LCD相关的平台信息
root@mach-s3c2410# vim mach-smdk2410.c
//相关的配置信息根据LCD屏相应的参数配置
static struct s3c2410fb_display s3c2410_lcd_cfg[] __initdata = {
{
.lcdcon5 = S3C2410_LCDCON5_FRM565 |
S3C2410_LCDCON5_INVVCLK |
S3C2410_LCDCON5_INVVLINE |
S3C2410_LCDCON5_INVVFRAME|
S3C2410_LCDCON5_PWREN |
S3C2410_LCDCON5_HWSWP,
.type = S3C2410_LCDCON1_TFT,
.width = 320,
.height = 240,
.pixclock = 100000,
.xres = 320,
.yres = 240,
.bpp = 16,
.left_margin = 20,//13,
.right_margin = 38,//8,
.hsync_len = 30,//4,
.upper_margin = 4,//2,
.lower_margin = 15,//7,
.vsync_len = 3,//4,
},
};
static struct s3c2410fb_mach_info s3c2410_fb_info __initdata = {
.displays = s3c2410_lcd_cfg,
.num_displays = ARRAY_SIZE(s3c2410_lcd_cfg),
.default_display= 0,
.gpcup = 0xffffffff,
.gpcup_mask = 0xffffffff,
.gpccon = 0xaa9556a9,
.gpccon_mask = 0xffffffff,
.gpdup = 0xffffffff,
.gpdup_mask = 0xffffffff,
.gpdcon = 0xaaaaaaaa,
.gpdcon_mask = 0xffffffff,
.lpcsel = ((0xCE6) & ~7) | 1<<4,
};
static void __init smdk2410_init(void)
{
s3c24xx_fb_set_platdata(&s3c2410_fb_info);
}
3, 配置内核
root@linux-3.1.4# make menuconfig
Device Drivers --->
Graphics support --->
<*> Support for frame buffer devices --->
<*> S3C2410 LCD framebuffer support
[*] Bootup logo --->//LCD成功启动,就可以看见linuxLOGO^^
4,编译内核
make zImage
七,USB驱动的添加
1, 配置内核
root@linux-3.1.4# make menuconfig
Device Drivers --->
SCSI device support --->
<*> SCSI disk support
<*> SCSI generic support
<*> SCSI media changer support
[*] USB support --->
<*> USB Mass Storage support
File systems --->
-*- Native language support --->
<*> Codepage 437 (United States, Canada)
<*> Simplified Chinese charset (CP936, GB2312)
<*> ASCII (United States)
<*> NLS ISO 8859-1 (Latin 1; Western European Languages)
2, 编译内核
make zImage
八,视频V4L2驱动的添加
1, 配置内核
Device Drivers --->
<*> Multimedia support --->
<*> Video For Linux
[*] Video capture adapters (NEW) --->
[*] V4L USB devices (NEW) --->
<*> USB Video Class (UVC)
[*] UVC input events device support (NEW)
2,编译内核
make zImage
进过上面八个步骤的配置,我们可以在板子上面看见这样的打印信息:
Using CS8900-0 device
TFTP from server 192.168.2.201; our IP address is 192.168.2.200
Filename 'zImage'.
Load address: 0x30008000
Loading: #################################################################
#################################################################
####################################
done
Bytes transferred = 2430016 (251440 hex)
setup linux parameters at 0x30000100
linux command line is: "root=nfs nfsroot=192.168.2.201:/source/rootfs init=/linuxrc console=ttySAC0,115200 ip=192.168.2.200"
## Starting application at 0x30008000 ...
Uncompressing Linux... done, booting the kernel.
Linux version 3.1.4@genehang (root@ubuntu) (gcc version 4.4.3 (ctng-1.6.1) ) #7 Thu Jan 12 14:38:47 CST 2012
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=00007177
CPU: VIVT data cache, VIVT instruction cache
Machine: fs2410@panzhh
ATAG_INITRD is deprecated; please update your bootloader.
Memory policy: ECC disabled, Data cache writeback
BUG: mapping for 0x19000000 at 0xe0000000 overlaps vmalloc space
CPU S3C2410A (id 0x32410002)
S3C24XX Clocks, Copyright 2004 Simtec Electronics
S3C2410: core 202.800 MHz, memory 101.400 MHz, peripheral 50.700 MHz
CLOCK: Slow mode (1.500 MHz), fast, MPLL on, UPLL on
Built 1 zonelists in Zone order, mobility grouping on. Total pages: 16256
Kernel command line: root=nfs nfsroot=192.168.2.201:/source/rootfs init=/linuxrc console=ttySAC0,115200 ip=192.168.2.200
PID hash table entries: 256 (order: -2, 1024 bytes)
Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)
Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)
Memory: 64MB = 64MB total
Memory: 60140k/60140k available, 5396k reserved, 0K highmem
Virtual kernel memory layout:
vector : 0xffff0000 - 0xffff1000 ( 4 kB)
fixmap : 0xfff00000 - 0xfffe0000 ( 896 kB)
DMA : 0xffc00000 - 0xffe00000 ( 2 MB)
vmalloc : 0xc4800000 - 0xf6000000 ( 792 MB)
lowmem : 0xc0000000 - 0xc4000000 ( 64 MB)
modules : 0xbf000000 - 0xc0000000 ( 16 MB)
.text : 0xc0008000 - 0xc0439a60 (4295 kB)
.init : 0xc043a000 - 0xc045d000 ( 140 kB)
.data : 0xc045e000 - 0xc04864e0 ( 162 kB)
.bss : 0xc0486504 - 0xc04aead4 ( 162 kB)
NR_IRQS:85
irq: clearing subpending status 00000002
Console: colour dummy device 80x30
Calibrating delay loop... 50.17 BogoMIPS (lpj=125440)
pid_max: default: 32768 minimum: 301
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
gpiochip_add: gpios 256..271 (GPIOJ) failed to register
gpiochip_add: gpios 288..303 (GPIOK) failed to register
gpiochip_add: gpios 320..334 (GPIOL) failed to register
gpiochip_add: gpios 352..353 (GPIOM) failed to register
NET: Registered protocol family 16
S3C Power Management, Copyright 2004 Simtec Electronics
S3C2410: Initialising architecture
bio: create slab <bio-0> at 0
SCSI subsystem initialized
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 2048 (order: 2, 16384 bytes)
TCP bind hash table entries: 2048 (order: 1, 8192 bytes)
TCP: Hash tables configured (established 2048 bind 2048)
TCP reno registered
UDP hash table entries: 256 (order: 0, 4096 bytes)
UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
NET: Registered protocol family 1
RPC: Registered named UNIX socket transport module.
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
NetWinder Floating Point Emulator V0.97 (extended precision)
s3c-adc s3c24xx-adc: attached adc driver
JFFS2 version 2.2. (NAND) (SUMMARY) 漏 2001-2006 Red Hat, Inc.
ROMFS MTD (C) 2007 Red Hat, Inc.
msgmni has been set to 117
io scheduler noop registered
io scheduler deadline registered
io scheduler cfq registered (default)
Console: switching to colour frame buffer device 40x30
fb0: s3c2410fb frame buffer device
Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled
s3c2410-uart.0: ttySAC0 at MMIO 0x50000000 (irq = 70) is a S3C2410
console [ttySAC0] enabled
s3c2410-uart.1: ttySAC1 at MMIO 0x50004000 (irq = 73) is a S3C2410
lp: driver loaded but no devices found
==========beep==============
==========led=============
ppdev: user-space parallel port driver
brd: module loaded
loop: module loaded
Uniform Multi-Platform E-IDE driver
ide-gd driver 1.18
ide-cd driver 5.00
SCSI Media Changer driver v0.25
S3C24XX NAND Driver, (c) 2004 Simtec Electronics
s3c24xx-nand s3c2410-nand: Tacls=3, 29ns Twrph0=7 69ns, Twrph1=3 29ns
s3c24xx-nand s3c2410-nand: NAND hardware ECC
NAND device: Manufacturer ID: 0xec, Chip ID: 0x76 (Samsung NAND 64MiB 3,3V 8-bit)
Scanning device for bad blocks
Creating 4 MTD partitions on "NAND":
0x000000000000-0x000000040000 : "uBoot"
0x000000040000-0x000000440000 : "kernel"
0x000000440000-0x000000c40000 : "fs"
0x000000c40000-0x000004000000 : "extern fs"
Cirrus Logic CS8900A driver for Linux (Modified for SMDK2410)
eth0: CS8900A rev E at 0xe0000300 irq=53, addr: 00: 0:3E:26:0A: 0
ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
s3c2410-ohci s3c2410-ohci: S3C24XX OHCI
s3c2410-ohci s3c2410-ohci: new USB bus registered, assigned bus number 1
s3c2410-ohci s3c2410-ohci: irq 42, io mem 0x49000000
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 2 ports detected
Initializing USB Mass Storage driver...
usbcore: registered new interface driver usb-storage
USB Mass Storage support registered.
usbcore: registered new interface driver libusual
usbcore: registered new interface driver usbserial
USB Serial support registered for generic
usbcore: registered new interface driver usbserial_generic
usbserial: USB Serial Driver core
USB Serial support registered for FTDI USB Serial Device
usbcore: registered new interface driver ftdi_sio
ftdi_sio: v1.6.0:USB FTDI Serial Converters Driver
USB Serial support registered for pl2303
usbcore: registered new interface driver pl2303
pl2303: Prolific PL2303 USB to serial adaptor driver
mousedev: PS/2 mouse device common for all mice
S3C24XX RTC, (c) 2004,2006 Simtec Electronics
s3c-rtc s3c2410-rtc: rtc disabled, re-enabling
s3c-rtc s3c2410-rtc: rtc core: registered s3c as rtc0
Linux video capture interface: v2.00
usbcore: registered new interface driver uvcvideo
USB Video Class driver (1.1.1)
S3C2410 Watchdog Timer, (c) 2004 Simtec Electronics
s3c2410-wdt s3c2410-wdt: watchdog inactive, reset disabled, irq enabled
s3c-sdi s3c2410-sdi: powered down.
s3c-sdi s3c2410-sdi: mmc0 - using pio, sw SDIO IRQ
TCP cubic registered
NET: Registered protocol family 17
s3c-rtc s3c2410-rtc: setting system clock to 2003-12-26 11:23:28 UTC (1072437808)
cs8900_start
enable the ethernet controlle
request_irq
IP-Config: Guessing netmask 255.255.255.0
IP-Config: Complete:
device=eth0, addr=192.168.2.200, mask=255.255.255.0, gw=255.255.255.255,
host=192.168.2.200, domain=, nis-domain=(none),
bootserver=255.255.255.255, rootserver=192.168.2.201, rootpath=
VFS: Mounted root (nfs filesystem) on device 0:12.
Freeing init memory: 140K
Please press Enter to activate this console.
[root@$ /]#usb 1-1: new full speed USB device number 2 using s3c2410-ohci
uvcvideo: Found UVC 1.00 device USB2.0 Camera (1871:0316)
input: USB2.0 Camera as /devices/platform/s3c2410-ohci/usb1/1-1/1-1:1.0/input/input0
[root@$ /]#ls
beep_app dev home linuxrc root tmp
bin etc led_app mnt sbin usr
boot fun lib proc sys var