* [PATCH] mmc: pwrseq_simple: use GPIO descriptors array API
@ 2015-09-21 12:14 Javier Martinez Canillas
2015-09-23 21:42 ` Ulf Hansson
0 siblings, 1 reply; 2+ messages in thread
From: Javier Martinez Canillas @ 2015-09-21 12:14 UTC (permalink / raw)
To: linux-kernel
Cc: Tony Lindgren, Javier Martinez Canillas, Srinivas Kandagatla,
linux-mmc, Alexandre Courbot, NeilBrown, Ulf Hansson
The simple power sequence provider sets a value for multiple GPIOs in one
go so it is better to use the API already provided by the GPIO descriptor
API instead of open coding the same logic.
Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
---
drivers/mmc/core/pwrseq_simple.c | 45 ++++++++++++++--------------------------
1 file changed, 15 insertions(+), 30 deletions(-)
diff --git a/drivers/mmc/core/pwrseq_simple.c b/drivers/mmc/core/pwrseq_simple.c
index 0b14b83a53d6..d10538bb5e07 100644
--- a/drivers/mmc/core/pwrseq_simple.c
+++ b/drivers/mmc/core/pwrseq_simple.c
@@ -23,18 +23,21 @@ struct mmc_pwrseq_simple {
struct mmc_pwrseq pwrseq;
bool clk_enabled;
struct clk *ext_clk;
- int nr_gpios;
- struct gpio_desc *reset_gpios[0];
+ struct gpio_descs *reset_gpios;
};
static void mmc_pwrseq_simple_set_gpios_value(struct mmc_pwrseq_simple *pwrseq,
int value)
{
int i;
+ struct gpio_descs *reset_gpios = pwrseq->reset_gpios;
+ int values[reset_gpios->ndescs];
- for (i = 0; i < pwrseq->nr_gpios; i++)
- if (!IS_ERR(pwrseq->reset_gpios[i]))
- gpiod_set_value_cansleep(pwrseq->reset_gpios[i], value);
+ for (i = 0; i < reset_gpios->ndescs; i++)
+ values[i] = value;
+
+ gpiod_set_array_value_cansleep(reset_gpios->ndescs, reset_gpios->desc,
+ values);
}
static void mmc_pwrseq_simple_pre_power_on(struct mmc_host *host)
@@ -75,11 +78,8 @@ static void mmc_pwrseq_simple_free(struct mmc_host *host)
{
struct mmc_pwrseq_simple *pwrseq = container_of(host->pwrseq,
struct mmc_pwrseq_simple, pwrseq);
- int i;
- for (i = 0; i < pwrseq->nr_gpios; i++)
- if (!IS_ERR(pwrseq->reset_gpios[i]))
- gpiod_put(pwrseq->reset_gpios[i]);
+ gpiod_put_array(pwrseq->reset_gpios);
if (!IS_ERR(pwrseq->ext_clk))
clk_put(pwrseq->ext_clk);
@@ -98,14 +98,9 @@ struct mmc_pwrseq *mmc_pwrseq_simple_alloc(struct mmc_host *host,
struct device *dev)
{
struct mmc_pwrseq_simple *pwrseq;
- int i, nr_gpios, ret = 0;
-
- nr_gpios = of_gpio_named_count(dev->of_node, "reset-gpios");
- if (nr_gpios < 0)
- nr_gpios = 0;
+ int ret = 0;
- pwrseq = kzalloc(sizeof(struct mmc_pwrseq_simple) + nr_gpios *
- sizeof(struct gpio_desc *), GFP_KERNEL);
+ pwrseq = kzalloc(sizeof(*pwrseq), GFP_KERNEL);
if (!pwrseq)
return ERR_PTR(-ENOMEM);
@@ -116,22 +111,12 @@ struct mmc_pwrseq *mmc_pwrseq_simple_alloc(struct mmc_host *host,
goto free;
}
- for (i = 0; i < nr_gpios; i++) {
- pwrseq->reset_gpios[i] = gpiod_get_index(dev, "reset", i,
- GPIOD_OUT_HIGH);
- if (IS_ERR(pwrseq->reset_gpios[i]) &&
- PTR_ERR(pwrseq->reset_gpios[i]) != -ENOENT &&
- PTR_ERR(pwrseq->reset_gpios[i]) != -ENOSYS) {
- ret = PTR_ERR(pwrseq->reset_gpios[i]);
-
- while (i--)
- gpiod_put(pwrseq->reset_gpios[i]);
-
- goto clk_put;
- }
+ pwrseq->reset_gpios = gpiod_get_array(dev, "reset", GPIOD_OUT_HIGH);
+ if (IS_ERR(pwrseq->reset_gpios)) {
+ ret = PTR_ERR(pwrseq->reset_gpios);
+ goto clk_put;
}
- pwrseq->nr_gpios = nr_gpios;
pwrseq->pwrseq.ops = &mmc_pwrseq_simple_ops;
return &pwrseq->pwrseq;
--
2.4.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] mmc: pwrseq_simple: use GPIO descriptors array API
2015-09-21 12:14 [PATCH] mmc: pwrseq_simple: use GPIO descriptors array API Javier Martinez Canillas
@ 2015-09-23 21:42 ` Ulf Hansson
0 siblings, 0 replies; 2+ messages in thread
From: Ulf Hansson @ 2015-09-23 21:42 UTC (permalink / raw)
To: Javier Martinez Canillas
Cc: linux-kernel, Tony Lindgren, Srinivas Kandagatla, linux-mmc,
Alexandre Courbot, NeilBrown
On 21 September 2015 at 14:14, Javier Martinez Canillas
<javier@osg.samsung.com> wrote:
> The simple power sequence provider sets a value for multiple GPIOs in one
> go so it is better to use the API already provided by the GPIO descriptor
> API instead of open coding the same logic.
>
> Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
Thanks, applied for next!
Kind regards
Uffe
>
> ---
>
> drivers/mmc/core/pwrseq_simple.c | 45 ++++++++++++++--------------------------
> 1 file changed, 15 insertions(+), 30 deletions(-)
>
> diff --git a/drivers/mmc/core/pwrseq_simple.c b/drivers/mmc/core/pwrseq_simple.c
> index 0b14b83a53d6..d10538bb5e07 100644
> --- a/drivers/mmc/core/pwrseq_simple.c
> +++ b/drivers/mmc/core/pwrseq_simple.c
> @@ -23,18 +23,21 @@ struct mmc_pwrseq_simple {
> struct mmc_pwrseq pwrseq;
> bool clk_enabled;
> struct clk *ext_clk;
> - int nr_gpios;
> - struct gpio_desc *reset_gpios[0];
> + struct gpio_descs *reset_gpios;
> };
>
> static void mmc_pwrseq_simple_set_gpios_value(struct mmc_pwrseq_simple *pwrseq,
> int value)
> {
> int i;
> + struct gpio_descs *reset_gpios = pwrseq->reset_gpios;
> + int values[reset_gpios->ndescs];
>
> - for (i = 0; i < pwrseq->nr_gpios; i++)
> - if (!IS_ERR(pwrseq->reset_gpios[i]))
> - gpiod_set_value_cansleep(pwrseq->reset_gpios[i], value);
> + for (i = 0; i < reset_gpios->ndescs; i++)
> + values[i] = value;
> +
> + gpiod_set_array_value_cansleep(reset_gpios->ndescs, reset_gpios->desc,
> + values);
> }
>
> static void mmc_pwrseq_simple_pre_power_on(struct mmc_host *host)
> @@ -75,11 +78,8 @@ static void mmc_pwrseq_simple_free(struct mmc_host *host)
> {
> struct mmc_pwrseq_simple *pwrseq = container_of(host->pwrseq,
> struct mmc_pwrseq_simple, pwrseq);
> - int i;
>
> - for (i = 0; i < pwrseq->nr_gpios; i++)
> - if (!IS_ERR(pwrseq->reset_gpios[i]))
> - gpiod_put(pwrseq->reset_gpios[i]);
> + gpiod_put_array(pwrseq->reset_gpios);
>
> if (!IS_ERR(pwrseq->ext_clk))
> clk_put(pwrseq->ext_clk);
> @@ -98,14 +98,9 @@ struct mmc_pwrseq *mmc_pwrseq_simple_alloc(struct mmc_host *host,
> struct device *dev)
> {
> struct mmc_pwrseq_simple *pwrseq;
> - int i, nr_gpios, ret = 0;
> -
> - nr_gpios = of_gpio_named_count(dev->of_node, "reset-gpios");
> - if (nr_gpios < 0)
> - nr_gpios = 0;
> + int ret = 0;
>
> - pwrseq = kzalloc(sizeof(struct mmc_pwrseq_simple) + nr_gpios *
> - sizeof(struct gpio_desc *), GFP_KERNEL);
> + pwrseq = kzalloc(sizeof(*pwrseq), GFP_KERNEL);
> if (!pwrseq)
> return ERR_PTR(-ENOMEM);
>
> @@ -116,22 +111,12 @@ struct mmc_pwrseq *mmc_pwrseq_simple_alloc(struct mmc_host *host,
> goto free;
> }
>
> - for (i = 0; i < nr_gpios; i++) {
> - pwrseq->reset_gpios[i] = gpiod_get_index(dev, "reset", i,
> - GPIOD_OUT_HIGH);
> - if (IS_ERR(pwrseq->reset_gpios[i]) &&
> - PTR_ERR(pwrseq->reset_gpios[i]) != -ENOENT &&
> - PTR_ERR(pwrseq->reset_gpios[i]) != -ENOSYS) {
> - ret = PTR_ERR(pwrseq->reset_gpios[i]);
> -
> - while (i--)
> - gpiod_put(pwrseq->reset_gpios[i]);
> -
> - goto clk_put;
> - }
> + pwrseq->reset_gpios = gpiod_get_array(dev, "reset", GPIOD_OUT_HIGH);
> + if (IS_ERR(pwrseq->reset_gpios)) {
> + ret = PTR_ERR(pwrseq->reset_gpios);
> + goto clk_put;
> }
>
> - pwrseq->nr_gpios = nr_gpios;
> pwrseq->pwrseq.ops = &mmc_pwrseq_simple_ops;
>
> return &pwrseq->pwrseq;
> --
> 2.4.3
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-mmc" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-09-23 21:42 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-21 12:14 [PATCH] mmc: pwrseq_simple: use GPIO descriptors array API Javier Martinez Canillas
2015-09-23 21:42 ` Ulf Hansson
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).