cm-x2xx.c 12 KB

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