linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [alsa-devel] [PATCH 2/4] ASoC: s3c64xx/smartq: use dynamic registration
       [not found]   ` <20140714183624.GV6800@sirena.org.uk>
@ 2014-07-15  7:19     ` Arnd Bergmann
  2014-07-15  7:36       ` Alexandre Courbot
  0 siblings, 1 reply; 24+ messages in thread
From: Arnd Bergmann @ 2014-07-15  7:19 UTC (permalink / raw)
  To: Mark Brown
  Cc: Lars-Peter Clausen, alsa-devel, Kukjin Kim, t.figa,
	Maurus Cuelenaere, lgirdwood, linux-arm-kernel, linus.walleij,
	linux-gpio, Alexandre Courbot

On Monday 14 July 2014 19:36:24 Mark Brown wrote:
> On Mon, Jul 14, 2014 at 08:23:55PM +0200, Arnd Bergmann wrote:
> > On Monday 14 July 2014 18:18:12 Lars-Peter Clausen wrote:
> 
> > > Yes. But now that you say it the gpiod_direction_output() call is missing 
> > > from this patch.
> 
> > I'm lost now. The GPIO_ACTIVE_HIGH I added comes from Documentation/gpio/board.txt
> > and as Linus Walleij explained to me the other day, the lookup is supposed
> > to replace devm_gpio_request_one(), which in turn replaced both the
> > gpio_request and the gpio_direction_output(). Do I need to put the
> > gpiod_direction_output() back or is there another interface for that when
> > registering the board gpios?
> 
> Indeed.  If you *do* need an explicit _output() then that sounds to me
> like we either need a gpiod_get_one() or an extension to the table,
> looking at the code it seems like this is indeed the case.  We can set
> if the GPIO is active high/low, or open source/drain but there's no flag
> for the initial state.

(adding Alexandre and the gpio list)

GPIO people: any guidance on how a board file should set a gpio to
output/default-high in a GPIO_LOOKUP() table to replace a
devm_gpio_request_one() call in a device driver with devm_gpiod_get()?
Do we need to add an interface extension to do this, e.g. passing
GPIOF_OUT_INIT_HIGH as the flags rather than GPIO_ACTIVE_HIGH?

	Arnd

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [alsa-devel] [PATCH 2/4] ASoC: s3c64xx/smartq: use dynamic registration
  2014-07-15  7:19     ` [alsa-devel] [PATCH 2/4] ASoC: s3c64xx/smartq: use dynamic registration Arnd Bergmann
@ 2014-07-15  7:36       ` Alexandre Courbot
  2014-07-15  7:58         ` Lars-Peter Clausen
  2014-07-15 10:39         ` Mark Brown
  0 siblings, 2 replies; 24+ messages in thread
From: Alexandre Courbot @ 2014-07-15  7:36 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Mark Brown, Lars-Peter Clausen, alsa-devel@alsa-project.org,
	Kukjin Kim, Tomasz Figa, Maurus Cuelenaere, Liam Girdwood,
	linux-arm-kernel@lists.infradead.org, Linus Walleij,
	linux-gpio@vger.kernel.org

On Tue, Jul 15, 2014 at 4:19 PM, Arnd Bergmann <arnd@arndb.de> wrote:
> On Monday 14 July 2014 19:36:24 Mark Brown wrote:
>> On Mon, Jul 14, 2014 at 08:23:55PM +0200, Arnd Bergmann wrote:
>> > On Monday 14 July 2014 18:18:12 Lars-Peter Clausen wrote:
>>
>> > > Yes. But now that you say it the gpiod_direction_output() call is missing
>> > > from this patch.
>>
>> > I'm lost now. The GPIO_ACTIVE_HIGH I added comes from Documentation/gpio/board.txt
>> > and as Linus Walleij explained to me the other day, the lookup is supposed
>> > to replace devm_gpio_request_one(), which in turn replaced both the
>> > gpio_request and the gpio_direction_output(). Do I need to put the
>> > gpiod_direction_output() back or is there another interface for that when
>> > registering the board gpios?
>>
>> Indeed.  If you *do* need an explicit _output() then that sounds to me
>> like we either need a gpiod_get_one() or an extension to the table,
>> looking at the code it seems like this is indeed the case.  We can set
>> if the GPIO is active high/low, or open source/drain but there's no flag
>> for the initial state.
>
> (adding Alexandre and the gpio list)
>
> GPIO people: any guidance on how a board file should set a gpio to
> output/default-high in a GPIO_LOOKUP() table to replace a
> devm_gpio_request_one() call in a device driver with devm_gpiod_get()?
> Do we need to add an interface extension to do this, e.g. passing
> GPIOF_OUT_INIT_HIGH as the flags rather than GPIO_ACTIVE_HIGH?

The way I see it, GPIO mappings (whether they are done using the
lookup tables, DT, or ACPI) should only care about details that are
relevant to the device layout and that should be abstracted to the
driver (e.g. whether the GPIO is active low or open drain) so drivers
do not need to check X conditions every time they want to drive the
GPIO.

Direction and initial value, on the other hand, are clearly properties
that ought to be set by the driver itself. Thus my expectation here
would be that the driver sets the GPIO direction and initial value as
soon as it gets it using gpiod_direction_output(). In other words,
there is no replacement for gpio_request_one() with the gpiod
interface. Is there any use-case that cannot be covered by calling
gpiod_direction_output() right after gpiod_get()? AFAICT this is what
gpio_request_one() was doing anyway.

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 2/4] ASoC: s3c64xx/smartq: use dynamic registration
  2014-07-15  7:36       ` Alexandre Courbot
@ 2014-07-15  7:58         ` Lars-Peter Clausen
  2014-07-15  9:14           ` [alsa-devel] " Alexandre Courbot
  2014-07-15 10:39         ` Mark Brown
  1 sibling, 1 reply; 24+ messages in thread
From: Lars-Peter Clausen @ 2014-07-15  7:58 UTC (permalink / raw)
  To: Alexandre Courbot, Arnd Bergmann
  Cc: alsa-devel@alsa-project.org, Kukjin Kim, Tomasz Figa,
	Maurus Cuelenaere, Liam Girdwood, linux-gpio@vger.kernel.org,
	Mark Brown, Linus Walleij, linux-arm-kernel@lists.infradead.org

On 07/15/2014 09:36 AM, Alexandre Courbot wrote:
> On Tue, Jul 15, 2014 at 4:19 PM, Arnd Bergmann <arnd@arndb.de> wrote:
>> On Monday 14 July 2014 19:36:24 Mark Brown wrote:
>>> On Mon, Jul 14, 2014 at 08:23:55PM +0200, Arnd Bergmann wrote:
>>>> On Monday 14 July 2014 18:18:12 Lars-Peter Clausen wrote:
>>>
>>>>> Yes. But now that you say it the gpiod_direction_output() call is missing
>>>>> from this patch.
>>>
>>>> I'm lost now. The GPIO_ACTIVE_HIGH I added comes from Documentation/gpio/board.txt
>>>> and as Linus Walleij explained to me the other day, the lookup is supposed
>>>> to replace devm_gpio_request_one(), which in turn replaced both the
>>>> gpio_request and the gpio_direction_output(). Do I need to put the
>>>> gpiod_direction_output() back or is there another interface for that when
>>>> registering the board gpios?
>>>
>>> Indeed.  If you *do* need an explicit _output() then that sounds to me
>>> like we either need a gpiod_get_one() or an extension to the table,
>>> looking at the code it seems like this is indeed the case.  We can set
>>> if the GPIO is active high/low, or open source/drain but there's no flag
>>> for the initial state.
>>
>> (adding Alexandre and the gpio list)
>>
>> GPIO people: any guidance on how a board file should set a gpio to
>> output/default-high in a GPIO_LOOKUP() table to replace a
>> devm_gpio_request_one() call in a device driver with devm_gpiod_get()?
>> Do we need to add an interface extension to do this, e.g. passing
>> GPIOF_OUT_INIT_HIGH as the flags rather than GPIO_ACTIVE_HIGH?
>
> The way I see it, GPIO mappings (whether they are done using the
> lookup tables, DT, or ACPI) should only care about details that are
> relevant to the device layout and that should be abstracted to the
> driver (e.g. whether the GPIO is active low or open drain) so drivers
> do not need to check X conditions every time they want to drive the
> GPIO.
>
> Direction and initial value, on the other hand, are clearly properties
> that ought to be set by the driver itself. Thus my expectation here
> would be that the driver sets the GPIO direction and initial value as
> soon as it gets it using gpiod_direction_output(). In other words,
> there is no replacement for gpio_request_one() with the gpiod
> interface. Is there any use-case that cannot be covered by calling
> gpiod_direction_output() right after gpiod_get()? AFAICT this is what
> gpio_request_one() was doing anyway.

I agree with you that this is something that should be done in the driver 
and not in the lookup table. I think that it is still a good idea to have a 
replacement for gpio_request_one with the new GPIO descriptor API. A large 
share of the drivers want to call either gpio_direction_input() or 
gpio_direction_output() right after requesting the GPIO. Combining both the 
requesting and the configuration of the GPIO into one function call makes 
the code a bit shorter and also simplifies the error handling. Even more so 
if e.g. the GPIO is optional. This was one of the main reasons why 
gpio_request_one was introduced, see the commit[1] that added it.

- Lars

[1] 
http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=3e45f1d1155894e6f4291f5536b224874d52d8e2

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [alsa-devel] [PATCH 2/4] ASoC: s3c64xx/smartq: use dynamic registration
  2014-07-15  7:58         ` Lars-Peter Clausen
@ 2014-07-15  9:14           ` Alexandre Courbot
  2014-07-16  3:00             ` Alexandre Courbot
  0 siblings, 1 reply; 24+ messages in thread
From: Alexandre Courbot @ 2014-07-15  9:14 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Arnd Bergmann, alsa-devel@alsa-project.org, Kukjin Kim,
	Tomasz Figa, Maurus Cuelenaere, Liam Girdwood,
	linux-gpio@vger.kernel.org, Mark Brown, Linus Walleij,
	linux-arm-kernel@lists.infradead.org

On Tue, Jul 15, 2014 at 4:58 PM, Lars-Peter Clausen <lars@metafoo.de> wrote:
> On 07/15/2014 09:36 AM, Alexandre Courbot wrote:
>>
>> On Tue, Jul 15, 2014 at 4:19 PM, Arnd Bergmann <arnd@arndb.de> wrote:
>>>
>>> On Monday 14 July 2014 19:36:24 Mark Brown wrote:
>>>>
>>>> On Mon, Jul 14, 2014 at 08:23:55PM +0200, Arnd Bergmann wrote:
>>>>>
>>>>> On Monday 14 July 2014 18:18:12 Lars-Peter Clausen wrote:
>>>>
>>>>
>>>>>> Yes. But now that you say it the gpiod_direction_output() call is
>>>>>> missing
>>>>>> from this patch.
>>>>
>>>>
>>>>> I'm lost now. The GPIO_ACTIVE_HIGH I added comes from
>>>>> Documentation/gpio/board.txt
>>>>> and as Linus Walleij explained to me the other day, the lookup is
>>>>> supposed
>>>>> to replace devm_gpio_request_one(), which in turn replaced both the
>>>>> gpio_request and the gpio_direction_output(). Do I need to put the
>>>>> gpiod_direction_output() back or is there another interface for that
>>>>> when
>>>>> registering the board gpios?
>>>>
>>>>
>>>> Indeed.  If you *do* need an explicit _output() then that sounds to me
>>>> like we either need a gpiod_get_one() or an extension to the table,
>>>> looking at the code it seems like this is indeed the case.  We can set
>>>> if the GPIO is active high/low, or open source/drain but there's no flag
>>>> for the initial state.
>>>
>>>
>>> (adding Alexandre and the gpio list)
>>>
>>> GPIO people: any guidance on how a board file should set a gpio to
>>> output/default-high in a GPIO_LOOKUP() table to replace a
>>> devm_gpio_request_one() call in a device driver with devm_gpiod_get()?
>>> Do we need to add an interface extension to do this, e.g. passing
>>> GPIOF_OUT_INIT_HIGH as the flags rather than GPIO_ACTIVE_HIGH?
>>
>>
>> The way I see it, GPIO mappings (whether they are done using the
>> lookup tables, DT, or ACPI) should only care about details that are
>> relevant to the device layout and that should be abstracted to the
>> driver (e.g. whether the GPIO is active low or open drain) so drivers
>> do not need to check X conditions every time they want to drive the
>> GPIO.
>>
>> Direction and initial value, on the other hand, are clearly properties
>> that ought to be set by the driver itself. Thus my expectation here
>> would be that the driver sets the GPIO direction and initial value as
>> soon as it gets it using gpiod_direction_output(). In other words,
>> there is no replacement for gpio_request_one() with the gpiod
>> interface. Is there any use-case that cannot be covered by calling
>> gpiod_direction_output() right after gpiod_get()? AFAICT this is what
>> gpio_request_one() was doing anyway.
>
>
> I agree with you that this is something that should be done in the driver
> and not in the lookup table. I think that it is still a good idea to have a
> replacement for gpio_request_one with the new GPIO descriptor API. A large
> share of the drivers want to call either gpio_direction_input() or
> gpio_direction_output() right after requesting the GPIO. Combining both the
> requesting and the configuration of the GPIO into one function call makes
> the code a bit shorter and also simplifies the error handling. Even more so
> if e.g. the GPIO is optional. This was one of the main reasons why
> gpio_request_one was introduced, see the commit[1] that added it.

I am not opposed to it as a convenience function. Note that since the
open-source and open-drain flags are already handled by the lookup
table, the only flags it should handle are those related to direction,
value, and (maybe) sysfs export.

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [alsa-devel] [PATCH 2/4] ASoC: s3c64xx/smartq: use dynamic registration
  2014-07-15  7:36       ` Alexandre Courbot
  2014-07-15  7:58         ` Lars-Peter Clausen
@ 2014-07-15 10:39         ` Mark Brown
  1 sibling, 0 replies; 24+ messages in thread
From: Mark Brown @ 2014-07-15 10:39 UTC (permalink / raw)
  To: Alexandre Courbot
  Cc: Arnd Bergmann, Lars-Peter Clausen, alsa-devel@alsa-project.org,
	Kukjin Kim, Tomasz Figa, Maurus Cuelenaere, Liam Girdwood,
	linux-arm-kernel@lists.infradead.org, Linus Walleij,
	linux-gpio@vger.kernel.org

[-- Attachment #1: Type: text/plain, Size: 1010 bytes --]

On Tue, Jul 15, 2014 at 04:36:20PM +0900, Alexandre Courbot wrote:

> Direction and initial value, on the other hand, are clearly properties
> that ought to be set by the driver itself. Thus my expectation here
> would be that the driver sets the GPIO direction and initial value as
> soon as it gets it using gpiod_direction_output(). In other words,

Well, it's a bit of a mix really - from a hardware point of view they
normally are actually often fixed.

> there is no replacement for gpio_request_one() with the gpiod
> interface. Is there any use-case that cannot be covered by calling
> gpiod_direction_output() right after gpiod_get()? AFAICT this is what
> gpio_request_one() was doing anyway.

Right, the original goal was to provide a better interface for
requesting a GPIO - it saves a lot of error handling code throughout the
kernel and avoids the possibility of bugs due to users forgetting to
mark the directio for the GPIO.  Having a direct replacement also makes
conversions to gpiod easier.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [alsa-devel] [PATCH 2/4] ASoC: s3c64xx/smartq: use dynamic registration
  2014-07-15  9:14           ` [alsa-devel] " Alexandre Courbot
@ 2014-07-16  3:00             ` Alexandre Courbot
  2014-07-16  7:12               ` Thierry Reding
  0 siblings, 1 reply; 24+ messages in thread
