Quentin Schulz | 14f731e | 2024-03-11 13:01:59 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * (C) Copyright 2023 Theobroma Systems Design und Consulting GmbH |
| 4 | */ |
| 5 | |
| 6 | #include <phy.h> |
| 7 | #include <eth_phy.h> |
| 8 | |
| 9 | #include <asm/types.h> |
| 10 | #include <asm/arch-rockchip/cru_rk3588.h> |
| 11 | #include <asm/arch-rockchip/hardware.h> |
| 12 | #include <asm/arch-rockchip/ioc_rk3588.h> |
| 13 | #include <asm-generic/u-boot.h> |
| 14 | #include <dm/device.h> |
| 15 | #include <dm/uclass-id.h> |
| 16 | #include <linux/bitfield.h> |
| 17 | |
| 18 | #include "../common/common.h" |
| 19 | |
| 20 | #define GPIO2C3_SEL_MASK GENMASK(15, 12) |
| 21 | #define GPIO2C3_ETH0_REFCLKO_25M FIELD_PREP(GPIO2C3_SEL_MASK, 1) |
| 22 | |
| 23 | #define REFCLKO25M_ETH0_OUT_SEL_MASK BIT(15) |
| 24 | #define REFCLKO25M_ETH0_OUT_SEL_CPLL FIELD_PREP(REFCLKO25M_ETH0_OUT_SEL_MASK, 1) |
| 25 | #define REFCLKO25M_ETH0_OUT_DIV_MASK GENMASK(14, 8) |
| 26 | #define REFCLKO25M_ETH0_OUT_DIV(x) FIELD_PREP(REFCLKO25M_ETH0_OUT_DIV_MASK, (x) - 1) |
| 27 | |
| 28 | #define REFCLKO25M_ETH0_OUT_EN BIT(4) |
| 29 | |
| 30 | void setup_eth0refclko(void) |
| 31 | { |
| 32 | /* Configure and enable ETH0_REFCLKO_25MHz */ |
| 33 | static struct rk3588_bus_ioc * const bus_ioc = (void *)BUS_IOC_BASE; |
| 34 | static struct rk3588_cru * const cru = (void *)CRU_BASE; |
| 35 | |
| 36 | /* 1. Pinmux */ |
| 37 | rk_clrsetreg(&bus_ioc->gpio2c_iomux_sel_l, GPIO2C3_SEL_MASK, GPIO2C3_ETH0_REFCLKO_25M); |
| 38 | /* 2. Parent clock selection + divider => CPLL (1.5GHz) / 60 => 25MHz */ |
| 39 | rk_clrsetreg(&cru->clksel_con[15], |
| 40 | REFCLKO25M_ETH0_OUT_SEL_MASK | REFCLKO25M_ETH0_OUT_DIV_MASK, |
| 41 | REFCLKO25M_ETH0_OUT_SEL_CPLL | REFCLKO25M_ETH0_OUT_DIV(60)); |
| 42 | /* 3. Enable clock */ |
| 43 | rk_clrreg(&cru->clkgate_con[5], REFCLKO25M_ETH0_OUT_EN); |
| 44 | } |
| 45 | |
| 46 | int rockchip_early_misc_init_r(void) |
| 47 | { |
| 48 | setup_boottargets(); |
| 49 | |
| 50 | setup_eth0refclko(); |
| 51 | |
| 52 | return 0; |
| 53 | } |