csi_ioctl.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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) csi_copy_data(a, b, c)
  61. #define copy_to_user(a, b, c) csi_copy_data(a, b, c)
  62. #define __user
  63. #define __iomem
  64. void csi_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 "csi_ioctl.h"
  74. #include "vivcsi_hub.h"
  75. long csi_priv_ioctl(struct vvcam_csi_dev *dev, unsigned int cmd, void *args)
  76. {
  77. int ret = -1;
  78. if (!dev) {
  79. return ret;
  80. }
  81. switch (cmd) {
  82. case VVCSI_IOC_S_RESET:
  83. ret = vivcsi_hub_reset(dev);
  84. break;
  85. case VVCSI_IOC_S_POWER:
  86. copy_from_user(&dev->power_status, args, sizeof(dev->power_status));
  87. ret = vivcsi_hub_set_power(dev);
  88. break;
  89. case VVCSI_IOC_G_POWER:
  90. ret = vivcsi_hub_get_power(dev);
  91. copy_to_user(args, &dev->power_status, sizeof(dev->power_status));
  92. break;
  93. case VVCSI_IOC_S_CLOCK:
  94. copy_from_user(&dev->clock, args, sizeof(dev->clock));
  95. ret = vivcsi_hub_set_clock(dev);
  96. break;
  97. case VVCSI_IOC_G_CLOCK:
  98. ret = vivcsi_hub_get_clock(dev);
  99. copy_to_user(args, &dev->clock, sizeof(dev->clock));
  100. ret = 0;
  101. break;
  102. case VVCSI_IOC_S_STREAM:
  103. copy_from_user(&dev->streaming_enable, args, sizeof(dev->streaming_enable));
  104. ret = vivcsi_hub_set_stream_control(dev);
  105. break;
  106. case VVCSI_IOC_G_STREAM:
  107. ret = vivcsi_hub_get_stream_control(dev);
  108. copy_to_user(args, &dev->streaming_enable, sizeof(dev->streaming_enable));
  109. break;
  110. case VVCSI_IOC_S_FMT:
  111. copy_from_user(&dev->csi_format, args, sizeof(dev->csi_format));
  112. ret = vivcsi_hub_set_fmt(dev);
  113. break;
  114. case VVCSI_IOC_G_FMT:
  115. ret = vivcsi_hub_get_fmt(dev);
  116. copy_to_user(args, &dev->csi_format, sizeof(dev->csi_format));
  117. break;
  118. case VVCSI_IOC_S_VC_SELECT:
  119. copy_from_user(&dev->csi_vc_select, args, sizeof(dev->csi_vc_select));
  120. ret = vivcsi_hub_set_vc_select(dev);
  121. break;
  122. case VVCSI_IOC_G_VC_SELECT:
  123. ret = vivcsi_hub_get_vc_select(dev);
  124. copy_to_user(args, &dev->csi_vc_select, sizeof(dev->csi_vc_select));
  125. break;
  126. case VVCSI_IOC_S_LANE_CFG:
  127. copy_from_user(&dev->csi_lane_cfg, args, sizeof(dev->csi_lane_cfg));
  128. ret = vivcsi_hub_set_csi_lane_cfg(dev);
  129. break;
  130. default:
  131. pr_err("unsupported command %d", cmd);
  132. break;
  133. }
  134. return ret;
  135. }
  136. extern struct vvcam_csi_hardware_function_s nwl_mipi_function;
  137. int vvnative_csi_init(struct vvcam_csi_dev *dev)
  138. {
  139. int ret = 0;
  140. if (dev == NULL)
  141. {
  142. pr_err("[%s] dev is NULL\n", __func__);
  143. return -1;
  144. }
  145. vvcsi_register_hardware(dev,&nwl_mipi_function);
  146. if (dev->csi_hard_func.init)
  147. {
  148. ret = dev->csi_hard_func.init(dev);
  149. if (ret < 0)
  150. {
  151. pr_err("[%s] init failed\n", __func__);
  152. return -1;
  153. }
  154. }
  155. return 0;
  156. }
  157. int vvnative_csi_deinit(struct vvcam_csi_dev *dev)
  158. {
  159. int ret = 0;
  160. if (dev == NULL)
  161. {
  162. pr_err("[%s] dev is NULL\n", __func__);
  163. return -1;
  164. }
  165. if (dev->csi_hard_func.exit)
  166. {
  167. ret = dev->csi_hard_func.exit(dev);
  168. if (ret < 0)
  169. {
  170. pr_err("[%s] exit failed\n", __func__);
  171. return -1;
  172. }
  173. }
  174. return 0;
  175. }