From: Alexandre Courbot @ 2014-07-16  3:00 UTC (permalink / raw)
  To: Lars-Peter Clausen, Thierry Reding
  Cc: Arnd Bergmann, alsa-devel@alsa-project.org, Kukjin Kim,
	Tomasz Figa, Maurus Cuelenaere, Liam Girdwood,
	linux-gpio@vger.kernel.org, Mark Brown, Linus Walleij,
	linux-arm-kernel@lists.infradead.org

On Tue, Jul 15, 2014 at 6:14 PM, Alexandre Courbot <gnurou@gmail.com> wrote:
> On Tue, Jul 15, 2014 at 4:58 PM, Lars-Peter Clausen <lars@metafoo.de> wrote:
>> On 07/15/2014 09:36 AM, Alexandre Courbot wrote:
>>>
>>> On Tue, Jul 15, 2014 at 4:19 PM, Arnd Bergmann <arnd@arndb.de> wrote:
>>>>
>>>> On Monday 14 July 2014 19:36:24 Mark Brown wrote:
>>>>>
>>>>> On Mon, Jul 14, 2014 at 08:23:55PM +0200, Arnd Bergmann wrote:
>>>>>>
>>>>>> On Monday 14 July 2014 18:18:12 Lars-Peter Clausen wrote:
>>>>>
>>>>>
>>>>>>> Yes. But now that you say it the gpiod_direction_output() call is
>>>>>>> missing
>>>>>>> from this patch.
>>>>>
>>>>>
>>>>>> I'm lost now. The GPIO_ACTIVE_HIGH I added comes from
>>>>>> Documentation/gpio/board.txt
>>>>>> and as Linus Walleij explained to me the other day, the lookup is
>>>>>> supposed
>>>>>> to replace devm_gpio_request_one(), which in turn replaced both the
>>>>>> gpio_request and the gpio_direction_output(). Do I need to put the
>>>>>> gpiod_direction_output() back or is there another interface for that
>>>>>> when
>>>>>> registering the board gpios?
>>>>>
>>>>>
>>>>> Indeed.  If you *do* need an explicit _output() then that sounds to me
>>>>> like we either need a gpiod_get_one() or an extension to the table,
>>>>> looking at the code it seems like this is indeed the case.  We can set
>>>>> if the GPIO is active high/low, or open source/drain but there's no flag
>>>>> for the initial state.
>>>>
>>>>
>>>> (adding Alexandre and the gpio list)
>>>>
>>>> GPIO people: any guidance on how a board file should set a gpio to
>>>> output/default-high in a GPIO_LOOKUP() table to replace a
>>>> devm_gpio_request_one() call in a device driver with devm_gpiod_get()?
>>>> Do we need to add an interface extension to do this, e.g. passing
>>>> GPIOF_OUT_INIT_HIGH as the flags rather than GPIO_ACTIVE_HIGH?
>>>
>>>
>>> The way I see it, GPIO mappings (whether they are done using the
>>> lookup tables, DT, or ACPI) should only care about details that are
>>> relevant to the device layout and that should be abstracted to the
>>> driver (e.g. whether the GPIO is active low or open drain) so drivers
>>> do not need to check X conditions every time they want to drive the
>>> GPIO.
>>>
>>> Direction and initial value, on the other hand, are clearly properties
>>> that ought to be set by the driver itself. Thus my expectation here
>>> would be that the driver sets the GPIO direction and initial value as
>>> soon as it gets it using gpiod_direction_output(). In other words,
>>> there is no replacement for gpio_request_one() with the gpiod
>>> interface. Is there any use-case that cannot be covered by calling
>>> gpiod_direction_output() right after gpiod_get()? AFAICT this is what
>>> gpio_request_one() was doing anyway.
>>
>>
>> I agree with you that this is something that should be done in the driver
>> and not in the lookup table. I think that it is still a good idea to have a
>> replacement for gpio_request_one with the new GPIO descriptor API. A large
>> share of the drivers want to call either gpio_direction_input() or
>> gpio_direction_output() right after requesting the GPIO. Combining both the
>> requesting and the configuration of the GPIO into one function call makes
>> the code a bit shorter and also simplifies the error handling. Even more so
>> if e.g. the GPIO is optional. This was one of the main reasons why
>> gpio_request_one was introduced, see the commit[1] that added it.
>
> I am not opposed to it as a convenience function. Note that since the
> open-source and open-drain flags are already handled by the lookup
> table, the only flags it should handle are those related to direction,
> value, and (maybe) sysfs export.

Problem is, too much convenience functions seems to ultimately kill convenience.

The canonical way to request a GPIO is by providing a (device,
function, index) triplet to gpiod_get_index(). Since most functions
only need one GPIO, we have gpiod_get(device, function) which is
basically an alias to gpiod_get_index(device, function, 0) (note to
self: we should probably inline it).

On top of these comes another set of convenience functions,
gpiod_get_optional() and gpiod_get_index_optional(), which return NULL
instead of -ENOENT if the requested GPIO mapping does not exist. This
is useful for the common case where a driver can work without a GPIO.

Of course these functions all have devm counterparts, so we currently
have 8 (devm_)gpiod_get(_index)(_optional) functions.

If we are to add functions with an init flags parameter, we will end
with 16 functions. That starts to be a bit too much to my taste, and
maybe that's where GPIO consumers should sacrifice some convenience to
preserve a comprehensible GPIO API.

There might be other ways to work around this though. For instance, we
could replace the _optional functions by a GPIOF_OPTIONAL flag to be
passed to a more generic function that would also accept direction and
init value flags. Actually I am not seeing any user of the _optional
variant in -next, so maybe we should just do this. Thierry, since you
introduced the _optional functions, can we get your thoughts about
this?

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [alsa-devel] [PATCH 2/4] ASoC: s3c64xx/smartq: use dynamic registration
  2014-07-16  3:00             ` Alexandre Courbot
@ 2014-07-16  7:12               ` Thierry Reding
  2014-07-16  7:28                 ` Alexandre Courbot
  0 siblings, 1 reply; 24+ messages in thread
From: Thierry Reding @ 2014-07-16  7:12 UTC (permalink / raw)
  To: Alexandre Courbot
  Cc: Lars-Peter Clausen, Arnd Bergmann, alsa-devel@alsa-project.org,
	Kukjin Kim, Tomasz Figa, Maurus Cuelenaere, Liam Girdwood,
	linux-gpio@vger.kernel.org, Mark Brown, Linus Walleij,
	linux-arm-kernel@lists.infradead.org

[-- Attachment #1: Type: text/plain, Size: 6439 bytes --]

On Wed, Jul 16, 2014 at 12:00:45PM +0900, Alexandre Courbot wrote:
> On Tue, Jul 15, 2014 at 6:14 PM, Alexandre Courbot <gnurou@gmail.com> wrote:
> > On Tue, Jul 15, 2014 at 4:58 PM, Lars-Peter Clausen <lars@metafoo.de> wrote:
> >> On 07/15/2014 09:36 AM, Alexandre Courbot wrote:
> >>>
> >>> On Tue, Jul 15, 2014 at 4:19 PM, Arnd Bergmann <arnd@arndb.de> wrote:
> >>>>
> >>>> On Monday 14 July 2014 19:36:24 Mark Brown wrote:
> >>>>>
> >>>>> On Mon, Jul 14, 2014 at 08:23:55PM +0200, Arnd Bergmann wrote:
> >>>>>>
> >>>>>> On Monday 14 July 2014 18:18:12 Lars-Peter Clausen wrote:
> >>>>>
> >>>>>
> >>>>>>> Yes. But now that you say it the gpiod_direction_output() call is
> >>>>>>> missing
> >>>>>>> from this patch.
> >>>>>
> >>>>>
> >>>>>> I'm lost now. The GPIO_ACTIVE_HIGH I added comes from
> >>>>>> Documentation/gpio/board.txt
> >>>>>> and as Linus Walleij explained to me the other day, the lookup is
> >>>>>> supposed
> >>>>>> to replace devm_gpio_request_one(), which in turn replaced both the
> >>>>>> gpio_request and the gpio_direction_output(). Do I need to put the
> >>>>>> gpiod_direction_output() back or is there another interface for that
> >>>>>> when
> >>>>>> registering the board gpios?
> >>>>>
> >>>>>
> >>>>> Indeed.  If you *do* need an explicit _output() then that sounds to me
> >>>>> like we either need a gpiod_get_one() or an extension to the table,
> >>>>> looking at the code it seems like this is indeed the case.  We can set
> >>>>> if the GPIO is active high/low, or open source/drain but there's no flag
> >>>>> for the initial state.
> >>>>
> >>>>
> >>>> (adding Alexandre and the gpio list)
> >>>>
> >>>> GPIO people: any guidance on how a board file should set a gpio to
> >>>> output/default-high in a GPIO_LOOKUP() table to replace a
> >>>> devm_gpio_request_one() call in a device driver with devm_gpiod_get()?
> >>>> Do we need to add an interface extension to do this, e.g. passing
> >>>> GPIOF_OUT_INIT_HIGH as the flags rather than GPIO_ACTIVE_HIGH?
> >>>
> >>>
> >>> The way I see it, GPIO mappings (whether they are done using the
> >>> lookup tables, DT, or ACPI) should only care about details that are
> >>> relevant to the device layout and that should be abstracted to the
> >>> driver (e.g. whether the GPIO is active low or open drain) so drivers
> >>> do not need to check X conditions every time they want to drive the
> >>> GPIO.
> >>>
> >>> Direction and initial value, on the other hand, are clearly properties
> >>> that ought to be set by the driver itself. Thus my expectation here
> >>> would be that the driver sets the GPIO direction and initial value as
> >>> soon as it gets it using gpiod_direction_output(). In other words,
> >>> there is no replacement for gpio_request_one() with the gpiod
> >>> interface. Is there any use-case that cannot be covered by calling
> >>> gpiod_direction_output() right after gpiod_get()? AFAICT this is what
> >>> gpio_request_one() was doing anyway.
> >>
> >>
> >> I agree with you that this is something that should be done in the driver
> >> and not in the lookup table. I think that it is still a good idea to have a
> >> replacement for gpio_request_one with the new GPIO descriptor API. A large
> >> share of the drivers want to call either gpio_direction_input() or
> >> gpio_direction_output() right after requesting the GPIO. Combining both the
> >> requesting and the configuration of the GPIO into one function call makes
> >> the code a bit shorter and also simplifies the error handling. Even more so
> >> if e.g. the GPIO is optional. This was one of the main reasons why
> >> gpio_request_one was introduced, see the commit[1] that added it.
> >
> > I am not opposed to it as a convenience function. Note that since the
> > open-source and open-drain flags are already handled by the lookup
> > table, the only flags it should handle are those related to direction,
> > value, and (maybe) sysfs export.
> 
> Problem is, too much convenience functions seems to ultimately kill convenience.
> 
> The canonical way to request a GPIO is by providing a (device,
> function, index) triplet to gpiod_get_index(). Since most functions
> only need one GPIO, we have gpiod_get(device, function) which is
> basically an alias to gpiod_get_index(device, function, 0) (note to
> self: we should probably inline it).
> 
> On top of these comes another set of convenience functions,
> gpiod_get_optional() and gpiod_get_index_optional(), which return NULL
> instead of -ENOENT if the requested GPIO mapping does not exist. This
> is useful for the common case where a driver can work without a GPIO.
> 
> Of course these functions all have devm counterparts, so we currently
> have 8 (devm_)gpiod_get(_index)(_optional) functions.
> 
> If we are to add functions with an init flags parameter, we will end
> with 16 functions. That starts to be a bit too much to my taste, and
> maybe that's where GPIO consumers should sacrifice some convenience to
> preserve a comprehensible GPIO API.
> 
> There might be other ways to work around this though. For instance, we
> could replace the _optional functions by a GPIOF_OPTIONAL flag to be
> passed to a more generic function that would also accept direction and
> init value flags. Actually I am not seeing any user of the _optional
> variant in -next, so maybe we should just do this. Thierry, since you
> introduced the _optional functions, can we get your thoughts about
> this?

I personally prefer explicit naming of the functions rather than putting
a bunch of flags into some parameter. If you're overly concerned about
the amount of convenience functions, perhaps the _index variants can be
left out for gpiod_get_one(). I'd argue that if drivers want to deal
with that level of detail anyway, they may just as well add the index
explicitly when calling the function.

While we're at it, gpiod_get_one() doesn't sound like a very good name.
All other variants only request "one" as well. Perhaps something like
gpiod_get_with_flags() would be a better name.

Then again, maybe rather than add a new set of functions we should bite
the bullet and change gpiod_get() (and variants) to take an additional
flags parameter. There aren't all that many users yet (I count 26
outside of drivers/gpio), so maybe now would still be a good time to do
that.

Thierry

[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [alsa-devel] [PATCH 2/4] ASoC: s3c64xx/smartq: use dynamic registration
  2014-07-16  7:12               ` Thierry Reding
