nfsd4: typo logical vs bitwise negate for want_mask
[linux-btrfs-devel.git] / arch / powerpc / platforms / 86xx / mpc8610_hpcd.c
blob74e018ef724b0acc0aed5574e0bc483f2be37b83
1 /*
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>
26 #include <linux/of.h>
28 #include <asm/system.h>
29 #include <asm/time.h>
30 #include <asm/machdep.h>
31 #include <asm/pci-bridge.h>
32 #include <asm/prom.h>
33 #include <mm/mmu_decl.h>
34 #include <asm/udbg.h>
36 #include <asm/mpic.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>
44 #include "mpc86xx.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
55 #ifdef CONFIG_SUSPEND
56 static irqreturn_t mpc8610_sw9_irq(int irq, void *data)
58 pr_debug("%s: PIXIS' event (sw9/wakeup) IRQ handled\n", __func__);
59 return IRQ_HANDLED;
62 static void __init mpc8610_suspend_init(void)
64 int irq;
65 int ret;
67 if (!pixis_node)
68 return;
70 irq = irq_of_parse_and_map(pixis_node, 0);
71 if (!irq) {
72 pr_err("%s: can't map pixis event IRQ.\n", __func__);
73 return;
76 ret = request_irq(irq, mpc8610_sw9_irq, 0, "sw9:wakeup", NULL);
77 if (ret) {
78 pr_err("%s: can't request pixis event IRQ: %d\n",
79 __func__, ret);
80 irq_dispose_mapping(irq);
83 enable_irq_wake(irq);
85 #else
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);
109 return 0;
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 unsigned int mpc8610hpcd_get_pixel_format(unsigned int bits_per_pixel,
156 int monitor_port)
158 static const unsigned long 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. */
173 arch_monitor = ((*pixis_arch == 0x01) && (monitor_port == 0))? 0 : 1;
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;
188 void mpc8610hpcd_set_gamma_table(int monitor_port, char *gamma_table_base)
190 int i;
191 if (monitor_port == 2) { /* dual link LVDS */
192 for (i = 0; i < 256*3; i++)
193 gamma_table_base[i] = (gamma_table_base[i] << 2) |
194 ((gamma_table_base[i] >> 6) & 0x03);
198 #define PX_BRDCFG0_DVISEL (1 << 3)
199 #define PX_BRDCFG0_DLINK (1 << 4)
200 #define PX_BRDCFG0_DIU_MASK (PX_BRDCFG0_DVISEL | PX_BRDCFG0_DLINK)
202 void mpc8610hpcd_set_monitor_port(int monitor_port)
204 static const u8 bdcfg[] = {
205 PX_BRDCFG0_DVISEL | PX_BRDCFG0_DLINK,
206 PX_BRDCFG0_DLINK,
210 if (monitor_port < 3)
211 clrsetbits_8(pixis_bdcfg0, PX_BRDCFG0_DIU_MASK,
212 bdcfg[monitor_port]);
216 * mpc8610hpcd_set_pixel_clock: program the DIU's clock
218 * @pixclock: the wavelength, in picoseconds, of the clock
220 void mpc8610hpcd_set_pixel_clock(unsigned int pixclock)
222 struct device_node *guts_np = NULL;
223 struct ccsr_guts_86xx __iomem *guts;
224 unsigned long freq;
225 u64 temp;
226 u32 pxclk;
228 /* Map the global utilities registers. */
229 guts_np = of_find_compatible_node(NULL, NULL, "fsl,mpc8610-guts");
230 if (!guts_np) {
231 pr_err("mpc8610hpcd: missing global utilties device node\n");
232 return;
235 guts = of_iomap(guts_np, 0);
236 of_node_put(guts_np);
237 if (!guts) {
238 pr_err("mpc8610hpcd: could not map global utilties device\n");
239 return;
242 /* Convert pixclock from a wavelength to a frequency */
243 temp = 1000000000000ULL;
244 do_div(temp, pixclock);
245 freq = temp;
248 * 'pxclk' is the ratio of the platform clock to the pixel clock.
249 * On the MPC8610, the value programmed into CLKDVDR is the ratio
250 * minus one. The valid range of values is 2-31.
252 pxclk = DIV_ROUND_CLOSEST(fsl_get_sys_freq(), freq) - 1;
253 pxclk = clamp_t(u32, pxclk, 2, 31);
255 /* Disable the pixel clock, and set it to non-inverted and no delay */
256 clrbits32(&guts->clkdvdr,
257 CLKDVDR_PXCKEN | CLKDVDR_PXCKDLY | CLKDVDR_PXCLK_MASK);
259 /* Enable the clock and set the pxclk */
260 setbits32(&guts->clkdvdr, CLKDVDR_PXCKEN | (pxclk << 16));
262 iounmap(guts);
265 ssize_t mpc8610hpcd_show_monitor_port(int monitor_port, char *buf)
267 return snprintf(buf, PAGE_SIZE,
268 "%c0 - DVI\n"
269 "%c1 - Single link LVDS\n"
270 "%c2 - Dual link LVDS\n",
271 monitor_port == 0 ? '*' : ' ',
272 monitor_port == 1 ? '*' : ' ',
273 monitor_port == 2 ? '*' : ' ');
276 int mpc8610hpcd_set_sysfs_monitor_port(int val)
278 return val < 3 ? val : 0;
281 #endif
283 static void __init mpc86xx_hpcd_setup_arch(void)
285 struct resource r;
286 struct device_node *np;
287 unsigned char *pixis;
289 if (ppc_md.progress)
290 ppc_md.progress("mpc86xx_hpcd_setup_arch()", 0);
292 #ifdef CONFIG_PCI
293 for_each_node_by_type(np, "pci") {
294 if (of_device_is_compatible(np, "fsl,mpc8610-pci")
295 || of_device_is_compatible(np, "fsl,mpc8641-pcie")) {
296 struct resource rsrc;
297 of_address_to_resource(np, 0, &rsrc);
298 if ((rsrc.start & 0xfffff) == 0xa000)
299 fsl_add_bridge(np, 1);
300 else
301 fsl_add_bridge(np, 0);
304 #endif
305 #if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
306 diu_ops.get_pixel_format = mpc8610hpcd_get_pixel_format;
307 diu_ops.set_gamma_table = mpc8610hpcd_set_gamma_table;
308 diu_ops.set_monitor_port = mpc8610hpcd_set_monitor_port;
309 diu_ops.set_pixel_clock = mpc8610hpcd_set_pixel_clock;
310 diu_ops.show_monitor_port = mpc8610hpcd_show_monitor_port;
311 diu_ops.set_sysfs_monitor_port = mpc8610hpcd_set_sysfs_monitor_port;
312 #endif
314 pixis_node = of_find_compatible_node(NULL, NULL, "fsl,fpga-pixis");
315 if (pixis_node) {
316 of_address_to_resource(pixis_node, 0, &r);
317 of_node_put(pixis_node);
318 pixis = ioremap(r.start, 32);
319 if (!pixis) {
320 printk(KERN_ERR "Err: can't map FPGA cfg register!\n");
321 return;
323 pixis_bdcfg0 = pixis + 8;
324 pixis_arch = pixis + 1;
325 } else
326 printk(KERN_ERR "Err: "
327 "can't find device node 'fsl,fpga-pixis'\n");
329 printk("MPC86xx HPCD board from Freescale Semiconductor\n");
333 * Called very early, device-tree isn't unflattened
335 static int __init mpc86xx_hpcd_probe(void)
337 unsigned long root = of_get_flat_dt_root();
339 if (of_flat_dt_is_compatible(root, "fsl,MPC8610HPCD"))
340 return 1; /* Looks good */
342 return 0;
345 static long __init mpc86xx_time_init(void)
347 unsigned int temp;
349 /* Set the time base to zero */
350 mtspr(SPRN_TBWL, 0);
351 mtspr(SPRN_TBWU, 0);
353 temp = mfspr(SPRN_HID0);
354 temp |= HID0_TBEN;
355 mtspr(SPRN_HID0, temp);
356 asm volatile("isync");
358 return 0;
361 define_machine(mpc86xx_hpcd) {
362 .name = "MPC86xx HPCD",
363 .probe = mpc86xx_hpcd_probe,
364 .setup_arch = mpc86xx_hpcd_setup_arch,
365 .init_IRQ = mpc86xx_init_irq,
366 .get_irq = mpic_get_irq,
367 .restart = fsl_rstcr_restart,
368 .time_init = mpc86xx_time_init,
369 .calibrate_decr = generic_calibrate_decr,
370 .progress = udbg_progress,
371 .pcibios_fixup_bus = fsl_pcibios_fixup_bus,