at91sam9261_devices.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062
  1. /*
  2. * arch/arm/mach-at91/at91sam9261_devices.c
  3. *
  4. * Copyright (C) 2005 Thibaut VARENE <varenet@parisc-linux.org>
  5. * Copyright (C) 2005 David Brownell
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. */
  13. #include <asm/mach/arch.h>
  14. #include <asm/mach/map.h>
  15. #include <linux/dma-mapping.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/i2c-gpio.h>
  18. #include <linux/fb.h>
  19. #include <video/atmel_lcdc.h>
  20. #include <mach/board.h>
  21. #include <mach/gpio.h>
  22. #include <mach/at91sam9261.h>
  23. #include <mach/at91sam9261_matrix.h>
  24. #include <mach/at91sam9_smc.h>
  25. #include "generic.h"
  26. /* --------------------------------------------------------------------
  27. * USB Host
  28. * -------------------------------------------------------------------- */
  29. #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
  30. static u64 ohci_dmamask = DMA_BIT_MASK(32);
  31. static struct at91_usbh_data usbh_data;
  32. static struct resource usbh_resources[] = {
  33. [0] = {
  34. .start = AT91SAM9261_UHP_BASE,
  35. .end = AT91SAM9261_UHP_BASE + SZ_1M - 1,
  36. .flags = IORESOURCE_MEM,
  37. },
  38. [1] = {
  39. .start = AT91SAM9261_ID_UHP,
  40. .end = AT91SAM9261_ID_UHP,
  41. .flags = IORESOURCE_IRQ,
  42. },
  43. };
  44. static struct platform_device at91sam9261_usbh_device = {
  45. .name = "at91_ohci",
  46. .id = -1,
  47. .dev = {
  48. .dma_mask = &ohci_dmamask,
  49. .coherent_dma_mask = DMA_BIT_MASK(32),
  50. .platform_data = &usbh_data,
  51. },
  52. .resource = usbh_resources,
  53. .num_resources = ARRAY_SIZE(usbh_resources),
  54. };
  55. void __init at91_add_device_usbh(struct at91_usbh_data *data)
  56. {
  57. if (!data)
  58. return;
  59. usbh_data = *data;
  60. platform_device_register(&at91sam9261_usbh_device);
  61. }
  62. #else
  63. void __init at91_add_device_usbh(struct at91_usbh_data *data) {}
  64. #endif
  65. /* --------------------------------------------------------------------
  66. * USB Device (Gadget)
  67. * -------------------------------------------------------------------- */
  68. #ifdef CONFIG_USB_GADGET_AT91
  69. static struct at91_udc_data udc_data;
  70. static struct resource udc_resources[] = {
  71. [0] = {
  72. .start = AT91SAM9261_BASE_UDP,
  73. .end = AT91SAM9261_BASE_UDP + SZ_16K - 1,
  74. .flags = IORESOURCE_MEM,
  75. },
  76. [1] = {
  77. .start = AT91SAM9261_ID_UDP,
  78. .end = AT91SAM9261_ID_UDP,
  79. .flags = IORESOURCE_IRQ,
  80. },
  81. };
  82. static struct platform_device at91sam9261_udc_device = {
  83. .name = "at91_udc",
  84. .id = -1,
  85. .dev = {
  86. .platform_data = &udc_data,
  87. },
  88. .resource = udc_resources,
  89. .num_resources = ARRAY_SIZE(udc_resources),
  90. };
  91. void __init at91_add_device_udc(struct at91_udc_data *data)
  92. {
  93. if (!data)
  94. return;
  95. if (data->vbus_pin) {
  96. at91_set_gpio_input(data->vbus_pin, 0);
  97. at91_set_deglitch(data->vbus_pin, 1);
  98. }
  99. /* Pullup pin is handled internally by USB device peripheral */
  100. udc_data = *data;
  101. platform_device_register(&at91sam9261_udc_device);
  102. }
  103. #else
  104. void __init at91_add_device_udc(struct at91_udc_data *data) {}
  105. #endif
  106. /* --------------------------------------------------------------------
  107. * MMC / SD
  108. * -------------------------------------------------------------------- */
  109. #if defined(CONFIG_MMC_AT91) || defined(CONFIG_MMC_AT91_MODULE)
  110. static u64 mmc_dmamask = DMA_BIT_MASK(32);
  111. static struct at91_mmc_data mmc_data;
  112. static struct resource mmc_resources[] = {
  113. [0] = {
  114. .start = AT91SAM9261_BASE_MCI,
  115. .end = AT91SAM9261_BASE_MCI + SZ_16K - 1,
  116. .flags = IORESOURCE_MEM,
  117. },
  118. [1] = {
  119. .start = AT91SAM9261_ID_MCI,
  120. .end = AT91SAM9261_ID_MCI,
  121. .flags = IORESOURCE_IRQ,
  122. },
  123. };
  124. static struct platform_device at91sam9261_mmc_device = {
  125. .name = "at91_mci",
  126. .id = -1,
  127. .dev = {
  128. .dma_mask = &mmc_dmamask,
  129. .coherent_dma_mask = DMA_BIT_MASK(32),
  130. .platform_data = &mmc_data,
  131. },
  132. .resource = mmc_resources,
  133. .num_resources = ARRAY_SIZE(mmc_resources),
  134. };
  135. void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data)
  136. {
  137. if (!data)
  138. return;
  139. /* input/irq */
  140. if (data->det_pin) {
  141. at91_set_gpio_input(data->det_pin, 1);
  142. at91_set_deglitch(data->det_pin, 1);
  143. }
  144. if (data->wp_pin)
  145. at91_set_gpio_input(data->wp_pin, 1);
  146. if (data->vcc_pin)
  147. at91_set_gpio_output(data->vcc_pin, 0);
  148. /* CLK */
  149. at91_set_B_periph(AT91_PIN_PA2, 0);
  150. /* CMD */
  151. at91_set_B_periph(AT91_PIN_PA1, 1);
  152. /* DAT0, maybe DAT1..DAT3 */
  153. at91_set_B_periph(AT91_PIN_PA0, 1);
  154. if (data->wire4) {
  155. at91_set_B_periph(AT91_PIN_PA4, 1);
  156. at91_set_B_periph(AT91_PIN_PA5, 1);
  157. at91_set_B_periph(AT91_PIN_PA6, 1);
  158. }
  159. mmc_data = *data;
  160. platform_device_register(&at91sam9261_mmc_device);
  161. }
  162. #else
  163. void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data) {}
  164. #endif
  165. /* --------------------------------------------------------------------
  166. * NAND / SmartMedia
  167. * -------------------------------------------------------------------- */
  168. #if defined(CONFIG_MTD_NAND_ATMEL) || defined(CONFIG_MTD_NAND_ATMEL_MODULE)
  169. static struct atmel_nand_data nand_data;
  170. #define NAND_BASE AT91_CHIPSELECT_3
  171. static struct resource nand_resources[] = {
  172. {
  173. .start = NAND_BASE,
  174. .end = NAND_BASE + SZ_256M - 1,
  175. .flags = IORESOURCE_MEM,
  176. }
  177. };
  178. static struct platform_device atmel_nand_device = {
  179. .name = "atmel_nand",
  180. .id = -1,
  181. .dev = {
  182. .platform_data = &nand_data,
  183. },
  184. .resource = nand_resources,
  185. .num_resources = ARRAY_SIZE(nand_resources),
  186. };
  187. void __init at91_add_device_nand(struct atmel_nand_data *data)
  188. {
  189. unsigned long csa;
  190. if (!data)
  191. return;
  192. csa = at91_sys_read(AT91_MATRIX_EBICSA);
  193. at91_sys_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_CS3A_SMC_SMARTMEDIA);
  194. /* enable pin */
  195. if (data->enable_pin)
  196. at91_set_gpio_output(data->enable_pin, 1);
  197. /* ready/busy pin */
  198. if (data->rdy_pin)
  199. at91_set_gpio_input(data->rdy_pin, 1);
  200. /* card detect pin */
  201. if (data->det_pin)
  202. at91_set_gpio_input(data->det_pin, 1);
  203. at91_set_A_periph(AT91_PIN_PC0, 0); /* NANDOE */
  204. at91_set_A_periph(AT91_PIN_PC1, 0); /* NANDWE */
  205. nand_data = *data;
  206. platform_device_register(&atmel_nand_device);
  207. }
  208. #else
  209. void __init at91_add_device_nand(struct atmel_nand_data *data) {}
  210. #endif
  211. /* --------------------------------------------------------------------
  212. * TWI (i2c)
  213. * -------------------------------------------------------------------- */
  214. /*
  215. * Prefer the GPIO code since the TWI controller isn't robust
  216. * (gets overruns and underruns under load) and can only issue
  217. * repeated STARTs in one scenario (the driver doesn't yet handle them).
  218. */
  219. #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
  220. static struct i2c_gpio_platform_data pdata = {
  221. .sda_pin = AT91_PIN_PA7,
  222. .sda_is_open_drain = 1,
  223. .scl_pin = AT91_PIN_PA8,
  224. .scl_is_open_drain = 1,
  225. .udelay = 2, /* ~100 kHz */
  226. };
  227. static struct platform_device at91sam9261_twi_device = {
  228. .name = "i2c-gpio",
  229. .id = -1,
  230. .dev.platform_data = &pdata,
  231. };
  232. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  233. {
  234. at91_set_GPIO_periph(AT91_PIN_PA7, 1); /* TWD (SDA) */
  235. at91_set_multi_drive(AT91_PIN_PA7, 1);
  236. at91_set_GPIO_periph(AT91_PIN_PA8, 1); /* TWCK (SCL) */
  237. at91_set_multi_drive(AT91_PIN_PA8, 1);
  238. i2c_register_board_info(0, devices, nr_devices);
  239. platform_device_register(&at91sam9261_twi_device);
  240. }
  241. #elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
  242. static struct resource twi_resources[] = {
  243. [0] = {
  244. .start = AT91SAM9261_BASE_TWI,
  245. .end = AT91SAM9261_BASE_TWI + SZ_16K - 1,
  246. .flags = IORESOURCE_MEM,
  247. },
  248. [1] = {
  249. .start = AT91SAM9261_ID_TWI,
  250. .end = AT91SAM9261_ID_TWI,
  251. .flags = IORESOURCE_IRQ,
  252. },
  253. };
  254. static struct platform_device at91sam9261_twi_device = {
  255. .name = "at91_i2c",
  256. .id = -1,
  257. .resource = twi_resources,
  258. .num_resources = ARRAY_SIZE(twi_resources),
  259. };
  260. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  261. {
  262. /* pins used for TWI interface */
  263. at91_set_A_periph(AT91_PIN_PA7, 0); /* TWD */
  264. at91_set_multi_drive(AT91_PIN_PA7, 1);
  265. at91_set_A_periph(AT91_PIN_PA8, 0); /* TWCK */
  266. at91_set_multi_drive(AT91_PIN_PA8, 1);
  267. i2c_register_board_info(0, devices, nr_devices);
  268. platform_device_register(&at91sam9261_twi_device);
  269. }
  270. #else
  271. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {}
  272. #endif
  273. /* --------------------------------------------------------------------
  274. * SPI
  275. * -------------------------------------------------------------------- */
  276. #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
  277. static u64 spi_dmamask = DMA_BIT_MASK(32);
  278. static struct resource spi0_resources[] = {
  279. [0] = {
  280. .start = AT91SAM9261_BASE_SPI0,
  281. .end = AT91SAM9261_BASE_SPI0 + SZ_16K - 1,
  282. .flags = IORESOURCE_MEM,
  283. },
  284. [1] = {
  285. .start = AT91SAM9261_ID_SPI0,
  286. .end = AT91SAM9261_ID_SPI0,
  287. .flags = IORESOURCE_IRQ,
  288. },
  289. };
  290. static struct platform_device at91sam9261_spi0_device = {
  291. .name = "atmel_spi",
  292. .id = 0,
  293. .dev = {
  294. .dma_mask = &spi_dmamask,
  295. .coherent_dma_mask = DMA_BIT_MASK(32),
  296. },
  297. .resource = spi0_resources,
  298. .num_resources = ARRAY_SIZE(spi0_resources),
  299. };
  300. static const unsigned spi0_standard_cs[4] = { AT91_PIN_PA3, AT91_PIN_PA4, AT91_PIN_PA5, AT91_PIN_PA6 };
  301. static struct resource spi1_resources[] = {
  302. [0] = {
  303. .start = AT91SAM9261_BASE_SPI1,
  304. .end = AT91SAM9261_BASE_SPI1 + SZ_16K - 1,
  305. .flags = IORESOURCE_MEM,
  306. },
  307. [1] = {
  308. .start = AT91SAM9261_ID_SPI1,
  309. .end = AT91SAM9261_ID_SPI1,
  310. .flags = IORESOURCE_IRQ,
  311. },
  312. };
  313. static struct platform_device at91sam9261_spi1_device = {
  314. .name = "atmel_spi",
  315. .id = 1,
  316. .dev = {
  317. .dma_mask = &spi_dmamask,
  318. .coherent_dma_mask = DMA_BIT_MASK(32),
  319. },
  320. .resource = spi1_resources,
  321. .num_resources = ARRAY_SIZE(spi1_resources),
  322. };
  323. static const unsigned spi1_standard_cs[4] = { AT91_PIN_PB28, AT91_PIN_PA24, AT91_PIN_PA25, AT91_PIN_PA26 };
  324. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
  325. {
  326. int i;
  327. unsigned long cs_pin;
  328. short enable_spi0 = 0;
  329. short enable_spi1 = 0;
  330. /* Choose SPI chip-selects */
  331. for (i = 0; i < nr_devices; i++) {
  332. if (devices[i].controller_data)
  333. cs_pin = (unsigned long) devices[i].controller_data;
  334. else if (devices[i].bus_num == 0)
  335. cs_pin = spi0_standard_cs[devices[i].chip_select];
  336. else
  337. cs_pin = spi1_standard_cs[devices[i].chip_select];
  338. if (devices[i].bus_num == 0)
  339. enable_spi0 = 1;
  340. else
  341. enable_spi1 = 1;
  342. /* enable chip-select pin */
  343. at91_set_gpio_output(cs_pin, 1);
  344. /* pass chip-select pin to driver */
  345. devices[i].controller_data = (void *) cs_pin;
  346. }
  347. spi_register_board_info(devices, nr_devices);
  348. /* Configure SPI bus(es) */
  349. if (enable_spi0) {
  350. at91_set_A_periph(AT91_PIN_PA0, 0); /* SPI0_MISO */
  351. at91_set_A_periph(AT91_PIN_PA1, 0); /* SPI0_MOSI */
  352. at91_set_A_periph(AT91_PIN_PA2, 0); /* SPI0_SPCK */
  353. at91_clock_associate("spi0_clk", &at91sam9261_spi0_device.dev, "spi_clk");
  354. platform_device_register(&at91sam9261_spi0_device);
  355. }
  356. if (enable_spi1) {
  357. at91_set_A_periph(AT91_PIN_PB30, 0); /* SPI1_MISO */
  358. at91_set_A_periph(AT91_PIN_PB31, 0); /* SPI1_MOSI */
  359. at91_set_A_periph(AT91_PIN_PB29, 0); /* SPI1_SPCK */
  360. at91_clock_associate("spi1_clk", &at91sam9261_spi1_device.dev, "spi_clk");
  361. platform_device_register(&at91sam9261_spi1_device);
  362. }
  363. }
  364. #else
  365. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
  366. #endif
  367. /* --------------------------------------------------------------------
  368. * LCD Controller
  369. * -------------------------------------------------------------------- */
  370. #if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
  371. static u64 lcdc_dmamask = DMA_BIT_MASK(32);
  372. static struct atmel_lcdfb_info lcdc_data;
  373. static struct resource lcdc_resources[] = {
  374. [0] = {
  375. .start = AT91SAM9261_LCDC_BASE,
  376. .end = AT91SAM9261_LCDC_BASE + SZ_4K - 1,
  377. .flags = IORESOURCE_MEM,
  378. },
  379. [1] = {
  380. .start = AT91SAM9261_ID_LCDC,
  381. .end = AT91SAM9261_ID_LCDC,
  382. .flags = IORESOURCE_IRQ,
  383. },
  384. #if defined(CONFIG_FB_INTSRAM)
  385. [2] = {
  386. .start = AT91SAM9261_SRAM_BASE,
  387. .end = AT91SAM9261_SRAM_BASE + AT91SAM9261_SRAM_SIZE - 1,
  388. .flags = IORESOURCE_MEM,
  389. },
  390. #endif
  391. };
  392. static struct platform_device at91_lcdc_device = {
  393. .name = "atmel_lcdfb",
  394. .id = 0,
  395. .dev = {
  396. .dma_mask = &lcdc_dmamask,
  397. .coherent_dma_mask = DMA_BIT_MASK(32),
  398. .platform_data = &lcdc_data,
  399. },
  400. .resource = lcdc_resources,
  401. .num_resources = ARRAY_SIZE(lcdc_resources),
  402. };
  403. void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data)
  404. {
  405. if (!data) {
  406. return;
  407. }
  408. #if defined(CONFIG_FB_ATMEL_STN)
  409. at91_set_A_periph(AT91_PIN_PB0, 0); /* LCDVSYNC */
  410. at91_set_A_periph(AT91_PIN_PB1, 0); /* LCDHSYNC */
  411. at91_set_A_periph(AT91_PIN_PB2, 0); /* LCDDOTCK */
  412. at91_set_A_periph(AT91_PIN_PB3, 0); /* LCDDEN */
  413. at91_set_A_periph(AT91_PIN_PB4, 0); /* LCDCC */
  414. at91_set_A_periph(AT91_PIN_PB5, 0); /* LCDD0 */
  415. at91_set_A_periph(AT91_PIN_PB6, 0); /* LCDD1 */
  416. at91_set_A_periph(AT91_PIN_PB7, 0); /* LCDD2 */
  417. at91_set_A_periph(AT91_PIN_PB8, 0); /* LCDD3 */
  418. #else
  419. at91_set_A_periph(AT91_PIN_PB1, 0); /* LCDHSYNC */
  420. at91_set_A_periph(AT91_PIN_PB2, 0); /* LCDDOTCK */
  421. at91_set_A_periph(AT91_PIN_PB3, 0); /* LCDDEN */
  422. at91_set_A_periph(AT91_PIN_PB4, 0); /* LCDCC */
  423. at91_set_A_periph(AT91_PIN_PB7, 0); /* LCDD2 */
  424. at91_set_A_periph(AT91_PIN_PB8, 0); /* LCDD3 */
  425. at91_set_A_periph(AT91_PIN_PB9, 0); /* LCDD4 */
  426. at91_set_A_periph(AT91_PIN_PB10, 0); /* LCDD5 */
  427. at91_set_A_periph(AT91_PIN_PB11, 0); /* LCDD6 */
  428. at91_set_A_periph(AT91_PIN_PB12, 0); /* LCDD7 */
  429. at91_set_A_periph(AT91_PIN_PB15, 0); /* LCDD10 */
  430. at91_set_A_periph(AT91_PIN_PB16, 0); /* LCDD11 */
  431. at91_set_A_periph(AT91_PIN_PB17, 0); /* LCDD12 */
  432. at91_set_A_periph(AT91_PIN_PB18, 0); /* LCDD13 */
  433. at91_set_A_periph(AT91_PIN_PB19, 0); /* LCDD14 */
  434. at91_set_A_periph(AT91_PIN_PB20, 0); /* LCDD15 */
  435. at91_set_B_periph(AT91_PIN_PB23, 0); /* LCDD18 */
  436. at91_set_B_periph(AT91_PIN_PB24, 0); /* LCDD19 */
  437. at91_set_B_periph(AT91_PIN_PB25, 0); /* LCDD20 */
  438. at91_set_B_periph(AT91_PIN_PB26, 0); /* LCDD21 */
  439. at91_set_B_periph(AT91_PIN_PB27, 0); /* LCDD22 */
  440. at91_set_B_periph(AT91_PIN_PB28, 0); /* LCDD23 */
  441. #endif
  442. if (ARRAY_SIZE(lcdc_resources) > 2) {
  443. void __iomem *fb;
  444. struct resource *fb_res = &lcdc_resources[2];
  445. size_t fb_len = fb_res->end - fb_res->start + 1;
  446. fb = ioremap(fb_res->start, fb_len);
  447. if (fb) {
  448. memset(fb, 0, fb_len);
  449. iounmap(fb);
  450. }
  451. }
  452. lcdc_data = *data;
  453. platform_device_register(&at91_lcdc_device);
  454. }
  455. #else
  456. void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data) {}
  457. #endif
  458. /* --------------------------------------------------------------------
  459. * Timer/Counter block
  460. * -------------------------------------------------------------------- */
  461. #ifdef CONFIG_ATMEL_TCLIB
  462. static struct resource tcb_resources[] = {
  463. [0] = {
  464. .start = AT91SAM9261_BASE_TCB0,
  465. .end = AT91SAM9261_BASE_TCB0 + SZ_16K - 1,
  466. .flags = IORESOURCE_MEM,
  467. },
  468. [1] = {
  469. .start = AT91SAM9261_ID_TC0,
  470. .end = AT91SAM9261_ID_TC0,
  471. .flags = IORESOURCE_IRQ,
  472. },
  473. [2] = {
  474. .start = AT91SAM9261_ID_TC1,
  475. .end = AT91SAM9261_ID_TC1,
  476. .flags = IORESOURCE_IRQ,
  477. },
  478. [3] = {
  479. .start = AT91SAM9261_ID_TC2,
  480. .end = AT91SAM9261_ID_TC2,
  481. .flags = IORESOURCE_IRQ,
  482. },
  483. };
  484. static struct platform_device at91sam9261_tcb_device = {
  485. .name = "atmel_tcb",
  486. .id = 0,
  487. .resource = tcb_resources,
  488. .num_resources = ARRAY_SIZE(tcb_resources),
  489. };
  490. static void __init at91_add_device_tc(void)
  491. {
  492. /* this chip has a separate clock and irq for each TC channel */
  493. at91_clock_associate("tc0_clk", &at91sam9261_tcb_device.dev, "t0_clk");
  494. at91_clock_associate("tc1_clk", &at91sam9261_tcb_device.dev, "t1_clk");
  495. at91_clock_associate("tc2_clk", &at91sam9261_tcb_device.dev, "t2_clk");
  496. platform_device_register(&at91sam9261_tcb_device);
  497. }
  498. #else
  499. static void __init at91_add_device_tc(void) { }
  500. #endif
  501. /* --------------------------------------------------------------------
  502. * RTT
  503. * -------------------------------------------------------------------- */
  504. static struct resource rtt_resources[] = {
  505. {
  506. .start = AT91_BASE_SYS + AT91_RTT,
  507. .end = AT91_BASE_SYS + AT91_RTT + SZ_16 - 1,
  508. .flags = IORESOURCE_MEM,
  509. }
  510. };
  511. static struct platform_device at91sam9261_rtt_device = {
  512. .name = "at91_rtt",
  513. .id = 0,
  514. .resource = rtt_resources,
  515. .num_resources = ARRAY_SIZE(rtt_resources),
  516. };
  517. static void __init at91_add_device_rtt(void)
  518. {
  519. platform_device_register(&at91sam9261_rtt_device);
  520. }
  521. /* --------------------------------------------------------------------
  522. * Watchdog
  523. * -------------------------------------------------------------------- */
  524. #if defined(CONFIG_AT91SAM9X_WATCHDOG) || defined(CONFIG_AT91SAM9X_WATCHDOG_MODULE)
  525. static struct platform_device at91sam9261_wdt_device = {
  526. .name = "at91_wdt",
  527. .id = -1,
  528. .num_resources = 0,
  529. };
  530. static void __init at91_add_device_watchdog(void)
  531. {
  532. platform_device_register(&at91sam9261_wdt_device);
  533. }
  534. #else
  535. static void __init at91_add_device_watchdog(void) {}
  536. #endif
  537. /* --------------------------------------------------------------------
  538. * SSC -- Synchronous Serial Controller
  539. * -------------------------------------------------------------------- */
  540. #if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
  541. static u64 ssc0_dmamask = DMA_BIT_MASK(32);
  542. static struct resource ssc0_resources[] = {
  543. [0] = {
  544. .start = AT91SAM9261_BASE_SSC0,
  545. .end = AT91SAM9261_BASE_SSC0 + SZ_16K - 1,
  546. .flags = IORESOURCE_MEM,
  547. },
  548. [1] = {
  549. .start = AT91SAM9261_ID_SSC0,
  550. .end = AT91SAM9261_ID_SSC0,
  551. .flags = IORESOURCE_IRQ,
  552. },
  553. };
  554. static struct platform_device at91sam9261_ssc0_device = {
  555. .name = "ssc",
  556. .id = 0,
  557. .dev = {
  558. .dma_mask = &ssc0_dmamask,
  559. .coherent_dma_mask = DMA_BIT_MASK(32),
  560. },
  561. .resource = ssc0_resources,
  562. .num_resources = ARRAY_SIZE(ssc0_resources),
  563. };
  564. static inline void configure_ssc0_pins(unsigned pins)
  565. {
  566. if (pins & ATMEL_SSC_TF)
  567. at91_set_A_periph(AT91_PIN_PB21, 1);
  568. if (pins & ATMEL_SSC_TK)
  569. at91_set_A_periph(AT91_PIN_PB22, 1);
  570. if (pins & ATMEL_SSC_TD)
  571. at91_set_A_periph(AT91_PIN_PB23, 1);
  572. if (pins & ATMEL_SSC_RD)
  573. at91_set_A_periph(AT91_PIN_PB24, 1);
  574. if (pins & ATMEL_SSC_RK)
  575. at91_set_A_periph(AT91_PIN_PB25, 1);
  576. if (pins & ATMEL_SSC_RF)
  577. at91_set_A_periph(AT91_PIN_PB26, 1);
  578. }
  579. static u64 ssc1_dmamask = DMA_BIT_MASK(32);
  580. static struct resource ssc1_resources[] = {
  581. [0] = {
  582. .start = AT91SAM9261_BASE_SSC1,
  583. .end = AT91SAM9261_BASE_SSC1 + SZ_16K - 1,
  584. .flags = IORESOURCE_MEM,
  585. },
  586. [1] = {
  587. .start = AT91SAM9261_ID_SSC1,
  588. .end = AT91SAM9261_ID_SSC1,
  589. .flags = IORESOURCE_IRQ,
  590. },
  591. };
  592. static struct platform_device at91sam9261_ssc1_device = {
  593. .name = "ssc",
  594. .id = 1,
  595. .dev = {
  596. .dma_mask = &ssc1_dmamask,
  597. .coherent_dma_mask = DMA_BIT_MASK(32),
  598. },
  599. .resource = ssc1_resources,
  600. .num_resources = ARRAY_SIZE(ssc1_resources),
  601. };
  602. static inline void configure_ssc1_pins(unsigned pins)
  603. {
  604. if (pins & ATMEL_SSC_TF)
  605. at91_set_B_periph(AT91_PIN_PA17, 1);
  606. if (pins & ATMEL_SSC_TK)
  607. at91_set_B_periph(AT91_PIN_PA18, 1);
  608. if (pins & ATMEL_SSC_TD)
  609. at91_set_B_periph(AT91_PIN_PA19, 1);
  610. if (pins & ATMEL_SSC_RD)
  611. at91_set_B_periph(AT91_PIN_PA20, 1);
  612. if (pins & ATMEL_SSC_RK)
  613. at91_set_B_periph(AT91_PIN_PA21, 1);
  614. if (pins & ATMEL_SSC_RF)
  615. at91_set_B_periph(AT91_PIN_PA22, 1);
  616. }
  617. static u64 ssc2_dmamask = DMA_BIT_MASK(32);
  618. static struct resource ssc2_resources[] = {
  619. [0] = {
  620. .start = AT91SAM9261_BASE_SSC2,
  621. .end = AT91SAM9261_BASE_SSC2 + SZ_16K - 1,
  622. .flags = IORESOURCE_MEM,
  623. },
  624. [1] = {
  625. .start = AT91SAM9261_ID_SSC2,
  626. .end = AT91SAM9261_ID_SSC2,
  627. .flags = IORESOURCE_IRQ,
  628. },
  629. };
  630. static struct platform_device at91sam9261_ssc2_device = {
  631. .name = "ssc",
  632. .id = 2,
  633. .dev = {
  634. .dma_mask = &ssc2_dmamask,
  635. .coherent_dma_mask = DMA_BIT_MASK(32),
  636. },
  637. .resource = ssc2_resources,
  638. .num_resources = ARRAY_SIZE(ssc2_resources),
  639. };
  640. static inline void configure_ssc2_pins(unsigned pins)
  641. {
  642. if (pins & ATMEL_SSC_TF)
  643. at91_set_B_periph(AT91_PIN_PC25, 1);
  644. if (pins & ATMEL_SSC_TK)
  645. at91_set_B_periph(AT91_PIN_PC26, 1);
  646. if (pins & ATMEL_SSC_TD)
  647. at91_set_B_periph(AT91_PIN_PC27, 1);
  648. if (pins & ATMEL_SSC_RD)
  649. at91_set_B_periph(AT91_PIN_PC28, 1);
  650. if (pins & ATMEL_SSC_RK)
  651. at91_set_B_periph(AT91_PIN_PC29, 1);
  652. if (pins & ATMEL_SSC_RF)
  653. at91_set_B_periph(AT91_PIN_PC30, 1);
  654. }
  655. /*
  656. * SSC controllers are accessed through library code, instead of any
  657. * kind of all-singing/all-dancing driver. For example one could be
  658. * used by a particular I2S audio codec's driver, while another one
  659. * on the same system might be used by a custom data capture driver.
  660. */
  661. void __init at91_add_device_ssc(unsigned id, unsigned pins)
  662. {
  663. struct platform_device *pdev;
  664. /*
  665. * NOTE: caller is responsible for passing information matching
  666. * "pins" to whatever will be using each particular controller.
  667. */
  668. switch (id) {
  669. case AT91SAM9261_ID_SSC0:
  670. pdev = &at91sam9261_ssc0_device;
  671. configure_ssc0_pins(pins);
  672. at91_clock_associate("ssc0_clk", &pdev->dev, "pclk");
  673. break;
  674. case AT91SAM9261_ID_SSC1:
  675. pdev = &at91sam9261_ssc1_device;
  676. configure_ssc1_pins(pins);
  677. at91_clock_associate("ssc1_clk", &pdev->dev, "pclk");
  678. break;
  679. case AT91SAM9261_ID_SSC2:
  680. pdev = &at91sam9261_ssc2_device;
  681. configure_ssc2_pins(pins);
  682. at91_clock_associate("ssc2_clk", &pdev->dev, "pclk");
  683. break;
  684. default:
  685. return;
  686. }
  687. platform_device_register(pdev);
  688. }
  689. #else
  690. void __init at91_add_device_ssc(unsigned id, unsigned pins) {}
  691. #endif
  692. /* --------------------------------------------------------------------
  693. * UART
  694. * -------------------------------------------------------------------- */
  695. #if defined(CONFIG_SERIAL_ATMEL)
  696. static struct resource dbgu_resources[] = {
  697. [0] = {
  698. .start = AT91_VA_BASE_SYS + AT91_DBGU,
  699. .end = AT91_VA_BASE_SYS + AT91_DBGU + SZ_512 - 1,
  700. .flags = IORESOURCE_MEM,
  701. },
  702. [1] = {
  703. .start = AT91_ID_SYS,
  704. .end = AT91_ID_SYS,
  705. .flags = IORESOURCE_IRQ,
  706. },
  707. };
  708. static struct atmel_uart_data dbgu_data = {
  709. .use_dma_tx = 0,
  710. .use_dma_rx = 0, /* DBGU not capable of receive DMA */
  711. .regs = (void __iomem *)(AT91_VA_BASE_SYS + AT91_DBGU),
  712. };
  713. static u64 dbgu_dmamask = DMA_BIT_MASK(32);
  714. static struct platform_device at91sam9261_dbgu_device = {
  715. .name = "atmel_usart",
  716. .id = 0,
  717. .dev = {
  718. .dma_mask = &dbgu_dmamask,
  719. .coherent_dma_mask = DMA_BIT_MASK(32),
  720. .platform_data = &dbgu_data,
  721. },
  722. .resource = dbgu_resources,
  723. .num_resources = ARRAY_SIZE(dbgu_resources),
  724. };
  725. static inline void configure_dbgu_pins(void)
  726. {
  727. at91_set_A_periph(AT91_PIN_PA9, 0); /* DRXD */
  728. at91_set_A_periph(AT91_PIN_PA10, 1); /* DTXD */
  729. }
  730. static struct resource uart0_resources[] = {
  731. [0] = {
  732. .start = AT91SAM9261_BASE_US0,
  733. .end = AT91SAM9261_BASE_US0 + SZ_16K - 1,
  734. .flags = IORESOURCE_MEM,
  735. },
  736. [1] = {
  737. .start = AT91SAM9261_ID_US0,
  738. .end = AT91SAM9261_ID_US0,
  739. .flags = IORESOURCE_IRQ,
  740. },
  741. };
  742. static struct atmel_uart_data uart0_data = {
  743. .use_dma_tx = 1,
  744. .use_dma_rx = 1,
  745. };
  746. static u64 uart0_dmamask = DMA_BIT_MASK(32);
  747. static struct platform_device at91sam9261_uart0_device = {
  748. .name = "atmel_usart",
  749. .id = 1,
  750. .dev = {
  751. .dma_mask = &uart0_dmamask,
  752. .coherent_dma_mask = DMA_BIT_MASK(32),
  753. .platform_data = &uart0_data,
  754. },
  755. .resource = uart0_resources,
  756. .num_resources = ARRAY_SIZE(uart0_resources),
  757. };
  758. static inline void configure_usart0_pins(unsigned pins)
  759. {
  760. at91_set_A_periph(AT91_PIN_PC8, 1); /* TXD0 */
  761. at91_set_A_periph(AT91_PIN_PC9, 0); /* RXD0 */
  762. if (pins & ATMEL_UART_RTS)
  763. at91_set_A_periph(AT91_PIN_PC10, 0); /* RTS0 */
  764. if (pins & ATMEL_UART_CTS)
  765. at91_set_A_periph(AT91_PIN_PC11, 0); /* CTS0 */
  766. }
  767. static struct resource uart1_resources[] = {
  768. [0] = {
  769. .start = AT91SAM9261_BASE_US1,
  770. .end = AT91SAM9261_BASE_US1 + SZ_16K - 1,
  771. .flags = IORESOURCE_MEM,
  772. },
  773. [1] = {
  774. .start = AT91SAM9261_ID_US1,
  775. .end = AT91SAM9261_ID_US1,
  776. .flags = IORESOURCE_IRQ,
  777. },
  778. };
  779. static struct atmel_uart_data uart1_data = {
  780. .use_dma_tx = 1,
  781. .use_dma_rx = 1,
  782. };
  783. static u64 uart1_dmamask = DMA_BIT_MASK(32);
  784. static struct platform_device at91sam9261_uart1_device = {
  785. .name = "atmel_usart",
  786. .id = 2,
  787. .dev = {
  788. .dma_mask = &uart1_dmamask,
  789. .coherent_dma_mask = DMA_BIT_MASK(32),
  790. .platform_data = &uart1_data,
  791. },
  792. .resource = uart1_resources,
  793. .num_resources = ARRAY_SIZE(uart1_resources),
  794. };
  795. static inline void configure_usart1_pins(unsigned pins)
  796. {
  797. at91_set_A_periph(AT91_PIN_PC12, 1); /* TXD1 */
  798. at91_set_A_periph(AT91_PIN_PC13, 0); /* RXD1 */
  799. if (pins & ATMEL_UART_RTS)
  800. at91_set_B_periph(AT91_PIN_PA12, 0); /* RTS1 */
  801. if (pins & ATMEL_UART_CTS)
  802. at91_set_B_periph(AT91_PIN_PA13, 0); /* CTS1 */
  803. }
  804. static struct resource uart2_resources[] = {
  805. [0] = {
  806. .start = AT91SAM9261_BASE_US2,
  807. .end = AT91SAM9261_BASE_US2 + SZ_16K - 1,
  808. .flags = IORESOURCE_MEM,
  809. },
  810. [1] = {
  811. .start = AT91SAM9261_ID_US2,
  812. .end = AT91SAM9261_ID_US2,
  813. .flags = IORESOURCE_IRQ,
  814. },
  815. };
  816. static struct atmel_uart_data uart2_data = {
  817. .use_dma_tx = 1,
  818. .use_dma_rx = 1,
  819. };
  820. static u64 uart2_dmamask = DMA_BIT_MASK(32);
  821. static struct platform_device at91sam9261_uart2_device = {
  822. .name = "atmel_usart",
  823. .id = 3,
  824. .dev = {
  825. .dma_mask = &uart2_dmamask,
  826. .coherent_dma_mask = DMA_BIT_MASK(32),
  827. .platform_data = &uart2_data,
  828. },
  829. .resource = uart2_resources,
  830. .num_resources = ARRAY_SIZE(uart2_resources),
  831. };
  832. static inline void configure_usart2_pins(unsigned pins)
  833. {
  834. at91_set_A_periph(AT91_PIN_PC15, 0); /* RXD2 */
  835. at91_set_A_periph(AT91_PIN_PC14, 1); /* TXD2 */
  836. if (pins & ATMEL_UART_RTS)
  837. at91_set_B_periph(AT91_PIN_PA15, 0); /* RTS2*/
  838. if (pins & ATMEL_UART_CTS)
  839. at91_set_B_periph(AT91_PIN_PA16, 0); /* CTS2 */
  840. }
  841. static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
  842. struct platform_device *atmel_default_console_device; /* the serial console device */
  843. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
  844. {
  845. struct platform_device *pdev;
  846. switch (id) {
  847. case 0: /* DBGU */
  848. pdev = &at91sam9261_dbgu_device;
  849. configure_dbgu_pins();
  850. at91_clock_associate("mck", &pdev->dev, "usart");
  851. break;
  852. case AT91SAM9261_ID_US0:
  853. pdev = &at91sam9261_uart0_device;
  854. configure_usart0_pins(pins);
  855. at91_clock_associate("usart0_clk", &pdev->dev, "usart");
  856. break;
  857. case AT91SAM9261_ID_US1:
  858. pdev = &at91sam9261_uart1_device;
  859. configure_usart1_pins(pins);
  860. at91_clock_associate("usart1_clk", &pdev->dev, "usart");
  861. break;
  862. case AT91SAM9261_ID_US2:
  863. pdev = &at91sam9261_uart2_device;
  864. configure_usart2_pins(pins);
  865. at91_clock_associate("usart2_clk", &pdev->dev, "usart");
  866. break;
  867. default:
  868. return;
  869. }
  870. pdev->id = portnr; /* update to mapped ID */
  871. if (portnr < ATMEL_MAX_UART)
  872. at91_uarts[portnr] = pdev;
  873. }
  874. void __init at91_set_serial_console(unsigned portnr)
  875. {
  876. if (portnr < ATMEL_MAX_UART)
  877. atmel_default_console_device = at91_uarts[portnr];
  878. }
  879. void __init at91_add_device_serial(void)
  880. {
  881. int i;
  882. for (i = 0; i < ATMEL_MAX_UART; i++) {
  883. if (at91_uarts[i])
  884. platform_device_register(at91_uarts[i]);
  885. }
  886. if (!atmel_default_console_device)
  887. printk(KERN_INFO "AT91: No default serial console defined.\n");
  888. }
  889. #else
  890. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
  891. void __init at91_set_serial_console(unsigned portnr) {}
  892. void __init at91_add_device_serial(void) {}
  893. #endif
  894. /* -------------------------------------------------------------------- */
  895. /*
  896. * These devices are always present and don't need any board-specific
  897. * setup.
  898. */
  899. static int __init at91_add_standard_devices(void)
  900. {
  901. at91_add_device_rtt();
  902. at91_add_device_watchdog();
  903. at91_add_device_tc();
  904. return 0;
  905. }
  906. arch_initcall(at91_add_standard_devices);