Skip to contentSkip to conversation

Convert i2c-mpc from a platform driver to an of_platform one

PATCH In review Jon Smirl 7 participants 14 messages Jun 11, 2008 – Jun 30, 2008 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

Jon Smirl

author
#0 lore raw

PATCH 1/1 Convert i2c-mpc from a platform driver to an of_platform one

Convert i2c-mpc from a platform driver into an of_platform driver. This patch is much smaller since Jochen already added of_find_i2c_driver(). Versions of this have been posted before.

Signature · 2 lines
 drivers/i2c/busses/i2c-mpc.c |  105 +++++++++++++++++++++++++-----------------
 1 files changed, 63 insertions(+), 42 deletions(-)
drivers/i2c/busses/i2c-mpc.c +5 -3
index a076129..76d8091 100644
@@ -18,6 +18,8 @@
 #include <linux/sched.h>
 #include <linux/init.h>
 #include <linux/platform_device.h>
+#include <linux/of_platform.h>
+#include <linux/of_i2c.h>
 
 #include <asm/io.h>
 #include <linux/fsl_devices.h>
@@ -25,13 +27,13 @@
 #include <linux/interrupt.h>
 #include <linux/delay.h>
 
-#define MPC_I2C_ADDR  0x00
+#define DRV_NAME "mpc-i2c"
+
 #define MPC_I2C_FDR 	0x04
 #define MPC_I2C_CR	0x08
 #define MPC_I2C_SR	0x0c
 #define MPC_I2C_DR	0x10
 #define MPC_I2C_DFSRR 0x14
-#define MPC_I2C_REGION 0x20
 
 #define CCR_MEN  0x80
 #define CCR_MIEN 0x40
@@ -315,102 +317,121 @@ static struct i2c_adapter mpc_ops = {
 	.timeout = 1,
 };
 
-static int fsl_i2c_probe(struct platform_device *pdev)
+static int fsl_i2c_probe(struct of_device *op, const struct

of_device_id *match)
{
int result = 0;
struct mpc_i2c *i2c;
- struct fsl_i2c_platform_data *pdata;
- struct resource *r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-
- pdata = (struct fsl_i2c_platform_data *) pdev->dev.platform_data;

i2c = kzalloc(sizeof(*i2c), GFP_KERNEL);
if (!i2c)
return -ENOMEM;

- i2c->irq = platform_get_irq(pdev, 0);
- if (i2c->irq < 0)
- i2c->irq = NO_IRQ; /* Use polling */
+ if (of_get_property(op->node, "dfsrr", NULL))
+ i2c->flags |= FSL_I2C_DEV_SEPARATE_DFSRR;

- i2c->flags = pdata->device_flags;
- init_waitqueue_head(&i2c->queue);
+ if (of_device_is_compatible(op->node, "mpc5200-i2c"))
+ i2c->flags |= FSL_I2C_DEV_CLOCK_5200;

- i2c->base = ioremap((phys_addr_t)r->start, MPC_I2C_REGION);
+ init_waitqueue_head(&i2c->queue);

+ i2c->base = of_iomap(op->node, 0);
if (!i2c->base) {
printk(KERN_ERR "i2c-mpc - failed to map controller\n"); result = -ENOMEM;
goto fail_map;
}

- if (i2c->irq != NO_IRQ)
- if ((result = request_irq(i2c->irq, mpc_i2c_isr,
- IRQF_SHARED, "i2c-mpc", i2c)) < 0) {
- printk(KERN_ERR
- "i2c-mpc - failed to attach interrupt\n");
- goto fail_irq;
- }
+ i2c->irq = irq_of_parse_and_map(op->node, 0);
+ if (i2c->irq == NO_IRQ) {
+ result = -ENXIO;
+ goto fail_irq;
+ }
+
+ result = request_irq(i2c->irq, mpc_i2c_isr,
+ IRQF_SHARED, "i2c-mpc", i2c);
+ if (result < 0) {
+ printk(KERN_ERR "i2c-mpc - failed to attach interrupt\n");
+ goto fail_request;
+ }

mpc_i2c_setclock(i2c);
- platform_set_drvdata(pdev, i2c);
+
+ dev_set_drvdata(&op->dev, 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_numbered_adapter(&i2c->adap)) < 0) {
+ i2c->adap.dev.parent = &op->dev;
+
+ result = i2c_add_adapter(&i2c->adap);
+ if (result < 0) {
printk(KERN_ERR "i2c-mpc - failed to add adapter\n"); goto fail_add;
}
+ of_register_i2c_devices(&i2c->adap, op->node);

return result;

- fail_add:
- if (i2c->irq != NO_IRQ)
- free_irq(i2c->irq, i2c);
- fail_irq:
+ fail_add:
+ dev_set_drvdata(&op->dev, NULL);
+ free_irq(i2c->irq, i2c);
+ fail_request:
+ irq_dispose_mapping(i2c->irq);
+ fail_irq:
iounmap(i2c->base);
- fail_map:
+ fail_map:
kfree(i2c);
return result;
};

-static int fsl_i2c_remove(struct platform_device *pdev) +static int fsl_i2c_remove(struct of_device *op)
{
- struct mpc_i2c *i2c = platform_get_drvdata(pdev);
+ struct mpc_i2c *i2c = dev_get_drvdata(&op->dev);

i2c_del_adapter(&i2c->adap);
- platform_set_drvdata(pdev, NULL);
+ dev_set_drvdata(&op->dev, NULL);

if (i2c->irq != NO_IRQ)
free_irq(i2c->irq, i2c);

+ irq_dispose_mapping(i2c->irq);
iounmap(i2c->base);
kfree(i2c);
return 0;
};

-/* work with hotplug and coldplug */ -MODULE_ALIAS("platform:fsl-i2c");
+static const struct of_device_id mpc_i2c_of_match[] = {
+ {
+ .compatible = "fsl-i2c",
+ },
+ {},
+};
+MODULE_DEVICE_TABLE(of, mpc_i2c_of_match);
+

