Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Haavard Skinnemoen | 2f5bfb7 | 2008-05-16 11:10:33 +0200 | [diff] [blame] | 2 | /* |
| 3 | * SPI flash internal definitions |
| 4 | * |
| 5 | * Copyright (C) 2008 Atmel Corporation |
Jagannadha Sutradharudu Teki | 25dc86a | 2013-10-02 19:38:49 +0530 | [diff] [blame] | 6 | * Copyright (C) 2013 Jagannadha Sutradharudu Teki, Xilinx Inc. |
Haavard Skinnemoen | 2f5bfb7 | 2008-05-16 11:10:33 +0200 | [diff] [blame] | 7 | */ |
| 8 | |
Jagannadha Sutradharudu Teki | 84fb863 | 2013-10-10 22:14:09 +0530 | [diff] [blame] | 9 | #ifndef _SF_INTERNAL_H_ |
| 10 | #define _SF_INTERNAL_H_ |
Haavard Skinnemoen | 2f5bfb7 | 2008-05-16 11:10:33 +0200 | [diff] [blame] | 11 | |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 12 | #include <linux/bitops.h> |
Simon Glass | d34b456 | 2014-10-13 23:42:04 -0600 | [diff] [blame] | 13 | #include <linux/types.h> |
| 14 | #include <linux/compiler.h> |
| 15 | |
Vignesh R | 1451041 | 2019-02-05 11:29:23 +0530 | [diff] [blame] | 16 | #define SPI_NOR_MAX_ID_LEN 6 |
| 17 | #define SPI_NOR_MAX_ADDR_WIDTH 4 |
Mike Frysinger | 37e13bc | 2011-01-10 02:20:12 -0500 | [diff] [blame] | 18 | |
Vignesh R | 1451041 | 2019-02-05 11:29:23 +0530 | [diff] [blame] | 19 | struct flash_info { |
Vignesh R | 3f5fb8b | 2019-02-05 11:29:25 +0530 | [diff] [blame] | 20 | #if !CONFIG_IS_ENABLED(SPI_FLASH_TINY) |
Vignesh R | 1451041 | 2019-02-05 11:29:23 +0530 | [diff] [blame] | 21 | char *name; |
Vignesh R | 3f5fb8b | 2019-02-05 11:29:25 +0530 | [diff] [blame] | 22 | #endif |
Jagan Teki | 77ae47b | 2016-10-30 23:16:10 +0530 | [diff] [blame] | 23 | |
| 24 | /* |
| 25 | * This array stores the ID bytes. |
| 26 | * The first three bytes are the JEDIC ID. |
| 27 | * JEDEC ID zero means "no ID" (mostly older chips). |
| 28 | */ |
Vignesh R | 1451041 | 2019-02-05 11:29:23 +0530 | [diff] [blame] | 29 | u8 id[SPI_NOR_MAX_ID_LEN]; |
Jagan Teki | 77ae47b | 2016-10-30 23:16:10 +0530 | [diff] [blame] | 30 | u8 id_len; |
| 31 | |
Vignesh R | 1451041 | 2019-02-05 11:29:23 +0530 | [diff] [blame] | 32 | /* The size listed here is what works with SPINOR_OP_SE, which isn't |
Jagan Teki | b7faef5 | 2016-10-30 23:16:13 +0530 | [diff] [blame] | 33 | * necessarily called a "sector" by the vendor. |
| 34 | */ |
Vignesh R | 1451041 | 2019-02-05 11:29:23 +0530 | [diff] [blame] | 35 | unsigned int sector_size; |
| 36 | u16 n_sectors; |
Jagan Teki | 235afa8 | 2016-08-08 19:25:55 +0530 | [diff] [blame] | 37 | |
Jagan Teki | b7faef5 | 2016-10-30 23:16:13 +0530 | [diff] [blame] | 38 | u16 page_size; |
Vignesh R | 1451041 | 2019-02-05 11:29:23 +0530 | [diff] [blame] | 39 | u16 addr_width; |
Jagan Teki | 77ae47b | 2016-10-30 23:16:10 +0530 | [diff] [blame] | 40 | |
Vignesh Raghavendra | c063ee3 | 2019-12-05 15:46:05 +0530 | [diff] [blame] | 41 | u32 flags; |
Vignesh R | 1451041 | 2019-02-05 11:29:23 +0530 | [diff] [blame] | 42 | #define SECT_4K BIT(0) /* SPINOR_OP_BE_4K works uniformly */ |
| 43 | #define SPI_NOR_NO_ERASE BIT(1) /* No erase command needed */ |
| 44 | #define SST_WRITE BIT(2) /* use SST byte programming */ |
| 45 | #define SPI_NOR_NO_FR BIT(3) /* Can't do fastread */ |
| 46 | #define SECT_4K_PMC BIT(4) /* SPINOR_OP_BE_4K_PMC works uniformly */ |
| 47 | #define SPI_NOR_DUAL_READ BIT(5) /* Flash supports Dual Read */ |
| 48 | #define SPI_NOR_QUAD_READ BIT(6) /* Flash supports Quad Read */ |
| 49 | #define USE_FSR BIT(7) /* use flag status register */ |
| 50 | #define SPI_NOR_HAS_LOCK BIT(8) /* Flash supports lock/unlock via SR */ |
| 51 | #define SPI_NOR_HAS_TB BIT(9) /* |
| 52 | * Flash SR has Top/Bottom (TB) protect |
| 53 | * bit. Must be used with |
| 54 | * SPI_NOR_HAS_LOCK. |
| 55 | */ |
| 56 | #define SPI_S3AN BIT(10) /* |
| 57 | * Xilinx Spartan 3AN In-System Flash |
| 58 | * (MFR cannot be used for probing |
| 59 | * because it has the same value as |
| 60 | * ATMEL flashes) |
| 61 | */ |
| 62 | #define SPI_NOR_4B_OPCODES BIT(11) /* |
| 63 | * Use dedicated 4byte address op codes |
| 64 | * to support memory size above 128Mib. |
| 65 | */ |
| 66 | #define NO_CHIP_ERASE BIT(12) /* Chip does not support chip erase */ |
| 67 | #define SPI_NOR_SKIP_SFDP BIT(13) /* Skip parsing of SFDP tables */ |
| 68 | #define USE_CLSR BIT(14) /* use CLSR command */ |
Eugeniy Paltsev | 04a11a6 | 2019-09-09 22:33:14 +0300 | [diff] [blame] | 69 | #define SPI_NOR_HAS_SST26LOCK BIT(15) /* Flash supports lock/unlock via BPR */ |
Michal Simek | 2074592 | 2020-10-26 11:28:27 +0100 | [diff] [blame] | 70 | #define SPI_NOR_OCTAL_READ BIT(16) /* Flash supports Octal Read */ |
Pratyush Yadav | be389f6 | 2021-06-26 00:47:16 +0530 | [diff] [blame] | 71 | #define SPI_NOR_OCTAL_DTR_READ BIT(17) /* Flash supports Octal DTR Read */ |
Simon Glass | d34b456 | 2014-10-13 23:42:04 -0600 | [diff] [blame] | 72 | }; |
| 73 | |
Vignesh R | 1451041 | 2019-02-05 11:29:23 +0530 | [diff] [blame] | 74 | extern const struct flash_info spi_nor_ids[]; |
| 75 | |
| 76 | #define JEDEC_MFR(info) ((info)->id[0]) |
| 77 | #define JEDEC_ID(info) (((info)->id[1]) << 8 | ((info)->id[2])) |
Simon Glass | d34b456 | 2014-10-13 23:42:04 -0600 | [diff] [blame] | 78 | |
Simon Glass | 61d0464 | 2021-03-15 18:11:17 +1300 | [diff] [blame] | 79 | /* Get software write-protect value (BP bits) */ |
| 80 | int spi_flash_cmd_get_sw_write_prot(struct spi_flash *flash); |
| 81 | |
| 82 | |
Frieder Schrempf | d7be62c | 2019-10-23 07:41:20 +0000 | [diff] [blame] | 83 | #if CONFIG_IS_ENABLED(SPI_FLASH_MTD) |
Daniel Schwierzeck | 06cfc03 | 2015-04-27 07:42:04 +0200 | [diff] [blame] | 84 | int spi_flash_mtd_register(struct spi_flash *flash); |
Marek BehĂșn | c1fcc14 | 2021-05-26 14:08:20 +0200 | [diff] [blame] | 85 | void spi_flash_mtd_unregister(struct spi_flash *flash); |
Jagan Teki | 380cdbe | 2020-05-13 00:11:27 +0530 | [diff] [blame] | 86 | #else |
| 87 | static inline int spi_flash_mtd_register(struct spi_flash *flash) |
| 88 | { |
| 89 | return 0; |
| 90 | } |
| 91 | |
Marek BehĂșn | c1fcc14 | 2021-05-26 14:08:20 +0200 | [diff] [blame] | 92 | static inline void spi_flash_mtd_unregister(struct spi_flash *flash) |
Jagan Teki | 380cdbe | 2020-05-13 00:11:27 +0530 | [diff] [blame] | 93 | { |
| 94 | } |
Daniel Schwierzeck | 06cfc03 | 2015-04-27 07:42:04 +0200 | [diff] [blame] | 95 | #endif |
Jagan Teki | 380cdbe | 2020-05-13 00:11:27 +0530 | [diff] [blame] | 96 | |
Jagannadha Sutradharudu Teki | 84fb863 | 2013-10-10 22:14:09 +0530 | [diff] [blame] | 97 | #endif /* _SF_INTERNAL_H_ */ |