首先还是关心device的注册过程
首先在board-mx6q_sabresd.c里
static void __init mx6_sabresd_board_init(void)
{
/* Move sd4 to first because sd4 connect to emmc.
Mfgtools want emmc is mmcblk0 and other sd card is mmcblk1.
*/
imx6q_add_sdhci_usdhc_imx(3, &mx6q_sabresd_sd4_data);
imx6q_add_sdhci_usdhc_imx(1, &mx6q_sabresd_sd2_data);
imx6q_add_sdhci_usdhc_imx(2, &mx6q_sabresd_sd3_data);
}
然后看这个add函数
devices-imx6q.h
#define imx6q_add_sdhci_usdhc_imx(id, pdata) \
imx_add_sdhci_esdhc_imx(&imx6q_sdhci_usdhc_imx_data[id], pdata)
看看这个数组哪里来的
在Platform-sdhci-esdhc-imx.c里
#ifdef CONFIG_SOC_IMX6Q
const struct imx_sdhci_esdhc_imx_data
imx6q_sdhci_usdhc_imx_data[] __initconst = {
#define imx6q_sdhci_usdhc_imx_data_entry(_id, _hwid) \
imx_sdhci_usdhc_imx_data_entry(MX6Q, _id, _hwid)
imx6q_sdhci_usdhc_imx_data_entry(0, 1),
imx6q_sdhci_usdhc_imx_data_entry(1, 2),
imx6q_sdhci_usdhc_imx_data_entry(2, 3),
imx6q_sdhci_usdhc_imx_data_entry(3, 4),
};
#endif /* ifdef CONFIG_SOC_IMX6Q */
Platform-sdhci-esdhc-imx.c
#define imx_sdhci_usdhc_imx_data_entry(soc, id, hwid) \
[id] = imx_sdhci_usdhc_imx_data_entry_single(soc, id, hwid)
#define imx_sdhci_usdhc_imx_data_entry_single(soc, _id, hwid) \
{ \
.id = _id, \
.iobase = soc ## _USDHC ## hwid ## _BASE_ADDR, \
.irq = soc ## _INT_USDHC ## hwid, \
}
然后看add过程
platform-sdhci-esdhc-imx.c
struct platform_device *__init imx_add_sdhci_esdhc_imx(
const struct imx_sdhci_esdhc_imx_data *data,
const struct esdhc_platform_data *pdata)
{
struct resource res[] = {
{
.start = data->iobase,
.end = data->iobase + SZ_16K - 1,
.flags = IORESOURCE_MEM,
}, {
.start = data->irq,
.end = data->irq,
.flags = IORESOURCE_IRQ,
},
};
return imx_add_platform_device_dmamask("sdhci-esdhc-imx", data->id, res,
ARRAY_SIZE(res), pdata, sizeof(*pdata), DMA_BIT_MASK(32));
}感觉很熟悉,和uart的device注册其实差不多