Merge branch 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jdelv...
[deliverable/linux.git] / arch / powerpc / platforms / 86xx / gef_sbc310.c
1 /*
2 * GE Fanuc SBC310 board support
3 *
4 * Author: Martyn Welch <martyn.welch@gefanuc.com>
5 *
6 * Copyright 2008 GE Fanuc Intelligent Platforms Embedded Systems, Inc.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 *
13 * Based on: mpc86xx_hpcn.c (MPC86xx HPCN board specific routines)
14 * Copyright 2006 Freescale Semiconductor Inc.
15 *
16 * NEC fixup adapted from arch/mips/pci/fixup-lm2e.c
17 */
18
19 #include <linux/stddef.h>
20 #include <linux/kernel.h>
21 #include <linux/pci.h>
22 #include <linux/kdev_t.h>
23 #include <linux/delay.h>
24 #include <linux/seq_file.h>
25 #include <linux/of_platform.h>
26
27 #include <asm/system.h>
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 <sysdev/fsl_pci.h>
38 #include <sysdev/fsl_soc.h>
39
40 #include "mpc86xx.h"
41 #include "gef_pic.h"
42
43 #undef DEBUG
44
45 #ifdef DEBUG
46 #define DBG (fmt...) do { printk(KERN_ERR "SBC310: " fmt); } while (0)
47 #else
48 #define DBG (fmt...) do { } while (0)
49 #endif
50
51 void __iomem *sbc310_regs;
52
53 static void __init gef_sbc310_init_irq(void)
54 {
55 struct device_node *cascade_node = NULL;
56
57 mpc86xx_init_irq();
58
59 /*
60 * There is a simple interrupt handler in the main FPGA, this needs
61 * to be cascaded into the MPIC
62 */
63 cascade_node = of_find_compatible_node(NULL, NULL, "gef,fpga-pic");
64 if (!cascade_node) {
65 printk(KERN_WARNING "SBC310: No FPGA PIC\n");
66 return;
67 }
68
69 gef_pic_init(cascade_node);
70 of_node_put(cascade_node);
71 }
72
73 static void __init gef_sbc310_setup_arch(void)
74 {
75 struct device_node *regs;
76 #ifdef CONFIG_PCI
77 struct device_node *np;
78
79 for_each_compatible_node(np, "pci", "fsl,mpc8641-pcie") {
80 fsl_add_bridge(np, 1);
81 }
82 #endif
83
84 printk(KERN_INFO "GE Fanuc Intelligent Platforms SBC310 6U VPX SBC\n");
85
86 #ifdef CONFIG_SMP
87 mpc86xx_smp_init();
88 #endif
89
90 /* Remap basic board registers */
91 regs = of_find_compatible_node(NULL, NULL, "gef,fpga-regs");
92 if (regs) {
93 sbc310_regs = of_iomap(regs, 0);
94 if (sbc310_regs == NULL)
95 printk(KERN_WARNING "Unable to map board registers\n");
96 of_node_put(regs);
97 }
98 }
99
100 /* Return the PCB revision */
101 static unsigned int gef_sbc310_get_board_id(void)
102 {
103 unsigned int reg;
104
105 reg = ioread32(sbc310_regs);
106 return reg & 0xff;
107 }
108
109 /* Return the PCB revision */
110 static unsigned int gef_sbc310_get_pcb_rev(void)
111 {
112 unsigned int reg;
113
114 reg = ioread32(sbc310_regs);
115 return (reg >> 8) & 0xff;
116 }
117
118 /* Return the board (software) revision */
119 static unsigned int gef_sbc310_get_board_rev(void)
120 {
121 unsigned int reg;
122
123 reg = ioread32(sbc310_regs);
124 return (reg >> 16) & 0xff;
125 }
126
127 /* Return the FPGA revision */
128 static unsigned int gef_sbc310_get_fpga_rev(void)
129 {
130 unsigned int reg;
131
132 reg = ioread32(sbc310_regs);
133 return (reg >> 24) & 0xf;
134 }
135
136 static void gef_sbc310_show_cpuinfo(struct seq_file *m)
137 {
138 uint svid = mfspr(SPRN_SVR);
139
140 seq_printf(m, "Vendor\t\t: GE Fanuc Intelligent Platforms\n");
141
142 seq_printf(m, "Board ID\t: 0x%2.2x\n", gef_sbc310_get_board_id());
143 seq_printf(m, "Revision\t: %u%c\n", gef_sbc310_get_pcb_rev(),
144 ('A' + gef_sbc310_get_board_rev() - 1));
145 seq_printf(m, "FPGA Revision\t: %u\n", gef_sbc310_get_fpga_rev());
146
147 seq_printf(m, "SVR\t\t: 0x%x\n", svid);
148
149 }
150
151 static void __init gef_sbc310_nec_fixup(struct pci_dev *pdev)
152 {
153 unsigned int val;
154
155 /* Do not do the fixup on other platforms! */
156 if (!machine_is(gef_sbc310))
157 return;
158
159 printk(KERN_INFO "Running NEC uPD720101 Fixup\n");
160
161 /* Ensure only ports 1 & 2 are enabled */
162 pci_read_config_dword(pdev, 0xe0, &val);
163 pci_write_config_dword(pdev, 0xe0, (val & ~7) | 0x2);
164
165 /* System clock is 48-MHz Oscillator and EHCI Enabled. */
166 pci_write_config_dword(pdev, 0xe4, 1 << 5);
167 }
168 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NEC, PCI_DEVICE_ID_NEC_USB,
169 gef_sbc310_nec_fixup);
170
171 /*
172 * Called very early, device-tree isn't unflattened
173 *
174 * This function is called to determine whether the BSP is compatible with the
175 * supplied device-tree, which is assumed to be the correct one for the actual
176 * board. It is expected thati, in the future, a kernel may support multiple
177 * boards.
178 */
179 static int __init gef_sbc310_probe(void)
180 {
181 unsigned long root = of_get_flat_dt_root();
182
183 if (of_flat_dt_is_compatible(root, "gef,sbc310"))
184 return 1;
185
186 return 0;
187 }
188
189 static long __init mpc86xx_time_init(void)
190 {
191 unsigned int temp;
192
193 /* Set the time base to zero */
194 mtspr(SPRN_TBWL, 0);
195 mtspr(SPRN_TBWU, 0);
196
197 temp = mfspr(SPRN_HID0);
198 temp |= HID0_TBEN;
199 mtspr(SPRN_HID0, temp);
200 asm volatile("isync");
201
202 return 0;
203 }
204
205 static __initdata struct of_device_id of_bus_ids[] = {
206 { .compatible = "simple-bus", },
207 { .compatible = "gianfar", },
208 {},
209 };
210
211 static int __init declare_of_platform_devices(void)
212 {
213 printk(KERN_DEBUG "Probe platform devices\n");
214 of_platform_bus_probe(NULL, of_bus_ids, NULL);
215
216 return 0;
217 }
218 machine_device_initcall(gef_sbc310, declare_of_platform_devices);
219
220 define_machine(gef_sbc310) {
221 .name = "GE Fanuc SBC310",
222 .probe = gef_sbc310_probe,
223 .setup_arch = gef_sbc310_setup_arch,
224 .init_IRQ = gef_sbc310_init_irq,
225 .show_cpuinfo = gef_sbc310_show_cpuinfo,
226 .get_irq = mpic_get_irq,
227 .restart = fsl_rstcr_restart,
228 .time_init = mpc86xx_time_init,
229 .calibrate_decr = generic_calibrate_decr,
230 .progress = udbg_progress,
231 #ifdef CONFIG_PCI
232 .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
233 #endif
234 };
This page took 0.035799 seconds and 5 git commands to generate.