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 V4 6/7] drivers/mtd: split mtd mtdoob devices
Date: Wed, 21 Dec 2011 22:30:43 +0100	[thread overview]
Message-ID: <1324503044-6085-6-git-send-email-robert.jarzmik@free.fr> (raw)
In-Reply-To: <1324503044-6085-1-git-send-email-robert.jarzmik@free.fr>

Split /dev/mtd and /dev/mtdoob devices.
Remove from mtd structure the mtdoob character device.

Signed-off-by: Robert Jarzmik <robert.jarzmik@free.fr>

---
Since V1:
 - fix Sascha name
 - rebase on the NAND_READ_OOB / NAND_DEVICE_OOB change
Since V3:
 - add missing mtdoob->mtd initialization
---
 drivers/mtd/Kconfig      |    3 +-
 drivers/mtd/Makefile     |    3 +-
 drivers/mtd/core.c       |   65 +------------------------------
 drivers/mtd/mtd.h        |    3 +
 drivers/mtd/mtdoob.c     |   97 ++++++++++++++++++++++++++++++++++++++++++++++
 drivers/mtd/nand/Kconfig |    6 ---
 include/linux/mtd/mtd.h  |    1 -
 7 files changed, 105 insertions(+), 73 deletions(-)
 create mode 100644 drivers/mtd/mtdoob.c

diff --git a/drivers/mtd/Kconfig b/drivers/mtd/Kconfig
index 81282ab..a130c74 100644
--- a/drivers/mtd/Kconfig
+++ b/drivers/mtd/Kconfig
@@ -8,8 +8,9 @@ config MTD_WRITE
 	default y
 	prompt "Support writing to MTD devices"
 
-config MTD_READ_OOB
+config MTD_OOB_DEVICE
 	bool
+	select NAND_READ_OOB
 	default y
 	prompt "Create a device for reading the OOB data"
 
diff --git a/drivers/mtd/Makefile b/drivers/mtd/Makefile
index 80fe386..d41ffd4 100644
--- a/drivers/mtd/Makefile
+++ b/drivers/mtd/Makefile
@@ -1,4 +1,5 @@
 obj-$(CONFIG_NAND)	+= nand/
 obj-$(CONFIG_UBI)	+= ubi/
 obj-$(CONFIG_PARTITION_NEED_MTD)	+= partition.o
-obj-$(CONFIG_MTD)	+= core.o
+obj-$(CONFIG_MTD)			+= core.o
+obj-$(CONFIG_MTD_OOB_DEVICE)		+= mtdoob.o
diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c
index fc36c1d..55d845d 100644
--- a/drivers/mtd/core.c
+++ b/drivers/mtd/core.c
@@ -114,7 +114,7 @@ out:
 }
 #endif
 
