cam_sync.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/init.h>
  6. #include <linux/module.h>
  7. #include <linux/irqflags.h>
  8. #include <linux/module.h>
  9. #include <linux/platform_device.h>
  10. #include <linux/debugfs.h>
  11. #if IS_REACHABLE(CONFIG_MSM_GLOBAL_SYNX)
  12. #include <synx_api.h>
  13. #endif
  14. #include "cam_sync_util.h"
  15. #include "cam_debug_util.h"
  16. #include "cam_common_util.h"
  17. #include "camera_main.h"
  18. struct sync_device *sync_dev;
  19. /*
  20. * Flag to determine whether to enqueue cb of a
  21. * signaled fence onto the workq or invoke it
  22. * directly in the same context
  23. */
  24. static bool trigger_cb_without_switch;
  25. static void cam_sync_print_fence_table(void)
  26. {
  27. int idx;
  28. for (idx = 0; idx < CAM_SYNC_MAX_OBJS; idx++) {
  29. spin_lock_bh(&sync_dev->row_spinlocks[idx]);
  30. CAM_INFO(CAM_SYNC,
  31. "index[%u]: sync_id=%d, name=%s, type=%d, state=%d, ref_cnt=%d",
  32. idx,
  33. sync_dev->sync_table[idx].sync_id,
  34. sync_dev->sync_table[idx].name,
  35. sync_dev->sync_table[idx].type,
  36. sync_dev->sync_table[idx].state,
  37. atomic_read(&sync_dev->sync_table[idx].ref_cnt));
  38. spin_unlock_bh(&sync_dev->row_spinlocks[idx]);
  39. }
  40. }
  41. int cam_sync_create(int32_t *sync_obj, const char *name)
  42. {
  43. int rc;
  44. long idx;
  45. bool bit;
  46. do {
  47. idx = find_first_zero_bit(sync_dev->bitmap, CAM_SYNC_MAX_OBJS);
  48. if (idx >= CAM_SYNC_MAX_OBJS) {
  49. CAM_ERR(CAM_SYNC,
  50. "Error: Unable to create sync idx = %d reached max!",
  51. idx);
  52. cam_sync_print_fence_table();
  53. return -ENOMEM;
  54. }
  55. CAM_DBG(CAM_SYNC, "Index location available at idx: %ld", idx);
  56. bit = test_and_set_bit(idx, sync_dev->bitmap);
  57. } while (bit);
  58. spin_lock_bh(&sync_dev->row_spinlocks[idx]);
  59. rc = cam_sync_init_row(sync_dev->sync_table, idx, name,
  60. CAM_SYNC_TYPE_INDV);
  61. if (rc) {
  62. CAM_ERR(CAM_SYNC, "Error: Unable to init row at idx = %ld",
  63. idx);
  64. clear_bit(idx, sync_dev->bitmap);
  65. spin_unlock_bh(&sync_dev->row_spinlocks[idx]);
  66. return -EINVAL;
  67. }
  68. *sync_obj = idx;
  69. CAM_DBG(CAM_SYNC, "sync_obj: %i", *sync_obj);
  70. spin_unlock_bh(&sync_dev->row_spinlocks[idx]);
  71. return rc;
  72. }
  73. int cam_sync_register_callback(sync_callback cb_func,
  74. void *userdata, int32_t sync_obj)
  75. {
  76. struct sync_callback_info *sync_cb;
  77. struct sync_table_row *row = NULL;
  78. int status = 0;
  79. if (sync_obj >= CAM_SYNC_MAX_OBJS || sync_obj <= 0 || !cb_func)
  80. return -EINVAL;
  81. spin_lock_bh(&sync_dev->row_spinlocks[sync_obj]);
  82. row = sync_dev->sync_table + sync_obj;
  83. if (row->state == CAM_SYNC_STATE_INVALID) {
  84. CAM_ERR(CAM_SYNC,
  85. "Error: accessing an uninitialized sync obj %d",
  86. sync_obj);
  87. spin_unlock_bh(&sync_dev->row_spinlocks[sync_obj]);
  88. return -EINVAL;
  89. }
  90. sync_cb = kzalloc(sizeof(*sync_cb), GFP_ATOMIC);
  91. if (!sync_cb) {
  92. spin_unlock_bh(&sync_dev->row_spinlocks[sync_obj]);
  93. return -ENOMEM;
  94. }
  95. /* Trigger callback if sync object is already in SIGNALED state */
  96. if (((row->state == CAM_SYNC_STATE_SIGNALED_SUCCESS) ||
  97. (row->state == CAM_SYNC_STATE_SIGNALED_ERROR) ||
  98. (row->state == CAM_SYNC_STATE_SIGNALED_CANCEL)) &&
  99. (!row->remaining)) {
  100. if (trigger_cb_without_switch) {
  101. CAM_DBG(CAM_SYNC, "Invoke callback for sync object:%d",
  102. sync_obj);
  103. status = row->state;
  104. kfree(sync_cb);
  105. spin_unlock_bh(&sync_dev->row_spinlocks[sync_obj]);
  106. cb_func(sync_obj, status, userdata);
  107. } else {
  108. sync_cb->callback_func = cb_func;
  109. sync_cb->cb_data = userdata;
  110. sync_cb->sync_obj = sync_obj;
  111. INIT_WORK(&sync_cb->cb_dispatch_work,
  112. cam_sync_util_cb_dispatch);
  113. sync_cb->status = row->state;
  114. CAM_DBG(CAM_SYNC, "Enqueue callback for sync object:%d",
  115. sync_cb->sync_obj);
  116. queue_work(sync_dev->work_queue,
  117. &sync_cb->cb_dispatch_work);
  118. spin_unlock_bh(&sync_dev->row_spinlocks[sync_obj]);
  119. }
  120. return 0;
  121. }
  122. sync_cb->callback_func = cb_func;
  123. sync_cb->cb_data = userdata;
  124. sync_cb->sync_obj = sync_obj;
  125. INIT_WORK(&sync_cb->cb_dispatch_work, cam_sync_util_cb_dispatch);
  126. list_add_tail(&sync_cb->list, &row->callback_list);
  127. spin_unlock_bh(&sync_dev->row_spinlocks[sync_obj]);
  128. return 0;
  129. }
  130. int cam_sync_deregister_callback(sync_callback cb_func,
  131. void *userdata, int32_t sync_obj)
  132. {
  133. struct sync_table_row *row = NULL;
  134. struct sync_callback_info *sync_cb, *temp;
  135. bool found = false;
  136. if (sync_obj >= CAM_SYNC_MAX_OBJS || sync_obj <= 0)
  137. return -EINVAL;
  138. spin_lock_bh(&sync_dev->row_spinlocks[sync_obj]);
  139. row = sync_dev->sync_table + sync_obj;
  140. if (row->state == CAM_SYNC_STATE_INVALID) {
  141. CAM_ERR(CAM_SYNC,
  142. "Error: accessing an uninitialized sync obj = %d",
  143. sync_obj);
  144. spin_unlock_bh(&sync_dev->row_spinlocks[sync_obj]);
  145. return -EINVAL;
  146. }
  147. CAM_DBG(CAM_SYNC, "deregistered callback for sync object:%d",
  148. sync_obj);
  149. list_for_each_entry_safe(sync_cb, temp, &row->callback_list, list) {
  150. if (sync_cb->callback_func == cb_func &&
  151. sync_cb->cb_data == userdata) {
  152. list_del_init(&sync_cb->list);
  153. kfree(sync_cb);
  154. found = true;
  155. }
  156. }
  157. spin_unlock_bh(&sync_dev->row_spinlocks[sync_obj]);
  158. return found ? 0 : -ENOENT;
  159. }
  160. int cam_sync_signal(int32_t sync_obj, uint32_t status)
  161. {
  162. struct sync_table_row *row = NULL;
  163. struct sync_table_row *parent_row = NULL;
  164. struct sync_parent_info *parent_info, *temp_parent_info;
  165. struct list_head parents_list;
  166. int rc = 0;
  167. if (sync_obj >= CAM_SYNC_MAX_OBJS || sync_obj <= 0) {
  168. CAM_ERR(CAM_SYNC, "Error: Out of range sync obj (0 <= %d < %d)",
  169. sync_obj, CAM_SYNC_MAX_OBJS);
  170. return -EINVAL;
  171. }
  172. row = sync_dev->sync_table + sync_obj;
  173. spin_lock_bh(&sync_dev->row_spinlocks[sync_obj]);
  174. if (row->state == CAM_SYNC_STATE_INVALID) {
  175. spin_unlock_bh(&sync_dev->row_spinlocks[sync_obj]);
  176. CAM_ERR(CAM_SYNC,
  177. "Error: accessing an uninitialized sync obj = %d",
  178. sync_obj);
  179. return -EINVAL;
  180. }
  181. if (row->type == CAM_SYNC_TYPE_GROUP) {
  182. spin_unlock_bh(&sync_dev->row_spinlocks[sync_obj]);
  183. CAM_ERR(CAM_SYNC,
  184. "Error: Signaling a GROUP sync object = %d",
  185. sync_obj);
  186. return -EINVAL;
  187. }
  188. if (row->state != CAM_SYNC_STATE_ACTIVE) {
  189. spin_unlock_bh(&sync_dev->row_spinlocks[sync_obj]);
  190. CAM_ERR(CAM_SYNC,
  191. "Error: Sync object already signaled sync_obj = %d",
  192. sync_obj);
  193. return -EALREADY;
  194. }
  195. if ((status != CAM_SYNC_STATE_SIGNALED_SUCCESS) &&
  196. (status != CAM_SYNC_STATE_SIGNALED_ERROR) &&
  197. (status != CAM_SYNC_STATE_SIGNALED_CANCEL)) {
  198. spin_unlock_bh(&sync_dev->row_spinlocks[sync_obj]);
  199. CAM_ERR(CAM_SYNC,
  200. "Error: signaling with undefined status = %d",
  201. status);
  202. return -EINVAL;
  203. }
  204. if (!atomic_dec_and_test(&row->ref_cnt)) {
  205. spin_unlock_bh(&sync_dev->row_spinlocks[sync_obj]);
  206. return 0;
  207. }
  208. row->state = status;
  209. cam_sync_util_dispatch_signaled_cb(sync_obj, status);
  210. /* copy parent list to local and release child lock */
  211. INIT_LIST_HEAD(&parents_list);
  212. list_splice_init(&row->parents_list, &parents_list);
  213. spin_unlock_bh(&sync_dev->row_spinlocks[sync_obj]);
  214. if (list_empty(&parents_list))
  215. return 0;
  216. /*
  217. * Now iterate over all parents of this object and if they too need to
  218. * be signaled dispatch cb's
  219. */
  220. list_for_each_entry_safe(parent_info,
  221. temp_parent_info,
  222. &parents_list,
  223. list) {
  224. parent_row = sync_dev->sync_table + parent_info->sync_id;
  225. spin_lock_bh(&sync_dev->row_spinlocks[parent_info->sync_id]);
  226. parent_row->remaining--;
  227. rc = cam_sync_util_update_parent_state(
  228. parent_row,
  229. status);
  230. if (rc) {
  231. CAM_ERR(CAM_SYNC, "Invalid parent state %d",
  232. parent_row->state);
  233. spin_unlock_bh(
  234. &sync_dev->row_spinlocks[parent_info->sync_id]);
  235. kfree(parent_info);
  236. continue;
  237. }
  238. if (!parent_row->remaining)
  239. cam_sync_util_dispatch_signaled_cb(
  240. parent_info->sync_id, parent_row->state);
  241. spin_unlock_bh(&sync_dev->row_spinlocks[parent_info->sync_id]);
  242. list_del_init(&parent_info->list);
  243. kfree(parent_info);
  244. }
  245. return 0;
  246. }
  247. int cam_sync_merge(int32_t *sync_obj, uint32_t num_objs, int32_t *merged_obj)
  248. {
  249. int rc;
  250. long idx = 0;
  251. bool bit;
  252. int i = 0;
  253. if (!sync_obj || !merged_obj) {
  254. CAM_ERR(CAM_SYNC, "Invalid pointer(s)");
  255. return -EINVAL;
  256. }
  257. if (num_objs <= 1) {
  258. CAM_ERR(CAM_SYNC, "Single object merge is not allowed");
  259. return -EINVAL;
  260. }
  261. if (cam_common_util_remove_duplicate_arr(sync_obj, num_objs)
  262. != num_objs) {
  263. CAM_ERR(CAM_SYNC, "The obj list has duplicate fence");
  264. return -EINVAL;
  265. }
  266. for (i = 0; i < num_objs; i++) {
  267. rc = cam_sync_check_valid(sync_obj[i]);
  268. if (rc) {
  269. CAM_ERR(CAM_SYNC, "Sync_obj[%d] %d valid check fail",
  270. i, sync_obj[i]);
  271. return rc;
  272. }
  273. }
  274. do {
  275. idx = find_first_zero_bit(sync_dev->bitmap, CAM_SYNC_MAX_OBJS);
  276. if (idx >= CAM_SYNC_MAX_OBJS)
  277. return -ENOMEM;
  278. bit = test_and_set_bit(idx, sync_dev->bitmap);
  279. } while (bit);
  280. spin_lock_bh(&sync_dev->row_spinlocks[idx]);
  281. rc = cam_sync_init_group_object(sync_dev->sync_table,
  282. idx, sync_obj,
  283. num_objs);
  284. if (rc < 0) {
  285. CAM_ERR(CAM_SYNC, "Error: Unable to init row at idx = %ld",
  286. idx);
  287. clear_bit(idx, sync_dev->bitmap);
  288. spin_unlock_bh(&sync_dev->row_spinlocks[idx]);
  289. return -EINVAL;
  290. }
  291. CAM_DBG(CAM_SYNC, "Init row at idx:%ld to merge objects", idx);
  292. *merged_obj = idx;
  293. spin_unlock_bh(&sync_dev->row_spinlocks[idx]);
  294. return 0;
  295. }
  296. int cam_sync_get_obj_ref(int32_t sync_obj)
  297. {
  298. struct sync_table_row *row = NULL;
  299. if (sync_obj >= CAM_SYNC_MAX_OBJS || sync_obj <= 0)
  300. return -EINVAL;
  301. row = sync_dev->sync_table + sync_obj;
  302. spin_lock(&sync_dev->row_spinlocks[sync_obj]);
  303. if (row->state != CAM_SYNC_STATE_ACTIVE) {
  304. spin_unlock(&sync_dev->row_spinlocks[sync_obj]);
  305. CAM_ERR(CAM_SYNC,
  306. "Error: accessing an uninitialized sync obj = %d",
  307. sync_obj);
  308. return -EINVAL;
  309. }
  310. atomic_inc(&row->ref_cnt);
  311. spin_unlock(&sync_dev->row_spinlocks[sync_obj]);
  312. CAM_DBG(CAM_SYNC, "get ref for obj %d", sync_obj);
  313. return 0;
  314. }
  315. int cam_sync_put_obj_ref(int32_t sync_obj)
  316. {
  317. struct sync_table_row *row = NULL;
  318. if (sync_obj >= CAM_SYNC_MAX_OBJS || sync_obj <= 0)
  319. return -EINVAL;
  320. row = sync_dev->sync_table + sync_obj;
  321. atomic_dec(&row->ref_cnt);
  322. CAM_DBG(CAM_SYNC, "put ref for obj %d", sync_obj);
  323. return 0;
  324. }
  325. int cam_sync_destroy(int32_t sync_obj)
  326. {
  327. CAM_DBG(CAM_SYNC, "sync_obj: %i", sync_obj);
  328. return cam_sync_deinit_object(sync_dev->sync_table, sync_obj);
  329. }
  330. int cam_sync_check_valid(int32_t sync_obj)
  331. {
  332. struct sync_table_row *row = NULL;
  333. if (sync_obj >= CAM_SYNC_MAX_OBJS || sync_obj <= 0)
  334. return -EINVAL;
  335. row = sync_dev->sync_table + sync_obj;
  336. if (!test_bit(sync_obj, sync_dev->bitmap)) {
  337. CAM_ERR(CAM_SYNC, "Error: Released sync obj received %d",
  338. sync_obj);
  339. return -EINVAL;
  340. }
  341. if (row->state == CAM_SYNC_STATE_INVALID) {
  342. CAM_ERR(CAM_SYNC,
  343. "Error: accessing an uninitialized sync obj = %d",
  344. sync_obj);
  345. return -EINVAL;
  346. }
  347. return 0;
  348. }
  349. int cam_sync_wait(int32_t sync_obj, uint64_t timeout_ms)
  350. {
  351. unsigned long timeleft;
  352. int rc = -EINVAL;
  353. struct sync_table_row *row = NULL;
  354. if (sync_obj >= CAM_SYNC_MAX_OBJS || sync_obj <= 0)
  355. return -EINVAL;
  356. row = sync_dev->sync_table + sync_obj;
  357. if (row->state == CAM_SYNC_STATE_INVALID) {
  358. CAM_ERR(CAM_SYNC,
  359. "Error: accessing an uninitialized sync obj = %d",
  360. sync_obj);
  361. return -EINVAL;
  362. }
  363. timeleft = wait_for_completion_timeout(&row->signaled,
  364. msecs_to_jiffies(timeout_ms));
  365. if (!timeleft) {
  366. CAM_ERR(CAM_SYNC,
  367. "Error: timed out for sync obj = %d", sync_obj);
  368. rc = -ETIMEDOUT;
  369. } else {
  370. switch (row->state) {
  371. case CAM_SYNC_STATE_INVALID:
  372. case CAM_SYNC_STATE_ACTIVE:
  373. case CAM_SYNC_STATE_SIGNALED_ERROR:
  374. case CAM_SYNC_STATE_SIGNALED_CANCEL:
  375. CAM_ERR(CAM_SYNC,
  376. "Error: Wait on invalid state = %d, obj = %d",
  377. row->state, sync_obj);
  378. rc = -EINVAL;
  379. break;
  380. case CAM_SYNC_STATE_SIGNALED_SUCCESS:
  381. rc = 0;
  382. break;
  383. default:
  384. rc = -EINVAL;
  385. break;
  386. }
  387. }
  388. return rc;
  389. }
  390. static int cam_sync_handle_create(struct cam_private_ioctl_arg *k_ioctl)
  391. {
  392. struct cam_sync_info sync_create;
  393. int result;
  394. if (k_ioctl->size != sizeof(struct cam_sync_info))
  395. return -EINVAL;
  396. if (!k_ioctl->ioctl_ptr)
  397. return -EINVAL;
  398. if (copy_from_user(&sync_create,
  399. u64_to_user_ptr(k_ioctl->ioctl_ptr),
  400. k_ioctl->size))
  401. return -EFAULT;
  402. result = cam_sync_create(&sync_create.sync_obj,
  403. sync_create.name);
  404. if (!result)
  405. if (copy_to_user(
  406. u64_to_user_ptr(k_ioctl->ioctl_ptr),
  407. &sync_create,
  408. k_ioctl->size))
  409. return -EFAULT;
  410. return result;
  411. }
  412. static int cam_sync_handle_signal(struct cam_private_ioctl_arg *k_ioctl)
  413. {
  414. int rc = 0;
  415. struct cam_sync_signal sync_signal;
  416. if (k_ioctl->size != sizeof(struct cam_sync_signal))
  417. return -EINVAL;
  418. if (!k_ioctl->ioctl_ptr)
  419. return -EINVAL;
  420. if (copy_from_user(&sync_signal,
  421. u64_to_user_ptr(k_ioctl->ioctl_ptr),
  422. k_ioctl->size))
  423. return -EFAULT;
  424. /* need to get ref for UMD signaled fences */
  425. rc = cam_sync_get_obj_ref(sync_signal.sync_obj);
  426. if (rc) {
  427. CAM_DBG(CAM_SYNC,
  428. "Error: cannot signal an uninitialized sync obj = %d",
  429. sync_signal.sync_obj);
  430. return rc;
  431. }
  432. return cam_sync_signal(sync_signal.sync_obj,
  433. sync_signal.sync_state);
  434. }
  435. static int cam_sync_handle_merge(struct cam_private_ioctl_arg *k_ioctl)
  436. {
  437. struct cam_sync_merge sync_merge;
  438. uint32_t *sync_objs;
  439. uint32_t num_objs;
  440. uint32_t size;
  441. int result;
  442. if (k_ioctl->size != sizeof(struct cam_sync_merge))
  443. return -EINVAL;
  444. if (!k_ioctl->ioctl_ptr)
  445. return -EINVAL;
  446. if (copy_from_user(&sync_merge,
  447. u64_to_user_ptr(k_ioctl->ioctl_ptr),
  448. k_ioctl->size))
  449. return -EFAULT;
  450. if (sync_merge.num_objs >= CAM_SYNC_MAX_OBJS)
  451. return -EINVAL;
  452. size = sizeof(uint32_t) * sync_merge.num_objs;
  453. sync_objs = kzalloc(size, GFP_ATOMIC);
  454. if (!sync_objs)
  455. return -ENOMEM;
  456. if (copy_from_user(sync_objs,
  457. u64_to_user_ptr(sync_merge.sync_objs),
  458. sizeof(uint32_t) * sync_merge.num_objs)) {
  459. kfree(sync_objs);
  460. return -EFAULT;
  461. }
  462. num_objs = sync_merge.num_objs;
  463. result = cam_sync_merge(sync_objs,
  464. num_objs,
  465. &sync_merge.merged);
  466. if (!result)
  467. if (copy_to_user(
  468. u64_to_user_ptr(k_ioctl->ioctl_ptr),
  469. &sync_merge,
  470. k_ioctl->size)) {
  471. kfree(sync_objs);
  472. return -EFAULT;
  473. }
  474. kfree(sync_objs);
  475. return result;
  476. }
  477. static int cam_sync_handle_wait(struct cam_private_ioctl_arg *k_ioctl)
  478. {
  479. struct cam_sync_wait sync_wait;
  480. if (k_ioctl->size != sizeof(struct cam_sync_wait))
  481. return -EINVAL;
  482. if (!k_ioctl->ioctl_ptr)
  483. return -EINVAL;
  484. if (copy_from_user(&sync_wait,
  485. u64_to_user_ptr(k_ioctl->ioctl_ptr),
  486. k_ioctl->size))
  487. return -EFAULT;
  488. k_ioctl->result = cam_sync_wait(sync_wait.sync_obj,
  489. sync_wait.timeout_ms);
  490. return 0;
  491. }
  492. static int cam_sync_handle_destroy(struct cam_private_ioctl_arg *k_ioctl)
  493. {
  494. struct cam_sync_info sync_create;
  495. if (k_ioctl->size != sizeof(struct cam_sync_info))
  496. return -EINVAL;
  497. if (!k_ioctl->ioctl_ptr)
  498. return -EINVAL;
  499. if (copy_from_user(&sync_create,
  500. u64_to_user_ptr(k_ioctl->ioctl_ptr),
  501. k_ioctl->size))
  502. return -EFAULT;
  503. return cam_sync_destroy(sync_create.sync_obj);
  504. }
  505. static int cam_sync_handle_register_user_payload(
  506. struct cam_private_ioctl_arg *k_ioctl)
  507. {
  508. struct cam_sync_userpayload_info userpayload_info;
  509. struct sync_user_payload *user_payload_kernel;
  510. struct sync_user_payload *user_payload_iter;
  511. struct sync_user_payload *temp_upayload_kernel;
  512. uint32_t sync_obj;
  513. struct sync_table_row *row = NULL;
  514. if (k_ioctl->size != sizeof(struct cam_sync_userpayload_info))
  515. return -EINVAL;
  516. if (!k_ioctl->ioctl_ptr)
  517. return -EINVAL;
  518. if (copy_from_user(&userpayload_info,
  519. u64_to_user_ptr(k_ioctl->ioctl_ptr),
  520. k_ioctl->size))
  521. return -EFAULT;
  522. sync_obj = userpayload_info.sync_obj;
  523. if (sync_obj >= CAM_SYNC_MAX_OBJS || sync_obj <= 0)
  524. return -EINVAL;
  525. user_payload_kernel = kzalloc(sizeof(*user_payload_kernel), GFP_KERNEL);
  526. if (!user_payload_kernel)
  527. return -ENOMEM;
  528. memcpy(user_payload_kernel->payload_data,
  529. userpayload_info.payload,
  530. CAM_SYNC_PAYLOAD_WORDS * sizeof(__u64));
  531. spin_lock_bh(&sync_dev->row_spinlocks[sync_obj]);
  532. row = sync_dev->sync_table + sync_obj;
  533. if (row->state == CAM_SYNC_STATE_INVALID) {
  534. CAM_ERR(CAM_SYNC,
  535. "Error: accessing an uninitialized sync obj = %d",
  536. sync_obj);
  537. spin_unlock_bh(&sync_dev->row_spinlocks[sync_obj]);
  538. kfree(user_payload_kernel);
  539. return -EINVAL;
  540. }
  541. if ((row->state == CAM_SYNC_STATE_SIGNALED_SUCCESS) ||
  542. (row->state == CAM_SYNC_STATE_SIGNALED_ERROR) ||
  543. (row->state == CAM_SYNC_STATE_SIGNALED_CANCEL)) {
  544. cam_sync_util_send_v4l2_event(CAM_SYNC_V4L_EVENT_ID_CB_TRIG,
  545. sync_obj,
  546. row->state,
  547. user_payload_kernel->payload_data,
  548. CAM_SYNC_USER_PAYLOAD_SIZE * sizeof(__u64));
  549. spin_unlock_bh(&sync_dev->row_spinlocks[sync_obj]);
  550. kfree(user_payload_kernel);
  551. return 0;
  552. }
  553. list_for_each_entry_safe(user_payload_iter,
  554. temp_upayload_kernel,
  555. &row->user_payload_list,
  556. list) {
  557. if (user_payload_iter->payload_data[0] ==
  558. user_payload_kernel->payload_data[0] &&
  559. user_payload_iter->payload_data[1] ==
  560. user_payload_kernel->payload_data[1]) {
  561. spin_unlock_bh(&sync_dev->row_spinlocks[sync_obj]);
  562. kfree(user_payload_kernel);
  563. return -EALREADY;
  564. }
  565. }
  566. list_add_tail(&user_payload_kernel->list, &row->user_payload_list);
  567. spin_unlock_bh(&sync_dev->row_spinlocks[sync_obj]);
  568. return 0;
  569. }
  570. static int cam_sync_handle_deregister_user_payload(
  571. struct cam_private_ioctl_arg *k_ioctl)
  572. {
  573. struct cam_sync_userpayload_info userpayload_info;
  574. struct sync_user_payload *user_payload_kernel, *temp;
  575. uint32_t sync_obj;
  576. struct sync_table_row *row = NULL;
  577. if (k_ioctl->size != sizeof(struct cam_sync_userpayload_info)) {
  578. CAM_ERR(CAM_SYNC, "Incorrect ioctl size");
  579. return -EINVAL;
  580. }
  581. if (!k_ioctl->ioctl_ptr) {
  582. CAM_ERR(CAM_SYNC, "Invalid embedded ioctl ptr");
  583. return -EINVAL;
  584. }
  585. if (copy_from_user(&userpayload_info,
  586. u64_to_user_ptr(k_ioctl->ioctl_ptr),
  587. k_ioctl->size))
  588. return -EFAULT;
  589. sync_obj = userpayload_info.sync_obj;
  590. if (sync_obj >= CAM_SYNC_MAX_OBJS || sync_obj <= 0)
  591. return -EINVAL;
  592. spin_lock_bh(&sync_dev->row_spinlocks[sync_obj]);
  593. row = sync_dev->sync_table + sync_obj;
  594. if (row->state == CAM_SYNC_STATE_INVALID) {
  595. CAM_ERR(CAM_SYNC,
  596. "Error: accessing an uninitialized sync obj = %d",
  597. sync_obj);
  598. spin_unlock_bh(&sync_dev->row_spinlocks[sync_obj]);
  599. return -EINVAL;
  600. }
  601. list_for_each_entry_safe(user_payload_kernel, temp,
  602. &row->user_payload_list, list) {
  603. if (user_payload_kernel->payload_data[0] ==
  604. userpayload_info.payload[0] &&
  605. user_payload_kernel->payload_data[1] ==
  606. userpayload_info.payload[1]) {
  607. list_del_init(&user_payload_kernel->list);
  608. kfree(user_payload_kernel);
  609. }
  610. }
  611. spin_unlock_bh(&sync_dev->row_spinlocks[sync_obj]);
  612. return 0;
  613. }
  614. static long cam_sync_dev_ioctl(struct file *filep, void *fh,
  615. bool valid_prio, unsigned int cmd, void *arg)
  616. {
  617. int32_t rc;
  618. struct sync_device *sync_dev = video_drvdata(filep);
  619. struct cam_private_ioctl_arg k_ioctl;
  620. if (!sync_dev) {
  621. CAM_ERR(CAM_SYNC, "sync_dev NULL");
  622. return -EINVAL;
  623. }
  624. if (!arg)
  625. return -EINVAL;
  626. if (cmd != CAM_PRIVATE_IOCTL_CMD)
  627. return -ENOIOCTLCMD;
  628. k_ioctl = *(struct cam_private_ioctl_arg *)arg;
  629. switch (k_ioctl.id) {
  630. case CAM_SYNC_CREATE:
  631. rc = cam_sync_handle_create(&k_ioctl);
  632. break;
  633. case CAM_SYNC_DESTROY:
  634. rc = cam_sync_handle_destroy(&k_ioctl);
  635. break;
  636. case CAM_SYNC_REGISTER_PAYLOAD:
  637. rc = cam_sync_handle_register_user_payload(
  638. &k_ioctl);
  639. break;
  640. case CAM_SYNC_DEREGISTER_PAYLOAD:
  641. rc = cam_sync_handle_deregister_user_payload(
  642. &k_ioctl);
  643. break;
  644. case CAM_SYNC_SIGNAL:
  645. rc = cam_sync_handle_signal(&k_ioctl);
  646. break;
  647. case CAM_SYNC_MERGE:
  648. rc = cam_sync_handle_merge(&k_ioctl);
  649. break;
  650. case CAM_SYNC_WAIT:
  651. rc = cam_sync_handle_wait(&k_ioctl);
  652. ((struct cam_private_ioctl_arg *)arg)->result =
  653. k_ioctl.result;
  654. break;
  655. default:
  656. rc = -ENOIOCTLCMD;
  657. }
  658. return rc;
  659. }
  660. static unsigned int cam_sync_poll(struct file *f,
  661. struct poll_table_struct *pll_table)
  662. {
  663. int rc = 0;
  664. struct v4l2_fh *eventq = f->private_data;
  665. if (!eventq)
  666. return -EINVAL;
  667. poll_wait(f, &eventq->wait, pll_table);
  668. if (v4l2_event_pending(eventq))
  669. rc = POLLPRI;
  670. return rc;
  671. }
  672. static int cam_sync_open(struct file *filep)
  673. {
  674. int rc;
  675. struct sync_device *sync_dev = video_drvdata(filep);
  676. if (!sync_dev) {
  677. CAM_ERR(CAM_SYNC, "Sync device NULL");
  678. return -ENODEV;
  679. }
  680. mutex_lock(&sync_dev->table_lock);
  681. if (sync_dev->open_cnt >= 1) {
  682. mutex_unlock(&sync_dev->table_lock);
  683. return -EALREADY;
  684. }
  685. rc = v4l2_fh_open(filep);
  686. if (!rc) {
  687. sync_dev->open_cnt++;
  688. spin_lock_bh(&sync_dev->cam_sync_eventq_lock);
  689. sync_dev->cam_sync_eventq = filep->private_data;
  690. spin_unlock_bh(&sync_dev->cam_sync_eventq_lock);
  691. } else {
  692. CAM_ERR(CAM_SYNC, "v4l2_fh_open failed : %d", rc);
  693. }
  694. mutex_unlock(&sync_dev->table_lock);
  695. return rc;
  696. }
  697. static int cam_sync_close(struct file *filep)
  698. {
  699. int rc = 0;
  700. int i;
  701. struct sync_device *sync_dev = video_drvdata(filep);
  702. if (!sync_dev) {
  703. CAM_ERR(CAM_SYNC, "Sync device NULL");
  704. rc = -ENODEV;
  705. return rc;
  706. }
  707. mutex_lock(&sync_dev->table_lock);
  708. sync_dev->open_cnt--;
  709. if (!sync_dev->open_cnt) {
  710. for (i = 1; i < CAM_SYNC_MAX_OBJS; i++) {
  711. struct sync_table_row *row =
  712. sync_dev->sync_table + i;
  713. /*
  714. * Signal all ACTIVE objects as ERR, but we don't
  715. * care about the return status here apart from logging
  716. * it.
  717. */
  718. if (row->state == CAM_SYNC_STATE_ACTIVE) {
  719. rc = cam_sync_signal(i,
  720. CAM_SYNC_STATE_SIGNALED_ERROR);
  721. if (rc < 0)
  722. CAM_ERR(CAM_SYNC,
  723. "Cleanup signal fail idx:%d\n",
  724. i);
  725. }
  726. }
  727. /*
  728. * Flush the work queue to wait for pending signal callbacks to
  729. * finish
  730. */
  731. flush_workqueue(sync_dev->work_queue);
  732. /*
  733. * Now that all callbacks worker threads have finished,
  734. * destroy the sync objects
  735. */
  736. for (i = 1; i < CAM_SYNC_MAX_OBJS; i++) {
  737. struct sync_table_row *row =
  738. sync_dev->sync_table + i;
  739. if (row->state != CAM_SYNC_STATE_INVALID) {
  740. rc = cam_sync_destroy(i);
  741. if (rc < 0)
  742. CAM_ERR(CAM_SYNC,
  743. "Cleanup destroy fail:idx:%d\n",
  744. i);
  745. }
  746. }
  747. }
  748. mutex_unlock(&sync_dev->table_lock);
  749. spin_lock_bh(&sync_dev->cam_sync_eventq_lock);
  750. sync_dev->cam_sync_eventq = NULL;
  751. spin_unlock_bh(&sync_dev->cam_sync_eventq_lock);
  752. v4l2_fh_release(filep);
  753. return rc;
  754. }
  755. static void cam_sync_event_queue_notify_error(const struct v4l2_event *old,
  756. struct v4l2_event *new)
  757. {
  758. struct cam_sync_ev_header *ev_header;
  759. ev_header = CAM_SYNC_GET_HEADER_PTR((*old));
  760. CAM_ERR(CAM_CRM, "Failed to notify event id %d fence %d statue %d",
  761. old->id, ev_header->sync_obj, ev_header->status);
  762. }
  763. static struct v4l2_subscribed_event_ops cam_sync_v4l2_ops = {
  764. .merge = cam_sync_event_queue_notify_error,
  765. };
  766. int cam_sync_subscribe_event(struct v4l2_fh *fh,
  767. const struct v4l2_event_subscription *sub)
  768. {
  769. return v4l2_event_subscribe(fh, sub, CAM_SYNC_MAX_V4L2_EVENTS,
  770. &cam_sync_v4l2_ops);
  771. }
  772. int cam_sync_unsubscribe_event(struct v4l2_fh *fh,
  773. const struct v4l2_event_subscription *sub)
  774. {
  775. return v4l2_event_unsubscribe(fh, sub);
  776. }
  777. static const struct v4l2_ioctl_ops g_cam_sync_ioctl_ops = {
  778. .vidioc_subscribe_event = cam_sync_subscribe_event,
  779. .vidioc_unsubscribe_event = cam_sync_unsubscribe_event,
  780. .vidioc_default = cam_sync_dev_ioctl,
  781. };
  782. static struct v4l2_file_operations cam_sync_v4l2_fops = {
  783. .owner = THIS_MODULE,
  784. .open = cam_sync_open,
  785. .release = cam_sync_close,
  786. .poll = cam_sync_poll,
  787. .unlocked_ioctl = video_ioctl2,
  788. #ifdef CONFIG_COMPAT
  789. .compat_ioctl32 = video_ioctl2,
  790. #endif
  791. };
  792. #if IS_REACHABLE(CONFIG_MEDIA_CONTROLLER)
  793. static int cam_sync_media_controller_init(struct sync_device *sync_dev,
  794. struct platform_device *pdev)
  795. {
  796. int rc;
  797. sync_dev->v4l2_dev.mdev = kzalloc(sizeof(struct media_device),
  798. GFP_KERNEL);
  799. if (!sync_dev->v4l2_dev.mdev)
  800. return -ENOMEM;
  801. media_device_init(sync_dev->v4l2_dev.mdev);
  802. strlcpy(sync_dev->v4l2_dev.mdev->model, CAM_SYNC_DEVICE_NAME,
  803. sizeof(sync_dev->v4l2_dev.mdev->model));
  804. sync_dev->v4l2_dev.mdev->dev = &(pdev->dev);
  805. rc = media_device_register(sync_dev->v4l2_dev.mdev);
  806. if (rc < 0)
  807. goto register_fail;
  808. rc = media_entity_pads_init(&sync_dev->vdev->entity, 0, NULL);
  809. if (rc < 0)
  810. goto entity_fail;
  811. return 0;
  812. entity_fail:
  813. media_device_unregister(sync_dev->v4l2_dev.mdev);
  814. register_fail:
  815. media_device_cleanup(sync_dev->v4l2_dev.mdev);
  816. return rc;
  817. }
  818. static void cam_sync_media_controller_cleanup(struct sync_device *sync_dev)
  819. {
  820. media_entity_cleanup(&sync_dev->vdev->entity);
  821. media_device_unregister(sync_dev->v4l2_dev.mdev);
  822. media_device_cleanup(sync_dev->v4l2_dev.mdev);
  823. kfree(sync_dev->v4l2_dev.mdev);
  824. }
  825. static void cam_sync_init_entity(struct sync_device *sync_dev)
  826. {
  827. sync_dev->vdev->entity.function = CAM_SYNC_DEVICE_TYPE;
  828. sync_dev->vdev->entity.name =
  829. video_device_node_name(sync_dev->vdev);
  830. }
  831. #else
  832. static int cam_sync_media_controller_init(struct sync_device *sync_dev,
  833. struct platform_device *pdev)
  834. {
  835. return 0;
  836. }
  837. static void cam_sync_media_controller_cleanup(struct sync_device *sync_dev)
  838. {
  839. }
  840. static void cam_sync_init_entity(struct sync_device *sync_dev)
  841. {
  842. }
  843. #endif
  844. static int cam_sync_create_debugfs(void)
  845. {
  846. sync_dev->dentry = debugfs_create_dir("camera_sync", NULL);
  847. if (!sync_dev->dentry) {
  848. CAM_ERR(CAM_SYNC, "Failed to create sync dir");
  849. return -ENOMEM;
  850. }
  851. if (!debugfs_create_bool("trigger_cb_without_switch",
  852. 0644, sync_dev->dentry,
  853. &trigger_cb_without_switch)) {
  854. CAM_ERR(CAM_SYNC,
  855. "failed to create trigger_cb_without_switch entry");
  856. return -ENOMEM;
  857. }
  858. return 0;
  859. }
  860. #if IS_REACHABLE(CONFIG_MSM_GLOBAL_SYNX)
  861. int cam_synx_sync_signal(int32_t sync_obj, uint32_t synx_status)
  862. {
  863. int rc = 0;
  864. uint32_t sync_status = synx_status;
  865. switch (synx_status) {
  866. case SYNX_STATE_ACTIVE:
  867. sync_status = CAM_SYNC_STATE_ACTIVE;
  868. break;
  869. case SYNX_STATE_SIGNALED_SUCCESS:
  870. sync_status = CAM_SYNC_STATE_SIGNALED_SUCCESS;
  871. break;
  872. case SYNX_STATE_SIGNALED_ERROR:
  873. sync_status = CAM_SYNC_STATE_SIGNALED_ERROR;
  874. break;
  875. case 4: /* SYNX_STATE_SIGNALED_CANCEL: */
  876. sync_status = CAM_SYNC_STATE_SIGNALED_CANCEL;
  877. break;
  878. default:
  879. CAM_ERR(CAM_SYNC, "Invalid synx status %d for obj %d",
  880. synx_status, sync_obj);
  881. sync_status = CAM_SYNC_STATE_SIGNALED_ERROR;
  882. break;
  883. }
  884. rc = cam_sync_signal(sync_obj, sync_status);
  885. if (rc) {
  886. CAM_ERR(CAM_SYNC,
  887. "synx signal failed with %d, sync_obj=%d, synx_status=%d, sync_status=%d",
  888. sync_obj, synx_status, sync_status, rc);
  889. }
  890. return rc;
  891. }
  892. static int cam_sync_register_synx_bind_ops(void)
  893. {
  894. int rc = 0;
  895. struct synx_register_params params;
  896. params.name = CAM_SYNC_NAME;
  897. params.type = SYNX_TYPE_CSL;
  898. params.ops.register_callback = cam_sync_register_callback;
  899. params.ops.deregister_callback = cam_sync_deregister_callback;
  900. params.ops.enable_signaling = cam_sync_get_obj_ref;
  901. params.ops.signal = cam_synx_sync_signal;
  902. rc = synx_register_ops(&params);
  903. if (rc)
  904. CAM_ERR(CAM_SYNC, "synx registration fail with rc=%d", rc);
  905. return rc;
  906. }
  907. #endif
  908. static int cam_sync_component_bind(struct device *dev,
  909. struct device *master_dev, void *data)
  910. {
  911. int rc;
  912. int idx;
  913. struct platform_device *pdev = to_platform_device(dev);
  914. sync_dev = kzalloc(sizeof(*sync_dev), GFP_KERNEL);
  915. if (!sync_dev)
  916. return -ENOMEM;
  917. mutex_init(&sync_dev->table_lock);
  918. spin_lock_init(&sync_dev->cam_sync_eventq_lock);
  919. for (idx = 0; idx < CAM_SYNC_MAX_OBJS; idx++)
  920. spin_lock_init(&sync_dev->row_spinlocks[idx]);
  921. sync_dev->vdev = video_device_alloc();
  922. if (!sync_dev->vdev) {
  923. rc = -ENOMEM;
  924. goto vdev_fail;
  925. }
  926. rc = cam_sync_media_controller_init(sync_dev, pdev);
  927. if (rc < 0)
  928. goto mcinit_fail;
  929. sync_dev->vdev->v4l2_dev = &sync_dev->v4l2_dev;
  930. rc = v4l2_device_register(&(pdev->dev), sync_dev->vdev->v4l2_dev);
  931. if (rc < 0)
  932. goto register_fail;
  933. strlcpy(sync_dev->vdev->name, CAM_SYNC_NAME,
  934. sizeof(sync_dev->vdev->name));
  935. sync_dev->vdev->release = video_device_release_empty;
  936. sync_dev->vdev->fops = &cam_sync_v4l2_fops;
  937. sync_dev->vdev->ioctl_ops = &g_cam_sync_ioctl_ops;
  938. sync_dev->vdev->minor = -1;
  939. sync_dev->vdev->device_caps |= V4L2_CAP_VIDEO_CAPTURE;
  940. sync_dev->vdev->vfl_type = VFL_TYPE_GRABBER;
  941. rc = video_register_device(sync_dev->vdev,
  942. VFL_TYPE_GRABBER, -1);
  943. if (rc < 0) {
  944. CAM_ERR(CAM_SYNC,
  945. "video device registration failure rc = %d, name = %s, device_caps = %d",
  946. rc, sync_dev->vdev->name, sync_dev->vdev->device_caps);
  947. goto v4l2_fail;
  948. }
  949. cam_sync_init_entity(sync_dev);
  950. video_set_drvdata(sync_dev->vdev, sync_dev);
  951. memset(&sync_dev->sync_table, 0, sizeof(sync_dev->sync_table));
  952. memset(&sync_dev->bitmap, 0, sizeof(sync_dev->bitmap));
  953. bitmap_zero(sync_dev->bitmap, CAM_SYNC_MAX_OBJS);
  954. /*
  955. * We treat zero as invalid handle, so we will keep the 0th bit set
  956. * always
  957. */
  958. set_bit(0, sync_dev->bitmap);
  959. sync_dev->work_queue = alloc_workqueue(CAM_SYNC_WORKQUEUE_NAME,
  960. WQ_HIGHPRI | WQ_UNBOUND, 1);
  961. if (!sync_dev->work_queue) {
  962. CAM_ERR(CAM_SYNC,
  963. "Error: high priority work queue creation failed");
  964. rc = -ENOMEM;
  965. goto v4l2_fail;
  966. }
  967. trigger_cb_without_switch = false;
  968. cam_sync_create_debugfs();
  969. #if IS_REACHABLE(CONFIG_MSM_GLOBAL_SYNX)
  970. CAM_INFO(CAM_SYNC, "Registering with synx driver");
  971. rc = cam_sync_register_synx_bind_ops();
  972. if (rc)
  973. goto v4l2_fail;
  974. #endif
  975. CAM_DBG(CAM_SYNC, "Component bound successfully");
  976. return rc;
  977. v4l2_fail:
  978. v4l2_device_unregister(sync_dev->vdev->v4l2_dev);
  979. register_fail:
  980. cam_sync_media_controller_cleanup(sync_dev);
  981. mcinit_fail:
  982. video_unregister_device(sync_dev->vdev);
  983. video_device_release(sync_dev->vdev);
  984. vdev_fail:
  985. mutex_destroy(&sync_dev->table_lock);
  986. kfree(sync_dev);
  987. return rc;
  988. }
  989. static void cam_sync_component_unbind(struct device *dev,
  990. struct device *master_dev, void *data)
  991. {
  992. int i;
  993. v4l2_device_unregister(sync_dev->vdev->v4l2_dev);
  994. cam_sync_media_controller_cleanup(sync_dev);
  995. video_unregister_device(sync_dev->vdev);
  996. video_device_release(sync_dev->vdev);
  997. debugfs_remove_recursive(sync_dev->dentry);
  998. sync_dev->dentry = NULL;
  999. for (i = 0; i < CAM_SYNC_MAX_OBJS; i++)
  1000. spin_lock_init(&sync_dev->row_spinlocks[i]);
  1001. kfree(sync_dev);
  1002. sync_dev = NULL;
  1003. }
  1004. const static struct component_ops cam_sync_component_ops = {
  1005. .bind = cam_sync_component_bind,
  1006. .unbind = cam_sync_component_unbind,
  1007. };
  1008. static int cam_sync_probe(struct platform_device *pdev)
  1009. {
  1010. int rc = 0;
  1011. CAM_DBG(CAM_SYNC, "Adding Sync component");
  1012. rc = component_add(&pdev->dev, &cam_sync_component_ops);
  1013. if (rc)
  1014. CAM_ERR(CAM_SYNC, "failed to add component rc: %d", rc);
  1015. return rc;
  1016. }
  1017. static int cam_sync_remove(struct platform_device *pdev)
  1018. {
  1019. component_del(&pdev->dev, &cam_sync_component_ops);
  1020. return 0;
  1021. }
  1022. static const struct of_device_id cam_sync_dt_match[] = {
  1023. {.compatible = "qcom,cam-sync"},
  1024. {}
  1025. };
  1026. MODULE_DEVICE_TABLE(of, cam_sync_dt_match);
  1027. struct platform_driver cam_sync_driver = {
  1028. .probe = cam_sync_probe,
  1029. .remove = cam_sync_remove,
  1030. .driver = {
  1031. .name = "cam_sync",
  1032. .owner = THIS_MODULE,
  1033. .of_match_table = cam_sync_dt_match,
  1034. .suppress_bind_attrs = true,
  1035. },
  1036. };
  1037. int cam_sync_init(void)
  1038. {
  1039. return platform_driver_register(&cam_sync_driver);
  1040. }
  1041. void cam_sync_exit(void)
  1042. {
  1043. platform_driver_unregister(&cam_sync_driver);
  1044. }
  1045. MODULE_DESCRIPTION("Camera sync driver");
  1046. MODULE_LICENSE("GPL v2");