@ 2014-07-16  7:28                 ` Alexandre Courbot
  2014-07-16  7:51                   ` Thierry Reding
                                     ` (2 more replies)
  0 siblings, 3 replies; 24+ messages in thread
From: Alexandre Courbot @ 2014-07-16  7:28 UTC (permalink / raw)
  To: Thierry Reding
  Cc: Lars-Peter Clausen, Arnd Bergmann, alsa-devel@alsa-project.org,
	Kukjin Kim, Tomasz Figa, Maurus Cuelenaere, Liam Girdwood,
	linux-gpio@vger.kernel.org, Mark Brown, Linus Walleij,
	linux-arm-kernel@lists.infradead.org

On Wed, Jul 16, 2014 at 4:12 PM, Thierry Reding
<thierry.reding@gmail.com> wrote:
> On Wed, Jul 16, 2014 at 12:00:45PM +0900, Alexandre Courbot wrote:
>> On Tue, Jul 15, 2014 at 6:14 PM, Alexandre Courbot <gnurou@gmail.com> wrote:
>> > On Tue, Jul 15, 2014 at 4:58 PM, Lars-Peter Clausen <lars@metafoo.de> wrote:
>> >> On 07/15/2014 09:36 AM, Alexandre Courbot wrote:
>> >>>
>> >>> On Tue, Jul 15, 2014 at 4:19 PM, Arnd Bergmann <arnd@arndb.de> wrote:
>> >>>>
>> >>>> On Monday 14 July 2014 19:36:24 Mark Brown wrote:
>> >>>>>
>> >>>>> On Mon, Jul 14, 2014 at 08:23:55PM +0200, Arnd Bergmann wrote:
>> >>>>>>
>> >>>>>> On Monday 14 July 2014 18:18:12 Lars-Peter Clausen wrote:
>> >>>>>
>> >>>>>
>> >>>>>>> Yes. But now that you say it the gpiod_direction_output() call is
>> >>>>>>> missing
>> >>>>>>> from this patch.
>> >>>>>
>> >>>>>
>> >>>>>> I'm lost now. The GPIO_ACTIVE_HIGH I added comes from
>> >>>>>> Documentation/gpio/board.txt
>> >>>>>> and as Linus Walleij explained to me the other day, the lookup is
>> >>>>>> supposed
>> >>>>>> to replace devm_gpio_request_one(), which in turn replaced both the
>> >>>>>> gpio_request and the gpio_direction_output(). Do I need to put the
>> >>>>>> gpiod_direction_output() back or is there another interface for that
>> >>>>>> when
>> >>>>>> registering the board gpios?
>> >>>>>
>> >>>>>
>> >>>>> Indeed.  If you *do* need an explicit _output() then that sounds to me
>> >>>>> like we either need a gpiod_get_one() or an extension to the table,
>> >>>>> looking at the code it seems like this is indeed the case.  We can set
>> >>>>> if the GPIO is active high/low, or open source/drain but there's no flag
>> >>>>> for the initial state.
>> >>>>
>> >>>>
>> >>>> (adding Alexandre and the gpio list)
>> >>>>
>> >>>> GPIO people: any guidance on how a board file should set a gpio to
>> >>>> output/default-high in a GPIO_LOOKUP() table to replace a
>> >>>> devm_gpio_request_one() call in a device driver with devm_gpiod_get()?
>> >>>> Do we need to add an interface extension to do this, e.g. passing
>> >>>> GPIOF_OUT_INIT_HIGH as the flags rather than GPIO_ACTIVE_HIGH?
>> >>>
>> >>>
>> >>> The way I see it, GPIO mappings (whether they are done using the
>> >>> lookup tables, DT, or ACPI) should only care about details that are
>> >>> relevant to the device layout and that should be abstracted to the
>> >>> driver (e.g. whether the GPIO is active low or open drain) so drivers
>> >>> do not need to check X conditions every time they want to drive the
>> >>> GPIO.
>> >>>
>> >>> Direction and initial value, on the other hand, are clearly properties
>> >>> that ought to be set by the driver itself. Thus my expectation here
>> >>> would be that the driver sets the GPIO direction and initial value as
>> >>> soon as it gets it using gpiod_direction_output(). In other words,
>> >>> there is no replacement for gpio_request_one() with the gpiod
>> >>> interface. Is there any use-case that cannot be covered by calling
>> >>> gpiod_direction_output() right after gpiod_get()? AFAICT this is what
>> >>> gpio_request_one() was doing anyway.
>> >>
>> >>
>> >> I agree with you that this is something that should be done in the driver
>> >> and not in the lookup table. I think that it is still a good idea to have a
>> >> replacement for gpio_request_one with the new GPIO descriptor API. A large
>> >> share of the drivers want to call either gpio_direction_input() or
>> >> gpio_direction_output() right after requesting the GPIO. Combining both the
>> >> requesting and the configuration of the GPIO into one function call makes
>> >> the code a bit shorter and also simplifies the error handling. Even more so
>> >> if e.g. the GPIO is optional. This was one of the main reasons why
>> >> gpio_request_one was introduced, see the commit[1] that added it.
>> >
>> > I am not opposed to it as a convenience function. Note that since the
>> > open-source and open-drain flags are already handled by the lookup
>> > table, the only flags it should handle are those related to direction,
>> > value, and (maybe) sysfs export.
>>
>> Problem is, too much convenience functions seems to ultimately kill convenience.
>>
>> The canonical way to request a GPIO is by providing a (device,
>> function, index) triplet to gpiod_get_index(). Since most functions
>> only need one GPIO, we have gpiod_get(device, function) which is
>> basically an alias to gpiod_get_index(device, function, 0) (note to
>> self: we should probably inline it).
>>
>> On top of these comes another set of convenience functions,
>> gpiod_get_optional() and gpiod_get_index_optional(), which return NULL
>> instead of -ENOENT if the requested GPIO mapping does not exist. This
>> is useful for the common case where a driver can work without a GPIO.
>>
>> Of course these functions all have devm counterparts, so we currently
>> have 8 (devm_)gpiod_get(_index)(_optional) functions.
>>
>> If we are to add functions with an init flags parameter, we will end
>> with 16 functions. That starts to be a bit too much to my taste, and
>> maybe that's where GPIO consumers should sacrifice some convenience to
>> preserve a comprehensible GPIO API.
>>
>> There might be other ways to work around this though. For instance, we
>> could replace the _optional functions by a GPIOF_OPTIONAL flag to be
>> passed to a more generic function that would also accept direction and
>> init value flags. Actually I am not seeing any user of the _optional
>> variant in -next, so maybe we should just do this. Thierry, since you
>> introduced the _optional functions, can we get your thoughts about
>> this?
>
> I personally prefer explicit naming of the functions rather than putting
> a bunch of flags into some parameter. If you're overly concerned about
> the amount of convenience functions, perhaps the _index variants can be
> left out for gpiod_get_one(). I'd argue that if drivers want to deal
> with that level of detail anyway, they may just as well add the index
> explicitly when calling the function.
>
> While we're at it, gpiod_get_one() doesn't sound like a very good name.
> All other variants only request "one" as well. Perhaps something like
> gpiod_get_with_flags() would be a better name.
>
> Then again, maybe rather than add a new set of functions we should bite
> the bullet and change gpiod_get() (and variants) to take an additional
> flags parameter. There aren't all that many users yet (I count 26
> outside of drivers/gpio), so maybe now would still be a good time to do
> that.

That sounds reasonable indeed. And preferable to getting an aneurysm
after trying to spell devm_gpiod_get_index_optional_with_flags().

This also makes the most sense since most GPIO users will want to set
a direction and value right after obtaining one. So if there is no
objection I will probably start refactoring gpiod_get() this week.

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [alsa-devel] [PATCH 2/4] ASoC: s3c64xx/smartq: use dynamic registration
  2014-07-16  7:28                 ` Alexandre Courbot
@ 2014-07-16  7:51                   ` Thierry Reding
  2014-07-16  8:50                     ` Rob Jones
  2014-07-16  9:48                   ` Mark Brown
  2014-07-24 15:10                   ` Alexandre Courbot
  2 siblings, 1 reply; 24+ messages in thread
From: Thierry Reding @ 2014-07-16  7:51 UTC (permalink / raw)
  To: Alexandre Courbot
  Cc: Lars-Peter Clausen, Arnd Bergmann, alsa-devel@alsa-project.org,
	Kukjin Kim, Tomasz Figa, Maurus Cuelenaere, Liam Girdwood,
	linux-gpio@vger.kernel.org, Mark Brown, Linus Walleij,
	linux-arm-kernel@lists.infradead.org

[-- Attachment #1: Type: text/plain, Size: 7357 bytes --]

On Wed, Jul 16, 2014 at 04:28:33PM +0900, Alexandre Courbot wrote:
> On Wed, Jul 16, 2014 at 4:12 PM, Thierry Reding
> <thierry.reding@gmail.com> wrote:
> > On Wed, Jul 16, 2014 at 12:00:45PM +0900, Alexandre Courbot wrote:
> >> On Tue, Jul 15, 2014 at 6:14 PM, Alexandre Courbot <gnurou@gmail.com> wrote:
> >> > On Tue, Jul 15, 2014 at 4:58 PM, Lars-Peter Clausen <lars@metafoo.de> wrote:
> >> >> On 07/15/2014 09:36 AM, Alexandre Courbot wrote:
> >> >>>
> >> >>> On Tue, Jul 15, 2014 at 4:19 PM, Arnd Bergmann <arnd@arndb.de> wrote:
> >> >>>>
> >> >>>> On Monday 14 July 2014 19:36:24 Mark Brown wrote:
> >> >>>>>
> >> >>>>> On Mon, Jul 14, 2014 at 08:23:55PM +0200, Arnd Bergmann wrote:
> >> >>>>>>
> >> >>>>>> On Monday 14 July 2014 18:18:12 Lars-Peter Clausen wrote:
> >> >>>>>
> >> >>>>>
> >> >>>>>>> Yes. But now that you say it the gpiod_direction_output() call is
> >> >>>>>>> missing
> >> >>>>>>> from this patch.
> >> >>>>>
> >> >>>>>
> >> >>>>>> I'm lost now. The GPIO_ACTIVE_HIGH I added comes from
> >> >>>>>> Documentation/gpio/board.txt
> >> >>>>>> and as Linus Walleij explained to me the other day, the lookup is
> >> >>>>>> supposed
> >> >>>>>> to replace devm_gpio_request_one(), which in turn replaced both the
> >> >>>>>> gpio_request and the gpio_direction_output(). Do I need to put the
> >> >>>>>> gpiod_direction_output() back or is there another interface for that
> >> >>>>>> when
> >> >>>>>> registering the board gpios?
> >> >>>>>
> >> >>>>>
> >> >>>>> Indeed.  If you *do* need an explicit _output() then that sounds to me
> >> >>>>> like we either need a gpiod_get_one() or an extension to the table,
> >> >>>>> looking at the code it seems like this is indeed the case.  We can set
> >> >>>>> if the GPIO is active high/low, or open source/drain but there's no flag
> >> >>>>> for the initial state.
> >> >>>>
> >> >>>>
> >> >>>> (adding Alexandre and the gpio list)
> >> >>>>
> >> >>>> GPIO people: any guidance on how a board file should set a gpio to
> >> >>>> output/default-high in a GPIO_LOOKUP() table to replace a
> >> >>>> devm_gpio_request_one() call in a device driver with devm_gpiod_get()?
> >> >>>> Do we need to add an interface extension to do this, e.g. passing
> >> >>>> GPIOF_OUT_INIT_HIGH as the flags rather than GPIO_ACTIVE_HIGH?
> >> >>>
> >> >>>
> >> >>> The way I see it, GPIO mappings (whether they are done using the
> >> >>> lookup tables, DT, or ACPI) should only care about details that are
> >> >>> relevant to the device layout and that should be abstracted to the
> >> >>> driver (e.g. whether the GPIO is active low or open drain) so drivers
> >> >>> do not need to check X conditions every time they want to drive the
> >> >>> GPIO.
> >> >>>
> >> >>> Direction and initial value, on the other hand, are clearly properties
> >> >>> that ought to be set by the driver itself. Thus my expectation here
> >> >>> would be that the driver sets the GPIO direction and initial value as
> >> >>> soon as it gets it using gpiod_direction_output(). In other words,
> >> >>> there is no replacement for gpio_request_one() with the gpiod
> >> >>> interface. Is there any use-case that cannot be covered by calling
> >> >>> gpiod_direction_output() right after gpiod_get()? AFAICT this is what
> >> >>> gpio_request_one() was doing anyway.
> >> >>
> >> >>
> >> >> I agree with you that this is something that should be done in the driver
> >> >> and not in the lookup table. I think that it is still a good idea to have a
> >> >> replacement for gpio_request_one with the new GPIO descriptor API. A large
> >> >> share of the drivers want to call either gpio_direction_input() or
> >> >> gpio_direction_output() right after requesting the GPIO. Combining both the
> >> >> requesting and the configuration of the GPIO into one function call makes
> >> >> the code a bit shorter and also simplifies the error handling. Even more so
> >> >> if e.g. the GPIO is optional. This was one of the main reasons why
> >> >> gpio_request_one was introduced, see the commit[1] that added it.
> >> >
> >> > I am not opposed to it as a convenience function. Note that since the
> >> > open-source and open-drain flags are already handled by the lookup
> >> > table, the only flags it should handle are those related to direction,
> >> > value, and (maybe) sysfs export.
> >>
> >> Problem is, too much convenience functions seems to ultimately kill convenience.
> >>
> >> The canonical way to request a GPIO is by providing a (device,
> >> function, index) triplet to gpiod_get_index(). Since most functions
> >> only need one GPIO, we have gpiod_get(device, function) which is
> >> basically an alias to gpiod_get_index(device, function, 0) (note to
> >> self: we should probably inline it).
> >>
> >> On top of these comes another set of convenience functions,
> >> gpiod_get_optional() and gpiod_get_index_optional(), which return NULL
> >> instead of -ENOENT if the requested GPIO mapping does not exist. This
> >> is useful for the common case where a driver can work without a GPIO.
> >>
> >> Of course these functions all have devm counterparts, so we currently
> >> have 8 (devm_)gpiod_get(_index)(_optional) functions.
> >>
> >> If we are to add functions with an init flags parameter, we will end
> >> with 16 functions. That starts to be a bit too much to my taste, and
> >> maybe that's where GPIO consumers should sacrifice some convenience to
> >> preserve a comprehensible GPIO API.
> >>
> >> There might be other ways to work around this though. For instance, we
> >> could replace the _optional functions by a GPIOF_OPTIONAL flag to be
> >> passed to a more generic function that would also accept direction and
> >> init value flags. Actually I am not seeing any user of the _optional
> >> variant in -next, so maybe we should just do this. Thierry, since you
> >> introduced the _optional functions, can we get your thoughts about
> >> this?
> >
> > I personally prefer explicit naming of the functions rather than putting
> > a bunch of flags into some parameter. If you're overly concerned about
> > the amount of convenience functions, perhaps the _index variants can be
> > left out for gpiod_get_one(). I'd argue that if drivers want to deal
> > with that level of detail anyway, they may just as well add the index
> > explicitly when calling the function.
> >
> > While we're at it, gpiod_get_one() doesn't sound like a very good name.
> > All other variants only request "one" as well. Perhaps something like
> > gpiod_get_with_flags() would be a better name.
> >
> > Then again, maybe rather than add a new set of functions we should bite
> > the bullet and change gpiod_get() (and variants) to take an additional
> > flags parameter. There aren't all that many users yet (I count 26
> > outside of drivers/gpio), so maybe now would still be a good time to do
> > that.
> 
> That sounds reasonable indeed. And preferable to getting an aneurysm
> after trying to spell devm_gpiod_get_index_optional_with_flags().
> 
> This also makes the most sense since most GPIO users will want to set
> a direction and value right after obtaining one. So if there is no
> objection I will probably start refactoring gpiod_get() this week.

Sounds good to me.

Thierry

