Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0+
0002 /*
0003  * Copyright (C) 2016 Freescale Semiconductor, Inc.
0004  * Copyright 2017~2018 NXP
0005  *  Author: Dong Aisheng <aisheng.dong@nxp.com>
0006  *
0007  * File containing client-side RPC functions for the MISC service. These
0008  * function are ported to clients that communicate to the SC.
0009  *
0010  */
0011 
0012 #include <linux/firmware/imx/svc/misc.h>
0013 
0014 struct imx_sc_msg_req_misc_set_ctrl {
0015     struct imx_sc_rpc_msg hdr;
0016     u32 ctrl;
0017     u32 val;
0018     u16 resource;
0019 } __packed __aligned(4);
0020 
0021 struct imx_sc_msg_req_cpu_start {
0022     struct imx_sc_rpc_msg hdr;
0023     u32 address_hi;
0024     u32 address_lo;
0025     u16 resource;
0026     u8 enable;
0027 } __packed __aligned(4);
0028 
0029 struct imx_sc_msg_req_misc_get_ctrl {
0030     struct imx_sc_rpc_msg hdr;
0031     u32 ctrl;
0032     u16 resource;
0033 } __packed __aligned(4);
0034 
0035 struct imx_sc_msg_resp_misc_get_ctrl {
0036     struct imx_sc_rpc_msg hdr;
0037     u32 val;
0038 } __packed __aligned(4);
0039 
0040 /*
0041  * This function sets a miscellaneous control value.
0042  *
0043  * @param[in]     ipc         IPC handle
0044  * @param[in]     resource    resource the control is associated with
0045  * @param[in]     ctrl        control to change
0046  * @param[in]     val         value to apply to the control
0047  *
0048  * @return Returns 0 for success and < 0 for errors.
0049  */
0050 
0051 int imx_sc_misc_set_control(struct imx_sc_ipc *ipc, u32 resource,
0052                 u8 ctrl, u32 val)
0053 {
0054     struct imx_sc_msg_req_misc_set_ctrl msg;
0055     struct imx_sc_rpc_msg *hdr = &msg.hdr;
0056 
0057     hdr->ver = IMX_SC_RPC_VERSION;
0058     hdr->svc = (uint8_t)IMX_SC_RPC_SVC_MISC;
0059     hdr->func = (uint8_t)IMX_SC_MISC_FUNC_SET_CONTROL;
0060     hdr->size = 4;
0061 
0062     msg.ctrl = ctrl;
0063     msg.val = val;
0064     msg.resource = resource;
0065 
0066     return imx_scu_call_rpc(ipc, &msg, true);
0067 }
0068 EXPORT_SYMBOL(imx_sc_misc_set_control);
0069 
0070 /*
0071  * This function gets a miscellaneous control value.
0072  *
0073  * @param[in]     ipc         IPC handle
0074  * @param[in]     resource    resource the control is associated with
0075  * @param[in]     ctrl        control to get
0076  * @param[out]    val         pointer to return the control value
0077  *
0078  * @return Returns 0 for success and < 0 for errors.
0079  */
0080 
0081 int imx_sc_misc_get_control(struct imx_sc_ipc *ipc, u32 resource,
0082                 u8 ctrl, u32 *val)
0083 {
0084     struct imx_sc_msg_req_misc_get_ctrl msg;
0085     struct imx_sc_msg_resp_misc_get_ctrl *resp;
0086     struct imx_sc_rpc_msg *hdr = &msg.hdr;
0087     int ret;
0088 
0089     hdr->ver = IMX_SC_RPC_VERSION;
0090     hdr->svc = (uint8_t)IMX_SC_RPC_SVC_MISC;
0091     hdr->func = (uint8_t)IMX_SC_MISC_FUNC_GET_CONTROL;
0092     hdr->size = 3;
0093 
0094     msg.ctrl = ctrl;
0095     msg.resource = resource;
0096 
0097     ret = imx_scu_call_rpc(ipc, &msg, true);
0098     if (ret)
0099         return ret;
0100 
0101     resp = (struct imx_sc_msg_resp_misc_get_ctrl *)&msg;
0102     if (val != NULL)
0103         *val = resp->val;
0104 
0105     return 0;
0106 }
0107 EXPORT_SYMBOL(imx_sc_misc_get_control);
0108 
0109 /*
0110  * This function starts/stops a CPU identified by @resource
0111  *
0112  * @param[in]     ipc         IPC handle
0113  * @param[in]     resource    resource the control is associated with
0114  * @param[in]     enable      true for start, false for stop
0115  * @param[in]     phys_addr   initial instruction address to be executed
0116  *
0117  * @return Returns 0 for success and < 0 for errors.
0118  */
0119 int imx_sc_pm_cpu_start(struct imx_sc_ipc *ipc, u32 resource,
0120             bool enable, u64 phys_addr)
0121 {
0122     struct imx_sc_msg_req_cpu_start msg;
0123     struct imx_sc_rpc_msg *hdr = &msg.hdr;
0124 
0125     hdr->ver = IMX_SC_RPC_VERSION;
0126     hdr->svc = IMX_SC_RPC_SVC_PM;
0127     hdr->func = IMX_SC_PM_FUNC_CPU_START;
0128     hdr->size = 4;
0129 
0130     msg.address_hi = phys_addr >> 32;
0131     msg.address_lo = phys_addr;
0132     msg.resource = resource;
0133     msg.enable = enable;
0134 
0135     return imx_scu_call_rpc(ipc, &msg, true);
0136 }
0137 EXPORT_SYMBOL(imx_sc_pm_cpu_start);