mpc8610_hpcd.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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 <linux/fsl/guts.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 "mpc86xx.h"
  39. static struct device_node *pixis_node;
  40. static unsigned char *pixis_bdcfg0, *pixis_arch;
  41. /* DIU Pixel Clock bits of the CLKDVDR Global Utilities register */
  42. #define CLKDVDR_PXCKEN 0x80000000
  43. #define CLKDVDR_PXCKINV 0x10000000
  44. #define CLKDVDR_PXCKDLY 0x06000000
  45. #define CLKDVDR_PXCLK_MASK 0x001F0000
  46. #ifdef CONFIG_SUSPEND
  47. static irqreturn_t mpc8610_sw9_irq(int irq, void *data)
  48. {
  49. pr_debug("%s: PIXIS' event (sw9/wakeup) IRQ handled\n", __func__);
  50. return IRQ_HANDLED;
  51. }
  52. static void __init mpc8610_suspend_init(void)
  53. {
  54. int irq;
  55. int ret;
  56. if (!pixis_node)
  57. return;
  58. irq = irq_of_parse_and_map(pixis_node, 0);
  59. if (!irq) {
  60. pr_err("%s: can't map pixis event IRQ.\n", __func__);
  61. return;
  62. }
  63. ret = request_irq(irq, mpc8610_sw9_irq, 0, "sw9:wakeup", NULL);
  64. if (ret) {
  65. pr_err("%s: can't request pixis event IRQ: %d\n",
  66. __func__, ret);
  67. irq_dispose_mapping(irq);
  68. }
  69. enable_irq_wake(irq);
  70. }
  71. #else
  72. static inline void mpc8610_suspend_init(void) { }
  73. #endif /* CONFIG_SUSPEND */
  74. static const struct of_device_id mpc8610_ids[] __initconst = {
  75. { .compatible = "fsl,mpc8610-immr", },
  76. { .compatible = "fsl,mpc8610-guts", },
  77. /* So that the DMA channel nodes can be probed individually: */
  78. { .compatible = "fsl,eloplus-dma", },
  79. /* PCI controllers */
  80. { .compatible = "fsl,mpc8610-pci", },
  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. mpc86xx_common_publish_devices();
  90. /* Without this call, the SSI device driver won't get probed. */
  91. of_platform_bus_probe(NULL, mpc8610_ids, NULL);
  92. return 0;
  93. }
  94. machine_arch_initcall(mpc86xx_hpcd, mpc8610_declare_of_platform_devices);
  95. #if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
  96. /*
  97. * DIU Area Descriptor
  98. *
  99. * The MPC8610 reference manual shows the bits of the AD register in
  100. * little-endian order, which causes the BLUE_C field to be split into two
  101. * parts. To simplify the definition of the MAKE_AD() macro, we define the
  102. * fields in big-endian order and byte-swap the result.
  103. *
  104. * So even though the registers don't look like they're in the
  105. * same bit positions as they are on the P1022, the same value is written to
  106. * the AD register on the MPC8610 and on the P1022.
  107. */
  108. #define AD_BYTE_F 0x10000000
  109. #define AD_ALPHA_C_MASK 0x0E000000
  110. #define AD_ALPHA_C_SHIFT 25
  111. #define AD_BLUE_C_MASK 0x01800000
  112. #define AD_BLUE_C_SHIFT 23
  113. #define AD_GREEN_C_MASK 0x00600000
  114. #define AD_GREEN_C_SHIFT 21
  115. #define AD_RED_C_MASK 0x00180000
  116. #define AD_RED_C_SHIFT 19
  117. #define AD_PALETTE 0x00040000
  118. #define AD_PIXEL_S_MASK 0x00030000
  119. #define AD_PIXEL_S_SHIFT 16
  120. #define AD_COMP_3_MASK 0x0000F000
  121. #define AD_COMP_3_SHIFT 12
  122. #define AD_COMP_2_MASK 0x00000F00
  123. #define AD_COMP_2_SHIFT 8
  124. #define AD_COMP_1_MASK 0x000000F0
  125. #define AD_COMP_1_SHIFT 4
  126. #define AD_COMP_0_MASK 0x0000000F
  127. #define AD_COMP_0_SHIFT 0
  128. #define MAKE_AD(alpha, red, blue, green, size, c0, c1, c2, c3) \
  129. cpu_to_le32(AD_BYTE_F | (alpha << AD_ALPHA_C_SHIFT) | \
  130. (blue << AD_BLUE_C_SHIFT) | (green << AD_GREEN_C_SHIFT) | \
  131. (red << AD_RED_C_SHIFT) | (c3 << AD_COMP_3_SHIFT) | \
  132. (c2 << AD_COMP_2_SHIFT) | (c1 << AD_COMP_1_SHIFT) | \
  133. (c0 << AD_COMP_0_SHIFT) | (size << AD_PIXEL_S_SHIFT))
  134. u32 mpc8610hpcd_get_pixel_format(enum fsl_diu_monitor_port port,
  135. unsigned int bits_per_pixel)
  136. {
  137. static const u32 pixelformat[][3] = {
  138. {
  139. MAKE_AD(3, 0, 2, 1, 3, 8, 8, 8, 8),
  140. MAKE_AD(4, 2, 0, 1, 2, 8, 8, 8, 0),
  141. MAKE_AD(4, 0, 2, 1, 1, 5, 6, 5, 0)
  142. },
  143. {
  144. MAKE_AD(3, 2, 0, 1, 3, 8, 8, 8, 8),
  145. MAKE_AD(4, 0, 2, 1, 2, 8, 8, 8, 0),
  146. MAKE_AD(4, 2, 0, 1, 1, 5, 6, 5, 0)
  147. },
  148. };
  149. unsigned int arch_monitor;
  150. /* The DVI port is mis-wired on revision 1 of this board. */
  151. arch_monitor =
  152. ((*pixis_arch == 0x01) && (port == FSL_DIU_PORT_DVI)) ? 0 : 1;
  153. switch (bits_per_pixel) {
  154. case 32:
  155. return pixelformat[arch_monitor][0];
  156. case 24:
  157. return pixelformat[arch_monitor][1];
  158. case 16:
  159. return pixelformat[arch_monitor][2];
  160. default:
  161. pr_err("fsl-diu: unsupported pixel depth %u\n", bits_per_pixel);
  162. return 0;
  163. }
  164. }
  165. void mpc8610hpcd_set_gamma_table(enum fsl_diu_monitor_port port,
  166. char *gamma_table_base)
  167. {
  168. int i;
  169. if (port == FSL_DIU_PORT_DLVDS) {
  170. for (i = 0; i < 256*3; i++)
  171. gamma_table_base[i] = (gamma_table_base[i] << 2) |
  172. ((gamma_table_base[i] >> 6) & 0x03);
  173. }
  174. }
  175. #define PX_BRDCFG0_DVISEL (1 << 3)
  176. #define PX_BRDCFG0_DLINK (1 << 4)
  177. #define PX_BRDCFG0_DIU_MASK (PX_BRDCFG0_DVISEL | PX_BRDCFG0_DLINK)
  178. void mpc8610hpcd_set_monitor_port(enum fsl_diu_monitor_port port)
  179. {
  180. switch (port) {
  181. case FSL_DIU_PORT_DVI:
  182. clrsetbits_8(pixis_bdcfg0, PX_BRDCFG0_DIU_MASK,
  183. PX_BRDCFG0_DVISEL | PX_BRDCFG0_DLINK);
  184. break;
  185. case FSL_DIU_PORT_LVDS:
  186. clrsetbits_8(pixis_bdcfg0, PX_BRDCFG0_DIU_MASK,
  187. PX_BRDCFG0_DLINK);
  188. break;
  189. case FSL_DIU_PORT_DLVDS:
  190. clrbits8(pixis_bdcfg0, PX_BRDCFG0_DIU_MASK);
  191. break;
  192. }
  193. }
  194. /**
  195. * mpc8610hpcd_set_pixel_clock: program the DIU's clock
  196. *
  197. * @pixclock: the wavelength, in picoseconds, of the clock
  198. */
  199. void mpc8610hpcd_set_pixel_clock(unsigned int pixclock)
  200. {
  201. struct device_node *guts_np = NULL;
  202. struct ccsr_guts __iomem *guts;
  203. unsigned long freq;
  204. u64 temp;
  205. u32 pxclk;
  206. /* Map the global utilities registers. */
  207. guts_np = of_find_compatible_node(NULL, NULL, "fsl,mpc8610-guts");
  208. if (!guts_np) {
  209. pr_err("mpc8610hpcd: missing global utilities device node\n");
  210. return;
  211. }
  212. guts = of_iomap(guts_np, 0);
  213. of_node_put(guts_np);
  214. if (!guts) {
  215. pr_err("mpc8610hpcd: could not map global utilities device\n");
  216. return;
  217. }
  218. /* Convert pixclock from a wavelength to a frequency */
  219. temp = 1000000000000ULL;
  220. do_div(temp, pixclock);
  221. freq = temp;
  222. /*
  223. * 'pxclk' is the ratio of the platform clock to the pixel clock.
  224. * On the MPC8610, the value programmed into CLKDVDR is the ratio
  225. * minus one. The valid range of values is 2-31.
  226. */
  227. pxclk = DIV_ROUND_CLOSEST(fsl_get_sys_freq(), freq) - 1;
  228. pxclk = clamp_t(u32, pxclk, 2, 31);
  229. /* Disable the pixel clock, and set it to non-inverted and no delay */
  230. clrbits32(&guts->clkdvdr,
  231. CLKDVDR_PXCKEN | CLKDVDR_PXCKDLY | CLKDVDR_PXCLK_MASK);
  232. /* Enable the clock and set the pxclk */
  233. setbits32(&guts->clkdvdr, CLKDVDR_PXCKEN | (pxclk << 16));
  234. iounmap(guts);
  235. }
  236. enum fsl_diu_monitor_port
  237. mpc8610hpcd_valid_monitor_port(enum fsl_diu_monitor_port port)
  238. {
  239. return port;
  240. }
  241. #endif
  242. static void __init mpc86xx_hpcd_setup_arch(void)
  243. {
  244. struct resource r;
  245. unsigned char *pixis;
  246. if (ppc_md.progress)
  247. ppc_md.progress("mpc86xx_hpcd_setup_arch()", 0);
  248. fsl_pci_assign_primary();
  249. #if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
  250. diu_ops.get_pixel_format = mpc8610hpcd_get_pixel_format;
  251. diu_ops.set_gamma_table = mpc8610hpcd_set_gamma_table;
  252. diu_ops.set_monitor_port = mpc8610hpcd_set_monitor_port;
  253. diu_ops.set_pixel_clock = mpc8610hpcd_set_pixel_clock;
  254. diu_ops.valid_monitor_port = mpc8610hpcd_valid_monitor_port;
  255. #endif
  256. pixis_node = of_find_compatible_node(NULL, NULL, "fsl,fpga-pixis");
  257. if (pixis_node) {
  258. of_address_to_resource(pixis_node, 0, &r);
  259. of_node_put(pixis_node);
  260. pixis = ioremap(r.start, 32);
  261. if (!pixis) {
  262. printk(KERN_ERR "Err: can't map FPGA cfg register!\n");
  263. return;
  264. }
  265. pixis_bdcfg0 = pixis + 8;
  266. pixis_arch = pixis + 1;
  267. } else
  268. printk(KERN_ERR "Err: "
  269. "can't find device node 'fsl,fpga-pixis'\n");
  270. printk("MPC86xx HPCD board from Freescale Semiconductor\n");
  271. }
  272. /*
  273. * Called very early, device-tree isn't unflattened
  274. */
  275. static int __init mpc86xx_hpcd_probe(void)
  276. {
  277. if (of_machine_is_compatible("fsl,MPC8610HPCD"))
  278. return 1; /* Looks good */
  279. return 0;
  280. }
  281. define_machine(mpc86xx_hpcd) {
  282. .name = "MPC86xx HPCD",
  283. .probe = mpc86xx_hpcd_probe,
  284. .setup_arch = mpc86xx_hpcd_setup_arch,
  285. .init_IRQ = mpc86xx_init_irq,
  286. .get_irq = mpic_get_irq,
  287. .time_init = mpc86xx_time_init,
  288. .calibrate_decr = generic_calibrate_decr,
  289. .progress = udbg_progress,
  290. #ifdef CONFIG_PCI
  291. .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
  292. #endif
  293. };