basicAlgorithmEncapsulation.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829
  1. /*
  2. * arch/arm/mach-at91/at91sam9260_devices.c
  3. *
  4. * Copyright (C) 2006 Atmel
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. */
  12. #include <asm/mach/arch.h>
  13. #include <asm/mach/map.h>
  14. #include <linux/dma-mapping.h>
  15. #include <linux/gpio.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/i2c-gpio.h>
  18. #include <linux/platform_data/at91_adc.h>
  19. #include <mach/cpu.h>
  20. #include <mach/at91sam9260.h>
  21. #include <mach/at91sam9260_matrix.h>
  22. #include <mach/at91_matrix.h>
  23. #include <mach/at91sam9_smc.h>
  24. #include <mach/at91_adc.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 = AT91SAM9260_UHP_BASE,
  36. .end = AT91SAM9260_UHP_BASE + SZ_1M - 1,
  37. .flags = IORESOURCE_MEM,
  38. },
  39. [1] = {
  40. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_UHP,
  41. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_UHP,
  42. .flags = IORESOURCE_IRQ,
  43. },
  44. };
  45. static struct platform_device at91_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(&at91_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 = AT91SAM9260_BASE_UDP,
  80. .end = AT91SAM9260_BASE_UDP + SZ_16K - 1,
  81. .flags = IORESOURCE_MEM,
  82. },
  83. [1] = {
  84. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_UDP,
  85. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_UDP,
  86. .flags = IORESOURCE_IRQ,
  87. },
  88. };
  89. static struct platform_device at91_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(&at91_udc_device);
  109. }
  110. #else
  111. void __init at91_add_device_udc(struct at91_udc_data *data) {}
  112. #endif
  113. /* --------------------------------------------------------------------
  114. * Ethernet
  115. * -------------------------------------------------------------------- */
  116. #if defined(CONFIG_MACB) || defined(CONFIG_MACB_MODULE)
  117. static u64 eth_dmamask = DMA_BIT_MASK(32);
  118. static struct macb_platform_data eth_data;
  119. static struct resource eth_resources[] = {
  120. [0] = {
  121. .start = AT91SAM9260_BASE_EMAC,
  122. .end = AT91SAM9260_BASE_EMAC + SZ_16K - 1,
  123. .flags = IORESOURCE_MEM,
  124. },
  125. [1] = {
  126. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_EMAC,
  127. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_EMAC,
  128. .flags = IORESOURCE_IRQ,
  129. },
  130. };
  131. static struct platform_device at91sam9260_eth_device = {
  132. .name = "macb",
  133. .id = -1,
  134. .dev = {
  135. .dma_mask = &eth_dmamask,
  136. .coherent_dma_mask = DMA_BIT_MASK(32),
  137. .platform_data = &eth_data,
  138. },
  139. .resource = eth_resources,
  140. .num_resources = ARRAY_SIZE(eth_resources),
  141. };
  142. void __init at91_add_device_eth(struct macb_platform_data *data)
  143. {
  144. if (!data)
  145. return;
  146. if (gpio_is_valid(data->phy_irq_pin)) {
  147. at91_set_gpio_input(data->phy_irq_pin, 0);
  148. at91_set_deglitch(data->phy_irq_pin, 1);
  149. }
  150. /* Pins used for MII and RMII */
  151. at91_set_A_periph(AT91_PIN_PA19, 0); /* ETXCK_EREFCK */
  152. at91_set_A_periph(AT91_PIN_PA17, 0); /* ERXDV */
  153. at91_set_A_periph(AT91_PIN_PA14, 0); /* ERX0 */
  154. at91_set_A_periph(AT91_PIN_PA15, 0); /* ERX1 */
  155. at91_set_A_periph(AT91_PIN_PA18, 0); /* ERXER */
  156. at91_set_A_periph(AT91_PIN_PA16, 0); /* ETXEN */
  157. at91_set_A_periph(AT91_PIN_PA12, 0); /* ETX0 */
  158. at91_set_A_periph(AT91_PIN_PA13, 0); /* ETX1 */
  159. at91_set_A_periph(AT91_PIN_PA21, 0); /* EMDIO */
  160. at91_set_A_periph(AT91_PIN_PA20, 0); /* EMDC */
  161. if (!data->is_rmii) {
  162. at91_set_B_periph(AT91_PIN_PA28, 0); /* ECRS */
  163. at91_set_B_periph(AT91_PIN_PA29, 0); /* ECOL */
  164. at91_set_B_periph(AT91_PIN_PA25, 0); /* ERX2 */
  165. at91_set_B_periph(AT91_PIN_PA26, 0); /* ERX3 */
  166. at91_set_B_periph(AT91_PIN_PA27, 0); /* ERXCK */
  167. at91_set_B_periph(AT91_PIN_PA23, 0); /* ETX2 */
  168. at91_set_B_periph(AT91_PIN_PA24, 0); /* ETX3 */
  169. at91_set_B_periph(AT91_PIN_PA22, 0); /* ETXER */
  170. }
  171. eth_data = *data;
  172. platform_device_register(&at91sam9260_eth_device);
  173. }
  174. #else
  175. void __init at91_add_device_eth(struct macb_platform_data *data) {}
  176. #endif
  177. /* --------------------------------------------------------------------
  178. * MMC / SD Slot for Atmel MCI Driver
  179. * -------------------------------------------------------------------- */
  180. #if IS_ENABLED(CONFIG_MMC_ATMELMCI)
  181. static u64 mmc_dmamask = DMA_BIT_MASK(32);
  182. static struct mci_platform_data mmc_data;
  183. static struct resource mmc_resources[] = {
  184. [0] = {
  185. .start = AT91SAM9260_BASE_MCI,
  186. .end = AT91SAM9260_BASE_MCI + SZ_16K - 1,
  187. .flags = IORESOURCE_MEM,
  188. },
  189. [1] = {
  190. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_MCI,
  191. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_MCI,
  192. .flags = IORESOURCE_IRQ,
  193. },
  194. };
  195. static struct platform_device at91sam9260_mmc_device = {
  196. .name = "atmel_mci",
  197. .id = -1,
  198. .dev = {
  199. .dma_mask = &mmc_dmamask,
  200. .coherent_dma_mask = DMA_BIT_MASK(32),
  201. .platform_data = &mmc_data,
  202. },
  203. .resource = mmc_resources,
  204. .num_resources = ARRAY_SIZE(mmc_resources),
  205. };
  206. void __init at91_add_device_mci(short mmc_id, struct mci_platform_data *data)
  207. {
  208. unsigned int i;
  209. unsigned int slot_count = 0;
  210. if (!data)
  211. return;
  212. for (i = 0; i < ATMCI_MAX_NR_SLOTS; i++) {
  213. if (data->slot[i].bus_width) {
  214. /* input/irq */
  215. if (gpio_is_valid(data->slot[i].detect_pin)) {
  216. at91_set_gpio_input(data->slot[i].detect_pin, 1);
  217. at91_set_deglitch(data->slot[i].detect_pin, 1);
  218. }
  219. if (gpio_is_valid(data->slot[i].wp_pin))
  220. at91_set_gpio_input(data->slot[i].wp_pin, 1);
  221. switch (i) {
  222. case 0:
  223. /* CMD */
  224. at91_set_A_periph(AT91_PIN_PA7, 1);
  225. /* DAT0, maybe DAT1..DAT3 */
  226. at91_set_A_periph(AT91_PIN_PA6, 1);
  227. if (data->slot[i].bus_width == 4) {
  228. at91_set_A_periph(AT91_PIN_PA9, 1);
  229. at91_set_A_periph(AT91_PIN_PA10, 1);
  230. at91_set_A_periph(AT91_PIN_PA11, 1);
  231. }
  232. slot_count++;
  233. break;
  234. case 1:
  235. /* CMD */
  236. at91_set_B_periph(AT91_PIN_PA1, 1);
  237. /* DAT0, maybe DAT1..DAT3 */
  238. at91_set_B_periph(AT91_PIN_PA0, 1);
  239. if (data->slot[i].bus_width == 4) {
  240. at91_set_B_periph(AT91_PIN_PA5, 1);
  241. at91_set_B_periph(AT91_PIN_PA4, 1);
  242. at91_set_B_periph(AT91_PIN_PA3, 1);
  243. }
  244. slot_count++;
  245. break;
  246. default:
  247. printk(KERN_ERR
  248. "AT91: SD/MMC slot %d not available\n", i);
  249. break;
  250. }
  251. }
  252. }
  253. if (slot_count) {
  254. /* CLK */
  255. at91_set_A_periph(AT91_PIN_PA8, 0);
  256. mmc_data = *data;
  257. platform_device_register(&at91sam9260_mmc_device);
  258. }
  259. }
  260. #else
  261. void __init at91_add_device_mci(short mmc_id, struct mci_platform_data *data) {}
  262. #endif
  263. /* --------------------------------------------------------------------
  264. * NAND / SmartMedia
  265. * -------------------------------------------------------------------- */
  266. #if defined(CONFIG_MTD_NAND_ATMEL) || defined(CONFIG_MTD_NAND_ATMEL_MODULE)
  267. static struct atmel_nand_data nand_data;
  268. #define NAND_BASE AT91_CHIPSELECT_3
  269. static struct resource nand_resources[] = {
  270. [0] = {
  271. .start = NAND_BASE,
  272. .end = NAND_BASE + SZ_256M - 1,
  273. .flags = IORESOURCE_MEM,
  274. },
  275. [1] = {
  276. .start = AT91SAM9260_BASE_ECC,
  277. .end = AT91SAM9260_BASE_ECC + SZ_512 - 1,
  278. .flags = IORESOURCE_MEM,
  279. }
  280. };
  281. static struct platform_device at91sam9260_nand_device = {
  282. .name = "atmel_nand",
  283. .id = -1,
  284. .dev = {
  285. .platform_data = &nand_data,
  286. },
  287. .resource = nand_resources,
  288. .num_resources = ARRAY_SIZE(nand_resources),
  289. };
  290. void __init at91_add_device_nand(struct atmel_nand_data *data)
  291. {
  292. unsigned long csa;
  293. if (!data)
  294. return;
  295. csa = at91_matrix_read(AT91_MATRIX_EBICSA);
  296. at91_matrix_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_CS3A_SMC_SMARTMEDIA);
  297. /* enable pin */
  298. if (gpio_is_valid(data->enable_pin))
  299. at91_set_gpio_output(data->enable_pin, 1);
  300. /* ready/busy pin */
  301. if (gpio_is_valid(data->rdy_pin))
  302. at91_set_gpio_input(data->rdy_pin, 1);
  303. /* card detect pin */
  304. if (gpio_is_valid(data->det_pin))
  305. at91_set_gpio_input(data->det_pin, 1);
  306. nand_data = *data;
  307. platform_device_register(&at91sam9260_nand_device);
  308. }
  309. #else
  310. void __init at91_add_device_nand(struct atmel_nand_data *data) {}
  311. #endif
  312. /* --------------------------------------------------------------------
  313. * TWI (i2c)
  314. * -------------------------------------------------------------------- */
  315. /*
  316. * Prefer the GPIO code since the TWI controller isn't robust
  317. * (gets overruns and underruns under load) and can only issue
  318. * repeated STARTs in one scenario (the driver doesn't yet handle them).
  319. */
  320. #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
  321. static struct i2c_gpio_platform_data pdata = {
  322. .sda_pin = AT91_PIN_PA23,
  323. .sda_is_open_drain = 1,
  324. .scl_pin = AT91_PIN_PA24,
  325. .scl_is_open_drain = 1,
  326. .udelay = 2, /* ~100 kHz */
  327. };
  328. static struct platform_device at91sam9260_twi_device = {
  329. .name = "i2c-gpio",
  330. .id = 0,
  331. .dev.platform_data = &pdata,
  332. };
  333. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  334. {
  335. at91_set_GPIO_periph(AT91_PIN_PA23, 1); /* TWD (SDA) */
  336. at91_set_multi_drive(AT91_PIN_PA23, 1);
  337. at91_set_GPIO_periph(AT91_PIN_PA24, 1); /* TWCK (SCL) */
  338. at91_set_multi_drive(AT91_PIN_PA24, 1);
  339. i2c_register_board_info(0, devices, nr_devices);
  340. platform_device_register(&at91sam9260_twi_device);
  341. }
  342. #elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
  343. static struct resource twi_resources[] = {
  344. [0] = {
  345. .start = AT91SAM9260_BASE_TWI,
  346. .end = AT91SAM9260_BASE_TWI + SZ_16K - 1,
  347. .flags = IORESOURCE_MEM,
  348. },
  349. [1] = {
  350. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_TWI,
  351. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_TWI,
  352. .flags = IORESOURCE_IRQ,
  353. },
  354. };
  355. static struct platform_device at91sam9260_twi_device = {
  356. .id = 0,
  357. .resource = twi_resources,
  358. .num_resources = ARRAY_SIZE(twi_resources),
  359. };
  360. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  361. {
  362. /* IP version is not the same on 9260 and g20 */
  363. if (cpu_is_at91sam9g20()) {
  364. at91sam9260_twi_device.name = "i2c-at91sam9g20";
  365. } else {
  366. at91sam9260_twi_device.name = "i2c-at91sam9260";
  367. }
  368. /* pins used for TWI interface */
  369. at91_set_A_periph(AT91_PIN_PA23, 0); /* TWD */
  370. at91_set_multi_drive(AT91_PIN_PA23, 1);
  371. at91_set_A_periph(AT91_PIN_PA24, 0); /* TWCK */
  372. at91_set_multi_drive(AT91_PIN_PA24, 1);
  373. i2c_register_board_info(0, devices, nr_devices);
  374. platform_device_register(&at91sam9260_twi_device);
  375. }
  376. #else
  377. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {}
  378. #endif
  379. /* --------------------------------------------------------------------
  380. * SPI
  381. * -------------------------------------------------------------------- */
  382. #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
  383. static u64 spi_dmamask = DMA_BIT_MASK(32);
  384. static struct resource spi0_resources[] = {
  385. [0] = {
  386. .start = AT91SAM9260_BASE_SPI0,
  387. .end = AT91SAM9260_BASE_SPI0 + SZ_16K - 1,
  388. .flags = IORESOURCE_MEM,
  389. },
  390. [1] = {
  391. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_SPI0,
  392. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_SPI0,
  393. .flags = IORESOURCE_IRQ,
  394. },
  395. };
  396. static struct platform_device at91sam9260_spi0_device = {
  397. .name = "atmel_spi",
  398. .id = 0,
  399. .dev = {
  400. .dma_mask = &spi_dmamask,
  401. .coherent_dma_mask = DMA_BIT_MASK(32),
  402. },
  403. .resource = spi0_resources,
  404. .num_resources = ARRAY_SIZE(spi0_resources),
  405. };
  406. static const unsigned spi0_standard_cs[4] = { AT91_PIN_PA3, AT91_PIN_PC11, AT91_PIN_PC16, AT91_PIN_PC17 };
  407. static struct resource spi1_resources[] = {
  408. [0] = {
  409. .start = AT91SAM9260_BASE_SPI1,
  410. .end = AT91SAM9260_BASE_SPI1 + SZ_16K - 1,
  411. .flags = IORESOURCE_MEM,
  412. },
  413. [1] = {
  414. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_SPI1,
  415. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_SPI1,
  416. .flags = IORESOURCE_IRQ,
  417. },
  418. };
  419. static struct platform_device at91sam9260_spi1_device = {
  420. .name = "atmel_spi",
  421. .id = 1,
  422. .dev = {
  423. .dma_mask = &spi_dmamask,
  424. .coherent_dma_mask = DMA_BIT_MASK(32),
  425. },
  426. .resource = spi1_resources,
  427. .num_resources = ARRAY_SIZE(spi1_resources),
  428. };
  429. static const unsigned spi1_standard_cs[4] = { AT91_PIN_PB3, AT91_PIN_PC5, AT91_PIN_PC4, AT91_PIN_PC3 };
  430. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
  431. {
  432. int i;
  433. unsigned long cs_pin;
  434. short enable_spi0 = 0;
  435. short enable_spi1 = 0;
  436. /* Choose SPI chip-selects */
  437. for (i = 0; i < nr_devices; i++) {
  438. if (devices[i].controller_data)
  439. cs_pin = (unsigned long) devices[i].controller_data;
  440. else if (devices[i].bus_num == 0)
  441. cs_pin = spi0_standard_cs[devices[i].chip_select];
  442. else
  443. cs_pin = spi1_standard_cs[devices[i].chip_select];
  444. if (!gpio_is_valid(cs_pin))
  445. continue;
  446. if (devices[i].bus_num == 0)
  447. enable_spi0 = 1;
  448. else
  449. enable_spi1 = 1;
  450. /* enable chip-select pin */
  451. at91_set_gpio_output(cs_pin, 1);
  452. /* pass chip-select pin to driver */
  453. devices[i].controller_data = (void *) cs_pin;
  454. }
  455. spi_register_board_info(devices, nr_devices);
  456. /* Configure SPI bus(es) */
  457. if (enable_spi0) {
  458. at91_set_A_periph(AT91_PIN_PA0, 0); /* SPI0_MISO */
  459. at91_set_A_periph(AT91_PIN_PA1, 0); /* SPI0_MOSI */
  460. at91_set_A_periph(AT91_PIN_PA2, 0); /* SPI1_SPCK */
  461. platform_device_register(&at91sam9260_spi0_device);
  462. }
  463. if (enable_spi1) {
  464. at91_set_A_periph(AT91_PIN_PB0, 0); /* SPI1_MISO */
  465. at91_set_A_periph(AT91_PIN_PB1, 0); /* SPI1_MOSI */
  466. at91_set_A_periph(AT91_PIN_PB2, 0); /* SPI1_SPCK */
  467. platform_device_register(&at91sam9260_spi1_device);
  468. }
  469. }
  470. #else
  471. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
  472. #endif
  473. /* --------------------------------------------------------------------
  474. * Timer/Counter blocks
  475. * -------------------------------------------------------------------- */
  476. #ifdef CONFIG_ATMEL_TCLIB
  477. static struct resource tcb0_resources[] = {
  478. [0] = {
  479. .start = AT91SAM9260_BASE_TCB0,
  480. .end = AT91SAM9260_BASE_TCB0 + SZ_256 - 1,
  481. .flags = IORESOURCE_MEM,
  482. },
  483. [1] = {
  484. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_TC0,
  485. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_TC0,
  486. .flags = IORESOURCE_IRQ,
  487. },
  488. [2] = {
  489. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_TC1,
  490. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_TC1,
  491. .flags = IORESOURCE_IRQ,
  492. },
  493. [3] = {
  494. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_TC2,
  495. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_TC2,
  496. .flags = IORESOURCE_IRQ,
  497. },
  498. };
  499. static struct platform_device at91sam9260_tcb0_device = {
  500. .name = "atmel_tcb",
  501. .id = 0,
  502. .resource = tcb0_resources,
  503. .num_resources = ARRAY_SIZE(tcb0_resources),
  504. };
  505. static struct resource tcb1_resources[] = {
  506. [0] = {
  507. .start = AT91SAM9260_BASE_TCB1,
  508. .end = AT91SAM9260_BASE_TCB1 + SZ_256 - 1,
  509. .flags = IORESOURCE_MEM,
  510. },
  511. [1] = {
  512. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_TC3,
  513. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_TC3,
  514. .flags = IORESOURCE_IRQ,
  515. },
  516. [2] = {
  517. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_TC4,
  518. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_TC4,
  519. .flags = IORESOURCE_IRQ,
  520. },
  521. [3] = {
  522. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_TC5,
  523. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_TC5,
  524. .flags = IORESOURCE_IRQ,
  525. },
  526. };
  527. static struct platform_device at91sam9260_tcb1_device = {
  528. .name = "atmel_tcb",
  529. .id = 1,
  530. .resource = tcb1_resources,
  531. .num_resources = ARRAY_SIZE(tcb1_resources),
  532. };
  533. static void __init at91_add_device_tc(void)
  534. {
  535. platform_device_register(&at91sam9260_tcb0_device);
  536. platform_device_register(&at91sam9260_tcb1_device);
  537. }
  538. #else
  539. static void __init at91_add_device_tc(void) { }
  540. #endif
  541. /* --------------------------------------------------------------------
  542. * RTT
  543. * -------------------------------------------------------------------- */
  544. static struct resource rtt_resources[] = {
  545. {
  546. .start = AT91SAM9260_BASE_RTT,
  547. .end = AT91SAM9260_BASE_RTT + SZ_16 - 1,
  548. .flags = IORESOURCE_MEM,
  549. }, {
  550. .flags = IORESOURCE_MEM,
  551. }, {
  552. .flags = IORESOURCE_IRQ,
  553. },
  554. };
  555. static struct platform_device at91sam9260_rtt_device = {
  556. .name = "at91_rtt",
  557. .id = 0,
  558. .resource = rtt_resources,
  559. };
  560. #if IS_ENABLED(CONFIG_RTC_DRV_AT91SAM9)
  561. static void __init at91_add_device_rtt_rtc(void)
  562. {
  563. at91sam9260_rtt_device.name = "rtc-at91sam9";
  564. /*
  565. * The second resource is needed:
  566. * GPBR will serve as the storage for RTC time offset
  567. */
  568. at91sam9260_rtt_device.num_resources = 3;
  569. rtt_resources[1].start = AT91SAM9260_BASE_GPBR +
  570. 4 * CONFIG_RTC_DRV_AT91SAM9_GPBR;
  571. rtt_resources[1].end = rtt_resources[1].start + 3;
  572. rtt_resources[2].start = NR_IRQS_LEGACY + AT91_ID_SYS;
  573. rtt_resources[2].end = NR_IRQS_LEGACY + AT91_ID_SYS;
  574. }
  575. #else
  576. static void __init at91_add_device_rtt_rtc(void)
  577. {
  578. /* Only one resource is needed: RTT not used as RTC */
  579. at91sam9260_rtt_device.num_resources = 1;
  580. }
  581. #endif
  582. static void __init at91_add_device_rtt(void)
  583. {
  584. at91_add_device_rtt_rtc();
  585. platform_device_register(&at91sam9260_rtt_device);
  586. }
  587. /* --------------------------------------------------------------------
  588. * Watchdog
  589. * -------------------------------------------------------------------- */
  590. #if defined(CONFIG_AT91SAM9X_WATCHDOG) || defined(CONFIG_AT91SAM9X_WATCHDOG_MODULE)
  591. static struct resource wdt_resources[] = {
  592. {
  593. .start = AT91SAM9260_BASE_WDT,
  594. .end = AT91SAM9260_BASE_WDT + SZ_16 - 1,
  595. .flags = IORESOURCE_MEM,
  596. }
  597. };
  598. static struct platform_device at91sam9260_wdt_device = {
  599. .name = "at91_wdt",
  600. .id = -1,
  601. .resource = wdt_resources,
  602. .num_resources = ARRAY_SIZE(wdt_resources),
  603. };
  604. static void __init at91_add_device_watchdog(void)
  605. {
  606. platform_device_register(&at91sam9260_wdt_device);
  607. }
  608. #else
  609. static void __init at91_add_device_watchdog(void) {}
  610. #endif
  611. /* --------------------------------------------------------------------
  612. * SSC -- Synchronous Serial Controller
  613. * -------------------------------------------------------------------- */
  614. #if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
  615. static u64 ssc_dmamask = DMA_BIT_MASK(32);
  616. static struct resource ssc_resources[] = {
  617. [0] = {
  618. .start = AT91SAM9260_BASE_SSC,
  619. .end = AT91SAM9260_BASE_SSC + SZ_16K - 1,
  620. .flags = IORESOURCE_MEM,
  621. },
  622. [1] = {
  623. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_SSC,
  624. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_SSC,
  625. .flags = IORESOURCE_IRQ,
  626. },
  627. };
  628. static struct platform_device at91sam9260_ssc_device = {
  629. .name = "at91rm9200_ssc",
  630. .id = 0,
  631. .dev = {
  632. .dma_mask = &ssc_dmamask,
  633. .coherent_dma_mask = DMA_BIT_MASK(32),
  634. },
  635. .resource = ssc_resources,
  636. .num_resources = ARRAY_SIZE(ssc_resources),
  637. };
  638. static inline void configure_ssc_pins(unsigned pins)
  639. {
  640. if (pins & ATMEL_SSC_TF)
  641. at91_set_A_periph(AT91_PIN_PB17, 1);
  642. if (pins & ATMEL_SSC_TK)
  643. at91_set_A_periph(AT91_PIN_PB16, 1);
  644. if (pins & ATMEL_SSC_TD)
  645. at91_set_A_periph(AT91_PIN_PB18, 1);
  646. if (pins & ATMEL_SSC_RD)
  647. at91_set_A_periph(AT91_PIN_PB19, 1);
  648. if (pins & ATMEL_SSC_RK)
  649. at91_set_A_periph(AT91_PIN_PB20, 1);
  650. if (pins & ATMEL_SSC_RF)
  651. at91_set_A_periph(AT91_PIN_PB21, 1);
  652. }
  653. /*
  654. * SSC controllers are accessed through library code, instead of any
  655. * kind of all-singing/all-dancing driver. For example one could be
  656. * used by a particular I2S audio codec's driver, while another one
  657. * on the same system might be used by a custom data capture driver.
  658. */
  659. void __init at91_add_device_ssc(unsigned id, unsigned pins)
  660. {
  661. struct platform_device *pdev;
  662. /*
  663. * NOTE: caller is responsible for passing information matching
  664. * "pins" to whatever will be using each particular controller.
  665. */
  666. switch (id) {
  667. case AT91SAM9260_ID_SSC:
  668. pdev = &at91sam9260_ssc_device;
  669. configure_ssc_pins(pins);
  670. break;
  671. default:
  672. return;
  673. }
  674. platform_device_register(pdev);
  675. }
  676. #else
  677. void __init at91_add_device_ssc(unsigned id, unsigned pins) {}
  678. #endif
  679. /* --------------------------------------------------------------------
  680. * UART
  681. * -------------------------------------------------------------------- */
  682. #if defined(CONFIG_SERIAL_ATMEL)
  683. static struct resource dbgu_resources[] = {
  684. [0] = {
  685. .start = AT91SAM9260_BASE_DBGU,
  686. .end = AT91SAM9260_BASE_DBGU + SZ_512 - 1,
  687. .flags = IORESOURCE_MEM,
  688. },
  689. [1] = {
  690. .start = NR_IRQS_LEGACY + AT91_ID_SYS,
  691. .end = NR_IRQS_LEGACY + AT91_ID_SYS,
  692. .flags = IORESOURCE_IRQ,
  693. },
  694. };
  695. static struct atmel_uart_data dbgu_data = {
  696. .use_dma_tx = 0,
  697. .use_dma_rx = 0, /* DBGU not capable of receive DMA */
  698. };
  699. static u64 dbgu_dmamask = DMA_BIT_MASK(32);
  700. static struct platform_device at91sam9260_dbgu_device = {
  701. .name = "atmel_usart",
  702. .id = 0,
  703. .dev = {