Skip to contentSkip to conversation

Make i2c-mpc driver use i2c_add_numbered_adapter

PATCH In review Grant Likely 4 participants 9 messages May 14, 2007 – May 16, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Make i2c-mpc driver use i2c_add_numbered_adapter

Move the i2c-mpc driver over to using the new i2c infrastructure. Specifically, it now uses i2c_add_numberd_adapter so that the bus number can be determined ahead of time and used to register i2c clients before the bus is instantiated.

Tested on an MPC5200 based board

---
This patch will need to be tested to make sure it does not break any 8xxx board ports.

Work still to be done (in another patch): support for pulling i2c client registrations out of the device tree.

 drivers/i2c/busses/i2c-mpc.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
drivers/i2c/busses/i2c-mpc.c +2 -1
index c6b6898..a769efc 100644
@@ -327,9 +327,10 @@ static int fsl_i2c_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, i2c);
 
 	i2c->adap = mpc_ops;
+	i2c->adap.nr = pdev->id;
 	i2c_set_adapdata(&i2c->adap, i2c);
 	i2c->adap.dev.parent = &pdev->dev;
-	if ((result = i2c_add_adapter(&i2c->adap)) < 0) {
+	if ((result = i2c_add_numbered_adapter(&i2c->adap)) < 0) {
 		printk(KERN_ERR "i2c-mpc - failed to add adapter\n");
 		goto fail_add;
 	}
#1 lore raw
Quoted 2 lines · Grant Likely

Work still to be done (in another patch): support for pulling i2c client registrations out of the device tree.

I had also fogotten about Scott Woods patches from last Nov. which take care of this.

g.

Signature · 4 lines
Grant Likely, B.Sc. P.Eng.
Secret Lab Technologies Ltd.
[email protected]
(403) 399-0195
Acked-by on v1 1/1
#2 lore raw
In reply to Grant Likely
Quoted 2 lines · Grant Likely

Move the i2c-mpc driver over to using the new i2c infrastructure. Specifically, it now uses i2c_add_numberd_adapter so that the bus number

i2c_add_numbered_adapter (missing e)

Quoted 6 lines

can be determined ahead of time and used to register i2c clients before the bus is instantiated.

Tested on an MPC5200 based board

Quoted 26 lines

---
This patch will need to be tested to make sure it does not break any 8xxx board ports.

Work still to be done (in another patch): support for pulling i2c client registrations out of the device tree.

 drivers/i2c/busses/i2c-mpc.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
drivers/i2c/busses/i2c-mpc.c +2 -1
index c6b6898..a769efc 100644
@@ -327,9 +327,10 @@ static int fsl_i2c_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, i2c);
 
 	i2c->adap = mpc_ops;
+	i2c->adap.nr = pdev->id;
 	i2c_set_adapdata(&i2c->adap, i2c);
 	i2c->adap.dev.parent = &pdev->dev;
-	if ((result = i2c_add_adapter(&i2c->adap)) < 0) {
+	if ((result = i2c_add_numbered_adapter(&i2c->adap)) < 0) {
 		printk(KERN_ERR "i2c-mpc - failed to add adapter\n");
 		goto fail_add;
 	}
Signature · 1 line
Jean Delvare
#3 lore raw
Quoted 9 lines · Jean Delvare

drivers/i2c/busses/i2c-mpc.c static int fsl_i2c_probe(struct platform_device *pdev) · line 330

Quoted 7 lines · Grant Likely
drivers/i2c/busses/i2c-mpc.c +1 -0
@@ -327,9 +327,10 @@ static int fsl_i2c_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, i2c);
 
 	i2c->adap = mpc_ops;
+	i2c->adap.nr = pdev->id;

By the way: mpc_ops is a static i2c_adapter, so given that the reason for using pdev->id that way was that there might be more than one such platform device ... shouldn't allocation of the adapter be moved into allocation of the "i2c->" object?

Or at least, add a check to ensure that the static mpc_ops structure isn't in use before progressing this probe().

- Dave

Quoted 11 lines
Quoted 7 lines
drivers/i2c/busses/i2c-mpc.c +1 -1
 	i2c_set_adapdata(&i2c->adap, i2c);
 	i2c->adap.dev.parent = &pdev->dev;
