mpc8610_hpcd.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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 "mpc86xx.h"
  39. static struct device_node *pixis_node;
  40. static unsigned char *pixis_bdcfg0, *pixis_arch;
  41. #ifdef CONFIG_SUSPEND
  42. static irqreturn_t mpc8610_sw9_irq(int irq, void *data)
  43. {
  44. pr_debug("%s: PIXIS' event (sw9/wakeup) IRQ handled\n", __func__);
  45. return IRQ_HANDLED;
  46. }
  47. static void __init mpc8610_suspend_init(void)
  48. {
  49. int irq;
  50. int ret;
  51. if (!pixis_node)
  52. return;
  53. irq = irq_of_parse_and_map(pixis_node, 0);
  54. if (!irq) {
  55. pr_err("%s: can't map pixis event IRQ.\n", __func__);
  56. return;
  57. }
  58. ret = request_irq(irq, mpc8610_sw9_irq, 0, "sw9:wakeup", NULL);
  59. if (ret) {
  60. pr_err("%s: can't request pixis event IRQ: %d\n",
  61. __func__, ret);
  62. irq_dispose_mapping(irq);
  63. }
  64. enable_irq_wake(irq);
  65. }
  66. #else
  67. static inline void mpc8610_suspend_init(void) { }
  68. #endif /* CONFIG_SUSPEND */
  69. static struct of_device_id __initdata mpc8610_ids[] = {
  70. { .compatible = "fsl,mpc8610-immr", },
  71. { .compatible = "fsl,mpc8610-guts", },
  72. { .compatible = "simple-bus", },
  73. /* So that the DMA channel nodes can be probed individually: */
  74. { .compatible = "fsl,eloplus-dma", },
  75. {}
  76. };
  77. static int __init mpc8610_declare_of_platform_devices(void)
  78. {
  79. /* Firstly, register PIXIS GPIOs. */
  80. simple_gpiochip_init("fsl,fpga-pixis-gpio-bank");
  81. /* Enable wakeup on PIXIS' event IRQ. */
  82. mpc8610_suspend_init();
  83. /* Without this call, the SSI device driver won't get probed. */
  84. of_platform_bus_probe(NULL, mpc8610_ids, NULL);
  85. return 0;
  86. }
  87. machine_device_initcall(mpc86xx_hpcd, mpc8610_declare_of_platform_devices);
  88. #if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
  89. /*
  90. * DIU Area Descriptor
  91. *
  92. * The MPC8610 reference manual shows the bits of the AD register in
  93. * little-endian order, which causes the BLUE_C field to be split into two
  94. * parts. To simplify the definition of the MAKE_AD() macro, we define the
  95. * fields in big-endian order and byte-swap the result.
  96. *
  97. * So even though the registers don't look like they're in the
  98. * same bit positions as they are on the P1022, the same value is written to
  99. * the AD register on the MPC8610 and on the P1022.
  100. */
  101. #define AD_BYTE_F 0x10000000
  102. #define AD_ALPHA_C_MASK 0x0E000000
  103. #define AD_ALPHA_C_SHIFT 25
  104. #define AD_BLUE_C_MASK 0x01800000
  105. #define AD_BLUE_C_SHIFT 23
  106. #define AD_GREEN_C_MASK 0x00600000
  107. #define AD_GREEN_C_SHIFT 21
  108. #define AD_RED_C_MASK 0x00180000
  109. #define AD_RED_C_SHIFT 19
  110. #define AD_PALETTE 0x00040000
  111. #define AD_PIXEL_S_MASK 0x00030000
  112. #define AD_PIXEL_S_SHIFT 16
  113. #define AD_COMP_3_MASK 0x0000F000
  114. #define AD_COMP_3_SHIFT 12
  115. #define AD_COMP_2_MASK 0x00000F00
  116. #define AD_COMP_2_SHIFT 8
  117. #define AD_COMP_1_MASK 0x000000F0
  118. #define AD_COMP_1_SHIFT 4
  119. #define AD_COMP_0_MASK 0x0000000F
  120. #define AD_COMP_0_SHIFT 0
  121. #define MAKE_AD(alpha, red, blue, green, size, c0, c1, c2, c3) \
  122. cpu_to_le32(AD_BYTE_F | (alpha << AD_ALPHA_C_SHIFT) | \
  123. (blue << AD_BLUE_C_SHIFT) | (green << AD_GREEN_C_SHIFT) | \
  124. (red << AD_RED_C_SHIFT) | (c3 << AD_COMP_3_SHIFT) | \
  125. (c2 << AD_COMP_2_SHIFT) | (c1 << AD_COMP_1_SHIFT) | \
  126. (c0 << AD_COMP_0_SHIFT) | (size << AD_PIXEL_S_SHIFT))
  127. unsigned int mpc8610hpcd_get_pixel_format(unsigned int bits_per_pixel,
  128. int monitor_port)
  129. {
  130. static const unsigned long pixelformat[][3] = {
  131. {
  132. MAKE_AD(3, 0, 2, 1, 3, 8, 8, 8, 8),
  133. MAKE_AD(4, 2, 0, 1, 2, 8, 8, 8, 0),
  134. MAKE_AD(4, 0, 2, 1, 1, 5, 6, 5, 0)
  135. },
  136. {
  137. MAKE_AD(3, 2, 0, 1, 3, 8, 8, 8, 8),
  138. MAKE_AD(4, 0, 2, 1, 2, 8, 8, 8, 0),
  139. MAKE_AD(4, 2, 0, 1, 1, 5, 6, 5, 0)
  140. },
  141. };
  142. unsigned int arch_monitor;
  143. /* The DVI port is mis-wired on revision 1 of this board. */
  144. arch_monitor = ((*pixis_arch == 0x01) && (monitor_port == 0))? 0 : 1;
  145. switch (bits_per_pixel) {
  146. case 32:
  147. return pixelformat[arch_monitor][0];
  148. case 24:
  149. return pixelformat[arch_monitor][1];
  150. case 16:
  151. return pixelformat[arch_monitor][2];
  152. default:
  153. pr_err("fsl-diu: unsupported pixel depth %u\n", bits_per_pixel);
  154. return 0;
  155. }
  156. }
  157. void mpc8610hpcd_set_gamma_table(int monitor_port, char *gamma_table_base)
  158. {
  159. int i;
  160. if (monitor_port == 2) { /* dual link LVDS */
  161. for (i = 0; i < 256*3; i++)
  162. gamma_table_base[i] = (gamma_table_base[i] << 2) |
  163. ((gamma_table_base[i] >> 6) & 0x03);
  164. }
  165. }
  166. #define PX_BRDCFG0_DVISEL (1 << 3)
  167. #define PX_BRDCFG0_DLINK (1 << 4)
  168. #define PX_BRDCFG0_DIU_MASK (PX_BRDCFG0_DVISEL | PX_BRDCFG0_DLINK)
  169. void mpc8610hpcd_set_monitor_port(int monitor_port)
  170. {
  171. static const u8 bdcfg[] = {
  172. PX_BRDCFG0_DVISEL | PX_BRDCFG0_DLINK,
  173. PX_BRDCFG0_DLINK,
  174. 0,
  175. };
  176. if (monitor_port < 3)
  177. clrsetbits_8(pixis_bdcfg0, PX_BRDCFG0_DIU_MASK,
  178. bdcfg[monitor_port]);
  179. }
  180. void mpc8610hpcd_set_pixel_clock(unsigned int pixclock)
  181. {
  182. u32 __iomem *clkdvdr;
  183. u32 temp;
  184. /* variables for pixel clock calcs */
  185. ulong bestval, bestfreq, speed_ccb, minpixclock, maxpixclock;
  186. ulong pixval;
  187. long err;
  188. int i;
  189. clkdvdr = ioremap(get_immrbase() + 0xe0800, sizeof(u32));
  190. if (!clkdvdr) {
  191. printk(KERN_ERR "Err: can't map clock divider register!\n");
  192. return;
  193. }
  194. /* Pixel Clock configuration */
  195. speed_ccb = fsl_get_sys_freq();
  196. /* Calculate the pixel clock with the smallest error */
  197. /* calculate the following in steps to avoid overflow */
  198. pr_debug("DIU pixclock in ps - %d\n", pixclock);
  199. temp = 1000000000/pixclock;
  200. temp *= 1000;
  201. pixclock = temp;
  202. pr_debug("DIU pixclock freq - %u\n", pixclock);
  203. temp = pixclock * 5 / 100;
  204. pr_debug("deviation = %d\n", temp);
  205. minpixclock = pixclock - temp;
  206. maxpixclock = pixclock + temp;
  207. pr_debug("DIU minpixclock - %lu\n", minpixclock);
  208. pr_debug("DIU maxpixclock - %lu\n", maxpixclock);
  209. pixval = speed_ccb/pixclock;
  210. pr_debug("DIU pixval = %lu\n", pixval);
  211. err = 100000000;
  212. bestval = pixval;
  213. pr_debug("DIU bestval = %lu\n", bestval);
  214. bestfreq = 0;
  215. for (i = -1; i <= 1; i++) {
  216. temp = speed_ccb / ((pixval+i) + 1);
  217. pr_debug("DIU test pixval i= %d, pixval=%lu, temp freq. = %u\n",
  218. i, pixval, temp);
  219. if ((temp < minpixclock) || (temp > maxpixclock))
  220. pr_debug("DIU exceeds monitor range (%lu to %lu)\n",
  221. minpixclock, maxpixclock);
  222. else if (abs(temp - pixclock) < err) {
  223. pr_debug("Entered the else if block %d\n", i);
  224. err = abs(temp - pixclock);
  225. bestval = pixval+i;
  226. bestfreq = temp;
  227. }
  228. }
  229. pr_debug("DIU chose = %lx\n", bestval);
  230. pr_debug("DIU error = %ld\n NomPixClk ", err);
  231. pr_debug("DIU: Best Freq = %lx\n", bestfreq);
  232. /* Modify PXCLK in GUTS CLKDVDR */
  233. pr_debug("DIU: Current value of CLKDVDR = 0x%08x\n", (*clkdvdr));
  234. temp = (*clkdvdr) & 0x2000FFFF;
  235. *clkdvdr = temp; /* turn off clock */
  236. *clkdvdr = temp | 0x80000000 | (((bestval) & 0x1F) << 16);
  237. pr_debug("DIU: Modified value of CLKDVDR = 0x%08x\n", (*clkdvdr));
  238. iounmap(clkdvdr);
  239. }
  240. ssize_t mpc8610hpcd_show_monitor_port(int monitor_port, char *buf)
  241. {
  242. return snprintf(buf, PAGE_SIZE,
  243. "%c0 - DVI\n"
  244. "%c1 - Single link LVDS\n"
  245. "%c2 - Dual link LVDS\n",
  246. monitor_port == 0 ? '*' : ' ',
  247. monitor_port == 1 ? '*' : ' ',
  248. monitor_port == 2 ? '*' : ' ');
  249. }
  250. int mpc8610hpcd_set_sysfs_monitor_port(int val)
  251. {
  252. return val < 3 ? val : 0;
  253. }
  254. #endif
  255. static void __init mpc86xx_hpcd_setup_arch(void)
  256. {
  257. struct resource r;
  258. struct device_node *np;
  259. unsigned char *pixis;
  260. if (ppc_md.progress)
  261. ppc_md.progress("mpc86xx_hpcd_setup_arch()", 0);
  262. #ifdef CONFIG_PCI
  263. for_each_node_by_type(np, "pci") {
  264. if (of_device_is_compatible(np, "fsl,mpc8610-pci")
  265. || of_device_is_compatible(np, "fsl,mpc8641-pcie")) {
  266. struct resource rsrc;
  267. of_address_to_resource(np, 0, &rsrc);
  268. if ((rsrc.start & 0xfffff) == 0xa000)
  269. fsl_add_bridge(np, 1);
  270. else
  271. fsl_add_bridge(np, 0);
  272. }
  273. }
  274. #endif
  275. #if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
  276. diu_ops.get_pixel_format = mpc8610hpcd_get_pixel_format;
  277. diu_ops.set_gamma_table = mpc8610hpcd_set_gamma_table;
  278. diu_ops.set_monitor_port = mpc8610hpcd_set_monitor_port;
  279. diu_ops.set_pixel_clock = mpc8610hpcd_set_pixel_clock;
  280. diu_ops.show_monitor_port = mpc8610hpcd_show_monitor_port;
  281. diu_ops.set_sysfs_monitor_port = mpc8610hpcd_set_sysfs_monitor_port;
  282. #endif
  283. pixis_node = of_find_compatible_node(NULL, NULL, "fsl,fpga-pixis");
  284. if (pixis_node) {
  285. of_address_to_resource(pixis_node, 0, &r);
  286. of_node_put(pixis_node);
  287. pixis = ioremap(r.start, 32);
  288. if (!pixis) {
  289. printk(KERN_ERR "Err: can't map FPGA cfg register!\n");
  290. return;
  291. }
  292. pixis_bdcfg0 = pixis + 8;
  293. pixis_arch = pixis + 1;
  294. } else
  295. printk(KERN_ERR "Err: "
  296. "can't find device node 'fsl,fpga-pixis'\n");
  297. printk("MPC86xx HPCD board from Freescale Semiconductor\n");
  298. }
  299. /*
  300. * Called very early, device-tree isn't unflattened
  301. */
  302. static int __init mpc86xx_hpcd_probe(void)
  303. {
  304. unsigned long root = of_get_flat_dt_root();
  305. if (of_flat_dt_is_compatible(root, "fsl,MPC8610HPCD"))
  306. return 1; /* Looks good */
  307. return 0;
  308. }
  309. static long __init mpc86xx_time_init(void)
  310. {
  311. unsigned int temp;
  312. /* Set the time base to zero */
  313. mtspr(SPRN_TBWL, 0);
  314. mtspr(SPRN_TBWU, 0);
  315. temp = mfspr(SPRN_HID0);
  316. temp |= HID0_TBEN;
  317. mtspr(SPRN_HID0, temp);
  318. asm volatile("isync");
  319. return 0;
  320. }
  321. define_machine(mpc86xx_hpcd) {
  322. .name = "MPC86xx HPCD",
  323. .probe = mpc86xx_hpcd_probe,
  324. .setup_arch = mpc86xx_hpcd_setup_arch,
  325. .init_IRQ = mpc86xx_init_irq,
  326. .get_irq = mpic_get_irq,
  327. .restart = fsl_rstcr_restart,
  328. .time_init = mpc86xx_time_init,
  329. .calibrate_decr = generic_calibrate_decr,
  330. .progress = udbg_progress,
  331. .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
  332. };