board-sam9261ek.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. /*
  2. * linux/arch/arm/mach-at91/board-sam9261ek.c
  3. *
  4. * Copyright (C) 2005 SAN People
  5. * Copyright (C) 2006 Atmel
  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. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #include <linux/types.h>
  22. #include <linux/init.h>
  23. #include <linux/mm.h>
  24. #include <linux/module.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/spi/spi.h>
  27. #include <linux/spi/ads7846.h>
  28. #include <linux/spi/at73c213.h>
  29. #include <linux/clk.h>
  30. #include <linux/dm9000.h>
  31. #include <linux/fb.h>
  32. #include <linux/gpio_keys.h>
  33. #include <linux/input.h>
  34. #include <video/atmel_lcdc.h>
  35. #include <asm/setup.h>
  36. #include <asm/mach-types.h>
  37. #include <asm/irq.h>
  38. #include <asm/mach/arch.h>
  39. #include <asm/mach/map.h>
  40. #include <asm/mach/irq.h>
  41. #include <mach/hardware.h>
  42. #include <mach/board.h>
  43. #include <mach/gpio.h>
  44. #include <mach/at91sam9_smc.h>
  45. #include "generic.h"
  46. static void __init ek_map_io(void)
  47. {
  48. /* Initialize processor: 18.432 MHz crystal */
  49. at91sam9261_initialize(18432000);
  50. /* Setup the LEDs */
  51. at91_init_leds(AT91_PIN_PA13, AT91_PIN_PA14);
  52. /* DGBU on ttyS0. (Rx & Tx only) */
  53. at91_register_uart(0, 0, 0);
  54. /* set serial console to ttyS0 (ie, DBGU) */
  55. at91_set_serial_console(0);
  56. }
  57. static void __init ek_init_irq(void)
  58. {
  59. at91sam9261_init_interrupts(NULL);
  60. }
  61. /*
  62. * DM9000 ethernet device
  63. */
  64. #if defined(CONFIG_DM9000)
  65. static struct resource at91sam9261_dm9000_resource[] = {
  66. [0] = {
  67. .start = AT91_CHIPSELECT_2,
  68. .end = AT91_CHIPSELECT_2 + 3,
  69. .flags = IORESOURCE_MEM
  70. },
  71. [1] = {
  72. .start = AT91_CHIPSELECT_2 + 0x44,
  73. .end = AT91_CHIPSELECT_2 + 0xFF,
  74. .flags = IORESOURCE_MEM
  75. },
  76. [2] = {
  77. .start = AT91_PIN_PC11,
  78. .end = AT91_PIN_PC11,
  79. .flags = IORESOURCE_IRQ
  80. }
  81. };
  82. static struct dm9000_plat_data dm9000_platdata = {
  83. .flags = DM9000_PLATF_16BITONLY,
  84. };
  85. static struct platform_device at91sam9261_dm9000_device = {
  86. .name = "dm9000",
  87. .id = 0,
  88. .num_resources = ARRAY_SIZE(at91sam9261_dm9000_resource),
  89. .resource = at91sam9261_dm9000_resource,
  90. .dev = {
  91. .platform_data = &dm9000_platdata,
  92. }
  93. };
  94. static void __init ek_add_device_dm9000(void)
  95. {
  96. /*
  97. * Configure Chip-Select 2 on SMC for the DM9000.
  98. * Note: These timings were calculated for MASTER_CLOCK = 100000000
  99. * according to the DM9000 timings.
  100. */
  101. at91_sys_write(AT91_SMC_SETUP(2), AT91_SMC_NWESETUP_(2) | AT91_SMC_NCS_WRSETUP_(0) | AT91_SMC_NRDSETUP_(2) | AT91_SMC_NCS_RDSETUP_(0));
  102. at91_sys_write(AT91_SMC_PULSE(2), AT91_SMC_NWEPULSE_(4) | AT91_SMC_NCS_WRPULSE_(8) | AT91_SMC_NRDPULSE_(4) | AT91_SMC_NCS_RDPULSE_(8));
  103. at91_sys_write(AT91_SMC_CYCLE(2), AT91_SMC_NWECYCLE_(16) | AT91_SMC_NRDCYCLE_(16));
  104. at91_sys_write(AT91_SMC_MODE(2), AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_BAT_WRITE | AT91_SMC_DBW_16 | AT91_SMC_TDF_(1));
  105. /* Configure Reset signal as output */
  106. at91_set_gpio_output(AT91_PIN_PC10, 0);
  107. /* Configure Interrupt pin as input, no pull-up */
  108. at91_set_gpio_input(AT91_PIN_PC11, 0);
  109. platform_device_register(&at91sam9261_dm9000_device);
  110. }
  111. #else
  112. static void __init ek_add_device_dm9000(void) {}
  113. #endif /* CONFIG_DM9000 */
  114. /*
  115. * USB Host Port
  116. */
  117. static struct at91_usbh_data __initdata ek_usbh_data = {
  118. .ports = 2,
  119. };
  120. /*
  121. * USB Device Port
  122. */
  123. static struct at91_udc_data __initdata ek_udc_data = {
  124. .vbus_pin = AT91_PIN_PB29,
  125. .pullup_pin = 0, /* pull-up driven by UDC */
  126. };
  127. /*
  128. * MCI (SD/MMC)
  129. */
  130. static struct at91_mmc_data __initdata ek_mmc_data = {
  131. .wire4 = 1,
  132. // .det_pin = ... not connected
  133. // .wp_pin = ... not connected
  134. // .vcc_pin = ... not connected
  135. };
  136. /*
  137. * NAND flash
  138. */
  139. static struct mtd_partition __initdata ek_nand_partition[] = {
  140. {
  141. .name = "Partition 1",
  142. .offset = 0,
  143. .size = SZ_256K,
  144. },
  145. {
  146. .name = "Partition 2",
  147. .offset = MTDPART_OFS_NXTBLK,
  148. .size = MTDPART_SIZ_FULL,
  149. },
  150. };
  151. static struct mtd_partition * __init nand_partitions(int size, int *num_partitions)
  152. {
  153. *num_partitions = ARRAY_SIZE(ek_nand_partition);
  154. return ek_nand_partition;
  155. }
  156. static struct atmel_nand_data __initdata ek_nand_data = {
  157. .ale = 22,
  158. .cle = 21,
  159. // .det_pin = ... not connected
  160. .rdy_pin = AT91_PIN_PC15,
  161. .enable_pin = AT91_PIN_PC14,
  162. .partition_info = nand_partitions,
  163. #if defined(CONFIG_MTD_NAND_ATMEL_BUSWIDTH_16)
  164. .bus_width_16 = 1,
  165. #else
  166. .bus_width_16 = 0,
  167. #endif
  168. };
  169. /*
  170. * ADS7846 Touchscreen
  171. */
  172. #if defined(CONFIG_TOUCHSCREEN_ADS7846) || defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
  173. static int ads7843_pendown_state(void)
  174. {
  175. return !at91_get_gpio_value(AT91_PIN_PC2); /* Touchscreen PENIRQ */
  176. }
  177. static struct ads7846_platform_data ads_info = {
  178. .model = 7843,
  179. .x_min = 150,
  180. .x_max = 3830,
  181. .y_min = 190,
  182. .y_max = 3830,
  183. .vref_delay_usecs = 100,
  184. .x_plate_ohms = 450,
  185. .y_plate_ohms = 250,
  186. .pressure_max = 15000,
  187. .debounce_max = 1,
  188. .debounce_rep = 0,
  189. .debounce_tol = (~0),
  190. .get_pendown_state = ads7843_pendown_state,
  191. };
  192. static void __init ek_add_device_ts(void)
  193. {
  194. at91_set_B_periph(AT91_PIN_PC2, 1); /* External IRQ0, with pullup */
  195. at91_set_gpio_input(AT91_PIN_PA11, 1); /* Touchscreen BUSY signal */
  196. }
  197. #else
  198. static void __init ek_add_device_ts(void) {}
  199. #endif
  200. /*
  201. * Audio
  202. */
  203. static struct at73c213_board_info at73c213_data = {
  204. .ssc_id = 1,
  205. .shortname = "AT91SAM9261-EK external DAC",
  206. };
  207. #if defined(CONFIG_SND_AT73C213) || defined(CONFIG_SND_AT73C213_MODULE)
  208. static void __init at73c213_set_clk(struct at73c213_board_info *info)
  209. {
  210. struct clk *pck2;
  211. struct clk *plla;
  212. pck2 = clk_get(NULL, "pck2");
  213. plla = clk_get(NULL, "plla");
  214. /* AT73C213 MCK Clock */
  215. at91_set_B_periph(AT91_PIN_PB31, 0); /* PCK2 */
  216. clk_set_parent(pck2, plla);
  217. clk_put(plla);
  218. info->dac_clk = pck2;
  219. }
  220. #else
  221. static void __init at73c213_set_clk(struct at73c213_board_info *info) {}
  222. #endif
  223. /*
  224. * SPI devices
  225. */
  226. static struct spi_board_info ek_spi_devices[] = {
  227. { /* DataFlash chip */
  228. .modalias = "mtd_dataflash",
  229. .chip_select = 0,
  230. .max_speed_hz = 15 * 1000 * 1000,
  231. .bus_num = 0,
  232. },
  233. #if defined(CONFIG_TOUCHSCREEN_ADS7846) || defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
  234. {
  235. .modalias = "ads7846",
  236. .chip_select = 2,
  237. .max_speed_hz = 125000 * 26, /* (max sample rate @ 3V) * (cmd + data + overhead) */
  238. .bus_num = 0,
  239. .platform_data = &ads_info,
  240. .irq = AT91SAM9261_ID_IRQ0,
  241. .controller_data = (void *) AT91_PIN_PA28, /* CS pin */
  242. },
  243. #endif
  244. #if defined(CONFIG_MTD_AT91_DATAFLASH_CARD)
  245. { /* DataFlash card - jumper (J12) configurable to CS3 or CS0 */
  246. .modalias = "mtd_dataflash",
  247. .chip_select = 3,
  248. .max_speed_hz = 15 * 1000 * 1000,
  249. .bus_num = 0,
  250. },
  251. #elif defined(CONFIG_SND_AT73C213) || defined(CONFIG_SND_AT73C213_MODULE)
  252. { /* AT73C213 DAC */
  253. .modalias = "at73c213",
  254. .chip_select = 3,
  255. .max_speed_hz = 10 * 1000 * 1000,
  256. .bus_num = 0,
  257. .mode = SPI_MODE_1,
  258. .platform_data = &at73c213_data,
  259. .controller_data = (void*) AT91_PIN_PA29, /* default for CS3 is PA6, but it must be PA29 */
  260. },
  261. #endif
  262. };
  263. /*
  264. * LCD Controller
  265. */
  266. #if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
  267. #if defined(CONFIG_FB_ATMEL_STN)
  268. /* STN */
  269. static struct fb_videomode at91_stn_modes[] = {
  270. {
  271. .name = "SP06Q002 @ 75",
  272. .refresh = 75,
  273. .xres = 320, .yres = 240,
  274. .pixclock = KHZ2PICOS(1440),
  275. .left_margin = 1, .right_margin = 1,
  276. .upper_margin = 0, .lower_margin = 0,
  277. .hsync_len = 1, .vsync_len = 1,
  278. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  279. .vmode = FB_VMODE_NONINTERLACED,
  280. },
  281. };
  282. static struct fb_monspecs at91fb_default_stn_monspecs = {
  283. .manufacturer = "HIT",
  284. .monitor = "SP06Q002",
  285. .modedb = at91_stn_modes,
  286. .modedb_len = ARRAY_SIZE(at91_stn_modes),
  287. .hfmin = 15000,
  288. .hfmax = 64000,
  289. .vfmin = 50,
  290. .vfmax = 150,
  291. };
  292. #define AT91SAM9261_DEFAULT_STN_LCDCON2 (ATMEL_LCDC_MEMOR_LITTLE \
  293. | ATMEL_LCDC_DISTYPE_STNMONO \
  294. | ATMEL_LCDC_CLKMOD_ALWAYSACTIVE \
  295. | ATMEL_LCDC_IFWIDTH_4 \
  296. | ATMEL_LCDC_SCANMOD_SINGLE)
  297. static void at91_lcdc_stn_power_control(int on)
  298. {
  299. /* backlight */
  300. if (on) { /* power up */
  301. at91_set_gpio_value(AT91_PIN_PC14, 0);
  302. at91_set_gpio_value(AT91_PIN_PC15, 0);
  303. } else { /* power down */
  304. at91_set_gpio_value(AT91_PIN_PC14, 1);
  305. at91_set_gpio_value(AT91_PIN_PC15, 1);
  306. }
  307. }
  308. static struct atmel_lcdfb_info __initdata ek_lcdc_data = {
  309. .default_bpp = 1,
  310. .default_dmacon = ATMEL_LCDC_DMAEN,
  311. .default_lcdcon2 = AT91SAM9261_DEFAULT_STN_LCDCON2,
  312. .default_monspecs = &at91fb_default_stn_monspecs,
  313. .atmel_lcdfb_power_control = at91_lcdc_stn_power_control,
  314. .guard_time = 1,
  315. };
  316. #else
  317. /* TFT */
  318. static struct fb_videomode at91_tft_vga_modes[] = {
  319. {
  320. .name = "TX09D50VM1CCA @ 60",
  321. .refresh = 60,
  322. .xres = 240, .yres = 320,
  323. .pixclock = KHZ2PICOS(4965),
  324. .left_margin = 1, .right_margin = 33,
  325. .upper_margin = 1, .lower_margin = 0,
  326. .hsync_len = 5, .vsync_len = 1,
  327. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  328. .vmode = FB_VMODE_NONINTERLACED,
  329. },
  330. };
  331. static struct fb_monspecs at91fb_default_tft_monspecs = {
  332. .manufacturer = "HIT",
  333. .monitor = "TX09D50VM1CCA",
  334. .modedb = at91_tft_vga_modes,
  335. .modedb_len = ARRAY_SIZE(at91_tft_vga_modes),
  336. .hfmin = 15000,
  337. .hfmax = 64000,
  338. .vfmin = 50,
  339. .vfmax = 150,
  340. };
  341. #define AT91SAM9261_DEFAULT_TFT_LCDCON2 (ATMEL_LCDC_MEMOR_LITTLE \
  342. | ATMEL_LCDC_DISTYPE_TFT \
  343. | ATMEL_LCDC_CLKMOD_ALWAYSACTIVE)
  344. static void at91_lcdc_tft_power_control(int on)
  345. {
  346. if (on)
  347. at91_set_gpio_value(AT91_PIN_PA12, 0); /* power up */
  348. else
  349. at91_set_gpio_value(AT91_PIN_PA12, 1); /* power down */
  350. }
  351. static struct atmel_lcdfb_info __initdata ek_lcdc_data = {
  352. .lcdcon_is_backlight = true,
  353. .default_bpp = 16,
  354. .default_dmacon = ATMEL_LCDC_DMAEN,
  355. .default_lcdcon2 = AT91SAM9261_DEFAULT_TFT_LCDCON2,
  356. .default_monspecs = &at91fb_default_tft_monspecs,
  357. .atmel_lcdfb_power_control = at91_lcdc_tft_power_control,
  358. .guard_time = 1,
  359. };
  360. #endif
  361. #else
  362. static struct atmel_lcdfb_info __initdata ek_lcdc_data;
  363. #endif
  364. /*
  365. * GPIO Buttons
  366. */
  367. #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
  368. static struct gpio_keys_button ek_buttons[] = {
  369. {
  370. .gpio = AT91_PIN_PA27,
  371. .code = BTN_0,
  372. .desc = "Button 0",
  373. .active_low = 1,
  374. .wakeup = 1,
  375. },
  376. {
  377. .gpio = AT91_PIN_PA26,
  378. .code = BTN_1,
  379. .desc = "Button 1",
  380. .active_low = 1,
  381. .wakeup = 1,
  382. },
  383. {
  384. .gpio = AT91_PIN_PA25,
  385. .code = BTN_2,
  386. .desc = "Button 2",
  387. .active_low = 1,
  388. .wakeup = 1,
  389. },
  390. {
  391. .gpio = AT91_PIN_PA24,
  392. .code = BTN_3,
  393. .desc = "Button 3",
  394. .active_low = 1,
  395. .wakeup = 1,
  396. }
  397. };
  398. static struct gpio_keys_platform_data ek_button_data = {
  399. .buttons = ek_buttons,
  400. .nbuttons = ARRAY_SIZE(ek_buttons),
  401. };
  402. static struct platform_device ek_button_device = {
  403. .name = "gpio-keys",
  404. .id = -1,
  405. .num_resources = 0,
  406. .dev = {
  407. .platform_data = &ek_button_data,
  408. }
  409. };
  410. static void __init ek_add_device_buttons(void)
  411. {
  412. at91_set_gpio_input(AT91_PIN_PA27, 1); /* btn0 */
  413. at91_set_deglitch(AT91_PIN_PA27, 1);
  414. at91_set_gpio_input(AT91_PIN_PA26, 1); /* btn1 */
  415. at91_set_deglitch(AT91_PIN_PA26, 1);
  416. at91_set_gpio_input(AT91_PIN_PA25, 1); /* btn2 */
  417. at91_set_deglitch(AT91_PIN_PA25, 1);
  418. at91_set_gpio_input(AT91_PIN_PA24, 1); /* btn3 */
  419. at91_set_deglitch(AT91_PIN_PA24, 1);
  420. platform_device_register(&ek_button_device);
  421. }
  422. #else
  423. static void __init ek_add_device_buttons(void) {}
  424. #endif
  425. /*
  426. * LEDs
  427. */
  428. static struct gpio_led ek_leds[] = {
  429. { /* "bottom" led, green, userled1 to be defined */
  430. .name = "ds7",
  431. .gpio = AT91_PIN_PA14,
  432. .active_low = 1,
  433. .default_trigger = "none",
  434. },
  435. { /* "top" led, green, userled2 to be defined */
  436. .name = "ds8",
  437. .gpio = AT91_PIN_PA13,
  438. .active_low = 1,
  439. .default_trigger = "none",
  440. },
  441. { /* "power" led, yellow */
  442. .name = "ds1",
  443. .gpio = AT91_PIN_PA23,
  444. .default_trigger = "heartbeat",
  445. }
  446. };
  447. static void __init ek_board_init(void)
  448. {
  449. /* Serial */
  450. at91_add_device_serial();
  451. /* USB Host */
  452. at91_add_device_usbh(&ek_usbh_data);
  453. /* USB Device */
  454. at91_add_device_udc(&ek_udc_data);
  455. /* I2C */
  456. at91_add_device_i2c(NULL, 0);
  457. /* NAND */
  458. at91_add_device_nand(&ek_nand_data);
  459. /* DM9000 ethernet */
  460. ek_add_device_dm9000();
  461. /* spi0 and mmc/sd share the same PIO pins */
  462. #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
  463. /* SPI */
  464. at91_add_device_spi(ek_spi_devices, ARRAY_SIZE(ek_spi_devices));
  465. /* Touchscreen */
  466. ek_add_device_ts();
  467. /* SSC (to AT73C213) */
  468. at73c213_set_clk(&at73c213_data);
  469. at91_add_device_ssc(AT91SAM9261_ID_SSC1, ATMEL_SSC_TX);
  470. #else
  471. /* MMC */
  472. at91_add_device_mmc(0, &ek_mmc_data);
  473. #endif
  474. /* LCD Controller */
  475. at91_add_device_lcdc(&ek_lcdc_data);
  476. /* Push Buttons */
  477. ek_add_device_buttons();
  478. /* LEDs */
  479. at91_gpio_leds(ek_leds, ARRAY_SIZE(ek_leds));
  480. }
  481. MACHINE_START(AT91SAM9261EK, "Atmel AT91SAM9261-EK")
  482. /* Maintainer: Atmel */
  483. .phys_io = AT91_BASE_SYS,
  484. .io_pg_offst = (AT91_VA_BASE_SYS >> 18) & 0xfffc,
  485. .boot_params = AT91_SDRAM_BASE + 0x100,
  486. .timer = &at91sam926x_timer,
  487. .map_io = ek_map_io,
  488. .init_irq = ek_init_irq,
  489. .init_machine = ek_board_init,
  490. MACHINE_END