blob: 3715a8f5ea44e0beb3d007d312670e718978eb1f [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>
22#include <asm/bootinfo.h>
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090023#include <asm/txx9/generic.h>
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090024#ifdef CONFIG_CPU_TX49XX
25#include <asm/txx9/tx4938.h>
26#endif
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090027
28/* EBUSC settings of TX4927, etc. */
29struct resource txx9_ce_res[8];
30static char txx9_ce_res_name[8][4]; /* "CEn" */
31
32/* pcode, internal register */
Atsushi Nemoto94a4c322008-07-19 01:51:47 +090033unsigned int txx9_pcode;
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090034char txx9_pcode_str[8];
35static struct resource txx9_reg_res = {
36 .name = txx9_pcode_str,
37 .flags = IORESOURCE_MEM,
38};
39void __init
40txx9_reg_res_init(unsigned int pcode, unsigned long base, unsigned long size)
41{
42 int i;
43
44 for (i = 0; i < ARRAY_SIZE(txx9_ce_res); i++) {
45 sprintf(txx9_ce_res_name[i], "CE%d", i);
46 txx9_ce_res[i].flags = IORESOURCE_MEM;
47 txx9_ce_res[i].name = txx9_ce_res_name[i];
48 }
49
50 sprintf(txx9_pcode_str, "TX%x", pcode);
51 if (base) {
52 txx9_reg_res.start = base & 0xfffffffffULL;
53 txx9_reg_res.end = (base & 0xfffffffffULL) + (size - 1);
54 request_resource(&iomem_resource, &txx9_reg_res);
55 }
56}
57
58/* clocks */
59unsigned int txx9_master_clock;
60unsigned int txx9_cpu_clock;
61unsigned int txx9_gbus_clock;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090062
Atsushi Nemoto94a4c322008-07-19 01:51:47 +090063int txx9_ccfg_toeon __initdata = 1;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090064
65/* Minimum CLK support */
66
67struct clk *clk_get(struct device *dev, const char *id)
68{
69 if (!strcmp(id, "spi-baseclk"))
Atsushi Nemoto94a4c322008-07-19 01:51:47 +090070 return (struct clk *)((unsigned long)txx9_gbus_clock / 2 / 4);
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090071 if (!strcmp(id, "imbus_clk"))
Atsushi Nemoto94a4c322008-07-19 01:51:47 +090072 return (struct clk *)((unsigned long)txx9_gbus_clock / 2);
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090073 return ERR_PTR(-ENOENT);
74}
75EXPORT_SYMBOL(clk_get);
76
77int clk_enable(struct clk *clk)
78{
79 return 0;
80}
81EXPORT_SYMBOL(clk_enable);
82
83void clk_disable(struct clk *clk)
84{
85}
86EXPORT_SYMBOL(clk_disable);
87
88unsigned long clk_get_rate(struct clk *clk)
89{
90 return (unsigned long)clk;
91}
92EXPORT_SYMBOL(clk_get_rate);
93
94void clk_put(struct clk *clk)
95{
96}
97EXPORT_SYMBOL(clk_put);
98
Atsushi Nemoto8d795f22008-07-18 00:43:48 +090099/* GPIO support */
100
101#ifdef CONFIG_GENERIC_GPIO
102int gpio_to_irq(unsigned gpio)
103{
104 return -EINVAL;
105}
106EXPORT_SYMBOL(gpio_to_irq);
107
108int irq_to_gpio(unsigned irq)
109{
110 return -EINVAL;
111}
112EXPORT_SYMBOL(irq_to_gpio);
113#endif
114
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900115extern struct txx9_board_vec jmr3927_vec;
116extern struct txx9_board_vec rbtx4927_vec;
117extern struct txx9_board_vec rbtx4937_vec;
118extern struct txx9_board_vec rbtx4938_vec;
119
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900120struct txx9_board_vec *txx9_board_vec __initdata;
121static char txx9_system_type[32];
122
123void __init prom_init_cmdline(void)
124{
125 int argc = (int)fw_arg0;
126 char **argv = (char **)fw_arg1;
127 int i; /* Always ignore the "-c" at argv[0] */
Atsushi Nemoto94a4c322008-07-19 01:51:47 +0900128#ifdef CONFIG_64BIT
129 char *fixed_argv[32];
130 for (i = 0; i < argc; i++)
131 fixed_argv[i] = (char *)(long)(*((__s32 *)argv + i));
132 argv = fixed_argv;
133#endif
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900134
135 /* ignore all built-in args if any f/w args given */
136 if (argc > 1)
137 *arcs_cmdline = '\0';
138
139 for (i = 1; i < argc; i++) {
140 if (i != 1)
141 strcat(arcs_cmdline, " ");
142 strcat(arcs_cmdline, argv[i]);
143 }
144}
145
146void __init prom_init(void)
147{
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900148#ifdef CONFIG_CPU_TX39XX
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900149 txx9_board_vec = &jmr3927_vec;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900150#endif
151#ifdef CONFIG_CPU_TX49XX
152 switch (TX4938_REV_PCODE()) {
Atsushi Nemoto8d795f22008-07-18 00:43:48 +0900153#ifdef CONFIG_TOSHIBA_RBTX4927
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900154 case 0x4927:
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900155 txx9_board_vec = &rbtx4927_vec;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900156 break;
157 case 0x4937:
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900158 txx9_board_vec = &rbtx4937_vec;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900159 break;
Atsushi Nemoto8d795f22008-07-18 00:43:48 +0900160#endif
161#ifdef CONFIG_TOSHIBA_RBTX4938
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900162 case 0x4938:
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900163 txx9_board_vec = &rbtx4938_vec;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900164 break;
Atsushi Nemoto8d795f22008-07-18 00:43:48 +0900165#endif
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900166 }
167#endif
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900168
169 strcpy(txx9_system_type, txx9_board_vec->system);
170
Atsushi Nemoto7b226092008-07-14 00:15:04 +0900171 txx9_board_vec->prom_init();
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900172}
173
174void __init prom_free_prom_memory(void)
175{
176}
177
178const char *get_system_type(void)
179{
180 return txx9_system_type;
181}
182
183char * __init prom_getcmdline(void)
184{
185 return &(arcs_cmdline[0]);
186}
187
188/* wrappers */
189void __init plat_mem_setup(void)
190{
Atsushi Nemoto94a4c322008-07-19 01:51:47 +0900191 ioport_resource.start = 0;
192 ioport_resource.end = ~0UL; /* no limit */
193 iomem_resource.start = 0;
194 iomem_resource.end = ~0UL; /* no limit */
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900195 txx9_board_vec->mem_setup();
196}
197
198void __init arch_init_irq(void)
199{
200 txx9_board_vec->irq_setup();
201}
202
203void __init plat_time_init(void)
204{
205 txx9_board_vec->time_init();
206}
207
208static int __init _txx9_arch_init(void)
209{
210 if (txx9_board_vec->arch_init)
211 txx9_board_vec->arch_init();
212 return 0;
213}
214arch_initcall(_txx9_arch_init);
215
216static int __init _txx9_device_init(void)
217{
218 if (txx9_board_vec->device_init)
219 txx9_board_vec->device_init();
220 return 0;
221}
222device_initcall(_txx9_device_init);
223
224int (*txx9_irq_dispatch)(int pending);
225asmlinkage void plat_irq_dispatch(void)
226{
227 int pending = read_c0_status() & read_c0_cause() & ST0_IM;
228 int irq = txx9_irq_dispatch(pending);
229
230 if (likely(irq >= 0))
231 do_IRQ(irq);
232 else
233 spurious_interrupt();
234}
Atsushi Nemoto4c642f32008-07-13 23:37:56 +0900235
236/* see include/asm-mips/mach-tx39xx/mangle-port.h, for example. */
237#ifdef NEEDS_TXX9_SWIZZLE_ADDR_B
238static unsigned long __swizzle_addr_none(unsigned long port)
239{
240 return port;
241}
242unsigned long (*__swizzle_addr_b)(unsigned long port) = __swizzle_addr_none;
243EXPORT_SYMBOL(__swizzle_addr_b);
244#endif