Merge branch 'sh-latest' of git://github.com/pmundt/linux-sh
[pandora-kernel.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         /* DBGU on ttyS0. (Rx & Tx only) */
58         at91_register_uart(0, 0, 0);
59
60         /* set serial console to ttyS0 (ie, DBGU) */
61         at91_set_serial_console(0);
62 }
63
64 /*
65  * USB Host port
66  */
67 static struct at91_usbh_data __initdata ek_usbh_data = {
68         .ports          = 2,
69 };
70
71 /*
72  * USB Device port
73  */
74 static struct at91_udc_data __initdata ek_udc_data = {
75         .vbus_pin       = AT91_PIN_PB11,
76         .pullup_pin     = 0,            /* pull-up driven by UDC */
77 };
78
79 static void __init ek_add_device_udc(void)
80 {
81         if (machine_is_usb_a9260() || machine_is_usb_a9g20())
82                 ek_udc_data.vbus_pin = AT91_PIN_PC5;
83
84         at91_add_device_udc(&ek_udc_data);
85 }
86
87 #if defined(CONFIG_MMC_SPI) || defined(CONFIG_MMC_SPI_MODULE)
88 #define MMC_SPI_CARD_DETECT_INT AT91_PIN_PC4
89 static int at91_mmc_spi_init(struct device *dev,
90         irqreturn_t (*detect_int)(int, void *), void *data)
91 {
92         /* Configure Interrupt pin as input, no pull-up */
93         at91_set_gpio_input(MMC_SPI_CARD_DETECT_INT, 0);
94         return request_irq(gpio_to_irq(MMC_SPI_CARD_DETECT_INT), detect_int,
95                 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
96                 "mmc-spi-detect", data);
97 }
98
99 static void at91_mmc_spi_exit(struct device *dev, void *data)
100 {
101         free_irq(gpio_to_irq(MMC_SPI_CARD_DETECT_INT), data);
102 }
103
104 static struct mmc_spi_platform_data at91_mmc_spi_pdata = {
105         .init = at91_mmc_spi_init,
106         .exit = at91_mmc_spi_exit,
107         .detect_delay = 100, /* msecs */
108 };
109 #endif
110
111 /*
112  * SPI devices.
113  */
114 static struct spi_board_info usb_a9263_spi_devices[] = {
115 #if !defined(CONFIG_MMC_AT91)
116         {       /* DataFlash chip */
117                 .modalias       = "mtd_dataflash",
118                 .chip_select    = 0,
119                 .max_speed_hz   = 15 * 1000 * 1000,
120                 .bus_num        = 0,
121         }
122 #endif
123 };
124
125 static struct spi_board_info usb_a9g20_spi_devices[] = {
126 #if defined(CONFIG_MMC_SPI) || defined(CONFIG_MMC_SPI_MODULE)
127         {
128                 .modalias = "mmc_spi",
129                 .max_speed_hz = 20000000,       /* max spi clock (SCK) speed in HZ */
130                 .bus_num = 1,
131                 .chip_select = 0,
132                 .platform_data = &at91_mmc_spi_pdata,
133                 .mode = SPI_MODE_3,
134         },
135 #endif
136 };
137
138 static void __init ek_add_device_spi(void)
139 {
140         if (machine_is_usb_a9263())
141                 at91_add_device_spi(usb_a9263_spi_devices, ARRAY_SIZE(usb_a9263_spi_devices));
142         else if (machine_is_usb_a9g20())
143                 at91_add_device_spi(usb_a9g20_spi_devices, ARRAY_SIZE(usb_a9g20_spi_devices));
144 }
145
146 /*
147  * MACB Ethernet device
148  */
149 static struct at91_eth_data __initdata ek_macb_data = {
150         .phy_irq_pin    = AT91_PIN_PE31,
151         .is_rmii        = 1,
152 };
153
154 static void __init ek_add_device_eth(void)
155 {
156         if (machine_is_usb_a9260() || machine_is_usb_a9g20())
157                 ek_macb_data.phy_irq_pin = AT91_PIN_PA31;
158
159         at91_add_device_eth(&ek_macb_data);
160 }
161
162 /*
163  * NAND flash
164  */
165 static struct mtd_partition __initdata ek_nand_partition[] = {
166         {
167                 .name   = "barebox",
168                 .offset = 0,
169                 .size   = 3 * SZ_128K,
170         }, {
171                 .name   = "bareboxenv",
172                 .offset = MTDPART_OFS_NXTBLK,
173                 .size   = SZ_128K,
174         }, {
175                 .name   = "bareboxenv2",
176                 .offset = MTDPART_OFS_NXTBLK,
177                 .size   = SZ_128K,
178         }, {
179                 .name   = "kernel",
180                 .offset = MTDPART_OFS_NXTBLK,
181                 .size   = 4 * SZ_1M,
182         }, {
183                 .name   = "rootfs",
184                 .offset = MTDPART_OFS_NXTBLK,
185                 .size   = 120 * SZ_1M,
186         }, {
187                 .name   = "data",
188                 .offset = MTDPART_OFS_NXTBLK,
189                 .size   = MTDPART_SIZ_FULL,
190         }
191 };
192
193 static struct mtd_partition * __init nand_partitions(int size, int *num_partitions)
194 {
195         *num_partitions = ARRAY_SIZE(ek_nand_partition);
196         return ek_nand_partition;
197 }
198
199 static struct atmel_nand_data __initdata ek_nand_data = {
200         .ale            = 21,
201         .cle            = 22,
202 //      .det_pin        = ... not connected
203         .rdy_pin        = AT91_PIN_PA22,
204         .enable_pin     = AT91_PIN_PD15,
205         .partition_info = nand_partitions,
206 };
207
208 static struct sam9_smc_config __initdata usb_a9260_nand_smc_config = {
209         .ncs_read_setup         = 0,
210         .nrd_setup              = 1,
211         .ncs_write_setup        = 0,
212         .nwe_setup              = 1,
213
214         .ncs_read_pulse         = 3,
215         .nrd_pulse              = 3,
216         .ncs_write_pulse        = 3,
217         .nwe_pulse              = 3,
218
219         .read_cycle             = 5,
220         .write_cycle            = 5,
221
222         .mode                   = AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_DBW_8,
223         .tdf_cycles             = 2,
224 };
225
226 static struct sam9_smc_config __initdata usb_a9g20_nand_smc_config = {
227         .ncs_read_setup         = 0,
228         .nrd_setup              = 2,
229         .ncs_write_setup        = 0,
230         .nwe_setup              = 2,
231
232         .ncs_read_pulse         = 4,
233         .nrd_pulse              = 4,
234         .ncs_write_pulse        = 4,
235         .nwe_pulse              = 4,
236
237         .read_cycle             = 7,
238         .write_cycle            = 7,
239
240         .mode                   = AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_DBW_8,
241         .tdf_cycles             = 3,
242 };
243
244 static void __init ek_add_device_nand(void)
245 {
246         if (machine_is_usb_a9260() || machine_is_usb_a9g20()) {
247                 ek_nand_data.rdy_pin    = AT91_PIN_PC13;
248                 ek_nand_data.enable_pin = AT91_PIN_PC14;
249         }
250
251         /* configure chip-select 3 (NAND) */
252         if (machine_is_usb_a9g20())
253                 sam9_smc_configure(3, &usb_a9g20_nand_smc_config);
254         else
255                 sam9_smc_configure(3, &usb_a9260_nand_smc_config);
256
257         at91_add_device_nand(&ek_nand_data);
258 }
259
260
261 /*
262  * GPIO Buttons
263  */
264 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
265 static struct gpio_keys_button ek_buttons[] = {
266         {       /* USER PUSH BUTTON */
267                 .code           = KEY_ENTER,
268                 .gpio           = AT91_PIN_PB10,
269                 .active_low     = 1,
270                 .desc           = "user_pb",
271                 .wakeup         = 1,
272         }
273 };
274
275 static struct gpio_keys_platform_data ek_button_data = {
276         .buttons        = ek_buttons,
277         .nbuttons       = ARRAY_SIZE(ek_buttons),
278 };
279
280 static struct platform_device ek_button_device = {
281         .name           = "gpio-keys",
282         .id             = -1,
283         .num_resources  = 0,
284         .dev            = {
285                 .platform_data  = &ek_button_data,
286         }
287 };
288
289 static void __init ek_add_device_buttons(void)
290 {
291         at91_set_GPIO_periph(AT91_PIN_PB10, 1); /* user push button, pull up enabled */
292         at91_set_deglitch(AT91_PIN_PB10, 1);
293
294         platform_device_register(&ek_button_device);
295 }
296 #else
297 static void __init ek_add_device_buttons(void) {}
298 #endif
299
300 /*
301  * LEDs
302  */
303 static struct gpio_led ek_leds[] = {
304         {       /* user_led (green) */
305                 .name                   = "user_led",
306                 .gpio                   = AT91_PIN_PB21,
307                 .active_low             = 1,
308                 .default_trigger        = "heartbeat",
309         }
310 };
311
312 static struct i2c_board_info __initdata ek_i2c_devices[] = {
313         {
314                 I2C_BOARD_INFO("rv3029c2", 0x56),
315         },
316 };
317
318 static void __init ek_add_device_leds(void)
319 {
320         if (machine_is_usb_a9260() || machine_is_usb_a9g20())
321                 ek_leds[0].active_low = 0;
322
323         at91_gpio_leds(ek_leds, ARRAY_SIZE(ek_leds));
324 }
325
326 static void __init ek_board_init(void)
327 {
328         /* Serial */
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_sys_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         .init_early     = ek_init_early,
363         .init_irq       = at91_init_irq_default,
364         .init_machine   = ek_board_init,
365 MACHINE_END
366
367 MACHINE_START(USB_A9260, "CALAO USB_A9260")
368         /* Maintainer: calao-systems */
369         .timer          = &at91sam926x_timer,
370         .map_io         = at91_map_io,
371         .init_early     = ek_init_early,
372         .init_irq       = at91_init_irq_default,
373         .init_machine   = ek_board_init,
374 MACHINE_END
375
376 MACHINE_START(USB_A9G20, "CALAO USB_A92G0")
377         /* Maintainer: Jean-Christophe PLAGNIOL-VILLARD */
378         .timer          = &at91sam926x_timer,
379         .map_io         = at91_map_io,
380         .init_early     = ek_init_early,
381         .init_irq       = at91_init_irq_default,
382         .init_machine   = ek_board_init,
383 MACHINE_END