0c3f396328bd45681899cffa5e9b9f0ea915f345
[pandora-kernel.git] / arch / arm / mach-omap1 / board-fsample.c
1 /*
2  * linux/arch/arm/mach-omap1/board-fsample.c
3  *
4  * Modified from board-perseus2.c
5  *
6  * Original OMAP730 support by Jean Pihet <j-pihet@ti.com>
7  * Updated for 2.6 by Kevin Hilman <kjh@hilman.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2 as
11  * published by the Free Software Foundation.
12  */
13
14 #include <linux/kernel.h>
15 #include <linux/init.h>
16 #include <linux/platform_device.h>
17 #include <linux/delay.h>
18 #include <linux/mtd/mtd.h>
19 #include <linux/mtd/nand.h>
20 #include <linux/mtd/partitions.h>
21 #include <linux/mtd/physmap.h>
22 #include <linux/input.h>
23 #include <linux/smc91x.h>
24
25 #include <mach/hardware.h>
26 #include <asm/mach-types.h>
27 #include <asm/mach/arch.h>
28 #include <asm/mach/map.h>
29
30 #include <plat/tc.h>
31 #include <mach/gpio.h>
32 #include <plat/mux.h>
33 #include <plat/flash.h>
34 #include <plat/fpga.h>
35 #include <plat/keypad.h>
36 #include <plat/common.h>
37 #include <plat/board.h>
38
39 /* fsample is pretty close to p2-sample */
40
41 #define fsample_cpld_read(reg) __raw_readb(reg)
42 #define fsample_cpld_write(val, reg) __raw_writeb(val, reg)
43
44 #define FSAMPLE_CPLD_BASE    0xE8100000
45 #define FSAMPLE_CPLD_SIZE    SZ_4K
46 #define FSAMPLE_CPLD_START   0x05080000
47
48 #define FSAMPLE_CPLD_REG_A   (FSAMPLE_CPLD_BASE + 0x00)
49 #define FSAMPLE_CPLD_SWITCH  (FSAMPLE_CPLD_BASE + 0x02)
50 #define FSAMPLE_CPLD_UART    (FSAMPLE_CPLD_BASE + 0x02)
51 #define FSAMPLE_CPLD_REG_B   (FSAMPLE_CPLD_BASE + 0x04)
52 #define FSAMPLE_CPLD_VERSION (FSAMPLE_CPLD_BASE + 0x06)
53 #define FSAMPLE_CPLD_SET_CLR (FSAMPLE_CPLD_BASE + 0x06)
54
55 #define FSAMPLE_CPLD_BIT_BT_RESET         0
56 #define FSAMPLE_CPLD_BIT_LCD_RESET        1
57 #define FSAMPLE_CPLD_BIT_CAM_PWDN         2
58 #define FSAMPLE_CPLD_BIT_CHARGER_ENABLE   3
59 #define FSAMPLE_CPLD_BIT_SD_MMC_EN        4
60 #define FSAMPLE_CPLD_BIT_aGPS_PWREN       5
61 #define FSAMPLE_CPLD_BIT_BACKLIGHT        6
62 #define FSAMPLE_CPLD_BIT_aGPS_EN_RESET    7
63 #define FSAMPLE_CPLD_BIT_aGPS_SLEEPx_N    8
64 #define FSAMPLE_CPLD_BIT_OTG_RESET        9
65
66 #define fsample_cpld_set(bit) \
67     fsample_cpld_write((((bit) & 15) << 4) | 0x0f, FSAMPLE_CPLD_SET_CLR)
68
69 #define fsample_cpld_clear(bit) \
70     fsample_cpld_write(0xf0 | ((bit) & 15), FSAMPLE_CPLD_SET_CLR)
71
72 static int fsample_keymap[] = {
73         KEY(0,0,KEY_UP),
74         KEY(0,1,KEY_RIGHT),
75         KEY(0,2,KEY_LEFT),
76         KEY(0,3,KEY_DOWN),
77         KEY(0,4,KEY_ENTER),
78         KEY(1,0,KEY_F10),
79         KEY(1,1,KEY_SEND),
80         KEY(1,2,KEY_END),
81         KEY(1,3,KEY_VOLUMEDOWN),
82         KEY(1,4,KEY_VOLUMEUP),
83         KEY(1,5,KEY_RECORD),
84         KEY(2,0,KEY_F9),
85         KEY(2,1,KEY_3),
86         KEY(2,2,KEY_6),
87         KEY(2,3,KEY_9),
88         KEY(2,4,KEY_KPDOT),
89         KEY(3,0,KEY_BACK),
90         KEY(3,1,KEY_2),
91         KEY(3,2,KEY_5),
92         KEY(3,3,KEY_8),
93         KEY(3,4,KEY_0),
94         KEY(3,5,KEY_KPSLASH),
95         KEY(4,0,KEY_HOME),
96         KEY(4,1,KEY_1),
97         KEY(4,2,KEY_4),
98         KEY(4,3,KEY_7),
99         KEY(4,4,KEY_KPASTERISK),
100         KEY(4,5,KEY_POWER),
101         0
102 };
103
104 static struct smc91x_platdata smc91x_info = {
105         .flags  = SMC91X_USE_16BIT | SMC91X_NOWAIT,
106         .leda   = RPC_LED_100_10,
107         .ledb   = RPC_LED_TX_RX,
108 };
109
110 static struct resource smc91x_resources[] = {
111         [0] = {
112                 .start  = H2P2_DBG_FPGA_ETHR_START,     /* Physical */
113                 .end    = H2P2_DBG_FPGA_ETHR_START + 0xf,
114                 .flags  = IORESOURCE_MEM,
115         },
116         [1] = {
117                 .start  = INT_7XX_MPU_EXT_NIRQ,
118                 .end    = 0,
119                 .flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
120         },
121 };
122
123 static void __init fsample_init_smc91x(void)
124 {
125         fpga_write(1, H2P2_DBG_FPGA_LAN_RESET);
126         mdelay(50);
127         fpga_write(fpga_read(H2P2_DBG_FPGA_LAN_RESET) & ~1,
128                    H2P2_DBG_FPGA_LAN_RESET);
129         mdelay(50);
130 }
131
132 static struct mtd_partition nor_partitions[] = {
133         /* bootloader (U-Boot, etc) in first sector */
134         {
135               .name             = "bootloader",
136               .offset           = 0,
137               .size             = SZ_128K,
138               .mask_flags       = MTD_WRITEABLE, /* force read-only */
139         },
140         /* bootloader params in the next sector */
141         {
142               .name             = "params",
143               .offset           = MTDPART_OFS_APPEND,
144               .size             = SZ_128K,
145               .mask_flags       = 0,
146         },
147         /* kernel */
148         {
149               .name             = "kernel",
150               .offset           = MTDPART_OFS_APPEND,
151               .size             = SZ_2M,
152               .mask_flags       = 0
153         },
154         /* rest of flash is a file system */
155         {
156               .name             = "rootfs",
157               .offset           = MTDPART_OFS_APPEND,
158               .size             = MTDPART_SIZ_FULL,
159               .mask_flags       = 0
160         },
161 };
162
163 static struct physmap_flash_data nor_data = {
164         .width          = 2,
165         .set_vpp        = omap1_set_vpp,
166         .parts          = nor_partitions,
167         .nr_parts       = ARRAY_SIZE(nor_partitions),
168 };
169
170 static struct resource nor_resource = {
171         .start          = OMAP_CS0_PHYS,
172         .end            = OMAP_CS0_PHYS + SZ_32M - 1,
173         .flags          = IORESOURCE_MEM,
174 };
175
176 static struct platform_device nor_device = {
177         .name           = "physmap-flash",
178         .id             = 0,
179         .dev            = {
180                 .platform_data  = &nor_data,
181         },
182         .num_resources  = 1,
183         .resource       = &nor_resource,
184 };
185
186 static void nand_cmd_ctl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
187 {
188         struct nand_chip *this = mtd->priv;
189         unsigned long mask;
190
191         if (cmd == NAND_CMD_NONE)
192                 return;
193
194         mask = (ctrl & NAND_CLE) ? 0x02 : 0;
195         if (ctrl & NAND_ALE)
196                 mask |= 0x04;
197         writeb(cmd, (unsigned long)this->IO_ADDR_W | mask);
198 }
199
200 #define FSAMPLE_NAND_RB_GPIO_PIN        62
201
202 static int nand_dev_ready(struct mtd_info *mtd)
203 {
204         return gpio_get_value(FSAMPLE_NAND_RB_GPIO_PIN);
205 }
206
207 static const char *part_probes[] = { "cmdlinepart", NULL };
208
209 static struct platform_nand_data nand_data = {
210         .chip   = {
211                 .nr_chips               = 1,
212                 .chip_offset            = 0,
213                 .options                = NAND_SAMSUNG_LP_OPTIONS,
214                 .part_probe_types       = part_probes,
215         },
216         .ctrl   = {
217                 .cmd_ctrl       = nand_cmd_ctl,
218                 .dev_ready      = nand_dev_ready,
219         },
220 };
221
222 static struct resource nand_resource = {
223         .start          = OMAP_CS3_PHYS,
224         .end            = OMAP_CS3_PHYS + SZ_4K - 1,
225         .flags          = IORESOURCE_MEM,
226 };
227
228 static struct platform_device nand_device = {
229         .name           = "gen_nand",
230         .id             = 0,
231         .dev            = {
232                 .platform_data  = &nand_data,
233         },
234         .num_resources  = 1,
235         .resource       = &nand_resource,
236 };
237
238 static struct platform_device smc91x_device = {
239         .name           = "smc91x",
240         .id             = 0,
241         .dev    = {
242                 .platform_data  = &smc91x_info,
243         },
244         .num_resources  = ARRAY_SIZE(smc91x_resources),
245         .resource       = smc91x_resources,
246 };
247
248 static struct resource kp_resources[] = {
249         [0] = {
250                 .start  = INT_7XX_MPUIO_KEYPAD,
251                 .end    = INT_7XX_MPUIO_KEYPAD,
252                 .flags  = IORESOURCE_IRQ,
253         },
254 };
255
256 static struct omap_kp_platform_data kp_data = {
257         .rows           = 8,
258         .cols           = 8,
259         .keymap         = fsample_keymap,
260         .keymapsize     = ARRAY_SIZE(fsample_keymap),
261         .delay          = 4,
262 };
263
264 static struct platform_device kp_device = {
265         .name           = "omap-keypad",
266         .id             = -1,
267         .dev            = {
268                 .platform_data = &kp_data,
269         },
270         .num_resources  = ARRAY_SIZE(kp_resources),
271         .resource       = kp_resources,
272 };
273
274 static struct platform_device lcd_device = {
275         .name           = "lcd_p2",
276         .id             = -1,
277 };
278
279 static struct platform_device *devices[] __initdata = {
280         &nor_device,
281         &nand_device,
282         &smc91x_device,
283         &kp_device,
284         &lcd_device,
285 };
286
287 static struct omap_lcd_config fsample_lcd_config __initdata = {
288         .ctrl_name      = "internal",
289 };
290
291 static struct omap_board_config_kernel fsample_config[] = {
292         { OMAP_TAG_LCD,         &fsample_lcd_config },
293 };
294
295 static void __init omap_fsample_init(void)
296 {
297         fsample_init_smc91x();
298
299         if (gpio_request(FSAMPLE_NAND_RB_GPIO_PIN, "NAND ready") < 0)
300                 BUG();
301         gpio_direction_input(FSAMPLE_NAND_RB_GPIO_PIN);
302
303         omap_cfg_reg(L3_1610_FLASH_CS2B_OE);
304         omap_cfg_reg(M8_1610_FLASH_CS2B_WE);
305
306         /* Mux pins for keypad */
307         omap_cfg_reg(E2_7XX_KBR0);
308         omap_cfg_reg(J7_7XX_KBR1);
309         omap_cfg_reg(E1_7XX_KBR2);
310         omap_cfg_reg(F3_7XX_KBR3);
311         omap_cfg_reg(D2_7XX_KBR4);
312         omap_cfg_reg(C2_7XX_KBC0);
313         omap_cfg_reg(D3_7XX_KBC1);
314         omap_cfg_reg(E4_7XX_KBC2);
315         omap_cfg_reg(F4_7XX_KBC3);
316         omap_cfg_reg(E3_7XX_KBC4);
317
318         platform_add_devices(devices, ARRAY_SIZE(devices));
319
320         omap_board_config = fsample_config;
321         omap_board_config_size = ARRAY_SIZE(fsample_config);
322         omap_serial_init();
323         omap_register_i2c_bus(1, 100, NULL, 0);
324 }
325
326 static void __init omap_fsample_init_irq(void)
327 {
328         omap1_init_common_hw();
329         omap_init_irq();
330 }
331
332 /* Only FPGA needs to be mapped here. All others are done with ioremap */
333 static struct map_desc omap_fsample_io_desc[] __initdata = {
334         {
335                 .virtual        = H2P2_DBG_FPGA_BASE,
336                 .pfn            = __phys_to_pfn(H2P2_DBG_FPGA_START),
337                 .length         = H2P2_DBG_FPGA_SIZE,
338                 .type           = MT_DEVICE
339         },
340         {
341                 .virtual        = FSAMPLE_CPLD_BASE,
342                 .pfn            = __phys_to_pfn(FSAMPLE_CPLD_START),
343                 .length         = FSAMPLE_CPLD_SIZE,
344                 .type           = MT_DEVICE
345         }
346 };
347
348 static void __init omap_fsample_map_io(void)
349 {
350         omap1_map_common_io();
351         iotable_init(omap_fsample_io_desc,
352                      ARRAY_SIZE(omap_fsample_io_desc));
353
354         /* Early, board-dependent init */
355
356         /*
357          * Hold GSM Reset until needed
358          */
359         omap_writew(omap_readw(OMAP7XX_DSP_M_CTL) & ~1, OMAP7XX_DSP_M_CTL);
360
361         /*
362          * UARTs -> done automagically by 8250 driver
363          */
364
365         /*
366          * CSx timings, GPIO Mux ... setup
367          */
368
369         /* Flash: CS0 timings setup */
370         omap_writel(0x0000fff3, OMAP7XX_FLASH_CFG_0);
371         omap_writel(0x00000088, OMAP7XX_FLASH_ACFG_0);
372
373         /*
374          * Ethernet support through the debug board
375          * CS1 timings setup
376          */
377         omap_writel(0x0000fff3, OMAP7XX_FLASH_CFG_1);
378         omap_writel(0x00000000, OMAP7XX_FLASH_ACFG_1);
379
380         /*
381          * Configure MPU_EXT_NIRQ IO in IO_CONF9 register,
382          * It is used as the Ethernet controller interrupt
383          */
384         omap_writel(omap_readl(OMAP7XX_IO_CONF_9) & 0x1FFFFFFF, OMAP7XX_IO_CONF_9);
385 }
386
387 MACHINE_START(OMAP_FSAMPLE, "OMAP730 F-Sample")
388 /* Maintainer: Brian Swetland <swetland@google.com> */
389         .boot_params    = 0x10000100,
390         .map_io         = omap_fsample_map_io,
391         .reserve        = omap_reserve,
392         .init_irq       = omap_fsample_init_irq,
393         .init_machine   = omap_fsample_init,
394         .timer          = &omap_timer,
395 MACHINE_END