blob: 72975e7811df623dc980b60f860a8d091f63c956 [file] [log] [blame]
Dhaval Patel3fe015e2017-02-18 10:11:27 -08001/* Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
Dhaval Patel480dc522016-07-27 18:36:59 -07002 *
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_POWER_HANDLE_H_
15#define _SDE_POWER_HANDLE_H_
16
17#define MAX_CLIENT_NAME_LEN 128
18
Ingrid Gallardof4c8e0d2017-07-19 16:46:25 -070019#define SDE_POWER_HANDLE_ENABLE_BUS_AB_QUOTA 0
Dhaval Patel60c25062017-02-21 17:44:05 -080020#define SDE_POWER_HANDLE_DISABLE_BUS_AB_QUOTA 0
Ingrid Gallardo72cca3002017-10-26 18:25:47 -070021#define SDE_POWER_HANDLE_ENABLE_BUS_IB_QUOTA 400000000
22#define SDE_POWER_HANDLE_ENABLE_NRT_BUS_IB_QUOTA 0
Dhaval Patel60c25062017-02-21 17:44:05 -080023#define SDE_POWER_HANDLE_DISABLE_BUS_IB_QUOTA 0
Alan Kwong67a3f792016-11-01 23:16:53 -040024
Shashank Babu Chinta Venkata74a03f12017-02-28 11:24:51 -080025#include <linux/sde_io_util.h>
26
Veera Sundaram Sankaran410d1562017-03-24 14:48:13 -070027/* event will be triggered before power handler disable */
28#define SDE_POWER_EVENT_PRE_DISABLE 0x1
29
30/* event will be triggered after power handler disable */
31#define SDE_POWER_EVENT_POST_DISABLE 0x2
32
33/* event will be triggered before power handler enable */
34#define SDE_POWER_EVENT_PRE_ENABLE 0x4
35
36/* event will be triggered after power handler enable */
37#define SDE_POWER_EVENT_POST_ENABLE 0x8
38
Dhaval Patel480dc522016-07-27 18:36:59 -070039/**
40 * mdss_bus_vote_type: register bus vote type
41 * VOTE_INDEX_DISABLE: removes the client vote
42 * VOTE_INDEX_LOW: keeps the lowest vote for register bus
43 * VOTE_INDEX_MAX: invalid
44 */
45enum mdss_bus_vote_type {
46 VOTE_INDEX_DISABLE,
47 VOTE_INDEX_LOW,
48 VOTE_INDEX_MAX,
49};
50
51/**
Alan Kwong67a3f792016-11-01 23:16:53 -040052 * enum sde_power_handle_data_bus_client - type of axi bus clients
53 * @SDE_POWER_HANDLE_DATA_BUS_CLIENT_RT: core real-time bus client
54 * @SDE_POWER_HANDLE_DATA_BUS_CLIENT_NRT: core non-real-time bus client
55 * @SDE_POWER_HANDLE_DATA_BUS_CLIENT_MAX: maximum number of bus client type
56 */
57enum sde_power_handle_data_bus_client {
58 SDE_POWER_HANDLE_DATA_BUS_CLIENT_RT,
59 SDE_POWER_HANDLE_DATA_BUS_CLIENT_NRT,
60 SDE_POWER_HANDLE_DATA_BUS_CLIENT_MAX
61};
62
63/**
Alan Kwong0230a102017-05-16 11:36:44 -070064 * enum SDE_POWER_HANDLE_DBUS_ID - data bus identifier
65 * @SDE_POWER_HANDLE_DBUS_ID_MNOC: DPU/MNOC data bus
66 * @SDE_POWER_HANDLE_DBUS_ID_LLCC: MNOC/LLCC data bus
67 * @SDE_POWER_HANDLE_DBUS_ID_EBI: LLCC/EBI data bus
68 */
69enum SDE_POWER_HANDLE_DBUS_ID {
70 SDE_POWER_HANDLE_DBUS_ID_MNOC,
71 SDE_POWER_HANDLE_DBUS_ID_LLCC,
72 SDE_POWER_HANDLE_DBUS_ID_EBI,
73 SDE_POWER_HANDLE_DBUS_ID_MAX,
74};
75
76/**
Dhaval Patel480dc522016-07-27 18:36:59 -070077 * struct sde_power_client: stores the power client for sde driver
78 * @name: name of the client
79 * @usecase_ndx: current regs bus vote type
80 * @refcount: current refcount if multiple modules are using same
81 * same client for enable/disable. Power module will
82 * aggregate the refcount and vote accordingly for this
83 * client.
84 * @id: assigned during create. helps for debugging.
85 * @list: list to attach power handle master list
Alan Kwong67a3f792016-11-01 23:16:53 -040086 * @ab: arbitrated bandwidth for each bus client
87 * @ib: instantaneous bandwidth for each bus client
Veera Sundaram Sankaran410d1562017-03-24 14:48:13 -070088 * @active: inidcates the state of sde power handle
Dhaval Patel480dc522016-07-27 18:36:59 -070089 */
90struct sde_power_client {
91 char name[MAX_CLIENT_NAME_LEN];
92 short usecase_ndx;
93 short refcount;
94 u32 id;
95 struct list_head list;
Alan Kwong67a3f792016-11-01 23:16:53 -040096 u64 ab[SDE_POWER_HANDLE_DATA_BUS_CLIENT_MAX];
97 u64 ib[SDE_POWER_HANDLE_DATA_BUS_CLIENT_MAX];
Veera Sundaram Sankaran410d1562017-03-24 14:48:13 -070098 bool active;
Alan Kwong67a3f792016-11-01 23:16:53 -040099};
100
101/**
102 * struct sde_power_data_handle: power handle struct for data bus
103 * @data_bus_scale_table: pointer to bus scaling table
104 * @data_bus_hdl: current data bus handle
Ingrid Gallardo72cca3002017-10-26 18:25:47 -0700105 * @data_paths_cnt: number of rt data path ports
106 * @nrt_data_paths_cnt: number of nrt data path ports
Alan Kwong67a3f792016-11-01 23:16:53 -0400107 * @bus_channels: number of memory bus channels
108 * @curr_bw_uc_idx: current use case index of data bus
109 * @ao_bw_uc_idx: active only use case index of data bus
Alan Kwongff30f4a2017-05-23 12:02:00 -0700110 * @ab_rt: realtime ab quota
111 * @ib_rt: realtime ib quota
112 * @ab_nrt: non-realtime ab quota
113 * @ib_nrt: non-realtime ib quota
114 * @enable: true if bus is enabled
Alan Kwong67a3f792016-11-01 23:16:53 -0400115 */
116struct sde_power_data_bus_handle {
117 struct msm_bus_scale_pdata *data_bus_scale_table;
118 u32 data_bus_hdl;
Ingrid Gallardo72cca3002017-10-26 18:25:47 -0700119 u32 data_paths_cnt;
120 u32 nrt_data_paths_cnt;
Alan Kwong67a3f792016-11-01 23:16:53 -0400121 u32 bus_channels;
122 u32 curr_bw_uc_idx;
123 u32 ao_bw_uc_idx;
Alan Kwongff30f4a2017-05-23 12:02:00 -0700124 u64 ab_rt;
125 u64 ib_rt;
126 u64 ab_nrt;
127 u64 ib_nrt;
128 bool enable;
Dhaval Patel480dc522016-07-27 18:36:59 -0700129};
130
Veera Sundaram Sankaran410d1562017-03-24 14:48:13 -0700131/*
132 * struct sde_power_event - local event registration structure
133 * @client_name: name of the client registering
134 * @cb_fnc: pointer to desired callback function
135 * @usr: user pointer to pass to callback event trigger
136 * @event: refer to SDE_POWER_HANDLE_EVENT_*
137 * @list: list to attach event master list
138 * @active: indicates the state of sde power handle
139 */
140struct sde_power_event {
141 char client_name[MAX_CLIENT_NAME_LEN];
142 void (*cb_fnc)(u32 event_type, void *usr);
143 void *usr;
144 u32 event_type;
145 struct list_head list;
146 bool active;
147};
148
Dhaval Patel480dc522016-07-27 18:36:59 -0700149/**
150 * struct sde_power_handle: power handle main struct
151 * @mp: module power for clock and regulator
152 * @client_clist: master list to store all clients
153 * @phandle_lock: lock to synchronize the enable/disable
Alan Kwong67a3f792016-11-01 23:16:53 -0400154 * @dev: pointer to device structure
Dhaval Patel480dc522016-07-27 18:36:59 -0700155 * @usecase_ndx: current usecase index
156 * @reg_bus_hdl: current register bus handle
Alan Kwong67a3f792016-11-01 23:16:53 -0400157 * @data_bus_handle: context structure for data bus control
Veera Sundaram Sankaran410d1562017-03-24 14:48:13 -0700158 * @event_list: current power handle event list
Veera Sundaram Sankaran38318f12017-03-24 15:54:21 -0700159 * @rsc_client: sde rsc client pointer
160 * @rsc_client_init: boolean to control rsc client create
Dhaval Patel480dc522016-07-27 18:36:59 -0700161 */
162struct sde_power_handle {
163 struct dss_module_power mp;
164 struct list_head power_client_clist;
165 struct mutex phandle_lock;
Alan Kwong67a3f792016-11-01 23:16:53 -0400166 struct device *dev;
Dhaval Patel480dc522016-07-27 18:36:59 -0700167 u32 current_usecase_ndx;
Dhaval Patel480dc522016-07-27 18:36:59 -0700168 u32 reg_bus_hdl;
Alan Kwong0230a102017-05-16 11:36:44 -0700169 struct sde_power_data_bus_handle data_bus_handle
170 [SDE_POWER_HANDLE_DBUS_ID_MAX];
Veera Sundaram Sankaran410d1562017-03-24 14:48:13 -0700171 struct list_head event_list;
Veera Sundaram Sankaran38318f12017-03-24 15:54:21 -0700172 struct sde_rsc_client *rsc_client;
173 bool rsc_client_init;
Dhaval Patel480dc522016-07-27 18:36:59 -0700174};
175
176/**
177 * sde_power_resource_init() - initializes the sde power handle
178 * @pdev: platform device to search the power resources
179 * @pdata: power handle to store the power resources
180 *
181 * Return: error code.
182 */
183int sde_power_resource_init(struct platform_device *pdev,
184 struct sde_power_handle *pdata);
185
186/**
187 * sde_power_resource_deinit() - release the sde power handle
188 * @pdev: platform device for power resources
189 * @pdata: power handle containing the resources
190 *
191 * Return: error code.
192 */
193void sde_power_resource_deinit(struct platform_device *pdev,
194 struct sde_power_handle *pdata);
195
196/**
197 * sde_power_client_create() - create the client on power handle
198 * @pdata: power handle containing the resources
199 * @client_name: new client name for registration
200 *
201 * Return: error code.
202 */
203struct sde_power_client *sde_power_client_create(struct sde_power_handle *pdata,
204 char *client_name);
205
206/**
207 * sde_power_client_destroy() - destroy the client on power handle
208 * @pdata: power handle containing the resources
209 * @client_name: new client name for registration
210 *
211 * Return: none
212 */
213void sde_power_client_destroy(struct sde_power_handle *phandle,
214 struct sde_power_client *client);
215
216/**
217 * sde_power_resource_enable() - enable/disable the power resources
218 * @pdata: power handle containing the resources
219 * @client: client information to enable/disable its vote
220 * @enable: boolean request for enable/disable
221 *
222 * Return: error code.
223 */
224int sde_power_resource_enable(struct sde_power_handle *pdata,
225 struct sde_power_client *pclient, bool enable);
226
227/**
Alan Kwong1124f1f2017-11-10 18:14:39 -0500228 * sde_power_resource_is_enabled() - return true if power resource is enabled
229 * @pdata: power handle containing the resources
230 *
231 * Return: true if enabled; false otherwise
232 */
233int sde_power_resource_is_enabled(struct sde_power_handle *pdata);
234
235/**
Dhaval Patelc4f1c7c2017-08-16 12:02:21 -0700236 * sde_power_data_bus_state_update() - update data bus state
237 * @pdata: power handle containing the resources
238 * @enable: take enable vs disable path
239 *
240 * Return: error code.
241 */
242int sde_power_data_bus_state_update(struct sde_power_handle *phandle,
243 bool enable);
244
245/**
Dhaval Patel480dc522016-07-27 18:36:59 -0700246 * sde_power_clk_set_rate() - set the clock rate
247 * @pdata: power handle containing the resources
248 * @clock_name: clock name which needs rate update.
249 * @rate: Requested rate.
250 *
251 * Return: error code.
252 */
253int sde_power_clk_set_rate(struct sde_power_handle *pdata, char *clock_name,
254 u64 rate);
255
256/**
257 * sde_power_clk_get_rate() - get the clock rate
258 * @pdata: power handle containing the resources
259 * @clock_name: clock name to get the rate
260 *
261 * Return: current clock rate
262 */
263u64 sde_power_clk_get_rate(struct sde_power_handle *pdata, char *clock_name);
264
Alan Kwong67a3f792016-11-01 23:16:53 -0400265/**
266 * sde_power_clk_get_max_rate() - get the maximum clock rate
267 * @pdata: power handle containing the resources
268 * @clock_name: clock name to get the max rate.
269 *
270 * Return: maximum clock rate or 0 if not found.
271 */
272u64 sde_power_clk_get_max_rate(struct sde_power_handle *pdata,
273 char *clock_name);
274
275/**
276 * sde_power_clk_get_clk() - get the clock
277 * @pdata: power handle containing the resources
278 * @clock_name: clock name to get the clk pointer.
279 *
280 * Return: Pointer to clock
281 */
282struct clk *sde_power_clk_get_clk(struct sde_power_handle *phandle,
283 char *clock_name);
284
285/**
286 * sde_power_data_bus_set_quota() - set data bus quota for power client
287 * @phandle: power handle containing the resources
288 * @client: client information to set quota
289 * @bus_client: real-time or non-real-time bus client
Alan Kwong0230a102017-05-16 11:36:44 -0700290 * @bus_id: identifier of data bus, see SDE_POWER_HANDLE_DBUS_ID
Alan Kwong67a3f792016-11-01 23:16:53 -0400291 * @ab_quota: arbitrated bus bandwidth
292 * @ib_quota: instantaneous bus bandwidth
293 *
294 * Return: zero if success, or error code otherwise
295 */
296int sde_power_data_bus_set_quota(struct sde_power_handle *phandle,
297 struct sde_power_client *pclient,
Alan Kwong0230a102017-05-16 11:36:44 -0700298 int bus_client, u32 bus_id,
299 u64 ab_quota, u64 ib_quota);
Alan Kwong67a3f792016-11-01 23:16:53 -0400300
301/**
302 * sde_power_data_bus_bandwidth_ctrl() - control data bus bandwidth enable
303 * @phandle: power handle containing the resources
304 * @client: client information to bandwidth control
305 * @enable: true to enable bandwidth for data base
306 *
307 * Return: none
308 */
309void sde_power_data_bus_bandwidth_ctrl(struct sde_power_handle *phandle,
310 struct sde_power_client *pclient, int enable);
311
Veera Sundaram Sankaran410d1562017-03-24 14:48:13 -0700312/**
313 * sde_power_handle_register_event - register a callback function for an event.
314 * Clients can register for multiple events with a single register.
315 * Any block with access to phandle can register for the event
316 * notification.
317 * @phandle: power handle containing the resources
318 * @event_type: event type to register; refer SDE_POWER_HANDLE_EVENT_*
319 * @cb_fnc: pointer to desired callback function
320 * @usr: user pointer to pass to callback on event trigger
321 *
322 * Return: event pointer if success, or error code otherwise
323 */
324struct sde_power_event *sde_power_handle_register_event(
325 struct sde_power_handle *phandle,
326 u32 event_type, void (*cb_fnc)(u32 event_type, void *usr),
327 void *usr, char *client_name);
328/**
329 * sde_power_handle_unregister_event - unregister callback for event(s)
330 * @phandle: power handle containing the resources
331 * @event: event pointer returned after power handle register
332 */
333void sde_power_handle_unregister_event(struct sde_power_handle *phandle,
334 struct sde_power_event *event);
335
Alan Kwong0230a102017-05-16 11:36:44 -0700336/**
337 * sde_power_handle_get_dbus_name - get name of given data bus identifier
338 * @bus_id: data bus identifier
339 * Return: Pointer to name string if success; NULL otherwise
340 */
341const char *sde_power_handle_get_dbus_name(u32 bus_id);
342
Dhaval Patel480dc522016-07-27 18:36:59 -0700343#endif /* _SDE_POWER_HANDLE_H_ */