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