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)
11 #include <linux/console.h>
12 #include <linux/init.h>
13 #include <linux/clk.h>
14 #include <linux/clkdev.h>
15 #include <linux/clk-provider.h>
17 #include <asm/addrspace.h>
20 #include <asm/bootinfo.h>
21 #include <linux/of_fdt.h>
22 #include <asm/reboot.h>
23 #include <asm/time.h> /* for mips_hpt_frequency */
25 #include <asm/smp-ops.h>
27 #include "mach-rtl838x.h"
29 extern int rtl838x_serial_init(void);
30 extern struct rtl838x_soc_info soc_info
;
41 static void rtl838x_restart(char *command
)
43 u32 pll
= sw_r32(RTL838X_PLL_CML_CTRL
);
44 /* SoC reset vector (in flash memory): on RTL839x platform preferred way to reset */
45 void (*f
)(void) = (void *) 0xbfc00000;
47 pr_info("System restart.\n");
48 if (soc_info
.family
== RTL8390_FAMILY_ID
) {
50 /* If calling reset vector fails, reset entire chip */
51 sw_w32(0xFFFFFFFF, RTL839X_RST_GLB_CTRL
);
52 /* If this fails, halt the CPU */
57 pr_info("PLL control register: %x, applying reset value %x\n",
58 pll
, pll_reset_value
);
59 sw_w32(3, RTL838X_INT_RW_CTRL
);
60 sw_w32(pll_reset_value
, RTL838X_PLL_CML_CTRL
);
61 sw_w32(0, RTL838X_INT_RW_CTRL
);
63 pr_info("Resetting RTL838X SoC\n");
64 /* Reset Global Control1 Register */
65 sw_w32(1, RTL838X_RST_GLB_CTRL_1
);
68 static void rtl838x_halt(void)
70 pr_info("System halted.\n");
75 static void __init
rtl838x_setup(void)
79 pr_info("Registering _machine_restart\n");
80 _machine_restart
= rtl838x_restart
;
81 _machine_halt
= rtl838x_halt
;
83 val
= rtl838x_r32((volatile void *)0xBB0040000);
85 pr_info("PCI device found\n");
87 pr_info("NO PCI device found\n");
89 /* Setup System LED. Bit 15 (14 for RTL8390) then allows to toggle it */
90 if (soc_info
.family
== RTL8380_FAMILY_ID
)
91 sw_w32_mask(0, 3 << 16, RTL838X_LED_GLB_CTRL
);
93 sw_w32_mask(0, 3 << 15, RTL839X_LED_GLB_CTRL
);
96 void __init
plat_mem_setup(void)
100 pr_info("%s called\n", __func__
);
102 set_io_port_base(KSEG1
);
104 if (fw_passed_dtb
) /* UHI interface */
105 dtb
= (void *)fw_passed_dtb
;
106 else if (__dtb_start
!= __dtb_end
)
107 dtb
= (void *)__dtb_start
;
109 panic("no dtb found");
112 * Load the devicetree. This causes the chosen node to be
113 * parsed resulting in our memory appearing
115 __dt_setup_arch(dtb
);
124 int clk_enable(struct clk
*clk
)
128 EXPORT_SYMBOL_GPL(clk_enable
);
130 void clk_disable(struct clk
*clk
)
134 EXPORT_SYMBOL_GPL(clk_disable
);
136 unsigned long clk_get_rate(struct clk
*clk
)
143 EXPORT_SYMBOL_GPL(clk_get_rate
);
145 int clk_set_rate(struct clk
*clk
, unsigned long rate
)
149 EXPORT_SYMBOL_GPL(clk_set_rate
);
151 long clk_round_rate(struct clk
*clk
, unsigned long rate
)
155 EXPORT_SYMBOL_GPL(clk_round_rate
);
157 void __init
plat_time_init(void)
159 u32 freq
= 500000000;
160 struct device_node
*np
;
161 struct clk
*clk
= &cpu_clk
;
163 np
= of_find_node_by_name(NULL
, "cpus");
165 pr_err("Missing 'cpus' DT node, using default frequency.");
167 if (of_property_read_u32(np
, "frequency", &freq
) < 0)
168 pr_err("No 'frequency' property in DT, using default.");
170 pr_info("CPU frequency from device tree: %d", freq
);
177 panic("unable to get CPU clock, err=%ld", PTR_ERR(clk
));
179 pr_info("CPU Clock: %ld MHz\n", clk
->rate
/ 1000000);
180 mips_hpt_frequency
= freq
/ 2;
182 pll_reset_value
= sw_r32(RTL838X_PLL_CML_CTRL
);
183 pr_info("PLL control register: %x\n", pll_reset_value
);
185 /* With the info from the command line and cpu-freq we can setup the console */
186 rtl838x_serial_init();