1124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König/*
2124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König * Copyright (C) 2010 Pengutronix, Wolfram Sang <w.sang@pengutronix.de>
3124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König *
4124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König * This program is free software; you can redistribute it and/or modify it under
5124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König * the terms of the GNU General Public License version 2 as published by the
6124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König * Free Software Foundation.
7124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König */
8124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König
9124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König#include <mach/hardware.h>
10124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König#include <mach/devices-common.h>
11124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König#include <mach/esdhc.h>
12124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König
1357ed3314e0bfa90ea63c63b8d3038814e9d98a20Shawn Guo#define imx_sdhci_esdhc_imx_data_entry_single(soc, _devid, _id, hwid) \
14124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König	{								\
1557ed3314e0bfa90ea63c63b8d3038814e9d98a20Shawn Guo		.devid = _devid,					\
16124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König		.id = _id,						\
17124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König		.iobase = soc ## _ESDHC ## hwid ## _BASE_ADDR,	\
18124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König		.irq = soc ## _INT_ESDHC ## hwid,			\
19124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König	}
20124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König
2157ed3314e0bfa90ea63c63b8d3038814e9d98a20Shawn Guo#define imx_sdhci_esdhc_imx_data_entry(soc, devid, id, hwid)	\
2257ed3314e0bfa90ea63c63b8d3038814e9d98a20Shawn Guo	[id] = imx_sdhci_esdhc_imx_data_entry_single(soc, devid, id, hwid)
23124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König
24124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König#ifdef CONFIG_SOC_IMX25
25124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-Königconst struct imx_sdhci_esdhc_imx_data
26124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-Königimx25_sdhci_esdhc_imx_data[] __initconst = {
27124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König#define imx25_sdhci_esdhc_imx_data_entry(_id, _hwid)			\
2857ed3314e0bfa90ea63c63b8d3038814e9d98a20Shawn Guo	imx_sdhci_esdhc_imx_data_entry(MX25, "sdhci-esdhc-imx25", _id, _hwid)
29124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König	imx25_sdhci_esdhc_imx_data_entry(0, 1),
30124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König	imx25_sdhci_esdhc_imx_data_entry(1, 2),
31124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König};
32124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König#endif /* ifdef CONFIG_SOC_IMX25 */
33124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König
34124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König#ifdef CONFIG_SOC_IMX35
35124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-Königconst struct imx_sdhci_esdhc_imx_data
36124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-Königimx35_sdhci_esdhc_imx_data[] __initconst = {
37124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König#define imx35_sdhci_esdhc_imx_data_entry(_id, _hwid)			\
3857ed3314e0bfa90ea63c63b8d3038814e9d98a20Shawn Guo	imx_sdhci_esdhc_imx_data_entry(MX35, "sdhci-esdhc-imx35", _id, _hwid)
39124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König	imx35_sdhci_esdhc_imx_data_entry(0, 1),
40124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König	imx35_sdhci_esdhc_imx_data_entry(1, 2),
41124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König	imx35_sdhci_esdhc_imx_data_entry(2, 3),
42124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König};
43124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König#endif /* ifdef CONFIG_SOC_IMX35 */
44124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König
45d94ed1287e11f91e4f4096838179984b0206be5eFabio Estevam#ifdef CONFIG_SOC_IMX51
46124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-Königconst struct imx_sdhci_esdhc_imx_data
47124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-Königimx51_sdhci_esdhc_imx_data[] __initconst = {
48124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König#define imx51_sdhci_esdhc_imx_data_entry(_id, _hwid)			\
4957ed3314e0bfa90ea63c63b8d3038814e9d98a20Shawn Guo	imx_sdhci_esdhc_imx_data_entry(MX51, "sdhci-esdhc-imx51", _id, _hwid)
50124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König	imx51_sdhci_esdhc_imx_data_entry(0, 1),
51124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König	imx51_sdhci_esdhc_imx_data_entry(1, 2),
52124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König	imx51_sdhci_esdhc_imx_data_entry(2, 3),
53124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König	imx51_sdhci_esdhc_imx_data_entry(3, 4),
54124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König};
55d94ed1287e11f91e4f4096838179984b0206be5eFabio Estevam#endif /* ifdef CONFIG_SOC_IMX51 */
56124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König
57410d3458e56bfe85ea4ac6358d5ae16d2f9acda6Yong Shen#ifdef CONFIG_SOC_IMX53
58410d3458e56bfe85ea4ac6358d5ae16d2f9acda6Yong Shenconst struct imx_sdhci_esdhc_imx_data
59410d3458e56bfe85ea4ac6358d5ae16d2f9acda6Yong Shenimx53_sdhci_esdhc_imx_data[] __initconst = {
60410d3458e56bfe85ea4ac6358d5ae16d2f9acda6Yong Shen#define imx53_sdhci_esdhc_imx_data_entry(_id, _hwid)			\
6157ed3314e0bfa90ea63c63b8d3038814e9d98a20Shawn Guo	imx_sdhci_esdhc_imx_data_entry(MX53, "sdhci-esdhc-imx53", _id, _hwid)
62410d3458e56bfe85ea4ac6358d5ae16d2f9acda6Yong Shen	imx53_sdhci_esdhc_imx_data_entry(0, 1),
63410d3458e56bfe85ea4ac6358d5ae16d2f9acda6Yong Shen	imx53_sdhci_esdhc_imx_data_entry(1, 2),
64410d3458e56bfe85ea4ac6358d5ae16d2f9acda6Yong Shen	imx53_sdhci_esdhc_imx_data_entry(2, 3),
65410d3458e56bfe85ea4ac6358d5ae16d2f9acda6Yong Shen	imx53_sdhci_esdhc_imx_data_entry(3, 4),
66410d3458e56bfe85ea4ac6358d5ae16d2f9acda6Yong Shen};
67410d3458e56bfe85ea4ac6358d5ae16d2f9acda6Yong Shen#endif /* ifdef CONFIG_SOC_IMX53 */
68410d3458e56bfe85ea4ac6358d5ae16d2f9acda6Yong Shen
69913413c307c919f8b21edccea23a9fd9d9d49a64Shawn Guostatic const struct esdhc_platform_data default_esdhc_pdata __initconst = {
70913413c307c919f8b21edccea23a9fd9d9d49a64Shawn Guo	.wp_type = ESDHC_WP_NONE,
71913413c307c919f8b21edccea23a9fd9d9d49a64Shawn Guo	.cd_type = ESDHC_CD_NONE,
72913413c307c919f8b21edccea23a9fd9d9d49a64Shawn Guo};
73913413c307c919f8b21edccea23a9fd9d9d49a64Shawn Guo
74124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-Königstruct platform_device *__init imx_add_sdhci_esdhc_imx(
75124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König		const struct imx_sdhci_esdhc_imx_data *data,
76124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König		const struct esdhc_platform_data *pdata)
77124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König{
78124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König	struct resource res[] = {
79124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König		{
80124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König			.start = data->iobase,
81124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König			.end = data->iobase + SZ_16K - 1,
82124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König			.flags = IORESOURCE_MEM,
83124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König		}, {
84124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König			.start = data->irq,
85124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König			.end = data->irq,
86124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König			.flags = IORESOURCE_IRQ,
87124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König		},
88124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König	};
89124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König
90913413c307c919f8b21edccea23a9fd9d9d49a64Shawn Guo	/*
91913413c307c919f8b21edccea23a9fd9d9d49a64Shawn Guo	 * If machine does not provide pdata, use the default one
92913413c307c919f8b21edccea23a9fd9d9d49a64Shawn Guo	 * which means no WP/CD support
93913413c307c919f8b21edccea23a9fd9d9d49a64Shawn Guo	 */
94913413c307c919f8b21edccea23a9fd9d9d49a64Shawn Guo	if (!pdata)
95913413c307c919f8b21edccea23a9fd9d9d49a64Shawn Guo		pdata = &default_esdhc_pdata;
96913413c307c919f8b21edccea23a9fd9d9d49a64Shawn Guo
9757ed3314e0bfa90ea63c63b8d3038814e9d98a20Shawn Guo	return imx_add_platform_device(data->devid, data->id, res,
98124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König			ARRAY_SIZE(res), pdata, sizeof(*pdata));
99124bf94a9f9b52341562628cd56b252e7d820ee8Uwe Kleine-König}
100