mpc8610_hpcd.c 9.4 KB

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