camera_main.c 7.5 KB

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