mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] mtd: mtdram: discard superfluous code
@ 2022-02-07  7:56 Ahmad Fatoum
  2022-02-07  7:56 ` [PATCH 2/2] mtd: mtdram: add physically mapped ROM (mtd-rom) support Ahmad Fatoum
  2022-02-07  8:11 ` [PATCH 1/2] mtd: mtdram: discard superfluous code Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2022-02-07  7:56 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

We don't need to get the exact same resource, we just requested.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/mtd/devices/mtdram.c | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)

diff --git a/drivers/mtd/devices/mtdram.c b/drivers/mtd/devices/mtdram.c
index ee1cbf792dbb..c9371b16d0f5 100644
--- a/drivers/mtd/devices/mtdram.c
+++ b/drivers/mtd/devices/mtdram.c
@@ -16,11 +16,6 @@
 #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);
@@ -44,10 +39,8 @@ static int ram_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retle
 static int mtdram_probe(struct device_d *dev)
 {
 	struct resource *iores;
-	void __iomem *base;
 	int device_id;
 	struct mtd_info *mtd;
-	struct resource *res;
 	loff_t size;
 	int ret = 0;
 
@@ -70,11 +63,9 @@ static int mtdram_probe(struct device_d *dev)
 		ret = PTR_ERR(iores);
 		goto nobase;
 	}
-	base = IOMEM(iores->start);
 
-	res = dev_get_resource(dev, IORESOURCE_MEM, 0);
-	size = (unsigned long) resource_size(res);
-	mtd->priv = base;
+	mtd->priv = IOMEM(iores->start);
+	size = (unsigned long) resource_size(iores);
 
 	mtd->type = MTD_RAM;
 	mtd->writesize = 1;
-- 
2.30.2


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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] mtd: mtdram: add physically mapped ROM (mtd-rom) support
  2022-02-07  7:56 [PATCH 1/2] mtd: mtdram: discard superfluous code Ahmad Fatoum
@ 2022-02-07  7:56 ` Ahmad Fatoum
  2022-02-07  8:11 ` [PATCH 1/2] mtd: mtdram: discard superfluous code Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2022-02-07  7:56 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

We already have mtd-ram support for accessing memory-mapped RAMs.
Add support for the mtd-rom binding, so read-only access while
using the driver can be enforced. This is e.g. useful for memory-mapped
flash that can be normally read, but needs special handling for write
and erasure.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/mtd/devices/mtdram.c | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/devices/mtdram.c b/drivers/mtd/devices/mtdram.c
index c9371b16d0f5..abef07d9c0a7 100644
--- a/drivers/mtd/devices/mtdram.c
+++ b/drivers/mtd/devices/mtdram.c
@@ -38,6 +38,7 @@ static int ram_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retle
 
 static int mtdram_probe(struct device_d *dev)
 {
+	long type;
 	struct resource *iores;
 	int device_id;
 	struct mtd_info *mtd;
@@ -53,9 +54,11 @@ static int mtdram_probe(struct device_d *dev)
 			mtd->name = xstrdup(alias);
 	}
 
+	type = (long)device_get_match_data(dev);
+
 	if (!mtd->name) {
 		device_id = DEVICE_ID_DYNAMIC;
-		mtd->name = "mtdram";
+		mtd->name = type == MTD_RAM ? "mtdram" : "mtdrom";
 	}
 
 	iores = dev_request_mem_resource(dev, 0);
@@ -67,16 +70,19 @@ static int mtdram_probe(struct device_d *dev)
 	mtd->priv = IOMEM(iores->start);
 	size = (unsigned long) resource_size(iores);
 
-	mtd->type = MTD_RAM;
+	mtd->type = type;
 	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;
+
+	if (type == MTD_RAM) {
+		mtd->flags = MTD_CAP_RAM;
+		mtd->_write = ram_write;
+		mtd->_erase = ram_erase;
+		mtd->erasesize = 1;
+	}
 
 	mtd->dev.parent = dev;
 
@@ -92,6 +98,10 @@ nobase:
 static __maybe_unused struct of_device_id mtdram_dt_ids[] = {
 	{
 		.compatible	= "mtd-ram",
+		.data		= (void *)MTD_RAM
+	}, {
+		.compatible	= "mtd-rom",
+		.data		= (void *)MTD_ROM
 	}, {
 		/*  sentinel */
 	}
-- 
2.30.2


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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] mtd: mtdram: discard superfluous code
  2022-02-07  7:56 [PATCH 1/2] mtd: mtdram: discard superfluous code Ahmad Fatoum
  2022-02-07  7:56 ` [PATCH 2/2] mtd: mtdram: add physically mapped ROM (mtd-rom) support Ahmad Fatoum
@ 2022-02-07  8:11 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2022-02-07  8:11 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Mon, Feb 07, 2022 at 08:56:29AM +0100, Ahmad Fatoum wrote:
> We don't need to get the exact same resource, we just requested.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  drivers/mtd/devices/mtdram.c | 13 ++-----------
>  1 file changed, 2 insertions(+), 11 deletions(-)

Applied, thanks

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
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] 3+ messages in thread

end of thread, other threads:[~2022-02-07  8:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-07  7:56 [PATCH 1/2] mtd: mtdram: discard superfluous code Ahmad Fatoum
2022-02-07  7:56 ` [PATCH 2/2] mtd: mtdram: add physically mapped ROM (mtd-rom) support Ahmad Fatoum
2022-02-07  8:11 ` [PATCH 1/2] mtd: mtdram: discard superfluous code Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox