blob: 7a05c34c1dec06a884eec0cf731e6d8bb315ec59 [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 Nemoto68314722008-07-24 00:25:18 +090023#include <linux/platform_device.h>
Atsushi Nemoto7779a5e2008-07-25 23:08:06 +090024#include <linux/serial_core.h>
Atsushi Nemoto51f607c2008-08-19 22:55:11 +090025#include <linux/mtd/physmap.h>
Atsushi Nemotoae027ea2008-09-01 22:22:38 +090026#include <linux/leds.h>
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090027#include <asm/bootinfo.h>
Atsushi Nemotoe0eb7302008-07-19 01:51:52 +090028#include <asm/time.h>
Atsushi Nemotoa49297e2008-07-24 00:25:17 +090029#include <asm/reboot.h>
Atsushi Nemotod10e0252008-08-19 22:55:09 +090030#include <asm/r4kcache.h>
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090031#include <asm/txx9/generic.h>
Atsushi Nemoto07517522008-07-24 00:25:15 +090032#include <asm/txx9/pci.h>
Atsushi Nemoto496a3b52008-08-19 22:55:15 +090033#include <asm/txx9tmr.h>
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090034#ifdef CONFIG_CPU_TX49XX
35#include <asm/txx9/tx4938.h>
36#endif
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090037
38/* EBUSC settings of TX4927, etc. */
39struct resource txx9_ce_res[8];
40static char txx9_ce_res_name[8][4]; /* "CEn" */
41
42/* pcode, internal register */
Atsushi Nemoto94a4c322008-07-19 01:51:47 +090043unsigned int txx9_pcode;
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090044char txx9_pcode_str[8];
45static struct resource txx9_reg_res = {
46 .name = txx9_pcode_str,
47 .flags = IORESOURCE_MEM,
48};
49void __init
50txx9_reg_res_init(unsigned int pcode, unsigned long base, unsigned long size)
51{
52 int i;
53
54 for (i = 0; i < ARRAY_SIZE(txx9_ce_res); i++) {
55 sprintf(txx9_ce_res_name[i], "CE%d", i);
56 txx9_ce_res[i].flags = IORESOURCE_MEM;
57 txx9_ce_res[i].name = txx9_ce_res_name[i];
58 }
59
Atsushi Nemoto073828d2008-08-26 21:29:58 +090060 txx9_pcode = pcode;
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090061 sprintf(txx9_pcode_str, "TX%x", pcode);
62 if (base) {
63 txx9_reg_res.start = base & 0xfffffffffULL;
64 txx9_reg_res.end = (base & 0xfffffffffULL) + (size - 1);
65 request_resource(&iomem_resource, &txx9_reg_res);
66 }
67}
68
69/* clocks */
70unsigned int txx9_master_clock;
71unsigned int txx9_cpu_clock;
72unsigned int txx9_gbus_clock;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090073
Atsushi Nemotoc7b95bc2008-08-19 22:55:10 +090074#ifdef CONFIG_CPU_TX39XX
75/* don't enable by default - see errata */
76int txx9_ccfg_toeon __initdata;
77#else
Atsushi Nemoto94a4c322008-07-19 01:51:47 +090078int txx9_ccfg_toeon __initdata = 1;
Atsushi Nemotoc7b95bc2008-08-19 22:55:10 +090079#endif
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090080
81/* Minimum CLK support */
82
83struct clk *clk_get(struct device *dev, const char *id)
84{
85 if (!strcmp(id, "spi-baseclk"))
Atsushi Nemoto94a4c322008-07-19 01:51:47 +090086 return (struct clk *)((unsigned long)txx9_gbus_clock / 2 / 4);
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090087 if (!strcmp(id, "imbus_clk"))
Atsushi Nemoto94a4c322008-07-19 01:51:47 +090088 return (struct clk *)((unsigned long)txx9_gbus_clock / 2);
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090089 return ERR_PTR(-ENOENT);
90}
91EXPORT_SYMBOL(clk_get);
92
93int clk_enable(struct clk *clk)
94{
95 return 0;
96}
97EXPORT_SYMBOL(clk_enable);
98
99void clk_disable(struct clk *clk)
100{
101}
102EXPORT_SYMBOL(clk_disable);
103
104unsigned long clk_get_rate(struct clk *clk)
105{
106 return (unsigned long)clk;
107}
108EXPORT_SYMBOL(clk_get_rate);
109
110void clk_put(struct clk *clk)
111{
112}
113EXPORT_SYMBOL(clk_put);
114
Atsushi Nemoto8d795f22008-07-18 00:43:48 +0900115/* GPIO support */
116
117#ifdef CONFIG_GENERIC_GPIO
118int gpio_to_irq(unsigned gpio)
119{
120 return -EINVAL;
121}
122EXPORT_SYMBOL(gpio_to_irq);
123
124int irq_to_gpio(unsigned irq)
125{
126 return -EINVAL;
127}
128EXPORT_SYMBOL(irq_to_gpio);
129#endif
130
Atsushi Nemoto860e5462008-08-19 22:55:08 +0900131#define BOARD_VEC(board) extern struct txx9_board_vec board;
132#include <asm/txx9/boards.h>
133#undef BOARD_VEC
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900134
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900135struct txx9_board_vec *txx9_board_vec __initdata;
136static char txx9_system_type[32];
137
Atsushi Nemoto860e5462008-08-19 22:55:08 +0900138static struct txx9_board_vec *board_vecs[] __initdata = {
139#define BOARD_VEC(board) &board,
140#include <asm/txx9/boards.h>
141#undef BOARD_VEC
142};
143
144static struct txx9_board_vec *__init find_board_byname(const char *name)
145{
146 int i;
147
148 /* search board_vecs table */
149 for (i = 0; i < ARRAY_SIZE(board_vecs); i++) {
150 if (strstr(board_vecs[i]->system, name))
151 return board_vecs[i];
152 }
153 return NULL;
154}
155
Atsushi Nemotoe0dfb202008-08-19 22:55:06 +0900156static void __init prom_init_cmdline(void)
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900157{
158 int argc = (int)fw_arg0;
Atsushi Nemotoe0dfb202008-08-19 22:55:06 +0900159 int *argv32 = (int *)fw_arg1;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900160 int i; /* Always ignore the "-c" at argv[0] */
Atsushi Nemotoe0dfb202008-08-19 22:55:06 +0900161 char builtin[CL_SIZE];
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900162
163 /* ignore all built-in args if any f/w args given */
Atsushi Nemotoe0dfb202008-08-19 22:55:06 +0900164 /*
165 * But if built-in strings was started with '+', append them
166 * to command line args. If built-in was started with '-',
167 * ignore all f/w args.
168 */
169 builtin[0] = '\0';
170 if (arcs_cmdline[0] == '+')
171 strcpy(builtin, arcs_cmdline + 1);
172 else if (arcs_cmdline[0] == '-') {
173 strcpy(builtin, arcs_cmdline + 1);
174 argc = 0;
175 } else if (argc <= 1)
176 strcpy(builtin, arcs_cmdline);
177 arcs_cmdline[0] = '\0';
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900178
179 for (i = 1; i < argc; i++) {
Atsushi Nemotoe0dfb202008-08-19 22:55:06 +0900180 char *str = (char *)(long)argv32[i];
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900181 if (i != 1)
182 strcat(arcs_cmdline, " ");
Atsushi Nemotoe0dfb202008-08-19 22:55:06 +0900183 if (strchr(str, ' ')) {
184 strcat(arcs_cmdline, "\"");
185 strcat(arcs_cmdline, str);
186 strcat(arcs_cmdline, "\"");
187 } else
188 strcat(arcs_cmdline, str);
189 }
190 /* append saved builtin args */
191 if (builtin[0]) {
192 if (arcs_cmdline[0])
193 strcat(arcs_cmdline, " ");
194 strcat(arcs_cmdline, builtin);
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900195 }
196}
197
Atsushi Nemotod10e0252008-08-19 22:55:09 +0900198static int txx9_ic_disable __initdata;
199static int txx9_dc_disable __initdata;
200
201#if defined(CONFIG_CPU_TX49XX)
202/* flush all cache on very early stage (before 4k_cache_init) */
203static void __init early_flush_dcache(void)
204{
205 unsigned int conf = read_c0_config();
206 unsigned int dc_size = 1 << (12 + ((conf & CONF_DC) >> 6));
207 unsigned int linesz = 32;
208 unsigned long addr, end;
209
210 end = INDEX_BASE + dc_size / 4;
211 /* 4way, waybit=0 */
212 for (addr = INDEX_BASE; addr < end; addr += linesz) {
213 cache_op(Index_Writeback_Inv_D, addr | 0);
214 cache_op(Index_Writeback_Inv_D, addr | 1);
215 cache_op(Index_Writeback_Inv_D, addr | 2);
216 cache_op(Index_Writeback_Inv_D, addr | 3);
217 }
218}
219
220static void __init txx9_cache_fixup(void)
221{
222 unsigned int conf;
223
224 conf = read_c0_config();
225 /* flush and disable */
226 if (txx9_ic_disable) {
227 conf |= TX49_CONF_IC;
228 write_c0_config(conf);
229 }
230 if (txx9_dc_disable) {
231 early_flush_dcache();
232 conf |= TX49_CONF_DC;
233 write_c0_config(conf);
234 }
235
236 /* enable cache */
237 conf = read_c0_config();
238 if (!txx9_ic_disable)
239 conf &= ~TX49_CONF_IC;
240 if (!txx9_dc_disable)
241 conf &= ~TX49_CONF_DC;
242 write_c0_config(conf);
243
244 if (conf & TX49_CONF_IC)
245 pr_info("TX49XX I-Cache disabled.\n");
246 if (conf & TX49_CONF_DC)
247 pr_info("TX49XX D-Cache disabled.\n");
248}
249#elif defined(CONFIG_CPU_TX39XX)
250/* flush all cache on very early stage (before tx39_cache_init) */
251static void __init early_flush_dcache(void)
252{
253 unsigned int conf = read_c0_config();
254 unsigned int dc_size = 1 << (10 + ((conf & TX39_CONF_DCS_MASK) >>
255 TX39_CONF_DCS_SHIFT));
256 unsigned int linesz = 16;
257 unsigned long addr, end;
258
259 end = INDEX_BASE + dc_size / 2;
260 /* 2way, waybit=0 */
261 for (addr = INDEX_BASE; addr < end; addr += linesz) {
262 cache_op(Index_Writeback_Inv_D, addr | 0);
263 cache_op(Index_Writeback_Inv_D, addr | 1);
264 }
265}
266
267static void __init txx9_cache_fixup(void)
268{
269 unsigned int conf;
270
271 conf = read_c0_config();
272 /* flush and disable */
273 if (txx9_ic_disable) {
274 conf &= ~TX39_CONF_ICE;
275 write_c0_config(conf);
276 }
277 if (txx9_dc_disable) {
278 early_flush_dcache();
279 conf &= ~TX39_CONF_DCE;
280 write_c0_config(conf);
281 }
282
283 /* enable cache */
284 conf = read_c0_config();
285 if (!txx9_ic_disable)
286 conf |= TX39_CONF_ICE;
287 if (!txx9_dc_disable)
288 conf |= TX39_CONF_DCE;
289 write_c0_config(conf);
290
291 if (!(conf & TX39_CONF_ICE))
292 pr_info("TX39XX I-Cache disabled.\n");
293 if (!(conf & TX39_CONF_DCE))
294 pr_info("TX39XX D-Cache disabled.\n");
295}
296#else
297static inline void txx9_cache_fixup(void)
298{
299}
300#endif
301
Atsushi Nemoto860e5462008-08-19 22:55:08 +0900302static void __init preprocess_cmdline(void)
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900303{
Atsushi Nemoto860e5462008-08-19 22:55:08 +0900304 char cmdline[CL_SIZE];
305 char *s;
306
307 strcpy(cmdline, arcs_cmdline);
308 s = cmdline;
309 arcs_cmdline[0] = '\0';
310 while (s && *s) {
311 char *str = strsep(&s, " ");
312 if (strncmp(str, "board=", 6) == 0) {
313 txx9_board_vec = find_board_byname(str + 6);
314 continue;
315 } else if (strncmp(str, "masterclk=", 10) == 0) {
316 unsigned long val;
317 if (strict_strtoul(str + 10, 10, &val) == 0)
318 txx9_master_clock = val;
319 continue;
Atsushi Nemotod10e0252008-08-19 22:55:09 +0900320 } else if (strcmp(str, "icdisable") == 0) {
321 txx9_ic_disable = 1;
322 continue;
323 } else if (strcmp(str, "dcdisable") == 0) {
324 txx9_dc_disable = 1;
325 continue;
Atsushi Nemotoc7b95bc2008-08-19 22:55:10 +0900326 } else if (strcmp(str, "toeoff") == 0) {
327 txx9_ccfg_toeon = 0;
328 continue;
329 } else if (strcmp(str, "toeon") == 0) {
330 txx9_ccfg_toeon = 1;
331 continue;
Atsushi Nemoto860e5462008-08-19 22:55:08 +0900332 }
333 if (arcs_cmdline[0])
334 strcat(arcs_cmdline, " ");
335 strcat(arcs_cmdline, str);
336 }
Atsushi Nemotod10e0252008-08-19 22:55:09 +0900337
338 txx9_cache_fixup();
Atsushi Nemoto860e5462008-08-19 22:55:08 +0900339}
340
341static void __init select_board(void)
342{
343 const char *envstr;
344
345 /* first, determine by "board=" argument in preprocess_cmdline() */
346 if (txx9_board_vec)
347 return;
348 /* next, determine by "board" envvar */
349 envstr = prom_getenv("board");
350 if (envstr) {
351 txx9_board_vec = find_board_byname(envstr);
352 if (txx9_board_vec)
353 return;
354 }
355
356 /* select "default" board */
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900357#ifdef CONFIG_CPU_TX39XX
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900358 txx9_board_vec = &jmr3927_vec;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900359#endif
360#ifdef CONFIG_CPU_TX49XX
361 switch (TX4938_REV_PCODE()) {
Atsushi Nemoto8d795f22008-07-18 00:43:48 +0900362#ifdef CONFIG_TOSHIBA_RBTX4927
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900363 case 0x4927:
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900364 txx9_board_vec = &rbtx4927_vec;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900365 break;
366 case 0x4937:
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900367 txx9_board_vec = &rbtx4937_vec;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900368 break;
Atsushi Nemoto8d795f22008-07-18 00:43:48 +0900369#endif
370#ifdef CONFIG_TOSHIBA_RBTX4938
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900371 case 0x4938:
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900372 txx9_board_vec = &rbtx4938_vec;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900373 break;
Atsushi Nemoto8d795f22008-07-18 00:43:48 +0900374#endif
Atsushi Nemotob27311e2008-09-01 22:22:40 +0900375#ifdef CONFIG_TOSHIBA_RBTX4939
376 case 0x4939:
377 txx9_board_vec = &rbtx4939_vec;
378 break;
379#endif
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900380 }
381#endif
Atsushi Nemoto860e5462008-08-19 22:55:08 +0900382}
383
384void __init prom_init(void)
385{
386 prom_init_cmdline();
387 preprocess_cmdline();
388 select_board();
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900389
390 strcpy(txx9_system_type, txx9_board_vec->system);
391
Atsushi Nemoto7b226092008-07-14 00:15:04 +0900392 txx9_board_vec->prom_init();
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900393}
394
395void __init prom_free_prom_memory(void)
396{
397}
398
399const char *get_system_type(void)
400{
401 return txx9_system_type;
402}
403
404char * __init prom_getcmdline(void)
405{
406 return &(arcs_cmdline[0]);
407}
408
Atsushi Nemoto265b89d2008-08-19 22:55:07 +0900409const char *__init prom_getenv(const char *name)
410{
411 const s32 *str = (const s32 *)fw_arg2;
412
413 if (!str)
414 return NULL;
415 /* YAMON style ("name", "value" pairs) */
416 while (str[0] && str[1]) {
417 if (!strcmp((const char *)(unsigned long)str[0], name))
418 return (const char *)(unsigned long)str[1];
419 str += 2;
420 }
421 return NULL;
422}
423
Atsushi Nemotoa49297e2008-07-24 00:25:17 +0900424static void __noreturn txx9_machine_halt(void)
425{
426 local_irq_disable();
427 clear_c0_status(ST0_IM);
428 while (1) {
429 if (cpu_wait) {
430 (*cpu_wait)();
431 if (cpu_has_counter) {
432 /*
433 * Clear counter interrupt while it
434 * breaks WAIT instruction even if
435 * masked.
436 */
437 write_c0_compare(0);
438 }
439 }
440 }
441}
442
Atsushi Nemoto68314722008-07-24 00:25:18 +0900443/* Watchdog support */
444void __init txx9_wdt_init(unsigned long base)
445{
446 struct resource res = {
447 .start = base,
448 .end = base + 0x100 - 1,
449 .flags = IORESOURCE_MEM,
450 };
451 platform_device_register_simple("txx9wdt", -1, &res, 1);
452}
453
Atsushi Nemoto496a3b52008-08-19 22:55:15 +0900454void txx9_wdt_now(unsigned long base)
455{
456 struct txx9_tmr_reg __iomem *tmrptr =
457 ioremap(base, sizeof(struct txx9_tmr_reg));
458 /* disable watch dog timer */
459 __raw_writel(TXx9_TMWTMR_WDIS | TXx9_TMWTMR_TWC, &tmrptr->wtmr);
460 __raw_writel(0, &tmrptr->tcr);
461 /* kick watchdog */
462 __raw_writel(TXx9_TMWTMR_TWIE, &tmrptr->wtmr);
463 __raw_writel(1, &tmrptr->cpra); /* immediate */
464 __raw_writel(TXx9_TMTCR_TCE | TXx9_TMTCR_CCDE | TXx9_TMTCR_TMODE_WDOG,
465 &tmrptr->tcr);
466}
467
Atsushi Nemotoc49f91f2008-07-24 00:25:20 +0900468/* SPI support */
469void __init txx9_spi_init(int busid, unsigned long base, int irq)
470{
471 struct resource res[] = {
472 {
473 .start = base,
474 .end = base + 0x20 - 1,
475 .flags = IORESOURCE_MEM,
476 }, {
477 .start = irq,
478 .flags = IORESOURCE_IRQ,
479 },
480 };
481 platform_device_register_simple("spi_txx9", busid,
482 res, ARRAY_SIZE(res));
483}
484
485void __init txx9_ethaddr_init(unsigned int id, unsigned char *ethaddr)
486{
487 struct platform_device *pdev =
488 platform_device_alloc("tc35815-mac", id);
489 if (!pdev ||
490 platform_device_add_data(pdev, ethaddr, 6) ||
491 platform_device_add(pdev))
492 platform_device_put(pdev);
493}
494
Atsushi Nemoto7779a5e2008-07-25 23:08:06 +0900495void __init txx9_sio_init(unsigned long baseaddr, int irq,
496 unsigned int line, unsigned int sclk, int nocts)
497{
498#ifdef CONFIG_SERIAL_TXX9
499 struct uart_port req;
500
501 memset(&req, 0, sizeof(req));
502 req.line = line;
503 req.iotype = UPIO_MEM;
504 req.membase = ioremap(baseaddr, 0x24);
505 req.mapbase = baseaddr;
506 req.irq = irq;
507 if (!nocts)
508 req.flags |= UPF_BUGGY_UART /*HAVE_CTS_LINE*/;
509 if (sclk) {
510 req.flags |= UPF_MAGIC_MULTIPLIER /*USE_SCLK*/;
511 req.uartclk = sclk;
512 } else
513 req.uartclk = TXX9_IMCLK;
514 early_serial_txx9_setup(&req);
515#endif /* CONFIG_SERIAL_TXX9 */
516}
517
Atsushi Nemotoe3529532008-07-29 22:10:08 +0900518#ifdef CONFIG_EARLY_PRINTK
519static void __init null_prom_putchar(char c)
520{
521}
522void (*txx9_prom_putchar)(char c) __initdata = null_prom_putchar;
523
524void __init prom_putchar(char c)
525{
526 txx9_prom_putchar(c);
527}
528
529static void __iomem *early_txx9_sio_port;
530
531static void __init early_txx9_sio_putchar(char c)
532{
533#define TXX9_SICISR 0x0c
534#define TXX9_SITFIFO 0x1c
535#define TXX9_SICISR_TXALS 0x00000002
536 while (!(__raw_readl(early_txx9_sio_port + TXX9_SICISR) &
537 TXX9_SICISR_TXALS))
538 ;
539 __raw_writel(c, early_txx9_sio_port + TXX9_SITFIFO);
540}
541
542void __init txx9_sio_putchar_init(unsigned long baseaddr)
543{
544 early_txx9_sio_port = ioremap(baseaddr, 0x24);
545 txx9_prom_putchar = early_txx9_sio_putchar;
546}
547#endif /* CONFIG_EARLY_PRINTK */
548
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900549/* wrappers */
550void __init plat_mem_setup(void)
551{
Atsushi Nemoto94a4c322008-07-19 01:51:47 +0900552 ioport_resource.start = 0;
553 ioport_resource.end = ~0UL; /* no limit */
554 iomem_resource.start = 0;
555 iomem_resource.end = ~0UL; /* no limit */
Atsushi Nemotoa49297e2008-07-24 00:25:17 +0900556
557 /* fallback restart/halt routines */
558 _machine_restart = (void (*)(char *))txx9_machine_halt;
559 _machine_halt = txx9_machine_halt;
560 pm_power_off = txx9_machine_halt;
561
Atsushi Nemoto07517522008-07-24 00:25:15 +0900562#ifdef CONFIG_PCI
563 pcibios_plat_setup = txx9_pcibios_setup;
564#endif
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900565 txx9_board_vec->mem_setup();
566}
567
568void __init arch_init_irq(void)
569{
570 txx9_board_vec->irq_setup();
571}
572
573void __init plat_time_init(void)
574{
Atsushi Nemoto1374d082008-07-31 22:29:53 +0900575#ifdef CONFIG_CPU_TX49XX
576 mips_hpt_frequency = txx9_cpu_clock / 2;
577#endif
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900578 txx9_board_vec->time_init();
579}
580
581static int __init _txx9_arch_init(void)
582{
583 if (txx9_board_vec->arch_init)
584 txx9_board_vec->arch_init();
585 return 0;
586}
587arch_initcall(_txx9_arch_init);
588
589static int __init _txx9_device_init(void)
590{
591 if (txx9_board_vec->device_init)
592 txx9_board_vec->device_init();
593 return 0;
594}
595device_initcall(_txx9_device_init);
596
597int (*txx9_irq_dispatch)(int pending);
598asmlinkage void plat_irq_dispatch(void)
599{
600 int pending = read_c0_status() & read_c0_cause() & ST0_IM;
601 int irq = txx9_irq_dispatch(pending);
602
603 if (likely(irq >= 0))
604 do_IRQ(irq);
605 else
606 spurious_interrupt();
607}
Atsushi Nemoto4c642f32008-07-13 23:37:56 +0900608
609/* see include/asm-mips/mach-tx39xx/mangle-port.h, for example. */
610#ifdef NEEDS_TXX9_SWIZZLE_ADDR_B
611static unsigned long __swizzle_addr_none(unsigned long port)
612{
613 return port;
614}
615unsigned long (*__swizzle_addr_b)(unsigned long port) = __swizzle_addr_none;
616EXPORT_SYMBOL(__swizzle_addr_b);
617#endif
Atsushi Nemoto51f607c2008-08-19 22:55:11 +0900618
619void __init txx9_physmap_flash_init(int no, unsigned long addr,
620 unsigned long size,
621 const struct physmap_flash_data *pdata)
622{
623#if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
624 struct resource res = {
625 .start = addr,
626 .end = addr + size - 1,
627 .flags = IORESOURCE_MEM,
628 };
629 struct platform_device *pdev;
630#ifdef CONFIG_MTD_PARTITIONS
631 static struct mtd_partition parts[2];
632 struct physmap_flash_data pdata_part;
633
634 /* If this area contained boot area, make separate partition */
635 if (pdata->nr_parts == 0 && !pdata->parts &&
636 addr < 0x1fc00000 && addr + size > 0x1fc00000 &&
637 !parts[0].name) {
638 parts[0].name = "boot";
639 parts[0].offset = 0x1fc00000 - addr;
640 parts[0].size = addr + size - 0x1fc00000;
641 parts[1].name = "user";
642 parts[1].offset = 0;
643 parts[1].size = 0x1fc00000 - addr;
644 pdata_part = *pdata;
645 pdata_part.nr_parts = ARRAY_SIZE(parts);
646 pdata_part.parts = parts;
647 pdata = &pdata_part;
648 }
649#endif
650 pdev = platform_device_alloc("physmap-flash", no);
651 if (!pdev ||
652 platform_device_add_resources(pdev, &res, 1) ||
653 platform_device_add_data(pdev, pdata, sizeof(*pdata)) ||
654 platform_device_add(pdev))
655 platform_device_put(pdev);
656#endif
657}
Atsushi Nemotoae027ea2008-09-01 22:22:38 +0900658
659#if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
660static DEFINE_SPINLOCK(txx9_iocled_lock);
661
662#define TXX9_IOCLED_MAXLEDS 8
663
664struct txx9_iocled_data {
665 struct gpio_chip chip;
666 u8 cur_val;
667 void __iomem *mmioaddr;
668 struct gpio_led_platform_data pdata;
669 struct gpio_led leds[TXX9_IOCLED_MAXLEDS];
670 char names[TXX9_IOCLED_MAXLEDS][32];
671};
672
673static int txx9_iocled_get(struct gpio_chip *chip, unsigned int offset)
674{
675 struct txx9_iocled_data *data =
676 container_of(chip, struct txx9_iocled_data, chip);
677 return data->cur_val & (1 << offset);
678}
679
680static void txx9_iocled_set(struct gpio_chip *chip, unsigned int offset,
681 int value)
682{
683 struct txx9_iocled_data *data =
684 container_of(chip, struct txx9_iocled_data, chip);
685 unsigned long flags;
686 spin_lock_irqsave(&txx9_iocled_lock, flags);
687 if (value)
688 data->cur_val |= 1 << offset;
689 else
690 data->cur_val &= ~(1 << offset);
691 writeb(data->cur_val, data->mmioaddr);
692 mmiowb();
693 spin_unlock_irqrestore(&txx9_iocled_lock, flags);
694}
695
696static int txx9_iocled_dir_in(struct gpio_chip *chip, unsigned int offset)
697{
698 return 0;
699}
700
701static int txx9_iocled_dir_out(struct gpio_chip *chip, unsigned int offset,
702 int value)
703{
704 txx9_iocled_set(chip, offset, value);
705 return 0;
706}
707
708void __init txx9_iocled_init(unsigned long baseaddr,
709 int basenum, unsigned int num, int lowactive,
710 const char *color, char **deftriggers)
711{
712 struct txx9_iocled_data *iocled;
713 struct platform_device *pdev;
714 int i;
715 static char *default_triggers[] __initdata = {
716 "heartbeat",
717 "ide-disk",
718 "nand-disk",
719 NULL,
720 };
721
722 if (!deftriggers)
723 deftriggers = default_triggers;
724 iocled = kzalloc(sizeof(*iocled), GFP_KERNEL);
725 if (!iocled)
726 return;
727 iocled->mmioaddr = ioremap(baseaddr, 1);
728 if (!iocled->mmioaddr)
729 return;
730 iocled->chip.get = txx9_iocled_get;
731 iocled->chip.set = txx9_iocled_set;
732 iocled->chip.direction_input = txx9_iocled_dir_in;
733 iocled->chip.direction_output = txx9_iocled_dir_out;
734 iocled->chip.label = "iocled";
735 iocled->chip.base = basenum;
736 iocled->chip.ngpio = num;
737 if (gpiochip_add(&iocled->chip))
738 return;
739 if (basenum < 0)
740 basenum = iocled->chip.base;
741
742 pdev = platform_device_alloc("leds-gpio", basenum);
743 if (!pdev)
744 return;
745 iocled->pdata.num_leds = num;
746 iocled->pdata.leds = iocled->leds;
747 for (i = 0; i < num; i++) {
748 struct gpio_led *led = &iocled->leds[i];
749 snprintf(iocled->names[i], sizeof(iocled->names[i]),
750 "iocled:%s:%u", color, i);
751 led->name = iocled->names[i];
752 led->gpio = basenum + i;
753 led->active_low = lowactive;
754 if (deftriggers && *deftriggers)
755 led->default_trigger = *deftriggers++;
756 }
757 pdev->dev.platform_data = &iocled->pdata;
758 if (platform_device_add(pdev))
759 platform_device_put(pdev);
760}
761#else /* CONFIG_LEDS_GPIO */
762void __init txx9_iocled_init(unsigned long baseaddr,
763 int basenum, unsigned int num, int lowactive,
764 const char *color, char **deftriggers)
765{
766}
767#endif /* CONFIG_LEDS_GPIO */