From: Jacob Pan <jacob.jun.pan@linux.intel.com>
To: Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: Darren Hart <dvhart@linux.intel.com>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Al Stone <al.stone@linaro.org>, Olof Johansson <olof@lixom.net>,
Matthew Garrett <matthew.garrett@nebula.com>,
Matt Fleming <matt.fleming@intel.com>,
David Woodhouse <dwmw2@infradead.org>,
"H. Peter Anvin" <hpa@zytor.com>,
Josh Triplett <josh@joshtriplett.org>,
Aaron Lu <aaron.lu@intel.com>,
Max Eliaser <max.eliaser@intel.com>,
Robert Moore <robert.moore@intel.com>,
Len Brown <lenb@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Linus Walleij <linus.walleij@linaro.org>,
Alexandre Courbot <gnurou@gmail.com>,
Mark Brown <broonie@linaro.org>,
Dmitry Torokhov <dmitry.torokhov@gmail.com>,
Bryan Wu <cooloney@gmail.com>, Richard Purdie <rpurdie@rpsys.net>,
Samuel Ortiz <sameo@linux.intel.com>,
Lee Jones <lee.jones@linaro.org>,
Grant Likely <grant.likely@linaro.org>Rob
Subject: Re: [RFC PATCH 8/9] Input: gpio_keys_polled - Make use of device property API
Date: Mon, 18 Aug 2014 10:55:12 -0700 [thread overview]
Message-ID: <20140818105512.7889980b@ultegra> (raw)
In-Reply-To: <1408172039-32513-9-git-send-email-mika.westerberg@linux.intel.com>
On Sat, 16 Aug 2014 09:53:58 +0300
Mika Westerberg <mika.westerberg@linux.intel.com> wrote:
> From: Aaron Lu <aaron.lu@intel.com>
>
> Make use of device property API in this driver so that both OF based
> system and ACPI based system can use this driver.
>
Do we always assume OF and ACPI _DSD will have the same property name
strings? i.e. in this patch "gpios"
> + if (device_property_get(dev, "gpios", NULL)) {
> - if (!of_find_property(pp, "gpios", NULL)) {
Maybe i missed something, but I don't think we can make that assumption
in BIOS. If not, what is the point of having unified interface?
> The driver isn't converted to descriptor based gpio API due to there
> are a lot of existing users of struct gpio_keys_button that expects
> the gpio integer field. Though this can be solved by adding a new
> field of type struct gpio_desc but then there is another problem: the
> devm_gpiod_get needs to operate on the button device instead of its
> parent device that has the driver binded, so when the driver is
> unloaded, the resources for the gpio will not get freed
> automatically. Alternatively, we can introduce a new API, something
> like gpiod_find_index that does almost the same thing as
> gpiod_get_index but doesn't do the gpiod_request call and use it
> during finding button resources in gpio_keys_polled_get_button
> function. But then this may seem too complicated and not desirable.
> So in the end, a simple dev_get_gpiod_flags which is introduced in
> the last patch gets used and the gpio field of the struct
> gpio_keys_button can be got from the desc_to_gpio.
>
> Signed-off-by: Aaron Lu <aaron.lu@intel.com>
> Signed-off-by: Max Eliaser <max@meliaserlow.dyndns.tv>
> Reviewed-by: Darren Hart <dvhart@linux.intel.com>
> Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
> ---
> drivers/input/keyboard/gpio_keys_polled.c | 139
> ++++++++++++++++++------------ 1 file changed, 84 insertions(+), 55
> deletions(-)
>
> diff --git a/drivers/input/keyboard/gpio_keys_polled.c
> b/drivers/input/keyboard/gpio_keys_polled.c index
> 432d36395f35..49895d75aaff 100644 ---
> a/drivers/input/keyboard/gpio_keys_polled.c +++
> b/drivers/input/keyboard/gpio_keys_polled.c @@ -27,6 +27,7 @@
> #include <linux/of.h>
> #include <linux/of_platform.h>
> #include <linux/of_gpio.h>
> +#include <linux/property.h>
>
> #define DRV_NAME "gpio-keys-polled"
>
> @@ -102,78 +103,95 @@ static void gpio_keys_polled_close(struct
> input_polled_dev *dev) pdata->disable(bdev->dev);
> }
>
> -#ifdef CONFIG_OF
> -static struct gpio_keys_platform_data
> *gpio_keys_polled_get_devtree_pdata(struct device *dev) -{
> - struct device_node *node, *pp;
> +#if defined(CONFIG_OF) || defined(CONFIG_ACPI)
> +
> +struct button_proc_context {
> struct gpio_keys_platform_data *pdata;
> - struct gpio_keys_button *button;
> - int error;
> - int nbuttons;
> int i;
> +};
>
> - node = dev->of_node;
> - if (!node)
> - return NULL;
> +static int gpio_keys_polled_get_button(struct device *dev, void
> *data) +{
> + struct button_proc_context *c = data;
> + struct gpio_keys_platform_data *pdata = c->pdata;
> + struct gpio_keys_button *button = &pdata->buttons[c->i];
> + struct gpio_desc *desc;
> + enum gpio_lookup_flags flags;
> + void *val;
> +
> + if (device_property_get(dev, "gpios", NULL)) {
> + pdata->nbuttons--;
> + dev_warn(dev, "Found button without gpios\n");
> + return 0;
> + }
>
> - nbuttons = of_get_child_count(node);
> - if (nbuttons == 0)
> - return NULL;
> + desc = dev_get_gpiod_flags(dev, 0, &flags);
> + if (IS_ERR(desc)) {
> + int error = PTR_ERR(desc);
>
> - pdata = devm_kzalloc(dev, sizeof(*pdata) + nbuttons *
> sizeof(*button),
> - GFP_KERNEL);
> - if (!pdata)
> - return ERR_PTR(-ENOMEM);
> + if (error != -EPROBE_DEFER)
> + dev_err(dev, "Failed to get gpio flags,
> error: %d\n",
> + error);
> + return error;
> + }
>
> - pdata->buttons = (struct gpio_keys_button *)(pdata + 1);
> - pdata->nbuttons = nbuttons;
> + button->gpio = desc_to_gpio(desc);
> + button->active_low = flags & GPIO_ACTIVE_LOW;
>
> - pdata->rep = !!of_get_property(node, "autorepeat", NULL);
> - of_property_read_u32(node, "poll-interval",
> &pdata->poll_interval);
> + if (device_property_read(dev, "linux,code", DEV_PROP_U32,
> + &button->code)) {
> + dev_err(dev, "Button without keycode: 0x%x\n",
> + button->gpio);
> + return -EINVAL;
> + }
>
> - i = 0;
> - for_each_child_of_node(node, pp) {
> - int gpio;
> - enum of_gpio_flags flags;
> + if (!device_property_get(dev, "label", &val))
> + button->desc = val;
>
> - if (!of_find_property(pp, "gpios", NULL)) {
> - pdata->nbuttons--;
> - dev_warn(dev, "Found button without
> gpios\n");
> - continue;
> - }
> + if (device_property_read(dev, "linux,input-type",
> DEV_PROP_U32,
> + &button->type))
> + button->type = EV_KEY;
>
> - gpio = of_get_gpio_flags(pp, 0, &flags);
> - if (gpio < 0) {
> - error = gpio;
> - if (error != -EPROBE_DEFER)
> - dev_err(dev,
> - "Failed to get gpio flags,
> error: %d\n",
> - error);
> - return ERR_PTR(error);
> - }
> + button->wakeup = !device_property_get(dev,
> "gpio-key,wakeup", NULL);
> - button = &pdata->buttons[i++];
> + if (device_property_read(dev, "debounce-interval",
> DEV_PROP_U32,
> + &button->debounce_interval))
> + button->debounce_interval = 5;
>
> - button->gpio = gpio;
> - button->active_low = flags & OF_GPIO_ACTIVE_LOW;
> + c->i++;
> + return 0;
> +}
>
> - if (of_property_read_u32(pp, "linux,code",
> &button->code)) {
> - dev_err(dev, "Button without keycode:
> 0x%x\n",
> - button->gpio);
> - return ERR_PTR(-EINVAL);
> - }
> +static struct gpio_keys_platform_data *
> +gpio_keys_polled_get_devtree_pdata(struct device *dev)
> +{
> + struct gpio_keys_platform_data *pdata;
> + int size;
> + struct button_proc_context c;
> + int error;
> + int nbuttons;
>
> - button->desc = of_get_property(pp, "label", NULL);
> + nbuttons = device_property_child_count(dev);
> + if (nbuttons <= 0)
> + return NULL;
>
> - if (of_property_read_u32(pp, "linux,input-type",
> &button->type))
> - button->type = EV_KEY;
> + size = sizeof(*pdata) + nbuttons * sizeof(struct
> gpio_keys_button);
> + pdata = devm_kzalloc(dev, size, GFP_KERNEL);
> + if (!pdata)
> + return ERR_PTR(-ENOMEM);
>
> - button->wakeup = !!of_get_property(pp,
> "gpio-key,wakeup", NULL);
> + pdata->buttons = (struct gpio_keys_button *)(pdata + 1);
> + pdata->nbuttons = nbuttons;
>
> - if (of_property_read_u32(pp, "debounce-interval",
> - &button->debounce_interval))
> - button->debounce_interval = 5;
> - }
> + pdata->rep = !device_property_get(dev, "autorepeat", NULL);
> + device_property_read(dev, "poll-interval", DEV_PROP_U32,
> + &pdata->poll_interval);
> +
> + c.pdata = pdata;
> + c.i = 0;
> + error = device_for_each_child(dev, &c,
> gpio_keys_polled_get_button);
> + if (error)
> + return ERR_PTR(error);
>
> if (pdata->nbuttons == 0)
> return ERR_PTR(-EINVAL);
> @@ -181,11 +199,21 @@ static struct gpio_keys_platform_data
> *gpio_keys_polled_get_devtree_pdata(struct return pdata;
> }
>
> +#ifdef CONFIG_OF
> static const struct of_device_id gpio_keys_polled_of_match[] = {
> { .compatible = "gpio-keys-polled", },
> { },
> };
> MODULE_DEVICE_TABLE(of, gpio_keys_polled_of_match);
> +#endif
> +
> +#ifdef CONFIG_ACPI
> +static struct acpi_device_id gpio_keys_polled_acpi_match[] = {
> + { "MNW0002" },
> + { },
> +};
> +MODULE_DEVICE_TABLE(acpi, gpio_keys_polled_acpi_match);
> +#endif
>
> #else
>
> @@ -309,6 +337,7 @@ static struct platform_driver
> gpio_keys_polled_driver = { .name = DRV_NAME,
> .owner = THIS_MODULE,
> .of_match_table =
> of_match_ptr(gpio_keys_polled_of_match),
> + .acpi_match_table =
> ACPI_PTR(gpio_keys_polled_acpi_match), },
> };
> module_platform_driver(gpio_keys_polled_driver);
[Jacob Pan]
next prev parent reply other threads:[~2014-08-18 17:55 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-16 6:53 [RFC PATCH 0/9] Add ACPI _DSD and unified device properties support Mika Westerberg
2014-08-16 6:53 ` [RFC PATCH 1/9] ACPI: Add support for device specific properties Mika Westerberg
2014-08-16 6:53 ` [RFC PATCH 2/9] ACPI: Document ACPI " Mika Westerberg
2014-08-16 6:53 ` [RFC PATCH 3/9] Driver core: Unified device properties interface for platform firmware Mika Westerberg
2014-08-16 6:53 ` [RFC PATCH 4/9] of: Add property_ops callback for devices with of_node Mika Westerberg
2014-08-16 6:53 ` [RFC PATCH 5/9] mfd: Add ACPI support Mika Westerberg
2014-08-20 15:54 ` Lee Jones
2014-08-21 9:05 ` Mika Westerberg
2014-08-16 6:53 ` [RFC PATCH 6/9] gpiolib: add API to get gpio desc and flags Mika Westerberg
2014-08-18 16:24 ` Alexandre Courbot
2014-08-19 8:56 ` Mika Westerberg
2014-08-19 9:02 ` Aaron Lu
2014-08-19 17:16 ` Alexandre Courbot
2014-08-16 6:53 ` [RFC PATCH 7/9] gpio: sch: Consolidate core and resume banks Mika Westerberg
2014-08-29 6:36 ` Linus Walleij
2014-08-16 6:53 ` [RFC PATCH 8/9] Input: gpio_keys_polled - Make use of device property API Mika Westerberg
2014-08-18 17:55 ` Jacob Pan [this message]
2014-08-19 9:27 ` Mika Westerberg
2014-08-19 15:21 ` Darren Hart
2014-08-16 6:53 ` [RFC PATCH 9/9] leds: leds-gpio: " Mika Westerberg
2014-08-16 16:06 ` [RFC PATCH 0/9] Add ACPI _DSD and unified device properties support Darren Hart
2014-08-17 14:11 ` Dmitry Torokhov
2014-08-17 16:52 ` Darren Hart
2014-08-16 18:48 ` Josh Triplett
2014-08-17 6:55 ` Mika Westerberg
-- strict thread matches above, loose matches on Subject: below --
2014-08-17 6:04 Mika Westerberg
2014-08-17 6:04 ` [RFC PATCH 8/9] Input: gpio_keys_polled - Make use of device property API Mika Westerberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140818105512.7889980b@ultegra \
--to=jacob.jun.pan@linux.intel.com \
--cc=aaron.lu@intel.com \
--cc=al.stone@linaro.org \
--cc=broonie@linaro.org \
--cc=cooloney@gmail.com \
--cc=dmitry.torokhov@gmail.com \
--cc=dvhart@linux.intel.com \
--cc=dwmw2@infradead.org \
--cc=gnurou@gmail.com \
--cc=grant.likely@linaro.org \
--cc=gregkh@linuxfoundation.org \
--cc=hpa@zytor.com \
--cc=josh@joshtriplett.org \
--cc=lee.jones@linaro.org \
--cc=lenb@kernel.org \
--cc=linus.walleij@linaro.org \
--cc=matt.fleming@intel.com \
--cc=matthew.garrett@nebula.com \
--cc=max.eliaser@intel.com \
--cc=mika.westerberg@linux.intel.com \
--cc=olof@lixom.net \
--cc=rafael@kernel.org \
--cc=robert.moore@intel.com \
--cc=rpurdie@rpsys.net \
--cc=sameo@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).