soc_ioctl.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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 *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. adfasf
  85. case VVSOC_IOC_S_RESET_ISP:
  86. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  87. ret = vivsoc_hub_isp_reset(dev, &soc_ctrl);
  88. break;
  89. case VVSOC_IOC_S_POWER_ISP:
  90. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  91. ret = vivsoc_hub_isp_s_power_ctrl(dev, &soc_ctrl);
  92. break;
  93. case VVSOC_IOC_G_POWER_ISP:
  94. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  95. ret = vivsoc_hub_isp_g_power_ctrl(dev, &soc_ctrl);
  96. copy_to_user(args, &soc_ctrl, sizeof(soc_ctrl));
  97. break;
  98. case VVSOC_IOC_S_CLOCK_ISP:
  99. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  100. ret = vivsoc_hub_isp_s_clock_ctrl(dev, &soc_ctrl);
  101. break;
  102. case VVSOC_IOC_G_CLOCK_ISP:
  103. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  104. ret = vivsoc_hub_isp_g_clock_ctrl(dev, &soc_ctrl);
  105. copy_to_user(args, &soc_ctrl, sizeof(soc_ctrl));
  106. break;
  107. /* DWE part */
  108. case VVSOC_IOC_S_RESET_DWE:
  109. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  110. ret = vivsoc_hub_dwe_reset(dev, &soc_ctrl);
  111. break;
  112. case VVSOC_IOC_S_POWER_DWE:
  113. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  114. ret = vivsoc_hub_dwe_s_power_ctrl(dev, &soc_ctrl);
  115. break;
  116. case VVSOC_IOC_G_POWER_DWE:
  117. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  118. ret = vivsoc_hub_dwe_g_power_ctrl(dev, &soc_ctrl);
  119. copy_to_user(args, &soc_ctrl, sizeof(soc_ctrl));
  120. break;
  121. case VVSOC_IOC_S_CLOCK_DWE:
  122. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  123. ret = vivsoc_hub_dwe_s_clock_ctrl(dev, &soc_ctrl);
  124. break;
  125. case VVSOC_IOC_G_CLOCK_DWE:
  126. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  127. ret = vivsoc_hub_isp_g_clock_ctrl(dev, &soc_ctrl);
  128. copy_to_user(args, &soc_ctrl, sizeof(soc_ctrl));
  129. break;
  130. /* VSE part */
  131. case VVSOC_IOC_S_RESET_VSE:
  132. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  133. ret = vivsoc_hub_vse_reset(dev, &soc_ctrl);
  134. break;
  135. case VVSOC_IOC_S_POWER_VSE:
  136. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  137. ret = vivsoc_hub_vse_s_power_ctrl(dev, &soc_ctrl);
  138. break;
  139. case VVSOC_IOC_G_POWER_VSE:
  140. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  141. ret = vivsoc_hub_vse_g_power_ctrl(dev, &soc_ctrl);
  142. copy_to_user(args, &soc_ctrl, sizeof(soc_ctrl));
  143. break;
  144. case VVSOC_IOC_S_CLOCK_VSE:
  145. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  146. ret = vivsoc_hub_vse_s_clock_ctrl(dev, &soc_ctrl);
  147. break;
  148. case VVSOC_IOC_G_CLOCK_VSE:
  149. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  150. ret = vivsoc_hub_vse_g_clock_ctrl(dev, &soc_ctrl);
  151. copy_to_user(args, &soc_ctrl, sizeof(soc_ctrl));
  152. break;
  153. /* CSI part */
  154. case VVSOC_IOC_S_RESET_CSI:
  155. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  156. ret = vivsoc_hub_csi_reset(dev, &soc_ctrl);
  157. break;
  158. case VVSOC_IOC_S_POWER_CSI:
  159. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  160. ret = vivsoc_hub_csi_s_power_ctrl(dev, &soc_ctrl);
  161. break;
  162. case VVSOC_IOC_G_POWER_CSI:
  163. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  164. ret = vivsoc_hub_csi_g_power_ctrl(dev, &soc_ctrl);
  165. copy_to_user(args, &soc_ctrl, sizeof(soc_ctrl));
  166. break;
  167. case VVSOC_IOC_S_CLOCK_CSI:
  168. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  169. ret = vivsoc_hub_csi_s_clock_ctrl(dev, &soc_ctrl);
  170. break;
  171. case VVSOC_IOC_G_CLOCK_CSI:
  172. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  173. ret = vivsoc_hub_csi_g_clock_ctrl(dev, &soc_ctrl);
  174. copy_to_user(args, &soc_ctrl, sizeof(soc_ctrl));
  175. break;
  176. /* sensor part */
  177. case VVSOC_IOC_S_RESET_SENSOR:
  178. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  179. ret = vivsoc_hub_sensor_reset(dev, &soc_ctrl);
  180. break;
  181. case VVSOC_IOC_S_POWER_SENSOR:
  182. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  183. ret = vivsoc_hub_sensor_s_power_ctrl(dev, &soc_ctrl);
  184. break;
  185. case VVSOC_IOC_G_POWER_SENSOR:
  186. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  187. ret = vivsoc_hub_sensor_g_power_ctrl(dev, &soc_ctrl);
  188. copy_to_user(args, &soc_ctrl, sizeof(soc_ctrl));
  189. break;
  190. case VVSOC_IOC_S_CLOCK_SENSOR:
  191. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  192. ret = vivsoc_hub_sensor_s_clock_ctrl(dev, &soc_ctrl);
  193. break;
  194. case VVSOC_IOC_G_CLOCK_SENSOR:
  195. copy_from_user(&soc_ctrl, args, sizeof(soc_ctrl));
  196. ret = vivsoc_hub_sensor_g_clock_ctrl(dev, &soc_ctrl);
  197. copy_to_user(args, &soc_ctrl, sizeof(soc_ctrl));
  198. break;
  199. default:
  200. pr_err("unsupported command %d", cmd);
  201. break;
  202. }
  203. return ret;
  204. }
  205. extern struct vvcam_soc_function_s gen6_soc_function;
  206. int vvnative_soc_init(struct vvcam_soc_dev *dev)
  207. {
  208. if (dev == NULL)
  209. {
  210. pr_err("[%s] dev is NULL\n", __func__);
  211. return -1;
  212. }
  213. vivsoc_register_hardware(dev, &gen6_soc_function);
  214. return 0;
  215. }
  216. int vvnative_soc_deinit(struct vvcam_soc_dev *dev)
  217. {
  218. return 0;
  219. }