mpc8610_hpcd.c 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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. u32 mpc8610hpcd_get_pixel_format(enum fsl_diu_monitor_port port,
  134. unsigned int bits_per_pixel)
  135. {
  136. static const u32 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 =
  151. ((*pixis_arch == 0x01) && (port == FSL_DIU_PORT_DVI)) ? 0 : 1;
  152. switch (bits_per_pixel) {
  153. case 32:
  154. return pixelformat[arch_monitor][0];
  155. case 24:
  156. return pixelformat[arch_monitor][1];
  157. case 16:
  158. return pixelformat[arch_monitor][2];
  159. default:
  160. pr_err("fsl-diu: unsupported pixel depth %u\n", bits_per_pixel);
  161. return 0;
  162. }
  163. }
  164. void mpc8610hpcd_set_gamma_table(enum fsl_diu_monitor_port port,
  165. char *gamma_table_base)
  166. {
  167. int i;
  168. if (port == FSL_DIU_PORT_DLVDS) {
  169. for (i = 0; i < 256*3; i++)
  170. gamma_table_base[i] = (gamma_table_base[i] << 2) |
  171. ((gamma_table_base[i] >> 6) & 0x03);
  172. }
  173. }
  174. #define PX_BRDCFG0_DVISEL (1 << 3)
  175. #define PX_BRDCFG0_DLINK (1 << 4)
  176. #define PX_BRDCFG0_DIU_MASK (PX_BRDCFG0_DVISEL | PX_BRDCFG0_DLINK)
  177. void mpc8610hpcd_set_monitor_port(enum fsl_diu_monitor_port port)
  178. {
  179. switch (port) {
  180. case FSL_DIU_PORT_DVI:
  181. clrsetbits_8(pixis_bdcfg0, PX_BRDCFG0_DIU_MASK,
  182. PX_BRDCFG0_DVISEL | PX_BRDCFG0_DLINK);
  183. break;
  184. case FSL_DIU_PORT_LVDS:
  185. clrsetbits_8(pixis_bdcfg0, PX_BRDCFG0_DIU_MASK,
  186. PX_BRDCFG0_DLINK);
  187. break;
  188. case FSL_DIU_PORT_DLVDS:
  189. clrbits8(pixis_bdcfg0, PX_BRDCFG0_DIU_MASK);
  190. break;
  191. }
  192. }
  193. /**
  194. * mpc8610hpcd_set_pixel_clock: program the DIU's clock
  195. *
  196. * @pixclock: the wavelength, in picoseconds, of the clock
  197. */
  198. void mpc8610hpcd_set_pixel_clock(unsigned int pixclock)
  199. {
  200. struct device_node *guts_np = NULL;
  201. struct ccsr_guts_86xx __iomem *guts;
  202. unsigned long freq;
  203. u64 temp;
  204. u32 pxclk;
  205. /* Map the global utilities registers. */
  206. guts_np = of_find_compatible_node(NULL, NULL, "fsl,mpc8610-guts");
  207. if (!guts_np) {
  208. pr_err("mpc8610hpcd: missing global utilties device node\n");
  209. return;
  210. }
  211. guts = of_iomap(guts_np, 0);
  212. of_node_put(guts_np);
  213. if (!guts) {
  214. pr_err("mpc8610hpcd: could not map global utilties device\n");
  215. return;
  216. }
  217. /* Convert pixclock from a wavelength to a frequency */
  218. temp = 1000000000000ULL;
  219. do_div(temp, pixclock);
  220. freq = temp;
  221. /*
  222. * 'pxclk' is the ratio of the platform clock to the pixel clock.
  223. * On the MPC8610, the value programmed into CLKDVDR is the ratio
  224. * minus one. The valid range of values is 2-31.
  225. */
  226. pxclk = DIV_ROUND_CLOSEST(fsl_get_sys_freq(), freq) - 1;
  227. pxclk = clamp_t(u32, pxclk, 2, 31);
  228. /* Disable the pixel clock, and set it to non-inverted and no delay */
  229. clrbits32(&guts->clkdvdr,
  230. CLKDVDR_PXCKEN | CLKDVDR_PXCKDLY | CLKDVDR_PXCLK_MASK);
  231. /* Enable the clock and set the pxclk */
  232. setbits32(&guts->clkdvdr, CLKDVDR_PXCKEN | (pxclk << 16));
  233. iounmap(guts);
  234. }
  235. enum fsl_diu_monitor_port
  236. mpc8610hpcd_valid_monitor_port(enum fsl_diu_monitor_port port)
  237. {
  238. return port;
  239. }
  240. #endif
  241. static void __init mpc86xx_hpcd_setup_arch(void)
  242. {
  243. struct resource r;
  244. struct device_node *np;
  245. unsigned char *pixis;
  246. if (ppc_md.progress)
  247. ppc_md.progress("mpc86xx_hpcd_setup_arch()", 0);
  248. #ifdef CONFIG_PCI
  249. for_each_node_by_type(np, "pci") {
  250. if (of_device_is_compatible(np, "fsl,mpc8610-pci")
  251. || of_device_is_compatible(np, "fsl,mpc8641-pcie")) {
  252. struct resource rsrc;
  253. of_address_to_resource(np, 0, &rsrc);
  254. if ((rsrc.start & 0xfffff) == 0xa000)
  255. fsl_add_bridge(np, 1);
  256. else
  257. fsl_add_bridge(np, 0);
  258. }
  259. }
  260. #endif
  261. #if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
  262. diu_ops.get_pixel_format = mpc8610hpcd_get_pixel_format;
  263. diu_ops.set_gamma_table = mpc8610hpcd_set_gamma_table;
  264. diu_ops.set_monitor_port = mpc8610hpcd_set_monitor_port;
  265. diu_ops.set_pixel_clock = mpc8610hpcd_set_pixel_clock;
  266. diu_ops.valid_monitor_port = mpc8610hpcd_valid_monitor_port;
  267. #endif
  268. pixis_node = of_find_compatible_node(NULL, NULL, "fsl,fpga-pixis");
  269. if (pixis_node) {
  270. of_address_to_resource(pixis_node, 0, &r);
  271. of_node_put(pixis_node);
  272. pixis = ioremap(r.start, 32);
  273. if (!pixis) {
  274. printk(KERN_ERR "Err: can't map FPGA cfg register!\n");
  275. return;
  276. }
  277. pixis_bdcfg0 = pixis + 8;
  278. pixis_arch = pixis + 1;
  279. } else
  280. printk(KERN_ERR "Err: "
  281. "can't find device node 'fsl,fpga-pixis'\n");
  282. printk("MPC86xx HPCD board from Freescale Semiconductor\n");
  283. }
  284. /*
  285. * Called very early, device-tree isn't unflattened
  286. */
  287. static int __init mpc86xx_hpcd_probe(void)
  288. {
  289. unsigned long root = of_get_flat_dt_root();
  290. if (of_flat_dt_is_compatible(root, "fsl,MPC8610HPCD"))
  291. return 1; /* Looks good */
  292. return 0;
  293. }
  294. static long __init mpc86xx_time_init(void)
  295. {
  296. unsigned int temp;
  297. /* Set the time base to zero */
  298. mtspr(SPRN_TBWL, 0);
  299. mtspr(SPRN_TBWU, 0);
  300. temp = mfspr(SPRN_HID0);
  301. temp |= HID0_TBEN;
  302. mtspr(SPRN_HID0, temp);
  303. asm volatile("isync");
  304. return 0;
  305. }
  306. define_machine(mpc86xx_hpcd) {
  307. .name = "MPC86xx HPCD",
  308. .probe = mpc86xx_hpcd_probe,
  309. .setup_arch = mpc86xx_hpcd_setup_arch,
  310. .init_IRQ = mpc86xx_init_irq,
  311. .get_irq = mpic_get_irq,
  312. .restart = fsl_rstcr_restart,
  313. .time_init = mpc86xx_time_init,
  314. .calibrate_decr = generic_calibrate_decr,
  315. .progress = udbg_progress,
  316. .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
  317. };