blob: dc6aa6deda8347db6bdf41a4c610af8996df6472 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +01002/*
3 * Copyright (C) 2005-2006 Atmel Corporation
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +01004 */
5#include <common.h>
Wenyou Yang3d8d3482016-11-02 10:06:56 +08006#include <clk.h>
Simon Glass75c5d182016-05-05 07:28:11 -06007#include <dm.h>
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +01008
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +01009/*
10 * The u-boot networking stack is a little weird. It seems like the
11 * networking core allocates receive buffers up front without any
12 * regard to the hardware that's supposed to actually receive those
13 * packets.
14 *
15 * The MACB receives packets into 128-byte receive buffers, so the
16 * buffers allocated by the core isn't very practical to use. We'll
17 * allocate our own, but we need one such buffer in case a packet
18 * wraps around the DMA ring so that we have to copy it.
19 *
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020020 * Therefore, define CONFIG_SYS_RX_ETH_BUFFER to 1 in the board-specific
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +010021 * configuration header. This way, the core allocates one RX buffer
22 * and one TX buffer, each of which can hold a ethernet packet of
23 * maximum size.
24 *
25 * For some reason, the networking core unconditionally specifies a
26 * 32-byte packet "alignment" (which really should be called
27 * "padding"). MACB shouldn't need that, but we'll refrain from any
28 * core modifications here...
29 */
30
31#include <net.h>
Simon Glass75c5d182016-05-05 07:28:11 -060032#ifndef CONFIG_DM_ETH
Ben Warren2f2b6b62008-08-31 22:22:04 -070033#include <netdev.h>
Simon Glass75c5d182016-05-05 07:28:11 -060034#endif
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +010035#include <malloc.h>
Semih Hazar790088e2009-12-17 15:07:15 +020036#include <miiphy.h>
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +010037
38#include <linux/mii.h>
39#include <asm/io.h>
40#include <asm/dma-mapping.h>
41#include <asm/arch/clk.h>
Masahiro Yamada64e4f7f2016-09-21 11:28:57 +090042#include <linux/errno.h>
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +010043
44#include "macb.h"
45
Wenyou Yang7b811852016-05-17 13:11:35 +080046DECLARE_GLOBAL_DATA_PTR;
47
Andreas Bießmann1e868122014-05-26 22:55:18 +020048#define MACB_RX_BUFFER_SIZE 4096
49#define MACB_RX_RING_SIZE (MACB_RX_BUFFER_SIZE / 128)
50#define MACB_TX_RING_SIZE 16
51#define MACB_TX_TIMEOUT 1000
52#define MACB_AUTONEG_TIMEOUT 5000000
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +010053
Wilson Lee41d6d1e2017-08-22 20:25:07 -070054#ifdef CONFIG_MACB_ZYNQ
55/* INCR4 AHB bursts */
56#define MACB_ZYNQ_GEM_DMACR_BLENGTH 0x00000004
57/* Use full configured addressable space (8 Kb) */
58#define MACB_ZYNQ_GEM_DMACR_RXSIZE 0x00000300
59/* Use full configured addressable space (4 Kb) */
60#define MACB_ZYNQ_GEM_DMACR_TXSIZE 0x00000400
61/* Set RXBUF with use of 128 byte */
62#define MACB_ZYNQ_GEM_DMACR_RXBUF 0x00020000
63#define MACB_ZYNQ_GEM_DMACR_INIT \
64 (MACB_ZYNQ_GEM_DMACR_BLENGTH | \
65 MACB_ZYNQ_GEM_DMACR_RXSIZE | \
66 MACB_ZYNQ_GEM_DMACR_TXSIZE | \
67 MACB_ZYNQ_GEM_DMACR_RXBUF)
68#endif
69
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +010070struct macb_dma_desc {
71 u32 addr;
72 u32 ctrl;
73};
74
Wu, Josh18052402014-05-27 16:31:05 +080075#define DMA_DESC_BYTES(n) (n * sizeof(struct macb_dma_desc))
76#define MACB_TX_DMA_DESC_SIZE (DMA_DESC_BYTES(MACB_TX_RING_SIZE))
77#define MACB_RX_DMA_DESC_SIZE (DMA_DESC_BYTES(MACB_RX_RING_SIZE))
Wu, Josh012d68d2015-06-03 16:45:44 +080078#define MACB_TX_DUMMY_DMA_DESC_SIZE (DMA_DESC_BYTES(1))
Wu, Josh18052402014-05-27 16:31:05 +080079
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +010080#define RXBUF_FRMLEN_MASK 0x00000fff
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +010081#define TXBUF_FRMLEN_MASK 0x000007ff
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +010082
83struct macb_device {
84 void *regs;
Ramon Fried834040c2019-07-16 22:04:35 +030085 unsigned int dma_burst_length;
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +010086
87 unsigned int rx_tail;
88 unsigned int tx_head;
89 unsigned int tx_tail;
Simon Glass5ad27512016-05-05 07:28:09 -060090 unsigned int next_rx_tail;
91 bool wrapped;
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +010092
93 void *rx_buffer;
94 void *tx_buffer;
95 struct macb_dma_desc *rx_ring;
96 struct macb_dma_desc *tx_ring;
97
98 unsigned long rx_buffer_dma;
99 unsigned long rx_ring_dma;
100 unsigned long tx_ring_dma;
101
Wu, Josh012d68d2015-06-03 16:45:44 +0800102 struct macb_dma_desc *dummy_desc;
103 unsigned long dummy_desc_dma;
104
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100105 const struct device *dev;
Simon Glass75c5d182016-05-05 07:28:11 -0600106#ifndef CONFIG_DM_ETH
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100107 struct eth_device netdev;
Simon Glass75c5d182016-05-05 07:28:11 -0600108#endif
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100109 unsigned short phy_addr;
Bo Shen7d91deb2013-04-24 15:59:27 +0800110 struct mii_dev *bus;
Wenyou Yang44835ea2017-04-14 14:36:04 +0800111#ifdef CONFIG_PHYLIB
112 struct phy_device *phydev;
113#endif
Wenyou Yang7b811852016-05-17 13:11:35 +0800114
115#ifdef CONFIG_DM_ETH
Wenyou Yang19449362017-02-14 16:24:40 +0800116#ifdef CONFIG_CLK
Wenyou Yang3d8d3482016-11-02 10:06:56 +0800117 unsigned long pclk_rate;
Wenyou Yang19449362017-02-14 16:24:40 +0800118#endif
Wenyou Yang7b811852016-05-17 13:11:35 +0800119 phy_interface_t phy_interface;
120#endif
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100121};
Ramon Fried834040c2019-07-16 22:04:35 +0300122
123struct macb_config {
124 unsigned int dma_burst_length;
125};
126
Simon Glass75c5d182016-05-05 07:28:11 -0600127#ifndef CONFIG_DM_ETH
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100128#define to_macb(_nd) container_of(_nd, struct macb_device, netdev)
Simon Glass75c5d182016-05-05 07:28:11 -0600129#endif
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100130
Bo Shen6f7d7d92013-04-24 15:59:28 +0800131static int macb_is_gem(struct macb_device *macb)
132{
Atish Patrae1a85182019-02-25 08:14:42 +0000133 return MACB_BFEXT(IDNUM, macb_readl(macb, MID)) >= 0x2;
Bo Shen6f7d7d92013-04-24 15:59:28 +0800134}
135
Gregory CLEMENTf1a1e582015-12-16 14:50:34 +0100136#ifndef cpu_is_sama5d2
137#define cpu_is_sama5d2() 0
138#endif
139
140#ifndef cpu_is_sama5d4
141#define cpu_is_sama5d4() 0
142#endif
143
144static int gem_is_gigabit_capable(struct macb_device *macb)
145{
146 /*
Robert P. J. Day8c60f922016-05-04 04:47:31 -0400147 * The GEM controllers embedded in SAMA5D2 and SAMA5D4 are
Gregory CLEMENTf1a1e582015-12-16 14:50:34 +0100148 * configured to support only 10/100.
149 */
150 return macb_is_gem(macb) && !cpu_is_sama5d2() && !cpu_is_sama5d4();
151}
152
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100153static void macb_mdio_write(struct macb_device *macb, u8 reg, u16 value)
154{
155 unsigned long netctl;
156 unsigned long netstat;
157 unsigned long frame;
158
159 netctl = macb_readl(macb, NCR);
160 netctl |= MACB_BIT(MPE);
161 macb_writel(macb, NCR, netctl);
162
163 frame = (MACB_BF(SOF, 1)
164 | MACB_BF(RW, 1)
165 | MACB_BF(PHYA, macb->phy_addr)
166 | MACB_BF(REGA, reg)
167 | MACB_BF(CODE, 2)
168 | MACB_BF(DATA, value));
169 macb_writel(macb, MAN, frame);
170
171 do {
172 netstat = macb_readl(macb, NSR);
173 } while (!(netstat & MACB_BIT(IDLE)));
174
175 netctl = macb_readl(macb, NCR);
176 netctl &= ~MACB_BIT(MPE);
177 macb_writel(macb, NCR, netctl);
178}
179
180static u16 macb_mdio_read(struct macb_device *macb, u8 reg)
181{
182 unsigned long netctl;
183 unsigned long netstat;
184 unsigned long frame;
185
186 netctl = macb_readl(macb, NCR);
187 netctl |= MACB_BIT(MPE);
188 macb_writel(macb, NCR, netctl);
189
190 frame = (MACB_BF(SOF, 1)
191 | MACB_BF(RW, 2)
192 | MACB_BF(PHYA, macb->phy_addr)
193 | MACB_BF(REGA, reg)
194 | MACB_BF(CODE, 2));
195 macb_writel(macb, MAN, frame);
196
197 do {
198 netstat = macb_readl(macb, NSR);
199 } while (!(netstat & MACB_BIT(IDLE)));
200
201 frame = macb_readl(macb, MAN);
202
203 netctl = macb_readl(macb, NCR);
204 netctl &= ~MACB_BIT(MPE);
205 macb_writel(macb, NCR, netctl);
206
207 return MACB_BFEXT(DATA, frame);
208}
209
Joe Hershberger9e5742b2013-06-24 19:06:38 -0500210void __weak arch_get_mdio_control(const char *name)
Shiraz Hashim77cdf0f2012-12-13 17:22:52 +0530211{
212 return;
213}
214
Bo Shen7d91deb2013-04-24 15:59:27 +0800215#if defined(CONFIG_CMD_MII) || defined(CONFIG_PHYLIB)
Semih Hazar790088e2009-12-17 15:07:15 +0200216
Joe Hershberger1fbcbed2016-08-08 11:28:38 -0500217int macb_miiphy_read(struct mii_dev *bus, int phy_adr, int devad, int reg)
Semih Hazar790088e2009-12-17 15:07:15 +0200218{
Joe Hershberger1fbcbed2016-08-08 11:28:38 -0500219 u16 value = 0;
Simon Glass75c5d182016-05-05 07:28:11 -0600220#ifdef CONFIG_DM_ETH
Joe Hershberger1fbcbed2016-08-08 11:28:38 -0500221 struct udevice *dev = eth_get_dev_by_name(bus->name);
Simon Glass75c5d182016-05-05 07:28:11 -0600222 struct macb_device *macb = dev_get_priv(dev);
223#else
Joe Hershberger1fbcbed2016-08-08 11:28:38 -0500224 struct eth_device *dev = eth_get_dev_by_name(bus->name);
Semih Hazar790088e2009-12-17 15:07:15 +0200225 struct macb_device *macb = to_macb(dev);
Simon Glass75c5d182016-05-05 07:28:11 -0600226#endif
Semih Hazar790088e2009-12-17 15:07:15 +0200227
Andreas Bießmann1e868122014-05-26 22:55:18 +0200228 if (macb->phy_addr != phy_adr)
Semih Hazar790088e2009-12-17 15:07:15 +0200229 return -1;
230
Joe Hershberger1fbcbed2016-08-08 11:28:38 -0500231 arch_get_mdio_control(bus->name);
232 value = macb_mdio_read(macb, reg);
Semih Hazar790088e2009-12-17 15:07:15 +0200233
Joe Hershberger1fbcbed2016-08-08 11:28:38 -0500234 return value;
Semih Hazar790088e2009-12-17 15:07:15 +0200235}
236
Joe Hershberger1fbcbed2016-08-08 11:28:38 -0500237int macb_miiphy_write(struct mii_dev *bus, int phy_adr, int devad, int reg,
238 u16 value)
Semih Hazar790088e2009-12-17 15:07:15 +0200239{
Simon Glass75c5d182016-05-05 07:28:11 -0600240#ifdef CONFIG_DM_ETH
Joe Hershberger1fbcbed2016-08-08 11:28:38 -0500241 struct udevice *dev = eth_get_dev_by_name(bus->name);
Simon Glass75c5d182016-05-05 07:28:11 -0600242 struct macb_device *macb = dev_get_priv(dev);
243#else
Joe Hershberger1fbcbed2016-08-08 11:28:38 -0500244 struct eth_device *dev = eth_get_dev_by_name(bus->name);
Semih Hazar790088e2009-12-17 15:07:15 +0200245 struct macb_device *macb = to_macb(dev);
Simon Glass75c5d182016-05-05 07:28:11 -0600246#endif
Semih Hazar790088e2009-12-17 15:07:15 +0200247
Andreas Bießmann1e868122014-05-26 22:55:18 +0200248 if (macb->phy_addr != phy_adr)
Semih Hazar790088e2009-12-17 15:07:15 +0200249 return -1;
250
Joe Hershberger1fbcbed2016-08-08 11:28:38 -0500251 arch_get_mdio_control(bus->name);
Semih Hazar790088e2009-12-17 15:07:15 +0200252 macb_mdio_write(macb, reg, value);
253
254 return 0;
255}
256#endif
257
Wu, Josh18052402014-05-27 16:31:05 +0800258#define RX 1
259#define TX 0
260static inline void macb_invalidate_ring_desc(struct macb_device *macb, bool rx)
261{
262 if (rx)
Heiko Schocher8353f9d2016-08-29 07:46:11 +0200263 invalidate_dcache_range(macb->rx_ring_dma,
264 ALIGN(macb->rx_ring_dma + MACB_RX_DMA_DESC_SIZE,
265 PKTALIGN));
Wu, Josh18052402014-05-27 16:31:05 +0800266 else
Heiko Schocher8353f9d2016-08-29 07:46:11 +0200267 invalidate_dcache_range(macb->tx_ring_dma,
268 ALIGN(macb->tx_ring_dma + MACB_TX_DMA_DESC_SIZE,
269 PKTALIGN));
Wu, Josh18052402014-05-27 16:31:05 +0800270}
271
272static inline void macb_flush_ring_desc(struct macb_device *macb, bool rx)
273{
274 if (rx)
275 flush_dcache_range(macb->rx_ring_dma, macb->rx_ring_dma +
Heiko Schocher8353f9d2016-08-29 07:46:11 +0200276 ALIGN(MACB_RX_DMA_DESC_SIZE, PKTALIGN));
Wu, Josh18052402014-05-27 16:31:05 +0800277 else
278 flush_dcache_range(macb->tx_ring_dma, macb->tx_ring_dma +
Heiko Schocher8353f9d2016-08-29 07:46:11 +0200279 ALIGN(MACB_TX_DMA_DESC_SIZE, PKTALIGN));
Wu, Josh18052402014-05-27 16:31:05 +0800280}
281
282static inline void macb_flush_rx_buffer(struct macb_device *macb)
283{
284 flush_dcache_range(macb->rx_buffer_dma, macb->rx_buffer_dma +
Heiko Schocher8353f9d2016-08-29 07:46:11 +0200285 ALIGN(MACB_RX_BUFFER_SIZE, PKTALIGN));
Wu, Josh18052402014-05-27 16:31:05 +0800286}
287
288static inline void macb_invalidate_rx_buffer(struct macb_device *macb)
289{
290 invalidate_dcache_range(macb->rx_buffer_dma, macb->rx_buffer_dma +
Heiko Schocher8353f9d2016-08-29 07:46:11 +0200291 ALIGN(MACB_RX_BUFFER_SIZE, PKTALIGN));
Wu, Josh18052402014-05-27 16:31:05 +0800292}
Semih Hazar790088e2009-12-17 15:07:15 +0200293
Jon Loeligerb1d408a2007-07-09 17:30:01 -0500294#if defined(CONFIG_CMD_NET)
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100295
Simon Glass5ad27512016-05-05 07:28:09 -0600296static int _macb_send(struct macb_device *macb, const char *name, void *packet,
297 int length)
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100298{
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100299 unsigned long paddr, ctrl;
300 unsigned int tx_head = macb->tx_head;
301 int i;
302
303 paddr = dma_map_single(packet, length, DMA_TO_DEVICE);
304
305 ctrl = length & TXBUF_FRMLEN_MASK;
Ramon Fried6402fb192019-07-16 22:04:33 +0300306 ctrl |= MACB_BIT(TX_LAST);
Andreas Bießmann1e868122014-05-26 22:55:18 +0200307 if (tx_head == (MACB_TX_RING_SIZE - 1)) {
Ramon Fried6402fb192019-07-16 22:04:33 +0300308 ctrl |= MACB_BIT(TX_WRAP);
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100309 macb->tx_head = 0;
Andreas Bießmann1e868122014-05-26 22:55:18 +0200310 } else {
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100311 macb->tx_head++;
Andreas Bießmann1e868122014-05-26 22:55:18 +0200312 }
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100313
314 macb->tx_ring[tx_head].ctrl = ctrl;
315 macb->tx_ring[tx_head].addr = paddr;
Haavard Skinnemoen996e1472007-05-02 13:22:38 +0200316 barrier();
Wu, Josh18052402014-05-27 16:31:05 +0800317 macb_flush_ring_desc(macb, TX);
318 /* Do we need check paddr and length is dcache line aligned? */
Simon Glass3d5dcef2016-05-05 07:28:10 -0600319 flush_dcache_range(paddr, paddr + ALIGN(length, ARCH_DMA_MINALIGN));
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100320 macb_writel(macb, NCR, MACB_BIT(TE) | MACB_BIT(RE) | MACB_BIT(TSTART));
321
322 /*
323 * I guess this is necessary because the networking core may
324 * re-use the transmit buffer as soon as we return...
325 */
Andreas Bießmann1e868122014-05-26 22:55:18 +0200326 for (i = 0; i <= MACB_TX_TIMEOUT; i++) {
Haavard Skinnemoen996e1472007-05-02 13:22:38 +0200327 barrier();
Wu, Josh18052402014-05-27 16:31:05 +0800328 macb_invalidate_ring_desc(macb, TX);
Haavard Skinnemoen996e1472007-05-02 13:22:38 +0200329 ctrl = macb->tx_ring[tx_head].ctrl;
Ramon Fried6402fb192019-07-16 22:04:33 +0300330 if (ctrl & MACB_BIT(TX_USED))
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100331 break;
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100332 udelay(1);
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100333 }
334
335 dma_unmap_single(packet, length, paddr);
336
Andreas Bießmann1e868122014-05-26 22:55:18 +0200337 if (i <= MACB_TX_TIMEOUT) {
Ramon Fried6402fb192019-07-16 22:04:33 +0300338 if (ctrl & MACB_BIT(TX_UNDERRUN))
Simon Glass5ad27512016-05-05 07:28:09 -0600339 printf("%s: TX underrun\n", name);
Ramon Fried6402fb192019-07-16 22:04:33 +0300340 if (ctrl & MACB_BIT(TX_BUF_EXHAUSTED))
Simon Glass5ad27512016-05-05 07:28:09 -0600341 printf("%s: TX buffers exhausted in mid frame\n", name);
Haavard Skinnemoen996e1472007-05-02 13:22:38 +0200342 } else {
Simon Glass5ad27512016-05-05 07:28:09 -0600343 printf("%s: TX timeout\n", name);
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100344 }
345
346 /* No one cares anyway */
347 return 0;
348}
349
350static void reclaim_rx_buffers(struct macb_device *macb,
351 unsigned int new_tail)
352{
353 unsigned int i;
354
355 i = macb->rx_tail;
Wu, Josh18052402014-05-27 16:31:05 +0800356
357 macb_invalidate_ring_desc(macb, RX);
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100358 while (i > new_tail) {
Ramon Fried6402fb192019-07-16 22:04:33 +0300359 macb->rx_ring[i].addr &= ~MACB_BIT(RX_USED);
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100360 i++;
Andreas Bießmann1e868122014-05-26 22:55:18 +0200361 if (i > MACB_RX_RING_SIZE)
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100362 i = 0;
363 }
364
365 while (i < new_tail) {
Ramon Fried6402fb192019-07-16 22:04:33 +0300366 macb->rx_ring[i].addr &= ~MACB_BIT(RX_USED);
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100367 i++;
368 }
369
Haavard Skinnemoen996e1472007-05-02 13:22:38 +0200370 barrier();
Wu, Josh18052402014-05-27 16:31:05 +0800371 macb_flush_ring_desc(macb, RX);
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100372 macb->rx_tail = new_tail;
373}
374
Simon Glass5ad27512016-05-05 07:28:09 -0600375static int _macb_recv(struct macb_device *macb, uchar **packetp)
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100376{
Simon Glass5ad27512016-05-05 07:28:09 -0600377 unsigned int next_rx_tail = macb->next_rx_tail;
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100378 void *buffer;
379 int length;
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100380 u32 status;
381
Simon Glass5ad27512016-05-05 07:28:09 -0600382 macb->wrapped = false;
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100383 for (;;) {
Wu, Josh18052402014-05-27 16:31:05 +0800384 macb_invalidate_ring_desc(macb, RX);
385
Ramon Fried6402fb192019-07-16 22:04:33 +0300386 if (!(macb->rx_ring[next_rx_tail].addr & MACB_BIT(RX_USED)))
Simon Glass5ad27512016-05-05 07:28:09 -0600387 return -EAGAIN;
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100388
Simon Glass5ad27512016-05-05 07:28:09 -0600389 status = macb->rx_ring[next_rx_tail].ctrl;
Ramon Fried6402fb192019-07-16 22:04:33 +0300390 if (status & MACB_BIT(RX_SOF)) {
Simon Glass5ad27512016-05-05 07:28:09 -0600391 if (next_rx_tail != macb->rx_tail)
392 reclaim_rx_buffers(macb, next_rx_tail);
393 macb->wrapped = false;
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100394 }
395
Ramon Fried6402fb192019-07-16 22:04:33 +0300396 if (status & MACB_BIT(RX_EOF)) {
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100397 buffer = macb->rx_buffer + 128 * macb->rx_tail;
398 length = status & RXBUF_FRMLEN_MASK;
Wu, Josh18052402014-05-27 16:31:05 +0800399
400 macb_invalidate_rx_buffer(macb);
Simon Glass5ad27512016-05-05 07:28:09 -0600401 if (macb->wrapped) {
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100402 unsigned int headlen, taillen;
403
Andreas Bießmann1e868122014-05-26 22:55:18 +0200404 headlen = 128 * (MACB_RX_RING_SIZE
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100405 - macb->rx_tail);
406 taillen = length - headlen;
Joe Hershberger9f09a362015-04-08 01:41:06 -0500407 memcpy((void *)net_rx_packets[0],
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100408 buffer, headlen);
Joe Hershberger9f09a362015-04-08 01:41:06 -0500409 memcpy((void *)net_rx_packets[0] + headlen,
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100410 macb->rx_buffer, taillen);
Simon Glass5ad27512016-05-05 07:28:09 -0600411 *packetp = (void *)net_rx_packets[0];
412 } else {
413 *packetp = buffer;
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100414 }
415
Simon Glass5ad27512016-05-05 07:28:09 -0600416 if (++next_rx_tail >= MACB_RX_RING_SIZE)
417 next_rx_tail = 0;
418 macb->next_rx_tail = next_rx_tail;
419 return length;
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100420 } else {
Simon Glass5ad27512016-05-05 07:28:09 -0600421 if (++next_rx_tail >= MACB_RX_RING_SIZE) {
422 macb->wrapped = true;
423 next_rx_tail = 0;
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100424 }
425 }
Haavard Skinnemoen996e1472007-05-02 13:22:38 +0200426 barrier();
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100427 }
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100428}
429
Simon Glass5ad27512016-05-05 07:28:09 -0600430static void macb_phy_reset(struct macb_device *macb, const char *name)
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100431{
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100432 int i;
Haavard Skinnemoenb3ad7722007-05-02 13:31:53 +0200433 u16 status, adv;
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100434
435 adv = ADVERTISE_CSMA | ADVERTISE_ALL;
436 macb_mdio_write(macb, MII_ADVERTISE, adv);
Simon Glass5ad27512016-05-05 07:28:09 -0600437 printf("%s: Starting autonegotiation...\n", name);
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100438 macb_mdio_write(macb, MII_BMCR, (BMCR_ANENABLE
439 | BMCR_ANRESTART));
440
Andreas Bießmann1e868122014-05-26 22:55:18 +0200441 for (i = 0; i < MACB_AUTONEG_TIMEOUT / 100; i++) {
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100442 status = macb_mdio_read(macb, MII_BMSR);
443 if (status & BMSR_ANEGCOMPLETE)
444 break;
445 udelay(100);
446 }
447
448 if (status & BMSR_ANEGCOMPLETE)
Simon Glass5ad27512016-05-05 07:28:09 -0600449 printf("%s: Autonegotiation complete\n", name);
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100450 else
451 printf("%s: Autonegotiation timed out (status=0x%04x)\n",
Simon Glass5ad27512016-05-05 07:28:09 -0600452 name, status);
Haavard Skinnemoenb3ad7722007-05-02 13:31:53 +0200453}
454
Wenyou Yang7b811852016-05-17 13:11:35 +0800455static int macb_phy_find(struct macb_device *macb, const char *name)
Gunnar Rangoy6dd74f32009-01-23 12:56:31 +0100456{
457 int i;
458 u16 phy_id;
459
460 /* Search for PHY... */
461 for (i = 0; i < 32; i++) {
462 macb->phy_addr = i;
463 phy_id = macb_mdio_read(macb, MII_PHYSID1);
464 if (phy_id != 0xffff) {
Wenyou Yang7b811852016-05-17 13:11:35 +0800465 printf("%s: PHY present at %d\n", name, i);
Wilson Lee41d6d1e2017-08-22 20:25:07 -0700466 return 0;
Gunnar Rangoy6dd74f32009-01-23 12:56:31 +0100467 }
468 }
469
470 /* PHY isn't up to snuff */
Wenyou Yang7b811852016-05-17 13:11:35 +0800471 printf("%s: PHY not found\n", name);
Gunnar Rangoy6dd74f32009-01-23 12:56:31 +0100472
Wilson Lee41d6d1e2017-08-22 20:25:07 -0700473 return -ENODEV;
474}
475
476/**
477 * macb_linkspd_cb - Linkspeed change callback function
Bin Mengcf821322019-05-22 00:09:45 -0700478 * @dev/@regs: MACB udevice (DM version) or
479 * Base Register of MACB devices (non-DM version)
Wilson Lee41d6d1e2017-08-22 20:25:07 -0700480 * @speed: Linkspeed
481 * Returns 0 when operation success and negative errno number
482 * when operation failed.
483 */
Bin Mengcf821322019-05-22 00:09:45 -0700484#ifdef CONFIG_DM_ETH
485int __weak macb_linkspd_cb(struct udevice *dev, unsigned int speed)
486{
Bin Meng12766ca2019-05-22 00:09:46 -0700487#ifdef CONFIG_CLK
488 struct clk tx_clk;
489 ulong rate;
490 int ret;
491
492 /*
493 * "tx_clk" is an optional clock source for MACB.
494 * Ignore if it does not exist in DT.
495 */
496 ret = clk_get_by_name(dev, "tx_clk", &tx_clk);
497 if (ret)
498 return 0;
499
500 switch (speed) {
501 case _10BASET:
502 rate = 2500000; /* 2.5 MHz */
503 break;
504 case _100BASET:
505 rate = 25000000; /* 25 MHz */
506 break;
507 case _1000BASET:
508 rate = 125000000; /* 125 MHz */
509 break;
510 default:
511 /* does not change anything */
512 return 0;
513 }
514
515 if (tx_clk.dev) {
516 ret = clk_set_rate(&tx_clk, rate);
517 if (ret)
518 return ret;
519 }
520#endif
521
Bin Mengcf821322019-05-22 00:09:45 -0700522 return 0;
523}
524#else
Wilson Lee41d6d1e2017-08-22 20:25:07 -0700525int __weak macb_linkspd_cb(void *regs, unsigned int speed)
526{
Gunnar Rangoy6dd74f32009-01-23 12:56:31 +0100527 return 0;
528}
Bin Mengcf821322019-05-22 00:09:45 -0700529#endif
Gunnar Rangoy6dd74f32009-01-23 12:56:31 +0100530
Wenyou Yang7b811852016-05-17 13:11:35 +0800531#ifdef CONFIG_DM_ETH
532static int macb_phy_init(struct udevice *dev, const char *name)
533#else
Simon Glass5ad27512016-05-05 07:28:09 -0600534static int macb_phy_init(struct macb_device *macb, const char *name)
Wenyou Yang7b811852016-05-17 13:11:35 +0800535#endif
Haavard Skinnemoenb3ad7722007-05-02 13:31:53 +0200536{
Wenyou Yang7b811852016-05-17 13:11:35 +0800537#ifdef CONFIG_DM_ETH
538 struct macb_device *macb = dev_get_priv(dev);
539#endif
Haavard Skinnemoenb3ad7722007-05-02 13:31:53 +0200540 u32 ncfgr;
541 u16 phy_id, status, adv, lpa;
542 int media, speed, duplex;
Wilson Lee41d6d1e2017-08-22 20:25:07 -0700543 int ret;
Haavard Skinnemoenb3ad7722007-05-02 13:31:53 +0200544 int i;
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100545
Simon Glass5ad27512016-05-05 07:28:09 -0600546 arch_get_mdio_control(name);
Gunnar Rangoy6dd74f32009-01-23 12:56:31 +0100547 /* Auto-detect phy_addr */
Wilson Lee41d6d1e2017-08-22 20:25:07 -0700548 ret = macb_phy_find(macb, name);
549 if (ret)
550 return ret;
Gunnar Rangoy6dd74f32009-01-23 12:56:31 +0100551
Haavard Skinnemoenb3ad7722007-05-02 13:31:53 +0200552 /* Check if the PHY is up to snuff... */
553 phy_id = macb_mdio_read(macb, MII_PHYSID1);
554 if (phy_id == 0xffff) {
Simon Glass5ad27512016-05-05 07:28:09 -0600555 printf("%s: No PHY present\n", name);
Wilson Lee41d6d1e2017-08-22 20:25:07 -0700556 return -ENODEV;
Haavard Skinnemoenb3ad7722007-05-02 13:31:53 +0200557 }
558
Bo Shen7d91deb2013-04-24 15:59:27 +0800559#ifdef CONFIG_PHYLIB
Wenyou Yang7b811852016-05-17 13:11:35 +0800560#ifdef CONFIG_DM_ETH
Wenyou Yang44835ea2017-04-14 14:36:04 +0800561 macb->phydev = phy_connect(macb->bus, macb->phy_addr, dev,
Wenyou Yang7b811852016-05-17 13:11:35 +0800562 macb->phy_interface);
563#else
Bo Shene04fe552013-08-19 10:35:47 +0800564 /* need to consider other phy interface mode */
Wenyou Yang44835ea2017-04-14 14:36:04 +0800565 macb->phydev = phy_connect(macb->bus, macb->phy_addr, &macb->netdev,
Bo Shene04fe552013-08-19 10:35:47 +0800566 PHY_INTERFACE_MODE_RGMII);
Wenyou Yang7b811852016-05-17 13:11:35 +0800567#endif
Wenyou Yang44835ea2017-04-14 14:36:04 +0800568 if (!macb->phydev) {
Bo Shene04fe552013-08-19 10:35:47 +0800569 printf("phy_connect failed\n");
570 return -ENODEV;
571 }
572
Wenyou Yang44835ea2017-04-14 14:36:04 +0800573 phy_config(macb->phydev);
Bo Shen7d91deb2013-04-24 15:59:27 +0800574#endif
575
Haavard Skinnemoenb3ad7722007-05-02 13:31:53 +0200576 status = macb_mdio_read(macb, MII_BMSR);
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100577 if (!(status & BMSR_LSTATUS)) {
Haavard Skinnemoenb3ad7722007-05-02 13:31:53 +0200578 /* Try to re-negotiate if we don't have link already. */
Simon Glass5ad27512016-05-05 07:28:09 -0600579 macb_phy_reset(macb, name);
Haavard Skinnemoenb3ad7722007-05-02 13:31:53 +0200580
Andreas Bießmann1e868122014-05-26 22:55:18 +0200581 for (i = 0; i < MACB_AUTONEG_TIMEOUT / 100; i++) {
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100582 status = macb_mdio_read(macb, MII_BMSR);
Stefan Roese40291802019-03-27 11:20:19 +0100583 if (status & BMSR_LSTATUS) {
584 /*
585 * Delay a bit after the link is established,
586 * so that the next xfer does not fail
587 */
588 mdelay(10);
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100589 break;
Stefan Roese40291802019-03-27 11:20:19 +0100590 }
Haavard Skinnemoenb3ad7722007-05-02 13:31:53 +0200591 udelay(100);
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100592 }
593 }
594
595 if (!(status & BMSR_LSTATUS)) {
596 printf("%s: link down (status: 0x%04x)\n",
Simon Glass5ad27512016-05-05 07:28:09 -0600597 name, status);
Wilson Lee41d6d1e2017-08-22 20:25:07 -0700598 return -ENETDOWN;
Bo Shen6f7d7d92013-04-24 15:59:28 +0800599 }
600
Gregory CLEMENTf1a1e582015-12-16 14:50:34 +0100601 /* First check for GMAC and that it is GiB capable */
602 if (gem_is_gigabit_capable(macb)) {
Radu Pirea015800c2019-06-07 14:18:35 +0300603 lpa = macb_mdio_read(macb, MII_LPA);
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100604
Radu Pirea1676dfb2019-06-07 14:18:36 +0300605 if (lpa & (LPA_1000FULL | LPA_1000HALF | LPA_1000XFULL |
606 LPA_1000XHALF)) {
607 duplex = ((lpa & (LPA_1000FULL | LPA_1000XFULL)) ?
608 1 : 0);
Andreas Bießmannd43a89a2014-09-18 23:46:48 +0200609
610 printf("%s: link up, 1000Mbps %s-duplex (lpa: 0x%04x)\n",
Simon Glass5ad27512016-05-05 07:28:09 -0600611 name,
Bo Shen6f7d7d92013-04-24 15:59:28 +0800612 duplex ? "full" : "half",
613 lpa);
614
615 ncfgr = macb_readl(macb, NCFGR);
Andreas Bießmannd43a89a2014-09-18 23:46:48 +0200616 ncfgr &= ~(MACB_BIT(SPD) | MACB_BIT(FD));
617 ncfgr |= GEM_BIT(GBE);
618
Bo Shen6f7d7d92013-04-24 15:59:28 +0800619 if (duplex)
620 ncfgr |= MACB_BIT(FD);
Andreas Bießmannd43a89a2014-09-18 23:46:48 +0200621
Bo Shen6f7d7d92013-04-24 15:59:28 +0800622 macb_writel(macb, NCFGR, ncfgr);
623
Bin Mengcf821322019-05-22 00:09:45 -0700624#ifdef CONFIG_DM_ETH
625 ret = macb_linkspd_cb(dev, _1000BASET);
626#else
Wilson Lee41d6d1e2017-08-22 20:25:07 -0700627 ret = macb_linkspd_cb(macb->regs, _1000BASET);
Bin Mengcf821322019-05-22 00:09:45 -0700628#endif
Wilson Lee41d6d1e2017-08-22 20:25:07 -0700629 if (ret)
630 return ret;
631
632 return 0;
Bo Shen6f7d7d92013-04-24 15:59:28 +0800633 }
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100634 }
Bo Shen6f7d7d92013-04-24 15:59:28 +0800635
636 /* fall back for EMAC checking */
637 adv = macb_mdio_read(macb, MII_ADVERTISE);
638 lpa = macb_mdio_read(macb, MII_LPA);
639 media = mii_nway_result(lpa & adv);
640 speed = (media & (ADVERTISE_100FULL | ADVERTISE_100HALF)
641 ? 1 : 0);
642 duplex = (media & ADVERTISE_FULL) ? 1 : 0;
643 printf("%s: link up, %sMbps %s-duplex (lpa: 0x%04x)\n",
Simon Glass5ad27512016-05-05 07:28:09 -0600644 name,
Bo Shen6f7d7d92013-04-24 15:59:28 +0800645 speed ? "100" : "10",
646 duplex ? "full" : "half",
647 lpa);
648
649 ncfgr = macb_readl(macb, NCFGR);
Bo Shenfe19ef32015-03-04 13:35:16 +0800650 ncfgr &= ~(MACB_BIT(SPD) | MACB_BIT(FD) | GEM_BIT(GBE));
Wilson Lee41d6d1e2017-08-22 20:25:07 -0700651 if (speed) {
Bo Shen6f7d7d92013-04-24 15:59:28 +0800652 ncfgr |= MACB_BIT(SPD);
Bin Mengcf821322019-05-22 00:09:45 -0700653#ifdef CONFIG_DM_ETH
654 ret = macb_linkspd_cb(dev, _100BASET);
655#else
Wilson Lee41d6d1e2017-08-22 20:25:07 -0700656 ret = macb_linkspd_cb(macb->regs, _100BASET);
Bin Mengcf821322019-05-22 00:09:45 -0700657#endif
Wilson Lee41d6d1e2017-08-22 20:25:07 -0700658 } else {
Bin Mengcf821322019-05-22 00:09:45 -0700659#ifdef CONFIG_DM_ETH
660 ret = macb_linkspd_cb(dev, _10BASET);
661#else
Wilson Lee41d6d1e2017-08-22 20:25:07 -0700662 ret = macb_linkspd_cb(macb->regs, _10BASET);
Bin Mengcf821322019-05-22 00:09:45 -0700663#endif
Wilson Lee41d6d1e2017-08-22 20:25:07 -0700664 }
665
666 if (ret)
667 return ret;
668
Bo Shen6f7d7d92013-04-24 15:59:28 +0800669 if (duplex)
670 ncfgr |= MACB_BIT(FD);
671 macb_writel(macb, NCFGR, ncfgr);
672
Wilson Lee41d6d1e2017-08-22 20:25:07 -0700673 return 0;
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100674}
675
Wu, Josh012d68d2015-06-03 16:45:44 +0800676static int gmac_init_multi_queues(struct macb_device *macb)
677{
678 int i, num_queues = 1;
679 u32 queue_mask;
680
681 /* bit 0 is never set but queue 0 always exists */
682 queue_mask = gem_readl(macb, DCFG6) & 0xff;
683 queue_mask |= 0x1;
684
685 for (i = 1; i < MACB_MAX_QUEUES; i++)
686 if (queue_mask & (1 << i))
687 num_queues++;
688
Ramon Fried6402fb192019-07-16 22:04:33 +0300689 macb->dummy_desc->ctrl = MACB_BIT(TX_USED);
Wu, Josh012d68d2015-06-03 16:45:44 +0800690 macb->dummy_desc->addr = 0;
691 flush_dcache_range(macb->dummy_desc_dma, macb->dummy_desc_dma +
Heiko Schocher8353f9d2016-08-29 07:46:11 +0200692 ALIGN(MACB_TX_DUMMY_DMA_DESC_SIZE, PKTALIGN));
Wu, Josh012d68d2015-06-03 16:45:44 +0800693
694 for (i = 1; i < num_queues; i++)
695 gem_writel_queue_TBQP(macb, macb->dummy_desc_dma, i - 1);
696
697 return 0;
698}
699
Wenyou Yang7b811852016-05-17 13:11:35 +0800700#ifdef CONFIG_DM_ETH
701static int _macb_init(struct udevice *dev, const char *name)
702#else
Simon Glass5ad27512016-05-05 07:28:09 -0600703static int _macb_init(struct macb_device *macb, const char *name)
Wenyou Yang7b811852016-05-17 13:11:35 +0800704#endif
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100705{
Wenyou Yang7b811852016-05-17 13:11:35 +0800706#ifdef CONFIG_DM_ETH
707 struct macb_device *macb = dev_get_priv(dev);
708#endif
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100709 unsigned long paddr;
Wilson Lee41d6d1e2017-08-22 20:25:07 -0700710 int ret;
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100711 int i;
712
713 /*
714 * macb_halt should have been called at some point before now,
715 * so we'll assume the controller is idle.
716 */
717
718 /* initialize DMA descriptors */
719 paddr = macb->rx_buffer_dma;
Andreas Bießmann1e868122014-05-26 22:55:18 +0200720 for (i = 0; i < MACB_RX_RING_SIZE; i++) {
721 if (i == (MACB_RX_RING_SIZE - 1))
Ramon Fried6402fb192019-07-16 22:04:33 +0300722 paddr |= MACB_BIT(RX_WRAP);
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100723 macb->rx_ring[i].addr = paddr;
724 macb->rx_ring[i].ctrl = 0;
725 paddr += 128;
726 }
Wu, Josh18052402014-05-27 16:31:05 +0800727 macb_flush_ring_desc(macb, RX);
728 macb_flush_rx_buffer(macb);
729
Andreas Bießmann1e868122014-05-26 22:55:18 +0200730 for (i = 0; i < MACB_TX_RING_SIZE; i++) {
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100731 macb->tx_ring[i].addr = 0;
Andreas Bießmann1e868122014-05-26 22:55:18 +0200732 if (i == (MACB_TX_RING_SIZE - 1))
Ramon Fried6402fb192019-07-16 22:04:33 +0300733 macb->tx_ring[i].ctrl = MACB_BIT(TX_USED) |
734 MACB_BIT(TX_WRAP);
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100735 else
Ramon Fried6402fb192019-07-16 22:04:33 +0300736 macb->tx_ring[i].ctrl = MACB_BIT(TX_USED);
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100737 }
Wu, Josh18052402014-05-27 16:31:05 +0800738 macb_flush_ring_desc(macb, TX);
739
Andreas Bießmann1e868122014-05-26 22:55:18 +0200740 macb->rx_tail = 0;
741 macb->tx_head = 0;
742 macb->tx_tail = 0;
Simon Glass5ad27512016-05-05 07:28:09 -0600743 macb->next_rx_tail = 0;
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100744
Wilson Lee41d6d1e2017-08-22 20:25:07 -0700745#ifdef CONFIG_MACB_ZYNQ
746 macb_writel(macb, DMACFG, MACB_ZYNQ_GEM_DMACR_INIT);
747#endif
748
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100749 macb_writel(macb, RBQP, macb->rx_ring_dma);
750 macb_writel(macb, TBQP, macb->tx_ring_dma);
751
Bo Shen6f7d7d92013-04-24 15:59:28 +0800752 if (macb_is_gem(macb)) {
Wu, Josh012d68d2015-06-03 16:45:44 +0800753 /* Check the multi queue and initialize the queue for tx */
754 gmac_init_multi_queues(macb);
755
Bo Shen4660b332014-11-10 15:24:01 +0800756 /*
757 * When the GMAC IP with GE feature, this bit is used to
758 * select interface between RGMII and GMII.
759 * When the GMAC IP without GE feature, this bit is used
760 * to select interface between RMII and MII.
761 */
Wenyou Yang7b811852016-05-17 13:11:35 +0800762#ifdef CONFIG_DM_ETH
Wenyou Yang5653dbc2017-04-20 11:13:13 +0800763 if ((macb->phy_interface == PHY_INTERFACE_MODE_RMII) ||
764 (macb->phy_interface == PHY_INTERFACE_MODE_RGMII))
Ramon Fried94e6bd82019-07-16 22:03:00 +0300765 gem_writel(macb, USRIO, GEM_BIT(RGMII));
Wenyou Yang7b811852016-05-17 13:11:35 +0800766 else
Ramon Fried94e6bd82019-07-16 22:03:00 +0300767 gem_writel(macb, USRIO, 0);
Ramon Fried588a5b72019-07-16 22:04:34 +0300768
769 if (macb->phy_interface == PHY_INTERFACE_MODE_SGMII) {
770 unsigned int ncfgr = macb_readl(macb, NCFGR);
771
772 ncfgr |= GEM_BIT(SGMIIEN) | GEM_BIT(PCSSEL);
773 macb_writel(macb, NCFGR, ncfgr);
774 }
Wenyou Yang7b811852016-05-17 13:11:35 +0800775#else
Bo Shen4660b332014-11-10 15:24:01 +0800776#if defined(CONFIG_RGMII) || defined(CONFIG_RMII)
Ramon Fried94e6bd82019-07-16 22:03:00 +0300777 gem_writel(macb, USRIO, GEM_BIT(RGMII));
Bo Shen6f7d7d92013-04-24 15:59:28 +0800778#else
Ramon Fried94e6bd82019-07-16 22:03:00 +0300779 gem_writel(macb, USRIO, 0);
Bo Shen6f7d7d92013-04-24 15:59:28 +0800780#endif
Wenyou Yang7b811852016-05-17 13:11:35 +0800781#endif
Bo Shen6f7d7d92013-04-24 15:59:28 +0800782 } else {
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100783 /* choose RMII or MII mode. This depends on the board */
Wenyou Yang7b811852016-05-17 13:11:35 +0800784#ifdef CONFIG_DM_ETH
785#ifdef CONFIG_AT91FAMILY
786 if (macb->phy_interface == PHY_INTERFACE_MODE_RMII) {
787 macb_writel(macb, USRIO,
788 MACB_BIT(RMII) | MACB_BIT(CLKEN));
789 } else {
790 macb_writel(macb, USRIO, MACB_BIT(CLKEN));
791 }
792#else
793 if (macb->phy_interface == PHY_INTERFACE_MODE_RMII)
794 macb_writel(macb, USRIO, 0);
795 else
796 macb_writel(macb, USRIO, MACB_BIT(MII));
797#endif
798#else
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100799#ifdef CONFIG_RMII
Bo Shencc29ce52013-04-24 15:59:26 +0800800#ifdef CONFIG_AT91FAMILY
Stelian Pop87a82542008-01-03 21:15:56 +0000801 macb_writel(macb, USRIO, MACB_BIT(RMII) | MACB_BIT(CLKEN));
802#else
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100803 macb_writel(macb, USRIO, 0);
Stelian Pop87a82542008-01-03 21:15:56 +0000804#endif
805#else
Bo Shencc29ce52013-04-24 15:59:26 +0800806#ifdef CONFIG_AT91FAMILY
Stelian Pop87a82542008-01-03 21:15:56 +0000807 macb_writel(macb, USRIO, MACB_BIT(CLKEN));
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100808#else
809 macb_writel(macb, USRIO, MACB_BIT(MII));
810#endif
Stelian Pop87a82542008-01-03 21:15:56 +0000811#endif /* CONFIG_RMII */
Wenyou Yang7b811852016-05-17 13:11:35 +0800812#endif
Bo Shen6f7d7d92013-04-24 15:59:28 +0800813 }
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100814
Wenyou Yang7b811852016-05-17 13:11:35 +0800815#ifdef CONFIG_DM_ETH
Wilson Lee41d6d1e2017-08-22 20:25:07 -0700816 ret = macb_phy_init(dev, name);
Wenyou Yang7b811852016-05-17 13:11:35 +0800817#else
Wilson Lee41d6d1e2017-08-22 20:25:07 -0700818 ret = macb_phy_init(macb, name);
Wenyou Yang7b811852016-05-17 13:11:35 +0800819#endif
Wilson Lee41d6d1e2017-08-22 20:25:07 -0700820 if (ret)
821 return ret;
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100822
823 /* Enable TX and RX */
824 macb_writel(macb, NCR, MACB_BIT(TE) | MACB_BIT(RE));
825
Ben Warrende9fcb52008-01-09 18:15:53 -0500826 return 0;
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100827}
828
Simon Glass5ad27512016-05-05 07:28:09 -0600829static void _macb_halt(struct macb_device *macb)
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100830{
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +0100831 u32 ncr, tsr;
832
833 /* Halt the controller and wait for any ongoing transmission to end. */
834 ncr = macb_readl(macb, NCR);
835 ncr |= MACB_BIT(THALT);
836 macb_writel(macb, NCR, ncr);
837
838 do {
839 tsr = macb_readl(macb, TSR);
840 } while (tsr & MACB_BIT(TGO));
841
842 /* Disable TX and RX, and clear statistics */
843 macb_writel(macb, NCR, MACB_BIT(CLRSTAT));
844}
845
Simon Glass5ad27512016-05-05 07:28:09 -0600846static int _macb_write_hwaddr(struct macb_device *macb, unsigned char *enetaddr)
Ben Warren33f84312010-06-01 11:55:42 -0700847{
Ben Warren33f84312010-06-01 11:55:42 -0700848 u32 hwaddr_bottom;
849 u16 hwaddr_top;
850
851 /* set hardware address */
Simon Glass5ad27512016-05-05 07:28:09 -0600852 hwaddr_bottom = enetaddr[0] | enetaddr[1] << 8 |
853 enetaddr[2] << 16 | enetaddr[3] << 24;
Ben Warren33f84312010-06-01 11:55:42 -0700854 macb_writel(macb, SA1B, hwaddr_bottom);
Simon Glass5ad27512016-05-05 07:28:09 -0600855 hwaddr_top = enetaddr[4] | enetaddr[5] << 8;
Ben Warren33f84312010-06-01 11:55:42 -0700856 macb_writel(macb, SA1T, hwaddr_top);
857 return 0;
858}
859
Bo Shen6f7d7d92013-04-24 15:59:28 +0800860static u32 macb_mdc_clk_div(int id, struct macb_device *macb)
861{
862 u32 config;
Wenyou Yang19449362017-02-14 16:24:40 +0800863#if defined(CONFIG_DM_ETH) && defined(CONFIG_CLK)
Wenyou Yang3d8d3482016-11-02 10:06:56 +0800864 unsigned long macb_hz = macb->pclk_rate;
865#else
Bo Shen6f7d7d92013-04-24 15:59:28 +0800866 unsigned long macb_hz = get_macb_pclk_rate(id);
Wenyou Yang3d8d3482016-11-02 10:06:56 +0800867#endif
Bo Shen6f7d7d92013-04-24 15:59:28 +0800868
869 if (macb_hz < 20000000)
870 config = MACB_BF(CLK, MACB_CLK_DIV8);
871 else if (macb_hz < 40000000)
872 config = MACB_BF(CLK, MACB_CLK_DIV16);
873 else if (macb_hz < 80000000)
874 config = MACB_BF(CLK, MACB_CLK_DIV32);
875 else
876 config = MACB_BF(CLK, MACB_CLK_DIV64);
877
878 return config;
879}
880
881static u32 gem_mdc_clk_div(int id, struct macb_device *macb)
882{
883 u32 config;
Wenyou Yang3d8d3482016-11-02 10:06:56 +0800884
Wenyou Yang19449362017-02-14 16:24:40 +0800885#if defined(CONFIG_DM_ETH) && defined(CONFIG_CLK)
Wenyou Yang3d8d3482016-11-02 10:06:56 +0800886 unsigned long macb_hz = macb->pclk_rate;
887#else
Bo Shen6f7d7d92013-04-24 15:59:28 +0800888 unsigned long macb_hz = get_macb_pclk_rate(id);
Wenyou Yang3d8d3482016-11-02 10:06:56 +0800889#endif
Bo Shen6f7d7d92013-04-24 15:59:28 +0800890
891 if (macb_hz < 20000000)
892 config = GEM_BF(CLK, GEM_CLK_DIV8);
893 else if (macb_hz < 40000000)
894 config = GEM_BF(CLK, GEM_CLK_DIV16);
895 else if (macb_hz < 80000000)
896 config = GEM_BF(CLK, GEM_CLK_DIV32);
897 else if (macb_hz < 120000000)
898 config = GEM_BF(CLK, GEM_CLK_DIV48);
899 else if (macb_hz < 160000000)
900 config = GEM_BF(CLK, GEM_CLK_DIV64);
Ramon Friedb1b9b4f2019-07-16 22:04:32 +0300901 else if (macb_hz < 240000000)
Bo Shen6f7d7d92013-04-24 15:59:28 +0800902 config = GEM_BF(CLK, GEM_CLK_DIV96);
Ramon Friedb1b9b4f2019-07-16 22:04:32 +0300903 else if (macb_hz < 320000000)
904 config = GEM_BF(CLK, GEM_CLK_DIV128);
905 else
906 config = GEM_BF(CLK, GEM_CLK_DIV224);
Bo Shen6f7d7d92013-04-24 15:59:28 +0800907
908 return config;
909}
910
Bo Shen0e6624a2013-09-18 15:07:44 +0800911/*
912 * Get the DMA bus width field of the network configuration register that we
913 * should program. We find the width from decoding the design configuration
914 * register to find the maximum supported data bus width.
915 */
916static u32 macb_dbw(struct macb_device *macb)
917{
918 switch (GEM_BFEXT(DBWDEF, gem_readl(macb, DCFG1))) {
919 case 4:
920 return GEM_BF(DBW, GEM_DBW128);
921 case 2:
922 return GEM_BF(DBW, GEM_DBW64);
923 case 1:
924 default:
925 return GEM_BF(DBW, GEM_DBW32);
926 }
Simon Glass5ad27512016-05-05 07:28:09 -0600927}
928
929static void _macb_eth_initialize(struct macb_device *macb)
930{
931 int id = 0; /* This is not used by functions we call */
932 u32 ncfgr;
933
934 /* TODO: we need check the rx/tx_ring_dma is dcache line aligned */
935 macb->rx_buffer = dma_alloc_coherent(MACB_RX_BUFFER_SIZE,
936 &macb->rx_buffer_dma);
937 macb->rx_ring = dma_alloc_coherent(MACB_RX_DMA_DESC_SIZE,
938 &macb->rx_ring_dma);
939 macb->tx_ring = dma_alloc_coherent(MACB_TX_DMA_DESC_SIZE,
940 &macb->tx_ring_dma);
941 macb->dummy_desc = dma_alloc_coherent(MACB_TX_DUMMY_DMA_DESC_SIZE,
942 &macb->dummy_desc_dma);
943
944 /*
945 * Do some basic initialization so that we at least can talk
946 * to the PHY
947 */
948 if (macb_is_gem(macb)) {
949 ncfgr = gem_mdc_clk_div(id, macb);
950 ncfgr |= macb_dbw(macb);
951 } else {
952 ncfgr = macb_mdc_clk_div(id, macb);
953 }
954
955 macb_writel(macb, NCFGR, ncfgr);
956}
957
Simon Glass75c5d182016-05-05 07:28:11 -0600958#ifndef CONFIG_DM_ETH
Simon Glass5ad27512016-05-05 07:28:09 -0600959static int macb_send(struct eth_device *netdev, void *packet, int length)
960{
961 struct macb_device *macb = to_macb(netdev);
962
963 return _macb_send(macb, netdev->name, packet, length);
Bo Shen0e6624a2013-09-18 15:07:44 +0800964}
965
Simon Glass5ad27512016-05-05 07:28:09 -0600966static int macb_recv(struct eth_device *netdev)
967{
968 struct macb_device *macb = to_macb(netdev);
969 uchar *packet;
970 int length;
971
972 macb->wrapped = false;
973 for (;;) {
974 macb->next_rx_tail = macb->rx_tail;
975 length = _macb_recv(macb, &packet);
976 if (length >= 0) {
977 net_process_received_packet(packet, length);
978 reclaim_rx_buffers(macb, macb->next_rx_tail);
Heinrich Schuchardt6c4aae92018-03-18 11:32:53 +0100979 } else {
Simon Glass5ad27512016-05-05 07:28:09 -0600980 return length;
981 }
982 }
983}
984
985static int macb_init(struct eth_device *netdev, bd_t *bd)
986{
987 struct macb_device *macb = to_macb(netdev);
988
989 return _macb_init(macb, netdev->name);
990}
991
992static void macb_halt(struct eth_device *netdev)
993{
994 struct macb_device *macb = to_macb(netdev);
995
996 return _macb_halt(macb);
997}
998
999static int macb_write_hwaddr(struct eth_device *netdev)
1000{
1001 struct macb_device *macb = to_macb(netdev);
1002
1003 return _macb_write_hwaddr(macb, netdev->enetaddr);
1004}
1005
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +01001006int macb_eth_initialize(int id, void *regs, unsigned int phy_addr)
1007{
1008 struct macb_device *macb;
1009 struct eth_device *netdev;
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +01001010
1011 macb = malloc(sizeof(struct macb_device));
1012 if (!macb) {
1013 printf("Error: Failed to allocate memory for MACB%d\n", id);
1014 return -1;
1015 }
1016 memset(macb, 0, sizeof(struct macb_device));
1017
1018 netdev = &macb->netdev;
1019
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +01001020 macb->regs = regs;
1021 macb->phy_addr = phy_addr;
1022
Bo Shen6f7d7d92013-04-24 15:59:28 +08001023 if (macb_is_gem(macb))
1024 sprintf(netdev->name, "gmac%d", id);
1025 else
1026 sprintf(netdev->name, "macb%d", id);
1027
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +01001028 netdev->init = macb_init;
1029 netdev->halt = macb_halt;
1030 netdev->send = macb_send;
1031 netdev->recv = macb_recv;
Ben Warren33f84312010-06-01 11:55:42 -07001032 netdev->write_hwaddr = macb_write_hwaddr;
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +01001033
Simon Glass5ad27512016-05-05 07:28:09 -06001034 _macb_eth_initialize(macb);
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +01001035
1036 eth_register(netdev);
1037
Bo Shen7d91deb2013-04-24 15:59:27 +08001038#if defined(CONFIG_CMD_MII) || defined(CONFIG_PHYLIB)
Joe Hershberger1fbcbed2016-08-08 11:28:38 -05001039 int retval;
1040 struct mii_dev *mdiodev = mdio_alloc();
1041 if (!mdiodev)
1042 return -ENOMEM;
1043 strncpy(mdiodev->name, netdev->name, MDIO_NAME_LEN);
1044 mdiodev->read = macb_miiphy_read;
1045 mdiodev->write = macb_miiphy_write;
1046
1047 retval = mdio_register(mdiodev);
1048 if (retval < 0)
1049 return retval;
Bo Shen7d91deb2013-04-24 15:59:27 +08001050 macb->bus = miiphy_get_dev_by_name(netdev->name);
Semih Hazar790088e2009-12-17 15:07:15 +02001051#endif
Simon Glass75c5d182016-05-05 07:28:11 -06001052 return 0;
1053}
1054#endif /* !CONFIG_DM_ETH */
1055
1056#ifdef CONFIG_DM_ETH
1057
1058static int macb_start(struct udevice *dev)
1059{
Wenyou Yang7b811852016-05-17 13:11:35 +08001060 return _macb_init(dev, dev->name);
Simon Glass75c5d182016-05-05 07:28:11 -06001061}
1062
1063static int macb_send(struct udevice *dev, void *packet, int length)
1064{
1065 struct macb_device *macb = dev_get_priv(dev);
1066
1067 return _macb_send(macb, dev->name, packet, length);
1068}
1069
1070static int macb_recv(struct udevice *dev, int flags, uchar **packetp)
1071{
1072 struct macb_device *macb = dev_get_priv(dev);
1073
1074 macb->next_rx_tail = macb->rx_tail;
1075 macb->wrapped = false;
1076
1077 return _macb_recv(macb, packetp);
1078}
1079
1080static int macb_free_pkt(struct udevice *dev, uchar *packet, int length)
1081{
1082 struct macb_device *macb = dev_get_priv(dev);
1083
1084 reclaim_rx_buffers(macb, macb->next_rx_tail);
1085
1086 return 0;
1087}
1088
1089static void macb_stop(struct udevice *dev)
1090{
1091 struct macb_device *macb = dev_get_priv(dev);
1092
1093 _macb_halt(macb);
1094}
1095
1096static int macb_write_hwaddr(struct udevice *dev)
1097{
1098 struct eth_pdata *plat = dev_get_platdata(dev);
1099 struct macb_device *macb = dev_get_priv(dev);
1100
1101 return _macb_write_hwaddr(macb, plat->enetaddr);
1102}
1103
1104static const struct eth_ops macb_eth_ops = {
1105 .start = macb_start,
1106 .send = macb_send,
1107 .recv = macb_recv,
1108 .stop = macb_stop,
1109 .free_pkt = macb_free_pkt,
1110 .write_hwaddr = macb_write_hwaddr,
1111};
1112
Wenyou Yang19449362017-02-14 16:24:40 +08001113#ifdef CONFIG_CLK
Wenyou Yang3d8d3482016-11-02 10:06:56 +08001114static int macb_enable_clk(struct udevice *dev)
1115{
1116 struct macb_device *macb = dev_get_priv(dev);
1117 struct clk clk;
1118 ulong clk_rate;
1119 int ret;
1120
1121 ret = clk_get_by_index(dev, 0, &clk);
1122 if (ret)
1123 return -EINVAL;
1124
Wilson Lee41d6d1e2017-08-22 20:25:07 -07001125 /*
Anup Patel51b51f82019-02-25 08:14:36 +00001126 * If clock driver didn't support enable or disable then
1127 * we get -ENOSYS from clk_enable(). To handle this, we
1128 * don't fail for ret == -ENOSYS.
Wilson Lee41d6d1e2017-08-22 20:25:07 -07001129 */
Wenyou Yang3d8d3482016-11-02 10:06:56 +08001130 ret = clk_enable(&clk);
Anup Patel51b51f82019-02-25 08:14:36 +00001131 if (ret && ret != -ENOSYS)
Wenyou Yang3d8d3482016-11-02 10:06:56 +08001132 return ret;
1133
1134 clk_rate = clk_get_rate(&clk);
1135 if (!clk_rate)
1136 return -EINVAL;
1137
1138 macb->pclk_rate = clk_rate;
1139
1140 return 0;
1141}
Wenyou Yang19449362017-02-14 16:24:40 +08001142#endif
Wenyou Yang3d8d3482016-11-02 10:06:56 +08001143
Ramon Fried834040c2019-07-16 22:04:35 +03001144static const struct macb_config default_gem_config = {
1145 .dma_burst_length = 16,
1146};
1147
Simon Glass75c5d182016-05-05 07:28:11 -06001148static int macb_eth_probe(struct udevice *dev)
1149{
Ramon Fried834040c2019-07-16 22:04:35 +03001150 const struct macb_config *macb_config;
Simon Glass75c5d182016-05-05 07:28:11 -06001151 struct eth_pdata *pdata = dev_get_platdata(dev);
1152 struct macb_device *macb = dev_get_priv(dev);
Wenyou Yang7b811852016-05-17 13:11:35 +08001153 const char *phy_mode;
Wenyou Yang44835ea2017-04-14 14:36:04 +08001154 __maybe_unused int ret;
Wenyou Yang7b811852016-05-17 13:11:35 +08001155
Simon Glassdd79d6e2017-01-17 16:52:55 -07001156 phy_mode = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "phy-mode",
1157 NULL);
Wenyou Yang7b811852016-05-17 13:11:35 +08001158 if (phy_mode)
1159 macb->phy_interface = phy_get_interface_by_name(phy_mode);
1160 if (macb->phy_interface == -1) {
1161 debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode);
1162 return -EINVAL;
1163 }
Wenyou Yang7b811852016-05-17 13:11:35 +08001164
Simon Glass75c5d182016-05-05 07:28:11 -06001165 macb->regs = (void *)pdata->iobase;
1166
Ramon Fried834040c2019-07-16 22:04:35 +03001167 macb_config = (struct macb_config *)dev_get_driver_data(dev);
1168 if (!macb_config)
1169 macb_config = &default_gem_config;
1170
1171 macb->dma_burst_length = macb_config->dma_burst_length;
Wenyou Yang19449362017-02-14 16:24:40 +08001172#ifdef CONFIG_CLK
Wenyou Yang44835ea2017-04-14 14:36:04 +08001173 ret = macb_enable_clk(dev);
Wenyou Yang3d8d3482016-11-02 10:06:56 +08001174 if (ret)
1175 return ret;
Wenyou Yang19449362017-02-14 16:24:40 +08001176#endif
Wenyou Yang3d8d3482016-11-02 10:06:56 +08001177
Simon Glass75c5d182016-05-05 07:28:11 -06001178 _macb_eth_initialize(macb);
Wenyou Yang3d8d3482016-11-02 10:06:56 +08001179
Simon Glass75c5d182016-05-05 07:28:11 -06001180#if defined(CONFIG_CMD_MII) || defined(CONFIG_PHYLIB)
Wenyou Yang44835ea2017-04-14 14:36:04 +08001181 macb->bus = mdio_alloc();
1182 if (!macb->bus)
Joe Hershberger1fbcbed2016-08-08 11:28:38 -05001183 return -ENOMEM;
Wenyou Yang44835ea2017-04-14 14:36:04 +08001184 strncpy(macb->bus->name, dev->name, MDIO_NAME_LEN);
1185 macb->bus->read = macb_miiphy_read;
1186 macb->bus->write = macb_miiphy_write;
Joe Hershberger1fbcbed2016-08-08 11:28:38 -05001187
Wenyou Yang44835ea2017-04-14 14:36:04 +08001188 ret = mdio_register(macb->bus);
1189 if (ret < 0)
1190 return ret;
Simon Glass75c5d182016-05-05 07:28:11 -06001191 macb->bus = miiphy_get_dev_by_name(dev->name);
1192#endif
Wenyou Yang44835ea2017-04-14 14:36:04 +08001193
1194 return 0;
1195}
1196
1197static int macb_eth_remove(struct udevice *dev)
1198{
1199 struct macb_device *macb = dev_get_priv(dev);
1200
1201#ifdef CONFIG_PHYLIB
1202 free(macb->phydev);
1203#endif
1204 mdio_unregister(macb->bus);
1205 mdio_free(macb->bus);
Simon Glass75c5d182016-05-05 07:28:11 -06001206
Wilson Lee41d6d1e2017-08-22 20:25:07 -07001207 return 0;
1208}
1209
1210/**
1211 * macb_late_eth_ofdata_to_platdata
1212 * @dev: udevice struct
1213 * Returns 0 when operation success and negative errno number
1214 * when operation failed.
1215 */
1216int __weak macb_late_eth_ofdata_to_platdata(struct udevice *dev)
1217{
Simon Glass75c5d182016-05-05 07:28:11 -06001218 return 0;
1219}
1220
1221static int macb_eth_ofdata_to_platdata(struct udevice *dev)
1222{
1223 struct eth_pdata *pdata = dev_get_platdata(dev);
1224
Ramon Friedbf15d2f2018-12-27 19:58:42 +02001225 pdata->iobase = (phys_addr_t)dev_remap_addr(dev);
1226 if (!pdata->iobase)
1227 return -EINVAL;
Wilson Lee41d6d1e2017-08-22 20:25:07 -07001228
1229 return macb_late_eth_ofdata_to_platdata(dev);
Haavard Skinnemoen51c8f242006-01-20 10:03:34 +01001230}
1231
Ramon Fried834040c2019-07-16 22:04:35 +03001232static const struct macb_config sama5d4_config = {
1233 .dma_burst_length = 4,
1234};
1235
Simon Glass75c5d182016-05-05 07:28:11 -06001236static const struct udevice_id macb_eth_ids[] = {
1237 { .compatible = "cdns,macb" },
Wenyou Yang8f155402017-04-14 14:36:05 +08001238 { .compatible = "cdns,at91sam9260-macb" },
1239 { .compatible = "atmel,sama5d2-gem" },
1240 { .compatible = "atmel,sama5d3-gem" },
Ramon Fried834040c2019-07-16 22:04:35 +03001241 { .compatible = "atmel,sama5d4-gem", .data = (ulong)&sama5d4_config },
Wilson Lee41d6d1e2017-08-22 20:25:07 -07001242 { .compatible = "cdns,zynq-gem" },
Simon Glass75c5d182016-05-05 07:28:11 -06001243 { }
1244};
1245
1246U_BOOT_DRIVER(eth_macb) = {
1247 .name = "eth_macb",
1248 .id = UCLASS_ETH,
1249 .of_match = macb_eth_ids,
1250 .ofdata_to_platdata = macb_eth_ofdata_to_platdata,
1251 .probe = macb_eth_probe,
Wenyou Yang44835ea2017-04-14 14:36:04 +08001252 .remove = macb_eth_remove,
Simon Glass75c5d182016-05-05 07:28:11 -06001253 .ops = &macb_eth_ops,
1254 .priv_auto_alloc_size = sizeof(struct macb_device),
1255 .platdata_auto_alloc_size = sizeof(struct eth_pdata),
1256};
1257#endif
1258
Jon Loeligerb1d408a2007-07-09 17:30:01 -05001259#endif