aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoland Stigge <stigge@antcom.de>2012-04-22 05:59:47 -0400
committerRoland Stigge <stigge@antcom.de>2012-04-22 05:59:47 -0400
commit1451ba3a5fa52d874e03a3380d053f3e6a5fcae4 (patch)
treee40a2b10951eabace15836d658eea8848d47564c
parentc4cea7fc1bfd8a36d08f8114efcb11d649d97d5a (diff)
i2c-pnx.c: Use resources in platforms
As a precondition for device tree conversion, the platforms using i2c-pnx.c are converted to using mem and irq resources instead of platform data. Signed-off-by: Roland Stigge <stigge@antcom.de> Reviewed-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
-rw-r--r--arch/arm/mach-lpc32xx/common.c67
-rw-r--r--arch/arm/mach-pnx4008/i2c.c64
-rw-r--r--drivers/i2c/busses/i2c-pnx.c47
-rw-r--r--include/linux/i2c-pnx.h9
4 files changed, 108 insertions, 79 deletions
diff --git a/arch/arm/mach-lpc32xx/common.c b/arch/arm/mach-lpc32xx/common.c
index bbbf063a74c2..6f255600fc97 100644
--- a/arch/arm/mach-lpc32xx/common.c
+++ b/arch/arm/mach-lpc32xx/common.c
@@ -27,7 +27,6 @@
27 27
28#include <asm/mach/map.h> 28#include <asm/mach/map.h>
29 29
30#include <mach/i2c.h>
31#include <mach/hardware.h> 30#include <mach/hardware.h>
32#include <mach/platform.h> 31#include <mach/platform.h>
33#include "common.h" 32#include "common.h"
@@ -53,46 +52,64 @@ struct platform_device lpc32xx_watchdog_device = {
53/* 52/*
54 * I2C busses 53 * I2C busses
55 */ 54 */
56static struct i2c_pnx_data i2c0_data = { 55static struct resource i2c0_resources[] = {
57 .name = I2C_CHIP_NAME "1", 56 [0] = {
58 .base = LPC32XX_I2C1_BASE, 57 .start = LPC32XX_I2C1_BASE,
59 .irq = IRQ_LPC32XX_I2C_1, 58 .end = LPC32XX_I2C1_BASE + 0x100 - 1,
59 .flags = IORESOURCE_MEM,
60 },
61 [1] = {
62 .start = IRQ_LPC32XX_I2C_1,
63 .end = IRQ_LPC32XX_I2C_1,
64 .flags = IORESOURCE_IRQ,
65 },
60}; 66};
61 67
62static struct i2c_pnx_data i2c1_data = { 68static struct resource i2c1_resources[] = {
63 .name = I2C_CHIP_NAME "2", 69 [0] = {
64 .base = LPC32XX_I2C2_BASE, 70 .start = LPC32XX_I2C2_BASE,
65 .irq = IRQ_LPC32XX_I2C_2, 71 .end = LPC32XX_I2C2_BASE + 0x100 - 1,
72 .flags = IORESOURCE_MEM,
73 },
74 [1] = {
75 .start = IRQ_LPC32XX_I2C_2,
76 .end = IRQ_LPC32XX_I2C_2,
77 .flags = IORESOURCE_IRQ,
78 },
66}; 79};
67 80
68static struct i2c_pnx_data i2c2_data = { 81static struct resource i2c2_resources[] = {
69 .name = "USB-I2C", 82 [0] = {
70 .base = LPC32XX_OTG_I2C_BASE, 83 .start = LPC32XX_OTG_I2C_BASE,
71 .irq = IRQ_LPC32XX_USB_I2C, 84 .end = LPC32XX_OTG_I2C_BASE + 0x100 - 1,
85 .flags = IORESOURCE_MEM,
86 },
87 [1] = {
88 .start = IRQ_LPC32XX_USB_I2C,
89 .end = IRQ_LPC32XX_USB_I2C,
90 .flags = IORESOURCE_IRQ,
91 },
72}; 92};
73 93
74struct platform_device lpc32xx_i2c0_device = { 94struct platform_device lpc32xx_i2c0_device = {
75 .name = "pnx-i2c", 95 .name = "pnx-i2c.0",
76 .id = 0, 96 .id = 0,
77 .dev = { 97 .num_resources = ARRAY_SIZE(i2c0_resources),
78 .platform_data = &i2c0_data, 98 .resource = i2c0_resources,
79 },
80}; 99};
81 100
82struct platform_device lpc32xx_i2c1_device = { 101struct platform_device lpc32xx_i2c1_device = {
83 .name = "pnx-i2c", 102 .name = "pnx-i2c.1",
84 .id = 1, 103 .id = 1,
85 .dev = { 104 .num_resources = ARRAY_SIZE(i2c1_resources),
86 .platform_data = &i2c1_data, 105 .resource = i2c1_resources,
87 },
88}; 106};
89 107
90struct platform_device lpc32xx_i2c2_device = { 108struct platform_device lpc32xx_i2c2_device = {
91 .name = "pnx-i2c", 109 .name = "pnx-i2c.2",
92 .id = 2, 110 .id = 2,
93 .dev = { 111 .num_resources = ARRAY_SIZE(i2c2_resources),
94 .platform_data = &i2c2_data, 112 .resource = i2c2_resources,
95 },
96}; 113};
97 114
98/* TSC (Touch Screen Controller) */ 115/* TSC (Touch Screen Controller) */
diff --git a/arch/arm/mach-pnx4008/i2c.c b/arch/arm/mach-pnx4008/i2c.c
index 8103f9644e2d..550cfc2a1f2e 100644
--- a/arch/arm/mach-pnx4008/i2c.c
+++ b/arch/arm/mach-pnx4008/i2c.c
@@ -16,48 +16,62 @@
16#include <linux/err.h> 16#include <linux/err.h>
17#include <mach/platform.h> 17#include <mach/platform.h>
18#include <mach/irqs.h> 18#include <mach/irqs.h>
19#include <mach/i2c.h>
20 19
21static struct i2c_pnx_data i2c0_data = { 20static struct resource i2c0_resources[] = {
22 .name = I2C_CHIP_NAME "0", 21 {
23 .base = PNX4008_I2C1_BASE, 22 .start = PNX4008_I2C1_BASE,
24 .irq = I2C_1_INT, 23 .end = PNX4008_I2C1_BASE + SZ_4K - 1,
24 .flags = IORESOURCE_MEM,
25 }, {
26 .start = I2C_1_INT,
27 .end = I2C_1_INT,
28 .flags = IORESOURCE_IRQ,
29 },
25}; 30};
26 31
27static struct i2c_pnx_data i2c1_data = { 32static struct resource i2c1_resources[] = {
28 .name = I2C_CHIP_NAME "1", 33 {
29 .base = PNX4008_I2C2_BASE, 34 .start = PNX4008_I2C2_BASE,
30 .irq = I2C_2_INT, 35 .end = PNX4008_I2C2_BASE + SZ_4K - 1,
36 .flags = IORESOURCE_MEM,
37 }, {
38 .start = I2C_2_INT,
39 .end = I2C_2_INT,
40 .flags = IORESOURCE_IRQ,
41 },
31}; 42};
32 43
33static struct i2c_pnx_data i2c2_data = { 44static struct resource i2c2_resources[] = {
34 .name = "USB-I2C", 45 {
35 .base = (PNX4008_USB_CONFIG_BASE + 0x300), 46 .start = PNX4008_USB_CONFIG_BASE + 0x300,
36 .irq = USB_I2C_INT, 47 .end = PNX4008_USB_CONFIG_BASE + 0x300 + SZ_4K - 1,
48 .flags = IORESOURCE_MEM,
49 }, {
50 .start = USB_I2C_INT,
51 .end = USB_I2C_INT,
52 .flags = IORESOURCE_IRQ,
53 },
37}; 54};
38 55
39static struct platform_device i2c0_device = { 56static struct platform_device i2c0_device = {
40 .name = "pnx-i2c", 57 .name = "pnx-i2c.0",
41 .id = 0, 58 .id = 0,
42 .dev = { 59 .resource = i2c0_resources,
43 .platform_data = &i2c0_data, 60 .num_resources = ARRAY_SIZE(i2c0_resources),
44 },
45}; 61};
46 62
47static struct platform_device i2c1_device = { 63static struct platform_device i2c1_device = {
48 .name = "pnx-i2c", 64 .name = "pnx-i2c.1",
49 .id = 1, 65 .id = 1,
50 .dev = { 66 .resource = i2c1_resources,
51 .platform_data = &i2c1_data, 67 .num_resources = ARRAY_SIZE(i2c1_resources),
52 },
53}; 68};
54 69
55static struct platform_device i2c2_device = { 70static struct platform_device i2c2_device = {
56 .name = "pnx-i2c", 71 .name = "pnx-i2c.2",
57 .id = 2, 72 .id = 2,
58 .dev = { 73 .resource = i2c2_resources,
59 .platform_data = &i2c2_data, 74 .num_resources = ARRAY_SIZE(i2c2_resources),
60 },
61}; 75};
62 76
63static struct platform_device *devices[] __initdata = { 77static struct platform_device *devices[] __initdata = {
diff --git a/drivers/i2c/busses/i2c-pnx.c b/drivers/i2c/busses/i2c-pnx.c
index eb8ad538c79f..6fb97aef0465 100644
--- a/drivers/i2c/busses/i2c-pnx.c
+++ b/drivers/i2c/busses/i2c-pnx.c
@@ -568,14 +568,7 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev)
568 int ret = 0; 568 int ret = 0;
569 struct i2c_pnx_algo_data *alg_data; 569 struct i2c_pnx_algo_data *alg_data;
570 unsigned long freq; 570 unsigned long freq;
571 struct i2c_pnx_data *i2c_pnx = pdev->dev.platform_data; 571 struct resource *res;
572
573 if (!i2c_pnx || !i2c_pnx->name) {
574 dev_err(&pdev->dev, "%s: no platform data supplied\n",
575 __func__);
576 ret = -EINVAL;
577 goto out;
578 }
579 572
580 alg_data = kzalloc(sizeof(*alg_data), GFP_KERNEL); 573 alg_data = kzalloc(sizeof(*alg_data), GFP_KERNEL);
581 if (!alg_data) { 574 if (!alg_data) {
@@ -585,13 +578,10 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev)
585 578
586 platform_set_drvdata(pdev, alg_data); 579 platform_set_drvdata(pdev, alg_data);
587 580
588 strlcpy(alg_data->adapter.name, i2c_pnx->name,
589 sizeof(alg_data->adapter.name));
590 alg_data->adapter.dev.parent = &pdev->dev; 581 alg_data->adapter.dev.parent = &pdev->dev;
591 alg_data->adapter.algo = &pnx_algorithm; 582 alg_data->adapter.algo = &pnx_algorithm;
592 alg_data->adapter.algo_data = alg_data; 583 alg_data->adapter.algo_data = alg_data;
593 alg_data->adapter.nr = pdev->id; 584 alg_data->adapter.nr = pdev->id;
594 alg_data->i2c_pnx = i2c_pnx;
595 585
596 alg_data->clk = clk_get(&pdev->dev, NULL); 586 alg_data->clk = clk_get(&pdev->dev, NULL);
597 if (IS_ERR(alg_data->clk)) { 587 if (IS_ERR(alg_data->clk)) {
@@ -603,17 +593,27 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev)
603 alg_data->mif.timer.function = i2c_pnx_timeout; 593 alg_data->mif.timer.function = i2c_pnx_timeout;
604 alg_data->mif.timer.data = (unsigned long)alg_data; 594 alg_data->mif.timer.data = (unsigned long)alg_data;
605 595
596 snprintf(alg_data->adapter.name, sizeof(alg_data->adapter.name),
597 "%s", pdev->name);
598
606 /* Register I/O resource */ 599 /* Register I/O resource */
607 if (!request_mem_region(i2c_pnx->base, I2C_PNX_REGION_SIZE, 600 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
601 if (!res) {
602 dev_err(&pdev->dev, "Unable to get mem resource.\n");
603 ret = -EBUSY;
604 goto out_clkget;
605 }
606 if (!request_mem_region(res->start, I2C_PNX_REGION_SIZE,
608 pdev->name)) { 607 pdev->name)) {
609 dev_err(&pdev->dev, 608 dev_err(&pdev->dev,
610 "I/O region 0x%08x for I2C already in use.\n", 609 "I/O region 0x%08x for I2C already in use.\n",
611 i2c_pnx->base); 610 res->start);
612 ret = -ENODEV; 611 ret = -ENODEV;
613 goto out_clkget; 612 goto out_clkget;
614 } 613 }
615 614
616 alg_data->ioaddr = ioremap(i2c_pnx->base, I2C_PNX_REGION_SIZE); 615 alg_data->base = res->start;
616 alg_data->ioaddr = ioremap(res->start, I2C_PNX_REGION_SIZE);
617 if (!alg_data->ioaddr) { 617 if (!alg_data->ioaddr) {
618 dev_err(&pdev->dev, "Couldn't ioremap I2C I/O region\n"); 618 dev_err(&pdev->dev, "Couldn't ioremap I2C I/O region\n");
619 ret = -ENOMEM; 619 ret = -ENOMEM;
@@ -650,7 +650,12 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev)
650 } 650 }
651 init_completion(&alg_data->mif.complete); 651 init_completion(&alg_data->mif.complete);
652 652
653 ret = request_irq(i2c_pnx->irq, i2c_pnx_interrupt, 653 alg_data->irq = platform_get_irq(pdev, 0);
654 if (alg_data->irq < 0) {
655 dev_err(&pdev->dev, "Failed to get IRQ from platform resource\n");
656 goto out_irq;
657 }
658 ret = request_irq(alg_data->irq, i2c_pnx_interrupt,
654 0, pdev->name, alg_data); 659 0, pdev->name, alg_data);
655 if (ret) 660 if (ret)
656 goto out_clock; 661 goto out_clock;
@@ -663,38 +668,36 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev)
663 } 668 }
664 669
665 dev_dbg(&pdev->dev, "%s: Master at %#8x, irq %d.\n", 670 dev_dbg(&pdev->dev, "%s: Master at %#8x, irq %d.\n",
666 alg_data->adapter.name, i2c_pnx->base, i2c_pnx->irq); 671 alg_data->adapter.name, res->start, alg_data->irq);
667 672
668 return 0; 673 return 0;
669 674
670out_irq: 675out_irq:
671 free_irq(i2c_pnx->irq, alg_data); 676 free_irq(alg_data->irq, alg_data);
672out_clock: 677out_clock:
673 clk_disable(alg_data->clk); 678 clk_disable(alg_data->clk);
674out_unmap: 679out_unmap:
675 iounmap(alg_data->ioaddr); 680 iounmap(alg_data->ioaddr);
676out_release: 681out_release:
677 release_mem_region(i2c_pnx->base, I2C_PNX_REGION_SIZE); 682 release_mem_region(res->start, I2C_PNX_REGION_SIZE);
678out_clkget: 683out_clkget:
679 clk_put(alg_data->clk); 684 clk_put(alg_data->clk);
680out_drvdata: 685out_drvdata:
681 kfree(alg_data); 686 kfree(alg_data);
682err_kzalloc: 687err_kzalloc:
683 platform_set_drvdata(pdev, NULL); 688 platform_set_drvdata(pdev, NULL);
684out:
685 return ret; 689 return ret;
686} 690}
687 691
688static int __devexit i2c_pnx_remove(struct platform_device *pdev) 692static int __devexit i2c_pnx_remove(struct platform_device *pdev)
689{ 693{
690 struct i2c_pnx_algo_data *alg_data = platform_get_drvdata(pdev); 694 struct i2c_pnx_algo_data *alg_data = platform_get_drvdata(pdev);
691 struct i2c_pnx_data *i2c_pnx = alg_data->i2c_pnx;
692 695
693 free_irq(i2c_pnx->irq, alg_data); 696 free_irq(alg_data->irq, alg_data);
694 i2c_del_adapter(&alg_data->adapter); 697 i2c_del_adapter(&alg_data->adapter);
695 clk_disable(alg_data->clk); 698 clk_disable(alg_data->clk);
696 iounmap(alg_data->ioaddr); 699 iounmap(alg_data->ioaddr);
697 release_mem_region(i2c_pnx->base, I2C_PNX_REGION_SIZE); 700 release_mem_region(alg_data->base, I2C_PNX_REGION_SIZE);
698 clk_put(alg_data->clk); 701 clk_put(alg_data->clk);
699 kfree(alg_data); 702 kfree(alg_data);
700 platform_set_drvdata(pdev, NULL); 703 platform_set_drvdata(pdev, NULL);
diff --git a/include/linux/i2c-pnx.h b/include/linux/i2c-pnx.h
index a87124d4d533..6e8efb7afd7c 100644
--- a/include/linux/i2c-pnx.h
+++ b/include/linux/i2c-pnx.h
@@ -29,14 +29,9 @@ struct i2c_pnx_algo_data {
29 struct i2c_pnx_mif mif; 29 struct i2c_pnx_mif mif;
30 int last; 30 int last;
31 struct clk *clk; 31 struct clk *clk;
32 struct i2c_pnx_data *i2c_pnx;
33 struct i2c_adapter adapter; 32 struct i2c_adapter adapter;
34}; 33 phys_addr_t base;
35 34 int irq;
36struct i2c_pnx_data {
37 const char *name;
38 u32 base;
39 int irq;
40}; 35};
41 36
42#endif /* __I2C_PNX_H__ */ 37#endif /* __I2C_PNX_H__ */