• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
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>
26 #include <linux/of.h>
27 
28 #include <asm/time.h>
29 #include <asm/machdep.h>
30 #include <asm/pci-bridge.h>
31 #include <asm/prom.h>
32 #include <mm/mmu_decl.h>
33 #include <asm/udbg.h>
34 
35 #include <asm/mpic.h>
36 
37 #include <linux/of_platform.h>
38 #include <sysdev/fsl_pci.h>
39 #include <sysdev/fsl_soc.h>
40 #include <sysdev/simple_gpio.h>
41 #include <asm/fsl_guts.h>
42 
43 #include "mpc86xx.h"
44 
45 static struct device_node *pixis_node;
46 static unsigned char *pixis_bdcfg0, *pixis_arch;
47 
48 /* DIU Pixel Clock bits of the CLKDVDR Global Utilities register */
49 #define CLKDVDR_PXCKEN		0x80000000
50 #define CLKDVDR_PXCKINV		0x10000000
51 #define CLKDVDR_PXCKDLY		0x06000000
52 #define CLKDVDR_PXCLK_MASK	0x001F0000
53 
54 #ifdef CONFIG_SUSPEND
mpc8610_sw9_irq(int irq,void * data)55 static irqreturn_t mpc8610_sw9_irq(int irq, void *data)
56 {
57 	pr_debug("%s: PIXIS' event (sw9/wakeup) IRQ handled\n", __func__);
58 	return IRQ_HANDLED;
59 }
60 
mpc8610_suspend_init(void)61 static void __init mpc8610_suspend_init(void)
62 {
63 	int irq;
64 	int ret;
65 
66 	if (!pixis_node)
67 		return;
68 
69 	irq = irq_of_parse_and_map(pixis_node, 0);
70 	if (!irq) {
71 		pr_err("%s: can't map pixis event IRQ.\n", __func__);
72 		return;
73 	}
74 
75 	ret = request_irq(irq, mpc8610_sw9_irq, 0, "sw9:wakeup", NULL);
76 	if (ret) {
77 		pr_err("%s: can't request pixis event IRQ: %d\n",
78 		       __func__, ret);
79 		irq_dispose_mapping(irq);
80 	}
81 
82 	enable_irq_wake(irq);
83 }
84 #else
mpc8610_suspend_init(void)85 static inline void mpc8610_suspend_init(void) { }
86 #endif /* CONFIG_SUSPEND */
87 
88 static struct of_device_id __initdata mpc8610_ids[] = {
89 	{ .compatible = "fsl,mpc8610-immr", },
90 	{ .compatible = "fsl,mpc8610-guts", },
91 	{ .compatible = "simple-bus", },
92 	/* So that the DMA channel nodes can be probed individually: */
93 	{ .compatible = "fsl,eloplus-dma", },
94 	{}
95 };
96 
mpc8610_declare_of_platform_devices(void)97 static int __init mpc8610_declare_of_platform_devices(void)
98 {
99 	/* Firstly, register PIXIS GPIOs. */
100 	simple_gpiochip_init("fsl,fpga-pixis-gpio-bank");
101 
102 	/* Enable wakeup on PIXIS' event IRQ. */
103 	mpc8610_suspend_init();
104 
105 	/* Without this call, the SSI device driver won't get probed. */
106 	of_platform_bus_probe(NULL, mpc8610_ids, NULL);
107 
108 	return 0;
109 }
110 machine_device_initcall(mpc86xx_hpcd, mpc8610_declare_of_platform_devices);
111 
112 #if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
113 
114 /*
115  * DIU Area Descriptor
116  *
117  * The MPC8610 reference manual shows the bits of the AD register in
118  * little-endian order, which causes the BLUE_C field to be split into two
119  * parts. To simplify the definition of the MAKE_AD() macro, we define the
120  * fields in big-endian order and byte-swap the result.
121  *
122  * So even though the registers don't look like they're in the
123  * same bit positions as they are on the P1022, the same value is written to
124  * the AD register on the MPC8610 and on the P1022.
125  */
126 #define AD_BYTE_F		0x10000000
127 #define AD_ALPHA_C_MASK		0x0E000000
128 #define AD_ALPHA_C_SHIFT	25
129 #define AD_BLUE_C_MASK		0x01800000
130 #define AD_BLUE_C_SHIFT		23
131 #define AD_GREEN_C_MASK		0x00600000
132 #define AD_GREEN_C_SHIFT	21
133 #define AD_RED_C_MASK		0x00180000
134 #define AD_RED_C_SHIFT		19
135 #define AD_PALETTE		0x00040000
136 #define AD_PIXEL_S_MASK		0x00030000
137 #define AD_PIXEL_S_SHIFT	16
138 #define AD_COMP_3_MASK		0x0000F000
139 #define AD_COMP_3_SHIFT		12
140 #define AD_COMP_2_MASK		0x00000F00
141 #define AD_COMP_2_SHIFT		8
142 #define AD_COMP_1_MASK		0x000000F0
143 #define AD_COMP_1_SHIFT		4
144 #define AD_COMP_0_MASK		0x0000000F
145 #define AD_COMP_0_SHIFT		0
146 
147 #define MAKE_AD(alpha, red, blue, green, size, c0, c1, c2, c3) \
148 	cpu_to_le32(AD_BYTE_F | (alpha << AD_ALPHA_C_SHIFT) | \
149 	(blue << AD_BLUE_C_SHIFT) | (green << AD_GREEN_C_SHIFT) | \
150 	(red << AD_RED_C_SHIFT) | (c3 << AD_COMP_3_SHIFT) | \
151 	(c2 << AD_COMP_2_SHIFT) | (c1 << AD_COMP_1_SHIFT) | \
152 	(c0 << AD_COMP_0_SHIFT) | (size << AD_PIXEL_S_SHIFT))
153 
mpc8610hpcd_get_pixel_format(enum fsl_diu_monitor_port port,unsigned int bits_per_pixel)154 u32 mpc8610hpcd_get_pixel_format(enum fsl_diu_monitor_port port,
155 				 unsigned int bits_per_pixel)
156 {
157 	static const u32 pixelformat[][3] = {
158 		{
159 			MAKE_AD(3, 0, 2, 1, 3, 8, 8, 8, 8),
160 			MAKE_AD(4, 2, 0, 1, 2, 8, 8, 8, 0),
161 			MAKE_AD(4, 0, 2, 1, 1, 5, 6, 5, 0)
162 		},
163 		{
164 			MAKE_AD(3, 2, 0, 1, 3, 8, 8, 8, 8),
165 			MAKE_AD(4, 0, 2, 1, 2, 8, 8, 8, 0),
166 			MAKE_AD(4, 2, 0, 1, 1, 5, 6, 5, 0)
167 		},
168 	};
169 	unsigned int arch_monitor;
170 
171 	/* The DVI port is mis-wired on revision 1 of this board. */
172 	arch_monitor =
173 		((*pixis_arch == 0x01) && (port == FSL_DIU_PORT_DVI)) ? 0 : 1;
174 
175 	switch (bits_per_pixel) {
176 	case 32:
177 		return pixelformat[arch_monitor][0];
178 	case 24:
179 		return pixelformat[arch_monitor][1];
180 	case 16:
181 		return pixelformat[arch_monitor][2];
182 	default:
183 		pr_err("fsl-diu: unsupported pixel depth %u\n", bits_per_pixel);
184 		return 0;
185 	}
186 }
187 
mpc8610hpcd_set_gamma_table(enum fsl_diu_monitor_port port,char * gamma_table_base)188 void mpc8610hpcd_set_gamma_table(enum fsl_diu_monitor_port port,
189 				 char *gamma_table_base)
190 {
191 	int i;
192 	if (port == FSL_DIU_PORT_DLVDS) {
193 		for (i = 0; i < 256*3; i++)
194 			gamma_table_base[i] = (gamma_table_base[i] << 2) |
195 					 ((gamma_table_base[i] >> 6) & 0x03);
196 	}
197 }
198 
199 #define PX_BRDCFG0_DVISEL	(1 << 3)
200 #define PX_BRDCFG0_DLINK	(1 << 4)
201 #define PX_BRDCFG0_DIU_MASK	(PX_BRDCFG0_DVISEL | PX_BRDCFG0_DLINK)
202 
mpc8610hpcd_set_monitor_port(enum fsl_diu_monitor_port port)203 void mpc8610hpcd_set_monitor_port(enum fsl_diu_monitor_port port)
204 {
205 	switch (port) {
206 	case FSL_DIU_PORT_DVI:
207 		clrsetbits_8(pixis_bdcfg0, PX_BRDCFG0_DIU_MASK,
208 			     PX_BRDCFG0_DVISEL | PX_BRDCFG0_DLINK);
209 		break;
210 	case FSL_DIU_PORT_LVDS:
211 		clrsetbits_8(pixis_bdcfg0, PX_BRDCFG0_DIU_MASK,
212 			     PX_BRDCFG0_DLINK);
213 		break;
214 	case FSL_DIU_PORT_DLVDS:
215 		clrbits8(pixis_bdcfg0, PX_BRDCFG0_DIU_MASK);
216 		break;
217 	}
218 }
219 
220 /**
221  * mpc8610hpcd_set_pixel_clock: program the DIU's clock
222  *
223  * @pixclock: the wavelength, in picoseconds, of the clock
224  */
mpc8610hpcd_set_pixel_clock(unsigned int pixclock)225 void mpc8610hpcd_set_pixel_clock(unsigned int pixclock)
226 {
227 	struct device_node *guts_np = NULL;
228 	struct ccsr_guts __iomem *guts;
229 	unsigned long freq;
230 	u64 temp;
231 	u32 pxclk;
232 
233 	/* Map the global utilities registers. */
234 	guts_np = of_find_compatible_node(NULL, NULL, "fsl,mpc8610-guts");
235 	if (!guts_np) {
236 		pr_err("mpc8610hpcd: missing global utilties device node\n");
237 		return;
238 	}
239 
240 	guts = of_iomap(guts_np, 0);
241 	of_node_put(guts_np);
242 	if (!guts) {
243 		pr_err("mpc8610hpcd: could not map global utilties device\n");
244 		return;
245 	}
246 
247 	/* Convert pixclock from a wavelength to a frequency */
248 	temp = 1000000000000ULL;
249 	do_div(temp, pixclock);
250 	freq = temp;
251 
252 	/*
253 	 * 'pxclk' is the ratio of the platform clock to the pixel clock.
254 	 * On the MPC8610, the value programmed into CLKDVDR is the ratio
255 	 * minus one.  The valid range of values is 2-31.
256 	 */
257 	pxclk = DIV_ROUND_CLOSEST(fsl_get_sys_freq(), freq) - 1;
258 	pxclk = clamp_t(u32, pxclk, 2, 31);
259 
260 	/* Disable the pixel clock, and set it to non-inverted and no delay */
261 	clrbits32(&guts->clkdvdr,
262 		  CLKDVDR_PXCKEN | CLKDVDR_PXCKDLY | CLKDVDR_PXCLK_MASK);
263 
264 	/* Enable the clock and set the pxclk */
265 	setbits32(&guts->clkdvdr, CLKDVDR_PXCKEN | (pxclk << 16));
266 
267 	iounmap(guts);
268 }
269 
270 enum fsl_diu_monitor_port
mpc8610hpcd_valid_monitor_port(enum fsl_diu_monitor_port port)271 mpc8610hpcd_valid_monitor_port(enum fsl_diu_monitor_port port)
272 {
273 	return port;
274 }
275 
276 #endif
277 
mpc86xx_hpcd_setup_arch(void)278 static void __init mpc86xx_hpcd_setup_arch(void)
279 {
280 	struct resource r;
281 	struct device_node *np;
282 	unsigned char *pixis;
283 
284 	if (ppc_md.progress)
285 		ppc_md.progress("mpc86xx_hpcd_setup_arch()", 0);
286 
287 #ifdef CONFIG_PCI
288 	for_each_node_by_type(np, "pci") {
289 		if (of_device_is_compatible(np, "fsl,mpc8610-pci")
290 		    || of_device_is_compatible(np, "fsl,mpc8641-pcie")) {
291 			struct resource rsrc;
292 			of_address_to_resource(np, 0, &rsrc);
293 			if ((rsrc.start & 0xfffff) == 0xa000)
294 				fsl_add_bridge(np, 1);
295 			else
296 				fsl_add_bridge(np, 0);
297 		}
298         }
299 #endif
300 #if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
301 	diu_ops.get_pixel_format	= mpc8610hpcd_get_pixel_format;
302 	diu_ops.set_gamma_table		= mpc8610hpcd_set_gamma_table;
303 	diu_ops.set_monitor_port	= mpc8610hpcd_set_monitor_port;
304 	diu_ops.set_pixel_clock		= mpc8610hpcd_set_pixel_clock;
305 	diu_ops.valid_monitor_port	= mpc8610hpcd_valid_monitor_port;
306 #endif
307 
308 	pixis_node = of_find_compatible_node(NULL, NULL, "fsl,fpga-pixis");
309 	if (pixis_node) {
310 		of_address_to_resource(pixis_node, 0, &r);
311 		of_node_put(pixis_node);
312 		pixis = ioremap(r.start, 32);
313 		if (!pixis) {
314 			printk(KERN_ERR "Err: can't map FPGA cfg register!\n");
315 			return;
316 		}
317 		pixis_bdcfg0 = pixis + 8;
318 		pixis_arch = pixis + 1;
319 	} else
320 		printk(KERN_ERR "Err: "
321 				"can't find device node 'fsl,fpga-pixis'\n");
322 
323 	printk("MPC86xx HPCD board from Freescale Semiconductor\n");
324 }
325 
326 /*
327  * Called very early, device-tree isn't unflattened
328  */
mpc86xx_hpcd_probe(void)329 static int __init mpc86xx_hpcd_probe(void)
330 {
331 	unsigned long root = of_get_flat_dt_root();
332 
333 	if (of_flat_dt_is_compatible(root, "fsl,MPC8610HPCD"))
334 		return 1;	/* Looks good */
335 
336 	return 0;
337 }
338 
mpc86xx_time_init(void)339 static long __init mpc86xx_time_init(void)
340 {
341 	unsigned int temp;
342 
343 	/* Set the time base to zero */
344 	mtspr(SPRN_TBWL, 0);
345 	mtspr(SPRN_TBWU, 0);
346 
347 	temp = mfspr(SPRN_HID0);
348 	temp |= HID0_TBEN;
349 	mtspr(SPRN_HID0, temp);
350 	asm volatile("isync");
351 
352 	return 0;
353 }
354 
define_machine(mpc86xx_hpcd)355 define_machine(mpc86xx_hpcd) {
356 	.name			= "MPC86xx HPCD",
357 	.probe			= mpc86xx_hpcd_probe,
358 	.setup_arch		= mpc86xx_hpcd_setup_arch,
359 	.init_IRQ		= mpc86xx_init_irq,
360 	.get_irq		= mpic_get_irq,
361 	.restart		= fsl_rstcr_restart,
362 	.time_init		= mpc86xx_time_init,
363 	.calibrate_decr		= generic_calibrate_decr,
364 	.progress		= udbg_progress,
365 	.pcibios_fixup_bus	= fsl_pcibios_fixup_bus,
366 };
367