ARM: mx51: dynamically register imx-uart devices
[pandora-kernel.git] / arch / arm / mach-mx5 / eukrea_mbimx51-baseboard.c
1 /*
2  *
3  * Copyright (C) 2010 Eric BĂ©nard <eric@eukrea.com>
4  *
5  * The code contained herein is licensed under the GNU General Public
6  * License. You may obtain a copy of the GNU General Public License
7  * Version 2 or later at the following locations:
8  *
9  * http://www.opensource.org/licenses/gpl-license.html
10  * http://www.gnu.org/copyleft/gpl.html
11  */
12
13 #include <linux/init.h>
14 #include <linux/platform_device.h>
15 #include <linux/serial_8250.h>
16 #include <linux/i2c.h>
17 #include <linux/gpio.h>
18 #include <linux/io.h>
19 #include <linux/interrupt.h>
20 #include <linux/irq.h>
21 #include <linux/fsl_devices.h>
22 #include <linux/i2c/tsc2007.h>
23 #include <linux/leds.h>
24 #include <linux/input/matrix_keypad.h>
25
26 #include <mach/common.h>
27 #include <mach/hardware.h>
28 #include <mach/imx-uart.h>
29 #include <mach/iomux-mx51.h>
30
31 #include <asm/mach/arch.h>
32
33 #include "devices-imx51.h"
34 #include "devices.h"
35
36 #define MBIMX51_TSC2007_GPIO    (2*32 + 30)
37 #define MBIMX51_TSC2007_IRQ     (MXC_INTERNAL_IRQS + MBIMX51_TSC2007_GPIO)
38 #define MBIMX51_LED0            (2*32 + 5)
39 #define MBIMX51_LED1            (2*32 + 6)
40 #define MBIMX51_LED2            (2*32 + 7)
41 #define MBIMX51_LED3            (2*32 + 8)
42
43 static struct gpio_led mbimx51_leds[] = {
44         {
45                 .name                   = "led0",
46                 .default_trigger        = "heartbeat",
47                 .active_low             = 1,
48                 .gpio                   = MBIMX51_LED0,
49         },
50         {
51                 .name                   = "led1",
52                 .default_trigger        = "nand-disk",
53                 .active_low             = 1,
54                 .gpio                   = MBIMX51_LED1,
55         },
56         {
57                 .name                   = "led2",
58                 .default_trigger        = "mmc0",
59                 .active_low             = 1,
60                 .gpio                   = MBIMX51_LED2,
61         },
62         {
63                 .name                   = "led3",
64                 .default_trigger        = "default-on",
65                 .active_low             = 1,
66                 .gpio                   = MBIMX51_LED3,
67         },
68 };
69
70 static struct gpio_led_platform_data mbimx51_leds_info = {
71         .leds           = mbimx51_leds,
72         .num_leds       = ARRAY_SIZE(mbimx51_leds),
73 };
74
75 static struct platform_device mbimx51_leds_gpio = {
76         .name   = "leds-gpio",
77         .id     = -1,
78         .dev    = {
79                 .platform_data  = &mbimx51_leds_info,
80         },
81 };
82
83 static struct platform_device *devices[] __initdata = {
84         &mbimx51_leds_gpio,
85 };
86
87 static struct pad_desc mbimx51_pads[] = {
88         /* UART2 */
89         MX51_PAD_UART2_RXD__UART2_RXD,
90         MX51_PAD_UART2_TXD__UART2_TXD,
91
92         /* UART3 */
93         MX51_PAD_UART3_RXD__UART3_RXD,
94         MX51_PAD_UART3_TXD__UART3_TXD,
95         MX51_PAD_KEY_COL4__UART3_RTS,
96         MX51_PAD_KEY_COL5__UART3_CTS,
97
98         /* TSC2007 IRQ */
99         MX51_PAD_NANDF_D10__GPIO_3_30,
100
101         /* LEDS */
102         MX51_PAD_DISPB2_SER_DIN__GPIO_3_5,
103         MX51_PAD_DISPB2_SER_DIO__GPIO_3_6,
104         MX51_PAD_DISPB2_SER_CLK__GPIO_3_7,
105         MX51_PAD_DISPB2_SER_RS__GPIO_3_8,
106
107         /* KPP */
108         MX51_PAD_KEY_ROW0__KEY_ROW0,
109         MX51_PAD_KEY_ROW1__KEY_ROW1,
110         MX51_PAD_KEY_ROW2__KEY_ROW2,
111         MX51_PAD_KEY_ROW3__KEY_ROW3,
112         MX51_PAD_KEY_COL0__KEY_COL0,
113         MX51_PAD_KEY_COL1__KEY_COL1,
114         MX51_PAD_KEY_COL2__KEY_COL2,
115         MX51_PAD_KEY_COL3__KEY_COL3,
116 };
117
118 static const struct imxuart_platform_data uart_pdata __initconst = {
119         .flags = IMXUART_HAVE_RTSCTS,
120 };
121
122 static int mbimx51_keymap[] = {
123         KEY(0, 0, KEY_1),
124         KEY(0, 1, KEY_2),
125         KEY(0, 2, KEY_3),
126         KEY(0, 3, KEY_UP),
127
128         KEY(1, 0, KEY_4),
129         KEY(1, 1, KEY_5),
130         KEY(1, 2, KEY_6),
131         KEY(1, 3, KEY_LEFT),
132
133         KEY(2, 0, KEY_7),
134         KEY(2, 1, KEY_8),
135         KEY(2, 2, KEY_9),
136         KEY(2, 3, KEY_RIGHT),
137
138         KEY(3, 0, KEY_0),
139         KEY(3, 1, KEY_DOWN),
140         KEY(3, 2, KEY_ESC),
141         KEY(3, 3, KEY_ENTER),
142 };
143
144 static struct matrix_keymap_data mbimx51_map_data = {
145         .keymap         = mbimx51_keymap,
146         .keymap_size    = ARRAY_SIZE(mbimx51_keymap),
147 };
148
149 static int tsc2007_get_pendown_state(void)
150 {
151         return !gpio_get_value(MBIMX51_TSC2007_GPIO);
152 }
153
154 struct tsc2007_platform_data tsc2007_data = {
155         .model = 2007,
156         .x_plate_ohms = 180,
157         .get_pendown_state = tsc2007_get_pendown_state,
158 };
159
160 static struct i2c_board_info mbimx51_i2c_devices[] = {
161         {
162                 I2C_BOARD_INFO("tsc2007", 0x48),
163                 .irq  = MBIMX51_TSC2007_IRQ,
164                 .platform_data = &tsc2007_data,
165         },
166 };
167
168 /*
169  * baseboard initialization.
170  */
171 void __init eukrea_mbimx51_baseboard_init(void)
172 {
173         mxc_iomux_v3_setup_multiple_pads(mbimx51_pads,
174                                         ARRAY_SIZE(mbimx51_pads));
175
176         imx51_add_imx_uart(1, NULL);
177         imx51_add_imx_uart(2, &uart_pdata);
178
179         gpio_request(MBIMX51_LED0, "LED0");
180         gpio_direction_output(MBIMX51_LED0, 1);
181         gpio_free(MBIMX51_LED0);
182         gpio_request(MBIMX51_LED1, "LED1");
183         gpio_direction_output(MBIMX51_LED1, 1);
184         gpio_free(MBIMX51_LED1);
185         gpio_request(MBIMX51_LED2, "LED2");
186         gpio_direction_output(MBIMX51_LED2, 1);
187         gpio_free(MBIMX51_LED2);
188         gpio_request(MBIMX51_LED3, "LED3");
189         gpio_direction_output(MBIMX51_LED3, 1);
190         gpio_free(MBIMX51_LED3);
191
192         platform_add_devices(devices, ARRAY_SIZE(devices));
193
194         mxc_register_device(&mxc_keypad_device, &mbimx51_map_data);
195
196         gpio_request(MBIMX51_TSC2007_GPIO, "tsc2007_irq");
197         gpio_direction_input(MBIMX51_TSC2007_GPIO);
198         set_irq_type(MBIMX51_TSC2007_IRQ, IRQF_TRIGGER_FALLING);
199         i2c_register_board_info(1, mbimx51_i2c_devices,
200                                 ARRAY_SIZE(mbimx51_i2c_devices));
201 }