Michael Trimarchi | fa5d40c | 2022-07-20 18:22:12 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (C) 2017 Free Electrons |
| 4 | * Copyright (C) 2017 NextThing Co |
| 5 | * |
| 6 | * Author: Boris Brezillon <boris.brezillon@free-electrons.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | */ |
| 18 | |
| 19 | #include <linux/mtd/rawnand.h> |
| 20 | |
| 21 | struct nand_onfi_vendor_micron { |
| 22 | u8 two_plane_read; |
| 23 | u8 read_cache; |
| 24 | u8 read_unique_id; |
| 25 | u8 dq_imped; |
| 26 | u8 dq_imped_num_settings; |
| 27 | u8 dq_imped_feat_addr; |
| 28 | u8 rb_pulldown_strength; |
| 29 | u8 rb_pulldown_strength_feat_addr; |
| 30 | u8 rb_pulldown_strength_num_settings; |
| 31 | u8 otp_mode; |
| 32 | u8 otp_page_start; |
| 33 | u8 otp_data_prot_addr; |
| 34 | u8 otp_num_pages; |
| 35 | u8 otp_feat_addr; |
| 36 | u8 read_retry_options; |
| 37 | u8 reserved[72]; |
| 38 | u8 param_revision; |
| 39 | } __packed; |
| 40 | |
| 41 | static int micron_nand_setup_read_retry(struct mtd_info *mtd, int retry_mode) |
| 42 | { |
| 43 | struct nand_chip *chip = mtd_to_nand(mtd); |
| 44 | u8 feature[ONFI_SUBFEATURE_PARAM_LEN] = {retry_mode}; |
| 45 | |
| 46 | return chip->onfi_set_features(mtd, chip, ONFI_FEATURE_ADDR_READ_RETRY, |
| 47 | feature); |
| 48 | } |
| 49 | |
| 50 | /* |
| 51 | * Configure chip properties from Micron vendor-specific ONFI table |
| 52 | */ |
| 53 | static int micron_nand_onfi_init(struct nand_chip *chip) |
| 54 | { |
| 55 | struct nand_onfi_params *p = &chip->onfi_params; |
| 56 | struct nand_onfi_vendor_micron *micron = (void *)p->vendor; |
| 57 | |
| 58 | if (!chip->onfi_version) |
| 59 | return 0; |
| 60 | |
| 61 | if (le16_to_cpu(p->vendor_revision) < 1) |
| 62 | return 0; |
| 63 | |
| 64 | chip->read_retries = micron->read_retry_options; |
| 65 | chip->setup_read_retry = micron_nand_setup_read_retry; |
| 66 | |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | static int micron_nand_init(struct nand_chip *chip) |
| 71 | { |
| 72 | struct mtd_info *mtd = nand_to_mtd(chip); |
| 73 | int ret; |
| 74 | |
| 75 | ret = micron_nand_onfi_init(chip); |
| 76 | if (ret) |
| 77 | return ret; |
| 78 | |
| 79 | if (mtd->writesize == 2048) |
| 80 | chip->bbt_options |= NAND_BBT_SCAN2NDPAGE; |
| 81 | |
| 82 | return 0; |
| 83 | } |
| 84 | |
| 85 | const struct nand_manufacturer_ops micron_nand_manuf_ops = { |
| 86 | .init = micron_nand_init, |
| 87 | }; |