]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/powerpc/platforms/85xx/ksi8560.c
[PATCH] fs: add a sanity check in d_free
[linux-2.6-omap-h63xx.git] / arch / powerpc / platforms / 85xx / ksi8560.c
1 /*
2  * Board setup routines for the Emerson KSI8560
3  *
4  * Author: Alexandr Smirnov <asmirnov@ru.mvista.com>
5  *
6  * Based on mpc85xx_ads.c maintained by Kumar Gala
7  *
8  * 2008 (c) MontaVista, Software, Inc.  This file is licensed under
9  * the terms of the GNU General Public License version 2.  This program
10  * is licensed "as is" without any warranty of any kind, whether express
11  * or implied.
12  *
13  */
14
15 #include <linux/stddef.h>
16 #include <linux/kernel.h>
17 #include <linux/pci.h>
18 #include <linux/kdev_t.h>
19 #include <linux/delay.h>
20 #include <linux/seq_file.h>
21 #include <linux/of_platform.h>
22
23 #include <asm/system.h>
24 #include <asm/time.h>
25 #include <asm/machdep.h>
26 #include <asm/pci-bridge.h>
27 #include <asm/mpic.h>
28 #include <mm/mmu_decl.h>
29 #include <asm/udbg.h>
30 #include <asm/prom.h>
31
32 #include <sysdev/fsl_soc.h>
33 #include <sysdev/fsl_pci.h>
34
35 #include <asm/cpm2.h>
36 #include <sysdev/cpm2_pic.h>
37
38
39 #define KSI8560_CPLD_HVR                0x04 /* Hardware Version Register */
40 #define KSI8560_CPLD_PVR                0x08 /* PLD Version Register */
41 #define KSI8560_CPLD_RCR1               0x30 /* Reset Command Register 1 */
42
43 #define KSI8560_CPLD_RCR1_CPUHR         0x80 /* CPU Hard Reset */
44
45 static void __iomem *cpld_base = NULL;
46
47 static void machine_restart(char *cmd)
48 {
49         if (cpld_base)
50                 out_8(cpld_base + KSI8560_CPLD_RCR1, KSI8560_CPLD_RCR1_CPUHR);
51         else
52                 printk(KERN_ERR "Can't find CPLD base, hang forever\n");
53
54         for (;;);
55 }
56
57 static void cpm2_cascade(unsigned int irq, struct irq_desc *desc)
58 {
59         int cascade_irq;
60
61         while ((cascade_irq = cpm2_get_irq()) >= 0)
62                 generic_handle_irq(cascade_irq);
63
64         desc->chip->eoi(irq);
65 }
66
67 static void __init ksi8560_pic_init(void)
68 {
69         struct mpic *mpic;
70         struct resource r;
71         struct device_node *np;
72 #ifdef CONFIG_CPM2
73         int irq;
74 #endif
75
76         np = of_find_node_by_type(NULL, "open-pic");
77
78         if (np == NULL) {
79                 printk(KERN_ERR "Could not find open-pic node\n");
80                 return;
81         }
82
83         if (of_address_to_resource(np, 0, &r)) {
84                 printk(KERN_ERR "Could not map mpic register space\n");
85                 of_node_put(np);
86                 return;
87         }
88
89         mpic = mpic_alloc(np, r.start,
90                         MPIC_PRIMARY | MPIC_WANTS_RESET | MPIC_BIG_ENDIAN,
91                         0, 256, " OpenPIC  ");
92         BUG_ON(mpic == NULL);
93         of_node_put(np);
94
95         mpic_init(mpic);
96
97 #ifdef CONFIG_CPM2
98         /* Setup CPM2 PIC */
99         np = of_find_compatible_node(NULL, NULL, "fsl,cpm2-pic");
100         if (np == NULL) {
101                 printk(KERN_ERR "PIC init: can not find fsl,cpm2-pic node\n");
102                 return;
103         }
104         irq = irq_of_parse_and_map(np, 0);
105
106         cpm2_pic_init(np);
107         of_node_put(np);
108         set_irq_chained_handler(irq, cpm2_cascade);
109
110         setup_irq(0, NULL);
111 #endif
112 }
113
114 #ifdef CONFIG_CPM2
115 /*
116  * Setup I/O ports
117  */
118 struct cpm_pin {
119         int port, pin, flags;
120 };
121
122 static struct cpm_pin __initdata ksi8560_pins[] = {
123         /* SCC1 */
124         {3, 29, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
125         {3, 30, CPM_PIN_OUTPUT | CPM_PIN_SECONDARY},
126         {3, 31, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
127
128         /* SCC2 */
129         {3, 26, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
130         {3, 27, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
131         {3, 28, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
132
133         /* FCC1 */
134         {0, 14, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
135         {0, 15, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
136         {0, 16, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
137         {0, 17, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
138         {0, 18, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
139         {0, 19, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
140         {0, 20, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
141         {0, 21, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
142         {0, 26, CPM_PIN_INPUT | CPM_PIN_SECONDARY},
143         {0, 27, CPM_PIN_INPUT | CPM_PIN_SECONDARY},
144         {0, 28, CPM_PIN_OUTPUT | CPM_PIN_SECONDARY},
145         {0, 29, CPM_PIN_OUTPUT | CPM_PIN_SECONDARY},
146         {0, 30, CPM_PIN_INPUT | CPM_PIN_SECONDARY},
147         {0, 31, CPM_PIN_INPUT | CPM_PIN_SECONDARY},
148         {2, 23, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, /* CLK9 */
149         {2, 22, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, /* CLK10 */
150
151 };
152
153 static void __init init_ioports(void)
154 {
155         int i;
156
157         for (i = 0; i < ARRAY_SIZE(ksi8560_pins); i++) {
158                 struct cpm_pin *pin = &ksi8560_pins[i];
159                 cpm2_set_pin(pin->port, pin->pin, pin->flags);
160         }
161
162         cpm2_clk_setup(CPM_CLK_SCC1, CPM_BRG1, CPM_CLK_RX);
163         cpm2_clk_setup(CPM_CLK_SCC1, CPM_BRG1, CPM_CLK_TX);
164         cpm2_clk_setup(CPM_CLK_SCC2, CPM_BRG2, CPM_CLK_RX);
165         cpm2_clk_setup(CPM_CLK_SCC2, CPM_BRG2, CPM_CLK_TX);
166         cpm2_clk_setup(CPM_CLK_FCC1, CPM_CLK9, CPM_CLK_RX);
167         cpm2_clk_setup(CPM_CLK_FCC1, CPM_CLK10, CPM_CLK_TX);
168 }
169 #endif
170
171 /*
172  * Setup the architecture
173  */
174 static void __init ksi8560_setup_arch(void)
175 {
176         struct device_node *cpld;
177
178         cpld = of_find_compatible_node(NULL, NULL, "emerson,KSI8560-cpld");
179         if (cpld)
180                 cpld_base = of_iomap(cpld, 0);
181         else
182                 printk(KERN_ERR "Can't find CPLD in device tree\n");
183
184         if (ppc_md.progress)
185                 ppc_md.progress("ksi8560_setup_arch()", 0);
186
187 #ifdef CONFIG_CPM2
188         cpm2_reset();
189         init_ioports();
190 #endif
191 }
192
193 static void ksi8560_show_cpuinfo(struct seq_file *m)
194 {
195         uint pvid, svid, phid1;
196         uint memsize = total_memory;
197
198         pvid = mfspr(SPRN_PVR);
199         svid = mfspr(SPRN_SVR);
200
201         seq_printf(m, "Vendor\t\t: Emerson Network Power\n");
202         seq_printf(m, "Board\t\t: KSI8560\n");
203
204         if (cpld_base) {
205                 seq_printf(m, "Hardware rev\t: %d\n",
206                                         in_8(cpld_base + KSI8560_CPLD_HVR));
207                 seq_printf(m, "CPLD rev\t: %d\n",
208                                         in_8(cpld_base + KSI8560_CPLD_PVR));
209         } else
210                 seq_printf(m, "Unknown Hardware and CPLD revs\n");
211
212         seq_printf(m, "PVR\t\t: 0x%x\n", pvid);
213         seq_printf(m, "SVR\t\t: 0x%x\n", svid);
214
215         /* Display cpu Pll setting */
216         phid1 = mfspr(SPRN_HID1);
217         seq_printf(m, "PLL setting\t: 0x%x\n", ((phid1 >> 24) & 0x3f));
218
219         /* Display the amount of memory */
220         seq_printf(m, "Memory\t\t: %d MB\n", memsize / (1024 * 1024));
221 }
222
223 static struct of_device_id __initdata of_bus_ids[] = {
224         { .type = "soc", },
225         { .type = "simple-bus", },
226         { .name = "cpm", },
227         { .name = "localbus", },
228         {},
229 };
230
231 static int __init declare_of_platform_devices(void)
232 {
233         of_platform_bus_probe(NULL, of_bus_ids, NULL);
234
235         return 0;
236 }
237 machine_device_initcall(ksi8560, declare_of_platform_devices);
238
239 /*
240  * Called very early, device-tree isn't unflattened
241  */
242 static int __init ksi8560_probe(void)
243 {
244         unsigned long root = of_get_flat_dt_root();
245
246         return of_flat_dt_is_compatible(root, "emerson,KSI8560");
247 }
248
249 define_machine(ksi8560) {
250         .name                   = "KSI8560",
251         .probe                  = ksi8560_probe,
252         .setup_arch             = ksi8560_setup_arch,
253         .init_IRQ               = ksi8560_pic_init,
254         .show_cpuinfo           = ksi8560_show_cpuinfo,
255         .get_irq                = mpic_get_irq,
256         .restart                = machine_restart,
257         .calibrate_decr         = generic_calibrate_decr,
258 };