linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] reset: Add reset_control_get_count()
@ 2018-11-13 12:47 Geert Uytterhoeven
  2018-11-13 14:29 ` Philipp Zabel
  2018-11-14  6:30 ` Ulrich Hecht
  0 siblings, 2 replies; 6+ messages in thread
From: Geert Uytterhoeven @ 2018-11-13 12:47 UTC (permalink / raw)
  To: Philipp Zabel
  Cc: Eric Auger, Alex Williamson, kvm, linux-renesas-soc,
	linux-kernel, Geert Uytterhoeven

Currently the reset core has internal support for counting the number of
resets for a device described in DT.  Generalize this to devices using
lookup resets, and export it for public use.

This will be used by generic drivers that need to be sure a device is
controlled by a single, dedicated reset line (e.g. vfio-platform).

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
See https://lore.kernel.org/lkml/1539003437.11512.20.camel@pengutronix.de/
for the rationale to ensure a single, dedicated reset line.

 drivers/reset/core.c  | 41 +++++++++++++++++++++++++++++++++++++++++
 include/linux/reset.h |  7 +++++++
 2 files changed, 48 insertions(+)

diff --git a/drivers/reset/core.c b/drivers/reset/core.c
index 654e20ff2d5da9d4..c32b755ec373c338 100644
--- a/drivers/reset/core.c
+++ b/drivers/reset/core.c
@@ -859,3 +859,44 @@ devm_reset_control_array_get(struct device *dev, bool shared, bool optional)
 	return rstc;
 }
 EXPORT_SYMBOL_GPL(devm_reset_control_array_get);
+
+static int reset_control_get_count_from_lookup(struct device *dev)
+{
+	const struct reset_control_lookup *lookup;
+	const char *dev_id = dev_name(dev);
+	int count = 0;
+
+	if (!dev)
+		return -EINVAL;
+
+	mutex_lock(&reset_lookup_mutex);
+
+	list_for_each_entry(lookup, &reset_lookup_list, list) {
+		if (!strcmp(lookup->dev_id, dev_id))
+			count++;
+	}
+
+	mutex_unlock(&reset_lookup_mutex);
+
+	if (count == 0)
+		count = -ENOENT;
+
+	return count;
+}
+
+/**
+ * of_reset_control_get_count - Count number of resets available with a device
+ *
+ * @dev: device for which to return the number of resets
+ *
+ * Returns positive reset count on success, or error number on failure and
+ * on count being zero.
+ */
+int reset_control_get_count(struct device *dev)
+{
+	if (dev->of_node)
+		return of_reset_control_get_count(dev->of_node);
+
+	return reset_control_get_count_from_lookup(dev);
+}
+EXPORT_SYMBOL_GPL(reset_control_get_count);
diff --git a/include/linux/reset.h b/include/linux/reset.h
index f0b094130686bf32..2698b36bd1eb3e0c 100644
--- a/include/linux/reset.h
+++ b/include/linux/reset.h
@@ -32,6 +32,8 @@ struct reset_control *devm_reset_control_array_get(struct device *dev,
 struct reset_control *of_reset_control_array_get(struct device_node *np,
 						 bool shared, bool optional);
 
+int reset_control_get_count(struct device *dev);
+
 #else
 
 static inline int reset_control_reset(struct reset_control *rstc)
@@ -97,6 +99,11 @@ of_reset_control_array_get(struct device_node *np, bool shared, bool optional)
 	return optional ? NULL : ERR_PTR(-ENOTSUPP);
 }
 
+static inline int reset_control_get_count(struct device *dev)
+{
+	return -ENOENT;
+}
+
 #endif /* CONFIG_RESET_CONTROLLER */
 
 static inline int __must_check device_reset(struct device *dev)
-- 
2.17.1


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

* Re: [PATCH] reset: Add reset_control_get_count()
  2018-11-13 12:47 [PATCH] reset: Add reset_control_get_count() Geert Uytterhoeven
