summaryrefslogtreecommitdiffstats
path: root/drivers/arm/mhu/mhu_v2_x.h
blob: 10247d24f43d4103d645dca842c881c87d91018e (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/*
 * Copyright (c) 2020-2022, Arm Limited. All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#ifndef MHU_V2_X_H
#define MHU_V2_X_H

#include <stdbool.h>
#include <stdint.h>

#define MHU_2_X_INTR_NR2R_OFF		(0x0u)
#define MHU_2_X_INTR_R2NR_OFF		(0x1u)
#define MHU_2_1_INTR_CHCOMB_OFF		(0x2u)

#define MHU_2_X_INTR_NR2R_MASK		(0x1u << MHU_2_X_INTR_NR2R_OFF)
#define MHU_2_X_INTR_R2NR_MASK		(0x1u << MHU_2_X_INTR_R2NR_OFF)
#define MHU_2_1_INTR_CHCOMB_MASK	(0x1u << MHU_2_1_INTR_CHCOMB_OFF)

enum mhu_v2_x_frame_t {
	MHU_V2_X_SENDER_FRAME   = 0x0u,
	MHU_V2_X_RECEIVER_FRAME = 0x1u,
};

enum mhu_v2_x_supported_revisions {
	MHU_REV_READ_FROM_HW = 0,
	MHU_REV_2_0,
	MHU_REV_2_1,
};

struct mhu_v2_x_dev_t {
	uintptr_t base;
	enum mhu_v2_x_frame_t frame;
	uint32_t subversion;	/*!< Hardware subversion: v2.X */
	bool is_initialized;	/*!< Indicates if the MHU driver
				 *   is initialized and enabled
				 */
};

/**
 * MHU v2 error enumeration types.
 */
enum mhu_v2_x_error_t {
	MHU_V_2_X_ERR_NONE			=  0,
	MHU_V_2_X_ERR_NOT_INIT			= -1,
	MHU_V_2_X_ERR_ALREADY_INIT		= -2,
	MHU_V_2_X_ERR_UNSUPPORTED_VERSION	= -3,
	MHU_V_2_X_ERR_INVALID_ARG		= -4,
	MHU_V_2_X_ERR_GENERAL			= -5
};

/**
 * Initializes the driver.
 *
 * dev		MHU device struct mhu_v2_x_dev_t.
 * rev		MHU revision (if can't be identified from HW).
 *
 * Reads the MHU hardware version.
 *
 * Returns mhu_v2_x_error_t error code.
 *
 * MHU revision only has to be specified when versions can't be read
 * from HW (ARCH_MAJOR_REV reg reads as 0x0).
 *
 * This function doesn't check if dev is NULL.
 */
enum mhu_v2_x_error_t mhu_v2_x_driver_init(struct mhu_v2_x_dev_t *dev,
	enum mhu_v2_x_supported_revisions rev);

/**
 * Returns the number of channels implemented.
 *
 * dev		MHU device struct mhu_v2_x_dev_t.
 *
 * This function doesn't check if dev is NULL.
 */
uint32_t mhu_v2_x_get_num_channel_implemented(
		const struct mhu_v2_x_dev_t *dev);

/**
 * Sends the value over a channel.
 *
 * dev		MHU device struct mhu_v2_x_dev_t.
 * channel	Channel to send the value over.
 * val		Value to send.
 *
 * Sends the value over a channel.
 *
 * Returns mhu_v2_x_error_t error code.
 *
 * This function doesn't check if dev is NULL.
 * This function doesn't check if channel is implemented.
 */
enum mhu_v2_x_error_t mhu_v2_x_channel_send(const struct mhu_v2_x_dev_t *dev,
	uint32_t channel, uint32_t val);

/**
 * Polls sender channel status.
 *
 * dev		MHU device struct mhu_v2_x_dev_t.
 * channel	Channel to poll the status of.
 * value	Pointer to variable that will store the value.
 *
 * Polls sender channel status.
 *
 * Returns mhu_v2_x_error_t error code.
 *
 * This function doesn't check if dev is NULL.
 * This function doesn't check if channel is implemented.
 */
enum mhu_v2_x_error_t mhu_v2_x_channel_poll(const struct mhu_v2_x_dev_t *dev,
	uint32_t channel, uint32_t *value);

/**
 * Clears the channel after the value is send over it.
 *
 * dev		MHU device struct mhu_v2_x_dev_t.
 * channel	Channel to clear.
 *
 * Clears the channel after the value is send over it.
 *
 * Returns mhu_v2_x_error_t error code..
 *
 * This function doesn't check if dev is NULL.
 * This function doesn't check if channel is implemented.
 */
enum mhu_v2_x_error_t mhu_v2_x_channel_clear(const struct mhu_v2_x_dev_t *dev,
	uint32_t channel);

/**
 * Receives the value over a channel.
 *
 * dev		MHU device struct mhu_v2_x_dev_t.
 * channel	Channel to receive the value from.
 * value	Pointer to variable that will store the value.
 *
 * Receives the value over a channel.
 *
 * Returns mhu_v2_x_error_t error code.
 *
 * This function doesn't check if dev is NULL.
 * This function doesn't check if channel is implemented.
 */
enum mhu_v2_x_error_t mhu_v2_x_channel_receive(
	const struct mhu_v2_x_dev_t *dev, uint32_t channel, uint32_t *value);

/**
 * Sets bits in the Channel Mask.
 *
 * dev		MHU device struct mhu_v2_x_dev_t.
 * channel	Which channel's mask to set.
 * mask		Mask to be set over a receiver frame.
 *
 * Sets bits in the Channel Mask.
 *
 * Returns mhu_v2_x_error_t error code..
 *
 * This function doesn't check if dev is NULL.
 *  This function doesn't check if channel is implemented.
 */
enum mhu_v2_x_error_t mhu_v2_x_channel_mask_set(
	const struct mhu_v2_x_dev_t *dev, uint32_t channel, uint32_t mask);

/**
 * Clears bits in the Channel Mask.
 *
 * dev	MHU device struct mhu_v2_x_dev_t.
 * channel	Which channel's mask to clear.
 * mask	Mask to be clear over a receiver frame.
 *
 * Clears bits in the Channel Mask.
 *
 * Returns mhu_v2_x_error_t error code.
 *
 * This function doesn't check if dev is NULL.
 *  This function doesn't check if channel is implemented.
 */
enum mhu_v2_x_error_t mhu_v2_x_channel_mask_clear(
	const struct mhu_v2_x_dev_t *dev, uint32_t channel, uint32_t mask);

/**
 * Initiates a MHU transfer with the handshake signals.
 *
 * dev		MHU device struct mhu_v2_x_dev_t.
 *
 * Initiates a MHU transfer with the handshake signals in a blocking mode.
 *
 * Returns mhu_v2_x_error_t error code.
 *
 * This function doesn't check if dev is NULL.
 */
enum mhu_v2_x_error_t mhu_v2_x_initiate_transfer(
	const struct mhu_v2_x_dev_t *dev);

/**
 * Closes a MHU transfer with the handshake signals.
 *
 * dev		MHU device struct mhu_v2_x_dev_t.
 *
 * Closes a MHU transfer with the handshake signals in a blocking mode.
 *
 * Returns mhu_v2_x_error_t error code.
 *
 * This function doesn't check if dev is NULL.
 */
enum mhu_v2_x_error_t mhu_v2_x_close_transfer(
	const struct mhu_v2_x_dev_t *dev);

#endif /* MHU_V2_X_H */