Dhaval Patel | 3fe015e | 2017-02-18 10:11:27 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2016-2017, The Linux Foundation. All rights reserved. |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 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_POWER_HANDLE_H_ |
| 15 | #define _SDE_POWER_HANDLE_H_ |
| 16 | |
| 17 | #define MAX_CLIENT_NAME_LEN 128 |
| 18 | |
Alan Kwong | ecd870b | 2017-06-16 15:31:28 -0400 | [diff] [blame^] | 19 | #define SDE_POWER_HANDLE_ENABLE_BUS_AB_QUOTA 1600000000 |
Dhaval Patel | 60c2506 | 2017-02-21 17:44:05 -0800 | [diff] [blame] | 20 | #define SDE_POWER_HANDLE_DISABLE_BUS_AB_QUOTA 0 |
Alan Kwong | ecd870b | 2017-06-16 15:31:28 -0400 | [diff] [blame^] | 21 | #define SDE_POWER_HANDLE_ENABLE_BUS_IB_QUOTA 1600000000 |
Dhaval Patel | 60c2506 | 2017-02-21 17:44:05 -0800 | [diff] [blame] | 22 | #define SDE_POWER_HANDLE_DISABLE_BUS_IB_QUOTA 0 |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 23 | |
Shashank Babu Chinta Venkata | 74a03f1 | 2017-02-28 11:24:51 -0800 | [diff] [blame] | 24 | #include <linux/sde_io_util.h> |
| 25 | |
Veera Sundaram Sankaran | 410d156 | 2017-03-24 14:48:13 -0700 | [diff] [blame] | 26 | /* 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 Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 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 | /** |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 51 | * 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 | */ |
| 56 | enum 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 | /** |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 63 | * struct sde_power_client: stores the power client for sde driver |
| 64 | * @name: name of the client |
| 65 | * @usecase_ndx: current regs bus vote type |
| 66 | * @refcount: current refcount if multiple modules are using same |
| 67 | * same client for enable/disable. Power module will |
| 68 | * aggregate the refcount and vote accordingly for this |
| 69 | * client. |
| 70 | * @id: assigned during create. helps for debugging. |
| 71 | * @list: list to attach power handle master list |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 72 | * @ab: arbitrated bandwidth for each bus client |
| 73 | * @ib: instantaneous bandwidth for each bus client |
Veera Sundaram Sankaran | 410d156 | 2017-03-24 14:48:13 -0700 | [diff] [blame] | 74 | * @active: inidcates the state of sde power handle |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 75 | */ |
| 76 | struct sde_power_client { |
| 77 | char name[MAX_CLIENT_NAME_LEN]; |
| 78 | short usecase_ndx; |
| 79 | short refcount; |
| 80 | u32 id; |
| 81 | struct list_head list; |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 82 | u64 ab[SDE_POWER_HANDLE_DATA_BUS_CLIENT_MAX]; |
| 83 | u64 ib[SDE_POWER_HANDLE_DATA_BUS_CLIENT_MAX]; |
Veera Sundaram Sankaran | 410d156 | 2017-03-24 14:48:13 -0700 | [diff] [blame] | 84 | bool active; |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | /** |
| 88 | * struct sde_power_data_handle: power handle struct for data bus |
| 89 | * @data_bus_scale_table: pointer to bus scaling table |
| 90 | * @data_bus_hdl: current data bus handle |
| 91 | * @axi_port_cnt: number of rt axi ports |
| 92 | * @nrt_axi_port_cnt: number of nrt axi ports |
| 93 | * @bus_channels: number of memory bus channels |
| 94 | * @curr_bw_uc_idx: current use case index of data bus |
| 95 | * @ao_bw_uc_idx: active only use case index of data bus |
Alan Kwong | ff30f4a | 2017-05-23 12:02:00 -0700 | [diff] [blame] | 96 | * @ab_rt: realtime ab quota |
| 97 | * @ib_rt: realtime ib quota |
| 98 | * @ab_nrt: non-realtime ab quota |
| 99 | * @ib_nrt: non-realtime ib quota |
| 100 | * @enable: true if bus is enabled |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 101 | */ |
| 102 | struct sde_power_data_bus_handle { |
| 103 | struct msm_bus_scale_pdata *data_bus_scale_table; |
| 104 | u32 data_bus_hdl; |
| 105 | u32 axi_port_cnt; |
| 106 | u32 nrt_axi_port_cnt; |
| 107 | u32 bus_channels; |
| 108 | u32 curr_bw_uc_idx; |
| 109 | u32 ao_bw_uc_idx; |
Alan Kwong | ff30f4a | 2017-05-23 12:02:00 -0700 | [diff] [blame] | 110 | u64 ab_rt; |
| 111 | u64 ib_rt; |
| 112 | u64 ab_nrt; |
| 113 | u64 ib_nrt; |
| 114 | bool enable; |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 115 | }; |
| 116 | |
Veera Sundaram Sankaran | 410d156 | 2017-03-24 14:48:13 -0700 | [diff] [blame] | 117 | /* |
| 118 | * struct sde_power_event - local event registration structure |
| 119 | * @client_name: name of the client registering |
| 120 | * @cb_fnc: pointer to desired callback function |
| 121 | * @usr: user pointer to pass to callback event trigger |
| 122 | * @event: refer to SDE_POWER_HANDLE_EVENT_* |
| 123 | * @list: list to attach event master list |
| 124 | * @active: indicates the state of sde power handle |
| 125 | */ |
| 126 | struct sde_power_event { |
| 127 | char client_name[MAX_CLIENT_NAME_LEN]; |
| 128 | void (*cb_fnc)(u32 event_type, void *usr); |
| 129 | void *usr; |
| 130 | u32 event_type; |
| 131 | struct list_head list; |
| 132 | bool active; |
| 133 | }; |
| 134 | |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 135 | /** |
| 136 | * struct sde_power_handle: power handle main struct |
| 137 | * @mp: module power for clock and regulator |
| 138 | * @client_clist: master list to store all clients |
| 139 | * @phandle_lock: lock to synchronize the enable/disable |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 140 | * @dev: pointer to device structure |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 141 | * @usecase_ndx: current usecase index |
| 142 | * @reg_bus_hdl: current register bus handle |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 143 | * @data_bus_handle: context structure for data bus control |
Veera Sundaram Sankaran | 410d156 | 2017-03-24 14:48:13 -0700 | [diff] [blame] | 144 | * @event_list: current power handle event list |
Veera Sundaram Sankaran | 38318f1 | 2017-03-24 15:54:21 -0700 | [diff] [blame] | 145 | * @rsc_client: sde rsc client pointer |
| 146 | * @rsc_client_init: boolean to control rsc client create |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 147 | */ |
| 148 | struct sde_power_handle { |
| 149 | struct dss_module_power mp; |
| 150 | struct list_head power_client_clist; |
| 151 | struct mutex phandle_lock; |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 152 | struct device *dev; |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 153 | u32 current_usecase_ndx; |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 154 | u32 reg_bus_hdl; |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 155 | struct sde_power_data_bus_handle data_bus_handle; |
Veera Sundaram Sankaran | 410d156 | 2017-03-24 14:48:13 -0700 | [diff] [blame] | 156 | struct list_head event_list; |
Veera Sundaram Sankaran | 38318f1 | 2017-03-24 15:54:21 -0700 | [diff] [blame] | 157 | struct sde_rsc_client *rsc_client; |
| 158 | bool rsc_client_init; |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 159 | }; |
| 160 | |
| 161 | /** |
| 162 | * sde_power_resource_init() - initializes the sde power handle |
| 163 | * @pdev: platform device to search the power resources |
| 164 | * @pdata: power handle to store the power resources |
| 165 | * |
| 166 | * Return: error code. |
| 167 | */ |
| 168 | int sde_power_resource_init(struct platform_device *pdev, |
| 169 | struct sde_power_handle *pdata); |
| 170 | |
| 171 | /** |
| 172 | * sde_power_resource_deinit() - release the sde power handle |
| 173 | * @pdev: platform device for power resources |
| 174 | * @pdata: power handle containing the resources |
| 175 | * |
| 176 | * Return: error code. |
| 177 | */ |
| 178 | void sde_power_resource_deinit(struct platform_device *pdev, |
| 179 | struct sde_power_handle *pdata); |
| 180 | |
| 181 | /** |
| 182 | * sde_power_client_create() - create the client on power handle |
| 183 | * @pdata: power handle containing the resources |
| 184 | * @client_name: new client name for registration |
| 185 | * |
| 186 | * Return: error code. |
| 187 | */ |
| 188 | struct sde_power_client *sde_power_client_create(struct sde_power_handle *pdata, |
| 189 | char *client_name); |
| 190 | |
| 191 | /** |
| 192 | * sde_power_client_destroy() - destroy the client on power handle |
| 193 | * @pdata: power handle containing the resources |
| 194 | * @client_name: new client name for registration |
| 195 | * |
| 196 | * Return: none |
| 197 | */ |
| 198 | void sde_power_client_destroy(struct sde_power_handle *phandle, |
| 199 | struct sde_power_client *client); |
| 200 | |
| 201 | /** |
| 202 | * sde_power_resource_enable() - enable/disable the power resources |
| 203 | * @pdata: power handle containing the resources |
| 204 | * @client: client information to enable/disable its vote |
| 205 | * @enable: boolean request for enable/disable |
| 206 | * |
| 207 | * Return: error code. |
| 208 | */ |
| 209 | int sde_power_resource_enable(struct sde_power_handle *pdata, |
| 210 | struct sde_power_client *pclient, bool enable); |
| 211 | |
| 212 | /** |
| 213 | * sde_power_clk_set_rate() - set the clock rate |
| 214 | * @pdata: power handle containing the resources |
| 215 | * @clock_name: clock name which needs rate update. |
| 216 | * @rate: Requested rate. |
| 217 | * |
| 218 | * Return: error code. |
| 219 | */ |
| 220 | int sde_power_clk_set_rate(struct sde_power_handle *pdata, char *clock_name, |
| 221 | u64 rate); |
| 222 | |
| 223 | /** |
| 224 | * sde_power_clk_get_rate() - get the clock rate |
| 225 | * @pdata: power handle containing the resources |
| 226 | * @clock_name: clock name to get the rate |
| 227 | * |
| 228 | * Return: current clock rate |
| 229 | */ |
| 230 | u64 sde_power_clk_get_rate(struct sde_power_handle *pdata, char *clock_name); |
| 231 | |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 232 | /** |
| 233 | * sde_power_clk_get_max_rate() - get the maximum clock rate |
| 234 | * @pdata: power handle containing the resources |
| 235 | * @clock_name: clock name to get the max rate. |
| 236 | * |
| 237 | * Return: maximum clock rate or 0 if not found. |
| 238 | */ |
| 239 | u64 sde_power_clk_get_max_rate(struct sde_power_handle *pdata, |
| 240 | char *clock_name); |
| 241 | |
| 242 | /** |
| 243 | * sde_power_clk_get_clk() - get the clock |
| 244 | * @pdata: power handle containing the resources |
| 245 | * @clock_name: clock name to get the clk pointer. |
| 246 | * |
| 247 | * Return: Pointer to clock |
| 248 | */ |
| 249 | struct clk *sde_power_clk_get_clk(struct sde_power_handle *phandle, |
| 250 | char *clock_name); |
| 251 | |
| 252 | /** |
| 253 | * sde_power_data_bus_set_quota() - set data bus quota for power client |
| 254 | * @phandle: power handle containing the resources |
| 255 | * @client: client information to set quota |
| 256 | * @bus_client: real-time or non-real-time bus client |
| 257 | * @ab_quota: arbitrated bus bandwidth |
| 258 | * @ib_quota: instantaneous bus bandwidth |
| 259 | * |
| 260 | * Return: zero if success, or error code otherwise |
| 261 | */ |
| 262 | int sde_power_data_bus_set_quota(struct sde_power_handle *phandle, |
| 263 | struct sde_power_client *pclient, |
| 264 | int bus_client, u64 ab_quota, u64 ib_quota); |
| 265 | |
| 266 | /** |
| 267 | * sde_power_data_bus_bandwidth_ctrl() - control data bus bandwidth enable |
| 268 | * @phandle: power handle containing the resources |
| 269 | * @client: client information to bandwidth control |
| 270 | * @enable: true to enable bandwidth for data base |
| 271 | * |
| 272 | * Return: none |
| 273 | */ |
| 274 | void sde_power_data_bus_bandwidth_ctrl(struct sde_power_handle *phandle, |
| 275 | struct sde_power_client *pclient, int enable); |
| 276 | |
Veera Sundaram Sankaran | 410d156 | 2017-03-24 14:48:13 -0700 | [diff] [blame] | 277 | /** |
| 278 | * sde_power_handle_register_event - register a callback function for an event. |
| 279 | * Clients can register for multiple events with a single register. |
| 280 | * Any block with access to phandle can register for the event |
| 281 | * notification. |
| 282 | * @phandle: power handle containing the resources |
| 283 | * @event_type: event type to register; refer SDE_POWER_HANDLE_EVENT_* |
| 284 | * @cb_fnc: pointer to desired callback function |
| 285 | * @usr: user pointer to pass to callback on event trigger |
| 286 | * |
| 287 | * Return: event pointer if success, or error code otherwise |
| 288 | */ |
| 289 | struct sde_power_event *sde_power_handle_register_event( |
| 290 | struct sde_power_handle *phandle, |
| 291 | u32 event_type, void (*cb_fnc)(u32 event_type, void *usr), |
| 292 | void *usr, char *client_name); |
| 293 | /** |
| 294 | * sde_power_handle_unregister_event - unregister callback for event(s) |
| 295 | * @phandle: power handle containing the resources |
| 296 | * @event: event pointer returned after power handle register |
| 297 | */ |
| 298 | void sde_power_handle_unregister_event(struct sde_power_handle *phandle, |
| 299 | struct sde_power_event *event); |
| 300 | |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 301 | #endif /* _SDE_POWER_HANDLE_H_ */ |