diff options
author | Ahmad Fatoum <a.fatoum@pengutronix.de> | 2022-02-07 08:56:30 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2022-02-07 09:11:29 +0100 |
commit | 9b630f4ec8e3a93521c48f8aa6e2ea2ce09d6ff0 (patch) | |
tree | d8fa24a6deff966f6545a13969eedc554ef93265 /drivers | |
parent | 3087e0c233e9f940a69f52d1f49cf10c2c999b1d (diff) | |
download | barebox-9b630f4ec8e3a93521c48f8aa6e2ea2ce09d6ff0.tar.gz barebox-9b630f4ec8e3a93521c48f8aa6e2ea2ce09d6ff0.tar.xz |
mtd: mtdram: add physically mapped ROM (mtd-rom) support
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>
Link: https://lore.barebox.org/20220207075630.1014476-2-a.fatoum@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/mtd/devices/mtdram.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/drivers/mtd/devices/mtdram.c b/drivers/mtd/devices/mtdram.c index c9371b16d0..abef07d9c0 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 */ } |