zephyr/drivers/flash/spi_nor.h
Savinay Dharmappa 87e5493167 drivers: flash: add a generic spi nor flash driver
This driver is inspired from the w25qxxdv SPI NOR flash driver which was
already implementing the CFI (Common Flash Interface) for its purpose.
To handle other NOR flash a flash id table (as Linux do) which contains
the geometry for a few SPI NOR flash based on their JEDEC ID has been
introduced.
We currently support the following flash:
 - W25Q80
 - W25Q16
 - W25Q32
 - S25FL216K
 - MX25UM512

The read and write functions are able to handle more then one page at a
time and return the number of bytes read or write.
Also because every NOR flash expect to disable the write protection
before writing or erasing, the write enable command is now part of the
write and erase functions.

Signed-off-by: Sebastien Bourdelin <sebastien.bourdelin@savoirfairelinux.com>
Signed-off-by: Savinay Dharmappa <savinay.dharmappa@intel.com>
2018-11-13 18:49:03 -05:00

41 lines
1.2 KiB
C

/*
* Copyright (c) 2018 Savoir-Faire Linux.
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef __SPI_NOR_H__
#define __SPI_NOR_H__
#include <misc/util.h>
#define SPI_NOR_MAX_ID_LEN 3
struct spi_nor_config {
u8_t id[SPI_NOR_MAX_ID_LEN];
u32_t page_size;
u32_t sector_size;
u32_t n_sectors;
u32_t block_size;
u32_t flag;
};
/* Status register bits */
#define SPI_NOR_WIP_BIT BIT(0) /* Write in progress */
#define SPI_NOR_WEL_BIT BIT(1) /* Write enable latch */
/* Flash opcodes */
#define SPI_NOR_CMD_WRSR 0x01 /* Write status register */
#define SPI_NOR_CMD_RDSR 0x05 /* Read status register */
#define SPI_NOR_CMD_READ 0x03 /* Read data */
#define SPI_NOR_CMD_WREN 0x06 /* Write enable */
#define SPI_NOR_CMD_WRDI 0x04 /* Write disable */
#define SPI_NOR_CMD_PP 0x02 /* Page program */
#define SPI_NOR_CMD_SE 0x20 /* Sector erase */
#define SPI_NOR_CMD_BE_32K 0x52 /* Block erase 32KB */
#define SPI_NOR_CMD_BE 0xD8 /* Block erase */
#define SPI_NOR_CMD_CE 0xC7 /* Chip erase */
#define SPI_NOR_CMD_RDID 0x9F /* Read JEDEC ID */
#endif /*__SPI_NOR_H__*/