camera_main.c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  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. #include "cam_flash_dev.h"
  24. #endif
  25. #include "a5_core.h"
  26. #include "ipe_core.h"
  27. #include "bps_core.h"
  28. #include "cam_icp_subdev.h"
  29. #include "jpeg_dma_core.h"
  30. #include "jpeg_enc_core.h"
  31. #include "cam_jpeg_dev.h"
  32. #include "cam_fd_hw_intf.h"
  33. #include "cam_fd_dev.h"
  34. #include "cam_lrme_hw_intf.h"
  35. #include "cam_lrme_dev.h"
  36. #include "cam_custom_dev.h"
  37. #include "cam_custom_csid_dev.h"
  38. #include "cam_custom_sub_mod_dev.h"
  39. #include "cam_debug_util.h"
  40. #include "ope_dev_intf.h"
  41. #include "cam_top_tpg.h"
  42. #include "cam_tfe_dev.h"
  43. #include "cam_tfe_csid530.h"
  44. #include "camera_main.h"
  45. struct camera_submodule_component {
  46. int (*init)(void);
  47. void (*exit)(void);
  48. };
  49. struct camera_submodule {
  50. char *name;
  51. uint num_component;
  52. const struct camera_submodule_component *component;
  53. };
  54. static const struct camera_submodule_component camera_base[] = {
  55. {&cam_req_mgr_init, &cam_req_mgr_exit},
  56. {&cam_sync_init, &cam_sync_exit},
  57. {&cam_smmu_init_module, &cam_smmu_exit_module},
  58. {&cam_cpas_dev_init_module, &cam_cpas_dev_exit_module},
  59. {&cam_cdm_intf_init_module, &cam_cdm_intf_exit_module},
  60. {&cam_hw_cdm_init_module, &cam_hw_cdm_exit_module},
  61. };
  62. static const struct camera_submodule_component camera_isp[] = {
  63. #ifdef CONFIG_SPECTRA_ISP
  64. {&cam_top_tpg_init_module, &cam_top_tpg_exit_module},
  65. {&cam_ife_csid17x_init_module, &cam_ife_csid17x_exit_module},
  66. {&cam_ife_csid_lite_init_module, &cam_ife_csid_lite_exit_module},
  67. {&cam_vfe_init_module, &cam_vfe_exit_module},
  68. {&cam_isp_dev_init_module, &cam_isp_dev_exit_module},
  69. #endif
  70. };
  71. static const struct camera_submodule_component camera_tfe[] = {
  72. #if IS_ENABLED(CONFIG_SPECTRA_TFE)
  73. {&cam_top_tpg_init_module, &cam_top_tpg_exit_module},
  74. {&cam_tfe_init_module, &cam_tfe_exit_module},
  75. {&cam_tfe_csid530_init_module, &cam_tfe_csid530_exit_module},
  76. #endif
  77. };
  78. static const struct camera_submodule_component camera_sensor[] = {
  79. #ifdef CONFIG_SPECTRA_SENSOR
  80. {&cam_res_mgr_init, &cam_res_mgr_exit},
  81. {&cam_cci_init_module, &cam_cci_exit_module},
  82. {&cam_csiphy_init_module, &cam_csiphy_exit_module},
  83. {&cam_actuator_driver_init, &cam_actuator_driver_exit},
  84. {&cam_sensor_driver_init, &cam_sensor_driver_exit},
  85. {&cam_eeprom_driver_init, &cam_eeprom_driver_exit},
  86. {&cam_ois_driver_init, &cam_ois_driver_exit},
  87. #if IS_REACHABLE(CONFIG_LEDS_QPNP_FLASH_V2)
  88. {&cam_flash_init_module, &cam_flash_exit_module},
  89. #endif
  90. #endif
  91. };
  92. static const struct camera_submodule_component camera_icp[] = {
  93. #ifdef CONFIG_SPECTRA_ICP
  94. {&cam_a5_init_module, &cam_a5_exit_module},
  95. {&cam_ipe_init_module, &cam_ipe_exit_module},
  96. {&cam_bps_init_module, &cam_bps_exit_module},
  97. {&cam_icp_init_module, &cam_icp_exit_module},
  98. #endif
  99. };
  100. static const struct camera_submodule_component camera_ope[] = {
  101. #ifdef CONFIG_SPECTRA_OPE
  102. {&cam_ope_init_module, &cam_ope_exit_module},
  103. {&cam_ope_subdev_init_module, &cam_ope_subdev_exit_module},
  104. #endif
  105. };
  106. static const struct camera_submodule_component camera_jpeg[] = {
  107. #ifdef CONFIG_SPECTRA_JPEG
  108. {&cam_jpeg_enc_init_module, &cam_jpeg_enc_exit_module},
  109. {&cam_jpeg_dma_init_module, &cam_jpeg_dma_exit_module},
  110. {&cam_jpeg_dev_init_module, &cam_jpeg_dev_exit_module},
  111. #endif
  112. };
  113. static const struct camera_submodule_component camera_fd[] = {
  114. #ifdef CONFIG_SPECTRA_FD
  115. {&cam_fd_hw_init_module, &cam_fd_hw_exit_module},
  116. {&cam_fd_dev_init_module, &cam_fd_dev_exit_module},
  117. #endif
  118. };
  119. static const struct camera_submodule_component camera_lrme[] = {
  120. #ifdef CONFIG_SPECTRA_LRME
  121. {&cam_lrme_hw_init_module, &cam_lrme_hw_exit_module},
  122. {&cam_lrme_dev_init_module, &cam_lrme_dev_exit_module},
  123. #endif
  124. };
  125. static const struct camera_submodule_component camera_custom[] = {
  126. #ifdef CONFIG_SPECTRA_CUSTOM
  127. {&cam_custom_hw_sub_module_init, &cam_custom_hw_sub_module_exit},
  128. {&cam_custom_csid_driver_init, &cam_custom_csid_driver_exit},
  129. {&cam_custom_dev_init_module, &cam_custom_dev_exit_module},
  130. #endif
  131. };
  132. static const struct camera_submodule submodule_table[] = {
  133. {
  134. .name = "Camera BASE",
  135. .num_component = ARRAY_SIZE(camera_base),
  136. .component = camera_base,
  137. },
  138. {
  139. .name = "Camera ISP",
  140. .num_component = ARRAY_SIZE(camera_isp),
  141. .component = camera_isp,
  142. },
  143. {
  144. .name = "Camera TFE",
  145. .num_component = ARRAY_SIZE(camera_tfe),
  146. .component = camera_tfe,
  147. },
  148. {
  149. .name = "Camera SENSOR",
  150. .num_component = ARRAY_SIZE(camera_sensor),
  151. .component = camera_sensor
  152. },
  153. {
  154. .name = "Camera ICP",
  155. .num_component = ARRAY_SIZE(camera_icp),
  156. .component = camera_icp,
  157. },
  158. {
  159. .name = "Camera OPE",
  160. .num_component = ARRAY_SIZE(camera_ope),
  161. .component = camera_ope,
  162. },
  163. {
  164. .name = "Camera JPEG",
  165. .num_component = ARRAY_SIZE(camera_jpeg),
  166. .component = camera_jpeg,
  167. },
  168. {
  169. .name = "Camera FD",
  170. .num_component = ARRAY_SIZE(camera_fd),
  171. .component = camera_fd,
  172. },
  173. {
  174. .name = "Camera LRME",
  175. .num_component = ARRAY_SIZE(camera_lrme),
  176. .component = camera_lrme,
  177. },
  178. {
  179. .name = "Camera CUSTOM",
  180. .num_component = ARRAY_SIZE(camera_custom),
  181. .component = camera_custom,
  182. }
  183. };
  184. /*
  185. * Drivers to be bound by component framework in this order with
  186. * CRM as master
  187. */
  188. static struct platform_driver *const cam_component_drivers[] = {
  189. /* BASE */
  190. &cam_sync_driver,
  191. &cam_smmu_driver,
  192. &cam_cpas_driver,
  193. &cam_cdm_intf_driver,
  194. &cam_hw_cdm_driver,
  195. #ifdef CONFIG_SPECTRA_ISP
  196. &cam_top_tpg_driver,
  197. &cam_ife_csid17x_driver,
  198. &cam_ife_csid_lite_driver,
  199. &cam_vfe_driver,
  200. &isp_driver,
  201. #endif
  202. #ifdef CONFIG_SPECTRA_TFE
  203. &cam_top_tpg_driver,
  204. &cam_tfe_driver,
  205. &cam_tfe_csid530_driver,
  206. #endif
  207. #ifdef CONFIG_SPECTRA_SENSOR
  208. &cam_res_mgr_driver,
  209. &cci_driver,
  210. &csiphy_driver,
  211. &cam_actuator_platform_driver,
  212. &cam_sensor_platform_driver,
  213. &cam_eeprom_platform_driver,
  214. &cam_ois_platform_driver,
  215. #if IS_REACHABLE(CONFIG_LEDS_QPNP_FLASH_V2)
  216. &cam_flash_platform_driver,
  217. #endif
  218. #endif
  219. #ifdef CONFIG_SPECTRA_ICP
  220. &cam_a5_driver,
  221. &cam_ipe_driver,
  222. &cam_bps_driver,
  223. &cam_icp_driver,
  224. #endif
  225. #ifdef CONFIG_SPECTRA_OPE
  226. &cam_ope_driver,
  227. &cam_ope_subdev_driver,
  228. #endif
  229. #ifdef CONFIG_SPECTRA_JPEG
  230. &cam_jpeg_enc_driver,
  231. &cam_jpeg_dma_driver,
  232. &jpeg_driver,
  233. #endif
  234. #ifdef CONFIG_SPECTRA_FD
  235. &cam_fd_hw_driver,
  236. &cam_fd_driver,
  237. #endif
  238. #ifdef CONFIG_SPECTRA_LRME
  239. &cam_lrme_hw_driver,
  240. &cam_lrme_driver,
  241. #endif
  242. #ifdef CONFIG_SPECTRA_CUSTOM
  243. &cam_custom_hw_sub_mod_driver,
  244. &cam_custom_csid_driver,
  245. &custom_driver,
  246. #endif
  247. };
  248. /* Callback to compare device from match list before adding as component */
  249. static int camera_component_compare_dev(struct device *dev, void *data)
  250. {
  251. return dev == data;
  252. }
  253. /* Add component matches to list for master of aggregate driver */
  254. int camera_component_match_add_drivers(struct device *master_dev,
  255. struct component_match **match_list)
  256. {
  257. int i, rc = 0;
  258. struct platform_device *pdev = NULL;
  259. if (!master_dev || !match_list) {
  260. CAM_ERR(CAM_UTIL, "Invalid parameters for component match add");
  261. rc = -EINVAL;
  262. goto end;
  263. }
  264. for (i = 0; i < ARRAY_SIZE(cam_component_drivers); i++) {
  265. struct device_driver *drv = &cam_component_drivers[i]->driver;
  266. struct device *start_dev = NULL, *match_dev;
  267. while ((match_dev = bus_find_device(&platform_bus_type,
  268. start_dev, drv, (void *)platform_bus_type.match))) {
  269. put_device(start_dev);
  270. pdev = to_platform_device(match_dev);
  271. CAM_DBG(CAM_UTIL, "Adding matched component:%s",
  272. pdev->name);
  273. component_match_add(master_dev, match_list,
  274. camera_component_compare_dev, match_dev);
  275. start_dev = match_dev;
  276. }
  277. put_device(start_dev);
  278. }
  279. end:
  280. return rc;
  281. }
  282. static int camera_verify_submodules(void)
  283. {
  284. int rc = 0;
  285. int i, j, num_components;
  286. for (i = 0; i < ARRAY_SIZE(submodule_table); i++) {
  287. num_components = submodule_table[i].num_component;
  288. for (j = 0; j < num_components; j++) {
  289. if (!submodule_table[i].component[j].init ||
  290. !submodule_table[i].component[j].exit) {
  291. CAM_ERR(CAM_UTIL,
  292. "%s module has init = %ps, exit = %ps",
  293. submodule_table[i].name,
  294. submodule_table[i].component[j].init,
  295. submodule_table[i].component[j].exit);
  296. rc = -EINVAL;
  297. goto end;
  298. }
  299. }
  300. }
  301. end:
  302. return rc;
  303. }
  304. static void __camera_exit(int i, int j)
  305. {
  306. uint num_exits;
  307. /* Exit from current submodule */
  308. for (j -= 1; j >= 0; j--)
  309. submodule_table[i].component[j].exit();
  310. /* Exit remaining submodules */
  311. for (i -= 1; i >= 0; i--) {
  312. num_exits = submodule_table[i].num_component;
  313. for (j = num_exits - 1; j >= 0; j--)
  314. submodule_table[i].component[j].exit();
  315. }
  316. }
  317. static int camera_init(void)
  318. {
  319. int rc;
  320. uint i, j, num_inits;
  321. rc = camera_verify_submodules();
  322. if (rc)
  323. goto end_init;
  324. /* For Probing all available submodules */
  325. for (i = 0; i < ARRAY_SIZE(submodule_table); i++) {
  326. num_inits = submodule_table[i].num_component;
  327. CAM_DBG(CAM_UTIL, "Number of %s components: %u",
  328. submodule_table[i].name, num_inits);
  329. for (j = 0; j < num_inits; j++) {
  330. rc = submodule_table[i].component[j].init();
  331. if (rc) {
  332. CAM_ERR(CAM_UTIL,
  333. "%s module failure at %ps rc = %d",
  334. submodule_table[i].name,
  335. submodule_table[i].component[j].init,
  336. rc);
  337. __camera_exit(i, j);
  338. goto end_init;
  339. }
  340. }
  341. }
  342. CAM_INFO(CAM_UTIL, "Spectra camera driver initialized!");
  343. end_init:
  344. return rc;
  345. }
  346. static void camera_exit(void)
  347. {
  348. __camera_exit(ARRAY_SIZE(submodule_table), 0);
  349. CAM_INFO(CAM_UTIL, "Spectra camera driver exited!");
  350. }
  351. module_init(camera_init);
  352. module_exit(camera_exit);
  353. MODULE_DESCRIPTION("Spectra camera driver");
  354. MODULE_LICENSE("GPL v2");