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

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

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

########位于drivers/mmc/core/core.c


/*
 * This restores the clock from gating by using the cached
 * clock value.
 */
void mmc_ungate_clock(struct mmc_host *host)
{
    /*
     * We should previously have gated the clock, so the clock shall
     * be 0 here! The clock may however be 0 during initialization,
     * when some request operations are performed before setting
     * the frequency. When ungate is requested in that situation
     * we just ignore the call.
     */
    if (host->clk_old) {
        BUG_ON(host->ios.clock);
        /* This call will also set host->clk_gated to false */
        __mmc_set_clock(host, host->clk_old);
    }

}


#####看样子gate缓存了clk值,可以恢复到上一个clk值.

#####跟进去


/*
 * Sets the host clock to the highest possible frequency that
 * is below "hz".
 */
static void __mmc_set_clock(struct mmc_host *host, unsigned int hz)
{
    WARN_ON(hz < host->f_min);

    if (hz > host->f_max)
        hz = host->f_max;

    host->ios.clock = hz;
    mmc_set_ios(host);
}

######把clock设置成传进的值


/*
 * Internal function that does the actual ios call to the host driver,
 * optionally printing some debug output.
 */
static inline void mmc_set_ios(struct mmc_host *host)
{
    struct mmc_ios *ios = &host->ios;

    pr_debug("%s: clock %uHz busmode %u powermode %u cs %u Vdd %u "
        "width %u timing %u\n",
         mmc_hostname(host), ios->clock, ios->bus_mode,
         ios->power_mode, ios->chip_select, ios->vdd,
         ios->bus_width, ios->timing);

    if (ios->clock > 0)                       //此时的clock如果不是0,那么clk_gate = false,
        mmc_set_ungated(host);         //只有0时才能再gate?
    host->ops->set_ios(host, ios);    //调用平台相关函数真正设置io
}


#####另外一个函数mmc_detect_change(host, 0);

#####在core.c中,


/**
 *    mmc_detect_change - process change of state on a MMC socket
 *    @host: host which changed state.
 *    @delay: optional delay to wait before detection (jiffies)
 *
 *    MMC drivers should call this when they detect a card has been
 *    inserted or removed. The MMC layer will confirm that any
 *    present card is still functional, and initialize any newly
 *    inserted.
 */
void mmc_detect_change(struct mmc_host *host, unsigned long delay)
{
#ifdef CONFIG_MMC_DEBUG
    unsigned long flags;
    spin_lock_irqsave(&host->lock, flags);
    WARN_ON(host->removed);
    spin_unlock_irqrestore(&host->lock, flags);
#endif

    mmc_schedule_delayed_work(&host->detect, delay);
}


#####这个地方对应于上面alloc_host时候的mmc_rescan,
#####注册完毕执行一次探测,确认默认是否sd卡被插入,
#####而插入卡后中断触发也会执行到这里,下面直接看插卡后isr函数函数了,

#####在s3cmci.c中,


/*
 * ISR for the CardDetect Pin
*/

static irqreturn_t s3cmci_irq_cd(int irq, void *dev_id)
{
    struct s3cmci_host *host = (struct s3cmci_host *)dev_id;

    dbg(host, dbg_irq, "card detect\n");

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

    return IRQ_HANDLED;

}


#####都走到mmc_detect_change,只不过多了个延迟,

#####继续追下去,core.c中,


/**
 *    mmc_detect_change - process change of state on a MMC socket
 *    @host: host which changed state.
 *    @delay: optional delay to wait before detection (jiffies)
 *
 *    MMC drivers should call this when they detect a card has been
 *    inserted or removed. The MMC layer will confirm that any
 *    present card is still functional, and initialize any newly
 *    inserted.
 */
void mmc_detect_change(struct mmc_host *host, unsigned long delay)
{
#ifdef CONFIG_MMC_DEBUG
    unsigned long flags;
    spin_lock_irqsave(&host->lock, flags);
    WARN_ON(host->removed);
    spin_unlock_irqrestore(&host->lock, flags);
#endif

    mmc_schedule_delayed_work(&host->detect, delay);
}


#####会调用mmc_schedule_delayed_work(&host->detect, delay);
#####host->detect这个延迟队列的初始化位于/drivers/mmc/core/host.c中,
#####INIT_DELAYED_WORK(&host->detect, mmc_rescan);
#####探测函数都会调用mmc_rescan这个系统提供的扫描sd卡函数,
#####核心扫描函数,下面就是重点的扫描卡函数了,放到下篇单独来说;


总结,概览了平台最相关的几个函数,接下来的都通用函数了,写的比较粗糙,还望见谅^.^!


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

       

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