Linux GPIO subsystem development
 help / color / mirror / Atom feed
From: Rojhalat Ibrahim <imr@rtschenk.de>
To: Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: Alexandre Courbot <gnurou@gmail.com>,
	"linux-gpio@vger.kernel.org" <linux-gpio@vger.kernel.org>,
	Alexandre Courbot <acourbot@nvidia.com>,
	Linus Walleij <linus.walleij@linaro.org>
Subject: Re: [PATCH 1/3][v2] gpiolib: add gpiod_get_array and gpiod_put_array functions
Date: Mon, 09 Feb 2015 14:20:52 +0100	[thread overview]
Message-ID: <13958989.5jUGxRK7u6@pcimr> (raw)
In-Reply-To: <20150209120926.GC1480@lahna.fi.intel.com>

On Monday 09 February 2015 14:09:26 Mika Westerberg wrote:
> On Mon, Feb 09, 2015 at 02:12:39PM +0900, Alexandre Courbot wrote:
> > > +#ifdef CONFIG_ACPI
> > > +
> > > +static int acpi_find_gpio_count(struct acpi_resource *ares, void *data)
> > > +{
> > > +       unsigned int *count = data;
> > > +
> > > +       if (ares->type == ACPI_RESOURCE_TYPE_GPIO)
> > > +               *count = ares->data.gpio.pin_table_length;
> > > +
> > > +       return 1;
> > > +}
> > > +
> > > +static unsigned int acpi_gpio_count(struct device *dev, const char *con_id)
> > > +{
> > > +       struct acpi_device *adev = ACPI_COMPANION(dev);
> > > +       const union acpi_object *obj;
> > > +       const struct acpi_gpio_mapping *gm;
> > > +       unsigned int count = 0;
> > > +       int ret;
> > > +       char propname[32];
> > > +       unsigned int i;
> > > +
> > > +       /* Try first from _DSD */
> > > +       for (i = 0; i < ARRAY_SIZE(gpio_suffixes); i++) {
> > > +               if (con_id && strcmp(con_id, "gpios"))
> > > +                       snprintf(propname, sizeof(propname), "%s-%s",
> > > +                                con_id, gpio_suffixes[i]);
> > > +               else
> > > +                       snprintf(propname, sizeof(propname), "%s",
> > > +                                gpio_suffixes[i]);
> > > +
> > > +               ret = acpi_dev_get_property(adev, propname, ACPI_TYPE_ANY,
> > > +                                           &obj);
> > > +               if (ret == 0) {
> > > +                       if (obj->type == ACPI_TYPE_LOCAL_REFERENCE)
> > > +                               count = 1;
> > > +                       else if (obj->type == ACPI_TYPE_PACKAGE)
> > > +                               count = obj->package.count;
> > > +               } else if (adev->driver_gpios) {
> > > +                       for (gm = adev->driver_gpios; gm->name; gm++)
> > > +                               if (strcmp(propname, gm->name) == 0) {
> > > +                                       count = gm->size;
> > > +                                       break;
> > > +                               }
> > > +               }
> > > +               if (count)
> > > +                       break;
> > > +       }
> > > +
> > > +       /* Then from plain _CRS GPIOs */
> > > +       if (!count) {
> > > +               struct list_head resource_list;
> > > +
> > > +               INIT_LIST_HEAD(&resource_list);
> > > +               acpi_dev_get_resources(adev, &resource_list,
> > > +                                      acpi_find_gpio_count, &count);
> > > +               acpi_dev_free_resource_list(&resource_list);
> > > +       }
> > > +       return count;
> > > +}
> > 
> > I'd really like to have an acked-by from some of the ACPI people
> > (Mika?) for this part.
> 
> If I understand correctly the new interface allows requesting all GPIOs
> for a given device?
> 

That's the general idea.

> In that case the above code will not work. In ACPI a device may have
> several GpioIo/GpioInt resources and each can hold several pins. If I
> read the above code right, it re-assigns 'count' for each GPIO instead
> of adding to it.
> 

Ok. That can be fixed easily.

> The _DSD path also seems to return number of elements in a package:
> 
> 	Package () {"reset-gpios", Package() {^BTH, 1, 1, 0}},
> 
> Here for example it returns 4 which is not what is expected. I think in
> this case the correct value is 1.
> 
> Also there may be several GPIOs for a single property like:
> 
> 	Package () {"reset-gpios", Package() {^BTH, 1, 1, 0, ^BTH, 1, 2, 0}},
> 
> I'm not sure if that is handled correctly here.

Obviously not. So instead of taking the number of elements in the package
we could count the number of device references (ACPI_TYPE_LOCAL_REFERENCE)
within the package. That should give us the number of GPIOs in the package,
right?



  reply	other threads:[~2015-02-09 13:20 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-21 16:46 [PATCH 1/3][v2] gpiolib: add gpiod_get_array and gpiod_put_array functions Rojhalat Ibrahim
2015-01-30  9:44 ` Linus Walleij
2015-01-30 10:02   ` Alexandre Courbot
2015-02-09  5:12 ` Alexandre Courbot
2015-02-09  9:07   ` Rojhalat Ibrahim
2015-02-09 12:09   ` Mika Westerberg
2015-02-09 13:20     ` Rojhalat Ibrahim [this message]
2015-02-09 13:32       ` 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=13958989.5jUGxRK7u6@pcimr \
    --to=imr@rtschenk.de \
    --cc=acourbot@nvidia.com \
    --cc=gnurou@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=mika.westerberg@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