blob: 5652dde4bbe291fd5723481ab9a978eb66bd5ec9 [file] [log] [blame]
Andrew Victor86ad76b2006-11-30 16:45:01 +01001/*
Andrew Victor9d041262007-02-05 11:42:07 +01002 * arch/arm/mach-at91/at91sam9260_devices.c
Andrew Victor86ad76b2006-11-30 16:45:01 +01003 *
4 * Copyright (C) 2006 Atmel
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 */
12#include <asm/mach/arch.h>
13#include <asm/mach/map.h>
14
Andrew Victorc6686ff2008-01-23 09:13:53 +010015#include <linux/dma-mapping.h>
Russell King2f8163b2011-07-26 10:53:52 +010016#include <linux/gpio.h>
Andrew Victor86ad76b2006-11-30 16:45:01 +010017#include <linux/platform_device.h>
Andrew Victorf230d3f2007-11-19 13:47:20 +010018#include <linux/i2c-gpio.h>
Andrew Victor86ad76b2006-11-30 16:45:01 +010019
Russell Kinga09e64f2008-08-05 16:14:15 +010020#include <mach/board.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010021#include <mach/cpu.h>
22#include <mach/at91sam9260.h>
23#include <mach/at91sam9260_matrix.h>
Jean-Christophe PLAGNIOL-VILLARD4342d642011-11-27 23:15:50 +080024#include <mach/at91_matrix.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010025#include <mach/at91sam9_smc.h>
Andrew Victor86ad76b2006-11-30 16:45:01 +010026
27#include "generic.h"
28
Andrew Victor86ad76b2006-11-30 16:45:01 +010029
30/* --------------------------------------------------------------------
31 * USB Host
32 * -------------------------------------------------------------------- */
33
34#if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
Andrew Victorc6686ff2008-01-23 09:13:53 +010035static u64 ohci_dmamask = DMA_BIT_MASK(32);
Andrew Victor86ad76b2006-11-30 16:45:01 +010036static struct at91_usbh_data usbh_data;
37
38static struct resource usbh_resources[] = {
39 [0] = {
40 .start = AT91SAM9260_UHP_BASE,
41 .end = AT91SAM9260_UHP_BASE + SZ_1M - 1,
42 .flags = IORESOURCE_MEM,
43 },
44 [1] = {
45 .start = AT91SAM9260_ID_UHP,
46 .end = AT91SAM9260_ID_UHP,
47 .flags = IORESOURCE_IRQ,
48 },
49};
50
51static struct platform_device at91_usbh_device = {
52 .name = "at91_ohci",
53 .id = -1,
54 .dev = {
55 .dma_mask = &ohci_dmamask,
Andrew Victorc6686ff2008-01-23 09:13:53 +010056 .coherent_dma_mask = DMA_BIT_MASK(32),
Andrew Victor86ad76b2006-11-30 16:45:01 +010057 .platform_data = &usbh_data,
58 },
59 .resource = usbh_resources,
60 .num_resources = ARRAY_SIZE(usbh_resources),
61};
62
63void __init at91_add_device_usbh(struct at91_usbh_data *data)
64{
Thomas Petazzoni1fcaea72011-07-13 11:29:18 +020065 int i;
66
Andrew Victor86ad76b2006-11-30 16:45:01 +010067 if (!data)
68 return;
69
Thomas Petazzoni1fcaea72011-07-13 11:29:18 +020070 /* Enable overcurrent notification */
71 for (i = 0; i < data->ports; i++) {
72 if (data->overcurrent_pin[i])
73 at91_set_gpio_input(data->overcurrent_pin[i], 1);
74 }
75
Andrew Victor86ad76b2006-11-30 16:45:01 +010076 usbh_data = *data;
77 platform_device_register(&at91_usbh_device);
78}
79#else
80void __init at91_add_device_usbh(struct at91_usbh_data *data) {}
81#endif
82
83
84/* --------------------------------------------------------------------
85 * USB Device (Gadget)
86 * -------------------------------------------------------------------- */
87
Nicolas Ferree8c9dc92012-01-27 11:14:44 +010088#if defined(CONFIG_USB_AT91) || defined(CONFIG_USB_AT91_MODULE)
Andrew Victor86ad76b2006-11-30 16:45:01 +010089static struct at91_udc_data udc_data;
90
91static struct resource udc_resources[] = {
92 [0] = {
93 .start = AT91SAM9260_BASE_UDP,
94 .end = AT91SAM9260_BASE_UDP + SZ_16K - 1,
95 .flags = IORESOURCE_MEM,
96 },
97 [1] = {
98 .start = AT91SAM9260_ID_UDP,
99 .end = AT91SAM9260_ID_UDP,
100 .flags = IORESOURCE_IRQ,
101 },
102};
103
104static struct platform_device at91_udc_device = {
105 .name = "at91_udc",
106 .id = -1,
107 .dev = {
108 .platform_data = &udc_data,
109 },
110 .resource = udc_resources,
111 .num_resources = ARRAY_SIZE(udc_resources),
112};
113
114void __init at91_add_device_udc(struct at91_udc_data *data)
115{
116 if (!data)
117 return;
118
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +0800119 if (gpio_is_valid(data->vbus_pin)) {
Andrew Victor86ad76b2006-11-30 16:45:01 +0100120 at91_set_gpio_input(data->vbus_pin, 0);
121 at91_set_deglitch(data->vbus_pin, 1);
122 }
123
124 /* Pullup pin is handled internally by USB device peripheral */
125
126 udc_data = *data;
127 platform_device_register(&at91_udc_device);
128}
129#else
130void __init at91_add_device_udc(struct at91_udc_data *data) {}
131#endif
132
133
134/* --------------------------------------------------------------------
135 * Ethernet
136 * -------------------------------------------------------------------- */
137
138#if defined(CONFIG_MACB) || defined(CONFIG_MACB_MODULE)
Andrew Victorc6686ff2008-01-23 09:13:53 +0100139static u64 eth_dmamask = DMA_BIT_MASK(32);
Jamie Iles84e0cdb2011-03-08 20:17:06 +0000140static struct macb_platform_data eth_data;
Andrew Victor86ad76b2006-11-30 16:45:01 +0100141
142static struct resource eth_resources[] = {
143 [0] = {
144 .start = AT91SAM9260_BASE_EMAC,
145 .end = AT91SAM9260_BASE_EMAC + SZ_16K - 1,
146 .flags = IORESOURCE_MEM,
147 },
148 [1] = {
149 .start = AT91SAM9260_ID_EMAC,
150 .end = AT91SAM9260_ID_EMAC,
151 .flags = IORESOURCE_IRQ,
152 },
153};
154
155static struct platform_device at91sam9260_eth_device = {
156 .name = "macb",
157 .id = -1,
158 .dev = {
159 .dma_mask = &eth_dmamask,
Andrew Victorc6686ff2008-01-23 09:13:53 +0100160 .coherent_dma_mask = DMA_BIT_MASK(32),
Andrew Victor86ad76b2006-11-30 16:45:01 +0100161 .platform_data = &eth_data,
162 },
163 .resource = eth_resources,
164 .num_resources = ARRAY_SIZE(eth_resources),
165};
166
Jamie Iles84e0cdb2011-03-08 20:17:06 +0000167void __init at91_add_device_eth(struct macb_platform_data *data)
Andrew Victor86ad76b2006-11-30 16:45:01 +0100168{
169 if (!data)
170 return;
171
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +0800172 if (gpio_is_valid(data->phy_irq_pin)) {
Andrew Victor86ad76b2006-11-30 16:45:01 +0100173 at91_set_gpio_input(data->phy_irq_pin, 0);
174 at91_set_deglitch(data->phy_irq_pin, 1);
175 }
176
177 /* Pins used for MII and RMII */
178 at91_set_A_periph(AT91_PIN_PA19, 0); /* ETXCK_EREFCK */
179 at91_set_A_periph(AT91_PIN_PA17, 0); /* ERXDV */
180 at91_set_A_periph(AT91_PIN_PA14, 0); /* ERX0 */
181 at91_set_A_periph(AT91_PIN_PA15, 0); /* ERX1 */
182 at91_set_A_periph(AT91_PIN_PA18, 0); /* ERXER */
183 at91_set_A_periph(AT91_PIN_PA16, 0); /* ETXEN */
184 at91_set_A_periph(AT91_PIN_PA12, 0); /* ETX0 */
185 at91_set_A_periph(AT91_PIN_PA13, 0); /* ETX1 */
186 at91_set_A_periph(AT91_PIN_PA21, 0); /* EMDIO */
187 at91_set_A_periph(AT91_PIN_PA20, 0); /* EMDC */
188
189 if (!data->is_rmii) {
190 at91_set_B_periph(AT91_PIN_PA28, 0); /* ECRS */
191 at91_set_B_periph(AT91_PIN_PA29, 0); /* ECOL */
192 at91_set_B_periph(AT91_PIN_PA25, 0); /* ERX2 */
193 at91_set_B_periph(AT91_PIN_PA26, 0); /* ERX3 */
194 at91_set_B_periph(AT91_PIN_PA27, 0); /* ERXCK */
195 at91_set_B_periph(AT91_PIN_PA23, 0); /* ETX2 */
196 at91_set_B_periph(AT91_PIN_PA24, 0); /* ETX3 */
197 at91_set_B_periph(AT91_PIN_PA22, 0); /* ETXER */
198 }
199
200 eth_data = *data;
201 platform_device_register(&at91sam9260_eth_device);
202}
203#else
Jamie Iles84e0cdb2011-03-08 20:17:06 +0000204void __init at91_add_device_eth(struct macb_platform_data *data) {}
Andrew Victor86ad76b2006-11-30 16:45:01 +0100205#endif
206
207
208/* --------------------------------------------------------------------
209 * MMC / SD
210 * -------------------------------------------------------------------- */
211
212#if defined(CONFIG_MMC_AT91) || defined(CONFIG_MMC_AT91_MODULE)
Andrew Victorc6686ff2008-01-23 09:13:53 +0100213static u64 mmc_dmamask = DMA_BIT_MASK(32);
Andrew Victor86ad76b2006-11-30 16:45:01 +0100214static struct at91_mmc_data mmc_data;
215
216static struct resource mmc_resources[] = {
217 [0] = {
218 .start = AT91SAM9260_BASE_MCI,
219 .end = AT91SAM9260_BASE_MCI + SZ_16K - 1,
220 .flags = IORESOURCE_MEM,
221 },
222 [1] = {
223 .start = AT91SAM9260_ID_MCI,
224 .end = AT91SAM9260_ID_MCI,
225 .flags = IORESOURCE_IRQ,
226 },
227};
228
229static struct platform_device at91sam9260_mmc_device = {
230 .name = "at91_mci",
231 .id = -1,
232 .dev = {
233 .dma_mask = &mmc_dmamask,
Andrew Victorc6686ff2008-01-23 09:13:53 +0100234 .coherent_dma_mask = DMA_BIT_MASK(32),
Andrew Victor86ad76b2006-11-30 16:45:01 +0100235 .platform_data = &mmc_data,
236 },
237 .resource = mmc_resources,
238 .num_resources = ARRAY_SIZE(mmc_resources),
239};
240
Andrew Victord0760b32007-02-08 09:00:39 +0100241void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data)
Andrew Victor86ad76b2006-11-30 16:45:01 +0100242{
243 if (!data)
244 return;
245
246 /* input/irq */
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +0800247 if (gpio_is_valid(data->det_pin)) {
Andrew Victor86ad76b2006-11-30 16:45:01 +0100248 at91_set_gpio_input(data->det_pin, 1);
249 at91_set_deglitch(data->det_pin, 1);
250 }
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +0800251 if (gpio_is_valid(data->wp_pin))
Andrew Victor86ad76b2006-11-30 16:45:01 +0100252 at91_set_gpio_input(data->wp_pin, 1);
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +0800253 if (gpio_is_valid(data->vcc_pin))
Andrew Victor86ad76b2006-11-30 16:45:01 +0100254 at91_set_gpio_output(data->vcc_pin, 0);
255
256 /* CLK */
257 at91_set_A_periph(AT91_PIN_PA8, 0);
258
259 if (data->slot_b) {
260 /* CMD */
261 at91_set_B_periph(AT91_PIN_PA1, 1);
262
263 /* DAT0, maybe DAT1..DAT3 */
264 at91_set_B_periph(AT91_PIN_PA0, 1);
265 if (data->wire4) {
266 at91_set_B_periph(AT91_PIN_PA5, 1);
267 at91_set_B_periph(AT91_PIN_PA4, 1);
268 at91_set_B_periph(AT91_PIN_PA3, 1);
269 }
270 } else {
271 /* CMD */
272 at91_set_A_periph(AT91_PIN_PA7, 1);
273
274 /* DAT0, maybe DAT1..DAT3 */
275 at91_set_A_periph(AT91_PIN_PA6, 1);
276 if (data->wire4) {
277 at91_set_A_periph(AT91_PIN_PA9, 1);
278 at91_set_A_periph(AT91_PIN_PA10, 1);
279 at91_set_A_periph(AT91_PIN_PA11, 1);
280 }
281 }
282
283 mmc_data = *data;
284 platform_device_register(&at91sam9260_mmc_device);
285}
286#else
Andrew Victord0760b32007-02-08 09:00:39 +0100287void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data) {}
Andrew Victor86ad76b2006-11-30 16:45:01 +0100288#endif
289
Rob Emanuele864f38e2009-09-22 16:45:22 -0700290/* --------------------------------------------------------------------
291 * MMC / SD Slot for Atmel MCI Driver
292 * -------------------------------------------------------------------- */
293
294#if defined(CONFIG_MMC_ATMELMCI) || defined(CONFIG_MMC_ATMELMCI_MODULE)
295static u64 mmc_dmamask = DMA_BIT_MASK(32);
296static struct mci_platform_data mmc_data;
297
298static struct resource mmc_resources[] = {
299 [0] = {
300 .start = AT91SAM9260_BASE_MCI,
301 .end = AT91SAM9260_BASE_MCI + SZ_16K - 1,
302 .flags = IORESOURCE_MEM,
303 },
304 [1] = {
305 .start = AT91SAM9260_ID_MCI,
306 .end = AT91SAM9260_ID_MCI,
307 .flags = IORESOURCE_IRQ,
308 },
309};
310
311static struct platform_device at91sam9260_mmc_device = {
312 .name = "atmel_mci",
313 .id = -1,
314 .dev = {
315 .dma_mask = &mmc_dmamask,
316 .coherent_dma_mask = DMA_BIT_MASK(32),
317 .platform_data = &mmc_data,
318 },
319 .resource = mmc_resources,
320 .num_resources = ARRAY_SIZE(mmc_resources),
321};
322
323void __init at91_add_device_mci(short mmc_id, struct mci_platform_data *data)
324{
325 unsigned int i;
326 unsigned int slot_count = 0;
327
328 if (!data)
329 return;
330
Ludovic Desroches2c96a292011-08-11 15:25:41 +0000331 for (i = 0; i < ATMCI_MAX_NR_SLOTS; i++) {
Rob Emanuele864f38e2009-09-22 16:45:22 -0700332 if (data->slot[i].bus_width) {
333 /* input/irq */
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +0800334 if (gpio_is_valid(data->slot[i].detect_pin)) {
Rob Emanuele864f38e2009-09-22 16:45:22 -0700335 at91_set_gpio_input(data->slot[i].detect_pin, 1);
336 at91_set_deglitch(data->slot[i].detect_pin, 1);
337 }
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +0800338 if (gpio_is_valid(data->slot[i].wp_pin))
Rob Emanuele864f38e2009-09-22 16:45:22 -0700339 at91_set_gpio_input(data->slot[i].wp_pin, 1);
340
341 switch (i) {
342 case 0:
343 /* CMD */
344 at91_set_A_periph(AT91_PIN_PA7, 1);
345 /* DAT0, maybe DAT1..DAT3 */
346 at91_set_A_periph(AT91_PIN_PA6, 1);
347 if (data->slot[i].bus_width == 4) {
348 at91_set_A_periph(AT91_PIN_PA9, 1);
349 at91_set_A_periph(AT91_PIN_PA10, 1);
350 at91_set_A_periph(AT91_PIN_PA11, 1);
351 }
352 slot_count++;
353 break;
354 case 1:
355 /* CMD */
356 at91_set_B_periph(AT91_PIN_PA1, 1);
357 /* DAT0, maybe DAT1..DAT3 */
358 at91_set_B_periph(AT91_PIN_PA0, 1);
359 if (data->slot[i].bus_width == 4) {
360 at91_set_B_periph(AT91_PIN_PA5, 1);
361 at91_set_B_periph(AT91_PIN_PA4, 1);
362 at91_set_B_periph(AT91_PIN_PA3, 1);
363 }
364 slot_count++;
365 break;
366 default:
367 printk(KERN_ERR
368 "AT91: SD/MMC slot %d not available\n", i);
369 break;
370 }
371 }
372 }
373
374 if (slot_count) {
375 /* CLK */
376 at91_set_A_periph(AT91_PIN_PA8, 0);
377
378 mmc_data = *data;
379 platform_device_register(&at91sam9260_mmc_device);
380 }
381}
382#else
383void __init at91_add_device_mci(short mmc_id, struct mci_platform_data *data) {}
384#endif
385
Andrew Victor86ad76b2006-11-30 16:45:01 +0100386
387/* --------------------------------------------------------------------
388 * NAND / SmartMedia
389 * -------------------------------------------------------------------- */
390
Pieter du Preezf6ed6f72008-08-01 10:06:40 +0100391#if defined(CONFIG_MTD_NAND_ATMEL) || defined(CONFIG_MTD_NAND_ATMEL_MODULE)
HÃ¥vard Skinnemoen3c3796c2008-06-06 18:04:53 +0200392static struct atmel_nand_data nand_data;
Andrew Victor86ad76b2006-11-30 16:45:01 +0100393
394#define NAND_BASE AT91_CHIPSELECT_3
395
396static struct resource nand_resources[] = {
Andrew Victord7a24152008-04-02 21:44:44 +0100397 [0] = {
Andrew Victor86ad76b2006-11-30 16:45:01 +0100398 .start = NAND_BASE,
Andrew Victor22823552008-01-23 09:21:02 +0100399 .end = NAND_BASE + SZ_256M - 1,
Andrew Victor86ad76b2006-11-30 16:45:01 +0100400 .flags = IORESOURCE_MEM,
Andrew Victord7a24152008-04-02 21:44:44 +0100401 },
402 [1] = {
Jean-Christophe PLAGNIOL-VILLARDd28edd12011-09-18 09:31:56 +0800403 .start = AT91SAM9260_BASE_ECC,
404 .end = AT91SAM9260_BASE_ECC + SZ_512 - 1,
Andrew Victord7a24152008-04-02 21:44:44 +0100405 .flags = IORESOURCE_MEM,
Andrew Victor86ad76b2006-11-30 16:45:01 +0100406 }
407};
408
409static struct platform_device at91sam9260_nand_device = {
HÃ¥vard Skinnemoen3c3796c2008-06-06 18:04:53 +0200410 .name = "atmel_nand",
Andrew Victor86ad76b2006-11-30 16:45:01 +0100411 .id = -1,
412 .dev = {
413 .platform_data = &nand_data,
414 },
415 .resource = nand_resources,
416 .num_resources = ARRAY_SIZE(nand_resources),
417};
418
HÃ¥vard Skinnemoen3c3796c2008-06-06 18:04:53 +0200419void __init at91_add_device_nand(struct atmel_nand_data *data)
Andrew Victor86ad76b2006-11-30 16:45:01 +0100420{
Andrew Victor461d3b42008-10-06 20:01:00 +0100421 unsigned long csa;
Andrew Victor86ad76b2006-11-30 16:45:01 +0100422
423 if (!data)
424 return;
425
Jean-Christophe PLAGNIOL-VILLARD4342d642011-11-27 23:15:50 +0800426 csa = at91_matrix_read(AT91_MATRIX_EBICSA);
427 at91_matrix_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_CS3A_SMC_SMARTMEDIA);
Andrew Victor86ad76b2006-11-30 16:45:01 +0100428
Andrew Victor86ad76b2006-11-30 16:45:01 +0100429 /* enable pin */
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +0800430 if (gpio_is_valid(data->enable_pin))
Andrew Victor86ad76b2006-11-30 16:45:01 +0100431 at91_set_gpio_output(data->enable_pin, 1);
432
433 /* ready/busy pin */
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +0800434 if (gpio_is_valid(data->rdy_pin))
Andrew Victor86ad76b2006-11-30 16:45:01 +0100435 at91_set_gpio_input(data->rdy_pin, 1);
436
437 /* card detect pin */
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +0800438 if (gpio_is_valid(data->det_pin))
Andrew Victor86ad76b2006-11-30 16:45:01 +0100439 at91_set_gpio_input(data->det_pin, 1);
440
441 nand_data = *data;
442 platform_device_register(&at91sam9260_nand_device);
443}
444#else
HÃ¥vard Skinnemoen3c3796c2008-06-06 18:04:53 +0200445void __init at91_add_device_nand(struct atmel_nand_data *data) {}
Andrew Victor86ad76b2006-11-30 16:45:01 +0100446#endif
447
448
449/* --------------------------------------------------------------------
450 * TWI (i2c)
451 * -------------------------------------------------------------------- */
452
Andrew Victorf230d3f2007-11-19 13:47:20 +0100453/*
454 * Prefer the GPIO code since the TWI controller isn't robust
455 * (gets overruns and underruns under load) and can only issue
456 * repeated STARTs in one scenario (the driver doesn't yet handle them).
457 */
458
459#if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
460
461static struct i2c_gpio_platform_data pdata = {
462 .sda_pin = AT91_PIN_PA23,
463 .sda_is_open_drain = 1,
464 .scl_pin = AT91_PIN_PA24,
465 .scl_is_open_drain = 1,
466 .udelay = 2, /* ~100 kHz */
467};
468
469static struct platform_device at91sam9260_twi_device = {
470 .name = "i2c-gpio",
471 .id = -1,
472 .dev.platform_data = &pdata,
473};
474
475void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
476{
477 at91_set_GPIO_periph(AT91_PIN_PA23, 1); /* TWD (SDA) */
478 at91_set_multi_drive(AT91_PIN_PA23, 1);
479
480 at91_set_GPIO_periph(AT91_PIN_PA24, 1); /* TWCK (SCL) */
481 at91_set_multi_drive(AT91_PIN_PA24, 1);
482
483 i2c_register_board_info(0, devices, nr_devices);
484 platform_device_register(&at91sam9260_twi_device);
485}
486
487#elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
Andrew Victor86ad76b2006-11-30 16:45:01 +0100488
489static struct resource twi_resources[] = {
490 [0] = {
491 .start = AT91SAM9260_BASE_TWI,
492 .end = AT91SAM9260_BASE_TWI + SZ_16K - 1,
493 .flags = IORESOURCE_MEM,
494 },
495 [1] = {
496 .start = AT91SAM9260_ID_TWI,
497 .end = AT91SAM9260_ID_TWI,
498 .flags = IORESOURCE_IRQ,
499 },
500};
501
502static struct platform_device at91sam9260_twi_device = {
503 .name = "at91_i2c",
504 .id = -1,
505 .resource = twi_resources,
506 .num_resources = ARRAY_SIZE(twi_resources),
507};
508
Andrew Victorf230d3f2007-11-19 13:47:20 +0100509void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
Andrew Victor86ad76b2006-11-30 16:45:01 +0100510{
511 /* pins used for TWI interface */
512 at91_set_A_periph(AT91_PIN_PA23, 0); /* TWD */
513 at91_set_multi_drive(AT91_PIN_PA23, 1);
514
515 at91_set_A_periph(AT91_PIN_PA24, 0); /* TWCK */
516 at91_set_multi_drive(AT91_PIN_PA24, 1);
517
Andrew Victorf230d3f2007-11-19 13:47:20 +0100518 i2c_register_board_info(0, devices, nr_devices);
Andrew Victor86ad76b2006-11-30 16:45:01 +0100519 platform_device_register(&at91sam9260_twi_device);
520}
521#else
Andrew Victorf230d3f2007-11-19 13:47:20 +0100522void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {}
Andrew Victor86ad76b2006-11-30 16:45:01 +0100523#endif
524
525
526/* --------------------------------------------------------------------
527 * SPI
528 * -------------------------------------------------------------------- */
529
530#if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
Andrew Victorc6686ff2008-01-23 09:13:53 +0100531static u64 spi_dmamask = DMA_BIT_MASK(32);
Andrew Victor86ad76b2006-11-30 16:45:01 +0100532
533static struct resource spi0_resources[] = {
534 [0] = {
535 .start = AT91SAM9260_BASE_SPI0,
536 .end = AT91SAM9260_BASE_SPI0 + SZ_16K - 1,
537 .flags = IORESOURCE_MEM,
538 },
539 [1] = {
540 .start = AT91SAM9260_ID_SPI0,
541 .end = AT91SAM9260_ID_SPI0,
542 .flags = IORESOURCE_IRQ,
543 },
544};
545
546static struct platform_device at91sam9260_spi0_device = {
547 .name = "atmel_spi",
548 .id = 0,
549 .dev = {
550 .dma_mask = &spi_dmamask,
Andrew Victorc6686ff2008-01-23 09:13:53 +0100551 .coherent_dma_mask = DMA_BIT_MASK(32),
Andrew Victor86ad76b2006-11-30 16:45:01 +0100552 },
553 .resource = spi0_resources,
554 .num_resources = ARRAY_SIZE(spi0_resources),
555};
556
557static const unsigned spi0_standard_cs[4] = { AT91_PIN_PA3, AT91_PIN_PC11, AT91_PIN_PC16, AT91_PIN_PC17 };
558
559static struct resource spi1_resources[] = {
560 [0] = {
561 .start = AT91SAM9260_BASE_SPI1,
562 .end = AT91SAM9260_BASE_SPI1 + SZ_16K - 1,
563 .flags = IORESOURCE_MEM,
564 },
565 [1] = {
566 .start = AT91SAM9260_ID_SPI1,
567 .end = AT91SAM9260_ID_SPI1,
568 .flags = IORESOURCE_IRQ,
569 },
570};
571
572static struct platform_device at91sam9260_spi1_device = {
573 .name = "atmel_spi",
574 .id = 1,
575 .dev = {
576 .dma_mask = &spi_dmamask,
Andrew Victorc6686ff2008-01-23 09:13:53 +0100577 .coherent_dma_mask = DMA_BIT_MASK(32),
Andrew Victor86ad76b2006-11-30 16:45:01 +0100578 },
579 .resource = spi1_resources,
580 .num_resources = ARRAY_SIZE(spi1_resources),
581};
582
583static const unsigned spi1_standard_cs[4] = { AT91_PIN_PB3, AT91_PIN_PC5, AT91_PIN_PC4, AT91_PIN_PC3 };
584
585void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
586{
587 int i;
588 unsigned long cs_pin;
589 short enable_spi0 = 0;
590 short enable_spi1 = 0;
591
592 /* Choose SPI chip-selects */
593 for (i = 0; i < nr_devices; i++) {
594 if (devices[i].controller_data)
595 cs_pin = (unsigned long) devices[i].controller_data;
596 else if (devices[i].bus_num == 0)
597 cs_pin = spi0_standard_cs[devices[i].chip_select];
598 else
599 cs_pin = spi1_standard_cs[devices[i].chip_select];
600
Nicolas Ferre0c2c1f62012-03-28 11:58:58 +0200601 if (!gpio_is_valid(cs_pin))
602 continue;
603
Andrew Victor86ad76b2006-11-30 16:45:01 +0100604 if (devices[i].bus_num == 0)
605 enable_spi0 = 1;
606 else
607 enable_spi1 = 1;
608
609 /* enable chip-select pin */
610 at91_set_gpio_output(cs_pin, 1);
611
612 /* pass chip-select pin to driver */
613 devices[i].controller_data = (void *) cs_pin;
614 }
615
616 spi_register_board_info(devices, nr_devices);
617
618 /* Configure SPI bus(es) */
619 if (enable_spi0) {
620 at91_set_A_periph(AT91_PIN_PA0, 0); /* SPI0_MISO */
621 at91_set_A_periph(AT91_PIN_PA1, 0); /* SPI0_MOSI */
622 at91_set_A_periph(AT91_PIN_PA2, 0); /* SPI1_SPCK */
623
Andrew Victor86ad76b2006-11-30 16:45:01 +0100624 platform_device_register(&at91sam9260_spi0_device);
625 }
626 if (enable_spi1) {
627 at91_set_A_periph(AT91_PIN_PB0, 0); /* SPI1_MISO */
628 at91_set_A_periph(AT91_PIN_PB1, 0); /* SPI1_MOSI */
629 at91_set_A_periph(AT91_PIN_PB2, 0); /* SPI1_SPCK */
630
Andrew Victor86ad76b2006-11-30 16:45:01 +0100631 platform_device_register(&at91sam9260_spi1_device);
632 }
633}
634#else
635void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
636#endif
637
638
639/* --------------------------------------------------------------------
Andrew Victore5f40bf2008-04-02 21:58:00 +0100640 * Timer/Counter blocks
641 * -------------------------------------------------------------------- */
642
643#ifdef CONFIG_ATMEL_TCLIB
644
645static struct resource tcb0_resources[] = {
646 [0] = {
647 .start = AT91SAM9260_BASE_TCB0,
Nicolas Ferre29831292012-01-18 16:56:36 +0100648 .end = AT91SAM9260_BASE_TCB0 + SZ_256 - 1,
Andrew Victore5f40bf2008-04-02 21:58:00 +0100649 .flags = IORESOURCE_MEM,
650 },
651 [1] = {
652 .start = AT91SAM9260_ID_TC0,
653 .end = AT91SAM9260_ID_TC0,
654 .flags = IORESOURCE_IRQ,
655 },
656 [2] = {
657 .start = AT91SAM9260_ID_TC1,
658 .end = AT91SAM9260_ID_TC1,
659 .flags = IORESOURCE_IRQ,
660 },
661 [3] = {
662 .start = AT91SAM9260_ID_TC2,
663 .end = AT91SAM9260_ID_TC2,
664 .flags = IORESOURCE_IRQ,
665 },
666};
667
668static struct platform_device at91sam9260_tcb0_device = {
669 .name = "atmel_tcb",
670 .id = 0,
671 .resource = tcb0_resources,
672 .num_resources = ARRAY_SIZE(tcb0_resources),
673};
674
675static struct resource tcb1_resources[] = {
676 [0] = {
677 .start = AT91SAM9260_BASE_TCB1,
Nicolas Ferre29831292012-01-18 16:56:36 +0100678 .end = AT91SAM9260_BASE_TCB1 + SZ_256 - 1,
Andrew Victore5f40bf2008-04-02 21:58:00 +0100679 .flags = IORESOURCE_MEM,
680 },
681 [1] = {
682 .start = AT91SAM9260_ID_TC3,
683 .end = AT91SAM9260_ID_TC3,
684 .flags = IORESOURCE_IRQ,
685 },
686 [2] = {
687 .start = AT91SAM9260_ID_TC4,
688 .end = AT91SAM9260_ID_TC4,
689 .flags = IORESOURCE_IRQ,
690 },
691 [3] = {
692 .start = AT91SAM9260_ID_TC5,
693 .end = AT91SAM9260_ID_TC5,
694 .flags = IORESOURCE_IRQ,
695 },
696};
697
698static struct platform_device at91sam9260_tcb1_device = {
699 .name = "atmel_tcb",
700 .id = 1,
701 .resource = tcb1_resources,
702 .num_resources = ARRAY_SIZE(tcb1_resources),
703};
704
Nicolas Ferre3a61a5d2012-01-19 10:13:40 +0100705#if defined(CONFIG_OF)
706static struct of_device_id tcb_ids[] = {
707 { .compatible = "atmel,at91rm9200-tcb" },
708 { /*sentinel*/ }
709};
710#endif
711
Andrew Victore5f40bf2008-04-02 21:58:00 +0100712static void __init at91_add_device_tc(void)
713{
Nicolas Ferre3a61a5d2012-01-19 10:13:40 +0100714#if defined(CONFIG_OF)
715 struct device_node *np;
716
717 np = of_find_matching_node(NULL, tcb_ids);
718 if (np) {
719 of_node_put(np);
720 return;
721 }
722#endif
723
Andrew Victore5f40bf2008-04-02 21:58:00 +0100724 platform_device_register(&at91sam9260_tcb0_device);
Andrew Victore5f40bf2008-04-02 21:58:00 +0100725 platform_device_register(&at91sam9260_tcb1_device);
726}
727#else
728static void __init at91_add_device_tc(void) { }
729#endif
730
731
732/* --------------------------------------------------------------------
Andrew Victor884f5a62008-01-23 09:11:13 +0100733 * RTT
734 * -------------------------------------------------------------------- */
735
736static struct resource rtt_resources[] = {
737 {
Jean-Christophe PLAGNIOL-VILLARDeab5fd62011-09-18 10:12:00 +0800738 .start = AT91SAM9260_BASE_RTT,
739 .end = AT91SAM9260_BASE_RTT + SZ_16 - 1,
Andrew Victor884f5a62008-01-23 09:11:13 +0100740 .flags = IORESOURCE_MEM,
Jean-Christophe PLAGNIOL-VILLARDb3af8b42012-02-15 21:24:46 +0800741 }, {
742 .flags = IORESOURCE_MEM,
743 },
Andrew Victor884f5a62008-01-23 09:11:13 +0100744};
745
746static struct platform_device at91sam9260_rtt_device = {
747 .name = "at91_rtt",
Andrew Victor4fd92122008-04-02 21:55:19 +0100748 .id = 0,
Andrew Victor884f5a62008-01-23 09:11:13 +0100749 .resource = rtt_resources,
Andrew Victor884f5a62008-01-23 09:11:13 +0100750};
751
Jean-Christophe PLAGNIOL-VILLARD205056a2012-02-15 20:51:37 +0800752
753#if IS_ENABLED(CONFIG_RTC_DRV_AT91SAM9)
754static void __init at91_add_device_rtt_rtc(void)
755{
756 at91sam9260_rtt_device.name = "rtc-at91sam9";
Jean-Christophe PLAGNIOL-VILLARDb3af8b42012-02-15 21:24:46 +0800757 /*
758 * The second resource is needed:
759 * GPBR will serve as the storage for RTC time offset
760 */
761 at91sam9260_rtt_device.num_resources = 2;
762 rtt_resources[1].start = AT91SAM9260_BASE_GPBR +
763 4 * CONFIG_RTC_DRV_AT91SAM9_GPBR;
764 rtt_resources[1].end = rtt_resources[1].start + 3;
Jean-Christophe PLAGNIOL-VILLARD205056a2012-02-15 20:51:37 +0800765}
766#else
Jean-Christophe PLAGNIOL-VILLARDb3af8b42012-02-15 21:24:46 +0800767static void __init at91_add_device_rtt_rtc(void)
768{
769 /* Only one resource is needed: RTT not used as RTC */
770 at91sam9260_rtt_device.num_resources = 1;
771}
Jean-Christophe PLAGNIOL-VILLARD205056a2012-02-15 20:51:37 +0800772#endif
773
Andrew Victor884f5a62008-01-23 09:11:13 +0100774static void __init at91_add_device_rtt(void)
775{
Jean-Christophe PLAGNIOL-VILLARD205056a2012-02-15 20:51:37 +0800776 at91_add_device_rtt_rtc();
Andrew Victor884f5a62008-01-23 09:11:13 +0100777 platform_device_register(&at91sam9260_rtt_device);
778}
779
780
781/* --------------------------------------------------------------------
782 * Watchdog
783 * -------------------------------------------------------------------- */
784
Andrew Victor2af29b72009-02-11 21:23:10 +0100785#if defined(CONFIG_AT91SAM9X_WATCHDOG) || defined(CONFIG_AT91SAM9X_WATCHDOG_MODULE)
Jean-Christophe PLAGNIOL-VILLARDc1c30a22011-11-02 01:43:31 +0800786static struct resource wdt_resources[] = {
787 {
788 .start = AT91SAM9260_BASE_WDT,
789 .end = AT91SAM9260_BASE_WDT + SZ_16 - 1,
790 .flags = IORESOURCE_MEM,
791 }
792};
793
Andrew Victor884f5a62008-01-23 09:11:13 +0100794static struct platform_device at91sam9260_wdt_device = {
795 .name = "at91_wdt",
796 .id = -1,
Jean-Christophe PLAGNIOL-VILLARDc1c30a22011-11-02 01:43:31 +0800797 .resource = wdt_resources,
798 .num_resources = ARRAY_SIZE(wdt_resources),
Andrew Victor884f5a62008-01-23 09:11:13 +0100799};
800
801static void __init at91_add_device_watchdog(void)
802{
803 platform_device_register(&at91sam9260_wdt_device);
804}
805#else
806static void __init at91_add_device_watchdog(void) {}
807#endif
808
809
810/* --------------------------------------------------------------------
Andrew Victorbfbc3262008-01-23 09:18:06 +0100811 * SSC -- Synchronous Serial Controller
812 * -------------------------------------------------------------------- */
813
814#if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
815static u64 ssc_dmamask = DMA_BIT_MASK(32);
816
817static struct resource ssc_resources[] = {
818 [0] = {
819 .start = AT91SAM9260_BASE_SSC,
820 .end = AT91SAM9260_BASE_SSC + SZ_16K - 1,
821 .flags = IORESOURCE_MEM,
822 },
823 [1] = {
824 .start = AT91SAM9260_ID_SSC,
825 .end = AT91SAM9260_ID_SSC,
826 .flags = IORESOURCE_IRQ,
827 },
828};
829
830static struct platform_device at91sam9260_ssc_device = {
831 .name = "ssc",
832 .id = 0,
833 .dev = {
834 .dma_mask = &ssc_dmamask,
835 .coherent_dma_mask = DMA_BIT_MASK(32),
836 },
837 .resource = ssc_resources,
838 .num_resources = ARRAY_SIZE(ssc_resources),
839};
840
841static inline void configure_ssc_pins(unsigned pins)
842{
843 if (pins & ATMEL_SSC_TF)
844 at91_set_A_periph(AT91_PIN_PB17, 1);
845 if (pins & ATMEL_SSC_TK)
846 at91_set_A_periph(AT91_PIN_PB16, 1);
847 if (pins & ATMEL_SSC_TD)
848 at91_set_A_periph(AT91_PIN_PB18, 1);
849 if (pins & ATMEL_SSC_RD)
850 at91_set_A_periph(AT91_PIN_PB19, 1);
851 if (pins & ATMEL_SSC_RK)
852 at91_set_A_periph(AT91_PIN_PB20, 1);
853 if (pins & ATMEL_SSC_RF)
854 at91_set_A_periph(AT91_PIN_PB21, 1);
855}
856
857/*
858 * SSC controllers are accessed through library code, instead of any
859 * kind of all-singing/all-dancing driver. For example one could be
860 * used by a particular I2S audio codec's driver, while another one
861 * on the same system might be used by a custom data capture driver.
862 */
863void __init at91_add_device_ssc(unsigned id, unsigned pins)
864{
865 struct platform_device *pdev;
866
867 /*
868 * NOTE: caller is responsible for passing information matching
869 * "pins" to whatever will be using each particular controller.
870 */
871 switch (id) {
872 case AT91SAM9260_ID_SSC:
873 pdev = &at91sam9260_ssc_device;
874 configure_ssc_pins(pins);
Andrew Victorbfbc3262008-01-23 09:18:06 +0100875 break;
876 default:
877 return;
878 }
879
880 platform_device_register(pdev);
881}
882
883#else
884void __init at91_add_device_ssc(unsigned id, unsigned pins) {}
885#endif
886
887
888/* --------------------------------------------------------------------
Andrew Victor86ad76b2006-11-30 16:45:01 +0100889 * UART
890 * -------------------------------------------------------------------- */
891#if defined(CONFIG_SERIAL_ATMEL)
892static struct resource dbgu_resources[] = {
893 [0] = {
Jean-Christophe PLAGNIOL-VILLARD13079a72011-11-02 01:43:31 +0800894 .start = AT91SAM9260_BASE_DBGU,
895 .end = AT91SAM9260_BASE_DBGU + SZ_512 - 1,
Andrew Victor86ad76b2006-11-30 16:45:01 +0100896 .flags = IORESOURCE_MEM,
897 },
898 [1] = {
899 .start = AT91_ID_SYS,
900 .end = AT91_ID_SYS,
901 .flags = IORESOURCE_IRQ,
902 },
903};
904
905static struct atmel_uart_data dbgu_data = {
906 .use_dma_tx = 0,
907 .use_dma_rx = 0, /* DBGU not capable of receive DMA */
Andrew Victor86ad76b2006-11-30 16:45:01 +0100908};
909
Andrew Victorc6686ff2008-01-23 09:13:53 +0100910static u64 dbgu_dmamask = DMA_BIT_MASK(32);
911
Andrew Victor86ad76b2006-11-30 16:45:01 +0100912static struct platform_device at91sam9260_dbgu_device = {
913 .name = "atmel_usart",
914 .id = 0,
915 .dev = {
Andrew Victorc6686ff2008-01-23 09:13:53 +0100916 .dma_mask = &dbgu_dmamask,
917 .coherent_dma_mask = DMA_BIT_MASK(32),
918 .platform_data = &dbgu_data,
Andrew Victor86ad76b2006-11-30 16:45:01 +0100919 },
920 .resource = dbgu_resources,
921 .num_resources = ARRAY_SIZE(dbgu_resources),
922};
923
924static inline void configure_dbgu_pins(void)
925{
926 at91_set_A_periph(AT91_PIN_PB14, 0); /* DRXD */
927 at91_set_A_periph(AT91_PIN_PB15, 1); /* DTXD */
928}
929
930static struct resource uart0_resources[] = {
931 [0] = {
932 .start = AT91SAM9260_BASE_US0,
933 .end = AT91SAM9260_BASE_US0 + SZ_16K - 1,
934 .flags = IORESOURCE_MEM,
935 },
936 [1] = {
937 .start = AT91SAM9260_ID_US0,
938 .end = AT91SAM9260_ID_US0,
939 .flags = IORESOURCE_IRQ,
940 },
941};
942
943static struct atmel_uart_data uart0_data = {
944 .use_dma_tx = 1,
945 .use_dma_rx = 1,
946};
947
Andrew Victorc6686ff2008-01-23 09:13:53 +0100948static u64 uart0_dmamask = DMA_BIT_MASK(32);
949
Andrew Victor86ad76b2006-11-30 16:45:01 +0100950static struct platform_device at91sam9260_uart0_device = {
951 .name = "atmel_usart",
952 .id = 1,
953 .dev = {
Andrew Victorc6686ff2008-01-23 09:13:53 +0100954 .dma_mask = &uart0_dmamask,
955 .coherent_dma_mask = DMA_BIT_MASK(32),
956 .platform_data = &uart0_data,
Andrew Victor86ad76b2006-11-30 16:45:01 +0100957 },
958 .resource = uart0_resources,
959 .num_resources = ARRAY_SIZE(uart0_resources),
960};
961
Andrew Victorc8f385a2008-01-23 09:25:15 +0100962static inline void configure_usart0_pins(unsigned pins)
Andrew Victor86ad76b2006-11-30 16:45:01 +0100963{
964 at91_set_A_periph(AT91_PIN_PB4, 1); /* TXD0 */
965 at91_set_A_periph(AT91_PIN_PB5, 0); /* RXD0 */
Andrew Victorc8f385a2008-01-23 09:25:15 +0100966
967 if (pins & ATMEL_UART_RTS)
968 at91_set_A_periph(AT91_PIN_PB26, 0); /* RTS0 */
969 if (pins & ATMEL_UART_CTS)
970 at91_set_A_periph(AT91_PIN_PB27, 0); /* CTS0 */
971 if (pins & ATMEL_UART_DTR)
972 at91_set_A_periph(AT91_PIN_PB24, 0); /* DTR0 */
973 if (pins & ATMEL_UART_DSR)
974 at91_set_A_periph(AT91_PIN_PB22, 0); /* DSR0 */
975 if (pins & ATMEL_UART_DCD)
976 at91_set_A_periph(AT91_PIN_PB23, 0); /* DCD0 */
977 if (pins & ATMEL_UART_RI)
978 at91_set_A_periph(AT91_PIN_PB25, 0); /* RI0 */
Andrew Victor86ad76b2006-11-30 16:45:01 +0100979}
980
981static struct resource uart1_resources[] = {
982 [0] = {
983 .start = AT91SAM9260_BASE_US1,
984 .end = AT91SAM9260_BASE_US1 + SZ_16K - 1,
985 .flags = IORESOURCE_MEM,
986 },
987 [1] = {
988 .start = AT91SAM9260_ID_US1,
989 .end = AT91SAM9260_ID_US1,
990 .flags = IORESOURCE_IRQ,
991 },
992};
993
994static struct atmel_uart_data uart1_data = {
995 .use_dma_tx = 1,
996 .use_dma_rx = 1,
997};
998
Andrew Victorc6686ff2008-01-23 09:13:53 +0100999static u64 uart1_dmamask = DMA_BIT_MASK(32);
1000
Andrew Victor86ad76b2006-11-30 16:45:01 +01001001static struct platform_device at91sam9260_uart1_device = {
1002 .name = "atmel_usart",
1003 .id = 2,
1004 .dev = {
Andrew Victorc6686ff2008-01-23 09:13:53 +01001005 .dma_mask = &uart1_dmamask,
1006 .coherent_dma_mask = DMA_BIT_MASK(32),
1007 .platform_data = &uart1_data,
Andrew Victor86ad76b2006-11-30 16:45:01 +01001008 },
1009 .resource = uart1_resources,
1010 .num_resources = ARRAY_SIZE(uart1_resources),
1011};
1012
Andrew Victorc8f385a2008-01-23 09:25:15 +01001013static inline void configure_usart1_pins(unsigned pins)
Andrew Victor86ad76b2006-11-30 16:45:01 +01001014{
1015 at91_set_A_periph(AT91_PIN_PB6, 1); /* TXD1 */
1016 at91_set_A_periph(AT91_PIN_PB7, 0); /* RXD1 */
Andrew Victorc8f385a2008-01-23 09:25:15 +01001017
1018 if (pins & ATMEL_UART_RTS)
1019 at91_set_A_periph(AT91_PIN_PB28, 0); /* RTS1 */
1020 if (pins & ATMEL_UART_CTS)
1021 at91_set_A_periph(AT91_PIN_PB29, 0); /* CTS1 */
Andrew Victor86ad76b2006-11-30 16:45:01 +01001022}
1023
1024static struct resource uart2_resources[] = {
1025 [0] = {
1026 .start = AT91SAM9260_BASE_US2,
1027 .end = AT91SAM9260_BASE_US2 + SZ_16K - 1,
1028 .flags = IORESOURCE_MEM,
1029 },
1030 [1] = {
1031 .start = AT91SAM9260_ID_US2,
1032 .end = AT91SAM9260_ID_US2,
1033 .flags = IORESOURCE_IRQ,
1034 },
1035};
1036
1037static struct atmel_uart_data uart2_data = {
1038 .use_dma_tx = 1,
1039 .use_dma_rx = 1,
1040};
1041
Andrew Victorc6686ff2008-01-23 09:13:53 +01001042static u64 uart2_dmamask = DMA_BIT_MASK(32);
1043
Andrew Victor86ad76b2006-11-30 16:45:01 +01001044static struct platform_device at91sam9260_uart2_device = {
1045 .name = "atmel_usart",
1046 .id = 3,
1047 .dev = {
Andrew Victorc6686ff2008-01-23 09:13:53 +01001048 .dma_mask = &uart2_dmamask,
1049 .coherent_dma_mask = DMA_BIT_MASK(32),
1050 .platform_data = &uart2_data,
Andrew Victor86ad76b2006-11-30 16:45:01 +01001051 },
1052 .resource = uart2_resources,
1053 .num_resources = ARRAY_SIZE(uart2_resources),
1054};
1055
Andrew Victorc8f385a2008-01-23 09:25:15 +01001056static inline void configure_usart2_pins(unsigned pins)
Andrew Victor86ad76b2006-11-30 16:45:01 +01001057{
1058 at91_set_A_periph(AT91_PIN_PB8, 1); /* TXD2 */
1059 at91_set_A_periph(AT91_PIN_PB9, 0); /* RXD2 */
Andrew Victorc8f385a2008-01-23 09:25:15 +01001060
1061 if (pins & ATMEL_UART_RTS)
1062 at91_set_A_periph(AT91_PIN_PA4, 0); /* RTS2 */
1063 if (pins & ATMEL_UART_CTS)
1064 at91_set_A_periph(AT91_PIN_PA5, 0); /* CTS2 */
Andrew Victor86ad76b2006-11-30 16:45:01 +01001065}
1066
1067static struct resource uart3_resources[] = {
1068 [0] = {
1069 .start = AT91SAM9260_BASE_US3,
1070 .end = AT91SAM9260_BASE_US3 + SZ_16K - 1,
1071 .flags = IORESOURCE_MEM,
1072 },
1073 [1] = {
1074 .start = AT91SAM9260_ID_US3,
1075 .end = AT91SAM9260_ID_US3,
1076 .flags = IORESOURCE_IRQ,
1077 },
1078};
1079
1080static struct atmel_uart_data uart3_data = {
1081 .use_dma_tx = 1,
1082 .use_dma_rx = 1,
1083};
1084
Andrew Victorc6686ff2008-01-23 09:13:53 +01001085static u64 uart3_dmamask = DMA_BIT_MASK(32);
1086
Andrew Victor86ad76b2006-11-30 16:45:01 +01001087static struct platform_device at91sam9260_uart3_device = {
1088 .name = "atmel_usart",
1089 .id = 4,
1090 .dev = {
Andrew Victorc6686ff2008-01-23 09:13:53 +01001091 .dma_mask = &uart3_dmamask,
1092 .coherent_dma_mask = DMA_BIT_MASK(32),
1093 .platform_data = &uart3_data,
Andrew Victor86ad76b2006-11-30 16:45:01 +01001094 },
1095 .resource = uart3_resources,
1096 .num_resources = ARRAY_SIZE(uart3_resources),
1097};
1098
Andrew Victorc8f385a2008-01-23 09:25:15 +01001099static inline void configure_usart3_pins(unsigned pins)
Andrew Victor86ad76b2006-11-30 16:45:01 +01001100{
1101 at91_set_A_periph(AT91_PIN_PB10, 1); /* TXD3 */
1102 at91_set_A_periph(AT91_PIN_PB11, 0); /* RXD3 */
Andrew Victorc8f385a2008-01-23 09:25:15 +01001103
1104 if (pins & ATMEL_UART_RTS)
1105 at91_set_B_periph(AT91_PIN_PC8, 0); /* RTS3 */
1106 if (pins & ATMEL_UART_CTS)
1107 at91_set_B_periph(AT91_PIN_PC10, 0); /* CTS3 */
Andrew Victor86ad76b2006-11-30 16:45:01 +01001108}
1109
1110static struct resource uart4_resources[] = {
1111 [0] = {
1112 .start = AT91SAM9260_BASE_US4,
1113 .end = AT91SAM9260_BASE_US4 + SZ_16K - 1,
1114 .flags = IORESOURCE_MEM,
1115 },
1116 [1] = {
1117 .start = AT91SAM9260_ID_US4,
1118 .end = AT91SAM9260_ID_US4,
1119 .flags = IORESOURCE_IRQ,
1120 },
1121};
1122
1123static struct atmel_uart_data uart4_data = {
1124 .use_dma_tx = 1,
1125 .use_dma_rx = 1,
1126};
1127
Andrew Victorc6686ff2008-01-23 09:13:53 +01001128static u64 uart4_dmamask = DMA_BIT_MASK(32);
1129
Andrew Victor86ad76b2006-11-30 16:45:01 +01001130static struct platform_device at91sam9260_uart4_device = {
1131 .name = "atmel_usart",
1132 .id = 5,
1133 .dev = {
Andrew Victorc6686ff2008-01-23 09:13:53 +01001134 .dma_mask = &uart4_dmamask,
1135 .coherent_dma_mask = DMA_BIT_MASK(32),
1136 .platform_data = &uart4_data,
Andrew Victor86ad76b2006-11-30 16:45:01 +01001137 },
1138 .resource = uart4_resources,
1139 .num_resources = ARRAY_SIZE(uart4_resources),
1140};
1141
1142static inline void configure_usart4_pins(void)
1143{
1144 at91_set_B_periph(AT91_PIN_PA31, 1); /* TXD4 */
1145 at91_set_B_periph(AT91_PIN_PA30, 0); /* RXD4 */
1146}
1147
1148static struct resource uart5_resources[] = {
1149 [0] = {
1150 .start = AT91SAM9260_BASE_US5,
1151 .end = AT91SAM9260_BASE_US5 + SZ_16K - 1,
1152 .flags = IORESOURCE_MEM,
1153 },
1154 [1] = {
1155 .start = AT91SAM9260_ID_US5,
1156 .end = AT91SAM9260_ID_US5,
1157 .flags = IORESOURCE_IRQ,
1158 },
1159};
1160
1161static struct atmel_uart_data uart5_data = {
1162 .use_dma_tx = 1,
1163 .use_dma_rx = 1,
1164};
1165
Andrew Victorc6686ff2008-01-23 09:13:53 +01001166static u64 uart5_dmamask = DMA_BIT_MASK(32);
1167
Andrew Victor86ad76b2006-11-30 16:45:01 +01001168static struct platform_device at91sam9260_uart5_device = {
1169 .name = "atmel_usart",
1170 .id = 6,
1171 .dev = {
Andrew Victorc6686ff2008-01-23 09:13:53 +01001172 .dma_mask = &uart5_dmamask,
1173 .coherent_dma_mask = DMA_BIT_MASK(32),
1174 .platform_data = &uart5_data,
Andrew Victor86ad76b2006-11-30 16:45:01 +01001175 },
1176 .resource = uart5_resources,
1177 .num_resources = ARRAY_SIZE(uart5_resources),
1178};
1179
1180static inline void configure_usart5_pins(void)
1181{
1182 at91_set_A_periph(AT91_PIN_PB12, 1); /* TXD5 */
1183 at91_set_A_periph(AT91_PIN_PB13, 0); /* RXD5 */
1184}
1185
Andrew Victor11aadac2008-04-15 21:16:38 +01001186static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
Andrew Victor86ad76b2006-11-30 16:45:01 +01001187
Andrew Victorc8f385a2008-01-23 09:25:15 +01001188void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
1189{
1190 struct platform_device *pdev;
Jean-Christophe PLAGNIOL-VILLARD2b348e22011-04-10 14:10:05 +08001191 struct atmel_uart_data *pdata;
Andrew Victorc8f385a2008-01-23 09:25:15 +01001192
1193 switch (id) {
1194 case 0: /* DBGU */
1195 pdev = &at91sam9260_dbgu_device;
1196 configure_dbgu_pins();
Andrew Victorc8f385a2008-01-23 09:25:15 +01001197 break;
1198 case AT91SAM9260_ID_US0:
1199 pdev = &at91sam9260_uart0_device;
1200 configure_usart0_pins(pins);
Andrew Victorc8f385a2008-01-23 09:25:15 +01001201 break;
1202 case AT91SAM9260_ID_US1:
1203 pdev = &at91sam9260_uart1_device;
1204 configure_usart1_pins(pins);
Andrew Victorc8f385a2008-01-23 09:25:15 +01001205 break;
1206 case AT91SAM9260_ID_US2:
1207 pdev = &at91sam9260_uart2_device;
1208 configure_usart2_pins(pins);
Andrew Victorc8f385a2008-01-23 09:25:15 +01001209 break;
1210 case AT91SAM9260_ID_US3:
1211 pdev = &at91sam9260_uart3_device;
1212 configure_usart3_pins(pins);
Andrew Victorc8f385a2008-01-23 09:25:15 +01001213 break;
1214 case AT91SAM9260_ID_US4:
1215 pdev = &at91sam9260_uart4_device;
1216 configure_usart4_pins();
Andrew Victorc8f385a2008-01-23 09:25:15 +01001217 break;
1218 case AT91SAM9260_ID_US5:
1219 pdev = &at91sam9260_uart5_device;
1220 configure_usart5_pins();
Andrew Victorc8f385a2008-01-23 09:25:15 +01001221 break;
1222 default:
1223 return;
1224 }
Jean-Christophe PLAGNIOL-VILLARD2b348e22011-04-10 14:10:05 +08001225 pdata = pdev->dev.platform_data;
1226 pdata->num = portnr; /* update to mapped ID */
Andrew Victorc8f385a2008-01-23 09:25:15 +01001227
1228 if (portnr < ATMEL_MAX_UART)
1229 at91_uarts[portnr] = pdev;
1230}
1231
1232void __init at91_set_serial_console(unsigned portnr)
1233{
Jean-Christophe PLAGNIOL-VILLARDbd602992011-02-02 07:27:07 +01001234 if (portnr < ATMEL_MAX_UART) {
Andrew Victorc8f385a2008-01-23 09:25:15 +01001235 atmel_default_console_device = at91_uarts[portnr];
Jean-Christophe PLAGNIOL-VILLARD5c1f9662011-06-21 11:24:33 +08001236 at91sam9260_set_console_clock(at91_uarts[portnr]->id);
Jean-Christophe PLAGNIOL-VILLARDbd602992011-02-02 07:27:07 +01001237 }
Andrew Victorc8f385a2008-01-23 09:25:15 +01001238}
1239
Andrew Victor86ad76b2006-11-30 16:45:01 +01001240void __init at91_add_device_serial(void)
1241{
1242 int i;
1243
1244 for (i = 0; i < ATMEL_MAX_UART; i++) {
1245 if (at91_uarts[i])
1246 platform_device_register(at91_uarts[i]);
1247 }
Andrew Victor11aadac2008-04-15 21:16:38 +01001248
1249 if (!atmel_default_console_device)
1250 printk(KERN_INFO "AT91: No default serial console defined.\n");
Andrew Victor86ad76b2006-11-30 16:45:01 +01001251}
1252#else
Andrew Victorc8f385a2008-01-23 09:25:15 +01001253void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
1254void __init at91_set_serial_console(unsigned portnr) {}
Andrew Victor86ad76b2006-11-30 16:45:01 +01001255void __init at91_add_device_serial(void) {}
1256#endif
1257
Sergey Matyukevichfb852052009-07-30 22:23:24 +01001258/* --------------------------------------------------------------------
1259 * CF/IDE
1260 * -------------------------------------------------------------------- */
1261
Jean-Christophe PLAGNIOL-VILLARDcf844752011-12-15 21:24:03 +08001262#if defined(CONFIG_PATA_AT91) || defined(CONFIG_PATA_AT91_MODULE) || \
Sergey Matyukevichfb852052009-07-30 22:23:24 +01001263 defined(CONFIG_AT91_CF) || defined(CONFIG_AT91_CF_MODULE)
1264
1265static struct at91_cf_data cf0_data;
1266
1267static struct resource cf0_resources[] = {
1268 [0] = {
1269 .start = AT91_CHIPSELECT_4,
1270 .end = AT91_CHIPSELECT_4 + SZ_256M - 1,
1271 .flags = IORESOURCE_MEM,
1272 }
1273};
1274
1275static struct platform_device cf0_device = {
1276 .id = 0,
1277 .dev = {
1278 .platform_data = &cf0_data,
1279 },
1280 .resource = cf0_resources,
1281 .num_resources = ARRAY_SIZE(cf0_resources),
1282};
1283
1284static struct at91_cf_data cf1_data;
1285
1286static struct resource cf1_resources[] = {
1287 [0] = {
1288 .start = AT91_CHIPSELECT_5,
1289 .end = AT91_CHIPSELECT_5 + SZ_256M - 1,
1290 .flags = IORESOURCE_MEM,
1291 }
1292};
1293
1294static struct platform_device cf1_device = {
1295 .id = 1,
1296 .dev = {
1297 .platform_data = &cf1_data,
1298 },
1299 .resource = cf1_resources,
1300 .num_resources = ARRAY_SIZE(cf1_resources),
1301};
1302
1303void __init at91_add_device_cf(struct at91_cf_data *data)
1304{
1305 struct platform_device *pdev;
1306 unsigned long csa;
1307
1308 if (!data)
1309 return;
1310
Jean-Christophe PLAGNIOL-VILLARD4342d642011-11-27 23:15:50 +08001311 csa = at91_matrix_read(AT91_MATRIX_EBICSA);
Sergey Matyukevichfb852052009-07-30 22:23:24 +01001312
1313 switch (data->chipselect) {
1314 case 4:
1315 at91_set_multi_drive(AT91_PIN_PC8, 0);
1316 at91_set_A_periph(AT91_PIN_PC8, 0);
1317 csa |= AT91_MATRIX_CS4A_SMC_CF1;
1318 cf0_data = *data;
1319 pdev = &cf0_device;
1320 break;
1321 case 5:
1322 at91_set_multi_drive(AT91_PIN_PC9, 0);
1323 at91_set_A_periph(AT91_PIN_PC9, 0);
1324 csa |= AT91_MATRIX_CS5A_SMC_CF2;
1325 cf1_data = *data;
1326 pdev = &cf1_device;
1327 break;
1328 default:
1329 printk(KERN_ERR "AT91 CF: bad chip-select requested (%u)\n",
1330 data->chipselect);
1331 return;
1332 }
1333
Jean-Christophe PLAGNIOL-VILLARD4342d642011-11-27 23:15:50 +08001334 at91_matrix_write(AT91_MATRIX_EBICSA, csa);
Sergey Matyukevichfb852052009-07-30 22:23:24 +01001335
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +08001336 if (gpio_is_valid(data->rst_pin)) {
Sergey Matyukevichfb852052009-07-30 22:23:24 +01001337 at91_set_multi_drive(data->rst_pin, 0);
1338 at91_set_gpio_output(data->rst_pin, 1);
1339 }
1340
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +08001341 if (gpio_is_valid(data->irq_pin)) {
Sergey Matyukevichfb852052009-07-30 22:23:24 +01001342 at91_set_gpio_input(data->irq_pin, 0);
1343 at91_set_deglitch(data->irq_pin, 1);
1344 }
1345
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +08001346 if (gpio_is_valid(data->det_pin)) {
Sergey Matyukevichfb852052009-07-30 22:23:24 +01001347 at91_set_gpio_input(data->det_pin, 0);
1348 at91_set_deglitch(data->det_pin, 1);
1349 }
1350
1351 at91_set_B_periph(AT91_PIN_PC6, 0); /* CFCE1 */
1352 at91_set_B_periph(AT91_PIN_PC7, 0); /* CFCE2 */
1353 at91_set_A_periph(AT91_PIN_PC10, 0); /* CFRNW */
1354 at91_set_A_periph(AT91_PIN_PC15, 1); /* NWAIT */
1355
1356 if (data->flags & AT91_CF_TRUE_IDE)
1357#if defined(CONFIG_PATA_AT91) || defined(CONFIG_PATA_AT91_MODULE)
1358 pdev->name = "pata_at91";
Sergey Matyukevichfb852052009-07-30 22:23:24 +01001359#else
Jean-Christophe PLAGNIOL-VILLARDcf844752011-12-15 21:24:03 +08001360#warning "board requires AT91_CF_TRUE_IDE: enable pata_at91"
Sergey Matyukevichfb852052009-07-30 22:23:24 +01001361#endif
1362 else
1363 pdev->name = "at91_cf";
1364
1365 platform_device_register(pdev);
1366}
1367
1368#else
1369void __init at91_add_device_cf(struct at91_cf_data * data) {}
1370#endif
Andrew Victor86ad76b2006-11-30 16:45:01 +01001371
1372/* -------------------------------------------------------------------- */
1373/*
1374 * These devices are always present and don't need any board-specific
1375 * setup.
1376 */
1377static int __init at91_add_standard_devices(void)
1378{
Andrew Victor884f5a62008-01-23 09:11:13 +01001379 at91_add_device_rtt();
1380 at91_add_device_watchdog();
Andrew Victore5f40bf2008-04-02 21:58:00 +01001381 at91_add_device_tc();
Andrew Victor86ad76b2006-11-30 16:45:01 +01001382 return 0;
1383}
1384
1385arch_initcall(at91_add_standard_devices);