1cb481b92STudor Ambarus /* SPDX-License-Identifier: GPL-2.0 */ 2cb481b92STudor Ambarus /* 3cb481b92STudor Ambarus * Copyright (C) 2005, Intec Automation Inc. 4cb481b92STudor Ambarus * Copyright (C) 2014, Freescale Semiconductor, Inc. 5cb481b92STudor Ambarus */ 6cb481b92STudor Ambarus 7cb481b92STudor Ambarus #ifndef __LINUX_MTD_SPI_NOR_INTERNAL_H 8cb481b92STudor Ambarus #define __LINUX_MTD_SPI_NOR_INTERNAL_H 9cb481b92STudor Ambarus 10cb481b92STudor Ambarus #include "sfdp.h" 11cb481b92STudor Ambarus 124f50e102SBoris Brezillon #define SPI_NOR_MAX_ID_LEN 6 134f50e102SBoris Brezillon 14829ec640STudor Ambarus enum spi_nor_option_flags { 15829ec640STudor Ambarus SNOR_F_USE_FSR = BIT(0), 16829ec640STudor Ambarus SNOR_F_HAS_SR_TB = BIT(1), 17829ec640STudor Ambarus SNOR_F_NO_OP_CHIP_ERASE = BIT(2), 18829ec640STudor Ambarus SNOR_F_READY_XSR_RDY = BIT(3), 19829ec640STudor Ambarus SNOR_F_USE_CLSR = BIT(4), 20829ec640STudor Ambarus SNOR_F_BROKEN_RESET = BIT(5), 21829ec640STudor Ambarus SNOR_F_4B_OPCODES = BIT(6), 22829ec640STudor Ambarus SNOR_F_HAS_4BAIT = BIT(7), 23829ec640STudor Ambarus SNOR_F_HAS_LOCK = BIT(8), 24829ec640STudor Ambarus SNOR_F_HAS_16BIT_SR = BIT(9), 25829ec640STudor Ambarus SNOR_F_NO_READ_CR = BIT(10), 26829ec640STudor Ambarus SNOR_F_HAS_SR_TB_BIT6 = BIT(11), 2705635c14SJungseung Lee SNOR_F_HAS_4BIT_BP = BIT(12), 2805635c14SJungseung Lee SNOR_F_HAS_SR_BP3_BIT6 = BIT(13), 29829ec640STudor Ambarus }; 30829ec640STudor Ambarus 31829ec640STudor Ambarus struct spi_nor_read_command { 32829ec640STudor Ambarus u8 num_mode_clocks; 33829ec640STudor Ambarus u8 num_wait_states; 34829ec640STudor Ambarus u8 opcode; 35829ec640STudor Ambarus enum spi_nor_protocol proto; 36829ec640STudor Ambarus }; 37829ec640STudor Ambarus 38829ec640STudor Ambarus struct spi_nor_pp_command { 39829ec640STudor Ambarus u8 opcode; 40829ec640STudor Ambarus enum spi_nor_protocol proto; 41829ec640STudor Ambarus }; 42829ec640STudor Ambarus 43829ec640STudor Ambarus enum spi_nor_read_command_index { 44829ec640STudor Ambarus SNOR_CMD_READ, 45829ec640STudor Ambarus SNOR_CMD_READ_FAST, 46829ec640STudor Ambarus SNOR_CMD_READ_1_1_1_DTR, 47829ec640STudor Ambarus 48829ec640STudor Ambarus /* Dual SPI */ 49829ec640STudor Ambarus SNOR_CMD_READ_1_1_2, 50829ec640STudor Ambarus SNOR_CMD_READ_1_2_2, 51829ec640STudor Ambarus SNOR_CMD_READ_2_2_2, 52829ec640STudor Ambarus SNOR_CMD_READ_1_2_2_DTR, 53829ec640STudor Ambarus 54829ec640STudor Ambarus /* Quad SPI */ 55829ec640STudor Ambarus SNOR_CMD_READ_1_1_4, 56829ec640STudor Ambarus SNOR_CMD_READ_1_4_4, 57829ec640STudor Ambarus SNOR_CMD_READ_4_4_4, 58829ec640STudor Ambarus SNOR_CMD_READ_1_4_4_DTR, 59829ec640STudor Ambarus 60829ec640STudor Ambarus /* Octal SPI */ 61829ec640STudor Ambarus SNOR_CMD_READ_1_1_8, 62829ec640STudor Ambarus SNOR_CMD_READ_1_8_8, 63829ec640STudor Ambarus SNOR_CMD_READ_8_8_8, 64829ec640STudor Ambarus SNOR_CMD_READ_1_8_8_DTR, 65829ec640STudor Ambarus 66829ec640STudor Ambarus SNOR_CMD_READ_MAX 67829ec640STudor Ambarus }; 68829ec640STudor Ambarus 69829ec640STudor Ambarus enum spi_nor_pp_command_index { 70829ec640STudor Ambarus SNOR_CMD_PP, 71829ec640STudor Ambarus 72829ec640STudor Ambarus /* Quad SPI */ 73829ec640STudor Ambarus SNOR_CMD_PP_1_1_4, 74829ec640STudor Ambarus SNOR_CMD_PP_1_4_4, 75829ec640STudor Ambarus SNOR_CMD_PP_4_4_4, 76829ec640STudor Ambarus 77829ec640STudor Ambarus /* Octal SPI */ 78829ec640STudor Ambarus SNOR_CMD_PP_1_1_8, 79829ec640STudor Ambarus SNOR_CMD_PP_1_8_8, 80829ec640STudor Ambarus SNOR_CMD_PP_8_8_8, 81829ec640STudor Ambarus 82829ec640STudor Ambarus SNOR_CMD_PP_MAX 83829ec640STudor Ambarus }; 84829ec640STudor Ambarus 85829ec640STudor Ambarus /** 86829ec640STudor Ambarus * struct spi_nor_erase_type - Structure to describe a SPI NOR erase type 87829ec640STudor Ambarus * @size: the size of the sector/block erased by the erase type. 88829ec640STudor Ambarus * JEDEC JESD216B imposes erase sizes to be a power of 2. 89829ec640STudor Ambarus * @size_shift: @size is a power of 2, the shift is stored in 90829ec640STudor Ambarus * @size_shift. 91829ec640STudor Ambarus * @size_mask: the size mask based on @size_shift. 92829ec640STudor Ambarus * @opcode: the SPI command op code to erase the sector/block. 93829ec640STudor Ambarus * @idx: Erase Type index as sorted in the Basic Flash Parameter 94829ec640STudor Ambarus * Table. It will be used to synchronize the supported 95829ec640STudor Ambarus * Erase Types with the ones identified in the SFDP 96829ec640STudor Ambarus * optional tables. 97829ec640STudor Ambarus */ 98829ec640STudor Ambarus struct spi_nor_erase_type { 99829ec640STudor Ambarus u32 size; 100829ec640STudor Ambarus u32 size_shift; 101829ec640STudor Ambarus u32 size_mask; 102829ec640STudor Ambarus u8 opcode; 103829ec640STudor Ambarus u8 idx; 104829ec640STudor Ambarus }; 105829ec640STudor Ambarus 106829ec640STudor Ambarus /** 107829ec640STudor Ambarus * struct spi_nor_erase_command - Used for non-uniform erases 108829ec640STudor Ambarus * The structure is used to describe a list of erase commands to be executed 109829ec640STudor Ambarus * once we validate that the erase can be performed. The elements in the list 110829ec640STudor Ambarus * are run-length encoded. 111829ec640STudor Ambarus * @list: for inclusion into the list of erase commands. 112829ec640STudor Ambarus * @count: how many times the same erase command should be 113829ec640STudor Ambarus * consecutively used. 114829ec640STudor Ambarus * @size: the size of the sector/block erased by the command. 115829ec640STudor Ambarus * @opcode: the SPI command op code to erase the sector/block. 116829ec640STudor Ambarus */ 117829ec640STudor Ambarus struct spi_nor_erase_command { 118829ec640STudor Ambarus struct list_head list; 119829ec640STudor Ambarus u32 count; 120829ec640STudor Ambarus u32 size; 121829ec640STudor Ambarus u8 opcode; 122829ec640STudor Ambarus }; 123829ec640STudor Ambarus 124829ec640STudor Ambarus /** 125829ec640STudor Ambarus * struct spi_nor_erase_region - Structure to describe a SPI NOR erase region 126829ec640STudor Ambarus * @offset: the offset in the data array of erase region start. 127829ec640STudor Ambarus * LSB bits are used as a bitmask encoding flags to 128829ec640STudor Ambarus * determine if this region is overlaid, if this region is 129829ec640STudor Ambarus * the last in the SPI NOR flash memory and to indicate 130829ec640STudor Ambarus * all the supported erase commands inside this region. 131829ec640STudor Ambarus * The erase types are sorted in ascending order with the 132829ec640STudor Ambarus * smallest Erase Type size being at BIT(0). 133829ec640STudor Ambarus * @size: the size of the region in bytes. 134829ec640STudor Ambarus */ 135829ec640STudor Ambarus struct spi_nor_erase_region { 136829ec640STudor Ambarus u64 offset; 137829ec640STudor Ambarus u64 size; 138829ec640STudor Ambarus }; 139829ec640STudor Ambarus 140829ec640STudor Ambarus #define SNOR_ERASE_TYPE_MAX 4 141829ec640STudor Ambarus #define SNOR_ERASE_TYPE_MASK GENMASK_ULL(SNOR_ERASE_TYPE_MAX - 1, 0) 142829ec640STudor Ambarus 143829ec640STudor Ambarus #define SNOR_LAST_REGION BIT(4) 144829ec640STudor Ambarus #define SNOR_OVERLAID_REGION BIT(5) 145829ec640STudor Ambarus 146829ec640STudor Ambarus #define SNOR_ERASE_FLAGS_MAX 6 147829ec640STudor Ambarus #define SNOR_ERASE_FLAGS_MASK GENMASK_ULL(SNOR_ERASE_FLAGS_MAX - 1, 0) 148829ec640STudor Ambarus 149829ec640STudor Ambarus /** 150829ec640STudor Ambarus * struct spi_nor_erase_map - Structure to describe the SPI NOR erase map 151829ec640STudor Ambarus * @regions: array of erase regions. The regions are consecutive in 152829ec640STudor Ambarus * address space. Walking through the regions is done 153829ec640STudor Ambarus * incrementally. 154829ec640STudor Ambarus * @uniform_region: a pre-allocated erase region for SPI NOR with a uniform 155829ec640STudor Ambarus * sector size (legacy implementation). 156829ec640STudor Ambarus * @erase_type: an array of erase types shared by all the regions. 157829ec640STudor Ambarus * The erase types are sorted in ascending order, with the 158829ec640STudor Ambarus * smallest Erase Type size being the first member in the 159829ec640STudor Ambarus * erase_type array. 160829ec640STudor Ambarus * @uniform_erase_type: bitmask encoding erase types that can erase the 161829ec640STudor Ambarus * entire memory. This member is completed at init by 162829ec640STudor Ambarus * uniform and non-uniform SPI NOR flash memories if they 163829ec640STudor Ambarus * support at least one erase type that can erase the 164829ec640STudor Ambarus * entire memory. 165829ec640STudor Ambarus */ 166829ec640STudor Ambarus struct spi_nor_erase_map { 167829ec640STudor Ambarus struct spi_nor_erase_region *regions; 168829ec640STudor Ambarus struct spi_nor_erase_region uniform_region; 169829ec640STudor Ambarus struct spi_nor_erase_type erase_type[SNOR_ERASE_TYPE_MAX]; 170829ec640STudor Ambarus u8 uniform_erase_type; 171829ec640STudor Ambarus }; 172829ec640STudor Ambarus 173829ec640STudor Ambarus /** 174829ec640STudor Ambarus * struct spi_nor_locking_ops - SPI NOR locking methods 175829ec640STudor Ambarus * @lock: lock a region of the SPI NOR. 176829ec640STudor Ambarus * @unlock: unlock a region of the SPI NOR. 177829ec640STudor Ambarus * @is_locked: check if a region of the SPI NOR is completely locked 178829ec640STudor Ambarus */ 179829ec640STudor Ambarus struct spi_nor_locking_ops { 180829ec640STudor Ambarus int (*lock)(struct spi_nor *nor, loff_t ofs, uint64_t len); 181829ec640STudor Ambarus int (*unlock)(struct spi_nor *nor, loff_t ofs, uint64_t len); 182829ec640STudor Ambarus int (*is_locked)(struct spi_nor *nor, loff_t ofs, uint64_t len); 183829ec640STudor Ambarus }; 184829ec640STudor Ambarus 185829ec640STudor Ambarus /** 186829ec640STudor Ambarus * struct spi_nor_flash_parameter - SPI NOR flash parameters and settings. 187829ec640STudor Ambarus * Includes legacy flash parameters and settings that can be overwritten 188829ec640STudor Ambarus * by the spi_nor_fixups hooks, or dynamically when parsing the JESD216 189829ec640STudor Ambarus * Serial Flash Discoverable Parameters (SFDP) tables. 190829ec640STudor Ambarus * 191829ec640STudor Ambarus * @size: the flash memory density in bytes. 192829ec640STudor Ambarus * @page_size: the page size of the SPI NOR flash memory. 193829ec640STudor Ambarus * @hwcaps: describes the read and page program hardware 194829ec640STudor Ambarus * capabilities. 195829ec640STudor Ambarus * @reads: read capabilities ordered by priority: the higher index 196829ec640STudor Ambarus * in the array, the higher priority. 197829ec640STudor Ambarus * @page_programs: page program capabilities ordered by priority: the 198829ec640STudor Ambarus * higher index in the array, the higher priority. 199829ec640STudor Ambarus * @erase_map: the erase map parsed from the SFDP Sector Map Parameter 200829ec640STudor Ambarus * Table. 201*1afc0c89SYicong Yang * @quad_enable: enables SPI NOR quad mode. 202829ec640STudor Ambarus * @set_4byte_addr_mode: puts the SPI NOR in 4 byte addressing mode. 203829ec640STudor Ambarus * @convert_addr: converts an absolute address into something the flash 204829ec640STudor Ambarus * will understand. Particularly useful when pagesize is 205829ec640STudor Ambarus * not a power-of-2. 206829ec640STudor Ambarus * @setup: configures the SPI NOR memory. Useful for SPI NOR 207829ec640STudor Ambarus * flashes that have peculiarities to the SPI NOR standard 208829ec640STudor Ambarus * e.g. different opcodes, specific address calculation, 209829ec640STudor Ambarus * page size, etc. 210829ec640STudor Ambarus * @locking_ops: SPI NOR locking methods. 211829ec640STudor Ambarus */ 212829ec640STudor Ambarus struct spi_nor_flash_parameter { 213829ec640STudor Ambarus u64 size; 214829ec640STudor Ambarus u32 page_size; 215829ec640STudor Ambarus 216829ec640STudor Ambarus struct spi_nor_hwcaps hwcaps; 217829ec640STudor Ambarus struct spi_nor_read_command reads[SNOR_CMD_READ_MAX]; 218829ec640STudor Ambarus struct spi_nor_pp_command page_programs[SNOR_CMD_PP_MAX]; 219829ec640STudor Ambarus 220829ec640STudor Ambarus struct spi_nor_erase_map erase_map; 221829ec640STudor Ambarus 222*1afc0c89SYicong Yang int (*quad_enable)(struct spi_nor *nor); 223829ec640STudor Ambarus int (*set_4byte_addr_mode)(struct spi_nor *nor, bool enable); 224829ec640STudor Ambarus u32 (*convert_addr)(struct spi_nor *nor, u32 addr); 225829ec640STudor Ambarus int (*setup)(struct spi_nor *nor, const struct spi_nor_hwcaps *hwcaps); 226829ec640STudor Ambarus 227829ec640STudor Ambarus const struct spi_nor_locking_ops *locking_ops; 228829ec640STudor Ambarus }; 229829ec640STudor Ambarus 2304f50e102SBoris Brezillon /** 2314f50e102SBoris Brezillon * struct spi_nor_fixups - SPI NOR fixup hooks 2324f50e102SBoris Brezillon * @default_init: called after default flash parameters init. Used to tweak 2334f50e102SBoris Brezillon * flash parameters when information provided by the flash_info 2344f50e102SBoris Brezillon * table is incomplete or wrong. 2354f50e102SBoris Brezillon * @post_bfpt: called after the BFPT table has been parsed 2364f50e102SBoris Brezillon * @post_sfdp: called after SFDP has been parsed (is also called for SPI NORs 2374f50e102SBoris Brezillon * that do not support RDSFDP). Typically used to tweak various 2384f50e102SBoris Brezillon * parameters that could not be extracted by other means (i.e. 2394f50e102SBoris Brezillon * when information provided by the SFDP/flash_info tables are 2404f50e102SBoris Brezillon * incomplete or wrong). 2414f50e102SBoris Brezillon * 2424f50e102SBoris Brezillon * Those hooks can be used to tweak the SPI NOR configuration when the SFDP 2434f50e102SBoris Brezillon * table is broken or not available. 2444f50e102SBoris Brezillon */ 2454f50e102SBoris Brezillon struct spi_nor_fixups { 2464f50e102SBoris Brezillon void (*default_init)(struct spi_nor *nor); 2474f50e102SBoris Brezillon int (*post_bfpt)(struct spi_nor *nor, 2484f50e102SBoris Brezillon const struct sfdp_parameter_header *bfpt_header, 2494f50e102SBoris Brezillon const struct sfdp_bfpt *bfpt, 2504f50e102SBoris Brezillon struct spi_nor_flash_parameter *params); 2514f50e102SBoris Brezillon void (*post_sfdp)(struct spi_nor *nor); 2524f50e102SBoris Brezillon }; 2534f50e102SBoris Brezillon 2544f50e102SBoris Brezillon struct flash_info { 2554f50e102SBoris Brezillon char *name; 2564f50e102SBoris Brezillon 2574f50e102SBoris Brezillon /* 2584f50e102SBoris Brezillon * This array stores the ID bytes. 2594f50e102SBoris Brezillon * The first three bytes are the JEDIC ID. 2604f50e102SBoris Brezillon * JEDEC ID zero means "no ID" (mostly older chips). 2614f50e102SBoris Brezillon */ 2624f50e102SBoris Brezillon u8 id[SPI_NOR_MAX_ID_LEN]; 2634f50e102SBoris Brezillon u8 id_len; 2644f50e102SBoris Brezillon 2654f50e102SBoris Brezillon /* The size listed here is what works with SPINOR_OP_SE, which isn't 2664f50e102SBoris Brezillon * necessarily called a "sector" by the vendor. 2674f50e102SBoris Brezillon */ 2684f50e102SBoris Brezillon unsigned sector_size; 2694f50e102SBoris Brezillon u16 n_sectors; 2704f50e102SBoris Brezillon 2714f50e102SBoris Brezillon u16 page_size; 2724f50e102SBoris Brezillon u16 addr_width; 2734f50e102SBoris Brezillon 2744f50e102SBoris Brezillon u32 flags; 2754f50e102SBoris Brezillon #define SECT_4K BIT(0) /* SPINOR_OP_BE_4K works uniformly */ 2764f50e102SBoris Brezillon #define SPI_NOR_NO_ERASE BIT(1) /* No erase command needed */ 2774f50e102SBoris Brezillon #define SST_WRITE BIT(2) /* use SST byte programming */ 2784f50e102SBoris Brezillon #define SPI_NOR_NO_FR BIT(3) /* Can't do fastread */ 2794f50e102SBoris Brezillon #define SECT_4K_PMC BIT(4) /* SPINOR_OP_BE_4K_PMC works uniformly */ 2804f50e102SBoris Brezillon #define SPI_NOR_DUAL_READ BIT(5) /* Flash supports Dual Read */ 2814f50e102SBoris Brezillon #define SPI_NOR_QUAD_READ BIT(6) /* Flash supports Quad Read */ 2824f50e102SBoris Brezillon #define USE_FSR BIT(7) /* use flag status register */ 2834f50e102SBoris Brezillon #define SPI_NOR_HAS_LOCK BIT(8) /* Flash supports lock/unlock via SR */ 2844f50e102SBoris Brezillon #define SPI_NOR_HAS_TB BIT(9) /* 2854f50e102SBoris Brezillon * Flash SR has Top/Bottom (TB) protect 2864f50e102SBoris Brezillon * bit. Must be used with 2874f50e102SBoris Brezillon * SPI_NOR_HAS_LOCK. 2884f50e102SBoris Brezillon */ 2894f50e102SBoris Brezillon #define SPI_NOR_XSR_RDY BIT(10) /* 2904f50e102SBoris Brezillon * S3AN flashes have specific opcode to 2914f50e102SBoris Brezillon * read the status register. 2924f50e102SBoris Brezillon */ 2934f50e102SBoris Brezillon #define SPI_NOR_4B_OPCODES BIT(11) /* 2944f50e102SBoris Brezillon * Use dedicated 4byte address op codes 2954f50e102SBoris Brezillon * to support memory size above 128Mib. 2964f50e102SBoris Brezillon */ 2974f50e102SBoris Brezillon #define NO_CHIP_ERASE BIT(12) /* Chip does not support chip erase */ 2984f50e102SBoris Brezillon #define SPI_NOR_SKIP_SFDP BIT(13) /* Skip parsing of SFDP tables */ 2994f50e102SBoris Brezillon #define USE_CLSR BIT(14) /* use CLSR command */ 3004f50e102SBoris Brezillon #define SPI_NOR_OCTAL_READ BIT(15) /* Flash supports Octal Read */ 3014f50e102SBoris Brezillon #define SPI_NOR_TB_SR_BIT6 BIT(16) /* 3024f50e102SBoris Brezillon * Top/Bottom (TB) is bit 6 of 3034f50e102SBoris Brezillon * status register. Must be used with 3044f50e102SBoris Brezillon * SPI_NOR_HAS_TB. 3054f50e102SBoris Brezillon */ 30605635c14SJungseung Lee #define SPI_NOR_4BIT_BP BIT(17) /* 30705635c14SJungseung Lee * Flash SR has 4 bit fields (BP0-3) 30805635c14SJungseung Lee * for block protection. 30905635c14SJungseung Lee */ 31005635c14SJungseung Lee #define SPI_NOR_BP3_SR_BIT6 BIT(18) /* 31105635c14SJungseung Lee * BP3 is bit 6 of status register. 31205635c14SJungseung Lee * Must be used with SPI_NOR_4BIT_BP. 31305635c14SJungseung Lee */ 3144f50e102SBoris Brezillon 3154f50e102SBoris Brezillon /* Part specific fixup hooks. */ 3164f50e102SBoris Brezillon const struct spi_nor_fixups *fixups; 3174f50e102SBoris Brezillon }; 3184f50e102SBoris Brezillon 3194f50e102SBoris Brezillon /* Used when the "_ext_id" is two bytes at most */ 3204f50e102SBoris Brezillon #define INFO(_jedec_id, _ext_id, _sector_size, _n_sectors, _flags) \ 3214f50e102SBoris Brezillon .id = { \ 3224f50e102SBoris Brezillon ((_jedec_id) >> 16) & 0xff, \ 3234f50e102SBoris Brezillon ((_jedec_id) >> 8) & 0xff, \ 3244f50e102SBoris Brezillon (_jedec_id) & 0xff, \ 3254f50e102SBoris Brezillon ((_ext_id) >> 8) & 0xff, \ 3264f50e102SBoris Brezillon (_ext_id) & 0xff, \ 3274f50e102SBoris Brezillon }, \ 3284f50e102SBoris Brezillon .id_len = (!(_jedec_id) ? 0 : (3 + ((_ext_id) ? 2 : 0))), \ 3294f50e102SBoris Brezillon .sector_size = (_sector_size), \ 3304f50e102SBoris Brezillon .n_sectors = (_n_sectors), \ 3314f50e102SBoris Brezillon .page_size = 256, \ 3324f50e102SBoris Brezillon .flags = (_flags), 3334f50e102SBoris Brezillon 3344f50e102SBoris Brezillon #define INFO6(_jedec_id, _ext_id, _sector_size, _n_sectors, _flags) \ 3354f50e102SBoris Brezillon .id = { \ 3364f50e102SBoris Brezillon ((_jedec_id) >> 16) & 0xff, \ 3374f50e102SBoris Brezillon ((_jedec_id) >> 8) & 0xff, \ 3384f50e102SBoris Brezillon (_jedec_id) & 0xff, \ 3394f50e102SBoris Brezillon ((_ext_id) >> 16) & 0xff, \ 3404f50e102SBoris Brezillon ((_ext_id) >> 8) & 0xff, \ 3414f50e102SBoris Brezillon (_ext_id) & 0xff, \ 3424f50e102SBoris Brezillon }, \ 3434f50e102SBoris Brezillon .id_len = 6, \ 3444f50e102SBoris Brezillon .sector_size = (_sector_size), \ 3454f50e102SBoris Brezillon .n_sectors = (_n_sectors), \ 3464f50e102SBoris Brezillon .page_size = 256, \ 3474f50e102SBoris Brezillon .flags = (_flags), 3484f50e102SBoris Brezillon 3494f50e102SBoris Brezillon #define CAT25_INFO(_sector_size, _n_sectors, _page_size, _addr_width, _flags) \ 3504f50e102SBoris Brezillon .sector_size = (_sector_size), \ 3514f50e102SBoris Brezillon .n_sectors = (_n_sectors), \ 3524f50e102SBoris Brezillon .page_size = (_page_size), \ 3534f50e102SBoris Brezillon .addr_width = (_addr_width), \ 3544f50e102SBoris Brezillon .flags = (_flags), 3554f50e102SBoris Brezillon 3564f50e102SBoris Brezillon #define S3AN_INFO(_jedec_id, _n_sectors, _page_size) \ 3574f50e102SBoris Brezillon .id = { \ 3584f50e102SBoris Brezillon ((_jedec_id) >> 16) & 0xff, \ 3594f50e102SBoris Brezillon ((_jedec_id) >> 8) & 0xff, \ 3604f50e102SBoris Brezillon (_jedec_id) & 0xff \ 3614f50e102SBoris Brezillon }, \ 3624f50e102SBoris Brezillon .id_len = 3, \ 3634f50e102SBoris Brezillon .sector_size = (8*_page_size), \ 3644f50e102SBoris Brezillon .n_sectors = (_n_sectors), \ 3654f50e102SBoris Brezillon .page_size = _page_size, \ 3664f50e102SBoris Brezillon .addr_width = 3, \ 3672d47cac1SBoris Brezillon .flags = SPI_NOR_NO_FR | SPI_NOR_XSR_RDY, 3684f50e102SBoris Brezillon 3699ec4bbcbSBoris Brezillon /** 3709ec4bbcbSBoris Brezillon * struct spi_nor_manufacturer - SPI NOR manufacturer object 3719ec4bbcbSBoris Brezillon * @name: manufacturer name 3729ec4bbcbSBoris Brezillon * @parts: array of parts supported by this manufacturer 3739ec4bbcbSBoris Brezillon * @nparts: number of entries in the parts array 3749ec4bbcbSBoris Brezillon * @fixups: hooks called at various points in time during spi_nor_scan() 3759ec4bbcbSBoris Brezillon */ 3769ec4bbcbSBoris Brezillon struct spi_nor_manufacturer { 3779ec4bbcbSBoris Brezillon const char *name; 3789ec4bbcbSBoris Brezillon const struct flash_info *parts; 3799ec4bbcbSBoris Brezillon unsigned int nparts; 3809ec4bbcbSBoris Brezillon const struct spi_nor_fixups *fixups; 3819ec4bbcbSBoris Brezillon }; 3829ec4bbcbSBoris Brezillon 383f7242bfcSBoris Brezillon /* Manufacturer drivers. */ 384f7242bfcSBoris Brezillon extern const struct spi_nor_manufacturer spi_nor_atmel; 385d8259257SBoris Brezillon extern const struct spi_nor_manufacturer spi_nor_catalyst; 386d22a3be6SBoris Brezillon extern const struct spi_nor_manufacturer spi_nor_eon; 38774c7e0e3SBoris Brezillon extern const struct spi_nor_manufacturer spi_nor_esmt; 3887bdbd1ceSBoris Brezillon extern const struct spi_nor_manufacturer spi_nor_everspin; 389893218a8SBoris Brezillon extern const struct spi_nor_manufacturer spi_nor_fujitsu; 390acb96ecdSBoris Brezillon extern const struct spi_nor_manufacturer spi_nor_gigadevice; 391aa635187SBoris Brezillon extern const struct spi_nor_manufacturer spi_nor_intel; 3920a371981SBoris Brezillon extern const struct spi_nor_manufacturer spi_nor_issi; 39310526d85SBoris Brezillon extern const struct spi_nor_manufacturer spi_nor_macronix; 39415f5c7e5SBoris Brezillon extern const struct spi_nor_manufacturer spi_nor_micron; 39515f5c7e5SBoris Brezillon extern const struct spi_nor_manufacturer spi_nor_st; 3960173c32aSBoris Brezillon extern const struct spi_nor_manufacturer spi_nor_spansion; 397c53b3f92SBoris Brezillon extern const struct spi_nor_manufacturer spi_nor_sst; 3987b8b2201SBoris Brezillon extern const struct spi_nor_manufacturer spi_nor_winbond; 3992d47cac1SBoris Brezillon extern const struct spi_nor_manufacturer spi_nor_xilinx; 400a674d5a6SBoris Brezillon extern const struct spi_nor_manufacturer spi_nor_xmc; 401f7242bfcSBoris Brezillon 4024f50e102SBoris Brezillon int spi_nor_write_enable(struct spi_nor *nor); 4034f50e102SBoris Brezillon int spi_nor_write_disable(struct spi_nor *nor); 4044f50e102SBoris Brezillon int spi_nor_set_4byte_addr_mode(struct spi_nor *nor, bool enable); 4054f50e102SBoris Brezillon int spi_nor_write_ear(struct spi_nor *nor, u8 ear); 4064f50e102SBoris Brezillon int spi_nor_wait_till_ready(struct spi_nor *nor); 4074f50e102SBoris Brezillon int spi_nor_lock_and_prep(struct spi_nor *nor); 4084f50e102SBoris Brezillon void spi_nor_unlock_and_unprep(struct spi_nor *nor); 409*1afc0c89SYicong Yang int spi_nor_sr1_bit6_quad_enable(struct spi_nor *nor); 410*1afc0c89SYicong Yang int spi_nor_sr2_bit1_quad_enable(struct spi_nor *nor); 411*1afc0c89SYicong Yang int spi_nor_sr2_bit7_quad_enable(struct spi_nor *nor); 412cb481b92STudor Ambarus 4134f50e102SBoris Brezillon int spi_nor_xread_sr(struct spi_nor *nor, u8 *sr); 414cb481b92STudor Ambarus ssize_t spi_nor_read_data(struct spi_nor *nor, loff_t from, size_t len, 415cb481b92STudor Ambarus u8 *buf); 4164f50e102SBoris Brezillon ssize_t spi_nor_write_data(struct spi_nor *nor, loff_t to, size_t len, 4174f50e102SBoris Brezillon const u8 *buf); 418cb481b92STudor Ambarus 419cb481b92STudor Ambarus int spi_nor_hwcaps_read2cmd(u32 hwcaps); 420cb481b92STudor Ambarus u8 spi_nor_convert_3to4_read(u8 opcode); 421cb481b92STudor Ambarus void spi_nor_set_pp_settings(struct spi_nor_pp_command *pp, u8 opcode, 422cb481b92STudor Ambarus enum spi_nor_protocol proto); 423cb481b92STudor Ambarus 424cb481b92STudor Ambarus void spi_nor_set_erase_type(struct spi_nor_erase_type *erase, u32 size, 425cb481b92STudor Ambarus u8 opcode); 426cb481b92STudor Ambarus struct spi_nor_erase_region * 427cb481b92STudor Ambarus spi_nor_region_next(struct spi_nor_erase_region *region); 428cb481b92STudor Ambarus void spi_nor_init_uniform_erase_map(struct spi_nor_erase_map *map, 429cb481b92STudor Ambarus u8 erase_mask, u64 flash_size); 430cb481b92STudor Ambarus 431cb481b92STudor Ambarus int spi_nor_post_bfpt_fixups(struct spi_nor *nor, 432cb481b92STudor Ambarus const struct sfdp_parameter_header *bfpt_header, 433cb481b92STudor Ambarus const struct sfdp_bfpt *bfpt, 434cb481b92STudor Ambarus struct spi_nor_flash_parameter *params); 435cb481b92STudor Ambarus 4364f50e102SBoris Brezillon static struct spi_nor __maybe_unused *mtd_to_spi_nor(struct mtd_info *mtd) 4374f50e102SBoris Brezillon { 4384f50e102SBoris Brezillon return mtd->priv; 4394f50e102SBoris Brezillon } 4404f50e102SBoris Brezillon 441cb481b92STudor Ambarus #endif /* __LINUX_MTD_SPI_NOR_INTERNAL_H */ 442