arm-trusted-firmware/include/drivers/nand.h
Lionel Debieve b114abb609 Add raw NAND framework
The raw NAND framework supports SLC NAND devices.

It introduces a new high level interface (io_mtd) that
defines operations a driver can register to the NAND framework.
This interface will fill in the io_mtd device specification:
	- device_size
        - erase_size
that could be used by the io_storage interface.

NAND core source file integrates the standard read loop that
performs NAND device read operations using a skip bad block strategy.
A platform buffer must be defined in case of unaligned
data. This buffer must fit to the maximum device page size
defined by PLATFORM_MTD_MAX_PAGE_SIZE.

The raw_nand.c source file embeds the specific NAND operations
to read data.
The read command is a raw page read without any ECC correction.
This can be overridden by a low level driver.
No generic support for write or erase command or software
ECC correction.

NAND ONFI detection is available and can be enabled using
NAND_ONFI_DETECT=1.
For non-ONFI NAND management, platform can define required
information.

Change-Id: Id80e9864456cf47f02b74938cf25d99261da8e82
Signed-off-by: Lionel Debieve <lionel.debieve@st.com>
Signed-off-by: Christophe Kerello <christophe.kerello@st.com>
2020-01-20 11:32:59 +01:00

55 lines
1.3 KiB
C

/*
* Copyright (c) 2019, STMicroelectronics - All Rights Reserved
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef DRIVERS_NAND_H
#define DRIVERS_NAND_H
#include <stddef.h>
#include <stdint.h>
#include <lib/utils_def.h>
#define PSEC_TO_MSEC(x) div_round_up((x), 1000000000ULL)
struct ecc {
unsigned int mode; /* ECC mode NAND_ECC_MODE_{NONE|HW|ONDIE} */
unsigned int size; /* Data byte per ECC step */
unsigned int bytes; /* ECC bytes per step */
unsigned int max_bit_corr; /* Max correctible bits per ECC steps */
};
struct nand_device {
unsigned int block_size;
unsigned int page_size;
unsigned long long size;
unsigned int nb_planes;
unsigned int buswidth;
struct ecc ecc;
int (*mtd_block_is_bad)(unsigned int block);
int (*mtd_read_page)(struct nand_device *nand, unsigned int page,
uintptr_t buffer);
};
/*
* Read bytes from NAND device
*
* @offset: Byte offset to read from in device
* @buffer: [out] Bytes read from device
* @length: Number of bytes to read
* @length_read: [out] Number of bytes read from device
* Return: 0 on success, a negative errno on failure
*/
int nand_read(unsigned int offset, uintptr_t buffer, size_t length,
size_t *length_read);
/*
* Get NAND device instance
*
* Return: NAND device instance reference
*/
struct nand_device *get_nand_device(void);
#endif /* DRIVERS_NAND_H */