手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

Linux设备模型之mmc,sd子系统<二>

[日期:2012-02-02] 来源:Linux社区  作者:gdt_A20 [字体:大 中 小]

####设置clock函数


static void s3cmci_set_clk(struct s3cmci_host *host, struct mmc_ios *ios)
{
    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;
}


######写保护函数:


static int s3cmci_get_ro(struct mmc_host *mmc)
{
    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;

}


######探测卡函数


static int s3cmci_card_present(struct mmc_host *mmc)
{
    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;       
}




#####下面说一下上文遗留几个函数,


/drivers/mmc/core/core.c
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),

#####同文件下的


void mmc_power_off(struct mmc_host *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);

}

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款