xref: /openbmc/linux/drivers/firmware/imx/misc.c (revision 565485b8)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2016 Freescale Semiconductor, Inc.
4  * Copyright 2017~2018 NXP
5  *  Author: Dong Aisheng <aisheng.dong@nxp.com>
6  *
7  * File containing client-side RPC functions for the MISC service. These
8  * function are ported to clients that communicate to the SC.
9  *
10  */
11 
12 #include <linux/firmware/imx/svc/misc.h>
13 
14 struct imx_sc_msg_req_misc_set_ctrl {
15 	struct imx_sc_rpc_msg hdr;
16 	u32 ctrl;
17 	u32 val;
18 	u16 resource;
19 } __packed;
20 
21 struct imx_sc_msg_req_misc_get_ctrl {
22 	struct imx_sc_rpc_msg hdr;
23 	u32 ctrl;
24 	u16 resource;
25 } __packed;
26 
27 struct imx_sc_msg_resp_misc_get_ctrl {
28 	struct imx_sc_rpc_msg hdr;
29 	u32 val;
30 } __packed;
31 
32 /*
33  * This function sets a miscellaneous control value.
34  *
35  * @param[in]     ipc         IPC handle
36  * @param[in]     resource    resource the control is associated with
37  * @param[in]     ctrl        control to change
38  * @param[in]     val         value to apply to the control
39  *
40  * @return Returns 0 for success and < 0 for errors.
41  */
42 
43 int imx_sc_misc_set_control(struct imx_sc_ipc *ipc, u32 resource,
44 			    u8 ctrl, u32 val)
45 {
46 	struct imx_sc_msg_req_misc_set_ctrl msg;
47 	struct imx_sc_rpc_msg *hdr = &msg.hdr;
48 
49 	hdr->ver = IMX_SC_RPC_VERSION;
50 	hdr->svc = (uint8_t)IMX_SC_RPC_SVC_MISC;
51 	hdr->func = (uint8_t)IMX_SC_MISC_FUNC_SET_CONTROL;
52 	hdr->size = 4;
53 
54 	msg.ctrl = ctrl;
55 	msg.val = val;
56 	msg.resource = resource;
57 
58 	return imx_scu_call_rpc(ipc, &msg, true);
59 }
60 EXPORT_SYMBOL(imx_sc_misc_set_control);
61 
62 /*
63  * This function gets a miscellaneous control value.
64  *
65  * @param[in]     ipc         IPC handle
66  * @param[in]     resource    resource the control is associated with
67  * @param[in]     ctrl        control to get
68  * @param[out]    val         pointer to return the control value
69  *
70  * @return Returns 0 for success and < 0 for errors.
71  */
72 
73 int imx_sc_misc_get_control(struct imx_sc_ipc *ipc, u32 resource,
74 			    u8 ctrl, u32 *val)
75 {
76 	struct imx_sc_msg_req_misc_get_ctrl msg;
77 	struct imx_sc_msg_resp_misc_get_ctrl *resp;
78 	struct imx_sc_rpc_msg *hdr = &msg.hdr;
79 	int ret;
80 
81 	hdr->ver = IMX_SC_RPC_VERSION;
82 	hdr->svc = (uint8_t)IMX_SC_RPC_SVC_MISC;
83 	hdr->func = (uint8_t)IMX_SC_MISC_FUNC_GET_CONTROL;
84 	hdr->size = 3;
85 
86 	msg.ctrl = ctrl;
87 	msg.resource = resource;
88 
89 	ret = imx_scu_call_rpc(ipc, &msg, true);
90 	if (ret)
91 		return ret;
92 
93 	resp = (struct imx_sc_msg_resp_misc_get_ctrl *)&msg;
94 	if (val != NULL)
95 		*val = resp->val;
96 
97 	return 0;
98 }
99 EXPORT_SYMBOL(imx_sc_misc_get_control);
100