aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c
diff options
context:
space:
mode:
authorJon Smirl <jonsmirl@gmail.com>2008-06-30 19:01:26 -0400
committerGrant Likely <grant.likely@secretlab.ca>2008-07-12 14:10:23 -0400
commit0d1cde235874b00905bce23f659690d060ebf475 (patch)
tree918cad848eb4d85a3ac909666b5639ff618b2bdc /drivers/i2c
parent6eb9d32298290b956693fd85c815b817d39a9505 (diff)
powerpc/i2c: Convert i2c-mpc into an of_platform driver
Convert i2c-mpc to an of_platform driver. Utilize the code in drivers/of-i2c.c to make i2c modules dynamically loadable by the device tree. Signed-off-by: Jon Smirl <jonsmirl@gmail.com> Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Diffstat (limited to 'drivers/i2c')
-rw-r--r--drivers/i2c/busses/i2c-mpc.c104
1 files changed, 60 insertions, 44 deletions
diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c
index a076129de7e8..4fdfb62d6f38 100644
--- a/drivers/i2c/busses/i2c-mpc.c
+++ b/drivers/i2c/busses/i2c-mpc.c
@@ -17,7 +17,8 @@
17#include <linux/module.h> 17#include <linux/module.h>
18#include <linux/sched.h> 18#include <linux/sched.h>
19#include <linux/init.h> 19#include <linux/init.h>
20#include <linux/platform_device.h> 20#include <linux/of_platform.h>
21#include <linux/of_i2c.h>
21 22
22#include <asm/io.h> 23#include <asm/io.h>
23#include <linux/fsl_devices.h> 24#include <linux/fsl_devices.h>
@@ -25,13 +26,13 @@
25#include <linux/interrupt.h> 26#include <linux/interrupt.h>
26#include <linux/delay.h> 27#include <linux/delay.h>
27 28
28#define MPC_I2C_ADDR 0x00 29#define DRV_NAME "mpc-i2c"
30
29#define MPC_I2C_FDR 0x04 31#define MPC_I2C_FDR 0x04
30#define MPC_I2C_CR 0x08 32#define MPC_I2C_CR 0x08
31#define MPC_I2C_SR 0x0c 33#define MPC_I2C_SR 0x0c
32#define MPC_I2C_DR 0x10 34#define MPC_I2C_DR 0x10
33#define MPC_I2C_DFSRR 0x14 35#define MPC_I2C_DFSRR 0x14
34#define MPC_I2C_REGION 0x20
35 36
36#define CCR_MEN 0x80 37#define CCR_MEN 0x80
37#define CCR_MIEN 0x40 38#define CCR_MIEN 0x40
@@ -315,102 +316,117 @@ static struct i2c_adapter mpc_ops = {
315 .timeout = 1, 316 .timeout = 1,
316}; 317};
317 318
318static int fsl_i2c_probe(struct platform_device *pdev) 319static int __devinit fsl_i2c_probe(struct of_device *op, const struct of_device_id *match)
319{ 320{
320 int result = 0; 321 int result = 0;
321 struct mpc_i2c *i2c; 322 struct mpc_i2c *i2c;
322 struct fsl_i2c_platform_data *pdata;
323 struct resource *r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
324
325 pdata = (struct fsl_i2c_platform_data *) pdev->dev.platform_data;
326 323
327 i2c = kzalloc(sizeof(*i2c), GFP_KERNEL); 324 i2c = kzalloc(sizeof(*i2c), GFP_KERNEL);
328 if (!i2c) 325 if (!i2c)
329 return -ENOMEM; 326 return -ENOMEM;
330 327
331 i2c->irq = platform_get_irq(pdev, 0); 328 if (of_get_property(op->node, "dfsrr", NULL))
332 if (i2c->irq < 0) 329 i2c->flags |= FSL_I2C_DEV_SEPARATE_DFSRR;
333 i2c->irq = NO_IRQ; /* Use polling */
334 330
335 i2c->flags = pdata->device_flags; 331 if (of_device_is_compatible(op->node, "fsl,mpc5200-i2c") ||
336 init_waitqueue_head(&i2c->queue); 332 of_device_is_compatible(op->node, "mpc5200-i2c"))
333 i2c->flags |= FSL_I2C_DEV_CLOCK_5200;
337 334
338 i2c->base = ioremap((phys_addr_t)r->start, MPC_I2C_REGION); 335 init_waitqueue_head(&i2c->queue);
339 336
337 i2c->base = of_iomap(op->node, 0);
340 if (!i2c->base) { 338 if (!i2c->base) {
341 printk(KERN_ERR "i2c-mpc - failed to map controller\n"); 339 printk(KERN_ERR "i2c-mpc - failed to map controller\n");
342 result = -ENOMEM; 340 result = -ENOMEM;
343 goto fail_map; 341 goto fail_map;
344 } 342 }
345 343
346 if (i2c->irq != NO_IRQ) 344 i2c->irq = irq_of_parse_and_map(op->node, 0);
347 if ((result = request_irq(i2c->irq, mpc_i2c_isr, 345 if (i2c->irq != NO_IRQ) { /* i2c->irq = NO_IRQ implies polling */
348 IRQF_SHARED, "i2c-mpc", i2c)) < 0) { 346 result = request_irq(i2c->irq, mpc_i2c_isr,
349 printk(KERN_ERR 347 IRQF_SHARED, "i2c-mpc", i2c);
350 "i2c-mpc - failed to attach interrupt\n"); 348 if (result < 0) {
351 goto fail_irq; 349 printk(KERN_ERR "i2c-mpc - failed to attach interrupt\n");
350 goto fail_request;
352 } 351 }
353 352 }
353
354 mpc_i2c_setclock(i2c); 354 mpc_i2c_setclock(i2c);
355 platform_set_drvdata(pdev, i2c); 355
356 dev_set_drvdata(&op->dev, i2c);
356 357
357 i2c->adap = mpc_ops; 358 i2c->adap = mpc_ops;
358 i2c->adap.nr = pdev->id;
359 i2c_set_adapdata(&i2c->adap, i2c); 359 i2c_set_adapdata(&i2c->adap, i2c);
360 i2c->adap.dev.parent = &pdev->dev; 360 i2c->adap.dev.parent = &op->dev;
361 if ((result = i2c_add_numbered_adapter(&i2c->adap)) < 0) { 361
362 result = i2c_add_adapter(&i2c->adap);
363 if (result < 0) {
362 printk(KERN_ERR "i2c-mpc - failed to add adapter\n"); 364 printk(KERN_ERR "i2c-mpc - failed to add adapter\n");
363 goto fail_add; 365 goto fail_add;
364 } 366 }
367 of_register_i2c_devices(&i2c->adap, op->node);
365 368
366 return result; 369 return result;
367 370
368 fail_add: 371 fail_add:
369 if (i2c->irq != NO_IRQ) 372 dev_set_drvdata(&op->dev, NULL);
370 free_irq(i2c->irq, i2c); 373 free_irq(i2c->irq, i2c);
371 fail_irq: 374 fail_request:
372 iounmap(i2c->base); 375 irq_dispose_mapping(i2c->irq);
373 fail_map: 376 iounmap(i2c->base);
377 fail_map:
374 kfree(i2c); 378 kfree(i2c);
375 return result; 379 return result;
376}; 380};
377 381
378static int fsl_i2c_remove(struct platform_device *pdev) 382static int __devexit fsl_i2c_remove(struct of_device *op)
379{ 383{
380 struct mpc_i2c *i2c = platform_get_drvdata(pdev); 384 struct mpc_i2c *i2c = dev_get_drvdata(&op->dev);
381 385
382 i2c_del_adapter(&i2c->adap); 386 i2c_del_adapter(&i2c->adap);
383 platform_set_drvdata(pdev, NULL); 387 dev_set_drvdata(&op->dev, NULL);
384 388
385 if (i2c->irq != NO_IRQ) 389 if (i2c->irq != NO_IRQ)
386 free_irq(i2c->irq, i2c); 390 free_irq(i2c->irq, i2c);
387 391
392 irq_dispose_mapping(i2c->irq);
388 iounmap(i2c->base); 393 iounmap(i2c->base);
389 kfree(i2c); 394 kfree(i2c);
390 return 0; 395 return 0;
391}; 396};
392 397
393/* work with hotplug and coldplug */ 398static const struct of_device_id mpc_i2c_of_match[] = {
394MODULE_ALIAS("platform:fsl-i2c"); 399 {.compatible = "fsl-i2c",},
400 {},
401};
402MODULE_DEVICE_TABLE(of, mpc_i2c_of_match);
403
395 404
396/* Structure for a device driver */ 405/* Structure for a device driver */
397static struct platform_driver fsl_i2c_driver = { 406static struct of_platform_driver mpc_i2c_driver = {
398 .probe = fsl_i2c_probe, 407 .match_table = mpc_i2c_of_match,
399 .remove = fsl_i2c_remove, 408 .probe = fsl_i2c_probe,
400 .driver = { 409 .remove = __devexit_p(fsl_i2c_remove),
401 .owner = THIS_MODULE, 410 .driver = {
402 .name = "fsl-i2c", 411 .owner = THIS_MODULE,
412 .name = DRV_NAME,
403 }, 413 },
404}; 414};
405 415
406static int __init fsl_i2c_init(void) 416static int __init fsl_i2c_init(void)
407{ 417{
408 return platform_driver_register(&fsl_i2c_driver); 418 int rv;
419
420 rv = of_register_platform_driver(&mpc_i2c_driver);
421 if (rv)
422 printk(KERN_ERR DRV_NAME
423 " of_register_platform_driver failed (%i)\n", rv);
424 return rv;
409} 425}
410 426
411static void __exit fsl_i2c_exit(void) 427static void __exit fsl_i2c_exit(void)
412{ 428{
413 platform_driver_unregister(&fsl_i2c_driver); 429 of_unregister_platform_driver(&mpc_i2c_driver);
414} 430}
415 431
416module_init(fsl_i2c_init); 432module_init(fsl_i2c_init);