mic: vop: Fix use-after-free on remove
[linux/fpc-iii.git] / drivers / firmware / imx / misc.c
blob97f5424dbac9872da032fdb221a8a932cfc47a26
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>
7 * File containing client-side RPC functions for the MISC service. These
8 * function are ported to clients that communicate to the SC.
12 #include <linux/firmware/imx/svc/misc.h>
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;
21 struct imx_sc_msg_req_misc_get_ctrl {
22 struct imx_sc_rpc_msg hdr;
23 u32 ctrl;
24 u16 resource;
25 } __packed;
27 struct imx_sc_msg_resp_misc_get_ctrl {
28 struct imx_sc_rpc_msg hdr;
29 u32 val;
30 } __packed;
33 * This function sets a miscellaneous control value.
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
40 * @return Returns 0 for success and < 0 for errors.
43 int imx_sc_misc_set_control(struct imx_sc_ipc *ipc, u32 resource,
44 u8 ctrl, u32 val)
46 struct imx_sc_msg_req_misc_set_ctrl msg;
47 struct imx_sc_rpc_msg *hdr = &msg.hdr;
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;
54 msg.ctrl = ctrl;
55 msg.val = val;
56 msg.resource = resource;
58 return imx_scu_call_rpc(ipc, &msg, true);
60 EXPORT_SYMBOL(imx_sc_misc_set_control);
63 * This function gets a miscellaneous control value.
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
70 * @return Returns 0 for success and < 0 for errors.
73 int imx_sc_misc_get_control(struct imx_sc_ipc *ipc, u32 resource,
74 u8 ctrl, u32 *val)
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;
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;
86 msg.ctrl = ctrl;
87 msg.resource = resource;
89 ret = imx_scu_call_rpc(ipc, &msg, true);
90 if (ret)
91 return ret;
93 resp = (struct imx_sc_msg_resp_misc_get_ctrl *)&msg;
94 if (val != NULL)
95 *val = resp->val;
97 return 0;
99 EXPORT_SYMBOL(imx_sc_misc_get_control);