Skip to content

Commit b92c3aa

Browse files
talih0kartben
authored andcommitted
drivers: flash: spi_nor: Set 4-byte addr mode via write instruction 0x17
Some flash devices enable entering the 4-byte address mode by setting BIT(7) in a special register via a write instruction 0x17. The support for this method is indicated in BIT(3) of Enter 4-Byte Addressing byte in 16th DWORD of the JEDEC Basic Flash Parameter Table. Infineon's S25FL512S is an example flash device with this feature. Signed-off-by: Andriy Gelman <[email protected]>
1 parent 3b43cb3 commit b92c3aa

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

drivers/flash/spi_nor.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,26 +1139,40 @@ static int spi_nor_set_address_mode(const struct device *dev,
11391139

11401140
/* This currently only supports command 0xB7 (Enter 4-Byte
11411141
* Address Mode), with or without preceding WREN.
1142+
* Or when BIT(3) is set where the 4-byte address mode can be entered
1143+
* by setting BIT(7) in a register via a 0x17 write
1144+
* instruction. See JEDEC 216F 16th DWORD.
11421145
*/
1143-
if ((enter_4byte_addr & 0x03) == 0) {
1146+
if ((enter_4byte_addr & 0x0b) == 0) {
11441147
return -ENOTSUP;
11451148
}
11461149

11471150
acquire_device(dev);
11481151

1152+
if ((enter_4byte_addr & 0x08) != 0) {
1153+
/* Enter 4-byte address mode by setting BIT(7) in a register
1154+
* via a 0x17 write instruction.
1155+
*/
1156+
uint8_t sr = BIT(7);
1157+
1158+
ret = spi_nor_access(dev, 0x17, NOR_ACCESS_WRITE, 0, &sr, sizeof(sr));
1159+
goto done;
1160+
}
1161+
11491162
if ((enter_4byte_addr & 0x02) != 0) {
11501163
/* Enter after WREN. */
11511164
ret = spi_nor_cmd_write(dev, SPI_NOR_CMD_WREN);
11521165
}
11531166

11541167
if (ret == 0) {
11551168
ret = spi_nor_cmd_write(dev, SPI_NOR_CMD_4BA);
1169+
}
11561170

1157-
if (ret == 0) {
1158-
struct spi_nor_data *data = dev->data;
1171+
done:
1172+
if (ret == 0) {
1173+
struct spi_nor_data *data = dev->data;
11591174

1160-
data->flag_access_32bit = true;
1161-
}
1175+
data->flag_access_32bit = true;
11621176
}
11631177

11641178
release_device(dev);

0 commit comments

Comments
 (0)