-static int mtd_ioctl(struct cdev *cdev, int request, void *buf)
+int mtd_ioctl(struct cdev *cdev, int request, void *buf)
 {
 	struct mtd_info *mtd = cdev->priv;
 	struct mtd_info_user *user = buf;
@@ -186,67 +186,6 @@ static struct file_operations mtd_ops = {
 	.lseek  = dev_lseek_default,
 };
 
-#ifdef CONFIG_NAND_OOB_DEVICE
-static ssize_t mtd_read_oob(struct cdev *cdev, void *buf, size_t count,
-			    ulong offset, ulong flags)
-{
-	struct mtd_info *mtd = cdev->priv;
-	struct mtd_oob_ops ops;
-	int ret;
-
-	if (count < mtd->oobsize)
-		return -EINVAL;
-
-	ops.mode = MTD_OOB_RAW;
-	ops.ooboffs = 0;
-	ops.ooblen = mtd->oobsize;
-	ops.oobbuf = buf;
-	ops.datbuf = NULL;
-	ops.len = mtd->oobsize;
-
-	offset /= mtd->oobsize;
-	ret = mtd->read_oob(mtd, offset * mtd->writesize, &ops);
-	if (ret)
-		return ret;
-
-	return mtd->oobsize;
-}
-
-static struct file_operations mtd_ops_oob = {
-	.read   = mtd_read_oob,
-	.ioctl  = mtd_ioctl,
-	.lseek  = dev_lseek_default,
-};
-
-static int mtd_init_oob_cdev(struct mtd_info *mtd, char *devname)
-{
-	mtd->cdev_oob.ops = &mtd_ops_oob;
-	mtd->cdev_oob.size = (mtd->size / mtd->writesize) * mtd->oobsize;
-	mtd->cdev_oob.name = asprintf("%s_oob%d", devname, mtd->class_dev.id);
-	mtd->cdev_oob.priv = mtd;
-	mtd->cdev_oob.dev = &mtd->class_dev;
-	devfs_create(&mtd->cdev_oob);
-
-	return 0;
-}
-
-static void mtd_exit_oob_cdev(struct mtd_info *mtd)
-{
-	free(mtd->cdev_oob.name);
-}
-#else
-
-static int mtd_init_oob_cdev(struct mtd_info *mtd, char *devname)
-{
-	return 0;
-}
-
-static void mtd_exit_oob_cdev(struct mtd_info *mtd)
-{
-	return;
-}
-#endif
-
 int add_mtd_device(struct mtd_info *mtd, char *devname)
 {
 	char str[16];
@@ -276,7 +215,6 @@ 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);
@@ -292,7 +230,6 @@ int del_mtd_device (struct mtd_info *mtd)
 		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);
 	free(mtd->cdev.name);
 	return 0;
diff --git a/drivers/mtd/mtd.h b/drivers/mtd/mtd.h
index 261cd2b..c8af6e3 100644
--- a/drivers/mtd/mtd.h
+++ b/drivers/mtd/mtd.h
@@ -28,6 +28,7 @@ struct mtddev_hook {
 	int (*add_mtd_device)(struct mtd_info *mtd, char *devname);
 	int (*del_mtd_device)(struct mtd_info *mtd);
 };
+struct cdev;
 
 /**
  * mtdcore_add_hook - add a hook to MTD registration/unregistration
@@ -37,3 +38,5 @@ struct mtddev_hook {
  * mtdraw, ...)
  */
 void mtdcore_add_hook(struct mtddev_hook *hook);
