mpc8610_hpcd.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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/kdev_t.h>
  22. #include <linux/delay.h>
  23. #include <linux/seq_file.h>
  24. #include <linux/of.h>
  25. #include <asm/system.h>
  26. #include <asm/time.h>
  27. #include <asm/machdep.h>
  28. #include <asm/pci-bridge.h>
  29. #include <asm/prom.h>
  30. #include <mm/mmu_decl.h>
  31. #include <asm/udbg.h>
  32. #include <asm/mpic.h>
  33. #include <linux/of_platform.h>
  34. #include <sysdev/fsl_pci.h>
  35. #include <sysdev/fsl_soc.h>
  36. #include <sysdev/simple_gpio.h>
  37. #include "mpc86xx.h"
  38. static unsigned char *pixis_bdcfg0, *pixis_arch;
  39. static struct of_device_id __initdata mpc8610_ids[] = {
  40. { .compatible = "fsl,mpc8610-immr", },
  41. { .compatible = "simple-bus", },
  42. { .compatible = "gianfar", },
  43. {}
  44. };
  45. static int __init mpc8610_declare_of_platform_devices(void)
  46. {
  47. /* Firstly, register PIXIS GPIOs. */
  48. simple_gpiochip_init("fsl,fpga-pixis-gpio-bank");
  49. /* Without this call, the SSI device driver won't get probed. */
  50. of_platform_bus_probe(NULL, mpc8610_ids, NULL);
  51. return 0;
  52. }
  53. machine_device_initcall(mpc86xx_hpcd, mpc8610_declare_of_platform_devices);
  54. #if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
  55. static u32 get_busfreq(void)
  56. {
  57. struct device_node *node;
  58. u32 fs_busfreq = 0;
  59. node = of_find_node_by_type(NULL, "cpu");
  60. if (node) {
  61. unsigned int size;
  62. const unsigned int *prop =
  63. of_get_property(node, "bus-frequency", &size);
  64. if (prop)
  65. fs_busfreq = *prop;
  66. of_node_put(node);
  67. };
  68. return fs_busfreq;
  69. }
  70. unsigned int mpc8610hpcd_get_pixel_format(unsigned int bits_per_pixel,
  71. int monitor_port)
  72. {
  73. static const unsigned long pixelformat[][3] = {
  74. {0x88882317, 0x88083218, 0x65052119},
  75. {0x88883316, 0x88082219, 0x65053118},
  76. };
  77. unsigned int pix_fmt, arch_monitor;
  78. arch_monitor = ((*pixis_arch == 0x01) && (monitor_port == 0))? 0 : 1;
  79. /* DVI port for board version 0x01 */
  80. if (bits_per_pixel == 32)
  81. pix_fmt = pixelformat[arch_monitor][0];
  82. else if (bits_per_pixel == 24)
  83. pix_fmt = pixelformat[arch_monitor][1];
  84. else if (bits_per_pixel == 16)
  85. pix_fmt = pixelformat[arch_monitor][2];
  86. else
  87. pix_fmt = pixelformat[1][0];
  88. return pix_fmt;
  89. }
  90. void mpc8610hpcd_set_gamma_table(int monitor_port, char *gamma_table_base)
  91. {
  92. int i;
  93. if (monitor_port == 2) { /* dual link LVDS */
  94. for (i = 0; i < 256*3; i++)
  95. gamma_table_base[i] = (gamma_table_base[i] << 2) |
  96. ((gamma_table_base[i] >> 6) & 0x03);
  97. }
  98. }
  99. #define PX_BRDCFG0_DVISEL (1 << 3)
  100. #define PX_BRDCFG0_DLINK (1 << 4)
  101. #define PX_BRDCFG0_DIU_MASK (PX_BRDCFG0_DVISEL | PX_BRDCFG0_DLINK)
  102. void mpc8610hpcd_set_monitor_port(int monitor_port)
  103. {
  104. static const u8 bdcfg[] = {
  105. PX_BRDCFG0_DVISEL | PX_BRDCFG0_DLINK,
  106. PX_BRDCFG0_DLINK,
  107. 0,
  108. };
  109. if (monitor_port < 3)
  110. clrsetbits_8(pixis_bdcfg0, PX_BRDCFG0_DIU_MASK,
  111. bdcfg[monitor_port]);
  112. }
  113. void mpc8610hpcd_set_pixel_clock(unsigned int pixclock)
  114. {
  115. u32 __iomem *clkdvdr;
  116. u32 temp;
  117. /* variables for pixel clock calcs */
  118. ulong bestval, bestfreq, speed_ccb, minpixclock, maxpixclock;
  119. ulong pixval;
  120. long err;
  121. int i;
  122. clkdvdr = ioremap(get_immrbase() + 0xe0800, sizeof(u32));
  123. if (!clkdvdr) {
  124. printk(KERN_ERR "Err: can't map clock divider register!\n");
  125. return;
  126. }
  127. /* Pixel Clock configuration */
  128. pr_debug("DIU: Bus Frequency = %d\n", get_busfreq());
  129. speed_ccb = get_busfreq();
  130. /* Calculate the pixel clock with the smallest error */
  131. /* calculate the following in steps to avoid overflow */
  132. pr_debug("DIU pixclock in ps - %d\n", pixclock);
  133. temp = 1000000000/pixclock;
  134. temp *= 1000;
  135. pixclock = temp;
  136. pr_debug("DIU pixclock freq - %u\n", pixclock);
  137. temp = pixclock * 5 / 100;
  138. pr_debug("deviation = %d\n", temp);
  139. minpixclock = pixclock - temp;
  140. maxpixclock = pixclock + temp;
  141. pr_debug("DIU minpixclock - %lu\n", minpixclock);
  142. pr_debug("DIU maxpixclock - %lu\n", maxpixclock);
  143. pixval = speed_ccb/pixclock;
  144. pr_debug("DIU pixval = %lu\n", pixval);
  145. err = 100000000;
  146. bestval = pixval;
  147. pr_debug("DIU bestval = %lu\n", bestval);
  148. bestfreq = 0;
  149. for (i = -1; i <= 1; i++) {
  150. temp = speed_ccb / ((pixval+i) + 1);
  151. pr_debug("DIU test pixval i= %d, pixval=%lu, temp freq. = %u\n",
  152. i, pixval, temp);
  153. if ((temp < minpixclock) || (temp > maxpixclock))
  154. pr_debug("DIU exceeds monitor range (%lu to %lu)\n",
  155. minpixclock, maxpixclock);
  156. else if (abs(temp - pixclock) < err) {
  157. pr_debug("Entered the else if block %d\n", i);
  158. err = abs(temp - pixclock);
  159. bestval = pixval+i;
  160. bestfreq = temp;
  161. }
  162. }
  163. pr_debug("DIU chose = %lx\n", bestval);
  164. pr_debug("DIU error = %ld\n NomPixClk ", err);
  165. pr_debug("DIU: Best Freq = %lx\n", bestfreq);
  166. /* Modify PXCLK in GUTS CLKDVDR */
  167. pr_debug("DIU: Current value of CLKDVDR = 0x%08x\n", (*clkdvdr));
  168. temp = (*clkdvdr) & 0x2000FFFF;
  169. *clkdvdr = temp; /* turn off clock */
  170. *clkdvdr = temp | 0x80000000 | (((bestval) & 0x1F) << 16);
  171. pr_debug("DIU: Modified value of CLKDVDR = 0x%08x\n", (*clkdvdr));
  172. iounmap(clkdvdr);
  173. }
  174. ssize_t mpc8610hpcd_show_monitor_port(int monitor_port, char *buf)
  175. {
  176. return snprintf(buf, PAGE_SIZE,
  177. "%c0 - DVI\n"
  178. "%c1 - Single link LVDS\n"
  179. "%c2 - Dual link LVDS\n",
  180. monitor_port == 0 ? '*' : ' ',
  181. monitor_port == 1 ? '*' : ' ',
  182. monitor_port == 2 ? '*' : ' ');
  183. }
  184. int mpc8610hpcd_set_sysfs_monitor_port(int val)
  185. {
  186. return val < 3 ? val : 0;
  187. }
  188. #endif
  189. static void __init mpc86xx_hpcd_setup_arch(void)
  190. {
  191. struct resource r;
  192. struct device_node *np;
  193. unsigned char *pixis;
  194. if (ppc_md.progress)
  195. ppc_md.progress("mpc86xx_hpcd_setup_arch()", 0);
  196. #ifdef CONFIG_PCI
  197. for_each_node_by_type(np, "pci") {
  198. if (of_device_is_compatible(np, "fsl,mpc8610-pci")
  199. || of_device_is_compatible(np, "fsl,mpc8641-pcie")) {
  200. struct resource rsrc;
  201. of_address_to_resource(np, 0, &rsrc);
  202. if ((rsrc.start & 0xfffff) == 0xa000)
  203. fsl_add_bridge(np, 1);
  204. else
  205. fsl_add_bridge(np, 0);
  206. }
  207. }
  208. #endif
  209. #if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
  210. diu_ops.get_pixel_format = mpc8610hpcd_get_pixel_format;
  211. diu_ops.set_gamma_table = mpc8610hpcd_set_gamma_table;
  212. diu_ops.set_monitor_port = mpc8610hpcd_set_monitor_port;
  213. diu_ops.set_pixel_clock = mpc8610hpcd_set_pixel_clock;
  214. diu_ops.show_monitor_port = mpc8610hpcd_show_monitor_port;
  215. diu_ops.set_sysfs_monitor_port = mpc8610hpcd_set_sysfs_monitor_port;
  216. #endif
  217. np = of_find_compatible_node(NULL, NULL, "fsl,fpga-pixis");
  218. if (np) {
  219. of_address_to_resource(np, 0, &r);
  220. of_node_put(np);
  221. pixis = ioremap(r.start, 32);
  222. if (!pixis) {
  223. printk(KERN_ERR "Err: can't map FPGA cfg register!\n");
  224. return;
  225. }
  226. pixis_bdcfg0 = pixis + 8;
  227. pixis_arch = pixis + 1;
  228. } else
  229. printk(KERN_ERR "Err: "
  230. "can't find device node 'fsl,fpga-pixis'\n");
  231. printk("MPC86xx HPCD board from Freescale Semiconductor\n");
  232. }
  233. /*
  234. * Called very early, device-tree isn't unflattened
  235. */
  236. static int __init mpc86xx_hpcd_probe(void)
  237. {
  238. unsigned long root = of_get_flat_dt_root();
  239. if (of_flat_dt_is_compatible(root, "fsl,MPC8610HPCD"))
  240. return 1; /* Looks good */
  241. return 0;
  242. }
  243. static long __init mpc86xx_time_init(void)
  244. {
  245. unsigned int temp;
  246. /* Set the time base to zero */
  247. mtspr(SPRN_TBWL, 0);
  248. mtspr(SPRN_TBWU, 0);
  249. temp = mfspr(SPRN_HID0);
  250. temp |= HID0_TBEN;
  251. mtspr(SPRN_HID0, temp);
  252. asm volatile("isync");
  253. return 0;
  254. }
  255. define_machine(mpc86xx_hpcd) {
  256. .name = "MPC86xx HPCD",
  257. .probe = mpc86xx_hpcd_probe,
  258. .setup_arch = mpc86xx_hpcd_setup_arch,
  259. .init_IRQ = mpc86xx_init_irq,
  260. .get_irq = mpic_get_irq,
  261. .restart = fsl_rstcr_restart,
  262. .time_init = mpc86xx_time_init,
  263. .calibrate_decr = generic_calibrate_decr,
  264. .progress = udbg_progress,
  265. .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
  266. };