blob: 7f9101257615f7fbc457cc02d30abba50cde2c1a [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 Nemotob6263ff2008-09-01 22:22:41 +090031#include <asm/sections.h>
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090032#include <asm/txx9/generic.h>
Atsushi Nemoto07517522008-07-24 00:25:15 +090033#include <asm/txx9/pci.h>
Atsushi Nemoto496a3b52008-08-19 22:55:15 +090034#include <asm/txx9tmr.h>
Atsushi Nemotoa591f5d2009-03-04 12:01:31 -080035#include <asm/txx9/ndfmc.h>
Atsushi Nemotof48c8c92009-04-23 00:40:31 +090036#include <asm/txx9/dmac.h>
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090037#ifdef CONFIG_CPU_TX49XX
38#include <asm/txx9/tx4938.h>
39#endif
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090040
41/* EBUSC settings of TX4927, etc. */
42struct resource txx9_ce_res[8];
43static char txx9_ce_res_name[8][4]; /* "CEn" */
44
45/* pcode, internal register */
Atsushi Nemoto94a4c322008-07-19 01:51:47 +090046unsigned int txx9_pcode;
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090047char txx9_pcode_str[8];
48static struct resource txx9_reg_res = {
49 .name = txx9_pcode_str,
50 .flags = IORESOURCE_MEM,
51};
52void __init
53txx9_reg_res_init(unsigned int pcode, unsigned long base, unsigned long size)
54{
55 int i;
56
57 for (i = 0; i < ARRAY_SIZE(txx9_ce_res); i++) {
58 sprintf(txx9_ce_res_name[i], "CE%d", i);
59 txx9_ce_res[i].flags = IORESOURCE_MEM;
60 txx9_ce_res[i].name = txx9_ce_res_name[i];
61 }
62
Atsushi Nemoto073828d2008-08-26 21:29:58 +090063 txx9_pcode = pcode;
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090064 sprintf(txx9_pcode_str, "TX%x", pcode);
65 if (base) {
66 txx9_reg_res.start = base & 0xfffffffffULL;
67 txx9_reg_res.end = (base & 0xfffffffffULL) + (size - 1);
68 request_resource(&iomem_resource, &txx9_reg_res);
69 }
70}
71
72/* clocks */
73unsigned int txx9_master_clock;
74unsigned int txx9_cpu_clock;
75unsigned int txx9_gbus_clock;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090076
Atsushi Nemotoc7b95bc2008-08-19 22:55:10 +090077#ifdef CONFIG_CPU_TX39XX
78/* don't enable by default - see errata */
79int txx9_ccfg_toeon __initdata;
80#else
Atsushi Nemoto94a4c322008-07-19 01:51:47 +090081int txx9_ccfg_toeon __initdata = 1;
Atsushi Nemotoc7b95bc2008-08-19 22:55:10 +090082#endif
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090083
84/* Minimum CLK support */
85
86struct clk *clk_get(struct device *dev, const char *id)
87{
88 if (!strcmp(id, "spi-baseclk"))
Atsushi Nemoto94a4c322008-07-19 01:51:47 +090089 return (struct clk *)((unsigned long)txx9_gbus_clock / 2 / 4);
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090090 if (!strcmp(id, "imbus_clk"))
Atsushi Nemoto94a4c322008-07-19 01:51:47 +090091 return (struct clk *)((unsigned long)txx9_gbus_clock / 2);
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090092 return ERR_PTR(-ENOENT);
93}
94EXPORT_SYMBOL(clk_get);
95
96int clk_enable(struct clk *clk)
97{
98 return 0;
99}
100EXPORT_SYMBOL(clk_enable);
101
102void clk_disable(struct clk *clk)
103{
104}
105EXPORT_SYMBOL(clk_disable);
106
107unsigned long clk_get_rate(struct clk *clk)
108{
109 return (unsigned long)clk;
110}
111EXPORT_SYMBOL(clk_get_rate);
112
113void clk_put(struct clk *clk)
114{
115}
116EXPORT_SYMBOL(clk_put);
117
Atsushi Nemoto8d795f22008-07-18 00:43:48 +0900118/* GPIO support */
119
120#ifdef CONFIG_GENERIC_GPIO
121int gpio_to_irq(unsigned gpio)
122{
123 return -EINVAL;
124}
125EXPORT_SYMBOL(gpio_to_irq);
126
127int irq_to_gpio(unsigned irq)
128{
129 return -EINVAL;
130}
131EXPORT_SYMBOL(irq_to_gpio);
132#endif
133
Atsushi Nemoto860e5462008-08-19 22:55:08 +0900134#define BOARD_VEC(board) extern struct txx9_board_vec board;
135#include <asm/txx9/boards.h>
136#undef BOARD_VEC
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900137
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900138struct txx9_board_vec *txx9_board_vec __initdata;
139static char txx9_system_type[32];
140
Atsushi Nemoto860e5462008-08-19 22:55:08 +0900141static struct txx9_board_vec *board_vecs[] __initdata = {
142#define BOARD_VEC(board) &board,
143#include <asm/txx9/boards.h>
144#undef BOARD_VEC
145};
146
147static struct txx9_board_vec *__init find_board_byname(const char *name)
148{
149 int i;
150
151 /* search board_vecs table */
152 for (i = 0; i < ARRAY_SIZE(board_vecs); i++) {
153 if (strstr(board_vecs[i]->system, name))
154 return board_vecs[i];
155 }
156 return NULL;
157}
158
Atsushi Nemotoe0dfb202008-08-19 22:55:06 +0900159static void __init prom_init_cmdline(void)
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900160{
Geert Uytterhoeven97b05112008-10-27 15:25:49 +0100161 int argc;
162 int *argv32;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900163 int i; /* Always ignore the "-c" at argv[0] */
Atsushi Nemotoe0dfb202008-08-19 22:55:06 +0900164 char builtin[CL_SIZE];
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900165
Geert Uytterhoeven97b05112008-10-27 15:25:49 +0100166 if (fw_arg0 >= CKSEG0 || fw_arg1 < CKSEG0) {
167 /*
168 * argc is not a valid number, or argv32 is not a valid
169 * pointer
170 */
171 argc = 0;
172 argv32 = NULL;
173 } else {
174 argc = (int)fw_arg0;
175 argv32 = (int *)fw_arg1;
176 }
177
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900178 /* ignore all built-in args if any f/w args given */
Atsushi Nemotoe0dfb202008-08-19 22:55:06 +0900179 /*
180 * But if built-in strings was started with '+', append them
181 * to command line args. If built-in was started with '-',
182 * ignore all f/w args.
183 */
184 builtin[0] = '\0';
185 if (arcs_cmdline[0] == '+')
186 strcpy(builtin, arcs_cmdline + 1);
187 else if (arcs_cmdline[0] == '-') {
188 strcpy(builtin, arcs_cmdline + 1);
189 argc = 0;
190 } else if (argc <= 1)
191 strcpy(builtin, arcs_cmdline);
192 arcs_cmdline[0] = '\0';
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900193
194 for (i = 1; i < argc; i++) {
Atsushi Nemotoe0dfb202008-08-19 22:55:06 +0900195 char *str = (char *)(long)argv32[i];
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900196 if (i != 1)
197 strcat(arcs_cmdline, " ");
Atsushi Nemotoe0dfb202008-08-19 22:55:06 +0900198 if (strchr(str, ' ')) {
199 strcat(arcs_cmdline, "\"");
200 strcat(arcs_cmdline, str);
201 strcat(arcs_cmdline, "\"");
202 } else
203 strcat(arcs_cmdline, str);
204 }
205 /* append saved builtin args */
206 if (builtin[0]) {
207 if (arcs_cmdline[0])
208 strcat(arcs_cmdline, " ");
209 strcat(arcs_cmdline, builtin);
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900210 }
211}
212
Atsushi Nemotod10e0252008-08-19 22:55:09 +0900213static int txx9_ic_disable __initdata;
214static int txx9_dc_disable __initdata;
215
216#if defined(CONFIG_CPU_TX49XX)
217/* flush all cache on very early stage (before 4k_cache_init) */
218static void __init early_flush_dcache(void)
219{
220 unsigned int conf = read_c0_config();
221 unsigned int dc_size = 1 << (12 + ((conf & CONF_DC) >> 6));
222 unsigned int linesz = 32;
223 unsigned long addr, end;
224
225 end = INDEX_BASE + dc_size / 4;
226 /* 4way, waybit=0 */
227 for (addr = INDEX_BASE; addr < end; addr += linesz) {
228 cache_op(Index_Writeback_Inv_D, addr | 0);
229 cache_op(Index_Writeback_Inv_D, addr | 1);
230 cache_op(Index_Writeback_Inv_D, addr | 2);
231 cache_op(Index_Writeback_Inv_D, addr | 3);
232 }
233}
234
235static void __init txx9_cache_fixup(void)
236{
237 unsigned int conf;
238
239 conf = read_c0_config();
240 /* flush and disable */
241 if (txx9_ic_disable) {
242 conf |= TX49_CONF_IC;
243 write_c0_config(conf);
244 }
245 if (txx9_dc_disable) {
246 early_flush_dcache();
247 conf |= TX49_CONF_DC;
248 write_c0_config(conf);
249 }
250
251 /* enable cache */
252 conf = read_c0_config();
253 if (!txx9_ic_disable)
254 conf &= ~TX49_CONF_IC;
255 if (!txx9_dc_disable)
256 conf &= ~TX49_CONF_DC;
257 write_c0_config(conf);
258
259 if (conf & TX49_CONF_IC)
260 pr_info("TX49XX I-Cache disabled.\n");
261 if (conf & TX49_CONF_DC)
262 pr_info("TX49XX D-Cache disabled.\n");
263}
264#elif defined(CONFIG_CPU_TX39XX)
265/* flush all cache on very early stage (before tx39_cache_init) */
266static void __init early_flush_dcache(void)
267{
268 unsigned int conf = read_c0_config();
269 unsigned int dc_size = 1 << (10 + ((conf & TX39_CONF_DCS_MASK) >>
270 TX39_CONF_DCS_SHIFT));
271 unsigned int linesz = 16;
272 unsigned long addr, end;
273
274 end = INDEX_BASE + dc_size / 2;
275 /* 2way, waybit=0 */
276 for (addr = INDEX_BASE; addr < end; addr += linesz) {
277 cache_op(Index_Writeback_Inv_D, addr | 0);
278 cache_op(Index_Writeback_Inv_D, addr | 1);
279 }
280}
281
282static void __init txx9_cache_fixup(void)
283{
284 unsigned int conf;
285
286 conf = read_c0_config();
287 /* flush and disable */
288 if (txx9_ic_disable) {
289 conf &= ~TX39_CONF_ICE;
290 write_c0_config(conf);
291 }
292 if (txx9_dc_disable) {
293 early_flush_dcache();
294 conf &= ~TX39_CONF_DCE;
295 write_c0_config(conf);
296 }
297
298 /* enable cache */
299 conf = read_c0_config();
300 if (!txx9_ic_disable)
301 conf |= TX39_CONF_ICE;
302 if (!txx9_dc_disable)
303 conf |= TX39_CONF_DCE;
304 write_c0_config(conf);
305
306 if (!(conf & TX39_CONF_ICE))
307 pr_info("TX39XX I-Cache disabled.\n");
308 if (!(conf & TX39_CONF_DCE))
309 pr_info("TX39XX D-Cache disabled.\n");
310}
311#else
312static inline void txx9_cache_fixup(void)
313{
314}
315#endif
316
Atsushi Nemoto860e5462008-08-19 22:55:08 +0900317static void __init preprocess_cmdline(void)
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900318{
Atsushi Nemoto860e5462008-08-19 22:55:08 +0900319 char cmdline[CL_SIZE];
320 char *s;
321
322 strcpy(cmdline, arcs_cmdline);
323 s = cmdline;
324 arcs_cmdline[0] = '\0';
325 while (s && *s) {
326 char *str = strsep(&s, " ");
327 if (strncmp(str, "board=", 6) == 0) {
328 txx9_board_vec = find_board_byname(str + 6);
329 continue;
330 } else if (strncmp(str, "masterclk=", 10) == 0) {
331 unsigned long val;
332 if (strict_strtoul(str + 10, 10, &val) == 0)
333 txx9_master_clock = val;
334 continue;
Atsushi Nemotod10e0252008-08-19 22:55:09 +0900335 } else if (strcmp(str, "icdisable") == 0) {
336 txx9_ic_disable = 1;
337 continue;
338 } else if (strcmp(str, "dcdisable") == 0) {
339 txx9_dc_disable = 1;
340 continue;
Atsushi Nemotoc7b95bc2008-08-19 22:55:10 +0900341 } else if (strcmp(str, "toeoff") == 0) {
342 txx9_ccfg_toeon = 0;
343 continue;
344 } else if (strcmp(str, "toeon") == 0) {
345 txx9_ccfg_toeon = 1;
346 continue;
Atsushi Nemoto860e5462008-08-19 22:55:08 +0900347 }
348 if (arcs_cmdline[0])
349 strcat(arcs_cmdline, " ");
350 strcat(arcs_cmdline, str);
351 }
Atsushi Nemotod10e0252008-08-19 22:55:09 +0900352
353 txx9_cache_fixup();
Atsushi Nemoto860e5462008-08-19 22:55:08 +0900354}
355
356static void __init select_board(void)
357{
358 const char *envstr;
359
360 /* first, determine by "board=" argument in preprocess_cmdline() */
361 if (txx9_board_vec)
362 return;
363 /* next, determine by "board" envvar */
364 envstr = prom_getenv("board");
365 if (envstr) {
366 txx9_board_vec = find_board_byname(envstr);
367 if (txx9_board_vec)
368 return;
369 }
370
371 /* select "default" board */
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900372#ifdef CONFIG_CPU_TX39XX
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900373 txx9_board_vec = &jmr3927_vec;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900374#endif
375#ifdef CONFIG_CPU_TX49XX
376 switch (TX4938_REV_PCODE()) {
Atsushi Nemoto8d795f22008-07-18 00:43:48 +0900377#ifdef CONFIG_TOSHIBA_RBTX4927
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900378 case 0x4927:
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900379 txx9_board_vec = &rbtx4927_vec;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900380 break;
381 case 0x4937:
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900382 txx9_board_vec = &rbtx4937_vec;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900383 break;
Atsushi Nemoto8d795f22008-07-18 00:43:48 +0900384#endif
385#ifdef CONFIG_TOSHIBA_RBTX4938
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900386 case 0x4938:
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900387 txx9_board_vec = &rbtx4938_vec;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900388 break;
Atsushi Nemoto8d795f22008-07-18 00:43:48 +0900389#endif
Atsushi Nemotob27311e2008-09-01 22:22:40 +0900390#ifdef CONFIG_TOSHIBA_RBTX4939
391 case 0x4939:
392 txx9_board_vec = &rbtx4939_vec;
393 break;
394#endif
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900395 }
396#endif
Atsushi Nemoto860e5462008-08-19 22:55:08 +0900397}
398
399void __init prom_init(void)
400{
401 prom_init_cmdline();
402 preprocess_cmdline();
403 select_board();
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900404
405 strcpy(txx9_system_type, txx9_board_vec->system);
406
Atsushi Nemoto7b226092008-07-14 00:15:04 +0900407 txx9_board_vec->prom_init();
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900408}
409
410void __init prom_free_prom_memory(void)
411{
Atsushi Nemotob6263ff2008-09-01 22:22:41 +0900412 unsigned long saddr = PAGE_SIZE;
413 unsigned long eaddr = __pa_symbol(&_text);
414
415 if (saddr < eaddr)
416 free_init_pages("prom memory", saddr, eaddr);
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900417}
418
419const char *get_system_type(void)
420{
421 return txx9_system_type;
422}
423
424char * __init prom_getcmdline(void)
425{
426 return &(arcs_cmdline[0]);
427}
428
Atsushi Nemoto265b89d2008-08-19 22:55:07 +0900429const char *__init prom_getenv(const char *name)
430{
Geert Uytterhoeven97b05112008-10-27 15:25:49 +0100431 const s32 *str;
Atsushi Nemoto265b89d2008-08-19 22:55:07 +0900432
Geert Uytterhoeven97b05112008-10-27 15:25:49 +0100433 if (fw_arg2 < CKSEG0)
Atsushi Nemoto265b89d2008-08-19 22:55:07 +0900434 return NULL;
Geert Uytterhoeven97b05112008-10-27 15:25:49 +0100435
436 str = (const s32 *)fw_arg2;
Atsushi Nemoto265b89d2008-08-19 22:55:07 +0900437 /* YAMON style ("name", "value" pairs) */
438 while (str[0] && str[1]) {
439 if (!strcmp((const char *)(unsigned long)str[0], name))
440 return (const char *)(unsigned long)str[1];
441 str += 2;
442 }
443 return NULL;
444}
445
Atsushi Nemotoa49297e2008-07-24 00:25:17 +0900446static void __noreturn txx9_machine_halt(void)
447{
448 local_irq_disable();
449 clear_c0_status(ST0_IM);
450 while (1) {
451 if (cpu_wait) {
452 (*cpu_wait)();
453 if (cpu_has_counter) {
454 /*
455 * Clear counter interrupt while it
456 * breaks WAIT instruction even if
457 * masked.
458 */
459 write_c0_compare(0);
460 }
461 }
462 }
463}
464
Atsushi Nemoto68314722008-07-24 00:25:18 +0900465/* Watchdog support */
466void __init txx9_wdt_init(unsigned long base)
467{
468 struct resource res = {
469 .start = base,
470 .end = base + 0x100 - 1,
471 .flags = IORESOURCE_MEM,
472 };
473 platform_device_register_simple("txx9wdt", -1, &res, 1);
474}
475
Atsushi Nemoto496a3b52008-08-19 22:55:15 +0900476void txx9_wdt_now(unsigned long base)
477{
478 struct txx9_tmr_reg __iomem *tmrptr =
479 ioremap(base, sizeof(struct txx9_tmr_reg));
480 /* disable watch dog timer */
481 __raw_writel(TXx9_TMWTMR_WDIS | TXx9_TMWTMR_TWC, &tmrptr->wtmr);
482 __raw_writel(0, &tmrptr->tcr);
483 /* kick watchdog */
484 __raw_writel(TXx9_TMWTMR_TWIE, &tmrptr->wtmr);
485 __raw_writel(1, &tmrptr->cpra); /* immediate */
486 __raw_writel(TXx9_TMTCR_TCE | TXx9_TMTCR_CCDE | TXx9_TMTCR_TMODE_WDOG,
487 &tmrptr->tcr);
488}
489
Atsushi Nemotoc49f91f2008-07-24 00:25:20 +0900490/* SPI support */
491void __init txx9_spi_init(int busid, unsigned long base, int irq)
492{
493 struct resource res[] = {
494 {
495 .start = base,
496 .end = base + 0x20 - 1,
497 .flags = IORESOURCE_MEM,
498 }, {
499 .start = irq,
500 .flags = IORESOURCE_IRQ,
501 },
502 };
503 platform_device_register_simple("spi_txx9", busid,
504 res, ARRAY_SIZE(res));
505}
506
507void __init txx9_ethaddr_init(unsigned int id, unsigned char *ethaddr)
508{
509 struct platform_device *pdev =
510 platform_device_alloc("tc35815-mac", id);
511 if (!pdev ||
512 platform_device_add_data(pdev, ethaddr, 6) ||
513 platform_device_add(pdev))
514 platform_device_put(pdev);
515}
516
Atsushi Nemoto7779a5e2008-07-25 23:08:06 +0900517void __init txx9_sio_init(unsigned long baseaddr, int irq,
518 unsigned int line, unsigned int sclk, int nocts)
519{
520#ifdef CONFIG_SERIAL_TXX9
521 struct uart_port req;
522
523 memset(&req, 0, sizeof(req));
524 req.line = line;
525 req.iotype = UPIO_MEM;
526 req.membase = ioremap(baseaddr, 0x24);
527 req.mapbase = baseaddr;
528 req.irq = irq;
529 if (!nocts)
530 req.flags |= UPF_BUGGY_UART /*HAVE_CTS_LINE*/;
531 if (sclk) {
532 req.flags |= UPF_MAGIC_MULTIPLIER /*USE_SCLK*/;
533 req.uartclk = sclk;
534 } else
535 req.uartclk = TXX9_IMCLK;
536 early_serial_txx9_setup(&req);
537#endif /* CONFIG_SERIAL_TXX9 */
538}
539
Atsushi Nemotoe3529532008-07-29 22:10:08 +0900540#ifdef CONFIG_EARLY_PRINTK
541static void __init null_prom_putchar(char c)
542{
543}
544void (*txx9_prom_putchar)(char c) __initdata = null_prom_putchar;
545
546void __init prom_putchar(char c)
547{
548 txx9_prom_putchar(c);
549}
550
551static void __iomem *early_txx9_sio_port;
552
553static void __init early_txx9_sio_putchar(char c)
554{
555#define TXX9_SICISR 0x0c
556#define TXX9_SITFIFO 0x1c
557#define TXX9_SICISR_TXALS 0x00000002
558 while (!(__raw_readl(early_txx9_sio_port + TXX9_SICISR) &
559 TXX9_SICISR_TXALS))
560 ;
561 __raw_writel(c, early_txx9_sio_port + TXX9_SITFIFO);
562}
563
564void __init txx9_sio_putchar_init(unsigned long baseaddr)
565{
566 early_txx9_sio_port = ioremap(baseaddr, 0x24);
567 txx9_prom_putchar = early_txx9_sio_putchar;
568}
569#endif /* CONFIG_EARLY_PRINTK */
570
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900571/* wrappers */
572void __init plat_mem_setup(void)
573{
Atsushi Nemoto94a4c322008-07-19 01:51:47 +0900574 ioport_resource.start = 0;
575 ioport_resource.end = ~0UL; /* no limit */
576 iomem_resource.start = 0;
577 iomem_resource.end = ~0UL; /* no limit */
Atsushi Nemotoa49297e2008-07-24 00:25:17 +0900578
579 /* fallback restart/halt routines */
580 _machine_restart = (void (*)(char *))txx9_machine_halt;
581 _machine_halt = txx9_machine_halt;
582 pm_power_off = txx9_machine_halt;
583
Atsushi Nemoto07517522008-07-24 00:25:15 +0900584#ifdef CONFIG_PCI
585 pcibios_plat_setup = txx9_pcibios_setup;
586#endif
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900587 txx9_board_vec->mem_setup();
588}
589
590void __init arch_init_irq(void)
591{
592 txx9_board_vec->irq_setup();
593}
594
595void __init plat_time_init(void)
596{
Atsushi Nemoto1374d082008-07-31 22:29:53 +0900597#ifdef CONFIG_CPU_TX49XX
598 mips_hpt_frequency = txx9_cpu_clock / 2;
599#endif
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900600 txx9_board_vec->time_init();
601}
602
603static int __init _txx9_arch_init(void)
604{
605 if (txx9_board_vec->arch_init)
606 txx9_board_vec->arch_init();
607 return 0;
608}
609arch_initcall(_txx9_arch_init);
610
611static int __init _txx9_device_init(void)
612{
613 if (txx9_board_vec->device_init)
614 txx9_board_vec->device_init();
615 return 0;
616}
617device_initcall(_txx9_device_init);
618
619int (*txx9_irq_dispatch)(int pending);
620asmlinkage void plat_irq_dispatch(void)
621{
622 int pending = read_c0_status() & read_c0_cause() & ST0_IM;
623 int irq = txx9_irq_dispatch(pending);
624
625 if (likely(irq >= 0))
626 do_IRQ(irq);
627 else
628 spurious_interrupt();
629}
Atsushi Nemoto4c642f32008-07-13 23:37:56 +0900630
631/* see include/asm-mips/mach-tx39xx/mangle-port.h, for example. */
632#ifdef NEEDS_TXX9_SWIZZLE_ADDR_B
633static unsigned long __swizzle_addr_none(unsigned long port)
634{
635 return port;
636}
637unsigned long (*__swizzle_addr_b)(unsigned long port) = __swizzle_addr_none;
638EXPORT_SYMBOL(__swizzle_addr_b);
639#endif
Atsushi Nemoto51f607c2008-08-19 22:55:11 +0900640
Atsushi Nemoto1ba5a172008-10-21 00:01:06 +0900641#ifdef NEEDS_TXX9_IOSWABW
642static u16 ioswabw_default(volatile u16 *a, u16 x)
643{
644 return le16_to_cpu(x);
645}
646static u16 __mem_ioswabw_default(volatile u16 *a, u16 x)
647{
648 return x;
649}
650u16 (*ioswabw)(volatile u16 *a, u16 x) = ioswabw_default;
651EXPORT_SYMBOL(ioswabw);
652u16 (*__mem_ioswabw)(volatile u16 *a, u16 x) = __mem_ioswabw_default;
653EXPORT_SYMBOL(__mem_ioswabw);
654#endif
655
Atsushi Nemoto51f607c2008-08-19 22:55:11 +0900656void __init txx9_physmap_flash_init(int no, unsigned long addr,
657 unsigned long size,
658 const struct physmap_flash_data *pdata)
659{
660#if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
661 struct resource res = {
662 .start = addr,
663 .end = addr + size - 1,
664 .flags = IORESOURCE_MEM,
665 };
666 struct platform_device *pdev;
667#ifdef CONFIG_MTD_PARTITIONS
668 static struct mtd_partition parts[2];
669 struct physmap_flash_data pdata_part;
670
671 /* If this area contained boot area, make separate partition */
672 if (pdata->nr_parts == 0 && !pdata->parts &&
673 addr < 0x1fc00000 && addr + size > 0x1fc00000 &&
674 !parts[0].name) {
675 parts[0].name = "boot";
676 parts[0].offset = 0x1fc00000 - addr;
677 parts[0].size = addr + size - 0x1fc00000;
678 parts[1].name = "user";
679 parts[1].offset = 0;
680 parts[1].size = 0x1fc00000 - addr;
681 pdata_part = *pdata;
682 pdata_part.nr_parts = ARRAY_SIZE(parts);
683 pdata_part.parts = parts;
684 pdata = &pdata_part;
685 }
686#endif
687 pdev = platform_device_alloc("physmap-flash", no);
688 if (!pdev ||
689 platform_device_add_resources(pdev, &res, 1) ||
690 platform_device_add_data(pdev, pdata, sizeof(*pdata)) ||
691 platform_device_add(pdev))
692 platform_device_put(pdev);
693#endif
694}
Atsushi Nemotoae027ea2008-09-01 22:22:38 +0900695
Atsushi Nemotoa591f5d2009-03-04 12:01:31 -0800696void __init txx9_ndfmc_init(unsigned long baseaddr,
697 const struct txx9ndfmc_platform_data *pdata)
698{
699#if defined(CONFIG_MTD_NAND_TXX9NDFMC) || \
700 defined(CONFIG_MTD_NAND_TXX9NDFMC_MODULE)
701 struct resource res = {
702 .start = baseaddr,
703 .end = baseaddr + 0x1000 - 1,
704 .flags = IORESOURCE_MEM,
705 };
706 struct platform_device *pdev = platform_device_alloc("txx9ndfmc", -1);
707
708 if (!pdev ||
709 platform_device_add_resources(pdev, &res, 1) ||
710 platform_device_add_data(pdev, pdata, sizeof(*pdata)) ||
711 platform_device_add(pdev))
712 platform_device_put(pdev);
713#endif
714}
715
Atsushi Nemotoae027ea2008-09-01 22:22:38 +0900716#if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
717static DEFINE_SPINLOCK(txx9_iocled_lock);
718
719#define TXX9_IOCLED_MAXLEDS 8
720
721struct txx9_iocled_data {
722 struct gpio_chip chip;
723 u8 cur_val;
724 void __iomem *mmioaddr;
725 struct gpio_led_platform_data pdata;
726 struct gpio_led leds[TXX9_IOCLED_MAXLEDS];
727 char names[TXX9_IOCLED_MAXLEDS][32];
728};
729
730static int txx9_iocled_get(struct gpio_chip *chip, unsigned int offset)
731{
732 struct txx9_iocled_data *data =
733 container_of(chip, struct txx9_iocled_data, chip);
734 return data->cur_val & (1 << offset);
735}
736
737static void txx9_iocled_set(struct gpio_chip *chip, unsigned int offset,
738 int value)
739{
740 struct txx9_iocled_data *data =
741 container_of(chip, struct txx9_iocled_data, chip);
742 unsigned long flags;
743 spin_lock_irqsave(&txx9_iocled_lock, flags);
744 if (value)
745 data->cur_val |= 1 << offset;
746 else
747 data->cur_val &= ~(1 << offset);
748 writeb(data->cur_val, data->mmioaddr);
749 mmiowb();
750 spin_unlock_irqrestore(&txx9_iocled_lock, flags);
751}
752
753static int txx9_iocled_dir_in(struct gpio_chip *chip, unsigned int offset)
754{
755 return 0;
756}
757
758static int txx9_iocled_dir_out(struct gpio_chip *chip, unsigned int offset,
759 int value)
760{
761 txx9_iocled_set(chip, offset, value);
762 return 0;
763}
764
765void __init txx9_iocled_init(unsigned long baseaddr,
766 int basenum, unsigned int num, int lowactive,
767 const char *color, char **deftriggers)
768{
769 struct txx9_iocled_data *iocled;
770 struct platform_device *pdev;
771 int i;
772 static char *default_triggers[] __initdata = {
773 "heartbeat",
774 "ide-disk",
775 "nand-disk",
776 NULL,
777 };
778
779 if (!deftriggers)
780 deftriggers = default_triggers;
781 iocled = kzalloc(sizeof(*iocled), GFP_KERNEL);
782 if (!iocled)
783 return;
784 iocled->mmioaddr = ioremap(baseaddr, 1);
785 if (!iocled->mmioaddr)
786 return;
787 iocled->chip.get = txx9_iocled_get;
788 iocled->chip.set = txx9_iocled_set;
789 iocled->chip.direction_input = txx9_iocled_dir_in;
790 iocled->chip.direction_output = txx9_iocled_dir_out;
791 iocled->chip.label = "iocled";
792 iocled->chip.base = basenum;
793 iocled->chip.ngpio = num;
794 if (gpiochip_add(&iocled->chip))
795 return;
796 if (basenum < 0)
797 basenum = iocled->chip.base;
798
799 pdev = platform_device_alloc("leds-gpio", basenum);
800 if (!pdev)
801 return;
802 iocled->pdata.num_leds = num;
803 iocled->pdata.leds = iocled->leds;
804 for (i = 0; i < num; i++) {
805 struct gpio_led *led = &iocled->leds[i];
806 snprintf(iocled->names[i], sizeof(iocled->names[i]),
807 "iocled:%s:%u", color, i);
808 led->name = iocled->names[i];
809 led->gpio = basenum + i;
810 led->active_low = lowactive;
811 if (deftriggers && *deftriggers)
812 led->default_trigger = *deftriggers++;
813 }
814 pdev->dev.platform_data = &iocled->pdata;
815 if (platform_device_add(pdev))
816 platform_device_put(pdev);
817}
818#else /* CONFIG_LEDS_GPIO */
819void __init txx9_iocled_init(unsigned long baseaddr,
820 int basenum, unsigned int num, int lowactive,
821 const char *color, char **deftriggers)
822{
823}
824#endif /* CONFIG_LEDS_GPIO */
Atsushi Nemotof48c8c92009-04-23 00:40:31 +0900825
826void __init txx9_dmac_init(int id, unsigned long baseaddr, int irq,
827 const struct txx9dmac_platform_data *pdata)
828{
829#if defined(CONFIG_TXX9_DMAC) || defined(CONFIG_TXX9_DMAC_MODULE)
830 struct resource res[] = {
831 {
832 .start = baseaddr,
833 .end = baseaddr + 0x800 - 1,
834 .flags = IORESOURCE_MEM,
835#ifndef CONFIG_MACH_TX49XX
836 }, {
837 .start = irq,
838 .flags = IORESOURCE_IRQ,
839#endif
840 }
841 };
842#ifdef CONFIG_MACH_TX49XX
843 struct resource chan_res[] = {
844 {
845 .flags = IORESOURCE_IRQ,
846 }
847 };
848#endif
849 struct platform_device *pdev = platform_device_alloc("txx9dmac", id);
850 struct txx9dmac_chan_platform_data cpdata;
851 int i;
852
853 if (!pdev ||
854 platform_device_add_resources(pdev, res, ARRAY_SIZE(res)) ||
855 platform_device_add_data(pdev, pdata, sizeof(*pdata)) ||
856 platform_device_add(pdev)) {
857 platform_device_put(pdev);
858 return;
859 }
860 memset(&cpdata, 0, sizeof(cpdata));
861 cpdata.dmac_dev = pdev;
862 for (i = 0; i < TXX9_DMA_MAX_NR_CHANNELS; i++) {
863#ifdef CONFIG_MACH_TX49XX
864 chan_res[0].start = irq + i;
865#endif
866 pdev = platform_device_alloc("txx9dmac-chan",
867 id * TXX9_DMA_MAX_NR_CHANNELS + i);
868 if (!pdev ||
869#ifdef CONFIG_MACH_TX49XX
870 platform_device_add_resources(pdev, chan_res,
871 ARRAY_SIZE(chan_res)) ||
872#endif
873 platform_device_add_data(pdev, &cpdata, sizeof(cpdata)) ||
874 platform_device_add(pdev))
875 platform_device_put(pdev);
876 }
877#endif
878}
Atsushi Nemoto742cd582009-05-19 22:12:22 +0900879
880void __init txx9_aclc_init(unsigned long baseaddr, int irq,
881 unsigned int dmac_id,
882 unsigned int dma_chan_out,
883 unsigned int dma_chan_in)
884{
885#if defined(CONFIG_SND_SOC_TXX9ACLC) || \
886 defined(CONFIG_SND_SOC_TXX9ACLC_MODULE)
887 unsigned int dma_base = dmac_id * TXX9_DMA_MAX_NR_CHANNELS;
888 struct resource res[] = {
889 {
890 .start = baseaddr,
891 .end = baseaddr + 0x100 - 1,
892 .flags = IORESOURCE_MEM,
893 }, {
894 .start = irq,
895 .flags = IORESOURCE_IRQ,
896 }, {
897 .name = "txx9dmac-chan",
898 .start = dma_base + dma_chan_out,
899 .flags = IORESOURCE_DMA,
900 }, {
901 .name = "txx9dmac-chan",
902 .start = dma_base + dma_chan_in,
903 .flags = IORESOURCE_DMA,
904 }
905 };
906 struct platform_device *pdev =
907 platform_device_alloc("txx9aclc-ac97", -1);
908
909 if (!pdev ||
910 platform_device_add_resources(pdev, res, ARRAY_SIZE(res)) ||
911 platform_device_add(pdev))
912 platform_device_put(pdev);
913#endif
914}