misc.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2016 Freescale Semiconductor, Inc.
  4. * Copyright 2017~2018 NXP
  5. * Author: Dong Aisheng <[email protected]>
  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 __aligned(4);
  18. struct imx_sc_msg_req_cpu_start {
  19. struct imx_sc_rpc_msg hdr;
  20. u32 address_hi;
  21. u32 address_lo;
  22. u16 resource;
  23. u8 enable;
  24. } __packed __aligned(4);
  25. struct imx_sc_msg_req_misc_get_ctrl {
  26. struct imx_sc_rpc_msg hdr;
  27. u32 ctrl;
  28. u16 resource;
  29. } __packed __aligned(4);
  30. struct imx_sc_msg_resp_misc_get_ctrl {
  31. struct imx_sc_rpc_msg hdr;
  32. u32 val;
  33. } __packed __aligned(4);
  34. /*
  35. * This function sets a miscellaneous control value.
  36. *
  37. * @param[in] ipc IPC handle
  38. * @param[in] resource resource the control is associated with
  39. * @param[in] ctrl control to change
  40. * @param[in] val value to apply to the control
  41. *
  42. * @return Returns 0 for success and < 0 for errors.
  43. */
  44. int imx_sc_misc_set_control(struct imx_sc_ipc *ipc, u32 resource,
  45. u8 ctrl, u32 val)
  46. {
  47. struct imx_sc_msg_req_misc_set_ctrl msg;
  48. 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;
  53. msg.ctrl = ctrl;
  54. msg.val = val;
  55. msg.resource = resource;
  56. return imx_scu_call_rpc(ipc, &msg, true);
  57. }
  58. EXPORT_SYMBOL(imx_sc_misc_set_control);
  59. /*
  60. * This function gets a miscellaneous control value.
  61. *
  62. * @param[in] ipc IPC handle
  63. * @param[in] resource resource the control is associated with
  64. * @param[in] ctrl control to get
  65. * @param[out] val pointer to return the control value
  66. *
  67. * @return Returns 0 for success and < 0 for errors.
  68. */
  69. int imx_sc_misc_get_control(struct imx_sc_ipc *ipc, u32 resource,
  70. u8 ctrl, u32 *val)
  71. {
  72. struct imx_sc_msg_req_misc_get_ctrl msg;
  73. struct imx_sc_msg_resp_misc_get_ctrl *resp;
  74. struct imx_sc_rpc_msg *hdr = &msg.hdr;
  75. int ret;
  76. hdr->ver = IMX_SC_RPC_VERSION;
  77. hdr->svc = (uint8_t)IMX_SC_RPC_SVC_MISC;
  78. hdr->func = (uint8_t)IMX_SC_MISC_FUNC_GET_CONTROL;
  79. hdr->size = 3;
  80. msg.ctrl = ctrl;
  81. msg.resource = resource;
  82. ret = imx_scu_call_rpc(ipc, &msg, true);
  83. if (ret)
  84. return ret;
  85. resp = (struct imx_sc_msg_resp_misc_get_ctrl *)&msg;
  86. if (val != NULL)
  87. *val = resp->val;
  88. return 0;
  89. }
  90. EXPORT_SYMBOL(imx_sc_misc_get_control);
  91. /*
  92. * This function starts/stops a CPU identified by @resource
  93. *
  94. * @param[in] ipc IPC handle
  95. * @param[in] resource resource the control is associated with
  96. * @param[in] enable true for start, false for stop
  97. * @param[in] phys_addr initial instruction address to be executed
  98. *
  99. * @return Returns 0 for success and < 0 for errors.
  100. */
  101. int imx_sc_pm_cpu_start(struct imx_sc_ipc *ipc, u32 resource,
  102. bool enable, u64 phys_addr)
  103. {
  104. struct imx_sc_msg_req_cpu_start msg;
  105. struct imx_sc_rpc_msg *hdr = &msg.hdr;
  106. hdr->ver = IMX_SC_RPC_VERSION;
  107. hdr->svc = IMX_SC_RPC_SVC_PM;
  108. hdr->func = IMX_SC_PM_FUNC_CPU_START;
  109. hdr->size = 4;
  110. msg.address_hi = phys_addr >> 32;
  111. msg.address_lo = phys_addr;
  112. msg.resource = resource;
  113. msg.enable = enable;
  114. return imx_scu_call_rpc(ipc, &msg, true);
  115. }
  116. EXPORT_SYMBOL(imx_sc_pm_cpu_start);