Linux 2.6.38
sdio总线上driver和设备的match成功只是软件之间的”切口“,好比《还钱》:
刘金山:明月几时有?
冯巩:抬头自己瞅。
但是冯巩并没有马上把钱请给他吧?这里硬件的连通性、能不能工作还不知道,所以要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 out;
}
/* 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);
out:
return ret;
}
3、4行不用说了。
第8~10行,之前的match操作也调用的sdio_match_device,不过当时仅仅关心是不是匹配,其他一概不管。这里需要用到它的sdio_device_id返回值。
第12~22行,sdio host的caps成员记录其特性(capability),MMC_CAP_POWER_OFF_CARD是电源管理(Power Manager)方面的选项,设置了这个标志的host在suspend的时候将把card的电关掉。很显然,在probe的过程中不允许这种情况发生,解决方式就是禁止MMC子系统进入suspend模式。pm_runtime_get_sync()调用后将增加sdio device的引用计数,系统suspend过程中检测这个引用计数,发现其不为零就会退出suspend流程。相应的,pm_runtime_put_noidle()降低引用计数,也即它们必须成对使用。
第26~28行,设置block siz