Re: Trying to understand basic concepts about GPIO reset pin

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Dec 11, 2019 at 2:45 PM Uwe Kleine-König
<u.kleine-koenig@xxxxxxxxxxxxxx> wrote:
> On Wed, Dec 11, 2019 at 01:22:03PM +0000, Russell King - ARM Linux admin wrote:
> > On Wed, Dec 11, 2019 at 02:05:45PM +0100, Marc Gonzalez wrote:

> > >     devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
> > >
> > > then I am able to interact with the device. How can that be?
> >
> > This is where things get complicated.  GPIOD_OUT_LOW is
> > GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT without
> > GPIOD_FLAGS_BIT_DIR_VAL.  The above will therefore call:
> >
> >       gpiod_direction_output(gpiod, !!(dflags & GPIOD_FLAGS_BIT_DIR_VAL));
> >
> > which will be zero.  gpiod_direction_output() respects the inversion
> > that GPIO_ACTIVE_LOW specified in DT.  So, GPIOD_OUT_LOW will set
> > the reset signal _high_.
> >
> > I don't blame you for thinking this is confusing - the terminology
> > adopted in the kernel certainly is.
> >
> > Thnk of whatever you give to the non-raw functions as "low means
> > inactive, high means active".
>
> I think it would be good to not pass GPIOD_OUT_LOW to
> devm_gpiod_get_optional (et al). Something like
>
>         devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_ACTIVE);
>
> would be much less confusing. Not sure this exists, but it would make a
> good alias for GPIOD_OUT_HIGH.

I have suggested in some other thread to create an alias
GPIO_OUT_ASSERTED / GPIO_OUT_DEASSERTED
and likewise change the name of the prototype
gpiod_set_value(gpiod, int value) to
gpiod_set_state(gpiod, bool asserted) rather than the
current int value so it is [more] clear what the argument to
these functions mean: that it is a logical level not
a physical level.

Then gradually or with a sed script just mass-convert
all users of the API to this signature. A single swift
conversion would be preferred by me personally.

I'll try to add it to my GPIO public TODO so that others
see it and be able to pick it up, because there are so
many ongoing refurbishing tasks that I need to tend to
personally.

Yours,
Linus Walleij




[Index of Archives]     [Linux SPI]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux