1 /*
2  * Board setup routines for the storcenter
3  *
4  * Copyright 2007 (C) Oyvind Repvik (nail@nslu2-linux.org)
5  * Copyright 2007 Andy Wilcox, Jon Loeliger
6  *
7  * Based on linkstation.c by G. Liakhovetski
8  *
9  * This file is licensed under the terms of the GNU General Public License
10  * version 2.  This program is licensed "as is" without any warranty of
11  * any kind, whether express or implied.
12  */
13 
14 #include <linux/kernel.h>
15 #include <linux/pci.h>
16 #include <linux/initrd.h>
17 #include <linux/of_platform.h>
18 
19 #include <asm/time.h>
20 #include <asm/prom.h>
21 #include <asm/mpic.h>
22 #include <asm/pci-bridge.h>
23 
24 #include "mpc10x.h"
25 
26 
27 static const struct of_device_id storcenter_of_bus[] __initconst = {
28 	{ .name = "soc", },
29 	{},
30 };
31 
storcenter_device_probe(void)32 static int __init storcenter_device_probe(void)
33 {
34 	of_platform_bus_probe(NULL, storcenter_of_bus, NULL);
35 	return 0;
36 }
37 machine_device_initcall(storcenter, storcenter_device_probe);
38 
39 
storcenter_add_bridge(struct device_node * dev)40 static int __init storcenter_add_bridge(struct device_node *dev)
41 {
42 #ifdef CONFIG_PCI
43 	int len;
44 	struct pci_controller *hose;
45 	const int *bus_range;
46 
47 	printk("Adding PCI host bridge %pOF\n", dev);
48 
49 	hose = pcibios_alloc_controller(dev);
50 	if (hose == NULL)
51 		return -ENOMEM;
52 
53 	bus_range = of_get_property(dev, "bus-range", &len);
54 	hose->first_busno = bus_range ? bus_range[0] : 0;
55 	hose->last_busno = bus_range ? bus_range[1] : 0xff;
56 
57 	setup_indirect_pci(hose, MPC10X_MAPB_CNFG_ADDR, MPC10X_MAPB_CNFG_DATA, 0);
58 
59 	/* Interpret the "ranges" property */
60 	/* This also maps the I/O region and sets isa_io/mem_base */
61 	pci_process_bridge_OF_ranges(hose, dev, 1);
62 #endif
63 
64 	return 0;
65 }
66 
storcenter_setup_arch(void)67 static void __init storcenter_setup_arch(void)
68 {
69 	printk(KERN_INFO "IOMEGA StorCenter\n");
70 }
71 
storcenter_setup_pci(void)72 static void __init storcenter_setup_pci(void)
73 {
74 	struct device_node *np;
75 
76 	/* Lookup PCI host bridges */
77 	for_each_compatible_node(np, "pci", "mpc10x-pci")
78 		storcenter_add_bridge(np);
79 }
80 
81 /*
82  * Interrupt setup and service.  Interrupts on the turbostation come
83  * from the four PCI slots plus onboard 8241 devices: I2C, DUART.
84  */
storcenter_init_IRQ(void)85 static void __init storcenter_init_IRQ(void)
86 {
87 	struct mpic *mpic;
88 
89 	mpic = mpic_alloc(NULL, 0, 0, 16, 0, " OpenPIC  ");
90 	BUG_ON(mpic == NULL);
91 
92 	/*
93 	 * 16 Serial Interrupts followed by 16 Internal Interrupts.
94 	 * I2C is the second internal, so it is at 17, 0x11020.
95 	 */
96 	mpic_assign_isu(mpic, 0, mpic->paddr + 0x10200);
97 	mpic_assign_isu(mpic, 1, mpic->paddr + 0x11000);
98 
99 	mpic_init(mpic);
100 }
101 
storcenter_restart(char * cmd)102 static void __noreturn storcenter_restart(char *cmd)
103 {
104 	local_irq_disable();
105 
106 	/* Set exception prefix high - to the firmware */
107 	mtmsr(mfmsr() | MSR_IP);
108 	isync();
109 
110 	/* Wait for reset to happen */
111 	for (;;) ;
112 }
113 
storcenter_probe(void)114 static int __init storcenter_probe(void)
115 {
116 	return of_machine_is_compatible("iomega,storcenter");
117 }
118 
define_machine(storcenter)119 define_machine(storcenter){
120 	.name 			= "IOMEGA StorCenter",
121 	.probe 			= storcenter_probe,
122 	.setup_arch 		= storcenter_setup_arch,
123 	.discover_phbs 		= storcenter_setup_pci,
124 	.init_IRQ 		= storcenter_init_IRQ,
125 	.get_irq 		= mpic_get_irq,
126 	.restart 		= storcenter_restart,
127 	.calibrate_decr 	= generic_calibrate_decr,
128 };
129