11a59d1b8SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
21da177e4SLinus Torvalds /*
3f137e463SAndrew Isaacson * Copyright (C) 2000, 2001, 2002, 2003, 2004 Broadcom Corporation
41da177e4SLinus Torvalds * Copyright (C) 2004 by Ralf Baechle (ralf@linux-mips.org)
51da177e4SLinus Torvalds */
61da177e4SLinus Torvalds
71da177e4SLinus Torvalds /*
81da177e4SLinus Torvalds * Setup code for the SWARM board
91da177e4SLinus Torvalds */
101da177e4SLinus Torvalds
111da177e4SLinus Torvalds #include <linux/spinlock.h>
121da177e4SLinus Torvalds #include <linux/mm.h>
1357c8a661SMike Rapoport #include <linux/memblock.h>
141da177e4SLinus Torvalds #include <linux/init.h>
151da177e4SLinus Torvalds #include <linux/kernel.h>
16894673eeSJon Smirl #include <linux/screen_info.h>
171da177e4SLinus Torvalds #include <linux/initrd.h>
181da177e4SLinus Torvalds
191da177e4SLinus Torvalds #include <asm/irq.h>
201da177e4SLinus Torvalds #include <asm/io.h>
211da177e4SLinus Torvalds #include <asm/bootinfo.h>
221da177e4SLinus Torvalds #include <asm/mipsregs.h>
231da177e4SLinus Torvalds #include <asm/reboot.h>
241da177e4SLinus Torvalds #include <asm/time.h>
251da177e4SLinus Torvalds #include <asm/traps.h>
261da177e4SLinus Torvalds #include <asm/sibyte/sb1250.h>
27b984d7b5SThomas Bogendoerfer #ifdef CONFIG_SIBYTE_BCM1x80
28f137e463SAndrew Isaacson #include <asm/sibyte/bcm1480_regs.h>
29f137e463SAndrew Isaacson #elif defined(CONFIG_SIBYTE_SB1250) || defined(CONFIG_SIBYTE_BCM112X)
301da177e4SLinus Torvalds #include <asm/sibyte/sb1250_regs.h>
31f137e463SAndrew Isaacson #else
3203dbd2e0SMaciej W. Rozycki #error invalid SiByte board configuration
33f137e463SAndrew Isaacson #endif
341da177e4SLinus Torvalds #include <asm/sibyte/sb1250_genbus.h>
351da177e4SLinus Torvalds #include <asm/sibyte/board.h>
361da177e4SLinus Torvalds
37b984d7b5SThomas Bogendoerfer #ifdef CONFIG_SIBYTE_BCM1x80
38f137e463SAndrew Isaacson extern void bcm1480_setup(void);
39f137e463SAndrew Isaacson #elif defined(CONFIG_SIBYTE_SB1250) || defined(CONFIG_SIBYTE_BCM112X)
401da177e4SLinus Torvalds extern void sb1250_setup(void);
41f137e463SAndrew Isaacson #else
4203dbd2e0SMaciej W. Rozycki #error invalid SiByte board configuration
43f137e463SAndrew Isaacson #endif
441da177e4SLinus Torvalds
451da177e4SLinus Torvalds extern int xicor_probe(void);
46f06e7aa4SBaolin Wang extern int xicor_set_time(time64_t);
4709adad17SBaolin Wang extern time64_t xicor_get_time(void);
481da177e4SLinus Torvalds
491da177e4SLinus Torvalds extern int m41t81_probe(void);
50f06e7aa4SBaolin Wang extern int m41t81_set_time(time64_t);
5109adad17SBaolin Wang extern time64_t m41t81_get_time(void);
521da177e4SLinus Torvalds
get_system_type(void)531da177e4SLinus Torvalds const char *get_system_type(void)
541da177e4SLinus Torvalds {
551da177e4SLinus Torvalds return "SiByte " SIBYTE_BOARD_NAME;
561da177e4SLinus Torvalds }
571da177e4SLinus Torvalds
swarm_be_handler(struct pt_regs * regs,int is_fixup)581da177e4SLinus Torvalds int swarm_be_handler(struct pt_regs *regs, int is_fixup)
591da177e4SLinus Torvalds {
601da177e4SLinus Torvalds if (!is_fixup && (regs->cp0_cause & 4)) {
611da177e4SLinus Torvalds /* Data bus error - print PA */
626aaf7786SRalf Baechle printk("DBE physical address: %010Lx\n",
631da177e4SLinus Torvalds __read_64bit_c0_register($26, 1));
641da177e4SLinus Torvalds }
65635c9907SRalf Baechle return is_fixup ? MIPS_BE_FIXUP : MIPS_BE_FATAL;
661da177e4SLinus Torvalds }
671da177e4SLinus Torvalds
684b550488SRalf Baechle enum swarm_rtc_type {
694b550488SRalf Baechle RTC_NONE,
704b550488SRalf Baechle RTC_XICOR,
712b3e5023SRalf Baechle RTC_M41T81,
724b550488SRalf Baechle };
734b550488SRalf Baechle
744b550488SRalf Baechle enum swarm_rtc_type swarm_rtc_type;
754b550488SRalf Baechle
read_persistent_clock64(struct timespec64 * ts)7609adad17SBaolin Wang void read_persistent_clock64(struct timespec64 *ts)
774b550488SRalf Baechle {
7809adad17SBaolin Wang time64_t sec;
79d4f587c6SMartin Schwidefsky
804b550488SRalf Baechle switch (swarm_rtc_type) {
814b550488SRalf Baechle case RTC_XICOR:
82d4f587c6SMartin Schwidefsky sec = xicor_get_time();
83d4f587c6SMartin Schwidefsky break;
844b550488SRalf Baechle
852b3e5023SRalf Baechle case RTC_M41T81:
86d4f587c6SMartin Schwidefsky sec = m41t81_get_time();
87d4f587c6SMartin Schwidefsky break;
884b550488SRalf Baechle
894b550488SRalf Baechle case RTC_NONE:
904b550488SRalf Baechle default:
9109adad17SBaolin Wang sec = mktime64(2000, 1, 1, 0, 0, 0);
92d4f587c6SMartin Schwidefsky break;
934b550488SRalf Baechle }
94d4f587c6SMartin Schwidefsky ts->tv_sec = sec;
95a648e811SMark Mason ts->tv_nsec = 0;
964b550488SRalf Baechle }
974b550488SRalf Baechle
update_persistent_clock64(struct timespec64 now)98f06e7aa4SBaolin Wang int update_persistent_clock64(struct timespec64 now)
994b550488SRalf Baechle {
100f06e7aa4SBaolin Wang time64_t sec = now.tv_sec;
101f06e7aa4SBaolin Wang
1024b550488SRalf Baechle switch (swarm_rtc_type) {
1034b550488SRalf Baechle case RTC_XICOR:
1044b550488SRalf Baechle return xicor_set_time(sec);
1054b550488SRalf Baechle
1062b3e5023SRalf Baechle case RTC_M41T81:
1074b550488SRalf Baechle return m41t81_set_time(sec);
1084b550488SRalf Baechle
1094b550488SRalf Baechle case RTC_NONE:
1104b550488SRalf Baechle default:
1114b550488SRalf Baechle return -1;
1124b550488SRalf Baechle }
1134b550488SRalf Baechle }
1144b550488SRalf Baechle
plat_mem_setup(void)1152925aba4SRalf Baechle void __init plat_mem_setup(void)
1161da177e4SLinus Torvalds {
117b984d7b5SThomas Bogendoerfer #ifdef CONFIG_SIBYTE_BCM1x80
118f137e463SAndrew Isaacson bcm1480_setup();
119f137e463SAndrew Isaacson #elif defined(CONFIG_SIBYTE_SB1250) || defined(CONFIG_SIBYTE_BCM112X)
1201da177e4SLinus Torvalds sb1250_setup();
121f137e463SAndrew Isaacson #else
12203dbd2e0SMaciej W. Rozycki #error invalid SiByte board configuration
123f137e463SAndrew Isaacson #endif
1241da177e4SLinus Torvalds
1251f761b3eSFlorian Fainelli mips_set_be_handler(swarm_be_handler);
1261da177e4SLinus Torvalds
1274b550488SRalf Baechle if (xicor_probe())
1284b550488SRalf Baechle swarm_rtc_type = RTC_XICOR;
1294b550488SRalf Baechle if (m41t81_probe())
1302b3e5023SRalf Baechle swarm_rtc_type = RTC_M41T81;
1311da177e4SLinus Torvalds
132*d9a5d5c4SArnd Bergmann #ifdef CONFIG_VGA_CONSOLE
1331da177e4SLinus Torvalds screen_info = (struct screen_info) {
134b20947aaSSebastian Andrzej Siewior .orig_video_page = 52,
135b20947aaSSebastian Andrzej Siewior .orig_video_mode = 3,
136b20947aaSSebastian Andrzej Siewior .orig_video_cols = 80,
137b20947aaSSebastian Andrzej Siewior .flags = 12,
138b20947aaSSebastian Andrzej Siewior .orig_video_ega_bx = 3,
139b20947aaSSebastian Andrzej Siewior .orig_video_lines = 25,
140b20947aaSSebastian Andrzej Siewior .orig_video_isVGA = 0x22,
141b20947aaSSebastian Andrzej Siewior .orig_video_points = 16,
1421da177e4SLinus Torvalds };
1431da177e4SLinus Torvalds /* XXXKW for CFE, get lines/cols from environment */
1441da177e4SLinus Torvalds #endif
1451da177e4SLinus Torvalds }
1461da177e4SLinus Torvalds
1471da177e4SLinus Torvalds #ifdef LEDS_PHYS
1481da177e4SLinus Torvalds
setleds(char * str)1491da177e4SLinus Torvalds void setleds(char *str)
1501da177e4SLinus Torvalds {
1518fb303c7SRalf Baechle void *reg;
1521da177e4SLinus Torvalds int i;
1538fb303c7SRalf Baechle
1541da177e4SLinus Torvalds for (i = 0; i < 4; i++) {
1558fb303c7SRalf Baechle reg = IOADDR(LEDS_PHYS) + 0x20 + ((3 - i) << 3);
1568fb303c7SRalf Baechle
1578fb303c7SRalf Baechle if (!str[i])
1588fb303c7SRalf Baechle writeb(' ', reg);
1598fb303c7SRalf Baechle else
1608fb303c7SRalf Baechle writeb(str[i], reg);
1611da177e4SLinus Torvalds }
1621da177e4SLinus Torvalds }
1638fb303c7SRalf Baechle
1648fb303c7SRalf Baechle #endif /* LEDS_PHYS */
165