summaryrefslogtreecommitdiffstats
path: root/drivers/mtd/devices/mtdram.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mtd/devices/mtdram.c')
-rw-r--r--drivers/mtd/devices/mtdram.c50
1 files changed, 24 insertions, 26 deletions
diff --git a/drivers/mtd/devices/mtdram.c b/drivers/mtd/devices/mtdram.c
index 9cc8194b5d..33c221e3a1 100644
--- a/drivers/mtd/devices/mtdram.c
+++ b/drivers/mtd/devices/mtdram.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0-only
/*
* Author: Sebastian Block <basti@linux-source.de>
* Copyright (c) 2014
@@ -5,11 +6,6 @@
* 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>
@@ -20,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);
@@ -45,28 +36,29 @@ static int ram_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retle
return 0;
}
-static int mtdram_probe(struct device_d *dev)
+static int mtdram_probe(struct device *dev)
{
+ long type;
struct resource *iores;
- 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));
device_id = DEVICE_ID_SINGLE;
- if (dev->device_node) {
- const char *alias = of_alias_get(dev->device_node);
+ if (dev->of_node) {
+ const char *alias = of_alias_get(dev->of_node);
if (alias)
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);
@@ -74,22 +66,23 @@ 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->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;
@@ -105,12 +98,17 @@ 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 */
}
};
+MODULE_DEVICE_TABLE(of, mtdram_dt_ids);
-static struct driver_d mtdram_driver = {
+static struct driver mtdram_driver = {
.name = "mtdram",
.probe = mtdram_probe,
.of_compatible = DRV_OF_COMPAT(mtdram_dt_ids),