-	if ((result = i2c_add_adapter(&i2c->adap)) < 0) {
+	if ((result = i2c_add_numbered_adapter(&i2c->adap)) < 0) {
 		printk(KERN_ERR "i2c-mpc - failed to add adapter\n");
 		goto fail_add;
 	}
Signature · 1 line
Jean Delvare
#4 lore raw
Quoted 8 lines · David Brownell
Quoted 7 lines · Jean Delvare
Quoted 5 lines · Grant Likely
drivers/i2c/busses/i2c-mpc.c +0 -0
@@ -327,9 +327,10 @@ static int fsl_i2c_probe(struct platform_device *pdev)
    platform_set_drvdata(pdev, i2c);
 
Quoted 7 lines
Quoted 2 lines

drivers/i2c/busses/i2c-mpc.c static int fsl_i2c_probe(struct platform_device *pdev) · line 330

Quoted 2 lines
drivers/i2c/busses/i2c-mpc.c +1 -0
    i2c->adap = mpc_ops;
+   i2c->adap.nr = pdev->id;

By the way: mpc_ops is a static i2c_adapter, so given that the reason for using pdev->id that way was that there might be more than one such platform device ... shouldn't allocation of the adapter be moved into allocation of the "i2c->" object?

Take another look; this is a funny quirk of the driver. The assignment is 'i2c->adap = mpc_ops'; not 'i2c->adap = &mpc_ops'. And in struct mpc_i2c, the field is declared as 'struct i2c_adapter adap', not 'struct i2c_adapter *adap'. The driver instance gets a copy of the mpc_ops structure to initialize it, not a pointer to the staticly defined structure. I got bitten by the same thing when I was looking at the code.

Not to mention that mpc_ops is poorly named.

Cheers,
g.

Signature · 4 lines
Grant Likely, B.Sc. P.Eng.
Secret Lab Technologies Ltd.
[email protected]
(403) 399-0195
#5 lore raw
Quoted 8 lines · Grant Likely

Take another look; this is a funny quirk of the driver. The assignment is 'i2c->adap = mpc_ops'; not 'i2c->adap = &mpc_ops'. And in struct mpc_i2c, the field is declared as 'struct i2c_adapter adap', not 'struct i2c_adapter *adap'. The driver instance gets a copy of the mpc_ops structure to initialize it, not a pointer to the staticly defined structure. I got bitten by the same thing when I was looking at the code.

I see -- you're right. That "template" idiom is a good one to get rid of, FWIW ... not only is it confusing, but it also wastes space.

- Dave

#6 lore raw
Quoted 10 lines · David Brownell
Quoted 8 lines · Grant Likely

Take another look; this is a funny quirk of the driver. The assignment is 'i2c->adap = mpc_ops'; not 'i2c->adap = &mpc_ops'. And in struct mpc_i2c, the field is declared as 'struct i2c_adapter adap', not 'struct i2c_adapter *adap'. The driver instance gets a copy of the mpc_ops structure to initialize it, not a pointer to the staticly defined structure. I got bitten by the same thing when I was looking at the code.

Quoted 2 lines

I see -- you're right. That "template" idiom is a good one to get rid of, FWIW ... not only is it confusing, but it also wastes space.

Well, maybe you can submit a patch fixing this one?

Signature · 1 line
Jean Delvare
#7 lore raw
Quoted 11 lines · Jean Delvare
Quoted 10 lines · David Brownell
Quoted 8 lines · Grant Likely

Take another look; this is a funny quirk of the driver. The assignment is 'i2c->adap = mpc_ops'; not 'i2c->adap = &mpc_ops'. And in struct mpc_i2c, the field is declared as 'struct i2c_adapter adap', not 'struct i2c_adapter *adap'. The driver instance gets a copy of the mpc_ops structure to initialize it, not a pointer to the staticly defined structure. I got bitten by the same thing when I was looking at the code.

Quoted 4 lines
Quoted 2 lines

I see -- you're right. That "template" idiom is a good one to get rid of, FWIW ... not only is it confusing, but it also wastes space.

Well, maybe you can submit a patch fixing this one?

Heh, oops.

I had replied to David saying that I would do this bit; but I forgot to cc the list.

I'll take care of this.

Cheers,
g.

Signature · 4 lines
Grant Likely, B.Sc. P.Eng.
Secret Lab Technologies Ltd.
[email protected]
(403) 399-0195
#8 lore raw
In reply to David Brownell
Quoted 19 lines · David Brownell
Quoted 10 lines · Jean Delvare

drivers/i2c/busses/i2c-mpc.c static int fsl_i2c_probe(struct platform_device *pdev) · line 330

Quoted 7 lines · Grant Likely
drivers/i2c/busses/i2c-mpc.c +1 -0
@@ -327,9 +327,10 @@ static int fsl_i2c_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, i2c);
 
 	i2c->adap = mpc_ops;
+	i2c->adap.nr = pdev->id;

By the way: mpc_ops is a static i2c_adapter, so given that the reason for using pdev->id that way was that there might be more than one such platform device ... shouldn't allocation of the adapter be moved into allocation of the "i2c->" object?

Quoted 2 lines

Or at least, add a check to ensure that the static mpc_ops structure isn't in use before progressing this probe().

The mpc_ops struct is only used as a template; it gets copied into i2c->adap for each adapter instance.

-Scott