blob: b136c6692a5fcf5f3db23d84efa2db6e0ee2abf2 [file] [log] [blame]
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +09001/*
2 * linux/arch/mips/txx9/generic/setup.c
3 *
4 * Based on linux/arch/mips/txx9/rbtx4938/setup.c,
5 * and RBTX49xx patch from CELF patch archive.
6 *
7 * 2003-2005 (c) MontaVista Software, Inc.
8 * (C) Copyright TOSHIBA CORPORATION 2000-2001, 2004-2007
9 *
10 * This file is subject to the terms and conditions of the GNU General Public
11 * License. See the file "COPYING" in the main directory of this archive
12 * for more details.
13 */
14#include <linux/init.h>
15#include <linux/kernel.h>
16#include <linux/types.h>
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090017#include <linux/interrupt.h>
18#include <linux/string.h>
19#include <linux/module.h>
20#include <linux/clk.h>
21#include <linux/err.h>
Atsushi Nemotoe0eb7302008-07-19 01:51:52 +090022#include <linux/gpio.h>
Atsushi Nemoto68314722008-07-24 00:25:18 +090023#include <linux/platform_device.h>
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090024#include <asm/bootinfo.h>
Atsushi Nemotoe0eb7302008-07-19 01:51:52 +090025#include <asm/time.h>
Atsushi Nemotoa49297e2008-07-24 00:25:17 +090026#include <asm/reboot.h>
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090027#include <asm/txx9/generic.h>
Atsushi Nemoto07517522008-07-24 00:25:15 +090028#include <asm/txx9/pci.h>
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090029#ifdef CONFIG_CPU_TX49XX
30#include <asm/txx9/tx4938.h>
31#endif
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090032
33/* EBUSC settings of TX4927, etc. */
34struct resource txx9_ce_res[8];
35static char txx9_ce_res_name[8][4]; /* "CEn" */
36
37/* pcode, internal register */
Atsushi Nemoto94a4c322008-07-19 01:51:47 +090038unsigned int txx9_pcode;
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090039char txx9_pcode_str[8];
40static struct resource txx9_reg_res = {
41 .name = txx9_pcode_str,
42 .flags = IORESOURCE_MEM,
43};
44void __init
45txx9_reg_res_init(unsigned int pcode, unsigned long base, unsigned long size)
46{
47 int i;
48
49 for (i = 0; i < ARRAY_SIZE(txx9_ce_res); i++) {
50 sprintf(txx9_ce_res_name[i], "CE%d", i);
51 txx9_ce_res[i].flags = IORESOURCE_MEM;
52 txx9_ce_res[i].name = txx9_ce_res_name[i];
53 }
54
55 sprintf(txx9_pcode_str, "TX%x", pcode);
56 if (base) {
57 txx9_reg_res.start = base & 0xfffffffffULL;
58 txx9_reg_res.end = (base & 0xfffffffffULL) + (size - 1);
59 request_resource(&iomem_resource, &txx9_reg_res);
60 }
61}
62
63/* clocks */
64unsigned int txx9_master_clock;
65unsigned int txx9_cpu_clock;
66unsigned int txx9_gbus_clock;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090067
Atsushi Nemoto94a4c322008-07-19 01:51:47 +090068int txx9_ccfg_toeon __initdata = 1;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090069
70/* Minimum CLK support */
71
72struct clk *clk_get(struct device *dev, const char *id)
73{
74 if (!strcmp(id, "spi-baseclk"))
Atsushi Nemoto94a4c322008-07-19 01:51:47 +090075 return (struct clk *)((unsigned long)txx9_gbus_clock / 2 / 4);
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090076 if (!strcmp(id, "imbus_clk"))
Atsushi Nemoto94a4c322008-07-19 01:51:47 +090077 return (struct clk *)((unsigned long)txx9_gbus_clock / 2);
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090078 return ERR_PTR(-ENOENT);
79}
80EXPORT_SYMBOL(clk_get);
81
82int clk_enable(struct clk *clk)
83{
84 return 0;
85}
86EXPORT_SYMBOL(clk_enable);
87
88void clk_disable(struct clk *clk)
89{
90}
91EXPORT_SYMBOL(clk_disable);
92
93unsigned long clk_get_rate(struct clk *clk)
94{
95 return (unsigned long)clk;
96}
97EXPORT_SYMBOL(clk_get_rate);
98
99void clk_put(struct clk *clk)
100{
101}
102EXPORT_SYMBOL(clk_put);
103
Atsushi Nemoto8d795f22008-07-18 00:43:48 +0900104/* GPIO support */
105
106#ifdef CONFIG_GENERIC_GPIO
107int gpio_to_irq(unsigned gpio)
108{
109 return -EINVAL;
110}
111EXPORT_SYMBOL(gpio_to_irq);
112
113int irq_to_gpio(unsigned irq)
114{
115 return -EINVAL;
116}
117EXPORT_SYMBOL(irq_to_gpio);
118#endif
119
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900120extern struct txx9_board_vec jmr3927_vec;
121extern struct txx9_board_vec rbtx4927_vec;
122extern struct txx9_board_vec rbtx4937_vec;
123extern struct txx9_board_vec rbtx4938_vec;
124
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900125struct txx9_board_vec *txx9_board_vec __initdata;
126static char txx9_system_type[32];
127
128void __init prom_init_cmdline(void)
129{
130 int argc = (int)fw_arg0;
131 char **argv = (char **)fw_arg1;
132 int i; /* Always ignore the "-c" at argv[0] */
Atsushi Nemoto94a4c322008-07-19 01:51:47 +0900133#ifdef CONFIG_64BIT
134 char *fixed_argv[32];
135 for (i = 0; i < argc; i++)
136 fixed_argv[i] = (char *)(long)(*((__s32 *)argv + i));
137 argv = fixed_argv;
138#endif
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900139
140 /* ignore all built-in args if any f/w args given */
141 if (argc > 1)
142 *arcs_cmdline = '\0';
143
144 for (i = 1; i < argc; i++) {
145 if (i != 1)
146 strcat(arcs_cmdline, " ");
147 strcat(arcs_cmdline, argv[i]);
148 }
149}
150
151void __init prom_init(void)
152{
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900153#ifdef CONFIG_CPU_TX39XX
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900154 txx9_board_vec = &jmr3927_vec;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900155#endif
156#ifdef CONFIG_CPU_TX49XX
157 switch (TX4938_REV_PCODE()) {
Atsushi Nemoto8d795f22008-07-18 00:43:48 +0900158#ifdef CONFIG_TOSHIBA_RBTX4927
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900159 case 0x4927:
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900160 txx9_board_vec = &rbtx4927_vec;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900161 break;
162 case 0x4937:
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900163 txx9_board_vec = &rbtx4937_vec;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900164 break;
Atsushi Nemoto8d795f22008-07-18 00:43:48 +0900165#endif
166#ifdef CONFIG_TOSHIBA_RBTX4938
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900167 case 0x4938:
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900168 txx9_board_vec = &rbtx4938_vec;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900169 break;
Atsushi Nemoto8d795f22008-07-18 00:43:48 +0900170#endif
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900171 }
172#endif
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900173
174 strcpy(txx9_system_type, txx9_board_vec->system);
175
Atsushi Nemoto7b226092008-07-14 00:15:04 +0900176 txx9_board_vec->prom_init();
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900177}
178
179void __init prom_free_prom_memory(void)
180{
181}
182
183const char *get_system_type(void)
184{
185 return txx9_system_type;
186}
187
188char * __init prom_getcmdline(void)
189{
190 return &(arcs_cmdline[0]);
191}
192
Atsushi Nemotoa49297e2008-07-24 00:25:17 +0900193static void __noreturn txx9_machine_halt(void)
194{
195 local_irq_disable();
196 clear_c0_status(ST0_IM);
197 while (1) {
198 if (cpu_wait) {
199 (*cpu_wait)();
200 if (cpu_has_counter) {
201 /*
202 * Clear counter interrupt while it
203 * breaks WAIT instruction even if
204 * masked.
205 */
206 write_c0_compare(0);
207 }
208 }
209 }
210}
211
Atsushi Nemoto68314722008-07-24 00:25:18 +0900212/* Watchdog support */
213void __init txx9_wdt_init(unsigned long base)
214{
215 struct resource res = {
216 .start = base,
217 .end = base + 0x100 - 1,
218 .flags = IORESOURCE_MEM,
219 };
220 platform_device_register_simple("txx9wdt", -1, &res, 1);
221}
222
Atsushi Nemotoc49f91f2008-07-24 00:25:20 +0900223/* SPI support */
224void __init txx9_spi_init(int busid, unsigned long base, int irq)
225{
226 struct resource res[] = {
227 {
228 .start = base,
229 .end = base + 0x20 - 1,
230 .flags = IORESOURCE_MEM,
231 }, {
232 .start = irq,
233 .flags = IORESOURCE_IRQ,
234 },
235 };
236 platform_device_register_simple("spi_txx9", busid,
237 res, ARRAY_SIZE(res));
238}
239
240void __init txx9_ethaddr_init(unsigned int id, unsigned char *ethaddr)
241{
242 struct platform_device *pdev =
243 platform_device_alloc("tc35815-mac", id);
244 if (!pdev ||
245 platform_device_add_data(pdev, ethaddr, 6) ||
246 platform_device_add(pdev))
247 platform_device_put(pdev);
248}
249
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900250/* wrappers */
251void __init plat_mem_setup(void)
252{
Atsushi Nemoto94a4c322008-07-19 01:51:47 +0900253 ioport_resource.start = 0;
254 ioport_resource.end = ~0UL; /* no limit */
255 iomem_resource.start = 0;
256 iomem_resource.end = ~0UL; /* no limit */
Atsushi Nemotoa49297e2008-07-24 00:25:17 +0900257
258 /* fallback restart/halt routines */
259 _machine_restart = (void (*)(char *))txx9_machine_halt;
260 _machine_halt = txx9_machine_halt;
261 pm_power_off = txx9_machine_halt;
262
Atsushi Nemoto07517522008-07-24 00:25:15 +0900263#ifdef CONFIG_PCI
264 pcibios_plat_setup = txx9_pcibios_setup;
265#endif
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900266 txx9_board_vec->mem_setup();
267}
268
269void __init arch_init_irq(void)
270{
271 txx9_board_vec->irq_setup();
272}
273
274void __init plat_time_init(void)
275{
276 txx9_board_vec->time_init();
277}
278
279static int __init _txx9_arch_init(void)
280{
281 if (txx9_board_vec->arch_init)
282 txx9_board_vec->arch_init();
283 return 0;
284}
285arch_initcall(_txx9_arch_init);
286
287static int __init _txx9_device_init(void)
288{
289 if (txx9_board_vec->device_init)
290 txx9_board_vec->device_init();
291 return 0;
292}
293device_initcall(_txx9_device_init);
294
295int (*txx9_irq_dispatch)(int pending);
296asmlinkage void plat_irq_dispatch(void)
297{
298 int pending = read_c0_status() & read_c0_cause() & ST0_IM;
299 int irq = txx9_irq_dispatch(pending);
300
301 if (likely(irq >= 0))
302 do_IRQ(irq);
303 else
304 spurious_interrupt();
305}
Atsushi Nemoto4c642f32008-07-13 23:37:56 +0900306
307/* see include/asm-mips/mach-tx39xx/mangle-port.h, for example. */
308#ifdef NEEDS_TXX9_SWIZZLE_ADDR_B
309static unsigned long __swizzle_addr_none(unsigned long port)
310{
311 return port;
312}
313unsigned long (*__swizzle_addr_b)(unsigned long port) = __swizzle_addr_none;
314EXPORT_SYMBOL(__swizzle_addr_b);
315#endif