at91sam9260_devices.c 32 KB

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