at91sam9260_devices.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369
  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. #ifdef CONFIG_USB_AT91
  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 (devices[i].bus_num == 0)
  509. enable_spi0 = 1;
  510. else
  511. enable_spi1 = 1;
  512. /* enable chip-select pin */
  513. at91_set_gpio_output(cs_pin, 1);
  514. /* pass chip-select pin to driver */
  515. devices[i].controller_data = (void *) cs_pin;
  516. }
  517. spi_register_board_info(devices, nr_devices);
  518. /* Configure SPI bus(es) */
  519. if (enable_spi0) {
  520. at91_set_A_periph(AT91_PIN_PA0, 0); /* SPI0_MISO */
  521. at91_set_A_periph(AT91_PIN_PA1, 0); /* SPI0_MOSI */
  522. at91_set_A_periph(AT91_PIN_PA2, 0); /* SPI1_SPCK */
  523. platform_device_register(&at91sam9260_spi0_device);
  524. }
  525. if (enable_spi1) {
  526. at91_set_A_periph(AT91_PIN_PB0, 0); /* SPI1_MISO */
  527. at91_set_A_periph(AT91_PIN_PB1, 0); /* SPI1_MOSI */
  528. at91_set_A_periph(AT91_PIN_PB2, 0); /* SPI1_SPCK */
  529. platform_device_register(&at91sam9260_spi1_device);
  530. }
  531. }
  532. #else
  533. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
  534. #endif
  535. /* --------------------------------------------------------------------
  536. * Timer/Counter blocks
  537. * -------------------------------------------------------------------- */
  538. #ifdef CONFIG_ATMEL_TCLIB
  539. static struct resource tcb0_resources[] = {
  540. [0] = {
  541. .start = AT91SAM9260_BASE_TCB0,
  542. .end = AT91SAM9260_BASE_TCB0 + SZ_16K - 1,
  543. .flags = IORESOURCE_MEM,
  544. },
  545. [1] = {
  546. .start = AT91SAM9260_ID_TC0,
  547. .end = AT91SAM9260_ID_TC0,
  548. .flags = IORESOURCE_IRQ,
  549. },
  550. [2] = {
  551. .start = AT91SAM9260_ID_TC1,
  552. .end = AT91SAM9260_ID_TC1,
  553. .flags = IORESOURCE_IRQ,
  554. },
  555. [3] = {
  556. .start = AT91SAM9260_ID_TC2,
  557. .end = AT91SAM9260_ID_TC2,
  558. .flags = IORESOURCE_IRQ,
  559. },
  560. };
  561. static struct platform_device at91sam9260_tcb0_device = {
  562. .name = "atmel_tcb",
  563. .id = 0,
  564. .resource = tcb0_resources,
  565. .num_resources = ARRAY_SIZE(tcb0_resources),
  566. };
  567. static struct resource tcb1_resources[] = {
  568. [0] = {
  569. .start = AT91SAM9260_BASE_TCB1,
  570. .end = AT91SAM9260_BASE_TCB1 + SZ_16K - 1,
  571. .flags = IORESOURCE_MEM,
  572. },
  573. [1] = {
  574. .start = AT91SAM9260_ID_TC3,
  575. .end = AT91SAM9260_ID_TC3,
  576. .flags = IORESOURCE_IRQ,
  577. },
  578. [2] = {
  579. .start = AT91SAM9260_ID_TC4,
  580. .end = AT91SAM9260_ID_TC4,
  581. .flags = IORESOURCE_IRQ,
  582. },
  583. [3] = {
  584. .start = AT91SAM9260_ID_TC5,
  585. .end = AT91SAM9260_ID_TC5,
  586. .flags = IORESOURCE_IRQ,
  587. },
  588. };
  589. static struct platform_device at91sam9260_tcb1_device = {
  590. .name = "atmel_tcb",
  591. .id = 1,
  592. .resource = tcb1_resources,
  593. .num_resources = ARRAY_SIZE(tcb1_resources),
  594. };
  595. static void __init at91_add_device_tc(void)
  596. {
  597. platform_device_register(&at91sam9260_tcb0_device);
  598. platform_device_register(&at91sam9260_tcb1_device);
  599. }
  600. #else
  601. static void __init at91_add_device_tc(void) { }
  602. #endif
  603. /* --------------------------------------------------------------------
  604. * RTT
  605. * -------------------------------------------------------------------- */
  606. static struct resource rtt_resources[] = {
  607. {
  608. .start = AT91SAM9260_BASE_RTT,
  609. .end = AT91SAM9260_BASE_RTT + SZ_16 - 1,
  610. .flags = IORESOURCE_MEM,
  611. }, {
  612. .flags = IORESOURCE_MEM,
  613. },
  614. };
  615. static struct platform_device at91sam9260_rtt_device = {
  616. .name = "at91_rtt",
  617. .id = 0,
  618. .resource = rtt_resources,
  619. };
  620. #if IS_ENABLED(CONFIG_RTC_DRV_AT91SAM9)
  621. static void __init at91_add_device_rtt_rtc(void)
  622. {
  623. at91sam9260_rtt_device.name = "rtc-at91sam9";
  624. /*
  625. * The second resource is needed:
  626. * GPBR will serve as the storage for RTC time offset
  627. */
  628. at91sam9260_rtt_device.num_resources = 2;
  629. rtt_resources[1].start = AT91SAM9260_BASE_GPBR +
  630. 4 * CONFIG_RTC_DRV_AT91SAM9_GPBR;
  631. rtt_resources[1].end = rtt_resources[1].start + 3;
  632. }
  633. #else
  634. static void __init at91_add_device_rtt_rtc(void)
  635. {
  636. /* Only one resource is needed: RTT not used as RTC */
  637. at91sam9260_rtt_device.num_resources = 1;
  638. }
  639. #endif
  640. static void __init at91_add_device_rtt(void)
  641. {
  642. at91_add_device_rtt_rtc();
  643. platform_device_register(&at91sam9260_rtt_device);
  644. }
  645. /* --------------------------------------------------------------------
  646. * Watchdog
  647. * -------------------------------------------------------------------- */
  648. #if defined(CONFIG_AT91SAM9X_WATCHDOG) || defined(CONFIG_AT91SAM9X_WATCHDOG_MODULE)
  649. static struct resource wdt_resources[] = {
  650. {
  651. .start = AT91SAM9260_BASE_WDT,
  652. .end = AT91SAM9260_BASE_WDT + SZ_16 - 1,
  653. .flags = IORESOURCE_MEM,
  654. }
  655. };
  656. static struct platform_device at91sam9260_wdt_device = {
  657. .name = "at91_wdt",
  658. .id = -1,
  659. .resource = wdt_resources,
  660. .num_resources = ARRAY_SIZE(wdt_resources),
  661. };
  662. static void __init at91_add_device_watchdog(void)
  663. {
  664. platform_device_register(&at91sam9260_wdt_device);
  665. }
  666. #else
  667. static void __init at91_add_device_watchdog(void) {}
  668. #endif
  669. /* --------------------------------------------------------------------
  670. * SSC -- Synchronous Serial Controller
  671. * -------------------------------------------------------------------- */
  672. #if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
  673. static u64 ssc_dmamask = DMA_BIT_MASK(32);
  674. static struct resource ssc_resources[] = {
  675. [0] = {
  676. .start = AT91SAM9260_BASE_SSC,
  677. .end = AT91SAM9260_BASE_SSC + SZ_16K - 1,
  678. .flags = IORESOURCE_MEM,
  679. },
  680. [1] = {
  681. .start = AT91SAM9260_ID_SSC,
  682. .end = AT91SAM9260_ID_SSC,
  683. .flags = IORESOURCE_IRQ,
  684. },
  685. };
  686. static struct platform_device at91sam9260_ssc_device = {
  687. .name = "ssc",
  688. .id = 0,
  689. .dev = {
  690. .dma_mask = &ssc_dmamask,
  691. .coherent_dma_mask = DMA_BIT_MASK(32),
  692. },
  693. .resource = ssc_resources,
  694. .num_resources = ARRAY_SIZE(ssc_resources),
  695. };
  696. static inline void configure_ssc_pins(unsigned pins)
  697. {
  698. if (pins & ATMEL_SSC_TF)
  699. at91_set_A_periph(AT91_PIN_PB17, 1);
  700. if (pins & ATMEL_SSC_TK)
  701. at91_set_A_periph(AT91_PIN_PB16, 1);
  702. if (pins & ATMEL_SSC_TD)
  703. at91_set_A_periph(AT91_PIN_PB18, 1);
  704. if (pins & ATMEL_SSC_RD)
  705. at91_set_A_periph(AT91_PIN_PB19, 1);
  706. if (pins & ATMEL_SSC_RK)
  707. at91_set_A_periph(AT91_PIN_PB20, 1);
  708. if (pins & ATMEL_SSC_RF)
  709. at91_set_A_periph(AT91_PIN_PB21, 1);
  710. }
  711. /*
  712. * SSC controllers are accessed through library code, instead of any
  713. * kind of all-singing/all-dancing driver. For example one could be
  714. * used by a particular I2S audio codec's driver, while another one
  715. * on the same system might be used by a custom data capture driver.
  716. */
  717. void __init at91_add_device_ssc(unsigned id, unsigned pins)
  718. {
  719. struct platform_device *pdev;
  720. /*
  721. * NOTE: caller is responsible for passing information matching
  722. * "pins" to whatever will be using each particular controller.
  723. */
  724. switch (id) {
  725. case AT91SAM9260_ID_SSC:
  726. pdev = &at91sam9260_ssc_device;
  727. configure_ssc_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 = AT91SAM9260_BASE_DBGU,
  744. .end = AT91SAM9260_BASE_DBGU + SZ_512 - 1,
  745. .flags = IORESOURCE_MEM,
  746. },
  747. [1] = {
  748. .start = AT91_ID_SYS,
  749. .end = 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 at91sam9260_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_PB14, 0); /* DRXD */
  772. at91_set_A_periph(AT91_PIN_PB15, 1); /* DTXD */
  773. }
  774. static struct resource uart0_resources[] = {
  775. [0] = {
  776. .start = AT91SAM9260_BASE_US0,
  777. .end = AT91SAM9260_BASE_US0 + SZ_16K - 1,
  778. .flags = IORESOURCE_MEM,
  779. },
  780. [1] = {
  781. .start = AT91SAM9260_ID_US0,
  782. .end = AT91SAM9260_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 at91sam9260_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_PB4, 1); /* TXD0 */
  805. at91_set_A_periph(AT91_PIN_PB5, 0); /* RXD0 */
  806. if (pins & ATMEL_UART_RTS)
  807. at91_set_A_periph(AT91_PIN_PB26, 0); /* RTS0 */
  808. if (pins & ATMEL_UART_CTS)
  809. at91_set_A_periph(AT91_PIN_PB27, 0); /* CTS0 */
  810. if (pins & ATMEL_UART_DTR)
  811. at91_set_A_periph(AT91_PIN_PB24, 0); /* DTR0 */
  812. if (pins & ATMEL_UART_DSR)
  813. at91_set_A_periph(AT91_PIN_PB22, 0); /* DSR0 */
  814. if (pins & ATMEL_UART_DCD)
  815. at91_set_A_periph(AT91_PIN_PB23, 0); /* DCD0 */
  816. if (pins & ATMEL_UART_RI)
  817. at91_set_A_periph(AT91_PIN_PB25, 0); /* RI0 */
  818. }
  819. static struct resource uart1_resources[] = {
  820. [0] = {
  821. .start = AT91SAM9260_BASE_US1,
  822. .end = AT91SAM9260_BASE_US1 + SZ_16K - 1,
  823. .flags = IORESOURCE_MEM,
  824. },
  825. [1] = {
  826. .start = AT91SAM9260_ID_US1,
  827. .end = AT91SAM9260_ID_US1,
  828. .flags = IORESOURCE_IRQ,
  829. },
  830. };
  831. static struct atmel_uart_data uart1_data = {
  832. .use_dma_tx = 1,
  833. .use_dma_rx = 1,
  834. };
  835. static u64 uart1_dmamask = DMA_BIT_MASK(32);
  836. static struct platform_device at91sam9260_uart1_device = {
  837. .name = "atmel_usart",
  838. .id = 2,
  839. .dev = {
  840. .dma_mask = &uart1_dmamask,
  841. .coherent_dma_mask = DMA_BIT_MASK(32),
  842. .platform_data = &uart1_data,
  843. },
  844. .resource = uart1_resources,
  845. .num_resources = ARRAY_SIZE(uart1_resources),
  846. };
  847. static inline void configure_usart1_pins(unsigned pins)
  848. {
  849. at91_set_A_periph(AT91_PIN_PB6, 1); /* TXD1 */
  850. at91_set_A_periph(AT91_PIN_PB7, 0); /* RXD1 */
  851. if (pins & ATMEL_UART_RTS)
  852. at91_set_A_periph(AT91_PIN_PB28, 0); /* RTS1 */
  853. if (pins & ATMEL_UART_CTS)
  854. at91_set_A_periph(AT91_PIN_PB29, 0); /* CTS1 */
  855. }
  856. static struct resource uart2_resources[] = {
  857. [0] = {
  858. .start = AT91SAM9260_BASE_US2,
  859. .end = AT91SAM9260_BASE_US2 + SZ_16K - 1,
  860. .flags = IORESOURCE_MEM,
  861. },
  862. [1] = {
  863. .start = AT91SAM9260_ID_US2,
  864. .end = AT91SAM9260_ID_US2,
  865. .flags = IORESOURCE_IRQ,
  866. },
  867. };
  868. static struct atmel_uart_data uart2_data = {
  869. .use_dma_tx = 1,
  870. .use_dma_rx = 1,
  871. };
  872. static u64 uart2_dmamask = DMA_BIT_MASK(32);
  873. static struct platform_device at91sam9260_uart2_device = {
  874. .name = "atmel_usart",
  875. .id = 3,
  876. .dev = {
  877. .dma_mask = &uart2_dmamask,
  878. .coherent_dma_mask = DMA_BIT_MASK(32),
  879. .platform_data = &uart2_data,
  880. },
  881. .resource = uart2_resources,
  882. .num_resources = ARRAY_SIZE(uart2_resources),
  883. };
  884. static inline void configure_usart2_pins(unsigned pins)
  885. {
  886. at91_set_A_periph(AT91_PIN_PB8, 1); /* TXD2 */
  887. at91_set_A_periph(AT91_PIN_PB9, 0); /* RXD2 */
  888. if (pins & ATMEL_UART_RTS)
  889. at91_set_A_periph(AT91_PIN_PA4, 0); /* RTS2 */
  890. if (pins & ATMEL_UART_CTS)
  891. at91_set_A_periph(AT91_PIN_PA5, 0); /* CTS2 */
  892. }
  893. static struct resource uart3_resources[] = {
  894. [0] = {
  895. .start = AT91SAM9260_BASE_US3,
  896. .end = AT91SAM9260_BASE_US3 + SZ_16K - 1,
  897. .flags = IORESOURCE_MEM,
  898. },
  899. [1] = {
  900. .start = AT91SAM9260_ID_US3,
  901. .end = AT91SAM9260_ID_US3,
  902. .flags = IORESOURCE_IRQ,
  903. },
  904. };
  905. static struct atmel_uart_data uart3_data = {
  906. .use_dma_tx = 1,
  907. .use_dma_rx = 1,
  908. };
  909. static u64 uart3_dmamask = DMA_BIT_MASK(32);
  910. static struct platform_device at91sam9260_uart3_device = {
  911. .name = "atmel_usart",
  912. .id = 4,
  913. .dev = {
  914. .dma_mask = &uart3_dmamask,
  915. .coherent_dma_mask = DMA_BIT_MASK(32),
  916. .platform_data = &uart3_data,
  917. },
  918. .resource = uart3_resources,
  919. .num_resources = ARRAY_SIZE(uart3_resources),
  920. };
  921. static inline void configure_usart3_pins(unsigned pins)
  922. {
  923. at91_set_A_periph(AT91_PIN_PB10, 1); /* TXD3 */
  924. at91_set_A_periph(AT91_PIN_PB11, 0); /* RXD3 */
  925. if (pins & ATMEL_UART_RTS)
  926. at91_set_B_periph(AT91_PIN_PC8, 0); /* RTS3 */
  927. if (pins & ATMEL_UART_CTS)
  928. at91_set_B_periph(AT91_PIN_PC10, 0); /* CTS3 */
  929. }
  930. static struct resource uart4_resources[] = {
  931. [0] = {
  932. .start = AT91SAM9260_BASE_US4,
  933. .end = AT91SAM9260_BASE_US4 + SZ_16K - 1,
  934. .flags = IORESOURCE_MEM,
  935. },
  936. [1] = {
  937. .start = AT91SAM9260_ID_US4,
  938. .end = AT91SAM9260_ID_US4,
  939. .flags = IORESOURCE_IRQ,
  940. },
  941. };
  942. static struct atmel_uart_data uart4_data = {
  943. .use_dma_tx = 1,
  944. .use_dma_rx = 1,
  945. };
  946. static u64 uart4_dmamask = DMA_BIT_MASK(32);
  947. static struct platform_device at91sam9260_uart4_device = {
  948. .name = "atmel_usart",
  949. .id = 5,
  950. .dev = {
  951. .dma_mask = &uart4_dmamask,
  952. .coherent_dma_mask = DMA_BIT_MASK(32),
  953. .platform_data = &uart4_data,
  954. },
  955. .resource = uart4_resources,
  956. .num_resources = ARRAY_SIZE(uart4_resources),
  957. };
  958. static inline void configure_usart4_pins(void)
  959. {
  960. at91_set_B_periph(AT91_PIN_PA31, 1); /* TXD4 */
  961. at91_set_B_periph(AT91_PIN_PA30, 0); /* RXD4 */
  962. }
  963. static struct resource uart5_resources[] = {
  964. [0] = {
  965. .start = AT91SAM9260_BASE_US5,
  966. .end = AT91SAM9260_BASE_US5 + SZ_16K - 1,
  967. .flags = IORESOURCE_MEM,
  968. },
  969. [1] = {
  970. .start = AT91SAM9260_ID_US5,
  971. .end = AT91SAM9260_ID_US5,
  972. .flags = IORESOURCE_IRQ,
  973. },
  974. };
  975. static struct atmel_uart_data uart5_data = {
  976. .use_dma_tx = 1,
  977. .use_dma_rx = 1,
  978. };
  979. static u64 uart5_dmamask = DMA_BIT_MASK(32);
  980. static struct platform_device at91sam9260_uart5_device = {
  981. .name = "atmel_usart",
  982. .id = 6,
  983. .dev = {
  984. .dma_mask = &uart5_dmamask,
  985. .coherent_dma_mask = DMA_BIT_MASK(32),
  986. .platform_data = &uart5_data,
  987. },
  988. .resource = uart5_resources,
  989. .num_resources = ARRAY_SIZE(uart5_resources),
  990. };
  991. static inline void configure_usart5_pins(void)
  992. {
  993. at91_set_A_periph(AT91_PIN_PB12, 1); /* TXD5 */
  994. at91_set_A_periph(AT91_PIN_PB13, 0); /* RXD5 */
  995. }
  996. static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
  997. struct platform_device *atmel_default_console_device; /* the serial console device */
  998. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
  999. {
  1000. struct platform_device *pdev;
  1001. struct atmel_uart_data *pdata;
  1002. switch (id) {
  1003. case 0: /* DBGU */
  1004. pdev = &at91sam9260_dbgu_device;
  1005. configure_dbgu_pins();
  1006. break;
  1007. case AT91SAM9260_ID_US0:
  1008. pdev = &at91sam9260_uart0_device;
  1009. configure_usart0_pins(pins);
  1010. break;
  1011. case AT91SAM9260_ID_US1:
  1012. pdev = &at91sam9260_uart1_device;
  1013. configure_usart1_pins(pins);
  1014. break;
  1015. case AT91SAM9260_ID_US2:
  1016. pdev = &at91sam9260_uart2_device;
  1017. configure_usart2_pins(pins);
  1018. break;
  1019. case AT91SAM9260_ID_US3:
  1020. pdev = &at91sam9260_uart3_device;
  1021. configure_usart3_pins(pins);
  1022. break;
  1023. case AT91SAM9260_ID_US4:
  1024. pdev = &at91sam9260_uart4_device;
  1025. configure_usart4_pins();
  1026. break;
  1027. case AT91SAM9260_ID_US5:
  1028. pdev = &at91sam9260_uart5_device;
  1029. configure_usart5_pins();
  1030. break;
  1031. default:
  1032. return;
  1033. }
  1034. pdata = pdev->dev.platform_data;
  1035. pdata->num = portnr; /* update to mapped ID */
  1036. if (portnr < ATMEL_MAX_UART)
  1037. at91_uarts[portnr] = pdev;
  1038. }
  1039. void __init at91_set_serial_console(unsigned portnr)
  1040. {
  1041. if (portnr < ATMEL_MAX_UART) {
  1042. atmel_default_console_device = at91_uarts[portnr];
  1043. at91sam9260_set_console_clock(at91_uarts[portnr]->id);
  1044. }
  1045. }
  1046. void __init at91_add_device_serial(void)
  1047. {
  1048. int i;
  1049. for (i = 0; i < ATMEL_MAX_UART; i++) {
  1050. if (at91_uarts[i])
  1051. platform_device_register(at91_uarts[i]);
  1052. }
  1053. if (!atmel_default_console_device)
  1054. printk(KERN_INFO "AT91: No default serial console defined.\n");
  1055. }
  1056. #else
  1057. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
  1058. void __init at91_set_serial_console(unsigned portnr) {}
  1059. void __init at91_add_device_serial(void) {}
  1060. #endif
  1061. /* --------------------------------------------------------------------
  1062. * CF/IDE
  1063. * -------------------------------------------------------------------- */
  1064. #if defined(CONFIG_BLK_DEV_IDE_AT91) || defined(CONFIG_BLK_DEV_IDE_AT91_MODULE) || \
  1065. defined(CONFIG_PATA_AT91) || defined(CONFIG_PATA_AT91_MODULE) || \
  1066. defined(CONFIG_AT91_CF) || defined(CONFIG_AT91_CF_MODULE)
  1067. static struct at91_cf_data cf0_data;
  1068. static struct resource cf0_resources[] = {
  1069. [0] = {
  1070. .start = AT91_CHIPSELECT_4,
  1071. .end = AT91_CHIPSELECT_4 + SZ_256M - 1,
  1072. .flags = IORESOURCE_MEM,
  1073. }
  1074. };
  1075. static struct platform_device cf0_device = {
  1076. .id = 0,
  1077. .dev = {
  1078. .platform_data = &cf0_data,
  1079. },
  1080. .resource = cf0_resources,
  1081. .num_resources = ARRAY_SIZE(cf0_resources),
  1082. };
  1083. static struct at91_cf_data cf1_data;
  1084. static struct resource cf1_resources[] = {
  1085. [0] = {
  1086. .start = AT91_CHIPSELECT_5,
  1087. .end = AT91_CHIPSELECT_5 + SZ_256M - 1,
  1088. .flags = IORESOURCE_MEM,
  1089. }
  1090. };
  1091. static struct platform_device cf1_device = {
  1092. .id = 1,
  1093. .dev = {
  1094. .platform_data = &cf1_data,
  1095. },
  1096. .resource = cf1_resources,
  1097. .num_resources = ARRAY_SIZE(cf1_resources),
  1098. };
  1099. void __init at91_add_device_cf(struct at91_cf_data *data)
  1100. {
  1101. struct platform_device *pdev;
  1102. unsigned long csa;
  1103. if (!data)
  1104. return;
  1105. csa = at91_matrix_read(AT91_MATRIX_EBICSA);
  1106. switch (data->chipselect) {
  1107. case 4:
  1108. at91_set_multi_drive(AT91_PIN_PC8, 0);
  1109. at91_set_A_periph(AT91_PIN_PC8, 0);
  1110. csa |= AT91_MATRIX_CS4A_SMC_CF1;
  1111. cf0_data = *data;
  1112. pdev = &cf0_device;
  1113. break;
  1114. case 5:
  1115. at91_set_multi_drive(AT91_PIN_PC9, 0);
  1116. at91_set_A_periph(AT91_PIN_PC9, 0);
  1117. csa |= AT91_MATRIX_CS5A_SMC_CF2;
  1118. cf1_data = *data;
  1119. pdev = &cf1_device;
  1120. break;
  1121. default:
  1122. printk(KERN_ERR "AT91 CF: bad chip-select requested (%u)\n",
  1123. data->chipselect);
  1124. return;
  1125. }
  1126. at91_matrix_write(AT91_MATRIX_EBICSA, csa);
  1127. if (gpio_is_valid(data->rst_pin)) {
  1128. at91_set_multi_drive(data->rst_pin, 0);
  1129. at91_set_gpio_output(data->rst_pin, 1);
  1130. }
  1131. if (gpio_is_valid(data->irq_pin)) {
  1132. at91_set_gpio_input(data->irq_pin, 0);
  1133. at91_set_deglitch(data->irq_pin, 1);
  1134. }
  1135. if (gpio_is_valid(data->det_pin)) {
  1136. at91_set_gpio_input(data->det_pin, 0);
  1137. at91_set_deglitch(data->det_pin, 1);
  1138. }
  1139. at91_set_B_periph(AT91_PIN_PC6, 0); /* CFCE1 */
  1140. at91_set_B_periph(AT91_PIN_PC7, 0); /* CFCE2 */
  1141. at91_set_A_periph(AT91_PIN_PC10, 0); /* CFRNW */
  1142. at91_set_A_periph(AT91_PIN_PC15, 1); /* NWAIT */
  1143. if (data->flags & AT91_CF_TRUE_IDE)
  1144. #if defined(CONFIG_PATA_AT91) || defined(CONFIG_PATA_AT91_MODULE)
  1145. pdev->name = "pata_at91";
  1146. #elif defined(CONFIG_BLK_DEV_IDE_AT91) || defined(CONFIG_BLK_DEV_IDE_AT91_MODULE)
  1147. pdev->name = "at91_ide";
  1148. #else
  1149. #warning "board requires AT91_CF_TRUE_IDE: enable either at91_ide or pata_at91"
  1150. #endif
  1151. else
  1152. pdev->name = "at91_cf";
  1153. platform_device_register(pdev);
  1154. }
  1155. #else
  1156. void __init at91_add_device_cf(struct at91_cf_data * data) {}
  1157. #endif
  1158. /* -------------------------------------------------------------------- */
  1159. /*
  1160. * These devices are always present and don't need any board-specific
  1161. * setup.
  1162. */
  1163. static int __init at91_add_standard_devices(void)
  1164. {
  1165. at91_add_device_rtt();
  1166. at91_add_device_watchdog();
  1167. at91_add_device_tc();
  1168. return 0;
  1169. }
  1170. arch_initcall(at91_add_standard_devices);