at91sam9260_devices.c 26 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052
  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. * LEDs
  487. * -------------------------------------------------------------------- */
  488. #if defined(CONFIG_LEDS)
  489. u8 at91_leds_cpu;
  490. u8 at91_leds_timer;
  491. void __init at91_init_leds(u8 cpu_led, u8 timer_led)
  492. {
  493. /* Enable GPIO to access the LEDs */
  494. at91_set_gpio_output(cpu_led, 1);
  495. at91_set_gpio_output(timer_led, 1);
  496. at91_leds_cpu = cpu_led;
  497. at91_leds_timer = timer_led;
  498. }
  499. #else
  500. void __init at91_init_leds(u8 cpu_led, u8 timer_led) {}
  501. #endif
  502. /* --------------------------------------------------------------------
  503. * SSC -- Synchronous Serial Controller
  504. * -------------------------------------------------------------------- */
  505. #if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
  506. static u64 ssc_dmamask = DMA_BIT_MASK(32);
  507. static struct resource ssc_resources[] = {
  508. [0] = {
  509. .start = AT91SAM9260_BASE_SSC,
  510. .end = AT91SAM9260_BASE_SSC + SZ_16K - 1,
  511. .flags = IORESOURCE_MEM,
  512. },
  513. [1] = {
  514. .start = AT91SAM9260_ID_SSC,
  515. .end = AT91SAM9260_ID_SSC,
  516. .flags = IORESOURCE_IRQ,
  517. },
  518. };
  519. static struct platform_device at91sam9260_ssc_device = {
  520. .name = "ssc",
  521. .id = 0,
  522. .dev = {
  523. .dma_mask = &ssc_dmamask,
  524. .coherent_dma_mask = DMA_BIT_MASK(32),
  525. },
  526. .resource = ssc_resources,
  527. .num_resources = ARRAY_SIZE(ssc_resources),
  528. };
  529. static inline void configure_ssc_pins(unsigned pins)
  530. {
  531. if (pins & ATMEL_SSC_TF)
  532. at91_set_A_periph(AT91_PIN_PB17, 1);
  533. if (pins & ATMEL_SSC_TK)
  534. at91_set_A_periph(AT91_PIN_PB16, 1);
  535. if (pins & ATMEL_SSC_TD)
  536. at91_set_A_periph(AT91_PIN_PB18, 1);
  537. if (pins & ATMEL_SSC_RD)
  538. at91_set_A_periph(AT91_PIN_PB19, 1);
  539. if (pins & ATMEL_SSC_RK)
  540. at91_set_A_periph(AT91_PIN_PB20, 1);
  541. if (pins & ATMEL_SSC_RF)
  542. at91_set_A_periph(AT91_PIN_PB21, 1);
  543. }
  544. /*
  545. * SSC controllers are accessed through library code, instead of any
  546. * kind of all-singing/all-dancing driver. For example one could be
  547. * used by a particular I2S audio codec's driver, while another one
  548. * on the same system might be used by a custom data capture driver.
  549. */
  550. void __init at91_add_device_ssc(unsigned id, unsigned pins)
  551. {
  552. struct platform_device *pdev;
  553. /*
  554. * NOTE: caller is responsible for passing information matching
  555. * "pins" to whatever will be using each particular controller.
  556. */
  557. switch (id) {
  558. case AT91SAM9260_ID_SSC:
  559. pdev = &at91sam9260_ssc_device;
  560. configure_ssc_pins(pins);
  561. at91_clock_associate("ssc_clk", &pdev->dev, "pclk");
  562. break;
  563. default:
  564. return;
  565. }
  566. platform_device_register(pdev);
  567. }
  568. #else
  569. void __init at91_add_device_ssc(unsigned id, unsigned pins) {}
  570. #endif
  571. /* --------------------------------------------------------------------
  572. * UART
  573. * -------------------------------------------------------------------- */
  574. #if defined(CONFIG_SERIAL_ATMEL)
  575. static struct resource dbgu_resources[] = {
  576. [0] = {
  577. .start = AT91_VA_BASE_SYS + AT91_DBGU,
  578. .end = AT91_VA_BASE_SYS + AT91_DBGU + SZ_512 - 1,
  579. .flags = IORESOURCE_MEM,
  580. },
  581. [1] = {
  582. .start = AT91_ID_SYS,
  583. .end = AT91_ID_SYS,
  584. .flags = IORESOURCE_IRQ,
  585. },
  586. };
  587. static struct atmel_uart_data dbgu_data = {
  588. .use_dma_tx = 0,
  589. .use_dma_rx = 0, /* DBGU not capable of receive DMA */
  590. .regs = (void __iomem *)(AT91_VA_BASE_SYS + AT91_DBGU),
  591. };
  592. static u64 dbgu_dmamask = DMA_BIT_MASK(32);
  593. static struct platform_device at91sam9260_dbgu_device = {
  594. .name = "atmel_usart",
  595. .id = 0,
  596. .dev = {
  597. .dma_mask = &dbgu_dmamask,
  598. .coherent_dma_mask = DMA_BIT_MASK(32),
  599. .platform_data = &dbgu_data,
  600. },
  601. .resource = dbgu_resources,
  602. .num_resources = ARRAY_SIZE(dbgu_resources),
  603. };
  604. static inline void configure_dbgu_pins(void)
  605. {
  606. at91_set_A_periph(AT91_PIN_PB14, 0); /* DRXD */
  607. at91_set_A_periph(AT91_PIN_PB15, 1); /* DTXD */
  608. }
  609. static struct resource uart0_resources[] = {
  610. [0] = {
  611. .start = AT91SAM9260_BASE_US0,
  612. .end = AT91SAM9260_BASE_US0 + SZ_16K - 1,
  613. .flags = IORESOURCE_MEM,
  614. },
  615. [1] = {
  616. .start = AT91SAM9260_ID_US0,
  617. .end = AT91SAM9260_ID_US0,
  618. .flags = IORESOURCE_IRQ,
  619. },
  620. };
  621. static struct atmel_uart_data uart0_data = {
  622. .use_dma_tx = 1,
  623. .use_dma_rx = 1,
  624. };
  625. static u64 uart0_dmamask = DMA_BIT_MASK(32);
  626. static struct platform_device at91sam9260_uart0_device = {
  627. .name = "atmel_usart",
  628. .id = 1,
  629. .dev = {
  630. .dma_mask = &uart0_dmamask,
  631. .coherent_dma_mask = DMA_BIT_MASK(32),
  632. .platform_data = &uart0_data,
  633. },
  634. .resource = uart0_resources,
  635. .num_resources = ARRAY_SIZE(uart0_resources),
  636. };
  637. static inline void configure_usart0_pins(void)
  638. {
  639. at91_set_A_periph(AT91_PIN_PB4, 1); /* TXD0 */
  640. at91_set_A_periph(AT91_PIN_PB5, 0); /* RXD0 */
  641. at91_set_A_periph(AT91_PIN_PB26, 0); /* RTS0 */
  642. at91_set_A_periph(AT91_PIN_PB27, 0); /* CTS0 */
  643. at91_set_A_periph(AT91_PIN_PB24, 0); /* DTR0 */
  644. at91_set_A_periph(AT91_PIN_PB22, 0); /* DSR0 */
  645. at91_set_A_periph(AT91_PIN_PB23, 0); /* DCD0 */
  646. at91_set_A_periph(AT91_PIN_PB25, 0); /* RI0 */
  647. }
  648. static struct resource uart1_resources[] = {
  649. [0] = {
  650. .start = AT91SAM9260_BASE_US1,
  651. .end = AT91SAM9260_BASE_US1 + SZ_16K - 1,
  652. .flags = IORESOURCE_MEM,
  653. },
  654. [1] = {
  655. .start = AT91SAM9260_ID_US1,
  656. .end = AT91SAM9260_ID_US1,
  657. .flags = IORESOURCE_IRQ,
  658. },
  659. };
  660. static struct atmel_uart_data uart1_data = {
  661. .use_dma_tx = 1,
  662. .use_dma_rx = 1,
  663. };
  664. static u64 uart1_dmamask = DMA_BIT_MASK(32);
  665. static struct platform_device at91sam9260_uart1_device = {
  666. .name = "atmel_usart",
  667. .id = 2,
  668. .dev = {
  669. .dma_mask = &uart1_dmamask,
  670. .coherent_dma_mask = DMA_BIT_MASK(32),
  671. .platform_data = &uart1_data,
  672. },
  673. .resource = uart1_resources,
  674. .num_resources = ARRAY_SIZE(uart1_resources),
  675. };
  676. static inline void configure_usart1_pins(void)
  677. {
  678. at91_set_A_periph(AT91_PIN_PB6, 1); /* TXD1 */
  679. at91_set_A_periph(AT91_PIN_PB7, 0); /* RXD1 */
  680. at91_set_A_periph(AT91_PIN_PB28, 0); /* RTS1 */
  681. at91_set_A_periph(AT91_PIN_PB29, 0); /* CTS1 */
  682. }
  683. static struct resource uart2_resources[] = {
  684. [0] = {
  685. .start = AT91SAM9260_BASE_US2,
  686. .end = AT91SAM9260_BASE_US2 + SZ_16K - 1,
  687. .flags = IORESOURCE_MEM,
  688. },
  689. [1] = {
  690. .start = AT91SAM9260_ID_US2,
  691. .end = AT91SAM9260_ID_US2,
  692. .flags = IORESOURCE_IRQ,
  693. },
  694. };
  695. static struct atmel_uart_data uart2_data = {
  696. .use_dma_tx = 1,
  697. .use_dma_rx = 1,
  698. };
  699. static u64 uart2_dmamask = DMA_BIT_MASK(32);
  700. static struct platform_device at91sam9260_uart2_device = {
  701. .name = "atmel_usart",
  702. .id = 3,
  703. .dev = {
  704. .dma_mask = &uart2_dmamask,
  705. .coherent_dma_mask = DMA_BIT_MASK(32),
  706. .platform_data = &uart2_data,
  707. },
  708. .resource = uart2_resources,
  709. .num_resources = ARRAY_SIZE(uart2_resources),
  710. };
  711. static inline void configure_usart2_pins(void)
  712. {
  713. at91_set_A_periph(AT91_PIN_PB8, 1); /* TXD2 */
  714. at91_set_A_periph(AT91_PIN_PB9, 0); /* RXD2 */
  715. }
  716. static struct resource uart3_resources[] = {
  717. [0] = {
  718. .start = AT91SAM9260_BASE_US3,
  719. .end = AT91SAM9260_BASE_US3 + SZ_16K - 1,
  720. .flags = IORESOURCE_MEM,
  721. },
  722. [1] = {
  723. .start = AT91SAM9260_ID_US3,
  724. .end = AT91SAM9260_ID_US3,
  725. .flags = IORESOURCE_IRQ,
  726. },
  727. };
  728. static struct atmel_uart_data uart3_data = {
  729. .use_dma_tx = 1,
  730. .use_dma_rx = 1,
  731. };
  732. static u64 uart3_dmamask = DMA_BIT_MASK(32);
  733. static struct platform_device at91sam9260_uart3_device = {
  734. .name = "atmel_usart",
  735. .id = 4,
  736. .dev = {
  737. .dma_mask = &uart3_dmamask,
  738. .coherent_dma_mask = DMA_BIT_MASK(32),
  739. .platform_data = &uart3_data,
  740. },
  741. .resource = uart3_resources,
  742. .num_resources = ARRAY_SIZE(uart3_resources),
  743. };
  744. static inline void configure_usart3_pins(void)
  745. {
  746. at91_set_A_periph(AT91_PIN_PB10, 1); /* TXD3 */
  747. at91_set_A_periph(AT91_PIN_PB11, 0); /* RXD3 */
  748. }
  749. static struct resource uart4_resources[] = {
  750. [0] = {
  751. .start = AT91SAM9260_BASE_US4,
  752. .end = AT91SAM9260_BASE_US4 + SZ_16K - 1,
  753. .flags = IORESOURCE_MEM,
  754. },
  755. [1] = {
  756. .start = AT91SAM9260_ID_US4,
  757. .end = AT91SAM9260_ID_US4,
  758. .flags = IORESOURCE_IRQ,
  759. },
  760. };
  761. static struct atmel_uart_data uart4_data = {
  762. .use_dma_tx = 1,
  763. .use_dma_rx = 1,
  764. };
  765. static u64 uart4_dmamask = DMA_BIT_MASK(32);
  766. static struct platform_device at91sam9260_uart4_device = {
  767. .name = "atmel_usart",
  768. .id = 5,
  769. .dev = {
  770. .dma_mask = &uart4_dmamask,
  771. .coherent_dma_mask = DMA_BIT_MASK(32),
  772. .platform_data = &uart4_data,
  773. },
  774. .resource = uart4_resources,
  775. .num_resources = ARRAY_SIZE(uart4_resources),
  776. };
  777. static inline void configure_usart4_pins(void)
  778. {
  779. at91_set_B_periph(AT91_PIN_PA31, 1); /* TXD4 */
  780. at91_set_B_periph(AT91_PIN_PA30, 0); /* RXD4 */
  781. }
  782. static struct resource uart5_resources[] = {
  783. [0] = {
  784. .start = AT91SAM9260_BASE_US5,
  785. .end = AT91SAM9260_BASE_US5 + SZ_16K - 1,
  786. .flags = IORESOURCE_MEM,
  787. },
  788. [1] = {
  789. .start = AT91SAM9260_ID_US5,
  790. .end = AT91SAM9260_ID_US5,
  791. .flags = IORESOURCE_IRQ,
  792. },
  793. };
  794. static struct atmel_uart_data uart5_data = {
  795. .use_dma_tx = 1,
  796. .use_dma_rx = 1,
  797. };
  798. static u64 uart5_dmamask = DMA_BIT_MASK(32);
  799. static struct platform_device at91sam9260_uart5_device = {
  800. .name = "atmel_usart",
  801. .id = 6,
  802. .dev = {
  803. .dma_mask = &uart5_dmamask,
  804. .coherent_dma_mask = DMA_BIT_MASK(32),
  805. .platform_data = &uart5_data,
  806. },
  807. .resource = uart5_resources,
  808. .num_resources = ARRAY_SIZE(uart5_resources),
  809. };
  810. static inline void configure_usart5_pins(void)
  811. {
  812. at91_set_A_periph(AT91_PIN_PB12, 1); /* TXD5 */
  813. at91_set_A_periph(AT91_PIN_PB13, 0); /* RXD5 */
  814. }
  815. static struct platform_device *at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
  816. struct platform_device *atmel_default_console_device; /* the serial console device */
  817. void __init at91_init_serial(struct at91_uart_config *config)
  818. {
  819. int i;
  820. /* Fill in list of supported UARTs */
  821. for (i = 0; i < config->nr_tty; i++) {
  822. switch (config->tty_map[i]) {
  823. case 0:
  824. configure_usart0_pins();
  825. at91_uarts[i] = &at91sam9260_uart0_device;
  826. at91_clock_associate("usart0_clk", &at91sam9260_uart0_device.dev, "usart");
  827. break;
  828. case 1:
  829. configure_usart1_pins();
  830. at91_uarts[i] = &at91sam9260_uart1_device;
  831. at91_clock_associate("usart1_clk", &at91sam9260_uart1_device.dev, "usart");
  832. break;
  833. case 2:
  834. configure_usart2_pins();
  835. at91_uarts[i] = &at91sam9260_uart2_device;
  836. at91_clock_associate("usart2_clk", &at91sam9260_uart2_device.dev, "usart");
  837. break;
  838. case 3:
  839. configure_usart3_pins();
  840. at91_uarts[i] = &at91sam9260_uart3_device;
  841. at91_clock_associate("usart3_clk", &at91sam9260_uart3_device.dev, "usart");
  842. break;
  843. case 4:
  844. configure_usart4_pins();
  845. at91_uarts[i] = &at91sam9260_uart4_device;
  846. at91_clock_associate("usart4_clk", &at91sam9260_uart4_device.dev, "usart");
  847. break;
  848. case 5:
  849. configure_usart5_pins();
  850. at91_uarts[i] = &at91sam9260_uart5_device;
  851. at91_clock_associate("usart5_clk", &at91sam9260_uart5_device.dev, "usart");
  852. break;
  853. case 6:
  854. configure_dbgu_pins();
  855. at91_uarts[i] = &at91sam9260_dbgu_device;
  856. at91_clock_associate("mck", &at91sam9260_dbgu_device.dev, "usart");
  857. break;
  858. default:
  859. continue;
  860. }
  861. at91_uarts[i]->id = i; /* update ID number to mapped ID */
  862. }
  863. /* Set serial console device */
  864. if (config->console_tty < ATMEL_MAX_UART)
  865. atmel_default_console_device = at91_uarts[config->console_tty];
  866. if (!atmel_default_console_device)
  867. printk(KERN_INFO "AT91: No default serial console defined.\n");
  868. }
  869. void __init at91_add_device_serial(void)
  870. {
  871. int i;
  872. for (i = 0; i < ATMEL_MAX_UART; i++) {
  873. if (at91_uarts[i])
  874. platform_device_register(at91_uarts[i]);
  875. }
  876. }
  877. #else
  878. void __init at91_init_serial(struct at91_uart_config *config) {}
  879. void __init at91_add_device_serial(void) {}
  880. #endif
  881. /* -------------------------------------------------------------------- */
  882. /*
  883. * These devices are always present and don't need any board-specific
  884. * setup.
  885. */
  886. static int __init at91_add_standard_devices(void)
  887. {
  888. at91_add_device_rtt();
  889. at91_add_device_watchdog();
  890. return 0;
  891. }
  892. arch_initcall(at91_add_standard_devices);