at91sam9261_devices.c 28 KB

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