mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Robert Jarzmik <robert.jarzmik@free.fr>
To: barebox@lists.infradead.org
Subject: [PATCH V3 6/8] drivers/mtd: add mtd core hooks
Date: Mon, 19 Dec 2011 15:04:07 +0100	[thread overview]
Message-ID: <1324303449-30045-7-git-send-email-robert.jarzmik@free.fr> (raw)
In-Reply-To: <1324303449-30045-1-git-send-email-robert.jarzmik@free.fr>

Add hooks for spinoff MTD drivers (mtdoob, mtdraw, ...).

Signed-off-by: Robert Jarzmik <robert.jarzmik@free.fr>
---
 drivers/mtd/core.c |   17 +++++++++++++++++
 drivers/mtd/mtd.h  |   39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+), 0 deletions(-)
 create mode 100644 drivers/mtd/mtd.h

diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c
index 8611d02..a3cea33 100644
--- a/drivers/mtd/core.c
+++ b/drivers/mtd/core.c
@@ -26,6 +26,10 @@
 #include <nand.h>
 #include <errno.h>
 
+#include "mtd.h"
+
+static LIST_HEAD(mtd_register_hooks);
+
 static 	ssize_t mtd_read(struct cdev *cdev, void* buf, size_t count,
 			  ulong offset, ulong flags)
 {
@@ -250,6 +254,7 @@ static void mtd_exit_oob_cdev(struct mtd_info *mtd)
 int add_mtd_device(struct mtd_info *mtd, char *devname)
 {
 	char str[16];
+	struct mtddev_hook *hook;
 
 	if (!devname)
 		devname = "mtd";
@@ -276,12 +281,20 @@ int add_mtd_device(struct mtd_info *mtd, char *devname)
 	devfs_create(&mtd->cdev);
 
 	mtd_init_oob_cdev(mtd, devname);
+	list_for_each_entry(hook, &mtd_register_hooks, hook)
+		if (hook->add_mtd_device)
+			hook->add_mtd_device(mtd, devname);
 
 	return 0;
 }
 
 int del_mtd_device (struct mtd_info *mtd)
 {
+	struct mtddev_hook *hook;
+
+	list_for_each_entry(hook, &mtd_register_hooks, hook)
+		if (hook->del_mtd_device)
+			hook->del_mtd_device(mtd);
 	unregister_device(&mtd->class_dev);
 	mtd_exit_oob_cdev(mtd);
 	free(mtd->param_size.value);
@@ -289,3 +302,7 @@ int del_mtd_device (struct mtd_info *mtd)
 	return 0;
 }
 
+void mtdcore_add_hook(struct mtddev_hook *hook)
+{
+	list_add(&hook->hook, &mtd_register_hooks);
+}
diff --git a/drivers/mtd/mtd.h b/drivers/mtd/mtd.h
new file mode 100644
index 0000000..261cd2b
--- /dev/null
+++ b/drivers/mtd/mtd.h
@@ -0,0 +1,39 @@
+/*
+ * MTD devices registration
+ *
+ * Copyright (C) 2011 Robert Jarzmik
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+/**
+ * mtddev_hook - hook to register additional mtd devices
+ * @add_mtd_device: called when a MTD driver calls add_mtd_device()
+ * @del_mtd_device: called when a MTD driver calls del_mtd_device()
+ *
+ * Provide a hook to be called whenether a add_mtd_device() is called.
+ * Additionnal devices like mtdoob and mtdraw subscribe to the service.
+ */
+struct mtddev_hook {
+	struct list_head hook;
+	int (*add_mtd_device)(struct mtd_info *mtd, char *devname);
+	int (*del_mtd_device)(struct mtd_info *mtd);
+};
+
+/**
+ * mtdcore_add_hook - add a hook to MTD registration/unregistration
+ * @hook: the hook
+ *
+ * Normally called in a coredevice_initcall() to add another MTD layout (such as
+ * mtdraw, ...)
+ */
+void mtdcore_add_hook(struct mtddev_hook *hook);
-- 
1.7.5.4


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

  parent reply	other threads:[~2011-12-19 14:04 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-19 14:04 [PATCH V3 0/8] mtd framework rework Robert Jarzmik
2011-12-19 14:04 ` [PATCH V3 1/8] drivers/mtd: move nand.c into core.c Robert Jarzmik
2011-12-19 14:04 ` [PATCH V3 2/8] drivers/mtd: cosmetic changes Robert Jarzmik
2011-12-21 11:00   ` Sascha Hauer
2011-12-21 21:27     ` Robert Jarzmik
2011-12-19 14:04 ` [PATCH V3 3/8] drivers/mtd: transfer NAND notions to MTD core Robert Jarzmik
2011-12-21 11:25   ` Sascha Hauer
2011-12-19 14:04 ` [PATCH V3 4/8] drivers/mtd: recover NAND default device name "nand" Robert Jarzmik
2011-12-19 14:04 ` [PATCH V3 5/8] drivers/mtd: fix core multiple MTD registrations Robert Jarzmik
2011-12-19 14:04 ` Robert Jarzmik [this message]
2011-12-19 14:04 ` [PATCH V3 7/8] drivers/mtd: split mtd mtdoob devices Robert Jarzmik
2011-12-21 11:32   ` Sascha Hauer
2011-12-21 21:28     ` Robert Jarzmik
2011-12-19 14:04 ` [PATCH V3 8/8] drivers/mtd: add the mtdraw device (data+oob) Robert Jarzmik
2011-12-21 10:59 ` [PATCH V3 0/8] mtd framework rework 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=1324303449-30045-7-git-send-email-robert.jarzmik@free.fr \
    --to=robert.jarzmik@free.fr \
    --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