diff options
author | Patrice Chotard <patrice.chotard@st.com> | 2013-06-20 10:05:44 -0400 |
---|---|---|
committer | Linus Walleij <linus.walleij@linaro.org> | 2013-06-24 07:33:21 -0400 |
commit | 8b5abd18e28d0eaadf62e2d51eac053cdab9045a (patch) | |
tree | 12eea843ecb80d05086d634e8c074e2ec1a440dc /drivers/pinctrl/pinctrl-abx500.c | |
parent | d8d4f7f875bb8f94c52583a788e456eabbd6281a (diff) |
pinctrl: abx500: factorize code
Factorize code by adding abx500_pullud_supported()
which improve code readability.
Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/pinctrl/pinctrl-abx500.c')
-rw-r--r-- | drivers/pinctrl/pinctrl-abx500.c | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/drivers/pinctrl/pinctrl-abx500.c b/drivers/pinctrl/pinctrl-abx500.c index d9d7ffc35c3e..c3f2b4baeed2 100644 --- a/drivers/pinctrl/pinctrl-abx500.c +++ b/drivers/pinctrl/pinctrl-abx500.c | |||
@@ -267,12 +267,21 @@ out: | |||
267 | return ret; | 267 | return ret; |
268 | } | 268 | } |
269 | 269 | ||
270 | static bool abx500_pullud_supported(struct gpio_chip *chip, unsigned gpio) | ||
271 | { | ||
272 | struct abx500_pinctrl *pct = to_abx500_pinctrl(chip); | ||
273 | struct pullud *pullud = pct->soc->pullud; | ||
274 | |||
275 | return (pullud && | ||
276 | gpio >= pullud->first_pin && | ||
277 | gpio <= pullud->last_pin); | ||
278 | } | ||
279 | |||
270 | static int abx500_gpio_direction_output(struct gpio_chip *chip, | 280 | static int abx500_gpio_direction_output(struct gpio_chip *chip, |
271 | unsigned offset, | 281 | unsigned offset, |
272 | int val) | 282 | int val) |
273 | { | 283 | { |
274 | struct abx500_pinctrl *pct = to_abx500_pinctrl(chip); | 284 | struct abx500_pinctrl *pct = to_abx500_pinctrl(chip); |
275 | struct pullud *pullud = pct->soc->pullud; | ||
276 | unsigned gpio; | 285 | unsigned gpio; |
277 | int ret; | 286 | int ret; |
278 | 287 | ||
@@ -288,7 +297,7 @@ static int abx500_gpio_direction_output(struct gpio_chip *chip, | |||
288 | 297 | ||
289 | /* if supported, disable both pull down and pull up */ | 298 | /* if supported, disable both pull down and pull up */ |
290 | gpio = offset + 1; | 299 | gpio = offset + 1; |
291 | if (pullud && gpio >= pullud->first_pin && gpio <= pullud->last_pin) { | 300 | if (abx500_pullud_supported(chip, gpio)) { |
292 | ret = abx500_set_pull_updown(pct, | 301 | ret = abx500_set_pull_updown(pct, |
293 | gpio, | 302 | gpio, |
294 | ABX500_GPIO_PULL_NONE); | 303 | ABX500_GPIO_PULL_NONE); |
@@ -514,7 +523,6 @@ static void abx500_gpio_dbg_show_one(struct seq_file *s, | |||
514 | unsigned offset, unsigned gpio) | 523 | unsigned offset, unsigned gpio) |
515 | { | 524 | { |
516 | struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev); | 525 | struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev); |
517 | struct pullud *pullud = pct->soc->pullud; | ||
518 | const char *label = gpiochip_is_requested(chip, offset - 1); | 526 | const char *label = gpiochip_is_requested(chip, offset - 1); |
519 | u8 gpio_offset = offset - 1; | 527 | u8 gpio_offset = offset - 1; |
520 | int mode = -1; | 528 | int mode = -1; |
@@ -543,9 +551,7 @@ static void abx500_gpio_dbg_show_one(struct seq_file *s, | |||
543 | is_out ? "out" : "in "); | 551 | is_out ? "out" : "in "); |
544 | 552 | ||
545 | if (!is_out) { | 553 | if (!is_out) { |
546 | if (pullud && | 554 | if (abx500_pullud_supported(chip, offset)) { |
547 | (offset >= pullud->first_pin) && | ||
548 | (offset <= pullud->last_pin)) { | ||
549 | abx500_get_pull_updown(pct, offset, &pud); | 555 | abx500_get_pull_updown(pct, offset, &pud); |
550 | seq_printf(s, " %-9s", pull_up_down[pud]); | 556 | seq_printf(s, " %-9s", pull_up_down[pud]); |
551 | } else { | 557 | } else { |
@@ -974,7 +980,6 @@ static int abx500_pin_config_set(struct pinctrl_dev *pctldev, | |||
974 | unsigned long config) | 980 | unsigned long config) |
975 | { | 981 | { |
976 | struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev); | 982 | struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev); |
977 | struct pullud *pullud = pct->soc->pullud; | ||
978 | struct gpio_chip *chip = &pct->chip; | 983 | struct gpio_chip *chip = &pct->chip; |
979 | unsigned offset; | 984 | unsigned offset; |
980 | int ret = -EINVAL; | 985 | int ret = -EINVAL; |
@@ -999,9 +1004,7 @@ static int abx500_pin_config_set(struct pinctrl_dev *pctldev, | |||
999 | * both features. If the pin is not within that range, we | 1004 | * both features. If the pin is not within that range, we |
1000 | * fall back to the old bit set that only support pull down. | 1005 | * fall back to the old bit set that only support pull down. |
1001 | */ | 1006 | */ |
1002 | if (pullud && | 1007 | if (abx500_pullud_supported(chip, pin)) |
1003 | pin >= pullud->first_pin && | ||
1004 | pin <= pullud->last_pin) | ||
1005 | ret = abx500_set_pull_updown(pct, | 1008 | ret = abx500_set_pull_updown(pct, |
1006 | pin, | 1009 | pin, |
1007 | ABX500_GPIO_PULL_NONE); | 1010 | ABX500_GPIO_PULL_NONE); |
@@ -1022,9 +1025,7 @@ static int abx500_pin_config_set(struct pinctrl_dev *pctldev, | |||
1022 | * both features. If the pin is not within that range, we | 1025 | * both features. If the pin is not within that range, we |
1023 | * fall back to the old bit set that only support pull down. | 1026 | * fall back to the old bit set that only support pull down. |
1024 | */ | 1027 | */ |
1025 | if (pullud && | 1028 | if (abx500_pullud_supported(chip, pin)) |
1026 | pin >= pullud->first_pin && | ||
1027 | pin <= pullud->last_pin) | ||
1028 | ret = abx500_set_pull_updown(pct, | 1029 | ret = abx500_set_pull_updown(pct, |
1029 | pin, | 1030 | pin, |
1030 | argument ? ABX500_GPIO_PULL_DOWN : ABX500_GPIO_PULL_NONE); | 1031 | argument ? ABX500_GPIO_PULL_DOWN : ABX500_GPIO_PULL_NONE); |
@@ -1048,13 +1049,10 @@ static int abx500_pin_config_set(struct pinctrl_dev *pctldev, | |||
1048 | * both features. If the pin is not within that range, do | 1049 | * both features. If the pin is not within that range, do |
1049 | * nothing | 1050 | * nothing |
1050 | */ | 1051 | */ |
1051 | if (pullud && | 1052 | if (abx500_pullud_supported(chip, pin)) |
1052 | pin >= pullud->first_pin && | ||
1053 | pin <= pullud->last_pin) { | ||
1054 | ret = abx500_set_pull_updown(pct, | 1053 | ret = abx500_set_pull_updown(pct, |
1055 | pin, | 1054 | pin, |
1056 | argument ? ABX500_GPIO_PULL_UP : ABX500_GPIO_PULL_NONE); | 1055 | argument ? ABX500_GPIO_PULL_UP : ABX500_GPIO_PULL_NONE); |
1057 | } | ||
1058 | break; | 1056 | break; |
1059 | 1057 | ||
1060 | case PIN_CONFIG_OUTPUT: | 1058 | case PIN_CONFIG_OUTPUT: |