Dhaval Patel | 49ef6d7 | 2017-03-26 09:35:53 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2016-2017, The Linux Foundation. All rights reserved. |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #ifndef _SDE_RSC_H_ |
| 15 | #define _SDE_RSC_H_ |
| 16 | |
| 17 | #include <linux/kernel.h> |
| 18 | |
| 19 | /* primary display rsc index */ |
| 20 | #define SDE_RSC_INDEX 0 |
| 21 | |
| 22 | #define MAX_RSC_CLIENT_NAME_LEN 128 |
| 23 | |
Lloyd Atkinson | f68a213 | 2017-07-17 10:16:30 -0400 | [diff] [blame] | 24 | /* DRM Object IDs are numbered excluding 0, use 0 to indicate invalid CRTC */ |
| 25 | #define SDE_RSC_INVALID_CRTC_ID 0 |
| 26 | |
Dhaval Patel | 49ef6d7 | 2017-03-26 09:35:53 -0700 | [diff] [blame] | 27 | /** |
| 28 | * event will be triggered before sde core power collapse, |
| 29 | * mdss gdsc is still on |
| 30 | */ |
| 31 | #define SDE_RSC_EVENT_PRE_CORE_PC 0x1 |
| 32 | /** |
| 33 | * event will be triggered after sde core collapse complete, |
| 34 | * mdss gdsc is off now |
| 35 | */ |
| 36 | #define SDE_RSC_EVENT_POST_CORE_PC 0x2 |
| 37 | /** |
| 38 | * event will be triggered before restoring the sde core from power collapse, |
| 39 | * mdss gdsc is still off |
| 40 | */ |
| 41 | #define SDE_RSC_EVENT_PRE_CORE_RESTORE 0x4 |
| 42 | /** |
| 43 | * event will be triggered after restoring the sde core from power collapse, |
| 44 | * mdss gdsc is on now |
| 45 | */ |
| 46 | #define SDE_RSC_EVENT_POST_CORE_RESTORE 0x8 |
| 47 | /** |
| 48 | * event attached with solver state enabled |
| 49 | * all clients in clk_state or cmd_state |
| 50 | */ |
| 51 | #define SDE_RSC_EVENT_SOLVER_ENABLED 0x10 |
| 52 | /** |
| 53 | * event attached with solver state disabled |
| 54 | * one of the client requested for vid state |
| 55 | */ |
| 56 | #define SDE_RSC_EVENT_SOLVER_DISABLED 0x20 |
| 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 | /** |
| 80 | * struct sde_rsc_client: stores the rsc client for sde driver |
| 81 | * @name: name of the client |
| 82 | * @current_state: current client state |
| 83 | * @crtc_id: crtc_id associated with this rsc client. |
| 84 | * @rsc_index: rsc index of a client - only index "0" valid. |
Dhaval Patel | 824e968 | 2017-05-01 23:31:22 -0700 | [diff] [blame] | 85 | * @id: Index of client. It will be assigned during client_create call |
Dhaval Patel | 49ef6d7 | 2017-03-26 09:35:53 -0700 | [diff] [blame] | 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; |
Dhaval Patel | 824e968 | 2017-05-01 23:31:22 -0700 | [diff] [blame] | 93 | u32 id; |
Dhaval Patel | 49ef6d7 | 2017-03-26 09:35:53 -0700 | [diff] [blame] | 94 | struct list_head list; |
| 95 | }; |
| 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 | /** |
| 114 | * struct sde_rsc_cmd_config: provides panel configuration to rsc |
| 115 | * when client is command mode. It is not required to set it during |
| 116 | * video mode. |
| 117 | * |
| 118 | * @fps: panel te interval |
| 119 | * @vtotal: current vertical total (height + vbp + vfp) |
Dhaval Patel | f5cc5a3 | 2017-07-10 17:33:23 -0700 | [diff] [blame] | 120 | * @jitter_numer: panel jitter numerator value. This config causes rsc/solver |
| 121 | * early before te. Default is 0.8% jitter. |
| 122 | * @jitter_denom: panel jitter denominator. |
Dhaval Patel | 49ef6d7 | 2017-03-26 09:35:53 -0700 | [diff] [blame] | 123 | * @prefill_lines: max prefill lines based on panel |
| 124 | */ |
| 125 | struct sde_rsc_cmd_config { |
| 126 | u32 fps; |
| 127 | u32 vtotal; |
Dhaval Patel | f5cc5a3 | 2017-07-10 17:33:23 -0700 | [diff] [blame] | 128 | u32 jitter_numer; |
| 129 | u32 jitter_denom; |
Dhaval Patel | 49ef6d7 | 2017-03-26 09:35:53 -0700 | [diff] [blame] | 130 | u32 prefill_lines; |
| 131 | }; |
| 132 | |
| 133 | #ifdef CONFIG_DRM_SDE_RSC |
| 134 | /** |
| 135 | * sde_rsc_client_create() - create the client for sde rsc. |
| 136 | * Different displays like DSI, HDMI, DP, WB, etc should call this |
| 137 | * api to register their vote for rpmh. They still need to vote for |
| 138 | * power handle to get the clocks. |
| 139 | |
| 140 | * @rsc_index: A client will be created on this RSC. As of now only |
| 141 | * SDE_RSC_INDEX is valid rsc index. |
| 142 | * @name: Caller needs to provide some valid string to identify |
| 143 | * the client. "primary", "dp", "hdmi" are suggested name. |
| 144 | * @is_primary: Caller needs to provide information if client is primary |
| 145 | * or not. Primary client votes will be redirected to |
| 146 | * display rsc. |
| 147 | * @config: fps, vtotal, porches, etc configuration for command mode |
| 148 | * panel |
| 149 | * |
| 150 | * Return: client node pointer. |
| 151 | */ |
| 152 | struct sde_rsc_client *sde_rsc_client_create(u32 rsc_index, char *name, |
| 153 | bool is_primary_display); |
| 154 | |
| 155 | /** |
| 156 | * sde_rsc_client_destroy() - Destroy the sde rsc client. |
| 157 | * |
| 158 | * @client: Client pointer provided by sde_rsc_client_create(). |
| 159 | * |
| 160 | * Return: none |
| 161 | */ |
| 162 | void sde_rsc_client_destroy(struct sde_rsc_client *client); |
| 163 | |
| 164 | /** |
| 165 | * sde_rsc_client_state_update() - rsc client state update |
| 166 | * Video mode, cmd mode and clk state are supported as modes. A client need to |
| 167 | * set this property during panel time. A switching client can set the |
| 168 | * property to change the state |
| 169 | * |
| 170 | * @client: Client pointer provided by sde_rsc_client_create(). |
| 171 | * @state: Client state - video/cmd |
| 172 | * @config: fps, vtotal, porches, etc configuration for command mode |
| 173 | * panel |
| 174 | * @crtc_id: current client's crtc id |
Lloyd Atkinson | f68a213 | 2017-07-17 10:16:30 -0400 | [diff] [blame] | 175 | * @wait_vblank_crtc_id: Output parameter. If set to non-zero, rsc hw |
| 176 | * state update requires a wait for one vblank on |
| 177 | * the primary crtc. In that case, this output |
| 178 | * param will be set to the crtc on which to wait. |
| 179 | * If SDE_RSC_INVALID_CRTC_ID, no wait necessary |
Dhaval Patel | 49ef6d7 | 2017-03-26 09:35:53 -0700 | [diff] [blame] | 180 | * |
| 181 | * Return: error code. |
| 182 | */ |
| 183 | int sde_rsc_client_state_update(struct sde_rsc_client *client, |
| 184 | enum sde_rsc_state state, |
Lloyd Atkinson | f68a213 | 2017-07-17 10:16:30 -0400 | [diff] [blame] | 185 | struct sde_rsc_cmd_config *config, int crtc_id, |
| 186 | int *wait_vblank_crtc_id); |
| 187 | |
| 188 | /** |
Ingrid Gallardo | e52302c | 2017-11-28 19:30:47 -0800 | [diff] [blame] | 189 | * sde_rsc_client_get_vsync_refcount() - returns the status of the vsync |
| 190 | * refcount, to signal if the client needs to reset the refcounting logic |
| 191 | * @client: Client pointer provided by sde_rsc_client_create(). |
| 192 | * |
| 193 | * Return: true if the state update has completed. |
| 194 | */ |
| 195 | int sde_rsc_client_get_vsync_refcount( |
| 196 | struct sde_rsc_client *caller_client); |
| 197 | |
| 198 | /** |
| 199 | * sde_rsc_client_reset_vsync_refcount() - reduces the refcounting |
| 200 | * logic that waits for the vsync. |
| 201 | * @client: Client pointer provided by sde_rsc_client_create(). |
| 202 | * |
| 203 | * Return: true if the state update has completed. |
| 204 | */ |
| 205 | int sde_rsc_client_reset_vsync_refcount( |
| 206 | struct sde_rsc_client *caller_client); |
| 207 | |
| 208 | /** |
Lloyd Atkinson | f68a213 | 2017-07-17 10:16:30 -0400 | [diff] [blame] | 209 | * sde_rsc_client_is_state_update_complete() - check if state update is complete |
| 210 | * RSC state transition is not complete until HW receives VBLANK signal. This |
| 211 | * function checks RSC HW to determine whether that signal has been received. |
| 212 | * @client: Client pointer provided by sde_rsc_client_create(). |
| 213 | * |
| 214 | * Return: true if the state update has completed. |
| 215 | */ |
| 216 | bool sde_rsc_client_is_state_update_complete( |
| 217 | struct sde_rsc_client *caller_client); |
Dhaval Patel | 49ef6d7 | 2017-03-26 09:35:53 -0700 | [diff] [blame] | 218 | |
| 219 | /** |
| 220 | * sde_rsc_client_vote() - ab/ib vote from rsc client |
| 221 | * |
| 222 | * @client: Client pointer provided by sde_rsc_client_create(). |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 223 | * @bus_id: data bus identifier |
Dhaval Patel | 49ef6d7 | 2017-03-26 09:35:53 -0700 | [diff] [blame] | 224 | * @ab: aggregated bandwidth vote from client. |
| 225 | * @ib: instant bandwidth vote from client. |
| 226 | * |
| 227 | * Return: error code. |
| 228 | */ |
| 229 | int sde_rsc_client_vote(struct sde_rsc_client *caller_client, |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 230 | u32 bus_id, u64 ab_vote, u64 ib_vote); |
Dhaval Patel | 49ef6d7 | 2017-03-26 09:35:53 -0700 | [diff] [blame] | 231 | |
| 232 | /** |
| 233 | * sde_rsc_register_event - register a callback function for an event |
| 234 | * @rsc_index: A client will be created on this RSC. As of now only |
| 235 | * SDE_RSC_INDEX is valid rsc index. |
| 236 | * @event_type: event type to register; client sets 0x3 if it wants |
| 237 | * to register for CORE_PC and CORE_RESTORE - both events. |
| 238 | * @cb_func: Pointer to desired callback function |
| 239 | * @usr: User pointer to pass to callback on event trigger |
| 240 | * Returns: sde_rsc_event pointer on success |
| 241 | */ |
| 242 | struct sde_rsc_event *sde_rsc_register_event(int rsc_index, uint32_t event_type, |
| 243 | void (*cb_func)(uint32_t event_type, void *usr), void *usr); |
| 244 | |
| 245 | /** |
| 246 | * sde_rsc_unregister_event - unregister callback for an event |
| 247 | * @sde_rsc_event: event returned by sde_rsc_register_event |
| 248 | */ |
| 249 | void sde_rsc_unregister_event(struct sde_rsc_event *event); |
| 250 | |
Dhaval Patel | dd2032a | 2017-04-11 10:50:36 -0700 | [diff] [blame] | 251 | /** |
| 252 | * is_sde_rsc_available - check if display rsc available. |
| 253 | * @rsc_index: A client will be created on this RSC. As of now only |
| 254 | * SDE_RSC_INDEX is valid rsc index. |
| 255 | * Returns: true if rsc is available; false in all other cases |
| 256 | */ |
| 257 | bool is_sde_rsc_available(int rsc_index); |
| 258 | |
| 259 | /** |
| 260 | * get_sde_rsc_current_state - gets the current state of sde rsc. |
| 261 | * @rsc_index: A client will be created on this RSC. As of now only |
| 262 | * SDE_RSC_INDEX is valid rsc index. |
| 263 | * Returns: current state if rsc available; SDE_RSC_IDLE_STATE for |
| 264 | * all other cases |
| 265 | */ |
| 266 | enum sde_rsc_state get_sde_rsc_current_state(int rsc_index); |
| 267 | |
Dhaval Patel | 49ef6d7 | 2017-03-26 09:35:53 -0700 | [diff] [blame] | 268 | #else |
| 269 | |
| 270 | static inline struct sde_rsc_client *sde_rsc_client_create(u32 rsc_index, |
| 271 | char *name, bool is_primary_display) |
| 272 | { |
| 273 | return NULL; |
| 274 | } |
| 275 | |
| 276 | static inline void sde_rsc_client_destroy(struct sde_rsc_client *client) |
| 277 | { |
| 278 | } |
| 279 | |
| 280 | static inline int sde_rsc_client_state_update(struct sde_rsc_client *client, |
| 281 | enum sde_rsc_state state, |
Maria Yu | 2bc499f | 2017-09-26 14:22:45 +0800 | [diff] [blame] | 282 | struct sde_rsc_cmd_config *config, int crtc_id, |
| 283 | int *wait_vblank_crtc_id) |
Dhaval Patel | 49ef6d7 | 2017-03-26 09:35:53 -0700 | [diff] [blame] | 284 | { |
| 285 | return 0; |
| 286 | } |
| 287 | |
Ingrid Gallardo | e52302c | 2017-11-28 19:30:47 -0800 | [diff] [blame] | 288 | int sde_rsc_client_get_vsync_refcount( |
| 289 | struct sde_rsc_client *caller_client) |
| 290 | { |
| 291 | return 0; |
| 292 | } |
| 293 | |
| 294 | int sde_rsc_client_reset_vsync_refcount( |
| 295 | struct sde_rsc_client *caller_client) |
| 296 | { |
| 297 | return 0; |
| 298 | } |
| 299 | |
Lloyd Atkinson | f68a213 | 2017-07-17 10:16:30 -0400 | [diff] [blame] | 300 | static inline bool sde_rsc_client_is_state_update_complete( |
| 301 | struct sde_rsc_client *caller_client) |
| 302 | { |
| 303 | return false; |
| 304 | } |
| 305 | |
Dhaval Patel | 49ef6d7 | 2017-03-26 09:35:53 -0700 | [diff] [blame] | 306 | static inline int sde_rsc_client_vote(struct sde_rsc_client *caller_client, |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 307 | u32 bus_id, u64 ab_vote, u64 ib_vote) |
Dhaval Patel | 49ef6d7 | 2017-03-26 09:35:53 -0700 | [diff] [blame] | 308 | { |
| 309 | return 0; |
| 310 | } |
| 311 | |
| 312 | static inline struct sde_rsc_event *sde_rsc_register_event(int rsc_index, |
| 313 | uint32_t event_type, |
| 314 | void (*cb_func)(uint32_t event_type, void *usr), void *usr) |
| 315 | { |
| 316 | return NULL; |
| 317 | } |
| 318 | |
| 319 | static inline void sde_rsc_unregister_event(struct sde_rsc_event *event) |
| 320 | { |
| 321 | } |
| 322 | |
Dhaval Patel | dd2032a | 2017-04-11 10:50:36 -0700 | [diff] [blame] | 323 | static inline bool is_sde_rsc_available(int rsc_index) |
| 324 | { |
| 325 | return false; |
| 326 | } |
| 327 | |
| 328 | static inline enum sde_rsc_state get_sde_rsc_current_state(int rsc_index) |
| 329 | { |
| 330 | return SDE_RSC_IDLE_STATE; |
| 331 | } |
Dhaval Patel | 49ef6d7 | 2017-03-26 09:35:53 -0700 | [diff] [blame] | 332 | #endif /* CONFIG_DRM_SDE_RSC */ |
| 333 | |
| 334 | #endif /* _SDE_RSC_H_ */ |