misc.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. #include <linux/firmware/imx/svc/misc.h>
  12. struct imx_sc_msg_req_misc_set_ctrl {
  13. struct imx_sc_rpc_msg hdr;
  14. u32 ctrl;
  15. u32 val;
  16. u16 resource;
  17. } __packed;
  18. struct imx_sc_msg_req_misc_get_ctrl {
  19. struct imx_sc_rpc_msg hdr;
  20. u32 ctrl;
  21. u16 resource;
  22. } __packed;
  23. struct imx_sc_msg_resp_misc_get_ctrl {
  24. struct imx_sc_rpc_msg hdr;
  25. u32 val;
  26. } __packed;
  27. /*
  28. * This function sets a miscellaneous control value.
  29. *
  30. * @param[in] ipc IPC handle
  31. * @param[in] resource resource the control is associated with
  32. * @param[in] ctrl control to change
  33. * @param[in] val value to apply to the control
  34. *
  35. * @return Returns 0 for success and < 0 for errors.
  36. */
  37. int imx_sc_misc_set_control(struct imx_sc_ipc *ipc, u32 resource,
  38. u8 ctrl, u32 val)
  39. {
  40. struct imx_sc_msg_req_misc_set_ctrl msg;
  41. struct imx_sc_rpc_msg *hdr = &msg.hdr;
  42. hdr->ver = IMX_SC_RPC_VERSION;
  43. hdr->svc = (uint8_t)IMX_SC_RPC_SVC_MISC;
  44. hdr->func = (uint8_t)IMX_SC_MISC_FUNC_SET_CONTROL;
  45. hdr->size = 4;
  46. msg.ctrl = ctrl;
  47. msg.val = val;
  48. msg.resource = resource;
  49. return imx_scu_call_rpc(ipc, &msg, true);
  50. }
  51. EXPORT_SYMBOL(imx_sc_misc_set_control);
  52. /*
  53. * This function gets a miscellaneous control value.
  54. *
  55. * @param[in] ipc IPC handle
  56. * @param[in] resource resource the control is associated with
  57. * @param[in] ctrl control to get
  58. * @param[out] val pointer to return the control value
  59. *
  60. * @return Returns 0 for success and < 0 for errors.
  61. */
  62. int imx_sc_misc_get_control(struct imx_sc_ipc *ipc, u32 resource,
  63. u8 ctrl, u32 *val)
  64. {
  65. struct imx_sc_msg_req_misc_get_ctrl msg;
  66. struct imx_sc_msg_resp_misc_get_ctrl *resp;
  67. struct imx_sc_rpc_msg *hdr = &msg.hdr;
  68. int ret;
  69. hdr->ver = IMX_SC_RPC_VERSION;
  70. hdr->svc = (uint8_t)IMX_SC_RPC_SVC_MISC;
  71. hdr->func = (uint8_t)IMX_SC_MISC_FUNC_GET_CONTROL;
  72. hdr->size = 3;
  73. msg.ctrl = ctrl;
  74. msg.resource = resource;
  75. ret = imx_scu_call_rpc(ipc, &msg, true);
  76. if (ret)
  77. return ret;
  78. resp = (struct imx_sc_msg_resp_misc_get_ctrl *)&msg;
  79. if (val != NULL)
  80. *val = resp->val;
  81. return 0;
  82. }
  83. EXPORT_SYMBOL(imx_sc_misc_get_control);