at91sam9261_devices.c 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097
  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 "board.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. .id = 0,
  407. .dev = {
  408. .dma_mask = &lcdc_dmamask,
  409. .coherent_dma_mask = DMA_BIT_MASK(32),
  410. .platform_data = &lcdc_data,
  411. },
  412. .resource = lcdc_resources,
  413. .num_resources = ARRAY_SIZE(lcdc_resources),
  414. };
  415. void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data)
  416. {
  417. if (!data) {
  418. return;
  419. }
  420. if (cpu_is_at91sam9g10())
  421. at91_lcdc_device.name = "at91sam9g10-lcdfb";
  422. else
  423. at91_lcdc_device.name = "at91sam9261-lcdfb";
  424. #if defined(CONFIG_FB_ATMEL_STN)
  425. at91_set_A_periph(AT91_PIN_PB0, 0); /* LCDVSYNC */
  426. at91_set_A_periph(AT91_PIN_PB1, 0); /* LCDHSYNC */
  427. at91_set_A_periph(AT91_PIN_PB2, 0); /* LCDDOTCK */
  428. at91_set_A_periph(AT91_PIN_PB3, 0); /* LCDDEN */
  429. at91_set_A_periph(AT91_PIN_PB4, 0); /* LCDCC */
  430. at91_set_A_periph(AT91_PIN_PB5, 0); /* LCDD0 */
  431. at91_set_A_periph(AT91_PIN_PB6, 0); /* LCDD1 */
  432. at91_set_A_periph(AT91_PIN_PB7, 0); /* LCDD2 */
  433. at91_set_A_periph(AT91_PIN_PB8, 0); /* LCDD3 */
  434. #else
  435. at91_set_A_periph(AT91_PIN_PB1, 0); /* LCDHSYNC */
  436. at91_set_A_periph(AT91_PIN_PB2, 0); /* LCDDOTCK */
  437. at91_set_A_periph(AT91_PIN_PB3, 0); /* LCDDEN */
  438. at91_set_A_periph(AT91_PIN_PB4, 0); /* LCDCC */
  439. at91_set_A_periph(AT91_PIN_PB7, 0); /* LCDD2 */
  440. at91_set_A_periph(AT91_PIN_PB8, 0); /* LCDD3 */
  441. at91_set_A_periph(AT91_PIN_PB9, 0); /* LCDD4 */
  442. at91_set_A_periph(AT91_PIN_PB10, 0); /* LCDD5 */
  443. at91_set_A_periph(AT91_PIN_PB11, 0); /* LCDD6 */
  444. at91_set_A_periph(AT91_PIN_PB12, 0); /* LCDD7 */
  445. at91_set_A_periph(AT91_PIN_PB15, 0); /* LCDD10 */
  446. at91_set_A_periph(AT91_PIN_PB16, 0); /* LCDD11 */
  447. at91_set_A_periph(AT91_PIN_PB17, 0); /* LCDD12 */
  448. at91_set_A_periph(AT91_PIN_PB18, 0); /* LCDD13 */
  449. at91_set_A_periph(AT91_PIN_PB19, 0); /* LCDD14 */
  450. at91_set_A_periph(AT91_PIN_PB20, 0); /* LCDD15 */
  451. at91_set_B_periph(AT91_PIN_PB23, 0); /* LCDD18 */
  452. at91_set_B_periph(AT91_PIN_PB24, 0); /* LCDD19 */
  453. at91_set_B_periph(AT91_PIN_PB25, 0); /* LCDD20 */
  454. at91_set_B_periph(AT91_PIN_PB26, 0); /* LCDD21 */
  455. at91_set_B_periph(AT91_PIN_PB27, 0); /* LCDD22 */
  456. at91_set_B_periph(AT91_PIN_PB28, 0); /* LCDD23 */
  457. #endif
  458. if (ARRAY_SIZE(lcdc_resources) > 2) {
  459. void __iomem *fb;
  460. struct resource *fb_res = &lcdc_resources[2];
  461. size_t fb_len = resource_size(fb_res);
  462. fb = ioremap(fb_res->start, fb_len);
  463. if (fb) {
  464. memset(fb, 0, fb_len);
  465. iounmap(fb);
  466. }
  467. }
  468. lcdc_data = *data;
  469. platform_device_register(&at91_lcdc_device);
  470. }
  471. #else
  472. void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data) {}
  473. #endif
  474. /* --------------------------------------------------------------------
  475. * Timer/Counter block
  476. * -------------------------------------------------------------------- */
  477. #ifdef CONFIG_ATMEL_TCLIB
  478. static struct resource tcb_resources[] = {
  479. [0] = {
  480. .start = AT91SAM9261_BASE_TCB0,
  481. .end = AT91SAM9261_BASE_TCB0 + SZ_16K - 1,
  482. .flags = IORESOURCE_MEM,
  483. },
  484. [1] = {
  485. .start = NR_IRQS_LEGACY + AT91SAM9261_ID_TC0,
  486. .end = NR_IRQS_LEGACY + AT91SAM9261_ID_TC0,
  487. .flags = IORESOURCE_IRQ,
  488. },
  489. [2] = {
  490. .start = NR_IRQS_LEGACY + AT91SAM9261_ID_TC1,
  491. .end = NR_IRQS_LEGACY + AT91SAM9261_ID_TC1,
  492. .flags = IORESOURCE_IRQ,
  493. },
  494. [3] = {
  495. .start = NR_IRQS_LEGACY + AT91SAM9261_ID_TC2,
  496. .end = NR_IRQS_LEGACY + AT91SAM9261_ID_TC2,
  497. .flags = IORESOURCE_IRQ,
  498. },
  499. };
  500. static struct platform_device at91sam9261_tcb_device = {
  501. .name = "atmel_tcb",
  502. .id = 0,
  503. .resource = tcb_resources,
  504. .num_resources = ARRAY_SIZE(tcb_resources),
  505. };
  506. static void __init at91_add_device_tc(void)
  507. {
  508. platform_device_register(&at91sam9261_tcb_device);
  509. }
  510. #else
  511. static void __init at91_add_device_tc(void) { }
  512. #endif
  513. /* --------------------------------------------------------------------
  514. * RTT
  515. * -------------------------------------------------------------------- */
  516. static struct resource rtt_resources[] = {
  517. {
  518. .start = AT91SAM9261_BASE_RTT,
  519. .end = AT91SAM9261_BASE_RTT + SZ_16 - 1,
  520. .flags = IORESOURCE_MEM,
  521. }, {
  522. .flags = IORESOURCE_MEM,
  523. }, {
  524. .flags = IORESOURCE_IRQ,
  525. }
  526. };
  527. static struct platform_device at91sam9261_rtt_device = {
  528. .name = "at91_rtt",
  529. .id = 0,
  530. .resource = rtt_resources,
  531. };
  532. #if IS_ENABLED(CONFIG_RTC_DRV_AT91SAM9)
  533. static void __init at91_add_device_rtt_rtc(void)
  534. {
  535. at91sam9261_rtt_device.name = "rtc-at91sam9";
  536. /*
  537. * The second resource is needed:
  538. * GPBR will serve as the storage for RTC time offset
  539. */
  540. at91sam9261_rtt_device.num_resources = 3;
  541. rtt_resources[1].start = AT91SAM9261_BASE_GPBR +
  542. 4 * CONFIG_RTC_DRV_AT91SAM9_GPBR;
  543. rtt_resources[1].end = rtt_resources[1].start + 3;
  544. rtt_resources[2].start = NR_IRQS_LEGACY + AT91_ID_SYS;
  545. rtt_resources[2].end = NR_IRQS_LEGACY + AT91_ID_SYS;
  546. }
  547. #else
  548. static void __init at91_add_device_rtt_rtc(void)
  549. {
  550. /* Only one resource is needed: RTT not used as RTC */
  551. at91sam9261_rtt_device.num_resources = 1;
  552. }
  553. #endif
  554. static void __init at91_add_device_rtt(void)
  555. {
  556. at91_add_device_rtt_rtc();
  557. platform_device_register(&at91sam9261_rtt_device);
  558. }
  559. /* --------------------------------------------------------------------
  560. * Watchdog
  561. * -------------------------------------------------------------------- */
  562. #if defined(CONFIG_AT91SAM9X_WATCHDOG) || defined(CONFIG_AT91SAM9X_WATCHDOG_MODULE)
  563. static struct resource wdt_resources[] = {
  564. {
  565. .start = AT91SAM9261_BASE_WDT,
  566. .end = AT91SAM9261_BASE_WDT + SZ_16 - 1,
  567. .flags = IORESOURCE_MEM,
  568. }
  569. };
  570. static struct platform_device at91sam9261_wdt_device = {
  571. .name = "at91_wdt",
  572. .id = -1,
  573. .resource = wdt_resources,
  574. .num_resources = ARRAY_SIZE(wdt_resources),
  575. };
  576. static void __init at91_add_device_watchdog(void)
  577. {
  578. platform_device_register(&at91sam9261_wdt_device);
  579. }
  580. #else
  581. static void __init at91_add_device_watchdog(void) {}
  582. #endif
  583. /* --------------------------------------------------------------------
  584. * SSC -- Synchronous Serial Controller
  585. * -------------------------------------------------------------------- */
  586. #if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
  587. static u64 ssc0_dmamask = DMA_BIT_MASK(32);
  588. static struct resource ssc0_resources[] = {
  589. [0] = {
  590. .start = AT91SAM9261_BASE_SSC0,
  591. .end = AT91SAM9261_BASE_SSC0 + SZ_16K - 1,
  592. .flags = IORESOURCE_MEM,
  593. },
  594. [1] = {
  595. .start = NR_IRQS_LEGACY + AT91SAM9261_ID_SSC0,
  596. .end = NR_IRQS_LEGACY + AT91SAM9261_ID_SSC0,
  597. .flags = IORESOURCE_IRQ,
  598. },
  599. };
  600. static struct platform_device at91sam9261_ssc0_device = {
  601. .name = "at91rm9200_ssc",
  602. .id = 0,
  603. .dev = {
  604. .dma_mask = &ssc0_dmamask,
  605. .coherent_dma_mask = DMA_BIT_MASK(32),
  606. },
  607. .resource = ssc0_resources,
  608. .num_resources = ARRAY_SIZE(ssc0_resources),
  609. };
  610. static inline void configure_ssc0_pins(unsigned pins)
  611. {
  612. if (pins & ATMEL_SSC_TF)
  613. at91_set_A_periph(AT91_PIN_PB21, 1);
  614. if (pins & ATMEL_SSC_TK)
  615. at91_set_A_periph(AT91_PIN_PB22, 1);
  616. if (pins & ATMEL_SSC_TD)
  617. at91_set_A_periph(AT91_PIN_PB23, 1);
  618. if (pins & ATMEL_SSC_RD)
  619. at91_set_A_periph(AT91_PIN_PB24, 1);
  620. if (pins & ATMEL_SSC_RK)
  621. at91_set_A_periph(AT91_PIN_PB25, 1);
  622. if (pins & ATMEL_SSC_RF)
  623. at91_set_A_periph(AT91_PIN_PB26, 1);
  624. }
  625. static u64 ssc1_dmamask = DMA_BIT_MASK(32);
  626. static struct resource ssc1_resources[] = {
  627. [0] = {
  628. .start = AT91SAM9261_BASE_SSC1,
  629. .end = AT91SAM9261_BASE_SSC1 + SZ_16K - 1,
  630. .flags = IORESOURCE_MEM,
  631. },
  632. [1] = {
  633. .start = NR_IRQS_LEGACY + AT91SAM9261_ID_SSC1,
  634. .end = NR_IRQS_LEGACY + AT91SAM9261_ID_SSC1,
  635. .flags = IORESOURCE_IRQ,
  636. },
  637. };
  638. static struct platform_device at91sam9261_ssc1_device = {
  639. .name = "at91rm9200_ssc",
  640. .id = 1,
  641. .dev = {
  642. .dma_mask = &ssc1_dmamask,
  643. .coherent_dma_mask = DMA_BIT_MASK(32),
  644. },
  645. .resource = ssc1_resources,
  646. .num_resources = ARRAY_SIZE(ssc1_resources),
  647. };
  648. static inline void configure_ssc1_pins(unsigned pins)
  649. {
  650. if (pins & ATMEL_SSC_TF)
  651. at91_set_B_periph(AT91_PIN_PA17, 1);
  652. if (pins & ATMEL_SSC_TK)
  653. at91_set_B_periph(AT91_PIN_PA18, 1);
  654. if (pins & ATMEL_SSC_TD)
  655. at91_set_B_periph(AT91_PIN_PA19, 1);
  656. if (pins & ATMEL_SSC_RD)
  657. at91_set_B_periph(AT91_PIN_PA20, 1);
  658. if (pins & ATMEL_SSC_RK)
  659. at91_set_B_periph(AT91_PIN_PA21, 1);
  660. if (pins & ATMEL_SSC_RF)
  661. at91_set_B_periph(AT91_PIN_PA22, 1);
  662. }
  663. static u64 ssc2_dmamask = DMA_BIT_MASK(32);
  664. static struct resource ssc2_resources[] = {
  665. [0] = {
  666. .start = AT91SAM9261_BASE_SSC2,
  667. .end = AT91SAM9261_BASE_SSC2 + SZ_16K - 1,
  668. .flags = IORESOURCE_MEM,
  669. },
  670. [1] = {
  671. .start = NR_IRQS_LEGACY + AT91SAM9261_ID_SSC2,
  672. .end = NR_IRQS_LEGACY + AT91SAM9261_ID_SSC2,
  673. .flags = IORESOURCE_IRQ,
  674. },
  675. };
  676. static struct platform_device at91sam9261_ssc2_device = {
  677. .name = "at91rm9200_ssc",
  678. .id = 2,
  679. .dev = {
  680. .dma_mask = &ssc2_dmamask,
  681. .coherent_dma_mask = DMA_BIT_MASK(32),
  682. },
  683. .resource = ssc2_resources,
  684. .num_resources = ARRAY_SIZE(ssc2_resources),
  685. };
  686. static inline void configure_ssc2_pins(unsigned pins)
  687. {
  688. if (pins & ATMEL_SSC_TF)
  689. at91_set_B_periph(AT91_PIN_PC25, 1);
  690. if (pins & ATMEL_SSC_TK)
  691. at91_set_B_periph(AT91_PIN_PC26, 1);
  692. if (pins & ATMEL_SSC_TD)
  693. at91_set_B_periph(AT91_PIN_PC27, 1);
  694. if (pins & ATMEL_SSC_RD)
  695. at91_set_B_periph(AT91_PIN_PC28, 1);
  696. if (pins & ATMEL_SSC_RK)
  697. at91_set_B_periph(AT91_PIN_PC29, 1);
  698. if (pins & ATMEL_SSC_RF)
  699. at91_set_B_periph(AT91_PIN_PC30, 1);
  700. }
  701. /*
  702. * SSC controllers are accessed through library code, instead of any
  703. * kind of all-singing/all-dancing driver. For example one could be
  704. * used by a particular I2S audio codec's driver, while another one
  705. * on the same system might be used by a custom data capture driver.
  706. */
  707. void __init at91_add_device_ssc(unsigned id, unsigned pins)
  708. {
  709. struct platform_device *pdev;
  710. /*
  711. * NOTE: caller is responsible for passing information matching
  712. * "pins" to whatever will be using each particular controller.
  713. */
  714. switch (id) {
  715. case AT91SAM9261_ID_SSC0:
  716. pdev = &at91sam9261_ssc0_device;
  717. configure_ssc0_pins(pins);
  718. break;
  719. case AT91SAM9261_ID_SSC1:
  720. pdev = &at91sam9261_ssc1_device;
  721. configure_ssc1_pins(pins);
  722. break;
  723. case AT91SAM9261_ID_SSC2:
  724. pdev = &at91sam9261_ssc2_device;
  725. configure_ssc2_pins(pins);
  726. break;
  727. default:
  728. return;
  729. }
  730. platform_device_register(pdev);
  731. }
  732. #else
  733. void __init at91_add_device_ssc(unsigned id, unsigned pins) {}
  734. #endif
  735. /* --------------------------------------------------------------------
  736. * UART
  737. * -------------------------------------------------------------------- */
  738. #if defined(CONFIG_SERIAL_ATMEL)
  739. static struct resource dbgu_resources[] = {
  740. [0] = {
  741. .start = AT91SAM9261_BASE_DBGU,
  742. .end = AT91SAM9261_BASE_DBGU + SZ_512 - 1,
  743. .flags = IORESOURCE_MEM,
  744. },
  745. [1] = {
  746. .start = NR_IRQS_LEGACY + AT91_ID_SYS,
  747. .end = NR_IRQS_LEGACY + AT91_ID_SYS,
  748. .flags = IORESOURCE_IRQ,
  749. },
  750. };
  751. static struct atmel_uart_data dbgu_data = {
  752. .use_dma_tx = 0,
  753. .use_dma_rx = 0, /* DBGU not capable of receive DMA */
  754. };
  755. static u64 dbgu_dmamask = DMA_BIT_MASK(32);
  756. static struct platform_device at91sam9261_dbgu_device = {
  757. .name = "atmel_usart",
  758. .id = 0,
  759. .dev = {
  760. .dma_mask = &dbgu_dmamask,
  761. .coherent_dma_mask = DMA_BIT_MASK(32),
  762. .platform_data = &dbgu_data,
  763. },
  764. .resource = dbgu_resources,
  765. .num_resources = ARRAY_SIZE(dbgu_resources),
  766. };
  767. static inline void configure_dbgu_pins(void)
  768. {
  769. at91_set_A_periph(AT91_PIN_PA9, 0); /* DRXD */
  770. at91_set_A_periph(AT91_PIN_PA10, 1); /* DTXD */
  771. }
  772. static struct resource uart0_resources[] = {
  773. [0] = {
  774. .start = AT91SAM9261_BASE_US0,
  775. .end = AT91SAM9261_BASE_US0 + SZ_16K - 1,
  776. .flags = IORESOURCE_MEM,
  777. },
  778. [1] = {
  779. .start = NR_IRQS_LEGACY + AT91SAM9261_ID_US0,
  780. .end = NR_IRQS_LEGACY + AT91SAM9261_ID_US0,
  781. .flags = IORESOURCE_IRQ,
  782. },
  783. };
  784. static struct atmel_uart_data uart0_data = {
  785. .use_dma_tx = 1,
  786. .use_dma_rx = 1,
  787. };
  788. static u64 uart0_dmamask = DMA_BIT_MASK(32);
  789. static struct platform_device at91sam9261_uart0_device = {
  790. .name = "atmel_usart",
  791. .id = 1,
  792. .dev = {
  793. .dma_mask = &uart0_dmamask,
  794. .coherent_dma_mask = DMA_BIT_MASK(32),
  795. .platform_data = &uart0_data,
  796. },
  797. .resource = uart0_resources,
  798. .num_resources = ARRAY_SIZE(uart0_resources),
  799. };
  800. static inline void configure_usart0_pins(unsigned pins)
  801. {
  802. at91_set_A_periph(AT91_PIN_PC8, 1); /* TXD0 */
  803. at91_set_A_periph(AT91_PIN_PC9, 0); /* RXD0 */
  804. if (pins & ATMEL_UART_RTS)
  805. at91_set_A_periph(AT91_PIN_PC10, 0); /* RTS0 */
  806. if (pins & ATMEL_UART_CTS)
  807. at91_set_A_periph(AT91_PIN_PC11, 0); /* CTS0 */
  808. }
  809. static struct resource uart1_resources[] = {
  810. [0] = {
  811. .start = AT91SAM9261_BASE_US1,
  812. .end = AT91SAM9261_BASE_US1 + SZ_16K - 1,
  813. .flags = IORESOURCE_MEM,
  814. },
  815. [1] = {
  816. .start = NR_IRQS_LEGACY + AT91SAM9261_ID_US1,
  817. .end = NR_IRQS_LEGACY + AT91SAM9261_ID_US1,
  818. .flags = IORESOURCE_IRQ,
  819. },
  820. };
  821. static struct atmel_uart_data uart1_data = {
  822. .use_dma_tx = 1,
  823. .use_dma_rx = 1,
  824. };
  825. static u64 uart1_dmamask = DMA_BIT_MASK(32);
  826. static struct platform_device at91sam9261_uart1_device = {
  827. .name = "atmel_usart",
  828. .id = 2,
  829. .dev = {
  830. .dma_mask = &uart1_dmamask,
  831. .coherent_dma_mask = DMA_BIT_MASK(32),
  832. .platform_data = &uart1_data,
  833. },
  834. .resource = uart1_resources,
  835. .num_resources = ARRAY_SIZE(uart1_resources),
  836. };
  837. static inline void configure_usart1_pins(unsigned pins)
  838. {
  839. at91_set_A_periph(AT91_PIN_PC12, 1); /* TXD1 */
  840. at91_set_A_periph(AT91_PIN_PC13, 0); /* RXD1 */
  841. if (pins & ATMEL_UART_RTS)
  842. at91_set_B_periph(AT91_PIN_PA12, 0); /* RTS1 */
  843. if (pins & ATMEL_UART_CTS)
  844. at91_set_B_periph(AT91_PIN_PA13, 0); /* CTS1 */
  845. }
  846. static struct resource uart2_resources[] = {
  847. [0] = {
  848. .start = AT91SAM9261_BASE_US2,
  849. .end = AT91SAM9261_BASE_US2 + SZ_16K - 1,
  850. .flags = IORESOURCE_MEM,
  851. },
  852. [1] = {
  853. .start = NR_IRQS_LEGACY + AT91SAM9261_ID_US2,
  854. .end = NR_IRQS_LEGACY + AT91SAM9261_ID_US2,
  855. .flags = IORESOURCE_IRQ,
  856. },
  857. };
  858. static struct atmel_uart_data uart2_data = {
  859. .use_dma_tx = 1,
  860. .use_dma_rx = 1,
  861. };
  862. static u64 uart2_dmamask = DMA_BIT_MASK(32);
  863. static struct platform_device at91sam9261_uart2_device = {
  864. .name = "atmel_usart",
  865. .id = 3,
  866. .dev = {
  867. .dma_mask = &uart2_dmamask,
  868. .coherent_dma_mask = DMA_BIT_MASK(32),
  869. .platform_data = &uart2_data,
  870. },
  871. .resource = uart2_resources,
  872. .num_resources = ARRAY_SIZE(uart2_resources),
  873. };
  874. static inline void configure_usart2_pins(unsigned pins)
  875. {
  876. at91_set_A_periph(AT91_PIN_PC15, 0); /* RXD2 */
  877. at91_set_A_periph(AT91_PIN_PC14, 1); /* TXD2 */
  878. if (pins & ATMEL_UART_RTS)
  879. at91_set_B_periph(AT91_PIN_PA15, 0); /* RTS2*/
  880. if (pins & ATMEL_UART_CTS)
  881. at91_set_B_periph(AT91_PIN_PA16, 0); /* CTS2 */
  882. }
  883. static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
  884. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
  885. {
  886. struct platform_device *pdev;
  887. struct atmel_uart_data *pdata;
  888. switch (id) {
  889. case 0: /* DBGU */
  890. pdev = &at91sam9261_dbgu_device;
  891. configure_dbgu_pins();
  892. break;
  893. case AT91SAM9261_ID_US0:
  894. pdev = &at91sam9261_uart0_device;
  895. configure_usart0_pins(pins);
  896. break;
  897. case AT91SAM9261_ID_US1:
  898. pdev = &at91sam9261_uart1_device;
  899. configure_usart1_pins(pins);
  900. break;
  901. case AT91SAM9261_ID_US2:
  902. pdev = &at91sam9261_uart2_device;
  903. configure_usart2_pins(pins);
  904. break;
  905. default:
  906. return;
  907. }
  908. pdata = pdev->dev.platform_data;
  909. pdata->num = portnr; /* update to mapped ID */
  910. if (portnr < ATMEL_MAX_UART)
  911. at91_uarts[portnr] = pdev;
  912. }
  913. void __init at91_add_device_serial(void)
  914. {
  915. int i;
  916. for (i = 0; i < ATMEL_MAX_UART; i++) {
  917. if (at91_uarts[i])
  918. platform_device_register(at91_uarts[i]);
  919. }
  920. }
  921. #else
  922. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
  923. void __init at91_add_device_serial(void) {}
  924. #endif
  925. /* -------------------------------------------------------------------- */
  926. /*
  927. * These devices are always present and don't need any board-specific
  928. * setup.
  929. */
  930. static int __init at91_add_standard_devices(void)
  931. {
  932. at91_add_device_rtt();
  933. at91_add_device_watchdog();
  934. at91_add_device_tc();
  935. return 0;
  936. }
  937. arch_initcall(at91_add_standard_devices);