Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 Atmel Corporation |
| 3 | * |
| 4 | * This file is subject to the terms and conditions of the GNU General Public |
| 5 | * License. See the file COPYING in the main directory of this archive for |
| 6 | * more details. |
| 7 | */ |
| 8 | |
| 9 | #include <asm/mach/arch.h> |
| 10 | #include <asm/mach/map.h> |
| 11 | |
Andrew Victor | c6686ff | 2008-01-23 09:13:53 +0100 | [diff] [blame] | 12 | #include <linux/dma-mapping.h> |
Russell King | 2f8163b | 2011-07-26 10:53:52 +0100 | [diff] [blame] | 13 | #include <linux/gpio.h> |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 14 | #include <linux/platform_device.h> |
Andrew Victor | f230d3f | 2007-11-19 13:47:20 +0100 | [diff] [blame] | 15 | #include <linux/i2c-gpio.h> |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 16 | |
Andrew Victor | f230d3f | 2007-11-19 13:47:20 +0100 | [diff] [blame] | 17 | #include <linux/fb.h> |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 18 | #include <video/atmel_lcdc.h> |
| 19 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 20 | #include <mach/at91sam9rl.h> |
| 21 | #include <mach/at91sam9rl_matrix.h> |
Jean-Christophe PLAGNIOL-VILLARD | 4342d64 | 2011-11-27 23:15:50 +0800 | [diff] [blame] | 22 | #include <mach/at91_matrix.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 23 | #include <mach/at91sam9_smc.h> |
Uwe Kleine-König | ac11a1d | 2013-11-14 10:49:19 +0100 | [diff] [blame] | 24 | #include <mach/hardware.h> |
Arnd Bergmann | 7cdc39e | 2012-08-24 15:10:04 +0200 | [diff] [blame] | 25 | #include <linux/platform_data/dma-atmel.h> |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 26 | |
Jean-Christophe PLAGNIOL-VILLARD | 43d2f53 | 2012-10-30 05:14:17 +0800 | [diff] [blame] | 27 | #include "board.h" |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 28 | #include "generic.h" |
| 29 | |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 30 | |
| 31 | /* -------------------------------------------------------------------- |
Nicolas Ferre | 6ff89e9 | 2009-07-24 11:43:00 +0100 | [diff] [blame] | 32 | * HDMAC - AHB DMA Controller |
| 33 | * -------------------------------------------------------------------- */ |
| 34 | |
| 35 | #if defined(CONFIG_AT_HDMAC) || defined(CONFIG_AT_HDMAC_MODULE) |
| 36 | static u64 hdmac_dmamask = DMA_BIT_MASK(32); |
| 37 | |
Nicolas Ferre | 6ff89e9 | 2009-07-24 11:43:00 +0100 | [diff] [blame] | 38 | static struct resource hdmac_resources[] = { |
| 39 | [0] = { |
Jean-Christophe PLAGNIOL-VILLARD | 9627b20 | 2011-10-15 15:47:51 +0800 | [diff] [blame] | 40 | .start = AT91SAM9RL_BASE_DMA, |
| 41 | .end = AT91SAM9RL_BASE_DMA + SZ_512 - 1, |
Nicolas Ferre | 6ff89e9 | 2009-07-24 11:43:00 +0100 | [diff] [blame] | 42 | .flags = IORESOURCE_MEM, |
| 43 | }, |
| 44 | [2] = { |
Ludovic Desroches | 8fe82a5 | 2012-06-21 14:47:27 +0200 | [diff] [blame] | 45 | .start = NR_IRQS_LEGACY + AT91SAM9RL_ID_DMA, |
| 46 | .end = NR_IRQS_LEGACY + AT91SAM9RL_ID_DMA, |
Nicolas Ferre | 6ff89e9 | 2009-07-24 11:43:00 +0100 | [diff] [blame] | 47 | .flags = IORESOURCE_IRQ, |
| 48 | }, |
| 49 | }; |
| 50 | |
| 51 | static struct platform_device at_hdmac_device = { |
Nicolas Ferre | bdad0b9 | 2011-10-10 14:55:17 +0200 | [diff] [blame] | 52 | .name = "at91sam9rl_dma", |
Nicolas Ferre | 6ff89e9 | 2009-07-24 11:43:00 +0100 | [diff] [blame] | 53 | .id = -1, |
| 54 | .dev = { |
| 55 | .dma_mask = &hdmac_dmamask, |
| 56 | .coherent_dma_mask = DMA_BIT_MASK(32), |
Nicolas Ferre | 6ff89e9 | 2009-07-24 11:43:00 +0100 | [diff] [blame] | 57 | }, |
| 58 | .resource = hdmac_resources, |
| 59 | .num_resources = ARRAY_SIZE(hdmac_resources), |
| 60 | }; |
| 61 | |
| 62 | void __init at91_add_device_hdmac(void) |
| 63 | { |
Nicolas Ferre | 6ff89e9 | 2009-07-24 11:43:00 +0100 | [diff] [blame] | 64 | platform_device_register(&at_hdmac_device); |
| 65 | } |
| 66 | #else |
| 67 | void __init at91_add_device_hdmac(void) {} |
| 68 | #endif |
| 69 | |
| 70 | /* -------------------------------------------------------------------- |
Nicolas Ferre | ba45ca4 | 2008-04-08 13:59:18 +0100 | [diff] [blame] | 71 | * USB HS Device (Gadget) |
| 72 | * -------------------------------------------------------------------- */ |
| 73 | |
Jochen Friedrich | dd0b382 | 2011-10-25 20:51:06 +0200 | [diff] [blame] | 74 | #if defined(CONFIG_USB_ATMEL_USBA) || defined(CONFIG_USB_ATMEL_USBA_MODULE) |
Nicolas Ferre | ba45ca4 | 2008-04-08 13:59:18 +0100 | [diff] [blame] | 75 | |
| 76 | static struct resource usba_udc_resources[] = { |
| 77 | [0] = { |
| 78 | .start = AT91SAM9RL_UDPHS_FIFO, |
| 79 | .end = AT91SAM9RL_UDPHS_FIFO + SZ_512K - 1, |
| 80 | .flags = IORESOURCE_MEM, |
| 81 | }, |
| 82 | [1] = { |
| 83 | .start = AT91SAM9RL_BASE_UDPHS, |
| 84 | .end = AT91SAM9RL_BASE_UDPHS + SZ_1K - 1, |
| 85 | .flags = IORESOURCE_MEM, |
| 86 | }, |
| 87 | [2] = { |
Ludovic Desroches | 8fe82a5 | 2012-06-21 14:47:27 +0200 | [diff] [blame] | 88 | .start = NR_IRQS_LEGACY + AT91SAM9RL_ID_UDPHS, |
| 89 | .end = NR_IRQS_LEGACY + AT91SAM9RL_ID_UDPHS, |
Nicolas Ferre | ba45ca4 | 2008-04-08 13:59:18 +0100 | [diff] [blame] | 90 | .flags = IORESOURCE_IRQ, |
| 91 | }, |
| 92 | }; |
| 93 | |
| 94 | #define EP(nam, idx, maxpkt, maxbk, dma, isoc) \ |
| 95 | [idx] = { \ |
| 96 | .name = nam, \ |
| 97 | .index = idx, \ |
| 98 | .fifo_size = maxpkt, \ |
| 99 | .nr_banks = maxbk, \ |
| 100 | .can_dma = dma, \ |
| 101 | .can_isoc = isoc, \ |
| 102 | } |
| 103 | |
| 104 | static struct usba_ep_data usba_udc_ep[] __initdata = { |
| 105 | EP("ep0", 0, 64, 1, 0, 0), |
| 106 | EP("ep1", 1, 1024, 2, 1, 1), |
| 107 | EP("ep2", 2, 1024, 2, 1, 1), |
| 108 | EP("ep3", 3, 1024, 3, 1, 0), |
| 109 | EP("ep4", 4, 1024, 3, 1, 0), |
| 110 | EP("ep5", 5, 1024, 3, 1, 1), |
| 111 | EP("ep6", 6, 1024, 3, 1, 1), |
| 112 | }; |
| 113 | |
| 114 | #undef EP |
| 115 | |
| 116 | /* |
| 117 | * pdata doesn't have room for any endpoints, so we need to |
| 118 | * append room for the ones we need right after it. |
| 119 | */ |
| 120 | static struct { |
| 121 | struct usba_platform_data pdata; |
| 122 | struct usba_ep_data ep[7]; |
| 123 | } usba_udc_data; |
| 124 | |
| 125 | static struct platform_device at91_usba_udc_device = { |
| 126 | .name = "atmel_usba_udc", |
| 127 | .id = -1, |
| 128 | .dev = { |
| 129 | .platform_data = &usba_udc_data.pdata, |
| 130 | }, |
| 131 | .resource = usba_udc_resources, |
| 132 | .num_resources = ARRAY_SIZE(usba_udc_resources), |
| 133 | }; |
| 134 | |
| 135 | void __init at91_add_device_usba(struct usba_platform_data *data) |
| 136 | { |
| 137 | /* |
| 138 | * Invalid pins are 0 on AT91, but the usba driver is shared |
| 139 | * with AVR32, which use negative values instead. Once/if |
| 140 | * gpio_is_valid() is ported to AT91, revisit this code. |
| 141 | */ |
| 142 | usba_udc_data.pdata.vbus_pin = -EINVAL; |
| 143 | usba_udc_data.pdata.num_ep = ARRAY_SIZE(usba_udc_ep); |
Justin P. Mattock | 6eab04a | 2011-04-08 19:49:08 -0700 | [diff] [blame] | 144 | memcpy(usba_udc_data.ep, usba_udc_ep, sizeof(usba_udc_ep)); |
Nicolas Ferre | ba45ca4 | 2008-04-08 13:59:18 +0100 | [diff] [blame] | 145 | |
Jean-Christophe PLAGNIOL-VILLARD | cc9f9ae | 2011-09-19 15:28:25 +0800 | [diff] [blame] | 146 | if (data && gpio_is_valid(data->vbus_pin)) { |
Nicolas Ferre | ba45ca4 | 2008-04-08 13:59:18 +0100 | [diff] [blame] | 147 | at91_set_gpio_input(data->vbus_pin, 0); |
| 148 | at91_set_deglitch(data->vbus_pin, 1); |
| 149 | usba_udc_data.pdata.vbus_pin = data->vbus_pin; |
| 150 | } |
| 151 | |
| 152 | /* Pullup pin is handled internally by USB device peripheral */ |
| 153 | |
Nicolas Ferre | ba45ca4 | 2008-04-08 13:59:18 +0100 | [diff] [blame] | 154 | platform_device_register(&at91_usba_udc_device); |
| 155 | } |
| 156 | #else |
| 157 | void __init at91_add_device_usba(struct usba_platform_data *data) {} |
| 158 | #endif |
| 159 | |
| 160 | |
| 161 | /* -------------------------------------------------------------------- |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 162 | * MMC / SD |
| 163 | * -------------------------------------------------------------------- */ |
| 164 | |
Ludovic Desroches | 4cf3326 | 2012-05-21 12:23:27 +0200 | [diff] [blame] | 165 | #if IS_ENABLED(CONFIG_MMC_ATMELMCI) |
Andrew Victor | c6686ff | 2008-01-23 09:13:53 +0100 | [diff] [blame] | 166 | static u64 mmc_dmamask = DMA_BIT_MASK(32); |
Ludovic Desroches | 4cf3326 | 2012-05-21 12:23:27 +0200 | [diff] [blame] | 167 | static struct mci_platform_data mmc_data; |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 168 | |
| 169 | static struct resource mmc_resources[] = { |
| 170 | [0] = { |
| 171 | .start = AT91SAM9RL_BASE_MCI, |
| 172 | .end = AT91SAM9RL_BASE_MCI + SZ_16K - 1, |
| 173 | .flags = IORESOURCE_MEM, |
| 174 | }, |
| 175 | [1] = { |
Ludovic Desroches | 8fe82a5 | 2012-06-21 14:47:27 +0200 | [diff] [blame] | 176 | .start = NR_IRQS_LEGACY + AT91SAM9RL_ID_MCI, |
| 177 | .end = NR_IRQS_LEGACY + AT91SAM9RL_ID_MCI, |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 178 | .flags = IORESOURCE_IRQ, |
| 179 | }, |
| 180 | }; |
| 181 | |
| 182 | static struct platform_device at91sam9rl_mmc_device = { |
Ludovic Desroches | 4cf3326 | 2012-05-21 12:23:27 +0200 | [diff] [blame] | 183 | .name = "atmel_mci", |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 184 | .id = -1, |
| 185 | .dev = { |
| 186 | .dma_mask = &mmc_dmamask, |
Andrew Victor | c6686ff | 2008-01-23 09:13:53 +0100 | [diff] [blame] | 187 | .coherent_dma_mask = DMA_BIT_MASK(32), |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 188 | .platform_data = &mmc_data, |
| 189 | }, |
| 190 | .resource = mmc_resources, |
| 191 | .num_resources = ARRAY_SIZE(mmc_resources), |
| 192 | }; |
| 193 | |
Ludovic Desroches | 4cf3326 | 2012-05-21 12:23:27 +0200 | [diff] [blame] | 194 | void __init at91_add_device_mci(short mmc_id, struct mci_platform_data *data) |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 195 | { |
| 196 | if (!data) |
| 197 | return; |
| 198 | |
Ludovic Desroches | 4cf3326 | 2012-05-21 12:23:27 +0200 | [diff] [blame] | 199 | if (data->slot[0].bus_width) { |
| 200 | /* input/irq */ |
| 201 | if (gpio_is_valid(data->slot[0].detect_pin)) { |
| 202 | at91_set_gpio_input(data->slot[0].detect_pin, 1); |
| 203 | at91_set_deglitch(data->slot[0].detect_pin, 1); |
| 204 | } |
| 205 | if (gpio_is_valid(data->slot[0].wp_pin)) |
| 206 | at91_set_gpio_input(data->slot[0].wp_pin, 1); |
| 207 | |
| 208 | /* CLK */ |
| 209 | at91_set_A_periph(AT91_PIN_PA2, 0); |
| 210 | |
| 211 | /* CMD */ |
| 212 | at91_set_A_periph(AT91_PIN_PA1, 1); |
| 213 | |
| 214 | /* DAT0, maybe DAT1..DAT3 */ |
| 215 | at91_set_A_periph(AT91_PIN_PA0, 1); |
| 216 | if (data->slot[0].bus_width == 4) { |
| 217 | at91_set_A_periph(AT91_PIN_PA3, 1); |
| 218 | at91_set_A_periph(AT91_PIN_PA4, 1); |
| 219 | at91_set_A_periph(AT91_PIN_PA5, 1); |
| 220 | } |
| 221 | |
| 222 | mmc_data = *data; |
| 223 | platform_device_register(&at91sam9rl_mmc_device); |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 224 | } |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 225 | } |
| 226 | #else |
Ludovic Desroches | 4cf3326 | 2012-05-21 12:23:27 +0200 | [diff] [blame] | 227 | void __init at91_add_device_mci(short mmc_id, struct mci_platform_data *data) {} |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 228 | #endif |
| 229 | |
| 230 | |
| 231 | /* -------------------------------------------------------------------- |
| 232 | * NAND / SmartMedia |
| 233 | * -------------------------------------------------------------------- */ |
| 234 | |
Pieter du Preez | f6ed6f7 | 2008-08-01 10:06:40 +0100 | [diff] [blame] | 235 | #if defined(CONFIG_MTD_NAND_ATMEL) || defined(CONFIG_MTD_NAND_ATMEL_MODULE) |
Håvard Skinnemoen | 3c3796c | 2008-06-06 18:04:53 +0200 | [diff] [blame] | 236 | static struct atmel_nand_data nand_data; |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 237 | |
| 238 | #define NAND_BASE AT91_CHIPSELECT_3 |
| 239 | |
| 240 | static struct resource nand_resources[] = { |
Andrew Victor | d7a2415 | 2008-04-02 21:44:44 +0100 | [diff] [blame] | 241 | [0] = { |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 242 | .start = NAND_BASE, |
| 243 | .end = NAND_BASE + SZ_256M - 1, |
| 244 | .flags = IORESOURCE_MEM, |
Andrew Victor | d7a2415 | 2008-04-02 21:44:44 +0100 | [diff] [blame] | 245 | }, |
| 246 | [1] = { |
Jean-Christophe PLAGNIOL-VILLARD | d28edd1 | 2011-09-18 09:31:56 +0800 | [diff] [blame] | 247 | .start = AT91SAM9RL_BASE_ECC, |
| 248 | .end = AT91SAM9RL_BASE_ECC + SZ_512 - 1, |
Andrew Victor | d7a2415 | 2008-04-02 21:44:44 +0100 | [diff] [blame] | 249 | .flags = IORESOURCE_MEM, |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 250 | } |
| 251 | }; |
| 252 | |
Håvard Skinnemoen | 3c3796c | 2008-06-06 18:04:53 +0200 | [diff] [blame] | 253 | static struct platform_device atmel_nand_device = { |
| 254 | .name = "atmel_nand", |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 255 | .id = -1, |
| 256 | .dev = { |
| 257 | .platform_data = &nand_data, |
| 258 | }, |
| 259 | .resource = nand_resources, |
| 260 | .num_resources = ARRAY_SIZE(nand_resources), |
| 261 | }; |
| 262 | |
Håvard Skinnemoen | 3c3796c | 2008-06-06 18:04:53 +0200 | [diff] [blame] | 263 | void __init at91_add_device_nand(struct atmel_nand_data *data) |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 264 | { |
| 265 | unsigned long csa; |
| 266 | |
| 267 | if (!data) |
| 268 | return; |
| 269 | |
Jean-Christophe PLAGNIOL-VILLARD | 4342d64 | 2011-11-27 23:15:50 +0800 | [diff] [blame] | 270 | csa = at91_matrix_read(AT91_MATRIX_EBICSA); |
| 271 | at91_matrix_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_CS3A_SMC_SMARTMEDIA); |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 272 | |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 273 | /* enable pin */ |
Jean-Christophe PLAGNIOL-VILLARD | cc9f9ae | 2011-09-19 15:28:25 +0800 | [diff] [blame] | 274 | if (gpio_is_valid(data->enable_pin)) |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 275 | at91_set_gpio_output(data->enable_pin, 1); |
| 276 | |
| 277 | /* ready/busy pin */ |
Jean-Christophe PLAGNIOL-VILLARD | cc9f9ae | 2011-09-19 15:28:25 +0800 | [diff] [blame] | 278 | if (gpio_is_valid(data->rdy_pin)) |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 279 | at91_set_gpio_input(data->rdy_pin, 1); |
| 280 | |
| 281 | /* card detect pin */ |
Jean-Christophe PLAGNIOL-VILLARD | cc9f9ae | 2011-09-19 15:28:25 +0800 | [diff] [blame] | 282 | if (gpio_is_valid(data->det_pin)) |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 283 | at91_set_gpio_input(data->det_pin, 1); |
| 284 | |
| 285 | at91_set_A_periph(AT91_PIN_PB4, 0); /* NANDOE */ |
| 286 | at91_set_A_periph(AT91_PIN_PB5, 0); /* NANDWE */ |
| 287 | |
| 288 | nand_data = *data; |
Håvard Skinnemoen | 3c3796c | 2008-06-06 18:04:53 +0200 | [diff] [blame] | 289 | platform_device_register(&atmel_nand_device); |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | #else |
Håvard Skinnemoen | 3c3796c | 2008-06-06 18:04:53 +0200 | [diff] [blame] | 293 | void __init at91_add_device_nand(struct atmel_nand_data *data) {} |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 294 | #endif |
| 295 | |
| 296 | |
| 297 | /* -------------------------------------------------------------------- |
| 298 | * TWI (i2c) |
| 299 | * -------------------------------------------------------------------- */ |
| 300 | |
Andrew Victor | f230d3f | 2007-11-19 13:47:20 +0100 | [diff] [blame] | 301 | /* |
| 302 | * Prefer the GPIO code since the TWI controller isn't robust |
| 303 | * (gets overruns and underruns under load) and can only issue |
| 304 | * repeated STARTs in one scenario (the driver doesn't yet handle them). |
| 305 | */ |
| 306 | #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE) |
| 307 | |
| 308 | static struct i2c_gpio_platform_data pdata = { |
| 309 | .sda_pin = AT91_PIN_PA23, |
| 310 | .sda_is_open_drain = 1, |
| 311 | .scl_pin = AT91_PIN_PA24, |
| 312 | .scl_is_open_drain = 1, |
| 313 | .udelay = 2, /* ~100 kHz */ |
| 314 | }; |
| 315 | |
| 316 | static struct platform_device at91sam9rl_twi_device = { |
| 317 | .name = "i2c-gpio", |
Bo Shen | 7840487 | 2012-10-15 17:30:27 +0800 | [diff] [blame] | 318 | .id = 0, |
Andrew Victor | f230d3f | 2007-11-19 13:47:20 +0100 | [diff] [blame] | 319 | .dev.platform_data = &pdata, |
| 320 | }; |
| 321 | |
| 322 | void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) |
| 323 | { |
| 324 | at91_set_GPIO_periph(AT91_PIN_PA23, 1); /* TWD (SDA) */ |
| 325 | at91_set_multi_drive(AT91_PIN_PA23, 1); |
| 326 | |
| 327 | at91_set_GPIO_periph(AT91_PIN_PA24, 1); /* TWCK (SCL) */ |
| 328 | at91_set_multi_drive(AT91_PIN_PA24, 1); |
| 329 | |
| 330 | i2c_register_board_info(0, devices, nr_devices); |
| 331 | platform_device_register(&at91sam9rl_twi_device); |
| 332 | } |
| 333 | |
| 334 | #elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE) |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 335 | |
| 336 | static struct resource twi_resources[] = { |
| 337 | [0] = { |
| 338 | .start = AT91SAM9RL_BASE_TWI0, |
| 339 | .end = AT91SAM9RL_BASE_TWI0 + SZ_16K - 1, |
| 340 | .flags = IORESOURCE_MEM, |
| 341 | }, |
| 342 | [1] = { |
Ludovic Desroches | 8fe82a5 | 2012-06-21 14:47:27 +0200 | [diff] [blame] | 343 | .start = NR_IRQS_LEGACY + AT91SAM9RL_ID_TWI0, |
| 344 | .end = NR_IRQS_LEGACY + AT91SAM9RL_ID_TWI0, |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 345 | .flags = IORESOURCE_IRQ, |
| 346 | }, |
| 347 | }; |
| 348 | |
| 349 | static struct platform_device at91sam9rl_twi_device = { |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 350 | .name = "i2c-at91sam9g20", |
Bo Shen | 302090a | 2012-10-15 17:30:28 +0800 | [diff] [blame] | 351 | .id = 0, |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 352 | .resource = twi_resources, |
| 353 | .num_resources = ARRAY_SIZE(twi_resources), |
| 354 | }; |
| 355 | |
Andrew Victor | f230d3f | 2007-11-19 13:47:20 +0100 | [diff] [blame] | 356 | void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 357 | { |
| 358 | /* pins used for TWI interface */ |
| 359 | at91_set_A_periph(AT91_PIN_PA23, 0); /* TWD */ |
| 360 | at91_set_multi_drive(AT91_PIN_PA23, 1); |
| 361 | |
| 362 | at91_set_A_periph(AT91_PIN_PA24, 0); /* TWCK */ |
| 363 | at91_set_multi_drive(AT91_PIN_PA24, 1); |
| 364 | |
Andrew Victor | f230d3f | 2007-11-19 13:47:20 +0100 | [diff] [blame] | 365 | i2c_register_board_info(0, devices, nr_devices); |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 366 | platform_device_register(&at91sam9rl_twi_device); |
| 367 | } |
| 368 | #else |
Andrew Victor | f230d3f | 2007-11-19 13:47:20 +0100 | [diff] [blame] | 369 | void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {} |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 370 | #endif |
| 371 | |
| 372 | |
| 373 | /* -------------------------------------------------------------------- |
| 374 | * SPI |
| 375 | * -------------------------------------------------------------------- */ |
| 376 | |
| 377 | #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE) |
Andrew Victor | c6686ff | 2008-01-23 09:13:53 +0100 | [diff] [blame] | 378 | static u64 spi_dmamask = DMA_BIT_MASK(32); |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 379 | |
| 380 | static struct resource spi_resources[] = { |
| 381 | [0] = { |
| 382 | .start = AT91SAM9RL_BASE_SPI, |
| 383 | .end = AT91SAM9RL_BASE_SPI + SZ_16K - 1, |
| 384 | .flags = IORESOURCE_MEM, |
| 385 | }, |
| 386 | [1] = { |
Ludovic Desroches | 8fe82a5 | 2012-06-21 14:47:27 +0200 | [diff] [blame] | 387 | .start = NR_IRQS_LEGACY + AT91SAM9RL_ID_SPI, |
| 388 | .end = NR_IRQS_LEGACY + AT91SAM9RL_ID_SPI, |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 389 | .flags = IORESOURCE_IRQ, |
| 390 | }, |
| 391 | }; |
| 392 | |
| 393 | static struct platform_device at91sam9rl_spi_device = { |
| 394 | .name = "atmel_spi", |
| 395 | .id = 0, |
| 396 | .dev = { |
| 397 | .dma_mask = &spi_dmamask, |
Andrew Victor | c6686ff | 2008-01-23 09:13:53 +0100 | [diff] [blame] | 398 | .coherent_dma_mask = DMA_BIT_MASK(32), |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 399 | }, |
| 400 | .resource = spi_resources, |
| 401 | .num_resources = ARRAY_SIZE(spi_resources), |
| 402 | }; |
| 403 | |
| 404 | static const unsigned spi_standard_cs[4] = { AT91_PIN_PA28, AT91_PIN_PB7, AT91_PIN_PD8, AT91_PIN_PD9 }; |
| 405 | |
| 406 | |
| 407 | void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) |
| 408 | { |
| 409 | int i; |
| 410 | unsigned long cs_pin; |
| 411 | |
| 412 | at91_set_A_periph(AT91_PIN_PA25, 0); /* MISO */ |
| 413 | at91_set_A_periph(AT91_PIN_PA26, 0); /* MOSI */ |
| 414 | at91_set_A_periph(AT91_PIN_PA27, 0); /* SPCK */ |
| 415 | |
| 416 | /* Enable SPI chip-selects */ |
| 417 | for (i = 0; i < nr_devices; i++) { |
| 418 | if (devices[i].controller_data) |
| 419 | cs_pin = (unsigned long) devices[i].controller_data; |
| 420 | else |
| 421 | cs_pin = spi_standard_cs[devices[i].chip_select]; |
| 422 | |
Nicolas Ferre | 0c2c1f6 | 2012-03-28 11:58:58 +0200 | [diff] [blame] | 423 | if (!gpio_is_valid(cs_pin)) |
| 424 | continue; |
| 425 | |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 426 | /* enable chip-select pin */ |
| 427 | at91_set_gpio_output(cs_pin, 1); |
| 428 | |
| 429 | /* pass chip-select pin to driver */ |
| 430 | devices[i].controller_data = (void *) cs_pin; |
| 431 | } |
| 432 | |
| 433 | spi_register_board_info(devices, nr_devices); |
| 434 | platform_device_register(&at91sam9rl_spi_device); |
| 435 | } |
| 436 | #else |
| 437 | void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {} |
| 438 | #endif |
| 439 | |
| 440 | |
| 441 | /* -------------------------------------------------------------------- |
Nicolas Ferre | 439a330 | 2009-09-18 16:14:21 +0100 | [diff] [blame] | 442 | * AC97 |
| 443 | * -------------------------------------------------------------------- */ |
| 444 | |
| 445 | #if defined(CONFIG_SND_ATMEL_AC97C) || defined(CONFIG_SND_ATMEL_AC97C_MODULE) |
| 446 | static u64 ac97_dmamask = DMA_BIT_MASK(32); |
| 447 | static struct ac97c_platform_data ac97_data; |
| 448 | |
| 449 | static struct resource ac97_resources[] = { |
| 450 | [0] = { |
| 451 | .start = AT91SAM9RL_BASE_AC97C, |
| 452 | .end = AT91SAM9RL_BASE_AC97C + SZ_16K - 1, |
| 453 | .flags = IORESOURCE_MEM, |
| 454 | }, |
| 455 | [1] = { |
Ludovic Desroches | 8fe82a5 | 2012-06-21 14:47:27 +0200 | [diff] [blame] | 456 | .start = NR_IRQS_LEGACY + AT91SAM9RL_ID_AC97C, |
| 457 | .end = NR_IRQS_LEGACY + AT91SAM9RL_ID_AC97C, |
Nicolas Ferre | 439a330 | 2009-09-18 16:14:21 +0100 | [diff] [blame] | 458 | .flags = IORESOURCE_IRQ, |
| 459 | }, |
| 460 | }; |
| 461 | |
| 462 | static struct platform_device at91sam9rl_ac97_device = { |
| 463 | .name = "atmel_ac97c", |
| 464 | .id = 0, |
| 465 | .dev = { |
| 466 | .dma_mask = &ac97_dmamask, |
| 467 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 468 | .platform_data = &ac97_data, |
| 469 | }, |
| 470 | .resource = ac97_resources, |
| 471 | .num_resources = ARRAY_SIZE(ac97_resources), |
| 472 | }; |
| 473 | |
| 474 | void __init at91_add_device_ac97(struct ac97c_platform_data *data) |
| 475 | { |
| 476 | if (!data) |
| 477 | return; |
| 478 | |
| 479 | at91_set_A_periph(AT91_PIN_PD1, 0); /* AC97FS */ |
| 480 | at91_set_A_periph(AT91_PIN_PD2, 0); /* AC97CK */ |
| 481 | at91_set_A_periph(AT91_PIN_PD3, 0); /* AC97TX */ |
| 482 | at91_set_A_periph(AT91_PIN_PD4, 0); /* AC97RX */ |
| 483 | |
| 484 | /* reset */ |
Jean-Christophe PLAGNIOL-VILLARD | cc9f9ae | 2011-09-19 15:28:25 +0800 | [diff] [blame] | 485 | if (gpio_is_valid(data->reset_pin)) |
Nicolas Ferre | 439a330 | 2009-09-18 16:14:21 +0100 | [diff] [blame] | 486 | at91_set_gpio_output(data->reset_pin, 0); |
| 487 | |
| 488 | ac97_data = *data; |
| 489 | platform_device_register(&at91sam9rl_ac97_device); |
| 490 | } |
| 491 | #else |
| 492 | void __init at91_add_device_ac97(struct ac97c_platform_data *data) {} |
| 493 | #endif |
| 494 | |
| 495 | |
| 496 | /* -------------------------------------------------------------------- |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 497 | * LCD Controller |
| 498 | * -------------------------------------------------------------------- */ |
| 499 | |
| 500 | #if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE) |
Andrew Victor | c6686ff | 2008-01-23 09:13:53 +0100 | [diff] [blame] | 501 | static u64 lcdc_dmamask = DMA_BIT_MASK(32); |
Jean-Christophe PLAGNIOL-VILLARD | 8af2c28 | 2013-03-28 22:53:42 +0800 | [diff] [blame] | 502 | static struct atmel_lcdfb_pdata lcdc_data; |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 503 | |
| 504 | static struct resource lcdc_resources[] = { |
| 505 | [0] = { |
| 506 | .start = AT91SAM9RL_LCDC_BASE, |
| 507 | .end = AT91SAM9RL_LCDC_BASE + SZ_4K - 1, |
| 508 | .flags = IORESOURCE_MEM, |
| 509 | }, |
| 510 | [1] = { |
Ludovic Desroches | 8fe82a5 | 2012-06-21 14:47:27 +0200 | [diff] [blame] | 511 | .start = NR_IRQS_LEGACY + AT91SAM9RL_ID_LCDC, |
| 512 | .end = NR_IRQS_LEGACY + AT91SAM9RL_ID_LCDC, |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 513 | .flags = IORESOURCE_IRQ, |
| 514 | }, |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 515 | }; |
| 516 | |
| 517 | static struct platform_device at91_lcdc_device = { |
Johan Hovold | bbd44f6b | 2013-02-07 16:31:58 +0100 | [diff] [blame] | 518 | .name = "at91sam9rl-lcdfb", |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 519 | .id = 0, |
| 520 | .dev = { |
| 521 | .dma_mask = &lcdc_dmamask, |
Andrew Victor | c6686ff | 2008-01-23 09:13:53 +0100 | [diff] [blame] | 522 | .coherent_dma_mask = DMA_BIT_MASK(32), |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 523 | .platform_data = &lcdc_data, |
| 524 | }, |
| 525 | .resource = lcdc_resources, |
| 526 | .num_resources = ARRAY_SIZE(lcdc_resources), |
| 527 | }; |
| 528 | |
Jean-Christophe PLAGNIOL-VILLARD | 8af2c28 | 2013-03-28 22:53:42 +0800 | [diff] [blame] | 529 | void __init at91_add_device_lcdc(struct atmel_lcdfb_pdata *data) |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 530 | { |
| 531 | if (!data) { |
| 532 | return; |
| 533 | } |
| 534 | |
| 535 | at91_set_B_periph(AT91_PIN_PC1, 0); /* LCDPWR */ |
| 536 | at91_set_A_periph(AT91_PIN_PC5, 0); /* LCDHSYNC */ |
| 537 | at91_set_A_periph(AT91_PIN_PC6, 0); /* LCDDOTCK */ |
| 538 | at91_set_A_periph(AT91_PIN_PC7, 0); /* LCDDEN */ |
| 539 | at91_set_A_periph(AT91_PIN_PC3, 0); /* LCDCC */ |
| 540 | at91_set_B_periph(AT91_PIN_PC9, 0); /* LCDD3 */ |
| 541 | at91_set_B_periph(AT91_PIN_PC10, 0); /* LCDD4 */ |
| 542 | at91_set_B_periph(AT91_PIN_PC11, 0); /* LCDD5 */ |
| 543 | at91_set_B_periph(AT91_PIN_PC12, 0); /* LCDD6 */ |
| 544 | at91_set_B_periph(AT91_PIN_PC13, 0); /* LCDD7 */ |
| 545 | at91_set_B_periph(AT91_PIN_PC15, 0); /* LCDD11 */ |
| 546 | at91_set_B_periph(AT91_PIN_PC16, 0); /* LCDD12 */ |
| 547 | at91_set_B_periph(AT91_PIN_PC17, 0); /* LCDD13 */ |
| 548 | at91_set_B_periph(AT91_PIN_PC18, 0); /* LCDD14 */ |
| 549 | at91_set_B_periph(AT91_PIN_PC19, 0); /* LCDD15 */ |
| 550 | at91_set_B_periph(AT91_PIN_PC20, 0); /* LCDD18 */ |
| 551 | at91_set_B_periph(AT91_PIN_PC21, 0); /* LCDD19 */ |
| 552 | at91_set_B_periph(AT91_PIN_PC22, 0); /* LCDD20 */ |
| 553 | at91_set_B_periph(AT91_PIN_PC23, 0); /* LCDD21 */ |
| 554 | at91_set_B_periph(AT91_PIN_PC24, 0); /* LCDD22 */ |
| 555 | at91_set_B_periph(AT91_PIN_PC25, 0); /* LCDD23 */ |
| 556 | |
| 557 | lcdc_data = *data; |
| 558 | platform_device_register(&at91_lcdc_device); |
| 559 | } |
| 560 | #else |
Jean-Christophe PLAGNIOL-VILLARD | 8af2c28 | 2013-03-28 22:53:42 +0800 | [diff] [blame] | 561 | void __init at91_add_device_lcdc(struct atmel_lcdfb_pdata *data) {} |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 562 | #endif |
| 563 | |
| 564 | |
| 565 | /* -------------------------------------------------------------------- |
Andrew Victor | e5f40bf | 2008-04-02 21:58:00 +0100 | [diff] [blame] | 566 | * Timer/Counter block |
| 567 | * -------------------------------------------------------------------- */ |
| 568 | |
| 569 | #ifdef CONFIG_ATMEL_TCLIB |
| 570 | |
| 571 | static struct resource tcb_resources[] = { |
| 572 | [0] = { |
| 573 | .start = AT91SAM9RL_BASE_TCB0, |
| 574 | .end = AT91SAM9RL_BASE_TCB0 + SZ_16K - 1, |
| 575 | .flags = IORESOURCE_MEM, |
| 576 | }, |
| 577 | [1] = { |
Ludovic Desroches | 8fe82a5 | 2012-06-21 14:47:27 +0200 | [diff] [blame] | 578 | .start = NR_IRQS_LEGACY + AT91SAM9RL_ID_TC0, |
| 579 | .end = NR_IRQS_LEGACY + AT91SAM9RL_ID_TC0, |
Andrew Victor | e5f40bf | 2008-04-02 21:58:00 +0100 | [diff] [blame] | 580 | .flags = IORESOURCE_IRQ, |
| 581 | }, |
| 582 | [2] = { |
Ludovic Desroches | 8fe82a5 | 2012-06-21 14:47:27 +0200 | [diff] [blame] | 583 | .start = NR_IRQS_LEGACY + AT91SAM9RL_ID_TC1, |
| 584 | .end = NR_IRQS_LEGACY + AT91SAM9RL_ID_TC1, |
Andrew Victor | e5f40bf | 2008-04-02 21:58:00 +0100 | [diff] [blame] | 585 | .flags = IORESOURCE_IRQ, |
| 586 | }, |
| 587 | [3] = { |
Ludovic Desroches | 8fe82a5 | 2012-06-21 14:47:27 +0200 | [diff] [blame] | 588 | .start = NR_IRQS_LEGACY + AT91SAM9RL_ID_TC2, |
| 589 | .end = NR_IRQS_LEGACY + AT91SAM9RL_ID_TC2, |
Andrew Victor | e5f40bf | 2008-04-02 21:58:00 +0100 | [diff] [blame] | 590 | .flags = IORESOURCE_IRQ, |
| 591 | }, |
| 592 | }; |
| 593 | |
| 594 | static struct platform_device at91sam9rl_tcb_device = { |
| 595 | .name = "atmel_tcb", |
| 596 | .id = 0, |
| 597 | .resource = tcb_resources, |
| 598 | .num_resources = ARRAY_SIZE(tcb_resources), |
| 599 | }; |
| 600 | |
| 601 | static void __init at91_add_device_tc(void) |
| 602 | { |
Andrew Victor | e5f40bf | 2008-04-02 21:58:00 +0100 | [diff] [blame] | 603 | platform_device_register(&at91sam9rl_tcb_device); |
| 604 | } |
| 605 | #else |
| 606 | static void __init at91_add_device_tc(void) { } |
| 607 | #endif |
| 608 | |
| 609 | |
| 610 | /* -------------------------------------------------------------------- |
Andrew Victor | f7647e6 | 2008-09-18 19:45:35 +0100 | [diff] [blame] | 611 | * Touchscreen |
| 612 | * -------------------------------------------------------------------- */ |
| 613 | |
| 614 | #if defined(CONFIG_TOUCHSCREEN_ATMEL_TSADCC) || defined(CONFIG_TOUCHSCREEN_ATMEL_TSADCC_MODULE) |
| 615 | static u64 tsadcc_dmamask = DMA_BIT_MASK(32); |
Nicolas Ferre | 423c9b0 | 2009-11-19 09:31:20 -0800 | [diff] [blame] | 616 | static struct at91_tsadcc_data tsadcc_data; |
Andrew Victor | f7647e6 | 2008-09-18 19:45:35 +0100 | [diff] [blame] | 617 | |
| 618 | static struct resource tsadcc_resources[] = { |
| 619 | [0] = { |
| 620 | .start = AT91SAM9RL_BASE_TSC, |
| 621 | .end = AT91SAM9RL_BASE_TSC + SZ_16K - 1, |
| 622 | .flags = IORESOURCE_MEM, |
| 623 | }, |
| 624 | [1] = { |
Ludovic Desroches | 8fe82a5 | 2012-06-21 14:47:27 +0200 | [diff] [blame] | 625 | .start = NR_IRQS_LEGACY + AT91SAM9RL_ID_TSC, |
| 626 | .end = NR_IRQS_LEGACY + AT91SAM9RL_ID_TSC, |
Andrew Victor | f7647e6 | 2008-09-18 19:45:35 +0100 | [diff] [blame] | 627 | .flags = IORESOURCE_IRQ, |
| 628 | } |
| 629 | }; |
| 630 | |
| 631 | static struct platform_device at91sam9rl_tsadcc_device = { |
| 632 | .name = "atmel_tsadcc", |
| 633 | .id = -1, |
| 634 | .dev = { |
| 635 | .dma_mask = &tsadcc_dmamask, |
| 636 | .coherent_dma_mask = DMA_BIT_MASK(32), |
Nicolas Ferre | 423c9b0 | 2009-11-19 09:31:20 -0800 | [diff] [blame] | 637 | .platform_data = &tsadcc_data, |
Andrew Victor | f7647e6 | 2008-09-18 19:45:35 +0100 | [diff] [blame] | 638 | }, |
| 639 | .resource = tsadcc_resources, |
| 640 | .num_resources = ARRAY_SIZE(tsadcc_resources), |
| 641 | }; |
| 642 | |
Nicolas Ferre | 423c9b0 | 2009-11-19 09:31:20 -0800 | [diff] [blame] | 643 | void __init at91_add_device_tsadcc(struct at91_tsadcc_data *data) |
Andrew Victor | f7647e6 | 2008-09-18 19:45:35 +0100 | [diff] [blame] | 644 | { |
Nicolas Ferre | 423c9b0 | 2009-11-19 09:31:20 -0800 | [diff] [blame] | 645 | if (!data) |
| 646 | return; |
| 647 | |
Andrew Victor | f7647e6 | 2008-09-18 19:45:35 +0100 | [diff] [blame] | 648 | at91_set_A_periph(AT91_PIN_PA17, 0); /* AD0_XR */ |
| 649 | at91_set_A_periph(AT91_PIN_PA18, 0); /* AD1_XL */ |
| 650 | at91_set_A_periph(AT91_PIN_PA19, 0); /* AD2_YT */ |
| 651 | at91_set_A_periph(AT91_PIN_PA20, 0); /* AD3_TB */ |
| 652 | |
Nicolas Ferre | 423c9b0 | 2009-11-19 09:31:20 -0800 | [diff] [blame] | 653 | tsadcc_data = *data; |
Andrew Victor | f7647e6 | 2008-09-18 19:45:35 +0100 | [diff] [blame] | 654 | platform_device_register(&at91sam9rl_tsadcc_device); |
| 655 | } |
| 656 | #else |
Nicolas Ferre | 423c9b0 | 2009-11-19 09:31:20 -0800 | [diff] [blame] | 657 | void __init at91_add_device_tsadcc(struct at91_tsadcc_data *data) {} |
Andrew Victor | f7647e6 | 2008-09-18 19:45:35 +0100 | [diff] [blame] | 658 | #endif |
| 659 | |
| 660 | |
| 661 | /* -------------------------------------------------------------------- |
Andrew Victor | 884f5a6 | 2008-01-23 09:11:13 +0100 | [diff] [blame] | 662 | * RTC |
| 663 | * -------------------------------------------------------------------- */ |
| 664 | |
| 665 | #if defined(CONFIG_RTC_DRV_AT91RM9200) || defined(CONFIG_RTC_DRV_AT91RM9200_MODULE) |
| 666 | static struct platform_device at91sam9rl_rtc_device = { |
| 667 | .name = "at91_rtc", |
| 668 | .id = -1, |
| 669 | .num_resources = 0, |
| 670 | }; |
| 671 | |
| 672 | static void __init at91_add_device_rtc(void) |
| 673 | { |
| 674 | platform_device_register(&at91sam9rl_rtc_device); |
| 675 | } |
| 676 | #else |
| 677 | static void __init at91_add_device_rtc(void) {} |
| 678 | #endif |
| 679 | |
| 680 | |
| 681 | /* -------------------------------------------------------------------- |
| 682 | * RTT |
| 683 | * -------------------------------------------------------------------- */ |
| 684 | |
| 685 | static struct resource rtt_resources[] = { |
| 686 | { |
Jean-Christophe PLAGNIOL-VILLARD | eab5fd6 | 2011-09-18 10:12:00 +0800 | [diff] [blame] | 687 | .start = AT91SAM9RL_BASE_RTT, |
| 688 | .end = AT91SAM9RL_BASE_RTT + SZ_16 - 1, |
Andrew Victor | 884f5a6 | 2008-01-23 09:11:13 +0100 | [diff] [blame] | 689 | .flags = IORESOURCE_MEM, |
Jean-Christophe PLAGNIOL-VILLARD | b3af8b4 | 2012-02-15 21:24:46 +0800 | [diff] [blame] | 690 | }, { |
| 691 | .flags = IORESOURCE_MEM, |
Ludovic Desroches | e402af6 | 2012-08-14 11:19:22 +0200 | [diff] [blame] | 692 | }, { |
| 693 | .flags = IORESOURCE_IRQ, |
Andrew Victor | 884f5a6 | 2008-01-23 09:11:13 +0100 | [diff] [blame] | 694 | } |
| 695 | }; |
| 696 | |
| 697 | static struct platform_device at91sam9rl_rtt_device = { |
| 698 | .name = "at91_rtt", |
Andrew Victor | 4fd9212 | 2008-04-02 21:55:19 +0100 | [diff] [blame] | 699 | .id = 0, |
Andrew Victor | 884f5a6 | 2008-01-23 09:11:13 +0100 | [diff] [blame] | 700 | .resource = rtt_resources, |
Andrew Victor | 884f5a6 | 2008-01-23 09:11:13 +0100 | [diff] [blame] | 701 | }; |
| 702 | |
Jean-Christophe PLAGNIOL-VILLARD | 205056a | 2012-02-15 20:51:37 +0800 | [diff] [blame] | 703 | #if IS_ENABLED(CONFIG_RTC_DRV_AT91SAM9) |
| 704 | static void __init at91_add_device_rtt_rtc(void) |
| 705 | { |
| 706 | at91sam9rl_rtt_device.name = "rtc-at91sam9"; |
Jean-Christophe PLAGNIOL-VILLARD | b3af8b4 | 2012-02-15 21:24:46 +0800 | [diff] [blame] | 707 | /* |
| 708 | * The second resource is needed: |
| 709 | * GPBR will serve as the storage for RTC time offset |
| 710 | */ |
Ludovic Desroches | e402af6 | 2012-08-14 11:19:22 +0200 | [diff] [blame] | 711 | at91sam9rl_rtt_device.num_resources = 3; |
Jean-Christophe PLAGNIOL-VILLARD | b3af8b4 | 2012-02-15 21:24:46 +0800 | [diff] [blame] | 712 | rtt_resources[1].start = AT91SAM9RL_BASE_GPBR + |
| 713 | 4 * CONFIG_RTC_DRV_AT91SAM9_GPBR; |
| 714 | rtt_resources[1].end = rtt_resources[1].start + 3; |
Ludovic Desroches | e402af6 | 2012-08-14 11:19:22 +0200 | [diff] [blame] | 715 | rtt_resources[2].start = NR_IRQS_LEGACY + AT91_ID_SYS; |
| 716 | rtt_resources[2].end = NR_IRQS_LEGACY + AT91_ID_SYS; |
Jean-Christophe PLAGNIOL-VILLARD | 205056a | 2012-02-15 20:51:37 +0800 | [diff] [blame] | 717 | } |
| 718 | #else |
Jean-Christophe PLAGNIOL-VILLARD | b3af8b4 | 2012-02-15 21:24:46 +0800 | [diff] [blame] | 719 | static void __init at91_add_device_rtt_rtc(void) |
| 720 | { |
| 721 | /* Only one resource is needed: RTT not used as RTC */ |
| 722 | at91sam9rl_rtt_device.num_resources = 1; |
| 723 | } |
Jean-Christophe PLAGNIOL-VILLARD | 205056a | 2012-02-15 20:51:37 +0800 | [diff] [blame] | 724 | #endif |
| 725 | |
Andrew Victor | 884f5a6 | 2008-01-23 09:11:13 +0100 | [diff] [blame] | 726 | static void __init at91_add_device_rtt(void) |
| 727 | { |
Jean-Christophe PLAGNIOL-VILLARD | 205056a | 2012-02-15 20:51:37 +0800 | [diff] [blame] | 728 | at91_add_device_rtt_rtc(); |
Andrew Victor | 884f5a6 | 2008-01-23 09:11:13 +0100 | [diff] [blame] | 729 | platform_device_register(&at91sam9rl_rtt_device); |
| 730 | } |
| 731 | |
| 732 | |
| 733 | /* -------------------------------------------------------------------- |
| 734 | * Watchdog |
| 735 | * -------------------------------------------------------------------- */ |
| 736 | |
Andrew Victor | 2af29b7 | 2009-02-11 21:23:10 +0100 | [diff] [blame] | 737 | #if defined(CONFIG_AT91SAM9X_WATCHDOG) || defined(CONFIG_AT91SAM9X_WATCHDOG_MODULE) |
Jean-Christophe PLAGNIOL-VILLARD | c1c30a2 | 2011-11-02 01:43:31 +0800 | [diff] [blame] | 738 | static struct resource wdt_resources[] = { |
| 739 | { |
| 740 | .start = AT91SAM9RL_BASE_WDT, |
| 741 | .end = AT91SAM9RL_BASE_WDT + SZ_16 - 1, |
| 742 | .flags = IORESOURCE_MEM, |
| 743 | } |
| 744 | }; |
| 745 | |
Andrew Victor | 884f5a6 | 2008-01-23 09:11:13 +0100 | [diff] [blame] | 746 | static struct platform_device at91sam9rl_wdt_device = { |
| 747 | .name = "at91_wdt", |
| 748 | .id = -1, |
Jean-Christophe PLAGNIOL-VILLARD | c1c30a2 | 2011-11-02 01:43:31 +0800 | [diff] [blame] | 749 | .resource = wdt_resources, |
| 750 | .num_resources = ARRAY_SIZE(wdt_resources), |
Andrew Victor | 884f5a6 | 2008-01-23 09:11:13 +0100 | [diff] [blame] | 751 | }; |
| 752 | |
| 753 | static void __init at91_add_device_watchdog(void) |
| 754 | { |
| 755 | platform_device_register(&at91sam9rl_wdt_device); |
| 756 | } |
| 757 | #else |
| 758 | static void __init at91_add_device_watchdog(void) {} |
| 759 | #endif |
| 760 | |
| 761 | |
| 762 | /* -------------------------------------------------------------------- |
Andrew Victor | bb1ad68 | 2008-09-18 19:42:37 +0100 | [diff] [blame] | 763 | * PWM |
| 764 | * --------------------------------------------------------------------*/ |
| 765 | |
| 766 | #if defined(CONFIG_ATMEL_PWM) |
| 767 | static u32 pwm_mask; |
| 768 | |
| 769 | static struct resource pwm_resources[] = { |
| 770 | [0] = { |
| 771 | .start = AT91SAM9RL_BASE_PWMC, |
| 772 | .end = AT91SAM9RL_BASE_PWMC + SZ_16K - 1, |
| 773 | .flags = IORESOURCE_MEM, |
| 774 | }, |
| 775 | [1] = { |
Ludovic Desroches | 8fe82a5 | 2012-06-21 14:47:27 +0200 | [diff] [blame] | 776 | .start = NR_IRQS_LEGACY + AT91SAM9RL_ID_PWMC, |
| 777 | .end = NR_IRQS_LEGACY + AT91SAM9RL_ID_PWMC, |
Andrew Victor | bb1ad68 | 2008-09-18 19:42:37 +0100 | [diff] [blame] | 778 | .flags = IORESOURCE_IRQ, |
| 779 | }, |
| 780 | }; |
| 781 | |
| 782 | static struct platform_device at91sam9rl_pwm0_device = { |
| 783 | .name = "atmel_pwm", |
| 784 | .id = -1, |
| 785 | .dev = { |
| 786 | .platform_data = &pwm_mask, |
| 787 | }, |
| 788 | .resource = pwm_resources, |
| 789 | .num_resources = ARRAY_SIZE(pwm_resources), |
| 790 | }; |
| 791 | |
| 792 | void __init at91_add_device_pwm(u32 mask) |
| 793 | { |
| 794 | if (mask & (1 << AT91_PWM0)) |
| 795 | at91_set_B_periph(AT91_PIN_PB8, 1); /* enable PWM0 */ |
| 796 | |
| 797 | if (mask & (1 << AT91_PWM1)) |
| 798 | at91_set_B_periph(AT91_PIN_PB9, 1); /* enable PWM1 */ |
| 799 | |
| 800 | if (mask & (1 << AT91_PWM2)) |
| 801 | at91_set_B_periph(AT91_PIN_PD5, 1); /* enable PWM2 */ |
| 802 | |
| 803 | if (mask & (1 << AT91_PWM3)) |
| 804 | at91_set_B_periph(AT91_PIN_PD8, 1); /* enable PWM3 */ |
| 805 | |
| 806 | pwm_mask = mask; |
| 807 | |
| 808 | platform_device_register(&at91sam9rl_pwm0_device); |
| 809 | } |
| 810 | #else |
| 811 | void __init at91_add_device_pwm(u32 mask) {} |
| 812 | #endif |
| 813 | |
| 814 | |
| 815 | /* -------------------------------------------------------------------- |
Andrew Victor | bfbc326 | 2008-01-23 09:18:06 +0100 | [diff] [blame] | 816 | * SSC -- Synchronous Serial Controller |
| 817 | * -------------------------------------------------------------------- */ |
| 818 | |
| 819 | #if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE) |
| 820 | static u64 ssc0_dmamask = DMA_BIT_MASK(32); |
| 821 | |
| 822 | static struct resource ssc0_resources[] = { |
| 823 | [0] = { |
| 824 | .start = AT91SAM9RL_BASE_SSC0, |
| 825 | .end = AT91SAM9RL_BASE_SSC0 + SZ_16K - 1, |
| 826 | .flags = IORESOURCE_MEM, |
| 827 | }, |
| 828 | [1] = { |
Ludovic Desroches | 8fe82a5 | 2012-06-21 14:47:27 +0200 | [diff] [blame] | 829 | .start = NR_IRQS_LEGACY + AT91SAM9RL_ID_SSC0, |
| 830 | .end = NR_IRQS_LEGACY + AT91SAM9RL_ID_SSC0, |
Andrew Victor | bfbc326 | 2008-01-23 09:18:06 +0100 | [diff] [blame] | 831 | .flags = IORESOURCE_IRQ, |
| 832 | }, |
| 833 | }; |
| 834 | |
| 835 | static struct platform_device at91sam9rl_ssc0_device = { |
Bo Shen | 636036d2 | 2012-11-06 13:57:51 +0800 | [diff] [blame] | 836 | .name = "at91rm9200_ssc", |
Andrew Victor | bfbc326 | 2008-01-23 09:18:06 +0100 | [diff] [blame] | 837 | .id = 0, |
| 838 | .dev = { |
| 839 | .dma_mask = &ssc0_dmamask, |
| 840 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 841 | }, |
| 842 | .resource = ssc0_resources, |
| 843 | .num_resources = ARRAY_SIZE(ssc0_resources), |
| 844 | }; |
| 845 | |
| 846 | static inline void configure_ssc0_pins(unsigned pins) |
| 847 | { |
| 848 | if (pins & ATMEL_SSC_TF) |
| 849 | at91_set_A_periph(AT91_PIN_PC0, 1); |
| 850 | if (pins & ATMEL_SSC_TK) |
| 851 | at91_set_A_periph(AT91_PIN_PC1, 1); |
| 852 | if (pins & ATMEL_SSC_TD) |
| 853 | at91_set_A_periph(AT91_PIN_PA15, 1); |
| 854 | if (pins & ATMEL_SSC_RD) |
| 855 | at91_set_A_periph(AT91_PIN_PA16, 1); |
| 856 | if (pins & ATMEL_SSC_RK) |
| 857 | at91_set_B_periph(AT91_PIN_PA10, 1); |
| 858 | if (pins & ATMEL_SSC_RF) |
| 859 | at91_set_B_periph(AT91_PIN_PA22, 1); |
| 860 | } |
| 861 | |
| 862 | static u64 ssc1_dmamask = DMA_BIT_MASK(32); |
| 863 | |
| 864 | static struct resource ssc1_resources[] = { |
| 865 | [0] = { |
| 866 | .start = AT91SAM9RL_BASE_SSC1, |
| 867 | .end = AT91SAM9RL_BASE_SSC1 + SZ_16K - 1, |
| 868 | .flags = IORESOURCE_MEM, |
| 869 | }, |
| 870 | [1] = { |
Ludovic Desroches | 8fe82a5 | 2012-06-21 14:47:27 +0200 | [diff] [blame] | 871 | .start = NR_IRQS_LEGACY + AT91SAM9RL_ID_SSC1, |
| 872 | .end = NR_IRQS_LEGACY + AT91SAM9RL_ID_SSC1, |
Andrew Victor | bfbc326 | 2008-01-23 09:18:06 +0100 | [diff] [blame] | 873 | .flags = IORESOURCE_IRQ, |
| 874 | }, |
| 875 | }; |
| 876 | |
| 877 | static struct platform_device at91sam9rl_ssc1_device = { |
Bo Shen | 636036d2 | 2012-11-06 13:57:51 +0800 | [diff] [blame] | 878 | .name = "at91rm9200_ssc", |
Andrew Victor | bfbc326 | 2008-01-23 09:18:06 +0100 | [diff] [blame] | 879 | .id = 1, |
| 880 | .dev = { |
| 881 | .dma_mask = &ssc1_dmamask, |
| 882 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 883 | }, |
| 884 | .resource = ssc1_resources, |
| 885 | .num_resources = ARRAY_SIZE(ssc1_resources), |
| 886 | }; |
| 887 | |
| 888 | static inline void configure_ssc1_pins(unsigned pins) |
| 889 | { |
| 890 | if (pins & ATMEL_SSC_TF) |
| 891 | at91_set_B_periph(AT91_PIN_PA29, 1); |
| 892 | if (pins & ATMEL_SSC_TK) |
| 893 | at91_set_B_periph(AT91_PIN_PA30, 1); |
| 894 | if (pins & ATMEL_SSC_TD) |
| 895 | at91_set_B_periph(AT91_PIN_PA13, 1); |
| 896 | if (pins & ATMEL_SSC_RD) |
| 897 | at91_set_B_periph(AT91_PIN_PA14, 1); |
| 898 | if (pins & ATMEL_SSC_RK) |
| 899 | at91_set_B_periph(AT91_PIN_PA9, 1); |
| 900 | if (pins & ATMEL_SSC_RF) |
| 901 | at91_set_B_periph(AT91_PIN_PA8, 1); |
| 902 | } |
| 903 | |
| 904 | /* |
Andrew Victor | bfbc326 | 2008-01-23 09:18:06 +0100 | [diff] [blame] | 905 | * SSC controllers are accessed through library code, instead of any |
| 906 | * kind of all-singing/all-dancing driver. For example one could be |
| 907 | * used by a particular I2S audio codec's driver, while another one |
| 908 | * on the same system might be used by a custom data capture driver. |
| 909 | */ |
| 910 | void __init at91_add_device_ssc(unsigned id, unsigned pins) |
| 911 | { |
| 912 | struct platform_device *pdev; |
| 913 | |
| 914 | /* |
| 915 | * NOTE: caller is responsible for passing information matching |
| 916 | * "pins" to whatever will be using each particular controller. |
| 917 | */ |
| 918 | switch (id) { |
| 919 | case AT91SAM9RL_ID_SSC0: |
| 920 | pdev = &at91sam9rl_ssc0_device; |
| 921 | configure_ssc0_pins(pins); |
Andrew Victor | bfbc326 | 2008-01-23 09:18:06 +0100 | [diff] [blame] | 922 | break; |
| 923 | case AT91SAM9RL_ID_SSC1: |
| 924 | pdev = &at91sam9rl_ssc1_device; |
| 925 | configure_ssc1_pins(pins); |
Andrew Victor | bfbc326 | 2008-01-23 09:18:06 +0100 | [diff] [blame] | 926 | break; |
| 927 | default: |
| 928 | return; |
| 929 | } |
| 930 | |
| 931 | platform_device_register(pdev); |
| 932 | } |
| 933 | |
| 934 | #else |
| 935 | void __init at91_add_device_ssc(unsigned id, unsigned pins) {} |
| 936 | #endif |
| 937 | |
| 938 | |
| 939 | /* -------------------------------------------------------------------- |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 940 | * UART |
| 941 | * -------------------------------------------------------------------- */ |
| 942 | |
| 943 | #if defined(CONFIG_SERIAL_ATMEL) |
| 944 | static struct resource dbgu_resources[] = { |
| 945 | [0] = { |
Jean-Christophe PLAGNIOL-VILLARD | 13079a7 | 2011-11-02 01:43:31 +0800 | [diff] [blame] | 946 | .start = AT91SAM9RL_BASE_DBGU, |
| 947 | .end = AT91SAM9RL_BASE_DBGU + SZ_512 - 1, |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 948 | .flags = IORESOURCE_MEM, |
| 949 | }, |
| 950 | [1] = { |
Ludovic Desroches | 8fe82a5 | 2012-06-21 14:47:27 +0200 | [diff] [blame] | 951 | .start = NR_IRQS_LEGACY + AT91_ID_SYS, |
| 952 | .end = NR_IRQS_LEGACY + AT91_ID_SYS, |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 953 | .flags = IORESOURCE_IRQ, |
| 954 | }, |
| 955 | }; |
| 956 | |
| 957 | static struct atmel_uart_data dbgu_data = { |
| 958 | .use_dma_tx = 0, |
| 959 | .use_dma_rx = 0, /* DBGU not capable of receive DMA */ |
Linus Walleij | 354e57f | 2013-11-07 10:25:55 +0100 | [diff] [blame] | 960 | .rts_gpio = -EINVAL, |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 961 | }; |
| 962 | |
Andrew Victor | c6686ff | 2008-01-23 09:13:53 +0100 | [diff] [blame] | 963 | static u64 dbgu_dmamask = DMA_BIT_MASK(32); |
| 964 | |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 965 | static struct platform_device at91sam9rl_dbgu_device = { |
| 966 | .name = "atmel_usart", |
| 967 | .id = 0, |
| 968 | .dev = { |
Andrew Victor | c6686ff | 2008-01-23 09:13:53 +0100 | [diff] [blame] | 969 | .dma_mask = &dbgu_dmamask, |
| 970 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 971 | .platform_data = &dbgu_data, |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 972 | }, |
| 973 | .resource = dbgu_resources, |
| 974 | .num_resources = ARRAY_SIZE(dbgu_resources), |
| 975 | }; |
| 976 | |
| 977 | static inline void configure_dbgu_pins(void) |
| 978 | { |
| 979 | at91_set_A_periph(AT91_PIN_PA21, 0); /* DRXD */ |
| 980 | at91_set_A_periph(AT91_PIN_PA22, 1); /* DTXD */ |
| 981 | } |
| 982 | |
| 983 | static struct resource uart0_resources[] = { |
| 984 | [0] = { |
| 985 | .start = AT91SAM9RL_BASE_US0, |
| 986 | .end = AT91SAM9RL_BASE_US0 + SZ_16K - 1, |
| 987 | .flags = IORESOURCE_MEM, |
| 988 | }, |
| 989 | [1] = { |
Ludovic Desroches | 8fe82a5 | 2012-06-21 14:47:27 +0200 | [diff] [blame] | 990 | .start = NR_IRQS_LEGACY + AT91SAM9RL_ID_US0, |
| 991 | .end = NR_IRQS_LEGACY + AT91SAM9RL_ID_US0, |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 992 | .flags = IORESOURCE_IRQ, |
| 993 | }, |
| 994 | }; |
| 995 | |
| 996 | static struct atmel_uart_data uart0_data = { |
| 997 | .use_dma_tx = 1, |
| 998 | .use_dma_rx = 1, |
Linus Walleij | 354e57f | 2013-11-07 10:25:55 +0100 | [diff] [blame] | 999 | .rts_gpio = -EINVAL, |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 1000 | }; |
| 1001 | |
Andrew Victor | c6686ff | 2008-01-23 09:13:53 +0100 | [diff] [blame] | 1002 | static u64 uart0_dmamask = DMA_BIT_MASK(32); |
| 1003 | |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 1004 | static struct platform_device at91sam9rl_uart0_device = { |
| 1005 | .name = "atmel_usart", |
| 1006 | .id = 1, |
| 1007 | .dev = { |
Andrew Victor | c6686ff | 2008-01-23 09:13:53 +0100 | [diff] [blame] | 1008 | .dma_mask = &uart0_dmamask, |
| 1009 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 1010 | .platform_data = &uart0_data, |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 1011 | }, |
| 1012 | .resource = uart0_resources, |
| 1013 | .num_resources = ARRAY_SIZE(uart0_resources), |
| 1014 | }; |
| 1015 | |
Andrew Victor | c8f385a | 2008-01-23 09:25:15 +0100 | [diff] [blame] | 1016 | static inline void configure_usart0_pins(unsigned pins) |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 1017 | { |
| 1018 | at91_set_A_periph(AT91_PIN_PA6, 1); /* TXD0 */ |
| 1019 | at91_set_A_periph(AT91_PIN_PA7, 0); /* RXD0 */ |
Andrew Victor | c8f385a | 2008-01-23 09:25:15 +0100 | [diff] [blame] | 1020 | |
| 1021 | if (pins & ATMEL_UART_RTS) |
| 1022 | at91_set_A_periph(AT91_PIN_PA9, 0); /* RTS0 */ |
| 1023 | if (pins & ATMEL_UART_CTS) |
| 1024 | at91_set_A_periph(AT91_PIN_PA10, 0); /* CTS0 */ |
| 1025 | if (pins & ATMEL_UART_DSR) |
| 1026 | at91_set_A_periph(AT91_PIN_PD14, 0); /* DSR0 */ |
| 1027 | if (pins & ATMEL_UART_DTR) |
| 1028 | at91_set_A_periph(AT91_PIN_PD15, 0); /* DTR0 */ |
| 1029 | if (pins & ATMEL_UART_DCD) |
| 1030 | at91_set_A_periph(AT91_PIN_PD16, 0); /* DCD0 */ |
| 1031 | if (pins & ATMEL_UART_RI) |
| 1032 | at91_set_A_periph(AT91_PIN_PD17, 0); /* RI0 */ |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 1033 | } |
| 1034 | |
| 1035 | static struct resource uart1_resources[] = { |
| 1036 | [0] = { |
| 1037 | .start = AT91SAM9RL_BASE_US1, |
| 1038 | .end = AT91SAM9RL_BASE_US1 + SZ_16K - 1, |
| 1039 | .flags = IORESOURCE_MEM, |
| 1040 | }, |
| 1041 | [1] = { |
Ludovic Desroches | 8fe82a5 | 2012-06-21 14:47:27 +0200 | [diff] [blame] | 1042 | .start = NR_IRQS_LEGACY + AT91SAM9RL_ID_US1, |
| 1043 | .end = NR_IRQS_LEGACY + AT91SAM9RL_ID_US1, |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 1044 | .flags = IORESOURCE_IRQ, |
| 1045 | }, |
| 1046 | }; |
| 1047 | |
| 1048 | static struct atmel_uart_data uart1_data = { |
| 1049 | .use_dma_tx = 1, |
| 1050 | .use_dma_rx = 1, |
Linus Walleij | 354e57f | 2013-11-07 10:25:55 +0100 | [diff] [blame] | 1051 | .rts_gpio = -EINVAL, |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 1052 | }; |
| 1053 | |
Andrew Victor | c6686ff | 2008-01-23 09:13:53 +0100 | [diff] [blame] | 1054 | static u64 uart1_dmamask = DMA_BIT_MASK(32); |
| 1055 | |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 1056 | static struct platform_device at91sam9rl_uart1_device = { |
| 1057 | .name = "atmel_usart", |
| 1058 | .id = 2, |
| 1059 | .dev = { |
Andrew Victor | c6686ff | 2008-01-23 09:13:53 +0100 | [diff] [blame] | 1060 | .dma_mask = &uart1_dmamask, |
| 1061 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 1062 | .platform_data = &uart1_data, |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 1063 | }, |
| 1064 | .resource = uart1_resources, |
| 1065 | .num_resources = ARRAY_SIZE(uart1_resources), |
| 1066 | }; |
| 1067 | |
Andrew Victor | c8f385a | 2008-01-23 09:25:15 +0100 | [diff] [blame] | 1068 | static inline void configure_usart1_pins(unsigned pins) |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 1069 | { |
| 1070 | at91_set_A_periph(AT91_PIN_PA11, 1); /* TXD1 */ |
| 1071 | at91_set_A_periph(AT91_PIN_PA12, 0); /* RXD1 */ |
Andrew Victor | c8f385a | 2008-01-23 09:25:15 +0100 | [diff] [blame] | 1072 | |
| 1073 | if (pins & ATMEL_UART_RTS) |
| 1074 | at91_set_B_periph(AT91_PIN_PA18, 0); /* RTS1 */ |
| 1075 | if (pins & ATMEL_UART_CTS) |
| 1076 | at91_set_B_periph(AT91_PIN_PA19, 0); /* CTS1 */ |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 1077 | } |
| 1078 | |
| 1079 | static struct resource uart2_resources[] = { |
| 1080 | [0] = { |
| 1081 | .start = AT91SAM9RL_BASE_US2, |
| 1082 | .end = AT91SAM9RL_BASE_US2 + SZ_16K - 1, |
| 1083 | .flags = IORESOURCE_MEM, |
| 1084 | }, |
| 1085 | [1] = { |
Ludovic Desroches | 8fe82a5 | 2012-06-21 14:47:27 +0200 | [diff] [blame] | 1086 | .start = NR_IRQS_LEGACY + AT91SAM9RL_ID_US2, |
| 1087 | .end = NR_IRQS_LEGACY + AT91SAM9RL_ID_US2, |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 1088 | .flags = IORESOURCE_IRQ, |
| 1089 | }, |
| 1090 | }; |
| 1091 | |
| 1092 | static struct atmel_uart_data uart2_data = { |
| 1093 | .use_dma_tx = 1, |
| 1094 | .use_dma_rx = 1, |
Linus Walleij | 354e57f | 2013-11-07 10:25:55 +0100 | [diff] [blame] | 1095 | .rts_gpio = -EINVAL, |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 1096 | }; |
| 1097 | |
Andrew Victor | c6686ff | 2008-01-23 09:13:53 +0100 | [diff] [blame] | 1098 | static u64 uart2_dmamask = DMA_BIT_MASK(32); |
| 1099 | |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 1100 | static struct platform_device at91sam9rl_uart2_device = { |
| 1101 | .name = "atmel_usart", |
| 1102 | .id = 3, |
| 1103 | .dev = { |
Andrew Victor | c6686ff | 2008-01-23 09:13:53 +0100 | [diff] [blame] | 1104 | .dma_mask = &uart2_dmamask, |
| 1105 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 1106 | .platform_data = &uart2_data, |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 1107 | }, |
| 1108 | .resource = uart2_resources, |
| 1109 | .num_resources = ARRAY_SIZE(uart2_resources), |
| 1110 | }; |
| 1111 | |
Andrew Victor | c8f385a | 2008-01-23 09:25:15 +0100 | [diff] [blame] | 1112 | static inline void configure_usart2_pins(unsigned pins) |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 1113 | { |
| 1114 | at91_set_A_periph(AT91_PIN_PA13, 1); /* TXD2 */ |
| 1115 | at91_set_A_periph(AT91_PIN_PA14, 0); /* RXD2 */ |
Andrew Victor | c8f385a | 2008-01-23 09:25:15 +0100 | [diff] [blame] | 1116 | |
| 1117 | if (pins & ATMEL_UART_RTS) |
| 1118 | at91_set_A_periph(AT91_PIN_PA29, 0); /* RTS2 */ |
| 1119 | if (pins & ATMEL_UART_CTS) |
| 1120 | at91_set_A_periph(AT91_PIN_PA30, 0); /* CTS2 */ |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 1121 | } |
| 1122 | |
| 1123 | static struct resource uart3_resources[] = { |
| 1124 | [0] = { |
| 1125 | .start = AT91SAM9RL_BASE_US3, |
| 1126 | .end = AT91SAM9RL_BASE_US3 + SZ_16K - 1, |
| 1127 | .flags = IORESOURCE_MEM, |
| 1128 | }, |
| 1129 | [1] = { |
Ludovic Desroches | 8fe82a5 | 2012-06-21 14:47:27 +0200 | [diff] [blame] | 1130 | .start = NR_IRQS_LEGACY + AT91SAM9RL_ID_US3, |
| 1131 | .end = NR_IRQS_LEGACY + AT91SAM9RL_ID_US3, |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 1132 | .flags = IORESOURCE_IRQ, |
| 1133 | }, |
| 1134 | }; |
| 1135 | |
| 1136 | static struct atmel_uart_data uart3_data = { |
| 1137 | .use_dma_tx = 1, |
| 1138 | .use_dma_rx = 1, |
Linus Walleij | 354e57f | 2013-11-07 10:25:55 +0100 | [diff] [blame] | 1139 | .rts_gpio = -EINVAL, |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 1140 | }; |
| 1141 | |
Andrew Victor | c6686ff | 2008-01-23 09:13:53 +0100 | [diff] [blame] | 1142 | static u64 uart3_dmamask = DMA_BIT_MASK(32); |
| 1143 | |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 1144 | static struct platform_device at91sam9rl_uart3_device = { |
| 1145 | .name = "atmel_usart", |
| 1146 | .id = 4, |
| 1147 | .dev = { |
Andrew Victor | c6686ff | 2008-01-23 09:13:53 +0100 | [diff] [blame] | 1148 | .dma_mask = &uart3_dmamask, |
| 1149 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 1150 | .platform_data = &uart3_data, |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 1151 | }, |
| 1152 | .resource = uart3_resources, |
| 1153 | .num_resources = ARRAY_SIZE(uart3_resources), |
| 1154 | }; |
| 1155 | |
Andrew Victor | c8f385a | 2008-01-23 09:25:15 +0100 | [diff] [blame] | 1156 | static inline void configure_usart3_pins(unsigned pins) |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 1157 | { |
| 1158 | at91_set_A_periph(AT91_PIN_PB0, 1); /* TXD3 */ |
| 1159 | at91_set_A_periph(AT91_PIN_PB1, 0); /* RXD3 */ |
Andrew Victor | c8f385a | 2008-01-23 09:25:15 +0100 | [diff] [blame] | 1160 | |
| 1161 | if (pins & ATMEL_UART_RTS) |
| 1162 | at91_set_B_periph(AT91_PIN_PD4, 0); /* RTS3 */ |
| 1163 | if (pins & ATMEL_UART_CTS) |
| 1164 | at91_set_B_periph(AT91_PIN_PD3, 0); /* CTS3 */ |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 1165 | } |
| 1166 | |
Andrew Victor | 11aadac | 2008-04-15 21:16:38 +0100 | [diff] [blame] | 1167 | static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */ |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 1168 | |
Andrew Victor | c8f385a | 2008-01-23 09:25:15 +0100 | [diff] [blame] | 1169 | void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) |
| 1170 | { |
| 1171 | struct platform_device *pdev; |
Jean-Christophe PLAGNIOL-VILLARD | 2b348e2 | 2011-04-10 14:10:05 +0800 | [diff] [blame] | 1172 | struct atmel_uart_data *pdata; |
Andrew Victor | c8f385a | 2008-01-23 09:25:15 +0100 | [diff] [blame] | 1173 | |
| 1174 | switch (id) { |
| 1175 | case 0: /* DBGU */ |
| 1176 | pdev = &at91sam9rl_dbgu_device; |
| 1177 | configure_dbgu_pins(); |
Andrew Victor | c8f385a | 2008-01-23 09:25:15 +0100 | [diff] [blame] | 1178 | break; |
| 1179 | case AT91SAM9RL_ID_US0: |
| 1180 | pdev = &at91sam9rl_uart0_device; |
| 1181 | configure_usart0_pins(pins); |
Andrew Victor | c8f385a | 2008-01-23 09:25:15 +0100 | [diff] [blame] | 1182 | break; |
| 1183 | case AT91SAM9RL_ID_US1: |
| 1184 | pdev = &at91sam9rl_uart1_device; |
| 1185 | configure_usart1_pins(pins); |
Andrew Victor | c8f385a | 2008-01-23 09:25:15 +0100 | [diff] [blame] | 1186 | break; |
| 1187 | case AT91SAM9RL_ID_US2: |
| 1188 | pdev = &at91sam9rl_uart2_device; |
| 1189 | configure_usart2_pins(pins); |
Andrew Victor | c8f385a | 2008-01-23 09:25:15 +0100 | [diff] [blame] | 1190 | break; |
| 1191 | case AT91SAM9RL_ID_US3: |
| 1192 | pdev = &at91sam9rl_uart3_device; |
| 1193 | configure_usart3_pins(pins); |
Andrew Victor | c8f385a | 2008-01-23 09:25:15 +0100 | [diff] [blame] | 1194 | break; |
| 1195 | default: |
| 1196 | return; |
| 1197 | } |
Jean-Christophe PLAGNIOL-VILLARD | 2b348e2 | 2011-04-10 14:10:05 +0800 | [diff] [blame] | 1198 | pdata = pdev->dev.platform_data; |
| 1199 | pdata->num = portnr; /* update to mapped ID */ |
Andrew Victor | c8f385a | 2008-01-23 09:25:15 +0100 | [diff] [blame] | 1200 | |
| 1201 | if (portnr < ATMEL_MAX_UART) |
| 1202 | at91_uarts[portnr] = pdev; |
| 1203 | } |
| 1204 | |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 1205 | void __init at91_add_device_serial(void) |
| 1206 | { |
| 1207 | int i; |
| 1208 | |
| 1209 | for (i = 0; i < ATMEL_MAX_UART; i++) { |
| 1210 | if (at91_uarts[i]) |
| 1211 | platform_device_register(at91_uarts[i]); |
| 1212 | } |
| 1213 | } |
| 1214 | #else |
Andrew Victor | c8f385a | 2008-01-23 09:25:15 +0100 | [diff] [blame] | 1215 | void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {} |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 1216 | void __init at91_add_device_serial(void) {} |
| 1217 | #endif |
| 1218 | |
| 1219 | |
| 1220 | /* -------------------------------------------------------------------- */ |
| 1221 | |
| 1222 | /* |
| 1223 | * These devices are always present and don't need any board-specific |
| 1224 | * setup. |
| 1225 | */ |
| 1226 | static int __init at91_add_standard_devices(void) |
| 1227 | { |
Nicolas Ferre | 6ff89e9 | 2009-07-24 11:43:00 +0100 | [diff] [blame] | 1228 | at91_add_device_hdmac(); |
Andrew Victor | 884f5a6 | 2008-01-23 09:11:13 +0100 | [diff] [blame] | 1229 | at91_add_device_rtc(); |
| 1230 | at91_add_device_rtt(); |
| 1231 | at91_add_device_watchdog(); |
Andrew Victor | e5f40bf | 2008-04-02 21:58:00 +0100 | [diff] [blame] | 1232 | at91_add_device_tc(); |
Andrew Victor | 877d772 | 2007-05-11 20:49:56 +0100 | [diff] [blame] | 1233 | return 0; |
| 1234 | } |
| 1235 | |
| 1236 | arch_initcall(at91_add_standard_devices); |