All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mike Frysinger <vapier@gentoo.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 2/5] smc911x: use dev->name in printfs
Date: Wed, 11 Nov 2009 17:50:22 -0500	[thread overview]
Message-ID: <200911111750.23141.vapier@gentoo.org> (raw)
In-Reply-To: <4AFB3E76.9090906@gmail.com>

On Wednesday 11 November 2009 17:45:10 Ben Warren wrote:
> Mike Frysinger wrote:
> > On Wednesday 11 November 2009 17:24:27 Mike Rapoport wrote:
> >> On Thu, Nov 12, 2009 at 12:11 AM, Mike Frysinger wrote:
> >>> On Wednesday 11 November 2009 16:56:57 Mike Rapoport wrote:
> >>>> It seems that eeprom code is broken since commit
> >>>> 736fead8fdbf8a8407048bebc373cd551d01ec98: "Convert SMC911X Ethernet
> >>>> driver to CONFIG_NET_MULTI API".
> >>>
> >>> broken how ?  i recall it working ...
> >>
> >> It gives pretty long list of compile errors. The smc911x.h header has
> >> now 'struct eth_device *dev' parameter in all the functions.
> >
> > yeah, i see that now.  it wasnt noticed earlier as the config name
> > changed but the eeprom code wasnt updated.  i can take a look if you like
> > since i wrote this sucker in the first place.
> 
> You fixed the SMC91111 eeprom code by defining a 'struct eth_dev', but I
> guess not the SMC9111x.  I'm responsible for making this mess, so if you
> don't have time I can take care of it (without being able to test, of
> course :)
> 
> We can probably still fit such a bug fix in this release if we act quickly.

here's my [compile] tested change as the board i have with this part isnt
readily accessible atm ...
-mike

diff --git a/examples/standalone/smc911x_eeprom.c 
b/examples/standalone/smc911x_eeprom.c
index bf22f0a..f2a6304 100644
--- a/examples/standalone/smc911x_eeprom.c
+++ b/examples/standalone/smc911x_eeprom.c
@@ -17,8 +17,8 @@
 #include <common.h>
 #include <exports.h>
 
-#ifdef CONFIG_DRIVER_SMC911X
-
+/* the smc911x.h gets base addr through eth_device' iobase */
+struct eth_device { const char *name; unsigned long iobase; };
 #include "../drivers/net/smc911x.h"
 
 /**
@@ -55,32 +55,32 @@ static void usage(void)
  * Registers 0x00 - 0x50 are FIFOs.  The 0x50+ are the control registers
  * and they're all 32bits long.  0xB8+ are reserved, so don't bother.
  */
-static void dump_regs(void)
+static void dump_regs(struct eth_device *dev)
 {
 	u8 i, j = 0;
 	for (i = 0x50; i < 0xB8; i += sizeof(u32))
 		printf("%02x: 0x%08x %c", i,
-			smc911x_reg_read(CONFIG_DRIVER_SMC911X_BASE + i),
+			smc911x_reg_read(dev, i),
 			(j++ % 2 ? '\n' : ' '));
 }
 
 /**
  *	do_eeprom_cmd - handle eeprom communication
  */
-static int do_eeprom_cmd(int cmd, u8 reg)
+static int do_eeprom_cmd(struct eth_device *dev, int cmd, u8 reg)
 {
-	if (smc911x_reg_read(E2P_CMD) & E2P_CMD_EPC_BUSY) {
+	if (smc911x_reg_read(dev, E2P_CMD) & E2P_CMD_EPC_BUSY) {
 		printf("eeprom_cmd: busy@start (E2P_CMD = 0x%08x)\n",
-			smc911x_reg_read(E2P_CMD));
+			smc911x_reg_read(dev, E2P_CMD));
 		return -1;
 	}
 
-	smc911x_reg_write(E2P_CMD, E2P_CMD_EPC_BUSY | cmd | reg);
+	smc911x_reg_write(dev, E2P_CMD, E2P_CMD_EPC_BUSY | cmd | reg);
 
-	while (smc911x_reg_read(E2P_CMD) & E2P_CMD_EPC_BUSY)
+	while (smc911x_reg_read(dev, E2P_CMD) & E2P_CMD_EPC_BUSY)
 		if (smsc_ctrlc()) {
 			printf("eeprom_cmd: timeout (E2P_CMD = 0x%08x)\n",
-				smc911x_reg_read(E2P_CMD));
+				smc911x_reg_read(dev, E2P_CMD));
 			return -1;
 		}
 
