at91sam9263_devices.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818
  1. /*
  2. * arch/arm/mach-at91/at91sam9263_devices.c
  3. *
  4. * Copyright (C) 2007 Atmel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. */
  12. #include <asm/mach/arch.h>
  13. #include <asm/mach/map.h>
  14. #include <linux/platform_device.h>
  15. #include <asm/arch/board.h>
  16. #include <asm/arch/gpio.h>
  17. #include <asm/arch/at91sam9263.h>
  18. #include <asm/arch/at91sam926x_mc.h>
  19. #include <asm/arch/at91sam9263_matrix.h>
  20. #include "generic.h"
  21. #define SZ_512 0x00000200
  22. #define SZ_256 0x00000100
  23. #define SZ_16 0x00000010
  24. /* --------------------------------------------------------------------
  25. * USB Host
  26. * -------------------------------------------------------------------- */
  27. #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
  28. static u64 ohci_dmamask = 0xffffffffUL;
  29. static struct at91_usbh_data usbh_data;
  30. static struct resource usbh_resources[] = {
  31. [0] = {
  32. .start = AT91SAM9263_UHP_BASE,
  33. .end = AT91SAM9263_UHP_BASE + SZ_1M - 1,
  34. .flags = IORESOURCE_MEM,
  35. },
  36. [1] = {
  37. .start = AT91SAM9263_ID_UHP,
  38. .end = AT91SAM9263_ID_UHP,
  39. .flags = IORESOURCE_IRQ,
  40. },
  41. };
  42. static struct platform_device at91_usbh_device = {
  43. .name = "at91_ohci",
  44. .id = -1,
  45. .dev = {
  46. .dma_mask = &ohci_dmamask,
  47. .coherent_dma_mask = 0xffffffff,
  48. .platform_data = &usbh_data,
  49. },
  50. .resource = usbh_resources,
  51. .num_resources = ARRAY_SIZE(usbh_resources),
  52. };
  53. void __init at91_add_device_usbh(struct at91_usbh_data *data)
  54. {
  55. int i;
  56. if (!data)
  57. return;
  58. /* Enable VBus control for UHP ports */
  59. for (i = 0; i < data->ports; i++) {
  60. if (data->vbus_pin[i])
  61. at91_set_gpio_output(data->vbus_pin[i], 0);
  62. }
  63. usbh_data = *data;
  64. platform_device_register(&at91_usbh_device);
  65. }
  66. #else
  67. void __init at91_add_device_usbh(struct at91_usbh_data *data) {}
  68. #endif
  69. /* --------------------------------------------------------------------
  70. * USB Device (Gadget)
  71. * -------------------------------------------------------------------- */
  72. #ifdef CONFIG_USB_GADGET_AT91
  73. static struct at91_udc_data udc_data;
  74. static struct resource udc_resources[] = {
  75. [0] = {
  76. .start = AT91SAM9263_BASE_UDP,
  77. .end = AT91SAM9263_BASE_UDP + SZ_16K - 1,
  78. .flags = IORESOURCE_MEM,
  79. },
  80. [1] = {
  81. .start = AT91SAM9263_ID_UDP,
  82. .end = AT91SAM9263_ID_UDP,
  83. .flags = IORESOURCE_IRQ,
  84. },
  85. };
  86. static struct platform_device at91_udc_device = {
  87. .name = "at91_udc",
  88. .id = -1,
  89. .dev = {
  90. .platform_data = &udc_data,
  91. },
  92. .resource = udc_resources,
  93. .num_resources = ARRAY_SIZE(udc_resources),
  94. };
  95. void __init at91_add_device_udc(struct at91_udc_data *data)
  96. {
  97. if (!data)
  98. return;
  99. if (data->vbus_pin) {
  100. at91_set_gpio_input(data->vbus_pin, 0);
  101. at91_set_deglitch(data->vbus_pin, 1);
  102. }
  103. /* Pullup pin is handled internally by USB device peripheral */
  104. udc_data = *data;
  105. platform_device_register(&at91_udc_device);
  106. }
  107. #else
  108. void __init at91_add_device_udc(struct at91_udc_data *data) {}
  109. #endif
  110. /* --------------------------------------------------------------------
  111. * Ethernet
  112. * -------------------------------------------------------------------- */
  113. #if defined(CONFIG_MACB) || defined(CONFIG_MACB_MODULE)
  114. static u64 eth_dmamask = 0xffffffffUL;
  115. static struct at91_eth_data eth_data;
  116. static struct resource eth_resources[] = {
  117. [0] = {
  118. .start = AT91SAM9263_BASE_EMAC,
  119. .end = AT91SAM9263_BASE_EMAC + SZ_16K - 1,
  120. .flags = IORESOURCE_MEM,
  121. },
  122. [1] = {
  123. .start = AT91SAM9263_ID_EMAC,
  124. .end = AT91SAM9263_ID_EMAC,
  125. .flags = IORESOURCE_IRQ,
  126. },
  127. };
  128. static struct platform_device at91sam9263_eth_device = {
  129. .name = "macb",
  130. .id = -1,
  131. .dev = {
  132. .dma_mask = &eth_dmamask,
  133. .coherent_dma_mask = 0xffffffff,
  134. .platform_data = &eth_data,
  135. },
  136. .resource = eth_resources,
  137. .num_resources = ARRAY_SIZE(eth_resources),
  138. };
  139. void __init at91_add_device_eth(struct at91_eth_data *data)
  140. {
  141. if (!data)
  142. return;
  143. if (data->phy_irq_pin) {
  144. at91_set_gpio_input(data->phy_irq_pin, 0);
  145. at91_set_deglitch(data->phy_irq_pin, 1);
  146. }
  147. /* Pins used for MII and RMII */
  148. at91_set_A_periph(AT91_PIN_PE21, 0); /* ETXCK_EREFCK */
  149. at91_set_B_periph(AT91_PIN_PC25, 0); /* ERXDV */
  150. at91_set_A_periph(AT91_PIN_PE25, 0); /* ERX0 */
  151. at91_set_A_periph(AT91_PIN_PE26, 0); /* ERX1 */
  152. at91_set_A_periph(AT91_PIN_PE27, 0); /* ERXER */
  153. at91_set_A_periph(AT91_PIN_PE28, 0); /* ETXEN */
  154. at91_set_A_periph(AT91_PIN_PE23, 0); /* ETX0 */
  155. at91_set_A_periph(AT91_PIN_PE24, 0); /* ETX1 */
  156. at91_set_A_periph(AT91_PIN_PE30, 0); /* EMDIO */
  157. at91_set_A_periph(AT91_PIN_PE29, 0); /* EMDC */
  158. if (!data->is_rmii) {
  159. at91_set_A_periph(AT91_PIN_PE22, 0); /* ECRS */
  160. at91_set_B_periph(AT91_PIN_PC26, 0); /* ECOL */
  161. at91_set_B_periph(AT91_PIN_PC22, 0); /* ERX2 */
  162. at91_set_B_periph(AT91_PIN_PC23, 0); /* ERX3 */
  163. at91_set_B_periph(AT91_PIN_PC27, 0); /* ERXCK */
  164. at91_set_B_periph(AT91_PIN_PC20, 0); /* ETX2 */
  165. at91_set_B_periph(AT91_PIN_PC21, 0); /* ETX3 */
  166. at91_set_B_periph(AT91_PIN_PC24, 0); /* ETXER */
  167. }
  168. eth_data = *data;
  169. platform_device_register(&at91sam9263_eth_device);
  170. }
  171. #else
  172. void __init at91_add_device_eth(struct at91_eth_data *data) {}
  173. #endif
  174. /* --------------------------------------------------------------------
  175. * MMC / SD
  176. * -------------------------------------------------------------------- */
  177. #if defined(CONFIG_MMC_AT91) || defined(CONFIG_MMC_AT91_MODULE)
  178. static u64 mmc_dmamask = 0xffffffffUL;
  179. static struct at91_mmc_data mmc0_data, mmc1_data;
  180. static struct resource mmc0_resources[] = {
  181. [0] = {
  182. .start = AT91SAM9263_BASE_MCI0,
  183. .end = AT91SAM9263_BASE_MCI0 + SZ_16K - 1,
  184. .flags = IORESOURCE_MEM,
  185. },
  186. [1] = {
  187. .start = AT91SAM9263_ID_MCI0,
  188. .end = AT91SAM9263_ID_MCI0,
  189. .flags = IORESOURCE_IRQ,
  190. },
  191. };
  192. static struct platform_device at91sam9263_mmc0_device = {
  193. .name = "at91_mci",
  194. .id = 0,
  195. .dev = {
  196. .dma_mask = &mmc_dmamask,
  197. .coherent_dma_mask = 0xffffffff,
  198. .platform_data = &mmc0_data,
  199. },
  200. .resource = mmc0_resources,
  201. .num_resources = ARRAY_SIZE(mmc0_resources),
  202. };
  203. static struct resource mmc1_resources[] = {
  204. [0] = {
  205. .start = AT91SAM9263_BASE_MCI1,
  206. .end = AT91SAM9263_BASE_MCI1 + SZ_16K - 1,
  207. .flags = IORESOURCE_MEM,
  208. },
  209. [1] = {
  210. .start = AT91SAM9263_ID_MCI1,
  211. .end = AT91SAM9263_ID_MCI1,
  212. .flags = IORESOURCE_IRQ,
  213. },
  214. };
  215. static struct platform_device at91sam9263_mmc1_device = {
  216. .name = "at91_mci",
  217. .id = 1,
  218. .dev = {
  219. .dma_mask = &mmc_dmamask,
  220. .coherent_dma_mask = 0xffffffff,
  221. .platform_data = &mmc1_data,
  222. },
  223. .resource = mmc1_resources,
  224. .num_resources = ARRAY_SIZE(mmc1_resources),
  225. };
  226. void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data)
  227. {
  228. if (!data)
  229. return;
  230. /* input/irq */
  231. if (data->det_pin) {
  232. at91_set_gpio_input(data->det_pin, 1);
  233. at91_set_deglitch(data->det_pin, 1);
  234. }
  235. if (data->wp_pin)
  236. at91_set_gpio_input(data->wp_pin, 1);
  237. if (data->vcc_pin)
  238. at91_set_gpio_output(data->vcc_pin, 0);
  239. if (mmc_id == 0) { /* MCI0 */
  240. /* CLK */
  241. at91_set_A_periph(AT91_PIN_PA12, 0);
  242. if (data->slot_b) {
  243. /* CMD */
  244. at91_set_A_periph(AT91_PIN_PA16, 1);
  245. /* DAT0, maybe DAT1..DAT3 */
  246. at91_set_A_periph(AT91_PIN_PA17, 1);
  247. if (data->wire4) {
  248. at91_set_A_periph(AT91_PIN_PA18, 1);
  249. at91_set_A_periph(AT91_PIN_PA19, 1);
  250. at91_set_A_periph(AT91_PIN_PA20, 1);
  251. }
  252. } else {
  253. /* CMD */
  254. at91_set_A_periph(AT91_PIN_PA1, 1);
  255. /* DAT0, maybe DAT1..DAT3 */
  256. at91_set_A_periph(AT91_PIN_PA0, 1);
  257. if (data->wire4) {
  258. at91_set_A_periph(AT91_PIN_PA3, 1);
  259. at91_set_A_periph(AT91_PIN_PA4, 1);
  260. at91_set_A_periph(AT91_PIN_PA5, 1);
  261. }
  262. }
  263. mmc0_data = *data;
  264. at91_clock_associate("mci0_clk", &at91sam9263_mmc1_device.dev, "mci_clk");
  265. platform_device_register(&at91sam9263_mmc0_device);
  266. } else { /* MCI1 */
  267. /* CLK */
  268. at91_set_A_periph(AT91_PIN_PA6, 0);
  269. if (data->slot_b) {
  270. /* CMD */
  271. at91_set_A_periph(AT91_PIN_PA21, 1);
  272. /* DAT0, maybe DAT1..DAT3 */
  273. at91_set_A_periph(AT91_PIN_PA22, 1);
  274. if (data->wire4) {
  275. at91_set_A_periph(AT91_PIN_PA23, 1);
  276. at91_set_A_periph(AT91_PIN_PA24, 1);
  277. at91_set_A_periph(AT91_PIN_PA25, 1);
  278. }
  279. } else {
  280. /* CMD */
  281. at91_set_A_periph(AT91_PIN_PA7, 1);
  282. /* DAT0, maybe DAT1..DAT3 */
  283. at91_set_A_periph(AT91_PIN_PA8, 1);
  284. if (data->wire4) {
  285. at91_set_A_periph(AT91_PIN_PA9, 1);
  286. at91_set_A_periph(AT91_PIN_PA10, 1);
  287. at91_set_A_periph(AT91_PIN_PA11, 1);
  288. }
  289. }
  290. mmc1_data = *data;
  291. at91_clock_associate("mci1_clk", &at91sam9263_mmc1_device.dev, "mci_clk");
  292. platform_device_register(&at91sam9263_mmc1_device);
  293. }
  294. }
  295. #else
  296. void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data) {}
  297. #endif
  298. /* --------------------------------------------------------------------
  299. * NAND / SmartMedia
  300. * -------------------------------------------------------------------- */
  301. #if defined(CONFIG_MTD_NAND_AT91) || defined(CONFIG_MTD_NAND_AT91_MODULE)
  302. static struct at91_nand_data nand_data;
  303. #define NAND_BASE AT91_CHIPSELECT_3
  304. static struct resource nand_resources[] = {
  305. {
  306. .start = NAND_BASE,
  307. .end = NAND_BASE + SZ_256M - 1,
  308. .flags = IORESOURCE_MEM,
  309. }
  310. };
  311. static struct platform_device at91sam9263_nand_device = {
  312. .name = "at91_nand",
  313. .id = -1,
  314. .dev = {
  315. .platform_data = &nand_data,
  316. },
  317. .resource = nand_resources,
  318. .num_resources = ARRAY_SIZE(nand_resources),
  319. };
  320. void __init at91_add_device_nand(struct at91_nand_data *data)
  321. {
  322. unsigned long csa, mode;
  323. if (!data)
  324. return;
  325. csa = at91_sys_read(AT91_MATRIX_EBI0CSA);
  326. at91_sys_write(AT91_MATRIX_EBI0CSA, csa | AT91_MATRIX_EBI0_CS3A_SMC);
  327. /* set the bus interface characteristics */
  328. at91_sys_write(AT91_SMC_SETUP(3), AT91_SMC_NWESETUP_(0) | AT91_SMC_NCS_WRSETUP_(0)
  329. | AT91_SMC_NRDSETUP_(0) | AT91_SMC_NCS_RDSETUP_(0));
  330. at91_sys_write(AT91_SMC_PULSE(3), AT91_SMC_NWEPULSE_(3) | AT91_SMC_NCS_WRPULSE_(3)
  331. | AT91_SMC_NRDPULSE_(3) | AT91_SMC_NCS_RDPULSE_(3));
  332. at91_sys_write(AT91_SMC_CYCLE(3), AT91_SMC_NWECYCLE_(5) | AT91_SMC_NRDCYCLE_(5));
  333. if (data->bus_width_16)
  334. mode = AT91_SMC_DBW_16;
  335. else
  336. mode = AT91_SMC_DBW_8;
  337. at91_sys_write(AT91_SMC_MODE(3), mode | AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_TDF_(2));
  338. /* enable pin */
  339. if (data->enable_pin)
  340. at91_set_gpio_output(data->enable_pin, 1);
  341. /* ready/busy pin */
  342. if (data->rdy_pin)
  343. at91_set_gpio_input(data->rdy_pin, 1);
  344. /* card detect pin */
  345. if (data->det_pin)
  346. at91_set_gpio_input(data->det_pin, 1);
  347. nand_data = *data;
  348. platform_device_register(&at91sam9263_nand_device);
  349. }
  350. #else
  351. void __init at91_add_device_nand(struct at91_nand_data *data) {}
  352. #endif
  353. /* --------------------------------------------------------------------
  354. * TWI (i2c)
  355. * -------------------------------------------------------------------- */
  356. #if defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
  357. static struct resource twi_resources[] = {
  358. [0] = {
  359. .start = AT91SAM9263_BASE_TWI,
  360. .end = AT91SAM9263_BASE_TWI + SZ_16K - 1,
  361. .flags = IORESOURCE_MEM,
  362. },
  363. [1] = {
  364. .start = AT91SAM9263_ID_TWI,
  365. .end = AT91SAM9263_ID_TWI,
  366. .flags = IORESOURCE_IRQ,
  367. },
  368. };
  369. static struct platform_device at91sam9263_twi_device = {
  370. .name = "at91_i2c",
  371. .id = -1,
  372. .resource = twi_resources,
  373. .num_resources = ARRAY_SIZE(twi_resources),
  374. };
  375. void __init at91_add_device_i2c(void)
  376. {
  377. /* pins used for TWI interface */
  378. at91_set_A_periph(AT91_PIN_PB4, 0); /* TWD */
  379. at91_set_multi_drive(AT91_PIN_PB4, 1);
  380. at91_set_A_periph(AT91_PIN_PB5, 0); /* TWCK */
  381. at91_set_multi_drive(AT91_PIN_PB5, 1);
  382. platform_device_register(&at91sam9263_twi_device);
  383. }
  384. #else
  385. void __init at91_add_device_i2c(void) {}
  386. #endif
  387. /* --------------------------------------------------------------------
  388. * SPI
  389. * -------------------------------------------------------------------- */
  390. #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
  391. static u64 spi_dmamask = 0xffffffffUL;
  392. static struct resource spi0_resources[] = {
  393. [0] = {
  394. .start = AT91SAM9263_BASE_SPI0,
  395. .end = AT91SAM9263_BASE_SPI0 + SZ_16K - 1,
  396. .flags = IORESOURCE_MEM,
  397. },
  398. [1] = {
  399. .start = AT91SAM9263_ID_SPI0,
  400. .end = AT91SAM9263_ID_SPI0,
  401. .flags = IORESOURCE_IRQ,
  402. },
  403. };
  404. static struct platform_device at91sam9263_spi0_device = {
  405. .name = "atmel_spi",
  406. .id = 0,
  407. .dev = {
  408. .dma_mask = &spi_dmamask,
  409. .coherent_dma_mask = 0xffffffff,
  410. },
  411. .resource = spi0_resources,
  412. .num_resources = ARRAY_SIZE(spi0_resources),
  413. };
  414. static const unsigned spi0_standard_cs[4] = { AT91_PIN_PA5, AT91_PIN_PA3, AT91_PIN_PA4, AT91_PIN_PB11 };
  415. static struct resource spi1_resources[] = {
  416. [0] = {
  417. .start = AT91SAM9263_BASE_SPI1,
  418. .end = AT91SAM9263_BASE_SPI1 + SZ_16K - 1,
  419. .flags = IORESOURCE_MEM,
  420. },
  421. [1] = {
  422. .start = AT91SAM9263_ID_SPI1,
  423. .end = AT91SAM9263_ID_SPI1,
  424. .flags = IORESOURCE_IRQ,
  425. },
  426. };
  427. static struct platform_device at91sam9263_spi1_device = {
  428. .name = "atmel_spi",
  429. .id = 1,
  430. .dev = {
  431. .dma_mask = &spi_dmamask,
  432. .coherent_dma_mask = 0xffffffff,
  433. },
  434. .resource = spi1_resources,
  435. .num_resources = ARRAY_SIZE(spi1_resources),
  436. };
  437. static const unsigned spi1_standard_cs[4] = { AT91_PIN_PB15, AT91_PIN_PB16, AT91_PIN_PB17, AT91_PIN_PB18 };
  438. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
  439. {
  440. int i;
  441. unsigned long cs_pin;
  442. short enable_spi0 = 0;
  443. short enable_spi1 = 0;
  444. /* Choose SPI chip-selects */
  445. for (i = 0; i < nr_devices; i++) {
  446. if (devices[i].controller_data)
  447. cs_pin = (unsigned long) devices[i].controller_data;
  448. else if (devices[i].bus_num == 0)
  449. cs_pin = spi0_standard_cs[devices[i].chip_select];
  450. else
  451. cs_pin = spi1_standard_cs[devices[i].chip_select];
  452. if (devices[i].bus_num == 0)
  453. enable_spi0 = 1;
  454. else
  455. enable_spi1 = 1;
  456. /* enable chip-select pin */
  457. at91_set_gpio_output(cs_pin, 1);
  458. /* pass chip-select pin to driver */
  459. devices[i].controller_data = (void *) cs_pin;
  460. }
  461. spi_register_board_info(devices, nr_devices);
  462. /* Configure SPI bus(es) */
  463. if (enable_spi0) {
  464. at91_set_B_periph(AT91_PIN_PA0, 0); /* SPI0_MISO */
  465. at91_set_B_periph(AT91_PIN_PA1, 0); /* SPI0_MOSI */
  466. at91_set_B_periph(AT91_PIN_PA2, 0); /* SPI0_SPCK */
  467. at91_clock_associate("spi0_clk", &at91sam9263_spi0_device.dev, "spi_clk");
  468. platform_device_register(&at91sam9263_spi0_device);
  469. }
  470. if (enable_spi1) {
  471. at91_set_A_periph(AT91_PIN_PB12, 0); /* SPI1_MISO */
  472. at91_set_A_periph(AT91_PIN_PB13, 0); /* SPI1_MOSI */
  473. at91_set_A_periph(AT91_PIN_PB14, 0); /* SPI1_SPCK */
  474. at91_clock_associate("spi1_clk", &at91sam9263_spi1_device.dev, "spi_clk");
  475. platform_device_register(&at91sam9263_spi1_device);
  476. }
  477. }
  478. #else
  479. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
  480. #endif
  481. /* --------------------------------------------------------------------
  482. * LEDs
  483. * -------------------------------------------------------------------- */
  484. #if defined(CONFIG_LEDS)
  485. u8 at91_leds_cpu;
  486. u8 at91_leds_timer;
  487. void __init at91_init_leds(u8 cpu_led, u8 timer_led)
  488. {
  489. /* Enable GPIO to access the LEDs */
  490. at91_set_gpio_output(cpu_led, 1);
  491. at91_set_gpio_output(timer_led, 1);
  492. at91_leds_cpu = cpu_led;
  493. at91_leds_timer = timer_led;
  494. }
  495. #else
  496. void __init at91_init_leds(u8 cpu_led, u8 timer_led) {}
  497. #endif
  498. /* --------------------------------------------------------------------
  499. * UART
  500. * -------------------------------------------------------------------- */
  501. #if defined(CONFIG_SERIAL_ATMEL)
  502. static struct resource dbgu_resources[] = {
  503. [0] = {
  504. .start = AT91_VA_BASE_SYS + AT91_DBGU,
  505. .end = AT91_VA_BASE_SYS + AT91_DBGU + SZ_512 - 1,
  506. .flags = IORESOURCE_MEM,
  507. },
  508. [1] = {
  509. .start = AT91_ID_SYS,
  510. .end = AT91_ID_SYS,
  511. .flags = IORESOURCE_IRQ,
  512. },
  513. };
  514. static struct atmel_uart_data dbgu_data = {
  515. .use_dma_tx = 0,
  516. .use_dma_rx = 0, /* DBGU not capable of receive DMA */
  517. .regs = (void __iomem *)(AT91_VA_BASE_SYS + AT91_DBGU),
  518. };
  519. static struct platform_device at91sam9263_dbgu_device = {
  520. .name = "atmel_usart",
  521. .id = 0,
  522. .dev = {
  523. .platform_data = &dbgu_data,
  524. .coherent_dma_mask = 0xffffffff,
  525. },
  526. .resource = dbgu_resources,
  527. .num_resources = ARRAY_SIZE(dbgu_resources),
  528. };
  529. static inline void configure_dbgu_pins(void)
  530. {
  531. at91_set_A_periph(AT91_PIN_PC30, 0); /* DRXD */
  532. at91_set_A_periph(AT91_PIN_PC31, 1); /* DTXD */
  533. }
  534. static struct resource uart0_resources[] = {
  535. [0] = {
  536. .start = AT91SAM9263_BASE_US0,
  537. .end = AT91SAM9263_BASE_US0 + SZ_16K - 1,
  538. .flags = IORESOURCE_MEM,
  539. },
  540. [1] = {
  541. .start = AT91SAM9263_ID_US0,
  542. .end = AT91SAM9263_ID_US0,
  543. .flags = IORESOURCE_IRQ,
  544. },
  545. };
  546. static struct atmel_uart_data uart0_data = {
  547. .use_dma_tx = 1,
  548. .use_dma_rx = 1,
  549. };
  550. static struct platform_device at91sam9263_uart0_device = {
  551. .name = "atmel_usart",
  552. .id = 1,
  553. .dev = {
  554. .platform_data = &uart0_data,
  555. .coherent_dma_mask = 0xffffffff,
  556. },
  557. .resource = uart0_resources,
  558. .num_resources = ARRAY_SIZE(uart0_resources),
  559. };
  560. static inline void configure_usart0_pins(void)
  561. {
  562. at91_set_A_periph(AT91_PIN_PA26, 1); /* TXD0 */
  563. at91_set_A_periph(AT91_PIN_PA27, 0); /* RXD0 */
  564. at91_set_A_periph(AT91_PIN_PA28, 0); /* RTS0 */
  565. at91_set_A_periph(AT91_PIN_PA29, 0); /* CTS0 */
  566. }
  567. static struct resource uart1_resources[] = {
  568. [0] = {
  569. .start = AT91SAM9263_BASE_US1,
  570. .end = AT91SAM9263_BASE_US1 + SZ_16K - 1,
  571. .flags = IORESOURCE_MEM,
  572. },
  573. [1] = {
  574. .start = AT91SAM9263_ID_US1,
  575. .end = AT91SAM9263_ID_US1,
  576. .flags = IORESOURCE_IRQ,
  577. },
  578. };
  579. static struct atmel_uart_data uart1_data = {
  580. .use_dma_tx = 1,
  581. .use_dma_rx = 1,
  582. };
  583. static struct platform_device at91sam9263_uart1_device = {
  584. .name = "atmel_usart",
  585. .id = 2,
  586. .dev = {
  587. .platform_data = &uart1_data,
  588. .coherent_dma_mask = 0xffffffff,
  589. },
  590. .resource = uart1_resources,
  591. .num_resources = ARRAY_SIZE(uart1_resources),
  592. };
  593. static inline void configure_usart1_pins(void)
  594. {
  595. at91_set_A_periph(AT91_PIN_PD0, 1); /* TXD1 */
  596. at91_set_A_periph(AT91_PIN_PD1, 0); /* RXD1 */
  597. at91_set_B_periph(AT91_PIN_PD7, 0); /* RTS1 */
  598. at91_set_B_periph(AT91_PIN_PD8, 0); /* CTS1 */
  599. }
  600. static struct resource uart2_resources[] = {
  601. [0] = {
  602. .start = AT91SAM9263_BASE_US2,
  603. .end = AT91SAM9263_BASE_US2 + SZ_16K - 1,
  604. .flags = IORESOURCE_MEM,
  605. },
  606. [1] = {
  607. .start = AT91SAM9263_ID_US2,
  608. .end = AT91SAM9263_ID_US2,
  609. .flags = IORESOURCE_IRQ,
  610. },
  611. };
  612. static struct atmel_uart_data uart2_data = {
  613. .use_dma_tx = 1,
  614. .use_dma_rx = 1,
  615. };
  616. static struct platform_device at91sam9263_uart2_device = {
  617. .name = "atmel_usart",
  618. .id = 3,
  619. .dev = {
  620. .platform_data = &uart2_data,
  621. .coherent_dma_mask = 0xffffffff,
  622. },
  623. .resource = uart2_resources,
  624. .num_resources = ARRAY_SIZE(uart2_resources),
  625. };
  626. static inline void configure_usart2_pins(void)
  627. {
  628. at91_set_A_periph(AT91_PIN_PD2, 1); /* TXD2 */
  629. at91_set_A_periph(AT91_PIN_PD3, 0); /* RXD2 */
  630. at91_set_B_periph(AT91_PIN_PD5, 0); /* RTS2 */
  631. at91_set_B_periph(AT91_PIN_PD6, 0); /* CTS2 */
  632. }
  633. struct platform_device *at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
  634. struct platform_device *atmel_default_console_device; /* the serial console device */
  635. void __init at91_init_serial(struct at91_uart_config *config)
  636. {
  637. int i;
  638. /* Fill in list of supported UARTs */
  639. for (i = 0; i < config->nr_tty; i++) {
  640. switch (config->tty_map[i]) {
  641. case 0:
  642. configure_usart0_pins();
  643. at91_uarts[i] = &at91sam9263_uart0_device;
  644. at91_clock_associate("usart0_clk", &at91sam9263_uart0_device.dev, "usart");
  645. break;
  646. case 1:
  647. configure_usart1_pins();
  648. at91_uarts[i] = &at91sam9263_uart1_device;
  649. at91_clock_associate("usart1_clk", &at91sam9263_uart1_device.dev, "usart");
  650. break;
  651. case 2:
  652. configure_usart2_pins();
  653. at91_uarts[i] = &at91sam9263_uart2_device;
  654. at91_clock_associate("usart2_clk", &at91sam9263_uart2_device.dev, "usart");
  655. break;
  656. case 3:
  657. configure_dbgu_pins();
  658. at91_uarts[i] = &at91sam9263_dbgu_device;
  659. at91_clock_associate("mck", &at91sam9263_dbgu_device.dev, "usart");
  660. break;
  661. default:
  662. continue;
  663. }
  664. at91_uarts[i]->id = i; /* update ID number to mapped ID */
  665. }
  666. /* Set serial console device */
  667. if (config->console_tty < ATMEL_MAX_UART)
  668. atmel_default_console_device = at91_uarts[config->console_tty];
  669. if (!atmel_default_console_device)
  670. printk(KERN_INFO "AT91: No default serial console defined.\n");
  671. }
  672. void __init at91_add_device_serial(void)
  673. {
  674. int i;
  675. for (i = 0; i < ATMEL_MAX_UART; i++) {
  676. if (at91_uarts[i])
  677. platform_device_register(at91_uarts[i]);
  678. }
  679. }
  680. #else
  681. void __init at91_init_serial(struct at91_uart_config *config) {}
  682. void __init at91_add_device_serial(void) {}
  683. #endif
  684. /* -------------------------------------------------------------------- */
  685. /*
  686. * These devices are always present and don't need any board-specific
  687. * setup.
  688. */
  689. static int __init at91_add_standard_devices(void)
  690. {
  691. return 0;
  692. }
  693. arch_initcall(at91_add_standard_devices);