omap: use smc91x_platdata to setup smc91x
[linux-2.6/kvm.git] / arch / arm / mach-omap2 / board-apollon.c
blobfbbd68d69cc8cc50d0f426bcc67db622f1bf5c16
1 /*
2 * linux/arch/arm/mach-omap2/board-apollon.c
4 * Copyright (C) 2005,2006 Samsung Electronics
5 * Author: Kyungmin Park <kyungmin.park@samsung.com>
7 * Modified from mach-omap/omap2/board-h4.c
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.
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.
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/delay.h>
26 #include <linux/leds.h>
27 #include <linux/err.h>
28 #include <linux/clk.h>
29 #include <linux/smc91x.h>
31 #include <mach/hardware.h>
32 #include <asm/mach-types.h>
33 #include <asm/mach/arch.h>
34 #include <asm/mach/flash.h>
36 #include <mach/gpio.h>
37 #include <plat/led.h>
38 #include <plat/mux.h>
39 #include <plat/usb.h>
40 #include <plat/board.h>
41 #include <plat/common.h>
42 #include <plat/gpmc.h>
43 #include <plat/control.h>
45 /* LED & Switch macros */
46 #define LED0_GPIO13 13
47 #define LED1_GPIO14 14
48 #define LED2_GPIO15 15
49 #define SW_ENTER_GPIO16 16
50 #define SW_UP_GPIO17 17
51 #define SW_DOWN_GPIO58 58
53 #define APOLLON_FLASH_CS 0
54 #define APOLLON_ETH_CS 1
55 #define APOLLON_ETHR_GPIO_IRQ 74
57 static struct mtd_partition apollon_partitions[] = {
59 .name = "X-Loader + U-Boot",
60 .offset = 0,
61 .size = SZ_128K,
62 .mask_flags = MTD_WRITEABLE,
65 .name = "params",
66 .offset = MTDPART_OFS_APPEND,
67 .size = SZ_128K,
70 .name = "kernel",
71 .offset = MTDPART_OFS_APPEND,
72 .size = SZ_2M,
75 .name = "rootfs",
76 .offset = MTDPART_OFS_APPEND,
77 .size = SZ_16M,
80 .name = "filesystem00",
81 .offset = MTDPART_OFS_APPEND,
82 .size = SZ_32M,
85 .name = "filesystem01",
86 .offset = MTDPART_OFS_APPEND,
87 .size = MTDPART_SIZ_FULL,
91 static struct onenand_platform_data apollon_flash_data = {
92 .parts = apollon_partitions,
93 .nr_parts = ARRAY_SIZE(apollon_partitions),
96 static struct resource apollon_flash_resource[] = {
97 [0] = {
98 .flags = IORESOURCE_MEM,
102 static struct platform_device apollon_onenand_device = {
103 .name = "onenand-flash",
104 .id = -1,
105 .dev = {
106 .platform_data = &apollon_flash_data,
108 .num_resources = ARRAY_SIZE(apollon_flash_resource),
109 .resource = apollon_flash_resource,
112 static void __init apollon_flash_init(void)
114 unsigned long base;
116 if (gpmc_cs_request(APOLLON_FLASH_CS, SZ_128K, &base) < 0) {
117 printk(KERN_ERR "Cannot request OneNAND GPMC CS\n");
118 return;
120 apollon_flash_resource[0].start = base;
121 apollon_flash_resource[0].end = base + SZ_128K - 1;
124 static struct smc91x_platdata appolon_smc91x_info = {
125 .flags = SMC91X_USE_16BIT | SMC91X_NOWAIT,
126 .leda = RPC_LED_100_10,
127 .ledb = RPC_LED_TX_RX,
130 static struct resource apollon_smc91x_resources[] = {
131 [0] = {
132 .flags = IORESOURCE_MEM,
134 [1] = {
135 .start = OMAP_GPIO_IRQ(APOLLON_ETHR_GPIO_IRQ),
136 .end = OMAP_GPIO_IRQ(APOLLON_ETHR_GPIO_IRQ),
137 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
141 static struct platform_device apollon_smc91x_device = {
142 .name = "smc91x",
143 .id = -1,
144 .dev = {
145 .platform_data = &appolon_smc91x_info,
147 .num_resources = ARRAY_SIZE(apollon_smc91x_resources),
148 .resource = apollon_smc91x_resources,
151 static struct platform_device apollon_lcd_device = {
152 .name = "apollon_lcd",
153 .id = -1,
156 static struct omap_led_config apollon_led_config[] = {
158 .cdev = {
159 .name = "apollon:led0",
161 .gpio = LED0_GPIO13,
164 .cdev = {
165 .name = "apollon:led1",
167 .gpio = LED1_GPIO14,
170 .cdev = {
171 .name = "apollon:led2",
173 .gpio = LED2_GPIO15,
177 static struct omap_led_platform_data apollon_led_data = {
178 .nr_leds = ARRAY_SIZE(apollon_led_config),
179 .leds = apollon_led_config,
182 static struct platform_device apollon_led_device = {
183 .name = "omap-led",
184 .id = -1,
185 .dev = {
186 .platform_data = &apollon_led_data,
190 static struct platform_device *apollon_devices[] __initdata = {
191 &apollon_onenand_device,
192 &apollon_smc91x_device,
193 &apollon_lcd_device,
194 &apollon_led_device,
197 static inline void __init apollon_init_smc91x(void)
199 unsigned long base;
201 unsigned int rate;
202 struct clk *gpmc_fck;
203 int eth_cs;
205 gpmc_fck = clk_get(NULL, "gpmc_fck"); /* Always on ENABLE_ON_INIT */
206 if (IS_ERR(gpmc_fck)) {
207 WARN_ON(1);
208 return;
211 clk_enable(gpmc_fck);
212 rate = clk_get_rate(gpmc_fck);
214 eth_cs = APOLLON_ETH_CS;
216 /* Make sure CS1 timings are correct */
217 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG1, 0x00011200);
219 if (rate >= 160000000) {
220 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG2, 0x001f1f01);
221 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG3, 0x00080803);
222 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG4, 0x1c0b1c0a);
223 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG5, 0x041f1F1F);
224 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG6, 0x000004C4);
225 } else if (rate >= 130000000) {
226 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG2, 0x001f1f00);
227 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG3, 0x00080802);
228 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG4, 0x1C091C09);
229 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG5, 0x041f1F1F);
230 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG6, 0x000004C4);
231 } else {/* rate = 100000000 */
232 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG2, 0x001f1f00);
233 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG3, 0x00080802);
234 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG4, 0x1C091C09);
235 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG5, 0x031A1F1F);
236 gpmc_cs_write_reg(eth_cs, GPMC_CS_CONFIG6, 0x000003C2);
239 if (gpmc_cs_request(APOLLON_ETH_CS, SZ_16M, &base) < 0) {
240 printk(KERN_ERR "Failed to request GPMC CS for smc91x\n");
241 goto out;
243 apollon_smc91x_resources[0].start = base + 0x300;
244 apollon_smc91x_resources[0].end = base + 0x30f;
245 udelay(100);
247 omap_cfg_reg(W4__24XX_GPIO74);
248 if (gpio_request(APOLLON_ETHR_GPIO_IRQ, "SMC91x irq") < 0) {
249 printk(KERN_ERR "Failed to request GPIO%d for smc91x IRQ\n",
250 APOLLON_ETHR_GPIO_IRQ);
251 gpmc_cs_free(APOLLON_ETH_CS);
252 goto out;
254 gpio_direction_input(APOLLON_ETHR_GPIO_IRQ);
256 out:
257 clk_disable(gpmc_fck);
258 clk_put(gpmc_fck);
261 static struct omap_usb_config apollon_usb_config __initdata = {
262 .register_dev = 1,
263 .hmc_mode = 0x14, /* 0:dev 1:host1 2:disable */
265 .pins[0] = 6,
268 static struct omap_lcd_config apollon_lcd_config __initdata = {
269 .ctrl_name = "internal",
272 static struct omap_board_config_kernel apollon_config[] = {
273 { OMAP_TAG_LCD, &apollon_lcd_config },
276 static void __init omap_apollon_init_irq(void)
278 omap_board_config = apollon_config;
279 omap_board_config_size = ARRAY_SIZE(apollon_config);
280 omap2_init_common_hw(NULL, NULL);
281 omap_init_irq();
282 omap_gpio_init();
283 apollon_init_smc91x();
286 static void __init apollon_led_init(void)
288 /* LED0 - AA10 */
289 omap_cfg_reg(AA10_242X_GPIO13);
290 gpio_request(LED0_GPIO13, "LED0");
291 gpio_direction_output(LED0_GPIO13, 0);
292 /* LED1 - AA6 */
293 omap_cfg_reg(AA6_242X_GPIO14);
294 gpio_request(LED1_GPIO14, "LED1");
295 gpio_direction_output(LED1_GPIO14, 0);
296 /* LED2 - AA4 */
297 omap_cfg_reg(AA4_242X_GPIO15);
298 gpio_request(LED2_GPIO15, "LED2");
299 gpio_direction_output(LED2_GPIO15, 0);
302 static void __init apollon_usb_init(void)
304 /* USB device */
305 /* DEVICE_SUSPEND */
306 omap_cfg_reg(P21_242X_GPIO12);
307 gpio_request(12, "USB suspend");
308 gpio_direction_output(12, 0);
309 omap_usb_init(&apollon_usb_config);
312 static void __init omap_apollon_init(void)
314 u32 v;
316 apollon_led_init();
317 apollon_flash_init();
318 apollon_usb_init();
320 /* REVISIT: where's the correct place */
321 omap_cfg_reg(W19_24XX_SYS_NIRQ);
323 /* Use Interal loop-back in MMC/SDIO Module Input Clock selection */
324 v = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0);
325 v |= (1 << 24);
326 omap_ctrl_writel(v, OMAP2_CONTROL_DEVCONF0);
329 * Make sure the serial ports are muxed on at this point.
330 * You have to mux them off in device drivers later on
331 * if not needed.
333 platform_add_devices(apollon_devices, ARRAY_SIZE(apollon_devices));
334 omap_serial_init();
337 static void __init omap_apollon_map_io(void)
339 omap2_set_globals_242x();
340 omap2_map_common_io();
343 MACHINE_START(OMAP_APOLLON, "OMAP24xx Apollon")
344 /* Maintainer: Kyungmin Park <kyungmin.park@samsung.com> */
345 .phys_io = 0x48000000,
346 .io_pg_offst = ((0xfa000000) >> 18) & 0xfffc,
347 .boot_params = 0x80000100,
348 .map_io = omap_apollon_map_io,
349 .init_irq = omap_apollon_init_irq,
350 .init_machine = omap_apollon_init,
351 .timer = &omap_timer,
352 MACHINE_END