mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] reset_source: use instance = -1 as default
@ 2019-08-25 14:55 Uwe Kleine-König
  2019-08-25 14:55 ` [PATCH 2/2] reset_source: drop reset_source_set_instance() Uwe Kleine-König
  0 siblings, 1 reply; 5+ messages in thread
From: Uwe Kleine-König @ 2019-08-25 14:55 UTC (permalink / raw)
  To: barebox

As with platform device id (does someone still remember?) 0 might be a valid
id. So use -1 for "unknown" or "doesn't apply" instead of 0.

Also don't pass the instance to the device tree if negative. (This ends
up as 0xffffffff otherwise.)

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 common/oftree.c        | 5 +++--
 common/reset_source.c  | 2 +-
 include/reset_source.h | 2 +-
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/common/oftree.c b/common/oftree.c
index 5bb5420a785b..28a3b965ffee 100644
--- a/common/oftree.c
+++ b/common/oftree.c
@@ -144,6 +144,7 @@ static int of_fixup_bootargs(struct device_node *root, void *unused)
 	struct device_node *node;
 	const char *str;
 	int err;
+	int instance = reset_source_get_instance();
 
 	str = linux_bootargs_get();
 	if (!str)
@@ -160,8 +161,8 @@ static int of_fixup_bootargs(struct device_node *root, void *unused)
 		return err;
 
 	of_property_write_string(node, "reset-source", reset_source_name());
-	of_property_write_u32(node, "reset-source-instance",
-			      reset_source_get_instance());
+	if (instance >= 0)
+		of_property_write_u32(node, "reset-source-instance", instance);
 
 	return of_fixup_bootargs_bootsource(root, node);
 }
diff --git a/common/reset_source.c b/common/reset_source.c
index 1955d3f87e33..e24aa337a7c4 100644
--- a/common/reset_source.c
+++ b/common/reset_source.c
@@ -54,7 +54,7 @@ void reset_source_set_priority(enum reset_src_type st, unsigned int priority)
 
 	reset_source = st;
 	reset_source_priority = priority;
-	reset_source_instance = 0;
+	reset_source_instance = -1;
 
 	pr_debug("Setting reset source to %s with priority %d\n",
 			reset_src_names[reset_source], priority);
diff --git a/include/reset_source.h b/include/reset_source.h
index 13bc3bcfde7c..2848a91115b8 100644
--- a/include/reset_source.h
+++ b/include/reset_source.h
@@ -49,7 +49,7 @@ static inline enum reset_src_type reset_source_get(void)
 
 static inline int reset_source_get_instance(void)
 {
-	return 0;
+	return -1;
 }
 
 static inline unsigned int of_get_reset_source_priority(struct device_node *node)
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 2/2] reset_source: drop reset_source_set_instance()
  2019-08-25 14:55 [PATCH 1/2] reset_source: use instance = -1 as default Uwe Kleine-König
@ 2019-08-25 14:55 ` Uwe Kleine-König
  2019-08-26 19:24   ` Andrey Smirnov
  0 siblings, 1 reply; 5+ messages in thread
From: Uwe Kleine-König @ 2019-08-25 14:55 UTC (permalink / raw)
  To: barebox

The semantic of reset_source_set_instance() required a separate call to
reset_source_set() (or reset_source_set_priority()) and checked right
usage only using the type. Make the set of functions a bit easier to use
by dropping reset_source_set_instance() and instead introduce a function
that can set all relevant parameters (source, priority and instance) in
one go.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 arch/arm/mach-imx/imx.c       |  4 +---
 common/reset_source.c         | 15 ++++-----------
 drivers/watchdog/stm32_iwdg.c |  3 +--
 include/reset_source.h        | 20 +++++++++++---------
 4 files changed, 17 insertions(+), 25 deletions(-)

diff --git a/arch/arm/mach-imx/imx.c b/arch/arm/mach-imx/imx.c
index 63914d306e6f..43b540b39771 100644
--- a/arch/arm/mach-imx/imx.c
+++ b/arch/arm/mach-imx/imx.c
@@ -199,9 +199,7 @@ void imx_set_reset_reason(void __iomem *srsr,
 		}
 	}
 
-	reset_source_set_priority(type,
-				  RESET_SOURCE_DEFAULT_PRIORITY);
-	reset_source_set_instance(type, instance);
+	reset_source_set_prinst(type, RESET_SOURCE_DEFAULT_PRIORITY, instance);
 
 	pr_info("i.MX reset reason %s (SRSR: 0x%08x)\n",
 		reset_source_name(), reg);
diff --git a/common/reset_source.c b/common/reset_source.c
index e24aa337a7c4..675b2071cb8d 100644
--- a/common/reset_source.c
+++ b/common/reset_source.c
@@ -47,19 +47,20 @@ int reset_source_get_instance(void)
 }
 EXPORT_SYMBOL(reset_source_get_instance);
 
-void reset_source_set_priority(enum reset_src_type st, unsigned int priority)
+void reset_source_set_prinst(enum reset_src_type st,
+			     unsigned int priority, int instance)
 {
 	if (priority <= reset_source_priority)
 		return;
 
 	reset_source = st;
 	reset_source_priority = priority;
-	reset_source_instance = -1;
+	reset_source_instance = instance;
 
 	pr_debug("Setting reset source to %s with priority %d\n",
 			reset_src_names[reset_source], priority);
 }
-EXPORT_SYMBOL(reset_source_set_priority);
+EXPORT_SYMBOL(reset_source_set_prinst);
 
 const char *reset_source_name(void)
 {
@@ -67,13 +68,6 @@ const char *reset_source_name(void)
 }
 EXPORT_SYMBOL(reset_source_name);
 
-void reset_source_set_instance(enum reset_src_type type, int instance)
-{
-	if (reset_source == type)
-		reset_source_instance = instance;
-}
-EXPORT_SYMBOL(reset_source_set_instance);
-
 static int reset_source_init(void)
 {
 	globalvar_add_simple_enum("system.reset", (unsigned int *)&reset_source,
@@ -83,7 +77,6 @@ static int reset_source_init(void)
 				 "%d");
 	return 0;
 }
-
 coredevice_initcall(reset_source_init);
 
 /**
diff --git a/drivers/watchdog/stm32_iwdg.c b/drivers/watchdog/stm32_iwdg.c
index 34912ae00eea..dbf776fa036c 100644
--- a/drivers/watchdog/stm32_iwdg.c
+++ b/drivers/watchdog/stm32_iwdg.c
@@ -187,8 +187,7 @@ static int stm32_set_reset_reason(struct regmap *rcc)
 		}
 	}
 
-	reset_source_set_priority(type, RESET_SOURCE_DEFAULT_PRIORITY);
-	reset_source_set_instance(type, instance);
+	reset_source_set_prinst(type, RESET_SOURCE_DEFAULT_PRIORITY, instance);
 
 	pr_info("STM32 RCC reset reason %s (MP_RSTSR: 0x%08x)\n",
 		reset_source_name(), reg);
diff --git a/include/reset_source.h b/include/reset_source.h
index 2848a91115b8..10ab9cc3871e 100644
--- a/include/reset_source.h
+++ b/include/reset_source.h
@@ -26,19 +26,15 @@ enum reset_src_type {
 };
 
 #ifdef CONFIG_RESET_SOURCE
-void reset_source_set_priority(enum reset_src_type, unsigned int priority);
+void reset_source_set_prinst(enum reset_src_type,
+			     unsigned int priority, int instance);
 enum reset_src_type reset_source_get(void);
-void reset_source_set_instance(enum reset_src_type type, int instance);
 int reset_source_get_instance(void);
 unsigned int of_get_reset_source_priority(struct device_node *node);
 const char *reset_source_name(void);
 #else
-static inline void reset_source_set_priority(enum reset_src_type type,
-		unsigned int priority)
-{
-}
-
-static inline void reset_source_set_instance(enum reset_src_type type, int instance)
+static inline void reset_source_set_prinst(enum reset_src_type type,
+					   unsigned int priority, int instance)
 {
 }
 
@@ -65,9 +61,15 @@ static inline const char *reset_source_name(void)
 
 #define RESET_SOURCE_DEFAULT_PRIORITY 100
 
+static inline void reset_source_set_priority(enum reset_src_type type,
+					     unsigned int priority)
+{
+       reset_source_set_prinst(type, priority, -1);
+}
+
 static inline void reset_source_set(enum reset_src_type type)
 {
-	reset_source_set_priority(type, RESET_SOURCE_DEFAULT_PRIORITY);
+       reset_source_set_priority(type, RESET_SOURCE_DEFAULT_PRIORITY);
 }
 
 #endif /* __INCLUDE_RESET_SOURCE_H */
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 2/2] reset_source: drop reset_source_set_instance()
  2019-08-25 14:55 ` [PATCH 2/2] reset_source: drop reset_source_set_instance() Uwe Kleine-König
