at91sam9263_devices.c 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027
  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. * Image Sensor Interface
  618. * -------------------------------------------------------------------- */
  619. #if defined(CONFIG_VIDEO_AT91_ISI) || defined(CONFIG_VIDEO_AT91_ISI_MODULE)
  620. struct resource isi_resources[] = {
  621. [0] = {
  622. .start = AT91SAM9263_BASE_ISI,
  623. .end = AT91SAM9263_BASE_ISI + SZ_16K - 1,
  624. .flags = IORESOURCE_MEM,
  625. },
  626. [1] = {
  627. .start = AT91SAM9263_ID_ISI,
  628. .end = AT91SAM9263_ID_ISI,
  629. .flags = IORESOURCE_IRQ,
  630. },
  631. };
  632. static struct platform_device at91sam9263_isi_device = {
  633. .name = "at91_isi",
  634. .id = -1,
  635. .resource = isi_resources,
  636. .num_resources = ARRAY_SIZE(isi_resources),
  637. };
  638. void __init at91_add_device_isi(void)
  639. {
  640. at91_set_A_periph(AT91_PIN_PE0, 0); /* ISI_D0 */
  641. at91_set_A_periph(AT91_PIN_PE1, 0); /* ISI_D1 */
  642. at91_set_A_periph(AT91_PIN_PE2, 0); /* ISI_D2 */
  643. at91_set_A_periph(AT91_PIN_PE3, 0); /* ISI_D3 */
  644. at91_set_A_periph(AT91_PIN_PE4, 0); /* ISI_D4 */
  645. at91_set_A_periph(AT91_PIN_PE5, 0); /* ISI_D5 */
  646. at91_set_A_periph(AT91_PIN_PE6, 0); /* ISI_D6 */
  647. at91_set_A_periph(AT91_PIN_PE7, 0); /* ISI_D7 */
  648. at91_set_A_periph(AT91_PIN_PE8, 0); /* ISI_PCK */
  649. at91_set_A_periph(AT91_PIN_PE9, 0); /* ISI_HSYNC */
  650. at91_set_A_periph(AT91_PIN_PE10, 0); /* ISI_VSYNC */
  651. at91_set_B_periph(AT91_PIN_PE11, 0); /* ISI_MCK (PCK3) */
  652. at91_set_B_periph(AT91_PIN_PE12, 0); /* ISI_PD8 */
  653. at91_set_B_periph(AT91_PIN_PE13, 0); /* ISI_PD9 */
  654. at91_set_B_periph(AT91_PIN_PE14, 0); /* ISI_PD10 */
  655. at91_set_B_periph(AT91_PIN_PE15, 0); /* ISI_PD11 */
  656. }
  657. #else
  658. void __init at91_add_device_isi(void) {}
  659. #endif
  660. /* --------------------------------------------------------------------
  661. * LEDs
  662. * -------------------------------------------------------------------- */
  663. #if defined(CONFIG_LEDS)
  664. u8 at91_leds_cpu;
  665. u8 at91_leds_timer;
  666. void __init at91_init_leds(u8 cpu_led, u8 timer_led)
  667. {
  668. /* Enable GPIO to access the LEDs */
  669. at91_set_gpio_output(cpu_led, 1);
  670. at91_set_gpio_output(timer_led, 1);
  671. at91_leds_cpu = cpu_led;
  672. at91_leds_timer = timer_led;
  673. }
  674. #else
  675. void __init at91_init_leds(u8 cpu_led, u8 timer_led) {}
  676. #endif
  677. /* --------------------------------------------------------------------
  678. * UART
  679. * -------------------------------------------------------------------- */
  680. #if defined(CONFIG_SERIAL_ATMEL)
  681. static struct resource dbgu_resources[] = {
  682. [0] = {
  683. .start = AT91_VA_BASE_SYS + AT91_DBGU,
  684. .end = AT91_VA_BASE_SYS + AT91_DBGU + SZ_512 - 1,
  685. .flags = IORESOURCE_MEM,
  686. },
  687. [1] = {
  688. .start = AT91_ID_SYS,
  689. .end = AT91_ID_SYS,
  690. .flags = IORESOURCE_IRQ,
  691. },
  692. };
  693. static struct atmel_uart_data dbgu_data = {
  694. .use_dma_tx = 0,
  695. .use_dma_rx = 0, /* DBGU not capable of receive DMA */
  696. .regs = (void __iomem *)(AT91_VA_BASE_SYS + AT91_DBGU),
  697. };
  698. static struct platform_device at91sam9263_dbgu_device = {
  699. .name = "atmel_usart",
  700. .id = 0,
  701. .dev = {
  702. .platform_data = &dbgu_data,
  703. .coherent_dma_mask = 0xffffffff,
  704. },
  705. .resource = dbgu_resources,
  706. .num_resources = ARRAY_SIZE(dbgu_resources),
  707. };
  708. static inline void configure_dbgu_pins(void)
  709. {
  710. at91_set_A_periph(AT91_PIN_PC30, 0); /* DRXD */
  711. at91_set_A_periph(AT91_PIN_PC31, 1); /* DTXD */
  712. }
  713. static struct resource uart0_resources[] = {
  714. [0] = {
  715. .start = AT91SAM9263_BASE_US0,
  716. .end = AT91SAM9263_BASE_US0 + SZ_16K - 1,
  717. .flags = IORESOURCE_MEM,
  718. },
  719. [1] = {
  720. .start = AT91SAM9263_ID_US0,
  721. .end = AT91SAM9263_ID_US0,
  722. .flags = IORESOURCE_IRQ,
  723. },
  724. };
  725. static struct atmel_uart_data uart0_data = {
  726. .use_dma_tx = 1,
  727. .use_dma_rx = 1,
  728. };
  729. static struct platform_device at91sam9263_uart0_device = {
  730. .name = "atmel_usart",
  731. .id = 1,
  732. .dev = {
  733. .platform_data = &uart0_data,
  734. .coherent_dma_mask = 0xffffffff,
  735. },
  736. .resource = uart0_resources,
  737. .num_resources = ARRAY_SIZE(uart0_resources),
  738. };
  739. static inline void configure_usart0_pins(void)
  740. {
  741. at91_set_A_periph(AT91_PIN_PA26, 1); /* TXD0 */
  742. at91_set_A_periph(AT91_PIN_PA27, 0); /* RXD0 */
  743. at91_set_A_periph(AT91_PIN_PA28, 0); /* RTS0 */
  744. at91_set_A_periph(AT91_PIN_PA29, 0); /* CTS0 */
  745. }
  746. static struct resource uart1_resources[] = {
  747. [0] = {
  748. .start = AT91SAM9263_BASE_US1,
  749. .end = AT91SAM9263_BASE_US1 + SZ_16K - 1,
  750. .flags = IORESOURCE_MEM,
  751. },
  752. [1] = {
  753. .start = AT91SAM9263_ID_US1,
  754. .end = AT91SAM9263_ID_US1,
  755. .flags = IORESOURCE_IRQ,
  756. },
  757. };
  758. static struct atmel_uart_data uart1_data = {
  759. .use_dma_tx = 1,
  760. .use_dma_rx = 1,
  761. };
  762. static struct platform_device at91sam9263_uart1_device = {
  763. .name = "atmel_usart",
  764. .id = 2,
  765. .dev = {
  766. .platform_data = &uart1_data,
  767. .coherent_dma_mask = 0xffffffff,
  768. },
  769. .resource = uart1_resources,
  770. .num_resources = ARRAY_SIZE(uart1_resources),
  771. };
  772. static inline void configure_usart1_pins(void)
  773. {
  774. at91_set_A_periph(AT91_PIN_PD0, 1); /* TXD1 */
  775. at91_set_A_periph(AT91_PIN_PD1, 0); /* RXD1 */
  776. at91_set_B_periph(AT91_PIN_PD7, 0); /* RTS1 */
  777. at91_set_B_periph(AT91_PIN_PD8, 0); /* CTS1 */
  778. }
  779. static struct resource uart2_resources[] = {
  780. [0] = {
  781. .start = AT91SAM9263_BASE_US2,
  782. .end = AT91SAM9263_BASE_US2 + SZ_16K - 1,
  783. .flags = IORESOURCE_MEM,
  784. },
  785. [1] = {
  786. .start = AT91SAM9263_ID_US2,
  787. .end = AT91SAM9263_ID_US2,
  788. .flags = IORESOURCE_IRQ,
  789. },
  790. };
  791. static struct atmel_uart_data uart2_data = {
  792. .use_dma_tx = 1,
  793. .use_dma_rx = 1,
  794. };
  795. static struct platform_device at91sam9263_uart2_device = {
  796. .name = "atmel_usart",
  797. .id = 3,
  798. .dev = {
  799. .platform_data = &uart2_data,
  800. .coherent_dma_mask = 0xffffffff,
  801. },
  802. .resource = uart2_resources,
  803. .num_resources = ARRAY_SIZE(uart2_resources),
  804. };
  805. static inline void configure_usart2_pins(void)
  806. {
  807. at91_set_A_periph(AT91_PIN_PD2, 1); /* TXD2 */
  808. at91_set_A_periph(AT91_PIN_PD3, 0); /* RXD2 */
  809. at91_set_B_periph(AT91_PIN_PD5, 0); /* RTS2 */
  810. at91_set_B_periph(AT91_PIN_PD6, 0); /* CTS2 */
  811. }
  812. struct platform_device *at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
  813. struct platform_device *atmel_default_console_device; /* the serial console device */
  814. void __init at91_init_serial(struct at91_uart_config *config)
  815. {
  816. int i;
  817. /* Fill in list of supported UARTs */
  818. for (i = 0; i < config->nr_tty; i++) {
  819. switch (config->tty_map[i]) {
  820. case 0:
  821. configure_usart0_pins();
  822. at91_uarts[i] = &at91sam9263_uart0_device;
  823. at91_clock_associate("usart0_clk", &at91sam9263_uart0_device.dev, "usart");
  824. break;
  825. case 1:
  826. configure_usart1_pins();
  827. at91_uarts[i] = &at91sam9263_uart1_device;
  828. at91_clock_associate("usart1_clk", &at91sam9263_uart1_device.dev, "usart");
  829. break;
  830. case 2:
  831. configure_usart2_pins();
  832. at91_uarts[i] = &at91sam9263_uart2_device;
  833. at91_clock_associate("usart2_clk", &at91sam9263_uart2_device.dev, "usart");
  834. break;
  835. case 3:
  836. configure_dbgu_pins();
  837. at91_uarts[i] = &at91sam9263_dbgu_device;
  838. at91_clock_associate("mck", &at91sam9263_dbgu_device.dev, "usart");
  839. break;
  840. default:
  841. continue;
  842. }
  843. at91_uarts[i]->id = i; /* update ID number to mapped ID */
  844. }
  845. /* Set serial console device */
  846. if (config->console_tty < ATMEL_MAX_UART)
  847. atmel_default_console_device = at91_uarts[config->console_tty];
  848. if (!atmel_default_console_device)
  849. printk(KERN_INFO "AT91: No default serial console defined.\n");
  850. }
  851. void __init at91_add_device_serial(void)
  852. {
  853. int i;
  854. for (i = 0; i < ATMEL_MAX_UART; i++) {
  855. if (at91_uarts[i])
  856. platform_device_register(at91_uarts[i]);
  857. }
  858. }
  859. #else
  860. void __init at91_init_serial(struct at91_uart_config *config) {}
  861. void __init at91_add_device_serial(void) {}
  862. #endif
  863. /* -------------------------------------------------------------------- */
  864. /*
  865. * These devices are always present and don't need any board-specific
  866. * setup.
  867. */
  868. static int __init at91_add_standard_devices(void)
  869. {
  870. return 0;
  871. }
  872. arch_initcall(at91_add_standard_devices);