linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: David Miller <davem@davemloft.net>
To: linuxppc-dev@ozlabs.org
Cc: scottwood@freescale.com, paulus@samba.org, sparclinux@vger.kernel.org
Subject: [PATCH 3/3]: of_i2c: Add Sparc support.
Date: Thu, 21 Aug 2008 21:21:45 -0700 (PDT)	[thread overview]
Message-ID: <20080821.212145.141028767.davem@davemloft.net> (raw)


of_i2c: Add Sparc support.

Signed-off-by: David S. Miller <davem@davemloft.net>
---
 arch/sparc/include/asm/of_i2c.h |   67 +++++++++++++++++++++++++++++++++++++++
 drivers/of/Kconfig              |    2 +-
 2 files changed, 68 insertions(+), 1 deletions(-)
 create mode 100644 arch/sparc/include/asm/of_i2c.h

diff --git a/arch/sparc/include/asm/of_i2c.h b/arch/sparc/include/asm/of_i2c.h
new file mode 100644
index 0000000..93c7c05
--- /dev/null
+++ b/arch/sparc/include/asm/of_i2c.h
@@ -0,0 +1,67 @@
+#ifndef _ASM_SPARC_OF_I2C_H
+#define _ASM_SPARC_OF_I2C_H
+
+/* In my copy of the I2C bindings for IEEE1275 the register value is
+ * encoded as a 2-cell value:
+ *
+ * Bit #    33222222 22221111 11111100 00000000
+ *          10987654 32109876 54321098 76543210
+ *
+ * bus:     00000000 00000000 00000000 bbbbbbbb
+ * address: 00000000 00000000 00000sss sssssss0
+ *
+ * where:
+ * bbbbbbbb        8-bit unsigned number representing
+ *                 the I2C bus address within this I2C bus
+ *                 controller node
+ * ssssssssss      10-bit unsigned number representing the
+ *                 slave address
+ *
+ * When doing I2C transfers to a device the low bit of the address
+ * indicates whether the transfer is a read or a write, and the upper
+ * bits indicate the device address.
+ *
+ * The Linux I2C layer wants device addresses which elide this
+ * direction bit.  Thus we should shift the OF provided reg property
+ * address down by one bit.
+ */
+static inline int of_i2c_fetch_addr(struct i2c_board_info *bp,
+				    struct device_node *client_node,
+				    struct device_node *adap_node,
+				    int num_addr_cells)
+{
+	const u32 *addr;
+	int len;
+
+	addr = of_get_property(client_node, "reg", &len);
+	if (!addr)
+		goto out_inval;
+
+	if (len < (num_addr_cells * sizeof(int)))
+		goto out_inval;
+
+	if (addr[num_addr_cells - 1] > (1 << 10) - 1)
+		goto out_inval;
+
+	switch (num_addr_cells) {
+	case 1:
+		bp->addr = addr[0];
+		break;
+
+	case 2:
+		/* XXX cell 0 contains bus number XXX */
+		bp->addr = addr[1];
+		break;
+
+	default:
+		goto out_inval;
+	}
+
+	return 0;
+
+out_inval:
+	printk(KERN_ERR "of-i2c: invalid i2c device entry\n");
+	return -EINVAL;
+}
+
+#endif /* _ASM_SPARC_OF_I2C_H */
diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
index f821dbc..493c717 100644
--- a/drivers/of/Kconfig
+++ b/drivers/of/Kconfig
@@ -10,7 +10,7 @@ config OF_GPIO
 
 config OF_I2C
 	def_tristate I2C
-	depends on PPC_OF && I2C
+	depends on I2C
 	help
 	  OpenFirmware I2C accessors
 
-- 
1.5.6.5.GIT

             reply	other threads:[~2008-08-22  4:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-22  4:21 David Miller [this message]
2008-08-22 10:10 ` [PATCH 3/3]: of_i2c: Add Sparc support David Miller

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=20080821.212145.141028767.davem@davemloft.net \
    --to=davem@davemloft.net \
    --cc=linuxppc-dev@ozlabs.org \
    --cc=paulus@samba.org \
    --cc=scottwood@freescale.com \
    --cc=sparclinux@vger.kernel.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).