mmc rescan简析

来源:互联网 发布:南京财经大学网络 编辑:程序博客网 时间:2024/06/03 21:41

mmc rescan是mmc host的detect work的功能函数,该函数用于探测目标卡的类型并且根据mmc/sd/sdio协议进行comm的初始化。

void mmc_rescan(struct work_struct *work){static const unsigned freqs[] = { 400000, 300000, 200000, 100000 };struct mmc_host *host =container_of(work, struct mmc_host, detect.work);int i;bool extend_wakelock = false;if (host->rescan_disable)return;mmc_bus_get(host);/* * if there is a _removable_ card registered, check whether it is * still present */if (host->bus_ops && host->bus_ops->detect && !host->bus_dead    && !(host->caps & MMC_CAP_NONREMOVABLE))host->bus_ops->detect(host);//这里所做的事情:当我们进入delay work时,我们首先要检查一下,目标卡是否依然存在,如果仍然存在而且目标卡是可插拔的,那么我们需要先将该卡在内核留下的一些痕迹清除,重新探测该卡。所以一般如果是目标卡复位的话,一般是调用内核提供的专用的复位接口(如sdio_reset_comm等),而不是调度host的这个delay work,host->detect_change = 0;/* If the card was removed the bus will be marked * as dead - extend the wakelock so userspace * can respond */if (host->bus_dead)extend_wakelock = 1;/* * Let mmc_bus_put() free the bus/bus_ops if we've found that * the card is no longer present. */mmc_bus_put(host);mmc_bus_get(host);/* if there still is a card present, stop here */if (host->bus_ops != NULL) { //判断是否bus的引用计数是否为0,如果不为0 ,说明bus仍然被引用,不能再继续下面的探测了。mmc_bus_put(host);goto out;}/* * Only we can add a new handler, so it's safe to * release the lock here. */mmc_bus_put(host);if (host->ops->get_cd && host->ops->get_cd(host) == 0)goto out;mmc_claim_host(host);for (i = 0; i < ARRAY_SIZE(freqs); i++) {if (!mmc_rescan_try_freq(host, max(freqs[i], host->f_min))) {extend_wakelock = true;break;}if (freqs[i] <= host->f_min)break;}mmc_release_host(host); out:if (extend_wakelock)wake_lock_timeout(&host->detect_wake_lock, HZ / 2);elsewake_unlock(&host->detect_wake_lock);if (host->caps & MMC_CAP_NEEDS_POLL) {wake_lock(&host->detect_wake_lock);mmc_schedule_delayed_work(&host->detect, HZ);}}


0 0
原创粉丝点击