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]     [Linux Samsung SOC]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux