1 /*
2  * Copyright (c) 2020-2022, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef MHU_V2_X_H
8 #define MHU_V2_X_H
9 
10 #include <stdbool.h>
11 #include <stdint.h>
12 
13 #define MHU_2_X_INTR_NR2R_OFF		(0x0u)
14 #define MHU_2_X_INTR_R2NR_OFF		(0x1u)
15 #define MHU_2_1_INTR_CHCOMB_OFF		(0x2u)
16 
17 #define MHU_2_X_INTR_NR2R_MASK		(0x1u << MHU_2_X_INTR_NR2R_OFF)
18 #define MHU_2_X_INTR_R2NR_MASK		(0x1u << MHU_2_X_INTR_R2NR_OFF)
19 #define MHU_2_1_INTR_CHCOMB_MASK	(0x1u << MHU_2_1_INTR_CHCOMB_OFF)
20 
21 enum mhu_v2_x_frame_t {
22 	MHU_V2_X_SENDER_FRAME   = 0x0u,
23 	MHU_V2_X_RECEIVER_FRAME = 0x1u,
24 };
25 
26 enum mhu_v2_x_supported_revisions {
27 	MHU_REV_READ_FROM_HW = 0,
28 	MHU_REV_2_0,
29 	MHU_REV_2_1,
30 };
31 
32 struct mhu_v2_x_dev_t {
33 	uintptr_t base;
34 	enum mhu_v2_x_frame_t frame;
35 	uint32_t subversion;	/*!< Hardware subversion: v2.X */
36 	bool is_initialized;	/*!< Indicates if the MHU driver
37 				 *   is initialized and enabled
38 				 */
39 };
40 
41 /**
42  * MHU v2 error enumeration types.
43  */
44 enum mhu_v2_x_error_t {
45 	MHU_V_2_X_ERR_NONE			=  0,
46 	MHU_V_2_X_ERR_NOT_INIT			= -1,
47 	MHU_V_2_X_ERR_ALREADY_INIT		= -2,
48 	MHU_V_2_X_ERR_UNSUPPORTED_VERSION	= -3,
49 	MHU_V_2_X_ERR_INVALID_ARG		= -4,
50 	MHU_V_2_X_ERR_GENERAL			= -5
51 };
52 
53 /**
54  * Initializes the driver.
55  *
56  * dev		MHU device struct mhu_v2_x_dev_t.
57  * rev		MHU revision (if can't be identified from HW).
58  *
59  * Reads the MHU hardware version.
60  *
61  * Returns mhu_v2_x_error_t error code.
62  *
63  * MHU revision only has to be specified when versions can't be read
64  * from HW (ARCH_MAJOR_REV reg reads as 0x0).
65  *
66  * This function doesn't check if dev is NULL.
67  */
68 enum mhu_v2_x_error_t mhu_v2_x_driver_init(struct mhu_v2_x_dev_t *dev,
69 	enum mhu_v2_x_supported_revisions rev);
70 
71 /**
72  * Returns the number of channels implemented.
73  *
74  * dev		MHU device struct mhu_v2_x_dev_t.
75  *
76  * This function doesn't check if dev is NULL.
77  */
78 uint32_t mhu_v2_x_get_num_channel_implemented(
79 		const struct mhu_v2_x_dev_t *dev);
80 
81 /**
82  * Sends the value over a channel.
83  *
84  * dev		MHU device struct mhu_v2_x_dev_t.
85  * channel	Channel to send the value over.
86  * val		Value to send.
87  *
88  * Sends the value over a channel.
89  *
90  * Returns mhu_v2_x_error_t error code.
91  *
92  * This function doesn't check if dev is NULL.
93  * This function doesn't check if channel is implemented.
94  */
95 enum mhu_v2_x_error_t mhu_v2_x_channel_send(const struct mhu_v2_x_dev_t *dev,
96 	uint32_t channel, uint32_t val);
97 
98 /**
99  * Polls sender channel status.
100  *
101  * dev		MHU device struct mhu_v2_x_dev_t.
102  * channel	Channel to poll the status of.
103  * value	Pointer to variable that will store the value.
104  *
105  * Polls sender channel status.
106  *
107  * Returns mhu_v2_x_error_t error code.
108  *
109  * This function doesn't check if dev is NULL.
110  * This function doesn't check if channel is implemented.
111  */
112 enum mhu_v2_x_error_t mhu_v2_x_channel_poll(const struct mhu_v2_x_dev_t *dev,
113 	uint32_t channel, uint32_t *value);
114 
115 /**
116  * Clears the channel after the value is send over it.
117  *
118  * dev		MHU device struct mhu_v2_x_dev_t.
119  * channel	Channel to clear.
120  *
121  * Clears the channel after the value is send over it.
122  *
123  * Returns mhu_v2_x_error_t error code..
124  *
125  * This function doesn't check if dev is NULL.
126  * This function doesn't check if channel is implemented.
127  */
128 enum mhu_v2_x_error_t mhu_v2_x_channel_clear(const struct mhu_v2_x_dev_t *dev,
129 	uint32_t channel);
130 
131 /**
132  * Receives the value over a channel.
133  *
134  * dev		MHU device struct mhu_v2_x_dev_t.
135  * channel	Channel to receive the value from.
136  * value	Pointer to variable that will store the value.
137  *
138  * Receives the value over a channel.
139  *
140  * Returns mhu_v2_x_error_t error code.
141  *
142  * This function doesn't check if dev is NULL.
143  * This function doesn't check if channel is implemented.
144  */
145 enum mhu_v2_x_error_t mhu_v2_x_channel_receive(
146 	const struct mhu_v2_x_dev_t *dev, uint32_t channel, uint32_t *value);
147 
148 /**
149  * Sets bits in the Channel Mask.
150  *
151  * dev		MHU device struct mhu_v2_x_dev_t.
152  * channel	Which channel's mask to set.
153  * mask		Mask to be set over a receiver frame.
154  *
155  * Sets bits in the Channel Mask.
156  *
157  * Returns mhu_v2_x_error_t error code..
158  *
159  * This function doesn't check if dev is NULL.
160  *  This function doesn't check if channel is implemented.
161  */
162 enum mhu_v2_x_error_t mhu_v2_x_channel_mask_set(
163 	const struct mhu_v2_x_dev_t *dev, uint32_t channel, uint32_t mask);
164 
165 /**
166  * Clears bits in the Channel Mask.
167  *
168  * dev	MHU device struct mhu_v2_x_dev_t.
169  * channel	Which channel's mask to clear.
170  * mask	Mask to be clear over a receiver frame.
171  *
172  * Clears bits in the Channel Mask.
173  *
174  * Returns mhu_v2_x_error_t error code.
175  *
176  * This function doesn't check if dev is NULL.
177  *  This function doesn't check if channel is implemented.
178  */
179 enum mhu_v2_x_error_t mhu_v2_x_channel_mask_clear(
180 	const struct mhu_v2_x_dev_t *dev, uint32_t channel, uint32_t mask);
181 
182 /**
183  * Initiates a MHU transfer with the handshake signals.
184  *
185  * dev		MHU device struct mhu_v2_x_dev_t.
186  *
187  * Initiates a MHU transfer with the handshake signals in a blocking mode.
188  *
189  * Returns mhu_v2_x_error_t error code.
190  *
191  * This function doesn't check if dev is NULL.
192  */
193 enum mhu_v2_x_error_t mhu_v2_x_initiate_transfer(
194 	const struct mhu_v2_x_dev_t *dev);
195 
196 /**
197  * Closes a MHU transfer with the handshake signals.
198  *
199  * dev		MHU device struct mhu_v2_x_dev_t.
200  *
201  * Closes a MHU transfer with the handshake signals in a blocking mode.
202  *
203  * Returns mhu_v2_x_error_t error code.
204  *
205  * This function doesn't check if dev is NULL.
206  */
207 enum mhu_v2_x_error_t mhu_v2_x_close_transfer(
208 	const struct mhu_v2_x_dev_t *dev);
209 
210 #endif /* MHU_V2_X_H */
211