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