blob: 49aa6a9f4323c118340713763138daeb88fbbb55 [file] [log] [blame]
Andrew Victorb2c65612007-02-08 09:42:40 +01001/*
2 * arch/arm/mach-at91/at91sam9263_devices.c
3 *
4 * Copyright (C) 2007 Atmel Corporation.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 */
12#include <asm/mach/arch.h>
13#include <asm/mach/map.h>
14
Andrew Victorc6686ff2008-01-23 09:13:53 +010015#include <linux/dma-mapping.h>
Russell King2f8163b2011-07-26 10:53:52 +010016#include <linux/gpio.h>
Andrew Victorb2c65612007-02-08 09:42:40 +010017#include <linux/platform_device.h>
Andrew Victorf230d3f2007-11-19 13:47:20 +010018#include <linux/i2c-gpio.h>
Andrew Victorb2c65612007-02-08 09:42:40 +010019
Andrew Victorf230d3f2007-11-19 13:47:20 +010020#include <linux/fb.h>
Jan Altenbergb8b786092007-08-03 12:14:34 +010021#include <video/atmel_lcdc.h>
22
Russell Kinga09e64f2008-08-05 16:14:15 +010023#include <mach/board.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010024#include <mach/at91sam9263.h>
25#include <mach/at91sam9263_matrix.h>
26#include <mach/at91sam9_smc.h>
Andrew Victorb2c65612007-02-08 09:42:40 +010027
28#include "generic.h"
29
Andrew Victorb2c65612007-02-08 09:42:40 +010030
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);
Andrew Victorb2c65612007-02-08 09:42:40 +010037static struct at91_usbh_data usbh_data;
38
39static struct resource usbh_resources[] = {
40 [0] = {
41 .start = AT91SAM9263_UHP_BASE,
42 .end = AT91SAM9263_UHP_BASE + SZ_1M - 1,
43 .flags = IORESOURCE_MEM,
44 },
45 [1] = {
46 .start = AT91SAM9263_ID_UHP,
47 .end = AT91SAM9263_ID_UHP,
48 .flags = IORESOURCE_IRQ,
49 },
50};
51
52static struct platform_device at91_usbh_device = {
53 .name = "at91_ohci",
54 .id = -1,
55 .dev = {
56 .dma_mask = &ohci_dmamask,
Andrew Victorc6686ff2008-01-23 09:13:53 +010057 .coherent_dma_mask = DMA_BIT_MASK(32),
Andrew Victorb2c65612007-02-08 09:42:40 +010058 .platform_data = &usbh_data,
59 },
60 .resource = usbh_resources,
61 .num_resources = ARRAY_SIZE(usbh_resources),
62};
63
64void __init at91_add_device_usbh(struct at91_usbh_data *data)
65{
66 int i;
67
68 if (!data)
69 return;
70
71 /* Enable VBus control for UHP ports */
72 for (i = 0; i < data->ports; i++) {
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +080073 if (gpio_is_valid(data->vbus_pin[i]))
Andrew Victorb2c65612007-02-08 09:42:40 +010074 at91_set_gpio_output(data->vbus_pin[i], 0);
75 }
76
Thomas Petazzoni1fcaea72011-07-13 11:29:18 +020077 /* Enable overcurrent notification */
78 for (i = 0; i < data->ports; i++) {
79 if (data->overcurrent_pin[i])
80 at91_set_gpio_input(data->overcurrent_pin[i], 1);
81 }
82
Andrew Victorb2c65612007-02-08 09:42:40 +010083 usbh_data = *data;
84 platform_device_register(&at91_usbh_device);
85}
86#else
87void __init at91_add_device_usbh(struct at91_usbh_data *data) {}
88#endif
89
90
91/* --------------------------------------------------------------------
92 * USB Device (Gadget)
93 * -------------------------------------------------------------------- */
94
Anders Darander0e934e22011-11-30 08:47:44 +010095#ifdef CONFIG_USB_AT91
Andrew Victorb2c65612007-02-08 09:42:40 +010096static struct at91_udc_data udc_data;
97
98static struct resource udc_resources[] = {
99 [0] = {
100 .start = AT91SAM9263_BASE_UDP,
101 .end = AT91SAM9263_BASE_UDP + SZ_16K - 1,
102 .flags = IORESOURCE_MEM,
103 },
104 [1] = {
105 .start = AT91SAM9263_ID_UDP,
106 .end = AT91SAM9263_ID_UDP,
107 .flags = IORESOURCE_IRQ,
108 },
109};
110
111static struct platform_device at91_udc_device = {
112 .name = "at91_udc",
113 .id = -1,
114 .dev = {
115 .platform_data = &udc_data,
116 },
117 .resource = udc_resources,
118 .num_resources = ARRAY_SIZE(udc_resources),
119};
120
121void __init at91_add_device_udc(struct at91_udc_data *data)
122{
123 if (!data)
124 return;
125
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +0800126 if (gpio_is_valid(data->vbus_pin)) {
Andrew Victorb2c65612007-02-08 09:42:40 +0100127 at91_set_gpio_input(data->vbus_pin, 0);
128 at91_set_deglitch(data->vbus_pin, 1);
129 }
130
131 /* Pullup pin is handled internally by USB device peripheral */
132
133 udc_data = *data;
134 platform_device_register(&at91_udc_device);
135}
136#else
137void __init at91_add_device_udc(struct at91_udc_data *data) {}
138#endif
139
140
141/* --------------------------------------------------------------------
142 * Ethernet
143 * -------------------------------------------------------------------- */
144
145#if defined(CONFIG_MACB) || defined(CONFIG_MACB_MODULE)
Andrew Victorc6686ff2008-01-23 09:13:53 +0100146static u64 eth_dmamask = DMA_BIT_MASK(32);
Jamie Iles84e0cdb2011-03-08 20:17:06 +0000147static struct macb_platform_data eth_data;
Andrew Victorb2c65612007-02-08 09:42:40 +0100148
149static struct resource eth_resources[] = {
150 [0] = {
151 .start = AT91SAM9263_BASE_EMAC,
152 .end = AT91SAM9263_BASE_EMAC + SZ_16K - 1,
153 .flags = IORESOURCE_MEM,
154 },
155 [1] = {
156 .start = AT91SAM9263_ID_EMAC,
157 .end = AT91SAM9263_ID_EMAC,
158 .flags = IORESOURCE_IRQ,
159 },
160};
161
162static struct platform_device at91sam9263_eth_device = {
163 .name = "macb",
164 .id = -1,
165 .dev = {
166 .dma_mask = &eth_dmamask,
Andrew Victorc6686ff2008-01-23 09:13:53 +0100167 .coherent_dma_mask = DMA_BIT_MASK(32),
Andrew Victorb2c65612007-02-08 09:42:40 +0100168 .platform_data = &eth_data,
169 },
170 .resource = eth_resources,
171 .num_resources = ARRAY_SIZE(eth_resources),
172};
173
Jamie Iles84e0cdb2011-03-08 20:17:06 +0000174void __init at91_add_device_eth(struct macb_platform_data *data)
Andrew Victorb2c65612007-02-08 09:42:40 +0100175{
176 if (!data)
177 return;
178
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +0800179 if (gpio_is_valid(data->phy_irq_pin)) {
Andrew Victorb2c65612007-02-08 09:42:40 +0100180 at91_set_gpio_input(data->phy_irq_pin, 0);
181 at91_set_deglitch(data->phy_irq_pin, 1);
182 }
183
184 /* Pins used for MII and RMII */
185 at91_set_A_periph(AT91_PIN_PE21, 0); /* ETXCK_EREFCK */
186 at91_set_B_periph(AT91_PIN_PC25, 0); /* ERXDV */
187 at91_set_A_periph(AT91_PIN_PE25, 0); /* ERX0 */
188 at91_set_A_periph(AT91_PIN_PE26, 0); /* ERX1 */
189 at91_set_A_periph(AT91_PIN_PE27, 0); /* ERXER */
190 at91_set_A_periph(AT91_PIN_PE28, 0); /* ETXEN */
191 at91_set_A_periph(AT91_PIN_PE23, 0); /* ETX0 */
192 at91_set_A_periph(AT91_PIN_PE24, 0); /* ETX1 */
193 at91_set_A_periph(AT91_PIN_PE30, 0); /* EMDIO */
194 at91_set_A_periph(AT91_PIN_PE29, 0); /* EMDC */
195
196 if (!data->is_rmii) {
197 at91_set_A_periph(AT91_PIN_PE22, 0); /* ECRS */
198 at91_set_B_periph(AT91_PIN_PC26, 0); /* ECOL */
199 at91_set_B_periph(AT91_PIN_PC22, 0); /* ERX2 */
200 at91_set_B_periph(AT91_PIN_PC23, 0); /* ERX3 */
201 at91_set_B_periph(AT91_PIN_PC27, 0); /* ERXCK */
202 at91_set_B_periph(AT91_PIN_PC20, 0); /* ETX2 */
203 at91_set_B_periph(AT91_PIN_PC21, 0); /* ETX3 */
204 at91_set_B_periph(AT91_PIN_PC24, 0); /* ETXER */
205 }
206
207 eth_data = *data;
208 platform_device_register(&at91sam9263_eth_device);
209}
210#else
Jamie Iles84e0cdb2011-03-08 20:17:06 +0000211void __init at91_add_device_eth(struct macb_platform_data *data) {}
Andrew Victorb2c65612007-02-08 09:42:40 +0100212#endif
213
214
215/* --------------------------------------------------------------------
216 * MMC / SD
217 * -------------------------------------------------------------------- */
218
219#if defined(CONFIG_MMC_AT91) || defined(CONFIG_MMC_AT91_MODULE)
Andrew Victorc6686ff2008-01-23 09:13:53 +0100220static u64 mmc_dmamask = DMA_BIT_MASK(32);
Andrew Victorb2c65612007-02-08 09:42:40 +0100221static struct at91_mmc_data mmc0_data, mmc1_data;
222
223static struct resource mmc0_resources[] = {
224 [0] = {
225 .start = AT91SAM9263_BASE_MCI0,
226 .end = AT91SAM9263_BASE_MCI0 + SZ_16K - 1,
227 .flags = IORESOURCE_MEM,
228 },
229 [1] = {
230 .start = AT91SAM9263_ID_MCI0,
231 .end = AT91SAM9263_ID_MCI0,
232 .flags = IORESOURCE_IRQ,
233 },
234};
235
236static struct platform_device at91sam9263_mmc0_device = {
237 .name = "at91_mci",
238 .id = 0,
239 .dev = {
240 .dma_mask = &mmc_dmamask,
Andrew Victorc6686ff2008-01-23 09:13:53 +0100241 .coherent_dma_mask = DMA_BIT_MASK(32),
Andrew Victorb2c65612007-02-08 09:42:40 +0100242 .platform_data = &mmc0_data,
243 },
244 .resource = mmc0_resources,
245 .num_resources = ARRAY_SIZE(mmc0_resources),
246};
247
248static struct resource mmc1_resources[] = {
249 [0] = {
250 .start = AT91SAM9263_BASE_MCI1,
251 .end = AT91SAM9263_BASE_MCI1 + SZ_16K - 1,
252 .flags = IORESOURCE_MEM,
253 },
254 [1] = {
255 .start = AT91SAM9263_ID_MCI1,
256 .end = AT91SAM9263_ID_MCI1,
257 .flags = IORESOURCE_IRQ,
258 },
259};
260
261static struct platform_device at91sam9263_mmc1_device = {
262 .name = "at91_mci",
263 .id = 1,
264 .dev = {
265 .dma_mask = &mmc_dmamask,
Andrew Victorc6686ff2008-01-23 09:13:53 +0100266 .coherent_dma_mask = DMA_BIT_MASK(32),
Andrew Victorb2c65612007-02-08 09:42:40 +0100267 .platform_data = &mmc1_data,
268 },
269 .resource = mmc1_resources,
270 .num_resources = ARRAY_SIZE(mmc1_resources),
271};
272
273void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data)
274{
275 if (!data)
276 return;
277
278 /* input/irq */
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +0800279 if (gpio_is_valid(data->det_pin)) {
Andrew Victorb2c65612007-02-08 09:42:40 +0100280 at91_set_gpio_input(data->det_pin, 1);
281 at91_set_deglitch(data->det_pin, 1);
282 }
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +0800283 if (gpio_is_valid(data->wp_pin))
Andrew Victorb2c65612007-02-08 09:42:40 +0100284 at91_set_gpio_input(data->wp_pin, 1);
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +0800285 if (gpio_is_valid(data->vcc_pin))
Andrew Victorb2c65612007-02-08 09:42:40 +0100286 at91_set_gpio_output(data->vcc_pin, 0);
287
288 if (mmc_id == 0) { /* MCI0 */
289 /* CLK */
290 at91_set_A_periph(AT91_PIN_PA12, 0);
291
292 if (data->slot_b) {
293 /* CMD */
294 at91_set_A_periph(AT91_PIN_PA16, 1);
295
296 /* DAT0, maybe DAT1..DAT3 */
297 at91_set_A_periph(AT91_PIN_PA17, 1);
298 if (data->wire4) {
299 at91_set_A_periph(AT91_PIN_PA18, 1);
300 at91_set_A_periph(AT91_PIN_PA19, 1);
301 at91_set_A_periph(AT91_PIN_PA20, 1);
302 }
303 } else {
304 /* CMD */
305 at91_set_A_periph(AT91_PIN_PA1, 1);
306
307 /* DAT0, maybe DAT1..DAT3 */
308 at91_set_A_periph(AT91_PIN_PA0, 1);
309 if (data->wire4) {
310 at91_set_A_periph(AT91_PIN_PA3, 1);
311 at91_set_A_periph(AT91_PIN_PA4, 1);
312 at91_set_A_periph(AT91_PIN_PA5, 1);
313 }
314 }
315
316 mmc0_data = *data;
Andrew Victorb2c65612007-02-08 09:42:40 +0100317 platform_device_register(&at91sam9263_mmc0_device);
318 } else { /* MCI1 */
319 /* CLK */
320 at91_set_A_periph(AT91_PIN_PA6, 0);
321
322 if (data->slot_b) {
323 /* CMD */
324 at91_set_A_periph(AT91_PIN_PA21, 1);
325
326 /* DAT0, maybe DAT1..DAT3 */
327 at91_set_A_periph(AT91_PIN_PA22, 1);
328 if (data->wire4) {
329 at91_set_A_periph(AT91_PIN_PA23, 1);
330 at91_set_A_periph(AT91_PIN_PA24, 1);
331 at91_set_A_periph(AT91_PIN_PA25, 1);
332 }
333 } else {
334 /* CMD */
335 at91_set_A_periph(AT91_PIN_PA7, 1);
336
337 /* DAT0, maybe DAT1..DAT3 */
338 at91_set_A_periph(AT91_PIN_PA8, 1);
339 if (data->wire4) {
340 at91_set_A_periph(AT91_PIN_PA9, 1);
341 at91_set_A_periph(AT91_PIN_PA10, 1);
342 at91_set_A_periph(AT91_PIN_PA11, 1);
343 }
344 }
345
346 mmc1_data = *data;
Andrew Victorb2c65612007-02-08 09:42:40 +0100347 platform_device_register(&at91sam9263_mmc1_device);
348 }
349}
350#else
351void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data) {}
352#endif
353
Stanislaw Gruszkae565f202009-03-05 16:10:58 +0100354/* --------------------------------------------------------------------
355 * Compact Flash (PCMCIA or IDE)
356 * -------------------------------------------------------------------- */
357
358#if defined(CONFIG_AT91_CF) || defined(CONFIG_AT91_CF_MODULE) || \
359 defined(CONFIG_BLK_DEV_IDE_AT91) || defined(CONFIG_BLK_DEV_IDE_AT91_MODULE)
360
361static struct at91_cf_data cf0_data;
362
363static struct resource cf0_resources[] = {
364 [0] = {
365 .start = AT91_CHIPSELECT_4,
366 .end = AT91_CHIPSELECT_4 + SZ_256M - 1,
367 .flags = IORESOURCE_MEM | IORESOURCE_MEM_8AND16BIT,
368 }
369};
370
371static struct platform_device cf0_device = {
372 .id = 0,
373 .dev = {
374 .platform_data = &cf0_data,
375 },
376 .resource = cf0_resources,
377 .num_resources = ARRAY_SIZE(cf0_resources),
378};
379
380static struct at91_cf_data cf1_data;
381
382static struct resource cf1_resources[] = {
383 [0] = {
384 .start = AT91_CHIPSELECT_5,
385 .end = AT91_CHIPSELECT_5 + SZ_256M - 1,
386 .flags = IORESOURCE_MEM | IORESOURCE_MEM_8AND16BIT,
387 }
388};
389
390static struct platform_device cf1_device = {
391 .id = 1,
392 .dev = {
393 .platform_data = &cf1_data,
394 },
395 .resource = cf1_resources,
396 .num_resources = ARRAY_SIZE(cf1_resources),
397};
398
399void __init at91_add_device_cf(struct at91_cf_data *data)
400{
401 unsigned long ebi0_csa;
402 struct platform_device *pdev;
403
404 if (!data)
405 return;
406
407 /*
408 * assign CS4 or CS5 to SMC with Compact Flash logic support,
409 * we assume SMC timings are configured by board code,
410 * except True IDE where timings are controlled by driver
411 */
412 ebi0_csa = at91_sys_read(AT91_MATRIX_EBI0CSA);
413 switch (data->chipselect) {
414 case 4:
415 at91_set_A_periph(AT91_PIN_PD6, 0); /* EBI0_NCS4/CFCS0 */
416 ebi0_csa |= AT91_MATRIX_EBI0_CS4A_SMC_CF1;
417 cf0_data = *data;
418 pdev = &cf0_device;
419 break;
420 case 5:
421 at91_set_A_periph(AT91_PIN_PD7, 0); /* EBI0_NCS5/CFCS1 */
422 ebi0_csa |= AT91_MATRIX_EBI0_CS5A_SMC_CF2;
423 cf1_data = *data;
424 pdev = &cf1_device;
425 break;
426 default:
427 printk(KERN_ERR "AT91 CF: bad chip-select requested (%u)\n",
428 data->chipselect);
429 return;
430 }
431 at91_sys_write(AT91_MATRIX_EBI0CSA, ebi0_csa);
432
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +0800433 if (gpio_is_valid(data->det_pin)) {
Stanislaw Gruszkae565f202009-03-05 16:10:58 +0100434 at91_set_gpio_input(data->det_pin, 1);
435 at91_set_deglitch(data->det_pin, 1);
436 }
437
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +0800438 if (gpio_is_valid(data->irq_pin)) {
Stanislaw Gruszkae565f202009-03-05 16:10:58 +0100439 at91_set_gpio_input(data->irq_pin, 1);
440 at91_set_deglitch(data->irq_pin, 1);
441 }
442
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +0800443 if (gpio_is_valid(data->vcc_pin))
Stanislaw Gruszkae565f202009-03-05 16:10:58 +0100444 /* initially off */
445 at91_set_gpio_output(data->vcc_pin, 0);
446
447 /* enable EBI controlled pins */
448 at91_set_A_periph(AT91_PIN_PD5, 1); /* NWAIT */
449 at91_set_A_periph(AT91_PIN_PD8, 0); /* CFCE1 */
450 at91_set_A_periph(AT91_PIN_PD9, 0); /* CFCE2 */
451 at91_set_A_periph(AT91_PIN_PD14, 0); /* CFNRW */
452
453 pdev->name = (data->flags & AT91_CF_TRUE_IDE) ? "at91_ide" : "at91_cf";
454 platform_device_register(pdev);
455}
456#else
457void __init at91_add_device_cf(struct at91_cf_data *data) {}
458#endif
Andrew Victorb2c65612007-02-08 09:42:40 +0100459
460/* --------------------------------------------------------------------
461 * NAND / SmartMedia
462 * -------------------------------------------------------------------- */
463
Pieter du Preezf6ed6f72008-08-01 10:06:40 +0100464#if defined(CONFIG_MTD_NAND_ATMEL) || defined(CONFIG_MTD_NAND_ATMEL_MODULE)
HÃ¥vard Skinnemoen3c3796c2008-06-06 18:04:53 +0200465static struct atmel_nand_data nand_data;
Andrew Victorb2c65612007-02-08 09:42:40 +0100466
467#define NAND_BASE AT91_CHIPSELECT_3
468
469static struct resource nand_resources[] = {
Andrew Victord7a24152008-04-02 21:44:44 +0100470 [0] = {
Andrew Victorb2c65612007-02-08 09:42:40 +0100471 .start = NAND_BASE,
472 .end = NAND_BASE + SZ_256M - 1,
473 .flags = IORESOURCE_MEM,
Andrew Victord7a24152008-04-02 21:44:44 +0100474 },
475 [1] = {
Jean-Christophe PLAGNIOL-VILLARDd28edd12011-09-18 09:31:56 +0800476 .start = AT91SAM9263_BASE_ECC0,
477 .end = AT91SAM9263_BASE_ECC0 + SZ_512 - 1,
Andrew Victord7a24152008-04-02 21:44:44 +0100478 .flags = IORESOURCE_MEM,
Andrew Victorb2c65612007-02-08 09:42:40 +0100479 }
480};
481
482static struct platform_device at91sam9263_nand_device = {
HÃ¥vard Skinnemoen3c3796c2008-06-06 18:04:53 +0200483 .name = "atmel_nand",
Andrew Victorb2c65612007-02-08 09:42:40 +0100484 .id = -1,
485 .dev = {
486 .platform_data = &nand_data,
487 },
488 .resource = nand_resources,
489 .num_resources = ARRAY_SIZE(nand_resources),
490};
491
HÃ¥vard Skinnemoen3c3796c2008-06-06 18:04:53 +0200492void __init at91_add_device_nand(struct atmel_nand_data *data)
Andrew Victorb2c65612007-02-08 09:42:40 +0100493{
Andrew Victor461d3b42008-10-06 20:01:00 +0100494 unsigned long csa;
Andrew Victorb2c65612007-02-08 09:42:40 +0100495
496 if (!data)
497 return;
498
499 csa = at91_sys_read(AT91_MATRIX_EBI0CSA);
Andrew Victor22823552008-01-23 09:21:02 +0100500 at91_sys_write(AT91_MATRIX_EBI0CSA, csa | AT91_MATRIX_EBI0_CS3A_SMC_SMARTMEDIA);
Andrew Victorb2c65612007-02-08 09:42:40 +0100501
Andrew Victorb2c65612007-02-08 09:42:40 +0100502 /* enable pin */
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +0800503 if (gpio_is_valid(data->enable_pin))
Andrew Victorb2c65612007-02-08 09:42:40 +0100504 at91_set_gpio_output(data->enable_pin, 1);
505
506 /* ready/busy pin */
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +0800507 if (gpio_is_valid(data->rdy_pin))
Andrew Victorb2c65612007-02-08 09:42:40 +0100508 at91_set_gpio_input(data->rdy_pin, 1);
509
510 /* card detect pin */
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +0800511 if (gpio_is_valid(data->det_pin))
Andrew Victorb2c65612007-02-08 09:42:40 +0100512 at91_set_gpio_input(data->det_pin, 1);
513
514 nand_data = *data;
515 platform_device_register(&at91sam9263_nand_device);
516}
517#else
HÃ¥vard Skinnemoen3c3796c2008-06-06 18:04:53 +0200518void __init at91_add_device_nand(struct atmel_nand_data *data) {}
Andrew Victorb2c65612007-02-08 09:42:40 +0100519#endif
520
521
522/* --------------------------------------------------------------------
523 * TWI (i2c)
524 * -------------------------------------------------------------------- */
525
Andrew Victorf230d3f2007-11-19 13:47:20 +0100526/*
527 * Prefer the GPIO code since the TWI controller isn't robust
528 * (gets overruns and underruns under load) and can only issue
529 * repeated STARTs in one scenario (the driver doesn't yet handle them).
530 */
531#if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
532
533static struct i2c_gpio_platform_data pdata = {
534 .sda_pin = AT91_PIN_PB4,
535 .sda_is_open_drain = 1,
536 .scl_pin = AT91_PIN_PB5,
537 .scl_is_open_drain = 1,
538 .udelay = 2, /* ~100 kHz */
539};
540
541static struct platform_device at91sam9263_twi_device = {
542 .name = "i2c-gpio",
543 .id = -1,
544 .dev.platform_data = &pdata,
545};
546
547void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
548{
549 at91_set_GPIO_periph(AT91_PIN_PB4, 1); /* TWD (SDA) */
550 at91_set_multi_drive(AT91_PIN_PB4, 1);
551
552 at91_set_GPIO_periph(AT91_PIN_PB5, 1); /* TWCK (SCL) */
553 at91_set_multi_drive(AT91_PIN_PB5, 1);
554
555 i2c_register_board_info(0, devices, nr_devices);
556 platform_device_register(&at91sam9263_twi_device);
557}
558
559#elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
Andrew Victorb2c65612007-02-08 09:42:40 +0100560
561static struct resource twi_resources[] = {
562 [0] = {
563 .start = AT91SAM9263_BASE_TWI,
564 .end = AT91SAM9263_BASE_TWI + SZ_16K - 1,
565 .flags = IORESOURCE_MEM,
566 },
567 [1] = {
568 .start = AT91SAM9263_ID_TWI,
569 .end = AT91SAM9263_ID_TWI,
570 .flags = IORESOURCE_IRQ,
571 },
572};
573
574static struct platform_device at91sam9263_twi_device = {
575 .name = "at91_i2c",
576 .id = -1,
577 .resource = twi_resources,
578 .num_resources = ARRAY_SIZE(twi_resources),
579};
580
Andrew Victorf230d3f2007-11-19 13:47:20 +0100581void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
Andrew Victorb2c65612007-02-08 09:42:40 +0100582{
583 /* pins used for TWI interface */
584 at91_set_A_periph(AT91_PIN_PB4, 0); /* TWD */
585 at91_set_multi_drive(AT91_PIN_PB4, 1);
586
587 at91_set_A_periph(AT91_PIN_PB5, 0); /* TWCK */
588 at91_set_multi_drive(AT91_PIN_PB5, 1);
589
Andrew Victorf230d3f2007-11-19 13:47:20 +0100590 i2c_register_board_info(0, devices, nr_devices);
Andrew Victorb2c65612007-02-08 09:42:40 +0100591 platform_device_register(&at91sam9263_twi_device);
592}
593#else
Andrew Victorf230d3f2007-11-19 13:47:20 +0100594void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {}
Andrew Victorb2c65612007-02-08 09:42:40 +0100595#endif
596
597
598/* --------------------------------------------------------------------
599 * SPI
600 * -------------------------------------------------------------------- */
601
602#if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
Andrew Victorc6686ff2008-01-23 09:13:53 +0100603static u64 spi_dmamask = DMA_BIT_MASK(32);
Andrew Victorb2c65612007-02-08 09:42:40 +0100604
605static struct resource spi0_resources[] = {
606 [0] = {
607 .start = AT91SAM9263_BASE_SPI0,
608 .end = AT91SAM9263_BASE_SPI0 + SZ_16K - 1,
609 .flags = IORESOURCE_MEM,
610 },
611 [1] = {
612 .start = AT91SAM9263_ID_SPI0,
613 .end = AT91SAM9263_ID_SPI0,
614 .flags = IORESOURCE_IRQ,
615 },
616};
617
618static struct platform_device at91sam9263_spi0_device = {
619 .name = "atmel_spi",
620 .id = 0,
621 .dev = {
622 .dma_mask = &spi_dmamask,
Andrew Victorc6686ff2008-01-23 09:13:53 +0100623 .coherent_dma_mask = DMA_BIT_MASK(32),
Andrew Victorb2c65612007-02-08 09:42:40 +0100624 },
625 .resource = spi0_resources,
626 .num_resources = ARRAY_SIZE(spi0_resources),
627};
628
629static const unsigned spi0_standard_cs[4] = { AT91_PIN_PA5, AT91_PIN_PA3, AT91_PIN_PA4, AT91_PIN_PB11 };
630
631static struct resource spi1_resources[] = {
632 [0] = {
633 .start = AT91SAM9263_BASE_SPI1,
634 .end = AT91SAM9263_BASE_SPI1 + SZ_16K - 1,
635 .flags = IORESOURCE_MEM,
636 },
637 [1] = {
638 .start = AT91SAM9263_ID_SPI1,
639 .end = AT91SAM9263_ID_SPI1,
640 .flags = IORESOURCE_IRQ,
641 },
642};
643
644static struct platform_device at91sam9263_spi1_device = {
645 .name = "atmel_spi",
646 .id = 1,
647 .dev = {
648 .dma_mask = &spi_dmamask,
Andrew Victorc6686ff2008-01-23 09:13:53 +0100649 .coherent_dma_mask = DMA_BIT_MASK(32),
Andrew Victorb2c65612007-02-08 09:42:40 +0100650 },
651 .resource = spi1_resources,
652 .num_resources = ARRAY_SIZE(spi1_resources),
653};
654
655static const unsigned spi1_standard_cs[4] = { AT91_PIN_PB15, AT91_PIN_PB16, AT91_PIN_PB17, AT91_PIN_PB18 };
656
657void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
658{
659 int i;
660 unsigned long cs_pin;
661 short enable_spi0 = 0;
662 short enable_spi1 = 0;
663
664 /* Choose SPI chip-selects */
665 for (i = 0; i < nr_devices; i++) {
666 if (devices[i].controller_data)
667 cs_pin = (unsigned long) devices[i].controller_data;
668 else if (devices[i].bus_num == 0)
669 cs_pin = spi0_standard_cs[devices[i].chip_select];
670 else
671 cs_pin = spi1_standard_cs[devices[i].chip_select];
672
673 if (devices[i].bus_num == 0)
674 enable_spi0 = 1;
675 else
676 enable_spi1 = 1;
677
678 /* enable chip-select pin */
679 at91_set_gpio_output(cs_pin, 1);
680
681 /* pass chip-select pin to driver */
682 devices[i].controller_data = (void *) cs_pin;
683 }
684
685 spi_register_board_info(devices, nr_devices);
686
687 /* Configure SPI bus(es) */
688 if (enable_spi0) {
689 at91_set_B_periph(AT91_PIN_PA0, 0); /* SPI0_MISO */
690 at91_set_B_periph(AT91_PIN_PA1, 0); /* SPI0_MOSI */
Andrew Victor7f6e2d92007-02-22 07:34:56 +0100691 at91_set_B_periph(AT91_PIN_PA2, 0); /* SPI0_SPCK */
Andrew Victorb2c65612007-02-08 09:42:40 +0100692
Andrew Victorb2c65612007-02-08 09:42:40 +0100693 platform_device_register(&at91sam9263_spi0_device);
694 }
695 if (enable_spi1) {
696 at91_set_A_periph(AT91_PIN_PB12, 0); /* SPI1_MISO */
697 at91_set_A_periph(AT91_PIN_PB13, 0); /* SPI1_MOSI */
698 at91_set_A_periph(AT91_PIN_PB14, 0); /* SPI1_SPCK */
699
Andrew Victorb2c65612007-02-08 09:42:40 +0100700 platform_device_register(&at91sam9263_spi1_device);
701 }
702}
703#else
704void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
705#endif
706
707
708/* --------------------------------------------------------------------
Andrew Victor7776a942007-05-02 17:46:49 +0100709 * AC97
710 * -------------------------------------------------------------------- */
711
sedji gaouaoud656f072009-08-06 15:20:22 +0100712#if defined(CONFIG_SND_ATMEL_AC97C) || defined(CONFIG_SND_ATMEL_AC97C_MODULE)
Andrew Victorc6686ff2008-01-23 09:13:53 +0100713static u64 ac97_dmamask = DMA_BIT_MASK(32);
sedji gaouaoud656f072009-08-06 15:20:22 +0100714static struct ac97c_platform_data ac97_data;
Andrew Victor7776a942007-05-02 17:46:49 +0100715
716static struct resource ac97_resources[] = {
717 [0] = {
718 .start = AT91SAM9263_BASE_AC97C,
719 .end = AT91SAM9263_BASE_AC97C + SZ_16K - 1,
720 .flags = IORESOURCE_MEM,
721 },
722 [1] = {
723 .start = AT91SAM9263_ID_AC97C,
724 .end = AT91SAM9263_ID_AC97C,
725 .flags = IORESOURCE_IRQ,
726 },
727};
728
729static struct platform_device at91sam9263_ac97_device = {
sedji gaouaoud656f072009-08-06 15:20:22 +0100730 .name = "atmel_ac97c",
731 .id = 0,
Andrew Victor7776a942007-05-02 17:46:49 +0100732 .dev = {
733 .dma_mask = &ac97_dmamask,
Andrew Victorc6686ff2008-01-23 09:13:53 +0100734 .coherent_dma_mask = DMA_BIT_MASK(32),
Andrew Victor7776a942007-05-02 17:46:49 +0100735 .platform_data = &ac97_data,
736 },
737 .resource = ac97_resources,
738 .num_resources = ARRAY_SIZE(ac97_resources),
739};
740
sedji gaouaoud656f072009-08-06 15:20:22 +0100741void __init at91_add_device_ac97(struct ac97c_platform_data *data)
Andrew Victor7776a942007-05-02 17:46:49 +0100742{
743 if (!data)
744 return;
745
746 at91_set_A_periph(AT91_PIN_PB0, 0); /* AC97FS */
747 at91_set_A_periph(AT91_PIN_PB1, 0); /* AC97CK */
748 at91_set_A_periph(AT91_PIN_PB2, 0); /* AC97TX */
749 at91_set_A_periph(AT91_PIN_PB3, 0); /* AC97RX */
750
751 /* reset */
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +0800752 if (gpio_is_valid(data->reset_pin))
Andrew Victor7776a942007-05-02 17:46:49 +0100753 at91_set_gpio_output(data->reset_pin, 0);
754
sedji gaouaoud656f072009-08-06 15:20:22 +0100755 ac97_data = *data;
Andrew Victor7776a942007-05-02 17:46:49 +0100756 platform_device_register(&at91sam9263_ac97_device);
757}
758#else
sedji gaouaoud656f072009-08-06 15:20:22 +0100759void __init at91_add_device_ac97(struct ac97c_platform_data *data) {}
Andrew Victor7776a942007-05-02 17:46:49 +0100760#endif
761
Marc Kleine-Budde58a587d2009-09-16 23:37:32 +0000762/* --------------------------------------------------------------------
763 * CAN Controller
764 * -------------------------------------------------------------------- */
765
766#if defined(CONFIG_CAN_AT91) || defined(CONFIG_CAN_AT91_MODULE)
767static struct resource can_resources[] = {
768 [0] = {
769 .start = AT91SAM9263_BASE_CAN,
770 .end = AT91SAM9263_BASE_CAN + SZ_16K - 1,
771 .flags = IORESOURCE_MEM,
772 },
773 [1] = {
774 .start = AT91SAM9263_ID_CAN,
775 .end = AT91SAM9263_ID_CAN,
776 .flags = IORESOURCE_IRQ,
777 },
778};
779
780static struct platform_device at91sam9263_can_device = {
781 .name = "at91_can",
782 .id = -1,
783 .resource = can_resources,
784 .num_resources = ARRAY_SIZE(can_resources),
785};
786
787void __init at91_add_device_can(struct at91_can_data *data)
788{
789 at91_set_A_periph(AT91_PIN_PA13, 0); /* CANTX */
790 at91_set_A_periph(AT91_PIN_PA14, 0); /* CANRX */
791 at91sam9263_can_device.dev.platform_data = data;
792
793 platform_device_register(&at91sam9263_can_device);
794}
795#else
796void __init at91_add_device_can(struct at91_can_data *data) {}
797#endif
Andrew Victor7776a942007-05-02 17:46:49 +0100798
799/* --------------------------------------------------------------------
800 * LCD Controller
801 * -------------------------------------------------------------------- */
802
803#if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
Andrew Victorc6686ff2008-01-23 09:13:53 +0100804static u64 lcdc_dmamask = DMA_BIT_MASK(32);
Andrew Victor7776a942007-05-02 17:46:49 +0100805static struct atmel_lcdfb_info lcdc_data;
806
807static struct resource lcdc_resources[] = {
808 [0] = {
809 .start = AT91SAM9263_LCDC_BASE,
810 .end = AT91SAM9263_LCDC_BASE + SZ_4K - 1,
811 .flags = IORESOURCE_MEM,
812 },
813 [1] = {
814 .start = AT91SAM9263_ID_LCDC,
815 .end = AT91SAM9263_ID_LCDC,
816 .flags = IORESOURCE_IRQ,
817 },
818};
819
820static struct platform_device at91_lcdc_device = {
821 .name = "atmel_lcdfb",
822 .id = 0,
823 .dev = {
824 .dma_mask = &lcdc_dmamask,
Andrew Victorc6686ff2008-01-23 09:13:53 +0100825 .coherent_dma_mask = DMA_BIT_MASK(32),
Andrew Victor7776a942007-05-02 17:46:49 +0100826 .platform_data = &lcdc_data,
827 },
828 .resource = lcdc_resources,
829 .num_resources = ARRAY_SIZE(lcdc_resources),
830};
831
832void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data)
833{
834 if (!data)
835 return;
836
837 at91_set_A_periph(AT91_PIN_PC1, 0); /* LCDHSYNC */
838 at91_set_A_periph(AT91_PIN_PC2, 0); /* LCDDOTCK */
839 at91_set_A_periph(AT91_PIN_PC3, 0); /* LCDDEN */
840 at91_set_B_periph(AT91_PIN_PB9, 0); /* LCDCC */
841 at91_set_A_periph(AT91_PIN_PC6, 0); /* LCDD2 */
842 at91_set_A_periph(AT91_PIN_PC7, 0); /* LCDD3 */
843 at91_set_A_periph(AT91_PIN_PC8, 0); /* LCDD4 */
844 at91_set_A_periph(AT91_PIN_PC9, 0); /* LCDD5 */
845 at91_set_A_periph(AT91_PIN_PC10, 0); /* LCDD6 */
846 at91_set_A_periph(AT91_PIN_PC11, 0); /* LCDD7 */
847 at91_set_A_periph(AT91_PIN_PC14, 0); /* LCDD10 */
848 at91_set_A_periph(AT91_PIN_PC15, 0); /* LCDD11 */
849 at91_set_A_periph(AT91_PIN_PC16, 0); /* LCDD12 */
850 at91_set_B_periph(AT91_PIN_PC12, 0); /* LCDD13 */
851 at91_set_A_periph(AT91_PIN_PC18, 0); /* LCDD14 */
852 at91_set_A_periph(AT91_PIN_PC19, 0); /* LCDD15 */
853 at91_set_A_periph(AT91_PIN_PC22, 0); /* LCDD18 */
854 at91_set_A_periph(AT91_PIN_PC23, 0); /* LCDD19 */
855 at91_set_A_periph(AT91_PIN_PC24, 0); /* LCDD20 */
856 at91_set_B_periph(AT91_PIN_PC17, 0); /* LCDD21 */
857 at91_set_A_periph(AT91_PIN_PC26, 0); /* LCDD22 */
858 at91_set_A_periph(AT91_PIN_PC27, 0); /* LCDD23 */
859
860 lcdc_data = *data;
861 platform_device_register(&at91_lcdc_device);
862}
863#else
864void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data) {}
865#endif
866
867
868/* --------------------------------------------------------------------
Andrew Victore2920802008-01-22 11:43:26 +0100869 * Image Sensor Interface
870 * -------------------------------------------------------------------- */
871
872#if defined(CONFIG_VIDEO_AT91_ISI) || defined(CONFIG_VIDEO_AT91_ISI_MODULE)
873
874struct resource isi_resources[] = {
875 [0] = {
876 .start = AT91SAM9263_BASE_ISI,
877 .end = AT91SAM9263_BASE_ISI + SZ_16K - 1,
878 .flags = IORESOURCE_MEM,
879 },
880 [1] = {
881 .start = AT91SAM9263_ID_ISI,
882 .end = AT91SAM9263_ID_ISI,
883 .flags = IORESOURCE_IRQ,
884 },
885};
886
887static struct platform_device at91sam9263_isi_device = {
888 .name = "at91_isi",
889 .id = -1,
890 .resource = isi_resources,
891 .num_resources = ARRAY_SIZE(isi_resources),
892};
893
Josh Wu45bb9e62011-10-22 15:17:39 +0800894void __init at91_add_device_isi(struct isi_platform_data *data,
895 bool use_pck_as_mck)
Andrew Victore2920802008-01-22 11:43:26 +0100896{
897 at91_set_A_periph(AT91_PIN_PE0, 0); /* ISI_D0 */
898 at91_set_A_periph(AT91_PIN_PE1, 0); /* ISI_D1 */
899 at91_set_A_periph(AT91_PIN_PE2, 0); /* ISI_D2 */
900 at91_set_A_periph(AT91_PIN_PE3, 0); /* ISI_D3 */
901 at91_set_A_periph(AT91_PIN_PE4, 0); /* ISI_D4 */
902 at91_set_A_periph(AT91_PIN_PE5, 0); /* ISI_D5 */
903 at91_set_A_periph(AT91_PIN_PE6, 0); /* ISI_D6 */
904 at91_set_A_periph(AT91_PIN_PE7, 0); /* ISI_D7 */
905 at91_set_A_periph(AT91_PIN_PE8, 0); /* ISI_PCK */
906 at91_set_A_periph(AT91_PIN_PE9, 0); /* ISI_HSYNC */
907 at91_set_A_periph(AT91_PIN_PE10, 0); /* ISI_VSYNC */
Andrew Victore2920802008-01-22 11:43:26 +0100908 at91_set_B_periph(AT91_PIN_PE12, 0); /* ISI_PD8 */
909 at91_set_B_periph(AT91_PIN_PE13, 0); /* ISI_PD9 */
910 at91_set_B_periph(AT91_PIN_PE14, 0); /* ISI_PD10 */
911 at91_set_B_periph(AT91_PIN_PE15, 0); /* ISI_PD11 */
Josh Wu45bb9e62011-10-22 15:17:39 +0800912
913 if (use_pck_as_mck) {
914 at91_set_B_periph(AT91_PIN_PE11, 0); /* ISI_MCK (PCK3) */
915
916 /* TODO: register the PCK for ISI_MCK and set its parent */
917 }
Andrew Victore2920802008-01-22 11:43:26 +0100918}
919#else
Josh Wu45bb9e62011-10-22 15:17:39 +0800920void __init at91_add_device_isi(struct isi_platform_data *data,
921 bool use_pck_as_mck) {}
Andrew Victore2920802008-01-22 11:43:26 +0100922#endif
923
924
925/* --------------------------------------------------------------------
Andrew Victore5f40bf2008-04-02 21:58:00 +0100926 * Timer/Counter block
927 * -------------------------------------------------------------------- */
928
929#ifdef CONFIG_ATMEL_TCLIB
930
931static struct resource tcb_resources[] = {
932 [0] = {
933 .start = AT91SAM9263_BASE_TCB0,
934 .end = AT91SAM9263_BASE_TCB0 + SZ_16K - 1,
935 .flags = IORESOURCE_MEM,
936 },
937 [1] = {
938 .start = AT91SAM9263_ID_TCB,
939 .end = AT91SAM9263_ID_TCB,
940 .flags = IORESOURCE_IRQ,
941 },
942};
943
944static struct platform_device at91sam9263_tcb_device = {
945 .name = "atmel_tcb",
946 .id = 0,
947 .resource = tcb_resources,
948 .num_resources = ARRAY_SIZE(tcb_resources),
949};
950
951static void __init at91_add_device_tc(void)
952{
Andrew Victore5f40bf2008-04-02 21:58:00 +0100953 platform_device_register(&at91sam9263_tcb_device);
954}
955#else
956static void __init at91_add_device_tc(void) { }
957#endif
958
959
960/* --------------------------------------------------------------------
Andrew Victor884f5a62008-01-23 09:11:13 +0100961 * RTT
962 * -------------------------------------------------------------------- */
963
964static struct resource rtt0_resources[] = {
965 {
Jean-Christophe PLAGNIOL-VILLARDeab5fd62011-09-18 10:12:00 +0800966 .start = AT91SAM9263_BASE_RTT0,
967 .end = AT91SAM9263_BASE_RTT0 + SZ_16 - 1,
Andrew Victor884f5a62008-01-23 09:11:13 +0100968 .flags = IORESOURCE_MEM,
969 }
970};
971
972static struct platform_device at91sam9263_rtt0_device = {
973 .name = "at91_rtt",
974 .id = 0,
975 .resource = rtt0_resources,
976 .num_resources = ARRAY_SIZE(rtt0_resources),
977};
978
979static struct resource rtt1_resources[] = {
980 {
Jean-Christophe PLAGNIOL-VILLARDeab5fd62011-09-18 10:12:00 +0800981 .start = AT91SAM9263_BASE_RTT1,
982 .end = AT91SAM9263_BASE_RTT1 + SZ_16 - 1,
Andrew Victor884f5a62008-01-23 09:11:13 +0100983 .flags = IORESOURCE_MEM,
984 }
985};
986
987static struct platform_device at91sam9263_rtt1_device = {
988 .name = "at91_rtt",
989 .id = 1,
990 .resource = rtt1_resources,
991 .num_resources = ARRAY_SIZE(rtt1_resources),
992};
993
994static void __init at91_add_device_rtt(void)
995{
996 platform_device_register(&at91sam9263_rtt0_device);
997 platform_device_register(&at91sam9263_rtt1_device);
998}
999
1000
1001/* --------------------------------------------------------------------
1002 * Watchdog
1003 * -------------------------------------------------------------------- */
1004
Andrew Victor2af29b72009-02-11 21:23:10 +01001005#if defined(CONFIG_AT91SAM9X_WATCHDOG) || defined(CONFIG_AT91SAM9X_WATCHDOG_MODULE)
Jean-Christophe PLAGNIOL-VILLARDc1c30a22011-11-02 01:43:31 +08001006static struct resource wdt_resources[] = {
1007 {
1008 .start = AT91SAM9263_BASE_WDT,
1009 .end = AT91SAM9263_BASE_WDT + SZ_16 - 1,
1010 .flags = IORESOURCE_MEM,
1011 }
1012};
1013
Andrew Victor884f5a62008-01-23 09:11:13 +01001014static struct platform_device at91sam9263_wdt_device = {
1015 .name = "at91_wdt",
1016 .id = -1,
Jean-Christophe PLAGNIOL-VILLARDc1c30a22011-11-02 01:43:31 +08001017 .resource = wdt_resources,
1018 .num_resources = ARRAY_SIZE(wdt_resources),
Andrew Victor884f5a62008-01-23 09:11:13 +01001019};
1020
1021static void __init at91_add_device_watchdog(void)
1022{
1023 platform_device_register(&at91sam9263_wdt_device);
1024}
1025#else
1026static void __init at91_add_device_watchdog(void) {}
1027#endif
1028
1029
1030/* --------------------------------------------------------------------
Andrew Victorbb1ad682008-09-18 19:42:37 +01001031 * PWM
1032 * --------------------------------------------------------------------*/
1033
1034#if defined(CONFIG_ATMEL_PWM)
1035static u32 pwm_mask;
1036
1037static struct resource pwm_resources[] = {
1038 [0] = {
1039 .start = AT91SAM9263_BASE_PWMC,
1040 .end = AT91SAM9263_BASE_PWMC + SZ_16K - 1,
1041 .flags = IORESOURCE_MEM,
1042 },
1043 [1] = {
1044 .start = AT91SAM9263_ID_PWMC,
1045 .end = AT91SAM9263_ID_PWMC,
1046 .flags = IORESOURCE_IRQ,
1047 },
1048};
1049
1050static struct platform_device at91sam9263_pwm0_device = {
1051 .name = "atmel_pwm",
1052 .id = -1,
1053 .dev = {
1054 .platform_data = &pwm_mask,
1055 },
1056 .resource = pwm_resources,
1057 .num_resources = ARRAY_SIZE(pwm_resources),
1058};
1059
1060void __init at91_add_device_pwm(u32 mask)
1061{
1062 if (mask & (1 << AT91_PWM0))
1063 at91_set_B_periph(AT91_PIN_PB7, 1); /* enable PWM0 */
1064
1065 if (mask & (1 << AT91_PWM1))
1066 at91_set_B_periph(AT91_PIN_PB8, 1); /* enable PWM1 */
1067
1068 if (mask & (1 << AT91_PWM2))
1069 at91_set_B_periph(AT91_PIN_PC29, 1); /* enable PWM2 */
1070
1071 if (mask & (1 << AT91_PWM3))
1072 at91_set_B_periph(AT91_PIN_PB29, 1); /* enable PWM3 */
1073
1074 pwm_mask = mask;
1075
1076 platform_device_register(&at91sam9263_pwm0_device);
1077}
1078#else
1079void __init at91_add_device_pwm(u32 mask) {}
1080#endif
1081
1082
1083/* --------------------------------------------------------------------
Andrew Victorbfbc3262008-01-23 09:18:06 +01001084 * SSC -- Synchronous Serial Controller
1085 * -------------------------------------------------------------------- */
1086
1087#if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
1088static u64 ssc0_dmamask = DMA_BIT_MASK(32);
1089
1090static struct resource ssc0_resources[] = {
1091 [0] = {
1092 .start = AT91SAM9263_BASE_SSC0,
1093 .end = AT91SAM9263_BASE_SSC0 + SZ_16K - 1,
1094 .flags = IORESOURCE_MEM,
1095 },
1096 [1] = {
1097 .start = AT91SAM9263_ID_SSC0,
1098 .end = AT91SAM9263_ID_SSC0,
1099 .flags = IORESOURCE_IRQ,
1100 },
1101};
1102
1103static struct platform_device at91sam9263_ssc0_device = {
1104 .name = "ssc",
1105 .id = 0,
1106 .dev = {
1107 .dma_mask = &ssc0_dmamask,
1108 .coherent_dma_mask = DMA_BIT_MASK(32),
1109 },
1110 .resource = ssc0_resources,
1111 .num_resources = ARRAY_SIZE(ssc0_resources),
1112};
1113
1114static inline void configure_ssc0_pins(unsigned pins)
1115{
1116 if (pins & ATMEL_SSC_TF)
1117 at91_set_B_periph(AT91_PIN_PB0, 1);
1118 if (pins & ATMEL_SSC_TK)
1119 at91_set_B_periph(AT91_PIN_PB1, 1);
1120 if (pins & ATMEL_SSC_TD)
1121 at91_set_B_periph(AT91_PIN_PB2, 1);
1122 if (pins & ATMEL_SSC_RD)
1123 at91_set_B_periph(AT91_PIN_PB3, 1);
1124 if (pins & ATMEL_SSC_RK)
1125 at91_set_B_periph(AT91_PIN_PB4, 1);
1126 if (pins & ATMEL_SSC_RF)
1127 at91_set_B_periph(AT91_PIN_PB5, 1);
1128}
1129
1130static u64 ssc1_dmamask = DMA_BIT_MASK(32);
1131
1132static struct resource ssc1_resources[] = {
1133 [0] = {
1134 .start = AT91SAM9263_BASE_SSC1,
1135 .end = AT91SAM9263_BASE_SSC1 + SZ_16K - 1,
1136 .flags = IORESOURCE_MEM,
1137 },
1138 [1] = {
1139 .start = AT91SAM9263_ID_SSC1,
1140 .end = AT91SAM9263_ID_SSC1,
1141 .flags = IORESOURCE_IRQ,
1142 },
1143};
1144
1145static struct platform_device at91sam9263_ssc1_device = {
1146 .name = "ssc",
1147 .id = 1,
1148 .dev = {
1149 .dma_mask = &ssc1_dmamask,
1150 .coherent_dma_mask = DMA_BIT_MASK(32),
1151 },
1152 .resource = ssc1_resources,
1153 .num_resources = ARRAY_SIZE(ssc1_resources),
1154};
1155
1156static inline void configure_ssc1_pins(unsigned pins)
1157{
1158 if (pins & ATMEL_SSC_TF)
1159 at91_set_A_periph(AT91_PIN_PB6, 1);
1160 if (pins & ATMEL_SSC_TK)
1161 at91_set_A_periph(AT91_PIN_PB7, 1);
1162 if (pins & ATMEL_SSC_TD)
1163 at91_set_A_periph(AT91_PIN_PB8, 1);
1164 if (pins & ATMEL_SSC_RD)
1165 at91_set_A_periph(AT91_PIN_PB9, 1);
1166 if (pins & ATMEL_SSC_RK)
1167 at91_set_A_periph(AT91_PIN_PB10, 1);
1168 if (pins & ATMEL_SSC_RF)
1169 at91_set_A_periph(AT91_PIN_PB11, 1);
1170}
1171
1172/*
Andrew Victorbfbc3262008-01-23 09:18:06 +01001173 * SSC controllers are accessed through library code, instead of any
1174 * kind of all-singing/all-dancing driver. For example one could be
1175 * used by a particular I2S audio codec's driver, while another one
1176 * on the same system might be used by a custom data capture driver.
1177 */
1178void __init at91_add_device_ssc(unsigned id, unsigned pins)
1179{
1180 struct platform_device *pdev;
1181
1182 /*
1183 * NOTE: caller is responsible for passing information matching
1184 * "pins" to whatever will be using each particular controller.
1185 */
1186 switch (id) {
1187 case AT91SAM9263_ID_SSC0:
1188 pdev = &at91sam9263_ssc0_device;
1189 configure_ssc0_pins(pins);
Andrew Victorbfbc3262008-01-23 09:18:06 +01001190 break;
1191 case AT91SAM9263_ID_SSC1:
1192 pdev = &at91sam9263_ssc1_device;
1193 configure_ssc1_pins(pins);
Andrew Victorbfbc3262008-01-23 09:18:06 +01001194 break;
1195 default:
1196 return;
1197 }
1198
1199 platform_device_register(pdev);
1200}
1201
1202#else
1203void __init at91_add_device_ssc(unsigned id, unsigned pins) {}
1204#endif
1205
1206
1207/* --------------------------------------------------------------------
Andrew Victorb2c65612007-02-08 09:42:40 +01001208 * UART
1209 * -------------------------------------------------------------------- */
1210
1211#if defined(CONFIG_SERIAL_ATMEL)
1212
1213static struct resource dbgu_resources[] = {
1214 [0] = {
Jean-Christophe PLAGNIOL-VILLARD13079a72011-11-02 01:43:31 +08001215 .start = AT91SAM9263_BASE_DBGU,
1216 .end = AT91SAM9263_BASE_DBGU + SZ_512 - 1,
Andrew Victorb2c65612007-02-08 09:42:40 +01001217 .flags = IORESOURCE_MEM,
1218 },
1219 [1] = {
1220 .start = AT91_ID_SYS,
1221 .end = AT91_ID_SYS,
1222 .flags = IORESOURCE_IRQ,
1223 },
1224};
1225
1226static struct atmel_uart_data dbgu_data = {
1227 .use_dma_tx = 0,
1228 .use_dma_rx = 0, /* DBGU not capable of receive DMA */
Andrew Victorb2c65612007-02-08 09:42:40 +01001229};
1230
Andrew Victorc6686ff2008-01-23 09:13:53 +01001231static u64 dbgu_dmamask = DMA_BIT_MASK(32);
1232
Andrew Victorb2c65612007-02-08 09:42:40 +01001233static struct platform_device at91sam9263_dbgu_device = {
1234 .name = "atmel_usart",
1235 .id = 0,
1236 .dev = {
Andrew Victorc6686ff2008-01-23 09:13:53 +01001237 .dma_mask = &dbgu_dmamask,
1238 .coherent_dma_mask = DMA_BIT_MASK(32),
1239 .platform_data = &dbgu_data,
Andrew Victorb2c65612007-02-08 09:42:40 +01001240 },
1241 .resource = dbgu_resources,
1242 .num_resources = ARRAY_SIZE(dbgu_resources),
1243};
1244
1245static inline void configure_dbgu_pins(void)
1246{
1247 at91_set_A_periph(AT91_PIN_PC30, 0); /* DRXD */
1248 at91_set_A_periph(AT91_PIN_PC31, 1); /* DTXD */
1249}
1250
1251static struct resource uart0_resources[] = {
1252 [0] = {
1253 .start = AT91SAM9263_BASE_US0,
1254 .end = AT91SAM9263_BASE_US0 + SZ_16K - 1,
1255 .flags = IORESOURCE_MEM,
1256 },
1257 [1] = {
1258 .start = AT91SAM9263_ID_US0,
1259 .end = AT91SAM9263_ID_US0,
1260 .flags = IORESOURCE_IRQ,
1261 },
1262};
1263
1264static struct atmel_uart_data uart0_data = {
1265 .use_dma_tx = 1,
1266 .use_dma_rx = 1,
1267};
1268
Andrew Victorc6686ff2008-01-23 09:13:53 +01001269static u64 uart0_dmamask = DMA_BIT_MASK(32);
1270
Andrew Victorb2c65612007-02-08 09:42:40 +01001271static struct platform_device at91sam9263_uart0_device = {
1272 .name = "atmel_usart",
1273 .id = 1,
1274 .dev = {
Andrew Victorc6686ff2008-01-23 09:13:53 +01001275 .dma_mask = &uart0_dmamask,
1276 .coherent_dma_mask = DMA_BIT_MASK(32),
1277 .platform_data = &uart0_data,
Andrew Victorb2c65612007-02-08 09:42:40 +01001278 },
1279 .resource = uart0_resources,
1280 .num_resources = ARRAY_SIZE(uart0_resources),
1281};
1282
Andrew Victorc8f385a2008-01-23 09:25:15 +01001283static inline void configure_usart0_pins(unsigned pins)
Andrew Victorb2c65612007-02-08 09:42:40 +01001284{
1285 at91_set_A_periph(AT91_PIN_PA26, 1); /* TXD0 */
1286 at91_set_A_periph(AT91_PIN_PA27, 0); /* RXD0 */
Andrew Victorc8f385a2008-01-23 09:25:15 +01001287
1288 if (pins & ATMEL_UART_RTS)
1289 at91_set_A_periph(AT91_PIN_PA28, 0); /* RTS0 */
1290 if (pins & ATMEL_UART_CTS)
1291 at91_set_A_periph(AT91_PIN_PA29, 0); /* CTS0 */
Andrew Victorb2c65612007-02-08 09:42:40 +01001292}
1293
1294static struct resource uart1_resources[] = {
1295 [0] = {
1296 .start = AT91SAM9263_BASE_US1,
1297 .end = AT91SAM9263_BASE_US1 + SZ_16K - 1,
1298 .flags = IORESOURCE_MEM,
1299 },
1300 [1] = {
1301 .start = AT91SAM9263_ID_US1,
1302 .end = AT91SAM9263_ID_US1,
1303 .flags = IORESOURCE_IRQ,
1304 },
1305};
1306
1307static struct atmel_uart_data uart1_data = {
1308 .use_dma_tx = 1,
1309 .use_dma_rx = 1,
1310};
1311
Andrew Victorc6686ff2008-01-23 09:13:53 +01001312static u64 uart1_dmamask = DMA_BIT_MASK(32);
1313
Andrew Victorb2c65612007-02-08 09:42:40 +01001314static struct platform_device at91sam9263_uart1_device = {
1315 .name = "atmel_usart",
1316 .id = 2,
1317 .dev = {
Andrew Victorc6686ff2008-01-23 09:13:53 +01001318 .dma_mask = &uart1_dmamask,
1319 .coherent_dma_mask = DMA_BIT_MASK(32),
1320 .platform_data = &uart1_data,
Andrew Victorb2c65612007-02-08 09:42:40 +01001321 },
1322 .resource = uart1_resources,
1323 .num_resources = ARRAY_SIZE(uart1_resources),
1324};
1325
Andrew Victorc8f385a2008-01-23 09:25:15 +01001326static inline void configure_usart1_pins(unsigned pins)
Andrew Victorb2c65612007-02-08 09:42:40 +01001327{
1328 at91_set_A_periph(AT91_PIN_PD0, 1); /* TXD1 */
1329 at91_set_A_periph(AT91_PIN_PD1, 0); /* RXD1 */
Andrew Victorc8f385a2008-01-23 09:25:15 +01001330
1331 if (pins & ATMEL_UART_RTS)
1332 at91_set_B_periph(AT91_PIN_PD7, 0); /* RTS1 */
1333 if (pins & ATMEL_UART_CTS)
1334 at91_set_B_periph(AT91_PIN_PD8, 0); /* CTS1 */
Andrew Victorb2c65612007-02-08 09:42:40 +01001335}
1336
1337static struct resource uart2_resources[] = {
1338 [0] = {
1339 .start = AT91SAM9263_BASE_US2,
1340 .end = AT91SAM9263_BASE_US2 + SZ_16K - 1,
1341 .flags = IORESOURCE_MEM,
1342 },
1343 [1] = {
1344 .start = AT91SAM9263_ID_US2,
1345 .end = AT91SAM9263_ID_US2,
1346 .flags = IORESOURCE_IRQ,
1347 },
1348};
1349
1350static struct atmel_uart_data uart2_data = {
1351 .use_dma_tx = 1,
1352 .use_dma_rx = 1,
1353};
1354
Andrew Victorc6686ff2008-01-23 09:13:53 +01001355static u64 uart2_dmamask = DMA_BIT_MASK(32);
1356
Andrew Victorb2c65612007-02-08 09:42:40 +01001357static struct platform_device at91sam9263_uart2_device = {
1358 .name = "atmel_usart",
1359 .id = 3,
1360 .dev = {
Andrew Victorc6686ff2008-01-23 09:13:53 +01001361 .dma_mask = &uart2_dmamask,
1362 .coherent_dma_mask = DMA_BIT_MASK(32),
1363 .platform_data = &uart2_data,
Andrew Victorb2c65612007-02-08 09:42:40 +01001364 },
1365 .resource = uart2_resources,
1366 .num_resources = ARRAY_SIZE(uart2_resources),
1367};
1368
Andrew Victorc8f385a2008-01-23 09:25:15 +01001369static inline void configure_usart2_pins(unsigned pins)
Andrew Victorb2c65612007-02-08 09:42:40 +01001370{
1371 at91_set_A_periph(AT91_PIN_PD2, 1); /* TXD2 */
1372 at91_set_A_periph(AT91_PIN_PD3, 0); /* RXD2 */
Andrew Victorc8f385a2008-01-23 09:25:15 +01001373
1374 if (pins & ATMEL_UART_RTS)
1375 at91_set_B_periph(AT91_PIN_PD5, 0); /* RTS2 */
1376 if (pins & ATMEL_UART_CTS)
1377 at91_set_B_periph(AT91_PIN_PD6, 0); /* CTS2 */
Andrew Victorb2c65612007-02-08 09:42:40 +01001378}
1379
Andrew Victor11aadac2008-04-15 21:16:38 +01001380static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
Andrew Victorb2c65612007-02-08 09:42:40 +01001381struct platform_device *atmel_default_console_device; /* the serial console device */
1382
Andrew Victorc8f385a2008-01-23 09:25:15 +01001383void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
1384{
1385 struct platform_device *pdev;
Jean-Christophe PLAGNIOL-VILLARD2b348e22011-04-10 14:10:05 +08001386 struct atmel_uart_data *pdata;
Andrew Victorc8f385a2008-01-23 09:25:15 +01001387
1388 switch (id) {
1389 case 0: /* DBGU */
1390 pdev = &at91sam9263_dbgu_device;
1391 configure_dbgu_pins();
Andrew Victorc8f385a2008-01-23 09:25:15 +01001392 break;
1393 case AT91SAM9263_ID_US0:
1394 pdev = &at91sam9263_uart0_device;
1395 configure_usart0_pins(pins);
Andrew Victorc8f385a2008-01-23 09:25:15 +01001396 break;
1397 case AT91SAM9263_ID_US1:
1398 pdev = &at91sam9263_uart1_device;
1399 configure_usart1_pins(pins);
Andrew Victorc8f385a2008-01-23 09:25:15 +01001400 break;
1401 case AT91SAM9263_ID_US2:
1402 pdev = &at91sam9263_uart2_device;
1403 configure_usart2_pins(pins);
Andrew Victorc8f385a2008-01-23 09:25:15 +01001404 break;
1405 default:
1406 return;
1407 }
Jean-Christophe PLAGNIOL-VILLARD2b348e22011-04-10 14:10:05 +08001408 pdata = pdev->dev.platform_data;
1409 pdata->num = portnr; /* update to mapped ID */
Andrew Victorc8f385a2008-01-23 09:25:15 +01001410
1411 if (portnr < ATMEL_MAX_UART)
1412 at91_uarts[portnr] = pdev;
1413}
1414
1415void __init at91_set_serial_console(unsigned portnr)
1416{
Jean-Christophe PLAGNIOL-VILLARDbd602992011-02-02 07:27:07 +01001417 if (portnr < ATMEL_MAX_UART) {
Andrew Victorc8f385a2008-01-23 09:25:15 +01001418 atmel_default_console_device = at91_uarts[portnr];
Jean-Christophe PLAGNIOL-VILLARD5c1f9662011-06-21 11:24:33 +08001419 at91sam9263_set_console_clock(at91_uarts[portnr]->id);
Jean-Christophe PLAGNIOL-VILLARDbd602992011-02-02 07:27:07 +01001420 }
Andrew Victorc8f385a2008-01-23 09:25:15 +01001421}
1422
Andrew Victorb2c65612007-02-08 09:42:40 +01001423void __init at91_add_device_serial(void)
1424{
1425 int i;
1426
1427 for (i = 0; i < ATMEL_MAX_UART; i++) {
1428 if (at91_uarts[i])
1429 platform_device_register(at91_uarts[i]);
1430 }
Andrew Victor11aadac2008-04-15 21:16:38 +01001431
1432 if (!atmel_default_console_device)
1433 printk(KERN_INFO "AT91: No default serial console defined.\n");
Andrew Victorb2c65612007-02-08 09:42:40 +01001434}
1435#else
Andrew Victorc8f385a2008-01-23 09:25:15 +01001436void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
1437void __init at91_set_serial_console(unsigned portnr) {}
Andrew Victorb2c65612007-02-08 09:42:40 +01001438void __init at91_add_device_serial(void) {}
1439#endif
1440
1441
1442/* -------------------------------------------------------------------- */
1443/*
1444 * These devices are always present and don't need any board-specific
1445 * setup.
1446 */
1447static int __init at91_add_standard_devices(void)
1448{
Andrew Victor884f5a62008-01-23 09:11:13 +01001449 at91_add_device_rtt();
1450 at91_add_device_watchdog();
Andrew Victore5f40bf2008-04-02 21:58:00 +01001451 at91_add_device_tc();
Andrew Victorb2c65612007-02-08 09:42:40 +01001452 return 0;
1453}
1454
1455arch_initcall(at91_add_standard_devices);