at572d940hf_devices.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970
  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. at91_clock_associate("spi0_clk", &at572d940hf_spi0_device.dev, "spi_clk");
  443. platform_device_register(&at572d940hf_spi0_device);
  444. }
  445. if (enable_spi1) {
  446. at91_set_A_periph(AT91_PIN_PC0, 0); /* SPI1_MISO */
  447. at91_set_A_periph(AT91_PIN_PC1, 0); /* SPI1_MOSI */
  448. at91_set_A_periph(AT91_PIN_PC2, 0); /* SPI1_SPCK */
  449. at91_clock_associate("spi1_clk", &at572d940hf_spi1_device.dev, "spi_clk");
  450. platform_device_register(&at572d940hf_spi1_device);
  451. }
  452. }
  453. #else
  454. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
  455. #endif
  456. /* --------------------------------------------------------------------
  457. * Timer/Counter blocks
  458. * -------------------------------------------------------------------- */
  459. #ifdef CONFIG_ATMEL_TCLIB
  460. static struct resource tcb_resources[] = {
  461. [0] = {
  462. .start = AT572D940HF_BASE_TCB,
  463. .end = AT572D940HF_BASE_TCB + SZ_16K - 1,
  464. .flags = IORESOURCE_MEM,
  465. },
  466. [1] = {
  467. .start = AT572D940HF_ID_TC0,
  468. .end = AT572D940HF_ID_TC0,
  469. .flags = IORESOURCE_IRQ,
  470. },
  471. [2] = {
  472. .start = AT572D940HF_ID_TC1,
  473. .end = AT572D940HF_ID_TC1,
  474. .flags = IORESOURCE_IRQ,
  475. },
  476. [3] = {
  477. .start = AT572D940HF_ID_TC2,
  478. .end = AT572D940HF_ID_TC2,
  479. .flags = IORESOURCE_IRQ,
  480. },
  481. };
  482. static struct platform_device at572d940hf_tcb_device = {
  483. .name = "atmel_tcb",
  484. .id = 0,
  485. .resource = tcb_resources,
  486. .num_resources = ARRAY_SIZE(tcb_resources),
  487. };
  488. static void __init at91_add_device_tc(void)
  489. {
  490. /* this chip has a separate clock and irq for each TC channel */
  491. at91_clock_associate("tc0_clk", &at572d940hf_tcb_device.dev, "t0_clk");
  492. at91_clock_associate("tc1_clk", &at572d940hf_tcb_device.dev, "t1_clk");
  493. at91_clock_associate("tc2_clk", &at572d940hf_tcb_device.dev, "t2_clk");
  494. platform_device_register(&at572d940hf_tcb_device);
  495. }
  496. #else
  497. static void __init at91_add_device_tc(void) { }
  498. #endif
  499. /* --------------------------------------------------------------------
  500. * RTT
  501. * -------------------------------------------------------------------- */
  502. static struct resource rtt_resources[] = {
  503. {
  504. .start = AT91_BASE_SYS + AT91_RTT,
  505. .end = AT91_BASE_SYS + AT91_RTT + SZ_16 - 1,
  506. .flags = IORESOURCE_MEM,
  507. }
  508. };
  509. static struct platform_device at572d940hf_rtt_device = {
  510. .name = "at91_rtt",
  511. .id = 0,
  512. .resource = rtt_resources,
  513. .num_resources = ARRAY_SIZE(rtt_resources),
  514. };
  515. static void __init at91_add_device_rtt(void)
  516. {
  517. platform_device_register(&at572d940hf_rtt_device);
  518. }
  519. /* --------------------------------------------------------------------
  520. * Watchdog
  521. * -------------------------------------------------------------------- */
  522. #if defined(CONFIG_AT91SAM9X_WATCHDOG) || defined(CONFIG_AT91SAM9X_WATCHDOG_MODULE)
  523. static struct platform_device at572d940hf_wdt_device = {
  524. .name = "at91_wdt",
  525. .id = -1,
  526. .num_resources = 0,
  527. };
  528. static void __init at91_add_device_watchdog(void)
  529. {
  530. platform_device_register(&at572d940hf_wdt_device);
  531. }
  532. #else
  533. static void __init at91_add_device_watchdog(void) {}
  534. #endif
  535. /* --------------------------------------------------------------------
  536. * UART
  537. * -------------------------------------------------------------------- */
  538. #if defined(CONFIG_SERIAL_ATMEL)
  539. static struct resource dbgu_resources[] = {
  540. [0] = {
  541. .start = AT91_VA_BASE_SYS + AT91_DBGU,
  542. .end = AT91_VA_BASE_SYS + AT91_DBGU + SZ_512 - 1,
  543. .flags = IORESOURCE_MEM,
  544. },
  545. [1] = {
  546. .start = AT91_ID_SYS,
  547. .end = AT91_ID_SYS,
  548. .flags = IORESOURCE_IRQ,
  549. },
  550. };
  551. static struct atmel_uart_data dbgu_data = {
  552. .use_dma_tx = 0,
  553. .use_dma_rx = 0, /* DBGU not capable of receive DMA */
  554. .regs = (void __iomem *)(AT91_VA_BASE_SYS + AT91_DBGU),
  555. };
  556. static u64 dbgu_dmamask = DMA_BIT_MASK(32);
  557. static struct platform_device at572d940hf_dbgu_device = {
  558. .name = "atmel_usart",
  559. .id = 0,
  560. .dev = {
  561. .dma_mask = &dbgu_dmamask,
  562. .coherent_dma_mask = DMA_BIT_MASK(32),
  563. .platform_data = &dbgu_data,
  564. },
  565. .resource = dbgu_resources,
  566. .num_resources = ARRAY_SIZE(dbgu_resources),
  567. };
  568. static inline void configure_dbgu_pins(void)
  569. {
  570. at91_set_A_periph(AT91_PIN_PC31, 1); /* DTXD */
  571. at91_set_A_periph(AT91_PIN_PC30, 0); /* DRXD */
  572. }
  573. static struct resource uart0_resources[] = {
  574. [0] = {
  575. .start = AT572D940HF_BASE_US0,
  576. .end = AT572D940HF_BASE_US0 + SZ_16K - 1,
  577. .flags = IORESOURCE_MEM,
  578. },
  579. [1] = {
  580. .start = AT572D940HF_ID_US0,
  581. .end = AT572D940HF_ID_US0,
  582. .flags = IORESOURCE_IRQ,
  583. },
  584. };
  585. static struct atmel_uart_data uart0_data = {
  586. .use_dma_tx = 1,
  587. .use_dma_rx = 1,
  588. };
  589. static u64 uart0_dmamask = DMA_BIT_MASK(32);
  590. static struct platform_device at572d940hf_uart0_device = {
  591. .name = "atmel_usart",
  592. .id = 1,
  593. .dev = {
  594. .dma_mask = &uart0_dmamask,
  595. .coherent_dma_mask = DMA_BIT_MASK(32),
  596. .platform_data = &uart0_data,
  597. },
  598. .resource = uart0_resources,
  599. .num_resources = ARRAY_SIZE(uart0_resources),
  600. };
  601. static inline void configure_usart0_pins(unsigned pins)
  602. {
  603. at91_set_A_periph(AT91_PIN_PA8, 1); /* TXD0 */
  604. at91_set_A_periph(AT91_PIN_PA7, 0); /* RXD0 */
  605. if (pins & ATMEL_UART_RTS)
  606. at91_set_A_periph(AT91_PIN_PA10, 0); /* RTS0 */
  607. if (pins & ATMEL_UART_CTS)
  608. at91_set_A_periph(AT91_PIN_PA9, 0); /* CTS0 */
  609. }
  610. static struct resource uart1_resources[] = {
  611. [0] = {
  612. .start = AT572D940HF_BASE_US1,
  613. .end = AT572D940HF_BASE_US1 + SZ_16K - 1,
  614. .flags = IORESOURCE_MEM,
  615. },
  616. [1] = {
  617. .start = AT572D940HF_ID_US1,
  618. .end = AT572D940HF_ID_US1,
  619. .flags = IORESOURCE_IRQ,
  620. },
  621. };
  622. static struct atmel_uart_data uart1_data = {
  623. .use_dma_tx = 1,
  624. .use_dma_rx = 1,
  625. };
  626. static u64 uart1_dmamask = DMA_BIT_MASK(32);
  627. static struct platform_device at572d940hf_uart1_device = {
  628. .name = "atmel_usart",
  629. .id = 2,
  630. .dev = {
  631. .dma_mask = &uart1_dmamask,
  632. .coherent_dma_mask = DMA_BIT_MASK(32),
  633. .platform_data = &uart1_data,
  634. },
  635. .resource = uart1_resources,
  636. .num_resources = ARRAY_SIZE(uart1_resources),
  637. };
  638. static inline void configure_usart1_pins(unsigned pins)
  639. {
  640. at91_set_A_periph(AT91_PIN_PC10, 1); /* TXD1 */
  641. at91_set_A_periph(AT91_PIN_PC9 , 0); /* RXD1 */
  642. if (pins & ATMEL_UART_RTS)
  643. at91_set_A_periph(AT91_PIN_PC12, 0); /* RTS1 */
  644. if (pins & ATMEL_UART_CTS)
  645. at91_set_A_periph(AT91_PIN_PC11, 0); /* CTS1 */
  646. }
  647. static struct resource uart2_resources[] = {
  648. [0] = {
  649. .start = AT572D940HF_BASE_US2,
  650. .end = AT572D940HF_BASE_US2 + SZ_16K - 1,
  651. .flags = IORESOURCE_MEM,
  652. },
  653. [1] = {
  654. .start = AT572D940HF_ID_US2,
  655. .end = AT572D940HF_ID_US2,
  656. .flags = IORESOURCE_IRQ,
  657. },
  658. };
  659. static struct atmel_uart_data uart2_data = {
  660. .use_dma_tx = 1,
  661. .use_dma_rx = 1,
  662. };
  663. static u64 uart2_dmamask = DMA_BIT_MASK(32);
  664. static struct platform_device at572d940hf_uart2_device = {
  665. .name = "atmel_usart",
  666. .id = 3,
  667. .dev = {
  668. .dma_mask = &uart2_dmamask,
  669. .coherent_dma_mask = DMA_BIT_MASK(32),
  670. .platform_data = &uart2_data,
  671. },
  672. .resource = uart2_resources,
  673. .num_resources = ARRAY_SIZE(uart2_resources),
  674. };
  675. static inline void configure_usart2_pins(unsigned pins)
  676. {
  677. at91_set_A_periph(AT91_PIN_PC15, 1); /* TXD2 */
  678. at91_set_A_periph(AT91_PIN_PC14, 0); /* RXD2 */
  679. if (pins & ATMEL_UART_RTS)
  680. at91_set_A_periph(AT91_PIN_PC17, 0); /* RTS2 */
  681. if (pins & ATMEL_UART_CTS)
  682. at91_set_A_periph(AT91_PIN_PC16, 0); /* CTS2 */
  683. }
  684. static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
  685. struct platform_device *atmel_default_console_device; /* the serial console device */
  686. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
  687. {
  688. struct platform_device *pdev;
  689. switch (id) {
  690. case 0: /* DBGU */
  691. pdev = &at572d940hf_dbgu_device;
  692. configure_dbgu_pins();
  693. at91_clock_associate("mck", &pdev->dev, "usart");
  694. break;
  695. case AT572D940HF_ID_US0:
  696. pdev = &at572d940hf_uart0_device;
  697. configure_usart0_pins(pins);
  698. at91_clock_associate("usart0_clk", &pdev->dev, "usart");
  699. break;
  700. case AT572D940HF_ID_US1:
  701. pdev = &at572d940hf_uart1_device;
  702. configure_usart1_pins(pins);
  703. at91_clock_associate("usart1_clk", &pdev->dev, "usart");
  704. break;
  705. case AT572D940HF_ID_US2:
  706. pdev = &at572d940hf_uart2_device;
  707. configure_usart2_pins(pins);
  708. at91_clock_associate("usart2_clk", &pdev->dev, "usart");
  709. break;
  710. default:
  711. return;
  712. }
  713. pdev->id = portnr; /* update to mapped ID */
  714. if (portnr < ATMEL_MAX_UART)
  715. at91_uarts[portnr] = pdev;
  716. }
  717. void __init at91_set_serial_console(unsigned portnr)
  718. {
  719. if (portnr < ATMEL_MAX_UART)
  720. atmel_default_console_device = at91_uarts[portnr];
  721. }
  722. void __init at91_add_device_serial(void)
  723. {
  724. int i;
  725. for (i = 0; i < ATMEL_MAX_UART; i++) {
  726. if (at91_uarts[i])
  727. platform_device_register(at91_uarts[i]);
  728. }
  729. if (!atmel_default_console_device)
  730. printk(KERN_INFO "AT91: No default serial console defined.\n");
  731. }
  732. #else
  733. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
  734. void __init at91_set_serial_console(unsigned portnr) {}
  735. void __init at91_add_device_serial(void) {}
  736. #endif
  737. /* --------------------------------------------------------------------
  738. * mAgic
  739. * -------------------------------------------------------------------- */
  740. #ifdef CONFIG_MAGICV
  741. static struct resource mAgic_resources[] = {
  742. {
  743. .start = AT91_MAGIC_PM_BASE,
  744. .end = AT91_MAGIC_PM_BASE + AT91_MAGIC_PM_SIZE - 1,
  745. .flags = IORESOURCE_MEM,
  746. },
  747. {
  748. .start = AT91_MAGIC_DM_I_BASE,
  749. .end = AT91_MAGIC_DM_I_BASE + AT91_MAGIC_DM_I_SIZE - 1,
  750. .flags = IORESOURCE_MEM,
  751. },
  752. {
  753. .start = AT91_MAGIC_DM_F_BASE,
  754. .end = AT91_MAGIC_DM_F_BASE + AT91_MAGIC_DM_F_SIZE - 1,
  755. .flags = IORESOURCE_MEM,
  756. },
  757. {
  758. .start = AT91_MAGIC_DM_DB_BASE,
  759. .end = AT91_MAGIC_DM_DB_BASE + AT91_MAGIC_DM_DB_SIZE - 1,
  760. .flags = IORESOURCE_MEM,
  761. },
  762. {
  763. .start = AT91_MAGIC_REGS_BASE,
  764. .end = AT91_MAGIC_REGS_BASE + AT91_MAGIC_REGS_SIZE - 1,
  765. .flags = IORESOURCE_MEM,
  766. },
  767. {
  768. .start = AT91_MAGIC_EXTPAGE_BASE,
  769. .end = AT91_MAGIC_EXTPAGE_BASE + AT91_MAGIC_EXTPAGE_SIZE - 1,
  770. .flags = IORESOURCE_MEM,
  771. },
  772. {
  773. .start = AT572D940HF_ID_MSIRQ0,
  774. .end = AT572D940HF_ID_MSIRQ0,
  775. .flags = IORESOURCE_IRQ,
  776. },
  777. {
  778. .start = AT572D940HF_ID_MHALT,
  779. .end = AT572D940HF_ID_MHALT,
  780. .flags = IORESOURCE_IRQ,
  781. },
  782. {
  783. .start = AT572D940HF_ID_MEXC,
  784. .end = AT572D940HF_ID_MEXC,
  785. .flags = IORESOURCE_IRQ,
  786. },
  787. {
  788. .start = AT572D940HF_ID_MEDMA,
  789. .end = AT572D940HF_ID_MEDMA,
  790. .flags = IORESOURCE_IRQ,
  791. },
  792. };
  793. static struct platform_device mAgic_device = {
  794. .name = "mAgic",
  795. .id = -1,
  796. .num_resources = ARRAY_SIZE(mAgic_resources),
  797. .resource = mAgic_resources,
  798. };
  799. void __init at91_add_device_mAgic(void)
  800. {
  801. platform_device_register(&mAgic_device);
  802. }
  803. #else
  804. void __init at91_add_device_mAgic(void) {}
  805. #endif
  806. /* -------------------------------------------------------------------- */
  807. /*
  808. * These devices are always present and don't need any board-specific
  809. * setup.
  810. */
  811. static int __init at91_add_standard_devices(void)
  812. {
  813. at91_add_device_rtt();
  814. at91_add_device_watchdog();
  815. at91_add_device_tc();
  816. return 0;
  817. }
  818. arch_initcall(at91_add_standard_devices);