at91sam9261_devices.c 28 KB

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