xilinx_emaclite.c 16.2 KB
Newer Older
1 2 3
/*
 * (C) Copyright 2007-2009 Michal Simek
 * (C) Copyright 2003 Xilinx Inc.
4 5 6
 *
 * Michal SIMEK <monstr@monstr.eu>
 *
7
 * SPDX-License-Identifier:	GPL-2.0+
8
 */
9 10 11 12

#include <common.h>
#include <net.h>
#include <config.h>
13
#include <dm.h>
14
#include <console.h>
Michal Simek's avatar
Michal Simek committed
15
#include <malloc.h>
16
#include <asm/io.h>
17 18
#include <phy.h>
#include <miiphy.h>
19
#include <fdtdec.h>
20
#include <asm-generic/errno.h>
21
#include <linux/kernel.h>
22

23
DECLARE_GLOBAL_DATA_PTR;
24 25

#define ENET_ADDR_LENGTH	6
26
#define ETH_FCS_LEN		4 /* Octets in the FCS */
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46

/* Xmit complete */
#define XEL_TSR_XMIT_BUSY_MASK		0x00000001UL
/* Xmit interrupt enable bit */
#define XEL_TSR_XMIT_IE_MASK		0x00000008UL
/* Program the MAC address */
#define XEL_TSR_PROGRAM_MASK		0x00000002UL
/* define for programming the MAC address into the EMAC Lite */
#define XEL_TSR_PROG_MAC_ADDR	(XEL_TSR_XMIT_BUSY_MASK | XEL_TSR_PROGRAM_MASK)

/* Transmit packet length upper byte */
#define XEL_TPLR_LENGTH_MASK_HI		0x0000FF00UL
/* Transmit packet length lower byte */
#define XEL_TPLR_LENGTH_MASK_LO		0x000000FFUL

/* Recv complete */
#define XEL_RSR_RECV_DONE_MASK		0x00000001UL
/* Recv interrupt enable bit */
#define XEL_RSR_RECV_IE_MASK		0x00000008UL

47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
/* MDIO Address Register Bit Masks */
#define XEL_MDIOADDR_REGADR_MASK  0x0000001F	/* Register Address */
#define XEL_MDIOADDR_PHYADR_MASK  0x000003E0	/* PHY Address */
#define XEL_MDIOADDR_PHYADR_SHIFT 5
#define XEL_MDIOADDR_OP_MASK	  0x00000400	/* RD/WR Operation */

/* MDIO Write Data Register Bit Masks */
#define XEL_MDIOWR_WRDATA_MASK	  0x0000FFFF	/* Data to be Written */

/* MDIO Read Data Register Bit Masks */
#define XEL_MDIORD_RDDATA_MASK	  0x0000FFFF	/* Data to be Read */

/* MDIO Control Register Bit Masks */
#define XEL_MDIOCTRL_MDIOSTS_MASK 0x00000001	/* MDIO Status Mask */
#define XEL_MDIOCTRL_MDIOEN_MASK  0x00000008	/* MDIO Enable */

63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
struct emaclite_regs {
	u32 tx_ping; /* 0x0 - TX Ping buffer */
	u32 reserved1[504];
	u32 mdioaddr; /* 0x7e4 - MDIO Address Register */
	u32 mdiowr; /* 0x7e8 - MDIO Write Data Register */
	u32 mdiord;/* 0x7ec - MDIO Read Data Register */
	u32 mdioctrl; /* 0x7f0 - MDIO Control Register */
	u32 tx_ping_tplr; /* 0x7f4 - Tx packet length */
	u32 global_interrupt; /* 0x7f8 - Global interrupt enable */
	u32 tx_ping_tsr; /* 0x7fc - Tx status */
	u32 tx_pong; /* 0x800 - TX Pong buffer */
	u32 reserved2[508];
	u32 tx_pong_tplr; /* 0xff4 - Tx packet length */
	u32 reserved3; /* 0xff8 */
	u32 tx_pong_tsr; /* 0xffc - Tx status */
	u32 rx_ping; /* 0x1000 - Receive Buffer */
	u32 reserved4[510];
	u32 rx_ping_rsr; /* 0x17fc - Rx status */
	u32 rx_pong; /* 0x1800 - Receive Buffer */
	u32 reserved5[510];
	u32 rx_pong_rsr; /* 0x1ffc - Rx status */
};

