linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Johannes Berg <johannes@sipsolutions.net>
To: linuxppc-dev@ozlabs.org
Subject: [PATCH] PowerMac11,2 i2c-bus@0 duplicate dev-tree workaround
Date: Wed, 29 Mar 2006 13:30:15 +0200	[thread overview]
Message-ID: <1143631816.9481.5.camel@localhost> (raw)

On a PowerMac11,2, there are two i2c-bus@0 nodes of which only the first
is correct. This patch makes the device tree unflattening code ignore
the second one on those machines.

Signed-Off-By: Johannes Berg <johannes@sipsolutions.net>

--- 
I'm not sure this is the right way to do it. Maybe we should have some
'dev-tree quirks fixer' that makes a third pass through the device tree
after the allnodes chain has been set up, and fixes it up. On the other
hand, as long as there aren't too many workarounds, this works fine.

The patch looks longer than it is because some code changed indentation
level.

--- a/arch/powerpc/kernel/prom.c
+++ b/arch/powerpc/kernel/prom.c
@@ -624,6 +624,11 @@ static void *__init unflatten_dt_alloc(u
 	return res;
 }
 
+/* PowerMac11,2 has a bug in the device tree where
+ * an i2c-bus@0 shows up twice. We ignore the second
+ * one since it is the bogus one */
+static __initdata int powermac_i2c_bus_0_workaround = 0;
+
 static unsigned long __init unflatten_dt_node(unsigned long mem,
 					      unsigned long *p,
 					      struct device_node *dad,
@@ -695,17 +700,31 @@ static unsigned long __init unflatten_dt
 			memcpy(p, pathp, l);
 		} else
 			memcpy(np->full_name, pathp, l);
+		DBG("node %s found\n", np->full_name);
 		prev_pp = &np->properties;
-		**allnextpp = np;
-		*allnextpp = &np->allnext;
-		if (dad != NULL) {
-			np->parent = dad;
-			/* we temporarily use the next field as `last_child'*/
-			if (dad->next == 0)
-				dad->child = np;
-			else
-				dad->next->sibling = np;
-			dad->next = np;
+		/* so if the workaround is in effect, and we have the right
+		 * node found, we increase the workaround count (we use the
+		 * same variable) and then set allnextpp to NULL on the second
+		 * one around so the node isn't added to the allnodes list */
+		if (powermac_i2c_bus_0_workaround &&
+		    strcmp(np->full_name,
+		           "/ht@0,f2000000/pci@8/mac-io@7/i2c@18000/i2c-bus@0") == 0) {
+			powermac_i2c_bus_0_workaround++;
+			if (powermac_i2c_bus_0_workaround == 3)
+				allnextpp = NULL;
+		}
+		if (allnextpp) {
+			**allnextpp = np;
+			*allnextpp = &np->allnext;
+			if (dad != NULL) {
+				np->parent = dad;
+				/* we temporarily use the next field as `last_child'*/
+				if (dad->next == 0)
+					dad->child = np;
+				else
+					dad->next->sibling = np;
+				dad->next = np;
+			}
 		}
 		kref_init(&np->kref);
 	}
@@ -745,6 +764,14 @@ static unsigned long __init unflatten_dt
 			}
 			if (strcmp(pname, "ibm,phandle") == 0)
 				np->linux_phandle = *((u32 *)*p);
+			/* we check the root node's compatible property
+			 * to see if we need to start the powermac i2c
+			 * workaround */
+			if ((pathp[0] == '\0') &&
+			    (strcmp(pname, "compatible") == 0) &&
+			    (strncmp((char*)*p, "PowerMac11,2", sz) == 0)) {
+				powermac_i2c_bus_0_workaround = 1;
+			}
 			pp->name = pname;
 			pp->length = sz;
 			pp->value = (void *)*p;

             reply	other threads:[~2006-03-29 12:36 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-29 11:30 Johannes Berg [this message]
2006-03-30  4:26 ` [PATCH] PowerMac11,2 i2c-bus@0 duplicate dev-tree workaround Benjamin Herrenschmidt
2006-03-30 13:04   ` Johannes Berg
2006-03-30  6:28 ` Michael Ellerman
2006-03-30 22:38   ` Johannes Berg
2006-03-31  5:37     ` Michael Ellerman
2006-03-31  9:42       ` Johannes Berg

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=1143631816.9481.5.camel@localhost \
    --to=johannes@sipsolutions.net \
    --cc=linuxppc-dev@ozlabs.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).