b874d3b72fd5d8bc02e6267f33f05b742a8b3d27
[pandora-kernel.git] / arch / arm / mach-omap2 / board-omap3beagle.c
1 /*
2  * linux/arch/arm/mach-omap2/board-omap3beagle.c
3  *
4  * Copyright (C) 2008 Texas Instruments
5  *
6  * Modified from mach-omap2/board-3430sdp.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/i2c/twl4030.h>
28 #include <linux/omapfb.h>
29
30 #include <linux/mtd/mtd.h>
31 #include <linux/mtd/partitions.h>
32 #include <linux/mtd/nand.h>
33
34 #include <mach/hardware.h>
35 #include <asm/mach-types.h>
36 #include <asm/mach/arch.h>
37 #include <asm/mach/map.h>
38 #include <asm/mach/flash.h>
39
40 #include <mach/board.h>
41 #include <mach/usb-musb.h>
42 #include <mach/usb-ehci.h>
43 #include <mach/hsmmc.h>
44 #include <mach/common.h>
45 #include <mach/gpmc.h>
46 #include <mach/nand.h>
47 #include <mach/mux.h>
48 #include <mach/display.h>
49
50
51 #define GPMC_CS0_BASE  0x60
52 #define GPMC_CS_SIZE   0x30
53
54 #define NAND_BLOCK_SIZE         SZ_128K
55
56 static struct mtd_partition omap3beagle_nand_partitions[] = {
57         /* All the partition sizes are listed in terms of NAND block size */
58         {
59                 .name           = "X-Loader",
60                 .offset         = 0,
61                 .size           = 4 * NAND_BLOCK_SIZE,
62                 .mask_flags     = MTD_WRITEABLE,        /* force read-only */
63         },
64         {
65                 .name           = "U-Boot",
66                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x80000 */
67                 .size           = 15 * NAND_BLOCK_SIZE,
68                 .mask_flags     = MTD_WRITEABLE,        /* force read-only */
69         },
70         {
71                 .name           = "U-Boot Env",
72                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x260000 */
73                 .size           = 1 * NAND_BLOCK_SIZE,
74         },
75         {
76                 .name           = "Kernel",
77                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x280000 */
78                 .size           = 32 * NAND_BLOCK_SIZE,
79         },
80         {
81                 .name           = "File System",
82                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x680000 */
83                 .size           = MTDPART_SIZ_FULL,
84         },
85 };
86
87 static struct omap_nand_platform_data omap3beagle_nand_data = {
88         .options        = NAND_BUSWIDTH_16,
89         .parts          = omap3beagle_nand_partitions,
90         .nr_parts       = ARRAY_SIZE(omap3beagle_nand_partitions),
91         .dma_channel    = -1,           /* disable DMA in OMAP NAND driver */
92         .nand_setup     = NULL,
93         .dev_ready      = NULL,
94 };
95
96 static struct resource omap3beagle_nand_resource = {
97         .flags          = IORESOURCE_MEM,
98 };
99
100 static struct platform_device omap3beagle_nand_device = {
101         .name           = "omap2-nand",
102         .id             = -1,
103         .dev            = {
104                 .platform_data  = &omap3beagle_nand_data,
105         },
106         .num_resources  = 1,
107         .resource       = &omap3beagle_nand_resource,
108 };
109
110 #include "sdram-micron-mt46h32m32lf-6.h"
111
112 static struct omap_uart_config omap3_beagle_uart_config __initdata = {
113         .enabled_uarts  = ((1 << 0) | (1 << 1) | (1 << 2)),
114 };
115
116 static struct twl4030_usb_data beagle_usb_data = {
117         .usb_mode       = T2_USB_MODE_ULPI,
118 };
119
120 static struct gpio_led gpio_leds[];
121
122 static int beagle_twl_gpio_setup(struct device *dev,
123                 unsigned gpio, unsigned ngpio)
124 {
125         /* gpio + 0 is "mmc0_cd" (input/IRQ) */
126
127         /* REVISIT: need ehci-omap hooks for external VBUS
128          * power switch and overcurrent detect
129          */
130
131         gpio_request(gpio + 1, "EHCI_nOC");
132         gpio_direction_input(gpio + 1);
133
134         /* TWL4030_GPIO_MAX + 0 == ledA, EHCI nEN_USB_PWR (out, active low) */
135         gpio_request(gpio + TWL4030_GPIO_MAX, "nEN_USB_PWR");
136         gpio_direction_output(gpio + TWL4030_GPIO_MAX, 1);
137
138         /* TWL4030_GPIO_MAX + 1 == ledB, PMU_STAT (out, active low LED) */
139         gpio_leds[2].gpio = gpio + TWL4030_GPIO_MAX + 1;
140
141         return 0;
142 }
143
144 static struct twl4030_gpio_platform_data beagle_gpio_data = {
145         .gpio_base      = OMAP_MAX_GPIO_LINES,
146         .irq_base       = TWL4030_GPIO_IRQ_BASE,
147         .irq_end        = TWL4030_GPIO_IRQ_END,
148         .use_leds       = true,
149         .pullups        = BIT(1),
150         .pulldowns      = BIT(2) | BIT(6) | BIT(7) | BIT(8) | BIT(13)
151                                 | BIT(15) | BIT(16) | BIT(17),
152         .setup          = beagle_twl_gpio_setup,
153 };
154
155 static struct twl4030_platform_data beagle_twldata = {
156         .irq_base       = TWL4030_IRQ_BASE,
157         .irq_end        = TWL4030_IRQ_END,
158
159         /* platform_data for children goes here */
160         .usb            = &beagle_usb_data,
161         .gpio           = &beagle_gpio_data,
162 };
163
164 static struct i2c_board_info __initdata beagle_i2c_boardinfo[] = {
165         {
166                 I2C_BOARD_INFO("twl4030", 0x48),
167                 .flags = I2C_CLIENT_WAKE,
168                 .irq = INT_34XX_SYS_NIRQ,
169                 .platform_data = &beagle_twldata,
170         },
171 };
172
173 static int __init omap3_beagle_i2c_init(void)
174 {
175         omap_register_i2c_bus(1, 2600, beagle_i2c_boardinfo,
176                         ARRAY_SIZE(beagle_i2c_boardinfo));
177 #ifdef CONFIG_I2C2_OMAP_BEAGLE
178         omap_register_i2c_bus(2, 400, NULL, 0);
179 #endif
180         omap_register_i2c_bus(3, 400, NULL, 0);
181         return 0;
182 }
183
184 static void __init omap3_beagle_init_irq(void)
185 {
186         omap2_init_common_hw(mt46h32m32lf6_sdrc_params);
187         omap_init_irq();
188         omap_gpio_init();
189 }
190
191 static struct platform_device omap3_beagle_lcd_device = {
192         .name           = "omap3beagle_lcd",
193         .id             = -1,
194 };
195
196 static struct gpio_led gpio_leds[] = {
197         {
198                 .name                   = "beagleboard::usr0",
199                 .default_trigger        = "heartbeat",
200                 .gpio                   = 150,
201         },
202         {
203                 .name                   = "beagleboard::usr1",
204                 .default_trigger        = "mmc0",
205                 .gpio                   = 149,
206         },
207         {
208                 .name                   = "beagleboard::pmu_stat",
209                 .gpio                   = -EINVAL,      /* gets replaced */
210                 .active_low             = true,
211         },
212 };
213
214 static struct gpio_led_platform_data gpio_led_info = {
215         .leds           = gpio_leds,
216         .num_leds       = ARRAY_SIZE(gpio_leds),
217 };
218
219 static struct platform_device leds_gpio = {
220         .name   = "leds-gpio",
221         .id     = -1,
222         .dev    = {
223                 .platform_data  = &gpio_led_info,
224         },
225 };
226
227 static struct gpio_keys_button gpio_buttons[] = {
228         {
229                 .code                   = BTN_EXTRA,
230                 .gpio                   = 7,
231                 .desc                   = "user",
232                 .wakeup                 = 1,
233         },
234 };
235
236 static struct gpio_keys_platform_data gpio_key_info = {
237         .buttons        = gpio_buttons,
238         .nbuttons       = ARRAY_SIZE(gpio_buttons),
239 };
240
241 static struct platform_device keys_gpio = {
242         .name   = "gpio-keys",
243         .id     = -1,
244         .dev    = {
245                 .platform_data  = &gpio_key_info,
246         },
247 };
248
249 /* DSS */
250
251 static int beagle_enable_dvi(struct omap_display *display)
252 {
253         if (display->hw_config.panel_reset_gpio != -1)
254                 gpio_direction_output(display->hw_config.panel_reset_gpio, 1);
255
256         return 0;
257 }
258
259 static void beagle_disable_dvi(struct omap_display *display)
260 {
261         if (display->hw_config.panel_reset_gpio != -1)
262                 gpio_direction_output(display->hw_config.panel_reset_gpio, 0);
263 }
264
265 static struct omap_dss_display_config beagle_display_data_dvi = {
266         .type = OMAP_DISPLAY_TYPE_DPI,
267         .name = "dvi",
268         .panel_name = "panel-generic",
269         .u.dpi.data_lines = 24,
270         .panel_reset_gpio = 170,
271         .panel_enable = beagle_enable_dvi,
272         .panel_disable = beagle_disable_dvi,
273 };
274
275
276 static int beagle_panel_enable_tv(struct omap_display *display)
277 {
278 #define ENABLE_VDAC_DEDICATED           0x03
279 #define ENABLE_VDAC_DEV_GRP             0x20
280
281         twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
282                         ENABLE_VDAC_DEDICATED,
283                         TWL4030_VDAC_DEDICATED);
284         twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
285                         ENABLE_VDAC_DEV_GRP, TWL4030_VDAC_DEV_GRP);
286
287         return 0;
288 }
289
290 static void beagle_panel_disable_tv(struct omap_display *display)
291 {
292         twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0x00,
293                         TWL4030_VDAC_DEDICATED);
294         twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0x00,
295                         TWL4030_VDAC_DEV_GRP);
296 }
297
298 static struct omap_dss_display_config beagle_display_data_tv = {
299         .type = OMAP_DISPLAY_TYPE_VENC,
300         .name = "tv",
301         .u.venc.type = OMAP_DSS_VENC_TYPE_SVIDEO,
302         .panel_enable = beagle_panel_enable_tv,
303         .panel_disable = beagle_panel_disable_tv,
304 };
305
306 static struct omap_dss_board_info beagle_dss_data = {
307         .num_displays = 2,
308         .displays = {
309                 &beagle_display_data_dvi,
310                 &beagle_display_data_tv,
311         }
312 };
313
314 static struct platform_device beagle_dss_device = {
315         .name          = "omapdss",
316         .id            = -1,
317         .dev            = {
318                 .platform_data = &beagle_dss_data,
319         },
320 };
321
322 static void __init beagle_display_init(void)
323 {
324         int r;
325
326         r = gpio_request(beagle_display_data_dvi.panel_reset_gpio, "DVI reset");
327         if (r < 0)
328                 printk(KERN_ERR "Unable to get DVI reset GPIO\n");
329 }
330
331 static struct omap_board_config_kernel omap3_beagle_config[] __initdata = {
332         { OMAP_TAG_UART,        &omap3_beagle_uart_config },
333 };
334
335 static struct platform_device *omap3_beagle_devices[] __initdata = {
336         &beagle_dss_device,
337         &leds_gpio,
338         &keys_gpio,
339 };
340
341 static void __init omap3beagle_flash_init(void)
342 {
343         u8 cs = 0;
344         u8 nandcs = GPMC_CS_NUM + 1;
345
346         u32 gpmc_base_add = OMAP34XX_GPMC_VIRT;
347
348         /* find out the chip-select on which NAND exists */
349         while (cs < GPMC_CS_NUM) {
350                 u32 ret = 0;
351                 ret = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1);
352
353                 if ((ret & 0xC00) == 0x800) {
354                         printk(KERN_INFO "Found NAND on CS%d\n", cs);
355                         if (nandcs > GPMC_CS_NUM)
356                                 nandcs = cs;
357                 }
358                 cs++;
359         }
360
361         if (nandcs > GPMC_CS_NUM) {
362                 printk(KERN_INFO "NAND: Unable to find configuration "
363                                  "in GPMC\n ");
364                 return;
365         }
366
367         if (nandcs < GPMC_CS_NUM) {
368                 omap3beagle_nand_data.cs = nandcs;
369                 omap3beagle_nand_data.gpmc_cs_baseaddr = (void *)
370                         (gpmc_base_add + GPMC_CS0_BASE + nandcs * GPMC_CS_SIZE);
371                 omap3beagle_nand_data.gpmc_baseaddr = (void *) (gpmc_base_add);
372
373                 printk(KERN_INFO "Registering NAND on CS%d\n", nandcs);
374                 if (platform_device_register(&omap3beagle_nand_device) < 0)
375                         printk(KERN_ERR "Unable to register NAND device\n");
376         }
377 }
378
379 static void __init omap3_beagle_init(void)
380 {
381         omap3_beagle_i2c_init();
382         platform_add_devices(omap3_beagle_devices,
383                         ARRAY_SIZE(omap3_beagle_devices));
384         omap_board_config = omap3_beagle_config;
385         omap_board_config_size = ARRAY_SIZE(omap3_beagle_config);
386         omap_serial_init();
387
388         omap_cfg_reg(AH8_34XX_GPIO29);
389         gpio_request(29, "mmc0_wp");
390         gpio_direction_input(29);
391         hsmmc_init();
392
393         omap_cfg_reg(J25_34XX_GPIO170);
394
395         usb_musb_init();
396         usb_ehci_init();
397         omap3beagle_flash_init();
398         beagle_display_init();
399 }
400
401 static void __init omap3_beagle_map_io(void)
402 {
403         omap2_set_globals_343x();
404         omap2_map_common_io();
405 }
406
407 MACHINE_START(OMAP3_BEAGLE, "OMAP3 Beagle Board")
408         /* Maintainer: Syed Mohammed Khasim - http://beagleboard.org */
409         .phys_io        = 0x48000000,
410         .io_pg_offst    = ((0xd8000000) >> 18) & 0xfffc,
411         .boot_params    = 0x80000100,
412         .map_io         = omap3_beagle_map_io,
413         .init_irq       = omap3_beagle_init_irq,
414         .init_machine   = omap3_beagle_init,
415         .timer          = &omap_timer,
416 MACHINE_END