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