Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
of_mtd.c
Go to the documentation of this file.
1 /*
2  * Copyright 2012 Jean-Christophe PLAGNIOL-VILLARD <[email protected]>
3  *
4  * OF helpers for mtd.
5  *
6  * This file is released under the GPLv2
7  *
8  */
9 #include <linux/kernel.h>
10 #include <linux/of_mtd.h>
11 #include <linux/mtd/nand.h>
12 #include <linux/export.h>
13 
19 static const char *nand_ecc_modes[] = {
20  [NAND_ECC_NONE] = "none",
21  [NAND_ECC_SOFT] = "soft",
22  [NAND_ECC_HW] = "hw",
23  [NAND_ECC_HW_SYNDROME] = "hw_syndrome",
24  [NAND_ECC_HW_OOB_FIRST] = "hw_oob_first",
25  [NAND_ECC_SOFT_BCH] = "soft_bch",
26 };
27 
36 {
37  const char *pm;
38  int err, i;
39 
40  err = of_property_read_string(np, "nand-ecc-mode", &pm);
41  if (err < 0)
42  return err;
43 
44  for (i = 0; i < ARRAY_SIZE(nand_ecc_modes); i++)
45  if (!strcasecmp(pm, nand_ecc_modes[i]))
46  return i;
47 
48  return -ENODEV;
49 }
51 
59 {
60  u32 val;
61 
62  if (of_property_read_u32(np, "nand-bus-width", &val))
63  return 8;
64 
65  switch(val) {
66  case 8:
67  case 16:
68  return val;
69  default:
70  return -EIO;
71  }
72 }
74 
82 {
83  return of_property_read_bool(np, "nand-on-flash-bbt");
84 }