at91sam9261_devices.c 27 KB

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