blob: 8c60c78b9a9e0506d2eb3307e6bbda8e1dbef710 [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 Nemoto89d63fe2008-07-11 00:33:08 +090025#include <asm/txx9/generic.h>
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090026#ifdef CONFIG_CPU_TX49XX
27#include <asm/txx9/tx4938.h>
28#endif
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090029
30/* EBUSC settings of TX4927, etc. */
31struct resource txx9_ce_res[8];
32static char txx9_ce_res_name[8][4]; /* "CEn" */
33
34/* pcode, internal register */
Atsushi Nemoto94a4c322008-07-19 01:51:47 +090035unsigned int txx9_pcode;
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090036char txx9_pcode_str[8];
37static struct resource txx9_reg_res = {
38 .name = txx9_pcode_str,
39 .flags = IORESOURCE_MEM,
40};
41void __init
42txx9_reg_res_init(unsigned int pcode, unsigned long base, unsigned long size)
43{
44 int i;
45
46 for (i = 0; i < ARRAY_SIZE(txx9_ce_res); i++) {
47 sprintf(txx9_ce_res_name[i], "CE%d", i);
48 txx9_ce_res[i].flags = IORESOURCE_MEM;
49 txx9_ce_res[i].name = txx9_ce_res_name[i];
50 }
51
52 sprintf(txx9_pcode_str, "TX%x", pcode);
53 if (base) {
54 txx9_reg_res.start = base & 0xfffffffffULL;
55 txx9_reg_res.end = (base & 0xfffffffffULL) + (size - 1);
56 request_resource(&iomem_resource, &txx9_reg_res);
57 }
58}
59
60/* clocks */
61unsigned int txx9_master_clock;
62unsigned int txx9_cpu_clock;
63unsigned int txx9_gbus_clock;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090064
Atsushi Nemoto94a4c322008-07-19 01:51:47 +090065int txx9_ccfg_toeon __initdata = 1;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090066
67/* Minimum CLK support */
68
69struct clk *clk_get(struct device *dev, const char *id)
70{
71 if (!strcmp(id, "spi-baseclk"))
Atsushi Nemoto94a4c322008-07-19 01:51:47 +090072 return (struct clk *)((unsigned long)txx9_gbus_clock / 2 / 4);
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090073 if (!strcmp(id, "imbus_clk"))
Atsushi Nemoto94a4c322008-07-19 01:51:47 +090074 return (struct clk *)((unsigned long)txx9_gbus_clock / 2);
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090075 return ERR_PTR(-ENOENT);
76}
77EXPORT_SYMBOL(clk_get);
78
79int clk_enable(struct clk *clk)
80{
81 return 0;
82}
83EXPORT_SYMBOL(clk_enable);
84
85void clk_disable(struct clk *clk)
86{
87}
88EXPORT_SYMBOL(clk_disable);
89
90unsigned long clk_get_rate(struct clk *clk)
91{
92 return (unsigned long)clk;
93}
94EXPORT_SYMBOL(clk_get_rate);
95
96void clk_put(struct clk *clk)
97{
98}
99EXPORT_SYMBOL(clk_put);
100
Atsushi Nemoto8d795f22008-07-18 00:43:48 +0900101/* GPIO support */
102
103#ifdef CONFIG_GENERIC_GPIO
104int gpio_to_irq(unsigned gpio)
105{
106 return -EINVAL;
107}
108EXPORT_SYMBOL(gpio_to_irq);
109
110int irq_to_gpio(unsigned irq)
111{
112 return -EINVAL;
113}
114EXPORT_SYMBOL(irq_to_gpio);
115#endif
116
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900117extern struct txx9_board_vec jmr3927_vec;
118extern struct txx9_board_vec rbtx4927_vec;
119extern struct txx9_board_vec rbtx4937_vec;
120extern struct txx9_board_vec rbtx4938_vec;
121
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900122struct txx9_board_vec *txx9_board_vec __initdata;
123static char txx9_system_type[32];
124
125void __init prom_init_cmdline(void)
126{
127 int argc = (int)fw_arg0;
128 char **argv = (char **)fw_arg1;
129 int i; /* Always ignore the "-c" at argv[0] */
Atsushi Nemoto94a4c322008-07-19 01:51:47 +0900130#ifdef CONFIG_64BIT
131 char *fixed_argv[32];
132 for (i = 0; i < argc; i++)
133 fixed_argv[i] = (char *)(long)(*((__s32 *)argv + i));
134 argv = fixed_argv;
135#endif
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900136
137 /* ignore all built-in args if any f/w args given */
138 if (argc > 1)
139 *arcs_cmdline = '\0';
140
141 for (i = 1; i < argc; i++) {
142 if (i != 1)
143 strcat(arcs_cmdline, " ");
144 strcat(arcs_cmdline, argv[i]);
145 }
146}
147
148void __init prom_init(void)
149{
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900150#ifdef CONFIG_CPU_TX39XX
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900151 txx9_board_vec = &jmr3927_vec;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900152#endif
153#ifdef CONFIG_CPU_TX49XX
154 switch (TX4938_REV_PCODE()) {
Atsushi Nemoto8d795f22008-07-18 00:43:48 +0900155#ifdef CONFIG_TOSHIBA_RBTX4927
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900156 case 0x4927:
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900157 txx9_board_vec = &rbtx4927_vec;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900158 break;
159 case 0x4937:
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900160 txx9_board_vec = &rbtx4937_vec;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900161 break;
Atsushi Nemoto8d795f22008-07-18 00:43:48 +0900162#endif
163#ifdef CONFIG_TOSHIBA_RBTX4938
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900164 case 0x4938:
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900165 txx9_board_vec = &rbtx4938_vec;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900166 break;
Atsushi Nemoto8d795f22008-07-18 00:43:48 +0900167#endif
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900168 }
169#endif
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900170
171 strcpy(txx9_system_type, txx9_board_vec->system);
172
Atsushi Nemoto7b226092008-07-14 00:15:04 +0900173 txx9_board_vec->prom_init();
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900174}
175
176void __init prom_free_prom_memory(void)
177{
178}
179
180const char *get_system_type(void)
181{
182 return txx9_system_type;
183}
184
185char * __init prom_getcmdline(void)
186{
187 return &(arcs_cmdline[0]);
188}
189
190/* wrappers */
191void __init plat_mem_setup(void)
192{
Atsushi Nemoto94a4c322008-07-19 01:51:47 +0900193 ioport_resource.start = 0;
194 ioport_resource.end = ~0UL; /* no limit */
195 iomem_resource.start = 0;
196 iomem_resource.end = ~0UL; /* no limit */
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900197 txx9_board_vec->mem_setup();
198}
199
200void __init arch_init_irq(void)
201{
202 txx9_board_vec->irq_setup();
203}
204
205void __init plat_time_init(void)
206{
207 txx9_board_vec->time_init();
208}
209
210static int __init _txx9_arch_init(void)
211{
212 if (txx9_board_vec->arch_init)
213 txx9_board_vec->arch_init();
214 return 0;
215}
216arch_initcall(_txx9_arch_init);
217
218static int __init _txx9_device_init(void)
219{
220 if (txx9_board_vec->device_init)
221 txx9_board_vec->device_init();
222 return 0;
223}
224device_initcall(_txx9_device_init);
225
226int (*txx9_irq_dispatch)(int pending);
227asmlinkage void plat_irq_dispatch(void)
228{
229 int pending = read_c0_status() & read_c0_cause() & ST0_IM;
230 int irq = txx9_irq_dispatch(pending);
231
232 if (likely(irq >= 0))
233 do_IRQ(irq);
234 else
235 spurious_interrupt();
236}
Atsushi Nemoto4c642f32008-07-13 23:37:56 +0900237
238/* see include/asm-mips/mach-tx39xx/mangle-port.h, for example. */
239#ifdef NEEDS_TXX9_SWIZZLE_ADDR_B
240static unsigned long __swizzle_addr_none(unsigned long port)
241{
242 return port;
243}
244unsigned long (*__swizzle_addr_b)(unsigned long port) = __swizzle_addr_none;
245EXPORT_SYMBOL(__swizzle_addr_b);
246#endif