ARM: imx: dynamically allocate imx-keypad devices
[deliverable/linux.git] / arch / arm / mach-imx / eukrea_mbimx27-baseboard.c
1 /*
2 * Copyright (C) 2009-2010 Eric Benard - eric@eukrea.com
3 *
4 * Based on pcm970-baseboard.c which is :
5 * Copyright (C) 2008 Juergen Beisert (kernel@pengutronix.de)
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 * MA 02110-1301, USA.
20 */
21
22 #include <linux/gpio.h>
23 #include <linux/irq.h>
24 #include <linux/platform_device.h>
25 #include <linux/spi/spi.h>
26 #include <linux/spi/ads7846.h>
27 #include <linux/backlight.h>
28 #include <video/platform_lcd.h>
29
30 #include <asm/mach/arch.h>
31
32 #include <mach/common.h>
33 #include <mach/iomux-mx27.h>
34 #include <mach/hardware.h>
35 #include <mach/spi.h>
36 #include <mach/audmux.h>
37
38 #include "devices-imx27.h"
39 #include "devices.h"
40
41 static const int eukrea_mbimx27_pins[] __initconst = {
42 /* UART2 */
43 PE3_PF_UART2_CTS,
44 PE4_PF_UART2_RTS,
45 PE6_PF_UART2_TXD,
46 PE7_PF_UART2_RXD,
47 /* UART3 */
48 PE8_PF_UART3_TXD,
49 PE9_PF_UART3_RXD,
50 PE10_PF_UART3_CTS,
51 PE11_PF_UART3_RTS,
52 /* UART4 */
53 #if !defined(MACH_EUKREA_CPUIMX27_USEUART4)
54 PB26_AF_UART4_RTS,
55 PB28_AF_UART4_TXD,
56 PB29_AF_UART4_CTS,
57 PB31_AF_UART4_RXD,
58 #endif
59 /* SDHC1*/
60 PE18_PF_SD1_D0,
61 PE19_PF_SD1_D1,
62 PE20_PF_SD1_D2,
63 PE21_PF_SD1_D3,
64 PE22_PF_SD1_CMD,
65 PE23_PF_SD1_CLK,
66 /* display */
67 PA5_PF_LSCLK,
68 PA6_PF_LD0,
69 PA7_PF_LD1,
70 PA8_PF_LD2,
71 PA9_PF_LD3,
72 PA10_PF_LD4,
73 PA11_PF_LD5,
74 PA12_PF_LD6,
75 PA13_PF_LD7,
76 PA14_PF_LD8,
77 PA15_PF_LD9,
78 PA16_PF_LD10,
79 PA17_PF_LD11,
80 PA18_PF_LD12,
81 PA19_PF_LD13,
82 PA20_PF_LD14,
83 PA21_PF_LD15,
84 PA22_PF_LD16,
85 PA23_PF_LD17,
86 PA28_PF_HSYNC,
87 PA29_PF_VSYNC,
88 PA30_PF_CONTRAST,
89 PA31_PF_OE_ACD,
90 /* SPI1 */
91 PD29_PF_CSPI1_SCLK,
92 PD30_PF_CSPI1_MISO,
93 PD31_PF_CSPI1_MOSI,
94 /* SSI4 */
95 #if defined(CONFIG_SND_SOC_EUKREA_TLV320) \
96 || defined(CONFIG_SND_SOC_EUKREA_TLV320_MODULE)
97 PC16_PF_SSI4_FS,
98 PC17_PF_SSI4_RXD | GPIO_PUEN,
99 PC18_PF_SSI4_TXD | GPIO_PUEN,
100 PC19_PF_SSI4_CLK,
101 #endif
102 };
103
104 static const uint32_t eukrea_mbimx27_keymap[] = {
105 KEY(0, 0, KEY_UP),
106 KEY(0, 1, KEY_DOWN),
107 KEY(1, 0, KEY_RIGHT),
108 KEY(1, 1, KEY_LEFT),
109 };
110
111 static const struct matrix_keymap_data
112 eukrea_mbimx27_keymap_data __initconst = {
113 .keymap = eukrea_mbimx27_keymap,
114 .keymap_size = ARRAY_SIZE(eukrea_mbimx27_keymap),
115 };
116
117 static struct gpio_led gpio_leds[] = {
118 {
119 .name = "led1",
120 .default_trigger = "heartbeat",
121 .active_low = 1,
122 .gpio = GPIO_PORTF | 16,
123 },
124 {
125 .name = "led2",
126 .default_trigger = "none",
127 .active_low = 1,
128 .gpio = GPIO_PORTF | 19,
129 },
130 };
131
132 static struct gpio_led_platform_data gpio_led_info = {
133 .leds = gpio_leds,
134 .num_leds = ARRAY_SIZE(gpio_leds),
135 };
136
137 static struct platform_device leds_gpio = {
138 .name = "leds-gpio",
139 .id = -1,
140 .dev = {
141 .platform_data = &gpio_led_info,
142 },
143 };
144
145 static struct imx_fb_videomode eukrea_mbimx27_modes[] = {
146 {
147 .mode = {
148 .name = "CMO-QVGA",
149 .refresh = 60,
150 .xres = 320,
151 .yres = 240,
152 .pixclock = 156000,
153 .hsync_len = 30,
154 .left_margin = 38,
155 .right_margin = 20,
156 .vsync_len = 3,
157 .upper_margin = 15,
158 .lower_margin = 4,
159 },
160 .pcr = 0xFAD08B80,
161 .bpp = 16,
162 }, {
163 .mode = {
164 .name = "DVI-VGA",
165 .refresh = 60,
166 .xres = 640,
167 .yres = 480,
168 .pixclock = 32000,
169 .hsync_len = 1,
170 .left_margin = 35,
171 .right_margin = 0,
172 .vsync_len = 1,
173 .upper_margin = 7,
174 .lower_margin = 0,
175 },
176 .pcr = 0xFA208B80,
177 .bpp = 16,
178 }, {
179 .mode = {
180 .name = "DVI-SVGA",
181 .refresh = 60,
182 .xres = 800,
183 .yres = 600,
184 .pixclock = 25000,
185 .hsync_len = 1,
186 .left_margin = 35,
187 .right_margin = 0,
188 .vsync_len = 1,
189 .upper_margin = 7,
190 .lower_margin = 0,
191 },
192 .pcr = 0xFA208B80,
193 .bpp = 16,
194 },
195 };
196
197 static const struct imx_fb_platform_data eukrea_mbimx27_fb_data __initconst = {
198 .mode = eukrea_mbimx27_modes,
199 .num_modes = ARRAY_SIZE(eukrea_mbimx27_modes),
200
201 .pwmr = 0x00A903FF,
202 .lscr1 = 0x00120300,
203 .dmacr = 0x00040060,
204 };
205
206 static void eukrea_mbimx27_bl_set_intensity(int intensity)
207 {
208 if (intensity)
209 gpio_direction_output(GPIO_PORTE | 5, 1);
210 else
211 gpio_direction_output(GPIO_PORTE | 5, 0);
212 }
213
214 static struct generic_bl_info eukrea_mbimx27_bl_info = {
215 .name = "eukrea_mbimx27-bl",
216 .max_intensity = 0xff,
217 .default_intensity = 0xff,
218 .set_bl_intensity = eukrea_mbimx27_bl_set_intensity,
219 };
220
221 static struct platform_device eukrea_mbimx27_bl_dev = {
222 .name = "generic-bl",
223 .id = 1,
224 .dev = {
225 .platform_data = &eukrea_mbimx27_bl_info,
226 },
227 };
228
229 static void eukrea_mbimx27_lcd_power_set(struct plat_lcd_data *pd,
230 unsigned int power)
231 {
232 if (power)
233 gpio_direction_output(GPIO_PORTA | 25, 1);
234 else
235 gpio_direction_output(GPIO_PORTA | 25, 0);
236 }
237
238 static struct plat_lcd_data eukrea_mbimx27_lcd_power_data = {
239 .set_power = eukrea_mbimx27_lcd_power_set,
240 };
241
242 static struct platform_device eukrea_mbimx27_lcd_powerdev = {
243 .name = "platform-lcd",
244 .dev.platform_data = &eukrea_mbimx27_lcd_power_data,
245 };
246
247 static const struct imxuart_platform_data uart_pdata __initconst = {
248 .flags = IMXUART_HAVE_RTSCTS,
249 };
250
251 #if defined(CONFIG_TOUCHSCREEN_ADS7846) \
252 || defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
253
254 #define ADS7846_PENDOWN (GPIO_PORTD | 25)
255
256 static void ads7846_dev_init(void)
257 {
258 if (gpio_request(ADS7846_PENDOWN, "ADS7846 pendown") < 0) {
259 printk(KERN_ERR "can't get ads746 pen down GPIO\n");
260 return;
261 }
262 gpio_direction_input(ADS7846_PENDOWN);
263 }
264
265 static int ads7846_get_pendown_state(void)
266 {
267 return !gpio_get_value(ADS7846_PENDOWN);
268 }
269
270 static struct ads7846_platform_data ads7846_config __initdata = {
271 .get_pendown_state = ads7846_get_pendown_state,
272 .keep_vref_on = 1,
273 };
274 #endif
275
276 #if defined(CONFIG_SPI_IMX) || defined(CONFIG_SPI_IMX_MODULE)
277 static struct spi_board_info eukrea_mbimx27_spi_board_info[] __initdata = {
278 [0] = {
279 .modalias = "ads7846",
280 .bus_num = 0,
281 .chip_select = 0,
282 .max_speed_hz = 1500000,
283 .irq = IRQ_GPIOD(25),
284 .platform_data = &ads7846_config,
285 .mode = SPI_MODE_2,
286 },
287 };
288
289 static int eukrea_mbimx27_spi_cs[] = {GPIO_PORTD | 28};
290
291 static const struct spi_imx_master eukrea_mbimx27_spi0_data __initconst = {
292 .chipselect = eukrea_mbimx27_spi_cs,
293 .num_chipselect = ARRAY_SIZE(eukrea_mbimx27_spi_cs),
294 };
295 #endif
296
297 static struct i2c_board_info eukrea_mbimx27_i2c_devices[] = {
298 {
299 I2C_BOARD_INFO("tlv320aic23", 0x1a),
300 },
301 };
302
303 static struct platform_device *platform_devices[] __initdata = {
304 &leds_gpio,
305 };
306
307 static const struct imxmmc_platform_data sdhc_pdata __initconst = {
308 .dat3_card_detect = 1,
309 };
310
311 static const
312 struct imx_ssi_platform_data eukrea_mbimx27_ssi_pdata __initconst = {
313 .flags = IMX_SSI_DMA | IMX_SSI_USE_I2S_SLAVE,
314 };
315
316 /*
317 * system init for baseboard usage. Will be called by cpuimx27 init.
318 *
319 * Add platform devices present on this baseboard and init
320 * them from CPU side as far as required to use them later on
321 */
322 void __init eukrea_mbimx27_baseboard_init(void)
323 {
324 mxc_gpio_setup_multiple_pins(eukrea_mbimx27_pins,
325 ARRAY_SIZE(eukrea_mbimx27_pins), "MBIMX27");
326
327 #if defined(CONFIG_SND_SOC_EUKREA_TLV320) \
328 || defined(CONFIG_SND_SOC_EUKREA_TLV320_MODULE)
329 /* SSI unit master I2S codec connected to SSI_PINS_4*/
330 mxc_audmux_v1_configure_port(MX27_AUDMUX_HPCR1_SSI0,
331 MXC_AUDMUX_V1_PCR_SYN |
332 MXC_AUDMUX_V1_PCR_TFSDIR |
333 MXC_AUDMUX_V1_PCR_TCLKDIR |
334 MXC_AUDMUX_V1_PCR_RFSDIR |
335 MXC_AUDMUX_V1_PCR_RCLKDIR |
336 MXC_AUDMUX_V1_PCR_TFCSEL(MX27_AUDMUX_HPCR3_SSI_PINS_4) |
337 MXC_AUDMUX_V1_PCR_RFCSEL(MX27_AUDMUX_HPCR3_SSI_PINS_4) |
338 MXC_AUDMUX_V1_PCR_RXDSEL(MX27_AUDMUX_HPCR3_SSI_PINS_4)
339 );
340 mxc_audmux_v1_configure_port(MX27_AUDMUX_HPCR3_SSI_PINS_4,
341 MXC_AUDMUX_V1_PCR_SYN |
342 MXC_AUDMUX_V1_PCR_RXDSEL(MX27_AUDMUX_HPCR1_SSI0)
343 );
344 #endif
345
346 imx27_add_imx_uart1(&uart_pdata);
347 imx27_add_imx_uart2(&uart_pdata);
348 #if !defined(MACH_EUKREA_CPUIMX27_USEUART4)
349 imx27_add_imx_uart3(&uart_pdata);
350 #endif
351
352 imx27_add_imx_fb(&eukrea_mbimx27_fb_data);
353 imx27_add_mxc_mmc(0, &sdhc_pdata);
354
355 i2c_register_board_info(0, eukrea_mbimx27_i2c_devices,
356 ARRAY_SIZE(eukrea_mbimx27_i2c_devices));
357
358 imx27_add_imx_ssi(0, &eukrea_mbimx27_ssi_pdata);
359
360 #if defined(CONFIG_TOUCHSCREEN_ADS7846) \
361 || defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
362 /* ADS7846 Touchscreen controller init */
363 mxc_gpio_mode(GPIO_PORTD | 25 | GPIO_GPIO | GPIO_IN);
364 ads7846_dev_init();
365 #endif
366
367 #if defined(CONFIG_SPI_IMX) || defined(CONFIG_SPI_IMX_MODULE)
368 /* SPI_CS0 init */
369 mxc_gpio_mode(GPIO_PORTD | 28 | GPIO_GPIO | GPIO_OUT);
370 imx27_add_spi_imx0(&eukrea_mbimx27_spi0_data);
371 spi_register_board_info(eukrea_mbimx27_spi_board_info,
372 ARRAY_SIZE(eukrea_mbimx27_spi_board_info));
373 #endif
374
375 /* Leds configuration */
376 mxc_gpio_mode(GPIO_PORTF | 16 | GPIO_GPIO | GPIO_OUT);
377 mxc_gpio_mode(GPIO_PORTF | 19 | GPIO_GPIO | GPIO_OUT);
378 /* Backlight */
379 mxc_gpio_mode(GPIO_PORTE | 5 | GPIO_GPIO | GPIO_OUT);
380 gpio_request(GPIO_PORTE | 5, "backlight");
381 platform_device_register(&eukrea_mbimx27_bl_dev);
382 /* LCD Reset */
383 mxc_gpio_mode(GPIO_PORTA | 25 | GPIO_GPIO | GPIO_OUT);
384 gpio_request(GPIO_PORTA | 25, "lcd_enable");
385 platform_device_register(&eukrea_mbimx27_lcd_powerdev);
386
387 imx27_add_imx_keypad(&eukrea_mbimx27_keymap_data);
388
389 platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices));
390 }
This page took 0.038047 seconds and 5 git commands to generate.