Lionel Debieve | 64a524d | 2019-09-09 20:13:34 +0200 | [diff] [blame] | 1 | /* |
Lionel Debieve | 6817698 | 2021-04-13 13:38:02 +0200 | [diff] [blame] | 2 | * Copyright (c) 2019-2022, STMicroelectronics - All Rights Reserved |
Lionel Debieve | 64a524d | 2019-09-09 20:13:34 +0200 | [diff] [blame] | 3 | * |
| 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 | |
| 17 | struct 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 | |
| 24 | struct 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 Debieve | 6817698 | 2021-04-13 13:38:02 +0200 | [diff] [blame] | 36 | void plat_get_scratch_buffer(void **buffer_addr, size_t *buf_size); |
| 37 | |
Lionel Debieve | 64a524d | 2019-09-09 20:13:34 +0200 | [diff] [blame] | 38 | /* |
| 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 | */ |
| 47 | int nand_read(unsigned int offset, uintptr_t buffer, size_t length, |
| 48 | size_t *length_read); |
| 49 | |
| 50 | /* |
Yann Gautier | 0970414 | 2020-08-05 14:39:00 +0200 | [diff] [blame] | 51 | * 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 | */ |
| 58 | int nand_seek_bb(uintptr_t base, unsigned int offset, size_t *extra_offset); |
| 59 | |
| 60 | /* |
Lionel Debieve | 64a524d | 2019-09-09 20:13:34 +0200 | [diff] [blame] | 61 | * Get NAND device instance |
| 62 | * |
| 63 | * Return: NAND device instance reference |
| 64 | */ |
| 65 | struct nand_device *get_nand_device(void); |
| 66 | |
| 67 | #endif /* DRIVERS_NAND_H */ |