blob: 4860918b411eaa1a348bc5a2570b02238cdbe08b [file] [log] [blame]
SAN People73a59c12006-01-09 17:05:41 +00001/*
Andrew Victor9d041262007-02-05 11:42:07 +01002 * arch/arm/mach-at91/at91rm9200_devices.c
SAN People73a59c12006-01-09 17:05:41 +00003 *
4 * Copyright (C) 2005 Thibaut VARENE <varenet@parisc-linux.org>
5 * Copyright (C) 2005 David Brownell
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 */
13#include <asm/mach/arch.h>
14#include <asm/mach/map.h>
15
Andrew Victorc6686ff2008-01-23 09:13:53 +010016#include <linux/dma-mapping.h>
Russell King2f8163b2011-07-26 10:53:52 +010017#include <linux/gpio.h>
SAN People73a59c12006-01-09 17:05:41 +000018#include <linux/platform_device.h>
Andrew Victorf230d3f2007-11-19 13:47:20 +010019#include <linux/i2c-gpio.h>
SAN People73a59c12006-01-09 17:05:41 +000020
Russell Kinga09e64f2008-08-05 16:14:15 +010021#include <mach/at91rm9200.h>
22#include <mach/at91rm9200_mc.h>
Jean-Christophe PLAGNIOL-VILLARDf363c402012-02-13 12:58:53 +080023#include <mach/at91_ramc.h>
Uwe Kleine-Königac11a1d2013-11-14 10:49:19 +010024#include <mach/hardware.h>
SAN People73a59c12006-01-09 17:05:41 +000025
Jean-Christophe PLAGNIOL-VILLARD43d2f532012-10-30 05:14:17 +080026#include "board.h"
Andrew Victor2e836402006-06-19 16:31:55 +010027#include "generic.h"
Linus Walleijcf2e9332014-03-27 14:18:51 +010028#include "gpio.h"
Andrew Victor2e836402006-06-19 16:31:55 +010029
SAN People73a59c12006-01-09 17:05:41 +000030
31/* --------------------------------------------------------------------
32 * USB Host
33 * -------------------------------------------------------------------- */
34
35#if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
Andrew Victorc6686ff2008-01-23 09:13:53 +010036static u64 ohci_dmamask = DMA_BIT_MASK(32);
SAN People73a59c12006-01-09 17:05:41 +000037static struct at91_usbh_data usbh_data;
38
Andrew Victor69c5ecc2006-12-01 15:53:20 +010039static struct resource usbh_resources[] = {
SAN People73a59c12006-01-09 17:05:41 +000040 [0] = {
Andrew Victor72729912006-09-27 09:44:11 +010041 .start = AT91RM9200_UHP_BASE,
42 .end = AT91RM9200_UHP_BASE + SZ_1M - 1,
SAN People73a59c12006-01-09 17:05:41 +000043 .flags = IORESOURCE_MEM,
44 },
45 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +020046 .start = NR_IRQS_LEGACY + AT91RM9200_ID_UHP,
47 .end = NR_IRQS_LEGACY + AT91RM9200_ID_UHP,
SAN People73a59c12006-01-09 17:05:41 +000048 .flags = IORESOURCE_IRQ,
49 },
50};
51
52static struct platform_device at91rm9200_usbh_device = {
Andrew Victor2e836402006-06-19 16:31:55 +010053 .name = "at91_ohci",
SAN People73a59c12006-01-09 17:05:41 +000054 .id = -1,
55 .dev = {
56 .dma_mask = &ohci_dmamask,
Andrew Victorc6686ff2008-01-23 09:13:53 +010057 .coherent_dma_mask = DMA_BIT_MASK(32),
SAN People73a59c12006-01-09 17:05:41 +000058 .platform_data = &usbh_data,
59 },
Andrew Victor69c5ecc2006-12-01 15:53:20 +010060 .resource = usbh_resources,
61 .num_resources = ARRAY_SIZE(usbh_resources),
SAN People73a59c12006-01-09 17:05:41 +000062};
63
64void __init at91_add_device_usbh(struct at91_usbh_data *data)
65{
Thomas Petazzoni1fcaea72011-07-13 11:29:18 +020066 int i;
67
SAN People73a59c12006-01-09 17:05:41 +000068 if (!data)
69 return;
70
Thomas Petazzoni1fcaea72011-07-13 11:29:18 +020071 /* Enable overcurrent notification */
72 for (i = 0; i < data->ports; i++) {
Johan Hovold641f3ce2012-11-14 12:18:17 +010073 if (gpio_is_valid(data->overcurrent_pin[i]))
Thomas Petazzoni1fcaea72011-07-13 11:29:18 +020074 at91_set_gpio_input(data->overcurrent_pin[i], 1);
75 }
76
SAN People73a59c12006-01-09 17:05:41 +000077 usbh_data = *data;
78 platform_device_register(&at91rm9200_usbh_device);
79}
80#else
81void __init at91_add_device_usbh(struct at91_usbh_data *data) {}
82#endif
83
84
85/* --------------------------------------------------------------------
86 * USB Device (Gadget)
87 * -------------------------------------------------------------------- */
88
Nicolas Ferree8c9dc92012-01-27 11:14:44 +010089#if defined(CONFIG_USB_AT91) || defined(CONFIG_USB_AT91_MODULE)
SAN People73a59c12006-01-09 17:05:41 +000090static struct at91_udc_data udc_data;
91
Andrew Victor69c5ecc2006-12-01 15:53:20 +010092static struct resource udc_resources[] = {
Andrew Victor2e836402006-06-19 16:31:55 +010093 [0] = {
Andrew Victor72729912006-09-27 09:44:11 +010094 .start = AT91RM9200_BASE_UDP,
95 .end = AT91RM9200_BASE_UDP + SZ_16K - 1,
SAN People73a59c12006-01-09 17:05:41 +000096 .flags = IORESOURCE_MEM,
Andrew Victor2e836402006-06-19 16:31:55 +010097 },
98 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +020099 .start = NR_IRQS_LEGACY + AT91RM9200_ID_UDP,
100 .end = NR_IRQS_LEGACY + AT91RM9200_ID_UDP,
Andrew Victor2e836402006-06-19 16:31:55 +0100101 .flags = IORESOURCE_IRQ,
102 },
SAN People73a59c12006-01-09 17:05:41 +0000103};
104
105static struct platform_device at91rm9200_udc_device = {
106 .name = "at91_udc",
107 .id = -1,
108 .dev = {
109 .platform_data = &udc_data,
110 },
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100111 .resource = udc_resources,
112 .num_resources = ARRAY_SIZE(udc_resources),
SAN People73a59c12006-01-09 17:05:41 +0000113};
114
115void __init at91_add_device_udc(struct at91_udc_data *data)
116{
117 if (!data)
118 return;
119
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +0800120 if (gpio_is_valid(data->vbus_pin)) {
SAN People73a59c12006-01-09 17:05:41 +0000121 at91_set_gpio_input(data->vbus_pin, 0);
122 at91_set_deglitch(data->vbus_pin, 1);
123 }
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +0800124 if (gpio_is_valid(data->pullup_pin))
SAN People73a59c12006-01-09 17:05:41 +0000125 at91_set_gpio_output(data->pullup_pin, 0);
SAN People73a59c12006-01-09 17:05:41 +0000126
127 udc_data = *data;
128 platform_device_register(&at91rm9200_udc_device);
129}
130#else
131void __init at91_add_device_udc(struct at91_udc_data *data) {}
132#endif
133
134
135/* --------------------------------------------------------------------
136 * Ethernet
137 * -------------------------------------------------------------------- */
138
139#if defined(CONFIG_ARM_AT91_ETHER) || defined(CONFIG_ARM_AT91_ETHER_MODULE)
Andrew Victorc6686ff2008-01-23 09:13:53 +0100140static u64 eth_dmamask = DMA_BIT_MASK(32);
Jamie Iles84e0cdb2011-03-08 20:17:06 +0000141static struct macb_platform_data eth_data;
SAN People73a59c12006-01-09 17:05:41 +0000142
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100143static struct resource eth_resources[] = {
Andrew Victor3267c072006-04-02 17:15:51 +0100144 [0] = {
Andrew Victorc5f0f832012-04-26 00:30:42 +0000145 .start = AT91RM9200_BASE_EMAC,
146 .end = AT91RM9200_BASE_EMAC + SZ_16K - 1,
Andrew Victor3267c072006-04-02 17:15:51 +0100147 .flags = IORESOURCE_MEM,
148 },
149 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200150 .start = NR_IRQS_LEGACY + AT91RM9200_ID_EMAC,
151 .end = NR_IRQS_LEGACY + AT91RM9200_ID_EMAC,
Andrew Victor3267c072006-04-02 17:15:51 +0100152 .flags = IORESOURCE_IRQ,
153 },
154};
155
SAN People73a59c12006-01-09 17:05:41 +0000156static struct platform_device at91rm9200_eth_device = {
157 .name = "at91_ether",
158 .id = -1,
159 .dev = {
160 .dma_mask = &eth_dmamask,
Andrew Victorc6686ff2008-01-23 09:13:53 +0100161 .coherent_dma_mask = DMA_BIT_MASK(32),
SAN People73a59c12006-01-09 17:05:41 +0000162 .platform_data = &eth_data,
163 },
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100164 .resource = eth_resources,
165 .num_resources = ARRAY_SIZE(eth_resources),
SAN People73a59c12006-01-09 17:05:41 +0000166};
167
Jamie Iles84e0cdb2011-03-08 20:17:06 +0000168void __init at91_add_device_eth(struct macb_platform_data *data)
SAN People73a59c12006-01-09 17:05:41 +0000169{
170 if (!data)
171 return;
172
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +0800173 if (gpio_is_valid(data->phy_irq_pin)) {
SAN People73a59c12006-01-09 17:05:41 +0000174 at91_set_gpio_input(data->phy_irq_pin, 0);
175 at91_set_deglitch(data->phy_irq_pin, 1);
176 }
177
178 /* Pins used for MII and RMII */
179 at91_set_A_periph(AT91_PIN_PA16, 0); /* EMDIO */
180 at91_set_A_periph(AT91_PIN_PA15, 0); /* EMDC */
181 at91_set_A_periph(AT91_PIN_PA14, 0); /* ERXER */
182 at91_set_A_periph(AT91_PIN_PA13, 0); /* ERX1 */
183 at91_set_A_periph(AT91_PIN_PA12, 0); /* ERX0 */
184 at91_set_A_periph(AT91_PIN_PA11, 0); /* ECRS_ECRSDV */
185 at91_set_A_periph(AT91_PIN_PA10, 0); /* ETX1 */
186 at91_set_A_periph(AT91_PIN_PA9, 0); /* ETX0 */
187 at91_set_A_periph(AT91_PIN_PA8, 0); /* ETXEN */
188 at91_set_A_periph(AT91_PIN_PA7, 0); /* ETXCK_EREFCK */
189
190 if (!data->is_rmii) {
191 at91_set_B_periph(AT91_PIN_PB19, 0); /* ERXCK */
192 at91_set_B_periph(AT91_PIN_PB18, 0); /* ECOL */
193 at91_set_B_periph(AT91_PIN_PB17, 0); /* ERXDV */
194 at91_set_B_periph(AT91_PIN_PB16, 0); /* ERX3 */
195 at91_set_B_periph(AT91_PIN_PB15, 0); /* ERX2 */
196 at91_set_B_periph(AT91_PIN_PB14, 0); /* ETXER */
197 at91_set_B_periph(AT91_PIN_PB13, 0); /* ETX3 */
198 at91_set_B_periph(AT91_PIN_PB12, 0); /* ETX2 */
199 }
200
201 eth_data = *data;
202 platform_device_register(&at91rm9200_eth_device);
203}
204#else
Jamie Iles84e0cdb2011-03-08 20:17:06 +0000205void __init at91_add_device_eth(struct macb_platform_data *data) {}
SAN People73a59c12006-01-09 17:05:41 +0000206#endif
207
208
209/* --------------------------------------------------------------------
210 * Compact Flash / PCMCIA
211 * -------------------------------------------------------------------- */
212
213#if defined(CONFIG_AT91_CF) || defined(CONFIG_AT91_CF_MODULE)
214static struct at91_cf_data cf_data;
215
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100216#define CF_BASE AT91_CHIPSELECT_4
217
218static struct resource cf_resources[] = {
David Brownell2c536202006-04-14 18:05:38 -0700219 [0] = {
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100220 .start = CF_BASE,
Andrew Victor2e836402006-06-19 16:31:55 +0100221 /* ties up CS4, CS5 and CS6 */
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100222 .end = CF_BASE + (0x30000000 - 1),
David Brownell2c536202006-04-14 18:05:38 -0700223 .flags = IORESOURCE_MEM | IORESOURCE_MEM_8AND16BIT,
224 },
225};
226
SAN People73a59c12006-01-09 17:05:41 +0000227static struct platform_device at91rm9200_cf_device = {
228 .name = "at91_cf",
229 .id = -1,
230 .dev = {
231 .platform_data = &cf_data,
232 },
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100233 .resource = cf_resources,
234 .num_resources = ARRAY_SIZE(cf_resources),
SAN People73a59c12006-01-09 17:05:41 +0000235};
236
237void __init at91_add_device_cf(struct at91_cf_data *data)
238{
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100239 unsigned int csa;
240
SAN People73a59c12006-01-09 17:05:41 +0000241 if (!data)
242 return;
243
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100244 data->chipselect = 4; /* can only use EBI ChipSelect 4 */
245
246 /* CF takes over CS4, CS5, CS6 */
Jean-Christophe PLAGNIOL-VILLARDf363c402012-02-13 12:58:53 +0800247 csa = at91_ramc_read(0, AT91_EBI_CSA);
248 at91_ramc_write(0, AT91_EBI_CSA, csa | AT91_EBI_CS4A_SMC_COMPACTFLASH);
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100249
250 /*
251 * Static memory controller timing adjustments.
252 * REVISIT: these timings are in terms of MCK cycles, so
253 * when MCK changes (cpufreq etc) so must these values...
254 */
Jean-Christophe PLAGNIOL-VILLARDf363c402012-02-13 12:58:53 +0800255 at91_ramc_write(0, AT91_SMC_CSR(4),
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100256 AT91_SMC_ACSS_STD
257 | AT91_SMC_DBW_16
258 | AT91_SMC_BAT
259 | AT91_SMC_WSEN
260 | AT91_SMC_NWS_(32) /* wait states */
261 | AT91_SMC_RWSETUP_(6) /* setup time */
262 | AT91_SMC_RWHOLD_(4) /* hold time */
263 );
264
SAN People73a59c12006-01-09 17:05:41 +0000265 /* input/irq */
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +0800266 if (gpio_is_valid(data->irq_pin)) {
SAN People73a59c12006-01-09 17:05:41 +0000267 at91_set_gpio_input(data->irq_pin, 1);
268 at91_set_deglitch(data->irq_pin, 1);
269 }
270 at91_set_gpio_input(data->det_pin, 1);
271 at91_set_deglitch(data->det_pin, 1);
272
273 /* outputs, initially off */
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +0800274 if (gpio_is_valid(data->vcc_pin))
SAN People73a59c12006-01-09 17:05:41 +0000275 at91_set_gpio_output(data->vcc_pin, 0);
276 at91_set_gpio_output(data->rst_pin, 0);
277
Andrew Victor2e836402006-06-19 16:31:55 +0100278 /* force poweron defaults for these pins ... */
279 at91_set_A_periph(AT91_PIN_PC9, 0); /* A25/CFRNW */
280 at91_set_A_periph(AT91_PIN_PC10, 0); /* NCS4/CFCS */
281 at91_set_A_periph(AT91_PIN_PC11, 0); /* NCS5/CFCE1 */
282 at91_set_A_periph(AT91_PIN_PC12, 0); /* NCS6/CFCE2 */
283
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100284 /* nWAIT is _not_ a default setting */
Andrew Victora14d5272007-01-09 09:03:42 +0100285 at91_set_A_periph(AT91_PIN_PC6, 1); /* nWAIT */
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100286
SAN People73a59c12006-01-09 17:05:41 +0000287 cf_data = *data;
288 platform_device_register(&at91rm9200_cf_device);
289}
290#else
291void __init at91_add_device_cf(struct at91_cf_data *data) {}
292#endif
293
294
295/* --------------------------------------------------------------------
296 * MMC / SD
297 * -------------------------------------------------------------------- */
298
Ludovic Desroches4cf33262012-05-21 12:23:27 +0200299#if IS_ENABLED(CONFIG_MMC_ATMELMCI)
Andrew Victorc6686ff2008-01-23 09:13:53 +0100300static u64 mmc_dmamask = DMA_BIT_MASK(32);
Ludovic Desroches4cf33262012-05-21 12:23:27 +0200301static struct mci_platform_data mmc_data;
SAN People73a59c12006-01-09 17:05:41 +0000302
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100303static struct resource mmc_resources[] = {
Andrew Victor3267c072006-04-02 17:15:51 +0100304 [0] = {
Andrew Victor72729912006-09-27 09:44:11 +0100305 .start = AT91RM9200_BASE_MCI,
306 .end = AT91RM9200_BASE_MCI + SZ_16K - 1,
SAN People73a59c12006-01-09 17:05:41 +0000307 .flags = IORESOURCE_MEM,
Andrew Victor3267c072006-04-02 17:15:51 +0100308 },
309 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200310 .start = NR_IRQS_LEGACY + AT91RM9200_ID_MCI,
311 .end = NR_IRQS_LEGACY + AT91RM9200_ID_MCI,
Andrew Victor3267c072006-04-02 17:15:51 +0100312 .flags = IORESOURCE_IRQ,
313 },
SAN People73a59c12006-01-09 17:05:41 +0000314};
315
316static struct platform_device at91rm9200_mmc_device = {
Ludovic Desroches4cf33262012-05-21 12:23:27 +0200317 .name = "atmel_mci",
SAN People73a59c12006-01-09 17:05:41 +0000318 .id = -1,
319 .dev = {
320 .dma_mask = &mmc_dmamask,
Andrew Victorc6686ff2008-01-23 09:13:53 +0100321 .coherent_dma_mask = DMA_BIT_MASK(32),
SAN People73a59c12006-01-09 17:05:41 +0000322 .platform_data = &mmc_data,
323 },
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100324 .resource = mmc_resources,
325 .num_resources = ARRAY_SIZE(mmc_resources),
SAN People73a59c12006-01-09 17:05:41 +0000326};
327
Ludovic Desroches4cf33262012-05-21 12:23:27 +0200328void __init at91_add_device_mci(short mmc_id, struct mci_platform_data *data)
SAN People73a59c12006-01-09 17:05:41 +0000329{
Ludovic Desroches4cf33262012-05-21 12:23:27 +0200330 unsigned int i;
331 unsigned int slot_count = 0;
332
SAN People73a59c12006-01-09 17:05:41 +0000333 if (!data)
334 return;
335
Ludovic Desroches4cf33262012-05-21 12:23:27 +0200336 for (i = 0; i < ATMCI_MAX_NR_SLOTS; i++) {
SAN People73a59c12006-01-09 17:05:41 +0000337
Ludovic Desroches4cf33262012-05-21 12:23:27 +0200338 if (!data->slot[i].bus_width)
339 continue;
SAN People73a59c12006-01-09 17:05:41 +0000340
Ludovic Desroches4cf33262012-05-21 12:23:27 +0200341 /* input/irq */
342 if (gpio_is_valid(data->slot[i].detect_pin)) {
343 at91_set_gpio_input(data->slot[i].detect_pin, 1);
344 at91_set_deglitch(data->slot[i].detect_pin, 1);
SAN People73a59c12006-01-09 17:05:41 +0000345 }
Ludovic Desroches4cf33262012-05-21 12:23:27 +0200346 if (gpio_is_valid(data->slot[i].wp_pin))
347 at91_set_gpio_input(data->slot[i].wp_pin, 1);
SAN People73a59c12006-01-09 17:05:41 +0000348
Ludovic Desroches4cf33262012-05-21 12:23:27 +0200349 switch (i) {
350 case 0: /* slot A */
351 /* CMD */
352 at91_set_A_periph(AT91_PIN_PA28, 1);
353 /* DAT0, maybe DAT1..DAT3 */
354 at91_set_A_periph(AT91_PIN_PA29, 1);
355 if (data->slot[i].bus_width == 4) {
356 at91_set_B_periph(AT91_PIN_PB3, 1);
357 at91_set_B_periph(AT91_PIN_PB4, 1);
358 at91_set_B_periph(AT91_PIN_PB5, 1);
359 }
360 slot_count++;
361 break;
362 case 1: /* slot B */
363 /* CMD */
364 at91_set_B_periph(AT91_PIN_PA8, 1);
365 /* DAT0, maybe DAT1..DAT3 */
366 at91_set_B_periph(AT91_PIN_PA9, 1);
367 if (data->slot[i].bus_width == 4) {
368 at91_set_B_periph(AT91_PIN_PA10, 1);
369 at91_set_B_periph(AT91_PIN_PA11, 1);
370 at91_set_B_periph(AT91_PIN_PA12, 1);
371 }
372 slot_count++;
373 break;
374 default:
375 printk(KERN_ERR
376 "AT91: SD/MMC slot %d not available\n", i);
377 break;
378 }
379 if (slot_count) {
380 /* CLK */
381 at91_set_A_periph(AT91_PIN_PA27, 0);
382
383 mmc_data = *data;
384 platform_device_register(&at91rm9200_mmc_device);
SAN People73a59c12006-01-09 17:05:41 +0000385 }
386 }
387
SAN People73a59c12006-01-09 17:05:41 +0000388}
389#else
Ludovic Desroches4cf33262012-05-21 12:23:27 +0200390void __init at91_add_device_mci(short mmc_id, struct mci_platform_data *data) {}
SAN People73a59c12006-01-09 17:05:41 +0000391#endif
392
Andrew Victor2e836402006-06-19 16:31:55 +0100393
Andrew Victorcc2832a2006-04-02 17:15:48 +0100394/* --------------------------------------------------------------------
Andrew Victor3267c072006-04-02 17:15:51 +0100395 * NAND / SmartMedia
396 * -------------------------------------------------------------------- */
397
Pieter du Preezf6ed6f72008-08-01 10:06:40 +0100398#if defined(CONFIG_MTD_NAND_ATMEL) || defined(CONFIG_MTD_NAND_ATMEL_MODULE)
Håvard Skinnemoen3c3796c2008-06-06 18:04:53 +0200399static struct atmel_nand_data nand_data;
Andrew Victor3267c072006-04-02 17:15:51 +0100400
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100401#define NAND_BASE AT91_CHIPSELECT_3
402
403static struct resource nand_resources[] = {
Andrew Victor3267c072006-04-02 17:15:51 +0100404 {
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100405 .start = NAND_BASE,
Andrew Victor22823552008-01-23 09:21:02 +0100406 .end = NAND_BASE + SZ_256M - 1,
Andrew Victor3267c072006-04-02 17:15:51 +0100407 .flags = IORESOURCE_MEM,
408 }
409};
410
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100411static struct platform_device at91rm9200_nand_device = {
Håvard Skinnemoen3c3796c2008-06-06 18:04:53 +0200412 .name = "atmel_nand",
Andrew Victor3267c072006-04-02 17:15:51 +0100413 .id = -1,
414 .dev = {
415 .platform_data = &nand_data,
416 },
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100417 .resource = nand_resources,
418 .num_resources = ARRAY_SIZE(nand_resources),
Andrew Victor3267c072006-04-02 17:15:51 +0100419};
420
Håvard Skinnemoen3c3796c2008-06-06 18:04:53 +0200421void __init at91_add_device_nand(struct atmel_nand_data *data)
Andrew Victor3267c072006-04-02 17:15:51 +0100422{
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100423 unsigned int csa;
424
Andrew Victor3267c072006-04-02 17:15:51 +0100425 if (!data)
426 return;
427
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100428 /* enable the address range of CS3 */
Jean-Christophe PLAGNIOL-VILLARDf363c402012-02-13 12:58:53 +0800429 csa = at91_ramc_read(0, AT91_EBI_CSA);
430 at91_ramc_write(0, AT91_EBI_CSA, csa | AT91_EBI_CS3A_SMC_SMARTMEDIA);
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100431
432 /* set the bus interface characteristics */
Jean-Christophe PLAGNIOL-VILLARDf363c402012-02-13 12:58:53 +0800433 at91_ramc_write(0, AT91_SMC_CSR(3), AT91_SMC_ACSS_STD | AT91_SMC_DBW_8 | AT91_SMC_WSEN
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100434 | AT91_SMC_NWS_(5)
435 | AT91_SMC_TDF_(1)
436 | AT91_SMC_RWSETUP_(0) /* tDS Data Set up Time 30 - ns */
437 | AT91_SMC_RWHOLD_(1) /* tDH Data Hold Time 20 - ns */
438 );
439
Andrew Victor3267c072006-04-02 17:15:51 +0100440 /* enable pin */
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +0800441 if (gpio_is_valid(data->enable_pin))
Andrew Victor3267c072006-04-02 17:15:51 +0100442 at91_set_gpio_output(data->enable_pin, 1);
443
444 /* ready/busy pin */
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +0800445 if (gpio_is_valid(data->rdy_pin))
Andrew Victor3267c072006-04-02 17:15:51 +0100446 at91_set_gpio_input(data->rdy_pin, 1);
447
448 /* card detect pin */
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +0800449 if (gpio_is_valid(data->det_pin))
Andrew Victor3267c072006-04-02 17:15:51 +0100450 at91_set_gpio_input(data->det_pin, 1);
451
452 at91_set_A_periph(AT91_PIN_PC1, 0); /* SMOE */
453 at91_set_A_periph(AT91_PIN_PC3, 0); /* SMWE */
454
455 nand_data = *data;
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100456 platform_device_register(&at91rm9200_nand_device);
Andrew Victor3267c072006-04-02 17:15:51 +0100457}
458#else
Håvard Skinnemoen3c3796c2008-06-06 18:04:53 +0200459void __init at91_add_device_nand(struct atmel_nand_data *data) {}
Andrew Victor3267c072006-04-02 17:15:51 +0100460#endif
461
462
463/* --------------------------------------------------------------------
464 * TWI (i2c)
465 * -------------------------------------------------------------------- */
466
Andrew Victorf230d3f2007-11-19 13:47:20 +0100467/*
468 * Prefer the GPIO code since the TWI controller isn't robust
469 * (gets overruns and underruns under load) and can only issue
470 * repeated STARTs in one scenario (the driver doesn't yet handle them).
471 */
472#if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
473
474static struct i2c_gpio_platform_data pdata = {
475 .sda_pin = AT91_PIN_PA25,
476 .sda_is_open_drain = 1,
477 .scl_pin = AT91_PIN_PA26,
478 .scl_is_open_drain = 1,
479 .udelay = 2, /* ~100 kHz */
480};
481
482static struct platform_device at91rm9200_twi_device = {
483 .name = "i2c-gpio",
Bo Shen78404872012-10-15 17:30:27 +0800484 .id = 0,
Andrew Victorf230d3f2007-11-19 13:47:20 +0100485 .dev.platform_data = &pdata,
486};
487
488void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
489{
490 at91_set_GPIO_periph(AT91_PIN_PA25, 1); /* TWD (SDA) */
491 at91_set_multi_drive(AT91_PIN_PA25, 1);
492
493 at91_set_GPIO_periph(AT91_PIN_PA26, 1); /* TWCK (SCL) */
494 at91_set_multi_drive(AT91_PIN_PA26, 1);
495
496 i2c_register_board_info(0, devices, nr_devices);
497 platform_device_register(&at91rm9200_twi_device);
498}
499
500#elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100501
502static struct resource twi_resources[] = {
503 [0] = {
504 .start = AT91RM9200_BASE_TWI,
505 .end = AT91RM9200_BASE_TWI + SZ_16K - 1,
506 .flags = IORESOURCE_MEM,
507 },
508 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200509 .start = NR_IRQS_LEGACY + AT91RM9200_ID_TWI,
510 .end = NR_IRQS_LEGACY + AT91RM9200_ID_TWI,
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100511 .flags = IORESOURCE_IRQ,
512 },
513};
514
Andrew Victor3267c072006-04-02 17:15:51 +0100515static struct platform_device at91rm9200_twi_device = {
Nikolaus Vossfac368a2011-11-08 11:49:46 +0100516 .name = "i2c-at91rm9200",
Bo Shen302090a2012-10-15 17:30:28 +0800517 .id = 0,
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100518 .resource = twi_resources,
519 .num_resources = ARRAY_SIZE(twi_resources),
Andrew Victor3267c072006-04-02 17:15:51 +0100520};
521
Andrew Victorf230d3f2007-11-19 13:47:20 +0100522void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
Andrew Victor3267c072006-04-02 17:15:51 +0100523{
524 /* pins used for TWI interface */
525 at91_set_A_periph(AT91_PIN_PA25, 0); /* TWD */
526 at91_set_multi_drive(AT91_PIN_PA25, 1);
527
528 at91_set_A_periph(AT91_PIN_PA26, 0); /* TWCK */
529 at91_set_multi_drive(AT91_PIN_PA26, 1);
530
Andrew Victorf230d3f2007-11-19 13:47:20 +0100531 i2c_register_board_info(0, devices, nr_devices);
Andrew Victor3267c072006-04-02 17:15:51 +0100532 platform_device_register(&at91rm9200_twi_device);
533}
534#else
Andrew Victorf230d3f2007-11-19 13:47:20 +0100535void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {}
Andrew Victor3267c072006-04-02 17:15:51 +0100536#endif
537
538
539/* --------------------------------------------------------------------
Andrew Victor2e836402006-06-19 16:31:55 +0100540 * SPI
541 * -------------------------------------------------------------------- */
542
Andrew Victorc06911c2007-07-16 11:35:40 +0100543#if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
Andrew Victorc6686ff2008-01-23 09:13:53 +0100544static u64 spi_dmamask = DMA_BIT_MASK(32);
Andrew Victor2e836402006-06-19 16:31:55 +0100545
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100546static struct resource spi_resources[] = {
Andrew Victor2e836402006-06-19 16:31:55 +0100547 [0] = {
Andrew Victor72729912006-09-27 09:44:11 +0100548 .start = AT91RM9200_BASE_SPI,
549 .end = AT91RM9200_BASE_SPI + SZ_16K - 1,
Andrew Victor2e836402006-06-19 16:31:55 +0100550 .flags = IORESOURCE_MEM,
551 },
552 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200553 .start = NR_IRQS_LEGACY + AT91RM9200_ID_SPI,
554 .end = NR_IRQS_LEGACY + AT91RM9200_ID_SPI,
Andrew Victor2e836402006-06-19 16:31:55 +0100555 .flags = IORESOURCE_IRQ,
556 },
557};
558
559static struct platform_device at91rm9200_spi_device = {
Andrew Victorc06911c2007-07-16 11:35:40 +0100560 .name = "atmel_spi",
Andrew Victor2e836402006-06-19 16:31:55 +0100561 .id = 0,
562 .dev = {
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100563 .dma_mask = &spi_dmamask,
Andrew Victorc6686ff2008-01-23 09:13:53 +0100564 .coherent_dma_mask = DMA_BIT_MASK(32),
Andrew Victor2e836402006-06-19 16:31:55 +0100565 },
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100566 .resource = spi_resources,
567 .num_resources = ARRAY_SIZE(spi_resources),
Andrew Victor2e836402006-06-19 16:31:55 +0100568};
569
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100570static const unsigned spi_standard_cs[4] = { AT91_PIN_PA3, AT91_PIN_PA4, AT91_PIN_PA5, AT91_PIN_PA6 };
Andrew Victor2e836402006-06-19 16:31:55 +0100571
572void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
573{
574 int i;
575 unsigned long cs_pin;
576
577 at91_set_A_periph(AT91_PIN_PA0, 0); /* MISO */
578 at91_set_A_periph(AT91_PIN_PA1, 0); /* MOSI */
579 at91_set_A_periph(AT91_PIN_PA2, 0); /* SPCK */
580
581 /* Enable SPI chip-selects */
582 for (i = 0; i < nr_devices; i++) {
583 if (devices[i].controller_data)
584 cs_pin = (unsigned long) devices[i].controller_data;
585 else
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100586 cs_pin = spi_standard_cs[devices[i].chip_select];
Andrew Victor2e836402006-06-19 16:31:55 +0100587
Andrew Victor2743f0c2008-01-23 09:29:46 +0100588 if (devices[i].chip_select == 0) /* for CS0 errata */
589 at91_set_A_periph(cs_pin, 0);
590 else
591 at91_set_gpio_output(cs_pin, 1);
592
Andrew Victor2e836402006-06-19 16:31:55 +0100593
594 /* pass chip-select pin to driver */
595 devices[i].controller_data = (void *) cs_pin;
596 }
597
598 spi_register_board_info(devices, nr_devices);
Andrew Victor2e836402006-06-19 16:31:55 +0100599 platform_device_register(&at91rm9200_spi_device);
600}
601#else
602void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
603#endif
604
605
606/* --------------------------------------------------------------------
Andrew Victore5f40bf2008-04-02 21:58:00 +0100607 * Timer/Counter blocks
608 * -------------------------------------------------------------------- */
609
610#ifdef CONFIG_ATMEL_TCLIB
611
612static struct resource tcb0_resources[] = {
613 [0] = {
614 .start = AT91RM9200_BASE_TCB0,
615 .end = AT91RM9200_BASE_TCB0 + SZ_16K - 1,
616 .flags = IORESOURCE_MEM,
617 },
618 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200619 .start = NR_IRQS_LEGACY + AT91RM9200_ID_TC0,
620 .end = NR_IRQS_LEGACY + AT91RM9200_ID_TC0,
Andrew Victore5f40bf2008-04-02 21:58:00 +0100621 .flags = IORESOURCE_IRQ,
622 },
623 [2] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200624 .start = NR_IRQS_LEGACY + AT91RM9200_ID_TC1,
625 .end = NR_IRQS_LEGACY + AT91RM9200_ID_TC1,
Andrew Victore5f40bf2008-04-02 21:58:00 +0100626 .flags = IORESOURCE_IRQ,
627 },
628 [3] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200629 .start = NR_IRQS_LEGACY + AT91RM9200_ID_TC2,
630 .end = NR_IRQS_LEGACY + AT91RM9200_ID_TC2,
Andrew Victore5f40bf2008-04-02 21:58:00 +0100631 .flags = IORESOURCE_IRQ,
632 },
633};
634
635static struct platform_device at91rm9200_tcb0_device = {
636 .name = "atmel_tcb",
637 .id = 0,
638 .resource = tcb0_resources,
639 .num_resources = ARRAY_SIZE(tcb0_resources),
640};
641
642static struct resource tcb1_resources[] = {
643 [0] = {
644 .start = AT91RM9200_BASE_TCB1,
645 .end = AT91RM9200_BASE_TCB1 + SZ_16K - 1,
646 .flags = IORESOURCE_MEM,
647 },
648 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200649 .start = NR_IRQS_LEGACY + AT91RM9200_ID_TC3,
650 .end = NR_IRQS_LEGACY + AT91RM9200_ID_TC3,
Andrew Victore5f40bf2008-04-02 21:58:00 +0100651 .flags = IORESOURCE_IRQ,
652 },
653 [2] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200654 .start = NR_IRQS_LEGACY + AT91RM9200_ID_TC4,
655 .end = NR_IRQS_LEGACY + AT91RM9200_ID_TC4,
Andrew Victore5f40bf2008-04-02 21:58:00 +0100656 .flags = IORESOURCE_IRQ,
657 },
658 [3] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200659 .start = NR_IRQS_LEGACY + AT91RM9200_ID_TC5,
660 .end = NR_IRQS_LEGACY + AT91RM9200_ID_TC5,
Andrew Victore5f40bf2008-04-02 21:58:00 +0100661 .flags = IORESOURCE_IRQ,
662 },
663};
664
665static struct platform_device at91rm9200_tcb1_device = {
666 .name = "atmel_tcb",
667 .id = 1,
668 .resource = tcb1_resources,
669 .num_resources = ARRAY_SIZE(tcb1_resources),
670};
671
672static void __init at91_add_device_tc(void)
673{
Andrew Victore5f40bf2008-04-02 21:58:00 +0100674 platform_device_register(&at91rm9200_tcb0_device);
Andrew Victore5f40bf2008-04-02 21:58:00 +0100675 platform_device_register(&at91rm9200_tcb1_device);
676}
677#else
678static void __init at91_add_device_tc(void) { }
679#endif
680
681
682/* --------------------------------------------------------------------
Andrew Victor3267c072006-04-02 17:15:51 +0100683 * RTC
684 * -------------------------------------------------------------------- */
685
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100686#if defined(CONFIG_RTC_DRV_AT91RM9200) || defined(CONFIG_RTC_DRV_AT91RM9200_MODULE)
Jean-Christophe PLAGNIOL-VILLARDd28bdfc2011-11-14 14:24:53 +0800687static struct resource rtc_resources[] = {
688 [0] = {
689 .start = AT91RM9200_BASE_RTC,
690 .end = AT91RM9200_BASE_RTC + SZ_256 - 1,
691 .flags = IORESOURCE_MEM,
692 },
693 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200694 .start = NR_IRQS_LEGACY + AT91_ID_SYS,
695 .end = NR_IRQS_LEGACY + AT91_ID_SYS,
Jean-Christophe PLAGNIOL-VILLARDd28bdfc2011-11-14 14:24:53 +0800696 .flags = IORESOURCE_IRQ,
697 },
698};
699
Andrew Victor3267c072006-04-02 17:15:51 +0100700static struct platform_device at91rm9200_rtc_device = {
701 .name = "at91_rtc",
702 .id = -1,
Jean-Christophe PLAGNIOL-VILLARDd28bdfc2011-11-14 14:24:53 +0800703 .resource = rtc_resources,
704 .num_resources = ARRAY_SIZE(rtc_resources),
Andrew Victor3267c072006-04-02 17:15:51 +0100705};
706
Andrew Victor2e836402006-06-19 16:31:55 +0100707static void __init at91_add_device_rtc(void)
Andrew Victor3267c072006-04-02 17:15:51 +0100708{
709 platform_device_register(&at91rm9200_rtc_device);
710}
711#else
Andrew Victor2e836402006-06-19 16:31:55 +0100712static void __init at91_add_device_rtc(void) {}
713#endif
714
715
716/* --------------------------------------------------------------------
717 * Watchdog
718 * -------------------------------------------------------------------- */
719
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100720#if defined(CONFIG_AT91RM9200_WATCHDOG) || defined(CONFIG_AT91RM9200_WATCHDOG_MODULE)
Andrew Victor2e836402006-06-19 16:31:55 +0100721static struct platform_device at91rm9200_wdt_device = {
722 .name = "at91_wdt",
723 .id = -1,
724 .num_resources = 0,
725};
726
727static void __init at91_add_device_watchdog(void)
728{
729 platform_device_register(&at91rm9200_wdt_device);
730}
731#else
732static void __init at91_add_device_watchdog(void) {}
Andrew Victor3267c072006-04-02 17:15:51 +0100733#endif
734
735
736/* --------------------------------------------------------------------
Andrew Victorbfbc3262008-01-23 09:18:06 +0100737 * SSC -- Synchronous Serial Controller
738 * -------------------------------------------------------------------- */
739
740#if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
741static u64 ssc0_dmamask = DMA_BIT_MASK(32);
742
743static struct resource ssc0_resources[] = {
744 [0] = {
745 .start = AT91RM9200_BASE_SSC0,
746 .end = AT91RM9200_BASE_SSC0 + SZ_16K - 1,
747 .flags = IORESOURCE_MEM,
748 },
749 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200750 .start = NR_IRQS_LEGACY + AT91RM9200_ID_SSC0,
751 .end = NR_IRQS_LEGACY + AT91RM9200_ID_SSC0,
Andrew Victorbfbc3262008-01-23 09:18:06 +0100752 .flags = IORESOURCE_IRQ,
753 },
754};
755
756static struct platform_device at91rm9200_ssc0_device = {
Bo Shen636036d22012-11-06 13:57:51 +0800757 .name = "at91rm9200_ssc",
Andrew Victorbfbc3262008-01-23 09:18:06 +0100758 .id = 0,
759 .dev = {
760 .dma_mask = &ssc0_dmamask,
761 .coherent_dma_mask = DMA_BIT_MASK(32),
762 },
763 .resource = ssc0_resources,
764 .num_resources = ARRAY_SIZE(ssc0_resources),
765};
766
767static inline void configure_ssc0_pins(unsigned pins)
768{
769 if (pins & ATMEL_SSC_TF)
770 at91_set_A_periph(AT91_PIN_PB0, 1);
771 if (pins & ATMEL_SSC_TK)
772 at91_set_A_periph(AT91_PIN_PB1, 1);
773 if (pins & ATMEL_SSC_TD)
774 at91_set_A_periph(AT91_PIN_PB2, 1);
775 if (pins & ATMEL_SSC_RD)
776 at91_set_A_periph(AT91_PIN_PB3, 1);
777 if (pins & ATMEL_SSC_RK)
778 at91_set_A_periph(AT91_PIN_PB4, 1);
779 if (pins & ATMEL_SSC_RF)
780 at91_set_A_periph(AT91_PIN_PB5, 1);
781}
782
783static u64 ssc1_dmamask = DMA_BIT_MASK(32);
784
785static struct resource ssc1_resources[] = {
786 [0] = {
787 .start = AT91RM9200_BASE_SSC1,
788 .end = AT91RM9200_BASE_SSC1 + SZ_16K - 1,
789 .flags = IORESOURCE_MEM,
790 },
791 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200792 .start = NR_IRQS_LEGACY + AT91RM9200_ID_SSC1,
793 .end = NR_IRQS_LEGACY + AT91RM9200_ID_SSC1,
Andrew Victorbfbc3262008-01-23 09:18:06 +0100794 .flags = IORESOURCE_IRQ,
795 },
796};
797
798static struct platform_device at91rm9200_ssc1_device = {
Bo Shen636036d22012-11-06 13:57:51 +0800799 .name = "at91rm9200_ssc",
Andrew Victorbfbc3262008-01-23 09:18:06 +0100800 .id = 1,
801 .dev = {
802 .dma_mask = &ssc1_dmamask,
803 .coherent_dma_mask = DMA_BIT_MASK(32),
804 },
805 .resource = ssc1_resources,
806 .num_resources = ARRAY_SIZE(ssc1_resources),
807};
808
809static inline void configure_ssc1_pins(unsigned pins)
810{
811 if (pins & ATMEL_SSC_TF)
812 at91_set_A_periph(AT91_PIN_PB6, 1);
813 if (pins & ATMEL_SSC_TK)
814 at91_set_A_periph(AT91_PIN_PB7, 1);
815 if (pins & ATMEL_SSC_TD)
816 at91_set_A_periph(AT91_PIN_PB8, 1);
817 if (pins & ATMEL_SSC_RD)
818 at91_set_A_periph(AT91_PIN_PB9, 1);
819 if (pins & ATMEL_SSC_RK)
820 at91_set_A_periph(AT91_PIN_PB10, 1);
821 if (pins & ATMEL_SSC_RF)
822 at91_set_A_periph(AT91_PIN_PB11, 1);
823}
824
825static u64 ssc2_dmamask = DMA_BIT_MASK(32);
826
827static struct resource ssc2_resources[] = {
828 [0] = {
829 .start = AT91RM9200_BASE_SSC2,
830 .end = AT91RM9200_BASE_SSC2 + SZ_16K - 1,
831 .flags = IORESOURCE_MEM,
832 },
833 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200834 .start = NR_IRQS_LEGACY + AT91RM9200_ID_SSC2,
835 .end = NR_IRQS_LEGACY + AT91RM9200_ID_SSC2,
Andrew Victorbfbc3262008-01-23 09:18:06 +0100836 .flags = IORESOURCE_IRQ,
837 },
838};
839
840static struct platform_device at91rm9200_ssc2_device = {
Bo Shen636036d22012-11-06 13:57:51 +0800841 .name = "at91rm9200_ssc",
Andrew Victorbfbc3262008-01-23 09:18:06 +0100842 .id = 2,
843 .dev = {
844 .dma_mask = &ssc2_dmamask,
845 .coherent_dma_mask = DMA_BIT_MASK(32),
846 },
847 .resource = ssc2_resources,
848 .num_resources = ARRAY_SIZE(ssc2_resources),
849};
850
851static inline void configure_ssc2_pins(unsigned pins)
852{
853 if (pins & ATMEL_SSC_TF)
854 at91_set_A_periph(AT91_PIN_PB12, 1);
855 if (pins & ATMEL_SSC_TK)
856 at91_set_A_periph(AT91_PIN_PB13, 1);
857 if (pins & ATMEL_SSC_TD)
858 at91_set_A_periph(AT91_PIN_PB14, 1);
859 if (pins & ATMEL_SSC_RD)
860 at91_set_A_periph(AT91_PIN_PB15, 1);
861 if (pins & ATMEL_SSC_RK)
862 at91_set_A_periph(AT91_PIN_PB16, 1);
863 if (pins & ATMEL_SSC_RF)
864 at91_set_A_periph(AT91_PIN_PB17, 1);
865}
866
867/*
868 * SSC controllers are accessed through library code, instead of any
869 * kind of all-singing/all-dancing driver. For example one could be
870 * used by a particular I2S audio codec's driver, while another one
871 * on the same system might be used by a custom data capture driver.
872 */
873void __init at91_add_device_ssc(unsigned id, unsigned pins)
874{
875 struct platform_device *pdev;
876
877 /*
878 * NOTE: caller is responsible for passing information matching
879 * "pins" to whatever will be using each particular controller.
880 */
881 switch (id) {
882 case AT91RM9200_ID_SSC0:
883 pdev = &at91rm9200_ssc0_device;
884 configure_ssc0_pins(pins);
Andrew Victorbfbc3262008-01-23 09:18:06 +0100885 break;
886 case AT91RM9200_ID_SSC1:
887 pdev = &at91rm9200_ssc1_device;
888 configure_ssc1_pins(pins);
Andrew Victorbfbc3262008-01-23 09:18:06 +0100889 break;
890 case AT91RM9200_ID_SSC2:
891 pdev = &at91rm9200_ssc2_device;
892 configure_ssc2_pins(pins);
Andrew Victorbfbc3262008-01-23 09:18:06 +0100893 break;
894 default:
895 return;
896 }
897
898 platform_device_register(pdev);
899}
900
901#else
902void __init at91_add_device_ssc(unsigned id, unsigned pins) {}
903#endif
904
905
906/* --------------------------------------------------------------------
Andrew Victor2e836402006-06-19 16:31:55 +0100907 * UART
908 * -------------------------------------------------------------------- */
909
Haavard Skinnemoen749c4e62006-10-04 16:02:02 +0200910#if defined(CONFIG_SERIAL_ATMEL)
Andrew Victor2e836402006-06-19 16:31:55 +0100911static struct resource dbgu_resources[] = {
912 [0] = {
Jean-Christophe PLAGNIOL-VILLARD13079a72011-11-02 01:43:31 +0800913 .start = AT91RM9200_BASE_DBGU,
914 .end = AT91RM9200_BASE_DBGU + SZ_512 - 1,
Andrew Victor2e836402006-06-19 16:31:55 +0100915 .flags = IORESOURCE_MEM,
916 },
917 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200918 .start = NR_IRQS_LEGACY + AT91_ID_SYS,
919 .end = NR_IRQS_LEGACY + AT91_ID_SYS,
Andrew Victor2e836402006-06-19 16:31:55 +0100920 .flags = IORESOURCE_IRQ,
921 },
922};
923
Haavard Skinnemoen73e27982006-10-04 16:02:04 +0200924static struct atmel_uart_data dbgu_data = {
Andrew Victor2e836402006-06-19 16:31:55 +0100925 .use_dma_tx = 0,
926 .use_dma_rx = 0, /* DBGU not capable of receive DMA */
Linus Walleij354e57f2013-11-07 10:25:55 +0100927 .rts_gpio = -EINVAL,
Andrew Victor2e836402006-06-19 16:31:55 +0100928};
929
Andrew Victorc6686ff2008-01-23 09:13:53 +0100930static u64 dbgu_dmamask = DMA_BIT_MASK(32);
931
Andrew Victor2e836402006-06-19 16:31:55 +0100932static struct platform_device at91rm9200_dbgu_device = {
Haavard Skinnemoen1e8ea802006-10-04 16:02:03 +0200933 .name = "atmel_usart",
Andrew Victor2e836402006-06-19 16:31:55 +0100934 .id = 0,
935 .dev = {
Andrew Victorc6686ff2008-01-23 09:13:53 +0100936 .dma_mask = &dbgu_dmamask,
937 .coherent_dma_mask = DMA_BIT_MASK(32),
938 .platform_data = &dbgu_data,
Andrew Victor2e836402006-06-19 16:31:55 +0100939 },
940 .resource = dbgu_resources,
941 .num_resources = ARRAY_SIZE(dbgu_resources),
942};
943
944static inline void configure_dbgu_pins(void)
945{
946 at91_set_A_periph(AT91_PIN_PA30, 0); /* DRXD */
947 at91_set_A_periph(AT91_PIN_PA31, 1); /* DTXD */
948}
949
950static struct resource uart0_resources[] = {
951 [0] = {
Andrew Victor72729912006-09-27 09:44:11 +0100952 .start = AT91RM9200_BASE_US0,
953 .end = AT91RM9200_BASE_US0 + SZ_16K - 1,
Andrew Victor2e836402006-06-19 16:31:55 +0100954 .flags = IORESOURCE_MEM,
955 },
956 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200957 .start = NR_IRQS_LEGACY + AT91RM9200_ID_US0,
958 .end = NR_IRQS_LEGACY + AT91RM9200_ID_US0,
Andrew Victor2e836402006-06-19 16:31:55 +0100959 .flags = IORESOURCE_IRQ,
960 },
961};
962
Haavard Skinnemoen73e27982006-10-04 16:02:04 +0200963static struct atmel_uart_data uart0_data = {
Andrew Victor2e836402006-06-19 16:31:55 +0100964 .use_dma_tx = 1,
965 .use_dma_rx = 1,
Linus Walleij354e57f2013-11-07 10:25:55 +0100966 .rts_gpio = -EINVAL,
Andrew Victor2e836402006-06-19 16:31:55 +0100967};
968
Andrew Victorc6686ff2008-01-23 09:13:53 +0100969static u64 uart0_dmamask = DMA_BIT_MASK(32);
970
Andrew Victor2e836402006-06-19 16:31:55 +0100971static struct platform_device at91rm9200_uart0_device = {
Haavard Skinnemoen1e8ea802006-10-04 16:02:03 +0200972 .name = "atmel_usart",
Andrew Victor2e836402006-06-19 16:31:55 +0100973 .id = 1,
974 .dev = {
Andrew Victorc6686ff2008-01-23 09:13:53 +0100975 .dma_mask = &uart0_dmamask,
976 .coherent_dma_mask = DMA_BIT_MASK(32),
977 .platform_data = &uart0_data,
Andrew Victor2e836402006-06-19 16:31:55 +0100978 },
979 .resource = uart0_resources,
980 .num_resources = ARRAY_SIZE(uart0_resources),
981};
982
Andrew Victorc8f385a2008-01-23 09:25:15 +0100983static inline void configure_usart0_pins(unsigned pins)
Andrew Victor2e836402006-06-19 16:31:55 +0100984{
985 at91_set_A_periph(AT91_PIN_PA17, 1); /* TXD0 */
986 at91_set_A_periph(AT91_PIN_PA18, 0); /* RXD0 */
Andrew Victor2e836402006-06-19 16:31:55 +0100987
Andrew Victorc8f385a2008-01-23 09:25:15 +0100988 if (pins & ATMEL_UART_CTS)
989 at91_set_A_periph(AT91_PIN_PA20, 0); /* CTS0 */
990
991 if (pins & ATMEL_UART_RTS) {
992 /*
993 * AT91RM9200 Errata #39 - RTS0 is not internally connected to PA21.
Linus Walleij354e57f2013-11-07 10:25:55 +0100994 * We need to drive the pin manually. The serial driver will driver
995 * this to high when initializing.
Andrew Victorc8f385a2008-01-23 09:25:15 +0100996 */
Linus Walleij354e57f2013-11-07 10:25:55 +0100997 uart0_data.rts_gpio = AT91_PIN_PA21;
Andrew Victorc8f385a2008-01-23 09:25:15 +0100998 }
Andrew Victor2e836402006-06-19 16:31:55 +0100999}
1000
1001static struct resource uart1_resources[] = {
1002 [0] = {
Andrew Victor72729912006-09-27 09:44:11 +01001003 .start = AT91RM9200_BASE_US1,
1004 .end = AT91RM9200_BASE_US1 + SZ_16K - 1,
Andrew Victor2e836402006-06-19 16:31:55 +01001005 .flags = IORESOURCE_MEM,
1006 },
1007 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +02001008 .start = NR_IRQS_LEGACY + AT91RM9200_ID_US1,
1009 .end = NR_IRQS_LEGACY + AT91RM9200_ID_US1,
Andrew Victor2e836402006-06-19 16:31:55 +01001010 .flags = IORESOURCE_IRQ,
1011 },
1012};
1013
Haavard Skinnemoen73e27982006-10-04 16:02:04 +02001014static struct atmel_uart_data uart1_data = {
Andrew Victor2e836402006-06-19 16:31:55 +01001015 .use_dma_tx = 1,
1016 .use_dma_rx = 1,
Linus Walleij354e57f2013-11-07 10:25:55 +01001017 .rts_gpio = -EINVAL,
Andrew Victor2e836402006-06-19 16:31:55 +01001018};
1019
Andrew Victorc6686ff2008-01-23 09:13:53 +01001020static u64 uart1_dmamask = DMA_BIT_MASK(32);
1021
Andrew Victor2e836402006-06-19 16:31:55 +01001022static struct platform_device at91rm9200_uart1_device = {
Haavard Skinnemoen1e8ea802006-10-04 16:02:03 +02001023 .name = "atmel_usart",
Andrew Victor2e836402006-06-19 16:31:55 +01001024 .id = 2,
1025 .dev = {
Andrew Victorc6686ff2008-01-23 09:13:53 +01001026 .dma_mask = &uart1_dmamask,
1027 .coherent_dma_mask = DMA_BIT_MASK(32),
1028 .platform_data = &uart1_data,
Andrew Victor2e836402006-06-19 16:31:55 +01001029 },
1030 .resource = uart1_resources,
1031 .num_resources = ARRAY_SIZE(uart1_resources),
1032};
1033
Andrew Victorc8f385a2008-01-23 09:25:15 +01001034static inline void configure_usart1_pins(unsigned pins)
Andrew Victor2e836402006-06-19 16:31:55 +01001035{
Andrew Victor2e836402006-06-19 16:31:55 +01001036 at91_set_A_periph(AT91_PIN_PB20, 1); /* TXD1 */
1037 at91_set_A_periph(AT91_PIN_PB21, 0); /* RXD1 */
Andrew Victorc8f385a2008-01-23 09:25:15 +01001038
1039 if (pins & ATMEL_UART_RI)
1040 at91_set_A_periph(AT91_PIN_PB18, 0); /* RI1 */
1041 if (pins & ATMEL_UART_DTR)
1042 at91_set_A_periph(AT91_PIN_PB19, 0); /* DTR1 */
1043 if (pins & ATMEL_UART_DCD)
1044 at91_set_A_periph(AT91_PIN_PB23, 0); /* DCD1 */
1045 if (pins & ATMEL_UART_CTS)
1046 at91_set_A_periph(AT91_PIN_PB24, 0); /* CTS1 */
1047 if (pins & ATMEL_UART_DSR)
1048 at91_set_A_periph(AT91_PIN_PB25, 0); /* DSR1 */
1049 if (pins & ATMEL_UART_RTS)
1050 at91_set_A_periph(AT91_PIN_PB26, 0); /* RTS1 */
Andrew Victor2e836402006-06-19 16:31:55 +01001051}
1052
1053static struct resource uart2_resources[] = {
1054 [0] = {
Andrew Victor72729912006-09-27 09:44:11 +01001055 .start = AT91RM9200_BASE_US2,
1056 .end = AT91RM9200_BASE_US2 + SZ_16K - 1,
Andrew Victor2e836402006-06-19 16:31:55 +01001057 .flags = IORESOURCE_MEM,
1058 },
1059 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +02001060 .start = NR_IRQS_LEGACY + AT91RM9200_ID_US2,
1061 .end = NR_IRQS_LEGACY + AT91RM9200_ID_US2,
Andrew Victor2e836402006-06-19 16:31:55 +01001062 .flags = IORESOURCE_IRQ,
1063 },
1064};
1065
Haavard Skinnemoen73e27982006-10-04 16:02:04 +02001066static struct atmel_uart_data uart2_data = {
Andrew Victor2e836402006-06-19 16:31:55 +01001067 .use_dma_tx = 1,
1068 .use_dma_rx = 1,
Linus Walleij354e57f2013-11-07 10:25:55 +01001069 .rts_gpio = -EINVAL,
Andrew Victor2e836402006-06-19 16:31:55 +01001070};
1071
Andrew Victorc6686ff2008-01-23 09:13:53 +01001072static u64 uart2_dmamask = DMA_BIT_MASK(32);
1073
Andrew Victor2e836402006-06-19 16:31:55 +01001074static struct platform_device at91rm9200_uart2_device = {
Haavard Skinnemoen1e8ea802006-10-04 16:02:03 +02001075 .name = "atmel_usart",
Andrew Victor2e836402006-06-19 16:31:55 +01001076 .id = 3,
1077 .dev = {
Andrew Victorc6686ff2008-01-23 09:13:53 +01001078 .dma_mask = &uart2_dmamask,
1079 .coherent_dma_mask = DMA_BIT_MASK(32),
1080 .platform_data = &uart2_data,
Andrew Victor2e836402006-06-19 16:31:55 +01001081 },
1082 .resource = uart2_resources,
1083 .num_resources = ARRAY_SIZE(uart2_resources),
1084};
1085
Andrew Victorc8f385a2008-01-23 09:25:15 +01001086static inline void configure_usart2_pins(unsigned pins)
Andrew Victor2e836402006-06-19 16:31:55 +01001087{
1088 at91_set_A_periph(AT91_PIN_PA22, 0); /* RXD2 */
1089 at91_set_A_periph(AT91_PIN_PA23, 1); /* TXD2 */
Andrew Victorc8f385a2008-01-23 09:25:15 +01001090
1091 if (pins & ATMEL_UART_CTS)
1092 at91_set_B_periph(AT91_PIN_PA30, 0); /* CTS2 */
1093 if (pins & ATMEL_UART_RTS)
1094 at91_set_B_periph(AT91_PIN_PA31, 0); /* RTS2 */
Andrew Victor2e836402006-06-19 16:31:55 +01001095}
1096
1097static struct resource uart3_resources[] = {
1098 [0] = {
Andrew Victor72729912006-09-27 09:44:11 +01001099 .start = AT91RM9200_BASE_US3,
1100 .end = AT91RM9200_BASE_US3 + SZ_16K - 1,
Andrew Victor2e836402006-06-19 16:31:55 +01001101 .flags = IORESOURCE_MEM,
1102 },
1103 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +02001104 .start = NR_IRQS_LEGACY + AT91RM9200_ID_US3,
1105 .end = NR_IRQS_LEGACY + AT91RM9200_ID_US3,
Andrew Victor2e836402006-06-19 16:31:55 +01001106 .flags = IORESOURCE_IRQ,
1107 },
1108};
1109
Haavard Skinnemoen73e27982006-10-04 16:02:04 +02001110static struct atmel_uart_data uart3_data = {
Andrew Victor2e836402006-06-19 16:31:55 +01001111 .use_dma_tx = 1,
1112 .use_dma_rx = 1,
Linus Walleij354e57f2013-11-07 10:25:55 +01001113 .rts_gpio = -EINVAL,
Andrew Victor2e836402006-06-19 16:31:55 +01001114};
1115
Andrew Victorc6686ff2008-01-23 09:13:53 +01001116static u64 uart3_dmamask = DMA_BIT_MASK(32);
1117
Andrew Victor2e836402006-06-19 16:31:55 +01001118static struct platform_device at91rm9200_uart3_device = {
Haavard Skinnemoen1e8ea802006-10-04 16:02:03 +02001119 .name = "atmel_usart",
Andrew Victor2e836402006-06-19 16:31:55 +01001120 .id = 4,
1121 .dev = {
Andrew Victorc6686ff2008-01-23 09:13:53 +01001122 .dma_mask = &uart3_dmamask,
1123 .coherent_dma_mask = DMA_BIT_MASK(32),
1124 .platform_data = &uart3_data,
Andrew Victor2e836402006-06-19 16:31:55 +01001125 },
1126 .resource = uart3_resources,
1127 .num_resources = ARRAY_SIZE(uart3_resources),
1128};
1129
Andrew Victorc8f385a2008-01-23 09:25:15 +01001130static inline void configure_usart3_pins(unsigned pins)
Andrew Victor2e836402006-06-19 16:31:55 +01001131{
1132 at91_set_B_periph(AT91_PIN_PA5, 1); /* TXD3 */
1133 at91_set_B_periph(AT91_PIN_PA6, 0); /* RXD3 */
Andrew Victorc8f385a2008-01-23 09:25:15 +01001134
1135 if (pins & ATMEL_UART_CTS)
1136 at91_set_B_periph(AT91_PIN_PB1, 0); /* CTS3 */
1137 if (pins & ATMEL_UART_RTS)
1138 at91_set_B_periph(AT91_PIN_PB0, 0); /* RTS3 */
Andrew Victor2e836402006-06-19 16:31:55 +01001139}
1140
Andrew Victor11aadac2008-04-15 21:16:38 +01001141static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
Andrew Victor2e836402006-06-19 16:31:55 +01001142
Andrew Victorc8f385a2008-01-23 09:25:15 +01001143void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
1144{
1145 struct platform_device *pdev;
Jean-Christophe PLAGNIOL-VILLARD2b348e22011-04-10 14:10:05 +08001146 struct atmel_uart_data *pdata;
Andrew Victorc8f385a2008-01-23 09:25:15 +01001147
1148 switch (id) {
1149 case 0: /* DBGU */
1150 pdev = &at91rm9200_dbgu_device;
1151 configure_dbgu_pins();
Andrew Victorc8f385a2008-01-23 09:25:15 +01001152 break;
1153 case AT91RM9200_ID_US0:
1154 pdev = &at91rm9200_uart0_device;
1155 configure_usart0_pins(pins);
Andrew Victorc8f385a2008-01-23 09:25:15 +01001156 break;
1157 case AT91RM9200_ID_US1:
1158 pdev = &at91rm9200_uart1_device;
1159 configure_usart1_pins(pins);
Andrew Victorc8f385a2008-01-23 09:25:15 +01001160 break;
1161 case AT91RM9200_ID_US2:
1162 pdev = &at91rm9200_uart2_device;
1163 configure_usart2_pins(pins);
Andrew Victorc8f385a2008-01-23 09:25:15 +01001164 break;
1165 case AT91RM9200_ID_US3:
1166 pdev = &at91rm9200_uart3_device;
1167 configure_usart3_pins(pins);
Andrew Victorc8f385a2008-01-23 09:25:15 +01001168 break;
1169 default:
1170 return;
1171 }
Jean-Christophe PLAGNIOL-VILLARD2b348e22011-04-10 14:10:05 +08001172 pdata = pdev->dev.platform_data;
1173 pdata->num = portnr; /* update to mapped ID */
Andrew Victorc8f385a2008-01-23 09:25:15 +01001174
1175 if (portnr < ATMEL_MAX_UART)
1176 at91_uarts[portnr] = pdev;
1177}
1178
Andrew Victor2e836402006-06-19 16:31:55 +01001179void __init at91_add_device_serial(void)
1180{
1181 int i;
1182
Haavard Skinnemoen73e27982006-10-04 16:02:04 +02001183 for (i = 0; i < ATMEL_MAX_UART; i++) {
Andrew Victor2e836402006-06-19 16:31:55 +01001184 if (at91_uarts[i])
1185 platform_device_register(at91_uarts[i]);
1186 }
1187}
1188#else
Andrew Victorc8f385a2008-01-23 09:25:15 +01001189void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
Andrew Victor2e836402006-06-19 16:31:55 +01001190void __init at91_add_device_serial(void) {}
1191#endif
1192
1193
SAN People73a59c12006-01-09 17:05:41 +00001194/* -------------------------------------------------------------------- */
Andrew Victor2e836402006-06-19 16:31:55 +01001195
1196/*
1197 * These devices are always present and don't need any board-specific
1198 * setup.
1199 */
1200static int __init at91_add_standard_devices(void)
1201{
1202 at91_add_device_rtc();
1203 at91_add_device_watchdog();
Andrew Victore5f40bf2008-04-02 21:58:00 +01001204 at91_add_device_tc();
Andrew Victor2e836402006-06-19 16:31:55 +01001205 return 0;
1206}
1207
1208arch_initcall(at91_add_standard_devices);