Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1504814 > unrolled thread

Re: [PATCH v2 2/4] ACPI / gpio: Add support for naming GPIOs

Started byLinus Walleij <linus.walleij@linaro.org>
First post2016-10-20 14:10 +0200
Last post2016-10-20 14:20 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [PATCH v2 2/4] ACPI / gpio: Add support for naming GPIOs Linus Walleij <linus.walleij@linaro.org> - 2016-10-20 14:10 +0200
    Re: [PATCH v2 2/4] ACPI / gpio: Add support for naming GPIOs Mika Westerberg <mika.westerberg@linux.intel.com> - 2016-10-20 14:20 +0200

#1504814 — Re: [PATCH v2 2/4] ACPI / gpio: Add support for naming GPIOs

FromLinus Walleij <linus.walleij@linaro.org>
Date2016-10-20 14:10 +0200
SubjectRe: [PATCH v2 2/4] ACPI / gpio: Add support for naming GPIOs
Message-ID<sukky-7mR-5@gated-at.bofh.it>
On Thu, Sep 29, 2016 at 3:39 PM, Mika Westerberg
<mika.westerberg@linux.intel.com> wrote:

> DT has property 'gpio-line-names' to name GPIO lines the controller has if
> present. Use this very same property in ACPI as well to provide nice names
> for the GPIOS.
>
> Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>

Oh wait:

> +static void acpi_gpiochip_set_names(struct acpi_gpio_chip *achip)
> +{
> +       struct gpio_chip *chip = achip->chip;
> +       struct gpio_device *gdev = chip->gpiodev;
> +       const char **names;
> +       int ret, i;
> +
> +       ret = device_property_read_string_array(chip->parent, "gpio-line-names",
> +                                               NULL, 0);
> +       if (ret < 0)
> +               return;
> +
> +       if (ret != gdev->ngpio) {
> +               dev_warn(chip->parent,
> +                        "names %d do not match number of GPIOs %d\n", ret,
> +                        gdev->ngpio);
> +               return;
> +       }
> +
> +       names = kcalloc(gdev->ngpio, sizeof(*names), GFP_KERNEL);
> +       if (!names)
> +               return;
> +
> +       ret = device_property_read_string_array(chip->parent, "gpio-line-names",
> +                                               names, gdev->ngpio);
> +       if (ret < 0) {
> +               dev_warn(chip->parent, "Failed to read GPIO line names\n");
> +               return;
> +       }
> +
> +       /*
> +        * It is fine to assign the name, it will be allocated as long as
> +        * the ACPI device exists.
> +        */
> +       for (i = 0; i < gdev->ngpio; i++)
> +               gdev->descs[i].name = names[i];
> +
> +       kfree(names);
> +}

Wouldn't this entire function work just as fine on device tree?

So should this snippet using device_property_* be moved into
a file like gpiolib-devprop.c+gpiolib.h signature and get used from
both gpiolib-of.c and gpiolib-acpi.c, replacing the DT-specific
code in gpiolib-of.c?

Yours,
Linus Walleij

[toc] | [next] | [standalone]


#1504829

FromMika Westerberg <mika.westerberg@linux.intel.com>
Date2016-10-20 14:20 +0200
Message-ID<sukuf-7se-77@gated-at.bofh.it>
In reply to#1504814
On Thu, Oct 20, 2016 at 02:06:42PM +0200, Linus Walleij wrote:
> On Thu, Sep 29, 2016 at 3:39 PM, Mika Westerberg
> <mika.westerberg@linux.intel.com> wrote:
> 
> > DT has property 'gpio-line-names' to name GPIO lines the controller has if
> > present. Use this very same property in ACPI as well to provide nice names
> > for the GPIOS.
> >
> > Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
> 
> Oh wait:
> 
> > +static void acpi_gpiochip_set_names(struct acpi_gpio_chip *achip)
> > +{
> > +       struct gpio_chip *chip = achip->chip;
> > +       struct gpio_device *gdev = chip->gpiodev;
> > +       const char **names;
> > +       int ret, i;
> > +
> > +       ret = device_property_read_string_array(chip->parent, "gpio-line-names",
> > +                                               NULL, 0);
> > +       if (ret < 0)
> > +               return;
> > +
> > +       if (ret != gdev->ngpio) {
> > +               dev_warn(chip->parent,
> > +                        "names %d do not match number of GPIOs %d\n", ret,
> > +                        gdev->ngpio);
> > +               return;
> > +       }
> > +
> > +       names = kcalloc(gdev->ngpio, sizeof(*names), GFP_KERNEL);
> > +       if (!names)
> > +               return;
> > +
> > +       ret = device_property_read_string_array(chip->parent, "gpio-line-names",
> > +                                               names, gdev->ngpio);
> > +       if (ret < 0) {
> > +               dev_warn(chip->parent, "Failed to read GPIO line names\n");
> > +               return;
> > +       }
> > +
> > +       /*
> > +        * It is fine to assign the name, it will be allocated as long as
> > +        * the ACPI device exists.
> > +        */
> > +       for (i = 0; i < gdev->ngpio; i++)
> > +               gdev->descs[i].name = names[i];
> > +
> > +       kfree(names);
> > +}
> 
> Wouldn't this entire function work just as fine on device tree?

Now that you mentioned it, yes, I think it should work with DT as well.

> So should this snippet using device_property_* be moved into
> a file like gpiolib-devprop.c+gpiolib.h signature and get used from
> both gpiolib-of.c and gpiolib-acpi.c, replacing the DT-specific
> code in gpiolib-of.c?

Works for me :)

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web