dsi_phy.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2016-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef _DSI_PHY_H_
  7. #define _DSI_PHY_H_
  8. #include "dsi_defs.h"
  9. #include "dsi_clk.h"
  10. #include "dsi_pwr.h"
  11. #include "dsi_phy_hw.h"
  12. #include "dsi_pll.h"
  13. struct dsi_ver_spec_info {
  14. enum dsi_phy_version version;
  15. u32 lane_cfg_count;
  16. u32 strength_cfg_count;
  17. u32 regulator_cfg_count;
  18. u32 timing_cfg_count;
  19. };
  20. /**
  21. * struct dsi_phy_power_info - digital and analog power supplies for DSI PHY
  22. * @digital: Digital power supply for DSI PHY.
  23. * @phy_pwr: Analog power supplies for DSI PHY to work.
  24. */
  25. struct dsi_phy_power_info {
  26. struct dsi_regulator_info digital;
  27. struct dsi_regulator_info phy_pwr;
  28. };
  29. /**
  30. * enum phy_engine_state - define engine status for dsi phy.
  31. * @DSI_PHY_ENGINE_OFF: Engine is turned off.
  32. * @DSI_PHY_ENGINE_ON: Engine is turned on.
  33. * @DSI_PHY_ENGINE_MAX: Maximum value.
  34. */
  35. enum phy_engine_state {
  36. DSI_PHY_ENGINE_OFF = 0,
  37. DSI_PHY_ENGINE_ON,
  38. DSI_PHY_ENGINE_MAX,
  39. };
  40. /**
  41. * enum phy_ulps_return_type - define set_ulps return type for dsi phy.
  42. * @DSI_PHY_ULPS_HANDLED: ulps is handled in phy.
  43. * @DSI_PHY_ULPS_NOT_HANDLED: ulps is not handled in phy.
  44. * @DSI_PHY_ULPS_ERROR: ulps request failed in phy.
  45. */
  46. enum phy_ulps_return_type {
  47. DSI_PHY_ULPS_HANDLED = 0,
  48. DSI_PHY_ULPS_NOT_HANDLED,
  49. DSI_PHY_ULPS_ERROR,
  50. };
  51. /**
  52. * struct msm_dsi_phy - DSI PHY object
  53. * @pdev: Pointer to platform device.
  54. * @index: Instance id.
  55. * @name: Name of the PHY instance.
  56. * @refcount: Reference count.
  57. * @phy_lock: Mutex for hardware and object access.
  58. * @ver_info: Version specific phy parameters.
  59. * @hw: DSI PHY hardware object.
  60. * @pwr_info: Power information.
  61. * @cfg: DSI phy configuration.
  62. * @clk_cb: structure containing call backs for clock control
  63. * @power_state: True if PHY is powered on.
  64. * @dsi_phy_state: PHY state information.
  65. * @mode: Current mode.
  66. * @data_lanes: Number of data lanes used.
  67. * @dst_format: Destination format.
  68. * @pll: Pointer to PLL resource.
  69. * @allow_phy_power_off: True if PHY is allowed to power off when idle
  70. * @regulator_min_datarate_bps: Minimum per lane data rate to turn on regulator
  71. * @regulator_required: True if phy regulator is required
  72. * @dfps_trigger_mdpintf_flush: mdp intf flush controls dfps trigger.
  73. * @dsi_phy_shared: True if phy is shared between dual displays.
  74. */
  75. struct msm_dsi_phy {
  76. struct platform_device *pdev;
  77. int index;
  78. const char *name;
  79. u32 refcount;
  80. struct mutex phy_lock;
  81. const struct dsi_ver_spec_info *ver_info;
  82. struct dsi_phy_hw hw;
  83. struct dsi_phy_power_info pwr_info;
  84. struct dsi_phy_cfg cfg;
  85. struct clk_ctrl_cb clk_cb;
  86. enum phy_engine_state dsi_phy_state;
  87. bool power_state;
  88. struct dsi_mode_info mode;
  89. enum dsi_data_lanes data_lanes;
  90. enum dsi_pixel_format dst_format;
  91. struct dsi_pll_resource *pll;
  92. bool allow_phy_power_off;
  93. u32 regulator_min_datarate_bps;
  94. bool regulator_required;
  95. bool dfps_trigger_mdpintf_flush;
  96. bool dsi_phy_shared;
  97. };
  98. /**
  99. * dsi_phy_check_resource() - check if DSI PHY is probed
  100. * @of_node: of_node of the DSI PHY.
  101. *
  102. * Checks if the DSI PHY has been probed and is available.
  103. *
  104. * Return: status of DSI PHY
  105. */
  106. bool dsi_phy_check_resource(struct device_node *of_node);
  107. /**
  108. * dsi_phy_get() - get a dsi phy handle from device node
  109. * @of_node: device node for dsi phy controller
  110. *
  111. * Gets the DSI PHY handle for the corresponding of_node. The ref count is
  112. * incremented to one all subsequents get will fail until the original client
  113. * calls a put.
  114. *
  115. * Return: DSI PHY handle or an error code.
  116. */
  117. struct msm_dsi_phy *dsi_phy_get(struct device_node *of_node);
  118. /**
  119. * dsi_phy_put() - release dsi phy handle
  120. * @dsi_phy: DSI PHY handle.
  121. *
  122. * Release the DSI PHY hardware. Driver will clean up all resources and puts
  123. * back the DSI PHY into reset state.
  124. */
  125. void dsi_phy_put(struct msm_dsi_phy *dsi_phy);
  126. /**
  127. * dsi_phy_get_version() - returns dsi phy version
  128. * @dsi_phy: DSI PHY handle.
  129. *
  130. * Return: phy version
  131. */
  132. int dsi_phy_get_version(struct msm_dsi_phy *phy);
  133. /**
  134. * dsi_phy_drv_init() - initialize dsi phy driver
  135. * @dsi_phy: DSI PHY handle.
  136. *
  137. * Initializes DSI PHY driver. Should be called after dsi_phy_get().
  138. *
  139. * Return: error code.
  140. */
  141. int dsi_phy_drv_init(struct msm_dsi_phy *dsi_phy);
  142. /**
  143. * dsi_phy_drv_deinit() - de-initialize dsi phy driver
  144. * @dsi_phy: DSI PHY handle.
  145. *
  146. * Release all resources acquired by dsi_phy_drv_init().
  147. *
  148. * Return: error code.
  149. */
  150. int dsi_phy_drv_deinit(struct msm_dsi_phy *dsi_phy);
  151. /**
  152. * dsi_phy_validate_mode() - validate a display mode
  153. * @dsi_phy: DSI PHY handle.
  154. * @mode: Mode information.
  155. *
  156. * Validation will fail if the mode cannot be supported by the PHY driver or
  157. * hardware.
  158. *
  159. * Return: error code.
  160. */
  161. int dsi_phy_validate_mode(struct msm_dsi_phy *dsi_phy,
  162. struct dsi_mode_info *mode);
  163. /**
  164. * dsi_phy_set_power_state() - enable/disable dsi phy power supplies
  165. * @dsi_phy: DSI PHY handle.
  166. * @enable: Boolean flag to enable/disable.
  167. *
  168. * Return: error code.
  169. */
  170. int dsi_phy_set_power_state(struct msm_dsi_phy *dsi_phy, bool enable);
  171. /**
  172. * dsi_phy_enable() - enable DSI PHY hardware
  173. * @dsi_phy: DSI PHY handle.
  174. * @config: DSI host configuration.
  175. * @pll_source: Source PLL for PHY clock.
  176. * @skip_validation: Validation will not be performed on parameters.
  177. * @skip_op: Skip re-enabling dsi phy hw during usecases like
  178. * cont-splash/trusted-vm if set to true.
  179. *
  180. * Validates and enables DSI PHY.
  181. *
  182. * Return: error code.
  183. */
  184. int dsi_phy_enable(struct msm_dsi_phy *dsi_phy,
  185. struct dsi_host_config *config,
  186. enum dsi_phy_pll_source pll_source,
  187. bool skip_validation,
  188. bool skip_op);
  189. /**
  190. * dsi_phy_disable() - disable DSI PHY hardware.
  191. * @phy: DSI PHY handle.
  192. * @skip_op: Skip disabling dsi phy hw during usecases like
  193. * trusted-vm if set to true.
  194. *
  195. * Return: error code.
  196. */
  197. int dsi_phy_disable(struct msm_dsi_phy *phy, bool skip_op);
  198. /**
  199. * dsi_phy_set_ulps() - set ulps state for DSI pHY
  200. * @phy: DSI PHY handle
  201. * @config: DSi host configuration information.
  202. * @enable: Enable/Disable
  203. * @clamp_enabled: mmss_clamp enabled/disabled
  204. *
  205. * Return: error code.
  206. */
  207. int dsi_phy_set_ulps(struct msm_dsi_phy *phy, struct dsi_host_config *config,
  208. bool enable, bool clamp_enabled);
  209. /**
  210. * dsi_phy_clk_cb_register() - Register PHY clock control callback
  211. * @phy: DSI PHY handle
  212. * @clk_cb: Structure containing call back for clock control
  213. *
  214. * Return: error code.
  215. */
  216. int dsi_phy_clk_cb_register(struct msm_dsi_phy *phy,
  217. struct clk_ctrl_cb *clk_cb);
  218. /**
  219. * dsi_phy_idle_ctrl() - enable/disable DSI PHY during idle screen
  220. * @phy: DSI PHY handle
  221. * @enable: boolean to specify PHY enable/disable.
  222. *
  223. * Return: error code.
  224. */
  225. int dsi_phy_idle_ctrl(struct msm_dsi_phy *phy, bool enable);
  226. /**
  227. * dsi_phy_set_clamp_state() - configure clamps for DSI lanes
  228. * @phy: DSI PHY handle.
  229. * @enable: boolean to specify clamp enable/disable.
  230. *
  231. * Return: error code.
  232. */
  233. int dsi_phy_set_clamp_state(struct msm_dsi_phy *phy, bool enable);
  234. /**
  235. * dsi_phy_set_clk_freq() - set DSI PHY clock frequency setting
  236. * @phy: DSI PHY handle
  237. * @clk_freq: link clock frequency
  238. *
  239. * Return: error code.
  240. */
  241. int dsi_phy_set_clk_freq(struct msm_dsi_phy *phy,
  242. struct link_clk_freq *clk_freq);
  243. /**
  244. * dsi_phy_set_timing_params() - timing parameters for the panel
  245. * @phy: DSI PHY handle
  246. * @timing: array holding timing params.
  247. * @size: size of the array.
  248. * @commit: boolean to indicate if programming PHY HW registers is
  249. * required
  250. *
  251. * When PHY timing calculator is not implemented, this array will be used to
  252. * pass PHY timing information.
  253. *
  254. * Return: error code.
  255. */
  256. int dsi_phy_set_timing_params(struct msm_dsi_phy *phy,
  257. u32 *timing, u32 size, bool commit);
  258. /**
  259. * dsi_phy_lane_reset() - Reset DSI PHY lanes in case of error
  260. * @phy: DSI PHY handle
  261. *
  262. * Return: error code.
  263. */
  264. int dsi_phy_lane_reset(struct msm_dsi_phy *phy);
  265. /**
  266. * dsi_phy_toggle_resync_fifo() - toggle resync retime FIFO
  267. * @phy: DSI PHY handle
  268. *
  269. * Toggle the resync retime FIFO to synchronize the data paths.
  270. * This should be done everytime there is a change in the link clock
  271. * rate
  272. */
  273. void dsi_phy_toggle_resync_fifo(struct msm_dsi_phy *phy);
  274. /**
  275. * dsi_phy_reset_clk_en_sel() - reset clk_en_select on cmn_clk_cfg1 register
  276. * @phy: DSI PHY handle
  277. *
  278. * After toggling resync fifo regiater, clk_en_sel bit on cmn_clk_cfg1
  279. * register has to be reset
  280. */
  281. void dsi_phy_reset_clk_en_sel(struct msm_dsi_phy *phy);
  282. /**
  283. * dsi_phy_drv_register() - register platform driver for dsi phy
  284. */
  285. void dsi_phy_drv_register(void);
  286. /**
  287. * dsi_phy_drv_unregister() - unregister platform driver
  288. */
  289. void dsi_phy_drv_unregister(void);
  290. /**
  291. * dsi_phy_update_phy_timings() - Update dsi phy timings
  292. * @phy: DSI PHY handle
  293. * @config: DSI Host config parameters
  294. *
  295. * Return: error code.
  296. */
  297. int dsi_phy_update_phy_timings(struct msm_dsi_phy *phy,
  298. struct dsi_host_config *config);
  299. /**
  300. * dsi_phy_config_dynamic_refresh() - Configure dynamic refresh registers
  301. * @phy: DSI PHY handle
  302. * @delay: pipe delays for dynamic refresh
  303. * @is_master: Boolean to indicate if for master or slave
  304. */
  305. void dsi_phy_config_dynamic_refresh(struct msm_dsi_phy *phy,
  306. struct dsi_dyn_clk_delay *delay,
  307. bool is_master);
  308. /**
  309. * dsi_phy_dynamic_refresh_trigger_sel() - dynamic refresh trigger select.
  310. * @phy: DSI PHY handle
  311. * @is_master: Boolean to indicate if for master or slave.
  312. */
  313. void dsi_phy_dynamic_refresh_trigger_sel(struct msm_dsi_phy *phy,
  314. bool is_master);
  315. /**
  316. * dsi_phy_dynamic_refresh_trigger() - trigger dynamic refresh
  317. * @phy: DSI PHY handle
  318. * @is_master: Boolean to indicate if for master or slave.
  319. */
  320. void dsi_phy_dynamic_refresh_trigger(struct msm_dsi_phy *phy, bool is_master);
  321. /**
  322. * dsi_phy_dynamic_refresh_clear() - clear dynamic refresh config
  323. * @phy: DSI PHY handle
  324. */
  325. void dsi_phy_dynamic_refresh_clear(struct msm_dsi_phy *phy);
  326. /**
  327. * dsi_phy_dyn_refresh_cache_phy_timings - cache the phy timings calculated
  328. * as part of dynamic refresh.
  329. * @phy: DSI PHY Handle.
  330. * @dst: Pointer to cache location.
  331. * @size: Number of phy lane settings.
  332. */
  333. int dsi_phy_dyn_refresh_cache_phy_timings(struct msm_dsi_phy *phy, u32 *dst,
  334. u32 size);
  335. /**
  336. * dsi_phy_set_continuous_clk() - API to set/unset force clock lane HS request.
  337. * @phy: DSI PHY Handle.
  338. * @enable: variable to control continuous clock.
  339. */
  340. void dsi_phy_set_continuous_clk(struct msm_dsi_phy *phy, bool enable);
  341. /**
  342. * dsi_phy_get_io_resources() - reads associated register range
  343. *
  344. * @io_res: pointer to msm_io_res struct to populate the ranges
  345. *
  346. * Return: error code.
  347. */
  348. int dsi_phy_get_io_resources(struct msm_io_res *io_res);
  349. /**
  350. * dsi_phy_configure() - Configure DSI PHY PLL
  351. * @dsi_phy: DSI PHY handle.
  352. * @commit: boolean to specify if calculated PHY configuration
  353. * needs to be committed. Set to false in case of
  354. * dynamic clock switch.
  355. *
  356. * Return: error code.
  357. */
  358. int dsi_phy_configure(struct msm_dsi_phy *dsi_phy, bool commit);
  359. /**
  360. * dsi_phy_pll_toggle() - Toggle DSI PHY PLL
  361. * @dsi_phy: DSI PHY handle.
  362. * @prepare: specifies if PLL needs to be turned on or not.
  363. *
  364. * Return: error code.
  365. */
  366. int dsi_phy_pll_toggle(struct msm_dsi_phy *dsi_phy, bool prepare);
  367. /**
  368. * dsi_phy_dynclk_configure() - Configure DSI PHY PLL during dynamic clock
  369. * @dsi_phy: DSI PHY handle.
  370. *
  371. * Return: error code.
  372. */
  373. int dsi_phy_dynclk_configure(struct msm_dsi_phy *phy);
  374. /**
  375. * dsi_phy_pll_parse_dfps_data() - parse dfps data for PLL
  376. * @phy: DSI PHY handle
  377. */
  378. void dsi_phy_pll_parse_dfps_data(struct msm_dsi_phy *phy);
  379. #endif /* _DSI_PHY_H_ */