提交 049bb69d 编写于 作者: J Jonas Bonn 提交者: Ben Dooks

i2c-ocores: Adapt for device tree

This patch adapts the i2c-ocores driver for being defined and configured via
a device tree description.

The device tree bits need to be protected by CONFIG_OF guards as this is
still an optional feature.
Signed-off-by: NJonas Bonn <jonas@southpole.se>
Signed-off-by: NBen Dooks <ben-linux@fluff.org>
上级 03ed6a3a
...@@ -210,6 +210,32 @@ static struct i2c_adapter ocores_adapter = { ...@@ -210,6 +210,32 @@ static struct i2c_adapter ocores_adapter = {
.algo = &ocores_algorithm, .algo = &ocores_algorithm,
}; };
#ifdef CONFIG_OF
static int ocores_i2c_of_probe(struct platform_device* pdev,
struct ocores_i2c* i2c)
{
__be32* val;
val = of_get_property(pdev->dev.of_node, "regstep", NULL);
if (!val) {
dev_err(&pdev->dev, "Missing required parameter 'regstep'");
return -ENODEV;
}
i2c->regstep = be32_to_cpup(val);
val = of_get_property(pdev->dev.of_node, "clock-frequency", NULL);
if (!val) {
dev_err(&pdev->dev,
"Missing required parameter 'clock-frequency'");
return -ENODEV;
}
i2c->clock_khz = be32_to_cpup(val) / 1000;
return 0;
}
#else
#define ocores_i2c_of_probe(pdev,i2c) -ENODEV
#endif
static int __devinit ocores_i2c_probe(struct platform_device *pdev) static int __devinit ocores_i2c_probe(struct platform_device *pdev)
{ {
...@@ -227,10 +253,6 @@ static int __devinit ocores_i2c_probe(struct platform_device *pdev) ...@@ -227,10 +253,6 @@ static int __devinit ocores_i2c_probe(struct platform_device *pdev)
if (!res2) if (!res2)
return -ENODEV; return -ENODEV;
pdata = (struct ocores_i2c_platform_data*) pdev->dev.platform_data;
if (!pdata)
return -ENODEV;
i2c = kzalloc(sizeof(*i2c), GFP_KERNEL); i2c = kzalloc(sizeof(*i2c), GFP_KERNEL);
if (!i2c) if (!i2c)
return -ENOMEM; return -ENOMEM;
...@@ -249,8 +271,16 @@ static int __devinit ocores_i2c_probe(struct platform_device *pdev) ...@@ -249,8 +271,16 @@ static int __devinit ocores_i2c_probe(struct platform_device *pdev)
goto map_failed; goto map_failed;
} }
pdata = pdev->dev.platform_data;
if (pdata) {
i2c->regstep = pdata->regstep; i2c->regstep = pdata->regstep;
i2c->clock_khz = pdata->clock_khz; i2c->clock_khz = pdata->clock_khz;
} else {
ret = ocores_i2c_of_probe(pdev, i2c);
if (ret)
return ret;
}
ocores_init(i2c); ocores_init(i2c);
init_waitqueue_head(&i2c->wait); init_waitqueue_head(&i2c->wait);
...@@ -265,6 +295,9 @@ static int __devinit ocores_i2c_probe(struct platform_device *pdev) ...@@ -265,6 +295,9 @@ static int __devinit ocores_i2c_probe(struct platform_device *pdev)
i2c->adap = ocores_adapter; i2c->adap = ocores_adapter;
i2c_set_adapdata(&i2c->adap, i2c); i2c_set_adapdata(&i2c->adap, i2c);
i2c->adap.dev.parent = &pdev->dev; i2c->adap.dev.parent = &pdev->dev;
#ifdef CONFIG_OF
i2c->adap.dev.of_node = pdev->dev.of_node;
#endif
/* add i2c adapter to i2c tree */ /* add i2c adapter to i2c tree */
ret = i2c_add_adapter(&i2c->adap); ret = i2c_add_adapter(&i2c->adap);
...@@ -274,8 +307,10 @@ static int __devinit ocores_i2c_probe(struct platform_device *pdev) ...@@ -274,8 +307,10 @@ static int __devinit ocores_i2c_probe(struct platform_device *pdev)
} }
/* add in known devices to the bus */ /* add in known devices to the bus */
if (pdata) {
for (i = 0; i < pdata->num_devices; i++) for (i = 0; i < pdata->num_devices; i++)
i2c_new_device(&i2c->adap, pdata->devices + i); i2c_new_device(&i2c->adap, pdata->devices + i);
}
return 0; return 0;
...@@ -344,6 +379,16 @@ static int ocores_i2c_resume(struct platform_device *pdev) ...@@ -344,6 +379,16 @@ static int ocores_i2c_resume(struct platform_device *pdev)
#define ocores_i2c_resume NULL #define ocores_i2c_resume NULL
#endif #endif
#ifdef CONFIG_OF
static struct of_device_id ocores_i2c_match[] = {
{
.compatible = "opencores,i2c-ocores",
},
{},
};
MODULE_DEVICE_TABLE(of, ocores_i2c_match);
#endif
/* work with hotplug and coldplug */ /* work with hotplug and coldplug */
MODULE_ALIAS("platform:ocores-i2c"); MODULE_ALIAS("platform:ocores-i2c");
...@@ -355,6 +400,9 @@ static struct platform_driver ocores_i2c_driver = { ...@@ -355,6 +400,9 @@ static struct platform_driver ocores_i2c_driver = {
.driver = { .driver = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.name = "ocores-i2c", .name = "ocores-i2c",
#ifdef CONFIG_OF
.of_match_table = ocores_i2c_match,
#endif
}, },
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册