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