aboutsummaryrefslogtreecommitdiff
path: root/include/drivers/nand.h
blob: 1dbb008f9c280407a2a874b58ace092d2b0a82b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
 * 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 */