Skip to content

Commit

Permalink
mtd: nand: move of_get_nand_xxx() helpers into nand_base.c
Browse files Browse the repository at this point in the history
Now that all drivers go through nand_set_flash_node() to parse the generic
NAND properties, we can move all of_get_nand_xxx() helpers in to
nand_base.c, make them static and remove of_mtd.c and of_mtd.h.

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
  • Loading branch information
Boris Brezillon committed May 5, 2016
1 parent 14667d8 commit d48f62b
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 213 deletions.
94 changes: 93 additions & 1 deletion drivers/mtd/nand/nand_base.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
#include <linux/bitops.h>
#include <linux/io.h>
#include <linux/mtd/partitions.h>
#include <linux/of_mtd.h>
#include <linux/of.h>

static int nand_get_device(struct mtd_info *mtd, int new_state);

Expand Down Expand Up @@ -3971,6 +3971,98 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
return type;
}

static const char * const nand_ecc_modes[] = {
[NAND_ECC_NONE] = "none",
[NAND_ECC_SOFT] = "soft",
[NAND_ECC_HW] = "hw",
[NAND_ECC_HW_SYNDROME] = "hw_syndrome",
[NAND_ECC_HW_OOB_FIRST] = "hw_oob_first",
[NAND_ECC_SOFT_BCH] = "soft_bch",
};

static int of_get_nand_ecc_mode(struct device_node *np)
{
const char *pm;
int err, i;

err = of_property_read_string(np, "nand-ecc-mode", &pm);
if (err < 0)
return err;

for (i = 0; i < ARRAY_SIZE(nand_ecc_modes); i++)
if (!strcasecmp(pm, nand_ecc_modes[i]))
return i;

return -ENODEV;
}

static int of_get_nand_ecc_algo(struct device_node *np)
{
const char *pm;
int err;

/*
* TODO: Read ECC algo OF property and map it to enum nand_ecc_algo.
* It's not implemented yet as currently NAND subsystem ignores
* algorithm explicitly set this way. Once it's handled we should
* document & support new property.
*/

/*
* For backward compatibility we also read "nand-ecc-mode" checking
* for some obsoleted values that were specifying ECC algorithm.
*/
err = of_property_read_string(np, "nand-ecc-mode", &pm);
if (err < 0)
return err;

if (!strcasecmp(pm, "soft"))
return NAND_ECC_HAMMING;
else if (!strcasecmp(pm, "soft_bch"))
return NAND_ECC_BCH;

return -ENODEV;
}

static int of_get_nand_ecc_step_size(struct device_node *np)
{
int ret;
u32 val;

ret = of_property_read_u32(np, "nand-ecc-step-size", &val);
return ret ? ret : val;
}

static int of_get_nand_ecc_strength(struct device_node *np)
{
int ret;
u32 val;

ret = of_property_read_u32(np, "nand-ecc-strength", &val);
return ret ? ret : val;
}

static int of_get_nand_bus_width(struct device_node *np)
{
u32 val;

if (of_property_read_u32(np, "nand-bus-width", &val))
return 8;

switch (val) {
case 8:
case 16:
return val;
default:
return -EIO;
}
}

static bool of_get_nand_on_flash_bbt(struct device_node *np)
{
return of_property_read_bool(np, "nand-on-flash-bbt");
}

static int nand_dt_init(struct nand_chip *chip)
{
struct device_node *dn = nand_get_flash_node(chip);
Expand Down
1 change: 0 additions & 1 deletion drivers/of/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ obj-$(CONFIG_OF_UNITTEST) += unittest.o
obj-$(CONFIG_OF_MDIO) += of_mdio.o
obj-$(CONFIG_OF_PCI) += of_pci.o
obj-$(CONFIG_OF_PCI_IRQ) += of_pci_irq.o
obj-$(CONFIG_OF_MTD) += of_mtd.o
obj-$(CONFIG_OF_RESERVED_MEM) += of_reserved_mem.o
obj-$(CONFIG_OF_RESOLVE) += resolver.o
obj-$(CONFIG_OF_OVERLAY) += overlay.o
Expand Down
155 changes: 0 additions & 155 deletions drivers/of/of_mtd.c

This file was deleted.

56 changes: 0 additions & 56 deletions include/linux/of_mtd.h

This file was deleted.

0 comments on commit d48f62b

Please sign in to comment.