mpc8610_hpcd.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. /*
  2. * MPC8610 HPCD board specific routines
  3. *
  4. * Initial author: Xianghua Xiao <x.xiao@freescale.com>
  5. * Recode: Jason Jin <jason.jin@freescale.com>
  6. * York Sun <yorksun@freescale.com>
  7. *
  8. * Rewrite the interrupt routing. remove the 8259PIC support,
  9. * All the integrated device in ULI use sideband interrupt.
  10. *
  11. * Copyright 2008 Freescale Semiconductor Inc.
  12. *
  13. * This program is free software; you can redistribute it and/or modify it
  14. * under the terms of the GNU General Public License as published by the
  15. * Free Software Foundation; either version 2 of the License, or (at your
  16. * option) any later version.
  17. */
  18. #include <linux/stddef.h>
  19. #include <linux/kernel.h>
  20. #include <linux/pci.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/kdev_t.h>
  23. #include <linux/delay.h>
  24. #include <linux/seq_file.h>
  25. #include <linux/of.h>
  26. #include <asm/system.h>
  27. #include <asm/time.h>
  28. #include <asm/machdep.h>
  29. #include <asm/pci-bridge.h>
  30. #include <asm/prom.h>
  31. #include <mm/mmu_decl.h>
  32. #include <asm/udbg.h>
  33. #include <asm/mpic.h>
  34. #include <linux/of_platform.h>
  35. #include <sysdev/fsl_pci.h>
  36. #include <sysdev/fsl_soc.h>
  37. #include <sysdev/simple_gpio.h>
  38. #include <asm/fsl_guts.h>
  39. #include "mpc86xx.h"
  40. static struct device_node *pixis_node;
  41. static unsigned char *pixis_bdcfg0, *pixis_arch;
  42. /* DIU Pixel Clock bits of the CLKDVDR Global Utilities register */
  43. #define CLKDVDR_PXCKEN 0x80000000
  44. #define CLKDVDR_PXCKINV 0x10000000
  45. #define CLKDVDR_PXCKDLY 0x06000000
  46. #define CLKDVDR_PXCLK_MASK 0x001F0000
  47. #ifdef CONFIG_SUSPEND
  48. static irqreturn_t mpc8610_sw9_irq(int irq, void *data)
  49. {
  50. pr_debug("%s: PIXIS' event (sw9/wakeup) IRQ handled\n", __func__);
  51. return IRQ_HANDLED;
  52. }
  53. static void __init mpc8610_suspend_init(void)
  54. {
  55. int irq;
  56. int ret;
  57. if (!pixis_node)
  58. return;
  59. irq = irq_of_parse_and_map(pixis_node, 0);
  60. if (!irq) {
  61. pr_err("%s: can't map pixis event IRQ.\n", __func__);
  62. return;
  63. }
  64. ret = request_irq(irq, mpc8610_sw9_irq, 0, "sw9:wakeup", NULL);
  65. if (ret) {
  66. pr_err("%s: can't request pixis event IRQ: %d\n",
  67. __func__, ret);
  68. irq_dispose_mapping(irq);
  69. }
  70. enable_irq_wake(irq);
  71. }
  72. #else
  73. static inline void mpc8610_suspend_init(void) { }
  74. #endif /* CONFIG_SUSPEND */
  75. static struct of_device_id __initdata mpc8610_ids[] = {
  76. { .compatible = "fsl,mpc8610-immr", },
  77. { .compatible = "fsl,mpc8610-guts", },
  78. { .compatible = "simple-bus", },
  79. /* So that the DMA channel nodes can be probed individually: */
  80. { .compatible = "fsl,eloplus-dma", },
  81. {}
  82. };
  83. static int __init mpc8610_declare_of_platform_devices(void)
  84. {
  85. /* Firstly, register PIXIS GPIOs. */
  86. simple_gpiochip_init("fsl,fpga-pixis-gpio-bank");
  87. /* Enable wakeup on PIXIS' event IRQ. */
  88. mpc8610_suspend_init();
  89. /* Without this call, the SSI device driver won't get probed. */
  90. of_platform_bus_probe(NULL, mpc8610_ids, NULL);
  91. return 0;
  92. }
  93. machine_device_initcall(mpc86xx_hpcd, mpc8610_declare_of_platform_devices);
  94. #if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
  95. /*
  96. * DIU Area Descriptor
  97. *
  98. * The MPC8610 reference manual shows the bits of the AD register in
  99. * little-endian order, which causes the BLUE_C field to be split into two
  100. * parts. To simplify the definition of the MAKE_AD() macro, we define the
  101. * fields in big-endian order and byte-swap the result.
  102. *
  103. * So even though the registers don't look like they're in the
  104. * same bit positions as they are on the P1022, the same value is written to
  105. * the AD register on the MPC8610 and on the P1022.
  106. */
  107. #define AD_BYTE_F 0x10000000
  108. #define AD_ALPHA_C_MASK 0x0E000000
  109. #define AD_ALPHA_C_SHIFT 25
  110. #define AD_BLUE_C_MASK 0x01800000
  111. #define AD_BLUE_C_SHIFT 23
  112. #define AD_GREEN_C_MASK 0x00600000
  113. #define AD_GREEN_C_SHIFT 21
  114. #define AD_RED_C_MASK 0x00180000
  115. #define AD_RED_C_SHIFT 19
  116. #define AD_PALETTE 0x00040000
  117. #define AD_PIXEL_S_MASK 0x00030000
  118. #define AD_PIXEL_S_SHIFT 16
  119. #define AD_COMP_3_MASK 0x0000F000
  120. #define AD_COMP_3_SHIFT 12
  121. #define AD_COMP_2_MASK 0x00000F00
  122. #define AD_COMP_2_SHIFT 8
  123. #define AD_COMP_1_MASK 0x000000F0
  124. #define AD_COMP_1_SHIFT 4
  125. #define AD_COMP_0_MASK 0x0000000F
  126. #define AD_COMP_0_SHIFT 0
  127. #define MAKE_AD(alpha, red, blue, green, size, c0, c1, c2, c3) \
  128. cpu_to_le32(AD_BYTE_F | (alpha << AD_ALPHA_C_SHIFT) | \
  129. (blue << AD_BLUE_C_SHIFT) | (green << AD_GREEN_C_SHIFT) | \
  130. (red << AD_RED_C_SHIFT) | (c3 << AD_COMP_3_SHIFT) | \
  131. (c2 << AD_COMP_2_SHIFT) | (c1 << AD_COMP_1_SHIFT) | \
  132. (c0 << AD_COMP_0_SHIFT) | (size << AD_PIXEL_S_SHIFT))
  133. unsigned int mpc8610hpcd_get_pixel_format(unsigned int bits_per_pixel,
  134. int monitor_port)
  135. {
  136. static const unsigned long pixelformat[][3] = {
  137. {
  138. MAKE_AD(3, 0, 2, 1, 3, 8, 8, 8, 8),
  139. MAKE_AD(4, 2, 0, 1, 2, 8, 8, 8, 0),
  140. MAKE_AD(4, 0, 2, 1, 1, 5, 6, 5, 0)
  141. },
  142. {
  143. MAKE_AD(3, 2, 0, 1, 3, 8, 8, 8, 8),
  144. MAKE_AD(4, 0, 2, 1, 2, 8, 8, 8, 0),
  145. MAKE_AD(4, 2, 0, 1, 1, 5, 6, 5, 0)
  146. },
  147. };
  148. unsigned int arch_monitor;
  149. /* The DVI port is mis-wired on revision 1 of this board. */
  150. arch_monitor = ((*pixis_arch == 0x01) && (monitor_port == 0))? 0 : 1;
  151. switch (bits_per_pixel) {
  152. case 32:
  153. return pixelformat[arch_monitor][0];
  154. case 24:
  155. return pixelformat[arch_monitor][1];
  156. case 16:
  157. return pixelformat[arch_monitor][2];
  158. default:
  159. pr_err("fsl-diu: unsupported pixel depth %u\n", bits_per_pixel);
  160. return 0;
  161. }
  162. }
  163. void mpc8610hpcd_set_gamma_table(int monitor_port, char *gamma_table_base)
  164. {
  165. int i;
  166. if (monitor_port == 2) { /* dual link LVDS */
  167. for (i = 0; i < 256*3; i++)
  168. gamma_table_base[i] = (gamma_table_base[i] << 2) |
  169. ((gamma_table_base[i] >> 6) & 0x03);
  170. }
  171. }
  172. #define PX_BRDCFG0_DVISEL (1 << 3)
  173. #define PX_BRDCFG0_DLINK (1 << 4)
  174. #define PX_BRDCFG0_DIU_MASK (PX_BRDCFG0_DVISEL | PX_BRDCFG0_DLINK)
  175. void mpc8610hpcd_set_monitor_port(int monitor_port)
  176. {
  177. static const u8 bdcfg[] = {
  178. PX_BRDCFG0_DVISEL | PX_BRDCFG0_DLINK,
  179. PX_BRDCFG0_DLINK,
  180. 0,
  181. };
  182. if (monitor_port < 3)
  183. clrsetbits_8(pixis_bdcfg0, PX_BRDCFG0_DIU_MASK,
  184. bdcfg[monitor_port]);
  185. }
  186. /**
  187. * mpc8610hpcd_set_pixel_clock: program the DIU's clock
  188. *
  189. * @pixclock: the wavelength, in picoseconds, of the clock
  190. */
  191. void mpc8610hpcd_set_pixel_clock(unsigned int pixclock)
  192. {
  193. struct device_node *guts_np = NULL;
  194. struct ccsr_guts_86xx __iomem *guts;
  195. unsigned long freq;
  196. u64 temp;
  197. u32 pxclk;
  198. /* Map the global utilities registers. */
  199. guts_np = of_find_compatible_node(NULL, NULL, "fsl,mpc8610-guts");
  200. if (!guts_np) {
  201. pr_err("mpc8610hpcd: missing global utilties device node\n");
  202. return;
  203. }
  204. guts = of_iomap(guts_np, 0);
  205. of_node_put(guts_np);
  206. if (!guts) {
  207. pr_err("mpc8610hpcd: could not map global utilties device\n");
  208. return;
  209. }
  210. /* Convert pixclock from a wavelength to a frequency */
  211. temp = 1000000000000ULL;
  212. do_div(temp, pixclock);
  213. freq = temp;
  214. /*
  215. * 'pxclk' is the ratio of the platform clock to the pixel clock.
  216. * On the MPC8610, the value programmed into CLKDVDR is the ratio
  217. * minus one. The valid range of values is 2-31.
  218. */
  219. pxclk = DIV_ROUND_CLOSEST(fsl_get_sys_freq(), freq) - 1;
  220. pxclk = clamp_t(u32, pxclk, 2, 31);
  221. /* Disable the pixel clock, and set it to non-inverted and no delay */
  222. clrbits32(&guts->clkdvdr,
  223. CLKDVDR_PXCKEN | CLKDVDR_PXCKDLY | CLKDVDR_PXCLK_MASK);
  224. /* Enable the clock and set the pxclk */
  225. setbits32(&guts->clkdvdr, CLKDVDR_PXCKEN | (pxclk << 16));
  226. iounmap(guts);
  227. }
  228. ssize_t mpc8610hpcd_show_monitor_port(int monitor_port, char *buf)
  229. {
  230. return snprintf(buf, PAGE_SIZE,
  231. "%c0 - DVI\n"
  232. "%c1 - Single link LVDS\n"
  233. "%c2 - Dual link LVDS\n",
  234. monitor_port == 0 ? '*' : ' ',
  235. monitor_port == 1 ? '*' : ' ',
  236. monitor_port == 2 ? '*' : ' ');
  237. }
  238. int mpc8610hpcd_set_sysfs_monitor_port(int val)
  239. {
  240. return val < 3 ? val : 0;
  241. }
  242. #endif
  243. static void __init mpc86xx_hpcd_setup_arch(void)
  244. {
  245. struct resource r;
  246. struct device_node *np;
  247. unsigned char *pixis;
  248. if (ppc_md.progress)
  249. ppc_md.progress("mpc86xx_hpcd_setup_arch()", 0);
  250. #ifdef CONFIG_PCI
  251. for_each_node_by_type(np, "pci") {
  252. if (of_device_is_compatible(np, "fsl,mpc8610-pci")
  253. || of_device_is_compatible(np, "fsl,mpc8641-pcie")) {
  254. struct resource rsrc;
  255. of_address_to_resource(np, 0, &rsrc);
  256. if ((rsrc.start & 0xfffff) == 0xa000)
  257. fsl_add_bridge(np, 1);
  258. else
  259. fsl_add_bridge(np, 0);
  260. }
  261. }
  262. #endif
  263. #if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
  264. diu_ops.get_pixel_format = mpc8610hpcd_get_pixel_format;
  265. diu_ops.set_gamma_table = mpc8610hpcd_set_gamma_table;
  266. diu_ops.set_monitor_port = mpc8610hpcd_set_monitor_port;
  267. diu_ops.set_pixel_clock = mpc8610hpcd_set_pixel_clock;
  268. diu_ops.show_monitor_port = mpc8610hpcd_show_monitor_port;
  269. diu_ops.set_sysfs_monitor_port = mpc8610hpcd_set_sysfs_monitor_port;
  270. #endif
  271. pixis_node = of_find_compatible_node(NULL, NULL, "fsl,fpga-pixis");
  272. if (pixis_node) {
  273. of_address_to_resource(pixis_node, 0, &r);
  274. of_node_put(pixis_node);
  275. pixis = ioremap(r.start, 32);
  276. if (!pixis) {
  277. printk(KERN_ERR "Err: can't map FPGA cfg register!\n");
  278. return;
  279. }
  280. pixis_bdcfg0 = pixis + 8;
  281. pixis_arch = pixis + 1;
  282. } else
  283. printk(KERN_ERR "Err: "
  284. "can't find device node 'fsl,fpga-pixis'\n");
  285. printk("MPC86xx HPCD board from Freescale Semiconductor\n");
  286. }
  287. /*
  288. * Called very early, device-tree isn't unflattened
  289. */
  290. static int __init mpc86xx_hpcd_probe(void)
  291. {
  292. unsigned long root = of_get_flat_dt_root();
  293. if (of_flat_dt_is_compatible(root, "fsl,MPC8610HPCD"))
  294. return 1; /* Looks good */
  295. return 0;
  296. }
  297. static long __init mpc86xx_time_init(void)
  298. {
  299. unsigned int temp;
  300. /* Set the time base to zero */
  301. mtspr(SPRN_TBWL, 0);
  302. mtspr(SPRN_TBWU, 0);
  303. temp = mfspr(SPRN_HID0);
  304. temp |= HID0_TBEN;
  305. mtspr(SPRN_HID0, temp);
  306. asm volatile("isync");
  307. return 0;
  308. }
  309. define_machine(mpc86xx_hpcd) {
  310. .name = "MPC86xx HPCD",
  311. .probe = mpc86xx_hpcd_probe,
  312. .setup_arch = mpc86xx_hpcd_setup_arch,
  313. .init_IRQ = mpc86xx_init_irq,
  314. .get_irq = mpic_get_irq,
  315. .restart = fsl_rstcr_restart,
  316. .time_init = mpc86xx_time_init,
  317. .calibrate_decr = generic_calibrate_decr,
  318. .progress = udbg_progress,
  319. .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
  320. };