cm-x270.c 14 KB

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