1 /*
2  * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 /*!
8  * File containing client-side RPC functions for the PAD service. These
9  * functions are ported to clients that communicate to the SC.
10  *
11  * @addtogroup PAD_SVC
12  * @{
13  */
14 
15 /* Includes */
16 
17 #include <stdlib.h>
18 
19 #include <sci/sci_types.h>
20 #include <sci/svc/rm/sci_rm_api.h>
21 #include <sci/svc/pad/sci_pad_api.h>
22 #include <sci/sci_rpc.h>
23 #include "sci_pad_rpc.h"
24 
25 /* Local Defines */
26 
27 /* Local Types */
28 
29 /* Local Functions */
30 
sc_pad_set_mux(sc_ipc_t ipc,sc_pad_t pad,uint8_t mux,sc_pad_config_t config,sc_pad_iso_t iso)31 sc_err_t sc_pad_set_mux(sc_ipc_t ipc, sc_pad_t pad,
32 			uint8_t mux, sc_pad_config_t config, sc_pad_iso_t iso)
33 {
34 	sc_rpc_msg_t msg;
35 	uint8_t result;
36 
37 	RPC_VER(&msg) = SC_RPC_VERSION;
38 	RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PAD;
39 	RPC_FUNC(&msg) = (uint8_t)PAD_FUNC_SET_MUX;
40 	RPC_U16(&msg, 0U) = (uint16_t)pad;
41 	RPC_U8(&msg, 2U) = (uint8_t)mux;
42 	RPC_U8(&msg, 3U) = (uint8_t)config;
43 	RPC_U8(&msg, 4U) = (uint8_t)iso;
44 	RPC_SIZE(&msg) = 3U;
45 
46 	sc_call_rpc(ipc, &msg, SC_FALSE);
47 
48 	result = RPC_R8(&msg);
49 	return (sc_err_t)result;
50 }
51 
sc_pad_get_mux(sc_ipc_t ipc,sc_pad_t pad,uint8_t * mux,sc_pad_config_t * config,sc_pad_iso_t * iso)52 sc_err_t sc_pad_get_mux(sc_ipc_t ipc, sc_pad_t pad,
53 			uint8_t *mux, sc_pad_config_t *config,
54 			sc_pad_iso_t *iso)
55 {
56 	sc_rpc_msg_t msg;
57 	uint8_t result;
58 
59 	RPC_VER(&msg) = SC_RPC_VERSION;
60 	RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PAD;
61 	RPC_FUNC(&msg) = (uint8_t)PAD_FUNC_GET_MUX;
62 	RPC_U16(&msg, 0U) = (uint16_t)pad;
63 	RPC_SIZE(&msg) = 2U;
64 
65 	sc_call_rpc(ipc, &msg, SC_FALSE);
66 
67 	result = RPC_R8(&msg);
68 	if (mux != NULL) {
69 		*mux = RPC_U8(&msg, 0U);
70 	}
71 
72 	if (config != NULL) {
73 		*config = RPC_U8(&msg, 1U);
74 	}
75 
76 	if (iso != NULL) {
77 		*iso = RPC_U8(&msg, 2U);
78 	}
79 
80 	return (sc_err_t)result;
81 }
82 
sc_pad_set_gp(sc_ipc_t ipc,sc_pad_t pad,uint32_t ctrl)83 sc_err_t sc_pad_set_gp(sc_ipc_t ipc, sc_pad_t pad, uint32_t ctrl)
84 {
85 	sc_rpc_msg_t msg;
86 	uint8_t result;
87 
88 	RPC_VER(&msg) = SC_RPC_VERSION;
89 	RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PAD;
90 	RPC_FUNC(&msg) = (uint8_t)PAD_FUNC_SET_GP;
91 	RPC_U32(&msg, 0U) = (uint32_t)ctrl;
92 	RPC_U16(&msg, 4U) = (uint16_t)pad;
93 	RPC_SIZE(&msg) = 3U;
94 
95 	sc_call_rpc(ipc, &msg, SC_FALSE);
96 
97 	result = RPC_R8(&msg);
98 	return (sc_err_t)result;
99 }
100 
sc_pad_get_gp(sc_ipc_t ipc,sc_pad_t pad,uint32_t * ctrl)101 sc_err_t sc_pad_get_gp(sc_ipc_t ipc, sc_pad_t pad, uint32_t *ctrl)
102 {
103 	sc_rpc_msg_t msg;
104 	uint8_t result;
105 
106 	RPC_VER(&msg) = SC_RPC_VERSION;
107 	RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PAD;
108 	RPC_FUNC(&msg) = (uint8_t)PAD_FUNC_GET_GP;
109 	RPC_U16(&msg, 0U) = (uint16_t)pad;
110 	RPC_SIZE(&msg) = 2U;
111 
112 	sc_call_rpc(ipc, &msg, SC_FALSE);
113 
114 	if (ctrl != NULL) {
115 		*ctrl = RPC_U32(&msg, 0U);
116 	}
117 
118 	result = RPC_R8(&msg);
119 	return (sc_err_t)result;
120 }
121 
sc_pad_set_wakeup(sc_ipc_t ipc,sc_pad_t pad,sc_pad_wakeup_t wakeup)122 sc_err_t sc_pad_set_wakeup(sc_ipc_t ipc, sc_pad_t pad, sc_pad_wakeup_t wakeup)
123 {
124 	sc_rpc_msg_t msg;
125 	uint8_t result;
126 
127 	RPC_VER(&msg) = SC_RPC_VERSION;
128 	RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PAD;
129 	RPC_FUNC(&msg) = (uint8_t)PAD_FUNC_SET_WAKEUP;
130 	RPC_U16(&msg, 0U) = (uint16_t)pad;
131 	RPC_U8(&msg, 2U) = (uint8_t)wakeup;
132 	RPC_SIZE(&msg) = 2U;
133 
134 	sc_call_rpc(ipc, &msg, SC_FALSE);
135 
136 	result = RPC_R8(&msg);
137 	return (sc_err_t)result;
138 }
139 
sc_pad_get_wakeup(sc_ipc_t ipc,sc_pad_t pad,sc_pad_wakeup_t * wakeup)140 sc_err_t sc_pad_get_wakeup(sc_ipc_t ipc, sc_pad_t pad, sc_pad_wakeup_t *wakeup)
141 {
142 	sc_rpc_msg_t msg;
143 	uint8_t result;
144 
145 	RPC_VER(&msg) = SC_RPC_VERSION;
146 	RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PAD;
147 	RPC_FUNC(&msg) = (uint8_t)PAD_FUNC_GET_WAKEUP;
148 	RPC_U16(&msg, 0U) = (uint16_t)pad;
149 	RPC_SIZE(&msg) = 2U;
150 
151 	sc_call_rpc(ipc, &msg, SC_FALSE);
152 
153 	result = RPC_R8(&msg);
154 	if (wakeup != NULL) {
155 		*wakeup = RPC_U8(&msg, 0U);
156 	}
157 
158 	return (sc_err_t)result;
159 }
160 
sc_pad_set_all(sc_ipc_t ipc,sc_pad_t pad,uint8_t mux,sc_pad_config_t config,sc_pad_iso_t iso,uint32_t ctrl,sc_pad_wakeup_t wakeup)161 sc_err_t sc_pad_set_all(sc_ipc_t ipc, sc_pad_t pad, uint8_t mux,
162 			sc_pad_config_t config, sc_pad_iso_t iso, uint32_t ctrl,
163 			sc_pad_wakeup_t wakeup)
164 {
165 	sc_rpc_msg_t msg;
166 	uint8_t result;
167 
168 	RPC_VER(&msg) = SC_RPC_VERSION;
169 	RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PAD;
170 	RPC_FUNC(&msg) = (uint8_t)PAD_FUNC_SET_ALL;
171 	RPC_U32(&msg, 0U) = (uint32_t)ctrl;
172 	RPC_U16(&msg, 4U) = (uint16_t)pad;
173 	RPC_U8(&msg, 6U) = (uint8_t)mux;
174 	RPC_U8(&msg, 7U) = (uint8_t)config;
175 	RPC_U8(&msg, 8U) = (uint8_t)iso;
176 	RPC_U8(&msg, 9U) = (uint8_t)wakeup;
177 	RPC_SIZE(&msg) = 4U;
178 
179 	sc_call_rpc(ipc, &msg, SC_FALSE);
180 
181 	result = RPC_R8(&msg);
182 	return (sc_err_t)result;
183 }
184 
sc_pad_get_all(sc_ipc_t ipc,sc_pad_t pad,uint8_t * mux,sc_pad_config_t * config,sc_pad_iso_t * iso,uint32_t * ctrl,sc_pad_wakeup_t * wakeup)185 sc_err_t sc_pad_get_all(sc_ipc_t ipc, sc_pad_t pad, uint8_t *mux,
186 			sc_pad_config_t *config, sc_pad_iso_t *iso,
187 			uint32_t *ctrl, sc_pad_wakeup_t *wakeup)
188 {
189 	sc_rpc_msg_t msg;
190 	uint8_t result;
191 
192 	RPC_VER(&msg) = SC_RPC_VERSION;
193 	RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PAD;
194 	RPC_FUNC(&msg) = (uint8_t)PAD_FUNC_GET_ALL;
195 	RPC_U16(&msg, 0U) = (uint16_t)pad;
196 	RPC_SIZE(&msg) = 2U;
197 
198 	sc_call_rpc(ipc, &msg, SC_FALSE);
199 
200 	if (ctrl != NULL) {
201 		*ctrl = RPC_U32(&msg, 0U);
202 	}
203 
204 	result = RPC_R8(&msg);
205 	if (mux != NULL) {
206 		*mux = RPC_U8(&msg, 4U);
207 	}
208 
209 	if (config != NULL) {
210 		*config = RPC_U8(&msg, 5U);
211 	}
212 
213 	if (iso != NULL) {
214 		*iso = RPC_U8(&msg, 6U);
215 	}
216 
217 	if (wakeup != NULL) {
218 		*wakeup = RPC_U8(&msg, 7U);
219 	}
220 
221 	return (sc_err_t)result;
222 }
223 
sc_pad_set(sc_ipc_t ipc,sc_pad_t pad,uint32_t val)224 sc_err_t sc_pad_set(sc_ipc_t ipc, sc_pad_t pad, uint32_t val)
225 {
226 	sc_rpc_msg_t msg;
227 	uint8_t result;
228 
229 	RPC_VER(&msg) = SC_RPC_VERSION;
230 	RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PAD;
231 	RPC_FUNC(&msg) = (uint8_t)PAD_FUNC_SET;
232 	RPC_U32(&msg, 0U) = (uint32_t)val;
233 	RPC_U16(&msg, 4U) = (uint16_t)pad;
234 	RPC_SIZE(&msg) = 3U;
235 
236 	sc_call_rpc(ipc, &msg, SC_FALSE);
237 
238 	result = RPC_R8(&msg);
239 	return (sc_err_t)result;
240 }
241 
sc_pad_get(sc_ipc_t ipc,sc_pad_t pad,uint32_t * val)242 sc_err_t sc_pad_get(sc_ipc_t ipc, sc_pad_t pad, uint32_t *val)
243 {
244 	sc_rpc_msg_t msg;
245 	uint8_t result;
246 
247 	RPC_VER(&msg) = SC_RPC_VERSION;
248 	RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PAD;
249 	RPC_FUNC(&msg) = (uint8_t)PAD_FUNC_GET;
250 	RPC_U16(&msg, 0U) = (uint16_t)pad;
251 	RPC_SIZE(&msg) = 2U;
252 
253 	sc_call_rpc(ipc, &msg, SC_FALSE);
254 
255 	if (val != NULL) {
256 		*val = RPC_U32(&msg, 0U);
257 	}
258 
259 	result = RPC_R8(&msg);
260 	return (sc_err_t)result;
261 }
262 
sc_pad_set_gp_28fdsoi(sc_ipc_t ipc,sc_pad_t pad,sc_pad_28fdsoi_dse_t dse,sc_pad_28fdsoi_ps_t ps)263 sc_err_t sc_pad_set_gp_28fdsoi(sc_ipc_t ipc, sc_pad_t pad,
264 			       sc_pad_28fdsoi_dse_t dse, sc_pad_28fdsoi_ps_t ps)
265 {
266 	sc_rpc_msg_t msg;
267 	uint8_t result;
268 
269 	RPC_VER(&msg) = SC_RPC_VERSION;
270 	RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PAD;
271 	RPC_FUNC(&msg) = (uint8_t)PAD_FUNC_SET_GP_28FDSOI;
272 	RPC_U16(&msg, 0U) = (uint16_t)pad;
273 	RPC_U8(&msg, 2U) = (uint8_t)dse;
274 	RPC_U8(&msg, 3U) = (uint8_t)ps;
275 	RPC_SIZE(&msg) = 2U;
276 
277 	sc_call_rpc(ipc, &msg, SC_FALSE);
278 
279 	result = RPC_R8(&msg);
280 	return (sc_err_t)result;
281 }
282 
sc_pad_get_gp_28fdsoi(sc_ipc_t ipc,sc_pad_t pad,sc_pad_28fdsoi_dse_t * dse,sc_pad_28fdsoi_ps_t * ps)283 sc_err_t sc_pad_get_gp_28fdsoi(sc_ipc_t ipc, sc_pad_t pad,
284 			       sc_pad_28fdsoi_dse_t *dse,
285 			       sc_pad_28fdsoi_ps_t *ps)
286 {
287 	sc_rpc_msg_t msg;
288 	uint8_t result;
289 
290 	RPC_VER(&msg) = SC_RPC_VERSION;
291 	RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PAD;
292 	RPC_FUNC(&msg) = (uint8_t)PAD_FUNC_GET_GP_28FDSOI;
293 	RPC_U16(&msg, 0U) = (uint16_t)pad;
294 	RPC_SIZE(&msg) = 2U;
295 
296 	sc_call_rpc(ipc, &msg, SC_FALSE);
297 
298 	result = RPC_R8(&msg);
299 	if (dse != NULL) {
300 		*dse = RPC_U8(&msg, 0U);
301 	}
302 
303 	if (ps != NULL) {
304 		*ps = RPC_U8(&msg, 1U);
305 	}
306 
307 	return (sc_err_t)result;
308 }
309 
sc_pad_set_gp_28fdsoi_hsic(sc_ipc_t ipc,sc_pad_t pad,sc_pad_28fdsoi_dse_t dse,sc_bool_t hys,sc_pad_28fdsoi_pus_t pus,sc_bool_t pke,sc_bool_t pue)310 sc_err_t sc_pad_set_gp_28fdsoi_hsic(sc_ipc_t ipc, sc_pad_t pad,
311 				    sc_pad_28fdsoi_dse_t dse, sc_bool_t hys,
312 				    sc_pad_28fdsoi_pus_t pus, sc_bool_t pke,
313 				    sc_bool_t pue)
314 {
315 	sc_rpc_msg_t msg;
316 	uint8_t result;
317 
318 	RPC_VER(&msg) = SC_RPC_VERSION;
319 	RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PAD;
320 	RPC_FUNC(&msg) = (uint8_t)PAD_FUNC_SET_GP_28FDSOI_HSIC;
321 	RPC_U16(&msg, 0U) = (uint16_t)pad;
322 	RPC_U8(&msg, 2U) = (uint8_t)dse;
323 	RPC_U8(&msg, 3U) = (uint8_t)pus;
324 	RPC_U8(&msg, 4U) = (uint8_t)hys;
325 	RPC_U8(&msg, 5U) = (uint8_t)pke;
326 	RPC_U8(&msg, 6U) = (uint8_t)pue;
327 	RPC_SIZE(&msg) = 3U;
328 
329 	sc_call_rpc(ipc, &msg, SC_FALSE);
330 
331 	result = RPC_R8(&msg);
332 	return (sc_err_t)result;
333 }
334 
sc_pad_get_gp_28fdsoi_hsic(sc_ipc_t ipc,sc_pad_t pad,sc_pad_28fdsoi_dse_t * dse,sc_bool_t * hys,sc_pad_28fdsoi_pus_t * pus,sc_bool_t * pke,sc_bool_t * pue)335 sc_err_t sc_pad_get_gp_28fdsoi_hsic(sc_ipc_t ipc, sc_pad_t pad,
336 				    sc_pad_28fdsoi_dse_t *dse, sc_bool_t *hys,
337 				    sc_pad_28fdsoi_pus_t *pus, sc_bool_t *pke,
338 				    sc_bool_t *pue)
339 {
340 	sc_rpc_msg_t msg;
341 	uint8_t result;
342 
343 	RPC_VER(&msg) = SC_RPC_VERSION;
344 	RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PAD;
345 	RPC_FUNC(&msg) = (uint8_t)PAD_FUNC_GET_GP_28FDSOI_HSIC;
346 	RPC_U16(&msg, 0U) = (uint16_t)pad;
347 	RPC_SIZE(&msg) = 2U;
348 
349 	sc_call_rpc(ipc, &msg, SC_FALSE);
350 
351 	result = RPC_R8(&msg);
352 	if (dse != NULL) {
353 		*dse = RPC_U8(&msg, 0U);
354 	}
355 
356 	if (pus != NULL) {
357 		*pus = RPC_U8(&msg, 1U);
358 	}
359 
360 	if (hys != NULL) {
361 		*hys = RPC_U8(&msg, 2U);
362 	}
363 
364 	if (pke != NULL) {
365 		*pke = RPC_U8(&msg, 3U);
366 	}
367 
368 	if (pue != NULL) {
369 		*pue = RPC_U8(&msg, 4U);
370 	}
371 
372 	return (sc_err_t)result;
373 }
374 
sc_pad_set_gp_28fdsoi_comp(sc_ipc_t ipc,sc_pad_t pad,uint8_t compen,sc_bool_t fastfrz,uint8_t rasrcp,uint8_t rasrcn,sc_bool_t nasrc_sel,sc_bool_t psw_ovr)375 sc_err_t sc_pad_set_gp_28fdsoi_comp(sc_ipc_t ipc, sc_pad_t pad,
376 				    uint8_t compen, sc_bool_t fastfrz,
377 				    uint8_t rasrcp, uint8_t rasrcn,
378 				    sc_bool_t nasrc_sel, sc_bool_t psw_ovr)
379 {
380 	sc_rpc_msg_t msg;
381 	uint8_t result;
382 
383 	RPC_VER(&msg) = SC_RPC_VERSION;
384 	RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PAD;
385 	RPC_FUNC(&msg) = (uint8_t)PAD_FUNC_SET_GP_28FDSOI_COMP;
386 	RPC_U16(&msg, 0U) = (uint16_t)pad;
387 	RPC_U8(&msg, 2U) = (uint8_t)compen;
388 	RPC_U8(&msg, 3U) = (uint8_t)rasrcp;
389 	RPC_U8(&msg, 4U) = (uint8_t)rasrcn;
390 	RPC_U8(&msg, 5U) = (uint8_t)fastfrz;
391 	RPC_U8(&msg, 6U) = (uint8_t)nasrc_sel;
392 	RPC_U8(&msg, 7U) = (uint8_t)psw_ovr;
393 	RPC_SIZE(&msg) = 3U;
394 
395 	sc_call_rpc(ipc, &msg, SC_FALSE);
396 
397 	result = RPC_R8(&msg);
398 	return (sc_err_t)result;
399 }
400 
sc_pad_get_gp_28fdsoi_comp(sc_ipc_t ipc,sc_pad_t pad,uint8_t * compen,sc_bool_t * fastfrz,uint8_t * rasrcp,uint8_t * rasrcn,sc_bool_t * nasrc_sel,sc_bool_t * compok,uint8_t * nasrc,sc_bool_t * psw_ovr)401 sc_err_t sc_pad_get_gp_28fdsoi_comp(sc_ipc_t ipc, sc_pad_t pad,
402 				    uint8_t *compen, sc_bool_t *fastfrz,
403 				    uint8_t *rasrcp, uint8_t *rasrcn,
404 				    sc_bool_t *nasrc_sel, sc_bool_t *compok,
405 				    uint8_t *nasrc, sc_bool_t *psw_ovr)
406 {
407 	sc_rpc_msg_t msg;
408 	uint8_t result;
409 
410 	RPC_VER(&msg) = SC_RPC_VERSION;
411 	RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PAD;
412 	RPC_FUNC(&msg) = (uint8_t)PAD_FUNC_GET_GP_28FDSOI_COMP;
413 	RPC_U16(&msg, 0U) = (uint16_t)pad;
414 	RPC_SIZE(&msg) = 2U;
415 
416 	sc_call_rpc(ipc, &msg, SC_FALSE);
417 
418 	result = RPC_R8(&msg);
419 	if (compen != NULL) {
420 		*compen = RPC_U8(&msg, 0U);
421 	}
422 
423 	if (rasrcp != NULL) {
424 		*rasrcp = RPC_U8(&msg, 1U);
425 	}
426 
427 	if (rasrcn != NULL) {
428 		*rasrcn = RPC_U8(&msg, 2U);
429 	}
430 
431 	if (nasrc != NULL) {
432 		*nasrc = RPC_U8(&msg, 3U);
433 	}
434 
435 	if (fastfrz != NULL) {
436 		*fastfrz = RPC_U8(&msg, 4U);
437 	}
438 
439 	if (nasrc_sel != NULL) {
440 		*nasrc_sel = RPC_U8(&msg, 5U);
441 	}
442 
443 	if (compok != NULL) {
444 		*compok = RPC_U8(&msg, 6U);
445 	}
446 
447 	if (psw_ovr != NULL) {
448 		*psw_ovr = RPC_U8(&msg, 7U);
449 	}
450 
451 	return (sc_err_t)result;
452 }
453 
454 /**@}*/
455