1 /* Copyright (c) 2016-2018, 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 _DPU_POWER_HANDLE_H_ 15 #define _DPU_POWER_HANDLE_H_ 16 17 #define MAX_CLIENT_NAME_LEN 128 18 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 23 24 #include "dpu_io_util.h" 25 26 /* event will be triggered before power handler disable */ 27 #define DPU_POWER_EVENT_PRE_DISABLE 0x1 28 29 /* event will be triggered after power handler disable */ 30 #define DPU_POWER_EVENT_POST_DISABLE 0x2 31 32 /* event will be triggered before power handler enable */ 33 #define DPU_POWER_EVENT_PRE_ENABLE 0x4 34 35 /* event will be triggered after power handler enable */ 36 #define DPU_POWER_EVENT_POST_ENABLE 0x8 37 38 /** 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 */ 44 enum mdss_bus_vote_type { 45 VOTE_INDEX_DISABLE, 46 VOTE_INDEX_LOW, 47 VOTE_INDEX_MAX, 48 }; 49 50 /** 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 55 */ 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 60 }; 61 62 /** 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 67 */ 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, 73 }; 74 75 /** 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 82 * client. 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 88 */ 89 struct dpu_power_client { 90 char name[MAX_CLIENT_NAME_LEN]; 91 short usecase_ndx; 92 short refcount; 93 u32 id; 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]; 97 bool active; 98 }; 99 100 /* 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 108 */ 109 struct dpu_power_event { 110 char client_name[MAX_CLIENT_NAME_LEN]; 111 void (*cb_fnc)(u32 event_type, void *usr); 112 void *usr; 113 u32 event_type; 114 struct list_head list; 115 bool active; 116 }; 117 118 /** 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 125 */ 126 struct dpu_power_handle { 127 struct list_head power_client_clist; 128 struct mutex phandle_lock; 129 struct device *dev; 130 u32 current_usecase_ndx; 131 struct list_head event_list; 132 }; 133 134 /** 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 138 */ 139 void dpu_power_resource_init(struct platform_device *pdev, 140 struct dpu_power_handle *pdata); 141 142 /** 143 * dpu_power_resource_deinit() - release the dpu power handle 144 * @pdev: platform device for power resources 145 * @pdata: power handle containing the resources 146 * 147 * Return: error code. 148 */ 149 void dpu_power_resource_deinit(struct platform_device *pdev, 150 struct dpu_power_handle *pdata); 151 152 /** 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 156 * 157 * Return: error code. 158 */ 159 struct dpu_power_client *dpu_power_client_create(struct dpu_power_handle *pdata, 160 char *client_name); 161 162 /** 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 166 * 167 * Return: none 168 */ 169 void dpu_power_client_destroy(struct dpu_power_handle *phandle, 170 struct dpu_power_client *client); 171 172 /** 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 177 * 178 * Return: error code. 179 */ 180 int dpu_power_resource_enable(struct dpu_power_handle *pdata, 181 struct dpu_power_client *pclient, bool enable); 182 183 /** 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 188 * 189 * Return: none 190 */ 191 void dpu_power_data_bus_bandwidth_ctrl(struct dpu_power_handle *phandle, 192 struct dpu_power_client *pclient, int enable); 193 194 /** 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 198 * notification. 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 203 * 204 * Return: event pointer if success, or error code otherwise 205 */ 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); 210 /** 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 214 */ 215 void dpu_power_handle_unregister_event(struct dpu_power_handle *phandle, 216 struct dpu_power_event *event); 217 218 /** 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 222 */ 223 const char *dpu_power_handle_get_dbus_name(u32 bus_id); 224 225 #endif /* _DPU_POWER_HANDLE_H_ */ 226