blob: 33d8c9e3223d37ac90e0b756f22c85b07d38f833 [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 Nemoto7779a5e2008-07-25 23:08:06 +090024#include <linux/serial_core.h>
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090025#include <asm/bootinfo.h>
Atsushi Nemotoe0eb7302008-07-19 01:51:52 +090026#include <asm/time.h>
Atsushi Nemotoa49297e2008-07-24 00:25:17 +090027#include <asm/reboot.h>
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090028#include <asm/txx9/generic.h>
Atsushi Nemoto07517522008-07-24 00:25:15 +090029#include <asm/txx9/pci.h>
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090030#ifdef CONFIG_CPU_TX49XX
31#include <asm/txx9/tx4938.h>
32#endif
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090033
34/* EBUSC settings of TX4927, etc. */
35struct resource txx9_ce_res[8];
36static char txx9_ce_res_name[8][4]; /* "CEn" */
37
38/* pcode, internal register */
Atsushi Nemoto94a4c322008-07-19 01:51:47 +090039unsigned int txx9_pcode;
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090040char txx9_pcode_str[8];
41static struct resource txx9_reg_res = {
42 .name = txx9_pcode_str,
43 .flags = IORESOURCE_MEM,
44};
45void __init
46txx9_reg_res_init(unsigned int pcode, unsigned long base, unsigned long size)
47{
48 int i;
49
50 for (i = 0; i < ARRAY_SIZE(txx9_ce_res); i++) {
51 sprintf(txx9_ce_res_name[i], "CE%d", i);
52 txx9_ce_res[i].flags = IORESOURCE_MEM;
53 txx9_ce_res[i].name = txx9_ce_res_name[i];
54 }
55
Atsushi Nemoto073828d2008-08-26 21:29:58 +090056 txx9_pcode = pcode;
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090057 sprintf(txx9_pcode_str, "TX%x", pcode);
58 if (base) {
59 txx9_reg_res.start = base & 0xfffffffffULL;
60 txx9_reg_res.end = (base & 0xfffffffffULL) + (size - 1);
61 request_resource(&iomem_resource, &txx9_reg_res);
62 }
63}
64
65/* clocks */
66unsigned int txx9_master_clock;
67unsigned int txx9_cpu_clock;
68unsigned int txx9_gbus_clock;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090069
Atsushi Nemoto94a4c322008-07-19 01:51:47 +090070int txx9_ccfg_toeon __initdata = 1;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090071
72/* Minimum CLK support */
73
74struct clk *clk_get(struct device *dev, const char *id)
75{
76 if (!strcmp(id, "spi-baseclk"))
Atsushi Nemoto94a4c322008-07-19 01:51:47 +090077 return (struct clk *)((unsigned long)txx9_gbus_clock / 2 / 4);
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090078 if (!strcmp(id, "imbus_clk"))
Atsushi Nemoto94a4c322008-07-19 01:51:47 +090079 return (struct clk *)((unsigned long)txx9_gbus_clock / 2);
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090080 return ERR_PTR(-ENOENT);
81}
82EXPORT_SYMBOL(clk_get);
83
84int clk_enable(struct clk *clk)
85{
86 return 0;
87}
88EXPORT_SYMBOL(clk_enable);
89
90void clk_disable(struct clk *clk)
91{
92}
93EXPORT_SYMBOL(clk_disable);
94
95unsigned long clk_get_rate(struct clk *clk)
96{
97 return (unsigned long)clk;
98}
99EXPORT_SYMBOL(clk_get_rate);
100
101void clk_put(struct clk *clk)
102{
103}
104EXPORT_SYMBOL(clk_put);
105
Atsushi Nemoto8d795f22008-07-18 00:43:48 +0900106/* GPIO support */
107
108#ifdef CONFIG_GENERIC_GPIO
109int gpio_to_irq(unsigned gpio)
110{
111 return -EINVAL;
112}
113EXPORT_SYMBOL(gpio_to_irq);
114
115int irq_to_gpio(unsigned irq)
116{
117 return -EINVAL;
118}
119EXPORT_SYMBOL(irq_to_gpio);
120#endif
121
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900122extern struct txx9_board_vec jmr3927_vec;
123extern struct txx9_board_vec rbtx4927_vec;
124extern struct txx9_board_vec rbtx4937_vec;
125extern struct txx9_board_vec rbtx4938_vec;
126
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900127struct txx9_board_vec *txx9_board_vec __initdata;
128static char txx9_system_type[32];
129
Atsushi Nemotoe0dfb202008-08-19 22:55:06 +0900130static void __init prom_init_cmdline(void)
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900131{
132 int argc = (int)fw_arg0;
Atsushi Nemotoe0dfb202008-08-19 22:55:06 +0900133 int *argv32 = (int *)fw_arg1;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900134 int i; /* Always ignore the "-c" at argv[0] */
Atsushi Nemotoe0dfb202008-08-19 22:55:06 +0900135 char builtin[CL_SIZE];
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900136
137 /* ignore all built-in args if any f/w args given */
Atsushi Nemotoe0dfb202008-08-19 22:55:06 +0900138 /*
139 * But if built-in strings was started with '+', append them
140 * to command line args. If built-in was started with '-',
141 * ignore all f/w args.
142 */
143 builtin[0] = '\0';
144 if (arcs_cmdline[0] == '+')
145 strcpy(builtin, arcs_cmdline + 1);
146 else if (arcs_cmdline[0] == '-') {
147 strcpy(builtin, arcs_cmdline + 1);
148 argc = 0;
149 } else if (argc <= 1)
150 strcpy(builtin, arcs_cmdline);
151 arcs_cmdline[0] = '\0';
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900152
153 for (i = 1; i < argc; i++) {
Atsushi Nemotoe0dfb202008-08-19 22:55:06 +0900154 char *str = (char *)(long)argv32[i];
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900155 if (i != 1)
156 strcat(arcs_cmdline, " ");
Atsushi Nemotoe0dfb202008-08-19 22:55:06 +0900157 if (strchr(str, ' ')) {
158 strcat(arcs_cmdline, "\"");
159 strcat(arcs_cmdline, str);
160 strcat(arcs_cmdline, "\"");
161 } else
162 strcat(arcs_cmdline, str);
163 }
164 /* append saved builtin args */
165 if (builtin[0]) {
166 if (arcs_cmdline[0])
167 strcat(arcs_cmdline, " ");
168 strcat(arcs_cmdline, builtin);
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900169 }
170}
171
172void __init prom_init(void)
173{
Atsushi Nemotoe0dfb202008-08-19 22:55:06 +0900174 prom_init_cmdline();
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900175#ifdef CONFIG_CPU_TX39XX
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900176 txx9_board_vec = &jmr3927_vec;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900177#endif
178#ifdef CONFIG_CPU_TX49XX
179 switch (TX4938_REV_PCODE()) {
Atsushi Nemoto8d795f22008-07-18 00:43:48 +0900180#ifdef CONFIG_TOSHIBA_RBTX4927
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900181 case 0x4927:
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900182 txx9_board_vec = &rbtx4927_vec;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900183 break;
184 case 0x4937:
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900185 txx9_board_vec = &rbtx4937_vec;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900186 break;
Atsushi Nemoto8d795f22008-07-18 00:43:48 +0900187#endif
188#ifdef CONFIG_TOSHIBA_RBTX4938
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900189 case 0x4938:
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900190 txx9_board_vec = &rbtx4938_vec;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900191 break;
Atsushi Nemoto8d795f22008-07-18 00:43:48 +0900192#endif
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900193 }
194#endif
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900195
196 strcpy(txx9_system_type, txx9_board_vec->system);
197
Atsushi Nemoto7b226092008-07-14 00:15:04 +0900198 txx9_board_vec->prom_init();
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900199}
200
201void __init prom_free_prom_memory(void)
202{
203}
204
205const char *get_system_type(void)
206{
207 return txx9_system_type;
208}
209
210char * __init prom_getcmdline(void)
211{
212 return &(arcs_cmdline[0]);
213}
214
Atsushi Nemotoa49297e2008-07-24 00:25:17 +0900215static void __noreturn txx9_machine_halt(void)
216{
217 local_irq_disable();
218 clear_c0_status(ST0_IM);
219 while (1) {
220 if (cpu_wait) {
221 (*cpu_wait)();
222 if (cpu_has_counter) {
223 /*
224 * Clear counter interrupt while it
225 * breaks WAIT instruction even if
226 * masked.
227 */
228 write_c0_compare(0);
229 }
230 }
231 }
232}
233
Atsushi Nemoto68314722008-07-24 00:25:18 +0900234/* Watchdog support */
235void __init txx9_wdt_init(unsigned long base)
236{
237 struct resource res = {
238 .start = base,
239 .end = base + 0x100 - 1,
240 .flags = IORESOURCE_MEM,
241 };
242 platform_device_register_simple("txx9wdt", -1, &res, 1);
243}
244
Atsushi Nemotoc49f91f2008-07-24 00:25:20 +0900245/* SPI support */
246void __init txx9_spi_init(int busid, unsigned long base, int irq)
247{
248 struct resource res[] = {
249 {
250 .start = base,
251 .end = base + 0x20 - 1,
252 .flags = IORESOURCE_MEM,
253 }, {
254 .start = irq,
255 .flags = IORESOURCE_IRQ,
256 },
257 };
258 platform_device_register_simple("spi_txx9", busid,
259 res, ARRAY_SIZE(res));
260}
261
262void __init txx9_ethaddr_init(unsigned int id, unsigned char *ethaddr)
263{
264 struct platform_device *pdev =
265 platform_device_alloc("tc35815-mac", id);
266 if (!pdev ||
267 platform_device_add_data(pdev, ethaddr, 6) ||
268 platform_device_add(pdev))
269 platform_device_put(pdev);
270}
271
Atsushi Nemoto7779a5e2008-07-25 23:08:06 +0900272void __init txx9_sio_init(unsigned long baseaddr, int irq,
273 unsigned int line, unsigned int sclk, int nocts)
274{
275#ifdef CONFIG_SERIAL_TXX9
276 struct uart_port req;
277
278 memset(&req, 0, sizeof(req));
279 req.line = line;
280 req.iotype = UPIO_MEM;
281 req.membase = ioremap(baseaddr, 0x24);
282 req.mapbase = baseaddr;
283 req.irq = irq;
284 if (!nocts)
285 req.flags |= UPF_BUGGY_UART /*HAVE_CTS_LINE*/;
286 if (sclk) {
287 req.flags |= UPF_MAGIC_MULTIPLIER /*USE_SCLK*/;
288 req.uartclk = sclk;
289 } else
290 req.uartclk = TXX9_IMCLK;
291 early_serial_txx9_setup(&req);
292#endif /* CONFIG_SERIAL_TXX9 */
293}
294
Atsushi Nemotoe3529532008-07-29 22:10:08 +0900295#ifdef CONFIG_EARLY_PRINTK
296static void __init null_prom_putchar(char c)
297{
298}
299void (*txx9_prom_putchar)(char c) __initdata = null_prom_putchar;
300
301void __init prom_putchar(char c)
302{
303 txx9_prom_putchar(c);
304}
305
306static void __iomem *early_txx9_sio_port;
307
308static void __init early_txx9_sio_putchar(char c)
309{
310#define TXX9_SICISR 0x0c
311#define TXX9_SITFIFO 0x1c
312#define TXX9_SICISR_TXALS 0x00000002
313 while (!(__raw_readl(early_txx9_sio_port + TXX9_SICISR) &
314 TXX9_SICISR_TXALS))
315 ;
316 __raw_writel(c, early_txx9_sio_port + TXX9_SITFIFO);
317}
318
319void __init txx9_sio_putchar_init(unsigned long baseaddr)
320{
321 early_txx9_sio_port = ioremap(baseaddr, 0x24);
322 txx9_prom_putchar = early_txx9_sio_putchar;
323}
324#endif /* CONFIG_EARLY_PRINTK */
325
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900326/* wrappers */
327void __init plat_mem_setup(void)
328{
Atsushi Nemoto94a4c322008-07-19 01:51:47 +0900329 ioport_resource.start = 0;
330 ioport_resource.end = ~0UL; /* no limit */
331 iomem_resource.start = 0;
332 iomem_resource.end = ~0UL; /* no limit */
Atsushi Nemotoa49297e2008-07-24 00:25:17 +0900333
334 /* fallback restart/halt routines */
335 _machine_restart = (void (*)(char *))txx9_machine_halt;
336 _machine_halt = txx9_machine_halt;
337 pm_power_off = txx9_machine_halt;
338
Atsushi Nemoto07517522008-07-24 00:25:15 +0900339#ifdef CONFIG_PCI
340 pcibios_plat_setup = txx9_pcibios_setup;
341#endif
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900342 txx9_board_vec->mem_setup();
343}
344
345void __init arch_init_irq(void)
346{
347 txx9_board_vec->irq_setup();
348}
349
350void __init plat_time_init(void)
351{
Atsushi Nemoto1374d082008-07-31 22:29:53 +0900352#ifdef CONFIG_CPU_TX49XX
353 mips_hpt_frequency = txx9_cpu_clock / 2;
354#endif
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900355 txx9_board_vec->time_init();
356}
357
358static int __init _txx9_arch_init(void)
359{
360 if (txx9_board_vec->arch_init)
361 txx9_board_vec->arch_init();
362 return 0;
363}
364arch_initcall(_txx9_arch_init);
365
366static int __init _txx9_device_init(void)
367{
368 if (txx9_board_vec->device_init)
369 txx9_board_vec->device_init();
370 return 0;
371}
372device_initcall(_txx9_device_init);
373
374int (*txx9_irq_dispatch)(int pending);
375asmlinkage void plat_irq_dispatch(void)
376{
377 int pending = read_c0_status() & read_c0_cause() & ST0_IM;
378 int irq = txx9_irq_dispatch(pending);
379
380 if (likely(irq >= 0))
381 do_IRQ(irq);
382 else
383 spurious_interrupt();
384}
Atsushi Nemoto4c642f32008-07-13 23:37:56 +0900385
386/* see include/asm-mips/mach-tx39xx/mangle-port.h, for example. */
387#ifdef NEEDS_TXX9_SWIZZLE_ADDR_B
388static unsigned long __swizzle_addr_none(unsigned long port)
389{
390 return port;
391}
392unsigned long (*__swizzle_addr_b)(unsigned long port) = __swizzle_addr_none;
393EXPORT_SYMBOL(__swizzle_addr_b);
394#endif