blob: a82f97b2d5446cfe7149aa81967d48a5318b2a79 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Klaus Goger81039932017-04-07 19:13:38 +02002/*
3 * (C) Copyright 2017 Theobroma Systems Design und Consulting GmbH
Klaus Goger81039932017-04-07 19:13:38 +02004 */
Philipp Tomsich3df66262017-09-29 19:27:54 +02005
Klaus Goger81039932017-04-07 19:13:38 +02006#include <dm.h>
Jakob Unterwurzacherb0720632017-12-15 16:23:14 +01007#include <syscon.h>
Klaus Goger81039932017-04-07 19:13:38 +02008#include <dm/pinctrl.h>
Jakob Unterwurzacherb0720632017-12-15 16:23:14 +01009#include <asm/io.h>
Kever Yang9fbe17c2019-03-28 11:01:23 +080010#include <asm/arch-rockchip/clock.h>
Kever Yang9fbe17c2019-03-28 11:01:23 +080011#include <asm/arch-rockchip/hardware.h>
12#include <asm/arch-rockchip/grf_rk3399.h>
Rohan Gargf49ad9d2019-08-12 17:04:36 +020013#include <asm/arch-rockchip/misc.h>
Quentin Schulz1e1a92b2024-01-17 18:59:10 +010014#include "../common/common.h"
Klaus Goger81039932017-04-07 19:13:38 +020015
Jakob Unterwurzacherb0720632017-12-15 16:23:14 +010016static void setup_iodomain(void)
17{
18 const u32 GRF_IO_VSEL_GPIO4CD_SHIFT = 3;
19 struct rk3399_grf_regs *grf =
20 syscon_get_first_range(ROCKCHIP_SYSCON_GRF);
21
22 /*
23 * Set bit 3 in GRF_IO_VSEL so PCIE_RST# works (pin GPIO4_C6).
24 * Linux assumes that PCIE_RST# works out of the box as it probes
25 * PCIe before loading the iodomain driver.
26 */
27 rk_setreg(&grf->io_vsel, 1 << GRF_IO_VSEL_GPIO4CD_SHIFT);
28}
29
Philipp Tomsich2ebe2892017-05-05 19:21:39 +020030int misc_init_r(void)
31{
Heiko Stuebner5a57b9b2020-06-05 12:06:39 +020032 const u32 cpuid_offset = 0x7;
33 const u32 cpuid_length = 0x10;
34 u8 cpuid[cpuid_length];
35 int ret;
Rohan Gargf49ad9d2019-08-12 17:04:36 +020036
Heiko Stuebner5a57b9b2020-06-05 12:06:39 +020037 ret = rockchip_cpuid_from_efuse(cpuid_offset, cpuid_length, cpuid);
38 if (ret)
39 return ret;
Rohan Gargf49ad9d2019-08-12 17:04:36 +020040
Heiko Stuebner5a57b9b2020-06-05 12:06:39 +020041 ret = rockchip_cpuid_set(cpuid, cpuid_length);
42 if (ret)
43 return ret;
Rohan Gargf49ad9d2019-08-12 17:04:36 +020044
Heiko Stuebner5a57b9b2020-06-05 12:06:39 +020045 ret = rockchip_setup_macaddr();
46 if (ret)
47 return ret;
Rohan Gargf49ad9d2019-08-12 17:04:36 +020048
Jakob Unterwurzacherb0720632017-12-15 16:23:14 +010049 setup_iodomain();
Klaus Goger810182f2018-05-24 17:15:53 +020050 setup_boottargets();
Philipp Tomsich2ebe2892017-05-05 19:21:39 +020051
52 return 0;
53}