at91sam9260_devices.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359
  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 <mach/board.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 "generic.h"
  25. /* --------------------------------------------------------------------
  26. * USB Host
  27. * -------------------------------------------------------------------- */
  28. #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
  29. static u64 ohci_dmamask = DMA_BIT_MASK(32);
  30. static struct at91_usbh_data usbh_data;
  31. static struct resource usbh_resources[] = {
  32. [0] = {
  33. .start = AT91SAM9260_UHP_BASE,
  34. .end = AT91SAM9260_UHP_BASE + SZ_1M - 1,
  35. .flags = IORESOURCE_MEM,
  36. },
  37. [1] = {
  38. .start = AT91SAM9260_ID_UHP,
  39. .end = AT91SAM9260_ID_UHP,
  40. .flags = IORESOURCE_IRQ,
  41. },
  42. };
  43. static struct platform_device at91_usbh_device = {
  44. .name = "at91_ohci",
  45. .id = -1,
  46. .dev = {
  47. .dma_mask = &ohci_dmamask,
  48. .coherent_dma_mask = DMA_BIT_MASK(32),
  49. .platform_data = &usbh_data,
  50. },
  51. .resource = usbh_resources,
  52. .num_resources = ARRAY_SIZE(usbh_resources),
  53. };
  54. void __init at91_add_device_usbh(struct at91_usbh_data *data)
  55. {
  56. int i;
  57. if (!data)
  58. return;
  59. /* Enable overcurrent notification */
  60. for (i = 0; i < data->ports; i++) {
  61. if (data->overcurrent_pin[i])
  62. at91_set_gpio_input(data->overcurrent_pin[i], 1);
  63. }
  64. usbh_data = *data;
  65. platform_device_register(&at91_usbh_device);
  66. }
  67. #else
  68. void __init at91_add_device_usbh(struct at91_usbh_data *data) {}
  69. #endif
  70. /* --------------------------------------------------------------------
  71. * USB Device (Gadget)
  72. * -------------------------------------------------------------------- */
  73. #if defined(CONFIG_USB_AT91) || defined(CONFIG_USB_AT91_MODULE)
  74. static struct at91_udc_data udc_data;
  75. static struct resource udc_resources[] = {
  76. [0] = {
  77. .start = AT91SAM9260_BASE_UDP,
  78. .end = AT91SAM9260_BASE_UDP + SZ_16K - 1,
  79. .flags = IORESOURCE_MEM,
  80. },
  81. [1] = {
  82. .start = AT91SAM9260_ID_UDP,
  83. .end = AT91SAM9260_ID_UDP,
  84. .flags = IORESOURCE_IRQ,
  85. },
  86. };
  87. static struct platform_device at91_udc_device = {
  88. .name = "at91_udc",
  89. .id = -1,
  90. .dev = {
  91. .platform_data = &udc_data,
  92. },
  93. .resource = udc_resources,
  94. .num_resources = ARRAY_SIZE(udc_resources),
  95. };
  96. void __init at91_add_device_udc(struct at91_udc_data *data)
  97. {
  98. if (!data)
  99. return;
  100. if (gpio_is_valid(data->vbus_pin)) {
  101. at91_set_gpio_input(data->vbus_pin, 0);
  102. at91_set_deglitch(data->vbus_pin, 1);
  103. }
  104. /* Pullup pin is handled internally by USB device peripheral */
  105. udc_data = *data;
  106. platform_device_register(&at91_udc_device);
  107. }
  108. #else
  109. void __init at91_add_device_udc(struct at91_udc_data *data) {}
  110. #endif
  111. /* --------------------------------------------------------------------
  112. * Ethernet
  113. * -------------------------------------------------------------------- */
  114. #if defined(CONFIG_MACB) || defined(CONFIG_MACB_MODULE)
  115. static u64 eth_dmamask = DMA_BIT_MASK(32);
  116. static struct macb_platform_data eth_data;
  117. static struct resource eth_resources[] = {
  118. [0] = {
  119. .start = AT91SAM9260_BASE_EMAC,
  120. .end = AT91SAM9260_BASE_EMAC + SZ_16K - 1,
  121. .flags = IORESOURCE_MEM,
  122. },
  123. [1] = {
  124. .start = AT91SAM9260_ID_EMAC,
  125. .end = AT91SAM9260_ID_EMAC,
  126. .flags = IORESOURCE_IRQ,
  127. },
  128. };
  129. static struct platform_device at91sam9260_eth_device = {
  130. .name = "macb",
  131. .id = -1,
  132. .dev = {
  133. .dma_mask = &eth_dmamask,
  134. .coherent_dma_mask = DMA_BIT_MASK(32),
  135. .platform_data = &eth_data,
  136. },
  137. .resource = eth_resources,
  138. .num_resources = ARRAY_SIZE(eth_resources),
  139. };
  140. void __init at91_add_device_eth(struct macb_platform_data *data)
  141. {
  142. if (!data)
  143. return;
  144. if (gpio_is_valid(data->phy_irq_pin)) {
  145. at91_set_gpio_input(data->phy_irq_pin, 0);
  146. at91_set_deglitch(data->phy_irq_pin, 1);
  147. }
  148. /* Pins used for MII and RMII */
  149. at91_set_A_periph(AT91_PIN_PA19, 0); /* ETXCK_EREFCK */
  150. at91_set_A_periph(AT91_PIN_PA17, 0); /* ERXDV */
  151. at91_set_A_periph(AT91_PIN_PA14, 0); /* ERX0 */
  152. at91_set_A_periph(AT91_PIN_PA15, 0); /* ERX1 */
  153. at91_set_A_periph(AT91_PIN_PA18, 0); /* ERXER */
  154. at91_set_A_periph(AT91_PIN_PA16, 0); /* ETXEN */
  155. at91_set_A_periph(AT91_PIN_PA12, 0); /* ETX0 */
  156. at91_set_A_periph(AT91_PIN_PA13, 0); /* ETX1 */
  157. at91_set_A_periph(AT91_PIN_PA21, 0); /* EMDIO */
  158. at91_set_A_periph(AT91_PIN_PA20, 0); /* EMDC */
  159. if (!data->is_rmii) {
  160. at91_set_B_periph(AT91_PIN_PA28, 0); /* ECRS */
  161. at91_set_B_periph(AT91_PIN_PA29, 0); /* ECOL */
  162. at91_set_B_periph(AT91_PIN_PA25, 0); /* ERX2 */
  163. at91_set_B_periph(AT91_PIN_PA26, 0); /* ERX3 */
  164. at91_set_B_periph(AT91_PIN_PA27, 0); /* ERXCK */
  165. at91_set_B_periph(AT91_PIN_PA23, 0); /* ETX2 */
  166. at91_set_B_periph(AT91_PIN_PA24, 0); /* ETX3 */
  167. at91_set_B_periph(AT91_PIN_PA22, 0); /* ETXER */
  168. }
  169. eth_data = *data;
  170. platform_device_register(&at91sam9260_eth_device);
  171. }
  172. #else
  173. void __init at91_add_device_eth(struct macb_platform_data *data) {}
  174. #endif
  175. /* --------------------------------------------------------------------
  176. * MMC / SD
  177. * -------------------------------------------------------------------- */
  178. #if defined(CONFIG_MMC_AT91) || defined(CONFIG_MMC_AT91_MODULE)
  179. static u64 mmc_dmamask = DMA_BIT_MASK(32);
  180. static struct at91_mmc_data mmc_data;
  181. static struct resource mmc_resources[] = {
  182. [0] = {
  183. .start = AT91SAM9260_BASE_MCI,
  184. .end = AT91SAM9260_BASE_MCI + SZ_16K - 1,
  185. .flags = IORESOURCE_MEM,
  186. },
  187. [1] = {
  188. .start = AT91SAM9260_ID_MCI,
  189. .end = AT91SAM9260_ID_MCI,
  190. .flags = IORESOURCE_IRQ,
  191. },
  192. };
  193. static struct platform_device at91sam9260_mmc_device = {
  194. .name = "at91_mci",
  195. .id = -1,
  196. .dev = {
  197. .dma_mask = &mmc_dmamask,
  198. .coherent_dma_mask = DMA_BIT_MASK(32),
  199. .platform_data = &mmc_data,
  200. },
  201. .resource = mmc_resources,
  202. .num_resources = ARRAY_SIZE(mmc_resources),
  203. };
  204. void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data)
  205. {
  206. if (!data)
  207. return;
  208. /* input/irq */
  209. if (gpio_is_valid(data->det_pin)) {
  210. at91_set_gpio_input(data->det_pin, 1);
  211. at91_set_deglitch(data->det_pin, 1);
  212. }
  213. if (gpio_is_valid(data->wp_pin))
  214. at91_set_gpio_input(data->wp_pin, 1);
  215. if (gpio_is_valid(data->vcc_pin))
  216. at91_set_gpio_output(data->vcc_pin, 0);
  217. /* CLK */
  218. at91_set_A_periph(AT91_PIN_PA8, 0);
  219. if (data->slot_b) {
  220. /* CMD */
  221. at91_set_B_periph(AT91_PIN_PA1, 1);
  222. /* DAT0, maybe DAT1..DAT3 */
  223. at91_set_B_periph(AT91_PIN_PA0, 1);
  224. if (data->wire4) {
  225. at91_set_B_periph(AT91_PIN_PA5, 1);
  226. at91_set_B_periph(AT91_PIN_PA4, 1);
  227. at91_set_B_periph(AT91_PIN_PA3, 1);
  228. }
  229. } else {
  230. /* CMD */
  231. at91_set_A_periph(AT91_PIN_PA7, 1);
  232. /* DAT0, maybe DAT1..DAT3 */
  233. at91_set_A_periph(AT91_PIN_PA6, 1);
  234. if (data->wire4) {
  235. at91_set_A_periph(AT91_PIN_PA9, 1);
  236. at91_set_A_periph(AT91_PIN_PA10, 1);
  237. at91_set_A_periph(AT91_PIN_PA11, 1);
  238. }
  239. }
  240. mmc_data = *data;
  241. platform_device_register(&at91sam9260_mmc_device);
  242. }
  243. #else
  244. void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data) {}
  245. #endif
  246. /* --------------------------------------------------------------------
  247. * MMC / SD Slot for Atmel MCI Driver
  248. * -------------------------------------------------------------------- */
  249. #if defined(CONFIG_MMC_ATMELMCI) || defined(CONFIG_MMC_ATMELMCI_MODULE)
  250. static u64 mmc_dmamask = DMA_BIT_MASK(32);
  251. static struct mci_platform_data mmc_data;
  252. static struct resource mmc_resources[] = {
  253. [0] = {
  254. .start = AT91SAM9260_BASE_MCI,
  255. .end = AT91SAM9260_BASE_MCI + SZ_16K - 1,
  256. .flags = IORESOURCE_MEM,
  257. },
  258. [1] = {
  259. .start = AT91SAM9260_ID_MCI,
  260. .end = AT91SAM9260_ID_MCI,
  261. .flags = IORESOURCE_IRQ,
  262. },
  263. };
  264. static struct platform_device at91sam9260_mmc_device = {
  265. .name = "atmel_mci",
  266. .id = -1,
  267. .dev = {
  268. .dma_mask = &mmc_dmamask,
  269. .coherent_dma_mask = DMA_BIT_MASK(32),
  270. .platform_data = &mmc_data,
  271. },
  272. .resource = mmc_resources,
  273. .num_resources = ARRAY_SIZE(mmc_resources),
  274. };
  275. void __init at91_add_device_mci(short mmc_id, struct mci_platform_data *data)
  276. {
  277. unsigned int i;
  278. unsigned int slot_count = 0;
  279. if (!data)
  280. return;
  281. for (i = 0; i < ATMCI_MAX_NR_SLOTS; i++) {
  282. if (data->slot[i].bus_width) {
  283. /* input/irq */
  284. if (gpio_is_valid(data->slot[i].detect_pin)) {
  285. at91_set_gpio_input(data->slot[i].detect_pin, 1);
  286. at91_set_deglitch(data->slot[i].detect_pin, 1);
  287. }
  288. if (gpio_is_valid(data->slot[i].wp_pin))
  289. at91_set_gpio_input(data->slot[i].wp_pin, 1);
  290. switch (i) {
  291. case 0:
  292. /* CMD */
  293. at91_set_A_periph(AT91_PIN_PA7, 1);
  294. /* DAT0, maybe DAT1..DAT3 */
  295. at91_set_A_periph(AT91_PIN_PA6, 1);
  296. if (data->slot[i].bus_width == 4) {
  297. at91_set_A_periph(AT91_PIN_PA9, 1);
  298. at91_set_A_periph(AT91_PIN_PA10, 1);
  299. at91_set_A_periph(AT91_PIN_PA11, 1);
  300. }
  301. slot_count++;
  302. break;
  303. case 1:
  304. /* CMD */
  305. at91_set_B_periph(AT91_PIN_PA1, 1);
  306. /* DAT0, maybe DAT1..DAT3 */
  307. at91_set_B_periph(AT91_PIN_PA0, 1);
  308. if (data->slot[i].bus_width == 4) {
  309. at91_set_B_periph(AT91_PIN_PA5, 1);
  310. at91_set_B_periph(AT91_PIN_PA4, 1);
  311. at91_set_B_periph(AT91_PIN_PA3, 1);
  312. }
  313. slot_count++;
  314. break;
  315. default:
  316. printk(KERN_ERR
  317. "AT91: SD/MMC slot %d not available\n", i);
  318. break;
  319. }
  320. }
  321. }
  322. if (slot_count) {
  323. /* CLK */
  324. at91_set_A_periph(AT91_PIN_PA8, 0);
  325. mmc_data = *data;
  326. platform_device_register(&at91sam9260_mmc_device);
  327. }
  328. }
  329. #else
  330. void __init at91_add_device_mci(short mmc_id, struct mci_platform_data *data) {}
  331. #endif
  332. /* --------------------------------------------------------------------
  333. * NAND / SmartMedia
  334. * -------------------------------------------------------------------- */
  335. #if defined(CONFIG_MTD_NAND_ATMEL) || defined(CONFIG_MTD_NAND_ATMEL_MODULE)
  336. static struct atmel_nand_data nand_data;
  337. #define NAND_BASE AT91_CHIPSELECT_3
  338. static struct resource nand_resources[] = {
  339. [0] = {
  340. .start = NAND_BASE,
  341. .end = NAND_BASE + SZ_256M - 1,
  342. .flags = IORESOURCE_MEM,
  343. },
  344. [1] = {
  345. .start = AT91SAM9260_BASE_ECC,
  346. .end = AT91SAM9260_BASE_ECC + SZ_512 - 1,
  347. .flags = IORESOURCE_MEM,
  348. }
  349. };
  350. static struct platform_device at91sam9260_nand_device = {
  351. .name = "atmel_nand",
  352. .id = -1,
  353. .dev = {
  354. .platform_data = &nand_data,
  355. },
  356. .resource = nand_resources,
  357. .num_resources = ARRAY_SIZE(nand_resources),
  358. };
  359. void __init at91_add_device_nand(struct atmel_nand_data *data)
  360. {
  361. unsigned long csa;
  362. if (!data)
  363. return;
  364. csa = at91_matrix_read(AT91_MATRIX_EBICSA);
  365. at91_matrix_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_CS3A_SMC_SMARTMEDIA);
  366. /* enable pin */
  367. if (gpio_is_valid(data->enable_pin))
  368. at91_set_gpio_output(data->enable_pin, 1);
  369. /* ready/busy pin */
  370. if (gpio_is_valid(data->rdy_pin))
  371. at91_set_gpio_input(data->rdy_pin, 1);
  372. /* card detect pin */
  373. if (gpio_is_valid(data->det_pin))
  374. at91_set_gpio_input(data->det_pin, 1);
  375. nand_data = *data;
  376. platform_device_register(&at91sam9260_nand_device);
  377. }
  378. #else
  379. void __init at91_add_device_nand(struct atmel_nand_data *data) {}
  380. #endif
  381. /* --------------------------------------------------------------------
  382. * TWI (i2c)
  383. * -------------------------------------------------------------------- */
  384. /*
  385. * Prefer the GPIO code since the TWI controller isn't robust
  386. * (gets overruns and underruns under load) and can only issue
  387. * repeated STARTs in one scenario (the driver doesn't yet handle them).
  388. */
  389. #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
  390. static struct i2c_gpio_platform_data pdata = {
  391. .sda_pin = AT91_PIN_PA23,
  392. .sda_is_open_drain = 1,
  393. .scl_pin = AT91_PIN_PA24,
  394. .scl_is_open_drain = 1,
  395. .udelay = 2, /* ~100 kHz */
  396. };
  397. static struct platform_device at91sam9260_twi_device = {
  398. .name = "i2c-gpio",
  399. .id = -1,
  400. .dev.platform_data = &pdata,
  401. };
  402. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  403. {
  404. at91_set_GPIO_periph(AT91_PIN_PA23, 1); /* TWD (SDA) */
  405. at91_set_multi_drive(AT91_PIN_PA23, 1);
  406. at91_set_GPIO_periph(AT91_PIN_PA24, 1); /* TWCK (SCL) */
  407. at91_set_multi_drive(AT91_PIN_PA24, 1);
  408. i2c_register_board_info(0, devices, nr_devices);
  409. platform_device_register(&at91sam9260_twi_device);
  410. }
  411. #elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
  412. static struct resource twi_resources[] = {
  413. [0] = {
  414. .start = AT91SAM9260_BASE_TWI,
  415. .end = AT91SAM9260_BASE_TWI + SZ_16K - 1,
  416. .flags = IORESOURCE_MEM,
  417. },
  418. [1] = {
  419. .start = AT91SAM9260_ID_TWI,
  420. .end = AT91SAM9260_ID_TWI,
  421. .flags = IORESOURCE_IRQ,
  422. },
  423. };
  424. static struct platform_device at91sam9260_twi_device = {
  425. .name = "at91_i2c",
  426. .id = -1,
  427. .resource = twi_resources,
  428. .num_resources = ARRAY_SIZE(twi_resources),
  429. };
  430. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  431. {
  432. /* pins used for TWI interface */
  433. at91_set_A_periph(AT91_PIN_PA23, 0); /* TWD */
  434. at91_set_multi_drive(AT91_PIN_PA23, 1);
  435. at91_set_A_periph(AT91_PIN_PA24, 0); /* TWCK */
  436. at91_set_multi_drive(AT91_PIN_PA24, 1);
  437. i2c_register_board_info(0, devices, nr_devices);
  438. platform_device_register(&at91sam9260_twi_device);
  439. }
  440. #else
  441. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {}
  442. #endif
  443. /* --------------------------------------------------------------------
  444. * SPI
  445. * -------------------------------------------------------------------- */
  446. #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
  447. static u64 spi_dmamask = DMA_BIT_MASK(32);
  448. static struct resource spi0_resources[] = {
  449. [0] = {
  450. .start = AT91SAM9260_BASE_SPI0,
  451. .end = AT91SAM9260_BASE_SPI0 + SZ_16K - 1,
  452. .flags = IORESOURCE_MEM,
  453. },
  454. [1] = {
  455. .start = AT91SAM9260_ID_SPI0,
  456. .end = AT91SAM9260_ID_SPI0,
  457. .flags = IORESOURCE_IRQ,
  458. },
  459. };
  460. static struct platform_device at91sam9260_spi0_device = {
  461. .name = "atmel_spi",
  462. .id = 0,
  463. .dev = {
  464. .dma_mask = &spi_dmamask,
  465. .coherent_dma_mask = DMA_BIT_MASK(32),
  466. },
  467. .resource = spi0_resources,
  468. .num_resources = ARRAY_SIZE(spi0_resources),
  469. };
  470. static const unsigned spi0_standard_cs[4] = { AT91_PIN_PA3, AT91_PIN_PC11, AT91_PIN_PC16, AT91_PIN_PC17 };
  471. static struct resource spi1_resources[] = {
  472. [0] = {
  473. .start = AT91SAM9260_BASE_SPI1,
  474. .end = AT91SAM9260_BASE_SPI1 + SZ_16K - 1,
  475. .flags = IORESOURCE_MEM,
  476. },
  477. [1] = {
  478. .start = AT91SAM9260_ID_SPI1,
  479. .end = AT91SAM9260_ID_SPI1,
  480. .flags = IORESOURCE_IRQ,
  481. },
  482. };
  483. static struct platform_device at91sam9260_spi1_device = {
  484. .name = "atmel_spi",
  485. .id = 1,
  486. .dev = {
  487. .dma_mask = &spi_dmamask,
  488. .coherent_dma_mask = DMA_BIT_MASK(32),
  489. },
  490. .resource = spi1_resources,
  491. .num_resources = ARRAY_SIZE(spi1_resources),
  492. };
  493. static const unsigned spi1_standard_cs[4] = { AT91_PIN_PB3, AT91_PIN_PC5, AT91_PIN_PC4, AT91_PIN_PC3 };
  494. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
  495. {
  496. int i;
  497. unsigned long cs_pin;
  498. short enable_spi0 = 0;
  499. short enable_spi1 = 0;
  500. /* Choose SPI chip-selects */
  501. for (i = 0; i < nr_devices; i++) {
  502. if (devices[i].controller_data)
  503. cs_pin = (unsigned long) devices[i].controller_data;
  504. else if (devices[i].bus_num == 0)
  505. cs_pin = spi0_standard_cs[devices[i].chip_select];
  506. else
  507. cs_pin = spi1_standard_cs[devices[i].chip_select];
  508. if (!gpio_is_valid(cs_pin))
  509. continue;
  510. if (devices[i].bus_num == 0)
  511. enable_spi0 = 1;
  512. else
  513. enable_spi1 = 1;
  514. /* enable chip-select pin */
  515. at91_set_gpio_output(cs_pin, 1);
  516. /* pass chip-select pin to driver */
  517. devices[i].controller_data = (void *) cs_pin;
  518. }
  519. spi_register_board_info(devices, nr_devices);
  520. /* Configure SPI bus(es) */
  521. if (enable_spi0) {
  522. at91_set_A_periph(AT91_PIN_PA0, 0); /* SPI0_MISO */
  523. at91_set_A_periph(AT91_PIN_PA1, 0); /* SPI0_MOSI */
  524. at91_set_A_periph(AT91_PIN_PA2, 0); /* SPI1_SPCK */
  525. platform_device_register(&at91sam9260_spi0_device);
  526. }
  527. if (enable_spi1) {
  528. at91_set_A_periph(AT91_PIN_PB0, 0); /* SPI1_MISO */
  529. at91_set_A_periph(AT91_PIN_PB1, 0); /* SPI1_MOSI */
  530. at91_set_A_periph(AT91_PIN_PB2, 0); /* SPI1_SPCK */
  531. platform_device_register(&at91sam9260_spi1_device);
  532. }
  533. }
  534. #else
  535. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
  536. #endif
  537. /* --------------------------------------------------------------------
  538. * Timer/Counter blocks
  539. * -------------------------------------------------------------------- */
  540. #ifdef CONFIG_ATMEL_TCLIB
  541. static struct resource tcb0_resources[] = {
  542. [0] = {
  543. .start = AT91SAM9260_BASE_TCB0,
  544. .end = AT91SAM9260_BASE_TCB0 + SZ_256 - 1,
  545. .flags = IORESOURCE_MEM,
  546. },
  547. [1] = {
  548. .start = AT91SAM9260_ID_TC0,
  549. .end = AT91SAM9260_ID_TC0,
  550. .flags = IORESOURCE_IRQ,
  551. },
  552. [2] = {
  553. .start = AT91SAM9260_ID_TC1,
  554. .end = AT91SAM9260_ID_TC1,
  555. .flags = IORESOURCE_IRQ,
  556. },
  557. [3] = {
  558. .start = AT91SAM9260_ID_TC2,
  559. .end = AT91SAM9260_ID_TC2,
  560. .flags = IORESOURCE_IRQ,
  561. },
  562. };
  563. static struct platform_device at91sam9260_tcb0_device = {
  564. .name = "atmel_tcb",
  565. .id = 0,
  566. .resource = tcb0_resources,
  567. .num_resources = ARRAY_SIZE(tcb0_resources),
  568. };
  569. static struct resource tcb1_resources[] = {
  570. [0] = {
  571. .start = AT91SAM9260_BASE_TCB1,
  572. .end = AT91SAM9260_BASE_TCB1 + SZ_256 - 1,
  573. .flags = IORESOURCE_MEM,
  574. },
  575. [1] = {
  576. .start = AT91SAM9260_ID_TC3,
  577. .end = AT91SAM9260_ID_TC3,
  578. .flags = IORESOURCE_IRQ,
  579. },
  580. [2] = {
  581. .start = AT91SAM9260_ID_TC4,
  582. .end = AT91SAM9260_ID_TC4,
  583. .flags = IORESOURCE_IRQ,
  584. },
  585. [3] = {
  586. .start = AT91SAM9260_ID_TC5,
  587. .end = AT91SAM9260_ID_TC5,
  588. .flags = IORESOURCE_IRQ,
  589. },
  590. };
  591. static struct platform_device at91sam9260_tcb1_device = {
  592. .name = "atmel_tcb",
  593. .id = 1,
  594. .resource = tcb1_resources,
  595. .num_resources = ARRAY_SIZE(tcb1_resources),
  596. };
  597. static void __init at91_add_device_tc(void)
  598. {
  599. platform_device_register(&at91sam9260_tcb0_device);
  600. platform_device_register(&at91sam9260_tcb1_device);
  601. }
  602. #else
  603. static void __init at91_add_device_tc(void) { }
  604. #endif
  605. /* --------------------------------------------------------------------
  606. * RTT
  607. * -------------------------------------------------------------------- */
  608. static struct resource rtt_resources[] = {
  609. {
  610. .start = AT91SAM9260_BASE_RTT,
  611. .end = AT91SAM9260_BASE_RTT + SZ_16 - 1,
  612. .flags = IORESOURCE_MEM,
  613. }, {
  614. .flags = IORESOURCE_MEM,
  615. },
  616. };
  617. static struct platform_device at91sam9260_rtt_device = {
  618. .name = "at91_rtt",
  619. .id = 0,
  620. .resource = rtt_resources,
  621. };
  622. #if IS_ENABLED(CONFIG_RTC_DRV_AT91SAM9)
  623. static void __init at91_add_device_rtt_rtc(void)
  624. {
  625. at91sam9260_rtt_device.name = "rtc-at91sam9";
  626. /*
  627. * The second resource is needed:
  628. * GPBR will serve as the storage for RTC time offset
  629. */
  630. at91sam9260_rtt_device.num_resources = 2;
  631. rtt_resources[1].start = AT91SAM9260_BASE_GPBR +
  632. 4 * CONFIG_RTC_DRV_AT91SAM9_GPBR;
  633. rtt_resources[1].end = rtt_resources[1].start + 3;
  634. }
  635. #else
  636. static void __init at91_add_device_rtt_rtc(void)
  637. {
  638. /* Only one resource is needed: RTT not used as RTC */
  639. at91sam9260_rtt_device.num_resources = 1;
  640. }
  641. #endif
  642. static void __init at91_add_device_rtt(void)
  643. {
  644. at91_add_device_rtt_rtc();
  645. platform_device_register(&at91sam9260_rtt_device);
  646. }
  647. /* --------------------------------------------------------------------
  648. * Watchdog
  649. * -------------------------------------------------------------------- */
  650. #if defined(CONFIG_AT91SAM9X_WATCHDOG) || defined(CONFIG_AT91SAM9X_WATCHDOG_MODULE)
  651. static struct resource wdt_resources[] = {
  652. {
  653. .start = AT91SAM9260_BASE_WDT,
  654. .end = AT91SAM9260_BASE_WDT + SZ_16 - 1,
  655. .flags = IORESOURCE_MEM,
  656. }
  657. };
  658. static struct platform_device at91sam9260_wdt_device = {
  659. .name = "at91_wdt",
  660. .id = -1,
  661. .resource = wdt_resources,
  662. .num_resources = ARRAY_SIZE(wdt_resources),
  663. };
  664. static void __init at91_add_device_watchdog(void)
  665. {
  666. platform_device_register(&at91sam9260_wdt_device);
  667. }
  668. #else
  669. static void __init at91_add_device_watchdog(void) {}
  670. #endif
  671. /* --------------------------------------------------------------------
  672. * SSC -- Synchronous Serial Controller
  673. * -------------------------------------------------------------------- */
  674. #if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
  675. static u64 ssc_dmamask = DMA_BIT_MASK(32);
  676. static struct resource ssc_resources[] = {
  677. [0] = {
  678. .start = AT91SAM9260_BASE_SSC,
  679. .end = AT91SAM9260_BASE_SSC + SZ_16K - 1,
  680. .flags = IORESOURCE_MEM,
  681. },
  682. [1] = {
  683. .start = AT91SAM9260_ID_SSC,
  684. .end = AT91SAM9260_ID_SSC,
  685. .flags = IORESOURCE_IRQ,
  686. },
  687. };
  688. static struct platform_device at91sam9260_ssc_device = {
  689. .name = "ssc",
  690. .id = 0,
  691. .dev = {
  692. .dma_mask = &ssc_dmamask,
  693. .coherent_dma_mask = DMA_BIT_MASK(32),
  694. },
  695. .resource = ssc_resources,
  696. .num_resources = ARRAY_SIZE(ssc_resources),
  697. };
  698. static inline void configure_ssc_pins(unsigned pins)
  699. {
  700. if (pins & ATMEL_SSC_TF)
  701. at91_set_A_periph(AT91_PIN_PB17, 1);
  702. if (pins & ATMEL_SSC_TK)
  703. at91_set_A_periph(AT91_PIN_PB16, 1);
  704. if (pins & ATMEL_SSC_TD)
  705. at91_set_A_periph(AT91_PIN_PB18, 1);
  706. if (pins & ATMEL_SSC_RD)
  707. at91_set_A_periph(AT91_PIN_PB19, 1);
  708. if (pins & ATMEL_SSC_RK)
  709. at91_set_A_periph(AT91_PIN_PB20, 1);
  710. if (pins & ATMEL_SSC_RF)
  711. at91_set_A_periph(AT91_PIN_PB21, 1);
  712. }
  713. /*
  714. * SSC controllers are accessed through library code, instead of any
  715. * kind of all-singing/all-dancing driver. For example one could be
  716. * used by a particular I2S audio codec's driver, while another one
  717. * on the same system might be used by a custom data capture driver.
  718. */
  719. void __init at91_add_device_ssc(unsigned id, unsigned pins)
  720. {
  721. struct platform_device *pdev;
  722. /*
  723. * NOTE: caller is responsible for passing information matching
  724. * "pins" to whatever will be using each particular controller.
  725. */
  726. switch (id) {
  727. case AT91SAM9260_ID_SSC:
  728. pdev = &at91sam9260_ssc_device;
  729. configure_ssc_pins(pins);
  730. break;
  731. default:
  732. return;
  733. }
  734. platform_device_register(pdev);
  735. }
  736. #else
  737. void __init at91_add_device_ssc(unsigned id, unsigned pins) {}
  738. #endif
  739. /* --------------------------------------------------------------------
  740. * UART
  741. * -------------------------------------------------------------------- */
  742. #if defined(CONFIG_SERIAL_ATMEL)
  743. static struct resource dbgu_resources[] = {
  744. [0] = {
  745. .start = AT91SAM9260_BASE_DBGU,
  746. .end = AT91SAM9260_BASE_DBGU + SZ_512 - 1,
  747. .flags = IORESOURCE_MEM,
  748. },
  749. [1] = {
  750. .start = AT91_ID_SYS,
  751. .end = AT91_ID_SYS,
  752. .flags = IORESOURCE_IRQ,
  753. },
  754. };
  755. static struct atmel_uart_data dbgu_data = {
  756. .use_dma_tx = 0,
  757. .use_dma_rx = 0, /* DBGU not capable of receive DMA */
  758. };
  759. static u64 dbgu_dmamask = DMA_BIT_MASK(32);
  760. static struct platform_device at91sam9260_dbgu_device = {
  761. .name = "atmel_usart",
  762. .id = 0,
  763. .dev = {
  764. .dma_mask = &dbgu_dmamask,
  765. .coherent_dma_mask = DMA_BIT_MASK(32),
  766. .platform_data = &dbgu_data,
  767. },
  768. .resource = dbgu_resources,
  769. .num_resources = ARRAY_SIZE(dbgu_resources),
  770. };
  771. static inline void configure_dbgu_pins(void)
  772. {
  773. at91_set_A_periph(AT91_PIN_PB14, 0); /* DRXD */
  774. at91_set_A_periph(AT91_PIN_PB15, 1); /* DTXD */
  775. }
  776. static struct resource uart0_resources[] = {
  777. [0] = {
  778. .start = AT91SAM9260_BASE_US0,
  779. .end = AT91SAM9260_BASE_US0 + SZ_16K - 1,
  780. .flags = IORESOURCE_MEM,
  781. },
  782. [1] = {
  783. .start = AT91SAM9260_ID_US0,
  784. .end = AT91SAM9260_ID_US0,
  785. .flags = IORESOURCE_IRQ,
  786. },
  787. };
  788. static struct atmel_uart_data uart0_data = {
  789. .use_dma_tx = 1,
  790. .use_dma_rx = 1,
  791. };
  792. static u64 uart0_dmamask = DMA_BIT_MASK(32);
  793. static struct platform_device at91sam9260_uart0_device = {
  794. .name = "atmel_usart",
  795. .id = 1,
  796. .dev = {
  797. .dma_mask = &uart0_dmamask,
  798. .coherent_dma_mask = DMA_BIT_MASK(32),
  799. .platform_data = &uart0_data,
  800. },
  801. .resource = uart0_resources,
  802. .num_resources = ARRAY_SIZE(uart0_resources),
  803. };
  804. static inline void configure_usart0_pins(unsigned pins)
  805. {
  806. at91_set_A_periph(AT91_PIN_PB4, 1); /* TXD0 */
  807. at91_set_A_periph(AT91_PIN_PB5, 0); /* RXD0 */
  808. if (pins & ATMEL_UART_RTS)
  809. at91_set_A_periph(AT91_PIN_PB26, 0); /* RTS0 */
  810. if (pins & ATMEL_UART_CTS)
  811. at91_set_A_periph(AT91_PIN_PB27, 0); /* CTS0 */
  812. if (pins & ATMEL_UART_DTR)
  813. at91_set_A_periph(AT91_PIN_PB24, 0); /* DTR0 */
  814. if (pins & ATMEL_UART_DSR)
  815. at91_set_A_periph(AT91_PIN_PB22, 0); /* DSR0 */
  816. if (pins & ATMEL_UART_DCD)
  817. at91_set_A_periph(AT91_PIN_PB23, 0); /* DCD0 */
  818. if (pins & ATMEL_UART_RI)
  819. at91_set_A_periph(AT91_PIN_PB25, 0); /* RI0 */
  820. }
  821. static struct resource uart1_resources[] = {
  822. [0] = {
  823. .start = AT91SAM9260_BASE_US1,
  824. .end = AT91SAM9260_BASE_US1 + SZ_16K - 1,
  825. .flags = IORESOURCE_MEM,
  826. },
  827. [1] = {
  828. .start = AT91SAM9260_ID_US1,
  829. .end = AT91SAM9260_ID_US1,
  830. .flags = IORESOURCE_IRQ,
  831. },
  832. };
  833. static struct atmel_uart_data uart1_data = {
  834. .use_dma_tx = 1,
  835. .use_dma_rx = 1,
  836. };
  837. static u64 uart1_dmamask = DMA_BIT_MASK(32);
  838. static struct platform_device at91sam9260_uart1_device = {
  839. .name = "atmel_usart",
  840. .id = 2,
  841. .dev = {
  842. .dma_mask = &uart1_dmamask,
  843. .coherent_dma_mask = DMA_BIT_MASK(32),
  844. .platform_data = &uart1_data,
  845. },
  846. .resource = uart1_resources,
  847. .num_resources = ARRAY_SIZE(uart1_resources),
  848. };
  849. static inline void configure_usart1_pins(unsigned pins)
  850. {
  851. at91_set_A_periph(AT91_PIN_PB6, 1); /* TXD1 */
  852. at91_set_A_periph(AT91_PIN_PB7, 0); /* RXD1 */
  853. if (pins & ATMEL_UART_RTS)
  854. at91_set_A_periph(AT91_PIN_PB28, 0); /* RTS1 */
  855. if (pins & ATMEL_UART_CTS)
  856. at91_set_A_periph(AT91_PIN_PB29, 0); /* CTS1 */
  857. }
  858. static struct resource uart2_resources[] = {
  859. [0] = {
  860. .start = AT91SAM9260_BASE_US2,
  861. .end = AT91SAM9260_BASE_US2 + SZ_16K - 1,
  862. .flags = IORESOURCE_MEM,
  863. },
  864. [1] = {
  865. .start = AT91SAM9260_ID_US2,
  866. .end = AT91SAM9260_ID_US2,
  867. .flags = IORESOURCE_IRQ,
  868. },
  869. };
  870. static struct atmel_uart_data uart2_data = {
  871. .use_dma_tx = 1,
  872. .use_dma_rx = 1,
  873. };
  874. static u64 uart2_dmamask = DMA_BIT_MASK(32);
  875. static struct platform_device at91sam9260_uart2_device = {
  876. .name = "atmel_usart",
  877. .id = 3,
  878. .dev = {
  879. .dma_mask = &uart2_dmamask,
  880. .coherent_dma_mask = DMA_BIT_MASK(32),
  881. .platform_data = &uart2_data,
  882. },
  883. .resource = uart2_resources,
  884. .num_resources = ARRAY_SIZE(uart2_resources),
  885. };
  886. static inline void configure_usart2_pins(unsigned pins)
  887. {
  888. at91_set_A_periph(AT91_PIN_PB8, 1); /* TXD2 */
  889. at91_set_A_periph(AT91_PIN_PB9, 0); /* RXD2 */
  890. if (pins & ATMEL_UART_RTS)
  891. at91_set_A_periph(AT91_PIN_PA4, 0); /* RTS2 */
  892. if (pins & ATMEL_UART_CTS)
  893. at91_set_A_periph(AT91_PIN_PA5, 0); /* CTS2 */
  894. }
  895. static struct resource uart3_resources[] = {
  896. [0] = {
  897. .start = AT91SAM9260_BASE_US3,
  898. .end = AT91SAM9260_BASE_US3 + SZ_16K - 1,
  899. .flags = IORESOURCE_MEM,
  900. },
  901. [1] = {
  902. .start = AT91SAM9260_ID_US3,
  903. .end = AT91SAM9260_ID_US3,
  904. .flags = IORESOURCE_IRQ,
  905. },
  906. };
  907. static struct atmel_uart_data uart3_data = {
  908. .use_dma_tx = 1,
  909. .use_dma_rx = 1,
  910. };
  911. static u64 uart3_dmamask = DMA_BIT_MASK(32);
  912. static struct platform_device at91sam9260_uart3_device = {
  913. .name = "atmel_usart",
  914. .id = 4,
  915. .dev = {
  916. .dma_mask = &uart3_dmamask,
  917. .coherent_dma_mask = DMA_BIT_MASK(32),
  918. .platform_data = &uart3_data,
  919. },
  920. .resource = uart3_resources,
  921. .num_resources = ARRAY_SIZE(uart3_resources),
  922. };
  923. static inline void configure_usart3_pins(unsigned pins)
  924. {
  925. at91_set_A_periph(AT91_PIN_PB10, 1); /* TXD3 */
  926. at91_set_A_periph(AT91_PIN_PB11, 0); /* RXD3 */
  927. if (pins & ATMEL_UART_RTS)
  928. at91_set_B_periph(AT91_PIN_PC8, 0); /* RTS3 */
  929. if (pins & ATMEL_UART_CTS)
  930. at91_set_B_periph(AT91_PIN_PC10, 0); /* CTS3 */
  931. }
  932. static struct resource uart4_resources[] = {
  933. [0] = {
  934. .start = AT91SAM9260_BASE_US4,
  935. .end = AT91SAM9260_BASE_US4 + SZ_16K - 1,
  936. .flags = IORESOURCE_MEM,
  937. },
  938. [1] = {
  939. .start = AT91SAM9260_ID_US4,
  940. .end = AT91SAM9260_ID_US4,
  941. .flags = IORESOURCE_IRQ,
  942. },
  943. };
  944. static struct atmel_uart_data uart4_data = {
  945. .use_dma_tx = 1,
  946. .use_dma_rx = 1,
  947. };
  948. static u64 uart4_dmamask = DMA_BIT_MASK(32);
  949. static struct platform_device at91sam9260_uart4_device = {
  950. .name = "atmel_usart",
  951. .id = 5,
  952. .dev = {
  953. .dma_mask = &uart4_dmamask,
  954. .coherent_dma_mask = DMA_BIT_MASK(32),
  955. .platform_data = &uart4_data,
  956. },
  957. .resource = uart4_resources,
  958. .num_resources = ARRAY_SIZE(uart4_resources),
  959. };
  960. static inline void configure_usart4_pins(void)
  961. {
  962. at91_set_B_periph(AT91_PIN_PA31, 1); /* TXD4 */
  963. at91_set_B_periph(AT91_PIN_PA30, 0); /* RXD4 */
  964. }
  965. static struct resource uart5_resources[] = {
  966. [0] = {
  967. .start = AT91SAM9260_BASE_US5,
  968. .end = AT91SAM9260_BASE_US5 + SZ_16K - 1,
  969. .flags = IORESOURCE_MEM,
  970. },
  971. [1] = {
  972. .start = AT91SAM9260_ID_US5,
  973. .end = AT91SAM9260_ID_US5,
  974. .flags = IORESOURCE_IRQ,
  975. },
  976. };
  977. static struct atmel_uart_data uart5_data = {
  978. .use_dma_tx = 1,
  979. .use_dma_rx = 1,
  980. };
  981. static u64 uart5_dmamask = DMA_BIT_MASK(32);
  982. static struct platform_device at91sam9260_uart5_device = {
  983. .name = "atmel_usart",
  984. .id = 6,
  985. .dev = {
  986. .dma_mask = &uart5_dmamask,
  987. .coherent_dma_mask = DMA_BIT_MASK(32),
  988. .platform_data = &uart5_data,
  989. },
  990. .resource = uart5_resources,
  991. .num_resources = ARRAY_SIZE(uart5_resources),
  992. };
  993. static inline void configure_usart5_pins(void)
  994. {
  995. at91_set_A_periph(AT91_PIN_PB12, 1); /* TXD5 */
  996. at91_set_A_periph(AT91_PIN_PB13, 0); /* RXD5 */
  997. }
  998. static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
  999. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
  1000. {
  1001. struct platform_device *pdev;
  1002. struct atmel_uart_data *pdata;
  1003. switch (id) {
  1004. case 0: /* DBGU */
  1005. pdev = &at91sam9260_dbgu_device;
  1006. configure_dbgu_pins();
  1007. break;
  1008. case AT91SAM9260_ID_US0:
  1009. pdev = &at91sam9260_uart0_device;
  1010. configure_usart0_pins(pins);
  1011. break;
  1012. case AT91SAM9260_ID_US1:
  1013. pdev = &at91sam9260_uart1_device;
  1014. configure_usart1_pins(pins);
  1015. break;
  1016. case AT91SAM9260_ID_US2:
  1017. pdev = &at91sam9260_uart2_device;
  1018. configure_usart2_pins(pins);
  1019. break;
  1020. case AT91SAM9260_ID_US3:
  1021. pdev = &at91sam9260_uart3_device;
  1022. configure_usart3_pins(pins);
  1023. break;
  1024. case AT91SAM9260_ID_US4:
  1025. pdev = &at91sam9260_uart4_device;
  1026. configure_usart4_pins();
  1027. break;
  1028. case AT91SAM9260_ID_US5:
  1029. pdev = &at91sam9260_uart5_device;
  1030. configure_usart5_pins();
  1031. break;
  1032. default:
  1033. return;
  1034. }
  1035. pdata = pdev->dev.platform_data;
  1036. pdata->num = portnr; /* update to mapped ID */
  1037. if (portnr < ATMEL_MAX_UART)
  1038. at91_uarts[portnr] = pdev;
  1039. }
  1040. void __init at91_add_device_serial(void)
  1041. {
  1042. int i;
  1043. for (i = 0; i < ATMEL_MAX_UART; i++) {
  1044. if (at91_uarts[i])
  1045. platform_device_register(at91_uarts[i]);
  1046. }
  1047. }
  1048. #else
  1049. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
  1050. void __init at91_add_device_serial(void) {}
  1051. #endif
  1052. /* --------------------------------------------------------------------
  1053. * CF/IDE
  1054. * -------------------------------------------------------------------- */
  1055. #if defined(CONFIG_PATA_AT91) || defined(CONFIG_PATA_AT91_MODULE) || \
  1056. defined(CONFIG_AT91_CF) || defined(CONFIG_AT91_CF_MODULE)
  1057. static struct at91_cf_data cf0_data;
  1058. static struct resource cf0_resources[] = {
  1059. [0] = {
  1060. .start = AT91_CHIPSELECT_4,
  1061. .end = AT91_CHIPSELECT_4 + SZ_256M - 1,
  1062. .flags = IORESOURCE_MEM,
  1063. }
  1064. };
  1065. static struct platform_device cf0_device = {
  1066. .id = 0,
  1067. .dev = {
  1068. .platform_data = &cf0_data,
  1069. },
  1070. .resource = cf0_resources,
  1071. .num_resources = ARRAY_SIZE(cf0_resources),
  1072. };
  1073. static struct at91_cf_data cf1_data;
  1074. static struct resource cf1_resources[] = {
  1075. [0] = {
  1076. .start = AT91_CHIPSELECT_5,
  1077. .end = AT91_CHIPSELECT_5 + SZ_256M - 1,
  1078. .flags = IORESOURCE_MEM,
  1079. }
  1080. };
  1081. static struct platform_device cf1_device = {
  1082. .id = 1,
  1083. .dev = {
  1084. .platform_data = &cf1_data,
  1085. },
  1086. .resource = cf1_resources,
  1087. .num_resources = ARRAY_SIZE(cf1_resources),
  1088. };
  1089. void __init at91_add_device_cf(struct at91_cf_data *data)
  1090. {
  1091. struct platform_device *pdev;
  1092. unsigned long csa;
  1093. if (!data)
  1094. return;
  1095. csa = at91_matrix_read(AT91_MATRIX_EBICSA);
  1096. switch (data->chipselect) {
  1097. case 4:
  1098. at91_set_multi_drive(AT91_PIN_PC8, 0);
  1099. at91_set_A_periph(AT91_PIN_PC8, 0);
  1100. csa |= AT91_MATRIX_CS4A_SMC_CF1;
  1101. cf0_data = *data;
  1102. pdev = &cf0_device;
  1103. break;
  1104. case 5:
  1105. at91_set_multi_drive(AT91_PIN_PC9, 0);
  1106. at91_set_A_periph(AT91_PIN_PC9, 0);
  1107. csa |= AT91_MATRIX_CS5A_SMC_CF2;
  1108. cf1_data = *data;
  1109. pdev = &cf1_device;
  1110. break;
  1111. default:
  1112. printk(KERN_ERR "AT91 CF: bad chip-select requested (%u)\n",
  1113. data->chipselect);
  1114. return;
  1115. }
  1116. at91_matrix_write(AT91_MATRIX_EBICSA, csa);
  1117. if (gpio_is_valid(data->rst_pin)) {
  1118. at91_set_multi_drive(data->rst_pin, 0);
  1119. at91_set_gpio_output(data->rst_pin, 1);
  1120. }
  1121. if (gpio_is_valid(data->irq_pin)) {
  1122. at91_set_gpio_input(data->irq_pin, 0);
  1123. at91_set_deglitch(data->irq_pin, 1);
  1124. }
  1125. if (gpio_is_valid(data->det_pin)) {
  1126. at91_set_gpio_input(data->det_pin, 0);
  1127. at91_set_deglitch(data->det_pin, 1);
  1128. }
  1129. at91_set_B_periph(AT91_PIN_PC6, 0); /* CFCE1 */
  1130. at91_set_B_periph(AT91_PIN_PC7, 0); /* CFCE2 */
  1131. at91_set_A_periph(AT91_PIN_PC10, 0); /* CFRNW */
  1132. at91_set_A_periph(AT91_PIN_PC15, 1); /* NWAIT */
  1133. if (data->flags & AT91_CF_TRUE_IDE)
  1134. #if defined(CONFIG_PATA_AT91) || defined(CONFIG_PATA_AT91_MODULE)
  1135. pdev->name = "pata_at91";
  1136. #else
  1137. #warning "board requires AT91_CF_TRUE_IDE: enable pata_at91"
  1138. #endif
  1139. else
  1140. pdev->name = "at91_cf";
  1141. platform_device_register(pdev);
  1142. }
  1143. #else
  1144. void __init at91_add_device_cf(struct at91_cf_data * data) {}
  1145. #endif
  1146. /* -------------------------------------------------------------------- */
  1147. /*
  1148. * These devices are always present and don't need any board-specific
  1149. * setup.
  1150. */
  1151. static int __init at91_add_standard_devices(void)
  1152. {
  1153. if (of_have_populated_dt())
  1154. return 0;
  1155. at91_add_device_rtt();
  1156. at91_add_device_watchdog();
  1157. at91_add_device_tc();
  1158. return 0;
  1159. }
  1160. arch_initcall(at91_add_standard_devices);