mpc8610_hpcd.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  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/mpc86xx.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. static unsigned char *pixis_bdcfg0, *pixis_arch;
  38. static struct of_device_id __initdata mpc8610_ids[] = {
  39. { .compatible = "fsl,mpc8610-immr", },
  40. { .compatible = "simple-bus", },
  41. {}
  42. };
  43. static int __init mpc8610_declare_of_platform_devices(void)
  44. {
  45. /* Without this call, the SSI device driver won't get probed. */
  46. of_platform_bus_probe(NULL, mpc8610_ids, NULL);
  47. return 0;
  48. }
  49. machine_device_initcall(mpc86xx_hpcd, mpc8610_declare_of_platform_devices);
  50. static void __init mpc86xx_hpcd_init_irq(void)
  51. {
  52. struct mpic *mpic1;
  53. struct device_node *np;
  54. struct resource res;
  55. /* Determine PIC address. */
  56. np = of_find_node_by_type(NULL, "open-pic");
  57. if (np == NULL)
  58. return;
  59. of_address_to_resource(np, 0, &res);
  60. /* Alloc mpic structure and per isu has 16 INT entries. */
  61. mpic1 = mpic_alloc(np, res.start,
  62. MPIC_PRIMARY | MPIC_WANTS_RESET |
  63. MPIC_BIG_ENDIAN | MPIC_BROKEN_FRR_NIRQS,
  64. 0, 256, " MPIC ");
  65. BUG_ON(mpic1 == NULL);
  66. mpic_init(mpic1);
  67. }
  68. #ifdef CONFIG_PCI
  69. static void __devinit quirk_uli1575(struct pci_dev *dev)
  70. {
  71. u32 temp32;
  72. /* Disable INTx */
  73. pci_read_config_dword(dev, 0x48, &temp32);
  74. pci_write_config_dword(dev, 0x48, (temp32 | 1<<26));
  75. /* Enable sideband interrupt */
  76. pci_read_config_dword(dev, 0x90, &temp32);
  77. pci_write_config_dword(dev, 0x90, (temp32 | 1<<22));
  78. }
  79. static void __devinit quirk_uli5288(struct pci_dev *dev)
  80. {
  81. unsigned char c;
  82. unsigned short temp;
  83. /* Interrupt Disable, Needed when SATA disabled */
  84. pci_read_config_word(dev, PCI_COMMAND, &temp);
  85. temp |= 1<<10;
  86. pci_write_config_word(dev, PCI_COMMAND, temp);
  87. pci_read_config_byte(dev, 0x83, &c);
  88. c |= 0x80;
  89. pci_write_config_byte(dev, 0x83, c);
  90. pci_write_config_byte(dev, PCI_CLASS_PROG, 0x01);
  91. pci_write_config_byte(dev, PCI_CLASS_DEVICE, 0x06);
  92. pci_read_config_byte(dev, 0x83, &c);
  93. c &= 0x7f;
  94. pci_write_config_byte(dev, 0x83, c);
  95. }
  96. /*
  97. * Since 8259PIC was disabled on the board, the IDE device can not
  98. * use the legacy IRQ, we need to let the IDE device work under
  99. * native mode and use the interrupt line like other PCI devices.
  100. * IRQ14 is a sideband interrupt from IDE device to CPU and we use this
  101. * as the interrupt for IDE device.
  102. */
  103. static void __devinit quirk_uli5229(struct pci_dev *dev)
  104. {
  105. unsigned char c;
  106. pci_read_config_byte(dev, 0x4b, &c);
  107. c |= 0x10;
  108. pci_write_config_byte(dev, 0x4b, c);
  109. }
  110. /*
  111. * SATA interrupt pin bug fix
  112. * There's a chip bug for 5288, The interrupt pin should be 2,
  113. * not the read only value 1, So it use INTB#, not INTA# which
  114. * actually used by the IDE device 5229.
  115. * As of this bug, during the PCI initialization, 5288 read the
  116. * irq of IDE device from the device tree, this function fix this
  117. * bug by re-assigning a correct irq to 5288.
  118. *
  119. */
  120. static void __devinit final_uli5288(struct pci_dev *dev)
  121. {
  122. struct pci_controller *hose = pci_bus_to_host(dev->bus);
  123. struct device_node *hosenode = hose ? hose->dn : NULL;
  124. struct of_irq oirq;
  125. int virq, pin = 2;
  126. u32 laddr[3];
  127. if (!hosenode)
  128. return;
  129. laddr[0] = (hose->first_busno << 16) | (PCI_DEVFN(31, 0) << 8);
  130. laddr[1] = laddr[2] = 0;
  131. of_irq_map_raw(hosenode, &pin, 1, laddr, &oirq);
  132. virq = irq_create_of_mapping(oirq.controller, oirq.specifier,
  133. oirq.size);
  134. dev->irq = virq;
  135. }
  136. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, 0x1575, quirk_uli1575);
  137. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, 0x5288, quirk_uli5288);
  138. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, 0x5229, quirk_uli5229);
  139. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AL, 0x5288, final_uli5288);
  140. #endif /* CONFIG_PCI */
  141. #if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
  142. static u32 get_busfreq(void)
  143. {
  144. struct device_node *node;
  145. u32 fs_busfreq = 0;
  146. node = of_find_node_by_type(NULL, "cpu");
  147. if (node) {
  148. unsigned int size;
  149. const unsigned int *prop =
  150. of_get_property(node, "bus-frequency", &size);
  151. if (prop)
  152. fs_busfreq = *prop;
  153. of_node_put(node);
  154. };
  155. return fs_busfreq;
  156. }
  157. unsigned int mpc8610hpcd_get_pixel_format(unsigned int bits_per_pixel,
  158. int monitor_port)
  159. {
  160. static const unsigned long pixelformat[][3] = {
  161. {0x88882317, 0x88083218, 0x65052119},
  162. {0x88883316, 0x88082219, 0x65053118},
  163. };
  164. unsigned int pix_fmt, arch_monitor;
  165. arch_monitor = ((*pixis_arch == 0x01) && (monitor_port == 0))? 0 : 1;
  166. /* DVI port for board version 0x01 */
  167. if (bits_per_pixel == 32)
  168. pix_fmt = pixelformat[arch_monitor][0];
  169. else if (bits_per_pixel == 24)
  170. pix_fmt = pixelformat[arch_monitor][1];
  171. else if (bits_per_pixel == 16)
  172. pix_fmt = pixelformat[arch_monitor][2];
  173. else
  174. pix_fmt = pixelformat[1][0];
  175. return pix_fmt;
  176. }
  177. void mpc8610hpcd_set_gamma_table(int monitor_port, char *gamma_table_base)
  178. {
  179. int i;
  180. if (monitor_port == 2) { /* dual link LVDS */
  181. for (i = 0; i < 256*3; i++)
  182. gamma_table_base[i] = (gamma_table_base[i] << 2) |
  183. ((gamma_table_base[i] >> 6) & 0x03);
  184. }
  185. }
  186. #define PX_BRDCFG0_DVISEL (1 << 3)
  187. #define PX_BRDCFG0_DLINK (1 << 4)
  188. #define PX_BRDCFG0_DIU_MASK (PX_BRDCFG0_DVISEL | PX_BRDCFG0_DLINK)
  189. void mpc8610hpcd_set_monitor_port(int monitor_port)
  190. {
  191. static const u8 bdcfg[] = {
  192. PX_BRDCFG0_DVISEL | PX_BRDCFG0_DLINK,
  193. PX_BRDCFG0_DLINK,
  194. 0,
  195. };
  196. if (monitor_port < 3)
  197. clrsetbits_8(pixis_bdcfg0, PX_BRDCFG0_DIU_MASK,
  198. bdcfg[monitor_port]);
  199. }
  200. void mpc8610hpcd_set_pixel_clock(unsigned int pixclock)
  201. {
  202. u32 __iomem *clkdvdr;
  203. u32 temp;
  204. /* variables for pixel clock calcs */
  205. ulong bestval, bestfreq, speed_ccb, minpixclock, maxpixclock;
  206. ulong pixval;
  207. long err;
  208. int i;
  209. clkdvdr = ioremap(get_immrbase() + 0xe0800, sizeof(u32));
  210. if (!clkdvdr) {
  211. printk(KERN_ERR "Err: can't map clock divider register!\n");
  212. return;
  213. }
  214. /* Pixel Clock configuration */
  215. pr_debug("DIU: Bus Frequency = %d\n", get_busfreq());
  216. speed_ccb = get_busfreq();
  217. /* Calculate the pixel clock with the smallest error */
  218. /* calculate the following in steps to avoid overflow */
  219. pr_debug("DIU pixclock in ps - %d\n", pixclock);
  220. temp = 1000000000/pixclock;
  221. temp *= 1000;
  222. pixclock = temp;
  223. pr_debug("DIU pixclock freq - %u\n", pixclock);
  224. temp = pixclock * 5 / 100;
  225. pr_debug("deviation = %d\n", temp);
  226. minpixclock = pixclock - temp;
  227. maxpixclock = pixclock + temp;
  228. pr_debug("DIU minpixclock - %lu\n", minpixclock);
  229. pr_debug("DIU maxpixclock - %lu\n", maxpixclock);
  230. pixval = speed_ccb/pixclock;
  231. pr_debug("DIU pixval = %lu\n", pixval);
  232. err = 100000000;
  233. bestval = pixval;
  234. pr_debug("DIU bestval = %lu\n", bestval);
  235. bestfreq = 0;
  236. for (i = -1; i <= 1; i++) {
  237. temp = speed_ccb / ((pixval+i) + 1);
  238. pr_debug("DIU test pixval i= %d, pixval=%lu, temp freq. = %u\n",
  239. i, pixval, temp);
  240. if ((temp < minpixclock) || (temp > maxpixclock))
  241. pr_debug("DIU exceeds monitor range (%lu to %lu)\n",
  242. minpixclock, maxpixclock);
  243. else if (abs(temp - pixclock) < err) {
  244. pr_debug("Entered the else if block %d\n", i);
  245. err = abs(temp - pixclock);
  246. bestval = pixval+i;
  247. bestfreq = temp;
  248. }
  249. }
  250. pr_debug("DIU chose = %lx\n", bestval);
  251. pr_debug("DIU error = %ld\n NomPixClk ", err);
  252. pr_debug("DIU: Best Freq = %lx\n", bestfreq);
  253. /* Modify PXCLK in GUTS CLKDVDR */
  254. pr_debug("DIU: Current value of CLKDVDR = 0x%08x\n", (*clkdvdr));
  255. temp = (*clkdvdr) & 0x2000FFFF;
  256. *clkdvdr = temp; /* turn off clock */
  257. *clkdvdr = temp | 0x80000000 | (((bestval) & 0x1F) << 16);
  258. pr_debug("DIU: Modified value of CLKDVDR = 0x%08x\n", (*clkdvdr));
  259. iounmap(clkdvdr);
  260. }
  261. ssize_t mpc8610hpcd_show_monitor_port(int monitor_port, char *buf)
  262. {
  263. return snprintf(buf, PAGE_SIZE,
  264. "%c0 - DVI\n"
  265. "%c1 - Single link LVDS\n"
  266. "%c2 - Dual link LVDS\n",
  267. monitor_port == 0 ? '*' : ' ',
  268. monitor_port == 1 ? '*' : ' ',
  269. monitor_port == 2 ? '*' : ' ');
  270. }
  271. int mpc8610hpcd_set_sysfs_monitor_port(int val)
  272. {
  273. return val < 3 ? val : 0;
  274. }
  275. #endif
  276. static void __init mpc86xx_hpcd_setup_arch(void)
  277. {
  278. struct resource r;
  279. struct device_node *np;
  280. unsigned char *pixis;
  281. if (ppc_md.progress)
  282. ppc_md.progress("mpc86xx_hpcd_setup_arch()", 0);
  283. #ifdef CONFIG_PCI
  284. for_each_node_by_type(np, "pci") {
  285. if (of_device_is_compatible(np, "fsl,mpc8610-pci")
  286. || of_device_is_compatible(np, "fsl,mpc8641-pcie")) {
  287. struct resource rsrc;
  288. of_address_to_resource(np, 0, &rsrc);
  289. if ((rsrc.start & 0xfffff) == 0xa000)
  290. fsl_add_bridge(np, 1);
  291. else
  292. fsl_add_bridge(np, 0);
  293. }
  294. }
  295. #endif
  296. #if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
  297. preallocate_diu_videomemory();
  298. diu_ops.get_pixel_format = mpc8610hpcd_get_pixel_format;
  299. diu_ops.set_gamma_table = mpc8610hpcd_set_gamma_table;
  300. diu_ops.set_monitor_port = mpc8610hpcd_set_monitor_port;
  301. diu_ops.set_pixel_clock = mpc8610hpcd_set_pixel_clock;
  302. diu_ops.show_monitor_port = mpc8610hpcd_show_monitor_port;
  303. diu_ops.set_sysfs_monitor_port = mpc8610hpcd_set_sysfs_monitor_port;
  304. #endif
  305. np = of_find_compatible_node(NULL, NULL, "fsl,fpga-pixis");
  306. if (np) {
  307. of_address_to_resource(np, 0, &r);
  308. of_node_put(np);
  309. pixis = ioremap(r.start, 32);
  310. if (!pixis) {
  311. printk(KERN_ERR "Err: can't map FPGA cfg register!\n");
  312. return;
  313. }
  314. pixis_bdcfg0 = pixis + 8;
  315. pixis_arch = pixis + 1;
  316. } else
  317. printk(KERN_ERR "Err: "
  318. "can't find device node 'fsl,fpga-pixis'\n");
  319. printk("MPC86xx HPCD board from Freescale Semiconductor\n");
  320. }
  321. /*
  322. * Called very early, device-tree isn't unflattened
  323. */
  324. static int __init mpc86xx_hpcd_probe(void)
  325. {
  326. unsigned long root = of_get_flat_dt_root();
  327. if (of_flat_dt_is_compatible(root, "fsl,MPC8610HPCD"))
  328. return 1; /* Looks good */
  329. return 0;
  330. }
  331. static long __init mpc86xx_time_init(void)
  332. {
  333. unsigned int temp;
  334. /* Set the time base to zero */
  335. mtspr(SPRN_TBWL, 0);
  336. mtspr(SPRN_TBWU, 0);
  337. temp = mfspr(SPRN_HID0);
  338. temp |= HID0_TBEN;
  339. mtspr(SPRN_HID0, temp);
  340. asm volatile("isync");
  341. return 0;
  342. }
  343. define_machine(mpc86xx_hpcd) {
  344. .name = "MPC86xx HPCD",
  345. .probe = mpc86xx_hpcd_probe,
  346. .setup_arch = mpc86xx_hpcd_setup_arch,
  347. .init_IRQ = mpc86xx_hpcd_init_irq,
  348. .get_irq = mpic_get_irq,
  349. .restart = fsl_rstcr_restart,
  350. .time_init = mpc86xx_time_init,
  351. .calibrate_decr = generic_calibrate_decr,
  352. .progress = udbg_progress,
  353. .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
  354. };