[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [alsa-devel] [PATCH 2/4] ASoC: s3c64xx/smartq: use dynamic registration
  2014-07-16  7:51                   ` Thierry Reding
@ 2014-07-16  8:50                     ` Rob Jones
  2014-07-16 11:09                       ` Thierry Reding
  2014-07-17  4:28                       ` Alexandre Courbot
  0 siblings, 2 replies; 24+ messages in thread
From: Rob Jones @ 2014-07-16  8:50 UTC (permalink / raw)
  To: Thierry Reding, Alexandre Courbot
  Cc: Lars-Peter Clausen, Arnd Bergmann, alsa-devel@alsa-project.org,
	Kukjin Kim, Tomasz Figa, Maurus Cuelenaere, Liam Girdwood,
	linux-gpio@vger.kernel.org, Mark Brown, Linus Walleij,
	linux-arm-kernel@lists.infradead.org



On 16/07/14 08:51, Thierry Reding wrote:
> On Wed, Jul 16, 2014 at 04:28:33PM +0900, Alexandre Courbot wrote:
>> On Wed, Jul 16, 2014 at 4:12 PM, Thierry Reding
>> <thierry.reding@gmail.com> wrote:
>>> On Wed, Jul 16, 2014 at 12:00:45PM +0900, Alexandre Courbot wrote:
>>>> On Tue, Jul 15, 2014 at 6:14 PM, Alexandre Courbot <gnurou@gmail.com> wrote:
>>>>> On Tue, Jul 15, 2014 at 4:58 PM, Lars-Peter Clausen <lars@metafoo.de> wrote:
>>>>>> On 07/15/2014 09:36 AM, Alexandre Courbot wrote:
>>>>>>>
>>>>>>> On Tue, Jul 15, 2014 at 4:19 PM, Arnd Bergmann <arnd@arndb.de> wrote:
>>>>>>>>
>>>>>>>> On Monday 14 July 2014 19:36:24 Mark Brown wrote:
>>>>>>>>>
>>>>>>>>> On Mon, Jul 14, 2014 at 08:23:55PM +0200, Arnd Bergmann wrote:
>>>>>>>>>>
>>>>>>>>>> On Monday 14 July 2014 18:18:12 Lars-Peter Clausen wrote:
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>>> Yes. But now that you say it the gpiod_direction_output() call is
>>>>>>>>>>> missing
>>>>>>>>>>> from this patch.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>> I'm lost now. The GPIO_ACTIVE_HIGH I added comes from
>>>>>>>>>> Documentation/gpio/board.txt
>>>>>>>>>> and as Linus Walleij explained to me the other day, the lookup is
>>>>>>>>>> supposed
>>>>>>>>>> to replace devm_gpio_request_one(), which in turn replaced both the
>>>>>>>>>> gpio_request and the gpio_direction_output(). Do I need to put the
>>>>>>>>>> gpiod_direction_output() back or is there another interface for that
>>>>>>>>>> when
>>>>>>>>>> registering the board gpios?
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Indeed.  If you *do* need an explicit _output() then that sounds to me
>>>>>>>>> like we either need a gpiod_get_one() or an extension to the table,
>>>>>>>>> looking at the code it seems like this is indeed the case.  We can set
>>>>>>>>> if the GPIO is active high/low, or open source/drain but there's no flag
>>>>>>>>> for the initial state.
>>>>>>>>
>>>>>>>>
>>>>>>>> (adding Alexandre and the gpio list)
>>>>>>>>
>>>>>>>> GPIO people: any guidance on how a board file should set a gpio to
>>>>>>>> output/default-high in a GPIO_LOOKUP() table to replace a
>>>>>>>> devm_gpio_request_one() call in a device driver with devm_gpiod_get()?
>>>>>>>> Do we need to add an interface extension to do this, e.g. passing
>>>>>>>> GPIOF_OUT_INIT_HIGH as the flags rather than GPIO_ACTIVE_HIGH?
>>>>>>>
>>>>>>>
>>>>>>> The way I see it, GPIO mappings (whether they are done using the
>>>>>>> lookup tables, DT, or ACPI) should only care about details that are
>>>>>>> relevant to the device layout and that should be abstracted to the
>>>>>>> driver (e.g. whether the GPIO is active low or open drain) so drivers
>>>>>>> do not need to check X conditions every time they want to drive the
>>>>>>> GPIO.
>>>>>>>
>>>>>>> Direction and initial value, on the other hand, are clearly properties
>>>>>>> that ought to be set by the driver itself. Thus my expectation here
>>>>>>> would be that the driver sets the GPIO direction and initial value as
>>>>>>> soon as it gets it using gpiod_direction_output(). In other words,
>>>>>>> there is no replacement for gpio_request_one() with the gpiod
>>>>>>> interface. Is there any use-case that cannot be covered by calling
>>>>>>> gpiod_direction_output() right after gpiod_get()? AFAICT this is what
>>>>>>> gpio_request_one() was doing anyway.
>>>>>>
>>>>>>
>>>>>> I agree with you that this is something that should be done in the driver
>>>>>> and not in the lookup table. I think that it is still a good idea to have a
>>>>>> replacement for gpio_request_one with the new GPIO descriptor API. A large
>>>>>> share of the drivers want to call either gpio_direction_input() or
>>>>>> gpio_direction_output() right after requesting the GPIO. Combining both the
>>>>>> requesting and the configuration of the GPIO into one function call makes
>>>>>> the code a bit shorter and also simplifies the error handling. Even more so
>>>>>> if e.g. the GPIO is optional. This was one of the main reasons why
>>>>>> gpio_request_one was introduced, see the commit[1] that added it.
>>>>>
>>>>> I am not opposed to it as a convenience function. Note that since the
>>>>> open-source and open-drain flags are already handled by the lookup
>>>>> table, the only flags it should handle are those related to direction,
>>>>> value, and (maybe) sysfs export.
>>>>
>>>> Problem is, too much convenience functions seems to ultimately kill convenience.
>>>>
>>>> The canonical way to request a GPIO is by providing a (device,
>>>> function, index) triplet to gpiod_get_index(). Since most functions
>>>> only need one GPIO, we have gpiod_get(device, function) which is
>>>> basically an alias to gpiod_get_index(device, function, 0) (note to
>>>> self: we should probably inline it).
>>>>
>>>> On top of these comes another set of convenience functions,
>>>> gpiod_get_optional() and gpiod_get_index_optional(), which return NULL
>>>> instead of -ENOENT if the requested GPIO mapping does not exist. This
>>>> is useful for the common case where a driver can work without a GPIO.
>>>>
>>>> Of course these functions all have devm counterparts, so we currently
>>>> have 8 (devm_)gpiod_get(_index)(_optional) functions.
>>>>
>>>> If we are to add functions with an init flags parameter, we will end
>>>> with 16 functions. That starts to be a bit too much to my taste, and
>>>> maybe that's where GPIO consumers should sacrifice some convenience to
>>>> preserve a comprehensible GPIO API.
>>>>
>>>> There might be other ways to work around this though. For instance, we
>>>> could replace the _optional functions by a GPIOF_OPTIONAL flag to be
>>>> passed to a more generic function that would also accept direction and
>>>> init value flags. Actually I am not seeing any user of the _optional
>>>> variant in -next, so maybe we should just do this. Thierry, since you
>>>> introduced the _optional functions, can we get your thoughts about
>>>> this?
>>>
>>> I personally prefer explicit naming of the functions rather than putting
>>> a bunch of flags into some parameter. If you're overly concerned about
>>> the amount of convenience functions, perhaps the _index variants can be
>>> left out for gpiod_get_one(). I'd argue that if drivers want to deal
>>> with that level of detail anyway, they may just as well add the index
>>> explicitly when calling the function.
>>>
>>> While we're at it, gpiod_get_one() doesn't sound like a very good name.
>>> All other variants only request "one" as well. Perhaps something like
>>> gpiod_get_with_flags() would be a better name.
>>>
>>> Then again, maybe rather than add a new set of functions we should bite
>>> the bullet and change gpiod_get() (and variants) to take an additional
>>> flags parameter. There aren't all that many users yet (I count 26
>>> outside of drivers/gpio), so maybe now would still be a good time to do
>>> that.
>>
>> That sounds reasonable indeed. And preferable to getting an aneurysm
>> after trying to spell devm_gpiod_get_index_optional_with_flags().
>>
>> This also makes the most sense since most GPIO users will want to set
>> a direction and value right after obtaining one. So if there is no
>> objection I will probably start refactoring gpiod_get() this week.
>
> Sounds good to me.
>

In light of this, should I hold off starting on devm_gpiod_get_array()
as discussed on here last week?

> Thierry
>

-- 
Rob Jones
Codethink Ltd
mailto:rob.jones@codethink.co.uk
tel:+44 161 236 5575

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [alsa-devel] [PATCH 2/4] ASoC: s3c64xx/smartq: use dynamic registration
  2014-07-16  7:28                 ` Alexandre Courbot
  2014-07-16  7:51                   ` Thierry Reding
@ 2014-07-16  9:48                   ` Mark Brown
  2014-07-24 15:10                   ` Alexandre Courbot
  2 siblings, 0 replies; 24+ messages in thread
From: Mark Brown @ 2014-07-16  9:48 UTC (permalink / raw)
  To: Alexandre Courbot
  Cc: Thierry Reding, Lars-Peter Clausen, Arnd Bergmann,
	alsa-devel@alsa-project.org, Kukjin Kim, Tomasz Figa,
	Maurus Cuelenaere, Liam Girdwood, linux-gpio@vger.kernel.org,
	Linus Walleij, linux-arm-kernel@lists.infradead.org

[-- Attachment #1: Type: text/plain, Size: 790 bytes --]

On Wed, Jul 16, 2014 at 04:28:33PM +0900, Alexandre Courbot wrote:
> On Wed, Jul 16, 2014 at 4:12 PM, Thierry Reding

> > Then again, maybe rather than add a new set of functions we should bite
> > the bullet and change gpiod_get() (and variants) to take an additional
> > flags parameter. There aren't all that many users yet (I count 26
> > outside of drivers/gpio), so maybe now would still be a good time to do
> > that.

> That sounds reasonable indeed. And preferable to getting an aneurysm
> after trying to spell devm_gpiod_get_index_optional_with_flags().

> This also makes the most sense since most GPIO users will want to set
> a direction and value right after obtaining one. So if there is no
> objection I will probably start refactoring gpiod_get() this week.

Yes, please!

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [alsa-devel] [PATCH 2/4] ASoC: s3c64xx/smartq: use dynamic registration
  2014-07-16  8:50                     ` Rob Jones
@ 2014-07-16 11:09                       ` Thierry Reding
  2014-07-23 15:20                         ` Linus Walleij
  2014-07-17  4:28                       ` Alexandre Courbot
  1 sibling, 1 reply; 24+ messages in thread
From: Thierry Reding @ 2014-07-16 11:09 UTC (permalink / raw)
  To: Rob Jones
  Cc: Alexandre Courbot, Lars-Peter Clausen, Arnd Bergmann,
	alsa-devel@alsa-project.org, Kukjin Kim, Tomasz Figa,
	Maurus Cuelenaere, Liam Girdwood, linux-gpio@vger.kernel.org,
	Mark Brown, Linus Walleij, linux-arm-kernel@lists.infradead.org

[-- Attachment #1: Type: text/plain, Size: 7924 bytes --]

On Wed, Jul 16, 2014 at 09:50:02AM +0100, Rob Jones wrote:
> 
> 
> On 16/07/14 08:51, Thierry Reding wrote:
> >On Wed, Jul 16, 2014 at 04:28:33PM +0900, Alexandre Courbot wrote:
> >>On Wed, Jul 16, 2014 at 4:12 PM, Thierry Reding
> >><thierry.reding@gmail.com> wrote:
> >>>On Wed, Jul 16, 2014 at 12:00:45PM +0900, Alexandre Courbot wrote:
> >>>>On Tue, Jul 15, 2014 at 6:14 PM, Alexandre Courbot <gnurou@gmail.com> wrote:
> >>>>>On Tue, Jul 15, 2014 at 4:58 PM, Lars-Peter Clausen <lars@metafoo.de> wrote:
> >>>>>>On 07/15/2014 09:36 AM, Alexandre Courbot wrote:
> >>>>>>>
> >>>>>>>On Tue, Jul 15, 2014 at 4:19 PM, Arnd Bergmann <arnd@arndb.de> wrote:
> >>>>>>>>
> >>>>>>>>On Monday 14 July 2014 19:36:24 Mark Brown wrote:
> >>>>>>>>>
> >>>>>>>>>On Mon, Jul 14, 2014 at 08:23:55PM +0200, Arnd Bergmann wrote:
> >>>>>>>>>>
> >>>>>>>>>>On Monday 14 July 2014 18:18:12 Lars-Peter Clausen wrote:
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>>>Yes. But now that you say it the gpiod_direction_output() call is
> >>>>>>>>>>>missing
> >>>>>>>>>>>from this patch.
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>>I'm lost now. The GPIO_ACTIVE_HIGH I added comes from
> >>>>>>>>>>Documentation/gpio/board.txt
> >>>>>>>>>>and as Linus Walleij explained to me the other day, the lookup is
> >>>>>>>>>>supposed
> >>>>>>>>>>to replace devm_gpio_request_one(), which in turn replaced both the
> >>>>>>>>>>gpio_request and the gpio_direction_output(). Do I need to put the
> >>>>>>>>>>gpiod_direction_output() back or is there another interface for that
> >>>>>>>>>>when
> >>>>>>>>>>registering the board gpios?
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>Indeed.  If you *do* need an explicit _output() then that sounds to me
> >>>>>>>>>like we either need a gpiod_get_one() or an extension to the table,
> >>>>>>>>>looking at the code it seems like this is indeed the case.  We can set
> >>>>>>>>>if the GPIO is active high/low, or open source/drain but there's no flag
> >>>>>>>>>for the initial state.
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>(adding Alexandre and the gpio list)
> >>>>>>>>
> >>>>>>>>GPIO people: any guidance on how a board file should set a gpio to
> >>>>>>>>output/default-high in a GPIO_LOOKUP() table to replace a
> >>>>>>>>devm_gpio_request_one() call in a device driver with devm_gpiod_get()?
> >>>>>>>>Do we need to add an interface extension to do this, e.g. passing
> >>>>>>>>GPIOF_OUT_INIT_HIGH as the flags rather than GPIO_ACTIVE_HIGH?
> >>>>>>>
> >>>>>>>
> >>>>>>>The way I see it, GPIO mappings (whether they are done using the
> >>>>>>>lookup tables, DT, or ACPI) should only care about details that are
> >>>>>>>relevant to the device layout and that should be abstracted to the
> >>>>>>>driver (e.g. whether the GPIO is active low or open drain) so drivers
> >>>>>>>do not need to check X conditions every time they want to drive the
> >>>>>>>GPIO.
> >>>>>>>
> >>>>>>>Direction and initial value, on the other hand, are clearly properties
> >>>>>>>that ought to be set by the driver itself. Thus my expectation here
> >>>>>>>would be that the driver sets the GPIO direction and initial value as
> >>>>>>>soon as it gets it using gpiod_direction_output(). In other words,
> >>>>>>>there is no replacement for gpio_request_one() with the gpiod
> >>>>>>>interface. Is there any use-case that cannot be covered by calling
> >>>>>>>gpiod_direction_output() right after gpiod_get()? AFAICT this is what
> >>>>>>>gpio_request_one() was doing anyway.
> >>>>>>
> >>>>>>
> >>>>>>I agree with you that this is something that should be done in the driver
> >>>>>>and not in the lookup table. I think that it is still a good idea to have a
> >>>>>>replacement for gpio_request_one with the new GPIO descriptor API. A large
> >>>>>>share of the drivers want to call either gpio_direction_input() or
> >>>>>>gpio_direction_output() right after requesting the GPIO. Combining both the
> >>>>>>requesting and the configuration of the GPIO into one function call makes
> >>>>>>the code a bit shorter and also simplifies the error handling. Even more so
> >>>>>>if e.g. the GPIO is optional. This was one of the main reasons why
> >>>>>>gpio_request_one was introduced, see the commit[1] that added it.
> >>>>>
> >>>>>I am not opposed to it as a convenience function. Note that since the
> >>>>>open-source and open-drain flags are already handled by the lookup
> >>>>>table, the only flags it should handle are those related to direction,
> >>>>>value, and (maybe) sysfs export.
> >>>>
> >>>>Problem is, too much convenience functions seems to ultimately kill convenience.
> >>>>
> >>>>The canonical way to request a GPIO is by providing a (device,
> >>>>function, index) triplet to gpiod_get_index(). Since most functions
> >>>>only need one GPIO, we have gpiod_get(device, function) which is
> >>>>basically an alias to gpiod_get_index(device, function, 0) (note to
> >>>>self: we should probably inline it).
> >>>>
> >>>>On top of these comes another set of convenience functions,
> >>>>gpiod_get_optional() and gpiod_get_index_optional(), which return NULL
> >>>>instead of -ENOENT if the requested GPIO mapping does not exist. This
> >>>>is useful for the common case where a driver can work without a GPIO.
> >>>>
> >>>>Of course these functions all have devm counterparts, so we currently
> >>>>have 8 (devm_)gpiod_get(_index)(_optional) functions.
> >>>>
> >>>>If we are to add functions with an init flags parameter, we will end
> >>>>with 16 functions. That starts to be a bit too much to my taste, and
> >>>>maybe that's where GPIO consumers should sacrifice some convenience to
> >>>>preserve a comprehensible GPIO API.
> >>>>
> >>>>There might be other ways to work around this though. For instance, we
> >>>>could replace the _optional functions by a GPIOF_OPTIONAL flag to be
> >>>>passed to a more generic function that would also accept direction and
> >>>>init value flags. Actually I am not seeing any user of the _optional
> >>>>variant in -next, so maybe we should just do this. Thierry, since you
> >>>>introduced the _optional functions, can we get your thoughts about
> >>>>this?
> >>>
> >>>I personally prefer explicit naming of the functions rather than putting
> >>>a bunch of flags into some parameter. If you're overly concerned about
> >>>the amount of convenience functions, perhaps the _index variants can be
> >>>left out for gpiod_get_one(). I'd argue that if drivers want to deal
> >>>with that level of detail anyway, they may just as well add the index
> >>>explicitly when calling the function.
> >>>
> >>>While we're at it, gpiod_get_one() doesn't sound like a very good name.
> >>>All other variants only request "one" as well. Perhaps something like
> >>>gpiod_get_with_flags() would be a better name.
> >>>
> >>>Then again, maybe rather than add a new set of functions we should bite
> >>>the bullet and change gpiod_get() (and variants) to take an additional
> >>>flags parameter. There aren't all that many users yet (I count 26
> >>>outside of drivers/gpio), so maybe now would still be a good time to do
> >>>that.
> >>
> >>That sounds reasonable indeed. And preferable to getting an aneurysm
> >>after trying to spell devm_gpiod_get_index_optional_with_flags().
> >>
> >>This also makes the most sense since most GPIO users will want to set
> >>a direction and value right after obtaining one. So if there is no
> >>objection I will probably start refactoring gpiod_get() this week.
> >
> >Sounds good to me.
> >
> 
> In light of this, should I hold off starting on devm_gpiod_get_array()
> as discussed on here last week?

