blob: 2b5d9b1017a35095d2d2feb5aac975a0742a65d9 [file] [log] [blame]
Lionel Debieve64a524d2019-09-09 20:13:34 +02001/*
Lionel Debieve02a48072020-07-17 12:35:30 +02002 * Copyright (c) 2019-2021, ARM Limited and Contributors. All rights reserved.
Lionel Debieve64a524d2019-09-09 20:13:34 +02003 *
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);
Lionel Debieve02a48072020-07-17 12:35:30 +020047
48 /*
49 * Look for an offset to be added to the given offset.
50 *
51 * @base: Base address of the area.
52 * @offset: Offset in bytes to start read operation.
53 * @extra_offset: [out] Offset to be added to the previous offset.
54 * Return 0 on success, a negative error code otherwise.
55 */
56 int (*seek)(uintptr_t base, unsigned int offset, size_t *extra_offset);
Lionel Debieve64a524d2019-09-09 20:13:34 +020057} io_mtd_ops_t;
58
59typedef struct io_mtd_dev_spec {
60 unsigned long long device_size;
61 unsigned int erase_size;
Lionel Debieve02a48072020-07-17 12:35:30 +020062 size_t offset;
Lionel Debieve64a524d2019-09-09 20:13:34 +020063 io_mtd_ops_t ops;
64} io_mtd_dev_spec_t;
65
66struct io_dev_connector;
67
68int register_io_dev_mtd(const struct io_dev_connector **dev_con);
69
70#endif /* IO_MTD_H */