From: "Raphaël Poggi" <poggi.raph@gmail.com>
To: barebox@lists.infradead.org
Cc: "Raphaël Poggi" <poggi.raph@gmail.com>
Subject: [PATCH V2 1/2] i2c: at91: add support of device tree
Date: Mon, 4 Aug 2014 10:31:51 +0200 [thread overview]
Message-ID: <1407141112-3868-2-git-send-email-poggi.raph@gmail.com> (raw)
In-Reply-To: <1407141112-3868-1-git-send-email-poggi.raph@gmail.com>
Signed-off-by: Raphaël Poggi <poggi.raph@gmail.com>
---
drivers/i2c/busses/i2c-at91.c | 66 ++++++++++++++++++++++++++++++++++++-----
1 file changed, 58 insertions(+), 8 deletions(-)
diff --git a/drivers/i2c/busses/i2c-at91.c b/drivers/i2c/busses/i2c-at91.c
index 399f6a9..944a8b3 100644
--- a/drivers/i2c/busses/i2c-at91.c
+++ b/drivers/i2c/busses/i2c-at91.c
@@ -346,6 +346,12 @@ static struct at91_twi_pdata at91sam9g10_config = {
.has_unre_flag = false,
};
+static struct at91_twi_pdata at91sam9x5_config = {
+ .clk_max_div = 7,
+ .clk_offset = 4,
+ .has_unre_flag = false,
+};
+
static struct platform_device_id at91_twi_devtypes[] = {
{
.name = "i2c-at91rm9200",
@@ -367,20 +373,63 @@ static struct platform_device_id at91_twi_devtypes[] = {
}
};
+static struct of_device_id at91_twi_dt_ids[] = {
+ {
+ .compatible = "atmel,at91rm9200-i2c",
+ .data = (unsigned long) &at91rm9200_config,
+ } , {
+ .compatible = "atmel,at91sam9260-i2c",
+ .data = (unsigned long) &at91sam9260_config,
+ } , {
+ .compatible = "atmel,at91sam9261-i2c",
+ .data = (unsigned long) &at91sam9261_config,
+ } , {
+ .compatible = "atmel,at91sam9g20-i2c",
+ .data = (unsigned long) &at91sam9g20_config,
+ } , {
+ .compatible = "atmel,at91sam9g10-i2c",
+ .data = (unsigned long) &at91sam9g10_config,
+ }, {
+ .compatible = "atmel,at91sam9x5-i2c",
+ .data = (unsigned long) &at91sam9x5_config,
+ }, {
+ /* sentinel */
+ }
+};
+
+static struct at91_twi_pdata *at91_twi_get_driver_data(struct device_d *dev)
+{
+ struct at91_twi_pdata *i2c_data = NULL;
+ int rc;
+
+ if (dev->device_node) {
+ const struct of_device_id *match;
+ match = of_match_node(at91_twi_dt_ids, dev->device_node);
+ if (!match)
+ i2c_data = NULL;
+ else
+ i2c_data = (struct at91_twi_pdata *)match->data;
+ }
+ else {
+ rc = dev_get_drvdata(dev, (unsigned long *)&i2c_data);
+ if (rc)
+ i2c_data = NULL;
+ }
+
+ return i2c_data;
+}
+
static int at91_twi_probe(struct device_d *dev)
{
struct at91_twi_dev *i2c_at91;
- struct at91_twi_pdata *i2c_data;
- int rc;
+ int rc = 0;
u32 bus_clk_rate;
i2c_at91 = xzalloc(sizeof(struct at91_twi_dev));
- rc = dev_get_drvdata(dev, (unsigned long *)&i2c_data);
- if (rc)
- goto out_free;
-
- i2c_at91->pdata = i2c_data;
+ i2c_at91->pdata = at91_twi_get_driver_data(dev);
+ if (!i2c_at91->pdata)
+ goto out_free;
i2c_at91->base = dev_request_mem_region(dev, 0);
if (!i2c_at91->base) {
@@ -389,7 +438,7 @@ static int at91_twi_probe(struct device_d *dev)
goto out_free;
}
- i2c_at91->clk = clk_get(dev, "twi_clk");
+ i2c_at91->clk = clk_get(dev, NULL);
if (IS_ERR(i2c_at91->clk)) {
dev_err(dev, "no clock defined\n");
rc = -ENODEV;
@@ -429,6 +478,7 @@ static struct driver_d at91_twi_driver = {
.name = "at91-twi",
.probe = at91_twi_probe,
.id_table = at91_twi_devtypes,
+ .of_compatible = DRV_OF_COMPAT(at91_twi_dt_ids),
};
device_platform_driver(at91_twi_driver);
--
1.7.9.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2014-08-04 8:31 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-04 8:31 [PATCH V2 0/2] Add device tree support of i2c Atmel driver Raphaël Poggi
2014-08-04 8:31 ` Raphaël Poggi [this message]
2014-08-04 9:14 ` [PATCH V2 1/2] i2c: at91: add support of device tree Bo Shen
2014-08-04 9:42 ` Raphaël Poggi
2014-08-04 9:50 ` Bo Shen
2014-08-04 8:31 ` [PATCH V2 2/2] at91sam9g45: clock: add i2c clocks Raphaël Poggi
2014-08-04 9:17 ` Bo Shen
2014-08-04 9:28 ` Raphaël Poggi
2014-08-04 9:11 ` [PATCH V2 0/2] Add device tree support of i2c Atmel driver Bo Shen
2014-08-04 9:22 ` Raphaël Poggi
2014-08-04 9:29 ` Bo Shen
2014-08-05 6:55 ` Bo Shen
2014-08-05 8:32 ` Raphaël Poggi
2014-08-05 20:05 ` Raphaël Poggi
2014-08-06 1:06 ` Bo Shen
2014-08-06 7:16 ` Raphaël Poggi
2014-08-06 7:33 ` Bo Shen
2014-08-06 7:40 ` Raphaël Poggi
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=1407141112-3868-2-git-send-email-poggi.raph@gmail.com \
--to=poggi.raph@gmail.com \
--cc=barebox@lists.infradead.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