blob: 34bdc26a75ba51b105b97a8ad85dc12e255a7df2 [file] [log] [blame]
Eric Benarda961bf32009-07-16 16:26:34 +02001/*
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>
Eric Bénardfc04ad02010-05-19 18:45:57 +020027#include <linux/backlight.h>
28#include <video/platform_lcd.h>
Eric Bénard5203b992010-05-19 18:46:07 +020029#include <linux/input/matrix_keypad.h>
Eric Benarda961bf32009-07-16 16:26:34 +020030
31#include <asm/mach/arch.h>
32
33#include <mach/common.h>
Uwe Kleine-Könige835d882010-02-16 11:07:49 +010034#include <mach/iomux-mx27.h>
Eric Benarda961bf32009-07-16 16:26:34 +020035#include <mach/imxfb.h>
36#include <mach/hardware.h>
37#include <mach/mmc.h>
38#include <mach/imx-uart.h>
Eric Bénard62d725b2010-05-20 09:22:28 +020039#include <mach/spi.h>
Eric Benarda961bf32009-07-16 16:26:34 +020040
41#include "devices.h"
42
43static 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 */
Eric Bénard2d66c782010-05-19 18:45:59 +020055#if !defined(MACH_EUKREA_CPUIMX27_USEUART4)
Eric Benarda961bf32009-07-16 16:26:34 +020056 PB26_AF_UART4_RTS,
57 PB28_AF_UART4_TXD,
58 PB29_AF_UART4_CTS,
59 PB31_AF_UART4_RXD,
Eric Bénard2d66c782010-05-19 18:45:59 +020060#endif
Eric Benarda961bf32009-07-16 16:26:34 +020061 /* 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 */
Eric Benarda961bf32009-07-16 16:26:34 +020093 PD29_PF_CSPI1_SCLK,
94 PD30_PF_CSPI1_MISO,
95 PD31_PF_CSPI1_MOSI,
96};
97
Eric Bénard5203b992010-05-19 18:46:07 +020098static 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
105static struct matrix_keymap_data eukrea_mbimx27_keymap_data = {
106 .keymap = eukrea_mbimx27_keymap,
107 .keymap_size = ARRAY_SIZE(eukrea_mbimx27_keymap),
108};
109
Eric Benarda961bf32009-07-16 16:26:34 +0200110static 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 },
Eric Benarda961bf32009-07-16 16:26:34 +0200123};
124
125static struct gpio_led_platform_data gpio_led_info = {
126 .leds = gpio_leds,
127 .num_leds = ARRAY_SIZE(gpio_leds),
128};
129
130static struct platform_device leds_gpio = {
131 .name = "leds-gpio",
132 .id = -1,
133 .dev = {
134 .platform_data = &gpio_led_info,
135 },
136};
137
138static struct imx_fb_videomode eukrea_mbimx27_modes[] = {
139 {
140 .mode = {
Eric Bénard4eaad662010-05-19 18:45:56 +0200141 .name = "CMO-QVGA",
Eric Benarda961bf32009-07-16 16:26:34 +0200142 .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,
Eric Bénarda4652422010-05-19 18:45:58 +0200155 }, {
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,
Eric Benarda961bf32009-07-16 16:26:34 +0200187 },
188};
189
190static 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
Eric Bénardfc04ad02010-05-19 18:45:57 +0200199static 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
207static 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
214static 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
222static 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
231static struct plat_lcd_data eukrea_mbimx27_lcd_power_data = {
232 .set_power = eukrea_mbimx27_lcd_power_set,
233};
234
235static struct platform_device eukrea_mbimx27_lcd_powerdev = {
236 .name = "platform-lcd",
237 .dev.platform_data = &eukrea_mbimx27_lcd_power_data,
238};
239
Eric Benarda961bf32009-07-16 16:26:34 +0200240static struct imxuart_platform_data uart_pdata[] = {
241 {
242 .flags = IMXUART_HAVE_RTSCTS,
243 },
244 {
245 .flags = IMXUART_HAVE_RTSCTS,
246 },
Eric Bénard2d66c782010-05-19 18:45:59 +0200247 {
248 .flags = IMXUART_HAVE_RTSCTS,
249 },
Eric Benarda961bf32009-07-16 16:26:34 +0200250};
251
Eric Bénard62d725b2010-05-20 09:22:28 +0200252#if defined(CONFIG_TOUCHSCREEN_ADS7846) \
Eric Benarda961bf32009-07-16 16:26:34 +0200253 || defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
254
255#define ADS7846_PENDOWN (GPIO_PORTD | 25)
256
257static 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 }
Eric Benarda961bf32009-07-16 16:26:34 +0200263 gpio_direction_input(ADS7846_PENDOWN);
264}
265
266static int ads7846_get_pendown_state(void)
267{
268 return !gpio_get_value(ADS7846_PENDOWN);
269}
270
271static struct ads7846_platform_data ads7846_config __initdata = {
272 .get_pendown_state = ads7846_get_pendown_state,
273 .keep_vref_on = 1,
274};
Eric Bénard62d725b2010-05-20 09:22:28 +0200275#endif
Eric Benarda961bf32009-07-16 16:26:34 +0200276
Eric Bénard62d725b2010-05-20 09:22:28 +0200277#if defined(CONFIG_SPI_IMX) || defined(CONFIG_SPI_IMX_MODULE)
Eric Benarda961bf32009-07-16 16:26:34 +0200278static 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
290static int eukrea_mbimx27_spi_cs[] = {GPIO_PORTD | 28};
291
292static 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
298static struct platform_device *platform_devices[] __initdata = {
299 &leds_gpio,
300};
301
Eric Bénarde76a17c2010-05-19 18:46:05 +0200302static struct imxmmc_platform_data sdhc_pdata = {
303 .dat3_card_detect = 1,
304};
305
Eric Benarda961bf32009-07-16 16:26:34 +0200306/*
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 */
312void __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]);
Eric Bénard2d66c782010-05-19 18:45:59 +0200319#if !defined(MACH_EUKREA_CPUIMX27_USEUART4)
320 mxc_register_device(&mxc_uart_device3, &uart_pdata[2]);
321#endif
Eric Benarda961bf32009-07-16 16:26:34 +0200322
323 mxc_register_device(&mxc_fb_device, &eukrea_mbimx27_fb_data);
Eric Bénarde76a17c2010-05-19 18:46:05 +0200324 mxc_register_device(&mxc_sdhc_device0, &sdhc_pdata);
Eric Benarda961bf32009-07-16 16:26:34 +0200325
Eric Bénard62d725b2010-05-20 09:22:28 +0200326#if defined(CONFIG_TOUCHSCREEN_ADS7846) \
Eric Benarda961bf32009-07-16 16:26:34 +0200327 || defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
Eric Bénard62d725b2010-05-20 09:22:28 +0200328 /* ADS7846 Touchscreen controller init */
Eric Benarda961bf32009-07-16 16:26:34 +0200329 mxc_gpio_mode(GPIO_PORTD | 25 | GPIO_GPIO | GPIO_IN);
Eric Bénard62d725b2010-05-20 09:22:28 +0200330 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);
Eric Benarda961bf32009-07-16 16:26:34 +0200336 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));
Eric Benarda961bf32009-07-16 16:26:34 +0200339#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);
Eric Bénardfc04ad02010-05-19 18:45:57 +0200346 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);
Eric Benarda961bf32009-07-16 16:26:34 +0200352
Eric Bénard5203b992010-05-19 18:46:07 +0200353 mxc_register_device(&imx_kpp_device, &eukrea_mbimx27_keymap_data);
354
Eric Benarda961bf32009-07-16 16:26:34 +0200355 platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices));
356}