cm-x2xx.c 12 KB

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