Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
(submitted) input: keyboard: gpio_keys_polled: use gpio lookup table
Support the recently introduced gpio lookup tables for
attaching to gpio lines. So, harcoded gpio numbers aren't
needed anymore.

changes v4:
    * completely rewritten in a much simpler way, now just adding
      a third case (in the button probe loop), where neither oftree
      nor raw gpio number exists.

changes v3:
    * fix printf string in gpio_keys_polled_get_gpiod()
    * fix unused variable 'error' in gpio_keys_polled_get_gpiod()
    * fix uninitialized variable in gpio_keys_polled_get_gpiod_fwnode()

Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: linux-input@vger.kernel.org
Signed-off-by: Enrico Weigelt <info@metux.net>
  • Loading branch information
metux committed Feb 3, 2020
1 parent 01c597f commit 0e0239f
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion drivers/input/keyboard/gpio_keys_polled.c
Expand Up @@ -307,7 +307,7 @@ static int gpio_keys_polled_probe(struct platform_device *pdev)
fwnode_handle_put(child);
return error;
}
} else if (gpio_is_valid(button->gpio)) {
} else if ((button->gpio > 0) && gpio_is_valid(button->gpio)) {
/*
* Legacy GPIO number so request the GPIO here and
* convert it to descriptor.
Expand All @@ -333,6 +333,18 @@ static int gpio_keys_polled_probe(struct platform_device *pdev)
button->gpio);
return -EINVAL;
}
} else {
/* try via gpio lookup table */
bdata->gpiod = devm_gpiod_get_index(dev, NULL, i, GPIOF_IN);
if (IS_ERR(bdata->gpiod)) {
dev_err(dev,
"unable to get gpio for button %d: %ld\n",
i, PTR_ERR(bdata->gpiod));
return PTR_ERR(bdata->gpiod);
}

gpiod_set_consumer_name(bdata->gpiod,
button->desc ? : DRV_NAME);
}

bdata->last_state = -1;
Expand Down

0 comments on commit 0e0239f

Please sign in to comment.