devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexandre Courbot <gnurou@gmail.com>
To: "Rafael J. Wysocki" <rjw@rjwysocki.net>
Cc: Mika Westerberg <mika.westerberg@linux.intel.com>,
	Arnd Bergmann <arnd@arndb.de>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Grant Likely <grant.likely@linaro.org>,
	ACPI Devel Maling List <linux-acpi@vger.kernel.org>,
	Aaron Lu <aaron.lu@intel.com>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	Linus Walleij <linus.walleij@linaro.org>,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Bryan Wu <cooloney@gmail.com>,
	Darren Hart <dvhart@linux.intel.com>,
	Mark Rutland <mark.rutland@arm.com>
Subject: Re: GPIO bindings guidelines (Was: Re: [PATCH v5 10/12] gpio: Support for unified device properties interface)
Date: Fri, 24 Oct 2014 16:15:32 +0900	[thread overview]
Message-ID: <CAAVeFuKyUok2yNwKmn0UtEufJRXgX7D0Ls5Pg_doVqCSDL1Riw@mail.gmail.com> (raw)
In-Reply-To: <1581499.2RkCnyfbq6@vostro.rjw.lan>

On Fri, Oct 24, 2014 at 6:51 AM, Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
> On Thursday, October 23, 2014 03:56:55 PM Mika Westerberg wrote:
>> On Thu, Oct 23, 2014 at 01:21:06AM +0200, Rafael J. Wysocki wrote:
>> > OK, would the below make sense, then (completely untested, on top of the v6
>> > of the device properties patchset)?
>>
>> Yes it does :-)
>>
>> With the the below fix it works nicely with the modified rfkill-gpio.c
>> driver.
>>
>> > +static bool acpi_get_driver_gpio_data(struct acpi_device *adev,
>> > +                                 const char *name,
>> > +                                 struct acpi_reference_args *args)
>> > +{
>> > +   struct acpi_gpio_data *gd;
>> > +
>> > +   mutex_lock(&driver_gpio_data_lock);
>> > +
>> > +   list_for_each_entry(gd, &adev->driver_gpios, item)
>> > +           if (!strcmp(name, gd->name)) {
>> > +                   args->adev = adev;
>> > +                   args->args[0] = gd->entry_index;
>> > +                   args->args[1] = gd->pin_index;
>> > +                   args->args[2] = gd->active_low;
>> > +                   args->nargs = 3;
>>
>>                       mutex_unlock(&driver_gpio_data_lock);
>>
>> > +                   return true;
>> > +           }
>> > +
>> > +   mutex_unlock(&driver_gpio_data_lock);
>> > +
>> > +   return false;
>> > +}
>>
>> Also I think the two functions should be exported to modules as well.
>>
>> Here are the modifications needed for rfkill-gpio.c driver. I think it
>> is not that bad considering that now the driver supports both ACPI _DSD
>> and non-_DSD at the same time.
>
> OK, let's try to take that a bit farther. :-)
>
> With the (untested) patch below applied (which is a replacement for the one
> sent previously), the driver can use static tables like these:
>
> static struct acpi_gpio_params reset_gpios = { 0, 0, false };
> statuc struct acpi_gpio_params shutdown_gpios = { 1, 0, false };
>
> static struct acpi_gpio_mapping my_gpio_mapping[] = {
>         { "reset-gpios", &reset_gpios, 1 },
>         { "shutdown-gpios", &shutdown_gpios, 1 },
>         NULL,
> };
>
> ->
>
>>
>> diff --git a/net/rfkill/rfkill-gpio.c b/net/rfkill/rfkill-gpio.c
>> index 0f62326c0f5e..f8754e7d81ea 100644
>> --- a/net/rfkill/rfkill-gpio.c
>> +++ b/net/rfkill/rfkill-gpio.c
>> @@ -67,6 +67,8 @@ static int rfkill_gpio_acpi_probe(struct device *dev,
>>                                 struct rfkill_gpio_data *rfkill)
>>  {
>>       const struct acpi_device_id *id;
>> +     struct acpi_device *adev = ACPI_COMPANION(dev);
>> +     int ret;
>>
>>       id = acpi_match_device(dev->driver->acpi_match_table, dev);
>>       if (!id)
>> @@ -75,6 +77,20 @@ static int rfkill_gpio_acpi_probe(struct device *dev,
>>       rfkill->name = dev_name(dev);
>>       rfkill->type = (unsigned)id->driver_data;
>>
>> +     /*
>> +      * Add default mapping for ACPI _DSD properties now just in case
>> +      * there is no _DSD for this device.
>> +      */
>> +     ret = acpi_dev_add_driver_gpio(adev, "reset-gpios", 0, 0, false);
>> +     if (ret)
>> +             return ret;
>> +
>> +     ret = acpi_dev_add_driver_gpio(adev, "shutdown-gpios", 1, 0, false);
>> +     if (ret) {
>> +             acpi_dev_remove_driver_gpios(adev);
>> +             return ret;
>> +     }
>
> -> and then simply do
>
>         ret = acpi_dev_add_driver_gpios(ACPI_COMPANION(dev), &my_gpio_mapping);
>
> instead of the above.
>
>>       return 0;
>>  }
>>
>> @@ -110,7 +126,7 @@ static int rfkill_gpio_probe(struct platform_device *pdev)
>>               rfkill->reset_gpio = gpio;
>>       }
>>
>> -     gpio = devm_gpiod_get_index(&pdev->dev, "shutdown", 1);
>> +     gpio = devm_gpiod_get_index(&pdev->dev, "shutdown", 0);
>>       if (!IS_ERR(gpio)) {
>>               ret = gpiod_direction_output(gpio, 0);
>>               if (ret)
>> @@ -150,6 +166,9 @@ static int rfkill_gpio_remove(struct platform_device *pdev)
>>       rfkill_unregister(rfkill->rfkill_dev);
>>       rfkill_destroy(rfkill->rfkill_dev);
>>
>> +     if (ACPI_COMPANION(&pdev->dev))
>> +             acpi_dev_remove_driver_gpios(ACPI_COMPANION(&pdev->dev));
>> +
>
> And here simply
>
>         acpi_dev_remove_driver_gpios(ACPI_COMPANION(&pdev->dev));
>
>>       return 0;
>>  }
>
> and then we can even cover situations in which there is one name for a list of
> GPIOs.

