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