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