blob: 82272e85a04212c31b5cf207be06661bf166c7aa [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 Nemotoedcaf1a2008-07-11 23:27:54 +090023#include <asm/bootinfo.h>
Atsushi Nemotoe0eb7302008-07-19 01:51:52 +090024#include <asm/time.h>
Atsushi Nemotoa49297e2008-07-24 00:25:17 +090025#include <asm/reboot.h>
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090026#include <asm/txx9/generic.h>
Atsushi Nemoto07517522008-07-24 00:25:15 +090027#include <asm/txx9/pci.h>
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090028#ifdef CONFIG_CPU_TX49XX
29#include <asm/txx9/tx4938.h>
30#endif
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090031
32/* EBUSC settings of TX4927, etc. */
33struct resource txx9_ce_res[8];
34static char txx9_ce_res_name[8][4]; /* "CEn" */
35
36/* pcode, internal register */
Atsushi Nemoto94a4c322008-07-19 01:51:47 +090037unsigned int txx9_pcode;
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090038char txx9_pcode_str[8];
39static struct resource txx9_reg_res = {
40 .name = txx9_pcode_str,
41 .flags = IORESOURCE_MEM,
42};
43void __init
44txx9_reg_res_init(unsigned int pcode, unsigned long base, unsigned long size)
45{
46 int i;
47
48 for (i = 0; i < ARRAY_SIZE(txx9_ce_res); i++) {
49 sprintf(txx9_ce_res_name[i], "CE%d", i);
50 txx9_ce_res[i].flags = IORESOURCE_MEM;
51 txx9_ce_res[i].name = txx9_ce_res_name[i];
52 }
53
54 sprintf(txx9_pcode_str, "TX%x", pcode);
55 if (base) {
56 txx9_reg_res.start = base & 0xfffffffffULL;
57 txx9_reg_res.end = (base & 0xfffffffffULL) + (size - 1);
58 request_resource(&iomem_resource, &txx9_reg_res);
59 }
60}
61
62/* clocks */
63unsigned int txx9_master_clock;
64unsigned int txx9_cpu_clock;
65unsigned int txx9_gbus_clock;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090066
Atsushi Nemoto94a4c322008-07-19 01:51:47 +090067int txx9_ccfg_toeon __initdata = 1;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090068
69/* Minimum CLK support */
70
71struct clk *clk_get(struct device *dev, const char *id)
72{
73 if (!strcmp(id, "spi-baseclk"))
Atsushi Nemoto94a4c322008-07-19 01:51:47 +090074 return (struct clk *)((unsigned long)txx9_gbus_clock / 2 / 4);
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090075 if (!strcmp(id, "imbus_clk"))
Atsushi Nemoto94a4c322008-07-19 01:51:47 +090076 return (struct clk *)((unsigned long)txx9_gbus_clock / 2);
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090077 return ERR_PTR(-ENOENT);
78}
79EXPORT_SYMBOL(clk_get);
80
81int clk_enable(struct clk *clk)
82{
83 return 0;
84}
85EXPORT_SYMBOL(clk_enable);
86
87void clk_disable(struct clk *clk)
88{
89}
90EXPORT_SYMBOL(clk_disable);
91
92unsigned long clk_get_rate(struct clk *clk)
93{
94 return (unsigned long)clk;
95}
96EXPORT_SYMBOL(clk_get_rate);
97
98void clk_put(struct clk *clk)
99{
100}
101EXPORT_SYMBOL(clk_put);
102
Atsushi Nemoto8d795f22008-07-18 00:43:48 +0900103/* GPIO support */
104
105#ifdef CONFIG_GENERIC_GPIO
106int gpio_to_irq(unsigned gpio)
107{
108 return -EINVAL;
109}
110EXPORT_SYMBOL(gpio_to_irq);
111
112int irq_to_gpio(unsigned irq)
113{
114 return -EINVAL;
115}
116EXPORT_SYMBOL(irq_to_gpio);
117#endif
118
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900119extern struct txx9_board_vec jmr3927_vec;
120extern struct txx9_board_vec rbtx4927_vec;
121extern struct txx9_board_vec rbtx4937_vec;
122extern struct txx9_board_vec rbtx4938_vec;
123
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900124struct txx9_board_vec *txx9_board_vec __initdata;
125static char txx9_system_type[32];
126
127void __init prom_init_cmdline(void)
128{
129 int argc = (int)fw_arg0;
130 char **argv = (char **)fw_arg1;
131 int i; /* Always ignore the "-c" at argv[0] */
Atsushi Nemoto94a4c322008-07-19 01:51:47 +0900132#ifdef CONFIG_64BIT
133 char *fixed_argv[32];
134 for (i = 0; i < argc; i++)
135 fixed_argv[i] = (char *)(long)(*((__s32 *)argv + i));
136 argv = fixed_argv;
137#endif
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900138
139 /* ignore all built-in args if any f/w args given */
140 if (argc > 1)
141 *arcs_cmdline = '\0';
142
143 for (i = 1; i < argc; i++) {
144 if (i != 1)
145 strcat(arcs_cmdline, " ");
146 strcat(arcs_cmdline, argv[i]);
147 }
148}
149
150void __init prom_init(void)
151{
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900152#ifdef CONFIG_CPU_TX39XX
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900153 txx9_board_vec = &jmr3927_vec;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900154#endif
155#ifdef CONFIG_CPU_TX49XX
156 switch (TX4938_REV_PCODE()) {
Atsushi Nemoto8d795f22008-07-18 00:43:48 +0900157#ifdef CONFIG_TOSHIBA_RBTX4927
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900158 case 0x4927:
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900159 txx9_board_vec = &rbtx4927_vec;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900160 break;
161 case 0x4937:
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900162 txx9_board_vec = &rbtx4937_vec;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900163 break;
Atsushi Nemoto8d795f22008-07-18 00:43:48 +0900164#endif
165#ifdef CONFIG_TOSHIBA_RBTX4938
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900166 case 0x4938:
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900167 txx9_board_vec = &rbtx4938_vec;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900168 break;
Atsushi Nemoto8d795f22008-07-18 00:43:48 +0900169#endif
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900170 }
171#endif
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900172
173 strcpy(txx9_system_type, txx9_board_vec->system);
174
Atsushi Nemoto7b226092008-07-14 00:15:04 +0900175 txx9_board_vec->prom_init();
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900176}
177
178void __init prom_free_prom_memory(void)
179{
180}
181
182const char *get_system_type(void)
183{
184 return txx9_system_type;
185}
186
187char * __init prom_getcmdline(void)
188{
189 return &(arcs_cmdline[0]);
190}
191
Atsushi Nemotoa49297e2008-07-24 00:25:17 +0900192static void __noreturn txx9_machine_halt(void)
193{
194 local_irq_disable();
195 clear_c0_status(ST0_IM);
196 while (1) {
197 if (cpu_wait) {
198 (*cpu_wait)();
199 if (cpu_has_counter) {
200 /*
201 * Clear counter interrupt while it
202 * breaks WAIT instruction even if
203 * masked.
204 */
205 write_c0_compare(0);
206 }
207 }
208 }
209}
210
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900211/* wrappers */
212void __init plat_mem_setup(void)
213{
Atsushi Nemoto94a4c322008-07-19 01:51:47 +0900214 ioport_resource.start = 0;
215 ioport_resource.end = ~0UL; /* no limit */
216 iomem_resource.start = 0;
217 iomem_resource.end = ~0UL; /* no limit */
Atsushi Nemotoa49297e2008-07-24 00:25:17 +0900218
219 /* fallback restart/halt routines */
220 _machine_restart = (void (*)(char *))txx9_machine_halt;
221 _machine_halt = txx9_machine_halt;
222 pm_power_off = txx9_machine_halt;
223
Atsushi Nemoto07517522008-07-24 00:25:15 +0900224#ifdef CONFIG_PCI
225 pcibios_plat_setup = txx9_pcibios_setup;
226#endif
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900227 txx9_board_vec->mem_setup();
228}
229
230void __init arch_init_irq(void)
231{
232 txx9_board_vec->irq_setup();
233}
234
235void __init plat_time_init(void)
236{
237 txx9_board_vec->time_init();
238}
239
240static int __init _txx9_arch_init(void)
241{
242 if (txx9_board_vec->arch_init)
243 txx9_board_vec->arch_init();
244 return 0;
245}
246arch_initcall(_txx9_arch_init);
247
248static int __init _txx9_device_init(void)
249{
250 if (txx9_board_vec->device_init)
251 txx9_board_vec->device_init();
252 return 0;
253}
254device_initcall(_txx9_device_init);
255
256int (*txx9_irq_dispatch)(int pending);
257asmlinkage void plat_irq_dispatch(void)
258{
259 int pending = read_c0_status() & read_c0_cause() & ST0_IM;
260 int irq = txx9_irq_dispatch(pending);
261
262 if (likely(irq >= 0))
263 do_IRQ(irq);
264 else
265 spurious_interrupt();
266}
Atsushi Nemoto4c642f32008-07-13 23:37:56 +0900267
268/* see include/asm-mips/mach-tx39xx/mangle-port.h, for example. */
269#ifdef NEEDS_TXX9_SWIZZLE_ADDR_B
270static unsigned long __swizzle_addr_none(unsigned long port)
271{
272 return port;
273}
274unsigned long (*__swizzle_addr_b)(unsigned long port) = __swizzle_addr_none;
275EXPORT_SYMBOL(__swizzle_addr_b);
276#endif