blob: 1395ff60196a726cc025a7e6e719482c752f480b [file] [log] [blame]
Lionel Debieve64a524d2019-09-09 20:13:34 +02001/*
2 * Copyright (c) 2019, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef IO_MTD_H
8#define IO_MTD_H
9
10#include <stdint.h>
11#include <stdio.h>
12
13#include <drivers/io/io_storage.h>
14
15/* MTD devices ops */
16typedef struct io_mtd_ops {
17 /*
18 * Initialize MTD framework and retrieve device information.
19 *
20 * @size: [out] MTD device size in bytes.
21 * @erase_size: [out] MTD erase size in bytes.
22 * Return 0 on success, a negative error code otherwise.
23 */
24 int (*init)(unsigned long long *size, unsigned int *erase_size);
25
26 /*
27 * Execute a read memory operation.
28 *
29 * @offset: Offset in bytes to start read operation.
30 * @buffer: [out] Buffer to store read data.
31 * @length: Required length to be read in bytes.
32 * @out_length: [out] Length read in bytes.
33 * Return 0 on success, a negative error code otherwise.
34 */
35 int (*read)(unsigned int offset, uintptr_t buffer, size_t length,
36 size_t *out_length);
37
38 /*
39 * Execute a write memory operation.
40 *
41 * @offset: Offset in bytes to start write operation.
42 * @buffer: Buffer to be written in device.
43 * @length: Required length to be written in bytes.
44 * Return 0 on success, a negative error code otherwise.
45 */
46 int (*write)(unsigned int offset, uintptr_t buffer, size_t length);
47} io_mtd_ops_t;
48
49typedef struct io_mtd_dev_spec {
50 unsigned long long device_size;
51 unsigned int erase_size;
52 io_mtd_ops_t ops;
53} io_mtd_dev_spec_t;
54
55struct io_dev_connector;
56
57int register_io_dev_mtd(const struct io_dev_connector **dev_con);
58
59#endif /* IO_MTD_H */