at91cap9_devices.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071
  1. /*
  2. * arch/arm/mach-at91/at91cap9_devices.c
  3. *
  4. * Copyright (C) 2007 Stelian Pop <stelian.pop@leadtechdesign.com>
  5. * Copyright (C) 2007 Lead Tech Design <www.leadtechdesign.com>
  6. * Copyright (C) 2007 Atmel Corporation.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. */
  14. #include <asm/mach/arch.h>
  15. #include <asm/mach/map.h>
  16. #include <linux/dma-mapping.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/mtd/physmap.h>
  19. #include <video/atmel_lcdc.h>
  20. #include <asm/arch/board.h>
  21. #include <asm/arch/gpio.h>
  22. #include <asm/arch/at91cap9.h>
  23. #include <asm/arch/at91cap9_matrix.h>
  24. #include <asm/arch/at91sam9_smc.h>
  25. #include "generic.h"
  26. /* --------------------------------------------------------------------
  27. * USB Host
  28. * -------------------------------------------------------------------- */
  29. #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
  30. static u64 ohci_dmamask = DMA_BIT_MASK(32);
  31. static struct at91_usbh_data usbh_data;
  32. static struct resource usbh_resources[] = {
  33. [0] = {
  34. .start = AT91CAP9_UHP_BASE,
  35. .end = AT91CAP9_UHP_BASE + SZ_1M - 1,
  36. .flags = IORESOURCE_MEM,
  37. },
  38. [1] = {
  39. .start = AT91CAP9_ID_UHP,
  40. .end = AT91CAP9_ID_UHP,
  41. .flags = IORESOURCE_IRQ,
  42. },
  43. };
  44. static struct platform_device at91_usbh_device = {
  45. .name = "at91_ohci",
  46. .id = -1,
  47. .dev = {
  48. .dma_mask = &ohci_dmamask,
  49. .coherent_dma_mask = DMA_BIT_MASK(32),
  50. .platform_data = &usbh_data,
  51. },
  52. .resource = usbh_resources,
  53. .num_resources = ARRAY_SIZE(usbh_resources),
  54. };
  55. void __init at91_add_device_usbh(struct at91_usbh_data *data)
  56. {
  57. int i;
  58. if (!data)
  59. return;
  60. /* Enable VBus control for UHP ports */
  61. for (i = 0; i < data->ports; i++) {
  62. if (data->vbus_pin[i])
  63. at91_set_gpio_output(data->vbus_pin[i], 0);
  64. }
  65. usbh_data = *data;
  66. platform_device_register(&at91_usbh_device);
  67. }
  68. #else
  69. void __init at91_add_device_usbh(struct at91_usbh_data *data) {}
  70. #endif
  71. /* --------------------------------------------------------------------
  72. * Ethernet
  73. * -------------------------------------------------------------------- */
  74. #if defined(CONFIG_MACB) || defined(CONFIG_MACB_MODULE)
  75. static u64 eth_dmamask = DMA_BIT_MASK(32);
  76. static struct at91_eth_data eth_data;
  77. static struct resource eth_resources[] = {
  78. [0] = {
  79. .start = AT91CAP9_BASE_EMAC,
  80. .end = AT91CAP9_BASE_EMAC + SZ_16K - 1,
  81. .flags = IORESOURCE_MEM,
  82. },
  83. [1] = {
  84. .start = AT91CAP9_ID_EMAC,
  85. .end = AT91CAP9_ID_EMAC,
  86. .flags = IORESOURCE_IRQ,
  87. },
  88. };
  89. static struct platform_device at91cap9_eth_device = {
  90. .name = "macb",
  91. .id = -1,
  92. .dev = {
  93. .dma_mask = &eth_dmamask,
  94. .coherent_dma_mask = DMA_BIT_MASK(32),
  95. .platform_data = &eth_data,
  96. },
  97. .resource = eth_resources,
  98. .num_resources = ARRAY_SIZE(eth_resources),
  99. };
  100. void __init at91_add_device_eth(struct at91_eth_data *data)
  101. {
  102. if (!data)
  103. return;
  104. if (data->phy_irq_pin) {
  105. at91_set_gpio_input(data->phy_irq_pin, 0);
  106. at91_set_deglitch(data->phy_irq_pin, 1);
  107. }
  108. /* Pins used for MII and RMII */
  109. at91_set_A_periph(AT91_PIN_PB21, 0); /* ETXCK_EREFCK */
  110. at91_set_A_periph(AT91_PIN_PB22, 0); /* ERXDV */
  111. at91_set_A_periph(AT91_PIN_PB25, 0); /* ERX0 */
  112. at91_set_A_periph(AT91_PIN_PB26, 0); /* ERX1 */
  113. at91_set_A_periph(AT91_PIN_PB27, 0); /* ERXER */
  114. at91_set_A_periph(AT91_PIN_PB28, 0); /* ETXEN */
  115. at91_set_A_periph(AT91_PIN_PB23, 0); /* ETX0 */
  116. at91_set_A_periph(AT91_PIN_PB24, 0); /* ETX1 */
  117. at91_set_A_periph(AT91_PIN_PB30, 0); /* EMDIO */
  118. at91_set_A_periph(AT91_PIN_PB29, 0); /* EMDC */
  119. if (!data->is_rmii) {
  120. at91_set_B_periph(AT91_PIN_PC25, 0); /* ECRS */
  121. at91_set_B_periph(AT91_PIN_PC26, 0); /* ECOL */
  122. at91_set_B_periph(AT91_PIN_PC22, 0); /* ERX2 */
  123. at91_set_B_periph(AT91_PIN_PC23, 0); /* ERX3 */
  124. at91_set_B_periph(AT91_PIN_PC27, 0); /* ERXCK */
  125. at91_set_B_periph(AT91_PIN_PC20, 0); /* ETX2 */
  126. at91_set_B_periph(AT91_PIN_PC21, 0); /* ETX3 */
  127. at91_set_B_periph(AT91_PIN_PC24, 0); /* ETXER */
  128. }
  129. eth_data = *data;
  130. platform_device_register(&at91cap9_eth_device);
  131. }
  132. #else
  133. void __init at91_add_device_eth(struct at91_eth_data *data) {}
  134. #endif
  135. /* --------------------------------------------------------------------
  136. * MMC / SD
  137. * -------------------------------------------------------------------- */
  138. #if defined(CONFIG_MMC_AT91) || defined(CONFIG_MMC_AT91_MODULE)
  139. static u64 mmc_dmamask = DMA_BIT_MASK(32);
  140. static struct at91_mmc_data mmc0_data, mmc1_data;
  141. static struct resource mmc0_resources[] = {
  142. [0] = {
  143. .start = AT91CAP9_BASE_MCI0,
  144. .end = AT91CAP9_BASE_MCI0 + SZ_16K - 1,
  145. .flags = IORESOURCE_MEM,
  146. },
  147. [1] = {
  148. .start = AT91CAP9_ID_MCI0,
  149. .end = AT91CAP9_ID_MCI0,
  150. .flags = IORESOURCE_IRQ,
  151. },
  152. };
  153. static struct platform_device at91cap9_mmc0_device = {
  154. .name = "at91_mci",
  155. .id = 0,
  156. .dev = {
  157. .dma_mask = &mmc_dmamask,
  158. .coherent_dma_mask = DMA_BIT_MASK(32),
  159. .platform_data = &mmc0_data,
  160. },
  161. .resource = mmc0_resources,
  162. .num_resources = ARRAY_SIZE(mmc0_resources),
  163. };
  164. static struct resource mmc1_resources[] = {
  165. [0] = {
  166. .start = AT91CAP9_BASE_MCI1,
  167. .end = AT91CAP9_BASE_MCI1 + SZ_16K - 1,
  168. .flags = IORESOURCE_MEM,
  169. },
  170. [1] = {
  171. .start = AT91CAP9_ID_MCI1,
  172. .end = AT91CAP9_ID_MCI1,
  173. .flags = IORESOURCE_IRQ,
  174. },
  175. };
  176. static struct platform_device at91cap9_mmc1_device = {
  177. .name = "at91_mci",
  178. .id = 1,
  179. .dev = {
  180. .dma_mask = &mmc_dmamask,
  181. .coherent_dma_mask = DMA_BIT_MASK(32),
  182. .platform_data = &mmc1_data,
  183. },
  184. .resource = mmc1_resources,
  185. .num_resources = ARRAY_SIZE(mmc1_resources),
  186. };
  187. void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data)
  188. {
  189. if (!data)
  190. return;
  191. /* input/irq */
  192. if (data->det_pin) {
  193. at91_set_gpio_input(data->det_pin, 1);
  194. at91_set_deglitch(data->det_pin, 1);
  195. }
  196. if (data->wp_pin)
  197. at91_set_gpio_input(data->wp_pin, 1);
  198. if (data->vcc_pin)
  199. at91_set_gpio_output(data->vcc_pin, 0);
  200. if (mmc_id == 0) { /* MCI0 */
  201. /* CLK */
  202. at91_set_A_periph(AT91_PIN_PA2, 0);
  203. /* CMD */
  204. at91_set_A_periph(AT91_PIN_PA1, 1);
  205. /* DAT0, maybe DAT1..DAT3 */
  206. at91_set_A_periph(AT91_PIN_PA0, 1);
  207. if (data->wire4) {
  208. at91_set_A_periph(AT91_PIN_PA3, 1);
  209. at91_set_A_periph(AT91_PIN_PA4, 1);
  210. at91_set_A_periph(AT91_PIN_PA5, 1);
  211. }
  212. mmc0_data = *data;
  213. at91_clock_associate("mci0_clk", &at91cap9_mmc1_device.dev, "mci_clk");
  214. platform_device_register(&at91cap9_mmc0_device);
  215. } else { /* MCI1 */
  216. /* CLK */
  217. at91_set_A_periph(AT91_PIN_PA16, 0);
  218. /* CMD */
  219. at91_set_A_periph(AT91_PIN_PA17, 1);
  220. /* DAT0, maybe DAT1..DAT3 */
  221. at91_set_A_periph(AT91_PIN_PA18, 1);
  222. if (data->wire4) {
  223. at91_set_A_periph(AT91_PIN_PA19, 1);
  224. at91_set_A_periph(AT91_PIN_PA20, 1);
  225. at91_set_A_periph(AT91_PIN_PA21, 1);
  226. }
  227. mmc1_data = *data;
  228. at91_clock_associate("mci1_clk", &at91cap9_mmc1_device.dev, "mci_clk");
  229. platform_device_register(&at91cap9_mmc1_device);
  230. }
  231. }
  232. #else
  233. void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data) {}
  234. #endif
  235. /* --------------------------------------------------------------------
  236. * NAND / SmartMedia
  237. * -------------------------------------------------------------------- */
  238. #if defined(CONFIG_MTD_NAND_AT91) || defined(CONFIG_MTD_NAND_AT91_MODULE)
  239. static struct at91_nand_data nand_data;
  240. #define NAND_BASE AT91_CHIPSELECT_3
  241. static struct resource nand_resources[] = {
  242. [0] = {
  243. .start = NAND_BASE,
  244. .end = NAND_BASE + SZ_256M - 1,
  245. .flags = IORESOURCE_MEM,
  246. },
  247. [1] = {
  248. .start = AT91_BASE_SYS + AT91_ECC,
  249. .end = AT91_BASE_SYS + AT91_ECC + SZ_512 - 1,
  250. .flags = IORESOURCE_MEM,
  251. }
  252. };
  253. static struct platform_device at91cap9_nand_device = {
  254. .name = "at91_nand",
  255. .id = -1,
  256. .dev = {
  257. .platform_data = &nand_data,
  258. },
  259. .resource = nand_resources,
  260. .num_resources = ARRAY_SIZE(nand_resources),
  261. };
  262. void __init at91_add_device_nand(struct at91_nand_data *data)
  263. {
  264. unsigned long csa, mode;
  265. if (!data)
  266. return;
  267. csa = at91_sys_read(AT91_MATRIX_EBICSA);
  268. at91_sys_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_EBI_CS3A_SMC_SMARTMEDIA | AT91_MATRIX_EBI_VDDIOMSEL_3_3V);
  269. /* set the bus interface characteristics */
  270. at91_sys_write(AT91_SMC_SETUP(3), AT91_SMC_NWESETUP_(2) | AT91_SMC_NCS_WRSETUP_(1)
  271. | AT91_SMC_NRDSETUP_(2) | AT91_SMC_NCS_RDSETUP_(1));
  272. at91_sys_write(AT91_SMC_PULSE(3), AT91_SMC_NWEPULSE_(4) | AT91_SMC_NCS_WRPULSE_(6)
  273. | AT91_SMC_NRDPULSE_(4) | AT91_SMC_NCS_RDPULSE_(6));
  274. at91_sys_write(AT91_SMC_CYCLE(3), AT91_SMC_NWECYCLE_(8) | AT91_SMC_NRDCYCLE_(8));
  275. if (data->bus_width_16)
  276. mode = AT91_SMC_DBW_16;
  277. else
  278. mode = AT91_SMC_DBW_8;
  279. at91_sys_write(AT91_SMC_MODE(3), mode | AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_TDF_(1));
  280. /* enable pin */
  281. if (data->enable_pin)
  282. at91_set_gpio_output(data->enable_pin, 1);
  283. /* ready/busy pin */
  284. if (data->rdy_pin)
  285. at91_set_gpio_input(data->rdy_pin, 1);
  286. /* card detect pin */
  287. if (data->det_pin)
  288. at91_set_gpio_input(data->det_pin, 1);
  289. nand_data = *data;
  290. platform_device_register(&at91cap9_nand_device);
  291. }
  292. #else
  293. void __init at91_add_device_nand(struct at91_nand_data *data) {}
  294. #endif
  295. /* --------------------------------------------------------------------
  296. * TWI (i2c)
  297. * -------------------------------------------------------------------- */
  298. /*
  299. * Prefer the GPIO code since the TWI controller isn't robust
  300. * (gets overruns and underruns under load) and can only issue
  301. * repeated STARTs in one scenario (the driver doesn't yet handle them).
  302. */
  303. #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
  304. static struct i2c_gpio_platform_data pdata = {
  305. .sda_pin = AT91_PIN_PB4,
  306. .sda_is_open_drain = 1,
  307. .scl_pin = AT91_PIN_PB5,
  308. .scl_is_open_drain = 1,
  309. .udelay = 2, /* ~100 kHz */
  310. };
  311. static struct platform_device at91cap9_twi_device = {
  312. .name = "i2c-gpio",
  313. .id = -1,
  314. .dev.platform_data = &pdata,
  315. };
  316. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  317. {
  318. at91_set_GPIO_periph(AT91_PIN_PB4, 1); /* TWD (SDA) */
  319. at91_set_multi_drive(AT91_PIN_PB4, 1);
  320. at91_set_GPIO_periph(AT91_PIN_PB5, 1); /* TWCK (SCL) */
  321. at91_set_multi_drive(AT91_PIN_PB5, 1);
  322. i2c_register_board_info(0, devices, nr_devices);
  323. platform_device_register(&at91cap9_twi_device);
  324. }
  325. #elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
  326. static struct resource twi_resources[] = {
  327. [0] = {
  328. .start = AT91CAP9_BASE_TWI,
  329. .end = AT91CAP9_BASE_TWI + SZ_16K - 1,
  330. .flags = IORESOURCE_MEM,
  331. },
  332. [1] = {
  333. .start = AT91CAP9_ID_TWI,
  334. .end = AT91CAP9_ID_TWI,
  335. .flags = IORESOURCE_IRQ,
  336. },
  337. };
  338. static struct platform_device at91cap9_twi_device = {
  339. .name = "at91_i2c",
  340. .id = -1,
  341. .resource = twi_resources,
  342. .num_resources = ARRAY_SIZE(twi_resources),
  343. };
  344. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  345. {
  346. /* pins used for TWI interface */
  347. at91_set_B_periph(AT91_PIN_PB4, 0); /* TWD */
  348. at91_set_multi_drive(AT91_PIN_PB4, 1);
  349. at91_set_B_periph(AT91_PIN_PB5, 0); /* TWCK */
  350. at91_set_multi_drive(AT91_PIN_PB5, 1);
  351. i2c_register_board_info(0, devices, nr_devices);
  352. platform_device_register(&at91cap9_twi_device);
  353. }
  354. #else
  355. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {}
  356. #endif
  357. /* --------------------------------------------------------------------
  358. * SPI
  359. * -------------------------------------------------------------------- */
  360. #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
  361. static u64 spi_dmamask = DMA_BIT_MASK(32);
  362. static struct resource spi0_resources[] = {
  363. [0] = {
  364. .start = AT91CAP9_BASE_SPI0,
  365. .end = AT91CAP9_BASE_SPI0 + SZ_16K - 1,
  366. .flags = IORESOURCE_MEM,
  367. },
  368. [1] = {
  369. .start = AT91CAP9_ID_SPI0,
  370. .end = AT91CAP9_ID_SPI0,
  371. .flags = IORESOURCE_IRQ,
  372. },
  373. };
  374. static struct platform_device at91cap9_spi0_device = {
  375. .name = "atmel_spi",
  376. .id = 0,
  377. .dev = {
  378. .dma_mask = &spi_dmamask,
  379. .coherent_dma_mask = DMA_BIT_MASK(32),
  380. },
  381. .resource = spi0_resources,
  382. .num_resources = ARRAY_SIZE(spi0_resources),
  383. };
  384. static const unsigned spi0_standard_cs[4] = { AT91_PIN_PA5, AT91_PIN_PA3, AT91_PIN_PD0, AT91_PIN_PD1 };
  385. static struct resource spi1_resources[] = {
  386. [0] = {
  387. .start = AT91CAP9_BASE_SPI1,
  388. .end = AT91CAP9_BASE_SPI1 + SZ_16K - 1,
  389. .flags = IORESOURCE_MEM,
  390. },
  391. [1] = {
  392. .start = AT91CAP9_ID_SPI1,
  393. .end = AT91CAP9_ID_SPI1,
  394. .flags = IORESOURCE_IRQ,
  395. },
  396. };
  397. static struct platform_device at91cap9_spi1_device = {
  398. .name = "atmel_spi",
  399. .id = 1,
  400. .dev = {
  401. .dma_mask = &spi_dmamask,
  402. .coherent_dma_mask = DMA_BIT_MASK(32),
  403. },
  404. .resource = spi1_resources,
  405. .num_resources = ARRAY_SIZE(spi1_resources),
  406. };
  407. static const unsigned spi1_standard_cs[4] = { AT91_PIN_PB15, AT91_PIN_PB16, AT91_PIN_PB17, AT91_PIN_PB18 };
  408. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
  409. {
  410. int i;
  411. unsigned long cs_pin;
  412. short enable_spi0 = 0;
  413. short enable_spi1 = 0;
  414. /* Choose SPI chip-selects */
  415. for (i = 0; i < nr_devices; i++) {
  416. if (devices[i].controller_data)
  417. cs_pin = (unsigned long) devices[i].controller_data;
  418. else if (devices[i].bus_num == 0)
  419. cs_pin = spi0_standard_cs[devices[i].chip_select];
  420. else
  421. cs_pin = spi1_standard_cs[devices[i].chip_select];
  422. if (devices[i].bus_num == 0)
  423. enable_spi0 = 1;
  424. else
  425. enable_spi1 = 1;
  426. /* enable chip-select pin */
  427. at91_set_gpio_output(cs_pin, 1);
  428. /* pass chip-select pin to driver */
  429. devices[i].controller_data = (void *) cs_pin;
  430. }
  431. spi_register_board_info(devices, nr_devices);
  432. /* Configure SPI bus(es) */
  433. if (enable_spi0) {
  434. at91_set_B_periph(AT91_PIN_PA0, 0); /* SPI0_MISO */
  435. at91_set_B_periph(AT91_PIN_PA1, 0); /* SPI0_MOSI */
  436. at91_set_B_periph(AT91_PIN_PA2, 0); /* SPI0_SPCK */
  437. at91_clock_associate("spi0_clk", &at91cap9_spi0_device.dev, "spi_clk");
  438. platform_device_register(&at91cap9_spi0_device);
  439. }
  440. if (enable_spi1) {
  441. at91_set_A_periph(AT91_PIN_PB12, 0); /* SPI1_MISO */
  442. at91_set_A_periph(AT91_PIN_PB13, 0); /* SPI1_MOSI */
  443. at91_set_A_periph(AT91_PIN_PB14, 0); /* SPI1_SPCK */
  444. at91_clock_associate("spi1_clk", &at91cap9_spi1_device.dev, "spi_clk");
  445. platform_device_register(&at91cap9_spi1_device);
  446. }
  447. }
  448. #else
  449. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
  450. #endif
  451. /* --------------------------------------------------------------------
  452. * RTT
  453. * -------------------------------------------------------------------- */
  454. static struct platform_device at91cap9_rtt_device = {
  455. .name = "at91_rtt",
  456. .id = -1,
  457. .num_resources = 0,
  458. };
  459. static void __init at91_add_device_rtt(void)
  460. {
  461. platform_device_register(&at91cap9_rtt_device);
  462. }
  463. /* --------------------------------------------------------------------
  464. * Watchdog
  465. * -------------------------------------------------------------------- */
  466. #if defined(CONFIG_AT91SAM9_WATCHDOG) || defined(CONFIG_AT91SAM9_WATCHDOG_MODULE)
  467. static struct platform_device at91cap9_wdt_device = {
  468. .name = "at91_wdt",
  469. .id = -1,
  470. .num_resources = 0,
  471. };
  472. static void __init at91_add_device_watchdog(void)
  473. {
  474. platform_device_register(&at91cap9_wdt_device);
  475. }
  476. #else
  477. static void __init at91_add_device_watchdog(void) {}
  478. #endif
  479. /* --------------------------------------------------------------------
  480. * AC97
  481. * -------------------------------------------------------------------- */
  482. #if defined(CONFIG_SND_AT91_AC97) || defined(CONFIG_SND_AT91_AC97_MODULE)
  483. static u64 ac97_dmamask = DMA_BIT_MASK(32);
  484. static struct atmel_ac97_data ac97_data;
  485. static struct resource ac97_resources[] = {
  486. [0] = {
  487. .start = AT91CAP9_BASE_AC97C,
  488. .end = AT91CAP9_BASE_AC97C + SZ_16K - 1,
  489. .flags = IORESOURCE_MEM,
  490. },
  491. [1] = {
  492. .start = AT91CAP9_ID_AC97C,
  493. .end = AT91CAP9_ID_AC97C,
  494. .flags = IORESOURCE_IRQ,
  495. },
  496. };
  497. static struct platform_device at91cap9_ac97_device = {
  498. .name = "ac97c",
  499. .id = 1,
  500. .dev = {
  501. .dma_mask = &ac97_dmamask,
  502. .coherent_dma_mask = DMA_BIT_MASK(32),
  503. .platform_data = &ac97_data,
  504. },
  505. .resource = ac97_resources,
  506. .num_resources = ARRAY_SIZE(ac97_resources),
  507. };
  508. void __init at91_add_device_ac97(struct atmel_ac97_data *data)
  509. {
  510. if (!data)
  511. return;
  512. at91_set_A_periph(AT91_PIN_PA6, 0); /* AC97FS */
  513. at91_set_A_periph(AT91_PIN_PA7, 0); /* AC97CK */
  514. at91_set_A_periph(AT91_PIN_PA8, 0); /* AC97TX */
  515. at91_set_A_periph(AT91_PIN_PA9, 0); /* AC97RX */
  516. /* reset */
  517. if (data->reset_pin)
  518. at91_set_gpio_output(data->reset_pin, 0);
  519. ac97_data = *data;
  520. platform_device_register(&at91cap9_ac97_device);
  521. }
  522. #else
  523. void __init at91_add_device_ac97(struct atmel_ac97_data *data) {}
  524. #endif
  525. /* --------------------------------------------------------------------
  526. * LCD Controller
  527. * -------------------------------------------------------------------- */
  528. #if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
  529. static u64 lcdc_dmamask = DMA_BIT_MASK(32);
  530. static struct atmel_lcdfb_info lcdc_data;
  531. static struct resource lcdc_resources[] = {
  532. [0] = {
  533. .start = AT91CAP9_LCDC_BASE,
  534. .end = AT91CAP9_LCDC_BASE + SZ_4K - 1,
  535. .flags = IORESOURCE_MEM,
  536. },
  537. [1] = {
  538. .start = AT91CAP9_ID_LCDC,
  539. .end = AT91CAP9_ID_LCDC,
  540. .flags = IORESOURCE_IRQ,
  541. },
  542. };
  543. static struct platform_device at91_lcdc_device = {
  544. .name = "atmel_lcdfb",
  545. .id = 0,
  546. .dev = {
  547. .dma_mask = &lcdc_dmamask,
  548. .coherent_dma_mask = DMA_BIT_MASK(32),
  549. .platform_data = &lcdc_data,
  550. },
  551. .resource = lcdc_resources,
  552. .num_resources = ARRAY_SIZE(lcdc_resources),
  553. };
  554. void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data)
  555. {
  556. if (!data)
  557. return;
  558. at91_set_A_periph(AT91_PIN_PC1, 0); /* LCDHSYNC */
  559. at91_set_A_periph(AT91_PIN_PC2, 0); /* LCDDOTCK */
  560. at91_set_A_periph(AT91_PIN_PC3, 0); /* LCDDEN */
  561. at91_set_B_periph(AT91_PIN_PB9, 0); /* LCDCC */
  562. at91_set_A_periph(AT91_PIN_PC6, 0); /* LCDD2 */
  563. at91_set_A_periph(AT91_PIN_PC7, 0); /* LCDD3 */
  564. at91_set_A_periph(AT91_PIN_PC8, 0); /* LCDD4 */
  565. at91_set_A_periph(AT91_PIN_PC9, 0); /* LCDD5 */
  566. at91_set_A_periph(AT91_PIN_PC10, 0); /* LCDD6 */
  567. at91_set_A_periph(AT91_PIN_PC11, 0); /* LCDD7 */
  568. at91_set_A_periph(AT91_PIN_PC14, 0); /* LCDD10 */
  569. at91_set_A_periph(AT91_PIN_PC15, 0); /* LCDD11 */
  570. at91_set_A_periph(AT91_PIN_PC16, 0); /* LCDD12 */
  571. at91_set_A_periph(AT91_PIN_PC17, 0); /* LCDD13 */
  572. at91_set_A_periph(AT91_PIN_PC18, 0); /* LCDD14 */
  573. at91_set_A_periph(AT91_PIN_PC19, 0); /* LCDD15 */
  574. at91_set_A_periph(AT91_PIN_PC22, 0); /* LCDD18 */
  575. at91_set_A_periph(AT91_PIN_PC23, 0); /* LCDD19 */
  576. at91_set_A_periph(AT91_PIN_PC24, 0); /* LCDD20 */
  577. at91_set_A_periph(AT91_PIN_PC25, 0); /* LCDD21 */
  578. at91_set_A_periph(AT91_PIN_PC26, 0); /* LCDD22 */
  579. at91_set_A_periph(AT91_PIN_PC27, 0); /* LCDD23 */
  580. lcdc_data = *data;
  581. platform_device_register(&at91_lcdc_device);
  582. }
  583. #else
  584. void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data) {}
  585. #endif
  586. /* --------------------------------------------------------------------
  587. * SSC -- Synchronous Serial Controller
  588. * -------------------------------------------------------------------- */
  589. #if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
  590. static u64 ssc0_dmamask = DMA_BIT_MASK(32);
  591. static struct resource ssc0_resources[] = {
  592. [0] = {
  593. .start = AT91CAP9_BASE_SSC0,
  594. .end = AT91CAP9_BASE_SSC0 + SZ_16K - 1,
  595. .flags = IORESOURCE_MEM,
  596. },
  597. [1] = {
  598. .start = AT91CAP9_ID_SSC0,
  599. .end = AT91CAP9_ID_SSC0,
  600. .flags = IORESOURCE_IRQ,
  601. },
  602. };
  603. static struct platform_device at91cap9_ssc0_device = {
  604. .name = "ssc",
  605. .id = 0,
  606. .dev = {
  607. .dma_mask = &ssc0_dmamask,
  608. .coherent_dma_mask = DMA_BIT_MASK(32),
  609. },
  610. .resource = ssc0_resources,
  611. .num_resources = ARRAY_SIZE(ssc0_resources),
  612. };
  613. static inline void configure_ssc0_pins(unsigned pins)
  614. {
  615. if (pins & ATMEL_SSC_TF)
  616. at91_set_A_periph(AT91_PIN_PB0, 1);
  617. if (pins & ATMEL_SSC_TK)
  618. at91_set_A_periph(AT91_PIN_PB1, 1);
  619. if (pins & ATMEL_SSC_TD)
  620. at91_set_A_periph(AT91_PIN_PB2, 1);
  621. if (pins & ATMEL_SSC_RD)
  622. at91_set_A_periph(AT91_PIN_PB3, 1);
  623. if (pins & ATMEL_SSC_RK)
  624. at91_set_A_periph(AT91_PIN_PB4, 1);
  625. if (pins & ATMEL_SSC_RF)
  626. at91_set_A_periph(AT91_PIN_PB5, 1);
  627. }
  628. static u64 ssc1_dmamask = DMA_BIT_MASK(32);
  629. static struct resource ssc1_resources[] = {
  630. [0] = {
  631. .start = AT91CAP9_BASE_SSC1,
  632. .end = AT91CAP9_BASE_SSC1 + SZ_16K - 1,
  633. .flags = IORESOURCE_MEM,
  634. },
  635. [1] = {
  636. .start = AT91CAP9_ID_SSC1,
  637. .end = AT91CAP9_ID_SSC1,
  638. .flags = IORESOURCE_IRQ,
  639. },
  640. };
  641. static struct platform_device at91cap9_ssc1_device = {
  642. .name = "ssc",
  643. .id = 1,
  644. .dev = {
  645. .dma_mask = &ssc1_dmamask,
  646. .coherent_dma_mask = DMA_BIT_MASK(32),
  647. },
  648. .resource = ssc1_resources,
  649. .num_resources = ARRAY_SIZE(ssc1_resources),
  650. };
  651. static inline void configure_ssc1_pins(unsigned pins)
  652. {
  653. if (pins & ATMEL_SSC_TF)
  654. at91_set_A_periph(AT91_PIN_PB6, 1);
  655. if (pins & ATMEL_SSC_TK)
  656. at91_set_A_periph(AT91_PIN_PB7, 1);
  657. if (pins & ATMEL_SSC_TD)
  658. at91_set_A_periph(AT91_PIN_PB8, 1);
  659. if (pins & ATMEL_SSC_RD)
  660. at91_set_A_periph(AT91_PIN_PB9, 1);
  661. if (pins & ATMEL_SSC_RK)
  662. at91_set_A_periph(AT91_PIN_PB10, 1);
  663. if (pins & ATMEL_SSC_RF)
  664. at91_set_A_periph(AT91_PIN_PB11, 1);
  665. }
  666. /*
  667. * SSC controllers are accessed through library code, instead of any
  668. * kind of all-singing/all-dancing driver. For example one could be
  669. * used by a particular I2S audio codec's driver, while another one
  670. * on the same system might be used by a custom data capture driver.
  671. */
  672. void __init at91_add_device_ssc(unsigned id, unsigned pins)
  673. {
  674. struct platform_device *pdev;
  675. /*
  676. * NOTE: caller is responsible for passing information matching
  677. * "pins" to whatever will be using each particular controller.
  678. */
  679. switch (id) {
  680. case AT91CAP9_ID_SSC0:
  681. pdev = &at91cap9_ssc0_device;
  682. configure_ssc0_pins(pins);
  683. at91_clock_associate("ssc0_clk", &pdev->dev, "ssc");
  684. break;
  685. case AT91CAP9_ID_SSC1:
  686. pdev = &at91cap9_ssc1_device;
  687. configure_ssc1_pins(pins);
  688. at91_clock_associate("ssc1_clk", &pdev->dev, "ssc");
  689. break;
  690. default:
  691. return;
  692. }
  693. platform_device_register(pdev);
  694. }
  695. #else
  696. void __init at91_add_device_ssc(unsigned id, unsigned pins) {}
  697. #endif
  698. /* --------------------------------------------------------------------
  699. * UART
  700. * -------------------------------------------------------------------- */
  701. #if defined(CONFIG_SERIAL_ATMEL)
  702. static struct resource dbgu_resources[] = {
  703. [0] = {
  704. .start = AT91_VA_BASE_SYS + AT91_DBGU,
  705. .end = AT91_VA_BASE_SYS + AT91_DBGU + SZ_512 - 1,
  706. .flags = IORESOURCE_MEM,
  707. },
  708. [1] = {
  709. .start = AT91_ID_SYS,
  710. .end = AT91_ID_SYS,
  711. .flags = IORESOURCE_IRQ,
  712. },
  713. };
  714. static struct atmel_uart_data dbgu_data = {
  715. .use_dma_tx = 0,
  716. .use_dma_rx = 0, /* DBGU not capable of receive DMA */
  717. .regs = (void __iomem *)(AT91_VA_BASE_SYS + AT91_DBGU),
  718. };
  719. static u64 dbgu_dmamask = DMA_BIT_MASK(32);
  720. static struct platform_device at91cap9_dbgu_device = {
  721. .name = "atmel_usart",
  722. .id = 0,
  723. .dev = {
  724. .dma_mask = &dbgu_dmamask,
  725. .coherent_dma_mask = DMA_BIT_MASK(32),
  726. .platform_data = &dbgu_data,
  727. },
  728. .resource = dbgu_resources,
  729. .num_resources = ARRAY_SIZE(dbgu_resources),
  730. };
  731. static inline void configure_dbgu_pins(void)
  732. {
  733. at91_set_A_periph(AT91_PIN_PC30, 0); /* DRXD */
  734. at91_set_A_periph(AT91_PIN_PC31, 1); /* DTXD */
  735. }
  736. static struct resource uart0_resources[] = {
  737. [0] = {
  738. .start = AT91CAP9_BASE_US0,
  739. .end = AT91CAP9_BASE_US0 + SZ_16K - 1,
  740. .flags = IORESOURCE_MEM,
  741. },
  742. [1] = {
  743. .start = AT91CAP9_ID_US0,
  744. .end = AT91CAP9_ID_US0,
  745. .flags = IORESOURCE_IRQ,
  746. },
  747. };
  748. static struct atmel_uart_data uart0_data = {
  749. .use_dma_tx = 1,
  750. .use_dma_rx = 1,
  751. };
  752. static u64 uart0_dmamask = DMA_BIT_MASK(32);
  753. static struct platform_device at91cap9_uart0_device = {
  754. .name = "atmel_usart",
  755. .id = 1,
  756. .dev = {
  757. .dma_mask = &uart0_dmamask,
  758. .coherent_dma_mask = DMA_BIT_MASK(32),
  759. .platform_data = &uart0_data,
  760. },
  761. .resource = uart0_resources,
  762. .num_resources = ARRAY_SIZE(uart0_resources),
  763. };
  764. static inline void configure_usart0_pins(unsigned pins)
  765. {
  766. at91_set_A_periph(AT91_PIN_PA22, 1); /* TXD0 */
  767. at91_set_A_periph(AT91_PIN_PA23, 0); /* RXD0 */
  768. if (pins & ATMEL_UART_RTS)
  769. at91_set_A_periph(AT91_PIN_PA24, 0); /* RTS0 */
  770. if (pins & ATMEL_UART_CTS)
  771. at91_set_A_periph(AT91_PIN_PA25, 0); /* CTS0 */
  772. }
  773. static struct resource uart1_resources[] = {
  774. [0] = {
  775. .start = AT91CAP9_BASE_US1,
  776. .end = AT91CAP9_BASE_US1 + SZ_16K - 1,
  777. .flags = IORESOURCE_MEM,
  778. },
  779. [1] = {
  780. .start = AT91CAP9_ID_US1,
  781. .end = AT91CAP9_ID_US1,
  782. .flags = IORESOURCE_IRQ,
  783. },
  784. };
  785. static struct atmel_uart_data uart1_data = {
  786. .use_dma_tx = 1,
  787. .use_dma_rx = 1,
  788. };
  789. static u64 uart1_dmamask = DMA_BIT_MASK(32);
  790. static struct platform_device at91cap9_uart1_device = {
  791. .name = "atmel_usart",
  792. .id = 2,
  793. .dev = {
  794. .dma_mask = &uart1_dmamask,
  795. .coherent_dma_mask = DMA_BIT_MASK(32),
  796. .platform_data = &uart1_data,
  797. },
  798. .resource = uart1_resources,
  799. .num_resources = ARRAY_SIZE(uart1_resources),
  800. };
  801. static inline void configure_usart1_pins(unsigned pins)
  802. {
  803. at91_set_A_periph(AT91_PIN_PD0, 1); /* TXD1 */
  804. at91_set_A_periph(AT91_PIN_PD1, 0); /* RXD1 */
  805. if (pins & ATMEL_UART_RTS)
  806. at91_set_B_periph(AT91_PIN_PD7, 0); /* RTS1 */
  807. if (pins & ATMEL_UART_CTS)
  808. at91_set_B_periph(AT91_PIN_PD8, 0); /* CTS1 */
  809. }
  810. static struct resource uart2_resources[] = {
  811. [0] = {
  812. .start = AT91CAP9_BASE_US2,
  813. .end = AT91CAP9_BASE_US2 + SZ_16K - 1,
  814. .flags = IORESOURCE_MEM,
  815. },
  816. [1] = {
  817. .start = AT91CAP9_ID_US2,
  818. .end = AT91CAP9_ID_US2,
  819. .flags = IORESOURCE_IRQ,
  820. },
  821. };
  822. static struct atmel_uart_data uart2_data = {
  823. .use_dma_tx = 1,
  824. .use_dma_rx = 1,
  825. };
  826. static u64 uart2_dmamask = DMA_BIT_MASK(32);
  827. static struct platform_device at91cap9_uart2_device = {
  828. .name = "atmel_usart",
  829. .id = 3,
  830. .dev = {
  831. .dma_mask = &uart2_dmamask,
  832. .coherent_dma_mask = DMA_BIT_MASK(32),
  833. .platform_data = &uart2_data,
  834. },
  835. .resource = uart2_resources,
  836. .num_resources = ARRAY_SIZE(uart2_resources),
  837. };
  838. static inline void configure_usart2_pins(unsigned pins)
  839. {
  840. at91_set_A_periph(AT91_PIN_PD2, 1); /* TXD2 */
  841. at91_set_A_periph(AT91_PIN_PD3, 0); /* RXD2 */
  842. if (pins & ATMEL_UART_RTS)
  843. at91_set_B_periph(AT91_PIN_PD5, 0); /* RTS2 */
  844. if (pins & ATMEL_UART_CTS)
  845. at91_set_B_periph(AT91_PIN_PD6, 0); /* CTS2 */
  846. }
  847. static struct platform_device *at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
  848. struct platform_device *atmel_default_console_device; /* the serial console device */
  849. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
  850. {
  851. struct platform_device *pdev;
  852. switch (id) {
  853. case 0: /* DBGU */
  854. pdev = &at91cap9_dbgu_device;
  855. configure_dbgu_pins();
  856. at91_clock_associate("mck", &pdev->dev, "usart");
  857. break;
  858. case AT91CAP9_ID_US0:
  859. pdev = &at91cap9_uart0_device;
  860. configure_usart0_pins(pins);
  861. at91_clock_associate("usart0_clk", &pdev->dev, "usart");
  862. break;
  863. case AT91CAP9_ID_US1:
  864. pdev = &at91cap9_uart1_device;
  865. configure_usart1_pins(pins);
  866. at91_clock_associate("usart1_clk", &pdev->dev, "usart");
  867. break;
  868. case AT91CAP9_ID_US2:
  869. pdev = &at91cap9_uart2_device;
  870. configure_usart2_pins(pins);
  871. at91_clock_associate("usart2_clk", &pdev->dev, "usart");
  872. break;
  873. default:
  874. return;
  875. }
  876. pdev->id = portnr; /* update to mapped ID */
  877. if (portnr < ATMEL_MAX_UART)
  878. at91_uarts[portnr] = pdev;
  879. }
  880. void __init at91_set_serial_console(unsigned portnr)
  881. {
  882. if (portnr < ATMEL_MAX_UART)
  883. atmel_default_console_device = at91_uarts[portnr];
  884. if (!atmel_default_console_device)
  885. printk(KERN_INFO "AT91: No default serial console defined.\n");
  886. }
  887. void __init at91_add_device_serial(void)
  888. {
  889. int i;
  890. for (i = 0; i < ATMEL_MAX_UART; i++) {
  891. if (at91_uarts[i])
  892. platform_device_register(at91_uarts[i]);
  893. }
  894. }
  895. #else
  896. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
  897. void __init at91_set_serial_console(unsigned portnr) {}
  898. void __init at91_add_device_serial(void) {}
  899. #endif
  900. /* -------------------------------------------------------------------- */
  901. /*
  902. * These devices are always present and don't need any board-specific
  903. * setup.
  904. */
  905. static int __init at91_add_standard_devices(void)
  906. {
  907. at91_add_device_rtt();
  908. at91_add_device_watchdog();
  909. return 0;
  910. }
  911. arch_initcall(at91_add_standard_devices);