cam_cdm_intf.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/delay.h>
  6. #include <linux/io.h>
  7. #include <linux/of.h>
  8. #include <linux/module.h>
  9. #include <linux/timer.h>
  10. #include <linux/kernel.h>
  11. #include "cam_cdm_intf_api.h"
  12. #include "cam_cdm.h"
  13. #include "cam_cdm_virtual.h"
  14. #include "cam_soc_util.h"
  15. #include "cam_cdm_soc.h"
  16. #include "cam_cdm_core_common.h"
  17. #include "camera_main.h"
  18. static struct cam_cdm_intf_mgr cdm_mgr;
  19. static DEFINE_MUTEX(cam_cdm_mgr_lock);
  20. static const struct of_device_id msm_cam_cdm_intf_dt_match[] = {
  21. { .compatible = "qcom,cam-cdm-intf", },
  22. {}
  23. };
  24. static int get_cdm_mgr_refcount(void)
  25. {
  26. int rc = 0;
  27. mutex_lock(&cam_cdm_mgr_lock);
  28. if (cdm_mgr.probe_done == false) {
  29. CAM_ERR(CAM_CDM, "CDM intf mgr not probed yet");
  30. rc = -EPERM;
  31. } else {
  32. CAM_DBG(CAM_CDM, "CDM intf mgr get refcount=%d",
  33. cdm_mgr.refcount);
  34. cdm_mgr.refcount++;
  35. }
  36. mutex_unlock(&cam_cdm_mgr_lock);
  37. return rc;
  38. }
  39. static void put_cdm_mgr_refcount(void)
  40. {
  41. mutex_lock(&cam_cdm_mgr_lock);
  42. if (cdm_mgr.probe_done == false) {
  43. CAM_ERR(CAM_CDM, "CDM intf mgr not probed yet");
  44. } else {
  45. CAM_DBG(CAM_CDM, "CDM intf mgr put refcount=%d",
  46. cdm_mgr.refcount);
  47. if (cdm_mgr.refcount > 0) {
  48. cdm_mgr.refcount--;
  49. } else {
  50. CAM_ERR(CAM_CDM, "Refcount put when zero");
  51. WARN_ON(1);
  52. }
  53. }
  54. mutex_unlock(&cam_cdm_mgr_lock);
  55. }
  56. static int get_cdm_iommu_handle(struct cam_iommu_handle *cdm_handles,
  57. uint32_t hw_idx)
  58. {
  59. int rc = -EPERM;
  60. struct cam_hw_intf *hw = cdm_mgr.nodes[hw_idx].device;
  61. if (hw->hw_ops.get_hw_caps) {
  62. rc = hw->hw_ops.get_hw_caps(hw->hw_priv, cdm_handles,
  63. sizeof(struct cam_iommu_handle));
  64. }
  65. return rc;
  66. }
  67. static int get_cdm_index_by_id(char *identifier,
  68. uint32_t cell_index, uint32_t *hw_index)
  69. {
  70. int rc = -EPERM, i, j;
  71. char client_name[128], name_index[160];
  72. snprintf(client_name, sizeof(client_name), "%s", identifier);
  73. snprintf(name_index, sizeof(name_index), "%s%d",
  74. identifier, cell_index);
  75. CAM_DBG(CAM_CDM,
  76. "Looking for HW id of =%s or %s and index=%d cdm_count %d",
  77. identifier, name_index, cell_index, cdm_mgr.cdm_count);
  78. mutex_lock(&cam_cdm_mgr_lock);
  79. for (i = 0; i < cdm_mgr.cdm_count; i++) {
  80. mutex_lock(&cdm_mgr.nodes[i].lock);
  81. CAM_DBG(CAM_CDM, "dt_num_supported_clients=%d",
  82. cdm_mgr.nodes[i].data->dt_num_supported_clients);
  83. for (j = 0; j <
  84. cdm_mgr.nodes[i].data->dt_num_supported_clients; j++) {
  85. CAM_DBG(CAM_CDM, "client name:%s dev Index: %d",
  86. cdm_mgr.nodes[i].data->dt_cdm_client_name[j],
  87. i);
  88. if (!strcmp(
  89. cdm_mgr.nodes[i].data->dt_cdm_client_name[j],
  90. client_name) || !strcmp(
  91. cdm_mgr.nodes[i].data->dt_cdm_client_name[j],
  92. name_index)) {
  93. rc = 0;
  94. *hw_index = i;
  95. break;
  96. }
  97. }
  98. mutex_unlock(&cdm_mgr.nodes[i].lock);
  99. if (rc == 0)
  100. break;
  101. }
  102. mutex_unlock(&cam_cdm_mgr_lock);
  103. return rc;
  104. }
  105. int cam_cdm_get_iommu_handle(char *identifier,
  106. struct cam_iommu_handle *cdm_handles)
  107. {
  108. int i, j, rc = -EPERM;
  109. if ((!identifier) || (!cdm_handles))
  110. return -EINVAL;
  111. if (get_cdm_mgr_refcount()) {
  112. CAM_ERR(CAM_CDM, "CDM intf mgr get refcount failed");
  113. return rc;
  114. }
  115. CAM_DBG(CAM_CDM, "Looking for Iommu handle of %s", identifier);
  116. for (i = 0; i < cdm_mgr.cdm_count; i++) {
  117. mutex_lock(&cdm_mgr.nodes[i].lock);
  118. if (!cdm_mgr.nodes[i].data) {
  119. mutex_unlock(&cdm_mgr.nodes[i].lock);
  120. continue;
  121. }
  122. CAM_DBG(CAM_CDM, "dt_num_supported_clients=%d",
  123. cdm_mgr.nodes[i].data->dt_num_supported_clients);
  124. for (j = 0; j <
  125. cdm_mgr.nodes[i].data->dt_num_supported_clients;
  126. j++) {
  127. CAM_DBG(CAM_CDM, "client name:%s dev Index: %d",
  128. cdm_mgr.nodes[i].data->dt_cdm_client_name[j],
  129. i);
  130. if (!strcmp(
  131. cdm_mgr.nodes[i].data->dt_cdm_client_name[j],
  132. identifier)) {
  133. rc = get_cdm_iommu_handle(cdm_handles, i);
  134. break;
  135. }
  136. }
  137. mutex_unlock(&cdm_mgr.nodes[i].lock);
  138. if (rc == 0)
  139. break;
  140. }
  141. put_cdm_mgr_refcount();
  142. return rc;
  143. }
  144. EXPORT_SYMBOL(cam_cdm_get_iommu_handle);
  145. int cam_cdm_acquire(struct cam_cdm_acquire_data *data)
  146. {
  147. int rc = -EPERM;
  148. struct cam_hw_intf *hw;
  149. struct cam_hw_info *cdm_hw;
  150. struct cam_cdm *core = NULL;
  151. uint32_t hw_index = 0;
  152. if ((!data) || (!data->base_array_cnt))
  153. return -EINVAL;
  154. if (get_cdm_mgr_refcount()) {
  155. CAM_ERR(CAM_CDM, "CDM intf mgr get refcount failed");
  156. return rc;
  157. }
  158. if (data->id > CAM_CDM_HW_ANY) {
  159. CAM_ERR(CAM_CDM,
  160. "only CAM_CDM_VIRTUAL/CAM_CDM_HW_ANY is supported");
  161. rc = -EPERM;
  162. goto end;
  163. }
  164. rc = get_cdm_index_by_id(data->identifier, data->cell_index,
  165. &hw_index);
  166. if ((rc < 0) && (hw_index < CAM_CDM_INTF_MGR_MAX_SUPPORTED_CDM)) {
  167. CAM_ERR(CAM_CDM, "Failed to identify associated hw id");
  168. goto end;
  169. } else {
  170. hw = cdm_mgr.nodes[hw_index].device;
  171. if (hw && hw->hw_ops.process_cmd) {
  172. cdm_hw = hw->hw_priv;
  173. core = (struct cam_cdm *)cdm_hw->core_info;
  174. data->id = core->id;
  175. CAM_DBG(CAM_CDM,
  176. "Device = %s, hw_index = %d, CDM id = %d",
  177. data->identifier, hw_index, data->id);
  178. rc = hw->hw_ops.process_cmd(hw->hw_priv,
  179. CAM_CDM_HW_INTF_CMD_ACQUIRE, data,
  180. sizeof(struct cam_cdm_acquire_data));
  181. if (rc < 0) {
  182. CAM_ERR(CAM_CDM, "CDM hw acquire failed");
  183. goto end;
  184. }
  185. } else {
  186. CAM_ERR(CAM_CDM, "idx %d doesn't have acquire ops",
  187. hw_index);
  188. rc = -EPERM;
  189. }
  190. }
  191. end:
  192. if (rc < 0) {
  193. CAM_ERR(CAM_CDM, "CDM acquire failed for id=%d name=%s, idx=%d",
  194. data->id, data->identifier, data->cell_index);
  195. put_cdm_mgr_refcount();
  196. }
  197. return rc;
  198. }
  199. EXPORT_SYMBOL(cam_cdm_acquire);
  200. struct cam_cdm_utils_ops *cam_cdm_publish_ops(void)
  201. {
  202. struct cam_hw_version cdm_version;
  203. cdm_version.major = 1;
  204. cdm_version.minor = 0;
  205. cdm_version.incr = 0;
  206. cdm_version.reserved = 0;
  207. return cam_cdm_get_ops(0, &cdm_version, true);
  208. }
  209. EXPORT_SYMBOL(cam_cdm_publish_ops);
  210. int cam_cdm_release(uint32_t handle)
  211. {
  212. uint32_t hw_index;
  213. int rc = -EPERM;
  214. struct cam_hw_intf *hw;
  215. if (get_cdm_mgr_refcount()) {
  216. CAM_ERR(CAM_CDM, "CDM intf mgr get refcount failed");
  217. return rc;
  218. }
  219. hw_index = CAM_CDM_GET_HW_IDX(handle);
  220. if (hw_index < CAM_CDM_INTF_MGR_MAX_SUPPORTED_CDM) {
  221. hw = cdm_mgr.nodes[hw_index].device;
  222. if (hw && hw->hw_ops.process_cmd) {
  223. rc = hw->hw_ops.process_cmd(hw->hw_priv,
  224. CAM_CDM_HW_INTF_CMD_RELEASE, &handle,
  225. sizeof(handle));
  226. if (rc < 0)
  227. CAM_ERR(CAM_CDM,
  228. "hw release failed for handle=%x",
  229. handle);
  230. } else
  231. CAM_ERR(CAM_CDM, "hw idx %d doesn't have release ops",
  232. hw_index);
  233. }
  234. put_cdm_mgr_refcount();
  235. if (rc == 0)
  236. put_cdm_mgr_refcount();
  237. return rc;
  238. }
  239. EXPORT_SYMBOL(cam_cdm_release);
  240. int cam_cdm_submit_bls(uint32_t handle, struct cam_cdm_bl_request *data)
  241. {
  242. uint32_t hw_index;
  243. int rc = -EINVAL;
  244. struct cam_hw_intf *hw;
  245. if (!data)
  246. return rc;
  247. if (get_cdm_mgr_refcount()) {
  248. CAM_ERR(CAM_CDM, "CDM intf mgr get refcount failed");
  249. rc = -EPERM;
  250. return rc;
  251. }
  252. hw_index = CAM_CDM_GET_HW_IDX(handle);
  253. if (hw_index < CAM_CDM_INTF_MGR_MAX_SUPPORTED_CDM) {
  254. struct cam_cdm_hw_intf_cmd_submit_bl req;
  255. hw = cdm_mgr.nodes[hw_index].device;
  256. if (hw && hw->hw_ops.process_cmd) {
  257. req.data = data;
  258. req.handle = handle;
  259. rc = hw->hw_ops.process_cmd(hw->hw_priv,
  260. CAM_CDM_HW_INTF_CMD_SUBMIT_BL, &req,
  261. sizeof(struct cam_cdm_hw_intf_cmd_submit_bl));
  262. if (rc < 0)
  263. CAM_ERR(CAM_CDM,
  264. "hw submit bl failed for handle=%x",
  265. handle);
  266. } else {
  267. CAM_ERR(CAM_CDM, "hw idx %d doesn't have submit ops",
  268. hw_index);
  269. }
  270. }
  271. put_cdm_mgr_refcount();
  272. return rc;
  273. }
  274. EXPORT_SYMBOL(cam_cdm_submit_bls);
  275. int cam_cdm_stream_on(uint32_t handle)
  276. {
  277. uint32_t hw_index;
  278. int rc = -EINVAL;
  279. struct cam_hw_intf *hw;
  280. if (get_cdm_mgr_refcount()) {
  281. CAM_ERR(CAM_CDM, "CDM intf mgr get refcount failed");
  282. rc = -EPERM;
  283. return rc;
  284. }
  285. hw_index = CAM_CDM_GET_HW_IDX(handle);
  286. if (hw_index < CAM_CDM_INTF_MGR_MAX_SUPPORTED_CDM) {
  287. hw = cdm_mgr.nodes[hw_index].device;
  288. if (hw && hw->hw_ops.start) {
  289. rc = hw->hw_ops.start(hw->hw_priv, &handle,
  290. sizeof(uint32_t));
  291. if (rc < 0)
  292. CAM_ERR(CAM_CDM,
  293. "hw start failed handle=%x",
  294. handle);
  295. } else {
  296. CAM_ERR(CAM_CDM,
  297. "hw idx %d doesn't have start ops",
  298. hw_index);
  299. }
  300. }
  301. put_cdm_mgr_refcount();
  302. return rc;
  303. }
  304. EXPORT_SYMBOL(cam_cdm_stream_on);
  305. int cam_cdm_stream_off(uint32_t handle)
  306. {
  307. uint32_t hw_index;
  308. int rc = -EINVAL;
  309. struct cam_hw_intf *hw;
  310. if (get_cdm_mgr_refcount()) {
  311. CAM_ERR(CAM_CDM, "CDM intf mgr get refcount failed");
  312. rc = -EPERM;
  313. return rc;
  314. }
  315. hw_index = CAM_CDM_GET_HW_IDX(handle);
  316. if (hw_index < CAM_CDM_INTF_MGR_MAX_SUPPORTED_CDM) {
  317. hw = cdm_mgr.nodes[hw_index].device;
  318. if (hw && hw->hw_ops.stop) {
  319. rc = hw->hw_ops.stop(hw->hw_priv, &handle,
  320. sizeof(uint32_t));
  321. if (rc < 0)
  322. CAM_ERR(CAM_CDM, "hw stop failed handle=%x",
  323. handle);
  324. } else {
  325. CAM_ERR(CAM_CDM, "hw idx %d doesn't have stop ops",
  326. hw_index);
  327. }
  328. }
  329. put_cdm_mgr_refcount();
  330. return rc;
  331. }
  332. EXPORT_SYMBOL(cam_cdm_stream_off);
  333. int cam_cdm_reset_hw(uint32_t handle)
  334. {
  335. uint32_t hw_index;
  336. int rc = -EINVAL;
  337. struct cam_hw_intf *hw;
  338. if (get_cdm_mgr_refcount()) {
  339. CAM_ERR(CAM_CDM, "CDM intf mgr get refcount failed");
  340. rc = -EPERM;
  341. return rc;
  342. }
  343. hw_index = CAM_CDM_GET_HW_IDX(handle);
  344. if (hw_index < CAM_CDM_INTF_MGR_MAX_SUPPORTED_CDM) {
  345. hw = cdm_mgr.nodes[hw_index].device;
  346. if (hw && hw->hw_ops.process_cmd) {
  347. rc = hw->hw_ops.process_cmd(hw->hw_priv,
  348. CAM_CDM_HW_INTF_CMD_RESET_HW, &handle,
  349. sizeof(handle));
  350. if (rc < 0)
  351. CAM_ERR(CAM_CDM,
  352. "CDM hw release failed for handle=%x",
  353. handle);
  354. } else {
  355. CAM_ERR(CAM_CDM, "hw idx %d doesn't have release ops",
  356. hw_index);
  357. }
  358. }
  359. put_cdm_mgr_refcount();
  360. return rc;
  361. }
  362. EXPORT_SYMBOL(cam_cdm_reset_hw);
  363. int cam_cdm_flush_hw(uint32_t handle)
  364. {
  365. uint32_t hw_index;
  366. int rc = -EINVAL;
  367. struct cam_hw_intf *hw;
  368. if (get_cdm_mgr_refcount()) {
  369. CAM_ERR(CAM_CDM, "CDM intf mgr get refcount failed");
  370. rc = -EPERM;
  371. return rc;
  372. }
  373. hw_index = CAM_CDM_GET_HW_IDX(handle);
  374. if (hw_index < CAM_CDM_INTF_MGR_MAX_SUPPORTED_CDM) {
  375. hw = cdm_mgr.nodes[hw_index].device;
  376. if (hw && hw->hw_ops.process_cmd) {
  377. rc = hw->hw_ops.process_cmd(hw->hw_priv,
  378. CAM_CDM_HW_INTF_CMD_FLUSH_HW, &handle,
  379. sizeof(handle));
  380. if (rc < 0)
  381. CAM_ERR(CAM_CDM,
  382. "CDM hw release failed for handle=%x",
  383. handle);
  384. } else {
  385. CAM_ERR(CAM_CDM, "hw idx %d doesn't have release ops",
  386. hw_index);
  387. }
  388. }
  389. put_cdm_mgr_refcount();
  390. return rc;
  391. }
  392. EXPORT_SYMBOL(cam_cdm_flush_hw);
  393. int cam_cdm_handle_error(uint32_t handle)
  394. {
  395. uint32_t hw_index;
  396. int rc = -EINVAL;
  397. struct cam_hw_intf *hw;
  398. if (get_cdm_mgr_refcount()) {
  399. CAM_ERR(CAM_CDM, "CDM intf mgr get refcount failed");
  400. rc = -EPERM;
  401. return rc;
  402. }
  403. hw_index = CAM_CDM_GET_HW_IDX(handle);
  404. if (hw_index < CAM_CDM_INTF_MGR_MAX_SUPPORTED_CDM) {
  405. hw = cdm_mgr.nodes[hw_index].device;
  406. if (hw && hw->hw_ops.process_cmd) {
  407. rc = hw->hw_ops.process_cmd(hw->hw_priv,
  408. CAM_CDM_HW_INTF_CMD_HANDLE_ERROR,
  409. &handle,
  410. sizeof(handle));
  411. if (rc < 0)
  412. CAM_ERR(CAM_CDM,
  413. "CDM hw release failed for handle=%x",
  414. handle);
  415. } else {
  416. CAM_ERR(CAM_CDM, "hw idx %d doesn't have release ops",
  417. hw_index);
  418. }
  419. }
  420. put_cdm_mgr_refcount();
  421. return rc;
  422. }
  423. EXPORT_SYMBOL(cam_cdm_handle_error);
  424. int cam_cdm_detect_hang_error(uint32_t handle)
  425. {
  426. uint32_t hw_index;
  427. int rc = -EINVAL;
  428. struct cam_hw_intf *hw;
  429. if (get_cdm_mgr_refcount()) {
  430. CAM_ERR(CAM_CDM, "CDM intf mgr get refcount failed");
  431. rc = -EPERM;
  432. return rc;
  433. }
  434. hw_index = CAM_CDM_GET_HW_IDX(handle);
  435. if (hw_index < CAM_CDM_INTF_MGR_MAX_SUPPORTED_CDM) {
  436. hw = cdm_mgr.nodes[hw_index].device;
  437. if (hw && hw->hw_ops.process_cmd)
  438. rc = hw->hw_ops.process_cmd(hw->hw_priv,
  439. CAM_CDM_HW_INTF_CMD_HANG_DETECT,
  440. &handle,
  441. sizeof(handle));
  442. }
  443. put_cdm_mgr_refcount();
  444. return rc;
  445. }
  446. EXPORT_SYMBOL(cam_cdm_detect_hang_error);
  447. int cam_cdm_intf_register_hw_cdm(struct cam_hw_intf *hw,
  448. struct cam_cdm_private_dt_data *data, enum cam_cdm_type type,
  449. uint32_t *index)
  450. {
  451. int rc = -EINVAL;
  452. if ((!hw) || (!data) || (!index))
  453. return rc;
  454. if (get_cdm_mgr_refcount()) {
  455. CAM_ERR(CAM_CDM, "CDM intf mgr get refcount failed");
  456. return rc;
  457. }
  458. mutex_lock(&cam_cdm_mgr_lock);
  459. if ((type == CAM_VIRTUAL_CDM) &&
  460. (!cdm_mgr.nodes[CAM_SW_CDM_INDEX].device)) {
  461. mutex_lock(&cdm_mgr.nodes[CAM_SW_CDM_INDEX].lock);
  462. cdm_mgr.nodes[CAM_SW_CDM_INDEX].device = hw;
  463. cdm_mgr.nodes[CAM_SW_CDM_INDEX].data = data;
  464. *index = cdm_mgr.cdm_count;
  465. mutex_unlock(&cdm_mgr.nodes[CAM_SW_CDM_INDEX].lock);
  466. cdm_mgr.cdm_count++;
  467. rc = 0;
  468. } else if ((type == CAM_HW_CDM) && (cdm_mgr.cdm_count > 0)) {
  469. mutex_lock(&cdm_mgr.nodes[cdm_mgr.cdm_count].lock);
  470. cdm_mgr.nodes[cdm_mgr.cdm_count].device = hw;
  471. cdm_mgr.nodes[cdm_mgr.cdm_count].data = data;
  472. *index = cdm_mgr.cdm_count;
  473. mutex_unlock(&cdm_mgr.nodes[cdm_mgr.cdm_count].lock);
  474. cdm_mgr.cdm_count++;
  475. rc = 0;
  476. } else {
  477. CAM_ERR(CAM_CDM, "CDM registration failed type=%d count=%d",
  478. type, cdm_mgr.cdm_count);
  479. }
  480. mutex_unlock(&cam_cdm_mgr_lock);
  481. put_cdm_mgr_refcount();
  482. return rc;
  483. }
  484. int cam_cdm_intf_deregister_hw_cdm(struct cam_hw_intf *hw,
  485. struct cam_cdm_private_dt_data *data, enum cam_cdm_type type,
  486. uint32_t index)
  487. {
  488. int rc = -EINVAL;
  489. if ((!hw) || (!data))
  490. return rc;
  491. if (get_cdm_mgr_refcount()) {
  492. CAM_ERR(CAM_CDM, "CDM intf mgr get refcount failed");
  493. rc = -EPERM;
  494. return rc;
  495. }
  496. mutex_lock(&cam_cdm_mgr_lock);
  497. if ((type == CAM_VIRTUAL_CDM) &&
  498. (hw == cdm_mgr.nodes[CAM_SW_CDM_INDEX].device) &&
  499. (index == CAM_SW_CDM_INDEX)) {
  500. mutex_lock(&cdm_mgr.nodes[cdm_mgr.cdm_count].lock);
  501. cdm_mgr.nodes[CAM_SW_CDM_INDEX].device = NULL;
  502. cdm_mgr.nodes[CAM_SW_CDM_INDEX].data = NULL;
  503. mutex_unlock(&cdm_mgr.nodes[cdm_mgr.cdm_count].lock);
  504. rc = 0;
  505. } else if ((type == CAM_HW_CDM) &&
  506. (hw == cdm_mgr.nodes[index].device)) {
  507. mutex_lock(&cdm_mgr.nodes[index].lock);
  508. cdm_mgr.nodes[index].device = NULL;
  509. cdm_mgr.nodes[index].data = NULL;
  510. mutex_unlock(&cdm_mgr.nodes[index].lock);
  511. cdm_mgr.cdm_count--;
  512. rc = 0;
  513. } else {
  514. CAM_ERR(CAM_CDM, "CDM Deregistration failed type=%d index=%d",
  515. type, index);
  516. }
  517. mutex_unlock(&cam_cdm_mgr_lock);
  518. put_cdm_mgr_refcount();
  519. return rc;
  520. }
  521. static int cam_cdm_intf_component_bind(struct device *dev,
  522. struct device *master_dev, void *data)
  523. {
  524. int i, rc;
  525. struct platform_device *pdev = to_platform_device(dev);
  526. rc = cam_cdm_intf_mgr_soc_get_dt_properties(pdev, &cdm_mgr);
  527. if (rc) {
  528. CAM_ERR(CAM_CDM, "Failed to get dt properties");
  529. return rc;
  530. }
  531. mutex_lock(&cam_cdm_mgr_lock);
  532. for (i = 0 ; i < CAM_CDM_INTF_MGR_MAX_SUPPORTED_CDM; i++) {
  533. mutex_init(&cdm_mgr.nodes[i].lock);
  534. cdm_mgr.nodes[i].device = NULL;
  535. cdm_mgr.nodes[i].data = NULL;
  536. cdm_mgr.nodes[i].refcount = 0;
  537. }
  538. cdm_mgr.probe_done = true;
  539. cdm_mgr.refcount = 0;
  540. mutex_unlock(&cam_cdm_mgr_lock);
  541. rc = cam_virtual_cdm_probe(pdev);
  542. if (rc) {
  543. mutex_lock(&cam_cdm_mgr_lock);
  544. cdm_mgr.probe_done = false;
  545. for (i = 0 ; i < CAM_CDM_INTF_MGR_MAX_SUPPORTED_CDM; i++) {
  546. if (cdm_mgr.nodes[i].device || cdm_mgr.nodes[i].data ||
  547. (cdm_mgr.nodes[i].refcount != 0))
  548. CAM_ERR(CAM_CDM,
  549. "Valid node present in index=%d", i);
  550. mutex_destroy(&cdm_mgr.nodes[i].lock);
  551. cdm_mgr.nodes[i].device = NULL;
  552. cdm_mgr.nodes[i].data = NULL;
  553. cdm_mgr.nodes[i].refcount = 0;
  554. }
  555. mutex_unlock(&cam_cdm_mgr_lock);
  556. }
  557. CAM_DBG(CAM_CDM, "CDM Intf component bound successfully");
  558. return rc;
  559. }
  560. static void cam_cdm_intf_component_unbind(struct device *dev,
  561. struct device *master_dev, void *data)
  562. {
  563. int i;
  564. struct platform_device *pdev = to_platform_device(dev);
  565. if (get_cdm_mgr_refcount()) {
  566. CAM_ERR(CAM_CDM, "CDM intf mgr get refcount failed");
  567. return;
  568. }
  569. if (cam_virtual_cdm_remove(pdev)) {
  570. CAM_ERR(CAM_CDM, "Virtual CDM remove failed");
  571. return;
  572. }
  573. put_cdm_mgr_refcount();
  574. mutex_lock(&cam_cdm_mgr_lock);
  575. if (cdm_mgr.refcount != 0) {
  576. CAM_ERR(CAM_CDM, "cdm manger refcount not zero %d",
  577. cdm_mgr.refcount);
  578. goto end;
  579. }
  580. for (i = 0 ; i < CAM_CDM_INTF_MGR_MAX_SUPPORTED_CDM; i++) {
  581. if (cdm_mgr.nodes[i].device || cdm_mgr.nodes[i].data ||
  582. (cdm_mgr.nodes[i].refcount != 0)) {
  583. CAM_ERR(CAM_CDM, "Valid node present in index=%d", i);
  584. goto end;
  585. }
  586. mutex_destroy(&cdm_mgr.nodes[i].lock);
  587. cdm_mgr.nodes[i].device = NULL;
  588. cdm_mgr.nodes[i].data = NULL;
  589. cdm_mgr.nodes[i].refcount = 0;
  590. }
  591. cdm_mgr.probe_done = false;
  592. end:
  593. mutex_unlock(&cam_cdm_mgr_lock);
  594. }
  595. const static struct component_ops cam_cdm_intf_component_ops = {
  596. .bind = cam_cdm_intf_component_bind,
  597. .unbind = cam_cdm_intf_component_unbind,
  598. };
  599. static int cam_cdm_intf_probe(struct platform_device *pdev)
  600. {
  601. int rc = 0;
  602. CAM_DBG(CAM_CDM, "Adding CDM INTF component");
  603. rc = component_add(&pdev->dev, &cam_cdm_intf_component_ops);
  604. if (rc)
  605. CAM_ERR(CAM_CDM, "failed to add component rc: %d", rc);
  606. return rc;
  607. }
  608. static int cam_cdm_intf_remove(struct platform_device *pdev)
  609. {
  610. component_del(&pdev->dev, &cam_cdm_intf_component_ops);
  611. return 0;
  612. }
  613. struct platform_driver cam_cdm_intf_driver = {
  614. .probe = cam_cdm_intf_probe,
  615. .remove = cam_cdm_intf_remove,
  616. .driver = {
  617. .name = "msm_cam_cdm_intf",
  618. .owner = THIS_MODULE,
  619. .of_match_table = msm_cam_cdm_intf_dt_match,
  620. .suppress_bind_attrs = true,
  621. },
  622. };
  623. int cam_cdm_intf_init_module(void)
  624. {
  625. return platform_driver_register(&cam_cdm_intf_driver);
  626. }
  627. void cam_cdm_intf_exit_module(void)
  628. {
  629. platform_driver_unregister(&cam_cdm_intf_driver);
  630. }
  631. MODULE_DESCRIPTION("MSM Camera CDM Intf driver");
  632. MODULE_LICENSE("GPL v2");