dsi_clk.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2016-2020, 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. * struct dsi_clk_info - clock information for DSI hardware.
  157. * @name: client name.
  158. * @c_clks[MAX_DSI_CTRL] array of core clock configurations
  159. * @l_lp_clks[MAX_DSI_CTRL] array of low power(esc) clock configurations
  160. * @l_hs_clks[MAX_DSI_CTRL] array of high speed clock configurations
  161. * @ctrl_index[MAX_DSI_CTRL] array of DSI controller indexes mapped
  162. * to core and link clock configurations
  163. * @pre_clkoff_cb callback before clock is turned off
  164. * @post_clkoff_cb callback after clock is turned off
  165. * @post_clkon_cb callback after clock is turned on
  166. * @pre_clkon_cb callback before clock is turned on
  167. * @priv_data pointer to private data
  168. * @master_ndx master DSI controller index
  169. * @dsi_ctrl_count number of DSI controllers
  170. */
  171. struct dsi_clk_info {
  172. char name[MAX_STRING_LEN];
  173. struct dsi_core_clk_info c_clks[MAX_DSI_CTRL];
  174. struct dsi_link_lp_clk_info l_lp_clks[MAX_DSI_CTRL];
  175. struct dsi_link_hs_clk_info l_hs_clks[MAX_DSI_CTRL];
  176. u32 ctrl_index[MAX_DSI_CTRL];
  177. pre_clockoff_cb pre_clkoff_cb;
  178. post_clockoff_cb post_clkoff_cb;
  179. post_clockon_cb post_clkon_cb;
  180. pre_clockon_cb pre_clkon_cb;
  181. void *priv_data;
  182. u32 master_ndx;
  183. u32 dsi_ctrl_count;
  184. };
  185. /**
  186. * struct dsi_clk_link_set - Pair of clock handles to describe link clocks
  187. * @byte_clk: Handle to DSi byte_clk.
  188. * @pixel_clk: Handle to DSI pixel_clk.
  189. */
  190. struct dsi_clk_link_set {
  191. struct clk *byte_clk;
  192. struct clk *pixel_clk;
  193. };
  194. /**
  195. * dsi_display_clk_mngr_update_splash_status() - Update splash stattus
  196. * @clk_mngr: Structure containing DSI clock information
  197. * @status: Splash status
  198. */
  199. void dsi_display_clk_mngr_update_splash_status(void *clk_mgr, bool status);
  200. /**
  201. * dsi_display_clk_mgr_register() - Register DSI clock manager
  202. * @info: Structure containing DSI clock information
  203. */
  204. void *dsi_display_clk_mngr_register(struct dsi_clk_info *info);
  205. /**
  206. * dsi_display_clk_mngr_deregister() - Deregister DSI clock manager
  207. * @clk_mngr: DSI clock manager pointer
  208. */
  209. int dsi_display_clk_mngr_deregister(void *clk_mngr);
  210. /**
  211. * dsi_register_clk_handle() - Register clock handle with DSI clock manager
  212. * @clk_mngr: DSI clock manager pointer
  213. * @client: DSI clock client pointer.
  214. */
  215. void *dsi_register_clk_handle(void *clk_mngr, char *client);
  216. /**
  217. * dsi_deregister_clk_handle() - Deregister clock handle from DSI clock manager
  218. * @client: DSI clock client pointer.
  219. *
  220. * return: error code in case of failure or 0 for success.
  221. */
  222. int dsi_deregister_clk_handle(void *client);
  223. /**
  224. * dsi_display_link_clk_force_update_ctrl() - force to set link clks
  225. * @handle: Handle of desired DSI clock client.
  226. *
  227. * return: error code in case of failure or 0 for success.
  228. */
  229. int dsi_display_link_clk_force_update_ctrl(void *handle);
  230. /**
  231. * dsi_display_clk_ctrl() - set frequencies for link clks
  232. * @handle: Handle of desired DSI clock client.
  233. * @clk_type: Clock which is being controlled.
  234. * @clk_state: Desired state of clock
  235. *
  236. * return: error code in case of failure or 0 for success.
  237. */
  238. int dsi_display_clk_ctrl(void *handle, u32 clk_type, u32 clk_state);
  239. /**
  240. * dsi_clk_set_link_frequencies() - set frequencies for link clks
  241. * @client: DSI clock client pointer.
  242. * @freq: Structure containing link clock frequencies.
  243. * @index: Index of the DSI controller.
  244. *
  245. * return: error code in case of failure or 0 for success.
  246. */
  247. int dsi_clk_set_link_frequencies(void *client, struct link_clk_freq freq,
  248. u32 index);
  249. /**
  250. * dsi_clk_set_pixel_clk_rate() - set frequency for pixel_clk
  251. * @client: DSI clock client pointer.
  252. * @pixel_clk: Pixel_clk rate in Hz.
  253. * @index: Index of the DSI controller.
  254. * return: error code in case of failure or 0 for success.
  255. */
  256. int dsi_clk_set_pixel_clk_rate(void *client, u64 pixel_clk, u32 index);
  257. /**
  258. * dsi_clk_set_byte_clk_rate() - set frequency for byte clock
  259. * @client: DSI clock client pointer.
  260. * @byte_clk: Pixel clock rate in Hz.
  261. * @byte_intf_clk: Byte interface clock rate in Hz.
  262. * @index: Index of the DSI controller.
  263. * return: error code in case of failure or 0 for success.
  264. */
  265. int dsi_clk_set_byte_clk_rate(void *client, u64 byte_clk,
  266. u64 byte_intf_clk, u32 index);
  267. /**
  268. * dsi_clk_update_parent() - update parent clocks for specified clock
  269. * @parent: link clock pair which are set as parent.
  270. * @child: link clock pair whose parent has to be set.
  271. */
  272. int dsi_clk_update_parent(struct dsi_clk_link_set *parent,
  273. struct dsi_clk_link_set *child);
  274. /**
  275. * dsi_clk_prepare_enable() - prepare and enable dsi src clocks
  276. * @clk: list of src clocks.
  277. *
  278. * @return: Zero on success and err no on failure
  279. */
  280. int dsi_clk_prepare_enable(struct dsi_clk_link_set *clk);
  281. /**
  282. * dsi_clk_disable_unprepare() - disable and unprepare dsi src clocks
  283. * @clk: list of src clocks.
  284. */
  285. void dsi_clk_disable_unprepare(struct dsi_clk_link_set *clk);
  286. /**
  287. * dsi_display_dump_clk_handle_state() - dump client clock state
  288. * @client: DSI clock client pointer.
  289. */
  290. int dsi_display_dump_clk_handle_state(void *client);
  291. #endif /* _DSI_CLK_H_ */