aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2013-06-05 09:38:02 -0400
committerLinus Walleij <linus.walleij@linaro.org>2013-06-16 05:56:52 -0400
commitac844b62713045557c834c8d5fe2863b8bbaf124 (patch)
tree33b5d914b373beccc6e591bf22eb14a88d26c862 /drivers/i2c
parent2b996fc50099f55d441470b55acc40c61f947025 (diff)
i2c: nomadik: use pinctrl PM helpers
This utilize the new pinctrl core PM helpers to transition the driver to "sleep" and "idle" states, cutting away some boilerplate code. Cc: Hebbar Gururaja <gururaja.hebbar@ti.com> Cc: Mark Brown <broonie@kernel.org> Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com> Cc: Kevin Hilman <khilman@linaro.org> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Stephen Warren <swarren@wwwdotorg.org> Acked-by: Wolfram Sang <wsa@the-dreams.de> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/i2c')
-rw-r--r--drivers/i2c/busses/i2c-nomadik.c90
1 files changed, 10 insertions, 80 deletions
diff --git a/drivers/i2c/busses/i2c-nomadik.c b/drivers/i2c/busses/i2c-nomadik.c
index 650293ff4d62..c7e3b0c1a1ca 100644
--- a/drivers/i2c/busses/i2c-nomadik.c
+++ b/drivers/i2c/busses/i2c-nomadik.c
@@ -148,10 +148,6 @@ struct i2c_nmk_client {
148 * @stop: stop condition. 148 * @stop: stop condition.
149 * @xfer_complete: acknowledge completion for a I2C message. 149 * @xfer_complete: acknowledge completion for a I2C message.
150 * @result: controller propogated result. 150 * @result: controller propogated result.
151 * @pinctrl: pinctrl handle.
152 * @pins_default: default state for the pins.
153 * @pins_idle: idle state for the pins.
154 * @pins_sleep: sleep state for the pins.
155 * @busy: Busy doing transfer. 151 * @busy: Busy doing transfer.
156 */ 152 */
157struct nmk_i2c_dev { 153struct nmk_i2c_dev {
@@ -165,11 +161,6 @@ struct nmk_i2c_dev {
165 int stop; 161 int stop;
166 struct completion xfer_complete; 162 struct completion xfer_complete;
167 int result; 163 int result;
168 /* Three pin states - default, idle & sleep */
169 struct pinctrl *pinctrl;
170 struct pinctrl_state *pins_default;
171 struct pinctrl_state *pins_idle;
172 struct pinctrl_state *pins_sleep;
173 bool busy; 164 bool busy;
174}; 165};
175 166
@@ -645,13 +636,7 @@ static int nmk_i2c_xfer(struct i2c_adapter *i2c_adap,
645 } 636 }
646 637
647 /* Optionaly enable pins to be muxed in and configured */ 638 /* Optionaly enable pins to be muxed in and configured */
648 if (!IS_ERR(dev->pins_default)) { 639 pinctrl_pm_select_default_state(&dev->adev->dev);
649 status = pinctrl_select_state(dev->pinctrl,
650 dev->pins_default);
651 if (status)
652 dev_err(&dev->adev->dev,
653 "could not set default pins\n");
654 }
655 640
656 status = init_hw(dev); 641 status = init_hw(dev);
657 if (status) 642 if (status)
@@ -681,13 +666,7 @@ out:
681 clk_disable_unprepare(dev->clk); 666 clk_disable_unprepare(dev->clk);
682out_clk: 667out_clk:
683 /* Optionally let pins go into idle state */ 668 /* Optionally let pins go into idle state */
684 if (!IS_ERR(dev->pins_idle)) { 669 pinctrl_pm_select_idle_state(&dev->adev->dev);
685 status = pinctrl_select_state(dev->pinctrl,
686 dev->pins_idle);
687 if (status)
688 dev_err(&dev->adev->dev,
689 "could not set pins to idle state\n");
690 }
691 670
692 pm_runtime_put_sync(&dev->adev->dev); 671 pm_runtime_put_sync(&dev->adev->dev);
693 672
@@ -882,41 +861,22 @@ static int nmk_i2c_suspend(struct device *dev)
882{ 861{
883 struct amba_device *adev = to_amba_device(dev); 862 struct amba_device *adev = to_amba_device(dev);
884 struct nmk_i2c_dev *nmk_i2c = amba_get_drvdata(adev); 863 struct nmk_i2c_dev *nmk_i2c = amba_get_drvdata(adev);
885 int ret;
886 864
887 if (nmk_i2c->busy) 865 if (nmk_i2c->busy)
888 return -EBUSY; 866 return -EBUSY;
889 867
890 if (!IS_ERR(nmk_i2c->pins_sleep)) { 868 pinctrl_pm_select_sleep_state(dev);
891 ret = pinctrl_select_state(nmk_i2c->pinctrl,
892 nmk_i2c->pins_sleep);
893 if (ret)
894 dev_err(dev, "could not set pins to sleep state\n");
895 }
896 869
897 return 0; 870 return 0;
898} 871}
899 872
900static int nmk_i2c_resume(struct device *dev) 873static int nmk_i2c_resume(struct device *dev)
901{ 874{
902 struct amba_device *adev = to_amba_device(dev);
903 struct nmk_i2c_dev *nmk_i2c = amba_get_drvdata(adev);
904 int ret;
905
906 /* First go to the default state */ 875 /* First go to the default state */
907 if (!IS_ERR(nmk_i2c->pins_default)) { 876 pinctrl_pm_select_default_state(dev);
908 ret = pinctrl_select_state(nmk_i2c->pinctrl,
909 nmk_i2c->pins_default);
910 if (ret)
911 dev_err(dev, "could not set pins to default state\n");
912 }
913 /* Then let's idle the pins until the next transfer happens */ 877 /* Then let's idle the pins until the next transfer happens */
914 if (!IS_ERR(nmk_i2c->pins_idle)) { 878 pinctrl_pm_select_idle_state(dev);
915 ret = pinctrl_select_state(nmk_i2c->pinctrl, 879
916 nmk_i2c->pins_idle);
917 if (ret)
918 dev_err(dev, "could not set pins to idle state\n");
919 }
920 return 0; 880 return 0;
921} 881}
922#else 882#else
@@ -1004,39 +964,10 @@ static int nmk_i2c_probe(struct amba_device *adev, const struct amba_id *id)
1004 dev->adev = adev; 964 dev->adev = adev;
1005 amba_set_drvdata(adev, dev); 965 amba_set_drvdata(adev, dev);
1006 966
1007 dev->pinctrl = devm_pinctrl_get(&adev->dev); 967 /* Select default pin state */
1008 if (IS_ERR(dev->pinctrl)) { 968 pinctrl_pm_select_default_state(&adev->dev);
1009 ret = PTR_ERR(dev->pinctrl); 969 /* If possible, let's go to idle until the first transfer */
1010 goto err_pinctrl; 970 pinctrl_pm_select_idle_state(&adev->dev);
1011 }
1012
1013 dev->pins_default = pinctrl_lookup_state(dev->pinctrl,
1014 PINCTRL_STATE_DEFAULT);
1015 if (IS_ERR(dev->pins_default)) {
1016 dev_err(&adev->dev, "could not get default pinstate\n");
1017 } else {
1018 ret = pinctrl_select_state(dev->pinctrl,
1019 dev->pins_default);
1020 if (ret)
1021 dev_dbg(&adev->dev, "could not set default pinstate\n");
1022 }
1023
1024 dev->pins_idle = pinctrl_lookup_state(dev->pinctrl,
1025 PINCTRL_STATE_IDLE);
1026 if (IS_ERR(dev->pins_idle)) {
1027 dev_dbg(&adev->dev, "could not get idle pinstate\n");
1028 } else {
1029 /* If possible, let's go to idle until the first transfer */
1030 ret = pinctrl_select_state(dev->pinctrl,
1031 dev->pins_idle);
1032 if (ret)
1033 dev_dbg(&adev->dev, "could not set idle pinstate\n");
1034 }
1035
1036 dev->pins_sleep = pinctrl_lookup_state(dev->pinctrl,
1037 PINCTRL_STATE_SLEEP);
1038 if (IS_ERR(dev->pins_sleep))
1039 dev_dbg(&adev->dev, "could not get sleep pinstate\n");
1040 971
1041 dev->virtbase = ioremap(adev->res.start, resource_size(&adev->res)); 972 dev->virtbase = ioremap(adev->res.start, resource_size(&adev->res));
1042 if (!dev->virtbase) { 973 if (!dev->virtbase) {
@@ -1106,7 +1037,6 @@ static int nmk_i2c_probe(struct amba_device *adev, const struct amba_id *id)
1106 iounmap(dev->virtbase); 1037 iounmap(dev->virtbase);
1107 err_no_ioremap: 1038 err_no_ioremap:
1108 kfree(dev); 1039 kfree(dev);
1109 err_pinctrl:
1110 err_no_mem: 1040 err_no_mem:
1111 1041
1112 return ret; 1042 return ret;