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