1 // SPDX-License-Identifier: GPL-2.0-only
3 * Setup for the Realtek RTL838X SoC:
4 * Memory, Timer and Serial
6 * Copyright (C) 2020 B. Koblitz
7 * based on the original BSP by
8 * Copyright (C) 2006-2012 Tony Wu (tonywu@realtek.com)
12 #include <linux/console.h>
13 #include <linux/init.h>
14 #include <linux/clk.h>
15 #include <linux/clkdev.h>
16 #include <linux/clk-provider.h>
18 #include <asm/addrspace.h>
21 #include <asm/bootinfo.h>
22 #include <linux/of_fdt.h>
23 #include <asm/reboot.h>
24 #include <asm/time.h> /* for mips_hpt_frequency */
26 #include <asm/smp-ops.h>
28 #include "mach-rtl83xx.h"
30 extern int rtl838x_serial_init(void);
31 extern struct rtl83xx_soc_info soc_info
;
35 static void rtl838x_restart(char *command
)
37 u32 pll
= sw_r32(RTL838X_PLL_CML_CTRL
);
38 /* SoC reset vector (in flash memory): on RTL839x platform preferred way to reset */
39 void (*f
)(void) = (void *) 0xbfc00000;
41 pr_info("System restart.\n");
42 if (soc_info
.family
== RTL8390_FAMILY_ID
) {
44 /* If calling reset vector fails, reset entire chip */
45 sw_w32(0xFFFFFFFF, RTL839X_RST_GLB_CTRL
);
46 /* If this fails, halt the CPU */
51 pr_info("PLL control register: %x, applying reset value %x\n",
52 pll
, pll_reset_value
);
53 sw_w32(3, RTL838X_INT_RW_CTRL
);
54 sw_w32(pll_reset_value
, RTL838X_PLL_CML_CTRL
);
55 sw_w32(0, RTL838X_INT_RW_CTRL
);
57 pr_info("Resetting RTL838X SoC\n");
58 /* Reset Global Control1 Register */
59 sw_w32(1, RTL838X_RST_GLB_CTRL_1
);
62 static void rtl838x_halt(void)
64 pr_info("System halted.\n");
68 void __init
plat_mem_setup(void)
72 set_io_port_base(KSEG1
);
73 _machine_restart
= rtl838x_restart
;
74 _machine_halt
= rtl838x_halt
;
76 if (fw_passed_dtb
) /* UHI interface */
77 dtb
= (void *)fw_passed_dtb
;
78 else if (__dtb_start
!= __dtb_end
)
79 dtb
= (void *)__dtb_start
;
81 panic("no dtb found");
84 * Load the devicetree. This causes the chosen node to be
85 * parsed resulting in our memory appearing
90 void __init
plat_time_init(void)
92 struct device_node
*np
;
95 np
= of_find_node_by_name(NULL
, "cpus");
97 pr_err("Missing 'cpus' DT node, using default frequency.");
99 if (of_property_read_u32(np
, "frequency", &freq
) < 0)
100 pr_err("No 'frequency' property in DT, using default.");
102 pr_info("CPU frequency from device tree: %d", freq
);
106 mips_hpt_frequency
= freq
/ 2;
108 pll_reset_value
= sw_r32(RTL838X_PLL_CML_CTRL
);