at91sam9rl_devices.c 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079
  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. * RTC
  439. * -------------------------------------------------------------------- */
  440. #if defined(CONFIG_RTC_DRV_AT91RM9200) || defined(CONFIG_RTC_DRV_AT91RM9200_MODULE)
  441. static struct platform_device at91sam9rl_rtc_device = {
  442. .name = "at91_rtc",
  443. .id = -1,
  444. .num_resources = 0,
  445. };
  446. static void __init at91_add_device_rtc(void)
  447. {
  448. platform_device_register(&at91sam9rl_rtc_device);
  449. }
  450. #else
  451. static void __init at91_add_device_rtc(void) {}
  452. #endif
  453. /* --------------------------------------------------------------------
  454. * RTT
  455. * -------------------------------------------------------------------- */
  456. static struct resource rtt_resources[] = {
  457. {
  458. .start = AT91_BASE_SYS + AT91_RTT,
  459. .end = AT91_BASE_SYS + AT91_RTT + SZ_16 - 1,
  460. .flags = IORESOURCE_MEM,
  461. }
  462. };
  463. static struct platform_device at91sam9rl_rtt_device = {
  464. .name = "at91_rtt",
  465. .id = 0,
  466. .resource = rtt_resources,
  467. .num_resources = ARRAY_SIZE(rtt_resources),
  468. };
  469. static void __init at91_add_device_rtt(void)
  470. {
  471. platform_device_register(&at91sam9rl_rtt_device);
  472. }
  473. /* --------------------------------------------------------------------
  474. * Watchdog
  475. * -------------------------------------------------------------------- */
  476. #if defined(CONFIG_AT91SAM9_WATCHDOG) || defined(CONFIG_AT91SAM9_WATCHDOG_MODULE)
  477. static struct platform_device at91sam9rl_wdt_device = {
  478. .name = "at91_wdt",
  479. .id = -1,
  480. .num_resources = 0,
  481. };
  482. static void __init at91_add_device_watchdog(void)
  483. {
  484. platform_device_register(&at91sam9rl_wdt_device);
  485. }
  486. #else
  487. static void __init at91_add_device_watchdog(void) {}
  488. #endif
  489. /* --------------------------------------------------------------------
  490. * PWM
  491. * --------------------------------------------------------------------*/
  492. #if defined(CONFIG_ATMEL_PWM)
  493. static u32 pwm_mask;
  494. static struct resource pwm_resources[] = {
  495. [0] = {
  496. .start = AT91SAM9RL_BASE_PWMC,
  497. .end = AT91SAM9RL_BASE_PWMC + SZ_16K - 1,
  498. .flags = IORESOURCE_MEM,
  499. },
  500. [1] = {
  501. .start = AT91SAM9RL_ID_PWMC,
  502. .end = AT91SAM9RL_ID_PWMC,
  503. .flags = IORESOURCE_IRQ,
  504. },
  505. };
  506. static struct platform_device at91sam9rl_pwm0_device = {
  507. .name = "atmel_pwm",
  508. .id = -1,
  509. .dev = {
  510. .platform_data = &pwm_mask,
  511. },
  512. .resource = pwm_resources,
  513. .num_resources = ARRAY_SIZE(pwm_resources),
  514. };
  515. void __init at91_add_device_pwm(u32 mask)
  516. {
  517. if (mask & (1 << AT91_PWM0))
  518. at91_set_B_periph(AT91_PIN_PB8, 1); /* enable PWM0 */
  519. if (mask & (1 << AT91_PWM1))
  520. at91_set_B_periph(AT91_PIN_PB9, 1); /* enable PWM1 */
  521. if (mask & (1 << AT91_PWM2))
  522. at91_set_B_periph(AT91_PIN_PD5, 1); /* enable PWM2 */
  523. if (mask & (1 << AT91_PWM3))
  524. at91_set_B_periph(AT91_PIN_PD8, 1); /* enable PWM3 */
  525. pwm_mask = mask;
  526. platform_device_register(&at91sam9rl_pwm0_device);
  527. }
  528. #else
  529. void __init at91_add_device_pwm(u32 mask) {}
  530. #endif
  531. /* --------------------------------------------------------------------
  532. * SSC -- Synchronous Serial Controller
  533. * -------------------------------------------------------------------- */
  534. #if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
  535. static u64 ssc0_dmamask = DMA_BIT_MASK(32);
  536. static struct resource ssc0_resources[] = {
  537. [0] = {
  538. .start = AT91SAM9RL_BASE_SSC0,
  539. .end = AT91SAM9RL_BASE_SSC0 + SZ_16K - 1,
  540. .flags = IORESOURCE_MEM,
  541. },
  542. [1] = {
  543. .start = AT91SAM9RL_ID_SSC0,
  544. .end = AT91SAM9RL_ID_SSC0,
  545. .flags = IORESOURCE_IRQ,
  546. },
  547. };
  548. static struct platform_device at91sam9rl_ssc0_device = {
  549. .name = "ssc",
  550. .id = 0,
  551. .dev = {
  552. .dma_mask = &ssc0_dmamask,
  553. .coherent_dma_mask = DMA_BIT_MASK(32),
  554. },
  555. .resource = ssc0_resources,
  556. .num_resources = ARRAY_SIZE(ssc0_resources),
  557. };
  558. static inline void configure_ssc0_pins(unsigned pins)
  559. {
  560. if (pins & ATMEL_SSC_TF)
  561. at91_set_A_periph(AT91_PIN_PC0, 1);
  562. if (pins & ATMEL_SSC_TK)
  563. at91_set_A_periph(AT91_PIN_PC1, 1);
  564. if (pins & ATMEL_SSC_TD)
  565. at91_set_A_periph(AT91_PIN_PA15, 1);
  566. if (pins & ATMEL_SSC_RD)
  567. at91_set_A_periph(AT91_PIN_PA16, 1);
  568. if (pins & ATMEL_SSC_RK)
  569. at91_set_B_periph(AT91_PIN_PA10, 1);
  570. if (pins & ATMEL_SSC_RF)
  571. at91_set_B_periph(AT91_PIN_PA22, 1);
  572. }
  573. static u64 ssc1_dmamask = DMA_BIT_MASK(32);
  574. static struct resource ssc1_resources[] = {
  575. [0] = {
  576. .start = AT91SAM9RL_BASE_SSC1,
  577. .end = AT91SAM9RL_BASE_SSC1 + SZ_16K - 1,
  578. .flags = IORESOURCE_MEM,
  579. },
  580. [1] = {
  581. .start = AT91SAM9RL_ID_SSC1,
  582. .end = AT91SAM9RL_ID_SSC1,
  583. .flags = IORESOURCE_IRQ,
  584. },
  585. };
  586. static struct platform_device at91sam9rl_ssc1_device = {
  587. .name = "ssc",
  588. .id = 1,
  589. .dev = {
  590. .dma_mask = &ssc1_dmamask,
  591. .coherent_dma_mask = DMA_BIT_MASK(32),
  592. },
  593. .resource = ssc1_resources,
  594. .num_resources = ARRAY_SIZE(ssc1_resources),
  595. };
  596. static inline void configure_ssc1_pins(unsigned pins)
  597. {
  598. if (pins & ATMEL_SSC_TF)
  599. at91_set_B_periph(AT91_PIN_PA29, 1);
  600. if (pins & ATMEL_SSC_TK)
  601. at91_set_B_periph(AT91_PIN_PA30, 1);
  602. if (pins & ATMEL_SSC_TD)
  603. at91_set_B_periph(AT91_PIN_PA13, 1);
  604. if (pins & ATMEL_SSC_RD)
  605. at91_set_B_periph(AT91_PIN_PA14, 1);
  606. if (pins & ATMEL_SSC_RK)
  607. at91_set_B_periph(AT91_PIN_PA9, 1);
  608. if (pins & ATMEL_SSC_RF)
  609. at91_set_B_periph(AT91_PIN_PA8, 1);
  610. }
  611. /*
  612. * SSC controllers are accessed through library code, instead of any
  613. * kind of all-singing/all-dancing driver. For example one could be
  614. * used by a particular I2S audio codec's driver, while another one
  615. * on the same system might be used by a custom data capture driver.
  616. */
  617. void __init at91_add_device_ssc(unsigned id, unsigned pins)
  618. {
  619. struct platform_device *pdev;
  620. /*
  621. * NOTE: caller is responsible for passing information matching
  622. * "pins" to whatever will be using each particular controller.
  623. */
  624. switch (id) {
  625. case AT91SAM9RL_ID_SSC0:
  626. pdev = &at91sam9rl_ssc0_device;
  627. configure_ssc0_pins(pins);
  628. at91_clock_associate("ssc0_clk", &pdev->dev, "pclk");
  629. break;
  630. case AT91SAM9RL_ID_SSC1:
  631. pdev = &at91sam9rl_ssc1_device;
  632. configure_ssc1_pins(pins);
  633. at91_clock_associate("ssc1_clk", &pdev->dev, "pclk");
  634. break;
  635. default:
  636. return;
  637. }
  638. platform_device_register(pdev);
  639. }
  640. #else
  641. void __init at91_add_device_ssc(unsigned id, unsigned pins) {}
  642. #endif
  643. /* --------------------------------------------------------------------
  644. * UART
  645. * -------------------------------------------------------------------- */
  646. #if defined(CONFIG_SERIAL_ATMEL)
  647. static struct resource dbgu_resources[] = {
  648. [0] = {
  649. .start = AT91_VA_BASE_SYS + AT91_DBGU,
  650. .end = AT91_VA_BASE_SYS + AT91_DBGU + SZ_512 - 1,
  651. .flags = IORESOURCE_MEM,
  652. },
  653. [1] = {
  654. .start = AT91_ID_SYS,
  655. .end = AT91_ID_SYS,
  656. .flags = IORESOURCE_IRQ,
  657. },
  658. };
  659. static struct atmel_uart_data dbgu_data = {
  660. .use_dma_tx = 0,
  661. .use_dma_rx = 0, /* DBGU not capable of receive DMA */
  662. .regs = (void __iomem *)(AT91_VA_BASE_SYS + AT91_DBGU),
  663. };
  664. static u64 dbgu_dmamask = DMA_BIT_MASK(32);
  665. static struct platform_device at91sam9rl_dbgu_device = {
  666. .name = "atmel_usart",
  667. .id = 0,
  668. .dev = {
  669. .dma_mask = &dbgu_dmamask,
  670. .coherent_dma_mask = DMA_BIT_MASK(32),
  671. .platform_data = &dbgu_data,
  672. },
  673. .resource = dbgu_resources,
  674. .num_resources = ARRAY_SIZE(dbgu_resources),
  675. };
  676. static inline void configure_dbgu_pins(void)
  677. {
  678. at91_set_A_periph(AT91_PIN_PA21, 0); /* DRXD */
  679. at91_set_A_periph(AT91_PIN_PA22, 1); /* DTXD */
  680. }
  681. static struct resource uart0_resources[] = {
  682. [0] = {
  683. .start = AT91SAM9RL_BASE_US0,
  684. .end = AT91SAM9RL_BASE_US0 + SZ_16K - 1,
  685. .flags = IORESOURCE_MEM,
  686. },
  687. [1] = {
  688. .start = AT91SAM9RL_ID_US0,
  689. .end = AT91SAM9RL_ID_US0,
  690. .flags = IORESOURCE_IRQ,
  691. },
  692. };
  693. static struct atmel_uart_data uart0_data = {
  694. .use_dma_tx = 1,
  695. .use_dma_rx = 1,
  696. };
  697. static u64 uart0_dmamask = DMA_BIT_MASK(32);
  698. static struct platform_device at91sam9rl_uart0_device = {
  699. .name = "atmel_usart",
  700. .id = 1,
  701. .dev = {
  702. .dma_mask = &uart0_dmamask,
  703. .coherent_dma_mask = DMA_BIT_MASK(32),
  704. .platform_data = &uart0_data,
  705. },
  706. .resource = uart0_resources,
  707. .num_resources = ARRAY_SIZE(uart0_resources),
  708. };
  709. static inline void configure_usart0_pins(unsigned pins)
  710. {
  711. at91_set_A_periph(AT91_PIN_PA6, 1); /* TXD0 */
  712. at91_set_A_periph(AT91_PIN_PA7, 0); /* RXD0 */
  713. if (pins & ATMEL_UART_RTS)
  714. at91_set_A_periph(AT91_PIN_PA9, 0); /* RTS0 */
  715. if (pins & ATMEL_UART_CTS)
  716. at91_set_A_periph(AT91_PIN_PA10, 0); /* CTS0 */
  717. if (pins & ATMEL_UART_DSR)
  718. at91_set_A_periph(AT91_PIN_PD14, 0); /* DSR0 */
  719. if (pins & ATMEL_UART_DTR)
  720. at91_set_A_periph(AT91_PIN_PD15, 0); /* DTR0 */
  721. if (pins & ATMEL_UART_DCD)
  722. at91_set_A_periph(AT91_PIN_PD16, 0); /* DCD0 */
  723. if (pins & ATMEL_UART_RI)
  724. at91_set_A_periph(AT91_PIN_PD17, 0); /* RI0 */
  725. }
  726. static struct resource uart1_resources[] = {
  727. [0] = {
  728. .start = AT91SAM9RL_BASE_US1,
  729. .end = AT91SAM9RL_BASE_US1 + SZ_16K - 1,
  730. .flags = IORESOURCE_MEM,
  731. },
  732. [1] = {
  733. .start = AT91SAM9RL_ID_US1,
  734. .end = AT91SAM9RL_ID_US1,
  735. .flags = IORESOURCE_IRQ,
  736. },
  737. };
  738. static struct atmel_uart_data uart1_data = {
  739. .use_dma_tx = 1,
  740. .use_dma_rx = 1,
  741. };
  742. static u64 uart1_dmamask = DMA_BIT_MASK(32);
  743. static struct platform_device at91sam9rl_uart1_device = {
  744. .name = "atmel_usart",
  745. .id = 2,
  746. .dev = {
  747. .dma_mask = &uart1_dmamask,
  748. .coherent_dma_mask = DMA_BIT_MASK(32),
  749. .platform_data = &uart1_data,
  750. },
  751. .resource = uart1_resources,
  752. .num_resources = ARRAY_SIZE(uart1_resources),
  753. };
  754. static inline void configure_usart1_pins(unsigned pins)
  755. {
  756. at91_set_A_periph(AT91_PIN_PA11, 1); /* TXD1 */
  757. at91_set_A_periph(AT91_PIN_PA12, 0); /* RXD1 */
  758. if (pins & ATMEL_UART_RTS)
  759. at91_set_B_periph(AT91_PIN_PA18, 0); /* RTS1 */
  760. if (pins & ATMEL_UART_CTS)
  761. at91_set_B_periph(AT91_PIN_PA19, 0); /* CTS1 */
  762. }
  763. static struct resource uart2_resources[] = {
  764. [0] = {
  765. .start = AT91SAM9RL_BASE_US2,
  766. .end = AT91SAM9RL_BASE_US2 + SZ_16K - 1,
  767. .flags = IORESOURCE_MEM,
  768. },
  769. [1] = {
  770. .start = AT91SAM9RL_ID_US2,
  771. .end = AT91SAM9RL_ID_US2,
  772. .flags = IORESOURCE_IRQ,
  773. },
  774. };
  775. static struct atmel_uart_data uart2_data = {
  776. .use_dma_tx = 1,
  777. .use_dma_rx = 1,
  778. };
  779. static u64 uart2_dmamask = DMA_BIT_MASK(32);
  780. static struct platform_device at91sam9rl_uart2_device = {
  781. .name = "atmel_usart",
  782. .id = 3,
  783. .dev = {
  784. .dma_mask = &uart2_dmamask,
  785. .coherent_dma_mask = DMA_BIT_MASK(32),
  786. .platform_data = &uart2_data,
  787. },
  788. .resource = uart2_resources,
  789. .num_resources = ARRAY_SIZE(uart2_resources),
  790. };
  791. static inline void configure_usart2_pins(unsigned pins)
  792. {
  793. at91_set_A_periph(AT91_PIN_PA13, 1); /* TXD2 */
  794. at91_set_A_periph(AT91_PIN_PA14, 0); /* RXD2 */
  795. if (pins & ATMEL_UART_RTS)
  796. at91_set_A_periph(AT91_PIN_PA29, 0); /* RTS2 */
  797. if (pins & ATMEL_UART_CTS)
  798. at91_set_A_periph(AT91_PIN_PA30, 0); /* CTS2 */
  799. }
  800. static struct resource uart3_resources[] = {
  801. [0] = {
  802. .start = AT91SAM9RL_BASE_US3,
  803. .end = AT91SAM9RL_BASE_US3 + SZ_16K - 1,
  804. .flags = IORESOURCE_MEM,
  805. },
  806. [1] = {
  807. .start = AT91SAM9RL_ID_US3,
  808. .end = AT91SAM9RL_ID_US3,
  809. .flags = IORESOURCE_IRQ,
  810. },
  811. };
  812. static struct atmel_uart_data uart3_data = {
  813. .use_dma_tx = 1,
  814. .use_dma_rx = 1,
  815. };
  816. static u64 uart3_dmamask = DMA_BIT_MASK(32);
  817. static struct platform_device at91sam9rl_uart3_device = {
  818. .name = "atmel_usart",
  819. .id = 4,
  820. .dev = {
  821. .dma_mask = &uart3_dmamask,
  822. .coherent_dma_mask = DMA_BIT_MASK(32),
  823. .platform_data = &uart3_data,
  824. },
  825. .resource = uart3_resources,
  826. .num_resources = ARRAY_SIZE(uart3_resources),
  827. };
  828. static inline void configure_usart3_pins(unsigned pins)
  829. {
  830. at91_set_A_periph(AT91_PIN_PB0, 1); /* TXD3 */
  831. at91_set_A_periph(AT91_PIN_PB1, 0); /* RXD3 */
  832. if (pins & ATMEL_UART_RTS)
  833. at91_set_B_periph(AT91_PIN_PD4, 0); /* RTS3 */
  834. if (pins & ATMEL_UART_CTS)
  835. at91_set_B_periph(AT91_PIN_PD3, 0); /* CTS3 */
  836. }
  837. static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
  838. struct platform_device *atmel_default_console_device; /* the serial console device */
  839. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
  840. {
  841. struct platform_device *pdev;
  842. switch (id) {
  843. case 0: /* DBGU */
  844. pdev = &at91sam9rl_dbgu_device;
  845. configure_dbgu_pins();
  846. at91_clock_associate("mck", &pdev->dev, "usart");
  847. break;
  848. case AT91SAM9RL_ID_US0:
  849. pdev = &at91sam9rl_uart0_device;
  850. configure_usart0_pins(pins);
  851. at91_clock_associate("usart0_clk", &pdev->dev, "usart");
  852. break;
  853. case AT91SAM9RL_ID_US1:
  854. pdev = &at91sam9rl_uart1_device;
  855. configure_usart1_pins(pins);
  856. at91_clock_associate("usart1_clk", &pdev->dev, "usart");
  857. break;
  858. case AT91SAM9RL_ID_US2:
  859. pdev = &at91sam9rl_uart2_device;
  860. configure_usart2_pins(pins);
  861. at91_clock_associate("usart2_clk", &pdev->dev, "usart");
  862. break;
  863. case AT91SAM9RL_ID_US3:
  864. pdev = &at91sam9rl_uart3_device;
  865. configure_usart3_pins(pins);
  866. at91_clock_associate("usart3_clk", &pdev->dev, "usart");
  867. break;
  868. default:
  869. return;
  870. }
  871. pdev->id = portnr; /* update to mapped ID */
  872. if (portnr < ATMEL_MAX_UART)
  873. at91_uarts[portnr] = pdev;
  874. }
  875. void __init at91_set_serial_console(unsigned portnr)
  876. {
  877. if (portnr < ATMEL_MAX_UART)
  878. atmel_default_console_device = at91_uarts[portnr];
  879. }
  880. void __init at91_add_device_serial(void)
  881. {
  882. int i;
  883. for (i = 0; i < ATMEL_MAX_UART; i++) {
  884. if (at91_uarts[i])
  885. platform_device_register(at91_uarts[i]);
  886. }
  887. if (!atmel_default_console_device)
  888. printk(KERN_INFO "AT91: No default serial console defined.\n");
  889. }
  890. #else
  891. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
  892. void __init at91_set_serial_console(unsigned portnr) {}
  893. void __init at91_add_device_serial(void) {}
  894. #endif
  895. /* -------------------------------------------------------------------- */
  896. /*
  897. * These devices are always present and don't need any board-specific
  898. * setup.
  899. */
  900. static int __init at91_add_standard_devices(void)
  901. {
  902. at91_add_device_rtc();
  903. at91_add_device_rtt();
  904. at91_add_device_watchdog();
  905. at91_add_device_tc();
  906. return 0;
  907. }
  908. arch_initcall(at91_add_standard_devices);