86
struct xemaclite {
87
	bool use_rx_pong_buffer_next;	/* Next RX buffer to read from */
88 89
	u32 txpp;		/* TX ping pong buffer */
	u32 rxpp;		/* RX ping pong buffer */
90
	int phyaddr;
91
	struct emaclite_regs *regs;
92 93
	struct phy_device *phydev;
	struct mii_dev *bus;
94
};
95

96
static u32 etherrxbuff[PKTSIZE_ALIGN/4]; /* Receive buffer */
97

Michal Simek's avatar
Michal Simek committed
98
static void xemaclite_alignedread(u32 *srcptr, void *destptr, u32 bytecount)
99
{
Michal Simek's avatar
Michal Simek committed
100
	u32 i;
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
	u32 alignbuffer;
	u32 *to32ptr;
	u32 *from32ptr;
	u8 *to8ptr;
	u8 *from8ptr;

	from32ptr = (u32 *) srcptr;

	/* Word aligned buffer, no correction needed. */
	to32ptr = (u32 *) destptr;
	while (bytecount > 3) {
		*to32ptr++ = *from32ptr++;
		bytecount -= 4;
	}
	to8ptr = (u8 *) to32ptr;

	alignbuffer = *from32ptr++;
Michal Simek's avatar
Michal Simek committed
118
	from8ptr = (u8 *) &alignbuffer;
119

Michal Simek's avatar
Michal Simek committed
120
	for (i = 0; i < bytecount; i++)
121 122 123
		*to8ptr++ = *from8ptr++;
}

124
static void xemaclite_alignedwrite(void *srcptr, u32 *destptr, u32 bytecount)
125
{
Michal Simek's avatar
Michal Simek committed
126
	u32 i;
127 128 129 130 131 132 133 134 135 136 137 138 139 140
	u32 alignbuffer;
	u32 *to32ptr = (u32 *) destptr;
	u32 *from32ptr;
	u8 *to8ptr;
	u8 *from8ptr;

	from32ptr = (u32 *) srcptr;
	while (bytecount > 3) {

		*to32ptr++ = *from32ptr++;
		bytecount -= 4;
	}

	alignbuffer = 0;
Michal Simek's avatar
Michal Simek committed
141
	to8ptr = (u8 *) &alignbuffer;
142 143
	from8ptr = (u8 *) from32ptr;

Michal Simek's avatar
Michal Simek committed
144
	for (i = 0; i < bytecount; i++)
145 146 147 148 149
		*to8ptr++ = *from8ptr++;

	*to32ptr++ = alignbuffer;
}

150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
static int wait_for_bit(const char *func, u32 *reg, const u32 mask,
			bool set, unsigned int timeout)
{
	u32 val;
	unsigned long start = get_timer(0);

	while (1) {
		val = readl(reg);

		if (!set)
			val = ~val;

		if ((val & mask) == mask)
			return 0;

		if (get_timer(start) > timeout)
			break;

		if (ctrlc()) {
			puts("Abort\n");
			return -EINTR;
		}

		udelay(1);
	}

	debug("%s: Timeout (reg=%p mask=%08x wait_set=%i)\n",
	      func, reg, mask, set);

	return -ETIMEDOUT;
}

182
static int mdio_wait(struct emaclite_regs *regs)
183
{
184
	return wait_for_bit(__func__, &regs->mdioctrl,
185 186 187
			    XEL_MDIOCTRL_MDIOSTS_MASK, false, 2000);
}

188
static u32 phyread(struct xemaclite *emaclite, u32 phyaddress, u32 registernum,
189 190
		   u16 *data)
{
191 192 193
	struct emaclite_regs *regs = emaclite->regs;

	if (mdio_wait(regs))
194 195
		return 1;

196 197
	u32 ctrl_reg = in_be32(&regs->mdioctrl);
	out_be32(&regs->mdioaddr, XEL_MDIOADDR_OP_MASK |
198
		 ((phyaddress << XEL_MDIOADDR_PHYADR_SHIFT) | registernum));
199
	out_be32(&regs->mdioctrl, ctrl_reg | XEL_MDIOCTRL_MDIOSTS_MASK);
200

201
	if (mdio_wait(regs))
202 203 204
		return 1;

	/* Read data */
205
	*data = in_be32(&regs->mdiord);
206 207 208
	return 0;
}

