vivcsi_hub.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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. #include <linux/module.h>
  54. #include <linux/uaccess.h>
  55. #include <linux/i2c.h>
  56. #include "csi_ioctl.h"
  57. #include "vivcsi_hub.h"
  58. unsigned int vvcsi_register_hardware(struct vvcam_csi_dev *dev, struct vvcam_csi_hardware_function_s *func)
  59. {
  60. int ret = 0;
  61. if (func == NULL)
  62. {
  63. return -1;
  64. }
  65. memcpy(&dev->csi_hard_func,func,sizeof(struct vvcam_csi_hardware_function_s));
  66. return 0;
  67. }
  68. int vivcsi_hub_init(struct vvcam_csi_dev *dev)
  69. {
  70. int ret = 0;
  71. if(NULL == dev)
  72. {
  73. pr_err("%s:dev is null!\n", __func__);
  74. return -1;
  75. }
  76. if (dev->csi_hard_func.init == NULL)
  77. {
  78. pr_err("%s:csi_hard_func is NULL!\n", __func__);
  79. return -1;
  80. }
  81. ret = dev->csi_hard_func.init(dev);
  82. return ret;
  83. }
  84. int vivcsi_hub_reset(struct vvcam_csi_dev *dev)
  85. {
  86. int ret = 0;
  87. if(NULL == dev)
  88. {
  89. pr_err("%s:dev is null!\n", __func__);
  90. return -1;
  91. }
  92. if (dev->csi_hard_func.reset == NULL)
  93. {
  94. pr_err("%s:csi_hard_func is NULL!\n", __func__);
  95. return -1;
  96. }
  97. ret = dev->csi_hard_func.reset(dev);
  98. return ret;
  99. }
  100. int vivcsi_hub_set_power(struct vvcam_csi_dev *dev)
  101. {
  102. int ret = 0;
  103. if(NULL == dev)
  104. {
  105. pr_err("%s:dev is null!\n", __func__);
  106. return -1;
  107. }
  108. if (dev->csi_hard_func.set_power == NULL)
  109. {
  110. pr_err("%s:csi_hard_func is NULL!\n", __func__);
  111. return -1;
  112. }
  113. ret = dev->csi_hard_func.set_power(dev);
  114. return ret;
  115. }
  116. int vivcsi_hub_get_power(struct vvcam_csi_dev *dev)
  117. {
  118. int ret = 0;
  119. if(NULL == dev)
  120. {
  121. pr_err("%s:dev is null!\n", __func__);
  122. return -1;
  123. }
  124. if (dev->csi_hard_func.get_power == NULL)
  125. {
  126. pr_err("%s:csi_hard_func is NULL!\n", __func__);
  127. return -1;
  128. }
  129. ret = dev->csi_hard_func.get_power(dev);
  130. return ret;
  131. }
  132. int vivcsi_hub_set_clock(struct vvcam_csi_dev *dev)
  133. {
  134. int ret = 0;
  135. if(NULL == dev)
  136. {
  137. pr_err("%s:dev is null!\n", __func__);
  138. return -1;
  139. }
  140. if (dev->csi_hard_func.set_clock == NULL)
  141. {
  142. pr_err("%s:csi_hard_func is NULL!\n", __func__);
  143. return -1;
  144. }
  145. ret = dev->csi_hard_func.set_clock(dev);
  146. return ret;
  147. }
  148. int vivcsi_hub_get_clock(struct vvcam_csi_dev *dev)
  149. {
  150. int ret = 0;
  151. if(NULL == dev)
  152. {
  153. pr_err("%s:dev is null!\n", __func__);
  154. return -1;
  155. }
  156. if (dev->csi_hard_func.get_clock == NULL)
  157. {
  158. pr_err("%s:csi_hard_func is NULL!\n", __func__);
  159. return -1;
  160. }
  161. ret = dev->csi_hard_func.get_clock(dev);
  162. return ret;
  163. }
  164. int vivcsi_hub_set_stream_control(struct vvcam_csi_dev *dev)
  165. {
  166. int ret = 0;
  167. if(NULL == dev)
  168. {
  169. pr_err("%s:dev is null!\n", __func__);
  170. return -1;
  171. }
  172. if (dev->csi_hard_func.set_stream_control == NULL)
  173. {
  174. pr_err("%s:csi_hard_func is NULL!\n", __func__);
  175. return -1;
  176. }
  177. ret = dev->csi_hard_func.set_stream_control(dev);
  178. return ret;
  179. }
  180. int vivcsi_hub_get_stream_control(struct vvcam_csi_dev *dev)
  181. {
  182. int ret = 0;
  183. if(NULL == dev)
  184. {
  185. pr_err("%s:dev is null!\n", __func__);
  186. return -1;
  187. }
  188. if (dev->csi_hard_func.get_stream_control == NULL)
  189. {
  190. pr_err("%s:csi_hard_func is NULL!\n", __func__);
  191. return -1;
  192. }
  193. ret = dev->csi_hard_func.get_stream_control(dev);
  194. return ret;
  195. }
  196. int vivcsi_hub_set_fmt(struct vvcam_csi_dev *dev)
  197. {
  198. int ret = 0;
  199. if(NULL == dev)
  200. {
  201. pr_err("%s:dev is null!\n", __func__);
  202. return -1;
  203. }
  204. if (dev->csi_hard_func.set_fmt == NULL)
  205. {
  206. pr_err("%s:csi_hard_func is NULL!\n", __func__);
  207. return -1;
  208. }
  209. ret = dev->csi_hard_func.set_fmt(dev);
  210. return ret;
  211. }
  212. int vivcsi_hub_get_fmt(struct vvcam_csi_dev *dev)
  213. {
  214. int ret = 0;
  215. if(NULL == dev)
  216. {
  217. pr_err("%s:dev is null!\n", __func__);
  218. return -1;
  219. }
  220. if (dev->csi_hard_func.get_fmt == NULL)
  221. {
  222. pr_err("%s:csi_hard_func is NULL!\n", __func__);
  223. return -1;
  224. }
  225. ret = dev->csi_hard_func.get_fmt(dev);
  226. return ret;
  227. }
  228. int vivcsi_hub_set_vc_select(struct vvcam_csi_dev *dev)
  229. {
  230. int ret = 0;
  231. if(NULL == dev)
  232. {
  233. pr_err("%s:dev is null!\n", __func__);
  234. return -1;
  235. }
  236. if (dev->csi_hard_func.set_vc_select == NULL)
  237. {
  238. pr_err("%s:csi_hard_func is NULL!\n", __func__);
  239. return -1;
  240. }
  241. ret = dev->csi_hard_func.set_vc_select(dev);
  242. return ret;
  243. }
  244. int vivcsi_hub_get_vc_select(struct vvcam_csi_dev *dev)
  245. {
  246. int ret = 0;
  247. if(NULL == dev)
  248. {
  249. pr_err("%s:dev is null!\n", __func__);
  250. return -1;
  251. }
  252. if (dev->csi_hard_func.get_vc_select == NULL)
  253. {
  254. pr_err("%s:csi_hard_func is NULL!\n", __func__);
  255. return -1;
  256. }
  257. ret = dev->csi_hard_func.get_vc_select(dev);
  258. return ret;
  259. }
  260. int vivcsi_hub_set_csi_lane_cfg(struct vvcam_csi_dev *dev)
  261. {
  262. int ret = 0;
  263. if(NULL == dev)
  264. {
  265. pr_err("%s:dev is null!\n", __func__);
  266. return -1;
  267. }
  268. if (dev->csi_hard_func.set_lane_cfg == NULL)
  269. {
  270. pr_err("%s:csi_hard_func is NULL!\n", __func__);
  271. return -1;
  272. }
  273. ret = dev->csi_hard_func.set_lane_cfg(dev);
  274. return ret;
  275. }