vivsoc_hub.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  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 "soc_ioctl.h"
  56. #include "vivsoc_hub.h"
  57. #include "vsi_core_gen6.h"
  58. int vivsoc_hub_isp_reset(struct vvcam_soc_dev *dev, struct soc_control_context * soc_ctrl)
  59. {
  60. int ret = 0;
  61. if ((dev==NULL) || (soc_ctrl == NULL))
  62. {
  63. pr_err("[%s]:dev is null\n", __func__);
  64. return -1;
  65. }
  66. if (dev->soc_func.isp_func.set_reset == NULL)
  67. {
  68. pr_err("[%s] function is null\n", __func__);
  69. return -1;
  70. }
  71. ret = dev->soc_func.isp_func.set_reset(dev, soc_ctrl->device_idx, soc_ctrl->control_value);
  72. return ret;
  73. }
  74. int vivsoc_hub_isp_s_power_ctrl(struct vvcam_soc_dev *dev, struct soc_control_context * soc_ctrl)
  75. {
  76. int ret = 0;
  77. if ((dev==NULL) || (soc_ctrl == NULL))
  78. {
  79. pr_err("[%s]:dev is null\n", __func__);
  80. return -1;
  81. }
  82. if (dev->soc_func.isp_func.set_power == NULL)
  83. {
  84. pr_err("[%s] function is null\n", __func__);
  85. return -1;
  86. }
  87. ret = dev->soc_func.isp_func.set_power(dev, soc_ctrl->device_idx, soc_ctrl->control_value);
  88. return ret;
  89. }
  90. int vivsoc_hub_isp_g_power_ctrl(struct vvcam_soc_dev *dev, struct soc_control_context * soc_ctrl)
  91. {
  92. int ret = 0;
  93. if ((dev==NULL) || (soc_ctrl == NULL))
  94. {
  95. pr_err("[%s]:dev is null\n", __func__);
  96. return -1;
  97. }
  98. if (dev->soc_func.isp_func.get_power == NULL)
  99. {
  100. pr_err("[%s] function is null\n", __func__);
  101. return -1;
  102. }
  103. ret = dev->soc_func.isp_func.get_power(dev, soc_ctrl->device_idx, &soc_ctrl->control_value);
  104. return ret;
  105. }
  106. int vivsoc_hub_isp_s_clock_ctrl(struct vvcam_soc_dev *dev, struct soc_control_context * soc_ctrl)
  107. {
  108. int ret = 0;
  109. if ((dev==NULL) || (soc_ctrl == NULL))
  110. {
  111. pr_err("[%s]:dev is null\n", __func__);
  112. return -1;
  113. }
  114. if (dev->soc_func.isp_func.set_clk == NULL)
  115. {
  116. pr_err("[%s] function is null\n", __func__);
  117. return -1;
  118. }
  119. ret = dev->soc_func.isp_func.set_clk(dev, soc_ctrl->device_idx, soc_ctrl->control_value);
  120. return ret;
  121. }
  122. int vivsoc_hub_isp_g_clock_ctrl(struct vvcam_soc_dev *dev, struct soc_control_context * soc_ctrl)
  123. {
  124. int ret = 0;
  125. if ((dev==NULL) || (soc_ctrl == NULL))
  126. {
  127. pr_err("[%s]:dev is null\n", __func__);
  128. return -1;
  129. }
  130. if (dev->soc_func.isp_func.get_clk == NULL)
  131. {
  132. pr_err("[%s] function is null\n", __func__);
  133. return -1;
  134. }
  135. ret = dev->soc_func.isp_func.get_clk(dev, soc_ctrl->device_idx, &soc_ctrl->control_value);
  136. return ret;
  137. }
  138. int vivsoc_hub_dwe_reset(struct vvcam_soc_dev *dev, struct soc_control_context * soc_ctrl)
  139. {
  140. int ret = 0;
  141. if ((dev==NULL) || (soc_ctrl == NULL))
  142. {
  143. pr_err("[%s]:dev is null\n", __func__);
  144. return -1;
  145. }
  146. if (dev->soc_func.dwe_func.set_reset == NULL)
  147. {
  148. pr_err("[%s] function is null\n", __func__);
  149. return -1;
  150. }
  151. ret = dev->soc_func.dwe_func.set_reset(dev, soc_ctrl->device_idx, soc_ctrl->control_value);
  152. return ret;
  153. }
  154. int vivsoc_hub_dwe_s_power_ctrl(struct vvcam_soc_dev *dev, struct soc_control_context * soc_ctrl)
  155. {
  156. int ret = 0;
  157. if ((dev==NULL) || (soc_ctrl == NULL))
  158. {
  159. pr_err("[%s]:dev is null\n", __func__);
  160. return -1;
  161. }
  162. if (dev->soc_func.dwe_func.set_power == NULL)
  163. {
  164. pr_err("[%s] function is null\n", __func__);
  165. return -1;
  166. }
  167. ret = dev->soc_func.dwe_func.set_power(dev, soc_ctrl->device_idx, soc_ctrl->control_value);
  168. return ret;
  169. }
  170. int vivsoc_hub_dwe_g_power_ctrl(struct vvcam_soc_dev *dev, struct soc_control_context * soc_ctrl)
  171. {
  172. int ret = 0;
  173. if ((dev==NULL) || (soc_ctrl == NULL))
  174. {
  175. pr_err("[%s]:dev is null\n", __func__);
  176. return -1;
  177. }
  178. if (dev->soc_func.dwe_func.get_power == NULL)
  179. {
  180. pr_err("[%s] function is null\n", __func__);
  181. return -1;
  182. }
  183. ret = dev->soc_func.dwe_func.get_power(dev, soc_ctrl->device_idx, &soc_ctrl->control_value);
  184. return ret;
  185. }
  186. int vivsoc_hub_dwe_s_clock_ctrl(struct vvcam_soc_dev *dev, struct soc_control_context * soc_ctrl)
  187. {
  188. int ret = 0;
  189. if ((dev==NULL) || (soc_ctrl == NULL))
  190. {
  191. pr_err("[%s]:dev is null\n", __func__);
  192. return -1;
  193. }
  194. if (dev->soc_func.dwe_func.set_clk == NULL)
  195. {
  196. pr_err("[%s] function is null\n", __func__);
  197. return -1;
  198. }
  199. ret = dev->soc_func.dwe_func.set_clk(dev, soc_ctrl->device_idx, soc_ctrl->control_value);
  200. return ret;
  201. }
  202. int vivsoc_hub_dwe_g_clock_ctrl(struct vvcam_soc_dev *dev, struct soc_control_context * soc_ctrl)
  203. {
  204. int ret = 0;
  205. if ((dev==NULL) || (soc_ctrl == NULL))
  206. {
  207. pr_err("[%s]:dev is null\n", __func__);
  208. return -1;
  209. }
  210. if (dev->soc_func.dwe_func.get_clk == NULL)
  211. {
  212. pr_err("[%s] function is null\n", __func__);
  213. return -1;
  214. }
  215. ret = dev->soc_func.dwe_func.get_clk(dev, soc_ctrl->device_idx, &soc_ctrl->control_value);
  216. return ret;
  217. }
  218. int vivsoc_hub_vse_reset(struct vvcam_soc_dev *dev, struct soc_control_context * soc_ctrl)
  219. {
  220. int ret = 0;
  221. if ((dev==NULL) || (soc_ctrl == NULL))
  222. {
  223. pr_err("[%s]:dev is null\n", __func__);
  224. return -1;
  225. }
  226. if (dev->soc_func.vse_func.set_reset == NULL)
  227. {
  228. pr_err("[%s] function is null\n", __func__);
  229. return -1;
  230. }
  231. ret = dev->soc_func.vse_func.set_reset(dev, soc_ctrl->device_idx, soc_ctrl->control_value);
  232. return ret;
  233. }
  234. int vivsoc_hub_vse_s_power_ctrl(struct vvcam_soc_dev *dev, struct soc_control_context * soc_ctrl)
  235. {
  236. int ret = 0;
  237. if ((dev==NULL) || (soc_ctrl == NULL))
  238. {
  239. pr_err("[%s]:dev is null\n", __func__);
  240. return -1;
  241. }
  242. if (dev->soc_func.vse_func.set_power == NULL)
  243. {
  244. pr_err("[%s] function is null\n", __func__);
  245. return -1;
  246. }
  247. ret = dev->soc_func.vse_func.set_power(dev, soc_ctrl->device_idx, soc_ctrl->control_value);
  248. return ret;
  249. }
  250. int vivsoc_hub_vse_g_power_ctrl(struct vvcam_soc_dev *dev, struct soc_control_context * soc_ctrl)
  251. {
  252. int ret = 0;
  253. if ((dev==NULL) || (soc_ctrl == NULL))
  254. {
  255. pr_err("[%s]:dev is null\n", __func__);
  256. return -1;
  257. }
  258. if (dev->soc_func.vse_func.get_power == NULL)
  259. {
  260. pr_err("[%s] function is null\n", __func__);
  261. return -1;
  262. }
  263. ret = dev->soc_func.vse_func.get_power(dev, soc_ctrl->device_idx, &soc_ctrl->control_value);
  264. return ret;
  265. }
  266. int vivsoc_hub_vse_s_clock_ctrl(struct vvcam_soc_dev *dev, struct soc_control_context * soc_ctrl)
  267. {
  268. int ret = 0;
  269. if ((dev==NULL) || (soc_ctrl == NULL))
  270. {
  271. pr_err("[%s]:dev is null\n", __func__);
  272. return -1;
  273. }
  274. if (dev->soc_func.vse_func.set_clk == NULL)
  275. {
  276. pr_err("[%s] function is null\n", __func__);
  277. return -1;
  278. }
  279. ret = dev->soc_func.vse_func.set_clk(dev, soc_ctrl->device_idx, soc_ctrl->control_value);
  280. return ret;
  281. }
  282. int vivsoc_hub_vse_g_clock_ctrl(struct vvcam_soc_dev *dev, struct soc_control_context * soc_ctrl)
  283. {
  284. int ret = 0;
  285. if ((dev==NULL) || (soc_ctrl == NULL))
  286. {
  287. pr_err("[%s]:dev is null\n", __func__);
  288. return -1;
  289. }
  290. if (dev->soc_func.vse_func.get_clk == NULL)
  291. {
  292. pr_err("[%s] function is null\n", __func__);
  293. return -1;
  294. }
  295. ret = dev->soc_func.vse_func.get_clk(dev, soc_ctrl->device_idx, &soc_ctrl->control_value);
  296. return ret;
  297. }
  298. int vivsoc_hub_csi_reset(struct vvcam_soc_dev *dev, struct soc_control_context * soc_ctrl)
  299. {
  300. int ret = 0;
  301. if ((dev==NULL) || (soc_ctrl == NULL))
  302. {
  303. pr_err("[%s]:dev is null\n", __func__);
  304. return -1;
  305. }
  306. if (dev->soc_func.csi_func.set_reset == NULL)
  307. {
  308. pr_err("[%s] function is null\n", __func__);
  309. return -1;
  310. }
  311. ret = dev->soc_func.csi_func.set_reset(dev, soc_ctrl->device_idx, soc_ctrl->control_value);
  312. return ret;
  313. }
  314. int vivsoc_hub_csi_s_power_ctrl(struct vvcam_soc_dev *dev, struct soc_control_context * soc_ctrl)
  315. {
  316. int ret = 0;
  317. if ((dev==NULL) || (soc_ctrl == NULL))
  318. {
  319. pr_err("[%s]:dev is null\n", __func__);
  320. return -1;
  321. }
  322. if (dev->soc_func.csi_func.set_power == NULL)
  323. {
  324. pr_err("[%s] function is null\n", __func__);
  325. return -1;
  326. }
  327. ret = dev->soc_func.csi_func.set_power(dev, soc_ctrl->device_idx, soc_ctrl->control_value);
  328. return ret;
  329. }
  330. int vivsoc_hub_csi_g_power_ctrl(struct vvcam_soc_dev *dev, struct soc_control_context * soc_ctrl)
  331. {
  332. int ret = 0;
  333. if ((dev==NULL) || (soc_ctrl == NULL))
  334. {
  335. pr_err("[%s]:dev is null\n", __func__);
  336. return -1;
  337. }
  338. if (dev->soc_func.csi_func.get_power == NULL)
  339. {
  340. pr_err("[%s] function is null\n", __func__);
  341. return -1;
  342. }
  343. ret = dev->soc_func.csi_func.get_power(dev, soc_ctrl->device_idx, &soc_ctrl->control_value);
  344. return ret;
  345. }
  346. int vivsoc_hub_csi_s_clock_ctrl(struct vvcam_soc_dev *dev, struct soc_control_context * soc_ctrl)
  347. {
  348. int ret = 0;
  349. if ((dev==NULL) || (soc_ctrl == NULL))
  350. {
  351. pr_err("[%s]:dev is null\n", __func__);
  352. return -1;
  353. }
  354. if (dev->soc_func.csi_func.set_clk == NULL)
  355. {
  356. pr_err("[%s] function is null\n", __func__);
  357. return -1;
  358. }
  359. ret = dev->soc_func.csi_func.set_clk(dev, soc_ctrl->device_idx, soc_ctrl->control_value);
  360. return ret;
  361. }
  362. int vivsoc_hub_csi_g_clock_ctrl(struct vvcam_soc_dev *dev, struct soc_control_context * soc_ctrl)
  363. {
  364. int ret = 0;
  365. if ((dev==NULL) || (soc_ctrl == NULL))
  366. {
  367. pr_err("[%s]:dev is null\n", __func__);
  368. return -1;
  369. }
  370. if (dev->soc_func.csi_func.get_clk == NULL)
  371. {
  372. pr_err("[%s] function is null\n", __func__);
  373. return -1;
  374. }
  375. ret = dev->soc_func.csi_func.get_clk(dev, soc_ctrl->device_idx, &soc_ctrl->control_value);
  376. return ret;
  377. }
  378. int vivsoc_hub_sensor_reset(struct vvcam_soc_dev *dev, struct soc_control_context * soc_ctrl)
  379. {
  380. int ret = 0;
  381. if ((dev==NULL) || (soc_ctrl == NULL))
  382. {
  383. pr_err("[%s]:dev is null\n", __func__);
  384. return -1;
  385. }
  386. if (dev->soc_func.sensor_func.set_reset == NULL)
  387. {
  388. pr_err("[%s] function is null\n", __func__);
  389. return -1;
  390. }
  391. ret = dev->soc_func.sensor_func.set_reset(dev, soc_ctrl->device_idx, soc_ctrl->control_value);
  392. return ret;
  393. }
  394. int vivsoc_hub_sensor_s_power_ctrl(struct vvcam_soc_dev *dev, struct soc_control_context * soc_ctrl)
  395. {
  396. int ret = 0;
  397. if ((dev==NULL) || (soc_ctrl == NULL))
  398. {
  399. pr_err("[%s]:dev is null\n", __func__);
  400. return -1;
  401. }
  402. if (dev->soc_func.sensor_func.set_power == NULL)
  403. {
  404. pr_err("[%s] function is null\n", __func__);
  405. return -1;
  406. }
  407. ret = dev->soc_func.sensor_func.set_power(dev, soc_ctrl->device_idx, soc_ctrl->control_value);
  408. return ret;
  409. }
  410. int vivsoc_hub_sensor_g_power_ctrl(struct vvcam_soc_dev *dev, struct soc_control_context * soc_ctrl)
  411. {
  412. int ret = 0;
  413. if ((dev==NULL) || (soc_ctrl == NULL))
  414. {
  415. pr_err("[%s]:dev is null\n", __func__);
  416. return -1;
  417. }
  418. if (dev->soc_func.sensor_func.get_power == NULL)
  419. {
  420. pr_err("[%s] function is null\n", __func__);
  421. return -1;
  422. }
  423. ret = dev->soc_func.sensor_func.get_power(dev, soc_ctrl->device_idx, &soc_ctrl->control_value);
  424. return ret;
  425. }
  426. int vivsoc_hub_sensor_s_clock_ctrl(struct vvcam_soc_dev *dev, struct soc_control_context * soc_ctrl)
  427. {
  428. int ret = 0;
  429. if ((dev==NULL) || (soc_ctrl == NULL))
  430. {
  431. pr_err("[%s]:dev is null\n", __func__);
  432. return -1;
  433. }
  434. if (dev->soc_func.sensor_func.set_clk == NULL)
  435. {
  436. pr_err("[%s] function is null\n", __func__);
  437. return -1;
  438. }
  439. ret = dev->soc_func.sensor_func.set_clk(dev, soc_ctrl->device_idx, soc_ctrl->control_value);
  440. return ret;
  441. }
  442. int vivsoc_hub_sensor_g_clock_ctrl(struct vvcam_soc_dev *dev, struct soc_control_context * soc_ctrl)
  443. {
  444. int ret = 0;
  445. if ((dev==NULL) || (soc_ctrl == NULL))
  446. {
  447. pr_err("[%s]:dev is null\n", __func__);
  448. return -1;
  449. }
  450. if (dev->soc_func.sensor_func.get_clk == NULL)
  451. {
  452. pr_err("[%s] function is null\n", __func__);
  453. return -1;
  454. }
  455. ret = dev->soc_func.sensor_func.get_clk(dev, soc_ctrl->device_idx, &soc_ctrl->control_value);
  456. return ret;
  457. }
  458. unsigned int vivsoc_register_hardware(struct vvcam_soc_dev *dev, struct vvcam_soc_function_s *func)
  459. {
  460. if (func == NULL)
  461. {
  462. return -1;
  463. }
  464. memcpy(&dev->soc_func,func,sizeof(struct vvcam_soc_function_s));
  465. dev->soc_access.write = gen6_write_reg;
  466. dev->soc_access.read = gen6_read_reg;
  467. return 0;
  468. }