at91sam9260_devices.c 28 KB

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