at91sam9260_devices.c 29 KB

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