blob: a0282928e9c10bdbc67b385423b225f8e5315756 [file] [log] [blame]
Andrew Victor86ad76b2006-11-30 16:45:01 +01001/*
Andrew Victor9d041262007-02-05 11:42:07 +01002 * arch/arm/mach-at91/at91sam9260_devices.c
Andrew Victor86ad76b2006-11-30 16:45:01 +01003 *
4 * Copyright (C) 2006 Atmel
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 */
12#include <asm/mach/arch.h>
13#include <asm/mach/map.h>
14
Andrew Victorc6686ff2008-01-23 09:13:53 +010015#include <linux/dma-mapping.h>
Russell King2f8163b2011-07-26 10:53:52 +010016#include <linux/gpio.h>
Andrew Victor86ad76b2006-11-30 16:45:01 +010017#include <linux/platform_device.h>
Andrew Victorf230d3f2007-11-19 13:47:20 +010018#include <linux/i2c-gpio.h>
Andrew Victor86ad76b2006-11-30 16:45:01 +010019
Maxime Ripard67b5d7b2012-05-11 15:35:34 +020020#include <linux/platform_data/at91_adc.h>
21
Russell Kinga09e64f2008-08-05 16:14:15 +010022#include <mach/cpu.h>
23#include <mach/at91sam9260.h>
24#include <mach/at91sam9260_matrix.h>
Jean-Christophe PLAGNIOL-VILLARD4342d642011-11-27 23:15:50 +080025#include <mach/at91_matrix.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010026#include <mach/at91sam9_smc.h>
Maxime Ripard67b5d7b2012-05-11 15:35:34 +020027#include <mach/at91_adc.h>
Uwe Kleine-Königac11a1d2013-11-14 10:49:19 +010028#include <mach/hardware.h>
Andrew Victor86ad76b2006-11-30 16:45:01 +010029
Jean-Christophe PLAGNIOL-VILLARD43d2f532012-10-30 05:14:17 +080030#include "board.h"
Andrew Victor86ad76b2006-11-30 16:45:01 +010031#include "generic.h"
32
Andrew Victor86ad76b2006-11-30 16:45:01 +010033
34/* --------------------------------------------------------------------
35 * USB Host
36 * -------------------------------------------------------------------- */
37
38#if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
Andrew Victorc6686ff2008-01-23 09:13:53 +010039static u64 ohci_dmamask = DMA_BIT_MASK(32);
Andrew Victor86ad76b2006-11-30 16:45:01 +010040static struct at91_usbh_data usbh_data;
41
42static struct resource usbh_resources[] = {
43 [0] = {
44 .start = AT91SAM9260_UHP_BASE,
45 .end = AT91SAM9260_UHP_BASE + SZ_1M - 1,
46 .flags = IORESOURCE_MEM,
47 },
48 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +020049 .start = NR_IRQS_LEGACY + AT91SAM9260_ID_UHP,
50 .end = NR_IRQS_LEGACY + AT91SAM9260_ID_UHP,
Andrew Victor86ad76b2006-11-30 16:45:01 +010051 .flags = IORESOURCE_IRQ,
52 },
53};
54
55static struct platform_device at91_usbh_device = {
56 .name = "at91_ohci",
57 .id = -1,
58 .dev = {
59 .dma_mask = &ohci_dmamask,
Andrew Victorc6686ff2008-01-23 09:13:53 +010060 .coherent_dma_mask = DMA_BIT_MASK(32),
Andrew Victor86ad76b2006-11-30 16:45:01 +010061 .platform_data = &usbh_data,
62 },
63 .resource = usbh_resources,
64 .num_resources = ARRAY_SIZE(usbh_resources),
65};
66
67void __init at91_add_device_usbh(struct at91_usbh_data *data)
68{
Thomas Petazzoni1fcaea72011-07-13 11:29:18 +020069 int i;
70
Andrew Victor86ad76b2006-11-30 16:45:01 +010071 if (!data)
72 return;
73
Thomas Petazzoni1fcaea72011-07-13 11:29:18 +020074 /* Enable overcurrent notification */
75 for (i = 0; i < data->ports; i++) {
Johan Hovold641f3ce2012-11-14 12:18:17 +010076 if (gpio_is_valid(data->overcurrent_pin[i]))
Thomas Petazzoni1fcaea72011-07-13 11:29:18 +020077 at91_set_gpio_input(data->overcurrent_pin[i], 1);
78 }
79
Andrew Victor86ad76b2006-11-30 16:45:01 +010080 usbh_data = *data;
81 platform_device_register(&at91_usbh_device);
82}
83#else
84void __init at91_add_device_usbh(struct at91_usbh_data *data) {}
85#endif
86
87
88/* --------------------------------------------------------------------
89 * USB Device (Gadget)
90 * -------------------------------------------------------------------- */
91
Nicolas Ferree8c9dc92012-01-27 11:14:44 +010092#if defined(CONFIG_USB_AT91) || defined(CONFIG_USB_AT91_MODULE)
Andrew Victor86ad76b2006-11-30 16:45:01 +010093static struct at91_udc_data udc_data;
94
95static struct resource udc_resources[] = {
96 [0] = {
97 .start = AT91SAM9260_BASE_UDP,
98 .end = AT91SAM9260_BASE_UDP + SZ_16K - 1,
99 .flags = IORESOURCE_MEM,
100 },
101 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200102 .start = NR_IRQS_LEGACY + AT91SAM9260_ID_UDP,
103 .end = NR_IRQS_LEGACY + AT91SAM9260_ID_UDP,
Andrew Victor86ad76b2006-11-30 16:45:01 +0100104 .flags = IORESOURCE_IRQ,
105 },
106};
107
108static struct platform_device at91_udc_device = {
109 .name = "at91_udc",
110 .id = -1,
111 .dev = {
112 .platform_data = &udc_data,
113 },
114 .resource = udc_resources,
115 .num_resources = ARRAY_SIZE(udc_resources),
116};
117
118void __init at91_add_device_udc(struct at91_udc_data *data)
119{
120 if (!data)
121 return;
122
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +0800123 if (gpio_is_valid(data->vbus_pin)) {
Andrew Victor86ad76b2006-11-30 16:45:01 +0100124 at91_set_gpio_input(data->vbus_pin, 0);
125 at91_set_deglitch(data->vbus_pin, 1);
126 }
127
128 /* Pullup pin is handled internally by USB device peripheral */
129
130 udc_data = *data;
131 platform_device_register(&at91_udc_device);
132}
133#else
134void __init at91_add_device_udc(struct at91_udc_data *data) {}
135#endif
136
137
138/* --------------------------------------------------------------------
139 * Ethernet
140 * -------------------------------------------------------------------- */
141
142#if defined(CONFIG_MACB) || defined(CONFIG_MACB_MODULE)
Andrew Victorc6686ff2008-01-23 09:13:53 +0100143static u64 eth_dmamask = DMA_BIT_MASK(32);
Jamie Iles84e0cdb2011-03-08 20:17:06 +0000144static struct macb_platform_data eth_data;
Andrew Victor86ad76b2006-11-30 16:45:01 +0100145
146static struct resource eth_resources[] = {
147 [0] = {
148 .start = AT91SAM9260_BASE_EMAC,
149 .end = AT91SAM9260_BASE_EMAC + SZ_16K - 1,
150 .flags = IORESOURCE_MEM,
151 },
152 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200153 .start = NR_IRQS_LEGACY + AT91SAM9260_ID_EMAC,
154 .end = NR_IRQS_LEGACY + AT91SAM9260_ID_EMAC,
Andrew Victor86ad76b2006-11-30 16:45:01 +0100155 .flags = IORESOURCE_IRQ,
156 },
157};
158
159static struct platform_device at91sam9260_eth_device = {
160 .name = "macb",
161 .id = -1,
162 .dev = {
163 .dma_mask = &eth_dmamask,
Andrew Victorc6686ff2008-01-23 09:13:53 +0100164 .coherent_dma_mask = DMA_BIT_MASK(32),
Andrew Victor86ad76b2006-11-30 16:45:01 +0100165 .platform_data = &eth_data,
166 },
167 .resource = eth_resources,
168 .num_resources = ARRAY_SIZE(eth_resources),
169};
170
Jamie Iles84e0cdb2011-03-08 20:17:06 +0000171void __init at91_add_device_eth(struct macb_platform_data *data)
Andrew Victor86ad76b2006-11-30 16:45:01 +0100172{
173 if (!data)
174 return;
175
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +0800176 if (gpio_is_valid(data->phy_irq_pin)) {
Andrew Victor86ad76b2006-11-30 16:45:01 +0100177 at91_set_gpio_input(data->phy_irq_pin, 0);
178 at91_set_deglitch(data->phy_irq_pin, 1);
179 }
180
181 /* Pins used for MII and RMII */
182 at91_set_A_periph(AT91_PIN_PA19, 0); /* ETXCK_EREFCK */
183 at91_set_A_periph(AT91_PIN_PA17, 0); /* ERXDV */
184 at91_set_A_periph(AT91_PIN_PA14, 0); /* ERX0 */
185 at91_set_A_periph(AT91_PIN_PA15, 0); /* ERX1 */
186 at91_set_A_periph(AT91_PIN_PA18, 0); /* ERXER */
187 at91_set_A_periph(AT91_PIN_PA16, 0); /* ETXEN */
188 at91_set_A_periph(AT91_PIN_PA12, 0); /* ETX0 */
189 at91_set_A_periph(AT91_PIN_PA13, 0); /* ETX1 */
190 at91_set_A_periph(AT91_PIN_PA21, 0); /* EMDIO */
191 at91_set_A_periph(AT91_PIN_PA20, 0); /* EMDC */
192
193 if (!data->is_rmii) {
194 at91_set_B_periph(AT91_PIN_PA28, 0); /* ECRS */
195 at91_set_B_periph(AT91_PIN_PA29, 0); /* ECOL */
196 at91_set_B_periph(AT91_PIN_PA25, 0); /* ERX2 */
197 at91_set_B_periph(AT91_PIN_PA26, 0); /* ERX3 */
198 at91_set_B_periph(AT91_PIN_PA27, 0); /* ERXCK */
199 at91_set_B_periph(AT91_PIN_PA23, 0); /* ETX2 */
200 at91_set_B_periph(AT91_PIN_PA24, 0); /* ETX3 */
201 at91_set_B_periph(AT91_PIN_PA22, 0); /* ETXER */
202 }
203
204 eth_data = *data;
205 platform_device_register(&at91sam9260_eth_device);
206}
207#else
Jamie Iles84e0cdb2011-03-08 20:17:06 +0000208void __init at91_add_device_eth(struct macb_platform_data *data) {}
Andrew Victor86ad76b2006-11-30 16:45:01 +0100209#endif
210
211
212/* --------------------------------------------------------------------
Rob Emanuele864f38e2009-09-22 16:45:22 -0700213 * MMC / SD Slot for Atmel MCI Driver
214 * -------------------------------------------------------------------- */
215
Ludovic Desroches4cf33262012-05-21 12:23:27 +0200216#if IS_ENABLED(CONFIG_MMC_ATMELMCI)
Rob Emanuele864f38e2009-09-22 16:45:22 -0700217static u64 mmc_dmamask = DMA_BIT_MASK(32);
218static struct mci_platform_data mmc_data;
219
220static struct resource mmc_resources[] = {
221 [0] = {
222 .start = AT91SAM9260_BASE_MCI,
223 .end = AT91SAM9260_BASE_MCI + SZ_16K - 1,
224 .flags = IORESOURCE_MEM,
225 },
226 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200227 .start = NR_IRQS_LEGACY + AT91SAM9260_ID_MCI,
228 .end = NR_IRQS_LEGACY + AT91SAM9260_ID_MCI,
Rob Emanuele864f38e2009-09-22 16:45:22 -0700229 .flags = IORESOURCE_IRQ,
230 },
231};
232
233static struct platform_device at91sam9260_mmc_device = {
234 .name = "atmel_mci",
235 .id = -1,
236 .dev = {
237 .dma_mask = &mmc_dmamask,
238 .coherent_dma_mask = DMA_BIT_MASK(32),
239 .platform_data = &mmc_data,
240 },
241 .resource = mmc_resources,
242 .num_resources = ARRAY_SIZE(mmc_resources),
243};
244
245void __init at91_add_device_mci(short mmc_id, struct mci_platform_data *data)
246{
247 unsigned int i;
248 unsigned int slot_count = 0;
249
250 if (!data)
251 return;
252
Ludovic Desroches2c96a292011-08-11 15:25:41 +0000253 for (i = 0; i < ATMCI_MAX_NR_SLOTS; i++) {
Rob Emanuele864f38e2009-09-22 16:45:22 -0700254 if (data->slot[i].bus_width) {
255 /* input/irq */
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +0800256 if (gpio_is_valid(data->slot[i].detect_pin)) {
Rob Emanuele864f38e2009-09-22 16:45:22 -0700257 at91_set_gpio_input(data->slot[i].detect_pin, 1);
258 at91_set_deglitch(data->slot[i].detect_pin, 1);
259 }
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +0800260 if (gpio_is_valid(data->slot[i].wp_pin))
Rob Emanuele864f38e2009-09-22 16:45:22 -0700261 at91_set_gpio_input(data->slot[i].wp_pin, 1);
262
263 switch (i) {
264 case 0:
265 /* CMD */
266 at91_set_A_periph(AT91_PIN_PA7, 1);
267 /* DAT0, maybe DAT1..DAT3 */
268 at91_set_A_periph(AT91_PIN_PA6, 1);
269 if (data->slot[i].bus_width == 4) {
270 at91_set_A_periph(AT91_PIN_PA9, 1);
271 at91_set_A_periph(AT91_PIN_PA10, 1);
272 at91_set_A_periph(AT91_PIN_PA11, 1);
273 }
274 slot_count++;
275 break;
276 case 1:
277 /* CMD */
278 at91_set_B_periph(AT91_PIN_PA1, 1);
279 /* DAT0, maybe DAT1..DAT3 */
280 at91_set_B_periph(AT91_PIN_PA0, 1);
281 if (data->slot[i].bus_width == 4) {
282 at91_set_B_periph(AT91_PIN_PA5, 1);
283 at91_set_B_periph(AT91_PIN_PA4, 1);
284 at91_set_B_periph(AT91_PIN_PA3, 1);
285 }
286 slot_count++;
287 break;
288 default:
289 printk(KERN_ERR
290 "AT91: SD/MMC slot %d not available\n", i);
291 break;
292 }
293 }
294 }
295
296 if (slot_count) {
297 /* CLK */
298 at91_set_A_periph(AT91_PIN_PA8, 0);
299
300 mmc_data = *data;
301 platform_device_register(&at91sam9260_mmc_device);
302 }
303}
304#else
305void __init at91_add_device_mci(short mmc_id, struct mci_platform_data *data) {}
306#endif
307
Andrew Victor86ad76b2006-11-30 16:45:01 +0100308
309/* --------------------------------------------------------------------
310 * NAND / SmartMedia
311 * -------------------------------------------------------------------- */
312
Pieter du Preezf6ed6f72008-08-01 10:06:40 +0100313#if defined(CONFIG_MTD_NAND_ATMEL) || defined(CONFIG_MTD_NAND_ATMEL_MODULE)
Håvard Skinnemoen3c3796c2008-06-06 18:04:53 +0200314static struct atmel_nand_data nand_data;
Andrew Victor86ad76b2006-11-30 16:45:01 +0100315
316#define NAND_BASE AT91_CHIPSELECT_3
317
318static struct resource nand_resources[] = {
Andrew Victord7a24152008-04-02 21:44:44 +0100319 [0] = {
Andrew Victor86ad76b2006-11-30 16:45:01 +0100320 .start = NAND_BASE,
Andrew Victor22823552008-01-23 09:21:02 +0100321 .end = NAND_BASE + SZ_256M - 1,
Andrew Victor86ad76b2006-11-30 16:45:01 +0100322 .flags = IORESOURCE_MEM,
Andrew Victord7a24152008-04-02 21:44:44 +0100323 },
324 [1] = {
Jean-Christophe PLAGNIOL-VILLARDd28edd12011-09-18 09:31:56 +0800325 .start = AT91SAM9260_BASE_ECC,
326 .end = AT91SAM9260_BASE_ECC + SZ_512 - 1,
Andrew Victord7a24152008-04-02 21:44:44 +0100327 .flags = IORESOURCE_MEM,
Andrew Victor86ad76b2006-11-30 16:45:01 +0100328 }
329};
330
331static struct platform_device at91sam9260_nand_device = {
Håvard Skinnemoen3c3796c2008-06-06 18:04:53 +0200332 .name = "atmel_nand",
Andrew Victor86ad76b2006-11-30 16:45:01 +0100333 .id = -1,
334 .dev = {
335 .platform_data = &nand_data,
336 },
337 .resource = nand_resources,
338 .num_resources = ARRAY_SIZE(nand_resources),
339};
340
Håvard Skinnemoen3c3796c2008-06-06 18:04:53 +0200341void __init at91_add_device_nand(struct atmel_nand_data *data)
Andrew Victor86ad76b2006-11-30 16:45:01 +0100342{
Andrew Victor461d3b42008-10-06 20:01:00 +0100343 unsigned long csa;
Andrew Victor86ad76b2006-11-30 16:45:01 +0100344
345 if (!data)
346 return;
347
Jean-Christophe PLAGNIOL-VILLARD4342d642011-11-27 23:15:50 +0800348 csa = at91_matrix_read(AT91_MATRIX_EBICSA);
349 at91_matrix_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_CS3A_SMC_SMARTMEDIA);
Andrew Victor86ad76b2006-11-30 16:45:01 +0100350
Andrew Victor86ad76b2006-11-30 16:45:01 +0100351 /* enable pin */
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +0800352 if (gpio_is_valid(data->enable_pin))
Andrew Victor86ad76b2006-11-30 16:45:01 +0100353 at91_set_gpio_output(data->enable_pin, 1);
354
355 /* ready/busy pin */
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +0800356 if (gpio_is_valid(data->rdy_pin))
Andrew Victor86ad76b2006-11-30 16:45:01 +0100357 at91_set_gpio_input(data->rdy_pin, 1);
358
359 /* card detect pin */
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +0800360 if (gpio_is_valid(data->det_pin))
Andrew Victor86ad76b2006-11-30 16:45:01 +0100361 at91_set_gpio_input(data->det_pin, 1);
362
363 nand_data = *data;
364 platform_device_register(&at91sam9260_nand_device);
365}
366#else
Håvard Skinnemoen3c3796c2008-06-06 18:04:53 +0200367void __init at91_add_device_nand(struct atmel_nand_data *data) {}
Andrew Victor86ad76b2006-11-30 16:45:01 +0100368#endif
369
370
371/* --------------------------------------------------------------------
372 * TWI (i2c)
373 * -------------------------------------------------------------------- */
374
Andrew Victorf230d3f2007-11-19 13:47:20 +0100375/*
376 * Prefer the GPIO code since the TWI controller isn't robust
377 * (gets overruns and underruns under load) and can only issue
378 * repeated STARTs in one scenario (the driver doesn't yet handle them).
379 */
380
381#if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
382
383static struct i2c_gpio_platform_data pdata = {
384 .sda_pin = AT91_PIN_PA23,
385 .sda_is_open_drain = 1,
386 .scl_pin = AT91_PIN_PA24,
387 .scl_is_open_drain = 1,
388 .udelay = 2, /* ~100 kHz */
389};
390
391static struct platform_device at91sam9260_twi_device = {
392 .name = "i2c-gpio",
Bo Shen78404872012-10-15 17:30:27 +0800393 .id = 0,
Andrew Victorf230d3f2007-11-19 13:47:20 +0100394 .dev.platform_data = &pdata,
395};
396
397void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
398{
399 at91_set_GPIO_periph(AT91_PIN_PA23, 1); /* TWD (SDA) */
400 at91_set_multi_drive(AT91_PIN_PA23, 1);
401
402 at91_set_GPIO_periph(AT91_PIN_PA24, 1); /* TWCK (SCL) */
403 at91_set_multi_drive(AT91_PIN_PA24, 1);
404
405 i2c_register_board_info(0, devices, nr_devices);
406 platform_device_register(&at91sam9260_twi_device);
407}
408
409#elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
Andrew Victor86ad76b2006-11-30 16:45:01 +0100410
411static struct resource twi_resources[] = {
412 [0] = {
413 .start = AT91SAM9260_BASE_TWI,
414 .end = AT91SAM9260_BASE_TWI + SZ_16K - 1,
415 .flags = IORESOURCE_MEM,
416 },
417 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200418 .start = NR_IRQS_LEGACY + AT91SAM9260_ID_TWI,
419 .end = NR_IRQS_LEGACY + AT91SAM9260_ID_TWI,
Andrew Victor86ad76b2006-11-30 16:45:01 +0100420 .flags = IORESOURCE_IRQ,
421 },
422};
423
424static struct platform_device at91sam9260_twi_device = {
Bo Shen302090a2012-10-15 17:30:28 +0800425 .id = 0,
Andrew Victor86ad76b2006-11-30 16:45:01 +0100426 .resource = twi_resources,
427 .num_resources = ARRAY_SIZE(twi_resources),
428};
429
Andrew Victorf230d3f2007-11-19 13:47:20 +0100430void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
Andrew Victor86ad76b2006-11-30 16:45:01 +0100431{
Nikolaus Vossfac368a2011-11-08 11:49:46 +0100432 /* IP version is not the same on 9260 and g20 */
433 if (cpu_is_at91sam9g20()) {
434 at91sam9260_twi_device.name = "i2c-at91sam9g20";
435 } else {
436 at91sam9260_twi_device.name = "i2c-at91sam9260";
437 }
438
Andrew Victor86ad76b2006-11-30 16:45:01 +0100439 /* pins used for TWI interface */
440 at91_set_A_periph(AT91_PIN_PA23, 0); /* TWD */
441 at91_set_multi_drive(AT91_PIN_PA23, 1);
442
443 at91_set_A_periph(AT91_PIN_PA24, 0); /* TWCK */
444 at91_set_multi_drive(AT91_PIN_PA24, 1);
445
Andrew Victorf230d3f2007-11-19 13:47:20 +0100446 i2c_register_board_info(0, devices, nr_devices);
Andrew Victor86ad76b2006-11-30 16:45:01 +0100447 platform_device_register(&at91sam9260_twi_device);
448}
449#else
Andrew Victorf230d3f2007-11-19 13:47:20 +0100450void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {}
Andrew Victor86ad76b2006-11-30 16:45:01 +0100451#endif
452
453
454/* --------------------------------------------------------------------
455 * SPI
456 * -------------------------------------------------------------------- */
457
458#if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
Andrew Victorc6686ff2008-01-23 09:13:53 +0100459static u64 spi_dmamask = DMA_BIT_MASK(32);
Andrew Victor86ad76b2006-11-30 16:45:01 +0100460
461static struct resource spi0_resources[] = {
462 [0] = {
463 .start = AT91SAM9260_BASE_SPI0,
464 .end = AT91SAM9260_BASE_SPI0 + SZ_16K - 1,
465 .flags = IORESOURCE_MEM,
466 },
467 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200468 .start = NR_IRQS_LEGACY + AT91SAM9260_ID_SPI0,
469 .end = NR_IRQS_LEGACY + AT91SAM9260_ID_SPI0,
Andrew Victor86ad76b2006-11-30 16:45:01 +0100470 .flags = IORESOURCE_IRQ,
471 },
472};
473
474static struct platform_device at91sam9260_spi0_device = {
475 .name = "atmel_spi",
476 .id = 0,
477 .dev = {
478 .dma_mask = &spi_dmamask,
Andrew Victorc6686ff2008-01-23 09:13:53 +0100479 .coherent_dma_mask = DMA_BIT_MASK(32),
Andrew Victor86ad76b2006-11-30 16:45:01 +0100480 },
481 .resource = spi0_resources,
482 .num_resources = ARRAY_SIZE(spi0_resources),
483};
484
485static const unsigned spi0_standard_cs[4] = { AT91_PIN_PA3, AT91_PIN_PC11, AT91_PIN_PC16, AT91_PIN_PC17 };
486
487static struct resource spi1_resources[] = {
488 [0] = {
489 .start = AT91SAM9260_BASE_SPI1,
490 .end = AT91SAM9260_BASE_SPI1 + SZ_16K - 1,
491 .flags = IORESOURCE_MEM,
492 },
493 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200494 .start = NR_IRQS_LEGACY + AT91SAM9260_ID_SPI1,
495 .end = NR_IRQS_LEGACY + AT91SAM9260_ID_SPI1,
Andrew Victor86ad76b2006-11-30 16:45:01 +0100496 .flags = IORESOURCE_IRQ,
497 },
498};
499
500static struct platform_device at91sam9260_spi1_device = {
501 .name = "atmel_spi",
502 .id = 1,
503 .dev = {
504 .dma_mask = &spi_dmamask,
Andrew Victorc6686ff2008-01-23 09:13:53 +0100505 .coherent_dma_mask = DMA_BIT_MASK(32),
Andrew Victor86ad76b2006-11-30 16:45:01 +0100506 },
507 .resource = spi1_resources,
508 .num_resources = ARRAY_SIZE(spi1_resources),
509};
510
511static const unsigned spi1_standard_cs[4] = { AT91_PIN_PB3, AT91_PIN_PC5, AT91_PIN_PC4, AT91_PIN_PC3 };
512
513void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
514{
515 int i;
516 unsigned long cs_pin;
517 short enable_spi0 = 0;
518 short enable_spi1 = 0;
519
520 /* Choose SPI chip-selects */
521 for (i = 0; i < nr_devices; i++) {
522 if (devices[i].controller_data)
523 cs_pin = (unsigned long) devices[i].controller_data;
524 else if (devices[i].bus_num == 0)
525 cs_pin = spi0_standard_cs[devices[i].chip_select];
526 else
527 cs_pin = spi1_standard_cs[devices[i].chip_select];
528
Nicolas Ferre0c2c1f62012-03-28 11:58:58 +0200529 if (!gpio_is_valid(cs_pin))
530 continue;
531
Andrew Victor86ad76b2006-11-30 16:45:01 +0100532 if (devices[i].bus_num == 0)
533 enable_spi0 = 1;
534 else
535 enable_spi1 = 1;
536
537 /* enable chip-select pin */
538 at91_set_gpio_output(cs_pin, 1);
539
540 /* pass chip-select pin to driver */
541 devices[i].controller_data = (void *) cs_pin;
542 }
543
544 spi_register_board_info(devices, nr_devices);
545
546 /* Configure SPI bus(es) */
547 if (enable_spi0) {
548 at91_set_A_periph(AT91_PIN_PA0, 0); /* SPI0_MISO */
549 at91_set_A_periph(AT91_PIN_PA1, 0); /* SPI0_MOSI */
550 at91_set_A_periph(AT91_PIN_PA2, 0); /* SPI1_SPCK */
551
Andrew Victor86ad76b2006-11-30 16:45:01 +0100552 platform_device_register(&at91sam9260_spi0_device);
553 }
554 if (enable_spi1) {
555 at91_set_A_periph(AT91_PIN_PB0, 0); /* SPI1_MISO */
556 at91_set_A_periph(AT91_PIN_PB1, 0); /* SPI1_MOSI */
557 at91_set_A_periph(AT91_PIN_PB2, 0); /* SPI1_SPCK */
558
Andrew Victor86ad76b2006-11-30 16:45:01 +0100559 platform_device_register(&at91sam9260_spi1_device);
560 }
561}
562#else
563void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
564#endif
565
566
567/* --------------------------------------------------------------------
Andrew Victore5f40bf2008-04-02 21:58:00 +0100568 * Timer/Counter blocks
569 * -------------------------------------------------------------------- */
570
571#ifdef CONFIG_ATMEL_TCLIB
572
573static struct resource tcb0_resources[] = {
574 [0] = {
575 .start = AT91SAM9260_BASE_TCB0,
Nicolas Ferre29831292012-01-18 16:56:36 +0100576 .end = AT91SAM9260_BASE_TCB0 + SZ_256 - 1,
Andrew Victore5f40bf2008-04-02 21:58:00 +0100577 .flags = IORESOURCE_MEM,
578 },
579 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200580 .start = NR_IRQS_LEGACY + AT91SAM9260_ID_TC0,
581 .end = NR_IRQS_LEGACY + AT91SAM9260_ID_TC0,
Andrew Victore5f40bf2008-04-02 21:58:00 +0100582 .flags = IORESOURCE_IRQ,
583 },
584 [2] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200585 .start = NR_IRQS_LEGACY + AT91SAM9260_ID_TC1,
586 .end = NR_IRQS_LEGACY + AT91SAM9260_ID_TC1,
Andrew Victore5f40bf2008-04-02 21:58:00 +0100587 .flags = IORESOURCE_IRQ,
588 },
589 [3] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200590 .start = NR_IRQS_LEGACY + AT91SAM9260_ID_TC2,
591 .end = NR_IRQS_LEGACY + AT91SAM9260_ID_TC2,
Andrew Victore5f40bf2008-04-02 21:58:00 +0100592 .flags = IORESOURCE_IRQ,
593 },
594};
595
596static struct platform_device at91sam9260_tcb0_device = {
597 .name = "atmel_tcb",
598 .id = 0,
599 .resource = tcb0_resources,
600 .num_resources = ARRAY_SIZE(tcb0_resources),
601};
602
603static struct resource tcb1_resources[] = {
604 [0] = {
605 .start = AT91SAM9260_BASE_TCB1,
Nicolas Ferre29831292012-01-18 16:56:36 +0100606 .end = AT91SAM9260_BASE_TCB1 + SZ_256 - 1,
Andrew Victore5f40bf2008-04-02 21:58:00 +0100607 .flags = IORESOURCE_MEM,
608 },
609 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200610 .start = NR_IRQS_LEGACY + AT91SAM9260_ID_TC3,
611 .end = NR_IRQS_LEGACY + AT91SAM9260_ID_TC3,
Andrew Victore5f40bf2008-04-02 21:58:00 +0100612 .flags = IORESOURCE_IRQ,
613 },
614 [2] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200615 .start = NR_IRQS_LEGACY + AT91SAM9260_ID_TC4,
616 .end = NR_IRQS_LEGACY + AT91SAM9260_ID_TC4,
Andrew Victore5f40bf2008-04-02 21:58:00 +0100617 .flags = IORESOURCE_IRQ,
618 },
619 [3] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200620 .start = NR_IRQS_LEGACY + AT91SAM9260_ID_TC5,
621 .end = NR_IRQS_LEGACY + AT91SAM9260_ID_TC5,
Andrew Victore5f40bf2008-04-02 21:58:00 +0100622 .flags = IORESOURCE_IRQ,
623 },
624};
625
626static struct platform_device at91sam9260_tcb1_device = {
627 .name = "atmel_tcb",
628 .id = 1,
629 .resource = tcb1_resources,
630 .num_resources = ARRAY_SIZE(tcb1_resources),
631};
632
633static void __init at91_add_device_tc(void)
634{
Andrew Victore5f40bf2008-04-02 21:58:00 +0100635 platform_device_register(&at91sam9260_tcb0_device);
Andrew Victore5f40bf2008-04-02 21:58:00 +0100636 platform_device_register(&at91sam9260_tcb1_device);
637}
638#else
639static void __init at91_add_device_tc(void) { }
640#endif
641
642
643/* --------------------------------------------------------------------
Andrew Victor884f5a62008-01-23 09:11:13 +0100644 * RTT
645 * -------------------------------------------------------------------- */
646
647static struct resource rtt_resources[] = {
648 {
Jean-Christophe PLAGNIOL-VILLARDeab5fd62011-09-18 10:12:00 +0800649 .start = AT91SAM9260_BASE_RTT,
650 .end = AT91SAM9260_BASE_RTT + SZ_16 - 1,
Andrew Victor884f5a62008-01-23 09:11:13 +0100651 .flags = IORESOURCE_MEM,
Jean-Christophe PLAGNIOL-VILLARDb3af8b42012-02-15 21:24:46 +0800652 }, {
653 .flags = IORESOURCE_MEM,
Ludovic Desrochese402af62012-08-14 11:19:22 +0200654 }, {
655 .flags = IORESOURCE_IRQ,
Jean-Christophe PLAGNIOL-VILLARDb3af8b42012-02-15 21:24:46 +0800656 },
Andrew Victor884f5a62008-01-23 09:11:13 +0100657};
658
659static struct platform_device at91sam9260_rtt_device = {
660 .name = "at91_rtt",
Andrew Victor4fd92122008-04-02 21:55:19 +0100661 .id = 0,
Andrew Victor884f5a62008-01-23 09:11:13 +0100662 .resource = rtt_resources,
Andrew Victor884f5a62008-01-23 09:11:13 +0100663};
664
Jean-Christophe PLAGNIOL-VILLARD205056a2012-02-15 20:51:37 +0800665
666#if IS_ENABLED(CONFIG_RTC_DRV_AT91SAM9)
667static void __init at91_add_device_rtt_rtc(void)
668{
669 at91sam9260_rtt_device.name = "rtc-at91sam9";
Jean-Christophe PLAGNIOL-VILLARDb3af8b42012-02-15 21:24:46 +0800670 /*
671 * The second resource is needed:
672 * GPBR will serve as the storage for RTC time offset
673 */
Ludovic Desrochese402af62012-08-14 11:19:22 +0200674 at91sam9260_rtt_device.num_resources = 3;
Jean-Christophe PLAGNIOL-VILLARDb3af8b42012-02-15 21:24:46 +0800675 rtt_resources[1].start = AT91SAM9260_BASE_GPBR +
676 4 * CONFIG_RTC_DRV_AT91SAM9_GPBR;
677 rtt_resources[1].end = rtt_resources[1].start + 3;
Ludovic Desrochese402af62012-08-14 11:19:22 +0200678 rtt_resources[2].start = NR_IRQS_LEGACY + AT91_ID_SYS;
679 rtt_resources[2].end = NR_IRQS_LEGACY + AT91_ID_SYS;
Jean-Christophe PLAGNIOL-VILLARD205056a2012-02-15 20:51:37 +0800680}
681#else
Jean-Christophe PLAGNIOL-VILLARDb3af8b42012-02-15 21:24:46 +0800682static void __init at91_add_device_rtt_rtc(void)
683{
684 /* Only one resource is needed: RTT not used as RTC */
685 at91sam9260_rtt_device.num_resources = 1;
686}
Jean-Christophe PLAGNIOL-VILLARD205056a2012-02-15 20:51:37 +0800687#endif
688
Andrew Victor884f5a62008-01-23 09:11:13 +0100689static void __init at91_add_device_rtt(void)
690{
Jean-Christophe PLAGNIOL-VILLARD205056a2012-02-15 20:51:37 +0800691 at91_add_device_rtt_rtc();
Andrew Victor884f5a62008-01-23 09:11:13 +0100692 platform_device_register(&at91sam9260_rtt_device);
693}
694
695
696/* --------------------------------------------------------------------
697 * Watchdog
698 * -------------------------------------------------------------------- */
699
Andrew Victor2af29b72009-02-11 21:23:10 +0100700#if defined(CONFIG_AT91SAM9X_WATCHDOG) || defined(CONFIG_AT91SAM9X_WATCHDOG_MODULE)
Jean-Christophe PLAGNIOL-VILLARDc1c30a22011-11-02 01:43:31 +0800701static struct resource wdt_resources[] = {
702 {
703 .start = AT91SAM9260_BASE_WDT,
704 .end = AT91SAM9260_BASE_WDT + SZ_16 - 1,
705 .flags = IORESOURCE_MEM,
706 }
707};
708
Andrew Victor884f5a62008-01-23 09:11:13 +0100709static struct platform_device at91sam9260_wdt_device = {
710 .name = "at91_wdt",
711 .id = -1,
Jean-Christophe PLAGNIOL-VILLARDc1c30a22011-11-02 01:43:31 +0800712 .resource = wdt_resources,
713 .num_resources = ARRAY_SIZE(wdt_resources),
Andrew Victor884f5a62008-01-23 09:11:13 +0100714};
715
716static void __init at91_add_device_watchdog(void)
717{
718 platform_device_register(&at91sam9260_wdt_device);
719}
720#else
721static void __init at91_add_device_watchdog(void) {}
722#endif
723
724
725/* --------------------------------------------------------------------
Andrew Victorbfbc3262008-01-23 09:18:06 +0100726 * SSC -- Synchronous Serial Controller
727 * -------------------------------------------------------------------- */
728
729#if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
730static u64 ssc_dmamask = DMA_BIT_MASK(32);
731
732static struct resource ssc_resources[] = {
733 [0] = {
734 .start = AT91SAM9260_BASE_SSC,
735 .end = AT91SAM9260_BASE_SSC + SZ_16K - 1,
736 .flags = IORESOURCE_MEM,
737 },
738 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200739 .start = NR_IRQS_LEGACY + AT91SAM9260_ID_SSC,
740 .end = NR_IRQS_LEGACY + AT91SAM9260_ID_SSC,
Andrew Victorbfbc3262008-01-23 09:18:06 +0100741 .flags = IORESOURCE_IRQ,
742 },
743};
744
745static struct platform_device at91sam9260_ssc_device = {
Bo Shen636036d22012-11-06 13:57:51 +0800746 .name = "at91rm9200_ssc",
Andrew Victorbfbc3262008-01-23 09:18:06 +0100747 .id = 0,
748 .dev = {
749 .dma_mask = &ssc_dmamask,
750 .coherent_dma_mask = DMA_BIT_MASK(32),
751 },
752 .resource = ssc_resources,
753 .num_resources = ARRAY_SIZE(ssc_resources),
754};
755
756static inline void configure_ssc_pins(unsigned pins)
757{
758 if (pins & ATMEL_SSC_TF)
759 at91_set_A_periph(AT91_PIN_PB17, 1);
760 if (pins & ATMEL_SSC_TK)
761 at91_set_A_periph(AT91_PIN_PB16, 1);
762 if (pins & ATMEL_SSC_TD)
763 at91_set_A_periph(AT91_PIN_PB18, 1);
764 if (pins & ATMEL_SSC_RD)
765 at91_set_A_periph(AT91_PIN_PB19, 1);
766 if (pins & ATMEL_SSC_RK)
767 at91_set_A_periph(AT91_PIN_PB20, 1);
768 if (pins & ATMEL_SSC_RF)
769 at91_set_A_periph(AT91_PIN_PB21, 1);
770}
771
772/*
773 * SSC controllers are accessed through library code, instead of any
774 * kind of all-singing/all-dancing driver. For example one could be
775 * used by a particular I2S audio codec's driver, while another one
776 * on the same system might be used by a custom data capture driver.
777 */
778void __init at91_add_device_ssc(unsigned id, unsigned pins)
779{
780 struct platform_device *pdev;
781
782 /*
783 * NOTE: caller is responsible for passing information matching
784 * "pins" to whatever will be using each particular controller.
785 */
786 switch (id) {
787 case AT91SAM9260_ID_SSC:
788 pdev = &at91sam9260_ssc_device;
789 configure_ssc_pins(pins);
Andrew Victorbfbc3262008-01-23 09:18:06 +0100790 break;
791 default:
792 return;
793 }
794
795 platform_device_register(pdev);
796}
797
798#else
799void __init at91_add_device_ssc(unsigned id, unsigned pins) {}
800#endif
801
802
803/* --------------------------------------------------------------------
Andrew Victor86ad76b2006-11-30 16:45:01 +0100804 * UART
805 * -------------------------------------------------------------------- */
806#if defined(CONFIG_SERIAL_ATMEL)
807static struct resource dbgu_resources[] = {
808 [0] = {
Jean-Christophe PLAGNIOL-VILLARD13079a72011-11-02 01:43:31 +0800809 .start = AT91SAM9260_BASE_DBGU,
810 .end = AT91SAM9260_BASE_DBGU + SZ_512 - 1,
Andrew Victor86ad76b2006-11-30 16:45:01 +0100811 .flags = IORESOURCE_MEM,
812 },
813 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200814 .start = NR_IRQS_LEGACY + AT91_ID_SYS,
815 .end = NR_IRQS_LEGACY + AT91_ID_SYS,
Andrew Victor86ad76b2006-11-30 16:45:01 +0100816 .flags = IORESOURCE_IRQ,
817 },
818};
819
820static struct atmel_uart_data dbgu_data = {
821 .use_dma_tx = 0,
822 .use_dma_rx = 0, /* DBGU not capable of receive DMA */
Linus Walleij354e57f2013-11-07 10:25:55 +0100823 .rts_gpio = -EINVAL,
Andrew Victor86ad76b2006-11-30 16:45:01 +0100824};
825
Andrew Victorc6686ff2008-01-23 09:13:53 +0100826static u64 dbgu_dmamask = DMA_BIT_MASK(32);
827
Andrew Victor86ad76b2006-11-30 16:45:01 +0100828static struct platform_device at91sam9260_dbgu_device = {
829 .name = "atmel_usart",
830 .id = 0,
831 .dev = {
Andrew Victorc6686ff2008-01-23 09:13:53 +0100832 .dma_mask = &dbgu_dmamask,
833 .coherent_dma_mask = DMA_BIT_MASK(32),
834 .platform_data = &dbgu_data,
Andrew Victor86ad76b2006-11-30 16:45:01 +0100835 },
836 .resource = dbgu_resources,
837 .num_resources = ARRAY_SIZE(dbgu_resources),
838};
839
840static inline void configure_dbgu_pins(void)
841{
842 at91_set_A_periph(AT91_PIN_PB14, 0); /* DRXD */
843 at91_set_A_periph(AT91_PIN_PB15, 1); /* DTXD */
844}
845
846static struct resource uart0_resources[] = {
847 [0] = {
848 .start = AT91SAM9260_BASE_US0,
849 .end = AT91SAM9260_BASE_US0 + SZ_16K - 1,
850 .flags = IORESOURCE_MEM,
851 },
852 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200853 .start = NR_IRQS_LEGACY + AT91SAM9260_ID_US0,
854 .end = NR_IRQS_LEGACY + AT91SAM9260_ID_US0,
Andrew Victor86ad76b2006-11-30 16:45:01 +0100855 .flags = IORESOURCE_IRQ,
856 },
857};
858
859static struct atmel_uart_data uart0_data = {
860 .use_dma_tx = 1,
861 .use_dma_rx = 1,
Linus Walleij354e57f2013-11-07 10:25:55 +0100862 .rts_gpio = -EINVAL,
Andrew Victor86ad76b2006-11-30 16:45:01 +0100863};
864
Andrew Victorc6686ff2008-01-23 09:13:53 +0100865static u64 uart0_dmamask = DMA_BIT_MASK(32);
866
Andrew Victor86ad76b2006-11-30 16:45:01 +0100867static struct platform_device at91sam9260_uart0_device = {
868 .name = "atmel_usart",
869 .id = 1,
870 .dev = {
Andrew Victorc6686ff2008-01-23 09:13:53 +0100871 .dma_mask = &uart0_dmamask,
872 .coherent_dma_mask = DMA_BIT_MASK(32),
873 .platform_data = &uart0_data,
Andrew Victor86ad76b2006-11-30 16:45:01 +0100874 },
875 .resource = uart0_resources,
876 .num_resources = ARRAY_SIZE(uart0_resources),
877};
878
Andrew Victorc8f385a2008-01-23 09:25:15 +0100879static inline void configure_usart0_pins(unsigned pins)
Andrew Victor86ad76b2006-11-30 16:45:01 +0100880{
881 at91_set_A_periph(AT91_PIN_PB4, 1); /* TXD0 */
882 at91_set_A_periph(AT91_PIN_PB5, 0); /* RXD0 */
Andrew Victorc8f385a2008-01-23 09:25:15 +0100883
884 if (pins & ATMEL_UART_RTS)
885 at91_set_A_periph(AT91_PIN_PB26, 0); /* RTS0 */
886 if (pins & ATMEL_UART_CTS)
887 at91_set_A_periph(AT91_PIN_PB27, 0); /* CTS0 */
888 if (pins & ATMEL_UART_DTR)
889 at91_set_A_periph(AT91_PIN_PB24, 0); /* DTR0 */
890 if (pins & ATMEL_UART_DSR)
891 at91_set_A_periph(AT91_PIN_PB22, 0); /* DSR0 */
892 if (pins & ATMEL_UART_DCD)
893 at91_set_A_periph(AT91_PIN_PB23, 0); /* DCD0 */
894 if (pins & ATMEL_UART_RI)
895 at91_set_A_periph(AT91_PIN_PB25, 0); /* RI0 */
Andrew Victor86ad76b2006-11-30 16:45:01 +0100896}
897
898static struct resource uart1_resources[] = {
899 [0] = {
900 .start = AT91SAM9260_BASE_US1,
901 .end = AT91SAM9260_BASE_US1 + SZ_16K - 1,
902 .flags = IORESOURCE_MEM,
903 },
904 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200905 .start = NR_IRQS_LEGACY + AT91SAM9260_ID_US1,
906 .end = NR_IRQS_LEGACY + AT91SAM9260_ID_US1,
Andrew Victor86ad76b2006-11-30 16:45:01 +0100907 .flags = IORESOURCE_IRQ,
908 },
909};
910
911static struct atmel_uart_data uart1_data = {
912 .use_dma_tx = 1,
913 .use_dma_rx = 1,
Linus Walleij354e57f2013-11-07 10:25:55 +0100914 .rts_gpio = -EINVAL,
Andrew Victor86ad76b2006-11-30 16:45:01 +0100915};
916
Andrew Victorc6686ff2008-01-23 09:13:53 +0100917static u64 uart1_dmamask = DMA_BIT_MASK(32);
918
Andrew Victor86ad76b2006-11-30 16:45:01 +0100919static struct platform_device at91sam9260_uart1_device = {
920 .name = "atmel_usart",
921 .id = 2,
922 .dev = {
Andrew Victorc6686ff2008-01-23 09:13:53 +0100923 .dma_mask = &uart1_dmamask,
924 .coherent_dma_mask = DMA_BIT_MASK(32),
925 .platform_data = &uart1_data,
Andrew Victor86ad76b2006-11-30 16:45:01 +0100926 },
927 .resource = uart1_resources,
928 .num_resources = ARRAY_SIZE(uart1_resources),
929};
930
Andrew Victorc8f385a2008-01-23 09:25:15 +0100931static inline void configure_usart1_pins(unsigned pins)
Andrew Victor86ad76b2006-11-30 16:45:01 +0100932{
933 at91_set_A_periph(AT91_PIN_PB6, 1); /* TXD1 */
934 at91_set_A_periph(AT91_PIN_PB7, 0); /* RXD1 */
Andrew Victorc8f385a2008-01-23 09:25:15 +0100935
936 if (pins & ATMEL_UART_RTS)
937 at91_set_A_periph(AT91_PIN_PB28, 0); /* RTS1 */
938 if (pins & ATMEL_UART_CTS)
939 at91_set_A_periph(AT91_PIN_PB29, 0); /* CTS1 */
Andrew Victor86ad76b2006-11-30 16:45:01 +0100940}
941
942static struct resource uart2_resources[] = {
943 [0] = {
944 .start = AT91SAM9260_BASE_US2,
945 .end = AT91SAM9260_BASE_US2 + SZ_16K - 1,
946 .flags = IORESOURCE_MEM,
947 },
948 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200949 .start = NR_IRQS_LEGACY + AT91SAM9260_ID_US2,
950 .end = NR_IRQS_LEGACY + AT91SAM9260_ID_US2,
Andrew Victor86ad76b2006-11-30 16:45:01 +0100951 .flags = IORESOURCE_IRQ,
952 },
953};
954
955static struct atmel_uart_data uart2_data = {
956 .use_dma_tx = 1,
957 .use_dma_rx = 1,
Linus Walleij354e57f2013-11-07 10:25:55 +0100958 .rts_gpio = -EINVAL,
Andrew Victor86ad76b2006-11-30 16:45:01 +0100959};
960
Andrew Victorc6686ff2008-01-23 09:13:53 +0100961static u64 uart2_dmamask = DMA_BIT_MASK(32);
962
Andrew Victor86ad76b2006-11-30 16:45:01 +0100963static struct platform_device at91sam9260_uart2_device = {
964 .name = "atmel_usart",
965 .id = 3,
966 .dev = {
Andrew Victorc6686ff2008-01-23 09:13:53 +0100967 .dma_mask = &uart2_dmamask,
968 .coherent_dma_mask = DMA_BIT_MASK(32),
969 .platform_data = &uart2_data,
Andrew Victor86ad76b2006-11-30 16:45:01 +0100970 },
971 .resource = uart2_resources,
972 .num_resources = ARRAY_SIZE(uart2_resources),
973};
974
Andrew Victorc8f385a2008-01-23 09:25:15 +0100975static inline void configure_usart2_pins(unsigned pins)
Andrew Victor86ad76b2006-11-30 16:45:01 +0100976{
977 at91_set_A_periph(AT91_PIN_PB8, 1); /* TXD2 */
978 at91_set_A_periph(AT91_PIN_PB9, 0); /* RXD2 */
Andrew Victorc8f385a2008-01-23 09:25:15 +0100979
980 if (pins & ATMEL_UART_RTS)
981 at91_set_A_periph(AT91_PIN_PA4, 0); /* RTS2 */
982 if (pins & ATMEL_UART_CTS)
983 at91_set_A_periph(AT91_PIN_PA5, 0); /* CTS2 */
Andrew Victor86ad76b2006-11-30 16:45:01 +0100984}
985
986static struct resource uart3_resources[] = {
987 [0] = {
988 .start = AT91SAM9260_BASE_US3,
989 .end = AT91SAM9260_BASE_US3 + SZ_16K - 1,
990 .flags = IORESOURCE_MEM,
991 },
992 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200993 .start = NR_IRQS_LEGACY + AT91SAM9260_ID_US3,
994 .end = NR_IRQS_LEGACY + AT91SAM9260_ID_US3,
Andrew Victor86ad76b2006-11-30 16:45:01 +0100995 .flags = IORESOURCE_IRQ,
996 },
997};
998
999static struct atmel_uart_data uart3_data = {
1000 .use_dma_tx = 1,
1001 .use_dma_rx = 1,
Linus Walleij354e57f2013-11-07 10:25:55 +01001002 .rts_gpio = -EINVAL,
Andrew Victor86ad76b2006-11-30 16:45:01 +01001003};
1004
Andrew Victorc6686ff2008-01-23 09:13:53 +01001005static u64 uart3_dmamask = DMA_BIT_MASK(32);
1006
Andrew Victor86ad76b2006-11-30 16:45:01 +01001007static struct platform_device at91sam9260_uart3_device = {
1008 .name = "atmel_usart",
1009 .id = 4,
1010 .dev = {
Andrew Victorc6686ff2008-01-23 09:13:53 +01001011 .dma_mask = &uart3_dmamask,
1012 .coherent_dma_mask = DMA_BIT_MASK(32),
1013 .platform_data = &uart3_data,
Andrew Victor86ad76b2006-11-30 16:45:01 +01001014 },
1015 .resource = uart3_resources,
1016 .num_resources = ARRAY_SIZE(uart3_resources),
1017};
1018
Andrew Victorc8f385a2008-01-23 09:25:15 +01001019static inline void configure_usart3_pins(unsigned pins)
Andrew Victor86ad76b2006-11-30 16:45:01 +01001020{
1021 at91_set_A_periph(AT91_PIN_PB10, 1); /* TXD3 */
1022 at91_set_A_periph(AT91_PIN_PB11, 0); /* RXD3 */
Andrew Victorc8f385a2008-01-23 09:25:15 +01001023
1024 if (pins & ATMEL_UART_RTS)
1025 at91_set_B_periph(AT91_PIN_PC8, 0); /* RTS3 */
1026 if (pins & ATMEL_UART_CTS)
1027 at91_set_B_periph(AT91_PIN_PC10, 0); /* CTS3 */
Andrew Victor86ad76b2006-11-30 16:45:01 +01001028}
1029
1030static struct resource uart4_resources[] = {
1031 [0] = {
1032 .start = AT91SAM9260_BASE_US4,
1033 .end = AT91SAM9260_BASE_US4 + SZ_16K - 1,
1034 .flags = IORESOURCE_MEM,
1035 },
1036 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +02001037 .start = NR_IRQS_LEGACY + AT91SAM9260_ID_US4,
1038 .end = NR_IRQS_LEGACY + AT91SAM9260_ID_US4,
Andrew Victor86ad76b2006-11-30 16:45:01 +01001039 .flags = IORESOURCE_IRQ,
1040 },
1041};
1042
1043static struct atmel_uart_data uart4_data = {
1044 .use_dma_tx = 1,
1045 .use_dma_rx = 1,
Linus Walleij354e57f2013-11-07 10:25:55 +01001046 .rts_gpio = -EINVAL,
Andrew Victor86ad76b2006-11-30 16:45:01 +01001047};
1048
Andrew Victorc6686ff2008-01-23 09:13:53 +01001049static u64 uart4_dmamask = DMA_BIT_MASK(32);
1050
Andrew Victor86ad76b2006-11-30 16:45:01 +01001051static struct platform_device at91sam9260_uart4_device = {
1052 .name = "atmel_usart",
1053 .id = 5,
1054 .dev = {
Andrew Victorc6686ff2008-01-23 09:13:53 +01001055 .dma_mask = &uart4_dmamask,
1056 .coherent_dma_mask = DMA_BIT_MASK(32),
1057 .platform_data = &uart4_data,
Andrew Victor86ad76b2006-11-30 16:45:01 +01001058 },
1059 .resource = uart4_resources,
1060 .num_resources = ARRAY_SIZE(uart4_resources),
1061};
1062
1063static inline void configure_usart4_pins(void)
1064{
1065 at91_set_B_periph(AT91_PIN_PA31, 1); /* TXD4 */
1066 at91_set_B_periph(AT91_PIN_PA30, 0); /* RXD4 */
1067}
1068
1069static struct resource uart5_resources[] = {
1070 [0] = {
1071 .start = AT91SAM9260_BASE_US5,
1072 .end = AT91SAM9260_BASE_US5 + SZ_16K - 1,
1073 .flags = IORESOURCE_MEM,
1074 },
1075 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +02001076 .start = NR_IRQS_LEGACY + AT91SAM9260_ID_US5,
1077 .end = NR_IRQS_LEGACY + AT91SAM9260_ID_US5,
Andrew Victor86ad76b2006-11-30 16:45:01 +01001078 .flags = IORESOURCE_IRQ,
1079 },
1080};
1081
1082static struct atmel_uart_data uart5_data = {
1083 .use_dma_tx = 1,
1084 .use_dma_rx = 1,
Linus Walleij354e57f2013-11-07 10:25:55 +01001085 .rts_gpio = -EINVAL,
Andrew Victor86ad76b2006-11-30 16:45:01 +01001086};
1087
Andrew Victorc6686ff2008-01-23 09:13:53 +01001088static u64 uart5_dmamask = DMA_BIT_MASK(32);
1089
Andrew Victor86ad76b2006-11-30 16:45:01 +01001090static struct platform_device at91sam9260_uart5_device = {
1091 .name = "atmel_usart",
1092 .id = 6,
1093 .dev = {
Andrew Victorc6686ff2008-01-23 09:13:53 +01001094 .dma_mask = &uart5_dmamask,
1095 .coherent_dma_mask = DMA_BIT_MASK(32),
1096 .platform_data = &uart5_data,
Andrew Victor86ad76b2006-11-30 16:45:01 +01001097 },
1098 .resource = uart5_resources,
1099 .num_resources = ARRAY_SIZE(uart5_resources),
1100};
1101
1102static inline void configure_usart5_pins(void)
1103{
1104 at91_set_A_periph(AT91_PIN_PB12, 1); /* TXD5 */
1105 at91_set_A_periph(AT91_PIN_PB13, 0); /* RXD5 */
1106}
1107
Andrew Victor11aadac2008-04-15 21:16:38 +01001108static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
Andrew Victor86ad76b2006-11-30 16:45:01 +01001109
Andrew Victorc8f385a2008-01-23 09:25:15 +01001110void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
1111{
1112 struct platform_device *pdev;
Jean-Christophe PLAGNIOL-VILLARD2b348e22011-04-10 14:10:05 +08001113 struct atmel_uart_data *pdata;
Andrew Victorc8f385a2008-01-23 09:25:15 +01001114
1115 switch (id) {
1116 case 0: /* DBGU */
1117 pdev = &at91sam9260_dbgu_device;
1118 configure_dbgu_pins();
Andrew Victorc8f385a2008-01-23 09:25:15 +01001119 break;
1120 case AT91SAM9260_ID_US0:
1121 pdev = &at91sam9260_uart0_device;
1122 configure_usart0_pins(pins);
Andrew Victorc8f385a2008-01-23 09:25:15 +01001123 break;
1124 case AT91SAM9260_ID_US1:
1125 pdev = &at91sam9260_uart1_device;
1126 configure_usart1_pins(pins);
Andrew Victorc8f385a2008-01-23 09:25:15 +01001127 break;
1128 case AT91SAM9260_ID_US2:
1129 pdev = &at91sam9260_uart2_device;
1130 configure_usart2_pins(pins);
Andrew Victorc8f385a2008-01-23 09:25:15 +01001131 break;
1132 case AT91SAM9260_ID_US3:
1133 pdev = &at91sam9260_uart3_device;
1134 configure_usart3_pins(pins);
Andrew Victorc8f385a2008-01-23 09:25:15 +01001135 break;
1136 case AT91SAM9260_ID_US4:
1137 pdev = &at91sam9260_uart4_device;
1138 configure_usart4_pins();
Andrew Victorc8f385a2008-01-23 09:25:15 +01001139 break;
1140 case AT91SAM9260_ID_US5:
1141 pdev = &at91sam9260_uart5_device;
1142 configure_usart5_pins();
Andrew Victorc8f385a2008-01-23 09:25:15 +01001143 break;
1144 default:
1145 return;
1146 }
Jean-Christophe PLAGNIOL-VILLARD2b348e22011-04-10 14:10:05 +08001147 pdata = pdev->dev.platform_data;
1148 pdata->num = portnr; /* update to mapped ID */
Andrew Victorc8f385a2008-01-23 09:25:15 +01001149
1150 if (portnr < ATMEL_MAX_UART)
1151 at91_uarts[portnr] = pdev;
1152}
1153
Andrew Victor86ad76b2006-11-30 16:45:01 +01001154void __init at91_add_device_serial(void)
1155{
1156 int i;
1157
1158 for (i = 0; i < ATMEL_MAX_UART; i++) {
1159 if (at91_uarts[i])
1160 platform_device_register(at91_uarts[i]);
1161 }
1162}
1163#else
Andrew Victorc8f385a2008-01-23 09:25:15 +01001164void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
Andrew Victor86ad76b2006-11-30 16:45:01 +01001165void __init at91_add_device_serial(void) {}
1166#endif
1167
Sergey Matyukevichfb852052009-07-30 22:23:24 +01001168/* --------------------------------------------------------------------
1169 * CF/IDE
1170 * -------------------------------------------------------------------- */
1171
Jean-Christophe PLAGNIOL-VILLARDcf844752011-12-15 21:24:03 +08001172#if defined(CONFIG_PATA_AT91) || defined(CONFIG_PATA_AT91_MODULE) || \
Sergey Matyukevichfb852052009-07-30 22:23:24 +01001173 defined(CONFIG_AT91_CF) || defined(CONFIG_AT91_CF_MODULE)
1174
1175static struct at91_cf_data cf0_data;
1176
1177static struct resource cf0_resources[] = {
1178 [0] = {
1179 .start = AT91_CHIPSELECT_4,
1180 .end = AT91_CHIPSELECT_4 + SZ_256M - 1,
1181 .flags = IORESOURCE_MEM,
1182 }
1183};
1184
1185static struct platform_device cf0_device = {
1186 .id = 0,
1187 .dev = {
1188 .platform_data = &cf0_data,
1189 },
1190 .resource = cf0_resources,
1191 .num_resources = ARRAY_SIZE(cf0_resources),
1192};
1193
1194static struct at91_cf_data cf1_data;
1195
1196static struct resource cf1_resources[] = {
1197 [0] = {
1198 .start = AT91_CHIPSELECT_5,
1199 .end = AT91_CHIPSELECT_5 + SZ_256M - 1,
1200 .flags = IORESOURCE_MEM,
1201 }
1202};
1203
1204static struct platform_device cf1_device = {
1205 .id = 1,
1206 .dev = {
1207 .platform_data = &cf1_data,
1208 },
1209 .resource = cf1_resources,
1210 .num_resources = ARRAY_SIZE(cf1_resources),
1211};
1212
1213void __init at91_add_device_cf(struct at91_cf_data *data)
1214{
1215 struct platform_device *pdev;
1216 unsigned long csa;
1217
1218 if (!data)
1219 return;
1220
Jean-Christophe PLAGNIOL-VILLARD4342d642011-11-27 23:15:50 +08001221 csa = at91_matrix_read(AT91_MATRIX_EBICSA);
Sergey Matyukevichfb852052009-07-30 22:23:24 +01001222
1223 switch (data->chipselect) {
1224 case 4:
1225 at91_set_multi_drive(AT91_PIN_PC8, 0);
1226 at91_set_A_periph(AT91_PIN_PC8, 0);
1227 csa |= AT91_MATRIX_CS4A_SMC_CF1;
1228 cf0_data = *data;
1229 pdev = &cf0_device;
1230 break;
1231 case 5:
1232 at91_set_multi_drive(AT91_PIN_PC9, 0);
1233 at91_set_A_periph(AT91_PIN_PC9, 0);
1234 csa |= AT91_MATRIX_CS5A_SMC_CF2;
1235 cf1_data = *data;
1236 pdev = &cf1_device;
1237 break;
1238 default:
1239 printk(KERN_ERR "AT91 CF: bad chip-select requested (%u)\n",
1240 data->chipselect);
1241 return;
1242 }
1243
Jean-Christophe PLAGNIOL-VILLARD4342d642011-11-27 23:15:50 +08001244 at91_matrix_write(AT91_MATRIX_EBICSA, csa);
Sergey Matyukevichfb852052009-07-30 22:23:24 +01001245
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +08001246 if (gpio_is_valid(data->rst_pin)) {
Sergey Matyukevichfb852052009-07-30 22:23:24 +01001247 at91_set_multi_drive(data->rst_pin, 0);
1248 at91_set_gpio_output(data->rst_pin, 1);
1249 }
1250
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +08001251 if (gpio_is_valid(data->irq_pin)) {
Sergey Matyukevichfb852052009-07-30 22:23:24 +01001252 at91_set_gpio_input(data->irq_pin, 0);
1253 at91_set_deglitch(data->irq_pin, 1);
1254 }
1255
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +08001256 if (gpio_is_valid(data->det_pin)) {
Sergey Matyukevichfb852052009-07-30 22:23:24 +01001257 at91_set_gpio_input(data->det_pin, 0);
1258 at91_set_deglitch(data->det_pin, 1);
1259 }
1260
1261 at91_set_B_periph(AT91_PIN_PC6, 0); /* CFCE1 */
1262 at91_set_B_periph(AT91_PIN_PC7, 0); /* CFCE2 */
1263 at91_set_A_periph(AT91_PIN_PC10, 0); /* CFRNW */
1264 at91_set_A_periph(AT91_PIN_PC15, 1); /* NWAIT */
1265
Arnd Bergmanncb46a252014-04-03 10:02:12 +02001266 if (IS_ENABLED(CONFIG_PATA_AT91) && (data->flags & AT91_CF_TRUE_IDE))
Sergey Matyukevichfb852052009-07-30 22:23:24 +01001267 pdev->name = "pata_at91";
Sergey Matyukevichfb852052009-07-30 22:23:24 +01001268 else
1269 pdev->name = "at91_cf";
1270
1271 platform_device_register(pdev);
1272}
1273
1274#else
1275void __init at91_add_device_cf(struct at91_cf_data * data) {}
1276#endif
Andrew Victor86ad76b2006-11-30 16:45:01 +01001277
Maxime Ripard67b5d7b2012-05-11 15:35:34 +02001278/* --------------------------------------------------------------------
1279 * ADCs
1280 * -------------------------------------------------------------------- */
1281
1282#if IS_ENABLED(CONFIG_AT91_ADC)
1283static struct at91_adc_data adc_data;
1284
1285static struct resource adc_resources[] = {
1286 [0] = {
1287 .start = AT91SAM9260_BASE_ADC,
1288 .end = AT91SAM9260_BASE_ADC + SZ_16K - 1,
1289 .flags = IORESOURCE_MEM,
1290 },
1291 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +02001292 .start = NR_IRQS_LEGACY + AT91SAM9260_ID_ADC,
1293 .end = NR_IRQS_LEGACY + AT91SAM9260_ID_ADC,
Maxime Ripard67b5d7b2012-05-11 15:35:34 +02001294 .flags = IORESOURCE_IRQ,
1295 },
1296};
1297
1298static struct platform_device at91_adc_device = {
Alexandre Belloni301841a2014-05-03 16:57:00 +01001299 .name = "at91sam9260-adc",
Maxime Ripard67b5d7b2012-05-11 15:35:34 +02001300 .id = -1,
1301 .dev = {
1302 .platform_data = &adc_data,
1303 },
1304 .resource = adc_resources,
1305 .num_resources = ARRAY_SIZE(adc_resources),
1306};
1307
1308static struct at91_adc_trigger at91_adc_triggers[] = {
1309 [0] = {
1310 .name = "timer-counter-0",
1311 .value = AT91_ADC_TRGSEL_TC0 | AT91_ADC_TRGEN,
1312 },
1313 [1] = {
1314 .name = "timer-counter-1",
1315 .value = AT91_ADC_TRGSEL_TC1 | AT91_ADC_TRGEN,
1316 },
1317 [2] = {
1318 .name = "timer-counter-2",
1319 .value = AT91_ADC_TRGSEL_TC2 | AT91_ADC_TRGEN,
1320 },
1321 [3] = {
1322 .name = "external",
1323 .value = AT91_ADC_TRGSEL_EXTERNAL | AT91_ADC_TRGEN,
1324 .is_external = true,
1325 },
1326};
1327
1328static struct at91_adc_reg_desc at91_adc_register_g20 = {
1329 .channel_base = AT91_ADC_CHR(0),
1330 .drdy_mask = AT91_ADC_DRDY,
1331 .status_register = AT91_ADC_SR,
1332 .trigger_register = AT91_ADC_MR,
1333};
1334
1335void __init at91_add_device_adc(struct at91_adc_data *data)
1336{
1337 if (!data)
1338 return;
1339
1340 if (test_bit(0, &data->channels_used))
1341 at91_set_A_periph(AT91_PIN_PC0, 0);
1342 if (test_bit(1, &data->channels_used))
1343 at91_set_A_periph(AT91_PIN_PC1, 0);
1344 if (test_bit(2, &data->channels_used))
1345 at91_set_A_periph(AT91_PIN_PC2, 0);
1346 if (test_bit(3, &data->channels_used))
1347 at91_set_A_periph(AT91_PIN_PC3, 0);
1348
1349 if (data->use_external_triggers)
1350 at91_set_A_periph(AT91_PIN_PA22, 0);
1351
1352 data->num_channels = 4;
1353 data->startup_time = 10;
1354 data->registers = &at91_adc_register_g20;
1355 data->trigger_number = 4;
1356 data->trigger_list = at91_adc_triggers;
1357
1358 adc_data = *data;
1359 platform_device_register(&at91_adc_device);
1360}
1361#else
1362void __init at91_add_device_adc(struct at91_adc_data *data) {}
1363#endif
1364
Andrew Victor86ad76b2006-11-30 16:45:01 +01001365/* -------------------------------------------------------------------- */
1366/*
1367 * These devices are always present and don't need any board-specific
1368 * setup.
1369 */
1370static int __init at91_add_standard_devices(void)
1371{
Jean-Christophe PLAGNIOL-VILLARD8cf93b92012-02-28 15:23:43 +08001372 if (of_have_populated_dt())
1373 return 0;
1374
Andrew Victor884f5a62008-01-23 09:11:13 +01001375 at91_add_device_rtt();
1376 at91_add_device_watchdog();
Andrew Victore5f40bf2008-04-02 21:58:00 +01001377 at91_add_device_tc();
Andrew Victor86ad76b2006-11-30 16:45:01 +01001378 return 0;
1379}
1380
1381arch_initcall(at91_add_standard_devices);