I'll let Alex or Linus answer this, since I wasn't involved in the
devm_gpiod_get_array() discussions. It's probably going to be tricky to
pass around an array of everything, but I suspect you've already got a
solution to that.

Thierry

[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [alsa-devel] [PATCH 2/4] ASoC: s3c64xx/smartq: use dynamic registration
  2014-07-16  8:50                     ` Rob Jones
  2014-07-16 11:09                       ` Thierry Reding
@ 2014-07-17  4:28                       ` Alexandre Courbot
  2014-07-17  7:44                         ` Thierry Reding
  1 sibling, 1 reply; 24+ messages in thread
From: Alexandre Courbot @ 2014-07-17  4:28 UTC (permalink / raw)
  To: Rob Jones, Rojhalat Ibrahim
  Cc: Thierry Reding, Lars-Peter Clausen, Arnd Bergmann,
	alsa-devel@alsa-project.org, Kukjin Kim, Tomasz Figa,
	Maurus Cuelenaere, Liam Girdwood, linux-gpio@vger.kernel.org,
	Mark Brown, Linus Walleij, linux-arm-kernel@lists.infradead.org

On Wed, Jul 16, 2014 at 5:50 PM, Rob Jones <rob.jones@codethink.co.uk> wrote:
>
>
> On 16/07/14 08:51, Thierry Reding wrote:
>>
>> On Wed, Jul 16, 2014 at 04:28:33PM +0900, Alexandre Courbot wrote:
>>>
>>> On Wed, Jul 16, 2014 at 4:12 PM, Thierry Reding
>>> <thierry.reding@gmail.com> wrote:
>>>>
>>>> On Wed, Jul 16, 2014 at 12:00:45PM +0900, Alexandre Courbot wrote:
>>>>>
>>>>> On Tue, Jul 15, 2014 at 6:14 PM, Alexandre Courbot <gnurou@gmail.com>
>>>>> wrote:
>>>>>>
>>>>>> On Tue, Jul 15, 2014 at 4:58 PM, Lars-Peter Clausen <lars@metafoo.de>
>>>>>> wrote:
>>>>>>>
>>>>>>> On 07/15/2014 09:36 AM, Alexandre Courbot wrote:
>>>>>>>>
>>>>>>>>
>>>>>>>> On Tue, Jul 15, 2014 at 4:19 PM, Arnd Bergmann <arnd@arndb.de>
>>>>>>>> wrote:
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On Monday 14 July 2014 19:36:24 Mark Brown wrote:
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On Mon, Jul 14, 2014 at 08:23:55PM +0200, Arnd Bergmann wrote:
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> On Monday 14 July 2014 18:18:12 Lars-Peter Clausen wrote:
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>>> Yes. But now that you say it the gpiod_direction_output() call
>>>>>>>>>>>> is
>>>>>>>>>>>> missing
>>>>>>>>>>>> from this patch.
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>> I'm lost now. The GPIO_ACTIVE_HIGH I added comes from
>>>>>>>>>>> Documentation/gpio/board.txt
>>>>>>>>>>> and as Linus Walleij explained to me the other day, the lookup is
>>>>>>>>>>> supposed
>>>>>>>>>>> to replace devm_gpio_request_one(), which in turn replaced both
>>>>>>>>>>> the
>>>>>>>>>>> gpio_request and the gpio_direction_output(). Do I need to put
>>>>>>>>>>> the
>>>>>>>>>>> gpiod_direction_output() back or is there another interface for
>>>>>>>>>>> that
>>>>>>>>>>> when
>>>>>>>>>>> registering the board gpios?
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> Indeed.  If you *do* need an explicit _output() then that sounds
>>>>>>>>>> to me
>>>>>>>>>> like we either need a gpiod_get_one() or an extension to the
>>>>>>>>>> table,
>>>>>>>>>> looking at the code it seems like this is indeed the case.  We can
>>>>>>>>>> set
>>>>>>>>>> if the GPIO is active high/low, or open source/drain but there's
>>>>>>>>>> no flag
>>>>>>>>>> for the initial state.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> (adding Alexandre and the gpio list)
>>>>>>>>>
>>>>>>>>> GPIO people: any guidance on how a board file should set a gpio to
>>>>>>>>> output/default-high in a GPIO_LOOKUP() table to replace a
>>>>>>>>> devm_gpio_request_one() call in a device driver with
>>>>>>>>> devm_gpiod_get()?
>>>>>>>>> Do we need to add an interface extension to do this, e.g. passing
>>>>>>>>> GPIOF_OUT_INIT_HIGH as the flags rather than GPIO_ACTIVE_HIGH?
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> The way I see it, GPIO mappings (whether they are done using the
>>>>>>>> lookup tables, DT, or ACPI) should only care about details that are
>>>>>>>> relevant to the device layout and that should be abstracted to the
>>>>>>>> driver (e.g. whether the GPIO is active low or open drain) so
>>>>>>>> drivers
>>>>>>>> do not need to check X conditions every time they want to drive the
>>>>>>>> GPIO.
>>>>>>>>
>>>>>>>> Direction and initial value, on the other hand, are clearly
>>>>>>>> properties
>>>>>>>> that ought to be set by the driver itself. Thus my expectation here
>>>>>>>> would be that the driver sets the GPIO direction and initial value
>>>>>>>> as
>>>>>>>> soon as it gets it using gpiod_direction_output(). In other words,
>>>>>>>> there is no replacement for gpio_request_one() with the gpiod
>>>>>>>> interface. Is there any use-case that cannot be covered by calling
>>>>>>>> gpiod_direction_output() right after gpiod_get()? AFAICT this is
>>>>>>>> what
>>>>>>>> gpio_request_one() was doing anyway.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> I agree with you that this is something that should be done in the
>>>>>>> driver
>>>>>>> and not in the lookup table. I think that it is still a good idea to
>>>>>>> have a
>>>>>>> replacement for gpio_request_one with the new GPIO descriptor API. A
>>>>>>> large
>>>>>>> share of the drivers want to call either gpio_direction_input() or
>>>>>>> gpio_direction_output() right after requesting the GPIO. Combining
>>>>>>> both the
>>>>>>> requesting and the configuration of the GPIO into one function call
>>>>>>> makes
>>>>>>> the code a bit shorter and also simplifies the error handling. Even
>>>>>>> more so
>>>>>>> if e.g. the GPIO is optional. This was one of the main reasons why
>>>>>>> gpio_request_one was introduced, see the commit[1] that added it.
>>>>>>
>>>>>>
>>>>>> I am not opposed to it as a convenience function. Note that since the
>>>>>> open-source and open-drain flags are already handled by the lookup
>>>>>> table, the only flags it should handle are those related to direction,
>>>>>> value, and (maybe) sysfs export.
>>>>>
>>>>>
>>>>> Problem is, too much convenience functions seems to ultimately kill
>>>>> convenience.
>>>>>
>>>>> The canonical way to request a GPIO is by providing a (device,
>>>>> function, index) triplet to gpiod_get_index(). Since most functions
>>>>> only need one GPIO, we have gpiod_get(device, function) which is
>>>>> basically an alias to gpiod_get_index(device, function, 0) (note to
>>>>> self: we should probably inline it).
>>>>>
>>>>> On top of these comes another set of convenience functions,
>>>>> gpiod_get_optional() and gpiod_get_index_optional(), which return NULL
>>>>> instead of -ENOENT if the requested GPIO mapping does not exist. This
>>>>> is useful for the common case where a driver can work without a GPIO.
>>>>>
>>>>> Of course these functions all have devm counterparts, so we currently
>>>>> have 8 (devm_)gpiod_get(_index)(_optional) functions.
>>>>>
>>>>> If we are to add functions with an init flags parameter, we will end
>>>>> with 16 functions. That starts to be a bit too much to my taste, and
>>>>> maybe that's where GPIO consumers should sacrifice some convenience to
>>>>> preserve a comprehensible GPIO API.
>>>>>
>>>>> There might be other ways to work around this though. For instance, we
>>>>> could replace the _optional functions by a GPIOF_OPTIONAL flag to be
>>>>> passed to a more generic function that would also accept direction and
>>>>> init value flags. Actually I am not seeing any user of the _optional
>>>>> variant in -next, so maybe we should just do this. Thierry, since you
>>>>> introduced the _optional functions, can we get your thoughts about
>>>>> this?
>>>>
>>>>
>>>> I personally prefer explicit naming of the functions rather than putting
>>>> a bunch of flags into some parameter. If you're overly concerned about
>>>> the amount of convenience functions, perhaps the _index variants can be
>>>> left out for gpiod_get_one(). I'd argue that if drivers want to deal
>>>> with that level of detail anyway, they may just as well add the index
>>>> explicitly when calling the function.
>>>>
>>>> While we're at it, gpiod_get_one() doesn't sound like a very good name.
>>>> All other variants only request "one" as well. Perhaps something like
>>>> gpiod_get_with_flags() would be a better name.
>>>>
>>>> Then again, maybe rather than add a new set of functions we should bite
>>>> the bullet and change gpiod_get() (and variants) to take an additional
>>>> flags parameter. There aren't all that many users yet (I count 26
>>>> outside of drivers/gpio), so maybe now would still be a good time to do
>>>> that.
>>>
>>>
>>> That sounds reasonable indeed. And preferable to getting an aneurysm
>>> after trying to spell devm_gpiod_get_index_optional_with_flags().
>>>
>>> This also makes the most sense since most GPIO users will want to set
>>> a direction and value right after obtaining one. So if there is no
>>> objection I will probably start refactoring gpiod_get() this week.
>>
>>
>> Sounds good to me.
>>
>
> In light of this, should I hold off starting on devm_gpiod_get_array()
> as discussed on here last week?

These are two independant issues, and adapting the get_array() patch
to a refactored gpiod_get() should be trivial.

But while we are at it (and sorry for going further off-topic), I also
think that gpiod_get_array() should not follow the same calling
convention as gpio_request_array() by taking an array of whatever
gpiod_get() would require. Instead, I think it should be redefined to
mean "get all the GPIOs for a given function". For instance, say that
in the DT you have

foo-gpios = <&gpio 0 GPIO_ACTIVE_HIGH &gpio 1 GPIO_ACTIVE_HIGH &gpio 2
GPIO_ACTIVE_HIGH>;

Then gpiod_get_array(dev, "foo", &num) should return descriptors to
these 3 GPIOs and assign "3" to num. The same thing can be done with
the platform lookup tables.

Actually it would be even better if this API could be designed to
interact nicely with the multiple GPIO setting patch by Rojhalat:
http://www.spinics.net/lists/linux-gpio/msg00827.html

