| Nicholas Flintham | 9fafe90 | 2014-03-31 13:51:31 +0100 | [diff] [blame^] | 1 | /* |
| 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> |
| 16 | #include <linux/gpio.h> |
| 17 | #include <linux/clk.h> |
| 18 | #include <linux/platform_device.h> |
| 19 | #include <linux/i2c-gpio.h> |
| 20 | #include <linux/atmel-mci.h> |
| 21 | |
| 22 | #include <linux/fb.h> |
| 23 | #include <video/atmel_lcdc.h> |
| 24 | |
| 25 | #include <mach/board.h> |
| 26 | #include <mach/at91sam9g45.h> |
| 27 | #include <mach/at91sam9g45_matrix.h> |
| 28 | #include <mach/at91_matrix.h> |
| 29 | #include <mach/at91sam9_smc.h> |
| 30 | #include <mach/at_hdmac.h> |
| 31 | #include <mach/atmel-mci.h> |
| 32 | |
| 33 | #include <media/atmel-isi.h> |
| 34 | |
| 35 | #include "generic.h" |
| 36 | #include "clock.h" |
| 37 | |
| 38 | |
| 39 | |
| 40 | #if defined(CONFIG_AT_HDMAC) || defined(CONFIG_AT_HDMAC_MODULE) |
| 41 | static u64 hdmac_dmamask = DMA_BIT_MASK(32); |
| 42 | |
| 43 | static struct resource hdmac_resources[] = { |
| 44 | [0] = { |
| 45 | .start = AT91SAM9G45_BASE_DMA, |
| 46 | .end = AT91SAM9G45_BASE_DMA + SZ_512 - 1, |
| 47 | .flags = IORESOURCE_MEM, |
| 48 | }, |
| 49 | [1] = { |
| 50 | .start = AT91SAM9G45_ID_DMA, |
| 51 | .end = AT91SAM9G45_ID_DMA, |
| 52 | .flags = IORESOURCE_IRQ, |
| 53 | }, |
| 54 | }; |
| 55 | |
| 56 | static struct platform_device at_hdmac_device = { |
| 57 | .name = "at91sam9g45_dma", |
| 58 | .id = -1, |
| 59 | .dev = { |
| 60 | .dma_mask = &hdmac_dmamask, |
| 61 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 62 | }, |
| 63 | .resource = hdmac_resources, |
| 64 | .num_resources = ARRAY_SIZE(hdmac_resources), |
| 65 | }; |
| 66 | |
| 67 | void __init at91_add_device_hdmac(void) |
| 68 | { |
| 69 | #if defined(CONFIG_OF) |
| 70 | struct device_node *of_node = |
| 71 | of_find_node_by_name(NULL, "dma-controller"); |
| 72 | |
| 73 | if (of_node) |
| 74 | of_node_put(of_node); |
| 75 | else |
| 76 | #endif |
| 77 | platform_device_register(&at_hdmac_device); |
| 78 | } |
| 79 | #else |
| 80 | void __init at91_add_device_hdmac(void) {} |
| 81 | #endif |
| 82 | |
| 83 | |
| 84 | |
| 85 | #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE) |
| 86 | static u64 ohci_dmamask = DMA_BIT_MASK(32); |
| 87 | static struct at91_usbh_data usbh_ohci_data; |
| 88 | |
| 89 | static struct resource usbh_ohci_resources[] = { |
| 90 | [0] = { |
| 91 | .start = AT91SAM9G45_OHCI_BASE, |
| 92 | .end = AT91SAM9G45_OHCI_BASE + SZ_1M - 1, |
| 93 | .flags = IORESOURCE_MEM, |
| 94 | }, |
| 95 | [1] = { |
| 96 | .start = AT91SAM9G45_ID_UHPHS, |
| 97 | .end = AT91SAM9G45_ID_UHPHS, |
| 98 | .flags = IORESOURCE_IRQ, |
| 99 | }, |
| 100 | }; |
| 101 | |
| 102 | static struct platform_device at91_usbh_ohci_device = { |
| 103 | .name = "at91_ohci", |
| 104 | .id = -1, |
| 105 | .dev = { |
| 106 | .dma_mask = &ohci_dmamask, |
| 107 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 108 | .platform_data = &usbh_ohci_data, |
| 109 | }, |
| 110 | .resource = usbh_ohci_resources, |
| 111 | .num_resources = ARRAY_SIZE(usbh_ohci_resources), |
| 112 | }; |
| 113 | |
| 114 | void __init at91_add_device_usbh_ohci(struct at91_usbh_data *data) |
| 115 | { |
| 116 | int i; |
| 117 | |
| 118 | if (!data) |
| 119 | return; |
| 120 | |
| 121 | |
| 122 | for (i = 0; i < data->ports; i++) { |
| 123 | if (gpio_is_valid(data->vbus_pin[i])) |
| 124 | at91_set_gpio_output(data->vbus_pin[i], |
| 125 | data->vbus_pin_active_low[i]); |
| 126 | } |
| 127 | |
| 128 | |
| 129 | for (i = 0; i < data->ports; i++) { |
| 130 | if (gpio_is_valid(data->overcurrent_pin[i])) |
| 131 | at91_set_gpio_input(data->overcurrent_pin[i], 1); |
| 132 | } |
| 133 | |
| 134 | usbh_ohci_data = *data; |
| 135 | platform_device_register(&at91_usbh_ohci_device); |
| 136 | } |
| 137 | #else |
| 138 | void __init at91_add_device_usbh_ohci(struct at91_usbh_data *data) {} |
| 139 | #endif |
| 140 | |
| 141 | |
| 142 | |
| 143 | #if defined(CONFIG_USB_EHCI_HCD) || defined(CONFIG_USB_EHCI_HCD_MODULE) |
| 144 | static u64 ehci_dmamask = DMA_BIT_MASK(32); |
| 145 | static struct at91_usbh_data usbh_ehci_data; |
| 146 | |
| 147 | static struct resource usbh_ehci_resources[] = { |
| 148 | [0] = { |
| 149 | .start = AT91SAM9G45_EHCI_BASE, |
| 150 | .end = AT91SAM9G45_EHCI_BASE + SZ_1M - 1, |
| 151 | .flags = IORESOURCE_MEM, |
| 152 | }, |
| 153 | [1] = { |
| 154 | .start = AT91SAM9G45_ID_UHPHS, |
| 155 | .end = AT91SAM9G45_ID_UHPHS, |
| 156 | .flags = IORESOURCE_IRQ, |
| 157 | }, |
| 158 | }; |
| 159 | |
| 160 | static struct platform_device at91_usbh_ehci_device = { |
| 161 | .name = "atmel-ehci", |
| 162 | .id = -1, |
| 163 | .dev = { |
| 164 | .dma_mask = &ehci_dmamask, |
| 165 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 166 | .platform_data = &usbh_ehci_data, |
| 167 | }, |
| 168 | .resource = usbh_ehci_resources, |
| 169 | .num_resources = ARRAY_SIZE(usbh_ehci_resources), |
| 170 | }; |
| 171 | |
| 172 | void __init at91_add_device_usbh_ehci(struct at91_usbh_data *data) |
| 173 | { |
| 174 | int i; |
| 175 | |
| 176 | if (!data) |
| 177 | return; |
| 178 | |
| 179 | |
| 180 | for (i = 0; i < data->ports; i++) { |
| 181 | if (gpio_is_valid(data->vbus_pin[i])) |
| 182 | at91_set_gpio_output(data->vbus_pin[i], |
| 183 | data->vbus_pin_active_low[i]); |
| 184 | } |
| 185 | |
| 186 | usbh_ehci_data = *data; |
| 187 | platform_device_register(&at91_usbh_ehci_device); |
| 188 | } |
| 189 | #else |
| 190 | void __init at91_add_device_usbh_ehci(struct at91_usbh_data *data) {} |
| 191 | #endif |
| 192 | |
| 193 | |
| 194 | |
| 195 | #if defined(CONFIG_USB_ATMEL_USBA) || defined(CONFIG_USB_ATMEL_USBA_MODULE) |
| 196 | static struct resource usba_udc_resources[] = { |
| 197 | [0] = { |
| 198 | .start = AT91SAM9G45_UDPHS_FIFO, |
| 199 | .end = AT91SAM9G45_UDPHS_FIFO + SZ_512K - 1, |
| 200 | .flags = IORESOURCE_MEM, |
| 201 | }, |
| 202 | [1] = { |
| 203 | .start = AT91SAM9G45_BASE_UDPHS, |
| 204 | .end = AT91SAM9G45_BASE_UDPHS + SZ_1K - 1, |
| 205 | .flags = IORESOURCE_MEM, |
| 206 | }, |
| 207 | [2] = { |
| 208 | .start = AT91SAM9G45_ID_UDPHS, |
| 209 | .end = AT91SAM9G45_ID_UDPHS, |
| 210 | .flags = IORESOURCE_IRQ, |
| 211 | }, |
| 212 | }; |
| 213 | |
| 214 | #define EP(nam, idx, maxpkt, maxbk, dma, isoc) \ |
| 215 | [idx] = { \ |
| 216 | .name = nam, \ |
| 217 | .index = idx, \ |
| 218 | .fifo_size = maxpkt, \ |
| 219 | .nr_banks = maxbk, \ |
| 220 | .can_dma = dma, \ |
| 221 | .can_isoc = isoc, \ |
| 222 | } |
| 223 | |
| 224 | static struct usba_ep_data usba_udc_ep[] __initdata = { |
| 225 | EP("ep0", 0, 64, 1, 0, 0), |
| 226 | EP("ep1", 1, 1024, 2, 1, 1), |
| 227 | EP("ep2", 2, 1024, 2, 1, 1), |
| 228 | EP("ep3", 3, 1024, 3, 1, 0), |
| 229 | EP("ep4", 4, 1024, 3, 1, 0), |
| 230 | EP("ep5", 5, 1024, 3, 1, 1), |
| 231 | EP("ep6", 6, 1024, 3, 1, 1), |
| 232 | }; |
| 233 | |
| 234 | #undef EP |
| 235 | |
| 236 | static struct { |
| 237 | struct usba_platform_data pdata; |
| 238 | struct usba_ep_data ep[7]; |
| 239 | } usba_udc_data; |
| 240 | |
| 241 | static struct platform_device at91_usba_udc_device = { |
| 242 | .name = "atmel_usba_udc", |
| 243 | .id = -1, |
| 244 | .dev = { |
| 245 | .platform_data = &usba_udc_data.pdata, |
| 246 | }, |
| 247 | .resource = usba_udc_resources, |
| 248 | .num_resources = ARRAY_SIZE(usba_udc_resources), |
| 249 | }; |
| 250 | |
| 251 | void __init at91_add_device_usba(struct usba_platform_data *data) |
| 252 | { |
| 253 | usba_udc_data.pdata.vbus_pin = -EINVAL; |
| 254 | usba_udc_data.pdata.num_ep = ARRAY_SIZE(usba_udc_ep); |
| 255 | memcpy(usba_udc_data.ep, usba_udc_ep, sizeof(usba_udc_ep)); |
| 256 | |
| 257 | if (data && gpio_is_valid(data->vbus_pin)) { |
| 258 | at91_set_gpio_input(data->vbus_pin, 0); |
| 259 | at91_set_deglitch(data->vbus_pin, 1); |
| 260 | usba_udc_data.pdata.vbus_pin = data->vbus_pin; |
| 261 | } |
| 262 | |
| 263 | |
| 264 | |
| 265 | platform_device_register(&at91_usba_udc_device); |
| 266 | } |
| 267 | #else |
| 268 | void __init at91_add_device_usba(struct usba_platform_data *data) {} |
| 269 | #endif |
| 270 | |
| 271 | |
| 272 | |
| 273 | #if defined(CONFIG_MACB) || defined(CONFIG_MACB_MODULE) |
| 274 | static u64 eth_dmamask = DMA_BIT_MASK(32); |
| 275 | static struct macb_platform_data eth_data; |
| 276 | |
| 277 | static struct resource eth_resources[] = { |
| 278 | [0] = { |
| 279 | .start = AT91SAM9G45_BASE_EMAC, |
| 280 | .end = AT91SAM9G45_BASE_EMAC + SZ_16K - 1, |
| 281 | .flags = IORESOURCE_MEM, |
| 282 | }, |
| 283 | [1] = { |
| 284 | .start = AT91SAM9G45_ID_EMAC, |
| 285 | .end = AT91SAM9G45_ID_EMAC, |
| 286 | .flags = IORESOURCE_IRQ, |
| 287 | }, |
| 288 | }; |
| 289 | |
| 290 | static struct platform_device at91sam9g45_eth_device = { |
| 291 | .name = "macb", |
| 292 | .id = -1, |
| 293 | .dev = { |
| 294 | .dma_mask = ð_dmamask, |
| 295 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 296 | .platform_data = ð_data, |
| 297 | }, |
| 298 | .resource = eth_resources, |
| 299 | .num_resources = ARRAY_SIZE(eth_resources), |
| 300 | }; |
| 301 | |
| 302 | void __init at91_add_device_eth(struct macb_platform_data *data) |
| 303 | { |
| 304 | if (!data) |
| 305 | return; |
| 306 | |
| 307 | if (gpio_is_valid(data->phy_irq_pin)) { |
| 308 | at91_set_gpio_input(data->phy_irq_pin, 0); |
| 309 | at91_set_deglitch(data->phy_irq_pin, 1); |
| 310 | } |
| 311 | |
| 312 | |
| 313 | at91_set_A_periph(AT91_PIN_PA17, 0); |
| 314 | at91_set_A_periph(AT91_PIN_PA15, 0); |
| 315 | at91_set_A_periph(AT91_PIN_PA12, 0); |
| 316 | at91_set_A_periph(AT91_PIN_PA13, 0); |
| 317 | at91_set_A_periph(AT91_PIN_PA16, 0); |
| 318 | at91_set_A_periph(AT91_PIN_PA14, 0); |
| 319 | at91_set_A_periph(AT91_PIN_PA10, 0); |
| 320 | at91_set_A_periph(AT91_PIN_PA11, 0); |
| 321 | at91_set_A_periph(AT91_PIN_PA19, 0); |
| 322 | at91_set_A_periph(AT91_PIN_PA18, 0); |
| 323 | |
| 324 | if (!data->is_rmii) { |
| 325 | at91_set_B_periph(AT91_PIN_PA29, 0); |
| 326 | at91_set_B_periph(AT91_PIN_PA30, 0); |
| 327 | at91_set_B_periph(AT91_PIN_PA8, 0); |
| 328 | at91_set_B_periph(AT91_PIN_PA9, 0); |
| 329 | at91_set_B_periph(AT91_PIN_PA28, 0); |
| 330 | at91_set_B_periph(AT91_PIN_PA6, 0); |
| 331 | at91_set_B_periph(AT91_PIN_PA7, 0); |
| 332 | at91_set_B_periph(AT91_PIN_PA27, 0); |
| 333 | } |
| 334 | |
| 335 | eth_data = *data; |
| 336 | platform_device_register(&at91sam9g45_eth_device); |
| 337 | } |
| 338 | #else |
| 339 | void __init at91_add_device_eth(struct macb_platform_data *data) {} |
| 340 | #endif |
| 341 | |
| 342 | |
| 343 | |
| 344 | #if defined(CONFIG_MMC_ATMELMCI) || defined(CONFIG_MMC_ATMELMCI_MODULE) |
| 345 | static u64 mmc_dmamask = DMA_BIT_MASK(32); |
| 346 | static struct mci_platform_data mmc0_data, mmc1_data; |
| 347 | |
| 348 | static struct resource mmc0_resources[] = { |
| 349 | [0] = { |
| 350 | .start = AT91SAM9G45_BASE_MCI0, |
| 351 | .end = AT91SAM9G45_BASE_MCI0 + SZ_16K - 1, |
| 352 | .flags = IORESOURCE_MEM, |
| 353 | }, |
| 354 | [1] = { |
| 355 | .start = AT91SAM9G45_ID_MCI0, |
| 356 | .end = AT91SAM9G45_ID_MCI0, |
| 357 | .flags = IORESOURCE_IRQ, |
| 358 | }, |
| 359 | }; |
| 360 | |
| 361 | static struct platform_device at91sam9g45_mmc0_device = { |
| 362 | .name = "atmel_mci", |
| 363 | .id = 0, |
| 364 | .dev = { |
| 365 | .dma_mask = &mmc_dmamask, |
| 366 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 367 | .platform_data = &mmc0_data, |
| 368 | }, |
| 369 | .resource = mmc0_resources, |
| 370 | .num_resources = ARRAY_SIZE(mmc0_resources), |
| 371 | }; |
| 372 | |
| 373 | static struct resource mmc1_resources[] = { |
| 374 | [0] = { |
| 375 | .start = AT91SAM9G45_BASE_MCI1, |
| 376 | .end = AT91SAM9G45_BASE_MCI1 + SZ_16K - 1, |
| 377 | .flags = IORESOURCE_MEM, |
| 378 | }, |
| 379 | [1] = { |
| 380 | .start = AT91SAM9G45_ID_MCI1, |
| 381 | .end = AT91SAM9G45_ID_MCI1, |
| 382 | .flags = IORESOURCE_IRQ, |
| 383 | }, |
| 384 | }; |
| 385 | |
| 386 | static struct platform_device at91sam9g45_mmc1_device = { |
| 387 | .name = "atmel_mci", |
| 388 | .id = 1, |
| 389 | .dev = { |
| 390 | .dma_mask = &mmc_dmamask, |
| 391 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 392 | .platform_data = &mmc1_data, |
| 393 | }, |
| 394 | .resource = mmc1_resources, |
| 395 | .num_resources = ARRAY_SIZE(mmc1_resources), |
| 396 | }; |
| 397 | |
| 398 | void __init at91_add_device_mci(short mmc_id, struct mci_platform_data *data) |
| 399 | { |
| 400 | |
| 401 | if (!data) |
| 402 | return; |
| 403 | |
| 404 | |
| 405 | if (!data->slot[0].bus_width) |
| 406 | return; |
| 407 | |
| 408 | #if defined(CONFIG_AT_HDMAC) || defined(CONFIG_AT_HDMAC_MODULE) |
| 409 | { |
| 410 | struct at_dma_slave *atslave; |
| 411 | struct mci_dma_data *alt_atslave; |
| 412 | |
| 413 | alt_atslave = kzalloc(sizeof(struct mci_dma_data), GFP_KERNEL); |
| 414 | atslave = &alt_atslave->sdata; |
| 415 | |
| 416 | |
| 417 | atslave->dma_dev = &at_hdmac_device.dev; |
| 418 | atslave->cfg = ATC_FIFOCFG_HALFFIFO |
| 419 | | ATC_SRC_H2SEL_HW | ATC_DST_H2SEL_HW; |
| 420 | atslave->ctrla = ATC_SCSIZE_16 | ATC_DCSIZE_16; |
| 421 | if (mmc_id == 0) |
| 422 | atslave->cfg |= ATC_SRC_PER(AT_DMA_ID_MCI0) |
| 423 | | ATC_DST_PER(AT_DMA_ID_MCI0); |
| 424 | |
| 425 | else |
| 426 | atslave->cfg |= ATC_SRC_PER(AT_DMA_ID_MCI1) |
| 427 | | ATC_DST_PER(AT_DMA_ID_MCI1); |
| 428 | |
| 429 | data->dma_slave = alt_atslave; |
| 430 | } |
| 431 | #endif |
| 432 | |
| 433 | |
| 434 | |
| 435 | if (gpio_is_valid(data->slot[0].detect_pin)) { |
| 436 | at91_set_gpio_input(data->slot[0].detect_pin, 1); |
| 437 | at91_set_deglitch(data->slot[0].detect_pin, 1); |
| 438 | } |
| 439 | if (gpio_is_valid(data->slot[0].wp_pin)) |
| 440 | at91_set_gpio_input(data->slot[0].wp_pin, 1); |
| 441 | |
| 442 | if (mmc_id == 0) { |
| 443 | |
| 444 | |
| 445 | at91_set_A_periph(AT91_PIN_PA0, 0); |
| 446 | |
| 447 | |
| 448 | at91_set_A_periph(AT91_PIN_PA1, 1); |
| 449 | |
| 450 | |
| 451 | at91_set_A_periph(AT91_PIN_PA2, 1); |
| 452 | if (data->slot[0].bus_width == 4) { |
| 453 | at91_set_A_periph(AT91_PIN_PA3, 1); |
| 454 | at91_set_A_periph(AT91_PIN_PA4, 1); |
| 455 | at91_set_A_periph(AT91_PIN_PA5, 1); |
| 456 | if (data->slot[0].bus_width == 8) { |
| 457 | at91_set_A_periph(AT91_PIN_PA6, 1); |
| 458 | at91_set_A_periph(AT91_PIN_PA7, 1); |
| 459 | at91_set_A_periph(AT91_PIN_PA8, 1); |
| 460 | at91_set_A_periph(AT91_PIN_PA9, 1); |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | mmc0_data = *data; |
| 465 | platform_device_register(&at91sam9g45_mmc0_device); |
| 466 | |
| 467 | } else { |
| 468 | |
| 469 | |
| 470 | at91_set_A_periph(AT91_PIN_PA31, 0); |
| 471 | |
| 472 | |
| 473 | at91_set_A_periph(AT91_PIN_PA22, 1); |
| 474 | |
| 475 | |
| 476 | at91_set_A_periph(AT91_PIN_PA23, 1); |
| 477 | if (data->slot[0].bus_width == 4) { |
| 478 | at91_set_A_periph(AT91_PIN_PA24, 1); |
| 479 | at91_set_A_periph(AT91_PIN_PA25, 1); |
| 480 | at91_set_A_periph(AT91_PIN_PA26, 1); |
| 481 | if (data->slot[0].bus_width == 8) { |
| 482 | at91_set_A_periph(AT91_PIN_PA27, 1); |
| 483 | at91_set_A_periph(AT91_PIN_PA28, 1); |
| 484 | at91_set_A_periph(AT91_PIN_PA29, 1); |
| 485 | at91_set_A_periph(AT91_PIN_PA30, 1); |
| 486 | } |
| 487 | } |
| 488 | |
| 489 | mmc1_data = *data; |
| 490 | platform_device_register(&at91sam9g45_mmc1_device); |
| 491 | |
| 492 | } |
| 493 | } |
| 494 | #else |
| 495 | void __init at91_add_device_mci(short mmc_id, struct mci_platform_data *data) {} |
| 496 | #endif |
| 497 | |
| 498 | |
| 499 | |
| 500 | #if defined(CONFIG_MTD_NAND_ATMEL) || defined(CONFIG_MTD_NAND_ATMEL_MODULE) |
| 501 | static struct atmel_nand_data nand_data; |
| 502 | |
| 503 | #define NAND_BASE AT91_CHIPSELECT_3 |
| 504 | |
| 505 | static struct resource nand_resources[] = { |
| 506 | [0] = { |
| 507 | .start = NAND_BASE, |
| 508 | .end = NAND_BASE + SZ_256M - 1, |
| 509 | .flags = IORESOURCE_MEM, |
| 510 | }, |
| 511 | [1] = { |
| 512 | .start = AT91SAM9G45_BASE_ECC, |
| 513 | .end = AT91SAM9G45_BASE_ECC + SZ_512 - 1, |
| 514 | .flags = IORESOURCE_MEM, |
| 515 | } |
| 516 | }; |
| 517 | |
| 518 | static struct platform_device at91sam9g45_nand_device = { |
| 519 | .name = "atmel_nand", |
| 520 | .id = -1, |
| 521 | .dev = { |
| 522 | .platform_data = &nand_data, |
| 523 | }, |
| 524 | .resource = nand_resources, |
| 525 | .num_resources = ARRAY_SIZE(nand_resources), |
| 526 | }; |
| 527 | |
| 528 | void __init at91_add_device_nand(struct atmel_nand_data *data) |
| 529 | { |
| 530 | unsigned long csa; |
| 531 | |
| 532 | if (!data) |
| 533 | return; |
| 534 | |
| 535 | csa = at91_matrix_read(AT91_MATRIX_EBICSA); |
| 536 | at91_matrix_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_EBI_CS3A_SMC_SMARTMEDIA); |
| 537 | |
| 538 | |
| 539 | if (gpio_is_valid(data->enable_pin)) |
| 540 | at91_set_gpio_output(data->enable_pin, 1); |
| 541 | |
| 542 | |
| 543 | if (gpio_is_valid(data->rdy_pin)) |
| 544 | at91_set_gpio_input(data->rdy_pin, 1); |
| 545 | |
| 546 | |
| 547 | if (gpio_is_valid(data->det_pin)) |
| 548 | at91_set_gpio_input(data->det_pin, 1); |
| 549 | |
| 550 | nand_data = *data; |
| 551 | platform_device_register(&at91sam9g45_nand_device); |
| 552 | } |
| 553 | #else |
| 554 | void __init at91_add_device_nand(struct atmel_nand_data *data) {} |
| 555 | #endif |
| 556 | |
| 557 | |
| 558 | |
| 559 | #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE) |
| 560 | static struct i2c_gpio_platform_data pdata_i2c0 = { |
| 561 | .sda_pin = AT91_PIN_PA20, |
| 562 | .sda_is_open_drain = 1, |
| 563 | .scl_pin = AT91_PIN_PA21, |
| 564 | .scl_is_open_drain = 1, |
| 565 | .udelay = 5, |
| 566 | }; |
| 567 | |
| 568 | static struct platform_device at91sam9g45_twi0_device = { |
| 569 | .name = "i2c-gpio", |
| 570 | .id = 0, |
| 571 | .dev.platform_data = &pdata_i2c0, |
| 572 | }; |
| 573 | |
| 574 | static struct i2c_gpio_platform_data pdata_i2c1 = { |
| 575 | .sda_pin = AT91_PIN_PB10, |
| 576 | .sda_is_open_drain = 1, |
| 577 | .scl_pin = AT91_PIN_PB11, |
| 578 | .scl_is_open_drain = 1, |
| 579 | .udelay = 5, |
| 580 | }; |
| 581 | |
| 582 | static struct platform_device at91sam9g45_twi1_device = { |
| 583 | .name = "i2c-gpio", |
| 584 | .id = 1, |
| 585 | .dev.platform_data = &pdata_i2c1, |
| 586 | }; |
| 587 | |
| 588 | void __init at91_add_device_i2c(short i2c_id, struct i2c_board_info *devices, int nr_devices) |
| 589 | { |
| 590 | i2c_register_board_info(i2c_id, devices, nr_devices); |
| 591 | |
| 592 | if (i2c_id == 0) { |
| 593 | at91_set_GPIO_periph(AT91_PIN_PA20, 1); |
| 594 | at91_set_multi_drive(AT91_PIN_PA20, 1); |
| 595 | |
| 596 | at91_set_GPIO_periph(AT91_PIN_PA21, 1); |
| 597 | at91_set_multi_drive(AT91_PIN_PA21, 1); |
| 598 | |
| 599 | platform_device_register(&at91sam9g45_twi0_device); |
| 600 | } else { |
| 601 | at91_set_GPIO_periph(AT91_PIN_PB10, 1); |
| 602 | at91_set_multi_drive(AT91_PIN_PB10, 1); |
| 603 | |
| 604 | at91_set_GPIO_periph(AT91_PIN_PB11, 1); |
| 605 | at91_set_multi_drive(AT91_PIN_PB11, 1); |
| 606 | |
| 607 | platform_device_register(&at91sam9g45_twi1_device); |
| 608 | } |
| 609 | } |
| 610 | |
| 611 | #elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE) |
| 612 | static struct resource twi0_resources[] = { |
| 613 | [0] = { |
| 614 | .start = AT91SAM9G45_BASE_TWI0, |
| 615 | .end = AT91SAM9G45_BASE_TWI0 + SZ_16K - 1, |
| 616 | .flags = IORESOURCE_MEM, |
| 617 | }, |
| 618 | [1] = { |
| 619 | .start = AT91SAM9G45_ID_TWI0, |
| 620 | .end = AT91SAM9G45_ID_TWI0, |
| 621 | .flags = IORESOURCE_IRQ, |
| 622 | }, |
| 623 | }; |
| 624 | |
| 625 | static struct platform_device at91sam9g45_twi0_device = { |
| 626 | .name = "at91_i2c", |
| 627 | .id = 0, |
| 628 | .resource = twi0_resources, |
| 629 | .num_resources = ARRAY_SIZE(twi0_resources), |
| 630 | }; |
| 631 | |
| 632 | static struct resource twi1_resources[] = { |
| 633 | [0] = { |
| 634 | .start = AT91SAM9G45_BASE_TWI1, |
| 635 | .end = AT91SAM9G45_BASE_TWI1 + SZ_16K - 1, |
| 636 | .flags = IORESOURCE_MEM, |
| 637 | }, |
| 638 | [1] = { |
| 639 | .start = AT91SAM9G45_ID_TWI1, |
| 640 | .end = AT91SAM9G45_ID_TWI1, |
| 641 | .flags = IORESOURCE_IRQ, |
| 642 | }, |
| 643 | }; |
| 644 | |
| 645 | static struct platform_device at91sam9g45_twi1_device = { |
| 646 | .name = "at91_i2c", |
| 647 | .id = 1, |
| 648 | .resource = twi1_resources, |
| 649 | .num_resources = ARRAY_SIZE(twi1_resources), |
| 650 | }; |
| 651 | |
| 652 | void __init at91_add_device_i2c(short i2c_id, struct i2c_board_info *devices, int nr_devices) |
| 653 | { |
| 654 | i2c_register_board_info(i2c_id, devices, nr_devices); |
| 655 | |
| 656 | |
| 657 | if (i2c_id == 0) { |
| 658 | at91_set_A_periph(AT91_PIN_PA20, 0); |
| 659 | at91_set_multi_drive(AT91_PIN_PA20, 1); |
| 660 | |
| 661 | at91_set_A_periph(AT91_PIN_PA21, 0); |
| 662 | at91_set_multi_drive(AT91_PIN_PA21, 1); |
| 663 | |
| 664 | platform_device_register(&at91sam9g45_twi0_device); |
| 665 | } else { |
| 666 | at91_set_A_periph(AT91_PIN_PB10, 0); |
| 667 | at91_set_multi_drive(AT91_PIN_PB10, 1); |
| 668 | |
| 669 | at91_set_A_periph(AT91_PIN_PB11, 0); |
| 670 | at91_set_multi_drive(AT91_PIN_PB11, 1); |
| 671 | |
| 672 | platform_device_register(&at91sam9g45_twi1_device); |
| 673 | } |
| 674 | } |
| 675 | #else |
| 676 | void __init at91_add_device_i2c(short i2c_id, struct i2c_board_info *devices, int nr_devices) {} |
| 677 | #endif |
| 678 | |
| 679 | |
| 680 | |
| 681 | #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE) |
| 682 | static u64 spi_dmamask = DMA_BIT_MASK(32); |
| 683 | |
| 684 | static struct resource spi0_resources[] = { |
| 685 | [0] = { |
| 686 | .start = AT91SAM9G45_BASE_SPI0, |
| 687 | .end = AT91SAM9G45_BASE_SPI0 + SZ_16K - 1, |
| 688 | .flags = IORESOURCE_MEM, |
| 689 | }, |
| 690 | [1] = { |
| 691 | .start = AT91SAM9G45_ID_SPI0, |
| 692 | .end = AT91SAM9G45_ID_SPI0, |
| 693 | .flags = IORESOURCE_IRQ, |
| 694 | }, |
| 695 | }; |
| 696 | |
| 697 | static struct platform_device at91sam9g45_spi0_device = { |
| 698 | .name = "atmel_spi", |
| 699 | .id = 0, |
| 700 | .dev = { |
| 701 | .dma_mask = &spi_dmamask, |
| 702 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 703 | }, |
| 704 | .resource = spi0_resources, |
| 705 | .num_resources = ARRAY_SIZE(spi0_resources), |
| 706 | }; |
| 707 | |
| 708 | static const unsigned spi0_standard_cs[4] = { AT91_PIN_PB3, AT91_PIN_PB18, AT91_PIN_PB19, AT91_PIN_PD27 }; |
| 709 | |
| 710 | static struct resource spi1_resources[] = { |
| 711 | [0] = { |
| 712 | .start = AT91SAM9G45_BASE_SPI1, |
| 713 | .end = AT91SAM9G45_BASE_SPI1 + SZ_16K - 1, |
| 714 | .flags = IORESOURCE_MEM, |
| 715 | }, |
| 716 | [1] = { |
| 717 | .start = AT91SAM9G45_ID_SPI1, |
| 718 | .end = AT91SAM9G45_ID_SPI1, |
| 719 | .flags = IORESOURCE_IRQ, |
| 720 | }, |
| 721 | }; |
| 722 | |
| 723 | static struct platform_device at91sam9g45_spi1_device = { |
| 724 | .name = "atmel_spi", |
| 725 | .id = 1, |
| 726 | .dev = { |
| 727 | .dma_mask = &spi_dmamask, |
| 728 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 729 | }, |
| 730 | .resource = spi1_resources, |
| 731 | .num_resources = ARRAY_SIZE(spi1_resources), |
| 732 | }; |
| 733 | |
| 734 | static const unsigned spi1_standard_cs[4] = { AT91_PIN_PB17, AT91_PIN_PD28, AT91_PIN_PD18, AT91_PIN_PD19 }; |
| 735 | |
| 736 | void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) |
| 737 | { |
| 738 | int i; |
| 739 | unsigned long cs_pin; |
| 740 | short enable_spi0 = 0; |
| 741 | short enable_spi1 = 0; |
| 742 | |
| 743 | |
| 744 | for (i = 0; i < nr_devices; i++) { |
| 745 | if (devices[i].controller_data) |
| 746 | cs_pin = (unsigned long) devices[i].controller_data; |
| 747 | else if (devices[i].bus_num == 0) |
| 748 | cs_pin = spi0_standard_cs[devices[i].chip_select]; |
| 749 | else |
| 750 | cs_pin = spi1_standard_cs[devices[i].chip_select]; |
| 751 | |
| 752 | if (!gpio_is_valid(cs_pin)) |
| 753 | continue; |
| 754 | |
| 755 | if (devices[i].bus_num == 0) |
| 756 | enable_spi0 = 1; |
| 757 | else |
| 758 | enable_spi1 = 1; |
| 759 | |
| 760 | |
| 761 | at91_set_gpio_output(cs_pin, 1); |
| 762 | |
| 763 | |
| 764 | devices[i].controller_data = (void *) cs_pin; |
| 765 | } |
| 766 | |
| 767 | spi_register_board_info(devices, nr_devices); |
| 768 | |
| 769 | |
| 770 | if (enable_spi0) { |
| 771 | at91_set_A_periph(AT91_PIN_PB0, 0); |
| 772 | at91_set_A_periph(AT91_PIN_PB1, 0); |
| 773 | at91_set_A_periph(AT91_PIN_PB2, 0); |
| 774 | |
| 775 | platform_device_register(&at91sam9g45_spi0_device); |
| 776 | } |
| 777 | if (enable_spi1) { |
| 778 | at91_set_A_periph(AT91_PIN_PB14, 0); |
| 779 | at91_set_A_periph(AT91_PIN_PB15, 0); |
| 780 | at91_set_A_periph(AT91_PIN_PB16, 0); |
| 781 | |
| 782 | platform_device_register(&at91sam9g45_spi1_device); |
| 783 | } |
| 784 | } |
| 785 | #else |
| 786 | void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {} |
| 787 | #endif |
| 788 | |
| 789 | |
| 790 | |
| 791 | #if defined(CONFIG_SND_ATMEL_AC97C) || defined(CONFIG_SND_ATMEL_AC97C_MODULE) |
| 792 | static u64 ac97_dmamask = DMA_BIT_MASK(32); |
| 793 | static struct ac97c_platform_data ac97_data; |
| 794 | |
| 795 | static struct resource ac97_resources[] = { |
| 796 | [0] = { |
| 797 | .start = AT91SAM9G45_BASE_AC97C, |
| 798 | .end = AT91SAM9G45_BASE_AC97C + SZ_16K - 1, |
| 799 | .flags = IORESOURCE_MEM, |
| 800 | }, |
| 801 | [1] = { |
| 802 | .start = AT91SAM9G45_ID_AC97C, |
| 803 | .end = AT91SAM9G45_ID_AC97C, |
| 804 | .flags = IORESOURCE_IRQ, |
| 805 | }, |
| 806 | }; |
| 807 | |
| 808 | static struct platform_device at91sam9g45_ac97_device = { |
| 809 | .name = "atmel_ac97c", |
| 810 | .id = 0, |
| 811 | .dev = { |
| 812 | .dma_mask = &ac97_dmamask, |
| 813 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 814 | .platform_data = &ac97_data, |
| 815 | }, |
| 816 | .resource = ac97_resources, |
| 817 | .num_resources = ARRAY_SIZE(ac97_resources), |
| 818 | }; |
| 819 | |
| 820 | void __init at91_add_device_ac97(struct ac97c_platform_data *data) |
| 821 | { |
| 822 | if (!data) |
| 823 | return; |
| 824 | |
| 825 | at91_set_A_periph(AT91_PIN_PD8, 0); |
| 826 | at91_set_A_periph(AT91_PIN_PD9, 0); |
| 827 | at91_set_A_periph(AT91_PIN_PD7, 0); |
| 828 | at91_set_A_periph(AT91_PIN_PD6, 0); |
| 829 | |
| 830 | |
| 831 | if (gpio_is_valid(data->reset_pin)) |
| 832 | at91_set_gpio_output(data->reset_pin, 0); |
| 833 | |
| 834 | ac97_data = *data; |
| 835 | platform_device_register(&at91sam9g45_ac97_device); |
| 836 | } |
| 837 | #else |
| 838 | void __init at91_add_device_ac97(struct ac97c_platform_data *data) {} |
| 839 | #endif |
| 840 | |
| 841 | #if defined(CONFIG_VIDEO_ATMEL_ISI) || defined(CONFIG_VIDEO_ATMEL_ISI_MODULE) |
| 842 | static u64 isi_dmamask = DMA_BIT_MASK(32); |
| 843 | static struct isi_platform_data isi_data; |
| 844 | |
| 845 | struct resource isi_resources[] = { |
| 846 | [0] = { |
| 847 | .start = AT91SAM9G45_BASE_ISI, |
| 848 | .end = AT91SAM9G45_BASE_ISI + SZ_16K - 1, |
| 849 | .flags = IORESOURCE_MEM, |
| 850 | }, |
| 851 | [1] = { |
| 852 | .start = AT91SAM9G45_ID_ISI, |
| 853 | .end = AT91SAM9G45_ID_ISI, |
| 854 | .flags = IORESOURCE_IRQ, |
| 855 | }, |
| 856 | }; |
| 857 | |
| 858 | static struct platform_device at91sam9g45_isi_device = { |
| 859 | .name = "atmel_isi", |
| 860 | .id = 0, |
| 861 | .dev = { |
| 862 | .dma_mask = &isi_dmamask, |
| 863 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 864 | .platform_data = &isi_data, |
| 865 | }, |
| 866 | .resource = isi_resources, |
| 867 | .num_resources = ARRAY_SIZE(isi_resources), |
| 868 | }; |
| 869 | |
| 870 | static struct clk_lookup isi_mck_lookups[] = { |
| 871 | CLKDEV_CON_DEV_ID("isi_mck", "atmel_isi.0", NULL), |
| 872 | }; |
| 873 | |
| 874 | void __init at91_add_device_isi(struct isi_platform_data *data, |
| 875 | bool use_pck_as_mck) |
| 876 | { |
| 877 | struct clk *pck; |
| 878 | struct clk *parent; |
| 879 | |
| 880 | if (!data) |
| 881 | return; |
| 882 | isi_data = *data; |
| 883 | |
| 884 | at91_set_A_periph(AT91_PIN_PB20, 0); |
| 885 | at91_set_A_periph(AT91_PIN_PB21, 0); |
| 886 | at91_set_A_periph(AT91_PIN_PB22, 0); |
| 887 | at91_set_A_periph(AT91_PIN_PB23, 0); |
| 888 | at91_set_A_periph(AT91_PIN_PB24, 0); |
| 889 | at91_set_A_periph(AT91_PIN_PB25, 0); |
| 890 | at91_set_A_periph(AT91_PIN_PB26, 0); |
| 891 | at91_set_A_periph(AT91_PIN_PB27, 0); |
| 892 | at91_set_A_periph(AT91_PIN_PB28, 0); |
| 893 | at91_set_A_periph(AT91_PIN_PB30, 0); |
| 894 | at91_set_A_periph(AT91_PIN_PB29, 0); |
| 895 | at91_set_B_periph(AT91_PIN_PB8, 0); |
| 896 | at91_set_B_periph(AT91_PIN_PB9, 0); |
| 897 | at91_set_B_periph(AT91_PIN_PB10, 0); |
| 898 | at91_set_B_periph(AT91_PIN_PB11, 0); |
| 899 | |
| 900 | platform_device_register(&at91sam9g45_isi_device); |
| 901 | |
| 902 | if (use_pck_as_mck) { |
| 903 | at91_set_B_periph(AT91_PIN_PB31, 0); |
| 904 | |
| 905 | pck = clk_get(NULL, "pck1"); |
| 906 | parent = clk_get(NULL, "plla"); |
| 907 | |
| 908 | BUG_ON(IS_ERR(pck) || IS_ERR(parent)); |
| 909 | |
| 910 | if (clk_set_parent(pck, parent)) { |
| 911 | pr_err("Failed to set PCK's parent\n"); |
| 912 | } else { |
| 913 | |
| 914 | isi_mck_lookups[0].clk = pck; |
| 915 | clkdev_add_table(isi_mck_lookups, |
| 916 | ARRAY_SIZE(isi_mck_lookups)); |
| 917 | } |
| 918 | |
| 919 | clk_put(pck); |
| 920 | clk_put(parent); |
| 921 | } |
| 922 | } |
| 923 | #else |
| 924 | void __init at91_add_device_isi(struct isi_platform_data *data, |
| 925 | bool use_pck_as_mck) {} |
| 926 | #endif |
| 927 | |
| 928 | |
| 929 | |
| 930 | #if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE) |
| 931 | static u64 lcdc_dmamask = DMA_BIT_MASK(32); |
| 932 | static struct atmel_lcdfb_info lcdc_data; |
| 933 | |
| 934 | static struct resource lcdc_resources[] = { |
| 935 | [0] = { |
| 936 | .start = AT91SAM9G45_LCDC_BASE, |
| 937 | .end = AT91SAM9G45_LCDC_BASE + SZ_4K - 1, |
| 938 | .flags = IORESOURCE_MEM, |
| 939 | }, |
| 940 | [1] = { |
| 941 | .start = AT91SAM9G45_ID_LCDC, |
| 942 | .end = AT91SAM9G45_ID_LCDC, |
| 943 | .flags = IORESOURCE_IRQ, |
| 944 | }, |
| 945 | }; |
| 946 | |
| 947 | static struct platform_device at91_lcdc_device = { |
| 948 | .name = "atmel_lcdfb", |
| 949 | .id = 0, |
| 950 | .dev = { |
| 951 | .dma_mask = &lcdc_dmamask, |
| 952 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 953 | .platform_data = &lcdc_data, |
| 954 | }, |
| 955 | .resource = lcdc_resources, |
| 956 | .num_resources = ARRAY_SIZE(lcdc_resources), |
| 957 | }; |
| 958 | |
| 959 | void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data) |
| 960 | { |
| 961 | if (!data) |
| 962 | return; |
| 963 | |
| 964 | at91_set_A_periph(AT91_PIN_PE0, 0); |
| 965 | |
| 966 | at91_set_A_periph(AT91_PIN_PE2, 0); |
| 967 | at91_set_A_periph(AT91_PIN_PE3, 0); |
| 968 | at91_set_A_periph(AT91_PIN_PE4, 0); |
| 969 | at91_set_A_periph(AT91_PIN_PE5, 0); |
| 970 | at91_set_A_periph(AT91_PIN_PE6, 0); |
| 971 | at91_set_A_periph(AT91_PIN_PE7, 0); |
| 972 | at91_set_A_periph(AT91_PIN_PE8, 0); |
| 973 | at91_set_A_periph(AT91_PIN_PE9, 0); |
| 974 | at91_set_A_periph(AT91_PIN_PE10, 0); |
| 975 | at91_set_A_periph(AT91_PIN_PE11, 0); |
| 976 | at91_set_A_periph(AT91_PIN_PE12, 0); |
| 977 | at91_set_A_periph(AT91_PIN_PE13, 0); |
| 978 | at91_set_A_periph(AT91_PIN_PE14, 0); |
| 979 | at91_set_A_periph(AT91_PIN_PE15, 0); |
| 980 | at91_set_A_periph(AT91_PIN_PE16, 0); |
| 981 | at91_set_A_periph(AT91_PIN_PE17, 0); |
| 982 | at91_set_A_periph(AT91_PIN_PE18, 0); |
| 983 | at91_set_A_periph(AT91_PIN_PE19, 0); |
| 984 | at91_set_A_periph(AT91_PIN_PE20, 0); |
| 985 | at91_set_A_periph(AT91_PIN_PE21, 0); |
| 986 | at91_set_A_periph(AT91_PIN_PE22, 0); |
| 987 | at91_set_A_periph(AT91_PIN_PE23, 0); |
| 988 | at91_set_A_periph(AT91_PIN_PE24, 0); |
| 989 | at91_set_A_periph(AT91_PIN_PE25, 0); |
| 990 | at91_set_A_periph(AT91_PIN_PE26, 0); |
| 991 | at91_set_A_periph(AT91_PIN_PE27, 0); |
| 992 | at91_set_A_periph(AT91_PIN_PE28, 0); |
| 993 | at91_set_A_periph(AT91_PIN_PE29, 0); |
| 994 | at91_set_A_periph(AT91_PIN_PE30, 0); |
| 995 | |
| 996 | lcdc_data = *data; |
| 997 | platform_device_register(&at91_lcdc_device); |
| 998 | } |
| 999 | #else |
| 1000 | void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data) {} |
| 1001 | #endif |
| 1002 | |
| 1003 | |
| 1004 | |
| 1005 | #ifdef CONFIG_ATMEL_TCLIB |
| 1006 | static struct resource tcb0_resources[] = { |
| 1007 | [0] = { |
| 1008 | .start = AT91SAM9G45_BASE_TCB0, |
| 1009 | .end = AT91SAM9G45_BASE_TCB0 + SZ_256 - 1, |
| 1010 | .flags = IORESOURCE_MEM, |
| 1011 | }, |
| 1012 | [1] = { |
| 1013 | .start = AT91SAM9G45_ID_TCB, |
| 1014 | .end = AT91SAM9G45_ID_TCB, |
| 1015 | .flags = IORESOURCE_IRQ, |
| 1016 | }, |
| 1017 | }; |
| 1018 | |
| 1019 | static struct platform_device at91sam9g45_tcb0_device = { |
| 1020 | .name = "atmel_tcb", |
| 1021 | .id = 0, |
| 1022 | .resource = tcb0_resources, |
| 1023 | .num_resources = ARRAY_SIZE(tcb0_resources), |
| 1024 | }; |
| 1025 | |
| 1026 | static struct resource tcb1_resources[] = { |
| 1027 | [0] = { |
| 1028 | .start = AT91SAM9G45_BASE_TCB1, |
| 1029 | .end = AT91SAM9G45_BASE_TCB1 + SZ_256 - 1, |
| 1030 | .flags = IORESOURCE_MEM, |
| 1031 | }, |
| 1032 | [1] = { |
| 1033 | .start = AT91SAM9G45_ID_TCB, |
| 1034 | .end = AT91SAM9G45_ID_TCB, |
| 1035 | .flags = IORESOURCE_IRQ, |
| 1036 | }, |
| 1037 | }; |
| 1038 | |
| 1039 | static struct platform_device at91sam9g45_tcb1_device = { |
| 1040 | .name = "atmel_tcb", |
| 1041 | .id = 1, |
| 1042 | .resource = tcb1_resources, |
| 1043 | .num_resources = ARRAY_SIZE(tcb1_resources), |
| 1044 | }; |
| 1045 | |
| 1046 | #if defined(CONFIG_OF) |
| 1047 | static struct of_device_id tcb_ids[] = { |
| 1048 | { .compatible = "atmel,at91rm9200-tcb" }, |
| 1049 | { } |
| 1050 | }; |
| 1051 | #endif |
| 1052 | |
| 1053 | static void __init at91_add_device_tc(void) |
| 1054 | { |
| 1055 | #if defined(CONFIG_OF) |
| 1056 | struct device_node *np; |
| 1057 | |
| 1058 | np = of_find_matching_node(NULL, tcb_ids); |
| 1059 | if (np) { |
| 1060 | of_node_put(np); |
| 1061 | return; |
| 1062 | } |
| 1063 | #endif |
| 1064 | |
| 1065 | platform_device_register(&at91sam9g45_tcb0_device); |
| 1066 | platform_device_register(&at91sam9g45_tcb1_device); |
| 1067 | } |
| 1068 | #else |
| 1069 | static void __init at91_add_device_tc(void) { } |
| 1070 | #endif |
| 1071 | |
| 1072 | |
| 1073 | |
| 1074 | #if defined(CONFIG_RTC_DRV_AT91RM9200) || defined(CONFIG_RTC_DRV_AT91RM9200_MODULE) |
| 1075 | static struct resource rtc_resources[] = { |
| 1076 | [0] = { |
| 1077 | .start = AT91SAM9G45_BASE_RTC, |
| 1078 | .end = AT91SAM9G45_BASE_RTC + SZ_256 - 1, |
| 1079 | .flags = IORESOURCE_MEM, |
| 1080 | }, |
| 1081 | [1] = { |
| 1082 | .start = AT91_ID_SYS, |
| 1083 | .end = AT91_ID_SYS, |
| 1084 | .flags = IORESOURCE_IRQ, |
| 1085 | }, |
| 1086 | }; |
| 1087 | |
| 1088 | static struct platform_device at91sam9g45_rtc_device = { |
| 1089 | .name = "at91_rtc", |
| 1090 | .id = -1, |
| 1091 | .resource = rtc_resources, |
| 1092 | .num_resources = ARRAY_SIZE(rtc_resources), |
| 1093 | }; |
| 1094 | |
| 1095 | static void __init at91_add_device_rtc(void) |
| 1096 | { |
| 1097 | platform_device_register(&at91sam9g45_rtc_device); |
| 1098 | } |
| 1099 | #else |
| 1100 | static void __init at91_add_device_rtc(void) {} |
| 1101 | #endif |
| 1102 | |
| 1103 | |
| 1104 | |
| 1105 | #if defined(CONFIG_TOUCHSCREEN_ATMEL_TSADCC) || defined(CONFIG_TOUCHSCREEN_ATMEL_TSADCC_MODULE) |
| 1106 | static u64 tsadcc_dmamask = DMA_BIT_MASK(32); |
| 1107 | static struct at91_tsadcc_data tsadcc_data; |
| 1108 | |
| 1109 | static struct resource tsadcc_resources[] = { |
| 1110 | [0] = { |
| 1111 | .start = AT91SAM9G45_BASE_TSC, |
| 1112 | .end = AT91SAM9G45_BASE_TSC + SZ_16K - 1, |
| 1113 | .flags = IORESOURCE_MEM, |
| 1114 | }, |
| 1115 | [1] = { |
| 1116 | .start = AT91SAM9G45_ID_TSC, |
| 1117 | .end = AT91SAM9G45_ID_TSC, |
| 1118 | .flags = IORESOURCE_IRQ, |
| 1119 | } |
| 1120 | }; |
| 1121 | |
| 1122 | static struct platform_device at91sam9g45_tsadcc_device = { |
| 1123 | .name = "atmel_tsadcc", |
| 1124 | .id = -1, |
| 1125 | .dev = { |
| 1126 | .dma_mask = &tsadcc_dmamask, |
| 1127 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 1128 | .platform_data = &tsadcc_data, |
| 1129 | }, |
| 1130 | .resource = tsadcc_resources, |
| 1131 | .num_resources = ARRAY_SIZE(tsadcc_resources), |
| 1132 | }; |
| 1133 | |
| 1134 | void __init at91_add_device_tsadcc(struct at91_tsadcc_data *data) |
| 1135 | { |
| 1136 | if (!data) |
| 1137 | return; |
| 1138 | |
| 1139 | at91_set_gpio_input(AT91_PIN_PD20, 0); |
| 1140 | at91_set_gpio_input(AT91_PIN_PD21, 0); |
| 1141 | at91_set_gpio_input(AT91_PIN_PD22, 0); |
| 1142 | at91_set_gpio_input(AT91_PIN_PD23, 0); |
| 1143 | |
| 1144 | tsadcc_data = *data; |
| 1145 | platform_device_register(&at91sam9g45_tsadcc_device); |
| 1146 | } |
| 1147 | #else |
| 1148 | void __init at91_add_device_tsadcc(struct at91_tsadcc_data *data) {} |
| 1149 | #endif |
| 1150 | |
| 1151 | |
| 1152 | |
| 1153 | static struct resource rtt_resources[] = { |
| 1154 | { |
| 1155 | .start = AT91SAM9G45_BASE_RTT, |
| 1156 | .end = AT91SAM9G45_BASE_RTT + SZ_16 - 1, |
| 1157 | .flags = IORESOURCE_MEM, |
| 1158 | }, { |
| 1159 | .flags = IORESOURCE_MEM, |
| 1160 | } |
| 1161 | }; |
| 1162 | |
| 1163 | static struct platform_device at91sam9g45_rtt_device = { |
| 1164 | .name = "at91_rtt", |
| 1165 | .id = 0, |
| 1166 | .resource = rtt_resources, |
| 1167 | }; |
| 1168 | |
| 1169 | #if IS_ENABLED(CONFIG_RTC_DRV_AT91SAM9) |
| 1170 | static void __init at91_add_device_rtt_rtc(void) |
| 1171 | { |
| 1172 | at91sam9g45_rtt_device.name = "rtc-at91sam9"; |
| 1173 | at91sam9g45_rtt_device.num_resources = 2; |
| 1174 | rtt_resources[1].start = AT91SAM9G45_BASE_GPBR + |
| 1175 | 4 * CONFIG_RTC_DRV_AT91SAM9_GPBR; |
| 1176 | rtt_resources[1].end = rtt_resources[1].start + 3; |
| 1177 | } |
| 1178 | #else |
| 1179 | static void __init at91_add_device_rtt_rtc(void) |
| 1180 | { |
| 1181 | |
| 1182 | at91sam9g45_rtt_device.num_resources = 1; |
| 1183 | } |
| 1184 | #endif |
| 1185 | |
| 1186 | static void __init at91_add_device_rtt(void) |
| 1187 | { |
| 1188 | at91_add_device_rtt_rtc(); |
| 1189 | platform_device_register(&at91sam9g45_rtt_device); |
| 1190 | } |
| 1191 | |
| 1192 | |
| 1193 | |
| 1194 | #if defined(CONFIG_HW_RANDOM_ATMEL) || defined(CONFIG_HW_RANDOM_ATMEL_MODULE) |
| 1195 | static struct resource trng_resources[] = { |
| 1196 | { |
| 1197 | .start = AT91SAM9G45_BASE_TRNG, |
| 1198 | .end = AT91SAM9G45_BASE_TRNG + SZ_16K - 1, |
| 1199 | .flags = IORESOURCE_MEM, |
| 1200 | }, |
| 1201 | }; |
| 1202 | |
| 1203 | static struct platform_device at91sam9g45_trng_device = { |
| 1204 | .name = "atmel-trng", |
| 1205 | .id = -1, |
| 1206 | .resource = trng_resources, |
| 1207 | .num_resources = ARRAY_SIZE(trng_resources), |
| 1208 | }; |
| 1209 | |
| 1210 | static void __init at91_add_device_trng(void) |
| 1211 | { |
| 1212 | platform_device_register(&at91sam9g45_trng_device); |
| 1213 | } |
| 1214 | #else |
| 1215 | static void __init at91_add_device_trng(void) {} |
| 1216 | #endif |
| 1217 | |
| 1218 | |
| 1219 | #if defined(CONFIG_AT91SAM9X_WATCHDOG) || defined(CONFIG_AT91SAM9X_WATCHDOG_MODULE) |
| 1220 | static struct resource wdt_resources[] = { |
| 1221 | { |
| 1222 | .start = AT91SAM9G45_BASE_WDT, |
| 1223 | .end = AT91SAM9G45_BASE_WDT + SZ_16 - 1, |
| 1224 | .flags = IORESOURCE_MEM, |
| 1225 | } |
| 1226 | }; |
| 1227 | |
| 1228 | static struct platform_device at91sam9g45_wdt_device = { |
| 1229 | .name = "at91_wdt", |
| 1230 | .id = -1, |
| 1231 | .resource = wdt_resources, |
| 1232 | .num_resources = ARRAY_SIZE(wdt_resources), |
| 1233 | }; |
| 1234 | |
| 1235 | static void __init at91_add_device_watchdog(void) |
| 1236 | { |
| 1237 | platform_device_register(&at91sam9g45_wdt_device); |
| 1238 | } |
| 1239 | #else |
| 1240 | static void __init at91_add_device_watchdog(void) {} |
| 1241 | #endif |
| 1242 | |
| 1243 | |
| 1244 | |
| 1245 | #if defined(CONFIG_ATMEL_PWM) || defined(CONFIG_ATMEL_PWM_MODULE) |
| 1246 | static u32 pwm_mask; |
| 1247 | |
| 1248 | static struct resource pwm_resources[] = { |
| 1249 | [0] = { |
| 1250 | .start = AT91SAM9G45_BASE_PWMC, |
| 1251 | .end = AT91SAM9G45_BASE_PWMC + SZ_16K - 1, |
| 1252 | .flags = IORESOURCE_MEM, |
| 1253 | }, |
| 1254 | [1] = { |
| 1255 | .start = AT91SAM9G45_ID_PWMC, |
| 1256 | .end = AT91SAM9G45_ID_PWMC, |
| 1257 | .flags = IORESOURCE_IRQ, |
| 1258 | }, |
| 1259 | }; |
| 1260 | |
| 1261 | static struct platform_device at91sam9g45_pwm0_device = { |
| 1262 | .name = "atmel_pwm", |
| 1263 | .id = -1, |
| 1264 | .dev = { |
| 1265 | .platform_data = &pwm_mask, |
| 1266 | }, |
| 1267 | .resource = pwm_resources, |
| 1268 | .num_resources = ARRAY_SIZE(pwm_resources), |
| 1269 | }; |
| 1270 | |
| 1271 | void __init at91_add_device_pwm(u32 mask) |
| 1272 | { |
| 1273 | if (mask & (1 << AT91_PWM0)) |
| 1274 | at91_set_B_periph(AT91_PIN_PD24, 1); |
| 1275 | |
| 1276 | if (mask & (1 << AT91_PWM1)) |
| 1277 | at91_set_B_periph(AT91_PIN_PD31, 1); |
| 1278 | |
| 1279 | if (mask & (1 << AT91_PWM2)) |
| 1280 | at91_set_B_periph(AT91_PIN_PD26, 1); |
| 1281 | |
| 1282 | if (mask & (1 << AT91_PWM3)) |
| 1283 | at91_set_B_periph(AT91_PIN_PD0, 1); |
| 1284 | |
| 1285 | pwm_mask = mask; |
| 1286 | |
| 1287 | platform_device_register(&at91sam9g45_pwm0_device); |
| 1288 | } |
| 1289 | #else |
| 1290 | void __init at91_add_device_pwm(u32 mask) {} |
| 1291 | #endif |
| 1292 | |
| 1293 | |
| 1294 | |
| 1295 | #if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE) |
| 1296 | static u64 ssc0_dmamask = DMA_BIT_MASK(32); |
| 1297 | |
| 1298 | static struct resource ssc0_resources[] = { |
| 1299 | [0] = { |
| 1300 | .start = AT91SAM9G45_BASE_SSC0, |
| 1301 | .end = AT91SAM9G45_BASE_SSC0 + SZ_16K - 1, |
| 1302 | .flags = IORESOURCE_MEM, |
| 1303 | }, |
| 1304 | [1] = { |
| 1305 | .start = AT91SAM9G45_ID_SSC0, |
| 1306 | .end = AT91SAM9G45_ID_SSC0, |
| 1307 | .flags = IORESOURCE_IRQ, |
| 1308 | }, |
| 1309 | }; |
| 1310 | |
| 1311 | static struct platform_device at91sam9g45_ssc0_device = { |
| 1312 | .name = "ssc", |
| 1313 | .id = 0, |
| 1314 | .dev = { |
| 1315 | .dma_mask = &ssc0_dmamask, |
| 1316 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 1317 | }, |
| 1318 | .resource = ssc0_resources, |
| 1319 | .num_resources = ARRAY_SIZE(ssc0_resources), |
| 1320 | }; |
| 1321 | |
| 1322 | static inline void configure_ssc0_pins(unsigned pins) |
| 1323 | { |
| 1324 | if (pins & ATMEL_SSC_TF) |
| 1325 | at91_set_A_periph(AT91_PIN_PD1, 1); |
| 1326 | if (pins & ATMEL_SSC_TK) |
| 1327 | at91_set_A_periph(AT91_PIN_PD0, 1); |
| 1328 | if (pins & ATMEL_SSC_TD) |
| 1329 | at91_set_A_periph(AT91_PIN_PD2, 1); |
| 1330 | if (pins & ATMEL_SSC_RD) |
| 1331 | at91_set_A_periph(AT91_PIN_PD3, 1); |
| 1332 | if (pins & ATMEL_SSC_RK) |
| 1333 | at91_set_A_periph(AT91_PIN_PD4, 1); |
| 1334 | if (pins & ATMEL_SSC_RF) |
| 1335 | at91_set_A_periph(AT91_PIN_PD5, 1); |
| 1336 | } |
| 1337 | |
| 1338 | static u64 ssc1_dmamask = DMA_BIT_MASK(32); |
| 1339 | |
| 1340 | static struct resource ssc1_resources[] = { |
| 1341 | [0] = { |
| 1342 | .start = AT91SAM9G45_BASE_SSC1, |
| 1343 | .end = AT91SAM9G45_BASE_SSC1 + SZ_16K - 1, |
| 1344 | .flags = IORESOURCE_MEM, |
| 1345 | }, |
| 1346 | [1] = { |
| 1347 | .start = AT91SAM9G45_ID_SSC1, |
| 1348 | .end = AT91SAM9G45_ID_SSC1, |
| 1349 | .flags = IORESOURCE_IRQ, |
| 1350 | }, |
| 1351 | }; |
| 1352 | |
| 1353 | static struct platform_device at91sam9g45_ssc1_device = { |
| 1354 | .name = "ssc", |
| 1355 | .id = 1, |
| 1356 | .dev = { |
| 1357 | .dma_mask = &ssc1_dmamask, |
| 1358 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 1359 | }, |
| 1360 | .resource = ssc1_resources, |
| 1361 | .num_resources = ARRAY_SIZE(ssc1_resources), |
| 1362 | }; |
| 1363 | |
| 1364 | static inline void configure_ssc1_pins(unsigned pins) |
| 1365 | { |
| 1366 | if (pins & ATMEL_SSC_TF) |
| 1367 | at91_set_A_periph(AT91_PIN_PD14, 1); |
| 1368 | if (pins & ATMEL_SSC_TK) |
| 1369 | at91_set_A_periph(AT91_PIN_PD12, 1); |
| 1370 | if (pins & ATMEL_SSC_TD) |
| 1371 | at91_set_A_periph(AT91_PIN_PD10, 1); |
| 1372 | if (pins & ATMEL_SSC_RD) |
| 1373 | at91_set_A_periph(AT91_PIN_PD11, 1); |
| 1374 | if (pins & ATMEL_SSC_RK) |
| 1375 | at91_set_A_periph(AT91_PIN_PD13, 1); |
| 1376 | if (pins & ATMEL_SSC_RF) |
| 1377 | at91_set_A_periph(AT91_PIN_PD15, 1); |
| 1378 | } |
| 1379 | |
| 1380 | void __init at91_add_device_ssc(unsigned id, unsigned pins) |
| 1381 | { |
| 1382 | struct platform_device *pdev; |
| 1383 | |
| 1384 | switch (id) { |
| 1385 | case AT91SAM9G45_ID_SSC0: |
| 1386 | pdev = &at91sam9g45_ssc0_device; |
| 1387 | configure_ssc0_pins(pins); |
| 1388 | break; |
| 1389 | case AT91SAM9G45_ID_SSC1: |
| 1390 | pdev = &at91sam9g45_ssc1_device; |
| 1391 | configure_ssc1_pins(pins); |
| 1392 | break; |
| 1393 | default: |
| 1394 | return; |
| 1395 | } |
| 1396 | |
| 1397 | platform_device_register(pdev); |
| 1398 | } |
| 1399 | |
| 1400 | #else |
| 1401 | void __init at91_add_device_ssc(unsigned id, unsigned pins) {} |
| 1402 | #endif |
| 1403 | |
| 1404 | |
| 1405 | |
| 1406 | #if defined(CONFIG_SERIAL_ATMEL) |
| 1407 | static struct resource dbgu_resources[] = { |
| 1408 | [0] = { |
| 1409 | .start = AT91SAM9G45_BASE_DBGU, |
| 1410 | .end = AT91SAM9G45_BASE_DBGU + SZ_512 - 1, |
| 1411 | .flags = IORESOURCE_MEM, |
| 1412 | }, |
| 1413 | [1] = { |
| 1414 | .start = AT91_ID_SYS, |
| 1415 | .end = AT91_ID_SYS, |
| 1416 | .flags = IORESOURCE_IRQ, |
| 1417 | }, |
| 1418 | }; |
| 1419 | |
| 1420 | static struct atmel_uart_data dbgu_data = { |
| 1421 | .use_dma_tx = 0, |
| 1422 | .use_dma_rx = 0, |
| 1423 | }; |
| 1424 | |
| 1425 | static u64 dbgu_dmamask = DMA_BIT_MASK(32); |
| 1426 | |
| 1427 | static struct platform_device at91sam9g45_dbgu_device = { |
| 1428 | .name = "atmel_usart", |
| 1429 | .id = 0, |
| 1430 | .dev = { |
| 1431 | .dma_mask = &dbgu_dmamask, |
| 1432 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 1433 | .platform_data = &dbgu_data, |
| 1434 | }, |
| 1435 | .resource = dbgu_resources, |
| 1436 | .num_resources = ARRAY_SIZE(dbgu_resources), |
| 1437 | }; |
| 1438 | |
| 1439 | static inline void configure_dbgu_pins(void) |
| 1440 | { |
| 1441 | at91_set_A_periph(AT91_PIN_PB12, 0); |
| 1442 | at91_set_A_periph(AT91_PIN_PB13, 1); |
| 1443 | } |
| 1444 | |
| 1445 | static struct resource uart0_resources[] = { |
| 1446 | [0] = { |
| 1447 | .start = AT91SAM9G45_BASE_US0, |
| 1448 | .end = AT91SAM9G45_BASE_US0 + SZ_16K - 1, |
| 1449 | .flags = IORESOURCE_MEM, |
| 1450 | }, |
| 1451 | [1] = { |
| 1452 | .start = AT91SAM9G45_ID_US0, |
| 1453 | .end = AT91SAM9G45_ID_US0, |
| 1454 | .flags = IORESOURCE_IRQ, |
| 1455 | }, |
| 1456 | }; |
| 1457 | |
| 1458 | static struct atmel_uart_data uart0_data = { |
| 1459 | .use_dma_tx = 1, |
| 1460 | .use_dma_rx = 1, |
| 1461 | }; |
| 1462 | |
| 1463 | static u64 uart0_dmamask = DMA_BIT_MASK(32); |
| 1464 | |
| 1465 | static struct platform_device at91sam9g45_uart0_device = { |
| 1466 | .name = "atmel_usart", |
| 1467 | .id = 1, |
| 1468 | .dev = { |
| 1469 | .dma_mask = &uart0_dmamask, |
| 1470 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 1471 | .platform_data = &uart0_data, |
| 1472 | }, |
| 1473 | .resource = uart0_resources, |
| 1474 | .num_resources = ARRAY_SIZE(uart0_resources), |
| 1475 | }; |
| 1476 | |
| 1477 | static inline void configure_usart0_pins(unsigned pins) |
| 1478 | { |
| 1479 | at91_set_A_periph(AT91_PIN_PB19, 1); |
| 1480 | at91_set_A_periph(AT91_PIN_PB18, 0); |
| 1481 | |
| 1482 | if (pins & ATMEL_UART_RTS) |
| 1483 | at91_set_B_periph(AT91_PIN_PB17, 0); |
| 1484 | if (pins & ATMEL_UART_CTS) |
| 1485 | at91_set_B_periph(AT91_PIN_PB15, 0); |
| 1486 | } |
| 1487 | |
| 1488 | static struct resource uart1_resources[] = { |
| 1489 | [0] = { |
| 1490 | .start = AT91SAM9G45_BASE_US1, |
| 1491 | .end = AT91SAM9G45_BASE_US1 + SZ_16K - 1, |
| 1492 | .flags = IORESOURCE_MEM, |
| 1493 | }, |
| 1494 | [1] = { |
| 1495 | .start = AT91SAM9G45_ID_US1, |
| 1496 | .end = AT91SAM9G45_ID_US1, |
| 1497 | .flags = IORESOURCE_IRQ, |
| 1498 | }, |
| 1499 | }; |
| 1500 | |
| 1501 | static struct atmel_uart_data uart1_data = { |
| 1502 | .use_dma_tx = 1, |
| 1503 | .use_dma_rx = 1, |
| 1504 | }; |
| 1505 | |
| 1506 | static u64 uart1_dmamask = DMA_BIT_MASK(32); |
| 1507 | |
| 1508 | static struct platform_device at91sam9g45_uart1_device = { |
| 1509 | .name = "atmel_usart", |
| 1510 | .id = 2, |
| 1511 | .dev = { |
| 1512 | .dma_mask = &uart1_dmamask, |
| 1513 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 1514 | .platform_data = &uart1_data, |
| 1515 | }, |
| 1516 | .resource = uart1_resources, |
| 1517 | .num_resources = ARRAY_SIZE(uart1_resources), |
| 1518 | }; |
| 1519 | |
| 1520 | static inline void configure_usart1_pins(unsigned pins) |
| 1521 | { |
| 1522 | at91_set_A_periph(AT91_PIN_PB4, 1); |
| 1523 | at91_set_A_periph(AT91_PIN_PB5, 0); |
| 1524 | |
| 1525 | if (pins & ATMEL_UART_RTS) |
| 1526 | at91_set_A_periph(AT91_PIN_PD16, 0); |
| 1527 | if (pins & ATMEL_UART_CTS) |
| 1528 | at91_set_A_periph(AT91_PIN_PD17, 0); |
| 1529 | } |
| 1530 | |
| 1531 | static struct resource uart2_resources[] = { |
| 1532 | [0] = { |
| 1533 | .start = AT91SAM9G45_BASE_US2, |
| 1534 | .end = AT91SAM9G45_BASE_US2 + SZ_16K - 1, |
| 1535 | .flags = IORESOURCE_MEM, |
| 1536 | }, |
| 1537 | [1] = { |
| 1538 | .start = AT91SAM9G45_ID_US2, |
| 1539 | .end = AT91SAM9G45_ID_US2, |
| 1540 | .flags = IORESOURCE_IRQ, |
| 1541 | }, |
| 1542 | }; |
| 1543 | |
| 1544 | static struct atmel_uart_data uart2_data = { |
| 1545 | .use_dma_tx = 1, |
| 1546 | .use_dma_rx = 1, |
| 1547 | }; |
| 1548 | |
| 1549 | static u64 uart2_dmamask = DMA_BIT_MASK(32); |
| 1550 | |
| 1551 | static struct platform_device at91sam9g45_uart2_device = { |
| 1552 | .name = "atmel_usart", |
| 1553 | .id = 3, |
| 1554 | .dev = { |
| 1555 | .dma_mask = &uart2_dmamask, |
| 1556 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 1557 | .platform_data = &uart2_data, |
| 1558 | }, |
| 1559 | .resource = uart2_resources, |
| 1560 | .num_resources = ARRAY_SIZE(uart2_resources), |
| 1561 | }; |
| 1562 | |
| 1563 | static inline void configure_usart2_pins(unsigned pins) |
| 1564 | { |
| 1565 | at91_set_A_periph(AT91_PIN_PB6, 1); |
| 1566 | at91_set_A_periph(AT91_PIN_PB7, 0); |
| 1567 | |
| 1568 | if (pins & ATMEL_UART_RTS) |
| 1569 | at91_set_B_periph(AT91_PIN_PC9, 0); |
| 1570 | if (pins & ATMEL_UART_CTS) |
| 1571 | at91_set_B_periph(AT91_PIN_PC11, 0); |
| 1572 | } |
| 1573 | |
| 1574 | static struct resource uart3_resources[] = { |
| 1575 | [0] = { |
| 1576 | .start = AT91SAM9G45_BASE_US3, |
| 1577 | .end = AT91SAM9G45_BASE_US3 + SZ_16K - 1, |
| 1578 | .flags = IORESOURCE_MEM, |
| 1579 | }, |
| 1580 | [1] = { |
| 1581 | .start = AT91SAM9G45_ID_US3, |
| 1582 | .end = AT91SAM9G45_ID_US3, |
| 1583 | .flags = IORESOURCE_IRQ, |
| 1584 | }, |
| 1585 | }; |
| 1586 | |
| 1587 | static struct atmel_uart_data uart3_data = { |
| 1588 | .use_dma_tx = 1, |
| 1589 | .use_dma_rx = 1, |
| 1590 | }; |
| 1591 | |
| 1592 | static u64 uart3_dmamask = DMA_BIT_MASK(32); |
| 1593 | |
| 1594 | static struct platform_device at91sam9g45_uart3_device = { |
| 1595 | .name = "atmel_usart", |
| 1596 | .id = 4, |
| 1597 | .dev = { |
| 1598 | .dma_mask = &uart3_dmamask, |
| 1599 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 1600 | .platform_data = &uart3_data, |
| 1601 | }, |
| 1602 | .resource = uart3_resources, |
| 1603 | .num_resources = ARRAY_SIZE(uart3_resources), |
| 1604 | }; |
| 1605 | |
| 1606 | static inline void configure_usart3_pins(unsigned pins) |
| 1607 | { |
| 1608 | at91_set_A_periph(AT91_PIN_PB8, 1); |
| 1609 | at91_set_A_periph(AT91_PIN_PB9, 0); |
| 1610 | |
| 1611 | if (pins & ATMEL_UART_RTS) |
| 1612 | at91_set_B_periph(AT91_PIN_PA23, 0); |
| 1613 | if (pins & ATMEL_UART_CTS) |
| 1614 | at91_set_B_periph(AT91_PIN_PA24, 0); |
| 1615 | } |
| 1616 | |
| 1617 | static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; |
| 1618 | |
| 1619 | void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) |
| 1620 | { |
| 1621 | struct platform_device *pdev; |
| 1622 | struct atmel_uart_data *pdata; |
| 1623 | |
| 1624 | switch (id) { |
| 1625 | case 0: |
| 1626 | pdev = &at91sam9g45_dbgu_device; |
| 1627 | configure_dbgu_pins(); |
| 1628 | break; |
| 1629 | case AT91SAM9G45_ID_US0: |
| 1630 | pdev = &at91sam9g45_uart0_device; |
| 1631 | configure_usart0_pins(pins); |
| 1632 | break; |
| 1633 | case AT91SAM9G45_ID_US1: |
| 1634 | pdev = &at91sam9g45_uart1_device; |
| 1635 | configure_usart1_pins(pins); |
| 1636 | break; |
| 1637 | case AT91SAM9G45_ID_US2: |
| 1638 | pdev = &at91sam9g45_uart2_device; |
| 1639 | configure_usart2_pins(pins); |
| 1640 | break; |
| 1641 | case AT91SAM9G45_ID_US3: |
| 1642 | pdev = &at91sam9g45_uart3_device; |
| 1643 | configure_usart3_pins(pins); |
| 1644 | break; |
| 1645 | default: |
| 1646 | return; |
| 1647 | } |
| 1648 | pdata = pdev->dev.platform_data; |
| 1649 | pdata->num = portnr; |
| 1650 | |
| 1651 | if (portnr < ATMEL_MAX_UART) |
| 1652 | at91_uarts[portnr] = pdev; |
| 1653 | } |
| 1654 | |
| 1655 | void __init at91_set_serial_console(unsigned portnr) |
| 1656 | { |
| 1657 | if (portnr < ATMEL_MAX_UART) { |
| 1658 | atmel_default_console_device = at91_uarts[portnr]; |
| 1659 | at91sam9g45_set_console_clock(at91_uarts[portnr]->id); |
| 1660 | } |
| 1661 | } |
| 1662 | |
| 1663 | void __init at91_add_device_serial(void) |
| 1664 | { |
| 1665 | int i; |
| 1666 | |
| 1667 | for (i = 0; i < ATMEL_MAX_UART; i++) { |
| 1668 | if (at91_uarts[i]) |
| 1669 | platform_device_register(at91_uarts[i]); |
| 1670 | } |
| 1671 | |
| 1672 | if (!atmel_default_console_device) |
| 1673 | printk(KERN_INFO "AT91: No default serial console defined.\n"); |
| 1674 | } |
| 1675 | #else |
| 1676 | void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {} |
| 1677 | void __init at91_set_serial_console(unsigned portnr) {} |
| 1678 | void __init at91_add_device_serial(void) {} |
| 1679 | #endif |
| 1680 | |
| 1681 | |
| 1682 | static int __init at91_add_standard_devices(void) |
| 1683 | { |
| 1684 | at91_add_device_hdmac(); |
| 1685 | at91_add_device_rtc(); |
| 1686 | at91_add_device_rtt(); |
| 1687 | at91_add_device_trng(); |
| 1688 | at91_add_device_watchdog(); |
| 1689 | at91_add_device_tc(); |
| 1690 | return 0; |
| 1691 | } |
| 1692 | |
| 1693 | arch_initcall(at91_add_standard_devices); |