blob: cfc60824756447fe894a4cc8b2f534c2b1239fc6 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Michal Simek4f1ec4c2011-10-06 20:35:35 +00002/*
3 * Copyright (C) 2011 Michal Simek <monstr@monstr.eu>
4 * Copyright (C) 2011 PetaLogix
5 * Copyright (C) 2010 Xilinx, Inc. All rights reserved.
Michal Simek4f1ec4c2011-10-06 20:35:35 +00006 */
7
8#include <config.h>
9#include <common.h>
Simon Glass1eb69ae2019-11-14 12:57:39 -070010#include <cpu_func.h>
Michal Simek75cc93f2015-12-08 15:44:41 +010011#include <dm.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060012#include <log.h>
Michal Simek4f1ec4c2011-10-06 20:35:35 +000013#include <net.h>
14#include <malloc.h>
Simon Glass401d1c42020-10-30 21:38:53 -060015#include <asm/global_data.h>
Michal Simek4f1ec4c2011-10-06 20:35:35 +000016#include <asm/io.h>
17#include <phy.h>
18#include <miiphy.h>
Siva Durga Prasad Paladugud02a0b12017-01-06 16:18:50 +053019#include <wait_bit.h>
Simon Glassc05ed002020-05-10 11:40:11 -060020#include <linux/delay.h>
Michal Simek4f1ec4c2011-10-06 20:35:35 +000021
Michal Simek75cc93f2015-12-08 15:44:41 +010022DECLARE_GLOBAL_DATA_PTR;
23
Michal Simek4f1ec4c2011-10-06 20:35:35 +000024/* Link setup */
25#define XAE_EMMC_LINKSPEED_MASK 0xC0000000 /* Link speed */
26#define XAE_EMMC_LINKSPD_10 0x00000000 /* Link Speed mask for 10 Mbit */
27#define XAE_EMMC_LINKSPD_100 0x40000000 /* Link Speed mask for 100 Mbit */
28#define XAE_EMMC_LINKSPD_1000 0x80000000 /* Link Speed mask for 1000 Mbit */
29
30/* Interrupt Status/Enable/Mask Registers bit definitions */
31#define XAE_INT_RXRJECT_MASK 0x00000008 /* Rx frame rejected */
32#define XAE_INT_MGTRDY_MASK 0x00000080 /* MGT clock Lock */
33
34/* Receive Configuration Word 1 (RCW1) Register bit definitions */
35#define XAE_RCW1_RX_MASK 0x10000000 /* Receiver enable */
36
37/* Transmitter Configuration (TC) Register bit definitions */
38#define XAE_TC_TX_MASK 0x10000000 /* Transmitter enable */
39
40#define XAE_UAW1_UNICASTADDR_MASK 0x0000FFFF
41
42/* MDIO Management Configuration (MC) Register bit definitions */
43#define XAE_MDIO_MC_MDIOEN_MASK 0x00000040 /* MII management enable*/
44
45/* MDIO Management Control Register (MCR) Register bit definitions */
46#define XAE_MDIO_MCR_PHYAD_MASK 0x1F000000 /* Phy Address Mask */
47#define XAE_MDIO_MCR_PHYAD_SHIFT 24 /* Phy Address Shift */
48#define XAE_MDIO_MCR_REGAD_MASK 0x001F0000 /* Reg Address Mask */
49#define XAE_MDIO_MCR_REGAD_SHIFT 16 /* Reg Address Shift */
50#define XAE_MDIO_MCR_OP_READ_MASK 0x00008000 /* Op Code Read Mask */
51#define XAE_MDIO_MCR_OP_WRITE_MASK 0x00004000 /* Op Code Write Mask */
52#define XAE_MDIO_MCR_INITIATE_MASK 0x00000800 /* Ready Mask */
53#define XAE_MDIO_MCR_READY_MASK 0x00000080 /* Ready Mask */
54
55#define XAE_MDIO_DIV_DFT 29 /* Default MDIO clock divisor */
56
Siva Durga Prasad Paladugu89ce5a92017-01-06 16:27:15 +053057#define XAXIDMA_BD_STS_ACTUAL_LEN_MASK 0x007FFFFF /* Actual len */
58
Michal Simek4f1ec4c2011-10-06 20:35:35 +000059/* DMA macros */
60/* Bitmasks of XAXIDMA_CR_OFFSET register */
61#define XAXIDMA_CR_RUNSTOP_MASK 0x00000001 /* Start/stop DMA channel */
62#define XAXIDMA_CR_RESET_MASK 0x00000004 /* Reset DMA engine */
63
64/* Bitmasks of XAXIDMA_SR_OFFSET register */
65#define XAXIDMA_HALTED_MASK 0x00000001 /* DMA channel halted */
66
67/* Bitmask for interrupts */
68#define XAXIDMA_IRQ_IOC_MASK 0x00001000 /* Completion intr */
69#define XAXIDMA_IRQ_DELAY_MASK 0x00002000 /* Delay interrupt */
70#define XAXIDMA_IRQ_ALL_MASK 0x00007000 /* All interrupts */
71
72/* Bitmasks of XAXIDMA_BD_CTRL_OFFSET register */
73#define XAXIDMA_BD_CTRL_TXSOF_MASK 0x08000000 /* First tx packet */
74#define XAXIDMA_BD_CTRL_TXEOF_MASK 0x04000000 /* Last tx packet */
75
76#define DMAALIGN 128
77
78static u8 rxframe[PKTSIZE_ALIGN] __attribute((aligned(DMAALIGN)));
79
80/* Reflect dma offsets */
81struct axidma_reg {
82 u32 control; /* DMACR */
83 u32 status; /* DMASR */
Vipul Kumar047f3bf2018-01-23 14:52:35 +053084 u32 current; /* CURDESC low 32 bit */
85 u32 current_hi; /* CURDESC high 32 bit */
86 u32 tail; /* TAILDESC low 32 bit */
87 u32 tail_hi; /* TAILDESC high 32 bit */
Michal Simek4f1ec4c2011-10-06 20:35:35 +000088};
89
Ashok Reddy Soma215f2062021-06-24 00:34:40 -060090/* Platform data structures */
91struct axidma_plat {
92 struct eth_pdata eth_pdata;
93 struct axidma_reg *dmatx;
94 struct axidma_reg *dmarx;
95 int phyaddr;
96 u8 eth_hasnobuf;
97 int phy_of_handle;
98};
99
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000100/* Private driver structures */
101struct axidma_priv {
102 struct axidma_reg *dmatx;
103 struct axidma_reg *dmarx;
104 int phyaddr;
Michal Simek6609f352015-12-09 14:39:42 +0100105 struct axi_regs *iobase;
Michal Simek75cc93f2015-12-08 15:44:41 +0100106 phy_interface_t interface;
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000107 struct phy_device *phydev;
108 struct mii_dev *bus;
Siva Durga Prasad Paladugu89ce5a92017-01-06 16:27:15 +0530109 u8 eth_hasnobuf;
Siva Durga Prasad Paladugufccfb712019-03-15 17:46:45 +0530110 int phy_of_handle;
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000111};
112
113/* BD descriptors */
114struct axidma_bd {
Ashok Reddy Somaf9d3b312020-09-03 08:36:43 -0600115 u32 next_desc; /* Next descriptor pointer */
116 u32 next_desc_msb;
117 u32 buf_addr; /* Buffer address */
118 u32 buf_addr_msb;
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000119 u32 reserved3;
120 u32 reserved4;
121 u32 cntrl; /* Control */
122 u32 status; /* Status */
123 u32 app0;
124 u32 app1; /* TX start << 16 | insert */
125 u32 app2; /* TX csum seed */
126 u32 app3;
127 u32 app4;
128 u32 sw_id_offset;
129 u32 reserved5;
130 u32 reserved6;
131};
132
133/* Static BDs - driver uses only one BD */
134static struct axidma_bd tx_bd __attribute((aligned(DMAALIGN)));
135static struct axidma_bd rx_bd __attribute((aligned(DMAALIGN)));
136
137struct axi_regs {
138 u32 reserved[3];
139 u32 is; /* 0xC: Interrupt status */
140 u32 reserved2;
141 u32 ie; /* 0x14: Interrupt enable */
142 u32 reserved3[251];
143 u32 rcw1; /* 0x404: Rx Configuration Word 1 */
144 u32 tc; /* 0x408: Tx Configuration */
145 u32 reserved4;
146 u32 emmc; /* 0x410: EMAC mode configuration */
147 u32 reserved5[59];
148 u32 mdio_mc; /* 0x500: MII Management Config */
149 u32 mdio_mcr; /* 0x504: MII Management Control */
150 u32 mdio_mwd; /* 0x508: MII Management Write Data */
151 u32 mdio_mrd; /* 0x50C: MII Management Read Data */
152 u32 reserved6[124];
153 u32 uaw0; /* 0x700: Unicast address word 0 */
154 u32 uaw1; /* 0x704: Unicast address word 1 */
155};
156
157/* Use MII register 1 (MII status register) to detect PHY */
158#define PHY_DETECT_REG 1
159
160/*
161 * Mask used to verify certain PHY features (or register contents)
162 * in the register above:
163 * 0x1000: 10Mbps full duplex support
164 * 0x0800: 10Mbps half duplex support
165 * 0x0008: Auto-negotiation support
166 */
167#define PHY_DETECT_MASK 0x1808
168
Michal Simekf36bbcc2015-12-09 14:36:31 +0100169static inline int mdio_wait(struct axi_regs *regs)
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000170{
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000171 u32 timeout = 200;
172
173 /* Wait till MDIO interface is ready to accept a new transaction. */
Siva Durga Prasad Paladugua04a5da2017-11-23 12:23:12 +0530174 while (timeout && (!(readl(&regs->mdio_mcr)
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000175 & XAE_MDIO_MCR_READY_MASK))) {
176 timeout--;
177 udelay(1);
178 }
179 if (!timeout) {
180 printf("%s: Timeout\n", __func__);
181 return 1;
182 }
183 return 0;
184}
185
Vipul Kumar047f3bf2018-01-23 14:52:35 +0530186/**
187 * axienet_dma_write - Memory mapped Axi DMA register Buffer Descriptor write.
188 * @bd: pointer to BD descriptor structure
189 * @desc: Address offset of DMA descriptors
190 *
191 * This function writes the value into the corresponding Axi DMA register.
192 */
193static inline void axienet_dma_write(struct axidma_bd *bd, u32 *desc)
194{
195#if defined(CONFIG_PHYS_64BIT)
Ashok Reddy Somaf9d3b312020-09-03 08:36:43 -0600196 writeq((unsigned long)bd, desc);
Vipul Kumar047f3bf2018-01-23 14:52:35 +0530197#else
198 writel((u32)bd, desc);
199#endif
200}
201
Michal Simek0d78abf2015-12-09 14:44:38 +0100202static u32 phyread(struct axidma_priv *priv, u32 phyaddress, u32 registernum,
203 u16 *val)
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000204{
Michal Simek0d78abf2015-12-09 14:44:38 +0100205 struct axi_regs *regs = priv->iobase;
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000206 u32 mdioctrlreg = 0;
207
Michal Simekf36bbcc2015-12-09 14:36:31 +0100208 if (mdio_wait(regs))
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000209 return 1;
210
211 mdioctrlreg = ((phyaddress << XAE_MDIO_MCR_PHYAD_SHIFT) &
212 XAE_MDIO_MCR_PHYAD_MASK) |
213 ((registernum << XAE_MDIO_MCR_REGAD_SHIFT)
214 & XAE_MDIO_MCR_REGAD_MASK) |
215 XAE_MDIO_MCR_INITIATE_MASK |
216 XAE_MDIO_MCR_OP_READ_MASK;
217
Siva Durga Prasad Paladugua04a5da2017-11-23 12:23:12 +0530218 writel(mdioctrlreg, &regs->mdio_mcr);
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000219
Michal Simekf36bbcc2015-12-09 14:36:31 +0100220 if (mdio_wait(regs))
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000221 return 1;
222
223 /* Read data */
Siva Durga Prasad Paladugua04a5da2017-11-23 12:23:12 +0530224 *val = readl(&regs->mdio_mrd);
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000225 return 0;
226}
227
Michal Simek0d78abf2015-12-09 14:44:38 +0100228static u32 phywrite(struct axidma_priv *priv, u32 phyaddress, u32 registernum,
229 u32 data)
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000230{
Michal Simek0d78abf2015-12-09 14:44:38 +0100231 struct axi_regs *regs = priv->iobase;
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000232 u32 mdioctrlreg = 0;
233
Michal Simekf36bbcc2015-12-09 14:36:31 +0100234 if (mdio_wait(regs))
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000235 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_WRITE_MASK;
243
244 /* Write data */
Siva Durga Prasad Paladugua04a5da2017-11-23 12:23:12 +0530245 writel(data, &regs->mdio_mwd);
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000246
Siva Durga Prasad Paladugua04a5da2017-11-23 12:23:12 +0530247 writel(mdioctrlreg, &regs->mdio_mcr);
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000248
Michal Simekf36bbcc2015-12-09 14:36:31 +0100249 if (mdio_wait(regs))
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000250 return 1;
251
252 return 0;
253}
254
Michal Simek5d0449d2015-12-08 16:10:05 +0100255static int axiemac_phy_init(struct udevice *dev)
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000256{
257 u16 phyreg;
Patrick van Gelder945a5502020-06-03 14:18:04 +0200258 int i;
259 u32 ret;
Michal Simek75cc93f2015-12-08 15:44:41 +0100260 struct axidma_priv *priv = dev_get_priv(dev);
Michal Simek6609f352015-12-09 14:39:42 +0100261 struct axi_regs *regs = priv->iobase;
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000262 struct phy_device *phydev;
263
264 u32 supported = SUPPORTED_10baseT_Half |
265 SUPPORTED_10baseT_Full |
266 SUPPORTED_100baseT_Half |
267 SUPPORTED_100baseT_Full |
268 SUPPORTED_1000baseT_Half |
269 SUPPORTED_1000baseT_Full;
270
Michal Simek5d0449d2015-12-08 16:10:05 +0100271 /* Set default MDIO divisor */
Siva Durga Prasad Paladugua04a5da2017-11-23 12:23:12 +0530272 writel(XAE_MDIO_DIV_DFT | XAE_MDIO_MC_MDIOEN_MASK, &regs->mdio_mc);
Michal Simek5d0449d2015-12-08 16:10:05 +0100273
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000274 if (priv->phyaddr == -1) {
275 /* Detect the PHY address */
276 for (i = 31; i >= 0; i--) {
Michal Simek0d78abf2015-12-09 14:44:38 +0100277 ret = phyread(priv, i, PHY_DETECT_REG, &phyreg);
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000278 if (!ret && (phyreg != 0xFFFF) &&
279 ((phyreg & PHY_DETECT_MASK) == PHY_DETECT_MASK)) {
280 /* Found a valid PHY address */
281 priv->phyaddr = i;
282 debug("axiemac: Found valid phy address, %x\n",
Michal Simek2652a622015-12-09 10:54:53 +0100283 i);
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000284 break;
285 }
286 }
287 }
288
289 /* Interface - look at tsec */
Siva Durga Prasad Paladugu9c0da762016-02-21 15:46:14 +0530290 phydev = phy_connect(priv->bus, priv->phyaddr, dev, priv->interface);
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000291
292 phydev->supported &= supported;
293 phydev->advertising = phydev->supported;
294 priv->phydev = phydev;
Siva Durga Prasad Paladugufccfb712019-03-15 17:46:45 +0530295 if (priv->phy_of_handle)
296 priv->phydev->node = offset_to_ofnode(priv->phy_of_handle);
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000297 phy_config(phydev);
Michal Simek5d0449d2015-12-08 16:10:05 +0100298
299 return 0;
300}
301
302/* Setting axi emac and phy to proper setting */
303static int setup_phy(struct udevice *dev)
304{
Siva Durga Prasad Paladugu8964f242016-02-21 15:46:15 +0530305 u16 temp;
306 u32 speed, emmc_reg, ret;
Michal Simek5d0449d2015-12-08 16:10:05 +0100307 struct axidma_priv *priv = dev_get_priv(dev);
308 struct axi_regs *regs = priv->iobase;
309 struct phy_device *phydev = priv->phydev;
310
Siva Durga Prasad Paladugu8964f242016-02-21 15:46:15 +0530311 if (priv->interface == PHY_INTERFACE_MODE_SGMII) {
312 /*
313 * In SGMII cases the isolate bit might set
314 * after DMA and ethernet resets and hence
315 * check and clear if set.
316 */
317 ret = phyread(priv, priv->phyaddr, MII_BMCR, &temp);
318 if (ret)
319 return 0;
320 if (temp & BMCR_ISOLATE) {
321 temp &= ~BMCR_ISOLATE;
322 ret = phywrite(priv, priv->phyaddr, MII_BMCR, temp);
323 if (ret)
324 return 0;
325 }
326 }
327
Timur Tabi11af8d62012-07-09 08:52:43 +0000328 if (phy_startup(phydev)) {
329 printf("axiemac: could not initialize PHY %s\n",
330 phydev->dev->name);
331 return 0;
332 }
Michal Simek6f9b9372013-11-21 16:15:51 +0100333 if (!phydev->link) {
334 printf("%s: No link.\n", phydev->dev->name);
335 return 0;
336 }
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000337
338 switch (phydev->speed) {
339 case 1000:
340 speed = XAE_EMMC_LINKSPD_1000;
341 break;
342 case 100:
343 speed = XAE_EMMC_LINKSPD_100;
344 break;
345 case 10:
346 speed = XAE_EMMC_LINKSPD_10;
347 break;
348 default:
349 return 0;
350 }
351
352 /* Setup the emac for the phy speed */
Siva Durga Prasad Paladugua04a5da2017-11-23 12:23:12 +0530353 emmc_reg = readl(&regs->emmc);
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000354 emmc_reg &= ~XAE_EMMC_LINKSPEED_MASK;
355 emmc_reg |= speed;
356
357 /* Write new speed setting out to Axi Ethernet */
Siva Durga Prasad Paladugua04a5da2017-11-23 12:23:12 +0530358 writel(emmc_reg, &regs->emmc);
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000359
360 /*
361 * Setting the operating speed of the MAC needs a delay. There
362 * doesn't seem to be register to poll, so please consider this
363 * during your application design.
364 */
365 udelay(1);
366
367 return 1;
368}
369
370/* STOP DMA transfers */
Michal Simekad499e42015-12-16 09:18:12 +0100371static void axiemac_stop(struct udevice *dev)
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000372{
Michal Simek75cc93f2015-12-08 15:44:41 +0100373 struct axidma_priv *priv = dev_get_priv(dev);
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000374 u32 temp;
375
376 /* Stop the hardware */
Siva Durga Prasad Paladugua04a5da2017-11-23 12:23:12 +0530377 temp = readl(&priv->dmatx->control);
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000378 temp &= ~XAXIDMA_CR_RUNSTOP_MASK;
Siva Durga Prasad Paladugua04a5da2017-11-23 12:23:12 +0530379 writel(temp, &priv->dmatx->control);
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000380
Siva Durga Prasad Paladugua04a5da2017-11-23 12:23:12 +0530381 temp = readl(&priv->dmarx->control);
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000382 temp &= ~XAXIDMA_CR_RUNSTOP_MASK;
Siva Durga Prasad Paladugua04a5da2017-11-23 12:23:12 +0530383 writel(temp, &priv->dmarx->control);
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000384
385 debug("axiemac: Halted\n");
386}
387
Michal Simekf0985482015-12-09 14:53:51 +0100388static int axi_ethernet_init(struct axidma_priv *priv)
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000389{
Michal Simekf0985482015-12-09 14:53:51 +0100390 struct axi_regs *regs = priv->iobase;
Siva Durga Prasad Paladugud02a0b12017-01-06 16:18:50 +0530391 int err;
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000392
393 /*
394 * Check the status of the MgtRdy bit in the interrupt status
395 * registers. This must be done to allow the MGT clock to become stable
396 * for the Sgmii and 1000BaseX PHY interfaces. No other register reads
397 * will be valid until this bit is valid.
398 * The bit is always a 1 for all other PHY interfaces.
Siva Durga Prasad Paladugu89ce5a92017-01-06 16:27:15 +0530399 * Interrupt status and enable registers are not available in non
400 * processor mode and hence bypass in this mode
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000401 */
Siva Durga Prasad Paladugu89ce5a92017-01-06 16:27:15 +0530402 if (!priv->eth_hasnobuf) {
Álvaro Fernández Rojas48263502018-01-23 17:14:55 +0100403 err = wait_for_bit_le32(&regs->is, XAE_INT_MGTRDY_MASK,
404 true, 200, false);
Siva Durga Prasad Paladugu89ce5a92017-01-06 16:27:15 +0530405 if (err) {
406 printf("%s: Timeout\n", __func__);
407 return 1;
408 }
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000409
Siva Durga Prasad Paladugu89ce5a92017-01-06 16:27:15 +0530410 /*
411 * Stop the device and reset HW
412 * Disable interrupts
413 */
Siva Durga Prasad Paladugua04a5da2017-11-23 12:23:12 +0530414 writel(0, &regs->ie);
Siva Durga Prasad Paladugu89ce5a92017-01-06 16:27:15 +0530415 }
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000416
417 /* Disable the receiver */
Siva Durga Prasad Paladugua04a5da2017-11-23 12:23:12 +0530418 writel(readl(&regs->rcw1) & ~XAE_RCW1_RX_MASK, &regs->rcw1);
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000419
420 /*
421 * Stopping the receiver in mid-packet causes a dropped packet
422 * indication from HW. Clear it.
423 */
Siva Durga Prasad Paladugu89ce5a92017-01-06 16:27:15 +0530424 if (!priv->eth_hasnobuf) {
425 /* Set the interrupt status register to clear the interrupt */
Siva Durga Prasad Paladugua04a5da2017-11-23 12:23:12 +0530426 writel(XAE_INT_RXRJECT_MASK, &regs->is);
Siva Durga Prasad Paladugu89ce5a92017-01-06 16:27:15 +0530427 }
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000428
429 /* Setup HW */
430 /* Set default MDIO divisor */
Siva Durga Prasad Paladugua04a5da2017-11-23 12:23:12 +0530431 writel(XAE_MDIO_DIV_DFT | XAE_MDIO_MC_MDIOEN_MASK, &regs->mdio_mc);
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000432
433 debug("axiemac: InitHw done\n");
434 return 0;
435}
436
Michal Simekad499e42015-12-16 09:18:12 +0100437static int axiemac_write_hwaddr(struct udevice *dev)
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000438{
Simon Glassc69cda22020-12-03 16:55:20 -0700439 struct eth_pdata *pdata = dev_get_plat(dev);
Michal Simek75cc93f2015-12-08 15:44:41 +0100440 struct axidma_priv *priv = dev_get_priv(dev);
441 struct axi_regs *regs = priv->iobase;
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000442
443 /* Set the MAC address */
Michal Simek75cc93f2015-12-08 15:44:41 +0100444 int val = ((pdata->enetaddr[3] << 24) | (pdata->enetaddr[2] << 16) |
445 (pdata->enetaddr[1] << 8) | (pdata->enetaddr[0]));
Siva Durga Prasad Paladugua04a5da2017-11-23 12:23:12 +0530446 writel(val, &regs->uaw0);
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000447
Michal Simek75cc93f2015-12-08 15:44:41 +0100448 val = (pdata->enetaddr[5] << 8) | pdata->enetaddr[4];
Siva Durga Prasad Paladugua04a5da2017-11-23 12:23:12 +0530449 val |= readl(&regs->uaw1) & ~XAE_UAW1_UNICASTADDR_MASK;
450 writel(val, &regs->uaw1);
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000451 return 0;
452}
453
454/* Reset DMA engine */
Michal Simekf0985482015-12-09 14:53:51 +0100455static void axi_dma_init(struct axidma_priv *priv)
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000456{
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000457 u32 timeout = 500;
458
459 /* Reset the engine so the hardware starts from a known state */
Siva Durga Prasad Paladugua04a5da2017-11-23 12:23:12 +0530460 writel(XAXIDMA_CR_RESET_MASK, &priv->dmatx->control);
461 writel(XAXIDMA_CR_RESET_MASK, &priv->dmarx->control);
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000462
463 /* At the initialization time, hardware should finish reset quickly */
464 while (timeout--) {
465 /* Check transmit/receive channel */
466 /* Reset is done when the reset bit is low */
Siva Durga Prasad Paladugua04a5da2017-11-23 12:23:12 +0530467 if (!((readl(&priv->dmatx->control) |
468 readl(&priv->dmarx->control))
Michal Simek3e3f8ba2015-10-28 11:00:47 +0100469 & XAXIDMA_CR_RESET_MASK)) {
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000470 break;
471 }
472 }
473 if (!timeout)
474 printf("%s: Timeout\n", __func__);
475}
476
Michal Simekad499e42015-12-16 09:18:12 +0100477static int axiemac_start(struct udevice *dev)
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000478{
Michal Simek75cc93f2015-12-08 15:44:41 +0100479 struct axidma_priv *priv = dev_get_priv(dev);
480 struct axi_regs *regs = priv->iobase;
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000481 u32 temp;
482
483 debug("axiemac: Init started\n");
484 /*
485 * Initialize AXIDMA engine. AXIDMA engine must be initialized before
486 * AxiEthernet. During AXIDMA engine initialization, AXIDMA hardware is
487 * reset, and since AXIDMA reset line is connected to AxiEthernet, this
488 * would ensure a reset of AxiEthernet.
489 */
Michal Simekf0985482015-12-09 14:53:51 +0100490 axi_dma_init(priv);
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000491
492 /* Initialize AxiEthernet hardware. */
Michal Simekf0985482015-12-09 14:53:51 +0100493 if (axi_ethernet_init(priv))
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000494 return -1;
495
496 /* Disable all RX interrupts before RxBD space setup */
Siva Durga Prasad Paladugua04a5da2017-11-23 12:23:12 +0530497 temp = readl(&priv->dmarx->control);
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000498 temp &= ~XAXIDMA_IRQ_ALL_MASK;
Siva Durga Prasad Paladugua04a5da2017-11-23 12:23:12 +0530499 writel(temp, &priv->dmarx->control);
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000500
501 /* Start DMA RX channel. Now it's ready to receive data.*/
Vipul Kumar047f3bf2018-01-23 14:52:35 +0530502 axienet_dma_write(&rx_bd, &priv->dmarx->current);
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000503
504 /* Setup the BD. */
505 memset(&rx_bd, 0, sizeof(rx_bd));
Ashok Reddy Somaf9d3b312020-09-03 08:36:43 -0600506 rx_bd.next_desc = lower_32_bits((unsigned long)&rx_bd);
507 rx_bd.buf_addr = lower_32_bits((unsigned long)&rxframe);
508#if defined(CONFIG_PHYS_64BIT)
509 rx_bd.next_desc_msb = upper_32_bits((unsigned long)&rx_bd);
510 rx_bd.buf_addr_msb = upper_32_bits((unsigned long)&rxframe);
511#endif
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000512 rx_bd.cntrl = sizeof(rxframe);
513 /* Flush the last BD so DMA core could see the updates */
Ashok Reddy Soma315a3c32020-09-03 08:36:44 -0600514 flush_cache((phys_addr_t)&rx_bd, sizeof(rx_bd));
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000515
516 /* It is necessary to flush rxframe because if you don't do it
517 * then cache can contain uninitialized data */
Ashok Reddy Soma315a3c32020-09-03 08:36:44 -0600518 flush_cache((phys_addr_t)&rxframe, sizeof(rxframe));
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000519
520 /* Start the hardware */
Siva Durga Prasad Paladugua04a5da2017-11-23 12:23:12 +0530521 temp = readl(&priv->dmarx->control);
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000522 temp |= XAXIDMA_CR_RUNSTOP_MASK;
Siva Durga Prasad Paladugua04a5da2017-11-23 12:23:12 +0530523 writel(temp, &priv->dmarx->control);
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000524
525 /* Rx BD is ready - start */
Vipul Kumar047f3bf2018-01-23 14:52:35 +0530526 axienet_dma_write(&rx_bd, &priv->dmarx->tail);
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000527
528 /* Enable TX */
Siva Durga Prasad Paladugua04a5da2017-11-23 12:23:12 +0530529 writel(XAE_TC_TX_MASK, &regs->tc);
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000530 /* Enable RX */
Siva Durga Prasad Paladugua04a5da2017-11-23 12:23:12 +0530531 writel(XAE_RCW1_RX_MASK, &regs->rcw1);
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000532
533 /* PHY setup */
534 if (!setup_phy(dev)) {
Michal Simekad499e42015-12-16 09:18:12 +0100535 axiemac_stop(dev);
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000536 return -1;
537 }
538
539 debug("axiemac: Init complete\n");
540 return 0;
541}
542
Michal Simek75cc93f2015-12-08 15:44:41 +0100543static int axiemac_send(struct udevice *dev, void *ptr, int len)
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000544{
Michal Simek75cc93f2015-12-08 15:44:41 +0100545 struct axidma_priv *priv = dev_get_priv(dev);
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000546 u32 timeout;
547
548 if (len > PKTSIZE_ALIGN)
549 len = PKTSIZE_ALIGN;
550
551 /* Flush packet to main memory to be trasfered by DMA */
Ashok Reddy Soma315a3c32020-09-03 08:36:44 -0600552 flush_cache((phys_addr_t)ptr, len);
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000553
554 /* Setup Tx BD */
555 memset(&tx_bd, 0, sizeof(tx_bd));
556 /* At the end of the ring, link the last BD back to the top */
Ashok Reddy Somaf9d3b312020-09-03 08:36:43 -0600557 tx_bd.next_desc = lower_32_bits((unsigned long)&tx_bd);
558 tx_bd.buf_addr = lower_32_bits((unsigned long)ptr);
559#if defined(CONFIG_PHYS_64BIT)
560 tx_bd.next_desc_msb = upper_32_bits((unsigned long)&tx_bd);
561 tx_bd.buf_addr_msb = upper_32_bits((unsigned long)ptr);
562#endif
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000563 /* Save len */
564 tx_bd.cntrl = len | XAXIDMA_BD_CTRL_TXSOF_MASK |
565 XAXIDMA_BD_CTRL_TXEOF_MASK;
566
567 /* Flush the last BD so DMA core could see the updates */
Ashok Reddy Soma315a3c32020-09-03 08:36:44 -0600568 flush_cache((phys_addr_t)&tx_bd, sizeof(tx_bd));
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000569
Siva Durga Prasad Paladugua04a5da2017-11-23 12:23:12 +0530570 if (readl(&priv->dmatx->status) & XAXIDMA_HALTED_MASK) {
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000571 u32 temp;
Vipul Kumar047f3bf2018-01-23 14:52:35 +0530572 axienet_dma_write(&tx_bd, &priv->dmatx->current);
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000573 /* Start the hardware */
Siva Durga Prasad Paladugua04a5da2017-11-23 12:23:12 +0530574 temp = readl(&priv->dmatx->control);
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000575 temp |= XAXIDMA_CR_RUNSTOP_MASK;
Siva Durga Prasad Paladugua04a5da2017-11-23 12:23:12 +0530576 writel(temp, &priv->dmatx->control);
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000577 }
578
579 /* Start transfer */
Vipul Kumar047f3bf2018-01-23 14:52:35 +0530580 axienet_dma_write(&tx_bd, &priv->dmatx->tail);
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000581
582 /* Wait for transmission to complete */
583 debug("axiemac: Waiting for tx to be done\n");
584 timeout = 200;
Siva Durga Prasad Paladugua04a5da2017-11-23 12:23:12 +0530585 while (timeout && (!(readl(&priv->dmatx->status) &
Michal Simek3e3f8ba2015-10-28 11:00:47 +0100586 (XAXIDMA_IRQ_DELAY_MASK | XAXIDMA_IRQ_IOC_MASK)))) {
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000587 timeout--;
588 udelay(1);
589 }
590 if (!timeout) {
591 printf("%s: Timeout\n", __func__);
592 return 1;
593 }
594
595 debug("axiemac: Sending complete\n");
596 return 0;
597}
598
Michal Simekf0985482015-12-09 14:53:51 +0100599static int isrxready(struct axidma_priv *priv)
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000600{
601 u32 status;
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000602
603 /* Read pending interrupts */
Siva Durga Prasad Paladugua04a5da2017-11-23 12:23:12 +0530604 status = readl(&priv->dmarx->status);
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000605
606 /* Acknowledge pending interrupts */
Siva Durga Prasad Paladugua04a5da2017-11-23 12:23:12 +0530607 writel(status & XAXIDMA_IRQ_ALL_MASK, &priv->dmarx->status);
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000608
609 /*
610 * If Reception done interrupt is asserted, call RX call back function
611 * to handle the processed BDs and then raise the according flag.
612 */
613 if ((status & (XAXIDMA_IRQ_DELAY_MASK | XAXIDMA_IRQ_IOC_MASK)))
614 return 1;
615
616 return 0;
617}
618
Michal Simek75cc93f2015-12-08 15:44:41 +0100619static int axiemac_recv(struct udevice *dev, int flags, uchar **packetp)
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000620{
621 u32 length;
Michal Simek75cc93f2015-12-08 15:44:41 +0100622 struct axidma_priv *priv = dev_get_priv(dev);
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000623 u32 temp;
624
625 /* Wait for an incoming packet */
Michal Simekf0985482015-12-09 14:53:51 +0100626 if (!isrxready(priv))
Michal Simek75cc93f2015-12-08 15:44:41 +0100627 return -1;
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000628
629 debug("axiemac: RX data ready\n");
630
631 /* Disable IRQ for a moment till packet is handled */
Siva Durga Prasad Paladugua04a5da2017-11-23 12:23:12 +0530632 temp = readl(&priv->dmarx->control);
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000633 temp &= ~XAXIDMA_IRQ_ALL_MASK;
Siva Durga Prasad Paladugua04a5da2017-11-23 12:23:12 +0530634 writel(temp, &priv->dmarx->control);
Siva Durga Prasad Paladugu89ce5a92017-01-06 16:27:15 +0530635 if (!priv->eth_hasnobuf)
636 length = rx_bd.app4 & 0xFFFF; /* max length mask */
637 else
638 length = rx_bd.status & XAXIDMA_BD_STS_ACTUAL_LEN_MASK;
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000639
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000640#ifdef DEBUG
641 print_buffer(&rxframe, &rxframe[0], 1, length, 16);
642#endif
Michal Simek97d23632015-12-09 14:13:23 +0100643
644 *packetp = rxframe;
645 return length;
646}
647
648static int axiemac_free_pkt(struct udevice *dev, uchar *packet, int length)
649{
650 struct axidma_priv *priv = dev_get_priv(dev);
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000651
652#ifdef DEBUG
653 /* It is useful to clear buffer to be sure that it is consistent */
654 memset(rxframe, 0, sizeof(rxframe));
655#endif
656 /* Setup RxBD */
657 /* Clear the whole buffer and setup it again - all flags are cleared */
658 memset(&rx_bd, 0, sizeof(rx_bd));
Ashok Reddy Somaf9d3b312020-09-03 08:36:43 -0600659 rx_bd.next_desc = lower_32_bits((unsigned long)&rx_bd);
660 rx_bd.buf_addr = lower_32_bits((unsigned long)&rxframe);
661#if defined(CONFIG_PHYS_64BIT)
662 rx_bd.next_desc_msb = upper_32_bits((unsigned long)&rx_bd);
663 rx_bd.buf_addr_msb = upper_32_bits((unsigned long)&rxframe);
664#endif
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000665 rx_bd.cntrl = sizeof(rxframe);
666
667 /* Write bd to HW */
Ashok Reddy Soma315a3c32020-09-03 08:36:44 -0600668 flush_cache((phys_addr_t)&rx_bd, sizeof(rx_bd));
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000669
670 /* It is necessary to flush rxframe because if you don't do it
671 * then cache will contain previous packet */
Ashok Reddy Soma315a3c32020-09-03 08:36:44 -0600672 flush_cache((phys_addr_t)&rxframe, sizeof(rxframe));
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000673
674 /* Rx BD is ready - start again */
Vipul Kumar047f3bf2018-01-23 14:52:35 +0530675 axienet_dma_write(&rx_bd, &priv->dmarx->tail);
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000676
677 debug("axiemac: RX completed, framelength = %d\n", length);
678
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000679 return 0;
680}
681
Michal Simek75cc93f2015-12-08 15:44:41 +0100682static int axiemac_miiphy_read(struct mii_dev *bus, int addr,
683 int devad, int reg)
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000684{
Michal Simek75cc93f2015-12-08 15:44:41 +0100685 int ret;
686 u16 value;
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000687
Michal Simek75cc93f2015-12-08 15:44:41 +0100688 ret = phyread(bus->priv, addr, reg, &value);
689 debug("axiemac: Read MII 0x%x, 0x%x, 0x%x, %d\n", addr, reg,
690 value, ret);
691 return value;
Michal Simek4f1ec4c2011-10-06 20:35:35 +0000692}
Michal Simek75cc93f2015-12-08 15:44:41 +0100693
694static int axiemac_miiphy_write(struct mii_dev *bus, int addr, int devad,
695 int reg, u16 value)
696{
697 debug("axiemac: Write MII 0x%x, 0x%x, 0x%x\n", addr, reg, value);
698 return phywrite(bus->priv, addr, reg, value);
699}
700
701static int axi_emac_probe(struct udevice *dev)
702{
Ashok Reddy Soma215f2062021-06-24 00:34:40 -0600703 struct axidma_plat *plat = dev_get_plat(dev);
704 struct eth_pdata *pdata = &plat->eth_pdata;
Michal Simek75cc93f2015-12-08 15:44:41 +0100705 struct axidma_priv *priv = dev_get_priv(dev);
706 int ret;
707
Ashok Reddy Soma215f2062021-06-24 00:34:40 -0600708 priv->iobase = (struct axi_regs *)pdata->iobase;
709 priv->dmatx = plat->dmatx;
710 /* RX channel offset is 0x30 */
711 priv->dmarx = (struct axidma_reg *)((phys_addr_t)priv->dmatx + 0x30);
712 priv->eth_hasnobuf = plat->eth_hasnobuf;
713 priv->phyaddr = plat->phyaddr;
714 priv->phy_of_handle = plat->phy_of_handle;
715 priv->interface = pdata->phy_interface;
716
Michal Simek75cc93f2015-12-08 15:44:41 +0100717 priv->bus = mdio_alloc();
718 priv->bus->read = axiemac_miiphy_read;
719 priv->bus->write = axiemac_miiphy_write;
720 priv->bus->priv = priv;
Michal Simek75cc93f2015-12-08 15:44:41 +0100721
Simon Glass8b85dfc2020-12-16 21:20:07 -0700722 ret = mdio_register_seq(priv->bus, dev_seq(dev));
Michal Simek75cc93f2015-12-08 15:44:41 +0100723 if (ret)
724 return ret;
725
Michal Simek5d0449d2015-12-08 16:10:05 +0100726 axiemac_phy_init(dev);
727
Michal Simek75cc93f2015-12-08 15:44:41 +0100728 return 0;
729}
730
731static int axi_emac_remove(struct udevice *dev)
732{
733 struct axidma_priv *priv = dev_get_priv(dev);
734
735 free(priv->phydev);
736 mdio_unregister(priv->bus);
737 mdio_free(priv->bus);
738
739 return 0;
740}
741
742static const struct eth_ops axi_emac_ops = {
Michal Simekad499e42015-12-16 09:18:12 +0100743 .start = axiemac_start,
Michal Simek75cc93f2015-12-08 15:44:41 +0100744 .send = axiemac_send,
745 .recv = axiemac_recv,
Michal Simek97d23632015-12-09 14:13:23 +0100746 .free_pkt = axiemac_free_pkt,
Michal Simekad499e42015-12-16 09:18:12 +0100747 .stop = axiemac_stop,
748 .write_hwaddr = axiemac_write_hwaddr,
Michal Simek75cc93f2015-12-08 15:44:41 +0100749};
750
Simon Glassd1998a92020-12-03 16:55:21 -0700751static int axi_emac_of_to_plat(struct udevice *dev)
Michal Simek75cc93f2015-12-08 15:44:41 +0100752{
Ashok Reddy Soma215f2062021-06-24 00:34:40 -0600753 struct axidma_plat *plat = dev_get_plat(dev);
754 struct eth_pdata *pdata = &plat->eth_pdata;
Simon Glasse160f7d2017-01-17 16:52:55 -0700755 int node = dev_of_offset(dev);
Michal Simek75cc93f2015-12-08 15:44:41 +0100756 int offset = 0;
757 const char *phy_mode;
758
Masahiro Yamada25484932020-07-17 14:36:48 +0900759 pdata->iobase = dev_read_addr(dev);
Michal Simek75cc93f2015-12-08 15:44:41 +0100760
Simon Glasse160f7d2017-01-17 16:52:55 -0700761 offset = fdtdec_lookup_phandle(gd->fdt_blob, node,
Michal Simek75cc93f2015-12-08 15:44:41 +0100762 "axistream-connected");
763 if (offset <= 0) {
764 printf("%s: axistream is not found\n", __func__);
765 return -EINVAL;
766 }
Ashok Reddy Soma215f2062021-06-24 00:34:40 -0600767 plat->dmatx = (struct axidma_reg *)fdtdec_get_addr(gd->fdt_blob,
Siva Durga Prasad Paladugudc1fcc42017-06-22 11:14:55 +0530768 offset, "reg");
Ashok Reddy Soma215f2062021-06-24 00:34:40 -0600769 if (!plat->dmatx) {
Michal Simek75cc93f2015-12-08 15:44:41 +0100770 printf("%s: axi_dma register space not found\n", __func__);
771 return -EINVAL;
772 }
Michal Simek75cc93f2015-12-08 15:44:41 +0100773
Ashok Reddy Soma215f2062021-06-24 00:34:40 -0600774 plat->phyaddr = -1;
Michal Simek75cc93f2015-12-08 15:44:41 +0100775
Simon Glasse160f7d2017-01-17 16:52:55 -0700776 offset = fdtdec_lookup_phandle(gd->fdt_blob, node, "phy-handle");
Siva Durga Prasad Paladugufccfb712019-03-15 17:46:45 +0530777 if (offset > 0) {
Ashok Reddy Soma215f2062021-06-24 00:34:40 -0600778 plat->phyaddr = fdtdec_get_int(gd->fdt_blob, offset, "reg", -1);
779 plat->phy_of_handle = offset;
Siva Durga Prasad Paladugufccfb712019-03-15 17:46:45 +0530780 }
Michal Simek75cc93f2015-12-08 15:44:41 +0100781
Simon Glasse160f7d2017-01-17 16:52:55 -0700782 phy_mode = fdt_getprop(gd->fdt_blob, node, "phy-mode", NULL);
Michal Simek75cc93f2015-12-08 15:44:41 +0100783 if (phy_mode)
784 pdata->phy_interface = phy_get_interface_by_name(phy_mode);
785 if (pdata->phy_interface == -1) {
Michal Simekceb04e12016-02-08 13:54:05 +0100786 printf("%s: Invalid PHY interface '%s'\n", __func__, phy_mode);
Michal Simek75cc93f2015-12-08 15:44:41 +0100787 return -EINVAL;
788 }
Michal Simek75cc93f2015-12-08 15:44:41 +0100789
Ashok Reddy Soma215f2062021-06-24 00:34:40 -0600790 plat->eth_hasnobuf = fdtdec_get_bool(gd->fdt_blob, node,
Siva Durga Prasad Paladugu89ce5a92017-01-06 16:27:15 +0530791 "xlnx,eth-hasnobuf");
792
Ashok Reddy Soma215f2062021-06-24 00:34:40 -0600793 printf("AXI EMAC: %lx, phyaddr %d, interface %s\n", (ulong)pdata->iobase,
794 plat->phyaddr, phy_string_for_interface(pdata->phy_interface));
Michal Simek75cc93f2015-12-08 15:44:41 +0100795
796 return 0;
797}
798
799static const struct udevice_id axi_emac_ids[] = {
800 { .compatible = "xlnx,axi-ethernet-1.00.a" },
801 { }
802};
803
804U_BOOT_DRIVER(axi_emac) = {
805 .name = "axi_emac",
806 .id = UCLASS_ETH,
807 .of_match = axi_emac_ids,
Simon Glassd1998a92020-12-03 16:55:21 -0700808 .of_to_plat = axi_emac_of_to_plat,
Michal Simek75cc93f2015-12-08 15:44:41 +0100809 .probe = axi_emac_probe,
810 .remove = axi_emac_remove,
811 .ops = &axi_emac_ops,
Simon Glass41575d82020-12-03 16:55:17 -0700812 .priv_auto = sizeof(struct axidma_priv),
Ashok Reddy Soma215f2062021-06-24 00:34:40 -0600813 .plat_auto = sizeof(struct axidma_plat),
Michal Simek75cc93f2015-12-08 15:44:41 +0100814};