blob: c9b0d5a061d63cea7bc2053f826306a21f9bade7 [file] [log] [blame]
Peter Robinson0b437a02022-12-31 09:24:00 +00001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * (C) Copyright 2016 Rockchip Electronics Co., Ltd
4 * (C) Copyright 2022 Peter Robinson <pbrobinson at gmail.com>
5 */
6
7#include <common.h>
8#include <dm.h>
9#include <init.h>
10#include <syscon.h>
Peter Robinson0b437a02022-12-31 09:24:00 +000011#include <asm/arch-rockchip/clock.h>
12#include <asm/arch-rockchip/grf_rk3399.h>
13#include <asm/arch-rockchip/hardware.h>
Peter Robinson0b437a02022-12-31 09:24:00 +000014#include <power/regulator.h>
15
Ondrej Jirman2a1b6282023-05-25 15:27:08 +020016#define GRF_IO_VSEL_BT565_GPIO2AB 1
17#define GRF_IO_VSEL_AUDIO_GPIO3D4A 2
Peter Robinson0b437a02022-12-31 09:24:00 +000018#define PMUGRF_CON0_VSEL_SHIFT 8
19
20#ifndef CONFIG_SPL_BUILD
21int board_early_init_f(void)
22{
23 struct udevice *regulator;
24 int ret;
25
26 ret = regulator_get_by_platname("vcc5v0_usb", &regulator);
27 if (ret) {
28 pr_debug("%s vcc5v0_usb init fail! ret %d\n", __func__, ret);
29 goto out;
30 }
31
32 ret = regulator_set_enable(regulator, true);
33 if (ret)
34 pr_debug("%s vcc5v0-host-en-gpio set fail! ret %d\n", __func__, ret);
35
36out:
37 return 0;
38}
39#endif
40
41#ifdef CONFIG_MISC_INIT_R
42static void setup_iodomain(void)
43{
44 struct rk3399_grf_regs *grf =
45 syscon_get_first_range(ROCKCHIP_SYSCON_GRF);
46 struct rk3399_pmugrf_regs *pmugrf =
47 syscon_get_first_range(ROCKCHIP_SYSCON_PMUGRF);
48
49 /* BT565 is in 1.8v domain */
Ondrej Jirman2a1b6282023-05-25 15:27:08 +020050 rk_setreg(&grf->io_vsel,
51 GRF_IO_VSEL_BT565_GPIO2AB | GRF_IO_VSEL_AUDIO_GPIO3D4A);
Peter Robinson0b437a02022-12-31 09:24:00 +000052
53 /* Set GPIO1 1.8v/3.0v source select to PMU1830_VOL */
54 rk_setreg(&pmugrf->soc_con0, 1 << PMUGRF_CON0_VSEL_SHIFT);
55}
56
Quentin Schulz15892102024-03-11 13:01:48 +010057int rockchip_early_misc_init_r(void)
Peter Robinson0b437a02022-12-31 09:24:00 +000058{
Peter Robinson0b437a02022-12-31 09:24:00 +000059 setup_iodomain();
60
Quentin Schulz15892102024-03-11 13:01:48 +010061 return 0;
Peter Robinson0b437a02022-12-31 09:24:00 +000062
Peter Robinson0b437a02022-12-31 09:24:00 +000063}
64#endif