Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 2 | /* |
Ashok Reddy Soma | 645aa76 | 2021-06-24 00:34:41 -0600 | [diff] [blame] | 3 | * Copyright (C) 2021 Waymo LLC |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 4 | * Copyright (C) 2011 Michal Simek <monstr@monstr.eu> |
| 5 | * Copyright (C) 2011 PetaLogix |
| 6 | * Copyright (C) 2010 Xilinx, Inc. All rights reserved. |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <config.h> |
Simon Glass | 6333448 | 2019-11-14 12:57:39 -0700 | [diff] [blame] | 10 | #include <cpu_func.h> |
Simon Glass | 1ab1692 | 2022-07-31 12:28:48 -0600 | [diff] [blame] | 11 | #include <display_options.h> |
Michal Simek | 682baac | 2015-12-08 15:44:41 +0100 | [diff] [blame] | 12 | #include <dm.h> |
Venkatesh Yadav Abbarapu | 1bbe450 | 2022-09-29 10:26:05 +0530 | [diff] [blame] | 13 | #include <dm/device_compat.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 14 | #include <log.h> |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 15 | #include <net.h> |
| 16 | #include <malloc.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 17 | #include <asm/global_data.h> |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 18 | #include <asm/io.h> |
| 19 | #include <phy.h> |
| 20 | #include <miiphy.h> |
Siva Durga Prasad Paladugu | 2063362 | 2017-01-06 16:18:50 +0530 | [diff] [blame] | 21 | #include <wait_bit.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 22 | #include <linux/delay.h> |
T Karthik Reddy | 4a3f40b | 2022-05-10 13:26:09 +0200 | [diff] [blame] | 23 | #include <eth_phy.h> |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 24 | |
Michal Simek | 682baac | 2015-12-08 15:44:41 +0100 | [diff] [blame] | 25 | DECLARE_GLOBAL_DATA_PTR; |
| 26 | |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 27 | /* Link setup */ |
| 28 | #define XAE_EMMC_LINKSPEED_MASK 0xC0000000 /* Link speed */ |
| 29 | #define XAE_EMMC_LINKSPD_10 0x00000000 /* Link Speed mask for 10 Mbit */ |
| 30 | #define XAE_EMMC_LINKSPD_100 0x40000000 /* Link Speed mask for 100 Mbit */ |
| 31 | #define XAE_EMMC_LINKSPD_1000 0x80000000 /* Link Speed mask for 1000 Mbit */ |
| 32 | |
| 33 | /* Interrupt Status/Enable/Mask Registers bit definitions */ |
| 34 | #define XAE_INT_RXRJECT_MASK 0x00000008 /* Rx frame rejected */ |
| 35 | #define XAE_INT_MGTRDY_MASK 0x00000080 /* MGT clock Lock */ |
| 36 | |
| 37 | /* Receive Configuration Word 1 (RCW1) Register bit definitions */ |
| 38 | #define XAE_RCW1_RX_MASK 0x10000000 /* Receiver enable */ |
| 39 | |
| 40 | /* Transmitter Configuration (TC) Register bit definitions */ |
| 41 | #define XAE_TC_TX_MASK 0x10000000 /* Transmitter enable */ |
| 42 | |
| 43 | #define XAE_UAW1_UNICASTADDR_MASK 0x0000FFFF |
| 44 | |
| 45 | /* MDIO Management Configuration (MC) Register bit definitions */ |
| 46 | #define XAE_MDIO_MC_MDIOEN_MASK 0x00000040 /* MII management enable*/ |
| 47 | |
| 48 | /* MDIO Management Control Register (MCR) Register bit definitions */ |
| 49 | #define XAE_MDIO_MCR_PHYAD_MASK 0x1F000000 /* Phy Address Mask */ |
| 50 | #define XAE_MDIO_MCR_PHYAD_SHIFT 24 /* Phy Address Shift */ |
| 51 | #define XAE_MDIO_MCR_REGAD_MASK 0x001F0000 /* Reg Address Mask */ |
| 52 | #define XAE_MDIO_MCR_REGAD_SHIFT 16 /* Reg Address Shift */ |
| 53 | #define XAE_MDIO_MCR_OP_READ_MASK 0x00008000 /* Op Code Read Mask */ |
| 54 | #define XAE_MDIO_MCR_OP_WRITE_MASK 0x00004000 /* Op Code Write Mask */ |
| 55 | #define XAE_MDIO_MCR_INITIATE_MASK 0x00000800 /* Ready Mask */ |
| 56 | #define XAE_MDIO_MCR_READY_MASK 0x00000080 /* Ready Mask */ |
| 57 | |
| 58 | #define XAE_MDIO_DIV_DFT 29 /* Default MDIO clock divisor */ |
| 59 | |
Siva Durga Prasad Paladugu | f802603 | 2017-01-06 16:27:15 +0530 | [diff] [blame] | 60 | #define XAXIDMA_BD_STS_ACTUAL_LEN_MASK 0x007FFFFF /* Actual len */ |
| 61 | |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 62 | /* DMA macros */ |
| 63 | /* Bitmasks of XAXIDMA_CR_OFFSET register */ |
| 64 | #define XAXIDMA_CR_RUNSTOP_MASK 0x00000001 /* Start/stop DMA channel */ |
| 65 | #define XAXIDMA_CR_RESET_MASK 0x00000004 /* Reset DMA engine */ |
| 66 | |
| 67 | /* Bitmasks of XAXIDMA_SR_OFFSET register */ |
| 68 | #define XAXIDMA_HALTED_MASK 0x00000001 /* DMA channel halted */ |
| 69 | |
| 70 | /* Bitmask for interrupts */ |
| 71 | #define XAXIDMA_IRQ_IOC_MASK 0x00001000 /* Completion intr */ |
| 72 | #define XAXIDMA_IRQ_DELAY_MASK 0x00002000 /* Delay interrupt */ |
| 73 | #define XAXIDMA_IRQ_ALL_MASK 0x00007000 /* All interrupts */ |
| 74 | |
| 75 | /* Bitmasks of XAXIDMA_BD_CTRL_OFFSET register */ |
| 76 | #define XAXIDMA_BD_CTRL_TXSOF_MASK 0x08000000 /* First tx packet */ |
| 77 | #define XAXIDMA_BD_CTRL_TXEOF_MASK 0x04000000 /* Last tx packet */ |
| 78 | |
Ashok Reddy Soma | 645aa76 | 2021-06-24 00:34:41 -0600 | [diff] [blame] | 79 | /* Bitmasks for XXV Ethernet MAC */ |
| 80 | #define XXV_TC_TX_MASK 0x00000001 |
| 81 | #define XXV_TC_FCS_MASK 0x00000002 |
| 82 | #define XXV_RCW1_RX_MASK 0x00000001 |
| 83 | #define XXV_RCW1_FCS_MASK 0x00000002 |
| 84 | |
| 85 | #define DMAALIGN 128 |
| 86 | #define XXV_MIN_PKT_SIZE 60 |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 87 | |
| 88 | static u8 rxframe[PKTSIZE_ALIGN] __attribute((aligned(DMAALIGN))); |
Ashok Reddy Soma | 645aa76 | 2021-06-24 00:34:41 -0600 | [diff] [blame] | 89 | static u8 txminframe[XXV_MIN_PKT_SIZE] __attribute((aligned(DMAALIGN))); |
| 90 | |
| 91 | enum emac_variant { |
| 92 | EMAC_1G = 0, |
| 93 | EMAC_10G_25G = 1, |
| 94 | }; |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 95 | |
| 96 | /* Reflect dma offsets */ |
| 97 | struct axidma_reg { |
| 98 | u32 control; /* DMACR */ |
| 99 | u32 status; /* DMASR */ |
Vipul Kumar | 3b06a0f | 2018-01-23 14:52:35 +0530 | [diff] [blame] | 100 | u32 current; /* CURDESC low 32 bit */ |
| 101 | u32 current_hi; /* CURDESC high 32 bit */ |
| 102 | u32 tail; /* TAILDESC low 32 bit */ |
| 103 | u32 tail_hi; /* TAILDESC high 32 bit */ |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 104 | }; |
| 105 | |
Ashok Reddy Soma | 3c4df95 | 2021-06-24 00:34:40 -0600 | [diff] [blame] | 106 | /* Platform data structures */ |
| 107 | struct axidma_plat { |
| 108 | struct eth_pdata eth_pdata; |
| 109 | struct axidma_reg *dmatx; |
| 110 | struct axidma_reg *dmarx; |
Andy Chiu | 58af7eb | 2022-11-01 11:57:59 +0800 | [diff] [blame] | 111 | int pcsaddr; |
Ashok Reddy Soma | 3c4df95 | 2021-06-24 00:34:40 -0600 | [diff] [blame] | 112 | int phyaddr; |
| 113 | u8 eth_hasnobuf; |
Maxim Kochetkov | 61cd6fd | 2023-08-11 10:43:51 +0300 | [diff] [blame] | 114 | ofnode phynode; |
Ashok Reddy Soma | 645aa76 | 2021-06-24 00:34:41 -0600 | [diff] [blame] | 115 | enum emac_variant mactype; |
Ashok Reddy Soma | 3c4df95 | 2021-06-24 00:34:40 -0600 | [diff] [blame] | 116 | }; |
| 117 | |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 118 | /* Private driver structures */ |
| 119 | struct axidma_priv { |
| 120 | struct axidma_reg *dmatx; |
| 121 | struct axidma_reg *dmarx; |
Andy Chiu | 58af7eb | 2022-11-01 11:57:59 +0800 | [diff] [blame] | 122 | int pcsaddr; |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 123 | int phyaddr; |
Michal Simek | 6cb55e7 | 2015-12-09 14:39:42 +0100 | [diff] [blame] | 124 | struct axi_regs *iobase; |
Michal Simek | 682baac | 2015-12-08 15:44:41 +0100 | [diff] [blame] | 125 | phy_interface_t interface; |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 126 | struct phy_device *phydev; |
| 127 | struct mii_dev *bus; |
Siva Durga Prasad Paladugu | f802603 | 2017-01-06 16:27:15 +0530 | [diff] [blame] | 128 | u8 eth_hasnobuf; |
Maxim Kochetkov | 61cd6fd | 2023-08-11 10:43:51 +0300 | [diff] [blame] | 129 | ofnode phynode; |
Ashok Reddy Soma | 645aa76 | 2021-06-24 00:34:41 -0600 | [diff] [blame] | 130 | enum emac_variant mactype; |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 131 | }; |
| 132 | |
| 133 | /* BD descriptors */ |
| 134 | struct axidma_bd { |
Ashok Reddy Soma | 91d455a | 2020-09-03 08:36:43 -0600 | [diff] [blame] | 135 | u32 next_desc; /* Next descriptor pointer */ |
| 136 | u32 next_desc_msb; |
| 137 | u32 buf_addr; /* Buffer address */ |
| 138 | u32 buf_addr_msb; |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 139 | u32 reserved3; |
| 140 | u32 reserved4; |
| 141 | u32 cntrl; /* Control */ |
| 142 | u32 status; /* Status */ |
| 143 | u32 app0; |
| 144 | u32 app1; /* TX start << 16 | insert */ |
| 145 | u32 app2; /* TX csum seed */ |
| 146 | u32 app3; |
| 147 | u32 app4; |
| 148 | u32 sw_id_offset; |
| 149 | u32 reserved5; |
| 150 | u32 reserved6; |
| 151 | }; |
| 152 | |
| 153 | /* Static BDs - driver uses only one BD */ |
| 154 | static struct axidma_bd tx_bd __attribute((aligned(DMAALIGN))); |
| 155 | static struct axidma_bd rx_bd __attribute((aligned(DMAALIGN))); |
| 156 | |
| 157 | struct axi_regs { |
| 158 | u32 reserved[3]; |
| 159 | u32 is; /* 0xC: Interrupt status */ |
| 160 | u32 reserved2; |
| 161 | u32 ie; /* 0x14: Interrupt enable */ |
| 162 | u32 reserved3[251]; |
| 163 | u32 rcw1; /* 0x404: Rx Configuration Word 1 */ |
| 164 | u32 tc; /* 0x408: Tx Configuration */ |
| 165 | u32 reserved4; |
| 166 | u32 emmc; /* 0x410: EMAC mode configuration */ |
| 167 | u32 reserved5[59]; |
| 168 | u32 mdio_mc; /* 0x500: MII Management Config */ |
| 169 | u32 mdio_mcr; /* 0x504: MII Management Control */ |
| 170 | u32 mdio_mwd; /* 0x508: MII Management Write Data */ |
| 171 | u32 mdio_mrd; /* 0x50C: MII Management Read Data */ |
| 172 | u32 reserved6[124]; |
| 173 | u32 uaw0; /* 0x700: Unicast address word 0 */ |
| 174 | u32 uaw1; /* 0x704: Unicast address word 1 */ |
| 175 | }; |
| 176 | |
Ashok Reddy Soma | 645aa76 | 2021-06-24 00:34:41 -0600 | [diff] [blame] | 177 | struct xxv_axi_regs { |
| 178 | u32 gt_reset; /* 0x0 */ |
| 179 | u32 reserved[2]; |
| 180 | u32 tc; /* 0xC: Tx Configuration */ |
| 181 | u32 reserved2; |
| 182 | u32 rcw1; /* 0x14: Rx Configuration Word 1 */ |
| 183 | }; |
| 184 | |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 185 | /* Use MII register 1 (MII status register) to detect PHY */ |
| 186 | #define PHY_DETECT_REG 1 |
| 187 | |
| 188 | /* |
| 189 | * Mask used to verify certain PHY features (or register contents) |
| 190 | * in the register above: |
| 191 | * 0x1000: 10Mbps full duplex support |
| 192 | * 0x0800: 10Mbps half duplex support |
| 193 | * 0x0008: Auto-negotiation support |
| 194 | */ |
| 195 | #define PHY_DETECT_MASK 0x1808 |
| 196 | |
Michal Simek | f522187 | 2015-12-09 14:36:31 +0100 | [diff] [blame] | 197 | static inline int mdio_wait(struct axi_regs *regs) |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 198 | { |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 199 | u32 timeout = 200; |
| 200 | |
| 201 | /* Wait till MDIO interface is ready to accept a new transaction. */ |
Siva Durga Prasad Paladugu | d227c9a | 2017-11-23 12:23:12 +0530 | [diff] [blame] | 202 | while (timeout && (!(readl(®s->mdio_mcr) |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 203 | & XAE_MDIO_MCR_READY_MASK))) { |
| 204 | timeout--; |
| 205 | udelay(1); |
| 206 | } |
| 207 | if (!timeout) { |
| 208 | printf("%s: Timeout\n", __func__); |
| 209 | return 1; |
| 210 | } |
| 211 | return 0; |
| 212 | } |
| 213 | |
Vipul Kumar | 3b06a0f | 2018-01-23 14:52:35 +0530 | [diff] [blame] | 214 | /** |
| 215 | * axienet_dma_write - Memory mapped Axi DMA register Buffer Descriptor write. |
| 216 | * @bd: pointer to BD descriptor structure |
| 217 | * @desc: Address offset of DMA descriptors |
| 218 | * |
| 219 | * This function writes the value into the corresponding Axi DMA register. |
| 220 | */ |
| 221 | static inline void axienet_dma_write(struct axidma_bd *bd, u32 *desc) |
| 222 | { |
| 223 | #if defined(CONFIG_PHYS_64BIT) |
Ashok Reddy Soma | 91d455a | 2020-09-03 08:36:43 -0600 | [diff] [blame] | 224 | writeq((unsigned long)bd, desc); |
Vipul Kumar | 3b06a0f | 2018-01-23 14:52:35 +0530 | [diff] [blame] | 225 | #else |
| 226 | writel((u32)bd, desc); |
| 227 | #endif |
| 228 | } |
| 229 | |
Michal Simek | 41beca1 | 2015-12-09 14:44:38 +0100 | [diff] [blame] | 230 | static u32 phyread(struct axidma_priv *priv, u32 phyaddress, u32 registernum, |
| 231 | u16 *val) |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 232 | { |
Michal Simek | 41beca1 | 2015-12-09 14:44:38 +0100 | [diff] [blame] | 233 | struct axi_regs *regs = priv->iobase; |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 234 | u32 mdioctrlreg = 0; |
| 235 | |
Michal Simek | f522187 | 2015-12-09 14:36:31 +0100 | [diff] [blame] | 236 | if (mdio_wait(regs)) |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 237 | return 1; |
| 238 | |
| 239 | mdioctrlreg = ((phyaddress << XAE_MDIO_MCR_PHYAD_SHIFT) & |
| 240 | XAE_MDIO_MCR_PHYAD_MASK) | |
| 241 | ((registernum << XAE_MDIO_MCR_REGAD_SHIFT) |
| 242 | & XAE_MDIO_MCR_REGAD_MASK) | |
| 243 | XAE_MDIO_MCR_INITIATE_MASK | |
| 244 | XAE_MDIO_MCR_OP_READ_MASK; |
| 245 | |
Siva Durga Prasad Paladugu | d227c9a | 2017-11-23 12:23:12 +0530 | [diff] [blame] | 246 | writel(mdioctrlreg, ®s->mdio_mcr); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 247 | |
Michal Simek | f522187 | 2015-12-09 14:36:31 +0100 | [diff] [blame] | 248 | if (mdio_wait(regs)) |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 249 | return 1; |
| 250 | |
| 251 | /* Read data */ |
Siva Durga Prasad Paladugu | d227c9a | 2017-11-23 12:23:12 +0530 | [diff] [blame] | 252 | *val = readl(®s->mdio_mrd); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 253 | return 0; |
| 254 | } |
| 255 | |
Michal Simek | 41beca1 | 2015-12-09 14:44:38 +0100 | [diff] [blame] | 256 | static u32 phywrite(struct axidma_priv *priv, u32 phyaddress, u32 registernum, |
| 257 | u32 data) |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 258 | { |
Michal Simek | 41beca1 | 2015-12-09 14:44:38 +0100 | [diff] [blame] | 259 | struct axi_regs *regs = priv->iobase; |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 260 | u32 mdioctrlreg = 0; |
| 261 | |
Michal Simek | f522187 | 2015-12-09 14:36:31 +0100 | [diff] [blame] | 262 | if (mdio_wait(regs)) |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 263 | return 1; |
| 264 | |
| 265 | mdioctrlreg = ((phyaddress << XAE_MDIO_MCR_PHYAD_SHIFT) & |
| 266 | XAE_MDIO_MCR_PHYAD_MASK) | |
| 267 | ((registernum << XAE_MDIO_MCR_REGAD_SHIFT) |
| 268 | & XAE_MDIO_MCR_REGAD_MASK) | |
| 269 | XAE_MDIO_MCR_INITIATE_MASK | |
| 270 | XAE_MDIO_MCR_OP_WRITE_MASK; |
| 271 | |
| 272 | /* Write data */ |
Siva Durga Prasad Paladugu | d227c9a | 2017-11-23 12:23:12 +0530 | [diff] [blame] | 273 | writel(data, ®s->mdio_mwd); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 274 | |
Siva Durga Prasad Paladugu | d227c9a | 2017-11-23 12:23:12 +0530 | [diff] [blame] | 275 | writel(mdioctrlreg, ®s->mdio_mcr); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 276 | |
Michal Simek | f522187 | 2015-12-09 14:36:31 +0100 | [diff] [blame] | 277 | if (mdio_wait(regs)) |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 278 | return 1; |
| 279 | |
| 280 | return 0; |
| 281 | } |
| 282 | |
Michal Simek | 0b13ee2 | 2015-12-08 16:10:05 +0100 | [diff] [blame] | 283 | static int axiemac_phy_init(struct udevice *dev) |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 284 | { |
| 285 | u16 phyreg; |
Patrick van Gelder | 70ab943 | 2020-06-03 14:18:04 +0200 | [diff] [blame] | 286 | int i; |
| 287 | u32 ret; |
Michal Simek | 682baac | 2015-12-08 15:44:41 +0100 | [diff] [blame] | 288 | struct axidma_priv *priv = dev_get_priv(dev); |
Michal Simek | 6cb55e7 | 2015-12-09 14:39:42 +0100 | [diff] [blame] | 289 | struct axi_regs *regs = priv->iobase; |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 290 | struct phy_device *phydev; |
| 291 | |
| 292 | u32 supported = SUPPORTED_10baseT_Half | |
| 293 | SUPPORTED_10baseT_Full | |
| 294 | SUPPORTED_100baseT_Half | |
| 295 | SUPPORTED_100baseT_Full | |
| 296 | SUPPORTED_1000baseT_Half | |
| 297 | SUPPORTED_1000baseT_Full; |
| 298 | |
Michal Simek | 0b13ee2 | 2015-12-08 16:10:05 +0100 | [diff] [blame] | 299 | /* Set default MDIO divisor */ |
Siva Durga Prasad Paladugu | d227c9a | 2017-11-23 12:23:12 +0530 | [diff] [blame] | 300 | writel(XAE_MDIO_DIV_DFT | XAE_MDIO_MC_MDIOEN_MASK, ®s->mdio_mc); |
Michal Simek | 0b13ee2 | 2015-12-08 16:10:05 +0100 | [diff] [blame] | 301 | |
T Karthik Reddy | 4a3f40b | 2022-05-10 13:26:09 +0200 | [diff] [blame] | 302 | if (IS_ENABLED(CONFIG_DM_ETH_PHY)) |
| 303 | priv->phyaddr = eth_phy_get_addr(dev); |
| 304 | |
Andy Chiu | 58af7eb | 2022-11-01 11:57:59 +0800 | [diff] [blame] | 305 | /* |
| 306 | * Set address of PCS/PMA PHY to the one pointed by phy-handle for |
| 307 | * backward compatibility. |
| 308 | */ |
| 309 | if (priv->phyaddr != -1 && priv->pcsaddr == 0) |
| 310 | priv->pcsaddr = priv->phyaddr; |
| 311 | |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 312 | if (priv->phyaddr == -1) { |
| 313 | /* Detect the PHY address */ |
| 314 | for (i = 31; i >= 0; i--) { |
Michal Simek | 41beca1 | 2015-12-09 14:44:38 +0100 | [diff] [blame] | 315 | ret = phyread(priv, i, PHY_DETECT_REG, &phyreg); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 316 | if (!ret && (phyreg != 0xFFFF) && |
| 317 | ((phyreg & PHY_DETECT_MASK) == PHY_DETECT_MASK)) { |
| 318 | /* Found a valid PHY address */ |
| 319 | priv->phyaddr = i; |
| 320 | debug("axiemac: Found valid phy address, %x\n", |
Michal Simek | 2f1e065 | 2015-12-09 10:54:53 +0100 | [diff] [blame] | 321 | i); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 322 | break; |
| 323 | } |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | /* Interface - look at tsec */ |
Siva Durga Prasad Paladugu | 4934851 | 2016-02-21 15:46:14 +0530 | [diff] [blame] | 328 | phydev = phy_connect(priv->bus, priv->phyaddr, dev, priv->interface); |
Venkatesh Yadav Abbarapu | 1bbe450 | 2022-09-29 10:26:05 +0530 | [diff] [blame] | 329 | if (IS_ERR_OR_NULL(phydev)) { |
| 330 | dev_err(dev, "phy_connect() failed\n"); |
| 331 | return -ENODEV; |
| 332 | } |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 333 | |
| 334 | phydev->supported &= supported; |
| 335 | phydev->advertising = phydev->supported; |
| 336 | priv->phydev = phydev; |
Maxim Kochetkov | 61cd6fd | 2023-08-11 10:43:51 +0300 | [diff] [blame] | 337 | if (ofnode_valid(priv->phynode)) |
| 338 | priv->phydev->node = priv->phynode; |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 339 | phy_config(phydev); |
Michal Simek | 0b13ee2 | 2015-12-08 16:10:05 +0100 | [diff] [blame] | 340 | |
| 341 | return 0; |
| 342 | } |
| 343 | |
Andy Chiu | 8144a2a | 2022-11-01 11:58:00 +0800 | [diff] [blame] | 344 | static int pcs_pma_startup(struct axidma_priv *priv) |
| 345 | { |
| 346 | u32 rc, retry_cnt = 0; |
| 347 | u16 mii_reg; |
| 348 | |
| 349 | rc = phyread(priv, priv->pcsaddr, MII_BMCR, &mii_reg); |
| 350 | if (rc) |
| 351 | goto failed_mdio; |
| 352 | |
| 353 | if (!(mii_reg & BMCR_ANENABLE)) { |
| 354 | mii_reg |= BMCR_ANENABLE; |
| 355 | if (phywrite(priv, priv->pcsaddr, MII_BMCR, mii_reg)) |
| 356 | goto failed_mdio; |
| 357 | } |
| 358 | |
| 359 | /* |
| 360 | * Check the internal PHY status and warn user if the link between it |
| 361 | * and the external PHY is not obtained. |
| 362 | */ |
| 363 | debug("axiemac: waiting for link status of the PCS/PMA PHY"); |
Marek Vasut | e4d70fd | 2024-05-31 18:47:17 +0200 | [diff] [blame] | 364 | while (retry_cnt * 10 < CONFIG_PHY_ANEG_TIMEOUT) { |
Andy Chiu | 8144a2a | 2022-11-01 11:58:00 +0800 | [diff] [blame] | 365 | rc = phyread(priv, priv->pcsaddr, MII_BMSR, &mii_reg); |
| 366 | if ((mii_reg & BMSR_LSTATUS) && mii_reg != 0xffff && !rc) { |
| 367 | debug(".Done\n"); |
| 368 | return 0; |
| 369 | } |
| 370 | if ((retry_cnt++ % 10) == 0) |
| 371 | debug("."); |
| 372 | mdelay(10); |
| 373 | } |
| 374 | debug("\n"); |
| 375 | printf("axiemac: Warning, PCS/PMA PHY@%d is not ready, link is down\n", |
| 376 | priv->pcsaddr); |
| 377 | return 1; |
| 378 | failed_mdio: |
| 379 | printf("axiemac: MDIO to the PCS/PMA PHY has failed\n"); |
| 380 | return 1; |
| 381 | } |
| 382 | |
Michal Simek | 0b13ee2 | 2015-12-08 16:10:05 +0100 | [diff] [blame] | 383 | /* Setting axi emac and phy to proper setting */ |
| 384 | static int setup_phy(struct udevice *dev) |
| 385 | { |
Siva Durga Prasad Paladugu | a1c6ed8 | 2016-02-21 15:46:15 +0530 | [diff] [blame] | 386 | u16 temp; |
| 387 | u32 speed, emmc_reg, ret; |
Michal Simek | 0b13ee2 | 2015-12-08 16:10:05 +0100 | [diff] [blame] | 388 | struct axidma_priv *priv = dev_get_priv(dev); |
| 389 | struct axi_regs *regs = priv->iobase; |
| 390 | struct phy_device *phydev = priv->phydev; |
| 391 | |
Siva Durga Prasad Paladugu | a1c6ed8 | 2016-02-21 15:46:15 +0530 | [diff] [blame] | 392 | if (priv->interface == PHY_INTERFACE_MODE_SGMII) { |
| 393 | /* |
| 394 | * In SGMII cases the isolate bit might set |
| 395 | * after DMA and ethernet resets and hence |
| 396 | * check and clear if set. |
| 397 | */ |
Andy Chiu | 58af7eb | 2022-11-01 11:57:59 +0800 | [diff] [blame] | 398 | ret = phyread(priv, priv->pcsaddr, MII_BMCR, &temp); |
Siva Durga Prasad Paladugu | a1c6ed8 | 2016-02-21 15:46:15 +0530 | [diff] [blame] | 399 | if (ret) |
| 400 | return 0; |
| 401 | if (temp & BMCR_ISOLATE) { |
| 402 | temp &= ~BMCR_ISOLATE; |
Andy Chiu | 58af7eb | 2022-11-01 11:57:59 +0800 | [diff] [blame] | 403 | ret = phywrite(priv, priv->pcsaddr, MII_BMCR, temp); |
Siva Durga Prasad Paladugu | a1c6ed8 | 2016-02-21 15:46:15 +0530 | [diff] [blame] | 404 | if (ret) |
| 405 | return 0; |
| 406 | } |
| 407 | } |
| 408 | |
Timur Tabi | 4238746 | 2012-07-09 08:52:43 +0000 | [diff] [blame] | 409 | if (phy_startup(phydev)) { |
| 410 | printf("axiemac: could not initialize PHY %s\n", |
| 411 | phydev->dev->name); |
| 412 | return 0; |
| 413 | } |
Andy Chiu | 8144a2a | 2022-11-01 11:58:00 +0800 | [diff] [blame] | 414 | if (priv->interface == PHY_INTERFACE_MODE_SGMII || |
| 415 | priv->interface == PHY_INTERFACE_MODE_1000BASEX) { |
| 416 | if (pcs_pma_startup(priv)) |
| 417 | return 0; |
| 418 | } |
Michal Simek | 5848f13 | 2013-11-21 16:15:51 +0100 | [diff] [blame] | 419 | if (!phydev->link) { |
| 420 | printf("%s: No link.\n", phydev->dev->name); |
| 421 | return 0; |
| 422 | } |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 423 | |
| 424 | switch (phydev->speed) { |
| 425 | case 1000: |
| 426 | speed = XAE_EMMC_LINKSPD_1000; |
| 427 | break; |
| 428 | case 100: |
| 429 | speed = XAE_EMMC_LINKSPD_100; |
| 430 | break; |
| 431 | case 10: |
| 432 | speed = XAE_EMMC_LINKSPD_10; |
| 433 | break; |
| 434 | default: |
| 435 | return 0; |
| 436 | } |
| 437 | |
| 438 | /* Setup the emac for the phy speed */ |
Siva Durga Prasad Paladugu | d227c9a | 2017-11-23 12:23:12 +0530 | [diff] [blame] | 439 | emmc_reg = readl(®s->emmc); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 440 | emmc_reg &= ~XAE_EMMC_LINKSPEED_MASK; |
| 441 | emmc_reg |= speed; |
| 442 | |
| 443 | /* Write new speed setting out to Axi Ethernet */ |
Siva Durga Prasad Paladugu | d227c9a | 2017-11-23 12:23:12 +0530 | [diff] [blame] | 444 | writel(emmc_reg, ®s->emmc); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 445 | |
| 446 | /* |
| 447 | * Setting the operating speed of the MAC needs a delay. There |
| 448 | * doesn't seem to be register to poll, so please consider this |
| 449 | * during your application design. |
| 450 | */ |
| 451 | udelay(1); |
| 452 | |
| 453 | return 1; |
| 454 | } |
| 455 | |
| 456 | /* STOP DMA transfers */ |
Michal Simek | 8fbf79f | 2015-12-16 09:18:12 +0100 | [diff] [blame] | 457 | static void axiemac_stop(struct udevice *dev) |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 458 | { |
Michal Simek | 682baac | 2015-12-08 15:44:41 +0100 | [diff] [blame] | 459 | struct axidma_priv *priv = dev_get_priv(dev); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 460 | u32 temp; |
| 461 | |
| 462 | /* Stop the hardware */ |
Siva Durga Prasad Paladugu | d227c9a | 2017-11-23 12:23:12 +0530 | [diff] [blame] | 463 | temp = readl(&priv->dmatx->control); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 464 | temp &= ~XAXIDMA_CR_RUNSTOP_MASK; |
Siva Durga Prasad Paladugu | d227c9a | 2017-11-23 12:23:12 +0530 | [diff] [blame] | 465 | writel(temp, &priv->dmatx->control); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 466 | |
Siva Durga Prasad Paladugu | d227c9a | 2017-11-23 12:23:12 +0530 | [diff] [blame] | 467 | temp = readl(&priv->dmarx->control); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 468 | temp &= ~XAXIDMA_CR_RUNSTOP_MASK; |
Siva Durga Prasad Paladugu | d227c9a | 2017-11-23 12:23:12 +0530 | [diff] [blame] | 469 | writel(temp, &priv->dmarx->control); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 470 | |
| 471 | debug("axiemac: Halted\n"); |
| 472 | } |
| 473 | |
Ashok Reddy Soma | 645aa76 | 2021-06-24 00:34:41 -0600 | [diff] [blame] | 474 | static int xxv_axi_ethernet_init(struct axidma_priv *priv) |
| 475 | { |
| 476 | struct xxv_axi_regs *regs = (struct xxv_axi_regs *)priv->iobase; |
| 477 | |
| 478 | writel(readl(®s->rcw1) | XXV_RCW1_FCS_MASK, ®s->rcw1); |
| 479 | writel(readl(®s->tc) | XXV_TC_FCS_MASK, ®s->tc); |
| 480 | writel(readl(®s->tc) | XXV_TC_TX_MASK, ®s->tc); |
| 481 | writel(readl(®s->rcw1) | XXV_RCW1_RX_MASK, ®s->rcw1); |
| 482 | |
| 483 | return 0; |
| 484 | } |
| 485 | |
Michal Simek | 638c0ef | 2015-12-09 14:53:51 +0100 | [diff] [blame] | 486 | static int axi_ethernet_init(struct axidma_priv *priv) |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 487 | { |
Michal Simek | 638c0ef | 2015-12-09 14:53:51 +0100 | [diff] [blame] | 488 | struct axi_regs *regs = priv->iobase; |
Siva Durga Prasad Paladugu | 2063362 | 2017-01-06 16:18:50 +0530 | [diff] [blame] | 489 | int err; |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 490 | |
| 491 | /* |
| 492 | * Check the status of the MgtRdy bit in the interrupt status |
| 493 | * registers. This must be done to allow the MGT clock to become stable |
| 494 | * for the Sgmii and 1000BaseX PHY interfaces. No other register reads |
| 495 | * will be valid until this bit is valid. |
| 496 | * The bit is always a 1 for all other PHY interfaces. |
Siva Durga Prasad Paladugu | f802603 | 2017-01-06 16:27:15 +0530 | [diff] [blame] | 497 | * Interrupt status and enable registers are not available in non |
| 498 | * processor mode and hence bypass in this mode |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 499 | */ |
Siva Durga Prasad Paladugu | f802603 | 2017-01-06 16:27:15 +0530 | [diff] [blame] | 500 | if (!priv->eth_hasnobuf) { |
Ălvaro FernĂĄndez Rojas | 918de03 | 2018-01-23 17:14:55 +0100 | [diff] [blame] | 501 | err = wait_for_bit_le32(®s->is, XAE_INT_MGTRDY_MASK, |
| 502 | true, 200, false); |
Siva Durga Prasad Paladugu | f802603 | 2017-01-06 16:27:15 +0530 | [diff] [blame] | 503 | if (err) { |
| 504 | printf("%s: Timeout\n", __func__); |
| 505 | return 1; |
| 506 | } |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 507 | |
Siva Durga Prasad Paladugu | f802603 | 2017-01-06 16:27:15 +0530 | [diff] [blame] | 508 | /* |
| 509 | * Stop the device and reset HW |
| 510 | * Disable interrupts |
| 511 | */ |
Siva Durga Prasad Paladugu | d227c9a | 2017-11-23 12:23:12 +0530 | [diff] [blame] | 512 | writel(0, ®s->ie); |
Siva Durga Prasad Paladugu | f802603 | 2017-01-06 16:27:15 +0530 | [diff] [blame] | 513 | } |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 514 | |
| 515 | /* Disable the receiver */ |
Siva Durga Prasad Paladugu | d227c9a | 2017-11-23 12:23:12 +0530 | [diff] [blame] | 516 | writel(readl(®s->rcw1) & ~XAE_RCW1_RX_MASK, ®s->rcw1); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 517 | |
| 518 | /* |
| 519 | * Stopping the receiver in mid-packet causes a dropped packet |
| 520 | * indication from HW. Clear it. |
| 521 | */ |
Siva Durga Prasad Paladugu | f802603 | 2017-01-06 16:27:15 +0530 | [diff] [blame] | 522 | if (!priv->eth_hasnobuf) { |
| 523 | /* Set the interrupt status register to clear the interrupt */ |
Siva Durga Prasad Paladugu | d227c9a | 2017-11-23 12:23:12 +0530 | [diff] [blame] | 524 | writel(XAE_INT_RXRJECT_MASK, ®s->is); |
Siva Durga Prasad Paladugu | f802603 | 2017-01-06 16:27:15 +0530 | [diff] [blame] | 525 | } |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 526 | |
| 527 | /* Setup HW */ |
| 528 | /* Set default MDIO divisor */ |
Siva Durga Prasad Paladugu | d227c9a | 2017-11-23 12:23:12 +0530 | [diff] [blame] | 529 | writel(XAE_MDIO_DIV_DFT | XAE_MDIO_MC_MDIOEN_MASK, ®s->mdio_mc); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 530 | |
| 531 | debug("axiemac: InitHw done\n"); |
| 532 | return 0; |
| 533 | } |
| 534 | |
Michal Simek | 8fbf79f | 2015-12-16 09:18:12 +0100 | [diff] [blame] | 535 | static int axiemac_write_hwaddr(struct udevice *dev) |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 536 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 537 | struct eth_pdata *pdata = dev_get_plat(dev); |
Michal Simek | 682baac | 2015-12-08 15:44:41 +0100 | [diff] [blame] | 538 | struct axidma_priv *priv = dev_get_priv(dev); |
| 539 | struct axi_regs *regs = priv->iobase; |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 540 | |
Ashok Reddy Soma | 645aa76 | 2021-06-24 00:34:41 -0600 | [diff] [blame] | 541 | if (priv->mactype != EMAC_1G) |
| 542 | return 0; |
| 543 | |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 544 | /* Set the MAC address */ |
Michal Simek | 682baac | 2015-12-08 15:44:41 +0100 | [diff] [blame] | 545 | int val = ((pdata->enetaddr[3] << 24) | (pdata->enetaddr[2] << 16) | |
| 546 | (pdata->enetaddr[1] << 8) | (pdata->enetaddr[0])); |
Siva Durga Prasad Paladugu | d227c9a | 2017-11-23 12:23:12 +0530 | [diff] [blame] | 547 | writel(val, ®s->uaw0); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 548 | |
Michal Simek | 682baac | 2015-12-08 15:44:41 +0100 | [diff] [blame] | 549 | val = (pdata->enetaddr[5] << 8) | pdata->enetaddr[4]; |
Siva Durga Prasad Paladugu | d227c9a | 2017-11-23 12:23:12 +0530 | [diff] [blame] | 550 | val |= readl(®s->uaw1) & ~XAE_UAW1_UNICASTADDR_MASK; |
| 551 | writel(val, ®s->uaw1); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 552 | return 0; |
| 553 | } |
| 554 | |
| 555 | /* Reset DMA engine */ |
Michal Simek | 638c0ef | 2015-12-09 14:53:51 +0100 | [diff] [blame] | 556 | static void axi_dma_init(struct axidma_priv *priv) |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 557 | { |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 558 | u32 timeout = 500; |
| 559 | |
| 560 | /* Reset the engine so the hardware starts from a known state */ |
Siva Durga Prasad Paladugu | d227c9a | 2017-11-23 12:23:12 +0530 | [diff] [blame] | 561 | writel(XAXIDMA_CR_RESET_MASK, &priv->dmatx->control); |
| 562 | writel(XAXIDMA_CR_RESET_MASK, &priv->dmarx->control); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 563 | |
| 564 | /* At the initialization time, hardware should finish reset quickly */ |
| 565 | while (timeout--) { |
| 566 | /* Check transmit/receive channel */ |
| 567 | /* Reset is done when the reset bit is low */ |
Siva Durga Prasad Paladugu | d227c9a | 2017-11-23 12:23:12 +0530 | [diff] [blame] | 568 | if (!((readl(&priv->dmatx->control) | |
| 569 | readl(&priv->dmarx->control)) |
Michal Simek | 5aa4539 | 2015-10-28 11:00:47 +0100 | [diff] [blame] | 570 | & XAXIDMA_CR_RESET_MASK)) { |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 571 | break; |
| 572 | } |
| 573 | } |
| 574 | if (!timeout) |
| 575 | printf("%s: Timeout\n", __func__); |
| 576 | } |
| 577 | |
Michal Simek | 8fbf79f | 2015-12-16 09:18:12 +0100 | [diff] [blame] | 578 | static int axiemac_start(struct udevice *dev) |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 579 | { |
Michal Simek | 682baac | 2015-12-08 15:44:41 +0100 | [diff] [blame] | 580 | struct axidma_priv *priv = dev_get_priv(dev); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 581 | u32 temp; |
| 582 | |
| 583 | debug("axiemac: Init started\n"); |
| 584 | /* |
| 585 | * Initialize AXIDMA engine. AXIDMA engine must be initialized before |
| 586 | * AxiEthernet. During AXIDMA engine initialization, AXIDMA hardware is |
| 587 | * reset, and since AXIDMA reset line is connected to AxiEthernet, this |
| 588 | * would ensure a reset of AxiEthernet. |
| 589 | */ |
Michal Simek | 638c0ef | 2015-12-09 14:53:51 +0100 | [diff] [blame] | 590 | axi_dma_init(priv); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 591 | |
| 592 | /* Initialize AxiEthernet hardware. */ |
Ashok Reddy Soma | 645aa76 | 2021-06-24 00:34:41 -0600 | [diff] [blame] | 593 | if (priv->mactype == EMAC_1G) { |
| 594 | if (axi_ethernet_init(priv)) |
| 595 | return -1; |
| 596 | } else { |
| 597 | if (xxv_axi_ethernet_init(priv)) |
| 598 | return -1; |
| 599 | } |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 600 | |
| 601 | /* Disable all RX interrupts before RxBD space setup */ |
Siva Durga Prasad Paladugu | d227c9a | 2017-11-23 12:23:12 +0530 | [diff] [blame] | 602 | temp = readl(&priv->dmarx->control); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 603 | temp &= ~XAXIDMA_IRQ_ALL_MASK; |
Siva Durga Prasad Paladugu | d227c9a | 2017-11-23 12:23:12 +0530 | [diff] [blame] | 604 | writel(temp, &priv->dmarx->control); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 605 | |
| 606 | /* Start DMA RX channel. Now it's ready to receive data.*/ |
Vipul Kumar | 3b06a0f | 2018-01-23 14:52:35 +0530 | [diff] [blame] | 607 | axienet_dma_write(&rx_bd, &priv->dmarx->current); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 608 | |
| 609 | /* Setup the BD. */ |
| 610 | memset(&rx_bd, 0, sizeof(rx_bd)); |
Ashok Reddy Soma | 91d455a | 2020-09-03 08:36:43 -0600 | [diff] [blame] | 611 | rx_bd.next_desc = lower_32_bits((unsigned long)&rx_bd); |
| 612 | rx_bd.buf_addr = lower_32_bits((unsigned long)&rxframe); |
| 613 | #if defined(CONFIG_PHYS_64BIT) |
| 614 | rx_bd.next_desc_msb = upper_32_bits((unsigned long)&rx_bd); |
| 615 | rx_bd.buf_addr_msb = upper_32_bits((unsigned long)&rxframe); |
| 616 | #endif |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 617 | rx_bd.cntrl = sizeof(rxframe); |
| 618 | /* Flush the last BD so DMA core could see the updates */ |
Ashok Reddy Soma | f29a570 | 2020-09-03 08:36:44 -0600 | [diff] [blame] | 619 | flush_cache((phys_addr_t)&rx_bd, sizeof(rx_bd)); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 620 | |
| 621 | /* It is necessary to flush rxframe because if you don't do it |
| 622 | * then cache can contain uninitialized data */ |
Ashok Reddy Soma | f29a570 | 2020-09-03 08:36:44 -0600 | [diff] [blame] | 623 | flush_cache((phys_addr_t)&rxframe, sizeof(rxframe)); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 624 | |
| 625 | /* Start the hardware */ |
Siva Durga Prasad Paladugu | d227c9a | 2017-11-23 12:23:12 +0530 | [diff] [blame] | 626 | temp = readl(&priv->dmarx->control); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 627 | temp |= XAXIDMA_CR_RUNSTOP_MASK; |
Siva Durga Prasad Paladugu | d227c9a | 2017-11-23 12:23:12 +0530 | [diff] [blame] | 628 | writel(temp, &priv->dmarx->control); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 629 | |
| 630 | /* Rx BD is ready - start */ |
Vipul Kumar | 3b06a0f | 2018-01-23 14:52:35 +0530 | [diff] [blame] | 631 | axienet_dma_write(&rx_bd, &priv->dmarx->tail); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 632 | |
Ashok Reddy Soma | 645aa76 | 2021-06-24 00:34:41 -0600 | [diff] [blame] | 633 | if (priv->mactype == EMAC_1G) { |
| 634 | struct axi_regs *regs = priv->iobase; |
| 635 | /* Enable TX */ |
| 636 | writel(XAE_TC_TX_MASK, ®s->tc); |
| 637 | /* Enable RX */ |
| 638 | writel(XAE_RCW1_RX_MASK, ®s->rcw1); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 639 | |
Ashok Reddy Soma | 645aa76 | 2021-06-24 00:34:41 -0600 | [diff] [blame] | 640 | /* PHY setup */ |
| 641 | if (!setup_phy(dev)) { |
| 642 | axiemac_stop(dev); |
| 643 | return -1; |
| 644 | } |
| 645 | } else { |
| 646 | struct xxv_axi_regs *regs = (struct xxv_axi_regs *)priv->iobase; |
| 647 | /* Enable TX */ |
| 648 | writel(readl(®s->tc) | XXV_TC_TX_MASK, ®s->tc); |
| 649 | |
| 650 | /* Enable RX */ |
| 651 | writel(readl(®s->rcw1) | XXV_RCW1_RX_MASK, ®s->rcw1); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | debug("axiemac: Init complete\n"); |
| 655 | return 0; |
| 656 | } |
| 657 | |
Michal Simek | 682baac | 2015-12-08 15:44:41 +0100 | [diff] [blame] | 658 | static int axiemac_send(struct udevice *dev, void *ptr, int len) |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 659 | { |
Michal Simek | 682baac | 2015-12-08 15:44:41 +0100 | [diff] [blame] | 660 | struct axidma_priv *priv = dev_get_priv(dev); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 661 | u32 timeout; |
| 662 | |
| 663 | if (len > PKTSIZE_ALIGN) |
| 664 | len = PKTSIZE_ALIGN; |
| 665 | |
Ashok Reddy Soma | 645aa76 | 2021-06-24 00:34:41 -0600 | [diff] [blame] | 666 | /* If size is less than min packet size, pad to min size */ |
| 667 | if (priv->mactype == EMAC_10G_25G && len < XXV_MIN_PKT_SIZE) { |
| 668 | memset(txminframe, 0, XXV_MIN_PKT_SIZE); |
| 669 | memcpy(txminframe, ptr, len); |
| 670 | len = XXV_MIN_PKT_SIZE; |
| 671 | ptr = txminframe; |
| 672 | } |
| 673 | |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 674 | /* Flush packet to main memory to be trasfered by DMA */ |
Ashok Reddy Soma | f29a570 | 2020-09-03 08:36:44 -0600 | [diff] [blame] | 675 | flush_cache((phys_addr_t)ptr, len); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 676 | |
| 677 | /* Setup Tx BD */ |
| 678 | memset(&tx_bd, 0, sizeof(tx_bd)); |
| 679 | /* At the end of the ring, link the last BD back to the top */ |
Ashok Reddy Soma | 91d455a | 2020-09-03 08:36:43 -0600 | [diff] [blame] | 680 | tx_bd.next_desc = lower_32_bits((unsigned long)&tx_bd); |
| 681 | tx_bd.buf_addr = lower_32_bits((unsigned long)ptr); |
| 682 | #if defined(CONFIG_PHYS_64BIT) |
| 683 | tx_bd.next_desc_msb = upper_32_bits((unsigned long)&tx_bd); |
| 684 | tx_bd.buf_addr_msb = upper_32_bits((unsigned long)ptr); |
| 685 | #endif |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 686 | /* Save len */ |
| 687 | tx_bd.cntrl = len | XAXIDMA_BD_CTRL_TXSOF_MASK | |
| 688 | XAXIDMA_BD_CTRL_TXEOF_MASK; |
| 689 | |
| 690 | /* Flush the last BD so DMA core could see the updates */ |
Ashok Reddy Soma | f29a570 | 2020-09-03 08:36:44 -0600 | [diff] [blame] | 691 | flush_cache((phys_addr_t)&tx_bd, sizeof(tx_bd)); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 692 | |
Siva Durga Prasad Paladugu | d227c9a | 2017-11-23 12:23:12 +0530 | [diff] [blame] | 693 | if (readl(&priv->dmatx->status) & XAXIDMA_HALTED_MASK) { |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 694 | u32 temp; |
Vipul Kumar | 3b06a0f | 2018-01-23 14:52:35 +0530 | [diff] [blame] | 695 | axienet_dma_write(&tx_bd, &priv->dmatx->current); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 696 | /* Start the hardware */ |
Siva Durga Prasad Paladugu | d227c9a | 2017-11-23 12:23:12 +0530 | [diff] [blame] | 697 | temp = readl(&priv->dmatx->control); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 698 | temp |= XAXIDMA_CR_RUNSTOP_MASK; |
Siva Durga Prasad Paladugu | d227c9a | 2017-11-23 12:23:12 +0530 | [diff] [blame] | 699 | writel(temp, &priv->dmatx->control); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | /* Start transfer */ |
Vipul Kumar | 3b06a0f | 2018-01-23 14:52:35 +0530 | [diff] [blame] | 703 | axienet_dma_write(&tx_bd, &priv->dmatx->tail); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 704 | |
| 705 | /* Wait for transmission to complete */ |
| 706 | debug("axiemac: Waiting for tx to be done\n"); |
| 707 | timeout = 200; |
Siva Durga Prasad Paladugu | d227c9a | 2017-11-23 12:23:12 +0530 | [diff] [blame] | 708 | while (timeout && (!(readl(&priv->dmatx->status) & |
Michal Simek | 5aa4539 | 2015-10-28 11:00:47 +0100 | [diff] [blame] | 709 | (XAXIDMA_IRQ_DELAY_MASK | XAXIDMA_IRQ_IOC_MASK)))) { |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 710 | timeout--; |
| 711 | udelay(1); |
| 712 | } |
| 713 | if (!timeout) { |
| 714 | printf("%s: Timeout\n", __func__); |
| 715 | return 1; |
| 716 | } |
| 717 | |
| 718 | debug("axiemac: Sending complete\n"); |
| 719 | return 0; |
| 720 | } |
| 721 | |
Michal Simek | 638c0ef | 2015-12-09 14:53:51 +0100 | [diff] [blame] | 722 | static int isrxready(struct axidma_priv *priv) |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 723 | { |
| 724 | u32 status; |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 725 | |
| 726 | /* Read pending interrupts */ |
Siva Durga Prasad Paladugu | d227c9a | 2017-11-23 12:23:12 +0530 | [diff] [blame] | 727 | status = readl(&priv->dmarx->status); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 728 | |
| 729 | /* Acknowledge pending interrupts */ |
Siva Durga Prasad Paladugu | d227c9a | 2017-11-23 12:23:12 +0530 | [diff] [blame] | 730 | writel(status & XAXIDMA_IRQ_ALL_MASK, &priv->dmarx->status); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 731 | |
| 732 | /* |
| 733 | * If Reception done interrupt is asserted, call RX call back function |
| 734 | * to handle the processed BDs and then raise the according flag. |
| 735 | */ |
| 736 | if ((status & (XAXIDMA_IRQ_DELAY_MASK | XAXIDMA_IRQ_IOC_MASK))) |
| 737 | return 1; |
| 738 | |
| 739 | return 0; |
| 740 | } |
| 741 | |
Michal Simek | 682baac | 2015-12-08 15:44:41 +0100 | [diff] [blame] | 742 | static int axiemac_recv(struct udevice *dev, int flags, uchar **packetp) |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 743 | { |
| 744 | u32 length; |
Michal Simek | 682baac | 2015-12-08 15:44:41 +0100 | [diff] [blame] | 745 | struct axidma_priv *priv = dev_get_priv(dev); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 746 | u32 temp; |
| 747 | |
| 748 | /* Wait for an incoming packet */ |
Michal Simek | 638c0ef | 2015-12-09 14:53:51 +0100 | [diff] [blame] | 749 | if (!isrxready(priv)) |
Maksim Kiselev | 3789b99 | 2023-07-19 09:53:37 +0300 | [diff] [blame] | 750 | return -EAGAIN; |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 751 | |
| 752 | debug("axiemac: RX data ready\n"); |
| 753 | |
| 754 | /* Disable IRQ for a moment till packet is handled */ |
Siva Durga Prasad Paladugu | d227c9a | 2017-11-23 12:23:12 +0530 | [diff] [blame] | 755 | temp = readl(&priv->dmarx->control); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 756 | temp &= ~XAXIDMA_IRQ_ALL_MASK; |
Siva Durga Prasad Paladugu | d227c9a | 2017-11-23 12:23:12 +0530 | [diff] [blame] | 757 | writel(temp, &priv->dmarx->control); |
Ashok Reddy Soma | 645aa76 | 2021-06-24 00:34:41 -0600 | [diff] [blame] | 758 | if (!priv->eth_hasnobuf && priv->mactype == EMAC_1G) |
Siva Durga Prasad Paladugu | f802603 | 2017-01-06 16:27:15 +0530 | [diff] [blame] | 759 | length = rx_bd.app4 & 0xFFFF; /* max length mask */ |
| 760 | else |
| 761 | length = rx_bd.status & XAXIDMA_BD_STS_ACTUAL_LEN_MASK; |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 762 | |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 763 | #ifdef DEBUG |
| 764 | print_buffer(&rxframe, &rxframe[0], 1, length, 16); |
| 765 | #endif |
Michal Simek | 0305be8 | 2015-12-09 14:13:23 +0100 | [diff] [blame] | 766 | |
| 767 | *packetp = rxframe; |
| 768 | return length; |
| 769 | } |
| 770 | |
| 771 | static int axiemac_free_pkt(struct udevice *dev, uchar *packet, int length) |
| 772 | { |
| 773 | struct axidma_priv *priv = dev_get_priv(dev); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 774 | |
| 775 | #ifdef DEBUG |
| 776 | /* It is useful to clear buffer to be sure that it is consistent */ |
| 777 | memset(rxframe, 0, sizeof(rxframe)); |
| 778 | #endif |
| 779 | /* Setup RxBD */ |
| 780 | /* Clear the whole buffer and setup it again - all flags are cleared */ |
| 781 | memset(&rx_bd, 0, sizeof(rx_bd)); |
Ashok Reddy Soma | 91d455a | 2020-09-03 08:36:43 -0600 | [diff] [blame] | 782 | rx_bd.next_desc = lower_32_bits((unsigned long)&rx_bd); |
| 783 | rx_bd.buf_addr = lower_32_bits((unsigned long)&rxframe); |
| 784 | #if defined(CONFIG_PHYS_64BIT) |
| 785 | rx_bd.next_desc_msb = upper_32_bits((unsigned long)&rx_bd); |
| 786 | rx_bd.buf_addr_msb = upper_32_bits((unsigned long)&rxframe); |
| 787 | #endif |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 788 | rx_bd.cntrl = sizeof(rxframe); |
| 789 | |
| 790 | /* Write bd to HW */ |
Ashok Reddy Soma | f29a570 | 2020-09-03 08:36:44 -0600 | [diff] [blame] | 791 | flush_cache((phys_addr_t)&rx_bd, sizeof(rx_bd)); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 792 | |
| 793 | /* It is necessary to flush rxframe because if you don't do it |
| 794 | * then cache will contain previous packet */ |
Ashok Reddy Soma | f29a570 | 2020-09-03 08:36:44 -0600 | [diff] [blame] | 795 | flush_cache((phys_addr_t)&rxframe, sizeof(rxframe)); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 796 | |
| 797 | /* Rx BD is ready - start again */ |
Vipul Kumar | 3b06a0f | 2018-01-23 14:52:35 +0530 | [diff] [blame] | 798 | axienet_dma_write(&rx_bd, &priv->dmarx->tail); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 799 | |
| 800 | debug("axiemac: RX completed, framelength = %d\n", length); |
| 801 | |
Michal Simek | 682baac | 2015-12-08 15:44:41 +0100 | [diff] [blame] | 802 | return 0; |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 803 | } |
| 804 | |
Michal Simek | 682baac | 2015-12-08 15:44:41 +0100 | [diff] [blame] | 805 | static int axiemac_miiphy_read(struct mii_dev *bus, int addr, |
| 806 | int devad, int reg) |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 807 | { |
Michal Simek | 682baac | 2015-12-08 15:44:41 +0100 | [diff] [blame] | 808 | int ret; |
| 809 | u16 value; |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 810 | |
Michal Simek | 682baac | 2015-12-08 15:44:41 +0100 | [diff] [blame] | 811 | ret = phyread(bus->priv, addr, reg, &value); |
| 812 | debug("axiemac: Read MII 0x%x, 0x%x, 0x%x, %d\n", addr, reg, |
| 813 | value, ret); |
| 814 | return value; |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 815 | } |
| 816 | |
Michal Simek | 682baac | 2015-12-08 15:44:41 +0100 | [diff] [blame] | 817 | static int axiemac_miiphy_write(struct mii_dev *bus, int addr, int devad, |
| 818 | int reg, u16 value) |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 819 | { |
Michal Simek | 682baac | 2015-12-08 15:44:41 +0100 | [diff] [blame] | 820 | debug("axiemac: Write MII 0x%x, 0x%x, 0x%x\n", addr, reg, value); |
| 821 | return phywrite(bus->priv, addr, reg, value); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 822 | } |
| 823 | |
Michal Simek | 682baac | 2015-12-08 15:44:41 +0100 | [diff] [blame] | 824 | static int axi_emac_probe(struct udevice *dev) |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 825 | { |
Ashok Reddy Soma | 3c4df95 | 2021-06-24 00:34:40 -0600 | [diff] [blame] | 826 | struct axidma_plat *plat = dev_get_plat(dev); |
| 827 | struct eth_pdata *pdata = &plat->eth_pdata; |
Michal Simek | 682baac | 2015-12-08 15:44:41 +0100 | [diff] [blame] | 828 | struct axidma_priv *priv = dev_get_priv(dev); |
| 829 | int ret; |
| 830 | |
Ashok Reddy Soma | 3c4df95 | 2021-06-24 00:34:40 -0600 | [diff] [blame] | 831 | priv->iobase = (struct axi_regs *)pdata->iobase; |
| 832 | priv->dmatx = plat->dmatx; |
| 833 | /* RX channel offset is 0x30 */ |
| 834 | priv->dmarx = (struct axidma_reg *)((phys_addr_t)priv->dmatx + 0x30); |
Ashok Reddy Soma | 645aa76 | 2021-06-24 00:34:41 -0600 | [diff] [blame] | 835 | priv->mactype = plat->mactype; |
Ashok Reddy Soma | 3c4df95 | 2021-06-24 00:34:40 -0600 | [diff] [blame] | 836 | |
Ashok Reddy Soma | 645aa76 | 2021-06-24 00:34:41 -0600 | [diff] [blame] | 837 | if (priv->mactype == EMAC_1G) { |
| 838 | priv->eth_hasnobuf = plat->eth_hasnobuf; |
Andy Chiu | 58af7eb | 2022-11-01 11:57:59 +0800 | [diff] [blame] | 839 | priv->pcsaddr = plat->pcsaddr; |
Ashok Reddy Soma | 645aa76 | 2021-06-24 00:34:41 -0600 | [diff] [blame] | 840 | priv->phyaddr = plat->phyaddr; |
Maxim Kochetkov | 61cd6fd | 2023-08-11 10:43:51 +0300 | [diff] [blame] | 841 | priv->phynode = plat->phynode; |
Ashok Reddy Soma | 645aa76 | 2021-06-24 00:34:41 -0600 | [diff] [blame] | 842 | priv->interface = pdata->phy_interface; |
Michal Simek | 682baac | 2015-12-08 15:44:41 +0100 | [diff] [blame] | 843 | |
T Karthik Reddy | 4a3f40b | 2022-05-10 13:26:09 +0200 | [diff] [blame] | 844 | if (IS_ENABLED(CONFIG_DM_ETH_PHY)) |
| 845 | priv->bus = eth_phy_get_mdio_bus(dev); |
Ashok Reddy Soma | 645aa76 | 2021-06-24 00:34:41 -0600 | [diff] [blame] | 846 | |
T Karthik Reddy | 4a3f40b | 2022-05-10 13:26:09 +0200 | [diff] [blame] | 847 | if (!priv->bus) { |
| 848 | priv->bus = mdio_alloc(); |
| 849 | priv->bus->read = axiemac_miiphy_read; |
| 850 | priv->bus->write = axiemac_miiphy_write; |
| 851 | priv->bus->priv = priv; |
| 852 | |
| 853 | ret = mdio_register_seq(priv->bus, dev_seq(dev)); |
| 854 | if (ret) |
| 855 | return ret; |
| 856 | } |
| 857 | |
| 858 | if (IS_ENABLED(CONFIG_DM_ETH_PHY)) |
| 859 | eth_phy_set_mdio_bus(dev, priv->bus); |
Michal Simek | 682baac | 2015-12-08 15:44:41 +0100 | [diff] [blame] | 860 | |
Ashok Reddy Soma | 645aa76 | 2021-06-24 00:34:41 -0600 | [diff] [blame] | 861 | axiemac_phy_init(dev); |
| 862 | } |
Michal Simek | 0b13ee2 | 2015-12-08 16:10:05 +0100 | [diff] [blame] | 863 | |
T Karthik Reddy | 4a3f40b | 2022-05-10 13:26:09 +0200 | [diff] [blame] | 864 | printf("AXI EMAC: %lx, phyaddr %d, interface %s\n", (ulong)pdata->iobase, |
| 865 | priv->phyaddr, phy_string_for_interface(pdata->phy_interface)); |
| 866 | |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 867 | return 0; |
| 868 | } |
| 869 | |
Michal Simek | 682baac | 2015-12-08 15:44:41 +0100 | [diff] [blame] | 870 | static int axi_emac_remove(struct udevice *dev) |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 871 | { |
Michal Simek | 682baac | 2015-12-08 15:44:41 +0100 | [diff] [blame] | 872 | struct axidma_priv *priv = dev_get_priv(dev); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 873 | |
Ashok Reddy Soma | 645aa76 | 2021-06-24 00:34:41 -0600 | [diff] [blame] | 874 | if (priv->mactype == EMAC_1G) { |
| 875 | free(priv->phydev); |
| 876 | mdio_unregister(priv->bus); |
| 877 | mdio_free(priv->bus); |
| 878 | } |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 879 | |
Michal Simek | 682baac | 2015-12-08 15:44:41 +0100 | [diff] [blame] | 880 | return 0; |
| 881 | } |
| 882 | |
| 883 | static const struct eth_ops axi_emac_ops = { |
Michal Simek | 8fbf79f | 2015-12-16 09:18:12 +0100 | [diff] [blame] | 884 | .start = axiemac_start, |
Michal Simek | 682baac | 2015-12-08 15:44:41 +0100 | [diff] [blame] | 885 | .send = axiemac_send, |
| 886 | .recv = axiemac_recv, |
Michal Simek | 0305be8 | 2015-12-09 14:13:23 +0100 | [diff] [blame] | 887 | .free_pkt = axiemac_free_pkt, |
Michal Simek | 8fbf79f | 2015-12-16 09:18:12 +0100 | [diff] [blame] | 888 | .stop = axiemac_stop, |
| 889 | .write_hwaddr = axiemac_write_hwaddr, |
Michal Simek | 682baac | 2015-12-08 15:44:41 +0100 | [diff] [blame] | 890 | }; |
| 891 | |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 892 | static int axi_emac_of_to_plat(struct udevice *dev) |
Michal Simek | 682baac | 2015-12-08 15:44:41 +0100 | [diff] [blame] | 893 | { |
Ashok Reddy Soma | 3c4df95 | 2021-06-24 00:34:40 -0600 | [diff] [blame] | 894 | struct axidma_plat *plat = dev_get_plat(dev); |
| 895 | struct eth_pdata *pdata = &plat->eth_pdata; |
Maxim Kochetkov | 61cd6fd | 2023-08-11 10:43:51 +0300 | [diff] [blame] | 896 | struct ofnode_phandle_args pcs_node, axistream_node; |
| 897 | ofnode phynode; |
| 898 | int ret; |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 899 | |
Masahiro Yamada | a89b4de | 2020-07-17 14:36:48 +0900 | [diff] [blame] | 900 | pdata->iobase = dev_read_addr(dev); |
Ashok Reddy Soma | 645aa76 | 2021-06-24 00:34:41 -0600 | [diff] [blame] | 901 | plat->mactype = dev_get_driver_data(dev); |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 902 | |
Maxim Kochetkov | 61cd6fd | 2023-08-11 10:43:51 +0300 | [diff] [blame] | 903 | ret = dev_read_phandle_with_args(dev, "axistream-connected", NULL, 0, 0, |
| 904 | &axistream_node); |
Mayuresh Chitale | 69e5104 | 2023-11-16 22:10:24 +0530 | [diff] [blame] | 905 | if (!ret) |
| 906 | plat->dmatx = (struct axidma_reg *)ofnode_get_addr(axistream_node.node); |
| 907 | else |
| 908 | plat->dmatx = (struct axidma_reg *)dev_read_addr_index(dev, 1); |
Maxim Kochetkov | 61cd6fd | 2023-08-11 10:43:51 +0300 | [diff] [blame] | 909 | |
Ashok Reddy Soma | 3c4df95 | 2021-06-24 00:34:40 -0600 | [diff] [blame] | 910 | if (!plat->dmatx) { |
Michal Simek | 682baac | 2015-12-08 15:44:41 +0100 | [diff] [blame] | 911 | printf("%s: axi_dma register space not found\n", __func__); |
| 912 | return -EINVAL; |
| 913 | } |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 914 | |
Ashok Reddy Soma | 645aa76 | 2021-06-24 00:34:41 -0600 | [diff] [blame] | 915 | if (plat->mactype == EMAC_1G) { |
| 916 | plat->phyaddr = -1; |
Andy Chiu | 58af7eb | 2022-11-01 11:57:59 +0800 | [diff] [blame] | 917 | /* PHYAD 0 always redirects to the PCS/PMA PHY */ |
| 918 | plat->pcsaddr = 0; |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 919 | |
Maxim Kochetkov | 61cd6fd | 2023-08-11 10:43:51 +0300 | [diff] [blame] | 920 | phynode = dev_get_phy_node(dev); |
| 921 | if (ofnode_valid(phynode)) { |
T Karthik Reddy | 4a3f40b | 2022-05-10 13:26:09 +0200 | [diff] [blame] | 922 | if (!(IS_ENABLED(CONFIG_DM_ETH_PHY))) |
Maxim Kochetkov | 61cd6fd | 2023-08-11 10:43:51 +0300 | [diff] [blame] | 923 | plat->phyaddr = ofnode_read_u32_default(phynode, |
| 924 | "reg", -1); |
| 925 | plat->phynode = phynode; |
Ashok Reddy Soma | 645aa76 | 2021-06-24 00:34:41 -0600 | [diff] [blame] | 926 | } |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 927 | |
Marek BehĂșn | bc19477 | 2022-04-07 00:33:01 +0200 | [diff] [blame] | 928 | pdata->phy_interface = dev_read_phy_mode(dev); |
Marek BehĂșn | 48631e4 | 2022-04-07 00:33:03 +0200 | [diff] [blame] | 929 | if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) |
Ashok Reddy Soma | 645aa76 | 2021-06-24 00:34:41 -0600 | [diff] [blame] | 930 | return -EINVAL; |
Michal Simek | 682baac | 2015-12-08 15:44:41 +0100 | [diff] [blame] | 931 | |
Maxim Kochetkov | 61cd6fd | 2023-08-11 10:43:51 +0300 | [diff] [blame] | 932 | plat->eth_hasnobuf = dev_read_bool(dev, "xlnx,eth-hasnobuf"); |
Andy Chiu | 58af7eb | 2022-11-01 11:57:59 +0800 | [diff] [blame] | 933 | |
| 934 | if (pdata->phy_interface == PHY_INTERFACE_MODE_SGMII || |
| 935 | pdata->phy_interface == PHY_INTERFACE_MODE_1000BASEX) { |
Maxim Kochetkov | 61cd6fd | 2023-08-11 10:43:51 +0300 | [diff] [blame] | 936 | ret = dev_read_phandle_with_args(dev, "pcs-handle", NULL, 0, 0, |
| 937 | &pcs_node); |
| 938 | if (!ret) { |
| 939 | plat->pcsaddr = ofnode_read_u32_default(pcs_node.node, |
| 940 | "reg", -1); |
Andy Chiu | 58af7eb | 2022-11-01 11:57:59 +0800 | [diff] [blame] | 941 | } |
| 942 | } |
Ashok Reddy Soma | 645aa76 | 2021-06-24 00:34:41 -0600 | [diff] [blame] | 943 | } |
Siva Durga Prasad Paladugu | f802603 | 2017-01-06 16:27:15 +0530 | [diff] [blame] | 944 | |
Michal Simek | 682baac | 2015-12-08 15:44:41 +0100 | [diff] [blame] | 945 | return 0; |
Michal Simek | 6fc7c45 | 2011-10-06 20:35:35 +0000 | [diff] [blame] | 946 | } |
Michal Simek | 682baac | 2015-12-08 15:44:41 +0100 | [diff] [blame] | 947 | |
| 948 | static const struct udevice_id axi_emac_ids[] = { |
Ashok Reddy Soma | 645aa76 | 2021-06-24 00:34:41 -0600 | [diff] [blame] | 949 | { .compatible = "xlnx,axi-ethernet-1.00.a", .data = (uintptr_t)EMAC_1G }, |
| 950 | { .compatible = "xlnx,xxv-ethernet-1.0", .data = (uintptr_t)EMAC_10G_25G }, |
Michal Simek | 682baac | 2015-12-08 15:44:41 +0100 | [diff] [blame] | 951 | { } |
| 952 | }; |
| 953 | |
| 954 | U_BOOT_DRIVER(axi_emac) = { |
| 955 | .name = "axi_emac", |
| 956 | .id = UCLASS_ETH, |
| 957 | .of_match = axi_emac_ids, |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 958 | .of_to_plat = axi_emac_of_to_plat, |
Michal Simek | 682baac | 2015-12-08 15:44:41 +0100 | [diff] [blame] | 959 | .probe = axi_emac_probe, |
| 960 | .remove = axi_emac_remove, |
| 961 | .ops = &axi_emac_ops, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 962 | .priv_auto = sizeof(struct axidma_priv), |
Ashok Reddy Soma | 3c4df95 | 2021-06-24 00:34:40 -0600 | [diff] [blame] | 963 | .plat_auto = sizeof(struct axidma_plat), |
Michal Simek | 682baac | 2015-12-08 15:44:41 +0100 | [diff] [blame] | 964 | }; |