blob: a601c7c1670e65b46121e2c9de3ea1a8f89b1625 [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>
SAN People73a59c12006-01-09 17:05:41 +000017#include <linux/platform_device.h>
Andrew Victorf230d3f2007-11-19 13:47:20 +010018#include <linux/i2c-gpio.h>
SAN People73a59c12006-01-09 17:05:41 +000019
20#include <asm/arch/board.h>
Andrew Victor2e836402006-06-19 16:31:55 +010021#include <asm/arch/gpio.h>
Andrew Victor69c5ecc2006-12-01 15:53:20 +010022#include <asm/arch/at91rm9200.h>
23#include <asm/arch/at91rm9200_mc.h>
SAN People73a59c12006-01-09 17:05:41 +000024
Andrew Victor2e836402006-06-19 16:31:55 +010025#include "generic.h"
26
SAN People73a59c12006-01-09 17:05:41 +000027
28/* --------------------------------------------------------------------
29 * USB Host
30 * -------------------------------------------------------------------- */
31
32#if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
Andrew Victorc6686ff2008-01-23 09:13:53 +010033static u64 ohci_dmamask = DMA_BIT_MASK(32);
SAN People73a59c12006-01-09 17:05:41 +000034static struct at91_usbh_data usbh_data;
35
Andrew Victor69c5ecc2006-12-01 15:53:20 +010036static struct resource usbh_resources[] = {
SAN People73a59c12006-01-09 17:05:41 +000037 [0] = {
Andrew Victor72729912006-09-27 09:44:11 +010038 .start = AT91RM9200_UHP_BASE,
39 .end = AT91RM9200_UHP_BASE + SZ_1M - 1,
SAN People73a59c12006-01-09 17:05:41 +000040 .flags = IORESOURCE_MEM,
41 },
42 [1] = {
Andrew Victor72729912006-09-27 09:44:11 +010043 .start = AT91RM9200_ID_UHP,
44 .end = AT91RM9200_ID_UHP,
SAN People73a59c12006-01-09 17:05:41 +000045 .flags = IORESOURCE_IRQ,
46 },
47};
48
49static struct platform_device at91rm9200_usbh_device = {
Andrew Victor2e836402006-06-19 16:31:55 +010050 .name = "at91_ohci",
SAN People73a59c12006-01-09 17:05:41 +000051 .id = -1,
52 .dev = {
53 .dma_mask = &ohci_dmamask,
Andrew Victorc6686ff2008-01-23 09:13:53 +010054 .coherent_dma_mask = DMA_BIT_MASK(32),
SAN People73a59c12006-01-09 17:05:41 +000055 .platform_data = &usbh_data,
56 },
Andrew Victor69c5ecc2006-12-01 15:53:20 +010057 .resource = usbh_resources,
58 .num_resources = ARRAY_SIZE(usbh_resources),
SAN People73a59c12006-01-09 17:05:41 +000059};
60
61void __init at91_add_device_usbh(struct at91_usbh_data *data)
62{
63 if (!data)
64 return;
65
66 usbh_data = *data;
67 platform_device_register(&at91rm9200_usbh_device);
68}
69#else
70void __init at91_add_device_usbh(struct at91_usbh_data *data) {}
71#endif
72
73
74/* --------------------------------------------------------------------
75 * USB Device (Gadget)
76 * -------------------------------------------------------------------- */
77
78#ifdef CONFIG_USB_GADGET_AT91
79static struct at91_udc_data udc_data;
80
Andrew Victor69c5ecc2006-12-01 15:53:20 +010081static struct resource udc_resources[] = {
Andrew Victor2e836402006-06-19 16:31:55 +010082 [0] = {
Andrew Victor72729912006-09-27 09:44:11 +010083 .start = AT91RM9200_BASE_UDP,
84 .end = AT91RM9200_BASE_UDP + SZ_16K - 1,
SAN People73a59c12006-01-09 17:05:41 +000085 .flags = IORESOURCE_MEM,
Andrew Victor2e836402006-06-19 16:31:55 +010086 },
87 [1] = {
Andrew Victor72729912006-09-27 09:44:11 +010088 .start = AT91RM9200_ID_UDP,
89 .end = AT91RM9200_ID_UDP,
Andrew Victor2e836402006-06-19 16:31:55 +010090 .flags = IORESOURCE_IRQ,
91 },
SAN People73a59c12006-01-09 17:05:41 +000092};
93
94static struct platform_device at91rm9200_udc_device = {
95 .name = "at91_udc",
96 .id = -1,
97 .dev = {
98 .platform_data = &udc_data,
99 },
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100100 .resource = udc_resources,
101 .num_resources = ARRAY_SIZE(udc_resources),
SAN People73a59c12006-01-09 17:05:41 +0000102};
103
104void __init at91_add_device_udc(struct at91_udc_data *data)
105{
106 if (!data)
107 return;
108
109 if (data->vbus_pin) {
110 at91_set_gpio_input(data->vbus_pin, 0);
111 at91_set_deglitch(data->vbus_pin, 1);
112 }
Andrew Victor2e836402006-06-19 16:31:55 +0100113 if (data->pullup_pin)
SAN People73a59c12006-01-09 17:05:41 +0000114 at91_set_gpio_output(data->pullup_pin, 0);
SAN People73a59c12006-01-09 17:05:41 +0000115
116 udc_data = *data;
117 platform_device_register(&at91rm9200_udc_device);
118}
119#else
120void __init at91_add_device_udc(struct at91_udc_data *data) {}
121#endif
122
123
124/* --------------------------------------------------------------------
125 * Ethernet
126 * -------------------------------------------------------------------- */
127
128#if defined(CONFIG_ARM_AT91_ETHER) || defined(CONFIG_ARM_AT91_ETHER_MODULE)
Andrew Victorc6686ff2008-01-23 09:13:53 +0100129static u64 eth_dmamask = DMA_BIT_MASK(32);
SAN People73a59c12006-01-09 17:05:41 +0000130static struct at91_eth_data eth_data;
131
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100132static struct resource eth_resources[] = {
Andrew Victor3267c072006-04-02 17:15:51 +0100133 [0] = {
Andrew Victor1f51c102006-09-28 16:26:47 +0100134 .start = AT91_VA_BASE_EMAC,
135 .end = AT91_VA_BASE_EMAC + SZ_16K - 1,
Andrew Victor3267c072006-04-02 17:15:51 +0100136 .flags = IORESOURCE_MEM,
137 },
138 [1] = {
Andrew Victor72729912006-09-27 09:44:11 +0100139 .start = AT91RM9200_ID_EMAC,
140 .end = AT91RM9200_ID_EMAC,
Andrew Victor3267c072006-04-02 17:15:51 +0100141 .flags = IORESOURCE_IRQ,
142 },
143};
144
SAN People73a59c12006-01-09 17:05:41 +0000145static struct platform_device at91rm9200_eth_device = {
146 .name = "at91_ether",
147 .id = -1,
148 .dev = {
149 .dma_mask = &eth_dmamask,
Andrew Victorc6686ff2008-01-23 09:13:53 +0100150 .coherent_dma_mask = DMA_BIT_MASK(32),
SAN People73a59c12006-01-09 17:05:41 +0000151 .platform_data = &eth_data,
152 },
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100153 .resource = eth_resources,
154 .num_resources = ARRAY_SIZE(eth_resources),
SAN People73a59c12006-01-09 17:05:41 +0000155};
156
157void __init at91_add_device_eth(struct at91_eth_data *data)
158{
159 if (!data)
160 return;
161
162 if (data->phy_irq_pin) {
163 at91_set_gpio_input(data->phy_irq_pin, 0);
164 at91_set_deglitch(data->phy_irq_pin, 1);
165 }
166
167 /* Pins used for MII and RMII */
168 at91_set_A_periph(AT91_PIN_PA16, 0); /* EMDIO */
169 at91_set_A_periph(AT91_PIN_PA15, 0); /* EMDC */
170 at91_set_A_periph(AT91_PIN_PA14, 0); /* ERXER */
171 at91_set_A_periph(AT91_PIN_PA13, 0); /* ERX1 */
172 at91_set_A_periph(AT91_PIN_PA12, 0); /* ERX0 */
173 at91_set_A_periph(AT91_PIN_PA11, 0); /* ECRS_ECRSDV */
174 at91_set_A_periph(AT91_PIN_PA10, 0); /* ETX1 */
175 at91_set_A_periph(AT91_PIN_PA9, 0); /* ETX0 */
176 at91_set_A_periph(AT91_PIN_PA8, 0); /* ETXEN */
177 at91_set_A_periph(AT91_PIN_PA7, 0); /* ETXCK_EREFCK */
178
179 if (!data->is_rmii) {
180 at91_set_B_periph(AT91_PIN_PB19, 0); /* ERXCK */
181 at91_set_B_periph(AT91_PIN_PB18, 0); /* ECOL */
182 at91_set_B_periph(AT91_PIN_PB17, 0); /* ERXDV */
183 at91_set_B_periph(AT91_PIN_PB16, 0); /* ERX3 */
184 at91_set_B_periph(AT91_PIN_PB15, 0); /* ERX2 */
185 at91_set_B_periph(AT91_PIN_PB14, 0); /* ETXER */
186 at91_set_B_periph(AT91_PIN_PB13, 0); /* ETX3 */
187 at91_set_B_periph(AT91_PIN_PB12, 0); /* ETX2 */
188 }
189
190 eth_data = *data;
191 platform_device_register(&at91rm9200_eth_device);
192}
193#else
194void __init at91_add_device_eth(struct at91_eth_data *data) {}
195#endif
196
197
198/* --------------------------------------------------------------------
199 * Compact Flash / PCMCIA
200 * -------------------------------------------------------------------- */
201
202#if defined(CONFIG_AT91_CF) || defined(CONFIG_AT91_CF_MODULE)
203static struct at91_cf_data cf_data;
204
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100205#define CF_BASE AT91_CHIPSELECT_4
206
207static struct resource cf_resources[] = {
David Brownell2c536202006-04-14 18:05:38 -0700208 [0] = {
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100209 .start = CF_BASE,
Andrew Victor2e836402006-06-19 16:31:55 +0100210 /* ties up CS4, CS5 and CS6 */
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100211 .end = CF_BASE + (0x30000000 - 1),
David Brownell2c536202006-04-14 18:05:38 -0700212 .flags = IORESOURCE_MEM | IORESOURCE_MEM_8AND16BIT,
213 },
214};
215
SAN People73a59c12006-01-09 17:05:41 +0000216static struct platform_device at91rm9200_cf_device = {
217 .name = "at91_cf",
218 .id = -1,
219 .dev = {
220 .platform_data = &cf_data,
221 },
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100222 .resource = cf_resources,
223 .num_resources = ARRAY_SIZE(cf_resources),
SAN People73a59c12006-01-09 17:05:41 +0000224};
225
226void __init at91_add_device_cf(struct at91_cf_data *data)
227{
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100228 unsigned int csa;
229
SAN People73a59c12006-01-09 17:05:41 +0000230 if (!data)
231 return;
232
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100233 data->chipselect = 4; /* can only use EBI ChipSelect 4 */
234
235 /* CF takes over CS4, CS5, CS6 */
236 csa = at91_sys_read(AT91_EBI_CSA);
237 at91_sys_write(AT91_EBI_CSA, csa | AT91_EBI_CS4A_SMC_COMPACTFLASH);
238
239 /*
240 * Static memory controller timing adjustments.
241 * REVISIT: these timings are in terms of MCK cycles, so
242 * when MCK changes (cpufreq etc) so must these values...
243 */
244 at91_sys_write(AT91_SMC_CSR(4),
245 AT91_SMC_ACSS_STD
246 | AT91_SMC_DBW_16
247 | AT91_SMC_BAT
248 | AT91_SMC_WSEN
249 | AT91_SMC_NWS_(32) /* wait states */
250 | AT91_SMC_RWSETUP_(6) /* setup time */
251 | AT91_SMC_RWHOLD_(4) /* hold time */
252 );
253
SAN People73a59c12006-01-09 17:05:41 +0000254 /* input/irq */
255 if (data->irq_pin) {
256 at91_set_gpio_input(data->irq_pin, 1);
257 at91_set_deglitch(data->irq_pin, 1);
258 }
259 at91_set_gpio_input(data->det_pin, 1);
260 at91_set_deglitch(data->det_pin, 1);
261
262 /* outputs, initially off */
263 if (data->vcc_pin)
264 at91_set_gpio_output(data->vcc_pin, 0);
265 at91_set_gpio_output(data->rst_pin, 0);
266
Andrew Victor2e836402006-06-19 16:31:55 +0100267 /* force poweron defaults for these pins ... */
268 at91_set_A_periph(AT91_PIN_PC9, 0); /* A25/CFRNW */
269 at91_set_A_periph(AT91_PIN_PC10, 0); /* NCS4/CFCS */
270 at91_set_A_periph(AT91_PIN_PC11, 0); /* NCS5/CFCE1 */
271 at91_set_A_periph(AT91_PIN_PC12, 0); /* NCS6/CFCE2 */
272
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100273 /* nWAIT is _not_ a default setting */
Andrew Victora14d5272007-01-09 09:03:42 +0100274 at91_set_A_periph(AT91_PIN_PC6, 1); /* nWAIT */
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100275
SAN People73a59c12006-01-09 17:05:41 +0000276 cf_data = *data;
277 platform_device_register(&at91rm9200_cf_device);
278}
279#else
280void __init at91_add_device_cf(struct at91_cf_data *data) {}
281#endif
282
283
284/* --------------------------------------------------------------------
285 * MMC / SD
286 * -------------------------------------------------------------------- */
287
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100288#if defined(CONFIG_MMC_AT91) || defined(CONFIG_MMC_AT91_MODULE)
Andrew Victorc6686ff2008-01-23 09:13:53 +0100289static u64 mmc_dmamask = DMA_BIT_MASK(32);
SAN People73a59c12006-01-09 17:05:41 +0000290static struct at91_mmc_data mmc_data;
291
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100292static struct resource mmc_resources[] = {
Andrew Victor3267c072006-04-02 17:15:51 +0100293 [0] = {
Andrew Victor72729912006-09-27 09:44:11 +0100294 .start = AT91RM9200_BASE_MCI,
295 .end = AT91RM9200_BASE_MCI + SZ_16K - 1,
SAN People73a59c12006-01-09 17:05:41 +0000296 .flags = IORESOURCE_MEM,
Andrew Victor3267c072006-04-02 17:15:51 +0100297 },
298 [1] = {
Andrew Victor72729912006-09-27 09:44:11 +0100299 .start = AT91RM9200_ID_MCI,
300 .end = AT91RM9200_ID_MCI,
Andrew Victor3267c072006-04-02 17:15:51 +0100301 .flags = IORESOURCE_IRQ,
302 },
SAN People73a59c12006-01-09 17:05:41 +0000303};
304
305static struct platform_device at91rm9200_mmc_device = {
Andrew Victor3267c072006-04-02 17:15:51 +0100306 .name = "at91_mci",
SAN People73a59c12006-01-09 17:05:41 +0000307 .id = -1,
308 .dev = {
309 .dma_mask = &mmc_dmamask,
Andrew Victorc6686ff2008-01-23 09:13:53 +0100310 .coherent_dma_mask = DMA_BIT_MASK(32),
SAN People73a59c12006-01-09 17:05:41 +0000311 .platform_data = &mmc_data,
312 },
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100313 .resource = mmc_resources,
314 .num_resources = ARRAY_SIZE(mmc_resources),
SAN People73a59c12006-01-09 17:05:41 +0000315};
316
Andrew Victord0760b32007-02-08 09:00:39 +0100317void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data)
SAN People73a59c12006-01-09 17:05:41 +0000318{
319 if (!data)
320 return;
321
322 /* input/irq */
323 if (data->det_pin) {
324 at91_set_gpio_input(data->det_pin, 1);
325 at91_set_deglitch(data->det_pin, 1);
326 }
327 if (data->wp_pin)
328 at91_set_gpio_input(data->wp_pin, 1);
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100329 if (data->vcc_pin)
330 at91_set_gpio_output(data->vcc_pin, 0);
SAN People73a59c12006-01-09 17:05:41 +0000331
332 /* CLK */
333 at91_set_A_periph(AT91_PIN_PA27, 0);
334
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100335 if (data->slot_b) {
SAN People73a59c12006-01-09 17:05:41 +0000336 /* CMD */
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100337 at91_set_B_periph(AT91_PIN_PA8, 1);
SAN People73a59c12006-01-09 17:05:41 +0000338
339 /* DAT0, maybe DAT1..DAT3 */
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100340 at91_set_B_periph(AT91_PIN_PA9, 1);
SAN People73a59c12006-01-09 17:05:41 +0000341 if (data->wire4) {
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100342 at91_set_B_periph(AT91_PIN_PA10, 1);
343 at91_set_B_periph(AT91_PIN_PA11, 1);
344 at91_set_B_periph(AT91_PIN_PA12, 1);
SAN People73a59c12006-01-09 17:05:41 +0000345 }
346 } else {
347 /* CMD */
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100348 at91_set_A_periph(AT91_PIN_PA28, 1);
SAN People73a59c12006-01-09 17:05:41 +0000349
350 /* DAT0, maybe DAT1..DAT3 */
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100351 at91_set_A_periph(AT91_PIN_PA29, 1);
SAN People73a59c12006-01-09 17:05:41 +0000352 if (data->wire4) {
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100353 at91_set_B_periph(AT91_PIN_PB3, 1);
354 at91_set_B_periph(AT91_PIN_PB4, 1);
355 at91_set_B_periph(AT91_PIN_PB5, 1);
SAN People73a59c12006-01-09 17:05:41 +0000356 }
357 }
358
359 mmc_data = *data;
360 platform_device_register(&at91rm9200_mmc_device);
361}
362#else
Andrew Victord0760b32007-02-08 09:00:39 +0100363void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data) {}
SAN People73a59c12006-01-09 17:05:41 +0000364#endif
365
Andrew Victor2e836402006-06-19 16:31:55 +0100366
Andrew Victorcc2832a2006-04-02 17:15:48 +0100367/* --------------------------------------------------------------------
Andrew Victor3267c072006-04-02 17:15:51 +0100368 * NAND / SmartMedia
369 * -------------------------------------------------------------------- */
370
371#if defined(CONFIG_MTD_NAND_AT91) || defined(CONFIG_MTD_NAND_AT91_MODULE)
372static struct at91_nand_data nand_data;
373
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100374#define NAND_BASE AT91_CHIPSELECT_3
375
376static struct resource nand_resources[] = {
Andrew Victor3267c072006-04-02 17:15:51 +0100377 {
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100378 .start = NAND_BASE,
379 .end = NAND_BASE + SZ_8M - 1,
Andrew Victor3267c072006-04-02 17:15:51 +0100380 .flags = IORESOURCE_MEM,
381 }
382};
383
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100384static struct platform_device at91rm9200_nand_device = {
Andrew Victor3267c072006-04-02 17:15:51 +0100385 .name = "at91_nand",
386 .id = -1,
387 .dev = {
388 .platform_data = &nand_data,
389 },
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100390 .resource = nand_resources,
391 .num_resources = ARRAY_SIZE(nand_resources),
Andrew Victor3267c072006-04-02 17:15:51 +0100392};
393
394void __init at91_add_device_nand(struct at91_nand_data *data)
395{
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100396 unsigned int csa;
397
Andrew Victor3267c072006-04-02 17:15:51 +0100398 if (!data)
399 return;
400
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100401 /* enable the address range of CS3 */
402 csa = at91_sys_read(AT91_EBI_CSA);
403 at91_sys_write(AT91_EBI_CSA, csa | AT91_EBI_CS3A_SMC_SMARTMEDIA);
404
405 /* set the bus interface characteristics */
406 at91_sys_write(AT91_SMC_CSR(3), AT91_SMC_ACSS_STD | AT91_SMC_DBW_8 | AT91_SMC_WSEN
407 | AT91_SMC_NWS_(5)
408 | AT91_SMC_TDF_(1)
409 | AT91_SMC_RWSETUP_(0) /* tDS Data Set up Time 30 - ns */
410 | AT91_SMC_RWHOLD_(1) /* tDH Data Hold Time 20 - ns */
411 );
412
Andrew Victor3267c072006-04-02 17:15:51 +0100413 /* enable pin */
414 if (data->enable_pin)
415 at91_set_gpio_output(data->enable_pin, 1);
416
417 /* ready/busy pin */
418 if (data->rdy_pin)
419 at91_set_gpio_input(data->rdy_pin, 1);
420
421 /* card detect pin */
422 if (data->det_pin)
423 at91_set_gpio_input(data->det_pin, 1);
424
425 at91_set_A_periph(AT91_PIN_PC1, 0); /* SMOE */
426 at91_set_A_periph(AT91_PIN_PC3, 0); /* SMWE */
427
428 nand_data = *data;
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100429 platform_device_register(&at91rm9200_nand_device);
Andrew Victor3267c072006-04-02 17:15:51 +0100430}
431#else
432void __init at91_add_device_nand(struct at91_nand_data *data) {}
433#endif
434
435
436/* --------------------------------------------------------------------
437 * TWI (i2c)
438 * -------------------------------------------------------------------- */
439
Andrew Victorf230d3f2007-11-19 13:47:20 +0100440/*
441 * Prefer the GPIO code since the TWI controller isn't robust
442 * (gets overruns and underruns under load) and can only issue
443 * repeated STARTs in one scenario (the driver doesn't yet handle them).
444 */
445#if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
446
447static struct i2c_gpio_platform_data pdata = {
448 .sda_pin = AT91_PIN_PA25,
449 .sda_is_open_drain = 1,
450 .scl_pin = AT91_PIN_PA26,
451 .scl_is_open_drain = 1,
452 .udelay = 2, /* ~100 kHz */
453};
454
455static struct platform_device at91rm9200_twi_device = {
456 .name = "i2c-gpio",
457 .id = -1,
458 .dev.platform_data = &pdata,
459};
460
461void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
462{
463 at91_set_GPIO_periph(AT91_PIN_PA25, 1); /* TWD (SDA) */
464 at91_set_multi_drive(AT91_PIN_PA25, 1);
465
466 at91_set_GPIO_periph(AT91_PIN_PA26, 1); /* TWCK (SCL) */
467 at91_set_multi_drive(AT91_PIN_PA26, 1);
468
469 i2c_register_board_info(0, devices, nr_devices);
470 platform_device_register(&at91rm9200_twi_device);
471}
472
473#elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100474
475static struct resource twi_resources[] = {
476 [0] = {
477 .start = AT91RM9200_BASE_TWI,
478 .end = AT91RM9200_BASE_TWI + SZ_16K - 1,
479 .flags = IORESOURCE_MEM,
480 },
481 [1] = {
482 .start = AT91RM9200_ID_TWI,
483 .end = AT91RM9200_ID_TWI,
484 .flags = IORESOURCE_IRQ,
485 },
486};
487
Andrew Victor3267c072006-04-02 17:15:51 +0100488static struct platform_device at91rm9200_twi_device = {
489 .name = "at91_i2c",
490 .id = -1,
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100491 .resource = twi_resources,
492 .num_resources = ARRAY_SIZE(twi_resources),
Andrew Victor3267c072006-04-02 17:15:51 +0100493};
494
Andrew Victorf230d3f2007-11-19 13:47:20 +0100495void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
Andrew Victor3267c072006-04-02 17:15:51 +0100496{
497 /* pins used for TWI interface */
498 at91_set_A_periph(AT91_PIN_PA25, 0); /* TWD */
499 at91_set_multi_drive(AT91_PIN_PA25, 1);
500
501 at91_set_A_periph(AT91_PIN_PA26, 0); /* TWCK */
502 at91_set_multi_drive(AT91_PIN_PA26, 1);
503
Andrew Victorf230d3f2007-11-19 13:47:20 +0100504 i2c_register_board_info(0, devices, nr_devices);
Andrew Victor3267c072006-04-02 17:15:51 +0100505 platform_device_register(&at91rm9200_twi_device);
506}
507#else
Andrew Victorf230d3f2007-11-19 13:47:20 +0100508void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {}
Andrew Victor3267c072006-04-02 17:15:51 +0100509#endif
510
511
512/* --------------------------------------------------------------------
Andrew Victor2e836402006-06-19 16:31:55 +0100513 * SPI
514 * -------------------------------------------------------------------- */
515
Andrew Victorc06911c2007-07-16 11:35:40 +0100516#if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
Andrew Victorc6686ff2008-01-23 09:13:53 +0100517static u64 spi_dmamask = DMA_BIT_MASK(32);
Andrew Victor2e836402006-06-19 16:31:55 +0100518
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100519static struct resource spi_resources[] = {
Andrew Victor2e836402006-06-19 16:31:55 +0100520 [0] = {
Andrew Victor72729912006-09-27 09:44:11 +0100521 .start = AT91RM9200_BASE_SPI,
522 .end = AT91RM9200_BASE_SPI + SZ_16K - 1,
Andrew Victor2e836402006-06-19 16:31:55 +0100523 .flags = IORESOURCE_MEM,
524 },
525 [1] = {
Andrew Victor72729912006-09-27 09:44:11 +0100526 .start = AT91RM9200_ID_SPI,
527 .end = AT91RM9200_ID_SPI,
Andrew Victor2e836402006-06-19 16:31:55 +0100528 .flags = IORESOURCE_IRQ,
529 },
530};
531
532static struct platform_device at91rm9200_spi_device = {
Andrew Victorc06911c2007-07-16 11:35:40 +0100533 .name = "atmel_spi",
Andrew Victor2e836402006-06-19 16:31:55 +0100534 .id = 0,
535 .dev = {
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100536 .dma_mask = &spi_dmamask,
Andrew Victorc6686ff2008-01-23 09:13:53 +0100537 .coherent_dma_mask = DMA_BIT_MASK(32),
Andrew Victor2e836402006-06-19 16:31:55 +0100538 },
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100539 .resource = spi_resources,
540 .num_resources = ARRAY_SIZE(spi_resources),
Andrew Victor2e836402006-06-19 16:31:55 +0100541};
542
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100543static 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 +0100544
545void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
546{
547 int i;
548 unsigned long cs_pin;
549
550 at91_set_A_periph(AT91_PIN_PA0, 0); /* MISO */
551 at91_set_A_periph(AT91_PIN_PA1, 0); /* MOSI */
552 at91_set_A_periph(AT91_PIN_PA2, 0); /* SPCK */
553
554 /* Enable SPI chip-selects */
555 for (i = 0; i < nr_devices; i++) {
556 if (devices[i].controller_data)
557 cs_pin = (unsigned long) devices[i].controller_data;
558 else
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100559 cs_pin = spi_standard_cs[devices[i].chip_select];
Andrew Victor2e836402006-06-19 16:31:55 +0100560
Andrew Victorc06911c2007-07-16 11:35:40 +0100561 /* enable chip-select pin */
Andrew Victor2e836402006-06-19 16:31:55 +0100562 at91_set_gpio_output(cs_pin, 1);
Andrew Victor2e836402006-06-19 16:31:55 +0100563
564 /* pass chip-select pin to driver */
565 devices[i].controller_data = (void *) cs_pin;
566 }
567
568 spi_register_board_info(devices, nr_devices);
Andrew Victor2e836402006-06-19 16:31:55 +0100569 platform_device_register(&at91rm9200_spi_device);
570}
571#else
572void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
573#endif
574
575
576/* --------------------------------------------------------------------
Andrew Victor3267c072006-04-02 17:15:51 +0100577 * RTC
578 * -------------------------------------------------------------------- */
579
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100580#if defined(CONFIG_RTC_DRV_AT91RM9200) || defined(CONFIG_RTC_DRV_AT91RM9200_MODULE)
Andrew Victor3267c072006-04-02 17:15:51 +0100581static struct platform_device at91rm9200_rtc_device = {
582 .name = "at91_rtc",
583 .id = -1,
584 .num_resources = 0,
585};
586
Andrew Victor2e836402006-06-19 16:31:55 +0100587static void __init at91_add_device_rtc(void)
Andrew Victor3267c072006-04-02 17:15:51 +0100588{
589 platform_device_register(&at91rm9200_rtc_device);
590}
591#else
Andrew Victor2e836402006-06-19 16:31:55 +0100592static void __init at91_add_device_rtc(void) {}
593#endif
594
595
596/* --------------------------------------------------------------------
597 * Watchdog
598 * -------------------------------------------------------------------- */
599
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100600#if defined(CONFIG_AT91RM9200_WATCHDOG) || defined(CONFIG_AT91RM9200_WATCHDOG_MODULE)
Andrew Victor2e836402006-06-19 16:31:55 +0100601static struct platform_device at91rm9200_wdt_device = {
602 .name = "at91_wdt",
603 .id = -1,
604 .num_resources = 0,
605};
606
607static void __init at91_add_device_watchdog(void)
608{
609 platform_device_register(&at91rm9200_wdt_device);
610}
611#else
612static void __init at91_add_device_watchdog(void) {}
Andrew Victor3267c072006-04-02 17:15:51 +0100613#endif
614
615
616/* --------------------------------------------------------------------
Andrew Victorcc2832a2006-04-02 17:15:48 +0100617 * LEDs
618 * -------------------------------------------------------------------- */
619
620#if defined(CONFIG_LEDS)
621u8 at91_leds_cpu;
622u8 at91_leds_timer;
623
624void __init at91_init_leds(u8 cpu_led, u8 timer_led)
625{
Andrew Victorda11d022007-02-08 11:18:14 +0100626 /* Enable GPIO to access the LEDs */
627 at91_set_gpio_output(cpu_led, 1);
628 at91_set_gpio_output(timer_led, 1);
629
Andrew Victor2e836402006-06-19 16:31:55 +0100630 at91_leds_cpu = cpu_led;
631 at91_leds_timer = timer_led;
Andrew Victorcc2832a2006-04-02 17:15:48 +0100632}
Andrew Victorcc2832a2006-04-02 17:15:48 +0100633#else
634void __init at91_init_leds(u8 cpu_led, u8 timer_led) {}
635#endif
636
637
Andrew Victor2e836402006-06-19 16:31:55 +0100638/* --------------------------------------------------------------------
639 * UART
640 * -------------------------------------------------------------------- */
641
Haavard Skinnemoen749c4e62006-10-04 16:02:02 +0200642#if defined(CONFIG_SERIAL_ATMEL)
Andrew Victor2e836402006-06-19 16:31:55 +0100643static struct resource dbgu_resources[] = {
644 [0] = {
645 .start = AT91_VA_BASE_SYS + AT91_DBGU,
646 .end = AT91_VA_BASE_SYS + AT91_DBGU + SZ_512 - 1,
647 .flags = IORESOURCE_MEM,
648 },
649 [1] = {
650 .start = AT91_ID_SYS,
651 .end = AT91_ID_SYS,
652 .flags = IORESOURCE_IRQ,
653 },
654};
655
Haavard Skinnemoen73e27982006-10-04 16:02:04 +0200656static struct atmel_uart_data dbgu_data = {
Andrew Victor2e836402006-06-19 16:31:55 +0100657 .use_dma_tx = 0,
658 .use_dma_rx = 0, /* DBGU not capable of receive DMA */
Haavard Skinnemoen75d35212006-10-04 16:02:08 +0200659 .regs = (void __iomem *)(AT91_VA_BASE_SYS + AT91_DBGU),
Andrew Victor2e836402006-06-19 16:31:55 +0100660};
661
Andrew Victorc6686ff2008-01-23 09:13:53 +0100662static u64 dbgu_dmamask = DMA_BIT_MASK(32);
663
Andrew Victor2e836402006-06-19 16:31:55 +0100664static struct platform_device at91rm9200_dbgu_device = {
Haavard Skinnemoen1e8ea802006-10-04 16:02:03 +0200665 .name = "atmel_usart",
Andrew Victor2e836402006-06-19 16:31:55 +0100666 .id = 0,
667 .dev = {
Andrew Victorc6686ff2008-01-23 09:13:53 +0100668 .dma_mask = &dbgu_dmamask,
669 .coherent_dma_mask = DMA_BIT_MASK(32),
670 .platform_data = &dbgu_data,
Andrew Victor2e836402006-06-19 16:31:55 +0100671 },
672 .resource = dbgu_resources,
673 .num_resources = ARRAY_SIZE(dbgu_resources),
674};
675
676static inline void configure_dbgu_pins(void)
677{
678 at91_set_A_periph(AT91_PIN_PA30, 0); /* DRXD */
679 at91_set_A_periph(AT91_PIN_PA31, 1); /* DTXD */
680}
681
682static struct resource uart0_resources[] = {
683 [0] = {
Andrew Victor72729912006-09-27 09:44:11 +0100684 .start = AT91RM9200_BASE_US0,
685 .end = AT91RM9200_BASE_US0 + SZ_16K - 1,
Andrew Victor2e836402006-06-19 16:31:55 +0100686 .flags = IORESOURCE_MEM,
687 },
688 [1] = {
Andrew Victor72729912006-09-27 09:44:11 +0100689 .start = AT91RM9200_ID_US0,
690 .end = AT91RM9200_ID_US0,
Andrew Victor2e836402006-06-19 16:31:55 +0100691 .flags = IORESOURCE_IRQ,
692 },
693};
694
Haavard Skinnemoen73e27982006-10-04 16:02:04 +0200695static struct atmel_uart_data uart0_data = {
Andrew Victor2e836402006-06-19 16:31:55 +0100696 .use_dma_tx = 1,
697 .use_dma_rx = 1,
698};
699
Andrew Victorc6686ff2008-01-23 09:13:53 +0100700static u64 uart0_dmamask = DMA_BIT_MASK(32);
701
Andrew Victor2e836402006-06-19 16:31:55 +0100702static struct platform_device at91rm9200_uart0_device = {
Haavard Skinnemoen1e8ea802006-10-04 16:02:03 +0200703 .name = "atmel_usart",
Andrew Victor2e836402006-06-19 16:31:55 +0100704 .id = 1,
705 .dev = {
Andrew Victorc6686ff2008-01-23 09:13:53 +0100706 .dma_mask = &uart0_dmamask,
707 .coherent_dma_mask = DMA_BIT_MASK(32),
708 .platform_data = &uart0_data,
Andrew Victor2e836402006-06-19 16:31:55 +0100709 },
710 .resource = uart0_resources,
711 .num_resources = ARRAY_SIZE(uart0_resources),
712};
713
714static inline void configure_usart0_pins(void)
715{
716 at91_set_A_periph(AT91_PIN_PA17, 1); /* TXD0 */
717 at91_set_A_periph(AT91_PIN_PA18, 0); /* RXD0 */
718 at91_set_A_periph(AT91_PIN_PA20, 0); /* CTS0 */
719
720 /*
721 * AT91RM9200 Errata #39 - RTS0 is not internally connected to PA21.
722 * We need to drive the pin manually. Default is off (RTS is active low).
723 */
724 at91_set_gpio_output(AT91_PIN_PA21, 1);
725}
726
727static struct resource uart1_resources[] = {
728 [0] = {
Andrew Victor72729912006-09-27 09:44:11 +0100729 .start = AT91RM9200_BASE_US1,
730 .end = AT91RM9200_BASE_US1 + SZ_16K - 1,
Andrew Victor2e836402006-06-19 16:31:55 +0100731 .flags = IORESOURCE_MEM,
732 },
733 [1] = {
Andrew Victor72729912006-09-27 09:44:11 +0100734 .start = AT91RM9200_ID_US1,
735 .end = AT91RM9200_ID_US1,
Andrew Victor2e836402006-06-19 16:31:55 +0100736 .flags = IORESOURCE_IRQ,
737 },
738};
739
Haavard Skinnemoen73e27982006-10-04 16:02:04 +0200740static struct atmel_uart_data uart1_data = {
Andrew Victor2e836402006-06-19 16:31:55 +0100741 .use_dma_tx = 1,
742 .use_dma_rx = 1,
743};
744
Andrew Victorc6686ff2008-01-23 09:13:53 +0100745static u64 uart1_dmamask = DMA_BIT_MASK(32);
746
Andrew Victor2e836402006-06-19 16:31:55 +0100747static struct platform_device at91rm9200_uart1_device = {
Haavard Skinnemoen1e8ea802006-10-04 16:02:03 +0200748 .name = "atmel_usart",
Andrew Victor2e836402006-06-19 16:31:55 +0100749 .id = 2,
750 .dev = {
Andrew Victorc6686ff2008-01-23 09:13:53 +0100751 .dma_mask = &uart1_dmamask,
752 .coherent_dma_mask = DMA_BIT_MASK(32),
753 .platform_data = &uart1_data,
Andrew Victor2e836402006-06-19 16:31:55 +0100754 },
755 .resource = uart1_resources,
756 .num_resources = ARRAY_SIZE(uart1_resources),
757};
758
759static inline void configure_usart1_pins(void)
760{
761 at91_set_A_periph(AT91_PIN_PB18, 0); /* RI1 */
762 at91_set_A_periph(AT91_PIN_PB19, 0); /* DTR1 */
763 at91_set_A_periph(AT91_PIN_PB20, 1); /* TXD1 */
764 at91_set_A_periph(AT91_PIN_PB21, 0); /* RXD1 */
765 at91_set_A_periph(AT91_PIN_PB23, 0); /* DCD1 */
766 at91_set_A_periph(AT91_PIN_PB24, 0); /* CTS1 */
767 at91_set_A_periph(AT91_PIN_PB25, 0); /* DSR1 */
768 at91_set_A_periph(AT91_PIN_PB26, 0); /* RTS1 */
769}
770
771static struct resource uart2_resources[] = {
772 [0] = {
Andrew Victor72729912006-09-27 09:44:11 +0100773 .start = AT91RM9200_BASE_US2,
774 .end = AT91RM9200_BASE_US2 + SZ_16K - 1,
Andrew Victor2e836402006-06-19 16:31:55 +0100775 .flags = IORESOURCE_MEM,
776 },
777 [1] = {
Andrew Victor72729912006-09-27 09:44:11 +0100778 .start = AT91RM9200_ID_US2,
779 .end = AT91RM9200_ID_US2,
Andrew Victor2e836402006-06-19 16:31:55 +0100780 .flags = IORESOURCE_IRQ,
781 },
782};
783
Haavard Skinnemoen73e27982006-10-04 16:02:04 +0200784static struct atmel_uart_data uart2_data = {
Andrew Victor2e836402006-06-19 16:31:55 +0100785 .use_dma_tx = 1,
786 .use_dma_rx = 1,
787};
788
Andrew Victorc6686ff2008-01-23 09:13:53 +0100789static u64 uart2_dmamask = DMA_BIT_MASK(32);
790
Andrew Victor2e836402006-06-19 16:31:55 +0100791static struct platform_device at91rm9200_uart2_device = {
Haavard Skinnemoen1e8ea802006-10-04 16:02:03 +0200792 .name = "atmel_usart",
Andrew Victor2e836402006-06-19 16:31:55 +0100793 .id = 3,
794 .dev = {
Andrew Victorc6686ff2008-01-23 09:13:53 +0100795 .dma_mask = &uart2_dmamask,
796 .coherent_dma_mask = DMA_BIT_MASK(32),
797 .platform_data = &uart2_data,
Andrew Victor2e836402006-06-19 16:31:55 +0100798 },
799 .resource = uart2_resources,
800 .num_resources = ARRAY_SIZE(uart2_resources),
801};
802
803static inline void configure_usart2_pins(void)
804{
805 at91_set_A_periph(AT91_PIN_PA22, 0); /* RXD2 */
806 at91_set_A_periph(AT91_PIN_PA23, 1); /* TXD2 */
807}
808
809static struct resource uart3_resources[] = {
810 [0] = {
Andrew Victor72729912006-09-27 09:44:11 +0100811 .start = AT91RM9200_BASE_US3,
812 .end = AT91RM9200_BASE_US3 + SZ_16K - 1,
Andrew Victor2e836402006-06-19 16:31:55 +0100813 .flags = IORESOURCE_MEM,
814 },
815 [1] = {
Andrew Victor72729912006-09-27 09:44:11 +0100816 .start = AT91RM9200_ID_US3,
817 .end = AT91RM9200_ID_US3,
Andrew Victor2e836402006-06-19 16:31:55 +0100818 .flags = IORESOURCE_IRQ,
819 },
820};
821
Haavard Skinnemoen73e27982006-10-04 16:02:04 +0200822static struct atmel_uart_data uart3_data = {
Andrew Victor2e836402006-06-19 16:31:55 +0100823 .use_dma_tx = 1,
824 .use_dma_rx = 1,
825};
826
Andrew Victorc6686ff2008-01-23 09:13:53 +0100827static u64 uart3_dmamask = DMA_BIT_MASK(32);
828
Andrew Victor2e836402006-06-19 16:31:55 +0100829static struct platform_device at91rm9200_uart3_device = {
Haavard Skinnemoen1e8ea802006-10-04 16:02:03 +0200830 .name = "atmel_usart",
Andrew Victor2e836402006-06-19 16:31:55 +0100831 .id = 4,
832 .dev = {
Andrew Victorc6686ff2008-01-23 09:13:53 +0100833 .dma_mask = &uart3_dmamask,
834 .coherent_dma_mask = DMA_BIT_MASK(32),
835 .platform_data = &uart3_data,
Andrew Victor2e836402006-06-19 16:31:55 +0100836 },
837 .resource = uart3_resources,
838 .num_resources = ARRAY_SIZE(uart3_resources),
839};
840
841static inline void configure_usart3_pins(void)
842{
843 at91_set_B_periph(AT91_PIN_PA5, 1); /* TXD3 */
844 at91_set_B_periph(AT91_PIN_PA6, 0); /* RXD3 */
845}
846
Andrew Victorc6686ff2008-01-23 09:13:53 +0100847static struct platform_device *at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
Haavard Skinnemoen73e27982006-10-04 16:02:04 +0200848struct platform_device *atmel_default_console_device; /* the serial console device */
Andrew Victor2e836402006-06-19 16:31:55 +0100849
850void __init at91_init_serial(struct at91_uart_config *config)
851{
852 int i;
853
854 /* Fill in list of supported UARTs */
855 for (i = 0; i < config->nr_tty; i++) {
856 switch (config->tty_map[i]) {
857 case 0:
858 configure_usart0_pins();
859 at91_uarts[i] = &at91rm9200_uart0_device;
860 at91_clock_associate("usart0_clk", &at91rm9200_uart0_device.dev, "usart");
861 break;
862 case 1:
863 configure_usart1_pins();
864 at91_uarts[i] = &at91rm9200_uart1_device;
865 at91_clock_associate("usart1_clk", &at91rm9200_uart1_device.dev, "usart");
866 break;
867 case 2:
868 configure_usart2_pins();
869 at91_uarts[i] = &at91rm9200_uart2_device;
870 at91_clock_associate("usart2_clk", &at91rm9200_uart2_device.dev, "usart");
871 break;
872 case 3:
873 configure_usart3_pins();
874 at91_uarts[i] = &at91rm9200_uart3_device;
875 at91_clock_associate("usart3_clk", &at91rm9200_uart3_device.dev, "usart");
876 break;
877 case 4:
878 configure_dbgu_pins();
879 at91_uarts[i] = &at91rm9200_dbgu_device;
880 at91_clock_associate("mck", &at91rm9200_dbgu_device.dev, "usart");
881 break;
882 default:
883 continue;
884 }
885 at91_uarts[i]->id = i; /* update ID number to mapped ID */
886 }
887
888 /* Set serial console device */
Haavard Skinnemoen73e27982006-10-04 16:02:04 +0200889 if (config->console_tty < ATMEL_MAX_UART)
890 atmel_default_console_device = at91_uarts[config->console_tty];
891 if (!atmel_default_console_device)
Andrew Victor2e836402006-06-19 16:31:55 +0100892 printk(KERN_INFO "AT91: No default serial console defined.\n");
893}
894
895void __init at91_add_device_serial(void)
896{
897 int i;
898
Haavard Skinnemoen73e27982006-10-04 16:02:04 +0200899 for (i = 0; i < ATMEL_MAX_UART; i++) {
Andrew Victor2e836402006-06-19 16:31:55 +0100900 if (at91_uarts[i])
901 platform_device_register(at91_uarts[i]);
902 }
903}
904#else
905void __init at91_init_serial(struct at91_uart_config *config) {}
906void __init at91_add_device_serial(void) {}
907#endif
908
909
SAN People73a59c12006-01-09 17:05:41 +0000910/* -------------------------------------------------------------------- */
Andrew Victor2e836402006-06-19 16:31:55 +0100911
912/*
913 * These devices are always present and don't need any board-specific
914 * setup.
915 */
916static int __init at91_add_standard_devices(void)
917{
918 at91_add_device_rtc();
919 at91_add_device_watchdog();
920 return 0;
921}
922
923arch_initcall(at91_add_standard_devices);