1 /*
2  * linux/arch/arm/mach-at91/board-sam9260ek.c
3  *
4  *  Copyright (C) 2005 SAN People
5  *  Copyright (C) 2006 Atmel
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21 
22 #include <linux/types.h>
23 #include <linux/gpio.h>
24 #include <linux/init.h>
25 #include <linux/mm.h>
26 #include <linux/module.h>
27 #include <linux/platform_device.h>
28 #include <linux/spi/spi.h>
29 #include <linux/spi/at73c213.h>
30 #include <linux/clk.h>
31 #include <linux/i2c/at24.h>
32 #include <linux/gpio_keys.h>
33 #include <linux/input.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 #include <mach/system_rev.h>
48 
49 #include "sam9_smc.h"
50 #include "generic.h"
51 
52 
ek_init_early(void)53 static void __init ek_init_early(void)
54 {
55 	/* Initialize processor: 18.432 MHz crystal */
56 	at91_initialize(18432000);
57 
58 	/* DBGU on ttyS0. (Rx & Tx only) */
59 	at91_register_uart(0, 0, 0);
60 
61 	/* USART0 on ttyS1. (Rx, Tx, CTS, RTS, DTR, DSR, DCD, RI) */
62 	at91_register_uart(AT91SAM9260_ID_US0, 1, ATMEL_UART_CTS | ATMEL_UART_RTS
63 			   | ATMEL_UART_DTR | ATMEL_UART_DSR | ATMEL_UART_DCD
64 			   | ATMEL_UART_RI);
65 
66 	/* USART1 on ttyS2. (Rx, Tx, RTS, CTS) */
67 	at91_register_uart(AT91SAM9260_ID_US1, 2, ATMEL_UART_CTS | ATMEL_UART_RTS);
68 
69 	/* set serial console to ttyS0 (ie, DBGU) */
70 	at91_set_serial_console(0);
71 }
72 
73 /*
74  * USB Host port
75  */
76 static struct at91_usbh_data __initdata ek_usbh_data = {
77 	.ports		= 2,
78 	.vbus_pin	= {-EINVAL, -EINVAL},
79 	.overcurrent_pin= {-EINVAL, -EINVAL},
80 };
81 
82 /*
83  * USB Device port
84  */
85 static struct at91_udc_data __initdata ek_udc_data = {
86 	.vbus_pin	= AT91_PIN_PC5,
87 	.pullup_pin	= -EINVAL,		/* pull-up driven by UDC */
88 };
89 
90 
91 /*
92  * Audio
93  */
94 static struct at73c213_board_info at73c213_data = {
95 	.ssc_id		= 0,
96 	.shortname	= "AT91SAM9260-EK external DAC",
97 };
98 
99 #if defined(CONFIG_SND_AT73C213) || defined(CONFIG_SND_AT73C213_MODULE)
at73c213_set_clk(struct at73c213_board_info * info)100 static void __init at73c213_set_clk(struct at73c213_board_info *info)
101 {
102 	struct clk *pck0;
103 	struct clk *plla;
104 
105 	pck0 = clk_get(NULL, "pck0");
106 	plla = clk_get(NULL, "plla");
107 
108 	/* AT73C213 MCK Clock */
109 	at91_set_B_periph(AT91_PIN_PC1, 0);	/* PCK0 */
110 
111 	clk_set_parent(pck0, plla);
112 	clk_put(plla);
113 
114 	info->dac_clk = pck0;
115 }
116 #else
at73c213_set_clk(struct at73c213_board_info * info)117 static void __init at73c213_set_clk(struct at73c213_board_info *info) {}
118 #endif
119 
120 /*
121  * SPI devices.
122  */
123 static struct spi_board_info ek_spi_devices[] = {
124 #if !defined(CONFIG_MMC_AT91)
125 	{	/* DataFlash chip */
126 		.modalias	= "mtd_dataflash",
127 		.chip_select	= 1,
128 		.max_speed_hz	= 15 * 1000 * 1000,
129 		.bus_num	= 0,
130 	},
131 #if defined(CONFIG_MTD_AT91_DATAFLASH_CARD)
132 	{	/* DataFlash card */
133 		.modalias	= "mtd_dataflash",
134 		.chip_select	= 0,
135 		.max_speed_hz	= 15 * 1000 * 1000,
136 		.bus_num	= 0,
137 	},
138 #endif
139 #endif
140 #if defined(CONFIG_SND_AT73C213) || defined(CONFIG_SND_AT73C213_MODULE)
141 	{	/* AT73C213 DAC */
142 		.modalias	= "at73c213",
143 		.chip_select	= 0,
144 		.max_speed_hz	= 10 * 1000 * 1000,
145 		.bus_num	= 1,
146 		.mode		= SPI_MODE_1,
147 		.platform_data	= &at73c213_data,
148 	},
149 #endif
150 };
151 
152 
153 /*
154  * MACB Ethernet device
155  */
156 static struct macb_platform_data __initdata ek_macb_data = {
157 	.phy_irq_pin	= AT91_PIN_PA7,
158 	.is_rmii	= 1,
159 };
160 
161 
162 /*
163  * NAND flash
164  */
165 static struct mtd_partition __initdata ek_nand_partition[] = {
166 	{
167 		.name	= "Partition 1",
168 		.offset	= 0,
169 		.size	= SZ_256K,
170 	},
171 	{
172 		.name	= "Partition 2",
173 		.offset	= MTDPART_OFS_NXTBLK,
174 		.size	= MTDPART_SIZ_FULL,
175 	},
176 };
177 
178 static struct atmel_nand_data __initdata ek_nand_data = {
179 	.ale		= 21,
180 	.cle		= 22,
181 	.det_pin	= -EINVAL,
182 	.rdy_pin	= AT91_PIN_PC13,
183 	.enable_pin	= AT91_PIN_PC14,
184 	.parts		= ek_nand_partition,
185 	.num_parts	= ARRAY_SIZE(ek_nand_partition),
186 };
187 
188 static struct sam9_smc_config __initdata ek_nand_smc_config = {
189 	.ncs_read_setup		= 0,
190 	.nrd_setup		= 1,
191 	.ncs_write_setup	= 0,
192 	.nwe_setup		= 1,
193 
194 	.ncs_read_pulse		= 3,
195 	.nrd_pulse		= 3,
196 	.ncs_write_pulse	= 3,
197 	.nwe_pulse		= 3,
198 
199 	.read_cycle		= 5,
200 	.write_cycle		= 5,
201 
202 	.mode			= AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE,
203 	.tdf_cycles		= 2,
204 };
205 
ek_add_device_nand(void)206 static void __init ek_add_device_nand(void)
207 {
208 	ek_nand_data.bus_width_16 = board_have_nand_16bit();
209 	/* setup bus-width (8 or 16) */
210 	if (ek_nand_data.bus_width_16)
211 		ek_nand_smc_config.mode |= AT91_SMC_DBW_16;
212 	else
213 		ek_nand_smc_config.mode |= AT91_SMC_DBW_8;
214 
215 	/* configure chip-select 3 (NAND) */
216 	sam9_smc_configure(0, 3, &ek_nand_smc_config);
217 
218 	at91_add_device_nand(&ek_nand_data);
219 }
220 
221 
222 /*
223  * MCI (SD/MMC)
224  */
225 static struct at91_mmc_data __initdata ek_mmc_data = {
226 	.slot_b		= 1,
227 	.wire4		= 1,
228 	.det_pin	= -EINVAL,
229 	.wp_pin		= -EINVAL,
230 	.vcc_pin	= -EINVAL,
231 };
232 
233 
234 /*
235  * LEDs
236  */
237 static struct gpio_led ek_leds[] = {
238 	{	/* "bottom" led, green, userled1 to be defined */
239 		.name			= "ds5",
240 		.gpio			= AT91_PIN_PA6,
241 		.active_low		= 1,
242 		.default_trigger	= "none",
243 	},
244 	{	/* "power" led, yellow */
245 		.name			= "ds1",
246 		.gpio			= AT91_PIN_PA9,
247 		.default_trigger	= "heartbeat",
248 	}
249 };
250 
251 /*
252  * I2C devices
253  */
254 static struct at24_platform_data at24c512 = {
255 	.byte_len	= SZ_512K / 8,
256 	.page_size	= 128,
257 	.flags		= AT24_FLAG_ADDR16,
258 };
259 
260 static struct i2c_board_info __initdata ek_i2c_devices[] = {
261 	{
262 		I2C_BOARD_INFO("24c512", 0x50),
263 		.platform_data = &at24c512,
264 	},
265 	/* more devices can be added using expansion connectors */
266 };
267 
268 
269 /*
270  * GPIO Buttons
271  */
272 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
273 static struct gpio_keys_button ek_buttons[] = {
274 	{
275 		.gpio		= AT91_PIN_PA30,
276 		.code		= BTN_3,
277 		.desc		= "Button 3",
278 		.active_low	= 1,
279 		.wakeup		= 1,
280 	},
281 	{
282 		.gpio		= AT91_PIN_PA31,
283 		.code		= BTN_4,
284 		.desc		= "Button 4",
285 		.active_low	= 1,
286 		.wakeup		= 1,
287 	}
288 };
289 
290 static struct gpio_keys_platform_data ek_button_data = {
291 	.buttons	= ek_buttons,
292 	.nbuttons	= ARRAY_SIZE(ek_buttons),
293 };
294 
295 static struct platform_device ek_button_device = {
296 	.name		= "gpio-keys",
297 	.id		= -1,
298 	.num_resources	= 0,
299 	.dev		= {
300 		.platform_data	= &ek_button_data,
301 	}
302 };
303 
ek_add_device_buttons(void)304 static void __init ek_add_device_buttons(void)
305 {
306 	at91_set_gpio_input(AT91_PIN_PA30, 1);	/* btn3 */
307 	at91_set_deglitch(AT91_PIN_PA30, 1);
308 	at91_set_gpio_input(AT91_PIN_PA31, 1);	/* btn4 */
309 	at91_set_deglitch(AT91_PIN_PA31, 1);
310 
311 	platform_device_register(&ek_button_device);
312 }
313 #else
ek_add_device_buttons(void)314 static void __init ek_add_device_buttons(void) {}
315 #endif
316 
317 
ek_board_init(void)318 static void __init ek_board_init(void)
319 {
320 	/* Serial */
321 	at91_add_device_serial();
322 	/* USB Host */
323 	at91_add_device_usbh(&ek_usbh_data);
324 	/* USB Device */
325 	at91_add_device_udc(&ek_udc_data);
326 	/* SPI */
327 	at91_add_device_spi(ek_spi_devices, ARRAY_SIZE(ek_spi_devices));
328 	/* NAND */
329 	ek_add_device_nand();
330 	/* Ethernet */
331 	at91_add_device_eth(&ek_macb_data);
332 	/* MMC */
333 	at91_add_device_mmc(0, &ek_mmc_data);
334 	/* I2C */
335 	at91_add_device_i2c(ek_i2c_devices, ARRAY_SIZE(ek_i2c_devices));
336 	/* SSC (to AT73C213) */
337 	at73c213_set_clk(&at73c213_data);
338 	at91_add_device_ssc(AT91SAM9260_ID_SSC, ATMEL_SSC_TX);
339 	/* LEDs */
340 	at91_gpio_leds(ek_leds, ARRAY_SIZE(ek_leds));
341 	/* Push Buttons */
342 	ek_add_device_buttons();
343 }
344 
345 MACHINE_START(AT91SAM9260EK, "Atmel AT91SAM9260-EK")
346 	/* Maintainer: Atmel */
347 	.timer		= &at91sam926x_timer,
348 	.map_io		= at91_map_io,
349 	.init_early	= ek_init_early,
350 	.init_irq	= at91_init_irq_default,
351 	.init_machine	= ek_board_init,
352 MACHINE_END
353