at91sam9261_devices.c 28 KB

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