diff options
-rw-r--r-- | arch/arm/mach-pnx4008/i2c.c | 18 | ||||
-rw-r--r-- | drivers/i2c/busses/i2c-pnx.c | 40 | ||||
-rw-r--r-- | include/linux/i2c-pnx.h | 4 |
3 files changed, 26 insertions, 36 deletions
diff --git a/arch/arm/mach-pnx4008/i2c.c b/arch/arm/mach-pnx4008/i2c.c index 33146e832dd7..8103f9644e2d 100644 --- a/arch/arm/mach-pnx4008/i2c.c +++ b/arch/arm/mach-pnx4008/i2c.c | |||
@@ -18,32 +18,20 @@ | |||
18 | #include <mach/irqs.h> | 18 | #include <mach/irqs.h> |
19 | #include <mach/i2c.h> | 19 | #include <mach/i2c.h> |
20 | 20 | ||
21 | static struct i2c_adapter pnx_adapter0 = { | ||
22 | .name = I2C_CHIP_NAME "0", | ||
23 | }; | ||
24 | |||
25 | static struct i2c_adapter pnx_adapter1 = { | ||
26 | .name = I2C_CHIP_NAME "1", | ||
27 | }; | ||
28 | |||
29 | static struct i2c_adapter pnx_adapter2 = { | ||
30 | .name = "USB-I2C", | ||
31 | }; | ||
32 | |||
33 | static struct i2c_pnx_data i2c0_data = { | 21 | static struct i2c_pnx_data i2c0_data = { |
34 | .adapter = &pnx_adapter0, | 22 | .name = I2C_CHIP_NAME "0", |
35 | .base = PNX4008_I2C1_BASE, | 23 | .base = PNX4008_I2C1_BASE, |
36 | .irq = I2C_1_INT, | 24 | .irq = I2C_1_INT, |
37 | }; | 25 | }; |
38 | 26 | ||
39 | static struct i2c_pnx_data i2c1_data = { | 27 | static struct i2c_pnx_data i2c1_data = { |
40 | .adapter = &pnx_adapter1, | 28 | .name = I2C_CHIP_NAME "1", |
41 | .base = PNX4008_I2C2_BASE, | 29 | .base = PNX4008_I2C2_BASE, |
42 | .irq = I2C_2_INT, | 30 | .irq = I2C_2_INT, |
43 | }; | 31 | }; |
44 | 32 | ||
45 | static struct i2c_pnx_data i2c2_data = { | 33 | static struct i2c_pnx_data i2c2_data = { |
46 | .adapter = &pnx_adapter2, | 34 | .name = "USB-I2C", |
47 | .base = (PNX4008_USB_CONFIG_BASE + 0x300), | 35 | .base = (PNX4008_USB_CONFIG_BASE + 0x300), |
48 | .irq = USB_I2C_INT, | 36 | .irq = USB_I2C_INT, |
49 | }; | 37 | }; |
diff --git a/drivers/i2c/busses/i2c-pnx.c b/drivers/i2c/busses/i2c-pnx.c index 1d66856a22fd..6b413c5300d3 100644 --- a/drivers/i2c/busses/i2c-pnx.c +++ b/drivers/i2c/busses/i2c-pnx.c | |||
@@ -551,8 +551,7 @@ static struct i2c_algorithm pnx_algorithm = { | |||
551 | static int i2c_pnx_controller_suspend(struct platform_device *pdev, | 551 | static int i2c_pnx_controller_suspend(struct platform_device *pdev, |
552 | pm_message_t state) | 552 | pm_message_t state) |
553 | { | 553 | { |
554 | struct i2c_pnx_data *i2c_pnx = platform_get_drvdata(pdev); | 554 | struct i2c_pnx_algo_data *alg_data = platform_get_drvdata(pdev); |
555 | struct i2c_pnx_algo_data *alg_data = i2c_pnx->adapter->algo_data; | ||
556 | 555 | ||
557 | /* FIXME: shouldn't this be clk_disable? */ | 556 | /* FIXME: shouldn't this be clk_disable? */ |
558 | clk_enable(alg_data->clk); | 557 | clk_enable(alg_data->clk); |
@@ -562,8 +561,7 @@ static int i2c_pnx_controller_suspend(struct platform_device *pdev, | |||
562 | 561 | ||
563 | static int i2c_pnx_controller_resume(struct platform_device *pdev) | 562 | static int i2c_pnx_controller_resume(struct platform_device *pdev) |
564 | { | 563 | { |
565 | struct i2c_pnx_data *i2c_pnx = platform_get_drvdata(pdev); | 564 | struct i2c_pnx_algo_data *alg_data = platform_get_drvdata(pdev); |
566 | struct i2c_pnx_algo_data *alg_data = i2c_pnx->adapter->algo_data; | ||
567 | 565 | ||
568 | return clk_enable(alg_data->clk); | 566 | return clk_enable(alg_data->clk); |
569 | } | 567 | } |
@@ -580,7 +578,7 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev) | |||
580 | unsigned long freq; | 578 | unsigned long freq; |
581 | struct i2c_pnx_data *i2c_pnx = pdev->dev.platform_data; | 579 | struct i2c_pnx_data *i2c_pnx = pdev->dev.platform_data; |
582 | 580 | ||
583 | if (!i2c_pnx || !i2c_pnx->adapter) { | 581 | if (!i2c_pnx || !i2c_pnx->name) { |
584 | dev_err(&pdev->dev, "%s: no platform data supplied\n", | 582 | dev_err(&pdev->dev, "%s: no platform data supplied\n", |
585 | __func__); | 583 | __func__); |
586 | ret = -EINVAL; | 584 | ret = -EINVAL; |
@@ -593,10 +591,15 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev) | |||
593 | goto err_kzalloc; | 591 | goto err_kzalloc; |
594 | } | 592 | } |
595 | 593 | ||
596 | platform_set_drvdata(pdev, i2c_pnx); | 594 | platform_set_drvdata(pdev, alg_data); |
597 | 595 | ||
598 | i2c_pnx->adapter->algo = &pnx_algorithm; | 596 | strlcpy(alg_data->adapter.name, i2c_pnx->name, |
599 | i2c_pnx->adapter->algo_data = alg_data; | 597 | sizeof(alg_data->adapter.name)); |
598 | alg_data->adapter.dev.parent = &pdev->dev; | ||
599 | alg_data->adapter.algo = &pnx_algorithm; | ||
600 | alg_data->adapter.algo_data = alg_data; | ||
601 | alg_data->adapter.nr = pdev->id; | ||
602 | alg_data->i2c_pnx = i2c_pnx; | ||
600 | 603 | ||
601 | alg_data->clk = clk_get(&pdev->dev, NULL); | 604 | alg_data->clk = clk_get(&pdev->dev, NULL); |
602 | if (IS_ERR(alg_data->clk)) { | 605 | if (IS_ERR(alg_data->clk)) { |
@@ -606,7 +609,7 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev) | |||
606 | 609 | ||
607 | init_timer(&alg_data->mif.timer); | 610 | init_timer(&alg_data->mif.timer); |
608 | alg_data->mif.timer.function = i2c_pnx_timeout; | 611 | alg_data->mif.timer.function = i2c_pnx_timeout; |
609 | alg_data->mif.timer.data = (unsigned long)i2c_pnx->adapter; | 612 | alg_data->mif.timer.data = (unsigned long)&alg_data->adapter; |
610 | 613 | ||
611 | /* Register I/O resource */ | 614 | /* Register I/O resource */ |
612 | if (!request_mem_region(i2c_pnx->base, I2C_PNX_REGION_SIZE, | 615 | if (!request_mem_region(i2c_pnx->base, I2C_PNX_REGION_SIZE, |
@@ -654,26 +657,24 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev) | |||
654 | init_completion(&alg_data->mif.complete); | 657 | init_completion(&alg_data->mif.complete); |
655 | 658 | ||
656 | ret = request_irq(i2c_pnx->irq, i2c_pnx_interrupt, | 659 | ret = request_irq(i2c_pnx->irq, i2c_pnx_interrupt, |
657 | 0, pdev->name, i2c_pnx->adapter); | 660 | 0, pdev->name, &alg_data->adapter); |
658 | if (ret) | 661 | if (ret) |
659 | goto out_clock; | 662 | goto out_clock; |
660 | 663 | ||
661 | /* Register this adapter with the I2C subsystem */ | 664 | /* Register this adapter with the I2C subsystem */ |
662 | i2c_pnx->adapter->dev.parent = &pdev->dev; | 665 | ret = i2c_add_numbered_adapter(&alg_data->adapter); |
663 | i2c_pnx->adapter->nr = pdev->id; | ||
664 | ret = i2c_add_numbered_adapter(i2c_pnx->adapter); | ||
665 | if (ret < 0) { | 666 | if (ret < 0) { |
666 | dev_err(&pdev->dev, "I2C: Failed to add bus\n"); | 667 | dev_err(&pdev->dev, "I2C: Failed to add bus\n"); |
667 | goto out_irq; | 668 | goto out_irq; |
668 | } | 669 | } |
669 | 670 | ||
670 | dev_dbg(&pdev->dev, "%s: Master at %#8x, irq %d.\n", | 671 | dev_dbg(&pdev->dev, "%s: Master at %#8x, irq %d.\n", |
671 | i2c_pnx->adapter->name, i2c_pnx->base, i2c_pnx->irq); | 672 | alg_data->adapter.name, i2c_pnx->base, i2c_pnx->irq); |
672 | 673 | ||
673 | return 0; | 674 | return 0; |
674 | 675 | ||
675 | out_irq: | 676 | out_irq: |
676 | free_irq(i2c_pnx->irq, i2c_pnx->adapter); | 677 | free_irq(i2c_pnx->irq, &alg_data->adapter); |
677 | out_clock: | 678 | out_clock: |
678 | clk_disable(alg_data->clk); | 679 | clk_disable(alg_data->clk); |
679 | out_unmap: | 680 | out_unmap: |
@@ -692,12 +693,11 @@ out: | |||
692 | 693 | ||
693 | static int __devexit i2c_pnx_remove(struct platform_device *pdev) | 694 | static int __devexit i2c_pnx_remove(struct platform_device *pdev) |
694 | { | 695 | { |
695 | struct i2c_pnx_data *i2c_pnx = platform_get_drvdata(pdev); | 696 | struct i2c_pnx_algo_data *alg_data = platform_get_drvdata(pdev); |
696 | struct i2c_adapter *adap = i2c_pnx->adapter; | 697 | struct i2c_pnx_data *i2c_pnx = alg_data->i2c_pnx; |
697 | struct i2c_pnx_algo_data *alg_data = adap->algo_data; | ||
698 | 698 | ||
699 | free_irq(i2c_pnx->irq, i2c_pnx->adapter); | 699 | free_irq(i2c_pnx->irq, &alg_data->adapter); |
700 | i2c_del_adapter(adap); | 700 | i2c_del_adapter(&alg_data->adapter); |
701 | clk_disable(alg_data->clk); | 701 | clk_disable(alg_data->clk); |
702 | iounmap(alg_data->ioaddr); | 702 | iounmap(alg_data->ioaddr); |
703 | release_mem_region(i2c_pnx->base, I2C_PNX_REGION_SIZE); | 703 | release_mem_region(i2c_pnx->base, I2C_PNX_REGION_SIZE); |
diff --git a/include/linux/i2c-pnx.h b/include/linux/i2c-pnx.h index 9ebdf882d032..a87124d4d533 100644 --- a/include/linux/i2c-pnx.h +++ b/include/linux/i2c-pnx.h | |||
@@ -29,10 +29,12 @@ 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 | }; | 34 | }; |
33 | 35 | ||
34 | struct i2c_pnx_data { | 36 | struct i2c_pnx_data { |
35 | struct i2c_adapter *adapter; | 37 | const char *name; |
36 | u32 base; | 38 | u32 base; |
37 | int irq; | 39 | int irq; |
38 | }; | 40 | }; |