1 /*
2  * Copyright (C) 2009-2010 Pengutronix
3  * Uwe Kleine-Koenig <u.kleine-koenig@pengutronix.de>
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 2 as published by the
7  * Free Software Foundation.
8  */
9 #include "../hardware.h"
10 #include "devices-common.h"
11 
12 #define imx_spi_imx_data_entry_single(soc, type, _devid, _id, hwid, _size) \
13 	{								\
14 		.devid = _devid,					\
15 		.id = _id,						\
16 		.iobase = soc ## _ ## type ## hwid ## _BASE_ADDR,	\
17 		.iosize = _size,					\
18 		.irq = soc ## _INT_ ## type ## hwid,			\
19 	}
20 
21 #define imx_spi_imx_data_entry(soc, type, devid, id, hwid, size)	\
22 	[id] = imx_spi_imx_data_entry_single(soc, type, devid, id, hwid, size)
23 
24 #ifdef CONFIG_SOC_IMX21
25 const struct imx_spi_imx_data imx21_cspi_data[] __initconst = {
26 #define imx21_cspi_data_entry(_id, _hwid)                            \
27 	imx_spi_imx_data_entry(MX21, CSPI, "imx21-cspi", _id, _hwid, SZ_4K)
28 	imx21_cspi_data_entry(0, 1),
29 	imx21_cspi_data_entry(1, 2),
30 };
31 #endif
32 
33 #ifdef CONFIG_SOC_IMX27
34 const struct imx_spi_imx_data imx27_cspi_data[] __initconst = {
35 #define imx27_cspi_data_entry(_id, _hwid)				\
36 	imx_spi_imx_data_entry(MX27, CSPI, "imx27-cspi", _id, _hwid, SZ_4K)
37 	imx27_cspi_data_entry(0, 1),
38 	imx27_cspi_data_entry(1, 2),
39 	imx27_cspi_data_entry(2, 3),
40 };
41 #endif /* ifdef CONFIG_SOC_IMX27 */
42 
43 #ifdef CONFIG_SOC_IMX31
44 const struct imx_spi_imx_data imx31_cspi_data[] __initconst = {
45 #define imx31_cspi_data_entry(_id, _hwid)				\
46 	imx_spi_imx_data_entry(MX31, CSPI, "imx31-cspi", _id, _hwid, SZ_4K)
47 	imx31_cspi_data_entry(0, 1),
48 	imx31_cspi_data_entry(1, 2),
49 	imx31_cspi_data_entry(2, 3),
50 };
51 #endif /* ifdef CONFIG_SOC_IMX31 */
52 
53 #ifdef CONFIG_SOC_IMX35
54 const struct imx_spi_imx_data imx35_cspi_data[] __initconst = {
55 #define imx35_cspi_data_entry(_id, _hwid)                           \
56 	imx_spi_imx_data_entry(MX35, CSPI, "imx35-cspi", _id, _hwid, SZ_4K)
57 	imx35_cspi_data_entry(0, 1),
58 	imx35_cspi_data_entry(1, 2),
59 };
60 #endif /* ifdef CONFIG_SOC_IMX35 */
61 
imx_add_spi_imx(const struct imx_spi_imx_data * data,const struct spi_imx_master * pdata)62 struct platform_device *__init imx_add_spi_imx(
63 		const struct imx_spi_imx_data *data,
64 		const struct spi_imx_master *pdata)
65 {
66 	struct resource res[] = {
67 		{
68 			.start = data->iobase,
69 			.end = data->iobase + data->iosize - 1,
70 			.flags = IORESOURCE_MEM,
71 		}, {
72 			.start = data->irq,
73 			.end = data->irq,
74 			.flags = IORESOURCE_IRQ,
75 		},
76 	};
77 
78 	return imx_add_platform_device(data->devid, data->id,
79 			res, ARRAY_SIZE(res), pdata, sizeof(*pdata));
80 }
81