99be540dbabef103e17bbbd2b2a4e645a304ac36
[linux-3.10.git] / arch / arm / mach-omap2 / board-omap3stalker.c
1 /*
2  * linux/arch/arm/mach-omap2/board-omap3evm.c
3  *
4  * Copyright (C) 2008 Guangzhou EMA-Tech
5  *
6  * Modified from mach-omap2/board-omap3evm.c
7  *
8  * Initial code: Syed Mohammed Khasim
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License version 2 as
12  * published by the Free Software Foundation.
13  */
14
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17 #include <linux/platform_device.h>
18 #include <linux/delay.h>
19 #include <linux/err.h>
20 #include <linux/clk.h>
21 #include <linux/io.h>
22 #include <linux/leds.h>
23 #include <linux/gpio.h>
24 #include <linux/input.h>
25 #include <linux/gpio_keys.h>
26
27 #include <linux/regulator/machine.h>
28 #include <linux/i2c/twl.h>
29 #include <linux/mmc/host.h>
30
31 #include <mach/hardware.h>
32 #include <asm/mach-types.h>
33 #include <asm/mach/arch.h>
34 #include <asm/mach/map.h>
35 #include <asm/mach/flash.h>
36
37 #include <plat/board.h>
38 #include <plat/common.h>
39 #include <plat/gpmc.h>
40 #include <plat/nand.h>
41 #include <plat/usb.h>
42 #include <video/omapdss.h>
43 #include <video/omap-panel-generic-dpi.h>
44
45 #include <plat/mcspi.h>
46 #include <linux/input/matrix_keypad.h>
47 #include <linux/spi/spi.h>
48 #include <linux/interrupt.h>
49 #include <linux/smsc911x.h>
50 #include <linux/i2c/at24.h>
51
52 #include "sdram-micron-mt46h32m32lf-6.h"
53 #include "mux.h"
54 #include "hsmmc.h"
55 #include "timer-gp.h"
56 #include "common-board-devices.h"
57
58 #if defined(CONFIG_SMSC911X) || defined(CONFIG_SMSC911X_MODULE)
59 #include <plat/gpmc-smsc911x.h>
60
61 #define OMAP3STALKER_ETHR_START 0x2c000000
62 #define OMAP3STALKER_ETHR_SIZE  1024
63 #define OMAP3STALKER_ETHR_GPIO_IRQ      19
64 #define OMAP3STALKER_SMC911X_CS 5
65
66 static struct omap_smsc911x_platform_data smsc911x_cfg = {
67         .cs             = OMAP3STALKER_SMC911X_CS,
68         .gpio_irq       = OMAP3STALKER_ETHR_GPIO_IRQ,
69         .gpio_reset     = -EINVAL,
70         .flags          = (SMSC911X_USE_32BIT | SMSC911X_SAVE_MAC_ADDRESS),
71 };
72
73 static inline void __init omap3stalker_init_eth(void)
74 {
75         struct clk *l3ck;
76         unsigned int rate;
77
78         l3ck = clk_get(NULL, "l3_ck");
79         if (IS_ERR(l3ck))
80                 rate = 100000000;
81         else
82                 rate = clk_get_rate(l3ck);
83
84         omap_mux_init_gpio(19, OMAP_PIN_INPUT_PULLUP);
85         gpmc_smsc911x_init(&smsc911x_cfg);
86 }
87
88 #else
89 static inline void __init omap3stalker_init_eth(void)
90 {
91         return;
92 }
93 #endif
94
95 /*
96  * OMAP3 DSS control signals
97  */
98
99 #define DSS_ENABLE_GPIO 199
100 #define LCD_PANEL_BKLIGHT_GPIO  210
101 #define ENABLE_VPLL2_DEV_GRP    0xE0
102
103 static int lcd_enabled;
104 static int dvi_enabled;
105
106 static void __init omap3_stalker_display_init(void)
107 {
108         return;
109 }
110
111 static int omap3_stalker_enable_lcd(struct omap_dss_device *dssdev)
112 {
113         if (dvi_enabled) {
114                 printk(KERN_ERR "cannot enable LCD, DVI is enabled\n");
115                 return -EINVAL;
116         }
117         gpio_set_value(DSS_ENABLE_GPIO, 1);
118         gpio_set_value(LCD_PANEL_BKLIGHT_GPIO, 1);
119         lcd_enabled = 1;
120         return 0;
121 }
122
123 static void omap3_stalker_disable_lcd(struct omap_dss_device *dssdev)
124 {
125         gpio_set_value(DSS_ENABLE_GPIO, 0);
126         gpio_set_value(LCD_PANEL_BKLIGHT_GPIO, 0);
127         lcd_enabled = 0;
128 }
129
130 static struct panel_generic_dpi_data lcd_panel = {
131         .name                   = "generic",
132         .platform_enable        = omap3_stalker_enable_lcd,
133         .platform_disable       = omap3_stalker_disable_lcd,
134 };
135
136 static struct omap_dss_device omap3_stalker_lcd_device = {
137         .name                   = "lcd",
138         .driver_name            = "generic_dpi_panel",
139         .data                   = &lcd_panel,
140         .phy.dpi.data_lines     = 24,
141         .type                   = OMAP_DISPLAY_TYPE_DPI,
142 };
143
144 static int omap3_stalker_enable_tv(struct omap_dss_device *dssdev)
145 {
146         return 0;
147 }
148
149 static void omap3_stalker_disable_tv(struct omap_dss_device *dssdev)
150 {
151 }
152
153 static struct omap_dss_device omap3_stalker_tv_device = {
154         .name                   = "tv",
155         .driver_name            = "venc",
156         .type                   = OMAP_DISPLAY_TYPE_VENC,
157 #if defined(CONFIG_OMAP2_VENC_OUT_TYPE_SVIDEO)
158         .phy.venc.type          = OMAP_DSS_VENC_TYPE_SVIDEO,
159 #elif defined(CONFIG_OMAP2_VENC_OUT_TYPE_COMPOSITE)
160         .u.venc.type            = OMAP_DSS_VENC_TYPE_COMPOSITE,
161 #endif
162         .platform_enable        = omap3_stalker_enable_tv,
163         .platform_disable       = omap3_stalker_disable_tv,
164 };
165
166 static int omap3_stalker_enable_dvi(struct omap_dss_device *dssdev)
167 {
168         if (lcd_enabled) {
169                 printk(KERN_ERR "cannot enable DVI, LCD is enabled\n");
170                 return -EINVAL;
171         }
172         gpio_set_value(DSS_ENABLE_GPIO, 1);
173         dvi_enabled = 1;
174         return 0;
175 }
176
177 static void omap3_stalker_disable_dvi(struct omap_dss_device *dssdev)
178 {
179         gpio_set_value(DSS_ENABLE_GPIO, 0);
180         dvi_enabled = 0;
181 }
182
183 static struct panel_generic_dpi_data dvi_panel = {
184         .name                   = "generic",
185         .platform_enable        = omap3_stalker_enable_dvi,
186         .platform_disable       = omap3_stalker_disable_dvi,
187 };
188
189 static struct omap_dss_device omap3_stalker_dvi_device = {
190         .name                   = "dvi",
191         .type                   = OMAP_DISPLAY_TYPE_DPI,
192         .driver_name            = "generic_dpi_panel",
193         .data                   = &dvi_panel,
194         .phy.dpi.data_lines     = 24,
195 };
196
197 static struct omap_dss_device *omap3_stalker_dss_devices[] = {
198         &omap3_stalker_lcd_device,
199         &omap3_stalker_tv_device,
200         &omap3_stalker_dvi_device,
201 };
202
203 static struct omap_dss_board_info omap3_stalker_dss_data = {
204         .num_devices    = ARRAY_SIZE(omap3_stalker_dss_devices),
205         .devices        = omap3_stalker_dss_devices,
206         .default_device = &omap3_stalker_dvi_device,
207 };
208
209 static struct regulator_consumer_supply omap3stalker_vmmc1_supply[] = {
210         REGULATOR_SUPPLY("vmmc", "omap_hsmmc.0"),
211 };
212
213 static struct regulator_consumer_supply omap3stalker_vsim_supply[] = {
214         REGULATOR_SUPPLY("vmmc_aux", "omap_hsmmc.0"),
215 };
216
217 /* VMMC1 for MMC1 pins CMD, CLK, DAT0..DAT3 (20 mA, plus card == max 220 mA) */
218 static struct regulator_init_data omap3stalker_vmmc1 = {
219         .constraints            = {
220                 .min_uV                 = 1850000,
221                 .max_uV                 = 3150000,
222                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
223                 | REGULATOR_MODE_STANDBY,
224                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
225                 | REGULATOR_CHANGE_MODE | REGULATOR_CHANGE_STATUS,
226         },
227         .num_consumer_supplies  = ARRAY_SIZE(omap3stalker_vmmc1_supply),
228         .consumer_supplies      = omap3stalker_vmmc1_supply,
229 };
230
231 /* VSIM for MMC1 pins DAT4..DAT7 (2 mA, plus card == max 50 mA) */
232 static struct regulator_init_data omap3stalker_vsim = {
233         .constraints            = {
234                 .min_uV                 = 1800000,
235                 .max_uV                 = 3000000,
236                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
237                 | REGULATOR_MODE_STANDBY,
238                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
239                 | REGULATOR_CHANGE_MODE | REGULATOR_CHANGE_STATUS,
240         },
241         .num_consumer_supplies  = ARRAY_SIZE(omap3stalker_vsim_supply),
242         .consumer_supplies      = omap3stalker_vsim_supply,
243 };
244
245 static struct omap2_hsmmc_info mmc[] = {
246         {
247          .mmc           = 1,
248          .caps          = MMC_CAP_4_BIT_DATA,
249          .gpio_cd       = -EINVAL,
250          .gpio_wp       = 23,
251          },
252         {}                      /* Terminator */
253 };
254
255 static struct gpio_keys_button gpio_buttons[] = {
256         {
257          .code          = BTN_EXTRA,
258          .gpio          = 18,
259          .desc          = "user",
260          .wakeup        = 1,
261          },
262 };
263
264 static struct gpio_keys_platform_data gpio_key_info = {
265         .buttons        = gpio_buttons,
266         .nbuttons       = ARRAY_SIZE(gpio_buttons),
267 };
268
269 static struct platform_device keys_gpio = {
270         .name           = "gpio-keys",
271         .id             = -1,
272         .dev            = {
273                 .platform_data  = &gpio_key_info,
274         },
275 };
276
277 static struct gpio_led gpio_leds[] = {
278         {
279          .name                  = "stalker:D8:usr0",
280          .default_trigger       = "default-on",
281          .gpio                  = 126,
282          },
283         {
284          .name                  = "stalker:D9:usr1",
285          .default_trigger       = "default-on",
286          .gpio                  = 127,
287          },
288         {
289          .name                  = "stalker:D3:mmc0",
290          .gpio                  = -EINVAL,      /* gets replaced */
291          .active_low            = true,
292          .default_trigger       = "mmc0",
293          },
294         {
295          .name                  = "stalker:D4:heartbeat",
296          .gpio                  = -EINVAL,      /* gets replaced */
297          .active_low            = true,
298          .default_trigger       = "heartbeat",
299          },
300 };
301
302 static struct gpio_led_platform_data gpio_led_info = {
303         .leds           = gpio_leds,
304         .num_leds       = ARRAY_SIZE(gpio_leds),
305 };
306
307 static struct platform_device leds_gpio = {
308         .name   = "leds-gpio",
309         .id     = -1,
310         .dev    = {
311                 .platform_data  = &gpio_led_info,
312         },
313 };
314
315 static int
316 omap3stalker_twl_gpio_setup(struct device *dev,
317                             unsigned gpio, unsigned ngpio)
318 {
319         /* gpio + 0 is "mmc0_cd" (input/IRQ) */
320         omap_mux_init_gpio(23, OMAP_PIN_INPUT);
321         mmc[0].gpio_cd = gpio + 0;
322         omap2_hsmmc_init(mmc);
323
324         /* link regulators to MMC adapters */
325         omap3stalker_vmmc1_supply.dev = mmc[0].dev;
326         omap3stalker_vsim_supply.dev = mmc[0].dev;
327
328         /*
329          * Most GPIOs are for USB OTG.  Some are mostly sent to
330          * the P2 connector; notably LEDA for the LCD backlight.
331          */
332
333         /* TWL4030_GPIO_MAX + 0 == ledA, LCD Backlight control */
334         gpio_request_one(gpio + TWL4030_GPIO_MAX, GPIOF_OUT_INIT_LOW,
335                          "EN_LCD_BKL");
336
337         /* gpio + 7 == DVI Enable */
338         gpio_request_one(gpio + 7, GPIOF_OUT_INIT_LOW, "EN_DVI");
339
340         /* TWL4030_GPIO_MAX + 1 == ledB (out, mmc0) */
341         gpio_leds[2].gpio = gpio + TWL4030_GPIO_MAX + 1;
342         /* GPIO + 13 == ledsync (out, heartbeat) */
343         gpio_leds[3].gpio = gpio + 13;
344
345         platform_device_register(&leds_gpio);
346         return 0;
347 }
348
349 static struct twl4030_gpio_platform_data omap3stalker_gpio_data = {
350         .gpio_base      = OMAP_MAX_GPIO_LINES,
351         .irq_base       = TWL4030_GPIO_IRQ_BASE,
352         .irq_end        = TWL4030_GPIO_IRQ_END,
353         .use_leds       = true,
354         .setup          = omap3stalker_twl_gpio_setup,
355 };
356
357 static struct twl4030_usb_data omap3stalker_usb_data = {
358         .usb_mode       = T2_USB_MODE_ULPI,
359 };
360
361 static uint32_t board_keymap[] = {
362         KEY(0, 0, KEY_LEFT),
363         KEY(0, 1, KEY_DOWN),
364         KEY(0, 2, KEY_ENTER),
365         KEY(0, 3, KEY_M),
366
367         KEY(1, 0, KEY_RIGHT),
368         KEY(1, 1, KEY_UP),
369         KEY(1, 2, KEY_I),
370         KEY(1, 3, KEY_N),
371
372         KEY(2, 0, KEY_A),
373         KEY(2, 1, KEY_E),
374         KEY(2, 2, KEY_J),
375         KEY(2, 3, KEY_O),
376
377         KEY(3, 0, KEY_B),
378         KEY(3, 1, KEY_F),
379         KEY(3, 2, KEY_K),
380         KEY(3, 3, KEY_P)
381 };
382
383 static struct matrix_keymap_data board_map_data = {
384         .keymap         = board_keymap,
385         .keymap_size    = ARRAY_SIZE(board_keymap),
386 };
387
388 static struct twl4030_keypad_data omap3stalker_kp_data = {
389         .keymap_data    = &board_map_data,
390         .rows           = 4,
391         .cols           = 4,
392         .rep            = 1,
393 };
394
395 static struct twl4030_madc_platform_data omap3stalker_madc_data = {
396         .irq_line       = 1,
397 };
398
399 static struct twl4030_codec_audio_data omap3stalker_audio_data;
400
401 static struct twl4030_codec_data omap3stalker_codec_data = {
402         .audio_mclk     = 26000000,
403         .audio          = &omap3stalker_audio_data,
404 };
405
406 static struct regulator_consumer_supply omap3_stalker_vdda_dac_supply[] = {
407         REGULATOR_SUPPLY("vdda_dac", "omapdss_venc"),
408 };
409
410 /* VDAC for DSS driving S-Video */
411 static struct regulator_init_data omap3_stalker_vdac = {
412         .constraints            = {
413                 .min_uV                 = 1800000,
414                 .max_uV                 = 1800000,
415                 .apply_uV               = true,
416                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
417                 | REGULATOR_MODE_STANDBY,
418                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
419                 | REGULATOR_CHANGE_STATUS,
420         },
421         .num_consumer_supplies  = ARRAY_SIZE(omap3_stalker_vdda_dac_supply),
422         .consumer_supplies      = omap3_stalker_vdda_dac_supply,
423 };
424
425 /* VPLL2 for digital video outputs */
426 static struct regulator_consumer_supply omap3_stalker_vpll2_supplies[] = {
427         REGULATOR_SUPPLY("vdds_dsi", "omapdss"),
428         REGULATOR_SUPPLY("vdds_dsi", "omapdss_dsi1"),
429 };
430
431 static struct regulator_init_data omap3_stalker_vpll2 = {
432         .constraints            = {
433                 .name                   = "VDVI",
434                 .min_uV                 = 1800000,
435                 .max_uV                 = 1800000,
436                 .apply_uV = true,
437                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
438                 | REGULATOR_MODE_STANDBY,
439                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
440                 | REGULATOR_CHANGE_STATUS,
441         },
442         .num_consumer_supplies  = ARRAY_SIZE(omap3_stalker_vpll2_supplies),
443         .consumer_supplies      = omap3_stalker_vpll2_supplies,
444 };
445
446 static struct twl4030_platform_data omap3stalker_twldata = {
447         .irq_base       = TWL4030_IRQ_BASE,
448         .irq_end        = TWL4030_IRQ_END,
449
450         /* platform_data for children goes here */
451         .keypad         = &omap3stalker_kp_data,
452         .madc           = &omap3stalker_madc_data,
453         .usb            = &omap3stalker_usb_data,
454         .gpio           = &omap3stalker_gpio_data,
455         .codec          = &omap3stalker_codec_data,
456         .vdac           = &omap3_stalker_vdac,
457         .vpll2          = &omap3_stalker_vpll2,
458         .vmmc1          = &omap3stalker_vmmc1,
459         .vsim           = &omap3stalker_vsim,
460 };
461
462 static struct at24_platform_data fram_info = {
463         .byte_len       = (64 * 1024) / 8,
464         .page_size      = 8192,
465         .flags          = AT24_FLAG_ADDR16 | AT24_FLAG_IRUGO,
466 };
467
468 static struct i2c_board_info __initdata omap3stalker_i2c_boardinfo3[] = {
469         {
470          I2C_BOARD_INFO("24c64", 0x50),
471          .flags         = I2C_CLIENT_WAKE,
472          .platform_data = &fram_info,
473          },
474 };
475
476 static int __init omap3_stalker_i2c_init(void)
477 {
478         omap3_pmic_init("twl4030", &omap3stalker_twldata);
479         omap_register_i2c_bus(2, 400, NULL, 0);
480         omap_register_i2c_bus(3, 400, omap3stalker_i2c_boardinfo3,
481                               ARRAY_SIZE(omap3stalker_i2c_boardinfo3));
482         return 0;
483 }
484
485 #define OMAP3_STALKER_TS_GPIO   175
486
487 static struct omap_board_config_kernel omap3_stalker_config[] __initdata = {
488 };
489
490 static void __init omap3_stalker_init_early(void)
491 {
492         omap2_init_common_infrastructure();
493         omap2_init_common_devices(mt46h32m32lf6_sdrc_params, NULL);
494 }
495
496 static void __init omap3_stalker_init_irq(void)
497 {
498         omap_init_irq();
499 #ifdef CONFIG_OMAP_32K_TIMER
500         omap2_gp_clockevent_set_gptimer(12);
501 #endif
502 }
503
504 static struct platform_device *omap3_stalker_devices[] __initdata = {
505         &keys_gpio,
506 };
507
508 static struct usbhs_omap_board_data usbhs_bdata __initconst = {
509         .port_mode[0] = OMAP_USBHS_PORT_MODE_UNUSED,
510         .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY,
511         .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED,
512
513         .phy_reset = true,
514         .reset_gpio_port[0] = -EINVAL,
515         .reset_gpio_port[1] = 21,
516         .reset_gpio_port[2] = -EINVAL,
517 };
518
519 #ifdef CONFIG_OMAP_MUX
520 static struct omap_board_mux board_mux[] __initdata = {
521         OMAP3_MUX(SYS_NIRQ, OMAP_MUX_MODE0 | OMAP_PIN_INPUT_PULLUP |
522                   OMAP_PIN_OFF_INPUT_PULLUP | OMAP_PIN_OFF_WAKEUPENABLE),
523         OMAP3_MUX(MCSPI1_CS1, OMAP_MUX_MODE4 | OMAP_PIN_INPUT_PULLUP |
524                   OMAP_PIN_OFF_INPUT_PULLUP | OMAP_PIN_OFF_WAKEUPENABLE),
525         {.reg_offset = OMAP_MUX_TERMINATOR},
526 };
527 #endif
528
529 static void __init omap3_stalker_init(void)
530 {
531         omap3_mux_init(board_mux, OMAP_PACKAGE_CUS);
532         omap_board_config = omap3_stalker_config;
533         omap_board_config_size = ARRAY_SIZE(omap3_stalker_config);
534
535         omap3_stalker_i2c_init();
536
537         platform_add_devices(omap3_stalker_devices,
538                              ARRAY_SIZE(omap3_stalker_devices));
539
540         omap_display_init(&omap3_stalker_dss_data);
541
542         omap_serial_init();
543         usb_musb_init(NULL);
544         usbhs_init(&usbhs_bdata);
545         omap_ads7846_init(1, OMAP3_STALKER_TS_GPIO, 310, NULL);
546
547         omap_mux_init_gpio(21, OMAP_PIN_OUTPUT);
548         omap_mux_init_gpio(18, OMAP_PIN_INPUT_PULLUP);
549
550         omap3stalker_init_eth();
551         omap3_stalker_display_init();
552 /* Ensure SDRC pins are mux'd for self-refresh */
553         omap_mux_init_signal("sdr_cke0", OMAP_PIN_OUTPUT);
554         omap_mux_init_signal("sdr_cke1", OMAP_PIN_OUTPUT);
555 }
556
557 MACHINE_START(SBC3530, "OMAP3 STALKER")
558         /* Maintainer: Jason Lam -lzg@ema-tech.com */
559         .boot_params            = 0x80000100,
560         .map_io                 = omap3_map_io,
561         .init_early             = omap3_stalker_init_early,
562         .init_irq               = omap3_stalker_init_irq,
563         .init_machine           = omap3_stalker_init,
564         .timer                  = &omap_timer,
565 MACHINE_END