@ 2019-08-26 19:24   ` Andrey Smirnov
  2019-08-26 20:12     ` Uwe Kleine-König
  0 siblings, 1 reply; 5+ messages in thread
From: Andrey Smirnov @ 2019-08-26 19:24 UTC (permalink / raw)
  To: Uwe Kleine-König; +Cc: Barebox List

On Sun, Aug 25, 2019 at 7:55 AM Uwe Kleine-König
<u.kleine-koenig@pengutronix.de> wrote:
>
> The semantic of reset_source_set_instance() required a separate call to
> reset_source_set() (or reset_source_set_priority()) and checked right
> usage only using the type. Make the set of functions a bit easier to use
> by dropping reset_source_set_instance() and instead introduce a function
> that can set all relevant parameters (source, priority and instance) in
> one go.
>
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
>  arch/arm/mach-imx/imx.c       |  4 +---
>  common/reset_source.c         | 15 ++++-----------
>  drivers/watchdog/stm32_iwdg.c |  3 +--
>  include/reset_source.h        | 20 +++++++++++---------
>  4 files changed, 17 insertions(+), 25 deletions(-)
>
> diff --git a/arch/arm/mach-imx/imx.c b/arch/arm/mach-imx/imx.c
> index 63914d306e6f..43b540b39771 100644
> --- a/arch/arm/mach-imx/imx.c
> +++ b/arch/arm/mach-imx/imx.c
> @@ -199,9 +199,7 @@ void imx_set_reset_reason(void __iomem *srsr,
>                 }
>         }
>
> -       reset_source_set_priority(type,
> -                                 RESET_SOURCE_DEFAULT_PRIORITY);
> -       reset_source_set_instance(type, instance);
> +       reset_source_set_prinst(type, RESET_SOURCE_DEFAULT_PRIORITY, instance);

