Skip to contentSkip to conversation

NET: add ENC28J60 driver using SPI framework

PATCH Superseded Reinhard Meyer 3 participants 5 messages Sep 6, 2010 – Sep 8, 2010 Network drivers

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 NET: add ENC28J60 driver using SPI framework

---
 drivers/net/Makefile   |    1 +
 drivers/net/enc28j60.c |  842 ++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/net/enc28j60.h |  250 ++++++++++++++
 include/netdev.h       |    2 +
 4 files changed, 1095 insertions(+), 0 deletions(-)
 create mode 100644 drivers/net/enc28j60.c
 create mode 100644 drivers/net/enc28j60.h
drivers/net/Makefile +1 -0
index 479954d..79eb66b 100644
@@ -39,6 +39,7 @@ COBJS-$(CONFIG_DRIVER_DM9000) += dm9000x.o
 COBJS-$(CONFIG_DNET) += dnet.o
 COBJS-$(CONFIG_E1000) += e1000.o
 COBJS-$(CONFIG_EEPRO100) += eepro100.o
+COBJS-$(CONFIG_ENC28J60) += enc28j60.o
 COBJS-$(CONFIG_ENC28J60_LPC2292) += enc28j60_lpc2292.o
 COBJS-$(CONFIG_EP93XX) += ep93xx_eth.o
 COBJS-$(CONFIG_ETHOC) += ethoc.o
drivers/net/enc28j60.c new file +842 -0

842 lines not on this page · raw message

drivers/net/enc28j60.h new file +250 -0

250 lines not on this page · raw message

include/netdev.h +2 -0
index 94eedfe..3ad16aa 100644
@@ -54,6 +54,8 @@ int designware_initialize(u32 id, ulong base_addr, u32 phy_addr);
 int dnet_eth_initialize(int id, void *regs, unsigned int phy_addr);
 int e1000_initialize(bd_t *bis);
 int eepro100_initialize(bd_t *bis);
+int enc28j60_initialize(unsigned int bus, unsigned int cs,
+	unsigned int max_hz, unsigned int mode);
 int ep93xx_eth_initialize(u8 dev_num, int base_addr);
 int ethoc_initialize(u8 dev_num, int base_addr);
 int eth_3com_initialize (bd_t * bis);
Signature · 1 line
1.5.6.5
#1 lore raw

PATCH v2 1/1 NET: add ENC28J60 driver using SPI framework

Quoted 5 lines · On Monday, September 06, 2010 10:59:16 Reinhard Meyer wrote:
drivers/net/enc28j60.c new file +5 -0
+int enc_miiphy_read(const char *devname, u8 phy_adr, u8 reg, u16 *value)
+{
+	struct eth_device *dev = eth_get_dev_by_name(devname);
+	if (dev) {
+		enc_dev_t *enc = to_enc(dev);

drivers/net/enc28j60.c line 669

Quoted 10 lines
drivers/net/enc28j60.c new file +10 -0
+
+		if (phy_adr != 0)
+			return -1;
+		spi_claim_bus(enc->slave);
+		*value = phy_read(enc, reg);
+		spi_release_bus(enc->slave);
+		return 0;
+	}
+	return -1;
+}

seems like this (and the write func) would be nicer if it were:
if (!dev)

	return -1;

...

drivers/net/enc28j60.c line 704

