Coverage Report

Created: 2026-10-17 06:38

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/barebox/drivers/of/of_mtd.c
Line
Count
Source
1
// SPDX-License-Identifier: GPL-2.0-only
2
/*
3
 * Copyright 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
4
 *
5
 * OF helpers for mtd.
6
 */
7
#include <common.h>
8
#include <of_mtd.h>
9
#include <linux/mtd/nand.h>
10
#include <linux/mtd/rawnand.h>
11
12
/**
13
 * It maps 'enum nand_ecc_modes_t' found in include/linux/mtd/nand.h
14
 * into the device tree binding of 'nand-ecc', so that MTD
15
 * device driver can get nand ecc from device tree.
16
 */
17
static const char *nand_ecc_modes[] = {
18
  [NAND_ECC_INVALID]  = "invalid",
19
  [NAND_ECC_NONE]   = "none",
20
  [NAND_ECC_SOFT]   = "soft",
21
  [NAND_ECC_HW]   = "hw",
22
  [NAND_ECC_HW_SYNDROME]  = "hw_syndrome",
23
  [NAND_ECC_ON_DIE] = "on-die",
24
  [NAND_ECC_SOFT_BCH] = "soft_bch",
25
};
26
27
/**
28
 * of_get_nand_ecc_mode - Get nand ecc mode for given device_node
29
 * @np: Pointer to the given device_node
30
 *
31
 * The function gets ecc mode string from property 'nand-ecc-mode',
32
 * and return its index in nand_ecc_modes table, or errno in error case.
33
 */
34
int of_get_nand_ecc_mode(struct device_node *np)
35
0
{
36
0
  const char *pm;
37
0
  int err, i;
38
39
0
  err = of_property_read_string(np, "nand-ecc-mode", &pm);
40
0
  if (err < 0)
41
0
    return err;
42
43
0
  for (i = 0; i < ARRAY_SIZE(nand_ecc_modes); i++)
44
0
    if (!strcasecmp(pm, nand_ecc_modes[i]))
45
0
      return i;
46
47
0
  return -ENODEV;
48
0
}
49
EXPORT_SYMBOL_GPL(of_get_nand_ecc_mode);
50
51
/**
52
 * of_get_nand_ecc_step_size - Get ECC step size associated to
53
 * the required ECC strength (see below).
54
 * @np: Pointer to the given device_node
55
 *
56
 * return the ECC step size, or errno in error case.
57
 */
58
int of_get_nand_ecc_step_size(struct device_node *np)
59
0
{
60
0
  int ret;
61
0
  u32 val;
62
63
0
  ret = of_property_read_u32(np, "nand-ecc-step-size", &val);
64
0
  return ret ? ret : val;
65
0
}
66
EXPORT_SYMBOL_GPL(of_get_nand_ecc_step_size);
67
68
/**
69
 * of_get_nand_ecc_strength - Get required ECC strength over the
70
 * correspnding step size as defined by 'nand-ecc-size'
71
 * @np: Pointer to the given device_node
72
 *
73
 * return the ECC strength, or errno in error case.
74
 */
75
int of_get_nand_ecc_strength(struct device_node *np)
76
0
{
77
0
  int ret;
78
0
  u32 val;
79
80
0
  ret = of_property_read_u32(np, "nand-ecc-strength", &val);
81
0
  return ret ? ret : val;
82
0
}
83
EXPORT_SYMBOL_GPL(of_get_nand_ecc_strength);
84
85
/**
86
 * of_get_nand_bus_width - Get nand bus witdh for given device_node
87
 * @np: Pointer to the given device_node
88
 *
89
 * return bus width option, or errno in error case.
90
 */
91
int of_get_nand_bus_width(struct device_node *np)
92
0
{
93
0
  u32 val;
94
95
0
  if (of_property_read_u32(np, "nand-bus-width", &val))
96
0
    return 8;
97
98
0
  switch(val) {
99
0
  case 8:
100
0
  case 16:
101
0
    return val;
102
0
  default:
103
0
    return -EIO;
104
0
  }
105
0
}
106
EXPORT_SYMBOL_GPL(of_get_nand_bus_width);
107
108
/**
109
 * of_get_nand_on_flash_bbt - Get nand on flash bbt for given device_node
110
 * @np: Pointer to the given device_node
111
 *
112
 * return true if present false other wise
113
 */
114
bool of_get_nand_on_flash_bbt(struct device_node *np)
115
0
{
116
0
  return of_property_read_bool(np, "nand-on-flash-bbt");
117
0
}
118
EXPORT_SYMBOL_GPL(of_get_nand_on_flash_bbt);