Any change we can call this function
reset_source_set_priority_instance() or reset_source_set_all() instead
of "prinst"?

Thanks,
Andrey Smirnov

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 2/2] reset_source: drop reset_source_set_instance()
  2019-08-26 19:24   ` Andrey Smirnov
@ 2019-08-26 20:12     ` Uwe Kleine-König
  2019-08-27  4:52       ` Andrey Smirnov
  0 siblings, 1 reply; 5+ messages in thread
From: Uwe Kleine-König @ 2019-08-26 20:12 UTC (permalink / raw)
  To: Andrey Smirnov; +Cc: Barebox List

On Mon, Aug 26, 2019 at 12:24:12PM -0700, Andrey Smirnov wrote:
> On Sun, Aug 25, 2019 at 7:55 AM Uwe Kleine-König
> <u.kleine-koenig@pengutronix.de> wrote:
> >
> > The semantic of reset_source_set_instance() required a separate call to
> > reset_source_set() (or reset_source_set_priority()) and checked right
> > usage only using the type. Make the set of functions a bit easier to use
> > by dropping reset_source_set_instance() and instead introduce a function
> > that can set all relevant parameters (source, priority and instance) in
> > one go.
> >
> > Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> > ---
> >  arch/arm/mach-imx/imx.c       |  4 +---
> >  common/reset_source.c         | 15 ++++-----------
> >  drivers/watchdog/stm32_iwdg.c |  3 +--
> >  include/reset_source.h        | 20 +++++++++++---------
> >  4 files changed, 17 insertions(+), 25 deletions(-)
> >
> > diff --git a/arch/arm/mach-imx/imx.c b/arch/arm/mach-imx/imx.c
> > index 63914d306e6f..43b540b39771 100644
> > --- a/arch/arm/mach-imx/imx.c
> > +++ b/arch/arm/mach-imx/imx.c
> > @@ -199,9 +199,7 @@ void imx_set_reset_reason(void __iomem *srsr,
> >                 }
> >         }
> >
> > -       reset_source_set_priority(type,
> > -                                 RESET_SOURCE_DEFAULT_PRIORITY);
> > -       reset_source_set_instance(type, instance);
> > +       reset_source_set_prinst(type, RESET_SOURCE_DEFAULT_PRIORITY, instance);
> 
> Any change we can call this function
> reset_source_set_priority_instance() or reset_source_set_all() instead
> of "prinst"?

Did you see my v2 series? It's still prinst there, but maybe some
instances can be moved to the device variant there.

Having said that, I don't care much. I considered to make
reset_source_set() the variant with all parameters and rename the
current reset_source_set() to reset_source_set_type(). Would that make
sense to you?

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 2/2] reset_source: drop reset_source_set_instance()
  2019-08-26 20:12     ` Uwe Kleine-König
