blob: 0320210c547eb4a3bac855d5847b8e5b1324c337 [file] [log] [blame]
Dhaval Patel49ef6d72017-03-26 09:35:53 -07001/* 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 */
69enum 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 Patel824e9682017-05-01 23:31:22 -070082 * @id: Index of client. It will be assigned during client_create call
Dhaval Patel49ef6d72017-03-26 09:35:53 -070083 * @list: list to attach client master list
84 */
85struct sde_rsc_client {
86 char name[MAX_RSC_CLIENT_NAME_LEN];
87 short current_state;
88 int crtc_id;
89 u32 rsc_index;
Dhaval Patel824e9682017-05-01 23:31:22 -070090 u32 id;
Dhaval Patel49ef6d72017-03-26 09:35:53 -070091 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 */
102struct 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)
Dhaval Patelf5cc5a32017-07-10 17:33:23 -0700117 * @jitter_numer: panel jitter numerator value. This config causes rsc/solver
118 * early before te. Default is 0.8% jitter.
119 * @jitter_denom: panel jitter denominator.
Dhaval Patel49ef6d72017-03-26 09:35:53 -0700120 * @prefill_lines: max prefill lines based on panel
121 */
122struct sde_rsc_cmd_config {
123 u32 fps;
124 u32 vtotal;
Dhaval Patelf5cc5a32017-07-10 17:33:23 -0700125 u32 jitter_numer;
126 u32 jitter_denom;
Dhaval Patel49ef6d72017-03-26 09:35:53 -0700127 u32 prefill_lines;
128};
129
130#ifdef CONFIG_DRM_SDE_RSC
131/**
132 * sde_rsc_client_create() - create the client for sde rsc.
133 * Different displays like DSI, HDMI, DP, WB, etc should call this
134 * api to register their vote for rpmh. They still need to vote for
135 * power handle to get the clocks.
136
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 * @is_primary: Caller needs to provide information if client is primary
142 * or not. Primary client votes will be redirected to
143 * display rsc.
144 * @config: fps, vtotal, porches, etc configuration for command mode
145 * panel
146 *
147 * Return: client node pointer.
148 */
149struct sde_rsc_client *sde_rsc_client_create(u32 rsc_index, char *name,
150 bool is_primary_display);
151
152/**
153 * sde_rsc_client_destroy() - Destroy the sde rsc client.
154 *
155 * @client: Client pointer provided by sde_rsc_client_create().
156 *
157 * Return: none
158 */
159void sde_rsc_client_destroy(struct sde_rsc_client *client);
160
161/**
162 * sde_rsc_client_state_update() - rsc client state update
163 * Video mode, cmd mode and clk state are supported as modes. A client need to
164 * set this property during panel time. A switching client can set the
165 * property to change the state
166 *
167 * @client: Client pointer provided by sde_rsc_client_create().
168 * @state: Client state - video/cmd
169 * @config: fps, vtotal, porches, etc configuration for command mode
170 * panel
171 * @crtc_id: current client's crtc id
172 *
173 * Return: error code.
174 */
175int sde_rsc_client_state_update(struct sde_rsc_client *client,
176 enum sde_rsc_state state,
177 struct sde_rsc_cmd_config *config, int crtc_id);
178
179/**
180 * sde_rsc_client_vote() - ab/ib vote from rsc client
181 *
182 * @client: Client pointer provided by sde_rsc_client_create().
Alan Kwong0230a102017-05-16 11:36:44 -0700183 * @bus_id: data bus identifier
Dhaval Patel49ef6d72017-03-26 09:35:53 -0700184 * @ab: aggregated bandwidth vote from client.
185 * @ib: instant bandwidth vote from client.
186 *
187 * Return: error code.
188 */
189int sde_rsc_client_vote(struct sde_rsc_client *caller_client,
Alan Kwong0230a102017-05-16 11:36:44 -0700190 u32 bus_id, u64 ab_vote, u64 ib_vote);
Dhaval Patel49ef6d72017-03-26 09:35:53 -0700191
192/**
193 * sde_rsc_register_event - register a callback function for an event
194 * @rsc_index: A client will be created on this RSC. As of now only
195 * SDE_RSC_INDEX is valid rsc index.
196 * @event_type: event type to register; client sets 0x3 if it wants
197 * to register for CORE_PC and CORE_RESTORE - both events.
198 * @cb_func: Pointer to desired callback function
199 * @usr: User pointer to pass to callback on event trigger
200 * Returns: sde_rsc_event pointer on success
201 */
202struct sde_rsc_event *sde_rsc_register_event(int rsc_index, uint32_t event_type,
203 void (*cb_func)(uint32_t event_type, void *usr), void *usr);
204
205/**
206 * sde_rsc_unregister_event - unregister callback for an event
207 * @sde_rsc_event: event returned by sde_rsc_register_event
208 */
209void sde_rsc_unregister_event(struct sde_rsc_event *event);
210
Dhaval Pateldd2032a2017-04-11 10:50:36 -0700211/**
212 * is_sde_rsc_available - check if display rsc available.
213 * @rsc_index: A client will be created on this RSC. As of now only
214 * SDE_RSC_INDEX is valid rsc index.
215 * Returns: true if rsc is available; false in all other cases
216 */
217bool is_sde_rsc_available(int rsc_index);
218
219/**
220 * get_sde_rsc_current_state - gets the current state of sde rsc.
221 * @rsc_index: A client will be created on this RSC. As of now only
222 * SDE_RSC_INDEX is valid rsc index.
223 * Returns: current state if rsc available; SDE_RSC_IDLE_STATE for
224 * all other cases
225 */
226enum sde_rsc_state get_sde_rsc_current_state(int rsc_index);
227
Dhaval Patel49ef6d72017-03-26 09:35:53 -0700228#else
229
230static inline struct sde_rsc_client *sde_rsc_client_create(u32 rsc_index,
231 char *name, bool is_primary_display)
232{
233 return NULL;
234}
235
236static inline void sde_rsc_client_destroy(struct sde_rsc_client *client)
237{
238}
239
240static inline int sde_rsc_client_state_update(struct sde_rsc_client *client,
241 enum sde_rsc_state state,
242 struct sde_rsc_cmd_config *config, int crtc_id)
243{
244 return 0;
245}
246
247static inline int sde_rsc_client_vote(struct sde_rsc_client *caller_client,
Alan Kwong0230a102017-05-16 11:36:44 -0700248 u32 bus_id, u64 ab_vote, u64 ib_vote)
Dhaval Patel49ef6d72017-03-26 09:35:53 -0700249{
250 return 0;
251}
252
253static inline struct sde_rsc_event *sde_rsc_register_event(int rsc_index,
254 uint32_t event_type,
255 void (*cb_func)(uint32_t event_type, void *usr), void *usr)
256{
257 return NULL;
258}
259
260static inline void sde_rsc_unregister_event(struct sde_rsc_event *event)
261{
262}
263
Dhaval Pateldd2032a2017-04-11 10:50:36 -0700264static inline bool is_sde_rsc_available(int rsc_index)
265{
266 return false;
267}
268
269static inline enum sde_rsc_state get_sde_rsc_current_state(int rsc_index)
270{
271 return SDE_RSC_IDLE_STATE;
272}
Dhaval Patel49ef6d72017-03-26 09:35:53 -0700273#endif /* CONFIG_DRM_SDE_RSC */
274
275#endif /* _SDE_RSC_H_ */