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_imx_i2c_data_entry_single(soc, _devid, _id, _hwid, _size)	\
13 	{								\
14 		.devid = _devid,					\
15 		.id = _id,						\
16 		.iobase = soc ## _I2C ## _hwid ## _BASE_ADDR,		\
17 		.iosize = _size,					\
18 		.irq = soc ## _INT_I2C ## _hwid,			\
19 	}
20 
21 #define imx_imx_i2c_data_entry(soc, _devid, _id, _hwid, _size)		\
22 	[_id] = imx_imx_i2c_data_entry_single(soc, _devid, _id, _hwid, _size)
23 
24 #ifdef CONFIG_SOC_IMX21
25 const struct imx_imx_i2c_data imx21_imx_i2c_data __initconst =
26 	imx_imx_i2c_data_entry_single(MX21, "imx21-i2c", 0, , SZ_4K);
27 #endif /* ifdef CONFIG_SOC_IMX21 */
28 
29 #ifdef CONFIG_SOC_IMX27
30 const struct imx_imx_i2c_data imx27_imx_i2c_data[] __initconst = {
31 #define imx27_imx_i2c_data_entry(_id, _hwid)				\
32 	imx_imx_i2c_data_entry(MX27, "imx21-i2c", _id, _hwid, SZ_4K)
33 	imx27_imx_i2c_data_entry(0, 1),
34 	imx27_imx_i2c_data_entry(1, 2),
35 };
36 #endif /* ifdef CONFIG_SOC_IMX27 */
37 
38 #ifdef CONFIG_SOC_IMX31
39 const struct imx_imx_i2c_data imx31_imx_i2c_data[] __initconst = {
40 #define imx31_imx_i2c_data_entry(_id, _hwid)				\
41 	imx_imx_i2c_data_entry(MX31, "imx21-i2c", _id, _hwid, SZ_4K)
42 	imx31_imx_i2c_data_entry(0, 1),
43 	imx31_imx_i2c_data_entry(1, 2),
44 	imx31_imx_i2c_data_entry(2, 3),
45 };
46 #endif /* ifdef CONFIG_SOC_IMX31 */
47 
48 #ifdef CONFIG_SOC_IMX35
49 const struct imx_imx_i2c_data imx35_imx_i2c_data[] __initconst = {
50 #define imx35_imx_i2c_data_entry(_id, _hwid)				\
51 	imx_imx_i2c_data_entry(MX35, "imx21-i2c", _id, _hwid, SZ_4K)
52 	imx35_imx_i2c_data_entry(0, 1),
53 	imx35_imx_i2c_data_entry(1, 2),
54 	imx35_imx_i2c_data_entry(2, 3),
55 };
56 #endif /* ifdef CONFIG_SOC_IMX35 */
57 
imx_add_imx_i2c(const struct imx_imx_i2c_data * data,const struct imxi2c_platform_data * pdata)58 struct platform_device *__init imx_add_imx_i2c(
59 		const struct imx_imx_i2c_data *data,
60 		const struct imxi2c_platform_data *pdata)
61 {
62 	struct resource res[] = {
63 		{
64 			.start = data->iobase,
65 			.end = data->iobase + data->iosize - 1,
66 			.flags = IORESOURCE_MEM,
67 		}, {
68 			.start = data->irq,
69 			.end = data->irq,
70 			.flags = IORESOURCE_IRQ,
71 		},
72 	};
73 
74 	return imx_add_platform_device(data->devid, data->id,
75 			res, ARRAY_SIZE(res),
76 			pdata, sizeof(*pdata));
77 }
78