camera_main.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2019-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #include <linux/module.h>
  7. #include <linux/build_bug.h>
  8. #include "cam_req_mgr_dev.h"
  9. #include "cam_sync_api.h"
  10. #include "cam_smmu_api.h"
  11. #include "cam_cpas_hw_intf.h"
  12. #include "cam_cdm_intf_api.h"
  13. #include "cam_ife_csid_dev.h"
  14. #include "cam_vfe.h"
  15. #include "cam_sfe_dev.h"
  16. #include "cam_isp_dev.h"
  17. #include "cam_res_mgr_api.h"
  18. #include "cam_cci_dev.h"
  19. #include "cam_sensor_dev.h"
  20. #include "cam_actuator_dev.h"
  21. #include "cam_csiphy_dev.h"
  22. #include "cam_eeprom_dev.h"
  23. #include "cam_ois_dev.h"
  24. #include "cam_tpg_dev.h"
  25. #include "cam_flash_dev.h"
  26. #include "cam_icp_v1_dev.h"
  27. #include "cam_icp_v2_dev.h"
  28. #include "ipe_core.h"
  29. #include "bps_core.h"
  30. #include "ofe_core.h"
  31. #include "cam_icp_subdev.h"
  32. #include "jpeg_dma_core.h"
  33. #include "jpeg_enc_core.h"
  34. #include "cam_jpeg_dev.h"
  35. #include "cre_core.h"
  36. #include "cam_cre_dev.h"
  37. #include "cam_fd_hw_intf.h"
  38. #include "cam_fd_dev.h"
  39. #include "cam_lrme_hw_intf.h"
  40. #include "cam_lrme_dev.h"
  41. #include "cam_custom_dev.h"
  42. #include "cam_custom_csid_dev.h"
  43. #include "cam_custom_sub_mod_dev.h"
  44. #include "cam_debug_util.h"
  45. #include "ope_dev_intf.h"
  46. #include "cre_dev_intf.h"
  47. #include "cam_tfe_dev.h"
  48. #include "cam_tfe_csid.h"
  49. #include "cam_csid_ppi100.h"
  50. #include "camera_main.h"
  51. #ifndef CAMERA_COMPILE_BY
  52. #include "cam_generated_h"
  53. #endif
  54. char camera_banner[] = "Camera-Banner: (" CAMERA_COMPILE_BY "@"
  55. CAMERA_COMPILE_HOST ") (" CAMERA_COMPILE_TIME ")";
  56. #ifdef CONFIG_CAM_PRESIL
  57. extern int cam_presil_framework_dev_init_from_main(void);
  58. extern void cam_presil_framework_dev_exit_from_main(void);
  59. #endif
  60. struct camera_submodule_component {
  61. int (*init)(void);
  62. void (*exit)(void);
  63. };
  64. struct camera_submodule {
  65. char *name;
  66. uint num_component;
  67. const struct camera_submodule_component *component;
  68. };
  69. static const struct camera_submodule_component camera_base[] = {
  70. {&cam_req_mgr_init, &cam_req_mgr_exit},
  71. {&cam_sync_init, &cam_sync_exit},
  72. {&cam_smmu_init_module, &cam_smmu_exit_module},
  73. {&cam_cpas_dev_init_module, &cam_cpas_dev_exit_module},
  74. {&cam_cdm_intf_init_module, &cam_cdm_intf_exit_module},
  75. {&cam_hw_cdm_init_module, &cam_hw_cdm_exit_module},
  76. };
  77. static const struct camera_submodule_component camera_tfe[] = {
  78. #ifdef CONFIG_SPECTRA_TFE
  79. {&cam_csid_ppi100_init_module, &cam_csid_ppi100_exit_module},
  80. {&cam_tfe_init_module, &cam_tfe_exit_module},
  81. {&cam_tfe_csid_init_module, &cam_tfe_csid_exit_module},
  82. #endif
  83. };
  84. static const struct camera_submodule_component camera_isp[] = {
  85. #ifdef CONFIG_SPECTRA_ISP
  86. {&cam_ife_csid_init_module, &cam_ife_csid_exit_module},
  87. {&cam_ife_csid_lite_init_module, &cam_ife_csid_lite_exit_module},
  88. {&cam_vfe_init_module, &cam_vfe_exit_module},
  89. {&cam_sfe_init_module, &cam_sfe_exit_module},
  90. {&cam_isp_dev_init_module, &cam_isp_dev_exit_module},
  91. #endif
  92. };
  93. static const struct camera_submodule_component camera_sensor[] = {
  94. #ifdef CONFIG_SPECTRA_SENSOR
  95. {&cam_res_mgr_init, &cam_res_mgr_exit},
  96. {&cam_cci_init_module, &cam_cci_exit_module},
  97. {&cam_csiphy_init_module, &cam_csiphy_exit_module},
  98. {&cam_tpg_init_module, &cam_tpg_exit_module},
  99. {&cam_actuator_driver_init, &cam_actuator_driver_exit},
  100. {&cam_sensor_driver_init, &cam_sensor_driver_exit},
  101. {&cam_eeprom_driver_init, &cam_eeprom_driver_exit},
  102. {&cam_ois_driver_init, &cam_ois_driver_exit},
  103. {&cam_flash_init_module, &cam_flash_exit_module},
  104. #endif
  105. };
  106. static const struct camera_submodule_component camera_icp[] = {
  107. #ifdef CONFIG_SPECTRA_ICP
  108. {&cam_icp_v1_init_module, &cam_icp_v1_exit_module},
  109. {&cam_icp_v2_init_module, &cam_icp_v2_exit_module},
  110. {&cam_ipe_init_module, &cam_ipe_exit_module},
  111. {&cam_bps_init_module, &cam_bps_exit_module},
  112. {&cam_ofe_init_module, &cam_ofe_exit_module},
  113. {&cam_icp_init_module, &cam_icp_exit_module},
  114. #endif
  115. };
  116. static const struct camera_submodule_component camera_ope[] = {
  117. #ifdef CONFIG_SPECTRA_OPE
  118. {&cam_ope_init_module, &cam_ope_exit_module},
  119. {&cam_ope_subdev_init_module, &cam_ope_subdev_exit_module},
  120. #endif
  121. };
  122. static const struct camera_submodule_component camera_cre[] = {
  123. #ifdef CONFIG_SPECTRA_CRE
  124. {&cam_cre_init_module, &cam_cre_exit_module},
  125. {&cam_cre_subdev_init_module, &cam_cre_subdev_exit_module},
  126. #endif
  127. };
  128. static const struct camera_submodule_component camera_jpeg[] = {
  129. #ifdef CONFIG_SPECTRA_JPEG
  130. {&cam_jpeg_enc_init_module, &cam_jpeg_enc_exit_module},
  131. {&cam_jpeg_dma_init_module, &cam_jpeg_dma_exit_module},
  132. {&cam_jpeg_dev_init_module, &cam_jpeg_dev_exit_module},
  133. #endif
  134. };
  135. static const struct camera_submodule_component camera_fd[] = {
  136. #ifdef CONFIG_SPECTRA_FD
  137. {&cam_fd_hw_init_module, &cam_fd_hw_exit_module},
  138. {&cam_fd_dev_init_module, &cam_fd_dev_exit_module},
  139. #endif
  140. };
  141. static const struct camera_submodule_component camera_lrme[] = {
  142. #ifdef CONFIG_SPECTRA_LRME
  143. {&cam_lrme_hw_init_module, &cam_lrme_hw_exit_module},
  144. {&cam_lrme_dev_init_module, &cam_lrme_dev_exit_module},
  145. #endif
  146. };
  147. static const struct camera_submodule_component camera_custom[] = {
  148. #ifdef CONFIG_SPECTRA_CUSTOM
  149. {&cam_custom_hw_sub_module_init, &cam_custom_hw_sub_module_exit},
  150. {&cam_custom_csid_driver_init, &cam_custom_csid_driver_exit},
  151. {&cam_custom_dev_init_module, &cam_custom_dev_exit_module},
  152. #endif
  153. };
  154. static const struct camera_submodule_component camera_presil[] = {
  155. #ifdef CONFIG_CAM_PRESIL
  156. {&cam_presil_framework_dev_init_from_main, &cam_presil_framework_dev_exit_from_main},
  157. #endif
  158. };
  159. static const struct camera_submodule submodule_table[] = {
  160. {
  161. .name = "Camera BASE",
  162. .num_component = ARRAY_SIZE(camera_base),
  163. .component = camera_base,
  164. },
  165. {
  166. .name = "Camera TFE",
  167. .num_component = ARRAY_SIZE(camera_tfe),
  168. .component = camera_tfe,
  169. },
  170. {
  171. .name = "Camera ISP",
  172. .num_component = ARRAY_SIZE(camera_isp),
  173. .component = camera_isp,
  174. },
  175. {
  176. .name = "Camera SENSOR",
  177. .num_component = ARRAY_SIZE(camera_sensor),
  178. .component = camera_sensor
  179. },
  180. {
  181. .name = "Camera ICP",
  182. .num_component = ARRAY_SIZE(camera_icp),
  183. .component = camera_icp,
  184. },
  185. {
  186. .name = "Camera OPE",
  187. .num_component = ARRAY_SIZE(camera_ope),
  188. .component = camera_ope,
  189. },
  190. {
  191. .name = "Camera JPEG",
  192. .num_component = ARRAY_SIZE(camera_jpeg),
  193. .component = camera_jpeg,
  194. },
  195. {
  196. .name = "Camera FD",
  197. .num_component = ARRAY_SIZE(camera_fd),
  198. .component = camera_fd,
  199. },
  200. {
  201. .name = "Camera LRME",
  202. .num_component = ARRAY_SIZE(camera_lrme),
  203. .component = camera_lrme,
  204. },
  205. {
  206. .name = "Camera CRE",
  207. .num_component = ARRAY_SIZE(camera_cre),
  208. .component = camera_cre,
  209. },
  210. {
  211. .name = "Camera CUSTOM",
  212. .num_component = ARRAY_SIZE(camera_custom),
  213. .component = camera_custom,
  214. },
  215. {
  216. .name = "Camera Presil",
  217. .num_component = ARRAY_SIZE(camera_presil),
  218. .component = camera_presil,
  219. }
  220. };
  221. static int camera_verify_submodules(void)
  222. {
  223. int rc = 0;
  224. int i, j, num_components;
  225. for (i = 0; i < ARRAY_SIZE(submodule_table); i++) {
  226. num_components = submodule_table[i].num_component;
  227. for (j = 0; j < num_components; j++) {
  228. if (!submodule_table[i].component[j].init ||
  229. !submodule_table[i].component[j].exit) {
  230. CAM_ERR(CAM_UTIL,
  231. "%s module has init = %ps, exit = %ps",
  232. submodule_table[i].name,
  233. submodule_table[i].component[j].init,
  234. submodule_table[i].component[j].exit);
  235. rc = -EINVAL;
  236. goto end;
  237. }
  238. }
  239. }
  240. end:
  241. return rc;
  242. }
  243. static void __camera_exit(int i, int j)
  244. {
  245. uint num_exits;
  246. /* Exit from current submodule */
  247. for (j -= 1; j >= 0; j--)
  248. submodule_table[i].component[j].exit();
  249. /* Exit remaining submodules */
  250. for (i -= 1; i >= 0; i--) {
  251. num_exits = submodule_table[i].num_component;
  252. for (j = num_exits - 1; j >= 0; j--)
  253. submodule_table[i].component[j].exit();
  254. }
  255. }
  256. static int camera_init(void)
  257. {
  258. int rc;
  259. uint i, j, num_inits;
  260. CAM_INFO(CAM_UTIL, "%s", camera_banner);
  261. rc = camera_verify_submodules();
  262. if (rc)
  263. goto end_init;
  264. cam_debugfs_init();
  265. /* For Probing all available submodules */
  266. for (i = 0; i < ARRAY_SIZE(submodule_table); i++) {
  267. num_inits = submodule_table[i].num_component;
  268. CAM_DBG(CAM_UTIL, "Number of %s components: %u",
  269. submodule_table[i].name, num_inits);
  270. for (j = 0; j < num_inits; j++) {
  271. rc = submodule_table[i].component[j].init();
  272. if (rc) {
  273. CAM_ERR(CAM_UTIL,
  274. "%s module failure at %ps rc = %d",
  275. submodule_table[i].name,
  276. submodule_table[i].component[j].init,
  277. rc);
  278. __camera_exit(i, j);
  279. goto end_init;
  280. }
  281. }
  282. }
  283. CAM_DBG(CAM_UTIL, "Camera initcalls done");
  284. end_init:
  285. return rc;
  286. }
  287. static void camera_exit(void)
  288. {
  289. __camera_exit(ARRAY_SIZE(submodule_table), 0);
  290. cam_debugfs_deinit();
  291. CAM_INFO(CAM_UTIL, "Spectra camera driver exited!");
  292. }
  293. module_init(camera_init);
  294. module_exit(camera_exit);
  295. MODULE_DESCRIPTION("Spectra camera driver");
  296. MODULE_LICENSE("GPL v2");