新路程 imx6 sd卡部分摘要

2021-08-11 19:17:01 字數 4405 閱讀 8064

首先iomux-mx6q.h裡

mx6_sabresd_board_init裡

if (cpu_is_mx6q()) ;

然後看sd卡的資源,在board-mx6q_sabresd.c 裡

static const struct esdhc_platform_data mx6q_sabresd_sd2_data __initconst = ;

這個cd_gpio

//#define sabresd_sd2_cdimx_gpio_nr(2, 2)

#define sabresd_sd2_cdimx_gpio_nr(1, 4)  本來是2,2,現在用的1,4,其實這樣改了以後本來是gpio2,2.現在gpio1,4,都是gpio功能,所以是一樣的

在sdhci-esdhc-imx.c裡

err = gpio_request_one(boarddata->cd_gpio, gpiof_in, "esdhc_cd");

err = request_irq(gpio_to_irq(boarddata->cd_gpio), cd_irq,irqf_trigger_falling | irqf_trigger_rising,mmc_hostname(host->mmc), host);

printk("matt-err2=%d \n",err);

sdhci-esdhc-imx.c

tasklet_schedule(&sdhost->card_tasklet);

這個card_tasklet在下面init

sdhci.c

tasklet_init(&host->card_tasklet,

sdhci_tasklet_card, (unsigned long)host);

sdhci.c中

static void sdhci_tasklet_card(unsigned long param)

mmc_detect_change(host->mmc, msecs_to_jiffies(500));

core.c中

void mmc_detect_change(struct mmc_host *host, unsigned long delay)

這個函式執行緒init在

host.c中mmc_alloc_host函式中

init_delayed_work(&host->detect, mmc_rescan);

看看mmc_rescan

在core.c

void mmc_rescan(struct work_struct *work);/*

* card detection callback from host.

*/static void mmc_sd_detect(struct mmc_host *host)

break;

}if (!retries)

#else

err = mmc_send_status(host->card, null);

#endif

mmc_release_host(host);

if (err)

}core.c中

這是第二條路,是正確的路,被log驗證了,是插入的時候用的

void mmc_rescan(struct work_struct *work)

for (i = 0; i < array_size(freqs); i++)

static int mmc_rescan_try_freq(struct mmc_host *host, unsigned freq)

if (!mmc_attach_sdio(host))

return 0;

if (!mmc_attach_sd(host))

return 0;

if (!mmc_attach_mmc(host))

return 0;

sd.c裡

int mmc_attach_sd(struct mmc_host *host)

mmc_release_host(host);

err = mmc_add_card(host->card);

mmc_claim_host(host);

bus.c裡

int mmc_add_card(struct mmc_card *card)

printk(kern_info "%s: new %s%s%s card at address %04x\n",

這裡有中斷了,但是由於電平是相反的,所以看看remove啥時候開始被呼叫

core.c中呼叫了後面的remove,由於ops一直沒有繫結成功,所以這裡一直失敗,一開始我們的sd卡沒有插入,

所以初始化到mmc_rescan_try_freq裡的if (!mmc_attach_sd(host))裡頭沒有繫結ops和host,所以當我們開機後插入sd卡,一樣是進不了detect的,

還是跑初始化的mmc_rescan_try_freq裡的if (!mmc_attach_sd(host))

if (host->bus_ops && host->bus_ops->detect && !host->bus_dead

&& !(host->caps & mmc_cap_nonremovable))

host->bus_ops->detect(host);這裡如果detect失敗就會呼叫下面的remove

這裡的host->bus_ops在sd.c中

這裡的host->caps在

sdhci-esdhc-imx.c (drivers\mmc\host):host->mmc->caps |= mmc_cap_nonremovable;

sdhci-esdhc-imx.c (drivers\mmc\host):host->mmc->caps &= ~mmc_cap_nonremovable;賦值的

而決定這個賦值的是

board-mx6q_sabresd.c

static const struct esdhc_platform_data mx6q_sabresd_sd2_data __initconst = ;

而檢測函式失敗最後呼叫的就是下面的

sd.c

static const struct mmc_bus_ops mmc_sd_ops = ;

static void mmc_sd_remove(struct mmc_host *host)

獲取gpio 1-4的狀態可以

gpio_state = gpio_get_value(4);

printk("matt-gpio_state=%d\n",gpio_state);

sd卡軟體部分驗證完畢,無事可做了,然而峰迴路轉,偶然把

static const struct esdhc_platform_data mx6q_sabresd_sd2_data __initconst = ;

我就納悶了,乙個管腳有什麼影響,於是搜

在sdhci-esdhc-imx.c裡看到

如果有cd pin,則這兩句話會執行

imx_data->flags |= esdhc_flag_gpio_for_cd_wp;

host->quirks &= ~sdhci_quirk_broken_card_detection;經過驗證,這句話起主要作用

在sdhci.c中發現這個變數會影響sd卡的狀態

if (host->quirks & sdhci_quirk_broken_card_detection)

present = true;

else

present = sdhci_readl(host, sdhci_present_state) &sdhci_card_present;

由於前面設定的是取反,納悶這裡肯定走else,這個readl被我偶然看到在

sdhci.h中

static inline u32 sdhci_readl(struct sdhci_host *host, int reg)

然後到sdhci-esdhc-imx.c裡

在esdhc_readl_le這個函式中

if (boarddata && gpio_is_valid(boarddata->cd_gpio)

&& gpio_get_value(boarddata->cd_gpio))  //果然根據cd pin的狀態決定當前卡的狀態,由於我們的板子和開發板是相反的電平,所以一直出錯

/* no card, if a valid gpio says so */

//val &= ~sdhci_card_present;

val |= sdhci_card_present;

else

/* in all other cases assume card is present */

//val |= sdhci_card_present;

val &= ~sdhci_card_present;

新路程 imx6 i2c clk頻率修改

最近有個需求,動態修改頻率,小看了一下,驗證了幾個猜想 在i2c imx.c中,probe函式裡的pdev id就是bus number 而頻率的設定在i2c imx start這個函式的 if pdata pdata bitrate i2c imx set clk i2c imx,pdata bi...

imx6 移植人臉識別

最近接到任務要移植人臉檢測,其他步驟網上都有,一步步做就好了,就是在載入haarcascade frontalface alt2.xml的時候,出現 root dchip linux qt opencv 2.4.13.1 modules core src persistence.cpp 5008 e...

IMX6清空framebuffer操作

static void fb clear int fb unsigned char fb mem fb open dev fb0 o rdwr fb mem mmap null,1920 720,prot read prot write,map shared,fb,0 memset fb mem,0...