@ 2018-11-13 14:29 ` Philipp Zabel
  2018-11-14  6:30 ` Ulrich Hecht
  1 sibling, 0 replies; 6+ messages in thread
From: Philipp Zabel @ 2018-11-13 14:29 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Eric Auger, Alex Williamson, kvm, linux-renesas-soc, linux-kernel

Hi Geert,

On Tue, 2018-11-13 at 13:47 +0100, Geert Uytterhoeven wrote:
> Currently the reset core has internal support for counting the number of
> resets for a device described in DT.  Generalize this to devices using
> lookup resets, and export it for public use.
> 
> This will be used by generic drivers that need to be sure a device is
> controlled by a single, dedicated reset line (e.g. vfio-platform).
> 
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>

Thank you, I have applied this patch to reset/next.

regards
Philipp

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

* Re: [PATCH] reset: Add reset_control_get_count()
  2018-11-13 12:47 [PATCH] reset: Add reset_control_get_count() Geert Uytterhoeven
  2018-11-13 14:29 ` Philipp Zabel
@ 2018-11-14  6:30 ` Ulrich Hecht
  2018-11-14  8:58   ` Geert Uytterhoeven
  1 sibling, 1 reply; 6+ messages in thread
From: Ulrich Hecht @ 2018-11-14  6:30 UTC (permalink / raw)
  To: Geert Uytterhoeven, Philipp Zabel
  Cc: Eric Auger, Alex Williamson, kvm, linux-renesas-soc, linux-kernel

Thank you for your patch.

> On November 13, 2018 at 1:47 PM Geert Uytterhoeven <geert+renesas@glider.be> wrote:
> 
> 
> Currently the reset core has internal support for counting the number of
> resets for a device described in DT.  Generalize this to devices using
> lookup resets, and export it for public use.
> 
> This will be used by generic drivers that need to be sure a device is
> controlled by a single, dedicated reset line (e.g. vfio-platform).
> 
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> ---
> See https://lore.kernel.org/lkml/1539003437.11512.20.camel@pengutronix.de/
> for the rationale to ensure a single, dedicated reset line.
> 
>  drivers/reset/core.c  | 41 +++++++++++++++++++++++++++++++++++++++++
>  include/linux/reset.h |  7 +++++++
>  2 files changed, 48 insertions(+)
> 
> diff --git a/drivers/reset/core.c b/drivers/reset/core.c
> index 654e20ff2d5da9d4..c32b755ec373c338 100644
> --- a/drivers/reset/core.c
> +++ b/drivers/reset/core.c
> @@ -859,3 +859,44 @@ devm_reset_control_array_get(struct device *dev, bool shared, bool optional)
>  	return rstc;
>  }
>  EXPORT_SYMBOL_GPL(devm_reset_control_array_get);
> +
> +static int reset_control_get_count_from_lookup(struct device *dev)
> +{
> +	const struct reset_control_lookup *lookup;
> +	const char *dev_id = dev_name(dev);
> +	int count = 0;
> +
> +	if (!dev)
> +		return -EINVAL;
> +
> +	mutex_lock(&reset_lookup_mutex);
> +
> +	list_for_each_entry(lookup, &reset_lookup_list, list) {
> +		if (!strcmp(lookup->dev_id, dev_id))
> +			count++;
> +	}
> +
> +	mutex_unlock(&reset_lookup_mutex);
> +
> +	if (count == 0)
> +		count = -ENOENT;
> +
> +	return count;
> +}
> +
> +/**
> + * of_reset_control_get_count - Count number of resets available with a device

Should be "reset_control_get_count", without of_ prefix.

> + *
> + * @dev: device for which to return the number of resets
> + *
> + * Returns positive reset count on success, or error number on failure and
> + * on count being zero.
> + */
> +int reset_control_get_count(struct device *dev)
> +{
> +	if (dev->of_node)
> +		return of_reset_control_get_count(dev->of_node);
> +
> +	return reset_control_get_count_from_lookup(dev);
> +}
> +EXPORT_SYMBOL_GPL(reset_control_get_count);
> diff --git a/include/linux/reset.h b/include/linux/reset.h
> index f0b094130686bf32..2698b36bd1eb3e0c 100644
> --- a/include/linux/reset.h
> +++ b/include/linux/reset.h
> @@ -32,6 +32,8 @@ struct reset_control *devm_reset_control_array_get(struct device *dev,
>  struct reset_control *of_reset_control_array_get(struct device_node *np,
>  						 bool shared, bool optional);
>  
> +int reset_control_get_count(struct device *dev);
> +
>  #else
>  
>  static inline int reset_control_reset(struct reset_control *rstc)
> @@ -97,6 +99,11 @@ of_reset_control_array_get(struct device_node *np, bool shared, bool optional)
>  	return optional ? NULL : ERR_PTR(-ENOTSUPP);
>  }
>  
> +static inline int reset_control_get_count(struct device *dev)
> +{
> +	return -ENOENT;
> +}
> +
>  #endif /* CONFIG_RESET_CONTROLLER */
>  
>  static inline int __must_check device_reset(struct device *dev)
> -- 
> 2.17.1
>

CU
Uli

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

* Re: [PATCH] reset: Add reset_control_get_count()
  2018-11-14  6:30 ` Ulrich Hecht
