]> git.karo-electronics.de Git - mv-sheeva.git/blob - arch/arm/mach-mx2/eukrea_mbimx27-baseboard.c
eukrea_mbimx27: add support for the keyboard
[mv-sheeva.git] / arch / arm / mach-mx2 / eukrea_mbimx27-baseboard.c
1 /*
2  * Copyright (C) 2009 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 #include <linux/input/matrix_keypad.h>
30
31 #include <asm/mach/arch.h>
32
33 #include <mach/common.h>
34 #include <mach/iomux-mx27.h>
35 #include <mach/imxfb.h>
36 #include <mach/hardware.h>
37 #include <mach/mmc.h>
38 #include <mach/imx-uart.h>
39 #include <mach/spi.h>
40
41 #include "devices.h"
42
43 static int eukrea_mbimx27_pins[] = {
44         /* UART2 */
45         PE3_PF_UART2_CTS,
46         PE4_PF_UART2_RTS,
47         PE6_PF_UART2_TXD,
48         PE7_PF_UART2_RXD,
49         /* UART3 */
50         PE8_PF_UART3_TXD,
51         PE9_PF_UART3_RXD,
52         PE10_PF_UART3_CTS,
53         PE11_PF_UART3_RTS,
54         /* UART4 */
55 #if !defined(MACH_EUKREA_CPUIMX27_USEUART4)
56         PB26_AF_UART4_RTS,
57         PB28_AF_UART4_TXD,
58         PB29_AF_UART4_CTS,
59         PB31_AF_UART4_RXD,
60 #endif
61         /* SDHC1*/
62         PE18_PF_SD1_D0,
63         PE19_PF_SD1_D1,
64         PE20_PF_SD1_D2,
65         PE21_PF_SD1_D3,
66         PE22_PF_SD1_CMD,
67         PE23_PF_SD1_CLK,
68         /* display */
69         PA5_PF_LSCLK,
70         PA6_PF_LD0,
71         PA7_PF_LD1,
72         PA8_PF_LD2,
73         PA9_PF_LD3,
74         PA10_PF_LD4,
75         PA11_PF_LD5,
76         PA12_PF_LD6,
77         PA13_PF_LD7,
78         PA14_PF_LD8,
79         PA15_PF_LD9,
80         PA16_PF_LD10,
81         PA17_PF_LD11,
82         PA18_PF_LD12,
83         PA19_PF_LD13,
84         PA20_PF_LD14,
85         PA21_PF_LD15,
86         PA22_PF_LD16,
87         PA23_PF_LD17,
88         PA28_PF_HSYNC,
89         PA29_PF_VSYNC,
90         PA30_PF_CONTRAST,
91         PA31_PF_OE_ACD,
92         /* SPI1 */
93         PD29_PF_CSPI1_SCLK,
94         PD30_PF_CSPI1_MISO,
95         PD31_PF_CSPI1_MOSI,
96 };
97
98 static const uint32_t eukrea_mbimx27_keymap[] = {
99         KEY(0, 0, KEY_UP),
100         KEY(0, 1, KEY_DOWN),
101         KEY(1, 0, KEY_RIGHT),
102         KEY(1, 1, KEY_LEFT),
103 };
104
105 static struct matrix_keymap_data eukrea_mbimx27_keymap_data = {
106         .keymap         = eukrea_mbimx27_keymap,
107         .keymap_size    = ARRAY_SIZE(eukrea_mbimx27_keymap),
108 };
109
110 static struct gpio_led gpio_leds[] = {
111         {
112                 .name                   = "led1",
113                 .default_trigger        = "heartbeat",
114                 .active_low             = 1,
115                 .gpio                   = GPIO_PORTF | 16,
116         },
117         {
118                 .name                   = "led2",
119                 .default_trigger        = "none",
120                 .active_low             = 1,
121                 .gpio                   = GPIO_PORTF | 19,
122         },
123 };
124
125 static struct gpio_led_platform_data gpio_led_info = {
126         .leds           = gpio_leds,
127         .num_leds       = ARRAY_SIZE(gpio_leds),
128 };
129
130 static struct platform_device leds_gpio = {
131         .name   = "leds-gpio",
132         .id     = -1,
133         .dev    = {
134                 .platform_data  = &gpio_led_info,
135         },
136 };
137
138 static struct imx_fb_videomode eukrea_mbimx27_modes[] = {
139         {
140                 .mode = {
141                         .name           = "CMO-QVGA",
142                         .refresh        = 60,
143                         .xres           = 320,
144                         .yres           = 240,
145                         .pixclock       = 156000,
146                         .hsync_len      = 30,
147                         .left_margin    = 38,
148                         .right_margin   = 20,
149                         .vsync_len      = 3,
150                         .upper_margin   = 15,
151                         .lower_margin   = 4,
152                 },
153                 .pcr            = 0xFAD08B80,
154                 .bpp            = 16,
155         }, {
156                 .mode = {
157                         .name           = "DVI-VGA",
158                         .refresh        = 60,
159                         .xres           = 640,
160                         .yres           = 480,
161                         .pixclock       = 32000,
162                         .hsync_len      = 1,
163                         .left_margin    = 35,
164                         .right_margin   = 0,
165                         .vsync_len      = 1,
166                         .upper_margin   = 7,
167                         .lower_margin   = 0,
168                 },
169                 .pcr            = 0xFA208B80,
170                 .bpp            = 16,
171         }, {
172                 .mode = {
173                         .name           = "DVI-SVGA",
174                         .refresh        = 60,
175                         .xres           = 800,
176                         .yres           = 600,
177                         .pixclock       = 25000,
178                         .hsync_len      = 1,
179                         .left_margin    = 35,
180                         .right_margin   = 0,
181                         .vsync_len      = 1,
182                         .upper_margin   = 7,
183                         .lower_margin   = 0,
184                 },
185                 .pcr            = 0xFA208B80,
186                 .bpp            = 16,
187         },
188 };
189
190 static struct imx_fb_platform_data eukrea_mbimx27_fb_data = {
191         .mode = eukrea_mbimx27_modes,
192         .num_modes = ARRAY_SIZE(eukrea_mbimx27_modes),
193
194         .pwmr           = 0x00A903FF,
195         .lscr1          = 0x00120300,
196         .dmacr          = 0x00040060,
197 };
198
199 static void eukrea_mbimx27_bl_set_intensity(int intensity)
200 {
201         if (intensity)
202                 gpio_direction_output(GPIO_PORTE | 5, 1);
203         else
204                 gpio_direction_output(GPIO_PORTE | 5, 0);
205 }
206
207 static struct generic_bl_info eukrea_mbimx27_bl_info = {
208         .name                   = "eukrea_mbimx27-bl",
209         .max_intensity          = 0xff,
210         .default_intensity      = 0xff,
211         .set_bl_intensity       = eukrea_mbimx27_bl_set_intensity,
212 };
213
214 static struct platform_device eukrea_mbimx27_bl_dev = {
215         .name                   = "generic-bl",
216         .id                     = 1,
217         .dev = {
218                 .platform_data  = &eukrea_mbimx27_bl_info,
219         },
220 };
221
222 static void eukrea_mbimx27_lcd_power_set(struct plat_lcd_data *pd,
223                                    unsigned int power)
224 {
225         if (power)
226                 gpio_direction_output(GPIO_PORTA | 25, 1);
227         else
228                 gpio_direction_output(GPIO_PORTA | 25, 0);
229 }
230
231 static struct plat_lcd_data eukrea_mbimx27_lcd_power_data = {
232         .set_power              = eukrea_mbimx27_lcd_power_set,
233 };
234
235 static struct platform_device eukrea_mbimx27_lcd_powerdev = {
236         .name                   = "platform-lcd",
237         .dev.platform_data      = &eukrea_mbimx27_lcd_power_data,
238 };
239
240 static struct imxuart_platform_data uart_pdata[] = {
241         {
242                 .flags = IMXUART_HAVE_RTSCTS,
243         },
244         {
245                 .flags = IMXUART_HAVE_RTSCTS,
246         },
247         {
248                 .flags = IMXUART_HAVE_RTSCTS,
249         },
250 };
251
252 #if defined(CONFIG_TOUCHSCREEN_ADS7846) \
253         || defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
254
255 #define ADS7846_PENDOWN (GPIO_PORTD | 25)
256
257 static void ads7846_dev_init(void)
258 {
259         if (gpio_request(ADS7846_PENDOWN, "ADS7846 pendown") < 0) {
260                 printk(KERN_ERR "can't get ads746 pen down GPIO\n");
261                 return;
262         }
263         gpio_direction_input(ADS7846_PENDOWN);
264 }
265
266 static int ads7846_get_pendown_state(void)
267 {
268         return !gpio_get_value(ADS7846_PENDOWN);
269 }
270
271 static struct ads7846_platform_data ads7846_config __initdata = {
272         .get_pendown_state      = ads7846_get_pendown_state,
273         .keep_vref_on           = 1,
274 };
275 #endif
276
277 #if defined(CONFIG_SPI_IMX) || defined(CONFIG_SPI_IMX_MODULE)
278 static struct spi_board_info eukrea_mbimx27_spi_board_info[] __initdata = {
279         [0] = {
280                 .modalias       = "ads7846",
281                 .bus_num        = 0,
282                 .chip_select    = 0,
283                 .max_speed_hz   = 1500000,
284                 .irq            = IRQ_GPIOD(25),
285                 .platform_data  = &ads7846_config,
286                 .mode           = SPI_MODE_2,
287         },
288 };
289
290 static int eukrea_mbimx27_spi_cs[] = {GPIO_PORTD | 28};
291
292 static struct spi_imx_master eukrea_mbimx27_spi_0_data = {
293         .chipselect     = eukrea_mbimx27_spi_cs,
294         .num_chipselect = ARRAY_SIZE(eukrea_mbimx27_spi_cs),
295 };
296 #endif
297
298 static struct platform_device *platform_devices[] __initdata = {
299         &leds_gpio,
300 };
301
302 static struct imxmmc_platform_data sdhc_pdata = {
303         .dat3_card_detect = 1,
304 };
305
306 /*
307  * system init for baseboard usage. Will be called by cpuimx27 init.
308  *
309  * Add platform devices present on this baseboard and init
310  * them from CPU side as far as required to use them later on
311  */
312 void __init eukrea_mbimx27_baseboard_init(void)
313 {
314         mxc_gpio_setup_multiple_pins(eukrea_mbimx27_pins,
315                 ARRAY_SIZE(eukrea_mbimx27_pins), "MBIMX27");
316
317         mxc_register_device(&mxc_uart_device1, &uart_pdata[0]);
318         mxc_register_device(&mxc_uart_device2, &uart_pdata[1]);
319 #if !defined(MACH_EUKREA_CPUIMX27_USEUART4)
320         mxc_register_device(&mxc_uart_device3, &uart_pdata[2]);
321 #endif
322
323         mxc_register_device(&mxc_fb_device, &eukrea_mbimx27_fb_data);
324         mxc_register_device(&mxc_sdhc_device0, &sdhc_pdata);
325
326 #if defined(CONFIG_TOUCHSCREEN_ADS7846) \
327         || defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
328         /* ADS7846 Touchscreen controller init */
329         mxc_gpio_mode(GPIO_PORTD | 25 | GPIO_GPIO | GPIO_IN);
330         ads7846_dev_init();
331 #endif
332
333 #if defined(CONFIG_SPI_IMX) || defined(CONFIG_SPI_IMX_MODULE)
334         /* SPI_CS0 init */
335         mxc_gpio_mode(GPIO_PORTD | 28 | GPIO_GPIO | GPIO_OUT);
336         mxc_register_device(&mxc_spi_device0, &eukrea_mbimx27_spi_0_data);
337         spi_register_board_info(eukrea_mbimx27_spi_board_info,
338                         ARRAY_SIZE(eukrea_mbimx27_spi_board_info));
339 #endif
340
341         /* Leds configuration */
342         mxc_gpio_mode(GPIO_PORTF | 16 | GPIO_GPIO | GPIO_OUT);
343         mxc_gpio_mode(GPIO_PORTF | 19 | GPIO_GPIO | GPIO_OUT);
344         /* Backlight */
345         mxc_gpio_mode(GPIO_PORTE | 5 | GPIO_GPIO | GPIO_OUT);
346         gpio_request(GPIO_PORTE | 5, "backlight");
347         platform_device_register(&eukrea_mbimx27_bl_dev);
348         /* LCD Reset */
349         mxc_gpio_mode(GPIO_PORTA | 25 | GPIO_GPIO | GPIO_OUT);
350         gpio_request(GPIO_PORTA | 25, "lcd_enable");
351         platform_device_register(&eukrea_mbimx27_lcd_powerdev);
352
353         mxc_register_device(&imx_kpp_device, &eukrea_mbimx27_keymap_data);
354
355         platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices));
356 }