基于QualComm的mmc driver解析(Kernel-3.10)——(2)sdio总线

sdio总线的注册函数也是在core.c 文件中调用注册的:

ret = sdio_register_bus();
    if (ret)
        goto unregister_host_class;

sdio_register_bus 在sdio_bus.c 文件中定义:

int sdio_register_bus(void)
{
    return bus_register(&sdio_bus_type);
}

sdio_register_bus 通过bus_register 函数注册了sdio总线, sdio总线的结构体定义如下:

static struct bus_type sdio_bus_type = {
    .name       = "sdio",
    .dev_attrs  = sdio_dev_attrs,
    .match      = sdio_bus_match,
    .uevent     = sdio_bus_uevent,
    .probe      = sdio_bus_probe,
    .remove     = sdio_bus_remove,
    .pm     = SDIO_PM_OPS_PTR,
};

总线名字为sdio,sdio_dev_attrs 在bus目录下创建属性节点。

sdio_bus_match 函数定义:

static int sdio_bus_match(struct device *dev, struct device_driver *drv)
{
    struct sdio_func *func = dev_to_sdio_func(dev);
    struct sdio_driver *sdrv = to_sdio_driver(drv);

    if (sdio_match_device(func, sdrv))
        return 1;

    return 0;
}

调用 sdio_match_device :

static const struct sdio_device_id *sdio_match_device(struct sdio_func *func,
    struct sdio_driver *sdrv)
{
    const struct sdio_device_id *ids;

    ids = sdrv->id_table;

    if (ids) {
        while (ids->class || ids->vendor || ids->device) {
            if (sdio_match_one(func, ids))
                return ids;
            ids++;
        }
    }

    return NULL;
}

以上两个函数是driver 匹配device使用的函数。

sdio_bus_probe 函数:

static int sdio_bus_probe(struct device *dev)
{
    struct sdio_driver *drv = to_sdio_driver(dev->driver);
    struct sdio_func *func = dev_to_sdio_func(dev);
    const struct sdio_device_id *id;
    int ret;

    id = sdio_match_device(func, drv);
    if (!id)
        return -ENODEV;

    /* Unbound SDIO functions are always suspended.
     * During probe, the function is set active and the usage count
     * is incremented.  If the driver supports runtime PM,
     * it should call pm_runtime_put_noidle() in its probe routine and
     * pm_runtime_get_noresume() in its remove routine.
     */
    if (func->card->host->caps & MMC_CAP_POWER_OFF_CARD) {
        ret = pm_runtime_get_sync(dev);
        if (ret < 0)
            goto disable_runtimepm;
    }

    /* Set the default block size so the driver is sure it's something
     * sensible. */
    sdio_claim_host(func);
    ret = sdio_set_block_size(func, 0);
    sdio_release_host(func);
    if (ret)
        goto disable_runtimepm;

    ret = drv->probe(func, id);
    if (ret)
        goto disable_runtimepm;

    return 0;

disable_runtimepm:
    if (func->card->host->caps & MMC_CAP_POWER_OFF_CARD)
        pm_runtime_put_noidle(dev);
    return ret;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值