From: Domen Puncer <domen.puncer@telargo.com>
To: linuxppc-embedded@ozlabs.org
Subject: [PATCH] i2c-mpc: add support for arch/powerpc/ tree
Date: Fri, 2 Mar 2007 11:47:18 +0100	[thread overview]
Message-ID: <20070302104718.GU4397@moe.telargo.com> (raw)
Add I2C support for mpc5200 powerpc tree.
Tested to work on eeprom on lite5200b.
Signed-off-by: Domen Puncer <domen.puncer@telargo.com>
---
I'm not sure how this relates to FSL_SOC config option and
fsl_i2c_of_init. Comments?
	Domen
 arch/powerpc/boot/dts/lite5200b.dts |    2 
 drivers/i2c/busses/i2c-mpc.c        |   80 +++++++++++++++++++++++++++++++++++-
 2 files changed, 80 insertions(+), 2 deletions(-)
Index: grant.git/arch/powerpc/boot/dts/lite5200b.dts
===================================================================
--- grant.git.orig/arch/powerpc/boot/dts/lite5200b.dts
+++ grant.git/arch/powerpc/boot/dts/lite5200b.dts
@@ -328,6 +328,7 @@
 			reg = <3d00 40>;
 			interrupts = <2 f 0>;
 			interrupt-parent = <500>;