@@ -90,37 +90,37 @@ static int do_eeprom_cmd(int cmd, u8 reg)
 /**
  *	read_eeprom_reg - read specified register in EEPROM
  */
-static u8 read_eeprom_reg(u8 reg)
+static u8 read_eeprom_reg(struct eth_device *dev, u8 reg)
 {
-	int ret = do_eeprom_cmd(E2P_CMD_EPC_CMD_READ, reg);
-	return (ret ? : smc911x_reg_read(E2P_DATA));
+	int ret = do_eeprom_cmd(dev, E2P_CMD_EPC_CMD_READ, reg);
+	return (ret ? : smc911x_reg_read(dev, E2P_DATA));
 }
 
 /**
  *	write_eeprom_reg - write specified value into specified register in EEPROM
  */
-static int write_eeprom_reg(u8 value, u8 reg)
+static int write_eeprom_reg(struct eth_device *dev, u8 value, u8 reg)
 {
 	int ret;
 
 	/* enable erasing/writing */
-	ret = do_eeprom_cmd(E2P_CMD_EPC_CMD_EWEN, reg);
+	ret = do_eeprom_cmd(dev, E2P_CMD_EPC_CMD_EWEN, reg);
 	if (ret)
 		goto done;
 
 	/* erase the eeprom reg */
-	ret = do_eeprom_cmd(E2P_CMD_EPC_CMD_ERASE, reg);
+	ret = do_eeprom_cmd(dev, E2P_CMD_EPC_CMD_ERASE, reg);
 	if (ret)
 		goto done;
 
 	/* write the eeprom reg */
-	smc911x_reg_write(E2P_DATA, value);
-	ret = do_eeprom_cmd(E2P_CMD_EPC_CMD_WRITE, reg);
+	smc911x_reg_write(dev, E2P_DATA, value);
+	ret = do_eeprom_cmd(dev, E2P_CMD_EPC_CMD_WRITE, reg);
 	if (ret)
 		goto done;
 
 	/* disable erasing/writing */
-	ret = do_eeprom_cmd(E2P_CMD_EPC_CMD_EWDS, reg);
+	ret = do_eeprom_cmd(dev, E2P_CMD_EPC_CMD_EWDS, reg);
 
  done:
 	return ret;
@@ -139,7 +139,7 @@ static char *skip_space(char *buf)
 /**
  *	write_stuff - handle writing of MAC registers / eeprom
  */
-static void write_stuff(char *line)
+static void write_stuff(struct eth_device *dev, char *line)
 {
 	char dest;
 	char *endp;
@@ -182,39 +182,39 @@ static void write_stuff(char *line)
 	/* Finally, execute the command */
 	if (dest == 'E') {
 		printf("Writing EEPROM register %02x with %02x\n", reg, value);
-		write_eeprom_reg(value, reg);
+		write_eeprom_reg(dev, value, reg);
 	} else {
 		printf("Writing MAC register %02x with %08x\n", reg, value);
-		smc911x_reg_write(CONFIG_DRIVER_SMC911X_BASE + reg, value);
+		smc911x_reg_write(dev, reg, value);
 	}
 }
 
 /**
  *	copy_from_eeprom - copy MAC address in eeprom to address registers
  */
-static void copy_from_eeprom(void)
+static void copy_from_eeprom(struct eth_device *dev)
 {
 	ulong addrl =
-		read_eeprom_reg(0x01) |
-		read_eeprom_reg(0x02) << 8 |
-		read_eeprom_reg(0x03) << 16 |
-		read_eeprom_reg(0x04) << 24;
+		read_eeprom_reg(dev, 0x01) |
+		read_eeprom_reg(dev, 0x02) << 8 |
+		read_eeprom_reg(dev, 0x03) << 16 |
+		read_eeprom_reg(dev, 0x04) << 24;
 	ulong addrh =
-		read_eeprom_reg(0x05) |
-		read_eeprom_reg(0x06) << 8;
-	smc911x_set_mac_csr(ADDRL, addrl);
-	smc911x_set_mac_csr(ADDRH, addrh);
+		read_eeprom_reg(dev, 0x05) |
+		read_eeprom_reg(dev, 0x06) << 8;
+	smc911x_set_mac_csr(dev, ADDRL, addrl);
+	smc911x_set_mac_csr(dev, ADDRH, addrh);
 	puts("EEPROM contents copied to MAC\n");
 }
 
 /**
  *	print_macaddr - print MAC address registers and MAC address in eeprom
  */
-static void print_macaddr(void)
+static void print_macaddr(struct eth_device *dev)
 {
 	puts("Current MAC Address in MAC:     ");
-	ulong addrl = smc911x_get_mac_csr(ADDRL);
-	ulong addrh = smc911x_get_mac_csr(ADDRH);
+	ulong addrl = smc911x_get_mac_csr(dev, ADDRL);
+	ulong addrh = smc911x_get_mac_csr(dev, ADDRH);
 	printf("%02x:%02x:%02x:%02x:%02x:%02x\n",
 		(u8)(addrl), (u8)(addrl >> 8), (u8)(addrl >> 16),
 		(u8)(addrl >> 24), (u8)(addrh), (u8)(addrh >> 8));
@@ -222,41 +222,42 @@ static void print_macaddr(void)
 	puts("Current MAC Address in EEPROM:  ");
 	int i;
 	for (i = 1; i < 6; ++i)
-		printf("%02x:", read_eeprom_reg(i));
-	printf("%02x\n", read_eeprom_reg(i));
+		printf("%02x:", read_eeprom_reg(dev, i));
+	printf("%02x\n", read_eeprom_reg(dev, i));
 }
 
 /**
  *	dump_eeprom - dump the whole content of the EEPROM
  */
-static void dump_eeprom(void)
+static void dump_eeprom(struct eth_device *dev)
 {
 	int i;
 	puts("EEPROM:\n");
 	for (i = 0; i < 7; ++i)
-		printf("%02x: 0x%02x\n", i, read_eeprom_reg(i));
+		printf("%02x: 0x%02x\n", i, read_eeprom_reg(dev, i));
 }
 
 /**
  *	smc911x_init - get the MAC/EEPROM up and ready for use
  */
-static int smc911x_init(void)
+static int smc911x_init(struct eth_device *dev)
 {
 	/* See if there is anything there */
-	if (!smc911x_detect_chip())
+	if (!smc911x_detect_chip(dev))
 		return 1;
 
-	smc911x_reset();
+	smc911x_reset(dev);
 
 	/* Make sure we set EEDIO/EECLK to the EEPROM */
-	if (smc911x_reg_read(GPIO_CFG) & GPIO_CFG_EEPR_EN) {
-		while (smc911x_reg_read(E2P_CMD) & E2P_CMD_EPC_BUSY)
+	if (smc911x_reg_read(dev, GPIO_CFG) & GPIO_CFG_EEPR_EN) {
+		while (smc911x_reg_read(dev, E2P_CMD) & E2P_CMD_EPC_BUSY)
 			if (smsc_ctrlc()) {
 				printf("init: timeout (E2P_CMD = 0x%08x)\n",
-					smc911x_reg_read(E2P_CMD));
+					smc911x_reg_read(dev, E2P_CMD));
 				return 1;
 			}
-		smc911x_reg_write(GPIO_CFG, smc911x_reg_read(GPIO_CFG) & 
~GPIO_CFG_EEPR_EN);
+		smc911x_reg_write(dev, GPIO_CFG,
+			smc911x_reg_read(dev, GPIO_CFG) & ~GPIO_CFG_EEPR_EN);
 	}
 
 	return 0;
@@ -317,6 +318,11 @@ static char *getline(void)
  */
 int smc911x_eeprom(int argc, char *argv[])
 {
+	struct eth_device dev = {
+		.name   = __func__,
+		.iobase = CONFIG_SMC911X_BASE,
+	};
+
 	/* Print the ABI version */
 	app_startup(argv);
 	if (XF_VERSION != get_version()) {
@@ -328,7 +334,7 @@ int smc911x_eeprom(int argc, char *argv[])
 
 	/* Initialize the MAC/EEPROM somewhat */
 	puts("\n");
-	if (smc911x_init())
+	if (smc911x_init(&dev))
 		return 1;
 
 	/* Dump helpful usage information */
@@ -360,11 +366,11 @@ int smc911x_eeprom(int argc, char *argv[])
 
 		/* Now parse the command */
 		switch (line[0]) {
-		case 'W': write_stuff(line);  break;
-		case 'D': dump_eeprom();      break;
-		case 'M': dump_regs();        break;
-		case 'C': copy_from_eeprom(); break;
-		case 'P': print_macaddr();    break;
+		case 'W': write_stuff(&dev, line); break;
+		case 'D': dump_eeprom(&dev);       break;
+		case 'M': dump_regs(&dev);         break;
+		case 'C': copy_from_eeprom(&dev);  break;
+		case 'P': print_macaddr(&dev);     break;
 		unknown_cmd:
 		default:  puts("ERROR: Unknown command!\n\n");
 		case '?':
@@ -373,11 +379,3 @@ int smc911x_eeprom(int argc, char *argv[])
 		}
 	}
 }
-
-#else
-int smc911x_eeprom(int argc, char *argv[])
-{
-	puts("Not supported for this board\n");
-	return 1;
-}
-#endif

  reply	other threads:[~2009-11-11 22:50 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-11  8:02 [U-Boot] [PATCH 0/5] smc911x driver fixes and additions Mike Rapoport
2009-11-11  8:03 ` [U-Boot] [PATCH 1/5] smc911x: return -1 when initialization fails Mike Rapoport
2009-11-11 15:16   ` Mike Frysinger
2009-11-12 13:35     ` [U-Boot] [PATCH] smc911x: make smc911x_initialize return correct value (Was: Re: [PATCH 1/5] smc911x: return -1 when initialization fails) Mike Rapoport
2009-11-13  3:44       ` Mike Frysinger
2009-11-11  8:03 ` [U-Boot] [PATCH 2/5] smc911x: use dev->name in printfs Mike Rapoport
2009-11-11 15:18   ` Mike Frysinger
2009-11-11 21:56     ` Mike Rapoport
2009-11-11 22:11       ` Mike Frysinger
2009-11-11 22:24         ` Mike Rapoport
2009-11-11 22:36           ` Mike Frysinger
2009-11-11 22:45             ` Ben Warren
2009-11-11 22:50               ` Mike Frysinger [this message]
2009-11-12  1:58                 ` Ben Warren
2009-11-13  3:23                   ` [U-Boot] [PATCH] smc911x_eeprom: fix building after smc911x overhaul Mike Frysinger
2009-11-13  3:26                     ` [U-Boot] [PATCH v2] " Mike Frysinger
2009-11-12  9:13                 ` [U-Boot] [PATCH 2/5] smc911x: use dev->name in printfs Mike Rapoport
2009-11-13  3:21                   ` Mike Frysinger
2009-11-11  8:03 ` [U-Boot] [PATCH 3/5] smc911x: silence MAC mismatch warning Mike Rapoport
2009-11-11 15:22   ` Mike Frysinger
2009-11-11 16:07     ` Mike Rapoport
2009-11-11  8:03 ` [U-Boot] [PATCH 4/5] smc911x: update SMC911X related configuration description Mike Rapoport
2009-12-07 21:06   ` Wolfgang Denk
2009-12-07 21:10     ` Ben Warren
2009-11-11  8:03 ` [U-Boot] [PATCH 5/5] smc911x: allow mac address to be kept after smc911x_halt Mike Rapoport
2009-11-11 15:23   ` Mike Frysinger
2009-11-11 16:05     ` Mike Rapoport
2009-11-11 16:32       ` Mike Frysinger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200911111750.23141.vapier@gentoo.org \
    --to=vapier@gentoo.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.