2022-08-15 04:20:27 -05:00
|
|
|
/***************************************************************************
|
|
|
|
*
|
|
|
|
* Copyright 2015-2019 BES.
|
|
|
|
* All rights reserved. All unpublished rights reserved.
|
|
|
|
*
|
|
|
|
* No part of this work may be used or reproduced in any form or by any
|
|
|
|
* means, or stored in a database or retrieval system, without prior written
|
|
|
|
* permission of BES.
|
|
|
|
*
|
|
|
|
* Use of this work is governed by a license granted by BES.
|
|
|
|
* This work contains confidential and proprietary information of
|
|
|
|
* BES. which is protected by copyright, trade secret,
|
|
|
|
* trademark and other intellectual property rights.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include "norflash_en25s80b.h"
|
2023-02-01 14:52:54 -06:00
|
|
|
#include "hal_norflaship.h"
|
2022-08-15 04:20:27 -05:00
|
|
|
#include "hal_timer.h"
|
2023-02-01 14:52:54 -06:00
|
|
|
#include "hal_trace.h"
|
|
|
|
#include "norflash_drv.h"
|
|
|
|
#include "plat_types.h"
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
static void POSSIBLY_UNUSED en25s80b_en25s80b_reset(void) {
|
|
|
|
// ip quad mode
|
|
|
|
norflaship_quad_mode(1);
|
|
|
|
norflaship_busy_wait();
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
hal_sys_timer_delay(20);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
// quad reset enable
|
|
|
|
norflaship_clear_txfifo();
|
|
|
|
norflaship_cmd_addr(EN25S80B_CMD_QUAD_RESET_ENABLE, 0);
|
|
|
|
norflaship_busy_wait();
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
hal_sys_timer_delay(20);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
// quad reset
|
|
|
|
norflaship_clear_txfifo();
|
|
|
|
norflaship_cmd_addr(EN25S80B_CMD_QUAD_RESET, 0);
|
|
|
|
norflaship_busy_wait();
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
hal_sys_timer_delay(20);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
// ip spi mode
|
|
|
|
norflaship_quad_mode(0);
|
|
|
|
norflaship_hold_pin(0);
|
|
|
|
norflaship_wpr_pin(0);
|
|
|
|
norflaship_busy_wait();
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
hal_sys_timer_delay(20);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
// reset enable
|
|
|
|
norflaship_clear_txfifo();
|
|
|
|
norflaship_cmd_addr(EN25S80B_CMD_SPI_RESET_ENABLE, 0);
|
|
|
|
norflaship_busy_wait();
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
hal_sys_timer_delay(20);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
// reset
|
|
|
|
norflaship_clear_txfifo();
|
|
|
|
norflaship_cmd_addr(EN25S80B_CMD_SPI_RESET, 0);
|
|
|
|
norflaship_busy_wait();
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
hal_sys_timer_delay(20);
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
static void en25s80b_enter_OTP(void) {
|
|
|
|
norflaship_clear_txfifo();
|
|
|
|
norflaship_cmd_addr(EN25S80B_CMD_ENTER_OTP, 0);
|
|
|
|
norflash_status_WIP_1_wait(0);
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
static void en25s80b_exit_OTP(void) {
|
|
|
|
norflaship_clear_txfifo();
|
|
|
|
norflaship_cmd_addr(EN25S80B_CMD_EXIT_OTP, 0);
|
|
|
|
norflash_status_WIP_1_wait(0);
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
static void en25s80b_write_status_s0_s7(uint8_t status) {
|
|
|
|
norflash_write_reg(EN25S80B_CMD_WRITE_STATUS, &status, 1);
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
static int en25s80b_write_status(enum DRV_NORFLASH_W_STATUS_T type,
|
|
|
|
uint32_t param) {
|
|
|
|
uint8_t status;
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
if (type == DRV_NORFLASH_W_STATUS_QE) {
|
|
|
|
en25s80b_enter_OTP();
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
status = norflash_read_status_s0_s7();
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
if (param) {
|
|
|
|
status |= (EN25S80B_WHDIS_BIT_MASK);
|
|
|
|
} else {
|
|
|
|
status &= ~(EN25S80B_WHDIS_BIT_MASK);
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
en25s80b_write_status_s0_s7(status);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
en25s80b_exit_OTP();
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
return 0;
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
return 1;
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
const struct NORFLASH_CFG_T en25s80b_cfg = {
|
2023-02-01 14:52:54 -06:00
|
|
|
.id =
|
|
|
|
{
|
|
|
|
0x1C,
|
|
|
|
0x38,
|
|
|
|
0x14,
|
|
|
|
},
|
|
|
|
.speed_ratio =
|
|
|
|
{
|
|
|
|
.s =
|
|
|
|
{
|
|
|
|
.std_read = SPEED_RATIO_6_EIGHTH,
|
|
|
|
.others = SPEED_RATIO_6_EIGHTH,
|
|
|
|
},
|
2022-08-15 04:20:27 -05:00
|
|
|
},
|
|
|
|
.crm_en_bits = 0xA5,
|
|
|
|
.crm_dis_bits = 0xAA,
|
2023-02-01 14:52:54 -06:00
|
|
|
.sec_reg_cfg =
|
|
|
|
{
|
|
|
|
.s =
|
|
|
|
{
|
|
|
|
.enabled = false,
|
|
|
|
},
|
2022-08-15 04:20:27 -05:00
|
|
|
},
|
|
|
|
.page_size = EN25S80B_PAGE_SIZE,
|
|
|
|
.sector_size = EN25S80B_SECTOR_SIZE,
|
|
|
|
.block_size = EN25S80B_BLOCK_SIZE,
|
|
|
|
.total_size = EN25S80B_TOTAL_SIZE,
|
|
|
|
.max_speed = 104 * 1000 * 1000,
|
2023-02-01 14:52:54 -06:00
|
|
|
.mode = (HAL_NORFLASH_OP_MODE_STAND_SPI | HAL_NORFLASH_OP_MODE_FAST_SPI |
|
|
|
|
HAL_NORFLASH_OP_MODE_DUAL_OUTPUT | HAL_NORFLASH_OP_MODE_DUAL_IO |
|
|
|
|
HAL_NORFLASH_OP_MODE_QUAD_OUTPUT | HAL_NORFLASH_OP_MODE_QUAD_IO |
|
|
|
|
HAL_NORFLASH_OP_MODE_PAGE_PROGRAM |
|
|
|
|
HAL_NORFLASH_OP_MODE_QUAD_PAGE_PROGRAM |
|
|
|
|
HAL_NORFLASH_OP_MODE_ERASE_IN_STD),
|
2022-08-15 04:20:27 -05:00
|
|
|
.write_status = en25s80b_write_status,
|
|
|
|
};
|