Author: Guowenxue Date: 2009.06.26
添加USB设备驱动
一,修改文件: linux-2.6.28/arch/arm/mach-s3c2410/mach-smdk2410.c
头文件处包含下面头文件:
#include <mach/usb-control.h>
#include <mach/regs-gpio.h>
#include <mach/regs-clock.h>
#include <linux/delay.h> // For mdelay()
添加USB设备及其初始化函数:
// add by guowenxue, 2009.06.26
static struct s3c2410_hcd_info s3c2410_usb_info = {
.port[0] = { .flags = S3C_HCDFLG_USED }, // Macro defined in mach/usb-control.h
// .port[1] = { .flags = S3C_HCDFLG_USED },
};
int s3c2410_usb_init(void)
{
unsigned long upllvalue = (0x78<<12)|(0x02<<4)|(0x03);
printk("Initial S3C241 USB Control, (c) 2009 kernel.\n");
s3c_device_usb.dev.platform_data = &s3c2410_usb_info;
// Follow two Macro defined in mach/regs-gpio.h
s3c2410_modify_misccr(S3C2410_MISCCR_USBSUSPND0 | S3C2410_MISCCR_USBSUSPND1, 0x8);
// S3C2410_UPLLCON defined in mach/regs-clock.h
while(upllvalue!=__raw_readl(S3C2410_UPLLCON))
{
__raw_writel(upllvalue,S3C2410_UPLLCON);
mdelay(1);
}
return 0;
}
// add end
在函数static void __init smdk2410_init(void)中调用USB设备初始化函数:
static void __init smdk2410_init(void)
{
platform_add_devices(smdk2410_devices, ARRAY_SIZE(smdk2410_devices));
s3c24xx_fb_set_platdata(&smdk2410_fb_info); //This line add by guowenxue 2009.05.24
s3c2410_usb_init();
smdk_machine_init();
}
二.Make menuconfig时选择USB驱动支持:
Device Drivers --->
[*] USB support --->
[*] Support for Host-side USB
[*] USB device filesystem
[*] OHCI HCD support
[*] USB Mass Storage support
[*] The shared table of common (or usual) storage devices
由于U盘最终还是模拟为SCSI设备来访问,所以还得选上SCSI层的支持
SCSI device support --->
[*] SCSI device support
[*] SCSI target support
[*] legacy /proc/scsi/ support
[*] SCSI disk support
由于没有选IS08859-1这个字符编码方式,所以在mount U盘的时候,会出现下面这个错误:
>: mount -t vfat /dev/sda1 /mnt/
FAT: IO charset iso8859-1 not found
mount: mounting /dev/sda1 on /mnt/ failed: Invalid argument
这时,需要make menuconfig时选择ISO8859的支持:
File systems --->
-*- Native language support --->
--- Native language support
(iso8859-1) Default NLS Option
[*] NLS ISO 8859-1 (Latin 1; Western European Languages)
当然也可以设置其他编码方式:
[*] Codepage 437 (United States, Canada)
[*] Simplified Chinese charset (CP936, GB2312)
[*] ASCII (United States)
[*] NLS UTF-8
后记:
估计是硬件上的问题,开发板上的USB port2不能使用,内核在启动时会抛出下面错误信息:
hub 1-0:1.0: Cannot enable port 2. Maybe the USB cable is bad?
hub 1-0:1.0: Cannot enable port 2. Maybe the USB cable is bad?
hub 1-0:1.0: Cannot enable port 2. Maybe the USB cable is bad?
hub 1-0:1.0: Cannot enable port 2. Maybe the USB cable is bad?
hub 1-0:1.0: unable to enumerate USB device on port 2
大学买的那个清华紫光512M U盘在s3c2410上的使用情况:
插入U盘后:
scsi 0:0:0:0: Direct-Access 2.0 USB Flash Drive 1.00 PQ: 0 ANSI: 2
sd 0:0:0:0: [sda] 1032192 512-byte hardware sectors: (528 MB/504 MiB)
sd 0:0:0:0: [sda] Write Protect is off
sd 0:0:0:0: [sda] Assuming drive cache: write through
sd 0:0:0:0: [sda] 1032192 512-byte hardware sectors: (528 MB/504 MiB)
sd 0:0:0:0: [sda] Write Protect is off
sd 0:0:0:0: [sda] Assuming drive cache: write through
sda: sda1
sd 0:0:0:0: [sda] Attached SCSI removable disk
>: fdisk -l
Disk /dev/sda: 528 MB, 528482304 bytes
65 heads, 32 sectors/track, 496 cylinders
Units = cylinders of 2080 * 512 = 1064960 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 497 516080 b Win95 FAT32
Partition 1 has different physical/logical endings:
phys=(502, 64, 32) logical=(496, 15, 32)
>: mount -t vfat /dev/sda1 /mnt/
>: ls /mnt/
LanQQ SCSI-2.4-HOWTO.pdf ttx.zip
添加SD卡设备驱动:
在linux-2.6.28内核树里,针对s3c2410的SD卡驱动已经完全支持了,只需要修改下面几处:
修改文件arch/arm/mach-s3c2410/mach-smdk2410.c,添加SD卡设备支持:
static struct platform_device *smdk2410_devices[] __initdata = {
&s3c_device_usb,
&s3c_device_lcd,
&s3c_device_wdt,
&s3c_device_i2c,
&s3c_device_iis,
&s3c_device_dm9000, // this member add by guowenxue 2008.05.15
&s3c_device_sdi, // this member add by guowenxue 2009.06.30
};
修改文件linux-2.6.28/drivers/mmc/host/s3cmci.c,
static struct s3c24xx_mci_pdata s3cmci_def_pdata = {
/* This is currently here to avoid a number of if (host->pdata)
* checks. Any zero fields to ensure reaonable defaults are picked. */
// Follow member setting add by guowenxue 2009.07.01, original is NULL.
// add by guowenxue
.gpio_detect = S3C2410_GPG10,
.gpio_wprotect = S3C2410_GPH8,
.ocr_avail = MMC_VDD_32_33,
.wprotect_invert = 0,
.detect_invert = 0,
.set_power = NULL,
// add end
};
make menuconfig 时选择:
Device Drivers --->
[*] MMC/SD/SDIO card support --->
[*] MMC block device driver
[*] Use bounce buffer for simple hosts
[*] Samsung S3C SD/MMC Card Interface support
插入SD卡系统启动,内核打印信息如下:
S3C24XX RTC, (c) 2004,2006 Simtec Electronics
S3C2410 Watchdog Timer, (c) 2004 Simtec Electronics
s3c2410-wdt s3c2410-wdt: watchdog inactive, reset disabled, irq enabled
s3c2410-sdi s3c2410-sdi: host detect has no irq available
mapped channel 0 to 0
s3c2410-sdi s3c2410-sdi: powered down.
s3c2410-sdi s3c2410-sdi: initialisation done.
s3c2410-sdi s3c2410-sdi: running at 0kHz (requested: 0kHz).
s3c2410-sdi s3c2410-sdi: running at 98kHz (requested: 97kHz).
s3c2410-sdi s3c2410-sdi: running at 98kHz (requested: 97kHz).
s3c2410-sdi s3c2410-sdi: running at 98kHz (requested: 97kHz).
TCP cubic registered
NET: Registered protocol family 17
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
s3c2410-sdi s3c2410-sdi: running at 98kHz (requested: 97kHz).
s3c2410-sdi s3c2410-sdi: running at 98kHz (requested: 97kHz).
s3c2410-sdi s3c2410-sdi: running at 98kHz (requested: 97kHz).
VFS: Mounted root (cramfs filesystem) readonly.
Freeing init memory: 128K
s3c2410-sdi s3c2410-sdi: running at 98kHz (requested: 97kHz).
s3c2410-sdi s3c2410-sdi: running at 25000kHz (requested: 25000kHz).
s3c2410-sdi s3c2410-sdi: running at 25000kHz (requested: 25000kHz).
mmc0: new SD card at address 0001
mmcblk0: mmc0:0001 946 MiB
mmcblk0: p1
usb 1-1: new full speed USB device using s3c2410-ohci and address 2
usb 1-1: configuration #1 chosen from 1 choice
scsi0 : SCSI emulation for USB Mass Storage devices
eth0: link down
eth0: link up, 100Mbps, full-duplex, lpa 0x45E1
在根文件系统中加入SD卡设备:
首先看SD卡设备的主设备号:
>: cat /proc/devices
Character devices:
1 mem
2 pty
3 ttyp
4 /dev/vc/0
4 tty
5 /dev/tty
5 /dev/console
5 /dev/ptmx
7 vcs
10 misc
13 input
29 fb
90 mtd
128 ptm
136 pts
152 aoechr
180 usb
189 usb_device
204 s3c2410_serial
254 usb_endpoint
Block devices:
1 ramdisk
259 blkext
7 loop
8 sd
31 mtdblock
43 nbd
65 sd
66 sd
67 sd
68 sd
69 sd
70 sd
71 sd
128 sd
129 sd
130 sd
131 sd
132 sd
133 sd
134 sd
135 sd
152 aoe
179 mmc
查出主设备号为179 。添加设备结点,并生成cramfs文件系统:
[root:/root/myBoard/rootfs/cramfs/dev]#mknod -m 755 mmcblk0 b 179 1
[root:/root/myBoard/rootfs/cramfs/dev]#mknod -m 755 mmcblk1 b 179 2
[root:/root/myBoard/rootfs]#sh mkcramfs.sh
Directory data: 9200 bytes
Everything: 3968 kilobytes
Super block: 76 bytes
CRC: 5738225d
warning: gids truncated to 8 bits (this may be a security concern)
[root:/root/myBoard/rootfs]#cat mkcramfs.sh
#!/bin/sh
rm -f /mnt/hgfs/winxp/image/cramfs.img
mkcramfs cramfs cramfs.img
mv cramfs.img /mnt/hgfs/winxp/image/
烧写新的文件系统并重启后,挂载SD卡:
>: mount -t vfat /dev/mmcblk0 /mnt/
>: ls /mnt/
terminal test.txt