Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+10 -80
+10 -80
drivers/i2c/busses/i2c-nomadik.c
··· 148 148 * @stop: stop condition. 149 149 * @xfer_complete: acknowledge completion for a I2C message. 150 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 151 * @busy: Busy doing transfer. 156 152 */ 157 153 struct nmk_i2c_dev { ··· 161 165 int stop; 162 166 struct completion xfer_complete; 163 167 int result; 164 - /* Three pin states - default, idle & sleep */ 165 - struct pinctrl *pinctrl; 166 - struct pinctrl_state *pins_default; 167 - struct pinctrl_state *pins_idle; 168 - struct pinctrl_state *pins_sleep; 169 168 bool busy; 170 169 }; 171 170 ··· 636 645 } 637 646 638 647 /* Optionaly enable pins to be muxed in and configured */ 639 - if (!IS_ERR(dev->pins_default)) { 640 - status = pinctrl_select_state(dev->pinctrl, 641 - dev->pins_default); 642 - if (status) 643 - dev_err(&dev->adev->dev, 644 - "could not set default pins\n"); 645 - } 648 + pinctrl_pm_select_default_state(&dev->adev->dev); 646 649 647 650 status = init_hw(dev); 648 651 if (status) ··· 666 681 clk_disable_unprepare(dev->clk); 667 682 out_clk: 668 683 /* Optionally let pins go into idle state */ 669 - if (!IS_ERR(dev->pins_idle)) { 670 - status = pinctrl_select_state(dev->pinctrl, 671 - dev->pins_idle); 672 - if (status) 673 - dev_err(&dev->adev->dev, 674 - "could not set pins to idle state\n"); 675 - } 684 + pinctrl_pm_select_idle_state(&dev->adev->dev); 676 685 677 686 pm_runtime_put_sync(&dev->adev->dev); 678 687 ··· 861 882 { 862 883 struct amba_device *adev = to_amba_device(dev); 863 884 struct nmk_i2c_dev *nmk_i2c = amba_get_drvdata(adev); 864 - int ret; 865 885 866 886 if (nmk_i2c->busy) 867 887 return -EBUSY; 868 888 869 - if (!IS_ERR(nmk_i2c->pins_sleep)) { 870 - ret = pinctrl_select_state(nmk_i2c->pinctrl, 871 - nmk_i2c->pins_sleep); 872 - if (ret) 873 - dev_err(dev, "could not set pins to sleep state\n"); 874 - } 889 + pinctrl_pm_select_sleep_state(dev); 875 890 876 891 return 0; 877 892 } 878 893 879 894 static int nmk_i2c_resume(struct device *dev) 880 895 { 881 - struct amba_device *adev = to_amba_device(dev); 882 - struct nmk_i2c_dev *nmk_i2c = amba_get_drvdata(adev); 883 - int ret; 884 - 885 896 /* First go to the default state */ 886 - if (!IS_ERR(nmk_i2c->pins_default)) { 887 - ret = pinctrl_select_state(nmk_i2c->pinctrl, 888 - nmk_i2c->pins_default); 889 - if (ret) 890 - dev_err(dev, "could not set pins to default state\n"); 891 - } 897 + pinctrl_pm_select_default_state(dev); 892 898 /* Then let's idle the pins until the next transfer happens */ 893 - if (!IS_ERR(nmk_i2c->pins_idle)) { 894 - ret = pinctrl_select_state(nmk_i2c->pinctrl, 895 - nmk_i2c->pins_idle); 896 - if (ret) 897 - dev_err(dev, "could not set pins to idle state\n"); 898 - } 899 + pinctrl_pm_select_idle_state(dev); 900 + 899 901 return 0; 900 902 } 901 903 #else ··· 964 1004 dev->adev = adev; 965 1005 amba_set_drvdata(adev, dev); 966 1006 967 - dev->pinctrl = devm_pinctrl_get(&adev->dev); 968 - if (IS_ERR(dev->pinctrl)) { 969 - ret = PTR_ERR(dev->pinctrl); 970 - goto err_pinctrl; 971 - } 972 - 973 - dev->pins_default = pinctrl_lookup_state(dev->pinctrl, 974 - PINCTRL_STATE_DEFAULT); 975 - if (IS_ERR(dev->pins_default)) { 976 - dev_err(&adev->dev, "could not get default pinstate\n"); 977 - } else { 978 - ret = pinctrl_select_state(dev->pinctrl, 979 - dev->pins_default); 980 - if (ret) 981 - dev_dbg(&adev->dev, "could not set default pinstate\n"); 982 - } 983 - 984 - dev->pins_idle = pinctrl_lookup_state(dev->pinctrl, 985 - PINCTRL_STATE_IDLE); 986 - if (IS_ERR(dev->pins_idle)) { 987 - dev_dbg(&adev->dev, "could not get idle pinstate\n"); 988 - } else { 989 - /* If possible, let's go to idle until the first transfer */ 990 - ret = pinctrl_select_state(dev->pinctrl, 991 - dev->pins_idle); 992 - if (ret) 993 - dev_dbg(&adev->dev, "could not set idle pinstate\n"); 994 - } 995 - 996 - dev->pins_sleep = pinctrl_lookup_state(dev->pinctrl, 997 - PINCTRL_STATE_SLEEP); 998 - if (IS_ERR(dev->pins_sleep)) 999 - dev_dbg(&adev->dev, "could not get sleep pinstate\n"); 1007 + /* Select default pin state */ 1008 + pinctrl_pm_select_default_state(&adev->dev); 1009 + /* If possible, let's go to idle until the first transfer */ 1010 + pinctrl_pm_select_idle_state(&adev->dev); 1000 1011 1001 1012 dev->virtbase = ioremap(adev->res.start, resource_size(&adev->res)); 1002 1013 if (!dev->virtbase) { ··· 1037 1106 iounmap(dev->virtbase); 1038 1107 err_no_ioremap: 1039 1108 kfree(dev); 1040 - err_pinctrl: 1041 1109 err_no_mem: 1042 1110 1043 1111 return ret;