/* Structure for a device driver */
-static struct platform_driver fsl_i2c_driver = {
- .probe = fsl_i2c_probe,
- .remove = fsl_i2c_remove,
- .driver = {
- .owner = THIS_MODULE,
- .name = "fsl-i2c",
+static struct of_platform_driver mpc_i2c_driver = {
+ .match_table = mpc_i2c_of_match,
+ .probe = fsl_i2c_probe,
+ .remove = __devexit_p(fsl_i2c_remove),
+ .driver = {
+ .owner = THIS_MODULE,
+ .name = DRV_NAME,
},
};

static int __init fsl_i2c_init(void)
{
- return platform_driver_register(&fsl_i2c_driver);
+ int rv;
+
+ rv = of_register_platform_driver(&mpc_i2c_driver);
+ if (rv)
+ printk(KERN_ERR DRV_NAME " of_register_platform_driver failed (%i)\n", rv);
+ return rv;
}

static void __exit fsl_i2c_exit(void)
{
- platform_driver_unregister(&fsl_i2c_driver);
+ of_unregister_platform_driver(&mpc_i2c_driver);
}

module_init(fsl_i2c_init);

Tested-by on v1 1/1
#1 lore raw
Quoted 5 lines · Jon Smirl

Convert i2c-mpc from a platform driver into an of_platform driver. This patch is much smaller since Jochen already added of_find_i2c_driver(). Versions of this have been posted before.

Typo: Signed-off... (I'm curious, do such typos enforce resending the patch?)

Quoted 37 lines
Signature · 4 lines
-- 

 drivers/i2c/busses/i2c-mpc.c |  105 +++++++++++++++++++++++++-----------------
 1 files changed, 63 insertions(+), 42 deletions(-)
drivers/i2c/busses/i2c-mpc.c +4 -2
index a076129..76d8091 100644
@@ -18,6 +18,8 @@
 #include <linux/sched.h>
 #include <linux/init.h>
 #include <linux/platform_device.h>
+#include <linux/of_platform.h>
+#include <linux/of_i2c.h>
 
 #include <asm/io.h>
 #include <linux/fsl_devices.h>
@@ -25,13 +27,13 @@
 #include <linux/interrupt.h>
 #include <linux/delay.h>
 
-#define MPC_I2C_ADDR  0x00
+#define DRV_NAME "mpc-i2c"
+
 #define MPC_I2C_FDR 	0x04
 #define MPC_I2C_CR	0x08
 #define MPC_I2C_SR	0x0c
 #define MPC_I2C_DR	0x10
 #define MPC_I2C_DFSRR 0x14
-#define MPC_I2C_REGION 0x20
 
 #define CCR_MEN  0x80
 #define CCR_MIEN 0x40

drivers/i2c/busses/i2c-mpc.c static struct i2c_adapter mpc_ops = { · line 321

Quoted 6 lines
drivers/i2c/busses/i2c-mpc.c +1 -1
@@ -315,102 +317,121 @@ static struct i2c_adapter mpc_ops = {
 	.timeout = 1,
 };
 
-static int fsl_i2c_probe(struct platform_device *pdev)
+static int fsl_i2c_probe(struct of_device *op, const struct
 of_device_id *match)

The above two lines have to be concatenated, otherwise the patch will not apply. Also, __devinit?

Quoted 33 lines
drivers/i2c/busses/i2c-mpc.c +6 -10
 {
 	int result = 0;
 	struct mpc_i2c *i2c;
-	struct fsl_i2c_platform_data *pdata;
-	struct resource *r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-
-	pdata = (struct fsl_i2c_platform_data *) pdev->dev.platform_data;
 
 	i2c = kzalloc(sizeof(*i2c), GFP_KERNEL);
 	if (!i2c)
 		return -ENOMEM;
 
-	i2c->irq = platform_get_irq(pdev, 0);
-	if (i2c->irq < 0)
-		i2c->irq = NO_IRQ; /* Use polling */
+	if (of_get_property(op->node, "dfsrr", NULL))
+		i2c->flags |= FSL_I2C_DEV_SEPARATE_DFSRR;
 
-	i2c->flags = pdata->device_flags;
-	init_waitqueue_head(&i2c->queue);
+	if (of_device_is_compatible(op->node, "mpc5200-i2c"))
+		i2c->flags |= FSL_I2C_DEV_CLOCK_5200;
 
-	i2c->base = ioremap((phys_addr_t)r->start, MPC_I2C_REGION);
+	init_waitqueue_head(&i2c->queue);
 
+	i2c->base = of_iomap(op->node, 0);
 	if (!i2c->base) {
 		printk(KERN_ERR "i2c-mpc - failed to map controller\n");
 		result = -ENOMEM;
 		goto fail_map;
 	}
 

drivers/i2c/busses/i2c-mpc.c static struct i2c_adapter mpc_ops = { · line 347

Quoted 10 lines
drivers/i2c/busses/i2c-mpc.c +3 -7
-	if (i2c->irq != NO_IRQ)
-		if ((result = request_irq(i2c->irq, mpc_i2c_isr,
-					  IRQF_SHARED, "i2c-mpc", i2c)) < 0) {
-			printk(KERN_ERR
-			       "i2c-mpc - failed to attach interrupt\n");
-			goto fail_irq;
-		}
+	i2c->irq = irq_of_parse_and_map(op->node, 0);
+	if (i2c->irq == NO_IRQ) {
+		result = -ENXIO;

Minor thing, but I wonder if -EINVAL is more appropriate?

Quoted 40 lines
drivers/i2c/busses/i2c-mpc.c +21 -8
+		goto fail_irq;
+	}
+
+	result = request_irq(i2c->irq, mpc_i2c_isr,
+						IRQF_SHARED, "i2c-mpc", i2c);
+	if (result < 0) {
+		printk(KERN_ERR "i2c-mpc - failed to attach interrupt\n");
+		goto fail_request;
+	}
 
 	mpc_i2c_setclock(i2c);
-	platform_set_drvdata(pdev, i2c);
+
+	dev_set_drvdata(&op->dev, 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_numbered_adapter(&i2c->adap)) < 0) {
+	i2c->adap.dev.parent = &op->dev;
+
+	result = i2c_add_adapter(&i2c->adap);
+	if (result < 0) {
 		printk(KERN_ERR "i2c-mpc - failed to add adapter\n");
 		goto fail_add;
 	}
+	of_register_i2c_devices(&i2c->adap, op->node);
 
 	return result;
 
-      fail_add:
-	if (i2c->irq != NO_IRQ)
-		free_irq(i2c->irq, i2c);
-      fail_irq:
+ fail_add:
+	dev_set_drvdata(&op->dev, NULL);
+	free_irq(i2c->irq, i2c);
+ fail_request:
+	irq_dispose_mapping(i2c->irq);

drivers/i2c/busses/i2c-mpc.c static struct i2c_adapter mpc_ops = { · line 387

Quoted 10 lines
drivers/i2c/busses/i2c-mpc.c +3 -2
+ fail_irq:
 	iounmap(i2c->base);
-      fail_map:
+ fail_map:
 	kfree(i2c);
 	return result;
 };
 
-static int fsl_i2c_remove(struct platform_device *pdev)
+static int fsl_i2c_remove(struct of_device *op)

__devexit?

Quoted 64 lines
drivers/i2c/busses/i2c-mpc.c +25 -12
 {
-	struct mpc_i2c *i2c = platform_get_drvdata(pdev);
+	struct mpc_i2c *i2c = dev_get_drvdata(&op->dev);
 
 	i2c_del_adapter(&i2c->adap);
-	platform_set_drvdata(pdev, NULL);
+	dev_set_drvdata(&op->dev, NULL);
 
 	if (i2c->irq != NO_IRQ)
 		free_irq(i2c->irq, i2c);
 
+	irq_dispose_mapping(i2c->irq);
 	iounmap(i2c->base);
 	kfree(i2c);
 	return 0;
 };
 
-/* work with hotplug and coldplug */
-MODULE_ALIAS("platform:fsl-i2c");
+static const struct of_device_id mpc_i2c_of_match[] = {
+	{
+		.compatible	= "fsl-i2c",
+	},
+	{},
+};
+MODULE_DEVICE_TABLE(of, mpc_i2c_of_match);
+
 
 /* Structure for a device driver */
-static struct platform_driver fsl_i2c_driver = {
-	.probe = fsl_i2c_probe,
-	.remove = fsl_i2c_remove,
-	.driver	= {
-		.owner = THIS_MODULE,
-		.name = "fsl-i2c",
+static struct of_platform_driver mpc_i2c_driver = {
+	.match_table	= mpc_i2c_of_match,
+	.probe		= fsl_i2c_probe,
+	.remove		= __devexit_p(fsl_i2c_remove),
+	.driver		= {
+		.owner	= THIS_MODULE,
+		.name	= DRV_NAME,
 	},
 };
 
 static int __init fsl_i2c_init(void)
 {
-	return platform_driver_register(&fsl_i2c_driver);
+	int rv;
+
+	rv = of_register_platform_driver(&mpc_i2c_driver);
+	if (rv)
+		printk(KERN_ERR DRV_NAME " of_register_platform_driver failed (%i)\n", rv);
+	return rv;
 }
 
 static void __exit fsl_i2c_exit(void)
 {
-	platform_driver_unregister(&fsl_i2c_driver);
+	of_unregister_platform_driver(&mpc_i2c_driver);
 }
 

module_init(fsl_i2c_init);

Quoted 4 lines

_______________________________________________
i2c mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/i2c

Kind regards,

Wolfram

Signature · 2 lines
  Dipl.-Ing. Wolfram Sang | http://www.pengutronix.de
 Pengutronix - Linux Solutions for Science and Industry

_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://ozlabs.org/mailman/listinfo/linuxppc-dev

author
#2 lore raw
Quoted 10 lines · Wolfram Sang
Quoted 5 lines · Jon Smirl

Convert i2c-mpc from a platform driver into an of_platform driver. This patch is much smaller since Jochen already added of_find_i2c_driver(). Versions of this have been posted before.

Typo: Signed-off... (I'm curious, do such typos enforce resending the
patch?)

I just cut and pasted this version to get the comments. Next pass I will send it using stgit which will add the right signed-off line and fix the wrapping.

Quoted 245 lines
Quoted 37 lines

--

 drivers/i2c/busses/i2c-mpc.c |  105 +++++++++++++++++++++++++-----------------
 1 files changed, 63 insertions(+), 42 deletions(-)
drivers/i2c/busses/i2c-mpc.c +4 -2
index a076129..76d8091 100644
@@ -18,6 +18,8 @@
 #include <linux/sched.h>
 #include <linux/init.h>
 #include <linux/platform_device.h>
+#include <linux/of_platform.h>
+#include <linux/of_i2c.h>
 
 #include <asm/io.h>
 #include <linux/fsl_devices.h>
@@ -25,13 +27,13 @@
 #include <linux/interrupt.h>
 #include <linux/delay.h>
 
-#define MPC_I2C_ADDR  0x00
+#define DRV_NAME "mpc-i2c"
+
 #define MPC_I2C_FDR  0x04
 #define MPC_I2C_CR   0x08
 #define MPC_I2C_SR   0x0c
 #define MPC_I2C_DR   0x10
 #define MPC_I2C_DFSRR 0x14
-#define MPC_I2C_REGION 0x20
 
 #define CCR_MEN  0x80
 #define CCR_MIEN 0x40

drivers/i2c/busses/i2c-mpc.c static struct i2c_adapter mpc_ops = { · line 321

Quoted 6 lines
drivers/i2c/busses/i2c-mpc.c +1 -1
@@ -315,102 +317,121 @@ static struct i2c_adapter mpc_ops = {
      .timeout = 1,
 };
 
-static int fsl_i2c_probe(struct platform_device *pdev)
+static int fsl_i2c_probe(struct of_device *op, const struct
 of_device_id *match)

The above two lines have to be concatenated, otherwise the patch will
not apply. Also, __devinit?

Quoted 33 lines
drivers/i2c/busses/i2c-mpc.c +6 -10
 {
      int result = 0;
      struct mpc_i2c *i2c;
-     struct fsl_i2c_platform_data *pdata;
-     struct resource *r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-
-     pdata = (struct fsl_i2c_platform_data *) pdev->dev.platform_data;
 
      i2c = kzalloc(sizeof(*i2c), GFP_KERNEL);
      if (!i2c)
              return -ENOMEM;
 
-     i2c->irq = platform_get_irq(pdev, 0);
-     if (i2c->irq < 0)
-             i2c->irq = NO_IRQ; /* Use polling */
+     if (of_get_property(op->node, "dfsrr", NULL))
+             i2c->flags |= FSL_I2C_DEV_SEPARATE_DFSRR;
 
-     i2c->flags = pdata->device_flags;
-     init_waitqueue_head(&i2c->queue);
+     if (of_device_is_compatible(op->node, "mpc5200-i2c"))
+             i2c->flags |= FSL_I2C_DEV_CLOCK_5200;
 
-     i2c->base = ioremap((phys_addr_t)r->start, MPC_I2C_REGION);
+     init_waitqueue_head(&i2c->queue);
 
+     i2c->base = of_iomap(op->node, 0);
      if (!i2c->base) {
              printk(KERN_ERR "i2c-mpc - failed to map controller\n");
              result = -ENOMEM;
              goto fail_map;
      }
 

drivers/i2c/busses/i2c-mpc.c static struct i2c_adapter mpc_ops = { · line 347

Quoted 10 lines
drivers/i2c/busses/i2c-mpc.c +3 -7
-     if (i2c->irq != NO_IRQ)
-             if ((result = request_irq(i2c->irq, mpc_i2c_isr,
-                                       IRQF_SHARED, "i2c-mpc", i2c)) < 0) {
-                     printk(KERN_ERR
-                            "i2c-mpc - failed to attach interrupt\n");
-                     goto fail_irq;
-             }
+     i2c->irq = irq_of_parse_and_map(op->node, 0);
+     if (i2c->irq == NO_IRQ) {
+             result = -ENXIO;

Minor thing, but I wonder if -EINVAL is more appropriate?

Quoted 40 lines
drivers/i2c/busses/i2c-mpc.c +21 -8
+             goto fail_irq;
+     }
+
+     result = request_irq(i2c->irq, mpc_i2c_isr,
+                                             IRQF_SHARED, "i2c-mpc", i2c);
+     if (result < 0) {
+             printk(KERN_ERR "i2c-mpc - failed to attach interrupt\n");
+             goto fail_request;
+     }
 
      mpc_i2c_setclock(i2c);
-     platform_set_drvdata(pdev, i2c);
+
+     dev_set_drvdata(&op->dev, 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_numbered_adapter(&i2c->adap)) < 0) {
+     i2c->adap.dev.parent = &op->dev;
+
+     result = i2c_add_adapter(&i2c->adap);
+     if (result < 0) {
              printk(KERN_ERR "i2c-mpc - failed to add adapter\n");
              goto fail_add;
      }
+     of_register_i2c_devices(&i2c->adap, op->node);
 
      return result;
 
-      fail_add:
-     if (i2c->irq != NO_IRQ)
-             free_irq(i2c->irq, i2c);
-      fail_irq:
+ fail_add:
+     dev_set_drvdata(&op->dev, NULL);
+     free_irq(i2c->irq, i2c);
+ fail_request:
+     irq_dispose_mapping(i2c->irq);

drivers/i2c/busses/i2c-mpc.c static struct i2c_adapter mpc_ops = { · line 387

Quoted 10 lines
drivers/i2c/busses/i2c-mpc.c +3 -2
+ fail_irq:
      iounmap(i2c->base);
-      fail_map:
+ fail_map:
      kfree(i2c);
      return result;
 };
 
-static int fsl_i2c_remove(struct platform_device *pdev)
+static int fsl_i2c_remove(struct of_device *op)

__devexit?

Quoted 65 lines
drivers/i2c/busses/i2c-mpc.c +25 -12
 {
-     struct mpc_i2c *i2c = platform_get_drvdata(pdev);
+     struct mpc_i2c *i2c = dev_get_drvdata(&op->dev);
 
      i2c_del_adapter(&i2c->adap);
-     platform_set_drvdata(pdev, NULL);
+     dev_set_drvdata(&op->dev, NULL);
 
      if (i2c->irq != NO_IRQ)
              free_irq(i2c->irq, i2c);
 
+     irq_dispose_mapping(i2c->irq);
      iounmap(i2c->base);
      kfree(i2c);
      return 0;
 };
 
-/* work with hotplug and coldplug */
-MODULE_ALIAS("platform:fsl-i2c");
+static const struct of_device_id mpc_i2c_of_match[] = {
+     {
+             .compatible     = "fsl-i2c",
+     },
+     {},
+};
+MODULE_DEVICE_TABLE(of, mpc_i2c_of_match);
+
 
 /* Structure for a device driver */
-static struct platform_driver fsl_i2c_driver = {
-     .probe = fsl_i2c_probe,
-     .remove = fsl_i2c_remove,
-     .driver = {
-             .owner = THIS_MODULE,
-             .name = "fsl-i2c",
+static struct of_platform_driver mpc_i2c_driver = {
+     .match_table    = mpc_i2c_of_match,
+     .probe          = fsl_i2c_probe,
+     .remove         = __devexit_p(fsl_i2c_remove),
+     .driver         = {
+             .owner  = THIS_MODULE,
+             .name   = DRV_NAME,
      },
 };
 
 static int __init fsl_i2c_init(void)
 {
-     return platform_driver_register(&fsl_i2c_driver);
+     int rv;
+
+     rv = of_register_platform_driver(&mpc_i2c_driver);
+     if (rv)
+             printk(KERN_ERR DRV_NAME " of_register_platform_driver failed (%i)\n", rv);
+     return rv;
 }
 
 static void __exit fsl_i2c_exit(void)
 {
-     platform_driver_unregister(&fsl_i2c_driver);
+     of_unregister_platform_driver(&mpc_i2c_driver);
 }
 

module_init(fsl_i2c_init);

Quoted 4 lines

_______________________________________________
i2c mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/i2c

Kind regards,

Wolfram

--
Dipl.-Ing. Wolfram Sang | http://www.pengutronix.de
Pengutronix - Linux Solutions for Science and Industry

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFIT/awD27XaX1/VRsRAoPrAJ0eWru6TJizVxfksnhS3KjZ7WHhmACcCbXJ YsAUtKZSxlJAV5r/G22BlaE=
=YX24
-----END PGP SIGNATURE-----

Signature · 2 lines
Jon Smirl
[email protected]
#3 lore raw

Hi Jon,

Quoted 10 lines · Jon Smirl
Quoted 9 lines · Wolfram Sang
Quoted 5 lines · Jon Smirl

Convert i2c-mpc from a platform driver into an of_platform driver. This patch is much smaller since Jochen already added of_find_i2c_driver(). Versions of this have been posted before.

Typo: Signed-off... (I'm curious, do such typos enforce resending the
patch?)

In theory it should. The line means that you've read the "Developer's Certificate of Origin" and you agree with it, so it's somewhat binding. I guess a lawyer would argue that the line isn't worth anything if "Signed-off-by" isn't spelled properly.

Thanks Wolfram for the review, BTW.

Quoted 3 lines

I just cut and pasted this version to get the comments. Next pass I will send it using stgit which will add the right signed-off line and fix the wrapping.

That's doing things the wrong way around. If you want people to comment on your patch, the least you can do is make sure they can apply it.

If I can't apply your patch, that means I can't verify if it applies properly, I can't run checkpatch.pl on it, I can't get quilt to color it, and I can't compare it to a previous version of the same patch.

Also, it would be a good idea to keep Jochen Friedrich in the loop (Cc'd), as he proposed a similar patch based on a previous version of yours back in April. I suppose he has some interest in it.

While mentioning Jochen's version of the patch: it was deleting 123 lines from arch/powerpc/sysdev/fsl_soc.c. Yours doesn't. Should it?
http://lists.lm-sensors.org/pipermail/i2c/2008-April/003314.html

Signature · 1 line
Jean Delvare
#4 lore raw
In reply to Jon Smirl

Hi Jon,

Quoted 7 lines

Convert i2c-mpc from a platform driver into an of_platform driver. This patch is much smaller since Jochen already added of_find_i2c_driver(). Versions of this have been posted before.

This separator is supposed to be 3 dashes, NOT 2 dashes followed by a space. The latter makes the patch look like your e-mail signature, and e-mail clients usually strip that when one replies. Which is pretty inconvenient when commenting on a patch ;)

drivers/i2c/busses/i2c-mpc.c line 20

Quoted 13 lines
 drivers/i2c/busses/i2c-mpc.c |  105 +++++++++++++++++++++++++-----------------
 1 files changed, 63 insertions(+), 42 deletions(-)
drivers/i2c/busses/i2c-mpc.c +0 -0
index a076129..76d8091 100644
@@ -18,6 +18,8 @@
 #include <linux/sched.h>
 #include <linux/init.h>
 #include <linux/platform_device.h>

If the driver is no longer a platform driver, do you still need to include <linux/platform_device.h>?

Quoted 63 lines
drivers/i2c/busses/i2c-mpc.c +11 -15
+#include <linux/of_platform.h>
+#include <linux/of_i2c.h>
 
 #include <asm/io.h>
 #include <linux/fsl_devices.h>
@@ -25,13 +27,13 @@
 #include <linux/interrupt.h>
 #include <linux/delay.h>
 
-#define MPC_I2C_ADDR  0x00
+#define DRV_NAME "mpc-i2c"
+
 #define MPC_I2C_FDR 	0x04
 #define MPC_I2C_CR	0x08
 #define MPC_I2C_SR	0x0c
 #define MPC_I2C_DR	0x10
 #define MPC_I2C_DFSRR 0x14
-#define MPC_I2C_REGION 0x20
 
 #define CCR_MEN  0x80
 #define CCR_MIEN 0x40
@@ -315,102 +317,121 @@ static struct i2c_adapter mpc_ops = {
 	.timeout = 1,
 };
 
-static int fsl_i2c_probe(struct platform_device *pdev)
+static int fsl_i2c_probe(struct of_device *op, const struct
 of_device_id *match)
 {
 	int result = 0;
 	struct mpc_i2c *i2c;
-	struct fsl_i2c_platform_data *pdata;
-	struct resource *r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-
-	pdata = (struct fsl_i2c_platform_data *) pdev->dev.platform_data;
 
 	i2c = kzalloc(sizeof(*i2c), GFP_KERNEL);
 	if (!i2c)
 		return -ENOMEM;
 
-	i2c->irq = platform_get_irq(pdev, 0);
-	if (i2c->irq < 0)
-		i2c->irq = NO_IRQ; /* Use polling */
+	if (of_get_property(op->node, "dfsrr", NULL))
+		i2c->flags |= FSL_I2C_DEV_SEPARATE_DFSRR;
 
-	i2c->flags = pdata->device_flags;
-	init_waitqueue_head(&i2c->queue);
+	if (of_device_is_compatible(op->node, "mpc5200-i2c"))
+		i2c->flags |= FSL_I2C_DEV_CLOCK_5200;
 
-	i2c->base = ioremap((phys_addr_t)r->start, MPC_I2C_REGION);
+	init_waitqueue_head(&i2c->queue);
 
+	i2c->base = of_iomap(op->node, 0);
 	if (!i2c->base) {
 		printk(KERN_ERR "i2c-mpc - failed to map controller\n");
 		result = -ENOMEM;
 		goto fail_map;
 	}
 
-	if (i2c->irq != NO_IRQ)
-		if ((result = request_irq(i2c->irq, mpc_i2c_isr,

drivers/i2c/busses/i2c-mpc.c static struct i2c_adapter mpc_ops = { · line 349

Quoted 10 lines
drivers/i2c/busses/i2c-mpc.c +5 -5
-					  IRQF_SHARED, "i2c-mpc", i2c)) < 0) {
-			printk(KERN_ERR
-			       "i2c-mpc - failed to attach interrupt\n");
-			goto fail_irq;
-		}
+	i2c->irq = irq_of_parse_and_map(op->node, 0);
+	if (i2c->irq == NO_IRQ) {
+		result = -ENXIO;
+		goto fail_irq;
+	}

This is a significant functionality change. The original code supported devices with no IRQ, now your enforce the use of an IRQ and fail if it's not there. If you have any reason to do that, this must be in a separate patch, and this must be done consistently (removing the polling code in i2c_wait, etc.)

Quoted 11 lines
drivers/i2c/busses/i2c-mpc.c +8 -1
+
+	result = request_irq(i2c->irq, mpc_i2c_isr,
+						IRQF_SHARED, "i2c-mpc", i2c);
+	if (result < 0) {
+		printk(KERN_ERR "i2c-mpc - failed to attach interrupt\n");
+		goto fail_request;
+	}
 
 	mpc_i2c_setclock(i2c);
-	platform_set_drvdata(pdev, i2c);
+

drivers/i2c/busses/i2c-mpc.c static struct i2c_adapter mpc_ops = { · line 366

Quoted 10 lines
drivers/i2c/busses/i2c-mpc.c +4 -3
+	dev_set_drvdata(&op->dev, 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_numbered_adapter(&i2c->adap)) < 0) {
+	i2c->adap.dev.parent = &op->dev;
+
+	result = i2c_add_adapter(&i2c->adap);

The driver was previously using i2c_add_numbered_adapter(), giving MPC platform the possibility to use new-style i2c drivers:
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=1469fa263870acd890a4b9f6ef557acc5d673b44
You're breaking this, I doubt it's on purpose?

Quoted 70 lines
drivers/i2c/busses/i2c-mpc.c +28 -16
+	if (result < 0) {
 		printk(KERN_ERR "i2c-mpc - failed to add adapter\n");
 		goto fail_add;
 	}
+	of_register_i2c_devices(&i2c->adap, op->node);
 
 	return result;
 
-      fail_add:
-	if (i2c->irq != NO_IRQ)
-		free_irq(i2c->irq, i2c);
-      fail_irq:
+ fail_add:
+	dev_set_drvdata(&op->dev, NULL);
+	free_irq(i2c->irq, i2c);
+ fail_request:
+	irq_dispose_mapping(i2c->irq);
+ fail_irq:
 	iounmap(i2c->base);
-      fail_map:
+ fail_map:
 	kfree(i2c);
 	return result;
 };
 
-static int fsl_i2c_remove(struct platform_device *pdev)
+static int fsl_i2c_remove(struct of_device *op)
 {
-	struct mpc_i2c *i2c = platform_get_drvdata(pdev);
+	struct mpc_i2c *i2c = dev_get_drvdata(&op->dev);
 
 	i2c_del_adapter(&i2c->adap);
-	platform_set_drvdata(pdev, NULL);
+	dev_set_drvdata(&op->dev, NULL);
 
 	if (i2c->irq != NO_IRQ)
 		free_irq(i2c->irq, i2c);
 
+	irq_dispose_mapping(i2c->irq);
 	iounmap(i2c->base);
 	kfree(i2c);
 	return 0;
 };
 
-/* work with hotplug and coldplug */
-MODULE_ALIAS("platform:fsl-i2c");
+static const struct of_device_id mpc_i2c_of_match[] = {
+	{
+		.compatible	= "fsl-i2c",
+	},
+	{},
+};
+MODULE_DEVICE_TABLE(of, mpc_i2c_of_match);
+
 
 /* Structure for a device driver */
-static struct platform_driver fsl_i2c_driver = {
-	.probe = fsl_i2c_probe,
-	.remove = fsl_i2c_remove,
-	.driver	= {
-		.owner = THIS_MODULE,
-		.name = "fsl-i2c",
+static struct of_platform_driver mpc_i2c_driver = {
+	.match_table	= mpc_i2c_of_match,
+	.probe		= fsl_i2c_probe,
+	.remove		= __devexit_p(fsl_i2c_remove),
+	.driver		= {
+		.owner	= THIS_MODULE,
+		.name	= DRV_NAME,
 	},

drivers/i2c/busses/i2c-mpc.c static struct i2c_adapter mpc_ops = { · line 429

Quoted 10 lines
drivers/i2c/busses/i2c-mpc.c +5 -1
 };
 
 static int __init fsl_i2c_init(void)
 {
-	return platform_driver_register(&fsl_i2c_driver);
+	int rv;
+
+	rv = of_register_platform_driver(&mpc_i2c_driver);
+	if (rv)
+		printk(KERN_ERR DRV_NAME " of_register_platform_driver failed (%i)\n", rv);

Line too long, please fold.

drivers/i2c/busses/i2c-mpc.c static struct i2c_adapter mpc_ops = { · line 431

Quoted 2 lines
drivers/i2c/busses/i2c-mpc.c +1 -0
+	return rv;
 }

Note, BTW, that this error check doesn't seem very useful. Driver registration can't really fail, if it does you can't really miss it, and modprobe will tell you error code if it happens (not too sure what happens if init of built-in drivers fail.)

drivers/i2c/busses/i2c-mpc.c static struct i2c_adapter mpc_ops = { · line 437

Quoted 8 lines
drivers/i2c/busses/i2c-mpc.c +1 -1
 static void __exit fsl_i2c_exit(void)
 {
-	platform_driver_unregister(&fsl_i2c_driver);
+	of_unregister_platform_driver(&mpc_i2c_driver);
 }
 
 module_init(fsl_i2c_init);

This adds to Wolfram's comments about missing devinit/devexit tags which were correct and should be addressed.

Signature · 1 line
Jean Delvare
author
#5 lore raw
Quoted 11 lines · Jean Delvare

Review

Quoted 9 lines
      i2c->adap = mpc_ops;
(quoted diff) +3 -3
-     i2c->adap.nr = pdev->id;
      i2c_set_adapdata(&i2c->adap, i2c);
-     i2c->adap.dev.parent = &pdev->dev;
-     if ((result = i2c_add_numbered_adapter(&i2c->adap)) < 0) {
+     i2c->adap.dev.parent = &op->dev;
+
+     result = i2c_add_adapter(&i2c->adap);
Quoted 4 lines

The driver was previously using i2c_add_numbered_adapter(), giving MPC
platform the possibility to use new-style i2c drivers:
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=1469fa263870acd890a4b9f6ef557acc5d673b44
You're breaking this, I doubt it's on purpose?

Grant, what do you want here? You're the one who converted it to i2c_add_numbered_adapter. But in other posts you've said that the device tree should have nothing to do with bus numbering.

Once this driver is converted to an OF one it shouldn't need bus ids since all of the i2c devices will be children of the bus node. We can just let the i2c subsystem assign a bus number.

Timur has some issues with the i2c bus number in his ALSA driver. The problem is locating the i2c device when the i2s driver loads. Parsing the device tree to extract an i2c bus and device number is not a good solution.

codec-handle should give you the i2c device node. But then we can't use of_find_device_by_node because the i2c device is not an of_device, it's a cross platform i2c_device. Should of_find_device_by_node() return a 'struct device' instead of a 'struct of_device' and leave it as a user exercise to cast up? It is used nine times in the kernel, mostly sparc.

		i2s@2000 { /* PSC1 in i2s mode */
			device_type = "sound";
			compatible = "mpc5200b-psc-i2s","fsl,mpc5200b-psc-i2s";
			cell-index = <0>;
			reg = <0x2000 0x100>;
			interrupts = <0x2 0x2 0x0>;
			interrupt-parent = <&mpc5200_pic>;
			codec-handle = <&tas0>;
		};
		i2c@3d00 {
			#address-cells = <1>;
			#size-cells = <0>;
			compatible = "fsl,mpc5200b-i2c","fsl,mpc5200-i2c","fsl-i2c";
			cell-index = <0>;
			reg = <0x3d00 0x40>;
			interrupts = <0x2 0xf 0x0>;
			interrupt-parent = <&mpc5200_pic>;
			fsl5200-clocking;
			
			tas0:codec@1b {
				compatible = "ti,tas5504";
				reg = <0x1b>;
			};
		};
Signature · 2 lines
Jon Smirl
[email protected]
#6 lore raw
Quoted 12 lines · Jon Smirl
Quoted 11 lines · Jean Delvare
Quoted 9 lines
      i2c->adap = mpc_ops;
(quoted diff) +3 -3
-     i2c->adap.nr = pdev->id;
      i2c_set_adapdata(&i2c->adap, i2c);
-     i2c->adap.dev.parent = &pdev->dev;
-     if ((result = i2c_add_numbered_adapter(&i2c->adap)) < 0) {
+     i2c->adap.dev.parent = &op->dev;
+
+     result = i2c_add_adapter(&i2c->adap);
Quoted 8 lines
Quoted 4 lines

The driver was previously using i2c_add_numbered_adapter(), giving MPC
platform the possibility to use new-style i2c drivers:
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=1469fa263870acd890a4b9f6ef557acc5d673b44
You're breaking this, I doubt it's on purpose?

Grant, what do you want here? You're the one who converted it to i2c_add_numbered_adapter. But in other posts you've said that the device tree should have nothing to do with bus numbering.

Yes, I did make that change, but that was when it was a platform bus driver. Converting it to an of_platform bus driver entirely changes the situation and it should go back to using i2c_add_adapter() with a parse of the device tree for child nodes.

Quoted 3 lines

Once this driver is converted to an OF one it shouldn't need bus ids since all of the i2c devices will be children of the bus node. We can just let the i2c subsystem assign a bus number.

Exactly.

Quoted 4 lines

Timur has some issues with the i2c bus number in his ALSA driver. The problem is locating the i2c device when the i2s driver loads. Parsing the device tree to extract an i2c bus and device number is not a good solution.

The trick here is to store the pointer to the device node inside the i2c device. I do this with SPI devices like this:

	/* Store a pointer to the node in the device structure */
	of_node_get(nc);
	spi->dev.archdata.of_node = nc;

Then, when you've got a device_node pointer, you can parse through the set of registered SPI devices and match against the one that has the same device node pointer.

Quoted 6 lines

codec-handle should give you the i2c device node. But then we can't use of_find_device_by_node because the i2c device is not an of_device, it's a cross platform i2c_device. Should of_find_device_by_node() return a 'struct device' instead of a 'struct of_device' and leave it as a user exercise to cast up? It is used nine times in the kernel, mostly sparc.

No, this doesn't work because I2C and SPI devices are not of_platform devices. They aren't even platform devices. of_find_device_by_node() only works for the of_platform bus.

Using archdata.of_node is part of the device structure and works for every bus type (platform, of_platform, SPI, I2C, PCI, etc.)

g.

#7 lore raw

Hi Jon, Grant,

Quoted 18 lines · Grant Likely
Quoted 17 lines · Jon Smirl
Quoted 15 lines · Jean Delvare

Review

Quoted 9 lines
      i2c->adap = mpc_ops;
(quoted diff) +3 -3
-     i2c->adap.nr = pdev->id;
      i2c_set_adapdata(&i2c->adap, i2c);
-     i2c->adap.dev.parent = &pdev->dev;
-     if ((result = i2c_add_numbered_adapter(&i2c->adap)) < 0) {
+     i2c->adap.dev.parent = &op->dev;
+
+     result = i2c_add_adapter(&i2c->adap);

The driver was previously using i2c_add_numbered_adapter(), giving MPC
platform the possibility to use new-style i2c drivers:
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=1469fa263870acd890a4b9f6ef557acc5d673b44
You're breaking this, I doubt it's on purpose?

Quoted 8 lines
Quoted 3 lines

Grant, what do you want here? You're the one who converted it to i2c_add_numbered_adapter. But in other posts you've said that the device tree should have nothing to do with bus numbering.

Yes, I did make that change, but that was when it was a platform bus driver. Converting it to an of_platform bus driver entirely changes the situation and it should go back to using i2c_add_adapter() with a parse of the device tree for child nodes.

I am surprised and disappointed, as this sounds like a regression. Registering the i2c buses with random numbers and parsing the device tree later to figure out which devices are where, is what everybody was doing before the new i2c device/driver matching model was implemented, because there was no other way. I'm curious why you are going back to this approach when i2c-core now offers something way cleaner and more efficient.

But well, you'll know better. I'm not familiar with the platform, and don't have the time to look into it anyway.

Quoted 35 lines
Quoted 3 lines

Once this driver is converted to an OF one it shouldn't need bus ids since all of the i2c devices will be children of the bus node. We can just let the i2c subsystem assign a bus number.

Exactly.

Quoted 4 lines

Timur has some issues with the i2c bus number in his ALSA driver. The problem is locating the i2c device when the i2s driver loads. Parsing the device tree to extract an i2c bus and device number is not a good solution.

The trick here is to store the pointer to the device node inside the i2c device. I do this with SPI devices like this:

	/* Store a pointer to the node in the device structure */
	of_node_get(nc);
	spi->dev.archdata.of_node = nc;

Then, when you've got a device_node pointer, you can parse through the set of registered SPI devices and match against the one that has the same device node pointer.

Quoted 6 lines

codec-handle should give you the i2c device node. But then we can't use of_find_device_by_node because the i2c device is not an of_device, it's a cross platform i2c_device. Should of_find_device_by_node() return a 'struct device' instead of a 'struct of_device' and leave it as a user exercise to cast up? It is used nine times in the kernel, mostly sparc.

No, this doesn't work because I2C and SPI devices are not of_platform devices. They aren't even platform devices. of_find_device_by_node() only works for the of_platform bus.

Using archdata.of_node is part of the device structure and works for every bus type (platform, of_platform, SPI, I2C, PCI, etc.)

Signature · 1 line
Jean Delvare
#8 lore raw
Quoted 19 lines · Jean Delvare

Hi Jon, Grant,

Quoted 7 lines · Grant Likely
Quoted 6 lines · Jon Smirl
Quoted 5 lines

The driver was previously using i2c_add_numbered_adapter(), giving MPC
platform the possibility to use new-style i2c drivers:
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=1469fa263870acd890a4b9f6ef557acc5d673b44
You're breaking this, I doubt it's on purpose?

Quoted 8 lines
Quoted 3 lines

Grant, what do you want here? You're the one who converted it to i2c_add_numbered_adapter. But in other posts you've said that the device tree should have nothing to do with bus numbering.

Yes, I did make that change, but that was when it was a platform bus driver. Converting it to an of_platform bus driver entirely changes the situation and it should go back to using i2c_add_adapter() with a parse of the device tree for child nodes.

Quoted 7 lines

I am surprised and disappointed, as this sounds like a regression. Registering the i2c buses with random numbers and parsing the device tree later to figure out which devices are where, is what everybody was doing before the new i2c device/driver matching model was implemented, because there was no other way. I'm curious why you are going back to this approach when i2c-core now offers something way cleaner and more efficient.

Ah, but the whole random number parsing thing is no longer necessary because we ensure that registration of i2c devices always occurs after the i2c adapter is created (for device tree aware i2c adapter drivers. adapters that aren't device tree aware still need to assign a number).

After the i2c adapter registers itself, of_register_i2c_devices() is called which walks through the child nodes of the i2c adapter node in the device tree. Each child node is an i2c device, and it immediately get registered with the adapter. Because this ensures that i2c device registration always happens after adapter registration, and since the pointer to the i2c_adapter is known, then i2c_new_device() can be used directly without ever needing to know the bus number.

g.

A message that is not in the archive (sent off-list or not yet received): 20080629065812.GO13876-s3s/[email protected]

#10 lore raw
Quoted 34 lines · Grant Likely
Quoted 19 lines · Jean Delvare

Hi Jon, Grant,

Quoted 7 lines · Grant Likely
Quoted 6 lines · Jon Smirl
Quoted 5 lines

The driver was previously using i2c_add_numbered_adapter(), giving MPC
platform the possibility to use new-style i2c drivers:
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=1469fa263870acd890a4b9f6ef557acc5d673b44
You're breaking this, I doubt it's on purpose?

Quoted 8 lines
Quoted 3 lines

Grant, what do you want here? You're the one who converted it to i2c_add_numbered_adapter. But in other posts you've said that the device tree should have nothing to do with bus numbering.

Yes, I did make that change, but that was when it was a platform bus driver. Converting it to an of_platform bus driver entirely changes the situation and it should go back to using i2c_add_adapter() with a parse of the device tree for child nodes.

Quoted 7 lines

I am surprised and disappointed, as this sounds like a regression. Registering the i2c buses with random numbers and parsing the device tree later to figure out which devices are where, is what everybody was doing before the new i2c device/driver matching model was implemented, because there was no other way. I'm curious why you are going back to this approach when i2c-core now offers something way cleaner and more efficient.

Ah, but the whole random number parsing thing is no longer necessary because we ensure that registration of i2c devices always occurs after the i2c adapter is created (for device tree aware i2c adapter drivers. adapters that aren't device tree aware still need to assign a number).

Quoted 7 lines

After the i2c adapter registers itself, of_register_i2c_devices() is called which walks through the child nodes of the i2c adapter node in the device tree. Each child node is an i2c device, and it immediately get registered with the adapter. Because this ensures that i2c device registration always happens after adapter registration, and since the pointer to the i2c_adapter is known, then i2c_new_device() can be used directly without ever needing to know the bus number.

Ah, OK. If you use i2c_new_device() then it's alright.

Signature · 6 lines
Jean Delvare

_______________________________________________
i2c mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/i2c
#11 lore raw
Quoted 1 line · On Sun, 29 Jun 2008 09:17:25 +0200 "Jean Delvare" <[email protected]> wrote:

Ah, OK. If you use i2c_new_device() then it's alright.

Correct.

I have done the same thing for the i2c-ibm_iic.c driver. Jean, I think you will like this. It gets rid of the index and the numbered drivers. And the walking of the device tree is very clean because the dts knows all the devices.

For example here is the relevant portion of the dts for the Warp:

IIC0: i2c@ef600700 {
	compatible = "ibm,iic-440ep", "ibm,iic-440gp", "ibm,iic";
	reg = <ef600700 14>;
	interrupt-parent = <&UIC0>;
	interrupts = <2 4>;
	#address-cells = <1>;
	#size-cells = <0>;

	ad7414@4a {
		compatible = "adi,ad7414";
		reg = <4a>;
		interrupts = <19 8>;
		interrupt-parent = <&UIC0>;
	};
};

It clearly shows that first i2c controller (IIC0) contains one ad7414 device at address 4A.

Cheers,
Sean

#12 lore raw
Quoted 30 lines · Sean MacLennan
Quoted 1 line · On Sun, 29 Jun 2008 09:17:25 +0200 "Jean Delvare" <[email protected]> wrote:

Ah, OK. If you use i2c_new_device() then it's alright.

Correct.

I have done the same thing for the i2c-ibm_iic.c driver. Jean, I think you will like this. It gets rid of the index and the numbered drivers. And the walking of the device tree is very clean because the dts knows all the devices.

For example here is the relevant portion of the dts for the Warp:

IIC0: i2c@ef600700 {
	compatible = "ibm,iic-440ep", "ibm,iic-440gp", "ibm,iic";
	reg = <ef600700 14>;
	interrupt-parent = <&UIC0>;
	interrupts = <2 4>;
	#address-cells = <1>;
	#size-cells = <0>;

	ad7414@4a {
		compatible = "adi,ad7414";
		reg = <4a>;
		interrupts = <19 8>;
		interrupt-parent = <&UIC0>;
	};
};
Quoted 1 line

It clearly shows that first i2c controller (IIC0) contains one ad7414 device at address 4A.

That's fine with me. I expected the dts to be converted to platform initialization data (i2c_board_info structures) being registered with i2c_register_board_info() and numbered adapters. But if you prefer unnumbered adapters and the platform code or the bus driver itself calls i2c_new_device() based on the dts, that should work too.

Signature · 1 line
Jean Delvare
#13 lore raw
In reply to Jean Delvare
Quoted 10 lines · Jean Delvare
Quoted 8 lines

After the i2c adapter registers itself, of_register_i2c_devices() is called which walks through the child nodes of the i2c adapter node in the device tree.  Each child node is an i2c device, and it immediately get registered with the adapter.  Because this ensures that i2c device registration always happens after adapter registration, and since the pointer to the i2c_adapter is known, then i2c_new_device() can be used directly without ever needing to know the bus number.

Ah, OK. If you use i2c_new_device() then it's alright.

Right. Conceptually the way that the i2c core uses "numbered" adapters and registered board_info could be viewed as a way to let platforms avoid tracking that stuff themselves. Since the of_* framework is already tracking that, there's no big win in trying to have i2c-core track that too, on its behalf.

- Dave

#14 lore raw
In reply to Jon Smirl

Review

Quoted 9 lines · Jon Smirl

Convert i2c-mpc from a platform driver into an of_platform driver. This patch is much smaller since Jochen already added of_find_i2c_driver(). Versions of this have been posted before.

--

(quoted diff) +2 -0
+       if (of_device_is_compatible(op->node, "mpc5200-i2c"))
+               i2c->flags |= FSL_I2C_DEV_CLOCK_5200;

This needs to also test for "fsl,mpc5200-i2c". "mpc5200-i2c" isn't used on current device trees, but there may be some deployed boards which still have this string.

Review

Quoted 4 lines
(quoted diff) +4 -0
+static const struct of_device_id mpc_i2c_of_match[] = {
+       {
+               .compatible     = "fsl-i2c",
+       },

You can probably shorten this by 2 lines if you change it to:
+ { .compatible = "fsl-i2c", },

Doing so makes it more readable when you need to add additional compatible values.

g.

Signature · 2 lines
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.