]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/arm/mach-omap2/board-apollon.c
5488961499d2c54a0cd7010a3ff4b5ae9258b615
[linux-2.6-omap-h63xx.git] / arch / arm / mach-omap2 / board-apollon.c
1 /*
2  * linux/arch/arm/mach-omap2/board-apollon.c
3  *
4  * Copyright (C) 2005,2006 Samsung Electronics
5  * Author: Kyungmin Park <kyungmin.park@samsung.com>
6  *
7  * Modified from mach-omap2/board-h4.c
8  *
9  * Code for apollon OMAP2 board. Should work on many OMAP2 systems where
10  * the bootloader passes the board-specific data to the kernel.
11  * Do not put any board specific code to this file; create a new machine
12  * type if you need custom low-level initializations.
13  *
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License version 2 as
16  * published by the Free Software Foundation.
17  */
18
19 #include <linux/kernel.h>
20 #include <linux/init.h>
21 #include <linux/platform_device.h>
22 #include <linux/mtd/mtd.h>
23 #include <linux/mtd/partitions.h>
24 #include <linux/mtd/onenand.h>
25 #include <linux/irq.h>
26 #include <linux/interrupt.h>
27 #include <linux/delay.h>
28 #include <linux/leds.h>
29 #include <linux/irq.h>
30 #include <linux/err.h>
31 #include <linux/clk.h>
32
33 #include <asm/hardware.h>
34 #include <asm/mach-types.h>
35 #include <asm/mach/arch.h>
36 #include <asm/mach/flash.h>
37
38 #include <asm/arch/gpio.h>
39 #include <asm/arch/led.h>
40 #include <asm/arch/mux.h>
41 #include <asm/arch/usb.h>
42 #include <asm/arch/board.h>
43 #include <asm/arch/common.h>
44 #include <asm/arch/gpmc.h>
45 #include "prcm-regs.h"
46
47 /* LED & Switch macros */
48 #define LED0_GPIO13             13
49 #define LED1_GPIO14             14
50 #define LED2_GPIO15             15
51 #define SW_ENTER_GPIO16         16
52 #define SW_UP_GPIO17            17
53 #define SW_DOWN_GPIO58          58
54
55 #define APOLLON_FLASH_CS        0
56 #define APOLLON_ETH_CS          1
57
58 static struct mtd_partition apollon_partitions[] = {
59         {
60                 .name           = "X-Loader + U-Boot",
61                 .offset         = 0,
62                 .size           = SZ_128K,
63                 .mask_flags     = MTD_WRITEABLE,
64         },
65         {
66                 .name           = "params",
67                 .offset         = MTDPART_OFS_APPEND,
68                 .size           = SZ_128K,
69         },
70         {
71                 .name           = "kernel",
72                 .offset         = MTDPART_OFS_APPEND,
73                 .size           = SZ_2M,
74         },
75         {
76                 .name           = "rootfs",
77                 .offset         = MTDPART_OFS_APPEND,
78                 .size           = SZ_16M,
79         },
80         {
81                 .name           = "filesystem00",
82                 .offset         = MTDPART_OFS_APPEND,
83                 .size           = SZ_32M,
84         },
85         {
86                 .name           = "filesystem01",
87                 .offset         = MTDPART_OFS_APPEND,
88                 .size           = MTDPART_SIZ_FULL,
89         },
90 };
91
92 static struct flash_platform_data apollon_flash_data = {
93         .parts          = apollon_partitions,
94         .nr_parts       = ARRAY_SIZE(apollon_partitions),
95 };
96
97 static struct resource apollon_flash_resource[] = {
98         [0] = {
99                 .flags          = IORESOURCE_MEM,
100         },
101 };
102
103 static struct platform_device apollon_onenand_device = {
104         .name           = "onenand",
105         .id             = -1,
106         .dev            = {
107                 .platform_data  = &apollon_flash_data,
108         },
109         .num_resources  = ARRAY_SIZE(apollon_flash_resource),
110         .resource       = apollon_flash_resource,
111 };
112
113 static void __init apollon_flash_init(void)
114 {
115         unsigned long base;
116
117         if (gpmc_cs_request(APOLLON_FLASH_CS, SZ_128K, &base) < 0) {
118                 printk(KERN_ERR "Cannot request OneNAND GPMC CS\n");
119                 return;
120         }
121         apollon_flash_resource[0].start = base;
122         apollon_flash_resource[0].end   = base + SZ_128K - 1;
123 }
124
125 static struct resource apollon_smc91x_resources[] = {
126         [0] = {
127                 .flags  = IORESOURCE_MEM,
128         },
129         [1] = {
130                 .start  = OMAP_GPIO_IRQ(APOLLON_ETHR_GPIO_IRQ),
131                 .end    = OMAP_GPIO_IRQ(APOLLON_ETHR_GPIO_IRQ),
132                 .flags  = IORESOURCE_IRQ,
133         },
134 };
135
136 static struct platform_device apollon_smc91x_device = {
137         .name           = "smc91x",
138         .id             = -1,
139         .num_resources  = ARRAY_SIZE(apollon_smc91x_resources),
140         .resource       = apollon_smc91x_resources,
141 };
142
143 static struct platform_device apollon_lcd_device = {
144         .name           = "apollon_lcd",
145         .id             = -1,
146 };
147
148 static struct omap_led_config apollon_led_config[] = {
149         {
150                 .cdev   = {
151                         .name   = "apollon:led0",
152                 },
153                 .gpio   = LED0_GPIO13,
154         },
155         {
156                 .cdev   = {
157                         .name   = "apollon:led1",
158                 },
159                 .gpio   = LED1_GPIO14,
160         },
161         {
162                 .cdev   = {
163                         .name   = "apollon:led2",
164                 },
165                 .gpio   = LED2_GPIO15,
166         },
167 };
168
169 static struct omap_led_platform_data apollon_led_data = {
170         .nr_leds        = ARRAY_SIZE(apollon_led_config),
171         .leds           = apollon_led_config,
172 };
173
174 static struct platform_device apollon_led_device = {
175         .name           = "omap-led",
176         .id             = -1,
177         .dev            = {
178                 .platform_data  = &apollon_led_data,
179         },
180 };
181
182 static struct platform_device *apollon_devices[] __initdata = {
183         &apollon_onenand_device,
184         &apollon_smc91x_device,
185         &apollon_lcd_device,
186         &apollon_led_device,
187 };
188
189 static inline void __init apollon_init_smc91x(void)
190 {
191         unsigned long base;
192         unsigned int rate;
193         struct clk *l3ck;
194         int eth_cs;
195
196         l3ck = clk_get(NULL, "core_l3_ck");
197         if (IS_ERR(l3ck))
198                 rate = 100000000;
199         else
200                 rate = clk_get_rate(l3ck);
201
202         eth_cs = APOLLON_ETH_CS;
203
204         /* Make sure CS1 timings are correct */
205         gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG1, 0x00011200);
206
207         if (rate >= 160000000) {
208                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG2, 0x001f1f01);
209                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG3, 0x00080803);
210                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG4, 0x1c0b1c0a);
211                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG5, 0x041f1F1F);
212                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG6, 0x000004C4);
213         } else if (rate >= 130000000) {
214                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG2, 0x001f1f00);
215                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG3, 0x00080802);
216                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG4, 0x1C091C09);
217                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG5, 0x041f1F1F);
218                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG6, 0x000004C4);
219         } else {/* rate = 100000000 */
220                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG2, 0x001f1f00);
221                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG3, 0x00080802);
222                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG4, 0x1C091C09);
223                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG5, 0x031A1F1F);
224                 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG6, 0x000003C2);
225         }
226
227         if (gpmc_cs_request(eth_cs, SZ_16M, &base) < 0) {
228                 printk(KERN_ERR "Failed to request GPMC CS for smc91x\n");
229                 return;
230         }
231         apollon_smc91x_resources[0].start = base + 0x300;
232         apollon_smc91x_resources[0].end   = base + 0x30f;
233         udelay(100);
234
235         omap_cfg_reg(W4__24XX_GPIO74);
236         if (omap_request_gpio(APOLLON_ETHR_GPIO_IRQ) < 0) {
237                 printk(KERN_ERR "Failed to request GPIO%d for smc91x IRQ\n",
238                         APOLLON_ETHR_GPIO_IRQ);
239                 gpmc_cs_free(eth_cs);
240                 return;
241         }
242         omap_set_gpio_direction(APOLLON_ETHR_GPIO_IRQ, 1);
243 }
244
245 static void __init omap_apollon_init_irq(void)
246 {
247         omap2_init_common_hw();
248         omap_init_irq();
249         omap_gpio_init();
250         apollon_init_smc91x();
251 }
252
253 static struct omap_uart_config apollon_uart_config __initdata = {
254         .enabled_uarts = (1 << 0) | (0 << 1) | (0 << 2),
255 };
256
257 static struct omap_mmc_config apollon_mmc_config __initdata = {
258         .mmc [0] = {
259                 .enabled        = 1,
260                 .wire4          = 1,
261                 .wp_pin         = -1,
262                 .power_pin      = -1,
263         /* Note: If you want to detect card feature, please assign 37 */
264                 .switch_pin     = -1,
265         },
266 };
267
268 static struct omap_usb_config apollon_usb_config __initdata = {
269         .register_dev   = 1,
270         .hmc_mode       = 0x14, /* 0:dev 1:host1 2:disable */
271
272         .pins[0]        = 6,
273 };
274
275 static struct omap_lcd_config apollon_lcd_config __initdata = {
276         .ctrl_name      = "internal",
277 };
278
279 static struct omap_board_config_kernel apollon_config[] = {
280         { OMAP_TAG_UART,        &apollon_uart_config },
281         { OMAP_TAG_MMC,         &apollon_mmc_config },
282         { OMAP_TAG_USB,         &apollon_usb_config },
283         { OMAP_TAG_LCD,         &apollon_lcd_config },
284 };
285
286 static void __init apollon_led_init(void)
287 {
288         /* LED0 - AA10 */
289         omap_cfg_reg(AA10_242X_GPIO13);
290         omap_request_gpio(LED0_GPIO13);
291         omap_set_gpio_direction(LED0_GPIO13, 0);
292         omap_set_gpio_dataout(LED0_GPIO13, 0);
293         /* LED1  - AA6 */
294         omap_cfg_reg(AA6_242X_GPIO14);
295         omap_request_gpio(LED1_GPIO14);
296         omap_set_gpio_direction(LED1_GPIO14, 0);
297         omap_set_gpio_dataout(LED1_GPIO14, 0);
298         /* LED2  - AA4 */
299         omap_cfg_reg(AA4_242X_GPIO15);
300         omap_request_gpio(LED2_GPIO15);
301         omap_set_gpio_direction(LED2_GPIO15, 0);
302         omap_set_gpio_dataout(LED2_GPIO15, 0);
303 }
304
305 static irqreturn_t apollon_sw_interrupt(int irq, void *ignored)
306 {
307         static unsigned int led0, led1, led2;
308
309         if (irq == OMAP_GPIO_IRQ(SW_ENTER_GPIO16))
310                 omap_set_gpio_dataout(LED0_GPIO13, led0 ^= 1);
311         else if (irq == OMAP_GPIO_IRQ(SW_UP_GPIO17))
312                 omap_set_gpio_dataout(LED1_GPIO14, led1 ^= 1);
313         else if (irq == OMAP_GPIO_IRQ(SW_DOWN_GPIO58))
314                 omap_set_gpio_dataout(LED2_GPIO15, led2 ^= 1);
315
316         return IRQ_HANDLED;
317 }
318
319 static void __init apollon_sw_init(void)
320 {
321         /* Enter SW - Y11 */
322         omap_cfg_reg(Y11_242X_GPIO16);
323         omap_request_gpio(SW_ENTER_GPIO16);
324         omap_set_gpio_direction(SW_ENTER_GPIO16, 1);
325         /* Up SW - AA12 */
326         omap_cfg_reg(AA12_242X_GPIO17);
327         omap_request_gpio(SW_UP_GPIO17);
328         omap_set_gpio_direction(SW_UP_GPIO17, 1);
329         /* Down SW - AA8 */
330         omap_cfg_reg(AA8_242X_GPIO58);
331         omap_request_gpio(SW_DOWN_GPIO58);
332         omap_set_gpio_direction(SW_DOWN_GPIO58, 1);
333
334         set_irq_type(OMAP_GPIO_IRQ(SW_ENTER_GPIO16), IRQT_RISING);
335         if (request_irq(OMAP_GPIO_IRQ(SW_ENTER_GPIO16), &apollon_sw_interrupt,
336                                 IRQF_SHARED, "enter sw",
337                                 &apollon_sw_interrupt))
338                 return;
339         set_irq_type(OMAP_GPIO_IRQ(SW_UP_GPIO17), IRQT_RISING);
340         if (request_irq(OMAP_GPIO_IRQ(SW_UP_GPIO17), &apollon_sw_interrupt,
341                                 IRQF_SHARED, "up sw",
342                                 &apollon_sw_interrupt))
343                 return;
344         set_irq_type(OMAP_GPIO_IRQ(SW_DOWN_GPIO58), IRQT_RISING);
345         if (request_irq(OMAP_GPIO_IRQ(SW_DOWN_GPIO58), &apollon_sw_interrupt,
346                                 IRQF_SHARED, "down sw",
347                                 &apollon_sw_interrupt))
348                 return;
349 }
350
351 static void __init apollon_usb_init(void)
352 {
353         /* USB device */
354         /* DEVICE_SUSPEND */
355         omap_cfg_reg(P21_242X_GPIO12);
356         omap_request_gpio(12);
357         omap_set_gpio_direction(12, 0);         /* OUT */
358         omap_set_gpio_dataout(12, 0);
359 }
360
361 static void __init omap_apollon_init(void)
362 {
363         apollon_led_init();
364         apollon_sw_init();
365         apollon_flash_init();
366         apollon_usb_init();
367
368         /* Use Interal loop-back in MMC/SDIO Module Input Clock selection */
369         CONTROL_DEVCONF |= (1 << 24);
370
371         /*
372          * Make sure the serial ports are muxed on at this point.
373          * You have to mux them off in device drivers later on
374          * if not needed.
375          */
376         platform_add_devices(apollon_devices, ARRAY_SIZE(apollon_devices));
377         omap_board_config = apollon_config;
378         omap_board_config_size = ARRAY_SIZE(apollon_config);
379         omap_serial_init();
380 }
381
382 static void __init omap_apollon_map_io(void)
383 {
384         omap2_map_common_io();
385 }
386
387 MACHINE_START(OMAP_APOLLON, "OMAP24xx Apollon")
388         /* Maintainer: Kyungmin Park <kyungmin.park@samsung.com> */
389         .phys_io        = 0x48000000,
390         .io_pg_offst    = ((0xd8000000) >> 18) & 0xfffc,
391         .boot_params    = 0x80000100,
392         .map_io         = omap_apollon_map_io,
393         .init_irq       = omap_apollon_init_irq,
394         .init_machine   = omap_apollon_init,
395         .timer          = &omap_timer,
396 MACHINE_END