209
static u32 phywrite(struct xemaclite *emaclite, u32 phyaddress, u32 registernum,
210 211
		    u16 data)
{
212 213 214
	struct emaclite_regs *regs = emaclite->regs;

	if (mdio_wait(regs))
215 216 217 218 219 220 221 222
		return 1;

	/*
	 * Write the PHY address, register number and clear the OP bit in the
	 * MDIO Address register and then write the value into the MDIO Write
	 * Data register. Finally, set the Status bit in the MDIO Control
	 * register to start a MDIO write transaction.
	 */
223 224
	u32 ctrl_reg = in_be32(&regs->mdioctrl);
	out_be32(&regs->mdioaddr, ~XEL_MDIOADDR_OP_MASK &
225
		 ((phyaddress << XEL_MDIOADDR_PHYADR_SHIFT) | registernum));
226 227
	out_be32(&regs->mdiowr, data);
	out_be32(&regs->mdioctrl, ctrl_reg | XEL_MDIOCTRL_MDIOSTS_MASK);
228

229
	if (mdio_wait(regs))
230 231 232 233 234
		return 1;

	return 0;
}

235
static void emaclite_halt(struct udevice *dev)
236
{
Michal Simek's avatar
Michal Simek committed
237
	debug("eth_halt\n");
238 239
}

240 241 242 243 244 245 246 247 248 249 250
/* Use MII register 1 (MII status register) to detect PHY */
#define PHY_DETECT_REG  1

/* Mask used to verify certain PHY features (or register contents)
 * in the register above:
 *  0x1000: 10Mbps full duplex support
 *  0x0800: 10Mbps half duplex support
 *  0x0008: Auto-negotiation support
 */
#define PHY_DETECT_MASK 0x1808

251
static int setup_phy(struct udevice *dev)
252 253 254
{
	int i;
	u16 phyreg;
255
	struct xemaclite *emaclite = dev_get_priv(dev);
256 257 258 259 260 261 262 263
	struct phy_device *phydev;

	u32 supported = SUPPORTED_10baseT_Half |
			SUPPORTED_10baseT_Full |
			SUPPORTED_100baseT_Half |
			SUPPORTED_100baseT_Full;

	if (emaclite->phyaddr != -1) {
264
		phyread(emaclite, emaclite->phyaddr, PHY_DETECT_REG, &phyreg);
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
		if ((phyreg != 0xFFFF) &&
		    ((phyreg & PHY_DETECT_MASK) == PHY_DETECT_MASK)) {
			/* Found a valid PHY address */
			debug("Default phy address %d is valid\n",
			      emaclite->phyaddr);
		} else {
			debug("PHY address is not setup correctly %d\n",
			      emaclite->phyaddr);
			emaclite->phyaddr = -1;
		}
	}

	if (emaclite->phyaddr == -1) {
		/* detect the PHY address */
		for (i = 31; i >= 0; i--) {
280
			phyread(emaclite, i, PHY_DETECT_REG, &phyreg);
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
			if ((phyreg != 0xFFFF) &&
			    ((phyreg & PHY_DETECT_MASK) == PHY_DETECT_MASK)) {
				/* Found a valid PHY address */
				emaclite->phyaddr = i;
				debug("emaclite: Found valid phy address, %d\n",
				      i);
				break;
			}
		}
	}

	/* interface - look at tsec */
	phydev = phy_connect(emaclite->bus, emaclite->phyaddr, dev,
			     PHY_INTERFACE_MODE_MII);
	/*
	 * Phy can support 1000baseT but device NOT that's why phydev->supported
	 * must be setup for 1000baseT. phydev->advertising setups what speeds
	 * will be used for autonegotiation where 1000baseT must be disabled.
	 */
	phydev->supported = supported | SUPPORTED_1000baseT_Half |
						SUPPORTED_1000baseT_Full;
	phydev->advertising = supported;
	emaclite->phydev = phydev;
	phy_config(phydev);
	phy_startup(phydev);

	if (!phydev->link) {
		printf("%s: No link.\n", phydev->dev->name);
		return 0;
	}

	/* Do not setup anything */
	return 1;
}

