]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - arch/ppc/platforms/4xx/ebony.c
[ATM]: Fix dereference of uninitialized pointer in zatm
[mirror_ubuntu-bionic-kernel.git] / arch / ppc / platforms / 4xx / ebony.c
1 /*
2 * arch/ppc/platforms/4xx/ebony.c
3 *
4 * Ebony board specific routines
5 *
6 * Matt Porter <mporter@kernel.crashing.org>
7 * Copyright 2002-2005 MontaVista Software Inc.
8 *
9 * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
10 * Copyright (c) 2003-2005 Zultys Technologies
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version.
16 */
17
18 #include <linux/config.h>
19 #include <linux/stddef.h>
20 #include <linux/kernel.h>
21 #include <linux/init.h>
22 #include <linux/errno.h>
23 #include <linux/reboot.h>
24 #include <linux/pci.h>
25 #include <linux/kdev_t.h>
26 #include <linux/types.h>
27 #include <linux/major.h>
28 #include <linux/blkdev.h>
29 #include <linux/console.h>
30 #include <linux/delay.h>
31 #include <linux/ide.h>
32 #include <linux/initrd.h>
33 #include <linux/irq.h>
34 #include <linux/seq_file.h>
35 #include <linux/root_dev.h>
36 #include <linux/tty.h>
37 #include <linux/serial.h>
38 #include <linux/serial_core.h>
39
40 #include <asm/system.h>
41 #include <asm/pgtable.h>
42 #include <asm/page.h>
43 #include <asm/dma.h>
44 #include <asm/io.h>
45 #include <asm/machdep.h>
46 #include <asm/ocp.h>
47 #include <asm/pci-bridge.h>
48 #include <asm/time.h>
49 #include <asm/todc.h>
50 #include <asm/bootinfo.h>
51 #include <asm/ppc4xx_pic.h>
52 #include <asm/ppcboot.h>
53 #include <asm/tlbflush.h>
54
55 #include <syslib/gen550.h>
56 #include <syslib/ibm440gp_common.h>
57
58 /*
59 * This is a horrible kludge, we eventually need to abstract this
60 * generic PHY stuff, so the standard phy mode defines can be
61 * easily used from arch code.
62 */
63 #include "../../../../drivers/net/ibm_emac/ibm_emac_phy.h"
64
65 bd_t __res;
66
67 static struct ibm44x_clocks clocks __initdata;
68
69 /*
70 * Ebony external IRQ triggering/polarity settings
71 */
72 unsigned char ppc4xx_uic_ext_irq_cfg[] __initdata = {
73 (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* IRQ0: PCI slot 0 */
74 (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* IRQ1: PCI slot 1 */
75 (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* IRQ2: PCI slot 2 */
76 (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* IRQ3: PCI slot 3 */
77 (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* IRQ4: IRDA */
78 (IRQ_SENSE_EDGE | IRQ_POLARITY_NEGATIVE), /* IRQ5: SMI pushbutton */
79 (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* IRQ6: PHYs */
80 (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* IRQ7: AUX */
81 (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* IRQ8: EXT */
82 (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* IRQ9: EXT */
83 (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* IRQ10: EXT */
84 (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* IRQ11: EXT */
85 (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* IRQ12: EXT */
86 };
87
88 static void __init
89 ebony_calibrate_decr(void)
90 {
91 unsigned int freq;
92
93 /*
94 * Determine system clock speed
95 *
96 * If we are on Rev. B silicon, then use
97 * default external system clock. If we are
98 * on Rev. C silicon then errata forces us to
99 * use the internal clock.
100 */
101 switch (PVR_REV(mfspr(SPRN_PVR))) {
102 case PVR_REV(PVR_440GP_RB):
103 freq = EBONY_440GP_RB_SYSCLK;
104 break;
105 case PVR_REV(PVR_440GP_RC1):
106 default:
107 freq = EBONY_440GP_RC_SYSCLK;
108 break;
109 }
110
111 ibm44x_calibrate_decr(freq);
112 }
113
114 static int
115 ebony_show_cpuinfo(struct seq_file *m)
116 {
117 seq_printf(m, "vendor\t\t: IBM\n");
118 seq_printf(m, "machine\t\t: Ebony\n");
119
120 return 0;
121 }
122
123 static inline int
124 ebony_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
125 {
126 static char pci_irq_table[][4] =
127 /*
128 * PCI IDSEL/INTPIN->INTLINE
129 * A B C D
130 */
131 {
132 { 23, 23, 23, 23 }, /* IDSEL 1 - PCI Slot 0 */
133 { 24, 24, 24, 24 }, /* IDSEL 2 - PCI Slot 1 */
134 { 25, 25, 25, 25 }, /* IDSEL 3 - PCI Slot 2 */
135 { 26, 26, 26, 26 }, /* IDSEL 4 - PCI Slot 3 */
136 };
137
138 const long min_idsel = 1, max_idsel = 4, irqs_per_slot = 4;
139 return PCI_IRQ_TABLE_LOOKUP;
140 }
141
142 #define PCIX_WRITEL(value, offset) \
143 (writel(value, pcix_reg_base + offset))
144
145 /*
146 * FIXME: This is only here to "make it work". This will move
147 * to a ibm_pcix.c which will contain a generic IBM PCIX bridge
148 * configuration library. -Matt
149 */
150 static void __init
151 ebony_setup_pcix(void)
152 {
153 void __iomem *pcix_reg_base;
154
155 pcix_reg_base = ioremap64(PCIX0_REG_BASE, PCIX_REG_SIZE);
156
157 /* Disable all windows */
158 PCIX_WRITEL(0, PCIX0_POM0SA);
159 PCIX_WRITEL(0, PCIX0_POM1SA);
160 PCIX_WRITEL(0, PCIX0_POM2SA);
161 PCIX_WRITEL(0, PCIX0_PIM0SA);
162 PCIX_WRITEL(0, PCIX0_PIM1SA);
163 PCIX_WRITEL(0, PCIX0_PIM2SA);
164
165 /* Setup 2GB PLB->PCI outbound mem window (3_8000_0000->0_8000_0000) */
166 PCIX_WRITEL(0x00000003, PCIX0_POM0LAH);
167 PCIX_WRITEL(0x80000000, PCIX0_POM0LAL);
168 PCIX_WRITEL(0x00000000, PCIX0_POM0PCIAH);
169 PCIX_WRITEL(0x80000000, PCIX0_POM0PCIAL);
170 PCIX_WRITEL(0x80000001, PCIX0_POM0SA);
171
172 /* Setup 2GB PCI->PLB inbound memory window at 0, enable MSIs */
173 PCIX_WRITEL(0x00000000, PCIX0_PIM0LAH);
174 PCIX_WRITEL(0x00000000, PCIX0_PIM0LAL);
175 PCIX_WRITEL(0x80000007, PCIX0_PIM0SA);
176
177 eieio();
178 }
179
180 static void __init
181 ebony_setup_hose(void)
182 {
183 struct pci_controller *hose;
184
185 /* Configure windows on the PCI-X host bridge */
186 ebony_setup_pcix();
187
188 hose = pcibios_alloc_controller();
189
190 if (!hose)
191 return;
192
193 hose->first_busno = 0;
194 hose->last_busno = 0xff;
195
196 hose->pci_mem_offset = EBONY_PCI_MEM_OFFSET;
197
198 pci_init_resource(&hose->io_resource,
199 EBONY_PCI_LOWER_IO,
200 EBONY_PCI_UPPER_IO,
201 IORESOURCE_IO,
202 "PCI host bridge");
203
204 pci_init_resource(&hose->mem_resources[0],
205 EBONY_PCI_LOWER_MEM,
206 EBONY_PCI_UPPER_MEM,
207 IORESOURCE_MEM,
208 "PCI host bridge");
209
210 hose->io_space.start = EBONY_PCI_LOWER_IO;
211 hose->io_space.end = EBONY_PCI_UPPER_IO;
212 hose->mem_space.start = EBONY_PCI_LOWER_MEM;
213 hose->mem_space.end = EBONY_PCI_UPPER_MEM;
214 hose->io_base_virt = ioremap64(EBONY_PCI_IO_BASE, EBONY_PCI_IO_SIZE);
215 isa_io_base = (unsigned long)hose->io_base_virt;
216
217 setup_indirect_pci(hose,
218 EBONY_PCI_CFGA_PLB32,
219 EBONY_PCI_CFGD_PLB32);
220 hose->set_cfg_type = 1;
221
222 hose->last_busno = pciauto_bus_scan(hose, hose->first_busno);
223
224 ppc_md.pci_swizzle = common_swizzle;
225 ppc_md.pci_map_irq = ebony_map_irq;
226 }
227
228 TODC_ALLOC();
229
230 static void __init
231 ebony_early_serial_map(void)
232 {
233 struct uart_port port;
234
235 /* Setup ioremapped serial port access */
236 memset(&port, 0, sizeof(port));
237 port.membase = ioremap64(PPC440GP_UART0_ADDR, 8);
238 port.irq = 0;
239 port.uartclk = clocks.uart0;
240 port.regshift = 0;
241 port.iotype = SERIAL_IO_MEM;
242 port.flags = ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST;
243 port.line = 0;
244
245 if (early_serial_setup(&port) != 0) {
246 printk("Early serial init of port 0 failed\n");
247 }
248
249 #if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
250 /* Configure debug serial access */
251 gen550_init(0, &port);
252
253 /* Purge TLB entry added in head_44x.S for early serial access */
254 _tlbie(UART0_IO_BASE);
255 #endif
256
257 port.membase = ioremap64(PPC440GP_UART1_ADDR, 8);
258 port.irq = 1;
259 port.uartclk = clocks.uart1;
260 port.line = 1;
261
262 if (early_serial_setup(&port) != 0) {
263 printk("Early serial init of port 1 failed\n");
264 }
265
266 #if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
267 /* Configure debug serial access */
268 gen550_init(1, &port);
269 #endif
270 }
271
272 static void __init
273 ebony_setup_arch(void)
274 {
275 struct ocp_def *def;
276 struct ocp_func_emac_data *emacdata;
277
278 /* Set mac_addr for each EMAC */
279 def = ocp_get_one_device(OCP_VENDOR_IBM, OCP_FUNC_EMAC, 0);
280 emacdata = def->additions;
281 emacdata->phy_map = 0x00000001; /* Skip 0x00 */
282 emacdata->phy_mode = PHY_MODE_RMII;
283 memcpy(emacdata->mac_addr, __res.bi_enetaddr, 6);
284
285 def = ocp_get_one_device(OCP_VENDOR_IBM, OCP_FUNC_EMAC, 1);
286 emacdata = def->additions;
287 emacdata->phy_map = 0x00000001; /* Skip 0x00 */
288 emacdata->phy_mode = PHY_MODE_RMII;
289 memcpy(emacdata->mac_addr, __res.bi_enet1addr, 6);
290
291 /*
292 * Determine various clocks.
293 * To be completely correct we should get SysClk
294 * from FPGA, because it can be changed by on-board switches
295 * --ebs
296 */
297 ibm440gp_get_clocks(&clocks, 33333333, 6 * 1843200);
298 ocp_sys_info.opb_bus_freq = clocks.opb;
299
300 /* Setup TODC access */
301 TODC_INIT(TODC_TYPE_DS1743,
302 0,
303 0,
304 ioremap64(EBONY_RTC_ADDR, EBONY_RTC_SIZE),
305 8);
306
307 /* init to some ~sane value until calibrate_delay() runs */
308 loops_per_jiffy = 50000000/HZ;
309
310 /* Setup PCI host bridge */
311 ebony_setup_hose();
312
313 #ifdef CONFIG_BLK_DEV_INITRD
314 if (initrd_start)
315 ROOT_DEV = Root_RAM0;
316 else
317 #endif
318 #ifdef CONFIG_ROOT_NFS
319 ROOT_DEV = Root_NFS;
320 #else
321 ROOT_DEV = Root_HDA1;
322 #endif
323
324 ebony_early_serial_map();
325
326 /* Identify the system */
327 printk("IBM Ebony port (MontaVista Software, Inc. (source@mvista.com))\n");
328 }
329
330 void __init platform_init(unsigned long r3, unsigned long r4,
331 unsigned long r5, unsigned long r6, unsigned long r7)
332 {
333 parse_bootinfo(find_bootinfo());
334
335 /*
336 * If we were passed in a board information, copy it into the
337 * residual data area.
338 */
339 if (r3)
340 __res = *(bd_t *)(r3 + KERNELBASE);
341
342 ibm44x_platform_init();
343
344 ppc_md.setup_arch = ebony_setup_arch;
345 ppc_md.show_cpuinfo = ebony_show_cpuinfo;
346 ppc_md.get_irq = NULL; /* Set in ppc4xx_pic_init() */
347
348 ppc_md.calibrate_decr = ebony_calibrate_decr;
349 ppc_md.time_init = todc_time_init;
350 ppc_md.set_rtc_time = todc_set_rtc_time;
351 ppc_md.get_rtc_time = todc_get_rtc_time;
352
353 ppc_md.nvram_read_val = todc_direct_read_val;
354 ppc_md.nvram_write_val = todc_direct_write_val;
355 #ifdef CONFIG_KGDB
356 ppc_md.early_serial_map = ebony_early_serial_map;
357 #endif
358 }
359