sde_rsc.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2016-2019, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef _SDE_RSC_H_
  6. #define _SDE_RSC_H_
  7. #include <linux/kernel.h>
  8. /* primary display rsc index */
  9. #define SDE_RSC_INDEX 0
  10. #define MAX_RSC_CLIENT_NAME_LEN 128
  11. /* DRM Object IDs are numbered excluding 0, use 0 to indicate invalid CRTC */
  12. #define SDE_RSC_INVALID_CRTC_ID 0
  13. /**
  14. * event will be triggered before sde core power collapse,
  15. * mdss gdsc is still on
  16. */
  17. #define SDE_RSC_EVENT_PRE_CORE_PC 0x1
  18. /**
  19. * event will be triggered after sde core collapse complete,
  20. * mdss gdsc is off now
  21. */
  22. #define SDE_RSC_EVENT_POST_CORE_PC 0x2
  23. /**
  24. * event will be triggered before restoring the sde core from power collapse,
  25. * mdss gdsc is still off
  26. */
  27. #define SDE_RSC_EVENT_PRE_CORE_RESTORE 0x4
  28. /**
  29. * event will be triggered after restoring the sde core from power collapse,
  30. * mdss gdsc is on now
  31. */
  32. #define SDE_RSC_EVENT_POST_CORE_RESTORE 0x8
  33. /**
  34. * event attached with solver state enabled
  35. * all clients in clk_state or cmd_state
  36. */
  37. #define SDE_RSC_EVENT_SOLVER_ENABLED 0x10
  38. /**
  39. * event attached with solver state disabled
  40. * one of the client requested for vid state
  41. */
  42. #define SDE_RSC_EVENT_SOLVER_DISABLED 0x20
  43. /**
  44. * sde_rsc_client_type: sde rsc client type information
  45. * SDE_RSC_PRIMARY_DISP_CLIENT: A primary display client which can request
  46. * vid or cmd state switch.
  47. * SDE_RSC_EXTERNAL_DISPLAY_CLIENT:An external display client which can
  48. * request only clk state switch.
  49. * SDE_RSC_CLK_CLIENT: A clk client request for only rsc clocks
  50. * enabled and mode_2 exit state.
  51. */
  52. enum sde_rsc_client_type {
  53. SDE_RSC_PRIMARY_DISP_CLIENT,
  54. SDE_RSC_EXTERNAL_DISP_CLIENT,
  55. SDE_RSC_CLK_CLIENT,
  56. SDE_RSC_INVALID_CLIENT,
  57. };
  58. /**
  59. * sde_rsc_state: sde rsc state information
  60. * SDE_RSC_IDLE_STATE: A client requests for idle state when there is no
  61. * pixel or cmd transfer expected. An idle vote from
  62. * all clients lead to power collapse state.
  63. * SDE_RSC_CLK_STATE: A client requests for clk state when it wants to
  64. * only avoid mode-2 entry/exit. For ex: V4L2 driver,
  65. * sde power handle, etc.
  66. * SDE_RSC_CMD_STATE: A client requests for cmd state when it wants to
  67. * enable the solver mode.
  68. * SDE_RSC_VID_STATE: A client requests for vid state it wants to avoid
  69. * solver enable because client is fetching data from
  70. * continuously.
  71. */
  72. enum sde_rsc_state {
  73. SDE_RSC_IDLE_STATE,
  74. SDE_RSC_CLK_STATE,
  75. SDE_RSC_CMD_STATE,
  76. SDE_RSC_VID_STATE,
  77. };
  78. /**
  79. * struct sde_rsc_client: stores the rsc client for sde driver
  80. * @name: name of the client
  81. * @current_state: current client state
  82. * @crtc_id: crtc_id associated with this rsc client.
  83. * @rsc_index: rsc index of a client - only index "0" valid.
  84. * @id: Index of client. It will be assigned during client_create call
  85. * @client_type: check sde_rsc_client_type information
  86. * @list: list to attach client master list
  87. */
  88. struct sde_rsc_client {
  89. char name[MAX_RSC_CLIENT_NAME_LEN];
  90. short current_state;
  91. int crtc_id;
  92. u32 rsc_index;
  93. u32 id;
  94. enum sde_rsc_client_type client_type;
  95. struct list_head list;
  96. };
  97. /**
  98. * struct sde_rsc_event: local event registration entry structure
  99. * @cb_func: Pointer to desired callback function
  100. * @usr: User pointer to pass to callback on event trigger
  101. * @rsc_index: rsc index of a client - only index "0" valid.
  102. * @event_type: refer comments in event_register
  103. * @list: list to attach event master list
  104. */
  105. struct sde_rsc_event {
  106. void (*cb_func)(uint32_t event_type, void *usr);
  107. void *usr;
  108. u32 rsc_index;
  109. uint32_t event_type;
  110. struct list_head list;
  111. };
  112. /**
  113. * struct sde_rsc_cmd_config: provides panel configuration to rsc
  114. * when client is command mode. It is not required to set it during
  115. * video mode.
  116. *
  117. * @fps: panel te interval
  118. * @vtotal: current vertical total (height + vbp + vfp)
  119. * @jitter_numer: panel jitter numerator value. This config causes rsc/solver
  120. * early before te. Default is 0.8% jitter.
  121. * @jitter_denom: panel jitter denominator.
  122. * @prefill_lines: max prefill lines based on panel
  123. */
  124. struct sde_rsc_cmd_config {
  125. u32 fps;
  126. u32 vtotal;
  127. u32 jitter_numer;
  128. u32 jitter_denom;
  129. u32 prefill_lines;
  130. };
  131. #ifdef CONFIG_DRM_SDE_RSC
  132. /**
  133. * sde_rsc_client_create() - create the client for sde rsc.
  134. * Different displays like DSI, HDMI, DP, WB, etc should call this
  135. * api to register their vote for rpmh. They still need to vote for
  136. * power handle to get the clocks.
  137. * @rsc_index: A client will be created on this RSC. As of now only
  138. * SDE_RSC_INDEX is valid rsc index.
  139. * @name: Caller needs to provide some valid string to identify
  140. * the client. "primary", "dp", "hdmi" are suggested name.
  141. * @client_type: check client_type enum for information
  142. * @vsync_source: This parameter is only valid for primary display. It provides
  143. * vsync source information
  144. *
  145. * Return: client node pointer.
  146. */
  147. struct sde_rsc_client *sde_rsc_client_create(u32 rsc_index, char *name,
  148. enum sde_rsc_client_type client_type, u32 vsync_source);
  149. /**
  150. * sde_rsc_client_destroy() - Destroy the sde rsc client.
  151. *
  152. * @client: Client pointer provided by sde_rsc_client_create().
  153. *
  154. * Return: none
  155. */
  156. void sde_rsc_client_destroy(struct sde_rsc_client *client);
  157. /**
  158. * sde_rsc_client_state_update() - rsc client state update
  159. * Video mode, cmd mode and clk state are supported as modes. A client need to
  160. * set this property during panel time. A switching client can set the
  161. * property to change the state
  162. *
  163. * @client: Client pointer provided by sde_rsc_client_create().
  164. * @state: Client state - video/cmd
  165. * @config: fps, vtotal, porches, etc configuration for command mode
  166. * panel
  167. * @crtc_id: current client's crtc id
  168. * @wait_vblank_crtc_id: Output parameter. If set to non-zero, rsc hw
  169. * state update requires a wait for one vblank on
  170. * the primary crtc. In that case, this output
  171. * param will be set to the crtc on which to wait.
  172. * If SDE_RSC_INVALID_CRTC_ID, no wait necessary
  173. *
  174. * Return: error code.
  175. */
  176. int sde_rsc_client_state_update(struct sde_rsc_client *client,
  177. enum sde_rsc_state state,
  178. struct sde_rsc_cmd_config *config, int crtc_id,
  179. int *wait_vblank_crtc_id);
  180. /**
  181. * sde_rsc_client_get_vsync_refcount() - returns the status of the vsync
  182. * refcount, to signal if the client needs to reset the refcounting logic
  183. * @client: Client pointer provided by sde_rsc_client_create().
  184. *
  185. * Return: true if the state update has completed.
  186. */
  187. int sde_rsc_client_get_vsync_refcount(
  188. struct sde_rsc_client *caller_client);
  189. /**
  190. * sde_rsc_client_reset_vsync_refcount() - reduces the refcounting
  191. * logic that waits for the vsync.
  192. * @client: Client pointer provided by sde_rsc_client_create().
  193. *
  194. * Return: true if the state update has completed.
  195. */
  196. int sde_rsc_client_reset_vsync_refcount(
  197. struct sde_rsc_client *caller_client);
  198. /**
  199. * sde_rsc_client_is_state_update_complete() - check if state update is complete
  200. * RSC state transition is not complete until HW receives VBLANK signal. This
  201. * function checks RSC HW to determine whether that signal has been received.
  202. * @client: Client pointer provided by sde_rsc_client_create().
  203. *
  204. * Return: true if the state update has completed.
  205. */
  206. bool sde_rsc_client_is_state_update_complete(
  207. struct sde_rsc_client *caller_client);
  208. /**
  209. * sde_rsc_client_vote() - stores ab/ib vote for rsc client
  210. *
  211. * @client: Client pointer provided by sde_rsc_client_create().
  212. * @bus_id: data bus identifier
  213. * @ab: aggregated bandwidth vote from client.
  214. * @ib: instant bandwidth vote from client.
  215. *
  216. * Return: error code.
  217. */
  218. int sde_rsc_client_vote(struct sde_rsc_client *caller_client,
  219. u32 bus_id, u64 ab_vote, u64 ib_vote);
  220. /**
  221. * sde_rsc_register_event - register a callback function for an event
  222. * @rsc_index: A client will be created on this RSC. As of now only
  223. * SDE_RSC_INDEX is valid rsc index.
  224. * @event_type: event type to register; client sets 0x3 if it wants
  225. * to register for CORE_PC and CORE_RESTORE - both events.
  226. * @cb_func: Pointer to desired callback function
  227. * @usr: User pointer to pass to callback on event trigger
  228. * Returns: sde_rsc_event pointer on success
  229. */
  230. struct sde_rsc_event *sde_rsc_register_event(int rsc_index, uint32_t event_type,
  231. void (*cb_func)(uint32_t event_type, void *usr), void *usr);
  232. /**
  233. * sde_rsc_unregister_event - unregister callback for an event
  234. * @sde_rsc_event: event returned by sde_rsc_register_event
  235. */
  236. void sde_rsc_unregister_event(struct sde_rsc_event *event);
  237. /**
  238. * is_sde_rsc_available - check if display rsc available.
  239. * @rsc_index: A client will be created on this RSC. As of now only
  240. * SDE_RSC_INDEX is valid rsc index.
  241. * Returns: true if rsc is available; false in all other cases
  242. */
  243. bool is_sde_rsc_available(int rsc_index);
  244. /**
  245. * get_sde_rsc_current_state - gets the current state of sde rsc.
  246. * @rsc_index: A client will be created on this RSC. As of now only
  247. * SDE_RSC_INDEX is valid rsc index.
  248. * Returns: current state if rsc available; SDE_RSC_IDLE_STATE for
  249. * all other cases
  250. */
  251. enum sde_rsc_state get_sde_rsc_current_state(int rsc_index);
  252. /**
  253. * sde_rsc_client_trigger_vote() - triggers ab/ib vote for rsc client
  254. *
  255. * @client: Client pointer provided by sde_rsc_client_create().
  256. * @delta_vote: if bw vote is increased or decreased
  257. *
  258. * Return: error code.
  259. */
  260. int sde_rsc_client_trigger_vote(struct sde_rsc_client *caller_client,
  261. bool delta_vote);
  262. #else
  263. static inline struct sde_rsc_client *sde_rsc_client_create(u32 rsc_index,
  264. char *name, enum sde_rsc_client_type client_type, u32 vsync_source)
  265. {
  266. return NULL;
  267. }
  268. static inline void sde_rsc_client_destroy(struct sde_rsc_client *client)
  269. {
  270. }
  271. static inline int sde_rsc_client_state_update(struct sde_rsc_client *client,
  272. enum sde_rsc_state state,
  273. struct sde_rsc_cmd_config *config, int crtc_id,
  274. int *wait_vblank_crtc_id)
  275. {
  276. return 0;
  277. }
  278. static inline int sde_rsc_client_get_vsync_refcount(
  279. struct sde_rsc_client *caller_client)
  280. {
  281. return 0;
  282. }
  283. static inline int sde_rsc_client_reset_vsync_refcount(
  284. struct sde_rsc_client *caller_client)
  285. {
  286. return 0;
  287. }
  288. static inline bool sde_rsc_client_is_state_update_complete(
  289. struct sde_rsc_client *caller_client)
  290. {
  291. return false;
  292. }
  293. static inline int sde_rsc_client_vote(struct sde_rsc_client *caller_client,
  294. u32 bus_id, u64 ab_vote, u64 ib_vote)
  295. {
  296. return 0;
  297. }
  298. static inline struct sde_rsc_event *sde_rsc_register_event(int rsc_index,
  299. uint32_t event_type,
  300. void (*cb_func)(uint32_t event_type, void *usr), void *usr)
  301. {
  302. return NULL;
  303. }
  304. static inline void sde_rsc_unregister_event(struct sde_rsc_event *event)
  305. {
  306. }
  307. static inline bool is_sde_rsc_available(int rsc_index)
  308. {
  309. return false;
  310. }
  311. static inline enum sde_rsc_state get_sde_rsc_current_state(int rsc_index)
  312. {
  313. return SDE_RSC_IDLE_STATE;
  314. }
  315. static inline int sde_rsc_client_trigger_vote(
  316. struct sde_rsc_client *caller_client, bool delta_vote)
  317. {
  318. return 0;
  319. }
  320. #endif /* CONFIG_DRM_SDE_RSC */
  321. #endif /* _SDE_RSC_H_ */