at91sam9rl_devices.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026
  1. /*
  2. * Copyright (C) 2007 Atmel Corporation
  3. *
  4. * This file is subject to the terms and conditions of the GNU General Public
  5. * License. See the file COPYING in the main directory of this archive for
  6. * more details.
  7. */
  8. #include <asm/mach/arch.h>
  9. #include <asm/mach/map.h>
  10. #include <linux/dma-mapping.h>
  11. #include <linux/platform_device.h>
  12. #include <linux/i2c-gpio.h>
  13. #include <linux/fb.h>
  14. #include <video/atmel_lcdc.h>
  15. #include <asm/arch/board.h>
  16. #include <asm/arch/gpio.h>
  17. #include <asm/arch/at91sam9rl.h>
  18. #include <asm/arch/at91sam9rl_matrix.h>
  19. #include <asm/arch/at91sam9_smc.h>
  20. #include "generic.h"
  21. /* --------------------------------------------------------------------
  22. * USB HS Device (Gadget)
  23. * -------------------------------------------------------------------- */
  24. #if defined(CONFIG_USB_GADGET_ATMEL_USBA) || defined(CONFIG_USB_GADGET_ATMEL_USBA_MODULE)
  25. static struct resource usba_udc_resources[] = {
  26. [0] = {
  27. .start = AT91SAM9RL_UDPHS_FIFO,
  28. .end = AT91SAM9RL_UDPHS_FIFO + SZ_512K - 1,
  29. .flags = IORESOURCE_MEM,
  30. },
  31. [1] = {
  32. .start = AT91SAM9RL_BASE_UDPHS,
  33. .end = AT91SAM9RL_BASE_UDPHS + SZ_1K - 1,
  34. .flags = IORESOURCE_MEM,
  35. },
  36. [2] = {
  37. .start = AT91SAM9RL_ID_UDPHS,
  38. .end = AT91SAM9RL_ID_UDPHS,
  39. .flags = IORESOURCE_IRQ,
  40. },
  41. };
  42. #define EP(nam, idx, maxpkt, maxbk, dma, isoc) \
  43. [idx] = { \
  44. .name = nam, \
  45. .index = idx, \
  46. .fifo_size = maxpkt, \
  47. .nr_banks = maxbk, \
  48. .can_dma = dma, \
  49. .can_isoc = isoc, \
  50. }
  51. static struct usba_ep_data usba_udc_ep[] __initdata = {
  52. EP("ep0", 0, 64, 1, 0, 0),
  53. EP("ep1", 1, 1024, 2, 1, 1),
  54. EP("ep2", 2, 1024, 2, 1, 1),
  55. EP("ep3", 3, 1024, 3, 1, 0),
  56. EP("ep4", 4, 1024, 3, 1, 0),
  57. EP("ep5", 5, 1024, 3, 1, 1),
  58. EP("ep6", 6, 1024, 3, 1, 1),
  59. };
  60. #undef EP
  61. /*
  62. * pdata doesn't have room for any endpoints, so we need to
  63. * append room for the ones we need right after it.
  64. */
  65. static struct {
  66. struct usba_platform_data pdata;
  67. struct usba_ep_data ep[7];
  68. } usba_udc_data;
  69. static struct platform_device at91_usba_udc_device = {
  70. .name = "atmel_usba_udc",
  71. .id = -1,
  72. .dev = {
  73. .platform_data = &usba_udc_data.pdata,
  74. },
  75. .resource = usba_udc_resources,
  76. .num_resources = ARRAY_SIZE(usba_udc_resources),
  77. };
  78. void __init at91_add_device_usba(struct usba_platform_data *data)
  79. {
  80. /*
  81. * Invalid pins are 0 on AT91, but the usba driver is shared
  82. * with AVR32, which use negative values instead. Once/if
  83. * gpio_is_valid() is ported to AT91, revisit this code.
  84. */
  85. usba_udc_data.pdata.vbus_pin = -EINVAL;
  86. usba_udc_data.pdata.num_ep = ARRAY_SIZE(usba_udc_ep);
  87. memcpy(usba_udc_data.ep, usba_udc_ep, sizeof(usba_udc_ep));;
  88. if (data && data->vbus_pin > 0) {
  89. at91_set_gpio_input(data->vbus_pin, 0);
  90. at91_set_deglitch(data->vbus_pin, 1);
  91. usba_udc_data.pdata.vbus_pin = data->vbus_pin;
  92. }
  93. /* Pullup pin is handled internally by USB device peripheral */
  94. /* Clocks */
  95. at91_clock_associate("utmi_clk", &at91_usba_udc_device.dev, "hclk");
  96. at91_clock_associate("udphs_clk", &at91_usba_udc_device.dev, "pclk");
  97. platform_device_register(&at91_usba_udc_device);
  98. }
  99. #else
  100. void __init at91_add_device_usba(struct usba_platform_data *data) {}
  101. #endif
  102. /* --------------------------------------------------------------------
  103. * MMC / SD
  104. * -------------------------------------------------------------------- */
  105. #if defined(CONFIG_MMC_AT91) || defined(CONFIG_MMC_AT91_MODULE)
  106. static u64 mmc_dmamask = DMA_BIT_MASK(32);
  107. static struct at91_mmc_data mmc_data;
  108. static struct resource mmc_resources[] = {
  109. [0] = {
  110. .start = AT91SAM9RL_BASE_MCI,
  111. .end = AT91SAM9RL_BASE_MCI + SZ_16K - 1,
  112. .flags = IORESOURCE_MEM,
  113. },
  114. [1] = {
  115. .start = AT91SAM9RL_ID_MCI,
  116. .end = AT91SAM9RL_ID_MCI,
  117. .flags = IORESOURCE_IRQ,
  118. },
  119. };
  120. static struct platform_device at91sam9rl_mmc_device = {
  121. .name = "at91_mci",
  122. .id = -1,
  123. .dev = {
  124. .dma_mask = &mmc_dmamask,
  125. .coherent_dma_mask = DMA_BIT_MASK(32),
  126. .platform_data = &mmc_data,
  127. },
  128. .resource = mmc_resources,
  129. .num_resources = ARRAY_SIZE(mmc_resources),
  130. };
  131. void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data)
  132. {
  133. if (!data)
  134. return;
  135. /* input/irq */
  136. if (data->det_pin) {
  137. at91_set_gpio_input(data->det_pin, 1);
  138. at91_set_deglitch(data->det_pin, 1);
  139. }
  140. if (data->wp_pin)
  141. at91_set_gpio_input(data->wp_pin, 1);
  142. if (data->vcc_pin)
  143. at91_set_gpio_output(data->vcc_pin, 0);
  144. /* CLK */
  145. at91_set_A_periph(AT91_PIN_PA2, 0);
  146. /* CMD */
  147. at91_set_A_periph(AT91_PIN_PA1, 1);
  148. /* DAT0, maybe DAT1..DAT3 */
  149. at91_set_A_periph(AT91_PIN_PA0, 1);
  150. if (data->wire4) {
  151. at91_set_A_periph(AT91_PIN_PA3, 1);
  152. at91_set_A_periph(AT91_PIN_PA4, 1);
  153. at91_set_A_periph(AT91_PIN_PA5, 1);
  154. }
  155. mmc_data = *data;
  156. platform_device_register(&at91sam9rl_mmc_device);
  157. }
  158. #else
  159. void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data) {}
  160. #endif
  161. /* --------------------------------------------------------------------
  162. * NAND / SmartMedia
  163. * -------------------------------------------------------------------- */
  164. #if defined(CONFIG_MTD_NAND_ATMEL) || defined(CONFIG_MTD_NAND_ATMEL_MODULE)
  165. static struct atmel_nand_data nand_data;
  166. #define NAND_BASE AT91_CHIPSELECT_3
  167. static struct resource nand_resources[] = {
  168. [0] = {
  169. .start = NAND_BASE,
  170. .end = NAND_BASE + SZ_256M - 1,
  171. .flags = IORESOURCE_MEM,
  172. },
  173. [1] = {
  174. .start = AT91_BASE_SYS + AT91_ECC,
  175. .end = AT91_BASE_SYS + AT91_ECC + SZ_512 - 1,
  176. .flags = IORESOURCE_MEM,
  177. }
  178. };
  179. static struct platform_device atmel_nand_device = {
  180. .name = "atmel_nand",
  181. .id = -1,
  182. .dev = {
  183. .platform_data = &nand_data,
  184. },
  185. .resource = nand_resources,
  186. .num_resources = ARRAY_SIZE(nand_resources),
  187. };
  188. void __init at91_add_device_nand(struct atmel_nand_data *data)
  189. {
  190. unsigned long csa;
  191. if (!data)
  192. return;
  193. csa = at91_sys_read(AT91_MATRIX_EBICSA);
  194. at91_sys_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_CS3A_SMC_SMARTMEDIA);
  195. /* set the bus interface characteristics */
  196. at91_sys_write(AT91_SMC_SETUP(3), AT91_SMC_NWESETUP_(1) | AT91_SMC_NCS_WRSETUP_(0)
  197. | AT91_SMC_NRDSETUP_(1) | AT91_SMC_NCS_RDSETUP_(0));
  198. at91_sys_write(AT91_SMC_PULSE(3), AT91_SMC_NWEPULSE_(3) | AT91_SMC_NCS_WRPULSE_(3)
  199. | AT91_SMC_NRDPULSE_(3) | AT91_SMC_NCS_RDPULSE_(3));
  200. at91_sys_write(AT91_SMC_CYCLE(3), AT91_SMC_NWECYCLE_(5) | AT91_SMC_NRDCYCLE_(5));
  201. at91_sys_write(AT91_SMC_MODE(3), AT91_SMC_DBW_8 | AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_TDF_(2));
  202. /* enable pin */
  203. if (data->enable_pin)
  204. at91_set_gpio_output(data->enable_pin, 1);
  205. /* ready/busy pin */
  206. if (data->rdy_pin)
  207. at91_set_gpio_input(data->rdy_pin, 1);
  208. /* card detect pin */
  209. if (data->det_pin)
  210. at91_set_gpio_input(data->det_pin, 1);
  211. at91_set_A_periph(AT91_PIN_PB4, 0); /* NANDOE */
  212. at91_set_A_periph(AT91_PIN_PB5, 0); /* NANDWE */
  213. nand_data = *data;
  214. platform_device_register(&atmel_nand_device);
  215. }
  216. #else
  217. void __init at91_add_device_nand(struct atmel_nand_data *data) {}
  218. #endif
  219. /* --------------------------------------------------------------------
  220. * TWI (i2c)
  221. * -------------------------------------------------------------------- */
  222. /*
  223. * Prefer the GPIO code since the TWI controller isn't robust
  224. * (gets overruns and underruns under load) and can only issue
  225. * repeated STARTs in one scenario (the driver doesn't yet handle them).
  226. */
  227. #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
  228. static struct i2c_gpio_platform_data pdata = {
  229. .sda_pin = AT91_PIN_PA23,
  230. .sda_is_open_drain = 1,
  231. .scl_pin = AT91_PIN_PA24,
  232. .scl_is_open_drain = 1,
  233. .udelay = 2, /* ~100 kHz */
  234. };
  235. static struct platform_device at91sam9rl_twi_device = {
  236. .name = "i2c-gpio",
  237. .id = -1,
  238. .dev.platform_data = &pdata,
  239. };
  240. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  241. {
  242. at91_set_GPIO_periph(AT91_PIN_PA23, 1); /* TWD (SDA) */
  243. at91_set_multi_drive(AT91_PIN_PA23, 1);
  244. at91_set_GPIO_periph(AT91_PIN_PA24, 1); /* TWCK (SCL) */
  245. at91_set_multi_drive(AT91_PIN_PA24, 1);
  246. i2c_register_board_info(0, devices, nr_devices);
  247. platform_device_register(&at91sam9rl_twi_device);
  248. }
  249. #elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
  250. static struct resource twi_resources[] = {
  251. [0] = {
  252. .start = AT91SAM9RL_BASE_TWI0,
  253. .end = AT91SAM9RL_BASE_TWI0 + SZ_16K - 1,
  254. .flags = IORESOURCE_MEM,
  255. },
  256. [1] = {
  257. .start = AT91SAM9RL_ID_TWI0,
  258. .end = AT91SAM9RL_ID_TWI0,
  259. .flags = IORESOURCE_IRQ,
  260. },
  261. };
  262. static struct platform_device at91sam9rl_twi_device = {
  263. .name = "at91_i2c",
  264. .id = -1,
  265. .resource = twi_resources,
  266. .num_resources = ARRAY_SIZE(twi_resources),
  267. };
  268. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  269. {
  270. /* pins used for TWI interface */
  271. at91_set_A_periph(AT91_PIN_PA23, 0); /* TWD */
  272. at91_set_multi_drive(AT91_PIN_PA23, 1);
  273. at91_set_A_periph(AT91_PIN_PA24, 0); /* TWCK */
  274. at91_set_multi_drive(AT91_PIN_PA24, 1);
  275. i2c_register_board_info(0, devices, nr_devices);
  276. platform_device_register(&at91sam9rl_twi_device);
  277. }
  278. #else
  279. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {}
  280. #endif
  281. /* --------------------------------------------------------------------
  282. * SPI
  283. * -------------------------------------------------------------------- */
  284. #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
  285. static u64 spi_dmamask = DMA_BIT_MASK(32);
  286. static struct resource spi_resources[] = {
  287. [0] = {
  288. .start = AT91SAM9RL_BASE_SPI,
  289. .end = AT91SAM9RL_BASE_SPI + SZ_16K - 1,
  290. .flags = IORESOURCE_MEM,
  291. },
  292. [1] = {
  293. .start = AT91SAM9RL_ID_SPI,
  294. .end = AT91SAM9RL_ID_SPI,
  295. .flags = IORESOURCE_IRQ,
  296. },
  297. };
  298. static struct platform_device at91sam9rl_spi_device = {
  299. .name = "atmel_spi",
  300. .id = 0,
  301. .dev = {
  302. .dma_mask = &spi_dmamask,
  303. .coherent_dma_mask = DMA_BIT_MASK(32),
  304. },
  305. .resource = spi_resources,
  306. .num_resources = ARRAY_SIZE(spi_resources),
  307. };
  308. static const unsigned spi_standard_cs[4] = { AT91_PIN_PA28, AT91_PIN_PB7, AT91_PIN_PD8, AT91_PIN_PD9 };
  309. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
  310. {
  311. int i;
  312. unsigned long cs_pin;
  313. at91_set_A_periph(AT91_PIN_PA25, 0); /* MISO */
  314. at91_set_A_periph(AT91_PIN_PA26, 0); /* MOSI */
  315. at91_set_A_periph(AT91_PIN_PA27, 0); /* SPCK */
  316. /* Enable SPI chip-selects */
  317. for (i = 0; i < nr_devices; i++) {
  318. if (devices[i].controller_data)
  319. cs_pin = (unsigned long) devices[i].controller_data;
  320. else
  321. cs_pin = spi_standard_cs[devices[i].chip_select];
  322. /* enable chip-select pin */
  323. at91_set_gpio_output(cs_pin, 1);
  324. /* pass chip-select pin to driver */
  325. devices[i].controller_data = (void *) cs_pin;
  326. }
  327. spi_register_board_info(devices, nr_devices);
  328. platform_device_register(&at91sam9rl_spi_device);
  329. }
  330. #else
  331. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
  332. #endif
  333. /* --------------------------------------------------------------------
  334. * LCD Controller
  335. * -------------------------------------------------------------------- */
  336. #if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
  337. static u64 lcdc_dmamask = DMA_BIT_MASK(32);
  338. static struct atmel_lcdfb_info lcdc_data;
  339. static struct resource lcdc_resources[] = {
  340. [0] = {
  341. .start = AT91SAM9RL_LCDC_BASE,
  342. .end = AT91SAM9RL_LCDC_BASE + SZ_4K - 1,
  343. .flags = IORESOURCE_MEM,
  344. },
  345. [1] = {
  346. .start = AT91SAM9RL_ID_LCDC,
  347. .end = AT91SAM9RL_ID_LCDC,
  348. .flags = IORESOURCE_IRQ,
  349. },
  350. };
  351. static struct platform_device at91_lcdc_device = {
  352. .name = "atmel_lcdfb",
  353. .id = 0,
  354. .dev = {
  355. .dma_mask = &lcdc_dmamask,
  356. .coherent_dma_mask = DMA_BIT_MASK(32),
  357. .platform_data = &lcdc_data,
  358. },
  359. .resource = lcdc_resources,
  360. .num_resources = ARRAY_SIZE(lcdc_resources),
  361. };
  362. void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data)
  363. {
  364. if (!data) {
  365. return;
  366. }
  367. at91_set_B_periph(AT91_PIN_PC1, 0); /* LCDPWR */
  368. at91_set_A_periph(AT91_PIN_PC5, 0); /* LCDHSYNC */
  369. at91_set_A_periph(AT91_PIN_PC6, 0); /* LCDDOTCK */
  370. at91_set_A_periph(AT91_PIN_PC7, 0); /* LCDDEN */
  371. at91_set_A_periph(AT91_PIN_PC3, 0); /* LCDCC */
  372. at91_set_B_periph(AT91_PIN_PC9, 0); /* LCDD3 */
  373. at91_set_B_periph(AT91_PIN_PC10, 0); /* LCDD4 */
  374. at91_set_B_periph(AT91_PIN_PC11, 0); /* LCDD5 */
  375. at91_set_B_periph(AT91_PIN_PC12, 0); /* LCDD6 */
  376. at91_set_B_periph(AT91_PIN_PC13, 0); /* LCDD7 */
  377. at91_set_B_periph(AT91_PIN_PC15, 0); /* LCDD11 */
  378. at91_set_B_periph(AT91_PIN_PC16, 0); /* LCDD12 */
  379. at91_set_B_periph(AT91_PIN_PC17, 0); /* LCDD13 */
  380. at91_set_B_periph(AT91_PIN_PC18, 0); /* LCDD14 */
  381. at91_set_B_periph(AT91_PIN_PC19, 0); /* LCDD15 */
  382. at91_set_B_periph(AT91_PIN_PC20, 0); /* LCDD18 */
  383. at91_set_B_periph(AT91_PIN_PC21, 0); /* LCDD19 */
  384. at91_set_B_periph(AT91_PIN_PC22, 0); /* LCDD20 */
  385. at91_set_B_periph(AT91_PIN_PC23, 0); /* LCDD21 */
  386. at91_set_B_periph(AT91_PIN_PC24, 0); /* LCDD22 */
  387. at91_set_B_periph(AT91_PIN_PC25, 0); /* LCDD23 */
  388. lcdc_data = *data;
  389. platform_device_register(&at91_lcdc_device);
  390. }
  391. #else
  392. void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data) {}
  393. #endif
  394. /* --------------------------------------------------------------------
  395. * Timer/Counter block
  396. * -------------------------------------------------------------------- */
  397. #ifdef CONFIG_ATMEL_TCLIB
  398. static struct resource tcb_resources[] = {
  399. [0] = {
  400. .start = AT91SAM9RL_BASE_TCB0,
  401. .end = AT91SAM9RL_BASE_TCB0 + SZ_16K - 1,
  402. .flags = IORESOURCE_MEM,
  403. },
  404. [1] = {
  405. .start = AT91SAM9RL_ID_TC0,
  406. .end = AT91SAM9RL_ID_TC0,
  407. .flags = IORESOURCE_IRQ,
  408. },
  409. [2] = {
  410. .start = AT91SAM9RL_ID_TC1,
  411. .end = AT91SAM9RL_ID_TC1,
  412. .flags = IORESOURCE_IRQ,
  413. },
  414. [3] = {
  415. .start = AT91SAM9RL_ID_TC2,
  416. .end = AT91SAM9RL_ID_TC2,
  417. .flags = IORESOURCE_IRQ,
  418. },
  419. };
  420. static struct platform_device at91sam9rl_tcb_device = {
  421. .name = "atmel_tcb",
  422. .id = 0,
  423. .resource = tcb_resources,
  424. .num_resources = ARRAY_SIZE(tcb_resources),
  425. };
  426. static void __init at91_add_device_tc(void)
  427. {
  428. /* this chip has a separate clock and irq for each TC channel */
  429. at91_clock_associate("tc0_clk", &at91sam9rl_tcb_device.dev, "t0_clk");
  430. at91_clock_associate("tc1_clk", &at91sam9rl_tcb_device.dev, "t1_clk");
  431. at91_clock_associate("tc2_clk", &at91sam9rl_tcb_device.dev, "t2_clk");
  432. platform_device_register(&at91sam9rl_tcb_device);
  433. }
  434. #else
  435. static void __init at91_add_device_tc(void) { }
  436. #endif
  437. /* --------------------------------------------------------------------
  438. * RTC
  439. * -------------------------------------------------------------------- */
  440. #if defined(CONFIG_RTC_DRV_AT91RM9200) || defined(CONFIG_RTC_DRV_AT91RM9200_MODULE)
  441. static struct platform_device at91sam9rl_rtc_device = {
  442. .name = "at91_rtc",
  443. .id = -1,
  444. .num_resources = 0,
  445. };
  446. static void __init at91_add_device_rtc(void)
  447. {
  448. platform_device_register(&at91sam9rl_rtc_device);
  449. }
  450. #else
  451. static void __init at91_add_device_rtc(void) {}
  452. #endif
  453. /* --------------------------------------------------------------------
  454. * RTT
  455. * -------------------------------------------------------------------- */
  456. static struct resource rtt_resources[] = {
  457. {
  458. .start = AT91_BASE_SYS + AT91_RTT,
  459. .end = AT91_BASE_SYS + AT91_RTT + SZ_16 - 1,
  460. .flags = IORESOURCE_MEM,
  461. }
  462. };
  463. static struct platform_device at91sam9rl_rtt_device = {
  464. .name = "at91_rtt",
  465. .id = 0,
  466. .resource = rtt_resources,
  467. .num_resources = ARRAY_SIZE(rtt_resources),
  468. };
  469. static void __init at91_add_device_rtt(void)
  470. {
  471. platform_device_register(&at91sam9rl_rtt_device);
  472. }
  473. /* --------------------------------------------------------------------
  474. * Watchdog
  475. * -------------------------------------------------------------------- */
  476. #if defined(CONFIG_AT91SAM9_WATCHDOG) || defined(CONFIG_AT91SAM9_WATCHDOG_MODULE)
  477. static struct platform_device at91sam9rl_wdt_device = {
  478. .name = "at91_wdt",
  479. .id = -1,
  480. .num_resources = 0,
  481. };
  482. static void __init at91_add_device_watchdog(void)
  483. {
  484. platform_device_register(&at91sam9rl_wdt_device);
  485. }
  486. #else
  487. static void __init at91_add_device_watchdog(void) {}
  488. #endif
  489. /* --------------------------------------------------------------------
  490. * SSC -- Synchronous Serial Controller
  491. * -------------------------------------------------------------------- */
  492. #if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
  493. static u64 ssc0_dmamask = DMA_BIT_MASK(32);
  494. static struct resource ssc0_resources[] = {
  495. [0] = {
  496. .start = AT91SAM9RL_BASE_SSC0,
  497. .end = AT91SAM9RL_BASE_SSC0 + SZ_16K - 1,
  498. .flags = IORESOURCE_MEM,
  499. },
  500. [1] = {
  501. .start = AT91SAM9RL_ID_SSC0,
  502. .end = AT91SAM9RL_ID_SSC0,
  503. .flags = IORESOURCE_IRQ,
  504. },
  505. };
  506. static struct platform_device at91sam9rl_ssc0_device = {
  507. .name = "ssc",
  508. .id = 0,
  509. .dev = {
  510. .dma_mask = &ssc0_dmamask,
  511. .coherent_dma_mask = DMA_BIT_MASK(32),
  512. },
  513. .resource = ssc0_resources,
  514. .num_resources = ARRAY_SIZE(ssc0_resources),
  515. };
  516. static inline void configure_ssc0_pins(unsigned pins)
  517. {
  518. if (pins & ATMEL_SSC_TF)
  519. at91_set_A_periph(AT91_PIN_PC0, 1);
  520. if (pins & ATMEL_SSC_TK)
  521. at91_set_A_periph(AT91_PIN_PC1, 1);
  522. if (pins & ATMEL_SSC_TD)
  523. at91_set_A_periph(AT91_PIN_PA15, 1);
  524. if (pins & ATMEL_SSC_RD)
  525. at91_set_A_periph(AT91_PIN_PA16, 1);
  526. if (pins & ATMEL_SSC_RK)
  527. at91_set_B_periph(AT91_PIN_PA10, 1);
  528. if (pins & ATMEL_SSC_RF)
  529. at91_set_B_periph(AT91_PIN_PA22, 1);
  530. }
  531. static u64 ssc1_dmamask = DMA_BIT_MASK(32);
  532. static struct resource ssc1_resources[] = {
  533. [0] = {
  534. .start = AT91SAM9RL_BASE_SSC1,
  535. .end = AT91SAM9RL_BASE_SSC1 + SZ_16K - 1,
  536. .flags = IORESOURCE_MEM,
  537. },
  538. [1] = {
  539. .start = AT91SAM9RL_ID_SSC1,
  540. .end = AT91SAM9RL_ID_SSC1,
  541. .flags = IORESOURCE_IRQ,
  542. },
  543. };
  544. static struct platform_device at91sam9rl_ssc1_device = {
  545. .name = "ssc",
  546. .id = 1,
  547. .dev = {
  548. .dma_mask = &ssc1_dmamask,
  549. .coherent_dma_mask = DMA_BIT_MASK(32),
  550. },
  551. .resource = ssc1_resources,
  552. .num_resources = ARRAY_SIZE(ssc1_resources),
  553. };
  554. static inline void configure_ssc1_pins(unsigned pins)
  555. {
  556. if (pins & ATMEL_SSC_TF)
  557. at91_set_B_periph(AT91_PIN_PA29, 1);
  558. if (pins & ATMEL_SSC_TK)
  559. at91_set_B_periph(AT91_PIN_PA30, 1);
  560. if (pins & ATMEL_SSC_TD)
  561. at91_set_B_periph(AT91_PIN_PA13, 1);
  562. if (pins & ATMEL_SSC_RD)
  563. at91_set_B_periph(AT91_PIN_PA14, 1);
  564. if (pins & ATMEL_SSC_RK)
  565. at91_set_B_periph(AT91_PIN_PA9, 1);
  566. if (pins & ATMEL_SSC_RF)
  567. at91_set_B_periph(AT91_PIN_PA8, 1);
  568. }
  569. /*
  570. * SSC controllers are accessed through library code, instead of any
  571. * kind of all-singing/all-dancing driver. For example one could be
  572. * used by a particular I2S audio codec's driver, while another one
  573. * on the same system might be used by a custom data capture driver.
  574. */
  575. void __init at91_add_device_ssc(unsigned id, unsigned pins)
  576. {
  577. struct platform_device *pdev;
  578. /*
  579. * NOTE: caller is responsible for passing information matching
  580. * "pins" to whatever will be using each particular controller.
  581. */
  582. switch (id) {
  583. case AT91SAM9RL_ID_SSC0:
  584. pdev = &at91sam9rl_ssc0_device;
  585. configure_ssc0_pins(pins);
  586. at91_clock_associate("ssc0_clk", &pdev->dev, "pclk");
  587. break;
  588. case AT91SAM9RL_ID_SSC1:
  589. pdev = &at91sam9rl_ssc1_device;
  590. configure_ssc1_pins(pins);
  591. at91_clock_associate("ssc1_clk", &pdev->dev, "pclk");
  592. break;
  593. default:
  594. return;
  595. }
  596. platform_device_register(pdev);
  597. }
  598. #else
  599. void __init at91_add_device_ssc(unsigned id, unsigned pins) {}
  600. #endif
  601. /* --------------------------------------------------------------------
  602. * UART
  603. * -------------------------------------------------------------------- */
  604. #if defined(CONFIG_SERIAL_ATMEL)
  605. static struct resource dbgu_resources[] = {
  606. [0] = {
  607. .start = AT91_VA_BASE_SYS + AT91_DBGU,
  608. .end = AT91_VA_BASE_SYS + AT91_DBGU + SZ_512 - 1,
  609. .flags = IORESOURCE_MEM,
  610. },
  611. [1] = {
  612. .start = AT91_ID_SYS,
  613. .end = AT91_ID_SYS,
  614. .flags = IORESOURCE_IRQ,
  615. },
  616. };
  617. static struct atmel_uart_data dbgu_data = {
  618. .use_dma_tx = 0,
  619. .use_dma_rx = 0, /* DBGU not capable of receive DMA */
  620. .regs = (void __iomem *)(AT91_VA_BASE_SYS + AT91_DBGU),
  621. };
  622. static u64 dbgu_dmamask = DMA_BIT_MASK(32);
  623. static struct platform_device at91sam9rl_dbgu_device = {
  624. .name = "atmel_usart",
  625. .id = 0,
  626. .dev = {
  627. .dma_mask = &dbgu_dmamask,
  628. .coherent_dma_mask = DMA_BIT_MASK(32),
  629. .platform_data = &dbgu_data,
  630. },
  631. .resource = dbgu_resources,
  632. .num_resources = ARRAY_SIZE(dbgu_resources),
  633. };
  634. static inline void configure_dbgu_pins(void)
  635. {
  636. at91_set_A_periph(AT91_PIN_PA21, 0); /* DRXD */
  637. at91_set_A_periph(AT91_PIN_PA22, 1); /* DTXD */
  638. }
  639. static struct resource uart0_resources[] = {
  640. [0] = {
  641. .start = AT91SAM9RL_BASE_US0,
  642. .end = AT91SAM9RL_BASE_US0 + SZ_16K - 1,
  643. .flags = IORESOURCE_MEM,
  644. },
  645. [1] = {
  646. .start = AT91SAM9RL_ID_US0,
  647. .end = AT91SAM9RL_ID_US0,
  648. .flags = IORESOURCE_IRQ,
  649. },
  650. };
  651. static struct atmel_uart_data uart0_data = {
  652. .use_dma_tx = 1,
  653. .use_dma_rx = 1,
  654. };
  655. static u64 uart0_dmamask = DMA_BIT_MASK(32);
  656. static struct platform_device at91sam9rl_uart0_device = {
  657. .name = "atmel_usart",
  658. .id = 1,
  659. .dev = {
  660. .dma_mask = &uart0_dmamask,
  661. .coherent_dma_mask = DMA_BIT_MASK(32),
  662. .platform_data = &uart0_data,
  663. },
  664. .resource = uart0_resources,
  665. .num_resources = ARRAY_SIZE(uart0_resources),
  666. };
  667. static inline void configure_usart0_pins(unsigned pins)
  668. {
  669. at91_set_A_periph(AT91_PIN_PA6, 1); /* TXD0 */
  670. at91_set_A_periph(AT91_PIN_PA7, 0); /* RXD0 */
  671. if (pins & ATMEL_UART_RTS)
  672. at91_set_A_periph(AT91_PIN_PA9, 0); /* RTS0 */
  673. if (pins & ATMEL_UART_CTS)
  674. at91_set_A_periph(AT91_PIN_PA10, 0); /* CTS0 */
  675. if (pins & ATMEL_UART_DSR)
  676. at91_set_A_periph(AT91_PIN_PD14, 0); /* DSR0 */
  677. if (pins & ATMEL_UART_DTR)
  678. at91_set_A_periph(AT91_PIN_PD15, 0); /* DTR0 */
  679. if (pins & ATMEL_UART_DCD)
  680. at91_set_A_periph(AT91_PIN_PD16, 0); /* DCD0 */
  681. if (pins & ATMEL_UART_RI)
  682. at91_set_A_periph(AT91_PIN_PD17, 0); /* RI0 */
  683. }
  684. static struct resource uart1_resources[] = {
  685. [0] = {
  686. .start = AT91SAM9RL_BASE_US1,
  687. .end = AT91SAM9RL_BASE_US1 + SZ_16K - 1,
  688. .flags = IORESOURCE_MEM,
  689. },
  690. [1] = {
  691. .start = AT91SAM9RL_ID_US1,
  692. .end = AT91SAM9RL_ID_US1,
  693. .flags = IORESOURCE_IRQ,
  694. },
  695. };
  696. static struct atmel_uart_data uart1_data = {
  697. .use_dma_tx = 1,
  698. .use_dma_rx = 1,
  699. };
  700. static u64 uart1_dmamask = DMA_BIT_MASK(32);
  701. static struct platform_device at91sam9rl_uart1_device = {
  702. .name = "atmel_usart",
  703. .id = 2,
  704. .dev = {
  705. .dma_mask = &uart1_dmamask,
  706. .coherent_dma_mask = DMA_BIT_MASK(32),
  707. .platform_data = &uart1_data,
  708. },
  709. .resource = uart1_resources,
  710. .num_resources = ARRAY_SIZE(uart1_resources),
  711. };
  712. static inline void configure_usart1_pins(unsigned pins)
  713. {
  714. at91_set_A_periph(AT91_PIN_PA11, 1); /* TXD1 */
  715. at91_set_A_periph(AT91_PIN_PA12, 0); /* RXD1 */
  716. if (pins & ATMEL_UART_RTS)
  717. at91_set_B_periph(AT91_PIN_PA18, 0); /* RTS1 */
  718. if (pins & ATMEL_UART_CTS)
  719. at91_set_B_periph(AT91_PIN_PA19, 0); /* CTS1 */
  720. }
  721. static struct resource uart2_resources[] = {
  722. [0] = {
  723. .start = AT91SAM9RL_BASE_US2,
  724. .end = AT91SAM9RL_BASE_US2 + SZ_16K - 1,
  725. .flags = IORESOURCE_MEM,
  726. },
  727. [1] = {
  728. .start = AT91SAM9RL_ID_US2,
  729. .end = AT91SAM9RL_ID_US2,
  730. .flags = IORESOURCE_IRQ,
  731. },
  732. };
  733. static struct atmel_uart_data uart2_data = {
  734. .use_dma_tx = 1,
  735. .use_dma_rx = 1,
  736. };
  737. static u64 uart2_dmamask = DMA_BIT_MASK(32);
  738. static struct platform_device at91sam9rl_uart2_device = {
  739. .name = "atmel_usart",
  740. .id = 3,
  741. .dev = {
  742. .dma_mask = &uart2_dmamask,
  743. .coherent_dma_mask = DMA_BIT_MASK(32),
  744. .platform_data = &uart2_data,
  745. },
  746. .resource = uart2_resources,
  747. .num_resources = ARRAY_SIZE(uart2_resources),
  748. };
  749. static inline void configure_usart2_pins(unsigned pins)
  750. {
  751. at91_set_A_periph(AT91_PIN_PA13, 1); /* TXD2 */
  752. at91_set_A_periph(AT91_PIN_PA14, 0); /* RXD2 */
  753. if (pins & ATMEL_UART_RTS)
  754. at91_set_A_periph(AT91_PIN_PA29, 0); /* RTS2 */
  755. if (pins & ATMEL_UART_CTS)
  756. at91_set_A_periph(AT91_PIN_PA30, 0); /* CTS2 */
  757. }
  758. static struct resource uart3_resources[] = {
  759. [0] = {
  760. .start = AT91SAM9RL_BASE_US3,
  761. .end = AT91SAM9RL_BASE_US3 + SZ_16K - 1,
  762. .flags = IORESOURCE_MEM,
  763. },
  764. [1] = {
  765. .start = AT91SAM9RL_ID_US3,
  766. .end = AT91SAM9RL_ID_US3,
  767. .flags = IORESOURCE_IRQ,
  768. },
  769. };
  770. static struct atmel_uart_data uart3_data = {
  771. .use_dma_tx = 1,
  772. .use_dma_rx = 1,
  773. };
  774. static u64 uart3_dmamask = DMA_BIT_MASK(32);
  775. static struct platform_device at91sam9rl_uart3_device = {
  776. .name = "atmel_usart",
  777. .id = 4,
  778. .dev = {
  779. .dma_mask = &uart3_dmamask,
  780. .coherent_dma_mask = DMA_BIT_MASK(32),
  781. .platform_data = &uart3_data,
  782. },
  783. .resource = uart3_resources,
  784. .num_resources = ARRAY_SIZE(uart3_resources),
  785. };
  786. static inline void configure_usart3_pins(unsigned pins)
  787. {
  788. at91_set_A_periph(AT91_PIN_PB0, 1); /* TXD3 */
  789. at91_set_A_periph(AT91_PIN_PB1, 0); /* RXD3 */
  790. if (pins & ATMEL_UART_RTS)
  791. at91_set_B_periph(AT91_PIN_PD4, 0); /* RTS3 */
  792. if (pins & ATMEL_UART_CTS)
  793. at91_set_B_periph(AT91_PIN_PD3, 0); /* CTS3 */
  794. }
  795. static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
  796. struct platform_device *atmel_default_console_device; /* the serial console device */
  797. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
  798. {
  799. struct platform_device *pdev;
  800. switch (id) {
  801. case 0: /* DBGU */
  802. pdev = &at91sam9rl_dbgu_device;
  803. configure_dbgu_pins();
  804. at91_clock_associate("mck", &pdev->dev, "usart");
  805. break;
  806. case AT91SAM9RL_ID_US0:
  807. pdev = &at91sam9rl_uart0_device;
  808. configure_usart0_pins(pins);
  809. at91_clock_associate("usart0_clk", &pdev->dev, "usart");
  810. break;
  811. case AT91SAM9RL_ID_US1:
  812. pdev = &at91sam9rl_uart1_device;
  813. configure_usart1_pins(pins);
  814. at91_clock_associate("usart1_clk", &pdev->dev, "usart");
  815. break;
  816. case AT91SAM9RL_ID_US2:
  817. pdev = &at91sam9rl_uart2_device;
  818. configure_usart2_pins(pins);
  819. at91_clock_associate("usart2_clk", &pdev->dev, "usart");
  820. break;
  821. case AT91SAM9RL_ID_US3:
  822. pdev = &at91sam9rl_uart3_device;
  823. configure_usart3_pins(pins);
  824. at91_clock_associate("usart3_clk", &pdev->dev, "usart");
  825. break;
  826. default:
  827. return;
  828. }
  829. pdev->id = portnr; /* update to mapped ID */
  830. if (portnr < ATMEL_MAX_UART)
  831. at91_uarts[portnr] = pdev;
  832. }
  833. void __init at91_set_serial_console(unsigned portnr)
  834. {
  835. if (portnr < ATMEL_MAX_UART)
  836. atmel_default_console_device = at91_uarts[portnr];
  837. }
  838. void __init at91_add_device_serial(void)
  839. {
  840. int i;
  841. for (i = 0; i < ATMEL_MAX_UART; i++) {
  842. if (at91_uarts[i])
  843. platform_device_register(at91_uarts[i]);
  844. }
  845. if (!atmel_default_console_device)
  846. printk(KERN_INFO "AT91: No default serial console defined.\n");
  847. }
  848. #else
  849. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
  850. void __init at91_set_serial_console(unsigned portnr) {}
  851. void __init at91_add_device_serial(void) {}
  852. #endif
  853. /* -------------------------------------------------------------------- */
  854. /*
  855. * These devices are always present and don't need any board-specific
  856. * setup.
  857. */
  858. static int __init at91_add_standard_devices(void)
  859. {
  860. at91_add_device_rtc();
  861. at91_add_device_rtt();
  862. at91_add_device_watchdog();
  863. at91_add_device_tc();
  864. return 0;
  865. }
  866. arch_initcall(at91_add_standard_devices);