That looks just perfect.

  reply	other threads:[~2014-10-24  7:15 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-21  5:14 GPIO bindings guidelines (Was: Re: [PATCH v5 10/12] gpio: Support for unified device properties interface) Alexandre Courbot
2014-10-21  7:54 ` Arnd Bergmann
2014-10-22  8:10   ` Mika Westerberg
2014-10-22  8:33     ` Arnd Bergmann
2014-10-22  8:51       ` Mika Westerberg
2014-10-22  9:28         ` Arnd Bergmann
2014-10-22 14:07           ` Rafael J. Wysocki
2014-10-22 14:56             ` Mika Westerberg
2014-10-22 23:21               ` Rafael J. Wysocki
2014-10-23 12:56                 ` Mika Westerberg
2014-10-23 21:51                   ` Rafael J. Wysocki
2014-10-24  7:15                     ` Alexandre Courbot [this message]
2014-10-24  7:34                     ` Mika Westerberg
2014-10-24 22:00                       ` Rafael J. Wysocki
2014-10-24 22:05                         ` [PATCH] ACPI / GPIO: Driver GPIO mappings for ACPI GPIOs Rafael J. Wysocki
2014-10-27  5:21                           ` Alexandre Courbot
2014-10-27 22:34                             ` Rafael J. Wysocki
2014-10-28  4:11                               ` Alexandre Courbot
2014-10-30  0:45                                 ` Rafael J. Wysocki
2014-10-30 10:22                                   ` Mika Westerberg
2014-11-03 13:22                           ` Linus Walleij
2014-11-03 22:56                             ` Rafael J. Wysocki
2014-11-14  8:58                               ` Linus Walleij
2014-11-14 22:54                                 ` Rafael J. Wysocki
2014-11-17  4:28                                 ` Alexandre Courbot
2014-11-17 23:31                                   ` Rafael J. Wysocki
2014-10-27  7:50                         ` GPIO bindings guidelines (Was: Re: [PATCH v5 10/12] gpio: Support for unified device properties interface) Mika Westerberg
2014-10-23  6:10             ` Alexandre Courbot
2014-10-23 12:08               ` Arnd Bergmann
2014-10-23  6:02   ` Alexandre Courbot
2014-10-23 12:25     ` Arnd Bergmann
2014-10-30 15:11       ` Linus Walleij

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=CAAVeFuKyUok2yNwKmn0UtEufJRXgX7D0Ls5Pg_doVqCSDL1Riw@mail.gmail.com \
    --to=gnurou@gmail.com \
    --cc=aaron.lu@intel.com \
    --cc=arnd@arndb.de \
    --cc=cooloney@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=dvhart@linux.intel.com \
    --cc=grant.likely@linaro.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mika.westerberg@linux.intel.com \
    --cc=rjw@rjwysocki.net \
    /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).