linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Rob Jones <rob.jones@codethink.co.uk>
To: "Heiko Stübner" <heiko@sntech.de>
Cc: linus.walleij@linaro.org, gnurou@gmail.com, lgirdwood@gmail.com,
	broonie@kernel.org, linux-gpio@vger.kernel.org,
	linux-kernel@vger.kernel.org, ian.molton@codethink.co.uk,
	ben.dooks@codethink.co.uk
Subject: Re: [PATCH 1/3] drivers/gpio: devres.c: allow gpio array requests for managed devices
Date: Wed, 18 Jun 2014 16:56:08 +0100	[thread overview]
Message-ID: <53A1B698.7090802@codethink.co.uk> (raw)
In-Reply-To: <4501550.PbI0gbPlXS@diego>


On 18/06/14 14:24, Heiko Stübner wrote:
> Am Dienstag, 10. Juni 2014, 15:41:46 schrieb Rob Jones:
>> Add functions devm_gpio_request_array() and devm_gpio_free_array()
>> which are exactly analogous to the equivalent non-managed device
>> functions gpio_request_array() and gpio_free_array(), which can be
>> found in module gpiolib.c.
>>
>> Note that if devm_gpio_request_array() fails, no gpios are obtained.
>> No indication is provided as to which particular request failed.
>>
>> Reviewed-by: Ian Molton <ian.molton@codethink.co.uk>
>> Signed-off-by: Rob Jones <rob.jones@codethink.co.uk>
> apart from the doc issue below this looks ok to me
>
>
>> ---
>>   drivers/gpio/devres.c |   57
>> +++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/gpio.h  |
>>   4 ++++
>>   2 files changed, 61 insertions(+)
>>
>> diff --git a/drivers/gpio/devres.c b/drivers/gpio/devres.c
>> index 307464f..fd95240d 100644
>> --- a/drivers/gpio/devres.c
>> +++ b/drivers/gpio/devres.c
>> @@ -186,6 +186,63 @@ int devm_gpio_request_one(struct device *dev, unsigned
>> gpio, EXPORT_SYMBOL(devm_gpio_request_one);
>>
>>   /**
>> + * devm_gpio_request_array - request multiple GPIOs in a single call
>> + *			     for a managed device
>> + * @dev:	device requesting the gpio
>> + * @array:      array of the 'struct gpio'
>> + * @num:        how many GPIOs in the array
> @dev uses a tab as spacing, while @array and @num use spaces, might be nice to
> have this consistent.

I'm not sure how that happened. I'll rework it before re-submitting the 
series.

>
>
>> + *
>> + * Except for the extra @dev argument, this function takes the
>> + * same arguments and performs the same function as
>> + * gpio_request().  GPIOs requested with this function will be
>> + * automatically freed on driver detach.
>> + *
>> + * If GPIOs allocated with this function need to be freed separately,
>> + * devm_gpio_free_array() or devm_gpio_free() must be used.
>> + */
>> +int devm_gpio_request_array(struct device *dev,
>> +			    const struct gpio *array,
>> +			    size_t num)
>> +{
>> +	int i, err = 0;
>> +
>> +	for (i = 0; i < num; i++, array++) {
>> +		err = devm_gpio_request_one(dev,
>> +					    array->gpio,
>> +					    array->flags,
>> +					    array->label);
>> +		if (err) {
>> +			while (i--)
>> +				devm_gpio_free(dev, (--array)->gpio);
>> +		}
>> +	}
>> +
>> +	return err;
>> +}
>> +EXPORT_SYMBOL(devm_gpio_request_array);
>> +
>> +/**
>> + * devm_gpio_free_array - release multiple GPIOs in a single call
>> + *			  for a managed device
>> + * @dev:	device requesting the gpio
>> + * @array:      array of the 'struct gpio'
>> + * @num:        how many GPIOs in the array
> same here
>
>> + *
>> + * Except for the extra @dev argument, this function takes the
>> + * same arguments and performs the same function as gpio_free_array().
>> + * This function instead of gpio_free_array() should be used to
>> + * manually free GPIOs allocated with devm_gpio_request().
>> + */
>> +void devm_gpio_free_array(struct device *dev,
>> +			  const struct gpio *array,
>> +			  size_t num)
>> +{
>> +	while (num--)
>> +		devm_gpio_free(dev, (array++)->gpio);
>> +}
>> +EXPORT_SYMBOL(devm_gpio_free_array);
>> +
>> +/**
>>    *      devm_gpio_free - free a GPIO
>>    *      @dev: device to free GPIO for
>>    *      @gpio: GPIO to free
>> diff --git a/include/linux/gpio.h b/include/linux/gpio.h
>> index 85aa5d0..12d5648 100644
>> --- a/include/linux/gpio.h
>> +++ b/include/linux/gpio.h
>> @@ -84,6 +84,10 @@ struct device;
>>   int devm_gpio_request(struct device *dev, unsigned gpio, const char
>> *label); int devm_gpio_request_one(struct device *dev, unsigned gpio,
>>   			  unsigned long flags, const char *label);
>> +int devm_gpio_request_array(struct device *dev, const struct gpio *array,
>> +			    size_t num);
>> +void devm_gpio_free_array(struct device *dev, const struct gpio *array,
>> +			 size_t num);
>>   void devm_gpio_free(struct device *dev, unsigned int gpio);
>>
>>   #else /* ! CONFIG_GPIOLIB */
>
>

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

--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2014-06-18 15:56 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-10 14:41 [PATCH 0/3] use managed resources for gpio-regulator probe Rob Jones
2014-06-10 14:41 ` [PATCH 1/3] drivers/gpio: devres.c: allow gpio array requests for managed devices Rob Jones
2014-06-18 13:24   ` Heiko Stübner
2014-06-18 15:56     ` Rob Jones [this message]
2014-06-10 14:41 ` [PATCH 2/3] drivers/base: devres.c: Add block copy func. " Rob Jones
2014-06-18 13:05   ` Heiko Stübner
2014-06-18 15:52     ` Rob Jones
2014-06-10 14:41 ` [PATCH 3/3] drivers/regulator: gpio-regulator.c: use managed resources for probe Rob Jones
2014-06-18 13:05   ` Heiko Stübner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=53A1B698.7090802@codethink.co.uk \
    --to=rob.jones@codethink.co.uk \
    --cc=ben.dooks@codethink.co.uk \
    --cc=broonie@kernel.org \
    --cc=gnurou@gmail.com \
    --cc=heiko@sntech.de \
    --cc=ian.molton@codethink.co.uk \
    --cc=lgirdwood@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).