Re: [PATCH 3/3]: of_i2c: Add Sparc support.

2008-08-22 Thread David Miller
From: David Miller [EMAIL PROTECTED]
Date: Thu, 21 Aug 2008 21:21:45 -0700 (PDT)

 of_i2c: Add Sparc support.
 
 Signed-off-by: David S. Miller [EMAIL PROTECTED]

Of course, after testing, I noticed that I forgot the all
important shifts here. :-)

Here is a fixed patch:

of_i2c: Add Sparc support.

Signed-off-by: David S. Miller [EMAIL PROTECTED]

diff --git a/arch/sparc/include/asm/of_i2c.h b/arch/sparc/include/asm/of_i2c.h
new file mode 100644
index 000..0fdab1e
--- /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 #3322  1100 
+ *  10987654 32109876 54321098 76543210
+ *
+ * bus:    
+ * address:   0sss sss0
+ *
+ * where:
+ * 8-bit unsigned number representing
+ * the I2C bus address within this I2C bus
+ * controller node
+ * ss  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]  1;
+   break;
+
+   case 2:
+   /* XXX cell 0 contains bus number XXX */
+   bp-addr = addr[1]  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

___
Linuxppc-dev mailing list
Linuxppc-dev@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-dev


[PATCH 3/3]: of_i2c: Add Sparc support.

2008-08-21 Thread David Miller

of_i2c: Add Sparc support.

Signed-off-by: David S. Miller [EMAIL PROTECTED]
---
 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 000..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 #3322  1100 
+ *  10987654 32109876 54321098 76543210
+ *
+ * bus:    
+ * address:   0sss sss0
+ *
+ * where:
+ * 8-bit unsigned number representing
+ * the I2C bus address within this I2C bus
+ * controller node
+ * ss  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

___
Linuxppc-dev mailing list
Linuxppc-dev@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-dev