[POWERPC] Autodetect serial console on efika
[linux-2.6/libata-dev.git] / arch / powerpc / platforms / 52xx / efika.c
blob31a2a8ca1de747cc57999496862c3f9ef1bff35c
1 /*
2 * Efika 5K2 platform code
3 * Some code really inspired from the lite5200b platform.
5 * Copyright (C) 2006 bplan GmbH
7 * This file is licensed under the terms of the GNU General Public License
8 * version 2. This program is licensed "as is" without any warranty of any
9 * kind, whether express or implied.
12 #include <linux/errno.h>
13 #include <linux/kernel.h>
14 #include <linux/slab.h>
15 #include <linux/reboot.h>
16 #include <linux/init.h>
17 #include <linux/utsrelease.h>
18 #include <linux/seq_file.h>
19 #include <linux/string.h>
20 #include <linux/root_dev.h>
21 #include <linux/initrd.h>
22 #include <linux/timer.h>
23 #include <linux/pci.h>
24 #include <linux/console.h>
26 #include <asm/io.h>
27 #include <asm/irq.h>
28 #include <asm/sections.h>
29 #include <asm/pci-bridge.h>
30 #include <asm/pgtable.h>
31 #include <asm/prom.h>
32 #include <asm/time.h>
33 #include <asm/machdep.h>
34 #include <asm/rtas.h>
35 #include <asm/of_device.h>
36 #include <asm/of_platform.h>
37 #include <asm/mpc52xx.h>
40 #define EFIKA_PLATFORM_NAME "Efika"
43 /* ------------------------------------------------------------------------ */
44 /* PCI accesses thru RTAS */
45 /* ------------------------------------------------------------------------ */
47 #ifdef CONFIG_PCI
50 * Access functions for PCI config space using RTAS calls.
52 static int rtas_read_config(struct pci_bus *bus, unsigned int devfn, int offset,
53 int len, u32 * val)
55 struct pci_controller *hose = bus->sysdata;
56 unsigned long addr = (offset & 0xff) | ((devfn & 0xff) << 8)
57 | (((bus->number - hose->first_busno) & 0xff) << 16)
58 | (hose->index << 24);
59 int ret = -1;
60 int rval;
62 rval = rtas_call(rtas_token("read-pci-config"), 2, 2, &ret, addr, len);
63 *val = ret;
64 return rval ? PCIBIOS_DEVICE_NOT_FOUND : PCIBIOS_SUCCESSFUL;
67 static int rtas_write_config(struct pci_bus *bus, unsigned int devfn,
68 int offset, int len, u32 val)
70 struct pci_controller *hose = bus->sysdata;
71 unsigned long addr = (offset & 0xff) | ((devfn & 0xff) << 8)
72 | (((bus->number - hose->first_busno) & 0xff) << 16)
73 | (hose->index << 24);
74 int rval;
76 rval = rtas_call(rtas_token("write-pci-config"), 3, 1, NULL,
77 addr, len, val);
78 return rval ? PCIBIOS_DEVICE_NOT_FOUND : PCIBIOS_SUCCESSFUL;
81 static struct pci_ops rtas_pci_ops = {
82 rtas_read_config,
83 rtas_write_config
87 void __init efika_pcisetup(void)
89 const int *bus_range;
90 int len;
91 struct pci_controller *hose;
92 struct device_node *root;
93 struct device_node *pcictrl;
95 root = of_find_node_by_path("/");
96 if (root == NULL) {
97 printk(KERN_WARNING EFIKA_PLATFORM_NAME
98 ": Unable to find the root node\n");
99 return;
102 for (pcictrl = NULL;;) {
103 pcictrl = of_get_next_child(root, pcictrl);
104 if ((pcictrl == NULL) || (strcmp(pcictrl->name, "pci") == 0))
105 break;
108 of_node_put(root);
110 if (pcictrl == NULL) {
111 printk(KERN_WARNING EFIKA_PLATFORM_NAME
112 ": Unable to find the PCI bridge node\n");
113 return;
116 bus_range = get_property(pcictrl, "bus-range", &len);
117 if (bus_range == NULL || len < 2 * sizeof(int)) {
118 printk(KERN_WARNING EFIKA_PLATFORM_NAME
119 ": Can't get bus-range for %s\n", pcictrl->full_name);
120 return;
123 if (bus_range[1] == bus_range[0])
124 printk(KERN_INFO EFIKA_PLATFORM_NAME ": PCI bus %d",
125 bus_range[0]);
126 else
127 printk(KERN_INFO EFIKA_PLATFORM_NAME ": PCI buses %d..%d",
128 bus_range[0], bus_range[1]);
129 printk(" controlled by %s\n", pcictrl->full_name);
130 printk("\n");
132 hose = pcibios_alloc_controller();
133 if (!hose) {
134 printk(KERN_WARNING EFIKA_PLATFORM_NAME
135 ": Can't allocate PCI controller structure for %s\n",
136 pcictrl->full_name);
137 return;
140 hose->arch_data = of_node_get(pcictrl);
141 hose->first_busno = bus_range[0];
142 hose->last_busno = bus_range[1];
143 hose->ops = &rtas_pci_ops;
145 pci_process_bridge_OF_ranges(hose, pcictrl, 0);
148 #else
149 void __init efika_pcisetup(void)
151 #endif
155 /* ------------------------------------------------------------------------ */
156 /* Platform setup */
157 /* ------------------------------------------------------------------------ */
159 static void efika_show_cpuinfo(struct seq_file *m)
161 struct device_node *root;
162 const char *revision = NULL;
163 const char *codegendescription = NULL;
164 const char *codegenvendor = NULL;
166 root = of_find_node_by_path("/");
167 if (!root)
168 return;
170 revision = get_property(root, "revision", NULL);
171 codegendescription =
172 get_property(root, "CODEGEN,description", NULL);
173 codegenvendor = get_property(root, "CODEGEN,vendor", NULL);
175 if (codegendescription)
176 seq_printf(m, "machine\t\t: %s\n", codegendescription);
177 else
178 seq_printf(m, "machine\t\t: Efika\n");
180 if (revision)
181 seq_printf(m, "revision\t: %s\n", revision);
183 if (codegenvendor)
184 seq_printf(m, "vendor\t\t: %s\n", codegenvendor);
186 of_node_put(root);
189 static void __init efika_setup_arch(void)
191 rtas_initialize();
193 #ifdef CONFIG_BLK_DEV_INITRD
194 initrd_below_start_ok = 1;
196 if (initrd_start)
197 ROOT_DEV = Root_RAM0;
198 else
199 #endif
200 ROOT_DEV = Root_SDA2; /* sda2 (sda1 is for the kernel) */
202 efika_pcisetup();
204 if (ppc_md.progress)
205 ppc_md.progress("Linux/PPC " UTS_RELEASE " running on Efika ;-)\n", 0x0);
208 static int __init efika_probe(void)
210 char *model = of_get_flat_dt_prop(of_get_flat_dt_root(),
211 "model", NULL);
213 if (model == NULL)
214 return 0;
215 if (strcmp(model, "EFIKA5K2"))
216 return 0;
218 ISA_DMA_THRESHOLD = ~0L;
219 DMA_MODE_READ = 0x44;
220 DMA_MODE_WRITE = 0x48;
222 return 1;
225 static void __init efika_init_early(void)
227 #ifdef CONFIG_SERIAL_MPC52xx
228 struct device_node *stdout_node;
229 const char *device_type;
231 if (strstr(cmd_line, "console="))
232 return;
233 /* find the boot console from /chosen/stdout */
234 if (!of_chosen)
235 return;
236 device_type = get_property(of_chosen, "linux,stdout-path", NULL);
237 if (!device_type)
238 return;
239 stdout_node = of_find_node_by_path(device_type);
240 if (stdout_node) {
241 device_type = get_property(stdout_node, "device_type", NULL);
242 if (device_type && strcmp(device_type, "serial") == 0)
243 add_preferred_console("ttyPSC", 0, NULL);
244 of_node_put(stdout_node);
246 #endif
249 define_machine(efika)
251 .name = EFIKA_PLATFORM_NAME,
252 .probe = efika_probe,
253 .setup_arch = efika_setup_arch,
254 .init = mpc52xx_declare_of_platform_devices,
255 .init_early = efika_init_early,
256 .show_cpuinfo = efika_show_cpuinfo,
257 .init_IRQ = mpc52xx_init_irq,
258 .get_irq = mpc52xx_get_irq,
259 .restart = rtas_restart,
260 .power_off = rtas_power_off,
261 .halt = rtas_halt,
262 .set_rtc_time = rtas_set_rtc_time,
263 .get_rtc_time = rtas_get_rtc_time,
264 .progress = rtas_progress,
265 .get_boot_time = rtas_get_boot_time,
266 .calibrate_decr = generic_calibrate_decr,
267 .phys_mem_access_prot = pci_phys_mem_access_prot,