at91sam9263_devices.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977
  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 <linux/i2c-gpio.h>
  16. #include <linux/fb.h>
  17. #include <video/atmel_lcdc.h>
  18. #include <asm/arch/board.h>
  19. #include <asm/arch/gpio.h>
  20. #include <asm/arch/at91sam9263.h>
  21. #include <asm/arch/at91sam926x_mc.h>
  22. #include <asm/arch/at91sam9263_matrix.h>
  23. #include "generic.h"
  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. /*
  357. * Prefer the GPIO code since the TWI controller isn't robust
  358. * (gets overruns and underruns under load) and can only issue
  359. * repeated STARTs in one scenario (the driver doesn't yet handle them).
  360. */
  361. #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
  362. static struct i2c_gpio_platform_data pdata = {
  363. .sda_pin = AT91_PIN_PB4,
  364. .sda_is_open_drain = 1,
  365. .scl_pin = AT91_PIN_PB5,
  366. .scl_is_open_drain = 1,
  367. .udelay = 2, /* ~100 kHz */
  368. };
  369. static struct platform_device at91sam9263_twi_device = {
  370. .name = "i2c-gpio",
  371. .id = -1,
  372. .dev.platform_data = &pdata,
  373. };
  374. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  375. {
  376. at91_set_GPIO_periph(AT91_PIN_PB4, 1); /* TWD (SDA) */
  377. at91_set_multi_drive(AT91_PIN_PB4, 1);
  378. at91_set_GPIO_periph(AT91_PIN_PB5, 1); /* TWCK (SCL) */
  379. at91_set_multi_drive(AT91_PIN_PB5, 1);
  380. i2c_register_board_info(0, devices, nr_devices);
  381. platform_device_register(&at91sam9263_twi_device);
  382. }
  383. #elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
  384. static struct resource twi_resources[] = {
  385. [0] = {
  386. .start = AT91SAM9263_BASE_TWI,
  387. .end = AT91SAM9263_BASE_TWI + SZ_16K - 1,
  388. .flags = IORESOURCE_MEM,
  389. },
  390. [1] = {
  391. .start = AT91SAM9263_ID_TWI,
  392. .end = AT91SAM9263_ID_TWI,
  393. .flags = IORESOURCE_IRQ,
  394. },
  395. };
  396. static struct platform_device at91sam9263_twi_device = {
  397. .name = "at91_i2c",
  398. .id = -1,
  399. .resource = twi_resources,
  400. .num_resources = ARRAY_SIZE(twi_resources),
  401. };
  402. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  403. {
  404. /* pins used for TWI interface */
  405. at91_set_A_periph(AT91_PIN_PB4, 0); /* TWD */
  406. at91_set_multi_drive(AT91_PIN_PB4, 1);
  407. at91_set_A_periph(AT91_PIN_PB5, 0); /* TWCK */
  408. at91_set_multi_drive(AT91_PIN_PB5, 1);
  409. i2c_register_board_info(0, devices, nr_devices);
  410. platform_device_register(&at91sam9263_twi_device);
  411. }
  412. #else
  413. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {}
  414. #endif
  415. /* --------------------------------------------------------------------
  416. * SPI
  417. * -------------------------------------------------------------------- */
  418. #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
  419. static u64 spi_dmamask = 0xffffffffUL;
  420. static struct resource spi0_resources[] = {
  421. [0] = {
  422. .start = AT91SAM9263_BASE_SPI0,
  423. .end = AT91SAM9263_BASE_SPI0 + SZ_16K - 1,
  424. .flags = IORESOURCE_MEM,
  425. },
  426. [1] = {
  427. .start = AT91SAM9263_ID_SPI0,
  428. .end = AT91SAM9263_ID_SPI0,
  429. .flags = IORESOURCE_IRQ,
  430. },
  431. };
  432. static struct platform_device at91sam9263_spi0_device = {
  433. .name = "atmel_spi",
  434. .id = 0,
  435. .dev = {
  436. .dma_mask = &spi_dmamask,
  437. .coherent_dma_mask = 0xffffffff,
  438. },
  439. .resource = spi0_resources,
  440. .num_resources = ARRAY_SIZE(spi0_resources),
  441. };
  442. static const unsigned spi0_standard_cs[4] = { AT91_PIN_PA5, AT91_PIN_PA3, AT91_PIN_PA4, AT91_PIN_PB11 };
  443. static struct resource spi1_resources[] = {
  444. [0] = {
  445. .start = AT91SAM9263_BASE_SPI1,
  446. .end = AT91SAM9263_BASE_SPI1 + SZ_16K - 1,
  447. .flags = IORESOURCE_MEM,
  448. },
  449. [1] = {
  450. .start = AT91SAM9263_ID_SPI1,
  451. .end = AT91SAM9263_ID_SPI1,
  452. .flags = IORESOURCE_IRQ,
  453. },
  454. };
  455. static struct platform_device at91sam9263_spi1_device = {
  456. .name = "atmel_spi",
  457. .id = 1,
  458. .dev = {
  459. .dma_mask = &spi_dmamask,
  460. .coherent_dma_mask = 0xffffffff,
  461. },
  462. .resource = spi1_resources,
  463. .num_resources = ARRAY_SIZE(spi1_resources),
  464. };
  465. static const unsigned spi1_standard_cs[4] = { AT91_PIN_PB15, AT91_PIN_PB16, AT91_PIN_PB17, AT91_PIN_PB18 };
  466. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
  467. {
  468. int i;
  469. unsigned long cs_pin;
  470. short enable_spi0 = 0;
  471. short enable_spi1 = 0;
  472. /* Choose SPI chip-selects */
  473. for (i = 0; i < nr_devices; i++) {
  474. if (devices[i].controller_data)
  475. cs_pin = (unsigned long) devices[i].controller_data;
  476. else if (devices[i].bus_num == 0)
  477. cs_pin = spi0_standard_cs[devices[i].chip_select];
  478. else
  479. cs_pin = spi1_standard_cs[devices[i].chip_select];
  480. if (devices[i].bus_num == 0)
  481. enable_spi0 = 1;
  482. else
  483. enable_spi1 = 1;
  484. /* enable chip-select pin */
  485. at91_set_gpio_output(cs_pin, 1);
  486. /* pass chip-select pin to driver */
  487. devices[i].controller_data = (void *) cs_pin;
  488. }
  489. spi_register_board_info(devices, nr_devices);
  490. /* Configure SPI bus(es) */
  491. if (enable_spi0) {
  492. at91_set_B_periph(AT91_PIN_PA0, 0); /* SPI0_MISO */
  493. at91_set_B_periph(AT91_PIN_PA1, 0); /* SPI0_MOSI */
  494. at91_set_B_periph(AT91_PIN_PA2, 0); /* SPI0_SPCK */
  495. at91_clock_associate("spi0_clk", &at91sam9263_spi0_device.dev, "spi_clk");
  496. platform_device_register(&at91sam9263_spi0_device);
  497. }
  498. if (enable_spi1) {
  499. at91_set_A_periph(AT91_PIN_PB12, 0); /* SPI1_MISO */
  500. at91_set_A_periph(AT91_PIN_PB13, 0); /* SPI1_MOSI */
  501. at91_set_A_periph(AT91_PIN_PB14, 0); /* SPI1_SPCK */
  502. at91_clock_associate("spi1_clk", &at91sam9263_spi1_device.dev, "spi_clk");
  503. platform_device_register(&at91sam9263_spi1_device);
  504. }
  505. }
  506. #else
  507. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
  508. #endif
  509. /* --------------------------------------------------------------------
  510. * AC97
  511. * -------------------------------------------------------------------- */
  512. #if defined(CONFIG_SND_AT91_AC97) || defined(CONFIG_SND_AT91_AC97_MODULE)
  513. static u64 ac97_dmamask = 0xffffffffUL;
  514. static struct atmel_ac97_data ac97_data;
  515. static struct resource ac97_resources[] = {
  516. [0] = {
  517. .start = AT91SAM9263_BASE_AC97C,
  518. .end = AT91SAM9263_BASE_AC97C + SZ_16K - 1,
  519. .flags = IORESOURCE_MEM,
  520. },
  521. [1] = {
  522. .start = AT91SAM9263_ID_AC97C,
  523. .end = AT91SAM9263_ID_AC97C,
  524. .flags = IORESOURCE_IRQ,
  525. },
  526. };
  527. static struct platform_device at91sam9263_ac97_device = {
  528. .name = "ac97c",
  529. .id = 1,
  530. .dev = {
  531. .dma_mask = &ac97_dmamask,
  532. .coherent_dma_mask = 0xffffffff,
  533. .platform_data = &ac97_data,
  534. },
  535. .resource = ac97_resources,
  536. .num_resources = ARRAY_SIZE(ac97_resources),
  537. };
  538. void __init at91_add_device_ac97(struct atmel_ac97_data *data)
  539. {
  540. if (!data)
  541. return;
  542. at91_set_A_periph(AT91_PIN_PB0, 0); /* AC97FS */
  543. at91_set_A_periph(AT91_PIN_PB1, 0); /* AC97CK */
  544. at91_set_A_periph(AT91_PIN_PB2, 0); /* AC97TX */
  545. at91_set_A_periph(AT91_PIN_PB3, 0); /* AC97RX */
  546. /* reset */
  547. if (data->reset_pin)
  548. at91_set_gpio_output(data->reset_pin, 0);
  549. ac97_data = *ek_data;
  550. platform_device_register(&at91sam9263_ac97_device);
  551. }
  552. #else
  553. void __init at91_add_device_ac97(struct atmel_ac97_data *data) {}
  554. #endif
  555. /* --------------------------------------------------------------------
  556. * LCD Controller
  557. * -------------------------------------------------------------------- */
  558. #if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
  559. static u64 lcdc_dmamask = 0xffffffffUL;
  560. static struct atmel_lcdfb_info lcdc_data;
  561. static struct resource lcdc_resources[] = {
  562. [0] = {
  563. .start = AT91SAM9263_LCDC_BASE,
  564. .end = AT91SAM9263_LCDC_BASE + SZ_4K - 1,
  565. .flags = IORESOURCE_MEM,
  566. },
  567. [1] = {
  568. .start = AT91SAM9263_ID_LCDC,
  569. .end = AT91SAM9263_ID_LCDC,
  570. .flags = IORESOURCE_IRQ,
  571. },
  572. };
  573. static struct platform_device at91_lcdc_device = {
  574. .name = "atmel_lcdfb",
  575. .id = 0,
  576. .dev = {
  577. .dma_mask = &lcdc_dmamask,
  578. .coherent_dma_mask = 0xffffffff,
  579. .platform_data = &lcdc_data,
  580. },
  581. .resource = lcdc_resources,
  582. .num_resources = ARRAY_SIZE(lcdc_resources),
  583. };
  584. void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data)
  585. {
  586. if (!data)
  587. return;
  588. at91_set_A_periph(AT91_PIN_PC1, 0); /* LCDHSYNC */
  589. at91_set_A_periph(AT91_PIN_PC2, 0); /* LCDDOTCK */
  590. at91_set_A_periph(AT91_PIN_PC3, 0); /* LCDDEN */
  591. at91_set_B_periph(AT91_PIN_PB9, 0); /* LCDCC */
  592. at91_set_A_periph(AT91_PIN_PC6, 0); /* LCDD2 */
  593. at91_set_A_periph(AT91_PIN_PC7, 0); /* LCDD3 */
  594. at91_set_A_periph(AT91_PIN_PC8, 0); /* LCDD4 */
  595. at91_set_A_periph(AT91_PIN_PC9, 0); /* LCDD5 */
  596. at91_set_A_periph(AT91_PIN_PC10, 0); /* LCDD6 */
  597. at91_set_A_periph(AT91_PIN_PC11, 0); /* LCDD7 */
  598. at91_set_A_periph(AT91_PIN_PC14, 0); /* LCDD10 */
  599. at91_set_A_periph(AT91_PIN_PC15, 0); /* LCDD11 */
  600. at91_set_A_periph(AT91_PIN_PC16, 0); /* LCDD12 */
  601. at91_set_B_periph(AT91_PIN_PC12, 0); /* LCDD13 */
  602. at91_set_A_periph(AT91_PIN_PC18, 0); /* LCDD14 */
  603. at91_set_A_periph(AT91_PIN_PC19, 0); /* LCDD15 */
  604. at91_set_A_periph(AT91_PIN_PC22, 0); /* LCDD18 */
  605. at91_set_A_periph(AT91_PIN_PC23, 0); /* LCDD19 */
  606. at91_set_A_periph(AT91_PIN_PC24, 0); /* LCDD20 */
  607. at91_set_B_periph(AT91_PIN_PC17, 0); /* LCDD21 */
  608. at91_set_A_periph(AT91_PIN_PC26, 0); /* LCDD22 */
  609. at91_set_A_periph(AT91_PIN_PC27, 0); /* LCDD23 */
  610. lcdc_data = *data;
  611. platform_device_register(&at91_lcdc_device);
  612. }
  613. #else
  614. void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data) {}
  615. #endif
  616. /* --------------------------------------------------------------------
  617. * LEDs
  618. * -------------------------------------------------------------------- */
  619. #if defined(CONFIG_LEDS)
  620. u8 at91_leds_cpu;
  621. u8 at91_leds_timer;
  622. void __init at91_init_leds(u8 cpu_led, u8 timer_led)
  623. {
  624. /* Enable GPIO to access the LEDs */
  625. at91_set_gpio_output(cpu_led, 1);
  626. at91_set_gpio_output(timer_led, 1);
  627. at91_leds_cpu = cpu_led;
  628. at91_leds_timer = timer_led;
  629. }
  630. #else
  631. void __init at91_init_leds(u8 cpu_led, u8 timer_led) {}
  632. #endif
  633. /* --------------------------------------------------------------------
  634. * UART
  635. * -------------------------------------------------------------------- */
  636. #if defined(CONFIG_SERIAL_ATMEL)
  637. static struct resource dbgu_resources[] = {
  638. [0] = {
  639. .start = AT91_VA_BASE_SYS + AT91_DBGU,
  640. .end = AT91_VA_BASE_SYS + AT91_DBGU + SZ_512 - 1,
  641. .flags = IORESOURCE_MEM,
  642. },
  643. [1] = {
  644. .start = AT91_ID_SYS,
  645. .end = AT91_ID_SYS,
  646. .flags = IORESOURCE_IRQ,
  647. },
  648. };
  649. static struct atmel_uart_data dbgu_data = {
  650. .use_dma_tx = 0,
  651. .use_dma_rx = 0, /* DBGU not capable of receive DMA */
  652. .regs = (void __iomem *)(AT91_VA_BASE_SYS + AT91_DBGU),
  653. };
  654. static struct platform_device at91sam9263_dbgu_device = {
  655. .name = "atmel_usart",
  656. .id = 0,
  657. .dev = {
  658. .platform_data = &dbgu_data,
  659. .coherent_dma_mask = 0xffffffff,
  660. },
  661. .resource = dbgu_resources,
  662. .num_resources = ARRAY_SIZE(dbgu_resources),
  663. };
  664. static inline void configure_dbgu_pins(void)
  665. {
  666. at91_set_A_periph(AT91_PIN_PC30, 0); /* DRXD */
  667. at91_set_A_periph(AT91_PIN_PC31, 1); /* DTXD */
  668. }
  669. static struct resource uart0_resources[] = {
  670. [0] = {
  671. .start = AT91SAM9263_BASE_US0,
  672. .end = AT91SAM9263_BASE_US0 + SZ_16K - 1,
  673. .flags = IORESOURCE_MEM,
  674. },
  675. [1] = {
  676. .start = AT91SAM9263_ID_US0,
  677. .end = AT91SAM9263_ID_US0,
  678. .flags = IORESOURCE_IRQ,
  679. },
  680. };
  681. static struct atmel_uart_data uart0_data = {
  682. .use_dma_tx = 1,
  683. .use_dma_rx = 1,
  684. };
  685. static struct platform_device at91sam9263_uart0_device = {
  686. .name = "atmel_usart",
  687. .id = 1,
  688. .dev = {
  689. .platform_data = &uart0_data,
  690. .coherent_dma_mask = 0xffffffff,
  691. },
  692. .resource = uart0_resources,
  693. .num_resources = ARRAY_SIZE(uart0_resources),
  694. };
  695. static inline void configure_usart0_pins(void)
  696. {
  697. at91_set_A_periph(AT91_PIN_PA26, 1); /* TXD0 */
  698. at91_set_A_periph(AT91_PIN_PA27, 0); /* RXD0 */
  699. at91_set_A_periph(AT91_PIN_PA28, 0); /* RTS0 */
  700. at91_set_A_periph(AT91_PIN_PA29, 0); /* CTS0 */
  701. }
  702. static struct resource uart1_resources[] = {
  703. [0] = {
  704. .start = AT91SAM9263_BASE_US1,
  705. .end = AT91SAM9263_BASE_US1 + SZ_16K - 1,
  706. .flags = IORESOURCE_MEM,
  707. },
  708. [1] = {
  709. .start = AT91SAM9263_ID_US1,
  710. .end = AT91SAM9263_ID_US1,
  711. .flags = IORESOURCE_IRQ,
  712. },
  713. };
  714. static struct atmel_uart_data uart1_data = {
  715. .use_dma_tx = 1,
  716. .use_dma_rx = 1,
  717. };
  718. static struct platform_device at91sam9263_uart1_device = {
  719. .name = "atmel_usart",
  720. .id = 2,
  721. .dev = {
  722. .platform_data = &uart1_data,
  723. .coherent_dma_mask = 0xffffffff,
  724. },
  725. .resource = uart1_resources,
  726. .num_resources = ARRAY_SIZE(uart1_resources),
  727. };
  728. static inline void configure_usart1_pins(void)
  729. {
  730. at91_set_A_periph(AT91_PIN_PD0, 1); /* TXD1 */
  731. at91_set_A_periph(AT91_PIN_PD1, 0); /* RXD1 */
  732. at91_set_B_periph(AT91_PIN_PD7, 0); /* RTS1 */
  733. at91_set_B_periph(AT91_PIN_PD8, 0); /* CTS1 */
  734. }
  735. static struct resource uart2_resources[] = {
  736. [0] = {
  737. .start = AT91SAM9263_BASE_US2,
  738. .end = AT91SAM9263_BASE_US2 + SZ_16K - 1,
  739. .flags = IORESOURCE_MEM,
  740. },
  741. [1] = {
  742. .start = AT91SAM9263_ID_US2,
  743. .end = AT91SAM9263_ID_US2,
  744. .flags = IORESOURCE_IRQ,
  745. },
  746. };
  747. static struct atmel_uart_data uart2_data = {
  748. .use_dma_tx = 1,
  749. .use_dma_rx = 1,
  750. };
  751. static struct platform_device at91sam9263_uart2_device = {
  752. .name = "atmel_usart",
  753. .id = 3,
  754. .dev = {
  755. .platform_data = &uart2_data,
  756. .coherent_dma_mask = 0xffffffff,
  757. },
  758. .resource = uart2_resources,
  759. .num_resources = ARRAY_SIZE(uart2_resources),
  760. };
  761. static inline void configure_usart2_pins(void)
  762. {
  763. at91_set_A_periph(AT91_PIN_PD2, 1); /* TXD2 */
  764. at91_set_A_periph(AT91_PIN_PD3, 0); /* RXD2 */
  765. at91_set_B_periph(AT91_PIN_PD5, 0); /* RTS2 */
  766. at91_set_B_periph(AT91_PIN_PD6, 0); /* CTS2 */
  767. }
  768. struct platform_device *at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
  769. struct platform_device *atmel_default_console_device; /* the serial console device */
  770. void __init at91_init_serial(struct at91_uart_config *config)
  771. {
  772. int i;
  773. /* Fill in list of supported UARTs */
  774. for (i = 0; i < config->nr_tty; i++) {
  775. switch (config->tty_map[i]) {
  776. case 0:
  777. configure_usart0_pins();
  778. at91_uarts[i] = &at91sam9263_uart0_device;
  779. at91_clock_associate("usart0_clk", &at91sam9263_uart0_device.dev, "usart");
  780. break;
  781. case 1:
  782. configure_usart1_pins();
  783. at91_uarts[i] = &at91sam9263_uart1_device;
  784. at91_clock_associate("usart1_clk", &at91sam9263_uart1_device.dev, "usart");
  785. break;
  786. case 2:
  787. configure_usart2_pins();
  788. at91_uarts[i] = &at91sam9263_uart2_device;
  789. at91_clock_associate("usart2_clk", &at91sam9263_uart2_device.dev, "usart");
  790. break;
  791. case 3:
  792. configure_dbgu_pins();
  793. at91_uarts[i] = &at91sam9263_dbgu_device;
  794. at91_clock_associate("mck", &at91sam9263_dbgu_device.dev, "usart");
  795. break;
  796. default:
  797. continue;
  798. }
  799. at91_uarts[i]->id = i; /* update ID number to mapped ID */
  800. }
  801. /* Set serial console device */
  802. if (config->console_tty < ATMEL_MAX_UART)
  803. atmel_default_console_device = at91_uarts[config->console_tty];
  804. if (!atmel_default_console_device)
  805. printk(KERN_INFO "AT91: No default serial console defined.\n");
  806. }
  807. void __init at91_add_device_serial(void)
  808. {
  809. int i;
  810. for (i = 0; i < ATMEL_MAX_UART; i++) {
  811. if (at91_uarts[i])
  812. platform_device_register(at91_uarts[i]);
  813. }
  814. }
  815. #else
  816. void __init at91_init_serial(struct at91_uart_config *config) {}
  817. void __init at91_add_device_serial(void) {}
  818. #endif
  819. /* -------------------------------------------------------------------- */
  820. /*
  821. * These devices are always present and don't need any board-specific
  822. * setup.
  823. */
  824. static int __init at91_add_standard_devices(void)
  825. {
  826. return 0;
  827. }
  828. arch_initcall(at91_add_standard_devices);