dsi_clk.h 10 KB

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