at91sam9260_devices.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866
  1. /*
  2. * arch/arm/mach-at91rm9200/at91sam9260_devices.c
  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. #include <linux/platform_device.h>
  15. #include <asm/arch/board.h>
  16. #include <asm/arch/gpio.h>
  17. #include <asm/arch/at91sam9260.h>
  18. #include <asm/arch/at91sam926x_mc.h>
  19. #include "generic.h"
  20. #define SZ_512 0x00000200
  21. #define SZ_256 0x00000100
  22. #define SZ_16 0x00000010
  23. /* --------------------------------------------------------------------
  24. * USB Host
  25. * -------------------------------------------------------------------- */
  26. #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
  27. static u64 ohci_dmamask = 0xffffffffUL;
  28. static struct at91_usbh_data usbh_data;
  29. static struct resource usbh_resources[] = {
  30. [0] = {
  31. .start = AT91SAM9260_UHP_BASE,
  32. .end = AT91SAM9260_UHP_BASE + SZ_1M - 1,
  33. .flags = IORESOURCE_MEM,
  34. },
  35. [1] = {
  36. .start = AT91SAM9260_ID_UHP,
  37. .end = AT91SAM9260_ID_UHP,
  38. .flags = IORESOURCE_IRQ,
  39. },
  40. };
  41. static struct platform_device at91_usbh_device = {
  42. .name = "at91_ohci",
  43. .id = -1,
  44. .dev = {
  45. .dma_mask = &ohci_dmamask,
  46. .coherent_dma_mask = 0xffffffff,
  47. .platform_data = &usbh_data,
  48. },
  49. .resource = usbh_resources,
  50. .num_resources = ARRAY_SIZE(usbh_resources),
  51. };
  52. void __init at91_add_device_usbh(struct at91_usbh_data *data)
  53. {
  54. if (!data)
  55. return;
  56. usbh_data = *data;
  57. platform_device_register(&at91_usbh_device);
  58. }
  59. #else
  60. void __init at91_add_device_usbh(struct at91_usbh_data *data) {}
  61. #endif
  62. /* --------------------------------------------------------------------
  63. * USB Device (Gadget)
  64. * -------------------------------------------------------------------- */
  65. #ifdef CONFIG_USB_GADGET_AT91
  66. static struct at91_udc_data udc_data;
  67. static struct resource udc_resources[] = {
  68. [0] = {
  69. .start = AT91SAM9260_BASE_UDP,
  70. .end = AT91SAM9260_BASE_UDP + SZ_16K - 1,
  71. .flags = IORESOURCE_MEM,
  72. },
  73. [1] = {
  74. .start = AT91SAM9260_ID_UDP,
  75. .end = AT91SAM9260_ID_UDP,
  76. .flags = IORESOURCE_IRQ,
  77. },
  78. };
  79. static struct platform_device at91_udc_device = {
  80. .name = "at91_udc",
  81. .id = -1,
  82. .dev = {
  83. .platform_data = &udc_data,
  84. },
  85. .resource = udc_resources,
  86. .num_resources = ARRAY_SIZE(udc_resources),
  87. };
  88. void __init at91_add_device_udc(struct at91_udc_data *data)
  89. {
  90. if (!data)
  91. return;
  92. if (data->vbus_pin) {
  93. at91_set_gpio_input(data->vbus_pin, 0);
  94. at91_set_deglitch(data->vbus_pin, 1);
  95. }
  96. /* Pullup pin is handled internally by USB device peripheral */
  97. udc_data = *data;
  98. platform_device_register(&at91_udc_device);
  99. }
  100. #else
  101. void __init at91_add_device_udc(struct at91_udc_data *data) {}
  102. #endif
  103. /* --------------------------------------------------------------------
  104. * Ethernet
  105. * -------------------------------------------------------------------- */
  106. #if defined(CONFIG_MACB) || defined(CONFIG_MACB_MODULE)
  107. static u64 eth_dmamask = 0xffffffffUL;
  108. static struct eth_platform_data eth_data;
  109. static struct resource eth_resources[] = {
  110. [0] = {
  111. .start = AT91SAM9260_BASE_EMAC,
  112. .end = AT91SAM9260_BASE_EMAC + SZ_16K - 1,
  113. .flags = IORESOURCE_MEM,
  114. },
  115. [1] = {
  116. .start = AT91SAM9260_ID_EMAC,
  117. .end = AT91SAM9260_ID_EMAC,
  118. .flags = IORESOURCE_IRQ,
  119. },
  120. };
  121. static struct platform_device at91sam9260_eth_device = {
  122. .name = "macb",
  123. .id = -1,
  124. .dev = {
  125. .dma_mask = &eth_dmamask,
  126. .coherent_dma_mask = 0xffffffff,
  127. .platform_data = &eth_data,
  128. },
  129. .resource = eth_resources,
  130. .num_resources = ARRAY_SIZE(eth_resources),
  131. };
  132. void __init at91_add_device_eth(struct eth_platform_data *data)
  133. {
  134. if (!data)
  135. return;
  136. if (data->phy_irq_pin) {
  137. at91_set_gpio_input(data->phy_irq_pin, 0);
  138. at91_set_deglitch(data->phy_irq_pin, 1);
  139. }
  140. /* Pins used for MII and RMII */
  141. at91_set_A_periph(AT91_PIN_PA19, 0); /* ETXCK_EREFCK */
  142. at91_set_A_periph(AT91_PIN_PA17, 0); /* ERXDV */
  143. at91_set_A_periph(AT91_PIN_PA14, 0); /* ERX0 */
  144. at91_set_A_periph(AT91_PIN_PA15, 0); /* ERX1 */
  145. at91_set_A_periph(AT91_PIN_PA18, 0); /* ERXER */
  146. at91_set_A_periph(AT91_PIN_PA16, 0); /* ETXEN */
  147. at91_set_A_periph(AT91_PIN_PA12, 0); /* ETX0 */
  148. at91_set_A_periph(AT91_PIN_PA13, 0); /* ETX1 */
  149. at91_set_A_periph(AT91_PIN_PA21, 0); /* EMDIO */
  150. at91_set_A_periph(AT91_PIN_PA20, 0); /* EMDC */
  151. if (!data->is_rmii) {
  152. at91_set_B_periph(AT91_PIN_PA28, 0); /* ECRS */
  153. at91_set_B_periph(AT91_PIN_PA29, 0); /* ECOL */
  154. at91_set_B_periph(AT91_PIN_PA25, 0); /* ERX2 */
  155. at91_set_B_periph(AT91_PIN_PA26, 0); /* ERX3 */
  156. at91_set_B_periph(AT91_PIN_PA27, 0); /* ERXCK */
  157. at91_set_B_periph(AT91_PIN_PA23, 0); /* ETX2 */
  158. at91_set_B_periph(AT91_PIN_PA24, 0); /* ETX3 */
  159. at91_set_B_periph(AT91_PIN_PA22, 0); /* ETXER */
  160. }
  161. eth_data = *data;
  162. platform_device_register(&at91sam9260_eth_device);
  163. }
  164. #else
  165. void __init at91_add_device_eth(struct eth_platform_data *data) {}
  166. #endif
  167. /* --------------------------------------------------------------------
  168. * MMC / SD
  169. * -------------------------------------------------------------------- */
  170. #if defined(CONFIG_MMC_AT91) || defined(CONFIG_MMC_AT91_MODULE)
  171. static u64 mmc_dmamask = 0xffffffffUL;
  172. static struct at91_mmc_data mmc_data;
  173. static struct resource mmc_resources[] = {
  174. [0] = {
  175. .start = AT91SAM9260_BASE_MCI,
  176. .end = AT91SAM9260_BASE_MCI + SZ_16K - 1,
  177. .flags = IORESOURCE_MEM,
  178. },
  179. [1] = {
  180. .start = AT91SAM9260_ID_MCI,
  181. .end = AT91SAM9260_ID_MCI,
  182. .flags = IORESOURCE_IRQ,
  183. },
  184. };
  185. static struct platform_device at91sam9260_mmc_device = {
  186. .name = "at91_mci",
  187. .id = -1,
  188. .dev = {
  189. .dma_mask = &mmc_dmamask,
  190. .coherent_dma_mask = 0xffffffff,
  191. .platform_data = &mmc_data,
  192. },
  193. .resource = mmc_resources,
  194. .num_resources = ARRAY_SIZE(mmc_resources),
  195. };
  196. void __init at91_add_device_mmc(struct at91_mmc_data *data)
  197. {
  198. if (!data)
  199. return;
  200. /* input/irq */
  201. if (data->det_pin) {
  202. at91_set_gpio_input(data->det_pin, 1);
  203. at91_set_deglitch(data->det_pin, 1);
  204. }
  205. if (data->wp_pin)
  206. at91_set_gpio_input(data->wp_pin, 1);
  207. if (data->vcc_pin)
  208. at91_set_gpio_output(data->vcc_pin, 0);
  209. /* CLK */
  210. at91_set_A_periph(AT91_PIN_PA8, 0);
  211. if (data->slot_b) {
  212. /* CMD */
  213. at91_set_B_periph(AT91_PIN_PA1, 1);
  214. /* DAT0, maybe DAT1..DAT3 */
  215. at91_set_B_periph(AT91_PIN_PA0, 1);
  216. if (data->wire4) {
  217. at91_set_B_periph(AT91_PIN_PA5, 1);
  218. at91_set_B_periph(AT91_PIN_PA4, 1);
  219. at91_set_B_periph(AT91_PIN_PA3, 1);
  220. }
  221. } else {
  222. /* CMD */
  223. at91_set_A_periph(AT91_PIN_PA7, 1);
  224. /* DAT0, maybe DAT1..DAT3 */
  225. at91_set_A_periph(AT91_PIN_PA6, 1);
  226. if (data->wire4) {
  227. at91_set_A_periph(AT91_PIN_PA9, 1);
  228. at91_set_A_periph(AT91_PIN_PA10, 1);
  229. at91_set_A_periph(AT91_PIN_PA11, 1);
  230. }
  231. }
  232. mmc_data = *data;
  233. platform_device_register(&at91sam9260_mmc_device);
  234. }
  235. #else
  236. void __init at91_add_device_mmc(struct at91_mmc_data *data) {}
  237. #endif
  238. /* --------------------------------------------------------------------
  239. * NAND / SmartMedia
  240. * -------------------------------------------------------------------- */
  241. #if defined(CONFIG_MTD_NAND_AT91) || defined(CONFIG_MTD_NAND_AT91_MODULE)
  242. static struct at91_nand_data nand_data;
  243. #define NAND_BASE AT91_CHIPSELECT_3
  244. static struct resource nand_resources[] = {
  245. {
  246. .start = NAND_BASE,
  247. .end = NAND_BASE + SZ_8M - 1,
  248. .flags = IORESOURCE_MEM,
  249. }
  250. };
  251. static struct platform_device at91sam9260_nand_device = {
  252. .name = "at91_nand",
  253. .id = -1,
  254. .dev = {
  255. .platform_data = &nand_data,
  256. },
  257. .resource = nand_resources,
  258. .num_resources = ARRAY_SIZE(nand_resources),
  259. };
  260. void __init at91_add_device_nand(struct at91_nand_data *data)
  261. {
  262. unsigned long csa, mode;
  263. if (!data)
  264. return;
  265. csa = at91_sys_read(AT91_MATRIX_EBICSA);
  266. at91_sys_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_CS3A_SMC);
  267. /* set the bus interface characteristics */
  268. at91_sys_write(AT91_SMC_SETUP(3), AT91_SMC_NWESETUP_(0) | AT91_SMC_NCS_WRSETUP_(0)
  269. | AT91_SMC_NRDSETUP_(0) | AT91_SMC_NCS_RDSETUP_(0));
  270. at91_sys_write(AT91_SMC_PULSE(3), AT91_SMC_NWEPULSE_(2) | AT91_SMC_NCS_WRPULSE_(5)
  271. | AT91_SMC_NRDPULSE_(2) | AT91_SMC_NCS_RDPULSE_(5));
  272. at91_sys_write(AT91_SMC_CYCLE(3), AT91_SMC_NWECYCLE_(7) | AT91_SMC_NRDCYCLE_(7));
  273. if (data->bus_width_16)
  274. mode = AT91_SMC_DBW_16;
  275. else
  276. mode = AT91_SMC_DBW_8;
  277. at91_sys_write(AT91_SMC_MODE(3), mode | AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_TDF_(1));
  278. /* enable pin */
  279. if (data->enable_pin)
  280. at91_set_gpio_output(data->enable_pin, 1);
  281. /* ready/busy pin */
  282. if (data->rdy_pin)
  283. at91_set_gpio_input(data->rdy_pin, 1);
  284. /* card detect pin */
  285. if (data->det_pin)
  286. at91_set_gpio_input(data->det_pin, 1);
  287. nand_data = *data;
  288. platform_device_register(&at91sam9260_nand_device);
  289. }
  290. #else
  291. void __init at91_add_device_nand(struct at91_nand_data *data) {}
  292. #endif
  293. /* --------------------------------------------------------------------
  294. * TWI (i2c)
  295. * -------------------------------------------------------------------- */
  296. #if defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
  297. static struct resource twi_resources[] = {
  298. [0] = {
  299. .start = AT91SAM9260_BASE_TWI,
  300. .end = AT91SAM9260_BASE_TWI + SZ_16K - 1,
  301. .flags = IORESOURCE_MEM,
  302. },
  303. [1] = {
  304. .start = AT91SAM9260_ID_TWI,
  305. .end = AT91SAM9260_ID_TWI,
  306. .flags = IORESOURCE_IRQ,
  307. },
  308. };
  309. static struct platform_device at91sam9260_twi_device = {
  310. .name = "at91_i2c",
  311. .id = -1,
  312. .resource = twi_resources,
  313. .num_resources = ARRAY_SIZE(twi_resources),
  314. };
  315. void __init at91_add_device_i2c(void)
  316. {
  317. /* pins used for TWI interface */
  318. at91_set_A_periph(AT91_PIN_PA23, 0); /* TWD */
  319. at91_set_multi_drive(AT91_PIN_PA23, 1);
  320. at91_set_A_periph(AT91_PIN_PA24, 0); /* TWCK */
  321. at91_set_multi_drive(AT91_PIN_PA24, 1);
  322. platform_device_register(&at91sam9260_twi_device);
  323. }
  324. #else
  325. void __init at91_add_device_i2c(void) {}
  326. #endif
  327. /* --------------------------------------------------------------------
  328. * SPI
  329. * -------------------------------------------------------------------- */
  330. #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
  331. static u64 spi_dmamask = 0xffffffffUL;
  332. static struct resource spi0_resources[] = {
  333. [0] = {
  334. .start = AT91SAM9260_BASE_SPI0,
  335. .end = AT91SAM9260_BASE_SPI0 + SZ_16K - 1,
  336. .flags = IORESOURCE_MEM,
  337. },
  338. [1] = {
  339. .start = AT91SAM9260_ID_SPI0,
  340. .end = AT91SAM9260_ID_SPI0,
  341. .flags = IORESOURCE_IRQ,
  342. },
  343. };
  344. static struct platform_device at91sam9260_spi0_device = {
  345. .name = "atmel_spi",
  346. .id = 0,
  347. .dev = {
  348. .dma_mask = &spi_dmamask,
  349. .coherent_dma_mask = 0xffffffff,
  350. },
  351. .resource = spi0_resources,
  352. .num_resources = ARRAY_SIZE(spi0_resources),
  353. };
  354. static const unsigned spi0_standard_cs[4] = { AT91_PIN_PA3, AT91_PIN_PC11, AT91_PIN_PC16, AT91_PIN_PC17 };
  355. static struct resource spi1_resources[] = {
  356. [0] = {
  357. .start = AT91SAM9260_BASE_SPI1,
  358. .end = AT91SAM9260_BASE_SPI1 + SZ_16K - 1,
  359. .flags = IORESOURCE_MEM,
  360. },
  361. [1] = {
  362. .start = AT91SAM9260_ID_SPI1,
  363. .end = AT91SAM9260_ID_SPI1,
  364. .flags = IORESOURCE_IRQ,
  365. },
  366. };
  367. static struct platform_device at91sam9260_spi1_device = {
  368. .name = "atmel_spi",
  369. .id = 1,
  370. .dev = {
  371. .dma_mask = &spi_dmamask,
  372. .coherent_dma_mask = 0xffffffff,
  373. },
  374. .resource = spi1_resources,
  375. .num_resources = ARRAY_SIZE(spi1_resources),
  376. };
  377. static const unsigned spi1_standard_cs[4] = { AT91_PIN_PB3, AT91_PIN_PC5, AT91_PIN_PC4, AT91_PIN_PC3 };
  378. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
  379. {
  380. int i;
  381. unsigned long cs_pin;
  382. short enable_spi0 = 0;
  383. short enable_spi1 = 0;
  384. /* Choose SPI chip-selects */
  385. for (i = 0; i < nr_devices; i++) {
  386. if (devices[i].controller_data)
  387. cs_pin = (unsigned long) devices[i].controller_data;
  388. else if (devices[i].bus_num == 0)
  389. cs_pin = spi0_standard_cs[devices[i].chip_select];
  390. else
  391. cs_pin = spi1_standard_cs[devices[i].chip_select];
  392. if (devices[i].bus_num == 0)
  393. enable_spi0 = 1;
  394. else
  395. enable_spi1 = 1;
  396. /* enable chip-select pin */
  397. at91_set_gpio_output(cs_pin, 1);
  398. /* pass chip-select pin to driver */
  399. devices[i].controller_data = (void *) cs_pin;
  400. }
  401. spi_register_board_info(devices, nr_devices);
  402. /* Configure SPI bus(es) */
  403. if (enable_spi0) {
  404. at91_set_A_periph(AT91_PIN_PA0, 0); /* SPI0_MISO */
  405. at91_set_A_periph(AT91_PIN_PA1, 0); /* SPI0_MOSI */
  406. at91_set_A_periph(AT91_PIN_PA2, 0); /* SPI1_SPCK */
  407. at91_clock_associate("spi0_clk", &at91sam9260_spi0_device.dev, "spi_clk");
  408. platform_device_register(&at91sam9260_spi0_device);
  409. }
  410. if (enable_spi1) {
  411. at91_set_A_periph(AT91_PIN_PB0, 0); /* SPI1_MISO */
  412. at91_set_A_periph(AT91_PIN_PB1, 0); /* SPI1_MOSI */
  413. at91_set_A_periph(AT91_PIN_PB2, 0); /* SPI1_SPCK */
  414. at91_clock_associate("spi1_clk", &at91sam9260_spi1_device.dev, "spi_clk");
  415. platform_device_register(&at91sam9260_spi1_device);
  416. }
  417. }
  418. #else
  419. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
  420. #endif
  421. /* --------------------------------------------------------------------
  422. * LEDs
  423. * -------------------------------------------------------------------- */
  424. #if defined(CONFIG_LEDS)
  425. u8 at91_leds_cpu;
  426. u8 at91_leds_timer;
  427. void __init at91_init_leds(u8 cpu_led, u8 timer_led)
  428. {
  429. at91_leds_cpu = cpu_led;
  430. at91_leds_timer = timer_led;
  431. }
  432. #else
  433. void __init at91_init_leds(u8 cpu_led, u8 timer_led) {}
  434. #endif
  435. /* --------------------------------------------------------------------
  436. * UART
  437. * -------------------------------------------------------------------- */
  438. #if defined(CONFIG_SERIAL_ATMEL)
  439. static struct resource dbgu_resources[] = {
  440. [0] = {
  441. .start = AT91_VA_BASE_SYS + AT91_DBGU,
  442. .end = AT91_VA_BASE_SYS + AT91_DBGU + SZ_512 - 1,
  443. .flags = IORESOURCE_MEM,
  444. },
  445. [1] = {
  446. .start = AT91_ID_SYS,
  447. .end = AT91_ID_SYS,
  448. .flags = IORESOURCE_IRQ,
  449. },
  450. };
  451. static struct atmel_uart_data dbgu_data = {
  452. .use_dma_tx = 0,
  453. .use_dma_rx = 0, /* DBGU not capable of receive DMA */
  454. .regs = (void __iomem *)(AT91_VA_BASE_SYS + AT91_DBGU),
  455. };
  456. static struct platform_device at91sam9260_dbgu_device = {
  457. .name = "atmel_usart",
  458. .id = 0,
  459. .dev = {
  460. .platform_data = &dbgu_data,
  461. .coherent_dma_mask = 0xffffffff,
  462. },
  463. .resource = dbgu_resources,
  464. .num_resources = ARRAY_SIZE(dbgu_resources),
  465. };
  466. static inline void configure_dbgu_pins(void)
  467. {
  468. at91_set_A_periph(AT91_PIN_PB14, 0); /* DRXD */
  469. at91_set_A_periph(AT91_PIN_PB15, 1); /* DTXD */
  470. }
  471. static struct resource uart0_resources[] = {
  472. [0] = {
  473. .start = AT91SAM9260_BASE_US0,
  474. .end = AT91SAM9260_BASE_US0 + SZ_16K - 1,
  475. .flags = IORESOURCE_MEM,
  476. },
  477. [1] = {
  478. .start = AT91SAM9260_ID_US0,
  479. .end = AT91SAM9260_ID_US0,
  480. .flags = IORESOURCE_IRQ,
  481. },
  482. };
  483. static struct atmel_uart_data uart0_data = {
  484. .use_dma_tx = 1,
  485. .use_dma_rx = 1,
  486. };
  487. static struct platform_device at91sam9260_uart0_device = {
  488. .name = "atmel_usart",
  489. .id = 1,
  490. .dev = {
  491. .platform_data = &uart0_data,
  492. .coherent_dma_mask = 0xffffffff,
  493. },
  494. .resource = uart0_resources,
  495. .num_resources = ARRAY_SIZE(uart0_resources),
  496. };
  497. static inline void configure_usart0_pins(void)
  498. {
  499. at91_set_A_periph(AT91_PIN_PB4, 1); /* TXD0 */
  500. at91_set_A_periph(AT91_PIN_PB5, 0); /* RXD0 */
  501. at91_set_A_periph(AT91_PIN_PB26, 0); /* RTS0 */
  502. at91_set_A_periph(AT91_PIN_PB27, 0); /* CTS0 */
  503. at91_set_A_periph(AT91_PIN_PB24, 0); /* DTR0 */
  504. at91_set_A_periph(AT91_PIN_PB22, 0); /* DSR0 */
  505. at91_set_A_periph(AT91_PIN_PB23, 0); /* DCD0 */
  506. at91_set_A_periph(AT91_PIN_PB25, 0); /* RI0 */
  507. }
  508. static struct resource uart1_resources[] = {
  509. [0] = {
  510. .start = AT91SAM9260_BASE_US1,
  511. .end = AT91SAM9260_BASE_US1 + SZ_16K - 1,
  512. .flags = IORESOURCE_MEM,
  513. },
  514. [1] = {
  515. .start = AT91SAM9260_ID_US1,
  516. .end = AT91SAM9260_ID_US1,
  517. .flags = IORESOURCE_IRQ,
  518. },
  519. };
  520. static struct atmel_uart_data uart1_data = {
  521. .use_dma_tx = 1,
  522. .use_dma_rx = 1,
  523. };
  524. static struct platform_device at91sam9260_uart1_device = {
  525. .name = "atmel_usart",
  526. .id = 2,
  527. .dev = {
  528. .platform_data = &uart1_data,
  529. .coherent_dma_mask = 0xffffffff,
  530. },
  531. .resource = uart1_resources,
  532. .num_resources = ARRAY_SIZE(uart1_resources),
  533. };
  534. static inline void configure_usart1_pins(void)
  535. {
  536. at91_set_A_periph(AT91_PIN_PB6, 1); /* TXD1 */
  537. at91_set_A_periph(AT91_PIN_PB7, 0); /* RXD1 */
  538. at91_set_A_periph(AT91_PIN_PB28, 0); /* RTS1 */
  539. at91_set_A_periph(AT91_PIN_PB29, 0); /* CTS1 */
  540. }
  541. static struct resource uart2_resources[] = {
  542. [0] = {
  543. .start = AT91SAM9260_BASE_US2,
  544. .end = AT91SAM9260_BASE_US2 + SZ_16K - 1,
  545. .flags = IORESOURCE_MEM,
  546. },
  547. [1] = {
  548. .start = AT91SAM9260_ID_US2,
  549. .end = AT91SAM9260_ID_US2,
  550. .flags = IORESOURCE_IRQ,
  551. },
  552. };
  553. static struct atmel_uart_data uart2_data = {
  554. .use_dma_tx = 1,
  555. .use_dma_rx = 1,
  556. };
  557. static struct platform_device at91sam9260_uart2_device = {
  558. .name = "atmel_usart",
  559. .id = 3,
  560. .dev = {
  561. .platform_data = &uart2_data,
  562. .coherent_dma_mask = 0xffffffff,
  563. },
  564. .resource = uart2_resources,
  565. .num_resources = ARRAY_SIZE(uart2_resources),
  566. };
  567. static inline void configure_usart2_pins(void)
  568. {
  569. at91_set_A_periph(AT91_PIN_PB8, 1); /* TXD2 */
  570. at91_set_A_periph(AT91_PIN_PB9, 0); /* RXD2 */
  571. }
  572. static struct resource uart3_resources[] = {
  573. [0] = {
  574. .start = AT91SAM9260_BASE_US3,
  575. .end = AT91SAM9260_BASE_US3 + SZ_16K - 1,
  576. .flags = IORESOURCE_MEM,
  577. },
  578. [1] = {
  579. .start = AT91SAM9260_ID_US3,
  580. .end = AT91SAM9260_ID_US3,
  581. .flags = IORESOURCE_IRQ,
  582. },
  583. };
  584. static struct atmel_uart_data uart3_data = {
  585. .use_dma_tx = 1,
  586. .use_dma_rx = 1,
  587. };
  588. static struct platform_device at91sam9260_uart3_device = {
  589. .name = "atmel_usart",
  590. .id = 4,
  591. .dev = {
  592. .platform_data = &uart3_data,
  593. .coherent_dma_mask = 0xffffffff,
  594. },
  595. .resource = uart3_resources,
  596. .num_resources = ARRAY_SIZE(uart3_resources),
  597. };
  598. static inline void configure_usart3_pins(void)
  599. {
  600. at91_set_A_periph(AT91_PIN_PB10, 1); /* TXD3 */
  601. at91_set_A_periph(AT91_PIN_PB11, 0); /* RXD3 */
  602. }
  603. static struct resource uart4_resources[] = {
  604. [0] = {
  605. .start = AT91SAM9260_BASE_US4,
  606. .end = AT91SAM9260_BASE_US4 + SZ_16K - 1,
  607. .flags = IORESOURCE_MEM,
  608. },
  609. [1] = {
  610. .start = AT91SAM9260_ID_US4,
  611. .end = AT91SAM9260_ID_US4,
  612. .flags = IORESOURCE_IRQ,
  613. },
  614. };
  615. static struct atmel_uart_data uart4_data = {
  616. .use_dma_tx = 1,
  617. .use_dma_rx = 1,
  618. };
  619. static struct platform_device at91sam9260_uart4_device = {
  620. .name = "atmel_usart",
  621. .id = 5,
  622. .dev = {
  623. .platform_data = &uart4_data,
  624. .coherent_dma_mask = 0xffffffff,
  625. },
  626. .resource = uart4_resources,
  627. .num_resources = ARRAY_SIZE(uart4_resources),
  628. };
  629. static inline void configure_usart4_pins(void)
  630. {
  631. at91_set_B_periph(AT91_PIN_PA31, 1); /* TXD4 */
  632. at91_set_B_periph(AT91_PIN_PA30, 0); /* RXD4 */
  633. }
  634. static struct resource uart5_resources[] = {
  635. [0] = {
  636. .start = AT91SAM9260_BASE_US5,
  637. .end = AT91SAM9260_BASE_US5 + SZ_16K - 1,
  638. .flags = IORESOURCE_MEM,
  639. },
  640. [1] = {
  641. .start = AT91SAM9260_ID_US5,
  642. .end = AT91SAM9260_ID_US5,
  643. .flags = IORESOURCE_IRQ,
  644. },
  645. };
  646. static struct atmel_uart_data uart5_data = {
  647. .use_dma_tx = 1,
  648. .use_dma_rx = 1,
  649. };
  650. static struct platform_device at91sam9260_uart5_device = {
  651. .name = "atmel_usart",
  652. .id = 6,
  653. .dev = {
  654. .platform_data = &uart5_data,
  655. .coherent_dma_mask = 0xffffffff,
  656. },
  657. .resource = uart5_resources,
  658. .num_resources = ARRAY_SIZE(uart5_resources),
  659. };
  660. static inline void configure_usart5_pins(void)
  661. {
  662. at91_set_A_periph(AT91_PIN_PB12, 1); /* TXD5 */
  663. at91_set_A_periph(AT91_PIN_PB13, 0); /* RXD5 */
  664. }
  665. struct platform_device *at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
  666. struct platform_device *atmel_default_console_device; /* the serial console device */
  667. void __init at91_init_serial(struct at91_uart_config *config)
  668. {
  669. int i;
  670. /* Fill in list of supported UARTs */
  671. for (i = 0; i < config->nr_tty; i++) {
  672. switch (config->tty_map[i]) {
  673. case 0:
  674. configure_usart0_pins();
  675. at91_uarts[i] = &at91sam9260_uart0_device;
  676. at91_clock_associate("usart0_clk", &at91sam9260_uart0_device.dev, "usart");
  677. break;
  678. case 1:
  679. configure_usart1_pins();
  680. at91_uarts[i] = &at91sam9260_uart1_device;
  681. at91_clock_associate("usart1_clk", &at91sam9260_uart1_device.dev, "usart");
  682. break;
  683. case 2:
  684. configure_usart2_pins();
  685. at91_uarts[i] = &at91sam9260_uart2_device;
  686. at91_clock_associate("usart2_clk", &at91sam9260_uart2_device.dev, "usart");
  687. break;
  688. case 3:
  689. configure_usart3_pins();
  690. at91_uarts[i] = &at91sam9260_uart3_device;
  691. at91_clock_associate("usart3_clk", &at91sam9260_uart3_device.dev, "usart");
  692. break;
  693. case 4:
  694. configure_usart4_pins();
  695. at91_uarts[i] = &at91sam9260_uart4_device;
  696. at91_clock_associate("usart4_clk", &at91sam9260_uart4_device.dev, "usart");
  697. break;
  698. case 5:
  699. configure_usart5_pins();
  700. at91_uarts[i] = &at91sam9260_uart5_device;
  701. at91_clock_associate("usart5_clk", &at91sam9260_uart5_device.dev, "usart");
  702. break;
  703. case 6:
  704. configure_dbgu_pins();
  705. at91_uarts[i] = &at91sam9260_dbgu_device;
  706. at91_clock_associate("mck", &at91sam9260_dbgu_device.dev, "usart");
  707. break;
  708. default:
  709. continue;
  710. }
  711. at91_uarts[i]->id = i; /* update ID number to mapped ID */
  712. }
  713. /* Set serial console device */
  714. if (config->console_tty < ATMEL_MAX_UART)
  715. atmel_default_console_device = at91_uarts[config->console_tty];
  716. if (!atmel_default_console_device)
  717. printk(KERN_INFO "AT91: No default serial console defined.\n");
  718. }
  719. void __init at91_add_device_serial(void)
  720. {
  721. int i;
  722. for (i = 0; i < ATMEL_MAX_UART; i++) {
  723. if (at91_uarts[i])
  724. platform_device_register(at91_uarts[i]);
  725. }
  726. }
  727. #else
  728. void __init at91_init_serial(struct at91_uart_config *config) {}
  729. void __init at91_add_device_serial(void) {}
  730. #endif
  731. /* -------------------------------------------------------------------- */
  732. /*
  733. * These devices are always present and don't need any board-specific
  734. * setup.
  735. */
  736. static int __init at91_add_standard_devices(void)
  737. {
  738. return 0;
  739. }
  740. arch_initcall(at91_add_standard_devices);