* [PATCH v2 1/7] reset_source: use instance = -1 as default
2019-08-25 15:58 [PATCH v2 0/7] clean up and complement reset source handling Uwe Kleine-König
@ 2019-08-25 15:58 ` Uwe Kleine-König
2019-08-25 15:58 ` [PATCH v2 2/7] reset_source: fix ordering of exported functions Uwe Kleine-König
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Uwe Kleine-König @ 2019-08-25 15:58 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] 9+ messages in thread
* [PATCH v2 2/7] reset_source: fix ordering of exported functions
2019-08-25 15:58 [PATCH v2 0/7] clean up and complement reset source handling Uwe Kleine-König
2019-08-25 15:58 ` [PATCH v2 1/7] reset_source: use instance = -1 as default Uwe Kleine-König
@ 2019-08-25 15:58 ` Uwe Kleine-König
2019-08-25 15:58 ` [PATCH v2 3/7] reset_source: drop reset_source_set_instance() Uwe Kleine-König
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Uwe Kleine-König @ 2019-08-25 15:58 UTC (permalink / raw)
To: barebox
Declare and implement getters first, then setters. This syncs the order
of functions in reset_source.c and reset_source.h.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
common/reset_source.c | 12 ++++++------
include/reset_source.h | 33 +++++++++++++++++++--------------
2 files changed, 25 insertions(+), 20 deletions(-)
diff --git a/common/reset_source.c b/common/reset_source.c
index e24aa337a7c4..f400112483a5 100644
--- a/common/reset_source.c
+++ b/common/reset_source.c
@@ -41,6 +41,12 @@ enum reset_src_type reset_source_get(void)
}
EXPORT_SYMBOL(reset_source_get);
+const char *reset_source_name(void)
+{
+ return reset_src_names[reset_source];
+}
+EXPORT_SYMBOL(reset_source_name);
+
int reset_source_get_instance(void)
{
return reset_source_instance;
@@ -61,12 +67,6 @@ void reset_source_set_priority(enum reset_src_type st, unsigned int priority)
}
EXPORT_SYMBOL(reset_source_set_priority);
-const char *reset_source_name(void)
-{
- return reset_src_names[reset_source];
-}
-EXPORT_SYMBOL(reset_source_name);
-
void reset_source_set_instance(enum reset_src_type type, int instance)
{
if (reset_source == type)
diff --git a/include/reset_source.h b/include/reset_source.h
index 2848a91115b8..85329c8cea7a 100644
--- a/include/reset_source.h
+++ b/include/reset_source.h
@@ -26,25 +26,26 @@ enum reset_src_type {
};
#ifdef CONFIG_RESET_SOURCE
-void reset_source_set_priority(enum reset_src_type, unsigned int priority);
+
enum reset_src_type reset_source_get(void);
-void reset_source_set_instance(enum reset_src_type type, int instance);
+const char *reset_source_name(void);
int reset_source_get_instance(void);
+
+void reset_source_set_priority(enum reset_src_type, unsigned int priority);
+void reset_source_set_instance(enum reset_src_type type, int instance);
+
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 enum reset_src_type reset_source_get(void)
{
+ return RESET_UKWN;
}
-static inline enum reset_src_type reset_source_get(void)
+static inline const char *reset_source_name(void)
{
- return RESET_UKWN;
+ return "unknown";
}
static inline int reset_source_get_instance(void)
@@ -52,14 +53,18 @@ static inline int reset_source_get_instance(void)
return -1;
}
-static inline unsigned int of_get_reset_source_priority(struct device_node *node)
+static inline void reset_source_set_priority(enum reset_src_type type,
+ unsigned int priority)
{
- return 0;
}
-static inline const char *reset_source_name(void)
+static inline void reset_source_set_instance(enum reset_src_type type, int instance)
{
- return "unknown";
+}
+
+static inline unsigned int of_get_reset_source_priority(struct device_node *node)
+{
+ return 0;
}
#endif
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 3/7] reset_source: drop reset_source_set_instance()
2019-08-25 15:58 [PATCH v2 0/7] clean up and complement reset source handling Uwe Kleine-König
2019-08-25 15:58 ` [PATCH v2 1/7] reset_source: use instance = -1 as default Uwe Kleine-König
2019-08-25 15:58 ` [PATCH v2 2/7] reset_source: fix ordering of exported functions Uwe Kleine-König
@ 2019-08-25 15:58 ` Uwe Kleine-König
2019-08-25 15:58 ` [PATCH v2 4/7] reset_source: implement helper to set a device as reset source Uwe Kleine-König
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Uwe Kleine-König @ 2019-08-25 15:58 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 | 14 ++++++++++----
4 files changed, 16 insertions(+), 20 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 f400112483a5..f32b4eac2818 100644
--- a/common/reset_source.c
+++ b/common/reset_source.c
@@ -53,26 +53,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);
-
-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);
+EXPORT_SYMBOL(reset_source_set_prinst);
static int reset_source_init(void)
{
@@ -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 85329c8cea7a..22c51a0ea674 100644
--- a/include/reset_source.h
+++ b/include/reset_source.h
@@ -31,8 +31,8 @@ enum reset_src_type reset_source_get(void);
const char *reset_source_name(void);
int reset_source_get_instance(void);
-void reset_source_set_priority(enum reset_src_type, unsigned int priority);
-void reset_source_set_instance(enum reset_src_type type, int instance);
+void reset_source_set_prinst(enum reset_src_type,
+ unsigned int priority, int instance);
unsigned int of_get_reset_source_priority(struct device_node *node);
@@ -53,8 +53,8 @@ static inline int reset_source_get_instance(void)
return -1;
}
-static inline void reset_source_set_priority(enum reset_src_type type,
- unsigned int priority)
+static inline void reset_source_set_prinst(enum reset_src_type type,
+ unsigned int priority, int instance)
{
}
@@ -70,6 +70,12 @@ static inline unsigned int of_get_reset_source_priority(struct device_node *node
#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);
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 4/7] reset_source: implement helper to set a device as reset source
2019-08-25 15:58 [PATCH v2 0/7] clean up and complement reset source handling Uwe Kleine-König
` (2 preceding siblings ...)
2019-08-25 15:58 ` [PATCH v2 3/7] reset_source: drop reset_source_set_instance() Uwe Kleine-König
@ 2019-08-25 15:58 ` Uwe Kleine-König
2019-08-25 15:58 ` [PATCH v2 5/7] mfd: da9053: use new reset_source_set_device() Uwe Kleine-König
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Uwe Kleine-König @ 2019-08-25 15:58 UTC (permalink / raw)
To: barebox
This allows to remove some boilerplate from drivers.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
common/reset_source.c | 27 +++++++++++++++++++++++++--
include/reset_source.h | 2 ++
2 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/common/reset_source.c b/common/reset_source.c
index f32b4eac2818..8fdf05215753 100644
--- a/common/reset_source.c
+++ b/common/reset_source.c
@@ -34,6 +34,7 @@ static const char * const reset_src_names[] = {
static enum reset_src_type reset_source;
static unsigned int reset_source_priority;
static int reset_source_instance;
+static struct device_d *reset_source_device;
enum reset_src_type reset_source_get(void)
{
@@ -53,8 +54,15 @@ int reset_source_get_instance(void)
}
EXPORT_SYMBOL(reset_source_get_instance);
-void reset_source_set_prinst(enum reset_src_type st,
- unsigned int priority, int instance)
+struct device_d *reset_source_get_device(void)
+{
+ return reset_source_device;
+}
+EXPORT_SYMBOL(reset_source_get_device);
+
+static void __reset_source_set(struct device_d *dev,
+ enum reset_src_type st,
+ unsigned int priority, int instance)
{
if (priority <= reset_source_priority)
return;
@@ -62,12 +70,27 @@ void reset_source_set_prinst(enum reset_src_type st,
reset_source = st;
reset_source_priority = priority;
reset_source_instance = instance;
+ reset_source_device = NULL;
pr_debug("Setting reset source to %s with priority %d\n",
reset_src_names[reset_source], priority);
}
+
+void reset_source_set_prinst(enum reset_src_type st,
+ unsigned int priority, int instance)
+{
+ __reset_source_set(NULL, st, priority, instance);
+}
EXPORT_SYMBOL(reset_source_set_prinst);
+void reset_source_set_device(struct device_d *dev, enum reset_src_type st)
+{
+ int priority = of_get_reset_source_priority(dev->device_node);
+
+ __reset_source_set(dev, st, priority, -1);
+}
+EXPORT_SYMBOL(reset_source_set_device);
+
static int reset_source_init(void)
{
globalvar_add_simple_enum("system.reset", (unsigned int *)&reset_source,
diff --git a/include/reset_source.h b/include/reset_source.h
index 22c51a0ea674..27ee077cc672 100644
--- a/include/reset_source.h
+++ b/include/reset_source.h
@@ -30,7 +30,9 @@ enum reset_src_type {
enum reset_src_type reset_source_get(void);
const char *reset_source_name(void);
int reset_source_get_instance(void);
+struct device_d *reset_source_get_device(void);
+void reset_source_set_device(struct device_d *dev, enum reset_src_type st);
void reset_source_set_prinst(enum reset_src_type,
unsigned int priority, int instance);
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 5/7] mfd: da9053: use new reset_source_set_device()
2019-08-25 15:58 [PATCH v2 0/7] clean up and complement reset source handling Uwe Kleine-König
` (3 preceding siblings ...)
2019-08-25 15:58 ` [PATCH v2 4/7] reset_source: implement helper to set a device as reset source Uwe Kleine-König
@ 2019-08-25 15:58 ` Uwe Kleine-König
2019-08-25 15:58 ` [PATCH v2 6/7] mfd: da9063: " Uwe Kleine-König
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Uwe Kleine-König @ 2019-08-25 15:58 UTC (permalink / raw)
To: barebox
Make use of the just introduced reset_source_set_device() to save some
boilerplate.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
drivers/mfd/da9053.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/mfd/da9053.c b/drivers/mfd/da9053.c
index b156bf113f46..f65f3e0bb2f9 100644
--- a/drivers/mfd/da9053.c
+++ b/drivers/mfd/da9053.c
@@ -236,9 +236,7 @@ static void da9053_detect_reset_source(struct da9053_priv *da9053)
else
return;
- priority = of_get_reset_source_priority(da9053->dev->device_node);
-
- reset_source_set_priority(type, priority);
+ reset_source_set_device(da9053->dev, ltype);
ret = da9053_reg_write(da9053, DA9053_FAULTLOG_REG, val);
if (ret < 0)
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 6/7] mfd: da9063: use new reset_source_set_device()
2019-08-25 15:58 [PATCH v2 0/7] clean up and complement reset source handling Uwe Kleine-König
` (4 preceding siblings ...)
2019-08-25 15:58 ` [PATCH v2 5/7] mfd: da9053: use new reset_source_set_device() Uwe Kleine-König
@ 2019-08-25 15:58 ` Uwe Kleine-König
2019-08-25 15:58 ` [PATCH v2 7/7] oftree: expose reset_source device in device tree Uwe Kleine-König
2019-08-28 11:34 ` [PATCH v2 0/7] clean up and complement reset source handling Sascha Hauer
7 siblings, 0 replies; 9+ messages in thread
From: Uwe Kleine-König @ 2019-08-25 15:58 UTC (permalink / raw)
To: barebox
Make use of the just introduced reset_source_set_device() to save some
boilerplate.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
drivers/mfd/da9063.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/mfd/da9063.c b/drivers/mfd/da9063.c
index a7fff2c5bfa3..e2aa9211e6b9 100644
--- a/drivers/mfd/da9063.c
+++ b/drivers/mfd/da9063.c
@@ -180,9 +180,7 @@ static void da9063_detect_reset_source(struct da9063 *priv)
else
return;
- priority = of_get_reset_source_priority(priv->dev->device_node);
-
- reset_source_set_priority(type, priority);
+ reset_source_set_device(priv->dev, type);
}
static void da9063_restart(struct restart_handler *rst)
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 7/7] oftree: expose reset_source device in device tree
2019-08-25 15:58 [PATCH v2 0/7] clean up and complement reset source handling Uwe Kleine-König
` (5 preceding siblings ...)
2019-08-25 15:58 ` [PATCH v2 6/7] mfd: da9063: " Uwe Kleine-König
@ 2019-08-25 15:58 ` Uwe Kleine-König
2019-08-28 11:34 ` [PATCH v2 0/7] clean up and complement reset source handling Sascha Hauer
7 siblings, 0 replies; 9+ messages in thread
From: Uwe Kleine-König @ 2019-08-25 15:58 UTC (permalink / raw)
To: barebox
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
common/oftree.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/common/oftree.c b/common/oftree.c
index 28a3b965ffee..09cb66021217 100644
--- a/common/oftree.c
+++ b/common/oftree.c
@@ -145,6 +145,7 @@ static int of_fixup_bootargs(struct device_node *root, void *unused)
const char *str;
int err;
int instance = reset_source_get_instance();
+ struct device_d *dev;
str = linux_bootargs_get();
if (!str)
@@ -164,6 +165,19 @@ static int of_fixup_bootargs(struct device_node *root, void *unused)
if (instance >= 0)
of_property_write_u32(node, "reset-source-instance", instance);
+
+ dev = reset_source_get_device();
+ if (dev && dev->device_node) {
+ phandle phandle;
+
+ phandle = of_node_create_phandle(dev->device_node);
+
+ err = of_property_write_u32(node,
+ "reset-source-device", phandle);
+ if (err)
+ return err;
+ }
+
return of_fixup_bootargs_bootsource(root, node);
}
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 0/7] clean up and complement reset source handling
2019-08-25 15:58 [PATCH v2 0/7] clean up and complement reset source handling Uwe Kleine-König
` (6 preceding siblings ...)
2019-08-25 15:58 ` [PATCH v2 7/7] oftree: expose reset_source device in device tree Uwe Kleine-König
@ 2019-08-28 11:34 ` Sascha Hauer
7 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2019-08-28 11:34 UTC (permalink / raw)
To: Uwe Kleine-König; +Cc: barebox
On Sun, Aug 25, 2019 at 05:58:37PM +0200, Uwe Kleine-König wrote:
> Hello,
>
> compared to the sent earlier (implicit) v1 there is a new patch to fix
> the ordering of exported functions and patched 4 to 7 add the concept of
> a reset_source device. Also v1 had some whitespace problems that are
> fixed here.
>
> Best regards
> Uwe
>
> Uwe Kleine-König (7):
> reset_source: use instance = -1 as default
> reset_source: fix ordering of exported functions
> reset_source: drop reset_source_set_instance()
> reset_source: implement helper to set a device as reset source
> mfd: da9053: use new reset_source_set_device()
> mfd: da9063: use new reset_source_set_device()
> oftree: expose reset_source device in device tree
Applied, thanks
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread