2 * MPC8610 HPCD board specific routines
4 * Initial author: Xianghua Xiao <x.xiao@freescale.com>
5 * Recode: Jason Jin <jason.jin@freescale.com>
6 * York Sun <yorksun@freescale.com>
8 * Rewrite the interrupt routing. remove the 8259PIC support,
9 * All the integrated device in ULI use sideband interrupt.
11 * Copyright 2008 Freescale Semiconductor Inc.
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.
19 #include <linux/stddef.h>
20 #include <linux/kernel.h>
21 #include <linux/pci.h>
22 #include <linux/kdev_t.h>
23 #include <linux/delay.h>
24 #include <linux/seq_file.h>
27 #include <asm/system.h>
29 #include <asm/machdep.h>
30 #include <asm/pci-bridge.h>
31 #include <asm/mpc86xx.h>
33 #include <mm/mmu_decl.h>
38 #include <linux/of_platform.h>
39 #include <sysdev/fsl_pci.h>
40 #include <sysdev/fsl_soc.h>
42 static unsigned char *pixis_bdcfg0, *pixis_arch;
44 static struct of_device_id __initdata mpc8610_ids[] = {
45 { .compatible = "fsl,mpc8610-immr", },
49 static int __init mpc8610_declare_of_platform_devices(void)
51 /* Without this call, the SSI device driver won't get probed. */
52 of_platform_bus_probe(NULL, mpc8610_ids, NULL);
56 machine_device_initcall(mpc86xx_hpcd, mpc8610_declare_of_platform_devices);
58 static void __init mpc86xx_hpcd_init_irq(void)
61 struct device_node *np;
64 /* Determine PIC address. */
65 np = of_find_node_by_type(NULL, "open-pic");
68 of_address_to_resource(np, 0, &res);
70 /* Alloc mpic structure and per isu has 16 INT entries. */
71 mpic1 = mpic_alloc(np, res.start,
72 MPIC_PRIMARY | MPIC_WANTS_RESET | MPIC_BIG_ENDIAN,
74 BUG_ON(mpic1 == NULL);
80 static void __devinit quirk_uli1575(struct pci_dev *dev)
85 pci_read_config_dword(dev, 0x48, &temp32);
86 pci_write_config_dword(dev, 0x48, (temp32 | 1<<26));
88 /* Enable sideband interrupt */
89 pci_read_config_dword(dev, 0x90, &temp32);
90 pci_write_config_dword(dev, 0x90, (temp32 | 1<<22));
93 static void __devinit quirk_uli5288(struct pci_dev *dev)
98 /* Interrupt Disable, Needed when SATA disabled */
99 pci_read_config_word(dev, PCI_COMMAND, &temp);
101 pci_write_config_word(dev, PCI_COMMAND, temp);
103 pci_read_config_byte(dev, 0x83, &c);
105 pci_write_config_byte(dev, 0x83, c);
107 pci_write_config_byte(dev, PCI_CLASS_PROG, 0x01);
108 pci_write_config_byte(dev, PCI_CLASS_DEVICE, 0x06);
110 pci_read_config_byte(dev, 0x83, &c);
112 pci_write_config_byte(dev, 0x83, c);
116 * Since 8259PIC was disabled on the board, the IDE device can not
117 * use the legacy IRQ, we need to let the IDE device work under
118 * native mode and use the interrupt line like other PCI devices.
119 * IRQ14 is a sideband interrupt from IDE device to CPU and we use this
120 * as the interrupt for IDE device.
122 static void __devinit quirk_uli5229(struct pci_dev *dev)
126 pci_read_config_byte(dev, 0x4b, &c);
128 pci_write_config_byte(dev, 0x4b, c);
132 * SATA interrupt pin bug fix
133 * There's a chip bug for 5288, The interrupt pin should be 2,
134 * not the read only value 1, So it use INTB#, not INTA# which
135 * actually used by the IDE device 5229.
136 * As of this bug, during the PCI initialization, 5288 read the
137 * irq of IDE device from the device tree, this function fix this
138 * bug by re-assigning a correct irq to 5288.
141 static void __devinit final_uli5288(struct pci_dev *dev)
143 struct pci_controller *hose = pci_bus_to_host(dev->bus);
144 struct device_node *hosenode = hose ? hose->dn : NULL;
152 laddr[0] = (hose->first_busno << 16) | (PCI_DEVFN(31, 0) << 8);
153 laddr[1] = laddr[2] = 0;
154 of_irq_map_raw(hosenode, &pin, 1, laddr, &oirq);
155 virq = irq_create_of_mapping(oirq.controller, oirq.specifier,
160 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, 0x1575, quirk_uli1575);
161 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, 0x5288, quirk_uli5288);
162 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, 0x5229, quirk_uli5229);
163 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AL, 0x5288, final_uli5288);
164 #endif /* CONFIG_PCI */
166 #if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
168 static u32 get_busfreq(void)
170 struct device_node *node;
173 node = of_find_node_by_type(NULL, "cpu");
176 const unsigned int *prop =
177 of_get_property(node, "bus-frequency", &size);
185 unsigned int mpc8610hpcd_get_pixel_format(unsigned int bits_per_pixel,
188 static const unsigned long pixelformat[][3] = {
189 {0x88882317, 0x88083218, 0x65052119},
190 {0x88883316, 0x88082219, 0x65053118},
192 unsigned int pix_fmt, arch_monitor;
194 arch_monitor = ((*pixis_arch == 0x01) && (monitor_port == 0))? 0 : 1;
195 /* DVI port for board version 0x01 */
197 if (bits_per_pixel == 32)
198 pix_fmt = pixelformat[arch_monitor][0];
199 else if (bits_per_pixel == 24)
200 pix_fmt = pixelformat[arch_monitor][1];
201 else if (bits_per_pixel == 16)
202 pix_fmt = pixelformat[arch_monitor][2];
204 pix_fmt = pixelformat[1][0];
209 void mpc8610hpcd_set_gamma_table(int monitor_port, char *gamma_table_base)
212 if (monitor_port == 2) { /* dual link LVDS */
213 for (i = 0; i < 256*3; i++)
214 gamma_table_base[i] = (gamma_table_base[i] << 2) |
215 ((gamma_table_base[i] >> 6) & 0x03);
219 void mpc8610hpcd_set_monitor_port(int monitor_port)
221 static const u8 bdcfg[] = {0xBD, 0xB5, 0xA5};
222 if (monitor_port < 3)
223 *pixis_bdcfg0 = bdcfg[monitor_port];
226 void mpc8610hpcd_set_pixel_clock(unsigned int pixclock)
228 u32 __iomem *clkdvdr;
230 /* variables for pixel clock calcs */
231 ulong bestval, bestfreq, speed_ccb, minpixclock, maxpixclock;
236 clkdvdr = ioremap(get_immrbase() + 0xe0800, sizeof(u32));
238 printk(KERN_ERR "Err: can't map clock divider register!\n");
242 /* Pixel Clock configuration */
243 pr_debug("DIU: Bus Frequency = %d\n", get_busfreq());
244 speed_ccb = get_busfreq();
246 /* Calculate the pixel clock with the smallest error */
247 /* calculate the following in steps to avoid overflow */
248 pr_debug("DIU pixclock in ps - %d\n", pixclock);
249 temp = 1000000000/pixclock;
252 pr_debug("DIU pixclock freq - %u\n", pixclock);
254 temp = pixclock * 5 / 100;
255 pr_debug("deviation = %d\n", temp);
256 minpixclock = pixclock - temp;
257 maxpixclock = pixclock + temp;
258 pr_debug("DIU minpixclock - %lu\n", minpixclock);
259 pr_debug("DIU maxpixclock - %lu\n", maxpixclock);
260 pixval = speed_ccb/pixclock;
261 pr_debug("DIU pixval = %lu\n", pixval);
265 pr_debug("DIU bestval = %lu\n", bestval);
268 for (i = -1; i <= 1; i++) {
269 temp = speed_ccb / ((pixval+i) + 1);
270 pr_debug("DIU test pixval i= %d, pixval=%lu, temp freq. = %u\n",
272 if ((temp < minpixclock) || (temp > maxpixclock))
273 pr_debug("DIU exceeds monitor range (%lu to %lu)\n",
274 minpixclock, maxpixclock);
275 else if (abs(temp - pixclock) < err) {
276 pr_debug("Entered the else if block %d\n", i);
277 err = abs(temp - pixclock);
283 pr_debug("DIU chose = %lx\n", bestval);
284 pr_debug("DIU error = %ld\n NomPixClk ", err);
285 pr_debug("DIU: Best Freq = %lx\n", bestfreq);
286 /* Modify PXCLK in GUTS CLKDVDR */
287 pr_debug("DIU: Current value of CLKDVDR = 0x%08x\n", (*clkdvdr));
288 temp = (*clkdvdr) & 0x2000FFFF;
289 *clkdvdr = temp; /* turn off clock */
290 *clkdvdr = temp | 0x80000000 | (((bestval) & 0x1F) << 16);
291 pr_debug("DIU: Modified value of CLKDVDR = 0x%08x\n", (*clkdvdr));
295 ssize_t mpc8610hpcd_show_monitor_port(int monitor_port, char *buf)
297 return snprintf(buf, PAGE_SIZE,
299 "%c1 - Single link LVDS\n"
300 "%c2 - Dual link LVDS\n",
301 monitor_port == 0 ? '*' : ' ',
302 monitor_port == 1 ? '*' : ' ',
303 monitor_port == 2 ? '*' : ' ');
306 int mpc8610hpcd_set_sysfs_monitor_port(int val)
308 return val < 3 ? val : 0;
313 static void __init mpc86xx_hpcd_setup_arch(void)
316 struct device_node *np;
317 unsigned char *pixis;
320 ppc_md.progress("mpc86xx_hpcd_setup_arch()", 0);
323 for_each_node_by_type(np, "pci") {
324 if (of_device_is_compatible(np, "fsl,mpc8610-pci")
325 || of_device_is_compatible(np, "fsl,mpc8641-pcie")) {
326 struct resource rsrc;
327 of_address_to_resource(np, 0, &rsrc);
328 if ((rsrc.start & 0xfffff) == 0xa000)
329 fsl_add_bridge(np, 1);
331 fsl_add_bridge(np, 0);
335 #if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
336 preallocate_diu_videomemory();
337 diu_ops.get_pixel_format = mpc8610hpcd_get_pixel_format;
338 diu_ops.set_gamma_table = mpc8610hpcd_set_gamma_table;
339 diu_ops.set_monitor_port = mpc8610hpcd_set_monitor_port;
340 diu_ops.set_pixel_clock = mpc8610hpcd_set_pixel_clock;
341 diu_ops.show_monitor_port = mpc8610hpcd_show_monitor_port;
342 diu_ops.set_sysfs_monitor_port = mpc8610hpcd_set_sysfs_monitor_port;
345 np = of_find_compatible_node(NULL, NULL, "fsl,fpga-pixis");
347 of_address_to_resource(np, 0, &r);
349 pixis = ioremap(r.start, 32);
351 printk(KERN_ERR "Err: can't map FPGA cfg register!\n");
354 pixis_bdcfg0 = pixis + 8;
355 pixis_arch = pixis + 1;
357 printk(KERN_ERR "Err: "
358 "can't find device node 'fsl,fpga-pixis'\n");
360 printk("MPC86xx HPCD board from Freescale Semiconductor\n");
364 * Called very early, device-tree isn't unflattened
366 static int __init mpc86xx_hpcd_probe(void)
368 unsigned long root = of_get_flat_dt_root();
370 if (of_flat_dt_is_compatible(root, "fsl,MPC8610HPCD"))
371 return 1; /* Looks good */
376 static long __init mpc86xx_time_init(void)
380 /* Set the time base to zero */
384 temp = mfspr(SPRN_HID0);
386 mtspr(SPRN_HID0, temp);
387 asm volatile("isync");
392 define_machine(mpc86xx_hpcd) {
393 .name = "MPC86xx HPCD",
394 .probe = mpc86xx_hpcd_probe,
395 .setup_arch = mpc86xx_hpcd_setup_arch,
396 .init_IRQ = mpc86xx_hpcd_init_irq,
397 .get_irq = mpic_get_irq,
398 .restart = fsl_rstcr_restart,
399 .time_init = mpc86xx_time_init,
400 .calibrate_decr = generic_calibrate_decr,
401 .progress = udbg_progress,
402 .pcibios_fixup_bus = fsl_pcibios_fixup_bus,