dsi_clk.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2016-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2021-2023, Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef _DSI_CLK_H_
  7. #define _DSI_CLK_H_
  8. #include <linux/device.h>
  9. #include <linux/platform_device.h>
  10. #include <linux/types.h>
  11. #include <linux/clk.h>
  12. #define MAX_STRING_LEN 32
  13. #define MAX_DSI_CTRL 2
  14. enum dsi_clk_state {
  15. DSI_CLK_OFF,
  16. DSI_CLK_ON,
  17. DSI_CLK_EARLY_GATE,
  18. };
  19. enum clk_req_client {
  20. DSI_CLK_REQ_MDP_CLIENT = 0,
  21. DSI_CLK_REQ_DSI_CLIENT,
  22. };
  23. enum dsi_link_clk_type {
  24. DSI_LINK_ESC_CLK,
  25. DSI_LINK_BYTE_CLK,
  26. DSI_LINK_PIX_CLK,
  27. DSI_LINK_BYTE_INTF_CLK,
  28. DSI_LINK_CLK_MAX,
  29. };
  30. enum dsi_link_clk_op_type {
  31. DSI_LINK_CLK_SET_RATE = BIT(0),
  32. DSI_LINK_CLK_PREPARE = BIT(1),
  33. DSI_LINK_CLK_ENABLE = BIT(2),
  34. DSI_LINK_CLK_START = BIT(0) | BIT(1) | BIT(2),
  35. };
  36. enum dsi_clk_type {
  37. DSI_CORE_CLK = BIT(0),
  38. DSI_LINK_CLK = BIT(1),
  39. DSI_ALL_CLKS = (BIT(0) | BIT(1)),
  40. DSI_CLKS_MAX = BIT(2),
  41. };
  42. enum dsi_lclk_type {
  43. DSI_LINK_NONE = 0,
  44. DSI_LINK_LP_CLK = BIT(0),
  45. DSI_LINK_HS_CLK = BIT(1),
  46. };
  47. struct dsi_clk_ctrl_info {
  48. enum dsi_clk_type clk_type;
  49. enum dsi_clk_state clk_state;
  50. enum clk_req_client client;
  51. };
  52. struct clk_ctrl_cb {
  53. void *priv;
  54. int (*dsi_clk_cb)(void *priv, struct dsi_clk_ctrl_info clk_ctrl_info);
  55. };
  56. /**
  57. * struct dsi_core_clk_info - Core clock information for DSI hardware
  58. * @mdp_core_clk: Handle to MDP core clock.
  59. * @iface_clk: Handle to MDP interface clock.
  60. * @core_mmss_clk: Handle to MMSS core clock.
  61. * @bus_clk: Handle to bus clock.
  62. * @mnoc_clk: Handle to MMSS NOC clock.
  63. * @drm: Pointer to drm device node
  64. */
  65. struct dsi_core_clk_info {
  66. struct clk *mdp_core_clk;
  67. struct clk *iface_clk;
  68. struct clk *core_mmss_clk;
  69. struct clk *bus_clk;
  70. struct clk *mnoc_clk;
  71. struct drm_device *drm;
  72. };
  73. /**
  74. * struct dsi_link_hs_clk_info - Set of high speed link clocks for DSI HW
  75. * @byte_clk: Handle to DSI byte_clk.
  76. * @pixel_clk: Handle to DSI pixel_clk.
  77. * @byte_intf_clk: Handle to DSI byte intf. clock.
  78. */
  79. struct dsi_link_hs_clk_info {
  80. struct clk *byte_clk;
  81. struct clk *pixel_clk;
  82. struct clk *byte_intf_clk;
  83. };
  84. /**
  85. * struct dsi_link_lp_clk_info - Set of low power link clocks for DSI HW.
  86. * @esc_clk: Handle to DSI escape clock.
  87. */
  88. struct dsi_link_lp_clk_info {
  89. struct clk *esc_clk;
  90. };
  91. /**
  92. * struct link_clk_freq - Clock frequency information for Link clocks
  93. * @byte_clk_rate: Frequency of DSI byte_clk in Hz.
  94. * @byte_intf_clk_rate: Frequency of DSI byte_intf_clk in Hz.
  95. * @pixel_clk_rate: Frequency of DSI pixel_clk in Hz.
  96. * @esc_clk_rate: Frequency of DSI escape clock in Hz.
  97. */
  98. struct link_clk_freq {
  99. u32 byte_clk_rate;
  100. u32 byte_intf_clk_rate;
  101. u32 pix_clk_rate;
  102. u32 esc_clk_rate;
  103. };
  104. /**
  105. * typedef *pre_clockoff_cb() - Callback before clock is turned off
  106. * @priv: private data pointer.
  107. * @clk_type: clock which is being turned off.
  108. * @l_type: specifies if the clock is HS or LP type. Valid only for link clocks.
  109. * @new_state: next state for the clock.
  110. *
  111. * @return: error code.
  112. */
  113. typedef int (*pre_clockoff_cb)(void *priv,
  114. enum dsi_clk_type clk_type,
  115. enum dsi_lclk_type l_type,
  116. enum dsi_clk_state new_state);
  117. /**
  118. * typedef *post_clockoff_cb() - Callback after clock is turned off
  119. * @priv: private data pointer.
  120. * @clk_type: clock which was turned off.
  121. * @l_type: specifies if the clock is HS or LP type. Valid only for link clocks.
  122. * @curr_state: current state for the clock.
  123. *
  124. * @return: error code.
  125. */
  126. typedef int (*post_clockoff_cb)(void *priv,
  127. enum dsi_clk_type clk_type,
  128. enum dsi_lclk_type l_type,
  129. enum dsi_clk_state curr_state);
  130. /**
  131. * typedef *post_clockon_cb() - Callback after clock is turned on
  132. * @priv: private data pointer.
  133. * @clk_type: clock which was turned on.
  134. * @l_type: specifies if the clock is HS or LP type. Valid only for link clocks.
  135. * @curr_state: current state for the clock.
  136. *
  137. * @return: error code.
  138. */
  139. typedef int (*post_clockon_cb)(void *priv,
  140. enum dsi_clk_type clk_type,
  141. enum dsi_lclk_type l_type,
  142. enum dsi_clk_state curr_state);
  143. /**
  144. * typedef *pre_clockon_cb() - Callback before clock is turned on
  145. * @priv: private data pointer.
  146. * @clk_type: clock which is being turned on.
  147. * @l_type: specifies if the clock is HS or LP type.Valid only for link clocks.
  148. * @new_state: next state for the clock.
  149. *
  150. * @return: error code.
  151. */
  152. typedef int (*pre_clockon_cb)(void *priv,
  153. enum dsi_clk_type clk_type,
  154. enum dsi_lclk_type l_type,
  155. enum dsi_clk_state new_state);
  156. /**
  157. * typedef *phy_configure_cb() - Callback to configure PHY for PLL clocks
  158. * @priv: private data pointer.
  159. * @commit: boolean to specify if calculated PHY configuration needs to be
  160. * committed. Set to false in case of dynamic clock switch.
  161. *
  162. * @return: error code.
  163. */
  164. typedef int (*phy_configure_cb)(void *priv, bool commit);
  165. /**
  166. * typedef *pll_toggle_cb() - Callback to toggle PHY PLL
  167. * @priv: private data pointer.
  168. * @prepare: specifies if the PLL needs to be turned on or off.
  169. *
  170. * @return: error code.
  171. */
  172. typedef int (*pll_toggle_cb)(void *priv, bool prepare);
  173. /**
  174. * struct dsi_clk_info - clock information for DSI hardware.
  175. * @name: client name.
  176. * @c_clks[MAX_DSI_CTRL] array of core clock configurations
  177. * @l_lp_clks[MAX_DSI_CTRL] array of low power(esc) clock configurations
  178. * @l_hs_clks[MAX_DSI_CTRL] array of high speed clock configurations
  179. * @ctrl_index[MAX_DSI_CTRL] array of DSI controller indexes mapped
  180. * to core and link clock configurations
  181. * @pre_clkoff_cb callback before clock is turned off
  182. * @post_clkoff_cb callback after clock is turned off
  183. * @post_clkon_cb callback after clock is turned on
  184. * @pre_clkon_cb callback before clock is turned on
  185. * @phy_config_cb callback to configure PHY PLL
  186. * @phy_pll_toggle_cb callback to toggle PHY PLL state
  187. * @priv_data pointer to private data
  188. * @master_ndx master DSI controller index
  189. * @dsi_ctrl_count number of DSI controllers
  190. * @phy_pll_bypass bypass PLL clock related operations
  191. */
  192. struct dsi_clk_info {
  193. char name[MAX_STRING_LEN];
  194. struct dsi_core_clk_info c_clks[MAX_DSI_CTRL];
  195. struct dsi_link_lp_clk_info l_lp_clks[MAX_DSI_CTRL];
  196. struct dsi_link_hs_clk_info l_hs_clks[MAX_DSI_CTRL];
  197. u32 ctrl_index[MAX_DSI_CTRL];
  198. pre_clockoff_cb pre_clkoff_cb;
  199. post_clockoff_cb post_clkoff_cb;
  200. post_clockon_cb post_clkon_cb;
  201. pre_clockon_cb pre_clkon_cb;
  202. phy_configure_cb phy_config_cb;
  203. pll_toggle_cb phy_pll_toggle_cb;
  204. void *priv_data;
  205. u32 master_ndx;
  206. u32 dsi_ctrl_count;
  207. bool phy_pll_bypass;
  208. };
  209. /**
  210. * struct dsi_clk_link_set - Pair of clock handles to describe link clocks
  211. * @byte_clk: Handle to DSi byte_clk.
  212. * @pixel_clk: Handle to DSI pixel_clk.
  213. */
  214. struct dsi_clk_link_set {
  215. struct clk *byte_clk;
  216. struct clk *pixel_clk;
  217. };
  218. /**
  219. * dsi_display_clk_mngr_update_splash_status() - Update splash stattus
  220. * @clk_mngr: Structure containing DSI clock information
  221. * @status: Splash status
  222. */
  223. void dsi_display_clk_mngr_update_splash_status(void *clk_mgr, bool status);
  224. /**
  225. * dsi_display_clk_mgr_register() - Register DSI clock manager
  226. * @info: Structure containing DSI clock information
  227. */
  228. void *dsi_display_clk_mngr_register(struct dsi_clk_info *info);
  229. /**
  230. * dsi_display_clk_mngr_deregister() - Deregister DSI clock manager
  231. * @clk_mngr: DSI clock manager pointer
  232. */
  233. int dsi_display_clk_mngr_deregister(void *clk_mngr);
  234. /**
  235. * dsi_register_clk_handle() - Register clock handle with DSI clock manager
  236. * @clk_mngr: DSI clock manager pointer
  237. * @client: DSI clock client pointer.
  238. */
  239. void *dsi_register_clk_handle(void *clk_mngr, char *client);
  240. /**
  241. * dsi_deregister_clk_handle() - Deregister clock handle from DSI clock manager
  242. * @client: DSI clock client pointer.
  243. *
  244. * return: error code in case of failure or 0 for success.
  245. */
  246. int dsi_deregister_clk_handle(void *client);
  247. /**
  248. * dsi_display_link_clk_force_update_ctrl() - force to set link clks
  249. * @handle: Handle of desired DSI clock client.
  250. *
  251. * return: error code in case of failure or 0 for success.
  252. */
  253. int dsi_display_link_clk_force_update_ctrl(void *handle);
  254. /**
  255. * dsi_display_clk_ctrl() - set frequencies for link clks
  256. * @handle: Handle of desired DSI clock client.
  257. * @clk_type: Clock which is being controlled.
  258. * @clk_state: Desired state of clock
  259. *
  260. * return: error code in case of failure or 0 for success.
  261. */
  262. int dsi_display_clk_ctrl(void *handle, u32 clk_type, u32 clk_state);
  263. /**
  264. * dsi_clk_set_link_frequencies() - set frequencies for link clks
  265. * @client: DSI clock client pointer.
  266. * @freq: Structure containing link clock frequencies.
  267. * @index: Index of the DSI controller.
  268. *
  269. * return: error code in case of failure or 0 for success.
  270. */
  271. int dsi_clk_set_link_frequencies(void *client, struct link_clk_freq freq,
  272. u32 index);
  273. /**
  274. * dsi_clk_get_link_frequencies() - get link clk frequencies
  275. * @link_freq: Structure to get link clock frequencies
  276. * @client: DSI clock client pointer.
  277. * @index: Index of the DSI controller.
  278. *
  279. * return: error code in case of failure or 0 for success.
  280. */
  281. int dsi_clk_get_link_frequencies(struct link_clk_freq *link_freq, void *client, u32 index);
  282. /**
  283. * dsi_clk_set_pixel_clk_rate() - set frequency for pixel_clk
  284. * @client: DSI clock client pointer.
  285. * @pixel_clk: Pixel_clk rate in Hz.
  286. * @index: Index of the DSI controller.
  287. * return: error code in case of failure or 0 for success.
  288. */
  289. int dsi_clk_set_pixel_clk_rate(void *client, u64 pixel_clk, u32 index);
  290. /**
  291. * dsi_clk_set_byte_clk_rate() - set frequency for byte clock
  292. * @client: DSI clock client pointer.
  293. * @byte_clk: Pixel clock rate in Hz.
  294. * @byte_intf_clk: Byte interface clock rate in Hz.
  295. * @index: Index of the DSI controller.
  296. * return: error code in case of failure or 0 for success.
  297. */
  298. int dsi_clk_set_byte_clk_rate(void *client, u64 byte_clk,
  299. u64 byte_intf_clk, u32 index);
  300. /**
  301. * dsi_clk_update_parent() - update parent clocks for specified clock
  302. * @parent: link clock pair which are set as parent.
  303. * @child: link clock pair whose parent has to be set.
  304. */
  305. int dsi_clk_update_parent(struct dsi_clk_link_set *parent,
  306. struct dsi_clk_link_set *child);
  307. /**
  308. * dsi_clk_prepare_enable() - prepare and enable dsi src clocks
  309. * @clk: list of src clocks.
  310. *
  311. * @return: Zero on success and err no on failure
  312. */
  313. int dsi_clk_prepare_enable(struct dsi_clk_link_set *clk);
  314. /**
  315. * dsi_clk_disable_unprepare() - disable and unprepare dsi src clocks
  316. * @clk: list of src clocks.
  317. */
  318. void dsi_clk_disable_unprepare(struct dsi_clk_link_set *clk);
  319. /**
  320. * dsi_display_dump_clk_handle_state() - dump client clock state
  321. * @client: DSI clock client pointer.
  322. */
  323. int dsi_display_dump_clk_handle_state(void *client);
  324. /**
  325. * dsi_clk_acquire_mngr_lock() - acquire clk manager mutex lock
  326. * @client: DSI clock client pointer.
  327. */
  328. void dsi_clk_acquire_mngr_lock(void *client);
  329. /**
  330. * dsi_clk_release_mngr_lock() - release clk manager mutex lock
  331. * @client: DSI clock client pointer.
  332. */
  333. void dsi_clk_release_mngr_lock(void *client);
  334. #endif /* _DSI_CLK_H_ */