162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (C) 2005, Intec Automation Inc. 462306a36Sopenharmony_ci * Copyright (C) 2014, Freescale Semiconductor, Inc. 562306a36Sopenharmony_ci */ 662306a36Sopenharmony_ci 762306a36Sopenharmony_ci#ifndef __LINUX_MTD_SFDP_H 862306a36Sopenharmony_ci#define __LINUX_MTD_SFDP_H 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci/* SFDP revisions */ 1162306a36Sopenharmony_ci#define SFDP_JESD216_MAJOR 1 1262306a36Sopenharmony_ci#define SFDP_JESD216_MINOR 0 1362306a36Sopenharmony_ci#define SFDP_JESD216A_MINOR 5 1462306a36Sopenharmony_ci#define SFDP_JESD216B_MINOR 6 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ci/* SFDP DWORDS are indexed from 1 but C arrays are indexed from 0. */ 1762306a36Sopenharmony_ci#define SFDP_DWORD(i) ((i) - 1) 1862306a36Sopenharmony_ci#define SFDP_MASK_CHECK(dword, mask) (((dword) & (mask)) == (mask)) 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ci/* Basic Flash Parameter Table */ 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ci/* JESD216 rev D defines a Basic Flash Parameter Table of 20 DWORDs. */ 2362306a36Sopenharmony_ci#define BFPT_DWORD_MAX 20 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_cistruct sfdp_bfpt { 2662306a36Sopenharmony_ci u32 dwords[BFPT_DWORD_MAX]; 2762306a36Sopenharmony_ci}; 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_ci/* The first version of JESD216 defined only 9 DWORDs. */ 3062306a36Sopenharmony_ci#define BFPT_DWORD_MAX_JESD216 9 3162306a36Sopenharmony_ci#define BFPT_DWORD_MAX_JESD216B 16 3262306a36Sopenharmony_ci 3362306a36Sopenharmony_ci/* 1st DWORD. */ 3462306a36Sopenharmony_ci#define BFPT_DWORD1_FAST_READ_1_1_2 BIT(16) 3562306a36Sopenharmony_ci#define BFPT_DWORD1_ADDRESS_BYTES_MASK GENMASK(18, 17) 3662306a36Sopenharmony_ci#define BFPT_DWORD1_ADDRESS_BYTES_3_ONLY (0x0UL << 17) 3762306a36Sopenharmony_ci#define BFPT_DWORD1_ADDRESS_BYTES_3_OR_4 (0x1UL << 17) 3862306a36Sopenharmony_ci#define BFPT_DWORD1_ADDRESS_BYTES_4_ONLY (0x2UL << 17) 3962306a36Sopenharmony_ci#define BFPT_DWORD1_DTR BIT(19) 4062306a36Sopenharmony_ci#define BFPT_DWORD1_FAST_READ_1_2_2 BIT(20) 4162306a36Sopenharmony_ci#define BFPT_DWORD1_FAST_READ_1_4_4 BIT(21) 4262306a36Sopenharmony_ci#define BFPT_DWORD1_FAST_READ_1_1_4 BIT(22) 4362306a36Sopenharmony_ci 4462306a36Sopenharmony_ci/* 5th DWORD. */ 4562306a36Sopenharmony_ci#define BFPT_DWORD5_FAST_READ_2_2_2 BIT(0) 4662306a36Sopenharmony_ci#define BFPT_DWORD5_FAST_READ_4_4_4 BIT(4) 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_ci/* 11th DWORD. */ 4962306a36Sopenharmony_ci#define BFPT_DWORD11_PAGE_SIZE_SHIFT 4 5062306a36Sopenharmony_ci#define BFPT_DWORD11_PAGE_SIZE_MASK GENMASK(7, 4) 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ci/* 15th DWORD. */ 5362306a36Sopenharmony_ci 5462306a36Sopenharmony_ci/* 5562306a36Sopenharmony_ci * (from JESD216 rev B) 5662306a36Sopenharmony_ci * Quad Enable Requirements (QER): 5762306a36Sopenharmony_ci * - 000b: Device does not have a QE bit. Device detects 1-1-4 and 1-4-4 5862306a36Sopenharmony_ci * reads based on instruction. DQ3/HOLD# functions are hold during 5962306a36Sopenharmony_ci * instruction phase. 6062306a36Sopenharmony_ci * - 001b: QE is bit 1 of status register 2. It is set via Write Status with 6162306a36Sopenharmony_ci * two data bytes where bit 1 of the second byte is one. 6262306a36Sopenharmony_ci * [...] 6362306a36Sopenharmony_ci * Writing only one byte to the status register has the side-effect of 6462306a36Sopenharmony_ci * clearing status register 2, including the QE bit. The 100b code is 6562306a36Sopenharmony_ci * used if writing one byte to the status register does not modify 6662306a36Sopenharmony_ci * status register 2. 6762306a36Sopenharmony_ci * - 010b: QE is bit 6 of status register 1. It is set via Write Status with 6862306a36Sopenharmony_ci * one data byte where bit 6 is one. 6962306a36Sopenharmony_ci * [...] 7062306a36Sopenharmony_ci * - 011b: QE is bit 7 of status register 2. It is set via Write status 7162306a36Sopenharmony_ci * register 2 instruction 3Eh with one data byte where bit 7 is one. 7262306a36Sopenharmony_ci * [...] 7362306a36Sopenharmony_ci * The status register 2 is read using instruction 3Fh. 7462306a36Sopenharmony_ci * - 100b: QE is bit 1 of status register 2. It is set via Write Status with 7562306a36Sopenharmony_ci * two data bytes where bit 1 of the second byte is one. 7662306a36Sopenharmony_ci * [...] 7762306a36Sopenharmony_ci * In contrast to the 001b code, writing one byte to the status 7862306a36Sopenharmony_ci * register does not modify status register 2. 7962306a36Sopenharmony_ci * - 101b: QE is bit 1 of status register 2. Status register 1 is read using 8062306a36Sopenharmony_ci * Read Status instruction 05h. Status register2 is read using 8162306a36Sopenharmony_ci * instruction 35h. QE is set via Write Status instruction 01h with 8262306a36Sopenharmony_ci * two data bytes where bit 1 of the second byte is one. 8362306a36Sopenharmony_ci * [...] 8462306a36Sopenharmony_ci */ 8562306a36Sopenharmony_ci#define BFPT_DWORD15_QER_MASK GENMASK(22, 20) 8662306a36Sopenharmony_ci#define BFPT_DWORD15_QER_NONE (0x0UL << 20) /* Micron */ 8762306a36Sopenharmony_ci#define BFPT_DWORD15_QER_SR2_BIT1_BUGGY (0x1UL << 20) 8862306a36Sopenharmony_ci#define BFPT_DWORD15_QER_SR1_BIT6 (0x2UL << 20) /* Macronix */ 8962306a36Sopenharmony_ci#define BFPT_DWORD15_QER_SR2_BIT7 (0x3UL << 20) 9062306a36Sopenharmony_ci#define BFPT_DWORD15_QER_SR2_BIT1_NO_RD (0x4UL << 20) 9162306a36Sopenharmony_ci#define BFPT_DWORD15_QER_SR2_BIT1 (0x5UL << 20) /* Spansion */ 9262306a36Sopenharmony_ci 9362306a36Sopenharmony_ci#define BFPT_DWORD16_EN4B_MASK GENMASK(31, 24) 9462306a36Sopenharmony_ci#define BFPT_DWORD16_EN4B_ALWAYS_4B BIT(30) 9562306a36Sopenharmony_ci#define BFPT_DWORD16_EN4B_4B_OPCODES BIT(29) 9662306a36Sopenharmony_ci#define BFPT_DWORD16_EN4B_16BIT_NV_CR BIT(28) 9762306a36Sopenharmony_ci#define BFPT_DWORD16_EN4B_BRWR BIT(27) 9862306a36Sopenharmony_ci#define BFPT_DWORD16_EN4B_WREAR BIT(26) 9962306a36Sopenharmony_ci#define BFPT_DWORD16_EN4B_WREN_EN4B BIT(25) 10062306a36Sopenharmony_ci#define BFPT_DWORD16_EN4B_EN4B BIT(24) 10162306a36Sopenharmony_ci#define BFPT_DWORD16_EX4B_MASK GENMASK(18, 14) 10262306a36Sopenharmony_ci#define BFPT_DWORD16_EX4B_16BIT_NV_CR BIT(18) 10362306a36Sopenharmony_ci#define BFPT_DWORD16_EX4B_BRWR BIT(17) 10462306a36Sopenharmony_ci#define BFPT_DWORD16_EX4B_WREAR BIT(16) 10562306a36Sopenharmony_ci#define BFPT_DWORD16_EX4B_WREN_EX4B BIT(15) 10662306a36Sopenharmony_ci#define BFPT_DWORD16_EX4B_EX4B BIT(14) 10762306a36Sopenharmony_ci#define BFPT_DWORD16_4B_ADDR_MODE_MASK \ 10862306a36Sopenharmony_ci (BFPT_DWORD16_EN4B_MASK | BFPT_DWORD16_EX4B_MASK) 10962306a36Sopenharmony_ci#define BFPT_DWORD16_4B_ADDR_MODE_16BIT_NV_CR \ 11062306a36Sopenharmony_ci (BFPT_DWORD16_EN4B_16BIT_NV_CR | BFPT_DWORD16_EX4B_16BIT_NV_CR) 11162306a36Sopenharmony_ci#define BFPT_DWORD16_4B_ADDR_MODE_BRWR \ 11262306a36Sopenharmony_ci (BFPT_DWORD16_EN4B_BRWR | BFPT_DWORD16_EX4B_BRWR) 11362306a36Sopenharmony_ci#define BFPT_DWORD16_4B_ADDR_MODE_WREAR \ 11462306a36Sopenharmony_ci (BFPT_DWORD16_EN4B_WREAR | BFPT_DWORD16_EX4B_WREAR) 11562306a36Sopenharmony_ci#define BFPT_DWORD16_4B_ADDR_MODE_WREN_EN4B_EX4B \ 11662306a36Sopenharmony_ci (BFPT_DWORD16_EN4B_WREN_EN4B | BFPT_DWORD16_EX4B_WREN_EX4B) 11762306a36Sopenharmony_ci#define BFPT_DWORD16_4B_ADDR_MODE_EN4B_EX4B \ 11862306a36Sopenharmony_ci (BFPT_DWORD16_EN4B_EN4B | BFPT_DWORD16_EX4B_EX4B) 11962306a36Sopenharmony_ci#define BFPT_DWORD16_SWRST_EN_RST BIT(12) 12062306a36Sopenharmony_ci 12162306a36Sopenharmony_ci#define BFPT_DWORD18_CMD_EXT_MASK GENMASK(30, 29) 12262306a36Sopenharmony_ci#define BFPT_DWORD18_CMD_EXT_REP (0x0UL << 29) /* Repeat */ 12362306a36Sopenharmony_ci#define BFPT_DWORD18_CMD_EXT_INV (0x1UL << 29) /* Invert */ 12462306a36Sopenharmony_ci#define BFPT_DWORD18_CMD_EXT_RES (0x2UL << 29) /* Reserved */ 12562306a36Sopenharmony_ci#define BFPT_DWORD18_CMD_EXT_16B (0x3UL << 29) /* 16-bit opcode */ 12662306a36Sopenharmony_ci 12762306a36Sopenharmony_cistruct sfdp_parameter_header { 12862306a36Sopenharmony_ci u8 id_lsb; 12962306a36Sopenharmony_ci u8 minor; 13062306a36Sopenharmony_ci u8 major; 13162306a36Sopenharmony_ci u8 length; /* in double words */ 13262306a36Sopenharmony_ci u8 parameter_table_pointer[3]; /* byte address */ 13362306a36Sopenharmony_ci u8 id_msb; 13462306a36Sopenharmony_ci}; 13562306a36Sopenharmony_ci 13662306a36Sopenharmony_ci#endif /* __LINUX_MTD_SFDP_H */ 137