316
static int emaclite_init(struct udevice *dev)
317
{
318 319
	struct xemaclite *emaclite = dev_get_priv(dev);
	struct eth_pdata *pdata = dev_get_platdata(dev);
320 321
	struct emaclite_regs *regs = emaclite->regs;

Michal Simek's avatar
Michal Simek committed
322
	debug("EmacLite Initialization Started\n");
323 324 325 326 327

/*
 * TX - TX_PING & TX_PONG initialization
 */
	/* Restart PING TX */
328
	out_be32(&regs->tx_ping_tsr, 0);
329
	/* Copy MAC address */
330
	xemaclite_alignedwrite(pdata->enetaddr, &regs->tx_ping,
331
			       ENET_ADDR_LENGTH);
332
	/* Set the length */
333
	out_be32(&regs->tx_ping_tplr, ENET_ADDR_LENGTH);
334
	/* Update the MAC address in the EMAC Lite */
335
	out_be32(&regs->tx_ping_tsr, XEL_TSR_PROG_MAC_ADDR);
336
	/* Wait for EMAC Lite to finish with the MAC address update */
337
	while ((in_be32 (&regs->tx_ping_tsr) &
338 339
		XEL_TSR_PROG_MAC_ADDR) != 0)
		;
340

341 342
	if (emaclite->txpp) {
		/* The same operation with PONG TX */
343
		out_be32(&regs->tx_pong_tsr, 0);
344
		xemaclite_alignedwrite(pdata->enetaddr, &regs->tx_pong,
345 346 347 348 349
				       ENET_ADDR_LENGTH);
		out_be32(&regs->tx_pong_tplr, ENET_ADDR_LENGTH);
		out_be32(&regs->tx_pong_tsr, XEL_TSR_PROG_MAC_ADDR);
		while ((in_be32(&regs->tx_pong_tsr) &
		       XEL_TSR_PROG_MAC_ADDR) != 0)
350 351
			;
	}
352 353 354 355 356

/*
 * RX - RX_PING & RX_PONG initialization
 */
	/* Write out the value to flush the RX buffer */
357
	out_be32(&regs->rx_ping_rsr, XEL_RSR_RECV_IE_MASK);
358 359

	if (emaclite->rxpp)
360
		out_be32(&regs->rx_pong_rsr, XEL_RSR_RECV_IE_MASK);
361

362 363
	out_be32(&regs->mdioctrl, XEL_MDIOCTRL_MDIOEN_MASK);
	if (in_be32(&regs->mdioctrl) & XEL_MDIOCTRL_MDIOEN_MASK)
364 365
		if (!setup_phy(dev))
			return -1;
366

Michal Simek's avatar
Michal Simek committed
367
	debug("EmacLite Initialization complete\n");
368 369 370
	return 0;
}

371
static int xemaclite_txbufferavailable(struct xemaclite *emaclite)
372
{
373 374
	u32 tmp;
	struct emaclite_regs *regs = emaclite->regs;
375

376 377 378 379
	/*
	 * Read the other buffer register
	 * and determine if the other buffer is available
	 */
380 381 382
	tmp = ~in_be32(&regs->tx_ping_tsr);
	if (emaclite->txpp)
		tmp |= ~in_be32(&regs->tx_pong_tsr);
383

384
	return !(tmp & XEL_TSR_XMIT_BUSY_MASK);
385 386
}

387
static int emaclite_send(struct udevice *dev, void *ptr, int len)
Michal Simek's avatar
Michal Simek committed
388 389
{
	u32 reg;
390
	struct xemaclite *emaclite = dev_get_priv(dev);
391
	struct emaclite_regs *regs = emaclite->regs;
392

Michal Simek's avatar
Michal Simek committed
393
	u32 maxtry = 1000;
394

395 396
	if (len > PKTSIZE)
		len = PKTSIZE;
397

398
	while (xemaclite_txbufferavailable(emaclite) && maxtry) {
Michal Simek's avatar
Michal Simek committed
399
		udelay(10);
400 401 402 403
		maxtry--;
	}

	if (!maxtry) {
Michal Simek's avatar
Michal Simek committed
404
		printf("Error: Timeout waiting for ethernet TX buffer\n");
405
		/* Restart PING TX */
406
		out_be32(&regs->tx_ping_tsr, 0);
407
		if (emaclite->txpp) {
408
			out_be32(&regs->tx_pong_tsr, 0);
409
		}
410
		return -1;
411 412 413
	}

	/* Determine if the expected buffer address is empty */
414
	reg = in_be32(&regs->tx_ping_tsr);
415
	if ((reg & XEL_TSR_XMIT_BUSY_MASK) == 0) {
416
		debug("Send packet from tx_ping buffer\n");
417
		/* Write the frame to the buffer */
418 419 420 421
		xemaclite_alignedwrite(ptr, &regs->tx_ping, len);
		out_be32(&regs->tx_ping_tplr, len &
			(XEL_TPLR_LENGTH_MASK_HI | XEL_TPLR_LENGTH_MASK_LO));
		reg = in_be32(&regs->tx_ping_tsr);
422
		reg |= XEL_TSR_XMIT_BUSY_MASK;
423
		out_be32(&regs->tx_ping_tsr, reg);
424
		return 0;
425
	}
426 427 428

	if (emaclite->txpp) {
		/* Determine if the expected buffer address is empty */
429
		reg = in_be32(&regs->tx_pong_tsr);
430
		if ((reg & XEL_TSR_XMIT_BUSY_MASK) == 0) {
431
			debug("Send packet from tx_pong buffer\n");
432
			/* Write the frame to the buffer */
433 434 435 436 437
			xemaclite_alignedwrite(ptr, &regs->tx_pong, len);
			out_be32(&regs->tx_pong_tplr, len &
				 (XEL_TPLR_LENGTH_MASK_HI |
				  XEL_TPLR_LENGTH_MASK_LO));
			reg = in_be32(&regs->tx_pong_tsr);
438
			reg |= XEL_TSR_XMIT_BUSY_MASK;
439
			out_be32(&regs->tx_pong_tsr, reg);
440
			return 0;
441 442
		}
	}
443

Michal Simek's avatar
Michal Simek committed
444
	puts("Error while sending frame\n");
445
	return -1;
446 447
}

