aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c/busses
diff options
context:
space:
mode:
authorJonas Bonn <jonas@southpole.se>2010-11-24 11:26:20 -0500
committerBen Dooks <ben-linux@fluff.org>2011-01-03 20:04:18 -0500
commit049bb69d82e5f7f356949c1ae34a244b3338611b (patch)
treeb9bab46f25147de7740681d31c7cf239ec9567a4 /drivers/i2c/busses
parent03ed6a3aa600c48593c3984812fda2d5945ddb46 (diff)
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: Jonas Bonn <jonas@southpole.se> Signed-off-by: Ben Dooks <ben-linux@fluff.org>
Diffstat (limited to 'drivers/i2c/busses')
-rw-r--r--drivers/i2c/busses/i2c-ocores.c64
1 files changed, 56 insertions, 8 deletions
diff --git a/drivers/i2c/busses/i2c-ocores.c b/drivers/i2c/busses/i2c-ocores.c
index 0070371b29f3..c05e8c44404a 100644
--- a/drivers/i2c/busses/i2c-ocores.c
+++ b/drivers/i2c/busses/i2c-ocores.c
@@ -210,6 +210,32 @@ static struct i2c_adapter ocores_adapter = {
210 .algo = &ocores_algorithm, 210 .algo = &ocores_algorithm,
211}; 211};
212 212
213#ifdef CONFIG_OF
214static int ocores_i2c_of_probe(struct platform_device* pdev,
215 struct ocores_i2c* i2c)
216{
217 __be32* val;
218
219 val = of_get_property(pdev->dev.of_node, "regstep", NULL);
220 if (!val) {
221 dev_err(&pdev->dev, "Missing required parameter 'regstep'");
222 return -ENODEV;
223 }
224 i2c->regstep = be32_to_cpup(val);
225
226 val = of_get_property(pdev->dev.of_node, "clock-frequency", NULL);
227 if (!val) {
228 dev_err(&pdev->dev,
229 "Missing required parameter 'clock-frequency'");
230 return -ENODEV;
231 }
232 i2c->clock_khz = be32_to_cpup(val) / 1000;
233
234 return 0;
235}
236#else
237#define ocores_i2c_of_probe(pdev,i2c) -ENODEV
238#endif
213 239
214static int __devinit ocores_i2c_probe(struct platform_device *pdev) 240static int __devinit ocores_i2c_probe(struct platform_device *pdev)
215{ 241{
@@ -227,10 +253,6 @@ static int __devinit ocores_i2c_probe(struct platform_device *pdev)
227 if (!res2) 253 if (!res2)
228 return -ENODEV; 254 return -ENODEV;
229 255
230 pdata = (struct ocores_i2c_platform_data*) pdev->dev.platform_data;
231 if (!pdata)
232 return -ENODEV;
233
234 i2c = kzalloc(sizeof(*i2c), GFP_KERNEL); 256 i2c = kzalloc(sizeof(*i2c), GFP_KERNEL);
235 if (!i2c) 257 if (!i2c)
236 return -ENOMEM; 258 return -ENOMEM;
@@ -249,8 +271,16 @@ static int __devinit ocores_i2c_probe(struct platform_device *pdev)
249 goto map_failed; 271 goto map_failed;
250 } 272 }
251 273
252 i2c->regstep = pdata->regstep; 274 pdata = pdev->dev.platform_data;
253 i2c->clock_khz = pdata->clock_khz; 275 if (pdata) {
276 i2c->regstep = pdata->regstep;
277 i2c->clock_khz = pdata->clock_khz;
278 } else {
279 ret = ocores_i2c_of_probe(pdev, i2c);
280 if (ret)
281 return ret;
282 }
283
254 ocores_init(i2c); 284 ocores_init(i2c);
255 285
256 init_waitqueue_head(&i2c->wait); 286 init_waitqueue_head(&i2c->wait);
@@ -265,6 +295,9 @@ static int __devinit ocores_i2c_probe(struct platform_device *pdev)
265 i2c->adap = ocores_adapter; 295 i2c->adap = ocores_adapter;
266 i2c_set_adapdata(&i2c->adap, i2c); 296 i2c_set_adapdata(&i2c->adap, i2c);
267 i2c->adap.dev.parent = &pdev->dev; 297 i2c->adap.dev.parent = &pdev->dev;
298#ifdef CONFIG_OF
299 i2c->adap.dev.of_node = pdev->dev.of_node;
300#endif
268 301
269 /* add i2c adapter to i2c tree */ 302 /* add i2c adapter to i2c tree */
270 ret = i2c_add_adapter(&i2c->adap); 303 ret = i2c_add_adapter(&i2c->adap);
@@ -274,8 +307,10 @@ static int __devinit ocores_i2c_probe(struct platform_device *pdev)
274 } 307 }
275 308
276 /* add in known devices to the bus */ 309 /* add in known devices to the bus */
277 for (i = 0; i < pdata->num_devices; i++) 310 if (pdata) {
278 i2c_new_device(&i2c->adap, pdata->devices + i); 311 for (i = 0; i < pdata->num_devices; i++)
312 i2c_new_device(&i2c->adap, pdata->devices + i);
313 }
279 314
280 return 0; 315 return 0;
281 316
@@ -344,6 +379,16 @@ static int ocores_i2c_resume(struct platform_device *pdev)
344#define ocores_i2c_resume NULL 379#define ocores_i2c_resume NULL
345#endif 380#endif
346 381
382#ifdef CONFIG_OF
383static struct of_device_id ocores_i2c_match[] = {
384 {
385 .compatible = "opencores,i2c-ocores",
386 },
387 {},
388};
389MODULE_DEVICE_TABLE(of, ocores_i2c_match);
390#endif
391
347/* work with hotplug and coldplug */ 392/* work with hotplug and coldplug */
348MODULE_ALIAS("platform:ocores-i2c"); 393MODULE_ALIAS("platform:ocores-i2c");
349 394
@@ -355,6 +400,9 @@ static struct platform_driver ocores_i2c_driver = {
355 .driver = { 400 .driver = {
356 .owner = THIS_MODULE, 401 .owner = THIS_MODULE,
357 .name = "ocores-i2c", 402 .name = "ocores-i2c",
403#ifdef CONFIG_OF
404 .of_match_table = ocores_i2c_match,
405#endif
358 }, 406 },
359}; 407};
360 408