Marek Vasut | 426ca62 | 2024-03-26 13:07:22 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Copyright (C) 2024, Marek Vasut <marex@denx.de> |
| 4 | * |
| 5 | * This is code moved from drivers/net/dwc_eth_qos.c , which is: |
| 6 | * Copyright (c) 2016, NVIDIA CORPORATION. |
| 7 | */ |
| 8 | |
Marek Vasut | 426ca62 | 2024-03-26 13:07:22 +0100 | [diff] [blame] | 9 | #include <asm/cache.h> |
| 10 | #include <asm/gpio.h> |
| 11 | #include <asm/io.h> |
| 12 | #include <clk.h> |
| 13 | #include <cpu_func.h> |
| 14 | #include <dm.h> |
| 15 | #include <dm/device_compat.h> |
| 16 | #include <errno.h> |
| 17 | #include <eth_phy.h> |
| 18 | #include <log.h> |
| 19 | #include <malloc.h> |
| 20 | #include <memalign.h> |
| 21 | #include <miiphy.h> |
| 22 | #include <net.h> |
| 23 | #include <netdev.h> |
| 24 | #include <phy.h> |
Christophe Roullier | 033dc76 | 2024-03-26 13:07:30 +0100 | [diff] [blame] | 25 | #include <regmap.h> |
Marek Vasut | 426ca62 | 2024-03-26 13:07:22 +0100 | [diff] [blame] | 26 | #include <reset.h> |
Marek Vasut | 7595bfc | 2024-03-26 13:07:24 +0100 | [diff] [blame] | 27 | #include <syscon.h> |
Marek Vasut | 426ca62 | 2024-03-26 13:07:22 +0100 | [diff] [blame] | 28 | #include <wait_bit.h> |
Marek Vasut | 577f46b | 2024-03-26 13:07:26 +0100 | [diff] [blame] | 29 | #include <linux/bitfield.h> |
Marek Vasut | 426ca62 | 2024-03-26 13:07:22 +0100 | [diff] [blame] | 30 | #include <linux/delay.h> |
| 31 | |
| 32 | #include "dwc_eth_qos.h" |
| 33 | |
Marek Vasut | 7595bfc | 2024-03-26 13:07:24 +0100 | [diff] [blame] | 34 | /* SYSCFG registers */ |
| 35 | #define SYSCFG_PMCSETR 0x04 |
Christophe Roullier | 033dc76 | 2024-03-26 13:07:30 +0100 | [diff] [blame] | 36 | #define SYSCFG_PMCCLRR_MP13 0x08 |
| 37 | #define SYSCFG_PMCCLRR_MP15 0x44 |
| 38 | |
| 39 | #define SYSCFG_PMCSETR_ETH1_MASK GENMASK(23, 16) |
| 40 | #define SYSCFG_PMCSETR_ETH2_MASK GENMASK(31, 24) |
Marek Vasut | 7595bfc | 2024-03-26 13:07:24 +0100 | [diff] [blame] | 41 | |
| 42 | #define SYSCFG_PMCSETR_ETH_CLK_SEL BIT(16) |
| 43 | #define SYSCFG_PMCSETR_ETH_REF_CLK_SEL BIT(17) |
| 44 | |
Christophe Roullier | 033dc76 | 2024-03-26 13:07:30 +0100 | [diff] [blame] | 45 | /* STM32MP15xx specific bit */ |
Marek Vasut | 7595bfc | 2024-03-26 13:07:24 +0100 | [diff] [blame] | 46 | #define SYSCFG_PMCSETR_ETH_SELMII BIT(20) |
| 47 | |
| 48 | #define SYSCFG_PMCSETR_ETH_SEL_MASK GENMASK(23, 21) |
Marek Vasut | 577f46b | 2024-03-26 13:07:26 +0100 | [diff] [blame] | 49 | #define SYSCFG_PMCSETR_ETH_SEL_GMII_MII 0x0 |
| 50 | #define SYSCFG_PMCSETR_ETH_SEL_RGMII 0x1 |
| 51 | #define SYSCFG_PMCSETR_ETH_SEL_RMII 0x4 |
Marek Vasut | 7595bfc | 2024-03-26 13:07:24 +0100 | [diff] [blame] | 52 | |
Marek Vasut | 426ca62 | 2024-03-26 13:07:22 +0100 | [diff] [blame] | 53 | static ulong eqos_get_tick_clk_rate_stm32(struct udevice *dev) |
| 54 | { |
Marek Vasut | b14101c | 2024-03-26 13:07:25 +0100 | [diff] [blame] | 55 | struct eqos_priv __maybe_unused *eqos = dev_get_priv(dev); |
| 56 | |
| 57 | if (!CONFIG_IS_ENABLED(CLK)) |
| 58 | return 0; |
Marek Vasut | 426ca62 | 2024-03-26 13:07:22 +0100 | [diff] [blame] | 59 | |
| 60 | return clk_get_rate(&eqos->clk_master_bus); |
Marek Vasut | 426ca62 | 2024-03-26 13:07:22 +0100 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | static int eqos_start_clks_stm32(struct udevice *dev) |
| 64 | { |
Marek Vasut | b14101c | 2024-03-26 13:07:25 +0100 | [diff] [blame] | 65 | struct eqos_priv __maybe_unused *eqos = dev_get_priv(dev); |
Marek Vasut | 426ca62 | 2024-03-26 13:07:22 +0100 | [diff] [blame] | 66 | int ret; |
| 67 | |
Marek Vasut | b14101c | 2024-03-26 13:07:25 +0100 | [diff] [blame] | 68 | if (!CONFIG_IS_ENABLED(CLK)) |
| 69 | return 0; |
| 70 | |
Marek Vasut | 5a1640e | 2024-03-26 13:07:28 +0100 | [diff] [blame] | 71 | dev_dbg(dev, "%s:\n", __func__); |
Marek Vasut | 426ca62 | 2024-03-26 13:07:22 +0100 | [diff] [blame] | 72 | |
| 73 | ret = clk_enable(&eqos->clk_master_bus); |
| 74 | if (ret < 0) { |
Marek Vasut | 5a1640e | 2024-03-26 13:07:28 +0100 | [diff] [blame] | 75 | dev_err(dev, "clk_enable(clk_master_bus) failed: %d\n", ret); |
Marek Vasut | 426ca62 | 2024-03-26 13:07:22 +0100 | [diff] [blame] | 76 | goto err; |
| 77 | } |
| 78 | |
| 79 | ret = clk_enable(&eqos->clk_rx); |
| 80 | if (ret < 0) { |
Marek Vasut | 5a1640e | 2024-03-26 13:07:28 +0100 | [diff] [blame] | 81 | dev_err(dev, "clk_enable(clk_rx) failed: %d\n", ret); |
Marek Vasut | 426ca62 | 2024-03-26 13:07:22 +0100 | [diff] [blame] | 82 | goto err_disable_clk_master_bus; |
| 83 | } |
| 84 | |
| 85 | ret = clk_enable(&eqos->clk_tx); |
| 86 | if (ret < 0) { |
Marek Vasut | 5a1640e | 2024-03-26 13:07:28 +0100 | [diff] [blame] | 87 | dev_err(dev, "clk_enable(clk_tx) failed: %d\n", ret); |
Marek Vasut | 426ca62 | 2024-03-26 13:07:22 +0100 | [diff] [blame] | 88 | goto err_disable_clk_rx; |
| 89 | } |
| 90 | |
| 91 | if (clk_valid(&eqos->clk_ck) && !eqos->clk_ck_enabled) { |
| 92 | ret = clk_enable(&eqos->clk_ck); |
| 93 | if (ret < 0) { |
Marek Vasut | 5a1640e | 2024-03-26 13:07:28 +0100 | [diff] [blame] | 94 | dev_err(dev, "clk_enable(clk_ck) failed: %d\n", ret); |
Marek Vasut | 426ca62 | 2024-03-26 13:07:22 +0100 | [diff] [blame] | 95 | goto err_disable_clk_tx; |
| 96 | } |
| 97 | eqos->clk_ck_enabled = true; |
| 98 | } |
Marek Vasut | 426ca62 | 2024-03-26 13:07:22 +0100 | [diff] [blame] | 99 | |
Marek Vasut | 5a1640e | 2024-03-26 13:07:28 +0100 | [diff] [blame] | 100 | dev_dbg(dev, "%s: OK\n", __func__); |
Marek Vasut | 426ca62 | 2024-03-26 13:07:22 +0100 | [diff] [blame] | 101 | return 0; |
| 102 | |
Marek Vasut | 426ca62 | 2024-03-26 13:07:22 +0100 | [diff] [blame] | 103 | err_disable_clk_tx: |
| 104 | clk_disable(&eqos->clk_tx); |
| 105 | err_disable_clk_rx: |
| 106 | clk_disable(&eqos->clk_rx); |
| 107 | err_disable_clk_master_bus: |
| 108 | clk_disable(&eqos->clk_master_bus); |
| 109 | err: |
Marek Vasut | 5a1640e | 2024-03-26 13:07:28 +0100 | [diff] [blame] | 110 | dev_dbg(dev, "%s: FAILED: %d\n", __func__, ret); |
| 111 | |
Marek Vasut | 426ca62 | 2024-03-26 13:07:22 +0100 | [diff] [blame] | 112 | return ret; |
Marek Vasut | 426ca62 | 2024-03-26 13:07:22 +0100 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | static int eqos_stop_clks_stm32(struct udevice *dev) |
| 116 | { |
Marek Vasut | b14101c | 2024-03-26 13:07:25 +0100 | [diff] [blame] | 117 | struct eqos_priv __maybe_unused *eqos = dev_get_priv(dev); |
| 118 | |
| 119 | if (!CONFIG_IS_ENABLED(CLK)) |
| 120 | return 0; |
Marek Vasut | 426ca62 | 2024-03-26 13:07:22 +0100 | [diff] [blame] | 121 | |
Marek Vasut | 5a1640e | 2024-03-26 13:07:28 +0100 | [diff] [blame] | 122 | dev_dbg(dev, "%s:\n", __func__); |
Marek Vasut | 426ca62 | 2024-03-26 13:07:22 +0100 | [diff] [blame] | 123 | |
| 124 | clk_disable(&eqos->clk_tx); |
| 125 | clk_disable(&eqos->clk_rx); |
| 126 | clk_disable(&eqos->clk_master_bus); |
Marek Vasut | 426ca62 | 2024-03-26 13:07:22 +0100 | [diff] [blame] | 127 | |
Marek Vasut | 5a1640e | 2024-03-26 13:07:28 +0100 | [diff] [blame] | 128 | dev_dbg(dev, "%s: OK\n", __func__); |
| 129 | |
Marek Vasut | 426ca62 | 2024-03-26 13:07:22 +0100 | [diff] [blame] | 130 | return 0; |
| 131 | } |
| 132 | |
Marek Vasut | 7595bfc | 2024-03-26 13:07:24 +0100 | [diff] [blame] | 133 | static int eqos_probe_syscfg_stm32(struct udevice *dev, |
| 134 | phy_interface_t interface_type) |
| 135 | { |
Marek Vasut | e77fa87 | 2024-03-26 13:07:29 +0100 | [diff] [blame] | 136 | /* Ethernet 50MHz RMII clock selection. */ |
| 137 | const bool eth_ref_clk_sel = dev_read_bool(dev, "st,eth-ref-clk-sel"); |
Christophe Roullier | 033dc76 | 2024-03-26 13:07:30 +0100 | [diff] [blame] | 138 | /* SoC is STM32MP13xx with two ethernet MACs */ |
| 139 | const bool is_mp13 = device_is_compatible(dev, "st,stm32mp13-dwmac"); |
Marek Vasut | e77fa87 | 2024-03-26 13:07:29 +0100 | [diff] [blame] | 140 | /* Gigabit Ethernet 125MHz clock selection. */ |
| 141 | const bool eth_clk_sel = dev_read_bool(dev, "st,eth-clk-sel"); |
Marek Vasut | 6c4b245 | 2024-03-26 13:07:32 +0100 | [diff] [blame] | 142 | /* Ethernet clock source is RCC. */ |
| 143 | const bool ext_phyclk = dev_read_bool(dev, "st,ext-phyclk"); |
Christophe Roullier | 033dc76 | 2024-03-26 13:07:30 +0100 | [diff] [blame] | 144 | struct regmap *regmap; |
| 145 | u32 regmap_mask; |
Marek Vasut | 7595bfc | 2024-03-26 13:07:24 +0100 | [diff] [blame] | 146 | u32 value; |
| 147 | |
Christophe Roullier | 033dc76 | 2024-03-26 13:07:30 +0100 | [diff] [blame] | 148 | regmap = syscon_regmap_lookup_by_phandle(dev, "st,syscon"); |
| 149 | if (IS_ERR(regmap)) |
| 150 | return PTR_ERR(regmap); |
| 151 | |
| 152 | regmap_mask = dev_read_u32_index_default(dev, "st,syscon", 2, |
| 153 | SYSCFG_PMCSETR_ETH1_MASK); |
Marek Vasut | 7595bfc | 2024-03-26 13:07:24 +0100 | [diff] [blame] | 154 | |
| 155 | switch (interface_type) { |
| 156 | case PHY_INTERFACE_MODE_MII: |
Marek Vasut | 5a1640e | 2024-03-26 13:07:28 +0100 | [diff] [blame] | 157 | dev_dbg(dev, "PHY_INTERFACE_MODE_MII\n"); |
Marek Vasut | 577f46b | 2024-03-26 13:07:26 +0100 | [diff] [blame] | 158 | value = FIELD_PREP(SYSCFG_PMCSETR_ETH_SEL_MASK, |
| 159 | SYSCFG_PMCSETR_ETH_SEL_GMII_MII); |
Marek Vasut | 6c4b245 | 2024-03-26 13:07:32 +0100 | [diff] [blame] | 160 | /* |
| 161 | * STM32MP15xx supports both MII and GMII, STM32MP13xx MII only. |
| 162 | * SYSCFG_PMCSETR ETH_SELMII is present only on STM32MP15xx and |
| 163 | * acts as a selector between 0:GMII and 1:MII. As STM32MP13xx |
| 164 | * supports only MII, ETH_SELMII is not present. |
| 165 | */ |
Christophe Roullier | 033dc76 | 2024-03-26 13:07:30 +0100 | [diff] [blame] | 166 | if (!is_mp13) /* Select MII mode on STM32MP15xx */ |
| 167 | value |= SYSCFG_PMCSETR_ETH_SELMII; |
Marek Vasut | 7595bfc | 2024-03-26 13:07:24 +0100 | [diff] [blame] | 168 | break; |
Christophe Roullier | 033dc76 | 2024-03-26 13:07:30 +0100 | [diff] [blame] | 169 | case PHY_INTERFACE_MODE_GMII: /* STM32MP15xx only */ |
Marek Vasut | 5a1640e | 2024-03-26 13:07:28 +0100 | [diff] [blame] | 170 | dev_dbg(dev, "PHY_INTERFACE_MODE_GMII\n"); |
Marek Vasut | 577f46b | 2024-03-26 13:07:26 +0100 | [diff] [blame] | 171 | value = FIELD_PREP(SYSCFG_PMCSETR_ETH_SEL_MASK, |
| 172 | SYSCFG_PMCSETR_ETH_SEL_GMII_MII); |
Marek Vasut | 6c4b245 | 2024-03-26 13:07:32 +0100 | [diff] [blame] | 173 | /* |
| 174 | * If eth_clk_sel is set, use internal ETH_CLKx clock from RCC, |
| 175 | * otherwise use external clock from IO pin (requires matching |
| 176 | * GPIO block AF setting of that pin). |
| 177 | */ |
| 178 | if (eth_clk_sel || ext_phyclk) |
Marek Vasut | 577f46b | 2024-03-26 13:07:26 +0100 | [diff] [blame] | 179 | value |= SYSCFG_PMCSETR_ETH_CLK_SEL; |
Marek Vasut | 7595bfc | 2024-03-26 13:07:24 +0100 | [diff] [blame] | 180 | break; |
| 181 | case PHY_INTERFACE_MODE_RMII: |
Marek Vasut | 5a1640e | 2024-03-26 13:07:28 +0100 | [diff] [blame] | 182 | dev_dbg(dev, "PHY_INTERFACE_MODE_RMII\n"); |
Marek Vasut | 577f46b | 2024-03-26 13:07:26 +0100 | [diff] [blame] | 183 | value = FIELD_PREP(SYSCFG_PMCSETR_ETH_SEL_MASK, |
| 184 | SYSCFG_PMCSETR_ETH_SEL_RMII); |
Marek Vasut | 6c4b245 | 2024-03-26 13:07:32 +0100 | [diff] [blame] | 185 | /* |
| 186 | * If eth_ref_clk_sel is set, use internal clock from RCC, |
| 187 | * otherwise use external clock from ETHn_RX_CLK/ETHn_REF_CLK |
| 188 | * IO pin (requires matching GPIO block AF setting of that |
| 189 | * pin). |
| 190 | */ |
| 191 | if (eth_ref_clk_sel || ext_phyclk) |
Marek Vasut | 577f46b | 2024-03-26 13:07:26 +0100 | [diff] [blame] | 192 | value |= SYSCFG_PMCSETR_ETH_REF_CLK_SEL; |
Marek Vasut | 7595bfc | 2024-03-26 13:07:24 +0100 | [diff] [blame] | 193 | break; |
| 194 | case PHY_INTERFACE_MODE_RGMII: |
| 195 | case PHY_INTERFACE_MODE_RGMII_ID: |
| 196 | case PHY_INTERFACE_MODE_RGMII_RXID: |
| 197 | case PHY_INTERFACE_MODE_RGMII_TXID: |
Marek Vasut | 5a1640e | 2024-03-26 13:07:28 +0100 | [diff] [blame] | 198 | dev_dbg(dev, "PHY_INTERFACE_MODE_RGMII\n"); |
Marek Vasut | 577f46b | 2024-03-26 13:07:26 +0100 | [diff] [blame] | 199 | value = FIELD_PREP(SYSCFG_PMCSETR_ETH_SEL_MASK, |
| 200 | SYSCFG_PMCSETR_ETH_SEL_RGMII); |
Marek Vasut | 6c4b245 | 2024-03-26 13:07:32 +0100 | [diff] [blame] | 201 | /* |
| 202 | * If eth_clk_sel is set, use internal ETH_CLKx clock from RCC, |
| 203 | * otherwise use external clock from ETHx_CLK125 pin (requires |
| 204 | * matching GPIO block AF setting of that pin). |
| 205 | */ |
| 206 | if (eth_clk_sel || ext_phyclk) |
Marek Vasut | 577f46b | 2024-03-26 13:07:26 +0100 | [diff] [blame] | 207 | value |= SYSCFG_PMCSETR_ETH_CLK_SEL; |
Marek Vasut | 7595bfc | 2024-03-26 13:07:24 +0100 | [diff] [blame] | 208 | break; |
| 209 | default: |
Marek Vasut | 5a1640e | 2024-03-26 13:07:28 +0100 | [diff] [blame] | 210 | dev_dbg(dev, "Do not manage %d interface\n", |
| 211 | interface_type); |
Marek Vasut | 7595bfc | 2024-03-26 13:07:24 +0100 | [diff] [blame] | 212 | /* Do not manage others interfaces */ |
| 213 | return -EINVAL; |
| 214 | } |
| 215 | |
Christophe Roullier | 033dc76 | 2024-03-26 13:07:30 +0100 | [diff] [blame] | 216 | /* Shift value at correct ethernet MAC offset in SYSCFG_PMCSETR */ |
| 217 | value <<= ffs(regmap_mask) - ffs(SYSCFG_PMCSETR_ETH1_MASK); |
Marek Vasut | 7595bfc | 2024-03-26 13:07:24 +0100 | [diff] [blame] | 218 | |
Christophe Roullier | 033dc76 | 2024-03-26 13:07:30 +0100 | [diff] [blame] | 219 | /* Update PMCCLRR (clear register) */ |
| 220 | regmap_write(regmap, is_mp13 ? |
| 221 | SYSCFG_PMCCLRR_MP13 : SYSCFG_PMCCLRR_MP15, |
| 222 | regmap_mask); |
| 223 | |
| 224 | return regmap_update_bits(regmap, SYSCFG_PMCSETR, regmap_mask, value); |
Marek Vasut | 7595bfc | 2024-03-26 13:07:24 +0100 | [diff] [blame] | 225 | } |
| 226 | |
Marek Vasut | 426ca62 | 2024-03-26 13:07:22 +0100 | [diff] [blame] | 227 | static int eqos_probe_resources_stm32(struct udevice *dev) |
| 228 | { |
| 229 | struct eqos_priv *eqos = dev_get_priv(dev); |
Marek Vasut | 426ca62 | 2024-03-26 13:07:22 +0100 | [diff] [blame] | 230 | phy_interface_t interface; |
Marek Vasut | 7595bfc | 2024-03-26 13:07:24 +0100 | [diff] [blame] | 231 | int ret; |
Marek Vasut | 426ca62 | 2024-03-26 13:07:22 +0100 | [diff] [blame] | 232 | |
Marek Vasut | 5a1640e | 2024-03-26 13:07:28 +0100 | [diff] [blame] | 233 | dev_dbg(dev, "%s:\n", __func__); |
Marek Vasut | 426ca62 | 2024-03-26 13:07:22 +0100 | [diff] [blame] | 234 | |
| 235 | interface = eqos->config->interface(dev); |
| 236 | |
Philip Oberfichtner | d6d22da | 2024-08-02 11:25:37 +0200 | [diff] [blame] | 237 | ret = eqos_get_base_addr_dt(dev); |
| 238 | if (ret) { |
| 239 | dev_err(dev, "eqos_get_base_addr_dt failed: %d\n", ret); |
| 240 | return ret; |
| 241 | } |
| 242 | |
Marek Vasut | 426ca62 | 2024-03-26 13:07:22 +0100 | [diff] [blame] | 243 | if (interface == PHY_INTERFACE_MODE_NA) { |
Marek Vasut | 5a1640e | 2024-03-26 13:07:28 +0100 | [diff] [blame] | 244 | dev_err(dev, "Invalid PHY interface\n"); |
Marek Vasut | 426ca62 | 2024-03-26 13:07:22 +0100 | [diff] [blame] | 245 | return -EINVAL; |
| 246 | } |
| 247 | |
Marek Vasut | 7595bfc | 2024-03-26 13:07:24 +0100 | [diff] [blame] | 248 | ret = eqos_probe_syscfg_stm32(dev, interface); |
Marek Vasut | 426ca62 | 2024-03-26 13:07:22 +0100 | [diff] [blame] | 249 | if (ret) |
| 250 | return -EINVAL; |
| 251 | |
| 252 | ret = clk_get_by_name(dev, "stmmaceth", &eqos->clk_master_bus); |
| 253 | if (ret) { |
Marek Vasut | 5a1640e | 2024-03-26 13:07:28 +0100 | [diff] [blame] | 254 | dev_err(dev, "clk_get_by_name(master_bus) failed: %d\n", ret); |
Marek Vasut | 426ca62 | 2024-03-26 13:07:22 +0100 | [diff] [blame] | 255 | goto err_probe; |
| 256 | } |
| 257 | |
| 258 | ret = clk_get_by_name(dev, "mac-clk-rx", &eqos->clk_rx); |
| 259 | if (ret) { |
Marek Vasut | 5a1640e | 2024-03-26 13:07:28 +0100 | [diff] [blame] | 260 | dev_err(dev, "clk_get_by_name(rx) failed: %d\n", ret); |
Marek Vasut | 426ca62 | 2024-03-26 13:07:22 +0100 | [diff] [blame] | 261 | goto err_probe; |
| 262 | } |
| 263 | |
| 264 | ret = clk_get_by_name(dev, "mac-clk-tx", &eqos->clk_tx); |
| 265 | if (ret) { |
Marek Vasut | 5a1640e | 2024-03-26 13:07:28 +0100 | [diff] [blame] | 266 | dev_err(dev, "clk_get_by_name(tx) failed: %d\n", ret); |
Marek Vasut | 426ca62 | 2024-03-26 13:07:22 +0100 | [diff] [blame] | 267 | goto err_probe; |
| 268 | } |
| 269 | |
| 270 | /* Get ETH_CLK clocks (optional) */ |
| 271 | ret = clk_get_by_name(dev, "eth-ck", &eqos->clk_ck); |
| 272 | if (ret) |
Marek Vasut | 5a1640e | 2024-03-26 13:07:28 +0100 | [diff] [blame] | 273 | dev_warn(dev, "No phy clock provided %d\n", ret); |
Marek Vasut | 426ca62 | 2024-03-26 13:07:22 +0100 | [diff] [blame] | 274 | |
Heesub Shin | 57a8884 | 2024-04-28 23:24:05 +0900 | [diff] [blame] | 275 | /* Get reset gpio pin (optional) */ |
| 276 | ret = gpio_request_by_name(dev, "phy-reset-gpios", 0, |
| 277 | &eqos->phy_reset_gpio, GPIOD_IS_OUT); |
| 278 | if (ret) |
| 279 | pr_warn("No phy reset gpio provided: %d\n", ret); |
| 280 | |
Marek Vasut | 5a1640e | 2024-03-26 13:07:28 +0100 | [diff] [blame] | 281 | dev_dbg(dev, "%s: OK\n", __func__); |
| 282 | |
Marek Vasut | 426ca62 | 2024-03-26 13:07:22 +0100 | [diff] [blame] | 283 | return 0; |
| 284 | |
| 285 | err_probe: |
| 286 | |
Marek Vasut | 5a1640e | 2024-03-26 13:07:28 +0100 | [diff] [blame] | 287 | dev_dbg(dev, "%s: returns %d\n", __func__, ret); |
| 288 | |
Marek Vasut | 426ca62 | 2024-03-26 13:07:22 +0100 | [diff] [blame] | 289 | return ret; |
| 290 | } |
| 291 | |
Heesub Shin | 57a8884 | 2024-04-28 23:24:05 +0900 | [diff] [blame] | 292 | static int eqos_start_resets_stm32(struct udevice *dev) |
| 293 | { |
| 294 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 295 | |
| 296 | debug("%s(dev=%p):\n", __func__, dev); |
| 297 | |
| 298 | if (dm_gpio_is_valid(&eqos->phy_reset_gpio)) { |
| 299 | dm_gpio_set_value(&eqos->phy_reset_gpio, 1); |
| 300 | udelay(2); |
| 301 | dm_gpio_set_value(&eqos->phy_reset_gpio, 0); |
| 302 | } |
| 303 | |
| 304 | return 0; |
| 305 | } |
| 306 | |
Marek Vasut | 426ca62 | 2024-03-26 13:07:22 +0100 | [diff] [blame] | 307 | static int eqos_remove_resources_stm32(struct udevice *dev) |
| 308 | { |
Marek Vasut | 5a1640e | 2024-03-26 13:07:28 +0100 | [diff] [blame] | 309 | dev_dbg(dev, "%s:\n", __func__); |
Marek Vasut | 426ca62 | 2024-03-26 13:07:22 +0100 | [diff] [blame] | 310 | |
| 311 | return 0; |
| 312 | } |
| 313 | |
| 314 | static struct eqos_ops eqos_stm32_ops = { |
| 315 | .eqos_inval_desc = eqos_inval_desc_generic, |
| 316 | .eqos_flush_desc = eqos_flush_desc_generic, |
| 317 | .eqos_inval_buffer = eqos_inval_buffer_generic, |
| 318 | .eqos_flush_buffer = eqos_flush_buffer_generic, |
| 319 | .eqos_probe_resources = eqos_probe_resources_stm32, |
| 320 | .eqos_remove_resources = eqos_remove_resources_stm32, |
| 321 | .eqos_stop_resets = eqos_null_ops, |
Heesub Shin | 57a8884 | 2024-04-28 23:24:05 +0900 | [diff] [blame] | 322 | .eqos_start_resets = eqos_start_resets_stm32, |
Marek Vasut | 426ca62 | 2024-03-26 13:07:22 +0100 | [diff] [blame] | 323 | .eqos_stop_clks = eqos_stop_clks_stm32, |
| 324 | .eqos_start_clks = eqos_start_clks_stm32, |
| 325 | .eqos_calibrate_pads = eqos_null_ops, |
| 326 | .eqos_disable_calibration = eqos_null_ops, |
| 327 | .eqos_set_tx_clk_speed = eqos_null_ops, |
| 328 | .eqos_get_enetaddr = eqos_null_ops, |
| 329 | .eqos_get_tick_clk_rate = eqos_get_tick_clk_rate_stm32 |
| 330 | }; |
| 331 | |
Christophe Roullier | 25a1686 | 2024-03-26 13:07:31 +0100 | [diff] [blame] | 332 | struct eqos_config __maybe_unused eqos_stm32mp13_config = { |
| 333 | .reg_access_always_ok = false, |
| 334 | .mdio_wait = 10000, |
| 335 | .swr_wait = 50, |
| 336 | .config_mac = EQOS_MAC_RXQ_CTRL0_RXQ0EN_ENABLED_DCB, |
| 337 | .config_mac_mdio = EQOS_MAC_MDIO_ADDRESS_CR_250_300, |
| 338 | .axi_bus_width = EQOS_AXI_WIDTH_32, |
| 339 | .interface = dev_read_phy_mode, |
| 340 | .ops = &eqos_stm32_ops |
| 341 | }; |
| 342 | |
Marek Vasut | 944ba37 | 2024-03-26 13:07:23 +0100 | [diff] [blame] | 343 | struct eqos_config __maybe_unused eqos_stm32mp15_config = { |
Marek Vasut | 426ca62 | 2024-03-26 13:07:22 +0100 | [diff] [blame] | 344 | .reg_access_always_ok = false, |
| 345 | .mdio_wait = 10000, |
| 346 | .swr_wait = 50, |
| 347 | .config_mac = EQOS_MAC_RXQ_CTRL0_RXQ0EN_ENABLED_AV, |
| 348 | .config_mac_mdio = EQOS_MAC_MDIO_ADDRESS_CR_250_300, |
| 349 | .axi_bus_width = EQOS_AXI_WIDTH_64, |
| 350 | .interface = dev_read_phy_mode, |
| 351 | .ops = &eqos_stm32_ops |
| 352 | }; |