1 /*
2  * linux/arch/arm/mach-at91/board-neocore926.c
3  *
4  *  Copyright (C) 2005 SAN People
5  *  Copyright (C) 2007 Atmel Corporation
6  *  Copyright (C) 2008 ADENEO.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22 
23 #include <linux/types.h>
24 #include <linux/gpio.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/spi/ads7846.h>
31 #include <linux/fb.h>
32 #include <linux/gpio_keys.h>
33 #include <linux/input.h>
34 
35 #include <video/atmel_lcdc.h>
36 
37 #include <asm/setup.h>
38 #include <asm/mach-types.h>
39 #include <asm/irq.h>
40 #include <asm/sizes.h>
41 
42 #include <asm/mach/arch.h>
43 #include <asm/mach/map.h>
44 #include <asm/mach/irq.h>
45 
46 #include <mach/hardware.h>
47 #include <mach/board.h>
48 #include <mach/at91sam9_smc.h>
49 
50 #include "sam9_smc.h"
51 #include "generic.h"
52 
53 
neocore926_init_early(void)54 static void __init neocore926_init_early(void)
55 {
56 	/* Initialize processor: 20 MHz crystal */
57 	at91_initialize(20000000);
58 
59 	/* DBGU on ttyS0. (Rx & Tx only) */
60 	at91_register_uart(0, 0, 0);
61 
62 	/* USART0 on ttyS1. (Rx, Tx, RTS, CTS) */
63 	at91_register_uart(AT91SAM9263_ID_US0, 1, ATMEL_UART_CTS | ATMEL_UART_RTS);
64 
65 	/* set serial console to ttyS0 (ie, DBGU) */
66 	at91_set_serial_console(0);
67 }
68 
69 /*
70  * USB Host port
71  */
72 static struct at91_usbh_data __initdata neocore926_usbh_data = {
73 	.ports		= 2,
74 	.vbus_pin	= { AT91_PIN_PA24, AT91_PIN_PA21 },
75 	.overcurrent_pin= {-EINVAL, -EINVAL},
76 };
77 
78 /*
79  * USB Device port
80  */
81 static struct at91_udc_data __initdata neocore926_udc_data = {
82 	.vbus_pin	= AT91_PIN_PA25,
83 	.pullup_pin	= -EINVAL,		/* pull-up driven by UDC */
84 };
85 
86 
87 /*
88  * ADS7846 Touchscreen
89  */
90 #if defined(CONFIG_TOUCHSCREEN_ADS7846) || defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
ads7843_pendown_state(void)91 static int ads7843_pendown_state(void)
92 {
93 	return !at91_get_gpio_value(AT91_PIN_PA15);	/* Touchscreen PENIRQ */
94 }
95 
96 static struct ads7846_platform_data ads_info = {
97 	.model			= 7843,
98 	.x_min			= 150,
99 	.x_max			= 3830,
100 	.y_min			= 190,
101 	.y_max			= 3830,
102 	.vref_delay_usecs	= 100,
103 	.x_plate_ohms		= 450,
104 	.y_plate_ohms		= 250,
105 	.pressure_max		= 15000,
106 	.debounce_max		= 1,
107 	.debounce_rep		= 0,
108 	.debounce_tol		= (~0),
109 	.get_pendown_state	= ads7843_pendown_state,
110 };
111 
neocore926_add_device_ts(void)112 static void __init neocore926_add_device_ts(void)
113 {
114 	at91_set_B_periph(AT91_PIN_PA15, 1);	/* External IRQ1, with pullup */
115 	at91_set_gpio_input(AT91_PIN_PC13, 1);	/* Touchscreen BUSY signal */
116 }
117 #else
neocore926_add_device_ts(void)118 static void __init neocore926_add_device_ts(void) {}
119 #endif
120 
121 /*
122  * SPI devices.
123  */
124 static struct spi_board_info neocore926_spi_devices[] = {
125 #if defined(CONFIG_MTD_AT91_DATAFLASH_CARD)
126 	{	/* DataFlash card */
127 		.modalias	= "mtd_dataflash",
128 		.chip_select	= 0,
129 		.max_speed_hz	= 15 * 1000 * 1000,
130 		.bus_num	= 0,
131 	},
132 #endif
133 #if defined(CONFIG_TOUCHSCREEN_ADS7846) || defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
134 	{
135 		.modalias	= "ads7846",
136 		.chip_select	= 1,
137 		.max_speed_hz	= 125000 * 16,
138 		.bus_num	= 0,
139 		.platform_data	= &ads_info,
140 		.irq		= AT91SAM9263_ID_IRQ1,
141 	},
142 #endif
143 };
144 
145 
146 /*
147  * MCI (SD/MMC)
148  */
149 static struct at91_mmc_data __initdata neocore926_mmc_data = {
150 	.wire4		= 1,
151 	.det_pin	= AT91_PIN_PE18,
152 	.wp_pin		= AT91_PIN_PE19,
153 	.vcc_pin	= -EINVAL,
154 };
155 
156 
157 /*
158  * MACB Ethernet device
159  */
160 static struct macb_platform_data __initdata neocore926_macb_data = {
161 	.phy_irq_pin	= AT91_PIN_PE31,
162 	.is_rmii	= 1,
163 };
164 
165 
166 /*
167  * NAND flash
168  */
169 static struct mtd_partition __initdata neocore926_nand_partition[] = {
170 	{
171 		.name	= "Linux Kernel",	/* "Partition 1", */
172 		.offset	= 0,
173 		.size	= SZ_8M,
174 	},
175 	{
176 		.name	= "Filesystem",		/* "Partition 2", */
177 		.offset	= MTDPART_OFS_NXTBLK,
178 		.size	= SZ_32M,
179 	},
180 	{
181 		.name	= "Free",		/* "Partition 3", */
182 		.offset	= MTDPART_OFS_NXTBLK,
183 		.size	= MTDPART_SIZ_FULL,
184 	},
185 };
186 
187 static struct atmel_nand_data __initdata neocore926_nand_data = {
188 	.ale			= 21,
189 	.cle			= 22,
190 	.rdy_pin		= AT91_PIN_PB19,
191 	.rdy_pin_active_low	= 1,
192 	.enable_pin		= AT91_PIN_PD15,
193 	.parts			= neocore926_nand_partition,
194 	.num_parts		= ARRAY_SIZE(neocore926_nand_partition),
195 	.det_pin		= -EINVAL,
196 };
197 
198 static struct sam9_smc_config __initdata neocore926_nand_smc_config = {
199 	.ncs_read_setup		= 0,
200 	.nrd_setup		= 1,
201 	.ncs_write_setup	= 0,
202 	.nwe_setup		= 1,
203 
204 	.ncs_read_pulse		= 4,
205 	.nrd_pulse		= 4,
206 	.ncs_write_pulse	= 4,
207 	.nwe_pulse		= 4,
208 
209 	.read_cycle		= 6,
210 	.write_cycle		= 6,
211 
212 	.mode			= AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_DBW_8,
213 	.tdf_cycles		= 2,
214 };
215 
neocore926_add_device_nand(void)216 static void __init neocore926_add_device_nand(void)
217 {
218 	/* configure chip-select 3 (NAND) */
219 	sam9_smc_configure(0, 3, &neocore926_nand_smc_config);
220 
221 	at91_add_device_nand(&neocore926_nand_data);
222 }
223 
224 
225 /*
226  * LCD Controller
227  */
228 #if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
229 static struct fb_videomode at91_tft_vga_modes[] = {
230 	{
231 		.name		= "TX09D50VM1CCA @ 60",
232 		.refresh	= 60,
233 		.xres		= 240,		.yres		= 320,
234 		.pixclock	= KHZ2PICOS(5000),
235 
236 		.left_margin	= 1,		.right_margin	= 33,
237 		.upper_margin	= 1,		.lower_margin	= 0,
238 		.hsync_len	= 5,		.vsync_len	= 1,
239 
240 		.sync		= FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
241 		.vmode		= FB_VMODE_NONINTERLACED,
242 	},
243 };
244 
245 static struct fb_monspecs at91fb_default_monspecs = {
246 	.manufacturer	= "HIT",
247 	.monitor	= "TX09D70VM1CCA",
248 
249 	.modedb		= at91_tft_vga_modes,
250 	.modedb_len	= ARRAY_SIZE(at91_tft_vga_modes),
251 	.hfmin		= 15000,
252 	.hfmax		= 64000,
253 	.vfmin		= 50,
254 	.vfmax		= 150,
255 };
256 
257 #define AT91SAM9263_DEFAULT_LCDCON2 (ATMEL_LCDC_MEMOR_LITTLE \
258 					| ATMEL_LCDC_DISTYPE_TFT \
259 					| ATMEL_LCDC_CLKMOD_ALWAYSACTIVE)
260 
at91_lcdc_power_control(int on)261 static void at91_lcdc_power_control(int on)
262 {
263 	at91_set_gpio_value(AT91_PIN_PA30, on);
264 }
265 
266 /* Driver datas */
267 static struct atmel_lcdfb_info __initdata neocore926_lcdc_data = {
268 	.lcdcon_is_backlight		= true,
269 	.default_bpp			= 16,
270 	.default_dmacon			= ATMEL_LCDC_DMAEN,
271 	.default_lcdcon2		= AT91SAM9263_DEFAULT_LCDCON2,
272 	.default_monspecs		= &at91fb_default_monspecs,
273 	.atmel_lcdfb_power_control	= at91_lcdc_power_control,
274 	.guard_time			= 1,
275 	.lcd_wiring_mode		= ATMEL_LCDC_WIRING_RGB555,
276 };
277 
278 #else
279 static struct atmel_lcdfb_info __initdata neocore926_lcdc_data;
280 #endif
281 
282 
283 /*
284  * GPIO Buttons
285  */
286 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
287 static struct gpio_keys_button neocore926_buttons[] = {
288 	{	/* BP1, "leftclic" */
289 		.code		= BTN_LEFT,
290 		.gpio		= AT91_PIN_PC5,
291 		.active_low	= 1,
292 		.desc		= "left_click",
293 		.wakeup		= 1,
294 	},
295 	{	/* BP2, "rightclic" */
296 		.code		= BTN_RIGHT,
297 		.gpio		= AT91_PIN_PC4,
298 		.active_low	= 1,
299 		.desc		= "right_click",
300 		.wakeup		= 1,
301 	},
302 };
303 
304 static struct gpio_keys_platform_data neocore926_button_data = {
305 	.buttons	= neocore926_buttons,
306 	.nbuttons	= ARRAY_SIZE(neocore926_buttons),
307 };
308 
309 static struct platform_device neocore926_button_device = {
310 	.name		= "gpio-keys",
311 	.id		= -1,
312 	.num_resources	= 0,
313 	.dev		= {
314 		.platform_data	= &neocore926_button_data,
315 	}
316 };
317 
neocore926_add_device_buttons(void)318 static void __init neocore926_add_device_buttons(void)
319 {
320 	at91_set_GPIO_periph(AT91_PIN_PC5, 0);	/* left button */
321 	at91_set_deglitch(AT91_PIN_PC5, 1);
322 	at91_set_GPIO_periph(AT91_PIN_PC4, 0);	/* right button */
323 	at91_set_deglitch(AT91_PIN_PC4, 1);
324 
325 	platform_device_register(&neocore926_button_device);
326 }
327 #else
neocore926_add_device_buttons(void)328 static void __init neocore926_add_device_buttons(void) {}
329 #endif
330 
331 
332 /*
333  * AC97
334  */
335 static struct ac97c_platform_data neocore926_ac97_data = {
336 	.reset_pin	= AT91_PIN_PA13,
337 };
338 
339 
neocore926_board_init(void)340 static void __init neocore926_board_init(void)
341 {
342 	/* Serial */
343 	at91_add_device_serial();
344 
345 	/* USB Host */
346 	at91_add_device_usbh(&neocore926_usbh_data);
347 
348 	/* USB Device */
349 	at91_add_device_udc(&neocore926_udc_data);
350 
351 	/* SPI */
352 	at91_set_gpio_output(AT91_PIN_PE20, 1);		/* select spi0 clock */
353 	at91_add_device_spi(neocore926_spi_devices, ARRAY_SIZE(neocore926_spi_devices));
354 
355 	/* Touchscreen */
356 	neocore926_add_device_ts();
357 
358 	/* MMC */
359 	at91_add_device_mmc(1, &neocore926_mmc_data);
360 
361 	/* Ethernet */
362 	at91_add_device_eth(&neocore926_macb_data);
363 
364 	/* NAND */
365 	neocore926_add_device_nand();
366 
367 	/* I2C */
368 	at91_add_device_i2c(NULL, 0);
369 
370 	/* LCD Controller */
371 	at91_add_device_lcdc(&neocore926_lcdc_data);
372 
373 	/* Push Buttons */
374 	neocore926_add_device_buttons();
375 
376 	/* AC97 */
377 	at91_add_device_ac97(&neocore926_ac97_data);
378 }
379 
380 MACHINE_START(NEOCORE926, "ADENEO NEOCORE 926")
381 	/* Maintainer: ADENEO */
382 	.timer		= &at91sam926x_timer,
383 	.map_io		= at91_map_io,
384 	.init_early	= neocore926_init_early,
385 	.init_irq	= at91_init_irq_default,
386 	.init_machine	= neocore926_board_init,
387 MACHINE_END
388