1 /**
2 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 * Description: Provides flash config info source file.
16 *
17 * History:
18 * 2022-11-30, Create file.
19 */
20
21 #include "flash_config_info.h"
22 #include "common_def.h"
23
24 #define _4K 0x1000
25 #define _32K 0x8000
26 #define _64K 0x10000
27 #define CHIP_SIZE 0x3ffff
28
29 #define FLASH_SIZE_512KB 0x80000
30 #define FLASH_SIZE_1MB 0x100000
31 #define FLASH_SIZE_2MB 0x200000
32 #define FLASH_SIZE_4MB 0x400000
33 #define FLASH_SIZE_8MB 0x800000
34 #define FLASH_SIZE_16MB 0x1000000
35 #define FLASH_SIZE_32MB 0x2000000
36
37 #define FLASH_ERASE_CMD_NUM_4 4
38 #define FLASH_ERASE_CMD_NUM_3 3
39
40 #define DISABLE 0x0
41 #define ENABLE 0x1
42 #define FLASH_MANUFACTURER_MAX 25
43 #define SPI_CMD_UNSUPPORT {0x0, 0x0, 0x0, 0x1}
44 #define WR_ENABLE 0x6
45
46 #define SFC_SUPPORT_IF_TYPE 0x6
47
48 #define FLASH_W25Q16 0x1560EF
49 #define FLASH_W25Q32 0x1660EF
50 #define FLASH_W25Q64 0x1760EF
51 #define FLASH_W25Q80 0x1460EF
52 #define FLASH_W25Q40 0x1360EF
53 #define FLASH_P25Q80 0x146085
54 #define FLASH_GD25WD40 0x1364C8
55 #define FLASH_G25LE80 0x1460C8
56 #define FLASH_GD25LQ64 0x1760C8
57 #define FLASH_GD25LQ32 0x1660C8
58 #define FLASH_GD25LQ16 0x1560C8
59 #define FLASH_GD25Q32 0x1640C8
60 #define FLASH_EN25S80 0x14381C
61 #define FLASH_UNKOWN 0xFFFFFF
62
63 static const flash_cmd_execute_t g_default_quad_enable[] = {
64 { FLASH_CMD_TYPE_END, 0, { 0x0 }}
65 };
66
67 static const spi_opreation_t g_default_read_cmds[] = {
68 {SPI_CMD_SUPPORT, 0x03, 0x0, 0x0},
69 };
70
71 static const spi_opreation_t g_default_write_cmds[] = {
72 {SPI_CMD_SUPPORT, 0x0, 0x0, 0},
73 {SPI_CMD_SUPPORT, 0x02, 0x0, 0},
74 };
75
76 static const spi_opreation_t g_default_erase_cmds[] = {
77 {SPI_CMD_SUPPORT, 0xC7, 0x0, CHIP_SIZE},
78 {SPI_CMD_SUPPORT, 0xD8, 0x0, _64K},
79 {SPI_CMD_SUPPORT, 0x20, 0x0, _4K},
80 };
81
82 static const flash_cmd_execute_t g_flash_gd_bus_enable[] = {
83 { FLASH_CMD_TYPE_PROCESSING, 3, { 0x05, 0, DISABLE } },
84 { FLASH_CMD_TYPE_PROCESSING, 3, { 0x35, 1, ENABLE } },
85 { FLASH_CMD_TYPE_END, 0, { 0x0 }}
86 };
87
88 static const spi_opreation_t g_flash_common_read_cmds[] = {
89 {SPI_CMD_SUPPORT, 0x03, 0x0, 0x0},
90 {SPI_CMD_SUPPORT, 0x0B, 0x0, 0x1},
91 {SPI_CMD_SUPPORT, 0x3B, 0x1, 0x1},
92 {SPI_CMD_SUPPORT, 0xBB, 0x2, 0x1},
93 {SPI_CMD_SUPPORT, 0x6B, 0x5, 0x1},
94 {SPI_CMD_SUPPORT, 0xEB, 0x6, 0x3}
95 };
96
97 static const spi_opreation_t g_flash_common_write_cmds[] = {
98 {SPI_CMD_SUPPORT, 0x0, 0x0, 0},
99 {SPI_CMD_SUPPORT, 0x02, 0x0, 0},
100 SPI_CMD_UNSUPPORT,
101 SPI_CMD_UNSUPPORT,
102 {SPI_CMD_SUPPORT, 0x32, 0x5, 0},
103 SPI_CMD_UNSUPPORT,
104 };
105
106 static const spi_opreation_t g_flash_common_erase_cmds[] = {
107 {SPI_CMD_SUPPORT, 0xC7, 0x0, CHIP_SIZE},
108 {SPI_CMD_SUPPORT, 0xD8, 0x0, _64K},
109 {SPI_CMD_SUPPORT, 0x52, 0x0, _32K},
110 {SPI_CMD_SUPPORT, 0x20, 0x0, _4K}
111 };
112
113 static const flash_spi_info_t g_flash_spi_info_list[] = {
114 {
115 FLASH_GD25Q32,
116 FLASH_SIZE_4MB,
117 FLASH_ERASE_CMD_NUM_4,
118 (spi_opreation_t *)g_flash_common_read_cmds,
119 (spi_opreation_t *)g_flash_common_write_cmds,
120 (spi_opreation_t *)g_flash_common_erase_cmds,
121 (flash_cmd_execute_t *)g_flash_gd_bus_enable
122 },
123 };
124
125 STATIC const flash_spi_info_t g_flash_spi_unknown_info = {
126 FLASH_UNKOWN,
127 FLASH_SIZE_512KB,
128 FLASH_ERASE_CMD_NUM_3,
129 (spi_opreation_t *)g_default_read_cmds,
130 (spi_opreation_t *)g_default_write_cmds,
131 (spi_opreation_t *)g_default_erase_cmds,
132 (flash_cmd_execute_t *)g_default_quad_enable
133 };
134
sfc_port_get_flash_spi_infos(void)135 flash_spi_info_t *sfc_port_get_flash_spi_infos(void)
136 {
137 return (flash_spi_info_t *)g_flash_spi_info_list;
138 }
139
sfc_port_get_flash_num(void)140 uint32_t sfc_port_get_flash_num(void)
141 {
142 return sizeof(g_flash_spi_info_list) / sizeof(flash_spi_info_t);
143 }
144
sfc_port_get_unknown_flash_info(void)145 flash_spi_info_t *sfc_port_get_unknown_flash_info(void)
146 {
147 return (flash_spi_info_t *)&g_flash_spi_unknown_info;
148 }