cm-x2xx.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  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/mfp-pxa27x.h>
  22. #include <mach/pxa-regs.h>
  23. #include <mach/audio.h>
  24. #include <mach/pxafb.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. /* virtual addresses for statically mapped regions */
  31. #define CMX2XX_VIRT_BASE (0xe8000000)
  32. #define CMX2XX_IT8152_VIRT (CMX2XX_VIRT_BASE)
  33. /* physical address if local-bus attached devices */
  34. #define CMX255_DM9000_PHYS_BASE (PXA_CS1_PHYS + (8 << 22))
  35. #define CMX270_DM9000_PHYS_BASE (PXA_CS1_PHYS + (6 << 22))
  36. /* leds */
  37. #define CMX255_GPIO_RED (27)
  38. #define CMX255_GPIO_GREEN (32)
  39. #define CMX270_GPIO_RED (93)
  40. #define CMX270_GPIO_GREEN (94)
  41. /* GPIO IRQ usage */
  42. #define GPIO22_ETHIRQ (22)
  43. #define GPIO10_ETHIRQ (10)
  44. #define CMX255_GPIO_IT8152_IRQ (0)
  45. #define CMX270_GPIO_IT8152_IRQ (22)
  46. #define CMX255_ETHIRQ IRQ_GPIO(GPIO22_ETHIRQ)
  47. #define CMX270_ETHIRQ IRQ_GPIO(GPIO10_ETHIRQ)
  48. #if defined(CONFIG_DM9000) || defined(CONFIG_DM9000_MODULE)
  49. static struct resource cmx255_dm9000_resource[] = {
  50. [0] = {
  51. .start = CMX255_DM9000_PHYS_BASE,
  52. .end = CMX255_DM9000_PHYS_BASE + 3,
  53. .flags = IORESOURCE_MEM,
  54. },
  55. [1] = {
  56. .start = CMX255_DM9000_PHYS_BASE + 4,
  57. .end = CMX255_DM9000_PHYS_BASE + 4 + 500,
  58. .flags = IORESOURCE_MEM,
  59. },
  60. [2] = {
  61. .start = CMX255_ETHIRQ,
  62. .end = CMX255_ETHIRQ,
  63. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
  64. }
  65. };
  66. static struct resource cmx270_dm9000_resource[] = {
  67. [0] = {
  68. .start = CMX270_DM9000_PHYS_BASE,
  69. .end = CMX270_DM9000_PHYS_BASE + 3,
  70. .flags = IORESOURCE_MEM,
  71. },
  72. [1] = {
  73. .start = CMX270_DM9000_PHYS_BASE + 8,
  74. .end = CMX270_DM9000_PHYS_BASE + 8 + 500,
  75. .flags = IORESOURCE_MEM,
  76. },
  77. [2] = {
  78. .start = CMX270_ETHIRQ,
  79. .end = CMX270_ETHIRQ,
  80. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
  81. }
  82. };
  83. static struct dm9000_plat_data cmx270_dm9000_platdata = {
  84. .flags = DM9000_PLATF_32BITONLY,
  85. };
  86. static struct platform_device cmx2xx_dm9000_device = {
  87. .name = "dm9000",
  88. .id = 0,
  89. .num_resources = ARRAY_SIZE(cmx270_dm9000_resource),
  90. .dev = {
  91. .platform_data = &cmx270_dm9000_platdata,
  92. }
  93. };
  94. static void __init cmx2xx_init_dm9000(void)
  95. {
  96. if (cpu_is_pxa25x())
  97. cmx2xx_dm9000_device.resource = cmx255_dm9000_resource;
  98. else
  99. cmx2xx_dm9000_device.resource = cmx270_dm9000_resource;
  100. platform_device_register(&cmx2xx_dm9000_device);
  101. }
  102. #else
  103. static inline void cmx2xx_init_dm9000(void) {}
  104. #endif
  105. /* UCB1400 touchscreen controller */
  106. #if defined(CONFIG_TOUCHSCREEN_UCB1400) || defined(CONFIG_TOUCHSCREEN_UCB1400_MODULE)
  107. static struct platform_device cmx2xx_ts_device = {
  108. .name = "ucb1400_ts",
  109. .id = -1,
  110. };
  111. static void __init cmx2xx_init_touchscreen(void)
  112. {
  113. platform_device_register(&cmx2xx_ts_device);
  114. }
  115. #else
  116. static inline void cmx2xx_init_touchscreen(void) {}
  117. #endif
  118. /* CM-X270 LEDs */
  119. #if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
  120. static struct gpio_led cmx2xx_leds[] = {
  121. [0] = {
  122. .name = "cm-x2xx:red",
  123. .default_trigger = "nand-disk",
  124. .active_low = 1,
  125. },
  126. [1] = {
  127. .name = "cm-x2xx:green",
  128. .default_trigger = "heartbeat",
  129. .active_low = 1,
  130. },
  131. };
  132. static struct gpio_led_platform_data cmx2xx_gpio_led_pdata = {
  133. .num_leds = ARRAY_SIZE(cmx2xx_leds),
  134. .leds = cmx2xx_leds,
  135. };
  136. static struct platform_device cmx2xx_led_device = {
  137. .name = "leds-gpio",
  138. .id = -1,
  139. .dev = {
  140. .platform_data = &cmx2xx_gpio_led_pdata,
  141. },
  142. };
  143. static void __init cmx2xx_init_leds(void)
  144. {
  145. if (cpu_is_pxa25x()) {
  146. cmx2xx_leds[0].gpio = CMX255_GPIO_RED;
  147. cmx2xx_leds[1].gpio = CMX255_GPIO_GREEN;
  148. } else {
  149. cmx2xx_leds[0].gpio = CMX270_GPIO_RED;
  150. cmx2xx_leds[1].gpio = CMX270_GPIO_GREEN;
  151. }
  152. platform_device_register(&cmx2xx_led_device);
  153. }
  154. #else
  155. static inline void cmx2xx_init_leds(void) {}
  156. #endif
  157. #if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
  158. /*
  159. Display definitions
  160. keep these for backwards compatibility, although symbolic names (as
  161. e.g. in lpd270.c) looks better
  162. */
  163. #define MTYPE_STN320x240 0
  164. #define MTYPE_TFT640x480 1
  165. #define MTYPE_CRT640x480 2
  166. #define MTYPE_CRT800x600 3
  167. #define MTYPE_TFT320x240 6
  168. #define MTYPE_STN640x480 7
  169. static struct pxafb_mode_info generic_stn_320x240_mode = {
  170. .pixclock = 76923,
  171. .bpp = 8,
  172. .xres = 320,
  173. .yres = 240,
  174. .hsync_len = 3,
  175. .vsync_len = 2,
  176. .left_margin = 3,
  177. .upper_margin = 0,
  178. .right_margin = 3,
  179. .lower_margin = 0,
  180. .sync = (FB_SYNC_HOR_HIGH_ACT |
  181. FB_SYNC_VERT_HIGH_ACT),
  182. .cmap_greyscale = 0,
  183. };
  184. static struct pxafb_mach_info generic_stn_320x240 = {
  185. .modes = &generic_stn_320x240_mode,
  186. .num_modes = 1,
  187. .lccr0 = 0,
  188. .lccr3 = (LCCR3_PixClkDiv(0x03) |
  189. LCCR3_Acb(0xff) |
  190. LCCR3_PCP),
  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. .lccr0 = (LCCR0_PAS),
  212. .lccr3 = (LCCR3_PixClkDiv(0x01) |
  213. LCCR3_Acb(0xff) |
  214. LCCR3_PCP),
  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. .lccr0 = (LCCR0_PAS),
  237. .lccr3 = (LCCR3_PixClkDiv(0x01) |
  238. LCCR3_Acb(0xff)),
  239. .cmap_inverse = 0,
  240. .cmap_static = 0,
  241. };
  242. static struct pxafb_mode_info generic_crt_800x600_mode = {
  243. .pixclock = 28846,
  244. .bpp = 8,
  245. .xres = 800,
  246. .yres = 600,
  247. .hsync_len = 63,
  248. .vsync_len = 2,
  249. .left_margin = 26,
  250. .upper_margin = 21,
  251. .right_margin = 26,
  252. .lower_margin = 11,
  253. .sync = (FB_SYNC_HOR_HIGH_ACT |
  254. FB_SYNC_VERT_HIGH_ACT),
  255. .cmap_greyscale = 0,
  256. };
  257. static struct pxafb_mach_info generic_crt_800x600 = {
  258. .modes = &generic_crt_800x600_mode,
  259. .num_modes = 1,
  260. .lccr0 = (LCCR0_PAS),
  261. .lccr3 = (LCCR3_PixClkDiv(0x02) |
  262. LCCR3_Acb(0xff)),
  263. .cmap_inverse = 0,
  264. .cmap_static = 0,
  265. };
  266. static struct pxafb_mode_info generic_tft_320x240_mode = {
  267. .pixclock = 134615,
  268. .bpp = 16,
  269. .xres = 320,
  270. .yres = 240,
  271. .hsync_len = 63,
  272. .vsync_len = 7,
  273. .left_margin = 75,
  274. .upper_margin = 0,
  275. .right_margin = 15,
  276. .lower_margin = 15,
  277. .sync = 0,
  278. .cmap_greyscale = 0,
  279. };
  280. static struct pxafb_mach_info generic_tft_320x240 = {
  281. .modes = &generic_tft_320x240_mode,
  282. .num_modes = 1,
  283. .lccr0 = (LCCR0_PAS),
  284. .lccr3 = (LCCR3_PixClkDiv(0x06) |
  285. LCCR3_Acb(0xff) |
  286. LCCR3_PCP),
  287. .cmap_inverse = 0,
  288. .cmap_static = 0,
  289. };
  290. static struct pxafb_mode_info generic_stn_640x480_mode = {
  291. .pixclock = 57692,
  292. .bpp = 8,
  293. .xres = 640,
  294. .yres = 480,
  295. .hsync_len = 4,
  296. .vsync_len = 2,
  297. .left_margin = 10,
  298. .upper_margin = 5,
  299. .right_margin = 10,
  300. .lower_margin = 5,
  301. .sync = (FB_SYNC_HOR_HIGH_ACT |
  302. FB_SYNC_VERT_HIGH_ACT),
  303. .cmap_greyscale = 0,
  304. };
  305. static struct pxafb_mach_info generic_stn_640x480 = {
  306. .modes = &generic_stn_640x480_mode,
  307. .num_modes = 1,
  308. .lccr0 = 0,
  309. .lccr3 = (LCCR3_PixClkDiv(0x02) |
  310. LCCR3_Acb(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. set_pxa_fb_info(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(struct sys_device *dev, pm_message_t state)
  361. {
  362. cmx2xx_pci_suspend();
  363. /* save MSC registers */
  364. sleep_save_msc[0] = MSC0;
  365. sleep_save_msc[1] = MSC1;
  366. sleep_save_msc[2] = 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 int cmx2xx_resume(struct sys_device *dev)
  381. {
  382. cmx2xx_pci_resume();
  383. /* restore MSC registers */
  384. MSC0 = sleep_save_msc[0];
  385. MSC1 = sleep_save_msc[1];
  386. MSC2 = sleep_save_msc[2];
  387. return 0;
  388. }
  389. static struct sysdev_class cmx2xx_pm_sysclass = {
  390. .name = "pm",
  391. .resume = cmx2xx_resume,
  392. .suspend = cmx2xx_suspend,
  393. };
  394. static struct sys_device cmx2xx_pm_device = {
  395. .cls = &cmx2xx_pm_sysclass,
  396. };
  397. static int __init cmx2xx_pm_init(void)
  398. {
  399. int error;
  400. error = sysdev_class_register(&cmx2xx_pm_sysclass);
  401. if (error == 0)
  402. error = sysdev_register(&cmx2xx_pm_device);
  403. return error;
  404. }
  405. #else
  406. static int __init cmx2xx_pm_init(void) { return 0; }
  407. #endif
  408. #if defined(CONFIG_SND_PXA2XX_AC97) || defined(CONFIG_SND_PXA2XX_AC97_MODULE)
  409. static void __init cmx2xx_init_ac97(void)
  410. {
  411. pxa_set_ac97_info(NULL);
  412. }
  413. #else
  414. static inline void cmx2xx_init_ac97(void) {}
  415. #endif
  416. static void __init cmx2xx_init(void)
  417. {
  418. cmx2xx_pm_init();
  419. if (cpu_is_pxa25x())
  420. cmx255_init();
  421. else
  422. cmx270_init();
  423. cmx2xx_init_dm9000();
  424. cmx2xx_init_display();
  425. cmx2xx_init_ac97();
  426. cmx2xx_init_touchscreen();
  427. cmx2xx_init_leds();
  428. }
  429. static void __init cmx2xx_init_irq(void)
  430. {
  431. pxa27x_init_irq();
  432. if (cpu_is_pxa25x()) {
  433. pxa25x_init_irq();
  434. cmx2xx_pci_init_irq(CMX255_GPIO_IT8152_IRQ);
  435. } else {
  436. pxa27x_init_irq();
  437. cmx2xx_pci_init_irq(CMX270_GPIO_IT8152_IRQ);
  438. }
  439. }
  440. #ifdef CONFIG_PCI
  441. /* Map PCI companion statically */
  442. static struct map_desc cmx2xx_io_desc[] __initdata = {
  443. [0] = { /* PCI bridge */
  444. .virtual = CMX2XX_IT8152_VIRT,
  445. .pfn = __phys_to_pfn(PXA_CS4_PHYS),
  446. .length = SZ_64M,
  447. .type = MT_DEVICE
  448. },
  449. };
  450. static void __init cmx2xx_map_io(void)
  451. {
  452. pxa_map_io();
  453. iotable_init(cmx2xx_io_desc, ARRAY_SIZE(cmx2xx_io_desc));
  454. it8152_base_address = CMX2XX_IT8152_VIRT;
  455. }
  456. #else
  457. static void __init cmx2xx_map_io(void)
  458. {
  459. pxa_map_io();
  460. }
  461. #endif
  462. MACHINE_START(ARMCORE, "Compulab CM-X2XX")
  463. .boot_params = 0xa0000100,
  464. .phys_io = 0x40000000,
  465. .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
  466. .map_io = cmx2xx_map_io,
  467. .init_irq = cmx2xx_init_irq,
  468. .timer = &pxa_timer,
  469. .init_machine = cmx2xx_init,
  470. MACHINE_END