blob: 95b4d6e4f0aacb956fcccdb97a2cdbee66e1451a [file] [log] [blame]
Michal Simek19dfc472012-09-13 20:23:34 +00001/*
2 * (C) Copyright 2011 Michal Simek
3 *
4 * Michal SIMEK <monstr@monstr.eu>
5 *
6 * Based on Xilinx gmac driver:
7 * (C) Copyright 2011 Xilinx
8 *
Wolfgang Denkbd8ec7e2013-10-07 13:07:26 +02009 * SPDX-License-Identifier: GPL-2.0+
Michal Simek19dfc472012-09-13 20:23:34 +000010 */
11
12#include <common.h>
Michal Simek250e05e2015-11-30 14:14:56 +010013#include <dm.h>
Michal Simek19dfc472012-09-13 20:23:34 +000014#include <net.h>
Michal Simekb055f672014-04-25 14:17:38 +020015#include <netdev.h>
Michal Simek19dfc472012-09-13 20:23:34 +000016#include <config.h>
Michal Simekd9cfa972015-09-24 20:13:45 +020017#include <console.h>
Michal Simek19dfc472012-09-13 20:23:34 +000018#include <malloc.h>
19#include <asm/io.h>
20#include <phy.h>
21#include <miiphy.h>
Mateusz Kulikowski93597d72016-01-23 11:54:33 +010022#include <wait_bit.h>
Michal Simek19dfc472012-09-13 20:23:34 +000023#include <watchdog.h>
Siva Durga Prasad Paladugu2b0690e2014-12-06 12:57:53 +053024#include <asm/system.h>
David Andrey73875dc2013-04-05 17:24:24 +020025#include <asm/arch/hardware.h>
Michal Simekd9f2c112012-10-15 14:01:23 +020026#include <asm/arch/sys_proto.h>
Masahiro Yamada64e4f7f2016-09-21 11:28:57 +090027#include <linux/errno.h>
Michal Simek19dfc472012-09-13 20:23:34 +000028
Michal Simek250e05e2015-11-30 14:14:56 +010029DECLARE_GLOBAL_DATA_PTR;
30
Michal Simek19dfc472012-09-13 20:23:34 +000031/* Bit/mask specification */
32#define ZYNQ_GEM_PHYMNTNC_OP_MASK 0x40020000 /* operation mask bits */
33#define ZYNQ_GEM_PHYMNTNC_OP_R_MASK 0x20000000 /* read operation */
34#define ZYNQ_GEM_PHYMNTNC_OP_W_MASK 0x10000000 /* write operation */
35#define ZYNQ_GEM_PHYMNTNC_PHYAD_SHIFT_MASK 23 /* Shift bits for PHYAD */
36#define ZYNQ_GEM_PHYMNTNC_PHREG_SHIFT_MASK 18 /* Shift bits for PHREG */
37
38#define ZYNQ_GEM_RXBUF_EOF_MASK 0x00008000 /* End of frame. */
39#define ZYNQ_GEM_RXBUF_SOF_MASK 0x00004000 /* Start of frame. */
40#define ZYNQ_GEM_RXBUF_LEN_MASK 0x00003FFF /* Mask for length field */
41
42#define ZYNQ_GEM_RXBUF_WRAP_MASK 0x00000002 /* Wrap bit, last BD */
43#define ZYNQ_GEM_RXBUF_NEW_MASK 0x00000001 /* Used bit.. */
44#define ZYNQ_GEM_RXBUF_ADD_MASK 0xFFFFFFFC /* Mask for address */
45
46/* Wrap bit, last descriptor */
47#define ZYNQ_GEM_TXBUF_WRAP_MASK 0x40000000
48#define ZYNQ_GEM_TXBUF_LAST_MASK 0x00008000 /* Last buffer */
Michal Simek1dc446e2015-08-17 09:58:54 +020049#define ZYNQ_GEM_TXBUF_USED_MASK 0x80000000 /* Used by Hw */
Michal Simek19dfc472012-09-13 20:23:34 +000050
Michal Simek19dfc472012-09-13 20:23:34 +000051#define ZYNQ_GEM_NWCTRL_TXEN_MASK 0x00000008 /* Enable transmit */
52#define ZYNQ_GEM_NWCTRL_RXEN_MASK 0x00000004 /* Enable receive */
53#define ZYNQ_GEM_NWCTRL_MDEN_MASK 0x00000010 /* Enable MDIO port */
54#define ZYNQ_GEM_NWCTRL_STARTTX_MASK 0x00000200 /* Start tx (tx_go) */
55
Siva Durga Prasad Paladugu7e7fcc32016-05-16 15:31:37 +053056#define ZYNQ_GEM_NWCFG_SPEED100 0x00000001 /* 100 Mbps operation */
57#define ZYNQ_GEM_NWCFG_SPEED1000 0x00000400 /* 1Gbps operation */
58#define ZYNQ_GEM_NWCFG_FDEN 0x00000002 /* Full Duplex mode */
59#define ZYNQ_GEM_NWCFG_FSREM 0x00020000 /* FCS removal */
Siva Durga Prasad Paladuguf6c2d202016-05-16 15:31:38 +053060#define ZYNQ_GEM_NWCFG_SGMII_ENBL 0x08000000 /* SGMII Enable */
Siva Durga Prasad Paladugu7e7fcc32016-05-16 15:31:37 +053061#define ZYNQ_GEM_NWCFG_PCS_SEL 0x00000800 /* PCS select */
Michal Simek780c5352015-09-08 17:20:01 +020062#ifdef CONFIG_ARM64
Siva Durga Prasad Paladugu7e7fcc32016-05-16 15:31:37 +053063#define ZYNQ_GEM_NWCFG_MDCCLKDIV 0x00100000 /* Div pclk by 64, max 160MHz */
Michal Simek780c5352015-09-08 17:20:01 +020064#else
Siva Durga Prasad Paladugu7e7fcc32016-05-16 15:31:37 +053065#define ZYNQ_GEM_NWCFG_MDCCLKDIV 0x000c0000 /* Div pclk by 48, max 120MHz */
Michal Simek780c5352015-09-08 17:20:01 +020066#endif
Michal Simek19dfc472012-09-13 20:23:34 +000067
Siva Durga Prasad Paladugu71245a42014-07-08 15:31:03 +053068#ifdef CONFIG_ARM64
69# define ZYNQ_GEM_DBUS_WIDTH (1 << 21) /* 64 bit bus */
70#else
71# define ZYNQ_GEM_DBUS_WIDTH (0 << 21) /* 32 bit bus */
72#endif
73
74#define ZYNQ_GEM_NWCFG_INIT (ZYNQ_GEM_DBUS_WIDTH | \
75 ZYNQ_GEM_NWCFG_FDEN | \
Michal Simek19dfc472012-09-13 20:23:34 +000076 ZYNQ_GEM_NWCFG_FSREM | \
77 ZYNQ_GEM_NWCFG_MDCCLKDIV)
78
79#define ZYNQ_GEM_NWSR_MDIOIDLE_MASK 0x00000004 /* PHY management idle */
80
81#define ZYNQ_GEM_DMACR_BLENGTH 0x00000004 /* INCR4 AHB bursts */
82/* Use full configured addressable space (8 Kb) */
83#define ZYNQ_GEM_DMACR_RXSIZE 0x00000300
84/* Use full configured addressable space (4 Kb) */
85#define ZYNQ_GEM_DMACR_TXSIZE 0x00000400
86/* Set with binary 00011000 to use 1536 byte(1*max length frame/buffer) */
87#define ZYNQ_GEM_DMACR_RXBUF 0x00180000
88
89#define ZYNQ_GEM_DMACR_INIT (ZYNQ_GEM_DMACR_BLENGTH | \
90 ZYNQ_GEM_DMACR_RXSIZE | \
91 ZYNQ_GEM_DMACR_TXSIZE | \
92 ZYNQ_GEM_DMACR_RXBUF)
93
Michal Simek975ae352015-08-17 09:57:46 +020094#define ZYNQ_GEM_TSR_DONE 0x00000020 /* Tx done mask */
95
Siva Durga Prasad Paladugu45467002016-03-25 12:53:44 +053096#define ZYNQ_GEM_PCS_CTL_ANEG_ENBL 0x1000
97
Michal Simekab72cb42013-04-22 14:41:09 +020098/* Use MII register 1 (MII status register) to detect PHY */
99#define PHY_DETECT_REG 1
100
101/* Mask used to verify certain PHY features (or register contents)
102 * in the register above:
103 * 0x1000: 10Mbps full duplex support
104 * 0x0800: 10Mbps half duplex support
105 * 0x0008: Auto-negotiation support
106 */
107#define PHY_DETECT_MASK 0x1808
108
Srikanth Thokalacbf20b22013-11-08 22:55:48 +0530109/* TX BD status masks */
110#define ZYNQ_GEM_TXBUF_FRMLEN_MASK 0x000007ff
111#define ZYNQ_GEM_TXBUF_EXHAUSTED 0x08000000
112#define ZYNQ_GEM_TXBUF_UNDERRUN 0x10000000
113
Soren Brinkmann4dded982013-11-21 13:39:01 -0800114/* Clock frequencies for different speeds */
115#define ZYNQ_GEM_FREQUENCY_10 2500000UL
116#define ZYNQ_GEM_FREQUENCY_100 25000000UL
117#define ZYNQ_GEM_FREQUENCY_1000 125000000UL
118
Michal Simek19dfc472012-09-13 20:23:34 +0000119/* Device registers */
120struct zynq_gem_regs {
Michal Simek74a86e82015-10-05 11:49:43 +0200121 u32 nwctrl; /* 0x0 - Network Control reg */
122 u32 nwcfg; /* 0x4 - Network Config reg */
123 u32 nwsr; /* 0x8 - Network Status reg */
Michal Simek19dfc472012-09-13 20:23:34 +0000124 u32 reserved1;
Michal Simek74a86e82015-10-05 11:49:43 +0200125 u32 dmacr; /* 0x10 - DMA Control reg */
126 u32 txsr; /* 0x14 - TX Status reg */
127 u32 rxqbase; /* 0x18 - RX Q Base address reg */
128 u32 txqbase; /* 0x1c - TX Q Base address reg */
129 u32 rxsr; /* 0x20 - RX Status reg */
Michal Simek19dfc472012-09-13 20:23:34 +0000130 u32 reserved2[2];
Michal Simek74a86e82015-10-05 11:49:43 +0200131 u32 idr; /* 0x2c - Interrupt Disable reg */
Michal Simek19dfc472012-09-13 20:23:34 +0000132 u32 reserved3;
Michal Simek74a86e82015-10-05 11:49:43 +0200133 u32 phymntnc; /* 0x34 - Phy Maintaince reg */
Michal Simek19dfc472012-09-13 20:23:34 +0000134 u32 reserved4[18];
Michal Simek74a86e82015-10-05 11:49:43 +0200135 u32 hashl; /* 0x80 - Hash Low address reg */
136 u32 hashh; /* 0x84 - Hash High address reg */
Michal Simek19dfc472012-09-13 20:23:34 +0000137#define LADDR_LOW 0
138#define LADDR_HIGH 1
Michal Simek74a86e82015-10-05 11:49:43 +0200139 u32 laddr[4][LADDR_HIGH + 1]; /* 0x8c - Specific1 addr low/high reg */
140 u32 match[4]; /* 0xa8 - Type ID1 Match reg */
Michal Simek19dfc472012-09-13 20:23:34 +0000141 u32 reserved6[18];
Michal Simekff5dbef2015-10-05 12:49:48 +0200142#define STAT_SIZE 44
143 u32 stat[STAT_SIZE]; /* 0x100 - Octects transmitted Low reg */
Siva Durga Prasad Paladugu45467002016-03-25 12:53:44 +0530144 u32 reserved9[20];
145 u32 pcscntrl;
146 u32 reserved7[143];
Edgar E. Iglesias23045112015-09-25 23:50:07 -0700147 u32 transmit_q1_ptr; /* 0x440 - Transmit priority queue 1 */
148 u32 reserved8[15];
149 u32 receive_q1_ptr; /* 0x480 - Receive priority queue 1 */
Michal Simek19dfc472012-09-13 20:23:34 +0000150};
151
152/* BD descriptors */
153struct emac_bd {
154 u32 addr; /* Next descriptor pointer */
155 u32 status;
156};
157
Siva Durga Prasad Paladugu55931cf2015-04-15 12:15:01 +0530158#define RX_BUF 32
Srikanth Thokalacbf20b22013-11-08 22:55:48 +0530159/* Page table entries are set to 1MB, or multiples of 1MB
160 * (not < 1MB). driver uses less bd's so use 1MB bdspace.
161 */
162#define BD_SPACE 0x100000
163/* BD separation space */
Michal Simekc6eb0bc2015-08-17 09:45:53 +0200164#define BD_SEPRN_SPACE (RX_BUF * sizeof(struct emac_bd))
Michal Simek19dfc472012-09-13 20:23:34 +0000165
Edgar E. Iglesias23045112015-09-25 23:50:07 -0700166/* Setup the first free TX descriptor */
167#define TX_FREE_DESC 2
168
Michal Simek19dfc472012-09-13 20:23:34 +0000169/* Initialized, rxbd_current, rx_first_buf must be 0 after init */
170struct zynq_gem_priv {
Srikanth Thokalacbf20b22013-11-08 22:55:48 +0530171 struct emac_bd *tx_bd;
172 struct emac_bd *rx_bd;
173 char *rxbuffers;
Michal Simek19dfc472012-09-13 20:23:34 +0000174 u32 rxbd_current;
175 u32 rx_first_buf;
176 int phyaddr;
David Andrey73875dc2013-04-05 17:24:24 +0200177 u32 emio;
Michal Simeka94f84d2013-01-24 13:04:12 +0100178 int init;
Michal Simek1a63ee22015-11-30 10:24:15 +0100179 struct zynq_gem_regs *iobase;
Michal Simek492de0f2015-10-07 16:42:56 +0200180 phy_interface_t interface;
Michal Simek19dfc472012-09-13 20:23:34 +0000181 struct phy_device *phydev;
Dan Murphya5828712016-05-02 15:45:57 -0500182 int phy_of_handle;
Michal Simek19dfc472012-09-13 20:23:34 +0000183 struct mii_dev *bus;
184};
185
Michal Simek1a63ee22015-11-30 10:24:15 +0100186static u32 phy_setup_op(struct zynq_gem_priv *priv, u32 phy_addr, u32 regnum,
187 u32 op, u16 *data)
Michal Simek19dfc472012-09-13 20:23:34 +0000188{
189 u32 mgtcr;
Michal Simek1a63ee22015-11-30 10:24:15 +0100190 struct zynq_gem_regs *regs = priv->iobase;
Michal Simeke6709652016-12-12 09:47:26 +0100191 int err;
Michal Simek19dfc472012-09-13 20:23:34 +0000192
Michal Simeke6709652016-12-12 09:47:26 +0100193 err = wait_for_bit(__func__, &regs->nwsr, ZYNQ_GEM_NWSR_MDIOIDLE_MASK,
194 true, 20000, true);
195 if (err)
196 return err;
Michal Simek19dfc472012-09-13 20:23:34 +0000197
198 /* Construct mgtcr mask for the operation */
199 mgtcr = ZYNQ_GEM_PHYMNTNC_OP_MASK | op |
200 (phy_addr << ZYNQ_GEM_PHYMNTNC_PHYAD_SHIFT_MASK) |
201 (regnum << ZYNQ_GEM_PHYMNTNC_PHREG_SHIFT_MASK) | *data;
202
203 /* Write mgtcr and wait for completion */
204 writel(mgtcr, &regs->phymntnc);
205
Michal Simeke6709652016-12-12 09:47:26 +0100206 err = wait_for_bit(__func__, &regs->nwsr, ZYNQ_GEM_NWSR_MDIOIDLE_MASK,
207 true, 20000, true);
208 if (err)
209 return err;
Michal Simek19dfc472012-09-13 20:23:34 +0000210
211 if (op == ZYNQ_GEM_PHYMNTNC_OP_R_MASK)
212 *data = readl(&regs->phymntnc);
213
214 return 0;
215}
216
Michal Simek1a63ee22015-11-30 10:24:15 +0100217static u32 phyread(struct zynq_gem_priv *priv, u32 phy_addr,
218 u32 regnum, u16 *val)
Michal Simek19dfc472012-09-13 20:23:34 +0000219{
Michal Simekc919c2c2015-10-07 16:34:51 +0200220 u32 ret;
221
Michal Simek1a63ee22015-11-30 10:24:15 +0100222 ret = phy_setup_op(priv, phy_addr, regnum,
223 ZYNQ_GEM_PHYMNTNC_OP_R_MASK, val);
Michal Simekc919c2c2015-10-07 16:34:51 +0200224
225 if (!ret)
226 debug("%s: phy_addr %d, regnum 0x%x, val 0x%x\n", __func__,
227 phy_addr, regnum, *val);
228
229 return ret;
Michal Simek19dfc472012-09-13 20:23:34 +0000230}
231
Michal Simek1a63ee22015-11-30 10:24:15 +0100232static u32 phywrite(struct zynq_gem_priv *priv, u32 phy_addr,
233 u32 regnum, u16 data)
Michal Simek19dfc472012-09-13 20:23:34 +0000234{
Michal Simekc919c2c2015-10-07 16:34:51 +0200235 debug("%s: phy_addr %d, regnum 0x%x, data 0x%x\n", __func__, phy_addr,
236 regnum, data);
237
Michal Simek1a63ee22015-11-30 10:24:15 +0100238 return phy_setup_op(priv, phy_addr, regnum,
239 ZYNQ_GEM_PHYMNTNC_OP_W_MASK, &data);
Michal Simek19dfc472012-09-13 20:23:34 +0000240}
241
Michal Simek250e05e2015-11-30 14:14:56 +0100242static int phy_detection(struct udevice *dev)
Michal Simekab72cb42013-04-22 14:41:09 +0200243{
244 int i;
245 u16 phyreg;
246 struct zynq_gem_priv *priv = dev->priv;
247
248 if (priv->phyaddr != -1) {
Michal Simek1a63ee22015-11-30 10:24:15 +0100249 phyread(priv, priv->phyaddr, PHY_DETECT_REG, &phyreg);
Michal Simekab72cb42013-04-22 14:41:09 +0200250 if ((phyreg != 0xFFFF) &&
251 ((phyreg & PHY_DETECT_MASK) == PHY_DETECT_MASK)) {
252 /* Found a valid PHY address */
253 debug("Default phy address %d is valid\n",
254 priv->phyaddr);
Michal Simek75fbb692015-11-30 13:38:32 +0100255 return 0;
Michal Simekab72cb42013-04-22 14:41:09 +0200256 } else {
257 debug("PHY address is not setup correctly %d\n",
258 priv->phyaddr);
259 priv->phyaddr = -1;
260 }
261 }
262
263 debug("detecting phy address\n");
264 if (priv->phyaddr == -1) {
265 /* detect the PHY address */
266 for (i = 31; i >= 0; i--) {
Michal Simek1a63ee22015-11-30 10:24:15 +0100267 phyread(priv, i, PHY_DETECT_REG, &phyreg);
Michal Simekab72cb42013-04-22 14:41:09 +0200268 if ((phyreg != 0xFFFF) &&
269 ((phyreg & PHY_DETECT_MASK) == PHY_DETECT_MASK)) {
270 /* Found a valid PHY address */
271 priv->phyaddr = i;
272 debug("Found valid phy address, %d\n", i);
Michal Simek75fbb692015-11-30 13:38:32 +0100273 return 0;
Michal Simekab72cb42013-04-22 14:41:09 +0200274 }
275 }
276 }
277 printf("PHY is not detected\n");
Michal Simek75fbb692015-11-30 13:38:32 +0100278 return -1;
Michal Simekab72cb42013-04-22 14:41:09 +0200279}
280
Michal Simek250e05e2015-11-30 14:14:56 +0100281static int zynq_gem_setup_mac(struct udevice *dev)
Michal Simek19dfc472012-09-13 20:23:34 +0000282{
283 u32 i, macaddrlow, macaddrhigh;
Michal Simek250e05e2015-11-30 14:14:56 +0100284 struct eth_pdata *pdata = dev_get_platdata(dev);
285 struct zynq_gem_priv *priv = dev_get_priv(dev);
286 struct zynq_gem_regs *regs = priv->iobase;
Michal Simek19dfc472012-09-13 20:23:34 +0000287
288 /* Set the MAC bits [31:0] in BOT */
Michal Simek250e05e2015-11-30 14:14:56 +0100289 macaddrlow = pdata->enetaddr[0];
290 macaddrlow |= pdata->enetaddr[1] << 8;
291 macaddrlow |= pdata->enetaddr[2] << 16;
292 macaddrlow |= pdata->enetaddr[3] << 24;
Michal Simek19dfc472012-09-13 20:23:34 +0000293
294 /* Set MAC bits [47:32] in TOP */
Michal Simek250e05e2015-11-30 14:14:56 +0100295 macaddrhigh = pdata->enetaddr[4];
296 macaddrhigh |= pdata->enetaddr[5] << 8;
Michal Simek19dfc472012-09-13 20:23:34 +0000297
298 for (i = 0; i < 4; i++) {
299 writel(0, &regs->laddr[i][LADDR_LOW]);
300 writel(0, &regs->laddr[i][LADDR_HIGH]);
301 /* Do not use MATCHx register */
302 writel(0, &regs->match[i]);
303 }
304
305 writel(macaddrlow, &regs->laddr[0][LADDR_LOW]);
306 writel(macaddrhigh, &regs->laddr[0][LADDR_HIGH]);
307
308 return 0;
309}
310
Michal Simek250e05e2015-11-30 14:14:56 +0100311static int zynq_phy_init(struct udevice *dev)
Michal Simek19dfc472012-09-13 20:23:34 +0000312{
Michal Simek75fbb692015-11-30 13:38:32 +0100313 int ret;
Michal Simek250e05e2015-11-30 14:14:56 +0100314 struct zynq_gem_priv *priv = dev_get_priv(dev);
315 struct zynq_gem_regs *regs = priv->iobase;
Michal Simek19dfc472012-09-13 20:23:34 +0000316 const u32 supported = SUPPORTED_10baseT_Half |
317 SUPPORTED_10baseT_Full |
318 SUPPORTED_100baseT_Half |
319 SUPPORTED_100baseT_Full |
320 SUPPORTED_1000baseT_Half |
321 SUPPORTED_1000baseT_Full;
322
Michal Simeke9ecc1c2015-11-30 13:58:36 +0100323 /* Enable only MDIO bus */
324 writel(ZYNQ_GEM_NWCTRL_MDEN_MASK, &regs->nwctrl);
325
Siva Durga Prasad Paladugu65d3f3a2016-02-05 13:22:11 +0530326 if (priv->interface != PHY_INTERFACE_MODE_SGMII) {
327 ret = phy_detection(dev);
328 if (ret) {
329 printf("GEM PHY init failed\n");
330 return ret;
331 }
Michal Simek7cd7ea62015-11-30 13:54:43 +0100332 }
333
334 priv->phydev = phy_connect(priv->bus, priv->phyaddr, dev,
335 priv->interface);
Michal Simek2c68e082015-11-30 14:03:37 +0100336 if (!priv->phydev)
337 return -ENODEV;
Michal Simek7cd7ea62015-11-30 13:54:43 +0100338
339 priv->phydev->supported = supported | ADVERTISED_Pause |
340 ADVERTISED_Asym_Pause;
341 priv->phydev->advertising = priv->phydev->supported;
Michal Simek7cd7ea62015-11-30 13:54:43 +0100342
Dan Murphya5828712016-05-02 15:45:57 -0500343 if (priv->phy_of_handle > 0)
344 priv->phydev->dev->of_offset = priv->phy_of_handle;
345
Michal Simek24ce2322016-05-18 14:37:23 +0200346 return phy_config(priv->phydev);
Michal Simek7cd7ea62015-11-30 13:54:43 +0100347}
348
Michal Simek250e05e2015-11-30 14:14:56 +0100349static int zynq_gem_init(struct udevice *dev)
Michal Simek7cd7ea62015-11-30 13:54:43 +0100350{
Siva Durga Prasad Paladugu65d3f3a2016-02-05 13:22:11 +0530351 u32 i, nwconfig;
Michal Simekdbc0cfc2016-05-18 12:37:22 +0200352 int ret;
Michal Simek7cd7ea62015-11-30 13:54:43 +0100353 unsigned long clk_rate = 0;
Michal Simek250e05e2015-11-30 14:14:56 +0100354 struct zynq_gem_priv *priv = dev_get_priv(dev);
355 struct zynq_gem_regs *regs = priv->iobase;
Michal Simek7cd7ea62015-11-30 13:54:43 +0100356 struct emac_bd *dummy_tx_bd = &priv->tx_bd[TX_FREE_DESC];
357 struct emac_bd *dummy_rx_bd = &priv->tx_bd[TX_FREE_DESC + 2];
358
Michal Simeka94f84d2013-01-24 13:04:12 +0100359 if (!priv->init) {
360 /* Disable all interrupts */
361 writel(0xFFFFFFFF, &regs->idr);
Michal Simek19dfc472012-09-13 20:23:34 +0000362
Michal Simeka94f84d2013-01-24 13:04:12 +0100363 /* Disable the receiver & transmitter */
364 writel(0, &regs->nwctrl);
365 writel(0, &regs->txsr);
366 writel(0, &regs->rxsr);
367 writel(0, &regs->phymntnc);
Michal Simek19dfc472012-09-13 20:23:34 +0000368
Michal Simeka94f84d2013-01-24 13:04:12 +0100369 /* Clear the Hash registers for the mac address
370 * pointed by AddressPtr
371 */
372 writel(0x0, &regs->hashl);
373 /* Write bits [63:32] in TOP */
374 writel(0x0, &regs->hashh);
Michal Simek19dfc472012-09-13 20:23:34 +0000375
Michal Simeka94f84d2013-01-24 13:04:12 +0100376 /* Clear all counters */
Michal Simekff5dbef2015-10-05 12:49:48 +0200377 for (i = 0; i < STAT_SIZE; i++)
Michal Simeka94f84d2013-01-24 13:04:12 +0100378 readl(&regs->stat[i]);
Michal Simek19dfc472012-09-13 20:23:34 +0000379
Michal Simeka94f84d2013-01-24 13:04:12 +0100380 /* Setup RxBD space */
Srikanth Thokalacbf20b22013-11-08 22:55:48 +0530381 memset(priv->rx_bd, 0, RX_BUF * sizeof(struct emac_bd));
Michal Simek19dfc472012-09-13 20:23:34 +0000382
Michal Simeka94f84d2013-01-24 13:04:12 +0100383 for (i = 0; i < RX_BUF; i++) {
384 priv->rx_bd[i].status = 0xF0000000;
385 priv->rx_bd[i].addr =
Prabhakar Kushwaha1e9e6192015-10-25 13:18:54 +0530386 ((ulong)(priv->rxbuffers) +
Michal Simek19dfc472012-09-13 20:23:34 +0000387 (i * PKTSIZE_ALIGN));
Michal Simeka94f84d2013-01-24 13:04:12 +0100388 }
389 /* WRAP bit to last BD */
390 priv->rx_bd[--i].addr |= ZYNQ_GEM_RXBUF_WRAP_MASK;
391 /* Write RxBDs to IP */
Prabhakar Kushwaha1e9e6192015-10-25 13:18:54 +0530392 writel((ulong)priv->rx_bd, &regs->rxqbase);
Michal Simek19dfc472012-09-13 20:23:34 +0000393
Michal Simeka94f84d2013-01-24 13:04:12 +0100394 /* Setup for DMA Configuration register */
395 writel(ZYNQ_GEM_DMACR_INIT, &regs->dmacr);
Michal Simek19dfc472012-09-13 20:23:34 +0000396
Michal Simeka94f84d2013-01-24 13:04:12 +0100397 /* Setup for Network Control register, MDIO, Rx and Tx enable */
Michal Simekd9f2c112012-10-15 14:01:23 +0200398 setbits_le32(&regs->nwctrl, ZYNQ_GEM_NWCTRL_MDEN_MASK);
Michal Simek19dfc472012-09-13 20:23:34 +0000399
Edgar E. Iglesias23045112015-09-25 23:50:07 -0700400 /* Disable the second priority queue */
401 dummy_tx_bd->addr = 0;
402 dummy_tx_bd->status = ZYNQ_GEM_TXBUF_WRAP_MASK |
403 ZYNQ_GEM_TXBUF_LAST_MASK|
404 ZYNQ_GEM_TXBUF_USED_MASK;
405
406 dummy_rx_bd->addr = ZYNQ_GEM_RXBUF_WRAP_MASK |
407 ZYNQ_GEM_RXBUF_NEW_MASK;
408 dummy_rx_bd->status = 0;
409 flush_dcache_range((ulong)&dummy_tx_bd, (ulong)&dummy_tx_bd +
410 sizeof(dummy_tx_bd));
411 flush_dcache_range((ulong)&dummy_rx_bd, (ulong)&dummy_rx_bd +
412 sizeof(dummy_rx_bd));
413
414 writel((ulong)dummy_tx_bd, &regs->transmit_q1_ptr);
415 writel((ulong)dummy_rx_bd, &regs->receive_q1_ptr);
416
Michal Simeka94f84d2013-01-24 13:04:12 +0100417 priv->init++;
418 }
419
Michal Simekdbc0cfc2016-05-18 12:37:22 +0200420 ret = phy_startup(priv->phydev);
421 if (ret)
422 return ret;
Michal Simek19dfc472012-09-13 20:23:34 +0000423
Michal Simek43b38322015-11-30 13:44:49 +0100424 if (!priv->phydev->link) {
425 printf("%s: No link.\n", priv->phydev->dev->name);
Michal Simek216b96d2013-11-12 14:25:29 +0100426 return -1;
427 }
428
Siva Durga Prasad Paladugu65d3f3a2016-02-05 13:22:11 +0530429 nwconfig = ZYNQ_GEM_NWCFG_INIT;
430
Siva Durga Prasad Paladugu45467002016-03-25 12:53:44 +0530431 if (priv->interface == PHY_INTERFACE_MODE_SGMII) {
Siva Durga Prasad Paladugu65d3f3a2016-02-05 13:22:11 +0530432 nwconfig |= ZYNQ_GEM_NWCFG_SGMII_ENBL |
433 ZYNQ_GEM_NWCFG_PCS_SEL;
Siva Durga Prasad Paladugu45467002016-03-25 12:53:44 +0530434#ifdef CONFIG_ARM64
435 writel(readl(&regs->pcscntrl) | ZYNQ_GEM_PCS_CTL_ANEG_ENBL,
436 &regs->pcscntrl);
437#endif
438 }
Siva Durga Prasad Paladugu65d3f3a2016-02-05 13:22:11 +0530439
Michal Simek43b38322015-11-30 13:44:49 +0100440 switch (priv->phydev->speed) {
Michal Simekd9f2c112012-10-15 14:01:23 +0200441 case SPEED_1000:
Siva Durga Prasad Paladugu65d3f3a2016-02-05 13:22:11 +0530442 writel(nwconfig | ZYNQ_GEM_NWCFG_SPEED1000,
Michal Simekd9f2c112012-10-15 14:01:23 +0200443 &regs->nwcfg);
Soren Brinkmann4dded982013-11-21 13:39:01 -0800444 clk_rate = ZYNQ_GEM_FREQUENCY_1000;
Michal Simekd9f2c112012-10-15 14:01:23 +0200445 break;
446 case SPEED_100:
Siva Durga Prasad Paladugu65d3f3a2016-02-05 13:22:11 +0530447 writel(nwconfig | ZYNQ_GEM_NWCFG_SPEED100,
Michal Simek64295952015-09-08 16:55:42 +0200448 &regs->nwcfg);
Soren Brinkmann4dded982013-11-21 13:39:01 -0800449 clk_rate = ZYNQ_GEM_FREQUENCY_100;
Michal Simekd9f2c112012-10-15 14:01:23 +0200450 break;
451 case SPEED_10:
Soren Brinkmann4dded982013-11-21 13:39:01 -0800452 clk_rate = ZYNQ_GEM_FREQUENCY_10;
Michal Simekd9f2c112012-10-15 14:01:23 +0200453 break;
454 }
David Andrey73875dc2013-04-05 17:24:24 +0200455
456 /* Change the rclk and clk only not using EMIO interface */
457 if (!priv->emio)
Michal Simek250e05e2015-11-30 14:14:56 +0100458 zynq_slcr_gem_clk_setup((ulong)priv->iobase !=
Soren Brinkmann4dded982013-11-21 13:39:01 -0800459 ZYNQ_GEM_BASEADDR0, clk_rate);
Michal Simekd9f2c112012-10-15 14:01:23 +0200460
461 setbits_le32(&regs->nwctrl, ZYNQ_GEM_NWCTRL_RXEN_MASK |
462 ZYNQ_GEM_NWCTRL_TXEN_MASK);
463
Michal Simek19dfc472012-09-13 20:23:34 +0000464 return 0;
465}
466
Michal Simek250e05e2015-11-30 14:14:56 +0100467static int zynq_gem_send(struct udevice *dev, void *ptr, int len)
Michal Simek19dfc472012-09-13 20:23:34 +0000468{
Srikanth Thokalacbf20b22013-11-08 22:55:48 +0530469 u32 addr, size;
Michal Simek250e05e2015-11-30 14:14:56 +0100470 struct zynq_gem_priv *priv = dev_get_priv(dev);
471 struct zynq_gem_regs *regs = priv->iobase;
Michal Simek1dc446e2015-08-17 09:58:54 +0200472 struct emac_bd *current_bd = &priv->tx_bd[1];
Michal Simek19dfc472012-09-13 20:23:34 +0000473
Michal Simek19dfc472012-09-13 20:23:34 +0000474 /* Setup Tx BD */
Srikanth Thokalacbf20b22013-11-08 22:55:48 +0530475 memset(priv->tx_bd, 0, sizeof(struct emac_bd));
Michal Simek19dfc472012-09-13 20:23:34 +0000476
Prabhakar Kushwaha1e9e6192015-10-25 13:18:54 +0530477 priv->tx_bd->addr = (ulong)ptr;
Srikanth Thokalacbf20b22013-11-08 22:55:48 +0530478 priv->tx_bd->status = (len & ZYNQ_GEM_TXBUF_FRMLEN_MASK) |
Michal Simek1dc446e2015-08-17 09:58:54 +0200479 ZYNQ_GEM_TXBUF_LAST_MASK;
480 /* Dummy descriptor to mark it as the last in descriptor chain */
481 current_bd->addr = 0x0;
482 current_bd->status = ZYNQ_GEM_TXBUF_WRAP_MASK |
483 ZYNQ_GEM_TXBUF_LAST_MASK|
484 ZYNQ_GEM_TXBUF_USED_MASK;
Srikanth Thokalacbf20b22013-11-08 22:55:48 +0530485
Michal Simekb6fe7ad2015-08-17 09:50:09 +0200486 /* setup BD */
487 writel((ulong)priv->tx_bd, &regs->txqbase);
488
Prabhakar Kushwaha1e9e6192015-10-25 13:18:54 +0530489 addr = (ulong) ptr;
Srikanth Thokalacbf20b22013-11-08 22:55:48 +0530490 addr &= ~(ARCH_DMA_MINALIGN - 1);
491 size = roundup(len, ARCH_DMA_MINALIGN);
492 flush_dcache_range(addr, addr + size);
Siva Durga Prasad Paladugu2b0690e2014-12-06 12:57:53 +0530493
Prabhakar Kushwaha1e9e6192015-10-25 13:18:54 +0530494 addr = (ulong)priv->rxbuffers;
Siva Durga Prasad Paladugu2b0690e2014-12-06 12:57:53 +0530495 addr &= ~(ARCH_DMA_MINALIGN - 1);
496 size = roundup((RX_BUF * PKTSIZE_ALIGN), ARCH_DMA_MINALIGN);
497 flush_dcache_range(addr, addr + size);
Srikanth Thokalacbf20b22013-11-08 22:55:48 +0530498 barrier();
Michal Simek19dfc472012-09-13 20:23:34 +0000499
500 /* Start transmit */
501 setbits_le32(&regs->nwctrl, ZYNQ_GEM_NWCTRL_STARTTX_MASK);
502
Srikanth Thokalacbf20b22013-11-08 22:55:48 +0530503 /* Read TX BD status */
Srikanth Thokalacbf20b22013-11-08 22:55:48 +0530504 if (priv->tx_bd->status & ZYNQ_GEM_TXBUF_EXHAUSTED)
505 printf("TX buffers exhausted in mid frame\n");
Michal Simek19dfc472012-09-13 20:23:34 +0000506
Michal Simek975ae352015-08-17 09:57:46 +0200507 return wait_for_bit(__func__, &regs->txsr, ZYNQ_GEM_TSR_DONE,
Mateusz Kulikowski93597d72016-01-23 11:54:33 +0100508 true, 20000, true);
Michal Simek19dfc472012-09-13 20:23:34 +0000509}
510
511/* Do not check frame_recd flag in rx_status register 0x20 - just poll BD */
Michal Simek250e05e2015-11-30 14:14:56 +0100512static int zynq_gem_recv(struct udevice *dev, int flags, uchar **packetp)
Michal Simek19dfc472012-09-13 20:23:34 +0000513{
514 int frame_len;
Michal Simek57b02692015-12-09 14:26:48 +0100515 u32 addr;
Michal Simek250e05e2015-11-30 14:14:56 +0100516 struct zynq_gem_priv *priv = dev_get_priv(dev);
Michal Simek19dfc472012-09-13 20:23:34 +0000517 struct emac_bd *current_bd = &priv->rx_bd[priv->rxbd_current];
Michal Simek19dfc472012-09-13 20:23:34 +0000518
519 if (!(current_bd->addr & ZYNQ_GEM_RXBUF_NEW_MASK))
Michal Simek57b02692015-12-09 14:26:48 +0100520 return -1;
Michal Simek19dfc472012-09-13 20:23:34 +0000521
522 if (!(current_bd->status &
523 (ZYNQ_GEM_RXBUF_SOF_MASK | ZYNQ_GEM_RXBUF_EOF_MASK))) {
524 printf("GEM: SOF or EOF not set for last buffer received!\n");
Michal Simek57b02692015-12-09 14:26:48 +0100525 return -1;
Michal Simek19dfc472012-09-13 20:23:34 +0000526 }
527
528 frame_len = current_bd->status & ZYNQ_GEM_RXBUF_LEN_MASK;
Michal Simek57b02692015-12-09 14:26:48 +0100529 if (!frame_len) {
530 printf("%s: Zero size packet?\n", __func__);
531 return -1;
532 }
Srikanth Thokalacbf20b22013-11-08 22:55:48 +0530533
Michal Simek57b02692015-12-09 14:26:48 +0100534 addr = current_bd->addr & ZYNQ_GEM_RXBUF_ADD_MASK;
535 addr &= ~(ARCH_DMA_MINALIGN - 1);
536 *packetp = (uchar *)(uintptr_t)addr;
Michal Simek19dfc472012-09-13 20:23:34 +0000537
Michal Simek57b02692015-12-09 14:26:48 +0100538 return frame_len;
539}
540
541static int zynq_gem_free_pkt(struct udevice *dev, uchar *packet, int length)
542{
543 struct zynq_gem_priv *priv = dev_get_priv(dev);
544 struct emac_bd *current_bd = &priv->rx_bd[priv->rxbd_current];
545 struct emac_bd *first_bd;
Michal Simek19dfc472012-09-13 20:23:34 +0000546
Michal Simek57b02692015-12-09 14:26:48 +0100547 if (current_bd->status & ZYNQ_GEM_RXBUF_SOF_MASK) {
548 priv->rx_first_buf = priv->rxbd_current;
549 } else {
550 current_bd->addr &= ~ZYNQ_GEM_RXBUF_NEW_MASK;
551 current_bd->status = 0xF0000000; /* FIXME */
552 }
Michal Simek19dfc472012-09-13 20:23:34 +0000553
Michal Simek57b02692015-12-09 14:26:48 +0100554 if (current_bd->status & ZYNQ_GEM_RXBUF_EOF_MASK) {
555 first_bd = &priv->rx_bd[priv->rx_first_buf];
556 first_bd->addr &= ~ZYNQ_GEM_RXBUF_NEW_MASK;
557 first_bd->status = 0xF0000000;
Michal Simek19dfc472012-09-13 20:23:34 +0000558 }
559
Michal Simek57b02692015-12-09 14:26:48 +0100560 if ((++priv->rxbd_current) >= RX_BUF)
561 priv->rxbd_current = 0;
562
Michal Simek139f4102015-12-09 14:16:32 +0100563 return 0;
Michal Simek19dfc472012-09-13 20:23:34 +0000564}
565
Michal Simek250e05e2015-11-30 14:14:56 +0100566static void zynq_gem_halt(struct udevice *dev)
Michal Simek19dfc472012-09-13 20:23:34 +0000567{
Michal Simek250e05e2015-11-30 14:14:56 +0100568 struct zynq_gem_priv *priv = dev_get_priv(dev);
569 struct zynq_gem_regs *regs = priv->iobase;
Michal Simek19dfc472012-09-13 20:23:34 +0000570
Michal Simekd9f2c112012-10-15 14:01:23 +0200571 clrsetbits_le32(&regs->nwctrl, ZYNQ_GEM_NWCTRL_RXEN_MASK |
572 ZYNQ_GEM_NWCTRL_TXEN_MASK, 0);
Michal Simek19dfc472012-09-13 20:23:34 +0000573}
574
Joe Hershberger7f4e5552016-01-26 11:57:03 -0600575__weak int zynq_board_read_rom_ethaddr(unsigned char *ethaddr)
576{
577 return -ENOSYS;
578}
579
580static int zynq_gem_read_rom_mac(struct udevice *dev)
581{
582 int retval;
583 struct eth_pdata *pdata = dev_get_platdata(dev);
584
585 retval = zynq_board_read_rom_ethaddr(pdata->enetaddr);
586 if (retval == -ENOSYS)
587 retval = 0;
588
589 return retval;
590}
591
Michal Simek250e05e2015-11-30 14:14:56 +0100592static int zynq_gem_miiphy_read(struct mii_dev *bus, int addr,
593 int devad, int reg)
Michal Simek19dfc472012-09-13 20:23:34 +0000594{
Michal Simek250e05e2015-11-30 14:14:56 +0100595 struct zynq_gem_priv *priv = bus->priv;
Michal Simek19dfc472012-09-13 20:23:34 +0000596 int ret;
Michal Simek250e05e2015-11-30 14:14:56 +0100597 u16 val;
Michal Simek19dfc472012-09-13 20:23:34 +0000598
Michal Simek250e05e2015-11-30 14:14:56 +0100599 ret = phyread(priv, addr, reg, &val);
600 debug("%s 0x%x, 0x%x, 0x%x, 0x%x\n", __func__, addr, reg, val, ret);
601 return val;
Michal Simek19dfc472012-09-13 20:23:34 +0000602}
603
Michal Simek250e05e2015-11-30 14:14:56 +0100604static int zynq_gem_miiphy_write(struct mii_dev *bus, int addr, int devad,
605 int reg, u16 value)
Michal Simek19dfc472012-09-13 20:23:34 +0000606{
Michal Simek250e05e2015-11-30 14:14:56 +0100607 struct zynq_gem_priv *priv = bus->priv;
Michal Simek19dfc472012-09-13 20:23:34 +0000608
Michal Simek250e05e2015-11-30 14:14:56 +0100609 debug("%s 0x%x, 0x%x, 0x%x\n", __func__, addr, reg, value);
610 return phywrite(priv, addr, reg, value);
Michal Simek19dfc472012-09-13 20:23:34 +0000611}
612
Michal Simek250e05e2015-11-30 14:14:56 +0100613static int zynq_gem_probe(struct udevice *dev)
Michal Simek19dfc472012-09-13 20:23:34 +0000614{
Srikanth Thokalacbf20b22013-11-08 22:55:48 +0530615 void *bd_space;
Michal Simek250e05e2015-11-30 14:14:56 +0100616 struct zynq_gem_priv *priv = dev_get_priv(dev);
617 int ret;
Michal Simek19dfc472012-09-13 20:23:34 +0000618
Srikanth Thokalacbf20b22013-11-08 22:55:48 +0530619 /* Align rxbuffers to ARCH_DMA_MINALIGN */
620 priv->rxbuffers = memalign(ARCH_DMA_MINALIGN, RX_BUF * PKTSIZE_ALIGN);
621 memset(priv->rxbuffers, 0, RX_BUF * PKTSIZE_ALIGN);
622
Siva Durga Prasad Paladugu2b0690e2014-12-06 12:57:53 +0530623 /* Align bd_space to MMU_SECTION_SHIFT */
Srikanth Thokalacbf20b22013-11-08 22:55:48 +0530624 bd_space = memalign(1 << MMU_SECTION_SHIFT, BD_SPACE);
Michal Simek0afb6b22015-04-15 13:31:28 +0200625 mmu_set_region_dcache_behaviour((phys_addr_t)bd_space,
626 BD_SPACE, DCACHE_OFF);
Srikanth Thokalacbf20b22013-11-08 22:55:48 +0530627
628 /* Initialize the bd spaces for tx and rx bd's */
629 priv->tx_bd = (struct emac_bd *)bd_space;
Prabhakar Kushwaha1e9e6192015-10-25 13:18:54 +0530630 priv->rx_bd = (struct emac_bd *)((ulong)bd_space + BD_SEPRN_SPACE);
Srikanth Thokalacbf20b22013-11-08 22:55:48 +0530631
Michal Simek250e05e2015-11-30 14:14:56 +0100632 priv->bus = mdio_alloc();
633 priv->bus->read = zynq_gem_miiphy_read;
634 priv->bus->write = zynq_gem_miiphy_write;
635 priv->bus->priv = priv;
Michal Simek19dfc472012-09-13 20:23:34 +0000636
Michal Simeke4dab432016-12-08 10:25:44 +0100637 ret = mdio_register_seq(priv->bus, dev->seq);
Michal Simek250e05e2015-11-30 14:14:56 +0100638 if (ret)
639 return ret;
Michal Simek19dfc472012-09-13 20:23:34 +0000640
Siva Durga Prasad Paladugub81fe872016-03-30 12:29:49 +0530641 return zynq_phy_init(dev);
Michal Simek250e05e2015-11-30 14:14:56 +0100642}
Michal Simek19dfc472012-09-13 20:23:34 +0000643
Michal Simek250e05e2015-11-30 14:14:56 +0100644static int zynq_gem_remove(struct udevice *dev)
645{
646 struct zynq_gem_priv *priv = dev_get_priv(dev);
Michal Simek19dfc472012-09-13 20:23:34 +0000647
Michal Simek250e05e2015-11-30 14:14:56 +0100648 free(priv->phydev);
649 mdio_unregister(priv->bus);
650 mdio_free(priv->bus);
Michal Simek19dfc472012-09-13 20:23:34 +0000651
Michal Simek250e05e2015-11-30 14:14:56 +0100652 return 0;
653}
654
655static const struct eth_ops zynq_gem_ops = {
656 .start = zynq_gem_init,
657 .send = zynq_gem_send,
658 .recv = zynq_gem_recv,
Michal Simek57b02692015-12-09 14:26:48 +0100659 .free_pkt = zynq_gem_free_pkt,
Michal Simek250e05e2015-11-30 14:14:56 +0100660 .stop = zynq_gem_halt,
661 .write_hwaddr = zynq_gem_setup_mac,
Joe Hershberger7f4e5552016-01-26 11:57:03 -0600662 .read_rom_hwaddr = zynq_gem_read_rom_mac,
Michal Simek250e05e2015-11-30 14:14:56 +0100663};
Michal Simeke9ecc1c2015-11-30 13:58:36 +0100664
Michal Simek250e05e2015-11-30 14:14:56 +0100665static int zynq_gem_ofdata_to_platdata(struct udevice *dev)
666{
667 struct eth_pdata *pdata = dev_get_platdata(dev);
668 struct zynq_gem_priv *priv = dev_get_priv(dev);
Michal Simek3c4ce3c2015-11-30 14:17:50 +0100669 const char *phy_mode;
Michal Simek250e05e2015-11-30 14:14:56 +0100670
671 pdata->iobase = (phys_addr_t)dev_get_addr(dev);
672 priv->iobase = (struct zynq_gem_regs *)pdata->iobase;
673 /* Hardcode for now */
674 priv->emio = 0;
Michal Simekc6aa4132015-12-09 09:29:12 +0100675 priv->phyaddr = -1;
Michal Simek250e05e2015-11-30 14:14:56 +0100676
Dan Murphya5828712016-05-02 15:45:57 -0500677 priv->phy_of_handle = fdtdec_lookup_phandle(gd->fdt_blob,
678 dev->of_offset, "phy-handle");
679 if (priv->phy_of_handle > 0)
680 priv->phyaddr = fdtdec_get_int(gd->fdt_blob,
681 priv->phy_of_handle, "reg", -1);
Michal Simek250e05e2015-11-30 14:14:56 +0100682
Michal Simek3c4ce3c2015-11-30 14:17:50 +0100683 phy_mode = fdt_getprop(gd->fdt_blob, dev->of_offset, "phy-mode", NULL);
684 if (phy_mode)
685 pdata->phy_interface = phy_get_interface_by_name(phy_mode);
686 if (pdata->phy_interface == -1) {
687 debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode);
688 return -EINVAL;
689 }
690 priv->interface = pdata->phy_interface;
691
Siva Durga Prasad Paladugu65d3f3a2016-02-05 13:22:11 +0530692 priv->emio = fdtdec_get_bool(gd->fdt_blob, dev->of_offset, "xlnx,emio");
693
Michal Simekfca1e842016-11-16 08:41:01 +0100694 printf("ZYNQ GEM: %lx, phyaddr %x, interface %s\n", (ulong)priv->iobase,
Michal Simek3c4ce3c2015-11-30 14:17:50 +0100695 priv->phyaddr, phy_string_for_interface(priv->interface));
Michal Simek250e05e2015-11-30 14:14:56 +0100696
697 return 0;
Michal Simek19dfc472012-09-13 20:23:34 +0000698}
Michal Simek250e05e2015-11-30 14:14:56 +0100699
700static const struct udevice_id zynq_gem_ids[] = {
701 { .compatible = "cdns,zynqmp-gem" },
702 { .compatible = "cdns,zynq-gem" },
703 { .compatible = "cdns,gem" },
704 { }
705};
706
707U_BOOT_DRIVER(zynq_gem) = {
708 .name = "zynq_gem",
709 .id = UCLASS_ETH,
710 .of_match = zynq_gem_ids,
711 .ofdata_to_platdata = zynq_gem_ofdata_to_platdata,
712 .probe = zynq_gem_probe,
713 .remove = zynq_gem_remove,
714 .ops = &zynq_gem_ops,
715 .priv_auto_alloc_size = sizeof(struct zynq_gem_priv),
716 .platdata_auto_alloc_size = sizeof(struct eth_pdata),
717};