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 <asm/bootinfo.h>
26 #include <asm/reboot.h>
27 #include <asm/txx9/generic.h>
28 #include <asm/txx9/pci.h>
29 #ifdef CONFIG_CPU_TX49XX
30 #include <asm/txx9/tx4938.h>
33 /* EBUSC settings of TX4927, etc. */
34 struct resource txx9_ce_res[8];
35 static char txx9_ce_res_name[8][4]; /* "CEn" */
37 /* pcode, internal register */
38 unsigned int txx9_pcode;
39 char txx9_pcode_str[8];
40 static struct resource txx9_reg_res = {
41 .name = txx9_pcode_str,
42 .flags = IORESOURCE_MEM,
45 txx9_reg_res_init(unsigned int pcode, unsigned long base, unsigned long size)
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];
55 sprintf(txx9_pcode_str, "TX%x", pcode);
57 txx9_reg_res.start = base & 0xfffffffffULL;
58 txx9_reg_res.end = (base & 0xfffffffffULL) + (size - 1);
59 request_resource(&iomem_resource, &txx9_reg_res);
64 unsigned int txx9_master_clock;
65 unsigned int txx9_cpu_clock;
66 unsigned int txx9_gbus_clock;
68 int txx9_ccfg_toeon __initdata = 1;
70 /* Minimum CLK support */
72 struct clk *clk_get(struct device *dev, const char *id)
74 if (!strcmp(id, "spi-baseclk"))
75 return (struct clk *)((unsigned long)txx9_gbus_clock / 2 / 4);
76 if (!strcmp(id, "imbus_clk"))
77 return (struct clk *)((unsigned long)txx9_gbus_clock / 2);
78 return ERR_PTR(-ENOENT);
80 EXPORT_SYMBOL(clk_get);
82 int clk_enable(struct clk *clk)
86 EXPORT_SYMBOL(clk_enable);
88 void clk_disable(struct clk *clk)
91 EXPORT_SYMBOL(clk_disable);
93 unsigned long clk_get_rate(struct clk *clk)
95 return (unsigned long)clk;
97 EXPORT_SYMBOL(clk_get_rate);
99 void clk_put(struct clk *clk)
102 EXPORT_SYMBOL(clk_put);
106 #ifdef CONFIG_GENERIC_GPIO
107 int gpio_to_irq(unsigned gpio)
111 EXPORT_SYMBOL(gpio_to_irq);
113 int irq_to_gpio(unsigned irq)
117 EXPORT_SYMBOL(irq_to_gpio);
120 extern struct txx9_board_vec jmr3927_vec;
121 extern struct txx9_board_vec rbtx4927_vec;
122 extern struct txx9_board_vec rbtx4937_vec;
123 extern struct txx9_board_vec rbtx4938_vec;
125 struct txx9_board_vec *txx9_board_vec __initdata;
126 static char txx9_system_type[32];
128 void __init prom_init_cmdline(void)
130 int argc = (int)fw_arg0;
131 char **argv = (char **)fw_arg1;
132 int i; /* Always ignore the "-c" at argv[0] */
134 char *fixed_argv[32];
135 for (i = 0; i < argc; i++)
136 fixed_argv[i] = (char *)(long)(*((__s32 *)argv + i));
140 /* ignore all built-in args if any f/w args given */
142 *arcs_cmdline = '\0';
144 for (i = 1; i < argc; i++) {
146 strcat(arcs_cmdline, " ");
147 strcat(arcs_cmdline, argv[i]);
151 void __init prom_init(void)
153 #ifdef CONFIG_CPU_TX39XX
154 txx9_board_vec = &jmr3927_vec;
156 #ifdef CONFIG_CPU_TX49XX
157 switch (TX4938_REV_PCODE()) {
158 #ifdef CONFIG_TOSHIBA_RBTX4927
160 txx9_board_vec = &rbtx4927_vec;
163 txx9_board_vec = &rbtx4937_vec;
166 #ifdef CONFIG_TOSHIBA_RBTX4938
168 txx9_board_vec = &rbtx4938_vec;
174 strcpy(txx9_system_type, txx9_board_vec->system);
176 txx9_board_vec->prom_init();
179 void __init prom_free_prom_memory(void)
183 const char *get_system_type(void)
185 return txx9_system_type;
188 char * __init prom_getcmdline(void)
190 return &(arcs_cmdline[0]);
193 static void __noreturn txx9_machine_halt(void)
196 clear_c0_status(ST0_IM);
200 if (cpu_has_counter) {
202 * Clear counter interrupt while it
203 * breaks WAIT instruction even if
212 /* Watchdog support */
213 void __init txx9_wdt_init(unsigned long base)
215 struct resource res = {
217 .end = base + 0x100 - 1,
218 .flags = IORESOURCE_MEM,
220 platform_device_register_simple("txx9wdt", -1, &res, 1);
224 void __init txx9_spi_init(int busid, unsigned long base, int irq)
226 struct resource res[] = {
229 .end = base + 0x20 - 1,
230 .flags = IORESOURCE_MEM,
233 .flags = IORESOURCE_IRQ,
236 platform_device_register_simple("spi_txx9", busid,
237 res, ARRAY_SIZE(res));
240 void __init txx9_ethaddr_init(unsigned int id, unsigned char *ethaddr)
242 struct platform_device *pdev =
243 platform_device_alloc("tc35815-mac", id);
245 platform_device_add_data(pdev, ethaddr, 6) ||
246 platform_device_add(pdev))
247 platform_device_put(pdev);
251 void __init plat_mem_setup(void)
253 ioport_resource.start = 0;
254 ioport_resource.end = ~0UL; /* no limit */
255 iomem_resource.start = 0;
256 iomem_resource.end = ~0UL; /* no limit */
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;
264 pcibios_plat_setup = txx9_pcibios_setup;
266 txx9_board_vec->mem_setup();
269 void __init arch_init_irq(void)
271 txx9_board_vec->irq_setup();
274 void __init plat_time_init(void)
276 txx9_board_vec->time_init();
279 static int __init _txx9_arch_init(void)
281 if (txx9_board_vec->arch_init)
282 txx9_board_vec->arch_init();
285 arch_initcall(_txx9_arch_init);
287 static int __init _txx9_device_init(void)
289 if (txx9_board_vec->device_init)
290 txx9_board_vec->device_init();
293 device_initcall(_txx9_device_init);
295 int (*txx9_irq_dispatch)(int pending);
296 asmlinkage void plat_irq_dispatch(void)
298 int pending = read_c0_status() & read_c0_cause() & ST0_IM;
299 int irq = txx9_irq_dispatch(pending);
301 if (likely(irq >= 0))
304 spurious_interrupt();
307 /* see include/asm-mips/mach-tx39xx/mangle-port.h, for example. */
308 #ifdef NEEDS_TXX9_SWIZZLE_ADDR_B
309 static unsigned long __swizzle_addr_none(unsigned long port)
313 unsigned long (*__swizzle_addr_b)(unsigned long port) = __swizzle_addr_none;
314 EXPORT_SYMBOL(__swizzle_addr_b);