@ 2018-11-14  8:58   ` Geert Uytterhoeven
  2018-11-14  9:26     ` Philipp Zabel
  0 siblings, 1 reply; 6+ messages in thread
From: Geert Uytterhoeven @ 2018-11-14  8:58 UTC (permalink / raw)
  To: uli
  Cc: Geert Uytterhoeven, Philipp Zabel, Auger Eric, Alex Williamson,
	KVM list, Linux-Renesas, Linux Kernel Mailing List

On Wed, Nov 14, 2018 at 7:30 AM Ulrich Hecht <uli@fpond.eu> wrote:
> On November 13, 2018 at 1:47 PM Geert Uytterhoeven <geert+renesas@glider.be> wrote:
> > Currently the reset core has internal support for counting the number of
> > resets for a device described in DT.  Generalize this to devices using
> > lookup resets, and export it for public use.
> >
> > This will be used by generic drivers that need to be sure a device is
> > controlled by a single, dedicated reset line (e.g. vfio-platform).
> >
> > Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> > ---
> > See https://lore.kernel.org/lkml/1539003437.11512.20.camel@pengutronix.de/
> > for the rationale to ensure a single, dedicated reset line.
> >
> >  drivers/reset/core.c  | 41 +++++++++++++++++++++++++++++++++++++++++
> >  include/linux/reset.h |  7 +++++++
> >  2 files changed, 48 insertions(+)
> >
> > diff --git a/drivers/reset/core.c b/drivers/reset/core.c
> > index 654e20ff2d5da9d4..c32b755ec373c338 100644
> > --- a/drivers/reset/core.c
> > +++ b/drivers/reset/core.c

