2008年11月27日星期四

mmc/sd 在 2.6.27 2440

让板子能识别热插拔的卡。正好手上MMC卡和SD卡都有,能用

1. 先加上sdi的platform_device, s3c_device_sdi
arch/arm/mach-s3c2440/mach-smdk2440.c
static struct platform_device *smdk2440_devices[] __initdata = {
&s3c_device_usb,
&s3c_device_lcd,
&s3c_device_wdt,
&s3c_device_i2c,
&s3c_device_iis,
//zhourr
&s3c_device_adc,
&s3c_device_sdi,
};

2. 添加自己板子特别的地方,比如卡接的中断脚,卡插入检测脚,卡写保护脚,检测和写保护脚的极性,提供的sd卡电压范围
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. */
//zhourr
.wprotect_invert = 0,
.detect_invert = 0,
.gpio_detect = S3C2410_GPG8,
.gpio_wprotect = S3C2410_GPH8,
.ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34,
.set_power = NULL,
};

此时MMC卡已经可以热插拔,并在dev下找到mmcblk0

# ls -l /dev/mmc*
brw-rw---- 1 0 0 179, 0 Jan 1 00:03 /dev/mmcblk0

但是SD卡系统启动前正常,热插拔插入时会有timeout错误
错误1:
s3c2440-sdi s3c2440-sdi: mci_setup_data() transfer stillin progress.
s3c2440-sdi s3c2440-sdi: CMDSTAT: error CMDTIMEOUT
s3c2440-sdi s3c2440-sdi: CMD[ERR -110] #47 op:6 arg:0x00fffff1 flags:0x08b5 retries:0 Status:nothing to complete
s3c2440-sdi s3c2440-sdi: DAT[OK] #4 bsize:64 blocks:1 bytes:64
s3c2440-sdi s3c2440-sdi: powered down.
mmc0: error -110 whilst initialising SD card

错误2:
s3c2440-sdi s3c2440-sdi: unfinished read - pio_count:[0] pio_words:[16]
s3c2440-sdi s3c2440-sdi: CMD[OK] #68 op:6 arg:0x00fffff1 flags:0x08b5 retries:0 R0:0x00000900
s3c2440-sdi s3c2440-sdi: DAT[ERR -22] #6 bsize:64 blocks:1 bytes:64 DCNT:0x00000000
mmc0: problem reading switch capabilities, performance might suffer.

3.解决SD插入错误-->加延时
driver/mmc/core/sd.c 的mmc_sd_init_card()函数中mmc_read_switch前延时10ms

mdelay(10);

err = mmc_read_switch(card);

查看插入后的设备
# ls -l /dev/mmc*
brw-rw---- 1 0 0 179, 0 Jan 1 00:04 /dev/mmcblk0
brw-rw---- 1 0 0 179, 1 Jan 1 00:04 /dev/mmcblk0p1

mount后使用卡,可读写
# mount -t vfat /dev/mmcblk0p1 /opt/

写完后自己sync一下,确保写进去了,PC上就可以看到了


4.有个问题:
如果拔出太快又插入,现在会当作只拔出了。还不清楚MMC里怎么做的,要看一下了

1 条评论:

匿名 说...

ehh.. luv this text..