1 /* Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
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.
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.
14 #ifndef _DPU_POWER_HANDLE_H_
15 #define _DPU_POWER_HANDLE_H_
17 #define MAX_CLIENT_NAME_LEN 128
19 #define DPU_POWER_HANDLE_ENABLE_BUS_AB_QUOTA 0
20 #define DPU_POWER_HANDLE_DISABLE_BUS_AB_QUOTA 0
21 #define DPU_POWER_HANDLE_ENABLE_BUS_IB_QUOTA 1600000000
22 #define DPU_POWER_HANDLE_DISABLE_BUS_IB_QUOTA 0
24 #include "dpu_io_util.h"
26 /* event will be triggered before power handler disable */
27 #define DPU_POWER_EVENT_PRE_DISABLE 0x1
29 /* event will be triggered after power handler disable */
30 #define DPU_POWER_EVENT_POST_DISABLE 0x2
32 /* event will be triggered before power handler enable */
33 #define DPU_POWER_EVENT_PRE_ENABLE 0x4
35 /* event will be triggered after power handler enable */
36 #define DPU_POWER_EVENT_POST_ENABLE 0x8
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
44 enum mdss_bus_vote_type {
51 * enum dpu_power_handle_data_bus_client - type of axi bus clients
52 * @DPU_POWER_HANDLE_DATA_BUS_CLIENT_RT: core real-time bus client
53 * @DPU_POWER_HANDLE_DATA_BUS_CLIENT_NRT: core non-real-time bus client
54 * @DPU_POWER_HANDLE_DATA_BUS_CLIENT_MAX: maximum number of bus client type
56 enum dpu_power_handle_data_bus_client {
57 DPU_POWER_HANDLE_DATA_BUS_CLIENT_RT,
58 DPU_POWER_HANDLE_DATA_BUS_CLIENT_NRT,
59 DPU_POWER_HANDLE_DATA_BUS_CLIENT_MAX
63 * enum DPU_POWER_HANDLE_DBUS_ID - data bus identifier
64 * @DPU_POWER_HANDLE_DBUS_ID_MNOC: DPU/MNOC data bus
65 * @DPU_POWER_HANDLE_DBUS_ID_LLCC: MNOC/LLCC data bus
66 * @DPU_POWER_HANDLE_DBUS_ID_EBI: LLCC/EBI data bus
68 enum DPU_POWER_HANDLE_DBUS_ID {
69 DPU_POWER_HANDLE_DBUS_ID_MNOC,
70 DPU_POWER_HANDLE_DBUS_ID_LLCC,
71 DPU_POWER_HANDLE_DBUS_ID_EBI,
72 DPU_POWER_HANDLE_DBUS_ID_MAX,
76 * struct dpu_power_client: stores the power client for dpu 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
83 * @id: assigned during create. helps for debugging.
84 * @list: list to attach power handle master list
85 * @ab: arbitrated bandwidth for each bus client
86 * @ib: instantaneous bandwidth for each bus client
87 * @active: inidcates the state of dpu power handle
89 struct dpu_power_client {
90 char name[MAX_CLIENT_NAME_LEN];
94 struct list_head list;
95 u64 ab[DPU_POWER_HANDLE_DATA_BUS_CLIENT_MAX];
96 u64 ib[DPU_POWER_HANDLE_DATA_BUS_CLIENT_MAX];
101 * struct dpu_power_event - local event registration structure
102 * @client_name: name of the client registering
103 * @cb_fnc: pointer to desired callback function
104 * @usr: user pointer to pass to callback event trigger
105 * @event: refer to DPU_POWER_HANDLE_EVENT_*
106 * @list: list to attach event master list
107 * @active: indicates the state of dpu power handle
109 struct dpu_power_event {
110 char client_name[MAX_CLIENT_NAME_LEN];
111 void (*cb_fnc)(u32 event_type, void *usr);
114 struct list_head list;
119 * struct dpu_power_handle: power handle main struct
120 * @client_clist: master list to store all clients
121 * @phandle_lock: lock to synchronize the enable/disable
122 * @dev: pointer to device structure
123 * @usecase_ndx: current usecase index
124 * @event_list: current power handle event list
126 struct dpu_power_handle {
127 struct list_head power_client_clist;
128 struct mutex phandle_lock;
130 u32 current_usecase_ndx;
131 struct list_head event_list;
135 * dpu_power_resource_init() - initializes the dpu power handle
136 * @pdev: platform device to search the power resources
137 * @pdata: power handle to store the power resources
139 void dpu_power_resource_init(struct platform_device *pdev,
140 struct dpu_power_handle *pdata);
143 * dpu_power_resource_deinit() - release the dpu power handle
144 * @pdev: platform device for power resources
145 * @pdata: power handle containing the resources
147 * Return: error code.
149 void dpu_power_resource_deinit(struct platform_device *pdev,
150 struct dpu_power_handle *pdata);
153 * dpu_power_client_create() - create the client on power handle
154 * @pdata: power handle containing the resources
155 * @client_name: new client name for registration
157 * Return: error code.
159 struct dpu_power_client *dpu_power_client_create(struct dpu_power_handle *pdata,
163 * dpu_power_client_destroy() - destroy the client on power handle
164 * @pdata: power handle containing the resources
165 * @client_name: new client name for registration
169 void dpu_power_client_destroy(struct dpu_power_handle *phandle,
170 struct dpu_power_client *client);
173 * dpu_power_resource_enable() - enable/disable the power resources
174 * @pdata: power handle containing the resources
175 * @client: client information to enable/disable its vote
176 * @enable: boolean request for enable/disable
178 * Return: error code.
180 int dpu_power_resource_enable(struct dpu_power_handle *pdata,
181 struct dpu_power_client *pclient, bool enable);
184 * dpu_power_data_bus_bandwidth_ctrl() - control data bus bandwidth enable
185 * @phandle: power handle containing the resources
186 * @client: client information to bandwidth control
187 * @enable: true to enable bandwidth for data base
191 void dpu_power_data_bus_bandwidth_ctrl(struct dpu_power_handle *phandle,
192 struct dpu_power_client *pclient, int enable);
195 * dpu_power_handle_register_event - register a callback function for an event.
196 * Clients can register for multiple events with a single register.
197 * Any block with access to phandle can register for the event
199 * @phandle: power handle containing the resources
200 * @event_type: event type to register; refer DPU_POWER_HANDLE_EVENT_*
201 * @cb_fnc: pointer to desired callback function
202 * @usr: user pointer to pass to callback on event trigger
204 * Return: event pointer if success, or error code otherwise
206 struct dpu_power_event *dpu_power_handle_register_event(
207 struct dpu_power_handle *phandle,
208 u32 event_type, void (*cb_fnc)(u32 event_type, void *usr),
209 void *usr, char *client_name);
211 * dpu_power_handle_unregister_event - unregister callback for event(s)
212 * @phandle: power handle containing the resources
213 * @event: event pointer returned after power handle register
215 void dpu_power_handle_unregister_event(struct dpu_power_handle *phandle,
216 struct dpu_power_event *event);
219 * dpu_power_handle_get_dbus_name - get name of given data bus identifier
220 * @bus_id: data bus identifier
221 * Return: Pointer to name string if success; NULL otherwise
223 const char *dpu_power_handle_get_dbus_name(u32 bus_id);
225 #endif /* _DPU_POWER_HANDLE_H_ */