Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Haavard Skinnemoen | d25ce7d | 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 | a5e8199 | 2013-10-02 19:38:49 +0530 | [diff] [blame] | 6 | * Copyright (C) 2013 Jagannadha Sutradharudu Teki, Xilinx Inc. |
Haavard Skinnemoen | d25ce7d | 2008-05-16 11:10:33 +0200 | [diff] [blame] | 7 | */ |
| 8 | |
Jagannadha Sutradharudu Teki | 469146c | 2013-10-10 22:14:09 +0530 | [diff] [blame] | 9 | #ifndef _SF_INTERNAL_H_ |
| 10 | #define _SF_INTERNAL_H_ |
Haavard Skinnemoen | d25ce7d | 2008-05-16 11:10:33 +0200 | [diff] [blame] | 11 | |
Simon Glass | ff0960f | 2014-10-13 23:42:04 -0600 | [diff] [blame] | 12 | #include <linux/types.h> |
| 13 | #include <linux/compiler.h> |
| 14 | |
Vignesh R | c4e8862 | 2019-02-05 11:29:23 +0530 | [diff] [blame] | 15 | #define SPI_NOR_MAX_ID_LEN 6 |
| 16 | #define SPI_NOR_MAX_ADDR_WIDTH 4 |
Simon Glass | ff0960f | 2014-10-13 23:42:04 -0600 | [diff] [blame] | 17 | |
Vignesh R | c4e8862 | 2019-02-05 11:29:23 +0530 | [diff] [blame] | 18 | struct flash_info { |
Vignesh R | 778572d | 2019-02-05 11:29:25 +0530 | [diff] [blame] | 19 | #if !CONFIG_IS_ENABLED(SPI_FLASH_TINY) |
Vignesh R | c4e8862 | 2019-02-05 11:29:23 +0530 | [diff] [blame] | 20 | char *name; |
Vignesh R | 778572d | 2019-02-05 11:29:25 +0530 | [diff] [blame] | 21 | #endif |
Jagan Teki | f790ca7 | 2016-10-30 23:16:10 +0530 | [diff] [blame] | 22 | |
| 23 | /* |
| 24 | * This array stores the ID bytes. |
| 25 | * The first three bytes are the JEDIC ID. |
| 26 | * JEDEC ID zero means "no ID" (mostly older chips). |
| 27 | */ |
Vignesh R | c4e8862 | 2019-02-05 11:29:23 +0530 | [diff] [blame] | 28 | u8 id[SPI_NOR_MAX_ID_LEN]; |
Jagan Teki | f790ca7 | 2016-10-30 23:16:10 +0530 | [diff] [blame] | 29 | u8 id_len; |
| 30 | |
Vignesh R | c4e8862 | 2019-02-05 11:29:23 +0530 | [diff] [blame] | 31 | /* The size listed here is what works with SPINOR_OP_SE, which isn't |
Jagan Teki | f3bf2e5 | 2016-10-30 23:16:13 +0530 | [diff] [blame] | 32 | * necessarily called a "sector" by the vendor. |
| 33 | */ |
Vignesh R | c4e8862 | 2019-02-05 11:29:23 +0530 | [diff] [blame] | 34 | unsigned int sector_size; |
| 35 | u16 n_sectors; |
Jagan Teki | 3632c8e | 2016-08-08 19:25:55 +0530 | [diff] [blame] | 36 | |
Jagan Teki | f3bf2e5 | 2016-10-30 23:16:13 +0530 | [diff] [blame] | 37 | u16 page_size; |
Vignesh R | c4e8862 | 2019-02-05 11:29:23 +0530 | [diff] [blame] | 38 | u16 addr_width; |
Jagan Teki | f790ca7 | 2016-10-30 23:16:10 +0530 | [diff] [blame] | 39 | |
Jagan Teki | f3bf2e5 | 2016-10-30 23:16:13 +0530 | [diff] [blame] | 40 | u16 flags; |
Vignesh R | c4e8862 | 2019-02-05 11:29:23 +0530 | [diff] [blame] | 41 | #define SECT_4K BIT(0) /* SPINOR_OP_BE_4K works uniformly */ |
| 42 | #define SPI_NOR_NO_ERASE BIT(1) /* No erase command needed */ |
| 43 | #define SST_WRITE BIT(2) /* use SST byte programming */ |
| 44 | #define SPI_NOR_NO_FR BIT(3) /* Can't do fastread */ |
| 45 | #define SECT_4K_PMC BIT(4) /* SPINOR_OP_BE_4K_PMC works uniformly */ |
| 46 | #define SPI_NOR_DUAL_READ BIT(5) /* Flash supports Dual Read */ |
| 47 | #define SPI_NOR_QUAD_READ BIT(6) /* Flash supports Quad Read */ |
| 48 | #define USE_FSR BIT(7) /* use flag status register */ |
| 49 | #define SPI_NOR_HAS_LOCK BIT(8) /* Flash supports lock/unlock via SR */ |
| 50 | #define SPI_NOR_HAS_TB BIT(9) /* |
| 51 | * Flash SR has Top/Bottom (TB) protect |
| 52 | * bit. Must be used with |
| 53 | * SPI_NOR_HAS_LOCK. |
| 54 | */ |
| 55 | #define SPI_S3AN BIT(10) /* |
| 56 | * Xilinx Spartan 3AN In-System Flash |
| 57 | * (MFR cannot be used for probing |
| 58 | * because it has the same value as |
| 59 | * ATMEL flashes) |
| 60 | */ |
| 61 | #define SPI_NOR_4B_OPCODES BIT(11) /* |
| 62 | * Use dedicated 4byte address op codes |
| 63 | * to support memory size above 128Mib. |
| 64 | */ |
| 65 | #define NO_CHIP_ERASE BIT(12) /* Chip does not support chip erase */ |
| 66 | #define SPI_NOR_SKIP_SFDP BIT(13) /* Skip parsing of SFDP tables */ |
| 67 | #define USE_CLSR BIT(14) /* use CLSR command */ |
Simon Glass | ff0960f | 2014-10-13 23:42:04 -0600 | [diff] [blame] | 68 | }; |
| 69 | |
Vignesh R | c4e8862 | 2019-02-05 11:29:23 +0530 | [diff] [blame] | 70 | extern const struct flash_info spi_nor_ids[]; |
| 71 | |
| 72 | #define JEDEC_MFR(info) ((info)->id[0]) |
| 73 | #define JEDEC_ID(info) (((info)->id[1]) << 8 | ((info)->id[2])) |
Simon Glass | ff0960f | 2014-10-13 23:42:04 -0600 | [diff] [blame] | 74 | |
Haavard Skinnemoen | d25ce7d | 2008-05-16 11:10:33 +0200 | [diff] [blame] | 75 | /* Send a single-byte command to the device and read the response */ |
| 76 | int spi_flash_cmd(struct spi_slave *spi, u8 cmd, void *response, size_t len); |
| 77 | |
| 78 | /* |
| 79 | * Send a multi-byte command to the device and read the response. Used |
| 80 | * for flash array reads, etc. |
| 81 | */ |
| 82 | int spi_flash_cmd_read(struct spi_slave *spi, const u8 *cmd, |
| 83 | size_t cmd_len, void *data, size_t data_len); |
| 84 | |
| 85 | /* |
| 86 | * Send a multi-byte command to the device followed by (optional) |
| 87 | * data. Used for programming the flash array, etc. |
| 88 | */ |
| 89 | int spi_flash_cmd_write(struct spi_slave *spi, const u8 *cmd, size_t cmd_len, |
| 90 | const void *data, size_t data_len); |
| 91 | |
Mike Frysinger | d4aa500 | 2011-04-25 06:58:29 +0000 | [diff] [blame] | 92 | |
Simon Glass | a58986c | 2018-11-06 15:21:41 -0700 | [diff] [blame] | 93 | /* Get software write-protect value (BP bits) */ |
| 94 | int spi_flash_cmd_get_sw_write_prot(struct spi_flash *flash); |
| 95 | |
Jagannadha Sutradharudu Teki | a5e8199 | 2013-10-02 19:38:49 +0530 | [diff] [blame] | 96 | |
Daniel Schwierzeck | 9fe6d87 | 2015-04-27 07:42:04 +0200 | [diff] [blame] | 97 | #ifdef CONFIG_SPI_FLASH_MTD |
| 98 | int spi_flash_mtd_register(struct spi_flash *flash); |
| 99 | void spi_flash_mtd_unregister(void); |
| 100 | #endif |
Jagannadha Sutradharudu Teki | 469146c | 2013-10-10 22:14:09 +0530 | [diff] [blame] | 101 | #endif /* _SF_INTERNAL_H_ */ |