blob: 26c36fc2d1e539b8c0c5d31ffd281a32f9ba587d [file] [log] [blame]
Andrew Victorca0a7892008-05-24 17:47:04 +01001/*
Nico Erfurth6939fd42011-08-30 18:25:52 +02002 * linux/arch/arm/mach-at91/board-usb-a926x.c
Andrew Victorca0a7892008-05-24 17:47:04 +01003 *
4 * Copyright (C) 2005 SAN People
5 * Copyright (C) 2007 Atmel Corporation.
6 * Copyright (C) 2007 Calao-systems
Jean-Christophe PLAGNIOL-VILLARD0a072a22011-08-30 18:25:53 +02007 * Copyright (C) 2011 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Andrew Victorca0a7892008-05-24 17:47:04 +01008 *
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>
Arnd Bergmann33533272011-10-21 16:46:26 +020031#include <linux/gpio.h>
Andrew Victorca0a7892008-05-24 17:47:04 +010032#include <linux/input.h>
Jean-Christophe PLAGNIOL-VILLARD0a072a22011-08-30 18:25:53 +020033#include <linux/spi/mmc_spi.h>
Andrew Victorca0a7892008-05-24 17:47:04 +010034
Andrew Victorca0a7892008-05-24 17:47:04 +010035#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
Andrew Victore5052402008-09-21 21:30:02 +010043#include <mach/hardware.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010044#include <mach/board.h>
Andrew Victor8cdae512008-10-06 20:05:35 +010045#include <mach/at91sam9_smc.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010046#include <mach/at91_shdwc.h>
Andrew Victorca0a7892008-05-24 17:47:04 +010047
Andrew Victor8cdae512008-10-06 20:05:35 +010048#include "sam9_smc.h"
Andrew Victorca0a7892008-05-24 17:47:04 +010049#include "generic.h"
50
51
Jean-Christophe PLAGNIOL-VILLARD1b021a32011-04-28 20:19:32 +080052static void __init ek_init_early(void)
Andrew Victorca0a7892008-05-24 17:47:04 +010053{
54 /* Initialize processor: 12.00 MHz crystal */
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +080055 at91_initialize(12000000);
Andrew Victorca0a7892008-05-24 17:47:04 +010056
Samuel R. C. Vale4f379402009-07-10 12:07:15 -030057 /* DBGU on ttyS0. (Rx & Tx only) */
Andrew Victorca0a7892008-05-24 17:47:04 +010058 at91_register_uart(0, 0, 0);
59
60 /* set serial console to ttyS0 (ie, DBGU) */
61 at91_set_serial_console(0);
62}
63
Andrew Victorca0a7892008-05-24 17:47:04 +010064/*
65 * USB Host port
66 */
67static struct at91_usbh_data __initdata ek_usbh_data = {
68 .ports = 2,
Jean-Christophe PLAGNIOL-VILLARD63b4c292011-11-25 01:51:06 +080069 .vbus_pin = {-EINVAL, -EINVAL},
70 .overcurrent_pin= {-EINVAL, -EINVAL},
Andrew Victorca0a7892008-05-24 17:47:04 +010071};
72
73/*
74 * USB Device port
75 */
76static struct at91_udc_data __initdata ek_udc_data = {
77 .vbus_pin = AT91_PIN_PB11,
Jean-Christophe PLAGNIOL-VILLARD63b4c292011-11-25 01:51:06 +080078 .pullup_pin = -EINVAL, /* pull-up driven by UDC */
Andrew Victorca0a7892008-05-24 17:47:04 +010079};
80
Jean-Christophe PLAGNIOL-VILLARD0a072a22011-08-30 18:25:53 +020081static void __init ek_add_device_udc(void)
Nico Erfurth6939fd42011-08-30 18:25:52 +020082{
Jean-Christophe PLAGNIOL-VILLARD0a072a22011-08-30 18:25:53 +020083 if (machine_is_usb_a9260() || machine_is_usb_a9g20())
Nico Erfurth6939fd42011-08-30 18:25:52 +020084 ek_udc_data.vbus_pin = AT91_PIN_PC5;
85
86 at91_add_device_udc(&ek_udc_data);
87}
88
Jean-Christophe PLAGNIOL-VILLARD0a072a22011-08-30 18:25:53 +020089#if defined(CONFIG_MMC_SPI) || defined(CONFIG_MMC_SPI_MODULE)
90#define MMC_SPI_CARD_DETECT_INT AT91_PIN_PC4
91static int at91_mmc_spi_init(struct device *dev,
92 irqreturn_t (*detect_int)(int, void *), void *data)
93{
94 /* Configure Interrupt pin as input, no pull-up */
95 at91_set_gpio_input(MMC_SPI_CARD_DETECT_INT, 0);
96 return request_irq(gpio_to_irq(MMC_SPI_CARD_DETECT_INT), detect_int,
97 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
98 "mmc-spi-detect", data);
99}
100
101static void at91_mmc_spi_exit(struct device *dev, void *data)
102{
103 free_irq(gpio_to_irq(MMC_SPI_CARD_DETECT_INT), data);
104}
105
106static struct mmc_spi_platform_data at91_mmc_spi_pdata = {
107 .init = at91_mmc_spi_init,
108 .exit = at91_mmc_spi_exit,
109 .detect_delay = 100, /* msecs */
110};
111#endif
112
Andrew Victorca0a7892008-05-24 17:47:04 +0100113/*
114 * SPI devices.
115 */
Jean-Christophe PLAGNIOL-VILLARD0a072a22011-08-30 18:25:53 +0200116static struct spi_board_info usb_a9263_spi_devices[] = {
Andrew Victorca0a7892008-05-24 17:47:04 +0100117#if !defined(CONFIG_MMC_AT91)
118 { /* DataFlash chip */
119 .modalias = "mtd_dataflash",
120 .chip_select = 0,
121 .max_speed_hz = 15 * 1000 * 1000,
122 .bus_num = 0,
123 }
124#endif
125};
126
Jean-Christophe PLAGNIOL-VILLARD0a072a22011-08-30 18:25:53 +0200127static struct spi_board_info usb_a9g20_spi_devices[] = {
128#if defined(CONFIG_MMC_SPI) || defined(CONFIG_MMC_SPI_MODULE)
129 {
130 .modalias = "mmc_spi",
131 .max_speed_hz = 20000000, /* max spi clock (SCK) speed in HZ */
132 .bus_num = 1,
133 .chip_select = 0,
134 .platform_data = &at91_mmc_spi_pdata,
135 .mode = SPI_MODE_3,
136 },
137#endif
138};
139
140static void __init ek_add_device_spi(void)
Nico Erfurth6939fd42011-08-30 18:25:52 +0200141{
142 if (machine_is_usb_a9263())
Jean-Christophe PLAGNIOL-VILLARD0a072a22011-08-30 18:25:53 +0200143 at91_add_device_spi(usb_a9263_spi_devices, ARRAY_SIZE(usb_a9263_spi_devices));
144 else if (machine_is_usb_a9g20())
145 at91_add_device_spi(usb_a9g20_spi_devices, ARRAY_SIZE(usb_a9g20_spi_devices));
Nico Erfurth6939fd42011-08-30 18:25:52 +0200146}
147
Andrew Victorca0a7892008-05-24 17:47:04 +0100148/*
149 * MACB Ethernet device
150 */
Jamie Iles84e0cdb2011-03-08 20:17:06 +0000151static struct macb_platform_data __initdata ek_macb_data = {
Andrew Victorca0a7892008-05-24 17:47:04 +0100152 .phy_irq_pin = AT91_PIN_PE31,
153 .is_rmii = 1,
154};
155
Jean-Christophe PLAGNIOL-VILLARD0a072a22011-08-30 18:25:53 +0200156static void __init ek_add_device_eth(void)
Nico Erfurth6939fd42011-08-30 18:25:52 +0200157{
Jean-Christophe PLAGNIOL-VILLARD0a072a22011-08-30 18:25:53 +0200158 if (machine_is_usb_a9260() || machine_is_usb_a9g20())
Nico Erfurth6939fd42011-08-30 18:25:52 +0200159 ek_macb_data.phy_irq_pin = AT91_PIN_PA31;
160
161 at91_add_device_eth(&ek_macb_data);
162}
163
Andrew Victorca0a7892008-05-24 17:47:04 +0100164/*
165 * NAND flash
166 */
167static struct mtd_partition __initdata ek_nand_partition[] = {
168 {
Jean-Christophe PLAGNIOL-VILLARD0a072a22011-08-30 18:25:53 +0200169 .name = "barebox",
Andrew Victore5052402008-09-21 21:30:02 +0100170 .offset = 0,
Jean-Christophe PLAGNIOL-VILLARD0a072a22011-08-30 18:25:53 +0200171 .size = 3 * SZ_128K,
172 }, {
173 .name = "bareboxenv",
174 .offset = MTDPART_OFS_NXTBLK,
175 .size = SZ_128K,
176 }, {
177 .name = "bareboxenv2",
178 .offset = MTDPART_OFS_NXTBLK,
179 .size = SZ_128K,
180 }, {
181 .name = "kernel",
182 .offset = MTDPART_OFS_NXTBLK,
183 .size = 4 * SZ_1M,
184 }, {
185 .name = "rootfs",
Andrew Victore5052402008-09-21 21:30:02 +0100186 .offset = MTDPART_OFS_NXTBLK,
187 .size = 120 * SZ_1M,
Jean-Christophe PLAGNIOL-VILLARD0a072a22011-08-30 18:25:53 +0200188 }, {
189 .name = "data",
Andrew Victore5052402008-09-21 21:30:02 +0100190 .offset = MTDPART_OFS_NXTBLK,
Jean-Christophe PLAGNIOL-VILLARD0a072a22011-08-30 18:25:53 +0200191 .size = MTDPART_SIZ_FULL,
Andrew Victorca0a7892008-05-24 17:47:04 +0100192 }
193};
194
Haavard Skinnemoen7c896832008-07-28 16:57:22 +0100195static struct atmel_nand_data __initdata ek_nand_data = {
Andrew Victorca0a7892008-05-24 17:47:04 +0100196 .ale = 21,
197 .cle = 22,
Jean-Christophe PLAGNIOL-VILLARD63b4c292011-11-25 01:51:06 +0800198 .det_pin = -EINVAL,
Andrew Victorca0a7892008-05-24 17:47:04 +0100199 .rdy_pin = AT91_PIN_PA22,
200 .enable_pin = AT91_PIN_PD15,
Linus Torvaldse0d65112011-11-07 09:11:16 -0800201 .parts = ek_nand_partition,
202 .num_parts = ARRAY_SIZE(ek_nand_partition),
Andrew Victorca0a7892008-05-24 17:47:04 +0100203};
204
Jean-Christophe PLAGNIOL-VILLARD0a072a22011-08-30 18:25:53 +0200205static struct sam9_smc_config __initdata usb_a9260_nand_smc_config = {
Andrew Victor8cdae512008-10-06 20:05:35 +0100206 .ncs_read_setup = 0,
207 .nrd_setup = 1,
208 .ncs_write_setup = 0,
209 .nwe_setup = 1,
210
211 .ncs_read_pulse = 3,
212 .nrd_pulse = 3,
213 .ncs_write_pulse = 3,
214 .nwe_pulse = 3,
215
216 .read_cycle = 5,
217 .write_cycle = 5,
218
219 .mode = AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_DBW_8,
220 .tdf_cycles = 2,
221};
222
Jean-Christophe PLAGNIOL-VILLARD0a072a22011-08-30 18:25:53 +0200223static struct sam9_smc_config __initdata usb_a9g20_nand_smc_config = {
224 .ncs_read_setup = 0,
225 .nrd_setup = 2,
226 .ncs_write_setup = 0,
227 .nwe_setup = 2,
228
229 .ncs_read_pulse = 4,
230 .nrd_pulse = 4,
231 .ncs_write_pulse = 4,
232 .nwe_pulse = 4,
233
234 .read_cycle = 7,
235 .write_cycle = 7,
236
237 .mode = AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_DBW_8,
238 .tdf_cycles = 3,
239};
240
Andrew Victor8cdae512008-10-06 20:05:35 +0100241static void __init ek_add_device_nand(void)
242{
Jean-Christophe PLAGNIOL-VILLARD0a072a22011-08-30 18:25:53 +0200243 if (machine_is_usb_a9260() || machine_is_usb_a9g20()) {
Nico Erfurth6939fd42011-08-30 18:25:52 +0200244 ek_nand_data.rdy_pin = AT91_PIN_PC13;
245 ek_nand_data.enable_pin = AT91_PIN_PC14;
246 }
247
Andrew Victor8cdae512008-10-06 20:05:35 +0100248 /* configure chip-select 3 (NAND) */
Jean-Christophe PLAGNIOL-VILLARD0a072a22011-08-30 18:25:53 +0200249 if (machine_is_usb_a9g20())
Jean-Christophe PLAGNIOL-VILLARDfaee0cc2011-10-14 01:37:09 +0800250 sam9_smc_configure(0, 3, &usb_a9g20_nand_smc_config);
Jean-Christophe PLAGNIOL-VILLARD0a072a22011-08-30 18:25:53 +0200251 else
Jean-Christophe PLAGNIOL-VILLARDfaee0cc2011-10-14 01:37:09 +0800252 sam9_smc_configure(0, 3, &usb_a9260_nand_smc_config);
Andrew Victor8cdae512008-10-06 20:05:35 +0100253
254 at91_add_device_nand(&ek_nand_data);
255}
256
257
Andrew Victorca0a7892008-05-24 17:47:04 +0100258/*
259 * GPIO Buttons
260 */
261#if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
262static struct gpio_keys_button ek_buttons[] = {
263 { /* USER PUSH BUTTON */
264 .code = KEY_ENTER,
265 .gpio = AT91_PIN_PB10,
266 .active_low = 1,
267 .desc = "user_pb",
268 .wakeup = 1,
269 }
270};
271
272static struct gpio_keys_platform_data ek_button_data = {
273 .buttons = ek_buttons,
274 .nbuttons = ARRAY_SIZE(ek_buttons),
275};
276
277static struct platform_device ek_button_device = {
278 .name = "gpio-keys",
279 .id = -1,
280 .num_resources = 0,
281 .dev = {
282 .platform_data = &ek_button_data,
283 }
284};
285
286static void __init ek_add_device_buttons(void)
287{
288 at91_set_GPIO_periph(AT91_PIN_PB10, 1); /* user push button, pull up enabled */
289 at91_set_deglitch(AT91_PIN_PB10, 1);
290
291 platform_device_register(&ek_button_device);
292}
293#else
294static void __init ek_add_device_buttons(void) {}
295#endif
296
297/*
298 * LEDs
299 */
300static struct gpio_led ek_leds[] = {
301 { /* user_led (green) */
302 .name = "user_led",
303 .gpio = AT91_PIN_PB21,
304 .active_low = 1,
305 .default_trigger = "heartbeat",
306 }
307};
308
Jean-Christophe PLAGNIOL-VILLARD0a072a22011-08-30 18:25:53 +0200309static struct i2c_board_info __initdata ek_i2c_devices[] = {
310 {
311 I2C_BOARD_INFO("rv3029c2", 0x56),
312 },
313};
314
315static void __init ek_add_device_leds(void)
Nico Erfurth6939fd42011-08-30 18:25:52 +0200316{
Jean-Christophe PLAGNIOL-VILLARD0a072a22011-08-30 18:25:53 +0200317 if (machine_is_usb_a9260() || machine_is_usb_a9g20())
Nico Erfurth6939fd42011-08-30 18:25:52 +0200318 ek_leds[0].active_low = 0;
319
320 at91_gpio_leds(ek_leds, ARRAY_SIZE(ek_leds));
321}
322
Andrew Victorca0a7892008-05-24 17:47:04 +0100323static void __init ek_board_init(void)
324{
325 /* Serial */
326 at91_add_device_serial();
327 /* USB Host */
328 at91_add_device_usbh(&ek_usbh_data);
329 /* USB Device */
Nico Erfurth6939fd42011-08-30 18:25:52 +0200330 ek_add_device_udc();
Andrew Victorca0a7892008-05-24 17:47:04 +0100331 /* SPI */
Nico Erfurth6939fd42011-08-30 18:25:52 +0200332 ek_add_device_spi();
Andrew Victorca0a7892008-05-24 17:47:04 +0100333 /* Ethernet */
Nico Erfurth6939fd42011-08-30 18:25:52 +0200334 ek_add_device_eth();
Andrew Victorca0a7892008-05-24 17:47:04 +0100335 /* NAND */
Andrew Victor8cdae512008-10-06 20:05:35 +0100336 ek_add_device_nand();
Andrew Victorca0a7892008-05-24 17:47:04 +0100337 /* Push Buttons */
338 ek_add_device_buttons();
339 /* LEDs */
Nico Erfurth6939fd42011-08-30 18:25:52 +0200340 ek_add_device_leds();
Jean-Christophe PLAGNIOL-VILLARD0a072a22011-08-30 18:25:53 +0200341
342 if (machine_is_usb_a9g20()) {
343 /* I2C */
344 at91_add_device_i2c(ek_i2c_devices, ARRAY_SIZE(ek_i2c_devices));
345 } else {
346 /* I2C */
347 at91_add_device_i2c(NULL, 0);
348 /* shutdown controller, wakeup button (5 msec low) */
Jean-Christophe PLAGNIOL-VILLARDf22deee2011-11-01 01:23:20 +0800349 at91_shdwc_write(AT91_SHDW_MR, AT91_SHDW_CPTWK0_(10)
Jean-Christophe PLAGNIOL-VILLARD0a072a22011-08-30 18:25:53 +0200350 | AT91_SHDW_WKMODE0_LOW
Andrew Victorca0a7892008-05-24 17:47:04 +0100351 | AT91_SHDW_RTTWKEN);
Jean-Christophe PLAGNIOL-VILLARD0a072a22011-08-30 18:25:53 +0200352 }
Andrew Victorca0a7892008-05-24 17:47:04 +0100353}
354
355MACHINE_START(USB_A9263, "CALAO USB_A9263")
356 /* Maintainer: calao-systems */
Andrew Victorca0a7892008-05-24 17:47:04 +0100357 .timer = &at91sam926x_timer,
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +0800358 .map_io = at91_map_io,
Jean-Christophe PLAGNIOL-VILLARD1b021a32011-04-28 20:19:32 +0800359 .init_early = ek_init_early,
Jean-Christophe PLAGNIOL-VILLARD92100c12011-04-23 15:28:34 +0800360 .init_irq = at91_init_irq_default,
Andrew Victorca0a7892008-05-24 17:47:04 +0100361 .init_machine = ek_board_init,
362MACHINE_END
Nico Erfurth6939fd42011-08-30 18:25:52 +0200363
364MACHINE_START(USB_A9260, "CALAO USB_A9260")
365 /* Maintainer: calao-systems */
366 .timer = &at91sam926x_timer,
367 .map_io = at91_map_io,
368 .init_early = ek_init_early,
369 .init_irq = at91_init_irq_default,
370 .init_machine = ek_board_init,
371MACHINE_END
Jean-Christophe PLAGNIOL-VILLARD0a072a22011-08-30 18:25:53 +0200372
373MACHINE_START(USB_A9G20, "CALAO USB_A92G0")
374 /* Maintainer: Jean-Christophe PLAGNIOL-VILLARD */
375 .timer = &at91sam926x_timer,
376 .map_io = at91_map_io,
377 .init_early = ek_init_early,
378 .init_irq = at91_init_irq_default,
379 .init_machine = ek_board_init,
380MACHINE_END