1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2017 Free Electrons
4 * Copyright (C) 2017 NextThing Co
6 * Author: Boris Brezillon <boris.brezillon@free-electrons.com>
11 #define MACRONIX_READ_RETRY_BIT BIT(0)
12 #define MACRONIX_NUM_READ_RETRY_MODES 6
14 struct nand_onfi_vendor_macronix
{
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
))
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
;
40 mxic
= (struct nand_onfi_vendor_macronix
*)p
->onfi
->vendor
;
41 if ((mxic
->reliability_func
& MACRONIX_READ_RETRY_BIT
) == 0)
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
)
63 static const char * const broken_get_timings
[] = {
80 if (!chip
->parameters
.supports_set_get_features
)
83 i
= match_string(broken_get_timings
, ARRAY_SIZE(broken_get_timings
),
84 chip
->parameters
.model
);
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
);
105 const struct nand_manufacturer_ops macronix_nand_manuf_ops
= {
106 .init
= macronix_nand_init
,