gpiod_get_array() would thus allocate and return an array of GPIO
descriptors suitable to be used immediatly with gpiod_set_array(). And
bam, a nice full-circle API for handling multiple GPIOs. My
expectations have risen all of a sudden. ;)

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [alsa-devel] [PATCH 2/4] ASoC: s3c64xx/smartq: use dynamic registration
  2014-07-17  4:28                       ` Alexandre Courbot
@ 2014-07-17  7:44                         ` Thierry Reding
  2014-07-17  8:55                           ` Alexandre Courbot
  0 siblings, 1 reply; 24+ messages in thread
From: Thierry Reding @ 2014-07-17  7:44 UTC (permalink / raw)
  To: Alexandre Courbot
  Cc: Rob Jones, Rojhalat Ibrahim, Lars-Peter Clausen, Arnd Bergmann,
	alsa-devel@alsa-project.org, Kukjin Kim, Tomasz Figa,
	Maurus Cuelenaere, Liam Girdwood, linux-gpio@vger.kernel.org,
	Mark Brown, Linus Walleij, linux-arm-kernel@lists.infradead.org

[-- Attachment #1: Type: text/plain, Size: 10304 bytes --]

On Thu, Jul 17, 2014 at 01:28:00PM +0900, Alexandre Courbot wrote:
> On Wed, Jul 16, 2014 at 5:50 PM, Rob Jones <rob.jones@codethink.co.uk> wrote:
> >
> >
> > On 16/07/14 08:51, Thierry Reding wrote:
> >>
> >> On Wed, Jul 16, 2014 at 04:28:33PM +0900, Alexandre Courbot wrote:
> >>>
> >>> On Wed, Jul 16, 2014 at 4:12 PM, Thierry Reding
> >>> <thierry.reding@gmail.com> wrote:
> >>>>
> >>>> On Wed, Jul 16, 2014 at 12:00:45PM +0900, Alexandre Courbot wrote:
> >>>>>
> >>>>> On Tue, Jul 15, 2014 at 6:14 PM, Alexandre Courbot <gnurou@gmail.com>
> >>>>> wrote:
> >>>>>>
> >>>>>> On Tue, Jul 15, 2014 at 4:58 PM, Lars-Peter Clausen <lars@metafoo.de>
> >>>>>> wrote:
> >>>>>>>
> >>>>>>> On 07/15/2014 09:36 AM, Alexandre Courbot wrote:
> >>>>>>>>
> >>>>>>>>
> >>>>>>>> On Tue, Jul 15, 2014 at 4:19 PM, Arnd Bergmann <arnd@arndb.de>
> >>>>>>>> wrote:
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>> On Monday 14 July 2014 19:36:24 Mark Brown wrote:
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>> On Mon, Jul 14, 2014 at 08:23:55PM +0200, Arnd Bergmann wrote:
> >>>>>>>>>>>
> >>>>>>>>>>>
> >>>>>>>>>>> On Monday 14 July 2014 18:18:12 Lars-Peter Clausen wrote:
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>>>> Yes. But now that you say it the gpiod_direction_output() call
> >>>>>>>>>>>> is
> >>>>>>>>>>>> missing
> >>>>>>>>>>>> from this patch.
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>>> I'm lost now. The GPIO_ACTIVE_HIGH I added comes from
> >>>>>>>>>>> Documentation/gpio/board.txt
> >>>>>>>>>>> and as Linus Walleij explained to me the other day, the lookup is
> >>>>>>>>>>> supposed
> >>>>>>>>>>> to replace devm_gpio_request_one(), which in turn replaced both
> >>>>>>>>>>> the
> >>>>>>>>>>> gpio_request and the gpio_direction_output(). Do I need to put
> >>>>>>>>>>> the
> >>>>>>>>>>> gpiod_direction_output() back or is there another interface for
> >>>>>>>>>>> that
> >>>>>>>>>>> when
> >>>>>>>>>>> registering the board gpios?
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>> Indeed.  If you *do* need an explicit _output() then that sounds
> >>>>>>>>>> to me
> >>>>>>>>>> like we either need a gpiod_get_one() or an extension to the
> >>>>>>>>>> table,
> >>>>>>>>>> looking at the code it seems like this is indeed the case.  We can
> >>>>>>>>>> set
> >>>>>>>>>> if the GPIO is active high/low, or open source/drain but there's
> >>>>>>>>>> no flag
> >>>>>>>>>> for the initial state.
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>> (adding Alexandre and the gpio list)
> >>>>>>>>>
> >>>>>>>>> GPIO people: any guidance on how a board file should set a gpio to
> >>>>>>>>> output/default-high in a GPIO_LOOKUP() table to replace a
> >>>>>>>>> devm_gpio_request_one() call in a device driver with
> >>>>>>>>> devm_gpiod_get()?
> >>>>>>>>> Do we need to add an interface extension to do this, e.g. passing
> >>>>>>>>> GPIOF_OUT_INIT_HIGH as the flags rather than GPIO_ACTIVE_HIGH?
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>> The way I see it, GPIO mappings (whether they are done using the
> >>>>>>>> lookup tables, DT, or ACPI) should only care about details that are
> >>>>>>>> relevant to the device layout and that should be abstracted to the
> >>>>>>>> driver (e.g. whether the GPIO is active low or open drain) so
> >>>>>>>> drivers
> >>>>>>>> do not need to check X conditions every time they want to drive the
> >>>>>>>> GPIO.
> >>>>>>>>
> >>>>>>>> Direction and initial value, on the other hand, are clearly
> >>>>>>>> properties
> >>>>>>>> that ought to be set by the driver itself. Thus my expectation here
> >>>>>>>> would be that the driver sets the GPIO direction and initial value
> >>>>>>>> as
> >>>>>>>> soon as it gets it using gpiod_direction_output(). In other words,
> >>>>>>>> there is no replacement for gpio_request_one() with the gpiod
> >>>>>>>> interface. Is there any use-case that cannot be covered by calling
> >>>>>>>> gpiod_direction_output() right after gpiod_get()? AFAICT this is
> >>>>>>>> what
> >>>>>>>> gpio_request_one() was doing anyway.
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>> I agree with you that this is something that should be done in the
> >>>>>>> driver
> >>>>>>> and not in the lookup table. I think that it is still a good idea to
> >>>>>>> have a
> >>>>>>> replacement for gpio_request_one with the new GPIO descriptor API. A
> >>>>>>> large
> >>>>>>> share of the drivers want to call either gpio_direction_input() or
> >>>>>>> gpio_direction_output() right after requesting the GPIO. Combining
> >>>>>>> both the
> >>>>>>> requesting and the configuration of the GPIO into one function call
> >>>>>>> makes
> >>>>>>> the code a bit shorter and also simplifies the error handling. Even
> >>>>>>> more so
> >>>>>>> if e.g. the GPIO is optional. This was one of the main reasons why
> >>>>>>> gpio_request_one was introduced, see the commit[1] that added it.
> >>>>>>
> >>>>>>
> >>>>>> I am not opposed to it as a convenience function. Note that since the
> >>>>>> open-source and open-drain flags are already handled by the lookup
> >>>>>> table, the only flags it should handle are those related to direction,
> >>>>>> value, and (maybe) sysfs export.
> >>>>>
> >>>>>
> >>>>> Problem is, too much convenience functions seems to ultimately kill
> >>>>> convenience.
> >>>>>
> >>>>> The canonical way to request a GPIO is by providing a (device,
> >>>>> function, index) triplet to gpiod_get_index(). Since most functions
> >>>>> only need one GPIO, we have gpiod_get(device, function) which is
> >>>>> basically an alias to gpiod_get_index(device, function, 0) (note to
> >>>>> self: we should probably inline it).
> >>>>>
> >>>>> On top of these comes another set of convenience functions,
> >>>>> gpiod_get_optional() and gpiod_get_index_optional(), which return NULL
> >>>>> instead of -ENOENT if the requested GPIO mapping does not exist. This
> >>>>> is useful for the common case where a driver can work without a GPIO.
> >>>>>
> >>>>> Of course these functions all have devm counterparts, so we currently
> >>>>> have 8 (devm_)gpiod_get(_index)(_optional) functions.
> >>>>>
> >>>>> If we are to add functions with an init flags parameter, we will end
> >>>>> with 16 functions. That starts to be a bit too much to my taste, and
> >>>>> maybe that's where GPIO consumers should sacrifice some convenience to
> >>>>> preserve a comprehensible GPIO API.
> >>>>>
> >>>>> There might be other ways to work around this though. For instance, we
> >>>>> could replace the _optional functions by a GPIOF_OPTIONAL flag to be
> >>>>> passed to a more generic function that would also accept direction and
> >>>>> init value flags. Actually I am not seeing any user of the _optional
> >>>>> variant in -next, so maybe we should just do this. Thierry, since you
> >>>>> introduced the _optional functions, can we get your thoughts about
> >>>>> this?
> >>>>
> >>>>
> >>>> I personally prefer explicit naming of the functions rather than putting
> >>>> a bunch of flags into some parameter. If you're overly concerned about
> >>>> the amount of convenience functions, perhaps the _index variants can be
> >>>> left out for gpiod_get_one(). I'd argue that if drivers want to deal
> >>>> with that level of detail anyway, they may just as well add the index
> >>>> explicitly when calling the function.
> >>>>
> >>>> While we're at it, gpiod_get_one() doesn't sound like a very good name.
> >>>> All other variants only request "one" as well. Perhaps something like
> >>>> gpiod_get_with_flags() would be a better name.
> >>>>
> >>>> Then again, maybe rather than add a new set of functions we should bite
> >>>> the bullet and change gpiod_get() (and variants) to take an additional
> >>>> flags parameter. There aren't all that many users yet (I count 26
> >>>> outside of drivers/gpio), so maybe now would still be a good time to do
> >>>> that.
> >>>
> >>>
> >>> That sounds reasonable indeed. And preferable to getting an aneurysm
> >>> after trying to spell devm_gpiod_get_index_optional_with_flags().
> >>>
> >>> This also makes the most sense since most GPIO users will want to set
> >>> a direction and value right after obtaining one. So if there is no
> >>> objection I will probably start refactoring gpiod_get() this week.
> >>
> >>
> >> Sounds good to me.
> >>
> >
> > In light of this, should I hold off starting on devm_gpiod_get_array()
> > as discussed on here last week?
> 
> These are two independant issues, and adapting the get_array() patch
> to a refactored gpiod_get() should be trivial.
> 
> But while we are at it (and sorry for going further off-topic), I also
> think that gpiod_get_array() should not follow the same calling
> convention as gpio_request_array() by taking an array of whatever
> gpiod_get() would require. Instead, I think it should be redefined to
> mean "get all the GPIOs for a given function". For instance, say that
> in the DT you have
> 
> foo-gpios = <&gpio 0 GPIO_ACTIVE_HIGH &gpio 1 GPIO_ACTIVE_HIGH &gpio 2
> GPIO_ACTIVE_HIGH>;
> 
> Then gpiod_get_array(dev, "foo", &num) should return descriptors to
> these 3 GPIOs and assign "3" to num. The same thing can be done with
> the platform lookup tables.
> 
> Actually it would be even better if this API could be designed to
> interact nicely with the multiple GPIO setting patch by Rojhalat:
> http://www.spinics.net/lists/linux-gpio/msg00827.html
> 
> gpiod_get_array() would thus allocate and return an array of GPIO
> descriptors suitable to be used immediatly with gpiod_set_array(). And
> bam, a nice full-circle API for handling multiple GPIOs. My
> expectations have risen all of a sudden. ;)

Should the new gpiod_get_array() function also have a way to specify the
flags similar to gpiod_get()? I agree that making it return all GPIOs of
a given function is a good idea. And given that GPIOs associated with
the same function probably behave very similarly it should be safe to
add flags handling to that as well. That is, I don't think we'd need to
worry about different GPIOs of the same function requiring different
directions or initial values (note that polarity is still handled by the
GPIO specifier).

Thierry

[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [alsa-devel] [PATCH 2/4] ASoC: s3c64xx/smartq: use dynamic registration
  2014-07-17  7:44                         ` Thierry Reding
@ 2014-07-17  8:55                           ` Alexandre Courbot
  2014-07-17 10:17                             ` Mark Brown
  0 siblings, 1 reply; 24+ messages in thread
From: Alexandre Courbot @ 2014-07-17  8:55 UTC (permalink / raw)
  To: Thierry Reding
  Cc: Rob Jones, Rojhalat Ibrahim, Lars-Peter Clausen, Arnd Bergmann,
	alsa-devel@alsa-project.org, Kukjin Kim, Tomasz Figa,
	Maurus Cuelenaere, Liam Girdwood, linux-gpio@vger.kernel.org,
	Mark Brown, Linus Walleij, linux-arm-kernel@lists.infradead.org

On Thu, Jul 17, 2014 at 4:44 PM, Thierry Reding
<thierry.reding@gmail.com> wrote:
> On Thu, Jul 17, 2014 at 01:28:00PM +0900, Alexandre Courbot wrote:
>> On Wed, Jul 16, 2014 at 5:50 PM, Rob Jones <rob.jones@codethink.co.uk> wrote:
>> >
>> >
>> > On 16/07/14 08:51, Thierry Reding wrote:
>> >>
>> >> On Wed, Jul 16, 2014 at 04:28:33PM +0900, Alexandre Courbot wrote:
>> >>>
>> >>> On Wed, Jul 16, 2014 at 4:12 PM, Thierry Reding
>> >>> <thierry.reding@gmail.com> wrote:
>> >>>>
>> >>>> On Wed, Jul 16, 2014 at 12:00:45PM +0900, Alexandre Courbot wrote:
>> >>>>>
>> >>>>> On Tue, Jul 15, 2014 at 6:14 PM, Alexandre Courbot <gnurou@gmail.com>
>> >>>>> wrote:
>> >>>>>>
>> >>>>>> On Tue, Jul 15, 2014 at 4:58 PM, Lars-Peter Clausen <lars@metafoo.de>
>> >>>>>> wrote:
>> >>>>>>>
>> >>>>>>> On 07/15/2014 09:36 AM, Alexandre Courbot wrote:
>> >>>>>>>>
>> >>>>>>>>
>> >>>>>>>> On Tue, Jul 15, 2014 at 4:19 PM, Arnd Bergmann <arnd@arndb.de>
>> >>>>>>>> wrote:
>> >>>>>>>>>
>> >>>>>>>>>
>> >>>>>>>>> On Monday 14 July 2014 19:36:24 Mark Brown wrote:
>> >>>>>>>>>>
>> >>>>>>>>>>
>> >>>>>>>>>> On Mon, Jul 14, 2014 at 08:23:55PM +0200, Arnd Bergmann wrote:
>> >>>>>>>>>>>
>> >>>>>>>>>>>
>> >>>>>>>>>>> On Monday 14 July 2014 18:18:12 Lars-Peter Clausen wrote:
>> >>>>>>>>>>
>> >>>>>>>>>>
>> >>>>>>>>>>
>> >>>>>>>>>>>> Yes. But now that you say it the gpiod_direction_output() call
>> >>>>>>>>>>>> is
>> >>>>>>>>>>>> missing
>> >>>>>>>>>>>> from this patch.
>> >>>>>>>>>>
>> >>>>>>>>>>
>> >>>>>>>>>>
>> >>>>>>>>>>> I'm lost now. The GPIO_ACTIVE_HIGH I added comes from
>> >>>>>>>>>>> Documentation/gpio/board.txt
>> >>>>>>>>>>> and as Linus Walleij explained to me the other day, the lookup is
>> >>>>>>>>>>> supposed
>> >>>>>>>>>>> to replace devm_gpio_request_one(), which in turn replaced both
>> >>>>>>>>>>> the
>> >>>>>>>>>>> gpio_request and the gpio_direction_output(). Do I need to put
>> >>>>>>>>>>> the
>> >>>>>>>>>>> gpiod_direction_output() back or is there another interface for
>> >>>>>>>>>>> that
>> >>>>>>>>>>> when
>> >>>>>>>>>>> registering the board gpios?
>> >>>>>>>>>>
>> >>>>>>>>>>
>> >>>>>>>>>>
>> >>>>>>>>>> Indeed.  If you *do* need an explicit _output() then that sounds
>> >>>>>>>>>> to me
>> >>>>>>>>>> like we either need a gpiod_get_one() or an extension to the
>> >>>>>>>>>> table,
>> >>>>>>>>>> looking at the code it seems like this is indeed the case.  We can
>> >>>>>>>>>> set
>> >>>>>>>>>> if the GPIO is active high/low, or open source/drain but there's
>> >>>>>>>>>> no flag
>> >>>>>>>>>> for the initial state.
>> >>>>>>>>>
>> >>>>>>>>>
>> >>>>>>>>>
>> >>>>>>>>> (adding Alexandre and the gpio list)
>> >>>>>>>>>
>> >>>>>>>>> GPIO people: any guidance on how a board file should set a gpio to
>> >>>>>>>>> output/default-high in a GPIO_LOOKUP() table to replace a
>> >>>>>>>>> devm_gpio_request_one() call in a device driver with
>> >>>>>>>>> devm_gpiod_get()?
>> >>>>>>>>> Do we need to add an interface extension to do this, e.g. passing
>> >>>>>>>>> GPIOF_OUT_INIT_HIGH as the flags rather than GPIO_ACTIVE_HIGH?
>> >>>>>>>>
>> >>>>>>>>
>> >>>>>>>>
>> >>>>>>>> The way I see it, GPIO mappings (whether they are done using the
>> >>>>>>>> lookup tables, DT, or ACPI) should only care about details that are
>> >>>>>>>> relevant to the device layout and that should be abstracted to the
>> >>>>>>>> driver (e.g. whether the GPIO is active low or open drain) so
>> >>>>>>>> drivers
>> >>>>>>>> do not need to check X conditions every time they want to drive the
>> >>>>>>>> GPIO.
>> >>>>>>>>
>> >>>>>>>> Direction and initial value, on the other hand, are clearly
>> >>>>>>>> properties
>> >>>>>>>> that ought to be set by the driver itself. Thus my expectation here
>> >>>>>>>> would be that the driver sets the GPIO direction and initial value
>> >>>>>>>> as
>> >>>>>>>> soon as it gets it using gpiod_direction_output(). In other words,
>> >>>>>>>> there is no replacement for gpio_request_one() with the gpiod
>> >>>>>>>> interface. Is there any use-case that cannot be covered by calling
>> >>>>>>>> gpiod_direction_output() right after gpiod_get()? AFAICT this is
>> >>>>>>>> what
>> >>>>>>>> gpio_request_one() was doing anyway.
>> >>>>>>>
>> >>>>>>>
>> >>>>>>>
>> >>>>>>> I agree with you that this is something that should be done in the
>> >>>>>>> driver
>> >>>>>>> and not in the lookup table. I think that it is still a good idea to
>> >>>>>>> have a
>> >>>>>>> replacement for gpio_request_one with the new GPIO descriptor API. A
>> >>>>>>> large
>> >>>>>>> share of the drivers want to call either gpio_direction_input() or
>> >>>>>>> gpio_direction_output() right after requesting the GPIO. Combining
>> >>>>>>> both the
>> >>>>>>> requesting and the configuration of the GPIO into one function call
>> >>>>>>> makes
>> >>>>>>> the code a bit shorter and also simplifies the error handling. Even
>> >>>>>>> more so
>> >>>>>>> if e.g. the GPIO is optional. This was one of the main reasons why
>> >>>>>>> gpio_request_one was introduced, see the commit[1] that added it.
>> >>>>>>
>> >>>>>>
>> >>>>>> I am not opposed to it as a convenience function. Note that since the
>> >>>>>> open-source and open-drain flags are already handled by the lookup
>> >>>>>> table, the only flags it should handle are those related to direction,
>> >>>>>> value, and (maybe) sysfs export.
>> >>>>>
>> >>>>>
>> >>>>> Problem is, too much convenience functions seems to ultimately kill
>> >>>>> convenience.
>> >>>>>
>> >>>>> The canonical way to request a GPIO is by providing a (device,
>> >>>>> function, index) triplet to gpiod_get_index(). Since most functions
>> >>>>> only need one GPIO, we have gpiod_get(device, function) which is
>> >>>>> basically an alias to gpiod_get_index(device, function, 0) (note to
>> >>>>> self: we should probably inline it).
>> >>>>>
>> >>>>> On top of these comes another set of convenience functions,
>> >>>>> gpiod_get_optional() and gpiod_get_index_optional(), which return NULL
>> >>>>> instead of -ENOENT if the requested GPIO mapping does not exist. This
>> >>>>> is useful for the common case where a driver can work without a GPIO.
>> >>>>>
>> >>>>> Of course these functions all have devm counterparts, so we currently
>> >>>>> have 8 (devm_)gpiod_get(_index)(_optional) functions.
>> >>>>>
>> >>>>> If we are to add functions with an init flags parameter, we will end
>> >>>>> with 16 functions. That starts to be a bit too much to my taste, and
>> >>>>> maybe that's where GPIO consumers should sacrifice some convenience to
>> >>>>> preserve a comprehensible GPIO API.
>> >>>>>
>> >>>>> There might be other ways to work around this though. For instance, we
>> >>>>> could replace the _optional functions by a GPIOF_OPTIONAL flag to be
>> >>>>> passed to a more generic function that would also accept direction and
>> >>>>> init value flags. Actually I am not seeing any user of the _optional
>> >>>>> variant in -next, so maybe we should just do this. Thierry, since you
>> >>>>> introduced the _optional functions, can we get your thoughts about
>> >>>>> this?
>> >>>>
>> >>>>
>> >>>> I personally prefer explicit naming of the functions rather than putting
>> >>>> a bunch of flags into some parameter. If you're overly concerned about
>> >>>> the amount of convenience functions, perhaps the _index variants can be
>> >>>> left out for gpiod_get_one(). I'd argue that if drivers want to deal
>> >>>> with that level of detail anyway, they may just as well add the index
>> >>>> explicitly when calling the function.
>> >>>>
>> >>>> While we're at it, gpiod_get_one() doesn't sound like a very good name.
>> >>>> All other variants only request "one" as well. Perhaps something like
>> >>>> gpiod_get_with_flags() would be a better name.
>> >>>>
>> >>>> Then again, maybe rather than add a new set of functions we should bite
>> >>>> the bullet and change gpiod_get() (and variants) to take an additional
>> >>>> flags parameter. There aren't all that many users yet (I count 26
>> >>>> outside of drivers/gpio), so maybe now would still be a good time to do
>> >>>> that.
>> >>>
>> >>>
>> >>> That sounds reasonable indeed. And preferable to getting an aneurysm
>> >>> after trying to spell devm_gpiod_get_index_optional_with_flags().
>> >>>
>> >>> This also makes the most sense since most GPIO users will want to set
>> >>> a direction and value right after obtaining one. So if there is no
>> >>> objection I will probably start refactoring gpiod_get() this week.
>> >>
>> >>
>> >> Sounds good to me.
>> >>
>> >
>> > In light of this, should I hold off starting on devm_gpiod_get_array()
>> > as discussed on here last week?
>>
>> These are two independant issues, and adapting the get_array() patch
>> to a refactored gpiod_get() should be trivial.
>>
>> But while we are at it (and sorry for going further off-topic), I also
>> think that gpiod_get_array() should not follow the same calling
>> convention as gpio_request_array() by taking an array of whatever
>> gpiod_get() would require. Instead, I think it should be redefined to
>> mean "get all the GPIOs for a given function". For instance, say that
>> in the DT you have
>>
>> foo-gpios = <&gpio 0 GPIO_ACTIVE_HIGH &gpio 1 GPIO_ACTIVE_HIGH &gpio 2
>> GPIO_ACTIVE_HIGH>;
>>
>> Then gpiod_get_array(dev, "foo", &num) should return descriptors to
>> these 3 GPIOs and assign "3" to num. The same thing can be done with
>> the platform lookup tables.
>>
>> Actually it would be even better if this API could be designed to
>> interact nicely with the multiple GPIO setting patch by Rojhalat:
>> http://www.spinics.net/lists/linux-gpio/msg00827.html
>>
>> gpiod_get_array() would thus allocate and return an array of GPIO
>> descriptors suitable to be used immediatly with gpiod_set_array(). And
>> bam, a nice full-circle API for handling multiple GPIOs. My
>> expectations have risen all of a sudden. ;)
>
> Should the new gpiod_get_array() function also have a way to specify the
> flags similar to gpiod_get()?

