at91sam9263_devices.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942
  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. * AC97
  483. * -------------------------------------------------------------------- */
  484. #if defined(CONFIG_SND_AT91_AC97) || defined(CONFIG_SND_AT91_AC97_MODULE)
  485. static u64 ac97_dmamask = 0xffffffffUL;
  486. static struct atmel_ac97_data ac97_data;
  487. static struct resource ac97_resources[] = {
  488. [0] = {
  489. .start = AT91SAM9263_BASE_AC97C,
  490. .end = AT91SAM9263_BASE_AC97C + SZ_16K - 1,
  491. .flags = IORESOURCE_MEM,
  492. },
  493. [1] = {
  494. .start = AT91SAM9263_ID_AC97C,
  495. .end = AT91SAM9263_ID_AC97C,
  496. .flags = IORESOURCE_IRQ,
  497. },
  498. };
  499. static struct platform_device at91sam9263_ac97_device = {
  500. .name = "ac97c",
  501. .id = 1,
  502. .dev = {
  503. .dma_mask = &ac97_dmamask,
  504. .coherent_dma_mask = 0xffffffff,
  505. .platform_data = &ac97_data,
  506. },
  507. .resource = ac97_resources,
  508. .num_resources = ARRAY_SIZE(ac97_resources),
  509. };
  510. void __init at91_add_device_ac97(struct atmel_ac97_data *data)
  511. {
  512. if (!data)
  513. return;
  514. at91_set_A_periph(AT91_PIN_PB0, 0); /* AC97FS */
  515. at91_set_A_periph(AT91_PIN_PB1, 0); /* AC97CK */
  516. at91_set_A_periph(AT91_PIN_PB2, 0); /* AC97TX */
  517. at91_set_A_periph(AT91_PIN_PB3, 0); /* AC97RX */
  518. /* reset */
  519. if (data->reset_pin)
  520. at91_set_gpio_output(data->reset_pin, 0);
  521. ac97_data = *ek_data;
  522. platform_device_register(&at91sam9263_ac97_device);
  523. }
  524. #else
  525. void __init at91_add_device_ac97(struct atmel_ac97_data *data) {}
  526. #endif
  527. /* --------------------------------------------------------------------
  528. * LCD Controller
  529. * -------------------------------------------------------------------- */
  530. #if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
  531. static u64 lcdc_dmamask = 0xffffffffUL;
  532. static struct atmel_lcdfb_info lcdc_data;
  533. static struct resource lcdc_resources[] = {
  534. [0] = {
  535. .start = AT91SAM9263_LCDC_BASE,
  536. .end = AT91SAM9263_LCDC_BASE + SZ_4K - 1,
  537. .flags = IORESOURCE_MEM,
  538. },
  539. [1] = {
  540. .start = AT91SAM9263_ID_LCDC,
  541. .end = AT91SAM9263_ID_LCDC,
  542. .flags = IORESOURCE_IRQ,
  543. },
  544. };
  545. static struct platform_device at91_lcdc_device = {
  546. .name = "atmel_lcdfb",
  547. .id = 0,
  548. .dev = {
  549. .dma_mask = &lcdc_dmamask,
  550. .coherent_dma_mask = 0xffffffff,
  551. .platform_data = &lcdc_data,
  552. },
  553. .resource = lcdc_resources,
  554. .num_resources = ARRAY_SIZE(lcdc_resources),
  555. };
  556. void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data)
  557. {
  558. if (!data)
  559. return;
  560. at91_set_A_periph(AT91_PIN_PC1, 0); /* LCDHSYNC */
  561. at91_set_A_periph(AT91_PIN_PC2, 0); /* LCDDOTCK */
  562. at91_set_A_periph(AT91_PIN_PC3, 0); /* LCDDEN */
  563. at91_set_B_periph(AT91_PIN_PB9, 0); /* LCDCC */
  564. at91_set_A_periph(AT91_PIN_PC6, 0); /* LCDD2 */
  565. at91_set_A_periph(AT91_PIN_PC7, 0); /* LCDD3 */
  566. at91_set_A_periph(AT91_PIN_PC8, 0); /* LCDD4 */
  567. at91_set_A_periph(AT91_PIN_PC9, 0); /* LCDD5 */
  568. at91_set_A_periph(AT91_PIN_PC10, 0); /* LCDD6 */
  569. at91_set_A_periph(AT91_PIN_PC11, 0); /* LCDD7 */
  570. at91_set_A_periph(AT91_PIN_PC14, 0); /* LCDD10 */
  571. at91_set_A_periph(AT91_PIN_PC15, 0); /* LCDD11 */
  572. at91_set_A_periph(AT91_PIN_PC16, 0); /* LCDD12 */
  573. at91_set_B_periph(AT91_PIN_PC12, 0); /* LCDD13 */
  574. at91_set_A_periph(AT91_PIN_PC18, 0); /* LCDD14 */
  575. at91_set_A_periph(AT91_PIN_PC19, 0); /* LCDD15 */
  576. at91_set_A_periph(AT91_PIN_PC22, 0); /* LCDD18 */
  577. at91_set_A_periph(AT91_PIN_PC23, 0); /* LCDD19 */
  578. at91_set_A_periph(AT91_PIN_PC24, 0); /* LCDD20 */
  579. at91_set_B_periph(AT91_PIN_PC17, 0); /* LCDD21 */
  580. at91_set_A_periph(AT91_PIN_PC26, 0); /* LCDD22 */
  581. at91_set_A_periph(AT91_PIN_PC27, 0); /* LCDD23 */
  582. lcdc_data = *data;
  583. platform_device_register(&at91_lcdc_device);
  584. }
  585. #else
  586. void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data) {}
  587. #endif
  588. /* --------------------------------------------------------------------
  589. * LEDs
  590. * -------------------------------------------------------------------- */
  591. #if defined(CONFIG_LEDS)
  592. u8 at91_leds_cpu;
  593. u8 at91_leds_timer;
  594. void __init at91_init_leds(u8 cpu_led, u8 timer_led)
  595. {
  596. /* Enable GPIO to access the LEDs */
  597. at91_set_gpio_output(cpu_led, 1);
  598. at91_set_gpio_output(timer_led, 1);
  599. at91_leds_cpu = cpu_led;
  600. at91_leds_timer = timer_led;
  601. }
  602. #else
  603. void __init at91_init_leds(u8 cpu_led, u8 timer_led) {}
  604. #endif
  605. /* --------------------------------------------------------------------
  606. * UART
  607. * -------------------------------------------------------------------- */
  608. #if defined(CONFIG_SERIAL_ATMEL)
  609. static struct resource dbgu_resources[] = {
  610. [0] = {
  611. .start = AT91_VA_BASE_SYS + AT91_DBGU,
  612. .end = AT91_VA_BASE_SYS + AT91_DBGU + SZ_512 - 1,
  613. .flags = IORESOURCE_MEM,
  614. },
  615. [1] = {
  616. .start = AT91_ID_SYS,
  617. .end = AT91_ID_SYS,
  618. .flags = IORESOURCE_IRQ,
  619. },
  620. };
  621. static struct atmel_uart_data dbgu_data = {
  622. .use_dma_tx = 0,
  623. .use_dma_rx = 0, /* DBGU not capable of receive DMA */
  624. .regs = (void __iomem *)(AT91_VA_BASE_SYS + AT91_DBGU),
  625. };
  626. static struct platform_device at91sam9263_dbgu_device = {
  627. .name = "atmel_usart",
  628. .id = 0,
  629. .dev = {
  630. .platform_data = &dbgu_data,
  631. .coherent_dma_mask = 0xffffffff,
  632. },
  633. .resource = dbgu_resources,
  634. .num_resources = ARRAY_SIZE(dbgu_resources),
  635. };
  636. static inline void configure_dbgu_pins(void)
  637. {
  638. at91_set_A_periph(AT91_PIN_PC30, 0); /* DRXD */
  639. at91_set_A_periph(AT91_PIN_PC31, 1); /* DTXD */
  640. }
  641. static struct resource uart0_resources[] = {
  642. [0] = {
  643. .start = AT91SAM9263_BASE_US0,
  644. .end = AT91SAM9263_BASE_US0 + SZ_16K - 1,
  645. .flags = IORESOURCE_MEM,
  646. },
  647. [1] = {
  648. .start = AT91SAM9263_ID_US0,
  649. .end = AT91SAM9263_ID_US0,
  650. .flags = IORESOURCE_IRQ,
  651. },
  652. };
  653. static struct atmel_uart_data uart0_data = {
  654. .use_dma_tx = 1,
  655. .use_dma_rx = 1,
  656. };
  657. static struct platform_device at91sam9263_uart0_device = {
  658. .name = "atmel_usart",
  659. .id = 1,
  660. .dev = {
  661. .platform_data = &uart0_data,
  662. .coherent_dma_mask = 0xffffffff,
  663. },
  664. .resource = uart0_resources,
  665. .num_resources = ARRAY_SIZE(uart0_resources),
  666. };
  667. static inline void configure_usart0_pins(void)
  668. {
  669. at91_set_A_periph(AT91_PIN_PA26, 1); /* TXD0 */
  670. at91_set_A_periph(AT91_PIN_PA27, 0); /* RXD0 */
  671. at91_set_A_periph(AT91_PIN_PA28, 0); /* RTS0 */
  672. at91_set_A_periph(AT91_PIN_PA29, 0); /* CTS0 */
  673. }
  674. static struct resource uart1_resources[] = {
  675. [0] = {
  676. .start = AT91SAM9263_BASE_US1,
  677. .end = AT91SAM9263_BASE_US1 + SZ_16K - 1,
  678. .flags = IORESOURCE_MEM,
  679. },
  680. [1] = {
  681. .start = AT91SAM9263_ID_US1,
  682. .end = AT91SAM9263_ID_US1,
  683. .flags = IORESOURCE_IRQ,
  684. },
  685. };
  686. static struct atmel_uart_data uart1_data = {
  687. .use_dma_tx = 1,
  688. .use_dma_rx = 1,
  689. };
  690. static struct platform_device at91sam9263_uart1_device = {
  691. .name = "atmel_usart",
  692. .id = 2,
  693. .dev = {
  694. .platform_data = &uart1_data,
  695. .coherent_dma_mask = 0xffffffff,
  696. },
  697. .resource = uart1_resources,
  698. .num_resources = ARRAY_SIZE(uart1_resources),
  699. };
  700. static inline void configure_usart1_pins(void)
  701. {
  702. at91_set_A_periph(AT91_PIN_PD0, 1); /* TXD1 */
  703. at91_set_A_periph(AT91_PIN_PD1, 0); /* RXD1 */
  704. at91_set_B_periph(AT91_PIN_PD7, 0); /* RTS1 */
  705. at91_set_B_periph(AT91_PIN_PD8, 0); /* CTS1 */
  706. }
  707. static struct resource uart2_resources[] = {
  708. [0] = {
  709. .start = AT91SAM9263_BASE_US2,
  710. .end = AT91SAM9263_BASE_US2 + SZ_16K - 1,
  711. .flags = IORESOURCE_MEM,
  712. },
  713. [1] = {
  714. .start = AT91SAM9263_ID_US2,
  715. .end = AT91SAM9263_ID_US2,
  716. .flags = IORESOURCE_IRQ,
  717. },
  718. };
  719. static struct atmel_uart_data uart2_data = {
  720. .use_dma_tx = 1,
  721. .use_dma_rx = 1,
  722. };
  723. static struct platform_device at91sam9263_uart2_device = {
  724. .name = "atmel_usart",
  725. .id = 3,
  726. .dev = {
  727. .platform_data = &uart2_data,
  728. .coherent_dma_mask = 0xffffffff,
  729. },
  730. .resource = uart2_resources,
  731. .num_resources = ARRAY_SIZE(uart2_resources),
  732. };
  733. static inline void configure_usart2_pins(void)
  734. {
  735. at91_set_A_periph(AT91_PIN_PD2, 1); /* TXD2 */
  736. at91_set_A_periph(AT91_PIN_PD3, 0); /* RXD2 */
  737. at91_set_B_periph(AT91_PIN_PD5, 0); /* RTS2 */
  738. at91_set_B_periph(AT91_PIN_PD6, 0); /* CTS2 */
  739. }
  740. struct platform_device *at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
  741. struct platform_device *atmel_default_console_device; /* the serial console device */
  742. void __init at91_init_serial(struct at91_uart_config *config)
  743. {
  744. int i;
  745. /* Fill in list of supported UARTs */
  746. for (i = 0; i < config->nr_tty; i++) {
  747. switch (config->tty_map[i]) {
  748. case 0:
  749. configure_usart0_pins();
  750. at91_uarts[i] = &at91sam9263_uart0_device;
  751. at91_clock_associate("usart0_clk", &at91sam9263_uart0_device.dev, "usart");
  752. break;
  753. case 1:
  754. configure_usart1_pins();
  755. at91_uarts[i] = &at91sam9263_uart1_device;
  756. at91_clock_associate("usart1_clk", &at91sam9263_uart1_device.dev, "usart");
  757. break;
  758. case 2:
  759. configure_usart2_pins();
  760. at91_uarts[i] = &at91sam9263_uart2_device;
  761. at91_clock_associate("usart2_clk", &at91sam9263_uart2_device.dev, "usart");
  762. break;
  763. case 3:
  764. configure_dbgu_pins();
  765. at91_uarts[i] = &at91sam9263_dbgu_device;
  766. at91_clock_associate("mck", &at91sam9263_dbgu_device.dev, "usart");
  767. break;
  768. default:
  769. continue;
  770. }
  771. at91_uarts[i]->id = i; /* update ID number to mapped ID */
  772. }
  773. /* Set serial console device */
  774. if (config->console_tty < ATMEL_MAX_UART)
  775. atmel_default_console_device = at91_uarts[config->console_tty];
  776. if (!atmel_default_console_device)
  777. printk(KERN_INFO "AT91: No default serial console defined.\n");
  778. }
  779. void __init at91_add_device_serial(void)
  780. {
  781. int i;
  782. for (i = 0; i < ATMEL_MAX_UART; i++) {
  783. if (at91_uarts[i])
  784. platform_device_register(at91_uarts[i]);
  785. }
  786. }
  787. #else
  788. void __init at91_init_serial(struct at91_uart_config *config) {}
  789. void __init at91_add_device_serial(void) {}
  790. #endif
  791. /* -------------------------------------------------------------------- */
  792. /*
  793. * These devices are always present and don't need any board-specific
  794. * setup.
  795. */
  796. static int __init at91_add_standard_devices(void)
  797. {
  798. return 0;
  799. }
  800. arch_initcall(at91_add_standard_devices);