at572d940hf_devices.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964
  1. /*
  2. * arch/arm/mach-at91/at572d940hf_devices.c
  3. *
  4. * Copyright (C) 2008 Atmel Antonio R. Costa <costa.antonior@gmail.com>
  5. * Copyright (C) 2005 Thibaut VARENE <varenet@parisc-linux.org>
  6. * Copyright (C) 2005 David Brownell
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. */
  23. #include <asm/mach/arch.h>
  24. #include <asm/mach/map.h>
  25. #include <linux/dma-mapping.h>
  26. #include <linux/platform_device.h>
  27. #include <mach/board.h>
  28. #include <mach/gpio.h>
  29. #include <mach/at572d940hf.h>
  30. #include <mach/at572d940hf_matrix.h>
  31. #include <mach/at91sam9_smc.h>
  32. #include "generic.h"
  33. #include "sam9_smc.h"
  34. /* --------------------------------------------------------------------
  35. * USB Host
  36. * -------------------------------------------------------------------- */
  37. #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
  38. static u64 ohci_dmamask = DMA_BIT_MASK(32);
  39. static struct at91_usbh_data usbh_data;
  40. static struct resource usbh_resources[] = {
  41. [0] = {
  42. .start = AT572D940HF_UHP_BASE,
  43. .end = AT572D940HF_UHP_BASE + SZ_1M - 1,
  44. .flags = IORESOURCE_MEM,
  45. },
  46. [1] = {
  47. .start = AT572D940HF_ID_UHP,
  48. .end = AT572D940HF_ID_UHP,
  49. .flags = IORESOURCE_IRQ,
  50. },
  51. };
  52. static struct platform_device at572d940hf_usbh_device = {
  53. .name = "at91_ohci",
  54. .id = -1,
  55. .dev = {
  56. .dma_mask = &ohci_dmamask,
  57. .coherent_dma_mask = DMA_BIT_MASK(32),
  58. .platform_data = &usbh_data,
  59. },
  60. .resource = usbh_resources,
  61. .num_resources = ARRAY_SIZE(usbh_resources),
  62. };
  63. void __init at91_add_device_usbh(struct at91_usbh_data *data)
  64. {
  65. if (!data)
  66. return;
  67. usbh_data = *data;
  68. platform_device_register(&at572d940hf_usbh_device);
  69. }
  70. #else
  71. void __init at91_add_device_usbh(struct at91_usbh_data *data) {}
  72. #endif
  73. /* --------------------------------------------------------------------
  74. * USB Device (Gadget)
  75. * -------------------------------------------------------------------- */
  76. #ifdef CONFIG_USB_GADGET_AT91
  77. static struct at91_udc_data udc_data;
  78. static struct resource udc_resources[] = {
  79. [0] = {
  80. .start = AT572D940HF_BASE_UDP,
  81. .end = AT572D940HF_BASE_UDP + SZ_16K - 1,
  82. .flags = IORESOURCE_MEM,
  83. },
  84. [1] = {
  85. .start = AT572D940HF_ID_UDP,
  86. .end = AT572D940HF_ID_UDP,
  87. .flags = IORESOURCE_IRQ,
  88. },
  89. };
  90. static struct platform_device at572d940hf_udc_device = {
  91. .name = "at91_udc",
  92. .id = -1,
  93. .dev = {
  94. .platform_data = &udc_data,
  95. },
  96. .resource = udc_resources,
  97. .num_resources = ARRAY_SIZE(udc_resources),
  98. };
  99. void __init at91_add_device_udc(struct at91_udc_data *data)
  100. {
  101. if (!data)
  102. return;
  103. if (data->vbus_pin) {
  104. at91_set_gpio_input(data->vbus_pin, 0);
  105. at91_set_deglitch(data->vbus_pin, 1);
  106. }
  107. /* Pullup pin is handled internally */
  108. udc_data = *data;
  109. platform_device_register(&at572d940hf_udc_device);
  110. }
  111. #else
  112. void __init at91_add_device_udc(struct at91_udc_data *data) {}
  113. #endif
  114. /* --------------------------------------------------------------------
  115. * Ethernet
  116. * -------------------------------------------------------------------- */
  117. #if defined(CONFIG_MACB) || defined(CONFIG_MACB_MODULE)
  118. static u64 eth_dmamask = DMA_BIT_MASK(32);
  119. static struct at91_eth_data eth_data;
  120. static struct resource eth_resources[] = {
  121. [0] = {
  122. .start = AT572D940HF_BASE_EMAC,
  123. .end = AT572D940HF_BASE_EMAC + SZ_16K - 1,
  124. .flags = IORESOURCE_MEM,
  125. },
  126. [1] = {
  127. .start = AT572D940HF_ID_EMAC,
  128. .end = AT572D940HF_ID_EMAC,
  129. .flags = IORESOURCE_IRQ,
  130. },
  131. };
  132. static struct platform_device at572d940hf_eth_device = {
  133. .name = "macb",
  134. .id = -1,
  135. .dev = {
  136. .dma_mask = &eth_dmamask,
  137. .coherent_dma_mask = DMA_BIT_MASK(32),
  138. .platform_data = &eth_data,
  139. },
  140. .resource = eth_resources,
  141. .num_resources = ARRAY_SIZE(eth_resources),
  142. };
  143. void __init at91_add_device_eth(struct at91_eth_data *data)
  144. {
  145. if (!data)
  146. return;
  147. if (data->phy_irq_pin) {
  148. at91_set_gpio_input(data->phy_irq_pin, 0);
  149. at91_set_deglitch(data->phy_irq_pin, 1);
  150. }
  151. /* Only RMII is supported */
  152. data->is_rmii = 1;
  153. /* Pins used for RMII */
  154. at91_set_A_periph(AT91_PIN_PA16, 0); /* ETXCK_EREFCK */
  155. at91_set_A_periph(AT91_PIN_PA17, 0); /* ERXDV */
  156. at91_set_A_periph(AT91_PIN_PA18, 0); /* ERX0 */
  157. at91_set_A_periph(AT91_PIN_PA19, 0); /* ERX1 */
  158. at91_set_A_periph(AT91_PIN_PA20, 0); /* ERXER */
  159. at91_set_A_periph(AT91_PIN_PA23, 0); /* ETXEN */
  160. at91_set_A_periph(AT91_PIN_PA21, 0); /* ETX0 */
  161. at91_set_A_periph(AT91_PIN_PA22, 0); /* ETX1 */
  162. at91_set_A_periph(AT91_PIN_PA13, 0); /* EMDIO */
  163. at91_set_A_periph(AT91_PIN_PA14, 0); /* EMDC */
  164. eth_data = *data;
  165. platform_device_register(&at572d940hf_eth_device);
  166. }
  167. #else
  168. void __init at91_add_device_eth(struct at91_eth_data *data) {}
  169. #endif
  170. /* --------------------------------------------------------------------
  171. * MMC / SD
  172. * -------------------------------------------------------------------- */
  173. #if defined(CONFIG_MMC_AT91) || defined(CONFIG_MMC_AT91_MODULE)
  174. static u64 mmc_dmamask = DMA_BIT_MASK(32);
  175. static struct at91_mmc_data mmc_data;
  176. static struct resource mmc_resources[] = {
  177. [0] = {
  178. .start = AT572D940HF_BASE_MCI,
  179. .end = AT572D940HF_BASE_MCI + SZ_16K - 1,
  180. .flags = IORESOURCE_MEM,
  181. },
  182. [1] = {
  183. .start = AT572D940HF_ID_MCI,
  184. .end = AT572D940HF_ID_MCI,
  185. .flags = IORESOURCE_IRQ,
  186. },
  187. };
  188. static struct platform_device at572d940hf_mmc_device = {
  189. .name = "at91_mci",
  190. .id = -1,
  191. .dev = {
  192. .dma_mask = &mmc_dmamask,
  193. .coherent_dma_mask = DMA_BIT_MASK(32),
  194. .platform_data = &mmc_data,
  195. },
  196. .resource = mmc_resources,
  197. .num_resources = ARRAY_SIZE(mmc_resources),
  198. };
  199. void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data)
  200. {
  201. if (!data)
  202. return;
  203. /* input/irq */
  204. if (data->det_pin) {
  205. at91_set_gpio_input(data->det_pin, 1);
  206. at91_set_deglitch(data->det_pin, 1);
  207. }
  208. if (data->wp_pin)
  209. at91_set_gpio_input(data->wp_pin, 1);
  210. if (data->vcc_pin)
  211. at91_set_gpio_output(data->vcc_pin, 0);
  212. /* CLK */
  213. at91_set_A_periph(AT91_PIN_PC22, 0);
  214. /* CMD */
  215. at91_set_A_periph(AT91_PIN_PC23, 1);
  216. /* DAT0, maybe DAT1..DAT3 */
  217. at91_set_A_periph(AT91_PIN_PC24, 1);
  218. if (data->wire4) {
  219. at91_set_A_periph(AT91_PIN_PC25, 1);
  220. at91_set_A_periph(AT91_PIN_PC26, 1);
  221. at91_set_A_periph(AT91_PIN_PC27, 1);
  222. }
  223. mmc_data = *data;
  224. platform_device_register(&at572d940hf_mmc_device);
  225. }
  226. #else
  227. void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data) {}
  228. #endif
  229. /* --------------------------------------------------------------------
  230. * NAND / SmartMedia
  231. * -------------------------------------------------------------------- */
  232. #if defined(CONFIG_MTD_NAND_ATMEL) || defined(CONFIG_MTD_NAND_ATMEL_MODULE)
  233. static struct atmel_nand_data nand_data;
  234. #define NAND_BASE AT91_CHIPSELECT_3
  235. static struct resource nand_resources[] = {
  236. {
  237. .start = NAND_BASE,
  238. .end = NAND_BASE + SZ_256M - 1,
  239. .flags = IORESOURCE_MEM,
  240. }
  241. };
  242. static struct platform_device at572d940hf_nand_device = {
  243. .name = "atmel_nand",
  244. .id = -1,
  245. .dev = {
  246. .platform_data = &nand_data,
  247. },
  248. .resource = nand_resources,
  249. .num_resources = ARRAY_SIZE(nand_resources),
  250. };
  251. void __init at91_add_device_nand(struct atmel_nand_data *data)
  252. {
  253. unsigned long csa;
  254. if (!data)
  255. return;
  256. csa = at91_sys_read(AT91_MATRIX_EBICSA);
  257. at91_sys_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_CS3A_SMC_SMARTMEDIA);
  258. /* enable pin */
  259. if (data->enable_pin)
  260. at91_set_gpio_output(data->enable_pin, 1);
  261. /* ready/busy pin */
  262. if (data->rdy_pin)
  263. at91_set_gpio_input(data->rdy_pin, 1);
  264. /* card detect pin */
  265. if (data->det_pin)
  266. at91_set_gpio_input(data->det_pin, 1);
  267. at91_set_A_periph(AT91_PIN_PB28, 0); /* A[22] */
  268. at91_set_B_periph(AT91_PIN_PA28, 0); /* NANDOE */
  269. at91_set_B_periph(AT91_PIN_PA29, 0); /* NANDWE */
  270. nand_data = *data;
  271. platform_device_register(&at572d940hf_nand_device);
  272. }
  273. #else
  274. void __init at91_add_device_nand(struct atmel_nand_data *data) {}
  275. #endif
  276. /* --------------------------------------------------------------------
  277. * TWI (i2c)
  278. * -------------------------------------------------------------------- */
  279. /*
  280. * Prefer the GPIO code since the TWI controller isn't robust
  281. * (gets overruns and underruns under load) and can only issue
  282. * repeated STARTs in one scenario (the driver doesn't yet handle them).
  283. */
  284. #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
  285. static struct i2c_gpio_platform_data pdata = {
  286. .sda_pin = AT91_PIN_PC7,
  287. .sda_is_open_drain = 1,
  288. .scl_pin = AT91_PIN_PC8,
  289. .scl_is_open_drain = 1,
  290. .udelay = 2, /* ~100 kHz */
  291. };
  292. static struct platform_device at572d940hf_twi_device {
  293. .name = "i2c-gpio",
  294. .id = -1,
  295. .dev.platform_data = &pdata,
  296. };
  297. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  298. {
  299. at91_set_GPIO_periph(AT91_PIN_PC7, 1); /* TWD (SDA) */
  300. at91_set_multi_drive(AT91_PIN_PC7, 1);
  301. at91_set_GPIO_periph(AT91_PIN_PA8, 1); /* TWCK (SCL) */
  302. at91_set_multi_drive(AT91_PIN_PC8, 1);
  303. i2c_register_board_info(0, devices, nr_devices);
  304. platform_device_register(&at572d940hf_twi_device);
  305. }
  306. #elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
  307. static struct resource twi0_resources[] = {
  308. [0] = {
  309. .start = AT572D940HF_BASE_TWI0,
  310. .end = AT572D940HF_BASE_TWI0 + SZ_16K - 1,
  311. .flags = IORESOURCE_MEM,
  312. },
  313. [1] = {
  314. .start = AT572D940HF_ID_TWI0,
  315. .end = AT572D940HF_ID_TWI0,
  316. .flags = IORESOURCE_IRQ,
  317. },
  318. };
  319. static struct platform_device at572d940hf_twi0_device = {
  320. .name = "at91_i2c",
  321. .id = 0,
  322. .resource = twi0_resources,
  323. .num_resources = ARRAY_SIZE(twi0_resources),
  324. };
  325. static struct resource twi1_resources[] = {
  326. [0] = {
  327. .start = AT572D940HF_BASE_TWI1,
  328. .end = AT572D940HF_BASE_TWI1 + SZ_16K - 1,
  329. .flags = IORESOURCE_MEM,
  330. },
  331. [1] = {
  332. .start = AT572D940HF_ID_TWI1,
  333. .end = AT572D940HF_ID_TWI1,
  334. .flags = IORESOURCE_IRQ,
  335. },
  336. };
  337. static struct platform_device at572d940hf_twi1_device = {
  338. .name = "at91_i2c",
  339. .id = 1,
  340. .resource = twi1_resources,
  341. .num_resources = ARRAY_SIZE(twi1_resources),
  342. };
  343. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  344. {
  345. /* pins used for TWI0 interface */
  346. at91_set_A_periph(AT91_PIN_PC7, 0); /* TWD */
  347. at91_set_multi_drive(AT91_PIN_PC7, 1);
  348. at91_set_A_periph(AT91_PIN_PC8, 0); /* TWCK */
  349. at91_set_multi_drive(AT91_PIN_PC8, 1);
  350. /* pins used for TWI1 interface */
  351. at91_set_A_periph(AT91_PIN_PC20, 0); /* TWD */
  352. at91_set_multi_drive(AT91_PIN_PC20, 1);
  353. at91_set_A_periph(AT91_PIN_PC21, 0); /* TWCK */
  354. at91_set_multi_drive(AT91_PIN_PC21, 1);
  355. i2c_register_board_info(0, devices, nr_devices);
  356. platform_device_register(&at572d940hf_twi0_device);
  357. platform_device_register(&at572d940hf_twi1_device);
  358. }
  359. #else
  360. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {}
  361. #endif
  362. /* --------------------------------------------------------------------
  363. * SPI
  364. * -------------------------------------------------------------------- */
  365. #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
  366. static u64 spi_dmamask = DMA_BIT_MASK(32);
  367. static struct resource spi0_resources[] = {
  368. [0] = {
  369. .start = AT572D940HF_BASE_SPI0,
  370. .end = AT572D940HF_BASE_SPI0 + SZ_16K - 1,
  371. .flags = IORESOURCE_MEM,
  372. },
  373. [1] = {
  374. .start = AT572D940HF_ID_SPI0,
  375. .end = AT572D940HF_ID_SPI0,
  376. .flags = IORESOURCE_IRQ,
  377. },
  378. };
  379. static struct platform_device at572d940hf_spi0_device = {
  380. .name = "atmel_spi",
  381. .id = 0,
  382. .dev = {
  383. .dma_mask = &spi_dmamask,
  384. .coherent_dma_mask = DMA_BIT_MASK(32),
  385. },
  386. .resource = spi0_resources,
  387. .num_resources = ARRAY_SIZE(spi0_resources),
  388. };
  389. static const unsigned spi0_standard_cs[4] = { AT91_PIN_PA3, AT91_PIN_PA4, AT91_PIN_PA5, AT91_PIN_PA6 };
  390. static struct resource spi1_resources[] = {
  391. [0] = {
  392. .start = AT572D940HF_BASE_SPI1,
  393. .end = AT572D940HF_BASE_SPI1 + SZ_16K - 1,
  394. .flags = IORESOURCE_MEM,
  395. },
  396. [1] = {
  397. .start = AT572D940HF_ID_SPI1,
  398. .end = AT572D940HF_ID_SPI1,
  399. .flags = IORESOURCE_IRQ,
  400. },
  401. };
  402. static struct platform_device at572d940hf_spi1_device = {
  403. .name = "atmel_spi",
  404. .id = 1,
  405. .dev = {
  406. .dma_mask = &spi_dmamask,
  407. .coherent_dma_mask = DMA_BIT_MASK(32),
  408. },
  409. .resource = spi1_resources,
  410. .num_resources = ARRAY_SIZE(spi1_resources),
  411. };
  412. static const unsigned spi1_standard_cs[4] = { AT91_PIN_PC3, AT91_PIN_PC4, AT91_PIN_PC5, AT91_PIN_PC6 };
  413. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
  414. {
  415. int i;
  416. unsigned long cs_pin;
  417. short enable_spi0 = 0;
  418. short enable_spi1 = 0;
  419. /* Choose SPI chip-selects */
  420. for (i = 0; i < nr_devices; i++) {
  421. if (devices[i].controller_data)
  422. cs_pin = (unsigned long) devices[i].controller_data;
  423. else if (devices[i].bus_num == 0)
  424. cs_pin = spi0_standard_cs[devices[i].chip_select];
  425. else
  426. cs_pin = spi1_standard_cs[devices[i].chip_select];
  427. if (devices[i].bus_num == 0)
  428. enable_spi0 = 1;
  429. else
  430. enable_spi1 = 1;
  431. /* enable chip-select pin */
  432. at91_set_gpio_output(cs_pin, 1);
  433. /* pass chip-select pin to driver */
  434. devices[i].controller_data = (void *) cs_pin;
  435. }
  436. spi_register_board_info(devices, nr_devices);
  437. /* Configure SPI bus(es) */
  438. if (enable_spi0) {
  439. at91_set_A_periph(AT91_PIN_PA0, 0); /* SPI0_MISO */
  440. at91_set_A_periph(AT91_PIN_PA1, 0); /* SPI0_MOSI */
  441. at91_set_A_periph(AT91_PIN_PA2, 0); /* SPI0_SPCK */
  442. platform_device_register(&at572d940hf_spi0_device);
  443. }
  444. if (enable_spi1) {
  445. at91_set_A_periph(AT91_PIN_PC0, 0); /* SPI1_MISO */
  446. at91_set_A_periph(AT91_PIN_PC1, 0); /* SPI1_MOSI */
  447. at91_set_A_periph(AT91_PIN_PC2, 0); /* SPI1_SPCK */
  448. platform_device_register(&at572d940hf_spi1_device);
  449. }
  450. }
  451. #else
  452. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
  453. #endif
  454. /* --------------------------------------------------------------------
  455. * Timer/Counter blocks
  456. * -------------------------------------------------------------------- */
  457. #ifdef CONFIG_ATMEL_TCLIB
  458. static struct resource tcb_resources[] = {
  459. [0] = {
  460. .start = AT572D940HF_BASE_TCB,
  461. .end = AT572D940HF_BASE_TCB + SZ_16K - 1,
  462. .flags = IORESOURCE_MEM,
  463. },
  464. [1] = {
  465. .start = AT572D940HF_ID_TC0,
  466. .end = AT572D940HF_ID_TC0,
  467. .flags = IORESOURCE_IRQ,
  468. },
  469. [2] = {
  470. .start = AT572D940HF_ID_TC1,
  471. .end = AT572D940HF_ID_TC1,
  472. .flags = IORESOURCE_IRQ,
  473. },
  474. [3] = {
  475. .start = AT572D940HF_ID_TC2,
  476. .end = AT572D940HF_ID_TC2,
  477. .flags = IORESOURCE_IRQ,
  478. },
  479. };
  480. static struct platform_device at572d940hf_tcb_device = {
  481. .name = "atmel_tcb",
  482. .id = 0,
  483. .resource = tcb_resources,
  484. .num_resources = ARRAY_SIZE(tcb_resources),
  485. };
  486. static void __init at91_add_device_tc(void)
  487. {
  488. platform_device_register(&at572d940hf_tcb_device);
  489. }
  490. #else
  491. static void __init at91_add_device_tc(void) { }
  492. #endif
  493. /* --------------------------------------------------------------------
  494. * RTT
  495. * -------------------------------------------------------------------- */
  496. static struct resource rtt_resources[] = {
  497. {
  498. .start = AT91_BASE_SYS + AT91_RTT,
  499. .end = AT91_BASE_SYS + AT91_RTT + SZ_16 - 1,
  500. .flags = IORESOURCE_MEM,
  501. }
  502. };
  503. static struct platform_device at572d940hf_rtt_device = {
  504. .name = "at91_rtt",
  505. .id = 0,
  506. .resource = rtt_resources,
  507. .num_resources = ARRAY_SIZE(rtt_resources),
  508. };
  509. static void __init at91_add_device_rtt(void)
  510. {
  511. platform_device_register(&at572d940hf_rtt_device);
  512. }
  513. /* --------------------------------------------------------------------
  514. * Watchdog
  515. * -------------------------------------------------------------------- */
  516. #if defined(CONFIG_AT91SAM9X_WATCHDOG) || defined(CONFIG_AT91SAM9X_WATCHDOG_MODULE)
  517. static struct platform_device at572d940hf_wdt_device = {
  518. .name = "at91_wdt",
  519. .id = -1,
  520. .num_resources = 0,
  521. };
  522. static void __init at91_add_device_watchdog(void)
  523. {
  524. platform_device_register(&at572d940hf_wdt_device);
  525. }
  526. #else
  527. static void __init at91_add_device_watchdog(void) {}
  528. #endif
  529. /* --------------------------------------------------------------------
  530. * UART
  531. * -------------------------------------------------------------------- */
  532. #if defined(CONFIG_SERIAL_ATMEL)
  533. static struct resource dbgu_resources[] = {
  534. [0] = {
  535. .start = AT91_VA_BASE_SYS + AT91_DBGU,
  536. .end = AT91_VA_BASE_SYS + AT91_DBGU + SZ_512 - 1,
  537. .flags = IORESOURCE_MEM,
  538. },
  539. [1] = {
  540. .start = AT91_ID_SYS,
  541. .end = AT91_ID_SYS,
  542. .flags = IORESOURCE_IRQ,
  543. },
  544. };
  545. static struct atmel_uart_data dbgu_data = {
  546. .use_dma_tx = 0,
  547. .use_dma_rx = 0, /* DBGU not capable of receive DMA */
  548. .regs = (void __iomem *)(AT91_VA_BASE_SYS + AT91_DBGU),
  549. };
  550. static u64 dbgu_dmamask = DMA_BIT_MASK(32);
  551. static struct platform_device at572d940hf_dbgu_device = {
  552. .name = "atmel_usart",
  553. .id = 0,
  554. .dev = {
  555. .dma_mask = &dbgu_dmamask,
  556. .coherent_dma_mask = DMA_BIT_MASK(32),
  557. .platform_data = &dbgu_data,
  558. },
  559. .resource = dbgu_resources,
  560. .num_resources = ARRAY_SIZE(dbgu_resources),
  561. };
  562. static inline void configure_dbgu_pins(void)
  563. {
  564. at91_set_A_periph(AT91_PIN_PC31, 1); /* DTXD */
  565. at91_set_A_periph(AT91_PIN_PC30, 0); /* DRXD */
  566. }
  567. static struct resource uart0_resources[] = {
  568. [0] = {
  569. .start = AT572D940HF_BASE_US0,
  570. .end = AT572D940HF_BASE_US0 + SZ_16K - 1,
  571. .flags = IORESOURCE_MEM,
  572. },
  573. [1] = {
  574. .start = AT572D940HF_ID_US0,
  575. .end = AT572D940HF_ID_US0,
  576. .flags = IORESOURCE_IRQ,
  577. },
  578. };
  579. static struct atmel_uart_data uart0_data = {
  580. .use_dma_tx = 1,
  581. .use_dma_rx = 1,
  582. };
  583. static u64 uart0_dmamask = DMA_BIT_MASK(32);
  584. static struct platform_device at572d940hf_uart0_device = {
  585. .name = "atmel_usart",
  586. .id = 1,
  587. .dev = {
  588. .dma_mask = &uart0_dmamask,
  589. .coherent_dma_mask = DMA_BIT_MASK(32),
  590. .platform_data = &uart0_data,
  591. },
  592. .resource = uart0_resources,
  593. .num_resources = ARRAY_SIZE(uart0_resources),
  594. };
  595. static inline void configure_usart0_pins(unsigned pins)
  596. {
  597. at91_set_A_periph(AT91_PIN_PA8, 1); /* TXD0 */
  598. at91_set_A_periph(AT91_PIN_PA7, 0); /* RXD0 */
  599. if (pins & ATMEL_UART_RTS)
  600. at91_set_A_periph(AT91_PIN_PA10, 0); /* RTS0 */
  601. if (pins & ATMEL_UART_CTS)
  602. at91_set_A_periph(AT91_PIN_PA9, 0); /* CTS0 */
  603. }
  604. static struct resource uart1_resources[] = {
  605. [0] = {
  606. .start = AT572D940HF_BASE_US1,
  607. .end = AT572D940HF_BASE_US1 + SZ_16K - 1,
  608. .flags = IORESOURCE_MEM,
  609. },
  610. [1] = {
  611. .start = AT572D940HF_ID_US1,
  612. .end = AT572D940HF_ID_US1,
  613. .flags = IORESOURCE_IRQ,
  614. },
  615. };
  616. static struct atmel_uart_data uart1_data = {
  617. .use_dma_tx = 1,
  618. .use_dma_rx = 1,
  619. };
  620. static u64 uart1_dmamask = DMA_BIT_MASK(32);
  621. static struct platform_device at572d940hf_uart1_device = {
  622. .name = "atmel_usart",
  623. .id = 2,
  624. .dev = {
  625. .dma_mask = &uart1_dmamask,
  626. .coherent_dma_mask = DMA_BIT_MASK(32),
  627. .platform_data = &uart1_data,
  628. },
  629. .resource = uart1_resources,
  630. .num_resources = ARRAY_SIZE(uart1_resources),
  631. };
  632. static inline void configure_usart1_pins(unsigned pins)
  633. {
  634. at91_set_A_periph(AT91_PIN_PC10, 1); /* TXD1 */
  635. at91_set_A_periph(AT91_PIN_PC9 , 0); /* RXD1 */
  636. if (pins & ATMEL_UART_RTS)
  637. at91_set_A_periph(AT91_PIN_PC12, 0); /* RTS1 */
  638. if (pins & ATMEL_UART_CTS)
  639. at91_set_A_periph(AT91_PIN_PC11, 0); /* CTS1 */
  640. }
  641. static struct resource uart2_resources[] = {
  642. [0] = {
  643. .start = AT572D940HF_BASE_US2,
  644. .end = AT572D940HF_BASE_US2 + SZ_16K - 1,
  645. .flags = IORESOURCE_MEM,
  646. },
  647. [1] = {
  648. .start = AT572D940HF_ID_US2,
  649. .end = AT572D940HF_ID_US2,
  650. .flags = IORESOURCE_IRQ,
  651. },
  652. };
  653. static struct atmel_uart_data uart2_data = {
  654. .use_dma_tx = 1,
  655. .use_dma_rx = 1,
  656. };
  657. static u64 uart2_dmamask = DMA_BIT_MASK(32);
  658. static struct platform_device at572d940hf_uart2_device = {
  659. .name = "atmel_usart",
  660. .id = 3,
  661. .dev = {
  662. .dma_mask = &uart2_dmamask,
  663. .coherent_dma_mask = DMA_BIT_MASK(32),
  664. .platform_data = &uart2_data,
  665. },
  666. .resource = uart2_resources,
  667. .num_resources = ARRAY_SIZE(uart2_resources),
  668. };
  669. static inline void configure_usart2_pins(unsigned pins)
  670. {
  671. at91_set_A_periph(AT91_PIN_PC15, 1); /* TXD2 */
  672. at91_set_A_periph(AT91_PIN_PC14, 0); /* RXD2 */
  673. if (pins & ATMEL_UART_RTS)
  674. at91_set_A_periph(AT91_PIN_PC17, 0); /* RTS2 */
  675. if (pins & ATMEL_UART_CTS)
  676. at91_set_A_periph(AT91_PIN_PC16, 0); /* CTS2 */
  677. }
  678. static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
  679. struct platform_device *atmel_default_console_device; /* the serial console device */
  680. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
  681. {
  682. struct platform_device *pdev;
  683. struct atmel_uart_data *pdata;
  684. switch (id) {
  685. case 0: /* DBGU */
  686. pdev = &at572d940hf_dbgu_device;
  687. configure_dbgu_pins();
  688. break;
  689. case AT572D940HF_ID_US0:
  690. pdev = &at572d940hf_uart0_device;
  691. configure_usart0_pins(pins);
  692. break;
  693. case AT572D940HF_ID_US1:
  694. pdev = &at572d940hf_uart1_device;
  695. configure_usart1_pins(pins);
  696. break;
  697. case AT572D940HF_ID_US2:
  698. pdev = &at572d940hf_uart2_device;
  699. configure_usart2_pins(pins);
  700. break;
  701. default:
  702. return;
  703. }
  704. pdata = pdev->dev.platform_data;
  705. pdata->num = portnr; /* update to mapped ID */
  706. if (portnr < ATMEL_MAX_UART)
  707. at91_uarts[portnr] = pdev;
  708. }
  709. void __init at91_set_serial_console(unsigned portnr)
  710. {
  711. if (portnr < ATMEL_MAX_UART) {
  712. atmel_default_console_device = at91_uarts[portnr];
  713. at572d940hf_set_console_clock(portnr);
  714. }
  715. }
  716. void __init at91_add_device_serial(void)
  717. {
  718. int i;
  719. for (i = 0; i < ATMEL_MAX_UART; i++) {
  720. if (at91_uarts[i])
  721. platform_device_register(at91_uarts[i]);
  722. }
  723. if (!atmel_default_console_device)
  724. printk(KERN_INFO "AT91: No default serial console defined.\n");
  725. }
  726. #else
  727. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
  728. void __init at91_set_serial_console(unsigned portnr) {}
  729. void __init at91_add_device_serial(void) {}
  730. #endif
  731. /* --------------------------------------------------------------------
  732. * mAgic
  733. * -------------------------------------------------------------------- */
  734. #ifdef CONFIG_MAGICV
  735. static struct resource mAgic_resources[] = {
  736. {
  737. .start = AT91_MAGIC_PM_BASE,
  738. .end = AT91_MAGIC_PM_BASE + AT91_MAGIC_PM_SIZE - 1,
  739. .flags = IORESOURCE_MEM,
  740. },
  741. {
  742. .start = AT91_MAGIC_DM_I_BASE,
  743. .end = AT91_MAGIC_DM_I_BASE + AT91_MAGIC_DM_I_SIZE - 1,
  744. .flags = IORESOURCE_MEM,
  745. },
  746. {
  747. .start = AT91_MAGIC_DM_F_BASE,
  748. .end = AT91_MAGIC_DM_F_BASE + AT91_MAGIC_DM_F_SIZE - 1,
  749. .flags = IORESOURCE_MEM,
  750. },
  751. {
  752. .start = AT91_MAGIC_DM_DB_BASE,
  753. .end = AT91_MAGIC_DM_DB_BASE + AT91_MAGIC_DM_DB_SIZE - 1,
  754. .flags = IORESOURCE_MEM,
  755. },
  756. {
  757. .start = AT91_MAGIC_REGS_BASE,
  758. .end = AT91_MAGIC_REGS_BASE + AT91_MAGIC_REGS_SIZE - 1,
  759. .flags = IORESOURCE_MEM,
  760. },
  761. {
  762. .start = AT91_MAGIC_EXTPAGE_BASE,
  763. .end = AT91_MAGIC_EXTPAGE_BASE + AT91_MAGIC_EXTPAGE_SIZE - 1,
  764. .flags = IORESOURCE_MEM,
  765. },
  766. {
  767. .start = AT572D940HF_ID_MSIRQ0,
  768. .end = AT572D940HF_ID_MSIRQ0,
  769. .flags = IORESOURCE_IRQ,
  770. },
  771. {
  772. .start = AT572D940HF_ID_MHALT,
  773. .end = AT572D940HF_ID_MHALT,
  774. .flags = IORESOURCE_IRQ,
  775. },
  776. {
  777. .start = AT572D940HF_ID_MEXC,
  778. .end = AT572D940HF_ID_MEXC,
  779. .flags = IORESOURCE_IRQ,
  780. },
  781. {
  782. .start = AT572D940HF_ID_MEDMA,
  783. .end = AT572D940HF_ID_MEDMA,
  784. .flags = IORESOURCE_IRQ,
  785. },
  786. };
  787. static struct platform_device mAgic_device = {
  788. .name = "mAgic",
  789. .id = -1,
  790. .num_resources = ARRAY_SIZE(mAgic_resources),
  791. .resource = mAgic_resources,
  792. };
  793. void __init at91_add_device_mAgic(void)
  794. {
  795. platform_device_register(&mAgic_device);
  796. }
  797. #else
  798. void __init at91_add_device_mAgic(void) {}
  799. #endif
  800. /* -------------------------------------------------------------------- */
  801. /*
  802. * These devices are always present and don't need any board-specific
  803. * setup.
  804. */
  805. static int __init at91_add_standard_devices(void)
  806. {
  807. at91_add_device_rtt();
  808. at91_add_device_watchdog();
  809. at91_add_device_tc();
  810. return 0;
  811. }
  812. arch_initcall(at91_add_standard_devices);