2 * Copyright (C) 2017 Free Electrons
3 * Copyright (C) 2017 NextThing Co
5 * Author: Boris Brezillon <boris.brezillon@free-electrons.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
18 #include <linux/mtd/nand.h>
20 struct nand_onfi_vendor_micron
{
25 u8 dq_imped_num_settings
;
26 u8 dq_imped_feat_addr
;
27 u8 rb_pulldown_strength
;
28 u8 rb_pulldown_strength_feat_addr
;
29 u8 rb_pulldown_strength_num_settings
;
32 u8 otp_data_prot_addr
;
35 u8 read_retry_options
;
40 static int micron_nand_setup_read_retry(struct mtd_info
*mtd
, int retry_mode
)
42 struct nand_chip
*chip
= mtd_to_nand(mtd
);
43 u8 feature
[ONFI_SUBFEATURE_PARAM_LEN
] = {retry_mode
};
45 return chip
->onfi_set_features(mtd
, chip
, ONFI_FEATURE_ADDR_READ_RETRY
,
50 * Configure chip properties from Micron vendor-specific ONFI table
52 static int micron_nand_onfi_init(struct nand_chip
*chip
)
54 struct nand_onfi_params
*p
= &chip
->onfi_params
;
55 struct nand_onfi_vendor_micron
*micron
= (void *)p
->vendor
;
57 if (!chip
->onfi_version
)
60 if (le16_to_cpu(p
->vendor_revision
) < 1)
63 chip
->read_retries
= micron
->read_retry_options
;
64 chip
->setup_read_retry
= micron_nand_setup_read_retry
;
69 static int micron_nand_init(struct nand_chip
*chip
)
71 struct mtd_info
*mtd
= nand_to_mtd(chip
);
74 ret
= micron_nand_onfi_init(chip
);
78 if (mtd
->writesize
== 2048)
79 chip
->bbt_options
|= NAND_BBT_SCAN2NDPAGE
;
84 const struct nand_manufacturer_ops micron_nand_manuf_ops
= {
85 .init
= micron_nand_init
,