* gpio-keys-polled enhancements v2 @ 2019-02-14 8:36 Enrico Weigelt, metux IT consult 2019-02-14 8:36 ` [PATCH 1/2] input: keyboard: gpio-keys-polled: use input name from pdata if available Enrico Weigelt, metux IT consult 2019-02-14 8:36 ` [PATCH 2/2] input: keyboard: gpio_keys_polled: use gpio lookup table Enrico Weigelt, metux IT consult 0 siblings, 2 replies; 5+ messages in thread From: Enrico Weigelt, metux IT consult @ 2019-02-14 8:36 UTC (permalink / raw) To: linux-kernel; +Cc: dmitry.torokhov, linux-input Hi folks, here's v2 of my gpio-keys-polled enhancements queue. I'm using this to allow it to be initialized by some other platform driver (in my case for the APUv2 board), when no proper fw data (oftree or acpi) is available. --mtx -- Enrico Weigelt, metux IT consult Free software and Linux embedded engineering info@metux.net -- +49-151-27565287 ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] input: keyboard: gpio-keys-polled: use input name from pdata if available 2019-02-14 8:36 gpio-keys-polled enhancements v2 Enrico Weigelt, metux IT consult @ 2019-02-14 8:36 ` Enrico Weigelt, metux IT consult 2019-02-14 8:36 ` [PATCH 2/2] input: keyboard: gpio_keys_polled: use gpio lookup table Enrico Weigelt, metux IT consult 1 sibling, 0 replies; 5+ messages in thread From: Enrico Weigelt, metux IT consult @ 2019-02-14 8:36 UTC (permalink / raw) To: linux-kernel; +Cc: dmitry.torokhov, linux-input Instead of hardcoding the input name to the driver name ('gpio-keys-polled'), allow the passing a name via platform data ('name' field was already present), but default to old behaviour in case of NULL. Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com> Cc: linux-input@vger.kernel.org Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net> --- drivers/input/keyboard/gpio_keys_polled.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/input/keyboard/gpio_keys_polled.c b/drivers/input/keyboard/gpio_keys_polled.c index edc7262..3312186 100644 --- a/drivers/input/keyboard/gpio_keys_polled.c +++ b/drivers/input/keyboard/gpio_keys_polled.c @@ -272,7 +272,7 @@ static int gpio_keys_polled_probe(struct platform_device *pdev) input = poll_dev->input; - input->name = pdev->name; + input->name = (pdata->name ? pdata->name : pdev->name); input->phys = DRV_NAME"/input0"; input->id.bustype = BUS_HOST; -- 1.9.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] input: keyboard: gpio_keys_polled: use gpio lookup table 2019-02-14 8:36 gpio-keys-polled enhancements v2 Enrico Weigelt, metux IT consult 2019-02-14 8:36 ` [PATCH 1/2] input: keyboard: gpio-keys-polled: use input name from pdata if available Enrico Weigelt, metux IT consult @ 2019-02-14 8:36 ` Enrico Weigelt, metux IT consult 1 sibling, 0 replies; 5+ messages in thread From: Enrico Weigelt, metux IT consult @ 2019-02-14 8:36 UTC (permalink / raw) To: linux-kernel; +Cc: dmitry.torokhov, linux-input Support the recently introduced gpio lookup tables for attaching to gpio lines. So, harcoded gpio numbers aren't needed anymore. Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com> Cc: linux-input@vger.kernel.org Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net> --- drivers/input/keyboard/gpio_keys_polled.c | 167 +++++++++++++++++++++--------- 1 file changed, 119 insertions(+), 48 deletions(-) diff --git a/drivers/input/keyboard/gpio_keys_polled.c b/drivers/input/keyboard/gpio_keys_polled.c index 3312186..3f773b2 100644 --- a/drivers/input/keyboard/gpio_keys_polled.c +++ b/drivers/input/keyboard/gpio_keys_polled.c @@ -24,6 +24,7 @@ #include <linux/platform_device.h> #include <linux/gpio.h> #include <linux/gpio/consumer.h> +#include <linux/gpio/machine.h> #include <linux/gpio_keys.h> #include <linux/property.h> @@ -227,6 +228,119 @@ static void gpio_keys_polled_set_abs_params(struct input_dev *input, }; MODULE_DEVICE_TABLE(of, gpio_keys_polled_of_match); +static struct gpio_desc *gpio_keys_polled_get_gpiod_fwnode( + struct device *dev, + int idx, + const char *desc) +{ + struct gpio_desc *gpiod; + struct fwnode_handle *child; + int x; + + /* get the idx'th child node */ + child = device_get_next_child_node(dev, NULL); + while (child && x) { + child = device_get_next_child_node(dev, child); + x--; + } + + if (!child) { + dev_err(dev, "missing oftree child node #%d\n", idx); + return ERR_PTR(-EINVAL); + } + + gpiod = devm_fwnode_get_gpiod_from_child(dev, + NULL, + child, + GPIOD_IN, + desc); + if (IS_ERR(gpiod)) { + if (PTR_ERR(gpiod) != -EPROBE_DEFER) + dev_err(dev, + "failed to get gpio: %ld\n", + PTR_ERR(gpiod)); + fwnode_handle_put(child); + return gpiod; + } + + return gpiod; +} + +static struct gpio_desc *gpio_keys_polled_get_gpiod_legacy( + struct device *dev, + int idx, + const struct gpio_keys_button *button) +{ + /* + * Legacy GPIO number so request the GPIO here and + * convert it to descriptor. + */ + unsigned int flags = GPIOF_IN; + struct gpio_desc *gpiod; + int error; + + dev_info(dev, "hardcoded gpio IDs are deprecated.\n"); + + if (button->active_low) + flags |= GPIOF_ACTIVE_LOW; + + error = devm_gpio_request_one(dev, button->gpio, + flags, button->desc ? : DRV_NAME); + if (error) { + dev_err(dev, + "unable to claim gpio %u, err=%d\n", + button->gpio, error); + return ERR_PTR(error); + } + + gpiod = gpio_to_desc(button->gpio); + if (!gpiod) { + dev_err(dev, + "unable to convert gpio %u to descriptor\n", + button->gpio); + return ERR_PTR(-EINVAL); + } + + return gpiod; +} + +static struct gpio_desc *gpio_keys_polled_get_gpiod( + struct device *dev, + int idx, + const struct gpio_keys_button *button) +{ + struct gpio_desc *gpiod = NULL; + int error; + + /* No legacy static platform data - use oftree */ + if (!dev_get_platdata(dev)) { + return gpio_keys_polled_get_gpiod_fwnode( + dev, idx, button->desc); + } + + gpiod = devm_gpiod_get_index(dev, NULL, idx, GPIOF_IN); + + if (!IS_ERR(gpiod)) { + dev_info(dev, "picked gpiod idx %d from gpio table\n", idx); + gpiod_set_consumer_name(gpiod, button->desc ? : DRV_NAME); + return gpiod; + } + + if (PTR_ERR(gpiod) != -ENOENT) { + dev_err(dev, "failed fetching gpiod #%d: %d\n", + idx, PTR_ERR(gpiod)); + return gpiod; + } + + /* Use legacy gpio id, if defined */ + if (gpio_is_valid(button->gpio)) { + return gpio_keys_polled_get_gpiod_legacy( + dev, idx, button); + } + + return ERR_PTR(-ENOENT); +} + static int gpio_keys_polled_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -291,57 +405,14 @@ static int gpio_keys_polled_probe(struct platform_device *pdev) if (button->wakeup) { dev_err(dev, DRV_NAME " does not support wakeup\n"); - fwnode_handle_put(child); return -EINVAL; } - if (!dev_get_platdata(dev)) { - /* No legacy static platform data */ - child = device_get_next_child_node(dev, child); - if (!child) { - dev_err(dev, "missing child device node\n"); - return -EINVAL; - } - - bdata->gpiod = devm_fwnode_get_gpiod_from_child(dev, - NULL, child, - GPIOD_IN, - button->desc); - if (IS_ERR(bdata->gpiod)) { - error = PTR_ERR(bdata->gpiod); - if (error != -EPROBE_DEFER) - dev_err(dev, - "failed to get gpio: %d\n", - error); - fwnode_handle_put(child); - return error; - } - } else if (gpio_is_valid(button->gpio)) { - /* - * Legacy GPIO number so request the GPIO here and - * convert it to descriptor. - */ - unsigned flags = GPIOF_IN; - - if (button->active_low) - flags |= GPIOF_ACTIVE_LOW; - - error = devm_gpio_request_one(dev, button->gpio, - flags, button->desc ? : DRV_NAME); - if (error) { - dev_err(dev, - "unable to claim gpio %u, err=%d\n", - button->gpio, error); - return error; - } - - bdata->gpiod = gpio_to_desc(button->gpio); - if (!bdata->gpiod) { - dev_err(dev, - "unable to convert gpio %u to descriptor\n", - button->gpio); - return -EINVAL; - } + bdata->gpiod = gpio_keys_polled_get_gpiod(dev, i, button); + + if (IS_ERR(bdata->gpiod)) { + dev_err(dev, "failed to fetch gpiod #%d\n", i); + return PTR_ERR(bdata->gpiod); } bdata->last_state = -1; -- 1.9.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 1/2] input: keyboard: gpio-keys-polled: use input name from pdata if available @ 2019-06-27 15:07 Enrico Weigelt, metux IT consult 2019-07-07 6:14 ` Dmitry Torokhov 0 siblings, 1 reply; 5+ messages in thread From: Enrico Weigelt, metux IT consult @ 2019-06-27 15:07 UTC (permalink / raw) To: linux-kernel; +Cc: dmitry.torokhov, linux-input Instead of hardcoding the input name to the driver name ('gpio-keys-polled'), allow the passing a name via platform data ('name' field was already present), but default to old behaviour in case of NULL. Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com> Cc: linux-input@vger.kernel.org Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net> --- drivers/input/keyboard/gpio_keys_polled.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/input/keyboard/gpio_keys_polled.c b/drivers/input/keyboard/gpio_keys_polled.c index 1eafe6b..c168493 100644 --- a/drivers/input/keyboard/gpio_keys_polled.c +++ b/drivers/input/keyboard/gpio_keys_polled.c @@ -269,7 +269,7 @@ static int gpio_keys_polled_probe(struct platform_device *pdev) input = poll_dev->input; - input->name = pdev->name; + input->name = (pdata->name ? pdata->name : pdev->name); input->phys = DRV_NAME"/input0"; input->id.bustype = BUS_HOST; -- 1.9.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] input: keyboard: gpio-keys-polled: use input name from pdata if available 2019-06-27 15:07 [PATCH 1/2] input: keyboard: gpio-keys-polled: use input name from pdata if available Enrico Weigelt, metux IT consult @ 2019-07-07 6:14 ` Dmitry Torokhov 0 siblings, 0 replies; 5+ messages in thread From: Dmitry Torokhov @ 2019-07-07 6:14 UTC (permalink / raw) To: Enrico Weigelt, metux IT consult; +Cc: linux-kernel, linux-input Hi Enrico, On Thu, Jun 27, 2019 at 05:07:10PM +0200, Enrico Weigelt, metux IT consult wrote: > Instead of hardcoding the input name to the driver name > ('gpio-keys-polled'), allow the passing a name via platform data > ('name' field was already present), but default to old behaviour > in case of NULL. > > Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com> > Cc: linux-input@vger.kernel.org > Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net> > --- > drivers/input/keyboard/gpio_keys_polled.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/input/keyboard/gpio_keys_polled.c b/drivers/input/keyboard/gpio_keys_polled.c > index 1eafe6b..c168493 100644 > --- a/drivers/input/keyboard/gpio_keys_polled.c > +++ b/drivers/input/keyboard/gpio_keys_polled.c > @@ -269,7 +269,7 @@ static int gpio_keys_polled_probe(struct platform_device *pdev) > > input = poll_dev->input; > > - input->name = pdev->name; > + input->name = (pdata->name ? pdata->name : pdev->name); > input->phys = DRV_NAME"/input0"; > > input->id.bustype = BUS_HOST; I also added fetching name from "label" device property ad applied, thank you. -- Dmitry ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-07-07 6:14 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2019-02-14 8:36 gpio-keys-polled enhancements v2 Enrico Weigelt, metux IT consult 2019-02-14 8:36 ` [PATCH 1/2] input: keyboard: gpio-keys-polled: use input name from pdata if available Enrico Weigelt, metux IT consult 2019-02-14 8:36 ` [PATCH 2/2] input: keyboard: gpio_keys_polled: use gpio lookup table Enrico Weigelt, metux IT consult -- strict thread matches above, loose matches on Subject: below -- 2019-06-27 15:07 [PATCH 1/2] input: keyboard: gpio-keys-polled: use input name from pdata if available Enrico Weigelt, metux IT consult 2019-07-07 6:14 ` Dmitry Torokhov
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).