1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * MPC8610 HPCD board specific routines
5 * Initial author: Xianghua Xiao <x.xiao@freescale.com>
6 * Recode: Jason Jin <jason.jin@freescale.com>
7 * York Sun <yorksun@freescale.com>
9 * Rewrite the interrupt routing. remove the 8259PIC support,
10 * All the integrated device in ULI use sideband interrupt.
12 * Copyright 2008 Freescale Semiconductor Inc.
15 #include <linux/stddef.h>
16 #include <linux/kernel.h>
17 #include <linux/pci.h>
18 #include <linux/interrupt.h>
19 #include <linux/kdev_t.h>
20 #include <linux/delay.h>
21 #include <linux/seq_file.h>
23 #include <linux/of_address.h>
24 #include <linux/of_irq.h>
25 #include <linux/fsl/guts.h>
28 #include <asm/machdep.h>
29 #include <asm/pci-bridge.h>
30 #include <mm/mmu_decl.h>
35 #include <linux/of_platform.h>
36 #include <sysdev/fsl_pci.h>
37 #include <sysdev/fsl_soc.h>
41 static struct device_node *pixis_node;
42 static unsigned char *pixis_bdcfg0, *pixis_arch;
44 /* DIU Pixel Clock bits of the CLKDVDR Global Utilities register */
45 #define CLKDVDR_PXCKEN 0x80000000
46 #define CLKDVDR_PXCKINV 0x10000000
47 #define CLKDVDR_PXCKDLY 0x06000000
48 #define CLKDVDR_PXCLK_MASK 0x001F0000
51 static irqreturn_t mpc8610_sw9_irq(int irq, void *data)
53 pr_debug("%s: PIXIS' event (sw9/wakeup) IRQ handled\n", __func__);
57 static void __init mpc8610_suspend_init(void)
65 irq = irq_of_parse_and_map(pixis_node, 0);
67 pr_err("%s: can't map pixis event IRQ.\n", __func__);
71 ret = request_irq(irq, mpc8610_sw9_irq, 0, "sw9:wakeup", NULL);
73 pr_err("%s: can't request pixis event IRQ: %d\n",
75 irq_dispose_mapping(irq);
81 static inline void mpc8610_suspend_init(void) { }
82 #endif /* CONFIG_SUSPEND */
84 static const struct of_device_id mpc8610_ids[] __initconst = {
85 { .compatible = "fsl,mpc8610-immr", },
86 { .compatible = "fsl,mpc8610-guts", },
87 /* So that the DMA channel nodes can be probed individually: */
88 { .compatible = "fsl,eloplus-dma", },
90 { .compatible = "fsl,mpc8610-pci", },
94 static int __init mpc8610_declare_of_platform_devices(void)
96 /* Enable wakeup on PIXIS' event IRQ. */
97 mpc8610_suspend_init();
99 mpc86xx_common_publish_devices();
101 /* Without this call, the SSI device driver won't get probed. */
102 of_platform_bus_probe(NULL, mpc8610_ids, NULL);
106 machine_arch_initcall(mpc86xx_hpcd, mpc8610_declare_of_platform_devices);
108 #if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
111 * DIU Area Descriptor
113 * The MPC8610 reference manual shows the bits of the AD register in
114 * little-endian order, which causes the BLUE_C field to be split into two
115 * parts. To simplify the definition of the MAKE_AD() macro, we define the
116 * fields in big-endian order and byte-swap the result.
118 * So even though the registers don't look like they're in the
119 * same bit positions as they are on the P1022, the same value is written to
120 * the AD register on the MPC8610 and on the P1022.
122 #define AD_BYTE_F 0x10000000
123 #define AD_ALPHA_C_MASK 0x0E000000
124 #define AD_ALPHA_C_SHIFT 25
125 #define AD_BLUE_C_MASK 0x01800000
126 #define AD_BLUE_C_SHIFT 23
127 #define AD_GREEN_C_MASK 0x00600000
128 #define AD_GREEN_C_SHIFT 21
129 #define AD_RED_C_MASK 0x00180000
130 #define AD_RED_C_SHIFT 19
131 #define AD_PALETTE 0x00040000
132 #define AD_PIXEL_S_MASK 0x00030000
133 #define AD_PIXEL_S_SHIFT 16
134 #define AD_COMP_3_MASK 0x0000F000
135 #define AD_COMP_3_SHIFT 12
136 #define AD_COMP_2_MASK 0x00000F00
137 #define AD_COMP_2_SHIFT 8
138 #define AD_COMP_1_MASK 0x000000F0
139 #define AD_COMP_1_SHIFT 4
140 #define AD_COMP_0_MASK 0x0000000F
141 #define AD_COMP_0_SHIFT 0
143 #define MAKE_AD(alpha, red, blue, green, size, c0, c1, c2, c3) \
144 cpu_to_le32(AD_BYTE_F | (alpha << AD_ALPHA_C_SHIFT) | \
145 (blue << AD_BLUE_C_SHIFT) | (green << AD_GREEN_C_SHIFT) | \
146 (red << AD_RED_C_SHIFT) | (c3 << AD_COMP_3_SHIFT) | \
147 (c2 << AD_COMP_2_SHIFT) | (c1 << AD_COMP_1_SHIFT) | \
148 (c0 << AD_COMP_0_SHIFT) | (size << AD_PIXEL_S_SHIFT))
150 u32 mpc8610hpcd_get_pixel_format(enum fsl_diu_monitor_port port,
151 unsigned int bits_per_pixel)
153 static const u32 pixelformat[][3] = {
155 MAKE_AD(3, 0, 2, 1, 3, 8, 8, 8, 8),
156 MAKE_AD(4, 2, 0, 1, 2, 8, 8, 8, 0),
157 MAKE_AD(4, 0, 2, 1, 1, 5, 6, 5, 0)
160 MAKE_AD(3, 2, 0, 1, 3, 8, 8, 8, 8),
161 MAKE_AD(4, 0, 2, 1, 2, 8, 8, 8, 0),
162 MAKE_AD(4, 2, 0, 1, 1, 5, 6, 5, 0)
165 unsigned int arch_monitor;
167 /* The DVI port is mis-wired on revision 1 of this board. */
169 ((*pixis_arch == 0x01) && (port == FSL_DIU_PORT_DVI)) ? 0 : 1;
171 switch (bits_per_pixel) {
173 return pixelformat[arch_monitor][0];
175 return pixelformat[arch_monitor][1];
177 return pixelformat[arch_monitor][2];
179 pr_err("fsl-diu: unsupported pixel depth %u\n", bits_per_pixel);
184 void mpc8610hpcd_set_gamma_table(enum fsl_diu_monitor_port port,
185 char *gamma_table_base)
188 if (port == FSL_DIU_PORT_DLVDS) {
189 for (i = 0; i < 256*3; i++)
190 gamma_table_base[i] = (gamma_table_base[i] << 2) |
191 ((gamma_table_base[i] >> 6) & 0x03);
195 #define PX_BRDCFG0_DVISEL (1 << 3)
196 #define PX_BRDCFG0_DLINK (1 << 4)
197 #define PX_BRDCFG0_DIU_MASK (PX_BRDCFG0_DVISEL | PX_BRDCFG0_DLINK)
199 void mpc8610hpcd_set_monitor_port(enum fsl_diu_monitor_port port)
202 case FSL_DIU_PORT_DVI:
203 clrsetbits_8(pixis_bdcfg0, PX_BRDCFG0_DIU_MASK,
204 PX_BRDCFG0_DVISEL | PX_BRDCFG0_DLINK);
206 case FSL_DIU_PORT_LVDS:
207 clrsetbits_8(pixis_bdcfg0, PX_BRDCFG0_DIU_MASK,
210 case FSL_DIU_PORT_DLVDS:
211 clrbits8(pixis_bdcfg0, PX_BRDCFG0_DIU_MASK);
217 * mpc8610hpcd_set_pixel_clock: program the DIU's clock
219 * @pixclock: the wavelength, in picoseconds, of the clock
221 void mpc8610hpcd_set_pixel_clock(unsigned int pixclock)
223 struct device_node *guts_np = NULL;
224 struct ccsr_guts __iomem *guts;
229 /* Map the global utilities registers. */
230 guts_np = of_find_compatible_node(NULL, NULL, "fsl,mpc8610-guts");
232 pr_err("mpc8610hpcd: missing global utilities device node\n");
236 guts = of_iomap(guts_np, 0);
237 of_node_put(guts_np);
239 pr_err("mpc8610hpcd: could not map global utilities device\n");
243 /* Convert pixclock from a wavelength to a frequency */
244 temp = 1000000000000ULL;
245 do_div(temp, pixclock);
249 * 'pxclk' is the ratio of the platform clock to the pixel clock.
250 * On the MPC8610, the value programmed into CLKDVDR is the ratio
251 * minus one. The valid range of values is 2-31.
253 pxclk = DIV_ROUND_CLOSEST(fsl_get_sys_freq(), freq) - 1;
254 pxclk = clamp_t(u32, pxclk, 2, 31);
256 /* Disable the pixel clock, and set it to non-inverted and no delay */
257 clrbits32(&guts->clkdvdr,
258 CLKDVDR_PXCKEN | CLKDVDR_PXCKDLY | CLKDVDR_PXCLK_MASK);
260 /* Enable the clock and set the pxclk */
261 setbits32(&guts->clkdvdr, CLKDVDR_PXCKEN | (pxclk << 16));
266 enum fsl_diu_monitor_port
267 mpc8610hpcd_valid_monitor_port(enum fsl_diu_monitor_port port)
274 static void __init mpc86xx_hpcd_setup_arch(void)
277 unsigned char *pixis;
280 ppc_md.progress("mpc86xx_hpcd_setup_arch()", 0);
282 fsl_pci_assign_primary();
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.valid_monitor_port = mpc8610hpcd_valid_monitor_port;
292 pixis_node = of_find_compatible_node(NULL, NULL, "fsl,fpga-pixis");
294 of_address_to_resource(pixis_node, 0, &r);
295 of_node_put(pixis_node);
296 pixis = ioremap(r.start, 32);
298 printk(KERN_ERR "Err: can't map FPGA cfg register!\n");
301 pixis_bdcfg0 = pixis + 8;
302 pixis_arch = pixis + 1;
304 printk(KERN_ERR "Err: "
305 "can't find device node 'fsl,fpga-pixis'\n");
307 printk("MPC86xx HPCD board from Freescale Semiconductor\n");
311 * Called very early, device-tree isn't unflattened
313 static int __init mpc86xx_hpcd_probe(void)
315 if (of_machine_is_compatible("fsl,MPC8610HPCD"))
316 return 1; /* Looks good */
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 .time_init = mpc86xx_time_init,
328 .calibrate_decr = generic_calibrate_decr,
329 .progress = udbg_progress,
331 .pcibios_fixup_bus = fsl_pcibios_fixup_bus,