aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c
diff options
context:
space:
mode:
authorDavid Daney <david.daney@cavium.com>2012-07-05 12:12:39 -0400
committerRalf Baechle <ralf@linux-mips.org>2012-07-23 08:54:53 -0400
commitf353a218de6393fb43a5e81c3adbe1aac1a871ab (patch)
tree2b005cd034b91c66f452b3a030373049edacce08 /drivers/i2c
parenta0c16582b5b50792b0fd3e07d23c537936fafcb7 (diff)
i2c: Convert i2c-octeon.c to use device tree.
There are three parts to this: 1) Remove the definitions of OCTEON_IRQ_TWSI and OCTEON_IRQ_TWSI2. The interrupts are specified by the device tree and these hard coded irq numbers block the used of the irq lines by the irq_domain code. 2) Remove platform device setup code from octeon-platform.c, it is now unused. 3) Convert i2c-octeon.c to use device tree. Part of this includes using the devm_* functions instead of the raw counterparts, thus simplifying error handling. No functionality is changed. Signed-off-by: David Daney <david.daney@cavium.com> Acked-by: Rob Herring <rob.herring@calxeda.com> Acked-by: Wolfram Sang <w.sang@pengutronix.de> Cc: linux-mips@linux-mips.org Cc: devicetree-discuss@lists.ozlabs.org Cc: Grant Likely <grant.likely@secretlab.ca> Cc: linux-kernel@vger.kernel.org Patchwork: https://patchwork.linux-mips.org/patch/3939/ Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Diffstat (limited to 'drivers/i2c')
-rw-r--r--drivers/i2c/busses/i2c-octeon.c92
1 files changed, 49 insertions, 43 deletions
diff --git a/drivers/i2c/busses/i2c-octeon.c b/drivers/i2c/busses/i2c-octeon.c
index ee139a598814..f44c83549fe5 100644
--- a/drivers/i2c/busses/i2c-octeon.c
+++ b/drivers/i2c/busses/i2c-octeon.c
@@ -2,7 +2,7 @@
2 * (C) Copyright 2009-2010 2 * (C) Copyright 2009-2010
3 * Nokia Siemens Networks, michael.lawnick.ext@nsn.com 3 * Nokia Siemens Networks, michael.lawnick.ext@nsn.com
4 * 4 *
5 * Portions Copyright (C) 2010 Cavium Networks, Inc. 5 * Portions Copyright (C) 2010, 2011 Cavium Networks, Inc.
6 * 6 *
7 * This is a driver for the i2c adapter in Cavium Networks' OCTEON processors. 7 * This is a driver for the i2c adapter in Cavium Networks' OCTEON processors.
8 * 8 *
@@ -11,17 +11,18 @@
11 * warranty of any kind, whether express or implied. 11 * warranty of any kind, whether express or implied.
12 */ 12 */
13 13
14#include <linux/platform_device.h>
15#include <linux/interrupt.h>
14#include <linux/kernel.h> 16#include <linux/kernel.h>
15#include <linux/module.h> 17#include <linux/module.h>
18#include <linux/of_i2c.h>
19#include <linux/delay.h>
16#include <linux/sched.h> 20#include <linux/sched.h>
17#include <linux/slab.h> 21#include <linux/slab.h>
18#include <linux/init.h> 22#include <linux/init.h>
19
20#include <linux/io.h>
21#include <linux/i2c.h> 23#include <linux/i2c.h>
22#include <linux/interrupt.h> 24#include <linux/io.h>
23#include <linux/delay.h> 25#include <linux/of.h>
24#include <linux/platform_device.h>
25 26
26#include <asm/octeon/octeon.h> 27#include <asm/octeon/octeon.h>
27 28
@@ -65,7 +66,7 @@ struct octeon_i2c {
65 wait_queue_head_t queue; 66 wait_queue_head_t queue;
66 struct i2c_adapter adap; 67 struct i2c_adapter adap;
67 int irq; 68 int irq;
68 int twsi_freq; 69 u32 twsi_freq;
69 int sys_freq; 70 int sys_freq;
70 resource_size_t twsi_phys; 71 resource_size_t twsi_phys;
71 void __iomem *twsi_base; 72 void __iomem *twsi_base;
@@ -121,10 +122,8 @@ static u8 octeon_i2c_read_sw(struct octeon_i2c *i2c, u64 eop_reg)
121 */ 122 */
122static void octeon_i2c_write_int(struct octeon_i2c *i2c, u64 data) 123static void octeon_i2c_write_int(struct octeon_i2c *i2c, u64 data)
123{ 124{
124 u64 tmp;
125
126 __raw_writeq(data, i2c->twsi_base + TWSI_INT); 125 __raw_writeq(data, i2c->twsi_base + TWSI_INT);
127 tmp = __raw_readq(i2c->twsi_base + TWSI_INT); 126 __raw_readq(i2c->twsi_base + TWSI_INT);
128} 127}
129 128
130/** 129/**
@@ -515,7 +514,6 @@ static int __devinit octeon_i2c_probe(struct platform_device *pdev)
515{ 514{
516 int irq, result = 0; 515 int irq, result = 0;
517 struct octeon_i2c *i2c; 516 struct octeon_i2c *i2c;
518 struct octeon_i2c_data *i2c_data;
519 struct resource *res_mem; 517 struct resource *res_mem;
520 518
521 /* All adaptors have an irq. */ 519 /* All adaptors have an irq. */
@@ -523,86 +521,90 @@ static int __devinit octeon_i2c_probe(struct platform_device *pdev)
523 if (irq < 0) 521 if (irq < 0)
524 return irq; 522 return irq;
525 523
526 i2c = kzalloc(sizeof(*i2c), GFP_KERNEL); 524 i2c = devm_kzalloc(&pdev->dev, sizeof(*i2c), GFP_KERNEL);
527 if (!i2c) { 525 if (!i2c) {
528 dev_err(&pdev->dev, "kzalloc failed\n"); 526 dev_err(&pdev->dev, "kzalloc failed\n");
529 result = -ENOMEM; 527 result = -ENOMEM;
530 goto out; 528 goto out;
531 } 529 }
532 i2c->dev = &pdev->dev; 530 i2c->dev = &pdev->dev;
533 i2c_data = pdev->dev.platform_data;
534 531
535 res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 532 res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
536 533
537 if (res_mem == NULL) { 534 if (res_mem == NULL) {
538 dev_err(i2c->dev, "found no memory resource\n"); 535 dev_err(i2c->dev, "found no memory resource\n");
539 result = -ENXIO; 536 result = -ENXIO;
540 goto fail_region; 537 goto out;
541 } 538 }
539 i2c->twsi_phys = res_mem->start;
540 i2c->regsize = resource_size(res_mem);
542 541
543 if (i2c_data == NULL) { 542 /*
544 dev_err(i2c->dev, "no I2C frequency data\n"); 543 * "clock-rate" is a legacy binding, the official binding is
544 * "clock-frequency". Try the official one first and then
545 * fall back if it doesn't exist.
546 */
547 if (of_property_read_u32(pdev->dev.of_node,
548 "clock-frequency", &i2c->twsi_freq) &&
549 of_property_read_u32(pdev->dev.of_node,
550 "clock-rate", &i2c->twsi_freq)) {
551 dev_err(i2c->dev,
552 "no I2C 'clock-rate' or 'clock-frequency' property\n");
545 result = -ENXIO; 553 result = -ENXIO;
546 goto fail_region; 554 goto out;
547 } 555 }
548 556
549 i2c->twsi_phys = res_mem->start; 557 i2c->sys_freq = octeon_get_io_clock_rate();
550 i2c->regsize = resource_size(res_mem);
551 i2c->twsi_freq = i2c_data->i2c_freq;
552 i2c->sys_freq = i2c_data->sys_freq;
553 558
554 if (!request_mem_region(i2c->twsi_phys, i2c->regsize, res_mem->name)) { 559 if (!devm_request_mem_region(&pdev->dev, i2c->twsi_phys, i2c->regsize,
560 res_mem->name)) {
555 dev_err(i2c->dev, "request_mem_region failed\n"); 561 dev_err(i2c->dev, "request_mem_region failed\n");
556 goto fail_region; 562 goto out;
557 } 563 }
558 i2c->twsi_base = ioremap(i2c->twsi_phys, i2c->regsize); 564 i2c->twsi_base = devm_ioremap(&pdev->dev, i2c->twsi_phys, i2c->regsize);
559 565
560 init_waitqueue_head(&i2c->queue); 566 init_waitqueue_head(&i2c->queue);
561 567
562 i2c->irq = irq; 568 i2c->irq = irq;
563 569
564 result = request_irq(i2c->irq, octeon_i2c_isr, 0, DRV_NAME, i2c); 570 result = devm_request_irq(&pdev->dev, i2c->irq,
571 octeon_i2c_isr, 0, DRV_NAME, i2c);
565 if (result < 0) { 572 if (result < 0) {
566 dev_err(i2c->dev, "failed to attach interrupt\n"); 573 dev_err(i2c->dev, "failed to attach interrupt\n");
567 goto fail_irq; 574 goto out;
568 } 575 }
569 576
570 result = octeon_i2c_initlowlevel(i2c); 577 result = octeon_i2c_initlowlevel(i2c);
571 if (result) { 578 if (result) {
572 dev_err(i2c->dev, "init low level failed\n"); 579 dev_err(i2c->dev, "init low level failed\n");
573 goto fail_add; 580 goto out;
574 } 581 }
575 582
576 result = octeon_i2c_setclock(i2c); 583 result = octeon_i2c_setclock(i2c);
577 if (result) { 584 if (result) {
578 dev_err(i2c->dev, "clock init failed\n"); 585 dev_err(i2c->dev, "clock init failed\n");
579 goto fail_add; 586 goto out;
580 } 587 }
581 588
582 i2c->adap = octeon_i2c_ops; 589 i2c->adap = octeon_i2c_ops;
583 i2c->adap.dev.parent = &pdev->dev; 590 i2c->adap.dev.parent = &pdev->dev;
584 i2c->adap.nr = pdev->id >= 0 ? pdev->id : 0; 591 i2c->adap.dev.of_node = pdev->dev.of_node;
585 i2c_set_adapdata(&i2c->adap, i2c); 592 i2c_set_adapdata(&i2c->adap, i2c);
586 platform_set_drvdata(pdev, i2c); 593 platform_set_drvdata(pdev, i2c);
587 594
588 result = i2c_add_numbered_adapter(&i2c->adap); 595 result = i2c_add_adapter(&i2c->adap);
589 if (result < 0) { 596 if (result < 0) {
590 dev_err(i2c->dev, "failed to add adapter\n"); 597 dev_err(i2c->dev, "failed to add adapter\n");
591 goto fail_add; 598 goto fail_add;
592 } 599 }
593
594 dev_info(i2c->dev, "version %s\n", DRV_VERSION); 600 dev_info(i2c->dev, "version %s\n", DRV_VERSION);
595 601
596 return result; 602 of_i2c_register_devices(&i2c->adap);
603
604 return 0;
597 605
598fail_add: 606fail_add:
599 platform_set_drvdata(pdev, NULL); 607 platform_set_drvdata(pdev, NULL);
600 free_irq(i2c->irq, i2c);
601fail_irq:
602 iounmap(i2c->twsi_base);
603 release_mem_region(i2c->twsi_phys, i2c->regsize);
604fail_region:
605 kfree(i2c);
606out: 608out:
607 return result; 609 return result;
608}; 610};
@@ -613,19 +615,24 @@ static int __devexit octeon_i2c_remove(struct platform_device *pdev)
613 615
614 i2c_del_adapter(&i2c->adap); 616 i2c_del_adapter(&i2c->adap);
615 platform_set_drvdata(pdev, NULL); 617 platform_set_drvdata(pdev, NULL);
616 free_irq(i2c->irq, i2c);
617 iounmap(i2c->twsi_base);
618 release_mem_region(i2c->twsi_phys, i2c->regsize);
619 kfree(i2c);
620 return 0; 618 return 0;
621}; 619};
622 620
621static struct of_device_id octeon_i2c_match[] = {
622 {
623 .compatible = "cavium,octeon-3860-twsi",
624 },
625 {},
626};
627MODULE_DEVICE_TABLE(of, octeon_i2c_match);
628
623static struct platform_driver octeon_i2c_driver = { 629static struct platform_driver octeon_i2c_driver = {
624 .probe = octeon_i2c_probe, 630 .probe = octeon_i2c_probe,
625 .remove = __devexit_p(octeon_i2c_remove), 631 .remove = __devexit_p(octeon_i2c_remove),
626 .driver = { 632 .driver = {
627 .owner = THIS_MODULE, 633 .owner = THIS_MODULE,
628 .name = DRV_NAME, 634 .name = DRV_NAME,
635 .of_match_table = octeon_i2c_match,
629 }, 636 },
630}; 637};
631 638
@@ -635,4 +642,3 @@ MODULE_AUTHOR("Michael Lawnick <michael.lawnick.ext@nsn.com>");
635MODULE_DESCRIPTION("I2C-Bus adapter for Cavium OCTEON processors"); 642MODULE_DESCRIPTION("I2C-Bus adapter for Cavium OCTEON processors");
636MODULE_LICENSE("GPL"); 643MODULE_LICENSE("GPL");
637MODULE_VERSION(DRV_VERSION); 644MODULE_VERSION(DRV_VERSION);
638MODULE_ALIAS("platform:" DRV_NAME);