blob: 18777fda9b56bd90fe9037c9ea2a73643e3022f0 [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
Alan Kwongecd870b2017-06-16 15:31:28 -040021#define SDE_POWER_HANDLE_ENABLE_BUS_IB_QUOTA 1600000000
Dhaval Patel60c25062017-02-21 17:44:05 -080022#define SDE_POWER_HANDLE_DISABLE_BUS_IB_QUOTA 0
Alan Kwong67a3f792016-11-01 23:16:53 -040023
Shashank Babu Chinta Venkata74a03f12017-02-28 11:24:51 -080024#include <linux/sde_io_util.h>
25
Veera Sundaram Sankaran410d1562017-03-24 14:48:13 -070026/* event will be triggered before power handler disable */
27#define SDE_POWER_EVENT_PRE_DISABLE 0x1
28
29/* event will be triggered after power handler disable */
30#define SDE_POWER_EVENT_POST_DISABLE 0x2
31
32/* event will be triggered before power handler enable */
33#define SDE_POWER_EVENT_PRE_ENABLE 0x4
34
35/* event will be triggered after power handler enable */
36#define SDE_POWER_EVENT_POST_ENABLE 0x8
37
Dhaval Patel480dc522016-07-27 18:36:59 -070038/**
39 * mdss_bus_vote_type: register bus vote type
40 * VOTE_INDEX_DISABLE: removes the client vote
41 * VOTE_INDEX_LOW: keeps the lowest vote for register bus
42 * VOTE_INDEX_MAX: invalid
43 */
44enum mdss_bus_vote_type {
45 VOTE_INDEX_DISABLE,
46 VOTE_INDEX_LOW,
47 VOTE_INDEX_MAX,
48};
49
50/**
Alan Kwong67a3f792016-11-01 23:16:53 -040051 * enum sde_power_handle_data_bus_client - type of axi bus clients
52 * @SDE_POWER_HANDLE_DATA_BUS_CLIENT_RT: core real-time bus client
53 * @SDE_POWER_HANDLE_DATA_BUS_CLIENT_NRT: core non-real-time bus client
54 * @SDE_POWER_HANDLE_DATA_BUS_CLIENT_MAX: maximum number of bus client type
55 */
56enum sde_power_handle_data_bus_client {
57 SDE_POWER_HANDLE_DATA_BUS_CLIENT_RT,
58 SDE_POWER_HANDLE_DATA_BUS_CLIENT_NRT,
59 SDE_POWER_HANDLE_DATA_BUS_CLIENT_MAX
60};
61
62/**
Alan Kwong0230a102017-05-16 11:36:44 -070063 * enum SDE_POWER_HANDLE_DBUS_ID - data bus identifier
64 * @SDE_POWER_HANDLE_DBUS_ID_MNOC: DPU/MNOC data bus
65 * @SDE_POWER_HANDLE_DBUS_ID_LLCC: MNOC/LLCC data bus
66 * @SDE_POWER_HANDLE_DBUS_ID_EBI: LLCC/EBI data bus
67 */
68enum SDE_POWER_HANDLE_DBUS_ID {
69 SDE_POWER_HANDLE_DBUS_ID_MNOC,
70 SDE_POWER_HANDLE_DBUS_ID_LLCC,
71 SDE_POWER_HANDLE_DBUS_ID_EBI,
72 SDE_POWER_HANDLE_DBUS_ID_MAX,
73};
74
75/**
Dhaval Patel480dc522016-07-27 18:36:59 -070076 * struct sde_power_client: stores the power client for sde driver
77 * @name: name of the client
78 * @usecase_ndx: current regs bus vote type
79 * @refcount: current refcount if multiple modules are using same
80 * same client for enable/disable. Power module will
81 * aggregate the refcount and vote accordingly for this
82 * client.
83 * @id: assigned during create. helps for debugging.
84 * @list: list to attach power handle master list
Alan Kwong67a3f792016-11-01 23:16:53 -040085 * @ab: arbitrated bandwidth for each bus client
86 * @ib: instantaneous bandwidth for each bus client
Veera Sundaram Sankaran410d1562017-03-24 14:48:13 -070087 * @active: inidcates the state of sde power handle
Dhaval Patel480dc522016-07-27 18:36:59 -070088 */
89struct sde_power_client {
90 char name[MAX_CLIENT_NAME_LEN];
91 short usecase_ndx;
92 short refcount;
93 u32 id;
94 struct list_head list;
Alan Kwong67a3f792016-11-01 23:16:53 -040095 u64 ab[SDE_POWER_HANDLE_DATA_BUS_CLIENT_MAX];
96 u64 ib[SDE_POWER_HANDLE_DATA_BUS_CLIENT_MAX];
Veera Sundaram Sankaran410d1562017-03-24 14:48:13 -070097 bool active;
Alan Kwong67a3f792016-11-01 23:16:53 -040098};
99
100/**
101 * struct sde_power_data_handle: power handle struct for data bus
102 * @data_bus_scale_table: pointer to bus scaling table
103 * @data_bus_hdl: current data bus handle
104 * @axi_port_cnt: number of rt axi ports
105 * @nrt_axi_port_cnt: number of nrt axi ports
106 * @bus_channels: number of memory bus channels
107 * @curr_bw_uc_idx: current use case index of data bus
108 * @ao_bw_uc_idx: active only use case index of data bus
Alan Kwongff30f4a2017-05-23 12:02:00 -0700109 * @ab_rt: realtime ab quota
110 * @ib_rt: realtime ib quota
111 * @ab_nrt: non-realtime ab quota
112 * @ib_nrt: non-realtime ib quota
113 * @enable: true if bus is enabled
Alan Kwong67a3f792016-11-01 23:16:53 -0400114 */
115struct sde_power_data_bus_handle {
116 struct msm_bus_scale_pdata *data_bus_scale_table;
117 u32 data_bus_hdl;
118 u32 axi_port_cnt;
119 u32 nrt_axi_port_cnt;
120 u32 bus_channels;
121 u32 curr_bw_uc_idx;
122 u32 ao_bw_uc_idx;
Alan Kwongff30f4a2017-05-23 12:02:00 -0700123 u64 ab_rt;
124 u64 ib_rt;
125 u64 ab_nrt;
126 u64 ib_nrt;
127 bool enable;
Dhaval Patel480dc522016-07-27 18:36:59 -0700128};
129
Veera Sundaram Sankaran410d1562017-03-24 14:48:13 -0700130/*
131 * struct sde_power_event - local event registration structure
132 * @client_name: name of the client registering
133 * @cb_fnc: pointer to desired callback function
134 * @usr: user pointer to pass to callback event trigger
135 * @event: refer to SDE_POWER_HANDLE_EVENT_*
136 * @list: list to attach event master list
137 * @active: indicates the state of sde power handle
138 */
139struct sde_power_event {
140 char client_name[MAX_CLIENT_NAME_LEN];
141 void (*cb_fnc)(u32 event_type, void *usr);
142 void *usr;
143 u32 event_type;
144 struct list_head list;
145 bool active;
146};
147
Dhaval Patel480dc522016-07-27 18:36:59 -0700148/**
149 * struct sde_power_handle: power handle main struct
150 * @mp: module power for clock and regulator
151 * @client_clist: master list to store all clients
152 * @phandle_lock: lock to synchronize the enable/disable
Alan Kwong67a3f792016-11-01 23:16:53 -0400153 * @dev: pointer to device structure
Dhaval Patel480dc522016-07-27 18:36:59 -0700154 * @usecase_ndx: current usecase index
155 * @reg_bus_hdl: current register bus handle
Alan Kwong67a3f792016-11-01 23:16:53 -0400156 * @data_bus_handle: context structure for data bus control
Veera Sundaram Sankaran410d1562017-03-24 14:48:13 -0700157 * @event_list: current power handle event list
Veera Sundaram Sankaran38318f12017-03-24 15:54:21 -0700158 * @rsc_client: sde rsc client pointer
159 * @rsc_client_init: boolean to control rsc client create
Dhaval Patel480dc522016-07-27 18:36:59 -0700160 */
161struct sde_power_handle {
162 struct dss_module_power mp;
163 struct list_head power_client_clist;
164 struct mutex phandle_lock;
Alan Kwong67a3f792016-11-01 23:16:53 -0400165 struct device *dev;
Dhaval Patel480dc522016-07-27 18:36:59 -0700166 u32 current_usecase_ndx;
Dhaval Patel480dc522016-07-27 18:36:59 -0700167 u32 reg_bus_hdl;
Alan Kwong0230a102017-05-16 11:36:44 -0700168 struct sde_power_data_bus_handle data_bus_handle
169 [SDE_POWER_HANDLE_DBUS_ID_MAX];
Veera Sundaram Sankaran410d1562017-03-24 14:48:13 -0700170 struct list_head event_list;
Veera Sundaram Sankaran38318f12017-03-24 15:54:21 -0700171 struct sde_rsc_client *rsc_client;
172 bool rsc_client_init;
Dhaval Patel480dc522016-07-27 18:36:59 -0700173};
174
175/**
176 * sde_power_resource_init() - initializes the sde power handle
177 * @pdev: platform device to search the power resources
178 * @pdata: power handle to store the power resources
179 *
180 * Return: error code.
181 */
182int sde_power_resource_init(struct platform_device *pdev,
183 struct sde_power_handle *pdata);
184
185/**
186 * sde_power_resource_deinit() - release the sde power handle
187 * @pdev: platform device for power resources
188 * @pdata: power handle containing the resources
189 *
190 * Return: error code.
191 */
192void sde_power_resource_deinit(struct platform_device *pdev,
193 struct sde_power_handle *pdata);
194
195/**
196 * sde_power_client_create() - create the client on power handle
197 * @pdata: power handle containing the resources
198 * @client_name: new client name for registration
199 *
200 * Return: error code.
201 */
202struct sde_power_client *sde_power_client_create(struct sde_power_handle *pdata,
203 char *client_name);
204
205/**
206 * sde_power_client_destroy() - destroy the client on power handle
207 * @pdata: power handle containing the resources
208 * @client_name: new client name for registration
209 *
210 * Return: none
211 */
212void sde_power_client_destroy(struct sde_power_handle *phandle,
213 struct sde_power_client *client);
214
215/**
216 * sde_power_resource_enable() - enable/disable the power resources
217 * @pdata: power handle containing the resources
218 * @client: client information to enable/disable its vote
219 * @enable: boolean request for enable/disable
220 *
221 * Return: error code.
222 */
223int sde_power_resource_enable(struct sde_power_handle *pdata,
224 struct sde_power_client *pclient, bool enable);
225
226/**
Dhaval Patelc4f1c7c2017-08-16 12:02:21 -0700227 * sde_power_data_bus_state_update() - update data bus state
228 * @pdata: power handle containing the resources
229 * @enable: take enable vs disable path
230 *
231 * Return: error code.
232 */
233int sde_power_data_bus_state_update(struct sde_power_handle *phandle,
234 bool enable);
235
236/**
Dhaval Patel480dc522016-07-27 18:36:59 -0700237 * sde_power_clk_set_rate() - set the clock rate
238 * @pdata: power handle containing the resources
239 * @clock_name: clock name which needs rate update.
240 * @rate: Requested rate.
241 *
242 * Return: error code.
243 */
244int sde_power_clk_set_rate(struct sde_power_handle *pdata, char *clock_name,
245 u64 rate);
246
247/**
248 * sde_power_clk_get_rate() - get the clock rate
249 * @pdata: power handle containing the resources
250 * @clock_name: clock name to get the rate
251 *
252 * Return: current clock rate
253 */
254u64 sde_power_clk_get_rate(struct sde_power_handle *pdata, char *clock_name);
255
Alan Kwong67a3f792016-11-01 23:16:53 -0400256/**
257 * sde_power_clk_get_max_rate() - get the maximum clock rate
258 * @pdata: power handle containing the resources
259 * @clock_name: clock name to get the max rate.
260 *
261 * Return: maximum clock rate or 0 if not found.
262 */
263u64 sde_power_clk_get_max_rate(struct sde_power_handle *pdata,
264 char *clock_name);
265
266/**
267 * sde_power_clk_get_clk() - get the clock
268 * @pdata: power handle containing the resources
269 * @clock_name: clock name to get the clk pointer.
270 *
271 * Return: Pointer to clock
272 */
273struct clk *sde_power_clk_get_clk(struct sde_power_handle *phandle,
274 char *clock_name);
275
276/**
277 * sde_power_data_bus_set_quota() - set data bus quota for power client
278 * @phandle: power handle containing the resources
279 * @client: client information to set quota
280 * @bus_client: real-time or non-real-time bus client
Alan Kwong0230a102017-05-16 11:36:44 -0700281 * @bus_id: identifier of data bus, see SDE_POWER_HANDLE_DBUS_ID
Alan Kwong67a3f792016-11-01 23:16:53 -0400282 * @ab_quota: arbitrated bus bandwidth
283 * @ib_quota: instantaneous bus bandwidth
284 *
285 * Return: zero if success, or error code otherwise
286 */
287int sde_power_data_bus_set_quota(struct sde_power_handle *phandle,
288 struct sde_power_client *pclient,
Alan Kwong0230a102017-05-16 11:36:44 -0700289 int bus_client, u32 bus_id,
290 u64 ab_quota, u64 ib_quota);
Alan Kwong67a3f792016-11-01 23:16:53 -0400291
292/**
293 * sde_power_data_bus_bandwidth_ctrl() - control data bus bandwidth enable
294 * @phandle: power handle containing the resources
295 * @client: client information to bandwidth control
296 * @enable: true to enable bandwidth for data base
297 *
298 * Return: none
299 */
300void sde_power_data_bus_bandwidth_ctrl(struct sde_power_handle *phandle,
301 struct sde_power_client *pclient, int enable);
302
Veera Sundaram Sankaran410d1562017-03-24 14:48:13 -0700303/**
304 * sde_power_handle_register_event - register a callback function for an event.
305 * Clients can register for multiple events with a single register.
306 * Any block with access to phandle can register for the event
307 * notification.
308 * @phandle: power handle containing the resources
309 * @event_type: event type to register; refer SDE_POWER_HANDLE_EVENT_*
310 * @cb_fnc: pointer to desired callback function
311 * @usr: user pointer to pass to callback on event trigger
312 *
313 * Return: event pointer if success, or error code otherwise
314 */
315struct sde_power_event *sde_power_handle_register_event(
316 struct sde_power_handle *phandle,
317 u32 event_type, void (*cb_fnc)(u32 event_type, void *usr),
318 void *usr, char *client_name);
319/**
320 * sde_power_handle_unregister_event - unregister callback for event(s)
321 * @phandle: power handle containing the resources
322 * @event: event pointer returned after power handle register
323 */
324void sde_power_handle_unregister_event(struct sde_power_handle *phandle,
325 struct sde_power_event *event);
326
Alan Kwong0230a102017-05-16 11:36:44 -0700327/**
328 * sde_power_handle_get_dbus_name - get name of given data bus identifier
329 * @bus_id: data bus identifier
330 * Return: Pointer to name string if success; NULL otherwise
331 */
332const char *sde_power_handle_get_dbus_name(u32 bus_id);
333
Dhaval Patel480dc522016-07-27 18:36:59 -0700334#endif /* _SDE_POWER_HANDLE_H_ */