2 * linux/arch/mips/txx9/generic/setup.c
4 * Based on linux/arch/mips/txx9/rbtx4938/setup.c,
5 * and RBTX49xx patch from CELF patch archive.
7 * 2003-2005 (c) MontaVista Software, Inc.
8 * (C) Copyright TOSHIBA CORPORATION 2000-2001, 2004-2007
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
14 #include <linux/init.h>
15 #include <linux/kernel.h>
16 #include <linux/types.h>
17 #include <linux/interrupt.h>
18 #include <linux/string.h>
19 #include <linux/module.h>
20 #include <linux/clk.h>
21 #include <linux/err.h>
22 #include <linux/gpio.h>
23 #include <linux/platform_device.h>
24 #include <linux/serial_core.h>
25 #include <asm/bootinfo.h>
27 #include <asm/reboot.h>
28 #include <asm/txx9/generic.h>
29 #include <asm/txx9/pci.h>
30 #ifdef CONFIG_CPU_TX49XX
31 #include <asm/txx9/tx4938.h>
34 /* EBUSC settings of TX4927, etc. */
35 struct resource txx9_ce_res[8];
36 static char txx9_ce_res_name[8][4]; /* "CEn" */
38 /* pcode, internal register */
39 unsigned int txx9_pcode;
40 char txx9_pcode_str[8];
41 static struct resource txx9_reg_res = {
42 .name = txx9_pcode_str,
43 .flags = IORESOURCE_MEM,
46 txx9_reg_res_init(unsigned int pcode, unsigned long base, unsigned long size)
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];
57 sprintf(txx9_pcode_str, "TX%x", pcode);
59 txx9_reg_res.start = base & 0xfffffffffULL;
60 txx9_reg_res.end = (base & 0xfffffffffULL) + (size - 1);
61 request_resource(&iomem_resource, &txx9_reg_res);
66 unsigned int txx9_master_clock;
67 unsigned int txx9_cpu_clock;
68 unsigned int txx9_gbus_clock;
70 int txx9_ccfg_toeon __initdata = 1;
72 /* Minimum CLK support */
74 struct clk *clk_get(struct device *dev, const char *id)
76 if (!strcmp(id, "spi-baseclk"))
77 return (struct clk *)((unsigned long)txx9_gbus_clock / 2 / 4);
78 if (!strcmp(id, "imbus_clk"))
79 return (struct clk *)((unsigned long)txx9_gbus_clock / 2);
80 return ERR_PTR(-ENOENT);
82 EXPORT_SYMBOL(clk_get);
84 int clk_enable(struct clk *clk)
88 EXPORT_SYMBOL(clk_enable);
90 void clk_disable(struct clk *clk)
93 EXPORT_SYMBOL(clk_disable);
95 unsigned long clk_get_rate(struct clk *clk)
97 return (unsigned long)clk;
99 EXPORT_SYMBOL(clk_get_rate);
101 void clk_put(struct clk *clk)
104 EXPORT_SYMBOL(clk_put);
108 #ifdef CONFIG_GENERIC_GPIO
109 int gpio_to_irq(unsigned gpio)
113 EXPORT_SYMBOL(gpio_to_irq);
115 int irq_to_gpio(unsigned irq)
119 EXPORT_SYMBOL(irq_to_gpio);
122 #define BOARD_VEC(board) extern struct txx9_board_vec board;
123 #include <asm/txx9/boards.h>
126 struct txx9_board_vec *txx9_board_vec __initdata;
127 static char txx9_system_type[32];
129 static struct txx9_board_vec *board_vecs[] __initdata = {
130 #define BOARD_VEC(board) &board,
131 #include <asm/txx9/boards.h>
135 static struct txx9_board_vec *__init find_board_byname(const char *name)
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];
147 static void __init prom_init_cmdline(void)
149 int argc = (int)fw_arg0;
150 int *argv32 = (int *)fw_arg1;
151 int i; /* Always ignore the "-c" at argv[0] */
152 char builtin[CL_SIZE];
154 /* ignore all built-in args if any f/w args given */
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.
161 if (arcs_cmdline[0] == '+')
162 strcpy(builtin, arcs_cmdline + 1);
163 else if (arcs_cmdline[0] == '-') {
164 strcpy(builtin, arcs_cmdline + 1);
166 } else if (argc <= 1)
167 strcpy(builtin, arcs_cmdline);
168 arcs_cmdline[0] = '\0';
170 for (i = 1; i < argc; i++) {
171 char *str = (char *)(long)argv32[i];
173 strcat(arcs_cmdline, " ");
174 if (strchr(str, ' ')) {
175 strcat(arcs_cmdline, "\"");
176 strcat(arcs_cmdline, str);
177 strcat(arcs_cmdline, "\"");
179 strcat(arcs_cmdline, str);
181 /* append saved builtin args */
184 strcat(arcs_cmdline, " ");
185 strcat(arcs_cmdline, builtin);
189 static void __init preprocess_cmdline(void)
191 char cmdline[CL_SIZE];
194 strcpy(cmdline, arcs_cmdline);
196 arcs_cmdline[0] = '\0';
198 char *str = strsep(&s, " ");
199 if (strncmp(str, "board=", 6) == 0) {
200 txx9_board_vec = find_board_byname(str + 6);
202 } else if (strncmp(str, "masterclk=", 10) == 0) {
204 if (strict_strtoul(str + 10, 10, &val) == 0)
205 txx9_master_clock = val;
209 strcat(arcs_cmdline, " ");
210 strcat(arcs_cmdline, str);
214 static void __init select_board(void)
218 /* first, determine by "board=" argument in preprocess_cmdline() */
221 /* next, determine by "board" envvar */
222 envstr = prom_getenv("board");
224 txx9_board_vec = find_board_byname(envstr);
229 /* select "default" board */
230 #ifdef CONFIG_CPU_TX39XX
231 txx9_board_vec = &jmr3927_vec;
233 #ifdef CONFIG_CPU_TX49XX
234 switch (TX4938_REV_PCODE()) {
235 #ifdef CONFIG_TOSHIBA_RBTX4927
237 txx9_board_vec = &rbtx4927_vec;
240 txx9_board_vec = &rbtx4937_vec;
243 #ifdef CONFIG_TOSHIBA_RBTX4938
245 txx9_board_vec = &rbtx4938_vec;
252 void __init prom_init(void)
255 preprocess_cmdline();
258 strcpy(txx9_system_type, txx9_board_vec->system);
260 txx9_board_vec->prom_init();
263 void __init prom_free_prom_memory(void)
267 const char *get_system_type(void)
269 return txx9_system_type;
272 char * __init prom_getcmdline(void)
274 return &(arcs_cmdline[0]);
277 const char *__init prom_getenv(const char *name)
279 const s32 *str = (const s32 *)fw_arg2;
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];
292 static void __noreturn txx9_machine_halt(void)
295 clear_c0_status(ST0_IM);
299 if (cpu_has_counter) {
301 * Clear counter interrupt while it
302 * breaks WAIT instruction even if
311 /* Watchdog support */
312 void __init txx9_wdt_init(unsigned long base)
314 struct resource res = {
316 .end = base + 0x100 - 1,
317 .flags = IORESOURCE_MEM,
319 platform_device_register_simple("txx9wdt", -1, &res, 1);
323 void __init txx9_spi_init(int busid, unsigned long base, int irq)
325 struct resource res[] = {
328 .end = base + 0x20 - 1,
329 .flags = IORESOURCE_MEM,
332 .flags = IORESOURCE_IRQ,
335 platform_device_register_simple("spi_txx9", busid,
336 res, ARRAY_SIZE(res));
339 void __init txx9_ethaddr_init(unsigned int id, unsigned char *ethaddr)
341 struct platform_device *pdev =
342 platform_device_alloc("tc35815-mac", id);
344 platform_device_add_data(pdev, ethaddr, 6) ||
345 platform_device_add(pdev))
346 platform_device_put(pdev);
349 void __init txx9_sio_init(unsigned long baseaddr, int irq,
350 unsigned int line, unsigned int sclk, int nocts)
352 #ifdef CONFIG_SERIAL_TXX9
353 struct uart_port req;
355 memset(&req, 0, sizeof(req));
357 req.iotype = UPIO_MEM;
358 req.membase = ioremap(baseaddr, 0x24);
359 req.mapbase = baseaddr;
362 req.flags |= UPF_BUGGY_UART /*HAVE_CTS_LINE*/;
364 req.flags |= UPF_MAGIC_MULTIPLIER /*USE_SCLK*/;
367 req.uartclk = TXX9_IMCLK;
368 early_serial_txx9_setup(&req);
369 #endif /* CONFIG_SERIAL_TXX9 */
372 #ifdef CONFIG_EARLY_PRINTK
373 static void __init null_prom_putchar(char c)
376 void (*txx9_prom_putchar)(char c) __initdata = null_prom_putchar;
378 void __init prom_putchar(char c)
380 txx9_prom_putchar(c);
383 static void __iomem *early_txx9_sio_port;
385 static void __init early_txx9_sio_putchar(char c)
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) &
393 __raw_writel(c, early_txx9_sio_port + TXX9_SITFIFO);
396 void __init txx9_sio_putchar_init(unsigned long baseaddr)
398 early_txx9_sio_port = ioremap(baseaddr, 0x24);
399 txx9_prom_putchar = early_txx9_sio_putchar;
401 #endif /* CONFIG_EARLY_PRINTK */
404 void __init plat_mem_setup(void)
406 ioport_resource.start = 0;
407 ioport_resource.end = ~0UL; /* no limit */
408 iomem_resource.start = 0;
409 iomem_resource.end = ~0UL; /* no limit */
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;
417 pcibios_plat_setup = txx9_pcibios_setup;
419 txx9_board_vec->mem_setup();
422 void __init arch_init_irq(void)
424 txx9_board_vec->irq_setup();
427 void __init plat_time_init(void)
429 #ifdef CONFIG_CPU_TX49XX
430 mips_hpt_frequency = txx9_cpu_clock / 2;
432 txx9_board_vec->time_init();
435 static int __init _txx9_arch_init(void)
437 if (txx9_board_vec->arch_init)
438 txx9_board_vec->arch_init();
441 arch_initcall(_txx9_arch_init);
443 static int __init _txx9_device_init(void)
445 if (txx9_board_vec->device_init)
446 txx9_board_vec->device_init();
449 device_initcall(_txx9_device_init);
451 int (*txx9_irq_dispatch)(int pending);
452 asmlinkage void plat_irq_dispatch(void)
454 int pending = read_c0_status() & read_c0_cause() & ST0_IM;
455 int irq = txx9_irq_dispatch(pending);
457 if (likely(irq >= 0))
460 spurious_interrupt();
463 /* see include/asm-mips/mach-tx39xx/mangle-port.h, for example. */
464 #ifdef NEEDS_TXX9_SWIZZLE_ADDR_B
465 static unsigned long __swizzle_addr_none(unsigned long port)
469 unsigned long (*__swizzle_addr_b)(unsigned long port) = __swizzle_addr_none;
470 EXPORT_SYMBOL(__swizzle_addr_b);