camera_main.c 8.4 KB

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