cm-x2xx.c 12 KB

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