Merge git://git.infradead.org/mtd-2.6
[pandora-kernel.git] / arch / arm / mach-at91 / board-sam9g20ek.c
1 /*
2  *  Copyright (C) 2005 SAN People
3  *  Copyright (C) 2008 Atmel
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  */
19
20 #include <linux/types.h>
21 #include <linux/gpio.h>
22 #include <linux/init.h>
23 #include <linux/mm.h>
24 #include <linux/module.h>
25 #include <linux/platform_device.h>
26 #include <linux/spi/spi.h>
27 #include <linux/spi/at73c213.h>
28 #include <linux/gpio_keys.h>
29 #include <linux/input.h>
30 #include <linux/clk.h>
31 #include <linux/regulator/machine.h>
32 #include <linux/regulator/fixed.h>
33 #include <linux/regulator/consumer.h>
34
35 #include <mach/hardware.h>
36 #include <asm/setup.h>
37 #include <asm/mach-types.h>
38 #include <asm/irq.h>
39
40 #include <asm/mach/arch.h>
41 #include <asm/mach/map.h>
42 #include <asm/mach/irq.h>
43
44 #include <mach/board.h>
45 #include <mach/at91sam9_smc.h>
46 #include <mach/system_rev.h>
47
48 #include "sam9_smc.h"
49 #include "generic.h"
50
51 /*
52  * board revision encoding
53  * bit 0:
54  *      0 => 1 sd/mmc slot
55  *      1 => 2 sd/mmc slots connectors (board from revision C)
56  */
57 #define HAVE_2MMC       (1 << 0)
58 static int inline ek_have_2mmc(void)
59 {
60         return machine_is_at91sam9g20ek_2mmc() || (system_rev & HAVE_2MMC);
61 }
62
63
64 static void __init ek_init_early(void)
65 {
66         /* Initialize processor: 18.432 MHz crystal */
67         at91_initialize(18432000);
68
69         /* DBGU on ttyS0. (Rx & Tx only) */
70         at91_register_uart(0, 0, 0);
71
72         /* USART0 on ttyS1. (Rx, Tx, CTS, RTS, DTR, DSR, DCD, RI) */
73         at91_register_uart(AT91SAM9260_ID_US0, 1, ATMEL_UART_CTS | ATMEL_UART_RTS
74                            | ATMEL_UART_DTR | ATMEL_UART_DSR | ATMEL_UART_DCD
75                            | ATMEL_UART_RI);
76
77         /* USART1 on ttyS2. (Rx, Tx, RTS, CTS) */
78         at91_register_uart(AT91SAM9260_ID_US1, 2, ATMEL_UART_CTS | ATMEL_UART_RTS);
79
80         /* set serial console to ttyS0 (ie, DBGU) */
81         at91_set_serial_console(0);
82 }
83
84 /*
85  * USB Host port
86  */
87 static struct at91_usbh_data __initdata ek_usbh_data = {
88         .ports          = 2,
89 };
90
91 /*
92  * USB Device port
93  */
94 static struct at91_udc_data __initdata ek_udc_data = {
95         .vbus_pin       = AT91_PIN_PC5,
96         .pullup_pin     = 0,            /* pull-up driven by UDC */
97 };
98
99
100 /*
101  * SPI devices.
102  */
103 static struct spi_board_info ek_spi_devices[] = {
104 #if !(defined(CONFIG_MMC_ATMELMCI) || defined(CONFIG_MMC_AT91))
105         {       /* DataFlash chip */
106                 .modalias       = "mtd_dataflash",
107                 .chip_select    = 1,
108                 .max_speed_hz   = 15 * 1000 * 1000,
109                 .bus_num        = 0,
110         },
111 #if defined(CONFIG_MTD_AT91_DATAFLASH_CARD)
112         {       /* DataFlash card */
113                 .modalias       = "mtd_dataflash",
114                 .chip_select    = 0,
115                 .max_speed_hz   = 15 * 1000 * 1000,
116                 .bus_num        = 0,
117         },
118 #endif
119 #endif
120 };
121
122
123 /*
124  * MACB Ethernet device
125  */
126 static struct at91_eth_data __initdata ek_macb_data = {
127         .phy_irq_pin    = AT91_PIN_PA7,
128         .is_rmii        = 1,
129 };
130
131 static void __init ek_add_device_macb(void)
132 {
133         if (ek_have_2mmc())
134                 ek_macb_data.phy_irq_pin = AT91_PIN_PB0;
135
136         at91_add_device_eth(&ek_macb_data);
137 }
138
139 /*
140  * NAND flash
141  */
142 static struct mtd_partition __initdata ek_nand_partition[] = {
143         {
144                 .name   = "Bootstrap",
145                 .offset = 0,
146                 .size   = 4 * SZ_1M,
147         },
148         {
149                 .name   = "Partition 1",
150                 .offset = MTDPART_OFS_NXTBLK,
151                 .size   = 60 * SZ_1M,
152         },
153         {
154                 .name   = "Partition 2",
155                 .offset = MTDPART_OFS_NXTBLK,
156                 .size   = MTDPART_SIZ_FULL,
157         },
158 };
159
160 /* det_pin is not connected */
161 static struct atmel_nand_data __initdata ek_nand_data = {
162         .ale            = 21,
163         .cle            = 22,
164         .rdy_pin        = AT91_PIN_PC13,
165         .enable_pin     = AT91_PIN_PC14,
166         .parts          = ek_nand_partition,
167         .num_parts      = ARRAY_SIZE(ek_nand_partition),
168 };
169
170 static struct sam9_smc_config __initdata ek_nand_smc_config = {
171         .ncs_read_setup         = 0,
172         .nrd_setup              = 2,
173         .ncs_write_setup        = 0,
174         .nwe_setup              = 2,
175
176         .ncs_read_pulse         = 4,
177         .nrd_pulse              = 4,
178         .ncs_write_pulse        = 4,
179         .nwe_pulse              = 4,
180
181         .read_cycle             = 7,
182         .write_cycle            = 7,
183
184         .mode                   = AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE,
185         .tdf_cycles             = 3,
186 };
187
188 static void __init ek_add_device_nand(void)
189 {
190         ek_nand_data.bus_width_16 = board_have_nand_16bit();
191         /* setup bus-width (8 or 16) */
192         if (ek_nand_data.bus_width_16)
193                 ek_nand_smc_config.mode |= AT91_SMC_DBW_16;
194         else
195                 ek_nand_smc_config.mode |= AT91_SMC_DBW_8;
196
197         /* configure chip-select 3 (NAND) */
198         sam9_smc_configure(3, &ek_nand_smc_config);
199
200         at91_add_device_nand(&ek_nand_data);
201 }
202
203
204 /*
205  * MCI (SD/MMC)
206  * wp_pin and vcc_pin are not connected
207  */
208 #if defined(CONFIG_MMC_ATMELMCI) || defined(CONFIG_MMC_ATMELMCI_MODULE)
209 static struct mci_platform_data __initdata ek_mmc_data = {
210         .slot[1] = {
211                 .bus_width      = 4,
212                 .detect_pin     = AT91_PIN_PC9,
213         },
214
215 };
216 #else
217 static struct at91_mmc_data __initdata ek_mmc_data = {
218         .slot_b         = 1,    /* Only one slot so use slot B */
219         .wire4          = 1,
220         .det_pin        = AT91_PIN_PC9,
221 };
222 #endif
223
224 static void __init ek_add_device_mmc(void)
225 {
226 #if defined(CONFIG_MMC_ATMELMCI) || defined(CONFIG_MMC_ATMELMCI_MODULE)
227         if (ek_have_2mmc()) {
228                 ek_mmc_data.slot[0].bus_width = 4;
229                 ek_mmc_data.slot[0].detect_pin = AT91_PIN_PC2;
230         }
231         at91_add_device_mci(0, &ek_mmc_data);
232 #else
233         at91_add_device_mmc(0, &ek_mmc_data);
234 #endif
235 }
236
237 /*
238  * LEDs
239  */
240 static struct gpio_led ek_leds[] = {
241         {       /* "bottom" led, green, userled1 to be defined */
242                 .name                   = "ds5",
243                 .gpio                   = AT91_PIN_PA6,
244                 .active_low             = 1,
245                 .default_trigger        = "none",
246         },
247         {       /* "power" led, yellow */
248                 .name                   = "ds1",
249                 .gpio                   = AT91_PIN_PA9,
250                 .default_trigger        = "heartbeat",
251         }
252 };
253
254 static void __init ek_add_device_gpio_leds(void)
255 {
256         if (ek_have_2mmc()) {
257                 ek_leds[0].gpio = AT91_PIN_PB8;
258                 ek_leds[1].gpio = AT91_PIN_PB9;
259         }
260
261         at91_gpio_leds(ek_leds, ARRAY_SIZE(ek_leds));
262 }
263
264 /*
265  * GPIO Buttons
266  */
267 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
268 static struct gpio_keys_button ek_buttons[] = {
269         {
270                 .gpio           = AT91_PIN_PA30,
271                 .code           = BTN_3,
272                 .desc           = "Button 3",
273                 .active_low     = 1,
274                 .wakeup         = 1,
275         },
276         {
277                 .gpio           = AT91_PIN_PA31,
278                 .code           = BTN_4,
279                 .desc           = "Button 4",
280                 .active_low     = 1,
281                 .wakeup         = 1,
282         }
283 };
284
285 static struct gpio_keys_platform_data ek_button_data = {
286         .buttons        = ek_buttons,
287         .nbuttons       = ARRAY_SIZE(ek_buttons),
288 };
289
290 static struct platform_device ek_button_device = {
291         .name           = "gpio-keys",
292         .id             = -1,
293         .num_resources  = 0,
294         .dev            = {
295                 .platform_data  = &ek_button_data,
296         }
297 };
298
299 static void __init ek_add_device_buttons(void)
300 {
301         at91_set_gpio_input(AT91_PIN_PA30, 1);  /* btn3 */
302         at91_set_deglitch(AT91_PIN_PA30, 1);
303         at91_set_gpio_input(AT91_PIN_PA31, 1);  /* btn4 */
304         at91_set_deglitch(AT91_PIN_PA31, 1);
305
306         platform_device_register(&ek_button_device);
307 }
308 #else
309 static void __init ek_add_device_buttons(void) {}
310 #endif
311
312 #if defined(CONFIG_REGULATOR_FIXED_VOLTAGE) || defined(CONFIG_REGULATOR_FIXED_VOLTAGE_MODULE)
313 static struct regulator_consumer_supply ek_audio_consumer_supplies[] = {
314         REGULATOR_SUPPLY("AVDD", "0-001b"),
315         REGULATOR_SUPPLY("HPVDD", "0-001b"),
316         REGULATOR_SUPPLY("DBVDD", "0-001b"),
317         REGULATOR_SUPPLY("DCVDD", "0-001b"),
318 };
319
320 static struct regulator_init_data ek_avdd_reg_init_data = {
321         .constraints    = {
322                 .name   = "3V3",
323                 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
324         },
325         .consumer_supplies = ek_audio_consumer_supplies,
326         .num_consumer_supplies = ARRAY_SIZE(ek_audio_consumer_supplies),
327 };
328
329 static struct fixed_voltage_config ek_vdd_pdata = {
330         .supply_name    = "board-3V3",
331         .microvolts     = 3300000,
332         .gpio           = -EINVAL,
333         .enabled_at_boot = 0,
334         .init_data      = &ek_avdd_reg_init_data,
335 };
336 static struct platform_device ek_voltage_regulator = {
337         .name           = "reg-fixed-voltage",
338         .id             = -1,
339         .num_resources  = 0,
340         .dev            = {
341                 .platform_data  = &ek_vdd_pdata,
342         },
343 };
344 static void __init ek_add_regulators(void)
345 {
346         platform_device_register(&ek_voltage_regulator);
347 }
348 #else
349 static void __init ek_add_regulators(void) {}
350 #endif
351
352
353 static struct i2c_board_info __initdata ek_i2c_devices[] = {
354         {
355                 I2C_BOARD_INFO("24c512", 0x50)
356         },
357         {
358                 I2C_BOARD_INFO("wm8731", 0x1b)
359         },
360 };
361
362
363 static void __init ek_board_init(void)
364 {
365         /* Serial */
366         at91_add_device_serial();
367         /* USB Host */
368         at91_add_device_usbh(&ek_usbh_data);
369         /* USB Device */
370         at91_add_device_udc(&ek_udc_data);
371         /* SPI */
372         at91_add_device_spi(ek_spi_devices, ARRAY_SIZE(ek_spi_devices));
373         /* NAND */
374         ek_add_device_nand();
375         /* Ethernet */
376         ek_add_device_macb();
377         /* Regulators */
378         ek_add_regulators();
379         /* MMC */
380         ek_add_device_mmc();
381         /* I2C */
382         at91_add_device_i2c(ek_i2c_devices, ARRAY_SIZE(ek_i2c_devices));
383         /* LEDs */
384         ek_add_device_gpio_leds();
385         /* Push Buttons */
386         ek_add_device_buttons();
387         /* PCK0 provides MCLK to the WM8731 */
388         at91_set_B_periph(AT91_PIN_PC1, 0);
389         /* SSC (for WM8731) */
390         at91_add_device_ssc(AT91SAM9260_ID_SSC, ATMEL_SSC_TX);
391 }
392
393 MACHINE_START(AT91SAM9G20EK, "Atmel AT91SAM9G20-EK")
394         /* Maintainer: Atmel */
395         .timer          = &at91sam926x_timer,
396         .map_io         = at91_map_io,
397         .init_early     = ek_init_early,
398         .init_irq       = at91_init_irq_default,
399         .init_machine   = ek_board_init,
400 MACHINE_END
401
402 MACHINE_START(AT91SAM9G20EK_2MMC, "Atmel AT91SAM9G20-EK 2 MMC Slot Mod")
403         /* Maintainer: Atmel */
404         .timer          = &at91sam926x_timer,
405         .map_io         = at91_map_io,
406         .init_early     = ek_init_early,
407         .init_irq       = at91_init_irq_default,
408         .init_machine   = ek_board_init,
409 MACHINE_END