448
static int emaclite_recv(struct udevice *dev, int flags, uchar **packetp)
449
{
450 451
	u32 length, first_read, reg, attempt = 0;
	void *addr, *ack;
452
	struct xemaclite *emaclite = dev->priv;
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477
	struct emaclite_regs *regs = emaclite->regs;
	struct ethernet_hdr *eth;
	struct ip_udp_hdr *ip;

try_again:
	if (!emaclite->use_rx_pong_buffer_next) {
		reg = in_be32(&regs->rx_ping_rsr);
		debug("Testing data at rx_ping\n");
		if ((reg & XEL_RSR_RECV_DONE_MASK) == XEL_RSR_RECV_DONE_MASK) {
			debug("Data found in rx_ping buffer\n");
			addr = &regs->rx_ping;
			ack = &regs->rx_ping_rsr;
		} else {
			debug("Data not found in rx_ping buffer\n");
			/* Pong buffer is not available - return immediately */
			if (!emaclite->rxpp)
				return -1;

			/* Try pong buffer if this is first attempt */
			if (attempt++)
				return -1;
			emaclite->use_rx_pong_buffer_next =
					!emaclite->use_rx_pong_buffer_next;
			goto try_again;
		}
478
	} else {
479 480 481 482 483 484
		reg = in_be32(&regs->rx_pong_rsr);
		debug("Testing data at rx_pong\n");
		if ((reg & XEL_RSR_RECV_DONE_MASK) == XEL_RSR_RECV_DONE_MASK) {
			debug("Data found in rx_pong buffer\n");
			addr = &regs->rx_pong;
			ack = &regs->rx_pong_rsr;
485
		} else {
486 487 488 489 490 491 492
			debug("Data not found in rx_pong buffer\n");
			/* Try ping buffer if this is first attempt */
			if (attempt++)
				return -1;
			emaclite->use_rx_pong_buffer_next =
					!emaclite->use_rx_pong_buffer_next;
			goto try_again;
493 494
		}
	}
495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516

	/* Read all bytes for ARP packet with 32bit alignment - 48bytes  */
	first_read = ALIGN(ETHER_HDR_SIZE + ARP_HDR_SIZE + ETH_FCS_LEN, 4);
	xemaclite_alignedread(addr, etherrxbuff, first_read);

	/* Detect real packet size */
	eth = (struct ethernet_hdr *)etherrxbuff;
	switch (ntohs(eth->et_protlen)) {
	case PROT_ARP:
		length = first_read;
		debug("ARP Packet %x\n", length);
		break;
	case PROT_IP:
		ip = (struct ip_udp_hdr *)(etherrxbuff + ETHER_HDR_SIZE);
		length = ntohs(ip->ip_len);
		length += ETHER_HDR_SIZE + ETH_FCS_LEN;
		debug("IP Packet %x\n", length);
		break;
	default:
		debug("Other Packet\n");
		length = PKTSIZE;
		break;
517 518
	}

519 520 521 522 523
	/* Read the rest of the packet which is longer then first read */
	if (length != first_read)
		xemaclite_alignedread(addr + first_read,
				      etherrxbuff + first_read,
				      length - first_read);
524 525

	/* Acknowledge the frame */
526
	reg = in_be32(ack);
527
	reg &= ~XEL_RSR_RECV_DONE_MASK;
528
	out_be32(ack, reg);
529

530
	debug("Packet receive from 0x%p, length %dB\n", addr, length);
531
	net_process_received_packet((uchar *)etherrxbuff, length);
532
	return 0;
533
}
Michal Simek's avatar
Michal Simek committed
534

