aboutsummaryrefslogtreecommitdiffstats
path: root/arch/mips/txx9/generic/setup.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/mips/txx9/generic/setup.c')
-rw-r--r--arch/mips/txx9/generic/setup.c431
1 files changed, 415 insertions, 16 deletions
diff --git a/arch/mips/txx9/generic/setup.c b/arch/mips/txx9/generic/setup.c
index fe6bee09cece..5526375010f8 100644
--- a/arch/mips/txx9/generic/setup.c
+++ b/arch/mips/txx9/generic/setup.c
@@ -22,11 +22,16 @@
22#include <linux/gpio.h> 22#include <linux/gpio.h>
23#include <linux/platform_device.h> 23#include <linux/platform_device.h>
24#include <linux/serial_core.h> 24#include <linux/serial_core.h>
25#include <linux/mtd/physmap.h>
26#include <linux/leds.h>
25#include <asm/bootinfo.h> 27#include <asm/bootinfo.h>
26#include <asm/time.h> 28#include <asm/time.h>
27#include <asm/reboot.h> 29#include <asm/reboot.h>
30#include <asm/r4kcache.h>
31#include <asm/sections.h>
28#include <asm/txx9/generic.h> 32#include <asm/txx9/generic.h>
29#include <asm/txx9/pci.h> 33#include <asm/txx9/pci.h>
34#include <asm/txx9tmr.h>
30#ifdef CONFIG_CPU_TX49XX 35#ifdef CONFIG_CPU_TX49XX
31#include <asm/txx9/tx4938.h> 36#include <asm/txx9/tx4938.h>
32#endif 37#endif
@@ -67,7 +72,12 @@ unsigned int txx9_master_clock;
67unsigned int txx9_cpu_clock; 72unsigned int txx9_cpu_clock;
68unsigned int txx9_gbus_clock; 73unsigned int txx9_gbus_clock;
69 74
75#ifdef CONFIG_CPU_TX39XX
76/* don't enable by default - see errata */
77int txx9_ccfg_toeon __initdata;
78#else
70int txx9_ccfg_toeon __initdata = 1; 79int txx9_ccfg_toeon __initdata = 1;
80#endif
71 81
72/* Minimum CLK support */ 82/* Minimum CLK support */
73 83
@@ -119,39 +129,232 @@ int irq_to_gpio(unsigned irq)
119EXPORT_SYMBOL(irq_to_gpio); 129EXPORT_SYMBOL(irq_to_gpio);
120#endif 130#endif
121 131
122extern struct txx9_board_vec jmr3927_vec; 132#define BOARD_VEC(board) extern struct txx9_board_vec board;
123extern struct txx9_board_vec rbtx4927_vec; 133#include <asm/txx9/boards.h>
124extern struct txx9_board_vec rbtx4937_vec; 134#undef BOARD_VEC
125extern struct txx9_board_vec rbtx4938_vec;
126 135
127struct txx9_board_vec *txx9_board_vec __initdata; 136struct txx9_board_vec *txx9_board_vec __initdata;
128static char txx9_system_type[32]; 137static char txx9_system_type[32];
129 138
130void __init prom_init_cmdline(void) 139static struct txx9_board_vec *board_vecs[] __initdata = {
140#define BOARD_VEC(board) &board,
141#include <asm/txx9/boards.h>
142#undef BOARD_VEC
143};
144
145static struct txx9_board_vec *__init find_board_byname(const char *name)
146{
147 int i;
148
149 /* search board_vecs table */
150 for (i = 0; i < ARRAY_SIZE(board_vecs); i++) {
151 if (strstr(board_vecs[i]->system, name))
152 return board_vecs[i];
153 }
154 return NULL;
155}
156
157static void __init prom_init_cmdline(void)
131{ 158{
132 int argc = (int)fw_arg0; 159 int argc = (int)fw_arg0;
133 char **argv = (char **)fw_arg1; 160 int *argv32 = (int *)fw_arg1;
134 int i; /* Always ignore the "-c" at argv[0] */ 161 int i; /* Always ignore the "-c" at argv[0] */
135#ifdef CONFIG_64BIT 162 char builtin[CL_SIZE];
136 char *fixed_argv[32];
137 for (i = 0; i < argc; i++)
138 fixed_argv[i] = (char *)(long)(*((__s32 *)argv + i));
139 argv = fixed_argv;
140#endif
141 163
142 /* ignore all built-in args if any f/w args given */ 164 /* ignore all built-in args if any f/w args given */
143 if (argc > 1) 165 /*
144 *arcs_cmdline = '\0'; 166 * But if built-in strings was started with '+', append them
167 * to command line args. If built-in was started with '-',
168 * ignore all f/w args.
169 */
170 builtin[0] = '\0';
171 if (arcs_cmdline[0] == '+')
172 strcpy(builtin, arcs_cmdline + 1);
173 else if (arcs_cmdline[0] == '-') {
174 strcpy(builtin, arcs_cmdline + 1);
175 argc = 0;
176 } else if (argc <= 1)
177 strcpy(builtin, arcs_cmdline);
178 arcs_cmdline[0] = '\0';
145 179
146 for (i = 1; i < argc; i++) { 180 for (i = 1; i < argc; i++) {
181 char *str = (char *)(long)argv32[i];
147 if (i != 1) 182 if (i != 1)
148 strcat(arcs_cmdline, " "); 183 strcat(arcs_cmdline, " ");
149 strcat(arcs_cmdline, argv[i]); 184 if (strchr(str, ' ')) {
185 strcat(arcs_cmdline, "\"");
186 strcat(arcs_cmdline, str);
187 strcat(arcs_cmdline, "\"");
188 } else
189 strcat(arcs_cmdline, str);
190 }
191 /* append saved builtin args */
192 if (builtin[0]) {
193 if (arcs_cmdline[0])
194 strcat(arcs_cmdline, " ");
195 strcat(arcs_cmdline, builtin);
150 } 196 }
151} 197}
152 198
153void __init prom_init(void) 199static int txx9_ic_disable __initdata;
200static int txx9_dc_disable __initdata;
201
202#if defined(CONFIG_CPU_TX49XX)
203/* flush all cache on very early stage (before 4k_cache_init) */
204static void __init early_flush_dcache(void)
154{ 205{
206 unsigned int conf = read_c0_config();
207 unsigned int dc_size = 1 << (12 + ((conf & CONF_DC) >> 6));
208 unsigned int linesz = 32;
209 unsigned long addr, end;
210
211 end = INDEX_BASE + dc_size / 4;
212 /* 4way, waybit=0 */
213 for (addr = INDEX_BASE; addr < end; addr += linesz) {
214 cache_op(Index_Writeback_Inv_D, addr | 0);
215 cache_op(Index_Writeback_Inv_D, addr | 1);
216 cache_op(Index_Writeback_Inv_D, addr | 2);
217 cache_op(Index_Writeback_Inv_D, addr | 3);
218 }
219}
220
221static void __init txx9_cache_fixup(void)
222{
223 unsigned int conf;
224
225 conf = read_c0_config();
226 /* flush and disable */
227 if (txx9_ic_disable) {
228 conf |= TX49_CONF_IC;
229 write_c0_config(conf);
230 }
231 if (txx9_dc_disable) {
232 early_flush_dcache();
233 conf |= TX49_CONF_DC;
234 write_c0_config(conf);
235 }
236
237 /* enable cache */
238 conf = read_c0_config();
239 if (!txx9_ic_disable)
240 conf &= ~TX49_CONF_IC;
241 if (!txx9_dc_disable)
242 conf &= ~TX49_CONF_DC;
243 write_c0_config(conf);
244
245 if (conf & TX49_CONF_IC)
246 pr_info("TX49XX I-Cache disabled.\n");
247 if (conf & TX49_CONF_DC)
248 pr_info("TX49XX D-Cache disabled.\n");
249}
250#elif defined(CONFIG_CPU_TX39XX)
251/* flush all cache on very early stage (before tx39_cache_init) */
252static void __init early_flush_dcache(void)
253{
254 unsigned int conf = read_c0_config();
255 unsigned int dc_size = 1 << (10 + ((conf & TX39_CONF_DCS_MASK) >>
256 TX39_CONF_DCS_SHIFT));
257 unsigned int linesz = 16;
258 unsigned long addr, end;
259
260 end = INDEX_BASE + dc_size / 2;
261 /* 2way, waybit=0 */
262 for (addr = INDEX_BASE; addr < end; addr += linesz) {
263 cache_op(Index_Writeback_Inv_D, addr | 0);
264 cache_op(Index_Writeback_Inv_D, addr | 1);
265 }
266}
267
268static void __init txx9_cache_fixup(void)
269{
270 unsigned int conf;
271
272 conf = read_c0_config();
273 /* flush and disable */
274 if (txx9_ic_disable) {
275 conf &= ~TX39_CONF_ICE;
276 write_c0_config(conf);
277 }
278 if (txx9_dc_disable) {
279 early_flush_dcache();
280 conf &= ~TX39_CONF_DCE;
281 write_c0_config(conf);
282 }
283
284 /* enable cache */
285 conf = read_c0_config();
286 if (!txx9_ic_disable)
287 conf |= TX39_CONF_ICE;
288 if (!txx9_dc_disable)
289 conf |= TX39_CONF_DCE;
290 write_c0_config(conf);
291
292 if (!(conf & TX39_CONF_ICE))
293 pr_info("TX39XX I-Cache disabled.\n");
294 if (!(conf & TX39_CONF_DCE))
295 pr_info("TX39XX D-Cache disabled.\n");
296}
297#else
298static inline void txx9_cache_fixup(void)
299{
300}
301#endif
302
303static void __init preprocess_cmdline(void)
304{
305 char cmdline[CL_SIZE];
306 char *s;
307
308 strcpy(cmdline, arcs_cmdline);
309 s = cmdline;
310 arcs_cmdline[0] = '\0';
311 while (s && *s) {
312 char *str = strsep(&s, " ");
313 if (strncmp(str, "board=", 6) == 0) {
314 txx9_board_vec = find_board_byname(str + 6);
315 continue;
316 } else if (strncmp(str, "masterclk=", 10) == 0) {
317 unsigned long val;
318 if (strict_strtoul(str + 10, 10, &val) == 0)
319 txx9_master_clock = val;
320 continue;
321 } else if (strcmp(str, "icdisable") == 0) {
322 txx9_ic_disable = 1;
323 continue;
324 } else if (strcmp(str, "dcdisable") == 0) {
325 txx9_dc_disable = 1;
326 continue;
327 } else if (strcmp(str, "toeoff") == 0) {
328 txx9_ccfg_toeon = 0;
329 continue;
330 } else if (strcmp(str, "toeon") == 0) {
331 txx9_ccfg_toeon = 1;
332 continue;
333 }
334 if (arcs_cmdline[0])
335 strcat(arcs_cmdline, " ");
336 strcat(arcs_cmdline, str);
337 }
338
339 txx9_cache_fixup();
340}
341
342static void __init select_board(void)
343{
344 const char *envstr;
345
346 /* first, determine by "board=" argument in preprocess_cmdline() */
347 if (txx9_board_vec)
348 return;
349 /* next, determine by "board" envvar */
350 envstr = prom_getenv("board");
351 if (envstr) {
352 txx9_board_vec = find_board_byname(envstr);
353 if (txx9_board_vec)
354 return;
355 }
356
357 /* select "default" board */
155#ifdef CONFIG_CPU_TX39XX 358#ifdef CONFIG_CPU_TX39XX
156 txx9_board_vec = &jmr3927_vec; 359 txx9_board_vec = &jmr3927_vec;
157#endif 360#endif
@@ -170,8 +373,20 @@ void __init prom_init(void)
170 txx9_board_vec = &rbtx4938_vec; 373 txx9_board_vec = &rbtx4938_vec;
171 break; 374 break;
172#endif 375#endif
376#ifdef CONFIG_TOSHIBA_RBTX4939
377 case 0x4939:
378 txx9_board_vec = &rbtx4939_vec;
379 break;
380#endif
173 } 381 }
174#endif 382#endif
383}
384
385void __init prom_init(void)
386{
387 prom_init_cmdline();
388 preprocess_cmdline();
389 select_board();
175 390
176 strcpy(txx9_system_type, txx9_board_vec->system); 391 strcpy(txx9_system_type, txx9_board_vec->system);
177 392
@@ -180,6 +395,11 @@ void __init prom_init(void)
180 395
181void __init prom_free_prom_memory(void) 396void __init prom_free_prom_memory(void)
182{ 397{
398 unsigned long saddr = PAGE_SIZE;
399 unsigned long eaddr = __pa_symbol(&_text);
400
401 if (saddr < eaddr)
402 free_init_pages("prom memory", saddr, eaddr);
183} 403}
184 404
185const char *get_system_type(void) 405const char *get_system_type(void)
@@ -192,6 +412,21 @@ char * __init prom_getcmdline(void)
192 return &(arcs_cmdline[0]); 412 return &(arcs_cmdline[0]);
193} 413}
194 414
415const char *__init prom_getenv(const char *name)
416{
417 const s32 *str = (const s32 *)fw_arg2;
418
419 if (!str)
420 return NULL;
421 /* YAMON style ("name", "value" pairs) */
422 while (str[0] && str[1]) {
423 if (!strcmp((const char *)(unsigned long)str[0], name))
424 return (const char *)(unsigned long)str[1];
425 str += 2;
426 }
427 return NULL;
428}
429
195static void __noreturn txx9_machine_halt(void) 430static void __noreturn txx9_machine_halt(void)
196{ 431{
197 local_irq_disable(); 432 local_irq_disable();
@@ -222,6 +457,20 @@ void __init txx9_wdt_init(unsigned long base)
222 platform_device_register_simple("txx9wdt", -1, &res, 1); 457 platform_device_register_simple("txx9wdt", -1, &res, 1);
223} 458}
224 459
460void txx9_wdt_now(unsigned long base)
461{
462 struct txx9_tmr_reg __iomem *tmrptr =
463 ioremap(base, sizeof(struct txx9_tmr_reg));
464 /* disable watch dog timer */
465 __raw_writel(TXx9_TMWTMR_WDIS | TXx9_TMWTMR_TWC, &tmrptr->wtmr);
466 __raw_writel(0, &tmrptr->tcr);
467 /* kick watchdog */
468 __raw_writel(TXx9_TMWTMR_TWIE, &tmrptr->wtmr);
469 __raw_writel(1, &tmrptr->cpra); /* immediate */
470 __raw_writel(TXx9_TMTCR_TCE | TXx9_TMTCR_CCDE | TXx9_TMTCR_TMODE_WDOG,
471 &tmrptr->tcr);
472}
473
225/* SPI support */ 474/* SPI support */
226void __init txx9_spi_init(int busid, unsigned long base, int irq) 475void __init txx9_spi_init(int busid, unsigned long base, int irq)
227{ 476{
@@ -372,3 +621,153 @@ static unsigned long __swizzle_addr_none(unsigned long port)
372unsigned long (*__swizzle_addr_b)(unsigned long port) = __swizzle_addr_none; 621unsigned long (*__swizzle_addr_b)(unsigned long port) = __swizzle_addr_none;
373EXPORT_SYMBOL(__swizzle_addr_b); 622EXPORT_SYMBOL(__swizzle_addr_b);
374#endif 623#endif
624
625void __init txx9_physmap_flash_init(int no, unsigned long addr,
626 unsigned long size,
627 const struct physmap_flash_data *pdata)
628{
629#if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
630 struct resource res = {
631 .start = addr,
632 .end = addr + size - 1,
633 .flags = IORESOURCE_MEM,
634 };
635 struct platform_device *pdev;
636#ifdef CONFIG_MTD_PARTITIONS
637 static struct mtd_partition parts[2];
638 struct physmap_flash_data pdata_part;
639
640 /* If this area contained boot area, make separate partition */
641 if (pdata->nr_parts == 0 && !pdata->parts &&
642 addr < 0x1fc00000 && addr + size > 0x1fc00000 &&
643 !parts[0].name) {
644 parts[0].name = "boot";
645 parts[0].offset = 0x1fc00000 - addr;
646 parts[0].size = addr + size - 0x1fc00000;
647 parts[1].name = "user";
648 parts[1].offset = 0;
649 parts[1].size = 0x1fc00000 - addr;
650 pdata_part = *pdata;
651 pdata_part.nr_parts = ARRAY_SIZE(parts);
652 pdata_part.parts = parts;
653 pdata = &pdata_part;
654 }
655#endif
656 pdev = platform_device_alloc("physmap-flash", no);
657 if (!pdev ||
658 platform_device_add_resources(pdev, &res, 1) ||
659 platform_device_add_data(pdev, pdata, sizeof(*pdata)) ||
660 platform_device_add(pdev))
661 platform_device_put(pdev);
662#endif
663}
664
665#if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
666static DEFINE_SPINLOCK(txx9_iocled_lock);
667
668#define TXX9_IOCLED_MAXLEDS 8
669
670struct txx9_iocled_data {
671 struct gpio_chip chip;
672 u8 cur_val;
673 void __iomem *mmioaddr;
674 struct gpio_led_platform_data pdata;
675 struct gpio_led leds[TXX9_IOCLED_MAXLEDS];
676 char names[TXX9_IOCLED_MAXLEDS][32];
677};
678
679static int txx9_iocled_get(struct gpio_chip *chip, unsigned int offset)
680{
681 struct txx9_iocled_data *data =
682 container_of(chip, struct txx9_iocled_data, chip);
683 return data->cur_val & (1 << offset);
684}
685
686static void txx9_iocled_set(struct gpio_chip *chip, unsigned int offset,
687 int value)
688{
689 struct txx9_iocled_data *data =
690 container_of(chip, struct txx9_iocled_data, chip);
691 unsigned long flags;
692 spin_lock_irqsave(&txx9_iocled_lock, flags);
693 if (value)
694 data->cur_val |= 1 << offset;
695 else
696 data->cur_val &= ~(1 << offset);
697 writeb(data->cur_val, data->mmioaddr);
698 mmiowb();
699 spin_unlock_irqrestore(&txx9_iocled_lock, flags);
700}
701
702static int txx9_iocled_dir_in(struct gpio_chip *chip, unsigned int offset)
703{
704 return 0;
705}
706
707static int txx9_iocled_dir_out(struct gpio_chip *chip, unsigned int offset,
708 int value)
709{
710 txx9_iocled_set(chip, offset, value);
711 return 0;
712}
713
714void __init txx9_iocled_init(unsigned long baseaddr,
715 int basenum, unsigned int num, int lowactive,
716 const char *color, char **deftriggers)
717{
718 struct txx9_iocled_data *iocled;
719 struct platform_device *pdev;
720 int i;
721 static char *default_triggers[] __initdata = {
722 "heartbeat",
723 "ide-disk",
724 "nand-disk",
725 NULL,
726 };
727
728 if (!deftriggers)
729 deftriggers = default_triggers;
730 iocled = kzalloc(sizeof(*iocled), GFP_KERNEL);
731 if (!iocled)
732 return;
733 iocled->mmioaddr = ioremap(baseaddr, 1);
734 if (!iocled->mmioaddr)
735 return;
736 iocled->chip.get = txx9_iocled_get;
737 iocled->chip.set = txx9_iocled_set;
738 iocled->chip.direction_input = txx9_iocled_dir_in;
739 iocled->chip.direction_output = txx9_iocled_dir_out;
740 iocled->chip.label = "iocled";
741 iocled->chip.base = basenum;
742 iocled->chip.ngpio = num;
743 if (gpiochip_add(&iocled->chip))
744 return;
745 if (basenum < 0)
746 basenum = iocled->chip.base;
747
748 pdev = platform_device_alloc("leds-gpio", basenum);
749 if (!pdev)
750 return;
751 iocled->pdata.num_leds = num;
752 iocled->pdata.leds = iocled->leds;
753 for (i = 0; i < num; i++) {
754 struct gpio_led *led = &iocled->leds[i];
755 snprintf(iocled->names[i], sizeof(iocled->names[i]),
756 "iocled:%s:%u", color, i);
757 led->name = iocled->names[i];
758 led->gpio = basenum + i;
759 led->active_low = lowactive;
760 if (deftriggers && *deftriggers)
761 led->default_trigger = *deftriggers++;
762 }
763 pdev->dev.platform_data = &iocled->pdata;
764 if (platform_device_add(pdev))
765 platform_device_put(pdev);
766}
767#else /* CONFIG_LEDS_GPIO */
768void __init txx9_iocled_init(unsigned long baseaddr,
769 int basenum, unsigned int num, int lowactive,
770 const char *color, char **deftriggers)
771{
772}
773#endif /* CONFIG_LEDS_GPIO */