[PATCH v2 4/7] reset_source: implement helper to set a device as reset source

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This allows to remove some boilerplate from drivers.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@xxxxxxxxxxxxxx>
---
 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@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox




[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux