]> git.karo-electronics.de Git - karo-tx-linux.git/blob - arch/arm/mach-at91/board-usb-a926x.c
Merge branch 'marvell_cleanup_for_v3.5' of git://git.infradead.org/users/jcooper...
[karo-tx-linux.git] / arch / arm / mach-at91 / board-usb-a926x.c
1 /*
2  * linux/arch/arm/mach-at91/board-usb-a926x.c
3  *
4  *  Copyright (C) 2005 SAN People
5  *  Copyright (C) 2007 Atmel Corporation.
6  *  Copyright (C) 2007 Calao-systems
7  *  Copyright (C) 2011 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
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 as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23
24 #include <linux/types.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/spi/spi.h>
30 #include <linux/gpio_keys.h>
31 #include <linux/gpio.h>
32 #include <linux/input.h>
33 #include <linux/spi/mmc_spi.h>
34
35 #include <asm/setup.h>
36 #include <asm/mach-types.h>
37 #include <asm/irq.h>
38
39 #include <asm/mach/arch.h>
40 #include <asm/mach/map.h>
41 #include <asm/mach/irq.h>
42
43 #include <mach/hardware.h>
44 #include <mach/board.h>
45 #include <mach/at91sam9_smc.h>
46 #include <mach/at91_shdwc.h>
47
48 #include "sam9_smc.h"
49 #include "generic.h"
50
51
52 static void __init ek_init_early(void)
53 {
54         /* Initialize processor: 12.00 MHz crystal */
55         at91_initialize(12000000);
56 }
57
58 /*
59  * USB Host port
60  */
61 static struct at91_usbh_data __initdata ek_usbh_data = {
62         .ports          = 2,
63         .vbus_pin       = {-EINVAL, -EINVAL},
64         .overcurrent_pin= {-EINVAL, -EINVAL},
65 };
66
67 /*
68  * USB Device port
69  */
70 static struct at91_udc_data __initdata ek_udc_data = {
71         .vbus_pin       = AT91_PIN_PB11,
72         .pullup_pin     = -EINVAL,              /* pull-up driven by UDC */
73 };
74
75 static void __init ek_add_device_udc(void)
76 {
77         if (machine_is_usb_a9260() || machine_is_usb_a9g20())
78                 ek_udc_data.vbus_pin = AT91_PIN_PC5;
79
80         at91_add_device_udc(&ek_udc_data);
81 }
82
83 #if defined(CONFIG_MMC_SPI) || defined(CONFIG_MMC_SPI_MODULE)
84 #define MMC_SPI_CARD_DETECT_INT AT91_PIN_PC4
85 static int at91_mmc_spi_init(struct device *dev,
86         irqreturn_t (*detect_int)(int, void *), void *data)
87 {
88         /* Configure Interrupt pin as input, no pull-up */
89         at91_set_gpio_input(MMC_SPI_CARD_DETECT_INT, 0);
90         return request_irq(gpio_to_irq(MMC_SPI_CARD_DETECT_INT), detect_int,
91                 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
92                 "mmc-spi-detect", data);
93 }
94
95 static void at91_mmc_spi_exit(struct device *dev, void *data)
96 {
97         free_irq(gpio_to_irq(MMC_SPI_CARD_DETECT_INT), data);
98 }
99
100 static struct mmc_spi_platform_data at91_mmc_spi_pdata = {
101         .init = at91_mmc_spi_init,
102         .exit = at91_mmc_spi_exit,
103         .detect_delay = 100, /* msecs */
104 };
105 #endif
106
107 /*
108  * SPI devices.
109  */
110 static struct spi_board_info usb_a9263_spi_devices[] = {
111 #if !defined(CONFIG_MMC_AT91)
112         {       /* DataFlash chip */
113                 .modalias       = "mtd_dataflash",
114                 .chip_select    = 0,
115                 .max_speed_hz   = 15 * 1000 * 1000,
116                 .bus_num        = 0,
117         }
118 #endif
119 };
120
121 static struct spi_board_info usb_a9g20_spi_devices[] = {
122 #if defined(CONFIG_MMC_SPI) || defined(CONFIG_MMC_SPI_MODULE)
123         {
124                 .modalias = "mmc_spi",
125                 .max_speed_hz = 20000000,       /* max spi clock (SCK) speed in HZ */
126                 .bus_num = 1,
127                 .chip_select = 0,
128                 .platform_data = &at91_mmc_spi_pdata,
129                 .mode = SPI_MODE_3,
130         },
131 #endif
132 };
133
134 static void __init ek_add_device_spi(void)
135 {
136         if (machine_is_usb_a9263())
137                 at91_add_device_spi(usb_a9263_spi_devices, ARRAY_SIZE(usb_a9263_spi_devices));
138         else if (machine_is_usb_a9g20())
139                 at91_add_device_spi(usb_a9g20_spi_devices, ARRAY_SIZE(usb_a9g20_spi_devices));
140 }
141
142 /*
143  * MACB Ethernet device
144  */
145 static struct macb_platform_data __initdata ek_macb_data = {
146         .phy_irq_pin    = AT91_PIN_PE31,
147         .is_rmii        = 1,
148 };
149
150 static void __init ek_add_device_eth(void)
151 {
152         if (machine_is_usb_a9260() || machine_is_usb_a9g20())
153                 ek_macb_data.phy_irq_pin = AT91_PIN_PA31;
154
155         at91_add_device_eth(&ek_macb_data);
156 }
157
158 /*
159  * NAND flash
160  */
161 static struct mtd_partition __initdata ek_nand_partition[] = {
162         {
163                 .name   = "barebox",
164                 .offset = 0,
165                 .size   = 3 * SZ_128K,
166         }, {
167                 .name   = "bareboxenv",
168                 .offset = MTDPART_OFS_NXTBLK,
169                 .size   = SZ_128K,
170         }, {
171                 .name   = "bareboxenv2",
172                 .offset = MTDPART_OFS_NXTBLK,
173                 .size   = SZ_128K,
174         }, {
175                 .name   = "kernel",
176                 .offset = MTDPART_OFS_NXTBLK,
177                 .size   = 4 * SZ_1M,
178         }, {
179                 .name   = "rootfs",
180                 .offset = MTDPART_OFS_NXTBLK,
181                 .size   = 120 * SZ_1M,
182         }, {
183                 .name   = "data",
184                 .offset = MTDPART_OFS_NXTBLK,
185                 .size   = MTDPART_SIZ_FULL,
186         }
187 };
188
189 static struct atmel_nand_data __initdata ek_nand_data = {
190         .ale            = 21,
191         .cle            = 22,
192         .det_pin        = -EINVAL,
193         .rdy_pin        = AT91_PIN_PA22,
194         .enable_pin     = AT91_PIN_PD15,
195         .ecc_mode       = NAND_ECC_SOFT,
196         .on_flash_bbt   = 1,
197         .parts          = ek_nand_partition,
198         .num_parts      = ARRAY_SIZE(ek_nand_partition),
199 };
200
201 static struct sam9_smc_config __initdata usb_a9260_nand_smc_config = {
202         .ncs_read_setup         = 0,
203         .nrd_setup              = 1,
204         .ncs_write_setup        = 0,
205         .nwe_setup              = 1,
206
207         .ncs_read_pulse         = 3,
208         .nrd_pulse              = 3,
209         .ncs_write_pulse        = 3,
210         .nwe_pulse              = 3,
211
212         .read_cycle             = 5,
213         .write_cycle            = 5,
214
215         .mode                   = AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_DBW_8,
216         .tdf_cycles             = 2,
217 };
218
219 static struct sam9_smc_config __initdata usb_a9g20_nand_smc_config = {
220         .ncs_read_setup         = 0,
221         .nrd_setup              = 2,
222         .ncs_write_setup        = 0,
223         .nwe_setup              = 2,
224
225         .ncs_read_pulse         = 4,
226         .nrd_pulse              = 4,
227         .ncs_write_pulse        = 4,
228         .nwe_pulse              = 4,
229
230         .read_cycle             = 7,
231         .write_cycle            = 7,
232
233         .mode                   = AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_DBW_8,
234         .tdf_cycles             = 3,
235 };
236
237 static void __init ek_add_device_nand(void)
238 {
239         if (machine_is_usb_a9260() || machine_is_usb_a9g20()) {
240                 ek_nand_data.rdy_pin    = AT91_PIN_PC13;
241                 ek_nand_data.enable_pin = AT91_PIN_PC14;
242         }
243
244         /* configure chip-select 3 (NAND) */
245         if (machine_is_usb_a9g20())
246                 sam9_smc_configure(0, 3, &usb_a9g20_nand_smc_config);
247         else
248                 sam9_smc_configure(0, 3, &usb_a9260_nand_smc_config);
249
250         at91_add_device_nand(&ek_nand_data);
251 }
252
253
254 /*
255  * GPIO Buttons
256  */
257 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
258 static struct gpio_keys_button ek_buttons[] = {
259         {       /* USER PUSH BUTTON */
260                 .code           = KEY_ENTER,
261                 .gpio           = AT91_PIN_PB10,
262                 .active_low     = 1,
263                 .desc           = "user_pb",
264                 .wakeup         = 1,
265         }
266 };
267
268 static struct gpio_keys_platform_data ek_button_data = {
269         .buttons        = ek_buttons,
270         .nbuttons       = ARRAY_SIZE(ek_buttons),
271 };
272
273 static struct platform_device ek_button_device = {
274         .name           = "gpio-keys",
275         .id             = -1,
276         .num_resources  = 0,
277         .dev            = {
278                 .platform_data  = &ek_button_data,
279         }
280 };
281
282 static void __init ek_add_device_buttons(void)
283 {
284         at91_set_GPIO_periph(AT91_PIN_PB10, 1); /* user push button, pull up enabled */
285         at91_set_deglitch(AT91_PIN_PB10, 1);
286
287         platform_device_register(&ek_button_device);
288 }
289 #else
290 static void __init ek_add_device_buttons(void) {}
291 #endif
292
293 /*
294  * LEDs
295  */
296 static struct gpio_led ek_leds[] = {
297         {       /* user_led (green) */
298                 .name                   = "user_led",
299                 .gpio                   = AT91_PIN_PB21,
300                 .active_low             = 1,
301                 .default_trigger        = "heartbeat",
302         }
303 };
304
305 static struct i2c_board_info __initdata ek_i2c_devices[] = {
306         {
307                 I2C_BOARD_INFO("rv3029c2", 0x56),
308         },
309 };
310
311 static void __init ek_add_device_leds(void)
312 {
313         if (machine_is_usb_a9260() || machine_is_usb_a9g20())
314                 ek_leds[0].active_low = 0;
315
316         at91_gpio_leds(ek_leds, ARRAY_SIZE(ek_leds));
317 }
318
319 static void __init ek_board_init(void)
320 {
321         /* Serial */
322         /* DBGU on ttyS0. (Rx & Tx only) */
323         at91_register_uart(0, 0, 0);
324         at91_add_device_serial();
325         /* USB Host */
326         at91_add_device_usbh(&ek_usbh_data);
327         /* USB Device */
328         ek_add_device_udc();
329         /* SPI */
330         ek_add_device_spi();
331         /* Ethernet */
332         ek_add_device_eth();
333         /* NAND */
334         ek_add_device_nand();
335         /* Push Buttons */
336         ek_add_device_buttons();
337         /* LEDs */
338         ek_add_device_leds();
339
340         if (machine_is_usb_a9g20()) {
341                 /* I2C */
342                 at91_add_device_i2c(ek_i2c_devices, ARRAY_SIZE(ek_i2c_devices));
343         } else {
344                 /* I2C */
345                 at91_add_device_i2c(NULL, 0);
346                 /* shutdown controller, wakeup button (5 msec low) */
347                 at91_shdwc_write(AT91_SHDW_MR, AT91_SHDW_CPTWK0_(10)
348                                 | AT91_SHDW_WKMODE0_LOW
349                                 | AT91_SHDW_RTTWKEN);
350         }
351 }
352
353 MACHINE_START(USB_A9263, "CALAO USB_A9263")
354         /* Maintainer: calao-systems */
355         .timer          = &at91sam926x_timer,
356         .map_io         = at91_map_io,
357         .init_early     = ek_init_early,
358         .init_irq       = at91_init_irq_default,
359         .init_machine   = ek_board_init,
360 MACHINE_END
361
362 MACHINE_START(USB_A9260, "CALAO USB_A9260")
363         /* Maintainer: calao-systems */
364         .timer          = &at91sam926x_timer,
365         .map_io         = at91_map_io,
366         .init_early     = ek_init_early,
367         .init_irq       = at91_init_irq_default,
368         .init_machine   = ek_board_init,
369 MACHINE_END
370
371 MACHINE_START(USB_A9G20, "CALAO USB_A92G0")
372         /* Maintainer: Jean-Christophe PLAGNIOL-VILLARD */
373         .timer          = &at91sam926x_timer,
374         .map_io         = at91_map_io,
375         .init_early     = ek_init_early,
376         .init_irq       = at91_init_irq_default,
377         .init_machine   = ek_board_init,
378 MACHINE_END