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>
42 #include <asm/fsl_guts.h>
46 static struct device_node
*pixis_node
;
47 static unsigned char *pixis_bdcfg0
, *pixis_arch
;
49 /* DIU Pixel Clock bits of the CLKDVDR Global Utilities register */
50 #define CLKDVDR_PXCKEN 0x80000000
51 #define CLKDVDR_PXCKINV 0x10000000
52 #define CLKDVDR_PXCKDLY 0x06000000
53 #define CLKDVDR_PXCLK_MASK 0x001F0000
56 static irqreturn_t
mpc8610_sw9_irq(int irq
, void *data
)
58 pr_debug("%s: PIXIS' event (sw9/wakeup) IRQ handled\n", __func__
);
62 static void __init
mpc8610_suspend_init(void)
70 irq
= irq_of_parse_and_map(pixis_node
, 0);
72 pr_err("%s: can't map pixis event IRQ.\n", __func__
);
76 ret
= request_irq(irq
, mpc8610_sw9_irq
, 0, "sw9:wakeup", NULL
);
78 pr_err("%s: can't request pixis event IRQ: %d\n",
80 irq_dispose_mapping(irq
);
86 static inline void mpc8610_suspend_init(void) { }
87 #endif /* CONFIG_SUSPEND */
89 static struct of_device_id __initdata mpc8610_ids
[] = {
90 { .compatible
= "fsl,mpc8610-immr", },
91 { .compatible
= "fsl,mpc8610-guts", },
92 { .compatible
= "simple-bus", },
93 /* So that the DMA channel nodes can be probed individually: */
94 { .compatible
= "fsl,eloplus-dma", },
98 static int __init
mpc8610_declare_of_platform_devices(void)
100 /* Firstly, register PIXIS GPIOs. */
101 simple_gpiochip_init("fsl,fpga-pixis-gpio-bank");
103 /* Enable wakeup on PIXIS' event IRQ. */
104 mpc8610_suspend_init();
106 /* Without this call, the SSI device driver won't get probed. */
107 of_platform_bus_probe(NULL
, mpc8610_ids
, NULL
);
111 machine_device_initcall(mpc86xx_hpcd
, mpc8610_declare_of_platform_devices
);
113 #if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
116 * DIU Area Descriptor
118 * The MPC8610 reference manual shows the bits of the AD register in
119 * little-endian order, which causes the BLUE_C field to be split into two
120 * parts. To simplify the definition of the MAKE_AD() macro, we define the
121 * fields in big-endian order and byte-swap the result.
123 * So even though the registers don't look like they're in the
124 * same bit positions as they are on the P1022, the same value is written to
125 * the AD register on the MPC8610 and on the P1022.
127 #define AD_BYTE_F 0x10000000
128 #define AD_ALPHA_C_MASK 0x0E000000
129 #define AD_ALPHA_C_SHIFT 25
130 #define AD_BLUE_C_MASK 0x01800000
131 #define AD_BLUE_C_SHIFT 23
132 #define AD_GREEN_C_MASK 0x00600000
133 #define AD_GREEN_C_SHIFT 21
134 #define AD_RED_C_MASK 0x00180000
135 #define AD_RED_C_SHIFT 19
136 #define AD_PALETTE 0x00040000
137 #define AD_PIXEL_S_MASK 0x00030000
138 #define AD_PIXEL_S_SHIFT 16
139 #define AD_COMP_3_MASK 0x0000F000
140 #define AD_COMP_3_SHIFT 12
141 #define AD_COMP_2_MASK 0x00000F00
142 #define AD_COMP_2_SHIFT 8
143 #define AD_COMP_1_MASK 0x000000F0
144 #define AD_COMP_1_SHIFT 4
145 #define AD_COMP_0_MASK 0x0000000F
146 #define AD_COMP_0_SHIFT 0
148 #define MAKE_AD(alpha, red, blue, green, size, c0, c1, c2, c3) \
149 cpu_to_le32(AD_BYTE_F | (alpha << AD_ALPHA_C_SHIFT) | \
150 (blue << AD_BLUE_C_SHIFT) | (green << AD_GREEN_C_SHIFT) | \
151 (red << AD_RED_C_SHIFT) | (c3 << AD_COMP_3_SHIFT) | \
152 (c2 << AD_COMP_2_SHIFT) | (c1 << AD_COMP_1_SHIFT) | \
153 (c0 << AD_COMP_0_SHIFT) | (size << AD_PIXEL_S_SHIFT))
155 u32
mpc8610hpcd_get_pixel_format(enum fsl_diu_monitor_port port
,
156 unsigned int bits_per_pixel
)
158 static const u32 pixelformat
[][3] = {
160 MAKE_AD(3, 0, 2, 1, 3, 8, 8, 8, 8),
161 MAKE_AD(4, 2, 0, 1, 2, 8, 8, 8, 0),
162 MAKE_AD(4, 0, 2, 1, 1, 5, 6, 5, 0)
165 MAKE_AD(3, 2, 0, 1, 3, 8, 8, 8, 8),
166 MAKE_AD(4, 0, 2, 1, 2, 8, 8, 8, 0),
167 MAKE_AD(4, 2, 0, 1, 1, 5, 6, 5, 0)
170 unsigned int arch_monitor
;
172 /* The DVI port is mis-wired on revision 1 of this board. */
174 ((*pixis_arch
== 0x01) && (port
== FSL_DIU_PORT_DVI
)) ? 0 : 1;
176 switch (bits_per_pixel
) {
178 return pixelformat
[arch_monitor
][0];
180 return pixelformat
[arch_monitor
][1];
182 return pixelformat
[arch_monitor
][2];
184 pr_err("fsl-diu: unsupported pixel depth %u\n", bits_per_pixel
);
189 void mpc8610hpcd_set_gamma_table(enum fsl_diu_monitor_port port
,
190 char *gamma_table_base
)
193 if (port
== FSL_DIU_PORT_DLVDS
) {
194 for (i
= 0; i
< 256*3; i
++)
195 gamma_table_base
[i
] = (gamma_table_base
[i
] << 2) |
196 ((gamma_table_base
[i
] >> 6) & 0x03);
200 #define PX_BRDCFG0_DVISEL (1 << 3)
201 #define PX_BRDCFG0_DLINK (1 << 4)
202 #define PX_BRDCFG0_DIU_MASK (PX_BRDCFG0_DVISEL | PX_BRDCFG0_DLINK)
204 void mpc8610hpcd_set_monitor_port(enum fsl_diu_monitor_port port
)
207 case FSL_DIU_PORT_DVI
:
208 clrsetbits_8(pixis_bdcfg0
, PX_BRDCFG0_DIU_MASK
,
209 PX_BRDCFG0_DVISEL
| PX_BRDCFG0_DLINK
);
211 case FSL_DIU_PORT_LVDS
:
212 clrsetbits_8(pixis_bdcfg0
, PX_BRDCFG0_DIU_MASK
,
215 case FSL_DIU_PORT_DLVDS
:
216 clrbits8(pixis_bdcfg0
, PX_BRDCFG0_DIU_MASK
);
222 * mpc8610hpcd_set_pixel_clock: program the DIU's clock
224 * @pixclock: the wavelength, in picoseconds, of the clock
226 void mpc8610hpcd_set_pixel_clock(unsigned int pixclock
)
228 struct device_node
*guts_np
= NULL
;
229 struct ccsr_guts_86xx __iomem
*guts
;
234 /* Map the global utilities registers. */
235 guts_np
= of_find_compatible_node(NULL
, NULL
, "fsl,mpc8610-guts");
237 pr_err("mpc8610hpcd: missing global utilties device node\n");
241 guts
= of_iomap(guts_np
, 0);
242 of_node_put(guts_np
);
244 pr_err("mpc8610hpcd: could not map global utilties device\n");
248 /* Convert pixclock from a wavelength to a frequency */
249 temp
= 1000000000000ULL;
250 do_div(temp
, pixclock
);
254 * 'pxclk' is the ratio of the platform clock to the pixel clock.
255 * On the MPC8610, the value programmed into CLKDVDR is the ratio
256 * minus one. The valid range of values is 2-31.
258 pxclk
= DIV_ROUND_CLOSEST(fsl_get_sys_freq(), freq
) - 1;
259 pxclk
= clamp_t(u32
, pxclk
, 2, 31);
261 /* Disable the pixel clock, and set it to non-inverted and no delay */
262 clrbits32(&guts
->clkdvdr
,
263 CLKDVDR_PXCKEN
| CLKDVDR_PXCKDLY
| CLKDVDR_PXCLK_MASK
);
265 /* Enable the clock and set the pxclk */
266 setbits32(&guts
->clkdvdr
, CLKDVDR_PXCKEN
| (pxclk
<< 16));
271 enum fsl_diu_monitor_port
272 mpc8610hpcd_valid_monitor_port(enum fsl_diu_monitor_port port
)
279 static void __init
mpc86xx_hpcd_setup_arch(void)
282 struct device_node
*np
;
283 unsigned char *pixis
;
286 ppc_md
.progress("mpc86xx_hpcd_setup_arch()", 0);
289 for_each_node_by_type(np
, "pci") {
290 if (of_device_is_compatible(np
, "fsl,mpc8610-pci")
291 || of_device_is_compatible(np
, "fsl,mpc8641-pcie")) {
292 struct resource rsrc
;
293 of_address_to_resource(np
, 0, &rsrc
);
294 if ((rsrc
.start
& 0xfffff) == 0xa000)
295 fsl_add_bridge(np
, 1);
297 fsl_add_bridge(np
, 0);
301 #if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
302 diu_ops
.get_pixel_format
= mpc8610hpcd_get_pixel_format
;
303 diu_ops
.set_gamma_table
= mpc8610hpcd_set_gamma_table
;
304 diu_ops
.set_monitor_port
= mpc8610hpcd_set_monitor_port
;
305 diu_ops
.set_pixel_clock
= mpc8610hpcd_set_pixel_clock
;
306 diu_ops
.valid_monitor_port
= mpc8610hpcd_valid_monitor_port
;
309 pixis_node
= of_find_compatible_node(NULL
, NULL
, "fsl,fpga-pixis");
311 of_address_to_resource(pixis_node
, 0, &r
);
312 of_node_put(pixis_node
);
313 pixis
= ioremap(r
.start
, 32);
315 printk(KERN_ERR
"Err: can't map FPGA cfg register!\n");
318 pixis_bdcfg0
= pixis
+ 8;
319 pixis_arch
= pixis
+ 1;
321 printk(KERN_ERR
"Err: "
322 "can't find device node 'fsl,fpga-pixis'\n");
324 printk("MPC86xx HPCD board from Freescale Semiconductor\n");
328 * Called very early, device-tree isn't unflattened
330 static int __init
mpc86xx_hpcd_probe(void)
332 unsigned long root
= of_get_flat_dt_root();
334 if (of_flat_dt_is_compatible(root
, "fsl,MPC8610HPCD"))
335 return 1; /* Looks good */
340 static long __init
mpc86xx_time_init(void)
344 /* Set the time base to zero */
348 temp
= mfspr(SPRN_HID0
);
350 mtspr(SPRN_HID0
, temp
);
351 asm volatile("isync");
356 define_machine(mpc86xx_hpcd
) {
357 .name
= "MPC86xx HPCD",
358 .probe
= mpc86xx_hpcd_probe
,
359 .setup_arch
= mpc86xx_hpcd_setup_arch
,
360 .init_IRQ
= mpc86xx_init_irq
,
361 .get_irq
= mpic_get_irq
,
362 .restart
= fsl_rstcr_restart
,
363 .time_init
= mpc86xx_time_init
,
364 .calibrate_decr
= generic_calibrate_decr
,
365 .progress
= udbg_progress
,
366 .pcibios_fixup_bus
= fsl_pcibios_fixup_bus
,