18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 2005, Intec Automation Inc. 48c2ecf20Sopenharmony_ci * Copyright (C) 2014, Freescale Semiconductor, Inc. 58c2ecf20Sopenharmony_ci */ 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#ifndef __LINUX_MTD_SFDP_H 88c2ecf20Sopenharmony_ci#define __LINUX_MTD_SFDP_H 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci/* SFDP revisions */ 118c2ecf20Sopenharmony_ci#define SFDP_JESD216_MAJOR 1 128c2ecf20Sopenharmony_ci#define SFDP_JESD216_MINOR 0 138c2ecf20Sopenharmony_ci#define SFDP_JESD216A_MINOR 5 148c2ecf20Sopenharmony_ci#define SFDP_JESD216B_MINOR 6 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci/* Basic Flash Parameter Table */ 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci/* 198c2ecf20Sopenharmony_ci * JESD216 rev D defines a Basic Flash Parameter Table of 20 DWORDs. 208c2ecf20Sopenharmony_ci * They are indexed from 1 but C arrays are indexed from 0. 218c2ecf20Sopenharmony_ci */ 228c2ecf20Sopenharmony_ci#define BFPT_DWORD(i) ((i) - 1) 238c2ecf20Sopenharmony_ci#define BFPT_DWORD_MAX 20 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_cistruct sfdp_bfpt { 268c2ecf20Sopenharmony_ci u32 dwords[BFPT_DWORD_MAX]; 278c2ecf20Sopenharmony_ci}; 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci/* The first version of JESD216 defined only 9 DWORDs. */ 308c2ecf20Sopenharmony_ci#define BFPT_DWORD_MAX_JESD216 9 318c2ecf20Sopenharmony_ci#define BFPT_DWORD_MAX_JESD216B 16 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci/* 1st DWORD. */ 348c2ecf20Sopenharmony_ci#define BFPT_DWORD1_FAST_READ_1_1_2 BIT(16) 358c2ecf20Sopenharmony_ci#define BFPT_DWORD1_ADDRESS_BYTES_MASK GENMASK(18, 17) 368c2ecf20Sopenharmony_ci#define BFPT_DWORD1_ADDRESS_BYTES_3_ONLY (0x0UL << 17) 378c2ecf20Sopenharmony_ci#define BFPT_DWORD1_ADDRESS_BYTES_3_OR_4 (0x1UL << 17) 388c2ecf20Sopenharmony_ci#define BFPT_DWORD1_ADDRESS_BYTES_4_ONLY (0x2UL << 17) 398c2ecf20Sopenharmony_ci#define BFPT_DWORD1_DTR BIT(19) 408c2ecf20Sopenharmony_ci#define BFPT_DWORD1_FAST_READ_1_2_2 BIT(20) 418c2ecf20Sopenharmony_ci#define BFPT_DWORD1_FAST_READ_1_4_4 BIT(21) 428c2ecf20Sopenharmony_ci#define BFPT_DWORD1_FAST_READ_1_1_4 BIT(22) 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci/* 5th DWORD. */ 458c2ecf20Sopenharmony_ci#define BFPT_DWORD5_FAST_READ_2_2_2 BIT(0) 468c2ecf20Sopenharmony_ci#define BFPT_DWORD5_FAST_READ_4_4_4 BIT(4) 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci/* 11th DWORD. */ 498c2ecf20Sopenharmony_ci#define BFPT_DWORD11_PAGE_SIZE_SHIFT 4 508c2ecf20Sopenharmony_ci#define BFPT_DWORD11_PAGE_SIZE_MASK GENMASK(7, 4) 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci/* 15th DWORD. */ 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci/* 558c2ecf20Sopenharmony_ci * (from JESD216 rev B) 568c2ecf20Sopenharmony_ci * Quad Enable Requirements (QER): 578c2ecf20Sopenharmony_ci * - 000b: Device does not have a QE bit. Device detects 1-1-4 and 1-4-4 588c2ecf20Sopenharmony_ci * reads based on instruction. DQ3/HOLD# functions are hold during 598c2ecf20Sopenharmony_ci * instruction phase. 608c2ecf20Sopenharmony_ci * - 001b: QE is bit 1 of status register 2. It is set via Write Status with 618c2ecf20Sopenharmony_ci * two data bytes where bit 1 of the second byte is one. 628c2ecf20Sopenharmony_ci * [...] 638c2ecf20Sopenharmony_ci * Writing only one byte to the status register has the side-effect of 648c2ecf20Sopenharmony_ci * clearing status register 2, including the QE bit. The 100b code is 658c2ecf20Sopenharmony_ci * used if writing one byte to the status register does not modify 668c2ecf20Sopenharmony_ci * status register 2. 678c2ecf20Sopenharmony_ci * - 010b: QE is bit 6 of status register 1. It is set via Write Status with 688c2ecf20Sopenharmony_ci * one data byte where bit 6 is one. 698c2ecf20Sopenharmony_ci * [...] 708c2ecf20Sopenharmony_ci * - 011b: QE is bit 7 of status register 2. It is set via Write status 718c2ecf20Sopenharmony_ci * register 2 instruction 3Eh with one data byte where bit 7 is one. 728c2ecf20Sopenharmony_ci * [...] 738c2ecf20Sopenharmony_ci * The status register 2 is read using instruction 3Fh. 748c2ecf20Sopenharmony_ci * - 100b: QE is bit 1 of status register 2. It is set via Write Status with 758c2ecf20Sopenharmony_ci * two data bytes where bit 1 of the second byte is one. 768c2ecf20Sopenharmony_ci * [...] 778c2ecf20Sopenharmony_ci * In contrast to the 001b code, writing one byte to the status 788c2ecf20Sopenharmony_ci * register does not modify status register 2. 798c2ecf20Sopenharmony_ci * - 101b: QE is bit 1 of status register 2. Status register 1 is read using 808c2ecf20Sopenharmony_ci * Read Status instruction 05h. Status register2 is read using 818c2ecf20Sopenharmony_ci * instruction 35h. QE is set via Write Status instruction 01h with 828c2ecf20Sopenharmony_ci * two data bytes where bit 1 of the second byte is one. 838c2ecf20Sopenharmony_ci * [...] 848c2ecf20Sopenharmony_ci */ 858c2ecf20Sopenharmony_ci#define BFPT_DWORD15_QER_MASK GENMASK(22, 20) 868c2ecf20Sopenharmony_ci#define BFPT_DWORD15_QER_NONE (0x0UL << 20) /* Micron */ 878c2ecf20Sopenharmony_ci#define BFPT_DWORD15_QER_SR2_BIT1_BUGGY (0x1UL << 20) 888c2ecf20Sopenharmony_ci#define BFPT_DWORD15_QER_SR1_BIT6 (0x2UL << 20) /* Macronix */ 898c2ecf20Sopenharmony_ci#define BFPT_DWORD15_QER_SR2_BIT7 (0x3UL << 20) 908c2ecf20Sopenharmony_ci#define BFPT_DWORD15_QER_SR2_BIT1_NO_RD (0x4UL << 20) 918c2ecf20Sopenharmony_ci#define BFPT_DWORD15_QER_SR2_BIT1 (0x5UL << 20) /* Spansion */ 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_cistruct sfdp_parameter_header { 948c2ecf20Sopenharmony_ci u8 id_lsb; 958c2ecf20Sopenharmony_ci u8 minor; 968c2ecf20Sopenharmony_ci u8 major; 978c2ecf20Sopenharmony_ci u8 length; /* in double words */ 988c2ecf20Sopenharmony_ci u8 parameter_table_pointer[3]; /* byte address */ 998c2ecf20Sopenharmony_ci u8 id_msb; 1008c2ecf20Sopenharmony_ci}; 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ciint spi_nor_parse_sfdp(struct spi_nor *nor, 1038c2ecf20Sopenharmony_ci struct spi_nor_flash_parameter *params); 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ci#endif /* __LINUX_MTD_SFDP_H */ 106