summaryrefslogtreecommitdiffstats
path: root/drivers/mtd
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2017-05-05 11:31:35 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2017-05-05 11:31:35 +0200
commit8e91536a000c1738e354827d6f72965fa1444985 (patch)
treecb48104fa7a635e82d2b8b8eed6af6fe671756f2 /drivers/mtd
parent30cce0c7414498317a43b2020dc1737b007acf98 (diff)
parent0071bacb4c7cab21c9fab8540f5aa9922a270a85 (diff)
downloadbarebox-8e91536a000c1738e354827d6f72965fa1444985.tar.gz
barebox-8e91536a000c1738e354827d6f72965fa1444985.tar.xz
Merge branch 'for-next/parameter-types'
Diffstat (limited to 'drivers/mtd')
-rw-r--r--drivers/mtd/core.c30
-rw-r--r--drivers/mtd/nand/nand_base.c34
-rw-r--r--drivers/mtd/peb.c6
-rw-r--r--drivers/mtd/ubi/build.c22
4 files changed, 55 insertions, 37 deletions
diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c
index 1eb8dd36d8..1950ee87ee 100644
--- a/drivers/mtd/core.c
+++ b/drivers/mtd/core.c
@@ -449,13 +449,13 @@ static struct file_operations mtd_ops = {
.lseek = dev_lseek_default,
};
-static int mtd_partition_set(struct device_d *dev, struct param_d *p, const char *val)
+static int mtd_partition_set(struct param_d *p, void *priv)
{
- struct mtd_info *mtd = container_of(dev, struct mtd_info, class_dev);
+ struct mtd_info *mtd = priv;
struct mtd_info *mtdpart, *tmp;
int ret;
- if (!val)
+ if (!mtd->partition_string)
return -EINVAL;
list_for_each_entry_safe(mtdpart, tmp, &mtd->partitions, partitions_entry) {
@@ -464,7 +464,7 @@ static int mtd_partition_set(struct device_d *dev, struct param_d *p, const char
return ret;
}
- return cmdlinepart_do_parse(mtd->cdev.name, val, mtd->size, CMDLINEPART_ADD_DEVNAME);
+ return cmdlinepart_do_parse(mtd->cdev.name, mtd->partition_string, mtd->size, CMDLINEPART_ADD_DEVNAME);
}
static char *print_size(uint64_t s)
@@ -530,18 +530,18 @@ static int print_parts(char *buf, int bufsize, struct mtd_info *mtd)
return ret;
}
-static const char *mtd_partition_get(struct device_d *dev, struct param_d *p)
+static int mtd_partition_get(struct param_d *p, void *priv)
{
- struct mtd_info *mtd = container_of(dev, struct mtd_info, class_dev);
+ struct mtd_info *mtd = priv;
int len = 0;
- free(p->value);
+ free(mtd->partition_string);
len = print_parts(NULL, 0, mtd);
- p->value = xzalloc(len + 1);
- print_parts(p->value, len + 1, mtd);
+ mtd->partition_string = xzalloc(len + 1);
+ print_parts(mtd->partition_string, len + 1, mtd);
- return p->value;
+ return 0;
}
static int mtd_part_compare(struct list_head *a, struct list_head *b)
@@ -637,10 +637,10 @@ int add_mtd_device(struct mtd_info *mtd, const char *devname, int device_id)
mtd->cdev.mtd = mtd;
if (IS_ENABLED(CONFIG_PARAMETER)) {
- dev_add_param_llint_ro(&mtd->class_dev, "size", mtd->size, "%llu");
- dev_add_param_int_ro(&mtd->class_dev, "erasesize", mtd->erasesize, "%u");
- dev_add_param_int_ro(&mtd->class_dev, "writesize", mtd->writesize, "%u");
- dev_add_param_int_ro(&mtd->class_dev, "oobsize", mtd->oobsize, "%u");
+ dev_add_param_uint64_ro(&mtd->class_dev, "size", &mtd->size, "%llu");
+ dev_add_param_uint32_ro(&mtd->class_dev, "erasesize", &mtd->erasesize, "%u");
+ dev_add_param_uint32_ro(&mtd->class_dev, "writesize", &mtd->writesize, "%u");
+ dev_add_param_uint32_ro(&mtd->class_dev, "oobsize", &mtd->oobsize, "%u");
}
ret = devfs_create(&mtd->cdev);
@@ -667,7 +667,7 @@ int add_mtd_device(struct mtd_info *mtd, const char *devname, int device_id)
mtd->cdev_bb = mtd_add_bb(mtd, NULL);
if (mtd->parent && !mtd->master) {
- dev_add_param(&mtd->class_dev, "partitions", mtd_partition_set, mtd_partition_get, 0);
+ dev_add_param_string(&mtd->class_dev, "partitions", mtd_partition_set, mtd_partition_get, &mtd->partition_string, mtd);
of_parse_partitions(&mtd->cdev, mtd->parent->device_node);
if (IS_ENABLED(CONFIG_OFDEVICE) && mtd->parent->device_node) {
mtd->of_path = xstrdup(mtd->parent->device_node->full_name);
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index ceb2bb7215..d9f79474cd 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -3853,25 +3853,40 @@ static int mtd_set_erasebad(struct param_d *param, void *priv)
return 0;
}
-static const char *mtd_get_bbt_type(struct device_d *dev, struct param_d *p)
+enum bbt_type {
+ BBT_TYPE_NONE = 0,
+ BBT_TYPE_FLASHBASED,
+ BBT_TYPE_MEMORYBASED,
+};
+
+static const char *bbt_type_strings[] = {
+ [BBT_TYPE_NONE] = "none",
+ [BBT_TYPE_FLASHBASED] = "flashbased",
+ [BBT_TYPE_MEMORYBASED] = "memorybased",
+};
+
+static int mtd_get_bbt_type(struct param_d *p, void *priv)
{
- struct mtd_info *mtd = container_of(dev, struct mtd_info, class_dev);
+ struct mtd_info *mtd = priv;
struct nand_chip *chip = mtd->priv;
- const char *str;
+ enum bbt_type type;
if (!chip->bbt)
- str = "none";
+ type = BBT_TYPE_NONE;
else if ((chip->bbt_td && chip->bbt_td->pages[0] != -1) ||
(chip->bbt_md && chip->bbt_md->pages[0] != -1))
- str = "flashbased";
+ type = BBT_TYPE_FLASHBASED;
else
- str = "memorybased";
+ type = BBT_TYPE_MEMORYBASED;
+
+ chip->bbt_type = type;
- return str;
+ return 0;
}
int add_mtd_nand_device(struct mtd_info *mtd, char *devname)
{
+ struct nand_chip *chip = mtd->priv;
int ret;
ret = add_mtd_device(mtd, devname, DEVICE_ID_DYNAMIC);
@@ -3882,7 +3897,10 @@ int add_mtd_nand_device(struct mtd_info *mtd, char *devname)
dev_add_param_bool(&mtd->class_dev, "erasebad", mtd_set_erasebad,
NULL, &mtd->p_allow_erasebad, mtd);
- dev_add_param(&mtd->class_dev, "bbt", NULL, mtd_get_bbt_type, 0);
+ dev_add_param_enum(&mtd->class_dev, "bbt", NULL, mtd_get_bbt_type,
+ &chip->bbt_type, bbt_type_strings,
+ ARRAY_SIZE(bbt_type_strings),
+ mtd);
return ret;
}
diff --git a/drivers/mtd/peb.c b/drivers/mtd/peb.c
index c35b63f2fd..0e64fe1671 100644
--- a/drivers/mtd/peb.c
+++ b/drivers/mtd/peb.c
@@ -76,11 +76,11 @@ static int mtd_peb_emulate_erase_failure(void)
#ifdef CONFIG_MTD_PEB_DEBUG
static int mtd_peb_debug_init(void)
{
- globalvar_add_simple_int("mtd_peb.mtd_peb_emulate_bitflip",
+ globalvar_add_simple_uint32("mtd_peb.mtd_peb_emulate_bitflip",
&__mtd_peb_emulate_bitflip, "%u");
- globalvar_add_simple_int("mtd_peb.mtd_peb_emulate_write_failure",
+ globalvar_add_simple_uint32("mtd_peb.mtd_peb_emulate_write_failure",
&__mtd_peb_emulate_write_failure, "%u");
- globalvar_add_simple_int("mtd_peb.mtd_peb_emulate_erase_failures",
+ globalvar_add_simple_uint32("mtd_peb.mtd_peb_emulate_erase_failures",
&__mtd_peb_emulate_erase_failures, "%u");
globalvar_add_simple_bool("mtd_peb.mtd_peb_chk_io",
&__mtd_peb_chk_io);
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 2ea66ed067..40fa890c9e 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -656,17 +656,17 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
ubi_msg(ubi, "available PEBs: %d, total reserved PEBs: %d, PEBs reserved for bad PEB handling: %d",
ubi->avail_pebs, ubi->rsvd_pebs, ubi->beb_rsvd_pebs);
- dev_add_param_int_ro(&ubi->dev, "peb_size", ubi->peb_size, "%d");
- dev_add_param_int_ro(&ubi->dev, "leb_size", ubi->leb_size, "%d");
- dev_add_param_int_ro(&ubi->dev, "vid_header_offset", ubi->vid_hdr_offset, "%d");
- dev_add_param_int_ro(&ubi->dev, "min_io_size", ubi->min_io_size, "%d");
- dev_add_param_int_ro(&ubi->dev, "sub_page_size", ubi->hdrs_min_io_size, "%d");
- dev_add_param_int_ro(&ubi->dev, "good_peb_count", ubi->good_peb_count, "%d");
- dev_add_param_int_ro(&ubi->dev, "bad_peb_count", ubi->bad_peb_count, "%d");
- dev_add_param_int_ro(&ubi->dev, "max_erase_counter", ubi->max_ec, "%d");
- dev_add_param_int_ro(&ubi->dev, "mean_erase_counter", ubi->mean_ec, "%d");
- dev_add_param_int_ro(&ubi->dev, "available_pebs", ubi->avail_pebs, "%d");
- dev_add_param_int_ro(&ubi->dev, "reserved_pebs", ubi->rsvd_pebs, "%d");
+ dev_add_param_uint32_ro(&ubi->dev, "peb_size", &ubi->peb_size, "%u");
+ dev_add_param_uint32_ro(&ubi->dev, "leb_size", &ubi->leb_size, "%u");
+ dev_add_param_uint32_ro(&ubi->dev, "vid_header_offset", &ubi->vid_hdr_offset, "%u");
+ dev_add_param_uint32_ro(&ubi->dev, "min_io_size", &ubi->min_io_size, "%u");
+ dev_add_param_uint32_ro(&ubi->dev, "sub_page_size", &ubi->hdrs_min_io_size, "%u");
+ dev_add_param_uint32_ro(&ubi->dev, "good_peb_count", &ubi->good_peb_count, "%u");
+ dev_add_param_uint32_ro(&ubi->dev, "bad_peb_count", &ubi->bad_peb_count, "%u");
+ dev_add_param_uint32_ro(&ubi->dev, "max_erase_counter", &ubi->max_ec, "%u");
+ dev_add_param_uint32_ro(&ubi->dev, "mean_erase_counter", &ubi->mean_ec, "%u");
+ dev_add_param_uint32_ro(&ubi->dev, "available_pebs", &ubi->avail_pebs, "%u");
+ dev_add_param_uint32_ro(&ubi->dev, "reserved_pebs", &ubi->rsvd_pebs, "%u");
ubi_devices[ubi_num] = ubi;