diff options
author | Masahiro Yamada <yamada.masahiro@socionext.com> | 2016-06-14 06:07:07 -0400 |
---|---|---|
committer | Linus Walleij <linus.walleij@linaro.org> | 2016-06-23 05:07:12 -0400 |
commit | 99468c1af913bb5662c223b68e783b4bf9200184 (patch) | |
tree | be0e9fc9480a7966d314c5651205e60307b5e641 | |
parent | 762c2e46c0591d207289105c8718e4adf29b2b34 (diff) |
gpio: of: factor out common code to a new helper function
The conversion from a DT spec to struct gpio_desc is common between
of_get_named_gpiod_flags() and of_parse_own_gpio(). Factor out the
common code to a new helper, of_xlate_and_get_gpiod_flags().
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
-rw-r--r-- | drivers/gpio/gpiolib-of.c | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index 9f86275a57b5..a28feb3edf33 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c | |||
@@ -36,6 +36,22 @@ static struct gpio_chip *of_find_gpiochip_by_node(struct device_node *np) | |||
36 | return gpiochip_find(np, of_gpiochip_match_node); | 36 | return gpiochip_find(np, of_gpiochip_match_node); |
37 | } | 37 | } |
38 | 38 | ||
39 | static struct gpio_desc *of_xlate_and_get_gpiod_flags(struct gpio_chip *chip, | ||
40 | struct of_phandle_args *gpiospec, | ||
41 | enum of_gpio_flags *flags) | ||
42 | { | ||
43 | int ret; | ||
44 | |||
45 | if (chip->of_gpio_n_cells != gpiospec->args_count) | ||
46 | return ERR_PTR(-EINVAL); | ||
47 | |||
48 | ret = chip->of_xlate(chip, gpiospec, flags); | ||
49 | if (ret < 0) | ||
50 | return ERR_PTR(ret); | ||
51 | |||
52 | return gpiochip_get_desc(chip, ret); | ||
53 | } | ||
54 | |||
39 | /** | 55 | /** |
40 | * of_get_named_gpiod_flags() - Get a GPIO descriptor and flags for GPIO API | 56 | * of_get_named_gpiod_flags() - Get a GPIO descriptor and flags for GPIO API |
41 | * @np: device node to get GPIO from | 57 | * @np: device node to get GPIO from |
@@ -68,18 +84,8 @@ struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np, | |||
68 | desc = ERR_PTR(-EPROBE_DEFER); | 84 | desc = ERR_PTR(-EPROBE_DEFER); |
69 | goto out; | 85 | goto out; |
70 | } | 86 | } |
71 | if (chip->of_gpio_n_cells != gpiospec.args_count) { | ||
72 | desc = ERR_PTR(-EINVAL); | ||
73 | goto out; | ||
74 | } | ||
75 | |||
76 | ret = chip->of_xlate(chip, &gpiospec, flags); | ||
77 | if (ret < 0) { | ||
78 | desc = ERR_PTR(ret); | ||
79 | goto out; | ||
80 | } | ||
81 | 87 | ||
82 | desc = gpiochip_get_desc(chip, ret); | 88 | desc = of_xlate_and_get_gpiod_flags(chip, &gpiospec, flags); |
83 | if (IS_ERR(desc)) | 89 | if (IS_ERR(desc)) |
84 | goto out; | 90 | goto out; |
85 | 91 | ||
@@ -144,9 +150,6 @@ static struct gpio_desc *of_parse_own_gpio(struct device_node *np, | |||
144 | if (ret) | 150 | if (ret) |
145 | return ERR_PTR(ret); | 151 | return ERR_PTR(ret); |
146 | 152 | ||
147 | if (tmp != chip->of_gpio_n_cells) | ||
148 | return ERR_PTR(-EINVAL); | ||
149 | |||
150 | gpiospec.np = chip_np; | 153 | gpiospec.np = chip_np; |
151 | gpiospec.args_count = tmp; | 154 | gpiospec.args_count = tmp; |
152 | 155 | ||
@@ -154,11 +157,7 @@ static struct gpio_desc *of_parse_own_gpio(struct device_node *np, | |||
154 | if (ret) | 157 | if (ret) |
155 | return ERR_PTR(ret); | 158 | return ERR_PTR(ret); |
156 | 159 | ||
157 | ret = chip->of_xlate(chip, &gpiospec, &xlate_flags); | 160 | desc = of_xlate_and_get_gpiod_flags(chip, &gpiospec, &xlate_flags); |
158 | if (ret < 0) | ||
159 | return ERR_PTR(ret); | ||
160 | |||
161 | desc = gpiochip_get_desc(chip, ret); | ||
162 | if (IS_ERR(desc)) | 161 | if (IS_ERR(desc)) |
163 | return desc; | 162 | return desc; |
164 | 163 | ||