Probably an optional array of flags could not hurt, to follow the
example of gpiod_get().

> I agree that making it return all GPIOs of
> a given function is a good idea. And given that GPIOs associated with
> the same function probably behave very similarly it should be safe to
> add flags handling to that as well. That is, I don't think we'd need to
> worry about different GPIOs of the same function requiring different
> directions or initial values (note that polarity is still handled by the
> GPIO specifier).

Right. It may very well be that a single flag specifier (as opposed to
an array) will be enough for this case. If you need to request some
GPIOs as input and some other as output then they are clearly
different functions and requesting them together would be an abuse of
the API.

Initial values of output GPIOs might be a reason why we want an array
though, and I leave it to Rob to decide what is best here since he has
a better idea of how this is going to be used.

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [alsa-devel] [PATCH 2/4] ASoC: s3c64xx/smartq: use dynamic registration
  2014-07-17  8:55                           ` Alexandre Courbot
@ 2014-07-17 10:17                             ` Mark Brown
  2014-07-17 10:41                               ` Thierry Reding
  0 siblings, 1 reply; 24+ messages in thread
From: Mark Brown @ 2014-07-17 10:17 UTC (permalink / raw)
  To: Alexandre Courbot
  Cc: Thierry Reding, Rob Jones, Rojhalat Ibrahim, Lars-Peter Clausen,
	Arnd Bergmann, alsa-devel@alsa-project.org, Kukjin Kim,
	Tomasz Figa, Maurus Cuelenaere, Liam Girdwood,
	linux-gpio@vger.kernel.org, Linus Walleij,
	linux-arm-kernel@lists.infradead.org

[-- Attachment #1: Type: text/plain, Size: 474 bytes --]

On Thu, Jul 17, 2014 at 05:55:36PM +0900, Alexandre Courbot wrote:

> Right. It may very well be that a single flag specifier (as opposed to
> an array) will be enough for this case. If you need to request some
> GPIOs as input and some other as output then they are clearly
> different functions and requesting them together would be an abuse of
> the API.

Not so sure about that - what about requesting GPIOs for a bidirectional
bus?  Thinking about SPI bitbanging here.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [alsa-devel] [PATCH 2/4] ASoC: s3c64xx/smartq: use dynamic registration
  2014-07-17 10:17                             ` Mark Brown
@ 2014-07-17 10:41                               ` Thierry Reding
  2014-07-17 10:58                                 ` Lars-Peter Clausen
  2014-07-17 11:05                                 ` Mark Brown
  0 siblings, 2 replies; 24+ messages in thread
From: Thierry Reding @ 2014-07-17 10:41 UTC (permalink / raw)
  To: Mark Brown
  Cc: Alexandre Courbot, Rob Jones, Rojhalat Ibrahim,
	Lars-Peter Clausen, Arnd Bergmann, alsa-devel@alsa-project.org,
	Kukjin Kim, Tomasz Figa, Maurus Cuelenaere, Liam Girdwood,
	linux-gpio@vger.kernel.org, Linus Walleij,
	linux-arm-kernel@lists.infradead.org

[-- Attachment #1: Type: text/plain, Size: 910 bytes --]

On Thu, Jul 17, 2014 at 11:17:23AM +0100, Mark Brown wrote:
> On Thu, Jul 17, 2014 at 05:55:36PM +0900, Alexandre Courbot wrote:
> 
> > Right. It may very well be that a single flag specifier (as opposed to
> > an array) will be enough for this case. If you need to request some
> > GPIOs as input and some other as output then they are clearly
> > different functions and requesting them together would be an abuse of
> > the API.
> 
> Not so sure about that - what about requesting GPIOs for a bidirectional
> bus?  Thinking about SPI bitbanging here.

Wouldn't you want to use a different means that the gpiod_array_*() API
to handle those cases? gpiod_array_*() is probably most useful to handle
bulk operations on a set of GPIOs that do essentially the same thing. If
you get and then need to index into that array to handle them all
differently then you don't gain very much.

Thierry

[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [alsa-devel] [PATCH 2/4] ASoC: s3c64xx/smartq: use dynamic registration
  2014-07-17 10:41                               ` Thierry Reding
@ 2014-07-17 10:58                                 ` Lars-Peter Clausen
  2014-07-17 11:05                                 ` Mark Brown
  1 sibling, 0 replies; 24+ messages in thread
From: Lars-Peter Clausen @ 2014-07-17 10:58 UTC (permalink / raw)
  To: Thierry Reding, Mark Brown
  Cc: Alexandre Courbot, alsa-devel@alsa-project.org, Rojhalat Ibrahim,
	Arnd Bergmann, Tomasz Figa, Maurus Cuelenaere, Liam Girdwood,
	linux-gpio@vger.kernel.org, Kukjin Kim, Rob Jones, Linus Walleij,
	linux-arm-kernel@lists.infradead.org

On 07/17/2014 12:41 PM, Thierry Reding wrote:
> On Thu, Jul 17, 2014 at 11:17:23AM +0100, Mark Brown wrote:
>> On Thu, Jul 17, 2014 at 05:55:36PM +0900, Alexandre Courbot wrote:
>>
>>> Right. It may very well be that a single flag specifier (as opposed to
>>> an array) will be enough for this case. If you need to request some
>>> GPIOs as input and some other as output then they are clearly
>>> different functions and requesting them together would be an abuse of
>>> the API.
>>
>> Not so sure about that - what about requesting GPIOs for a bidirectional
>> bus?  Thinking about SPI bitbanging here.
>
> Wouldn't you want to use a different means that the gpiod_array_*() API
> to handle those cases? gpiod_array_*() is probably most useful to handle
> bulk operations on a set of GPIOs that do essentially the same thing. If
> you get and then need to index into that array to handle them all
> differently then you don't gain very much.

I think the goal of a gpiod_array_* API should be to make requesting 
multiple GPIOs that are used by a driver as convenient as possible and at 
the same time reduce the amount of boiler plate code necessary. E.g compare

gpios[0] = gpio_get(...);
if (IS_ERR(gpios[0])) {
	ret = PTR_ERR(gpios[0]);
	goto cleanup;
}

gpios[1] = gpio_get(...);
if (IS_ERR(gpios[1])) {
	ret = PTR_ERR(gpios[1]);
	goto cleanup;
}

gpios[2] = gpio_get(...);
if (IS_ERR(gpios[2])) {
	ret = PTR_ERR(gpioss[2]);
	goto cleanup;
}

with

ret = gpio_array_get(..., gpios);
if (ret)
	goto err_cleanup;

- Lars

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [alsa-devel] [PATCH 2/4] ASoC: s3c64xx/smartq: use dynamic registration
  2014-07-17 10:41                               ` Thierry Reding
  2014-07-17 10:58                                 ` Lars-Peter Clausen
@ 2014-07-17 11:05                                 ` Mark Brown
  2014-07-21  3:36                                   ` Alexandre Courbot
  1 sibling, 1 reply; 24+ messages in thread
From: Mark Brown @ 2014-07-17 11:05 UTC (permalink / raw)
  To: Thierry Reding
  Cc: Alexandre Courbot, Rob Jones, Rojhalat Ibrahim,
	Lars-Peter Clausen, Arnd Bergmann, alsa-devel@alsa-project.org,
	Kukjin Kim, Tomasz Figa, Maurus Cuelenaere, Liam Girdwood,
	linux-gpio@vger.kernel.org, Linus Walleij,
	linux-arm-kernel@lists.infradead.org