Quoted 7 lines
drivers/net/enc28j60.c new file +7 -0
+static int enc_init(struct eth_device *dev, bd_t *bis)
+{
+	enc_dev_t *enc = to_enc(dev);
+	u8 status;
+	uint64_t etime;
+
+	spi_claim_bus(enc->slave);

check the return value

otherwise this looks pretty good ... i'll try and test on my hardware this week
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20100906/12f3258f/attachment.pgp

#2 lore raw

PATCH v2 1/1 NET: add ENC28J60 driver using SPI framework

Dear Mike Frysinger,

Quoted 19 lines · On Monday, September 06, 2010 10:59:16 Reinhard Meyer wrote:
Quoted 5 lines
drivers/net/enc28j60.c new file +5 -0
+int enc_miiphy_read(const char *devname, u8 phy_adr, u8 reg, u16 *value)
+{
+	struct eth_device *dev = eth_get_dev_by_name(devname);
+	if (dev) {
+		enc_dev_t *enc = to_enc(dev);

drivers/net/enc28j60.c line 669

Quoted 10 lines
drivers/net/enc28j60.c new file +10 -0
+
+		if (phy_adr != 0)
+			return -1;
+		spi_claim_bus(enc->slave);
+		*value = phy_read(enc, reg);
+		spi_release_bus(enc->slave);
+		return 0;
+	}
+	return -1;
+}

seems like this (and the write func) would be nicer if it were:
if (!dev)

Quoted 2 lines
	return -1;

...

Umm, no. That would split enc_dev_t *enc = to_enc (dev) into two lines:
Declaration, if, assigment

Quoted 10 lines

drivers/net/enc28j60.c line 704

Quoted 8 lines
drivers/net/enc28j60.c new file +7 -0
+static int enc_init(struct eth_device *dev, bd_t *bis)
+{
+	enc_dev_t *enc = to_enc(dev);
+	u8 status;
+	uint64_t etime;
+
+	spi_claim_bus(enc->slave);

check the return value

OK, for sake of completeness in every function using it..
Hmm blows up the code :)
Or should it suffice to do it once in the enc_init() - assuming no one will likely claim the same bus in between and keep it?

Quoted 3 lines

otherwise this looks pretty good ... i'll try and test on my hardware this week

Good. However after today's discussion about setting the mac address I had a closer look at the eth_device structure. I decided to use the priv element instead of the ugly (IMHO) container_of method. Although it means 2x malloc(), its the cleaner way. But that need not defer you from testing.

One odd thing I noticed is that without "link up" reading the phy registers fails with timeout after a few tries. I have found no clue as to why that is. Can you observe this on your hardware, too?

Best Regards,
Reinhard

#3 lore raw

PATCH v2 1/1 NET: add ENC28J60 driver using SPI framework

Dear Reinhard Meyer,

Quoted 23 lines · In message <[email protected]> you wrote:

Dear Mike Frysinger,

Quoted 19 lines · On Monday, September 06, 2010 10:59:16 Reinhard Meyer wrote:
Quoted 5 lines
drivers/net/enc28j60.c new file +5 -0
+int enc_miiphy_read(const char *devname, u8 phy_adr, u8 reg, u16 *value)
+{
+	struct eth_device *dev = eth_get_dev_by_name(devname);
+	if (dev) {
+		enc_dev_t *enc = to_enc(dev);

drivers/net/enc28j60.c line 669

Quoted 10 lines
drivers/net/enc28j60.c new file +10 -0
+
+		if (phy_adr != 0)
+			return -1;
+		spi_claim_bus(enc->slave);
+		*value = phy_read(enc, reg);
+		spi_release_bus(enc->slave);
+		return 0;
+	}
+	return -1;
+}

seems like this (and the write func) would be nicer if it were:
if (!dev)

Quoted 2 lines
	return -1;

...

Quoted 2 lines

Umm, no. That would split enc_dev_t *enc = to_enc (dev) into two lines:
Declaration, if, assigment

Yes? What's the problem with that? But then you can unindent a whole block of code one level, which means the code is much easier toi read and to maintain.

Please do as Mike suggested.

Quoted 4 lines
Quoted 1 line

check the return value

OK, for sake of completeness in every function using it.. Hmm blows up the code :)

Yes, error handling blows up the code. But it helpos a lot to make programs reliable and robust.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
There has been an alarming increase in the number of things you  know
nothing about.
#4 lore raw

PATCH v2 1/1 NET: add ENC28J60 driver using SPI framework

Dear Wolfgang Denk,

Quoted 2 lines

Yes, error handling blows up the code. But it helpos a lot to make programs reliable and robust.

Of course I will add that.

And in theory it could help.
In reality no SPI drivers check for conflicting
claims - and therefore notoriously return ZERO.

A nice example:

int spi_claim_bus(struct spi_slave *slave)

{
	return 0;
}

I know... patches welcome ;)

Reinhard