blob: 61ca02c2d644f03349944d3a3b7f2f60c04ac98a [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>
14#include <linux/pci.h>
15#include <linux/initrd.h>
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +010016#include <linux/mtd/physmap.h>
17
18#include <asm/time.h>
19#include <asm/prom.h>
20#include <asm/mpic.h>
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +010021#include <asm/pci-bridge.h>
22
Kumar Gala33d71d22007-08-20 08:50:28 -050023#include "mpc10x.h"
24
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +010025static struct mtd_partition linkstation_physmap_partitions[] = {
26 {
27 .name = "mtd_firmimg",
28 .offset = 0x000000,
29 .size = 0x300000,
30 },
31 {
32 .name = "mtd_bootcode",
33 .offset = 0x300000,
34 .size = 0x070000,
35 },
36 {
37 .name = "mtd_status",
38 .offset = 0x370000,
39 .size = 0x010000,
40 },
41 {
42 .name = "mtd_conf",
43 .offset = 0x380000,
44 .size = 0x080000,
45 },
46 {
47 .name = "mtd_allflash",
48 .offset = 0x000000,
49 .size = 0x400000,
50 },
51 {
52 .name = "mtd_data",
53 .offset = 0x310000,
54 .size = 0x0f0000,
55 },
56};
57
Arnd Bergmann09b55f72007-06-18 01:06:54 +020058static int __init linkstation_add_bridge(struct device_node *dev)
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +010059{
Arnd Bergmannd6658402007-06-18 01:06:57 +020060#ifdef CONFIG_PCI
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +010061 int len;
62 struct pci_controller *hose;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +100063 const int *bus_range;
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +010064
65 printk("Adding PCI host bridge %s\n", dev->full_name);
66
Stephen Rothwelle2eb6392007-04-03 22:26:41 +100067 bus_range = of_get_property(dev, "bus-range", &len);
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +010068 if (bus_range == NULL || len < 2 * sizeof(int))
69 printk(KERN_WARNING "Can't get bus-range for %s, assume"
70 " bus 0\n", dev->full_name);
71
Kumar Galadbf84712007-06-27 01:56:50 -050072 hose = pcibios_alloc_controller(dev);
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +010073 if (hose == NULL)
74 return -ENOMEM;
75 hose->first_busno = bus_range ? bus_range[0] : 0;
76 hose->last_busno = bus_range ? bus_range[1] : 0xff;
Kumar Gala2e56ff22007-07-19 16:07:35 -050077 setup_indirect_pci(hose, 0xfec00000, 0xfee00000, 0);
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +010078
79 /* Interpret the "ranges" property */
80 /* This also maps the I/O region and sets isa_io/mem_base */
81 pci_process_bridge_OF_ranges(hose, dev, 1);
Arnd Bergmannd6658402007-06-18 01:06:57 +020082#endif
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +010083 return 0;
84}
85
86static void __init linkstation_setup_arch(void)
87{
88 struct device_node *np;
89#ifdef CONFIG_MTD_PHYSMAP
90 physmap_set_partitions(linkstation_physmap_partitions,
91 ARRAY_SIZE(linkstation_physmap_partitions));
92#endif
93
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +010094 /* Lookup PCI host bridges */
95 for (np = NULL; (np = of_find_node_by_type(np, "pci")) != NULL;)
Arnd Bergmann09b55f72007-06-18 01:06:54 +020096 linkstation_add_bridge(np);
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +010097
98 printk(KERN_INFO "BUFFALO Network Attached Storage Series\n");
99 printk(KERN_INFO "(C) 2002-2005 BUFFALO INC.\n");
100}
101
102/*
Gabriel C33567a02007-08-01 19:41:09 +1000103 * Interrupt setup and service. Interrupts on the linkstation come
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +0100104 * from the four PCI slots plus onboard 8241 devices: I2C, DUART.
105 */
106static void __init linkstation_init_IRQ(void)
107{
108 struct mpic *mpic;
109 struct device_node *dnp;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000110 const u32 *prop;
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +0100111 int size;
112 phys_addr_t paddr;
113
114 dnp = of_find_node_by_type(NULL, "open-pic");
115 if (dnp == NULL)
116 return;
117
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000118 prop = of_get_property(dnp, "reg", &size);
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +0100119 paddr = (phys_addr_t)of_translate_address(dnp, prop);
120
121 mpic = mpic_alloc(dnp, paddr, MPIC_PRIMARY | MPIC_WANTS_RESET, 4, 32, " EPIC ");
122 BUG_ON(mpic == NULL);
123
124 /* PCI IRQs */
125 mpic_assign_isu(mpic, 0, paddr + 0x10200);
126
127 /* I2C */
128 mpic_assign_isu(mpic, 1, paddr + 0x11000);
129
130 /* ttyS0, ttyS1 */
131 mpic_assign_isu(mpic, 2, paddr + 0x11100);
132
133 mpic_init(mpic);
134}
135
136extern void avr_uart_configure(void);
137extern void avr_uart_send(const char);
138
139static void linkstation_restart(char *cmd)
140{
141 local_irq_disable();
142
143 /* Reset system via AVR */
144 avr_uart_configure();
145 /* Send reboot command */
146 avr_uart_send('C');
147
148 for(;;) /* Spin until reset happens */
149 avr_uart_send('G'); /* "kick" */
150}
151
152static void linkstation_power_off(void)
153{
154 local_irq_disable();
155
156 /* Power down system via AVR */
157 avr_uart_configure();
158 /* send shutdown command */
159 avr_uart_send('E');
160
161 for(;;) /* Spin until power-off happens */
162 avr_uart_send('G'); /* "kick" */
163 /* NOTREACHED */
164}
165
166static void linkstation_halt(void)
167{
168 linkstation_power_off();
169 /* NOTREACHED */
170}
171
172static void linkstation_show_cpuinfo(struct seq_file *m)
173{
174 seq_printf(m, "vendor\t\t: Buffalo Technology\n");
175 seq_printf(m, "machine\t\t: Linkstation I/Kurobox(HG)\n");
176}
177
178static int __init linkstation_probe(void)
179{
180 unsigned long root;
181
182 root = of_get_flat_dt_root();
183
184 if (!of_flat_dt_is_compatible(root, "linkstation"))
185 return 0;
186 return 1;
187}
188
189define_machine(linkstation){
190 .name = "Buffalo Linkstation",
191 .probe = linkstation_probe,
192 .setup_arch = linkstation_setup_arch,
193 .init_IRQ = linkstation_init_IRQ,
194 .show_cpuinfo = linkstation_show_cpuinfo,
195 .get_irq = mpic_get_irq,
196 .restart = linkstation_restart,
197 .power_off = linkstation_power_off,
198 .halt = linkstation_halt,
199 .calibrate_decr = generic_calibrate_decr,
200};