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