cm-x2xx.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. /*
  2. * linux/arch/arm/mach-pxa/cm-x2xx.c
  3. *
  4. * Copyright (C) 2008 CompuLab, Ltd.
  5. * Mike Rapoport <mike@compulab.co.il>
  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 version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/platform_device.h>
  12. #include <linux/syscore_ops.h>
  13. #include <linux/irq.h>
  14. #include <linux/gpio.h>
  15. #include <linux/dm9000.h>
  16. #include <linux/leds.h>
  17. #include <asm/mach/arch.h>
  18. #include <asm/mach-types.h>
  19. #include <asm/mach/map.h>
  20. #include <mach/pxa25x.h>
  21. #undef GPIO24_SSP1_SFRM
  22. #include <mach/pxa27x.h>
  23. #include <mach/audio.h>
  24. #include <linux/platform_data/video-pxafb.h>
  25. #include <mach/smemc.h>
  26. #include <asm/hardware/it8152.h>
  27. #include "generic.h"
  28. #include "cm-x2xx-pci.h"
  29. extern void cmx255_init(void);
  30. extern void cmx270_init(void);
  31. /* reserve IRQs for IT8152 */
  32. #define CMX2XX_NR_IRQS (IRQ_BOARD_START + 40)
  33. /* virtual addresses for statically mapped regions */
  34. #define CMX2XX_VIRT_BASE (void __iomem *)(0xe8000000)
  35. #define CMX2XX_IT8152_VIRT (CMX2XX_VIRT_BASE)
  36. /* physical address if local-bus attached devices */
  37. #define CMX255_DM9000_PHYS_BASE (PXA_CS1_PHYS + (8 << 22))
  38. #define CMX270_DM9000_PHYS_BASE (PXA_CS1_PHYS + (6 << 22))
  39. /* leds */
  40. #define CMX255_GPIO_RED (27)
  41. #define CMX255_GPIO_GREEN (32)
  42. #define CMX270_GPIO_RED (93)
  43. #define CMX270_GPIO_GREEN (94)
  44. /* GPIO IRQ usage */
  45. #define GPIO22_ETHIRQ (22)
  46. #define GPIO10_ETHIRQ (10)
  47. #define CMX255_GPIO_IT8152_IRQ (0)
  48. #define CMX270_GPIO_IT8152_IRQ (22)
  49. #define CMX255_ETHIRQ PXA_GPIO_TO_IRQ(GPIO22_ETHIRQ)
  50. #define CMX270_ETHIRQ PXA_GPIO_TO_IRQ(GPIO10_ETHIRQ)
  51. #if defined(CONFIG_DM9000) || defined(CONFIG_DM9000_MODULE)
  52. static struct resource cmx255_dm9000_resource[] = {
  53. [0] = {
  54. .start = CMX255_DM9000_PHYS_BASE,
  55. .end = CMX255_DM9000_PHYS_BASE + 3,
  56. .flags = IORESOURCE_MEM,
  57. },
  58. [1] = {
  59. .start = CMX255_DM9000_PHYS_BASE + 4,
  60. .end = CMX255_DM9000_PHYS_BASE + 4 + 500,
  61. .flags = IORESOURCE_MEM,
  62. },
  63. [2] = {
  64. .start = CMX255_ETHIRQ,
  65. .end = CMX255_ETHIRQ,
  66. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
  67. }
  68. };
  69. static struct resource cmx270_dm9000_resource[] = {
  70. [0] = {
  71. .start = CMX270_DM9000_PHYS_BASE,
  72. .end = CMX270_DM9000_PHYS_BASE + 3,
  73. .flags = IORESOURCE_MEM,
  74. },
  75. [1] = {
  76. .start = CMX270_DM9000_PHYS_BASE + 8,
  77. .end = CMX270_DM9000_PHYS_BASE + 8 + 500,
  78. .flags = IORESOURCE_MEM,
  79. },
  80. [2] = {
  81. .start = CMX270_ETHIRQ,
  82. .end = CMX270_ETHIRQ,
  83. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
  84. }
  85. };
  86. static struct dm9000_plat_data cmx270_dm9000_platdata = {
  87. .flags = DM9000_PLATF_32BITONLY | DM9000_PLATF_NO_EEPROM,
  88. };
  89. static struct platform_device cmx2xx_dm9000_device = {
  90. .name = "dm9000",
  91. .id = 0,
  92. .num_resources = ARRAY_SIZE(cmx270_dm9000_resource),
  93. .dev = {
  94. .platform_data = &cmx270_dm9000_platdata,
  95. }
  96. };
  97. static void __init cmx2xx_init_dm9000(void)
  98. {
  99. if (cpu_is_pxa25x())
  100. cmx2xx_dm9000_device.resource = cmx255_dm9000_resource;
  101. else
  102. cmx2xx_dm9000_device.resource = cmx270_dm9000_resource;
  103. platform_device_register(&cmx2xx_dm9000_device);
  104. }
  105. #else
  106. static inline void cmx2xx_init_dm9000(void) {}
  107. #endif
  108. /* UCB1400 touchscreen controller */
  109. #if defined(CONFIG_TOUCHSCREEN_UCB1400) || defined(CONFIG_TOUCHSCREEN_UCB1400_MODULE)
  110. static struct platform_device cmx2xx_ts_device = {
  111. .name = "ucb1400_core",
  112. .id = -1,
  113. };
  114. static void __init cmx2xx_init_touchscreen(void)
  115. {
  116. platform_device_register(&cmx2xx_ts_device);
  117. }
  118. #else
  119. static inline void cmx2xx_init_touchscreen(void) {}
  120. #endif
  121. /* CM-X270 LEDs */
  122. #if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
  123. static struct gpio_led cmx2xx_leds[] = {
  124. [0] = {
  125. .name = "cm-x2xx:red",
  126. .default_trigger = "nand-disk",
  127. .active_low = 1,
  128. },
  129. [1] = {
  130. .name = "cm-x2xx:green",
  131. .default_trigger = "heartbeat",
  132. .active_low = 1,
  133. },
  134. };
  135. static struct gpio_led_platform_data cmx2xx_gpio_led_pdata = {
  136. .num_leds = ARRAY_SIZE(cmx2xx_leds),
  137. .leds = cmx2xx_leds,
  138. };
  139. static struct platform_device cmx2xx_led_device = {
  140. .name = "leds-gpio",
  141. .id = -1,
  142. .dev = {
  143. .platform_data = &cmx2xx_gpio_led_pdata,
  144. },
  145. };
  146. static void __init cmx2xx_init_leds(void)
  147. {
  148. if (cpu_is_pxa25x()) {
  149. cmx2xx_leds[0].gpio = CMX255_GPIO_RED;
  150. cmx2xx_leds[1].gpio = CMX255_GPIO_GREEN;
  151. } else {
  152. cmx2xx_leds[0].gpio = CMX270_GPIO_RED;
  153. cmx2xx_leds[1].gpio = CMX270_GPIO_GREEN;
  154. }
  155. platform_device_register(&cmx2xx_led_device);
  156. }
  157. #else
  158. static inline void cmx2xx_init_leds(void) {}
  159. #endif
  160. #if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
  161. /*
  162. Display definitions
  163. keep these for backwards compatibility, although symbolic names (as
  164. e.g. in lpd270.c) looks better
  165. */
  166. #define MTYPE_STN320x240 0
  167. #define MTYPE_TFT640x480 1
  168. #define MTYPE_CRT640x480 2
  169. #define MTYPE_CRT800x600 3
  170. #define MTYPE_TFT320x240 6
  171. #define MTYPE_STN640x480 7
  172. static struct pxafb_mode_info generic_stn_320x240_mode = {
  173. .pixclock = 76923,
  174. .bpp = 8,
  175. .xres = 320,
  176. .yres = 240,
  177. .hsync_len = 3,
  178. .vsync_len = 2,
  179. .left_margin = 3,
  180. .upper_margin = 0,
  181. .right_margin = 3,
  182. .lower_margin = 0,
  183. .sync = (FB_SYNC_HOR_HIGH_ACT |
  184. FB_SYNC_VERT_HIGH_ACT),
  185. .cmap_greyscale = 0,
  186. };
  187. static struct pxafb_mach_info generic_stn_320x240 = {
  188. .modes = &generic_stn_320x240_mode,
  189. .num_modes = 1,
  190. .lcd_conn = LCD_COLOR_STN_8BPP | LCD_PCLK_EDGE_FALL |\
  191. LCD_AC_BIAS_FREQ(0xff),
  192. .cmap_inverse = 0,
  193. .cmap_static = 0,
  194. };
  195. static struct pxafb_mode_info generic_tft_640x480_mode = {
  196. .pixclock = 38461,
  197. .bpp = 8,
  198. .xres = 640,
  199. .yres = 480,
  200. .hsync_len = 60,
  201. .vsync_len = 2,
  202. .left_margin = 70,
  203. .upper_margin = 10,
  204. .right_margin = 70,
  205. .lower_margin = 5,
  206. .sync = 0,
  207. .cmap_greyscale = 0,
  208. };
  209. static struct pxafb_mach_info generic_tft_640x480 = {
  210. .modes = &generic_tft_640x480_mode,
  211. .num_modes = 1,
  212. .lcd_conn = LCD_COLOR_TFT_8BPP | LCD_PCLK_EDGE_FALL |\
  213. LCD_AC_BIAS_FREQ(0xff),
  214. .cmap_inverse = 0,
  215. .cmap_static = 0,
  216. };
  217. static struct pxafb_mode_info generic_crt_640x480_mode = {
  218. .pixclock = 38461,
  219. .bpp = 8,
  220. .xres = 640,
  221. .yres = 480,
  222. .hsync_len = 63,
  223. .vsync_len = 2,
  224. .left_margin = 81,
  225. .upper_margin = 33,
  226. .right_margin = 16,
  227. .lower_margin = 10,
  228. .sync = (FB_SYNC_HOR_HIGH_ACT |
  229. FB_SYNC_VERT_HIGH_ACT),
  230. .cmap_greyscale = 0,
  231. };
  232. static struct pxafb_mach_info generic_crt_640x480 = {
  233. .modes = &generic_crt_640x480_mode,
  234. .num_modes = 1,
  235. .lcd_conn = LCD_COLOR_TFT_8BPP | LCD_AC_BIAS_FREQ(0xff),
  236. .cmap_inverse = 0,
  237. .cmap_static = 0,
  238. };
  239. static struct pxafb_mode_info generic_crt_800x600_mode = {
  240. .pixclock = 28846,
  241. .bpp = 8,
  242. .xres = 800,
  243. .yres = 600,
  244. .hsync_len = 63,
  245. .vsync_len = 2,
  246. .left_margin = 26,
  247. .upper_margin = 21,
  248. .right_margin = 26,
  249. .lower_margin = 11,
  250. .sync = (FB_SYNC_HOR_HIGH_ACT |
  251. FB_SYNC_VERT_HIGH_ACT),
  252. .cmap_greyscale = 0,
  253. };
  254. static struct pxafb_mach_info generic_crt_800x600 = {
  255. .modes = &generic_crt_800x600_mode,
  256. .num_modes = 1,
  257. .lcd_conn = LCD_COLOR_TFT_8BPP | LCD_AC_BIAS_FREQ(0xff),
  258. .cmap_inverse = 0,
  259. .cmap_static = 0,
  260. };
  261. static struct pxafb_mode_info generic_tft_320x240_mode = {
  262. .pixclock = 134615,
  263. .bpp = 16,
  264. .xres = 320,
  265. .yres = 240,
  266. .hsync_len = 63,
  267. .vsync_len = 7,
  268. .left_margin = 75,
  269. .upper_margin = 0,
  270. .right_margin = 15,
  271. .lower_margin = 15,
  272. .sync = 0,
  273. .cmap_greyscale = 0,
  274. };
  275. static struct pxafb_mach_info generic_tft_320x240 = {
  276. .modes = &generic_tft_320x240_mode,
  277. .num_modes = 1,
  278. .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_AC_BIAS_FREQ(0xff),
  279. .cmap_inverse = 0,
  280. .cmap_static = 0,
  281. };
  282. static struct pxafb_mode_info generic_stn_640x480_mode = {
  283. .pixclock = 57692,
  284. .bpp = 8,
  285. .xres = 640,
  286. .yres = 480,
  287. .hsync_len = 4,
  288. .vsync_len = 2,
  289. .left_margin = 10,
  290. .upper_margin = 5,
  291. .right_margin = 10,
  292. .lower_margin = 5,
  293. .sync = (FB_SYNC_HOR_HIGH_ACT |
  294. FB_SYNC_VERT_HIGH_ACT),
  295. .cmap_greyscale = 0,
  296. };
  297. static struct pxafb_mach_info generic_stn_640x480 = {
  298. .modes = &generic_stn_640x480_mode,
  299. .num_modes = 1,
  300. .lcd_conn = LCD_COLOR_STN_8BPP | LCD_AC_BIAS_FREQ(0xff),
  301. .cmap_inverse = 0,
  302. .cmap_static = 0,
  303. };
  304. static struct pxafb_mach_info *cmx2xx_display = &generic_crt_640x480;
  305. static int __init cmx2xx_set_display(char *str)
  306. {
  307. int disp_type = simple_strtol(str, NULL, 0);
  308. switch (disp_type) {
  309. case MTYPE_STN320x240:
  310. cmx2xx_display = &generic_stn_320x240;
  311. break;
  312. case MTYPE_TFT640x480:
  313. cmx2xx_display = &generic_tft_640x480;
  314. break;
  315. case MTYPE_CRT640x480:
  316. cmx2xx_display = &generic_crt_640x480;
  317. break;
  318. case MTYPE_CRT800x600:
  319. cmx2xx_display = &generic_crt_800x600;
  320. break;
  321. case MTYPE_TFT320x240:
  322. cmx2xx_display = &generic_tft_320x240;
  323. break;
  324. case MTYPE_STN640x480:
  325. cmx2xx_display = &generic_stn_640x480;
  326. break;
  327. default: /* fallback to CRT 640x480 */
  328. cmx2xx_display = &generic_crt_640x480;
  329. break;
  330. }
  331. return 1;
  332. }
  333. /*
  334. This should be done really early to get proper configuration for
  335. frame buffer.
  336. Indeed, pxafb parameters can be used istead, but CM-X2XX bootloader
  337. has limitied line length for kernel command line, and also it will
  338. break compatibitlty with proprietary releases already in field.
  339. */
  340. __setup("monitor=", cmx2xx_set_display);
  341. static void __init cmx2xx_init_display(void)
  342. {
  343. pxa_set_fb_info(NULL, cmx2xx_display);
  344. }
  345. #else
  346. static inline void cmx2xx_init_display(void) {}
  347. #endif
  348. #ifdef CONFIG_PM
  349. static unsigned long sleep_save_msc[10];
  350. static int cmx2xx_suspend(void)
  351. {
  352. cmx2xx_pci_suspend();
  353. /* save MSC registers */
  354. sleep_save_msc[0] = __raw_readl(MSC0);
  355. sleep_save_msc[1] = __raw_readl(MSC1);
  356. sleep_save_msc[2] = __raw_readl(MSC2);
  357. /* setup power saving mode registers */
  358. PCFR = 0x0;
  359. PSLR = 0xff400000;
  360. PMCR = 0x00000005;
  361. PWER = 0x80000000;
  362. PFER = 0x00000000;
  363. PRER = 0x00000000;
  364. PGSR0 = 0xC0018800;
  365. PGSR1 = 0x004F0002;
  366. PGSR2 = 0x6021C000;
  367. PGSR3 = 0x00020000;
  368. return 0;
  369. }
  370. static void cmx2xx_resume(void)
  371. {
  372. cmx2xx_pci_resume();
  373. /* restore MSC registers */
  374. __raw_writel(sleep_save_msc[0], MSC0);
  375. __raw_writel(sleep_save_msc[1], MSC1);
  376. __raw_writel(sleep_save_msc[2], MSC2);
  377. }
  378. static struct syscore_ops cmx2xx_pm_syscore_ops = {
  379. .resume = cmx2xx_resume,
  380. .suspend = cmx2xx_suspend,
  381. };
  382. static int __init cmx2xx_pm_init(void)
  383. {
  384. register_syscore_ops(&cmx2xx_pm_syscore_ops);
  385. return 0;
  386. }
  387. #else
  388. static int __init cmx2xx_pm_init(void) { return 0; }
  389. #endif
  390. #if defined(CONFIG_SND_PXA2XX_AC97) || defined(CONFIG_SND_PXA2XX_AC97_MODULE)
  391. static void __init cmx2xx_init_ac97(void)
  392. {
  393. pxa_set_ac97_info(NULL);
  394. }
  395. #else
  396. static inline void cmx2xx_init_ac97(void) {}
  397. #endif
  398. static void __init cmx2xx_init(void)
  399. {
  400. pxa_set_ffuart_info(NULL);
  401. pxa_set_btuart_info(NULL);
  402. pxa_set_stuart_info(NULL);
  403. cmx2xx_pm_init();
  404. if (cpu_is_pxa25x())
  405. cmx255_init();
  406. else
  407. cmx270_init();
  408. cmx2xx_init_dm9000();
  409. cmx2xx_init_display();
  410. cmx2xx_init_ac97();
  411. cmx2xx_init_touchscreen();
  412. cmx2xx_init_leds();
  413. }
  414. static void __init cmx2xx_init_irq(void)
  415. {
  416. if (cpu_is_pxa25x()) {
  417. pxa25x_init_irq();
  418. cmx2xx_pci_init_irq(CMX255_GPIO_IT8152_IRQ);
  419. } else {
  420. pxa27x_init_irq();
  421. cmx2xx_pci_init_irq(CMX270_GPIO_IT8152_IRQ);
  422. }
  423. }
  424. #ifdef CONFIG_PCI
  425. /* Map PCI companion statically */
  426. static struct map_desc cmx2xx_io_desc[] __initdata = {
  427. [0] = { /* PCI bridge */
  428. .virtual = (unsigned long)CMX2XX_IT8152_VIRT,
  429. .pfn = __phys_to_pfn(PXA_CS4_PHYS),
  430. .length = SZ_64M,
  431. .type = MT_DEVICE
  432. },
  433. };
  434. static void __init cmx2xx_map_io(void)
  435. {
  436. if (cpu_is_pxa25x())
  437. pxa25x_map_io();
  438. if (cpu_is_pxa27x())
  439. pxa27x_map_io();
  440. iotable_init(cmx2xx_io_desc, ARRAY_SIZE(cmx2xx_io_desc));
  441. it8152_base_address = CMX2XX_IT8152_VIRT;
  442. }
  443. #else
  444. static void __init cmx2xx_map_io(void)
  445. {
  446. if (cpu_is_pxa25x())
  447. pxa25x_map_io();
  448. if (cpu_is_pxa27x())
  449. pxa27x_map_io();
  450. }
  451. #endif
  452. MACHINE_START(ARMCORE, "Compulab CM-X2XX")
  453. .atag_offset = 0x100,
  454. .map_io = cmx2xx_map_io,
  455. .nr_irqs = CMX2XX_NR_IRQS,
  456. .init_irq = cmx2xx_init_irq,
  457. /* NOTE: pxa25x_handle_irq() works on PXA27x w/o camera support */
  458. .handle_irq = pxa25x_handle_irq,
  459. .timer = &pxa_timer,
  460. .init_machine = cmx2xx_init,
  461. #ifdef CONFIG_PCI
  462. .dma_zone_size = SZ_64M,
  463. #endif
  464. .restart = pxa_restart,
  465. MACHINE_END