blob: f392374309b342f937d13a626dddf10f23b66abc [file] [log] [blame]
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +01001/*
2 * Board setup routines for the Buffalo Linkstation / Kurobox Platform.
3 *
4 * Copyright (C) 2006 G. Liakhovetski (g.liakhovetski@gmx.de)
5 *
6 * Based on sandpoint.c by Mark A. Greer
7 *
8 * This file is licensed under the terms of the GNU General Public License
9 * version 2. This program is licensed "as is" without any warranty of
10 * any kind, whether express or implied.
11 */
12
13#include <linux/kernel.h>
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +010014#include <linux/initrd.h>
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +010015#include <linux/mtd/physmap.h>
16
17#include <asm/time.h>
18#include <asm/prom.h>
19#include <asm/mpic.h>
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +010020#include <asm/pci-bridge.h>
21
Kumar Gala33d71d22007-08-20 08:50:28 -050022#include "mpc10x.h"
23
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +010024static struct mtd_partition linkstation_physmap_partitions[] = {
25 {
26 .name = "mtd_firmimg",
27 .offset = 0x000000,
28 .size = 0x300000,
29 },
30 {
31 .name = "mtd_bootcode",
32 .offset = 0x300000,
33 .size = 0x070000,
34 },
35 {
36 .name = "mtd_status",
37 .offset = 0x370000,
38 .size = 0x010000,
39 },
40 {
41 .name = "mtd_conf",
42 .offset = 0x380000,
43 .size = 0x080000,
44 },
45 {
46 .name = "mtd_allflash",
47 .offset = 0x000000,
48 .size = 0x400000,
49 },
50 {
51 .name = "mtd_data",
52 .offset = 0x310000,
53 .size = 0x0f0000,
54 },
55};
56
Arnd Bergmann09b55f72007-06-18 01:06:54 +020057static int __init linkstation_add_bridge(struct device_node *dev)
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +010058{
Arnd Bergmannd6658402007-06-18 01:06:57 +020059#ifdef CONFIG_PCI
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +010060 int len;
61 struct pci_controller *hose;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +100062 const int *bus_range;
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +010063
64 printk("Adding PCI host bridge %s\n", dev->full_name);
65
Stephen Rothwelle2eb6392007-04-03 22:26:41 +100066 bus_range = of_get_property(dev, "bus-range", &len);
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +010067 if (bus_range == NULL || len < 2 * sizeof(int))
68 printk(KERN_WARNING "Can't get bus-range for %s, assume"
69 " bus 0\n", dev->full_name);
70
Kumar Galadbf84712007-06-27 01:56:50 -050071 hose = pcibios_alloc_controller(dev);
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +010072 if (hose == NULL)
73 return -ENOMEM;
74 hose->first_busno = bus_range ? bus_range[0] : 0;
75 hose->last_busno = bus_range ? bus_range[1] : 0xff;
Kumar Gala2e56ff22007-07-19 16:07:35 -050076 setup_indirect_pci(hose, 0xfec00000, 0xfee00000, 0);
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +010077
78 /* Interpret the "ranges" property */
79 /* This also maps the I/O region and sets isa_io/mem_base */
80 pci_process_bridge_OF_ranges(hose, dev, 1);
Arnd Bergmannd6658402007-06-18 01:06:57 +020081#endif
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +010082 return 0;
83}
84
85static void __init linkstation_setup_arch(void)
86{
87 struct device_node *np;
88#ifdef CONFIG_MTD_PHYSMAP
89 physmap_set_partitions(linkstation_physmap_partitions,
90 ARRAY_SIZE(linkstation_physmap_partitions));
91#endif
92
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +010093 /* Lookup PCI host bridges */
94 for (np = NULL; (np = of_find_node_by_type(np, "pci")) != NULL;)
Arnd Bergmann09b55f72007-06-18 01:06:54 +020095 linkstation_add_bridge(np);
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +010096
97 printk(KERN_INFO "BUFFALO Network Attached Storage Series\n");
98 printk(KERN_INFO "(C) 2002-2005 BUFFALO INC.\n");
99}
100
101/*
Gabriel C33567a02007-08-01 19:41:09 +1000102 * Interrupt setup and service. Interrupts on the linkstation come
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +0100103 * from the four PCI slots plus onboard 8241 devices: I2C, DUART.
104 */
105static void __init linkstation_init_IRQ(void)
106{
107 struct mpic *mpic;
108 struct device_node *dnp;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000109 const u32 *prop;
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +0100110 int size;
111 phys_addr_t paddr;
112
113 dnp = of_find_node_by_type(NULL, "open-pic");
114 if (dnp == NULL)
115 return;
116
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000117 prop = of_get_property(dnp, "reg", &size);
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +0100118 paddr = (phys_addr_t)of_translate_address(dnp, prop);
119
120 mpic = mpic_alloc(dnp, paddr, MPIC_PRIMARY | MPIC_WANTS_RESET, 4, 32, " EPIC ");
121 BUG_ON(mpic == NULL);
122
123 /* PCI IRQs */
124 mpic_assign_isu(mpic, 0, paddr + 0x10200);
125
126 /* I2C */
127 mpic_assign_isu(mpic, 1, paddr + 0x11000);
128
129 /* ttyS0, ttyS1 */
130 mpic_assign_isu(mpic, 2, paddr + 0x11100);
131
132 mpic_init(mpic);
133}
134
135extern void avr_uart_configure(void);
136extern void avr_uart_send(const char);
137
138static void linkstation_restart(char *cmd)
139{
140 local_irq_disable();
141
142 /* Reset system via AVR */
143 avr_uart_configure();
144 /* Send reboot command */
145 avr_uart_send('C');
146
147 for(;;) /* Spin until reset happens */
148 avr_uart_send('G'); /* "kick" */
149}
150
151static void linkstation_power_off(void)
152{
153 local_irq_disable();
154
155 /* Power down system via AVR */
156 avr_uart_configure();
157 /* send shutdown command */
158 avr_uart_send('E');
159
160 for(;;) /* Spin until power-off happens */
161 avr_uart_send('G'); /* "kick" */
162 /* NOTREACHED */
163}
164
165static void linkstation_halt(void)
166{
167 linkstation_power_off();
168 /* NOTREACHED */
169}
170
171static void linkstation_show_cpuinfo(struct seq_file *m)
172{
173 seq_printf(m, "vendor\t\t: Buffalo Technology\n");
174 seq_printf(m, "machine\t\t: Linkstation I/Kurobox(HG)\n");
175}
176
177static int __init linkstation_probe(void)
178{
179 unsigned long root;
180
181 root = of_get_flat_dt_root();
182
183 if (!of_flat_dt_is_compatible(root, "linkstation"))
184 return 0;
185 return 1;
186}
187
188define_machine(linkstation){
189 .name = "Buffalo Linkstation",
190 .probe = linkstation_probe,
191 .setup_arch = linkstation_setup_arch,
192 .init_IRQ = linkstation_init_IRQ,
193 .show_cpuinfo = linkstation_show_cpuinfo,
194 .get_irq = mpic_get_irq,
195 .restart = linkstation_restart,
196 .power_off = linkstation_power_off,
197 .halt = linkstation_halt,
198 .calibrate_decr = generic_calibrate_decr,
199};