at91sam9261_devices.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  1. /*
  2. * arch/arm/mach-at91/at91sam9261_devices.c
  3. *
  4. * Copyright (C) 2005 Thibaut VARENE <varenet@parisc-linux.org>
  5. * Copyright (C) 2005 David Brownell
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. */
  13. #include <asm/mach/arch.h>
  14. #include <asm/mach/map.h>
  15. #include <linux/platform_device.h>
  16. #include <asm/arch/board.h>
  17. #include <asm/arch/gpio.h>
  18. #include <asm/arch/at91sam9261.h>
  19. #include <asm/arch/at91sam9261_matrix.h>
  20. #include <asm/arch/at91sam926x_mc.h>
  21. #include "generic.h"
  22. /* --------------------------------------------------------------------
  23. * USB Host
  24. * -------------------------------------------------------------------- */
  25. #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
  26. static u64 ohci_dmamask = 0xffffffffUL;
  27. static struct at91_usbh_data usbh_data;
  28. static struct resource usbh_resources[] = {
  29. [0] = {
  30. .start = AT91SAM9261_UHP_BASE,
  31. .end = AT91SAM9261_UHP_BASE + SZ_1M - 1,
  32. .flags = IORESOURCE_MEM,
  33. },
  34. [1] = {
  35. .start = AT91SAM9261_ID_UHP,
  36. .end = AT91SAM9261_ID_UHP,
  37. .flags = IORESOURCE_IRQ,
  38. },
  39. };
  40. static struct platform_device at91sam9261_usbh_device = {
  41. .name = "at91_ohci",
  42. .id = -1,
  43. .dev = {
  44. .dma_mask = &ohci_dmamask,
  45. .coherent_dma_mask = 0xffffffff,
  46. .platform_data = &usbh_data,
  47. },
  48. .resource = usbh_resources,
  49. .num_resources = ARRAY_SIZE(usbh_resources),
  50. };
  51. void __init at91_add_device_usbh(struct at91_usbh_data *data)
  52. {
  53. if (!data)
  54. return;
  55. usbh_data = *data;
  56. platform_device_register(&at91sam9261_usbh_device);
  57. }
  58. #else
  59. void __init at91_add_device_usbh(struct at91_usbh_data *data) {}
  60. #endif
  61. /* --------------------------------------------------------------------
  62. * USB Device (Gadget)
  63. * -------------------------------------------------------------------- */
  64. #ifdef CONFIG_USB_GADGET_AT91
  65. static struct at91_udc_data udc_data;
  66. static struct resource udc_resources[] = {
  67. [0] = {
  68. .start = AT91SAM9261_BASE_UDP,
  69. .end = AT91SAM9261_BASE_UDP + SZ_16K - 1,
  70. .flags = IORESOURCE_MEM,
  71. },
  72. [1] = {
  73. .start = AT91SAM9261_ID_UDP,
  74. .end = AT91SAM9261_ID_UDP,
  75. .flags = IORESOURCE_IRQ,
  76. },
  77. };
  78. static struct platform_device at91sam9261_udc_device = {
  79. .name = "at91_udc",
  80. .id = -1,
  81. .dev = {
  82. .platform_data = &udc_data,
  83. },
  84. .resource = udc_resources,
  85. .num_resources = ARRAY_SIZE(udc_resources),
  86. };
  87. void __init at91_add_device_udc(struct at91_udc_data *data)
  88. {
  89. unsigned long x;
  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 */
  97. x = at91_sys_read(AT91_MATRIX_USBPUCR);
  98. at91_sys_write(AT91_MATRIX_USBPUCR, x | AT91_MATRIX_USBPUCR_PUON);
  99. udc_data = *data;
  100. platform_device_register(&at91sam9261_udc_device);
  101. }
  102. #else
  103. void __init at91_add_device_udc(struct at91_udc_data *data) {}
  104. #endif
  105. /* --------------------------------------------------------------------
  106. * MMC / SD
  107. * -------------------------------------------------------------------- */
  108. #if defined(CONFIG_MMC_AT91) || defined(CONFIG_MMC_AT91_MODULE)
  109. static u64 mmc_dmamask = 0xffffffffUL;
  110. static struct at91_mmc_data mmc_data;
  111. static struct resource mmc_resources[] = {
  112. [0] = {
  113. .start = AT91SAM9261_BASE_MCI,
  114. .end = AT91SAM9261_BASE_MCI + SZ_16K - 1,
  115. .flags = IORESOURCE_MEM,
  116. },
  117. [1] = {
  118. .start = AT91SAM9261_ID_MCI,
  119. .end = AT91SAM9261_ID_MCI,
  120. .flags = IORESOURCE_IRQ,
  121. },
  122. };
  123. static struct platform_device at91sam9261_mmc_device = {
  124. .name = "at91_mci",
  125. .id = -1,
  126. .dev = {
  127. .dma_mask = &mmc_dmamask,
  128. .coherent_dma_mask = 0xffffffff,
  129. .platform_data = &mmc_data,
  130. },
  131. .resource = mmc_resources,
  132. .num_resources = ARRAY_SIZE(mmc_resources),
  133. };
  134. void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data)
  135. {
  136. if (!data)
  137. return;
  138. /* input/irq */
  139. if (data->det_pin) {
  140. at91_set_gpio_input(data->det_pin, 1);
  141. at91_set_deglitch(data->det_pin, 1);
  142. }
  143. if (data->wp_pin)
  144. at91_set_gpio_input(data->wp_pin, 1);
  145. if (data->vcc_pin)
  146. at91_set_gpio_output(data->vcc_pin, 0);
  147. /* CLK */
  148. at91_set_B_periph(AT91_PIN_PA2, 0);
  149. /* CMD */
  150. at91_set_B_periph(AT91_PIN_PA1, 1);
  151. /* DAT0, maybe DAT1..DAT3 */
  152. at91_set_B_periph(AT91_PIN_PA0, 1);
  153. if (data->wire4) {
  154. at91_set_B_periph(AT91_PIN_PA4, 1);
  155. at91_set_B_periph(AT91_PIN_PA5, 1);
  156. at91_set_B_periph(AT91_PIN_PA6, 1);
  157. }
  158. mmc_data = *data;
  159. platform_device_register(&at91sam9261_mmc_device);
  160. }
  161. #else
  162. void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data) {}
  163. #endif
  164. /* --------------------------------------------------------------------
  165. * NAND / SmartMedia
  166. * -------------------------------------------------------------------- */
  167. #if defined(CONFIG_MTD_NAND_AT91) || defined(CONFIG_MTD_NAND_AT91_MODULE)
  168. static struct at91_nand_data nand_data;
  169. #define NAND_BASE AT91_CHIPSELECT_3
  170. static struct resource nand_resources[] = {
  171. {
  172. .start = NAND_BASE,
  173. .end = NAND_BASE + SZ_256M - 1,
  174. .flags = IORESOURCE_MEM,
  175. }
  176. };
  177. static struct platform_device at91_nand_device = {
  178. .name = "at91_nand",
  179. .id = -1,
  180. .dev = {
  181. .platform_data = &nand_data,
  182. },
  183. .resource = nand_resources,
  184. .num_resources = ARRAY_SIZE(nand_resources),
  185. };
  186. void __init at91_add_device_nand(struct at91_nand_data *data)
  187. {
  188. unsigned long csa, mode;
  189. if (!data)
  190. return;
  191. csa = at91_sys_read(AT91_MATRIX_EBICSA);
  192. at91_sys_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_CS3A_SMC);
  193. /* set the bus interface characteristics */
  194. at91_sys_write(AT91_SMC_SETUP(3), AT91_SMC_NWESETUP_(0) | AT91_SMC_NCS_WRSETUP_(0)
  195. | AT91_SMC_NRDSETUP_(0) | AT91_SMC_NCS_RDSETUP_(0));
  196. at91_sys_write(AT91_SMC_PULSE(3), AT91_SMC_NWEPULSE_(2) | AT91_SMC_NCS_WRPULSE_(5)
  197. | AT91_SMC_NRDPULSE_(2) | AT91_SMC_NCS_RDPULSE_(5));
  198. at91_sys_write(AT91_SMC_CYCLE(3), AT91_SMC_NWECYCLE_(7) | AT91_SMC_NRDCYCLE_(7));
  199. if (data->bus_width_16)
  200. mode = AT91_SMC_DBW_16;
  201. else
  202. mode = AT91_SMC_DBW_8;
  203. at91_sys_write(AT91_SMC_MODE(3), mode | AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_TDF_(1));
  204. /* enable pin */
  205. if (data->enable_pin)
  206. at91_set_gpio_output(data->enable_pin, 1);
  207. /* ready/busy pin */
  208. if (data->rdy_pin)
  209. at91_set_gpio_input(data->rdy_pin, 1);
  210. /* card detect pin */
  211. if (data->det_pin)
  212. at91_set_gpio_input(data->det_pin, 1);
  213. at91_set_A_periph(AT91_PIN_PC0, 0); /* NANDOE */
  214. at91_set_A_periph(AT91_PIN_PC1, 0); /* NANDWE */
  215. nand_data = *data;
  216. platform_device_register(&at91_nand_device);
  217. }
  218. #else
  219. void __init at91_add_device_nand(struct at91_nand_data *data) {}
  220. #endif
  221. /* --------------------------------------------------------------------
  222. * TWI (i2c)
  223. * -------------------------------------------------------------------- */
  224. #if defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
  225. static struct resource twi_resources[] = {
  226. [0] = {
  227. .start = AT91SAM9261_BASE_TWI,
  228. .end = AT91SAM9261_BASE_TWI + SZ_16K - 1,
  229. .flags = IORESOURCE_MEM,
  230. },
  231. [1] = {
  232. .start = AT91SAM9261_ID_TWI,
  233. .end = AT91SAM9261_ID_TWI,
  234. .flags = IORESOURCE_IRQ,
  235. },
  236. };
  237. static struct platform_device at91sam9261_twi_device = {
  238. .name = "at91_i2c",
  239. .id = -1,
  240. .resource = twi_resources,
  241. .num_resources = ARRAY_SIZE(twi_resources),
  242. };
  243. void __init at91_add_device_i2c(void)
  244. {
  245. /* pins used for TWI interface */
  246. at91_set_A_periph(AT91_PIN_PA7, 0); /* TWD */
  247. at91_set_multi_drive(AT91_PIN_PA7, 1);
  248. at91_set_A_periph(AT91_PIN_PA8, 0); /* TWCK */
  249. at91_set_multi_drive(AT91_PIN_PA8, 1);
  250. platform_device_register(&at91sam9261_twi_device);
  251. }
  252. #else
  253. void __init at91_add_device_i2c(void) {}
  254. #endif
  255. /* --------------------------------------------------------------------
  256. * SPI
  257. * -------------------------------------------------------------------- */
  258. #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
  259. static u64 spi_dmamask = 0xffffffffUL;
  260. static struct resource spi0_resources[] = {
  261. [0] = {
  262. .start = AT91SAM9261_BASE_SPI0,
  263. .end = AT91SAM9261_BASE_SPI0 + SZ_16K - 1,
  264. .flags = IORESOURCE_MEM,
  265. },
  266. [1] = {
  267. .start = AT91SAM9261_ID_SPI0,
  268. .end = AT91SAM9261_ID_SPI0,
  269. .flags = IORESOURCE_IRQ,
  270. },
  271. };
  272. static struct platform_device at91sam9261_spi0_device = {
  273. .name = "atmel_spi",
  274. .id = 0,
  275. .dev = {
  276. .dma_mask = &spi_dmamask,
  277. .coherent_dma_mask = 0xffffffff,
  278. },
  279. .resource = spi0_resources,
  280. .num_resources = ARRAY_SIZE(spi0_resources),
  281. };
  282. static const unsigned spi0_standard_cs[4] = { AT91_PIN_PA3, AT91_PIN_PA4, AT91_PIN_PA5, AT91_PIN_PA6 };
  283. static struct resource spi1_resources[] = {
  284. [0] = {
  285. .start = AT91SAM9261_BASE_SPI1,
  286. .end = AT91SAM9261_BASE_SPI1 + SZ_16K - 1,
  287. .flags = IORESOURCE_MEM,
  288. },
  289. [1] = {
  290. .start = AT91SAM9261_ID_SPI1,
  291. .end = AT91SAM9261_ID_SPI1,
  292. .flags = IORESOURCE_IRQ,
  293. },
  294. };
  295. static struct platform_device at91sam9261_spi1_device = {
  296. .name = "atmel_spi",
  297. .id = 1,
  298. .dev = {
  299. .dma_mask = &spi_dmamask,
  300. .coherent_dma_mask = 0xffffffff,
  301. },
  302. .resource = spi1_resources,
  303. .num_resources = ARRAY_SIZE(spi1_resources),
  304. };
  305. static const unsigned spi1_standard_cs[4] = { AT91_PIN_PB28, AT91_PIN_PA24, AT91_PIN_PA25, AT91_PIN_PA26 };
  306. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
  307. {
  308. int i;
  309. unsigned long cs_pin;
  310. short enable_spi0 = 0;
  311. short enable_spi1 = 0;
  312. /* Choose SPI chip-selects */
  313. for (i = 0; i < nr_devices; i++) {
  314. if (devices[i].controller_data)
  315. cs_pin = (unsigned long) devices[i].controller_data;
  316. else if (devices[i].bus_num == 0)
  317. cs_pin = spi0_standard_cs[devices[i].chip_select];
  318. else
  319. cs_pin = spi1_standard_cs[devices[i].chip_select];
  320. if (devices[i].bus_num == 0)
  321. enable_spi0 = 1;
  322. else
  323. enable_spi1 = 1;
  324. /* enable chip-select pin */
  325. at91_set_gpio_output(cs_pin, 1);
  326. /* pass chip-select pin to driver */
  327. devices[i].controller_data = (void *) cs_pin;
  328. }
  329. spi_register_board_info(devices, nr_devices);
  330. /* Configure SPI bus(es) */
  331. if (enable_spi0) {
  332. at91_set_A_periph(AT91_PIN_PA0, 0); /* SPI0_MISO */
  333. at91_set_A_periph(AT91_PIN_PA1, 0); /* SPI0_MOSI */
  334. at91_set_A_periph(AT91_PIN_PA2, 0); /* SPI0_SPCK */
  335. at91_clock_associate("spi0_clk", &at91sam9261_spi0_device.dev, "spi_clk");
  336. platform_device_register(&at91sam9261_spi0_device);
  337. }
  338. if (enable_spi1) {
  339. at91_set_A_periph(AT91_PIN_PB30, 0); /* SPI1_MISO */
  340. at91_set_A_periph(AT91_PIN_PB31, 0); /* SPI1_MOSI */
  341. at91_set_A_periph(AT91_PIN_PB29, 0); /* SPI1_SPCK */
  342. at91_clock_associate("spi1_clk", &at91sam9261_spi1_device.dev, "spi_clk");
  343. platform_device_register(&at91sam9261_spi1_device);
  344. }
  345. }
  346. #else
  347. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
  348. #endif
  349. /* --------------------------------------------------------------------
  350. * LCD Controller
  351. * -------------------------------------------------------------------- */
  352. #if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
  353. static u64 lcdc_dmamask = 0xffffffffUL;
  354. static struct atmel_lcdfb_info lcdc_data;
  355. static struct resource lcdc_resources[] = {
  356. [0] = {
  357. .start = AT91SAM9261_LCDC_BASE,
  358. .end = AT91SAM9261_LCDC_BASE + SZ_4K - 1,
  359. .flags = IORESOURCE_MEM,
  360. },
  361. [1] = {
  362. .start = AT91SAM9261_ID_LCDC,
  363. .end = AT91SAM9261_ID_LCDC,
  364. .flags = IORESOURCE_IRQ,
  365. },
  366. #if defined(CONFIG_FB_INTSRAM)
  367. [2] = {
  368. .start = AT91SAM9261_SRAM_BASE,
  369. .end = AT91SAM9261_SRAM_BASE + AT91SAM9261_SRAM_SIZE - 1,
  370. .flags = IORESOURCE_MEM,
  371. },
  372. #endif
  373. };
  374. static struct platform_device at91_lcdc_device = {
  375. .name = "atmel_lcdfb",
  376. .id = 0,
  377. .dev = {
  378. .dma_mask = &lcdc_dmamask,
  379. .coherent_dma_mask = 0xffffffff,
  380. .platform_data = &lcdc_data,
  381. },
  382. .resource = lcdc_resources,
  383. .num_resources = ARRAY_SIZE(lcdc_resources),
  384. };
  385. void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data)
  386. {
  387. if (!data) {
  388. return;
  389. }
  390. at91_set_A_periph(AT91_PIN_PB1, 0); /* LCDHSYNC */
  391. at91_set_A_periph(AT91_PIN_PB2, 0); /* LCDDOTCK */
  392. at91_set_A_periph(AT91_PIN_PB3, 0); /* LCDDEN */
  393. at91_set_A_periph(AT91_PIN_PB4, 0); /* LCDCC */
  394. at91_set_A_periph(AT91_PIN_PB7, 0); /* LCDD2 */
  395. at91_set_A_periph(AT91_PIN_PB8, 0); /* LCDD3 */
  396. at91_set_A_periph(AT91_PIN_PB9, 0); /* LCDD4 */
  397. at91_set_A_periph(AT91_PIN_PB10, 0); /* LCDD5 */
  398. at91_set_A_periph(AT91_PIN_PB11, 0); /* LCDD6 */
  399. at91_set_A_periph(AT91_PIN_PB12, 0); /* LCDD7 */
  400. at91_set_A_periph(AT91_PIN_PB15, 0); /* LCDD10 */
  401. at91_set_A_periph(AT91_PIN_PB16, 0); /* LCDD11 */
  402. at91_set_A_periph(AT91_PIN_PB17, 0); /* LCDD12 */
  403. at91_set_A_periph(AT91_PIN_PB18, 0); /* LCDD13 */
  404. at91_set_A_periph(AT91_PIN_PB19, 0); /* LCDD14 */
  405. at91_set_A_periph(AT91_PIN_PB20, 0); /* LCDD15 */
  406. at91_set_B_periph(AT91_PIN_PB23, 0); /* LCDD18 */
  407. at91_set_B_periph(AT91_PIN_PB24, 0); /* LCDD19 */
  408. at91_set_B_periph(AT91_PIN_PB25, 0); /* LCDD20 */
  409. at91_set_B_periph(AT91_PIN_PB26, 0); /* LCDD21 */
  410. at91_set_B_periph(AT91_PIN_PB27, 0); /* LCDD22 */
  411. at91_set_B_periph(AT91_PIN_PB28, 0); /* LCDD23 */
  412. lcdc_data = *data;
  413. platform_device_register(&at91_lcdc_device);
  414. }
  415. #else
  416. void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data) {}
  417. #endif
  418. /* --------------------------------------------------------------------
  419. * LEDs
  420. * -------------------------------------------------------------------- */
  421. #if defined(CONFIG_LEDS)
  422. u8 at91_leds_cpu;
  423. u8 at91_leds_timer;
  424. void __init at91_init_leds(u8 cpu_led, u8 timer_led)
  425. {
  426. /* Enable GPIO to access the LEDs */
  427. at91_set_gpio_output(cpu_led, 1);
  428. at91_set_gpio_output(timer_led, 1);
  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 at91sam9261_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_PA9, 0); /* DRXD */
  469. at91_set_A_periph(AT91_PIN_PA10, 1); /* DTXD */
  470. }
  471. static struct resource uart0_resources[] = {
  472. [0] = {
  473. .start = AT91SAM9261_BASE_US0,
  474. .end = AT91SAM9261_BASE_US0 + SZ_16K - 1,
  475. .flags = IORESOURCE_MEM,
  476. },
  477. [1] = {
  478. .start = AT91SAM9261_ID_US0,
  479. .end = AT91SAM9261_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 at91sam9261_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_PC8, 1); /* TXD0 */
  500. at91_set_A_periph(AT91_PIN_PC9, 0); /* RXD0 */
  501. at91_set_A_periph(AT91_PIN_PC10, 0); /* RTS0 */
  502. at91_set_A_periph(AT91_PIN_PC11, 0); /* CTS0 */
  503. }
  504. static struct resource uart1_resources[] = {
  505. [0] = {
  506. .start = AT91SAM9261_BASE_US1,
  507. .end = AT91SAM9261_BASE_US1 + SZ_16K - 1,
  508. .flags = IORESOURCE_MEM,
  509. },
  510. [1] = {
  511. .start = AT91SAM9261_ID_US1,
  512. .end = AT91SAM9261_ID_US1,
  513. .flags = IORESOURCE_IRQ,
  514. },
  515. };
  516. static struct atmel_uart_data uart1_data = {
  517. .use_dma_tx = 1,
  518. .use_dma_rx = 1,
  519. };
  520. static struct platform_device at91sam9261_uart1_device = {
  521. .name = "atmel_usart",
  522. .id = 2,
  523. .dev = {
  524. .platform_data = &uart1_data,
  525. .coherent_dma_mask = 0xffffffff,
  526. },
  527. .resource = uart1_resources,
  528. .num_resources = ARRAY_SIZE(uart1_resources),
  529. };
  530. static inline void configure_usart1_pins(void)
  531. {
  532. at91_set_A_periph(AT91_PIN_PC12, 1); /* TXD1 */
  533. at91_set_A_periph(AT91_PIN_PC13, 0); /* RXD1 */
  534. }
  535. static struct resource uart2_resources[] = {
  536. [0] = {
  537. .start = AT91SAM9261_BASE_US2,
  538. .end = AT91SAM9261_BASE_US2 + SZ_16K - 1,
  539. .flags = IORESOURCE_MEM,
  540. },
  541. [1] = {
  542. .start = AT91SAM9261_ID_US2,
  543. .end = AT91SAM9261_ID_US2,
  544. .flags = IORESOURCE_IRQ,
  545. },
  546. };
  547. static struct atmel_uart_data uart2_data = {
  548. .use_dma_tx = 1,
  549. .use_dma_rx = 1,
  550. };
  551. static struct platform_device at91sam9261_uart2_device = {
  552. .name = "atmel_usart",
  553. .id = 3,
  554. .dev = {
  555. .platform_data = &uart2_data,
  556. .coherent_dma_mask = 0xffffffff,
  557. },
  558. .resource = uart2_resources,
  559. .num_resources = ARRAY_SIZE(uart2_resources),
  560. };
  561. static inline void configure_usart2_pins(void)
  562. {
  563. at91_set_A_periph(AT91_PIN_PC15, 0); /* RXD2 */
  564. at91_set_A_periph(AT91_PIN_PC14, 1); /* TXD2 */
  565. }
  566. struct platform_device *at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
  567. struct platform_device *atmel_default_console_device; /* the serial console device */
  568. void __init at91_init_serial(struct at91_uart_config *config)
  569. {
  570. int i;
  571. /* Fill in list of supported UARTs */
  572. for (i = 0; i < config->nr_tty; i++) {
  573. switch (config->tty_map[i]) {
  574. case 0:
  575. configure_usart0_pins();
  576. at91_uarts[i] = &at91sam9261_uart0_device;
  577. at91_clock_associate("usart0_clk", &at91sam9261_uart0_device.dev, "usart");
  578. break;
  579. case 1:
  580. configure_usart1_pins();
  581. at91_uarts[i] = &at91sam9261_uart1_device;
  582. at91_clock_associate("usart1_clk", &at91sam9261_uart1_device.dev, "usart");
  583. break;
  584. case 2:
  585. configure_usart2_pins();
  586. at91_uarts[i] = &at91sam9261_uart2_device;
  587. at91_clock_associate("usart2_clk", &at91sam9261_uart2_device.dev, "usart");
  588. break;
  589. case 3:
  590. configure_dbgu_pins();
  591. at91_uarts[i] = &at91sam9261_dbgu_device;
  592. at91_clock_associate("mck", &at91sam9261_dbgu_device.dev, "usart");
  593. break;
  594. default:
  595. continue;
  596. }
  597. at91_uarts[i]->id = i; /* update ID number to mapped ID */
  598. }
  599. /* Set serial console device */
  600. if (config->console_tty < ATMEL_MAX_UART)
  601. atmel_default_console_device = at91_uarts[config->console_tty];
  602. if (!atmel_default_console_device)
  603. printk(KERN_INFO "AT91: No default serial console defined.\n");
  604. }
  605. void __init at91_add_device_serial(void)
  606. {
  607. int i;
  608. for (i = 0; i < ATMEL_MAX_UART; i++) {
  609. if (at91_uarts[i])
  610. platform_device_register(at91_uarts[i]);
  611. }
  612. }
  613. #else
  614. void __init at91_init_serial(struct at91_uart_config *config) {}
  615. void __init at91_add_device_serial(void) {}
  616. #endif
  617. /* -------------------------------------------------------------------- */
  618. /*
  619. * These devices are always present and don't need any board-specific
  620. * setup.
  621. */
  622. static int __init at91_add_standard_devices(void)
  623. {
  624. return 0;
  625. }
  626. arch_initcall(at91_add_standard_devices);