at91sam9261_devices.c 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070
  1. /*
  2. * arch/arm/mach-at91/at91sam9261_devices.c
  3. *
  4. * Copyright (C) 2005 Thibaut VARENE <varenet@parisc-linux.org>
  5. * Copyright (C) 2005 David Brownell
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. */
  13. #include <asm/mach/arch.h>
  14. #include <asm/mach/map.h>
  15. #include <linux/dma-mapping.h>
  16. #include <linux/gpio.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/i2c-gpio.h>
  19. #include <linux/fb.h>
  20. #include <video/atmel_lcdc.h>
  21. #include <mach/board.h>
  22. #include <mach/at91sam9261.h>
  23. #include <mach/at91sam9261_matrix.h>
  24. #include <mach/at91_matrix.h>
  25. #include <mach/at91sam9_smc.h>
  26. #include "generic.h"
  27. /* --------------------------------------------------------------------
  28. * USB Host
  29. * -------------------------------------------------------------------- */
  30. #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
  31. static u64 ohci_dmamask = DMA_BIT_MASK(32);
  32. static struct at91_usbh_data usbh_data;
  33. static struct resource usbh_resources[] = {
  34. [0] = {
  35. .start = AT91SAM9261_UHP_BASE,
  36. .end = AT91SAM9261_UHP_BASE + SZ_1M - 1,
  37. .flags = IORESOURCE_MEM,
  38. },
  39. [1] = {
  40. .start = AT91SAM9261_ID_UHP,
  41. .end = AT91SAM9261_ID_UHP,
  42. .flags = IORESOURCE_IRQ,
  43. },
  44. };
  45. static struct platform_device at91sam9261_usbh_device = {
  46. .name = "at91_ohci",
  47. .id = -1,
  48. .dev = {
  49. .dma_mask = &ohci_dmamask,
  50. .coherent_dma_mask = DMA_BIT_MASK(32),
  51. .platform_data = &usbh_data,
  52. },
  53. .resource = usbh_resources,
  54. .num_resources = ARRAY_SIZE(usbh_resources),
  55. };
  56. void __init at91_add_device_usbh(struct at91_usbh_data *data)
  57. {
  58. int i;
  59. if (!data)
  60. return;
  61. /* Enable overcurrent notification */
  62. for (i = 0; i < data->ports; i++) {
  63. if (data->overcurrent_pin[i])
  64. at91_set_gpio_input(data->overcurrent_pin[i], 1);
  65. }
  66. usbh_data = *data;
  67. platform_device_register(&at91sam9261_usbh_device);
  68. }
  69. #else
  70. void __init at91_add_device_usbh(struct at91_usbh_data *data) {}
  71. #endif
  72. /* --------------------------------------------------------------------
  73. * USB Device (Gadget)
  74. * -------------------------------------------------------------------- */
  75. #ifdef CONFIG_USB_AT91
  76. static struct at91_udc_data udc_data;
  77. static struct resource udc_resources[] = {
  78. [0] = {
  79. .start = AT91SAM9261_BASE_UDP,
  80. .end = AT91SAM9261_BASE_UDP + SZ_16K - 1,
  81. .flags = IORESOURCE_MEM,
  82. },
  83. [1] = {
  84. .start = AT91SAM9261_ID_UDP,
  85. .end = AT91SAM9261_ID_UDP,
  86. .flags = IORESOURCE_IRQ,
  87. },
  88. };
  89. static struct platform_device at91sam9261_udc_device = {
  90. .name = "at91_udc",
  91. .id = -1,
  92. .dev = {
  93. .platform_data = &udc_data,
  94. },
  95. .resource = udc_resources,
  96. .num_resources = ARRAY_SIZE(udc_resources),
  97. };
  98. void __init at91_add_device_udc(struct at91_udc_data *data)
  99. {
  100. if (!data)
  101. return;
  102. if (gpio_is_valid(data->vbus_pin)) {
  103. at91_set_gpio_input(data->vbus_pin, 0);
  104. at91_set_deglitch(data->vbus_pin, 1);
  105. }
  106. /* Pullup pin is handled internally by USB device peripheral */
  107. udc_data = *data;
  108. platform_device_register(&at91sam9261_udc_device);
  109. }
  110. #else
  111. void __init at91_add_device_udc(struct at91_udc_data *data) {}
  112. #endif
  113. /* --------------------------------------------------------------------
  114. * MMC / SD
  115. * -------------------------------------------------------------------- */
  116. #if defined(CONFIG_MMC_AT91) || defined(CONFIG_MMC_AT91_MODULE)
  117. static u64 mmc_dmamask = DMA_BIT_MASK(32);
  118. static struct at91_mmc_data mmc_data;
  119. static struct resource mmc_resources[] = {
  120. [0] = {
  121. .start = AT91SAM9261_BASE_MCI,
  122. .end = AT91SAM9261_BASE_MCI + SZ_16K - 1,
  123. .flags = IORESOURCE_MEM,
  124. },
  125. [1] = {
  126. .start = AT91SAM9261_ID_MCI,
  127. .end = AT91SAM9261_ID_MCI,
  128. .flags = IORESOURCE_IRQ,
  129. },
  130. };
  131. static struct platform_device at91sam9261_mmc_device = {
  132. .name = "at91_mci",
  133. .id = -1,
  134. .dev = {
  135. .dma_mask = &mmc_dmamask,
  136. .coherent_dma_mask = DMA_BIT_MASK(32),
  137. .platform_data = &mmc_data,
  138. },
  139. .resource = mmc_resources,
  140. .num_resources = ARRAY_SIZE(mmc_resources),
  141. };
  142. void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data)
  143. {
  144. if (!data)
  145. return;
  146. /* input/irq */
  147. if (gpio_is_valid(data->det_pin)) {
  148. at91_set_gpio_input(data->det_pin, 1);
  149. at91_set_deglitch(data->det_pin, 1);
  150. }
  151. if (gpio_is_valid(data->wp_pin))
  152. at91_set_gpio_input(data->wp_pin, 1);
  153. if (gpio_is_valid(data->vcc_pin))
  154. at91_set_gpio_output(data->vcc_pin, 0);
  155. /* CLK */
  156. at91_set_B_periph(AT91_PIN_PA2, 0);
  157. /* CMD */
  158. at91_set_B_periph(AT91_PIN_PA1, 1);
  159. /* DAT0, maybe DAT1..DAT3 */
  160. at91_set_B_periph(AT91_PIN_PA0, 1);
  161. if (data->wire4) {
  162. at91_set_B_periph(AT91_PIN_PA4, 1);
  163. at91_set_B_periph(AT91_PIN_PA5, 1);
  164. at91_set_B_periph(AT91_PIN_PA6, 1);
  165. }
  166. mmc_data = *data;
  167. platform_device_register(&at91sam9261_mmc_device);
  168. }
  169. #else
  170. void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data) {}
  171. #endif
  172. /* --------------------------------------------------------------------
  173. * NAND / SmartMedia
  174. * -------------------------------------------------------------------- */
  175. #if defined(CONFIG_MTD_NAND_ATMEL) || defined(CONFIG_MTD_NAND_ATMEL_MODULE)
  176. static struct atmel_nand_data nand_data;
  177. #define NAND_BASE AT91_CHIPSELECT_3
  178. static struct resource nand_resources[] = {
  179. {
  180. .start = NAND_BASE,
  181. .end = NAND_BASE + SZ_256M - 1,
  182. .flags = IORESOURCE_MEM,
  183. }
  184. };
  185. static struct platform_device atmel_nand_device = {
  186. .name = "atmel_nand",
  187. .id = -1,
  188. .dev = {
  189. .platform_data = &nand_data,
  190. },
  191. .resource = nand_resources,
  192. .num_resources = ARRAY_SIZE(nand_resources),
  193. };
  194. void __init at91_add_device_nand(struct atmel_nand_data *data)
  195. {
  196. unsigned long csa;
  197. if (!data)
  198. return;
  199. csa = at91_matrix_read(AT91_MATRIX_EBICSA);
  200. at91_matrix_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_CS3A_SMC_SMARTMEDIA);
  201. /* enable pin */
  202. if (gpio_is_valid(data->enable_pin))
  203. at91_set_gpio_output(data->enable_pin, 1);
  204. /* ready/busy pin */
  205. if (gpio_is_valid(data->rdy_pin))
  206. at91_set_gpio_input(data->rdy_pin, 1);
  207. /* card detect pin */
  208. if (gpio_is_valid(data->det_pin))
  209. at91_set_gpio_input(data->det_pin, 1);
  210. at91_set_A_periph(AT91_PIN_PC0, 0); /* NANDOE */
  211. at91_set_A_periph(AT91_PIN_PC1, 0); /* NANDWE */
  212. nand_data = *data;
  213. platform_device_register(&atmel_nand_device);
  214. }
  215. #else
  216. void __init at91_add_device_nand(struct atmel_nand_data *data) {}
  217. #endif
  218. /* --------------------------------------------------------------------
  219. * TWI (i2c)
  220. * -------------------------------------------------------------------- */
  221. /*
  222. * Prefer the GPIO code since the TWI controller isn't robust
  223. * (gets overruns and underruns under load) and can only issue
  224. * repeated STARTs in one scenario (the driver doesn't yet handle them).
  225. */
  226. #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
  227. static struct i2c_gpio_platform_data pdata = {
  228. .sda_pin = AT91_PIN_PA7,
  229. .sda_is_open_drain = 1,
  230. .scl_pin = AT91_PIN_PA8,
  231. .scl_is_open_drain = 1,
  232. .udelay = 2, /* ~100 kHz */
  233. };
  234. static struct platform_device at91sam9261_twi_device = {
  235. .name = "i2c-gpio",
  236. .id = -1,
  237. .dev.platform_data = &pdata,
  238. };
  239. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  240. {
  241. at91_set_GPIO_periph(AT91_PIN_PA7, 1); /* TWD (SDA) */
  242. at91_set_multi_drive(AT91_PIN_PA7, 1);
  243. at91_set_GPIO_periph(AT91_PIN_PA8, 1); /* TWCK (SCL) */
  244. at91_set_multi_drive(AT91_PIN_PA8, 1);
  245. i2c_register_board_info(0, devices, nr_devices);
  246. platform_device_register(&at91sam9261_twi_device);
  247. }
  248. #elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
  249. static struct resource twi_resources[] = {
  250. [0] = {
  251. .start = AT91SAM9261_BASE_TWI,
  252. .end = AT91SAM9261_BASE_TWI + SZ_16K - 1,
  253. .flags = IORESOURCE_MEM,
  254. },
  255. [1] = {
  256. .start = AT91SAM9261_ID_TWI,
  257. .end = AT91SAM9261_ID_TWI,
  258. .flags = IORESOURCE_IRQ,
  259. },
  260. };
  261. static struct platform_device at91sam9261_twi_device = {
  262. .name = "at91_i2c",
  263. .id = -1,
  264. .resource = twi_resources,
  265. .num_resources = ARRAY_SIZE(twi_resources),
  266. };
  267. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  268. {
  269. /* pins used for TWI interface */
  270. at91_set_A_periph(AT91_PIN_PA7, 0); /* TWD */
  271. at91_set_multi_drive(AT91_PIN_PA7, 1);
  272. at91_set_A_periph(AT91_PIN_PA8, 0); /* TWCK */
  273. at91_set_multi_drive(AT91_PIN_PA8, 1);
  274. i2c_register_board_info(0, devices, nr_devices);
  275. platform_device_register(&at91sam9261_twi_device);
  276. }
  277. #else
  278. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {}
  279. #endif
  280. /* --------------------------------------------------------------------
  281. * SPI
  282. * -------------------------------------------------------------------- */
  283. #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
  284. static u64 spi_dmamask = DMA_BIT_MASK(32);
  285. static struct resource spi0_resources[] = {
  286. [0] = {
  287. .start = AT91SAM9261_BASE_SPI0,
  288. .end = AT91SAM9261_BASE_SPI0 + SZ_16K - 1,
  289. .flags = IORESOURCE_MEM,
  290. },
  291. [1] = {
  292. .start = AT91SAM9261_ID_SPI0,
  293. .end = AT91SAM9261_ID_SPI0,
  294. .flags = IORESOURCE_IRQ,
  295. },
  296. };
  297. static struct platform_device at91sam9261_spi0_device = {
  298. .name = "atmel_spi",
  299. .id = 0,
  300. .dev = {
  301. .dma_mask = &spi_dmamask,
  302. .coherent_dma_mask = DMA_BIT_MASK(32),
  303. },
  304. .resource = spi0_resources,
  305. .num_resources = ARRAY_SIZE(spi0_resources),
  306. };
  307. static const unsigned spi0_standard_cs[4] = { AT91_PIN_PA3, AT91_PIN_PA4, AT91_PIN_PA5, AT91_PIN_PA6 };
  308. static struct resource spi1_resources[] = {
  309. [0] = {
  310. .start = AT91SAM9261_BASE_SPI1,
  311. .end = AT91SAM9261_BASE_SPI1 + SZ_16K - 1,
  312. .flags = IORESOURCE_MEM,
  313. },
  314. [1] = {
  315. .start = AT91SAM9261_ID_SPI1,
  316. .end = AT91SAM9261_ID_SPI1,
  317. .flags = IORESOURCE_IRQ,
  318. },
  319. };
  320. static struct platform_device at91sam9261_spi1_device = {
  321. .name = "atmel_spi",
  322. .id = 1,
  323. .dev = {
  324. .dma_mask = &spi_dmamask,
  325. .coherent_dma_mask = DMA_BIT_MASK(32),
  326. },
  327. .resource = spi1_resources,
  328. .num_resources = ARRAY_SIZE(spi1_resources),
  329. };
  330. static const unsigned spi1_standard_cs[4] = { AT91_PIN_PB28, AT91_PIN_PA24, AT91_PIN_PA25, AT91_PIN_PA26 };
  331. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
  332. {
  333. int i;
  334. unsigned long cs_pin;
  335. short enable_spi0 = 0;
  336. short enable_spi1 = 0;
  337. /* Choose SPI chip-selects */
  338. for (i = 0; i < nr_devices; i++) {
  339. if (devices[i].controller_data)
  340. cs_pin = (unsigned long) devices[i].controller_data;
  341. else if (devices[i].bus_num == 0)
  342. cs_pin = spi0_standard_cs[devices[i].chip_select];
  343. else
  344. cs_pin = spi1_standard_cs[devices[i].chip_select];
  345. if (devices[i].bus_num == 0)
  346. enable_spi0 = 1;
  347. else
  348. enable_spi1 = 1;
  349. /* enable chip-select pin */
  350. at91_set_gpio_output(cs_pin, 1);
  351. /* pass chip-select pin to driver */
  352. devices[i].controller_data = (void *) cs_pin;
  353. }
  354. spi_register_board_info(devices, nr_devices);
  355. /* Configure SPI bus(es) */
  356. if (enable_spi0) {
  357. at91_set_A_periph(AT91_PIN_PA0, 0); /* SPI0_MISO */
  358. at91_set_A_periph(AT91_PIN_PA1, 0); /* SPI0_MOSI */
  359. at91_set_A_periph(AT91_PIN_PA2, 0); /* SPI0_SPCK */
  360. platform_device_register(&at91sam9261_spi0_device);
  361. }
  362. if (enable_spi1) {
  363. at91_set_A_periph(AT91_PIN_PB30, 0); /* SPI1_MISO */
  364. at91_set_A_periph(AT91_PIN_PB31, 0); /* SPI1_MOSI */
  365. at91_set_A_periph(AT91_PIN_PB29, 0); /* SPI1_SPCK */
  366. platform_device_register(&at91sam9261_spi1_device);
  367. }
  368. }
  369. #else
  370. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
  371. #endif
  372. /* --------------------------------------------------------------------
  373. * LCD Controller
  374. * -------------------------------------------------------------------- */
  375. #if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
  376. static u64 lcdc_dmamask = DMA_BIT_MASK(32);
  377. static struct atmel_lcdfb_info lcdc_data;
  378. static struct resource lcdc_resources[] = {
  379. [0] = {
  380. .start = AT91SAM9261_LCDC_BASE,
  381. .end = AT91SAM9261_LCDC_BASE + SZ_4K - 1,
  382. .flags = IORESOURCE_MEM,
  383. },
  384. [1] = {
  385. .start = AT91SAM9261_ID_LCDC,
  386. .end = AT91SAM9261_ID_LCDC,
  387. .flags = IORESOURCE_IRQ,
  388. },
  389. #if defined(CONFIG_FB_INTSRAM)
  390. [2] = {
  391. .start = AT91SAM9261_SRAM_BASE,
  392. .end = AT91SAM9261_SRAM_BASE + AT91SAM9261_SRAM_SIZE - 1,
  393. .flags = IORESOURCE_MEM,
  394. },
  395. #endif
  396. };
  397. static struct platform_device at91_lcdc_device = {
  398. .name = "atmel_lcdfb",
  399. .id = 0,
  400. .dev = {
  401. .dma_mask = &lcdc_dmamask,
  402. .coherent_dma_mask = DMA_BIT_MASK(32),
  403. .platform_data = &lcdc_data,
  404. },
  405. .resource = lcdc_resources,
  406. .num_resources = ARRAY_SIZE(lcdc_resources),
  407. };
  408. void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data)
  409. {
  410. if (!data) {
  411. return;
  412. }
  413. #if defined(CONFIG_FB_ATMEL_STN)
  414. at91_set_A_periph(AT91_PIN_PB0, 0); /* LCDVSYNC */
  415. at91_set_A_periph(AT91_PIN_PB1, 0); /* LCDHSYNC */
  416. at91_set_A_periph(AT91_PIN_PB2, 0); /* LCDDOTCK */
  417. at91_set_A_periph(AT91_PIN_PB3, 0); /* LCDDEN */
  418. at91_set_A_periph(AT91_PIN_PB4, 0); /* LCDCC */
  419. at91_set_A_periph(AT91_PIN_PB5, 0); /* LCDD0 */
  420. at91_set_A_periph(AT91_PIN_PB6, 0); /* LCDD1 */
  421. at91_set_A_periph(AT91_PIN_PB7, 0); /* LCDD2 */
  422. at91_set_A_periph(AT91_PIN_PB8, 0); /* LCDD3 */
  423. #else
  424. at91_set_A_periph(AT91_PIN_PB1, 0); /* LCDHSYNC */
  425. at91_set_A_periph(AT91_PIN_PB2, 0); /* LCDDOTCK */
  426. at91_set_A_periph(AT91_PIN_PB3, 0); /* LCDDEN */
  427. at91_set_A_periph(AT91_PIN_PB4, 0); /* LCDCC */
  428. at91_set_A_periph(AT91_PIN_PB7, 0); /* LCDD2 */
  429. at91_set_A_periph(AT91_PIN_PB8, 0); /* LCDD3 */
  430. at91_set_A_periph(AT91_PIN_PB9, 0); /* LCDD4 */
  431. at91_set_A_periph(AT91_PIN_PB10, 0); /* LCDD5 */
  432. at91_set_A_periph(AT91_PIN_PB11, 0); /* LCDD6 */
  433. at91_set_A_periph(AT91_PIN_PB12, 0); /* LCDD7 */
  434. at91_set_A_periph(AT91_PIN_PB15, 0); /* LCDD10 */
  435. at91_set_A_periph(AT91_PIN_PB16, 0); /* LCDD11 */
  436. at91_set_A_periph(AT91_PIN_PB17, 0); /* LCDD12 */
  437. at91_set_A_periph(AT91_PIN_PB18, 0); /* LCDD13 */
  438. at91_set_A_periph(AT91_PIN_PB19, 0); /* LCDD14 */
  439. at91_set_A_periph(AT91_PIN_PB20, 0); /* LCDD15 */
  440. at91_set_B_periph(AT91_PIN_PB23, 0); /* LCDD18 */
  441. at91_set_B_periph(AT91_PIN_PB24, 0); /* LCDD19 */
  442. at91_set_B_periph(AT91_PIN_PB25, 0); /* LCDD20 */
  443. at91_set_B_periph(AT91_PIN_PB26, 0); /* LCDD21 */
  444. at91_set_B_periph(AT91_PIN_PB27, 0); /* LCDD22 */
  445. at91_set_B_periph(AT91_PIN_PB28, 0); /* LCDD23 */
  446. #endif
  447. if (ARRAY_SIZE(lcdc_resources) > 2) {
  448. void __iomem *fb;
  449. struct resource *fb_res = &lcdc_resources[2];
  450. size_t fb_len = resource_size(fb_res);
  451. fb = ioremap(fb_res->start, fb_len);
  452. if (fb) {
  453. memset(fb, 0, fb_len);
  454. iounmap(fb);
  455. }
  456. }
  457. lcdc_data = *data;
  458. platform_device_register(&at91_lcdc_device);
  459. }
  460. #else
  461. void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data) {}
  462. #endif
  463. /* --------------------------------------------------------------------
  464. * Timer/Counter block
  465. * -------------------------------------------------------------------- */
  466. #ifdef CONFIG_ATMEL_TCLIB
  467. static struct resource tcb_resources[] = {
  468. [0] = {
  469. .start = AT91SAM9261_BASE_TCB0,
  470. .end = AT91SAM9261_BASE_TCB0 + SZ_16K - 1,
  471. .flags = IORESOURCE_MEM,
  472. },
  473. [1] = {
  474. .start = AT91SAM9261_ID_TC0,
  475. .end = AT91SAM9261_ID_TC0,
  476. .flags = IORESOURCE_IRQ,
  477. },
  478. [2] = {
  479. .start = AT91SAM9261_ID_TC1,
  480. .end = AT91SAM9261_ID_TC1,
  481. .flags = IORESOURCE_IRQ,
  482. },
  483. [3] = {
  484. .start = AT91SAM9261_ID_TC2,
  485. .end = AT91SAM9261_ID_TC2,
  486. .flags = IORESOURCE_IRQ,
  487. },
  488. };
  489. static struct platform_device at91sam9261_tcb_device = {
  490. .name = "atmel_tcb",
  491. .id = 0,
  492. .resource = tcb_resources,
  493. .num_resources = ARRAY_SIZE(tcb_resources),
  494. };
  495. static void __init at91_add_device_tc(void)
  496. {
  497. platform_device_register(&at91sam9261_tcb_device);
  498. }
  499. #else
  500. static void __init at91_add_device_tc(void) { }
  501. #endif
  502. /* --------------------------------------------------------------------
  503. * RTT
  504. * -------------------------------------------------------------------- */
  505. static struct resource rtt_resources[] = {
  506. {
  507. .start = AT91SAM9261_BASE_RTT,
  508. .end = AT91SAM9261_BASE_RTT + SZ_16 - 1,
  509. .flags = IORESOURCE_MEM,
  510. }
  511. };
  512. static struct platform_device at91sam9261_rtt_device = {
  513. .name = "at91_rtt",
  514. .id = 0,
  515. .resource = rtt_resources,
  516. .num_resources = ARRAY_SIZE(rtt_resources),
  517. };
  518. static void __init at91_add_device_rtt(void)
  519. {
  520. platform_device_register(&at91sam9261_rtt_device);
  521. }
  522. /* --------------------------------------------------------------------
  523. * Watchdog
  524. * -------------------------------------------------------------------- */
  525. #if defined(CONFIG_AT91SAM9X_WATCHDOG) || defined(CONFIG_AT91SAM9X_WATCHDOG_MODULE)
  526. static struct resource wdt_resources[] = {
  527. {
  528. .start = AT91SAM9261_BASE_WDT,
  529. .end = AT91SAM9261_BASE_WDT + SZ_16 - 1,
  530. .flags = IORESOURCE_MEM,
  531. }
  532. };
  533. static struct platform_device at91sam9261_wdt_device = {
  534. .name = "at91_wdt",
  535. .id = -1,
  536. .resource = wdt_resources,
  537. .num_resources = ARRAY_SIZE(wdt_resources),
  538. };
  539. static void __init at91_add_device_watchdog(void)
  540. {
  541. platform_device_register(&at91sam9261_wdt_device);
  542. }
  543. #else
  544. static void __init at91_add_device_watchdog(void) {}
  545. #endif
  546. /* --------------------------------------------------------------------
  547. * SSC -- Synchronous Serial Controller
  548. * -------------------------------------------------------------------- */
  549. #if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
  550. static u64 ssc0_dmamask = DMA_BIT_MASK(32);
  551. static struct resource ssc0_resources[] = {
  552. [0] = {
  553. .start = AT91SAM9261_BASE_SSC0,
  554. .end = AT91SAM9261_BASE_SSC0 + SZ_16K - 1,
  555. .flags = IORESOURCE_MEM,
  556. },
  557. [1] = {
  558. .start = AT91SAM9261_ID_SSC0,
  559. .end = AT91SAM9261_ID_SSC0,
  560. .flags = IORESOURCE_IRQ,
  561. },
  562. };
  563. static struct platform_device at91sam9261_ssc0_device = {
  564. .name = "ssc",
  565. .id = 0,
  566. .dev = {
  567. .dma_mask = &ssc0_dmamask,
  568. .coherent_dma_mask = DMA_BIT_MASK(32),
  569. },
  570. .resource = ssc0_resources,
  571. .num_resources = ARRAY_SIZE(ssc0_resources),
  572. };
  573. static inline void configure_ssc0_pins(unsigned pins)
  574. {
  575. if (pins & ATMEL_SSC_TF)
  576. at91_set_A_periph(AT91_PIN_PB21, 1);
  577. if (pins & ATMEL_SSC_TK)
  578. at91_set_A_periph(AT91_PIN_PB22, 1);
  579. if (pins & ATMEL_SSC_TD)
  580. at91_set_A_periph(AT91_PIN_PB23, 1);
  581. if (pins & ATMEL_SSC_RD)
  582. at91_set_A_periph(AT91_PIN_PB24, 1);
  583. if (pins & ATMEL_SSC_RK)
  584. at91_set_A_periph(AT91_PIN_PB25, 1);
  585. if (pins & ATMEL_SSC_RF)
  586. at91_set_A_periph(AT91_PIN_PB26, 1);
  587. }
  588. static u64 ssc1_dmamask = DMA_BIT_MASK(32);
  589. static struct resource ssc1_resources[] = {
  590. [0] = {
  591. .start = AT91SAM9261_BASE_SSC1,
  592. .end = AT91SAM9261_BASE_SSC1 + SZ_16K - 1,
  593. .flags = IORESOURCE_MEM,
  594. },
  595. [1] = {
  596. .start = AT91SAM9261_ID_SSC1,
  597. .end = AT91SAM9261_ID_SSC1,
  598. .flags = IORESOURCE_IRQ,
  599. },
  600. };
  601. static struct platform_device at91sam9261_ssc1_device = {
  602. .name = "ssc",
  603. .id = 1,
  604. .dev = {
  605. .dma_mask = &ssc1_dmamask,
  606. .coherent_dma_mask = DMA_BIT_MASK(32),
  607. },
  608. .resource = ssc1_resources,
  609. .num_resources = ARRAY_SIZE(ssc1_resources),
  610. };
  611. static inline void configure_ssc1_pins(unsigned pins)
  612. {
  613. if (pins & ATMEL_SSC_TF)
  614. at91_set_B_periph(AT91_PIN_PA17, 1);
  615. if (pins & ATMEL_SSC_TK)
  616. at91_set_B_periph(AT91_PIN_PA18, 1);
  617. if (pins & ATMEL_SSC_TD)
  618. at91_set_B_periph(AT91_PIN_PA19, 1);
  619. if (pins & ATMEL_SSC_RD)
  620. at91_set_B_periph(AT91_PIN_PA20, 1);
  621. if (pins & ATMEL_SSC_RK)
  622. at91_set_B_periph(AT91_PIN_PA21, 1);
  623. if (pins & ATMEL_SSC_RF)
  624. at91_set_B_periph(AT91_PIN_PA22, 1);
  625. }
  626. static u64 ssc2_dmamask = DMA_BIT_MASK(32);
  627. static struct resource ssc2_resources[] = {
  628. [0] = {
  629. .start = AT91SAM9261_BASE_SSC2,
  630. .end = AT91SAM9261_BASE_SSC2 + SZ_16K - 1,
  631. .flags = IORESOURCE_MEM,
  632. },
  633. [1] = {
  634. .start = AT91SAM9261_ID_SSC2,
  635. .end = AT91SAM9261_ID_SSC2,
  636. .flags = IORESOURCE_IRQ,
  637. },
  638. };
  639. static struct platform_device at91sam9261_ssc2_device = {
  640. .name = "ssc",
  641. .id = 2,
  642. .dev = {
  643. .dma_mask = &ssc2_dmamask,
  644. .coherent_dma_mask = DMA_BIT_MASK(32),
  645. },
  646. .resource = ssc2_resources,
  647. .num_resources = ARRAY_SIZE(ssc2_resources),
  648. };
  649. static inline void configure_ssc2_pins(unsigned pins)
  650. {
  651. if (pins & ATMEL_SSC_TF)
  652. at91_set_B_periph(AT91_PIN_PC25, 1);
  653. if (pins & ATMEL_SSC_TK)
  654. at91_set_B_periph(AT91_PIN_PC26, 1);
  655. if (pins & ATMEL_SSC_TD)
  656. at91_set_B_periph(AT91_PIN_PC27, 1);
  657. if (pins & ATMEL_SSC_RD)
  658. at91_set_B_periph(AT91_PIN_PC28, 1);
  659. if (pins & ATMEL_SSC_RK)
  660. at91_set_B_periph(AT91_PIN_PC29, 1);
  661. if (pins & ATMEL_SSC_RF)
  662. at91_set_B_periph(AT91_PIN_PC30, 1);
  663. }
  664. /*
  665. * SSC controllers are accessed through library code, instead of any
  666. * kind of all-singing/all-dancing driver. For example one could be
  667. * used by a particular I2S audio codec's driver, while another one
  668. * on the same system might be used by a custom data capture driver.
  669. */
  670. void __init at91_add_device_ssc(unsigned id, unsigned pins)
  671. {
  672. struct platform_device *pdev;
  673. /*
  674. * NOTE: caller is responsible for passing information matching
  675. * "pins" to whatever will be using each particular controller.
  676. */
  677. switch (id) {
  678. case AT91SAM9261_ID_SSC0:
  679. pdev = &at91sam9261_ssc0_device;
  680. configure_ssc0_pins(pins);
  681. break;
  682. case AT91SAM9261_ID_SSC1:
  683. pdev = &at91sam9261_ssc1_device;
  684. configure_ssc1_pins(pins);
  685. break;
  686. case AT91SAM9261_ID_SSC2:
  687. pdev = &at91sam9261_ssc2_device;
  688. configure_ssc2_pins(pins);
  689. break;
  690. default:
  691. return;
  692. }
  693. platform_device_register(pdev);
  694. }
  695. #else
  696. void __init at91_add_device_ssc(unsigned id, unsigned pins) {}
  697. #endif
  698. /* --------------------------------------------------------------------
  699. * UART
  700. * -------------------------------------------------------------------- */
  701. #if defined(CONFIG_SERIAL_ATMEL)
  702. static struct resource dbgu_resources[] = {
  703. [0] = {
  704. .start = AT91SAM9261_BASE_DBGU,
  705. .end = AT91SAM9261_BASE_DBGU + SZ_512 - 1,
  706. .flags = IORESOURCE_MEM,
  707. },
  708. [1] = {
  709. .start = AT91_ID_SYS,
  710. .end = AT91_ID_SYS,
  711. .flags = IORESOURCE_IRQ,
  712. },
  713. };
  714. static struct atmel_uart_data dbgu_data = {
  715. .use_dma_tx = 0,
  716. .use_dma_rx = 0, /* DBGU not capable of receive DMA */
  717. };
  718. static u64 dbgu_dmamask = DMA_BIT_MASK(32);
  719. static struct platform_device at91sam9261_dbgu_device = {
  720. .name = "atmel_usart",
  721. .id = 0,
  722. .dev = {
  723. .dma_mask = &dbgu_dmamask,
  724. .coherent_dma_mask = DMA_BIT_MASK(32),
  725. .platform_data = &dbgu_data,
  726. },
  727. .resource = dbgu_resources,
  728. .num_resources = ARRAY_SIZE(dbgu_resources),
  729. };
  730. static inline void configure_dbgu_pins(void)
  731. {
  732. at91_set_A_periph(AT91_PIN_PA9, 0); /* DRXD */
  733. at91_set_A_periph(AT91_PIN_PA10, 1); /* DTXD */
  734. }
  735. static struct resource uart0_resources[] = {
  736. [0] = {
  737. .start = AT91SAM9261_BASE_US0,
  738. .end = AT91SAM9261_BASE_US0 + SZ_16K - 1,
  739. .flags = IORESOURCE_MEM,
  740. },
  741. [1] = {
  742. .start = AT91SAM9261_ID_US0,
  743. .end = AT91SAM9261_ID_US0,
  744. .flags = IORESOURCE_IRQ,
  745. },
  746. };
  747. static struct atmel_uart_data uart0_data = {
  748. .use_dma_tx = 1,
  749. .use_dma_rx = 1,
  750. };
  751. static u64 uart0_dmamask = DMA_BIT_MASK(32);
  752. static struct platform_device at91sam9261_uart0_device = {
  753. .name = "atmel_usart",
  754. .id = 1,
  755. .dev = {
  756. .dma_mask = &uart0_dmamask,
  757. .coherent_dma_mask = DMA_BIT_MASK(32),
  758. .platform_data = &uart0_data,
  759. },
  760. .resource = uart0_resources,
  761. .num_resources = ARRAY_SIZE(uart0_resources),
  762. };
  763. static inline void configure_usart0_pins(unsigned pins)
  764. {
  765. at91_set_A_periph(AT91_PIN_PC8, 1); /* TXD0 */
  766. at91_set_A_periph(AT91_PIN_PC9, 0); /* RXD0 */
  767. if (pins & ATMEL_UART_RTS)
  768. at91_set_A_periph(AT91_PIN_PC10, 0); /* RTS0 */
  769. if (pins & ATMEL_UART_CTS)
  770. at91_set_A_periph(AT91_PIN_PC11, 0); /* CTS0 */
  771. }
  772. static struct resource uart1_resources[] = {
  773. [0] = {
  774. .start = AT91SAM9261_BASE_US1,
  775. .end = AT91SAM9261_BASE_US1 + SZ_16K - 1,
  776. .flags = IORESOURCE_MEM,
  777. },
  778. [1] = {
  779. .start = AT91SAM9261_ID_US1,
  780. .end = AT91SAM9261_ID_US1,
  781. .flags = IORESOURCE_IRQ,
  782. },
  783. };
  784. static struct atmel_uart_data uart1_data = {
  785. .use_dma_tx = 1,
  786. .use_dma_rx = 1,
  787. };
  788. static u64 uart1_dmamask = DMA_BIT_MASK(32);
  789. static struct platform_device at91sam9261_uart1_device = {
  790. .name = "atmel_usart",
  791. .id = 2,
  792. .dev = {
  793. .dma_mask = &uart1_dmamask,
  794. .coherent_dma_mask = DMA_BIT_MASK(32),
  795. .platform_data = &uart1_data,
  796. },
  797. .resource = uart1_resources,
  798. .num_resources = ARRAY_SIZE(uart1_resources),
  799. };
  800. static inline void configure_usart1_pins(unsigned pins)
  801. {
  802. at91_set_A_periph(AT91_PIN_PC12, 1); /* TXD1 */
  803. at91_set_A_periph(AT91_PIN_PC13, 0); /* RXD1 */
  804. if (pins & ATMEL_UART_RTS)
  805. at91_set_B_periph(AT91_PIN_PA12, 0); /* RTS1 */
  806. if (pins & ATMEL_UART_CTS)
  807. at91_set_B_periph(AT91_PIN_PA13, 0); /* CTS1 */
  808. }
  809. static struct resource uart2_resources[] = {
  810. [0] = {
  811. .start = AT91SAM9261_BASE_US2,
  812. .end = AT91SAM9261_BASE_US2 + SZ_16K - 1,
  813. .flags = IORESOURCE_MEM,
  814. },
  815. [1] = {
  816. .start = AT91SAM9261_ID_US2,
  817. .end = AT91SAM9261_ID_US2,
  818. .flags = IORESOURCE_IRQ,
  819. },
  820. };
  821. static struct atmel_uart_data uart2_data = {
  822. .use_dma_tx = 1,
  823. .use_dma_rx = 1,
  824. };
  825. static u64 uart2_dmamask = DMA_BIT_MASK(32);
  826. static struct platform_device at91sam9261_uart2_device = {
  827. .name = "atmel_usart",
  828. .id = 3,
  829. .dev = {
  830. .dma_mask = &uart2_dmamask,
  831. .coherent_dma_mask = DMA_BIT_MASK(32),
  832. .platform_data = &uart2_data,
  833. },
  834. .resource = uart2_resources,
  835. .num_resources = ARRAY_SIZE(uart2_resources),
  836. };
  837. static inline void configure_usart2_pins(unsigned pins)
  838. {
  839. at91_set_A_periph(AT91_PIN_PC15, 0); /* RXD2 */
  840. at91_set_A_periph(AT91_PIN_PC14, 1); /* TXD2 */
  841. if (pins & ATMEL_UART_RTS)
  842. at91_set_B_periph(AT91_PIN_PA15, 0); /* RTS2*/
  843. if (pins & ATMEL_UART_CTS)
  844. at91_set_B_periph(AT91_PIN_PA16, 0); /* CTS2 */
  845. }
  846. static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
  847. struct platform_device *atmel_default_console_device; /* the serial console device */
  848. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
  849. {
  850. struct platform_device *pdev;
  851. struct atmel_uart_data *pdata;
  852. switch (id) {
  853. case 0: /* DBGU */
  854. pdev = &at91sam9261_dbgu_device;
  855. configure_dbgu_pins();
  856. break;
  857. case AT91SAM9261_ID_US0:
  858. pdev = &at91sam9261_uart0_device;
  859. configure_usart0_pins(pins);
  860. break;
  861. case AT91SAM9261_ID_US1:
  862. pdev = &at91sam9261_uart1_device;
  863. configure_usart1_pins(pins);
  864. break;
  865. case AT91SAM9261_ID_US2:
  866. pdev = &at91sam9261_uart2_device;
  867. configure_usart2_pins(pins);
  868. break;
  869. default:
  870. return;
  871. }
  872. pdata = pdev->dev.platform_data;
  873. pdata->num = portnr; /* update to mapped ID */
  874. if (portnr < ATMEL_MAX_UART)
  875. at91_uarts[portnr] = pdev;
  876. }
  877. void __init at91_set_serial_console(unsigned portnr)
  878. {
  879. if (portnr < ATMEL_MAX_UART) {
  880. atmel_default_console_device = at91_uarts[portnr];
  881. at91sam9261_set_console_clock(at91_uarts[portnr]->id);
  882. }
  883. }
  884. void __init at91_add_device_serial(void)
  885. {
  886. int i;
  887. for (i = 0; i < ATMEL_MAX_UART; i++) {
  888. if (at91_uarts[i])
  889. platform_device_register(at91_uarts[i]);
  890. }
  891. if (!atmel_default_console_device)
  892. printk(KERN_INFO "AT91: No default serial console defined.\n");
  893. }
  894. #else
  895. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
  896. void __init at91_set_serial_console(unsigned portnr) {}
  897. void __init at91_add_device_serial(void) {}
  898. #endif
  899. /* -------------------------------------------------------------------- */
  900. /*
  901. * These devices are always present and don't need any board-specific
  902. * setup.
  903. */
  904. static int __init at91_add_standard_devices(void)
  905. {
  906. at91_add_device_rtt();
  907. at91_add_device_watchdog();
  908. at91_add_device_tc();
  909. return 0;
  910. }
  911. arch_initcall(at91_add_standard_devices);