camera_main.c 7.4 KB

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