Merge branch 'devel' of git://git.kernel.org/pub/scm/linux/kernel/git/ycmiao/pxa...
[linux-2.6] / 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/mtd/mtd.h>
28 #include <linux/mtd/partitions.h>
29 #include <linux/mtd/nand.h>
30
31 #include <linux/i2c/twl4030.h>
32
33 #include <mach/hardware.h>
34 #include <asm/mach-types.h>
35 #include <asm/mach/arch.h>
36 #include <asm/mach/map.h>
37 #include <asm/mach/flash.h>
38
39 #include <mach/board.h>
40 #include <mach/common.h>
41 #include <mach/gpmc.h>
42 #include <mach/nand.h>
43 #include <mach/mux.h>
44
45 #include "mmc-twl4030.h"
46
47 #define GPMC_CS0_BASE  0x60
48 #define GPMC_CS_SIZE   0x30
49
50 #define NAND_BLOCK_SIZE         SZ_128K
51
52 static struct mtd_partition omap3beagle_nand_partitions[] = {
53         /* All the partition sizes are listed in terms of NAND block size */
54         {
55                 .name           = "X-Loader",
56                 .offset         = 0,
57                 .size           = 4 * NAND_BLOCK_SIZE,
58                 .mask_flags     = MTD_WRITEABLE,        /* force read-only */
59         },
60         {
61                 .name           = "U-Boot",
62                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x80000 */
63                 .size           = 15 * NAND_BLOCK_SIZE,
64                 .mask_flags     = MTD_WRITEABLE,        /* force read-only */
65         },
66         {
67                 .name           = "U-Boot Env",
68                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x260000 */
69                 .size           = 1 * NAND_BLOCK_SIZE,
70         },
71         {
72                 .name           = "Kernel",
73                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x280000 */
74                 .size           = 32 * NAND_BLOCK_SIZE,
75         },
76         {
77                 .name           = "File System",
78                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x680000 */
79                 .size           = MTDPART_SIZ_FULL,
80         },
81 };
82
83 static struct omap_nand_platform_data omap3beagle_nand_data = {
84         .options        = NAND_BUSWIDTH_16,
85         .parts          = omap3beagle_nand_partitions,
86         .nr_parts       = ARRAY_SIZE(omap3beagle_nand_partitions),
87         .dma_channel    = -1,           /* disable DMA in OMAP NAND driver */
88         .nand_setup     = NULL,
89         .dev_ready      = NULL,
90 };
91
92 static struct resource omap3beagle_nand_resource = {
93         .flags          = IORESOURCE_MEM,
94 };
95
96 static struct platform_device omap3beagle_nand_device = {
97         .name           = "omap2-nand",
98         .id             = -1,
99         .dev            = {
100                 .platform_data  = &omap3beagle_nand_data,
101         },
102         .num_resources  = 1,
103         .resource       = &omap3beagle_nand_resource,
104 };
105
106 static struct omap_uart_config omap3_beagle_uart_config __initdata = {
107         .enabled_uarts  = ((1 << 0) | (1 << 1) | (1 << 2)),
108 };
109
110 static struct twl4030_hsmmc_info mmc[] = {
111         {
112                 .mmc            = 1,
113                 .wires          = 8,
114                 .gpio_wp        = 29,
115         },
116         {}      /* Terminator */
117 };
118
119 static struct gpio_led gpio_leds[];
120
121 static int beagle_twl_gpio_setup(struct device *dev,
122                 unsigned gpio, unsigned ngpio)
123 {
124         /* gpio + 0 is "mmc0_cd" (input/IRQ) */
125         omap_cfg_reg(AH8_34XX_GPIO29);
126         mmc[0].gpio_cd = gpio + 0;
127         twl4030_mmc_init(mmc);
128
129         /* REVISIT: need ehci-omap hooks for external VBUS
130          * power switch and overcurrent detect
131          */
132
133         gpio_request(gpio + 1, "EHCI_nOC");
134         gpio_direction_input(gpio + 1);
135
136         /* TWL4030_GPIO_MAX + 0 == ledA, EHCI nEN_USB_PWR (out, active low) */
137         gpio_request(gpio + TWL4030_GPIO_MAX, "nEN_USB_PWR");
138         gpio_direction_output(gpio + TWL4030_GPIO_MAX, 1);
139
140         /* TWL4030_GPIO_MAX + 1 == ledB, PMU_STAT (out, active low LED) */
141         gpio_leds[2].gpio = gpio + TWL4030_GPIO_MAX + 1;
142
143         return 0;
144 }
145
146 static struct twl4030_gpio_platform_data beagle_gpio_data = {
147         .gpio_base      = OMAP_MAX_GPIO_LINES,
148         .irq_base       = TWL4030_GPIO_IRQ_BASE,
149         .irq_end        = TWL4030_GPIO_IRQ_END,
150         .use_leds       = true,
151         .pullups        = BIT(1),
152         .pulldowns      = BIT(2) | BIT(6) | BIT(7) | BIT(8) | BIT(13)
153                                 | BIT(15) | BIT(16) | BIT(17),
154         .setup          = beagle_twl_gpio_setup,
155 };
156
157 static struct twl4030_platform_data beagle_twldata = {
158         .irq_base       = TWL4030_IRQ_BASE,
159         .irq_end        = TWL4030_IRQ_END,
160
161         /* platform_data for children goes here */
162         .gpio           = &beagle_gpio_data,
163 };
164
165 static struct i2c_board_info __initdata beagle_i2c_boardinfo[] = {
166         {
167                 I2C_BOARD_INFO("twl4030", 0x48),
168                 .flags = I2C_CLIENT_WAKE,
169                 .irq = INT_34XX_SYS_NIRQ,
170                 .platform_data = &beagle_twldata,
171         },
172 };
173
174 static int __init omap3_beagle_i2c_init(void)
175 {
176         omap_register_i2c_bus(1, 2600, beagle_i2c_boardinfo,
177                         ARRAY_SIZE(beagle_i2c_boardinfo));
178 #ifdef CONFIG_I2C2_OMAP_BEAGLE
179         omap_register_i2c_bus(2, 400, NULL, 0);
180 #endif
181         /* Bus 3 is attached to the DVI port where devices like the pico DLP
182          * projector don't work reliably with 400kHz */
183         omap_register_i2c_bus(3, 100, NULL, 0);
184         return 0;
185 }
186
187 static void __init omap3_beagle_init_irq(void)
188 {
189         omap2_init_common_hw(NULL);
190         omap_init_irq();
191         omap_gpio_init();
192 }
193
194 static struct platform_device omap3_beagle_lcd_device = {
195         .name           = "omap3beagle_lcd",
196         .id             = -1,
197 };
198
199 static struct omap_lcd_config omap3_beagle_lcd_config __initdata = {
200         .ctrl_name      = "internal",
201 };
202
203 static struct gpio_led gpio_leds[] = {
204         {
205                 .name                   = "beagleboard::usr0",
206                 .default_trigger        = "heartbeat",
207                 .gpio                   = 150,
208         },
209         {
210                 .name                   = "beagleboard::usr1",
211                 .default_trigger        = "mmc0",
212                 .gpio                   = 149,
213         },
214         {
215                 .name                   = "beagleboard::pmu_stat",
216                 .gpio                   = -EINVAL,      /* gets replaced */
217                 .active_low             = true,
218         },
219 };
220
221 static struct gpio_led_platform_data gpio_led_info = {
222         .leds           = gpio_leds,
223         .num_leds       = ARRAY_SIZE(gpio_leds),
224 };
225
226 static struct platform_device leds_gpio = {
227         .name   = "leds-gpio",
228         .id     = -1,
229         .dev    = {
230                 .platform_data  = &gpio_led_info,
231         },
232 };
233
234 static struct gpio_keys_button gpio_buttons[] = {
235         {
236                 .code                   = BTN_EXTRA,
237                 .gpio                   = 7,
238                 .desc                   = "user",
239                 .wakeup                 = 1,
240         },
241 };
242
243 static struct gpio_keys_platform_data gpio_key_info = {
244         .buttons        = gpio_buttons,
245         .nbuttons       = ARRAY_SIZE(gpio_buttons),
246 };
247
248 static struct platform_device keys_gpio = {
249         .name   = "gpio-keys",
250         .id     = -1,
251         .dev    = {
252                 .platform_data  = &gpio_key_info,
253         },
254 };
255
256 static struct omap_board_config_kernel omap3_beagle_config[] __initdata = {
257         { OMAP_TAG_UART,        &omap3_beagle_uart_config },
258         { OMAP_TAG_LCD,         &omap3_beagle_lcd_config },
259 };
260
261 static struct platform_device *omap3_beagle_devices[] __initdata = {
262         &omap3_beagle_lcd_device,
263         &leds_gpio,
264         &keys_gpio,
265 };
266
267 static void __init omap3beagle_flash_init(void)
268 {
269         u8 cs = 0;
270         u8 nandcs = GPMC_CS_NUM + 1;
271
272         u32 gpmc_base_add = OMAP34XX_GPMC_VIRT;
273
274         /* find out the chip-select on which NAND exists */
275         while (cs < GPMC_CS_NUM) {
276                 u32 ret = 0;
277                 ret = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1);
278
279                 if ((ret & 0xC00) == 0x800) {
280                         printk(KERN_INFO "Found NAND on CS%d\n", cs);
281                         if (nandcs > GPMC_CS_NUM)
282                                 nandcs = cs;
283                 }
284                 cs++;
285         }
286
287         if (nandcs > GPMC_CS_NUM) {
288                 printk(KERN_INFO "NAND: Unable to find configuration "
289                                  "in GPMC\n ");
290                 return;
291         }
292
293         if (nandcs < GPMC_CS_NUM) {
294                 omap3beagle_nand_data.cs = nandcs;
295                 omap3beagle_nand_data.gpmc_cs_baseaddr = (void *)
296                         (gpmc_base_add + GPMC_CS0_BASE + nandcs * GPMC_CS_SIZE);
297                 omap3beagle_nand_data.gpmc_baseaddr = (void *) (gpmc_base_add);
298
299                 printk(KERN_INFO "Registering NAND on CS%d\n", nandcs);
300                 if (platform_device_register(&omap3beagle_nand_device) < 0)
301                         printk(KERN_ERR "Unable to register NAND device\n");
302         }
303 }
304
305 static void __init omap3_beagle_init(void)
306 {
307         omap3_beagle_i2c_init();
308         platform_add_devices(omap3_beagle_devices,
309                         ARRAY_SIZE(omap3_beagle_devices));
310         omap_board_config = omap3_beagle_config;
311         omap_board_config_size = ARRAY_SIZE(omap3_beagle_config);
312         omap_serial_init();
313
314         omap_cfg_reg(J25_34XX_GPIO170);
315         gpio_request(170, "DVI_nPD");
316         /* REVISIT leave DVI powered down until it's needed ... */
317         gpio_direction_output(170, true);
318
319         omap3beagle_flash_init();
320 }
321
322 static void __init omap3_beagle_map_io(void)
323 {
324         omap2_set_globals_343x();
325         omap2_map_common_io();
326 }
327
328 MACHINE_START(OMAP3_BEAGLE, "OMAP3 Beagle Board")
329         /* Maintainer: Syed Mohammed Khasim - http://beagleboard.org */
330         .phys_io        = 0x48000000,
331         .io_pg_offst    = ((0xd8000000) >> 18) & 0xfffc,
332         .boot_params    = 0x80000100,
333         .map_io         = omap3_beagle_map_io,
334         .init_irq       = omap3_beagle_init_irq,
335         .init_machine   = omap3_beagle_init,
336         .timer          = &omap_timer,
337 MACHINE_END