1 /*
2  * Copyright (c) 2018 Savoir-Faire Linux.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef __SPI_NOR_H__
8 #define __SPI_NOR_H__
9 
10 #include <sys/util.h>
11 
12 #define SPI_NOR_MAX_ID_LEN	3
13 
14 /* Status register bits */
15 #define SPI_NOR_WIP_BIT         BIT(0)  /* Write in progress */
16 #define SPI_NOR_WEL_BIT         BIT(1)  /* Write enable latch */
17 
18 /* Flash opcodes */
19 #define SPI_NOR_CMD_WRSR        0x01    /* Write status register */
20 #define SPI_NOR_CMD_RDSR        0x05    /* Read status register */
21 #define SPI_NOR_CMD_READ        0x03    /* Read data */
22 #define SPI_NOR_CMD_WREN        0x06    /* Write enable */
23 #define SPI_NOR_CMD_WRDI        0x04    /* Write disable */
24 #define SPI_NOR_CMD_PP          0x02    /* Page program */
25 #define SPI_NOR_CMD_SE          0x20    /* Sector erase */
26 #define SPI_NOR_CMD_BE_32K      0x52    /* Block erase 32KB */
27 #define SPI_NOR_CMD_BE          0xD8    /* Block erase */
28 #define SPI_NOR_CMD_CE          0xC7    /* Chip erase */
29 #define SPI_NOR_CMD_RDID        0x9F    /* Read JEDEC ID */
30 #define SPI_NOR_CMD_ULBPR       0x98    /* Global Block Protection Unlock */
31 #define SPI_NOR_CMD_4BA         0xB7    /* Enter 4-Byte Address Mode */
32 #define SPI_NOR_CMD_DPD         0xB9    /* Deep Power Down */
33 #define SPI_NOR_CMD_RDPD        0xAB    /* Release from Deep Power Down */
34 
35 /* Page, sector, and block size are standard, not configurable. */
36 #define SPI_NOR_PAGE_SIZE    0x0100U
37 #define SPI_NOR_SECTOR_SIZE  0x1000U
38 #define SPI_NOR_BLOCK_SIZE   0x10000U
39 
40 /* Test whether offset is aligned to a given number of bits. */
41 #define SPI_NOR_IS_ALIGNED(_ofs, _bits) (((_ofs) & BIT_MASK(_bits)) == 0)
42 #define SPI_NOR_IS_SECTOR_ALIGNED(_ofs) SPI_NOR_IS_ALIGNED(_ofs, 12)
43 
44 #endif /*__SPI_NOR_H__*/
45