Linux-2.6.32.2內(nèi)核在mini2440上的移植(十一)---移植SD卡驅(qū)動(dòng)
掃描二維碼
隨時(shí)隨地手機(jī)看文章
移植環(huán)境
1,主機(jī)環(huán)境:VMare下CentOS 5.5 ,1G內(nèi)存。
2,集成開發(fā)環(huán)境:Elipse IDE
3,編譯編譯環(huán)境:arm-linux-gcc v4.4.3,arm-none-linux-gnueabi-gcc v4.5.1。
4,開發(fā)板:mini2440,2M nor flash,128M nand flash。
5,u-boot版本:u-boot-2009.08
6,linux 版本:linux-2.6.32.2
7,參考文章:
嵌入式linux應(yīng)用開發(fā)完全手冊(cè),韋東山,編著。
Mini2440 之Linux 移植開發(fā)實(shí)戰(zhàn)指南
【1】在內(nèi)核中注冊(cè)SD 設(shè)備驅(qū)動(dòng)
Linux-2.6.32.2 已經(jīng)自帶了S3C2440 芯片的SD 卡驅(qū)動(dòng),我們只需在初始化代碼中加入SD 平臺(tái)設(shè)備結(jié)構(gòu)就可以,打開arch/arm/mach-s3c2440/mach-mini2440.c,在開始部分添加如下紅色代碼的頭文件:
#include
#include
//添加SD 卡設(shè)備結(jié)構(gòu)所需的頭文件
#include
#include
然后定位到304行附近,加入如下代碼:
static struct platform_device mini2440_device_eth = {
.name = "dm9000",
.id = -1,
.num_resources = ARRAY_SIZE(mini2440_dm9k_resource),
.resource = mini2440_dm9k_resource,
.dev = {
.platform_data = &mini2440_dm9k_pdata,
},
};
/* MMC/SD */
static struct s3c24xx_mci_pdata mini2440_mmc_cfg = {
.gpio_detect = S3C2410_GPG(8),
.gpio_wprotect = S3C2410_GPH(8),
.set_power = NULL,
.ocr_avail = MMC_VDD_32_33|MMC_VDD_33_34,
};
static struct platform_device *mini2440_devices[] __initdata = {
&s3c_device_usb,
&s3c_device_rtc,
&s3c_device_lcd,
&s3c_device_wdt,
&s3c_device_i2c0,
&s3c_device_iis,
&s3c_device_nand, //;把nand flash 設(shè)備添加到開發(fā)板的設(shè)備列表結(jié)構(gòu)
&mini2440_device_eth,//;把網(wǎng)卡平臺(tái)設(shè)備添加到開發(fā)板的設(shè)備列表結(jié)構(gòu)
&s3c_device_sdi,//把SD 卡結(jié)構(gòu)設(shè)備添加到目標(biāo)平臺(tái)設(shè)備集中
};
定位到333行附近,在平臺(tái)初始化部分加入:
static void __init mini2440_map_io(void)
{
s3c24xx_init_io(mini2440_iodesc, ARRAY_SIZE(mini2440_iodesc));
s3c24xx_init_clocks(12000000);
s3c24xx_init_uarts(mini2440_uartcfgs, ARRAY_SIZE(mini2440_uartcfgs));
}
static void __init mini2440_machine_init(void)
{
#if defined (LCD_WIDTH)
s3c24xx_fb_set_platdata(&mini2440_fb_info);
#endif
s3c_device_sdi.dev.platform_data = &mini2440_mmc_cfg;
s3c_i2c0_set_platdata(NULL);
s3c_device_nand.dev.platform_data = &mini2440_nand_info;
platform_add_devices(mini2440_devices, ARRAY_SIZE(mini2440_devices));
//smdk_machine_init();
}
SD 卡的驅(qū)動(dòng)程序底層操作實(shí)際對(duì)應(yīng)源代碼linux-2.6.32.2/drivers/mmc/host/s3cmci.c,根據(jù)測(cè)試,當(dāng)包含內(nèi)核打印信息時(shí),SD 卡可以被正常識(shí)別使用,而沒有打印信息時(shí),則表現(xiàn)的不太穩(wěn)定,因此我們?cè)谠摮绦蛑刑砑恿艘痪溲訒r(shí)代碼,如下:
打開linux-2.6.32.2/drivers/mmc/host/s3cmci.c,定位到490行附近,修改如下:
//;延時(shí)函數(shù)所需的頭文件
#include
static void pio_tasklet(unsigned long data)
{
struct s3cmci_host *host = (struct s3cmci_host *) data;
s3cmci_disable_irq(host, true);
udelay(50);//在此處添加了延時(shí)函數(shù)
if (host->pio_active == XFER_WRITE)
do_pio_write(host);
... ...
這樣,我們就完成了SD 卡驅(qū)動(dòng)的移植。
【2】配置內(nèi)核,確認(rèn)配置選項(xiàng)
確認(rèn)內(nèi)核已經(jīng)配置了如下選項(xiàng):
Device Drivers --->
<*> MMC/SD/SDIO card support --->
<*> MMC block device driver
<*> Secure Digital Host Controller Interface support
<*> Samsung S3C SD/MMC Card Interface support
退出并保存以上配置。
【3】重新編譯測(cè)試
執(zhí)行make uImage ,把生成的uImage復(fù)制到/nfsboot/kernel,然后重啟開發(fā)板可以看到如下信息:
... ...
sdhci: Secure Digital Host Controller Interface driver
sdhci: Copyright(c) Pierre Ossman
s3c-sdi s3c2440-sdi: powered down.
s3c-sdi s3c2440-sdi: mmc0 - using pio, sw SDIO IRQ
... ...
回車后進(jìn)入控制臺(tái),然后插入SD卡:
[root@mini2440 /]#s3c-sdi s3c2440-sdi: running at 0kHz (requested: 0kHz).
s3c-sdi s3c2440-sdi: running at 398kHz (requested: 400kHz).
s3c-sdi s3c2440-sdi: running at 398kHz (requested: 400kHz).
s3c-sdi s3c2440-sdi: running at 398kHz (requested: 400kHz).
s3c-sdi s3c2440-sdi: running at 398kHz (requested: 400kHz).
s3c-sdi s3c2440-sdi: running at 398kHz (requested: 400kHz).
s3c-sdi s3c2440-sdi: running at 398kHz (requested: 400kHz).
s3c-sdi s3c2440-sdi: running at 398kHz (requested: 400kHz).
s3c-sdi s3c2440-sdi: running at 16875kHz (requested: 25000kHz).
s3c-sdi s3c2440-sdi: running at 16875kHz (requested: 25000kHz).
mmc0: new SD card at address e06f
mmcblk0: mmc0:e06f SS128 122 MiB
mmcblk0: p1
[root@mini2440 /]#ls /dev/mmc*
/dev/mmcblk0/dev/mmcblk0p1
[root@mini2440 /]#mount -t vfat /dev/mmcblk0p1 /mnt/sdcard
[root@mini2440 /]#cd /mnt/sdcard
[root@mini2440 sdcard]#ls
DCIM uImage_T35
[root@mini2440 sdcard]#
可以看到上面列出了SD卡的內(nèi)容。
有關(guān)mini2440的SD部分代碼詳情請(qǐng)參見Mini2440 SDcard啟動(dòng)分析。
接下來,移植I2C EEPROM驅(qū)動(dòng)