Allow to use bit mask in asm code
[oweals/u-boot_mod.git] / u-boot / include / flash.h
1 /*
2  * Copyright (C) 2015 Piotr Dymacz <piotr@dymacz.pl>
3  * Copyright (C) 2005 Wolfgang Denk, DENX Software Engineering, <wd@denx.de>
4  *
5  * SPDX-License-Identifier:GPL-2.0
6  */
7
8 #ifndef _FLASH_H_
9 #define _FLASH_H_
10
11 #ifndef CFG_NO_FLASH
12
13 /*
14  * Struct for info about FLASH chip/bank, with:
15  * - manufacturer and model names
16  * - JEDEC ID (combined device & manufacturer code)
17  * - total bank size in bytes
18  * - size of erase unit in bytes
19  * - bank number
20  * - size of program page in bytes
21  * - number of erase units
22  * - erase command
23  * - physical sector start addresses
24  */
25 typedef struct {
26         char *manuf_name;
27         char *model_name;
28         u32 flash_id;
29         u32 size;
30         u32 sector_size;
31         u32 bank;
32         u16 page_size;
33         u16 sector_count;
34         u8  erase_cmd;
35         u32 start[CFG_MAX_FLASH_SECT];
36 } flash_info_t;
37
38 extern flash_info_t flash_info[];
39
40 /*
41  * Struct for info about supported SPI NOR FLASH chips, with:
42  * - model names
43  * - JEDEC ID (combined device & manufacturer code)
44  * - total size in bytes
45  * - size of erase unit in bytes
46  * - size of program page in bytes
47  * - erase command
48  */
49 typedef struct {
50         char *model_name;
51         u32 flash_id;
52         u32 size;
53         u32 sector_size;
54         u16 page_size;
55         u8  erase_cmd;
56 } spi_nor_ids_info_t;
57
58 extern const spi_nor_ids_info_t spi_nor_ids[];
59 extern const u32 spi_nor_ids_count;
60
61 /* Prototypes */
62 u32 flash_init(void);
63 u32 flash_erase(flash_info_t *info, u32 s_first, u32 s_last);
64 const char *flash_manuf_name(u32 jedec_id);
65
66 extern int flash_sect_erase(ulong addr_first, ulong addr_last);
67
68 /* common/flash.c */
69 extern int flash_write(char *, ulong, ulong);
70 extern flash_info_t *addr2info(ulong);
71 extern u32 write_buff(flash_info_t *info, uchar *src, ulong addr, ulong cnt);
72
73 /* Useful size */
74 #define SIZE_4KiB        4 * 1024
75 #define SIZE_64KiB      64 * 1024
76
77 #define SIZE_4MiB        4 * 1024 * 1024
78 #define SIZE_8MiB        8 * 1024 * 1024
79 #define SIZE_16MiB      16 * 1024 * 1024
80 #define SIZE_32MiB      32 * 1024 * 1024
81 #define SIZE_64MiB      64 * 1024 * 1024
82
83 /* Return codes from flash_write(): */
84 #define ERR_OK                                                  0
85 #define ERR_TIMOUT                                              1
86 #define ERR_NOT_ERASED                                  2
87 #define ERR_PROTECTED                                   4
88 #define ERR_INVAL                                               8
89 #define ERR_ALIGN                                               16
90 #define ERR_UNKNOWN_FLASH_VENDOR                32
91 #define ERR_UNKNOWN_FLASH_TYPE                  64
92 #define ERR_PROG_ERROR                                  128
93
94 /* FLASH vendors IDs */
95 #define FLASH_VENDOR_JEDEC_ATMEL                0x1F
96 #define FLASH_VENDOR_JEDEC_EON                  0x1C
97 #define FLASH_VENDOR_JEDEC_MACRONIX             0xC2
98 #define FLASH_VENDOR_JEDEC_MICRON               0x20
99 #define FLASH_VENDOR_JEDEC_SPANSION             0x01
100 #define FLASH_VENDOR_JEDEC_WINBOND              0xEF
101
102 /* Device IDs */
103 #define FLASH_UNKNOWN   0xFFFFFF
104 #define FLASH_CUSTOM    0x111111
105
106 /* Basic SPI FLASH commands */
107 #define SPI_FLASH_CMD_WRSR              0x01
108 #define SPI_FLASH_CMD_PP                0x02
109 #define SPI_FLASH_CMD_READ              0x03
110 #define SPI_FLASH_CMD_WRDI              0x04
111 #define SPI_FLASH_CMD_RDSR              0x05
112 #define SPI_FLASH_CMD_WREN              0x06
113
114 /* SPI FLASH erase related commands */
115 #define SPI_FLASH_CMD_ES_4KB    0x20
116 #define SPI_FLASH_CMD_ES_32KB   0x52
117 #define SPI_FLASH_CMD_ES_64KB   0xD8
118 #define SPI_FLASH_CMD_ES_ALL    0xC7
119
120 /* Other SPI FLASH commands */
121 #define SPI_FLASH_CMD_JEDEC             0x9F
122 #define SPI_FLASH_CMD_SFDP              0x5A
123
124 /* SFDP related defines */
125 #define SPI_FLASH_SFDP_SIGN             0x50444653
126
127 #endif /* !CFG_NO_FLASH */
128
129 #endif /* _FLASH_H_ */