cam_cdm_intf.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  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_dump_debug_registers(uint32_t handle)
  448. {
  449. uint32_t hw_index;
  450. int rc = -EINVAL;
  451. struct cam_hw_intf *hw;
  452. if (get_cdm_mgr_refcount()) {
  453. CAM_ERR(CAM_CDM, "CDM intf mgr get refcount failed");
  454. rc = -EPERM;
  455. return rc;
  456. }
  457. hw_index = CAM_CDM_GET_HW_IDX(handle);
  458. if (hw_index < CAM_CDM_INTF_MGR_MAX_SUPPORTED_CDM) {
  459. hw = cdm_mgr.nodes[hw_index].device;
  460. if (hw && hw->hw_ops.process_cmd)
  461. rc = hw->hw_ops.process_cmd(hw->hw_priv,
  462. CAM_CDM_HW_INTF_DUMP_DBG_REGS,
  463. &handle,
  464. sizeof(handle));
  465. }
  466. put_cdm_mgr_refcount();
  467. return rc;
  468. }
  469. int cam_cdm_intf_register_hw_cdm(struct cam_hw_intf *hw,
  470. struct cam_cdm_private_dt_data *data, enum cam_cdm_type type,
  471. uint32_t *index)
  472. {
  473. int rc = -EINVAL;
  474. if ((!hw) || (!data) || (!index))
  475. return rc;
  476. if (get_cdm_mgr_refcount()) {
  477. CAM_ERR(CAM_CDM, "CDM intf mgr get refcount failed");
  478. return rc;
  479. }
  480. mutex_lock(&cam_cdm_mgr_lock);
  481. if ((type == CAM_VIRTUAL_CDM) &&
  482. (!cdm_mgr.nodes[CAM_SW_CDM_INDEX].device)) {
  483. mutex_lock(&cdm_mgr.nodes[CAM_SW_CDM_INDEX].lock);
  484. cdm_mgr.nodes[CAM_SW_CDM_INDEX].device = hw;
  485. cdm_mgr.nodes[CAM_SW_CDM_INDEX].data = data;
  486. *index = cdm_mgr.cdm_count;
  487. mutex_unlock(&cdm_mgr.nodes[CAM_SW_CDM_INDEX].lock);
  488. cdm_mgr.cdm_count++;
  489. rc = 0;
  490. } else if ((type == CAM_HW_CDM) && (cdm_mgr.cdm_count > 0)) {
  491. mutex_lock(&cdm_mgr.nodes[cdm_mgr.cdm_count].lock);
  492. cdm_mgr.nodes[cdm_mgr.cdm_count].device = hw;
  493. cdm_mgr.nodes[cdm_mgr.cdm_count].data = data;
  494. *index = cdm_mgr.cdm_count;
  495. mutex_unlock(&cdm_mgr.nodes[cdm_mgr.cdm_count].lock);
  496. cdm_mgr.cdm_count++;
  497. rc = 0;
  498. } else {
  499. CAM_ERR(CAM_CDM, "CDM registration failed type=%d count=%d",
  500. type, cdm_mgr.cdm_count);
  501. }
  502. mutex_unlock(&cam_cdm_mgr_lock);
  503. put_cdm_mgr_refcount();
  504. return rc;
  505. }
  506. int cam_cdm_intf_deregister_hw_cdm(struct cam_hw_intf *hw,
  507. struct cam_cdm_private_dt_data *data, enum cam_cdm_type type,
  508. uint32_t index)
  509. {
  510. int rc = -EINVAL;
  511. if ((!hw) || (!data))
  512. return rc;
  513. if (get_cdm_mgr_refcount()) {
  514. CAM_ERR(CAM_CDM, "CDM intf mgr get refcount failed");
  515. rc = -EPERM;
  516. return rc;
  517. }
  518. mutex_lock(&cam_cdm_mgr_lock);
  519. if ((type == CAM_VIRTUAL_CDM) &&
  520. (hw == cdm_mgr.nodes[CAM_SW_CDM_INDEX].device) &&
  521. (index == CAM_SW_CDM_INDEX)) {
  522. mutex_lock(&cdm_mgr.nodes[cdm_mgr.cdm_count].lock);
  523. cdm_mgr.nodes[CAM_SW_CDM_INDEX].device = NULL;
  524. cdm_mgr.nodes[CAM_SW_CDM_INDEX].data = NULL;
  525. mutex_unlock(&cdm_mgr.nodes[cdm_mgr.cdm_count].lock);
  526. rc = 0;
  527. } else if ((type == CAM_HW_CDM) &&
  528. (hw == cdm_mgr.nodes[index].device)) {
  529. mutex_lock(&cdm_mgr.nodes[index].lock);
  530. cdm_mgr.nodes[index].device = NULL;
  531. cdm_mgr.nodes[index].data = NULL;
  532. mutex_unlock(&cdm_mgr.nodes[index].lock);
  533. cdm_mgr.cdm_count--;
  534. rc = 0;
  535. } else {
  536. CAM_ERR(CAM_CDM, "CDM Deregistration failed type=%d index=%d",
  537. type, index);
  538. }
  539. mutex_unlock(&cam_cdm_mgr_lock);
  540. put_cdm_mgr_refcount();
  541. return rc;
  542. }
  543. static int cam_cdm_intf_component_bind(struct device *dev,
  544. struct device *master_dev, void *data)
  545. {
  546. int i, rc;
  547. struct platform_device *pdev = to_platform_device(dev);
  548. rc = cam_cdm_intf_mgr_soc_get_dt_properties(pdev, &cdm_mgr);
  549. if (rc) {
  550. CAM_ERR(CAM_CDM, "Failed to get dt properties");
  551. return rc;
  552. }
  553. mutex_lock(&cam_cdm_mgr_lock);
  554. for (i = 0 ; i < CAM_CDM_INTF_MGR_MAX_SUPPORTED_CDM; i++) {
  555. mutex_init(&cdm_mgr.nodes[i].lock);
  556. cdm_mgr.nodes[i].device = NULL;
  557. cdm_mgr.nodes[i].data = NULL;
  558. cdm_mgr.nodes[i].refcount = 0;
  559. }
  560. cdm_mgr.probe_done = true;
  561. cdm_mgr.refcount = 0;
  562. mutex_unlock(&cam_cdm_mgr_lock);
  563. rc = cam_virtual_cdm_probe(pdev);
  564. if (rc) {
  565. mutex_lock(&cam_cdm_mgr_lock);
  566. cdm_mgr.probe_done = false;
  567. for (i = 0 ; i < CAM_CDM_INTF_MGR_MAX_SUPPORTED_CDM; i++) {
  568. if (cdm_mgr.nodes[i].device || cdm_mgr.nodes[i].data ||
  569. (cdm_mgr.nodes[i].refcount != 0))
  570. CAM_ERR(CAM_CDM,
  571. "Valid node present in index=%d", i);
  572. mutex_destroy(&cdm_mgr.nodes[i].lock);
  573. cdm_mgr.nodes[i].device = NULL;
  574. cdm_mgr.nodes[i].data = NULL;
  575. cdm_mgr.nodes[i].refcount = 0;
  576. }
  577. mutex_unlock(&cam_cdm_mgr_lock);
  578. }
  579. CAM_DBG(CAM_CDM, "CDM Intf component bound successfully");
  580. return rc;
  581. }
  582. static void cam_cdm_intf_component_unbind(struct device *dev,
  583. struct device *master_dev, void *data)
  584. {
  585. int i;
  586. struct platform_device *pdev = to_platform_device(dev);
  587. if (get_cdm_mgr_refcount()) {
  588. CAM_ERR(CAM_CDM, "CDM intf mgr get refcount failed");
  589. return;
  590. }
  591. if (cam_virtual_cdm_remove(pdev)) {
  592. CAM_ERR(CAM_CDM, "Virtual CDM remove failed");
  593. return;
  594. }
  595. put_cdm_mgr_refcount();
  596. mutex_lock(&cam_cdm_mgr_lock);
  597. if (cdm_mgr.refcount != 0) {
  598. CAM_ERR(CAM_CDM, "cdm manger refcount not zero %d",
  599. cdm_mgr.refcount);
  600. goto end;
  601. }
  602. for (i = 0 ; i < CAM_CDM_INTF_MGR_MAX_SUPPORTED_CDM; i++) {
  603. if (cdm_mgr.nodes[i].device || cdm_mgr.nodes[i].data ||
  604. (cdm_mgr.nodes[i].refcount != 0)) {
  605. CAM_ERR(CAM_CDM, "Valid node present in index=%d", i);
  606. goto end;
  607. }
  608. mutex_destroy(&cdm_mgr.nodes[i].lock);
  609. cdm_mgr.nodes[i].device = NULL;
  610. cdm_mgr.nodes[i].data = NULL;
  611. cdm_mgr.nodes[i].refcount = 0;
  612. }
  613. cdm_mgr.probe_done = false;
  614. end:
  615. mutex_unlock(&cam_cdm_mgr_lock);
  616. }
  617. const static struct component_ops cam_cdm_intf_component_ops = {
  618. .bind = cam_cdm_intf_component_bind,
  619. .unbind = cam_cdm_intf_component_unbind,
  620. };
  621. static int cam_cdm_intf_probe(struct platform_device *pdev)
  622. {
  623. int rc = 0;
  624. CAM_DBG(CAM_CDM, "Adding CDM INTF component");
  625. rc = component_add(&pdev->dev, &cam_cdm_intf_component_ops);
  626. if (rc)
  627. CAM_ERR(CAM_CDM, "failed to add component rc: %d", rc);
  628. return rc;
  629. }
  630. static int cam_cdm_intf_remove(struct platform_device *pdev)
  631. {
  632. component_del(&pdev->dev, &cam_cdm_intf_component_ops);
  633. return 0;
  634. }
  635. struct platform_driver cam_cdm_intf_driver = {
  636. .probe = cam_cdm_intf_probe,
  637. .remove = cam_cdm_intf_remove,
  638. .driver = {
  639. .name = "msm_cam_cdm_intf",
  640. .owner = THIS_MODULE,
  641. .of_match_table = msm_cam_cdm_intf_dt_match,
  642. .suppress_bind_attrs = true,
  643. },
  644. };
  645. int cam_cdm_intf_init_module(void)
  646. {
  647. return platform_driver_register(&cam_cdm_intf_driver);
  648. }
  649. void cam_cdm_intf_exit_module(void)
  650. {
  651. platform_driver_unregister(&cam_cdm_intf_driver);
  652. }
  653. MODULE_DESCRIPTION("MSM Camera CDM Intf driver");
  654. MODULE_LICENSE("GPL v2");