535 536
static int emaclite_miiphy_read(struct mii_dev *bus, int addr,
				int devad, int reg)
537 538
{
	u32 ret;
539
	u16 val = 0;
540

541 542 543
	ret = phyread(bus->priv, addr, reg, &val);
	debug("emaclite: Read MII 0x%x, 0x%x, 0x%x, %d\n", addr, reg, val, ret);
	return val;
544 545
}

546 547
static int emaclite_miiphy_write(struct mii_dev *bus, int addr, int devad,
				 int reg, u16 value)
548
{
549 550
	debug("emaclite: Write MII 0x%x, 0x%x, 0x%x\n", addr, reg, value);
	return phywrite(bus->priv, addr, reg, value);
551 552
}

553
static int emaclite_probe(struct udevice *dev)
Michal Simek's avatar
Michal Simek committed
554
{
555 556
	struct xemaclite *emaclite = dev_get_priv(dev);
	int ret;
Michal Simek's avatar
Michal Simek committed
557

558 559 560 561 562
	emaclite->bus = mdio_alloc();
	emaclite->bus->read = emaclite_miiphy_read;
	emaclite->bus->write = emaclite_miiphy_write;
	emaclite->bus->priv = emaclite;
	strcpy(emaclite->bus->name, "emaclite");
Michal Simek's avatar
Michal Simek committed
563

564 565 566 567 568 569
	ret = mdio_register(emaclite->bus);
	if (ret)
		return ret;

	return 0;
}
570

571 572 573 574 575 576 577
static int emaclite_remove(struct udevice *dev)
{
	struct xemaclite *emaclite = dev_get_priv(dev);

	free(emaclite->phydev);
	mdio_unregister(emaclite->bus);
	mdio_free(emaclite->bus);
578

579 580
	return 0;
}
581

582 583 584 585 586 587 588 589 590 591 592 593
static const struct eth_ops emaclite_ops = {
	.start = emaclite_init,
	.send = emaclite_send,
	.recv = emaclite_recv,
	.stop = emaclite_halt,
};

static int emaclite_ofdata_to_platdata(struct udevice *dev)
{
	struct eth_pdata *pdata = dev_get_platdata(dev);
	struct xemaclite *emaclite = dev_get_priv(dev);
	int offset = 0;
Michal Simek's avatar
Michal Simek committed
594

595 596
	pdata->iobase = (phys_addr_t)dev_get_addr(dev);
	emaclite->regs = (struct emaclite_regs *)pdata->iobase;
Michal Simek's avatar
Michal Simek committed
597

598 599
	emaclite->phyaddr = -1;

600 601 602 603 604
	offset = fdtdec_lookup_phandle(gd->fdt_blob, dev->of_offset,
				      "phy-handle");
	if (offset > 0)
		emaclite->phyaddr = fdtdec_get_int(gd->fdt_blob, offset,
						   "reg", -1);
Michal Simek's avatar
Michal Simek committed
605

606 607 608 609
	emaclite->txpp = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
					"xlnx,tx-ping-pong", 0);
	emaclite->rxpp = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
					"xlnx,rx-ping-pong", 0);
610

611 612
	printf("EMACLITE: %lx, phyaddr %d, %d/%d\n", (ulong)emaclite->regs,
	       emaclite->phyaddr, emaclite->txpp, emaclite->rxpp);
613

614
	return 0;
Michal Simek's avatar
Michal Simek committed
615
}
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632

static const struct udevice_id emaclite_ids[] = {
	{ .compatible = "xlnx,xps-ethernetlite-1.00.a" },
	{ }
};

U_BOOT_DRIVER(emaclite) = {
	.name   = "emaclite",
	.id     = UCLASS_ETH,
	.of_match = emaclite_ids,
	.ofdata_to_platdata = emaclite_ofdata_to_platdata,
	.probe  = emaclite_probe,
	.remove = emaclite_remove,
	.ops    = &emaclite_ops,
	.priv_auto_alloc_size = sizeof(struct xemaclite),
	.platdata_auto_alloc_size = sizeof(struct eth_pdata),
};