board-sam9261ek.c 14 KB

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