mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
To: barebox@lists.infradead.org
Subject: [PATCH 1/4] misc: add bootcount framework
Date: Sat, 21 Sep 2013 08:46:04 +0200	[thread overview]
Message-ID: <1379745967-4575-1-git-send-email-plagnioj@jcrosoft.com> (raw)
In-Reply-To: <20130921064503.GI1137@ns203013.ovh.net>

The bootcount is always how many time the system start.
To determine since when, this will depend on the driver implementation
and your hardware feature.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 drivers/misc/Kconfig            |  2 ++
 drivers/misc/Makefile           |  1 +
 drivers/misc/bootcount/Kconfig  | 12 +++++++++
 drivers/misc/bootcount/Makefile |  1 +
 drivers/misc/bootcount/core.c   | 54 +++++++++++++++++++++++++++++++++++++++++
 include/bootcount.h             | 31 +++++++++++++++++++++++
 6 files changed, 101 insertions(+)
 create mode 100644 drivers/misc/bootcount/Kconfig
 create mode 100644 drivers/misc/bootcount/Makefile
 create mode 100644 drivers/misc/bootcount/core.c
 create mode 100644 include/bootcount.h

diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 606490b..2532444 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -15,4 +15,6 @@ config JTAG
 	help
 	  Controls JTAG chains connected to I/O pins
 
+source "drivers/misc/bootcount/Kconfig"
+
 endif # MISC_DEVICES
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index b085577..6d94db0 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -3,3 +3,4 @@
 #
 
 obj-$(CONFIG_JTAG)		+= jtag.o
+obj-$(CONFIG_BOOTCOUNT)		+= bootcount/
diff --git a/drivers/misc/bootcount/Kconfig b/drivers/misc/bootcount/Kconfig
new file mode 100644
index 0000000..77a1140
--- /dev/null
+++ b/drivers/misc/bootcount/Kconfig
@@ -0,0 +1,12 @@
+#
+# Boot Count devices
+#
+
+menuconfig BOOTCOUNT
+	bool "Boot Count"
+	help
+	  Add support for boot count devices
+
+if BOOTCOUNT
+
+endif # BOOTCOUNT
diff --git a/drivers/misc/bootcount/Makefile b/drivers/misc/bootcount/Makefile
new file mode 100644
index 0000000..3c02ba1
--- /dev/null
+++ b/drivers/misc/bootcount/Makefile
@@ -0,0 +1 @@
+obj-y		+= core.o
diff --git a/drivers/misc/bootcount/core.c b/drivers/misc/bootcount/core.c
new file mode 100644
index 0000000..91274b3
--- /dev/null
+++ b/drivers/misc/bootcount/core.c
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2013 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
+ *
+ * GPLv2 Only
+ */
+
+#include <common.h>
+#include <init.h>
+#include <bootcount.h>
+
+static struct bootcount_driver *bd;
+
+static struct device_d bootcount_device = {
+	.name = "bootcount",
+	.id = DEVICE_ID_SINGLE,
+};
+
+static int bootcount_count_set(struct param_d *p, void *priv)
+{
+	struct bootcount_driver *bd = priv;
+
+	bd->set(bd);
+
+	return 0;
+}
+
+int register_bootcount(struct bootcount_driver *drv)
+{
+	if (bd)
+		return -EBUSY;
+
+	bootcount_device.parent = drv->parent;
+	register_device(&bootcount_device);
+
+	bd = drv;
+
+	bd->dev = &bootcount_device;
+	dev_add_param_int(bd->dev, "count", bootcount_count_set,
+				NULL, &bd->count, "%d", bd);
+
+	return 0;
+}
+
+static int bootcount_inc(void)
+{
+	if (!bd)
+		return 0;
+
+	bd->count++;
+	bd->set(bd);
+
+	return 0;
+}
+late_initcall(bootcount_inc);
diff --git a/include/bootcount.h b/include/bootcount.h
new file mode 100644
index 0000000..2ef36b5
--- /dev/null
+++ b/include/bootcount.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2013 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
+ *
+ * GPLv2 Only
+ */
+
+#ifndef __BOOTCOUNT_H__
+#define __BOOTCOUNT_H__
+
+#include <driver.h>
+
+struct bootcount_driver {
+	void (*set)(struct bootcount_driver *d);
+	void *priv;
+
+	int count;
+
+	struct device_d *dev;
+	struct device_d *parent;
+};
+
+#ifdef CONFIG_BOOTCOUNT
+int register_bootcount(struct bootcount_driver *d);
+#else
+static inline int register_bootcount(struct bootcount_driver *d)
+{
+	return 0
+}
+#endif
+
+#endif /* __BOOTCOUNT_H__ */
-- 
1.8.4.rc1


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

  reply	other threads:[~2013-09-21  6:45 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-21  6:45 [PATCH 0/4 v2] introduce bootcount support Jean-Christophe PLAGNIOL-VILLARD
2013-09-21  6:46 ` Jean-Christophe PLAGNIOL-VILLARD [this message]
2013-09-21  6:46   ` [PATCH 2/4] bootcount: add simple register support Jean-Christophe PLAGNIOL-VILLARD
2013-09-21  6:46   ` [PATCH 3/4] bootcount: add somfy bootcount support Jean-Christophe PLAGNIOL-VILLARD
2013-09-21  6:46   ` [PATCH 4/4] animeo_ip: add " Jean-Christophe PLAGNIOL-VILLARD
2013-09-23  7:33   ` [PATCH 1/4] misc: add bootcount framework Sascha Hauer
2013-09-23  8:05     ` Jean-Christophe PLAGNIOL-VILLARD
2013-09-23  8:52       ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1379745967-4575-1-git-send-email-plagnioj@jcrosoft.com \
    --to=plagnioj@jcrosoft.com \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox