Peter Robinson | 0b437a0 | 2022-12-31 09:24:00 +0000 | [diff] [blame] | 1 | // 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 Robinson | 0b437a0 | 2022-12-31 09:24:00 +0000 | [diff] [blame] | 11 | #include <asm/arch-rockchip/clock.h> |
| 12 | #include <asm/arch-rockchip/grf_rk3399.h> |
| 13 | #include <asm/arch-rockchip/hardware.h> |
Peter Robinson | 0b437a0 | 2022-12-31 09:24:00 +0000 | [diff] [blame] | 14 | #include <power/regulator.h> |
| 15 | |
Ondrej Jirman | 2a1b628 | 2023-05-25 15:27:08 +0200 | [diff] [blame] | 16 | #define GRF_IO_VSEL_BT565_GPIO2AB 1 |
| 17 | #define GRF_IO_VSEL_AUDIO_GPIO3D4A 2 |
Peter Robinson | 0b437a0 | 2022-12-31 09:24:00 +0000 | [diff] [blame] | 18 | #define PMUGRF_CON0_VSEL_SHIFT 8 |
| 19 | |
| 20 | #ifndef CONFIG_SPL_BUILD |
| 21 | int board_early_init_f(void) |
| 22 | { |
| 23 | struct udevice *regulator; |
| 24 | int ret; |
| 25 | |
| 26 | ret = regulator_get_by_platname("vcc5v0_usb", ®ulator); |
| 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 | |
| 36 | out: |
| 37 | return 0; |
| 38 | } |
| 39 | #endif |
| 40 | |
| 41 | #ifdef CONFIG_MISC_INIT_R |
| 42 | static 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 Jirman | 2a1b628 | 2023-05-25 15:27:08 +0200 | [diff] [blame] | 50 | rk_setreg(&grf->io_vsel, |
| 51 | GRF_IO_VSEL_BT565_GPIO2AB | GRF_IO_VSEL_AUDIO_GPIO3D4A); |
Peter Robinson | 0b437a0 | 2022-12-31 09:24:00 +0000 | [diff] [blame] | 52 | |
| 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 Schulz | 1589210 | 2024-03-11 13:01:48 +0100 | [diff] [blame] | 57 | int rockchip_early_misc_init_r(void) |
Peter Robinson | 0b437a0 | 2022-12-31 09:24:00 +0000 | [diff] [blame] | 58 | { |
Peter Robinson | 0b437a0 | 2022-12-31 09:24:00 +0000 | [diff] [blame] | 59 | setup_iodomain(); |
| 60 | |
Quentin Schulz | 1589210 | 2024-03-11 13:01:48 +0100 | [diff] [blame] | 61 | return 0; |
Peter Robinson | 0b437a0 | 2022-12-31 09:24:00 +0000 | [diff] [blame] | 62 | |
Peter Robinson | 0b437a0 | 2022-12-31 09:24:00 +0000 | [diff] [blame] | 63 | } |
| 64 | #endif |