Peng Fan | c0a5995 | 2022-07-26 16:41:14 +0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
| 2 | /* |
| 3 | * Copyright 2022 NXP |
| 4 | */ |
| 5 | |
| 6 | #include <phy_interface.h> |
| 7 | #include <linux/bitops.h> |
| 8 | |
| 9 | /* Core registers */ |
| 10 | |
| 11 | #define EQOS_MAC_REGS_BASE 0x000 |
| 12 | struct eqos_mac_regs { |
| 13 | u32 configuration; /* 0x000 */ |
| 14 | u32 unused_004[(0x070 - 0x004) / 4]; /* 0x004 */ |
| 15 | u32 q0_tx_flow_ctrl; /* 0x070 */ |
| 16 | u32 unused_070[(0x090 - 0x074) / 4]; /* 0x074 */ |
| 17 | u32 rx_flow_ctrl; /* 0x090 */ |
| 18 | u32 unused_094; /* 0x094 */ |
| 19 | u32 txq_prty_map0; /* 0x098 */ |
| 20 | u32 unused_09c; /* 0x09c */ |
| 21 | u32 rxq_ctrl0; /* 0x0a0 */ |
| 22 | u32 unused_0a4; /* 0x0a4 */ |
| 23 | u32 rxq_ctrl2; /* 0x0a8 */ |
| 24 | u32 unused_0ac[(0x0dc - 0x0ac) / 4]; /* 0x0ac */ |
| 25 | u32 us_tic_counter; /* 0x0dc */ |
| 26 | u32 unused_0e0[(0x11c - 0x0e0) / 4]; /* 0x0e0 */ |
| 27 | u32 hw_feature0; /* 0x11c */ |
| 28 | u32 hw_feature1; /* 0x120 */ |
| 29 | u32 hw_feature2; /* 0x124 */ |
| 30 | u32 unused_128[(0x200 - 0x128) / 4]; /* 0x128 */ |
| 31 | u32 mdio_address; /* 0x200 */ |
| 32 | u32 mdio_data; /* 0x204 */ |
| 33 | u32 unused_208[(0x300 - 0x208) / 4]; /* 0x208 */ |
| 34 | u32 address0_high; /* 0x300 */ |
| 35 | u32 address0_low; /* 0x304 */ |
| 36 | }; |
| 37 | |
| 38 | #define EQOS_MAC_CONFIGURATION_GPSLCE BIT(23) |
| 39 | #define EQOS_MAC_CONFIGURATION_CST BIT(21) |
| 40 | #define EQOS_MAC_CONFIGURATION_ACS BIT(20) |
| 41 | #define EQOS_MAC_CONFIGURATION_WD BIT(19) |
| 42 | #define EQOS_MAC_CONFIGURATION_JD BIT(17) |
| 43 | #define EQOS_MAC_CONFIGURATION_JE BIT(16) |
| 44 | #define EQOS_MAC_CONFIGURATION_PS BIT(15) |
| 45 | #define EQOS_MAC_CONFIGURATION_FES BIT(14) |
| 46 | #define EQOS_MAC_CONFIGURATION_DM BIT(13) |
| 47 | #define EQOS_MAC_CONFIGURATION_LM BIT(12) |
| 48 | #define EQOS_MAC_CONFIGURATION_TE BIT(1) |
| 49 | #define EQOS_MAC_CONFIGURATION_RE BIT(0) |
| 50 | |
| 51 | #define EQOS_MAC_Q0_TX_FLOW_CTRL_PT_SHIFT 16 |
| 52 | #define EQOS_MAC_Q0_TX_FLOW_CTRL_PT_MASK 0xffff |
| 53 | #define EQOS_MAC_Q0_TX_FLOW_CTRL_TFE BIT(1) |
| 54 | |
| 55 | #define EQOS_MAC_RX_FLOW_CTRL_RFE BIT(0) |
| 56 | |
| 57 | #define EQOS_MAC_TXQ_PRTY_MAP0_PSTQ0_SHIFT 0 |
| 58 | #define EQOS_MAC_TXQ_PRTY_MAP0_PSTQ0_MASK 0xff |
| 59 | |
| 60 | #define EQOS_MAC_RXQ_CTRL0_RXQ0EN_SHIFT 0 |
| 61 | #define EQOS_MAC_RXQ_CTRL0_RXQ0EN_MASK 3 |
| 62 | #define EQOS_MAC_RXQ_CTRL0_RXQ0EN_NOT_ENABLED 0 |
| 63 | #define EQOS_MAC_RXQ_CTRL0_RXQ0EN_ENABLED_DCB 2 |
| 64 | #define EQOS_MAC_RXQ_CTRL0_RXQ0EN_ENABLED_AV 1 |
| 65 | |
| 66 | #define EQOS_MAC_RXQ_CTRL2_PSRQ0_SHIFT 0 |
| 67 | #define EQOS_MAC_RXQ_CTRL2_PSRQ0_MASK 0xff |
| 68 | |
| 69 | #define EQOS_MAC_HW_FEATURE0_MMCSEL_SHIFT 8 |
| 70 | #define EQOS_MAC_HW_FEATURE0_HDSEL_SHIFT 2 |
| 71 | #define EQOS_MAC_HW_FEATURE0_GMIISEL_SHIFT 1 |
| 72 | #define EQOS_MAC_HW_FEATURE0_MIISEL_SHIFT 0 |
| 73 | |
| 74 | #define EQOS_MAC_HW_FEATURE1_TXFIFOSIZE_SHIFT 6 |
| 75 | #define EQOS_MAC_HW_FEATURE1_TXFIFOSIZE_MASK 0x1f |
| 76 | #define EQOS_MAC_HW_FEATURE1_RXFIFOSIZE_SHIFT 0 |
| 77 | #define EQOS_MAC_HW_FEATURE1_RXFIFOSIZE_MASK 0x1f |
| 78 | |
| 79 | #define EQOS_MAC_HW_FEATURE3_ASP_SHIFT 28 |
| 80 | #define EQOS_MAC_HW_FEATURE3_ASP_MASK 0x3 |
| 81 | |
| 82 | #define EQOS_MAC_MDIO_ADDRESS_PA_SHIFT 21 |
| 83 | #define EQOS_MAC_MDIO_ADDRESS_RDA_SHIFT 16 |
| 84 | #define EQOS_MAC_MDIO_ADDRESS_CR_SHIFT 8 |
| 85 | #define EQOS_MAC_MDIO_ADDRESS_CR_20_35 2 |
| 86 | #define EQOS_MAC_MDIO_ADDRESS_CR_250_300 5 |
| 87 | #define EQOS_MAC_MDIO_ADDRESS_SKAP BIT(4) |
| 88 | #define EQOS_MAC_MDIO_ADDRESS_GOC_SHIFT 2 |
| 89 | #define EQOS_MAC_MDIO_ADDRESS_GOC_READ 3 |
| 90 | #define EQOS_MAC_MDIO_ADDRESS_GOC_WRITE 1 |
| 91 | #define EQOS_MAC_MDIO_ADDRESS_C45E BIT(1) |
| 92 | #define EQOS_MAC_MDIO_ADDRESS_GB BIT(0) |
| 93 | |
| 94 | #define EQOS_MAC_MDIO_DATA_GD_MASK 0xffff |
| 95 | |
| 96 | #define EQOS_MTL_REGS_BASE 0xd00 |
| 97 | struct eqos_mtl_regs { |
| 98 | u32 txq0_operation_mode; /* 0xd00 */ |
| 99 | u32 unused_d04; /* 0xd04 */ |
| 100 | u32 txq0_debug; /* 0xd08 */ |
| 101 | u32 unused_d0c[(0xd18 - 0xd0c) / 4]; /* 0xd0c */ |
| 102 | u32 txq0_quantum_weight; /* 0xd18 */ |
| 103 | u32 unused_d1c[(0xd30 - 0xd1c) / 4]; /* 0xd1c */ |
| 104 | u32 rxq0_operation_mode; /* 0xd30 */ |
| 105 | u32 unused_d34; /* 0xd34 */ |
| 106 | u32 rxq0_debug; /* 0xd38 */ |
| 107 | }; |
| 108 | |
| 109 | #define EQOS_MTL_TXQ0_OPERATION_MODE_TQS_SHIFT 16 |
| 110 | #define EQOS_MTL_TXQ0_OPERATION_MODE_TQS_MASK 0x1ff |
| 111 | #define EQOS_MTL_TXQ0_OPERATION_MODE_TXQEN_SHIFT 2 |
| 112 | #define EQOS_MTL_TXQ0_OPERATION_MODE_TXQEN_MASK 3 |
| 113 | #define EQOS_MTL_TXQ0_OPERATION_MODE_TXQEN_ENABLED 2 |
| 114 | #define EQOS_MTL_TXQ0_OPERATION_MODE_TSF BIT(1) |
| 115 | #define EQOS_MTL_TXQ0_OPERATION_MODE_FTQ BIT(0) |
| 116 | |
| 117 | #define EQOS_MTL_TXQ0_DEBUG_TXQSTS BIT(4) |
| 118 | #define EQOS_MTL_TXQ0_DEBUG_TRCSTS_SHIFT 1 |
| 119 | #define EQOS_MTL_TXQ0_DEBUG_TRCSTS_MASK 3 |
| 120 | |
| 121 | #define EQOS_MTL_RXQ0_OPERATION_MODE_RQS_SHIFT 20 |
| 122 | #define EQOS_MTL_RXQ0_OPERATION_MODE_RQS_MASK 0x3ff |
| 123 | #define EQOS_MTL_RXQ0_OPERATION_MODE_RFD_SHIFT 14 |
| 124 | #define EQOS_MTL_RXQ0_OPERATION_MODE_RFD_MASK 0x3f |
| 125 | #define EQOS_MTL_RXQ0_OPERATION_MODE_RFA_SHIFT 8 |
| 126 | #define EQOS_MTL_RXQ0_OPERATION_MODE_RFA_MASK 0x3f |
| 127 | #define EQOS_MTL_RXQ0_OPERATION_MODE_EHFC BIT(7) |
| 128 | #define EQOS_MTL_RXQ0_OPERATION_MODE_RSF BIT(5) |
| 129 | |
| 130 | #define EQOS_MTL_RXQ0_DEBUG_PRXQ_SHIFT 16 |
| 131 | #define EQOS_MTL_RXQ0_DEBUG_PRXQ_MASK 0x7fff |
| 132 | #define EQOS_MTL_RXQ0_DEBUG_RXQSTS_SHIFT 4 |
| 133 | #define EQOS_MTL_RXQ0_DEBUG_RXQSTS_MASK 3 |
| 134 | |
| 135 | #define EQOS_DMA_REGS_BASE 0x1000 |
| 136 | struct eqos_dma_regs { |
| 137 | u32 mode; /* 0x1000 */ |
| 138 | u32 sysbus_mode; /* 0x1004 */ |
| 139 | u32 unused_1008[(0x1100 - 0x1008) / 4]; /* 0x1008 */ |
| 140 | u32 ch0_control; /* 0x1100 */ |
| 141 | u32 ch0_tx_control; /* 0x1104 */ |
| 142 | u32 ch0_rx_control; /* 0x1108 */ |
| 143 | u32 unused_110c; /* 0x110c */ |
| 144 | u32 ch0_txdesc_list_haddress; /* 0x1110 */ |
| 145 | u32 ch0_txdesc_list_address; /* 0x1114 */ |
| 146 | u32 ch0_rxdesc_list_haddress; /* 0x1118 */ |
| 147 | u32 ch0_rxdesc_list_address; /* 0x111c */ |
| 148 | u32 ch0_txdesc_tail_pointer; /* 0x1120 */ |
| 149 | u32 unused_1124; /* 0x1124 */ |
| 150 | u32 ch0_rxdesc_tail_pointer; /* 0x1128 */ |
| 151 | u32 ch0_txdesc_ring_length; /* 0x112c */ |
| 152 | u32 ch0_rxdesc_ring_length; /* 0x1130 */ |
| 153 | }; |
| 154 | |
| 155 | #define EQOS_DMA_MODE_SWR BIT(0) |
| 156 | |
| 157 | #define EQOS_DMA_SYSBUS_MODE_RD_OSR_LMT_SHIFT 16 |
| 158 | #define EQOS_DMA_SYSBUS_MODE_RD_OSR_LMT_MASK 0xf |
| 159 | #define EQOS_DMA_SYSBUS_MODE_EAME BIT(11) |
| 160 | #define EQOS_DMA_SYSBUS_MODE_BLEN16 BIT(3) |
| 161 | #define EQOS_DMA_SYSBUS_MODE_BLEN8 BIT(2) |
| 162 | #define EQOS_DMA_SYSBUS_MODE_BLEN4 BIT(1) |
| 163 | |
| 164 | #define EQOS_DMA_CH0_CONTROL_DSL_SHIFT 18 |
Marek Vasut | 3e8a1be | 2022-10-09 17:51:46 +0200 | [diff] [blame] | 165 | #define EQOS_DMA_CH0_CONTROL_DSL_MASK 0x7 |
Peng Fan | c0a5995 | 2022-07-26 16:41:14 +0800 | [diff] [blame] | 166 | #define EQOS_DMA_CH0_CONTROL_PBLX8 BIT(16) |
| 167 | |
| 168 | #define EQOS_DMA_CH0_TX_CONTROL_TXPBL_SHIFT 16 |
| 169 | #define EQOS_DMA_CH0_TX_CONTROL_TXPBL_MASK 0x3f |
| 170 | #define EQOS_DMA_CH0_TX_CONTROL_OSP BIT(4) |
| 171 | #define EQOS_DMA_CH0_TX_CONTROL_ST BIT(0) |
| 172 | |
| 173 | #define EQOS_DMA_CH0_RX_CONTROL_RXPBL_SHIFT 16 |
| 174 | #define EQOS_DMA_CH0_RX_CONTROL_RXPBL_MASK 0x3f |
| 175 | #define EQOS_DMA_CH0_RX_CONTROL_RBSZ_SHIFT 1 |
| 176 | #define EQOS_DMA_CH0_RX_CONTROL_RBSZ_MASK 0x3fff |
| 177 | #define EQOS_DMA_CH0_RX_CONTROL_SR BIT(0) |
| 178 | |
| 179 | /* These registers are Tegra186-specific */ |
| 180 | #define EQOS_TEGRA186_REGS_BASE 0x8800 |
| 181 | struct eqos_tegra186_regs { |
| 182 | u32 sdmemcomppadctrl; /* 0x8800 */ |
| 183 | u32 auto_cal_config; /* 0x8804 */ |
| 184 | u32 unused_8808; /* 0x8808 */ |
| 185 | u32 auto_cal_status; /* 0x880c */ |
| 186 | }; |
| 187 | |
| 188 | #define EQOS_SDMEMCOMPPADCTRL_PAD_E_INPUT_OR_E_PWRD BIT(31) |
| 189 | |
| 190 | #define EQOS_AUTO_CAL_CONFIG_START BIT(31) |
| 191 | #define EQOS_AUTO_CAL_CONFIG_ENABLE BIT(29) |
| 192 | |
| 193 | #define EQOS_AUTO_CAL_STATUS_ACTIVE BIT(31) |
| 194 | |
| 195 | /* Descriptors */ |
| 196 | #define EQOS_DESCRIPTORS_TX 4 |
| 197 | #define EQOS_DESCRIPTORS_RX 4 |
| 198 | #define EQOS_DESCRIPTORS_NUM (EQOS_DESCRIPTORS_TX + EQOS_DESCRIPTORS_RX) |
| 199 | #define EQOS_BUFFER_ALIGN ARCH_DMA_MINALIGN |
| 200 | #define EQOS_MAX_PACKET_SIZE ALIGN(1568, ARCH_DMA_MINALIGN) |
| 201 | #define EQOS_RX_BUFFER_SIZE (EQOS_DESCRIPTORS_RX * EQOS_MAX_PACKET_SIZE) |
| 202 | |
| 203 | struct eqos_desc { |
| 204 | u32 des0; |
| 205 | u32 des1; |
| 206 | u32 des2; |
| 207 | u32 des3; |
| 208 | }; |
| 209 | |
| 210 | #define EQOS_DESC3_OWN BIT(31) |
| 211 | #define EQOS_DESC3_FD BIT(29) |
| 212 | #define EQOS_DESC3_LD BIT(28) |
| 213 | #define EQOS_DESC3_BUF1V BIT(24) |
| 214 | |
| 215 | #define EQOS_AXI_WIDTH_32 4 |
| 216 | #define EQOS_AXI_WIDTH_64 8 |
| 217 | #define EQOS_AXI_WIDTH_128 16 |
| 218 | |
| 219 | struct eqos_config { |
| 220 | bool reg_access_always_ok; |
| 221 | int mdio_wait; |
| 222 | int swr_wait; |
| 223 | int config_mac; |
| 224 | int config_mac_mdio; |
| 225 | unsigned int axi_bus_width; |
| 226 | phy_interface_t (*interface)(const struct udevice *dev); |
| 227 | struct eqos_ops *ops; |
| 228 | }; |
| 229 | |
| 230 | struct eqos_ops { |
| 231 | void (*eqos_inval_desc)(void *desc); |
| 232 | void (*eqos_flush_desc)(void *desc); |
| 233 | void (*eqos_inval_buffer)(void *buf, size_t size); |
| 234 | void (*eqos_flush_buffer)(void *buf, size_t size); |
| 235 | int (*eqos_probe_resources)(struct udevice *dev); |
| 236 | int (*eqos_remove_resources)(struct udevice *dev); |
| 237 | int (*eqos_stop_resets)(struct udevice *dev); |
| 238 | int (*eqos_start_resets)(struct udevice *dev); |
| 239 | int (*eqos_stop_clks)(struct udevice *dev); |
| 240 | int (*eqos_start_clks)(struct udevice *dev); |
| 241 | int (*eqos_calibrate_pads)(struct udevice *dev); |
| 242 | int (*eqos_disable_calibration)(struct udevice *dev); |
| 243 | int (*eqos_set_tx_clk_speed)(struct udevice *dev); |
Peng Fan | bf69a7b9 | 2022-07-26 16:41:17 +0800 | [diff] [blame] | 244 | int (*eqos_get_enetaddr)(struct udevice *dev); |
Peng Fan | c0a5995 | 2022-07-26 16:41:14 +0800 | [diff] [blame] | 245 | ulong (*eqos_get_tick_clk_rate)(struct udevice *dev); |
| 246 | }; |
| 247 | |
| 248 | struct eqos_priv { |
| 249 | struct udevice *dev; |
| 250 | const struct eqos_config *config; |
| 251 | fdt_addr_t regs; |
| 252 | struct eqos_mac_regs *mac_regs; |
| 253 | struct eqos_mtl_regs *mtl_regs; |
| 254 | struct eqos_dma_regs *dma_regs; |
| 255 | struct eqos_tegra186_regs *tegra186_regs; |
Sumit Garg | 7c3be94 | 2023-02-01 19:28:55 +0530 | [diff] [blame] | 256 | void *eqos_qcom_rgmii_regs; |
Peng Fan | c0a5995 | 2022-07-26 16:41:14 +0800 | [diff] [blame] | 257 | struct reset_ctl reset_ctl; |
| 258 | struct gpio_desc phy_reset_gpio; |
| 259 | struct clk clk_master_bus; |
| 260 | struct clk clk_rx; |
| 261 | struct clk clk_ptp_ref; |
| 262 | struct clk clk_tx; |
| 263 | struct clk clk_ck; |
| 264 | struct clk clk_slave_bus; |
| 265 | struct mii_dev *mii; |
| 266 | struct phy_device *phy; |
Ye Li | 2f2aa48 | 2022-07-26 16:41:16 +0800 | [diff] [blame] | 267 | ofnode phy_of_node; |
Peng Fan | c0a5995 | 2022-07-26 16:41:14 +0800 | [diff] [blame] | 268 | u32 max_speed; |
Marek Vasut | 90cc13a | 2022-10-09 17:51:45 +0200 | [diff] [blame] | 269 | void *tx_descs; |
| 270 | void *rx_descs; |
Peng Fan | c0a5995 | 2022-07-26 16:41:14 +0800 | [diff] [blame] | 271 | int tx_desc_idx, rx_desc_idx; |
| 272 | unsigned int desc_size; |
Marek Vasut | 3e8a1be | 2022-10-09 17:51:46 +0200 | [diff] [blame] | 273 | unsigned int desc_per_cacheline; |
Peng Fan | c0a5995 | 2022-07-26 16:41:14 +0800 | [diff] [blame] | 274 | void *tx_dma_buf; |
| 275 | void *rx_dma_buf; |
| 276 | void *rx_pkt; |
| 277 | bool started; |
| 278 | bool reg_access_ok; |
| 279 | bool clk_ck_enabled; |
Sumit Garg | 4d5c965 | 2023-02-01 19:28:54 +0530 | [diff] [blame] | 280 | unsigned int tx_fifo_sz, rx_fifo_sz; |
Sumit Garg | 7c3be94 | 2023-02-01 19:28:55 +0530 | [diff] [blame] | 281 | u32 reset_delays[3]; |
Peng Fan | c0a5995 | 2022-07-26 16:41:14 +0800 | [diff] [blame] | 282 | }; |
| 283 | |
| 284 | void eqos_inval_desc_generic(void *desc); |
| 285 | void eqos_flush_desc_generic(void *desc); |
| 286 | void eqos_inval_buffer_generic(void *buf, size_t size); |
| 287 | void eqos_flush_buffer_generic(void *buf, size_t size); |
| 288 | int eqos_null_ops(struct udevice *dev); |
Peng Fan | 5721a82 | 2022-07-26 16:41:15 +0800 | [diff] [blame] | 289 | |
| 290 | extern struct eqos_config eqos_imx_config; |
Sumit Garg | 7c3be94 | 2023-02-01 19:28:55 +0530 | [diff] [blame] | 291 | extern struct eqos_config eqos_qcom_config; |