cm-x2xx.c 11 KB

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