2019-01-08 05:29:25 -05:00
|
|
|
// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD
|
2017-05-23 22:35:12 -04:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
2019-01-08 05:29:25 -05:00
|
|
|
//
|
2017-05-23 22:35:12 -04:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
2019-01-08 05:29:25 -05:00
|
|
|
|
2017-05-23 22:35:12 -04:00
|
|
|
#include <stdlib.h>
|
2019-01-08 05:29:25 -05:00
|
|
|
#include "spi_flash_chip_generic.h"
|
2020-12-15 22:50:13 -05:00
|
|
|
#include "spi_flash_chip_issi.h"
|
2019-01-08 05:29:25 -05:00
|
|
|
#include "spi_flash_defs.h"
|
2017-05-23 22:35:12 -04:00
|
|
|
|
|
|
|
/* Driver for ISSI flash chip, as used in ESP32 D2WD */
|
|
|
|
|
2019-01-08 05:29:25 -05:00
|
|
|
esp_err_t spi_flash_chip_issi_probe(esp_flash_t *chip, uint32_t flash_id)
|
2017-05-23 22:35:12 -04:00
|
|
|
{
|
|
|
|
/* Check manufacturer and product IDs match our desired masks */
|
|
|
|
const uint8_t MFG_ID = 0x9D;
|
|
|
|
if (flash_id >> 16 != MFG_ID) {
|
2019-01-08 05:29:25 -05:00
|
|
|
return ESP_ERR_NOT_FOUND;
|
2017-05-23 22:35:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
const uint16_t FLASH_ID_MASK = 0xCF00;
|
|
|
|
const uint16_t FLASH_ID_VALUE = 0x4000;
|
|
|
|
if ((flash_id & FLASH_ID_MASK) != FLASH_ID_VALUE) {
|
2019-01-08 05:29:25 -05:00
|
|
|
return ESP_ERR_NOT_FOUND;
|
2017-05-23 22:35:12 -04:00
|
|
|
}
|
|
|
|
|
2019-01-08 05:29:25 -05:00
|
|
|
return ESP_OK;
|
2017-05-23 22:35:12 -04:00
|
|
|
}
|
|
|
|
|
2019-09-05 01:11:36 -04:00
|
|
|
esp_err_t spi_flash_chip_issi_set_io_mode(esp_flash_t *chip)
|
2017-05-23 22:35:12 -04:00
|
|
|
{
|
|
|
|
/* ISSI uses bit 6 of "basic" SR as Quad Enable */
|
2019-01-08 05:29:25 -05:00
|
|
|
const uint8_t BIT_QE = 1 << 6;
|
2019-09-05 01:11:36 -04:00
|
|
|
return spi_flash_common_set_io_mode(chip,
|
|
|
|
spi_flash_common_write_status_8b_wrsr,
|
|
|
|
spi_flash_common_read_status_8b_rdsr,
|
|
|
|
BIT_QE);
|
2017-05-23 22:35:12 -04:00
|
|
|
}
|
|
|
|
|
2019-09-05 01:11:36 -04:00
|
|
|
esp_err_t spi_flash_chip_issi_get_io_mode(esp_flash_t *chip, esp_flash_io_mode_t* out_io_mode)
|
|
|
|
{
|
|
|
|
/* ISSI uses bit 6 of "basic" SR as Quad Enable */
|
|
|
|
const uint8_t BIT_QE = 1 << 6;
|
|
|
|
uint32_t sr;
|
|
|
|
esp_err_t ret = spi_flash_common_read_status_8b_rdsr(chip, &sr);
|
|
|
|
if (ret == ESP_OK) {
|
|
|
|
*out_io_mode = ((sr & BIT_QE)? SPI_FLASH_QOUT: 0);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-05-18 00:05:41 -04:00
|
|
|
spi_flash_caps_t spi_flash_chip_issi_get_caps(esp_flash_t *chip)
|
|
|
|
{
|
|
|
|
spi_flash_caps_t caps_flags = 0;
|
|
|
|
// 32-bit-address flash is not supported
|
|
|
|
// flash-suspend is not supported
|
|
|
|
return caps_flags;
|
|
|
|
}
|
|
|
|
|
2019-01-08 05:29:25 -05:00
|
|
|
static const char chip_name[] = "issi";
|
2017-05-23 22:35:12 -04:00
|
|
|
|
2019-01-08 05:29:25 -05:00
|
|
|
// The issi chip can use the functions for generic chips except from set read mode and probe,
|
|
|
|
// So we only replace these two functions.
|
|
|
|
const spi_flash_chip_t esp_flash_chip_issi = {
|
|
|
|
.name = chip_name,
|
2020-04-29 22:37:35 -04:00
|
|
|
.timeout = &spi_flash_chip_generic_timeout,
|
2019-01-08 05:29:25 -05:00
|
|
|
.probe = spi_flash_chip_issi_probe,
|
|
|
|
.reset = spi_flash_chip_generic_reset,
|
|
|
|
.detect_size = spi_flash_chip_generic_detect_size,
|
|
|
|
.erase_chip = spi_flash_chip_generic_erase_chip,
|
|
|
|
.erase_sector = spi_flash_chip_generic_erase_sector,
|
|
|
|
.erase_block = spi_flash_chip_generic_erase_block,
|
2017-05-23 22:35:12 -04:00
|
|
|
.sector_size = 4 * 1024,
|
|
|
|
.block_erase_size = 64 * 1024,
|
|
|
|
|
2019-08-02 01:04:48 -04:00
|
|
|
.get_chip_write_protect = spi_flash_chip_generic_get_write_protect,
|
|
|
|
.set_chip_write_protect = spi_flash_chip_generic_set_write_protect,
|
2017-05-23 22:35:12 -04:00
|
|
|
|
|
|
|
.num_protectable_regions = 0,
|
|
|
|
.protectable_regions = NULL,
|
|
|
|
.get_protected_regions = NULL,
|
|
|
|
.set_protected_regions = NULL,
|
|
|
|
|
2019-01-08 05:29:25 -05:00
|
|
|
.read = spi_flash_chip_generic_read,
|
|
|
|
.write = spi_flash_chip_generic_write,
|
|
|
|
.program_page = spi_flash_chip_generic_page_program,
|
2017-05-23 22:35:12 -04:00
|
|
|
.page_size = 256,
|
2019-01-08 05:29:25 -05:00
|
|
|
.write_encrypted = spi_flash_chip_generic_write_encrypted,
|
2017-05-23 22:35:12 -04:00
|
|
|
|
2019-01-08 05:29:25 -05:00
|
|
|
.wait_idle = spi_flash_chip_generic_wait_idle,
|
2019-09-05 01:11:36 -04:00
|
|
|
.set_io_mode = spi_flash_chip_issi_set_io_mode,
|
|
|
|
.get_io_mode = spi_flash_chip_issi_get_io_mode,
|
2020-07-26 15:13:07 -04:00
|
|
|
|
|
|
|
.read_reg = spi_flash_chip_generic_read_reg,
|
2020-12-15 22:50:13 -05:00
|
|
|
.yield = spi_flash_chip_generic_yield,
|
2021-03-19 05:39:56 -04:00
|
|
|
.sus_setup = spi_flash_chip_generic_suspend_cmd_conf,
|
2021-05-18 00:05:41 -04:00
|
|
|
.get_chip_caps = spi_flash_chip_issi_get_caps,
|
2017-05-23 22:35:12 -04:00
|
|
|
};
|