rev3 changes
[pandora-kernel.git] / arch / arm / mach-omap2 / board-omap3pandora.c
1 /*
2  * board-omap3pandora.c (Pandora Handheld Console)
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * version 2 as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
16  * 02110-1301 USA
17  *
18  */
19
20 #include <linux/clk.h>
21 #include <linux/delay.h>
22 #include <linux/err.h>
23 #include <linux/init.h>
24 #include <linux/io.h>
25 #include <linux/kernel.h>
26 #include <linux/platform_device.h>
27
28 #include <linux/spi/spi.h>
29 #include <linux/spi/ads7846.h>
30 #include <linux/i2c/twl4030.h>
31 #include <linux/i2c/vsense.h>
32 #include <linux/leds.h>
33
34 #include <linux/mtd/mtd.h>
35 #include <linux/mtd/nand.h>
36 #include <linux/mtd/partitions.h>
37
38 #include <asm/mach-types.h>
39 #include <asm/mach/arch.h>
40 #include <asm/mach/flash.h>
41 #include <asm/mach/map.h>
42
43 #include <mach/board.h>
44 #include <mach/common.h>
45 #include <mach/gpio.h>
46 #include <mach/gpmc.h>
47 #include <mach/hardware.h>
48 #include <mach/hsmmc.h>
49 #include <mach/nand.h>
50 #include <mach/usb-ehci.h>
51 #include <mach/usb-musb.h>
52 #include <mach/mcspi.h>
53 #include <mach/display.h>
54
55 #include "sdram-micron-mt46h32m32lf-6.h"
56
57 #define NAND_BLOCK_SIZE SZ_128K
58 #define GPMC_CS0_BASE  0x60
59 #define GPMC_CS_SIZE   0x30
60
61 static struct mtd_partition omap3pandora_nand_partitions[] = {
62         {
63                 .name           = "xloader",
64                 .offset         = 0,                    /* Offset = 0x00000 */
65                 .size           = 4 * NAND_BLOCK_SIZE,
66                 .mask_flags     = MTD_WRITEABLE
67         }, {
68                 .name           = "uboot",
69                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x80000 */
70                 .size           = 14 * NAND_BLOCK_SIZE,
71         }, {
72                 .name           = "uboot environment",
73                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x240000 */
74                 .size           = 2 * NAND_BLOCK_SIZE,
75         }, {
76                 .name           = "linux",
77                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x280000 */
78                 .size           = 32 * NAND_BLOCK_SIZE,
79         }, {
80                 .name           = "rootfs",
81                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x680000 */
82                 .size           = MTDPART_SIZ_FULL,
83         },
84 };
85
86 static struct omap_nand_platform_data omap3pandora_nand_data = {
87         .parts          = omap3pandora_nand_partitions,
88         .nr_parts       = ARRAY_SIZE(omap3pandora_nand_partitions),
89         .dma_channel    = -1,   /* disable DMA in OMAP NAND driver */
90 };
91
92 static struct resource omap3pandora_nand_resource[] = {
93         {
94                 .flags          = IORESOURCE_MEM,
95         },
96 };
97
98 static struct platform_device omap3pandora_nand_device = {
99         .name           = "omap2-nand",
100         .id             = -1,
101         .dev            = {
102                 .platform_data  = &omap3pandora_nand_data,
103         },
104         .num_resources  = ARRAY_SIZE(omap3pandora_nand_resource),
105         .resource       = omap3pandora_nand_resource,
106 };
107
108 static void __init omap3pandora_flash_init(void)
109 {
110         u8 cs = 0;
111         u8 nandcs = GPMC_CS_NUM + 1;
112
113         u32 gpmc_base_add = OMAP34XX_GPMC_VIRT;
114
115         /* find out the chip-select on which NAND exists */
116         while (cs < GPMC_CS_NUM) {
117                 u32 ret = 0;
118                 ret = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1);
119
120                 if ((ret & 0xC00) == 0x800) {
121                         printk(KERN_INFO "Found NAND on CS%d\n", cs);
122                         if (nandcs > GPMC_CS_NUM)
123                                 nandcs = cs;
124                 }
125                 cs++;
126         }
127
128         if (nandcs > GPMC_CS_NUM) {
129                 printk(KERN_INFO "NAND: Unable to find configuration "
130                                  "in GPMC\n ");
131                 return;
132         }
133
134         if (nandcs < GPMC_CS_NUM) {
135                 omap3pandora_nand_data.cs = nandcs;
136                 omap3pandora_nand_data.gpmc_cs_baseaddr = (void *)
137                         (gpmc_base_add + GPMC_CS0_BASE + nandcs * GPMC_CS_SIZE);
138                 omap3pandora_nand_data.gpmc_baseaddr = (void *) (gpmc_base_add);
139
140                 printk(KERN_INFO "Registering NAND on CS%d\n", nandcs);
141                 if (platform_device_register(&omap3pandora_nand_device) < 0)
142                         printk(KERN_ERR "Unable to register NAND device\n");
143         }
144 }
145
146 static struct omap_uart_config omap3pandora_uart_config __initdata = {
147         .enabled_uarts  = (1 << 2), /* UART3 */
148 };
149
150 static struct gpio_led omap3pandora_gpio_leds[] = {
151         {
152                 .name                   = "pandora::keypad_bl",
153                 .gpio                   = -EINVAL,      /* gets replaced */
154                 .active_low             = true,
155         }, {
156                 .name                   = "pandora::power",
157                 .default_trigger        = "default-on",
158                 .gpio                   = -EINVAL,
159                 .active_low             = true,
160         }, {
161                 .name                   = "pandora::charger",
162                 .gpio                   = -EINVAL,
163         }, {
164                 .name                   = "pandora::sd1",
165                 .default_trigger        = "mmc0",
166                 .gpio                   = 128,
167         }, {
168                 .name                   = "pandora::sd2",
169                 .default_trigger        = "mmc1",
170                 .gpio                   = 129,
171         }, {
172                 .name                   = "pandora::bluetooth",
173                 .default_trigger        = "bluetooth",
174                 .gpio                   = 158,
175         }, {
176                 .name                   = "pandora::wifi",
177                 .gpio                   = 159,
178         },
179 };
180
181 static struct gpio_led_platform_data omap3pandora_gpio_led_data = {
182         .leds           = omap3pandora_gpio_leds,
183         .num_leds       = ARRAY_SIZE(omap3pandora_gpio_leds),
184 };
185
186 static struct platform_device omap3pandora_leds_gpio = {
187         .name   = "leds-gpio",
188         .id     = -1,
189         .dev    = {
190                 .platform_data  = &omap3pandora_gpio_led_data,
191         },
192 };
193
194 static struct platform_device omap3pandora_bl = {
195         .name   = "twl4030-pwm0-bl",
196         .id     = -1,
197 };
198
199 static int omap3pandora_twl_gpio_setup(struct device *dev,
200                 unsigned gpio, unsigned ngpio)
201 {
202         /* TWL4030_GPIO_MAX + 0 == ledA, KEYPAD_BACKLIGHT (out, active low) */
203         omap3pandora_gpio_leds[0].gpio = gpio + TWL4030_GPIO_MAX + 0;
204
205         /* TWL4030_GPIO_MAX + 1 == ledB, POWER_LED (out, active low) */
206         omap3pandora_gpio_leds[1].gpio = gpio + TWL4030_GPIO_MAX + 1;
207
208         /* gpio + 7 is PWM1, CHARGER_LED */
209         omap3pandora_gpio_leds[2].gpio = gpio + 7;
210
211         return 0;
212 }
213
214 static struct twl4030_gpio_platform_data omap3pandora_gpio_data = {
215         .gpio_base      = OMAP_MAX_GPIO_LINES,
216         .irq_base       = TWL4030_GPIO_IRQ_BASE,
217         .irq_end        = TWL4030_GPIO_IRQ_END,
218         .use_leds       = true,
219         .setup          = omap3pandora_twl_gpio_setup,
220 };
221
222 static struct twl4030_usb_data omap3pandora_usb_data = {
223         .usb_mode       = T2_USB_MODE_ULPI,
224 };
225
226 static struct twl4030_platform_data omap3pandora_twldata = {
227         .irq_base       = TWL4030_IRQ_BASE,
228         .irq_end        = TWL4030_IRQ_END,
229         .gpio           = &omap3pandora_gpio_data,
230         .usb            = &omap3pandora_usb_data,
231         .keypad         = &omap3pandora_kp_data,
232 };
233
234 static struct i2c_board_info __initdata omap3pandora_i2c_boardinfo[] = {
235         {
236                 I2C_BOARD_INFO("twl4030", 0x48),
237                 .flags = I2C_CLIENT_WAKE,
238                 .irq = INT_34XX_SYS_NIRQ,
239                 .platform_data = &omap3pandora_twldata,
240         },
241 };
242
243 static struct vsense_platform_data omap3pandora_nub1_data = {
244         .gpio_irq       = 161,
245         .gpio_reset     = 156,
246 };
247
248 static struct vsense_platform_data omap3pandora_nub2_data = {
249         .gpio_irq       = 162,
250         .gpio_reset     = 156,
251 };
252
253 static struct i2c_board_info __initdata omap3pandora_i2c_vsense[] = {
254         {
255                 I2C_BOARD_INFO("vsense", 0x66),
256                 .flags = I2C_CLIENT_WAKE,
257                 .platform_data = &omap3pandora_nub1_data,
258         }, {
259                 I2C_BOARD_INFO("vsense", 0x67),
260                 .flags = I2C_CLIENT_WAKE,
261                 .platform_data = &omap3pandora_nub2_data,
262         },
263 };
264
265 static int __init omap3pandora_i2c_init(void)
266 {
267         omap_register_i2c_bus(1, 2600, omap3pandora_i2c_boardinfo,
268                         ARRAY_SIZE(omap3pandora_i2c_boardinfo));
269         /* i2c2 pins are not connected */
270         omap_register_i2c_bus(3, 400, omap3pandora_i2c_vsense,
271                         ARRAY_SIZE(omap3pandora_i2c_vsense));
272         return 0;
273 }
274
275 static void __init omap3pandora_init_irq(void)
276 {
277         omap2_init_common_hw(mt46h32m32lf6_sdrc_params);
278         omap_init_irq();
279         omap_gpio_init();
280 }
281
282 static void __init omap3pandora_ads7846_init(void)
283 {
284         int gpio = OMAP3_PANDORA_TS_GPIO;
285         int ret;
286
287         ret = gpio_request(gpio, "ads7846_pen_down");
288         if (ret < 0) {
289                 printk(KERN_ERR "Failed to request GPIO %d for "
290                                 "ads7846 pen down IRQ\n", gpio);
291                 return;
292         }
293
294         gpio_direction_input(gpio);
295 }
296
297 static int ads7846_get_pendown_state(void)
298 {
299         return !omap_get_gpio_datain(OMAP3_PANDORA_TS_GPIO);
300 }
301
302 static struct ads7846_platform_data ads7846_config = {
303         .x_max                  = 0x0fff,
304         .y_max                  = 0x0fff,
305         .x_plate_ohms           = 180,
306         .pressure_max           = 255,
307         .debounce_max           = 10,
308         .debounce_tol           = 3,
309         .debounce_rep           = 1,
310         .get_pendown_state      = ads7846_get_pendown_state,
311         .keep_vref_on           = 1,
312 };
313
314 static struct omap2_mcspi_device_config ads7846_mcspi_config = {
315         .turbo_mode     = 0,
316         .single_channel = 1,  /* 0: slave, 1: master */
317 };
318
319 static struct spi_board_info omap3pandora_spi_board_info[] = {
320         {
321                 .modalias               = "ads7846",
322                 .bus_num                = 1,
323                 .chip_select            = 0,
324                 .max_speed_hz           = 1500000,
325                 .controller_data        = &ads7846_mcspi_config,
326                 .irq                    = OMAP_GPIO_IRQ(OMAP3_PANDORA_TS_GPIO),
327                 .platform_data          = &ads7846_config,
328         }, {
329                 .modalias               = "panel-tpo-td043mtea1",
330                 .bus_num                = 1,
331                 .chip_select            = 1,
332                 .max_speed_hz           = 375000,
333         }
334 };
335
336 static struct platform_device omap3pandora_lcd_device = {
337         .name           = "pandora_lcd",
338         .id             = -1,
339 };
340
341 static struct omap_lcd_config omap3pandora_lcd_config __initdata = {
342         .ctrl_name      = "internal",
343 };
344
345 static struct omap_board_config_kernel omap3pandora_config[] __initdata = {
346         { OMAP_TAG_UART,        &omap3pandora_uart_config },
347         { OMAP_TAG_LCD,         &omap3pandora_lcd_config },
348 };
349
350 /* DSS2 */
351 static int pandora_panel_enable_lcd(struct omap_display *display)
352 {
353 #define ENABLE_VAUX1_DEDICATED           0x04
354 #define ENABLE_VAUX1_DEV_GRP             0x20
355
356         twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
357                         ENABLE_VAUX1_DEDICATED,
358                         TWL4030_VAUX1_DEDICATED);
359         twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
360                         ENABLE_VAUX1_DEV_GRP, TWL4030_VAUX1_DEV_GRP);
361
362         return 0;
363 }
364
365 static void pandora_panel_disable_lcd(struct omap_display *display)
366 {
367         twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0x00,
368                         TWL4030_VAUX1_DEV_GRP);
369         twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0x00,
370                         TWL4030_VAUX1_DEDICATED);
371 }
372
373 static int pandora_panel_enable_tv(struct omap_display *display)
374 {
375 #define ENABLE_VDAC_DEDICATED           0x03
376 #define ENABLE_VDAC_DEV_GRP             0x20
377
378         twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
379                         ENABLE_VDAC_DEDICATED,
380                         TWL4030_VDAC_DEDICATED);
381         twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
382                         ENABLE_VDAC_DEV_GRP, TWL4030_VDAC_DEV_GRP);
383
384         return 0;
385 }
386
387 static void pandora_panel_disable_tv(struct omap_display *display)
388 {
389         twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0x00,
390                         TWL4030_VDAC_DEV_GRP);
391         twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0x00,
392                         TWL4030_VDAC_DEDICATED);
393 }
394
395 static struct omap_dss_display_config omap3pandora_display_data[] = {
396         {
397                 .type           = OMAP_DISPLAY_TYPE_DPI,
398                 .name           = "lcd",
399                 .panel_name     = "tpo-td043mtea1",
400                 .panel_reset_gpio = 157,
401                 .u.dpi.data_lines = 24,
402                 .panel_enable   = pandora_panel_enable_lcd,
403                 .panel_disable  = pandora_panel_disable_lcd,
404         }, {
405                 .type           = OMAP_DISPLAY_TYPE_VENC,
406                 .name           = "tv",
407                 .u.venc.type    = OMAP_DSS_VENC_TYPE_SVIDEO,
408                 .panel_enable   = pandora_panel_enable_tv,
409                 .panel_disable  = pandora_panel_disable_tv,
410         }
411 };
412
413 static struct omap_dss_board_info omap3pandora_dss_data = {
414         .num_displays = ARRAY_SIZE(omap3pandora_display_data),
415         .displays = {
416                 &omap3pandora_display_data[0],
417                 &omap3pandora_display_data[1],
418         }
419 };
420
421 static struct platform_device omap3pandora_dss_device = {
422         .name   = "omapdss",
423         .id     = -1,
424         .dev    = {
425                 .platform_data = &omap3pandora_dss_data,
426         },
427 };
428
429 #include <mach/board-nokia.h>
430
431 static struct omap_bluetooth_config bt_config = {
432         .chip_type              = BT_CHIP_TI,
433         .bt_wakeup_gpio         = -EINVAL,
434         .host_wakeup_gpio       = -EINVAL,
435         .reset_gpio             = 15,
436         .bt_uart                = 1,
437 //      .bd_addr[6],
438 //      .bt_sysclk,     /* unused? */
439 };
440
441 static struct platform_device bt_device = {
442         .name           = "hci_h4p",
443         .id             = -1,
444         .dev            = {
445                 .platform_data  = &bt_config,
446         },
447 };
448
449 static struct platform_device *omap3pandora_devices[] __initdata = {
450         &omap3pandora_lcd_device,
451         &omap3pandora_leds_gpio,
452         &bt_device,
453         &omap3pandora_bl,
454         &omap3pandora_dss_device,
455 };
456
457 static void __init omap3pandora_init(void)
458 {
459         omap3pandora_i2c_init();
460         omap3pandora_input_init();
461         platform_add_devices(omap3pandora_devices, ARRAY_SIZE(omap3pandora_devices));
462         omap_board_config = omap3pandora_config;
463         omap_board_config_size = ARRAY_SIZE(omap3pandora_config);
464         spi_register_board_info(omap3pandora_spi_board_info,
465                         ARRAY_SIZE(omap3pandora_spi_board_info));
466         omap_serial_init();
467         hsmmc_init();
468         usb_musb_init();
469         usb_ehci_init();
470         omap3pandora_flash_init();
471         omap3pandora_ads7846_init();
472 }
473
474 static void __init omap3pandora_map_io(void)
475 {
476         omap2_set_globals_343x();
477         omap2_map_common_io();
478 }
479
480 MACHINE_START(OMAP3_PANDORA, "Pandora Handheld Console")
481         .phys_io        = 0x48000000,
482         .io_pg_offst    = ((0xd8000000) >> 18) & 0xfffc,
483         .boot_params    = 0x80000100,
484         .map_io         = omap3pandora_map_io,
485         .init_irq       = omap3pandora_init_irq,
486         .init_machine   = omap3pandora_init,
487         .timer          = &omap_timer,
488 MACHINE_END