at91sam9260_devices.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166
  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, mode;
  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. if (cpu_is_at91sam9260()) {
  274. /* Timing for sam9260 */
  275. /* set the bus interface characteristics */
  276. at91_sys_write(AT91_SMC_SETUP(3), AT91_SMC_NWESETUP_(1) | AT91_SMC_NCS_WRSETUP_(0)
  277. | AT91_SMC_NRDSETUP_(1) | AT91_SMC_NCS_RDSETUP_(0));
  278. at91_sys_write(AT91_SMC_PULSE(3), AT91_SMC_NWEPULSE_(3) | AT91_SMC_NCS_WRPULSE_(3)
  279. | AT91_SMC_NRDPULSE_(3) | AT91_SMC_NCS_RDPULSE_(3));
  280. at91_sys_write(AT91_SMC_CYCLE(3), AT91_SMC_NWECYCLE_(5) | AT91_SMC_NRDCYCLE_(5));
  281. if (data->bus_width_16)
  282. mode = AT91_SMC_DBW_16;
  283. else
  284. mode = AT91_SMC_DBW_8;
  285. at91_sys_write(AT91_SMC_MODE(3), mode | AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_TDF_(2));
  286. }
  287. if (cpu_is_at91sam9g20()) {
  288. /* Timing for sam9g20 */
  289. /* set the bus interface characteristics */
  290. at91_sys_write(AT91_SMC_SETUP(3), AT91_SMC_NWESETUP_(2) | AT91_SMC_NCS_WRSETUP_(0)
  291. | AT91_SMC_NRDSETUP_(2) | AT91_SMC_NCS_RDSETUP_(0));
  292. at91_sys_write(AT91_SMC_PULSE(3), AT91_SMC_NWEPULSE_(4) | AT91_SMC_NCS_WRPULSE_(4)
  293. | AT91_SMC_NRDPULSE_(4) | AT91_SMC_NCS_RDPULSE_(4));
  294. at91_sys_write(AT91_SMC_CYCLE(3), AT91_SMC_NWECYCLE_(7) | AT91_SMC_NRDCYCLE_(7));
  295. if (data->bus_width_16)
  296. mode = AT91_SMC_DBW_16;
  297. else
  298. mode = AT91_SMC_DBW_8;
  299. at91_sys_write(AT91_SMC_MODE(3), mode | AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_TDF_(3));
  300. }
  301. /* enable pin */
  302. if (data->enable_pin)
  303. at91_set_gpio_output(data->enable_pin, 1);
  304. /* ready/busy pin */
  305. if (data->rdy_pin)
  306. at91_set_gpio_input(data->rdy_pin, 1);
  307. /* card detect pin */
  308. if (data->det_pin)
  309. at91_set_gpio_input(data->det_pin, 1);
  310. nand_data = *data;
  311. platform_device_register(&at91sam9260_nand_device);
  312. }
  313. #else
  314. void __init at91_add_device_nand(struct atmel_nand_data *data) {}
  315. #endif
  316. /* --------------------------------------------------------------------
  317. * TWI (i2c)
  318. * -------------------------------------------------------------------- */
  319. /*
  320. * Prefer the GPIO code since the TWI controller isn't robust
  321. * (gets overruns and underruns under load) and can only issue
  322. * repeated STARTs in one scenario (the driver doesn't yet handle them).
  323. */
  324. #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
  325. static struct i2c_gpio_platform_data pdata = {
  326. .sda_pin = AT91_PIN_PA23,
  327. .sda_is_open_drain = 1,
  328. .scl_pin = AT91_PIN_PA24,
  329. .scl_is_open_drain = 1,
  330. .udelay = 2, /* ~100 kHz */
  331. };
  332. static struct platform_device at91sam9260_twi_device = {
  333. .name = "i2c-gpio",
  334. .id = -1,
  335. .dev.platform_data = &pdata,
  336. };
  337. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  338. {
  339. at91_set_GPIO_periph(AT91_PIN_PA23, 1); /* TWD (SDA) */
  340. at91_set_multi_drive(AT91_PIN_PA23, 1);
  341. at91_set_GPIO_periph(AT91_PIN_PA24, 1); /* TWCK (SCL) */
  342. at91_set_multi_drive(AT91_PIN_PA24, 1);
  343. i2c_register_board_info(0, devices, nr_devices);
  344. platform_device_register(&at91sam9260_twi_device);
  345. }
  346. #elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
  347. static struct resource twi_resources[] = {
  348. [0] = {
  349. .start = AT91SAM9260_BASE_TWI,
  350. .end = AT91SAM9260_BASE_TWI + SZ_16K - 1,
  351. .flags = IORESOURCE_MEM,
  352. },
  353. [1] = {
  354. .start = AT91SAM9260_ID_TWI,
  355. .end = AT91SAM9260_ID_TWI,
  356. .flags = IORESOURCE_IRQ,
  357. },
  358. };
  359. static struct platform_device at91sam9260_twi_device = {
  360. .name = "at91_i2c",
  361. .id = -1,
  362. .resource = twi_resources,
  363. .num_resources = ARRAY_SIZE(twi_resources),
  364. };
  365. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  366. {
  367. /* pins used for TWI interface */
  368. at91_set_A_periph(AT91_PIN_PA23, 0); /* TWD */
  369. at91_set_multi_drive(AT91_PIN_PA23, 1);
  370. at91_set_A_periph(AT91_PIN_PA24, 0); /* TWCK */
  371. at91_set_multi_drive(AT91_PIN_PA24, 1);
  372. i2c_register_board_info(0, devices, nr_devices);
  373. platform_device_register(&at91sam9260_twi_device);
  374. }
  375. #else
  376. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {}
  377. #endif
  378. /* --------------------------------------------------------------------
  379. * SPI
  380. * -------------------------------------------------------------------- */
  381. #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
  382. static u64 spi_dmamask = DMA_BIT_MASK(32);
  383. static struct resource spi0_resources[] = {
  384. [0] = {
  385. .start = AT91SAM9260_BASE_SPI0,
  386. .end = AT91SAM9260_BASE_SPI0 + SZ_16K - 1,
  387. .flags = IORESOURCE_MEM,
  388. },
  389. [1] = {
  390. .start = AT91SAM9260_ID_SPI0,
  391. .end = AT91SAM9260_ID_SPI0,
  392. .flags = IORESOURCE_IRQ,
  393. },
  394. };
  395. static struct platform_device at91sam9260_spi0_device = {
  396. .name = "atmel_spi",
  397. .id = 0,
  398. .dev = {
  399. .dma_mask = &spi_dmamask,
  400. .coherent_dma_mask = DMA_BIT_MASK(32),
  401. },
  402. .resource = spi0_resources,
  403. .num_resources = ARRAY_SIZE(spi0_resources),
  404. };
  405. static const unsigned spi0_standard_cs[4] = { AT91_PIN_PA3, AT91_PIN_PC11, AT91_PIN_PC16, AT91_PIN_PC17 };
  406. static struct resource spi1_resources[] = {
  407. [0] = {
  408. .start = AT91SAM9260_BASE_SPI1,
  409. .end = AT91SAM9260_BASE_SPI1 + SZ_16K - 1,
  410. .flags = IORESOURCE_MEM,
  411. },
  412. [1] = {
  413. .start = AT91SAM9260_ID_SPI1,
  414. .end = AT91SAM9260_ID_SPI1,
  415. .flags = IORESOURCE_IRQ,
  416. },
  417. };
  418. static struct platform_device at91sam9260_spi1_device = {
  419. .name = "atmel_spi",
  420. .id = 1,
  421. .dev = {
  422. .dma_mask = &spi_dmamask,
  423. .coherent_dma_mask = DMA_BIT_MASK(32),
  424. },
  425. .resource = spi1_resources,
  426. .num_resources = ARRAY_SIZE(spi1_resources),
  427. };
  428. static const unsigned spi1_standard_cs[4] = { AT91_PIN_PB3, AT91_PIN_PC5, AT91_PIN_PC4, AT91_PIN_PC3 };
  429. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
  430. {
  431. int i;
  432. unsigned long cs_pin;
  433. short enable_spi0 = 0;
  434. short enable_spi1 = 0;
  435. /* Choose SPI chip-selects */
  436. for (i = 0; i < nr_devices; i++) {
  437. if (devices[i].controller_data)
  438. cs_pin = (unsigned long) devices[i].controller_data;
  439. else if (devices[i].bus_num == 0)
  440. cs_pin = spi0_standard_cs[devices[i].chip_select];
  441. else
  442. cs_pin = spi1_standard_cs[devices[i].chip_select];
  443. if (devices[i].bus_num == 0)
  444. enable_spi0 = 1;
  445. else
  446. enable_spi1 = 1;
  447. /* enable chip-select pin */
  448. at91_set_gpio_output(cs_pin, 1);
  449. /* pass chip-select pin to driver */
  450. devices[i].controller_data = (void *) cs_pin;
  451. }
  452. spi_register_board_info(devices, nr_devices);
  453. /* Configure SPI bus(es) */
  454. if (enable_spi0) {
  455. at91_set_A_periph(AT91_PIN_PA0, 0); /* SPI0_MISO */
  456. at91_set_A_periph(AT91_PIN_PA1, 0); /* SPI0_MOSI */
  457. at91_set_A_periph(AT91_PIN_PA2, 0); /* SPI1_SPCK */
  458. at91_clock_associate("spi0_clk", &at91sam9260_spi0_device.dev, "spi_clk");
  459. platform_device_register(&at91sam9260_spi0_device);
  460. }
  461. if (enable_spi1) {
  462. at91_set_A_periph(AT91_PIN_PB0, 0); /* SPI1_MISO */
  463. at91_set_A_periph(AT91_PIN_PB1, 0); /* SPI1_MOSI */
  464. at91_set_A_periph(AT91_PIN_PB2, 0); /* SPI1_SPCK */
  465. at91_clock_associate("spi1_clk", &at91sam9260_spi1_device.dev, "spi_clk");
  466. platform_device_register(&at91sam9260_spi1_device);
  467. }
  468. }
  469. #else
  470. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
  471. #endif
  472. /* --------------------------------------------------------------------
  473. * Timer/Counter blocks
  474. * -------------------------------------------------------------------- */
  475. #ifdef CONFIG_ATMEL_TCLIB
  476. static struct resource tcb0_resources[] = {
  477. [0] = {
  478. .start = AT91SAM9260_BASE_TCB0,
  479. .end = AT91SAM9260_BASE_TCB0 + SZ_16K - 1,
  480. .flags = IORESOURCE_MEM,
  481. },
  482. [1] = {
  483. .start = AT91SAM9260_ID_TC0,
  484. .end = AT91SAM9260_ID_TC0,
  485. .flags = IORESOURCE_IRQ,
  486. },
  487. [2] = {
  488. .start = AT91SAM9260_ID_TC1,
  489. .end = AT91SAM9260_ID_TC1,
  490. .flags = IORESOURCE_IRQ,
  491. },
  492. [3] = {
  493. .start = AT91SAM9260_ID_TC2,
  494. .end = AT91SAM9260_ID_TC2,
  495. .flags = IORESOURCE_IRQ,
  496. },
  497. };
  498. static struct platform_device at91sam9260_tcb0_device = {
  499. .name = "atmel_tcb",
  500. .id = 0,
  501. .resource = tcb0_resources,
  502. .num_resources = ARRAY_SIZE(tcb0_resources),
  503. };
  504. static struct resource tcb1_resources[] = {
  505. [0] = {
  506. .start = AT91SAM9260_BASE_TCB1,
  507. .end = AT91SAM9260_BASE_TCB1 + SZ_16K - 1,
  508. .flags = IORESOURCE_MEM,
  509. },
  510. [1] = {
  511. .start = AT91SAM9260_ID_TC3,
  512. .end = AT91SAM9260_ID_TC3,
  513. .flags = IORESOURCE_IRQ,
  514. },
  515. [2] = {
  516. .start = AT91SAM9260_ID_TC4,
  517. .end = AT91SAM9260_ID_TC4,
  518. .flags = IORESOURCE_IRQ,
  519. },
  520. [3] = {
  521. .start = AT91SAM9260_ID_TC5,
  522. .end = AT91SAM9260_ID_TC5,
  523. .flags = IORESOURCE_IRQ,
  524. },
  525. };
  526. static struct platform_device at91sam9260_tcb1_device = {
  527. .name = "atmel_tcb",
  528. .id = 1,
  529. .resource = tcb1_resources,
  530. .num_resources = ARRAY_SIZE(tcb1_resources),
  531. };
  532. static void __init at91_add_device_tc(void)
  533. {
  534. /* this chip has a separate clock and irq for each TC channel */
  535. at91_clock_associate("tc0_clk", &at91sam9260_tcb0_device.dev, "t0_clk");
  536. at91_clock_associate("tc1_clk", &at91sam9260_tcb0_device.dev, "t1_clk");
  537. at91_clock_associate("tc2_clk", &at91sam9260_tcb0_device.dev, "t2_clk");
  538. platform_device_register(&at91sam9260_tcb0_device);
  539. at91_clock_associate("tc3_clk", &at91sam9260_tcb1_device.dev, "t0_clk");
  540. at91_clock_associate("tc4_clk", &at91sam9260_tcb1_device.dev, "t1_clk");
  541. at91_clock_associate("tc5_clk", &at91sam9260_tcb1_device.dev, "t2_clk");
  542. platform_device_register(&at91sam9260_tcb1_device);
  543. }
  544. #else
  545. static void __init at91_add_device_tc(void) { }
  546. #endif
  547. /* --------------------------------------------------------------------
  548. * RTT
  549. * -------------------------------------------------------------------- */
  550. static struct resource rtt_resources[] = {
  551. {
  552. .start = AT91_BASE_SYS + AT91_RTT,
  553. .end = AT91_BASE_SYS + AT91_RTT + SZ_16 - 1,
  554. .flags = IORESOURCE_MEM,
  555. }
  556. };
  557. static struct platform_device at91sam9260_rtt_device = {
  558. .name = "at91_rtt",
  559. .id = 0,
  560. .resource = rtt_resources,
  561. .num_resources = ARRAY_SIZE(rtt_resources),
  562. };
  563. static void __init at91_add_device_rtt(void)
  564. {
  565. platform_device_register(&at91sam9260_rtt_device);
  566. }
  567. /* --------------------------------------------------------------------
  568. * Watchdog
  569. * -------------------------------------------------------------------- */
  570. #if defined(CONFIG_AT91SAM9_WATCHDOG) || defined(CONFIG_AT91SAM9_WATCHDOG_MODULE)
  571. static struct platform_device at91sam9260_wdt_device = {
  572. .name = "at91_wdt",
  573. .id = -1,
  574. .num_resources = 0,
  575. };
  576. static void __init at91_add_device_watchdog(void)
  577. {
  578. platform_device_register(&at91sam9260_wdt_device);
  579. }
  580. #else
  581. static void __init at91_add_device_watchdog(void) {}
  582. #endif
  583. /* --------------------------------------------------------------------
  584. * SSC -- Synchronous Serial Controller
  585. * -------------------------------------------------------------------- */
  586. #if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
  587. static u64 ssc_dmamask = DMA_BIT_MASK(32);
  588. static struct resource ssc_resources[] = {
  589. [0] = {
  590. .start = AT91SAM9260_BASE_SSC,
  591. .end = AT91SAM9260_BASE_SSC + SZ_16K - 1,
  592. .flags = IORESOURCE_MEM,
  593. },
  594. [1] = {
  595. .start = AT91SAM9260_ID_SSC,
  596. .end = AT91SAM9260_ID_SSC,
  597. .flags = IORESOURCE_IRQ,
  598. },
  599. };
  600. static struct platform_device at91sam9260_ssc_device = {
  601. .name = "ssc",
  602. .id = 0,
  603. .dev = {
  604. .dma_mask = &ssc_dmamask,
  605. .coherent_dma_mask = DMA_BIT_MASK(32),
  606. },
  607. .resource = ssc_resources,
  608. .num_resources = ARRAY_SIZE(ssc_resources),
  609. };
  610. static inline void configure_ssc_pins(unsigned pins)
  611. {
  612. if (pins & ATMEL_SSC_TF)
  613. at91_set_A_periph(AT91_PIN_PB17, 1);
  614. if (pins & ATMEL_SSC_TK)
  615. at91_set_A_periph(AT91_PIN_PB16, 1);
  616. if (pins & ATMEL_SSC_TD)
  617. at91_set_A_periph(AT91_PIN_PB18, 1);
  618. if (pins & ATMEL_SSC_RD)
  619. at91_set_A_periph(AT91_PIN_PB19, 1);
  620. if (pins & ATMEL_SSC_RK)
  621. at91_set_A_periph(AT91_PIN_PB20, 1);
  622. if (pins & ATMEL_SSC_RF)
  623. at91_set_A_periph(AT91_PIN_PB21, 1);
  624. }
  625. /*
  626. * SSC controllers are accessed through library code, instead of any
  627. * kind of all-singing/all-dancing driver. For example one could be
  628. * used by a particular I2S audio codec's driver, while another one
  629. * on the same system might be used by a custom data capture driver.
  630. */
  631. void __init at91_add_device_ssc(unsigned id, unsigned pins)
  632. {
  633. struct platform_device *pdev;
  634. /*
  635. * NOTE: caller is responsible for passing information matching
  636. * "pins" to whatever will be using each particular controller.
  637. */
  638. switch (id) {
  639. case AT91SAM9260_ID_SSC:
  640. pdev = &at91sam9260_ssc_device;
  641. configure_ssc_pins(pins);
  642. at91_clock_associate("ssc_clk", &pdev->dev, "pclk");
  643. break;
  644. default:
  645. return;
  646. }
  647. platform_device_register(pdev);
  648. }
  649. #else
  650. void __init at91_add_device_ssc(unsigned id, unsigned pins) {}
  651. #endif
  652. /* --------------------------------------------------------------------
  653. * UART
  654. * -------------------------------------------------------------------- */
  655. #if defined(CONFIG_SERIAL_ATMEL)
  656. static struct resource dbgu_resources[] = {
  657. [0] = {
  658. .start = AT91_VA_BASE_SYS + AT91_DBGU,
  659. .end = AT91_VA_BASE_SYS + AT91_DBGU + SZ_512 - 1,
  660. .flags = IORESOURCE_MEM,
  661. },
  662. [1] = {
  663. .start = AT91_ID_SYS,
  664. .end = AT91_ID_SYS,
  665. .flags = IORESOURCE_IRQ,
  666. },
  667. };
  668. static struct atmel_uart_data dbgu_data = {
  669. .use_dma_tx = 0,
  670. .use_dma_rx = 0, /* DBGU not capable of receive DMA */
  671. .regs = (void __iomem *)(AT91_VA_BASE_SYS + AT91_DBGU),
  672. };
  673. static u64 dbgu_dmamask = DMA_BIT_MASK(32);
  674. static struct platform_device at91sam9260_dbgu_device = {
  675. .name = "atmel_usart",
  676. .id = 0,
  677. .dev = {
  678. .dma_mask = &dbgu_dmamask,
  679. .coherent_dma_mask = DMA_BIT_MASK(32),
  680. .platform_data = &dbgu_data,
  681. },
  682. .resource = dbgu_resources,
  683. .num_resources = ARRAY_SIZE(dbgu_resources),
  684. };
  685. static inline void configure_dbgu_pins(void)
  686. {
  687. at91_set_A_periph(AT91_PIN_PB14, 0); /* DRXD */
  688. at91_set_A_periph(AT91_PIN_PB15, 1); /* DTXD */
  689. }
  690. static struct resource uart0_resources[] = {
  691. [0] = {
  692. .start = AT91SAM9260_BASE_US0,
  693. .end = AT91SAM9260_BASE_US0 + SZ_16K - 1,
  694. .flags = IORESOURCE_MEM,
  695. },
  696. [1] = {
  697. .start = AT91SAM9260_ID_US0,
  698. .end = AT91SAM9260_ID_US0,
  699. .flags = IORESOURCE_IRQ,
  700. },
  701. };
  702. static struct atmel_uart_data uart0_data = {
  703. .use_dma_tx = 1,
  704. .use_dma_rx = 1,
  705. };
  706. static u64 uart0_dmamask = DMA_BIT_MASK(32);
  707. static struct platform_device at91sam9260_uart0_device = {
  708. .name = "atmel_usart",
  709. .id = 1,
  710. .dev = {
  711. .dma_mask = &uart0_dmamask,
  712. .coherent_dma_mask = DMA_BIT_MASK(32),
  713. .platform_data = &uart0_data,
  714. },
  715. .resource = uart0_resources,
  716. .num_resources = ARRAY_SIZE(uart0_resources),
  717. };
  718. static inline void configure_usart0_pins(unsigned pins)
  719. {
  720. at91_set_A_periph(AT91_PIN_PB4, 1); /* TXD0 */
  721. at91_set_A_periph(AT91_PIN_PB5, 0); /* RXD0 */
  722. if (pins & ATMEL_UART_RTS)
  723. at91_set_A_periph(AT91_PIN_PB26, 0); /* RTS0 */
  724. if (pins & ATMEL_UART_CTS)
  725. at91_set_A_periph(AT91_PIN_PB27, 0); /* CTS0 */
  726. if (pins & ATMEL_UART_DTR)
  727. at91_set_A_periph(AT91_PIN_PB24, 0); /* DTR0 */
  728. if (pins & ATMEL_UART_DSR)
  729. at91_set_A_periph(AT91_PIN_PB22, 0); /* DSR0 */
  730. if (pins & ATMEL_UART_DCD)
  731. at91_set_A_periph(AT91_PIN_PB23, 0); /* DCD0 */
  732. if (pins & ATMEL_UART_RI)
  733. at91_set_A_periph(AT91_PIN_PB25, 0); /* RI0 */
  734. }
  735. static struct resource uart1_resources[] = {
  736. [0] = {
  737. .start = AT91SAM9260_BASE_US1,
  738. .end = AT91SAM9260_BASE_US1 + SZ_16K - 1,
  739. .flags = IORESOURCE_MEM,
  740. },
  741. [1] = {
  742. .start = AT91SAM9260_ID_US1,
  743. .end = AT91SAM9260_ID_US1,
  744. .flags = IORESOURCE_IRQ,
  745. },
  746. };
  747. static struct atmel_uart_data uart1_data = {
  748. .use_dma_tx = 1,
  749. .use_dma_rx = 1,
  750. };
  751. static u64 uart1_dmamask = DMA_BIT_MASK(32);
  752. static struct platform_device at91sam9260_uart1_device = {
  753. .name = "atmel_usart",
  754. .id = 2,
  755. .dev = {
  756. .dma_mask = &uart1_dmamask,
  757. .coherent_dma_mask = DMA_BIT_MASK(32),
  758. .platform_data = &uart1_data,
  759. },
  760. .resource = uart1_resources,
  761. .num_resources = ARRAY_SIZE(uart1_resources),
  762. };
  763. static inline void configure_usart1_pins(unsigned pins)
  764. {
  765. at91_set_A_periph(AT91_PIN_PB6, 1); /* TXD1 */
  766. at91_set_A_periph(AT91_PIN_PB7, 0); /* RXD1 */
  767. if (pins & ATMEL_UART_RTS)
  768. at91_set_A_periph(AT91_PIN_PB28, 0); /* RTS1 */
  769. if (pins & ATMEL_UART_CTS)
  770. at91_set_A_periph(AT91_PIN_PB29, 0); /* CTS1 */
  771. }
  772. static struct resource uart2_resources[] = {
  773. [0] = {
  774. .start = AT91SAM9260_BASE_US2,
  775. .end = AT91SAM9260_BASE_US2 + SZ_16K - 1,
  776. .flags = IORESOURCE_MEM,
  777. },
  778. [1] = {
  779. .start = AT91SAM9260_ID_US2,
  780. .end = AT91SAM9260_ID_US2,
  781. .flags = IORESOURCE_IRQ,
  782. },
  783. };
  784. static struct atmel_uart_data uart2_data = {
  785. .use_dma_tx = 1,
  786. .use_dma_rx = 1,
  787. };
  788. static u64 uart2_dmamask = DMA_BIT_MASK(32);
  789. static struct platform_device at91sam9260_uart2_device = {
  790. .name = "atmel_usart",
  791. .id = 3,
  792. .dev = {
  793. .dma_mask = &uart2_dmamask,
  794. .coherent_dma_mask = DMA_BIT_MASK(32),
  795. .platform_data = &uart2_data,
  796. },
  797. .resource = uart2_resources,
  798. .num_resources = ARRAY_SIZE(uart2_resources),
  799. };
  800. static inline void configure_usart2_pins(unsigned pins)
  801. {
  802. at91_set_A_periph(AT91_PIN_PB8, 1); /* TXD2 */
  803. at91_set_A_periph(AT91_PIN_PB9, 0); /* RXD2 */
  804. if (pins & ATMEL_UART_RTS)
  805. at91_set_A_periph(AT91_PIN_PA4, 0); /* RTS2 */
  806. if (pins & ATMEL_UART_CTS)
  807. at91_set_A_periph(AT91_PIN_PA5, 0); /* CTS2 */
  808. }
  809. static struct resource uart3_resources[] = {
  810. [0] = {
  811. .start = AT91SAM9260_BASE_US3,
  812. .end = AT91SAM9260_BASE_US3 + SZ_16K - 1,
  813. .flags = IORESOURCE_MEM,
  814. },
  815. [1] = {
  816. .start = AT91SAM9260_ID_US3,
  817. .end = AT91SAM9260_ID_US3,
  818. .flags = IORESOURCE_IRQ,
  819. },
  820. };
  821. static struct atmel_uart_data uart3_data = {
  822. .use_dma_tx = 1,
  823. .use_dma_rx = 1,
  824. };
  825. static u64 uart3_dmamask = DMA_BIT_MASK(32);
  826. static struct platform_device at91sam9260_uart3_device = {
  827. .name = "atmel_usart",
  828. .id = 4,
  829. .dev = {
  830. .dma_mask = &uart3_dmamask,
  831. .coherent_dma_mask = DMA_BIT_MASK(32),
  832. .platform_data = &uart3_data,
  833. },
  834. .resource = uart3_resources,
  835. .num_resources = ARRAY_SIZE(uart3_resources),
  836. };
  837. static inline void configure_usart3_pins(unsigned pins)
  838. {
  839. at91_set_A_periph(AT91_PIN_PB10, 1); /* TXD3 */
  840. at91_set_A_periph(AT91_PIN_PB11, 0); /* RXD3 */
  841. if (pins & ATMEL_UART_RTS)
  842. at91_set_B_periph(AT91_PIN_PC8, 0); /* RTS3 */
  843. if (pins & ATMEL_UART_CTS)
  844. at91_set_B_periph(AT91_PIN_PC10, 0); /* CTS3 */
  845. }
  846. static struct resource uart4_resources[] = {
  847. [0] = {
  848. .start = AT91SAM9260_BASE_US4,
  849. .end = AT91SAM9260_BASE_US4 + SZ_16K - 1,
  850. .flags = IORESOURCE_MEM,
  851. },
  852. [1] = {
  853. .start = AT91SAM9260_ID_US4,
  854. .end = AT91SAM9260_ID_US4,
  855. .flags = IORESOURCE_IRQ,
  856. },
  857. };
  858. static struct atmel_uart_data uart4_data = {
  859. .use_dma_tx = 1,
  860. .use_dma_rx = 1,
  861. };
  862. static u64 uart4_dmamask = DMA_BIT_MASK(32);
  863. static struct platform_device at91sam9260_uart4_device = {
  864. .name = "atmel_usart",
  865. .id = 5,
  866. .dev = {
  867. .dma_mask = &uart4_dmamask,
  868. .coherent_dma_mask = DMA_BIT_MASK(32),
  869. .platform_data = &uart4_data,
  870. },
  871. .resource = uart4_resources,
  872. .num_resources = ARRAY_SIZE(uart4_resources),
  873. };
  874. static inline void configure_usart4_pins(void)
  875. {
  876. at91_set_B_periph(AT91_PIN_PA31, 1); /* TXD4 */
  877. at91_set_B_periph(AT91_PIN_PA30, 0); /* RXD4 */
  878. }
  879. static struct resource uart5_resources[] = {
  880. [0] = {
  881. .start = AT91SAM9260_BASE_US5,
  882. .end = AT91SAM9260_BASE_US5 + SZ_16K - 1,
  883. .flags = IORESOURCE_MEM,
  884. },
  885. [1] = {
  886. .start = AT91SAM9260_ID_US5,
  887. .end = AT91SAM9260_ID_US5,
  888. .flags = IORESOURCE_IRQ,
  889. },
  890. };
  891. static struct atmel_uart_data uart5_data = {
  892. .use_dma_tx = 1,
  893. .use_dma_rx = 1,
  894. };
  895. static u64 uart5_dmamask = DMA_BIT_MASK(32);
  896. static struct platform_device at91sam9260_uart5_device = {
  897. .name = "atmel_usart",
  898. .id = 6,
  899. .dev = {
  900. .dma_mask = &uart5_dmamask,
  901. .coherent_dma_mask = DMA_BIT_MASK(32),
  902. .platform_data = &uart5_data,
  903. },
  904. .resource = uart5_resources,
  905. .num_resources = ARRAY_SIZE(uart5_resources),
  906. };
  907. static inline void configure_usart5_pins(void)
  908. {
  909. at91_set_A_periph(AT91_PIN_PB12, 1); /* TXD5 */
  910. at91_set_A_periph(AT91_PIN_PB13, 0); /* RXD5 */
  911. }
  912. static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
  913. struct platform_device *atmel_default_console_device; /* the serial console device */
  914. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
  915. {
  916. struct platform_device *pdev;
  917. switch (id) {
  918. case 0: /* DBGU */
  919. pdev = &at91sam9260_dbgu_device;
  920. configure_dbgu_pins();
  921. at91_clock_associate("mck", &pdev->dev, "usart");
  922. break;
  923. case AT91SAM9260_ID_US0:
  924. pdev = &at91sam9260_uart0_device;
  925. configure_usart0_pins(pins);
  926. at91_clock_associate("usart0_clk", &pdev->dev, "usart");
  927. break;
  928. case AT91SAM9260_ID_US1:
  929. pdev = &at91sam9260_uart1_device;
  930. configure_usart1_pins(pins);
  931. at91_clock_associate("usart1_clk", &pdev->dev, "usart");
  932. break;
  933. case AT91SAM9260_ID_US2:
  934. pdev = &at91sam9260_uart2_device;
  935. configure_usart2_pins(pins);
  936. at91_clock_associate("usart2_clk", &pdev->dev, "usart");
  937. break;
  938. case AT91SAM9260_ID_US3:
  939. pdev = &at91sam9260_uart3_device;
  940. configure_usart3_pins(pins);
  941. at91_clock_associate("usart3_clk", &pdev->dev, "usart");
  942. break;
  943. case AT91SAM9260_ID_US4:
  944. pdev = &at91sam9260_uart4_device;
  945. configure_usart4_pins();
  946. at91_clock_associate("usart4_clk", &pdev->dev, "usart");
  947. break;
  948. case AT91SAM9260_ID_US5:
  949. pdev = &at91sam9260_uart5_device;
  950. configure_usart5_pins();
  951. at91_clock_associate("usart5_clk", &pdev->dev, "usart");
  952. break;
  953. default:
  954. return;
  955. }
  956. pdev->id = portnr; /* update to mapped ID */
  957. if (portnr < ATMEL_MAX_UART)
  958. at91_uarts[portnr] = pdev;
  959. }
  960. void __init at91_set_serial_console(unsigned portnr)
  961. {
  962. if (portnr < ATMEL_MAX_UART)
  963. atmel_default_console_device = at91_uarts[portnr];
  964. }
  965. void __init at91_add_device_serial(void)
  966. {
  967. int i;
  968. for (i = 0; i < ATMEL_MAX_UART; i++) {
  969. if (at91_uarts[i])
  970. platform_device_register(at91_uarts[i]);
  971. }
  972. if (!atmel_default_console_device)
  973. printk(KERN_INFO "AT91: No default serial console defined.\n");
  974. }
  975. #else
  976. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
  977. void __init at91_set_serial_console(unsigned portnr) {}
  978. void __init at91_add_device_serial(void) {}
  979. #endif
  980. /* -------------------------------------------------------------------- */
  981. /*
  982. * These devices are always present and don't need any board-specific
  983. * setup.
  984. */
  985. static int __init at91_add_standard_devices(void)
  986. {
  987. at91_add_device_rtt();
  988. at91_add_device_watchdog();
  989. at91_add_device_tc();
  990. return 0;
  991. }
  992. arch_initcall(at91_add_standard_devices);