mmc_rescan_try_freq 简析

本文深入分析了mmc_rescan_try_freq函数在MMC卡初始化阶段如何通过不同频率尝试与目标卡建立连接。重点介绍了从上电到复位硬件、初始化I/O和内存控制器的过程,并详细解释了如何根据不同类型的MMC卡(如SD、SDIO、SD卡和SDIO卡组合)进行正确的初始化操作。

继之前的文章mmc_rescan之后,我们来分析一下mmc_rescan_try_freq,顾名思义,就是用不同的clock去尝试初始化与目标卡的连接。

static int mmc_rescan_try_freq(struct mmc_host *host, unsigned freq)
{
	host->f_init = freq; //根据mmc_recan函数传进来的参数知道,首先传进来的是400kHZ.一般mmc/sd/sdio的初始化时钟采用的是400kHZ.

#ifdef CONFIG_MMC_DEBUG
	pr_info("%s: %s: trying to init card at %u Hz\n",
		mmc_hostname(host), __func__, host->f_init);
#endif
1.	mmc_power_up(host); //上电,我们知道,在mmc_add_host时,会调用mmc_start_host,而那里首先是将host掉电的。这里上电。

	/*
	 * Some eMMCs (with VCCQ always on) may not be reset after power up, so
	 * do a hardware reset if possible.
	 */
	mmc_hw_reset_for_init(host); //复位硬件,可以选择性实现。

	/* Initialization should be done at 3.3 V I/O voltage. */
	mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_330, 0);//这里其实什么事情都没做,因为一般host控制器并不会实现host->ops->start_signal_voltage_switch

	/*
	 * sdio_reset sends CMD52 to reset card.  Since we do not know
	 * if the card is being re-initialized, just send it.  CMD52
	 * should be ignored by SD/eMMC cards.
	 */
	2. sdio_reset(host);//①如果目标卡是纯SD卡(对MMC卡不了解,所以不加评论),则目标卡不会应答,一般主机host的寄存器会报错,但是这个无关紧要,可以不理它。②如果目标卡是纯SDIO卡,那么这里就是复位SDIO卡,通过命令CMD52来实现的。③如果目标卡是SD卡和SDIO卡的组合卡,则需要先发送CMD52来复位SDIO卡,再复位SD卡,因为CMD52要先于CMD0发送。

When the host re-initializes both I/O and Memory controllers, it is strongly recommended that the host either execute a power reset (power off then on) or issues a reset commands to both controllers prior to any other operation. If the host chooses to use the reset commands, it shall issue CMD52 (I/O Reset) first, because it cannot issue CMD52 after CMD0 (see 4.4). After the reset, the host shall re-initialize both the I/O and Memory controller as defined in Figure 3-2.(协议)
	
	3. mmc_go_idle(host); //发送CMD0 复位SD卡。

	4. mmc_send_if_cond(host, host->ocr_avail); //为了支持sd version 2.0以上的sd卡,在初始化的过程中必须在发送ACMD41之前,先发送CMD8,CMD8一般是用于检测SD卡是否能运行在host提供的电压范围内。大家可能发现,这个调用过程没有检查是否出错,其实一般CMD8是用来辨别目标卡是否是高容量SD卡,如果是,CMD8 会有R7应答,R7应答中会有目标SD卡支持的电压范围以及CMD8中发送过去的“check pattern(一般是0xAA)”,否则,目标卡不会应答,在Linux 内核代码中,判断是这样的,如果应答,目标卡就是SD高容量卡,否则出现应答超时错误,就是标准SD卡!这里的调用,主要作用是为了在发送ACMD41之前发送CMD8,这是version 2.0及以上的规定顺序,后面还会有发送CMD8的地方,那里才是真正检测目标卡的类型的地方。
 

	/* Order's important: probe SDIO, then SD, then MMC */
	5 .if (!mmc_attach_sdio(host))
		return 0;
	6.if (!mmc_attach_sd(host))
		return 0;
	7.if (!mmc_attach_mmc(host))
		return 0;
	Linux 卡的探测顺序是:先辨别卡是否是sdio功能卡或者是sdio与sd卡的组合卡,然后辨别是否是SD卡,最后才会辨别是否是mmc卡。
	mmc_power_off(host); 
	return -EIO;
}


void mmc_rescan(struct work_struct *work) 2214 { 2215 struct mmc_host *host = 2216 container_of(work, struct mmc_host, detect.work); 2217 int i; 2218 2219 if (host->rescan_disable) 2220 return; 2221 2222 /* If there is a non-removable card registered, only scan once */ 2223 if (!mmc_card_is_removable(host) && host->rescan_entered) 2224 return; 2225 host->rescan_entered = 1; 2226 2227 if (host->trigger_card_event && host->ops->card_event) { 2228 mmc_claim_host(host); 2229 host->ops->card_event(host); 2230 mmc_release_host(host); 2231 host->trigger_card_event = false; 2232 } 2233 2234 /* Verify a registered card to be functional, else remove it. */ 2235 if (host->bus_ops) 2236 host->bus_ops->detect(host); 2237 2238 host->detect_change = 0; 2239 2240 /* if there still is a card present, stop here */ 2241 if (host->bus_ops != NULL) 2242 goto out; 2243 2244 mmc_claim_host(host); 2245 if (mmc_card_is_removable(host) && host->ops->get_cd && 2246 host->ops->get_cd(host) == 0) { 2247 mmc_power_off(host); 2248 mmc_release_host(host); 2249 goto out; 2250 } 2251 2252 /* If an SD express card is present, then leave it as is. */ 2253 if (mmc_card_sd_express(host)) { 2254 mmc_release_host(host); 2255 goto out; 2256 } 2257 2258 for (i = 0; i < ARRAY_SIZE(freqs); i++) { 2259 unsigned int freq = freqs[i]; 2260 if (freq > host->f_max) { 2261 if (i + 1 < ARRAY_SIZE(freqs)) 2262 continue; 2263 freq = host->f_max; 2264 } 2265 if (!mmc_rescan_try_freq(host, max(freq, host->f_min))) 2266 break; 2267 if (freqs[i] <= host->f_min) 2268 break; 2269 } 2270 2271 /* A non-removable card should have been detected by now. */ 2272 if (!mmc_card_is_removable(host) && !host->bus_ops) 2273 pr_info("%s: Failed to initialize a non-removable card", 2274 mmc_hostname(host)); 2275 2276 /* 2277 * Ignore the command timeout errors observed during 2278 * the card init as those are excepted. 2279 */ 2280 host->err_stats[MMC_ERR_CMD_TIMEOUT] = 0; 2281 mmc_release_host(host); 2282 2283 out: 2284 if (host->caps & MMC_CAP_NEEDS_POLL) 2285 mmc_schedule_delayed_work(&host->detect, HZ); 2286 }
最新发布
07-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值