cm-x2xx.c 11 KB

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