@ 2019-08-27  4:52       ` Andrey Smirnov
  0 siblings, 0 replies; 5+ messages in thread
From: Andrey Smirnov @ 2019-08-27  4:52 UTC (permalink / raw)
  To: Uwe Kleine-König; +Cc: Barebox List

On Mon, Aug 26, 2019 at 3:17 PM Uwe Kleine-König
<u.kleine-koenig@pengutronix.de> wrote:
>
> On Mon, Aug 26, 2019 at 12:24:12PM -0700, Andrey Smirnov wrote:
> > On Sun, Aug 25, 2019 at 7:55 AM Uwe Kleine-König
> > <u.kleine-koenig@pengutronix.de> wrote:
> > >
> > > The semantic of reset_source_set_instance() required a separate call to
> > > reset_source_set() (or reset_source_set_priority()) and checked right
> > > usage only using the type. Make the set of functions a bit easier to use
> > > by dropping reset_source_set_instance() and instead introduce a function
> > > that can set all relevant parameters (source, priority and instance) in
> > > one go.
> > >
> > > Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> > > ---
> > >  arch/arm/mach-imx/imx.c       |  4 +---
> > >  common/reset_source.c         | 15 ++++-----------
> > >  drivers/watchdog/stm32_iwdg.c |  3 +--
> > >  include/reset_source.h        | 20 +++++++++++---------
> > >  4 files changed, 17 insertions(+), 25 deletions(-)
> > >
> > > diff --git a/arch/arm/mach-imx/imx.c b/arch/arm/mach-imx/imx.c
> > > index 63914d306e6f..43b540b39771 100644
> > > --- a/arch/arm/mach-imx/imx.c
> > > +++ b/arch/arm/mach-imx/imx.c
> > > @@ -199,9 +199,7 @@ void imx_set_reset_reason(void __iomem *srsr,
> > >                 }
> > >         }
> > >
> > > -       reset_source_set_priority(type,
> > > -                                 RESET_SOURCE_DEFAULT_PRIORITY);
> > > -       reset_source_set_instance(type, instance);
> > > +       reset_source_set_prinst(type, RESET_SOURCE_DEFAULT_PRIORITY, instance);
> >
> > Any change we can call this function
> > reset_source_set_priority_instance() or reset_source_set_all() instead
> > of "prinst"?
>
> Did you see my v2 series? It's still prinst there, but maybe some
> instances can be moved to the device variant there.
>
> Having said that, I don't care much. I considered to make
> reset_source_set() the variant with all parameters and rename the
> current reset_source_set() to reset_source_set_type(). Would that make
> sense to you?

Yeah, totally, that'd probably be even better.

Thanks,
Andrey Smirnov

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2019-08-27  4:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-25 14:55 [PATCH 1/2] reset_source: use instance = -1 as default Uwe Kleine-König
2019-08-25 14:55 ` [PATCH 2/2] reset_source: drop reset_source_set_instance() Uwe Kleine-König
2019-08-26 19:24   ` Andrey Smirnov
2019-08-26 20:12     ` Uwe Kleine-König
2019-08-27  4:52       ` Andrey Smirnov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox