cm-x270.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. /*
  2. * linux/arch/arm/mach-pxa/cm-x270.c
  3. *
  4. * Copyright (C) 2007 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/types.h>
  12. #include <linux/pm.h>
  13. #include <linux/fb.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/irq.h>
  16. #include <linux/sysdev.h>
  17. #include <linux/io.h>
  18. #include <linux/delay.h>
  19. #include <linux/dm9000.h>
  20. #include <linux/rtc-v3020.h>
  21. #include <linux/serial_8250.h>
  22. #include <video/mbxfb.h>
  23. #include <asm/mach/arch.h>
  24. #include <asm/mach-types.h>
  25. #include <asm/mach/map.h>
  26. #include <asm/arch/pxa-regs.h>
  27. #include <asm/arch/pxa2xx-regs.h>
  28. #include <asm/arch/pxa2xx-gpio.h>
  29. #include <asm/arch/pxafb.h>
  30. #include <asm/arch/ohci.h>
  31. #include <asm/arch/mmc.h>
  32. #include <asm/arch/bitfield.h>
  33. #include <asm/arch/cm-x270.h>
  34. #include <asm/hardware/it8152.h>
  35. #include "generic.h"
  36. #include "cm-x270-pci.h"
  37. #define RTC_PHYS_BASE (PXA_CS1_PHYS + (5 << 22))
  38. #define DM9000_PHYS_BASE (PXA_CS1_PHYS + (6 << 22))
  39. static struct resource cmx270_dm9k_resource[] = {
  40. [0] = {
  41. .start = DM9000_PHYS_BASE,
  42. .end = DM9000_PHYS_BASE + 4,
  43. .flags = IORESOURCE_MEM,
  44. },
  45. [1] = {
  46. .start = DM9000_PHYS_BASE + 8,
  47. .end = DM9000_PHYS_BASE + 8 + 500,
  48. .flags = IORESOURCE_MEM,
  49. },
  50. [2] = {
  51. .start = CMX270_ETHIRQ,
  52. .end = CMX270_ETHIRQ,
  53. .flags = IORESOURCE_IRQ,
  54. }
  55. };
  56. /* for the moment we limit ourselves to 32bit IO until some
  57. * better IO routines can be written and tested
  58. */
  59. static struct dm9000_plat_data cmx270_dm9k_platdata = {
  60. .flags = DM9000_PLATF_32BITONLY,
  61. };
  62. /* Ethernet device */
  63. static struct platform_device cmx270_device_dm9k = {
  64. .name = "dm9000",
  65. .id = 0,
  66. .num_resources = ARRAY_SIZE(cmx270_dm9k_resource),
  67. .resource = cmx270_dm9k_resource,
  68. .dev = {
  69. .platform_data = &cmx270_dm9k_platdata,
  70. }
  71. };
  72. /* audio device */
  73. static struct platform_device cmx270_audio_device = {
  74. .name = "pxa2xx-ac97",
  75. .id = -1,
  76. };
  77. /* touchscreen controller */
  78. static struct platform_device cmx270_ts_device = {
  79. .name = "ucb1400_ts",
  80. .id = -1,
  81. };
  82. /* RTC */
  83. static struct resource cmx270_v3020_resource[] = {
  84. [0] = {
  85. .start = RTC_PHYS_BASE,
  86. .end = RTC_PHYS_BASE + 4,
  87. .flags = IORESOURCE_MEM,
  88. },
  89. };
  90. struct v3020_platform_data cmx270_v3020_pdata = {
  91. .leftshift = 16,
  92. };
  93. static struct platform_device cmx270_rtc_device = {
  94. .name = "v3020",
  95. .num_resources = ARRAY_SIZE(cmx270_v3020_resource),
  96. .resource = cmx270_v3020_resource,
  97. .id = -1,
  98. .dev = {
  99. .platform_data = &cmx270_v3020_pdata,
  100. }
  101. };
  102. /*
  103. * CM-X270 LEDs
  104. */
  105. static struct platform_device cmx270_led_device = {
  106. .name = "cm-x270-led",
  107. .id = -1,
  108. };
  109. /* 2700G graphics */
  110. static u64 fb_dma_mask = ~(u64)0;
  111. static struct resource cmx270_2700G_resource[] = {
  112. /* frame buffer memory including ODFB and External SDRAM */
  113. [0] = {
  114. .start = MARATHON_PHYS,
  115. .end = MARATHON_PHYS + 0x02000000,
  116. .flags = IORESOURCE_MEM,
  117. },
  118. /* Marathon registers */
  119. [1] = {
  120. .start = MARATHON_PHYS + 0x03fe0000,
  121. .end = MARATHON_PHYS + 0x03ffffff,
  122. .flags = IORESOURCE_MEM,
  123. },
  124. };
  125. static unsigned long save_lcd_regs[10];
  126. static int cmx270_marathon_probe(struct fb_info *fb)
  127. {
  128. /* save PXA-270 pin settings before enabling 2700G */
  129. save_lcd_regs[0] = GPDR1;
  130. save_lcd_regs[1] = GPDR2;
  131. save_lcd_regs[2] = GAFR1_U;
  132. save_lcd_regs[3] = GAFR2_L;
  133. save_lcd_regs[4] = GAFR2_U;
  134. /* Disable PXA-270 on-chip controller driving pins */
  135. GPDR1 &= ~(0xfc000000);
  136. GPDR2 &= ~(0x00c03fff);
  137. GAFR1_U &= ~(0xfff00000);
  138. GAFR2_L &= ~(0x0fffffff);
  139. GAFR2_U &= ~(0x0000f000);
  140. return 0;
  141. }
  142. static int cmx270_marathon_remove(struct fb_info *fb)
  143. {
  144. GPDR1 = save_lcd_regs[0];
  145. GPDR2 = save_lcd_regs[1];
  146. GAFR1_U = save_lcd_regs[2];
  147. GAFR2_L = save_lcd_regs[3];
  148. GAFR2_U = save_lcd_regs[4];
  149. return 0;
  150. }
  151. static struct mbxfb_platform_data cmx270_2700G_data = {
  152. .xres = {
  153. .min = 240,
  154. .max = 1200,
  155. .defval = 640,
  156. },
  157. .yres = {
  158. .min = 240,
  159. .max = 1200,
  160. .defval = 480,
  161. },
  162. .bpp = {
  163. .min = 16,
  164. .max = 32,
  165. .defval = 16,
  166. },
  167. .memsize = 8*1024*1024,
  168. .probe = cmx270_marathon_probe,
  169. .remove = cmx270_marathon_remove,
  170. };
  171. static struct platform_device cmx270_2700G = {
  172. .name = "mbx-fb",
  173. .dev = {
  174. .platform_data = &cmx270_2700G_data,
  175. .dma_mask = &fb_dma_mask,
  176. .coherent_dma_mask = 0xffffffff,
  177. },
  178. .num_resources = ARRAY_SIZE(cmx270_2700G_resource),
  179. .resource = cmx270_2700G_resource,
  180. .id = -1,
  181. };
  182. static u64 ata_dma_mask = ~(u64)0;
  183. static struct platform_device cmx270_ata = {
  184. .name = "pata_cm_x270",
  185. .id = -1,
  186. .dev = {
  187. .dma_mask = &ata_dma_mask,
  188. .coherent_dma_mask = 0xffffffff,
  189. },
  190. };
  191. /* platform devices */
  192. static struct platform_device *platform_devices[] __initdata = {
  193. &cmx270_device_dm9k,
  194. &cmx270_audio_device,
  195. &cmx270_rtc_device,
  196. &cmx270_2700G,
  197. &cmx270_led_device,
  198. &cmx270_ts_device,
  199. &cmx270_ata,
  200. };
  201. /* Map PCI companion and IDE/General Purpose CS statically */
  202. static struct map_desc cmx270_io_desc[] __initdata = {
  203. [0] = { /* IDE/general purpose space */
  204. .virtual = CMX270_IDE104_VIRT,
  205. .pfn = __phys_to_pfn(CMX270_IDE104_PHYS),
  206. .length = SZ_64M - SZ_8M,
  207. .type = MT_DEVICE
  208. },
  209. [1] = { /* PCI bridge */
  210. .virtual = CMX270_IT8152_VIRT,
  211. .pfn = __phys_to_pfn(CMX270_IT8152_PHYS),
  212. .length = SZ_64M,
  213. .type = MT_DEVICE
  214. },
  215. };
  216. /*
  217. Display definitions
  218. keep these for backwards compatibility, although symbolic names (as
  219. e.g. in lpd270.c) looks better
  220. */
  221. #define MTYPE_STN320x240 0
  222. #define MTYPE_TFT640x480 1
  223. #define MTYPE_CRT640x480 2
  224. #define MTYPE_CRT800x600 3
  225. #define MTYPE_TFT320x240 6
  226. #define MTYPE_STN640x480 7
  227. static struct pxafb_mode_info generic_stn_320x240_mode = {
  228. .pixclock = 76923,
  229. .bpp = 8,
  230. .xres = 320,
  231. .yres = 240,
  232. .hsync_len = 3,
  233. .vsync_len = 2,
  234. .left_margin = 3,
  235. .upper_margin = 0,
  236. .right_margin = 3,
  237. .lower_margin = 0,
  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_stn_320x240 = {
  243. .modes = &generic_stn_320x240_mode,
  244. .num_modes = 1,
  245. .lccr0 = 0,
  246. .lccr3 = (LCCR3_PixClkDiv(0x03) |
  247. LCCR3_Acb(0xff) |
  248. LCCR3_PCP),
  249. .cmap_inverse = 0,
  250. .cmap_static = 0,
  251. };
  252. static struct pxafb_mode_info generic_tft_640x480_mode = {
  253. .pixclock = 38461,
  254. .bpp = 8,
  255. .xres = 640,
  256. .yres = 480,
  257. .hsync_len = 60,
  258. .vsync_len = 2,
  259. .left_margin = 70,
  260. .upper_margin = 10,
  261. .right_margin = 70,
  262. .lower_margin = 5,
  263. .sync = 0,
  264. .cmap_greyscale = 0,
  265. };
  266. static struct pxafb_mach_info generic_tft_640x480 = {
  267. .modes = &generic_tft_640x480_mode,
  268. .num_modes = 1,
  269. .lccr0 = (LCCR0_PAS),
  270. .lccr3 = (LCCR3_PixClkDiv(0x01) |
  271. LCCR3_Acb(0xff) |
  272. LCCR3_PCP),
  273. .cmap_inverse = 0,
  274. .cmap_static = 0,
  275. };
  276. static struct pxafb_mode_info generic_crt_640x480_mode = {
  277. .pixclock = 38461,
  278. .bpp = 8,
  279. .xres = 640,
  280. .yres = 480,
  281. .hsync_len = 63,
  282. .vsync_len = 2,
  283. .left_margin = 81,
  284. .upper_margin = 33,
  285. .right_margin = 16,
  286. .lower_margin = 10,
  287. .sync = (FB_SYNC_HOR_HIGH_ACT |
  288. FB_SYNC_VERT_HIGH_ACT),
  289. .cmap_greyscale = 0,
  290. };
  291. static struct pxafb_mach_info generic_crt_640x480 = {
  292. .modes = &generic_crt_640x480_mode,
  293. .num_modes = 1,
  294. .lccr0 = (LCCR0_PAS),
  295. .lccr3 = (LCCR3_PixClkDiv(0x01) |
  296. LCCR3_Acb(0xff)),
  297. .cmap_inverse = 0,
  298. .cmap_static = 0,
  299. };
  300. static struct pxafb_mode_info generic_crt_800x600_mode = {
  301. .pixclock = 28846,
  302. .bpp = 8,
  303. .xres = 800,
  304. .yres = 600,
  305. .hsync_len = 63,
  306. .vsync_len = 2,
  307. .left_margin = 26,
  308. .upper_margin = 21,
  309. .right_margin = 26,
  310. .lower_margin = 11,
  311. .sync = (FB_SYNC_HOR_HIGH_ACT |
  312. FB_SYNC_VERT_HIGH_ACT),
  313. .cmap_greyscale = 0,
  314. };
  315. static struct pxafb_mach_info generic_crt_800x600 = {
  316. .modes = &generic_crt_800x600_mode,
  317. .num_modes = 1,
  318. .lccr0 = (LCCR0_PAS),
  319. .lccr3 = (LCCR3_PixClkDiv(0x02) |
  320. LCCR3_Acb(0xff)),
  321. .cmap_inverse = 0,
  322. .cmap_static = 0,
  323. };
  324. static struct pxafb_mode_info generic_tft_320x240_mode = {
  325. .pixclock = 134615,
  326. .bpp = 16,
  327. .xres = 320,
  328. .yres = 240,
  329. .hsync_len = 63,
  330. .vsync_len = 7,
  331. .left_margin = 75,
  332. .upper_margin = 0,
  333. .right_margin = 15,
  334. .lower_margin = 15,
  335. .sync = 0,
  336. .cmap_greyscale = 0,
  337. };
  338. static struct pxafb_mach_info generic_tft_320x240 = {
  339. .modes = &generic_tft_320x240_mode,
  340. .num_modes = 1,
  341. .lccr0 = (LCCR0_PAS),
  342. .lccr3 = (LCCR3_PixClkDiv(0x06) |
  343. LCCR3_Acb(0xff) |
  344. LCCR3_PCP),
  345. .cmap_inverse = 0,
  346. .cmap_static = 0,
  347. };
  348. static struct pxafb_mode_info generic_stn_640x480_mode = {
  349. .pixclock = 57692,
  350. .bpp = 8,
  351. .xres = 640,
  352. .yres = 480,
  353. .hsync_len = 4,
  354. .vsync_len = 2,
  355. .left_margin = 10,
  356. .upper_margin = 5,
  357. .right_margin = 10,
  358. .lower_margin = 5,
  359. .sync = (FB_SYNC_HOR_HIGH_ACT |
  360. FB_SYNC_VERT_HIGH_ACT),
  361. .cmap_greyscale = 0,
  362. };
  363. static struct pxafb_mach_info generic_stn_640x480 = {
  364. .modes = &generic_stn_640x480_mode,
  365. .num_modes = 1,
  366. .lccr0 = 0,
  367. .lccr3 = (LCCR3_PixClkDiv(0x02) |
  368. LCCR3_Acb(0xff)),
  369. .cmap_inverse = 0,
  370. .cmap_static = 0,
  371. };
  372. static struct pxafb_mach_info *cmx270_display = &generic_crt_640x480;
  373. static int __init cmx270_set_display(char *str)
  374. {
  375. int disp_type = simple_strtol(str, NULL, 0);
  376. switch (disp_type) {
  377. case MTYPE_STN320x240:
  378. cmx270_display = &generic_stn_320x240;
  379. break;
  380. case MTYPE_TFT640x480:
  381. cmx270_display = &generic_tft_640x480;
  382. break;
  383. case MTYPE_CRT640x480:
  384. cmx270_display = &generic_crt_640x480;
  385. break;
  386. case MTYPE_CRT800x600:
  387. cmx270_display = &generic_crt_800x600;
  388. break;
  389. case MTYPE_TFT320x240:
  390. cmx270_display = &generic_tft_320x240;
  391. break;
  392. case MTYPE_STN640x480:
  393. cmx270_display = &generic_stn_640x480;
  394. break;
  395. default: /* fallback to CRT 640x480 */
  396. cmx270_display = &generic_crt_640x480;
  397. break;
  398. }
  399. return 1;
  400. }
  401. /*
  402. This should be done really early to get proper configuration for
  403. frame buffer.
  404. Indeed, pxafb parameters can be used istead, but CM-X270 bootloader
  405. has limitied line length for kernel command line, and also it will
  406. break compatibitlty with proprietary releases already in field.
  407. */
  408. __setup("monitor=", cmx270_set_display);
  409. /* PXA27x OHCI controller setup */
  410. static int cmx270_ohci_init(struct device *dev)
  411. {
  412. /* Set the Power Control Polarity Low */
  413. UHCHR = (UHCHR | UHCHR_PCPL) &
  414. ~(UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSE);
  415. return 0;
  416. }
  417. static struct pxaohci_platform_data cmx270_ohci_platform_data = {
  418. .port_mode = PMM_PERPORT_MODE,
  419. .init = cmx270_ohci_init,
  420. };
  421. static int cmx270_mci_init(struct device *dev,
  422. irq_handler_t cmx270_detect_int,
  423. void *data)
  424. {
  425. int err;
  426. /*
  427. * setup GPIO for PXA27x MMC controller
  428. */
  429. pxa_gpio_mode(GPIO32_MMCCLK_MD);
  430. pxa_gpio_mode(GPIO112_MMCCMD_MD);
  431. pxa_gpio_mode(GPIO92_MMCDAT0_MD);
  432. pxa_gpio_mode(GPIO109_MMCDAT1_MD);
  433. pxa_gpio_mode(GPIO110_MMCDAT2_MD);
  434. pxa_gpio_mode(GPIO111_MMCDAT3_MD);
  435. /* SB-X270 uses GPIO105 as SD power enable */
  436. pxa_gpio_mode(105 | GPIO_OUT);
  437. /* card detect IRQ on GPIO 83 */
  438. pxa_gpio_mode(IRQ_TO_GPIO(CMX270_MMC_IRQ));
  439. err = request_irq(CMX270_MMC_IRQ, cmx270_detect_int,
  440. IRQF_DISABLED | IRQF_TRIGGER_FALLING,
  441. "MMC card detect", data);
  442. if (err)
  443. printk(KERN_ERR "cmx270_mci_init: MMC/SD: can't"
  444. " request MMC card detect IRQ\n");
  445. return err;
  446. }
  447. static void cmx270_mci_setpower(struct device *dev, unsigned int vdd)
  448. {
  449. struct pxamci_platform_data *p_d = dev->platform_data;
  450. if ((1 << vdd) & p_d->ocr_mask) {
  451. printk(KERN_DEBUG "%s: on\n", __func__);
  452. GPCR(105) = GPIO_bit(105);
  453. } else {
  454. GPSR(105) = GPIO_bit(105);
  455. printk(KERN_DEBUG "%s: off\n", __func__);
  456. }
  457. }
  458. static void cmx270_mci_exit(struct device *dev, void *data)
  459. {
  460. free_irq(CMX270_MMC_IRQ, data);
  461. }
  462. static struct pxamci_platform_data cmx270_mci_platform_data = {
  463. .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
  464. .init = cmx270_mci_init,
  465. .setpower = cmx270_mci_setpower,
  466. .exit = cmx270_mci_exit,
  467. };
  468. #ifdef CONFIG_PM
  469. static unsigned long sleep_save_msc[10];
  470. static int cmx270_suspend(struct sys_device *dev, pm_message_t state)
  471. {
  472. cmx270_pci_suspend();
  473. /* save MSC registers */
  474. sleep_save_msc[0] = MSC0;
  475. sleep_save_msc[1] = MSC1;
  476. sleep_save_msc[2] = MSC2;
  477. /* setup power saving mode registers */
  478. PCFR = 0x0;
  479. PSLR = 0xff400000;
  480. PMCR = 0x00000005;
  481. PWER = 0x80000000;
  482. PFER = 0x00000000;
  483. PRER = 0x00000000;
  484. PGSR0 = 0xC0018800;
  485. PGSR1 = 0x004F0002;
  486. PGSR2 = 0x6021C000;
  487. PGSR3 = 0x00020000;
  488. return 0;
  489. }
  490. static int cmx270_resume(struct sys_device *dev)
  491. {
  492. cmx270_pci_resume();
  493. /* restore MSC registers */
  494. MSC0 = sleep_save_msc[0];
  495. MSC1 = sleep_save_msc[1];
  496. MSC2 = sleep_save_msc[2];
  497. return 0;
  498. }
  499. static struct sysdev_class cmx270_pm_sysclass = {
  500. .name = "pm",
  501. .resume = cmx270_resume,
  502. .suspend = cmx270_suspend,
  503. };
  504. static struct sys_device cmx270_pm_device = {
  505. .cls = &cmx270_pm_sysclass,
  506. };
  507. static int __init cmx270_pm_init(void)
  508. {
  509. int error;
  510. error = sysdev_class_register(&cmx270_pm_sysclass);
  511. if (error == 0)
  512. error = sysdev_register(&cmx270_pm_device);
  513. return error;
  514. }
  515. #else
  516. static int __init cmx270_pm_init(void) { return 0; }
  517. #endif
  518. static void __init cmx270_init(void)
  519. {
  520. cmx270_pm_init();
  521. set_pxa_fb_info(cmx270_display);
  522. /* register CM-X270 platform devices */
  523. platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices));
  524. /* set MCI and OHCI platform parameters */
  525. pxa_set_mci_info(&cmx270_mci_platform_data);
  526. pxa_set_ohci_info(&cmx270_ohci_platform_data);
  527. /* This enables the STUART */
  528. pxa_gpio_mode(GPIO46_STRXD_MD);
  529. pxa_gpio_mode(GPIO47_STTXD_MD);
  530. /* This enables the BTUART */
  531. pxa_gpio_mode(GPIO42_BTRXD_MD);
  532. pxa_gpio_mode(GPIO43_BTTXD_MD);
  533. pxa_gpio_mode(GPIO44_BTCTS_MD);
  534. pxa_gpio_mode(GPIO45_BTRTS_MD);
  535. }
  536. static void __init cmx270_init_irq(void)
  537. {
  538. pxa27x_init_irq();
  539. cmx270_pci_init_irq();
  540. /* Setup interrupt for dm9000 */
  541. pxa_gpio_mode(IRQ_TO_GPIO(CMX270_ETHIRQ));
  542. set_irq_type(CMX270_ETHIRQ, IRQT_RISING);
  543. /* Setup interrupt for 2700G */
  544. pxa_gpio_mode(IRQ_TO_GPIO(CMX270_GFXIRQ));
  545. set_irq_type(CMX270_GFXIRQ, IRQT_FALLING);
  546. }
  547. static void __init cmx270_map_io(void)
  548. {
  549. pxa_map_io();
  550. iotable_init(cmx270_io_desc, ARRAY_SIZE(cmx270_io_desc));
  551. }
  552. MACHINE_START(ARMCORE, "Compulab CM-x270")
  553. .boot_params = 0xa0000100,
  554. .phys_io = 0x40000000,
  555. .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
  556. .map_io = cmx270_map_io,
  557. .init_irq = cmx270_init_irq,
  558. .timer = &pxa_timer,
  559. .init_machine = cmx270_init,
  560. MACHINE_END