aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMasahiro Yamada <yamada.masahiro@socionext.com>2016-06-14 06:07:04 -0400
committerLinus Walleij <linus.walleij@linaro.org>2016-06-23 05:07:10 -0400
commitbe715343011b80a8da71ff978b50981984f037b9 (patch)
tree413c219d1be5c0fce5c291748de767df62fdc322
parent3f9547e1c9f06219c5788668ea2f7495d3b13f60 (diff)
gpio: of: drop needless gpio_chip look-up in of_parse_own_gpio()
This function is doing more complicated than needed. The caller of this function, of_gpiochip_scan_gpios() already knows the pointer to the gpio_chip. It can pass it to of_parse_own_gpio() instead of looking up the gpio_chip by gpiochip_find(). 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.c39
1 files changed, 20 insertions, 19 deletions
diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index 6b866fc4657d..37a3221d67dc 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -121,6 +121,7 @@ EXPORT_SYMBOL(of_get_named_gpio_flags);
121/** 121/**
122 * of_parse_own_gpio() - Get a GPIO hog descriptor, names and flags for GPIO API 122 * of_parse_own_gpio() - Get a GPIO hog descriptor, names and flags for GPIO API
123 * @np: device node to get GPIO from 123 * @np: device node to get GPIO from
124 * @chip: GPIO chip whose hog is parsed
124 * @name: GPIO line name 125 * @name: GPIO line name
125 * @lflags: gpio_lookup_flags - returned from of_find_gpio() or 126 * @lflags: gpio_lookup_flags - returned from of_find_gpio() or
126 * of_parse_own_gpio() 127 * of_parse_own_gpio()
@@ -130,19 +131,19 @@ EXPORT_SYMBOL(of_get_named_gpio_flags);
130 * value on the error condition. 131 * value on the error condition.
131 */ 132 */
132static struct gpio_desc *of_parse_own_gpio(struct device_node *np, 133static struct gpio_desc *of_parse_own_gpio(struct device_node *np,
134 struct gpio_chip *chip,
133 const char **name, 135 const char **name,
134 enum gpio_lookup_flags *lflags, 136 enum gpio_lookup_flags *lflags,
135 enum gpiod_flags *dflags) 137 enum gpiod_flags *dflags)
136{ 138{
137 struct device_node *chip_np; 139 struct device_node *chip_np;
138 enum of_gpio_flags xlate_flags; 140 enum of_gpio_flags xlate_flags;
139 struct gg_data gg_data = { 141 struct of_phandle_args gpiospec;
140 .flags = &xlate_flags, 142 struct gpio_desc *desc;
141 };
142 u32 tmp; 143 u32 tmp;
143 int ret; 144 int ret;
144 145
145 chip_np = np->parent; 146 chip_np = chip->of_node;
146 if (!chip_np) 147 if (!chip_np)
147 return ERR_PTR(-EINVAL); 148 return ERR_PTR(-EINVAL);
148 149
@@ -154,23 +155,23 @@ static struct gpio_desc *of_parse_own_gpio(struct device_node *np,
154 if (ret) 155 if (ret)
155 return ERR_PTR(ret); 156 return ERR_PTR(ret);
156 157
157 if (tmp > MAX_PHANDLE_ARGS) 158 if (tmp > MAX_PHANDLE_ARGS || tmp != chip->of_gpio_n_cells)
158 return ERR_PTR(-EINVAL); 159 return ERR_PTR(-EINVAL);
159 160
160 gg_data.gpiospec.args_count = tmp; 161 gpiospec.np = chip_np;
161 gg_data.gpiospec.np = chip_np; 162 gpiospec.args_count = tmp;
162 ret = of_property_read_u32_array(np, "gpios", gg_data.gpiospec.args, 163
163 tmp); 164 ret = of_property_read_u32_array(np, "gpios", gpiospec.args, tmp);
164 if (ret) 165 if (ret)
165 return ERR_PTR(ret); 166 return ERR_PTR(ret);
166 167
167 gpiochip_find(&gg_data, of_gpiochip_find_and_xlate); 168 ret = chip->of_xlate(chip, &gpiospec, &xlate_flags);
168 if (!gg_data.out_gpio) { 169 if (ret < 0)
169 if (np->parent == np) 170 return ERR_PTR(ret);
170 return ERR_PTR(-ENXIO); 171
171 else 172 desc = gpiochip_get_desc(chip, ret);
172 return ERR_PTR(-EINVAL); 173 if (IS_ERR(desc))
173 } 174 return desc;
174 175
175 if (xlate_flags & OF_GPIO_ACTIVE_LOW) 176 if (xlate_flags & OF_GPIO_ACTIVE_LOW)
176 *lflags |= GPIO_ACTIVE_LOW; 177 *lflags |= GPIO_ACTIVE_LOW;
@@ -183,14 +184,14 @@ static struct gpio_desc *of_parse_own_gpio(struct device_node *np,
183 *dflags |= GPIOD_OUT_HIGH; 184 *dflags |= GPIOD_OUT_HIGH;
184 else { 185 else {
185 pr_warn("GPIO line %d (%s): no hogging state specified, bailing out\n", 186 pr_warn("GPIO line %d (%s): no hogging state specified, bailing out\n",
186 desc_to_gpio(gg_data.out_gpio), np->name); 187 desc_to_gpio(desc), np->name);
187 return ERR_PTR(-EINVAL); 188 return ERR_PTR(-EINVAL);
188 } 189 }
189 190
190 if (name && of_property_read_string(np, "line-name", name)) 191 if (name && of_property_read_string(np, "line-name", name))
191 *name = np->name; 192 *name = np->name;
192 193
193 return gg_data.out_gpio; 194 return desc;
194} 195}
195 196
196/** 197/**
@@ -259,7 +260,7 @@ static int of_gpiochip_scan_gpios(struct gpio_chip *chip)
259 if (!of_property_read_bool(np, "gpio-hog")) 260 if (!of_property_read_bool(np, "gpio-hog"))
260 continue; 261 continue;
261 262
262 desc = of_parse_own_gpio(np, &name, &lflags, &dflags); 263 desc = of_parse_own_gpio(np, chip, &name, &lflags, &dflags);
263 if (IS_ERR(desc)) 264 if (IS_ERR(desc))
264 continue; 265 continue;
265 266