cam_cdm_intf.c 16 KB

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