1 /*
2  * linux/arch/arm/mach-at91/board-cap9adk.c
3  *
4  *  Copyright (C) 2007 Stelian Pop <stelian.pop@leadtechdesign.com>
5  *  Copyright (C) 2007 Lead Tech Design <www.leadtechdesign.com>
6  *  Copyright (C) 2005 SAN People
7  *  Copyright (C) 2007 Atmel Corporation.
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/gpio.h>
26 #include <linux/init.h>
27 #include <linux/mm.h>
28 #include <linux/module.h>
29 #include <linux/platform_device.h>
30 #include <linux/spi/spi.h>
31 #include <linux/spi/ads7846.h>
32 #include <linux/fb.h>
33 #include <linux/mtd/physmap.h>
34 
35 #include <video/atmel_lcdc.h>
36 
37 #include <mach/hardware.h>
38 #include <asm/setup.h>
39 #include <asm/mach-types.h>
40 
41 #include <asm/mach/arch.h>
42 #include <asm/mach/map.h>
43 
44 #include <mach/board.h>
45 #include <mach/at91cap9_matrix.h>
46 #include <mach/at91sam9_smc.h>
47 #include <mach/system_rev.h>
48 
49 #include "sam9_smc.h"
50 #include "generic.h"
51 
52 
cap9adk_init_early(void)53 static void __init cap9adk_init_early(void)
54 {
55 	/* Initialize processor: 12 MHz crystal */
56 	at91_initialize(12000000);
57 
58 	/* Setup the LEDs: USER1 and USER2 LED for cpu/timer... */
59 	at91_init_leds(AT91_PIN_PA10, AT91_PIN_PA11);
60 	/* ... POWER LED always on */
61 	at91_set_gpio_output(AT91_PIN_PC29, 1);
62 
63 	/* Setup the serial ports and console */
64 	at91_register_uart(0, 0, 0);		/* DBGU = ttyS0 */
65 	at91_set_serial_console(0);
66 }
67 
68 /*
69  * USB Host port
70  */
71 static struct at91_usbh_data __initdata cap9adk_usbh_data = {
72 	.ports		= 2,
73 	.vbus_pin	= {-EINVAL, -EINVAL},
74 	.overcurrent_pin= {-EINVAL, -EINVAL},
75 };
76 
77 /*
78  * USB HS Device port
79  */
80 static struct usba_platform_data __initdata cap9adk_usba_udc_data = {
81 	.vbus_pin	= AT91_PIN_PB31,
82 };
83 
84 /*
85  * ADS7846 Touchscreen
86  */
87 #if defined(CONFIG_TOUCHSCREEN_ADS7846) || defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
ads7843_pendown_state(void)88 static int ads7843_pendown_state(void)
89 {
90 	return !at91_get_gpio_value(AT91_PIN_PC4);	/* Touchscreen PENIRQ */
91 }
92 
93 static struct ads7846_platform_data ads_info = {
94 	.model			= 7843,
95 	.x_min			= 150,
96 	.x_max			= 3830,
97 	.y_min			= 190,
98 	.y_max			= 3830,
99 	.vref_delay_usecs	= 100,
100 	.x_plate_ohms		= 450,
101 	.y_plate_ohms		= 250,
102 	.pressure_max		= 15000,
103 	.debounce_max		= 1,
104 	.debounce_rep		= 0,
105 	.debounce_tol		= (~0),
106 	.get_pendown_state	= ads7843_pendown_state,
107 };
108 
cap9adk_add_device_ts(void)109 static void __init cap9adk_add_device_ts(void)
110 {
111 	at91_set_gpio_input(AT91_PIN_PC4, 1);	/* Touchscreen PENIRQ */
112 	at91_set_gpio_input(AT91_PIN_PC5, 1);	/* Touchscreen BUSY */
113 }
114 #else
cap9adk_add_device_ts(void)115 static void __init cap9adk_add_device_ts(void) {}
116 #endif
117 
118 
119 /*
120  * SPI devices.
121  */
122 static struct spi_board_info cap9adk_spi_devices[] = {
123 #if defined(CONFIG_MTD_AT91_DATAFLASH_CARD)
124 	{	/* DataFlash card */
125 		.modalias	= "mtd_dataflash",
126 		.chip_select	= 0,
127 		.max_speed_hz	= 15 * 1000 * 1000,
128 		.bus_num	= 0,
129 	},
130 #endif
131 #if defined(CONFIG_TOUCHSCREEN_ADS7846) || defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
132 	{
133 		.modalias	= "ads7846",
134 		.chip_select	= 3,		/* can be 2 or 3, depending on J2 jumper */
135 		.max_speed_hz	= 125000 * 26,	/* (max sample rate @ 3V) * (cmd + data + overhead) */
136 		.bus_num	= 0,
137 		.platform_data	= &ads_info,
138 		.irq		= AT91_PIN_PC4,
139 	},
140 #endif
141 };
142 
143 
144 /*
145  * MCI (SD/MMC)
146  */
147 static struct at91_mmc_data __initdata cap9adk_mmc_data = {
148 	.wire4		= 1,
149 	.det_pin	= -EINVAL,
150 	.wp_pin		= -EINVAL,
151 	.vcc_pin	= -EINVAL,
152 };
153 
154 
155 /*
156  * MACB Ethernet device
157  */
158 static struct macb_platform_data __initdata cap9adk_macb_data = {
159 	.phy_irq_pin	= -EINVAL,
160 	.is_rmii	= 1,
161 };
162 
163 
164 /*
165  * NAND flash
166  */
167 static struct mtd_partition __initdata cap9adk_nand_partitions[] = {
168 	{
169 		.name	= "NAND partition",
170 		.offset	= 0,
171 		.size	= MTDPART_SIZ_FULL,
172 	},
173 };
174 
175 static struct atmel_nand_data __initdata cap9adk_nand_data = {
176 	.ale		= 21,
177 	.cle		= 22,
178 	.det_pin	= -EINVAL,
179 	.rdy_pin	= -EINVAL,
180 	.enable_pin	= AT91_PIN_PD15,
181 	.parts		= cap9adk_nand_partitions,
182 	.num_parts	= ARRAY_SIZE(cap9adk_nand_partitions),
183 };
184 
185 static struct sam9_smc_config __initdata cap9adk_nand_smc_config = {
186 	.ncs_read_setup		= 1,
187 	.nrd_setup		= 2,
188 	.ncs_write_setup	= 1,
189 	.nwe_setup		= 2,
190 
191 	.ncs_read_pulse		= 6,
192 	.nrd_pulse		= 4,
193 	.ncs_write_pulse	= 6,
194 	.nwe_pulse		= 4,
195 
196 	.read_cycle		= 8,
197 	.write_cycle		= 8,
198 
199 	.mode			= AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE,
200 	.tdf_cycles		= 1,
201 };
202 
cap9adk_add_device_nand(void)203 static void __init cap9adk_add_device_nand(void)
204 {
205 	unsigned long csa;
206 
207 	csa = at91_sys_read(AT91_MATRIX_EBICSA);
208 	at91_sys_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_EBI_VDDIOMSEL_3_3V);
209 
210 	cap9adk_nand_data.bus_width_16 = board_have_nand_16bit();
211 	/* setup bus-width (8 or 16) */
212 	if (cap9adk_nand_data.bus_width_16)
213 		cap9adk_nand_smc_config.mode |= AT91_SMC_DBW_16;
214 	else
215 		cap9adk_nand_smc_config.mode |= AT91_SMC_DBW_8;
216 
217 	/* configure chip-select 3 (NAND) */
218 	sam9_smc_configure(0, 3, &cap9adk_nand_smc_config);
219 
220 	at91_add_device_nand(&cap9adk_nand_data);
221 }
222 
223 
224 /*
225  * NOR flash
226  */
227 static struct mtd_partition cap9adk_nor_partitions[] = {
228 	{
229 		.name		= "NOR partition",
230 		.offset		= 0,
231 		.size		= MTDPART_SIZ_FULL,
232 	},
233 };
234 
235 static struct physmap_flash_data cap9adk_nor_data = {
236 	.width		= 2,
237 	.parts		= cap9adk_nor_partitions,
238 	.nr_parts	= ARRAY_SIZE(cap9adk_nor_partitions),
239 };
240 
241 #define NOR_BASE	AT91_CHIPSELECT_0
242 #define NOR_SIZE	SZ_8M
243 
244 static struct resource nor_flash_resources[] = {
245 	{
246 		.start	= NOR_BASE,
247 		.end	= NOR_BASE + NOR_SIZE - 1,
248 		.flags	= IORESOURCE_MEM,
249 	}
250 };
251 
252 static struct platform_device cap9adk_nor_flash = {
253 	.name		= "physmap-flash",
254 	.id		= 0,
255 	.dev		= {
256 				.platform_data	= &cap9adk_nor_data,
257 	},
258 	.resource	= nor_flash_resources,
259 	.num_resources	= ARRAY_SIZE(nor_flash_resources),
260 };
261 
262 static struct sam9_smc_config __initdata cap9adk_nor_smc_config = {
263 	.ncs_read_setup		= 2,
264 	.nrd_setup		= 4,
265 	.ncs_write_setup	= 2,
266 	.nwe_setup		= 4,
267 
268 	.ncs_read_pulse		= 10,
269 	.nrd_pulse		= 8,
270 	.ncs_write_pulse	= 10,
271 	.nwe_pulse		= 8,
272 
273 	.read_cycle		= 16,
274 	.write_cycle		= 16,
275 
276 	.mode			= AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_BAT_WRITE | AT91_SMC_DBW_16,
277 	.tdf_cycles		= 1,
278 };
279 
cap9adk_add_device_nor(void)280 static __init void cap9adk_add_device_nor(void)
281 {
282 	unsigned long csa;
283 
284 	csa = at91_sys_read(AT91_MATRIX_EBICSA);
285 	at91_sys_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_EBI_VDDIOMSEL_3_3V);
286 
287 	/* configure chip-select 0 (NOR) */
288 	sam9_smc_configure(0, 0, &cap9adk_nor_smc_config);
289 
290 	platform_device_register(&cap9adk_nor_flash);
291 }
292 
293 
294 /*
295  * LCD Controller
296  */
297 #if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
298 static struct fb_videomode at91_tft_vga_modes[] = {
299 	{
300 	        .name           = "TX09D50VM1CCA @ 60",
301 		.refresh	= 60,
302 		.xres		= 240,		.yres		= 320,
303 		.pixclock	= KHZ2PICOS(4965),
304 
305 		.left_margin	= 1,		.right_margin	= 33,
306 		.upper_margin	= 1,		.lower_margin	= 0,
307 		.hsync_len	= 5,		.vsync_len	= 1,
308 
309 		.sync		= FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
310 		.vmode		= FB_VMODE_NONINTERLACED,
311 	},
312 };
313 
314 static struct fb_monspecs at91fb_default_monspecs = {
315 	.manufacturer	= "HIT",
316 	.monitor        = "TX09D70VM1CCA",
317 
318 	.modedb		= at91_tft_vga_modes,
319 	.modedb_len	= ARRAY_SIZE(at91_tft_vga_modes),
320 	.hfmin		= 15000,
321 	.hfmax		= 64000,
322 	.vfmin		= 50,
323 	.vfmax		= 150,
324 };
325 
326 #define AT91CAP9_DEFAULT_LCDCON2 	(ATMEL_LCDC_MEMOR_LITTLE \
327 					| ATMEL_LCDC_DISTYPE_TFT    \
328 					| ATMEL_LCDC_CLKMOD_ALWAYSACTIVE)
329 
at91_lcdc_power_control(int on)330 static void at91_lcdc_power_control(int on)
331 {
332 	if (on)
333 		at91_set_gpio_value(AT91_PIN_PC0, 0);	/* power up */
334 	else
335 		at91_set_gpio_value(AT91_PIN_PC0, 1);	/* power down */
336 }
337 
338 /* Driver datas */
339 static struct atmel_lcdfb_info __initdata cap9adk_lcdc_data = {
340 	.default_bpp			= 16,
341 	.default_dmacon			= ATMEL_LCDC_DMAEN,
342 	.default_lcdcon2		= AT91CAP9_DEFAULT_LCDCON2,
343 	.default_monspecs		= &at91fb_default_monspecs,
344 	.atmel_lcdfb_power_control	= at91_lcdc_power_control,
345 	.guard_time			= 1,
346 };
347 
348 #else
349 static struct atmel_lcdfb_info __initdata cap9adk_lcdc_data;
350 #endif
351 
352 
353 /*
354  * AC97
355  */
356 static struct ac97c_platform_data cap9adk_ac97_data = {
357 	.reset_pin	= -EINVAL,
358 };
359 
360 
cap9adk_board_init(void)361 static void __init cap9adk_board_init(void)
362 {
363 	/* Serial */
364 	at91_add_device_serial();
365 	/* USB Host */
366 	at91_add_device_usbh(&cap9adk_usbh_data);
367 	/* USB HS */
368 	at91_add_device_usba(&cap9adk_usba_udc_data);
369 	/* SPI */
370 	at91_add_device_spi(cap9adk_spi_devices, ARRAY_SIZE(cap9adk_spi_devices));
371 	/* Touchscreen */
372 	cap9adk_add_device_ts();
373 	/* MMC */
374 	at91_add_device_mmc(1, &cap9adk_mmc_data);
375 	/* Ethernet */
376 	at91_add_device_eth(&cap9adk_macb_data);
377 	/* NAND */
378 	cap9adk_add_device_nand();
379 	/* NOR Flash */
380 	cap9adk_add_device_nor();
381 	/* I2C */
382 	at91_add_device_i2c(NULL, 0);
383 	/* LCD Controller */
384 	at91_add_device_lcdc(&cap9adk_lcdc_data);
385 	/* AC97 */
386 	at91_add_device_ac97(&cap9adk_ac97_data);
387 }
388 
389 MACHINE_START(AT91CAP9ADK, "Atmel AT91CAP9A-DK")
390 	/* Maintainer: Stelian Pop <stelian.pop@leadtechdesign.com> */
391 	.timer		= &at91sam926x_timer,
392 	.map_io		= at91_map_io,
393 	.init_early	= cap9adk_init_early,
394 	.init_irq	= at91_init_irq_default,
395 	.init_machine	= cap9adk_board_init,
396 MACHINE_END
397