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 
ek_init_early(void)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 	.vbus_pin	= {-EINVAL, -EINVAL},
70 	.overcurrent_pin= {-EINVAL, -EINVAL},
71 };
72 
73 /*
74  * USB Device port
75  */
76 static struct at91_udc_data __initdata ek_udc_data = {
77 	.vbus_pin	= AT91_PIN_PB11,
78 	.pullup_pin	= -EINVAL,		/* pull-up driven by UDC */
79 };
80 
ek_add_device_udc(void)81 static void __init ek_add_device_udc(void)
82 {
83 	if (machine_is_usb_a9260() || machine_is_usb_a9g20())
84 		ek_udc_data.vbus_pin = AT91_PIN_PC5;
85 
86 	at91_add_device_udc(&ek_udc_data);
87 }
88 
89 #if defined(CONFIG_MMC_SPI) || defined(CONFIG_MMC_SPI_MODULE)
90 #define MMC_SPI_CARD_DETECT_INT AT91_PIN_PC4
at91_mmc_spi_init(struct device * dev,irqreturn_t (* detect_int)(int,void *),void * data)91 static 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 
at91_mmc_spi_exit(struct device * dev,void * data)101 static 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 
106 static 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 
113 /*
114  * SPI devices.
115  */
116 static struct spi_board_info usb_a9263_spi_devices[] = {
117 #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 
127 static 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 
ek_add_device_spi(void)140 static void __init ek_add_device_spi(void)
141 {
142 	if (machine_is_usb_a9263())
143 		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));
146 }
147 
148 /*
149  * MACB Ethernet device
150  */
151 static struct macb_platform_data __initdata ek_macb_data = {
152 	.phy_irq_pin	= AT91_PIN_PE31,
153 	.is_rmii	= 1,
154 };
155 
ek_add_device_eth(void)156 static void __init ek_add_device_eth(void)
157 {
158 	if (machine_is_usb_a9260() || machine_is_usb_a9g20())
159 		ek_macb_data.phy_irq_pin = AT91_PIN_PA31;
160 
161 	at91_add_device_eth(&ek_macb_data);
162 }
163 
164 /*
165  * NAND flash
166  */
167 static struct mtd_partition __initdata ek_nand_partition[] = {
168 	{
169 		.name	= "barebox",
170 		.offset	= 0,
171 		.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",
186 		.offset	= MTDPART_OFS_NXTBLK,
187 		.size	= 120 * SZ_1M,
188 	}, {
189 		.name	= "data",
190 		.offset	= MTDPART_OFS_NXTBLK,
191 		.size	= MTDPART_SIZ_FULL,
192 	}
193 };
194 
195 static struct atmel_nand_data __initdata ek_nand_data = {
196 	.ale		= 21,
197 	.cle		= 22,
198 	.det_pin	= -EINVAL,
199 	.rdy_pin	= AT91_PIN_PA22,
200 	.enable_pin	= AT91_PIN_PD15,
201 	.ecc_mode	= NAND_ECC_SOFT,
202 	.on_flash_bbt	= 1,
203 	.parts		= ek_nand_partition,
204 	.num_parts	= ARRAY_SIZE(ek_nand_partition),
205 };
206 
207 static struct sam9_smc_config __initdata usb_a9260_nand_smc_config = {
208 	.ncs_read_setup		= 0,
209 	.nrd_setup		= 1,
210 	.ncs_write_setup	= 0,
211 	.nwe_setup		= 1,
212 
213 	.ncs_read_pulse		= 3,
214 	.nrd_pulse		= 3,
215 	.ncs_write_pulse	= 3,
216 	.nwe_pulse		= 3,
217 
218 	.read_cycle		= 5,
219 	.write_cycle		= 5,
220 
221 	.mode			= AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_DBW_8,
222 	.tdf_cycles		= 2,
223 };
224 
225 static struct sam9_smc_config __initdata usb_a9g20_nand_smc_config = {
226 	.ncs_read_setup		= 0,
227 	.nrd_setup		= 2,
228 	.ncs_write_setup	= 0,
229 	.nwe_setup		= 2,
230 
231 	.ncs_read_pulse		= 4,
232 	.nrd_pulse		= 4,
233 	.ncs_write_pulse	= 4,
234 	.nwe_pulse		= 4,
235 
236 	.read_cycle		= 7,
237 	.write_cycle		= 7,
238 
239 	.mode			= AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_DBW_8,
240 	.tdf_cycles		= 3,
241 };
242 
ek_add_device_nand(void)243 static void __init ek_add_device_nand(void)
244 {
245 	if (machine_is_usb_a9260() || machine_is_usb_a9g20()) {
246 		ek_nand_data.rdy_pin	= AT91_PIN_PC13;
247 		ek_nand_data.enable_pin	= AT91_PIN_PC14;
248 	}
249 
250 	/* configure chip-select 3 (NAND) */
251 	if (machine_is_usb_a9g20())
252 		sam9_smc_configure(0, 3, &usb_a9g20_nand_smc_config);
253 	else
254 		sam9_smc_configure(0, 3, &usb_a9260_nand_smc_config);
255 
256 	at91_add_device_nand(&ek_nand_data);
257 }
258 
259 
260 /*
261  * GPIO Buttons
262  */
263 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
264 static struct gpio_keys_button ek_buttons[] = {
265 	{	/* USER PUSH BUTTON */
266 		.code		= KEY_ENTER,
267 		.gpio		= AT91_PIN_PB10,
268 		.active_low	= 1,
269 		.desc		= "user_pb",
270 		.wakeup		= 1,
271 	}
272 };
273 
274 static struct gpio_keys_platform_data ek_button_data = {
275 	.buttons	= ek_buttons,
276 	.nbuttons	= ARRAY_SIZE(ek_buttons),
277 };
278 
279 static struct platform_device ek_button_device = {
280 	.name		= "gpio-keys",
281 	.id		= -1,
282 	.num_resources	= 0,
283 	.dev		= {
284 		.platform_data	= &ek_button_data,
285 	}
286 };
287 
ek_add_device_buttons(void)288 static void __init ek_add_device_buttons(void)
289 {
290 	at91_set_GPIO_periph(AT91_PIN_PB10, 1);	/* user push button, pull up enabled */
291 	at91_set_deglitch(AT91_PIN_PB10, 1);
292 
293 	platform_device_register(&ek_button_device);
294 }
295 #else
ek_add_device_buttons(void)296 static void __init ek_add_device_buttons(void) {}
297 #endif
298 
299 /*
300  * LEDs
301  */
302 static struct gpio_led ek_leds[] = {
303 	{	/* user_led (green) */
304 		.name			= "user_led",
305 		.gpio			= AT91_PIN_PB21,
306 		.active_low		= 1,
307 		.default_trigger	= "heartbeat",
308 	}
309 };
310 
311 static struct i2c_board_info __initdata ek_i2c_devices[] = {
312 	{
313 		I2C_BOARD_INFO("rv3029c2", 0x56),
314 	},
315 };
316 
ek_add_device_leds(void)317 static void __init ek_add_device_leds(void)
318 {
319 	if (machine_is_usb_a9260() || machine_is_usb_a9g20())
320 		ek_leds[0].active_low = 0;
321 
322 	at91_gpio_leds(ek_leds, ARRAY_SIZE(ek_leds));
323 }
324 
ek_board_init(void)325 static void __init ek_board_init(void)
326 {
327 	/* Serial */
328 	at91_add_device_serial();
329 	/* USB Host */
330 	at91_add_device_usbh(&ek_usbh_data);
331 	/* USB Device */
332 	ek_add_device_udc();
333 	/* SPI */
334 	ek_add_device_spi();
335 	/* Ethernet */
336 	ek_add_device_eth();
337 	/* NAND */
338 	ek_add_device_nand();
339 	/* Push Buttons */
340 	ek_add_device_buttons();
341 	/* LEDs */
342 	ek_add_device_leds();
343 
344 	if (machine_is_usb_a9g20()) {
345 		/* I2C */
346 		at91_add_device_i2c(ek_i2c_devices, ARRAY_SIZE(ek_i2c_devices));
347 	} else {
348 		/* I2C */
349 		at91_add_device_i2c(NULL, 0);
350 		/* shutdown controller, wakeup button (5 msec low) */
351 		at91_shdwc_write(AT91_SHDW_MR, AT91_SHDW_CPTWK0_(10)
352 				| AT91_SHDW_WKMODE0_LOW
353 				| AT91_SHDW_RTTWKEN);
354 	}
355 }
356 
357 MACHINE_START(USB_A9263, "CALAO USB_A9263")
358 	/* Maintainer: calao-systems */
359 	.timer		= &at91sam926x_timer,
360 	.map_io		= at91_map_io,
361 	.init_early	= ek_init_early,
362 	.init_irq	= at91_init_irq_default,
363 	.init_machine	= ek_board_init,
364 MACHINE_END
365 
366 MACHINE_START(USB_A9260, "CALAO USB_A9260")
367 	/* Maintainer: calao-systems */
368 	.timer		= &at91sam926x_timer,
369 	.map_io		= at91_map_io,
370 	.init_early	= ek_init_early,
371 	.init_irq	= at91_init_irq_default,
372 	.init_machine	= ek_board_init,
373 MACHINE_END
374 
375 MACHINE_START(USB_A9G20, "CALAO USB_A92G0")
376 	/* Maintainer: Jean-Christophe PLAGNIOL-VILLARD */
377 	.timer		= &at91sam926x_timer,
378 	.map_io		= at91_map_io,
379 	.init_early	= ek_init_early,
380 	.init_irq	= at91_init_irq_default,
381 	.init_machine	= ek_board_init,
382 MACHINE_END
383