+
+int mtd_ioctl(struct cdev *cdev, int request, void *buf);
diff --git a/drivers/mtd/mtdoob.c b/drivers/mtd/mtdoob.c
new file mode 100644
index 0000000..be656a4
--- /dev/null
+++ b/drivers/mtd/mtdoob.c
@@ -0,0 +1,97 @@
+/*
+ * MTD oob device
+ *
+ * Copyright (C) 2011 Sascha Hauer
+ *
+ * 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.
+ *
+ * Adds a character devices :
+ *  - mtdoob<N>
+ */
+
+#include <common.h>
+#include <init.h>
+#include <malloc.h>
+#include <ioctl.h>
+#include <errno.h>
+#include <linux/mtd/mtd.h>
+
+#include "mtd.h"
+
+struct mtdoob {
+	struct cdev cdev;
+	struct mtd_info *mtd;
+};
+
+static struct mtd_info *to_mtd(struct cdev *cdev)
+{
+	struct mtdoob *mtdoob = cdev->priv;
+	return mtdoob->mtd;
+}
+
+static ssize_t mtd_read_oob(struct cdev *cdev, void *buf, size_t count,
+			     ulong offset, ulong flags)
+{
+	struct mtd_info *mtd = to_mtd(cdev);
+	struct mtd_oob_ops ops;
+	int ret;
+
+	if (count < mtd->oobsize)
+		return -EINVAL;
+
+	ops.mode = MTD_OOB_RAW;
+	ops.ooboffs = 0;
+	ops.ooblen = mtd->oobsize;
+	ops.oobbuf = buf;
+	ops.datbuf = NULL;
+	ops.len = mtd->oobsize;
+
+	offset /= mtd->oobsize;
+	ret = mtd->read_oob(mtd, offset * mtd->writesize, &ops);
+	if (ret)
+		return ret;
+
+	return mtd->oobsize;
+}
+
+static struct file_operations mtd_ops_oob = {
+	.read   = mtd_read_oob,
+	.ioctl  = mtd_ioctl,
+	.lseek  = dev_lseek_default,
+};
+
+static int add_mtdoob_device(struct mtd_info *mtd, char *devname)
+{
+	struct mtdoob *mtdoob;
+
+	mtdoob = xzalloc(sizeof(*mtdoob));
+	mtdoob->cdev.ops = &mtd_ops_oob;
+	mtdoob->cdev.size = (mtd->size / mtd->writesize) * mtd->oobsize;
+	mtdoob->cdev.name = asprintf("%s_oob%d", devname, mtd->class_dev.id);
+	mtdoob->cdev.priv = mtdoob;
+	mtdoob->cdev.dev = &mtd->class_dev;
+	mtdoob->mtd = mtd;
+	devfs_create(&mtdoob->cdev);
+
+	return 0;
+}
+
+static struct mtddev_hook mtdoob_hook = {
+	.add_mtd_device = add_mtdoob_device,
+};
+
+static int __init register_mtdoob(void)
+{
+	mtdcore_add_hook(&mtdoob_hook);
+	return 0;
+}
+
+coredevice_initcall(register_mtdoob);
diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
index b6e38ff..bda0529 100644
--- a/drivers/mtd/nand/Kconfig
+++ b/drivers/mtd/nand/Kconfig
@@ -48,12 +48,6 @@ config NAND_BBT
 	  Say y here to include support for bad block tables. This speeds
 	  up the process of checking for bad blocks
 
-config NAND_OOB_DEVICE
-	bool
-	select NAND_READ_OOB
-	default y
-	prompt "create a device for reading the OOB data"
-
 config NAND_IMX
 	bool
 	prompt "i.MX NAND driver"
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index a985c30..71d3c6f 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -202,7 +202,6 @@ struct mtd_info {
 	struct device_d class_dev;
 	struct device_d *dev;
 	struct cdev cdev;
-	struct cdev cdev_oob;
 
 	struct param_d param_size;
 	char *size_str;
-- 
1.7.5.4


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

  parent reply	other threads:[~2011-12-21 21:31 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-21 21:30 [PATCH V4 1/7] drivers/mtd: move nand.c into core.c Robert Jarzmik
2011-12-21 21:30 ` [PATCH V4 2/7] drivers/mtd: cosmetic changes Robert Jarzmik
2011-12-21 21:30 ` [PATCH V4 3/7] drivers/mtd: transfer NAND notions to MTD core Robert Jarzmik
2011-12-21 21:30 ` [PATCH V4 4/7] drivers/mtd: fix core multiple MTD registrations Robert Jarzmik
2011-12-21 21:30 ` [PATCH V4 5/7] drivers/mtd: add mtd core hooks Robert Jarzmik
2011-12-21 21:30 ` Robert Jarzmik [this message]
2011-12-21 21:30 ` [PATCH V4 7/7] drivers/mtd: add the mtdraw device (data+oob) Robert Jarzmik
2011-12-22  9:18 ` [PATCH V4 1/7] drivers/mtd: move nand.c into core.c Sascha Hauer
2011-12-22 10:05   ` Robert Jarzmik
2011-12-31  8:29 ` Jean-Christophe PLAGNIOL-VILLARD
2011-12-31 13:43   ` Robert Jarzmik
2011-12-31 14:13     ` Jean-Christophe PLAGNIOL-VILLARD
2012-01-02 11:53       ` Sascha Hauer
2012-01-03  8:00         ` Jean-Christophe PLAGNIOL-VILLARD

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=1324503044-6085-6-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