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 | |
| 15 | #include <linux/platform_device.h> |
Andrew Victor | f230d3f | 2007-11-19 13:47:20 +0100 | [diff] [blame] | 16 | #include <linux/i2c-gpio.h> |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 17 | |
| 18 | #include <asm/arch/board.h> |
| 19 | #include <asm/arch/gpio.h> |
| 20 | #include <asm/arch/at91sam9260.h> |
| 21 | #include <asm/arch/at91sam926x_mc.h> |
Andrew Victor | 8df1292 | 2006-12-08 11:30:29 +0100 | [diff] [blame] | 22 | #include <asm/arch/at91sam9260_matrix.h> |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 23 | |
| 24 | #include "generic.h" |
| 25 | |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 26 | |
| 27 | /* -------------------------------------------------------------------- |
| 28 | * USB Host |
| 29 | * -------------------------------------------------------------------- */ |
| 30 | |
| 31 | #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE) |
| 32 | static u64 ohci_dmamask = 0xffffffffUL; |
| 33 | static struct at91_usbh_data usbh_data; |
| 34 | |
| 35 | static struct resource usbh_resources[] = { |
| 36 | [0] = { |
| 37 | .start = AT91SAM9260_UHP_BASE, |
| 38 | .end = AT91SAM9260_UHP_BASE + SZ_1M - 1, |
| 39 | .flags = IORESOURCE_MEM, |
| 40 | }, |
| 41 | [1] = { |
| 42 | .start = AT91SAM9260_ID_UHP, |
| 43 | .end = AT91SAM9260_ID_UHP, |
| 44 | .flags = IORESOURCE_IRQ, |
| 45 | }, |
| 46 | }; |
| 47 | |
| 48 | static struct platform_device at91_usbh_device = { |
| 49 | .name = "at91_ohci", |
| 50 | .id = -1, |
| 51 | .dev = { |
| 52 | .dma_mask = &ohci_dmamask, |
| 53 | .coherent_dma_mask = 0xffffffff, |
| 54 | .platform_data = &usbh_data, |
| 55 | }, |
| 56 | .resource = usbh_resources, |
| 57 | .num_resources = ARRAY_SIZE(usbh_resources), |
| 58 | }; |
| 59 | |
| 60 | void __init at91_add_device_usbh(struct at91_usbh_data *data) |
| 61 | { |
| 62 | if (!data) |
| 63 | return; |
| 64 | |
| 65 | usbh_data = *data; |
| 66 | platform_device_register(&at91_usbh_device); |
| 67 | } |
| 68 | #else |
| 69 | void __init at91_add_device_usbh(struct at91_usbh_data *data) {} |
| 70 | #endif |
| 71 | |
| 72 | |
| 73 | /* -------------------------------------------------------------------- |
| 74 | * USB Device (Gadget) |
| 75 | * -------------------------------------------------------------------- */ |
| 76 | |
| 77 | #ifdef CONFIG_USB_GADGET_AT91 |
| 78 | static struct at91_udc_data udc_data; |
| 79 | |
| 80 | static struct resource udc_resources[] = { |
| 81 | [0] = { |
| 82 | .start = AT91SAM9260_BASE_UDP, |
| 83 | .end = AT91SAM9260_BASE_UDP + SZ_16K - 1, |
| 84 | .flags = IORESOURCE_MEM, |
| 85 | }, |
| 86 | [1] = { |
| 87 | .start = AT91SAM9260_ID_UDP, |
| 88 | .end = AT91SAM9260_ID_UDP, |
| 89 | .flags = IORESOURCE_IRQ, |
| 90 | }, |
| 91 | }; |
| 92 | |
| 93 | static struct platform_device at91_udc_device = { |
| 94 | .name = "at91_udc", |
| 95 | .id = -1, |
| 96 | .dev = { |
| 97 | .platform_data = &udc_data, |
| 98 | }, |
| 99 | .resource = udc_resources, |
| 100 | .num_resources = ARRAY_SIZE(udc_resources), |
| 101 | }; |
| 102 | |
| 103 | void __init at91_add_device_udc(struct at91_udc_data *data) |
| 104 | { |
| 105 | if (!data) |
| 106 | return; |
| 107 | |
| 108 | if (data->vbus_pin) { |
| 109 | at91_set_gpio_input(data->vbus_pin, 0); |
| 110 | at91_set_deglitch(data->vbus_pin, 1); |
| 111 | } |
| 112 | |
| 113 | /* Pullup pin is handled internally by USB device peripheral */ |
| 114 | |
| 115 | udc_data = *data; |
| 116 | platform_device_register(&at91_udc_device); |
| 117 | } |
| 118 | #else |
| 119 | void __init at91_add_device_udc(struct at91_udc_data *data) {} |
| 120 | #endif |
| 121 | |
| 122 | |
| 123 | /* -------------------------------------------------------------------- |
| 124 | * Ethernet |
| 125 | * -------------------------------------------------------------------- */ |
| 126 | |
| 127 | #if defined(CONFIG_MACB) || defined(CONFIG_MACB_MODULE) |
| 128 | static u64 eth_dmamask = 0xffffffffUL; |
Andrew Victor | a93d48c | 2007-02-01 09:22:23 +0100 | [diff] [blame] | 129 | static struct at91_eth_data eth_data; |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 130 | |
| 131 | static struct resource eth_resources[] = { |
| 132 | [0] = { |
| 133 | .start = AT91SAM9260_BASE_EMAC, |
| 134 | .end = AT91SAM9260_BASE_EMAC + SZ_16K - 1, |
| 135 | .flags = IORESOURCE_MEM, |
| 136 | }, |
| 137 | [1] = { |
| 138 | .start = AT91SAM9260_ID_EMAC, |
| 139 | .end = AT91SAM9260_ID_EMAC, |
| 140 | .flags = IORESOURCE_IRQ, |
| 141 | }, |
| 142 | }; |
| 143 | |
| 144 | static struct platform_device at91sam9260_eth_device = { |
| 145 | .name = "macb", |
| 146 | .id = -1, |
| 147 | .dev = { |
| 148 | .dma_mask = ð_dmamask, |
| 149 | .coherent_dma_mask = 0xffffffff, |
| 150 | .platform_data = ð_data, |
| 151 | }, |
| 152 | .resource = eth_resources, |
| 153 | .num_resources = ARRAY_SIZE(eth_resources), |
| 154 | }; |
| 155 | |
Andrew Victor | a93d48c | 2007-02-01 09:22:23 +0100 | [diff] [blame] | 156 | void __init at91_add_device_eth(struct at91_eth_data *data) |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 157 | { |
| 158 | if (!data) |
| 159 | return; |
| 160 | |
| 161 | if (data->phy_irq_pin) { |
| 162 | at91_set_gpio_input(data->phy_irq_pin, 0); |
| 163 | at91_set_deglitch(data->phy_irq_pin, 1); |
| 164 | } |
| 165 | |
| 166 | /* Pins used for MII and RMII */ |
| 167 | at91_set_A_periph(AT91_PIN_PA19, 0); /* ETXCK_EREFCK */ |
| 168 | at91_set_A_periph(AT91_PIN_PA17, 0); /* ERXDV */ |
| 169 | at91_set_A_periph(AT91_PIN_PA14, 0); /* ERX0 */ |
| 170 | at91_set_A_periph(AT91_PIN_PA15, 0); /* ERX1 */ |
| 171 | at91_set_A_periph(AT91_PIN_PA18, 0); /* ERXER */ |
| 172 | at91_set_A_periph(AT91_PIN_PA16, 0); /* ETXEN */ |
| 173 | at91_set_A_periph(AT91_PIN_PA12, 0); /* ETX0 */ |
| 174 | at91_set_A_periph(AT91_PIN_PA13, 0); /* ETX1 */ |
| 175 | at91_set_A_periph(AT91_PIN_PA21, 0); /* EMDIO */ |
| 176 | at91_set_A_periph(AT91_PIN_PA20, 0); /* EMDC */ |
| 177 | |
| 178 | if (!data->is_rmii) { |
| 179 | at91_set_B_periph(AT91_PIN_PA28, 0); /* ECRS */ |
| 180 | at91_set_B_periph(AT91_PIN_PA29, 0); /* ECOL */ |
| 181 | at91_set_B_periph(AT91_PIN_PA25, 0); /* ERX2 */ |
| 182 | at91_set_B_periph(AT91_PIN_PA26, 0); /* ERX3 */ |
| 183 | at91_set_B_periph(AT91_PIN_PA27, 0); /* ERXCK */ |
| 184 | at91_set_B_periph(AT91_PIN_PA23, 0); /* ETX2 */ |
| 185 | at91_set_B_periph(AT91_PIN_PA24, 0); /* ETX3 */ |
| 186 | at91_set_B_periph(AT91_PIN_PA22, 0); /* ETXER */ |
| 187 | } |
| 188 | |
| 189 | eth_data = *data; |
| 190 | platform_device_register(&at91sam9260_eth_device); |
| 191 | } |
| 192 | #else |
Andrew Victor | a93d48c | 2007-02-01 09:22:23 +0100 | [diff] [blame] | 193 | void __init at91_add_device_eth(struct at91_eth_data *data) {} |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 194 | #endif |
| 195 | |
| 196 | |
| 197 | /* -------------------------------------------------------------------- |
| 198 | * MMC / SD |
| 199 | * -------------------------------------------------------------------- */ |
| 200 | |
| 201 | #if defined(CONFIG_MMC_AT91) || defined(CONFIG_MMC_AT91_MODULE) |
| 202 | static u64 mmc_dmamask = 0xffffffffUL; |
| 203 | static struct at91_mmc_data mmc_data; |
| 204 | |
| 205 | static struct resource mmc_resources[] = { |
| 206 | [0] = { |
| 207 | .start = AT91SAM9260_BASE_MCI, |
| 208 | .end = AT91SAM9260_BASE_MCI + SZ_16K - 1, |
| 209 | .flags = IORESOURCE_MEM, |
| 210 | }, |
| 211 | [1] = { |
| 212 | .start = AT91SAM9260_ID_MCI, |
| 213 | .end = AT91SAM9260_ID_MCI, |
| 214 | .flags = IORESOURCE_IRQ, |
| 215 | }, |
| 216 | }; |
| 217 | |
| 218 | static struct platform_device at91sam9260_mmc_device = { |
| 219 | .name = "at91_mci", |
| 220 | .id = -1, |
| 221 | .dev = { |
| 222 | .dma_mask = &mmc_dmamask, |
| 223 | .coherent_dma_mask = 0xffffffff, |
| 224 | .platform_data = &mmc_data, |
| 225 | }, |
| 226 | .resource = mmc_resources, |
| 227 | .num_resources = ARRAY_SIZE(mmc_resources), |
| 228 | }; |
| 229 | |
Andrew Victor | d0760b3 | 2007-02-08 09:00:39 +0100 | [diff] [blame] | 230 | 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] | 231 | { |
| 232 | if (!data) |
| 233 | return; |
| 234 | |
| 235 | /* input/irq */ |
| 236 | if (data->det_pin) { |
| 237 | at91_set_gpio_input(data->det_pin, 1); |
| 238 | at91_set_deglitch(data->det_pin, 1); |
| 239 | } |
| 240 | if (data->wp_pin) |
| 241 | at91_set_gpio_input(data->wp_pin, 1); |
| 242 | if (data->vcc_pin) |
| 243 | at91_set_gpio_output(data->vcc_pin, 0); |
| 244 | |
| 245 | /* CLK */ |
| 246 | at91_set_A_periph(AT91_PIN_PA8, 0); |
| 247 | |
| 248 | if (data->slot_b) { |
| 249 | /* CMD */ |
| 250 | at91_set_B_periph(AT91_PIN_PA1, 1); |
| 251 | |
| 252 | /* DAT0, maybe DAT1..DAT3 */ |
| 253 | at91_set_B_periph(AT91_PIN_PA0, 1); |
| 254 | if (data->wire4) { |
| 255 | at91_set_B_periph(AT91_PIN_PA5, 1); |
| 256 | at91_set_B_periph(AT91_PIN_PA4, 1); |
| 257 | at91_set_B_periph(AT91_PIN_PA3, 1); |
| 258 | } |
| 259 | } else { |
| 260 | /* CMD */ |
| 261 | at91_set_A_periph(AT91_PIN_PA7, 1); |
| 262 | |
| 263 | /* DAT0, maybe DAT1..DAT3 */ |
| 264 | at91_set_A_periph(AT91_PIN_PA6, 1); |
| 265 | if (data->wire4) { |
| 266 | at91_set_A_periph(AT91_PIN_PA9, 1); |
| 267 | at91_set_A_periph(AT91_PIN_PA10, 1); |
| 268 | at91_set_A_periph(AT91_PIN_PA11, 1); |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | mmc_data = *data; |
| 273 | platform_device_register(&at91sam9260_mmc_device); |
| 274 | } |
| 275 | #else |
Andrew Victor | d0760b3 | 2007-02-08 09:00:39 +0100 | [diff] [blame] | 276 | 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] | 277 | #endif |
| 278 | |
| 279 | |
| 280 | /* -------------------------------------------------------------------- |
| 281 | * NAND / SmartMedia |
| 282 | * -------------------------------------------------------------------- */ |
| 283 | |
| 284 | #if defined(CONFIG_MTD_NAND_AT91) || defined(CONFIG_MTD_NAND_AT91_MODULE) |
| 285 | static struct at91_nand_data nand_data; |
| 286 | |
| 287 | #define NAND_BASE AT91_CHIPSELECT_3 |
| 288 | |
| 289 | static struct resource nand_resources[] = { |
| 290 | { |
| 291 | .start = NAND_BASE, |
| 292 | .end = NAND_BASE + SZ_8M - 1, |
| 293 | .flags = IORESOURCE_MEM, |
| 294 | } |
| 295 | }; |
| 296 | |
| 297 | static struct platform_device at91sam9260_nand_device = { |
| 298 | .name = "at91_nand", |
| 299 | .id = -1, |
| 300 | .dev = { |
| 301 | .platform_data = &nand_data, |
| 302 | }, |
| 303 | .resource = nand_resources, |
| 304 | .num_resources = ARRAY_SIZE(nand_resources), |
| 305 | }; |
| 306 | |
| 307 | void __init at91_add_device_nand(struct at91_nand_data *data) |
| 308 | { |
| 309 | unsigned long csa, mode; |
| 310 | |
| 311 | if (!data) |
| 312 | return; |
| 313 | |
| 314 | csa = at91_sys_read(AT91_MATRIX_EBICSA); |
| 315 | at91_sys_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_CS3A_SMC); |
| 316 | |
| 317 | /* set the bus interface characteristics */ |
| 318 | at91_sys_write(AT91_SMC_SETUP(3), AT91_SMC_NWESETUP_(0) | AT91_SMC_NCS_WRSETUP_(0) |
| 319 | | AT91_SMC_NRDSETUP_(0) | AT91_SMC_NCS_RDSETUP_(0)); |
| 320 | |
Andrew Victor | 2848e64 | 2007-03-26 11:02:48 +0100 | [diff] [blame] | 321 | at91_sys_write(AT91_SMC_PULSE(3), AT91_SMC_NWEPULSE_(3) | AT91_SMC_NCS_WRPULSE_(3) |
| 322 | | AT91_SMC_NRDPULSE_(3) | AT91_SMC_NCS_RDPULSE_(3)); |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 323 | |
Andrew Victor | 2848e64 | 2007-03-26 11:02:48 +0100 | [diff] [blame] | 324 | 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] | 325 | |
| 326 | if (data->bus_width_16) |
| 327 | mode = AT91_SMC_DBW_16; |
| 328 | else |
| 329 | mode = AT91_SMC_DBW_8; |
Andrew Victor | 2848e64 | 2007-03-26 11:02:48 +0100 | [diff] [blame] | 330 | 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] | 331 | |
| 332 | /* enable pin */ |
| 333 | if (data->enable_pin) |
| 334 | at91_set_gpio_output(data->enable_pin, 1); |
| 335 | |
| 336 | /* ready/busy pin */ |
| 337 | if (data->rdy_pin) |
| 338 | at91_set_gpio_input(data->rdy_pin, 1); |
| 339 | |
| 340 | /* card detect pin */ |
| 341 | if (data->det_pin) |
| 342 | at91_set_gpio_input(data->det_pin, 1); |
| 343 | |
| 344 | nand_data = *data; |
| 345 | platform_device_register(&at91sam9260_nand_device); |
| 346 | } |
| 347 | #else |
| 348 | void __init at91_add_device_nand(struct at91_nand_data *data) {} |
| 349 | #endif |
| 350 | |
| 351 | |
| 352 | /* -------------------------------------------------------------------- |
| 353 | * TWI (i2c) |
| 354 | * -------------------------------------------------------------------- */ |
| 355 | |
Andrew Victor | f230d3f | 2007-11-19 13:47:20 +0100 | [diff] [blame] | 356 | /* |
| 357 | * Prefer the GPIO code since the TWI controller isn't robust |
| 358 | * (gets overruns and underruns under load) and can only issue |
| 359 | * repeated STARTs in one scenario (the driver doesn't yet handle them). |
| 360 | */ |
| 361 | |
| 362 | #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE) |
| 363 | |
| 364 | static struct i2c_gpio_platform_data pdata = { |
| 365 | .sda_pin = AT91_PIN_PA23, |
| 366 | .sda_is_open_drain = 1, |
| 367 | .scl_pin = AT91_PIN_PA24, |
| 368 | .scl_is_open_drain = 1, |
| 369 | .udelay = 2, /* ~100 kHz */ |
| 370 | }; |
| 371 | |
| 372 | static struct platform_device at91sam9260_twi_device = { |
| 373 | .name = "i2c-gpio", |
| 374 | .id = -1, |
| 375 | .dev.platform_data = &pdata, |
| 376 | }; |
| 377 | |
| 378 | void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) |
| 379 | { |
| 380 | at91_set_GPIO_periph(AT91_PIN_PA23, 1); /* TWD (SDA) */ |
| 381 | at91_set_multi_drive(AT91_PIN_PA23, 1); |
| 382 | |
| 383 | at91_set_GPIO_periph(AT91_PIN_PA24, 1); /* TWCK (SCL) */ |
| 384 | at91_set_multi_drive(AT91_PIN_PA24, 1); |
| 385 | |
| 386 | i2c_register_board_info(0, devices, nr_devices); |
| 387 | platform_device_register(&at91sam9260_twi_device); |
| 388 | } |
| 389 | |
| 390 | #elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE) |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 391 | |
| 392 | static struct resource twi_resources[] = { |
| 393 | [0] = { |
| 394 | .start = AT91SAM9260_BASE_TWI, |
| 395 | .end = AT91SAM9260_BASE_TWI + SZ_16K - 1, |
| 396 | .flags = IORESOURCE_MEM, |
| 397 | }, |
| 398 | [1] = { |
| 399 | .start = AT91SAM9260_ID_TWI, |
| 400 | .end = AT91SAM9260_ID_TWI, |
| 401 | .flags = IORESOURCE_IRQ, |
| 402 | }, |
| 403 | }; |
| 404 | |
| 405 | static struct platform_device at91sam9260_twi_device = { |
| 406 | .name = "at91_i2c", |
| 407 | .id = -1, |
| 408 | .resource = twi_resources, |
| 409 | .num_resources = ARRAY_SIZE(twi_resources), |
| 410 | }; |
| 411 | |
Andrew Victor | f230d3f | 2007-11-19 13:47:20 +0100 | [diff] [blame] | 412 | 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] | 413 | { |
| 414 | /* pins used for TWI interface */ |
| 415 | at91_set_A_periph(AT91_PIN_PA23, 0); /* TWD */ |
| 416 | at91_set_multi_drive(AT91_PIN_PA23, 1); |
| 417 | |
| 418 | at91_set_A_periph(AT91_PIN_PA24, 0); /* TWCK */ |
| 419 | at91_set_multi_drive(AT91_PIN_PA24, 1); |
| 420 | |
Andrew Victor | f230d3f | 2007-11-19 13:47:20 +0100 | [diff] [blame] | 421 | i2c_register_board_info(0, devices, nr_devices); |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 422 | platform_device_register(&at91sam9260_twi_device); |
| 423 | } |
| 424 | #else |
Andrew Victor | f230d3f | 2007-11-19 13:47:20 +0100 | [diff] [blame] | 425 | 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] | 426 | #endif |
| 427 | |
| 428 | |
| 429 | /* -------------------------------------------------------------------- |
| 430 | * SPI |
| 431 | * -------------------------------------------------------------------- */ |
| 432 | |
| 433 | #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE) |
| 434 | static u64 spi_dmamask = 0xffffffffUL; |
| 435 | |
| 436 | static struct resource spi0_resources[] = { |
| 437 | [0] = { |
| 438 | .start = AT91SAM9260_BASE_SPI0, |
| 439 | .end = AT91SAM9260_BASE_SPI0 + SZ_16K - 1, |
| 440 | .flags = IORESOURCE_MEM, |
| 441 | }, |
| 442 | [1] = { |
| 443 | .start = AT91SAM9260_ID_SPI0, |
| 444 | .end = AT91SAM9260_ID_SPI0, |
| 445 | .flags = IORESOURCE_IRQ, |
| 446 | }, |
| 447 | }; |
| 448 | |
| 449 | static struct platform_device at91sam9260_spi0_device = { |
| 450 | .name = "atmel_spi", |
| 451 | .id = 0, |
| 452 | .dev = { |
| 453 | .dma_mask = &spi_dmamask, |
| 454 | .coherent_dma_mask = 0xffffffff, |
| 455 | }, |
| 456 | .resource = spi0_resources, |
| 457 | .num_resources = ARRAY_SIZE(spi0_resources), |
| 458 | }; |
| 459 | |
| 460 | static const unsigned spi0_standard_cs[4] = { AT91_PIN_PA3, AT91_PIN_PC11, AT91_PIN_PC16, AT91_PIN_PC17 }; |
| 461 | |
| 462 | static struct resource spi1_resources[] = { |
| 463 | [0] = { |
| 464 | .start = AT91SAM9260_BASE_SPI1, |
| 465 | .end = AT91SAM9260_BASE_SPI1 + SZ_16K - 1, |
| 466 | .flags = IORESOURCE_MEM, |
| 467 | }, |
| 468 | [1] = { |
| 469 | .start = AT91SAM9260_ID_SPI1, |
| 470 | .end = AT91SAM9260_ID_SPI1, |
| 471 | .flags = IORESOURCE_IRQ, |
| 472 | }, |
| 473 | }; |
| 474 | |
| 475 | static struct platform_device at91sam9260_spi1_device = { |
| 476 | .name = "atmel_spi", |
| 477 | .id = 1, |
| 478 | .dev = { |
| 479 | .dma_mask = &spi_dmamask, |
| 480 | .coherent_dma_mask = 0xffffffff, |
| 481 | }, |
| 482 | .resource = spi1_resources, |
| 483 | .num_resources = ARRAY_SIZE(spi1_resources), |
| 484 | }; |
| 485 | |
| 486 | static const unsigned spi1_standard_cs[4] = { AT91_PIN_PB3, AT91_PIN_PC5, AT91_PIN_PC4, AT91_PIN_PC3 }; |
| 487 | |
| 488 | void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) |
| 489 | { |
| 490 | int i; |
| 491 | unsigned long cs_pin; |
| 492 | short enable_spi0 = 0; |
| 493 | short enable_spi1 = 0; |
| 494 | |
| 495 | /* Choose SPI chip-selects */ |
| 496 | for (i = 0; i < nr_devices; i++) { |
| 497 | if (devices[i].controller_data) |
| 498 | cs_pin = (unsigned long) devices[i].controller_data; |
| 499 | else if (devices[i].bus_num == 0) |
| 500 | cs_pin = spi0_standard_cs[devices[i].chip_select]; |
| 501 | else |
| 502 | cs_pin = spi1_standard_cs[devices[i].chip_select]; |
| 503 | |
| 504 | if (devices[i].bus_num == 0) |
| 505 | enable_spi0 = 1; |
| 506 | else |
| 507 | enable_spi1 = 1; |
| 508 | |
| 509 | /* enable chip-select pin */ |
| 510 | at91_set_gpio_output(cs_pin, 1); |
| 511 | |
| 512 | /* pass chip-select pin to driver */ |
| 513 | devices[i].controller_data = (void *) cs_pin; |
| 514 | } |
| 515 | |
| 516 | spi_register_board_info(devices, nr_devices); |
| 517 | |
| 518 | /* Configure SPI bus(es) */ |
| 519 | if (enable_spi0) { |
| 520 | at91_set_A_periph(AT91_PIN_PA0, 0); /* SPI0_MISO */ |
| 521 | at91_set_A_periph(AT91_PIN_PA1, 0); /* SPI0_MOSI */ |
| 522 | at91_set_A_periph(AT91_PIN_PA2, 0); /* SPI1_SPCK */ |
| 523 | |
| 524 | at91_clock_associate("spi0_clk", &at91sam9260_spi0_device.dev, "spi_clk"); |
| 525 | platform_device_register(&at91sam9260_spi0_device); |
| 526 | } |
| 527 | if (enable_spi1) { |
| 528 | at91_set_A_periph(AT91_PIN_PB0, 0); /* SPI1_MISO */ |
| 529 | at91_set_A_periph(AT91_PIN_PB1, 0); /* SPI1_MOSI */ |
| 530 | at91_set_A_periph(AT91_PIN_PB2, 0); /* SPI1_SPCK */ |
| 531 | |
| 532 | at91_clock_associate("spi1_clk", &at91sam9260_spi1_device.dev, "spi_clk"); |
| 533 | platform_device_register(&at91sam9260_spi1_device); |
| 534 | } |
| 535 | } |
| 536 | #else |
| 537 | void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {} |
| 538 | #endif |
| 539 | |
| 540 | |
| 541 | /* -------------------------------------------------------------------- |
Andrew Victor | 884f5a6 | 2008-01-23 09:11:13 +0100 | [diff] [blame^] | 542 | * RTT |
| 543 | * -------------------------------------------------------------------- */ |
| 544 | |
| 545 | static struct resource rtt_resources[] = { |
| 546 | { |
| 547 | .start = AT91_BASE_SYS + AT91_RTT, |
| 548 | .end = AT91_BASE_SYS + AT91_RTT + SZ_16 - 1, |
| 549 | .flags = IORESOURCE_MEM, |
| 550 | } |
| 551 | }; |
| 552 | |
| 553 | static struct platform_device at91sam9260_rtt_device = { |
| 554 | .name = "at91_rtt", |
| 555 | .id = -1, |
| 556 | .resource = rtt_resources, |
| 557 | .num_resources = ARRAY_SIZE(rtt_resources), |
| 558 | }; |
| 559 | |
| 560 | static void __init at91_add_device_rtt(void) |
| 561 | { |
| 562 | platform_device_register(&at91sam9260_rtt_device); |
| 563 | } |
| 564 | |
| 565 | |
| 566 | /* -------------------------------------------------------------------- |
| 567 | * Watchdog |
| 568 | * -------------------------------------------------------------------- */ |
| 569 | |
| 570 | #if defined(CONFIG_AT91SAM9_WATCHDOG) || defined(CONFIG_AT91SAM9_WATCHDOG_MODULE) |
| 571 | static struct platform_device at91sam9260_wdt_device = { |
| 572 | .name = "at91_wdt", |
| 573 | .id = -1, |
| 574 | .num_resources = 0, |
| 575 | }; |
| 576 | |
| 577 | static void __init at91_add_device_watchdog(void) |
| 578 | { |
| 579 | platform_device_register(&at91sam9260_wdt_device); |
| 580 | } |
| 581 | #else |
| 582 | static void __init at91_add_device_watchdog(void) {} |
| 583 | #endif |
| 584 | |
| 585 | |
| 586 | /* -------------------------------------------------------------------- |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 587 | * LEDs |
| 588 | * -------------------------------------------------------------------- */ |
| 589 | |
| 590 | #if defined(CONFIG_LEDS) |
| 591 | u8 at91_leds_cpu; |
| 592 | u8 at91_leds_timer; |
| 593 | |
| 594 | void __init at91_init_leds(u8 cpu_led, u8 timer_led) |
| 595 | { |
Andrew Victor | da11d02 | 2007-02-08 11:18:14 +0100 | [diff] [blame] | 596 | /* Enable GPIO to access the LEDs */ |
| 597 | at91_set_gpio_output(cpu_led, 1); |
| 598 | at91_set_gpio_output(timer_led, 1); |
| 599 | |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 600 | at91_leds_cpu = cpu_led; |
| 601 | at91_leds_timer = timer_led; |
| 602 | } |
| 603 | #else |
| 604 | void __init at91_init_leds(u8 cpu_led, u8 timer_led) {} |
| 605 | #endif |
| 606 | |
| 607 | |
| 608 | /* -------------------------------------------------------------------- |
| 609 | * UART |
| 610 | * -------------------------------------------------------------------- */ |
| 611 | #if defined(CONFIG_SERIAL_ATMEL) |
| 612 | static struct resource dbgu_resources[] = { |
| 613 | [0] = { |
| 614 | .start = AT91_VA_BASE_SYS + AT91_DBGU, |
| 615 | .end = AT91_VA_BASE_SYS + AT91_DBGU + SZ_512 - 1, |
| 616 | .flags = IORESOURCE_MEM, |
| 617 | }, |
| 618 | [1] = { |
| 619 | .start = AT91_ID_SYS, |
| 620 | .end = AT91_ID_SYS, |
| 621 | .flags = IORESOURCE_IRQ, |
| 622 | }, |
| 623 | }; |
| 624 | |
| 625 | static struct atmel_uart_data dbgu_data = { |
| 626 | .use_dma_tx = 0, |
| 627 | .use_dma_rx = 0, /* DBGU not capable of receive DMA */ |
| 628 | .regs = (void __iomem *)(AT91_VA_BASE_SYS + AT91_DBGU), |
| 629 | }; |
| 630 | |
| 631 | static struct platform_device at91sam9260_dbgu_device = { |
| 632 | .name = "atmel_usart", |
| 633 | .id = 0, |
| 634 | .dev = { |
| 635 | .platform_data = &dbgu_data, |
| 636 | .coherent_dma_mask = 0xffffffff, |
| 637 | }, |
| 638 | .resource = dbgu_resources, |
| 639 | .num_resources = ARRAY_SIZE(dbgu_resources), |
| 640 | }; |
| 641 | |
| 642 | static inline void configure_dbgu_pins(void) |
| 643 | { |
| 644 | at91_set_A_periph(AT91_PIN_PB14, 0); /* DRXD */ |
| 645 | at91_set_A_periph(AT91_PIN_PB15, 1); /* DTXD */ |
| 646 | } |
| 647 | |
| 648 | static struct resource uart0_resources[] = { |
| 649 | [0] = { |
| 650 | .start = AT91SAM9260_BASE_US0, |
| 651 | .end = AT91SAM9260_BASE_US0 + SZ_16K - 1, |
| 652 | .flags = IORESOURCE_MEM, |
| 653 | }, |
| 654 | [1] = { |
| 655 | .start = AT91SAM9260_ID_US0, |
| 656 | .end = AT91SAM9260_ID_US0, |
| 657 | .flags = IORESOURCE_IRQ, |
| 658 | }, |
| 659 | }; |
| 660 | |
| 661 | static struct atmel_uart_data uart0_data = { |
| 662 | .use_dma_tx = 1, |
| 663 | .use_dma_rx = 1, |
| 664 | }; |
| 665 | |
| 666 | static struct platform_device at91sam9260_uart0_device = { |
| 667 | .name = "atmel_usart", |
| 668 | .id = 1, |
| 669 | .dev = { |
| 670 | .platform_data = &uart0_data, |
| 671 | .coherent_dma_mask = 0xffffffff, |
| 672 | }, |
| 673 | .resource = uart0_resources, |
| 674 | .num_resources = ARRAY_SIZE(uart0_resources), |
| 675 | }; |
| 676 | |
| 677 | static inline void configure_usart0_pins(void) |
| 678 | { |
| 679 | at91_set_A_periph(AT91_PIN_PB4, 1); /* TXD0 */ |
| 680 | at91_set_A_periph(AT91_PIN_PB5, 0); /* RXD0 */ |
| 681 | at91_set_A_periph(AT91_PIN_PB26, 0); /* RTS0 */ |
| 682 | at91_set_A_periph(AT91_PIN_PB27, 0); /* CTS0 */ |
| 683 | at91_set_A_periph(AT91_PIN_PB24, 0); /* DTR0 */ |
| 684 | at91_set_A_periph(AT91_PIN_PB22, 0); /* DSR0 */ |
| 685 | at91_set_A_periph(AT91_PIN_PB23, 0); /* DCD0 */ |
| 686 | at91_set_A_periph(AT91_PIN_PB25, 0); /* RI0 */ |
| 687 | } |
| 688 | |
| 689 | static struct resource uart1_resources[] = { |
| 690 | [0] = { |
| 691 | .start = AT91SAM9260_BASE_US1, |
| 692 | .end = AT91SAM9260_BASE_US1 + SZ_16K - 1, |
| 693 | .flags = IORESOURCE_MEM, |
| 694 | }, |
| 695 | [1] = { |
| 696 | .start = AT91SAM9260_ID_US1, |
| 697 | .end = AT91SAM9260_ID_US1, |
| 698 | .flags = IORESOURCE_IRQ, |
| 699 | }, |
| 700 | }; |
| 701 | |
| 702 | static struct atmel_uart_data uart1_data = { |
| 703 | .use_dma_tx = 1, |
| 704 | .use_dma_rx = 1, |
| 705 | }; |
| 706 | |
| 707 | static struct platform_device at91sam9260_uart1_device = { |
| 708 | .name = "atmel_usart", |
| 709 | .id = 2, |
| 710 | .dev = { |
| 711 | .platform_data = &uart1_data, |
| 712 | .coherent_dma_mask = 0xffffffff, |
| 713 | }, |
| 714 | .resource = uart1_resources, |
| 715 | .num_resources = ARRAY_SIZE(uart1_resources), |
| 716 | }; |
| 717 | |
| 718 | static inline void configure_usart1_pins(void) |
| 719 | { |
| 720 | at91_set_A_periph(AT91_PIN_PB6, 1); /* TXD1 */ |
| 721 | at91_set_A_periph(AT91_PIN_PB7, 0); /* RXD1 */ |
| 722 | at91_set_A_periph(AT91_PIN_PB28, 0); /* RTS1 */ |
| 723 | at91_set_A_periph(AT91_PIN_PB29, 0); /* CTS1 */ |
| 724 | } |
| 725 | |
| 726 | static struct resource uart2_resources[] = { |
| 727 | [0] = { |
| 728 | .start = AT91SAM9260_BASE_US2, |
| 729 | .end = AT91SAM9260_BASE_US2 + SZ_16K - 1, |
| 730 | .flags = IORESOURCE_MEM, |
| 731 | }, |
| 732 | [1] = { |
| 733 | .start = AT91SAM9260_ID_US2, |
| 734 | .end = AT91SAM9260_ID_US2, |
| 735 | .flags = IORESOURCE_IRQ, |
| 736 | }, |
| 737 | }; |
| 738 | |
| 739 | static struct atmel_uart_data uart2_data = { |
| 740 | .use_dma_tx = 1, |
| 741 | .use_dma_rx = 1, |
| 742 | }; |
| 743 | |
| 744 | static struct platform_device at91sam9260_uart2_device = { |
| 745 | .name = "atmel_usart", |
| 746 | .id = 3, |
| 747 | .dev = { |
| 748 | .platform_data = &uart2_data, |
| 749 | .coherent_dma_mask = 0xffffffff, |
| 750 | }, |
| 751 | .resource = uart2_resources, |
| 752 | .num_resources = ARRAY_SIZE(uart2_resources), |
| 753 | }; |
| 754 | |
| 755 | static inline void configure_usart2_pins(void) |
| 756 | { |
| 757 | at91_set_A_periph(AT91_PIN_PB8, 1); /* TXD2 */ |
| 758 | at91_set_A_periph(AT91_PIN_PB9, 0); /* RXD2 */ |
| 759 | } |
| 760 | |
| 761 | static struct resource uart3_resources[] = { |
| 762 | [0] = { |
| 763 | .start = AT91SAM9260_BASE_US3, |
| 764 | .end = AT91SAM9260_BASE_US3 + SZ_16K - 1, |
| 765 | .flags = IORESOURCE_MEM, |
| 766 | }, |
| 767 | [1] = { |
| 768 | .start = AT91SAM9260_ID_US3, |
| 769 | .end = AT91SAM9260_ID_US3, |
| 770 | .flags = IORESOURCE_IRQ, |
| 771 | }, |
| 772 | }; |
| 773 | |
| 774 | static struct atmel_uart_data uart3_data = { |
| 775 | .use_dma_tx = 1, |
| 776 | .use_dma_rx = 1, |
| 777 | }; |
| 778 | |
| 779 | static struct platform_device at91sam9260_uart3_device = { |
| 780 | .name = "atmel_usart", |
| 781 | .id = 4, |
| 782 | .dev = { |
| 783 | .platform_data = &uart3_data, |
| 784 | .coherent_dma_mask = 0xffffffff, |
| 785 | }, |
| 786 | .resource = uart3_resources, |
| 787 | .num_resources = ARRAY_SIZE(uart3_resources), |
| 788 | }; |
| 789 | |
| 790 | static inline void configure_usart3_pins(void) |
| 791 | { |
| 792 | at91_set_A_periph(AT91_PIN_PB10, 1); /* TXD3 */ |
| 793 | at91_set_A_periph(AT91_PIN_PB11, 0); /* RXD3 */ |
| 794 | } |
| 795 | |
| 796 | static struct resource uart4_resources[] = { |
| 797 | [0] = { |
| 798 | .start = AT91SAM9260_BASE_US4, |
| 799 | .end = AT91SAM9260_BASE_US4 + SZ_16K - 1, |
| 800 | .flags = IORESOURCE_MEM, |
| 801 | }, |
| 802 | [1] = { |
| 803 | .start = AT91SAM9260_ID_US4, |
| 804 | .end = AT91SAM9260_ID_US4, |
| 805 | .flags = IORESOURCE_IRQ, |
| 806 | }, |
| 807 | }; |
| 808 | |
| 809 | static struct atmel_uart_data uart4_data = { |
| 810 | .use_dma_tx = 1, |
| 811 | .use_dma_rx = 1, |
| 812 | }; |
| 813 | |
| 814 | static struct platform_device at91sam9260_uart4_device = { |
| 815 | .name = "atmel_usart", |
| 816 | .id = 5, |
| 817 | .dev = { |
| 818 | .platform_data = &uart4_data, |
| 819 | .coherent_dma_mask = 0xffffffff, |
| 820 | }, |
| 821 | .resource = uart4_resources, |
| 822 | .num_resources = ARRAY_SIZE(uart4_resources), |
| 823 | }; |
| 824 | |
| 825 | static inline void configure_usart4_pins(void) |
| 826 | { |
| 827 | at91_set_B_periph(AT91_PIN_PA31, 1); /* TXD4 */ |
| 828 | at91_set_B_periph(AT91_PIN_PA30, 0); /* RXD4 */ |
| 829 | } |
| 830 | |
| 831 | static struct resource uart5_resources[] = { |
| 832 | [0] = { |
| 833 | .start = AT91SAM9260_BASE_US5, |
| 834 | .end = AT91SAM9260_BASE_US5 + SZ_16K - 1, |
| 835 | .flags = IORESOURCE_MEM, |
| 836 | }, |
| 837 | [1] = { |
| 838 | .start = AT91SAM9260_ID_US5, |
| 839 | .end = AT91SAM9260_ID_US5, |
| 840 | .flags = IORESOURCE_IRQ, |
| 841 | }, |
| 842 | }; |
| 843 | |
| 844 | static struct atmel_uart_data uart5_data = { |
| 845 | .use_dma_tx = 1, |
| 846 | .use_dma_rx = 1, |
| 847 | }; |
| 848 | |
| 849 | static struct platform_device at91sam9260_uart5_device = { |
| 850 | .name = "atmel_usart", |
| 851 | .id = 6, |
| 852 | .dev = { |
| 853 | .platform_data = &uart5_data, |
| 854 | .coherent_dma_mask = 0xffffffff, |
| 855 | }, |
| 856 | .resource = uart5_resources, |
| 857 | .num_resources = ARRAY_SIZE(uart5_resources), |
| 858 | }; |
| 859 | |
| 860 | static inline void configure_usart5_pins(void) |
| 861 | { |
| 862 | at91_set_A_periph(AT91_PIN_PB12, 1); /* TXD5 */ |
| 863 | at91_set_A_periph(AT91_PIN_PB13, 0); /* RXD5 */ |
| 864 | } |
| 865 | |
| 866 | struct platform_device *at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */ |
| 867 | struct platform_device *atmel_default_console_device; /* the serial console device */ |
| 868 | |
| 869 | void __init at91_init_serial(struct at91_uart_config *config) |
| 870 | { |
| 871 | int i; |
| 872 | |
| 873 | /* Fill in list of supported UARTs */ |
| 874 | for (i = 0; i < config->nr_tty; i++) { |
| 875 | switch (config->tty_map[i]) { |
| 876 | case 0: |
| 877 | configure_usart0_pins(); |
| 878 | at91_uarts[i] = &at91sam9260_uart0_device; |
| 879 | at91_clock_associate("usart0_clk", &at91sam9260_uart0_device.dev, "usart"); |
| 880 | break; |
| 881 | case 1: |
| 882 | configure_usart1_pins(); |
| 883 | at91_uarts[i] = &at91sam9260_uart1_device; |
| 884 | at91_clock_associate("usart1_clk", &at91sam9260_uart1_device.dev, "usart"); |
| 885 | break; |
| 886 | case 2: |
| 887 | configure_usart2_pins(); |
| 888 | at91_uarts[i] = &at91sam9260_uart2_device; |
| 889 | at91_clock_associate("usart2_clk", &at91sam9260_uart2_device.dev, "usart"); |
| 890 | break; |
| 891 | case 3: |
| 892 | configure_usart3_pins(); |
| 893 | at91_uarts[i] = &at91sam9260_uart3_device; |
| 894 | at91_clock_associate("usart3_clk", &at91sam9260_uart3_device.dev, "usart"); |
| 895 | break; |
| 896 | case 4: |
| 897 | configure_usart4_pins(); |
| 898 | at91_uarts[i] = &at91sam9260_uart4_device; |
| 899 | at91_clock_associate("usart4_clk", &at91sam9260_uart4_device.dev, "usart"); |
| 900 | break; |
| 901 | case 5: |
| 902 | configure_usart5_pins(); |
| 903 | at91_uarts[i] = &at91sam9260_uart5_device; |
| 904 | at91_clock_associate("usart5_clk", &at91sam9260_uart5_device.dev, "usart"); |
| 905 | break; |
| 906 | case 6: |
| 907 | configure_dbgu_pins(); |
| 908 | at91_uarts[i] = &at91sam9260_dbgu_device; |
| 909 | at91_clock_associate("mck", &at91sam9260_dbgu_device.dev, "usart"); |
| 910 | break; |
| 911 | default: |
| 912 | continue; |
| 913 | } |
| 914 | at91_uarts[i]->id = i; /* update ID number to mapped ID */ |
| 915 | } |
| 916 | |
| 917 | /* Set serial console device */ |
| 918 | if (config->console_tty < ATMEL_MAX_UART) |
| 919 | atmel_default_console_device = at91_uarts[config->console_tty]; |
| 920 | if (!atmel_default_console_device) |
| 921 | printk(KERN_INFO "AT91: No default serial console defined.\n"); |
| 922 | } |
| 923 | |
| 924 | void __init at91_add_device_serial(void) |
| 925 | { |
| 926 | int i; |
| 927 | |
| 928 | for (i = 0; i < ATMEL_MAX_UART; i++) { |
| 929 | if (at91_uarts[i]) |
| 930 | platform_device_register(at91_uarts[i]); |
| 931 | } |
| 932 | } |
| 933 | #else |
| 934 | void __init at91_init_serial(struct at91_uart_config *config) {} |
| 935 | void __init at91_add_device_serial(void) {} |
| 936 | #endif |
| 937 | |
| 938 | |
| 939 | /* -------------------------------------------------------------------- */ |
| 940 | /* |
| 941 | * These devices are always present and don't need any board-specific |
| 942 | * setup. |
| 943 | */ |
| 944 | static int __init at91_add_standard_devices(void) |
| 945 | { |
Andrew Victor | 884f5a6 | 2008-01-23 09:11:13 +0100 | [diff] [blame^] | 946 | at91_add_device_rtt(); |
| 947 | at91_add_device_watchdog(); |
Andrew Victor | 86ad76b | 2006-11-30 16:45:01 +0100 | [diff] [blame] | 948 | return 0; |
| 949 | } |
| 950 | |
| 951 | arch_initcall(at91_add_standard_devices); |