blob: f29cf29b11f895799740bd25cd7585024a9b840a [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 Liakhovetski22e181b2008-10-24 01:05:56 +020015#include <linux/of_platform.h>
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +010016
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
Uwe Kleine-Königce6d73c2014-09-10 21:56:38 +020024static const struct of_device_id of_bus_ids[] __initconst = {
Guennadi Liakhovetski22e181b2008-10-24 01:05:56 +020025 { .type = "soc", },
26 { .compatible = "simple-bus", },
27 {},
28};
29
30static int __init declare_of_platform_devices(void)
31{
32 of_platform_bus_probe(NULL, of_bus_ids, NULL);
33 return 0;
34}
35machine_device_initcall(linkstation, declare_of_platform_devices);
36
Arnd Bergmann09b55f72007-06-18 01:06:54 +020037static int __init linkstation_add_bridge(struct device_node *dev)
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +010038{
Arnd Bergmannd6658402007-06-18 01:06:57 +020039#ifdef CONFIG_PCI
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +010040 int len;
41 struct pci_controller *hose;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +100042 const int *bus_range;
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +010043
44 printk("Adding PCI host bridge %s\n", dev->full_name);
45
Stephen Rothwelle2eb6392007-04-03 22:26:41 +100046 bus_range = of_get_property(dev, "bus-range", &len);
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +010047 if (bus_range == NULL || len < 2 * sizeof(int))
48 printk(KERN_WARNING "Can't get bus-range for %s, assume"
49 " bus 0\n", dev->full_name);
50
Kumar Galadbf84712007-06-27 01:56:50 -050051 hose = pcibios_alloc_controller(dev);
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +010052 if (hose == NULL)
53 return -ENOMEM;
54 hose->first_busno = bus_range ? bus_range[0] : 0;
55 hose->last_busno = bus_range ? bus_range[1] : 0xff;
Kumar Gala2e56ff22007-07-19 16:07:35 -050056 setup_indirect_pci(hose, 0xfec00000, 0xfee00000, 0);
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +010057
58 /* Interpret the "ranges" property */
59 /* This also maps the I/O region and sets isa_io/mem_base */
60 pci_process_bridge_OF_ranges(hose, dev, 1);
Arnd Bergmannd6658402007-06-18 01:06:57 +020061#endif
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +010062 return 0;
63}
64
65static void __init linkstation_setup_arch(void)
66{
67 struct device_node *np;
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +010068
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +010069 /* Lookup PCI host bridges */
Kumar Galac9438af2007-10-04 00:28:43 -050070 for_each_compatible_node(np, "pci", "mpc10x-pci")
Arnd Bergmann09b55f72007-06-18 01:06:54 +020071 linkstation_add_bridge(np);
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +010072
73 printk(KERN_INFO "BUFFALO Network Attached Storage Series\n");
74 printk(KERN_INFO "(C) 2002-2005 BUFFALO INC.\n");
75}
76
77/*
Gabriel C33567a02007-08-01 19:41:09 +100078 * Interrupt setup and service. Interrupts on the linkstation come
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +010079 * from the four PCI slots plus onboard 8241 devices: I2C, DUART.
80 */
81static void __init linkstation_init_IRQ(void)
82{
83 struct mpic *mpic;
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +010084
Kyle Moffette55d7f72011-12-22 10:19:14 +000085 mpic = mpic_alloc(NULL, 0, 0, 4, 0, " EPIC ");
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +010086 BUG_ON(mpic == NULL);
87
88 /* PCI IRQs */
Kyle Moffette7a98672011-12-02 06:28:01 +000089 mpic_assign_isu(mpic, 0, mpic->paddr + 0x10200);
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +010090
91 /* I2C */
Kyle Moffette7a98672011-12-02 06:28:01 +000092 mpic_assign_isu(mpic, 1, mpic->paddr + 0x11000);
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +010093
94 /* ttyS0, ttyS1 */
Kyle Moffette7a98672011-12-02 06:28:01 +000095 mpic_assign_isu(mpic, 2, mpic->paddr + 0x11100);
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +010096
97 mpic_init(mpic);
98}
99
100extern void avr_uart_configure(void);
101extern void avr_uart_send(const char);
102
Daniel Axtens95ec77c2016-07-12 10:54:52 +1000103static void __noreturn linkstation_restart(char *cmd)
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +0100104{
105 local_irq_disable();
106
107 /* Reset system via AVR */
108 avr_uart_configure();
109 /* Send reboot command */
110 avr_uart_send('C');
111
112 for(;;) /* Spin until reset happens */
113 avr_uart_send('G'); /* "kick" */
114}
115
Daniel Axtens95ec77c2016-07-12 10:54:52 +1000116static void __noreturn linkstation_power_off(void)
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +0100117{
118 local_irq_disable();
119
120 /* Power down system via AVR */
121 avr_uart_configure();
122 /* send shutdown command */
123 avr_uart_send('E');
124
125 for(;;) /* Spin until power-off happens */
126 avr_uart_send('G'); /* "kick" */
127 /* NOTREACHED */
128}
129
Daniel Axtens95ec77c2016-07-12 10:54:52 +1000130static void __noreturn linkstation_halt(void)
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +0100131{
132 linkstation_power_off();
133 /* NOTREACHED */
134}
135
136static void linkstation_show_cpuinfo(struct seq_file *m)
137{
138 seq_printf(m, "vendor\t\t: Buffalo Technology\n");
139 seq_printf(m, "machine\t\t: Linkstation I/Kurobox(HG)\n");
140}
141
142static int __init linkstation_probe(void)
143{
Benjamin Herrenschmidt56571382016-07-05 15:04:05 +1000144 if (!of_machine_is_compatible("linkstation"))
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +0100145 return 0;
Alexander Graf9178ba22014-10-13 16:01:09 +0200146
147 pm_power_off = linkstation_power_off;
148
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +0100149 return 1;
150}
151
152define_machine(linkstation){
153 .name = "Buffalo Linkstation",
154 .probe = linkstation_probe,
155 .setup_arch = linkstation_setup_arch,
156 .init_IRQ = linkstation_init_IRQ,
157 .show_cpuinfo = linkstation_show_cpuinfo,
158 .get_irq = mpic_get_irq,
159 .restart = linkstation_restart,
Guennadi Liakhovetski04d76b92006-12-01 22:53:48 +0100160 .halt = linkstation_halt,
161 .calibrate_decr = generic_calibrate_decr,
162};