1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Copyright © 2000-2010 David Woodhouse <dwmw2@infradead.org> 4 * Steven J. Hill <sjhill@realitydiluted.com> 5 * Thomas Gleixner <tglx@linutronix.de> 6 * 7 * Contains all ONFI related definitions 8 */ 9 10 #ifndef __LINUX_MTD_ONFI_H 11 #define __LINUX_MTD_ONFI_H 12 13 #include <linux/types.h> 14 #include <linux/bitfield.h> 15 16 /* ONFI version bits */ 17 #define ONFI_VERSION_1_0 BIT(1) 18 #define ONFI_VERSION_2_0 BIT(2) 19 #define ONFI_VERSION_2_1 BIT(3) 20 #define ONFI_VERSION_2_2 BIT(4) 21 #define ONFI_VERSION_2_3 BIT(5) 22 #define ONFI_VERSION_3_0 BIT(6) 23 #define ONFI_VERSION_3_1 BIT(7) 24 #define ONFI_VERSION_3_2 BIT(8) 25 #define ONFI_VERSION_4_0 BIT(9) 26 27 /* ONFI features */ 28 #define ONFI_FEATURE_16_BIT_BUS BIT(0) 29 #define ONFI_FEATURE_NV_DDR BIT(5) 30 #define ONFI_FEATURE_EXT_PARAM_PAGE BIT(7) 31 32 /* ONFI timing mode, used in both asynchronous and synchronous mode */ 33 #define ONFI_DATA_INTERFACE_SDR 0 34 #define ONFI_DATA_INTERFACE_NVDDR BIT(4) 35 #define ONFI_DATA_INTERFACE_NVDDR2 BIT(5) 36 #define ONFI_TIMING_MODE_0 BIT(0) 37 #define ONFI_TIMING_MODE_1 BIT(1) 38 #define ONFI_TIMING_MODE_2 BIT(2) 39 #define ONFI_TIMING_MODE_3 BIT(3) 40 #define ONFI_TIMING_MODE_4 BIT(4) 41 #define ONFI_TIMING_MODE_5 BIT(5) 42 #define ONFI_TIMING_MODE_UNKNOWN BIT(6) 43 #define ONFI_TIMING_MODE_PARAM(x) FIELD_GET(GENMASK(3, 0), (x)) 44 45 /* ONFI feature number/address */ 46 #define ONFI_FEATURE_NUMBER 256 47 #define ONFI_FEATURE_ADDR_TIMING_MODE 0x1 48 49 /* Vendor-specific feature address (Micron) */ 50 #define ONFI_FEATURE_ADDR_READ_RETRY 0x89 51 #define ONFI_FEATURE_ON_DIE_ECC 0x90 52 #define ONFI_FEATURE_ON_DIE_ECC_EN BIT(3) 53 54 /* ONFI subfeature parameters length */ 55 #define ONFI_SUBFEATURE_PARAM_LEN 4 56 57 /* ONFI optional commands SET/GET FEATURES supported? */ 58 #define ONFI_OPT_CMD_SET_GET_FEATURES BIT(2) 59 60 struct nand_onfi_params { 61 /* rev info and features block */ 62 /* 'O' 'N' 'F' 'I' */ 63 u8 sig[4]; 64 __le16 revision; 65 __le16 features; 66 __le16 opt_cmd; 67 u8 reserved0[2]; 68 __le16 ext_param_page_length; /* since ONFI 2.1 */ 69 u8 num_of_param_pages; /* since ONFI 2.1 */ 70 u8 reserved1[17]; 71 72 /* manufacturer information block */ 73 char manufacturer[12]; 74 char model[20]; 75 u8 jedec_id; 76 __le16 date_code; 77 u8 reserved2[13]; 78 79 /* memory organization block */ 80 __le32 byte_per_page; 81 __le16 spare_bytes_per_page; 82 __le32 data_bytes_per_ppage; 83 __le16 spare_bytes_per_ppage; 84 __le32 pages_per_block; 85 __le32 blocks_per_lun; 86 u8 lun_count; 87 u8 addr_cycles; 88 u8 bits_per_cell; 89 __le16 bb_per_lun; 90 __le16 block_endurance; 91 u8 guaranteed_good_blocks; 92 __le16 guaranteed_block_endurance; 93 u8 programs_per_page; 94 u8 ppage_attr; 95 u8 ecc_bits; 96 u8 interleaved_bits; 97 u8 interleaved_ops; 98 u8 reserved3[13]; 99 100 /* electrical parameter block */ 101 u8 io_pin_capacitance_max; 102 __le16 sdr_timing_modes; 103 __le16 program_cache_timing_mode; 104 __le16 t_prog; 105 __le16 t_bers; 106 __le16 t_r; 107 __le16 t_ccs; 108 u8 nvddr_timing_modes; 109 u8 nvddr2_timing_modes; 110 u8 nvddr_nvddr2_features; 111 __le16 clk_pin_capacitance_typ; 112 __le16 io_pin_capacitance_typ; 113 __le16 input_pin_capacitance_typ; 114 u8 input_pin_capacitance_max; 115 u8 driver_strength_support; 116 __le16 t_int_r; 117 __le16 t_adl; 118 u8 reserved4[8]; 119 120 /* vendor */ 121 __le16 vendor_revision; 122 u8 vendor[88]; 123 124 __le16 crc; 125 } __packed; 126 127 #define ONFI_CRC_BASE 0x4F4E 128 129 /* Extended ECC information Block Definition (since ONFI 2.1) */ 130 struct onfi_ext_ecc_info { 131 u8 ecc_bits; 132 u8 codeword_size; 133 __le16 bb_per_lun; 134 __le16 block_endurance; 135 u8 reserved[2]; 136 } __packed; 137 138 #define ONFI_SECTION_TYPE_0 0 /* Unused section. */ 139 #define ONFI_SECTION_TYPE_1 1 /* for additional sections. */ 140 #define ONFI_SECTION_TYPE_2 2 /* for ECC information. */ 141 struct onfi_ext_section { 142 u8 type; 143 u8 length; 144 } __packed; 145 146 #define ONFI_EXT_SECTION_MAX 8 147 148 /* Extended Parameter Page Definition (since ONFI 2.1) */ 149 struct onfi_ext_param_page { 150 __le16 crc; 151 u8 sig[4]; /* 'E' 'P' 'P' 'S' */ 152 u8 reserved0[10]; 153 struct onfi_ext_section sections[ONFI_EXT_SECTION_MAX]; 154 155 /* 156 * The actual size of the Extended Parameter Page is in 157 * @ext_param_page_length of nand_onfi_params{}. 158 * The following are the variable length sections. 159 * So we do not add any fields below. Please see the ONFI spec. 160 */ 161 } __packed; 162 163 /** 164 * struct onfi_params - ONFI specific parameters that will be reused 165 * @version: ONFI version (BCD encoded), 0 if ONFI is not supported 166 * @tPROG: Page program time 167 * @tBERS: Block erase time 168 * @tR: Page read time 169 * @tCCS: Change column setup time 170 * @fast_tCAD: Command/Address/Data slow or fast delay (NV-DDR only) 171 * @sdr_timing_modes: Supported asynchronous/SDR timing modes 172 * @nvddr_timing_modes: Supported source synchronous/NV-DDR timing modes 173 * @vendor_revision: Vendor specific revision number 174 * @vendor: Vendor specific data 175 */ 176 struct onfi_params { 177 int version; 178 u16 tPROG; 179 u16 tBERS; 180 u16 tR; 181 u16 tCCS; 182 bool fast_tCAD; 183 u16 sdr_timing_modes; 184 u16 nvddr_timing_modes; 185 u16 vendor_revision; 186 u8 vendor[88]; 187 }; 188 189 #endif /* __LINUX_MTD_ONFI_H */ 190