diff options
Diffstat (limited to 'drivers/i2c/busses')
-rw-r--r-- | drivers/i2c/busses/i2c-pnx.c | 64 |
1 files changed, 13 insertions, 51 deletions
diff --git a/drivers/i2c/busses/i2c-pnx.c b/drivers/i2c/busses/i2c-pnx.c index c9a352f0a9a5..dc7ff829ad78 100644 --- a/drivers/i2c/busses/i2c-pnx.c +++ b/drivers/i2c/busses/i2c-pnx.c | |||
@@ -628,11 +628,9 @@ static int i2c_pnx_probe(struct platform_device *pdev) | |||
628 | struct resource *res; | 628 | struct resource *res; |
629 | u32 speed = I2C_PNX_SPEED_KHZ_DEFAULT * 1000; | 629 | u32 speed = I2C_PNX_SPEED_KHZ_DEFAULT * 1000; |
630 | 630 | ||
631 | alg_data = kzalloc(sizeof(*alg_data), GFP_KERNEL); | 631 | alg_data = devm_kzalloc(&pdev->dev, sizeof(*alg_data), GFP_KERNEL); |
632 | if (!alg_data) { | 632 | if (!alg_data) |
633 | ret = -ENOMEM; | 633 | return -ENOMEM; |
634 | goto err_kzalloc; | ||
635 | } | ||
636 | 634 | ||
637 | platform_set_drvdata(pdev, alg_data); | 635 | platform_set_drvdata(pdev, alg_data); |
638 | 636 | ||
@@ -657,11 +655,9 @@ static int i2c_pnx_probe(struct platform_device *pdev) | |||
657 | */ | 655 | */ |
658 | } | 656 | } |
659 | #endif | 657 | #endif |
660 | alg_data->clk = clk_get(&pdev->dev, NULL); | 658 | alg_data->clk = devm_clk_get(&pdev->dev, NULL); |
661 | if (IS_ERR(alg_data->clk)) { | 659 | if (IS_ERR(alg_data->clk)) |
662 | ret = PTR_ERR(alg_data->clk); | 660 | return PTR_ERR(alg_data->clk); |
663 | goto out_drvdata; | ||
664 | } | ||
665 | 661 | ||
666 | init_timer(&alg_data->mif.timer); | 662 | init_timer(&alg_data->mif.timer); |
667 | alg_data->mif.timer.function = i2c_pnx_timeout; | 663 | alg_data->mif.timer.function = i2c_pnx_timeout; |
@@ -672,31 +668,13 @@ static int i2c_pnx_probe(struct platform_device *pdev) | |||
672 | 668 | ||
673 | /* Register I/O resource */ | 669 | /* Register I/O resource */ |
674 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 670 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
675 | if (!res) { | 671 | alg_data->ioaddr = devm_ioremap_resource(&pdev->dev, res); |
676 | dev_err(&pdev->dev, "Unable to get mem resource.\n"); | 672 | if (IS_ERR(alg_data->ioaddr)) |
677 | ret = -EBUSY; | 673 | return PTR_ERR(alg_data->ioaddr); |
678 | goto out_clkget; | ||
679 | } | ||
680 | if (!request_mem_region(res->start, I2C_PNX_REGION_SIZE, | ||
681 | pdev->name)) { | ||
682 | dev_err(&pdev->dev, | ||
683 | "I/O region 0x%08x for I2C already in use.\n", | ||
684 | res->start); | ||
685 | ret = -ENOMEM; | ||
686 | goto out_clkget; | ||
687 | } | ||
688 | |||
689 | alg_data->base = res->start; | ||
690 | alg_data->ioaddr = ioremap(res->start, I2C_PNX_REGION_SIZE); | ||
691 | if (!alg_data->ioaddr) { | ||
692 | dev_err(&pdev->dev, "Couldn't ioremap I2C I/O region\n"); | ||
693 | ret = -ENOMEM; | ||
694 | goto out_release; | ||
695 | } | ||
696 | 674 | ||
697 | ret = clk_enable(alg_data->clk); | 675 | ret = clk_enable(alg_data->clk); |
698 | if (ret) | 676 | if (ret) |
699 | goto out_unmap; | 677 | return ret; |
700 | 678 | ||
701 | freq = clk_get_rate(alg_data->clk); | 679 | freq = clk_get_rate(alg_data->clk); |
702 | 680 | ||
@@ -730,8 +708,8 @@ static int i2c_pnx_probe(struct platform_device *pdev) | |||
730 | ret = alg_data->irq; | 708 | ret = alg_data->irq; |
731 | goto out_clock; | 709 | goto out_clock; |
732 | } | 710 | } |
733 | ret = request_irq(alg_data->irq, i2c_pnx_interrupt, | 711 | ret = devm_request_irq(&pdev->dev, alg_data->irq, i2c_pnx_interrupt, |
734 | 0, pdev->name, alg_data); | 712 | 0, pdev->name, alg_data); |
735 | if (ret) | 713 | if (ret) |
736 | goto out_clock; | 714 | goto out_clock; |
737 | 715 | ||
@@ -739,7 +717,7 @@ static int i2c_pnx_probe(struct platform_device *pdev) | |||
739 | ret = i2c_add_numbered_adapter(&alg_data->adapter); | 717 | ret = i2c_add_numbered_adapter(&alg_data->adapter); |
740 | if (ret < 0) { | 718 | if (ret < 0) { |
741 | dev_err(&pdev->dev, "I2C: Failed to add bus\n"); | 719 | dev_err(&pdev->dev, "I2C: Failed to add bus\n"); |
742 | goto out_irq; | 720 | goto out_clock; |
743 | } | 721 | } |
744 | 722 | ||
745 | dev_dbg(&pdev->dev, "%s: Master at %#8x, irq %d.\n", | 723 | dev_dbg(&pdev->dev, "%s: Master at %#8x, irq %d.\n", |
@@ -747,19 +725,8 @@ static int i2c_pnx_probe(struct platform_device *pdev) | |||
747 | 725 | ||
748 | return 0; | 726 | return 0; |
749 | 727 | ||
750 | out_irq: | ||
751 | free_irq(alg_data->irq, alg_data); | ||
752 | out_clock: | 728 | out_clock: |
753 | clk_disable(alg_data->clk); | 729 | clk_disable(alg_data->clk); |
754 | out_unmap: | ||
755 | iounmap(alg_data->ioaddr); | ||
756 | out_release: | ||
757 | release_mem_region(res->start, I2C_PNX_REGION_SIZE); | ||
758 | out_clkget: | ||
759 | clk_put(alg_data->clk); | ||
760 | out_drvdata: | ||
761 | kfree(alg_data); | ||
762 | err_kzalloc: | ||
763 | return ret; | 730 | return ret; |
764 | } | 731 | } |
765 | 732 | ||
@@ -767,13 +734,8 @@ static int i2c_pnx_remove(struct platform_device *pdev) | |||
767 | { | 734 | { |
768 | struct i2c_pnx_algo_data *alg_data = platform_get_drvdata(pdev); | 735 | struct i2c_pnx_algo_data *alg_data = platform_get_drvdata(pdev); |
769 | 736 | ||
770 | free_irq(alg_data->irq, alg_data); | ||
771 | i2c_del_adapter(&alg_data->adapter); | 737 | i2c_del_adapter(&alg_data->adapter); |
772 | clk_disable(alg_data->clk); | 738 | clk_disable(alg_data->clk); |
773 | iounmap(alg_data->ioaddr); | ||
774 | release_mem_region(alg_data->base, I2C_PNX_REGION_SIZE); | ||
775 | clk_put(alg_data->clk); | ||
776 | kfree(alg_data); | ||
777 | 739 | ||
778 | return 0; | 740 | return 0; |
779 | } | 741 | } |