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/interrupt.h>
23 #include <linux/kdev_t.h>
24 #include <linux/delay.h>
25 #include <linux/seq_file.h>
28 #include <asm/system.h>
30 #include <asm/machdep.h>
31 #include <asm/pci-bridge.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>
41 #include <sysdev/simple_gpio.h>
45 static struct device_node *pixis_node;
46 static unsigned char *pixis_bdcfg0, *pixis_arch;
49 static irqreturn_t mpc8610_sw9_irq(int irq, void *data)
51 pr_debug("%s: PIXIS' event (sw9/wakeup) IRQ handled\n", __func__);
55 static void __init mpc8610_suspend_init(void)
63 irq = irq_of_parse_and_map(pixis_node, 0);
65 pr_err("%s: can't map pixis event IRQ.\n", __func__);
69 ret = request_irq(irq, mpc8610_sw9_irq, 0, "sw9/wakeup", NULL);
71 pr_err("%s: can't request pixis event IRQ: %d\n",
73 irq_dispose_mapping(irq);
79 static inline void mpc8610_suspend_init(void) { }
80 #endif /* CONFIG_SUSPEND */
82 static struct of_device_id __initdata mpc8610_ids[] = {
83 { .compatible = "fsl,mpc8610-immr", },
84 { .compatible = "fsl,mpc8610-guts", },
85 { .compatible = "simple-bus", },
86 { .compatible = "gianfar", },
90 static int __init mpc8610_declare_of_platform_devices(void)
92 /* Firstly, register PIXIS GPIOs. */
93 simple_gpiochip_init("fsl,fpga-pixis-gpio-bank");
95 /* Enable wakeup on PIXIS' event IRQ. */
96 mpc8610_suspend_init();
98 /* Without this call, the SSI device driver won't get probed. */
99 of_platform_bus_probe(NULL, mpc8610_ids, NULL);
103 machine_device_initcall(mpc86xx_hpcd, mpc8610_declare_of_platform_devices);
105 #if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
107 static u32 get_busfreq(void)
109 struct device_node *node;
112 node = of_find_node_by_type(NULL, "cpu");
115 const unsigned int *prop =
116 of_get_property(node, "bus-frequency", &size);
124 unsigned int mpc8610hpcd_get_pixel_format(unsigned int bits_per_pixel,
127 static const unsigned long pixelformat[][3] = {
128 {0x88882317, 0x88083218, 0x65052119},
129 {0x88883316, 0x88082219, 0x65053118},
131 unsigned int pix_fmt, arch_monitor;
133 arch_monitor = ((*pixis_arch == 0x01) && (monitor_port == 0))? 0 : 1;
134 /* DVI port for board version 0x01 */
136 if (bits_per_pixel == 32)
137 pix_fmt = pixelformat[arch_monitor][0];
138 else if (bits_per_pixel == 24)
139 pix_fmt = pixelformat[arch_monitor][1];
140 else if (bits_per_pixel == 16)
141 pix_fmt = pixelformat[arch_monitor][2];
143 pix_fmt = pixelformat[1][0];
148 void mpc8610hpcd_set_gamma_table(int monitor_port, char *gamma_table_base)
151 if (monitor_port == 2) { /* dual link LVDS */
152 for (i = 0; i < 256*3; i++)
153 gamma_table_base[i] = (gamma_table_base[i] << 2) |
154 ((gamma_table_base[i] >> 6) & 0x03);
158 #define PX_BRDCFG0_DVISEL (1 << 3)
159 #define PX_BRDCFG0_DLINK (1 << 4)
160 #define PX_BRDCFG0_DIU_MASK (PX_BRDCFG0_DVISEL | PX_BRDCFG0_DLINK)
162 void mpc8610hpcd_set_monitor_port(int monitor_port)
164 static const u8 bdcfg[] = {
165 PX_BRDCFG0_DVISEL | PX_BRDCFG0_DLINK,
170 if (monitor_port < 3)
171 clrsetbits_8(pixis_bdcfg0, PX_BRDCFG0_DIU_MASK,
172 bdcfg[monitor_port]);
175 void mpc8610hpcd_set_pixel_clock(unsigned int pixclock)
177 u32 __iomem *clkdvdr;
179 /* variables for pixel clock calcs */
180 ulong bestval, bestfreq, speed_ccb, minpixclock, maxpixclock;
185 clkdvdr = ioremap(get_immrbase() + 0xe0800, sizeof(u32));
187 printk(KERN_ERR "Err: can't map clock divider register!\n");
191 /* Pixel Clock configuration */
192 pr_debug("DIU: Bus Frequency = %d\n", get_busfreq());
193 speed_ccb = get_busfreq();
195 /* Calculate the pixel clock with the smallest error */
196 /* calculate the following in steps to avoid overflow */
197 pr_debug("DIU pixclock in ps - %d\n", pixclock);
198 temp = 1000000000/pixclock;
201 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);
214 pr_debug("DIU bestval = %lu\n", bestval);
217 for (i = -1; i <= 1; i++) {
218 temp = speed_ccb / ((pixval+i) + 1);
219 pr_debug("DIU test pixval i= %d, pixval=%lu, temp freq. = %u\n",
221 if ((temp < minpixclock) || (temp > maxpixclock))
222 pr_debug("DIU exceeds monitor range (%lu to %lu)\n",
223 minpixclock, maxpixclock);
224 else if (abs(temp - pixclock) < err) {
225 pr_debug("Entered the else if block %d\n", i);
226 err = abs(temp - pixclock);
232 pr_debug("DIU chose = %lx\n", bestval);
233 pr_debug("DIU error = %ld\n NomPixClk ", err);
234 pr_debug("DIU: Best Freq = %lx\n", bestfreq);
235 /* Modify PXCLK in GUTS CLKDVDR */
236 pr_debug("DIU: Current value of CLKDVDR = 0x%08x\n", (*clkdvdr));
237 temp = (*clkdvdr) & 0x2000FFFF;
238 *clkdvdr = temp; /* turn off clock */
239 *clkdvdr = temp | 0x80000000 | (((bestval) & 0x1F) << 16);
240 pr_debug("DIU: Modified value of CLKDVDR = 0x%08x\n", (*clkdvdr));
244 ssize_t mpc8610hpcd_show_monitor_port(int monitor_port, char *buf)
246 return snprintf(buf, PAGE_SIZE,
248 "%c1 - Single link LVDS\n"
249 "%c2 - Dual link LVDS\n",
250 monitor_port == 0 ? '*' : ' ',
251 monitor_port == 1 ? '*' : ' ',
252 monitor_port == 2 ? '*' : ' ');
255 int mpc8610hpcd_set_sysfs_monitor_port(int val)
257 return val < 3 ? val : 0;
262 static void __init mpc86xx_hpcd_setup_arch(void)
265 struct device_node *np;
266 unsigned char *pixis;
269 ppc_md.progress("mpc86xx_hpcd_setup_arch()", 0);
272 for_each_node_by_type(np, "pci") {
273 if (of_device_is_compatible(np, "fsl,mpc8610-pci")
274 || of_device_is_compatible(np, "fsl,mpc8641-pcie")) {
275 struct resource rsrc;
276 of_address_to_resource(np, 0, &rsrc);
277 if ((rsrc.start & 0xfffff) == 0xa000)
278 fsl_add_bridge(np, 1);
280 fsl_add_bridge(np, 0);
284 #if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
285 diu_ops.get_pixel_format = mpc8610hpcd_get_pixel_format;
286 diu_ops.set_gamma_table = mpc8610hpcd_set_gamma_table;
287 diu_ops.set_monitor_port = mpc8610hpcd_set_monitor_port;
288 diu_ops.set_pixel_clock = mpc8610hpcd_set_pixel_clock;
289 diu_ops.show_monitor_port = mpc8610hpcd_show_monitor_port;
290 diu_ops.set_sysfs_monitor_port = mpc8610hpcd_set_sysfs_monitor_port;
293 pixis_node = of_find_compatible_node(NULL, NULL, "fsl,fpga-pixis");
295 of_address_to_resource(pixis_node, 0, &r);
296 of_node_put(pixis_node);
297 pixis = ioremap(r.start, 32);
299 printk(KERN_ERR "Err: can't map FPGA cfg register!\n");
302 pixis_bdcfg0 = pixis + 8;
303 pixis_arch = pixis + 1;
305 printk(KERN_ERR "Err: "
306 "can't find device node 'fsl,fpga-pixis'\n");
308 printk("MPC86xx HPCD board from Freescale Semiconductor\n");
312 * Called very early, device-tree isn't unflattened
314 static int __init mpc86xx_hpcd_probe(void)
316 unsigned long root = of_get_flat_dt_root();
318 if (of_flat_dt_is_compatible(root, "fsl,MPC8610HPCD"))
319 return 1; /* Looks good */
324 static long __init mpc86xx_time_init(void)
328 /* Set the time base to zero */
332 temp = mfspr(SPRN_HID0);
334 mtspr(SPRN_HID0, temp);
335 asm volatile("isync");
340 define_machine(mpc86xx_hpcd) {
341 .name = "MPC86xx HPCD",
342 .probe = mpc86xx_hpcd_probe,
343 .setup_arch = mpc86xx_hpcd_setup_arch,
344 .init_IRQ = mpc86xx_init_irq,
345 .get_irq = mpic_get_irq,
346 .restart = fsl_rstcr_restart,
347 .time_init = mpc86xx_time_init,
348 .calibrate_decr = generic_calibrate_decr,
349 .progress = udbg_progress,
350 .pcibios_fixup_bus = fsl_pcibios_fixup_bus,