blob: 9296833f91ccd576c7c5dbbacffbf94cb7a28518 [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
SAN People73a59c12006-01-09 17:05:41 +000016#include <linux/platform_device.h>
Andrew Victorf230d3f2007-11-19 13:47:20 +010017#include <linux/i2c-gpio.h>
SAN People73a59c12006-01-09 17:05:41 +000018
19#include <asm/arch/board.h>
Andrew Victor2e836402006-06-19 16:31:55 +010020#include <asm/arch/gpio.h>
Andrew Victor69c5ecc2006-12-01 15:53:20 +010021#include <asm/arch/at91rm9200.h>
22#include <asm/arch/at91rm9200_mc.h>
SAN People73a59c12006-01-09 17:05:41 +000023
Andrew Victor2e836402006-06-19 16:31:55 +010024#include "generic.h"
25
SAN People73a59c12006-01-09 17:05:41 +000026
27/* --------------------------------------------------------------------
28 * USB Host
29 * -------------------------------------------------------------------- */
30
31#if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
32static u64 ohci_dmamask = 0xffffffffUL;
33static struct at91_usbh_data usbh_data;
34
Andrew Victor69c5ecc2006-12-01 15:53:20 +010035static struct resource usbh_resources[] = {
SAN People73a59c12006-01-09 17:05:41 +000036 [0] = {
Andrew Victor72729912006-09-27 09:44:11 +010037 .start = AT91RM9200_UHP_BASE,
38 .end = AT91RM9200_UHP_BASE + SZ_1M - 1,
SAN People73a59c12006-01-09 17:05:41 +000039 .flags = IORESOURCE_MEM,
40 },
41 [1] = {
Andrew Victor72729912006-09-27 09:44:11 +010042 .start = AT91RM9200_ID_UHP,
43 .end = AT91RM9200_ID_UHP,
SAN People73a59c12006-01-09 17:05:41 +000044 .flags = IORESOURCE_IRQ,
45 },
46};
47
48static struct platform_device at91rm9200_usbh_device = {
Andrew Victor2e836402006-06-19 16:31:55 +010049 .name = "at91_ohci",
SAN People73a59c12006-01-09 17:05:41 +000050 .id = -1,
51 .dev = {
52 .dma_mask = &ohci_dmamask,
53 .coherent_dma_mask = 0xffffffff,
54 .platform_data = &usbh_data,
55 },
Andrew Victor69c5ecc2006-12-01 15:53:20 +010056 .resource = usbh_resources,
57 .num_resources = ARRAY_SIZE(usbh_resources),
SAN People73a59c12006-01-09 17:05:41 +000058};
59
60void __init at91_add_device_usbh(struct at91_usbh_data *data)
61{
62 if (!data)
63 return;
64
65 usbh_data = *data;
66 platform_device_register(&at91rm9200_usbh_device);
67}
68#else
69void __init at91_add_device_usbh(struct at91_usbh_data *data) {}
70#endif
71
72
73/* --------------------------------------------------------------------
74 * USB Device (Gadget)
75 * -------------------------------------------------------------------- */
76
77#ifdef CONFIG_USB_GADGET_AT91
78static struct at91_udc_data udc_data;
79
Andrew Victor69c5ecc2006-12-01 15:53:20 +010080static struct resource udc_resources[] = {
Andrew Victor2e836402006-06-19 16:31:55 +010081 [0] = {
Andrew Victor72729912006-09-27 09:44:11 +010082 .start = AT91RM9200_BASE_UDP,
83 .end = AT91RM9200_BASE_UDP + SZ_16K - 1,
SAN People73a59c12006-01-09 17:05:41 +000084 .flags = IORESOURCE_MEM,
Andrew Victor2e836402006-06-19 16:31:55 +010085 },
86 [1] = {
Andrew Victor72729912006-09-27 09:44:11 +010087 .start = AT91RM9200_ID_UDP,
88 .end = AT91RM9200_ID_UDP,
Andrew Victor2e836402006-06-19 16:31:55 +010089 .flags = IORESOURCE_IRQ,
90 },
SAN People73a59c12006-01-09 17:05:41 +000091};
92
93static struct platform_device at91rm9200_udc_device = {
94 .name = "at91_udc",
95 .id = -1,
96 .dev = {
97 .platform_data = &udc_data,
98 },
Andrew Victor69c5ecc2006-12-01 15:53:20 +010099 .resource = udc_resources,
100 .num_resources = ARRAY_SIZE(udc_resources),
SAN People73a59c12006-01-09 17:05:41 +0000101};
102
103void __init at91_add_device_udc(struct at91_udc_data *data)
104{
105 if (!data)
106 return;
107
108 if (data->vbus_pin) {
109 at91_set_gpio_input(data->vbus_pin, 0);
110 at91_set_deglitch(data->vbus_pin, 1);
111 }
Andrew Victor2e836402006-06-19 16:31:55 +0100112 if (data->pullup_pin)
SAN People73a59c12006-01-09 17:05:41 +0000113 at91_set_gpio_output(data->pullup_pin, 0);
SAN People73a59c12006-01-09 17:05:41 +0000114
115 udc_data = *data;
116 platform_device_register(&at91rm9200_udc_device);
117}
118#else
119void __init at91_add_device_udc(struct at91_udc_data *data) {}
120#endif
121
122
123/* --------------------------------------------------------------------
124 * Ethernet
125 * -------------------------------------------------------------------- */
126
127#if defined(CONFIG_ARM_AT91_ETHER) || defined(CONFIG_ARM_AT91_ETHER_MODULE)
128static u64 eth_dmamask = 0xffffffffUL;
129static struct at91_eth_data eth_data;
130
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100131static struct resource eth_resources[] = {
Andrew Victor3267c072006-04-02 17:15:51 +0100132 [0] = {
Andrew Victor1f51c102006-09-28 16:26:47 +0100133 .start = AT91_VA_BASE_EMAC,
134 .end = AT91_VA_BASE_EMAC + SZ_16K - 1,
Andrew Victor3267c072006-04-02 17:15:51 +0100135 .flags = IORESOURCE_MEM,
136 },
137 [1] = {
Andrew Victor72729912006-09-27 09:44:11 +0100138 .start = AT91RM9200_ID_EMAC,
139 .end = AT91RM9200_ID_EMAC,
Andrew Victor3267c072006-04-02 17:15:51 +0100140 .flags = IORESOURCE_IRQ,
141 },
142};
143
SAN People73a59c12006-01-09 17:05:41 +0000144static struct platform_device at91rm9200_eth_device = {
145 .name = "at91_ether",
146 .id = -1,
147 .dev = {
148 .dma_mask = &eth_dmamask,
149 .coherent_dma_mask = 0xffffffff,
150 .platform_data = &eth_data,
151 },
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100152 .resource = eth_resources,
153 .num_resources = ARRAY_SIZE(eth_resources),
SAN People73a59c12006-01-09 17:05:41 +0000154};
155
156void __init at91_add_device_eth(struct at91_eth_data *data)
157{
158 if (!data)
159 return;
160
161 if (data->phy_irq_pin) {
162 at91_set_gpio_input(data->phy_irq_pin, 0);
163 at91_set_deglitch(data->phy_irq_pin, 1);
164 }
165
166 /* Pins used for MII and RMII */
167 at91_set_A_periph(AT91_PIN_PA16, 0); /* EMDIO */
168 at91_set_A_periph(AT91_PIN_PA15, 0); /* EMDC */
169 at91_set_A_periph(AT91_PIN_PA14, 0); /* ERXER */
170 at91_set_A_periph(AT91_PIN_PA13, 0); /* ERX1 */
171 at91_set_A_periph(AT91_PIN_PA12, 0); /* ERX0 */
172 at91_set_A_periph(AT91_PIN_PA11, 0); /* ECRS_ECRSDV */
173 at91_set_A_periph(AT91_PIN_PA10, 0); /* ETX1 */
174 at91_set_A_periph(AT91_PIN_PA9, 0); /* ETX0 */
175 at91_set_A_periph(AT91_PIN_PA8, 0); /* ETXEN */
176 at91_set_A_periph(AT91_PIN_PA7, 0); /* ETXCK_EREFCK */
177
178 if (!data->is_rmii) {
179 at91_set_B_periph(AT91_PIN_PB19, 0); /* ERXCK */
180 at91_set_B_periph(AT91_PIN_PB18, 0); /* ECOL */
181 at91_set_B_periph(AT91_PIN_PB17, 0); /* ERXDV */
182 at91_set_B_periph(AT91_PIN_PB16, 0); /* ERX3 */
183 at91_set_B_periph(AT91_PIN_PB15, 0); /* ERX2 */
184 at91_set_B_periph(AT91_PIN_PB14, 0); /* ETXER */
185 at91_set_B_periph(AT91_PIN_PB13, 0); /* ETX3 */
186 at91_set_B_periph(AT91_PIN_PB12, 0); /* ETX2 */
187 }
188
189 eth_data = *data;
190 platform_device_register(&at91rm9200_eth_device);
191}
192#else
193void __init at91_add_device_eth(struct at91_eth_data *data) {}
194#endif
195
196
197/* --------------------------------------------------------------------
198 * Compact Flash / PCMCIA
199 * -------------------------------------------------------------------- */
200
201#if defined(CONFIG_AT91_CF) || defined(CONFIG_AT91_CF_MODULE)
202static struct at91_cf_data cf_data;
203
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100204#define CF_BASE AT91_CHIPSELECT_4
205
206static struct resource cf_resources[] = {
David Brownell2c536202006-04-14 18:05:38 -0700207 [0] = {
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100208 .start = CF_BASE,
Andrew Victor2e836402006-06-19 16:31:55 +0100209 /* ties up CS4, CS5 and CS6 */
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100210 .end = CF_BASE + (0x30000000 - 1),
David Brownell2c536202006-04-14 18:05:38 -0700211 .flags = IORESOURCE_MEM | IORESOURCE_MEM_8AND16BIT,
212 },
213};
214
SAN People73a59c12006-01-09 17:05:41 +0000215static struct platform_device at91rm9200_cf_device = {
216 .name = "at91_cf",
217 .id = -1,
218 .dev = {
219 .platform_data = &cf_data,
220 },
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100221 .resource = cf_resources,
222 .num_resources = ARRAY_SIZE(cf_resources),
SAN People73a59c12006-01-09 17:05:41 +0000223};
224
225void __init at91_add_device_cf(struct at91_cf_data *data)
226{
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100227 unsigned int csa;
228
SAN People73a59c12006-01-09 17:05:41 +0000229 if (!data)
230 return;
231
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100232 data->chipselect = 4; /* can only use EBI ChipSelect 4 */
233
234 /* CF takes over CS4, CS5, CS6 */
235 csa = at91_sys_read(AT91_EBI_CSA);
236 at91_sys_write(AT91_EBI_CSA, csa | AT91_EBI_CS4A_SMC_COMPACTFLASH);
237
238 /*
239 * Static memory controller timing adjustments.
240 * REVISIT: these timings are in terms of MCK cycles, so
241 * when MCK changes (cpufreq etc) so must these values...
242 */
243 at91_sys_write(AT91_SMC_CSR(4),
244 AT91_SMC_ACSS_STD
245 | AT91_SMC_DBW_16
246 | AT91_SMC_BAT
247 | AT91_SMC_WSEN
248 | AT91_SMC_NWS_(32) /* wait states */
249 | AT91_SMC_RWSETUP_(6) /* setup time */
250 | AT91_SMC_RWHOLD_(4) /* hold time */
251 );
252
SAN People73a59c12006-01-09 17:05:41 +0000253 /* input/irq */
254 if (data->irq_pin) {
255 at91_set_gpio_input(data->irq_pin, 1);
256 at91_set_deglitch(data->irq_pin, 1);
257 }
258 at91_set_gpio_input(data->det_pin, 1);
259 at91_set_deglitch(data->det_pin, 1);
260
261 /* outputs, initially off */
262 if (data->vcc_pin)
263 at91_set_gpio_output(data->vcc_pin, 0);
264 at91_set_gpio_output(data->rst_pin, 0);
265
Andrew Victor2e836402006-06-19 16:31:55 +0100266 /* force poweron defaults for these pins ... */
267 at91_set_A_periph(AT91_PIN_PC9, 0); /* A25/CFRNW */
268 at91_set_A_periph(AT91_PIN_PC10, 0); /* NCS4/CFCS */
269 at91_set_A_periph(AT91_PIN_PC11, 0); /* NCS5/CFCE1 */
270 at91_set_A_periph(AT91_PIN_PC12, 0); /* NCS6/CFCE2 */
271
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100272 /* nWAIT is _not_ a default setting */
Andrew Victora14d5272007-01-09 09:03:42 +0100273 at91_set_A_periph(AT91_PIN_PC6, 1); /* nWAIT */
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100274
SAN People73a59c12006-01-09 17:05:41 +0000275 cf_data = *data;
276 platform_device_register(&at91rm9200_cf_device);
277}
278#else
279void __init at91_add_device_cf(struct at91_cf_data *data) {}
280#endif
281
282
283/* --------------------------------------------------------------------
284 * MMC / SD
285 * -------------------------------------------------------------------- */
286
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100287#if defined(CONFIG_MMC_AT91) || defined(CONFIG_MMC_AT91_MODULE)
SAN People73a59c12006-01-09 17:05:41 +0000288static u64 mmc_dmamask = 0xffffffffUL;
289static struct at91_mmc_data mmc_data;
290
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100291static struct resource mmc_resources[] = {
Andrew Victor3267c072006-04-02 17:15:51 +0100292 [0] = {
Andrew Victor72729912006-09-27 09:44:11 +0100293 .start = AT91RM9200_BASE_MCI,
294 .end = AT91RM9200_BASE_MCI + SZ_16K - 1,
SAN People73a59c12006-01-09 17:05:41 +0000295 .flags = IORESOURCE_MEM,
Andrew Victor3267c072006-04-02 17:15:51 +0100296 },
297 [1] = {
Andrew Victor72729912006-09-27 09:44:11 +0100298 .start = AT91RM9200_ID_MCI,
299 .end = AT91RM9200_ID_MCI,
Andrew Victor3267c072006-04-02 17:15:51 +0100300 .flags = IORESOURCE_IRQ,
301 },
SAN People73a59c12006-01-09 17:05:41 +0000302};
303
304static struct platform_device at91rm9200_mmc_device = {
Andrew Victor3267c072006-04-02 17:15:51 +0100305 .name = "at91_mci",
SAN People73a59c12006-01-09 17:05:41 +0000306 .id = -1,
307 .dev = {
308 .dma_mask = &mmc_dmamask,
309 .coherent_dma_mask = 0xffffffff,
310 .platform_data = &mmc_data,
311 },
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100312 .resource = mmc_resources,
313 .num_resources = ARRAY_SIZE(mmc_resources),
SAN People73a59c12006-01-09 17:05:41 +0000314};
315
Andrew Victord0760b32007-02-08 09:00:39 +0100316void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data)
SAN People73a59c12006-01-09 17:05:41 +0000317{
318 if (!data)
319 return;
320
321 /* input/irq */
322 if (data->det_pin) {
323 at91_set_gpio_input(data->det_pin, 1);
324 at91_set_deglitch(data->det_pin, 1);
325 }
326 if (data->wp_pin)
327 at91_set_gpio_input(data->wp_pin, 1);
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100328 if (data->vcc_pin)
329 at91_set_gpio_output(data->vcc_pin, 0);
SAN People73a59c12006-01-09 17:05:41 +0000330
331 /* CLK */
332 at91_set_A_periph(AT91_PIN_PA27, 0);
333
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100334 if (data->slot_b) {
SAN People73a59c12006-01-09 17:05:41 +0000335 /* CMD */
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100336 at91_set_B_periph(AT91_PIN_PA8, 1);
SAN People73a59c12006-01-09 17:05:41 +0000337
338 /* DAT0, maybe DAT1..DAT3 */
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100339 at91_set_B_periph(AT91_PIN_PA9, 1);
SAN People73a59c12006-01-09 17:05:41 +0000340 if (data->wire4) {
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100341 at91_set_B_periph(AT91_PIN_PA10, 1);
342 at91_set_B_periph(AT91_PIN_PA11, 1);
343 at91_set_B_periph(AT91_PIN_PA12, 1);
SAN People73a59c12006-01-09 17:05:41 +0000344 }
345 } else {
346 /* CMD */
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100347 at91_set_A_periph(AT91_PIN_PA28, 1);
SAN People73a59c12006-01-09 17:05:41 +0000348
349 /* DAT0, maybe DAT1..DAT3 */
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100350 at91_set_A_periph(AT91_PIN_PA29, 1);
SAN People73a59c12006-01-09 17:05:41 +0000351 if (data->wire4) {
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100352 at91_set_B_periph(AT91_PIN_PB3, 1);
353 at91_set_B_periph(AT91_PIN_PB4, 1);
354 at91_set_B_periph(AT91_PIN_PB5, 1);
SAN People73a59c12006-01-09 17:05:41 +0000355 }
356 }
357
358 mmc_data = *data;
359 platform_device_register(&at91rm9200_mmc_device);
360}
361#else
Andrew Victord0760b32007-02-08 09:00:39 +0100362void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data) {}
SAN People73a59c12006-01-09 17:05:41 +0000363#endif
364
Andrew Victor2e836402006-06-19 16:31:55 +0100365
Andrew Victorcc2832a2006-04-02 17:15:48 +0100366/* --------------------------------------------------------------------
Andrew Victor3267c072006-04-02 17:15:51 +0100367 * NAND / SmartMedia
368 * -------------------------------------------------------------------- */
369
370#if defined(CONFIG_MTD_NAND_AT91) || defined(CONFIG_MTD_NAND_AT91_MODULE)
371static struct at91_nand_data nand_data;
372
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100373#define NAND_BASE AT91_CHIPSELECT_3
374
375static struct resource nand_resources[] = {
Andrew Victor3267c072006-04-02 17:15:51 +0100376 {
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100377 .start = NAND_BASE,
378 .end = NAND_BASE + SZ_8M - 1,
Andrew Victor3267c072006-04-02 17:15:51 +0100379 .flags = IORESOURCE_MEM,
380 }
381};
382
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100383static struct platform_device at91rm9200_nand_device = {
Andrew Victor3267c072006-04-02 17:15:51 +0100384 .name = "at91_nand",
385 .id = -1,
386 .dev = {
387 .platform_data = &nand_data,
388 },
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100389 .resource = nand_resources,
390 .num_resources = ARRAY_SIZE(nand_resources),
Andrew Victor3267c072006-04-02 17:15:51 +0100391};
392
393void __init at91_add_device_nand(struct at91_nand_data *data)
394{
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100395 unsigned int csa;
396
Andrew Victor3267c072006-04-02 17:15:51 +0100397 if (!data)
398 return;
399
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100400 /* enable the address range of CS3 */
401 csa = at91_sys_read(AT91_EBI_CSA);
402 at91_sys_write(AT91_EBI_CSA, csa | AT91_EBI_CS3A_SMC_SMARTMEDIA);
403
404 /* set the bus interface characteristics */
405 at91_sys_write(AT91_SMC_CSR(3), AT91_SMC_ACSS_STD | AT91_SMC_DBW_8 | AT91_SMC_WSEN
406 | AT91_SMC_NWS_(5)
407 | AT91_SMC_TDF_(1)
408 | AT91_SMC_RWSETUP_(0) /* tDS Data Set up Time 30 - ns */
409 | AT91_SMC_RWHOLD_(1) /* tDH Data Hold Time 20 - ns */
410 );
411
Andrew Victor3267c072006-04-02 17:15:51 +0100412 /* enable pin */
413 if (data->enable_pin)
414 at91_set_gpio_output(data->enable_pin, 1);
415
416 /* ready/busy pin */
417 if (data->rdy_pin)
418 at91_set_gpio_input(data->rdy_pin, 1);
419
420 /* card detect pin */
421 if (data->det_pin)
422 at91_set_gpio_input(data->det_pin, 1);
423
424 at91_set_A_periph(AT91_PIN_PC1, 0); /* SMOE */
425 at91_set_A_periph(AT91_PIN_PC3, 0); /* SMWE */
426
427 nand_data = *data;
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100428 platform_device_register(&at91rm9200_nand_device);
Andrew Victor3267c072006-04-02 17:15:51 +0100429}
430#else
431void __init at91_add_device_nand(struct at91_nand_data *data) {}
432#endif
433
434
435/* --------------------------------------------------------------------
436 * TWI (i2c)
437 * -------------------------------------------------------------------- */
438
Andrew Victorf230d3f2007-11-19 13:47:20 +0100439/*
440 * Prefer the GPIO code since the TWI controller isn't robust
441 * (gets overruns and underruns under load) and can only issue
442 * repeated STARTs in one scenario (the driver doesn't yet handle them).
443 */
444#if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
445
446static struct i2c_gpio_platform_data pdata = {
447 .sda_pin = AT91_PIN_PA25,
448 .sda_is_open_drain = 1,
449 .scl_pin = AT91_PIN_PA26,
450 .scl_is_open_drain = 1,
451 .udelay = 2, /* ~100 kHz */
452};
453
454static struct platform_device at91rm9200_twi_device = {
455 .name = "i2c-gpio",
456 .id = -1,
457 .dev.platform_data = &pdata,
458};
459
460void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
461{
462 at91_set_GPIO_periph(AT91_PIN_PA25, 1); /* TWD (SDA) */
463 at91_set_multi_drive(AT91_PIN_PA25, 1);
464
465 at91_set_GPIO_periph(AT91_PIN_PA26, 1); /* TWCK (SCL) */
466 at91_set_multi_drive(AT91_PIN_PA26, 1);
467
468 i2c_register_board_info(0, devices, nr_devices);
469 platform_device_register(&at91rm9200_twi_device);
470}
471
472#elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100473
474static struct resource twi_resources[] = {
475 [0] = {
476 .start = AT91RM9200_BASE_TWI,
477 .end = AT91RM9200_BASE_TWI + SZ_16K - 1,
478 .flags = IORESOURCE_MEM,
479 },
480 [1] = {
481 .start = AT91RM9200_ID_TWI,
482 .end = AT91RM9200_ID_TWI,
483 .flags = IORESOURCE_IRQ,
484 },
485};
486
Andrew Victor3267c072006-04-02 17:15:51 +0100487static struct platform_device at91rm9200_twi_device = {
488 .name = "at91_i2c",
489 .id = -1,
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100490 .resource = twi_resources,
491 .num_resources = ARRAY_SIZE(twi_resources),
Andrew Victor3267c072006-04-02 17:15:51 +0100492};
493
Andrew Victorf230d3f2007-11-19 13:47:20 +0100494void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
Andrew Victor3267c072006-04-02 17:15:51 +0100495{
496 /* pins used for TWI interface */
497 at91_set_A_periph(AT91_PIN_PA25, 0); /* TWD */
498 at91_set_multi_drive(AT91_PIN_PA25, 1);
499
500 at91_set_A_periph(AT91_PIN_PA26, 0); /* TWCK */
501 at91_set_multi_drive(AT91_PIN_PA26, 1);
502
Andrew Victorf230d3f2007-11-19 13:47:20 +0100503 i2c_register_board_info(0, devices, nr_devices);
Andrew Victor3267c072006-04-02 17:15:51 +0100504 platform_device_register(&at91rm9200_twi_device);
505}
506#else
Andrew Victorf230d3f2007-11-19 13:47:20 +0100507void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {}
Andrew Victor3267c072006-04-02 17:15:51 +0100508#endif
509
510
511/* --------------------------------------------------------------------
Andrew Victor2e836402006-06-19 16:31:55 +0100512 * SPI
513 * -------------------------------------------------------------------- */
514
Andrew Victorc06911c2007-07-16 11:35:40 +0100515#if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
Andrew Victor2e836402006-06-19 16:31:55 +0100516static u64 spi_dmamask = 0xffffffffUL;
517
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100518static struct resource spi_resources[] = {
Andrew Victor2e836402006-06-19 16:31:55 +0100519 [0] = {
Andrew Victor72729912006-09-27 09:44:11 +0100520 .start = AT91RM9200_BASE_SPI,
521 .end = AT91RM9200_BASE_SPI + SZ_16K - 1,
Andrew Victor2e836402006-06-19 16:31:55 +0100522 .flags = IORESOURCE_MEM,
523 },
524 [1] = {
Andrew Victor72729912006-09-27 09:44:11 +0100525 .start = AT91RM9200_ID_SPI,
526 .end = AT91RM9200_ID_SPI,
Andrew Victor2e836402006-06-19 16:31:55 +0100527 .flags = IORESOURCE_IRQ,
528 },
529};
530
531static struct platform_device at91rm9200_spi_device = {
Andrew Victorc06911c2007-07-16 11:35:40 +0100532 .name = "atmel_spi",
Andrew Victor2e836402006-06-19 16:31:55 +0100533 .id = 0,
534 .dev = {
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100535 .dma_mask = &spi_dmamask,
536 .coherent_dma_mask = 0xffffffff,
Andrew Victor2e836402006-06-19 16:31:55 +0100537 },
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100538 .resource = spi_resources,
539 .num_resources = ARRAY_SIZE(spi_resources),
Andrew Victor2e836402006-06-19 16:31:55 +0100540};
541
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100542static 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 +0100543
544void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
545{
546 int i;
547 unsigned long cs_pin;
548
549 at91_set_A_periph(AT91_PIN_PA0, 0); /* MISO */
550 at91_set_A_periph(AT91_PIN_PA1, 0); /* MOSI */
551 at91_set_A_periph(AT91_PIN_PA2, 0); /* SPCK */
552
553 /* Enable SPI chip-selects */
554 for (i = 0; i < nr_devices; i++) {
555 if (devices[i].controller_data)
556 cs_pin = (unsigned long) devices[i].controller_data;
557 else
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100558 cs_pin = spi_standard_cs[devices[i].chip_select];
Andrew Victor2e836402006-06-19 16:31:55 +0100559
Andrew Victorc06911c2007-07-16 11:35:40 +0100560 /* enable chip-select pin */
Andrew Victor2e836402006-06-19 16:31:55 +0100561 at91_set_gpio_output(cs_pin, 1);
Andrew Victor2e836402006-06-19 16:31:55 +0100562
563 /* pass chip-select pin to driver */
564 devices[i].controller_data = (void *) cs_pin;
565 }
566
567 spi_register_board_info(devices, nr_devices);
Andrew Victor2e836402006-06-19 16:31:55 +0100568 platform_device_register(&at91rm9200_spi_device);
569}
570#else
571void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
572#endif
573
574
575/* --------------------------------------------------------------------
Andrew Victor3267c072006-04-02 17:15:51 +0100576 * RTC
577 * -------------------------------------------------------------------- */
578
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100579#if defined(CONFIG_RTC_DRV_AT91RM9200) || defined(CONFIG_RTC_DRV_AT91RM9200_MODULE)
Andrew Victor3267c072006-04-02 17:15:51 +0100580static struct platform_device at91rm9200_rtc_device = {
581 .name = "at91_rtc",
582 .id = -1,
583 .num_resources = 0,
584};
585
Andrew Victor2e836402006-06-19 16:31:55 +0100586static void __init at91_add_device_rtc(void)
Andrew Victor3267c072006-04-02 17:15:51 +0100587{
588 platform_device_register(&at91rm9200_rtc_device);
589}
590#else
Andrew Victor2e836402006-06-19 16:31:55 +0100591static void __init at91_add_device_rtc(void) {}
592#endif
593
594
595/* --------------------------------------------------------------------
596 * Watchdog
597 * -------------------------------------------------------------------- */
598
Andrew Victor69c5ecc2006-12-01 15:53:20 +0100599#if defined(CONFIG_AT91RM9200_WATCHDOG) || defined(CONFIG_AT91RM9200_WATCHDOG_MODULE)
Andrew Victor2e836402006-06-19 16:31:55 +0100600static struct platform_device at91rm9200_wdt_device = {
601 .name = "at91_wdt",
602 .id = -1,
603 .num_resources = 0,
604};
605
606static void __init at91_add_device_watchdog(void)
607{
608 platform_device_register(&at91rm9200_wdt_device);
609}
610#else
611static void __init at91_add_device_watchdog(void) {}
Andrew Victor3267c072006-04-02 17:15:51 +0100612#endif
613
614
615/* --------------------------------------------------------------------
Andrew Victorcc2832a2006-04-02 17:15:48 +0100616 * LEDs
617 * -------------------------------------------------------------------- */
618
619#if defined(CONFIG_LEDS)
620u8 at91_leds_cpu;
621u8 at91_leds_timer;
622
623void __init at91_init_leds(u8 cpu_led, u8 timer_led)
624{
Andrew Victorda11d022007-02-08 11:18:14 +0100625 /* Enable GPIO to access the LEDs */
626 at91_set_gpio_output(cpu_led, 1);
627 at91_set_gpio_output(timer_led, 1);
628
Andrew Victor2e836402006-06-19 16:31:55 +0100629 at91_leds_cpu = cpu_led;
630 at91_leds_timer = timer_led;
Andrew Victorcc2832a2006-04-02 17:15:48 +0100631}
Andrew Victorcc2832a2006-04-02 17:15:48 +0100632#else
633void __init at91_init_leds(u8 cpu_led, u8 timer_led) {}
634#endif
635
636
Andrew Victor2e836402006-06-19 16:31:55 +0100637/* --------------------------------------------------------------------
638 * UART
639 * -------------------------------------------------------------------- */
640
Haavard Skinnemoen749c4e62006-10-04 16:02:02 +0200641#if defined(CONFIG_SERIAL_ATMEL)
Andrew Victor2e836402006-06-19 16:31:55 +0100642static struct resource dbgu_resources[] = {
643 [0] = {
644 .start = AT91_VA_BASE_SYS + AT91_DBGU,
645 .end = AT91_VA_BASE_SYS + AT91_DBGU + SZ_512 - 1,
646 .flags = IORESOURCE_MEM,
647 },
648 [1] = {
649 .start = AT91_ID_SYS,
650 .end = AT91_ID_SYS,
651 .flags = IORESOURCE_IRQ,
652 },
653};
654
Haavard Skinnemoen73e27982006-10-04 16:02:04 +0200655static struct atmel_uart_data dbgu_data = {
Andrew Victor2e836402006-06-19 16:31:55 +0100656 .use_dma_tx = 0,
657 .use_dma_rx = 0, /* DBGU not capable of receive DMA */
Haavard Skinnemoen75d35212006-10-04 16:02:08 +0200658 .regs = (void __iomem *)(AT91_VA_BASE_SYS + AT91_DBGU),
Andrew Victor2e836402006-06-19 16:31:55 +0100659};
660
661static struct platform_device at91rm9200_dbgu_device = {
Haavard Skinnemoen1e8ea802006-10-04 16:02:03 +0200662 .name = "atmel_usart",
Andrew Victor2e836402006-06-19 16:31:55 +0100663 .id = 0,
664 .dev = {
665 .platform_data = &dbgu_data,
666 .coherent_dma_mask = 0xffffffff,
667 },
668 .resource = dbgu_resources,
669 .num_resources = ARRAY_SIZE(dbgu_resources),
670};
671
672static inline void configure_dbgu_pins(void)
673{
674 at91_set_A_periph(AT91_PIN_PA30, 0); /* DRXD */
675 at91_set_A_periph(AT91_PIN_PA31, 1); /* DTXD */
676}
677
678static struct resource uart0_resources[] = {
679 [0] = {
Andrew Victor72729912006-09-27 09:44:11 +0100680 .start = AT91RM9200_BASE_US0,
681 .end = AT91RM9200_BASE_US0 + SZ_16K - 1,
Andrew Victor2e836402006-06-19 16:31:55 +0100682 .flags = IORESOURCE_MEM,
683 },
684 [1] = {
Andrew Victor72729912006-09-27 09:44:11 +0100685 .start = AT91RM9200_ID_US0,
686 .end = AT91RM9200_ID_US0,
Andrew Victor2e836402006-06-19 16:31:55 +0100687 .flags = IORESOURCE_IRQ,
688 },
689};
690
Haavard Skinnemoen73e27982006-10-04 16:02:04 +0200691static struct atmel_uart_data uart0_data = {
Andrew Victor2e836402006-06-19 16:31:55 +0100692 .use_dma_tx = 1,
693 .use_dma_rx = 1,
694};
695
696static struct platform_device at91rm9200_uart0_device = {
Haavard Skinnemoen1e8ea802006-10-04 16:02:03 +0200697 .name = "atmel_usart",
Andrew Victor2e836402006-06-19 16:31:55 +0100698 .id = 1,
699 .dev = {
700 .platform_data = &uart0_data,
701 .coherent_dma_mask = 0xffffffff,
702 },
703 .resource = uart0_resources,
704 .num_resources = ARRAY_SIZE(uart0_resources),
705};
706
707static inline void configure_usart0_pins(void)
708{
709 at91_set_A_periph(AT91_PIN_PA17, 1); /* TXD0 */
710 at91_set_A_periph(AT91_PIN_PA18, 0); /* RXD0 */
711 at91_set_A_periph(AT91_PIN_PA20, 0); /* CTS0 */
712
713 /*
714 * AT91RM9200 Errata #39 - RTS0 is not internally connected to PA21.
715 * We need to drive the pin manually. Default is off (RTS is active low).
716 */
717 at91_set_gpio_output(AT91_PIN_PA21, 1);
718}
719
720static struct resource uart1_resources[] = {
721 [0] = {
Andrew Victor72729912006-09-27 09:44:11 +0100722 .start = AT91RM9200_BASE_US1,
723 .end = AT91RM9200_BASE_US1 + SZ_16K - 1,
Andrew Victor2e836402006-06-19 16:31:55 +0100724 .flags = IORESOURCE_MEM,
725 },
726 [1] = {
Andrew Victor72729912006-09-27 09:44:11 +0100727 .start = AT91RM9200_ID_US1,
728 .end = AT91RM9200_ID_US1,
Andrew Victor2e836402006-06-19 16:31:55 +0100729 .flags = IORESOURCE_IRQ,
730 },
731};
732
Haavard Skinnemoen73e27982006-10-04 16:02:04 +0200733static struct atmel_uart_data uart1_data = {
Andrew Victor2e836402006-06-19 16:31:55 +0100734 .use_dma_tx = 1,
735 .use_dma_rx = 1,
736};
737
738static struct platform_device at91rm9200_uart1_device = {
Haavard Skinnemoen1e8ea802006-10-04 16:02:03 +0200739 .name = "atmel_usart",
Andrew Victor2e836402006-06-19 16:31:55 +0100740 .id = 2,
741 .dev = {
742 .platform_data = &uart1_data,
743 .coherent_dma_mask = 0xffffffff,
744 },
745 .resource = uart1_resources,
746 .num_resources = ARRAY_SIZE(uart1_resources),
747};
748
749static inline void configure_usart1_pins(void)
750{
751 at91_set_A_periph(AT91_PIN_PB18, 0); /* RI1 */
752 at91_set_A_periph(AT91_PIN_PB19, 0); /* DTR1 */
753 at91_set_A_periph(AT91_PIN_PB20, 1); /* TXD1 */
754 at91_set_A_periph(AT91_PIN_PB21, 0); /* RXD1 */
755 at91_set_A_periph(AT91_PIN_PB23, 0); /* DCD1 */
756 at91_set_A_periph(AT91_PIN_PB24, 0); /* CTS1 */
757 at91_set_A_periph(AT91_PIN_PB25, 0); /* DSR1 */
758 at91_set_A_periph(AT91_PIN_PB26, 0); /* RTS1 */
759}
760
761static struct resource uart2_resources[] = {
762 [0] = {
Andrew Victor72729912006-09-27 09:44:11 +0100763 .start = AT91RM9200_BASE_US2,
764 .end = AT91RM9200_BASE_US2 + SZ_16K - 1,
Andrew Victor2e836402006-06-19 16:31:55 +0100765 .flags = IORESOURCE_MEM,
766 },
767 [1] = {
Andrew Victor72729912006-09-27 09:44:11 +0100768 .start = AT91RM9200_ID_US2,
769 .end = AT91RM9200_ID_US2,
Andrew Victor2e836402006-06-19 16:31:55 +0100770 .flags = IORESOURCE_IRQ,
771 },
772};
773
Haavard Skinnemoen73e27982006-10-04 16:02:04 +0200774static struct atmel_uart_data uart2_data = {
Andrew Victor2e836402006-06-19 16:31:55 +0100775 .use_dma_tx = 1,
776 .use_dma_rx = 1,
777};
778
779static struct platform_device at91rm9200_uart2_device = {
Haavard Skinnemoen1e8ea802006-10-04 16:02:03 +0200780 .name = "atmel_usart",
Andrew Victor2e836402006-06-19 16:31:55 +0100781 .id = 3,
782 .dev = {
783 .platform_data = &uart2_data,
784 .coherent_dma_mask = 0xffffffff,
785 },
786 .resource = uart2_resources,
787 .num_resources = ARRAY_SIZE(uart2_resources),
788};
789
790static inline void configure_usart2_pins(void)
791{
792 at91_set_A_periph(AT91_PIN_PA22, 0); /* RXD2 */
793 at91_set_A_periph(AT91_PIN_PA23, 1); /* TXD2 */
794}
795
796static struct resource uart3_resources[] = {
797 [0] = {
Andrew Victor72729912006-09-27 09:44:11 +0100798 .start = AT91RM9200_BASE_US3,
799 .end = AT91RM9200_BASE_US3 + SZ_16K - 1,
Andrew Victor2e836402006-06-19 16:31:55 +0100800 .flags = IORESOURCE_MEM,
801 },
802 [1] = {
Andrew Victor72729912006-09-27 09:44:11 +0100803 .start = AT91RM9200_ID_US3,
804 .end = AT91RM9200_ID_US3,
Andrew Victor2e836402006-06-19 16:31:55 +0100805 .flags = IORESOURCE_IRQ,
806 },
807};
808
Haavard Skinnemoen73e27982006-10-04 16:02:04 +0200809static struct atmel_uart_data uart3_data = {
Andrew Victor2e836402006-06-19 16:31:55 +0100810 .use_dma_tx = 1,
811 .use_dma_rx = 1,
812};
813
814static struct platform_device at91rm9200_uart3_device = {
Haavard Skinnemoen1e8ea802006-10-04 16:02:03 +0200815 .name = "atmel_usart",
Andrew Victor2e836402006-06-19 16:31:55 +0100816 .id = 4,
817 .dev = {
818 .platform_data = &uart3_data,
819 .coherent_dma_mask = 0xffffffff,
820 },
821 .resource = uart3_resources,
822 .num_resources = ARRAY_SIZE(uart3_resources),
823};
824
825static inline void configure_usart3_pins(void)
826{
827 at91_set_B_periph(AT91_PIN_PA5, 1); /* TXD3 */
828 at91_set_B_periph(AT91_PIN_PA6, 0); /* RXD3 */
829}
830
Haavard Skinnemoen73e27982006-10-04 16:02:04 +0200831struct platform_device *at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
832struct platform_device *atmel_default_console_device; /* the serial console device */
Andrew Victor2e836402006-06-19 16:31:55 +0100833
834void __init at91_init_serial(struct at91_uart_config *config)
835{
836 int i;
837
838 /* Fill in list of supported UARTs */
839 for (i = 0; i < config->nr_tty; i++) {
840 switch (config->tty_map[i]) {
841 case 0:
842 configure_usart0_pins();
843 at91_uarts[i] = &at91rm9200_uart0_device;
844 at91_clock_associate("usart0_clk", &at91rm9200_uart0_device.dev, "usart");
845 break;
846 case 1:
847 configure_usart1_pins();
848 at91_uarts[i] = &at91rm9200_uart1_device;
849 at91_clock_associate("usart1_clk", &at91rm9200_uart1_device.dev, "usart");
850 break;
851 case 2:
852 configure_usart2_pins();
853 at91_uarts[i] = &at91rm9200_uart2_device;
854 at91_clock_associate("usart2_clk", &at91rm9200_uart2_device.dev, "usart");
855 break;
856 case 3:
857 configure_usart3_pins();
858 at91_uarts[i] = &at91rm9200_uart3_device;
859 at91_clock_associate("usart3_clk", &at91rm9200_uart3_device.dev, "usart");
860 break;
861 case 4:
862 configure_dbgu_pins();
863 at91_uarts[i] = &at91rm9200_dbgu_device;
864 at91_clock_associate("mck", &at91rm9200_dbgu_device.dev, "usart");
865 break;
866 default:
867 continue;
868 }
869 at91_uarts[i]->id = i; /* update ID number to mapped ID */
870 }
871
872 /* Set serial console device */
Haavard Skinnemoen73e27982006-10-04 16:02:04 +0200873 if (config->console_tty < ATMEL_MAX_UART)
874 atmel_default_console_device = at91_uarts[config->console_tty];
875 if (!atmel_default_console_device)
Andrew Victor2e836402006-06-19 16:31:55 +0100876 printk(KERN_INFO "AT91: No default serial console defined.\n");
877}
878
879void __init at91_add_device_serial(void)
880{
881 int i;
882
Haavard Skinnemoen73e27982006-10-04 16:02:04 +0200883 for (i = 0; i < ATMEL_MAX_UART; i++) {
Andrew Victor2e836402006-06-19 16:31:55 +0100884 if (at91_uarts[i])
885 platform_device_register(at91_uarts[i]);
886 }
887}
888#else
889void __init at91_init_serial(struct at91_uart_config *config) {}
890void __init at91_add_device_serial(void) {}
891#endif
892
893
SAN People73a59c12006-01-09 17:05:41 +0000894/* -------------------------------------------------------------------- */
Andrew Victor2e836402006-06-19 16:31:55 +0100895
896/*
897 * These devices are always present and don't need any board-specific
898 * setup.
899 */
900static int __init at91_add_standard_devices(void)
901{
902 at91_add_device_rtc();
903 at91_add_device_watchdog();
904 return 0;
905}
906
907arch_initcall(at91_add_standard_devices);