blob: 21ab782cc8e90340cfbb2967dbe346b2c6ae0bbb [file] [log] [blame]
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001/*
2 * On-Chip devices setup code for the AT91SAM9G45 family
3 *
4 * Copyright (C) 2009 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
15#include <linux/dma-mapping.h>
Russell King2f8163b2011-07-26 10:53:52 +010016#include <linux/gpio.h>
Josh Wu343754f2011-10-22 15:17:40 +080017#include <linux/clk.h>
Nicolas Ferre789b23b2009-06-26 15:36:58 +010018#include <linux/platform_device.h>
19#include <linux/i2c-gpio.h>
Nicolas Ferre75305d72010-10-22 18:27:48 +020020#include <linux/atmel-mci.h>
Nicolas Royer6150f3b2013-02-20 17:10:23 +010021#include <linux/platform_data/crypto-atmel.h>
Nicolas Ferre789b23b2009-06-26 15:36:58 +010022
Maxime Ripard4a5920e2012-05-11 15:35:35 +020023#include <linux/platform_data/at91_adc.h>
24
Nicolas Ferre789b23b2009-06-26 15:36:58 +010025#include <linux/fb.h>
26#include <video/atmel_lcdc.h>
27
Nicolas Ferre789b23b2009-06-26 15:36:58 +010028#include <mach/at91sam9g45.h>
29#include <mach/at91sam9g45_matrix.h>
Jean-Christophe PLAGNIOL-VILLARD4342d642011-11-27 23:15:50 +080030#include <mach/at91_matrix.h>
Nicolas Ferre789b23b2009-06-26 15:36:58 +010031#include <mach/at91sam9_smc.h>
Arnd Bergmann7cdc39e2012-08-24 15:10:04 +020032#include <linux/platform_data/dma-atmel.h>
Nicolas Ferre75305d72010-10-22 18:27:48 +020033#include <mach/atmel-mci.h>
Uwe Kleine-Königac11a1d2013-11-14 10:49:19 +010034#include <mach/hardware.h>
Nicolas Ferre789b23b2009-06-26 15:36:58 +010035
Josh Wu343754f2011-10-22 15:17:40 +080036#include <media/atmel-isi.h>
37
Jean-Christophe PLAGNIOL-VILLARD43d2f532012-10-30 05:14:17 +080038#include "board.h"
Nicolas Ferre789b23b2009-06-26 15:36:58 +010039#include "generic.h"
Josh Wu343754f2011-10-22 15:17:40 +080040#include "clock.h"
Linus Walleijcf2e9332014-03-27 14:18:51 +010041#include "gpio.h"
Nicolas Ferre789b23b2009-06-26 15:36:58 +010042
43
44/* --------------------------------------------------------------------
Nicolas Ferre40262b22009-07-24 11:43:01 +010045 * HDMAC - AHB DMA Controller
46 * -------------------------------------------------------------------- */
47
48#if defined(CONFIG_AT_HDMAC) || defined(CONFIG_AT_HDMAC_MODULE)
49static u64 hdmac_dmamask = DMA_BIT_MASK(32);
50
Nicolas Ferre40262b22009-07-24 11:43:01 +010051static struct resource hdmac_resources[] = {
52 [0] = {
Jean-Christophe PLAGNIOL-VILLARD9627b202011-10-15 15:47:51 +080053 .start = AT91SAM9G45_BASE_DMA,
54 .end = AT91SAM9G45_BASE_DMA + SZ_512 - 1,
Nicolas Ferre40262b22009-07-24 11:43:01 +010055 .flags = IORESOURCE_MEM,
56 },
Nicolas Ferre8d2602e2010-08-20 16:44:33 +020057 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +020058 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_DMA,
59 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_DMA,
Nicolas Ferre40262b22009-07-24 11:43:01 +010060 .flags = IORESOURCE_IRQ,
61 },
62};
63
64static struct platform_device at_hdmac_device = {
Nicolas Ferrebdad0b92011-10-10 14:55:17 +020065 .name = "at91sam9g45_dma",
Nicolas Ferre40262b22009-07-24 11:43:01 +010066 .id = -1,
67 .dev = {
68 .dma_mask = &hdmac_dmamask,
69 .coherent_dma_mask = DMA_BIT_MASK(32),
Nicolas Ferre40262b22009-07-24 11:43:01 +010070 },
71 .resource = hdmac_resources,
72 .num_resources = ARRAY_SIZE(hdmac_resources),
73};
74
75void __init at91_add_device_hdmac(void)
76{
Jean-Christophe PLAGNIOL-VILLARD8cf93b92012-02-28 15:23:43 +080077 platform_device_register(&at_hdmac_device);
Nicolas Ferre40262b22009-07-24 11:43:01 +010078}
79#else
80void __init at91_add_device_hdmac(void) {}
81#endif
82
83
84/* --------------------------------------------------------------------
Nicolas Ferre789b23b2009-06-26 15:36:58 +010085 * USB Host (OHCI)
86 * -------------------------------------------------------------------- */
87
88#if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
89static u64 ohci_dmamask = DMA_BIT_MASK(32);
90static struct at91_usbh_data usbh_ohci_data;
91
92static struct resource usbh_ohci_resources[] = {
93 [0] = {
94 .start = AT91SAM9G45_OHCI_BASE,
95 .end = AT91SAM9G45_OHCI_BASE + SZ_1M - 1,
96 .flags = IORESOURCE_MEM,
97 },
98 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +020099 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_UHPHS,
100 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_UHPHS,
Nicolas Ferre789b23b2009-06-26 15:36:58 +0100101 .flags = IORESOURCE_IRQ,
102 },
103};
104
105static struct platform_device at91_usbh_ohci_device = {
106 .name = "at91_ohci",
107 .id = -1,
108 .dev = {
109 .dma_mask = &ohci_dmamask,
110 .coherent_dma_mask = DMA_BIT_MASK(32),
111 .platform_data = &usbh_ohci_data,
112 },
113 .resource = usbh_ohci_resources,
114 .num_resources = ARRAY_SIZE(usbh_ohci_resources),
115};
116
117void __init at91_add_device_usbh_ohci(struct at91_usbh_data *data)
118{
119 int i;
120
121 if (!data)
122 return;
123
124 /* Enable VBus control for UHP ports */
125 for (i = 0; i < data->ports; i++) {
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +0800126 if (gpio_is_valid(data->vbus_pin[i]))
Nicolas Ferrecca03552012-03-28 11:56:28 +0200127 at91_set_gpio_output(data->vbus_pin[i],
128 data->vbus_pin_active_low[i]);
Nicolas Ferre789b23b2009-06-26 15:36:58 +0100129 }
130
Thomas Petazzoni1fcaea72011-07-13 11:29:18 +0200131 /* Enable overcurrent notification */
132 for (i = 0; i < data->ports; i++) {
Nicolas Ferre0c2c1f62012-03-28 11:58:58 +0200133 if (gpio_is_valid(data->overcurrent_pin[i]))
Thomas Petazzoni1fcaea72011-07-13 11:29:18 +0200134 at91_set_gpio_input(data->overcurrent_pin[i], 1);
135 }
136
Nicolas Ferre789b23b2009-06-26 15:36:58 +0100137 usbh_ohci_data = *data;
138 platform_device_register(&at91_usbh_ohci_device);
139}
140#else
141void __init at91_add_device_usbh_ohci(struct at91_usbh_data *data) {}
142#endif
143
144
145/* --------------------------------------------------------------------
Nicolas Ferref51f78c2009-09-25 12:11:32 +0100146 * USB Host HS (EHCI)
147 * Needs an OHCI host for low and full speed management
148 * -------------------------------------------------------------------- */
149
150#if defined(CONFIG_USB_EHCI_HCD) || defined(CONFIG_USB_EHCI_HCD_MODULE)
151static u64 ehci_dmamask = DMA_BIT_MASK(32);
152static struct at91_usbh_data usbh_ehci_data;
153
154static struct resource usbh_ehci_resources[] = {
155 [0] = {
156 .start = AT91SAM9G45_EHCI_BASE,
157 .end = AT91SAM9G45_EHCI_BASE + SZ_1M - 1,
158 .flags = IORESOURCE_MEM,
159 },
160 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200161 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_UHPHS,
162 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_UHPHS,
Nicolas Ferref51f78c2009-09-25 12:11:32 +0100163 .flags = IORESOURCE_IRQ,
164 },
165};
166
167static struct platform_device at91_usbh_ehci_device = {
168 .name = "atmel-ehci",
169 .id = -1,
170 .dev = {
171 .dma_mask = &ehci_dmamask,
172 .coherent_dma_mask = DMA_BIT_MASK(32),
173 .platform_data = &usbh_ehci_data,
174 },
175 .resource = usbh_ehci_resources,
176 .num_resources = ARRAY_SIZE(usbh_ehci_resources),
177};
178
179void __init at91_add_device_usbh_ehci(struct at91_usbh_data *data)
180{
181 int i;
182
183 if (!data)
184 return;
185
186 /* Enable VBus control for UHP ports */
187 for (i = 0; i < data->ports; i++) {
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +0800188 if (gpio_is_valid(data->vbus_pin[i]))
Nicolas Ferrecca03552012-03-28 11:56:28 +0200189 at91_set_gpio_output(data->vbus_pin[i],
190 data->vbus_pin_active_low[i]);
Nicolas Ferref51f78c2009-09-25 12:11:32 +0100191 }
192
193 usbh_ehci_data = *data;
Nicolas Ferref51f78c2009-09-25 12:11:32 +0100194 platform_device_register(&at91_usbh_ehci_device);
195}
196#else
197void __init at91_add_device_usbh_ehci(struct at91_usbh_data *data) {}
198#endif
199
200
201/* --------------------------------------------------------------------
Nicolas Ferre789b23b2009-06-26 15:36:58 +0100202 * USB HS Device (Gadget)
203 * -------------------------------------------------------------------- */
204
Jochen Friedrichdd0b3822011-10-25 20:51:06 +0200205#if defined(CONFIG_USB_ATMEL_USBA) || defined(CONFIG_USB_ATMEL_USBA_MODULE)
Nicolas Ferre789b23b2009-06-26 15:36:58 +0100206static struct resource usba_udc_resources[] = {
207 [0] = {
208 .start = AT91SAM9G45_UDPHS_FIFO,
209 .end = AT91SAM9G45_UDPHS_FIFO + SZ_512K - 1,
210 .flags = IORESOURCE_MEM,
211 },
212 [1] = {
213 .start = AT91SAM9G45_BASE_UDPHS,
214 .end = AT91SAM9G45_BASE_UDPHS + SZ_1K - 1,
215 .flags = IORESOURCE_MEM,
216 },
217 [2] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200218 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_UDPHS,
219 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_UDPHS,
Nicolas Ferre789b23b2009-06-26 15:36:58 +0100220 .flags = IORESOURCE_IRQ,
221 },
222};
223
224#define EP(nam, idx, maxpkt, maxbk, dma, isoc) \
225 [idx] = { \
226 .name = nam, \
227 .index = idx, \
228 .fifo_size = maxpkt, \
229 .nr_banks = maxbk, \
230 .can_dma = dma, \
231 .can_isoc = isoc, \
232 }
233
234static struct usba_ep_data usba_udc_ep[] __initdata = {
235 EP("ep0", 0, 64, 1, 0, 0),
236 EP("ep1", 1, 1024, 2, 1, 1),
237 EP("ep2", 2, 1024, 2, 1, 1),
238 EP("ep3", 3, 1024, 3, 1, 0),
239 EP("ep4", 4, 1024, 3, 1, 0),
240 EP("ep5", 5, 1024, 3, 1, 1),
241 EP("ep6", 6, 1024, 3, 1, 1),
242};
243
244#undef EP
245
246/*
247 * pdata doesn't have room for any endpoints, so we need to
248 * append room for the ones we need right after it.
249 */
250static struct {
251 struct usba_platform_data pdata;
252 struct usba_ep_data ep[7];
253} usba_udc_data;
254
255static struct platform_device at91_usba_udc_device = {
256 .name = "atmel_usba_udc",
257 .id = -1,
258 .dev = {
259 .platform_data = &usba_udc_data.pdata,
260 },
261 .resource = usba_udc_resources,
262 .num_resources = ARRAY_SIZE(usba_udc_resources),
263};
264
265void __init at91_add_device_usba(struct usba_platform_data *data)
266{
267 usba_udc_data.pdata.vbus_pin = -EINVAL;
268 usba_udc_data.pdata.num_ep = ARRAY_SIZE(usba_udc_ep);
Justin P. Mattock6eab04a2011-04-08 19:49:08 -0700269 memcpy(usba_udc_data.ep, usba_udc_ep, sizeof(usba_udc_ep));
Nicolas Ferre789b23b2009-06-26 15:36:58 +0100270
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +0800271 if (data && gpio_is_valid(data->vbus_pin)) {
Nicolas Ferre789b23b2009-06-26 15:36:58 +0100272 at91_set_gpio_input(data->vbus_pin, 0);
273 at91_set_deglitch(data->vbus_pin, 1);
274 usba_udc_data.pdata.vbus_pin = data->vbus_pin;
275 }
276
277 /* Pullup pin is handled internally by USB device peripheral */
278
Nicolas Ferre789b23b2009-06-26 15:36:58 +0100279 platform_device_register(&at91_usba_udc_device);
280}
281#else
282void __init at91_add_device_usba(struct usba_platform_data *data) {}
283#endif
284
285
286/* --------------------------------------------------------------------
287 * Ethernet
288 * -------------------------------------------------------------------- */
289
290#if defined(CONFIG_MACB) || defined(CONFIG_MACB_MODULE)
291static u64 eth_dmamask = DMA_BIT_MASK(32);
Jamie Iles84e0cdb2011-03-08 20:17:06 +0000292static struct macb_platform_data eth_data;
Nicolas Ferre789b23b2009-06-26 15:36:58 +0100293
294static struct resource eth_resources[] = {
295 [0] = {
296 .start = AT91SAM9G45_BASE_EMAC,
297 .end = AT91SAM9G45_BASE_EMAC + SZ_16K - 1,
298 .flags = IORESOURCE_MEM,
299 },
300 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200301 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_EMAC,
302 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_EMAC,
Nicolas Ferre789b23b2009-06-26 15:36:58 +0100303 .flags = IORESOURCE_IRQ,
304 },
305};
306
307static struct platform_device at91sam9g45_eth_device = {
308 .name = "macb",
309 .id = -1,
310 .dev = {
311 .dma_mask = &eth_dmamask,
312 .coherent_dma_mask = DMA_BIT_MASK(32),
313 .platform_data = &eth_data,
314 },
315 .resource = eth_resources,
316 .num_resources = ARRAY_SIZE(eth_resources),
317};
318
Jamie Iles84e0cdb2011-03-08 20:17:06 +0000319void __init at91_add_device_eth(struct macb_platform_data *data)
Nicolas Ferre789b23b2009-06-26 15:36:58 +0100320{
321 if (!data)
322 return;
323
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +0800324 if (gpio_is_valid(data->phy_irq_pin)) {
Nicolas Ferre789b23b2009-06-26 15:36:58 +0100325 at91_set_gpio_input(data->phy_irq_pin, 0);
326 at91_set_deglitch(data->phy_irq_pin, 1);
327 }
328
329 /* Pins used for MII and RMII */
330 at91_set_A_periph(AT91_PIN_PA17, 0); /* ETXCK_EREFCK */
331 at91_set_A_periph(AT91_PIN_PA15, 0); /* ERXDV */
332 at91_set_A_periph(AT91_PIN_PA12, 0); /* ERX0 */
333 at91_set_A_periph(AT91_PIN_PA13, 0); /* ERX1 */
334 at91_set_A_periph(AT91_PIN_PA16, 0); /* ERXER */
335 at91_set_A_periph(AT91_PIN_PA14, 0); /* ETXEN */
336 at91_set_A_periph(AT91_PIN_PA10, 0); /* ETX0 */
337 at91_set_A_periph(AT91_PIN_PA11, 0); /* ETX1 */
338 at91_set_A_periph(AT91_PIN_PA19, 0); /* EMDIO */
339 at91_set_A_periph(AT91_PIN_PA18, 0); /* EMDC */
340
341 if (!data->is_rmii) {
342 at91_set_B_periph(AT91_PIN_PA29, 0); /* ECRS */
343 at91_set_B_periph(AT91_PIN_PA30, 0); /* ECOL */
344 at91_set_B_periph(AT91_PIN_PA8, 0); /* ERX2 */
345 at91_set_B_periph(AT91_PIN_PA9, 0); /* ERX3 */
346 at91_set_B_periph(AT91_PIN_PA28, 0); /* ERXCK */
347 at91_set_B_periph(AT91_PIN_PA6, 0); /* ETX2 */
348 at91_set_B_periph(AT91_PIN_PA7, 0); /* ETX3 */
349 at91_set_B_periph(AT91_PIN_PA27, 0); /* ETXER */
350 }
351
352 eth_data = *data;
353 platform_device_register(&at91sam9g45_eth_device);
354}
355#else
Jamie Iles84e0cdb2011-03-08 20:17:06 +0000356void __init at91_add_device_eth(struct macb_platform_data *data) {}
Nicolas Ferre789b23b2009-06-26 15:36:58 +0100357#endif
358
359
360/* --------------------------------------------------------------------
Nicolas Ferre75305d72010-10-22 18:27:48 +0200361 * MMC / SD
362 * -------------------------------------------------------------------- */
363
364#if defined(CONFIG_MMC_ATMELMCI) || defined(CONFIG_MMC_ATMELMCI_MODULE)
365static u64 mmc_dmamask = DMA_BIT_MASK(32);
366static struct mci_platform_data mmc0_data, mmc1_data;
367
368static struct resource mmc0_resources[] = {
369 [0] = {
370 .start = AT91SAM9G45_BASE_MCI0,
371 .end = AT91SAM9G45_BASE_MCI0 + SZ_16K - 1,
372 .flags = IORESOURCE_MEM,
373 },
374 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200375 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_MCI0,
376 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_MCI0,
Nicolas Ferre75305d72010-10-22 18:27:48 +0200377 .flags = IORESOURCE_IRQ,
378 },
379};
380
381static struct platform_device at91sam9g45_mmc0_device = {
382 .name = "atmel_mci",
383 .id = 0,
384 .dev = {
385 .dma_mask = &mmc_dmamask,
386 .coherent_dma_mask = DMA_BIT_MASK(32),
387 .platform_data = &mmc0_data,
388 },
389 .resource = mmc0_resources,
390 .num_resources = ARRAY_SIZE(mmc0_resources),
391};
392
393static struct resource mmc1_resources[] = {
394 [0] = {
395 .start = AT91SAM9G45_BASE_MCI1,
396 .end = AT91SAM9G45_BASE_MCI1 + SZ_16K - 1,
397 .flags = IORESOURCE_MEM,
398 },
399 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200400 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_MCI1,
401 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_MCI1,
Nicolas Ferre75305d72010-10-22 18:27:48 +0200402 .flags = IORESOURCE_IRQ,
403 },
404};
405
406static struct platform_device at91sam9g45_mmc1_device = {
407 .name = "atmel_mci",
408 .id = 1,
409 .dev = {
410 .dma_mask = &mmc_dmamask,
411 .coherent_dma_mask = DMA_BIT_MASK(32),
412 .platform_data = &mmc1_data,
413 },
414 .resource = mmc1_resources,
415 .num_resources = ARRAY_SIZE(mmc1_resources),
416};
417
418/* Consider only one slot : slot 0 */
419void __init at91_add_device_mci(short mmc_id, struct mci_platform_data *data)
420{
421
422 if (!data)
423 return;
424
425 /* Must have at least one usable slot */
426 if (!data->slot[0].bus_width)
427 return;
428
429#if defined(CONFIG_AT_HDMAC) || defined(CONFIG_AT_HDMAC_MODULE)
430 {
431 struct at_dma_slave *atslave;
432 struct mci_dma_data *alt_atslave;
433
434 alt_atslave = kzalloc(sizeof(struct mci_dma_data), GFP_KERNEL);
435 atslave = &alt_atslave->sdata;
436
437 /* DMA slave channel configuration */
438 atslave->dma_dev = &at_hdmac_device.dev;
Nicolas Ferre75305d72010-10-22 18:27:48 +0200439 atslave->cfg = ATC_FIFOCFG_HALFFIFO
440 | ATC_SRC_H2SEL_HW | ATC_DST_H2SEL_HW;
Nicolas Ferre75305d72010-10-22 18:27:48 +0200441 if (mmc_id == 0) /* MCI0 */
442 atslave->cfg |= ATC_SRC_PER(AT_DMA_ID_MCI0)
443 | ATC_DST_PER(AT_DMA_ID_MCI0);
444
445 else /* MCI1 */
446 atslave->cfg |= ATC_SRC_PER(AT_DMA_ID_MCI1)
447 | ATC_DST_PER(AT_DMA_ID_MCI1);
448
449 data->dma_slave = alt_atslave;
450 }
451#endif
452
453
454 /* input/irq */
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +0800455 if (gpio_is_valid(data->slot[0].detect_pin)) {
Nicolas Ferre75305d72010-10-22 18:27:48 +0200456 at91_set_gpio_input(data->slot[0].detect_pin, 1);
457 at91_set_deglitch(data->slot[0].detect_pin, 1);
458 }
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +0800459 if (gpio_is_valid(data->slot[0].wp_pin))
Nicolas Ferre75305d72010-10-22 18:27:48 +0200460 at91_set_gpio_input(data->slot[0].wp_pin, 1);
461
462 if (mmc_id == 0) { /* MCI0 */
463
464 /* CLK */
465 at91_set_A_periph(AT91_PIN_PA0, 0);
466
467 /* CMD */
468 at91_set_A_periph(AT91_PIN_PA1, 1);
469
470 /* DAT0, maybe DAT1..DAT3 and maybe DAT4..DAT7 */
471 at91_set_A_periph(AT91_PIN_PA2, 1);
472 if (data->slot[0].bus_width == 4) {
473 at91_set_A_periph(AT91_PIN_PA3, 1);
474 at91_set_A_periph(AT91_PIN_PA4, 1);
475 at91_set_A_periph(AT91_PIN_PA5, 1);
476 if (data->slot[0].bus_width == 8) {
477 at91_set_A_periph(AT91_PIN_PA6, 1);
478 at91_set_A_periph(AT91_PIN_PA7, 1);
479 at91_set_A_periph(AT91_PIN_PA8, 1);
480 at91_set_A_periph(AT91_PIN_PA9, 1);
481 }
482 }
483
484 mmc0_data = *data;
Nicolas Ferre75305d72010-10-22 18:27:48 +0200485 platform_device_register(&at91sam9g45_mmc0_device);
486
487 } else { /* MCI1 */
488
489 /* CLK */
490 at91_set_A_periph(AT91_PIN_PA31, 0);
491
492 /* CMD */
493 at91_set_A_periph(AT91_PIN_PA22, 1);
494
495 /* DAT0, maybe DAT1..DAT3 and maybe DAT4..DAT7 */
496 at91_set_A_periph(AT91_PIN_PA23, 1);
497 if (data->slot[0].bus_width == 4) {
498 at91_set_A_periph(AT91_PIN_PA24, 1);
499 at91_set_A_periph(AT91_PIN_PA25, 1);
500 at91_set_A_periph(AT91_PIN_PA26, 1);
501 if (data->slot[0].bus_width == 8) {
502 at91_set_A_periph(AT91_PIN_PA27, 1);
503 at91_set_A_periph(AT91_PIN_PA28, 1);
504 at91_set_A_periph(AT91_PIN_PA29, 1);
505 at91_set_A_periph(AT91_PIN_PA30, 1);
506 }
507 }
508
509 mmc1_data = *data;
Nicolas Ferre75305d72010-10-22 18:27:48 +0200510 platform_device_register(&at91sam9g45_mmc1_device);
511
512 }
513}
514#else
515void __init at91_add_device_mci(short mmc_id, struct mci_platform_data *data) {}
516#endif
517
518
519/* --------------------------------------------------------------------
Nicolas Ferre789b23b2009-06-26 15:36:58 +0100520 * NAND / SmartMedia
521 * -------------------------------------------------------------------- */
522
523#if defined(CONFIG_MTD_NAND_ATMEL) || defined(CONFIG_MTD_NAND_ATMEL_MODULE)
524static struct atmel_nand_data nand_data;
525
526#define NAND_BASE AT91_CHIPSELECT_3
527
528static struct resource nand_resources[] = {
529 [0] = {
530 .start = NAND_BASE,
531 .end = NAND_BASE + SZ_256M - 1,
532 .flags = IORESOURCE_MEM,
533 },
534 [1] = {
Jean-Christophe PLAGNIOL-VILLARDd28edd12011-09-18 09:31:56 +0800535 .start = AT91SAM9G45_BASE_ECC,
536 .end = AT91SAM9G45_BASE_ECC + SZ_512 - 1,
Nicolas Ferre789b23b2009-06-26 15:36:58 +0100537 .flags = IORESOURCE_MEM,
538 }
539};
540
541static struct platform_device at91sam9g45_nand_device = {
542 .name = "atmel_nand",
543 .id = -1,
544 .dev = {
545 .platform_data = &nand_data,
546 },
547 .resource = nand_resources,
548 .num_resources = ARRAY_SIZE(nand_resources),
549};
550
551void __init at91_add_device_nand(struct atmel_nand_data *data)
552{
553 unsigned long csa;
554
555 if (!data)
556 return;
557
Jean-Christophe PLAGNIOL-VILLARD4342d642011-11-27 23:15:50 +0800558 csa = at91_matrix_read(AT91_MATRIX_EBICSA);
559 at91_matrix_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_EBI_CS3A_SMC_SMARTMEDIA);
Nicolas Ferre789b23b2009-06-26 15:36:58 +0100560
561 /* enable pin */
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +0800562 if (gpio_is_valid(data->enable_pin))
Nicolas Ferre789b23b2009-06-26 15:36:58 +0100563 at91_set_gpio_output(data->enable_pin, 1);
564
565 /* ready/busy pin */
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +0800566 if (gpio_is_valid(data->rdy_pin))
Nicolas Ferre789b23b2009-06-26 15:36:58 +0100567 at91_set_gpio_input(data->rdy_pin, 1);
568
569 /* card detect pin */
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +0800570 if (gpio_is_valid(data->det_pin))
Nicolas Ferre789b23b2009-06-26 15:36:58 +0100571 at91_set_gpio_input(data->det_pin, 1);
572
573 nand_data = *data;
574 platform_device_register(&at91sam9g45_nand_device);
575}
576#else
577void __init at91_add_device_nand(struct atmel_nand_data *data) {}
578#endif
579
580
581/* --------------------------------------------------------------------
582 * TWI (i2c)
583 * -------------------------------------------------------------------- */
584
585/*
586 * Prefer the GPIO code since the TWI controller isn't robust
587 * (gets overruns and underruns under load) and can only issue
588 * repeated STARTs in one scenario (the driver doesn't yet handle them).
589 */
590#if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
591static struct i2c_gpio_platform_data pdata_i2c0 = {
592 .sda_pin = AT91_PIN_PA20,
593 .sda_is_open_drain = 1,
594 .scl_pin = AT91_PIN_PA21,
595 .scl_is_open_drain = 1,
Peter Korsgaard1d5b4c02010-09-22 21:29:59 +0100596 .udelay = 5, /* ~100 kHz */
Nicolas Ferre789b23b2009-06-26 15:36:58 +0100597};
598
599static struct platform_device at91sam9g45_twi0_device = {
600 .name = "i2c-gpio",
601 .id = 0,
602 .dev.platform_data = &pdata_i2c0,
603};
604
605static struct i2c_gpio_platform_data pdata_i2c1 = {
606 .sda_pin = AT91_PIN_PB10,
607 .sda_is_open_drain = 1,
608 .scl_pin = AT91_PIN_PB11,
609 .scl_is_open_drain = 1,
Peter Korsgaard1d5b4c02010-09-22 21:29:59 +0100610 .udelay = 5, /* ~100 kHz */
Nicolas Ferre789b23b2009-06-26 15:36:58 +0100611};
612
613static struct platform_device at91sam9g45_twi1_device = {
614 .name = "i2c-gpio",
615 .id = 1,
616 .dev.platform_data = &pdata_i2c1,
617};
618
619void __init at91_add_device_i2c(short i2c_id, struct i2c_board_info *devices, int nr_devices)
620{
621 i2c_register_board_info(i2c_id, devices, nr_devices);
622
623 if (i2c_id == 0) {
624 at91_set_GPIO_periph(AT91_PIN_PA20, 1); /* TWD (SDA) */
625 at91_set_multi_drive(AT91_PIN_PA20, 1);
626
627 at91_set_GPIO_periph(AT91_PIN_PA21, 1); /* TWCK (SCL) */
628 at91_set_multi_drive(AT91_PIN_PA21, 1);
629
630 platform_device_register(&at91sam9g45_twi0_device);
631 } else {
632 at91_set_GPIO_periph(AT91_PIN_PB10, 1); /* TWD (SDA) */
633 at91_set_multi_drive(AT91_PIN_PB10, 1);
634
635 at91_set_GPIO_periph(AT91_PIN_PB11, 1); /* TWCK (SCL) */
636 at91_set_multi_drive(AT91_PIN_PB11, 1);
637
638 platform_device_register(&at91sam9g45_twi1_device);
639 }
640}
641
642#elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
643static struct resource twi0_resources[] = {
644 [0] = {
645 .start = AT91SAM9G45_BASE_TWI0,
646 .end = AT91SAM9G45_BASE_TWI0 + SZ_16K - 1,
647 .flags = IORESOURCE_MEM,
648 },
649 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200650 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_TWI0,
651 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_TWI0,
Nicolas Ferre789b23b2009-06-26 15:36:58 +0100652 .flags = IORESOURCE_IRQ,
653 },
654};
655
656static struct platform_device at91sam9g45_twi0_device = {
Nikolaus Vossfac368a2011-11-08 11:49:46 +0100657 .name = "i2c-at91sam9g10",
Nicolas Ferre789b23b2009-06-26 15:36:58 +0100658 .id = 0,
659 .resource = twi0_resources,
660 .num_resources = ARRAY_SIZE(twi0_resources),
661};
662
663static struct resource twi1_resources[] = {
664 [0] = {
665 .start = AT91SAM9G45_BASE_TWI1,
666 .end = AT91SAM9G45_BASE_TWI1 + SZ_16K - 1,
667 .flags = IORESOURCE_MEM,
668 },
669 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200670 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_TWI1,
671 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_TWI1,
Nicolas Ferre789b23b2009-06-26 15:36:58 +0100672 .flags = IORESOURCE_IRQ,
673 },
674};
675
676static struct platform_device at91sam9g45_twi1_device = {
Nikolaus Vossfac368a2011-11-08 11:49:46 +0100677 .name = "i2c-at91sam9g10",
Nicolas Ferre789b23b2009-06-26 15:36:58 +0100678 .id = 1,
679 .resource = twi1_resources,
680 .num_resources = ARRAY_SIZE(twi1_resources),
681};
682
683void __init at91_add_device_i2c(short i2c_id, struct i2c_board_info *devices, int nr_devices)
684{
685 i2c_register_board_info(i2c_id, devices, nr_devices);
686
687 /* pins used for TWI interface */
688 if (i2c_id == 0) {
689 at91_set_A_periph(AT91_PIN_PA20, 0); /* TWD */
Nicolas Ferre789b23b2009-06-26 15:36:58 +0100690 at91_set_A_periph(AT91_PIN_PA21, 0); /* TWCK */
Nicolas Ferre789b23b2009-06-26 15:36:58 +0100691
692 platform_device_register(&at91sam9g45_twi0_device);
693 } else {
694 at91_set_A_periph(AT91_PIN_PB10, 0); /* TWD */
Nicolas Ferre789b23b2009-06-26 15:36:58 +0100695 at91_set_A_periph(AT91_PIN_PB11, 0); /* TWCK */
Nicolas Ferre789b23b2009-06-26 15:36:58 +0100696
697 platform_device_register(&at91sam9g45_twi1_device);
698 }
699}
700#else
701void __init at91_add_device_i2c(short i2c_id, struct i2c_board_info *devices, int nr_devices) {}
702#endif
703
704
705/* --------------------------------------------------------------------
706 * SPI
707 * -------------------------------------------------------------------- */
708
709#if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
710static u64 spi_dmamask = DMA_BIT_MASK(32);
711
712static struct resource spi0_resources[] = {
713 [0] = {
714 .start = AT91SAM9G45_BASE_SPI0,
715 .end = AT91SAM9G45_BASE_SPI0 + SZ_16K - 1,
716 .flags = IORESOURCE_MEM,
717 },
718 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200719 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_SPI0,
720 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_SPI0,
Nicolas Ferre789b23b2009-06-26 15:36:58 +0100721 .flags = IORESOURCE_IRQ,
722 },
723};
724
725static struct platform_device at91sam9g45_spi0_device = {
726 .name = "atmel_spi",
727 .id = 0,
728 .dev = {
729 .dma_mask = &spi_dmamask,
730 .coherent_dma_mask = DMA_BIT_MASK(32),
731 },
732 .resource = spi0_resources,
733 .num_resources = ARRAY_SIZE(spi0_resources),
734};
735
736static const unsigned spi0_standard_cs[4] = { AT91_PIN_PB3, AT91_PIN_PB18, AT91_PIN_PB19, AT91_PIN_PD27 };
737
738static struct resource spi1_resources[] = {
739 [0] = {
740 .start = AT91SAM9G45_BASE_SPI1,
741 .end = AT91SAM9G45_BASE_SPI1 + SZ_16K - 1,
742 .flags = IORESOURCE_MEM,
743 },
744 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200745 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_SPI1,
746 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_SPI1,
Nicolas Ferre789b23b2009-06-26 15:36:58 +0100747 .flags = IORESOURCE_IRQ,
748 },
749};
750
751static struct platform_device at91sam9g45_spi1_device = {
752 .name = "atmel_spi",
753 .id = 1,
754 .dev = {
755 .dma_mask = &spi_dmamask,
756 .coherent_dma_mask = DMA_BIT_MASK(32),
757 },
758 .resource = spi1_resources,
759 .num_resources = ARRAY_SIZE(spi1_resources),
760};
761
762static const unsigned spi1_standard_cs[4] = { AT91_PIN_PB17, AT91_PIN_PD28, AT91_PIN_PD18, AT91_PIN_PD19 };
763
764void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
765{
766 int i;
767 unsigned long cs_pin;
768 short enable_spi0 = 0;
769 short enable_spi1 = 0;
770
771 /* Choose SPI chip-selects */
772 for (i = 0; i < nr_devices; i++) {
773 if (devices[i].controller_data)
774 cs_pin = (unsigned long) devices[i].controller_data;
775 else if (devices[i].bus_num == 0)
776 cs_pin = spi0_standard_cs[devices[i].chip_select];
777 else
778 cs_pin = spi1_standard_cs[devices[i].chip_select];
779
Nicolas Ferre0c2c1f62012-03-28 11:58:58 +0200780 if (!gpio_is_valid(cs_pin))
781 continue;
782
Nicolas Ferre789b23b2009-06-26 15:36:58 +0100783 if (devices[i].bus_num == 0)
784 enable_spi0 = 1;
785 else
786 enable_spi1 = 1;
787
788 /* enable chip-select pin */
789 at91_set_gpio_output(cs_pin, 1);
790
791 /* pass chip-select pin to driver */
792 devices[i].controller_data = (void *) cs_pin;
793 }
794
795 spi_register_board_info(devices, nr_devices);
796
797 /* Configure SPI bus(es) */
798 if (enable_spi0) {
799 at91_set_A_periph(AT91_PIN_PB0, 0); /* SPI0_MISO */
800 at91_set_A_periph(AT91_PIN_PB1, 0); /* SPI0_MOSI */
801 at91_set_A_periph(AT91_PIN_PB2, 0); /* SPI0_SPCK */
802
Nicolas Ferre789b23b2009-06-26 15:36:58 +0100803 platform_device_register(&at91sam9g45_spi0_device);
804 }
805 if (enable_spi1) {
806 at91_set_A_periph(AT91_PIN_PB14, 0); /* SPI1_MISO */
807 at91_set_A_periph(AT91_PIN_PB15, 0); /* SPI1_MOSI */
808 at91_set_A_periph(AT91_PIN_PB16, 0); /* SPI1_SPCK */
809
Nicolas Ferre789b23b2009-06-26 15:36:58 +0100810 platform_device_register(&at91sam9g45_spi1_device);
811 }
812}
813#else
814void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
815#endif
816
817
818/* --------------------------------------------------------------------
Nicolas Ferre378ac652009-09-18 16:14:22 +0100819 * AC97
820 * -------------------------------------------------------------------- */
821
822#if defined(CONFIG_SND_ATMEL_AC97C) || defined(CONFIG_SND_ATMEL_AC97C_MODULE)
823static u64 ac97_dmamask = DMA_BIT_MASK(32);
824static struct ac97c_platform_data ac97_data;
825
826static struct resource ac97_resources[] = {
827 [0] = {
828 .start = AT91SAM9G45_BASE_AC97C,
829 .end = AT91SAM9G45_BASE_AC97C + SZ_16K - 1,
830 .flags = IORESOURCE_MEM,
831 },
832 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200833 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_AC97C,
834 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_AC97C,
Nicolas Ferre378ac652009-09-18 16:14:22 +0100835 .flags = IORESOURCE_IRQ,
836 },
837};
838
839static struct platform_device at91sam9g45_ac97_device = {
840 .name = "atmel_ac97c",
841 .id = 0,
842 .dev = {
843 .dma_mask = &ac97_dmamask,
844 .coherent_dma_mask = DMA_BIT_MASK(32),
845 .platform_data = &ac97_data,
846 },
847 .resource = ac97_resources,
848 .num_resources = ARRAY_SIZE(ac97_resources),
849};
850
851void __init at91_add_device_ac97(struct ac97c_platform_data *data)
852{
853 if (!data)
854 return;
855
856 at91_set_A_periph(AT91_PIN_PD8, 0); /* AC97FS */
857 at91_set_A_periph(AT91_PIN_PD9, 0); /* AC97CK */
858 at91_set_A_periph(AT91_PIN_PD7, 0); /* AC97TX */
859 at91_set_A_periph(AT91_PIN_PD6, 0); /* AC97RX */
860
861 /* reset */
Jean-Christophe PLAGNIOL-VILLARDcc9f9ae2011-09-19 15:28:25 +0800862 if (gpio_is_valid(data->reset_pin))
Nicolas Ferre378ac652009-09-18 16:14:22 +0100863 at91_set_gpio_output(data->reset_pin, 0);
864
865 ac97_data = *data;
866 platform_device_register(&at91sam9g45_ac97_device);
867}
868#else
869void __init at91_add_device_ac97(struct ac97c_platform_data *data) {}
870#endif
871
Josh Wu343754f2011-10-22 15:17:40 +0800872/* --------------------------------------------------------------------
873 * Image Sensor Interface
874 * -------------------------------------------------------------------- */
875#if defined(CONFIG_VIDEO_ATMEL_ISI) || defined(CONFIG_VIDEO_ATMEL_ISI_MODULE)
876static u64 isi_dmamask = DMA_BIT_MASK(32);
877static struct isi_platform_data isi_data;
878
879struct resource isi_resources[] = {
880 [0] = {
881 .start = AT91SAM9G45_BASE_ISI,
882 .end = AT91SAM9G45_BASE_ISI + SZ_16K - 1,
883 .flags = IORESOURCE_MEM,
884 },
885 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200886 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_ISI,
887 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_ISI,
Josh Wu343754f2011-10-22 15:17:40 +0800888 .flags = IORESOURCE_IRQ,
889 },
890};
891
892static struct platform_device at91sam9g45_isi_device = {
893 .name = "atmel_isi",
894 .id = 0,
895 .dev = {
896 .dma_mask = &isi_dmamask,
897 .coherent_dma_mask = DMA_BIT_MASK(32),
898 .platform_data = &isi_data,
899 },
900 .resource = isi_resources,
901 .num_resources = ARRAY_SIZE(isi_resources),
902};
903
904static struct clk_lookup isi_mck_lookups[] = {
905 CLKDEV_CON_DEV_ID("isi_mck", "atmel_isi.0", NULL),
906};
907
908void __init at91_add_device_isi(struct isi_platform_data *data,
909 bool use_pck_as_mck)
910{
911 struct clk *pck;
912 struct clk *parent;
913
914 if (!data)
915 return;
916 isi_data = *data;
917
918 at91_set_A_periph(AT91_PIN_PB20, 0); /* ISI_D0 */
919 at91_set_A_periph(AT91_PIN_PB21, 0); /* ISI_D1 */
920 at91_set_A_periph(AT91_PIN_PB22, 0); /* ISI_D2 */
921 at91_set_A_periph(AT91_PIN_PB23, 0); /* ISI_D3 */
922 at91_set_A_periph(AT91_PIN_PB24, 0); /* ISI_D4 */
923 at91_set_A_periph(AT91_PIN_PB25, 0); /* ISI_D5 */
924 at91_set_A_periph(AT91_PIN_PB26, 0); /* ISI_D6 */
925 at91_set_A_periph(AT91_PIN_PB27, 0); /* ISI_D7 */
926 at91_set_A_periph(AT91_PIN_PB28, 0); /* ISI_PCK */
927 at91_set_A_periph(AT91_PIN_PB30, 0); /* ISI_HSYNC */
928 at91_set_A_periph(AT91_PIN_PB29, 0); /* ISI_VSYNC */
929 at91_set_B_periph(AT91_PIN_PB8, 0); /* ISI_PD8 */
930 at91_set_B_periph(AT91_PIN_PB9, 0); /* ISI_PD9 */
931 at91_set_B_periph(AT91_PIN_PB10, 0); /* ISI_PD10 */
932 at91_set_B_periph(AT91_PIN_PB11, 0); /* ISI_PD11 */
933
934 platform_device_register(&at91sam9g45_isi_device);
935
936 if (use_pck_as_mck) {
937 at91_set_B_periph(AT91_PIN_PB31, 0); /* ISI_MCK (PCK1) */
938
939 pck = clk_get(NULL, "pck1");
940 parent = clk_get(NULL, "plla");
941
942 BUG_ON(IS_ERR(pck) || IS_ERR(parent));
943
944 if (clk_set_parent(pck, parent)) {
945 pr_err("Failed to set PCK's parent\n");
946 } else {
947 /* Register PCK as ISI_MCK */
948 isi_mck_lookups[0].clk = pck;
949 clkdev_add_table(isi_mck_lookups,
950 ARRAY_SIZE(isi_mck_lookups));
951 }
952
953 clk_put(pck);
954 clk_put(parent);
955 }
956}
957#else
958void __init at91_add_device_isi(struct isi_platform_data *data,
959 bool use_pck_as_mck) {}
960#endif
961
Nicolas Ferre378ac652009-09-18 16:14:22 +0100962
963/* --------------------------------------------------------------------
Nicolas Ferre789b23b2009-06-26 15:36:58 +0100964 * LCD Controller
965 * -------------------------------------------------------------------- */
966
967#if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
968static u64 lcdc_dmamask = DMA_BIT_MASK(32);
Jean-Christophe PLAGNIOL-VILLARD8af2c282013-03-28 22:53:42 +0800969static struct atmel_lcdfb_pdata lcdc_data;
Nicolas Ferre789b23b2009-06-26 15:36:58 +0100970
971static struct resource lcdc_resources[] = {
972 [0] = {
973 .start = AT91SAM9G45_LCDC_BASE,
974 .end = AT91SAM9G45_LCDC_BASE + SZ_4K - 1,
975 .flags = IORESOURCE_MEM,
976 },
977 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200978 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_LCDC,
979 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_LCDC,
Nicolas Ferre789b23b2009-06-26 15:36:58 +0100980 .flags = IORESOURCE_IRQ,
981 },
982};
983
984static struct platform_device at91_lcdc_device = {
Nicolas Ferre789b23b2009-06-26 15:36:58 +0100985 .id = 0,
986 .dev = {
987 .dma_mask = &lcdc_dmamask,
988 .coherent_dma_mask = DMA_BIT_MASK(32),
989 .platform_data = &lcdc_data,
990 },
991 .resource = lcdc_resources,
992 .num_resources = ARRAY_SIZE(lcdc_resources),
993};
994
Jean-Christophe PLAGNIOL-VILLARD8af2c282013-03-28 22:53:42 +0800995void __init at91_add_device_lcdc(struct atmel_lcdfb_pdata *data)
Nicolas Ferre789b23b2009-06-26 15:36:58 +0100996{
997 if (!data)
998 return;
999
Johan Hovoldbbd44f6b2013-02-07 16:31:58 +01001000 if (cpu_is_at91sam9g45es())
1001 at91_lcdc_device.name = "at91sam9g45es-lcdfb";
1002 else
1003 at91_lcdc_device.name = "at91sam9g45-lcdfb";
1004
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001005 at91_set_A_periph(AT91_PIN_PE0, 0); /* LCDDPWR */
1006
1007 at91_set_A_periph(AT91_PIN_PE2, 0); /* LCDCC */
1008 at91_set_A_periph(AT91_PIN_PE3, 0); /* LCDVSYNC */
1009 at91_set_A_periph(AT91_PIN_PE4, 0); /* LCDHSYNC */
1010 at91_set_A_periph(AT91_PIN_PE5, 0); /* LCDDOTCK */
1011 at91_set_A_periph(AT91_PIN_PE6, 0); /* LCDDEN */
1012 at91_set_A_periph(AT91_PIN_PE7, 0); /* LCDD0 */
1013 at91_set_A_periph(AT91_PIN_PE8, 0); /* LCDD1 */
1014 at91_set_A_periph(AT91_PIN_PE9, 0); /* LCDD2 */
1015 at91_set_A_periph(AT91_PIN_PE10, 0); /* LCDD3 */
1016 at91_set_A_periph(AT91_PIN_PE11, 0); /* LCDD4 */
1017 at91_set_A_periph(AT91_PIN_PE12, 0); /* LCDD5 */
1018 at91_set_A_periph(AT91_PIN_PE13, 0); /* LCDD6 */
1019 at91_set_A_periph(AT91_PIN_PE14, 0); /* LCDD7 */
1020 at91_set_A_periph(AT91_PIN_PE15, 0); /* LCDD8 */
1021 at91_set_A_periph(AT91_PIN_PE16, 0); /* LCDD9 */
1022 at91_set_A_periph(AT91_PIN_PE17, 0); /* LCDD10 */
1023 at91_set_A_periph(AT91_PIN_PE18, 0); /* LCDD11 */
1024 at91_set_A_periph(AT91_PIN_PE19, 0); /* LCDD12 */
1025 at91_set_A_periph(AT91_PIN_PE20, 0); /* LCDD13 */
1026 at91_set_A_periph(AT91_PIN_PE21, 0); /* LCDD14 */
1027 at91_set_A_periph(AT91_PIN_PE22, 0); /* LCDD15 */
1028 at91_set_A_periph(AT91_PIN_PE23, 0); /* LCDD16 */
1029 at91_set_A_periph(AT91_PIN_PE24, 0); /* LCDD17 */
1030 at91_set_A_periph(AT91_PIN_PE25, 0); /* LCDD18 */
1031 at91_set_A_periph(AT91_PIN_PE26, 0); /* LCDD19 */
1032 at91_set_A_periph(AT91_PIN_PE27, 0); /* LCDD20 */
1033 at91_set_A_periph(AT91_PIN_PE28, 0); /* LCDD21 */
1034 at91_set_A_periph(AT91_PIN_PE29, 0); /* LCDD22 */
1035 at91_set_A_periph(AT91_PIN_PE30, 0); /* LCDD23 */
1036
1037 lcdc_data = *data;
1038 platform_device_register(&at91_lcdc_device);
1039}
1040#else
Jean-Christophe PLAGNIOL-VILLARD8af2c282013-03-28 22:53:42 +08001041void __init at91_add_device_lcdc(struct atmel_lcdfb_pdata *data) {}
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001042#endif
1043
1044
1045/* --------------------------------------------------------------------
1046 * Timer/Counter block
1047 * -------------------------------------------------------------------- */
1048
1049#ifdef CONFIG_ATMEL_TCLIB
1050static struct resource tcb0_resources[] = {
1051 [0] = {
1052 .start = AT91SAM9G45_BASE_TCB0,
Nicolas Ferre29831292012-01-18 16:56:36 +01001053 .end = AT91SAM9G45_BASE_TCB0 + SZ_256 - 1,
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001054 .flags = IORESOURCE_MEM,
1055 },
1056 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +02001057 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_TCB,
1058 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_TCB,
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001059 .flags = IORESOURCE_IRQ,
1060 },
1061};
1062
1063static struct platform_device at91sam9g45_tcb0_device = {
1064 .name = "atmel_tcb",
1065 .id = 0,
1066 .resource = tcb0_resources,
1067 .num_resources = ARRAY_SIZE(tcb0_resources),
1068};
1069
1070/* TCB1 begins with TC3 */
1071static struct resource tcb1_resources[] = {
1072 [0] = {
1073 .start = AT91SAM9G45_BASE_TCB1,
Nicolas Ferre29831292012-01-18 16:56:36 +01001074 .end = AT91SAM9G45_BASE_TCB1 + SZ_256 - 1,
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001075 .flags = IORESOURCE_MEM,
1076 },
1077 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +02001078 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_TCB,
1079 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_TCB,
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001080 .flags = IORESOURCE_IRQ,
1081 },
1082};
1083
1084static struct platform_device at91sam9g45_tcb1_device = {
1085 .name = "atmel_tcb",
1086 .id = 1,
1087 .resource = tcb1_resources,
1088 .num_resources = ARRAY_SIZE(tcb1_resources),
1089};
1090
1091static void __init at91_add_device_tc(void)
1092{
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001093 platform_device_register(&at91sam9g45_tcb0_device);
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001094 platform_device_register(&at91sam9g45_tcb1_device);
1095}
1096#else
1097static void __init at91_add_device_tc(void) { }
1098#endif
1099
1100
1101/* --------------------------------------------------------------------
1102 * RTC
1103 * -------------------------------------------------------------------- */
1104
1105#if defined(CONFIG_RTC_DRV_AT91RM9200) || defined(CONFIG_RTC_DRV_AT91RM9200_MODULE)
Jean-Christophe PLAGNIOL-VILLARDd28bdfc2011-11-14 14:24:53 +08001106static struct resource rtc_resources[] = {
1107 [0] = {
1108 .start = AT91SAM9G45_BASE_RTC,
1109 .end = AT91SAM9G45_BASE_RTC + SZ_256 - 1,
1110 .flags = IORESOURCE_MEM,
1111 },
1112 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +02001113 .start = NR_IRQS_LEGACY + AT91_ID_SYS,
1114 .end = NR_IRQS_LEGACY + AT91_ID_SYS,
Jean-Christophe PLAGNIOL-VILLARDd28bdfc2011-11-14 14:24:53 +08001115 .flags = IORESOURCE_IRQ,
1116 },
1117};
1118
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001119static struct platform_device at91sam9g45_rtc_device = {
1120 .name = "at91_rtc",
1121 .id = -1,
Jean-Christophe PLAGNIOL-VILLARDd28bdfc2011-11-14 14:24:53 +08001122 .resource = rtc_resources,
1123 .num_resources = ARRAY_SIZE(rtc_resources),
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001124};
1125
1126static void __init at91_add_device_rtc(void)
1127{
1128 platform_device_register(&at91sam9g45_rtc_device);
1129}
1130#else
1131static void __init at91_add_device_rtc(void) {}
1132#endif
1133
1134
1135/* --------------------------------------------------------------------
Alexandre Belloni9d971622014-04-15 12:28:05 +02001136 * ADC and touchscreen
Maxime Ripard4a5920e2012-05-11 15:35:35 +02001137 * -------------------------------------------------------------------- */
1138
1139#if IS_ENABLED(CONFIG_AT91_ADC)
1140static struct at91_adc_data adc_data;
1141
1142static struct resource adc_resources[] = {
1143 [0] = {
1144 .start = AT91SAM9G45_BASE_TSC,
1145 .end = AT91SAM9G45_BASE_TSC + SZ_16K - 1,
1146 .flags = IORESOURCE_MEM,
1147 },
1148 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +02001149 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_TSC,
1150 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_TSC,
Maxime Ripard4a5920e2012-05-11 15:35:35 +02001151 .flags = IORESOURCE_IRQ,
1152 }
1153};
1154
1155static struct platform_device at91_adc_device = {
Alexandre Belloni142df132014-05-03 16:57:00 +01001156 .name = "at91sam9g45-adc",
Maxime Ripard4a5920e2012-05-11 15:35:35 +02001157 .id = -1,
1158 .dev = {
1159 .platform_data = &adc_data,
1160 },
1161 .resource = adc_resources,
1162 .num_resources = ARRAY_SIZE(adc_resources),
1163};
1164
1165static struct at91_adc_trigger at91_adc_triggers[] = {
1166 [0] = {
1167 .name = "external-rising",
1168 .value = 1,
1169 .is_external = true,
1170 },
1171 [1] = {
1172 .name = "external-falling",
1173 .value = 2,
1174 .is_external = true,
1175 },
1176 [2] = {
1177 .name = "external-any",
1178 .value = 3,
1179 .is_external = true,
1180 },
1181 [3] = {
1182 .name = "continuous",
1183 .value = 6,
1184 .is_external = false,
1185 },
1186};
1187
Maxime Ripard4a5920e2012-05-11 15:35:35 +02001188void __init at91_add_device_adc(struct at91_adc_data *data)
1189{
1190 if (!data)
1191 return;
1192
1193 if (test_bit(0, &data->channels_used))
1194 at91_set_gpio_input(AT91_PIN_PD20, 0);
1195 if (test_bit(1, &data->channels_used))
1196 at91_set_gpio_input(AT91_PIN_PD21, 0);
1197 if (test_bit(2, &data->channels_used))
1198 at91_set_gpio_input(AT91_PIN_PD22, 0);
1199 if (test_bit(3, &data->channels_used))
1200 at91_set_gpio_input(AT91_PIN_PD23, 0);
1201 if (test_bit(4, &data->channels_used))
1202 at91_set_gpio_input(AT91_PIN_PD24, 0);
1203 if (test_bit(5, &data->channels_used))
1204 at91_set_gpio_input(AT91_PIN_PD25, 0);
1205 if (test_bit(6, &data->channels_used))
1206 at91_set_gpio_input(AT91_PIN_PD26, 0);
1207 if (test_bit(7, &data->channels_used))
1208 at91_set_gpio_input(AT91_PIN_PD27, 0);
1209
1210 if (data->use_external_triggers)
1211 at91_set_A_periph(AT91_PIN_PD28, 0);
1212
Maxime Ripard4a5920e2012-05-11 15:35:35 +02001213 data->startup_time = 40;
Maxime Ripard4a5920e2012-05-11 15:35:35 +02001214 data->trigger_number = 4;
1215 data->trigger_list = at91_adc_triggers;
1216
1217 adc_data = *data;
1218 platform_device_register(&at91_adc_device);
1219}
1220#else
1221void __init at91_add_device_adc(struct at91_adc_data *data) {}
1222#endif
1223
1224/* --------------------------------------------------------------------
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001225 * RTT
1226 * -------------------------------------------------------------------- */
1227
1228static struct resource rtt_resources[] = {
1229 {
Jean-Christophe PLAGNIOL-VILLARDeab5fd62011-09-18 10:12:00 +08001230 .start = AT91SAM9G45_BASE_RTT,
1231 .end = AT91SAM9G45_BASE_RTT + SZ_16 - 1,
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001232 .flags = IORESOURCE_MEM,
Jean-Christophe PLAGNIOL-VILLARDb3af8b42012-02-15 21:24:46 +08001233 }, {
1234 .flags = IORESOURCE_MEM,
Ludovic Desrochese402af62012-08-14 11:19:22 +02001235 }, {
1236 .flags = IORESOURCE_IRQ,
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001237 }
1238};
1239
1240static struct platform_device at91sam9g45_rtt_device = {
1241 .name = "at91_rtt",
1242 .id = 0,
1243 .resource = rtt_resources,
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001244};
1245
Jean-Christophe PLAGNIOL-VILLARD205056a2012-02-15 20:51:37 +08001246#if IS_ENABLED(CONFIG_RTC_DRV_AT91SAM9)
1247static void __init at91_add_device_rtt_rtc(void)
1248{
1249 at91sam9g45_rtt_device.name = "rtc-at91sam9";
Jean-Christophe PLAGNIOL-VILLARDb3af8b42012-02-15 21:24:46 +08001250 /*
1251 * The second resource is needed:
1252 * GPBR will serve as the storage for RTC time offset
1253 */
Ludovic Desrochese402af62012-08-14 11:19:22 +02001254 at91sam9g45_rtt_device.num_resources = 3;
Jean-Christophe PLAGNIOL-VILLARDb3af8b42012-02-15 21:24:46 +08001255 rtt_resources[1].start = AT91SAM9G45_BASE_GPBR +
1256 4 * CONFIG_RTC_DRV_AT91SAM9_GPBR;
1257 rtt_resources[1].end = rtt_resources[1].start + 3;
Ludovic Desrochese402af62012-08-14 11:19:22 +02001258 rtt_resources[2].start = NR_IRQS_LEGACY + AT91_ID_SYS;
1259 rtt_resources[2].end = NR_IRQS_LEGACY + AT91_ID_SYS;
Jean-Christophe PLAGNIOL-VILLARD205056a2012-02-15 20:51:37 +08001260}
1261#else
Jean-Christophe PLAGNIOL-VILLARDb3af8b42012-02-15 21:24:46 +08001262static void __init at91_add_device_rtt_rtc(void)
1263{
1264 /* Only one resource is needed: RTT not used as RTC */
1265 at91sam9g45_rtt_device.num_resources = 1;
1266}
Jean-Christophe PLAGNIOL-VILLARD205056a2012-02-15 20:51:37 +08001267#endif
1268
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001269static void __init at91_add_device_rtt(void)
1270{
Jean-Christophe PLAGNIOL-VILLARD205056a2012-02-15 20:51:37 +08001271 at91_add_device_rtt_rtc();
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001272 platform_device_register(&at91sam9g45_rtt_device);
1273}
1274
1275
1276/* --------------------------------------------------------------------
Peter Korsgaard237a62a2011-10-06 17:41:33 +02001277 * TRNG
1278 * -------------------------------------------------------------------- */
1279
1280#if defined(CONFIG_HW_RANDOM_ATMEL) || defined(CONFIG_HW_RANDOM_ATMEL_MODULE)
1281static struct resource trng_resources[] = {
1282 {
1283 .start = AT91SAM9G45_BASE_TRNG,
1284 .end = AT91SAM9G45_BASE_TRNG + SZ_16K - 1,
1285 .flags = IORESOURCE_MEM,
1286 },
1287};
1288
1289static struct platform_device at91sam9g45_trng_device = {
1290 .name = "atmel-trng",
1291 .id = -1,
1292 .resource = trng_resources,
1293 .num_resources = ARRAY_SIZE(trng_resources),
1294};
1295
1296static void __init at91_add_device_trng(void)
1297{
1298 platform_device_register(&at91sam9g45_trng_device);
1299}
1300#else
1301static void __init at91_add_device_trng(void) {}
1302#endif
1303
1304/* --------------------------------------------------------------------
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001305 * Watchdog
1306 * -------------------------------------------------------------------- */
1307
Yegor Yefremov47263742009-10-20 08:39:41 +01001308#if defined(CONFIG_AT91SAM9X_WATCHDOG) || defined(CONFIG_AT91SAM9X_WATCHDOG_MODULE)
Jean-Christophe PLAGNIOL-VILLARDc1c30a22011-11-02 01:43:31 +08001309static struct resource wdt_resources[] = {
1310 {
1311 .start = AT91SAM9G45_BASE_WDT,
1312 .end = AT91SAM9G45_BASE_WDT + SZ_16 - 1,
1313 .flags = IORESOURCE_MEM,
1314 }
1315};
1316
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001317static struct platform_device at91sam9g45_wdt_device = {
1318 .name = "at91_wdt",
1319 .id = -1,
Jean-Christophe PLAGNIOL-VILLARDc1c30a22011-11-02 01:43:31 +08001320 .resource = wdt_resources,
1321 .num_resources = ARRAY_SIZE(wdt_resources),
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001322};
1323
1324static void __init at91_add_device_watchdog(void)
1325{
1326 platform_device_register(&at91sam9g45_wdt_device);
1327}
1328#else
1329static void __init at91_add_device_watchdog(void) {}
1330#endif
1331
1332
1333/* --------------------------------------------------------------------
1334 * PWM
1335 * --------------------------------------------------------------------*/
1336
Alexandre Bellonie0304272014-05-29 01:20:04 +02001337#if IS_ENABLED(CONFIG_PWM_ATMEL)
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001338static struct resource pwm_resources[] = {
1339 [0] = {
1340 .start = AT91SAM9G45_BASE_PWMC,
1341 .end = AT91SAM9G45_BASE_PWMC + SZ_16K - 1,
1342 .flags = IORESOURCE_MEM,
1343 },
1344 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +02001345 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_PWMC,
1346 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_PWMC,
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001347 .flags = IORESOURCE_IRQ,
1348 },
1349};
1350
1351static struct platform_device at91sam9g45_pwm0_device = {
Alexandre Bellonie0304272014-05-29 01:20:04 +02001352 .name = "at91sam9rl-pwm",
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001353 .id = -1,
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001354 .resource = pwm_resources,
1355 .num_resources = ARRAY_SIZE(pwm_resources),
1356};
1357
1358void __init at91_add_device_pwm(u32 mask)
1359{
1360 if (mask & (1 << AT91_PWM0))
1361 at91_set_B_periph(AT91_PIN_PD24, 1); /* enable PWM0 */
1362
1363 if (mask & (1 << AT91_PWM1))
1364 at91_set_B_periph(AT91_PIN_PD31, 1); /* enable PWM1 */
1365
1366 if (mask & (1 << AT91_PWM2))
1367 at91_set_B_periph(AT91_PIN_PD26, 1); /* enable PWM2 */
1368
1369 if (mask & (1 << AT91_PWM3))
1370 at91_set_B_periph(AT91_PIN_PD0, 1); /* enable PWM3 */
1371
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001372 platform_device_register(&at91sam9g45_pwm0_device);
1373}
1374#else
1375void __init at91_add_device_pwm(u32 mask) {}
1376#endif
1377
1378
1379/* --------------------------------------------------------------------
1380 * SSC -- Synchronous Serial Controller
1381 * -------------------------------------------------------------------- */
1382
1383#if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
1384static u64 ssc0_dmamask = DMA_BIT_MASK(32);
1385
1386static struct resource ssc0_resources[] = {
1387 [0] = {
1388 .start = AT91SAM9G45_BASE_SSC0,
1389 .end = AT91SAM9G45_BASE_SSC0 + SZ_16K - 1,
1390 .flags = IORESOURCE_MEM,
1391 },
1392 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +02001393 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_SSC0,
1394 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_SSC0,
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001395 .flags = IORESOURCE_IRQ,
1396 },
1397};
1398
1399static struct platform_device at91sam9g45_ssc0_device = {
Bo Shen636036d22012-11-06 13:57:51 +08001400 .name = "at91sam9g45_ssc",
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001401 .id = 0,
1402 .dev = {
1403 .dma_mask = &ssc0_dmamask,
1404 .coherent_dma_mask = DMA_BIT_MASK(32),
1405 },
1406 .resource = ssc0_resources,
1407 .num_resources = ARRAY_SIZE(ssc0_resources),
1408};
1409
1410static inline void configure_ssc0_pins(unsigned pins)
1411{
1412 if (pins & ATMEL_SSC_TF)
1413 at91_set_A_periph(AT91_PIN_PD1, 1);
1414 if (pins & ATMEL_SSC_TK)
1415 at91_set_A_periph(AT91_PIN_PD0, 1);
1416 if (pins & ATMEL_SSC_TD)
1417 at91_set_A_periph(AT91_PIN_PD2, 1);
1418 if (pins & ATMEL_SSC_RD)
1419 at91_set_A_periph(AT91_PIN_PD3, 1);
1420 if (pins & ATMEL_SSC_RK)
1421 at91_set_A_periph(AT91_PIN_PD4, 1);
1422 if (pins & ATMEL_SSC_RF)
1423 at91_set_A_periph(AT91_PIN_PD5, 1);
1424}
1425
1426static u64 ssc1_dmamask = DMA_BIT_MASK(32);
1427
1428static struct resource ssc1_resources[] = {
1429 [0] = {
1430 .start = AT91SAM9G45_BASE_SSC1,
1431 .end = AT91SAM9G45_BASE_SSC1 + SZ_16K - 1,
1432 .flags = IORESOURCE_MEM,
1433 },
1434 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +02001435 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_SSC1,
1436 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_SSC1,
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001437 .flags = IORESOURCE_IRQ,
1438 },
1439};
1440
1441static struct platform_device at91sam9g45_ssc1_device = {
Bo Shen636036d22012-11-06 13:57:51 +08001442 .name = "at91sam9g45_ssc",
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001443 .id = 1,
1444 .dev = {
1445 .dma_mask = &ssc1_dmamask,
1446 .coherent_dma_mask = DMA_BIT_MASK(32),
1447 },
1448 .resource = ssc1_resources,
1449 .num_resources = ARRAY_SIZE(ssc1_resources),
1450};
1451
1452static inline void configure_ssc1_pins(unsigned pins)
1453{
1454 if (pins & ATMEL_SSC_TF)
1455 at91_set_A_periph(AT91_PIN_PD14, 1);
1456 if (pins & ATMEL_SSC_TK)
1457 at91_set_A_periph(AT91_PIN_PD12, 1);
1458 if (pins & ATMEL_SSC_TD)
1459 at91_set_A_periph(AT91_PIN_PD10, 1);
1460 if (pins & ATMEL_SSC_RD)
1461 at91_set_A_periph(AT91_PIN_PD11, 1);
1462 if (pins & ATMEL_SSC_RK)
1463 at91_set_A_periph(AT91_PIN_PD13, 1);
1464 if (pins & ATMEL_SSC_RF)
1465 at91_set_A_periph(AT91_PIN_PD15, 1);
1466}
1467
1468/*
1469 * SSC controllers are accessed through library code, instead of any
1470 * kind of all-singing/all-dancing driver. For example one could be
1471 * used by a particular I2S audio codec's driver, while another one
1472 * on the same system might be used by a custom data capture driver.
1473 */
1474void __init at91_add_device_ssc(unsigned id, unsigned pins)
1475{
1476 struct platform_device *pdev;
1477
1478 /*
1479 * NOTE: caller is responsible for passing information matching
1480 * "pins" to whatever will be using each particular controller.
1481 */
1482 switch (id) {
1483 case AT91SAM9G45_ID_SSC0:
1484 pdev = &at91sam9g45_ssc0_device;
1485 configure_ssc0_pins(pins);
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001486 break;
1487 case AT91SAM9G45_ID_SSC1:
1488 pdev = &at91sam9g45_ssc1_device;
1489 configure_ssc1_pins(pins);
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001490 break;
1491 default:
1492 return;
1493 }
1494
1495 platform_device_register(pdev);
1496}
1497
1498#else
1499void __init at91_add_device_ssc(unsigned id, unsigned pins) {}
1500#endif
1501
1502
1503/* --------------------------------------------------------------------
1504 * UART
1505 * -------------------------------------------------------------------- */
1506
1507#if defined(CONFIG_SERIAL_ATMEL)
1508static struct resource dbgu_resources[] = {
1509 [0] = {
Jean-Christophe PLAGNIOL-VILLARD13079a72011-11-02 01:43:31 +08001510 .start = AT91SAM9G45_BASE_DBGU,
1511 .end = AT91SAM9G45_BASE_DBGU + SZ_512 - 1,
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001512 .flags = IORESOURCE_MEM,
1513 },
1514 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +02001515 .start = NR_IRQS_LEGACY + AT91_ID_SYS,
1516 .end = NR_IRQS_LEGACY + AT91_ID_SYS,
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001517 .flags = IORESOURCE_IRQ,
1518 },
1519};
1520
1521static struct atmel_uart_data dbgu_data = {
1522 .use_dma_tx = 0,
1523 .use_dma_rx = 0,
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001524};
1525
1526static u64 dbgu_dmamask = DMA_BIT_MASK(32);
1527
1528static struct platform_device at91sam9g45_dbgu_device = {
1529 .name = "atmel_usart",
1530 .id = 0,
1531 .dev = {
1532 .dma_mask = &dbgu_dmamask,
1533 .coherent_dma_mask = DMA_BIT_MASK(32),
1534 .platform_data = &dbgu_data,
1535 },
1536 .resource = dbgu_resources,
1537 .num_resources = ARRAY_SIZE(dbgu_resources),
1538};
1539
1540static inline void configure_dbgu_pins(void)
1541{
1542 at91_set_A_periph(AT91_PIN_PB12, 0); /* DRXD */
1543 at91_set_A_periph(AT91_PIN_PB13, 1); /* DTXD */
1544}
1545
1546static struct resource uart0_resources[] = {
1547 [0] = {
1548 .start = AT91SAM9G45_BASE_US0,
1549 .end = AT91SAM9G45_BASE_US0 + SZ_16K - 1,
1550 .flags = IORESOURCE_MEM,
1551 },
1552 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +02001553 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_US0,
1554 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_US0,
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001555 .flags = IORESOURCE_IRQ,
1556 },
1557};
1558
1559static struct atmel_uart_data uart0_data = {
1560 .use_dma_tx = 1,
1561 .use_dma_rx = 1,
1562};
1563
1564static u64 uart0_dmamask = DMA_BIT_MASK(32);
1565
1566static struct platform_device at91sam9g45_uart0_device = {
1567 .name = "atmel_usart",
1568 .id = 1,
1569 .dev = {
1570 .dma_mask = &uart0_dmamask,
1571 .coherent_dma_mask = DMA_BIT_MASK(32),
1572 .platform_data = &uart0_data,
1573 },
1574 .resource = uart0_resources,
1575 .num_resources = ARRAY_SIZE(uart0_resources),
1576};
1577
1578static inline void configure_usart0_pins(unsigned pins)
1579{
1580 at91_set_A_periph(AT91_PIN_PB19, 1); /* TXD0 */
1581 at91_set_A_periph(AT91_PIN_PB18, 0); /* RXD0 */
1582
1583 if (pins & ATMEL_UART_RTS)
1584 at91_set_B_periph(AT91_PIN_PB17, 0); /* RTS0 */
1585 if (pins & ATMEL_UART_CTS)
1586 at91_set_B_periph(AT91_PIN_PB15, 0); /* CTS0 */
1587}
1588
1589static struct resource uart1_resources[] = {
1590 [0] = {
1591 .start = AT91SAM9G45_BASE_US1,
1592 .end = AT91SAM9G45_BASE_US1 + SZ_16K - 1,
1593 .flags = IORESOURCE_MEM,
1594 },
1595 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +02001596 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_US1,
1597 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_US1,
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001598 .flags = IORESOURCE_IRQ,
1599 },
1600};
1601
1602static struct atmel_uart_data uart1_data = {
1603 .use_dma_tx = 1,
1604 .use_dma_rx = 1,
1605};
1606
1607static u64 uart1_dmamask = DMA_BIT_MASK(32);
1608
1609static struct platform_device at91sam9g45_uart1_device = {
1610 .name = "atmel_usart",
1611 .id = 2,
1612 .dev = {
1613 .dma_mask = &uart1_dmamask,
1614 .coherent_dma_mask = DMA_BIT_MASK(32),
1615 .platform_data = &uart1_data,
1616 },
1617 .resource = uart1_resources,
1618 .num_resources = ARRAY_SIZE(uart1_resources),
1619};
1620
1621static inline void configure_usart1_pins(unsigned pins)
1622{
1623 at91_set_A_periph(AT91_PIN_PB4, 1); /* TXD1 */
1624 at91_set_A_periph(AT91_PIN_PB5, 0); /* RXD1 */
1625
1626 if (pins & ATMEL_UART_RTS)
1627 at91_set_A_periph(AT91_PIN_PD16, 0); /* RTS1 */
1628 if (pins & ATMEL_UART_CTS)
1629 at91_set_A_periph(AT91_PIN_PD17, 0); /* CTS1 */
1630}
1631
1632static struct resource uart2_resources[] = {
1633 [0] = {
1634 .start = AT91SAM9G45_BASE_US2,
1635 .end = AT91SAM9G45_BASE_US2 + SZ_16K - 1,
1636 .flags = IORESOURCE_MEM,
1637 },
1638 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +02001639 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_US2,
1640 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_US2,
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001641 .flags = IORESOURCE_IRQ,
1642 },
1643};
1644
1645static struct atmel_uart_data uart2_data = {
1646 .use_dma_tx = 1,
1647 .use_dma_rx = 1,
1648};
1649
1650static u64 uart2_dmamask = DMA_BIT_MASK(32);
1651
1652static struct platform_device at91sam9g45_uart2_device = {
1653 .name = "atmel_usart",
1654 .id = 3,
1655 .dev = {
1656 .dma_mask = &uart2_dmamask,
1657 .coherent_dma_mask = DMA_BIT_MASK(32),
1658 .platform_data = &uart2_data,
1659 },
1660 .resource = uart2_resources,
1661 .num_resources = ARRAY_SIZE(uart2_resources),
1662};
1663
1664static inline void configure_usart2_pins(unsigned pins)
1665{
1666 at91_set_A_periph(AT91_PIN_PB6, 1); /* TXD2 */
1667 at91_set_A_periph(AT91_PIN_PB7, 0); /* RXD2 */
1668
1669 if (pins & ATMEL_UART_RTS)
1670 at91_set_B_periph(AT91_PIN_PC9, 0); /* RTS2 */
1671 if (pins & ATMEL_UART_CTS)
1672 at91_set_B_periph(AT91_PIN_PC11, 0); /* CTS2 */
1673}
1674
1675static struct resource uart3_resources[] = {
1676 [0] = {
1677 .start = AT91SAM9G45_BASE_US3,
1678 .end = AT91SAM9G45_BASE_US3 + SZ_16K - 1,
1679 .flags = IORESOURCE_MEM,
1680 },
1681 [1] = {
Ludovic Desroches8fe82a52012-06-21 14:47:27 +02001682 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_US3,
1683 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_US3,
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001684 .flags = IORESOURCE_IRQ,
1685 },
1686};
1687
1688static struct atmel_uart_data uart3_data = {
1689 .use_dma_tx = 1,
1690 .use_dma_rx = 1,
1691};
1692
1693static u64 uart3_dmamask = DMA_BIT_MASK(32);
1694
1695static struct platform_device at91sam9g45_uart3_device = {
1696 .name = "atmel_usart",
1697 .id = 4,
1698 .dev = {
1699 .dma_mask = &uart3_dmamask,
1700 .coherent_dma_mask = DMA_BIT_MASK(32),
1701 .platform_data = &uart3_data,
1702 },
1703 .resource = uart3_resources,
1704 .num_resources = ARRAY_SIZE(uart3_resources),
1705};
1706
1707static inline void configure_usart3_pins(unsigned pins)
1708{
1709 at91_set_A_periph(AT91_PIN_PB8, 1); /* TXD3 */
1710 at91_set_A_periph(AT91_PIN_PB9, 0); /* RXD3 */
1711
1712 if (pins & ATMEL_UART_RTS)
1713 at91_set_B_periph(AT91_PIN_PA23, 0); /* RTS3 */
1714 if (pins & ATMEL_UART_CTS)
1715 at91_set_B_periph(AT91_PIN_PA24, 0); /* CTS3 */
1716}
1717
1718static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001719
1720void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
1721{
1722 struct platform_device *pdev;
Jean-Christophe PLAGNIOL-VILLARD2b348e22011-04-10 14:10:05 +08001723 struct atmel_uart_data *pdata;
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001724
1725 switch (id) {
1726 case 0: /* DBGU */
1727 pdev = &at91sam9g45_dbgu_device;
1728 configure_dbgu_pins();
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001729 break;
1730 case AT91SAM9G45_ID_US0:
1731 pdev = &at91sam9g45_uart0_device;
1732 configure_usart0_pins(pins);
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001733 break;
1734 case AT91SAM9G45_ID_US1:
1735 pdev = &at91sam9g45_uart1_device;
1736 configure_usart1_pins(pins);
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001737 break;
1738 case AT91SAM9G45_ID_US2:
1739 pdev = &at91sam9g45_uart2_device;
1740 configure_usart2_pins(pins);
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001741 break;
1742 case AT91SAM9G45_ID_US3:
1743 pdev = &at91sam9g45_uart3_device;
1744 configure_usart3_pins(pins);
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001745 break;
1746 default:
1747 return;
1748 }
Jean-Christophe PLAGNIOL-VILLARD2b348e22011-04-10 14:10:05 +08001749 pdata = pdev->dev.platform_data;
1750 pdata->num = portnr; /* update to mapped ID */
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001751
1752 if (portnr < ATMEL_MAX_UART)
1753 at91_uarts[portnr] = pdev;
1754}
1755
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001756void __init at91_add_device_serial(void)
1757{
1758 int i;
1759
1760 for (i = 0; i < ATMEL_MAX_UART; i++) {
1761 if (at91_uarts[i])
1762 platform_device_register(at91_uarts[i]);
1763 }
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001764}
1765#else
1766void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001767void __init at91_add_device_serial(void) {}
1768#endif
1769
Nicolas Royer815e9722012-07-01 19:19:43 +02001770/* --------------------------------------------------------------------
1771 * SHA1/SHA256
1772 * -------------------------------------------------------------------- */
1773
1774#if defined(CONFIG_CRYPTO_DEV_ATMEL_SHA) || defined(CONFIG_CRYPTO_DEV_ATMEL_SHA_MODULE)
1775static struct resource sha_resources[] = {
1776 {
1777 .start = AT91SAM9G45_BASE_SHA,
1778 .end = AT91SAM9G45_BASE_SHA + SZ_16K - 1,
1779 .flags = IORESOURCE_MEM,
1780 },
1781 [1] = {
Nicolas Royer097965e2012-11-06 17:31:03 +01001782 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_AESTDESSHA,
1783 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_AESTDESSHA,
Nicolas Royer815e9722012-07-01 19:19:43 +02001784 .flags = IORESOURCE_IRQ,
1785 },
1786};
1787
1788static struct platform_device at91sam9g45_sha_device = {
1789 .name = "atmel_sha",
1790 .id = -1,
1791 .resource = sha_resources,
1792 .num_resources = ARRAY_SIZE(sha_resources),
1793};
1794
1795static void __init at91_add_device_sha(void)
1796{
1797 platform_device_register(&at91sam9g45_sha_device);
1798}
1799#else
1800static void __init at91_add_device_sha(void) {}
1801#endif
1802
1803/* --------------------------------------------------------------------
1804 * DES/TDES
1805 * -------------------------------------------------------------------- */
1806
1807#if defined(CONFIG_CRYPTO_DEV_ATMEL_TDES) || defined(CONFIG_CRYPTO_DEV_ATMEL_TDES_MODULE)
1808static struct resource tdes_resources[] = {
1809 [0] = {
1810 .start = AT91SAM9G45_BASE_TDES,
1811 .end = AT91SAM9G45_BASE_TDES + SZ_16K - 1,
1812 .flags = IORESOURCE_MEM,
1813 },
1814 [1] = {
Nicolas Royer097965e2012-11-06 17:31:03 +01001815 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_AESTDESSHA,
1816 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_AESTDESSHA,
Nicolas Royer815e9722012-07-01 19:19:43 +02001817 .flags = IORESOURCE_IRQ,
1818 },
1819};
1820
1821static struct platform_device at91sam9g45_tdes_device = {
1822 .name = "atmel_tdes",
1823 .id = -1,
1824 .resource = tdes_resources,
1825 .num_resources = ARRAY_SIZE(tdes_resources),
1826};
1827
1828static void __init at91_add_device_tdes(void)
1829{
1830 platform_device_register(&at91sam9g45_tdes_device);
1831}
1832#else
1833static void __init at91_add_device_tdes(void) {}
1834#endif
1835
1836/* --------------------------------------------------------------------
1837 * AES
1838 * -------------------------------------------------------------------- */
1839
1840#if defined(CONFIG_CRYPTO_DEV_ATMEL_AES) || defined(CONFIG_CRYPTO_DEV_ATMEL_AES_MODULE)
Nicolas Royer6150f3b2013-02-20 17:10:23 +01001841static struct crypto_platform_data aes_data;
1842static struct crypto_dma_data alt_atslave;
Nicolas Royer815e9722012-07-01 19:19:43 +02001843static u64 aes_dmamask = DMA_BIT_MASK(32);
1844
1845static struct resource aes_resources[] = {
1846 [0] = {
1847 .start = AT91SAM9G45_BASE_AES,
1848 .end = AT91SAM9G45_BASE_AES + SZ_16K - 1,
1849 .flags = IORESOURCE_MEM,
1850 },
1851 [1] = {
Nicolas Royer097965e2012-11-06 17:31:03 +01001852 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_AESTDESSHA,
1853 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_AESTDESSHA,
Nicolas Royer815e9722012-07-01 19:19:43 +02001854 .flags = IORESOURCE_IRQ,
1855 },
1856};
1857
1858static struct platform_device at91sam9g45_aes_device = {
1859 .name = "atmel_aes",
1860 .id = -1,
1861 .dev = {
1862 .dma_mask = &aes_dmamask,
1863 .coherent_dma_mask = DMA_BIT_MASK(32),
1864 .platform_data = &aes_data,
1865 },
1866 .resource = aes_resources,
1867 .num_resources = ARRAY_SIZE(aes_resources),
1868};
1869
1870static void __init at91_add_device_aes(void)
1871{
1872 struct at_dma_slave *atslave;
Nicolas Royer815e9722012-07-01 19:19:43 +02001873
1874 /* DMA TX slave channel configuration */
Nicolas Royer6150f3b2013-02-20 17:10:23 +01001875 atslave = &alt_atslave.txdata;
Nicolas Royer815e9722012-07-01 19:19:43 +02001876 atslave->dma_dev = &at_hdmac_device.dev;
1877 atslave->cfg = ATC_FIFOCFG_ENOUGHSPACE | ATC_SRC_H2SEL_HW |
1878 ATC_SRC_PER(AT_DMA_ID_AES_RX);
1879
1880 /* DMA RX slave channel configuration */
Nicolas Royer6150f3b2013-02-20 17:10:23 +01001881 atslave = &alt_atslave.rxdata;
Nicolas Royer815e9722012-07-01 19:19:43 +02001882 atslave->dma_dev = &at_hdmac_device.dev;
1883 atslave->cfg = ATC_FIFOCFG_ENOUGHSPACE | ATC_DST_H2SEL_HW |
1884 ATC_DST_PER(AT_DMA_ID_AES_TX);
1885
Nicolas Royer6150f3b2013-02-20 17:10:23 +01001886 aes_data.dma_slave = &alt_atslave;
Nicolas Royer815e9722012-07-01 19:19:43 +02001887 platform_device_register(&at91sam9g45_aes_device);
1888}
1889#else
1890static void __init at91_add_device_aes(void) {}
1891#endif
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001892
1893/* -------------------------------------------------------------------- */
1894/*
1895 * These devices are always present and don't need any board-specific
1896 * setup.
1897 */
1898static int __init at91_add_standard_devices(void)
1899{
Jean-Christophe PLAGNIOL-VILLARD8cf93b92012-02-28 15:23:43 +08001900 if (of_have_populated_dt())
1901 return 0;
1902
Nicolas Ferre40262b22009-07-24 11:43:01 +01001903 at91_add_device_hdmac();
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001904 at91_add_device_rtc();
1905 at91_add_device_rtt();
Peter Korsgaard237a62a2011-10-06 17:41:33 +02001906 at91_add_device_trng();
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001907 at91_add_device_watchdog();
1908 at91_add_device_tc();
Nicolas Royer815e9722012-07-01 19:19:43 +02001909 at91_add_device_sha();
1910 at91_add_device_tdes();
1911 at91_add_device_aes();
Nicolas Ferre789b23b2009-06-26 15:36:58 +01001912 return 0;
1913}
1914
1915arch_initcall(at91_add_standard_devices);