treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / mtd / nand / raw / nand_macronix.c
blob3ff7ce00cbdb1c55678e78bd910ca6a6be0f4c75
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (C) 2017 Free Electrons
4 * Copyright (C) 2017 NextThing Co
6 * Author: Boris Brezillon <boris.brezillon@free-electrons.com>
7 */
9 #include "internals.h"
11 #define MACRONIX_READ_RETRY_BIT BIT(0)
12 #define MACRONIX_NUM_READ_RETRY_MODES 6
14 struct nand_onfi_vendor_macronix {
15 u8 reserved;
16 u8 reliability_func;
17 } __packed;
19 static int macronix_nand_setup_read_retry(struct nand_chip *chip, int mode)
21 u8 feature[ONFI_SUBFEATURE_PARAM_LEN];
23 if (!chip->parameters.supports_set_get_features ||
24 !test_bit(ONFI_FEATURE_ADDR_READ_RETRY,
25 chip->parameters.set_feature_list))
26 return -ENOTSUPP;
28 feature[0] = mode;
29 return nand_set_features(chip, ONFI_FEATURE_ADDR_READ_RETRY, feature);
32 static void macronix_nand_onfi_init(struct nand_chip *chip)
34 struct nand_parameters *p = &chip->parameters;
35 struct nand_onfi_vendor_macronix *mxic;
37 if (!p->onfi)
38 return;
40 mxic = (struct nand_onfi_vendor_macronix *)p->onfi->vendor;
41 if ((mxic->reliability_func & MACRONIX_READ_RETRY_BIT) == 0)
42 return;
44 chip->read_retries = MACRONIX_NUM_READ_RETRY_MODES;
45 chip->setup_read_retry = macronix_nand_setup_read_retry;
47 if (p->supports_set_get_features) {
48 bitmap_set(p->set_feature_list,
49 ONFI_FEATURE_ADDR_READ_RETRY, 1);
50 bitmap_set(p->get_feature_list,
51 ONFI_FEATURE_ADDR_READ_RETRY, 1);
56 * Macronix AC series does not support using SET/GET_FEATURES to change
57 * the timings unlike what is declared in the parameter page. Unflag
58 * this feature to avoid unnecessary downturns.
60 static void macronix_nand_fix_broken_get_timings(struct nand_chip *chip)
62 int i;
63 static const char * const broken_get_timings[] = {
64 "MX30LF1G18AC",
65 "MX30LF1G28AC",
66 "MX30LF2G18AC",
67 "MX30LF2G28AC",
68 "MX30LF4G18AC",
69 "MX30LF4G28AC",
70 "MX60LF8G18AC",
71 "MX30UF1G18AC",
72 "MX30UF1G16AC",
73 "MX30UF2G18AC",
74 "MX30UF2G16AC",
75 "MX30UF4G18AC",
76 "MX30UF4G16AC",
77 "MX30UF4G28AC",
80 if (!chip->parameters.supports_set_get_features)
81 return;
83 i = match_string(broken_get_timings, ARRAY_SIZE(broken_get_timings),
84 chip->parameters.model);
85 if (i < 0)
86 return;
88 bitmap_clear(chip->parameters.get_feature_list,
89 ONFI_FEATURE_ADDR_TIMING_MODE, 1);
90 bitmap_clear(chip->parameters.set_feature_list,
91 ONFI_FEATURE_ADDR_TIMING_MODE, 1);
94 static int macronix_nand_init(struct nand_chip *chip)
96 if (nand_is_slc(chip))
97 chip->options |= NAND_BBM_FIRSTPAGE | NAND_BBM_SECONDPAGE;
99 macronix_nand_fix_broken_get_timings(chip);
100 macronix_nand_onfi_init(chip);
102 return 0;
105 const struct nand_manufacturer_ops macronix_nand_manuf_ops = {
106 .init = macronix_nand_init,