board-sam9261ek.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  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/dm9000.h>
  29. #include <linux/fb.h>
  30. #include <linux/gpio_keys.h>
  31. #include <linux/input.h>
  32. #include <video/atmel_lcdc.h>
  33. #include <asm/hardware.h>
  34. #include <asm/setup.h>
  35. #include <asm/mach-types.h>
  36. #include <asm/irq.h>
  37. #include <asm/mach/arch.h>
  38. #include <asm/mach/map.h>
  39. #include <asm/mach/irq.h>
  40. #include <asm/arch/board.h>
  41. #include <asm/arch/gpio.h>
  42. #include <asm/arch/at91sam926x_mc.h>
  43. #include "generic.h"
  44. /*
  45. * Serial port configuration.
  46. * 0 .. 2 = USART0 .. USART2
  47. * 3 = DBGU
  48. */
  49. static struct at91_uart_config __initdata ek_uart_config = {
  50. .console_tty = 0, /* ttyS0 */
  51. .nr_tty = 1,
  52. .tty_map = { 3, -1, -1, -1 } /* ttyS0, ..., ttyS3 */
  53. };
  54. static void __init ek_map_io(void)
  55. {
  56. /* Initialize processor: 18.432 MHz crystal */
  57. at91sam9261_initialize(18432000);
  58. /* Setup the LEDs */
  59. at91_init_leds(AT91_PIN_PA13, AT91_PIN_PA14);
  60. /* Setup the serial ports and console */
  61. at91_init_serial(&ek_uart_config);
  62. }
  63. static void __init ek_init_irq(void)
  64. {
  65. at91sam9261_init_interrupts(NULL);
  66. }
  67. /*
  68. * DM9000 ethernet device
  69. */
  70. #if defined(CONFIG_DM9000)
  71. static struct resource at91sam9261_dm9000_resource[] = {
  72. [0] = {
  73. .start = AT91_CHIPSELECT_2,
  74. .end = AT91_CHIPSELECT_2 + 3,
  75. .flags = IORESOURCE_MEM
  76. },
  77. [1] = {
  78. .start = AT91_CHIPSELECT_2 + 0x44,
  79. .end = AT91_CHIPSELECT_2 + 0xFF,
  80. .flags = IORESOURCE_MEM
  81. },
  82. [2] = {
  83. .start = AT91_PIN_PC11,
  84. .end = AT91_PIN_PC11,
  85. .flags = IORESOURCE_IRQ
  86. }
  87. };
  88. static struct dm9000_plat_data dm9000_platdata = {
  89. .flags = DM9000_PLATF_16BITONLY,
  90. };
  91. static struct platform_device at91sam9261_dm9000_device = {
  92. .name = "dm9000",
  93. .id = 0,
  94. .num_resources = ARRAY_SIZE(at91sam9261_dm9000_resource),
  95. .resource = at91sam9261_dm9000_resource,
  96. .dev = {
  97. .platform_data = &dm9000_platdata,
  98. }
  99. };
  100. static void __init ek_add_device_dm9000(void)
  101. {
  102. /*
  103. * Configure Chip-Select 2 on SMC for the DM9000.
  104. * Note: These timings were calculated for MASTER_CLOCK = 100000000
  105. * according to the DM9000 timings.
  106. */
  107. 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));
  108. 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));
  109. at91_sys_write(AT91_SMC_CYCLE(2), AT91_SMC_NWECYCLE_(16) | AT91_SMC_NRDCYCLE_(16));
  110. 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));
  111. /* Configure Reset signal as output */
  112. at91_set_gpio_output(AT91_PIN_PC10, 0);
  113. /* Configure Interrupt pin as input, no pull-up */
  114. at91_set_gpio_input(AT91_PIN_PC11, 0);
  115. platform_device_register(&at91sam9261_dm9000_device);
  116. }
  117. #else
  118. static void __init ek_add_device_dm9000(void) {}
  119. #endif /* CONFIG_DM9000 */
  120. /*
  121. * USB Host Port
  122. */
  123. static struct at91_usbh_data __initdata ek_usbh_data = {
  124. .ports = 2,
  125. };
  126. /*
  127. * USB Device Port
  128. */
  129. static struct at91_udc_data __initdata ek_udc_data = {
  130. .vbus_pin = AT91_PIN_PB29,
  131. .pullup_pin = 0, /* pull-up driven by UDC */
  132. };
  133. /*
  134. * MCI (SD/MMC)
  135. */
  136. static struct at91_mmc_data __initdata ek_mmc_data = {
  137. .wire4 = 1,
  138. // .det_pin = ... not connected
  139. // .wp_pin = ... not connected
  140. // .vcc_pin = ... not connected
  141. };
  142. /*
  143. * NAND flash
  144. */
  145. static struct mtd_partition __initdata ek_nand_partition[] = {
  146. {
  147. .name = "Partition 1",
  148. .offset = 0,
  149. .size = 256 * 1024,
  150. },
  151. {
  152. .name = "Partition 2",
  153. .offset = 256 * 1024 ,
  154. .size = MTDPART_SIZ_FULL,
  155. },
  156. };
  157. static struct mtd_partition * __init nand_partitions(int size, int *num_partitions)
  158. {
  159. *num_partitions = ARRAY_SIZE(ek_nand_partition);
  160. return ek_nand_partition;
  161. }
  162. static struct at91_nand_data __initdata ek_nand_data = {
  163. .ale = 22,
  164. .cle = 21,
  165. // .det_pin = ... not connected
  166. .rdy_pin = AT91_PIN_PC15,
  167. .enable_pin = AT91_PIN_PC14,
  168. .partition_info = nand_partitions,
  169. #if defined(CONFIG_MTD_NAND_AT91_BUSWIDTH_16)
  170. .bus_width_16 = 1,
  171. #else
  172. .bus_width_16 = 0,
  173. #endif
  174. };
  175. /*
  176. * ADS7846 Touchscreen
  177. */
  178. #if defined(CONFIG_TOUCHSCREEN_ADS7846) || defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
  179. static int ads7843_pendown_state(void)
  180. {
  181. return !at91_get_gpio_value(AT91_PIN_PC2); /* Touchscreen PENIRQ */
  182. }
  183. static struct ads7846_platform_data ads_info = {
  184. .model = 7843,
  185. .x_min = 150,
  186. .x_max = 3830,
  187. .y_min = 190,
  188. .y_max = 3830,
  189. .vref_delay_usecs = 100,
  190. .x_plate_ohms = 450,
  191. .y_plate_ohms = 250,
  192. .pressure_max = 15000,
  193. .debounce_max = 1,
  194. .debounce_rep = 0,
  195. .debounce_tol = (~0),
  196. .get_pendown_state = ads7843_pendown_state,
  197. };
  198. static void __init ek_add_device_ts(void)
  199. {
  200. at91_set_B_periph(AT91_PIN_PC2, 1); /* External IRQ0, with pullup */
  201. at91_set_gpio_input(AT91_PIN_PA11, 1); /* Touchscreen BUSY signal */
  202. }
  203. #else
  204. static void __init ek_add_device_ts(void) {}
  205. #endif
  206. /*
  207. * SPI devices
  208. */
  209. static struct spi_board_info ek_spi_devices[] = {
  210. { /* DataFlash chip */
  211. .modalias = "mtd_dataflash",
  212. .chip_select = 0,
  213. .max_speed_hz = 15 * 1000 * 1000,
  214. .bus_num = 0,
  215. },
  216. #if defined(CONFIG_TOUCHSCREEN_ADS7846) || defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
  217. {
  218. .modalias = "ads7846",
  219. .chip_select = 2,
  220. .max_speed_hz = 125000 * 26, /* (max sample rate @ 3V) * (cmd + data + overhead) */
  221. .bus_num = 0,
  222. .platform_data = &ads_info,
  223. .irq = AT91SAM9261_ID_IRQ0,
  224. },
  225. #endif
  226. #if defined(CONFIG_MTD_AT91_DATAFLASH_CARD)
  227. { /* DataFlash card - jumper (J12) configurable to CS3 or CS0 */
  228. .modalias = "mtd_dataflash",
  229. .chip_select = 3,
  230. .max_speed_hz = 15 * 1000 * 1000,
  231. .bus_num = 0,
  232. },
  233. #elif defined(CONFIG_SND_AT73C213) || defined(CONFIG_SND_AT73C213_MODULE)
  234. { /* AT73C213 DAC */
  235. .modalias = "at73c213",
  236. .chip_select = 3,
  237. .max_speed_hz = 10 * 1000 * 1000,
  238. .bus_num = 0,
  239. },
  240. #endif
  241. };
  242. /*
  243. * LCD Controller
  244. */
  245. #if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
  246. #if defined(CONFIG_FB_ATMEL_STN)
  247. /* STN */
  248. static struct fb_videomode at91_stn_modes[] = {
  249. {
  250. .name = "SP06Q002 @ 75",
  251. .refresh = 75,
  252. .xres = 320, .yres = 240,
  253. .pixclock = KHZ2PICOS(1440),
  254. .left_margin = 1, .right_margin = 1,
  255. .upper_margin = 0, .lower_margin = 0,
  256. .hsync_len = 1, .vsync_len = 1,
  257. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  258. .vmode = FB_VMODE_NONINTERLACED,
  259. },
  260. };
  261. static struct fb_monspecs at91fb_default_stn_monspecs = {
  262. .manufacturer = "HIT",
  263. .monitor = "SP06Q002",
  264. .modedb = at91_stn_modes,
  265. .modedb_len = ARRAY_SIZE(at91_stn_modes),
  266. .hfmin = 15000,
  267. .hfmax = 64000,
  268. .vfmin = 50,
  269. .vfmax = 150,
  270. };
  271. #define AT91SAM9261_DEFAULT_STN_LCDCON2 (ATMEL_LCDC_MEMOR_LITTLE \
  272. | ATMEL_LCDC_DISTYPE_STNMONO \
  273. | ATMEL_LCDC_CLKMOD_ALWAYSACTIVE \
  274. | ATMEL_LCDC_IFWIDTH_4 \
  275. | ATMEL_LCDC_SCANMOD_SINGLE)
  276. static void at91_lcdc_stn_power_control(int on)
  277. {
  278. /* backlight */
  279. if (on) { /* power up */
  280. at91_set_gpio_value(AT91_PIN_PC14, 0);
  281. at91_set_gpio_value(AT91_PIN_PC15, 0);
  282. } else { /* power down */
  283. at91_set_gpio_value(AT91_PIN_PC14, 1);
  284. at91_set_gpio_value(AT91_PIN_PC15, 1);
  285. }
  286. }
  287. static struct atmel_lcdfb_info __initdata ek_lcdc_data = {
  288. .default_bpp = 1,
  289. .default_dmacon = ATMEL_LCDC_DMAEN,
  290. .default_lcdcon2 = AT91SAM9261_DEFAULT_STN_LCDCON2,
  291. .default_monspecs = &at91fb_default_stn_monspecs,
  292. .atmel_lcdfb_power_control = at91_lcdc_stn_power_control,
  293. .guard_time = 1,
  294. };
  295. #else
  296. /* TFT */
  297. static struct fb_videomode at91_tft_vga_modes[] = {
  298. {
  299. .name = "TX09D50VM1CCA @ 60",
  300. .refresh = 60,
  301. .xres = 240, .yres = 320,
  302. .pixclock = KHZ2PICOS(4965),
  303. .left_margin = 1, .right_margin = 33,
  304. .upper_margin = 1, .lower_margin = 0,
  305. .hsync_len = 5, .vsync_len = 1,
  306. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  307. .vmode = FB_VMODE_NONINTERLACED,
  308. },
  309. };
  310. static struct fb_monspecs at91fb_default_tft_monspecs = {
  311. .manufacturer = "HIT",
  312. .monitor = "TX09D50VM1CCA",
  313. .modedb = at91_tft_vga_modes,
  314. .modedb_len = ARRAY_SIZE(at91_tft_vga_modes),
  315. .hfmin = 15000,
  316. .hfmax = 64000,
  317. .vfmin = 50,
  318. .vfmax = 150,
  319. };
  320. #define AT91SAM9261_DEFAULT_TFT_LCDCON2 (ATMEL_LCDC_MEMOR_LITTLE \
  321. | ATMEL_LCDC_DISTYPE_TFT \
  322. | ATMEL_LCDC_CLKMOD_ALWAYSACTIVE)
  323. static void at91_lcdc_tft_power_control(int on)
  324. {
  325. if (on)
  326. at91_set_gpio_value(AT91_PIN_PA12, 0); /* power up */
  327. else
  328. at91_set_gpio_value(AT91_PIN_PA12, 1); /* power down */
  329. }
  330. static struct atmel_lcdfb_info __initdata ek_lcdc_data = {
  331. .lcdcon_is_backlight = true,
  332. .default_bpp = 16,
  333. .default_dmacon = ATMEL_LCDC_DMAEN,
  334. .default_lcdcon2 = AT91SAM9261_DEFAULT_TFT_LCDCON2,
  335. .default_monspecs = &at91fb_default_tft_monspecs,
  336. .atmel_lcdfb_power_control = at91_lcdc_tft_power_control,
  337. .guard_time = 1,
  338. };
  339. #endif
  340. #else
  341. static struct atmel_lcdfb_info __initdata ek_lcdc_data;
  342. #endif
  343. /*
  344. * GPIO Buttons
  345. */
  346. #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
  347. static struct gpio_keys_button ek_buttons[] = {
  348. {
  349. .gpio = AT91_PIN_PA27,
  350. .code = BTN_0,
  351. .desc = "Button 0",
  352. .active_low = 1,
  353. },
  354. {
  355. .gpio = AT91_PIN_PA26,
  356. .code = BTN_1,
  357. .desc = "Button 1",
  358. .active_low = 1,
  359. },
  360. {
  361. .gpio = AT91_PIN_PA25,
  362. .code = BTN_2,
  363. .desc = "Button 2",
  364. .active_low = 1,
  365. },
  366. {
  367. .gpio = AT91_PIN_PA24,
  368. .code = BTN_3,
  369. .desc = "Button 3",
  370. .active_low = 1,
  371. }
  372. };
  373. static struct gpio_keys_platform_data ek_button_data = {
  374. .buttons = ek_buttons,
  375. .nbuttons = ARRAY_SIZE(ek_buttons),
  376. };
  377. static struct platform_device ek_button_device = {
  378. .name = "gpio-keys",
  379. .id = -1,
  380. .num_resources = 0,
  381. .dev = {
  382. .platform_data = &ek_button_data,
  383. }
  384. };
  385. static void __init ek_add_device_buttons(void)
  386. {
  387. at91_set_gpio_input(AT91_PIN_PA27, 0); /* btn0 */
  388. at91_set_deglitch(AT91_PIN_PA27, 1);
  389. at91_set_gpio_input(AT91_PIN_PA26, 0); /* btn1 */
  390. at91_set_deglitch(AT91_PIN_PA26, 1);
  391. at91_set_gpio_input(AT91_PIN_PA25, 0); /* btn2 */
  392. at91_set_deglitch(AT91_PIN_PA25, 1);
  393. at91_set_gpio_input(AT91_PIN_PA24, 0); /* btn3 */
  394. at91_set_deglitch(AT91_PIN_PA24, 1);
  395. platform_device_register(&ek_button_device);
  396. }
  397. #else
  398. static void __init ek_add_device_buttons(void) {}
  399. #endif
  400. static void __init ek_board_init(void)
  401. {
  402. /* Serial */
  403. at91_add_device_serial();
  404. /* USB Host */
  405. at91_add_device_usbh(&ek_usbh_data);
  406. /* USB Device */
  407. at91_add_device_udc(&ek_udc_data);
  408. /* I2C */
  409. at91_add_device_i2c(NULL, 0);
  410. /* NAND */
  411. at91_add_device_nand(&ek_nand_data);
  412. /* DM9000 ethernet */
  413. ek_add_device_dm9000();
  414. /* spi0 and mmc/sd share the same PIO pins */
  415. #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
  416. /* SPI */
  417. at91_add_device_spi(ek_spi_devices, ARRAY_SIZE(ek_spi_devices));
  418. /* Touchscreen */
  419. ek_add_device_ts();
  420. #else
  421. /* MMC */
  422. at91_add_device_mmc(0, &ek_mmc_data);
  423. #endif
  424. /* LCD Controller */
  425. at91_add_device_lcdc(&ek_lcdc_data);
  426. /* Push Buttons */
  427. ek_add_device_buttons();
  428. }
  429. MACHINE_START(AT91SAM9261EK, "Atmel AT91SAM9261-EK")
  430. /* Maintainer: Atmel */
  431. .phys_io = AT91_BASE_SYS,
  432. .io_pg_offst = (AT91_VA_BASE_SYS >> 18) & 0xfffc,
  433. .boot_params = AT91_SDRAM_BASE + 0x100,
  434. .timer = &at91sam926x_timer,
  435. .map_io = ek_map_io,
  436. .init_irq = ek_init_irq,
  437. .init_machine = ek_board_init,
  438. MACHINE_END