blob: 560fe89917537972050d9ed8ee09e78a2df736f8 [file] [log] [blame]
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +09001/*
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +09002 * Based on linux/arch/mips/txx9/rbtx4938/setup.c,
3 * and RBTX49xx patch from CELF patch archive.
4 *
5 * 2003-2005 (c) MontaVista Software, Inc.
6 * (C) Copyright TOSHIBA CORPORATION 2000-2001, 2004-2007
7 *
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file "COPYING" in the main directory of this archive
10 * for more details.
11 */
12#include <linux/init.h>
13#include <linux/kernel.h>
14#include <linux/types.h>
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090015#include <linux/interrupt.h>
16#include <linux/string.h>
17#include <linux/module.h>
18#include <linux/clk.h>
19#include <linux/err.h>
Atsushi Nemotoe0eb7302008-07-19 01:51:52 +090020#include <linux/gpio.h>
Atsushi Nemoto68314722008-07-24 00:25:18 +090021#include <linux/platform_device.h>
Atsushi Nemoto7779a5e2008-07-25 23:08:06 +090022#include <linux/serial_core.h>
Atsushi Nemoto51f607c2008-08-19 22:55:11 +090023#include <linux/mtd/physmap.h>
Atsushi Nemotoae027ea2008-09-01 22:22:38 +090024#include <linux/leds.h>
Kay Sievers269a3eb2011-12-21 15:09:54 -080025#include <linux/device.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090026#include <linux/slab.h>
David Howellsca4d3e672010-10-07 14:08:54 +010027#include <linux/irq.h>
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090028#include <asm/bootinfo.h>
Atsushi Nemotoe0eb7302008-07-19 01:51:52 +090029#include <asm/time.h>
Atsushi Nemotoa49297e2008-07-24 00:25:17 +090030#include <asm/reboot.h>
Atsushi Nemotod10e0252008-08-19 22:55:09 +090031#include <asm/r4kcache.h>
Atsushi Nemotob6263ff2008-09-01 22:22:41 +090032#include <asm/sections.h>
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090033#include <asm/txx9/generic.h>
Atsushi Nemoto07517522008-07-24 00:25:15 +090034#include <asm/txx9/pci.h>
Atsushi Nemoto496a3b52008-08-19 22:55:15 +090035#include <asm/txx9tmr.h>
Atsushi Nemotoa591f5d2009-03-04 12:01:31 -080036#include <asm/txx9/ndfmc.h>
Atsushi Nemotof48c8c92009-04-23 00:40:31 +090037#include <asm/txx9/dmac.h>
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090038#ifdef CONFIG_CPU_TX49XX
39#include <asm/txx9/tx4938.h>
40#endif
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090041
42/* EBUSC settings of TX4927, etc. */
43struct resource txx9_ce_res[8];
44static char txx9_ce_res_name[8][4]; /* "CEn" */
45
46/* pcode, internal register */
Atsushi Nemoto94a4c322008-07-19 01:51:47 +090047unsigned int txx9_pcode;
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090048char txx9_pcode_str[8];
49static struct resource txx9_reg_res = {
50 .name = txx9_pcode_str,
51 .flags = IORESOURCE_MEM,
52};
53void __init
54txx9_reg_res_init(unsigned int pcode, unsigned long base, unsigned long size)
55{
56 int i;
57
58 for (i = 0; i < ARRAY_SIZE(txx9_ce_res); i++) {
59 sprintf(txx9_ce_res_name[i], "CE%d", i);
60 txx9_ce_res[i].flags = IORESOURCE_MEM;
61 txx9_ce_res[i].name = txx9_ce_res_name[i];
62 }
63
Atsushi Nemoto073828d2008-08-26 21:29:58 +090064 txx9_pcode = pcode;
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090065 sprintf(txx9_pcode_str, "TX%x", pcode);
66 if (base) {
67 txx9_reg_res.start = base & 0xfffffffffULL;
68 txx9_reg_res.end = (base & 0xfffffffffULL) + (size - 1);
69 request_resource(&iomem_resource, &txx9_reg_res);
70 }
71}
72
73/* clocks */
74unsigned int txx9_master_clock;
75unsigned int txx9_cpu_clock;
76unsigned int txx9_gbus_clock;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090077
Atsushi Nemotoc7b95bc2008-08-19 22:55:10 +090078#ifdef CONFIG_CPU_TX39XX
79/* don't enable by default - see errata */
80int txx9_ccfg_toeon __initdata;
81#else
Atsushi Nemoto94a4c322008-07-19 01:51:47 +090082int txx9_ccfg_toeon __initdata = 1;
Atsushi Nemotoc7b95bc2008-08-19 22:55:10 +090083#endif
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090084
85/* Minimum CLK support */
86
87struct clk *clk_get(struct device *dev, const char *id)
88{
89 if (!strcmp(id, "spi-baseclk"))
Atsushi Nemotofcc152f2009-09-03 22:59:00 +090090 return (struct clk *)((unsigned long)txx9_gbus_clock / 2 / 2);
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090091 if (!strcmp(id, "imbus_clk"))
Atsushi Nemoto94a4c322008-07-19 01:51:47 +090092 return (struct clk *)((unsigned long)txx9_gbus_clock / 2);
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090093 return ERR_PTR(-ENOENT);
94}
95EXPORT_SYMBOL(clk_get);
96
97int clk_enable(struct clk *clk)
98{
99 return 0;
100}
101EXPORT_SYMBOL(clk_enable);
102
103void clk_disable(struct clk *clk)
104{
105}
106EXPORT_SYMBOL(clk_disable);
107
108unsigned long clk_get_rate(struct clk *clk)
109{
110 return (unsigned long)clk;
111}
112EXPORT_SYMBOL(clk_get_rate);
113
114void clk_put(struct clk *clk)
115{
116}
117EXPORT_SYMBOL(clk_put);
118
Atsushi Nemoto8d795f22008-07-18 00:43:48 +0900119/* GPIO support */
120
121#ifdef CONFIG_GENERIC_GPIO
122int gpio_to_irq(unsigned gpio)
123{
124 return -EINVAL;
125}
126EXPORT_SYMBOL(gpio_to_irq);
127
128int irq_to_gpio(unsigned irq)
129{
130 return -EINVAL;
131}
132EXPORT_SYMBOL(irq_to_gpio);
133#endif
134
Atsushi Nemoto860e5462008-08-19 22:55:08 +0900135#define BOARD_VEC(board) extern struct txx9_board_vec board;
136#include <asm/txx9/boards.h>
137#undef BOARD_VEC
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900138
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900139struct txx9_board_vec *txx9_board_vec __initdata;
140static char txx9_system_type[32];
141
Atsushi Nemoto860e5462008-08-19 22:55:08 +0900142static struct txx9_board_vec *board_vecs[] __initdata = {
143#define BOARD_VEC(board) &board,
144#include <asm/txx9/boards.h>
145#undef BOARD_VEC
146};
147
148static struct txx9_board_vec *__init find_board_byname(const char *name)
149{
150 int i;
151
152 /* search board_vecs table */
153 for (i = 0; i < ARRAY_SIZE(board_vecs); i++) {
154 if (strstr(board_vecs[i]->system, name))
155 return board_vecs[i];
156 }
157 return NULL;
158}
159
Atsushi Nemotoe0dfb202008-08-19 22:55:06 +0900160static void __init prom_init_cmdline(void)
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900161{
Geert Uytterhoeven97b05112008-10-27 15:25:49 +0100162 int argc;
163 int *argv32;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900164 int i; /* Always ignore the "-c" at argv[0] */
165
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 Nemotoe0dfb202008-08-19 22:55:06 +0900178 arcs_cmdline[0] = '\0';
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900179
180 for (i = 1; i < argc; i++) {
Atsushi Nemotoe0dfb202008-08-19 22:55:06 +0900181 char *str = (char *)(long)argv32[i];
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900182 if (i != 1)
183 strcat(arcs_cmdline, " ");
Atsushi Nemotoe0dfb202008-08-19 22:55:06 +0900184 if (strchr(str, ' ')) {
185 strcat(arcs_cmdline, "\"");
186 strcat(arcs_cmdline, str);
187 strcat(arcs_cmdline, "\"");
188 } else
189 strcat(arcs_cmdline, str);
190 }
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900191}
192
Atsushi Nemotod10e0252008-08-19 22:55:09 +0900193static int txx9_ic_disable __initdata;
194static int txx9_dc_disable __initdata;
195
196#if defined(CONFIG_CPU_TX49XX)
197/* flush all cache on very early stage (before 4k_cache_init) */
198static void __init early_flush_dcache(void)
199{
200 unsigned int conf = read_c0_config();
201 unsigned int dc_size = 1 << (12 + ((conf & CONF_DC) >> 6));
202 unsigned int linesz = 32;
203 unsigned long addr, end;
204
205 end = INDEX_BASE + dc_size / 4;
206 /* 4way, waybit=0 */
207 for (addr = INDEX_BASE; addr < end; addr += linesz) {
208 cache_op(Index_Writeback_Inv_D, addr | 0);
209 cache_op(Index_Writeback_Inv_D, addr | 1);
210 cache_op(Index_Writeback_Inv_D, addr | 2);
211 cache_op(Index_Writeback_Inv_D, addr | 3);
212 }
213}
214
215static void __init txx9_cache_fixup(void)
216{
217 unsigned int conf;
218
219 conf = read_c0_config();
220 /* flush and disable */
221 if (txx9_ic_disable) {
222 conf |= TX49_CONF_IC;
223 write_c0_config(conf);
224 }
225 if (txx9_dc_disable) {
226 early_flush_dcache();
227 conf |= TX49_CONF_DC;
228 write_c0_config(conf);
229 }
230
231 /* enable cache */
232 conf = read_c0_config();
233 if (!txx9_ic_disable)
234 conf &= ~TX49_CONF_IC;
235 if (!txx9_dc_disable)
236 conf &= ~TX49_CONF_DC;
237 write_c0_config(conf);
238
239 if (conf & TX49_CONF_IC)
240 pr_info("TX49XX I-Cache disabled.\n");
241 if (conf & TX49_CONF_DC)
242 pr_info("TX49XX D-Cache disabled.\n");
243}
244#elif defined(CONFIG_CPU_TX39XX)
245/* flush all cache on very early stage (before tx39_cache_init) */
246static void __init early_flush_dcache(void)
247{
248 unsigned int conf = read_c0_config();
249 unsigned int dc_size = 1 << (10 + ((conf & TX39_CONF_DCS_MASK) >>
250 TX39_CONF_DCS_SHIFT));
251 unsigned int linesz = 16;
252 unsigned long addr, end;
253
254 end = INDEX_BASE + dc_size / 2;
255 /* 2way, waybit=0 */
256 for (addr = INDEX_BASE; addr < end; addr += linesz) {
257 cache_op(Index_Writeback_Inv_D, addr | 0);
258 cache_op(Index_Writeback_Inv_D, addr | 1);
259 }
260}
261
262static void __init txx9_cache_fixup(void)
263{
264 unsigned int conf;
265
266 conf = read_c0_config();
267 /* flush and disable */
268 if (txx9_ic_disable) {
269 conf &= ~TX39_CONF_ICE;
270 write_c0_config(conf);
271 }
272 if (txx9_dc_disable) {
273 early_flush_dcache();
274 conf &= ~TX39_CONF_DCE;
275 write_c0_config(conf);
276 }
277
278 /* enable cache */
279 conf = read_c0_config();
280 if (!txx9_ic_disable)
281 conf |= TX39_CONF_ICE;
282 if (!txx9_dc_disable)
283 conf |= TX39_CONF_DCE;
284 write_c0_config(conf);
285
286 if (!(conf & TX39_CONF_ICE))
287 pr_info("TX39XX I-Cache disabled.\n");
288 if (!(conf & TX39_CONF_DCE))
289 pr_info("TX39XX D-Cache disabled.\n");
290}
291#else
292static inline void txx9_cache_fixup(void)
293{
294}
295#endif
296
Atsushi Nemoto860e5462008-08-19 22:55:08 +0900297static void __init preprocess_cmdline(void)
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900298{
Dmitri Vorobiev7580c9c2009-10-13 23:43:24 +0300299 static char cmdline[COMMAND_LINE_SIZE] __initdata;
Atsushi Nemoto860e5462008-08-19 22:55:08 +0900300 char *s;
301
302 strcpy(cmdline, arcs_cmdline);
303 s = cmdline;
304 arcs_cmdline[0] = '\0';
305 while (s && *s) {
306 char *str = strsep(&s, " ");
307 if (strncmp(str, "board=", 6) == 0) {
308 txx9_board_vec = find_board_byname(str + 6);
309 continue;
310 } else if (strncmp(str, "masterclk=", 10) == 0) {
311 unsigned long val;
312 if (strict_strtoul(str + 10, 10, &val) == 0)
313 txx9_master_clock = val;
314 continue;
Atsushi Nemotod10e0252008-08-19 22:55:09 +0900315 } else if (strcmp(str, "icdisable") == 0) {
316 txx9_ic_disable = 1;
317 continue;
318 } else if (strcmp(str, "dcdisable") == 0) {
319 txx9_dc_disable = 1;
320 continue;
Atsushi Nemotoc7b95bc2008-08-19 22:55:10 +0900321 } else if (strcmp(str, "toeoff") == 0) {
322 txx9_ccfg_toeon = 0;
323 continue;
324 } else if (strcmp(str, "toeon") == 0) {
325 txx9_ccfg_toeon = 1;
326 continue;
Atsushi Nemoto860e5462008-08-19 22:55:08 +0900327 }
328 if (arcs_cmdline[0])
329 strcat(arcs_cmdline, " ");
330 strcat(arcs_cmdline, str);
331 }
Atsushi Nemotod10e0252008-08-19 22:55:09 +0900332
333 txx9_cache_fixup();
Atsushi Nemoto860e5462008-08-19 22:55:08 +0900334}
335
336static void __init select_board(void)
337{
338 const char *envstr;
339
340 /* first, determine by "board=" argument in preprocess_cmdline() */
341 if (txx9_board_vec)
342 return;
343 /* next, determine by "board" envvar */
344 envstr = prom_getenv("board");
345 if (envstr) {
346 txx9_board_vec = find_board_byname(envstr);
347 if (txx9_board_vec)
348 return;
349 }
350
351 /* select "default" board */
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900352#ifdef CONFIG_CPU_TX39XX
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900353 txx9_board_vec = &jmr3927_vec;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900354#endif
355#ifdef CONFIG_CPU_TX49XX
356 switch (TX4938_REV_PCODE()) {
Atsushi Nemoto8d795f22008-07-18 00:43:48 +0900357#ifdef CONFIG_TOSHIBA_RBTX4927
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900358 case 0x4927:
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900359 txx9_board_vec = &rbtx4927_vec;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900360 break;
361 case 0x4937:
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900362 txx9_board_vec = &rbtx4937_vec;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900363 break;
Atsushi Nemoto8d795f22008-07-18 00:43:48 +0900364#endif
365#ifdef CONFIG_TOSHIBA_RBTX4938
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900366 case 0x4938:
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900367 txx9_board_vec = &rbtx4938_vec;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900368 break;
Atsushi Nemoto8d795f22008-07-18 00:43:48 +0900369#endif
Atsushi Nemotob27311e2008-09-01 22:22:40 +0900370#ifdef CONFIG_TOSHIBA_RBTX4939
371 case 0x4939:
372 txx9_board_vec = &rbtx4939_vec;
373 break;
374#endif
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900375 }
376#endif
Atsushi Nemoto860e5462008-08-19 22:55:08 +0900377}
378
379void __init prom_init(void)
380{
381 prom_init_cmdline();
382 preprocess_cmdline();
383 select_board();
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900384
385 strcpy(txx9_system_type, txx9_board_vec->system);
386
Atsushi Nemoto7b226092008-07-14 00:15:04 +0900387 txx9_board_vec->prom_init();
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900388}
389
390void __init prom_free_prom_memory(void)
391{
Atsushi Nemotob6263ff2008-09-01 22:22:41 +0900392 unsigned long saddr = PAGE_SIZE;
393 unsigned long eaddr = __pa_symbol(&_text);
394
395 if (saddr < eaddr)
396 free_init_pages("prom memory", saddr, eaddr);
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900397}
398
399const char *get_system_type(void)
400{
401 return txx9_system_type;
402}
403
Atsushi Nemoto265b89d2008-08-19 22:55:07 +0900404const char *__init prom_getenv(const char *name)
405{
Geert Uytterhoeven97b05112008-10-27 15:25:49 +0100406 const s32 *str;
Atsushi Nemoto265b89d2008-08-19 22:55:07 +0900407
Geert Uytterhoeven97b05112008-10-27 15:25:49 +0100408 if (fw_arg2 < CKSEG0)
Atsushi Nemoto265b89d2008-08-19 22:55:07 +0900409 return NULL;
Geert Uytterhoeven97b05112008-10-27 15:25:49 +0100410
411 str = (const s32 *)fw_arg2;
Atsushi Nemoto265b89d2008-08-19 22:55:07 +0900412 /* YAMON style ("name", "value" pairs) */
413 while (str[0] && str[1]) {
414 if (!strcmp((const char *)(unsigned long)str[0], name))
415 return (const char *)(unsigned long)str[1];
416 str += 2;
417 }
418 return NULL;
419}
420
Atsushi Nemotoa49297e2008-07-24 00:25:17 +0900421static void __noreturn txx9_machine_halt(void)
422{
423 local_irq_disable();
424 clear_c0_status(ST0_IM);
425 while (1) {
426 if (cpu_wait) {
427 (*cpu_wait)();
428 if (cpu_has_counter) {
429 /*
430 * Clear counter interrupt while it
431 * breaks WAIT instruction even if
432 * masked.
433 */
434 write_c0_compare(0);
435 }
436 }
437 }
438}
439
Atsushi Nemoto68314722008-07-24 00:25:18 +0900440/* Watchdog support */
441void __init txx9_wdt_init(unsigned long base)
442{
443 struct resource res = {
444 .start = base,
445 .end = base + 0x100 - 1,
446 .flags = IORESOURCE_MEM,
447 };
448 platform_device_register_simple("txx9wdt", -1, &res, 1);
449}
450
Atsushi Nemoto496a3b52008-08-19 22:55:15 +0900451void txx9_wdt_now(unsigned long base)
452{
453 struct txx9_tmr_reg __iomem *tmrptr =
454 ioremap(base, sizeof(struct txx9_tmr_reg));
455 /* disable watch dog timer */
456 __raw_writel(TXx9_TMWTMR_WDIS | TXx9_TMWTMR_TWC, &tmrptr->wtmr);
457 __raw_writel(0, &tmrptr->tcr);
458 /* kick watchdog */
459 __raw_writel(TXx9_TMWTMR_TWIE, &tmrptr->wtmr);
460 __raw_writel(1, &tmrptr->cpra); /* immediate */
461 __raw_writel(TXx9_TMTCR_TCE | TXx9_TMTCR_CCDE | TXx9_TMTCR_TMODE_WDOG,
462 &tmrptr->tcr);
463}
464
Atsushi Nemotoc49f91f2008-07-24 00:25:20 +0900465/* SPI support */
466void __init txx9_spi_init(int busid, unsigned long base, int irq)
467{
468 struct resource res[] = {
469 {
470 .start = base,
471 .end = base + 0x20 - 1,
472 .flags = IORESOURCE_MEM,
473 }, {
474 .start = irq,
475 .flags = IORESOURCE_IRQ,
476 },
477 };
478 platform_device_register_simple("spi_txx9", busid,
479 res, ARRAY_SIZE(res));
480}
481
482void __init txx9_ethaddr_init(unsigned int id, unsigned char *ethaddr)
483{
484 struct platform_device *pdev =
485 platform_device_alloc("tc35815-mac", id);
486 if (!pdev ||
487 platform_device_add_data(pdev, ethaddr, 6) ||
488 platform_device_add(pdev))
489 platform_device_put(pdev);
490}
491
Atsushi Nemoto7779a5e2008-07-25 23:08:06 +0900492void __init txx9_sio_init(unsigned long baseaddr, int irq,
493 unsigned int line, unsigned int sclk, int nocts)
494{
495#ifdef CONFIG_SERIAL_TXX9
496 struct uart_port req;
497
498 memset(&req, 0, sizeof(req));
499 req.line = line;
500 req.iotype = UPIO_MEM;
501 req.membase = ioremap(baseaddr, 0x24);
502 req.mapbase = baseaddr;
503 req.irq = irq;
504 if (!nocts)
505 req.flags |= UPF_BUGGY_UART /*HAVE_CTS_LINE*/;
506 if (sclk) {
507 req.flags |= UPF_MAGIC_MULTIPLIER /*USE_SCLK*/;
508 req.uartclk = sclk;
509 } else
510 req.uartclk = TXX9_IMCLK;
511 early_serial_txx9_setup(&req);
512#endif /* CONFIG_SERIAL_TXX9 */
513}
514
Atsushi Nemotoe3529532008-07-29 22:10:08 +0900515#ifdef CONFIG_EARLY_PRINTK
516static void __init null_prom_putchar(char c)
517{
518}
519void (*txx9_prom_putchar)(char c) __initdata = null_prom_putchar;
520
521void __init prom_putchar(char c)
522{
523 txx9_prom_putchar(c);
524}
525
526static void __iomem *early_txx9_sio_port;
527
528static void __init early_txx9_sio_putchar(char c)
529{
530#define TXX9_SICISR 0x0c
531#define TXX9_SITFIFO 0x1c
532#define TXX9_SICISR_TXALS 0x00000002
533 while (!(__raw_readl(early_txx9_sio_port + TXX9_SICISR) &
534 TXX9_SICISR_TXALS))
535 ;
536 __raw_writel(c, early_txx9_sio_port + TXX9_SITFIFO);
537}
538
539void __init txx9_sio_putchar_init(unsigned long baseaddr)
540{
541 early_txx9_sio_port = ioremap(baseaddr, 0x24);
542 txx9_prom_putchar = early_txx9_sio_putchar;
543}
544#endif /* CONFIG_EARLY_PRINTK */
545
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900546/* wrappers */
547void __init plat_mem_setup(void)
548{
Atsushi Nemoto94a4c322008-07-19 01:51:47 +0900549 ioport_resource.start = 0;
550 ioport_resource.end = ~0UL; /* no limit */
551 iomem_resource.start = 0;
552 iomem_resource.end = ~0UL; /* no limit */
Atsushi Nemotoa49297e2008-07-24 00:25:17 +0900553
554 /* fallback restart/halt routines */
555 _machine_restart = (void (*)(char *))txx9_machine_halt;
556 _machine_halt = txx9_machine_halt;
557 pm_power_off = txx9_machine_halt;
558
Atsushi Nemoto07517522008-07-24 00:25:15 +0900559#ifdef CONFIG_PCI
560 pcibios_plat_setup = txx9_pcibios_setup;
561#endif
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900562 txx9_board_vec->mem_setup();
563}
564
565void __init arch_init_irq(void)
566{
567 txx9_board_vec->irq_setup();
568}
569
570void __init plat_time_init(void)
571{
Atsushi Nemoto1374d082008-07-31 22:29:53 +0900572#ifdef CONFIG_CPU_TX49XX
573 mips_hpt_frequency = txx9_cpu_clock / 2;
574#endif
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900575 txx9_board_vec->time_init();
576}
577
578static int __init _txx9_arch_init(void)
579{
580 if (txx9_board_vec->arch_init)
581 txx9_board_vec->arch_init();
582 return 0;
583}
584arch_initcall(_txx9_arch_init);
585
586static int __init _txx9_device_init(void)
587{
588 if (txx9_board_vec->device_init)
589 txx9_board_vec->device_init();
590 return 0;
591}
592device_initcall(_txx9_device_init);
593
594int (*txx9_irq_dispatch)(int pending);
595asmlinkage void plat_irq_dispatch(void)
596{
597 int pending = read_c0_status() & read_c0_cause() & ST0_IM;
598 int irq = txx9_irq_dispatch(pending);
599
600 if (likely(irq >= 0))
601 do_IRQ(irq);
602 else
603 spurious_interrupt();
604}
Atsushi Nemoto4c642f32008-07-13 23:37:56 +0900605
606/* see include/asm-mips/mach-tx39xx/mangle-port.h, for example. */
607#ifdef NEEDS_TXX9_SWIZZLE_ADDR_B
608static unsigned long __swizzle_addr_none(unsigned long port)
609{
610 return port;
611}
612unsigned long (*__swizzle_addr_b)(unsigned long port) = __swizzle_addr_none;
613EXPORT_SYMBOL(__swizzle_addr_b);
614#endif
Atsushi Nemoto51f607c2008-08-19 22:55:11 +0900615
Atsushi Nemoto1ba5a172008-10-21 00:01:06 +0900616#ifdef NEEDS_TXX9_IOSWABW
617static u16 ioswabw_default(volatile u16 *a, u16 x)
618{
619 return le16_to_cpu(x);
620}
621static u16 __mem_ioswabw_default(volatile u16 *a, u16 x)
622{
623 return x;
624}
625u16 (*ioswabw)(volatile u16 *a, u16 x) = ioswabw_default;
626EXPORT_SYMBOL(ioswabw);
627u16 (*__mem_ioswabw)(volatile u16 *a, u16 x) = __mem_ioswabw_default;
628EXPORT_SYMBOL(__mem_ioswabw);
629#endif
630
Atsushi Nemoto51f607c2008-08-19 22:55:11 +0900631void __init txx9_physmap_flash_init(int no, unsigned long addr,
632 unsigned long size,
633 const struct physmap_flash_data *pdata)
634{
Florian Fainellib33b4402012-01-31 18:19:05 +0100635#if IS_ENABLED(CONFIG_MTD_PHYSMAP)
Atsushi Nemoto51f607c2008-08-19 22:55:11 +0900636 struct resource res = {
637 .start = addr,
638 .end = addr + size - 1,
639 .flags = IORESOURCE_MEM,
640 };
641 struct platform_device *pdev;
Atsushi Nemoto51f607c2008-08-19 22:55:11 +0900642 static struct mtd_partition parts[2];
643 struct physmap_flash_data pdata_part;
644
645 /* If this area contained boot area, make separate partition */
646 if (pdata->nr_parts == 0 && !pdata->parts &&
647 addr < 0x1fc00000 && addr + size > 0x1fc00000 &&
648 !parts[0].name) {
649 parts[0].name = "boot";
650 parts[0].offset = 0x1fc00000 - addr;
651 parts[0].size = addr + size - 0x1fc00000;
652 parts[1].name = "user";
653 parts[1].offset = 0;
654 parts[1].size = 0x1fc00000 - addr;
655 pdata_part = *pdata;
656 pdata_part.nr_parts = ARRAY_SIZE(parts);
657 pdata_part.parts = parts;
658 pdata = &pdata_part;
659 }
Jamie Iles47854882011-05-23 10:22:55 +0100660
Atsushi Nemoto51f607c2008-08-19 22:55:11 +0900661 pdev = platform_device_alloc("physmap-flash", no);
662 if (!pdev ||
663 platform_device_add_resources(pdev, &res, 1) ||
664 platform_device_add_data(pdev, pdata, sizeof(*pdata)) ||
665 platform_device_add(pdev))
666 platform_device_put(pdev);
667#endif
668}
Atsushi Nemotoae027ea2008-09-01 22:22:38 +0900669
Atsushi Nemotoa591f5d2009-03-04 12:01:31 -0800670void __init txx9_ndfmc_init(unsigned long baseaddr,
671 const struct txx9ndfmc_platform_data *pdata)
672{
Florian Fainellib33b4402012-01-31 18:19:05 +0100673#if IS_ENABLED(CONFIG_MTD_NAND_TXX9NDFMC)
Atsushi Nemotoa591f5d2009-03-04 12:01:31 -0800674 struct resource res = {
675 .start = baseaddr,
676 .end = baseaddr + 0x1000 - 1,
677 .flags = IORESOURCE_MEM,
678 };
679 struct platform_device *pdev = platform_device_alloc("txx9ndfmc", -1);
680
681 if (!pdev ||
682 platform_device_add_resources(pdev, &res, 1) ||
683 platform_device_add_data(pdev, pdata, sizeof(*pdata)) ||
684 platform_device_add(pdev))
685 platform_device_put(pdev);
686#endif
687}
688
Florian Fainellib33b4402012-01-31 18:19:05 +0100689#if IS_ENABLED(CONFIG_LEDS_GPIO)
Atsushi Nemotoae027ea2008-09-01 22:22:38 +0900690static DEFINE_SPINLOCK(txx9_iocled_lock);
691
692#define TXX9_IOCLED_MAXLEDS 8
693
694struct txx9_iocled_data {
695 struct gpio_chip chip;
696 u8 cur_val;
697 void __iomem *mmioaddr;
698 struct gpio_led_platform_data pdata;
699 struct gpio_led leds[TXX9_IOCLED_MAXLEDS];
700 char names[TXX9_IOCLED_MAXLEDS][32];
701};
702
703static int txx9_iocled_get(struct gpio_chip *chip, unsigned int offset)
704{
705 struct txx9_iocled_data *data =
706 container_of(chip, struct txx9_iocled_data, chip);
707 return data->cur_val & (1 << offset);
708}
709
710static void txx9_iocled_set(struct gpio_chip *chip, unsigned int offset,
711 int value)
712{
713 struct txx9_iocled_data *data =
714 container_of(chip, struct txx9_iocled_data, chip);
715 unsigned long flags;
716 spin_lock_irqsave(&txx9_iocled_lock, flags);
717 if (value)
718 data->cur_val |= 1 << offset;
719 else
720 data->cur_val &= ~(1 << offset);
721 writeb(data->cur_val, data->mmioaddr);
722 mmiowb();
723 spin_unlock_irqrestore(&txx9_iocled_lock, flags);
724}
725
726static int txx9_iocled_dir_in(struct gpio_chip *chip, unsigned int offset)
727{
728 return 0;
729}
730
731static int txx9_iocled_dir_out(struct gpio_chip *chip, unsigned int offset,
732 int value)
733{
734 txx9_iocled_set(chip, offset, value);
735 return 0;
736}
737
738void __init txx9_iocled_init(unsigned long baseaddr,
739 int basenum, unsigned int num, int lowactive,
740 const char *color, char **deftriggers)
741{
742 struct txx9_iocled_data *iocled;
743 struct platform_device *pdev;
744 int i;
745 static char *default_triggers[] __initdata = {
746 "heartbeat",
747 "ide-disk",
748 "nand-disk",
749 NULL,
750 };
751
752 if (!deftriggers)
753 deftriggers = default_triggers;
754 iocled = kzalloc(sizeof(*iocled), GFP_KERNEL);
755 if (!iocled)
756 return;
757 iocled->mmioaddr = ioremap(baseaddr, 1);
758 if (!iocled->mmioaddr)
Julia Lawall70ebadc2009-09-13 21:15:18 +0200759 goto out_free;
Atsushi Nemotoae027ea2008-09-01 22:22:38 +0900760 iocled->chip.get = txx9_iocled_get;
761 iocled->chip.set = txx9_iocled_set;
762 iocled->chip.direction_input = txx9_iocled_dir_in;
763 iocled->chip.direction_output = txx9_iocled_dir_out;
764 iocled->chip.label = "iocled";
765 iocled->chip.base = basenum;
766 iocled->chip.ngpio = num;
767 if (gpiochip_add(&iocled->chip))
Julia Lawall70ebadc2009-09-13 21:15:18 +0200768 goto out_unmap;
Atsushi Nemotoae027ea2008-09-01 22:22:38 +0900769 if (basenum < 0)
770 basenum = iocled->chip.base;
771
772 pdev = platform_device_alloc("leds-gpio", basenum);
773 if (!pdev)
Julia Lawall70ebadc2009-09-13 21:15:18 +0200774 goto out_gpio;
Atsushi Nemotoae027ea2008-09-01 22:22:38 +0900775 iocled->pdata.num_leds = num;
776 iocled->pdata.leds = iocled->leds;
777 for (i = 0; i < num; i++) {
778 struct gpio_led *led = &iocled->leds[i];
779 snprintf(iocled->names[i], sizeof(iocled->names[i]),
780 "iocled:%s:%u", color, i);
781 led->name = iocled->names[i];
782 led->gpio = basenum + i;
783 led->active_low = lowactive;
784 if (deftriggers && *deftriggers)
785 led->default_trigger = *deftriggers++;
786 }
787 pdev->dev.platform_data = &iocled->pdata;
788 if (platform_device_add(pdev))
Julia Lawall70ebadc2009-09-13 21:15:18 +0200789 goto out_pdev;
790 return;
791out_pdev:
792 platform_device_put(pdev);
793out_gpio:
Ralf Roescha2e62f32009-09-16 08:01:20 +0200794 if (gpiochip_remove(&iocled->chip))
795 return;
Julia Lawall70ebadc2009-09-13 21:15:18 +0200796out_unmap:
797 iounmap(iocled->mmioaddr);
798out_free:
799 kfree(iocled);
Atsushi Nemotoae027ea2008-09-01 22:22:38 +0900800}
801#else /* CONFIG_LEDS_GPIO */
802void __init txx9_iocled_init(unsigned long baseaddr,
803 int basenum, unsigned int num, int lowactive,
804 const char *color, char **deftriggers)
805{
806}
807#endif /* CONFIG_LEDS_GPIO */
Atsushi Nemotof48c8c92009-04-23 00:40:31 +0900808
809void __init txx9_dmac_init(int id, unsigned long baseaddr, int irq,
810 const struct txx9dmac_platform_data *pdata)
811{
Florian Fainellib33b4402012-01-31 18:19:05 +0100812#if IS_ENABLED(CONFIG_TXX9_DMAC)
Atsushi Nemotof48c8c92009-04-23 00:40:31 +0900813 struct resource res[] = {
814 {
815 .start = baseaddr,
816 .end = baseaddr + 0x800 - 1,
817 .flags = IORESOURCE_MEM,
818#ifndef CONFIG_MACH_TX49XX
819 }, {
820 .start = irq,
821 .flags = IORESOURCE_IRQ,
822#endif
823 }
824 };
825#ifdef CONFIG_MACH_TX49XX
826 struct resource chan_res[] = {
827 {
828 .flags = IORESOURCE_IRQ,
829 }
830 };
831#endif
832 struct platform_device *pdev = platform_device_alloc("txx9dmac", id);
833 struct txx9dmac_chan_platform_data cpdata;
834 int i;
835
836 if (!pdev ||
837 platform_device_add_resources(pdev, res, ARRAY_SIZE(res)) ||
838 platform_device_add_data(pdev, pdata, sizeof(*pdata)) ||
839 platform_device_add(pdev)) {
840 platform_device_put(pdev);
841 return;
842 }
843 memset(&cpdata, 0, sizeof(cpdata));
844 cpdata.dmac_dev = pdev;
845 for (i = 0; i < TXX9_DMA_MAX_NR_CHANNELS; i++) {
846#ifdef CONFIG_MACH_TX49XX
847 chan_res[0].start = irq + i;
848#endif
849 pdev = platform_device_alloc("txx9dmac-chan",
850 id * TXX9_DMA_MAX_NR_CHANNELS + i);
851 if (!pdev ||
852#ifdef CONFIG_MACH_TX49XX
853 platform_device_add_resources(pdev, chan_res,
854 ARRAY_SIZE(chan_res)) ||
855#endif
856 platform_device_add_data(pdev, &cpdata, sizeof(cpdata)) ||
857 platform_device_add(pdev))
858 platform_device_put(pdev);
859 }
860#endif
861}
Atsushi Nemoto742cd582009-05-19 22:12:22 +0900862
863void __init txx9_aclc_init(unsigned long baseaddr, int irq,
864 unsigned int dmac_id,
865 unsigned int dma_chan_out,
866 unsigned int dma_chan_in)
867{
Florian Fainellib33b4402012-01-31 18:19:05 +0100868#if IS_ENABLED(CONFIG_SND_SOC_TXX9ACLC)
Atsushi Nemoto742cd582009-05-19 22:12:22 +0900869 unsigned int dma_base = dmac_id * TXX9_DMA_MAX_NR_CHANNELS;
870 struct resource res[] = {
871 {
872 .start = baseaddr,
873 .end = baseaddr + 0x100 - 1,
874 .flags = IORESOURCE_MEM,
875 }, {
876 .start = irq,
877 .flags = IORESOURCE_IRQ,
878 }, {
879 .name = "txx9dmac-chan",
880 .start = dma_base + dma_chan_out,
881 .flags = IORESOURCE_DMA,
882 }, {
883 .name = "txx9dmac-chan",
884 .start = dma_base + dma_chan_in,
885 .flags = IORESOURCE_DMA,
886 }
887 };
888 struct platform_device *pdev =
889 platform_device_alloc("txx9aclc-ac97", -1);
890
891 if (!pdev ||
892 platform_device_add_resources(pdev, res, ARRAY_SIZE(res)) ||
893 platform_device_add(pdev))
894 platform_device_put(pdev);
895#endif
896}
Atsushi Nemotoc3b28ae2009-05-25 22:04:02 +0900897
Kay Sievers269a3eb2011-12-21 15:09:54 -0800898static struct bus_type txx9_sramc_subsys = {
899 .name = "txx9_sram",
900 .dev_name = "txx9_sram",
901};
Atsushi Nemotoc3b28ae2009-05-25 22:04:02 +0900902
Kay Sievers269a3eb2011-12-21 15:09:54 -0800903struct txx9_sramc_dev {
904 struct device dev;
Atsushi Nemotoc3b28ae2009-05-25 22:04:02 +0900905 struct bin_attribute bindata_attr;
906 void __iomem *base;
907};
908
Chris Wright2c3c8be2010-05-12 18:28:57 -0700909static ssize_t txx9_sram_read(struct file *filp, struct kobject *kobj,
Atsushi Nemotoc3b28ae2009-05-25 22:04:02 +0900910 struct bin_attribute *bin_attr,
911 char *buf, loff_t pos, size_t size)
912{
Kay Sievers269a3eb2011-12-21 15:09:54 -0800913 struct txx9_sramc_dev *dev = bin_attr->private;
Atsushi Nemotoc3b28ae2009-05-25 22:04:02 +0900914 size_t ramsize = bin_attr->size;
915
916 if (pos >= ramsize)
917 return 0;
918 if (pos + size > ramsize)
919 size = ramsize - pos;
920 memcpy_fromio(buf, dev->base + pos, size);
921 return size;
922}
923
Chris Wright2c3c8be2010-05-12 18:28:57 -0700924static ssize_t txx9_sram_write(struct file *filp, struct kobject *kobj,
Atsushi Nemotoc3b28ae2009-05-25 22:04:02 +0900925 struct bin_attribute *bin_attr,
926 char *buf, loff_t pos, size_t size)
927{
Kay Sievers269a3eb2011-12-21 15:09:54 -0800928 struct txx9_sramc_dev *dev = bin_attr->private;
Atsushi Nemotoc3b28ae2009-05-25 22:04:02 +0900929 size_t ramsize = bin_attr->size;
930
931 if (pos >= ramsize)
932 return 0;
933 if (pos + size > ramsize)
934 size = ramsize - pos;
935 memcpy_toio(dev->base + pos, buf, size);
936 return size;
937}
938
939void __init txx9_sramc_init(struct resource *r)
940{
Kay Sievers269a3eb2011-12-21 15:09:54 -0800941 struct txx9_sramc_dev *dev;
Atsushi Nemotoc3b28ae2009-05-25 22:04:02 +0900942 size_t size;
943 int err;
944
Kay Sievers269a3eb2011-12-21 15:09:54 -0800945 err = subsys_system_register(&txx9_sramc_subsys, NULL);
946 if (err)
947 return;
Atsushi Nemotoc3b28ae2009-05-25 22:04:02 +0900948 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
949 if (!dev)
950 return;
951 size = resource_size(r);
952 dev->base = ioremap(r->start, size);
953 if (!dev->base)
954 goto exit;
Kay Sievers269a3eb2011-12-21 15:09:54 -0800955 dev->dev.bus = &txx9_sramc_subsys;
Wolfram Sangf9373312010-03-15 01:29:41 +0100956 sysfs_bin_attr_init(&dev->bindata_attr);
Atsushi Nemotoc3b28ae2009-05-25 22:04:02 +0900957 dev->bindata_attr.attr.name = "bindata";
958 dev->bindata_attr.attr.mode = S_IRUSR | S_IWUSR;
959 dev->bindata_attr.read = txx9_sram_read;
960 dev->bindata_attr.write = txx9_sram_write;
961 dev->bindata_attr.size = size;
962 dev->bindata_attr.private = dev;
Kay Sievers269a3eb2011-12-21 15:09:54 -0800963 err = device_register(&dev->dev);
Atsushi Nemotoc3b28ae2009-05-25 22:04:02 +0900964 if (err)
965 goto exit;
966 err = sysfs_create_bin_file(&dev->dev.kobj, &dev->bindata_attr);
967 if (err) {
Kay Sievers269a3eb2011-12-21 15:09:54 -0800968 device_unregister(&dev->dev);
Atsushi Nemotoc3b28ae2009-05-25 22:04:02 +0900969 goto exit;
970 }
971 return;
972exit:
973 if (dev) {
974 if (dev->base)
975 iounmap(dev->base);
976 kfree(dev);
977 }
978}