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 | |
Dhaval Patel | 60c2506 | 2017-02-21 17:44:05 -0800 | [diff] [blame^] | 19 | #define SDE_POWER_HANDLE_ENABLE_BUS_AB_QUOTA 64000 |
| 20 | #define SDE_POWER_HANDLE_DISABLE_BUS_AB_QUOTA 0 |
| 21 | #define SDE_POWER_HANDLE_ENABLE_BUS_IB_QUOTA 64000 |
| 22 | #define SDE_POWER_HANDLE_DISABLE_BUS_IB_QUOTA 0 |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 23 | |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 24 | /** |
| 25 | * mdss_bus_vote_type: register bus vote type |
| 26 | * VOTE_INDEX_DISABLE: removes the client vote |
| 27 | * VOTE_INDEX_LOW: keeps the lowest vote for register bus |
| 28 | * VOTE_INDEX_MAX: invalid |
| 29 | */ |
| 30 | enum mdss_bus_vote_type { |
| 31 | VOTE_INDEX_DISABLE, |
| 32 | VOTE_INDEX_LOW, |
| 33 | VOTE_INDEX_MAX, |
| 34 | }; |
| 35 | |
| 36 | /** |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 37 | * enum sde_power_handle_data_bus_client - type of axi bus clients |
| 38 | * @SDE_POWER_HANDLE_DATA_BUS_CLIENT_RT: core real-time bus client |
| 39 | * @SDE_POWER_HANDLE_DATA_BUS_CLIENT_NRT: core non-real-time bus client |
| 40 | * @SDE_POWER_HANDLE_DATA_BUS_CLIENT_MAX: maximum number of bus client type |
| 41 | */ |
| 42 | enum sde_power_handle_data_bus_client { |
| 43 | SDE_POWER_HANDLE_DATA_BUS_CLIENT_RT, |
| 44 | SDE_POWER_HANDLE_DATA_BUS_CLIENT_NRT, |
| 45 | SDE_POWER_HANDLE_DATA_BUS_CLIENT_MAX |
| 46 | }; |
| 47 | |
| 48 | /** |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 49 | * struct sde_power_client: stores the power client for sde driver |
| 50 | * @name: name of the client |
| 51 | * @usecase_ndx: current regs bus vote type |
| 52 | * @refcount: current refcount if multiple modules are using same |
| 53 | * same client for enable/disable. Power module will |
| 54 | * aggregate the refcount and vote accordingly for this |
| 55 | * client. |
| 56 | * @id: assigned during create. helps for debugging. |
| 57 | * @list: list to attach power handle master list |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 58 | * @ab: arbitrated bandwidth for each bus client |
| 59 | * @ib: instantaneous bandwidth for each bus client |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 60 | */ |
| 61 | struct sde_power_client { |
| 62 | char name[MAX_CLIENT_NAME_LEN]; |
| 63 | short usecase_ndx; |
| 64 | short refcount; |
| 65 | u32 id; |
| 66 | struct list_head list; |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 67 | u64 ab[SDE_POWER_HANDLE_DATA_BUS_CLIENT_MAX]; |
| 68 | u64 ib[SDE_POWER_HANDLE_DATA_BUS_CLIENT_MAX]; |
| 69 | }; |
| 70 | |
| 71 | /** |
| 72 | * struct sde_power_data_handle: power handle struct for data bus |
| 73 | * @data_bus_scale_table: pointer to bus scaling table |
| 74 | * @data_bus_hdl: current data bus handle |
| 75 | * @axi_port_cnt: number of rt axi ports |
| 76 | * @nrt_axi_port_cnt: number of nrt axi ports |
| 77 | * @bus_channels: number of memory bus channels |
| 78 | * @curr_bw_uc_idx: current use case index of data bus |
| 79 | * @ao_bw_uc_idx: active only use case index of data bus |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 80 | */ |
| 81 | struct sde_power_data_bus_handle { |
| 82 | struct msm_bus_scale_pdata *data_bus_scale_table; |
| 83 | u32 data_bus_hdl; |
| 84 | u32 axi_port_cnt; |
| 85 | u32 nrt_axi_port_cnt; |
| 86 | u32 bus_channels; |
| 87 | u32 curr_bw_uc_idx; |
| 88 | u32 ao_bw_uc_idx; |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | /** |
| 92 | * struct sde_power_handle: power handle main struct |
| 93 | * @mp: module power for clock and regulator |
| 94 | * @client_clist: master list to store all clients |
| 95 | * @phandle_lock: lock to synchronize the enable/disable |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 96 | * @dev: pointer to device structure |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 97 | * @usecase_ndx: current usecase index |
| 98 | * @reg_bus_hdl: current register bus handle |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 99 | * @data_bus_handle: context structure for data bus control |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 100 | */ |
| 101 | struct sde_power_handle { |
| 102 | struct dss_module_power mp; |
| 103 | struct list_head power_client_clist; |
| 104 | struct mutex phandle_lock; |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 105 | struct device *dev; |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 106 | u32 current_usecase_ndx; |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 107 | u32 reg_bus_hdl; |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 108 | struct sde_power_data_bus_handle data_bus_handle; |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 109 | }; |
| 110 | |
| 111 | /** |
| 112 | * sde_power_resource_init() - initializes the sde power handle |
| 113 | * @pdev: platform device to search the power resources |
| 114 | * @pdata: power handle to store the power resources |
| 115 | * |
| 116 | * Return: error code. |
| 117 | */ |
| 118 | int sde_power_resource_init(struct platform_device *pdev, |
| 119 | struct sde_power_handle *pdata); |
| 120 | |
| 121 | /** |
| 122 | * sde_power_resource_deinit() - release the sde power handle |
| 123 | * @pdev: platform device for power resources |
| 124 | * @pdata: power handle containing the resources |
| 125 | * |
| 126 | * Return: error code. |
| 127 | */ |
| 128 | void sde_power_resource_deinit(struct platform_device *pdev, |
| 129 | struct sde_power_handle *pdata); |
| 130 | |
| 131 | /** |
| 132 | * sde_power_client_create() - create the client on power handle |
| 133 | * @pdata: power handle containing the resources |
| 134 | * @client_name: new client name for registration |
| 135 | * |
| 136 | * Return: error code. |
| 137 | */ |
| 138 | struct sde_power_client *sde_power_client_create(struct sde_power_handle *pdata, |
| 139 | char *client_name); |
| 140 | |
| 141 | /** |
| 142 | * sde_power_client_destroy() - destroy the client on power handle |
| 143 | * @pdata: power handle containing the resources |
| 144 | * @client_name: new client name for registration |
| 145 | * |
| 146 | * Return: none |
| 147 | */ |
| 148 | void sde_power_client_destroy(struct sde_power_handle *phandle, |
| 149 | struct sde_power_client *client); |
| 150 | |
| 151 | /** |
| 152 | * sde_power_resource_enable() - enable/disable the power resources |
| 153 | * @pdata: power handle containing the resources |
| 154 | * @client: client information to enable/disable its vote |
| 155 | * @enable: boolean request for enable/disable |
| 156 | * |
| 157 | * Return: error code. |
| 158 | */ |
| 159 | int sde_power_resource_enable(struct sde_power_handle *pdata, |
| 160 | struct sde_power_client *pclient, bool enable); |
| 161 | |
| 162 | /** |
| 163 | * sde_power_clk_set_rate() - set the clock rate |
| 164 | * @pdata: power handle containing the resources |
| 165 | * @clock_name: clock name which needs rate update. |
| 166 | * @rate: Requested rate. |
| 167 | * |
| 168 | * Return: error code. |
| 169 | */ |
| 170 | int sde_power_clk_set_rate(struct sde_power_handle *pdata, char *clock_name, |
| 171 | u64 rate); |
| 172 | |
| 173 | /** |
| 174 | * sde_power_clk_get_rate() - get the clock rate |
| 175 | * @pdata: power handle containing the resources |
| 176 | * @clock_name: clock name to get the rate |
| 177 | * |
| 178 | * Return: current clock rate |
| 179 | */ |
| 180 | u64 sde_power_clk_get_rate(struct sde_power_handle *pdata, char *clock_name); |
| 181 | |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 182 | /** |
| 183 | * sde_power_clk_get_max_rate() - get the maximum clock rate |
| 184 | * @pdata: power handle containing the resources |
| 185 | * @clock_name: clock name to get the max rate. |
| 186 | * |
| 187 | * Return: maximum clock rate or 0 if not found. |
| 188 | */ |
| 189 | u64 sde_power_clk_get_max_rate(struct sde_power_handle *pdata, |
| 190 | char *clock_name); |
| 191 | |
| 192 | /** |
| 193 | * sde_power_clk_get_clk() - get the clock |
| 194 | * @pdata: power handle containing the resources |
| 195 | * @clock_name: clock name to get the clk pointer. |
| 196 | * |
| 197 | * Return: Pointer to clock |
| 198 | */ |
| 199 | struct clk *sde_power_clk_get_clk(struct sde_power_handle *phandle, |
| 200 | char *clock_name); |
| 201 | |
| 202 | /** |
| 203 | * sde_power_data_bus_set_quota() - set data bus quota for power client |
| 204 | * @phandle: power handle containing the resources |
| 205 | * @client: client information to set quota |
| 206 | * @bus_client: real-time or non-real-time bus client |
| 207 | * @ab_quota: arbitrated bus bandwidth |
| 208 | * @ib_quota: instantaneous bus bandwidth |
| 209 | * |
| 210 | * Return: zero if success, or error code otherwise |
| 211 | */ |
| 212 | int sde_power_data_bus_set_quota(struct sde_power_handle *phandle, |
| 213 | struct sde_power_client *pclient, |
| 214 | int bus_client, u64 ab_quota, u64 ib_quota); |
| 215 | |
| 216 | /** |
| 217 | * sde_power_data_bus_bandwidth_ctrl() - control data bus bandwidth enable |
| 218 | * @phandle: power handle containing the resources |
| 219 | * @client: client information to bandwidth control |
| 220 | * @enable: true to enable bandwidth for data base |
| 221 | * |
| 222 | * Return: none |
| 223 | */ |
| 224 | void sde_power_data_bus_bandwidth_ctrl(struct sde_power_handle *phandle, |
| 225 | struct sde_power_client *pclient, int enable); |
| 226 | |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 227 | #endif /* _SDE_POWER_HANDLE_H_ */ |