diff options
author | Shawn Guo <shawn.guo@linaro.org> | 2011-09-08 03:09:35 -0400 |
---|---|---|
committer | Ben Dooks <ben-linux@fluff.org> | 2011-09-14 17:16:14 -0400 |
commit | dfcd04b19d16c0016c705ed96a8b3cfa5315a2e9 (patch) | |
tree | 8053f44b44ee36faa97ede5914eca19fbb1ed123 | |
parent | 593702c71a415b153bd81fbc487394979f3e7a63 (diff) |
i2c-imx: add device tree probe support
It adds device tree probe support for i2c-imx driver.
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
Cc: Grant Likely <grant.likely@secretlab.ca>
Cc: Darius Augulis <augulis.darius@gmail.com>
Cc: Ben Dooks <ben-linux@fluff.org>
Acked-by: Grant Likely <grant.likely@secretlab.ca>
Signed-off-by: Ben Dooks <ben-linux@fluff.org>
-rw-r--r-- | Documentation/devicetree/bindings/i2c/fsl-imx-i2c.txt | 25 | ||||
-rw-r--r-- | drivers/i2c/busses/i2c-imx.c | 25 |
2 files changed, 44 insertions, 6 deletions
diff --git a/Documentation/devicetree/bindings/i2c/fsl-imx-i2c.txt b/Documentation/devicetree/bindings/i2c/fsl-imx-i2c.txt new file mode 100644 index 000000000000..f3cf43b66f7e --- /dev/null +++ b/Documentation/devicetree/bindings/i2c/fsl-imx-i2c.txt | |||
@@ -0,0 +1,25 @@ | |||
1 | * Freescale Inter IC (I2C) and High Speed Inter IC (HS-I2C) for i.MX | ||
2 | |||
3 | Required properties: | ||
4 | - compatible : Should be "fsl,<chip>-i2c" | ||
5 | - reg : Should contain I2C/HS-I2C registers location and length | ||
6 | - interrupts : Should contain I2C/HS-I2C interrupt | ||
7 | |||
8 | Optional properties: | ||
9 | - clock-frequency : Constains desired I2C/HS-I2C bus clock frequency in Hz. | ||
10 | The absence of the propoerty indicates the default frequency 100 kHz. | ||
11 | |||
12 | Examples: | ||
13 | |||
14 | i2c@83fc4000 { /* I2C2 on i.MX51 */ | ||
15 | compatible = "fsl,imx51-i2c", "fsl,imx1-i2c"; | ||
16 | reg = <0x83fc4000 0x4000>; | ||
17 | interrupts = <63>; | ||
18 | }; | ||
19 | |||
20 | i2c@70038000 { /* HS-I2C on i.MX51 */ | ||
21 | compatible = "fsl,imx51-i2c", "fsl,imx1-i2c"; | ||
22 | reg = <0x70038000 0x4000>; | ||
23 | interrupts = <64>; | ||
24 | clock-frequency = <400000>; | ||
25 | }; | ||
diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c index 54d809ed20be..58832e578fff 100644 --- a/drivers/i2c/busses/i2c-imx.c +++ b/drivers/i2c/busses/i2c-imx.c | |||
@@ -48,6 +48,9 @@ | |||
48 | #include <linux/platform_device.h> | 48 | #include <linux/platform_device.h> |
49 | #include <linux/clk.h> | 49 | #include <linux/clk.h> |
50 | #include <linux/slab.h> | 50 | #include <linux/slab.h> |
51 | #include <linux/of.h> | ||
52 | #include <linux/of_device.h> | ||
53 | #include <linux/of_i2c.h> | ||
51 | 54 | ||
52 | #include <mach/irqs.h> | 55 | #include <mach/irqs.h> |
53 | #include <mach/hardware.h> | 56 | #include <mach/hardware.h> |
@@ -125,6 +128,11 @@ struct imx_i2c_struct { | |||
125 | unsigned int ifdr; /* IMX_I2C_IFDR */ | 128 | unsigned int ifdr; /* IMX_I2C_IFDR */ |
126 | }; | 129 | }; |
127 | 130 | ||
131 | static const struct of_device_id i2c_imx_dt_ids[] = { | ||
132 | { .compatible = "fsl,imx1-i2c", }, | ||
133 | { /* sentinel */ } | ||
134 | }; | ||
135 | |||
128 | /** Functions for IMX I2C adapter driver *************************************** | 136 | /** Functions for IMX I2C adapter driver *************************************** |
129 | *******************************************************************************/ | 137 | *******************************************************************************/ |
130 | 138 | ||
@@ -469,7 +477,7 @@ static int __init i2c_imx_probe(struct platform_device *pdev) | |||
469 | struct imxi2c_platform_data *pdata = pdev->dev.platform_data; | 477 | struct imxi2c_platform_data *pdata = pdev->dev.platform_data; |
470 | void __iomem *base; | 478 | void __iomem *base; |
471 | resource_size_t res_size; | 479 | resource_size_t res_size; |
472 | int irq; | 480 | int irq, bitrate; |
473 | int ret; | 481 | int ret; |
474 | 482 | ||
475 | dev_dbg(&pdev->dev, "<%s>\n", __func__); | 483 | dev_dbg(&pdev->dev, "<%s>\n", __func__); |
@@ -512,6 +520,7 @@ static int __init i2c_imx_probe(struct platform_device *pdev) | |||
512 | i2c_imx->adapter.algo = &i2c_imx_algo; | 520 | i2c_imx->adapter.algo = &i2c_imx_algo; |
513 | i2c_imx->adapter.dev.parent = &pdev->dev; | 521 | i2c_imx->adapter.dev.parent = &pdev->dev; |
514 | i2c_imx->adapter.nr = pdev->id; | 522 | i2c_imx->adapter.nr = pdev->id; |
523 | i2c_imx->adapter.dev.of_node = pdev->dev.of_node; | ||
515 | i2c_imx->irq = irq; | 524 | i2c_imx->irq = irq; |
516 | i2c_imx->base = base; | 525 | i2c_imx->base = base; |
517 | i2c_imx->res = res; | 526 | i2c_imx->res = res; |
@@ -538,10 +547,12 @@ static int __init i2c_imx_probe(struct platform_device *pdev) | |||
538 | i2c_set_adapdata(&i2c_imx->adapter, i2c_imx); | 547 | i2c_set_adapdata(&i2c_imx->adapter, i2c_imx); |
539 | 548 | ||
540 | /* Set up clock divider */ | 549 | /* Set up clock divider */ |
541 | if (pdata && pdata->bitrate) | 550 | bitrate = IMX_I2C_BIT_RATE; |
542 | i2c_imx_set_clk(i2c_imx, pdata->bitrate); | 551 | ret = of_property_read_u32(pdev->dev.of_node, |
543 | else | 552 | "clock-frequency", &bitrate); |
544 | i2c_imx_set_clk(i2c_imx, IMX_I2C_BIT_RATE); | 553 | if (ret < 0 && pdata && pdata->bitrate) |
554 | bitrate = pdata->bitrate; | ||
555 | i2c_imx_set_clk(i2c_imx, bitrate); | ||
545 | 556 | ||
546 | /* Set up chip registers to defaults */ | 557 | /* Set up chip registers to defaults */ |
547 | writeb(0, i2c_imx->base + IMX_I2C_I2CR); | 558 | writeb(0, i2c_imx->base + IMX_I2C_I2CR); |
@@ -554,6 +565,8 @@ static int __init i2c_imx_probe(struct platform_device *pdev) | |||
554 | goto fail5; | 565 | goto fail5; |
555 | } | 566 | } |
556 | 567 | ||
568 | of_i2c_register_devices(&i2c_imx->adapter); | ||
569 | |||
557 | /* Set up platform driver data */ | 570 | /* Set up platform driver data */ |
558 | platform_set_drvdata(pdev, i2c_imx); | 571 | platform_set_drvdata(pdev, i2c_imx); |
559 | 572 | ||
@@ -584,7 +597,6 @@ fail1: | |||
584 | static int __exit i2c_imx_remove(struct platform_device *pdev) | 597 | static int __exit i2c_imx_remove(struct platform_device *pdev) |
585 | { | 598 | { |
586 | struct imx_i2c_struct *i2c_imx = platform_get_drvdata(pdev); | 599 | struct imx_i2c_struct *i2c_imx = platform_get_drvdata(pdev); |
587 | struct imxi2c_platform_data *pdata = pdev->dev.platform_data; | ||
588 | 600 | ||
589 | /* remove adapter */ | 601 | /* remove adapter */ |
590 | dev_dbg(&i2c_imx->adapter.dev, "adapter removed\n"); | 602 | dev_dbg(&i2c_imx->adapter.dev, "adapter removed\n"); |
@@ -613,6 +625,7 @@ static struct platform_driver i2c_imx_driver = { | |||
613 | .driver = { | 625 | .driver = { |
614 | .name = DRIVER_NAME, | 626 | .name = DRIVER_NAME, |
615 | .owner = THIS_MODULE, | 627 | .owner = THIS_MODULE, |
628 | .of_match_table = i2c_imx_dt_ids, | ||
616 | } | 629 | } |
617 | }; | 630 | }; |
618 | 631 | ||