1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright (C) 2010 Pengutronix, Wolfram Sang <kernel@pengutronix.de>
4  */
5 
6 #include <linux/platform_data/mmc-esdhc-imx.h>
7 
8 #include "../hardware.h"
9 #include "devices-common.h"
10 
11 #define imx_sdhci_esdhc_imx_data_entry_single(soc, _devid, _id, hwid) \
12 	{								\
13 		.devid = _devid,					\
14 		.id = _id,						\
15 		.iobase = soc ## _ESDHC ## hwid ## _BASE_ADDR,	\
16 		.irq = soc ## _INT_ESDHC ## hwid,			\
17 	}
18 
19 #define imx_sdhci_esdhc_imx_data_entry(soc, devid, id, hwid)	\
20 	[id] = imx_sdhci_esdhc_imx_data_entry_single(soc, devid, id, hwid)
21 
22 #ifdef CONFIG_SOC_IMX35
23 const struct imx_sdhci_esdhc_imx_data
24 imx35_sdhci_esdhc_imx_data[] __initconst = {
25 #define imx35_sdhci_esdhc_imx_data_entry(_id, _hwid)			\
26 	imx_sdhci_esdhc_imx_data_entry(MX35, "sdhci-esdhc-imx35", _id, _hwid)
27 	imx35_sdhci_esdhc_imx_data_entry(0, 1),
28 	imx35_sdhci_esdhc_imx_data_entry(1, 2),
29 	imx35_sdhci_esdhc_imx_data_entry(2, 3),
30 };
31 #endif /* ifdef CONFIG_SOC_IMX35 */
32 
33 static const struct esdhc_platform_data default_esdhc_pdata __initconst = {
34 	.wp_type = ESDHC_WP_NONE,
35 	.cd_type = ESDHC_CD_NONE,
36 };
37 
imx_add_sdhci_esdhc_imx(const struct imx_sdhci_esdhc_imx_data * data,const struct esdhc_platform_data * pdata)38 struct platform_device *__init imx_add_sdhci_esdhc_imx(
39 		const struct imx_sdhci_esdhc_imx_data *data,
40 		const struct esdhc_platform_data *pdata)
41 {
42 	struct resource res[] = {
43 		{
44 			.start = data->iobase,
45 			.end = data->iobase + SZ_16K - 1,
46 			.flags = IORESOURCE_MEM,
47 		}, {
48 			.start = data->irq,
49 			.end = data->irq,
50 			.flags = IORESOURCE_IRQ,
51 		},
52 	};
53 
54 	/*
55 	 * If machine does not provide pdata, use the default one
56 	 * which means no WP/CD support
57 	 */
58 	if (!pdata)
59 		pdata = &default_esdhc_pdata;
60 
61 	return imx_add_platform_device_dmamask(data->devid, data->id, res,
62 			ARRAY_SIZE(res), pdata, sizeof(*pdata),
63 			DMA_BIT_MASK(32));
64 }
65