[-- Attachment #1: Type: text/plain, Size: 760 bytes --]

On Thu, Jul 17, 2014 at 12:41:23PM +0200, Thierry Reding wrote:
> On Thu, Jul 17, 2014 at 11:17:23AM +0100, Mark Brown wrote:

> > Not so sure about that - what about requesting GPIOs for a bidirectional
> > bus?  Thinking about SPI bitbanging here.

> Wouldn't you want to use a different means that the gpiod_array_*() API
> to handle those cases? gpiod_array_*() is probably most useful to handle
> bulk operations on a set of GPIOs that do essentially the same thing. If
> you get and then need to index into that array to handle them all
> differently then you don't gain very much.

For set and get, sure - but it's still useful to be able to do bulk
requests for GPIOs especially since that's the only bit of the interface
that requires error handling.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [alsa-devel] [PATCH 2/4] ASoC: s3c64xx/smartq: use dynamic registration
  2014-07-17 11:05                                 ` Mark Brown
@ 2014-07-21  3:36                                   ` Alexandre Courbot
  2014-07-21 10:04                                     ` Mark Brown
  0 siblings, 1 reply; 24+ messages in thread
From: Alexandre Courbot @ 2014-07-21  3:36 UTC (permalink / raw)
  To: Mark Brown
  Cc: Thierry Reding, Rob Jones, Rojhalat Ibrahim, Lars-Peter Clausen,
	Arnd Bergmann, alsa-devel@alsa-project.org, Kukjin Kim,
	Tomasz Figa, Maurus Cuelenaere, Liam Girdwood,
	linux-gpio@vger.kernel.org, Linus Walleij,
	linux-arm-kernel@lists.infradead.org

On Thu, Jul 17, 2014 at 8:05 PM, Mark Brown <broonie@kernel.org> wrote:
> On Thu, Jul 17, 2014 at 12:41:23PM +0200, Thierry Reding wrote:
>> On Thu, Jul 17, 2014 at 11:17:23AM +0100, Mark Brown wrote:
>
>> > Not so sure about that - what about requesting GPIOs for a bidirectional
>> > bus?  Thinking about SPI bitbanging here.
>
>> Wouldn't you want to use a different means that the gpiod_array_*() API
>> to handle those cases? gpiod_array_*() is probably most useful to handle
>> bulk operations on a set of GPIOs that do essentially the same thing. If
>> you get and then need to index into that array to handle them all
>> differently then you don't gain very much.
>
> For set and get, sure - but it's still useful to be able to do bulk
> requests for GPIOs especially since that's the only bit of the interface
> that requires error handling.

I foresee many problems if people start using gpiod_array_get() as a
way to spare a few lines of error-checking code. First all the GPIOs
would end into an array instead of members with meaningful names -
unless they are moved later on, but doing so would add extra code and
somewhat kill the purpose. It also becomes more difficult to maintain
as you are dealing with array indexes to update all over the code.
Finally, it will make it more difficult to use gpiod_array_*() the way
it is intended to be used, as you would have to discriminate between
GPIOs of the same function and the rest by yourself.

Also, if such a convenience function is legitimate for GPIO, shouldn't
it also apply to other sub-systems? E.g. regulator_array_get()?

Maybe I am missing your point, but I still think some error-handling
code really doesn't hurt here, and the few drivers that would actually
benefit from a more automated GPIO request error handling can easily
implement it themselves. Let's keep gpiod_array_*() single-purposed
and to the point.

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 2/4] ASoC: s3c64xx/smartq: use dynamic registration
  2014-07-21  3:36                                   ` Alexandre Courbot
@ 2014-07-21 10:04                                     ` Mark Brown
  2014-07-21 14:19                                       ` [alsa-devel] " Alexandre Courbot
  0 siblings, 1 reply; 24+ messages in thread
From: Mark Brown @ 2014-07-21 10:04 UTC (permalink / raw)
  To: Alexandre Courbot
  Cc: alsa-devel@alsa-project.org, Lars-Peter Clausen, Rojhalat Ibrahim,
	Arnd Bergmann, Tomasz Figa, Maurus Cuelenaere, Liam Girdwood,
	linux-gpio@vger.kernel.org, Thierry Reding, Kukjin Kim, Rob Jones,
	Linus Walleij, linux-arm-kernel@lists.infradead.org


[-- Attachment #1.1: Type: text/plain, Size: 1777 bytes --]

On Mon, Jul 21, 2014 at 12:36:43PM +0900, Alexandre Courbot wrote:
> On Thu, Jul 17, 2014 at 8:05 PM, Mark Brown <broonie@kernel.org> wrote:

> > For set and get, sure - but it's still useful to be able to do bulk
> > requests for GPIOs especially since that's the only bit of the interface
> > that requires error handling.

> I foresee many problems if people start using gpiod_array_get() as a
> way to spare a few lines of error-checking code. First all the GPIOs
> would end into an array instead of members with meaningful names -
> unless they are moved later on, but doing so would add extra code and
> somewhat kill the purpose. It also becomes more difficult to maintain
> as you are dealing with array indexes to update all over the code.

You just need a few defines for the names, it's not a big deal.

> Finally, it will make it more difficult to use gpiod_array_*() the way
> it is intended to be used, as you would have to discriminate between
> GPIOs of the same function and the rest by yourself.

Yes, you probably shouldn't mix and match here but that's fine.

> Also, if such a convenience function is legitimate for GPIO, shouldn't
> it also apply to other sub-systems? E.g. regulator_array_get()?

It's certainly a totally reasonable and expected way of using
regulator_bulk_get().

> Maybe I am missing your point, but I still think some error-handling
> code really doesn't hurt here, and the few drivers that would actually
> benefit from a more automated GPIO request error handling can easily
> implement it themselves. Let's keep gpiod_array_*() single-purposed
> and to the point.

I'm not sure I see the massive complication TBH - it's not so much about
complexity as it is about reducing the amount of boilerplate that people
need to get right.

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [alsa-devel] [PATCH 2/4] ASoC: s3c64xx/smartq: use dynamic registration
  2014-07-21 10:04                                     ` Mark Brown
@ 2014-07-21 14:19                                       ` Alexandre Courbot
  0 siblings, 0 replies; 24+ messages in thread
From: Alexandre Courbot @ 2014-07-21 14:19 UTC (permalink / raw)
  To: Mark Brown
  Cc: Thierry Reding, Rob Jones, Rojhalat Ibrahim, Lars-Peter Clausen,
	Arnd Bergmann, alsa-devel@alsa-project.org, Kukjin Kim,
	Tomasz Figa, Maurus Cuelenaere, Liam Girdwood,
	linux-gpio@vger.kernel.org, Linus Walleij,
	linux-arm-kernel@lists.infradead.org

On Mon, Jul 21, 2014 at 7:04 PM, Mark Brown <broonie@kernel.org> wrote:
> On Mon, Jul 21, 2014 at 12:36:43PM +0900, Alexandre Courbot wrote:
>> On Thu, Jul 17, 2014 at 8:05 PM, Mark Brown <broonie@kernel.org> wrote:
>
>> > For set and get, sure - but it's still useful to be able to do bulk
>> > requests for GPIOs especially since that's the only bit of the interface
>> > that requires error handling.
>
>> I foresee many problems if people start using gpiod_array_get() as a
>> way to spare a few lines of error-checking code. First all the GPIOs
>> would end into an array instead of members with meaningful names -
>> unless they are moved later on, but doing so would add extra code and
>> somewhat kill the purpose. It also becomes more difficult to maintain
>> as you are dealing with array indexes to update all over the code.
>
> You just need a few defines for the names, it's not a big deal.
>
>> Finally, it will make it more difficult to use gpiod_array_*() the way
>> it is intended to be used, as you would have to discriminate between
>> GPIOs of the same function and the rest by yourself.
>
> Yes, you probably shouldn't mix and match here but that's fine.
>
>> Also, if such a convenience function is legitimate for GPIO, shouldn't
>> it also apply to other sub-systems? E.g. regulator_array_get()?
>
> It's certainly a totally reasonable and expected way of using
> regulator_bulk_get().
>
>> Maybe I am missing your point, but I still think some error-handling
>> code really doesn't hurt here, and the few drivers that would actually
>> benefit from a more automated GPIO request error handling can easily
>> implement it themselves. Let's keep gpiod_array_*() single-purposed
>> and to the point.
>
> I'm not sure I see the massive complication TBH - it's not so much about
> complexity as it is about reducing the amount of boilerplate that people
> need to get right.

I guess our disagreement came from the fact that we want the same
function to perform two different things. GPIOs are different from
regulators in that the former are really requested using a (dev,
function, index) vs. a (dev, function) tuple for regulators. I want a
convenience function to easily request all the GPIOs that match (dev,
function) so that functionally identical GPIOs can be manipulated as
an "atomic" set using the rest of the gpiod_array API (which would
make no sense for regulators which have no "index". You want an
equivalent to regulator_bulk_get() so a driver can conveniently
request all its GPIOs no matter the function they fullfil.

These should really be two different functions for two different
use-cases - gpiod_array_get() that returns an array suitable for being
manipulated using the rest of the gpiod_array API ; gpiod_bulk_get()
that takes the equivalent of regulator_bulk_data for GPIOs and fills
it the same way.

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [alsa-devel] [PATCH 2/4] ASoC: s3c64xx/smartq: use dynamic registration
  2014-07-16 11:09                       ` Thierry Reding
@ 2014-07-23 15:20                         ` Linus Walleij
  0 siblings, 0 replies; 24+ messages in thread
From: Linus Walleij @ 2014-07-23 15:20 UTC (permalink / raw)
  To: Thierry Reding
  Cc: Rob Jones, Alexandre Courbot, Lars-Peter Clausen, Arnd Bergmann,
	alsa-devel@alsa-project.org, Kukjin Kim, Tomasz Figa,
	Maurus Cuelenaere, Liam Girdwood, linux-gpio@vger.kernel.org,
	Mark Brown, linux-arm-kernel@lists.infradead.org

On Wed, Jul 16, 2014 at 1:09 PM, Thierry Reding
<thierry.reding@gmail.com> wrote:
> On Wed, Jul 16, 2014 at 09:50:02AM +0100, Rob Jones wrote:

>> In light of this, should I hold off starting on devm_gpiod_get_array()
>> as discussed on here last week?
>
> I'll let Alex or Linus answer this, since I wasn't involved in the
> devm_gpiod_get_array() discussions.

I'm gonna shut up in this thread as Alex is doing such an excellent
job at hashing out the details of gpiod*, and he understands it way
better than me.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [alsa-devel] [PATCH 2/4] ASoC: s3c64xx/smartq: use dynamic registration
  2014-07-16  7:28                 ` Alexandre Courbot
  2014-07-16  7:51                   ` Thierry Reding
  2014-07-16  9:48                   ` Mark Brown
@ 2014-07-24 15:10                   ` Alexandre Courbot
  2 siblings, 0 replies; 24+ messages in thread
From: Alexandre Courbot @ 2014-07-24 15:10 UTC (permalink / raw)
  To: Thierry Reding
  Cc: Lars-Peter Clausen, Arnd Bergmann, alsa-devel@alsa-project.org,
	Kukjin Kim, Tomasz Figa, Maurus Cuelenaere, Liam Girdwood,
	linux-gpio@vger.kernel.org, Mark Brown, Linus Walleij,
	linux-arm-kernel@lists.infradead.org

On Wed, Jul 16, 2014 at 4:28 PM, Alexandre Courbot <gnurou@gmail.com> wrote:
> On Wed, Jul 16, 2014 at 4:12 PM, Thierry Reding
> <thierry.reding@gmail.com> wrote:
>> On Wed, Jul 16, 2014 at 12:00:45PM +0900, Alexandre Courbot wrote:
>>> On Tue, Jul 15, 2014 at 6:14 PM, Alexandre Courbot <gnurou@gmail.com> wrote:
>>> > On Tue, Jul 15, 2014 at 4:58 PM, Lars-Peter Clausen <lars@metafoo.de> wrote:
>>> >> On 07/15/2014 09:36 AM, Alexandre Courbot wrote:
>>> >>>
>>> >>> On Tue, Jul 15, 2014 at 4:19 PM, Arnd Bergmann <arnd@arndb.de> wrote:
>>> >>>>
>>> >>>> On Monday 14 July 2014 19:36:24 Mark Brown wrote:
>>> >>>>>
>>> >>>>> On Mon, Jul 14, 2014 at 08:23:55PM +0200, Arnd Bergmann wrote:
>>> >>>>>>
>>> >>>>>> On Monday 14 July 2014 18:18:12 Lars-Peter Clausen wrote:
>>> >>>>>
>>> >>>>>
>>> >>>>>>> Yes. But now that you say it the gpiod_direction_output() call is
>>> >>>>>>> missing
>>> >>>>>>> from this patch.
>>> >>>>>
>>> >>>>>
>>> >>>>>> I'm lost now. The GPIO_ACTIVE_HIGH I added comes from
>>> >>>>>> Documentation/gpio/board.txt
>>> >>>>>> and as Linus Walleij explained to me the other day, the lookup is
>>> >>>>>> supposed
>>> >>>>>> to replace devm_gpio_request_one(), which in turn replaced both the
>>> >>>>>> gpio_request and the gpio_direction_output(). Do I need to put the
>>> >>>>>> gpiod_direction_output() back or is there another interface for that
>>> >>>>>> when
>>> >>>>>> registering the board gpios?
>>> >>>>>
>>> >>>>>
>>> >>>>> Indeed.  If you *do* need an explicit _output() then that sounds to me
>>> >>>>> like we either need a gpiod_get_one() or an extension to the table,
>>> >>>>> looking at the code it seems like this is indeed the case.  We can set
>>> >>>>> if the GPIO is active high/low, or open source/drain but there's no flag
>>> >>>>> for the initial state.
>>> >>>>
>>> >>>>
>>> >>>> (adding Alexandre and the gpio list)
>>> >>>>
>>> >>>> GPIO people: any guidance on how a board file should set a gpio to
>>> >>>> output/default-high in a GPIO_LOOKUP() table to replace a
>>> >>>> devm_gpio_request_one() call in a device driver with devm_gpiod_get()?
>>> >>>> Do we need to add an interface extension to do this, e.g. passing
>>> >>>> GPIOF_OUT_INIT_HIGH as the flags rather than GPIO_ACTIVE_HIGH?
>>> >>>
>>> >>>
>>> >>> The way I see it, GPIO mappings (whether they are done using the
>>> >>> lookup tables, DT, or ACPI) should only care about details that are
>>> >>> relevant to the device layout and that should be abstracted to the
>>> >>> driver (e.g. whether the GPIO is active low or open drain) so drivers
>>> >>> do not need to check X conditions every time they want to drive the
>>> >>> GPIO.
>>> >>>
>>> >>> Direction and initial value, on the other hand, are clearly properties
>>> >>> that ought to be set by the driver itself. Thus my expectation here
>>> >>> would be that the driver sets the GPIO direction and initial value as
>>> >>> soon as it gets it using gpiod_direction_output(). In other words,
>>> >>> there is no replacement for gpio_request_one() with the gpiod
>>> >>> interface. Is there any use-case that cannot be covered by calling
>>> >>> gpiod_direction_output() right after gpiod_get()? AFAICT this is what
>>> >>> gpio_request_one() was doing anyway.
>>> >>
>>> >>
>>> >> I agree with you that this is something that should be done in the driver
>>> >> and not in the lookup table. I think that it is still a good idea to have a
>>> >> replacement for gpio_request_one with the new GPIO descriptor API. A large
>>> >> share of the drivers want to call either gpio_direction_input() or
>>> >> gpio_direction_output() right after requesting the GPIO. Combining both the
>>> >> requesting and the configuration of the GPIO into one function call makes
>>> >> the code a bit shorter and also simplifies the error handling. Even more so
>>> >> if e.g. the GPIO is optional. This was one of the main reasons why
>>> >> gpio_request_one was introduced, see the commit[1] that added it.
>>> >
>>> > I am not opposed to it as a convenience function. Note that since the
>>> > open-source and open-drain flags are already handled by the lookup
>>> > table, the only flags it should handle are those related to direction,
>>> > value, and (maybe) sysfs export.
>>>
>>> Problem is, too much convenience functions seems to ultimately kill convenience.
>>>
>>> The canonical way to request a GPIO is by providing a (device,
>>> function, index) triplet to gpiod_get_index(). Since most functions
>>> only need one GPIO, we have gpiod_get(device, function) which is
>>> basically an alias to gpiod_get_index(device, function, 0) (note to
>>> self: we should probably inline it).
>>>
>>> On top of these comes another set of convenience functions,
>>> gpiod_get_optional() and gpiod_get_index_optional(), which return NULL
>>> instead of -ENOENT if the requested GPIO mapping does not exist. This
>>> is useful for the common case where a driver can work without a GPIO.
>>>
>>> Of course these functions all have devm counterparts, so we currently
>>> have 8 (devm_)gpiod_get(_index)(_optional) functions.
>>>
>>> If we are to add functions with an init flags parameter, we will end
>>> with 16 functions. That starts to be a bit too much to my taste, and
>>> maybe that's where GPIO consumers should sacrifice some convenience to
>>> preserve a comprehensible GPIO API.
>>>
>>> There might be other ways to work around this though. For instance, we
>>> could replace the _optional functions by a GPIOF_OPTIONAL flag to be
>>> passed to a more generic function that would also accept direction and
>>> init value flags. Actually I am not seeing any user of the _optional
>>> variant in -next, so maybe we should just do this. Thierry, since you
>>> introduced the _optional functions, can we get your thoughts about
>>> this?
>>
>> I personally prefer explicit naming of the functions rather than putting
>> a bunch of flags into some parameter. If you're overly concerned about
>> the amount of convenience functions, perhaps the _index variants can be
>> left out for gpiod_get_one(). I'd argue that if drivers want to deal
>> with that level of detail anyway, they may just as well add the index
>> explicitly when calling the function.
>>
>> While we're at it, gpiod_get_one() doesn't sound like a very good name.
>> All other variants only request "one" as well. Perhaps something like
>> gpiod_get_with_flags() would be a better name.
>>
>> Then again, maybe rather than add a new set of functions we should bite
>> the bullet and change gpiod_get() (and variants) to take an additional
>> flags parameter. There aren't all that many users yet (I count 26
>> outside of drivers/gpio), so maybe now would still be a good time to do
>> that.
>
> That sounds reasonable indeed. And preferable to getting an aneurysm
> after trying to spell devm_gpiod_get_index_optional_with_flags().
>
> This also makes the most sense since most GPIO users will want to set
> a direction and value right after obtaining one. So if there is no
> objection I will probably start refactoring gpiod_get() this week.

Spammed half of the kernel developers with a patch adding a flags
argument to the gpiod getters and updating all gpiod users (there were
more than I thought!). I'm not sure how such a cross-subsystem patch
is supposed to be applied ; suggestions are welcome!

^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2014-07-24 15:10 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <1405086308-1461192-1-git-send-email-arnd@arndb.de>
     [not found] ` <16507628.c6raaN50oI@wuerfel>
     [not found]   ` <20140714183624.GV6800@sirena.org.uk>
2014-07-15  7:19     ` [alsa-devel] [PATCH 2/4] ASoC: s3c64xx/smartq: use dynamic registration Arnd Bergmann
2014-07-15  7:36       ` Alexandre Courbot
2014-07-15  7:58         ` Lars-Peter Clausen
2014-07-15  9:14           ` [alsa-devel] " Alexandre Courbot
2014-07-16  3:00             ` Alexandre Courbot
2014-07-16  7:12               ` Thierry Reding
2014-07-16  7:28                 ` Alexandre Courbot
2014-07-16  7:51                   ` Thierry Reding
2014-07-16  8:50                     ` Rob Jones
2014-07-16 11:09                       ` Thierry Reding
2014-07-23 15:20                         ` Linus Walleij
2014-07-17  4:28                       ` Alexandre Courbot
2014-07-17  7:44                         ` Thierry Reding
2014-07-17  8:55                           ` Alexandre Courbot
2014-07-17 10:17                             ` Mark Brown
2014-07-17 10:41                               ` Thierry Reding
2014-07-17 10:58                                 ` Lars-Peter Clausen
2014-07-17 11:05                                 ` Mark Brown
2014-07-21  3:36                                   ` Alexandre Courbot
2014-07-21 10:04                                     ` Mark Brown
2014-07-21 14:19                                       ` [alsa-devel] " Alexandre Courbot
2014-07-16  9:48                   ` Mark Brown
2014-07-24 15:10                   ` Alexandre Courbot
2014-07-15 10:39         ` Mark Brown

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).