aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c/busses/i2c-nomadik.c
diff options
context:
space:
mode:
authorUlf Hansson <ulf.hansson@linaro.org>2014-02-17 10:20:41 -0500
committerWolfram Sang <wsa@the-dreams.de>2014-03-05 11:10:32 -0500
commite46d397550835fc41eeaee08afb37ddeb6a01e72 (patch)
tree3b9e2e2905afc128af8905656ddd91146e7d31cc /drivers/i2c/busses/i2c-nomadik.c
parent0ec80c29a3c6339a840a797e4fc9cfdb419fbb3f (diff)
i2c: nomadik: Fixup deployment of runtime PM
Since the runtime PM state is expected to be active according to the amba bus, we must align our behaviour while probing to it. Moreover, this is needed to be able to have the driver fully functional without depending on CONFIG_RUNTIME_PM. Since the device is active while a successful probe has been completed, the reference counting for the clock will be screwed up and never reach zero. We resolve this by implementing runtime PM callbacks and let them handle the resources accordingly, including the clock. Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org> [wsa: s/#if/#ifdef/] Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
Diffstat (limited to 'drivers/i2c/busses/i2c-nomadik.c')
-rw-r--r--drivers/i2c/busses/i2c-nomadik.c77
1 files changed, 51 insertions, 26 deletions
diff --git a/drivers/i2c/busses/i2c-nomadik.c b/drivers/i2c/busses/i2c-nomadik.c
index ce835e80a0fd..6319f449804e 100644
--- a/drivers/i2c/busses/i2c-nomadik.c
+++ b/drivers/i2c/busses/i2c-nomadik.c
@@ -666,7 +666,7 @@ static int nmk_i2c_xfer_one(struct nmk_i2c_dev *dev, u16 flags)
666static int nmk_i2c_xfer(struct i2c_adapter *i2c_adap, 666static int nmk_i2c_xfer(struct i2c_adapter *i2c_adap,
667 struct i2c_msg msgs[], int num_msgs) 667 struct i2c_msg msgs[], int num_msgs)
668{ 668{
669 int status; 669 int status = 0;
670 int i; 670 int i;
671 struct nmk_i2c_dev *dev = i2c_get_adapdata(i2c_adap); 671 struct nmk_i2c_dev *dev = i2c_get_adapdata(i2c_adap);
672 int j; 672 int j;
@@ -675,19 +675,6 @@ static int nmk_i2c_xfer(struct i2c_adapter *i2c_adap,
675 675
676 pm_runtime_get_sync(&dev->adev->dev); 676 pm_runtime_get_sync(&dev->adev->dev);
677 677
678 status = clk_prepare_enable(dev->clk);
679 if (status) {
680 dev_err(&dev->adev->dev, "can't prepare_enable clock\n");
681 goto out_clk;
682 }
683
684 /* Optionaly enable pins to be muxed in and configured */
685 pinctrl_pm_select_default_state(&dev->adev->dev);
686
687 status = init_hw(dev);
688 if (status)
689 goto out;
690
691 /* Attempt three times to send the message queue */ 678 /* Attempt three times to send the message queue */
692 for (j = 0; j < 3; j++) { 679 for (j = 0; j < 3; j++) {
693 /* setup the i2c controller */ 680 /* setup the i2c controller */
@@ -708,12 +695,6 @@ static int nmk_i2c_xfer(struct i2c_adapter *i2c_adap,
708 break; 695 break;
709 } 696 }
710 697
711out:
712 clk_disable_unprepare(dev->clk);
713out_clk:
714 /* Optionally let pins go into idle state */
715 pinctrl_pm_select_idle_state(&dev->adev->dev);
716
717 pm_runtime_put_sync(&dev->adev->dev); 698 pm_runtime_put_sync(&dev->adev->dev);
718 699
719 dev->busy = false; 700 dev->busy = false;
@@ -930,6 +911,41 @@ static int nmk_i2c_resume(struct device *dev)
930#define nmk_i2c_resume NULL 911#define nmk_i2c_resume NULL
931#endif 912#endif
932 913
914#ifdef CONFIG_PM
915static int nmk_i2c_runtime_suspend(struct device *dev)
916{
917 struct amba_device *adev = to_amba_device(dev);
918 struct nmk_i2c_dev *nmk_i2c = amba_get_drvdata(adev);
919
920 clk_disable_unprepare(nmk_i2c->clk);
921 pinctrl_pm_select_idle_state(dev);
922 return 0;
923}
924
925static int nmk_i2c_runtime_resume(struct device *dev)
926{
927 struct amba_device *adev = to_amba_device(dev);
928 struct nmk_i2c_dev *nmk_i2c = amba_get_drvdata(adev);
929 int ret;
930
931 ret = clk_prepare_enable(nmk_i2c->clk);
932 if (ret) {
933 dev_err(dev, "can't prepare_enable clock\n");
934 return ret;
935 }
936
937 pinctrl_pm_select_default_state(dev);
938
939 ret = init_hw(nmk_i2c);
940 if (ret) {
941 clk_disable_unprepare(nmk_i2c->clk);
942 pinctrl_pm_select_idle_state(dev);
943 }
944
945 return ret;
946}
947#endif
948
933/* 949/*
934 * We use noirq so that we suspend late and resume before the wakeup interrupt 950 * We use noirq so that we suspend late and resume before the wakeup interrupt
935 * to ensure that we do the !pm_runtime_suspended() check in resume before 951 * to ensure that we do the !pm_runtime_suspended() check in resume before
@@ -938,6 +954,9 @@ static int nmk_i2c_resume(struct device *dev)
938static const struct dev_pm_ops nmk_i2c_pm = { 954static const struct dev_pm_ops nmk_i2c_pm = {
939 .suspend_noirq = nmk_i2c_suspend, 955 .suspend_noirq = nmk_i2c_suspend,
940 .resume_noirq = nmk_i2c_resume, 956 .resume_noirq = nmk_i2c_resume,
957 SET_PM_RUNTIME_PM_OPS(nmk_i2c_runtime_suspend,
958 nmk_i2c_runtime_resume,
959 NULL)
941}; 960};
942 961
943static unsigned int nmk_i2c_functionality(struct i2c_adapter *adap) 962static unsigned int nmk_i2c_functionality(struct i2c_adapter *adap)
@@ -1001,11 +1020,6 @@ static int nmk_i2c_probe(struct amba_device *adev, const struct amba_id *id)
1001 1020
1002 amba_set_drvdata(adev, dev); 1021 amba_set_drvdata(adev, dev);
1003 1022
1004 /* Select default pin state */
1005 pinctrl_pm_select_default_state(&adev->dev);
1006 /* If possible, let's go to idle until the first transfer */
1007 pinctrl_pm_select_idle_state(&adev->dev);
1008
1009 dev->virtbase = devm_ioremap(&adev->dev, adev->res.start, 1023 dev->virtbase = devm_ioremap(&adev->dev, adev->res.start,
1010 resource_size(&adev->res)); 1024 resource_size(&adev->res));
1011 if (IS_ERR(dev->virtbase)) { 1025 if (IS_ERR(dev->virtbase)) {
@@ -1030,6 +1044,14 @@ static int nmk_i2c_probe(struct amba_device *adev, const struct amba_id *id)
1030 goto err_no_mem; 1044 goto err_no_mem;
1031 } 1045 }
1032 1046
1047 ret = clk_prepare_enable(dev->clk);
1048 if (ret) {
1049 dev_err(&adev->dev, "can't prepare_enable clock\n");
1050 goto err_no_mem;
1051 }
1052
1053 init_hw(dev);
1054
1033 adap = &dev->adap; 1055 adap = &dev->adap;
1034 adap->dev.of_node = np; 1056 adap->dev.of_node = np;
1035 adap->dev.parent = &adev->dev; 1057 adap->dev.parent = &adev->dev;
@@ -1049,13 +1071,15 @@ static int nmk_i2c_probe(struct amba_device *adev, const struct amba_id *id)
1049 ret = i2c_add_adapter(adap); 1071 ret = i2c_add_adapter(adap);
1050 if (ret) { 1072 if (ret) {
1051 dev_err(&adev->dev, "failed to add adapter\n"); 1073 dev_err(&adev->dev, "failed to add adapter\n");
1052 goto err_no_mem; 1074 goto err_no_adap;
1053 } 1075 }
1054 1076
1055 pm_runtime_put(&adev->dev); 1077 pm_runtime_put(&adev->dev);
1056 1078
1057 return 0; 1079 return 0;
1058 1080
1081 err_no_adap:
1082 clk_disable_unprepare(dev->clk);
1059 err_no_mem: 1083 err_no_mem:
1060 1084
1061 return ret; 1085 return ret;
@@ -1072,6 +1096,7 @@ static int nmk_i2c_remove(struct amba_device *adev)
1072 clear_all_interrupts(dev); 1096 clear_all_interrupts(dev);
1073 /* disable the controller */ 1097 /* disable the controller */
1074 i2c_clr_bit(dev->virtbase + I2C_CR, I2C_CR_PE); 1098 i2c_clr_bit(dev->virtbase + I2C_CR, I2C_CR_PE);
1099 clk_disable_unprepare(dev->clk);
1075 if (res) 1100 if (res)
1076 release_mem_region(res->start, resource_size(res)); 1101 release_mem_region(res->start, resource_size(res));
1077 1102