####设置clock函数
{
u32 mci_psc;
/* Set clock */
for (mci_psc = 0; mci_psc < 255; mci_psc++) {
host->real_rate = host->clk_rate / (host->clk_div*(mci_psc+1));
if (host->real_rate <= ios->clock)
break;
}
if (mci_psc > 255)
mci_psc = 255;
host->prescaler = mci_psc;
writel(host->prescaler, host->base + S3C2410_SDIPRE);
/* If requested clock is 0, real_rate will be 0, too */
if (ios->clock == 0)
host->real_rate = 0;
}
######写保护函数:
{
struct s3cmci_host *host = mmc_priv(mmc);
struct s3c24xx_mci_pdata *pdata = host->pdata;
int ret;
if (pdata->no_wprotect)
return 0;
ret = gpio_get_value(pdata->gpio_wprotect) ? 1 : 0;
ret ^= pdata->wprotect_invert;
return ret;
}
######探测卡函数
{
struct s3cmci_host *host = mmc_priv(mmc);
struct s3c24xx_mci_pdata *pdata = host->pdata;
int ret;
if (pdata->no_detect) //没有探测函数
return -ENOSYS;
ret = gpio_get_value(pdata->gpio_detect) ? 0 : 1; //直接读取gpio值
return ret ^ pdata->detect_invert;
}
#####下面说一下上文遗留几个函数,
void mmc_start_host(struct mmc_host *host)
{
mmc_power_off(host); //host power off
mmc_detect_change(host, 0); //detect
}
#####首先是mmc_power_off(host),
#####同文件下的
{
mmc_host_clk_hold(host); //clk可能恢复到先前的一个值,
host->ios.clock = 0; //强制设置成0?
host->ios.vdd = 0;
mmc_poweroff_notify(host);
/*
* Reset ocr mask to be the highest possible voltage supported for
* this mmc host. This value will be used at next power up.
*/
host->ocr = 1 << (fls(host->ocr_avail) - 1); //支持的最大电压
if (!mmc_host_is_spi(host)) { //不是spi
host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN; //漏极开路式
host->ios.chip_select = MMC_CS_DONTCARE; //不关心cs
}
host->ios.power_mode = MMC_POWER_OFF; //状态power_off
host->ios.bus_width = MMC_BUS_WIDTH_1;
host->ios.timing = MMC_TIMING_LEGACY;
mmc_set_ios(host); //关闭电压,真正设置成0
/*
* Some configurations, such as the 802.11 SDIO card in the OLPC
* XO-1.5, require a short delay after poweroff before the card
* can be successfully turned on again.
*/
mmc_delay(1); //短暂延迟
mmc_host_clk_release(host); //disable
}
######同文件夹下
* mmc_host_clk_hold - ungate hardware MCI clocks
* @host: host to ungate.
* //gate用于限制保证有最低clk???
* Makes sure the host ios.clock is restored to a non-zero value
* past this call. Increase clock reference count and ungate clock
* if we're the first user.
*/
void mmc_host_clk_hold(struct mmc_host *host)
{
unsigned long flags;
mutex_lock(&host->clk_gate_mutex);
spin_lock_irqsave(&host->clk_lock, flags);
if (host->clk_gated) {
spin_unlock_irqrestore(&host->clk_lock, flags);
mmc_ungate_clock(host);
spin_lock_irqsave(&host->clk_lock, flags);
pr_debug("%s: ungated MCI clock\n", mmc_hostname(host));
}
host->clk_requests++;
spin_unlock_irqrestore(&host->clk_lock, flags);
mutex_unlock(&host->clk_gate_mutex);
}
