- error = devm_gpio_request(dev, gpio,
- button->desc ? button->desc : DRV_NAME);
- if (error) {
- dev_err(dev, "unable to claim gpio %u, err=%d\n",
- gpio, error);
- return error;
+ if (gpio_is_valid(button->gpio)) {
+ /* legacy platform data... but is it the lookup table? */
+ bdata->gpiod = devm_gpiod_get_index(dev, desc, i,
+ GPIOD_IN);
+ if (IS_ERR(bdata->gpiod)) {
+ /* or the legacy (button->gpio is good) way? */
+ error = devm_gpio_request_one(dev,
+ button->gpio, GPIOF_IN | (
+ button->active_low ? GPIOF_ACTIVE_LOW :
+ 0), desc);
+ if (error) {
+ if (error != -EPROBE_DEFER) {
+ dev_err(dev, "unable to claim gpio %d, err=%d\n",
+ button->gpio, error);
+ }
+ goto out;
+ }
+
+ bdata->gpiod = gpio_to_desc(button->gpio);
+ }
+ } else {
+ /* Device-tree */
+ struct device_node *child =
+ of_get_next_child(dev->of_node, prev);
+
+ bdata->gpiod = devm_gpiod_get_from_of_node(dev,
+ child, "gpios", 0, GPIOD_IN, desc);
+
+ prev = child;