Re: [Patch v2 1/2] gpio: add GPIO hogging mechanism

From: Linus Walleij
Date: Tue Dec 02 2014 - 09:25:43 EST


On Tue, Dec 2, 2014 at 1:22 AM, Benoit Parrot <bparrot@xxxxxx> wrote:
> Alexandre Courbot <gnurou@xxxxxxxxx> wrote on Fri [2014-Nov-28 16:30:01 +0900]:
>> On Fri, Nov 21, 2014 at 8:54 AM, Benoit Parrot <bparrot@xxxxxx> wrote:

>> > + }
>> > +
>> > + if (tmp > MAX_PHANDLE_ARGS) {
>> > + desc = ERR_PTR(-EINVAL);
>> > + goto out;
>> > + }
>> > +
>> > + gg_data.gpiospec.args_count = tmp;
>> > + gg_data.gpiospec.np = chip_np;
>> > + for (i = 0; i < tmp; i++) {
>> > + ret = of_property_read_u32(np, "gpios",
>> > + &gg_data.gpiospec.args[i]);
>> > + if (ret) {
>> > + desc = ERR_PTR(ret);
>> > + goto out;
>> > + }
>> > + }
>> > +
>> > + gpiochip_find(&gg_data, of_gpiochip_find_and_xlate);
>>
>> This seems to work but only supports one GPIO per hog node. It would
>> be nice to be able to specify several GPIOs to which the same settings
>> need to be applied.
>
> This is on purpose following Linus Walleij's comment.

Yes, I think either we have separate nodes for each hogged line *OR*
we just put a list of hogs under the gpiochip, no special node at all.

The one-node-per-hog pattern has the upside of being usable
to also name the hogs. (Exporting them is dubious however!
I would add a special type of node for that.)

>> > + if (err < 0)
>> > + return err;
>> > +
>> > + if (lflags & GPIO_ACTIVE_LOW)
>> > + set_bit(FLAG_ACTIVE_LOW, &desc->flags);
>> > + if (lflags & GPIO_OPEN_DRAIN)
>> > + set_bit(FLAG_OPEN_DRAIN, &desc->flags);
>> > + if (lflags & GPIO_OPEN_SOURCE)
>> > + set_bit(FLAG_OPEN_SOURCE, &desc->flags);
>> > +
>> > + /* No particular flag request, not really hogging then... */
>> > + if (!(dflags & GPIOD_FLAGS_BIT_DIR_SET)) {
>> > + pr_warn("%s: GPIO %s: no hogging direction specified, bailing out\n",
>> > + __func__, name);
>> > + err = -EINVAL;
>> > + goto free_gpio;
>> > + }
>> > +
>> > + /* Process flags */
>> > + if (dflags & GPIOD_FLAGS_BIT_DIR_OUT)
>> > + err = gpiod_direction_output(desc,
>> > + dflags & GPIOD_FLAGS_BIT_DIR_VAL);
>> > + else
>> > + err = gpiod_direction_input(desc);
>> > +
>> > + if (err < 0) {
>> > + pr_warn("%s: GPIO %s setting direction/value failed\n",
>> > + __func__, name);
>> > + goto free_gpio;
>> > + }
>>
>> I would suggest to factorize this code that is similar to the one
>> found in __gpiod_get_index(). Do all the DT parsing in a function that
>> just returns a descriptor and the
>
> I would tend to agree.
> But as Linus suggested I was trying to contain the changes to gpiolib_of.c only.

Yes I prefer we begin by supporting it in OF and then generalize it later
if more users (board files, ACPI) appear.

Not a big deal but I want to avoid big design up front unless it's
easy and a few alterations.
http://c2.com/cgi/wiki?BigDesignUpFront

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/