camera_main.c 9.7 KB

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