summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>2019-08-25 17:58:41 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2019-08-28 13:33:42 +0200
commita0748840c104a3ea9af5e9e27741541e526edbd5 (patch)
treea8d3f2a817af5ef16b633cda6e74b9d3fe23c062
parent935446094311ccbc6888dc2dbe238b764a8e073e (diff)
downloadbarebox-a0748840c104a3ea9af5e9e27741541e526edbd5.tar.gz
reset_source: implement helper to set a device as reset source
This allows to remove some boilerplate from drivers. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--common/reset_source.c27
-rw-r--r--include/reset_source.h2
2 files changed, 27 insertions, 2 deletions
diff --git a/common/reset_source.c b/common/reset_source.c
index f32b4ea..8fdf052 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 22c51a0..27ee077 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);