]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/mips/txx9/generic/setup.c
82272e85a04212c31b5cf207be06661bf166c7aa
[linux-2.6-omap-h63xx.git] / arch / mips / txx9 / generic / setup.c
1 /*
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>
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 <asm/bootinfo.h>
24 #include <asm/time.h>
25 #include <asm/reboot.h>
26 #include <asm/txx9/generic.h>
27 #include <asm/txx9/pci.h>
28 #ifdef CONFIG_CPU_TX49XX
29 #include <asm/txx9/tx4938.h>
30 #endif
31
32 /* EBUSC settings of TX4927, etc. */
33 struct resource txx9_ce_res[8];
34 static char txx9_ce_res_name[8][4];     /* "CEn" */
35
36 /* pcode, internal register */
37 unsigned int txx9_pcode;
38 char txx9_pcode_str[8];
39 static struct resource txx9_reg_res = {
40         .name = txx9_pcode_str,
41         .flags = IORESOURCE_MEM,
42 };
43 void __init
44 txx9_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 */
63 unsigned int txx9_master_clock;
64 unsigned int txx9_cpu_clock;
65 unsigned int txx9_gbus_clock;
66
67 int txx9_ccfg_toeon __initdata = 1;
68
69 /* Minimum CLK support */
70
71 struct clk *clk_get(struct device *dev, const char *id)
72 {
73         if (!strcmp(id, "spi-baseclk"))
74                 return (struct clk *)((unsigned long)txx9_gbus_clock / 2 / 4);
75         if (!strcmp(id, "imbus_clk"))
76                 return (struct clk *)((unsigned long)txx9_gbus_clock / 2);
77         return ERR_PTR(-ENOENT);
78 }
79 EXPORT_SYMBOL(clk_get);
80
81 int clk_enable(struct clk *clk)
82 {
83         return 0;
84 }
85 EXPORT_SYMBOL(clk_enable);
86
87 void clk_disable(struct clk *clk)
88 {
89 }
90 EXPORT_SYMBOL(clk_disable);
91
92 unsigned long clk_get_rate(struct clk *clk)
93 {
94         return (unsigned long)clk;
95 }
96 EXPORT_SYMBOL(clk_get_rate);
97
98 void clk_put(struct clk *clk)
99 {
100 }
101 EXPORT_SYMBOL(clk_put);
102
103 /* GPIO support */
104
105 #ifdef CONFIG_GENERIC_GPIO
106 int gpio_to_irq(unsigned gpio)
107 {
108         return -EINVAL;
109 }
110 EXPORT_SYMBOL(gpio_to_irq);
111
112 int irq_to_gpio(unsigned irq)
113 {
114         return -EINVAL;
115 }
116 EXPORT_SYMBOL(irq_to_gpio);
117 #endif
118
119 extern struct txx9_board_vec jmr3927_vec;
120 extern struct txx9_board_vec rbtx4927_vec;
121 extern struct txx9_board_vec rbtx4937_vec;
122 extern struct txx9_board_vec rbtx4938_vec;
123
124 struct txx9_board_vec *txx9_board_vec __initdata;
125 static char txx9_system_type[32];
126
127 void __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] */
132 #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
138
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
150 void __init prom_init(void)
151 {
152 #ifdef CONFIG_CPU_TX39XX
153         txx9_board_vec = &jmr3927_vec;
154 #endif
155 #ifdef CONFIG_CPU_TX49XX
156         switch (TX4938_REV_PCODE()) {
157 #ifdef CONFIG_TOSHIBA_RBTX4927
158         case 0x4927:
159                 txx9_board_vec = &rbtx4927_vec;
160                 break;
161         case 0x4937:
162                 txx9_board_vec = &rbtx4937_vec;
163                 break;
164 #endif
165 #ifdef CONFIG_TOSHIBA_RBTX4938
166         case 0x4938:
167                 txx9_board_vec = &rbtx4938_vec;
168                 break;
169 #endif
170         }
171 #endif
172
173         strcpy(txx9_system_type, txx9_board_vec->system);
174
175         txx9_board_vec->prom_init();
176 }
177
178 void __init prom_free_prom_memory(void)
179 {
180 }
181
182 const char *get_system_type(void)
183 {
184         return txx9_system_type;
185 }
186
187 char * __init prom_getcmdline(void)
188 {
189         return &(arcs_cmdline[0]);
190 }
191
192 static 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
211 /* wrappers */
212 void __init plat_mem_setup(void)
213 {
214         ioport_resource.start = 0;
215         ioport_resource.end = ~0UL;     /* no limit */
216         iomem_resource.start = 0;
217         iomem_resource.end = ~0UL;      /* no limit */
218
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
224 #ifdef CONFIG_PCI
225         pcibios_plat_setup = txx9_pcibios_setup;
226 #endif
227         txx9_board_vec->mem_setup();
228 }
229
230 void __init arch_init_irq(void)
231 {
232         txx9_board_vec->irq_setup();
233 }
234
235 void __init plat_time_init(void)
236 {
237         txx9_board_vec->time_init();
238 }
239
240 static int __init _txx9_arch_init(void)
241 {
242         if (txx9_board_vec->arch_init)
243                 txx9_board_vec->arch_init();
244         return 0;
245 }
246 arch_initcall(_txx9_arch_init);
247
248 static int __init _txx9_device_init(void)
249 {
250         if (txx9_board_vec->device_init)
251                 txx9_board_vec->device_init();
252         return 0;
253 }
254 device_initcall(_txx9_device_init);
255
256 int (*txx9_irq_dispatch)(int pending);
257 asmlinkage 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 }
267
268 /* see include/asm-mips/mach-tx39xx/mangle-port.h, for example. */
269 #ifdef NEEDS_TXX9_SWIZZLE_ADDR_B
270 static unsigned long __swizzle_addr_none(unsigned long port)
271 {
272         return port;
273 }
274 unsigned long (*__swizzle_addr_b)(unsigned long port) = __swizzle_addr_none;
275 EXPORT_SYMBOL(__swizzle_addr_b);
276 #endif