]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/mips/txx9/generic/setup.c
005179c2af21ffc892bea142f97eeac0f3a95fd4
[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 <linux/platform_device.h>
24 #include <linux/serial_core.h>
25 #include <asm/bootinfo.h>
26 #include <asm/time.h>
27 #include <asm/reboot.h>
28 #include <asm/txx9/generic.h>
29 #include <asm/txx9/pci.h>
30 #ifdef CONFIG_CPU_TX49XX
31 #include <asm/txx9/tx4938.h>
32 #endif
33
34 /* EBUSC settings of TX4927, etc. */
35 struct resource txx9_ce_res[8];
36 static char txx9_ce_res_name[8][4];     /* "CEn" */
37
38 /* pcode, internal register */
39 unsigned int txx9_pcode;
40 char txx9_pcode_str[8];
41 static struct resource txx9_reg_res = {
42         .name = txx9_pcode_str,
43         .flags = IORESOURCE_MEM,
44 };
45 void __init
46 txx9_reg_res_init(unsigned int pcode, unsigned long base, unsigned long size)
47 {
48         int i;
49
50         for (i = 0; i < ARRAY_SIZE(txx9_ce_res); i++) {
51                 sprintf(txx9_ce_res_name[i], "CE%d", i);
52                 txx9_ce_res[i].flags = IORESOURCE_MEM;
53                 txx9_ce_res[i].name = txx9_ce_res_name[i];
54         }
55
56         txx9_pcode = pcode;
57         sprintf(txx9_pcode_str, "TX%x", pcode);
58         if (base) {
59                 txx9_reg_res.start = base & 0xfffffffffULL;
60                 txx9_reg_res.end = (base & 0xfffffffffULL) + (size - 1);
61                 request_resource(&iomem_resource, &txx9_reg_res);
62         }
63 }
64
65 /* clocks */
66 unsigned int txx9_master_clock;
67 unsigned int txx9_cpu_clock;
68 unsigned int txx9_gbus_clock;
69
70 int txx9_ccfg_toeon __initdata = 1;
71
72 /* Minimum CLK support */
73
74 struct clk *clk_get(struct device *dev, const char *id)
75 {
76         if (!strcmp(id, "spi-baseclk"))
77                 return (struct clk *)((unsigned long)txx9_gbus_clock / 2 / 4);
78         if (!strcmp(id, "imbus_clk"))
79                 return (struct clk *)((unsigned long)txx9_gbus_clock / 2);
80         return ERR_PTR(-ENOENT);
81 }
82 EXPORT_SYMBOL(clk_get);
83
84 int clk_enable(struct clk *clk)
85 {
86         return 0;
87 }
88 EXPORT_SYMBOL(clk_enable);
89
90 void clk_disable(struct clk *clk)
91 {
92 }
93 EXPORT_SYMBOL(clk_disable);
94
95 unsigned long clk_get_rate(struct clk *clk)
96 {
97         return (unsigned long)clk;
98 }
99 EXPORT_SYMBOL(clk_get_rate);
100
101 void clk_put(struct clk *clk)
102 {
103 }
104 EXPORT_SYMBOL(clk_put);
105
106 /* GPIO support */
107
108 #ifdef CONFIG_GENERIC_GPIO
109 int gpio_to_irq(unsigned gpio)
110 {
111         return -EINVAL;
112 }
113 EXPORT_SYMBOL(gpio_to_irq);
114
115 int irq_to_gpio(unsigned irq)
116 {
117         return -EINVAL;
118 }
119 EXPORT_SYMBOL(irq_to_gpio);
120 #endif
121
122 extern struct txx9_board_vec jmr3927_vec;
123 extern struct txx9_board_vec rbtx4927_vec;
124 extern struct txx9_board_vec rbtx4937_vec;
125 extern struct txx9_board_vec rbtx4938_vec;
126
127 struct txx9_board_vec *txx9_board_vec __initdata;
128 static char txx9_system_type[32];
129
130 static void __init prom_init_cmdline(void)
131 {
132         int argc = (int)fw_arg0;
133         int *argv32 = (int *)fw_arg1;
134         int i;                  /* Always ignore the "-c" at argv[0] */
135         char builtin[CL_SIZE];
136
137         /* ignore all built-in args if any f/w args given */
138         /*
139          * But if built-in strings was started with '+', append them
140          * to command line args.  If built-in was started with '-',
141          * ignore all f/w args.
142          */
143         builtin[0] = '\0';
144         if (arcs_cmdline[0] == '+')
145                 strcpy(builtin, arcs_cmdline + 1);
146         else if (arcs_cmdline[0] == '-') {
147                 strcpy(builtin, arcs_cmdline + 1);
148                 argc = 0;
149         } else if (argc <= 1)
150                 strcpy(builtin, arcs_cmdline);
151         arcs_cmdline[0] = '\0';
152
153         for (i = 1; i < argc; i++) {
154                 char *str = (char *)(long)argv32[i];
155                 if (i != 1)
156                         strcat(arcs_cmdline, " ");
157                 if (strchr(str, ' ')) {
158                         strcat(arcs_cmdline, "\"");
159                         strcat(arcs_cmdline, str);
160                         strcat(arcs_cmdline, "\"");
161                 } else
162                         strcat(arcs_cmdline, str);
163         }
164         /* append saved builtin args */
165         if (builtin[0]) {
166                 if (arcs_cmdline[0])
167                         strcat(arcs_cmdline, " ");
168                 strcat(arcs_cmdline, builtin);
169         }
170 }
171
172 void __init prom_init(void)
173 {
174         prom_init_cmdline();
175 #ifdef CONFIG_CPU_TX39XX
176         txx9_board_vec = &jmr3927_vec;
177 #endif
178 #ifdef CONFIG_CPU_TX49XX
179         switch (TX4938_REV_PCODE()) {
180 #ifdef CONFIG_TOSHIBA_RBTX4927
181         case 0x4927:
182                 txx9_board_vec = &rbtx4927_vec;
183                 break;
184         case 0x4937:
185                 txx9_board_vec = &rbtx4937_vec;
186                 break;
187 #endif
188 #ifdef CONFIG_TOSHIBA_RBTX4938
189         case 0x4938:
190                 txx9_board_vec = &rbtx4938_vec;
191                 break;
192 #endif
193         }
194 #endif
195
196         strcpy(txx9_system_type, txx9_board_vec->system);
197
198         txx9_board_vec->prom_init();
199 }
200
201 void __init prom_free_prom_memory(void)
202 {
203 }
204
205 const char *get_system_type(void)
206 {
207         return txx9_system_type;
208 }
209
210 char * __init prom_getcmdline(void)
211 {
212         return &(arcs_cmdline[0]);
213 }
214
215 const char *__init prom_getenv(const char *name)
216 {
217         const s32 *str = (const s32 *)fw_arg2;
218
219         if (!str)
220                 return NULL;
221         /* YAMON style ("name", "value" pairs) */
222         while (str[0] && str[1]) {
223                 if (!strcmp((const char *)(unsigned long)str[0], name))
224                         return (const char *)(unsigned long)str[1];
225                 str += 2;
226         }
227         return NULL;
228 }
229
230 static void __noreturn txx9_machine_halt(void)
231 {
232         local_irq_disable();
233         clear_c0_status(ST0_IM);
234         while (1) {
235                 if (cpu_wait) {
236                         (*cpu_wait)();
237                         if (cpu_has_counter) {
238                                 /*
239                                  * Clear counter interrupt while it
240                                  * breaks WAIT instruction even if
241                                  * masked.
242                                  */
243                                 write_c0_compare(0);
244                         }
245                 }
246         }
247 }
248
249 /* Watchdog support */
250 void __init txx9_wdt_init(unsigned long base)
251 {
252         struct resource res = {
253                 .start  = base,
254                 .end    = base + 0x100 - 1,
255                 .flags  = IORESOURCE_MEM,
256         };
257         platform_device_register_simple("txx9wdt", -1, &res, 1);
258 }
259
260 /* SPI support */
261 void __init txx9_spi_init(int busid, unsigned long base, int irq)
262 {
263         struct resource res[] = {
264                 {
265                         .start  = base,
266                         .end    = base + 0x20 - 1,
267                         .flags  = IORESOURCE_MEM,
268                 }, {
269                         .start  = irq,
270                         .flags  = IORESOURCE_IRQ,
271                 },
272         };
273         platform_device_register_simple("spi_txx9", busid,
274                                         res, ARRAY_SIZE(res));
275 }
276
277 void __init txx9_ethaddr_init(unsigned int id, unsigned char *ethaddr)
278 {
279         struct platform_device *pdev =
280                 platform_device_alloc("tc35815-mac", id);
281         if (!pdev ||
282             platform_device_add_data(pdev, ethaddr, 6) ||
283             platform_device_add(pdev))
284                 platform_device_put(pdev);
285 }
286
287 void __init txx9_sio_init(unsigned long baseaddr, int irq,
288                           unsigned int line, unsigned int sclk, int nocts)
289 {
290 #ifdef CONFIG_SERIAL_TXX9
291         struct uart_port req;
292
293         memset(&req, 0, sizeof(req));
294         req.line = line;
295         req.iotype = UPIO_MEM;
296         req.membase = ioremap(baseaddr, 0x24);
297         req.mapbase = baseaddr;
298         req.irq = irq;
299         if (!nocts)
300                 req.flags |= UPF_BUGGY_UART /*HAVE_CTS_LINE*/;
301         if (sclk) {
302                 req.flags |= UPF_MAGIC_MULTIPLIER /*USE_SCLK*/;
303                 req.uartclk = sclk;
304         } else
305                 req.uartclk = TXX9_IMCLK;
306         early_serial_txx9_setup(&req);
307 #endif /* CONFIG_SERIAL_TXX9 */
308 }
309
310 #ifdef CONFIG_EARLY_PRINTK
311 static void __init null_prom_putchar(char c)
312 {
313 }
314 void (*txx9_prom_putchar)(char c) __initdata = null_prom_putchar;
315
316 void __init prom_putchar(char c)
317 {
318         txx9_prom_putchar(c);
319 }
320
321 static void __iomem *early_txx9_sio_port;
322
323 static void __init early_txx9_sio_putchar(char c)
324 {
325 #define TXX9_SICISR     0x0c
326 #define TXX9_SITFIFO    0x1c
327 #define TXX9_SICISR_TXALS       0x00000002
328         while (!(__raw_readl(early_txx9_sio_port + TXX9_SICISR) &
329                  TXX9_SICISR_TXALS))
330                 ;
331         __raw_writel(c, early_txx9_sio_port + TXX9_SITFIFO);
332 }
333
334 void __init txx9_sio_putchar_init(unsigned long baseaddr)
335 {
336         early_txx9_sio_port = ioremap(baseaddr, 0x24);
337         txx9_prom_putchar = early_txx9_sio_putchar;
338 }
339 #endif /* CONFIG_EARLY_PRINTK */
340
341 /* wrappers */
342 void __init plat_mem_setup(void)
343 {
344         ioport_resource.start = 0;
345         ioport_resource.end = ~0UL;     /* no limit */
346         iomem_resource.start = 0;
347         iomem_resource.end = ~0UL;      /* no limit */
348
349         /* fallback restart/halt routines */
350         _machine_restart = (void (*)(char *))txx9_machine_halt;
351         _machine_halt = txx9_machine_halt;
352         pm_power_off = txx9_machine_halt;
353
354 #ifdef CONFIG_PCI
355         pcibios_plat_setup = txx9_pcibios_setup;
356 #endif
357         txx9_board_vec->mem_setup();
358 }
359
360 void __init arch_init_irq(void)
361 {
362         txx9_board_vec->irq_setup();
363 }
364
365 void __init plat_time_init(void)
366 {
367 #ifdef CONFIG_CPU_TX49XX
368         mips_hpt_frequency = txx9_cpu_clock / 2;
369 #endif
370         txx9_board_vec->time_init();
371 }
372
373 static int __init _txx9_arch_init(void)
374 {
375         if (txx9_board_vec->arch_init)
376                 txx9_board_vec->arch_init();
377         return 0;
378 }
379 arch_initcall(_txx9_arch_init);
380
381 static int __init _txx9_device_init(void)
382 {
383         if (txx9_board_vec->device_init)
384                 txx9_board_vec->device_init();
385         return 0;
386 }
387 device_initcall(_txx9_device_init);
388
389 int (*txx9_irq_dispatch)(int pending);
390 asmlinkage void plat_irq_dispatch(void)
391 {
392         int pending = read_c0_status() & read_c0_cause() & ST0_IM;
393         int irq = txx9_irq_dispatch(pending);
394
395         if (likely(irq >= 0))
396                 do_IRQ(irq);
397         else
398                 spurious_interrupt();
399 }
400
401 /* see include/asm-mips/mach-tx39xx/mangle-port.h, for example. */
402 #ifdef NEEDS_TXX9_SWIZZLE_ADDR_B
403 static unsigned long __swizzle_addr_none(unsigned long port)
404 {
405         return port;
406 }
407 unsigned long (*__swizzle_addr_b)(unsigned long port) = __swizzle_addr_none;
408 EXPORT_SYMBOL(__swizzle_addr_b);
409 #endif