Re: [RFC PATCH 6/7] i2c: of: mark a whole array of regs as reserved

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> > +int of_i2c_get_board_info(struct device_node *node, struct i2c_board_info *info)
> > +{
> > +       u32 addr;
> > +       int ret;
> > +
> > +       ret = of_property_read_u32(node, "reg", &addr);
> 
> Perhaps the time is ripe to start considering #address-cells, instead
> of assuming 1, here ...

I think here it is okay because we really want the first entry of the
first tuple.

> > +       of_property_for_each_u32(node, "reg", prop, cur, reg) {
> 
> ... and especially here, if this code can ever be reused for i3c, which uses 3.

But here I agree. I reimplemented the code to handle it, and it worked
with '#address-cells = <2>;' as expected. Here is the diff to this
patch:

@@ -16,6 +16,7 @@
 #include <linux/i2c.h>
 #include <linux/module.h>
 #include <linux/of.h>
+#include <linux/of_address.h>
 #include <linux/of_device.h>
 #include <linux/sysfs.h>
 
@@ -75,13 +76,14 @@ static struct i2c_client *of_i2c_register_device(struct i2c_adapter *adap,
 	struct i2c_client *client, *first_client = ERR_PTR(-ENOENT);
 	struct i2c_board_info info;
 	bool first_reg = true;
-	struct property *prop;
-	const __be32 *cur;
-	u32 reg;
+	unsigned int i = 0;
+	const __be32 *prop;
+	u16 reg;
 
 	pr_debug("register %pOF\n", node);
 
-	of_property_for_each_u32(node, "reg", prop, cur, reg) {
+	while ((prop = of_get_address(node, i++, NULL, NULL))) {
+		reg = of_read_number(prop, 1);
 		of_i2c_decode_board_info(node, reg, first_reg, &info);
 
 		client = i2c_new_client_device(adap, &info);

Thanks, Geert! I will send out the new version in a few minutes.

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]


  Powered by Linux