at91sam9260_devices.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144
  1. /*
  2. * arch/arm/mach-at91/at91sam9260_devices.c
  3. *
  4. * Copyright (C) 2006 Atmel
  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/dma-mapping.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/i2c-gpio.h>
  17. #include <asm/arch/board.h>
  18. #include <asm/arch/gpio.h>
  19. #include <asm/arch/at91sam9260.h>
  20. #include <asm/arch/at91sam9260_matrix.h>
  21. #include <asm/arch/at91sam9_smc.h>
  22. #include "generic.h"
  23. /* --------------------------------------------------------------------
  24. * USB Host
  25. * -------------------------------------------------------------------- */
  26. #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
  27. static u64 ohci_dmamask = DMA_BIT_MASK(32);
  28. static struct at91_usbh_data usbh_data;
  29. static struct resource usbh_resources[] = {
  30. [0] = {
  31. .start = AT91SAM9260_UHP_BASE,
  32. .end = AT91SAM9260_UHP_BASE + SZ_1M - 1,
  33. .flags = IORESOURCE_MEM,
  34. },
  35. [1] = {
  36. .start = AT91SAM9260_ID_UHP,
  37. .end = AT91SAM9260_ID_UHP,
  38. .flags = IORESOURCE_IRQ,
  39. },
  40. };
  41. static struct platform_device at91_usbh_device = {
  42. .name = "at91_ohci",
  43. .id = -1,
  44. .dev = {
  45. .dma_mask = &ohci_dmamask,
  46. .coherent_dma_mask = DMA_BIT_MASK(32),
  47. .platform_data = &usbh_data,
  48. },
  49. .resource = usbh_resources,
  50. .num_resources = ARRAY_SIZE(usbh_resources),
  51. };
  52. void __init at91_add_device_usbh(struct at91_usbh_data *data)
  53. {
  54. if (!data)
  55. return;
  56. usbh_data = *data;
  57. platform_device_register(&at91_usbh_device);
  58. }
  59. #else
  60. void __init at91_add_device_usbh(struct at91_usbh_data *data) {}
  61. #endif
  62. /* --------------------------------------------------------------------
  63. * USB Device (Gadget)
  64. * -------------------------------------------------------------------- */
  65. #ifdef CONFIG_USB_GADGET_AT91
  66. static struct at91_udc_data udc_data;
  67. static struct resource udc_resources[] = {
  68. [0] = {
  69. .start = AT91SAM9260_BASE_UDP,
  70. .end = AT91SAM9260_BASE_UDP + SZ_16K - 1,
  71. .flags = IORESOURCE_MEM,
  72. },
  73. [1] = {
  74. .start = AT91SAM9260_ID_UDP,
  75. .end = AT91SAM9260_ID_UDP,
  76. .flags = IORESOURCE_IRQ,
  77. },
  78. };
  79. static struct platform_device at91_udc_device = {
  80. .name = "at91_udc",
  81. .id = -1,
  82. .dev = {
  83. .platform_data = &udc_data,
  84. },
  85. .resource = udc_resources,
  86. .num_resources = ARRAY_SIZE(udc_resources),
  87. };
  88. void __init at91_add_device_udc(struct at91_udc_data *data)
  89. {
  90. if (!data)
  91. return;
  92. if (data->vbus_pin) {
  93. at91_set_gpio_input(data->vbus_pin, 0);
  94. at91_set_deglitch(data->vbus_pin, 1);
  95. }
  96. /* Pullup pin is handled internally by USB device peripheral */
  97. udc_data = *data;
  98. platform_device_register(&at91_udc_device);
  99. }
  100. #else
  101. void __init at91_add_device_udc(struct at91_udc_data *data) {}
  102. #endif
  103. /* --------------------------------------------------------------------
  104. * Ethernet
  105. * -------------------------------------------------------------------- */
  106. #if defined(CONFIG_MACB) || defined(CONFIG_MACB_MODULE)
  107. static u64 eth_dmamask = DMA_BIT_MASK(32);
  108. static struct at91_eth_data eth_data;
  109. static struct resource eth_resources[] = {
  110. [0] = {
  111. .start = AT91SAM9260_BASE_EMAC,
  112. .end = AT91SAM9260_BASE_EMAC + SZ_16K - 1,
  113. .flags = IORESOURCE_MEM,
  114. },
  115. [1] = {
  116. .start = AT91SAM9260_ID_EMAC,
  117. .end = AT91SAM9260_ID_EMAC,
  118. .flags = IORESOURCE_IRQ,
  119. },
  120. };
  121. static struct platform_device at91sam9260_eth_device = {
  122. .name = "macb",
  123. .id = -1,
  124. .dev = {
  125. .dma_mask = &eth_dmamask,
  126. .coherent_dma_mask = DMA_BIT_MASK(32),
  127. .platform_data = &eth_data,
  128. },
  129. .resource = eth_resources,
  130. .num_resources = ARRAY_SIZE(eth_resources),
  131. };
  132. void __init at91_add_device_eth(struct at91_eth_data *data)
  133. {
  134. if (!data)
  135. return;
  136. if (data->phy_irq_pin) {
  137. at91_set_gpio_input(data->phy_irq_pin, 0);
  138. at91_set_deglitch(data->phy_irq_pin, 1);
  139. }
  140. /* Pins used for MII and RMII */
  141. at91_set_A_periph(AT91_PIN_PA19, 0); /* ETXCK_EREFCK */
  142. at91_set_A_periph(AT91_PIN_PA17, 0); /* ERXDV */
  143. at91_set_A_periph(AT91_PIN_PA14, 0); /* ERX0 */
  144. at91_set_A_periph(AT91_PIN_PA15, 0); /* ERX1 */
  145. at91_set_A_periph(AT91_PIN_PA18, 0); /* ERXER */
  146. at91_set_A_periph(AT91_PIN_PA16, 0); /* ETXEN */
  147. at91_set_A_periph(AT91_PIN_PA12, 0); /* ETX0 */
  148. at91_set_A_periph(AT91_PIN_PA13, 0); /* ETX1 */
  149. at91_set_A_periph(AT91_PIN_PA21, 0); /* EMDIO */
  150. at91_set_A_periph(AT91_PIN_PA20, 0); /* EMDC */
  151. if (!data->is_rmii) {
  152. at91_set_B_periph(AT91_PIN_PA28, 0); /* ECRS */
  153. at91_set_B_periph(AT91_PIN_PA29, 0); /* ECOL */
  154. at91_set_B_periph(AT91_PIN_PA25, 0); /* ERX2 */
  155. at91_set_B_periph(AT91_PIN_PA26, 0); /* ERX3 */
  156. at91_set_B_periph(AT91_PIN_PA27, 0); /* ERXCK */
  157. at91_set_B_periph(AT91_PIN_PA23, 0); /* ETX2 */
  158. at91_set_B_periph(AT91_PIN_PA24, 0); /* ETX3 */
  159. at91_set_B_periph(AT91_PIN_PA22, 0); /* ETXER */
  160. }
  161. eth_data = *data;
  162. platform_device_register(&at91sam9260_eth_device);
  163. }
  164. #else
  165. void __init at91_add_device_eth(struct at91_eth_data *data) {}
  166. #endif
  167. /* --------------------------------------------------------------------
  168. * MMC / SD
  169. * -------------------------------------------------------------------- */
  170. #if defined(CONFIG_MMC_AT91) || defined(CONFIG_MMC_AT91_MODULE)
  171. static u64 mmc_dmamask = DMA_BIT_MASK(32);
  172. static struct at91_mmc_data mmc_data;
  173. static struct resource mmc_resources[] = {
  174. [0] = {
  175. .start = AT91SAM9260_BASE_MCI,
  176. .end = AT91SAM9260_BASE_MCI + SZ_16K - 1,
  177. .flags = IORESOURCE_MEM,
  178. },
  179. [1] = {
  180. .start = AT91SAM9260_ID_MCI,
  181. .end = AT91SAM9260_ID_MCI,
  182. .flags = IORESOURCE_IRQ,
  183. },
  184. };
  185. static struct platform_device at91sam9260_mmc_device = {
  186. .name = "at91_mci",
  187. .id = -1,
  188. .dev = {
  189. .dma_mask = &mmc_dmamask,
  190. .coherent_dma_mask = DMA_BIT_MASK(32),
  191. .platform_data = &mmc_data,
  192. },
  193. .resource = mmc_resources,
  194. .num_resources = ARRAY_SIZE(mmc_resources),
  195. };
  196. void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data)
  197. {
  198. if (!data)
  199. return;
  200. /* input/irq */
  201. if (data->det_pin) {
  202. at91_set_gpio_input(data->det_pin, 1);
  203. at91_set_deglitch(data->det_pin, 1);
  204. }
  205. if (data->wp_pin)
  206. at91_set_gpio_input(data->wp_pin, 1);
  207. if (data->vcc_pin)
  208. at91_set_gpio_output(data->vcc_pin, 0);
  209. /* CLK */
  210. at91_set_A_periph(AT91_PIN_PA8, 0);
  211. if (data->slot_b) {
  212. /* CMD */
  213. at91_set_B_periph(AT91_PIN_PA1, 1);
  214. /* DAT0, maybe DAT1..DAT3 */
  215. at91_set_B_periph(AT91_PIN_PA0, 1);
  216. if (data->wire4) {
  217. at91_set_B_periph(AT91_PIN_PA5, 1);
  218. at91_set_B_periph(AT91_PIN_PA4, 1);
  219. at91_set_B_periph(AT91_PIN_PA3, 1);
  220. }
  221. } else {
  222. /* CMD */
  223. at91_set_A_periph(AT91_PIN_PA7, 1);
  224. /* DAT0, maybe DAT1..DAT3 */
  225. at91_set_A_periph(AT91_PIN_PA6, 1);
  226. if (data->wire4) {
  227. at91_set_A_periph(AT91_PIN_PA9, 1);
  228. at91_set_A_periph(AT91_PIN_PA10, 1);
  229. at91_set_A_periph(AT91_PIN_PA11, 1);
  230. }
  231. }
  232. mmc_data = *data;
  233. platform_device_register(&at91sam9260_mmc_device);
  234. }
  235. #else
  236. void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data) {}
  237. #endif
  238. /* --------------------------------------------------------------------
  239. * NAND / SmartMedia
  240. * -------------------------------------------------------------------- */
  241. #if defined(CONFIG_MTD_NAND_AT91) || defined(CONFIG_MTD_NAND_AT91_MODULE)
  242. static struct at91_nand_data nand_data;
  243. #define NAND_BASE AT91_CHIPSELECT_3
  244. static struct resource nand_resources[] = {
  245. [0] = {
  246. .start = NAND_BASE,
  247. .end = NAND_BASE + SZ_256M - 1,
  248. .flags = IORESOURCE_MEM,
  249. },
  250. [1] = {
  251. .start = AT91_BASE_SYS + AT91_ECC,
  252. .end = AT91_BASE_SYS + AT91_ECC + SZ_512 - 1,
  253. .flags = IORESOURCE_MEM,
  254. }
  255. };
  256. static struct platform_device at91sam9260_nand_device = {
  257. .name = "at91_nand",
  258. .id = -1,
  259. .dev = {
  260. .platform_data = &nand_data,
  261. },
  262. .resource = nand_resources,
  263. .num_resources = ARRAY_SIZE(nand_resources),
  264. };
  265. void __init at91_add_device_nand(struct at91_nand_data *data)
  266. {
  267. unsigned long csa, mode;
  268. if (!data)
  269. return;
  270. csa = at91_sys_read(AT91_MATRIX_EBICSA);
  271. at91_sys_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_CS3A_SMC_SMARTMEDIA);
  272. /* set the bus interface characteristics */
  273. at91_sys_write(AT91_SMC_SETUP(3), AT91_SMC_NWESETUP_(0) | AT91_SMC_NCS_WRSETUP_(0)
  274. | AT91_SMC_NRDSETUP_(0) | AT91_SMC_NCS_RDSETUP_(0));
  275. at91_sys_write(AT91_SMC_PULSE(3), AT91_SMC_NWEPULSE_(3) | AT91_SMC_NCS_WRPULSE_(3)
  276. | AT91_SMC_NRDPULSE_(3) | AT91_SMC_NCS_RDPULSE_(3));
  277. at91_sys_write(AT91_SMC_CYCLE(3), AT91_SMC_NWECYCLE_(5) | AT91_SMC_NRDCYCLE_(5));
  278. if (data->bus_width_16)
  279. mode = AT91_SMC_DBW_16;
  280. else
  281. mode = AT91_SMC_DBW_8;
  282. at91_sys_write(AT91_SMC_MODE(3), mode | AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_TDF_(2));
  283. /* enable pin */
  284. if (data->enable_pin)
  285. at91_set_gpio_output(data->enable_pin, 1);
  286. /* ready/busy pin */
  287. if (data->rdy_pin)
  288. at91_set_gpio_input(data->rdy_pin, 1);
  289. /* card detect pin */
  290. if (data->det_pin)
  291. at91_set_gpio_input(data->det_pin, 1);
  292. nand_data = *data;
  293. platform_device_register(&at91sam9260_nand_device);
  294. }
  295. #else
  296. void __init at91_add_device_nand(struct at91_nand_data *data) {}
  297. #endif
  298. /* --------------------------------------------------------------------
  299. * TWI (i2c)
  300. * -------------------------------------------------------------------- */
  301. /*
  302. * Prefer the GPIO code since the TWI controller isn't robust
  303. * (gets overruns and underruns under load) and can only issue
  304. * repeated STARTs in one scenario (the driver doesn't yet handle them).
  305. */
  306. #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
  307. static struct i2c_gpio_platform_data pdata = {
  308. .sda_pin = AT91_PIN_PA23,
  309. .sda_is_open_drain = 1,
  310. .scl_pin = AT91_PIN_PA24,
  311. .scl_is_open_drain = 1,
  312. .udelay = 2, /* ~100 kHz */
  313. };
  314. static struct platform_device at91sam9260_twi_device = {
  315. .name = "i2c-gpio",
  316. .id = -1,
  317. .dev.platform_data = &pdata,
  318. };
  319. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  320. {
  321. at91_set_GPIO_periph(AT91_PIN_PA23, 1); /* TWD (SDA) */
  322. at91_set_multi_drive(AT91_PIN_PA23, 1);
  323. at91_set_GPIO_periph(AT91_PIN_PA24, 1); /* TWCK (SCL) */
  324. at91_set_multi_drive(AT91_PIN_PA24, 1);
  325. i2c_register_board_info(0, devices, nr_devices);
  326. platform_device_register(&at91sam9260_twi_device);
  327. }
  328. #elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
  329. static struct resource twi_resources[] = {
  330. [0] = {
  331. .start = AT91SAM9260_BASE_TWI,
  332. .end = AT91SAM9260_BASE_TWI + SZ_16K - 1,
  333. .flags = IORESOURCE_MEM,
  334. },
  335. [1] = {
  336. .start = AT91SAM9260_ID_TWI,
  337. .end = AT91SAM9260_ID_TWI,
  338. .flags = IORESOURCE_IRQ,
  339. },
  340. };
  341. static struct platform_device at91sam9260_twi_device = {
  342. .name = "at91_i2c",
  343. .id = -1,
  344. .resource = twi_resources,
  345. .num_resources = ARRAY_SIZE(twi_resources),
  346. };
  347. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  348. {
  349. /* pins used for TWI interface */
  350. at91_set_A_periph(AT91_PIN_PA23, 0); /* TWD */
  351. at91_set_multi_drive(AT91_PIN_PA23, 1);
  352. at91_set_A_periph(AT91_PIN_PA24, 0); /* TWCK */
  353. at91_set_multi_drive(AT91_PIN_PA24, 1);
  354. i2c_register_board_info(0, devices, nr_devices);
  355. platform_device_register(&at91sam9260_twi_device);
  356. }
  357. #else
  358. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {}
  359. #endif
  360. /* --------------------------------------------------------------------
  361. * SPI
  362. * -------------------------------------------------------------------- */
  363. #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
  364. static u64 spi_dmamask = DMA_BIT_MASK(32);
  365. static struct resource spi0_resources[] = {
  366. [0] = {
  367. .start = AT91SAM9260_BASE_SPI0,
  368. .end = AT91SAM9260_BASE_SPI0 + SZ_16K - 1,
  369. .flags = IORESOURCE_MEM,
  370. },
  371. [1] = {
  372. .start = AT91SAM9260_ID_SPI0,
  373. .end = AT91SAM9260_ID_SPI0,
  374. .flags = IORESOURCE_IRQ,
  375. },
  376. };
  377. static struct platform_device at91sam9260_spi0_device = {
  378. .name = "atmel_spi",
  379. .id = 0,
  380. .dev = {
  381. .dma_mask = &spi_dmamask,
  382. .coherent_dma_mask = DMA_BIT_MASK(32),
  383. },
  384. .resource = spi0_resources,
  385. .num_resources = ARRAY_SIZE(spi0_resources),
  386. };
  387. static const unsigned spi0_standard_cs[4] = { AT91_PIN_PA3, AT91_PIN_PC11, AT91_PIN_PC16, AT91_PIN_PC17 };
  388. static struct resource spi1_resources[] = {
  389. [0] = {
  390. .start = AT91SAM9260_BASE_SPI1,
  391. .end = AT91SAM9260_BASE_SPI1 + SZ_16K - 1,
  392. .flags = IORESOURCE_MEM,
  393. },
  394. [1] = {
  395. .start = AT91SAM9260_ID_SPI1,
  396. .end = AT91SAM9260_ID_SPI1,
  397. .flags = IORESOURCE_IRQ,
  398. },
  399. };
  400. static struct platform_device at91sam9260_spi1_device = {
  401. .name = "atmel_spi",
  402. .id = 1,
  403. .dev = {
  404. .dma_mask = &spi_dmamask,
  405. .coherent_dma_mask = DMA_BIT_MASK(32),
  406. },
  407. .resource = spi1_resources,
  408. .num_resources = ARRAY_SIZE(spi1_resources),
  409. };
  410. static const unsigned spi1_standard_cs[4] = { AT91_PIN_PB3, AT91_PIN_PC5, AT91_PIN_PC4, AT91_PIN_PC3 };
  411. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
  412. {
  413. int i;
  414. unsigned long cs_pin;
  415. short enable_spi0 = 0;
  416. short enable_spi1 = 0;
  417. /* Choose SPI chip-selects */
  418. for (i = 0; i < nr_devices; i++) {
  419. if (devices[i].controller_data)
  420. cs_pin = (unsigned long) devices[i].controller_data;
  421. else if (devices[i].bus_num == 0)
  422. cs_pin = spi0_standard_cs[devices[i].chip_select];
  423. else
  424. cs_pin = spi1_standard_cs[devices[i].chip_select];
  425. if (devices[i].bus_num == 0)
  426. enable_spi0 = 1;
  427. else
  428. enable_spi1 = 1;
  429. /* enable chip-select pin */
  430. at91_set_gpio_output(cs_pin, 1);
  431. /* pass chip-select pin to driver */
  432. devices[i].controller_data = (void *) cs_pin;
  433. }
  434. spi_register_board_info(devices, nr_devices);
  435. /* Configure SPI bus(es) */
  436. if (enable_spi0) {
  437. at91_set_A_periph(AT91_PIN_PA0, 0); /* SPI0_MISO */
  438. at91_set_A_periph(AT91_PIN_PA1, 0); /* SPI0_MOSI */
  439. at91_set_A_periph(AT91_PIN_PA2, 0); /* SPI1_SPCK */
  440. at91_clock_associate("spi0_clk", &at91sam9260_spi0_device.dev, "spi_clk");
  441. platform_device_register(&at91sam9260_spi0_device);
  442. }
  443. if (enable_spi1) {
  444. at91_set_A_periph(AT91_PIN_PB0, 0); /* SPI1_MISO */
  445. at91_set_A_periph(AT91_PIN_PB1, 0); /* SPI1_MOSI */
  446. at91_set_A_periph(AT91_PIN_PB2, 0); /* SPI1_SPCK */
  447. at91_clock_associate("spi1_clk", &at91sam9260_spi1_device.dev, "spi_clk");
  448. platform_device_register(&at91sam9260_spi1_device);
  449. }
  450. }
  451. #else
  452. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
  453. #endif
  454. /* --------------------------------------------------------------------
  455. * Timer/Counter blocks
  456. * -------------------------------------------------------------------- */
  457. #ifdef CONFIG_ATMEL_TCLIB
  458. static struct resource tcb0_resources[] = {
  459. [0] = {
  460. .start = AT91SAM9260_BASE_TCB0,
  461. .end = AT91SAM9260_BASE_TCB0 + SZ_16K - 1,
  462. .flags = IORESOURCE_MEM,
  463. },
  464. [1] = {
  465. .start = AT91SAM9260_ID_TC0,
  466. .end = AT91SAM9260_ID_TC0,
  467. .flags = IORESOURCE_IRQ,
  468. },
  469. [2] = {
  470. .start = AT91SAM9260_ID_TC1,
  471. .end = AT91SAM9260_ID_TC1,
  472. .flags = IORESOURCE_IRQ,
  473. },
  474. [3] = {
  475. .start = AT91SAM9260_ID_TC2,
  476. .end = AT91SAM9260_ID_TC2,
  477. .flags = IORESOURCE_IRQ,
  478. },
  479. };
  480. static struct platform_device at91sam9260_tcb0_device = {
  481. .name = "atmel_tcb",
  482. .id = 0,
  483. .resource = tcb0_resources,
  484. .num_resources = ARRAY_SIZE(tcb0_resources),
  485. };
  486. static struct resource tcb1_resources[] = {
  487. [0] = {
  488. .start = AT91SAM9260_BASE_TCB1,
  489. .end = AT91SAM9260_BASE_TCB1 + SZ_16K - 1,
  490. .flags = IORESOURCE_MEM,
  491. },
  492. [1] = {
  493. .start = AT91SAM9260_ID_TC3,
  494. .end = AT91SAM9260_ID_TC3,
  495. .flags = IORESOURCE_IRQ,
  496. },
  497. [2] = {
  498. .start = AT91SAM9260_ID_TC4,
  499. .end = AT91SAM9260_ID_TC4,
  500. .flags = IORESOURCE_IRQ,
  501. },
  502. [3] = {
  503. .start = AT91SAM9260_ID_TC5,
  504. .end = AT91SAM9260_ID_TC5,
  505. .flags = IORESOURCE_IRQ,
  506. },
  507. };
  508. static struct platform_device at91sam9260_tcb1_device = {
  509. .name = "atmel_tcb",
  510. .id = 1,
  511. .resource = tcb1_resources,
  512. .num_resources = ARRAY_SIZE(tcb1_resources),
  513. };
  514. static void __init at91_add_device_tc(void)
  515. {
  516. /* this chip has a separate clock and irq for each TC channel */
  517. at91_clock_associate("tc0_clk", &at91sam9260_tcb0_device.dev, "t0_clk");
  518. at91_clock_associate("tc1_clk", &at91sam9260_tcb0_device.dev, "t1_clk");
  519. at91_clock_associate("tc2_clk", &at91sam9260_tcb0_device.dev, "t2_clk");
  520. platform_device_register(&at91sam9260_tcb0_device);
  521. at91_clock_associate("tc3_clk", &at91sam9260_tcb1_device.dev, "t0_clk");
  522. at91_clock_associate("tc4_clk", &at91sam9260_tcb1_device.dev, "t1_clk");
  523. at91_clock_associate("tc5_clk", &at91sam9260_tcb1_device.dev, "t2_clk");
  524. platform_device_register(&at91sam9260_tcb1_device);
  525. }
  526. #else
  527. static void __init at91_add_device_tc(void) { }
  528. #endif
  529. /* --------------------------------------------------------------------
  530. * RTT
  531. * -------------------------------------------------------------------- */
  532. static struct resource rtt_resources[] = {
  533. {
  534. .start = AT91_BASE_SYS + AT91_RTT,
  535. .end = AT91_BASE_SYS + AT91_RTT + SZ_16 - 1,
  536. .flags = IORESOURCE_MEM,
  537. }
  538. };
  539. static struct platform_device at91sam9260_rtt_device = {
  540. .name = "at91_rtt",
  541. .id = 0,
  542. .resource = rtt_resources,
  543. .num_resources = ARRAY_SIZE(rtt_resources),
  544. };
  545. static void __init at91_add_device_rtt(void)
  546. {
  547. platform_device_register(&at91sam9260_rtt_device);
  548. }
  549. /* --------------------------------------------------------------------
  550. * Watchdog
  551. * -------------------------------------------------------------------- */
  552. #if defined(CONFIG_AT91SAM9_WATCHDOG) || defined(CONFIG_AT91SAM9_WATCHDOG_MODULE)
  553. static struct platform_device at91sam9260_wdt_device = {
  554. .name = "at91_wdt",
  555. .id = -1,
  556. .num_resources = 0,
  557. };
  558. static void __init at91_add_device_watchdog(void)
  559. {
  560. platform_device_register(&at91sam9260_wdt_device);
  561. }
  562. #else
  563. static void __init at91_add_device_watchdog(void) {}
  564. #endif
  565. /* --------------------------------------------------------------------
  566. * SSC -- Synchronous Serial Controller
  567. * -------------------------------------------------------------------- */
  568. #if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
  569. static u64 ssc_dmamask = DMA_BIT_MASK(32);
  570. static struct resource ssc_resources[] = {
  571. [0] = {
  572. .start = AT91SAM9260_BASE_SSC,
  573. .end = AT91SAM9260_BASE_SSC + SZ_16K - 1,
  574. .flags = IORESOURCE_MEM,
  575. },
  576. [1] = {
  577. .start = AT91SAM9260_ID_SSC,
  578. .end = AT91SAM9260_ID_SSC,
  579. .flags = IORESOURCE_IRQ,
  580. },
  581. };
  582. static struct platform_device at91sam9260_ssc_device = {
  583. .name = "ssc",
  584. .id = 0,
  585. .dev = {
  586. .dma_mask = &ssc_dmamask,
  587. .coherent_dma_mask = DMA_BIT_MASK(32),
  588. },
  589. .resource = ssc_resources,
  590. .num_resources = ARRAY_SIZE(ssc_resources),
  591. };
  592. static inline void configure_ssc_pins(unsigned pins)
  593. {
  594. if (pins & ATMEL_SSC_TF)
  595. at91_set_A_periph(AT91_PIN_PB17, 1);
  596. if (pins & ATMEL_SSC_TK)
  597. at91_set_A_periph(AT91_PIN_PB16, 1);
  598. if (pins & ATMEL_SSC_TD)
  599. at91_set_A_periph(AT91_PIN_PB18, 1);
  600. if (pins & ATMEL_SSC_RD)
  601. at91_set_A_periph(AT91_PIN_PB19, 1);
  602. if (pins & ATMEL_SSC_RK)
  603. at91_set_A_periph(AT91_PIN_PB20, 1);
  604. if (pins & ATMEL_SSC_RF)
  605. at91_set_A_periph(AT91_PIN_PB21, 1);
  606. }
  607. /*
  608. * SSC controllers are accessed through library code, instead of any
  609. * kind of all-singing/all-dancing driver. For example one could be
  610. * used by a particular I2S audio codec's driver, while another one
  611. * on the same system might be used by a custom data capture driver.
  612. */
  613. void __init at91_add_device_ssc(unsigned id, unsigned pins)
  614. {
  615. struct platform_device *pdev;
  616. /*
  617. * NOTE: caller is responsible for passing information matching
  618. * "pins" to whatever will be using each particular controller.
  619. */
  620. switch (id) {
  621. case AT91SAM9260_ID_SSC:
  622. pdev = &at91sam9260_ssc_device;
  623. configure_ssc_pins(pins);
  624. at91_clock_associate("ssc_clk", &pdev->dev, "pclk");
  625. break;
  626. default:
  627. return;
  628. }
  629. platform_device_register(pdev);
  630. }
  631. #else
  632. void __init at91_add_device_ssc(unsigned id, unsigned pins) {}
  633. #endif
  634. /* --------------------------------------------------------------------
  635. * UART
  636. * -------------------------------------------------------------------- */
  637. #if defined(CONFIG_SERIAL_ATMEL)
  638. static struct resource dbgu_resources[] = {
  639. [0] = {
  640. .start = AT91_VA_BASE_SYS + AT91_DBGU,
  641. .end = AT91_VA_BASE_SYS + AT91_DBGU + SZ_512 - 1,
  642. .flags = IORESOURCE_MEM,
  643. },
  644. [1] = {
  645. .start = AT91_ID_SYS,
  646. .end = AT91_ID_SYS,
  647. .flags = IORESOURCE_IRQ,
  648. },
  649. };
  650. static struct atmel_uart_data dbgu_data = {
  651. .use_dma_tx = 0,
  652. .use_dma_rx = 0, /* DBGU not capable of receive DMA */
  653. .regs = (void __iomem *)(AT91_VA_BASE_SYS + AT91_DBGU),
  654. };
  655. static u64 dbgu_dmamask = DMA_BIT_MASK(32);
  656. static struct platform_device at91sam9260_dbgu_device = {
  657. .name = "atmel_usart",
  658. .id = 0,
  659. .dev = {
  660. .dma_mask = &dbgu_dmamask,
  661. .coherent_dma_mask = DMA_BIT_MASK(32),
  662. .platform_data = &dbgu_data,
  663. },
  664. .resource = dbgu_resources,
  665. .num_resources = ARRAY_SIZE(dbgu_resources),
  666. };
  667. static inline void configure_dbgu_pins(void)
  668. {
  669. at91_set_A_periph(AT91_PIN_PB14, 0); /* DRXD */
  670. at91_set_A_periph(AT91_PIN_PB15, 1); /* DTXD */
  671. }
  672. static struct resource uart0_resources[] = {
  673. [0] = {
  674. .start = AT91SAM9260_BASE_US0,
  675. .end = AT91SAM9260_BASE_US0 + SZ_16K - 1,
  676. .flags = IORESOURCE_MEM,
  677. },
  678. [1] = {
  679. .start = AT91SAM9260_ID_US0,
  680. .end = AT91SAM9260_ID_US0,
  681. .flags = IORESOURCE_IRQ,
  682. },
  683. };
  684. static struct atmel_uart_data uart0_data = {
  685. .use_dma_tx = 1,
  686. .use_dma_rx = 1,
  687. };
  688. static u64 uart0_dmamask = DMA_BIT_MASK(32);
  689. static struct platform_device at91sam9260_uart0_device = {
  690. .name = "atmel_usart",
  691. .id = 1,
  692. .dev = {
  693. .dma_mask = &uart0_dmamask,
  694. .coherent_dma_mask = DMA_BIT_MASK(32),
  695. .platform_data = &uart0_data,
  696. },
  697. .resource = uart0_resources,
  698. .num_resources = ARRAY_SIZE(uart0_resources),
  699. };
  700. static inline void configure_usart0_pins(unsigned pins)
  701. {
  702. at91_set_A_periph(AT91_PIN_PB4, 1); /* TXD0 */
  703. at91_set_A_periph(AT91_PIN_PB5, 0); /* RXD0 */
  704. if (pins & ATMEL_UART_RTS)
  705. at91_set_A_periph(AT91_PIN_PB26, 0); /* RTS0 */
  706. if (pins & ATMEL_UART_CTS)
  707. at91_set_A_periph(AT91_PIN_PB27, 0); /* CTS0 */
  708. if (pins & ATMEL_UART_DTR)
  709. at91_set_A_periph(AT91_PIN_PB24, 0); /* DTR0 */
  710. if (pins & ATMEL_UART_DSR)
  711. at91_set_A_periph(AT91_PIN_PB22, 0); /* DSR0 */
  712. if (pins & ATMEL_UART_DCD)
  713. at91_set_A_periph(AT91_PIN_PB23, 0); /* DCD0 */
  714. if (pins & ATMEL_UART_RI)
  715. at91_set_A_periph(AT91_PIN_PB25, 0); /* RI0 */
  716. }
  717. static struct resource uart1_resources[] = {
  718. [0] = {
  719. .start = AT91SAM9260_BASE_US1,
  720. .end = AT91SAM9260_BASE_US1 + SZ_16K - 1,
  721. .flags = IORESOURCE_MEM,
  722. },
  723. [1] = {
  724. .start = AT91SAM9260_ID_US1,
  725. .end = AT91SAM9260_ID_US1,
  726. .flags = IORESOURCE_IRQ,
  727. },
  728. };
  729. static struct atmel_uart_data uart1_data = {
  730. .use_dma_tx = 1,
  731. .use_dma_rx = 1,
  732. };
  733. static u64 uart1_dmamask = DMA_BIT_MASK(32);
  734. static struct platform_device at91sam9260_uart1_device = {
  735. .name = "atmel_usart",
  736. .id = 2,
  737. .dev = {
  738. .dma_mask = &uart1_dmamask,
  739. .coherent_dma_mask = DMA_BIT_MASK(32),
  740. .platform_data = &uart1_data,
  741. },
  742. .resource = uart1_resources,
  743. .num_resources = ARRAY_SIZE(uart1_resources),
  744. };
  745. static inline void configure_usart1_pins(unsigned pins)
  746. {
  747. at91_set_A_periph(AT91_PIN_PB6, 1); /* TXD1 */
  748. at91_set_A_periph(AT91_PIN_PB7, 0); /* RXD1 */
  749. if (pins & ATMEL_UART_RTS)
  750. at91_set_A_periph(AT91_PIN_PB28, 0); /* RTS1 */
  751. if (pins & ATMEL_UART_CTS)
  752. at91_set_A_periph(AT91_PIN_PB29, 0); /* CTS1 */
  753. }
  754. static struct resource uart2_resources[] = {
  755. [0] = {
  756. .start = AT91SAM9260_BASE_US2,
  757. .end = AT91SAM9260_BASE_US2 + SZ_16K - 1,
  758. .flags = IORESOURCE_MEM,
  759. },
  760. [1] = {
  761. .start = AT91SAM9260_ID_US2,
  762. .end = AT91SAM9260_ID_US2,
  763. .flags = IORESOURCE_IRQ,
  764. },
  765. };
  766. static struct atmel_uart_data uart2_data = {
  767. .use_dma_tx = 1,
  768. .use_dma_rx = 1,
  769. };
  770. static u64 uart2_dmamask = DMA_BIT_MASK(32);
  771. static struct platform_device at91sam9260_uart2_device = {
  772. .name = "atmel_usart",
  773. .id = 3,
  774. .dev = {
  775. .dma_mask = &uart2_dmamask,
  776. .coherent_dma_mask = DMA_BIT_MASK(32),
  777. .platform_data = &uart2_data,
  778. },
  779. .resource = uart2_resources,
  780. .num_resources = ARRAY_SIZE(uart2_resources),
  781. };
  782. static inline void configure_usart2_pins(unsigned pins)
  783. {
  784. at91_set_A_periph(AT91_PIN_PB8, 1); /* TXD2 */
  785. at91_set_A_periph(AT91_PIN_PB9, 0); /* RXD2 */
  786. if (pins & ATMEL_UART_RTS)
  787. at91_set_A_periph(AT91_PIN_PA4, 0); /* RTS2 */
  788. if (pins & ATMEL_UART_CTS)
  789. at91_set_A_periph(AT91_PIN_PA5, 0); /* CTS2 */
  790. }
  791. static struct resource uart3_resources[] = {
  792. [0] = {
  793. .start = AT91SAM9260_BASE_US3,
  794. .end = AT91SAM9260_BASE_US3 + SZ_16K - 1,
  795. .flags = IORESOURCE_MEM,
  796. },
  797. [1] = {
  798. .start = AT91SAM9260_ID_US3,
  799. .end = AT91SAM9260_ID_US3,
  800. .flags = IORESOURCE_IRQ,
  801. },
  802. };
  803. static struct atmel_uart_data uart3_data = {
  804. .use_dma_tx = 1,
  805. .use_dma_rx = 1,
  806. };
  807. static u64 uart3_dmamask = DMA_BIT_MASK(32);
  808. static struct platform_device at91sam9260_uart3_device = {
  809. .name = "atmel_usart",
  810. .id = 4,
  811. .dev = {
  812. .dma_mask = &uart3_dmamask,
  813. .coherent_dma_mask = DMA_BIT_MASK(32),
  814. .platform_data = &uart3_data,
  815. },
  816. .resource = uart3_resources,
  817. .num_resources = ARRAY_SIZE(uart3_resources),
  818. };
  819. static inline void configure_usart3_pins(unsigned pins)
  820. {
  821. at91_set_A_periph(AT91_PIN_PB10, 1); /* TXD3 */
  822. at91_set_A_periph(AT91_PIN_PB11, 0); /* RXD3 */
  823. if (pins & ATMEL_UART_RTS)
  824. at91_set_B_periph(AT91_PIN_PC8, 0); /* RTS3 */
  825. if (pins & ATMEL_UART_CTS)
  826. at91_set_B_periph(AT91_PIN_PC10, 0); /* CTS3 */
  827. }
  828. static struct resource uart4_resources[] = {
  829. [0] = {
  830. .start = AT91SAM9260_BASE_US4,
  831. .end = AT91SAM9260_BASE_US4 + SZ_16K - 1,
  832. .flags = IORESOURCE_MEM,
  833. },
  834. [1] = {
  835. .start = AT91SAM9260_ID_US4,
  836. .end = AT91SAM9260_ID_US4,
  837. .flags = IORESOURCE_IRQ,
  838. },
  839. };
  840. static struct atmel_uart_data uart4_data = {
  841. .use_dma_tx = 1,
  842. .use_dma_rx = 1,
  843. };
  844. static u64 uart4_dmamask = DMA_BIT_MASK(32);
  845. static struct platform_device at91sam9260_uart4_device = {
  846. .name = "atmel_usart",
  847. .id = 5,
  848. .dev = {
  849. .dma_mask = &uart4_dmamask,
  850. .coherent_dma_mask = DMA_BIT_MASK(32),
  851. .platform_data = &uart4_data,
  852. },
  853. .resource = uart4_resources,
  854. .num_resources = ARRAY_SIZE(uart4_resources),
  855. };
  856. static inline void configure_usart4_pins(void)
  857. {
  858. at91_set_B_periph(AT91_PIN_PA31, 1); /* TXD4 */
  859. at91_set_B_periph(AT91_PIN_PA30, 0); /* RXD4 */
  860. }
  861. static struct resource uart5_resources[] = {
  862. [0] = {
  863. .start = AT91SAM9260_BASE_US5,
  864. .end = AT91SAM9260_BASE_US5 + SZ_16K - 1,
  865. .flags = IORESOURCE_MEM,
  866. },
  867. [1] = {
  868. .start = AT91SAM9260_ID_US5,
  869. .end = AT91SAM9260_ID_US5,
  870. .flags = IORESOURCE_IRQ,
  871. },
  872. };
  873. static struct atmel_uart_data uart5_data = {
  874. .use_dma_tx = 1,
  875. .use_dma_rx = 1,
  876. };
  877. static u64 uart5_dmamask = DMA_BIT_MASK(32);
  878. static struct platform_device at91sam9260_uart5_device = {
  879. .name = "atmel_usart",
  880. .id = 6,
  881. .dev = {
  882. .dma_mask = &uart5_dmamask,
  883. .coherent_dma_mask = DMA_BIT_MASK(32),
  884. .platform_data = &uart5_data,
  885. },
  886. .resource = uart5_resources,
  887. .num_resources = ARRAY_SIZE(uart5_resources),
  888. };
  889. static inline void configure_usart5_pins(void)
  890. {
  891. at91_set_A_periph(AT91_PIN_PB12, 1); /* TXD5 */
  892. at91_set_A_periph(AT91_PIN_PB13, 0); /* RXD5 */
  893. }
  894. static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
  895. struct platform_device *atmel_default_console_device; /* the serial console device */
  896. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
  897. {
  898. struct platform_device *pdev;
  899. switch (id) {
  900. case 0: /* DBGU */
  901. pdev = &at91sam9260_dbgu_device;
  902. configure_dbgu_pins();
  903. at91_clock_associate("mck", &pdev->dev, "usart");
  904. break;
  905. case AT91SAM9260_ID_US0:
  906. pdev = &at91sam9260_uart0_device;
  907. configure_usart0_pins(pins);
  908. at91_clock_associate("usart0_clk", &pdev->dev, "usart");
  909. break;
  910. case AT91SAM9260_ID_US1:
  911. pdev = &at91sam9260_uart1_device;
  912. configure_usart1_pins(pins);
  913. at91_clock_associate("usart1_clk", &pdev->dev, "usart");
  914. break;
  915. case AT91SAM9260_ID_US2:
  916. pdev = &at91sam9260_uart2_device;
  917. configure_usart2_pins(pins);
  918. at91_clock_associate("usart2_clk", &pdev->dev, "usart");
  919. break;
  920. case AT91SAM9260_ID_US3:
  921. pdev = &at91sam9260_uart3_device;
  922. configure_usart3_pins(pins);
  923. at91_clock_associate("usart3_clk", &pdev->dev, "usart");
  924. break;
  925. case AT91SAM9260_ID_US4:
  926. pdev = &at91sam9260_uart4_device;
  927. configure_usart4_pins();
  928. at91_clock_associate("usart4_clk", &pdev->dev, "usart");
  929. break;
  930. case AT91SAM9260_ID_US5:
  931. pdev = &at91sam9260_uart5_device;
  932. configure_usart5_pins();
  933. at91_clock_associate("usart5_clk", &pdev->dev, "usart");
  934. break;
  935. default:
  936. return;
  937. }
  938. pdev->id = portnr; /* update to mapped ID */
  939. if (portnr < ATMEL_MAX_UART)
  940. at91_uarts[portnr] = pdev;
  941. }
  942. void __init at91_set_serial_console(unsigned portnr)
  943. {
  944. if (portnr < ATMEL_MAX_UART)
  945. atmel_default_console_device = at91_uarts[portnr];
  946. }
  947. void __init at91_add_device_serial(void)
  948. {
  949. int i;
  950. for (i = 0; i < ATMEL_MAX_UART; i++) {
  951. if (at91_uarts[i])
  952. platform_device_register(at91_uarts[i]);
  953. }
  954. if (!atmel_default_console_device)
  955. printk(KERN_INFO "AT91: No default serial console defined.\n");
  956. }
  957. #else
  958. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
  959. void __init at91_set_serial_console(unsigned portnr) {}
  960. void __init at91_add_device_serial(void) {}
  961. #endif
  962. /* -------------------------------------------------------------------- */
  963. /*
  964. * These devices are always present and don't need any board-specific
  965. * setup.
  966. */
  967. static int __init at91_add_standard_devices(void)
  968. {
  969. at91_add_device_rtt();
  970. at91_add_device_watchdog();
  971. at91_add_device_tc();
  972. return 0;
  973. }
  974. arch_initcall(at91_add_standard_devices);