at91sam9261_devices.c 28 KB

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