* [PATCH] mtd: add mtdram device (which build mtd over ram area - useful for FRAM oder MRAM)
@ 2014-08-28 8:59 basti
2014-08-28 11:51 ` Alexander Aring
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: basti @ 2014-08-28 8:59 UTC (permalink / raw)
To: barebox
This adds support for MTD in RAM devices (like FRAM or MRAM).
Signed-off-by: Sebastian Block <basti@linux-source.de>
---
drivers/mtd/devices/Kconfig | 6 ++
drivers/mtd/devices/Makefile | 1 +
drivers/mtd/devices/mtdram.c | 132
++++++++++++++++++++++++++++++++++++++++++
3 files changed, 139 insertions(+)
create mode 100644 drivers/mtd/devices/mtdram.c
diff --git a/drivers/mtd/devices/Kconfig b/drivers/mtd/devices/Kconfig
index 94668a2..c512242 100644
--- a/drivers/mtd/devices/Kconfig
+++ b/drivers/mtd/devices/Kconfig
@@ -64,4 +64,10 @@ config MTD_DOCG3
M-Systems and now Sandisk. The support is very experimental,
and doesn't give access to any write operations.
+config MTD_MTDRAM
+ tristate "Provide test driver using RAM"
+ help
+ This enables a test MTD device driver which uses RAM to
+ provide storage.
+
endmenu
diff --git a/drivers/mtd/devices/Makefile b/drivers/mtd/devices/Makefile
index bf1f8a9..bc1960e 100644
--- a/drivers/mtd/devices/Makefile
+++ b/drivers/mtd/devices/Makefile
@@ -5,3 +5,4 @@
obj-$(CONFIG_MTD_DATAFLASH) += mtd_dataflash.o
obj-$(CONFIG_MTD_DOCG3) += docg3.o
obj-$(CONFIG_MTD_M25P80) += m25p80.o
+obj-$(CONFIG_MTD_MTDRAM) += mtdram.o
diff --git a/drivers/mtd/devices/mtdram.c b/drivers/mtd/devices/mtdram.c
new file mode 100644
index 0000000..bd0bbb4
--- /dev/null
+++ b/drivers/mtd/devices/mtdram.c
@@ -0,0 +1,132 @@
+/*
+ * MTD RAM driver - a mtd test device driver
+ *
+ * Author: Sebastian Block <basti@linux-source.de>
+ * Copyright (c) 2014
+ *
+ * Some parts are based on mtdram.c found in Linux kernel
+ * by Alexander Larsson <alex@cendio.se>
+ * and Joern Engel <joern@wh.fh-wedel.de>.
+ *
+ * This code is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+#include <common.h>
+#include <environment.h>
+#include <errno.h>
+#include <init.h>
+#include <io.h>
+#include <linux/mtd/mtd.h>
+#include <malloc.h>
+#include <of.h>
+
+struct mtdram_priv_data {
+ struct mtd_info mtd;
+ void *base;
+};
+
+static int ram_erase(struct mtd_info *mtd, struct erase_info *instr) {
+ memset((char *)mtd->priv + instr->addr, 0xff, instr->len);
+ instr->state = MTD_ERASE_DONE;
+ mtd_erase_callback(instr);
+ return 0;
+}
+
+static int ram_write(struct mtd_info *mtd, loff_t to, size_t len,
+ size_t *retlen, const u_char *buf) {
+ memcpy((char*)mtd->priv + to, buf, len);
+ *retlen = len;
+ return 0;
+}
+
+static int ram_read(struct mtd_info *mtd, loff_t from, size_t len,
+ size_t *retlen, u_char *buf) {
+ memcpy(buf, mtd->priv + from, len);
+ *retlen = len;
+ return 0;
+}
+
+static int mtdram_probe(struct device_d *dev) {
+ void __iomem *base;
+ int device_id;
+ struct mtd_info *mtd;
+ struct resource *res;
+ loff_t size;
+ int ret = 0;
+
+
+ mtd = kzalloc(sizeof(struct mtd_info), GFP_KERNEL);
+ if (!mtd) {
+ ret = -ENOMEM;
+ goto nomem1;
+ }
+
+ device_id = DEVICE_ID_SINGLE;
+ if (dev->device_node) {
+ const char *alias = of_alias_get(dev->device_node);
+ dev_info (dev, "is alias for %s\n", alias);
+ if (alias)
+ mtd->name = xstrdup(alias);
+ }
+
+ if (!mtd->name) {
+ device_id = DEVICE_ID_DYNAMIC;
+ mtd->name = "mtdram";
+ }
+
+ dev_info(dev, "MTDRAM: probe for %s (dev_name=%s)\n", dev->name,
mtd->name);
+
+ base = dev_request_mem_region(dev, 0);
+ if (!base) {
+ ret = -EBUSY;
+ goto nobase;
+ }
+
+ res = dev_get_resource(dev, IORESOURCE_MEM, 0);
+ size = (unsigned long) resource_size(res);
+ mtd->priv = base;
+
+ mtd->type = MTD_RAM;
+ mtd->writesize = 1;
+ mtd->writebufsize = 64;
+ mtd->flags = MTD_CAP_RAM;
+ mtd->size = size;
+
+ mtd->read = ram_read;
+ mtd->write = ram_write;
+ mtd->erase = ram_erase;
+ mtd->erasesize = 1;
+
+ mtd->parent = dev;
+
+ dev_info(dev, "add MTDRAM with size=%llx @%p\n", mtd->size,
mtd->priv);
+ ret = add_mtd_device(mtd, mtd->name, device_id);
+ dev_info(dev, "MTDRAM: add_mtd_dev ret: %d\n", ret);
+ return ret;
+
+nobase:
+ kfree(mtd);
+nomem1:
+ return ret;
+}
+
+static __maybe_unused struct of_device_id mtdram_dt_ids[] = {
+ {
+ .compatible = "mtd-ram",
+ }, {
+ /* sentinel */
+ }
+};
+
+static struct driver_d mtdram_driver = {
+ .name = "mtdram",
+ .probe = mtdram_probe,
+ .of_compatible = DRV_OF_COMPAT(mtdram_dt_ids),
+};
+device_platform_driver(mtdram_driver);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Sebastian Block");
+MODULE_DESCRIPTION("MTD RAM test driver");
--
1.7.10.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] mtd: add mtdram device (which build mtd over ram area - useful for FRAM oder MRAM)
2014-08-28 8:59 [PATCH] mtd: add mtdram device (which build mtd over ram area - useful for FRAM oder MRAM) basti
@ 2014-08-28 11:51 ` Alexander Aring
2014-08-28 11:58 ` Alexander Aring
2014-09-01 8:06 ` Sascha Hauer
2 siblings, 0 replies; 6+ messages in thread
From: Alexander Aring @ 2014-08-28 11:51 UTC (permalink / raw)
To: basti; +Cc: barebox
Hi Sebastian,
On Thu, Aug 28, 2014 at 10:59:51AM +0200, basti@linux-source.de wrote:
> This adds support for MTD in RAM devices (like FRAM or MRAM).
>
> Signed-off-by: Sebastian Block <basti@linux-source.de>
>
for what do you need something like this?
If for testing I thought about to porting nandsim to barebox [0].
I was only a RFC and I forget to bring this mainline, because I can't
validate that the nandsim behaviour is correct.
- Alex
[0] http://lists.infradead.org/pipermail/barebox/2012-October/010817.html
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] mtd: add mtdram device (which build mtd over ram area - useful for FRAM oder MRAM)
2014-08-28 8:59 [PATCH] mtd: add mtdram device (which build mtd over ram area - useful for FRAM oder MRAM) basti
2014-08-28 11:51 ` Alexander Aring
@ 2014-08-28 11:58 ` Alexander Aring
2014-09-01 8:06 ` Sascha Hauer
2 siblings, 0 replies; 6+ messages in thread
From: Alexander Aring @ 2014-08-28 11:58 UTC (permalink / raw)
To: basti; +Cc: barebox
On Thu, Aug 28, 2014 at 10:59:51AM +0200, basti@linux-source.de wrote:
> This adds support for MTD in RAM devices (like FRAM or MRAM).
ah, non volatile memory. Okay. :-)
- Alex
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] mtd: add mtdram device (which build mtd over ram area - useful for FRAM oder MRAM)
2014-08-28 8:59 [PATCH] mtd: add mtdram device (which build mtd over ram area - useful for FRAM oder MRAM) basti
2014-08-28 11:51 ` Alexander Aring
2014-08-28 11:58 ` Alexander Aring
@ 2014-09-01 8:06 ` Sascha Hauer
2014-09-06 11:21 ` [PATCH v2] " Sebastian Block
2 siblings, 1 reply; 6+ messages in thread
From: Sascha Hauer @ 2014-09-01 8:06 UTC (permalink / raw)
To: basti; +Cc: barebox
Hi Sebastian,
On Thu, Aug 28, 2014 at 10:59:51AM +0200, basti@linux-source.de wrote:
> This adds support for MTD in RAM devices (like FRAM or MRAM).
>
> Signed-off-by: Sebastian Block <basti@linux-source.de>
>
> ---
> drivers/mtd/devices/Kconfig | 6 ++
> drivers/mtd/devices/Makefile | 1 +
> drivers/mtd/devices/mtdram.c | 132
> ++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 139 insertions(+)
> create mode 100644 drivers/mtd/devices/mtdram.c
>
> diff --git a/drivers/mtd/devices/Kconfig b/drivers/mtd/devices/Kconfig
> index 94668a2..c512242 100644
> --- a/drivers/mtd/devices/Kconfig
> +++ b/drivers/mtd/devices/Kconfig
> @@ -64,4 +64,10 @@ config MTD_DOCG3
> M-Systems and now Sandisk. The support is very experimental,
> and doesn't give access to any write operations.
>
> +config MTD_MTDRAM
> + tristate "Provide test driver using RAM"
This description is probably directly takes from the Kernel. I think
something like "driver for memory mapped MRAM/FRAM" would be more
appropriate.
> new file mode 100644
> index 0000000..bd0bbb4
> --- /dev/null
> +++ b/drivers/mtd/devices/mtdram.c
> @@ -0,0 +1,132 @@
> +/*
> + * MTD RAM driver - a mtd test device driver
> + *
> + * Author: Sebastian Block <basti@linux-source.de>
> + * Copyright (c) 2014
> + *
> + * Some parts are based on mtdram.c found in Linux kernel
> + * by Alexander Larsson <alex@cendio.se>
> + * and Joern Engel <joern@wh.fh-wedel.de>.
> + *
> + * This code is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + *
> + */
> +#include <common.h>
> +#include <environment.h>
> +#include <errno.h>
> +#include <init.h>
> +#include <io.h>
> +#include <linux/mtd/mtd.h>
> +#include <malloc.h>
> +#include <of.h>
> +
> +struct mtdram_priv_data {
> + struct mtd_info mtd;
> + void *base;
> +};
> +
> +static int ram_erase(struct mtd_info *mtd, struct erase_info *instr) {
The coding style is to have the opening brace separately on a new line.
> + memset((char *)mtd->priv + instr->addr, 0xff, instr->len);
> + instr->state = MTD_ERASE_DONE;
> + mtd_erase_callback(instr);
> + return 0;
> +}
> +
> +static int ram_write(struct mtd_info *mtd, loff_t to, size_t len,
> + size_t *retlen, const u_char *buf) {
> + memcpy((char*)mtd->priv + to, buf, len);
> + *retlen = len;
> + return 0;
> +}
> +
> +static int ram_read(struct mtd_info *mtd, loff_t from, size_t len,
> + size_t *retlen, u_char *buf) {
> + memcpy(buf, mtd->priv + from, len);
> + *retlen = len;
> + return 0;
> +}
> +
> +static int mtdram_probe(struct device_d *dev) {
> + void __iomem *base;
> + int device_id;
> + struct mtd_info *mtd;
> + struct resource *res;
> + loff_t size;
> + int ret = 0;
> +
> +
> + mtd = kzalloc(sizeof(struct mtd_info), GFP_KERNEL);
> + if (!mtd) {
> + ret = -ENOMEM;
> + goto nomem1;
> + }
You could use xzalloc here and skip the return check.
> +
> + device_id = DEVICE_ID_SINGLE;
> + if (dev->device_node) {
> + const char *alias = of_alias_get(dev->device_node);
> + dev_info (dev, "is alias for %s\n", alias);
> + if (alias)
> + mtd->name = xstrdup(alias);
> + }
> +
> + if (!mtd->name) {
> + device_id = DEVICE_ID_DYNAMIC;
> + mtd->name = "mtdram";
> + }
> +
> + dev_info(dev, "MTDRAM: probe for %s (dev_name=%s)\n",
> dev->name, mtd->name);
Your mailer wraps the lines. Can you change that? I won't be able to
apply this patch otherwise.
The driver seems a bit verbose. Can you limit the information printed in
the normal case to a single line?
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2] mtd: add mtdram device (which build mtd over ram area - useful for FRAM oder MRAM)
2014-09-01 8:06 ` Sascha Hauer
@ 2014-09-06 11:21 ` Sebastian Block
2014-09-08 6:23 ` Sascha Hauer
0 siblings, 1 reply; 6+ messages in thread
From: Sebastian Block @ 2014-09-06 11:21 UTC (permalink / raw)
To: barebox
Change since v1 (Sascha, thanks for review):
* use xzalloc instead of kzalloc and control check
* correct help and names
* fix coding style issue
* remove verbose and unneeded messages
This adds support for MTD in RAM devices (like FRAM or MRAM).
Signed-off-by: Sebastian Block <basti@linux-source.de>
---
drivers/mtd/devices/Kconfig | 5 ++
drivers/mtd/devices/Makefile | 1 +
drivers/mtd/devices/mtdram.c | 124 +++++++++++++++++++++++++++++++++++++++++++
3 files changed, 130 insertions(+)
create mode 100644 drivers/mtd/devices/mtdram.c
diff --git a/drivers/mtd/devices/Kconfig b/drivers/mtd/devices/Kconfig
index 61278a2..7f9c306 100644
--- a/drivers/mtd/devices/Kconfig
+++ b/drivers/mtd/devices/Kconfig
@@ -58,4 +58,9 @@ config MTD_DOCG3
M-Systems and now Sandisk. The support is very experimental,
and doesn't give access to any write operations.
+config MTD_MTDRAM
+ tristate "Support for NVRAM devices (FRAM, MRAM, ...)"
+ help
+ This enables non volatile RAM to used as MTD devices.
+
endmenu
diff --git a/drivers/mtd/devices/Makefile b/drivers/mtd/devices/Makefile
index bf1f8a9..bc1960e 100644
--- a/drivers/mtd/devices/Makefile
+++ b/drivers/mtd/devices/Makefile
@@ -5,3 +5,4 @@
obj-$(CONFIG_MTD_DATAFLASH) += mtd_dataflash.o
obj-$(CONFIG_MTD_DOCG3) += docg3.o
obj-$(CONFIG_MTD_M25P80) += m25p80.o
+obj-$(CONFIG_MTD_MTDRAM) += mtdram.o
diff --git a/drivers/mtd/devices/mtdram.c b/drivers/mtd/devices/mtdram.c
new file mode 100644
index 0000000..47c5ad7
--- /dev/null
+++ b/drivers/mtd/devices/mtdram.c
+ *
+ * Author: Sebastian Block <basti@linux-source.de>
+ * Copyright (c) 2014
+ *
+ * Some parts are based on mtdram.c found in Linux kernel
+ * by Alexander Larsson <alex@cendio.se>
+ * and Joern Engel <joern@wh.fh-wedel.de>.
+ *
+ * This code is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+#include <common.h>
+#include <environment.h>
+#include <errno.h>
+#include <init.h>
+#include <io.h>
+#include <linux/mtd/mtd.h>
+#include <malloc.h>
+#include <of.h>
+
+struct mtdram_priv_data {
+ struct mtd_info mtd;
+ void *base;
+};
+
+static int ram_erase(struct mtd_info *mtd, struct erase_info *instr)
+{
+ memset((char *)mtd->priv + instr->addr, 0xff, instr->len);
+ instr->state = MTD_ERASE_DONE;
+ mtd_erase_callback(instr);
+ return 0;
+}
+
+static int ram_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf)
+{
+ memcpy((char*)mtd->priv + to, buf, len);
+ *retlen = len;
+ return 0;
+}
+
+static int ram_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf)
+{
+ memcpy(buf, mtd->priv + from, len);
+ *retlen = len;
+ return 0;
+}
+
+static int mtdram_probe(struct device_d *dev)
+{
+ void __iomem *base;
+ int device_id;
+ struct mtd_info *mtd;
+ struct resource *res;
+ loff_t size;
+ int ret = 0;
+
+ mtd = xzalloc(sizeof(struct mtd_info), GFP_KERNEL);
+
+ device_id = DEVICE_ID_SINGLE;
+ if (dev->device_node) {
+ const char *alias = of_alias_get(dev->device_node);
+ if (alias)
+ mtd->name = xstrdup(alias);
+ }
+
+ if (!mtd->name) {
+ device_id = DEVICE_ID_DYNAMIC;
+ mtd->name = "mtdram";
+ }
+
+ base = dev_request_mem_region(dev, 0);
+ if (!base) {
+ ret = -EBUSY;
+ goto nobase;
+ }
+
+ res = dev_get_resource(dev, IORESOURCE_MEM, 0);
+ size = (unsigned long) resource_size(res);
+ mtd->priv = base;
+
+ mtd->type = MTD_RAM;
+ mtd->writesize = 1;
+ mtd->writebufsize = 64;
+ mtd->flags = MTD_CAP_RAM;
+ mtd->size = size;
+
+ mtd->read = ram_read;
+ mtd->write = ram_write;
+ mtd->erase = ram_erase;
+ mtd->erasesize = 1;
+
+ mtd->parent = dev;
+
+ ret = add_mtd_device(mtd, mtd->name, device_id);
+ return ret;
+
+nobase:
+ kfree(mtd);
+nomem1:
+ return ret;
+}
+
+static __maybe_unused struct of_device_id mtdram_dt_ids[] = {
+ {
+ .compatible = "mtd-ram",
+ }, {
+ /* sentinel */
+ }
+};
+
+static struct driver_d mtdram_driver = {
+ .name = "mtdram",
+ .probe = mtdram_probe,
+ .of_compatible = DRV_OF_COMPAT(mtdram_dt_ids),
+};
+device_platform_driver(mtdram_driver);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Sebastian Block");
+MODULE_DESCRIPTION("MTD RAM driver for NVRAMs");
--
1.9.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] mtd: add mtdram device (which build mtd over ram area - useful for FRAM oder MRAM)
2014-09-06 11:21 ` [PATCH v2] " Sebastian Block
@ 2014-09-08 6:23 ` Sascha Hauer
0 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2014-09-08 6:23 UTC (permalink / raw)
To: Sebastian Block; +Cc: barebox
On Sat, Sep 06, 2014 at 01:21:03PM +0200, Sebastian Block wrote:
> Change since v1 (Sascha, thanks for review):
> * use xzalloc instead of kzalloc and control check
> * correct help and names
> * fix coding style issue
> * remove verbose and unneeded messages
>
> This adds support for MTD in RAM devices (like FRAM or MRAM).
>
> Signed-off-by: Sebastian Block <basti@linux-source.de>
Your patch has several trailing whitespaces. Please remove them next
time.
> diff --git a/drivers/mtd/devices/mtdram.c b/drivers/mtd/devices/mtdram.c
> new file mode 100644
> index 0000000..47c5ad7
> --- /dev/null
> +++ b/drivers/mtd/devices/mtdram.c
> + *
Strange. the initial '/' introducing the comment is missing here. Also
git-am ended up creating an empty file. How did you generate/send this
patch?
> +static int mtdram_probe(struct device_d *dev)
> +{
> + void __iomem *base;
> + int device_id;
> + struct mtd_info *mtd;
> + struct resource *res;
> + loff_t size;
> + int ret = 0;
> +
> + mtd = xzalloc(sizeof(struct mtd_info), GFP_KERNEL);
xzalloc takes only one argument. Please compile test your patches before
sending them.
Anyway, fixed this up this time and applied.
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-09-08 6:23 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-28 8:59 [PATCH] mtd: add mtdram device (which build mtd over ram area - useful for FRAM oder MRAM) basti
2014-08-28 11:51 ` Alexander Aring
2014-08-28 11:58 ` Alexander Aring
2014-09-01 8:06 ` Sascha Hauer
2014-09-06 11:21 ` [PATCH v2] " Sebastian Block
2014-09-08 6:23 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox