blob: dc5dbcc53a913c449e09bd5f8e65d963bdea794a [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 Nemoto860e5462008-08-19 22:55:08 +0900122#define BOARD_VEC(board) extern struct txx9_board_vec board;
123#include <asm/txx9/boards.h>
124#undef BOARD_VEC
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900125
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900126struct txx9_board_vec *txx9_board_vec __initdata;
127static char txx9_system_type[32];
128
Atsushi Nemoto860e5462008-08-19 22:55:08 +0900129static struct txx9_board_vec *board_vecs[] __initdata = {
130#define BOARD_VEC(board) &board,
131#include <asm/txx9/boards.h>
132#undef BOARD_VEC
133};
134
135static struct txx9_board_vec *__init find_board_byname(const char *name)
136{
137 int i;
138
139 /* search board_vecs table */
140 for (i = 0; i < ARRAY_SIZE(board_vecs); i++) {
141 if (strstr(board_vecs[i]->system, name))
142 return board_vecs[i];
143 }
144 return NULL;
145}
146
Atsushi Nemotoe0dfb202008-08-19 22:55:06 +0900147static void __init prom_init_cmdline(void)
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900148{
149 int argc = (int)fw_arg0;
Atsushi Nemotoe0dfb202008-08-19 22:55:06 +0900150 int *argv32 = (int *)fw_arg1;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900151 int i; /* Always ignore the "-c" at argv[0] */
Atsushi Nemotoe0dfb202008-08-19 22:55:06 +0900152 char builtin[CL_SIZE];
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900153
154 /* ignore all built-in args if any f/w args given */
Atsushi Nemotoe0dfb202008-08-19 22:55:06 +0900155 /*
156 * But if built-in strings was started with '+', append them
157 * to command line args. If built-in was started with '-',
158 * ignore all f/w args.
159 */
160 builtin[0] = '\0';
161 if (arcs_cmdline[0] == '+')
162 strcpy(builtin, arcs_cmdline + 1);
163 else if (arcs_cmdline[0] == '-') {
164 strcpy(builtin, arcs_cmdline + 1);
165 argc = 0;
166 } else if (argc <= 1)
167 strcpy(builtin, arcs_cmdline);
168 arcs_cmdline[0] = '\0';
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900169
170 for (i = 1; i < argc; i++) {
Atsushi Nemotoe0dfb202008-08-19 22:55:06 +0900171 char *str = (char *)(long)argv32[i];
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900172 if (i != 1)
173 strcat(arcs_cmdline, " ");
Atsushi Nemotoe0dfb202008-08-19 22:55:06 +0900174 if (strchr(str, ' ')) {
175 strcat(arcs_cmdline, "\"");
176 strcat(arcs_cmdline, str);
177 strcat(arcs_cmdline, "\"");
178 } else
179 strcat(arcs_cmdline, str);
180 }
181 /* append saved builtin args */
182 if (builtin[0]) {
183 if (arcs_cmdline[0])
184 strcat(arcs_cmdline, " ");
185 strcat(arcs_cmdline, builtin);
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900186 }
187}
188
Atsushi Nemoto860e5462008-08-19 22:55:08 +0900189static void __init preprocess_cmdline(void)
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900190{
Atsushi Nemoto860e5462008-08-19 22:55:08 +0900191 char cmdline[CL_SIZE];
192 char *s;
193
194 strcpy(cmdline, arcs_cmdline);
195 s = cmdline;
196 arcs_cmdline[0] = '\0';
197 while (s && *s) {
198 char *str = strsep(&s, " ");
199 if (strncmp(str, "board=", 6) == 0) {
200 txx9_board_vec = find_board_byname(str + 6);
201 continue;
202 } else if (strncmp(str, "masterclk=", 10) == 0) {
203 unsigned long val;
204 if (strict_strtoul(str + 10, 10, &val) == 0)
205 txx9_master_clock = val;
206 continue;
207 }
208 if (arcs_cmdline[0])
209 strcat(arcs_cmdline, " ");
210 strcat(arcs_cmdline, str);
211 }
212}
213
214static void __init select_board(void)
215{
216 const char *envstr;
217
218 /* first, determine by "board=" argument in preprocess_cmdline() */
219 if (txx9_board_vec)
220 return;
221 /* next, determine by "board" envvar */
222 envstr = prom_getenv("board");
223 if (envstr) {
224 txx9_board_vec = find_board_byname(envstr);
225 if (txx9_board_vec)
226 return;
227 }
228
229 /* select "default" board */
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900230#ifdef CONFIG_CPU_TX39XX
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900231 txx9_board_vec = &jmr3927_vec;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900232#endif
233#ifdef CONFIG_CPU_TX49XX
234 switch (TX4938_REV_PCODE()) {
Atsushi Nemoto8d795f22008-07-18 00:43:48 +0900235#ifdef CONFIG_TOSHIBA_RBTX4927
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900236 case 0x4927:
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900237 txx9_board_vec = &rbtx4927_vec;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900238 break;
239 case 0x4937:
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900240 txx9_board_vec = &rbtx4937_vec;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900241 break;
Atsushi Nemoto8d795f22008-07-18 00:43:48 +0900242#endif
243#ifdef CONFIG_TOSHIBA_RBTX4938
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900244 case 0x4938:
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900245 txx9_board_vec = &rbtx4938_vec;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900246 break;
Atsushi Nemoto8d795f22008-07-18 00:43:48 +0900247#endif
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900248 }
249#endif
Atsushi Nemoto860e5462008-08-19 22:55:08 +0900250}
251
252void __init prom_init(void)
253{
254 prom_init_cmdline();
255 preprocess_cmdline();
256 select_board();
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900257
258 strcpy(txx9_system_type, txx9_board_vec->system);
259
Atsushi Nemoto7b226092008-07-14 00:15:04 +0900260 txx9_board_vec->prom_init();
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900261}
262
263void __init prom_free_prom_memory(void)
264{
265}
266
267const char *get_system_type(void)
268{
269 return txx9_system_type;
270}
271
272char * __init prom_getcmdline(void)
273{
274 return &(arcs_cmdline[0]);
275}
276
Atsushi Nemoto265b89d2008-08-19 22:55:07 +0900277const char *__init prom_getenv(const char *name)
278{
279 const s32 *str = (const s32 *)fw_arg2;
280
281 if (!str)
282 return NULL;
283 /* YAMON style ("name", "value" pairs) */
284 while (str[0] && str[1]) {
285 if (!strcmp((const char *)(unsigned long)str[0], name))
286 return (const char *)(unsigned long)str[1];
287 str += 2;
288 }
289 return NULL;
290}
291
Atsushi Nemotoa49297e2008-07-24 00:25:17 +0900292static void __noreturn txx9_machine_halt(void)
293{
294 local_irq_disable();
295 clear_c0_status(ST0_IM);
296 while (1) {
297 if (cpu_wait) {
298 (*cpu_wait)();
299 if (cpu_has_counter) {
300 /*
301 * Clear counter interrupt while it
302 * breaks WAIT instruction even if
303 * masked.
304 */
305 write_c0_compare(0);
306 }
307 }
308 }
309}
310
Atsushi Nemoto68314722008-07-24 00:25:18 +0900311/* Watchdog support */
312void __init txx9_wdt_init(unsigned long base)
313{
314 struct resource res = {
315 .start = base,
316 .end = base + 0x100 - 1,
317 .flags = IORESOURCE_MEM,
318 };
319 platform_device_register_simple("txx9wdt", -1, &res, 1);
320}
321
Atsushi Nemotoc49f91f2008-07-24 00:25:20 +0900322/* SPI support */
323void __init txx9_spi_init(int busid, unsigned long base, int irq)
324{
325 struct resource res[] = {
326 {
327 .start = base,
328 .end = base + 0x20 - 1,
329 .flags = IORESOURCE_MEM,
330 }, {
331 .start = irq,
332 .flags = IORESOURCE_IRQ,
333 },
334 };
335 platform_device_register_simple("spi_txx9", busid,
336 res, ARRAY_SIZE(res));
337}
338
339void __init txx9_ethaddr_init(unsigned int id, unsigned char *ethaddr)
340{
341 struct platform_device *pdev =
342 platform_device_alloc("tc35815-mac", id);
343 if (!pdev ||
344 platform_device_add_data(pdev, ethaddr, 6) ||
345 platform_device_add(pdev))
346 platform_device_put(pdev);
347}
348
Atsushi Nemoto7779a5e2008-07-25 23:08:06 +0900349void __init txx9_sio_init(unsigned long baseaddr, int irq,
350 unsigned int line, unsigned int sclk, int nocts)
351{
352#ifdef CONFIG_SERIAL_TXX9
353 struct uart_port req;
354
355 memset(&req, 0, sizeof(req));
356 req.line = line;
357 req.iotype = UPIO_MEM;
358 req.membase = ioremap(baseaddr, 0x24);
359 req.mapbase = baseaddr;
360 req.irq = irq;
361 if (!nocts)
362 req.flags |= UPF_BUGGY_UART /*HAVE_CTS_LINE*/;
363 if (sclk) {
364 req.flags |= UPF_MAGIC_MULTIPLIER /*USE_SCLK*/;
365 req.uartclk = sclk;
366 } else
367 req.uartclk = TXX9_IMCLK;
368 early_serial_txx9_setup(&req);
369#endif /* CONFIG_SERIAL_TXX9 */
370}
371
Atsushi Nemotoe3529532008-07-29 22:10:08 +0900372#ifdef CONFIG_EARLY_PRINTK
373static void __init null_prom_putchar(char c)
374{
375}
376void (*txx9_prom_putchar)(char c) __initdata = null_prom_putchar;
377
378void __init prom_putchar(char c)
379{
380 txx9_prom_putchar(c);
381}
382
383static void __iomem *early_txx9_sio_port;
384
385static void __init early_txx9_sio_putchar(char c)
386{
387#define TXX9_SICISR 0x0c
388#define TXX9_SITFIFO 0x1c
389#define TXX9_SICISR_TXALS 0x00000002
390 while (!(__raw_readl(early_txx9_sio_port + TXX9_SICISR) &
391 TXX9_SICISR_TXALS))
392 ;
393 __raw_writel(c, early_txx9_sio_port + TXX9_SITFIFO);
394}
395
396void __init txx9_sio_putchar_init(unsigned long baseaddr)
397{
398 early_txx9_sio_port = ioremap(baseaddr, 0x24);
399 txx9_prom_putchar = early_txx9_sio_putchar;
400}
401#endif /* CONFIG_EARLY_PRINTK */
402
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900403/* wrappers */
404void __init plat_mem_setup(void)
405{
Atsushi Nemoto94a4c322008-07-19 01:51:47 +0900406 ioport_resource.start = 0;
407 ioport_resource.end = ~0UL; /* no limit */
408 iomem_resource.start = 0;
409 iomem_resource.end = ~0UL; /* no limit */
Atsushi Nemotoa49297e2008-07-24 00:25:17 +0900410
411 /* fallback restart/halt routines */
412 _machine_restart = (void (*)(char *))txx9_machine_halt;
413 _machine_halt = txx9_machine_halt;
414 pm_power_off = txx9_machine_halt;
415
Atsushi Nemoto07517522008-07-24 00:25:15 +0900416#ifdef CONFIG_PCI
417 pcibios_plat_setup = txx9_pcibios_setup;
418#endif
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900419 txx9_board_vec->mem_setup();
420}
421
422void __init arch_init_irq(void)
423{
424 txx9_board_vec->irq_setup();
425}
426
427void __init plat_time_init(void)
428{
Atsushi Nemoto1374d082008-07-31 22:29:53 +0900429#ifdef CONFIG_CPU_TX49XX
430 mips_hpt_frequency = txx9_cpu_clock / 2;
431#endif
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900432 txx9_board_vec->time_init();
433}
434
435static int __init _txx9_arch_init(void)
436{
437 if (txx9_board_vec->arch_init)
438 txx9_board_vec->arch_init();
439 return 0;
440}
441arch_initcall(_txx9_arch_init);
442
443static int __init _txx9_device_init(void)
444{
445 if (txx9_board_vec->device_init)
446 txx9_board_vec->device_init();
447 return 0;
448}
449device_initcall(_txx9_device_init);
450
451int (*txx9_irq_dispatch)(int pending);
452asmlinkage void plat_irq_dispatch(void)
453{
454 int pending = read_c0_status() & read_c0_cause() & ST0_IM;
455 int irq = txx9_irq_dispatch(pending);
456
457 if (likely(irq >= 0))
458 do_IRQ(irq);
459 else
460 spurious_interrupt();
461}
Atsushi Nemoto4c642f32008-07-13 23:37:56 +0900462
463/* see include/asm-mips/mach-tx39xx/mangle-port.h, for example. */
464#ifdef NEEDS_TXX9_SWIZZLE_ADDR_B
465static unsigned long __swizzle_addr_none(unsigned long port)
466{
467 return port;
468}
469unsigned long (*__swizzle_addr_b)(unsigned long port) = __swizzle_addr_none;
470EXPORT_SYMBOL(__swizzle_addr_b);
471#endif