blob: 5e5607c648555223295ec8c7430435b43b6cc6b6 [file] [log] [blame]
Lionel Debieve64a524d2019-09-09 20:13:34 +02001/*
Lionel Debieve68176982021-04-13 13:38:02 +02002 * Copyright (c) 2019-2022, STMicroelectronics - All Rights Reserved
Lionel Debieve64a524d2019-09-09 20:13:34 +02003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef DRIVERS_NAND_H
8#define DRIVERS_NAND_H
9
10#include <stddef.h>
11#include <stdint.h>
12
13#include <lib/utils_def.h>
14
15#define PSEC_TO_MSEC(x) div_round_up((x), 1000000000ULL)
16
17struct ecc {
18 unsigned int mode; /* ECC mode NAND_ECC_MODE_{NONE|HW|ONDIE} */
19 unsigned int size; /* Data byte per ECC step */
20 unsigned int bytes; /* ECC bytes per step */
21 unsigned int max_bit_corr; /* Max correctible bits per ECC steps */
22};
23
24struct nand_device {
25 unsigned int block_size;
26 unsigned int page_size;
27 unsigned long long size;
28 unsigned int nb_planes;
29 unsigned int buswidth;
30 struct ecc ecc;
31 int (*mtd_block_is_bad)(unsigned int block);
32 int (*mtd_read_page)(struct nand_device *nand, unsigned int page,
33 uintptr_t buffer);
34};
35
Lionel Debieve68176982021-04-13 13:38:02 +020036void plat_get_scratch_buffer(void **buffer_addr, size_t *buf_size);
37
Lionel Debieve64a524d2019-09-09 20:13:34 +020038/*
39 * Read bytes from NAND device
40 *
41 * @offset: Byte offset to read from in device
42 * @buffer: [out] Bytes read from device
43 * @length: Number of bytes to read
44 * @length_read: [out] Number of bytes read from device
45 * Return: 0 on success, a negative errno on failure
46 */
47int nand_read(unsigned int offset, uintptr_t buffer, size_t length,
48 size_t *length_read);
49
50/*
Yann Gautier09704142020-08-05 14:39:00 +020051 * Look for an extra offset to be added in case of bad blocks
52 *
53 * @base: Base address of the area
54 * @offset: Byte offset to read from in device
55 * @extra_offset: [out] Extra offset to be added if bad blocks are found
56 * Return: 0 on success, a negative errno on failure
57 */
58int nand_seek_bb(uintptr_t base, unsigned int offset, size_t *extra_offset);
59
60/*
Lionel Debieve64a524d2019-09-09 20:13:34 +020061 * Get NAND device instance
62 *
63 * Return: NAND device instance reference
64 */
65struct nand_device *get_nand_device(void);
66
67#endif /* DRIVERS_NAND_H */