dsi_catalog.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2015-2021, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/errno.h>
  6. #include "dsi_catalog.h"
  7. /**
  8. * dsi_catalog_cmn_init() - catalog init for dsi controller v1.4
  9. */
  10. static void dsi_catalog_cmn_init(struct dsi_ctrl_hw *ctrl,
  11. enum dsi_ctrl_version version)
  12. {
  13. /* common functions */
  14. ctrl->ops.host_setup = dsi_ctrl_hw_cmn_host_setup;
  15. ctrl->ops.video_engine_en = dsi_ctrl_hw_cmn_video_engine_en;
  16. ctrl->ops.video_engine_setup = dsi_ctrl_hw_cmn_video_engine_setup;
  17. ctrl->ops.set_video_timing = dsi_ctrl_hw_cmn_set_video_timing;
  18. ctrl->ops.set_timing_db = dsi_ctrl_hw_cmn_set_timing_db;
  19. ctrl->ops.cmd_engine_setup = dsi_ctrl_hw_cmn_cmd_engine_setup;
  20. ctrl->ops.setup_cmd_stream = dsi_ctrl_hw_cmn_setup_cmd_stream;
  21. ctrl->ops.ctrl_en = dsi_ctrl_hw_cmn_ctrl_en;
  22. ctrl->ops.cmd_engine_en = dsi_ctrl_hw_cmn_cmd_engine_en;
  23. ctrl->ops.phy_sw_reset = dsi_ctrl_hw_cmn_phy_sw_reset;
  24. ctrl->ops.soft_reset = dsi_ctrl_hw_cmn_soft_reset;
  25. ctrl->ops.kickoff_command = dsi_ctrl_hw_cmn_kickoff_command;
  26. ctrl->ops.kickoff_fifo_command = dsi_ctrl_hw_cmn_kickoff_fifo_command;
  27. ctrl->ops.reset_cmd_fifo = dsi_ctrl_hw_cmn_reset_cmd_fifo;
  28. ctrl->ops.trigger_command_dma = dsi_ctrl_hw_cmn_trigger_command_dma;
  29. ctrl->ops.get_interrupt_status = dsi_ctrl_hw_cmn_get_interrupt_status;
  30. ctrl->ops.poll_dma_status = dsi_ctrl_hw_cmn_poll_dma_status;
  31. ctrl->ops.get_error_status = dsi_ctrl_hw_cmn_get_error_status;
  32. ctrl->ops.clear_error_status = dsi_ctrl_hw_cmn_clear_error_status;
  33. ctrl->ops.clear_interrupt_status =
  34. dsi_ctrl_hw_cmn_clear_interrupt_status;
  35. ctrl->ops.enable_status_interrupts =
  36. dsi_ctrl_hw_cmn_enable_status_interrupts;
  37. ctrl->ops.enable_error_interrupts =
  38. dsi_ctrl_hw_cmn_enable_error_interrupts;
  39. ctrl->ops.video_test_pattern_setup =
  40. dsi_ctrl_hw_cmn_video_test_pattern_setup;
  41. ctrl->ops.cmd_test_pattern_setup =
  42. dsi_ctrl_hw_cmn_cmd_test_pattern_setup;
  43. ctrl->ops.test_pattern_enable = dsi_ctrl_hw_cmn_test_pattern_enable;
  44. ctrl->ops.trigger_cmd_test_pattern =
  45. dsi_ctrl_hw_cmn_trigger_cmd_test_pattern;
  46. ctrl->ops.clear_phy0_ln_err = dsi_ctrl_hw_dln0_phy_err;
  47. ctrl->ops.phy_reset_config = dsi_ctrl_hw_cmn_phy_reset_config;
  48. ctrl->ops.setup_misr = dsi_ctrl_hw_cmn_setup_misr;
  49. ctrl->ops.collect_misr = dsi_ctrl_hw_cmn_collect_misr;
  50. ctrl->ops.get_cmd_read_data = dsi_ctrl_hw_cmn_get_cmd_read_data;
  51. ctrl->ops.clear_rdbk_register = dsi_ctrl_hw_cmn_clear_rdbk_reg;
  52. ctrl->ops.ctrl_reset = dsi_ctrl_hw_cmn_ctrl_reset;
  53. ctrl->ops.mask_error_intr = dsi_ctrl_hw_cmn_mask_error_intr;
  54. ctrl->ops.error_intr_ctrl = dsi_ctrl_hw_cmn_error_intr_ctrl;
  55. ctrl->ops.get_error_mask = dsi_ctrl_hw_cmn_get_error_mask;
  56. ctrl->ops.get_hw_version = dsi_ctrl_hw_cmn_get_hw_version;
  57. ctrl->ops.wait_for_cmd_mode_mdp_idle =
  58. dsi_ctrl_hw_cmn_wait_for_cmd_mode_mdp_idle;
  59. ctrl->ops.setup_avr = dsi_ctrl_hw_cmn_setup_avr;
  60. ctrl->ops.set_continuous_clk = dsi_ctrl_hw_cmn_set_continuous_clk;
  61. ctrl->ops.wait4dynamic_refresh_done =
  62. dsi_ctrl_hw_cmn_wait4dynamic_refresh_done;
  63. ctrl->ops.hs_req_sel = dsi_ctrl_hw_cmn_hs_req_sel;
  64. ctrl->ops.vid_engine_busy = dsi_ctrl_hw_cmn_vid_engine_busy;
  65. switch (version) {
  66. case DSI_CTRL_VERSION_1_4:
  67. ctrl->ops.setup_lane_map = dsi_ctrl_hw_14_setup_lane_map;
  68. ctrl->ops.ulps_ops.ulps_request = dsi_ctrl_hw_cmn_ulps_request;
  69. ctrl->ops.ulps_ops.ulps_exit = dsi_ctrl_hw_cmn_ulps_exit;
  70. ctrl->ops.wait_for_lane_idle =
  71. dsi_ctrl_hw_14_wait_for_lane_idle;
  72. ctrl->ops.ulps_ops.get_lanes_in_ulps =
  73. dsi_ctrl_hw_cmn_get_lanes_in_ulps;
  74. ctrl->ops.clamp_enable = dsi_ctrl_hw_14_clamp_enable;
  75. ctrl->ops.clamp_disable = dsi_ctrl_hw_14_clamp_disable;
  76. ctrl->ops.reg_dump_to_buffer =
  77. dsi_ctrl_hw_14_reg_dump_to_buffer;
  78. ctrl->ops.schedule_dma_cmd = NULL;
  79. ctrl->ops.kickoff_command_non_embedded_mode = NULL;
  80. ctrl->ops.config_clk_gating = NULL;
  81. ctrl->ops.configure_cmddma_window = NULL;
  82. ctrl->ops.reset_trig_ctrl = NULL;
  83. ctrl->ops.log_line_count = NULL;
  84. ctrl->ops.splitlink_cmd_setup = NULL;
  85. break;
  86. case DSI_CTRL_VERSION_2_0:
  87. ctrl->ops.setup_lane_map = dsi_ctrl_hw_20_setup_lane_map;
  88. ctrl->ops.wait_for_lane_idle =
  89. dsi_ctrl_hw_20_wait_for_lane_idle;
  90. ctrl->ops.reg_dump_to_buffer =
  91. dsi_ctrl_hw_20_reg_dump_to_buffer;
  92. ctrl->ops.ulps_ops.ulps_request = NULL;
  93. ctrl->ops.ulps_ops.ulps_exit = NULL;
  94. ctrl->ops.ulps_ops.get_lanes_in_ulps = NULL;
  95. ctrl->ops.clamp_enable = NULL;
  96. ctrl->ops.clamp_disable = NULL;
  97. ctrl->ops.schedule_dma_cmd = NULL;
  98. ctrl->ops.kickoff_command_non_embedded_mode = NULL;
  99. ctrl->ops.config_clk_gating = NULL;
  100. ctrl->ops.configure_cmddma_window = NULL;
  101. ctrl->ops.reset_trig_ctrl = NULL;
  102. ctrl->ops.log_line_count = NULL;
  103. ctrl->ops.splitlink_cmd_setup = NULL;
  104. break;
  105. case DSI_CTRL_VERSION_2_2:
  106. case DSI_CTRL_VERSION_2_3:
  107. case DSI_CTRL_VERSION_2_4:
  108. case DSI_CTRL_VERSION_2_5:
  109. case DSI_CTRL_VERSION_2_6:
  110. ctrl->ops.phy_reset_config = dsi_ctrl_hw_22_phy_reset_config;
  111. ctrl->ops.config_clk_gating = dsi_ctrl_hw_22_config_clk_gating;
  112. ctrl->ops.setup_lane_map = dsi_ctrl_hw_22_setup_lane_map;
  113. ctrl->ops.wait_for_lane_idle =
  114. dsi_ctrl_hw_22_wait_for_lane_idle;
  115. ctrl->ops.reg_dump_to_buffer =
  116. dsi_ctrl_hw_22_reg_dump_to_buffer;
  117. ctrl->ops.ulps_ops.ulps_request = dsi_ctrl_hw_cmn_ulps_request;
  118. ctrl->ops.ulps_ops.ulps_exit = dsi_ctrl_hw_cmn_ulps_exit;
  119. ctrl->ops.ulps_ops.get_lanes_in_ulps =
  120. dsi_ctrl_hw_cmn_get_lanes_in_ulps;
  121. ctrl->ops.clamp_enable = NULL;
  122. ctrl->ops.clamp_disable = NULL;
  123. ctrl->ops.schedule_dma_cmd = dsi_ctrl_hw_22_schedule_dma_cmd;
  124. ctrl->ops.kickoff_command_non_embedded_mode =
  125. dsi_ctrl_hw_kickoff_non_embedded_mode;
  126. ctrl->ops.configure_cmddma_window =
  127. dsi_ctrl_hw_22_configure_cmddma_window;
  128. ctrl->ops.reset_trig_ctrl =
  129. dsi_ctrl_hw_22_reset_trigger_controls;
  130. ctrl->ops.log_line_count = dsi_ctrl_hw_22_log_line_count;
  131. ctrl->ops.splitlink_cmd_setup = dsi_ctrl_hw_22_configure_splitlink;
  132. break;
  133. default:
  134. break;
  135. }
  136. }
  137. /**
  138. * dsi_catalog_ctrl_setup() - return catalog info for dsi controller
  139. * @ctrl: Pointer to DSI controller hw object.
  140. * @version: DSI controller version.
  141. * @index: DSI controller instance ID.
  142. * @phy_isolation_enabled: DSI controller works isolated from phy.
  143. * @null_insertion_enabled: DSI controller inserts null packet.
  144. *
  145. * This function setups the catalog information in the dsi_ctrl_hw object.
  146. *
  147. * return: error code for failure and 0 for success.
  148. */
  149. int dsi_catalog_ctrl_setup(struct dsi_ctrl_hw *ctrl,
  150. enum dsi_ctrl_version version, u32 index,
  151. bool phy_isolation_enabled, bool null_insertion_enabled)
  152. {
  153. int rc = 0;
  154. if (version == DSI_CTRL_VERSION_UNKNOWN ||
  155. version >= DSI_CTRL_VERSION_MAX) {
  156. DSI_ERR("Unsupported version: %d\n", version);
  157. return -ENOTSUPP;
  158. }
  159. ctrl->index = index;
  160. ctrl->null_insertion_enabled = null_insertion_enabled;
  161. set_bit(DSI_CTRL_VIDEO_TPG, ctrl->feature_map);
  162. set_bit(DSI_CTRL_CMD_TPG, ctrl->feature_map);
  163. set_bit(DSI_CTRL_VARIABLE_REFRESH_RATE, ctrl->feature_map);
  164. set_bit(DSI_CTRL_DYNAMIC_REFRESH, ctrl->feature_map);
  165. set_bit(DSI_CTRL_DESKEW_CALIB, ctrl->feature_map);
  166. set_bit(DSI_CTRL_DPHY, ctrl->feature_map);
  167. switch (version) {
  168. case DSI_CTRL_VERSION_1_4:
  169. dsi_catalog_cmn_init(ctrl, version);
  170. break;
  171. case DSI_CTRL_VERSION_2_0:
  172. case DSI_CTRL_VERSION_2_2:
  173. case DSI_CTRL_VERSION_2_3:
  174. case DSI_CTRL_VERSION_2_4:
  175. ctrl->phy_isolation_enabled = phy_isolation_enabled;
  176. dsi_catalog_cmn_init(ctrl, version);
  177. break;
  178. case DSI_CTRL_VERSION_2_5:
  179. case DSI_CTRL_VERSION_2_6:
  180. ctrl->widebus_support = true;
  181. ctrl->phy_isolation_enabled = phy_isolation_enabled;
  182. dsi_catalog_cmn_init(ctrl, version);
  183. break;
  184. default:
  185. return -ENOTSUPP;
  186. }
  187. return rc;
  188. }
  189. /**
  190. * dsi_catalog_phy_2_0_init() - catalog init for DSI PHY 14nm
  191. */
  192. static void dsi_catalog_phy_2_0_init(struct dsi_phy_hw *phy)
  193. {
  194. phy->ops.regulator_enable = dsi_phy_hw_v2_0_regulator_enable;
  195. phy->ops.regulator_disable = dsi_phy_hw_v2_0_regulator_disable;
  196. phy->ops.enable = dsi_phy_hw_v2_0_enable;
  197. phy->ops.disable = dsi_phy_hw_v2_0_disable;
  198. phy->ops.calculate_timing_params =
  199. dsi_phy_hw_calculate_timing_params;
  200. phy->ops.phy_idle_on = dsi_phy_hw_v2_0_idle_on;
  201. phy->ops.phy_idle_off = dsi_phy_hw_v2_0_idle_off;
  202. phy->ops.calculate_timing_params =
  203. dsi_phy_hw_calculate_timing_params;
  204. phy->ops.phy_timing_val = dsi_phy_hw_timing_val_v2_0;
  205. phy->ops.clamp_ctrl = dsi_phy_hw_v2_0_clamp_ctrl;
  206. phy->ops.dyn_refresh_ops.dyn_refresh_config =
  207. dsi_phy_hw_v2_0_dyn_refresh_config;
  208. phy->ops.dyn_refresh_ops.dyn_refresh_pipe_delay =
  209. dsi_phy_hw_v2_0_dyn_refresh_pipe_delay;
  210. phy->ops.dyn_refresh_ops.dyn_refresh_helper =
  211. dsi_phy_hw_v2_0_dyn_refresh_helper;
  212. phy->ops.dyn_refresh_ops.dyn_refresh_trigger_sel = NULL;
  213. phy->ops.dyn_refresh_ops.cache_phy_timings =
  214. dsi_phy_hw_v2_0_cache_phy_timings;
  215. }
  216. /**
  217. * dsi_catalog_phy_3_0_init() - catalog init for DSI PHY 10nm
  218. */
  219. static void dsi_catalog_phy_3_0_init(struct dsi_phy_hw *phy)
  220. {
  221. phy->ops.regulator_enable = dsi_phy_hw_v3_0_regulator_enable;
  222. phy->ops.regulator_disable = dsi_phy_hw_v3_0_regulator_disable;
  223. phy->ops.enable = dsi_phy_hw_v3_0_enable;
  224. phy->ops.disable = dsi_phy_hw_v3_0_disable;
  225. phy->ops.calculate_timing_params =
  226. dsi_phy_hw_calculate_timing_params;
  227. phy->ops.ulps_ops.wait_for_lane_idle =
  228. dsi_phy_hw_v3_0_wait_for_lane_idle;
  229. phy->ops.ulps_ops.ulps_request =
  230. dsi_phy_hw_v3_0_ulps_request;
  231. phy->ops.ulps_ops.ulps_exit =
  232. dsi_phy_hw_v3_0_ulps_exit;
  233. phy->ops.ulps_ops.get_lanes_in_ulps =
  234. dsi_phy_hw_v3_0_get_lanes_in_ulps;
  235. phy->ops.ulps_ops.is_lanes_in_ulps =
  236. dsi_phy_hw_v3_0_is_lanes_in_ulps;
  237. phy->ops.phy_timing_val = dsi_phy_hw_timing_val_v3_0;
  238. phy->ops.clamp_ctrl = dsi_phy_hw_v3_0_clamp_ctrl;
  239. phy->ops.phy_lane_reset = dsi_phy_hw_v3_0_lane_reset;
  240. phy->ops.toggle_resync_fifo = dsi_phy_hw_v3_0_toggle_resync_fifo;
  241. phy->ops.dyn_refresh_ops.dyn_refresh_config =
  242. dsi_phy_hw_v3_0_dyn_refresh_config;
  243. phy->ops.dyn_refresh_ops.dyn_refresh_pipe_delay =
  244. dsi_phy_hw_v3_0_dyn_refresh_pipe_delay;
  245. phy->ops.dyn_refresh_ops.dyn_refresh_helper =
  246. dsi_phy_hw_v3_0_dyn_refresh_helper;
  247. phy->ops.dyn_refresh_ops.dyn_refresh_trigger_sel = NULL;
  248. phy->ops.dyn_refresh_ops.cache_phy_timings =
  249. dsi_phy_hw_v3_0_cache_phy_timings;
  250. }
  251. /**
  252. * dsi_catalog_phy_4_0_init() - catalog init for DSI PHY 7nm
  253. */
  254. static void dsi_catalog_phy_4_0_init(struct dsi_phy_hw *phy)
  255. {
  256. phy->ops.regulator_enable = NULL;
  257. phy->ops.regulator_disable = NULL;
  258. phy->ops.enable = dsi_phy_hw_v4_0_enable;
  259. phy->ops.disable = dsi_phy_hw_v4_0_disable;
  260. phy->ops.calculate_timing_params =
  261. dsi_phy_hw_calculate_timing_params;
  262. phy->ops.ulps_ops.wait_for_lane_idle =
  263. dsi_phy_hw_v4_0_wait_for_lane_idle;
  264. phy->ops.ulps_ops.ulps_request =
  265. dsi_phy_hw_v4_0_ulps_request;
  266. phy->ops.ulps_ops.ulps_exit =
  267. dsi_phy_hw_v4_0_ulps_exit;
  268. phy->ops.ulps_ops.get_lanes_in_ulps =
  269. dsi_phy_hw_v4_0_get_lanes_in_ulps;
  270. phy->ops.ulps_ops.is_lanes_in_ulps =
  271. dsi_phy_hw_v4_0_is_lanes_in_ulps;
  272. phy->ops.phy_timing_val = dsi_phy_hw_timing_val_v4_0;
  273. phy->ops.phy_lane_reset = dsi_phy_hw_v4_0_lane_reset;
  274. phy->ops.toggle_resync_fifo = dsi_phy_hw_v4_0_toggle_resync_fifo;
  275. phy->ops.reset_clk_en_sel = dsi_phy_hw_v4_0_reset_clk_en_sel;
  276. phy->ops.dyn_refresh_ops.dyn_refresh_config =
  277. dsi_phy_hw_v4_0_dyn_refresh_config;
  278. phy->ops.dyn_refresh_ops.dyn_refresh_pipe_delay =
  279. dsi_phy_hw_v4_0_dyn_refresh_pipe_delay;
  280. phy->ops.dyn_refresh_ops.dyn_refresh_helper =
  281. dsi_phy_hw_v4_0_dyn_refresh_helper;
  282. phy->ops.dyn_refresh_ops.dyn_refresh_trigger_sel =
  283. dsi_phy_hw_v4_0_dyn_refresh_trigger_sel;
  284. phy->ops.dyn_refresh_ops.cache_phy_timings =
  285. dsi_phy_hw_v4_0_cache_phy_timings;
  286. phy->ops.set_continuous_clk = dsi_phy_hw_v4_0_set_continuous_clk;
  287. phy->ops.commit_phy_timing = dsi_phy_hw_v4_0_commit_phy_timing;
  288. }
  289. /**
  290. * dsi_catalog_phy_setup() - return catalog info for dsi phy hardware
  291. * @ctrl: Pointer to DSI PHY hw object.
  292. * @version: DSI PHY version.
  293. * @index: DSI PHY instance ID.
  294. *
  295. * This function setups the catalog information in the dsi_phy_hw object.
  296. *
  297. * return: error code for failure and 0 for success.
  298. */
  299. int dsi_catalog_phy_setup(struct dsi_phy_hw *phy,
  300. enum dsi_phy_version version,
  301. u32 index)
  302. {
  303. int rc = 0;
  304. if (version == DSI_PHY_VERSION_UNKNOWN ||
  305. version >= DSI_PHY_VERSION_MAX) {
  306. DSI_ERR("Unsupported version: %d\n", version);
  307. return -ENOTSUPP;
  308. }
  309. phy->index = index;
  310. phy->version = version;
  311. set_bit(DSI_PHY_DPHY, phy->feature_map);
  312. dsi_phy_timing_calc_init(phy, version);
  313. switch (version) {
  314. case DSI_PHY_VERSION_2_0:
  315. dsi_catalog_phy_2_0_init(phy);
  316. break;
  317. case DSI_PHY_VERSION_3_0:
  318. dsi_catalog_phy_3_0_init(phy);
  319. break;
  320. case DSI_PHY_VERSION_4_0:
  321. case DSI_PHY_VERSION_4_1:
  322. case DSI_PHY_VERSION_4_2:
  323. case DSI_PHY_VERSION_4_3:
  324. dsi_catalog_phy_4_0_init(phy);
  325. break;
  326. case DSI_PHY_VERSION_0_0_HPM:
  327. case DSI_PHY_VERSION_0_0_LPM:
  328. case DSI_PHY_VERSION_1_0:
  329. default:
  330. return -ENOTSUPP;
  331. }
  332. return rc;
  333. }
  334. int dsi_catalog_phy_pll_setup(struct dsi_phy_hw *phy, u32 pll_ver)
  335. {
  336. int rc = 0;
  337. if (pll_ver >= DSI_PLL_VERSION_UNKNOWN) {
  338. DSI_ERR("Unsupported version: %d\n", pll_ver);
  339. return -EOPNOTSUPP;
  340. }
  341. switch (pll_ver) {
  342. case DSI_PLL_VERSION_5NM:
  343. phy->ops.configure = dsi_pll_5nm_configure;
  344. phy->ops.pll_toggle = dsi_pll_5nm_toggle;
  345. break;
  346. default:
  347. phy->ops.configure = NULL;
  348. phy->ops.pll_toggle = NULL;
  349. break;
  350. }
  351. return rc;
  352. }