blob: a1d98b5c8fd6757683d1e9c23196660676006a54 [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>
Geert Uytterhoeven44ce9a92016-09-11 10:59:58 +020018#include <linux/clk-provider.h>
19#include <linux/clkdev.h>
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090020#include <linux/err.h>
Linus Walleijbe7658f2015-12-08 14:40:40 +010021#include <linux/gpio/driver.h>
Atsushi Nemoto68314722008-07-24 00:25:18 +090022#include <linux/platform_device.h>
Atsushi Nemoto7779a5e2008-07-25 23:08:06 +090023#include <linux/serial_core.h>
Atsushi Nemoto51f607c2008-08-19 22:55:11 +090024#include <linux/mtd/physmap.h>
Atsushi Nemotoae027ea2008-09-01 22:22:38 +090025#include <linux/leds.h>
Kay Sievers269a3eb2011-12-21 15:09:54 -080026#include <linux/device.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090027#include <linux/slab.h>
David Howellsca4d3e672010-10-07 14:08:54 +010028#include <linux/irq.h>
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090029#include <asm/bootinfo.h>
Ralf Baechlebdc92d742013-05-21 16:59:19 +020030#include <asm/idle.h>
Atsushi Nemotoe0eb7302008-07-19 01:51:52 +090031#include <asm/time.h>
Atsushi Nemotoa49297e2008-07-24 00:25:17 +090032#include <asm/reboot.h>
Atsushi Nemotod10e0252008-08-19 22:55:09 +090033#include <asm/r4kcache.h>
Atsushi Nemotob6263ff2008-09-01 22:22:41 +090034#include <asm/sections.h>
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090035#include <asm/txx9/generic.h>
Atsushi Nemoto07517522008-07-24 00:25:15 +090036#include <asm/txx9/pci.h>
Atsushi Nemoto496a3b52008-08-19 22:55:15 +090037#include <asm/txx9tmr.h>
Atsushi Nemotoa591f5d2009-03-04 12:01:31 -080038#include <asm/txx9/ndfmc.h>
Atsushi Nemotof48c8c92009-04-23 00:40:31 +090039#include <asm/txx9/dmac.h>
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090040#ifdef CONFIG_CPU_TX49XX
41#include <asm/txx9/tx4938.h>
42#endif
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090043
44/* EBUSC settings of TX4927, etc. */
45struct resource txx9_ce_res[8];
46static char txx9_ce_res_name[8][4]; /* "CEn" */
47
48/* pcode, internal register */
Atsushi Nemoto94a4c322008-07-19 01:51:47 +090049unsigned int txx9_pcode;
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090050char txx9_pcode_str[8];
51static struct resource txx9_reg_res = {
52 .name = txx9_pcode_str,
53 .flags = IORESOURCE_MEM,
54};
55void __init
56txx9_reg_res_init(unsigned int pcode, unsigned long base, unsigned long size)
57{
58 int i;
59
60 for (i = 0; i < ARRAY_SIZE(txx9_ce_res); i++) {
61 sprintf(txx9_ce_res_name[i], "CE%d", i);
62 txx9_ce_res[i].flags = IORESOURCE_MEM;
63 txx9_ce_res[i].name = txx9_ce_res_name[i];
64 }
65
Atsushi Nemoto073828d2008-08-26 21:29:58 +090066 txx9_pcode = pcode;
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090067 sprintf(txx9_pcode_str, "TX%x", pcode);
68 if (base) {
69 txx9_reg_res.start = base & 0xfffffffffULL;
70 txx9_reg_res.end = (base & 0xfffffffffULL) + (size - 1);
71 request_resource(&iomem_resource, &txx9_reg_res);
72 }
73}
74
75/* clocks */
76unsigned int txx9_master_clock;
77unsigned int txx9_cpu_clock;
78unsigned int txx9_gbus_clock;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090079
Atsushi Nemotoc7b95bc2008-08-19 22:55:10 +090080#ifdef CONFIG_CPU_TX39XX
81/* don't enable by default - see errata */
82int txx9_ccfg_toeon __initdata;
83#else
Atsushi Nemoto94a4c322008-07-19 01:51:47 +090084int txx9_ccfg_toeon __initdata = 1;
Atsushi Nemotoc7b95bc2008-08-19 22:55:10 +090085#endif
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090086
Atsushi Nemoto860e5462008-08-19 22:55:08 +090087#define BOARD_VEC(board) extern struct txx9_board_vec board;
88#include <asm/txx9/boards.h>
89#undef BOARD_VEC
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090090
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +090091struct txx9_board_vec *txx9_board_vec __initdata;
92static char txx9_system_type[32];
93
Atsushi Nemoto860e5462008-08-19 22:55:08 +090094static struct txx9_board_vec *board_vecs[] __initdata = {
95#define BOARD_VEC(board) &board,
96#include <asm/txx9/boards.h>
97#undef BOARD_VEC
98};
99
100static struct txx9_board_vec *__init find_board_byname(const char *name)
101{
102 int i;
103
104 /* search board_vecs table */
105 for (i = 0; i < ARRAY_SIZE(board_vecs); i++) {
106 if (strstr(board_vecs[i]->system, name))
107 return board_vecs[i];
108 }
109 return NULL;
110}
111
Atsushi Nemotoe0dfb202008-08-19 22:55:06 +0900112static void __init prom_init_cmdline(void)
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900113{
Geert Uytterhoeven97b05112008-10-27 15:25:49 +0100114 int argc;
115 int *argv32;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900116 int i; /* Always ignore the "-c" at argv[0] */
117
Geert Uytterhoeven97b05112008-10-27 15:25:49 +0100118 if (fw_arg0 >= CKSEG0 || fw_arg1 < CKSEG0) {
119 /*
120 * argc is not a valid number, or argv32 is not a valid
121 * pointer
122 */
123 argc = 0;
124 argv32 = NULL;
125 } else {
126 argc = (int)fw_arg0;
127 argv32 = (int *)fw_arg1;
128 }
129
Atsushi Nemotoe0dfb202008-08-19 22:55:06 +0900130 arcs_cmdline[0] = '\0';
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900131
132 for (i = 1; i < argc; i++) {
Atsushi Nemotoe0dfb202008-08-19 22:55:06 +0900133 char *str = (char *)(long)argv32[i];
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900134 if (i != 1)
135 strcat(arcs_cmdline, " ");
Atsushi Nemotoe0dfb202008-08-19 22:55:06 +0900136 if (strchr(str, ' ')) {
137 strcat(arcs_cmdline, "\"");
138 strcat(arcs_cmdline, str);
139 strcat(arcs_cmdline, "\"");
140 } else
141 strcat(arcs_cmdline, str);
142 }
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900143}
144
Atsushi Nemotod10e0252008-08-19 22:55:09 +0900145static int txx9_ic_disable __initdata;
146static int txx9_dc_disable __initdata;
147
148#if defined(CONFIG_CPU_TX49XX)
149/* flush all cache on very early stage (before 4k_cache_init) */
150static void __init early_flush_dcache(void)
151{
152 unsigned int conf = read_c0_config();
153 unsigned int dc_size = 1 << (12 + ((conf & CONF_DC) >> 6));
154 unsigned int linesz = 32;
155 unsigned long addr, end;
156
157 end = INDEX_BASE + dc_size / 4;
158 /* 4way, waybit=0 */
159 for (addr = INDEX_BASE; addr < end; addr += linesz) {
160 cache_op(Index_Writeback_Inv_D, addr | 0);
161 cache_op(Index_Writeback_Inv_D, addr | 1);
162 cache_op(Index_Writeback_Inv_D, addr | 2);
163 cache_op(Index_Writeback_Inv_D, addr | 3);
164 }
165}
166
167static void __init txx9_cache_fixup(void)
168{
169 unsigned int conf;
170
171 conf = read_c0_config();
172 /* flush and disable */
173 if (txx9_ic_disable) {
174 conf |= TX49_CONF_IC;
175 write_c0_config(conf);
176 }
177 if (txx9_dc_disable) {
178 early_flush_dcache();
179 conf |= TX49_CONF_DC;
180 write_c0_config(conf);
181 }
182
183 /* enable cache */
184 conf = read_c0_config();
185 if (!txx9_ic_disable)
186 conf &= ~TX49_CONF_IC;
187 if (!txx9_dc_disable)
188 conf &= ~TX49_CONF_DC;
189 write_c0_config(conf);
190
191 if (conf & TX49_CONF_IC)
192 pr_info("TX49XX I-Cache disabled.\n");
193 if (conf & TX49_CONF_DC)
194 pr_info("TX49XX D-Cache disabled.\n");
195}
196#elif defined(CONFIG_CPU_TX39XX)
197/* flush all cache on very early stage (before tx39_cache_init) */
198static void __init early_flush_dcache(void)
199{
200 unsigned int conf = read_c0_config();
201 unsigned int dc_size = 1 << (10 + ((conf & TX39_CONF_DCS_MASK) >>
202 TX39_CONF_DCS_SHIFT));
203 unsigned int linesz = 16;
204 unsigned long addr, end;
205
206 end = INDEX_BASE + dc_size / 2;
207 /* 2way, waybit=0 */
208 for (addr = INDEX_BASE; addr < end; addr += linesz) {
209 cache_op(Index_Writeback_Inv_D, addr | 0);
210 cache_op(Index_Writeback_Inv_D, addr | 1);
211 }
212}
213
214static void __init txx9_cache_fixup(void)
215{
216 unsigned int conf;
217
218 conf = read_c0_config();
219 /* flush and disable */
220 if (txx9_ic_disable) {
221 conf &= ~TX39_CONF_ICE;
222 write_c0_config(conf);
223 }
224 if (txx9_dc_disable) {
225 early_flush_dcache();
226 conf &= ~TX39_CONF_DCE;
227 write_c0_config(conf);
228 }
229
230 /* enable cache */
231 conf = read_c0_config();
232 if (!txx9_ic_disable)
233 conf |= TX39_CONF_ICE;
234 if (!txx9_dc_disable)
235 conf |= TX39_CONF_DCE;
236 write_c0_config(conf);
237
238 if (!(conf & TX39_CONF_ICE))
239 pr_info("TX39XX I-Cache disabled.\n");
240 if (!(conf & TX39_CONF_DCE))
241 pr_info("TX39XX D-Cache disabled.\n");
242}
243#else
244static inline void txx9_cache_fixup(void)
245{
246}
247#endif
248
Atsushi Nemoto860e5462008-08-19 22:55:08 +0900249static void __init preprocess_cmdline(void)
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900250{
Dmitri Vorobiev7580c9c2009-10-13 23:43:24 +0300251 static char cmdline[COMMAND_LINE_SIZE] __initdata;
Atsushi Nemoto860e5462008-08-19 22:55:08 +0900252 char *s;
253
254 strcpy(cmdline, arcs_cmdline);
255 s = cmdline;
256 arcs_cmdline[0] = '\0';
257 while (s && *s) {
258 char *str = strsep(&s, " ");
259 if (strncmp(str, "board=", 6) == 0) {
260 txx9_board_vec = find_board_byname(str + 6);
261 continue;
262 } else if (strncmp(str, "masterclk=", 10) == 0) {
Daniel Walter8e9ecbc2014-06-03 16:22:08 +0100263 unsigned int val;
264 if (kstrtouint(str + 10, 10, &val) == 0)
Atsushi Nemoto860e5462008-08-19 22:55:08 +0900265 txx9_master_clock = val;
266 continue;
Atsushi Nemotod10e0252008-08-19 22:55:09 +0900267 } else if (strcmp(str, "icdisable") == 0) {
268 txx9_ic_disable = 1;
269 continue;
270 } else if (strcmp(str, "dcdisable") == 0) {
271 txx9_dc_disable = 1;
272 continue;
Atsushi Nemotoc7b95bc2008-08-19 22:55:10 +0900273 } else if (strcmp(str, "toeoff") == 0) {
274 txx9_ccfg_toeon = 0;
275 continue;
276 } else if (strcmp(str, "toeon") == 0) {
277 txx9_ccfg_toeon = 1;
278 continue;
Atsushi Nemoto860e5462008-08-19 22:55:08 +0900279 }
280 if (arcs_cmdline[0])
281 strcat(arcs_cmdline, " ");
282 strcat(arcs_cmdline, str);
283 }
Atsushi Nemotod10e0252008-08-19 22:55:09 +0900284
285 txx9_cache_fixup();
Atsushi Nemoto860e5462008-08-19 22:55:08 +0900286}
287
288static void __init select_board(void)
289{
290 const char *envstr;
291
292 /* first, determine by "board=" argument in preprocess_cmdline() */
293 if (txx9_board_vec)
294 return;
295 /* next, determine by "board" envvar */
296 envstr = prom_getenv("board");
297 if (envstr) {
298 txx9_board_vec = find_board_byname(envstr);
299 if (txx9_board_vec)
300 return;
301 }
302
303 /* select "default" board */
Markos Chandrasc8acd402013-08-14 09:57:16 +0100304#ifdef CONFIG_TOSHIBA_JMR3927
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900305 txx9_board_vec = &jmr3927_vec;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900306#endif
307#ifdef CONFIG_CPU_TX49XX
308 switch (TX4938_REV_PCODE()) {
Atsushi Nemoto8d795f22008-07-18 00:43:48 +0900309#ifdef CONFIG_TOSHIBA_RBTX4927
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900310 case 0x4927:
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900311 txx9_board_vec = &rbtx4927_vec;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900312 break;
313 case 0x4937:
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900314 txx9_board_vec = &rbtx4937_vec;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900315 break;
Atsushi Nemoto8d795f22008-07-18 00:43:48 +0900316#endif
317#ifdef CONFIG_TOSHIBA_RBTX4938
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900318 case 0x4938:
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900319 txx9_board_vec = &rbtx4938_vec;
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900320 break;
Atsushi Nemoto8d795f22008-07-18 00:43:48 +0900321#endif
Atsushi Nemotob27311e2008-09-01 22:22:40 +0900322#ifdef CONFIG_TOSHIBA_RBTX4939
323 case 0x4939:
324 txx9_board_vec = &rbtx4939_vec;
325 break;
326#endif
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900327 }
328#endif
Atsushi Nemoto860e5462008-08-19 22:55:08 +0900329}
330
331void __init prom_init(void)
332{
333 prom_init_cmdline();
334 preprocess_cmdline();
335 select_board();
Yoichi Yuasa7a1fdf12008-07-13 19:51:55 +0900336
337 strcpy(txx9_system_type, txx9_board_vec->system);
338
Atsushi Nemoto7b226092008-07-14 00:15:04 +0900339 txx9_board_vec->prom_init();
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900340}
341
342void __init prom_free_prom_memory(void)
343{
Atsushi Nemotob6263ff2008-09-01 22:22:41 +0900344 unsigned long saddr = PAGE_SIZE;
345 unsigned long eaddr = __pa_symbol(&_text);
346
347 if (saddr < eaddr)
348 free_init_pages("prom memory", saddr, eaddr);
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900349}
350
351const char *get_system_type(void)
352{
353 return txx9_system_type;
354}
355
Atsushi Nemoto265b89d2008-08-19 22:55:07 +0900356const char *__init prom_getenv(const char *name)
357{
Geert Uytterhoeven97b05112008-10-27 15:25:49 +0100358 const s32 *str;
Atsushi Nemoto265b89d2008-08-19 22:55:07 +0900359
Geert Uytterhoeven97b05112008-10-27 15:25:49 +0100360 if (fw_arg2 < CKSEG0)
Atsushi Nemoto265b89d2008-08-19 22:55:07 +0900361 return NULL;
Geert Uytterhoeven97b05112008-10-27 15:25:49 +0100362
363 str = (const s32 *)fw_arg2;
Atsushi Nemoto265b89d2008-08-19 22:55:07 +0900364 /* YAMON style ("name", "value" pairs) */
365 while (str[0] && str[1]) {
366 if (!strcmp((const char *)(unsigned long)str[0], name))
367 return (const char *)(unsigned long)str[1];
368 str += 2;
369 }
370 return NULL;
371}
372
Atsushi Nemotoa49297e2008-07-24 00:25:17 +0900373static void __noreturn txx9_machine_halt(void)
374{
375 local_irq_disable();
376 clear_c0_status(ST0_IM);
377 while (1) {
378 if (cpu_wait) {
379 (*cpu_wait)();
380 if (cpu_has_counter) {
381 /*
382 * Clear counter interrupt while it
383 * breaks WAIT instruction even if
384 * masked.
385 */
386 write_c0_compare(0);
387 }
388 }
389 }
390}
391
Atsushi Nemoto68314722008-07-24 00:25:18 +0900392/* Watchdog support */
393void __init txx9_wdt_init(unsigned long base)
394{
395 struct resource res = {
396 .start = base,
397 .end = base + 0x100 - 1,
398 .flags = IORESOURCE_MEM,
399 };
400 platform_device_register_simple("txx9wdt", -1, &res, 1);
401}
402
Atsushi Nemoto496a3b52008-08-19 22:55:15 +0900403void txx9_wdt_now(unsigned long base)
404{
405 struct txx9_tmr_reg __iomem *tmrptr =
406 ioremap(base, sizeof(struct txx9_tmr_reg));
407 /* disable watch dog timer */
408 __raw_writel(TXx9_TMWTMR_WDIS | TXx9_TMWTMR_TWC, &tmrptr->wtmr);
409 __raw_writel(0, &tmrptr->tcr);
410 /* kick watchdog */
411 __raw_writel(TXx9_TMWTMR_TWIE, &tmrptr->wtmr);
412 __raw_writel(1, &tmrptr->cpra); /* immediate */
413 __raw_writel(TXx9_TMTCR_TCE | TXx9_TMTCR_CCDE | TXx9_TMTCR_TMODE_WDOG,
414 &tmrptr->tcr);
415}
416
Atsushi Nemotoc49f91f2008-07-24 00:25:20 +0900417/* SPI support */
418void __init txx9_spi_init(int busid, unsigned long base, int irq)
419{
420 struct resource res[] = {
421 {
422 .start = base,
423 .end = base + 0x20 - 1,
424 .flags = IORESOURCE_MEM,
425 }, {
426 .start = irq,
427 .flags = IORESOURCE_IRQ,
428 },
429 };
430 platform_device_register_simple("spi_txx9", busid,
431 res, ARRAY_SIZE(res));
432}
433
434void __init txx9_ethaddr_init(unsigned int id, unsigned char *ethaddr)
435{
436 struct platform_device *pdev =
437 platform_device_alloc("tc35815-mac", id);
438 if (!pdev ||
439 platform_device_add_data(pdev, ethaddr, 6) ||
440 platform_device_add(pdev))
441 platform_device_put(pdev);
442}
443
Atsushi Nemoto7779a5e2008-07-25 23:08:06 +0900444void __init txx9_sio_init(unsigned long baseaddr, int irq,
445 unsigned int line, unsigned int sclk, int nocts)
446{
447#ifdef CONFIG_SERIAL_TXX9
448 struct uart_port req;
449
450 memset(&req, 0, sizeof(req));
451 req.line = line;
452 req.iotype = UPIO_MEM;
453 req.membase = ioremap(baseaddr, 0x24);
454 req.mapbase = baseaddr;
455 req.irq = irq;
456 if (!nocts)
457 req.flags |= UPF_BUGGY_UART /*HAVE_CTS_LINE*/;
458 if (sclk) {
459 req.flags |= UPF_MAGIC_MULTIPLIER /*USE_SCLK*/;
460 req.uartclk = sclk;
461 } else
462 req.uartclk = TXX9_IMCLK;
463 early_serial_txx9_setup(&req);
464#endif /* CONFIG_SERIAL_TXX9 */
465}
466
Atsushi Nemotoe3529532008-07-29 22:10:08 +0900467#ifdef CONFIG_EARLY_PRINTK
Aaro Koskinenf7be4e72013-02-11 20:51:49 +0000468static void null_prom_putchar(char c)
Atsushi Nemotoe3529532008-07-29 22:10:08 +0900469{
470}
Aaro Koskinenf7be4e72013-02-11 20:51:49 +0000471void (*txx9_prom_putchar)(char c) = null_prom_putchar;
Atsushi Nemotoe3529532008-07-29 22:10:08 +0900472
Aaro Koskinenf7be4e72013-02-11 20:51:49 +0000473void prom_putchar(char c)
Atsushi Nemotoe3529532008-07-29 22:10:08 +0900474{
475 txx9_prom_putchar(c);
476}
477
478static void __iomem *early_txx9_sio_port;
479
Aaro Koskinenf7be4e72013-02-11 20:51:49 +0000480static void early_txx9_sio_putchar(char c)
Atsushi Nemotoe3529532008-07-29 22:10:08 +0900481{
482#define TXX9_SICISR 0x0c
483#define TXX9_SITFIFO 0x1c
484#define TXX9_SICISR_TXALS 0x00000002
485 while (!(__raw_readl(early_txx9_sio_port + TXX9_SICISR) &
486 TXX9_SICISR_TXALS))
487 ;
488 __raw_writel(c, early_txx9_sio_port + TXX9_SITFIFO);
489}
490
491void __init txx9_sio_putchar_init(unsigned long baseaddr)
492{
493 early_txx9_sio_port = ioremap(baseaddr, 0x24);
494 txx9_prom_putchar = early_txx9_sio_putchar;
495}
496#endif /* CONFIG_EARLY_PRINTK */
497
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900498/* wrappers */
499void __init plat_mem_setup(void)
500{
Atsushi Nemoto94a4c322008-07-19 01:51:47 +0900501 ioport_resource.start = 0;
502 ioport_resource.end = ~0UL; /* no limit */
503 iomem_resource.start = 0;
504 iomem_resource.end = ~0UL; /* no limit */
Atsushi Nemotoa49297e2008-07-24 00:25:17 +0900505
506 /* fallback restart/halt routines */
507 _machine_restart = (void (*)(char *))txx9_machine_halt;
508 _machine_halt = txx9_machine_halt;
509 pm_power_off = txx9_machine_halt;
510
Atsushi Nemoto07517522008-07-24 00:25:15 +0900511#ifdef CONFIG_PCI
512 pcibios_plat_setup = txx9_pcibios_setup;
513#endif
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900514 txx9_board_vec->mem_setup();
515}
516
517void __init arch_init_irq(void)
518{
519 txx9_board_vec->irq_setup();
520}
521
522void __init plat_time_init(void)
523{
Atsushi Nemoto1374d082008-07-31 22:29:53 +0900524#ifdef CONFIG_CPU_TX49XX
525 mips_hpt_frequency = txx9_cpu_clock / 2;
526#endif
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900527 txx9_board_vec->time_init();
528}
529
Geert Uytterhoeven44ce9a92016-09-11 10:59:58 +0200530static void txx9_clk_init(void)
531{
532 struct clk_hw *hw;
533 int error;
534
535 hw = clk_hw_register_fixed_rate(NULL, "gbus", NULL, 0, txx9_gbus_clock);
536 if (IS_ERR(hw)) {
537 error = PTR_ERR(hw);
538 goto fail;
539 }
540
541 hw = clk_hw_register_fixed_factor(NULL, "imbus", "gbus", 0, 1, 2);
542 error = clk_hw_register_clkdev(hw, "imbus_clk", NULL);
543 if (error)
544 goto fail;
545
546#ifdef CONFIG_CPU_TX49XX
547 if (TX4938_REV_PCODE() == 0x4938) {
548 hw = clk_hw_register_fixed_factor(NULL, "spi", "gbus", 0, 1, 4);
549 error = clk_hw_register_clkdev(hw, "spi-baseclk", NULL);
550 if (error)
551 goto fail;
552 }
553#endif
554
555 return;
556
557fail:
558 pr_err("Failed to register clocks: %d\n", error);
559}
560
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900561static int __init _txx9_arch_init(void)
562{
Geert Uytterhoeven44ce9a92016-09-11 10:59:58 +0200563 txx9_clk_init();
564
Atsushi Nemotoedcaf1a2008-07-11 23:27:54 +0900565 if (txx9_board_vec->arch_init)
566 txx9_board_vec->arch_init();
567 return 0;
568}
569arch_initcall(_txx9_arch_init);
570
571static int __init _txx9_device_init(void)
572{
573 if (txx9_board_vec->device_init)
574 txx9_board_vec->device_init();
575 return 0;
576}
577device_initcall(_txx9_device_init);
578
579int (*txx9_irq_dispatch)(int pending);
580asmlinkage void plat_irq_dispatch(void)
581{
582 int pending = read_c0_status() & read_c0_cause() & ST0_IM;
583 int irq = txx9_irq_dispatch(pending);
584
585 if (likely(irq >= 0))
586 do_IRQ(irq);
587 else
588 spurious_interrupt();
589}
Atsushi Nemoto4c642f32008-07-13 23:37:56 +0900590
591/* see include/asm-mips/mach-tx39xx/mangle-port.h, for example. */
592#ifdef NEEDS_TXX9_SWIZZLE_ADDR_B
593static unsigned long __swizzle_addr_none(unsigned long port)
594{
595 return port;
596}
597unsigned long (*__swizzle_addr_b)(unsigned long port) = __swizzle_addr_none;
598EXPORT_SYMBOL(__swizzle_addr_b);
599#endif
Atsushi Nemoto51f607c2008-08-19 22:55:11 +0900600
Atsushi Nemoto1ba5a172008-10-21 00:01:06 +0900601#ifdef NEEDS_TXX9_IOSWABW
602static u16 ioswabw_default(volatile u16 *a, u16 x)
603{
604 return le16_to_cpu(x);
605}
606static u16 __mem_ioswabw_default(volatile u16 *a, u16 x)
607{
608 return x;
609}
610u16 (*ioswabw)(volatile u16 *a, u16 x) = ioswabw_default;
611EXPORT_SYMBOL(ioswabw);
612u16 (*__mem_ioswabw)(volatile u16 *a, u16 x) = __mem_ioswabw_default;
613EXPORT_SYMBOL(__mem_ioswabw);
614#endif
615
Atsushi Nemoto51f607c2008-08-19 22:55:11 +0900616void __init txx9_physmap_flash_init(int no, unsigned long addr,
617 unsigned long size,
618 const struct physmap_flash_data *pdata)
619{
Florian Fainellib33b4402012-01-31 18:19:05 +0100620#if IS_ENABLED(CONFIG_MTD_PHYSMAP)
Atsushi Nemoto51f607c2008-08-19 22:55:11 +0900621 struct resource res = {
622 .start = addr,
623 .end = addr + size - 1,
624 .flags = IORESOURCE_MEM,
625 };
626 struct platform_device *pdev;
Atsushi Nemoto51f607c2008-08-19 22:55:11 +0900627 static struct mtd_partition parts[2];
628 struct physmap_flash_data pdata_part;
629
630 /* If this area contained boot area, make separate partition */
631 if (pdata->nr_parts == 0 && !pdata->parts &&
632 addr < 0x1fc00000 && addr + size > 0x1fc00000 &&
633 !parts[0].name) {
634 parts[0].name = "boot";
635 parts[0].offset = 0x1fc00000 - addr;
636 parts[0].size = addr + size - 0x1fc00000;
637 parts[1].name = "user";
638 parts[1].offset = 0;
639 parts[1].size = 0x1fc00000 - addr;
640 pdata_part = *pdata;
641 pdata_part.nr_parts = ARRAY_SIZE(parts);
642 pdata_part.parts = parts;
643 pdata = &pdata_part;
644 }
Jamie Iles47854882011-05-23 10:22:55 +0100645
Atsushi Nemoto51f607c2008-08-19 22:55:11 +0900646 pdev = platform_device_alloc("physmap-flash", no);
647 if (!pdev ||
648 platform_device_add_resources(pdev, &res, 1) ||
649 platform_device_add_data(pdev, pdata, sizeof(*pdata)) ||
650 platform_device_add(pdev))
651 platform_device_put(pdev);
652#endif
653}
Atsushi Nemotoae027ea2008-09-01 22:22:38 +0900654
Atsushi Nemotoa591f5d2009-03-04 12:01:31 -0800655void __init txx9_ndfmc_init(unsigned long baseaddr,
656 const struct txx9ndfmc_platform_data *pdata)
657{
Florian Fainellib33b4402012-01-31 18:19:05 +0100658#if IS_ENABLED(CONFIG_MTD_NAND_TXX9NDFMC)
Atsushi Nemotoa591f5d2009-03-04 12:01:31 -0800659 struct resource res = {
660 .start = baseaddr,
661 .end = baseaddr + 0x1000 - 1,
662 .flags = IORESOURCE_MEM,
663 };
664 struct platform_device *pdev = platform_device_alloc("txx9ndfmc", -1);
665
666 if (!pdev ||
667 platform_device_add_resources(pdev, &res, 1) ||
668 platform_device_add_data(pdev, pdata, sizeof(*pdata)) ||
669 platform_device_add(pdev))
670 platform_device_put(pdev);
671#endif
672}
673
Florian Fainellib33b4402012-01-31 18:19:05 +0100674#if IS_ENABLED(CONFIG_LEDS_GPIO)
Atsushi Nemotoae027ea2008-09-01 22:22:38 +0900675static DEFINE_SPINLOCK(txx9_iocled_lock);
676
677#define TXX9_IOCLED_MAXLEDS 8
678
679struct txx9_iocled_data {
680 struct gpio_chip chip;
681 u8 cur_val;
682 void __iomem *mmioaddr;
683 struct gpio_led_platform_data pdata;
684 struct gpio_led leds[TXX9_IOCLED_MAXLEDS];
685 char names[TXX9_IOCLED_MAXLEDS][32];
686};
687
688static int txx9_iocled_get(struct gpio_chip *chip, unsigned int offset)
689{
Linus Walleijbe7658f2015-12-08 14:40:40 +0100690 struct txx9_iocled_data *data = gpiochip_get_data(chip);
Linus Walleij8cbe4b52015-12-22 15:41:44 +0100691 return !!(data->cur_val & (1 << offset));
Atsushi Nemotoae027ea2008-09-01 22:22:38 +0900692}
693
694static void txx9_iocled_set(struct gpio_chip *chip, unsigned int offset,
695 int value)
696{
Linus Walleijbe7658f2015-12-08 14:40:40 +0100697 struct txx9_iocled_data *data = gpiochip_get_data(chip);
Atsushi Nemotoae027ea2008-09-01 22:22:38 +0900698 unsigned long flags;
699 spin_lock_irqsave(&txx9_iocled_lock, flags);
700 if (value)
701 data->cur_val |= 1 << offset;
702 else
703 data->cur_val &= ~(1 << offset);
704 writeb(data->cur_val, data->mmioaddr);
705 mmiowb();
706 spin_unlock_irqrestore(&txx9_iocled_lock, flags);
707}
708
709static int txx9_iocled_dir_in(struct gpio_chip *chip, unsigned int offset)
710{
711 return 0;
712}
713
714static int txx9_iocled_dir_out(struct gpio_chip *chip, unsigned int offset,
715 int value)
716{
717 txx9_iocled_set(chip, offset, value);
718 return 0;
719}
720
721void __init txx9_iocled_init(unsigned long baseaddr,
722 int basenum, unsigned int num, int lowactive,
723 const char *color, char **deftriggers)
724{
725 struct txx9_iocled_data *iocled;
726 struct platform_device *pdev;
727 int i;
728 static char *default_triggers[] __initdata = {
729 "heartbeat",
Stephan Linzdde00512016-06-10 08:00:00 +0200730 "disk-activity",
Atsushi Nemotoae027ea2008-09-01 22:22:38 +0900731 "nand-disk",
732 NULL,
733 };
734
735 if (!deftriggers)
736 deftriggers = default_triggers;
737 iocled = kzalloc(sizeof(*iocled), GFP_KERNEL);
738 if (!iocled)
739 return;
740 iocled->mmioaddr = ioremap(baseaddr, 1);
741 if (!iocled->mmioaddr)
Julia Lawall70ebadc2009-09-13 21:15:18 +0200742 goto out_free;
Atsushi Nemotoae027ea2008-09-01 22:22:38 +0900743 iocled->chip.get = txx9_iocled_get;
744 iocled->chip.set = txx9_iocled_set;
745 iocled->chip.direction_input = txx9_iocled_dir_in;
746 iocled->chip.direction_output = txx9_iocled_dir_out;
747 iocled->chip.label = "iocled";
748 iocled->chip.base = basenum;
749 iocled->chip.ngpio = num;
Linus Walleijbe7658f2015-12-08 14:40:40 +0100750 if (gpiochip_add_data(&iocled->chip, iocled))
Julia Lawall70ebadc2009-09-13 21:15:18 +0200751 goto out_unmap;
Atsushi Nemotoae027ea2008-09-01 22:22:38 +0900752 if (basenum < 0)
753 basenum = iocled->chip.base;
754
755 pdev = platform_device_alloc("leds-gpio", basenum);
756 if (!pdev)
Julia Lawall70ebadc2009-09-13 21:15:18 +0200757 goto out_gpio;
Atsushi Nemotoae027ea2008-09-01 22:22:38 +0900758 iocled->pdata.num_leds = num;
759 iocled->pdata.leds = iocled->leds;
760 for (i = 0; i < num; i++) {
761 struct gpio_led *led = &iocled->leds[i];
762 snprintf(iocled->names[i], sizeof(iocled->names[i]),
763 "iocled:%s:%u", color, i);
764 led->name = iocled->names[i];
765 led->gpio = basenum + i;
766 led->active_low = lowactive;
767 if (deftriggers && *deftriggers)
768 led->default_trigger = *deftriggers++;
769 }
770 pdev->dev.platform_data = &iocled->pdata;
771 if (platform_device_add(pdev))
Julia Lawall70ebadc2009-09-13 21:15:18 +0200772 goto out_pdev;
773 return;
abdoulaye berthe88d5e522014-07-12 22:30:14 +0200774
Julia Lawall70ebadc2009-09-13 21:15:18 +0200775out_pdev:
776 platform_device_put(pdev);
777out_gpio:
abdoulaye berthe88d5e522014-07-12 22:30:14 +0200778 gpiochip_remove(&iocled->chip);
Julia Lawall70ebadc2009-09-13 21:15:18 +0200779out_unmap:
780 iounmap(iocled->mmioaddr);
781out_free:
782 kfree(iocled);
Atsushi Nemotoae027ea2008-09-01 22:22:38 +0900783}
784#else /* CONFIG_LEDS_GPIO */
785void __init txx9_iocled_init(unsigned long baseaddr,
786 int basenum, unsigned int num, int lowactive,
787 const char *color, char **deftriggers)
788{
789}
790#endif /* CONFIG_LEDS_GPIO */
Atsushi Nemotof48c8c92009-04-23 00:40:31 +0900791
792void __init txx9_dmac_init(int id, unsigned long baseaddr, int irq,
793 const struct txx9dmac_platform_data *pdata)
794{
Florian Fainellib33b4402012-01-31 18:19:05 +0100795#if IS_ENABLED(CONFIG_TXX9_DMAC)
Atsushi Nemotof48c8c92009-04-23 00:40:31 +0900796 struct resource res[] = {
797 {
798 .start = baseaddr,
799 .end = baseaddr + 0x800 - 1,
800 .flags = IORESOURCE_MEM,
801#ifndef CONFIG_MACH_TX49XX
802 }, {
803 .start = irq,
804 .flags = IORESOURCE_IRQ,
805#endif
806 }
807 };
808#ifdef CONFIG_MACH_TX49XX
809 struct resource chan_res[] = {
810 {
811 .flags = IORESOURCE_IRQ,
812 }
813 };
814#endif
815 struct platform_device *pdev = platform_device_alloc("txx9dmac", id);
816 struct txx9dmac_chan_platform_data cpdata;
817 int i;
818
819 if (!pdev ||
820 platform_device_add_resources(pdev, res, ARRAY_SIZE(res)) ||
821 platform_device_add_data(pdev, pdata, sizeof(*pdata)) ||
822 platform_device_add(pdev)) {
823 platform_device_put(pdev);
824 return;
825 }
826 memset(&cpdata, 0, sizeof(cpdata));
827 cpdata.dmac_dev = pdev;
828 for (i = 0; i < TXX9_DMA_MAX_NR_CHANNELS; i++) {
829#ifdef CONFIG_MACH_TX49XX
830 chan_res[0].start = irq + i;
831#endif
832 pdev = platform_device_alloc("txx9dmac-chan",
833 id * TXX9_DMA_MAX_NR_CHANNELS + i);
834 if (!pdev ||
835#ifdef CONFIG_MACH_TX49XX
836 platform_device_add_resources(pdev, chan_res,
837 ARRAY_SIZE(chan_res)) ||
838#endif
839 platform_device_add_data(pdev, &cpdata, sizeof(cpdata)) ||
840 platform_device_add(pdev))
841 platform_device_put(pdev);
842 }
843#endif
844}
Atsushi Nemoto742cd582009-05-19 22:12:22 +0900845
846void __init txx9_aclc_init(unsigned long baseaddr, int irq,
847 unsigned int dmac_id,
848 unsigned int dma_chan_out,
849 unsigned int dma_chan_in)
850{
Florian Fainellib33b4402012-01-31 18:19:05 +0100851#if IS_ENABLED(CONFIG_SND_SOC_TXX9ACLC)
Atsushi Nemoto742cd582009-05-19 22:12:22 +0900852 unsigned int dma_base = dmac_id * TXX9_DMA_MAX_NR_CHANNELS;
853 struct resource res[] = {
854 {
855 .start = baseaddr,
856 .end = baseaddr + 0x100 - 1,
857 .flags = IORESOURCE_MEM,
858 }, {
859 .start = irq,
860 .flags = IORESOURCE_IRQ,
861 }, {
862 .name = "txx9dmac-chan",
863 .start = dma_base + dma_chan_out,
864 .flags = IORESOURCE_DMA,
865 }, {
866 .name = "txx9dmac-chan",
867 .start = dma_base + dma_chan_in,
868 .flags = IORESOURCE_DMA,
869 }
870 };
871 struct platform_device *pdev =
872 platform_device_alloc("txx9aclc-ac97", -1);
873
874 if (!pdev ||
875 platform_device_add_resources(pdev, res, ARRAY_SIZE(res)) ||
876 platform_device_add(pdev))
877 platform_device_put(pdev);
878#endif
879}
Atsushi Nemotoc3b28ae2009-05-25 22:04:02 +0900880
Kay Sievers269a3eb2011-12-21 15:09:54 -0800881static struct bus_type txx9_sramc_subsys = {
882 .name = "txx9_sram",
883 .dev_name = "txx9_sram",
884};
Atsushi Nemotoc3b28ae2009-05-25 22:04:02 +0900885
Kay Sievers269a3eb2011-12-21 15:09:54 -0800886struct txx9_sramc_dev {
887 struct device dev;
Atsushi Nemotoc3b28ae2009-05-25 22:04:02 +0900888 struct bin_attribute bindata_attr;
889 void __iomem *base;
890};
891
Chris Wright2c3c8be2010-05-12 18:28:57 -0700892static ssize_t txx9_sram_read(struct file *filp, struct kobject *kobj,
Atsushi Nemotoc3b28ae2009-05-25 22:04:02 +0900893 struct bin_attribute *bin_attr,
894 char *buf, loff_t pos, size_t size)
895{
Kay Sievers269a3eb2011-12-21 15:09:54 -0800896 struct txx9_sramc_dev *dev = bin_attr->private;
Atsushi Nemotoc3b28ae2009-05-25 22:04:02 +0900897 size_t ramsize = bin_attr->size;
898
899 if (pos >= ramsize)
900 return 0;
901 if (pos + size > ramsize)
902 size = ramsize - pos;
903 memcpy_fromio(buf, dev->base + pos, size);
904 return size;
905}
906
Chris Wright2c3c8be2010-05-12 18:28:57 -0700907static ssize_t txx9_sram_write(struct file *filp, struct kobject *kobj,
Atsushi Nemotoc3b28ae2009-05-25 22:04:02 +0900908 struct bin_attribute *bin_attr,
909 char *buf, loff_t pos, size_t size)
910{
Kay Sievers269a3eb2011-12-21 15:09:54 -0800911 struct txx9_sramc_dev *dev = bin_attr->private;
Atsushi Nemotoc3b28ae2009-05-25 22:04:02 +0900912 size_t ramsize = bin_attr->size;
913
914 if (pos >= ramsize)
915 return 0;
916 if (pos + size > ramsize)
917 size = ramsize - pos;
918 memcpy_toio(dev->base + pos, buf, size);
919 return size;
920}
921
Levente Kurusa1610c8a2013-12-19 16:03:25 +0100922static void txx9_device_release(struct device *dev)
923{
924 struct txx9_sramc_dev *tdev;
925
926 tdev = container_of(dev, struct txx9_sramc_dev, dev);
927 kfree(tdev);
928}
929
Atsushi Nemotoc3b28ae2009-05-25 22:04:02 +0900930void __init txx9_sramc_init(struct resource *r)
931{
Kay Sievers269a3eb2011-12-21 15:09:54 -0800932 struct txx9_sramc_dev *dev;
Atsushi Nemotoc3b28ae2009-05-25 22:04:02 +0900933 size_t size;
934 int err;
935
Kay Sievers269a3eb2011-12-21 15:09:54 -0800936 err = subsys_system_register(&txx9_sramc_subsys, NULL);
937 if (err)
938 return;
Atsushi Nemotoc3b28ae2009-05-25 22:04:02 +0900939 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
940 if (!dev)
941 return;
942 size = resource_size(r);
943 dev->base = ioremap(r->start, size);
Levente Kurusa1610c8a2013-12-19 16:03:25 +0100944 if (!dev->base) {
945 kfree(dev);
946 return;
947 }
948 dev->dev.release = &txx9_device_release;
Kay Sievers269a3eb2011-12-21 15:09:54 -0800949 dev->dev.bus = &txx9_sramc_subsys;
Wolfram Sangf9373312010-03-15 01:29:41 +0100950 sysfs_bin_attr_init(&dev->bindata_attr);
Atsushi Nemotoc3b28ae2009-05-25 22:04:02 +0900951 dev->bindata_attr.attr.name = "bindata";
952 dev->bindata_attr.attr.mode = S_IRUSR | S_IWUSR;
953 dev->bindata_attr.read = txx9_sram_read;
954 dev->bindata_attr.write = txx9_sram_write;
955 dev->bindata_attr.size = size;
956 dev->bindata_attr.private = dev;
Kay Sievers269a3eb2011-12-21 15:09:54 -0800957 err = device_register(&dev->dev);
Atsushi Nemotoc3b28ae2009-05-25 22:04:02 +0900958 if (err)
Levente Kurusa1610c8a2013-12-19 16:03:25 +0100959 goto exit_put;
Atsushi Nemotoc3b28ae2009-05-25 22:04:02 +0900960 err = sysfs_create_bin_file(&dev->dev.kobj, &dev->bindata_attr);
961 if (err) {
Kay Sievers269a3eb2011-12-21 15:09:54 -0800962 device_unregister(&dev->dev);
Levente Kurusa1610c8a2013-12-19 16:03:25 +0100963 iounmap(dev->base);
Atsushi Nemotoc3b28ae2009-05-25 22:04:02 +0900964 kfree(dev);
965 }
Levente Kurusa1610c8a2013-12-19 16:03:25 +0100966 return;
967exit_put:
968 put_device(&dev->dev);
969 return;
Atsushi Nemotoc3b28ae2009-05-25 22:04:02 +0900970}