Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gerg/m68knommu
[sfrench/cifs-2.6.git] / arch / arm / mach-at91 / board-cpu9krea.c
1 /*
2  * linux/arch/arm/mach-at91/board-cpu9krea.c
3  *
4  *  Copyright (C) 2005 SAN People
5  *  Copyright (C) 2006 Atmel
6  *  Copyright (C) 2009 Eric Benard - eric@eukrea.com
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 #include <linux/types.h>
24 #include <linux/gpio.h>
25 #include <linux/init.h>
26 #include <linux/mm.h>
27 #include <linux/module.h>
28 #include <linux/platform_device.h>
29 #include <linux/clk.h>
30 #include <linux/gpio_keys.h>
31 #include <linux/input.h>
32 #include <linux/mtd/physmap.h>
33
34 #include <asm/setup.h>
35 #include <asm/mach-types.h>
36 #include <asm/irq.h>
37
38 #include <asm/mach/arch.h>
39 #include <asm/mach/map.h>
40 #include <asm/mach/irq.h>
41
42 #include <mach/hardware.h>
43 #include <mach/at91sam9_smc.h>
44 #include <mach/at91sam9260_matrix.h>
45 #include <mach/at91_matrix.h>
46
47 #include "at91_aic.h"
48 #include "board.h"
49 #include "sam9_smc.h"
50 #include "generic.h"
51 #include "gpio.h"
52
53 static void __init cpu9krea_init_early(void)
54 {
55         /* Initialize processor: 18.432 MHz crystal */
56         at91_initialize(18432000);
57 }
58
59 /*
60  * USB Host port
61  */
62 static struct at91_usbh_data __initdata cpu9krea_usbh_data = {
63         .ports          = 2,
64         .vbus_pin       = {-EINVAL, -EINVAL},
65         .overcurrent_pin= {-EINVAL, -EINVAL},
66 };
67
68 /*
69  * USB Device port
70  */
71 static struct at91_udc_data __initdata cpu9krea_udc_data = {
72         .vbus_pin       = AT91_PIN_PC8,
73         .pullup_pin     = -EINVAL,              /* pull-up driven by UDC */
74 };
75
76 /*
77  * MACB Ethernet device
78  */
79 static struct macb_platform_data __initdata cpu9krea_macb_data = {
80         .phy_irq_pin    = -EINVAL,
81         .is_rmii        = 1,
82 };
83
84 /*
85  * NAND flash
86  */
87 static struct atmel_nand_data __initdata cpu9krea_nand_data = {
88         .ale            = 21,
89         .cle            = 22,
90         .rdy_pin        = AT91_PIN_PC13,
91         .enable_pin     = AT91_PIN_PC14,
92         .bus_width_16   = 0,
93         .det_pin        = -EINVAL,
94         .ecc_mode       = NAND_ECC_SOFT,
95 };
96
97 #ifdef CONFIG_MACH_CPU9260
98 static struct sam9_smc_config __initdata cpu9krea_nand_smc_config = {
99         .ncs_read_setup         = 0,
100         .nrd_setup              = 1,
101         .ncs_write_setup        = 0,
102         .nwe_setup              = 1,
103
104         .ncs_read_pulse         = 3,
105         .nrd_pulse              = 3,
106         .ncs_write_pulse        = 3,
107         .nwe_pulse              = 3,
108
109         .read_cycle             = 5,
110         .write_cycle            = 5,
111
112         .mode                   = AT91_SMC_READMODE | AT91_SMC_WRITEMODE
113                 | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_DBW_8,
114         .tdf_cycles             = 2,
115 };
116 #else
117 static struct sam9_smc_config __initdata cpu9krea_nand_smc_config = {
118         .ncs_read_setup         = 0,
119         .nrd_setup              = 2,
120         .ncs_write_setup        = 0,
121         .nwe_setup              = 2,
122
123         .ncs_read_pulse         = 4,
124         .nrd_pulse              = 4,
125         .ncs_write_pulse        = 4,
126         .nwe_pulse              = 4,
127
128         .read_cycle             = 7,
129         .write_cycle            = 7,
130
131         .mode                   = AT91_SMC_READMODE | AT91_SMC_WRITEMODE
132                 | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_DBW_8,
133         .tdf_cycles             = 3,
134 };
135 #endif
136
137 static void __init cpu9krea_add_device_nand(void)
138 {
139         sam9_smc_configure(0, 3, &cpu9krea_nand_smc_config);
140         at91_add_device_nand(&cpu9krea_nand_data);
141 }
142
143 /*
144  * NOR flash
145  */
146 static struct physmap_flash_data cpuat9260_nor_data = {
147         .width          = 2,
148 };
149
150 #define NOR_BASE        AT91_CHIPSELECT_0
151 #define NOR_SIZE        SZ_64M
152
153 static struct resource nor_flash_resources[] = {
154         {
155                 .start  = NOR_BASE,
156                 .end    = NOR_BASE + NOR_SIZE - 1,
157                 .flags  = IORESOURCE_MEM,
158         }
159 };
160
161 static struct platform_device cpu9krea_nor_flash = {
162         .name           = "physmap-flash",
163         .id             = 0,
164         .dev            = {
165                 .platform_data  = &cpuat9260_nor_data,
166         },
167         .resource       = nor_flash_resources,
168         .num_resources  = ARRAY_SIZE(nor_flash_resources),
169 };
170
171 #ifdef CONFIG_MACH_CPU9260
172 static struct sam9_smc_config __initdata cpu9krea_nor_smc_config = {
173         .ncs_read_setup         = 0,
174         .nrd_setup              = 1,
175         .ncs_write_setup        = 0,
176         .nwe_setup              = 1,
177
178         .ncs_read_pulse         = 10,
179         .nrd_pulse              = 10,
180         .ncs_write_pulse        = 6,
181         .nwe_pulse              = 6,
182
183         .read_cycle             = 12,
184         .write_cycle            = 8,
185
186         .mode                   = AT91_SMC_READMODE | AT91_SMC_WRITEMODE
187                         | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_BAT_WRITE
188                         | AT91_SMC_DBW_16,
189         .tdf_cycles             = 2,
190 };
191 #else
192 static struct sam9_smc_config __initdata cpu9krea_nor_smc_config = {
193         .ncs_read_setup         = 0,
194         .nrd_setup              = 1,
195         .ncs_write_setup        = 0,
196         .nwe_setup              = 1,
197
198         .ncs_read_pulse         = 13,
199         .nrd_pulse              = 13,
200         .ncs_write_pulse        = 8,
201         .nwe_pulse              = 8,
202
203         .read_cycle             = 15,
204         .write_cycle            = 10,
205
206         .mode                   = AT91_SMC_READMODE | AT91_SMC_WRITEMODE
207                         | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_BAT_WRITE
208                         | AT91_SMC_DBW_16,
209         .tdf_cycles             = 2,
210 };
211 #endif
212
213 static __init void cpu9krea_add_device_nor(void)
214 {
215         unsigned long csa;
216
217         csa = at91_matrix_read(AT91_MATRIX_EBICSA);
218         at91_matrix_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_VDDIOMSEL_3_3V);
219
220         /* configure chip-select 0 (NOR) */
221         sam9_smc_configure(0, 0, &cpu9krea_nor_smc_config);
222
223         platform_device_register(&cpu9krea_nor_flash);
224 }
225
226 /*
227  * LEDs
228  */
229 static struct gpio_led cpu9krea_leds[] = {
230         {       /* LED1 */
231                 .name                   = "LED1",
232                 .gpio                   = AT91_PIN_PC11,
233                 .active_low             = 1,
234                 .default_trigger        = "timer",
235         },
236         {       /* LED2 */
237                 .name                   = "LED2",
238                 .gpio                   = AT91_PIN_PC12,
239                 .active_low             = 1,
240                 .default_trigger        = "heartbeat",
241         },
242         {       /* LED3 */
243                 .name                   = "LED3",
244                 .gpio                   = AT91_PIN_PC7,
245                 .active_low             = 1,
246                 .default_trigger        = "none",
247         },
248         {       /* LED4 */
249                 .name                   = "LED4",
250                 .gpio                   = AT91_PIN_PC9,
251                 .active_low             = 1,
252                 .default_trigger        = "none",
253         }
254 };
255
256 static struct i2c_board_info __initdata cpu9krea_i2c_devices[] = {
257         {
258                 I2C_BOARD_INFO("ds1339", 0x68),
259         },
260 };
261
262 /*
263  * GPIO Buttons
264  */
265 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
266 static struct gpio_keys_button cpu9krea_buttons[] = {
267         {
268                 .gpio           = AT91_PIN_PC3,
269                 .code           = BTN_0,
270                 .desc           = "BP1",
271                 .active_low     = 1,
272                 .wakeup         = 1,
273         },
274         {
275                 .gpio           = AT91_PIN_PB20,
276                 .code           = BTN_1,
277                 .desc           = "BP2",
278                 .active_low     = 1,
279                 .wakeup         = 1,
280         }
281 };
282
283 static struct gpio_keys_platform_data cpu9krea_button_data = {
284         .buttons        = cpu9krea_buttons,
285         .nbuttons       = ARRAY_SIZE(cpu9krea_buttons),
286 };
287
288 static struct platform_device cpu9krea_button_device = {
289         .name           = "gpio-keys",
290         .id             = -1,
291         .num_resources  = 0,
292         .dev            = {
293                 .platform_data  = &cpu9krea_button_data,
294         }
295 };
296
297 static void __init cpu9krea_add_device_buttons(void)
298 {
299         at91_set_gpio_input(AT91_PIN_PC3, 1);   /* BP1 */
300         at91_set_deglitch(AT91_PIN_PC3, 1);
301         at91_set_gpio_input(AT91_PIN_PB20, 1);  /* BP2 */
302         at91_set_deglitch(AT91_PIN_PB20, 1);
303
304         platform_device_register(&cpu9krea_button_device);
305 }
306 #else
307 static void __init cpu9krea_add_device_buttons(void)
308 {
309 }
310 #endif
311
312 /*
313  * MCI (SD/MMC)
314  */
315 static struct mci_platform_data __initdata cpu9krea_mci0_data = {
316         .slot[0] = {
317                 .bus_width      = 4,
318                 .detect_pin     = AT91_PIN_PA29,
319                 .wp_pin         = -EINVAL,
320         },
321 };
322
323 static void __init cpu9krea_board_init(void)
324 {
325         at91_register_devices();
326
327         /* NOR */
328         cpu9krea_add_device_nor();
329         /* Serial */
330         /* DGBU on ttyS0. (Rx & Tx only) */
331         at91_register_uart(0, 0, 0);
332
333         /* USART0 on ttyS1. (Rx, Tx, CTS, RTS, DTR, DSR, DCD, RI) */
334         at91_register_uart(AT91SAM9260_ID_US0, 1, ATMEL_UART_CTS |
335                 ATMEL_UART_RTS | ATMEL_UART_DTR | ATMEL_UART_DSR |
336                 ATMEL_UART_DCD | ATMEL_UART_RI);
337
338         /* USART1 on ttyS2. (Rx, Tx, RTS, CTS) */
339         at91_register_uart(AT91SAM9260_ID_US1, 2, ATMEL_UART_CTS |
340                 ATMEL_UART_RTS);
341
342         /* USART2 on ttyS3. (Rx, Tx, RTS, CTS) */
343         at91_register_uart(AT91SAM9260_ID_US2, 3, ATMEL_UART_CTS |
344                 ATMEL_UART_RTS);
345
346         /* USART3 on ttyS4. (Rx, Tx) */
347         at91_register_uart(AT91SAM9260_ID_US3, 4, 0);
348
349         /* USART4 on ttyS5. (Rx, Tx) */
350         at91_register_uart(AT91SAM9260_ID_US4, 5, 0);
351
352         /* USART5 on ttyS6. (Rx, Tx) */
353         at91_register_uart(AT91SAM9260_ID_US5, 6, 0);
354         at91_add_device_serial();
355         /* USB Host */
356         at91_add_device_usbh(&cpu9krea_usbh_data);
357         /* USB Device */
358         at91_add_device_udc(&cpu9krea_udc_data);
359         /* NAND */
360         cpu9krea_add_device_nand();
361         /* Ethernet */
362         at91_add_device_eth(&cpu9krea_macb_data);
363         /* MMC */
364         at91_add_device_mci(0, &cpu9krea_mci0_data);
365         /* I2C */
366         at91_add_device_i2c(cpu9krea_i2c_devices,
367                 ARRAY_SIZE(cpu9krea_i2c_devices));
368         /* LEDs */
369         at91_gpio_leds(cpu9krea_leds, ARRAY_SIZE(cpu9krea_leds));
370         /* Push Buttons */
371         cpu9krea_add_device_buttons();
372 }
373
374 #ifdef CONFIG_MACH_CPU9260
375 MACHINE_START(CPUAT9260, "Eukrea CPU9260")
376 #else
377 MACHINE_START(CPUAT9G20, "Eukrea CPU9G20")
378 #endif
379         /* Maintainer: Eric Benard - EUKREA Electromatique */
380         .init_time      = at91_init_time,
381         .map_io         = at91_map_io,
382         .handle_irq     = at91_aic_handle_irq,
383         .init_early     = cpu9krea_init_early,
384         .init_irq       = at91_init_irq_default,
385         .init_machine   = cpu9krea_board_init,
386 MACHINE_END