at91sam9260_devices.c 28 KB

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