Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 1 | /* |
Andrew Victor | 9d04126 | 2007-02-05 11:42:07 +0100 | [diff] [blame] | 2 | * arch/arm/mach-at91/at91sam9260_devices.c |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2006 Atmel |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | */ |
| 12 | #include <asm/mach/arch.h> |
| 13 | #include <asm/mach/map.h> |
| 14 | |
Andrew Victor | c6686ff | 2008-01-23 09:13:53 +0100 | [diff] [blame] | 15 | #include <linux/dma-mapping.h> |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 16 | #include <linux/platform_device.h> |
Andrew Victor | f230d3f | 2007-11-19 13:47:20 +0100 | [diff] [blame] | 17 | #include <linux/i2c-gpio.h> |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 18 | |
| 19 | #include <asm/arch/board.h> |
| 20 | #include <asm/arch/gpio.h> |
| 21 | #include <asm/arch/at91sam9260.h> |
Andrew Victor | 8df1292 | 2006-12-08 11:30:29 +0100 | [diff] [blame] | 22 | #include <asm/arch/at91sam9260_matrix.h> |
Andrew Victor | b78eabd | 2008-04-02 21:38:40 +0100 | [diff] [blame] | 23 | #include <asm/arch/at91sam9_smc.h> |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 24 | |
| 25 | #include "generic.h" |
| 26 | |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 27 | |
| 28 | /* -------------------------------------------------------------------- |
| 29 | * USB Host |
| 30 | * -------------------------------------------------------------------- */ |
| 31 | |
| 32 | #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE) |
Andrew Victor | c6686ff | 2008-01-23 09:13:53 +0100 | [diff] [blame] | 33 | static u64 ohci_dmamask = DMA_BIT_MASK(32); |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 34 | static struct at91_usbh_data usbh_data; |
| 35 | |
| 36 | static struct resource usbh_resources[] = { |
| 37 | [0] = { |
| 38 | .start = AT91SAM9260_UHP_BASE, |
| 39 | .end = AT91SAM9260_UHP_BASE + SZ_1M - 1, |
| 40 | .flags = IORESOURCE_MEM, |
| 41 | }, |
| 42 | [1] = { |
| 43 | .start = AT91SAM9260_ID_UHP, |
| 44 | .end = AT91SAM9260_ID_UHP, |
| 45 | .flags = IORESOURCE_IRQ, |
| 46 | }, |
| 47 | }; |
| 48 | |
| 49 | static struct platform_device at91_usbh_device = { |
| 50 | .name = "at91_ohci", |
| 51 | .id = -1, |
| 52 | .dev = { |
| 53 | .dma_mask = &ohci_dmamask, |
Andrew Victor | c6686ff | 2008-01-23 09:13:53 +0100 | [diff] [blame] | 54 | .coherent_dma_mask = DMA_BIT_MASK(32), |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 55 | .platform_data = &usbh_data, |
| 56 | }, |
| 57 | .resource = usbh_resources, |
| 58 | .num_resources = ARRAY_SIZE(usbh_resources), |
| 59 | }; |
| 60 | |
| 61 | void __init at91_add_device_usbh(struct at91_usbh_data *data) |
| 62 | { |
| 63 | if (!data) |
| 64 | return; |
| 65 | |
| 66 | usbh_data = *data; |
| 67 | platform_device_register(&at91_usbh_device); |
| 68 | } |
| 69 | #else |
| 70 | void __init at91_add_device_usbh(struct at91_usbh_data *data) {} |
| 71 | #endif |
| 72 | |
| 73 | |
| 74 | /* -------------------------------------------------------------------- |
| 75 | * USB Device (Gadget) |
| 76 | * -------------------------------------------------------------------- */ |
| 77 | |
| 78 | #ifdef CONFIG_USB_GADGET_AT91 |
| 79 | static struct at91_udc_data udc_data; |
| 80 | |
| 81 | static struct resource udc_resources[] = { |
| 82 | [0] = { |
| 83 | .start = AT91SAM9260_BASE_UDP, |
| 84 | .end = AT91SAM9260_BASE_UDP + SZ_16K - 1, |
| 85 | .flags = IORESOURCE_MEM, |
| 86 | }, |
| 87 | [1] = { |
| 88 | .start = AT91SAM9260_ID_UDP, |
| 89 | .end = AT91SAM9260_ID_UDP, |
| 90 | .flags = IORESOURCE_IRQ, |
| 91 | }, |
| 92 | }; |
| 93 | |
| 94 | static struct platform_device at91_udc_device = { |
| 95 | .name = "at91_udc", |
| 96 | .id = -1, |
| 97 | .dev = { |
| 98 | .platform_data = &udc_data, |
| 99 | }, |
| 100 | .resource = udc_resources, |
| 101 | .num_resources = ARRAY_SIZE(udc_resources), |
| 102 | }; |
| 103 | |
| 104 | void __init at91_add_device_udc(struct at91_udc_data *data) |
| 105 | { |
| 106 | if (!data) |
| 107 | return; |
| 108 | |
| 109 | if (data->vbus_pin) { |
| 110 | at91_set_gpio_input(data->vbus_pin, 0); |
| 111 | at91_set_deglitch(data->vbus_pin, 1); |
| 112 | } |
| 113 | |
| 114 | /* Pullup pin is handled internally by USB device peripheral */ |
| 115 | |
| 116 | udc_data = *data; |
| 117 | platform_device_register(&at91_udc_device); |
| 118 | } |
| 119 | #else |
| 120 | void __init at91_add_device_udc(struct at91_udc_data *data) {} |
| 121 | #endif |
| 122 | |
| 123 | |
| 124 | /* -------------------------------------------------------------------- |
| 125 | * Ethernet |
| 126 | * -------------------------------------------------------------------- */ |
| 127 | |
| 128 | #if defined(CONFIG_MACB) || defined(CONFIG_MACB_MODULE) |
Andrew Victor | c6686ff | 2008-01-23 09:13:53 +0100 | [diff] [blame] | 129 | static u64 eth_dmamask = DMA_BIT_MASK(32); |
Andrew Victor | a93d48c | 2007-02-01 09:22:23 +0100 | [diff] [blame] | 130 | static struct at91_eth_data eth_data; |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 131 | |
| 132 | static struct resource eth_resources[] = { |
| 133 | [0] = { |
| 134 | .start = AT91SAM9260_BASE_EMAC, |
| 135 | .end = AT91SAM9260_BASE_EMAC + SZ_16K - 1, |
| 136 | .flags = IORESOURCE_MEM, |
| 137 | }, |
| 138 | [1] = { |
| 139 | .start = AT91SAM9260_ID_EMAC, |
| 140 | .end = AT91SAM9260_ID_EMAC, |
| 141 | .flags = IORESOURCE_IRQ, |
| 142 | }, |
| 143 | }; |
| 144 | |
| 145 | static struct platform_device at91sam9260_eth_device = { |
| 146 | .name = "macb", |
| 147 | .id = -1, |
| 148 | .dev = { |
| 149 | .dma_mask = ð_dmamask, |
Andrew Victor | c6686ff | 2008-01-23 09:13:53 +0100 | [diff] [blame] | 150 | .coherent_dma_mask = DMA_BIT_MASK(32), |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 151 | .platform_data = ð_data, |
| 152 | }, |
| 153 | .resource = eth_resources, |
| 154 | .num_resources = ARRAY_SIZE(eth_resources), |
| 155 | }; |
| 156 | |
Andrew Victor | a93d48c | 2007-02-01 09:22:23 +0100 | [diff] [blame] | 157 | void __init at91_add_device_eth(struct at91_eth_data *data) |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 158 | { |
| 159 | if (!data) |
| 160 | return; |
| 161 | |
| 162 | if (data->phy_irq_pin) { |
| 163 | at91_set_gpio_input(data->phy_irq_pin, 0); |
| 164 | at91_set_deglitch(data->phy_irq_pin, 1); |
| 165 | } |
| 166 | |
| 167 | /* Pins used for MII and RMII */ |
| 168 | at91_set_A_periph(AT91_PIN_PA19, 0); /* ETXCK_EREFCK */ |
| 169 | at91_set_A_periph(AT91_PIN_PA17, 0); /* ERXDV */ |
| 170 | at91_set_A_periph(AT91_PIN_PA14, 0); /* ERX0 */ |
| 171 | at91_set_A_periph(AT91_PIN_PA15, 0); /* ERX1 */ |
| 172 | at91_set_A_periph(AT91_PIN_PA18, 0); /* ERXER */ |
| 173 | at91_set_A_periph(AT91_PIN_PA16, 0); /* ETXEN */ |
| 174 | at91_set_A_periph(AT91_PIN_PA12, 0); /* ETX0 */ |
| 175 | at91_set_A_periph(AT91_PIN_PA13, 0); /* ETX1 */ |
| 176 | at91_set_A_periph(AT91_PIN_PA21, 0); /* EMDIO */ |
| 177 | at91_set_A_periph(AT91_PIN_PA20, 0); /* EMDC */ |
| 178 | |
| 179 | if (!data->is_rmii) { |
| 180 | at91_set_B_periph(AT91_PIN_PA28, 0); /* ECRS */ |
| 181 | at91_set_B_periph(AT91_PIN_PA29, 0); /* ECOL */ |
| 182 | at91_set_B_periph(AT91_PIN_PA25, 0); /* ERX2 */ |
| 183 | at91_set_B_periph(AT91_PIN_PA26, 0); /* ERX3 */ |
| 184 | at91_set_B_periph(AT91_PIN_PA27, 0); /* ERXCK */ |
| 185 | at91_set_B_periph(AT91_PIN_PA23, 0); /* ETX2 */ |
| 186 | at91_set_B_periph(AT91_PIN_PA24, 0); /* ETX3 */ |
| 187 | at91_set_B_periph(AT91_PIN_PA22, 0); /* ETXER */ |
| 188 | } |
| 189 | |
| 190 | eth_data = *data; |
| 191 | platform_device_register(&at91sam9260_eth_device); |
| 192 | } |
| 193 | #else |
Andrew Victor | a93d48c | 2007-02-01 09:22:23 +0100 | [diff] [blame] | 194 | void __init at91_add_device_eth(struct at91_eth_data *data) {} |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 195 | #endif |
| 196 | |
| 197 | |
| 198 | /* -------------------------------------------------------------------- |
| 199 | * MMC / SD |
| 200 | * -------------------------------------------------------------------- */ |
| 201 | |
| 202 | #if defined(CONFIG_MMC_AT91) || defined(CONFIG_MMC_AT91_MODULE) |
Andrew Victor | c6686ff | 2008-01-23 09:13:53 +0100 | [diff] [blame] | 203 | static u64 mmc_dmamask = DMA_BIT_MASK(32); |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 204 | static struct at91_mmc_data mmc_data; |
| 205 | |
| 206 | static struct resource mmc_resources[] = { |
| 207 | [0] = { |
| 208 | .start = AT91SAM9260_BASE_MCI, |
| 209 | .end = AT91SAM9260_BASE_MCI + SZ_16K - 1, |
| 210 | .flags = IORESOURCE_MEM, |
| 211 | }, |
| 212 | [1] = { |
| 213 | .start = AT91SAM9260_ID_MCI, |
| 214 | .end = AT91SAM9260_ID_MCI, |
| 215 | .flags = IORESOURCE_IRQ, |
| 216 | }, |
| 217 | }; |
| 218 | |
| 219 | static struct platform_device at91sam9260_mmc_device = { |
| 220 | .name = "at91_mci", |
| 221 | .id = -1, |
| 222 | .dev = { |
| 223 | .dma_mask = &mmc_dmamask, |
Andrew Victor | c6686ff | 2008-01-23 09:13:53 +0100 | [diff] [blame] | 224 | .coherent_dma_mask = DMA_BIT_MASK(32), |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 225 | .platform_data = &mmc_data, |
| 226 | }, |
| 227 | .resource = mmc_resources, |
| 228 | .num_resources = ARRAY_SIZE(mmc_resources), |
| 229 | }; |
| 230 | |
Andrew Victor | d0760b3 | 2007-02-08 09:00:39 +0100 | [diff] [blame] | 231 | void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data) |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 232 | { |
| 233 | if (!data) |
| 234 | return; |
| 235 | |
| 236 | /* input/irq */ |
| 237 | if (data->det_pin) { |
| 238 | at91_set_gpio_input(data->det_pin, 1); |
| 239 | at91_set_deglitch(data->det_pin, 1); |
| 240 | } |
| 241 | if (data->wp_pin) |
| 242 | at91_set_gpio_input(data->wp_pin, 1); |
| 243 | if (data->vcc_pin) |
| 244 | at91_set_gpio_output(data->vcc_pin, 0); |
| 245 | |
| 246 | /* CLK */ |
| 247 | at91_set_A_periph(AT91_PIN_PA8, 0); |
| 248 | |
| 249 | if (data->slot_b) { |
| 250 | /* CMD */ |
| 251 | at91_set_B_periph(AT91_PIN_PA1, 1); |
| 252 | |
| 253 | /* DAT0, maybe DAT1..DAT3 */ |
| 254 | at91_set_B_periph(AT91_PIN_PA0, 1); |
| 255 | if (data->wire4) { |
| 256 | at91_set_B_periph(AT91_PIN_PA5, 1); |
| 257 | at91_set_B_periph(AT91_PIN_PA4, 1); |
| 258 | at91_set_B_periph(AT91_PIN_PA3, 1); |
| 259 | } |
| 260 | } else { |
| 261 | /* CMD */ |
| 262 | at91_set_A_periph(AT91_PIN_PA7, 1); |
| 263 | |
| 264 | /* DAT0, maybe DAT1..DAT3 */ |
| 265 | at91_set_A_periph(AT91_PIN_PA6, 1); |
| 266 | if (data->wire4) { |
| 267 | at91_set_A_periph(AT91_PIN_PA9, 1); |
| 268 | at91_set_A_periph(AT91_PIN_PA10, 1); |
| 269 | at91_set_A_periph(AT91_PIN_PA11, 1); |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | mmc_data = *data; |
| 274 | platform_device_register(&at91sam9260_mmc_device); |
| 275 | } |
| 276 | #else |
Andrew Victor | d0760b3 | 2007-02-08 09:00:39 +0100 | [diff] [blame] | 277 | void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data) {} |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 278 | #endif |
| 279 | |
| 280 | |
| 281 | /* -------------------------------------------------------------------- |
| 282 | * NAND / SmartMedia |
| 283 | * -------------------------------------------------------------------- */ |
| 284 | |
| 285 | #if defined(CONFIG_MTD_NAND_AT91) || defined(CONFIG_MTD_NAND_AT91_MODULE) |
| 286 | static struct at91_nand_data nand_data; |
| 287 | |
| 288 | #define NAND_BASE AT91_CHIPSELECT_3 |
| 289 | |
| 290 | static struct resource nand_resources[] = { |
Andrew Victor | d7a2415 | 2008-04-02 21:44:44 +0100 | [diff] [blame] | 291 | [0] = { |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 292 | .start = NAND_BASE, |
Andrew Victor | 2282355 | 2008-01-23 09:21:02 +0100 | [diff] [blame] | 293 | .end = NAND_BASE + SZ_256M - 1, |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 294 | .flags = IORESOURCE_MEM, |
Andrew Victor | d7a2415 | 2008-04-02 21:44:44 +0100 | [diff] [blame] | 295 | }, |
| 296 | [1] = { |
| 297 | .start = AT91_BASE_SYS + AT91_ECC, |
| 298 | .end = AT91_BASE_SYS + AT91_ECC + SZ_512 - 1, |
| 299 | .flags = IORESOURCE_MEM, |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 300 | } |
| 301 | }; |
| 302 | |
| 303 | static struct platform_device at91sam9260_nand_device = { |
| 304 | .name = "at91_nand", |
| 305 | .id = -1, |
| 306 | .dev = { |
| 307 | .platform_data = &nand_data, |
| 308 | }, |
| 309 | .resource = nand_resources, |
| 310 | .num_resources = ARRAY_SIZE(nand_resources), |
| 311 | }; |
| 312 | |
| 313 | void __init at91_add_device_nand(struct at91_nand_data *data) |
| 314 | { |
| 315 | unsigned long csa, mode; |
| 316 | |
| 317 | if (!data) |
| 318 | return; |
| 319 | |
| 320 | csa = at91_sys_read(AT91_MATRIX_EBICSA); |
Andrew Victor | 2282355 | 2008-01-23 09:21:02 +0100 | [diff] [blame] | 321 | at91_sys_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_CS3A_SMC_SMARTMEDIA); |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 322 | |
| 323 | /* set the bus interface characteristics */ |
| 324 | at91_sys_write(AT91_SMC_SETUP(3), AT91_SMC_NWESETUP_(0) | AT91_SMC_NCS_WRSETUP_(0) |
| 325 | | AT91_SMC_NRDSETUP_(0) | AT91_SMC_NCS_RDSETUP_(0)); |
| 326 | |
Andrew Victor | 2848e64 | 2007-03-26 11:02:48 +0100 | [diff] [blame] | 327 | at91_sys_write(AT91_SMC_PULSE(3), AT91_SMC_NWEPULSE_(3) | AT91_SMC_NCS_WRPULSE_(3) |
| 328 | | AT91_SMC_NRDPULSE_(3) | AT91_SMC_NCS_RDPULSE_(3)); |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 329 | |
Andrew Victor | 2848e64 | 2007-03-26 11:02:48 +0100 | [diff] [blame] | 330 | at91_sys_write(AT91_SMC_CYCLE(3), AT91_SMC_NWECYCLE_(5) | AT91_SMC_NRDCYCLE_(5)); |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 331 | |
| 332 | if (data->bus_width_16) |
| 333 | mode = AT91_SMC_DBW_16; |
| 334 | else |
| 335 | mode = AT91_SMC_DBW_8; |
Andrew Victor | 2848e64 | 2007-03-26 11:02:48 +0100 | [diff] [blame] | 336 | at91_sys_write(AT91_SMC_MODE(3), mode | AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_TDF_(2)); |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 337 | |
| 338 | /* enable pin */ |
| 339 | if (data->enable_pin) |
| 340 | at91_set_gpio_output(data->enable_pin, 1); |
| 341 | |
| 342 | /* ready/busy pin */ |
| 343 | if (data->rdy_pin) |
| 344 | at91_set_gpio_input(data->rdy_pin, 1); |
| 345 | |
| 346 | /* card detect pin */ |
| 347 | if (data->det_pin) |
| 348 | at91_set_gpio_input(data->det_pin, 1); |
| 349 | |
| 350 | nand_data = *data; |
| 351 | platform_device_register(&at91sam9260_nand_device); |
| 352 | } |
| 353 | #else |
| 354 | void __init at91_add_device_nand(struct at91_nand_data *data) {} |
| 355 | #endif |
| 356 | |
| 357 | |
| 358 | /* -------------------------------------------------------------------- |
| 359 | * TWI (i2c) |
| 360 | * -------------------------------------------------------------------- */ |
| 361 | |
Andrew Victor | f230d3f | 2007-11-19 13:47:20 +0100 | [diff] [blame] | 362 | /* |
| 363 | * Prefer the GPIO code since the TWI controller isn't robust |
| 364 | * (gets overruns and underruns under load) and can only issue |
| 365 | * repeated STARTs in one scenario (the driver doesn't yet handle them). |
| 366 | */ |
| 367 | |
| 368 | #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE) |
| 369 | |
| 370 | static struct i2c_gpio_platform_data pdata = { |
| 371 | .sda_pin = AT91_PIN_PA23, |
| 372 | .sda_is_open_drain = 1, |
| 373 | .scl_pin = AT91_PIN_PA24, |
| 374 | .scl_is_open_drain = 1, |
| 375 | .udelay = 2, /* ~100 kHz */ |
| 376 | }; |
| 377 | |
| 378 | static struct platform_device at91sam9260_twi_device = { |
| 379 | .name = "i2c-gpio", |
| 380 | .id = -1, |
| 381 | .dev.platform_data = &pdata, |
| 382 | }; |
| 383 | |
| 384 | void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) |
| 385 | { |
| 386 | at91_set_GPIO_periph(AT91_PIN_PA23, 1); /* TWD (SDA) */ |
| 387 | at91_set_multi_drive(AT91_PIN_PA23, 1); |
| 388 | |
| 389 | at91_set_GPIO_periph(AT91_PIN_PA24, 1); /* TWCK (SCL) */ |
| 390 | at91_set_multi_drive(AT91_PIN_PA24, 1); |
| 391 | |
| 392 | i2c_register_board_info(0, devices, nr_devices); |
| 393 | platform_device_register(&at91sam9260_twi_device); |
| 394 | } |
| 395 | |
| 396 | #elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE) |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 397 | |
| 398 | static struct resource twi_resources[] = { |
| 399 | [0] = { |
| 400 | .start = AT91SAM9260_BASE_TWI, |
| 401 | .end = AT91SAM9260_BASE_TWI + SZ_16K - 1, |
| 402 | .flags = IORESOURCE_MEM, |
| 403 | }, |
| 404 | [1] = { |
| 405 | .start = AT91SAM9260_ID_TWI, |
| 406 | .end = AT91SAM9260_ID_TWI, |
| 407 | .flags = IORESOURCE_IRQ, |
| 408 | }, |
| 409 | }; |
| 410 | |
| 411 | static struct platform_device at91sam9260_twi_device = { |
| 412 | .name = "at91_i2c", |
| 413 | .id = -1, |
| 414 | .resource = twi_resources, |
| 415 | .num_resources = ARRAY_SIZE(twi_resources), |
| 416 | }; |
| 417 | |
Andrew Victor | f230d3f | 2007-11-19 13:47:20 +0100 | [diff] [blame] | 418 | void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 419 | { |
| 420 | /* pins used for TWI interface */ |
| 421 | at91_set_A_periph(AT91_PIN_PA23, 0); /* TWD */ |
| 422 | at91_set_multi_drive(AT91_PIN_PA23, 1); |
| 423 | |
| 424 | at91_set_A_periph(AT91_PIN_PA24, 0); /* TWCK */ |
| 425 | at91_set_multi_drive(AT91_PIN_PA24, 1); |
| 426 | |
Andrew Victor | f230d3f | 2007-11-19 13:47:20 +0100 | [diff] [blame] | 427 | i2c_register_board_info(0, devices, nr_devices); |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 428 | platform_device_register(&at91sam9260_twi_device); |
| 429 | } |
| 430 | #else |
Andrew Victor | f230d3f | 2007-11-19 13:47:20 +0100 | [diff] [blame] | 431 | void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {} |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 432 | #endif |
| 433 | |
| 434 | |
| 435 | /* -------------------------------------------------------------------- |
| 436 | * SPI |
| 437 | * -------------------------------------------------------------------- */ |
| 438 | |
| 439 | #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE) |
Andrew Victor | c6686ff | 2008-01-23 09:13:53 +0100 | [diff] [blame] | 440 | static u64 spi_dmamask = DMA_BIT_MASK(32); |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 441 | |
| 442 | static struct resource spi0_resources[] = { |
| 443 | [0] = { |
| 444 | .start = AT91SAM9260_BASE_SPI0, |
| 445 | .end = AT91SAM9260_BASE_SPI0 + SZ_16K - 1, |
| 446 | .flags = IORESOURCE_MEM, |
| 447 | }, |
| 448 | [1] = { |
| 449 | .start = AT91SAM9260_ID_SPI0, |
| 450 | .end = AT91SAM9260_ID_SPI0, |
| 451 | .flags = IORESOURCE_IRQ, |
| 452 | }, |
| 453 | }; |
| 454 | |
| 455 | static struct platform_device at91sam9260_spi0_device = { |
| 456 | .name = "atmel_spi", |
| 457 | .id = 0, |
| 458 | .dev = { |
| 459 | .dma_mask = &spi_dmamask, |
Andrew Victor | c6686ff | 2008-01-23 09:13:53 +0100 | [diff] [blame] | 460 | .coherent_dma_mask = DMA_BIT_MASK(32), |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 461 | }, |
| 462 | .resource = spi0_resources, |
| 463 | .num_resources = ARRAY_SIZE(spi0_resources), |
| 464 | }; |
| 465 | |
| 466 | static const unsigned spi0_standard_cs[4] = { AT91_PIN_PA3, AT91_PIN_PC11, AT91_PIN_PC16, AT91_PIN_PC17 }; |
| 467 | |
| 468 | static struct resource spi1_resources[] = { |
| 469 | [0] = { |
| 470 | .start = AT91SAM9260_BASE_SPI1, |
| 471 | .end = AT91SAM9260_BASE_SPI1 + SZ_16K - 1, |
| 472 | .flags = IORESOURCE_MEM, |
| 473 | }, |
| 474 | [1] = { |
| 475 | .start = AT91SAM9260_ID_SPI1, |
| 476 | .end = AT91SAM9260_ID_SPI1, |
| 477 | .flags = IORESOURCE_IRQ, |
| 478 | }, |
| 479 | }; |
| 480 | |
| 481 | static struct platform_device at91sam9260_spi1_device = { |
| 482 | .name = "atmel_spi", |
| 483 | .id = 1, |
| 484 | .dev = { |
| 485 | .dma_mask = &spi_dmamask, |
Andrew Victor | c6686ff | 2008-01-23 09:13:53 +0100 | [diff] [blame] | 486 | .coherent_dma_mask = DMA_BIT_MASK(32), |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 487 | }, |
| 488 | .resource = spi1_resources, |
| 489 | .num_resources = ARRAY_SIZE(spi1_resources), |
| 490 | }; |
| 491 | |
| 492 | static const unsigned spi1_standard_cs[4] = { AT91_PIN_PB3, AT91_PIN_PC5, AT91_PIN_PC4, AT91_PIN_PC3 }; |
| 493 | |
| 494 | void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) |
| 495 | { |
| 496 | int i; |
| 497 | unsigned long cs_pin; |
| 498 | short enable_spi0 = 0; |
| 499 | short enable_spi1 = 0; |
| 500 | |
| 501 | /* Choose SPI chip-selects */ |
| 502 | for (i = 0; i < nr_devices; i++) { |
| 503 | if (devices[i].controller_data) |
| 504 | cs_pin = (unsigned long) devices[i].controller_data; |
| 505 | else if (devices[i].bus_num == 0) |
| 506 | cs_pin = spi0_standard_cs[devices[i].chip_select]; |
| 507 | else |
| 508 | cs_pin = spi1_standard_cs[devices[i].chip_select]; |
| 509 | |
| 510 | if (devices[i].bus_num == 0) |
| 511 | enable_spi0 = 1; |
| 512 | else |
| 513 | enable_spi1 = 1; |
| 514 | |
| 515 | /* enable chip-select pin */ |
| 516 | at91_set_gpio_output(cs_pin, 1); |
| 517 | |
| 518 | /* pass chip-select pin to driver */ |
| 519 | devices[i].controller_data = (void *) cs_pin; |
| 520 | } |
| 521 | |
| 522 | spi_register_board_info(devices, nr_devices); |
| 523 | |
| 524 | /* Configure SPI bus(es) */ |
| 525 | if (enable_spi0) { |
| 526 | at91_set_A_periph(AT91_PIN_PA0, 0); /* SPI0_MISO */ |
| 527 | at91_set_A_periph(AT91_PIN_PA1, 0); /* SPI0_MOSI */ |
| 528 | at91_set_A_periph(AT91_PIN_PA2, 0); /* SPI1_SPCK */ |
| 529 | |
| 530 | at91_clock_associate("spi0_clk", &at91sam9260_spi0_device.dev, "spi_clk"); |
| 531 | platform_device_register(&at91sam9260_spi0_device); |
| 532 | } |
| 533 | if (enable_spi1) { |
| 534 | at91_set_A_periph(AT91_PIN_PB0, 0); /* SPI1_MISO */ |
| 535 | at91_set_A_periph(AT91_PIN_PB1, 0); /* SPI1_MOSI */ |
| 536 | at91_set_A_periph(AT91_PIN_PB2, 0); /* SPI1_SPCK */ |
| 537 | |
| 538 | at91_clock_associate("spi1_clk", &at91sam9260_spi1_device.dev, "spi_clk"); |
| 539 | platform_device_register(&at91sam9260_spi1_device); |
| 540 | } |
| 541 | } |
| 542 | #else |
| 543 | void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {} |
| 544 | #endif |
| 545 | |
| 546 | |
| 547 | /* -------------------------------------------------------------------- |
Andrew Victor | e5f40bf | 2008-04-02 21:58:00 +0100 | [diff] [blame^] | 548 | * Timer/Counter blocks |
| 549 | * -------------------------------------------------------------------- */ |
| 550 | |
| 551 | #ifdef CONFIG_ATMEL_TCLIB |
| 552 | |
| 553 | static struct resource tcb0_resources[] = { |
| 554 | [0] = { |
| 555 | .start = AT91SAM9260_BASE_TCB0, |
| 556 | .end = AT91SAM9260_BASE_TCB0 + SZ_16K - 1, |
| 557 | .flags = IORESOURCE_MEM, |
| 558 | }, |
| 559 | [1] = { |
| 560 | .start = AT91SAM9260_ID_TC0, |
| 561 | .end = AT91SAM9260_ID_TC0, |
| 562 | .flags = IORESOURCE_IRQ, |
| 563 | }, |
| 564 | [2] = { |
| 565 | .start = AT91SAM9260_ID_TC1, |
| 566 | .end = AT91SAM9260_ID_TC1, |
| 567 | .flags = IORESOURCE_IRQ, |
| 568 | }, |
| 569 | [3] = { |
| 570 | .start = AT91SAM9260_ID_TC2, |
| 571 | .end = AT91SAM9260_ID_TC2, |
| 572 | .flags = IORESOURCE_IRQ, |
| 573 | }, |
| 574 | }; |
| 575 | |
| 576 | static struct platform_device at91sam9260_tcb0_device = { |
| 577 | .name = "atmel_tcb", |
| 578 | .id = 0, |
| 579 | .resource = tcb0_resources, |
| 580 | .num_resources = ARRAY_SIZE(tcb0_resources), |
| 581 | }; |
| 582 | |
| 583 | static struct resource tcb1_resources[] = { |
| 584 | [0] = { |
| 585 | .start = AT91SAM9260_BASE_TCB1, |
| 586 | .end = AT91SAM9260_BASE_TCB1 + SZ_16K - 1, |
| 587 | .flags = IORESOURCE_MEM, |
| 588 | }, |
| 589 | [1] = { |
| 590 | .start = AT91SAM9260_ID_TC3, |
| 591 | .end = AT91SAM9260_ID_TC3, |
| 592 | .flags = IORESOURCE_IRQ, |
| 593 | }, |
| 594 | [2] = { |
| 595 | .start = AT91SAM9260_ID_TC4, |
| 596 | .end = AT91SAM9260_ID_TC4, |
| 597 | .flags = IORESOURCE_IRQ, |
| 598 | }, |
| 599 | [3] = { |
| 600 | .start = AT91SAM9260_ID_TC5, |
| 601 | .end = AT91SAM9260_ID_TC5, |
| 602 | .flags = IORESOURCE_IRQ, |
| 603 | }, |
| 604 | }; |
| 605 | |
| 606 | static struct platform_device at91sam9260_tcb1_device = { |
| 607 | .name = "atmel_tcb", |
| 608 | .id = 1, |
| 609 | .resource = tcb1_resources, |
| 610 | .num_resources = ARRAY_SIZE(tcb1_resources), |
| 611 | }; |
| 612 | |
| 613 | static void __init at91_add_device_tc(void) |
| 614 | { |
| 615 | /* this chip has a separate clock and irq for each TC channel */ |
| 616 | at91_clock_associate("tc0_clk", &at91sam9260_tcb0_device.dev, "t0_clk"); |
| 617 | at91_clock_associate("tc1_clk", &at91sam9260_tcb0_device.dev, "t1_clk"); |
| 618 | at91_clock_associate("tc2_clk", &at91sam9260_tcb0_device.dev, "t2_clk"); |
| 619 | platform_device_register(&at91sam9260_tcb0_device); |
| 620 | |
| 621 | at91_clock_associate("tc3_clk", &at91sam9260_tcb1_device.dev, "t0_clk"); |
| 622 | at91_clock_associate("tc4_clk", &at91sam9260_tcb1_device.dev, "t1_clk"); |
| 623 | at91_clock_associate("tc5_clk", &at91sam9260_tcb1_device.dev, "t2_clk"); |
| 624 | platform_device_register(&at91sam9260_tcb1_device); |
| 625 | } |
| 626 | #else |
| 627 | static void __init at91_add_device_tc(void) { } |
| 628 | #endif |
| 629 | |
| 630 | |
| 631 | /* -------------------------------------------------------------------- |
Andrew Victor | 884f5a6 | 2008-01-23 09:11:13 +0100 | [diff] [blame] | 632 | * RTT |
| 633 | * -------------------------------------------------------------------- */ |
| 634 | |
| 635 | static struct resource rtt_resources[] = { |
| 636 | { |
| 637 | .start = AT91_BASE_SYS + AT91_RTT, |
| 638 | .end = AT91_BASE_SYS + AT91_RTT + SZ_16 - 1, |
| 639 | .flags = IORESOURCE_MEM, |
| 640 | } |
| 641 | }; |
| 642 | |
| 643 | static struct platform_device at91sam9260_rtt_device = { |
| 644 | .name = "at91_rtt", |
Andrew Victor | 4fd9212 | 2008-04-02 21:55:19 +0100 | [diff] [blame] | 645 | .id = 0, |
Andrew Victor | 884f5a6 | 2008-01-23 09:11:13 +0100 | [diff] [blame] | 646 | .resource = rtt_resources, |
| 647 | .num_resources = ARRAY_SIZE(rtt_resources), |
| 648 | }; |
| 649 | |
| 650 | static void __init at91_add_device_rtt(void) |
| 651 | { |
| 652 | platform_device_register(&at91sam9260_rtt_device); |
| 653 | } |
| 654 | |
| 655 | |
| 656 | /* -------------------------------------------------------------------- |
| 657 | * Watchdog |
| 658 | * -------------------------------------------------------------------- */ |
| 659 | |
| 660 | #if defined(CONFIG_AT91SAM9_WATCHDOG) || defined(CONFIG_AT91SAM9_WATCHDOG_MODULE) |
| 661 | static struct platform_device at91sam9260_wdt_device = { |
| 662 | .name = "at91_wdt", |
| 663 | .id = -1, |
| 664 | .num_resources = 0, |
| 665 | }; |
| 666 | |
| 667 | static void __init at91_add_device_watchdog(void) |
| 668 | { |
| 669 | platform_device_register(&at91sam9260_wdt_device); |
| 670 | } |
| 671 | #else |
| 672 | static void __init at91_add_device_watchdog(void) {} |
| 673 | #endif |
| 674 | |
| 675 | |
| 676 | /* -------------------------------------------------------------------- |
Andrew Victor | bfbc326 | 2008-01-23 09:18:06 +0100 | [diff] [blame] | 677 | * SSC -- Synchronous Serial Controller |
| 678 | * -------------------------------------------------------------------- */ |
| 679 | |
| 680 | #if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE) |
| 681 | static u64 ssc_dmamask = DMA_BIT_MASK(32); |
| 682 | |
| 683 | static struct resource ssc_resources[] = { |
| 684 | [0] = { |
| 685 | .start = AT91SAM9260_BASE_SSC, |
| 686 | .end = AT91SAM9260_BASE_SSC + SZ_16K - 1, |
| 687 | .flags = IORESOURCE_MEM, |
| 688 | }, |
| 689 | [1] = { |
| 690 | .start = AT91SAM9260_ID_SSC, |
| 691 | .end = AT91SAM9260_ID_SSC, |
| 692 | .flags = IORESOURCE_IRQ, |
| 693 | }, |
| 694 | }; |
| 695 | |
| 696 | static struct platform_device at91sam9260_ssc_device = { |
| 697 | .name = "ssc", |
| 698 | .id = 0, |
| 699 | .dev = { |
| 700 | .dma_mask = &ssc_dmamask, |
| 701 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 702 | }, |
| 703 | .resource = ssc_resources, |
| 704 | .num_resources = ARRAY_SIZE(ssc_resources), |
| 705 | }; |
| 706 | |
| 707 | static inline void configure_ssc_pins(unsigned pins) |
| 708 | { |
| 709 | if (pins & ATMEL_SSC_TF) |
| 710 | at91_set_A_periph(AT91_PIN_PB17, 1); |
| 711 | if (pins & ATMEL_SSC_TK) |
| 712 | at91_set_A_periph(AT91_PIN_PB16, 1); |
| 713 | if (pins & ATMEL_SSC_TD) |
| 714 | at91_set_A_periph(AT91_PIN_PB18, 1); |
| 715 | if (pins & ATMEL_SSC_RD) |
| 716 | at91_set_A_periph(AT91_PIN_PB19, 1); |
| 717 | if (pins & ATMEL_SSC_RK) |
| 718 | at91_set_A_periph(AT91_PIN_PB20, 1); |
| 719 | if (pins & ATMEL_SSC_RF) |
| 720 | at91_set_A_periph(AT91_PIN_PB21, 1); |
| 721 | } |
| 722 | |
| 723 | /* |
| 724 | * SSC controllers are accessed through library code, instead of any |
| 725 | * kind of all-singing/all-dancing driver. For example one could be |
| 726 | * used by a particular I2S audio codec's driver, while another one |
| 727 | * on the same system might be used by a custom data capture driver. |
| 728 | */ |
| 729 | void __init at91_add_device_ssc(unsigned id, unsigned pins) |
| 730 | { |
| 731 | struct platform_device *pdev; |
| 732 | |
| 733 | /* |
| 734 | * NOTE: caller is responsible for passing information matching |
| 735 | * "pins" to whatever will be using each particular controller. |
| 736 | */ |
| 737 | switch (id) { |
| 738 | case AT91SAM9260_ID_SSC: |
| 739 | pdev = &at91sam9260_ssc_device; |
| 740 | configure_ssc_pins(pins); |
| 741 | at91_clock_associate("ssc_clk", &pdev->dev, "pclk"); |
| 742 | break; |
| 743 | default: |
| 744 | return; |
| 745 | } |
| 746 | |
| 747 | platform_device_register(pdev); |
| 748 | } |
| 749 | |
| 750 | #else |
| 751 | void __init at91_add_device_ssc(unsigned id, unsigned pins) {} |
| 752 | #endif |
| 753 | |
| 754 | |
| 755 | /* -------------------------------------------------------------------- |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 756 | * UART |
| 757 | * -------------------------------------------------------------------- */ |
| 758 | #if defined(CONFIG_SERIAL_ATMEL) |
| 759 | static struct resource dbgu_resources[] = { |
| 760 | [0] = { |
| 761 | .start = AT91_VA_BASE_SYS + AT91_DBGU, |
| 762 | .end = AT91_VA_BASE_SYS + AT91_DBGU + SZ_512 - 1, |
| 763 | .flags = IORESOURCE_MEM, |
| 764 | }, |
| 765 | [1] = { |
| 766 | .start = AT91_ID_SYS, |
| 767 | .end = AT91_ID_SYS, |
| 768 | .flags = IORESOURCE_IRQ, |
| 769 | }, |
| 770 | }; |
| 771 | |
| 772 | static struct atmel_uart_data dbgu_data = { |
| 773 | .use_dma_tx = 0, |
| 774 | .use_dma_rx = 0, /* DBGU not capable of receive DMA */ |
| 775 | .regs = (void __iomem *)(AT91_VA_BASE_SYS + AT91_DBGU), |
| 776 | }; |
| 777 | |
Andrew Victor | c6686ff | 2008-01-23 09:13:53 +0100 | [diff] [blame] | 778 | static u64 dbgu_dmamask = DMA_BIT_MASK(32); |
| 779 | |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 780 | static struct platform_device at91sam9260_dbgu_device = { |
| 781 | .name = "atmel_usart", |
| 782 | .id = 0, |
| 783 | .dev = { |
Andrew Victor | c6686ff | 2008-01-23 09:13:53 +0100 | [diff] [blame] | 784 | .dma_mask = &dbgu_dmamask, |
| 785 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 786 | .platform_data = &dbgu_data, |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 787 | }, |
| 788 | .resource = dbgu_resources, |
| 789 | .num_resources = ARRAY_SIZE(dbgu_resources), |
| 790 | }; |
| 791 | |
| 792 | static inline void configure_dbgu_pins(void) |
| 793 | { |
| 794 | at91_set_A_periph(AT91_PIN_PB14, 0); /* DRXD */ |
| 795 | at91_set_A_periph(AT91_PIN_PB15, 1); /* DTXD */ |
| 796 | } |
| 797 | |
| 798 | static struct resource uart0_resources[] = { |
| 799 | [0] = { |
| 800 | .start = AT91SAM9260_BASE_US0, |
| 801 | .end = AT91SAM9260_BASE_US0 + SZ_16K - 1, |
| 802 | .flags = IORESOURCE_MEM, |
| 803 | }, |
| 804 | [1] = { |
| 805 | .start = AT91SAM9260_ID_US0, |
| 806 | .end = AT91SAM9260_ID_US0, |
| 807 | .flags = IORESOURCE_IRQ, |
| 808 | }, |
| 809 | }; |
| 810 | |
| 811 | static struct atmel_uart_data uart0_data = { |
| 812 | .use_dma_tx = 1, |
| 813 | .use_dma_rx = 1, |
| 814 | }; |
| 815 | |
Andrew Victor | c6686ff | 2008-01-23 09:13:53 +0100 | [diff] [blame] | 816 | static u64 uart0_dmamask = DMA_BIT_MASK(32); |
| 817 | |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 818 | static struct platform_device at91sam9260_uart0_device = { |
| 819 | .name = "atmel_usart", |
| 820 | .id = 1, |
| 821 | .dev = { |
Andrew Victor | c6686ff | 2008-01-23 09:13:53 +0100 | [diff] [blame] | 822 | .dma_mask = &uart0_dmamask, |
| 823 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 824 | .platform_data = &uart0_data, |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 825 | }, |
| 826 | .resource = uart0_resources, |
| 827 | .num_resources = ARRAY_SIZE(uart0_resources), |
| 828 | }; |
| 829 | |
Andrew Victor | c8f385a | 2008-01-23 09:25:15 +0100 | [diff] [blame] | 830 | static inline void configure_usart0_pins(unsigned pins) |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 831 | { |
| 832 | at91_set_A_periph(AT91_PIN_PB4, 1); /* TXD0 */ |
| 833 | at91_set_A_periph(AT91_PIN_PB5, 0); /* RXD0 */ |
Andrew Victor | c8f385a | 2008-01-23 09:25:15 +0100 | [diff] [blame] | 834 | |
| 835 | if (pins & ATMEL_UART_RTS) |
| 836 | at91_set_A_periph(AT91_PIN_PB26, 0); /* RTS0 */ |
| 837 | if (pins & ATMEL_UART_CTS) |
| 838 | at91_set_A_periph(AT91_PIN_PB27, 0); /* CTS0 */ |
| 839 | if (pins & ATMEL_UART_DTR) |
| 840 | at91_set_A_periph(AT91_PIN_PB24, 0); /* DTR0 */ |
| 841 | if (pins & ATMEL_UART_DSR) |
| 842 | at91_set_A_periph(AT91_PIN_PB22, 0); /* DSR0 */ |
| 843 | if (pins & ATMEL_UART_DCD) |
| 844 | at91_set_A_periph(AT91_PIN_PB23, 0); /* DCD0 */ |
| 845 | if (pins & ATMEL_UART_RI) |
| 846 | at91_set_A_periph(AT91_PIN_PB25, 0); /* RI0 */ |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 847 | } |
| 848 | |
| 849 | static struct resource uart1_resources[] = { |
| 850 | [0] = { |
| 851 | .start = AT91SAM9260_BASE_US1, |
| 852 | .end = AT91SAM9260_BASE_US1 + SZ_16K - 1, |
| 853 | .flags = IORESOURCE_MEM, |
| 854 | }, |
| 855 | [1] = { |
| 856 | .start = AT91SAM9260_ID_US1, |
| 857 | .end = AT91SAM9260_ID_US1, |
| 858 | .flags = IORESOURCE_IRQ, |
| 859 | }, |
| 860 | }; |
| 861 | |
| 862 | static struct atmel_uart_data uart1_data = { |
| 863 | .use_dma_tx = 1, |
| 864 | .use_dma_rx = 1, |
| 865 | }; |
| 866 | |
Andrew Victor | c6686ff | 2008-01-23 09:13:53 +0100 | [diff] [blame] | 867 | static u64 uart1_dmamask = DMA_BIT_MASK(32); |
| 868 | |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 869 | static struct platform_device at91sam9260_uart1_device = { |
| 870 | .name = "atmel_usart", |
| 871 | .id = 2, |
| 872 | .dev = { |
Andrew Victor | c6686ff | 2008-01-23 09:13:53 +0100 | [diff] [blame] | 873 | .dma_mask = &uart1_dmamask, |
| 874 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 875 | .platform_data = &uart1_data, |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 876 | }, |
| 877 | .resource = uart1_resources, |
| 878 | .num_resources = ARRAY_SIZE(uart1_resources), |
| 879 | }; |
| 880 | |
Andrew Victor | c8f385a | 2008-01-23 09:25:15 +0100 | [diff] [blame] | 881 | static inline void configure_usart1_pins(unsigned pins) |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 882 | { |
| 883 | at91_set_A_periph(AT91_PIN_PB6, 1); /* TXD1 */ |
| 884 | at91_set_A_periph(AT91_PIN_PB7, 0); /* RXD1 */ |
Andrew Victor | c8f385a | 2008-01-23 09:25:15 +0100 | [diff] [blame] | 885 | |
| 886 | if (pins & ATMEL_UART_RTS) |
| 887 | at91_set_A_periph(AT91_PIN_PB28, 0); /* RTS1 */ |
| 888 | if (pins & ATMEL_UART_CTS) |
| 889 | at91_set_A_periph(AT91_PIN_PB29, 0); /* CTS1 */ |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 890 | } |
| 891 | |
| 892 | static struct resource uart2_resources[] = { |
| 893 | [0] = { |
| 894 | .start = AT91SAM9260_BASE_US2, |
| 895 | .end = AT91SAM9260_BASE_US2 + SZ_16K - 1, |
| 896 | .flags = IORESOURCE_MEM, |
| 897 | }, |
| 898 | [1] = { |
| 899 | .start = AT91SAM9260_ID_US2, |
| 900 | .end = AT91SAM9260_ID_US2, |
| 901 | .flags = IORESOURCE_IRQ, |
| 902 | }, |
| 903 | }; |
| 904 | |
| 905 | static struct atmel_uart_data uart2_data = { |
| 906 | .use_dma_tx = 1, |
| 907 | .use_dma_rx = 1, |
| 908 | }; |
| 909 | |
Andrew Victor | c6686ff | 2008-01-23 09:13:53 +0100 | [diff] [blame] | 910 | static u64 uart2_dmamask = DMA_BIT_MASK(32); |
| 911 | |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 912 | static struct platform_device at91sam9260_uart2_device = { |
| 913 | .name = "atmel_usart", |
| 914 | .id = 3, |
| 915 | .dev = { |
Andrew Victor | c6686ff | 2008-01-23 09:13:53 +0100 | [diff] [blame] | 916 | .dma_mask = &uart2_dmamask, |
| 917 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 918 | .platform_data = &uart2_data, |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 919 | }, |
| 920 | .resource = uart2_resources, |
| 921 | .num_resources = ARRAY_SIZE(uart2_resources), |
| 922 | }; |
| 923 | |
Andrew Victor | c8f385a | 2008-01-23 09:25:15 +0100 | [diff] [blame] | 924 | static inline void configure_usart2_pins(unsigned pins) |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 925 | { |
| 926 | at91_set_A_periph(AT91_PIN_PB8, 1); /* TXD2 */ |
| 927 | at91_set_A_periph(AT91_PIN_PB9, 0); /* RXD2 */ |
Andrew Victor | c8f385a | 2008-01-23 09:25:15 +0100 | [diff] [blame] | 928 | |
| 929 | if (pins & ATMEL_UART_RTS) |
| 930 | at91_set_A_periph(AT91_PIN_PA4, 0); /* RTS2 */ |
| 931 | if (pins & ATMEL_UART_CTS) |
| 932 | at91_set_A_periph(AT91_PIN_PA5, 0); /* CTS2 */ |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 933 | } |
| 934 | |
| 935 | static struct resource uart3_resources[] = { |
| 936 | [0] = { |
| 937 | .start = AT91SAM9260_BASE_US3, |
| 938 | .end = AT91SAM9260_BASE_US3 + SZ_16K - 1, |
| 939 | .flags = IORESOURCE_MEM, |
| 940 | }, |
| 941 | [1] = { |
| 942 | .start = AT91SAM9260_ID_US3, |
| 943 | .end = AT91SAM9260_ID_US3, |
| 944 | .flags = IORESOURCE_IRQ, |
| 945 | }, |
| 946 | }; |
| 947 | |
| 948 | static struct atmel_uart_data uart3_data = { |
| 949 | .use_dma_tx = 1, |
| 950 | .use_dma_rx = 1, |
| 951 | }; |
| 952 | |
Andrew Victor | c6686ff | 2008-01-23 09:13:53 +0100 | [diff] [blame] | 953 | static u64 uart3_dmamask = DMA_BIT_MASK(32); |
| 954 | |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 955 | static struct platform_device at91sam9260_uart3_device = { |
| 956 | .name = "atmel_usart", |
| 957 | .id = 4, |
| 958 | .dev = { |
Andrew Victor | c6686ff | 2008-01-23 09:13:53 +0100 | [diff] [blame] | 959 | .dma_mask = &uart3_dmamask, |
| 960 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 961 | .platform_data = &uart3_data, |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 962 | }, |
| 963 | .resource = uart3_resources, |
| 964 | .num_resources = ARRAY_SIZE(uart3_resources), |
| 965 | }; |
| 966 | |
Andrew Victor | c8f385a | 2008-01-23 09:25:15 +0100 | [diff] [blame] | 967 | static inline void configure_usart3_pins(unsigned pins) |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 968 | { |
| 969 | at91_set_A_periph(AT91_PIN_PB10, 1); /* TXD3 */ |
| 970 | at91_set_A_periph(AT91_PIN_PB11, 0); /* RXD3 */ |
Andrew Victor | c8f385a | 2008-01-23 09:25:15 +0100 | [diff] [blame] | 971 | |
| 972 | if (pins & ATMEL_UART_RTS) |
| 973 | at91_set_B_periph(AT91_PIN_PC8, 0); /* RTS3 */ |
| 974 | if (pins & ATMEL_UART_CTS) |
| 975 | at91_set_B_periph(AT91_PIN_PC10, 0); /* CTS3 */ |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 976 | } |
| 977 | |
| 978 | static struct resource uart4_resources[] = { |
| 979 | [0] = { |
| 980 | .start = AT91SAM9260_BASE_US4, |
| 981 | .end = AT91SAM9260_BASE_US4 + SZ_16K - 1, |
| 982 | .flags = IORESOURCE_MEM, |
| 983 | }, |
| 984 | [1] = { |
| 985 | .start = AT91SAM9260_ID_US4, |
| 986 | .end = AT91SAM9260_ID_US4, |
| 987 | .flags = IORESOURCE_IRQ, |
| 988 | }, |
| 989 | }; |
| 990 | |
| 991 | static struct atmel_uart_data uart4_data = { |
| 992 | .use_dma_tx = 1, |
| 993 | .use_dma_rx = 1, |
| 994 | }; |
| 995 | |
Andrew Victor | c6686ff | 2008-01-23 09:13:53 +0100 | [diff] [blame] | 996 | static u64 uart4_dmamask = DMA_BIT_MASK(32); |
| 997 | |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 998 | static struct platform_device at91sam9260_uart4_device = { |
| 999 | .name = "atmel_usart", |
| 1000 | .id = 5, |
| 1001 | .dev = { |
Andrew Victor | c6686ff | 2008-01-23 09:13:53 +0100 | [diff] [blame] | 1002 | .dma_mask = &uart4_dmamask, |
| 1003 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 1004 | .platform_data = &uart4_data, |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 1005 | }, |
| 1006 | .resource = uart4_resources, |
| 1007 | .num_resources = ARRAY_SIZE(uart4_resources), |
| 1008 | }; |
| 1009 | |
| 1010 | static inline void configure_usart4_pins(void) |
| 1011 | { |
| 1012 | at91_set_B_periph(AT91_PIN_PA31, 1); /* TXD4 */ |
| 1013 | at91_set_B_periph(AT91_PIN_PA30, 0); /* RXD4 */ |
| 1014 | } |
| 1015 | |
| 1016 | static struct resource uart5_resources[] = { |
| 1017 | [0] = { |
| 1018 | .start = AT91SAM9260_BASE_US5, |
| 1019 | .end = AT91SAM9260_BASE_US5 + SZ_16K - 1, |
| 1020 | .flags = IORESOURCE_MEM, |
| 1021 | }, |
| 1022 | [1] = { |
| 1023 | .start = AT91SAM9260_ID_US5, |
| 1024 | .end = AT91SAM9260_ID_US5, |
| 1025 | .flags = IORESOURCE_IRQ, |
| 1026 | }, |
| 1027 | }; |
| 1028 | |
| 1029 | static struct atmel_uart_data uart5_data = { |
| 1030 | .use_dma_tx = 1, |
| 1031 | .use_dma_rx = 1, |
| 1032 | }; |
| 1033 | |
Andrew Victor | c6686ff | 2008-01-23 09:13:53 +0100 | [diff] [blame] | 1034 | static u64 uart5_dmamask = DMA_BIT_MASK(32); |
| 1035 | |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 1036 | static struct platform_device at91sam9260_uart5_device = { |
| 1037 | .name = "atmel_usart", |
| 1038 | .id = 6, |
| 1039 | .dev = { |
Andrew Victor | c6686ff | 2008-01-23 09:13:53 +0100 | [diff] [blame] | 1040 | .dma_mask = &uart5_dmamask, |
| 1041 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 1042 | .platform_data = &uart5_data, |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 1043 | }, |
| 1044 | .resource = uart5_resources, |
| 1045 | .num_resources = ARRAY_SIZE(uart5_resources), |
| 1046 | }; |
| 1047 | |
| 1048 | static inline void configure_usart5_pins(void) |
| 1049 | { |
| 1050 | at91_set_A_periph(AT91_PIN_PB12, 1); /* TXD5 */ |
| 1051 | at91_set_A_periph(AT91_PIN_PB13, 0); /* RXD5 */ |
| 1052 | } |
| 1053 | |
Andrew Victor | c6686ff | 2008-01-23 09:13:53 +0100 | [diff] [blame] | 1054 | static struct platform_device *at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */ |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 1055 | struct platform_device *atmel_default_console_device; /* the serial console device */ |
| 1056 | |
Andrew Victor | c8f385a | 2008-01-23 09:25:15 +0100 | [diff] [blame] | 1057 | void __init __deprecated at91_init_serial(struct at91_uart_config *config) |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 1058 | { |
| 1059 | int i; |
| 1060 | |
| 1061 | /* Fill in list of supported UARTs */ |
| 1062 | for (i = 0; i < config->nr_tty; i++) { |
| 1063 | switch (config->tty_map[i]) { |
| 1064 | case 0: |
Andrew Victor | c8f385a | 2008-01-23 09:25:15 +0100 | [diff] [blame] | 1065 | configure_usart0_pins(ATMEL_UART_CTS | ATMEL_UART_RTS | ATMEL_UART_DSR | ATMEL_UART_DTR | ATMEL_UART_DCD | ATMEL_UART_RI); |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 1066 | at91_uarts[i] = &at91sam9260_uart0_device; |
| 1067 | at91_clock_associate("usart0_clk", &at91sam9260_uart0_device.dev, "usart"); |
| 1068 | break; |
| 1069 | case 1: |
Andrew Victor | c8f385a | 2008-01-23 09:25:15 +0100 | [diff] [blame] | 1070 | configure_usart1_pins(ATMEL_UART_CTS | ATMEL_UART_RTS); |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 1071 | at91_uarts[i] = &at91sam9260_uart1_device; |
| 1072 | at91_clock_associate("usart1_clk", &at91sam9260_uart1_device.dev, "usart"); |
| 1073 | break; |
| 1074 | case 2: |
Andrew Victor | c8f385a | 2008-01-23 09:25:15 +0100 | [diff] [blame] | 1075 | configure_usart2_pins(0); |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 1076 | at91_uarts[i] = &at91sam9260_uart2_device; |
| 1077 | at91_clock_associate("usart2_clk", &at91sam9260_uart2_device.dev, "usart"); |
| 1078 | break; |
| 1079 | case 3: |
Andrew Victor | c8f385a | 2008-01-23 09:25:15 +0100 | [diff] [blame] | 1080 | configure_usart3_pins(0); |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 1081 | at91_uarts[i] = &at91sam9260_uart3_device; |
| 1082 | at91_clock_associate("usart3_clk", &at91sam9260_uart3_device.dev, "usart"); |
| 1083 | break; |
| 1084 | case 4: |
| 1085 | configure_usart4_pins(); |
| 1086 | at91_uarts[i] = &at91sam9260_uart4_device; |
| 1087 | at91_clock_associate("usart4_clk", &at91sam9260_uart4_device.dev, "usart"); |
| 1088 | break; |
| 1089 | case 5: |
| 1090 | configure_usart5_pins(); |
| 1091 | at91_uarts[i] = &at91sam9260_uart5_device; |
| 1092 | at91_clock_associate("usart5_clk", &at91sam9260_uart5_device.dev, "usart"); |
| 1093 | break; |
| 1094 | case 6: |
| 1095 | configure_dbgu_pins(); |
| 1096 | at91_uarts[i] = &at91sam9260_dbgu_device; |
| 1097 | at91_clock_associate("mck", &at91sam9260_dbgu_device.dev, "usart"); |
| 1098 | break; |
| 1099 | default: |
| 1100 | continue; |
| 1101 | } |
| 1102 | at91_uarts[i]->id = i; /* update ID number to mapped ID */ |
| 1103 | } |
| 1104 | |
| 1105 | /* Set serial console device */ |
| 1106 | if (config->console_tty < ATMEL_MAX_UART) |
| 1107 | atmel_default_console_device = at91_uarts[config->console_tty]; |
| 1108 | if (!atmel_default_console_device) |
| 1109 | printk(KERN_INFO "AT91: No default serial console defined.\n"); |
| 1110 | } |
| 1111 | |
Andrew Victor | c8f385a | 2008-01-23 09:25:15 +0100 | [diff] [blame] | 1112 | void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) |
| 1113 | { |
| 1114 | struct platform_device *pdev; |
| 1115 | |
| 1116 | switch (id) { |
| 1117 | case 0: /* DBGU */ |
| 1118 | pdev = &at91sam9260_dbgu_device; |
| 1119 | configure_dbgu_pins(); |
| 1120 | at91_clock_associate("mck", &pdev->dev, "usart"); |
| 1121 | break; |
| 1122 | case AT91SAM9260_ID_US0: |
| 1123 | pdev = &at91sam9260_uart0_device; |
| 1124 | configure_usart0_pins(pins); |
| 1125 | at91_clock_associate("usart0_clk", &pdev->dev, "usart"); |
| 1126 | break; |
| 1127 | case AT91SAM9260_ID_US1: |
| 1128 | pdev = &at91sam9260_uart1_device; |
| 1129 | configure_usart1_pins(pins); |
| 1130 | at91_clock_associate("usart1_clk", &pdev->dev, "usart"); |
| 1131 | break; |
| 1132 | case AT91SAM9260_ID_US2: |
| 1133 | pdev = &at91sam9260_uart2_device; |
| 1134 | configure_usart2_pins(pins); |
| 1135 | at91_clock_associate("usart2_clk", &pdev->dev, "usart"); |
| 1136 | break; |
| 1137 | case AT91SAM9260_ID_US3: |
| 1138 | pdev = &at91sam9260_uart3_device; |
| 1139 | configure_usart3_pins(pins); |
| 1140 | at91_clock_associate("usart3_clk", &pdev->dev, "usart"); |
| 1141 | break; |
| 1142 | case AT91SAM9260_ID_US4: |
| 1143 | pdev = &at91sam9260_uart4_device; |
| 1144 | configure_usart4_pins(); |
| 1145 | at91_clock_associate("usart4_clk", &pdev->dev, "usart"); |
| 1146 | break; |
| 1147 | case AT91SAM9260_ID_US5: |
| 1148 | pdev = &at91sam9260_uart5_device; |
| 1149 | configure_usart5_pins(); |
| 1150 | at91_clock_associate("usart5_clk", &pdev->dev, "usart"); |
| 1151 | break; |
| 1152 | default: |
| 1153 | return; |
| 1154 | } |
| 1155 | pdev->id = portnr; /* update to mapped ID */ |
| 1156 | |
| 1157 | if (portnr < ATMEL_MAX_UART) |
| 1158 | at91_uarts[portnr] = pdev; |
| 1159 | } |
| 1160 | |
| 1161 | void __init at91_set_serial_console(unsigned portnr) |
| 1162 | { |
| 1163 | if (portnr < ATMEL_MAX_UART) |
| 1164 | atmel_default_console_device = at91_uarts[portnr]; |
| 1165 | if (!atmel_default_console_device) |
| 1166 | printk(KERN_INFO "AT91: No default serial console defined.\n"); |
| 1167 | } |
| 1168 | |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 1169 | void __init at91_add_device_serial(void) |
| 1170 | { |
| 1171 | int i; |
| 1172 | |
| 1173 | for (i = 0; i < ATMEL_MAX_UART; i++) { |
| 1174 | if (at91_uarts[i]) |
| 1175 | platform_device_register(at91_uarts[i]); |
| 1176 | } |
| 1177 | } |
| 1178 | #else |
Andrew Victor | c8f385a | 2008-01-23 09:25:15 +0100 | [diff] [blame] | 1179 | void __init __deprecated at91_init_serial(struct at91_uart_config *config) {} |
| 1180 | void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {} |
| 1181 | void __init at91_set_serial_console(unsigned portnr) {} |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 1182 | void __init at91_add_device_serial(void) {} |
| 1183 | #endif |
| 1184 | |
| 1185 | |
| 1186 | /* -------------------------------------------------------------------- */ |
| 1187 | /* |
| 1188 | * These devices are always present and don't need any board-specific |
| 1189 | * setup. |
| 1190 | */ |
| 1191 | static int __init at91_add_standard_devices(void) |
| 1192 | { |
Andrew Victor | 884f5a6 | 2008-01-23 09:11:13 +0100 | [diff] [blame] | 1193 | at91_add_device_rtt(); |
| 1194 | at91_add_device_watchdog(); |
Andrew Victor | e5f40bf | 2008-04-02 21:58:00 +0100 | [diff] [blame^] | 1195 | at91_add_device_tc(); |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 1196 | return 0; |
| 1197 | } |
| 1198 | |
| 1199 | arch_initcall(at91_add_standard_devices); |