Skip to content

Commit

Permalink
of: mtd: prepare helper reading NAND ECC algo from DT
Browse files Browse the repository at this point in the history
NAND subsystem is being slightly reworked to store ECC details in
separated fields. In future we'll want to add support for more DT
properties as specifying every possible setup with a single
"nand-ecc-mode" is a pretty bad idea.
To allow this let's add a helper that will support something like
"nand-ecc-algo" in future. Right now we use it for keeping backward
compatibility.

Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
  • Loading branch information
Rafał Miłecki authored and Boris Brezillon committed Apr 19, 2016
1 parent b0fcd8a commit dd2dcc0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
36 changes: 36 additions & 0 deletions drivers/of/of_mtd.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,42 @@ int of_get_nand_ecc_mode(struct device_node *np)
}
EXPORT_SYMBOL_GPL(of_get_nand_ecc_mode);

/**
* of_get_nand_ecc_algo - Get nand ecc algorithm for given device_node
* @np: Pointer to the given device_node
*
* The function gets ecc algorithm and returns its enum value, or errno in error
* case.
*/
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;
}
EXPORT_SYMBOL_GPL(of_get_nand_ecc_algo);

/**
* of_get_nand_ecc_step_size - Get ECC step size associated to
* the required ECC strength (see below).
Expand Down
6 changes: 6 additions & 0 deletions include/linux/of_mtd.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <linux/of.h>
int of_get_nand_ecc_mode(struct device_node *np);
int of_get_nand_ecc_algo(struct device_node *np);
int of_get_nand_ecc_step_size(struct device_node *np);
int of_get_nand_ecc_strength(struct device_node *np);
int of_get_nand_bus_width(struct device_node *np);
Expand All @@ -25,6 +26,11 @@ static inline int of_get_nand_ecc_mode(struct device_node *np)
return -ENOSYS;
}

static inline int of_get_nand_ecc_algo(struct device_node *np)
{
return -ENOSYS;
}

static inline int of_get_nand_ecc_step_size(struct device_node *np)
{
return -ENOSYS;
Expand Down

0 comments on commit dd2dcc0

Please sign in to comment.