vvnative_combo.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  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/cdev.h> /* Charactor device support */
  54. #include <linux/i2c.h>
  55. #include "isp_ioctl.h"
  56. #include "sensor_ioctl.h"
  57. #include "csi_ioctl.h"
  58. #include "soc_ioctl.h"
  59. #include "dwe_ioctl.h"
  60. #include "vse_ioctl.h"
  61. #include "vvnative.h"
  62. #include "vvnative_combo.h"
  63. /* IOCTL combos */
  64. long vvcam_combo_isp_ioctl(struct vvcam_isp_dev *vvcam_isp_drv,unsigned int cmd, void *args)
  65. {
  66. long ret;
  67. struct isp_ic_dev * dev;
  68. if(NULL == vvcam_isp_drv)
  69. {
  70. pr_err("-->%s: NULL pointer input!\n", __func__);
  71. return -1;
  72. }
  73. mutex_lock(&vvcam_isp_drv->vvmutex);
  74. pr_info("-->%s: Ioctl runs, cmd:%d, args:%px...\n", __func__, cmd, args);
  75. dev = (struct isp_ic_dev *)vvcam_isp_drv->private_ctx;
  76. ret = isp_priv_ioctl(dev, cmd, args);
  77. mutex_unlock(&vvcam_isp_drv->vvmutex);
  78. return ret;
  79. }
  80. long vvcam_combo_csi_ioctl(struct vvcam_isp_dev *vvcam_isp_drv,unsigned int cmd, void *args)
  81. {
  82. long ret;
  83. struct vvcam_csi_dev *dev;
  84. if(NULL == vvcam_isp_drv)
  85. {
  86. pr_err("-->%s: NULL pointer input!\n", __func__);
  87. return -1;
  88. }
  89. mutex_lock(&vvcam_isp_drv->vvmutex);
  90. dev = (struct vvcam_csi_dev *)vvcam_isp_drv->private_ctx;
  91. ret = csi_priv_ioctl(dev, cmd, args);
  92. mutex_unlock(&vvcam_isp_drv->vvmutex);
  93. return ret;
  94. }
  95. #if 0
  96. static struct i2c_board_info sensor_i2c_info =
  97. {
  98. I2C_BOARD_INFO("sensor_ov2775", 0x00),
  99. };
  100. static void *vvcamGetSensorI2cClient(struct vvcam_isp_dev *vvcam_isp_drv)
  101. {
  102. struct i2c_adapter *i2c_adap;
  103. static struct i2c_client *i2c_client = NULL;
  104. if (i2c_client == NULL)
  105. {
  106. i2c_adap = i2c_get_adapter(0);
  107. i2c_client = i2c_new_device(i2c_adap, &sensor_i2c_info);
  108. i2c_put_adapter(i2c_adap);
  109. }
  110. return i2c_client;
  111. }
  112. #endif
  113. long vvcam_combo_sensor_ioctl(struct vvcam_isp_dev *vvcam_isp_drv,unsigned int cmd, void *args)
  114. {
  115. long ret;
  116. struct vvcam_sensor_dev * dev;
  117. if(NULL == vvcam_isp_drv)
  118. {
  119. pr_err("-->%s: NULL pointer input!\n", __func__);
  120. return -1;
  121. }
  122. mutex_lock(&vvcam_isp_drv->vvmutex);
  123. pr_info("-->%s: Ioctl runs, cmd:%d, args:%px...\n", __func__, cmd, args);
  124. dev = (struct vvcam_sensor_dev *)vvcam_isp_drv->private_ctx;
  125. ret = sensor_priv_ioctl(dev, cmd, (void __user *)args);
  126. mutex_unlock(&vvcam_isp_drv->vvmutex);
  127. return ret;
  128. }
  129. long vvcam_combo_dwe_ioctl(struct vvcam_isp_dev *vvcam_isp_drv,unsigned int cmd, void *args)
  130. {
  131. long ret;
  132. struct dwe_ic_dev *dev;
  133. mutex_lock(&vvcam_isp_drv->vvmutex);
  134. pr_info("-->%s: Ioctl runs, cmd:%d, args:%px...\n", __func__, cmd, args);
  135. dev = (struct dwe_ic_dev *)vvcam_isp_drv->private_ctx;
  136. ret = dwe_priv_ioctl(dev, cmd, args);
  137. mutex_unlock(&vvcam_isp_drv->vvmutex);
  138. return ret;
  139. }
  140. long vvcam_combo_vse_ioctl(struct vvcam_isp_dev *vvcam_isp_drv,unsigned int cmd, void *args)
  141. {
  142. long ret;
  143. struct vse_ic_dev *dev;
  144. mutex_lock(&vvcam_isp_drv->vvmutex);
  145. pr_info("-->%s: Ioctl runs, cmd:%d, args:%px...\n", __func__, cmd, args);
  146. dev = (struct vse_ic_dev *)vvcam_isp_drv->private_ctx;
  147. ret = vse_priv_ioctl(dev, cmd, args);
  148. mutex_unlock(&vvcam_isp_drv->vvmutex);
  149. return ret;
  150. }
  151. long vvcam_combo_soc_ioctl(struct vvcam_isp_dev *vvcam_isp_drv,unsigned int cmd, void *args)
  152. {
  153. long ret;
  154. struct vvcam_soc_dev *dev;
  155. if(NULL == vvcam_isp_drv)
  156. {
  157. pr_err("-->%s: NULL pointer input!\n", __func__);
  158. return -1;
  159. }
  160. mutex_lock(&vvcam_isp_drv->vvmutex);
  161. dev = (struct vvcam_soc_dev *)vvcam_isp_drv->private_ctx;
  162. ret = soc_priv_ioctl(dev, cmd, (void __user)args);
  163. mutex_unlock(&vvcam_isp_drv->vvmutex);
  164. return ret;
  165. }
  166. /* Submodule init combos */
  167. int vvcam_combo_isp_init(struct vvcam_isp_dev *vvcam_isp_drv)
  168. {
  169. int ret = 0;
  170. struct isp_ic_dev * dev;
  171. if(NULL == vvcam_isp_drv)
  172. {
  173. pr_err("-->%s: input NULL pointer!\n", __func__);
  174. return -1;
  175. }
  176. vvcam_isp_drv->private_ctx = kzalloc(sizeof(struct isp_ic_dev), GFP_KERNEL);
  177. if(NULL == vvcam_isp_drv->private_ctx)
  178. {
  179. pr_err("-->%s: internal alloc memory error!\n", __func__);
  180. return -1;
  181. }
  182. dev = (struct isp_ic_dev *)vvcam_isp_drv->private_ctx;
  183. dev->base = vvcam_isp_drv->base_address;
  184. dev->reset = NULL;
  185. return ret;
  186. }
  187. int vvcam_combo_csi_init(struct vvcam_isp_dev *vvcam_isp_drv)
  188. {
  189. int ret = 0;
  190. struct vvcam_csi_dev * dev;
  191. if(NULL == vvcam_isp_drv)
  192. {
  193. pr_err("-->%s: input NULL pointer!\n", __func__);
  194. return -1;
  195. }
  196. vvcam_isp_drv->private_ctx = kzalloc(sizeof(struct vvcam_csi_dev), GFP_KERNEL);
  197. if(NULL == vvcam_isp_drv->private_ctx)
  198. {
  199. pr_err("-->%s: internal alloc memory error!\n", __func__);
  200. return -1;
  201. }
  202. dev = (struct vvcam_csi_dev *)vvcam_isp_drv->private_ctx;
  203. dev->base = vvcam_isp_drv->base_address;
  204. dev->device_idx = vvcam_isp_drv->dev_idx;
  205. ret = vvnative_csi_init(dev);
  206. if (ret != 0)
  207. {
  208. pr_err("-->%s: vvnative_csi_init error!\n", __func__);
  209. return -1;
  210. }
  211. return ret;
  212. }
  213. int vvcam_combo_sensor_init(struct vvcam_isp_dev *vvcam_isp_drv)
  214. {
  215. int ret = 0;
  216. struct vvcam_sensor_dev * dev;
  217. if(NULL == vvcam_isp_drv)
  218. {
  219. pr_err("-->%s: input NULL pointer!\n", __func__);
  220. return -1;
  221. }
  222. vvcam_isp_drv->private_ctx = kzalloc(sizeof(struct vvcam_sensor_dev), GFP_KERNEL);
  223. if(NULL == vvcam_isp_drv->private_ctx)
  224. {
  225. pr_err("-->%s: internal alloc memory error!\n", __func__);
  226. return -1;
  227. }
  228. dev = (struct vvcam_sensor_dev *)vvcam_isp_drv->private_ctx;
  229. dev->phy_addr = vvcam_isp_drv->phy_address;
  230. dev->reg_size = vvcam_isp_drv->size;
  231. dev->base = vvcam_isp_drv->base_address;
  232. dev->device_idx = vvcam_isp_drv->dev_idx;
  233. ret = vvnative_sensor_init(dev);
  234. if (ret != 0)
  235. {
  236. pr_err("-->%s: vvnative_sensor_init error!\n", __func__);
  237. return -1;
  238. }
  239. return ret;
  240. }
  241. int vvcam_combo_dwe_init(struct vvcam_isp_dev *vvcam_isp_drv)
  242. {
  243. int ret = 0;
  244. struct dwe_ic_dev * dev;
  245. if(NULL == vvcam_isp_drv)
  246. {
  247. pr_err("-->%s: input NULL pointer!\n", __func__);
  248. return -1;
  249. }
  250. vvcam_isp_drv->private_ctx = kzalloc(sizeof(struct dwe_ic_dev), GFP_KERNEL);
  251. if(NULL == vvcam_isp_drv->private_ctx)
  252. {
  253. pr_err("-->%s: internal alloc memory error!\n", __func__);
  254. return -1;
  255. }
  256. dev = (struct dwe_ic_dev *)vvcam_isp_drv->private_ctx;
  257. dev->base = vvcam_isp_drv->base_address;
  258. ret = vvnative_dwe_init(dev);
  259. if (ret != 0)
  260. {
  261. pr_err("-->%s: vvnative_dwe_init error!\n", __func__);
  262. return -1;
  263. }
  264. return ret;
  265. }
  266. int vvcam_combo_vse_init(struct vvcam_isp_dev *vvcam_isp_drv)
  267. {
  268. int ret = 0;
  269. struct vse_ic_dev * dev;
  270. if(NULL == vvcam_isp_drv)
  271. {
  272. pr_err("-->%s: input NULL pointer!\n", __func__);
  273. return -1;
  274. }
  275. vvcam_isp_drv->private_ctx = kzalloc(sizeof(struct vse_ic_dev), GFP_KERNEL);
  276. if(NULL == vvcam_isp_drv->private_ctx)
  277. {
  278. pr_err("-->%s: internal alloc memory error!\n", __func__);
  279. return -1;
  280. }
  281. dev = (struct vse_ic_dev *)vvcam_isp_drv->private_ctx;
  282. dev->base = vvcam_isp_drv->base_address;
  283. ret = vvnative_vse_init(dev);
  284. if (ret != 0)
  285. {
  286. pr_err("-->%s: vvnative_vse_init error!\n", __func__);
  287. return -1;
  288. }
  289. return ret;
  290. }
  291. int vvcam_combo_soc_init(struct vvcam_isp_dev *vvcam_isp_drv)
  292. {
  293. int ret = 0;
  294. struct vvcam_soc_dev * dev;
  295. if(NULL == vvcam_isp_drv)
  296. {
  297. pr_err("-->%s: input NULL pointer!\n", __func__);
  298. return -1;
  299. }
  300. vvcam_isp_drv->private_ctx = kzalloc(sizeof(struct vvcam_soc_dev), GFP_KERNEL);
  301. if(NULL == vvcam_isp_drv->private_ctx)
  302. {
  303. pr_err("-->%s: internal alloc memory error!\n", __func__);
  304. return -1;
  305. }
  306. dev = (struct vvcam_soc_dev *)vvcam_isp_drv->private_ctx;
  307. dev->base = vvcam_isp_drv->base_address;
  308. vvnative_soc_init(dev);
  309. return ret;
  310. }
  311. /* Submodule deinit combos */
  312. int vvcam_combo_isp_deinit(struct vvcam_isp_dev *vvcam_isp_drv)
  313. {
  314. int ret = 0;
  315. if(NULL == vvcam_isp_drv)
  316. {
  317. pr_err("-->%s: input NULL pointer!\n", __func__);
  318. return -1;
  319. }
  320. if(NULL != vvcam_isp_drv->private_ctx)
  321. {
  322. kzfree(vvcam_isp_drv->private_ctx);
  323. vvcam_isp_drv->private_ctx = NULL;
  324. }
  325. return ret;
  326. }
  327. int vvcam_combo_csi_deinit(struct vvcam_isp_dev *vvcam_isp_drv)
  328. {
  329. int ret = 0;
  330. struct vvcam_csi_dev * dev;
  331. if(NULL == vvcam_isp_drv)
  332. {
  333. pr_err("-->%s: input NULL pointer!\n", __func__);
  334. return -1;
  335. }
  336. if(NULL != vvcam_isp_drv->private_ctx)
  337. {
  338. dev = (struct vvcam_csi_dev *)vvcam_isp_drv->private_ctx;
  339. vvnative_csi_deinit(dev);
  340. kzfree(vvcam_isp_drv->private_ctx);
  341. vvcam_isp_drv->private_ctx = NULL;
  342. }
  343. return ret;
  344. }
  345. int vvcam_combo_sensor_deinit(struct vvcam_isp_dev *vvcam_isp_drv)
  346. {
  347. int ret = 0;
  348. struct vvcam_sensor_dev * dev;
  349. if(NULL == vvcam_isp_drv)
  350. {
  351. pr_err("-->%s: input NULL pointer!\n", __func__);
  352. return -1;
  353. }
  354. if(NULL != vvcam_isp_drv->private_ctx)
  355. {
  356. dev = (struct vvcam_sensor_dev *)vvcam_isp_drv->private_ctx;
  357. vvnative_sensor_deinit(dev);
  358. kzfree(vvcam_isp_drv->private_ctx);
  359. vvcam_isp_drv->private_ctx = NULL;
  360. }
  361. return ret;
  362. }
  363. int vvcam_combo_dwe_deinit(struct vvcam_isp_dev *vvcam_isp_drv)
  364. {
  365. int ret = 0;
  366. struct dwe_ic_dev * dev;
  367. if(NULL == vvcam_isp_drv)
  368. {
  369. pr_err("-->%s: input NULL pointer!\n", __func__);
  370. return -1;
  371. }
  372. if(NULL != vvcam_isp_drv->private_ctx)
  373. {
  374. dev = (struct dwe_ic_dev *)vvcam_isp_drv->private_ctx;
  375. vvnative_dwe_deinit(dev);
  376. kzfree(vvcam_isp_drv->private_ctx);
  377. vvcam_isp_drv->private_ctx = NULL;
  378. }
  379. return ret;
  380. }
  381. int vvcam_combo_vse_deinit(struct vvcam_isp_dev *vvcam_isp_drv)
  382. {
  383. int ret = 0;
  384. struct vse_ic_dev * dev;
  385. if(NULL == vvcam_isp_drv)
  386. {
  387. pr_err("-->%s: input NULL pointer!\n", __func__);
  388. return -1;
  389. }
  390. if(NULL != vvcam_isp_drv->private_ctx)
  391. {
  392. dev = (struct vse_ic_dev *)vvcam_isp_drv->private_ctx;
  393. vvnative_vse_deinit(dev);
  394. kzfree(vvcam_isp_drv->private_ctx);
  395. vvcam_isp_drv->private_ctx = NULL;
  396. }
  397. return ret;
  398. }
  399. int vvcam_combo_soc_deinit(struct vvcam_isp_dev *vvcam_isp_drv)
  400. {
  401. int ret = 0;
  402. struct vvcam_soc_dev * dev;
  403. if(NULL == vvcam_isp_drv)
  404. {
  405. pr_err("-->%s: input NULL pointer!\n", __func__);
  406. return -1;
  407. }
  408. if(NULL != vvcam_isp_drv->private_ctx)
  409. {
  410. dev = (struct vvcam_soc_dev *)vvcam_isp_drv->private_ctx;
  411. vvnative_soc_deinit(dev);
  412. kzfree(vvcam_isp_drv->private_ctx);
  413. vvcam_isp_drv->private_ctx = NULL;
  414. }
  415. return ret;
  416. }