at91sam9261_devices.c 27 KB

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