at91sam9rl_devices.c 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124
  1. /*
  2. * Copyright (C) 2007 Atmel Corporation
  3. *
  4. * This file is subject to the terms and conditions of the GNU General Public
  5. * License. See the file COPYING in the main directory of this archive for
  6. * more details.
  7. */
  8. #include <asm/mach/arch.h>
  9. #include <asm/mach/map.h>
  10. #include <linux/dma-mapping.h>
  11. #include <linux/platform_device.h>
  12. #include <linux/i2c-gpio.h>
  13. #include <linux/fb.h>
  14. #include <video/atmel_lcdc.h>
  15. #include <mach/board.h>
  16. #include <mach/gpio.h>
  17. #include <mach/at91sam9rl.h>
  18. #include <mach/at91sam9rl_matrix.h>
  19. #include <mach/at91sam9_smc.h>
  20. #include "generic.h"
  21. /* --------------------------------------------------------------------
  22. * USB HS Device (Gadget)
  23. * -------------------------------------------------------------------- */
  24. #if defined(CONFIG_USB_GADGET_ATMEL_USBA) || defined(CONFIG_USB_GADGET_ATMEL_USBA_MODULE)
  25. static struct resource usba_udc_resources[] = {
  26. [0] = {
  27. .start = AT91SAM9RL_UDPHS_FIFO,
  28. .end = AT91SAM9RL_UDPHS_FIFO + SZ_512K - 1,
  29. .flags = IORESOURCE_MEM,
  30. },
  31. [1] = {
  32. .start = AT91SAM9RL_BASE_UDPHS,
  33. .end = AT91SAM9RL_BASE_UDPHS + SZ_1K - 1,
  34. .flags = IORESOURCE_MEM,
  35. },
  36. [2] = {
  37. .start = AT91SAM9RL_ID_UDPHS,
  38. .end = AT91SAM9RL_ID_UDPHS,
  39. .flags = IORESOURCE_IRQ,
  40. },
  41. };
  42. #define EP(nam, idx, maxpkt, maxbk, dma, isoc) \
  43. [idx] = { \
  44. .name = nam, \
  45. .index = idx, \
  46. .fifo_size = maxpkt, \
  47. .nr_banks = maxbk, \
  48. .can_dma = dma, \
  49. .can_isoc = isoc, \
  50. }
  51. static struct usba_ep_data usba_udc_ep[] __initdata = {
  52. EP("ep0", 0, 64, 1, 0, 0),
  53. EP("ep1", 1, 1024, 2, 1, 1),
  54. EP("ep2", 2, 1024, 2, 1, 1),
  55. EP("ep3", 3, 1024, 3, 1, 0),
  56. EP("ep4", 4, 1024, 3, 1, 0),
  57. EP("ep5", 5, 1024, 3, 1, 1),
  58. EP("ep6", 6, 1024, 3, 1, 1),
  59. };
  60. #undef EP
  61. /*
  62. * pdata doesn't have room for any endpoints, so we need to
  63. * append room for the ones we need right after it.
  64. */
  65. static struct {
  66. struct usba_platform_data pdata;
  67. struct usba_ep_data ep[7];
  68. } usba_udc_data;
  69. static struct platform_device at91_usba_udc_device = {
  70. .name = "atmel_usba_udc",
  71. .id = -1,
  72. .dev = {
  73. .platform_data = &usba_udc_data.pdata,
  74. },
  75. .resource = usba_udc_resources,
  76. .num_resources = ARRAY_SIZE(usba_udc_resources),
  77. };
  78. void __init at91_add_device_usba(struct usba_platform_data *data)
  79. {
  80. /*
  81. * Invalid pins are 0 on AT91, but the usba driver is shared
  82. * with AVR32, which use negative values instead. Once/if
  83. * gpio_is_valid() is ported to AT91, revisit this code.
  84. */
  85. usba_udc_data.pdata.vbus_pin = -EINVAL;
  86. usba_udc_data.pdata.num_ep = ARRAY_SIZE(usba_udc_ep);
  87. memcpy(usba_udc_data.ep, usba_udc_ep, sizeof(usba_udc_ep));;
  88. if (data && data->vbus_pin > 0) {
  89. at91_set_gpio_input(data->vbus_pin, 0);
  90. at91_set_deglitch(data->vbus_pin, 1);
  91. usba_udc_data.pdata.vbus_pin = data->vbus_pin;
  92. }
  93. /* Pullup pin is handled internally by USB device peripheral */
  94. /* Clocks */
  95. at91_clock_associate("utmi_clk", &at91_usba_udc_device.dev, "hclk");
  96. at91_clock_associate("udphs_clk", &at91_usba_udc_device.dev, "pclk");
  97. platform_device_register(&at91_usba_udc_device);
  98. }
  99. #else
  100. void __init at91_add_device_usba(struct usba_platform_data *data) {}
  101. #endif
  102. /* --------------------------------------------------------------------
  103. * MMC / SD
  104. * -------------------------------------------------------------------- */
  105. #if defined(CONFIG_MMC_AT91) || defined(CONFIG_MMC_AT91_MODULE)
  106. static u64 mmc_dmamask = DMA_BIT_MASK(32);
  107. static struct at91_mmc_data mmc_data;
  108. static struct resource mmc_resources[] = {
  109. [0] = {
  110. .start = AT91SAM9RL_BASE_MCI,
  111. .end = AT91SAM9RL_BASE_MCI + SZ_16K - 1,
  112. .flags = IORESOURCE_MEM,
  113. },
  114. [1] = {
  115. .start = AT91SAM9RL_ID_MCI,
  116. .end = AT91SAM9RL_ID_MCI,
  117. .flags = IORESOURCE_IRQ,
  118. },
  119. };
  120. static struct platform_device at91sam9rl_mmc_device = {
  121. .name = "at91_mci",
  122. .id = -1,
  123. .dev = {
  124. .dma_mask = &mmc_dmamask,
  125. .coherent_dma_mask = DMA_BIT_MASK(32),
  126. .platform_data = &mmc_data,
  127. },
  128. .resource = mmc_resources,
  129. .num_resources = ARRAY_SIZE(mmc_resources),
  130. };
  131. void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data)
  132. {
  133. if (!data)
  134. return;
  135. /* input/irq */
  136. if (data->det_pin) {
  137. at91_set_gpio_input(data->det_pin, 1);
  138. at91_set_deglitch(data->det_pin, 1);
  139. }
  140. if (data->wp_pin)
  141. at91_set_gpio_input(data->wp_pin, 1);
  142. if (data->vcc_pin)
  143. at91_set_gpio_output(data->vcc_pin, 0);
  144. /* CLK */
  145. at91_set_A_periph(AT91_PIN_PA2, 0);
  146. /* CMD */
  147. at91_set_A_periph(AT91_PIN_PA1, 1);
  148. /* DAT0, maybe DAT1..DAT3 */
  149. at91_set_A_periph(AT91_PIN_PA0, 1);
  150. if (data->wire4) {
  151. at91_set_A_periph(AT91_PIN_PA3, 1);
  152. at91_set_A_periph(AT91_PIN_PA4, 1);
  153. at91_set_A_periph(AT91_PIN_PA5, 1);
  154. }
  155. mmc_data = *data;
  156. platform_device_register(&at91sam9rl_mmc_device);
  157. }
  158. #else
  159. void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data) {}
  160. #endif
  161. /* --------------------------------------------------------------------
  162. * NAND / SmartMedia
  163. * -------------------------------------------------------------------- */
  164. #if defined(CONFIG_MTD_NAND_ATMEL) || defined(CONFIG_MTD_NAND_ATMEL_MODULE)
  165. static struct atmel_nand_data nand_data;
  166. #define NAND_BASE AT91_CHIPSELECT_3
  167. static struct resource nand_resources[] = {
  168. [0] = {
  169. .start = NAND_BASE,
  170. .end = NAND_BASE + SZ_256M - 1,
  171. .flags = IORESOURCE_MEM,
  172. },
  173. [1] = {
  174. .start = AT91_BASE_SYS + AT91_ECC,
  175. .end = AT91_BASE_SYS + AT91_ECC + SZ_512 - 1,
  176. .flags = IORESOURCE_MEM,
  177. }
  178. };
  179. static struct platform_device atmel_nand_device = {
  180. .name = "atmel_nand",
  181. .id = -1,
  182. .dev = {
  183. .platform_data = &nand_data,
  184. },
  185. .resource = nand_resources,
  186. .num_resources = ARRAY_SIZE(nand_resources),
  187. };
  188. void __init at91_add_device_nand(struct atmel_nand_data *data)
  189. {
  190. unsigned long csa;
  191. if (!data)
  192. return;
  193. csa = at91_sys_read(AT91_MATRIX_EBICSA);
  194. at91_sys_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_CS3A_SMC_SMARTMEDIA);
  195. /* set the bus interface characteristics */
  196. at91_sys_write(AT91_SMC_SETUP(3), AT91_SMC_NWESETUP_(1) | AT91_SMC_NCS_WRSETUP_(0)
  197. | AT91_SMC_NRDSETUP_(1) | AT91_SMC_NCS_RDSETUP_(0));
  198. at91_sys_write(AT91_SMC_PULSE(3), AT91_SMC_NWEPULSE_(3) | AT91_SMC_NCS_WRPULSE_(3)
  199. | AT91_SMC_NRDPULSE_(3) | AT91_SMC_NCS_RDPULSE_(3));
  200. at91_sys_write(AT91_SMC_CYCLE(3), AT91_SMC_NWECYCLE_(5) | AT91_SMC_NRDCYCLE_(5));
  201. at91_sys_write(AT91_SMC_MODE(3), AT91_SMC_DBW_8 | AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_TDF_(2));
  202. /* enable pin */
  203. if (data->enable_pin)
  204. at91_set_gpio_output(data->enable_pin, 1);
  205. /* ready/busy pin */
  206. if (data->rdy_pin)
  207. at91_set_gpio_input(data->rdy_pin, 1);
  208. /* card detect pin */
  209. if (data->det_pin)
  210. at91_set_gpio_input(data->det_pin, 1);
  211. at91_set_A_periph(AT91_PIN_PB4, 0); /* NANDOE */
  212. at91_set_A_periph(AT91_PIN_PB5, 0); /* NANDWE */
  213. nand_data = *data;
  214. platform_device_register(&atmel_nand_device);
  215. }
  216. #else
  217. void __init at91_add_device_nand(struct atmel_nand_data *data) {}
  218. #endif
  219. /* --------------------------------------------------------------------
  220. * TWI (i2c)
  221. * -------------------------------------------------------------------- */
  222. /*
  223. * Prefer the GPIO code since the TWI controller isn't robust
  224. * (gets overruns and underruns under load) and can only issue
  225. * repeated STARTs in one scenario (the driver doesn't yet handle them).
  226. */
  227. #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
  228. static struct i2c_gpio_platform_data pdata = {
  229. .sda_pin = AT91_PIN_PA23,
  230. .sda_is_open_drain = 1,
  231. .scl_pin = AT91_PIN_PA24,
  232. .scl_is_open_drain = 1,
  233. .udelay = 2, /* ~100 kHz */
  234. };
  235. static struct platform_device at91sam9rl_twi_device = {
  236. .name = "i2c-gpio",
  237. .id = -1,
  238. .dev.platform_data = &pdata,
  239. };
  240. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  241. {
  242. at91_set_GPIO_periph(AT91_PIN_PA23, 1); /* TWD (SDA) */
  243. at91_set_multi_drive(AT91_PIN_PA23, 1);
  244. at91_set_GPIO_periph(AT91_PIN_PA24, 1); /* TWCK (SCL) */
  245. at91_set_multi_drive(AT91_PIN_PA24, 1);
  246. i2c_register_board_info(0, devices, nr_devices);
  247. platform_device_register(&at91sam9rl_twi_device);
  248. }
  249. #elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
  250. static struct resource twi_resources[] = {
  251. [0] = {
  252. .start = AT91SAM9RL_BASE_TWI0,
  253. .end = AT91SAM9RL_BASE_TWI0 + SZ_16K - 1,
  254. .flags = IORESOURCE_MEM,
  255. },
  256. [1] = {
  257. .start = AT91SAM9RL_ID_TWI0,
  258. .end = AT91SAM9RL_ID_TWI0,
  259. .flags = IORESOURCE_IRQ,
  260. },
  261. };
  262. static struct platform_device at91sam9rl_twi_device = {
  263. .name = "at91_i2c",
  264. .id = -1,
  265. .resource = twi_resources,
  266. .num_resources = ARRAY_SIZE(twi_resources),
  267. };
  268. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  269. {
  270. /* pins used for TWI interface */
  271. at91_set_A_periph(AT91_PIN_PA23, 0); /* TWD */
  272. at91_set_multi_drive(AT91_PIN_PA23, 1);
  273. at91_set_A_periph(AT91_PIN_PA24, 0); /* TWCK */
  274. at91_set_multi_drive(AT91_PIN_PA24, 1);
  275. i2c_register_board_info(0, devices, nr_devices);
  276. platform_device_register(&at91sam9rl_twi_device);
  277. }
  278. #else
  279. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {}
  280. #endif
  281. /* --------------------------------------------------------------------
  282. * SPI
  283. * -------------------------------------------------------------------- */
  284. #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
  285. static u64 spi_dmamask = DMA_BIT_MASK(32);
  286. static struct resource spi_resources[] = {
  287. [0] = {
  288. .start = AT91SAM9RL_BASE_SPI,
  289. .end = AT91SAM9RL_BASE_SPI + SZ_16K - 1,
  290. .flags = IORESOURCE_MEM,
  291. },
  292. [1] = {
  293. .start = AT91SAM9RL_ID_SPI,
  294. .end = AT91SAM9RL_ID_SPI,
  295. .flags = IORESOURCE_IRQ,
  296. },
  297. };
  298. static struct platform_device at91sam9rl_spi_device = {
  299. .name = "atmel_spi",
  300. .id = 0,
  301. .dev = {
  302. .dma_mask = &spi_dmamask,
  303. .coherent_dma_mask = DMA_BIT_MASK(32),
  304. },
  305. .resource = spi_resources,
  306. .num_resources = ARRAY_SIZE(spi_resources),
  307. };
  308. static const unsigned spi_standard_cs[4] = { AT91_PIN_PA28, AT91_PIN_PB7, AT91_PIN_PD8, AT91_PIN_PD9 };
  309. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
  310. {
  311. int i;
  312. unsigned long cs_pin;
  313. at91_set_A_periph(AT91_PIN_PA25, 0); /* MISO */
  314. at91_set_A_periph(AT91_PIN_PA26, 0); /* MOSI */
  315. at91_set_A_periph(AT91_PIN_PA27, 0); /* SPCK */
  316. /* Enable SPI chip-selects */
  317. for (i = 0; i < nr_devices; i++) {
  318. if (devices[i].controller_data)
  319. cs_pin = (unsigned long) devices[i].controller_data;
  320. else
  321. cs_pin = spi_standard_cs[devices[i].chip_select];
  322. /* enable chip-select pin */
  323. at91_set_gpio_output(cs_pin, 1);
  324. /* pass chip-select pin to driver */
  325. devices[i].controller_data = (void *) cs_pin;
  326. }
  327. spi_register_board_info(devices, nr_devices);
  328. platform_device_register(&at91sam9rl_spi_device);
  329. }
  330. #else
  331. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
  332. #endif
  333. /* --------------------------------------------------------------------
  334. * LCD Controller
  335. * -------------------------------------------------------------------- */
  336. #if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
  337. static u64 lcdc_dmamask = DMA_BIT_MASK(32);
  338. static struct atmel_lcdfb_info lcdc_data;
  339. static struct resource lcdc_resources[] = {
  340. [0] = {
  341. .start = AT91SAM9RL_LCDC_BASE,
  342. .end = AT91SAM9RL_LCDC_BASE + SZ_4K - 1,
  343. .flags = IORESOURCE_MEM,
  344. },
  345. [1] = {
  346. .start = AT91SAM9RL_ID_LCDC,
  347. .end = AT91SAM9RL_ID_LCDC,
  348. .flags = IORESOURCE_IRQ,
  349. },
  350. };
  351. static struct platform_device at91_lcdc_device = {
  352. .name = "atmel_lcdfb",
  353. .id = 0,
  354. .dev = {
  355. .dma_mask = &lcdc_dmamask,
  356. .coherent_dma_mask = DMA_BIT_MASK(32),
  357. .platform_data = &lcdc_data,
  358. },
  359. .resource = lcdc_resources,
  360. .num_resources = ARRAY_SIZE(lcdc_resources),
  361. };
  362. void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data)
  363. {
  364. if (!data) {
  365. return;
  366. }
  367. at91_set_B_periph(AT91_PIN_PC1, 0); /* LCDPWR */
  368. at91_set_A_periph(AT91_PIN_PC5, 0); /* LCDHSYNC */
  369. at91_set_A_periph(AT91_PIN_PC6, 0); /* LCDDOTCK */
  370. at91_set_A_periph(AT91_PIN_PC7, 0); /* LCDDEN */
  371. at91_set_A_periph(AT91_PIN_PC3, 0); /* LCDCC */
  372. at91_set_B_periph(AT91_PIN_PC9, 0); /* LCDD3 */
  373. at91_set_B_periph(AT91_PIN_PC10, 0); /* LCDD4 */
  374. at91_set_B_periph(AT91_PIN_PC11, 0); /* LCDD5 */
  375. at91_set_B_periph(AT91_PIN_PC12, 0); /* LCDD6 */
  376. at91_set_B_periph(AT91_PIN_PC13, 0); /* LCDD7 */
  377. at91_set_B_periph(AT91_PIN_PC15, 0); /* LCDD11 */
  378. at91_set_B_periph(AT91_PIN_PC16, 0); /* LCDD12 */
  379. at91_set_B_periph(AT91_PIN_PC17, 0); /* LCDD13 */
  380. at91_set_B_periph(AT91_PIN_PC18, 0); /* LCDD14 */
  381. at91_set_B_periph(AT91_PIN_PC19, 0); /* LCDD15 */
  382. at91_set_B_periph(AT91_PIN_PC20, 0); /* LCDD18 */
  383. at91_set_B_periph(AT91_PIN_PC21, 0); /* LCDD19 */
  384. at91_set_B_periph(AT91_PIN_PC22, 0); /* LCDD20 */
  385. at91_set_B_periph(AT91_PIN_PC23, 0); /* LCDD21 */
  386. at91_set_B_periph(AT91_PIN_PC24, 0); /* LCDD22 */
  387. at91_set_B_periph(AT91_PIN_PC25, 0); /* LCDD23 */
  388. lcdc_data = *data;
  389. platform_device_register(&at91_lcdc_device);
  390. }
  391. #else
  392. void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data) {}
  393. #endif
  394. /* --------------------------------------------------------------------
  395. * Timer/Counter block
  396. * -------------------------------------------------------------------- */
  397. #ifdef CONFIG_ATMEL_TCLIB
  398. static struct resource tcb_resources[] = {
  399. [0] = {
  400. .start = AT91SAM9RL_BASE_TCB0,
  401. .end = AT91SAM9RL_BASE_TCB0 + SZ_16K - 1,
  402. .flags = IORESOURCE_MEM,
  403. },
  404. [1] = {
  405. .start = AT91SAM9RL_ID_TC0,
  406. .end = AT91SAM9RL_ID_TC0,
  407. .flags = IORESOURCE_IRQ,
  408. },
  409. [2] = {
  410. .start = AT91SAM9RL_ID_TC1,
  411. .end = AT91SAM9RL_ID_TC1,
  412. .flags = IORESOURCE_IRQ,
  413. },
  414. [3] = {
  415. .start = AT91SAM9RL_ID_TC2,
  416. .end = AT91SAM9RL_ID_TC2,
  417. .flags = IORESOURCE_IRQ,
  418. },
  419. };
  420. static struct platform_device at91sam9rl_tcb_device = {
  421. .name = "atmel_tcb",
  422. .id = 0,
  423. .resource = tcb_resources,
  424. .num_resources = ARRAY_SIZE(tcb_resources),
  425. };
  426. static void __init at91_add_device_tc(void)
  427. {
  428. /* this chip has a separate clock and irq for each TC channel */
  429. at91_clock_associate("tc0_clk", &at91sam9rl_tcb_device.dev, "t0_clk");
  430. at91_clock_associate("tc1_clk", &at91sam9rl_tcb_device.dev, "t1_clk");
  431. at91_clock_associate("tc2_clk", &at91sam9rl_tcb_device.dev, "t2_clk");
  432. platform_device_register(&at91sam9rl_tcb_device);
  433. }
  434. #else
  435. static void __init at91_add_device_tc(void) { }
  436. #endif
  437. /* --------------------------------------------------------------------
  438. * Touchscreen
  439. * -------------------------------------------------------------------- */
  440. #if defined(CONFIG_TOUCHSCREEN_ATMEL_TSADCC) || defined(CONFIG_TOUCHSCREEN_ATMEL_TSADCC_MODULE)
  441. static u64 tsadcc_dmamask = DMA_BIT_MASK(32);
  442. static struct resource tsadcc_resources[] = {
  443. [0] = {
  444. .start = AT91SAM9RL_BASE_TSC,
  445. .end = AT91SAM9RL_BASE_TSC + SZ_16K - 1,
  446. .flags = IORESOURCE_MEM,
  447. },
  448. [1] = {
  449. .start = AT91SAM9RL_ID_TSC,
  450. .end = AT91SAM9RL_ID_TSC,
  451. .flags = IORESOURCE_IRQ,
  452. }
  453. };
  454. static struct platform_device at91sam9rl_tsadcc_device = {
  455. .name = "atmel_tsadcc",
  456. .id = -1,
  457. .dev = {
  458. .dma_mask = &tsadcc_dmamask,
  459. .coherent_dma_mask = DMA_BIT_MASK(32),
  460. },
  461. .resource = tsadcc_resources,
  462. .num_resources = ARRAY_SIZE(tsadcc_resources),
  463. };
  464. void __init at91_add_device_tsadcc(void)
  465. {
  466. at91_set_A_periph(AT91_PIN_PA17, 0); /* AD0_XR */
  467. at91_set_A_periph(AT91_PIN_PA18, 0); /* AD1_XL */
  468. at91_set_A_periph(AT91_PIN_PA19, 0); /* AD2_YT */
  469. at91_set_A_periph(AT91_PIN_PA20, 0); /* AD3_TB */
  470. platform_device_register(&at91sam9rl_tsadcc_device);
  471. }
  472. #else
  473. void __init at91_add_device_tsadcc(void) {}
  474. #endif
  475. /* --------------------------------------------------------------------
  476. * RTC
  477. * -------------------------------------------------------------------- */
  478. #if defined(CONFIG_RTC_DRV_AT91RM9200) || defined(CONFIG_RTC_DRV_AT91RM9200_MODULE)
  479. static struct platform_device at91sam9rl_rtc_device = {
  480. .name = "at91_rtc",
  481. .id = -1,
  482. .num_resources = 0,
  483. };
  484. static void __init at91_add_device_rtc(void)
  485. {
  486. platform_device_register(&at91sam9rl_rtc_device);
  487. }
  488. #else
  489. static void __init at91_add_device_rtc(void) {}
  490. #endif
  491. /* --------------------------------------------------------------------
  492. * RTT
  493. * -------------------------------------------------------------------- */
  494. static struct resource rtt_resources[] = {
  495. {
  496. .start = AT91_BASE_SYS + AT91_RTT,
  497. .end = AT91_BASE_SYS + AT91_RTT + SZ_16 - 1,
  498. .flags = IORESOURCE_MEM,
  499. }
  500. };
  501. static struct platform_device at91sam9rl_rtt_device = {
  502. .name = "at91_rtt",
  503. .id = 0,
  504. .resource = rtt_resources,
  505. .num_resources = ARRAY_SIZE(rtt_resources),
  506. };
  507. static void __init at91_add_device_rtt(void)
  508. {
  509. platform_device_register(&at91sam9rl_rtt_device);
  510. }
  511. /* --------------------------------------------------------------------
  512. * Watchdog
  513. * -------------------------------------------------------------------- */
  514. #if defined(CONFIG_AT91SAM9_WATCHDOG) || defined(CONFIG_AT91SAM9_WATCHDOG_MODULE)
  515. static struct platform_device at91sam9rl_wdt_device = {
  516. .name = "at91_wdt",
  517. .id = -1,
  518. .num_resources = 0,
  519. };
  520. static void __init at91_add_device_watchdog(void)
  521. {
  522. platform_device_register(&at91sam9rl_wdt_device);
  523. }
  524. #else
  525. static void __init at91_add_device_watchdog(void) {}
  526. #endif
  527. /* --------------------------------------------------------------------
  528. * PWM
  529. * --------------------------------------------------------------------*/
  530. #if defined(CONFIG_ATMEL_PWM)
  531. static u32 pwm_mask;
  532. static struct resource pwm_resources[] = {
  533. [0] = {
  534. .start = AT91SAM9RL_BASE_PWMC,
  535. .end = AT91SAM9RL_BASE_PWMC + SZ_16K - 1,
  536. .flags = IORESOURCE_MEM,
  537. },
  538. [1] = {
  539. .start = AT91SAM9RL_ID_PWMC,
  540. .end = AT91SAM9RL_ID_PWMC,
  541. .flags = IORESOURCE_IRQ,
  542. },
  543. };
  544. static struct platform_device at91sam9rl_pwm0_device = {
  545. .name = "atmel_pwm",
  546. .id = -1,
  547. .dev = {
  548. .platform_data = &pwm_mask,
  549. },
  550. .resource = pwm_resources,
  551. .num_resources = ARRAY_SIZE(pwm_resources),
  552. };
  553. void __init at91_add_device_pwm(u32 mask)
  554. {
  555. if (mask & (1 << AT91_PWM0))
  556. at91_set_B_periph(AT91_PIN_PB8, 1); /* enable PWM0 */
  557. if (mask & (1 << AT91_PWM1))
  558. at91_set_B_periph(AT91_PIN_PB9, 1); /* enable PWM1 */
  559. if (mask & (1 << AT91_PWM2))
  560. at91_set_B_periph(AT91_PIN_PD5, 1); /* enable PWM2 */
  561. if (mask & (1 << AT91_PWM3))
  562. at91_set_B_periph(AT91_PIN_PD8, 1); /* enable PWM3 */
  563. pwm_mask = mask;
  564. platform_device_register(&at91sam9rl_pwm0_device);
  565. }
  566. #else
  567. void __init at91_add_device_pwm(u32 mask) {}
  568. #endif
  569. /* --------------------------------------------------------------------
  570. * SSC -- Synchronous Serial Controller
  571. * -------------------------------------------------------------------- */
  572. #if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
  573. static u64 ssc0_dmamask = DMA_BIT_MASK(32);
  574. static struct resource ssc0_resources[] = {
  575. [0] = {
  576. .start = AT91SAM9RL_BASE_SSC0,
  577. .end = AT91SAM9RL_BASE_SSC0 + SZ_16K - 1,
  578. .flags = IORESOURCE_MEM,
  579. },
  580. [1] = {
  581. .start = AT91SAM9RL_ID_SSC0,
  582. .end = AT91SAM9RL_ID_SSC0,
  583. .flags = IORESOURCE_IRQ,
  584. },
  585. };
  586. static struct platform_device at91sam9rl_ssc0_device = {
  587. .name = "ssc",
  588. .id = 0,
  589. .dev = {
  590. .dma_mask = &ssc0_dmamask,
  591. .coherent_dma_mask = DMA_BIT_MASK(32),
  592. },
  593. .resource = ssc0_resources,
  594. .num_resources = ARRAY_SIZE(ssc0_resources),
  595. };
  596. static inline void configure_ssc0_pins(unsigned pins)
  597. {
  598. if (pins & ATMEL_SSC_TF)
  599. at91_set_A_periph(AT91_PIN_PC0, 1);
  600. if (pins & ATMEL_SSC_TK)
  601. at91_set_A_periph(AT91_PIN_PC1, 1);
  602. if (pins & ATMEL_SSC_TD)
  603. at91_set_A_periph(AT91_PIN_PA15, 1);
  604. if (pins & ATMEL_SSC_RD)
  605. at91_set_A_periph(AT91_PIN_PA16, 1);
  606. if (pins & ATMEL_SSC_RK)
  607. at91_set_B_periph(AT91_PIN_PA10, 1);
  608. if (pins & ATMEL_SSC_RF)
  609. at91_set_B_periph(AT91_PIN_PA22, 1);
  610. }
  611. static u64 ssc1_dmamask = DMA_BIT_MASK(32);
  612. static struct resource ssc1_resources[] = {
  613. [0] = {
  614. .start = AT91SAM9RL_BASE_SSC1,
  615. .end = AT91SAM9RL_BASE_SSC1 + SZ_16K - 1,
  616. .flags = IORESOURCE_MEM,
  617. },
  618. [1] = {
  619. .start = AT91SAM9RL_ID_SSC1,
  620. .end = AT91SAM9RL_ID_SSC1,
  621. .flags = IORESOURCE_IRQ,
  622. },
  623. };
  624. static struct platform_device at91sam9rl_ssc1_device = {
  625. .name = "ssc",
  626. .id = 1,
  627. .dev = {
  628. .dma_mask = &ssc1_dmamask,
  629. .coherent_dma_mask = DMA_BIT_MASK(32),
  630. },
  631. .resource = ssc1_resources,
  632. .num_resources = ARRAY_SIZE(ssc1_resources),
  633. };
  634. static inline void configure_ssc1_pins(unsigned pins)
  635. {
  636. if (pins & ATMEL_SSC_TF)
  637. at91_set_B_periph(AT91_PIN_PA29, 1);
  638. if (pins & ATMEL_SSC_TK)
  639. at91_set_B_periph(AT91_PIN_PA30, 1);
  640. if (pins & ATMEL_SSC_TD)
  641. at91_set_B_periph(AT91_PIN_PA13, 1);
  642. if (pins & ATMEL_SSC_RD)
  643. at91_set_B_periph(AT91_PIN_PA14, 1);
  644. if (pins & ATMEL_SSC_RK)
  645. at91_set_B_periph(AT91_PIN_PA9, 1);
  646. if (pins & ATMEL_SSC_RF)
  647. at91_set_B_periph(AT91_PIN_PA8, 1);
  648. }
  649. /*
  650. * SSC controllers are accessed through library code, instead of any
  651. * kind of all-singing/all-dancing driver. For example one could be
  652. * used by a particular I2S audio codec's driver, while another one
  653. * on the same system might be used by a custom data capture driver.
  654. */
  655. void __init at91_add_device_ssc(unsigned id, unsigned pins)
  656. {
  657. struct platform_device *pdev;
  658. /*
  659. * NOTE: caller is responsible for passing information matching
  660. * "pins" to whatever will be using each particular controller.
  661. */
  662. switch (id) {
  663. case AT91SAM9RL_ID_SSC0:
  664. pdev = &at91sam9rl_ssc0_device;
  665. configure_ssc0_pins(pins);
  666. at91_clock_associate("ssc0_clk", &pdev->dev, "pclk");
  667. break;
  668. case AT91SAM9RL_ID_SSC1:
  669. pdev = &at91sam9rl_ssc1_device;
  670. configure_ssc1_pins(pins);
  671. at91_clock_associate("ssc1_clk", &pdev->dev, "pclk");
  672. break;
  673. default:
  674. return;
  675. }
  676. platform_device_register(pdev);
  677. }
  678. #else
  679. void __init at91_add_device_ssc(unsigned id, unsigned pins) {}
  680. #endif
  681. /* --------------------------------------------------------------------
  682. * UART
  683. * -------------------------------------------------------------------- */
  684. #if defined(CONFIG_SERIAL_ATMEL)
  685. static struct resource dbgu_resources[] = {
  686. [0] = {
  687. .start = AT91_VA_BASE_SYS + AT91_DBGU,
  688. .end = AT91_VA_BASE_SYS + AT91_DBGU + SZ_512 - 1,
  689. .flags = IORESOURCE_MEM,
  690. },
  691. [1] = {
  692. .start = AT91_ID_SYS,
  693. .end = AT91_ID_SYS,
  694. .flags = IORESOURCE_IRQ,
  695. },
  696. };
  697. static struct atmel_uart_data dbgu_data = {
  698. .use_dma_tx = 0,
  699. .use_dma_rx = 0, /* DBGU not capable of receive DMA */
  700. .regs = (void __iomem *)(AT91_VA_BASE_SYS + AT91_DBGU),
  701. };
  702. static u64 dbgu_dmamask = DMA_BIT_MASK(32);
  703. static struct platform_device at91sam9rl_dbgu_device = {
  704. .name = "atmel_usart",
  705. .id = 0,
  706. .dev = {
  707. .dma_mask = &dbgu_dmamask,
  708. .coherent_dma_mask = DMA_BIT_MASK(32),
  709. .platform_data = &dbgu_data,
  710. },
  711. .resource = dbgu_resources,
  712. .num_resources = ARRAY_SIZE(dbgu_resources),
  713. };
  714. static inline void configure_dbgu_pins(void)
  715. {
  716. at91_set_A_periph(AT91_PIN_PA21, 0); /* DRXD */
  717. at91_set_A_periph(AT91_PIN_PA22, 1); /* DTXD */
  718. }
  719. static struct resource uart0_resources[] = {
  720. [0] = {
  721. .start = AT91SAM9RL_BASE_US0,
  722. .end = AT91SAM9RL_BASE_US0 + SZ_16K - 1,
  723. .flags = IORESOURCE_MEM,
  724. },
  725. [1] = {
  726. .start = AT91SAM9RL_ID_US0,
  727. .end = AT91SAM9RL_ID_US0,
  728. .flags = IORESOURCE_IRQ,
  729. },
  730. };
  731. static struct atmel_uart_data uart0_data = {
  732. .use_dma_tx = 1,
  733. .use_dma_rx = 1,
  734. };
  735. static u64 uart0_dmamask = DMA_BIT_MASK(32);
  736. static struct platform_device at91sam9rl_uart0_device = {
  737. .name = "atmel_usart",
  738. .id = 1,
  739. .dev = {
  740. .dma_mask = &uart0_dmamask,
  741. .coherent_dma_mask = DMA_BIT_MASK(32),
  742. .platform_data = &uart0_data,
  743. },
  744. .resource = uart0_resources,
  745. .num_resources = ARRAY_SIZE(uart0_resources),
  746. };
  747. static inline void configure_usart0_pins(unsigned pins)
  748. {
  749. at91_set_A_periph(AT91_PIN_PA6, 1); /* TXD0 */
  750. at91_set_A_periph(AT91_PIN_PA7, 0); /* RXD0 */
  751. if (pins & ATMEL_UART_RTS)
  752. at91_set_A_periph(AT91_PIN_PA9, 0); /* RTS0 */
  753. if (pins & ATMEL_UART_CTS)
  754. at91_set_A_periph(AT91_PIN_PA10, 0); /* CTS0 */
  755. if (pins & ATMEL_UART_DSR)
  756. at91_set_A_periph(AT91_PIN_PD14, 0); /* DSR0 */
  757. if (pins & ATMEL_UART_DTR)
  758. at91_set_A_periph(AT91_PIN_PD15, 0); /* DTR0 */
  759. if (pins & ATMEL_UART_DCD)
  760. at91_set_A_periph(AT91_PIN_PD16, 0); /* DCD0 */
  761. if (pins & ATMEL_UART_RI)
  762. at91_set_A_periph(AT91_PIN_PD17, 0); /* RI0 */
  763. }
  764. static struct resource uart1_resources[] = {
  765. [0] = {
  766. .start = AT91SAM9RL_BASE_US1,
  767. .end = AT91SAM9RL_BASE_US1 + SZ_16K - 1,
  768. .flags = IORESOURCE_MEM,
  769. },
  770. [1] = {
  771. .start = AT91SAM9RL_ID_US1,
  772. .end = AT91SAM9RL_ID_US1,
  773. .flags = IORESOURCE_IRQ,
  774. },
  775. };
  776. static struct atmel_uart_data uart1_data = {
  777. .use_dma_tx = 1,
  778. .use_dma_rx = 1,
  779. };
  780. static u64 uart1_dmamask = DMA_BIT_MASK(32);
  781. static struct platform_device at91sam9rl_uart1_device = {
  782. .name = "atmel_usart",
  783. .id = 2,
  784. .dev = {
  785. .dma_mask = &uart1_dmamask,
  786. .coherent_dma_mask = DMA_BIT_MASK(32),
  787. .platform_data = &uart1_data,
  788. },
  789. .resource = uart1_resources,
  790. .num_resources = ARRAY_SIZE(uart1_resources),
  791. };
  792. static inline void configure_usart1_pins(unsigned pins)
  793. {
  794. at91_set_A_periph(AT91_PIN_PA11, 1); /* TXD1 */
  795. at91_set_A_periph(AT91_PIN_PA12, 0); /* RXD1 */
  796. if (pins & ATMEL_UART_RTS)
  797. at91_set_B_periph(AT91_PIN_PA18, 0); /* RTS1 */
  798. if (pins & ATMEL_UART_CTS)
  799. at91_set_B_periph(AT91_PIN_PA19, 0); /* CTS1 */
  800. }
  801. static struct resource uart2_resources[] = {
  802. [0] = {
  803. .start = AT91SAM9RL_BASE_US2,
  804. .end = AT91SAM9RL_BASE_US2 + SZ_16K - 1,
  805. .flags = IORESOURCE_MEM,
  806. },
  807. [1] = {
  808. .start = AT91SAM9RL_ID_US2,
  809. .end = AT91SAM9RL_ID_US2,
  810. .flags = IORESOURCE_IRQ,
  811. },
  812. };
  813. static struct atmel_uart_data uart2_data = {
  814. .use_dma_tx = 1,
  815. .use_dma_rx = 1,
  816. };
  817. static u64 uart2_dmamask = DMA_BIT_MASK(32);
  818. static struct platform_device at91sam9rl_uart2_device = {
  819. .name = "atmel_usart",
  820. .id = 3,
  821. .dev = {
  822. .dma_mask = &uart2_dmamask,
  823. .coherent_dma_mask = DMA_BIT_MASK(32),
  824. .platform_data = &uart2_data,
  825. },
  826. .resource = uart2_resources,
  827. .num_resources = ARRAY_SIZE(uart2_resources),
  828. };
  829. static inline void configure_usart2_pins(unsigned pins)
  830. {
  831. at91_set_A_periph(AT91_PIN_PA13, 1); /* TXD2 */
  832. at91_set_A_periph(AT91_PIN_PA14, 0); /* RXD2 */
  833. if (pins & ATMEL_UART_RTS)
  834. at91_set_A_periph(AT91_PIN_PA29, 0); /* RTS2 */
  835. if (pins & ATMEL_UART_CTS)
  836. at91_set_A_periph(AT91_PIN_PA30, 0); /* CTS2 */
  837. }
  838. static struct resource uart3_resources[] = {
  839. [0] = {
  840. .start = AT91SAM9RL_BASE_US3,
  841. .end = AT91SAM9RL_BASE_US3 + SZ_16K - 1,
  842. .flags = IORESOURCE_MEM,
  843. },
  844. [1] = {
  845. .start = AT91SAM9RL_ID_US3,
  846. .end = AT91SAM9RL_ID_US3,
  847. .flags = IORESOURCE_IRQ,
  848. },
  849. };
  850. static struct atmel_uart_data uart3_data = {
  851. .use_dma_tx = 1,
  852. .use_dma_rx = 1,
  853. };
  854. static u64 uart3_dmamask = DMA_BIT_MASK(32);
  855. static struct platform_device at91sam9rl_uart3_device = {
  856. .name = "atmel_usart",
  857. .id = 4,
  858. .dev = {
  859. .dma_mask = &uart3_dmamask,
  860. .coherent_dma_mask = DMA_BIT_MASK(32),
  861. .platform_data = &uart3_data,
  862. },
  863. .resource = uart3_resources,
  864. .num_resources = ARRAY_SIZE(uart3_resources),
  865. };
  866. static inline void configure_usart3_pins(unsigned pins)
  867. {
  868. at91_set_A_periph(AT91_PIN_PB0, 1); /* TXD3 */
  869. at91_set_A_periph(AT91_PIN_PB1, 0); /* RXD3 */
  870. if (pins & ATMEL_UART_RTS)
  871. at91_set_B_periph(AT91_PIN_PD4, 0); /* RTS3 */
  872. if (pins & ATMEL_UART_CTS)
  873. at91_set_B_periph(AT91_PIN_PD3, 0); /* CTS3 */
  874. }
  875. static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
  876. struct platform_device *atmel_default_console_device; /* the serial console device */
  877. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
  878. {
  879. struct platform_device *pdev;
  880. switch (id) {
  881. case 0: /* DBGU */
  882. pdev = &at91sam9rl_dbgu_device;
  883. configure_dbgu_pins();
  884. at91_clock_associate("mck", &pdev->dev, "usart");
  885. break;
  886. case AT91SAM9RL_ID_US0:
  887. pdev = &at91sam9rl_uart0_device;
  888. configure_usart0_pins(pins);
  889. at91_clock_associate("usart0_clk", &pdev->dev, "usart");
  890. break;
  891. case AT91SAM9RL_ID_US1:
  892. pdev = &at91sam9rl_uart1_device;
  893. configure_usart1_pins(pins);
  894. at91_clock_associate("usart1_clk", &pdev->dev, "usart");
  895. break;
  896. case AT91SAM9RL_ID_US2:
  897. pdev = &at91sam9rl_uart2_device;
  898. configure_usart2_pins(pins);
  899. at91_clock_associate("usart2_clk", &pdev->dev, "usart");
  900. break;
  901. case AT91SAM9RL_ID_US3:
  902. pdev = &at91sam9rl_uart3_device;
  903. configure_usart3_pins(pins);
  904. at91_clock_associate("usart3_clk", &pdev->dev, "usart");
  905. break;
  906. default:
  907. return;
  908. }
  909. pdev->id = portnr; /* update to mapped ID */
  910. if (portnr < ATMEL_MAX_UART)
  911. at91_uarts[portnr] = pdev;
  912. }
  913. void __init at91_set_serial_console(unsigned portnr)
  914. {
  915. if (portnr < ATMEL_MAX_UART)
  916. atmel_default_console_device = at91_uarts[portnr];
  917. }
  918. void __init at91_add_device_serial(void)
  919. {
  920. int i;
  921. for (i = 0; i < ATMEL_MAX_UART; i++) {
  922. if (at91_uarts[i])
  923. platform_device_register(at91_uarts[i]);
  924. }
  925. if (!atmel_default_console_device)
  926. printk(KERN_INFO "AT91: No default serial console defined.\n");
  927. }
  928. #else
  929. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
  930. void __init at91_set_serial_console(unsigned portnr) {}
  931. void __init at91_add_device_serial(void) {}
  932. #endif
  933. /* -------------------------------------------------------------------- */
  934. /*
  935. * These devices are always present and don't need any board-specific
  936. * setup.
  937. */
  938. static int __init at91_add_standard_devices(void)
  939. {
  940. at91_add_device_rtc();
  941. at91_add_device_rtt();
  942. at91_add_device_watchdog();
  943. at91_add_device_tc();
  944. return 0;
  945. }
  946. arch_initcall(at91_add_standard_devices);