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 | |
| 24 | /** |
| 25 | * event will be triggered before sde core power collapse, |
| 26 | * mdss gdsc is still on |
| 27 | */ |
| 28 | #define SDE_RSC_EVENT_PRE_CORE_PC 0x1 |
| 29 | /** |
| 30 | * event will be triggered after sde core collapse complete, |
| 31 | * mdss gdsc is off now |
| 32 | */ |
| 33 | #define SDE_RSC_EVENT_POST_CORE_PC 0x2 |
| 34 | /** |
| 35 | * event will be triggered before restoring the sde core from power collapse, |
| 36 | * mdss gdsc is still off |
| 37 | */ |
| 38 | #define SDE_RSC_EVENT_PRE_CORE_RESTORE 0x4 |
| 39 | /** |
| 40 | * event will be triggered after restoring the sde core from power collapse, |
| 41 | * mdss gdsc is on now |
| 42 | */ |
| 43 | #define SDE_RSC_EVENT_POST_CORE_RESTORE 0x8 |
| 44 | /** |
| 45 | * event attached with solver state enabled |
| 46 | * all clients in clk_state or cmd_state |
| 47 | */ |
| 48 | #define SDE_RSC_EVENT_SOLVER_ENABLED 0x10 |
| 49 | /** |
| 50 | * event attached with solver state disabled |
| 51 | * one of the client requested for vid state |
| 52 | */ |
| 53 | #define SDE_RSC_EVENT_SOLVER_DISABLED 0x20 |
| 54 | |
| 55 | /** |
| 56 | * sde_rsc_state: sde rsc state information |
| 57 | * SDE_RSC_IDLE_STATE: A client requests for idle state when there is no |
| 58 | * pixel or cmd transfer expected. An idle vote from |
| 59 | * all clients lead to power collapse state. |
| 60 | * SDE_RSC_CLK_STATE: A client requests for clk state when it wants to |
| 61 | * only avoid mode-2 entry/exit. For ex: V4L2 driver, |
| 62 | * sde power handle, etc. |
| 63 | * SDE_RSC_CMD_STATE: A client requests for cmd state when it wants to |
| 64 | * enable the solver mode. |
| 65 | * SDE_RSC_VID_STATE: A client requests for vid state it wants to avoid |
| 66 | * solver enable because client is fetching data from |
| 67 | * continuously. |
| 68 | */ |
| 69 | enum sde_rsc_state { |
| 70 | SDE_RSC_IDLE_STATE, |
| 71 | SDE_RSC_CLK_STATE, |
| 72 | SDE_RSC_CMD_STATE, |
| 73 | SDE_RSC_VID_STATE, |
| 74 | }; |
| 75 | |
| 76 | /** |
| 77 | * struct sde_rsc_client: stores the rsc client for sde driver |
| 78 | * @name: name of the client |
| 79 | * @current_state: current client state |
| 80 | * @crtc_id: crtc_id associated with this rsc client. |
| 81 | * @rsc_index: rsc index of a client - only index "0" valid. |
Dhaval Patel | 824e968 | 2017-05-01 23:31:22 -0700 | [diff] [blame] | 82 | * @id: Index of client. It will be assigned during client_create call |
Dhaval Patel | 49ef6d7 | 2017-03-26 09:35:53 -0700 | [diff] [blame] | 83 | * @list: list to attach client master list |
| 84 | */ |
| 85 | struct sde_rsc_client { |
| 86 | char name[MAX_RSC_CLIENT_NAME_LEN]; |
| 87 | short current_state; |
| 88 | int crtc_id; |
| 89 | u32 rsc_index; |
Dhaval Patel | 824e968 | 2017-05-01 23:31:22 -0700 | [diff] [blame] | 90 | u32 id; |
Dhaval Patel | 49ef6d7 | 2017-03-26 09:35:53 -0700 | [diff] [blame] | 91 | struct list_head list; |
| 92 | }; |
| 93 | |
| 94 | /** |
| 95 | * struct sde_rsc_event: local event registration entry structure |
| 96 | * @cb_func: Pointer to desired callback function |
| 97 | * @usr: User pointer to pass to callback on event trigger |
| 98 | * @rsc_index: rsc index of a client - only index "0" valid. |
| 99 | * @event_type: refer comments in event_register |
| 100 | * @list: list to attach event master list |
| 101 | */ |
| 102 | struct sde_rsc_event { |
| 103 | void (*cb_func)(uint32_t event_type, void *usr); |
| 104 | void *usr; |
| 105 | u32 rsc_index; |
| 106 | uint32_t event_type; |
| 107 | struct list_head list; |
| 108 | }; |
| 109 | |
| 110 | /** |
| 111 | * struct sde_rsc_cmd_config: provides panel configuration to rsc |
| 112 | * when client is command mode. It is not required to set it during |
| 113 | * video mode. |
| 114 | * |
| 115 | * @fps: panel te interval |
| 116 | * @vtotal: current vertical total (height + vbp + vfp) |
| 117 | * @jitter: panel can set the jitter to wake up rsc/solver early |
| 118 | * This value causes mdp core to exit certain mode |
| 119 | * early. Default is 10% jitter |
| 120 | * @prefill_lines: max prefill lines based on panel |
| 121 | */ |
| 122 | struct sde_rsc_cmd_config { |
| 123 | u32 fps; |
| 124 | u32 vtotal; |
| 125 | u32 jitter; |
| 126 | u32 prefill_lines; |
| 127 | }; |
| 128 | |
| 129 | #ifdef CONFIG_DRM_SDE_RSC |
| 130 | /** |
| 131 | * sde_rsc_client_create() - create the client for sde rsc. |
| 132 | * Different displays like DSI, HDMI, DP, WB, etc should call this |
| 133 | * api to register their vote for rpmh. They still need to vote for |
| 134 | * power handle to get the clocks. |
| 135 | |
| 136 | * @rsc_index: A client will be created on this RSC. As of now only |
| 137 | * SDE_RSC_INDEX is valid rsc index. |
| 138 | * @name: Caller needs to provide some valid string to identify |
| 139 | * the client. "primary", "dp", "hdmi" are suggested name. |
| 140 | * @is_primary: Caller needs to provide information if client is primary |
| 141 | * or not. Primary client votes will be redirected to |
| 142 | * display rsc. |
| 143 | * @config: fps, vtotal, porches, etc configuration for command mode |
| 144 | * panel |
| 145 | * |
| 146 | * Return: client node pointer. |
| 147 | */ |
| 148 | struct sde_rsc_client *sde_rsc_client_create(u32 rsc_index, char *name, |
| 149 | bool is_primary_display); |
| 150 | |
| 151 | /** |
| 152 | * sde_rsc_client_destroy() - Destroy the sde rsc client. |
| 153 | * |
| 154 | * @client: Client pointer provided by sde_rsc_client_create(). |
| 155 | * |
| 156 | * Return: none |
| 157 | */ |
| 158 | void sde_rsc_client_destroy(struct sde_rsc_client *client); |
| 159 | |
| 160 | /** |
| 161 | * sde_rsc_client_state_update() - rsc client state update |
| 162 | * Video mode, cmd mode and clk state are supported as modes. A client need to |
| 163 | * set this property during panel time. A switching client can set the |
| 164 | * property to change the state |
| 165 | * |
| 166 | * @client: Client pointer provided by sde_rsc_client_create(). |
| 167 | * @state: Client state - video/cmd |
| 168 | * @config: fps, vtotal, porches, etc configuration for command mode |
| 169 | * panel |
| 170 | * @crtc_id: current client's crtc id |
| 171 | * |
| 172 | * Return: error code. |
| 173 | */ |
| 174 | int sde_rsc_client_state_update(struct sde_rsc_client *client, |
| 175 | enum sde_rsc_state state, |
| 176 | struct sde_rsc_cmd_config *config, int crtc_id); |
| 177 | |
| 178 | /** |
| 179 | * sde_rsc_client_vote() - ab/ib vote from rsc client |
| 180 | * |
| 181 | * @client: Client pointer provided by sde_rsc_client_create(). |
| 182 | * @ab: aggregated bandwidth vote from client. |
| 183 | * @ib: instant bandwidth vote from client. |
| 184 | * |
| 185 | * Return: error code. |
| 186 | */ |
| 187 | int sde_rsc_client_vote(struct sde_rsc_client *caller_client, |
| 188 | u64 ab_vote, u64 ib_vote); |
| 189 | |
| 190 | /** |
| 191 | * sde_rsc_register_event - register a callback function for an event |
| 192 | * @rsc_index: A client will be created on this RSC. As of now only |
| 193 | * SDE_RSC_INDEX is valid rsc index. |
| 194 | * @event_type: event type to register; client sets 0x3 if it wants |
| 195 | * to register for CORE_PC and CORE_RESTORE - both events. |
| 196 | * @cb_func: Pointer to desired callback function |
| 197 | * @usr: User pointer to pass to callback on event trigger |
| 198 | * Returns: sde_rsc_event pointer on success |
| 199 | */ |
| 200 | struct sde_rsc_event *sde_rsc_register_event(int rsc_index, uint32_t event_type, |
| 201 | void (*cb_func)(uint32_t event_type, void *usr), void *usr); |
| 202 | |
| 203 | /** |
| 204 | * sde_rsc_unregister_event - unregister callback for an event |
| 205 | * @sde_rsc_event: event returned by sde_rsc_register_event |
| 206 | */ |
| 207 | void sde_rsc_unregister_event(struct sde_rsc_event *event); |
| 208 | |
Dhaval Patel | dd2032a | 2017-04-11 10:50:36 -0700 | [diff] [blame] | 209 | /** |
| 210 | * is_sde_rsc_available - check if display rsc available. |
| 211 | * @rsc_index: A client will be created on this RSC. As of now only |
| 212 | * SDE_RSC_INDEX is valid rsc index. |
| 213 | * Returns: true if rsc is available; false in all other cases |
| 214 | */ |
| 215 | bool is_sde_rsc_available(int rsc_index); |
| 216 | |
| 217 | /** |
| 218 | * get_sde_rsc_current_state - gets the current state of sde rsc. |
| 219 | * @rsc_index: A client will be created on this RSC. As of now only |
| 220 | * SDE_RSC_INDEX is valid rsc index. |
| 221 | * Returns: current state if rsc available; SDE_RSC_IDLE_STATE for |
| 222 | * all other cases |
| 223 | */ |
| 224 | enum sde_rsc_state get_sde_rsc_current_state(int rsc_index); |
| 225 | |
Dhaval Patel | 49ef6d7 | 2017-03-26 09:35:53 -0700 | [diff] [blame] | 226 | #else |
| 227 | |
| 228 | static inline struct sde_rsc_client *sde_rsc_client_create(u32 rsc_index, |
| 229 | char *name, bool is_primary_display) |
| 230 | { |
| 231 | return NULL; |
| 232 | } |
| 233 | |
| 234 | static inline void sde_rsc_client_destroy(struct sde_rsc_client *client) |
| 235 | { |
| 236 | } |
| 237 | |
| 238 | static inline int sde_rsc_client_state_update(struct sde_rsc_client *client, |
| 239 | enum sde_rsc_state state, |
| 240 | struct sde_rsc_cmd_config *config, int crtc_id) |
| 241 | { |
| 242 | return 0; |
| 243 | } |
| 244 | |
| 245 | static inline int sde_rsc_client_vote(struct sde_rsc_client *caller_client, |
| 246 | u64 ab_vote, u64 ib_vote) |
| 247 | { |
| 248 | return 0; |
| 249 | } |
| 250 | |
| 251 | static inline struct sde_rsc_event *sde_rsc_register_event(int rsc_index, |
| 252 | uint32_t event_type, |
| 253 | void (*cb_func)(uint32_t event_type, void *usr), void *usr) |
| 254 | { |
| 255 | return NULL; |
| 256 | } |
| 257 | |
| 258 | static inline void sde_rsc_unregister_event(struct sde_rsc_event *event) |
| 259 | { |
| 260 | } |
| 261 | |
Dhaval Patel | dd2032a | 2017-04-11 10:50:36 -0700 | [diff] [blame] | 262 | static inline bool is_sde_rsc_available(int rsc_index) |
| 263 | { |
| 264 | return false; |
| 265 | } |
| 266 | |
| 267 | static inline enum sde_rsc_state get_sde_rsc_current_state(int rsc_index) |
| 268 | { |
| 269 | return SDE_RSC_IDLE_STATE; |
| 270 | } |
Dhaval Patel | 49ef6d7 | 2017-03-26 09:35:53 -0700 | [diff] [blame] | 271 | #endif /* CONFIG_DRM_SDE_RSC */ |
| 272 | |
| 273 | #endif /* _SDE_RSC_H_ */ |