+			fsl5200-clocking;
 		};
 
 		i2c@3d40 {
@@ -337,6 +338,7 @@
 			reg = <3d40 40>;
 			interrupts = <2 10 0>;
 			interrupt-parent = <500>;
+			fsl5200-clocking;
 		};
 		sram@8000 {
 			device_type = "sram";
Index: grant.git/drivers/i2c/busses/i2c-mpc.c
===================================================================
--- grant.git.orig/drivers/i2c/busses/i2c-mpc.c
+++ grant.git/drivers/i2c/busses/i2c-mpc.c
@@ -20,6 +20,10 @@
 #include <linux/pci.h>
 #include <linux/platform_device.h>
 
+#ifdef CONFIG_PPC_MERGE
+#include <asm/of_device.h>
+#include <asm/of_platform.h>
+#endif
 #include <asm/io.h>
 #include <linux/fsl_devices.h>
 #include <linux/i2c.h>
@@ -287,25 +291,50 @@ static struct i2c_adapter mpc_ops = {
 	.retries = 1
 };
 
+#ifdef CONFIG_PPC_MERGE
+static int fsl_i2c_probe(struct of_device *op, const struct of_device_id *match)
+#else
 static int fsl_i2c_probe(struct platform_device *pdev)
+#endif
 {
 	int result = 0;
 	struct mpc_i2c *i2c;
 	struct fsl_i2c_platform_data *pdata;
+#ifdef CONFIG_PPC_MERGE
+	struct resource __r;
+	struct resource *r = &__r;
+
+	result = of_address_to_resource(op->node, 0, r);
+	if (result) {
+		printk(KERN_ERR "i2c-mpc - error parsing device node resource\n");
+		return result;
+	}
+
+	pdata = (struct fsl_i2c_platform_data *) op->dev.platform_data;
+#else
 	struct resource *r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 
 	pdata = (struct fsl_i2c_platform_data *) pdev->dev.platform_data;
+#endif
 
 	if (!(i2c = kzalloc(sizeof(*i2c), GFP_KERNEL))) {
 		return -ENOMEM;
 	}
 
+#ifdef CONFIG_PPC_MERGE
+	i2c->irq = irq_of_parse_and_map(op->node, 0);
+	if (get_property(op->node, "dfsrr", NULL))
+		i2c->flags = FSL_I2C_DEV_SEPARATE_DFSRR;
+	if (get_property(op->node, "fsl5200-clocking", NULL))
+		i2c->flags = FSL_I2C_DEV_CLOCK_5200;
+#else
 	i2c->irq = platform_get_irq(pdev, 0);
+	i2c->flags = pdata->device_flags;
+#endif
 	if (i2c->irq < 0) {
 		result = -ENXIO;
 		goto fail_get_irq;
 	}
-	i2c->flags = pdata->device_flags;
 	init_waitqueue_head(&i2c->queue);
 
 	i2c->base = ioremap((phys_addr_t)r->start, MPC_I2C_REGION);
@@ -325,11 +354,16 @@ static int fsl_i2c_probe(struct platform
 		}
 
 	mpc_i2c_setclock(i2c);
-	platform_set_drvdata(pdev, i2c);
 
 	i2c->adap = mpc_ops;
 	i2c_set_adapdata(&i2c->adap, i2c);
+#ifdef CONFIG_PPC_MERGE
+	dev_set_drvdata(&op->dev, i2c);
+	i2c->adap.dev.parent = &op->dev;
+#else
+	platform_set_drvdata(pdev, i2c);
 	i2c->adap.dev.parent = &pdev->dev;
+#endif
 	if ((result = i2c_add_adapter(&i2c->adap)) < 0) {
 		printk(KERN_ERR "i2c-mpc - failed to add adapter\n");
 		goto fail_add;
@@ -348,21 +382,54 @@ static int fsl_i2c_probe(struct platform
 	return result;
 };
 
+#ifdef CONFIG_PPC_MERGE
+static int fsl_i2c_remove(struct of_device *op)
+#else
 static int fsl_i2c_remove(struct platform_device *pdev)
+#endif
 {
+#ifdef CONFIG_PPC_MERGE
+	struct mpc_i2c *i2c = dev_get_drvdata(&op->dev);
+#else
 	struct mpc_i2c *i2c = platform_get_drvdata(pdev);
+#endif
 
 	i2c_del_adapter(&i2c->adap);
+#ifdef CONFIG_PPC_MERGE
+	dev_set_drvdata(&op->dev, NULL);
+#else
 	platform_set_drvdata(pdev, NULL);
+#endif
 
 	if (i2c->irq != 0)
 		free_irq(i2c->irq, i2c);
 
+#ifdef CONFIG_PPC_MERGE
+	irq_dispose_mapping(i2c->irq);
+#endif
 	iounmap(i2c->base);
 	kfree(i2c);
 	return 0;
 };
 
+#ifdef CONFIG_PPC_MERGE
+static struct of_device_id fsl_i2c_of_match[] = {
+	{ .compatible = "mpc5200-i2c", },
+	{},
+};
+
+static struct of_platform_driver fsl_i2c_driver = {
+	.name = "fsl-i2c",
+	.owner = THIS_MODULE,
+	.match_table = fsl_i2c_of_match,
+	.probe = fsl_i2c_probe,
+	.remove = fsl_i2c_remove,
+	.driver	= {
+		.name = "fsl-i2c",
+		.owner = THIS_MODULE,
+	},
+};
+#else
 /* Structure for a device driver */
 static struct platform_driver fsl_i2c_driver = {
 	.probe = fsl_i2c_probe,
@@ -372,15 +439,24 @@ static struct platform_driver fsl_i2c_dr
 		.name = "fsl-i2c",
 	},
 };
+#endif
 
 static int __init fsl_i2c_init(void)
 {
+#ifdef CONFIG_PPC_MERGE
+	return of_register_platform_driver(&fsl_i2c_driver);
+#else
 	return platform_driver_register(&fsl_i2c_driver);
+#endif
 }
 
 static void __exit fsl_i2c_exit(void)
 {
+#ifdef CONFIG_PPC_MERGE
+	of_unregister_platform_driver(&fsl_i2c_driver);
+#else
 	platform_driver_unregister(&fsl_i2c_driver);
+#endif
 }
 
 module_init(fsl_i2c_init);
next             reply	other threads:[~2007-03-02 10:56 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-02 10:47 Domen Puncer [this message]
2007-03-05 10:08 ` [PATCH alternative] lite5200(b) support for i2c Domen Puncer
2007-03-05 10:24   ` Sylvain Munaut
2007-03-05 10:40     ` [PATCH try3] " Domen Puncer
2007-03-05 10:53       ` Sylvain Munaut
2007-03-05 14:53         ` Kumar Gala
2007-03-05 14:55           ` Kumar Gala
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox
  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):
  git send-email \
    --in-reply-to=20070302104718.GU4397@moe.telargo.com \
    --to=domen.puncer@telargo.com \
    --cc=linuxppc-embedded@ozlabs.org \
    /path/to/YOUR_REPLY
  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
  Be sure your reply has a Subject: header at the top and a blank line
  before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).