camera_main.c 7.8 KB

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