> > +/**
> > + * of_reset_control_get_count - Count number of resets available with a device
>
> Should be "reset_control_get_count", without of_ prefix.

Oops, thanks for catching!

Philipp: Do you want a v2 or incremental, or can you fix it up yourself?

Thanks!

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH] reset: Add reset_control_get_count()
  2018-11-14  8:58   ` Geert Uytterhoeven
@ 2018-11-14  9:26     ` Philipp Zabel
  2018-11-14  9:37       ` Geert Uytterhoeven
  0 siblings, 1 reply; 6+ messages in thread
From: Philipp Zabel @ 2018-11-14  9:26 UTC (permalink / raw)
  To: Geert Uytterhoeven, uli
  Cc: Geert Uytterhoeven, Auger Eric, Alex Williamson, KVM list,
	Linux-Renesas, Linux Kernel Mailing List

On Wed, 2018-11-14 at 09:58 +0100, Geert Uytterhoeven wrote:
> On Wed, Nov 14, 2018 at 7:30 AM Ulrich Hecht <uli@fpond.eu> wrote:
> > On November 13, 2018 at 1:47 PM Geert Uytterhoeven <geert+renesas@glider.be> wrote:
> > > Currently the reset core has internal support for counting the number of
> > > resets for a device described in DT.  Generalize this to devices using
> > > lookup resets, and export it for public use.
> > > 
> > > This will be used by generic drivers that need to be sure a device is
> > > controlled by a single, dedicated reset line (e.g. vfio-platform).
> > > 
> > > Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> > > ---
> > > See https://lore.kernel.org/lkml/1539003437.11512.20.camel@pengutronix.de/
> > > for the rationale to ensure a single, dedicated reset line.
> > > 
> > >  drivers/reset/core.c  | 41 +++++++++++++++++++++++++++++++++++++++++
> > >  include/linux/reset.h |  7 +++++++
> > >  2 files changed, 48 insertions(+)
> > > 
> > > diff --git a/drivers/reset/core.c b/drivers/reset/core.c
> > > index 654e20ff2d5da9d4..c32b755ec373c338 100644
> > > --- a/drivers/reset/core.c
> > > +++ b/drivers/reset/core.c
> > > +/**
> > > + * of_reset_control_get_count - Count number of resets available with a device
> > 
> > Should be "reset_control_get_count", without of_ prefix.
> 
> Oops, thanks for catching!
> 
> Philipp: Do you want a v2 or incremental, or can you fix it up yourself?

No need, I'll fix it up.

thanks
Philipp

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

* Re: [PATCH] reset: Add reset_control_get_count()
  2018-11-14  9:26     ` Philipp Zabel
@ 2018-11-14  9:37       ` Geert Uytterhoeven
  0 siblings, 0 replies; 6+ messages in thread
From: Geert Uytterhoeven @ 2018-11-14  9:37 UTC (permalink / raw)
  To: Philipp Zabel
  Cc: uli, Geert Uytterhoeven, Auger Eric, Alex Williamson, KVM list,
	Linux-Renesas, Linux Kernel Mailing List

Hi Philipp,

On Wed, Nov 14, 2018 at 10:26 AM Philipp Zabel <p.zabel@pengutronix.de> wrote:
> On Wed, 2018-11-14 at 09:58 +0100, Geert Uytterhoeven wrote:
> > On Wed, Nov 14, 2018 at 7:30 AM Ulrich Hecht <uli@fpond.eu> wrote:
> > > On November 13, 2018 at 1:47 PM Geert Uytterhoeven <geert+renesas@glider.be> wrote:
> > > > Currently the reset core has internal support for counting the number of
> > > > resets for a device described in DT.  Generalize this to devices using
> > > > lookup resets, and export it for public use.
> > > >
> > > > This will be used by generic drivers that need to be sure a device is
> > > > controlled by a single, dedicated reset line (e.g. vfio-platform).
> > > >
> > > > Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>

> > > > --- a/drivers/reset/core.c
> > > > +++ b/drivers/reset/core.c
> > > > +/**
> > > > + * of_reset_control_get_count - Count number of resets available with a device
> > >
> > > Should be "reset_control_get_count", without of_ prefix.
> >
> > Oops, thanks for catching!
> >
> > Philipp: Do you want a v2 or incremental, or can you fix it up yourself?
>
> No need, I'll fix it up.

Thanks, and sorry for the typo.

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

end of thread, other threads:[~2018-11-14  9:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-13 12:47 [PATCH] reset: Add reset_control_get_count() Geert Uytterhoeven
2018-11-13 14:29 ` Philipp Zabel
2018-11-14  6:30 ` Ulrich Hecht
2018-11-14  8:58   ` Geert Uytterhoeven
2018-11-14  9:26     ` Philipp Zabel
2018-11-14  9:37       ` Geert Uytterhoeven

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