Commit dfcd04b1 authored by Shawn Guo's avatar Shawn Guo Committed by Ben Dooks

i2c-imx: add device tree probe support

It adds device tree probe support for i2c-imx driver.
Signed-off-by: default avatarShawn 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: default avatarGrant Likely <grant.likely@secretlab.ca>
Signed-off-by: default avatarBen Dooks <ben-linux@fluff.org>
parent 593702c7
* Freescale Inter IC (I2C) and High Speed Inter IC (HS-I2C) for i.MX
Required properties:
- compatible : Should be "fsl,<chip>-i2c"
- reg : Should contain I2C/HS-I2C registers location and length
- interrupts : Should contain I2C/HS-I2C interrupt
Optional properties:
- clock-frequency : Constains desired I2C/HS-I2C bus clock frequency in Hz.
The absence of the propoerty indicates the default frequency 100 kHz.
Examples:
i2c@83fc4000 { /* I2C2 on i.MX51 */
compatible = "fsl,imx51-i2c", "fsl,imx1-i2c";
reg = <0x83fc4000 0x4000>;
interrupts = <63>;
};
i2c@70038000 { /* HS-I2C on i.MX51 */
compatible = "fsl,imx51-i2c", "fsl,imx1-i2c";
reg = <0x70038000 0x4000>;
interrupts = <64>;
clock-frequency = <400000>;
};
...@@ -48,6 +48,9 @@ ...@@ -48,6 +48,9 @@
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/of.h>
#include <linux/of_device.h>
#include <linux/of_i2c.h>
#include <mach/irqs.h> #include <mach/irqs.h>
#include <mach/hardware.h> #include <mach/hardware.h>
...@@ -125,6 +128,11 @@ struct imx_i2c_struct { ...@@ -125,6 +128,11 @@ struct imx_i2c_struct {
unsigned int ifdr; /* IMX_I2C_IFDR */ unsigned int ifdr; /* IMX_I2C_IFDR */
}; };
static const struct of_device_id i2c_imx_dt_ids[] = {
{ .compatible = "fsl,imx1-i2c", },
{ /* sentinel */ }
};
/** Functions for IMX I2C adapter driver *************************************** /** Functions for IMX I2C adapter driver ***************************************
*******************************************************************************/ *******************************************************************************/
...@@ -469,7 +477,7 @@ static int __init i2c_imx_probe(struct platform_device *pdev) ...@@ -469,7 +477,7 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
struct imxi2c_platform_data *pdata = pdev->dev.platform_data; struct imxi2c_platform_data *pdata = pdev->dev.platform_data;
void __iomem *base; void __iomem *base;
resource_size_t res_size; resource_size_t res_size;
int irq; int irq, bitrate;
int ret; int ret;
dev_dbg(&pdev->dev, "<%s>\n", __func__); dev_dbg(&pdev->dev, "<%s>\n", __func__);
...@@ -512,6 +520,7 @@ static int __init i2c_imx_probe(struct platform_device *pdev) ...@@ -512,6 +520,7 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
i2c_imx->adapter.algo = &i2c_imx_algo; i2c_imx->adapter.algo = &i2c_imx_algo;
i2c_imx->adapter.dev.parent = &pdev->dev; i2c_imx->adapter.dev.parent = &pdev->dev;
i2c_imx->adapter.nr = pdev->id; i2c_imx->adapter.nr = pdev->id;
i2c_imx->adapter.dev.of_node = pdev->dev.of_node;
i2c_imx->irq = irq; i2c_imx->irq = irq;
i2c_imx->base = base; i2c_imx->base = base;
i2c_imx->res = res; i2c_imx->res = res;
...@@ -538,10 +547,12 @@ static int __init i2c_imx_probe(struct platform_device *pdev) ...@@ -538,10 +547,12 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
i2c_set_adapdata(&i2c_imx->adapter, i2c_imx); i2c_set_adapdata(&i2c_imx->adapter, i2c_imx);
/* Set up clock divider */ /* Set up clock divider */
if (pdata && pdata->bitrate) bitrate = IMX_I2C_BIT_RATE;
i2c_imx_set_clk(i2c_imx, pdata->bitrate); ret = of_property_read_u32(pdev->dev.of_node,
else "clock-frequency", &bitrate);
i2c_imx_set_clk(i2c_imx, IMX_I2C_BIT_RATE); if (ret < 0 && pdata && pdata->bitrate)
bitrate = pdata->bitrate;
i2c_imx_set_clk(i2c_imx, bitrate);
/* Set up chip registers to defaults */ /* Set up chip registers to defaults */
writeb(0, i2c_imx->base + IMX_I2C_I2CR); writeb(0, i2c_imx->base + IMX_I2C_I2CR);
...@@ -554,6 +565,8 @@ static int __init i2c_imx_probe(struct platform_device *pdev) ...@@ -554,6 +565,8 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
goto fail5; goto fail5;
} }
of_i2c_register_devices(&i2c_imx->adapter);
/* Set up platform driver data */ /* Set up platform driver data */
platform_set_drvdata(pdev, i2c_imx); platform_set_drvdata(pdev, i2c_imx);
...@@ -584,7 +597,6 @@ static int __init i2c_imx_probe(struct platform_device *pdev) ...@@ -584,7 +597,6 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
static int __exit i2c_imx_remove(struct platform_device *pdev) static int __exit i2c_imx_remove(struct platform_device *pdev)
{ {
struct imx_i2c_struct *i2c_imx = platform_get_drvdata(pdev); struct imx_i2c_struct *i2c_imx = platform_get_drvdata(pdev);
struct imxi2c_platform_data *pdata = pdev->dev.platform_data;
/* remove adapter */ /* remove adapter */
dev_dbg(&i2c_imx->adapter.dev, "adapter removed\n"); dev_dbg(&i2c_imx->adapter.dev, "adapter removed\n");
...@@ -613,6 +625,7 @@ static struct platform_driver i2c_imx_driver = { ...@@ -613,6 +625,7 @@ static struct platform_driver i2c_imx_driver = {
.driver = { .driver = {
.name = DRIVER_NAME, .name = DRIVER_NAME,
.owner = THIS_MODULE, .owner = THIS_MODULE,
.of_match_table = i2c_imx_dt_ids,
} }
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment