at91sam9g45_devices.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230
  1. /*
  2. * On-Chip devices setup code for the AT91SAM9G45 family
  3. *
  4. * Copyright (C) 2009 Atmel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. */
  12. #include <asm/mach/arch.h>
  13. #include <asm/mach/map.h>
  14. #include <linux/dma-mapping.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/i2c-gpio.h>
  17. #include <linux/fb.h>
  18. #include <video/atmel_lcdc.h>
  19. #include <mach/board.h>
  20. #include <mach/gpio.h>
  21. #include <mach/at91sam9g45.h>
  22. #include <mach/at91sam9g45_matrix.h>
  23. #include <mach/at91sam9_smc.h>
  24. #include "generic.h"
  25. /* --------------------------------------------------------------------
  26. * USB Host (OHCI)
  27. * -------------------------------------------------------------------- */
  28. #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
  29. static u64 ohci_dmamask = DMA_BIT_MASK(32);
  30. static struct at91_usbh_data usbh_ohci_data;
  31. static struct resource usbh_ohci_resources[] = {
  32. [0] = {
  33. .start = AT91SAM9G45_OHCI_BASE,
  34. .end = AT91SAM9G45_OHCI_BASE + SZ_1M - 1,
  35. .flags = IORESOURCE_MEM,
  36. },
  37. [1] = {
  38. .start = AT91SAM9G45_ID_UHPHS,
  39. .end = AT91SAM9G45_ID_UHPHS,
  40. .flags = IORESOURCE_IRQ,
  41. },
  42. };
  43. static struct platform_device at91_usbh_ohci_device = {
  44. .name = "at91_ohci",
  45. .id = -1,
  46. .dev = {
  47. .dma_mask = &ohci_dmamask,
  48. .coherent_dma_mask = DMA_BIT_MASK(32),
  49. .platform_data = &usbh_ohci_data,
  50. },
  51. .resource = usbh_ohci_resources,
  52. .num_resources = ARRAY_SIZE(usbh_ohci_resources),
  53. };
  54. void __init at91_add_device_usbh_ohci(struct at91_usbh_data *data)
  55. {
  56. int i;
  57. if (!data)
  58. return;
  59. /* Enable VBus control for UHP ports */
  60. for (i = 0; i < data->ports; i++) {
  61. if (data->vbus_pin[i])
  62. at91_set_gpio_output(data->vbus_pin[i], 0);
  63. }
  64. usbh_ohci_data = *data;
  65. platform_device_register(&at91_usbh_ohci_device);
  66. }
  67. #else
  68. void __init at91_add_device_usbh_ohci(struct at91_usbh_data *data) {}
  69. #endif
  70. /* --------------------------------------------------------------------
  71. * USB HS Device (Gadget)
  72. * -------------------------------------------------------------------- */
  73. #if defined(CONFIG_USB_GADGET_ATMEL_USBA) || defined(CONFIG_USB_GADGET_ATMEL_USBA_MODULE)
  74. static struct resource usba_udc_resources[] = {
  75. [0] = {
  76. .start = AT91SAM9G45_UDPHS_FIFO,
  77. .end = AT91SAM9G45_UDPHS_FIFO + SZ_512K - 1,
  78. .flags = IORESOURCE_MEM,
  79. },
  80. [1] = {
  81. .start = AT91SAM9G45_BASE_UDPHS,
  82. .end = AT91SAM9G45_BASE_UDPHS + SZ_1K - 1,
  83. .flags = IORESOURCE_MEM,
  84. },
  85. [2] = {
  86. .start = AT91SAM9G45_ID_UDPHS,
  87. .end = AT91SAM9G45_ID_UDPHS,
  88. .flags = IORESOURCE_IRQ,
  89. },
  90. };
  91. #define EP(nam, idx, maxpkt, maxbk, dma, isoc) \
  92. [idx] = { \
  93. .name = nam, \
  94. .index = idx, \
  95. .fifo_size = maxpkt, \
  96. .nr_banks = maxbk, \
  97. .can_dma = dma, \
  98. .can_isoc = isoc, \
  99. }
  100. static struct usba_ep_data usba_udc_ep[] __initdata = {
  101. EP("ep0", 0, 64, 1, 0, 0),
  102. EP("ep1", 1, 1024, 2, 1, 1),
  103. EP("ep2", 2, 1024, 2, 1, 1),
  104. EP("ep3", 3, 1024, 3, 1, 0),
  105. EP("ep4", 4, 1024, 3, 1, 0),
  106. EP("ep5", 5, 1024, 3, 1, 1),
  107. EP("ep6", 6, 1024, 3, 1, 1),
  108. };
  109. #undef EP
  110. /*
  111. * pdata doesn't have room for any endpoints, so we need to
  112. * append room for the ones we need right after it.
  113. */
  114. static struct {
  115. struct usba_platform_data pdata;
  116. struct usba_ep_data ep[7];
  117. } usba_udc_data;
  118. static struct platform_device at91_usba_udc_device = {
  119. .name = "atmel_usba_udc",
  120. .id = -1,
  121. .dev = {
  122. .platform_data = &usba_udc_data.pdata,
  123. },
  124. .resource = usba_udc_resources,
  125. .num_resources = ARRAY_SIZE(usba_udc_resources),
  126. };
  127. void __init at91_add_device_usba(struct usba_platform_data *data)
  128. {
  129. usba_udc_data.pdata.vbus_pin = -EINVAL;
  130. usba_udc_data.pdata.num_ep = ARRAY_SIZE(usba_udc_ep);
  131. memcpy(usba_udc_data.ep, usba_udc_ep, sizeof(usba_udc_ep));;
  132. if (data && data->vbus_pin > 0) {
  133. at91_set_gpio_input(data->vbus_pin, 0);
  134. at91_set_deglitch(data->vbus_pin, 1);
  135. usba_udc_data.pdata.vbus_pin = data->vbus_pin;
  136. }
  137. /* Pullup pin is handled internally by USB device peripheral */
  138. /* Clocks */
  139. at91_clock_associate("utmi_clk", &at91_usba_udc_device.dev, "hclk");
  140. at91_clock_associate("udphs_clk", &at91_usba_udc_device.dev, "pclk");
  141. platform_device_register(&at91_usba_udc_device);
  142. }
  143. #else
  144. void __init at91_add_device_usba(struct usba_platform_data *data) {}
  145. #endif
  146. /* --------------------------------------------------------------------
  147. * Ethernet
  148. * -------------------------------------------------------------------- */
  149. #if defined(CONFIG_MACB) || defined(CONFIG_MACB_MODULE)
  150. static u64 eth_dmamask = DMA_BIT_MASK(32);
  151. static struct at91_eth_data eth_data;
  152. static struct resource eth_resources[] = {
  153. [0] = {
  154. .start = AT91SAM9G45_BASE_EMAC,
  155. .end = AT91SAM9G45_BASE_EMAC + SZ_16K - 1,
  156. .flags = IORESOURCE_MEM,
  157. },
  158. [1] = {
  159. .start = AT91SAM9G45_ID_EMAC,
  160. .end = AT91SAM9G45_ID_EMAC,
  161. .flags = IORESOURCE_IRQ,
  162. },
  163. };
  164. static struct platform_device at91sam9g45_eth_device = {
  165. .name = "macb",
  166. .id = -1,
  167. .dev = {
  168. .dma_mask = &eth_dmamask,
  169. .coherent_dma_mask = DMA_BIT_MASK(32),
  170. .platform_data = &eth_data,
  171. },
  172. .resource = eth_resources,
  173. .num_resources = ARRAY_SIZE(eth_resources),
  174. };
  175. void __init at91_add_device_eth(struct at91_eth_data *data)
  176. {
  177. if (!data)
  178. return;
  179. if (data->phy_irq_pin) {
  180. at91_set_gpio_input(data->phy_irq_pin, 0);
  181. at91_set_deglitch(data->phy_irq_pin, 1);
  182. }
  183. /* Pins used for MII and RMII */
  184. at91_set_A_periph(AT91_PIN_PA17, 0); /* ETXCK_EREFCK */
  185. at91_set_A_periph(AT91_PIN_PA15, 0); /* ERXDV */
  186. at91_set_A_periph(AT91_PIN_PA12, 0); /* ERX0 */
  187. at91_set_A_periph(AT91_PIN_PA13, 0); /* ERX1 */
  188. at91_set_A_periph(AT91_PIN_PA16, 0); /* ERXER */
  189. at91_set_A_periph(AT91_PIN_PA14, 0); /* ETXEN */
  190. at91_set_A_periph(AT91_PIN_PA10, 0); /* ETX0 */
  191. at91_set_A_periph(AT91_PIN_PA11, 0); /* ETX1 */
  192. at91_set_A_periph(AT91_PIN_PA19, 0); /* EMDIO */
  193. at91_set_A_periph(AT91_PIN_PA18, 0); /* EMDC */
  194. if (!data->is_rmii) {
  195. at91_set_B_periph(AT91_PIN_PA29, 0); /* ECRS */
  196. at91_set_B_periph(AT91_PIN_PA30, 0); /* ECOL */
  197. at91_set_B_periph(AT91_PIN_PA8, 0); /* ERX2 */
  198. at91_set_B_periph(AT91_PIN_PA9, 0); /* ERX3 */
  199. at91_set_B_periph(AT91_PIN_PA28, 0); /* ERXCK */
  200. at91_set_B_periph(AT91_PIN_PA6, 0); /* ETX2 */
  201. at91_set_B_periph(AT91_PIN_PA7, 0); /* ETX3 */
  202. at91_set_B_periph(AT91_PIN_PA27, 0); /* ETXER */
  203. }
  204. eth_data = *data;
  205. platform_device_register(&at91sam9g45_eth_device);
  206. }
  207. #else
  208. void __init at91_add_device_eth(struct at91_eth_data *data) {}
  209. #endif
  210. /* --------------------------------------------------------------------
  211. * NAND / SmartMedia
  212. * -------------------------------------------------------------------- */
  213. #if defined(CONFIG_MTD_NAND_ATMEL) || defined(CONFIG_MTD_NAND_ATMEL_MODULE)
  214. static struct atmel_nand_data nand_data;
  215. #define NAND_BASE AT91_CHIPSELECT_3
  216. static struct resource nand_resources[] = {
  217. [0] = {
  218. .start = NAND_BASE,
  219. .end = NAND_BASE + SZ_256M - 1,
  220. .flags = IORESOURCE_MEM,
  221. },
  222. [1] = {
  223. .start = AT91_BASE_SYS + AT91_ECC,
  224. .end = AT91_BASE_SYS + AT91_ECC + SZ_512 - 1,
  225. .flags = IORESOURCE_MEM,
  226. }
  227. };
  228. static struct platform_device at91sam9g45_nand_device = {
  229. .name = "atmel_nand",
  230. .id = -1,
  231. .dev = {
  232. .platform_data = &nand_data,
  233. },
  234. .resource = nand_resources,
  235. .num_resources = ARRAY_SIZE(nand_resources),
  236. };
  237. void __init at91_add_device_nand(struct atmel_nand_data *data)
  238. {
  239. unsigned long csa;
  240. if (!data)
  241. return;
  242. csa = at91_sys_read(AT91_MATRIX_EBICSA);
  243. at91_sys_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_EBI_CS3A_SMC_SMARTMEDIA);
  244. /* enable pin */
  245. if (data->enable_pin)
  246. at91_set_gpio_output(data->enable_pin, 1);
  247. /* ready/busy pin */
  248. if (data->rdy_pin)
  249. at91_set_gpio_input(data->rdy_pin, 1);
  250. /* card detect pin */
  251. if (data->det_pin)
  252. at91_set_gpio_input(data->det_pin, 1);
  253. nand_data = *data;
  254. platform_device_register(&at91sam9g45_nand_device);
  255. }
  256. #else
  257. void __init at91_add_device_nand(struct atmel_nand_data *data) {}
  258. #endif
  259. /* --------------------------------------------------------------------
  260. * TWI (i2c)
  261. * -------------------------------------------------------------------- */
  262. /*
  263. * Prefer the GPIO code since the TWI controller isn't robust
  264. * (gets overruns and underruns under load) and can only issue
  265. * repeated STARTs in one scenario (the driver doesn't yet handle them).
  266. */
  267. #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
  268. static struct i2c_gpio_platform_data pdata_i2c0 = {
  269. .sda_pin = AT91_PIN_PA20,
  270. .sda_is_open_drain = 1,
  271. .scl_pin = AT91_PIN_PA21,
  272. .scl_is_open_drain = 1,
  273. .udelay = 2, /* ~100 kHz */
  274. };
  275. static struct platform_device at91sam9g45_twi0_device = {
  276. .name = "i2c-gpio",
  277. .id = 0,
  278. .dev.platform_data = &pdata_i2c0,
  279. };
  280. static struct i2c_gpio_platform_data pdata_i2c1 = {
  281. .sda_pin = AT91_PIN_PB10,
  282. .sda_is_open_drain = 1,
  283. .scl_pin = AT91_PIN_PB11,
  284. .scl_is_open_drain = 1,
  285. .udelay = 2, /* ~100 kHz */
  286. };
  287. static struct platform_device at91sam9g45_twi1_device = {
  288. .name = "i2c-gpio",
  289. .id = 1,
  290. .dev.platform_data = &pdata_i2c1,
  291. };
  292. void __init at91_add_device_i2c(short i2c_id, struct i2c_board_info *devices, int nr_devices)
  293. {
  294. i2c_register_board_info(i2c_id, devices, nr_devices);
  295. if (i2c_id == 0) {
  296. at91_set_GPIO_periph(AT91_PIN_PA20, 1); /* TWD (SDA) */
  297. at91_set_multi_drive(AT91_PIN_PA20, 1);
  298. at91_set_GPIO_periph(AT91_PIN_PA21, 1); /* TWCK (SCL) */
  299. at91_set_multi_drive(AT91_PIN_PA21, 1);
  300. platform_device_register(&at91sam9g45_twi0_device);
  301. } else {
  302. at91_set_GPIO_periph(AT91_PIN_PB10, 1); /* TWD (SDA) */
  303. at91_set_multi_drive(AT91_PIN_PB10, 1);
  304. at91_set_GPIO_periph(AT91_PIN_PB11, 1); /* TWCK (SCL) */
  305. at91_set_multi_drive(AT91_PIN_PB11, 1);
  306. platform_device_register(&at91sam9g45_twi1_device);
  307. }
  308. }
  309. #elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
  310. static struct resource twi0_resources[] = {
  311. [0] = {
  312. .start = AT91SAM9G45_BASE_TWI0,
  313. .end = AT91SAM9G45_BASE_TWI0 + SZ_16K - 1,
  314. .flags = IORESOURCE_MEM,
  315. },
  316. [1] = {
  317. .start = AT91SAM9G45_ID_TWI0,
  318. .end = AT91SAM9G45_ID_TWI0,
  319. .flags = IORESOURCE_IRQ,
  320. },
  321. };
  322. static struct platform_device at91sam9g45_twi0_device = {
  323. .name = "at91_i2c",
  324. .id = 0,
  325. .resource = twi0_resources,
  326. .num_resources = ARRAY_SIZE(twi0_resources),
  327. };
  328. static struct resource twi1_resources[] = {
  329. [0] = {
  330. .start = AT91SAM9G45_BASE_TWI1,
  331. .end = AT91SAM9G45_BASE_TWI1 + SZ_16K - 1,
  332. .flags = IORESOURCE_MEM,
  333. },
  334. [1] = {
  335. .start = AT91SAM9G45_ID_TWI1,
  336. .end = AT91SAM9G45_ID_TWI1,
  337. .flags = IORESOURCE_IRQ,
  338. },
  339. };
  340. static struct platform_device at91sam9g45_twi1_device = {
  341. .name = "at91_i2c",
  342. .id = 1,
  343. .resource = twi1_resources,
  344. .num_resources = ARRAY_SIZE(twi1_resources),
  345. };
  346. void __init at91_add_device_i2c(short i2c_id, struct i2c_board_info *devices, int nr_devices)
  347. {
  348. i2c_register_board_info(i2c_id, devices, nr_devices);
  349. /* pins used for TWI interface */
  350. if (i2c_id == 0) {
  351. at91_set_A_periph(AT91_PIN_PA20, 0); /* TWD */
  352. at91_set_multi_drive(AT91_PIN_PA20, 1);
  353. at91_set_A_periph(AT91_PIN_PA21, 0); /* TWCK */
  354. at91_set_multi_drive(AT91_PIN_PA21, 1);
  355. platform_device_register(&at91sam9g45_twi0_device);
  356. } else {
  357. at91_set_A_periph(AT91_PIN_PB10, 0); /* TWD */
  358. at91_set_multi_drive(AT91_PIN_PB10, 1);
  359. at91_set_A_periph(AT91_PIN_PB11, 0); /* TWCK */
  360. at91_set_multi_drive(AT91_PIN_PB11, 1);
  361. platform_device_register(&at91sam9g45_twi1_device);
  362. }
  363. }
  364. #else
  365. void __init at91_add_device_i2c(short i2c_id, struct i2c_board_info *devices, int nr_devices) {}
  366. #endif
  367. /* --------------------------------------------------------------------
  368. * SPI
  369. * -------------------------------------------------------------------- */
  370. #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
  371. static u64 spi_dmamask = DMA_BIT_MASK(32);
  372. static struct resource spi0_resources[] = {
  373. [0] = {
  374. .start = AT91SAM9G45_BASE_SPI0,
  375. .end = AT91SAM9G45_BASE_SPI0 + SZ_16K - 1,
  376. .flags = IORESOURCE_MEM,
  377. },
  378. [1] = {
  379. .start = AT91SAM9G45_ID_SPI0,
  380. .end = AT91SAM9G45_ID_SPI0,
  381. .flags = IORESOURCE_IRQ,
  382. },
  383. };
  384. static struct platform_device at91sam9g45_spi0_device = {
  385. .name = "atmel_spi",
  386. .id = 0,
  387. .dev = {
  388. .dma_mask = &spi_dmamask,
  389. .coherent_dma_mask = DMA_BIT_MASK(32),
  390. },
  391. .resource = spi0_resources,
  392. .num_resources = ARRAY_SIZE(spi0_resources),
  393. };
  394. static const unsigned spi0_standard_cs[4] = { AT91_PIN_PB3, AT91_PIN_PB18, AT91_PIN_PB19, AT91_PIN_PD27 };
  395. static struct resource spi1_resources[] = {
  396. [0] = {
  397. .start = AT91SAM9G45_BASE_SPI1,
  398. .end = AT91SAM9G45_BASE_SPI1 + SZ_16K - 1,
  399. .flags = IORESOURCE_MEM,
  400. },
  401. [1] = {
  402. .start = AT91SAM9G45_ID_SPI1,
  403. .end = AT91SAM9G45_ID_SPI1,
  404. .flags = IORESOURCE_IRQ,
  405. },
  406. };
  407. static struct platform_device at91sam9g45_spi1_device = {
  408. .name = "atmel_spi",
  409. .id = 1,
  410. .dev = {
  411. .dma_mask = &spi_dmamask,
  412. .coherent_dma_mask = DMA_BIT_MASK(32),
  413. },
  414. .resource = spi1_resources,
  415. .num_resources = ARRAY_SIZE(spi1_resources),
  416. };
  417. static const unsigned spi1_standard_cs[4] = { AT91_PIN_PB17, AT91_PIN_PD28, AT91_PIN_PD18, AT91_PIN_PD19 };
  418. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
  419. {
  420. int i;
  421. unsigned long cs_pin;
  422. short enable_spi0 = 0;
  423. short enable_spi1 = 0;
  424. /* Choose SPI chip-selects */
  425. for (i = 0; i < nr_devices; i++) {
  426. if (devices[i].controller_data)
  427. cs_pin = (unsigned long) devices[i].controller_data;
  428. else if (devices[i].bus_num == 0)
  429. cs_pin = spi0_standard_cs[devices[i].chip_select];
  430. else
  431. cs_pin = spi1_standard_cs[devices[i].chip_select];
  432. if (devices[i].bus_num == 0)
  433. enable_spi0 = 1;
  434. else
  435. enable_spi1 = 1;
  436. /* enable chip-select pin */
  437. at91_set_gpio_output(cs_pin, 1);
  438. /* pass chip-select pin to driver */
  439. devices[i].controller_data = (void *) cs_pin;
  440. }
  441. spi_register_board_info(devices, nr_devices);
  442. /* Configure SPI bus(es) */
  443. if (enable_spi0) {
  444. at91_set_A_periph(AT91_PIN_PB0, 0); /* SPI0_MISO */
  445. at91_set_A_periph(AT91_PIN_PB1, 0); /* SPI0_MOSI */
  446. at91_set_A_periph(AT91_PIN_PB2, 0); /* SPI0_SPCK */
  447. at91_clock_associate("spi0_clk", &at91sam9g45_spi0_device.dev, "spi_clk");
  448. platform_device_register(&at91sam9g45_spi0_device);
  449. }
  450. if (enable_spi1) {
  451. at91_set_A_periph(AT91_PIN_PB14, 0); /* SPI1_MISO */
  452. at91_set_A_periph(AT91_PIN_PB15, 0); /* SPI1_MOSI */
  453. at91_set_A_periph(AT91_PIN_PB16, 0); /* SPI1_SPCK */
  454. at91_clock_associate("spi1_clk", &at91sam9g45_spi1_device.dev, "spi_clk");
  455. platform_device_register(&at91sam9g45_spi1_device);
  456. }
  457. }
  458. #else
  459. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
  460. #endif
  461. /* --------------------------------------------------------------------
  462. * LCD Controller
  463. * -------------------------------------------------------------------- */
  464. #if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
  465. static u64 lcdc_dmamask = DMA_BIT_MASK(32);
  466. static struct atmel_lcdfb_info lcdc_data;
  467. static struct resource lcdc_resources[] = {
  468. [0] = {
  469. .start = AT91SAM9G45_LCDC_BASE,
  470. .end = AT91SAM9G45_LCDC_BASE + SZ_4K - 1,
  471. .flags = IORESOURCE_MEM,
  472. },
  473. [1] = {
  474. .start = AT91SAM9G45_ID_LCDC,
  475. .end = AT91SAM9G45_ID_LCDC,
  476. .flags = IORESOURCE_IRQ,
  477. },
  478. };
  479. static struct platform_device at91_lcdc_device = {
  480. .name = "atmel_lcdfb",
  481. .id = 0,
  482. .dev = {
  483. .dma_mask = &lcdc_dmamask,
  484. .coherent_dma_mask = DMA_BIT_MASK(32),
  485. .platform_data = &lcdc_data,
  486. },
  487. .resource = lcdc_resources,
  488. .num_resources = ARRAY_SIZE(lcdc_resources),
  489. };
  490. void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data)
  491. {
  492. if (!data)
  493. return;
  494. at91_set_A_periph(AT91_PIN_PE0, 0); /* LCDDPWR */
  495. at91_set_A_periph(AT91_PIN_PE2, 0); /* LCDCC */
  496. at91_set_A_periph(AT91_PIN_PE3, 0); /* LCDVSYNC */
  497. at91_set_A_periph(AT91_PIN_PE4, 0); /* LCDHSYNC */
  498. at91_set_A_periph(AT91_PIN_PE5, 0); /* LCDDOTCK */
  499. at91_set_A_periph(AT91_PIN_PE6, 0); /* LCDDEN */
  500. at91_set_A_periph(AT91_PIN_PE7, 0); /* LCDD0 */
  501. at91_set_A_periph(AT91_PIN_PE8, 0); /* LCDD1 */
  502. at91_set_A_periph(AT91_PIN_PE9, 0); /* LCDD2 */
  503. at91_set_A_periph(AT91_PIN_PE10, 0); /* LCDD3 */
  504. at91_set_A_periph(AT91_PIN_PE11, 0); /* LCDD4 */
  505. at91_set_A_periph(AT91_PIN_PE12, 0); /* LCDD5 */
  506. at91_set_A_periph(AT91_PIN_PE13, 0); /* LCDD6 */
  507. at91_set_A_periph(AT91_PIN_PE14, 0); /* LCDD7 */
  508. at91_set_A_periph(AT91_PIN_PE15, 0); /* LCDD8 */
  509. at91_set_A_periph(AT91_PIN_PE16, 0); /* LCDD9 */
  510. at91_set_A_periph(AT91_PIN_PE17, 0); /* LCDD10 */
  511. at91_set_A_periph(AT91_PIN_PE18, 0); /* LCDD11 */
  512. at91_set_A_periph(AT91_PIN_PE19, 0); /* LCDD12 */
  513. at91_set_A_periph(AT91_PIN_PE20, 0); /* LCDD13 */
  514. at91_set_A_periph(AT91_PIN_PE21, 0); /* LCDD14 */
  515. at91_set_A_periph(AT91_PIN_PE22, 0); /* LCDD15 */
  516. at91_set_A_periph(AT91_PIN_PE23, 0); /* LCDD16 */
  517. at91_set_A_periph(AT91_PIN_PE24, 0); /* LCDD17 */
  518. at91_set_A_periph(AT91_PIN_PE25, 0); /* LCDD18 */
  519. at91_set_A_periph(AT91_PIN_PE26, 0); /* LCDD19 */
  520. at91_set_A_periph(AT91_PIN_PE27, 0); /* LCDD20 */
  521. at91_set_A_periph(AT91_PIN_PE28, 0); /* LCDD21 */
  522. at91_set_A_periph(AT91_PIN_PE29, 0); /* LCDD22 */
  523. at91_set_A_periph(AT91_PIN_PE30, 0); /* LCDD23 */
  524. lcdc_data = *data;
  525. platform_device_register(&at91_lcdc_device);
  526. }
  527. #else
  528. void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data) {}
  529. #endif
  530. /* --------------------------------------------------------------------
  531. * Timer/Counter block
  532. * -------------------------------------------------------------------- */
  533. #ifdef CONFIG_ATMEL_TCLIB
  534. static struct resource tcb0_resources[] = {
  535. [0] = {
  536. .start = AT91SAM9G45_BASE_TCB0,
  537. .end = AT91SAM9G45_BASE_TCB0 + SZ_16K - 1,
  538. .flags = IORESOURCE_MEM,
  539. },
  540. [1] = {
  541. .start = AT91SAM9G45_ID_TCB,
  542. .end = AT91SAM9G45_ID_TCB,
  543. .flags = IORESOURCE_IRQ,
  544. },
  545. };
  546. static struct platform_device at91sam9g45_tcb0_device = {
  547. .name = "atmel_tcb",
  548. .id = 0,
  549. .resource = tcb0_resources,
  550. .num_resources = ARRAY_SIZE(tcb0_resources),
  551. };
  552. /* TCB1 begins with TC3 */
  553. static struct resource tcb1_resources[] = {
  554. [0] = {
  555. .start = AT91SAM9G45_BASE_TCB1,
  556. .end = AT91SAM9G45_BASE_TCB1 + SZ_16K - 1,
  557. .flags = IORESOURCE_MEM,
  558. },
  559. [1] = {
  560. .start = AT91SAM9G45_ID_TCB,
  561. .end = AT91SAM9G45_ID_TCB,
  562. .flags = IORESOURCE_IRQ,
  563. },
  564. };
  565. static struct platform_device at91sam9g45_tcb1_device = {
  566. .name = "atmel_tcb",
  567. .id = 1,
  568. .resource = tcb1_resources,
  569. .num_resources = ARRAY_SIZE(tcb1_resources),
  570. };
  571. static void __init at91_add_device_tc(void)
  572. {
  573. /* this chip has one clock and irq for all six TC channels */
  574. at91_clock_associate("tcb_clk", &at91sam9g45_tcb0_device.dev, "t0_clk");
  575. platform_device_register(&at91sam9g45_tcb0_device);
  576. at91_clock_associate("tcb_clk", &at91sam9g45_tcb1_device.dev, "t0_clk");
  577. platform_device_register(&at91sam9g45_tcb1_device);
  578. }
  579. #else
  580. static void __init at91_add_device_tc(void) { }
  581. #endif
  582. /* --------------------------------------------------------------------
  583. * RTC
  584. * -------------------------------------------------------------------- */
  585. #if defined(CONFIG_RTC_DRV_AT91RM9200) || defined(CONFIG_RTC_DRV_AT91RM9200_MODULE)
  586. static struct platform_device at91sam9g45_rtc_device = {
  587. .name = "at91_rtc",
  588. .id = -1,
  589. .num_resources = 0,
  590. };
  591. static void __init at91_add_device_rtc(void)
  592. {
  593. platform_device_register(&at91sam9g45_rtc_device);
  594. }
  595. #else
  596. static void __init at91_add_device_rtc(void) {}
  597. #endif
  598. /* --------------------------------------------------------------------
  599. * RTT
  600. * -------------------------------------------------------------------- */
  601. static struct resource rtt_resources[] = {
  602. {
  603. .start = AT91_BASE_SYS + AT91_RTT,
  604. .end = AT91_BASE_SYS + AT91_RTT + SZ_16 - 1,
  605. .flags = IORESOURCE_MEM,
  606. }
  607. };
  608. static struct platform_device at91sam9g45_rtt_device = {
  609. .name = "at91_rtt",
  610. .id = 0,
  611. .resource = rtt_resources,
  612. .num_resources = ARRAY_SIZE(rtt_resources),
  613. };
  614. static void __init at91_add_device_rtt(void)
  615. {
  616. platform_device_register(&at91sam9g45_rtt_device);
  617. }
  618. /* --------------------------------------------------------------------
  619. * Watchdog
  620. * -------------------------------------------------------------------- */
  621. #if defined(CONFIG_AT91SAM9_WATCHDOG) || defined(CONFIG_AT91SAM9_WATCHDOG_MODULE)
  622. static struct platform_device at91sam9g45_wdt_device = {
  623. .name = "at91_wdt",
  624. .id = -1,
  625. .num_resources = 0,
  626. };
  627. static void __init at91_add_device_watchdog(void)
  628. {
  629. platform_device_register(&at91sam9g45_wdt_device);
  630. }
  631. #else
  632. static void __init at91_add_device_watchdog(void) {}
  633. #endif
  634. /* --------------------------------------------------------------------
  635. * PWM
  636. * --------------------------------------------------------------------*/
  637. #if defined(CONFIG_ATMEL_PWM) || defined(CONFIG_ATMEL_PWM_MODULE)
  638. static u32 pwm_mask;
  639. static struct resource pwm_resources[] = {
  640. [0] = {
  641. .start = AT91SAM9G45_BASE_PWMC,
  642. .end = AT91SAM9G45_BASE_PWMC + SZ_16K - 1,
  643. .flags = IORESOURCE_MEM,
  644. },
  645. [1] = {
  646. .start = AT91SAM9G45_ID_PWMC,
  647. .end = AT91SAM9G45_ID_PWMC,
  648. .flags = IORESOURCE_IRQ,
  649. },
  650. };
  651. static struct platform_device at91sam9g45_pwm0_device = {
  652. .name = "atmel_pwm",
  653. .id = -1,
  654. .dev = {
  655. .platform_data = &pwm_mask,
  656. },
  657. .resource = pwm_resources,
  658. .num_resources = ARRAY_SIZE(pwm_resources),
  659. };
  660. void __init at91_add_device_pwm(u32 mask)
  661. {
  662. if (mask & (1 << AT91_PWM0))
  663. at91_set_B_periph(AT91_PIN_PD24, 1); /* enable PWM0 */
  664. if (mask & (1 << AT91_PWM1))
  665. at91_set_B_periph(AT91_PIN_PD31, 1); /* enable PWM1 */
  666. if (mask & (1 << AT91_PWM2))
  667. at91_set_B_periph(AT91_PIN_PD26, 1); /* enable PWM2 */
  668. if (mask & (1 << AT91_PWM3))
  669. at91_set_B_periph(AT91_PIN_PD0, 1); /* enable PWM3 */
  670. pwm_mask = mask;
  671. platform_device_register(&at91sam9g45_pwm0_device);
  672. }
  673. #else
  674. void __init at91_add_device_pwm(u32 mask) {}
  675. #endif
  676. /* --------------------------------------------------------------------
  677. * SSC -- Synchronous Serial Controller
  678. * -------------------------------------------------------------------- */
  679. #if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
  680. static u64 ssc0_dmamask = DMA_BIT_MASK(32);
  681. static struct resource ssc0_resources[] = {
  682. [0] = {
  683. .start = AT91SAM9G45_BASE_SSC0,
  684. .end = AT91SAM9G45_BASE_SSC0 + SZ_16K - 1,
  685. .flags = IORESOURCE_MEM,
  686. },
  687. [1] = {
  688. .start = AT91SAM9G45_ID_SSC0,
  689. .end = AT91SAM9G45_ID_SSC0,
  690. .flags = IORESOURCE_IRQ,
  691. },
  692. };
  693. static struct platform_device at91sam9g45_ssc0_device = {
  694. .name = "ssc",
  695. .id = 0,
  696. .dev = {
  697. .dma_mask = &ssc0_dmamask,
  698. .coherent_dma_mask = DMA_BIT_MASK(32),
  699. },
  700. .resource = ssc0_resources,
  701. .num_resources = ARRAY_SIZE(ssc0_resources),
  702. };
  703. static inline void configure_ssc0_pins(unsigned pins)
  704. {
  705. if (pins & ATMEL_SSC_TF)
  706. at91_set_A_periph(AT91_PIN_PD1, 1);
  707. if (pins & ATMEL_SSC_TK)
  708. at91_set_A_periph(AT91_PIN_PD0, 1);
  709. if (pins & ATMEL_SSC_TD)
  710. at91_set_A_periph(AT91_PIN_PD2, 1);
  711. if (pins & ATMEL_SSC_RD)
  712. at91_set_A_periph(AT91_PIN_PD3, 1);
  713. if (pins & ATMEL_SSC_RK)
  714. at91_set_A_periph(AT91_PIN_PD4, 1);
  715. if (pins & ATMEL_SSC_RF)
  716. at91_set_A_periph(AT91_PIN_PD5, 1);
  717. }
  718. static u64 ssc1_dmamask = DMA_BIT_MASK(32);
  719. static struct resource ssc1_resources[] = {
  720. [0] = {
  721. .start = AT91SAM9G45_BASE_SSC1,
  722. .end = AT91SAM9G45_BASE_SSC1 + SZ_16K - 1,
  723. .flags = IORESOURCE_MEM,
  724. },
  725. [1] = {
  726. .start = AT91SAM9G45_ID_SSC1,
  727. .end = AT91SAM9G45_ID_SSC1,
  728. .flags = IORESOURCE_IRQ,
  729. },
  730. };
  731. static struct platform_device at91sam9g45_ssc1_device = {
  732. .name = "ssc",
  733. .id = 1,
  734. .dev = {
  735. .dma_mask = &ssc1_dmamask,
  736. .coherent_dma_mask = DMA_BIT_MASK(32),
  737. },
  738. .resource = ssc1_resources,
  739. .num_resources = ARRAY_SIZE(ssc1_resources),
  740. };
  741. static inline void configure_ssc1_pins(unsigned pins)
  742. {
  743. if (pins & ATMEL_SSC_TF)
  744. at91_set_A_periph(AT91_PIN_PD14, 1);
  745. if (pins & ATMEL_SSC_TK)
  746. at91_set_A_periph(AT91_PIN_PD12, 1);
  747. if (pins & ATMEL_SSC_TD)
  748. at91_set_A_periph(AT91_PIN_PD10, 1);
  749. if (pins & ATMEL_SSC_RD)
  750. at91_set_A_periph(AT91_PIN_PD11, 1);
  751. if (pins & ATMEL_SSC_RK)
  752. at91_set_A_periph(AT91_PIN_PD13, 1);
  753. if (pins & ATMEL_SSC_RF)
  754. at91_set_A_periph(AT91_PIN_PD15, 1);
  755. }
  756. /*
  757. * SSC controllers are accessed through library code, instead of any
  758. * kind of all-singing/all-dancing driver. For example one could be
  759. * used by a particular I2S audio codec's driver, while another one
  760. * on the same system might be used by a custom data capture driver.
  761. */
  762. void __init at91_add_device_ssc(unsigned id, unsigned pins)
  763. {
  764. struct platform_device *pdev;
  765. /*
  766. * NOTE: caller is responsible for passing information matching
  767. * "pins" to whatever will be using each particular controller.
  768. */
  769. switch (id) {
  770. case AT91SAM9G45_ID_SSC0:
  771. pdev = &at91sam9g45_ssc0_device;
  772. configure_ssc0_pins(pins);
  773. at91_clock_associate("ssc0_clk", &pdev->dev, "pclk");
  774. break;
  775. case AT91SAM9G45_ID_SSC1:
  776. pdev = &at91sam9g45_ssc1_device;
  777. configure_ssc1_pins(pins);
  778. at91_clock_associate("ssc1_clk", &pdev->dev, "pclk");
  779. break;
  780. default:
  781. return;
  782. }
  783. platform_device_register(pdev);
  784. }
  785. #else
  786. void __init at91_add_device_ssc(unsigned id, unsigned pins) {}
  787. #endif
  788. /* --------------------------------------------------------------------
  789. * UART
  790. * -------------------------------------------------------------------- */
  791. #if defined(CONFIG_SERIAL_ATMEL)
  792. static struct resource dbgu_resources[] = {
  793. [0] = {
  794. .start = AT91_VA_BASE_SYS + AT91_DBGU,
  795. .end = AT91_VA_BASE_SYS + AT91_DBGU + SZ_512 - 1,
  796. .flags = IORESOURCE_MEM,
  797. },
  798. [1] = {
  799. .start = AT91_ID_SYS,
  800. .end = AT91_ID_SYS,
  801. .flags = IORESOURCE_IRQ,
  802. },
  803. };
  804. static struct atmel_uart_data dbgu_data = {
  805. .use_dma_tx = 0,
  806. .use_dma_rx = 0,
  807. .regs = (void __iomem *)(AT91_VA_BASE_SYS + AT91_DBGU),
  808. };
  809. static u64 dbgu_dmamask = DMA_BIT_MASK(32);
  810. static struct platform_device at91sam9g45_dbgu_device = {
  811. .name = "atmel_usart",
  812. .id = 0,
  813. .dev = {
  814. .dma_mask = &dbgu_dmamask,
  815. .coherent_dma_mask = DMA_BIT_MASK(32),
  816. .platform_data = &dbgu_data,
  817. },
  818. .resource = dbgu_resources,
  819. .num_resources = ARRAY_SIZE(dbgu_resources),
  820. };
  821. static inline void configure_dbgu_pins(void)
  822. {
  823. at91_set_A_periph(AT91_PIN_PB12, 0); /* DRXD */
  824. at91_set_A_periph(AT91_PIN_PB13, 1); /* DTXD */
  825. }
  826. static struct resource uart0_resources[] = {
  827. [0] = {
  828. .start = AT91SAM9G45_BASE_US0,
  829. .end = AT91SAM9G45_BASE_US0 + SZ_16K - 1,
  830. .flags = IORESOURCE_MEM,
  831. },
  832. [1] = {
  833. .start = AT91SAM9G45_ID_US0,
  834. .end = AT91SAM9G45_ID_US0,
  835. .flags = IORESOURCE_IRQ,
  836. },
  837. };
  838. static struct atmel_uart_data uart0_data = {
  839. .use_dma_tx = 1,
  840. .use_dma_rx = 1,
  841. };
  842. static u64 uart0_dmamask = DMA_BIT_MASK(32);
  843. static struct platform_device at91sam9g45_uart0_device = {
  844. .name = "atmel_usart",
  845. .id = 1,
  846. .dev = {
  847. .dma_mask = &uart0_dmamask,
  848. .coherent_dma_mask = DMA_BIT_MASK(32),
  849. .platform_data = &uart0_data,
  850. },
  851. .resource = uart0_resources,
  852. .num_resources = ARRAY_SIZE(uart0_resources),
  853. };
  854. static inline void configure_usart0_pins(unsigned pins)
  855. {
  856. at91_set_A_periph(AT91_PIN_PB19, 1); /* TXD0 */
  857. at91_set_A_periph(AT91_PIN_PB18, 0); /* RXD0 */
  858. if (pins & ATMEL_UART_RTS)
  859. at91_set_B_periph(AT91_PIN_PB17, 0); /* RTS0 */
  860. if (pins & ATMEL_UART_CTS)
  861. at91_set_B_periph(AT91_PIN_PB15, 0); /* CTS0 */
  862. }
  863. static struct resource uart1_resources[] = {
  864. [0] = {
  865. .start = AT91SAM9G45_BASE_US1,
  866. .end = AT91SAM9G45_BASE_US1 + SZ_16K - 1,
  867. .flags = IORESOURCE_MEM,
  868. },
  869. [1] = {
  870. .start = AT91SAM9G45_ID_US1,
  871. .end = AT91SAM9G45_ID_US1,
  872. .flags = IORESOURCE_IRQ,
  873. },
  874. };
  875. static struct atmel_uart_data uart1_data = {
  876. .use_dma_tx = 1,
  877. .use_dma_rx = 1,
  878. };
  879. static u64 uart1_dmamask = DMA_BIT_MASK(32);
  880. static struct platform_device at91sam9g45_uart1_device = {
  881. .name = "atmel_usart",
  882. .id = 2,
  883. .dev = {
  884. .dma_mask = &uart1_dmamask,
  885. .coherent_dma_mask = DMA_BIT_MASK(32),
  886. .platform_data = &uart1_data,
  887. },
  888. .resource = uart1_resources,
  889. .num_resources = ARRAY_SIZE(uart1_resources),
  890. };
  891. static inline void configure_usart1_pins(unsigned pins)
  892. {
  893. at91_set_A_periph(AT91_PIN_PB4, 1); /* TXD1 */
  894. at91_set_A_periph(AT91_PIN_PB5, 0); /* RXD1 */
  895. if (pins & ATMEL_UART_RTS)
  896. at91_set_A_periph(AT91_PIN_PD16, 0); /* RTS1 */
  897. if (pins & ATMEL_UART_CTS)
  898. at91_set_A_periph(AT91_PIN_PD17, 0); /* CTS1 */
  899. }
  900. static struct resource uart2_resources[] = {
  901. [0] = {
  902. .start = AT91SAM9G45_BASE_US2,
  903. .end = AT91SAM9G45_BASE_US2 + SZ_16K - 1,
  904. .flags = IORESOURCE_MEM,
  905. },
  906. [1] = {
  907. .start = AT91SAM9G45_ID_US2,
  908. .end = AT91SAM9G45_ID_US2,
  909. .flags = IORESOURCE_IRQ,
  910. },
  911. };
  912. static struct atmel_uart_data uart2_data = {
  913. .use_dma_tx = 1,
  914. .use_dma_rx = 1,
  915. };
  916. static u64 uart2_dmamask = DMA_BIT_MASK(32);
  917. static struct platform_device at91sam9g45_uart2_device = {
  918. .name = "atmel_usart",
  919. .id = 3,
  920. .dev = {
  921. .dma_mask = &uart2_dmamask,
  922. .coherent_dma_mask = DMA_BIT_MASK(32),
  923. .platform_data = &uart2_data,
  924. },
  925. .resource = uart2_resources,
  926. .num_resources = ARRAY_SIZE(uart2_resources),
  927. };
  928. static inline void configure_usart2_pins(unsigned pins)
  929. {
  930. at91_set_A_periph(AT91_PIN_PB6, 1); /* TXD2 */
  931. at91_set_A_periph(AT91_PIN_PB7, 0); /* RXD2 */
  932. if (pins & ATMEL_UART_RTS)
  933. at91_set_B_periph(AT91_PIN_PC9, 0); /* RTS2 */
  934. if (pins & ATMEL_UART_CTS)
  935. at91_set_B_periph(AT91_PIN_PC11, 0); /* CTS2 */
  936. }
  937. static struct resource uart3_resources[] = {
  938. [0] = {
  939. .start = AT91SAM9G45_BASE_US3,
  940. .end = AT91SAM9G45_BASE_US3 + SZ_16K - 1,
  941. .flags = IORESOURCE_MEM,
  942. },
  943. [1] = {
  944. .start = AT91SAM9G45_ID_US3,
  945. .end = AT91SAM9G45_ID_US3,
  946. .flags = IORESOURCE_IRQ,
  947. },
  948. };
  949. static struct atmel_uart_data uart3_data = {
  950. .use_dma_tx = 1,
  951. .use_dma_rx = 1,
  952. };
  953. static u64 uart3_dmamask = DMA_BIT_MASK(32);
  954. static struct platform_device at91sam9g45_uart3_device = {
  955. .name = "atmel_usart",
  956. .id = 4,
  957. .dev = {
  958. .dma_mask = &uart3_dmamask,
  959. .coherent_dma_mask = DMA_BIT_MASK(32),
  960. .platform_data = &uart3_data,
  961. },
  962. .resource = uart3_resources,
  963. .num_resources = ARRAY_SIZE(uart3_resources),
  964. };
  965. static inline void configure_usart3_pins(unsigned pins)
  966. {
  967. at91_set_A_periph(AT91_PIN_PB8, 1); /* TXD3 */
  968. at91_set_A_periph(AT91_PIN_PB9, 0); /* RXD3 */
  969. if (pins & ATMEL_UART_RTS)
  970. at91_set_B_periph(AT91_PIN_PA23, 0); /* RTS3 */
  971. if (pins & ATMEL_UART_CTS)
  972. at91_set_B_periph(AT91_PIN_PA24, 0); /* CTS3 */
  973. }
  974. static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
  975. struct platform_device *atmel_default_console_device; /* the serial console device */
  976. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
  977. {
  978. struct platform_device *pdev;
  979. switch (id) {
  980. case 0: /* DBGU */
  981. pdev = &at91sam9g45_dbgu_device;
  982. configure_dbgu_pins();
  983. at91_clock_associate("mck", &pdev->dev, "usart");
  984. break;
  985. case AT91SAM9G45_ID_US0:
  986. pdev = &at91sam9g45_uart0_device;
  987. configure_usart0_pins(pins);
  988. at91_clock_associate("usart0_clk", &pdev->dev, "usart");
  989. break;
  990. case AT91SAM9G45_ID_US1:
  991. pdev = &at91sam9g45_uart1_device;
  992. configure_usart1_pins(pins);
  993. at91_clock_associate("usart1_clk", &pdev->dev, "usart");
  994. break;
  995. case AT91SAM9G45_ID_US2:
  996. pdev = &at91sam9g45_uart2_device;
  997. configure_usart2_pins(pins);
  998. at91_clock_associate("usart2_clk", &pdev->dev, "usart");
  999. break;
  1000. case AT91SAM9G45_ID_US3:
  1001. pdev = &at91sam9g45_uart3_device;
  1002. configure_usart3_pins(pins);
  1003. at91_clock_associate("usart3_clk", &pdev->dev, "usart");
  1004. break;
  1005. default:
  1006. return;
  1007. }
  1008. pdev->id = portnr; /* update to mapped ID */
  1009. if (portnr < ATMEL_MAX_UART)
  1010. at91_uarts[portnr] = pdev;
  1011. }
  1012. void __init at91_set_serial_console(unsigned portnr)
  1013. {
  1014. if (portnr < ATMEL_MAX_UART)
  1015. atmel_default_console_device = at91_uarts[portnr];
  1016. }
  1017. void __init at91_add_device_serial(void)
  1018. {
  1019. int i;
  1020. for (i = 0; i < ATMEL_MAX_UART; i++) {
  1021. if (at91_uarts[i])
  1022. platform_device_register(at91_uarts[i]);
  1023. }
  1024. if (!atmel_default_console_device)
  1025. printk(KERN_INFO "AT91: No default serial console defined.\n");
  1026. }
  1027. #else
  1028. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
  1029. void __init at91_set_serial_console(unsigned portnr) {}
  1030. void __init at91_add_device_serial(void) {}
  1031. #endif
  1032. /* -------------------------------------------------------------------- */
  1033. /*
  1034. * These devices are always present and don't need any board-specific
  1035. * setup.
  1036. */
  1037. static int __init at91_add_standard_devices(void)
  1038. {
  1039. at91_add_device_rtc();
  1040. at91_add_device_rtt();
  1041. at91_add_device_watchdog();
  1042. at91_add_device_tc();
  1043. return 0;
  1044. }
  1045. arch_initcall(at91_add_standard_devices);