提交 8b5abd18 编写于 作者: P Patrice Chotard 提交者: Linus Walleij

pinctrl: abx500: factorize code

Factorize code by adding abx500_pullud_supported()
which improve code readability.
Signed-off-by: NPatrice Chotard <patrice.chotard@st.com>
Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
上级 d8d4f7f8
...@@ -267,12 +267,21 @@ static int abx500_set_pull_updown(struct abx500_pinctrl *pct, ...@@ -267,12 +267,21 @@ static int abx500_set_pull_updown(struct abx500_pinctrl *pct,
return ret; return ret;
} }
static bool abx500_pullud_supported(struct gpio_chip *chip, unsigned gpio)
{
struct abx500_pinctrl *pct = to_abx500_pinctrl(chip);
struct pullud *pullud = pct->soc->pullud;
return (pullud &&
gpio >= pullud->first_pin &&
gpio <= pullud->last_pin);
}
static int abx500_gpio_direction_output(struct gpio_chip *chip, static int abx500_gpio_direction_output(struct gpio_chip *chip,
unsigned offset, unsigned offset,
int val) int val)
{ {
struct abx500_pinctrl *pct = to_abx500_pinctrl(chip); struct abx500_pinctrl *pct = to_abx500_pinctrl(chip);
struct pullud *pullud = pct->soc->pullud;
unsigned gpio; unsigned gpio;
int ret; int ret;
...@@ -288,7 +297,7 @@ static int abx500_gpio_direction_output(struct gpio_chip *chip, ...@@ -288,7 +297,7 @@ static int abx500_gpio_direction_output(struct gpio_chip *chip,
/* if supported, disable both pull down and pull up */ /* if supported, disable both pull down and pull up */
gpio = offset + 1; gpio = offset + 1;
if (pullud && gpio >= pullud->first_pin && gpio <= pullud->last_pin) { if (abx500_pullud_supported(chip, gpio)) {
ret = abx500_set_pull_updown(pct, ret = abx500_set_pull_updown(pct,
gpio, gpio,
ABX500_GPIO_PULL_NONE); ABX500_GPIO_PULL_NONE);
...@@ -514,7 +523,6 @@ static void abx500_gpio_dbg_show_one(struct seq_file *s, ...@@ -514,7 +523,6 @@ static void abx500_gpio_dbg_show_one(struct seq_file *s,
unsigned offset, unsigned gpio) unsigned offset, unsigned gpio)
{ {
struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev); struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
struct pullud *pullud = pct->soc->pullud;
const char *label = gpiochip_is_requested(chip, offset - 1); const char *label = gpiochip_is_requested(chip, offset - 1);
u8 gpio_offset = offset - 1; u8 gpio_offset = offset - 1;
int mode = -1; int mode = -1;
...@@ -543,9 +551,7 @@ static void abx500_gpio_dbg_show_one(struct seq_file *s, ...@@ -543,9 +551,7 @@ static void abx500_gpio_dbg_show_one(struct seq_file *s,
is_out ? "out" : "in "); is_out ? "out" : "in ");
if (!is_out) { if (!is_out) {
if (pullud && if (abx500_pullud_supported(chip, offset)) {
(offset >= pullud->first_pin) &&
(offset <= pullud->last_pin)) {
abx500_get_pull_updown(pct, offset, &pud); abx500_get_pull_updown(pct, offset, &pud);
seq_printf(s, " %-9s", pull_up_down[pud]); seq_printf(s, " %-9s", pull_up_down[pud]);
} else { } else {
...@@ -974,7 +980,6 @@ static int abx500_pin_config_set(struct pinctrl_dev *pctldev, ...@@ -974,7 +980,6 @@ static int abx500_pin_config_set(struct pinctrl_dev *pctldev,
unsigned long config) unsigned long config)
{ {
struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev); struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
struct pullud *pullud = pct->soc->pullud;
struct gpio_chip *chip = &pct->chip; struct gpio_chip *chip = &pct->chip;
unsigned offset; unsigned offset;
int ret = -EINVAL; int ret = -EINVAL;
...@@ -999,9 +1004,7 @@ static int abx500_pin_config_set(struct pinctrl_dev *pctldev, ...@@ -999,9 +1004,7 @@ static int abx500_pin_config_set(struct pinctrl_dev *pctldev,
* both features. If the pin is not within that range, we * both features. If the pin is not within that range, we
* fall back to the old bit set that only support pull down. * fall back to the old bit set that only support pull down.
*/ */
if (pullud && if (abx500_pullud_supported(chip, pin))
pin >= pullud->first_pin &&
pin <= pullud->last_pin)
ret = abx500_set_pull_updown(pct, ret = abx500_set_pull_updown(pct,
pin, pin,
ABX500_GPIO_PULL_NONE); ABX500_GPIO_PULL_NONE);
...@@ -1022,9 +1025,7 @@ static int abx500_pin_config_set(struct pinctrl_dev *pctldev, ...@@ -1022,9 +1025,7 @@ static int abx500_pin_config_set(struct pinctrl_dev *pctldev,
* both features. If the pin is not within that range, we * both features. If the pin is not within that range, we
* fall back to the old bit set that only support pull down. * fall back to the old bit set that only support pull down.
*/ */
if (pullud && if (abx500_pullud_supported(chip, pin))
pin >= pullud->first_pin &&
pin <= pullud->last_pin)
ret = abx500_set_pull_updown(pct, ret = abx500_set_pull_updown(pct,
pin, pin,
argument ? ABX500_GPIO_PULL_DOWN : ABX500_GPIO_PULL_NONE); argument ? ABX500_GPIO_PULL_DOWN : ABX500_GPIO_PULL_NONE);
...@@ -1048,13 +1049,10 @@ static int abx500_pin_config_set(struct pinctrl_dev *pctldev, ...@@ -1048,13 +1049,10 @@ static int abx500_pin_config_set(struct pinctrl_dev *pctldev,
* both features. If the pin is not within that range, do * both features. If the pin is not within that range, do
* nothing * nothing
*/ */
if (pullud && if (abx500_pullud_supported(chip, pin))
pin >= pullud->first_pin &&
pin <= pullud->last_pin) {
ret = abx500_set_pull_updown(pct, ret = abx500_set_pull_updown(pct,
pin, pin,
argument ? ABX500_GPIO_PULL_UP : ABX500_GPIO_PULL_NONE); argument ? ABX500_GPIO_PULL_UP : ABX500_GPIO_PULL_NONE);
}
break; break;
case PIN_CONFIG_OUTPUT: case PIN_CONFIG_OUTPUT:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册