Lionel Debieve | ed821de | 2019-09-24 17:39:14 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2019, STMicroelectronics - All Rights Reserved |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #ifndef DRIVERS_SPI_NOR_H |
| 8 | #define DRIVERS_SPI_NOR_H |
| 9 | |
| 10 | #include <drivers/spi_mem.h> |
| 11 | |
| 12 | /* OPCODE */ |
| 13 | #define SPI_NOR_OP_WREN 0x06U /* Write enable */ |
| 14 | #define SPI_NOR_OP_WRSR 0x01U /* Write status register 1 byte */ |
| 15 | #define SPI_NOR_OP_READ_ID 0x9FU /* Read JEDEC ID */ |
| 16 | #define SPI_NOR_OP_READ_CR 0x35U /* Read configuration register */ |
| 17 | #define SPI_NOR_OP_READ_SR 0x05U /* Read status register */ |
| 18 | #define SPI_NOR_OP_READ_FSR 0x70U /* Read flag status register */ |
| 19 | #define SPINOR_OP_RDEAR 0xC8U /* Read Extended Address Register */ |
| 20 | #define SPINOR_OP_WREAR 0xC5U /* Write Extended Address Register */ |
| 21 | |
| 22 | /* Used for Spansion flashes only. */ |
| 23 | #define SPINOR_OP_BRWR 0x17U /* Bank register write */ |
| 24 | #define SPINOR_OP_BRRD 0x16U /* Bank register read */ |
| 25 | |
| 26 | #define SPI_NOR_OP_READ 0x03U /* Read data bytes (low frequency) */ |
| 27 | #define SPI_NOR_OP_READ_FAST 0x0BU /* Read data bytes (high frequency) */ |
| 28 | #define SPI_NOR_OP_READ_1_1_2 0x3BU /* Read data bytes (Dual Output SPI) */ |
| 29 | #define SPI_NOR_OP_READ_1_2_2 0xBBU /* Read data bytes (Dual I/O SPI) */ |
| 30 | #define SPI_NOR_OP_READ_1_1_4 0x6BU /* Read data bytes (Quad Output SPI) */ |
| 31 | #define SPI_NOR_OP_READ_1_4_4 0xEBU /* Read data bytes (Quad I/O SPI) */ |
| 32 | |
| 33 | /* Flags for NOR specific configuration */ |
| 34 | #define SPI_NOR_USE_FSR BIT(0) |
| 35 | #define SPI_NOR_USE_BANK BIT(1) |
| 36 | |
| 37 | struct nor_device { |
| 38 | struct spi_mem_op read_op; |
| 39 | uint32_t size; |
| 40 | uint32_t flags; |
| 41 | uint8_t selected_bank; |
| 42 | uint8_t bank_write_cmd; |
| 43 | uint8_t bank_read_cmd; |
| 44 | }; |
| 45 | |
| 46 | int spi_nor_read(unsigned int offset, uintptr_t buffer, size_t length, |
| 47 | size_t *length_read); |
| 48 | int spi_nor_init(unsigned long long *device_size, unsigned int *erase_size); |
| 49 | |
| 50 | /* |
| 51 | * Platform can implement this to override default NOR instance configuration. |
| 52 | * |
| 53 | * @device: target NOR instance. |
| 54 | * Return 0 on success, negative value otherwise. |
| 55 | */ |
| 56 | int plat_get_nor_data(struct nor_device *device); |
| 57 | |
| 58 | #endif /* DRIVERS_SPI_NOR_H */ |