soc_ioctl.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /****************************************************************************
  2. *
  3. * The MIT License (MIT)
  4. *
  5. * Copyright (c) 2020 VeriSilicon Holdings Co., Ltd.
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a
  8. * copy of this software and associated documentation files (the "Software"),
  9. * to deal in the Software without restriction, including without limitation
  10. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  11. * and/or sell copies of the Software, and to permit persons to whom the
  12. * Software is furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in
  15. * all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  22. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. * DEALINGS IN THE SOFTWARE.
  24. *
  25. *****************************************************************************
  26. *
  27. * The GPL License (GPL)
  28. *
  29. * Copyright (c) 2020 VeriSilicon Holdings Co., Ltd.
  30. *
  31. * This program is free software; you can redistribute it and/or
  32. * modify it under the terms of the GNU General Public License
  33. * as published by the Free Software Foundation; either version 2
  34. * of the License, or (at your option) any later version.
  35. *
  36. * This program is distributed in the hope that it will be useful,
  37. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  38. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  39. * GNU General Public License for more details.
  40. *
  41. * You should have received a copy of the GNU General Public License
  42. * along with this program;
  43. *
  44. *****************************************************************************
  45. *
  46. * Note: This software is released under dual MIT and GPL licenses. A
  47. * recipient may use this file under the terms of either the MIT license or
  48. * GPL License. If you wish to use only one license not the other, you can
  49. * indicate your decision by deleting one of the above license notices in your
  50. * version of this file.
  51. *
  52. *****************************************************************************/
  53. #ifndef __KERNEL__
  54. #include <stdlib.h>
  55. #include <stdint.h>
  56. #include <stdbool.h>
  57. #include <errno.h>
  58. #define pr_info printf
  59. #define pr_err printf
  60. #define copy_from_user(a, b, c) soc_copy_data(a, b, c)
  61. #define copy_to_user(a, b, c) soc_copy_data(a, b, c)
  62. #define __user
  63. #define __iomem
  64. void soc_copy_data(void *dst, void *src, int size)
  65. {
  66. if (dst != src)
  67. memcpy(dst, src, size);
  68. }
  69. #else // __KERNEL__
  70. #include <linux/module.h> /* Module support */
  71. #include <linux/uaccess.h>
  72. #endif
  73. #include "soc_ioctl.h"
  74. #include "vivsoc_hub.h"
  75. long soc_priv_ioctl(struct vvcam_soc_dev *dev, unsigned int cmd, void __user *args)
  76. {
  77. int ret = -1;
  78. struct soc_control_context soc_ctrl;
  79. if (!dev) {
  80. return ret;
  81. }
  82. switch (cmd) {
  83. /* ISP part */
  84. case VVSOC_IOC_S_RESET_ISP:
  85. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  86. ret = vivsoc_hub_isp_reset(dev, &soc_ctrl);
  87. break;
  88. case VVSOC_IOC_S_POWER_ISP:
  89. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  90. ret = vivsoc_hub_isp_s_power_ctrl(dev, &soc_ctrl);
  91. break;
  92. case VVSOC_IOC_G_POWER_ISP:
  93. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  94. ret = vivsoc_hub_isp_g_power_ctrl(dev, &soc_ctrl);
  95. copy_to_user(args, &soc_ctrl, sizeof(soc_ctrl));
  96. break;
  97. case VVSOC_IOC_S_CLOCK_ISP:
  98. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  99. ret = vivsoc_hub_isp_s_clock_ctrl(dev, &soc_ctrl);
  100. break;
  101. case VVSOC_IOC_G_CLOCK_ISP:
  102. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  103. ret = vivsoc_hub_isp_g_clock_ctrl(dev, &soc_ctrl);
  104. copy_to_user(args, &soc_ctrl, sizeof(soc_ctrl));
  105. break;
  106. /* DWE part */
  107. case VVSOC_IOC_S_RESET_DWE:
  108. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  109. ret = vivsoc_hub_dwe_reset(dev, &soc_ctrl);
  110. break;
  111. case VVSOC_IOC_S_POWER_DWE:
  112. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  113. ret = vivsoc_hub_dwe_s_power_ctrl(dev, &soc_ctrl);
  114. break;
  115. case VVSOC_IOC_G_POWER_DWE:
  116. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  117. ret = vivsoc_hub_dwe_g_power_ctrl(dev, &soc_ctrl);
  118. copy_to_user(args, &soc_ctrl, sizeof(soc_ctrl));
  119. break;
  120. case VVSOC_IOC_S_CLOCK_DWE:
  121. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  122. ret = vivsoc_hub_dwe_s_clock_ctrl(dev, &soc_ctrl);
  123. break;
  124. case VVSOC_IOC_G_CLOCK_DWE:
  125. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  126. ret = vivsoc_hub_isp_g_clock_ctrl(dev, &soc_ctrl);
  127. copy_to_user(args, &soc_ctrl, sizeof(soc_ctrl));
  128. break;
  129. /* VSE part */
  130. case VVSOC_IOC_S_RESET_VSE:
  131. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  132. ret = vivsoc_hub_vse_reset(dev, &soc_ctrl);
  133. break;
  134. case VVSOC_IOC_S_POWER_VSE:
  135. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  136. ret = vivsoc_hub_vse_s_power_ctrl(dev, &soc_ctrl);
  137. break;
  138. case VVSOC_IOC_G_POWER_VSE:
  139. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  140. ret = vivsoc_hub_vse_g_power_ctrl(dev, &soc_ctrl);
  141. copy_to_user(args, &soc_ctrl, sizeof(soc_ctrl));
  142. break;
  143. case VVSOC_IOC_S_CLOCK_VSE:
  144. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  145. ret = vivsoc_hub_vse_s_clock_ctrl(dev, &soc_ctrl);
  146. break;
  147. case VVSOC_IOC_G_CLOCK_VSE:
  148. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  149. ret = vivsoc_hub_vse_g_clock_ctrl(dev, &soc_ctrl);
  150. copy_to_user(args, &soc_ctrl, sizeof(soc_ctrl));
  151. break;
  152. /* CSI part */
  153. case VVSOC_IOC_S_RESET_CSI:
  154. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  155. ret = vivsoc_hub_csi_reset(dev, &soc_ctrl);
  156. break;
  157. case VVSOC_IOC_S_POWER_CSI:
  158. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  159. ret = vivsoc_hub_csi_s_power_ctrl(dev, &soc_ctrl);
  160. break;
  161. case VVSOC_IOC_G_POWER_CSI:
  162. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  163. ret = vivsoc_hub_csi_g_power_ctrl(dev, &soc_ctrl);
  164. copy_to_user(args, &soc_ctrl, sizeof(soc_ctrl));
  165. break;
  166. case VVSOC_IOC_S_CLOCK_CSI:
  167. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  168. ret = vivsoc_hub_csi_s_clock_ctrl(dev, &soc_ctrl);
  169. break;
  170. case VVSOC_IOC_G_CLOCK_CSI:
  171. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  172. ret = vivsoc_hub_csi_g_clock_ctrl(dev, &soc_ctrl);
  173. copy_to_user(args, &soc_ctrl, sizeof(soc_ctrl));
  174. break;
  175. /* sensor part */
  176. case VVSOC_IOC_S_RESET_SENSOR:
  177. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  178. ret = vivsoc_hub_sensor_reset(dev, &soc_ctrl);
  179. break;
  180. case VVSOC_IOC_S_POWER_SENSOR:
  181. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  182. ret = vivsoc_hub_sensor_s_power_ctrl(dev, &soc_ctrl);
  183. break;
  184. case VVSOC_IOC_G_POWER_SENSOR:
  185. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  186. ret = vivsoc_hub_sensor_g_power_ctrl(dev, &soc_ctrl);
  187. copy_to_user(args, &soc_ctrl, sizeof(soc_ctrl));
  188. break;
  189. case VVSOC_IOC_S_CLOCK_SENSOR:
  190. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  191. ret = vivsoc_hub_sensor_s_clock_ctrl(dev, &soc_ctrl);
  192. break;
  193. case VVSOC_IOC_G_CLOCK_SENSOR:
  194. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  195. ret = vivsoc_hub_sensor_g_clock_ctrl(dev, &soc_ctrl);
  196. copy_to_user(args, &soc_ctrl, sizeof(soc_ctrl));
  197. break;
  198. /*ry part*/
  199. case VVSOC_IOC_S_RESET_ISP_RY:
  200. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  201. ret = vivsoc_hub_isp_ry_reset(dev, &soc_ctrl);
  202. break;
  203. default:
  204. pr_err("unsupported command %d", cmd);
  205. break;
  206. }
  207. return ret;
  208. }
  209. extern struct vvcam_soc_function_s gen6_soc_function;
  210. int vvnative_soc_init(struct vvcam_soc_dev *dev)
  211. {
  212. if (dev == NULL)
  213. {
  214. pr_err("[%s] dev is NULL\n", __func__);
  215. return -1;
  216. }
  217. vivsoc_register_hardware(dev, &gen6_soc_function);
  218. return 0;
  219. }
  220. int vvnative_soc_deinit(struct vvcam_soc_dev *dev)
  221. {
  222. return 0;
  223. }