xref: /linux/arch/powerpc/platforms/amigaone/setup.c (revision c532de5a67a70f8533d495f8f2aaa9a0491c3ad0)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * AmigaOne platform setup
4  *
5  * Copyright 2008 Gerhard Pircher (gerhard_pircher@gmx.net)
6  *
7  *   Based on original amigaone_setup.c source code
8  * Copyright 2003 by Hans-Joerg Frieden and Thomas Frieden
9  */
10 
11 #include <linux/irqdomain.h>
12 #include <linux/kernel.h>
13 #include <linux/of.h>
14 #include <linux/of_address.h>
15 #include <linux/seq_file.h>
16 #include <generated/utsrelease.h>
17 
18 #include <asm/machdep.h>
19 #include <asm/cputable.h>
20 #include <asm/pci-bridge.h>
21 #include <asm/i8259.h>
22 #include <asm/time.h>
23 #include <asm/udbg.h>
24 #include <asm/dma.h>
25 
26 extern void __flush_disable_L1(void);
27 
28 static void amigaone_show_cpuinfo(struct seq_file *m)
29 {
30 	seq_printf(m, "vendor\t\t: Eyetech Ltd.\n");
31 }
32 
33 static int __init amigaone_add_bridge(struct device_node *dev)
34 {
35 	const u32 *cfg_addr, *cfg_data;
36 	int len;
37 	const int *bus_range;
38 	struct pci_controller *hose;
39 
40 	printk(KERN_INFO "Adding PCI host bridge %pOF\n", dev);
41 
42 	cfg_addr = of_get_address(dev, 0, NULL, NULL);
43 	cfg_data = of_get_address(dev, 1, NULL, NULL);
44 	if ((cfg_addr == NULL) || (cfg_data == NULL))
45 		return -ENODEV;
46 
47 	bus_range = of_get_property(dev, "bus-range", &len);
48 	if ((bus_range == NULL) || (len < 2 * sizeof(int)))
49 		printk(KERN_WARNING "Can't get bus-range for %pOF, assume"
50 		       " bus 0\n", dev);
51 
52 	hose = pcibios_alloc_controller(dev);
53 	if (hose == NULL)
54 		return -ENOMEM;
55 
56 	hose->first_busno = bus_range ? bus_range[0] : 0;
57 	hose->last_busno = bus_range ? bus_range[1] : 0xff;
58 
59 	setup_indirect_pci(hose, cfg_addr[0], cfg_data[0], 0);
60 
61 	/* Interpret the "ranges" property */
62 	/* This also maps the I/O region and sets isa_io/mem_base */
63 	pci_process_bridge_OF_ranges(hose, dev, 1);
64 
65 	return 0;
66 }
67 
68 static void __init amigaone_setup_arch(void)
69 {
70 	if (ppc_md.progress)
71 		ppc_md.progress("Linux/PPC "UTS_RELEASE"\n", 0);
72 }
73 
74 static void __init amigaone_discover_phbs(void)
75 {
76 	struct device_node *np;
77 	int phb = -ENODEV;
78 
79 	/* Lookup PCI host bridges. */
80 	for_each_compatible_node(np, "pci", "mai-logic,articia-s")
81 		phb = amigaone_add_bridge(np);
82 
83 	BUG_ON(phb != 0);
84 }
85 
86 static void __init amigaone_init_IRQ(void)
87 {
88 	struct device_node *pic, *np = NULL;
89 	const unsigned long *prop = NULL;
90 	unsigned long int_ack = 0;
91 
92 	/* Search for ISA interrupt controller. */
93 	pic = of_find_compatible_node(NULL, "interrupt-controller",
94 	                              "pnpPNP,000");
95 	BUG_ON(pic == NULL);
96 
97 	/* Look for interrupt acknowledge address in the PCI root node. */
98 	np = of_find_compatible_node(NULL, "pci", "mai-logic,articia-s");
99 	if (np) {
100 		prop = of_get_property(np, "8259-interrupt-acknowledge", NULL);
101 		if (prop)
102 			int_ack = prop[0];
103 		of_node_put(np);
104 	}
105 
106 	if (int_ack == 0)
107 		printk(KERN_WARNING "Cannot find PCI interrupt acknowledge"
108 		       " address, polling\n");
109 
110 	i8259_init(pic, int_ack);
111 	ppc_md.get_irq = i8259_irq;
112 	irq_set_default_host(i8259_get_host());
113 }
114 
115 static int __init request_isa_regions(void)
116 {
117 	request_region(0x00, 0x20, "dma1");
118 	request_region(0x40, 0x20, "timer");
119 	request_region(0x80, 0x10, "dma page reg");
120 	request_region(0xc0, 0x20, "dma2");
121 
122 	return 0;
123 }
124 machine_device_initcall(amigaone, request_isa_regions);
125 
126 static void __noreturn amigaone_restart(char *cmd)
127 {
128 	local_irq_disable();
129 
130 	/* Flush and disable caches. */
131 	__flush_disable_L1();
132 
133         /* Set SRR0 to the reset vector and turn on MSR_IP. */
134 	mtspr(SPRN_SRR0, 0xfff00100);
135 	mtspr(SPRN_SRR1, MSR_IP);
136 
137 	/* Do an rfi to jump back to firmware. */
138 	__asm__ __volatile__("rfi" : : : "memory");
139 
140 	/* Not reached. */
141 	while (1);
142 }
143 
144 static int __init amigaone_probe(void)
145 {
146 	/*
147 	 * Coherent memory access cause complete system lockup! Thus
148 	 * disable this CPU feature, even if the CPU needs it.
149 	 */
150 	cur_cpu_spec->cpu_features &= ~CPU_FTR_NEED_COHERENT;
151 
152 	DMA_MODE_READ = 0x44;
153 	DMA_MODE_WRITE = 0x48;
154 
155 	return 1;
156 }
157 
158 define_machine(amigaone) {
159 	.name			= "AmigaOne",
160 	.compatible		= "eyetech,amigaone",
161 	.probe			= amigaone_probe,
162 	.setup_arch		= amigaone_setup_arch,
163 	.discover_phbs		= amigaone_discover_phbs,
164 	.show_cpuinfo		= amigaone_show_cpuinfo,
165 	.init_IRQ		= amigaone_init_IRQ,
166 	.restart		= amigaone_restart,
167 	.progress		= udbg_progress,
168 };
169