Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2016, NVIDIA CORPORATION. |
| 4 | * |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 5 | * Portions based on U-Boot's rtl8169.c. |
| 6 | */ |
| 7 | |
| 8 | /* |
| 9 | * This driver supports the Synopsys Designware Ethernet QOS (Quality Of |
| 10 | * Service) IP block. The IP supports multiple options for bus type, clocking/ |
| 11 | * reset structure, and feature list. |
| 12 | * |
| 13 | * The driver is written such that generic core logic is kept separate from |
| 14 | * configuration-specific logic. Code that interacts with configuration- |
| 15 | * specific resources is split out into separate functions to avoid polluting |
| 16 | * common code. If/when this driver is enhanced to support multiple |
| 17 | * configurations, the core code should be adapted to call all configuration- |
| 18 | * specific functions through function pointers, with the definition of those |
| 19 | * function pointers being supplied by struct udevice_id eqos_ids[]'s .data |
| 20 | * field. |
| 21 | * |
| 22 | * The following configurations are currently supported: |
| 23 | * tegra186: |
| 24 | * NVIDIA's Tegra186 chip. This configuration uses an AXI master/DMA bus, an |
| 25 | * AHB slave/register bus, contains the DMA, MTL, and MAC sub-blocks, and |
| 26 | * supports a single RGMII PHY. This configuration also has SW control over |
| 27 | * all clock and reset signals to the HW block. |
| 28 | */ |
Patrick Delaunay | 9e6ed38 | 2020-09-09 18:30:06 +0200 | [diff] [blame] | 29 | |
Patrick Delaunay | 5787284 | 2021-07-20 20:15:29 +0200 | [diff] [blame] | 30 | #define LOG_CATEGORY UCLASS_ETH |
| 31 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 32 | #include <common.h> |
| 33 | #include <clk.h> |
Simon Glass | 6333448 | 2019-11-14 12:57:39 -0700 | [diff] [blame] | 34 | #include <cpu_func.h> |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 35 | #include <dm.h> |
| 36 | #include <errno.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 37 | #include <log.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 38 | #include <malloc.h> |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 39 | #include <memalign.h> |
| 40 | #include <miiphy.h> |
| 41 | #include <net.h> |
| 42 | #include <netdev.h> |
| 43 | #include <phy.h> |
| 44 | #include <reset.h> |
| 45 | #include <wait_bit.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 46 | #include <asm/cache.h> |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 47 | #include <asm/gpio.h> |
| 48 | #include <asm/io.h> |
Ye Li | ad122b7 | 2020-05-03 22:41:15 +0800 | [diff] [blame] | 49 | #include <eth_phy.h> |
Fugang Duan | dd455e6 | 2020-05-03 22:41:18 +0800 | [diff] [blame] | 50 | #ifdef CONFIG_ARCH_IMX8M |
| 51 | #include <asm/arch/clock.h> |
| 52 | #include <asm/mach-imx/sys_proto.h> |
| 53 | #endif |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 54 | #include <linux/bitops.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 55 | #include <linux/delay.h> |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 56 | |
| 57 | /* Core registers */ |
| 58 | |
| 59 | #define EQOS_MAC_REGS_BASE 0x000 |
| 60 | struct eqos_mac_regs { |
| 61 | uint32_t configuration; /* 0x000 */ |
| 62 | uint32_t unused_004[(0x070 - 0x004) / 4]; /* 0x004 */ |
| 63 | uint32_t q0_tx_flow_ctrl; /* 0x070 */ |
| 64 | uint32_t unused_070[(0x090 - 0x074) / 4]; /* 0x074 */ |
| 65 | uint32_t rx_flow_ctrl; /* 0x090 */ |
| 66 | uint32_t unused_094; /* 0x094 */ |
| 67 | uint32_t txq_prty_map0; /* 0x098 */ |
| 68 | uint32_t unused_09c; /* 0x09c */ |
| 69 | uint32_t rxq_ctrl0; /* 0x0a0 */ |
| 70 | uint32_t unused_0a4; /* 0x0a4 */ |
| 71 | uint32_t rxq_ctrl2; /* 0x0a8 */ |
| 72 | uint32_t unused_0ac[(0x0dc - 0x0ac) / 4]; /* 0x0ac */ |
| 73 | uint32_t us_tic_counter; /* 0x0dc */ |
| 74 | uint32_t unused_0e0[(0x11c - 0x0e0) / 4]; /* 0x0e0 */ |
| 75 | uint32_t hw_feature0; /* 0x11c */ |
| 76 | uint32_t hw_feature1; /* 0x120 */ |
| 77 | uint32_t hw_feature2; /* 0x124 */ |
| 78 | uint32_t unused_128[(0x200 - 0x128) / 4]; /* 0x128 */ |
| 79 | uint32_t mdio_address; /* 0x200 */ |
| 80 | uint32_t mdio_data; /* 0x204 */ |
| 81 | uint32_t unused_208[(0x300 - 0x208) / 4]; /* 0x208 */ |
| 82 | uint32_t address0_high; /* 0x300 */ |
| 83 | uint32_t address0_low; /* 0x304 */ |
| 84 | }; |
| 85 | |
| 86 | #define EQOS_MAC_CONFIGURATION_GPSLCE BIT(23) |
| 87 | #define EQOS_MAC_CONFIGURATION_CST BIT(21) |
| 88 | #define EQOS_MAC_CONFIGURATION_ACS BIT(20) |
| 89 | #define EQOS_MAC_CONFIGURATION_WD BIT(19) |
| 90 | #define EQOS_MAC_CONFIGURATION_JD BIT(17) |
| 91 | #define EQOS_MAC_CONFIGURATION_JE BIT(16) |
| 92 | #define EQOS_MAC_CONFIGURATION_PS BIT(15) |
| 93 | #define EQOS_MAC_CONFIGURATION_FES BIT(14) |
| 94 | #define EQOS_MAC_CONFIGURATION_DM BIT(13) |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 95 | #define EQOS_MAC_CONFIGURATION_LM BIT(12) |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 96 | #define EQOS_MAC_CONFIGURATION_TE BIT(1) |
| 97 | #define EQOS_MAC_CONFIGURATION_RE BIT(0) |
| 98 | |
| 99 | #define EQOS_MAC_Q0_TX_FLOW_CTRL_PT_SHIFT 16 |
| 100 | #define EQOS_MAC_Q0_TX_FLOW_CTRL_PT_MASK 0xffff |
| 101 | #define EQOS_MAC_Q0_TX_FLOW_CTRL_TFE BIT(1) |
| 102 | |
| 103 | #define EQOS_MAC_RX_FLOW_CTRL_RFE BIT(0) |
| 104 | |
| 105 | #define EQOS_MAC_TXQ_PRTY_MAP0_PSTQ0_SHIFT 0 |
| 106 | #define EQOS_MAC_TXQ_PRTY_MAP0_PSTQ0_MASK 0xff |
| 107 | |
| 108 | #define EQOS_MAC_RXQ_CTRL0_RXQ0EN_SHIFT 0 |
| 109 | #define EQOS_MAC_RXQ_CTRL0_RXQ0EN_MASK 3 |
| 110 | #define EQOS_MAC_RXQ_CTRL0_RXQ0EN_NOT_ENABLED 0 |
| 111 | #define EQOS_MAC_RXQ_CTRL0_RXQ0EN_ENABLED_DCB 2 |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 112 | #define EQOS_MAC_RXQ_CTRL0_RXQ0EN_ENABLED_AV 1 |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 113 | |
| 114 | #define EQOS_MAC_RXQ_CTRL2_PSRQ0_SHIFT 0 |
| 115 | #define EQOS_MAC_RXQ_CTRL2_PSRQ0_MASK 0xff |
| 116 | |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 117 | #define EQOS_MAC_HW_FEATURE0_MMCSEL_SHIFT 8 |
| 118 | #define EQOS_MAC_HW_FEATURE0_HDSEL_SHIFT 2 |
| 119 | #define EQOS_MAC_HW_FEATURE0_GMIISEL_SHIFT 1 |
| 120 | #define EQOS_MAC_HW_FEATURE0_MIISEL_SHIFT 0 |
| 121 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 122 | #define EQOS_MAC_HW_FEATURE1_TXFIFOSIZE_SHIFT 6 |
| 123 | #define EQOS_MAC_HW_FEATURE1_TXFIFOSIZE_MASK 0x1f |
| 124 | #define EQOS_MAC_HW_FEATURE1_RXFIFOSIZE_SHIFT 0 |
| 125 | #define EQOS_MAC_HW_FEATURE1_RXFIFOSIZE_MASK 0x1f |
| 126 | |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 127 | #define EQOS_MAC_HW_FEATURE3_ASP_SHIFT 28 |
| 128 | #define EQOS_MAC_HW_FEATURE3_ASP_MASK 0x3 |
| 129 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 130 | #define EQOS_MAC_MDIO_ADDRESS_PA_SHIFT 21 |
| 131 | #define EQOS_MAC_MDIO_ADDRESS_RDA_SHIFT 16 |
| 132 | #define EQOS_MAC_MDIO_ADDRESS_CR_SHIFT 8 |
| 133 | #define EQOS_MAC_MDIO_ADDRESS_CR_20_35 2 |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 134 | #define EQOS_MAC_MDIO_ADDRESS_CR_250_300 5 |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 135 | #define EQOS_MAC_MDIO_ADDRESS_SKAP BIT(4) |
| 136 | #define EQOS_MAC_MDIO_ADDRESS_GOC_SHIFT 2 |
| 137 | #define EQOS_MAC_MDIO_ADDRESS_GOC_READ 3 |
| 138 | #define EQOS_MAC_MDIO_ADDRESS_GOC_WRITE 1 |
| 139 | #define EQOS_MAC_MDIO_ADDRESS_C45E BIT(1) |
| 140 | #define EQOS_MAC_MDIO_ADDRESS_GB BIT(0) |
| 141 | |
| 142 | #define EQOS_MAC_MDIO_DATA_GD_MASK 0xffff |
| 143 | |
| 144 | #define EQOS_MTL_REGS_BASE 0xd00 |
| 145 | struct eqos_mtl_regs { |
| 146 | uint32_t txq0_operation_mode; /* 0xd00 */ |
| 147 | uint32_t unused_d04; /* 0xd04 */ |
| 148 | uint32_t txq0_debug; /* 0xd08 */ |
| 149 | uint32_t unused_d0c[(0xd18 - 0xd0c) / 4]; /* 0xd0c */ |
| 150 | uint32_t txq0_quantum_weight; /* 0xd18 */ |
| 151 | uint32_t unused_d1c[(0xd30 - 0xd1c) / 4]; /* 0xd1c */ |
| 152 | uint32_t rxq0_operation_mode; /* 0xd30 */ |
| 153 | uint32_t unused_d34; /* 0xd34 */ |
| 154 | uint32_t rxq0_debug; /* 0xd38 */ |
| 155 | }; |
| 156 | |
| 157 | #define EQOS_MTL_TXQ0_OPERATION_MODE_TQS_SHIFT 16 |
| 158 | #define EQOS_MTL_TXQ0_OPERATION_MODE_TQS_MASK 0x1ff |
| 159 | #define EQOS_MTL_TXQ0_OPERATION_MODE_TXQEN_SHIFT 2 |
| 160 | #define EQOS_MTL_TXQ0_OPERATION_MODE_TXQEN_MASK 3 |
| 161 | #define EQOS_MTL_TXQ0_OPERATION_MODE_TXQEN_ENABLED 2 |
| 162 | #define EQOS_MTL_TXQ0_OPERATION_MODE_TSF BIT(1) |
| 163 | #define EQOS_MTL_TXQ0_OPERATION_MODE_FTQ BIT(0) |
| 164 | |
| 165 | #define EQOS_MTL_TXQ0_DEBUG_TXQSTS BIT(4) |
| 166 | #define EQOS_MTL_TXQ0_DEBUG_TRCSTS_SHIFT 1 |
| 167 | #define EQOS_MTL_TXQ0_DEBUG_TRCSTS_MASK 3 |
| 168 | |
| 169 | #define EQOS_MTL_RXQ0_OPERATION_MODE_RQS_SHIFT 20 |
| 170 | #define EQOS_MTL_RXQ0_OPERATION_MODE_RQS_MASK 0x3ff |
| 171 | #define EQOS_MTL_RXQ0_OPERATION_MODE_RFD_SHIFT 14 |
| 172 | #define EQOS_MTL_RXQ0_OPERATION_MODE_RFD_MASK 0x3f |
| 173 | #define EQOS_MTL_RXQ0_OPERATION_MODE_RFA_SHIFT 8 |
| 174 | #define EQOS_MTL_RXQ0_OPERATION_MODE_RFA_MASK 0x3f |
| 175 | #define EQOS_MTL_RXQ0_OPERATION_MODE_EHFC BIT(7) |
| 176 | #define EQOS_MTL_RXQ0_OPERATION_MODE_RSF BIT(5) |
| 177 | |
| 178 | #define EQOS_MTL_RXQ0_DEBUG_PRXQ_SHIFT 16 |
| 179 | #define EQOS_MTL_RXQ0_DEBUG_PRXQ_MASK 0x7fff |
| 180 | #define EQOS_MTL_RXQ0_DEBUG_RXQSTS_SHIFT 4 |
| 181 | #define EQOS_MTL_RXQ0_DEBUG_RXQSTS_MASK 3 |
| 182 | |
| 183 | #define EQOS_DMA_REGS_BASE 0x1000 |
| 184 | struct eqos_dma_regs { |
| 185 | uint32_t mode; /* 0x1000 */ |
| 186 | uint32_t sysbus_mode; /* 0x1004 */ |
| 187 | uint32_t unused_1008[(0x1100 - 0x1008) / 4]; /* 0x1008 */ |
| 188 | uint32_t ch0_control; /* 0x1100 */ |
| 189 | uint32_t ch0_tx_control; /* 0x1104 */ |
| 190 | uint32_t ch0_rx_control; /* 0x1108 */ |
| 191 | uint32_t unused_110c; /* 0x110c */ |
| 192 | uint32_t ch0_txdesc_list_haddress; /* 0x1110 */ |
| 193 | uint32_t ch0_txdesc_list_address; /* 0x1114 */ |
| 194 | uint32_t ch0_rxdesc_list_haddress; /* 0x1118 */ |
| 195 | uint32_t ch0_rxdesc_list_address; /* 0x111c */ |
| 196 | uint32_t ch0_txdesc_tail_pointer; /* 0x1120 */ |
| 197 | uint32_t unused_1124; /* 0x1124 */ |
| 198 | uint32_t ch0_rxdesc_tail_pointer; /* 0x1128 */ |
| 199 | uint32_t ch0_txdesc_ring_length; /* 0x112c */ |
| 200 | uint32_t ch0_rxdesc_ring_length; /* 0x1130 */ |
| 201 | }; |
| 202 | |
| 203 | #define EQOS_DMA_MODE_SWR BIT(0) |
| 204 | |
| 205 | #define EQOS_DMA_SYSBUS_MODE_RD_OSR_LMT_SHIFT 16 |
| 206 | #define EQOS_DMA_SYSBUS_MODE_RD_OSR_LMT_MASK 0xf |
| 207 | #define EQOS_DMA_SYSBUS_MODE_EAME BIT(11) |
| 208 | #define EQOS_DMA_SYSBUS_MODE_BLEN16 BIT(3) |
| 209 | #define EQOS_DMA_SYSBUS_MODE_BLEN8 BIT(2) |
| 210 | #define EQOS_DMA_SYSBUS_MODE_BLEN4 BIT(1) |
| 211 | |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 212 | #define EQOS_DMA_CH0_CONTROL_DSL_SHIFT 18 |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 213 | #define EQOS_DMA_CH0_CONTROL_PBLX8 BIT(16) |
| 214 | |
| 215 | #define EQOS_DMA_CH0_TX_CONTROL_TXPBL_SHIFT 16 |
| 216 | #define EQOS_DMA_CH0_TX_CONTROL_TXPBL_MASK 0x3f |
| 217 | #define EQOS_DMA_CH0_TX_CONTROL_OSP BIT(4) |
| 218 | #define EQOS_DMA_CH0_TX_CONTROL_ST BIT(0) |
| 219 | |
| 220 | #define EQOS_DMA_CH0_RX_CONTROL_RXPBL_SHIFT 16 |
| 221 | #define EQOS_DMA_CH0_RX_CONTROL_RXPBL_MASK 0x3f |
| 222 | #define EQOS_DMA_CH0_RX_CONTROL_RBSZ_SHIFT 1 |
| 223 | #define EQOS_DMA_CH0_RX_CONTROL_RBSZ_MASK 0x3fff |
| 224 | #define EQOS_DMA_CH0_RX_CONTROL_SR BIT(0) |
| 225 | |
| 226 | /* These registers are Tegra186-specific */ |
| 227 | #define EQOS_TEGRA186_REGS_BASE 0x8800 |
| 228 | struct eqos_tegra186_regs { |
| 229 | uint32_t sdmemcomppadctrl; /* 0x8800 */ |
| 230 | uint32_t auto_cal_config; /* 0x8804 */ |
| 231 | uint32_t unused_8808; /* 0x8808 */ |
| 232 | uint32_t auto_cal_status; /* 0x880c */ |
| 233 | }; |
| 234 | |
| 235 | #define EQOS_SDMEMCOMPPADCTRL_PAD_E_INPUT_OR_E_PWRD BIT(31) |
| 236 | |
| 237 | #define EQOS_AUTO_CAL_CONFIG_START BIT(31) |
| 238 | #define EQOS_AUTO_CAL_CONFIG_ENABLE BIT(29) |
| 239 | |
| 240 | #define EQOS_AUTO_CAL_STATUS_ACTIVE BIT(31) |
| 241 | |
| 242 | /* Descriptors */ |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 243 | #define EQOS_DESCRIPTORS_TX 4 |
| 244 | #define EQOS_DESCRIPTORS_RX 4 |
| 245 | #define EQOS_DESCRIPTORS_NUM (EQOS_DESCRIPTORS_TX + EQOS_DESCRIPTORS_RX) |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 246 | #define EQOS_BUFFER_ALIGN ARCH_DMA_MINALIGN |
| 247 | #define EQOS_MAX_PACKET_SIZE ALIGN(1568, ARCH_DMA_MINALIGN) |
| 248 | #define EQOS_RX_BUFFER_SIZE (EQOS_DESCRIPTORS_RX * EQOS_MAX_PACKET_SIZE) |
| 249 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 250 | struct eqos_desc { |
| 251 | u32 des0; |
| 252 | u32 des1; |
| 253 | u32 des2; |
| 254 | u32 des3; |
| 255 | }; |
| 256 | |
| 257 | #define EQOS_DESC3_OWN BIT(31) |
| 258 | #define EQOS_DESC3_FD BIT(29) |
| 259 | #define EQOS_DESC3_LD BIT(28) |
| 260 | #define EQOS_DESC3_BUF1V BIT(24) |
| 261 | |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 262 | #define EQOS_AXI_WIDTH_32 4 |
| 263 | #define EQOS_AXI_WIDTH_64 8 |
| 264 | #define EQOS_AXI_WIDTH_128 16 |
| 265 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 266 | struct eqos_config { |
| 267 | bool reg_access_always_ok; |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 268 | int mdio_wait; |
| 269 | int swr_wait; |
| 270 | int config_mac; |
| 271 | int config_mac_mdio; |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 272 | unsigned int axi_bus_width; |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 273 | phy_interface_t (*interface)(struct udevice *dev); |
| 274 | struct eqos_ops *ops; |
| 275 | }; |
| 276 | |
| 277 | struct eqos_ops { |
| 278 | void (*eqos_inval_desc)(void *desc); |
| 279 | void (*eqos_flush_desc)(void *desc); |
| 280 | void (*eqos_inval_buffer)(void *buf, size_t size); |
| 281 | void (*eqos_flush_buffer)(void *buf, size_t size); |
| 282 | int (*eqos_probe_resources)(struct udevice *dev); |
| 283 | int (*eqos_remove_resources)(struct udevice *dev); |
| 284 | int (*eqos_stop_resets)(struct udevice *dev); |
| 285 | int (*eqos_start_resets)(struct udevice *dev); |
Patrick Delaunay | 1bc6ce7 | 2021-07-20 20:09:56 +0200 | [diff] [blame] | 286 | int (*eqos_stop_clks)(struct udevice *dev); |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 287 | int (*eqos_start_clks)(struct udevice *dev); |
| 288 | int (*eqos_calibrate_pads)(struct udevice *dev); |
| 289 | int (*eqos_disable_calibration)(struct udevice *dev); |
| 290 | int (*eqos_set_tx_clk_speed)(struct udevice *dev); |
| 291 | ulong (*eqos_get_tick_clk_rate)(struct udevice *dev); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 292 | }; |
| 293 | |
| 294 | struct eqos_priv { |
| 295 | struct udevice *dev; |
| 296 | const struct eqos_config *config; |
| 297 | fdt_addr_t regs; |
| 298 | struct eqos_mac_regs *mac_regs; |
| 299 | struct eqos_mtl_regs *mtl_regs; |
| 300 | struct eqos_dma_regs *dma_regs; |
| 301 | struct eqos_tegra186_regs *tegra186_regs; |
| 302 | struct reset_ctl reset_ctl; |
| 303 | struct gpio_desc phy_reset_gpio; |
| 304 | struct clk clk_master_bus; |
| 305 | struct clk clk_rx; |
| 306 | struct clk clk_ptp_ref; |
| 307 | struct clk clk_tx; |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 308 | struct clk clk_ck; |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 309 | struct clk clk_slave_bus; |
| 310 | struct mii_dev *mii; |
| 311 | struct phy_device *phy; |
Patrick Delaunay | 5c8db37 | 2020-03-18 10:50:16 +0100 | [diff] [blame] | 312 | u32 max_speed; |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 313 | void *descs; |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 314 | int tx_desc_idx, rx_desc_idx; |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 315 | unsigned int desc_size; |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 316 | void *tx_dma_buf; |
| 317 | void *rx_dma_buf; |
| 318 | void *rx_pkt; |
| 319 | bool started; |
| 320 | bool reg_access_ok; |
Daniil Stas | 8159792 | 2021-05-23 22:24:48 +0000 | [diff] [blame] | 321 | bool clk_ck_enabled; |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 322 | }; |
| 323 | |
| 324 | /* |
| 325 | * TX and RX descriptors are 16 bytes. This causes problems with the cache |
| 326 | * maintenance on CPUs where the cache-line size exceeds the size of these |
| 327 | * descriptors. What will happen is that when the driver receives a packet |
| 328 | * it will be immediately requeued for the hardware to reuse. The CPU will |
| 329 | * therefore need to flush the cache-line containing the descriptor, which |
| 330 | * will cause all other descriptors in the same cache-line to be flushed |
| 331 | * along with it. If one of those descriptors had been written to by the |
| 332 | * device those changes (and the associated packet) will be lost. |
| 333 | * |
| 334 | * To work around this, we make use of non-cached memory if available. If |
| 335 | * descriptors are mapped uncached there's no need to manually flush them |
| 336 | * or invalidate them. |
| 337 | * |
| 338 | * Note that this only applies to descriptors. The packet data buffers do |
| 339 | * not have the same constraints since they are 1536 bytes large, so they |
| 340 | * are unlikely to share cache-lines. |
| 341 | */ |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 342 | static void *eqos_alloc_descs(struct eqos_priv *eqos, unsigned int num) |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 343 | { |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 344 | eqos->desc_size = ALIGN(sizeof(struct eqos_desc), |
| 345 | (unsigned int)ARCH_DMA_MINALIGN); |
| 346 | |
| 347 | return memalign(eqos->desc_size, num * eqos->desc_size); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | static void eqos_free_descs(void *descs) |
| 351 | { |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 352 | free(descs); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 353 | } |
| 354 | |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 355 | static struct eqos_desc *eqos_get_desc(struct eqos_priv *eqos, |
| 356 | unsigned int num, bool rx) |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 357 | { |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 358 | return eqos->descs + |
| 359 | ((rx ? EQOS_DESCRIPTORS_TX : 0) + num) * eqos->desc_size; |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 360 | } |
| 361 | |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 362 | static void eqos_inval_desc_generic(void *desc) |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 363 | { |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 364 | unsigned long start = (unsigned long)desc; |
| 365 | unsigned long end = ALIGN(start + sizeof(struct eqos_desc), |
| 366 | ARCH_DMA_MINALIGN); |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 367 | |
| 368 | invalidate_dcache_range(start, end); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 369 | } |
| 370 | |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 371 | static void eqos_flush_desc_generic(void *desc) |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 372 | { |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 373 | unsigned long start = (unsigned long)desc; |
| 374 | unsigned long end = ALIGN(start + sizeof(struct eqos_desc), |
| 375 | ARCH_DMA_MINALIGN); |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 376 | |
| 377 | flush_dcache_range(start, end); |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | static void eqos_inval_buffer_tegra186(void *buf, size_t size) |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 381 | { |
| 382 | unsigned long start = (unsigned long)buf & ~(ARCH_DMA_MINALIGN - 1); |
| 383 | unsigned long end = ALIGN(start + size, ARCH_DMA_MINALIGN); |
| 384 | |
| 385 | invalidate_dcache_range(start, end); |
| 386 | } |
| 387 | |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 388 | static void eqos_inval_buffer_generic(void *buf, size_t size) |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 389 | { |
| 390 | unsigned long start = rounddown((unsigned long)buf, ARCH_DMA_MINALIGN); |
| 391 | unsigned long end = roundup((unsigned long)buf + size, |
| 392 | ARCH_DMA_MINALIGN); |
| 393 | |
| 394 | invalidate_dcache_range(start, end); |
| 395 | } |
| 396 | |
| 397 | static void eqos_flush_buffer_tegra186(void *buf, size_t size) |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 398 | { |
| 399 | flush_cache((unsigned long)buf, size); |
| 400 | } |
| 401 | |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 402 | static void eqos_flush_buffer_generic(void *buf, size_t size) |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 403 | { |
| 404 | unsigned long start = rounddown((unsigned long)buf, ARCH_DMA_MINALIGN); |
| 405 | unsigned long end = roundup((unsigned long)buf + size, |
| 406 | ARCH_DMA_MINALIGN); |
| 407 | |
| 408 | flush_dcache_range(start, end); |
| 409 | } |
| 410 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 411 | static int eqos_mdio_wait_idle(struct eqos_priv *eqos) |
| 412 | { |
Álvaro Fernández Rojas | 918de03 | 2018-01-23 17:14:55 +0100 | [diff] [blame] | 413 | return wait_for_bit_le32(&eqos->mac_regs->mdio_address, |
| 414 | EQOS_MAC_MDIO_ADDRESS_GB, false, |
| 415 | 1000000, true); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | static int eqos_mdio_read(struct mii_dev *bus, int mdio_addr, int mdio_devad, |
| 419 | int mdio_reg) |
| 420 | { |
| 421 | struct eqos_priv *eqos = bus->priv; |
| 422 | u32 val; |
| 423 | int ret; |
| 424 | |
| 425 | debug("%s(dev=%p, addr=%x, reg=%d):\n", __func__, eqos->dev, mdio_addr, |
| 426 | mdio_reg); |
| 427 | |
| 428 | ret = eqos_mdio_wait_idle(eqos); |
| 429 | if (ret) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 430 | pr_err("MDIO not idle at entry"); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 431 | return ret; |
| 432 | } |
| 433 | |
| 434 | val = readl(&eqos->mac_regs->mdio_address); |
| 435 | val &= EQOS_MAC_MDIO_ADDRESS_SKAP | |
| 436 | EQOS_MAC_MDIO_ADDRESS_C45E; |
| 437 | val |= (mdio_addr << EQOS_MAC_MDIO_ADDRESS_PA_SHIFT) | |
| 438 | (mdio_reg << EQOS_MAC_MDIO_ADDRESS_RDA_SHIFT) | |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 439 | (eqos->config->config_mac_mdio << |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 440 | EQOS_MAC_MDIO_ADDRESS_CR_SHIFT) | |
| 441 | (EQOS_MAC_MDIO_ADDRESS_GOC_READ << |
| 442 | EQOS_MAC_MDIO_ADDRESS_GOC_SHIFT) | |
| 443 | EQOS_MAC_MDIO_ADDRESS_GB; |
| 444 | writel(val, &eqos->mac_regs->mdio_address); |
| 445 | |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 446 | udelay(eqos->config->mdio_wait); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 447 | |
| 448 | ret = eqos_mdio_wait_idle(eqos); |
| 449 | if (ret) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 450 | pr_err("MDIO read didn't complete"); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 451 | return ret; |
| 452 | } |
| 453 | |
| 454 | val = readl(&eqos->mac_regs->mdio_data); |
| 455 | val &= EQOS_MAC_MDIO_DATA_GD_MASK; |
| 456 | |
| 457 | debug("%s: val=%x\n", __func__, val); |
| 458 | |
| 459 | return val; |
| 460 | } |
| 461 | |
| 462 | static int eqos_mdio_write(struct mii_dev *bus, int mdio_addr, int mdio_devad, |
| 463 | int mdio_reg, u16 mdio_val) |
| 464 | { |
| 465 | struct eqos_priv *eqos = bus->priv; |
| 466 | u32 val; |
| 467 | int ret; |
| 468 | |
| 469 | debug("%s(dev=%p, addr=%x, reg=%d, val=%x):\n", __func__, eqos->dev, |
| 470 | mdio_addr, mdio_reg, mdio_val); |
| 471 | |
| 472 | ret = eqos_mdio_wait_idle(eqos); |
| 473 | if (ret) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 474 | pr_err("MDIO not idle at entry"); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 475 | return ret; |
| 476 | } |
| 477 | |
| 478 | writel(mdio_val, &eqos->mac_regs->mdio_data); |
| 479 | |
| 480 | val = readl(&eqos->mac_regs->mdio_address); |
| 481 | val &= EQOS_MAC_MDIO_ADDRESS_SKAP | |
| 482 | EQOS_MAC_MDIO_ADDRESS_C45E; |
| 483 | val |= (mdio_addr << EQOS_MAC_MDIO_ADDRESS_PA_SHIFT) | |
| 484 | (mdio_reg << EQOS_MAC_MDIO_ADDRESS_RDA_SHIFT) | |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 485 | (eqos->config->config_mac_mdio << |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 486 | EQOS_MAC_MDIO_ADDRESS_CR_SHIFT) | |
| 487 | (EQOS_MAC_MDIO_ADDRESS_GOC_WRITE << |
| 488 | EQOS_MAC_MDIO_ADDRESS_GOC_SHIFT) | |
| 489 | EQOS_MAC_MDIO_ADDRESS_GB; |
| 490 | writel(val, &eqos->mac_regs->mdio_address); |
| 491 | |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 492 | udelay(eqos->config->mdio_wait); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 493 | |
| 494 | ret = eqos_mdio_wait_idle(eqos); |
| 495 | if (ret) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 496 | pr_err("MDIO read didn't complete"); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 497 | return ret; |
| 498 | } |
| 499 | |
| 500 | return 0; |
| 501 | } |
| 502 | |
| 503 | static int eqos_start_clks_tegra186(struct udevice *dev) |
| 504 | { |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 505 | #ifdef CONFIG_CLK |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 506 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 507 | int ret; |
| 508 | |
| 509 | debug("%s(dev=%p):\n", __func__, dev); |
| 510 | |
| 511 | ret = clk_enable(&eqos->clk_slave_bus); |
| 512 | if (ret < 0) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 513 | pr_err("clk_enable(clk_slave_bus) failed: %d", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 514 | goto err; |
| 515 | } |
| 516 | |
| 517 | ret = clk_enable(&eqos->clk_master_bus); |
| 518 | if (ret < 0) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 519 | pr_err("clk_enable(clk_master_bus) failed: %d", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 520 | goto err_disable_clk_slave_bus; |
| 521 | } |
| 522 | |
| 523 | ret = clk_enable(&eqos->clk_rx); |
| 524 | if (ret < 0) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 525 | pr_err("clk_enable(clk_rx) failed: %d", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 526 | goto err_disable_clk_master_bus; |
| 527 | } |
| 528 | |
| 529 | ret = clk_enable(&eqos->clk_ptp_ref); |
| 530 | if (ret < 0) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 531 | pr_err("clk_enable(clk_ptp_ref) failed: %d", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 532 | goto err_disable_clk_rx; |
| 533 | } |
| 534 | |
| 535 | ret = clk_set_rate(&eqos->clk_ptp_ref, 125 * 1000 * 1000); |
| 536 | if (ret < 0) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 537 | pr_err("clk_set_rate(clk_ptp_ref) failed: %d", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 538 | goto err_disable_clk_ptp_ref; |
| 539 | } |
| 540 | |
| 541 | ret = clk_enable(&eqos->clk_tx); |
| 542 | if (ret < 0) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 543 | pr_err("clk_enable(clk_tx) failed: %d", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 544 | goto err_disable_clk_ptp_ref; |
| 545 | } |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 546 | #endif |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 547 | |
| 548 | debug("%s: OK\n", __func__); |
| 549 | return 0; |
| 550 | |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 551 | #ifdef CONFIG_CLK |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 552 | err_disable_clk_ptp_ref: |
| 553 | clk_disable(&eqos->clk_ptp_ref); |
| 554 | err_disable_clk_rx: |
| 555 | clk_disable(&eqos->clk_rx); |
| 556 | err_disable_clk_master_bus: |
| 557 | clk_disable(&eqos->clk_master_bus); |
| 558 | err_disable_clk_slave_bus: |
| 559 | clk_disable(&eqos->clk_slave_bus); |
| 560 | err: |
| 561 | debug("%s: FAILED: %d\n", __func__, ret); |
| 562 | return ret; |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 563 | #endif |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 564 | } |
| 565 | |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 566 | static int eqos_start_clks_stm32(struct udevice *dev) |
| 567 | { |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 568 | #ifdef CONFIG_CLK |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 569 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 570 | int ret; |
| 571 | |
| 572 | debug("%s(dev=%p):\n", __func__, dev); |
| 573 | |
| 574 | ret = clk_enable(&eqos->clk_master_bus); |
| 575 | if (ret < 0) { |
| 576 | pr_err("clk_enable(clk_master_bus) failed: %d", ret); |
| 577 | goto err; |
| 578 | } |
| 579 | |
| 580 | ret = clk_enable(&eqos->clk_rx); |
| 581 | if (ret < 0) { |
| 582 | pr_err("clk_enable(clk_rx) failed: %d", ret); |
| 583 | goto err_disable_clk_master_bus; |
| 584 | } |
| 585 | |
| 586 | ret = clk_enable(&eqos->clk_tx); |
| 587 | if (ret < 0) { |
| 588 | pr_err("clk_enable(clk_tx) failed: %d", ret); |
| 589 | goto err_disable_clk_rx; |
| 590 | } |
| 591 | |
Daniil Stas | 8159792 | 2021-05-23 22:24:48 +0000 | [diff] [blame] | 592 | if (clk_valid(&eqos->clk_ck) && !eqos->clk_ck_enabled) { |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 593 | ret = clk_enable(&eqos->clk_ck); |
| 594 | if (ret < 0) { |
| 595 | pr_err("clk_enable(clk_ck) failed: %d", ret); |
| 596 | goto err_disable_clk_tx; |
| 597 | } |
Daniil Stas | 8159792 | 2021-05-23 22:24:48 +0000 | [diff] [blame] | 598 | eqos->clk_ck_enabled = true; |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 599 | } |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 600 | #endif |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 601 | |
| 602 | debug("%s: OK\n", __func__); |
| 603 | return 0; |
| 604 | |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 605 | #ifdef CONFIG_CLK |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 606 | err_disable_clk_tx: |
| 607 | clk_disable(&eqos->clk_tx); |
| 608 | err_disable_clk_rx: |
| 609 | clk_disable(&eqos->clk_rx); |
| 610 | err_disable_clk_master_bus: |
| 611 | clk_disable(&eqos->clk_master_bus); |
| 612 | err: |
| 613 | debug("%s: FAILED: %d\n", __func__, ret); |
| 614 | return ret; |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 615 | #endif |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 616 | } |
| 617 | |
Patrick Delaunay | 1bc6ce7 | 2021-07-20 20:09:56 +0200 | [diff] [blame] | 618 | static int eqos_stop_clks_tegra186(struct udevice *dev) |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 619 | { |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 620 | #ifdef CONFIG_CLK |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 621 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 622 | |
| 623 | debug("%s(dev=%p):\n", __func__, dev); |
| 624 | |
| 625 | clk_disable(&eqos->clk_tx); |
| 626 | clk_disable(&eqos->clk_ptp_ref); |
| 627 | clk_disable(&eqos->clk_rx); |
| 628 | clk_disable(&eqos->clk_master_bus); |
| 629 | clk_disable(&eqos->clk_slave_bus); |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 630 | #endif |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 631 | |
| 632 | debug("%s: OK\n", __func__); |
Patrick Delaunay | 1bc6ce7 | 2021-07-20 20:09:56 +0200 | [diff] [blame] | 633 | return 0; |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 634 | } |
| 635 | |
Patrick Delaunay | 1bc6ce7 | 2021-07-20 20:09:56 +0200 | [diff] [blame] | 636 | static int eqos_stop_clks_stm32(struct udevice *dev) |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 637 | { |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 638 | #ifdef CONFIG_CLK |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 639 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 640 | |
| 641 | debug("%s(dev=%p):\n", __func__, dev); |
| 642 | |
| 643 | clk_disable(&eqos->clk_tx); |
| 644 | clk_disable(&eqos->clk_rx); |
| 645 | clk_disable(&eqos->clk_master_bus); |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 646 | #endif |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 647 | |
| 648 | debug("%s: OK\n", __func__); |
Patrick Delaunay | 1bc6ce7 | 2021-07-20 20:09:56 +0200 | [diff] [blame] | 649 | return 0; |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 650 | } |
| 651 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 652 | static int eqos_start_resets_tegra186(struct udevice *dev) |
| 653 | { |
| 654 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 655 | int ret; |
| 656 | |
| 657 | debug("%s(dev=%p):\n", __func__, dev); |
| 658 | |
| 659 | ret = dm_gpio_set_value(&eqos->phy_reset_gpio, 1); |
| 660 | if (ret < 0) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 661 | pr_err("dm_gpio_set_value(phy_reset, assert) failed: %d", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 662 | return ret; |
| 663 | } |
| 664 | |
| 665 | udelay(2); |
| 666 | |
| 667 | ret = dm_gpio_set_value(&eqos->phy_reset_gpio, 0); |
| 668 | if (ret < 0) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 669 | pr_err("dm_gpio_set_value(phy_reset, deassert) failed: %d", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 670 | return ret; |
| 671 | } |
| 672 | |
| 673 | ret = reset_assert(&eqos->reset_ctl); |
| 674 | if (ret < 0) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 675 | pr_err("reset_assert() failed: %d", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 676 | return ret; |
| 677 | } |
| 678 | |
| 679 | udelay(2); |
| 680 | |
| 681 | ret = reset_deassert(&eqos->reset_ctl); |
| 682 | if (ret < 0) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 683 | pr_err("reset_deassert() failed: %d", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 684 | return ret; |
| 685 | } |
| 686 | |
| 687 | debug("%s: OK\n", __func__); |
| 688 | return 0; |
| 689 | } |
| 690 | |
| 691 | static int eqos_stop_resets_tegra186(struct udevice *dev) |
| 692 | { |
| 693 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 694 | |
| 695 | reset_assert(&eqos->reset_ctl); |
| 696 | dm_gpio_set_value(&eqos->phy_reset_gpio, 1); |
| 697 | |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 698 | return 0; |
| 699 | } |
| 700 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 701 | static int eqos_calibrate_pads_tegra186(struct udevice *dev) |
| 702 | { |
| 703 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 704 | int ret; |
| 705 | |
| 706 | debug("%s(dev=%p):\n", __func__, dev); |
| 707 | |
| 708 | setbits_le32(&eqos->tegra186_regs->sdmemcomppadctrl, |
| 709 | EQOS_SDMEMCOMPPADCTRL_PAD_E_INPUT_OR_E_PWRD); |
| 710 | |
| 711 | udelay(1); |
| 712 | |
| 713 | setbits_le32(&eqos->tegra186_regs->auto_cal_config, |
| 714 | EQOS_AUTO_CAL_CONFIG_START | EQOS_AUTO_CAL_CONFIG_ENABLE); |
| 715 | |
Álvaro Fernández Rojas | 918de03 | 2018-01-23 17:14:55 +0100 | [diff] [blame] | 716 | ret = wait_for_bit_le32(&eqos->tegra186_regs->auto_cal_status, |
| 717 | EQOS_AUTO_CAL_STATUS_ACTIVE, true, 10, false); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 718 | if (ret) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 719 | pr_err("calibrate didn't start"); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 720 | goto failed; |
| 721 | } |
| 722 | |
Álvaro Fernández Rojas | 918de03 | 2018-01-23 17:14:55 +0100 | [diff] [blame] | 723 | ret = wait_for_bit_le32(&eqos->tegra186_regs->auto_cal_status, |
| 724 | EQOS_AUTO_CAL_STATUS_ACTIVE, false, 10, false); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 725 | if (ret) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 726 | pr_err("calibrate didn't finish"); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 727 | goto failed; |
| 728 | } |
| 729 | |
| 730 | ret = 0; |
| 731 | |
| 732 | failed: |
| 733 | clrbits_le32(&eqos->tegra186_regs->sdmemcomppadctrl, |
| 734 | EQOS_SDMEMCOMPPADCTRL_PAD_E_INPUT_OR_E_PWRD); |
| 735 | |
| 736 | debug("%s: returns %d\n", __func__, ret); |
| 737 | |
| 738 | return ret; |
| 739 | } |
| 740 | |
| 741 | static int eqos_disable_calibration_tegra186(struct udevice *dev) |
| 742 | { |
| 743 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 744 | |
| 745 | debug("%s(dev=%p):\n", __func__, dev); |
| 746 | |
| 747 | clrbits_le32(&eqos->tegra186_regs->auto_cal_config, |
| 748 | EQOS_AUTO_CAL_CONFIG_ENABLE); |
| 749 | |
| 750 | return 0; |
| 751 | } |
| 752 | |
| 753 | static ulong eqos_get_tick_clk_rate_tegra186(struct udevice *dev) |
| 754 | { |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 755 | #ifdef CONFIG_CLK |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 756 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 757 | |
| 758 | return clk_get_rate(&eqos->clk_slave_bus); |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 759 | #else |
| 760 | return 0; |
| 761 | #endif |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 762 | } |
| 763 | |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 764 | static ulong eqos_get_tick_clk_rate_stm32(struct udevice *dev) |
| 765 | { |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 766 | #ifdef CONFIG_CLK |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 767 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 768 | |
| 769 | return clk_get_rate(&eqos->clk_master_bus); |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 770 | #else |
| 771 | return 0; |
| 772 | #endif |
| 773 | } |
| 774 | |
Fugang Duan | dd455e6 | 2020-05-03 22:41:18 +0800 | [diff] [blame] | 775 | __weak u32 imx_get_eqos_csr_clk(void) |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 776 | { |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 777 | return 100 * 1000000; |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 778 | } |
Fugang Duan | dd455e6 | 2020-05-03 22:41:18 +0800 | [diff] [blame] | 779 | __weak int imx_eqos_txclk_set_rate(unsigned long rate) |
| 780 | { |
| 781 | return 0; |
| 782 | } |
| 783 | |
| 784 | static ulong eqos_get_tick_clk_rate_imx(struct udevice *dev) |
| 785 | { |
| 786 | return imx_get_eqos_csr_clk(); |
| 787 | } |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 788 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 789 | static int eqos_set_full_duplex(struct udevice *dev) |
| 790 | { |
| 791 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 792 | |
| 793 | debug("%s(dev=%p):\n", __func__, dev); |
| 794 | |
| 795 | setbits_le32(&eqos->mac_regs->configuration, EQOS_MAC_CONFIGURATION_DM); |
| 796 | |
| 797 | return 0; |
| 798 | } |
| 799 | |
| 800 | static int eqos_set_half_duplex(struct udevice *dev) |
| 801 | { |
| 802 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 803 | |
| 804 | debug("%s(dev=%p):\n", __func__, dev); |
| 805 | |
| 806 | clrbits_le32(&eqos->mac_regs->configuration, EQOS_MAC_CONFIGURATION_DM); |
| 807 | |
| 808 | /* WAR: Flush TX queue when switching to half-duplex */ |
| 809 | setbits_le32(&eqos->mtl_regs->txq0_operation_mode, |
| 810 | EQOS_MTL_TXQ0_OPERATION_MODE_FTQ); |
| 811 | |
| 812 | return 0; |
| 813 | } |
| 814 | |
| 815 | static int eqos_set_gmii_speed(struct udevice *dev) |
| 816 | { |
| 817 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 818 | |
| 819 | debug("%s(dev=%p):\n", __func__, dev); |
| 820 | |
| 821 | clrbits_le32(&eqos->mac_regs->configuration, |
| 822 | EQOS_MAC_CONFIGURATION_PS | EQOS_MAC_CONFIGURATION_FES); |
| 823 | |
| 824 | return 0; |
| 825 | } |
| 826 | |
| 827 | static int eqos_set_mii_speed_100(struct udevice *dev) |
| 828 | { |
| 829 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 830 | |
| 831 | debug("%s(dev=%p):\n", __func__, dev); |
| 832 | |
| 833 | setbits_le32(&eqos->mac_regs->configuration, |
| 834 | EQOS_MAC_CONFIGURATION_PS | EQOS_MAC_CONFIGURATION_FES); |
| 835 | |
| 836 | return 0; |
| 837 | } |
| 838 | |
| 839 | static int eqos_set_mii_speed_10(struct udevice *dev) |
| 840 | { |
| 841 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 842 | |
| 843 | debug("%s(dev=%p):\n", __func__, dev); |
| 844 | |
| 845 | clrsetbits_le32(&eqos->mac_regs->configuration, |
| 846 | EQOS_MAC_CONFIGURATION_FES, EQOS_MAC_CONFIGURATION_PS); |
| 847 | |
| 848 | return 0; |
| 849 | } |
| 850 | |
| 851 | static int eqos_set_tx_clk_speed_tegra186(struct udevice *dev) |
| 852 | { |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 853 | #ifdef CONFIG_CLK |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 854 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 855 | ulong rate; |
| 856 | int ret; |
| 857 | |
| 858 | debug("%s(dev=%p):\n", __func__, dev); |
| 859 | |
| 860 | switch (eqos->phy->speed) { |
| 861 | case SPEED_1000: |
| 862 | rate = 125 * 1000 * 1000; |
| 863 | break; |
| 864 | case SPEED_100: |
| 865 | rate = 25 * 1000 * 1000; |
| 866 | break; |
| 867 | case SPEED_10: |
| 868 | rate = 2.5 * 1000 * 1000; |
| 869 | break; |
| 870 | default: |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 871 | pr_err("invalid speed %d", eqos->phy->speed); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 872 | return -EINVAL; |
| 873 | } |
| 874 | |
| 875 | ret = clk_set_rate(&eqos->clk_tx, rate); |
| 876 | if (ret < 0) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 877 | pr_err("clk_set_rate(tx_clk, %lu) failed: %d", rate, ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 878 | return ret; |
| 879 | } |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 880 | #endif |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 881 | |
| 882 | return 0; |
| 883 | } |
| 884 | |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 885 | static int eqos_set_tx_clk_speed_imx(struct udevice *dev) |
| 886 | { |
Fugang Duan | dd455e6 | 2020-05-03 22:41:18 +0800 | [diff] [blame] | 887 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 888 | ulong rate; |
| 889 | int ret; |
| 890 | |
| 891 | debug("%s(dev=%p):\n", __func__, dev); |
| 892 | |
| 893 | switch (eqos->phy->speed) { |
| 894 | case SPEED_1000: |
| 895 | rate = 125 * 1000 * 1000; |
| 896 | break; |
| 897 | case SPEED_100: |
| 898 | rate = 25 * 1000 * 1000; |
| 899 | break; |
| 900 | case SPEED_10: |
| 901 | rate = 2.5 * 1000 * 1000; |
| 902 | break; |
| 903 | default: |
| 904 | pr_err("invalid speed %d", eqos->phy->speed); |
| 905 | return -EINVAL; |
| 906 | } |
| 907 | |
| 908 | ret = imx_eqos_txclk_set_rate(rate); |
| 909 | if (ret < 0) { |
| 910 | pr_err("imx (tx_clk, %lu) failed: %d", rate, ret); |
| 911 | return ret; |
| 912 | } |
| 913 | |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 914 | return 0; |
| 915 | } |
| 916 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 917 | static int eqos_adjust_link(struct udevice *dev) |
| 918 | { |
| 919 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 920 | int ret; |
| 921 | bool en_calibration; |
| 922 | |
| 923 | debug("%s(dev=%p):\n", __func__, dev); |
| 924 | |
| 925 | if (eqos->phy->duplex) |
| 926 | ret = eqos_set_full_duplex(dev); |
| 927 | else |
| 928 | ret = eqos_set_half_duplex(dev); |
| 929 | if (ret < 0) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 930 | pr_err("eqos_set_*_duplex() failed: %d", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 931 | return ret; |
| 932 | } |
| 933 | |
| 934 | switch (eqos->phy->speed) { |
| 935 | case SPEED_1000: |
| 936 | en_calibration = true; |
| 937 | ret = eqos_set_gmii_speed(dev); |
| 938 | break; |
| 939 | case SPEED_100: |
| 940 | en_calibration = true; |
| 941 | ret = eqos_set_mii_speed_100(dev); |
| 942 | break; |
| 943 | case SPEED_10: |
| 944 | en_calibration = false; |
| 945 | ret = eqos_set_mii_speed_10(dev); |
| 946 | break; |
| 947 | default: |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 948 | pr_err("invalid speed %d", eqos->phy->speed); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 949 | return -EINVAL; |
| 950 | } |
| 951 | if (ret < 0) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 952 | pr_err("eqos_set_*mii_speed*() failed: %d", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 953 | return ret; |
| 954 | } |
| 955 | |
| 956 | if (en_calibration) { |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 957 | ret = eqos->config->ops->eqos_calibrate_pads(dev); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 958 | if (ret < 0) { |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 959 | pr_err("eqos_calibrate_pads() failed: %d", |
| 960 | ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 961 | return ret; |
| 962 | } |
| 963 | } else { |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 964 | ret = eqos->config->ops->eqos_disable_calibration(dev); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 965 | if (ret < 0) { |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 966 | pr_err("eqos_disable_calibration() failed: %d", |
| 967 | ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 968 | return ret; |
| 969 | } |
| 970 | } |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 971 | ret = eqos->config->ops->eqos_set_tx_clk_speed(dev); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 972 | if (ret < 0) { |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 973 | pr_err("eqos_set_tx_clk_speed() failed: %d", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 974 | return ret; |
| 975 | } |
| 976 | |
| 977 | return 0; |
| 978 | } |
| 979 | |
| 980 | static int eqos_write_hwaddr(struct udevice *dev) |
| 981 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 982 | struct eth_pdata *plat = dev_get_plat(dev); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 983 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 984 | uint32_t val; |
| 985 | |
| 986 | /* |
| 987 | * This function may be called before start() or after stop(). At that |
| 988 | * time, on at least some configurations of the EQoS HW, all clocks to |
| 989 | * the EQoS HW block will be stopped, and a reset signal applied. If |
| 990 | * any register access is attempted in this state, bus timeouts or CPU |
| 991 | * hangs may occur. This check prevents that. |
| 992 | * |
| 993 | * A simple solution to this problem would be to not implement |
| 994 | * write_hwaddr(), since start() always writes the MAC address into HW |
| 995 | * anyway. However, it is desirable to implement write_hwaddr() to |
| 996 | * support the case of SW that runs subsequent to U-Boot which expects |
| 997 | * the MAC address to already be programmed into the EQoS registers, |
| 998 | * which must happen irrespective of whether the U-Boot user (or |
| 999 | * scripts) actually made use of the EQoS device, and hence |
| 1000 | * irrespective of whether start() was ever called. |
| 1001 | * |
| 1002 | * Note that this requirement by subsequent SW is not valid for |
| 1003 | * Tegra186, and is likely not valid for any non-PCI instantiation of |
| 1004 | * the EQoS HW block. This function is implemented solely as |
| 1005 | * future-proofing with the expectation the driver will eventually be |
| 1006 | * ported to some system where the expectation above is true. |
| 1007 | */ |
| 1008 | if (!eqos->config->reg_access_always_ok && !eqos->reg_access_ok) |
| 1009 | return 0; |
| 1010 | |
| 1011 | /* Update the MAC address */ |
| 1012 | val = (plat->enetaddr[5] << 8) | |
| 1013 | (plat->enetaddr[4]); |
| 1014 | writel(val, &eqos->mac_regs->address0_high); |
| 1015 | val = (plat->enetaddr[3] << 24) | |
| 1016 | (plat->enetaddr[2] << 16) | |
| 1017 | (plat->enetaddr[1] << 8) | |
| 1018 | (plat->enetaddr[0]); |
| 1019 | writel(val, &eqos->mac_regs->address0_low); |
| 1020 | |
| 1021 | return 0; |
| 1022 | } |
| 1023 | |
Ye Li | 3fb1a0e | 2020-05-03 22:41:20 +0800 | [diff] [blame] | 1024 | static int eqos_read_rom_hwaddr(struct udevice *dev) |
| 1025 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 1026 | struct eth_pdata *pdata = dev_get_plat(dev); |
Ye Li | 3fb1a0e | 2020-05-03 22:41:20 +0800 | [diff] [blame] | 1027 | |
| 1028 | #ifdef CONFIG_ARCH_IMX8M |
Simon Glass | 3e14a22 | 2020-12-16 21:20:16 -0700 | [diff] [blame] | 1029 | imx_get_mac_from_fuse(dev_seq(dev), pdata->enetaddr); |
Ye Li | 3fb1a0e | 2020-05-03 22:41:20 +0800 | [diff] [blame] | 1030 | #endif |
| 1031 | return !is_valid_ethaddr(pdata->enetaddr); |
| 1032 | } |
| 1033 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1034 | static int eqos_start(struct udevice *dev) |
| 1035 | { |
| 1036 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1037 | int ret, i; |
| 1038 | ulong rate; |
| 1039 | u32 val, tx_fifo_sz, rx_fifo_sz, tqs, rqs, pbl; |
| 1040 | ulong last_rx_desc; |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 1041 | ulong desc_pad; |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1042 | |
| 1043 | debug("%s(dev=%p):\n", __func__, dev); |
| 1044 | |
| 1045 | eqos->tx_desc_idx = 0; |
| 1046 | eqos->rx_desc_idx = 0; |
| 1047 | |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1048 | ret = eqos->config->ops->eqos_start_resets(dev); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1049 | if (ret < 0) { |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1050 | pr_err("eqos_start_resets() failed: %d", ret); |
Marek Vasut | 30b28c4 | 2021-11-13 03:23:52 +0100 | [diff] [blame] | 1051 | goto err; |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1052 | } |
| 1053 | |
| 1054 | udelay(10); |
| 1055 | |
| 1056 | eqos->reg_access_ok = true; |
| 1057 | |
Álvaro Fernández Rojas | 918de03 | 2018-01-23 17:14:55 +0100 | [diff] [blame] | 1058 | ret = wait_for_bit_le32(&eqos->dma_regs->mode, |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1059 | EQOS_DMA_MODE_SWR, false, |
| 1060 | eqos->config->swr_wait, false); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1061 | if (ret) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1062 | pr_err("EQOS_DMA_MODE_SWR stuck"); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1063 | goto err_stop_resets; |
| 1064 | } |
| 1065 | |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1066 | ret = eqos->config->ops->eqos_calibrate_pads(dev); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1067 | if (ret < 0) { |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1068 | pr_err("eqos_calibrate_pads() failed: %d", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1069 | goto err_stop_resets; |
| 1070 | } |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1071 | rate = eqos->config->ops->eqos_get_tick_clk_rate(dev); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1072 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1073 | val = (rate / 1000000) - 1; |
| 1074 | writel(val, &eqos->mac_regs->us_tic_counter); |
| 1075 | |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1076 | /* |
| 1077 | * if PHY was already connected and configured, |
| 1078 | * don't need to reconnect/reconfigure again |
| 1079 | */ |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1080 | if (!eqos->phy) { |
Ye Li | ad122b7 | 2020-05-03 22:41:15 +0800 | [diff] [blame] | 1081 | int addr = -1; |
| 1082 | #ifdef CONFIG_DM_ETH_PHY |
| 1083 | addr = eth_phy_get_addr(dev); |
| 1084 | #endif |
| 1085 | #ifdef DWC_NET_PHYADDR |
| 1086 | addr = DWC_NET_PHYADDR; |
| 1087 | #endif |
| 1088 | eqos->phy = phy_connect(eqos->mii, addr, dev, |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1089 | eqos->config->interface(dev)); |
| 1090 | if (!eqos->phy) { |
| 1091 | pr_err("phy_connect() failed"); |
| 1092 | goto err_stop_resets; |
| 1093 | } |
Patrick Delaunay | 5c8db37 | 2020-03-18 10:50:16 +0100 | [diff] [blame] | 1094 | |
| 1095 | if (eqos->max_speed) { |
| 1096 | ret = phy_set_supported(eqos->phy, eqos->max_speed); |
| 1097 | if (ret) { |
| 1098 | pr_err("phy_set_supported() failed: %d", ret); |
| 1099 | goto err_shutdown_phy; |
| 1100 | } |
| 1101 | } |
| 1102 | |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1103 | ret = phy_config(eqos->phy); |
| 1104 | if (ret < 0) { |
| 1105 | pr_err("phy_config() failed: %d", ret); |
| 1106 | goto err_shutdown_phy; |
| 1107 | } |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1108 | } |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1109 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1110 | ret = phy_startup(eqos->phy); |
| 1111 | if (ret < 0) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1112 | pr_err("phy_startup() failed: %d", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1113 | goto err_shutdown_phy; |
| 1114 | } |
| 1115 | |
| 1116 | if (!eqos->phy->link) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1117 | pr_err("No link"); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1118 | goto err_shutdown_phy; |
| 1119 | } |
| 1120 | |
| 1121 | ret = eqos_adjust_link(dev); |
| 1122 | if (ret < 0) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1123 | pr_err("eqos_adjust_link() failed: %d", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1124 | goto err_shutdown_phy; |
| 1125 | } |
| 1126 | |
| 1127 | /* Configure MTL */ |
| 1128 | |
| 1129 | /* Enable Store and Forward mode for TX */ |
| 1130 | /* Program Tx operating mode */ |
| 1131 | setbits_le32(&eqos->mtl_regs->txq0_operation_mode, |
| 1132 | EQOS_MTL_TXQ0_OPERATION_MODE_TSF | |
| 1133 | (EQOS_MTL_TXQ0_OPERATION_MODE_TXQEN_ENABLED << |
| 1134 | EQOS_MTL_TXQ0_OPERATION_MODE_TXQEN_SHIFT)); |
| 1135 | |
| 1136 | /* Transmit Queue weight */ |
| 1137 | writel(0x10, &eqos->mtl_regs->txq0_quantum_weight); |
| 1138 | |
| 1139 | /* Enable Store and Forward mode for RX, since no jumbo frame */ |
| 1140 | setbits_le32(&eqos->mtl_regs->rxq0_operation_mode, |
Daniil Stas | 470c06c | 2021-05-30 13:34:09 +0000 | [diff] [blame] | 1141 | EQOS_MTL_RXQ0_OPERATION_MODE_RSF); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1142 | |
| 1143 | /* Transmit/Receive queue fifo size; use all RAM for 1 queue */ |
| 1144 | val = readl(&eqos->mac_regs->hw_feature1); |
| 1145 | tx_fifo_sz = (val >> EQOS_MAC_HW_FEATURE1_TXFIFOSIZE_SHIFT) & |
| 1146 | EQOS_MAC_HW_FEATURE1_TXFIFOSIZE_MASK; |
| 1147 | rx_fifo_sz = (val >> EQOS_MAC_HW_FEATURE1_RXFIFOSIZE_SHIFT) & |
| 1148 | EQOS_MAC_HW_FEATURE1_RXFIFOSIZE_MASK; |
| 1149 | |
| 1150 | /* |
| 1151 | * r/tx_fifo_sz is encoded as log2(n / 128). Undo that by shifting. |
| 1152 | * r/tqs is encoded as (n / 256) - 1. |
| 1153 | */ |
| 1154 | tqs = (128 << tx_fifo_sz) / 256 - 1; |
| 1155 | rqs = (128 << rx_fifo_sz) / 256 - 1; |
| 1156 | |
| 1157 | clrsetbits_le32(&eqos->mtl_regs->txq0_operation_mode, |
| 1158 | EQOS_MTL_TXQ0_OPERATION_MODE_TQS_MASK << |
| 1159 | EQOS_MTL_TXQ0_OPERATION_MODE_TQS_SHIFT, |
| 1160 | tqs << EQOS_MTL_TXQ0_OPERATION_MODE_TQS_SHIFT); |
| 1161 | clrsetbits_le32(&eqos->mtl_regs->rxq0_operation_mode, |
| 1162 | EQOS_MTL_RXQ0_OPERATION_MODE_RQS_MASK << |
| 1163 | EQOS_MTL_RXQ0_OPERATION_MODE_RQS_SHIFT, |
| 1164 | rqs << EQOS_MTL_RXQ0_OPERATION_MODE_RQS_SHIFT); |
| 1165 | |
| 1166 | /* Flow control used only if each channel gets 4KB or more FIFO */ |
| 1167 | if (rqs >= ((4096 / 256) - 1)) { |
| 1168 | u32 rfd, rfa; |
| 1169 | |
| 1170 | setbits_le32(&eqos->mtl_regs->rxq0_operation_mode, |
| 1171 | EQOS_MTL_RXQ0_OPERATION_MODE_EHFC); |
| 1172 | |
| 1173 | /* |
| 1174 | * Set Threshold for Activating Flow Contol space for min 2 |
| 1175 | * frames ie, (1500 * 1) = 1500 bytes. |
| 1176 | * |
| 1177 | * Set Threshold for Deactivating Flow Contol for space of |
| 1178 | * min 1 frame (frame size 1500bytes) in receive fifo |
| 1179 | */ |
| 1180 | if (rqs == ((4096 / 256) - 1)) { |
| 1181 | /* |
| 1182 | * This violates the above formula because of FIFO size |
| 1183 | * limit therefore overflow may occur inspite of this. |
| 1184 | */ |
| 1185 | rfd = 0x3; /* Full-3K */ |
| 1186 | rfa = 0x1; /* Full-1.5K */ |
| 1187 | } else if (rqs == ((8192 / 256) - 1)) { |
| 1188 | rfd = 0x6; /* Full-4K */ |
| 1189 | rfa = 0xa; /* Full-6K */ |
| 1190 | } else if (rqs == ((16384 / 256) - 1)) { |
| 1191 | rfd = 0x6; /* Full-4K */ |
| 1192 | rfa = 0x12; /* Full-10K */ |
| 1193 | } else { |
| 1194 | rfd = 0x6; /* Full-4K */ |
| 1195 | rfa = 0x1E; /* Full-16K */ |
| 1196 | } |
| 1197 | |
| 1198 | clrsetbits_le32(&eqos->mtl_regs->rxq0_operation_mode, |
| 1199 | (EQOS_MTL_RXQ0_OPERATION_MODE_RFD_MASK << |
| 1200 | EQOS_MTL_RXQ0_OPERATION_MODE_RFD_SHIFT) | |
| 1201 | (EQOS_MTL_RXQ0_OPERATION_MODE_RFA_MASK << |
| 1202 | EQOS_MTL_RXQ0_OPERATION_MODE_RFA_SHIFT), |
| 1203 | (rfd << |
| 1204 | EQOS_MTL_RXQ0_OPERATION_MODE_RFD_SHIFT) | |
| 1205 | (rfa << |
| 1206 | EQOS_MTL_RXQ0_OPERATION_MODE_RFA_SHIFT)); |
| 1207 | } |
| 1208 | |
| 1209 | /* Configure MAC */ |
| 1210 | |
| 1211 | clrsetbits_le32(&eqos->mac_regs->rxq_ctrl0, |
| 1212 | EQOS_MAC_RXQ_CTRL0_RXQ0EN_MASK << |
| 1213 | EQOS_MAC_RXQ_CTRL0_RXQ0EN_SHIFT, |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1214 | eqos->config->config_mac << |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1215 | EQOS_MAC_RXQ_CTRL0_RXQ0EN_SHIFT); |
| 1216 | |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 1217 | /* Multicast and Broadcast Queue Enable */ |
| 1218 | setbits_le32(&eqos->mac_regs->unused_0a4, |
| 1219 | 0x00100000); |
| 1220 | /* enable promise mode */ |
| 1221 | setbits_le32(&eqos->mac_regs->unused_004[1], |
| 1222 | 0x1); |
| 1223 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1224 | /* Set TX flow control parameters */ |
| 1225 | /* Set Pause Time */ |
| 1226 | setbits_le32(&eqos->mac_regs->q0_tx_flow_ctrl, |
| 1227 | 0xffff << EQOS_MAC_Q0_TX_FLOW_CTRL_PT_SHIFT); |
| 1228 | /* Assign priority for TX flow control */ |
| 1229 | clrbits_le32(&eqos->mac_regs->txq_prty_map0, |
| 1230 | EQOS_MAC_TXQ_PRTY_MAP0_PSTQ0_MASK << |
| 1231 | EQOS_MAC_TXQ_PRTY_MAP0_PSTQ0_SHIFT); |
| 1232 | /* Assign priority for RX flow control */ |
| 1233 | clrbits_le32(&eqos->mac_regs->rxq_ctrl2, |
| 1234 | EQOS_MAC_RXQ_CTRL2_PSRQ0_MASK << |
| 1235 | EQOS_MAC_RXQ_CTRL2_PSRQ0_SHIFT); |
| 1236 | /* Enable flow control */ |
| 1237 | setbits_le32(&eqos->mac_regs->q0_tx_flow_ctrl, |
| 1238 | EQOS_MAC_Q0_TX_FLOW_CTRL_TFE); |
| 1239 | setbits_le32(&eqos->mac_regs->rx_flow_ctrl, |
| 1240 | EQOS_MAC_RX_FLOW_CTRL_RFE); |
| 1241 | |
| 1242 | clrsetbits_le32(&eqos->mac_regs->configuration, |
| 1243 | EQOS_MAC_CONFIGURATION_GPSLCE | |
| 1244 | EQOS_MAC_CONFIGURATION_WD | |
| 1245 | EQOS_MAC_CONFIGURATION_JD | |
| 1246 | EQOS_MAC_CONFIGURATION_JE, |
| 1247 | EQOS_MAC_CONFIGURATION_CST | |
| 1248 | EQOS_MAC_CONFIGURATION_ACS); |
| 1249 | |
| 1250 | eqos_write_hwaddr(dev); |
| 1251 | |
| 1252 | /* Configure DMA */ |
| 1253 | |
| 1254 | /* Enable OSP mode */ |
| 1255 | setbits_le32(&eqos->dma_regs->ch0_tx_control, |
| 1256 | EQOS_DMA_CH0_TX_CONTROL_OSP); |
| 1257 | |
| 1258 | /* RX buffer size. Must be a multiple of bus width */ |
| 1259 | clrsetbits_le32(&eqos->dma_regs->ch0_rx_control, |
| 1260 | EQOS_DMA_CH0_RX_CONTROL_RBSZ_MASK << |
| 1261 | EQOS_DMA_CH0_RX_CONTROL_RBSZ_SHIFT, |
| 1262 | EQOS_MAX_PACKET_SIZE << |
| 1263 | EQOS_DMA_CH0_RX_CONTROL_RBSZ_SHIFT); |
| 1264 | |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 1265 | desc_pad = (eqos->desc_size - sizeof(struct eqos_desc)) / |
| 1266 | eqos->config->axi_bus_width; |
| 1267 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1268 | setbits_le32(&eqos->dma_regs->ch0_control, |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 1269 | EQOS_DMA_CH0_CONTROL_PBLX8 | |
| 1270 | (desc_pad << EQOS_DMA_CH0_CONTROL_DSL_SHIFT)); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1271 | |
| 1272 | /* |
| 1273 | * Burst length must be < 1/2 FIFO size. |
| 1274 | * FIFO size in tqs is encoded as (n / 256) - 1. |
| 1275 | * Each burst is n * 8 (PBLX8) * 16 (AXI width) == 128 bytes. |
| 1276 | * Half of n * 256 is n * 128, so pbl == tqs, modulo the -1. |
| 1277 | */ |
| 1278 | pbl = tqs + 1; |
| 1279 | if (pbl > 32) |
| 1280 | pbl = 32; |
| 1281 | clrsetbits_le32(&eqos->dma_regs->ch0_tx_control, |
| 1282 | EQOS_DMA_CH0_TX_CONTROL_TXPBL_MASK << |
| 1283 | EQOS_DMA_CH0_TX_CONTROL_TXPBL_SHIFT, |
| 1284 | pbl << EQOS_DMA_CH0_TX_CONTROL_TXPBL_SHIFT); |
| 1285 | |
| 1286 | clrsetbits_le32(&eqos->dma_regs->ch0_rx_control, |
| 1287 | EQOS_DMA_CH0_RX_CONTROL_RXPBL_MASK << |
| 1288 | EQOS_DMA_CH0_RX_CONTROL_RXPBL_SHIFT, |
| 1289 | 8 << EQOS_DMA_CH0_RX_CONTROL_RXPBL_SHIFT); |
| 1290 | |
| 1291 | /* DMA performance configuration */ |
| 1292 | val = (2 << EQOS_DMA_SYSBUS_MODE_RD_OSR_LMT_SHIFT) | |
| 1293 | EQOS_DMA_SYSBUS_MODE_EAME | EQOS_DMA_SYSBUS_MODE_BLEN16 | |
| 1294 | EQOS_DMA_SYSBUS_MODE_BLEN8 | EQOS_DMA_SYSBUS_MODE_BLEN4; |
| 1295 | writel(val, &eqos->dma_regs->sysbus_mode); |
| 1296 | |
| 1297 | /* Set up descriptors */ |
| 1298 | |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 1299 | memset(eqos->descs, 0, eqos->desc_size * EQOS_DESCRIPTORS_NUM); |
| 1300 | |
| 1301 | for (i = 0; i < EQOS_DESCRIPTORS_TX; i++) { |
| 1302 | struct eqos_desc *tx_desc = eqos_get_desc(eqos, i, false); |
| 1303 | eqos->config->ops->eqos_flush_desc(tx_desc); |
| 1304 | } |
| 1305 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1306 | for (i = 0; i < EQOS_DESCRIPTORS_RX; i++) { |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 1307 | struct eqos_desc *rx_desc = eqos_get_desc(eqos, i, true); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1308 | rx_desc->des0 = (u32)(ulong)(eqos->rx_dma_buf + |
| 1309 | (i * EQOS_MAX_PACKET_SIZE)); |
Marek Vasut | d54c98e | 2020-03-23 02:02:57 +0100 | [diff] [blame] | 1310 | rx_desc->des3 = EQOS_DESC3_OWN | EQOS_DESC3_BUF1V; |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 1311 | mb(); |
Marek Vasut | 873f8e4 | 2020-03-23 02:09:01 +0100 | [diff] [blame] | 1312 | eqos->config->ops->eqos_flush_desc(rx_desc); |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 1313 | eqos->config->ops->eqos_inval_buffer(eqos->rx_dma_buf + |
| 1314 | (i * EQOS_MAX_PACKET_SIZE), |
| 1315 | EQOS_MAX_PACKET_SIZE); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1316 | } |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1317 | |
| 1318 | writel(0, &eqos->dma_regs->ch0_txdesc_list_haddress); |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 1319 | writel((ulong)eqos_get_desc(eqos, 0, false), |
| 1320 | &eqos->dma_regs->ch0_txdesc_list_address); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1321 | writel(EQOS_DESCRIPTORS_TX - 1, |
| 1322 | &eqos->dma_regs->ch0_txdesc_ring_length); |
| 1323 | |
| 1324 | writel(0, &eqos->dma_regs->ch0_rxdesc_list_haddress); |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 1325 | writel((ulong)eqos_get_desc(eqos, 0, true), |
| 1326 | &eqos->dma_regs->ch0_rxdesc_list_address); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1327 | writel(EQOS_DESCRIPTORS_RX - 1, |
| 1328 | &eqos->dma_regs->ch0_rxdesc_ring_length); |
| 1329 | |
| 1330 | /* Enable everything */ |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1331 | setbits_le32(&eqos->dma_regs->ch0_tx_control, |
| 1332 | EQOS_DMA_CH0_TX_CONTROL_ST); |
| 1333 | setbits_le32(&eqos->dma_regs->ch0_rx_control, |
| 1334 | EQOS_DMA_CH0_RX_CONTROL_SR); |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 1335 | setbits_le32(&eqos->mac_regs->configuration, |
| 1336 | EQOS_MAC_CONFIGURATION_TE | EQOS_MAC_CONFIGURATION_RE); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1337 | |
| 1338 | /* TX tail pointer not written until we need to TX a packet */ |
| 1339 | /* |
| 1340 | * Point RX tail pointer at last descriptor. Ideally, we'd point at the |
| 1341 | * first descriptor, implying all descriptors were available. However, |
| 1342 | * that's not distinguishable from none of the descriptors being |
| 1343 | * available. |
| 1344 | */ |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 1345 | last_rx_desc = (ulong)eqos_get_desc(eqos, EQOS_DESCRIPTORS_RX - 1, true); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1346 | writel(last_rx_desc, &eqos->dma_regs->ch0_rxdesc_tail_pointer); |
| 1347 | |
| 1348 | eqos->started = true; |
| 1349 | |
| 1350 | debug("%s: OK\n", __func__); |
| 1351 | return 0; |
| 1352 | |
| 1353 | err_shutdown_phy: |
| 1354 | phy_shutdown(eqos->phy); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1355 | err_stop_resets: |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1356 | eqos->config->ops->eqos_stop_resets(dev); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1357 | err: |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1358 | pr_err("FAILED: %d", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1359 | return ret; |
| 1360 | } |
| 1361 | |
Patrick Delaunay | 6864a599 | 2019-08-01 11:29:02 +0200 | [diff] [blame] | 1362 | static void eqos_stop(struct udevice *dev) |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1363 | { |
| 1364 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1365 | int i; |
| 1366 | |
| 1367 | debug("%s(dev=%p):\n", __func__, dev); |
| 1368 | |
| 1369 | if (!eqos->started) |
| 1370 | return; |
| 1371 | eqos->started = false; |
| 1372 | eqos->reg_access_ok = false; |
| 1373 | |
| 1374 | /* Disable TX DMA */ |
| 1375 | clrbits_le32(&eqos->dma_regs->ch0_tx_control, |
| 1376 | EQOS_DMA_CH0_TX_CONTROL_ST); |
| 1377 | |
| 1378 | /* Wait for TX all packets to drain out of MTL */ |
| 1379 | for (i = 0; i < 1000000; i++) { |
| 1380 | u32 val = readl(&eqos->mtl_regs->txq0_debug); |
| 1381 | u32 trcsts = (val >> EQOS_MTL_TXQ0_DEBUG_TRCSTS_SHIFT) & |
| 1382 | EQOS_MTL_TXQ0_DEBUG_TRCSTS_MASK; |
| 1383 | u32 txqsts = val & EQOS_MTL_TXQ0_DEBUG_TXQSTS; |
| 1384 | if ((trcsts != 1) && (!txqsts)) |
| 1385 | break; |
| 1386 | } |
| 1387 | |
| 1388 | /* Turn off MAC TX and RX */ |
| 1389 | clrbits_le32(&eqos->mac_regs->configuration, |
| 1390 | EQOS_MAC_CONFIGURATION_TE | EQOS_MAC_CONFIGURATION_RE); |
| 1391 | |
| 1392 | /* Wait for all RX packets to drain out of MTL */ |
| 1393 | for (i = 0; i < 1000000; i++) { |
| 1394 | u32 val = readl(&eqos->mtl_regs->rxq0_debug); |
| 1395 | u32 prxq = (val >> EQOS_MTL_RXQ0_DEBUG_PRXQ_SHIFT) & |
| 1396 | EQOS_MTL_RXQ0_DEBUG_PRXQ_MASK; |
| 1397 | u32 rxqsts = (val >> EQOS_MTL_RXQ0_DEBUG_RXQSTS_SHIFT) & |
| 1398 | EQOS_MTL_RXQ0_DEBUG_RXQSTS_MASK; |
| 1399 | if ((!prxq) && (!rxqsts)) |
| 1400 | break; |
| 1401 | } |
| 1402 | |
| 1403 | /* Turn off RX DMA */ |
| 1404 | clrbits_le32(&eqos->dma_regs->ch0_rx_control, |
| 1405 | EQOS_DMA_CH0_RX_CONTROL_SR); |
| 1406 | |
| 1407 | if (eqos->phy) { |
| 1408 | phy_shutdown(eqos->phy); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1409 | } |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1410 | eqos->config->ops->eqos_stop_resets(dev); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1411 | |
| 1412 | debug("%s: OK\n", __func__); |
| 1413 | } |
| 1414 | |
Patrick Delaunay | 6864a599 | 2019-08-01 11:29:02 +0200 | [diff] [blame] | 1415 | static int eqos_send(struct udevice *dev, void *packet, int length) |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1416 | { |
| 1417 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1418 | struct eqos_desc *tx_desc; |
| 1419 | int i; |
| 1420 | |
| 1421 | debug("%s(dev=%p, packet=%p, length=%d):\n", __func__, dev, packet, |
| 1422 | length); |
| 1423 | |
| 1424 | memcpy(eqos->tx_dma_buf, packet, length); |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1425 | eqos->config->ops->eqos_flush_buffer(eqos->tx_dma_buf, length); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1426 | |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 1427 | tx_desc = eqos_get_desc(eqos, eqos->tx_desc_idx, false); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1428 | eqos->tx_desc_idx++; |
| 1429 | eqos->tx_desc_idx %= EQOS_DESCRIPTORS_TX; |
| 1430 | |
| 1431 | tx_desc->des0 = (ulong)eqos->tx_dma_buf; |
| 1432 | tx_desc->des1 = 0; |
| 1433 | tx_desc->des2 = length; |
| 1434 | /* |
| 1435 | * Make sure that if HW sees the _OWN write below, it will see all the |
| 1436 | * writes to the rest of the descriptor too. |
| 1437 | */ |
| 1438 | mb(); |
| 1439 | tx_desc->des3 = EQOS_DESC3_OWN | EQOS_DESC3_FD | EQOS_DESC3_LD | length; |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1440 | eqos->config->ops->eqos_flush_desc(tx_desc); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1441 | |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 1442 | writel((ulong)eqos_get_desc(eqos, eqos->tx_desc_idx, false), |
Marek Vasut | f4f1f4d | 2020-03-23 02:03:50 +0100 | [diff] [blame] | 1443 | &eqos->dma_regs->ch0_txdesc_tail_pointer); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1444 | |
| 1445 | for (i = 0; i < 1000000; i++) { |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1446 | eqos->config->ops->eqos_inval_desc(tx_desc); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1447 | if (!(readl(&tx_desc->des3) & EQOS_DESC3_OWN)) |
| 1448 | return 0; |
| 1449 | udelay(1); |
| 1450 | } |
| 1451 | |
| 1452 | debug("%s: TX timeout\n", __func__); |
| 1453 | |
| 1454 | return -ETIMEDOUT; |
| 1455 | } |
| 1456 | |
Patrick Delaunay | 6864a599 | 2019-08-01 11:29:02 +0200 | [diff] [blame] | 1457 | static int eqos_recv(struct udevice *dev, int flags, uchar **packetp) |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1458 | { |
| 1459 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1460 | struct eqos_desc *rx_desc; |
| 1461 | int length; |
| 1462 | |
| 1463 | debug("%s(dev=%p, flags=%x):\n", __func__, dev, flags); |
| 1464 | |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 1465 | rx_desc = eqos_get_desc(eqos, eqos->rx_desc_idx, true); |
Marek Vasut | c4db844 | 2020-03-23 02:09:21 +0100 | [diff] [blame] | 1466 | eqos->config->ops->eqos_inval_desc(rx_desc); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1467 | if (rx_desc->des3 & EQOS_DESC3_OWN) { |
| 1468 | debug("%s: RX packet not available\n", __func__); |
| 1469 | return -EAGAIN; |
| 1470 | } |
| 1471 | |
| 1472 | *packetp = eqos->rx_dma_buf + |
| 1473 | (eqos->rx_desc_idx * EQOS_MAX_PACKET_SIZE); |
| 1474 | length = rx_desc->des3 & 0x7fff; |
| 1475 | debug("%s: *packetp=%p, length=%d\n", __func__, *packetp, length); |
| 1476 | |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1477 | eqos->config->ops->eqos_inval_buffer(*packetp, length); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1478 | |
| 1479 | return length; |
| 1480 | } |
| 1481 | |
Patrick Delaunay | 6864a599 | 2019-08-01 11:29:02 +0200 | [diff] [blame] | 1482 | static int eqos_free_pkt(struct udevice *dev, uchar *packet, int length) |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1483 | { |
| 1484 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1485 | uchar *packet_expected; |
| 1486 | struct eqos_desc *rx_desc; |
| 1487 | |
| 1488 | debug("%s(packet=%p, length=%d)\n", __func__, packet, length); |
| 1489 | |
| 1490 | packet_expected = eqos->rx_dma_buf + |
| 1491 | (eqos->rx_desc_idx * EQOS_MAX_PACKET_SIZE); |
| 1492 | if (packet != packet_expected) { |
| 1493 | debug("%s: Unexpected packet (expected %p)\n", __func__, |
| 1494 | packet_expected); |
| 1495 | return -EINVAL; |
| 1496 | } |
| 1497 | |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 1498 | eqos->config->ops->eqos_inval_buffer(packet, length); |
| 1499 | |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 1500 | rx_desc = eqos_get_desc(eqos, eqos->rx_desc_idx, true); |
Marek Vasut | e8e5c2b | 2020-03-23 02:09:55 +0100 | [diff] [blame] | 1501 | |
Marek Vasut | 091b6db | 2020-03-23 02:11:46 +0100 | [diff] [blame] | 1502 | rx_desc->des0 = 0; |
| 1503 | mb(); |
| 1504 | eqos->config->ops->eqos_flush_desc(rx_desc); |
Marek Vasut | e8e5c2b | 2020-03-23 02:09:55 +0100 | [diff] [blame] | 1505 | eqos->config->ops->eqos_inval_buffer(packet, length); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1506 | rx_desc->des0 = (u32)(ulong)packet; |
| 1507 | rx_desc->des1 = 0; |
| 1508 | rx_desc->des2 = 0; |
| 1509 | /* |
| 1510 | * Make sure that if HW sees the _OWN write below, it will see all the |
| 1511 | * writes to the rest of the descriptor too. |
| 1512 | */ |
| 1513 | mb(); |
Marek Vasut | d54c98e | 2020-03-23 02:02:57 +0100 | [diff] [blame] | 1514 | rx_desc->des3 = EQOS_DESC3_OWN | EQOS_DESC3_BUF1V; |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1515 | eqos->config->ops->eqos_flush_desc(rx_desc); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1516 | |
| 1517 | writel((ulong)rx_desc, &eqos->dma_regs->ch0_rxdesc_tail_pointer); |
| 1518 | |
| 1519 | eqos->rx_desc_idx++; |
| 1520 | eqos->rx_desc_idx %= EQOS_DESCRIPTORS_RX; |
| 1521 | |
| 1522 | return 0; |
| 1523 | } |
| 1524 | |
| 1525 | static int eqos_probe_resources_core(struct udevice *dev) |
| 1526 | { |
| 1527 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1528 | int ret; |
| 1529 | |
| 1530 | debug("%s(dev=%p):\n", __func__, dev); |
| 1531 | |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 1532 | eqos->descs = eqos_alloc_descs(eqos, EQOS_DESCRIPTORS_NUM); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1533 | if (!eqos->descs) { |
| 1534 | debug("%s: eqos_alloc_descs() failed\n", __func__); |
| 1535 | ret = -ENOMEM; |
| 1536 | goto err; |
| 1537 | } |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1538 | |
| 1539 | eqos->tx_dma_buf = memalign(EQOS_BUFFER_ALIGN, EQOS_MAX_PACKET_SIZE); |
| 1540 | if (!eqos->tx_dma_buf) { |
| 1541 | debug("%s: memalign(tx_dma_buf) failed\n", __func__); |
| 1542 | ret = -ENOMEM; |
| 1543 | goto err_free_descs; |
| 1544 | } |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1545 | debug("%s: tx_dma_buf=%p\n", __func__, eqos->tx_dma_buf); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1546 | |
| 1547 | eqos->rx_dma_buf = memalign(EQOS_BUFFER_ALIGN, EQOS_RX_BUFFER_SIZE); |
| 1548 | if (!eqos->rx_dma_buf) { |
| 1549 | debug("%s: memalign(rx_dma_buf) failed\n", __func__); |
| 1550 | ret = -ENOMEM; |
| 1551 | goto err_free_tx_dma_buf; |
| 1552 | } |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1553 | debug("%s: rx_dma_buf=%p\n", __func__, eqos->rx_dma_buf); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1554 | |
| 1555 | eqos->rx_pkt = malloc(EQOS_MAX_PACKET_SIZE); |
| 1556 | if (!eqos->rx_pkt) { |
| 1557 | debug("%s: malloc(rx_pkt) failed\n", __func__); |
| 1558 | ret = -ENOMEM; |
| 1559 | goto err_free_rx_dma_buf; |
| 1560 | } |
| 1561 | debug("%s: rx_pkt=%p\n", __func__, eqos->rx_pkt); |
| 1562 | |
Marek Vasut | e8e5c2b | 2020-03-23 02:09:55 +0100 | [diff] [blame] | 1563 | eqos->config->ops->eqos_inval_buffer(eqos->rx_dma_buf, |
| 1564 | EQOS_MAX_PACKET_SIZE * EQOS_DESCRIPTORS_RX); |
| 1565 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1566 | debug("%s: OK\n", __func__); |
| 1567 | return 0; |
| 1568 | |
| 1569 | err_free_rx_dma_buf: |
| 1570 | free(eqos->rx_dma_buf); |
| 1571 | err_free_tx_dma_buf: |
| 1572 | free(eqos->tx_dma_buf); |
| 1573 | err_free_descs: |
| 1574 | eqos_free_descs(eqos->descs); |
| 1575 | err: |
| 1576 | |
| 1577 | debug("%s: returns %d\n", __func__, ret); |
| 1578 | return ret; |
| 1579 | } |
| 1580 | |
| 1581 | static int eqos_remove_resources_core(struct udevice *dev) |
| 1582 | { |
| 1583 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1584 | |
| 1585 | debug("%s(dev=%p):\n", __func__, dev); |
| 1586 | |
| 1587 | free(eqos->rx_pkt); |
| 1588 | free(eqos->rx_dma_buf); |
| 1589 | free(eqos->tx_dma_buf); |
| 1590 | eqos_free_descs(eqos->descs); |
| 1591 | |
| 1592 | debug("%s: OK\n", __func__); |
| 1593 | return 0; |
| 1594 | } |
| 1595 | |
| 1596 | static int eqos_probe_resources_tegra186(struct udevice *dev) |
| 1597 | { |
| 1598 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1599 | int ret; |
| 1600 | |
| 1601 | debug("%s(dev=%p):\n", __func__, dev); |
| 1602 | |
| 1603 | ret = reset_get_by_name(dev, "eqos", &eqos->reset_ctl); |
| 1604 | if (ret) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1605 | pr_err("reset_get_by_name(rst) failed: %d", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1606 | return ret; |
| 1607 | } |
| 1608 | |
| 1609 | ret = gpio_request_by_name(dev, "phy-reset-gpios", 0, |
| 1610 | &eqos->phy_reset_gpio, |
| 1611 | GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE); |
| 1612 | if (ret) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1613 | pr_err("gpio_request_by_name(phy reset) failed: %d", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1614 | goto err_free_reset_eqos; |
| 1615 | } |
| 1616 | |
| 1617 | ret = clk_get_by_name(dev, "slave_bus", &eqos->clk_slave_bus); |
| 1618 | if (ret) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1619 | pr_err("clk_get_by_name(slave_bus) failed: %d", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1620 | goto err_free_gpio_phy_reset; |
| 1621 | } |
| 1622 | |
| 1623 | ret = clk_get_by_name(dev, "master_bus", &eqos->clk_master_bus); |
| 1624 | if (ret) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1625 | pr_err("clk_get_by_name(master_bus) failed: %d", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1626 | goto err_free_clk_slave_bus; |
| 1627 | } |
| 1628 | |
| 1629 | ret = clk_get_by_name(dev, "rx", &eqos->clk_rx); |
| 1630 | if (ret) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1631 | pr_err("clk_get_by_name(rx) failed: %d", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1632 | goto err_free_clk_master_bus; |
| 1633 | } |
| 1634 | |
| 1635 | ret = clk_get_by_name(dev, "ptp_ref", &eqos->clk_ptp_ref); |
| 1636 | if (ret) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1637 | pr_err("clk_get_by_name(ptp_ref) failed: %d", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1638 | goto err_free_clk_rx; |
| 1639 | return ret; |
| 1640 | } |
| 1641 | |
| 1642 | ret = clk_get_by_name(dev, "tx", &eqos->clk_tx); |
| 1643 | if (ret) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1644 | pr_err("clk_get_by_name(tx) failed: %d", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1645 | goto err_free_clk_ptp_ref; |
| 1646 | } |
| 1647 | |
| 1648 | debug("%s: OK\n", __func__); |
| 1649 | return 0; |
| 1650 | |
| 1651 | err_free_clk_ptp_ref: |
| 1652 | clk_free(&eqos->clk_ptp_ref); |
| 1653 | err_free_clk_rx: |
| 1654 | clk_free(&eqos->clk_rx); |
| 1655 | err_free_clk_master_bus: |
| 1656 | clk_free(&eqos->clk_master_bus); |
| 1657 | err_free_clk_slave_bus: |
| 1658 | clk_free(&eqos->clk_slave_bus); |
| 1659 | err_free_gpio_phy_reset: |
| 1660 | dm_gpio_free(dev, &eqos->phy_reset_gpio); |
| 1661 | err_free_reset_eqos: |
| 1662 | reset_free(&eqos->reset_ctl); |
| 1663 | |
| 1664 | debug("%s: returns %d\n", __func__, ret); |
| 1665 | return ret; |
| 1666 | } |
| 1667 | |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1668 | /* board-specific Ethernet Interface initializations. */ |
Patrick Delaunay | bff66f9 | 2019-08-01 11:29:03 +0200 | [diff] [blame] | 1669 | __weak int board_interface_eth_init(struct udevice *dev, |
| 1670 | phy_interface_t interface_type) |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1671 | { |
| 1672 | return 0; |
| 1673 | } |
| 1674 | |
| 1675 | static int eqos_probe_resources_stm32(struct udevice *dev) |
| 1676 | { |
| 1677 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1678 | int ret; |
| 1679 | phy_interface_t interface; |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1680 | |
| 1681 | debug("%s(dev=%p):\n", __func__, dev); |
| 1682 | |
| 1683 | interface = eqos->config->interface(dev); |
| 1684 | |
| 1685 | if (interface == PHY_INTERFACE_MODE_NONE) { |
| 1686 | pr_err("Invalid PHY interface\n"); |
| 1687 | return -EINVAL; |
| 1688 | } |
| 1689 | |
Patrick Delaunay | bff66f9 | 2019-08-01 11:29:03 +0200 | [diff] [blame] | 1690 | ret = board_interface_eth_init(dev, interface); |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1691 | if (ret) |
| 1692 | return -EINVAL; |
| 1693 | |
Patrick Delaunay | 5c8db37 | 2020-03-18 10:50:16 +0100 | [diff] [blame] | 1694 | eqos->max_speed = dev_read_u32_default(dev, "max-speed", 0); |
| 1695 | |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1696 | ret = clk_get_by_name(dev, "stmmaceth", &eqos->clk_master_bus); |
| 1697 | if (ret) { |
| 1698 | pr_err("clk_get_by_name(master_bus) failed: %d", ret); |
| 1699 | goto err_probe; |
| 1700 | } |
| 1701 | |
| 1702 | ret = clk_get_by_name(dev, "mac-clk-rx", &eqos->clk_rx); |
| 1703 | if (ret) { |
| 1704 | pr_err("clk_get_by_name(rx) failed: %d", ret); |
| 1705 | goto err_free_clk_master_bus; |
| 1706 | } |
| 1707 | |
| 1708 | ret = clk_get_by_name(dev, "mac-clk-tx", &eqos->clk_tx); |
| 1709 | if (ret) { |
| 1710 | pr_err("clk_get_by_name(tx) failed: %d", ret); |
| 1711 | goto err_free_clk_rx; |
| 1712 | } |
| 1713 | |
| 1714 | /* Get ETH_CLK clocks (optional) */ |
| 1715 | ret = clk_get_by_name(dev, "eth-ck", &eqos->clk_ck); |
| 1716 | if (ret) |
| 1717 | pr_warn("No phy clock provided %d", ret); |
| 1718 | |
| 1719 | debug("%s: OK\n", __func__); |
| 1720 | return 0; |
| 1721 | |
| 1722 | err_free_clk_rx: |
| 1723 | clk_free(&eqos->clk_rx); |
| 1724 | err_free_clk_master_bus: |
| 1725 | clk_free(&eqos->clk_master_bus); |
| 1726 | err_probe: |
| 1727 | |
| 1728 | debug("%s: returns %d\n", __func__, ret); |
| 1729 | return ret; |
| 1730 | } |
| 1731 | |
| 1732 | static phy_interface_t eqos_get_interface_stm32(struct udevice *dev) |
| 1733 | { |
| 1734 | const char *phy_mode; |
| 1735 | phy_interface_t interface = PHY_INTERFACE_MODE_NONE; |
| 1736 | |
| 1737 | debug("%s(dev=%p):\n", __func__, dev); |
| 1738 | |
Patrick Delaunay | 9e6ed38 | 2020-09-09 18:30:06 +0200 | [diff] [blame] | 1739 | phy_mode = dev_read_prop(dev, "phy-mode", NULL); |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1740 | if (phy_mode) |
| 1741 | interface = phy_get_interface_by_name(phy_mode); |
| 1742 | |
| 1743 | return interface; |
| 1744 | } |
| 1745 | |
| 1746 | static phy_interface_t eqos_get_interface_tegra186(struct udevice *dev) |
| 1747 | { |
| 1748 | return PHY_INTERFACE_MODE_MII; |
| 1749 | } |
| 1750 | |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 1751 | static int eqos_probe_resources_imx(struct udevice *dev) |
| 1752 | { |
| 1753 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1754 | phy_interface_t interface; |
| 1755 | |
| 1756 | debug("%s(dev=%p):\n", __func__, dev); |
| 1757 | |
| 1758 | interface = eqos->config->interface(dev); |
| 1759 | |
| 1760 | if (interface == PHY_INTERFACE_MODE_NONE) { |
| 1761 | pr_err("Invalid PHY interface\n"); |
| 1762 | return -EINVAL; |
| 1763 | } |
| 1764 | |
| 1765 | debug("%s: OK\n", __func__); |
| 1766 | return 0; |
| 1767 | } |
| 1768 | |
| 1769 | static phy_interface_t eqos_get_interface_imx(struct udevice *dev) |
| 1770 | { |
Fugang Duan | dd455e6 | 2020-05-03 22:41:18 +0800 | [diff] [blame] | 1771 | const char *phy_mode; |
| 1772 | phy_interface_t interface = PHY_INTERFACE_MODE_NONE; |
| 1773 | |
| 1774 | debug("%s(dev=%p):\n", __func__, dev); |
| 1775 | |
Patrick Delaunay | 9e6ed38 | 2020-09-09 18:30:06 +0200 | [diff] [blame] | 1776 | phy_mode = dev_read_prop(dev, "phy-mode", NULL); |
Fugang Duan | dd455e6 | 2020-05-03 22:41:18 +0800 | [diff] [blame] | 1777 | if (phy_mode) |
| 1778 | interface = phy_get_interface_by_name(phy_mode); |
| 1779 | |
| 1780 | return interface; |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 1781 | } |
| 1782 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1783 | static int eqos_remove_resources_tegra186(struct udevice *dev) |
| 1784 | { |
| 1785 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1786 | |
| 1787 | debug("%s(dev=%p):\n", __func__, dev); |
| 1788 | |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 1789 | #ifdef CONFIG_CLK |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1790 | clk_free(&eqos->clk_tx); |
| 1791 | clk_free(&eqos->clk_ptp_ref); |
| 1792 | clk_free(&eqos->clk_rx); |
| 1793 | clk_free(&eqos->clk_slave_bus); |
| 1794 | clk_free(&eqos->clk_master_bus); |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 1795 | #endif |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1796 | dm_gpio_free(dev, &eqos->phy_reset_gpio); |
| 1797 | reset_free(&eqos->reset_ctl); |
| 1798 | |
| 1799 | debug("%s: OK\n", __func__); |
| 1800 | return 0; |
| 1801 | } |
| 1802 | |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1803 | static int eqos_remove_resources_stm32(struct udevice *dev) |
| 1804 | { |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 1805 | #ifdef CONFIG_CLK |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1806 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1807 | |
| 1808 | debug("%s(dev=%p):\n", __func__, dev); |
| 1809 | |
| 1810 | clk_free(&eqos->clk_tx); |
| 1811 | clk_free(&eqos->clk_rx); |
| 1812 | clk_free(&eqos->clk_master_bus); |
| 1813 | if (clk_valid(&eqos->clk_ck)) |
| 1814 | clk_free(&eqos->clk_ck); |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 1815 | #endif |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1816 | |
Christophe Roullier | 104dab5 | 2020-03-18 10:50:15 +0100 | [diff] [blame] | 1817 | if (dm_gpio_is_valid(&eqos->phy_reset_gpio)) |
| 1818 | dm_gpio_free(dev, &eqos->phy_reset_gpio); |
| 1819 | |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1820 | debug("%s: OK\n", __func__); |
| 1821 | return 0; |
| 1822 | } |
| 1823 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1824 | static int eqos_probe(struct udevice *dev) |
| 1825 | { |
| 1826 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1827 | int ret; |
| 1828 | |
| 1829 | debug("%s(dev=%p):\n", __func__, dev); |
| 1830 | |
| 1831 | eqos->dev = dev; |
| 1832 | eqos->config = (void *)dev_get_driver_data(dev); |
| 1833 | |
Masahiro Yamada | a89b4de | 2020-07-17 14:36:48 +0900 | [diff] [blame] | 1834 | eqos->regs = dev_read_addr(dev); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1835 | if (eqos->regs == FDT_ADDR_T_NONE) { |
Masahiro Yamada | a89b4de | 2020-07-17 14:36:48 +0900 | [diff] [blame] | 1836 | pr_err("dev_read_addr() failed"); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1837 | return -ENODEV; |
| 1838 | } |
| 1839 | eqos->mac_regs = (void *)(eqos->regs + EQOS_MAC_REGS_BASE); |
| 1840 | eqos->mtl_regs = (void *)(eqos->regs + EQOS_MTL_REGS_BASE); |
| 1841 | eqos->dma_regs = (void *)(eqos->regs + EQOS_DMA_REGS_BASE); |
| 1842 | eqos->tegra186_regs = (void *)(eqos->regs + EQOS_TEGRA186_REGS_BASE); |
| 1843 | |
| 1844 | ret = eqos_probe_resources_core(dev); |
| 1845 | if (ret < 0) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1846 | pr_err("eqos_probe_resources_core() failed: %d", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1847 | return ret; |
| 1848 | } |
| 1849 | |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1850 | ret = eqos->config->ops->eqos_probe_resources(dev); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1851 | if (ret < 0) { |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1852 | pr_err("eqos_probe_resources() failed: %d", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1853 | goto err_remove_resources_core; |
| 1854 | } |
| 1855 | |
Marek Vasut | 30b28c4 | 2021-11-13 03:23:52 +0100 | [diff] [blame] | 1856 | ret = eqos->config->ops->eqos_start_clks(dev); |
| 1857 | if (ret < 0) { |
| 1858 | pr_err("eqos_start_clks() failed: %d", ret); |
| 1859 | goto err_remove_resources_tegra; |
| 1860 | } |
| 1861 | |
Ye Li | ad122b7 | 2020-05-03 22:41:15 +0800 | [diff] [blame] | 1862 | #ifdef CONFIG_DM_ETH_PHY |
| 1863 | eqos->mii = eth_phy_get_mdio_bus(dev); |
| 1864 | #endif |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1865 | if (!eqos->mii) { |
Ye Li | ad122b7 | 2020-05-03 22:41:15 +0800 | [diff] [blame] | 1866 | eqos->mii = mdio_alloc(); |
| 1867 | if (!eqos->mii) { |
| 1868 | pr_err("mdio_alloc() failed"); |
| 1869 | ret = -ENOMEM; |
Marek Vasut | 30b28c4 | 2021-11-13 03:23:52 +0100 | [diff] [blame] | 1870 | goto err_stop_clks; |
Ye Li | ad122b7 | 2020-05-03 22:41:15 +0800 | [diff] [blame] | 1871 | } |
| 1872 | eqos->mii->read = eqos_mdio_read; |
| 1873 | eqos->mii->write = eqos_mdio_write; |
| 1874 | eqos->mii->priv = eqos; |
| 1875 | strcpy(eqos->mii->name, dev->name); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1876 | |
Ye Li | ad122b7 | 2020-05-03 22:41:15 +0800 | [diff] [blame] | 1877 | ret = mdio_register(eqos->mii); |
| 1878 | if (ret < 0) { |
| 1879 | pr_err("mdio_register() failed: %d", ret); |
| 1880 | goto err_free_mdio; |
| 1881 | } |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1882 | } |
| 1883 | |
Ye Li | ad122b7 | 2020-05-03 22:41:15 +0800 | [diff] [blame] | 1884 | #ifdef CONFIG_DM_ETH_PHY |
| 1885 | eth_phy_set_mdio_bus(dev, eqos->mii); |
| 1886 | #endif |
| 1887 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1888 | debug("%s: OK\n", __func__); |
| 1889 | return 0; |
| 1890 | |
| 1891 | err_free_mdio: |
| 1892 | mdio_free(eqos->mii); |
Marek Vasut | 30b28c4 | 2021-11-13 03:23:52 +0100 | [diff] [blame] | 1893 | err_stop_clks: |
| 1894 | eqos->config->ops->eqos_stop_clks(dev); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1895 | err_remove_resources_tegra: |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1896 | eqos->config->ops->eqos_remove_resources(dev); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1897 | err_remove_resources_core: |
| 1898 | eqos_remove_resources_core(dev); |
| 1899 | |
| 1900 | debug("%s: returns %d\n", __func__, ret); |
| 1901 | return ret; |
| 1902 | } |
| 1903 | |
| 1904 | static int eqos_remove(struct udevice *dev) |
| 1905 | { |
| 1906 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1907 | |
| 1908 | debug("%s(dev=%p):\n", __func__, dev); |
| 1909 | |
| 1910 | mdio_unregister(eqos->mii); |
| 1911 | mdio_free(eqos->mii); |
Marek Vasut | 30b28c4 | 2021-11-13 03:23:52 +0100 | [diff] [blame] | 1912 | eqos->config->ops->eqos_stop_clks(dev); |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1913 | eqos->config->ops->eqos_remove_resources(dev); |
| 1914 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1915 | eqos_probe_resources_core(dev); |
| 1916 | |
| 1917 | debug("%s: OK\n", __func__); |
| 1918 | return 0; |
| 1919 | } |
| 1920 | |
Patrick Delaunay | 1bc6ce7 | 2021-07-20 20:09:56 +0200 | [diff] [blame] | 1921 | static int eqos_null_ops(struct udevice *dev) |
| 1922 | { |
| 1923 | return 0; |
| 1924 | } |
| 1925 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1926 | static const struct eth_ops eqos_ops = { |
| 1927 | .start = eqos_start, |
| 1928 | .stop = eqos_stop, |
| 1929 | .send = eqos_send, |
| 1930 | .recv = eqos_recv, |
| 1931 | .free_pkt = eqos_free_pkt, |
| 1932 | .write_hwaddr = eqos_write_hwaddr, |
Ye Li | 3fb1a0e | 2020-05-03 22:41:20 +0800 | [diff] [blame] | 1933 | .read_rom_hwaddr = eqos_read_rom_hwaddr, |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1934 | }; |
| 1935 | |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1936 | static struct eqos_ops eqos_tegra186_ops = { |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 1937 | .eqos_inval_desc = eqos_inval_desc_generic, |
| 1938 | .eqos_flush_desc = eqos_flush_desc_generic, |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1939 | .eqos_inval_buffer = eqos_inval_buffer_tegra186, |
| 1940 | .eqos_flush_buffer = eqos_flush_buffer_tegra186, |
| 1941 | .eqos_probe_resources = eqos_probe_resources_tegra186, |
| 1942 | .eqos_remove_resources = eqos_remove_resources_tegra186, |
| 1943 | .eqos_stop_resets = eqos_stop_resets_tegra186, |
| 1944 | .eqos_start_resets = eqos_start_resets_tegra186, |
| 1945 | .eqos_stop_clks = eqos_stop_clks_tegra186, |
| 1946 | .eqos_start_clks = eqos_start_clks_tegra186, |
| 1947 | .eqos_calibrate_pads = eqos_calibrate_pads_tegra186, |
| 1948 | .eqos_disable_calibration = eqos_disable_calibration_tegra186, |
| 1949 | .eqos_set_tx_clk_speed = eqos_set_tx_clk_speed_tegra186, |
| 1950 | .eqos_get_tick_clk_rate = eqos_get_tick_clk_rate_tegra186 |
| 1951 | }; |
| 1952 | |
Patrick Delaunay | 6808390 | 2020-06-08 11:27:19 +0200 | [diff] [blame] | 1953 | static const struct eqos_config __maybe_unused eqos_tegra186_config = { |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1954 | .reg_access_always_ok = false, |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1955 | .mdio_wait = 10, |
| 1956 | .swr_wait = 10, |
| 1957 | .config_mac = EQOS_MAC_RXQ_CTRL0_RXQ0EN_ENABLED_DCB, |
| 1958 | .config_mac_mdio = EQOS_MAC_MDIO_ADDRESS_CR_20_35, |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 1959 | .axi_bus_width = EQOS_AXI_WIDTH_128, |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1960 | .interface = eqos_get_interface_tegra186, |
| 1961 | .ops = &eqos_tegra186_ops |
| 1962 | }; |
| 1963 | |
| 1964 | static struct eqos_ops eqos_stm32_ops = { |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 1965 | .eqos_inval_desc = eqos_inval_desc_generic, |
| 1966 | .eqos_flush_desc = eqos_flush_desc_generic, |
| 1967 | .eqos_inval_buffer = eqos_inval_buffer_generic, |
| 1968 | .eqos_flush_buffer = eqos_flush_buffer_generic, |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1969 | .eqos_probe_resources = eqos_probe_resources_stm32, |
| 1970 | .eqos_remove_resources = eqos_remove_resources_stm32, |
Patrick Delaunay | 1bc6ce7 | 2021-07-20 20:09:56 +0200 | [diff] [blame] | 1971 | .eqos_stop_resets = eqos_null_ops, |
| 1972 | .eqos_start_resets = eqos_null_ops, |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1973 | .eqos_stop_clks = eqos_stop_clks_stm32, |
| 1974 | .eqos_start_clks = eqos_start_clks_stm32, |
Patrick Delaunay | 1bc6ce7 | 2021-07-20 20:09:56 +0200 | [diff] [blame] | 1975 | .eqos_calibrate_pads = eqos_null_ops, |
| 1976 | .eqos_disable_calibration = eqos_null_ops, |
| 1977 | .eqos_set_tx_clk_speed = eqos_null_ops, |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1978 | .eqos_get_tick_clk_rate = eqos_get_tick_clk_rate_stm32 |
| 1979 | }; |
| 1980 | |
Patrick Delaunay | 6808390 | 2020-06-08 11:27:19 +0200 | [diff] [blame] | 1981 | static const struct eqos_config __maybe_unused eqos_stm32_config = { |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1982 | .reg_access_always_ok = false, |
| 1983 | .mdio_wait = 10000, |
| 1984 | .swr_wait = 50, |
| 1985 | .config_mac = EQOS_MAC_RXQ_CTRL0_RXQ0EN_ENABLED_AV, |
| 1986 | .config_mac_mdio = EQOS_MAC_MDIO_ADDRESS_CR_250_300, |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 1987 | .axi_bus_width = EQOS_AXI_WIDTH_64, |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1988 | .interface = eqos_get_interface_stm32, |
| 1989 | .ops = &eqos_stm32_ops |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1990 | }; |
| 1991 | |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 1992 | static struct eqos_ops eqos_imx_ops = { |
| 1993 | .eqos_inval_desc = eqos_inval_desc_generic, |
| 1994 | .eqos_flush_desc = eqos_flush_desc_generic, |
| 1995 | .eqos_inval_buffer = eqos_inval_buffer_generic, |
| 1996 | .eqos_flush_buffer = eqos_flush_buffer_generic, |
| 1997 | .eqos_probe_resources = eqos_probe_resources_imx, |
Patrick Delaunay | 1bc6ce7 | 2021-07-20 20:09:56 +0200 | [diff] [blame] | 1998 | .eqos_remove_resources = eqos_null_ops, |
| 1999 | .eqos_stop_resets = eqos_null_ops, |
| 2000 | .eqos_start_resets = eqos_null_ops, |
| 2001 | .eqos_stop_clks = eqos_null_ops, |
| 2002 | .eqos_start_clks = eqos_null_ops, |
| 2003 | .eqos_calibrate_pads = eqos_null_ops, |
| 2004 | .eqos_disable_calibration = eqos_null_ops, |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 2005 | .eqos_set_tx_clk_speed = eqos_set_tx_clk_speed_imx, |
| 2006 | .eqos_get_tick_clk_rate = eqos_get_tick_clk_rate_imx |
| 2007 | }; |
| 2008 | |
Patrick Delaunay | 6808390 | 2020-06-08 11:27:19 +0200 | [diff] [blame] | 2009 | struct eqos_config __maybe_unused eqos_imx_config = { |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 2010 | .reg_access_always_ok = false, |
Ye Li | f369e69 | 2020-12-28 20:15:10 +0800 | [diff] [blame] | 2011 | .mdio_wait = 10, |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 2012 | .swr_wait = 50, |
| 2013 | .config_mac = EQOS_MAC_RXQ_CTRL0_RXQ0EN_ENABLED_DCB, |
| 2014 | .config_mac_mdio = EQOS_MAC_MDIO_ADDRESS_CR_250_300, |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 2015 | .axi_bus_width = EQOS_AXI_WIDTH_64, |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 2016 | .interface = eqos_get_interface_imx, |
| 2017 | .ops = &eqos_imx_ops |
| 2018 | }; |
| 2019 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 2020 | static const struct udevice_id eqos_ids[] = { |
Patrick Delaunay | 6808390 | 2020-06-08 11:27:19 +0200 | [diff] [blame] | 2021 | #if IS_ENABLED(CONFIG_DWC_ETH_QOS_TEGRA186) |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 2022 | { |
| 2023 | .compatible = "nvidia,tegra186-eqos", |
| 2024 | .data = (ulong)&eqos_tegra186_config |
| 2025 | }, |
Patrick Delaunay | 6808390 | 2020-06-08 11:27:19 +0200 | [diff] [blame] | 2026 | #endif |
| 2027 | #if IS_ENABLED(CONFIG_DWC_ETH_QOS_STM32) |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 2028 | { |
Patrick Delaunay | a0466f6 | 2020-05-14 15:00:23 +0200 | [diff] [blame] | 2029 | .compatible = "st,stm32mp1-dwmac", |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 2030 | .data = (ulong)&eqos_stm32_config |
| 2031 | }, |
Patrick Delaunay | 6808390 | 2020-06-08 11:27:19 +0200 | [diff] [blame] | 2032 | #endif |
| 2033 | #if IS_ENABLED(CONFIG_DWC_ETH_QOS_IMX) |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 2034 | { |
| 2035 | .compatible = "fsl,imx-eqos", |
| 2036 | .data = (ulong)&eqos_imx_config |
| 2037 | }, |
Patrick Delaunay | 6808390 | 2020-06-08 11:27:19 +0200 | [diff] [blame] | 2038 | #endif |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 2039 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 2040 | { } |
| 2041 | }; |
| 2042 | |
| 2043 | U_BOOT_DRIVER(eth_eqos) = { |
| 2044 | .name = "eth_eqos", |
| 2045 | .id = UCLASS_ETH, |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 2046 | .of_match = of_match_ptr(eqos_ids), |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 2047 | .probe = eqos_probe, |
| 2048 | .remove = eqos_remove, |
| 2049 | .ops = &eqos_ops, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 2050 | .priv_auto = sizeof(struct eqos_priv), |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 2051 | .plat_auto = sizeof(struct eth_pdata), |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 2052 | }; |