Alan Kwong | 83b6cbe | 2016-09-17 20:08:37 -0400 | [diff] [blame] | 1 | /* Copyright (c) 2014-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 | #define pr_fmt(fmt) "[drm:%s:%d]: " fmt, __func__, __LINE__ |
| 15 | |
| 16 | #include <linux/clk.h> |
| 17 | #include <linux/kernel.h> |
| 18 | #include <linux/of.h> |
| 19 | #include <linux/string.h> |
| 20 | #include <linux/of_address.h> |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 21 | #include <linux/slab.h> |
| 22 | #include <linux/mutex.h> |
| 23 | #include <linux/of_platform.h> |
| 24 | |
| 25 | #include <linux/msm-bus.h> |
| 26 | #include <linux/msm-bus-board.h> |
Dhaval Patel | 1ac9103 | 2016-09-26 19:25:39 -0700 | [diff] [blame] | 27 | #include <linux/sde_io_util.h> |
Veera Sundaram Sankaran | 38318f1 | 2017-03-24 15:54:21 -0700 | [diff] [blame] | 28 | #include <linux/sde_rsc.h> |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 29 | |
| 30 | #include "sde_power_handle.h" |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 31 | #include "sde_trace.h" |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 32 | |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 33 | static const char *data_bus_name[SDE_POWER_HANDLE_DBUS_ID_MAX] = { |
| 34 | [SDE_POWER_HANDLE_DBUS_ID_MNOC] = "qcom,sde-data-bus", |
| 35 | [SDE_POWER_HANDLE_DBUS_ID_LLCC] = "qcom,sde-llcc-bus", |
| 36 | [SDE_POWER_HANDLE_DBUS_ID_EBI] = "qcom,sde-ebi-bus", |
| 37 | }; |
| 38 | |
| 39 | const char *sde_power_handle_get_dbus_name(u32 bus_id) |
| 40 | { |
| 41 | if (bus_id < SDE_POWER_HANDLE_DBUS_ID_MAX) |
| 42 | return data_bus_name[bus_id]; |
| 43 | |
| 44 | return NULL; |
| 45 | } |
| 46 | |
Veera Sundaram Sankaran | 410d156 | 2017-03-24 14:48:13 -0700 | [diff] [blame] | 47 | static void sde_power_event_trigger_locked(struct sde_power_handle *phandle, |
| 48 | u32 event_type) |
| 49 | { |
| 50 | struct sde_power_event *event; |
| 51 | |
| 52 | list_for_each_entry(event, &phandle->event_list, list) { |
| 53 | if (event->event_type & event_type) |
| 54 | event->cb_fnc(event_type, event->usr); |
| 55 | } |
| 56 | } |
| 57 | |
Veera Sundaram Sankaran | 38318f1 | 2017-03-24 15:54:21 -0700 | [diff] [blame] | 58 | static int sde_power_rsc_update(struct sde_power_handle *phandle, bool enable) |
| 59 | { |
| 60 | u32 rsc_state; |
Veera Sundaram Sankaran | 479defc | 2017-04-28 15:33:54 -0700 | [diff] [blame] | 61 | int ret = 0; |
Veera Sundaram Sankaran | 38318f1 | 2017-03-24 15:54:21 -0700 | [diff] [blame] | 62 | |
| 63 | /* creates the rsc client on the first enable */ |
| 64 | if (!phandle->rsc_client_init) { |
| 65 | phandle->rsc_client = sde_rsc_client_create(SDE_RSC_INDEX, |
| 66 | "sde_power_handle", false); |
| 67 | if (IS_ERR_OR_NULL(phandle->rsc_client)) { |
| 68 | pr_debug("sde rsc client create failed :%ld\n", |
| 69 | PTR_ERR(phandle->rsc_client)); |
| 70 | phandle->rsc_client = NULL; |
| 71 | } |
| 72 | phandle->rsc_client_init = true; |
| 73 | } |
| 74 | |
| 75 | rsc_state = enable ? SDE_RSC_CLK_STATE : SDE_RSC_IDLE_STATE; |
| 76 | |
Veera Sundaram Sankaran | 479defc | 2017-04-28 15:33:54 -0700 | [diff] [blame] | 77 | if (phandle->rsc_client) |
| 78 | ret = sde_rsc_client_state_update(phandle->rsc_client, |
Lloyd Atkinson | f68a213 | 2017-07-17 10:16:30 -0400 | [diff] [blame] | 79 | rsc_state, NULL, SDE_RSC_INVALID_CRTC_ID, NULL); |
Veera Sundaram Sankaran | 479defc | 2017-04-28 15:33:54 -0700 | [diff] [blame] | 80 | |
| 81 | return ret; |
Veera Sundaram Sankaran | 38318f1 | 2017-03-24 15:54:21 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 84 | struct sde_power_client *sde_power_client_create( |
| 85 | struct sde_power_handle *phandle, char *client_name) |
| 86 | { |
| 87 | struct sde_power_client *client; |
| 88 | static u32 id; |
| 89 | |
| 90 | if (!client_name || !phandle) { |
| 91 | pr_err("client name is null or invalid power data\n"); |
| 92 | return ERR_PTR(-EINVAL); |
| 93 | } |
| 94 | |
| 95 | client = kzalloc(sizeof(struct sde_power_client), GFP_KERNEL); |
| 96 | if (!client) |
| 97 | return ERR_PTR(-ENOMEM); |
| 98 | |
| 99 | mutex_lock(&phandle->phandle_lock); |
| 100 | strlcpy(client->name, client_name, MAX_CLIENT_NAME_LEN); |
| 101 | client->usecase_ndx = VOTE_INDEX_DISABLE; |
| 102 | client->id = id; |
Veera Sundaram Sankaran | 410d156 | 2017-03-24 14:48:13 -0700 | [diff] [blame] | 103 | client->active = true; |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 104 | pr_debug("client %s created:%pK id :%d\n", client_name, |
| 105 | client, id); |
| 106 | id++; |
| 107 | list_add(&client->list, &phandle->power_client_clist); |
| 108 | mutex_unlock(&phandle->phandle_lock); |
| 109 | |
| 110 | return client; |
| 111 | } |
| 112 | |
| 113 | void sde_power_client_destroy(struct sde_power_handle *phandle, |
| 114 | struct sde_power_client *client) |
| 115 | { |
| 116 | if (!client || !phandle) { |
| 117 | pr_err("reg bus vote: invalid client handle\n"); |
Veera Sundaram Sankaran | 410d156 | 2017-03-24 14:48:13 -0700 | [diff] [blame] | 118 | } else if (!client->active) { |
| 119 | pr_err("sde power deinit already done\n"); |
| 120 | kfree(client); |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 121 | } else { |
| 122 | pr_debug("bus vote client %s destroyed:%pK id:%u\n", |
| 123 | client->name, client, client->id); |
| 124 | mutex_lock(&phandle->phandle_lock); |
| 125 | list_del_init(&client->list); |
| 126 | mutex_unlock(&phandle->phandle_lock); |
| 127 | kfree(client); |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | static int sde_power_parse_dt_supply(struct platform_device *pdev, |
| 132 | struct dss_module_power *mp) |
| 133 | { |
| 134 | int i = 0, rc = 0; |
| 135 | u32 tmp = 0; |
| 136 | struct device_node *of_node = NULL, *supply_root_node = NULL; |
| 137 | struct device_node *supply_node = NULL; |
| 138 | |
| 139 | if (!pdev || !mp) { |
| 140 | pr_err("invalid input param pdev:%pK mp:%pK\n", pdev, mp); |
| 141 | return -EINVAL; |
| 142 | } |
| 143 | |
| 144 | of_node = pdev->dev.of_node; |
| 145 | |
| 146 | mp->num_vreg = 0; |
| 147 | supply_root_node = of_get_child_by_name(of_node, |
| 148 | "qcom,platform-supply-entries"); |
| 149 | if (!supply_root_node) { |
Dhaval Patel | cd78b8a | 2016-10-11 10:26:07 -0700 | [diff] [blame] | 150 | pr_debug("no supply entry present\n"); |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 151 | return rc; |
| 152 | } |
| 153 | |
| 154 | for_each_child_of_node(supply_root_node, supply_node) |
| 155 | mp->num_vreg++; |
| 156 | |
| 157 | if (mp->num_vreg == 0) { |
| 158 | pr_debug("no vreg\n"); |
| 159 | return rc; |
| 160 | } |
| 161 | |
| 162 | pr_debug("vreg found. count=%d\n", mp->num_vreg); |
| 163 | mp->vreg_config = devm_kzalloc(&pdev->dev, sizeof(struct dss_vreg) * |
| 164 | mp->num_vreg, GFP_KERNEL); |
| 165 | if (!mp->vreg_config) { |
| 166 | rc = -ENOMEM; |
| 167 | return rc; |
| 168 | } |
| 169 | |
| 170 | for_each_child_of_node(supply_root_node, supply_node) { |
| 171 | |
| 172 | const char *st = NULL; |
| 173 | |
| 174 | rc = of_property_read_string(supply_node, |
| 175 | "qcom,supply-name", &st); |
| 176 | if (rc) { |
| 177 | pr_err("error reading name. rc=%d\n", rc); |
| 178 | goto error; |
| 179 | } |
| 180 | |
| 181 | strlcpy(mp->vreg_config[i].vreg_name, st, |
| 182 | sizeof(mp->vreg_config[i].vreg_name)); |
| 183 | |
| 184 | rc = of_property_read_u32(supply_node, |
| 185 | "qcom,supply-min-voltage", &tmp); |
| 186 | if (rc) { |
| 187 | pr_err("error reading min volt. rc=%d\n", rc); |
| 188 | goto error; |
| 189 | } |
| 190 | mp->vreg_config[i].min_voltage = tmp; |
| 191 | |
| 192 | rc = of_property_read_u32(supply_node, |
| 193 | "qcom,supply-max-voltage", &tmp); |
| 194 | if (rc) { |
| 195 | pr_err("error reading max volt. rc=%d\n", rc); |
| 196 | goto error; |
| 197 | } |
| 198 | mp->vreg_config[i].max_voltage = tmp; |
| 199 | |
| 200 | rc = of_property_read_u32(supply_node, |
| 201 | "qcom,supply-enable-load", &tmp); |
| 202 | if (rc) { |
| 203 | pr_err("error reading enable load. rc=%d\n", rc); |
| 204 | goto error; |
| 205 | } |
| 206 | mp->vreg_config[i].enable_load = tmp; |
| 207 | |
| 208 | rc = of_property_read_u32(supply_node, |
| 209 | "qcom,supply-disable-load", &tmp); |
| 210 | if (rc) { |
| 211 | pr_err("error reading disable load. rc=%d\n", rc); |
| 212 | goto error; |
| 213 | } |
| 214 | mp->vreg_config[i].disable_load = tmp; |
| 215 | |
| 216 | rc = of_property_read_u32(supply_node, |
| 217 | "qcom,supply-pre-on-sleep", &tmp); |
| 218 | if (rc) |
| 219 | pr_debug("error reading supply pre sleep value. rc=%d\n", |
| 220 | rc); |
| 221 | |
| 222 | mp->vreg_config[i].pre_on_sleep = (!rc ? tmp : 0); |
| 223 | |
| 224 | rc = of_property_read_u32(supply_node, |
| 225 | "qcom,supply-pre-off-sleep", &tmp); |
| 226 | if (rc) |
| 227 | pr_debug("error reading supply pre sleep value. rc=%d\n", |
| 228 | rc); |
| 229 | |
| 230 | mp->vreg_config[i].pre_off_sleep = (!rc ? tmp : 0); |
| 231 | |
| 232 | rc = of_property_read_u32(supply_node, |
| 233 | "qcom,supply-post-on-sleep", &tmp); |
| 234 | if (rc) |
| 235 | pr_debug("error reading supply post sleep value. rc=%d\n", |
| 236 | rc); |
| 237 | |
| 238 | mp->vreg_config[i].post_on_sleep = (!rc ? tmp : 0); |
| 239 | |
| 240 | rc = of_property_read_u32(supply_node, |
| 241 | "qcom,supply-post-off-sleep", &tmp); |
| 242 | if (rc) |
| 243 | pr_debug("error reading supply post sleep value. rc=%d\n", |
| 244 | rc); |
| 245 | |
| 246 | mp->vreg_config[i].post_off_sleep = (!rc ? tmp : 0); |
| 247 | |
| 248 | pr_debug("%s min=%d, max=%d, enable=%d, disable=%d, preonsleep=%d, postonsleep=%d, preoffsleep=%d, postoffsleep=%d\n", |
| 249 | mp->vreg_config[i].vreg_name, |
| 250 | mp->vreg_config[i].min_voltage, |
| 251 | mp->vreg_config[i].max_voltage, |
| 252 | mp->vreg_config[i].enable_load, |
| 253 | mp->vreg_config[i].disable_load, |
| 254 | mp->vreg_config[i].pre_on_sleep, |
| 255 | mp->vreg_config[i].post_on_sleep, |
| 256 | mp->vreg_config[i].pre_off_sleep, |
| 257 | mp->vreg_config[i].post_off_sleep); |
| 258 | ++i; |
| 259 | |
| 260 | rc = 0; |
| 261 | } |
| 262 | |
| 263 | return rc; |
| 264 | |
| 265 | error: |
| 266 | if (mp->vreg_config) { |
| 267 | devm_kfree(&pdev->dev, mp->vreg_config); |
| 268 | mp->vreg_config = NULL; |
| 269 | mp->num_vreg = 0; |
| 270 | } |
| 271 | |
| 272 | return rc; |
| 273 | } |
| 274 | |
| 275 | static int sde_power_parse_dt_clock(struct platform_device *pdev, |
| 276 | struct dss_module_power *mp) |
| 277 | { |
| 278 | u32 i = 0, rc = 0; |
| 279 | const char *clock_name; |
Kalyan Thota | 8f72792 | 2016-10-28 19:09:03 +0530 | [diff] [blame] | 280 | u32 clock_rate = 0; |
| 281 | u32 clock_max_rate = 0; |
| 282 | int num_clk = 0; |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 283 | |
| 284 | if (!pdev || !mp) { |
| 285 | pr_err("invalid input param pdev:%pK mp:%pK\n", pdev, mp); |
| 286 | return -EINVAL; |
| 287 | } |
| 288 | |
Dhaval Patel | cd78b8a | 2016-10-11 10:26:07 -0700 | [diff] [blame] | 289 | mp->num_clk = 0; |
| 290 | num_clk = of_property_count_strings(pdev->dev.of_node, |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 291 | "clock-names"); |
Dhaval Patel | cd78b8a | 2016-10-11 10:26:07 -0700 | [diff] [blame] | 292 | if (num_clk <= 0) { |
| 293 | pr_debug("clocks are not defined\n"); |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 294 | goto clk_err; |
| 295 | } |
| 296 | |
Dhaval Patel | cd78b8a | 2016-10-11 10:26:07 -0700 | [diff] [blame] | 297 | mp->num_clk = num_clk; |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 298 | mp->clk_config = devm_kzalloc(&pdev->dev, |
Dhaval Patel | cd78b8a | 2016-10-11 10:26:07 -0700 | [diff] [blame] | 299 | sizeof(struct dss_clk) * num_clk, GFP_KERNEL); |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 300 | if (!mp->clk_config) { |
| 301 | rc = -ENOMEM; |
| 302 | mp->num_clk = 0; |
| 303 | goto clk_err; |
| 304 | } |
| 305 | |
Dhaval Patel | cd78b8a | 2016-10-11 10:26:07 -0700 | [diff] [blame] | 306 | for (i = 0; i < num_clk; i++) { |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 307 | of_property_read_string_index(pdev->dev.of_node, "clock-names", |
| 308 | i, &clock_name); |
| 309 | strlcpy(mp->clk_config[i].clk_name, clock_name, |
| 310 | sizeof(mp->clk_config[i].clk_name)); |
| 311 | |
| 312 | of_property_read_u32_index(pdev->dev.of_node, "clock-rate", |
| 313 | i, &clock_rate); |
| 314 | mp->clk_config[i].rate = clock_rate; |
| 315 | |
| 316 | if (!clock_rate) |
| 317 | mp->clk_config[i].type = DSS_CLK_AHB; |
| 318 | else |
| 319 | mp->clk_config[i].type = DSS_CLK_PCLK; |
Alan Kwong | 83b6cbe | 2016-09-17 20:08:37 -0400 | [diff] [blame] | 320 | |
| 321 | clock_max_rate = 0; |
| 322 | of_property_read_u32_index(pdev->dev.of_node, "clock-max-rate", |
| 323 | i, &clock_max_rate); |
| 324 | mp->clk_config[i].max_rate = clock_max_rate; |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | clk_err: |
| 328 | return rc; |
| 329 | } |
| 330 | |
| 331 | #ifdef CONFIG_QCOM_BUS_SCALING |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 332 | |
| 333 | #define MAX_AXI_PORT_COUNT 3 |
| 334 | |
| 335 | static int _sde_power_data_bus_set_quota( |
| 336 | struct sde_power_data_bus_handle *pdbus, |
| 337 | u64 ab_quota_rt, u64 ab_quota_nrt, |
| 338 | u64 ib_quota_rt, u64 ib_quota_nrt) |
| 339 | { |
| 340 | int new_uc_idx; |
| 341 | u64 ab_quota[MAX_AXI_PORT_COUNT] = {0, 0}; |
| 342 | u64 ib_quota[MAX_AXI_PORT_COUNT] = {0, 0}; |
| 343 | int rc; |
| 344 | |
| 345 | if (pdbus->data_bus_hdl < 1) { |
| 346 | pr_err("invalid bus handle %d\n", pdbus->data_bus_hdl); |
| 347 | return -EINVAL; |
| 348 | } |
| 349 | |
Alan Kwong | ff30f4a | 2017-05-23 12:02:00 -0700 | [diff] [blame] | 350 | pdbus->ab_rt = ab_quota_rt; |
| 351 | pdbus->ib_rt = ib_quota_rt; |
| 352 | pdbus->ab_nrt = ab_quota_nrt; |
| 353 | pdbus->ib_nrt = ib_quota_nrt; |
| 354 | |
| 355 | if (pdbus->enable) { |
| 356 | ab_quota_rt = max_t(u64, ab_quota_rt, |
| 357 | SDE_POWER_HANDLE_ENABLE_BUS_AB_QUOTA); |
| 358 | ib_quota_rt = max_t(u64, ib_quota_rt, |
| 359 | SDE_POWER_HANDLE_ENABLE_BUS_IB_QUOTA); |
| 360 | ab_quota_nrt = max_t(u64, ab_quota_nrt, |
| 361 | SDE_POWER_HANDLE_ENABLE_BUS_AB_QUOTA); |
| 362 | ib_quota_nrt = max_t(u64, ib_quota_nrt, |
| 363 | SDE_POWER_HANDLE_ENABLE_BUS_IB_QUOTA); |
| 364 | } else { |
Dhaval Patel | c4f1c7c | 2017-08-16 12:02:21 -0700 | [diff] [blame] | 365 | ab_quota_rt = min_t(u64, ab_quota_rt, |
Alan Kwong | ff30f4a | 2017-05-23 12:02:00 -0700 | [diff] [blame] | 366 | SDE_POWER_HANDLE_DISABLE_BUS_AB_QUOTA); |
Dhaval Patel | c4f1c7c | 2017-08-16 12:02:21 -0700 | [diff] [blame] | 367 | ib_quota_rt = min_t(u64, ib_quota_rt, |
Alan Kwong | ff30f4a | 2017-05-23 12:02:00 -0700 | [diff] [blame] | 368 | SDE_POWER_HANDLE_DISABLE_BUS_IB_QUOTA); |
Dhaval Patel | c4f1c7c | 2017-08-16 12:02:21 -0700 | [diff] [blame] | 369 | ab_quota_nrt = min_t(u64, ab_quota_nrt, |
Alan Kwong | ff30f4a | 2017-05-23 12:02:00 -0700 | [diff] [blame] | 370 | SDE_POWER_HANDLE_DISABLE_BUS_AB_QUOTA); |
Dhaval Patel | c4f1c7c | 2017-08-16 12:02:21 -0700 | [diff] [blame] | 371 | ib_quota_nrt = min_t(u64, ib_quota_nrt, |
Alan Kwong | ff30f4a | 2017-05-23 12:02:00 -0700 | [diff] [blame] | 372 | SDE_POWER_HANDLE_DISABLE_BUS_IB_QUOTA); |
| 373 | } |
| 374 | |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 375 | if (!ab_quota_rt && !ab_quota_nrt && !ib_quota_rt && !ib_quota_nrt) { |
| 376 | new_uc_idx = 0; |
| 377 | } else { |
| 378 | int i; |
| 379 | struct msm_bus_vectors *vect = NULL; |
| 380 | struct msm_bus_scale_pdata *bw_table = |
| 381 | pdbus->data_bus_scale_table; |
| 382 | u32 nrt_axi_port_cnt = pdbus->nrt_axi_port_cnt; |
| 383 | u32 total_axi_port_cnt = pdbus->axi_port_cnt; |
| 384 | u32 rt_axi_port_cnt = total_axi_port_cnt - nrt_axi_port_cnt; |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 385 | |
| 386 | if (!bw_table || !total_axi_port_cnt || |
| 387 | total_axi_port_cnt > MAX_AXI_PORT_COUNT) { |
| 388 | pr_err("invalid input\n"); |
| 389 | return -EINVAL; |
| 390 | } |
| 391 | |
| 392 | if (pdbus->bus_channels) { |
| 393 | ib_quota_rt = div_u64(ib_quota_rt, |
| 394 | pdbus->bus_channels); |
| 395 | ib_quota_nrt = div_u64(ib_quota_nrt, |
| 396 | pdbus->bus_channels); |
| 397 | } |
| 398 | |
| 399 | if (nrt_axi_port_cnt) { |
| 400 | |
| 401 | ab_quota_rt = div_u64(ab_quota_rt, rt_axi_port_cnt); |
| 402 | ab_quota_nrt = div_u64(ab_quota_nrt, nrt_axi_port_cnt); |
| 403 | |
| 404 | for (i = 0; i < total_axi_port_cnt; i++) { |
| 405 | if (i < rt_axi_port_cnt) { |
| 406 | ab_quota[i] = ab_quota_rt; |
| 407 | ib_quota[i] = ib_quota_rt; |
| 408 | } else { |
| 409 | ab_quota[i] = ab_quota_nrt; |
| 410 | ib_quota[i] = ib_quota_nrt; |
| 411 | } |
| 412 | } |
| 413 | } else { |
| 414 | ab_quota[0] = div_u64(ab_quota_rt + ab_quota_nrt, |
| 415 | total_axi_port_cnt); |
| 416 | ib_quota[0] = ib_quota_rt + ib_quota_nrt; |
| 417 | |
| 418 | for (i = 1; i < total_axi_port_cnt; i++) { |
| 419 | ab_quota[i] = ab_quota[0]; |
| 420 | ib_quota[i] = ib_quota[0]; |
| 421 | } |
| 422 | } |
| 423 | |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 424 | new_uc_idx = (pdbus->curr_bw_uc_idx % |
| 425 | (bw_table->num_usecases - 1)) + 1; |
| 426 | |
| 427 | for (i = 0; i < total_axi_port_cnt; i++) { |
| 428 | vect = &bw_table->usecase[new_uc_idx].vectors[i]; |
| 429 | vect->ab = ab_quota[i]; |
| 430 | vect->ib = ib_quota[i]; |
| 431 | |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 432 | pr_debug( |
| 433 | "%s uc_idx=%d %s path idx=%d ab=%llu ib=%llu\n", |
| 434 | bw_table->name, |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 435 | new_uc_idx, (i < rt_axi_port_cnt) ? "rt" : "nrt" |
| 436 | , i, vect->ab, vect->ib); |
| 437 | } |
| 438 | } |
| 439 | pdbus->curr_bw_uc_idx = new_uc_idx; |
| 440 | pdbus->ao_bw_uc_idx = new_uc_idx; |
| 441 | |
Dhaval Patel | 3fe015e | 2017-02-18 10:11:27 -0800 | [diff] [blame] | 442 | SDE_ATRACE_BEGIN("msm_bus_scale_req"); |
| 443 | rc = msm_bus_scale_client_update_request(pdbus->data_bus_hdl, |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 444 | new_uc_idx); |
Dhaval Patel | 3fe015e | 2017-02-18 10:11:27 -0800 | [diff] [blame] | 445 | SDE_ATRACE_END("msm_bus_scale_req"); |
| 446 | |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 447 | return rc; |
| 448 | } |
| 449 | |
| 450 | int sde_power_data_bus_set_quota(struct sde_power_handle *phandle, |
| 451 | struct sde_power_client *pclient, |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 452 | int bus_client, u32 bus_id, |
| 453 | u64 ab_quota, u64 ib_quota) |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 454 | { |
| 455 | int rc = 0; |
| 456 | int i; |
| 457 | u64 total_ab_rt = 0, total_ib_rt = 0; |
| 458 | u64 total_ab_nrt = 0, total_ib_nrt = 0; |
| 459 | struct sde_power_client *client; |
| 460 | |
| 461 | if (!phandle || !pclient || |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 462 | bus_client >= SDE_POWER_HANDLE_DATA_BUS_CLIENT_MAX || |
| 463 | bus_id >= SDE_POWER_HANDLE_DBUS_ID_MAX) { |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 464 | pr_err("invalid parameters\n"); |
| 465 | return -EINVAL; |
| 466 | } |
| 467 | |
| 468 | mutex_lock(&phandle->phandle_lock); |
| 469 | |
| 470 | pclient->ab[bus_client] = ab_quota; |
| 471 | pclient->ib[bus_client] = ib_quota; |
| 472 | trace_sde_perf_update_bus(bus_client, ab_quota, ib_quota); |
| 473 | |
| 474 | list_for_each_entry(client, &phandle->power_client_clist, list) { |
| 475 | for (i = 0; i < SDE_POWER_HANDLE_DATA_BUS_CLIENT_MAX; i++) { |
| 476 | if (i == SDE_POWER_HANDLE_DATA_BUS_CLIENT_NRT) { |
| 477 | total_ab_nrt += client->ab[i]; |
| 478 | total_ib_nrt += client->ib[i]; |
| 479 | } else { |
| 480 | total_ab_rt += client->ab[i]; |
| 481 | total_ib_rt = max(total_ib_rt, client->ib[i]); |
| 482 | } |
| 483 | } |
| 484 | } |
| 485 | |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 486 | if (phandle->data_bus_handle[bus_id].data_bus_hdl) |
| 487 | rc = _sde_power_data_bus_set_quota( |
| 488 | &phandle->data_bus_handle[bus_id], |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 489 | total_ab_rt, total_ab_nrt, |
| 490 | total_ib_rt, total_ib_nrt); |
| 491 | |
| 492 | mutex_unlock(&phandle->phandle_lock); |
| 493 | |
| 494 | return rc; |
| 495 | } |
| 496 | |
| 497 | static void sde_power_data_bus_unregister( |
| 498 | struct sde_power_data_bus_handle *pdbus) |
| 499 | { |
| 500 | if (pdbus->data_bus_hdl) { |
| 501 | msm_bus_scale_unregister_client(pdbus->data_bus_hdl); |
| 502 | pdbus->data_bus_hdl = 0; |
| 503 | } |
| 504 | } |
| 505 | |
| 506 | static int sde_power_data_bus_parse(struct platform_device *pdev, |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 507 | struct sde_power_data_bus_handle *pdbus, const char *name) |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 508 | { |
| 509 | struct device_node *node; |
| 510 | int rc = 0; |
| 511 | int paths; |
| 512 | |
| 513 | pdbus->bus_channels = 1; |
| 514 | rc = of_property_read_u32(pdev->dev.of_node, |
| 515 | "qcom,sde-dram-channels", &pdbus->bus_channels); |
Alan Kwong | 1bd11be | 2017-01-10 10:31:39 -0500 | [diff] [blame] | 516 | if (rc) { |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 517 | pr_debug("number of channels property not specified\n"); |
Alan Kwong | 1bd11be | 2017-01-10 10:31:39 -0500 | [diff] [blame] | 518 | rc = 0; |
| 519 | } |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 520 | |
| 521 | pdbus->nrt_axi_port_cnt = 0; |
| 522 | rc = of_property_read_u32(pdev->dev.of_node, |
| 523 | "qcom,sde-num-nrt-paths", |
| 524 | &pdbus->nrt_axi_port_cnt); |
Alan Kwong | 1bd11be | 2017-01-10 10:31:39 -0500 | [diff] [blame] | 525 | if (rc) { |
| 526 | pr_debug("number of axi port property not specified\n"); |
| 527 | rc = 0; |
| 528 | } |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 529 | |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 530 | node = of_get_child_by_name(pdev->dev.of_node, name); |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 531 | if (node) { |
| 532 | rc = of_property_read_u32(node, |
| 533 | "qcom,msm-bus,num-paths", &paths); |
| 534 | if (rc) { |
| 535 | pr_err("Error. qcom,msm-bus,num-paths not found\n"); |
| 536 | return rc; |
| 537 | } |
| 538 | pdbus->axi_port_cnt = paths; |
| 539 | |
| 540 | pdbus->data_bus_scale_table = |
| 541 | msm_bus_pdata_from_node(pdev, node); |
| 542 | if (IS_ERR_OR_NULL(pdbus->data_bus_scale_table)) { |
| 543 | pr_err("reg bus handle parsing failed\n"); |
| 544 | rc = PTR_ERR(pdbus->data_bus_scale_table); |
Dhaval Patel | 5398f60 | 2017-03-25 18:25:18 -0700 | [diff] [blame] | 545 | if (!pdbus->data_bus_scale_table) |
| 546 | rc = -EINVAL; |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 547 | goto end; |
| 548 | } |
| 549 | pdbus->data_bus_hdl = msm_bus_scale_register_client( |
| 550 | pdbus->data_bus_scale_table); |
| 551 | if (!pdbus->data_bus_hdl) { |
| 552 | pr_err("data_bus_client register failed\n"); |
| 553 | rc = -EINVAL; |
| 554 | goto end; |
| 555 | } |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 556 | pr_debug("register %s data_bus_hdl=%x\n", name, |
| 557 | pdbus->data_bus_hdl); |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | end: |
| 561 | return rc; |
| 562 | } |
| 563 | |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 564 | static int sde_power_reg_bus_parse(struct platform_device *pdev, |
| 565 | struct sde_power_handle *phandle) |
| 566 | { |
| 567 | struct device_node *node; |
| 568 | struct msm_bus_scale_pdata *bus_scale_table; |
| 569 | int rc = 0; |
| 570 | |
| 571 | node = of_get_child_by_name(pdev->dev.of_node, "qcom,sde-reg-bus"); |
| 572 | if (node) { |
| 573 | bus_scale_table = msm_bus_pdata_from_node(pdev, node); |
| 574 | if (IS_ERR_OR_NULL(bus_scale_table)) { |
| 575 | pr_err("reg bus handle parsing failed\n"); |
| 576 | rc = PTR_ERR(bus_scale_table); |
Dhaval Patel | 5398f60 | 2017-03-25 18:25:18 -0700 | [diff] [blame] | 577 | if (!bus_scale_table) |
| 578 | rc = -EINVAL; |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 579 | goto end; |
| 580 | } |
| 581 | phandle->reg_bus_hdl = msm_bus_scale_register_client( |
| 582 | bus_scale_table); |
| 583 | if (!phandle->reg_bus_hdl) { |
| 584 | pr_err("reg_bus_client register failed\n"); |
| 585 | rc = -EINVAL; |
| 586 | goto end; |
| 587 | } |
| 588 | pr_debug("register reg_bus_hdl=%x\n", phandle->reg_bus_hdl); |
| 589 | } |
| 590 | |
| 591 | end: |
| 592 | return rc; |
| 593 | } |
| 594 | |
| 595 | static void sde_power_reg_bus_unregister(u32 reg_bus_hdl) |
| 596 | { |
| 597 | if (reg_bus_hdl) |
| 598 | msm_bus_scale_unregister_client(reg_bus_hdl); |
| 599 | } |
| 600 | |
Dhaval Patel | c4f1c7c | 2017-08-16 12:02:21 -0700 | [diff] [blame] | 601 | int sde_power_data_bus_state_update(struct sde_power_handle *phandle, |
| 602 | bool enable) |
| 603 | { |
| 604 | int i; |
| 605 | |
| 606 | if (!phandle) { |
| 607 | pr_err("invalid param\n"); |
| 608 | return -EINVAL; |
| 609 | } |
| 610 | |
| 611 | for (i = SDE_POWER_HANDLE_DBUS_ID_MNOC; |
| 612 | i < SDE_POWER_HANDLE_DBUS_ID_MAX; i++) |
| 613 | phandle->data_bus_handle[i].enable = enable; |
| 614 | |
| 615 | return 0; |
| 616 | } |
| 617 | |
Dhaval Patel | 60c2506 | 2017-02-21 17:44:05 -0800 | [diff] [blame] | 618 | static int sde_power_data_bus_update(struct sde_power_data_bus_handle *pdbus, |
| 619 | bool enable) |
| 620 | { |
| 621 | int rc = 0; |
Dhaval Patel | 60c2506 | 2017-02-21 17:44:05 -0800 | [diff] [blame] | 622 | |
Alan Kwong | ff30f4a | 2017-05-23 12:02:00 -0700 | [diff] [blame] | 623 | pdbus->enable = enable; |
Dhaval Patel | 60c2506 | 2017-02-21 17:44:05 -0800 | [diff] [blame] | 624 | |
| 625 | if (pdbus->data_bus_hdl) |
Alan Kwong | ff30f4a | 2017-05-23 12:02:00 -0700 | [diff] [blame] | 626 | rc = _sde_power_data_bus_set_quota(pdbus, pdbus->ab_rt, |
| 627 | pdbus->ab_nrt, pdbus->ib_rt, pdbus->ib_nrt); |
Dhaval Patel | 60c2506 | 2017-02-21 17:44:05 -0800 | [diff] [blame] | 628 | |
| 629 | if (rc) |
| 630 | pr_err("failed to set data bus vote rc=%d enable:%d\n", |
| 631 | rc, enable); |
| 632 | |
| 633 | return rc; |
| 634 | } |
| 635 | |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 636 | static int sde_power_reg_bus_update(u32 reg_bus_hdl, u32 usecase_ndx) |
| 637 | { |
| 638 | int rc = 0; |
| 639 | |
| 640 | if (reg_bus_hdl) |
| 641 | rc = msm_bus_scale_client_update_request(reg_bus_hdl, |
| 642 | usecase_ndx); |
| 643 | if (rc) |
| 644 | pr_err("failed to set reg bus vote rc=%d\n", rc); |
| 645 | |
| 646 | return rc; |
| 647 | } |
| 648 | #else |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 649 | static int sde_power_data_bus_parse(struct platform_device *pdev, |
Lingutla Chandrasekhar | 6044b96 | 2017-07-10 13:07:50 +0530 | [diff] [blame] | 650 | struct sde_power_data_bus_handle *pdbus, const char *name) |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 651 | { |
| 652 | return 0; |
| 653 | } |
| 654 | |
| 655 | static void sde_power_data_bus_unregister( |
| 656 | struct sde_power_data_bus_handle *pdbus) |
| 657 | { |
| 658 | } |
| 659 | |
| 660 | int sde_power_data_bus_set_quota(struct sde_power_handle *phandle, |
| 661 | struct sde_power_client *pclient, |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 662 | int bus_client, u32 bus_id, |
| 663 | u64 ab_quota, u64 ib_quota) |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 664 | { |
| 665 | return 0; |
| 666 | } |
| 667 | |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 668 | static int sde_power_reg_bus_parse(struct platform_device *pdev, |
| 669 | struct sde_power_handle *phandle) |
| 670 | { |
| 671 | return 0; |
| 672 | } |
| 673 | |
| 674 | static void sde_power_reg_bus_unregister(u32 reg_bus_hdl) |
| 675 | { |
| 676 | } |
| 677 | |
| 678 | static int sde_power_reg_bus_update(u32 reg_bus_hdl, u32 usecase_ndx) |
| 679 | { |
| 680 | return 0; |
| 681 | } |
Dhaval Patel | 60c2506 | 2017-02-21 17:44:05 -0800 | [diff] [blame] | 682 | |
| 683 | static int sde_power_data_bus_update(struct sde_power_data_bus_handle *pdbus, |
| 684 | bool enable) |
| 685 | { |
| 686 | return 0; |
| 687 | } |
Dhaval Patel | c4f1c7c | 2017-08-16 12:02:21 -0700 | [diff] [blame] | 688 | |
| 689 | int sde_power_data_bus_state_update(struct sde_power_handle *phandle, |
| 690 | bool enable) |
| 691 | { |
| 692 | return 0; |
| 693 | } |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 694 | #endif |
| 695 | |
| 696 | int sde_power_resource_init(struct platform_device *pdev, |
| 697 | struct sde_power_handle *phandle) |
| 698 | { |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 699 | int rc = 0, i; |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 700 | struct dss_module_power *mp; |
| 701 | |
| 702 | if (!phandle || !pdev) { |
| 703 | pr_err("invalid input param\n"); |
| 704 | rc = -EINVAL; |
| 705 | goto end; |
| 706 | } |
| 707 | mp = &phandle->mp; |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 708 | phandle->dev = &pdev->dev; |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 709 | |
| 710 | rc = sde_power_parse_dt_clock(pdev, mp); |
| 711 | if (rc) { |
| 712 | pr_err("device clock parsing failed\n"); |
| 713 | goto end; |
| 714 | } |
| 715 | |
| 716 | rc = sde_power_parse_dt_supply(pdev, mp); |
| 717 | if (rc) { |
| 718 | pr_err("device vreg supply parsing failed\n"); |
| 719 | goto parse_vreg_err; |
| 720 | } |
| 721 | |
| 722 | rc = msm_dss_config_vreg(&pdev->dev, |
| 723 | mp->vreg_config, mp->num_vreg, 1); |
| 724 | if (rc) { |
| 725 | pr_err("vreg config failed rc=%d\n", rc); |
| 726 | goto vreg_err; |
| 727 | } |
| 728 | |
| 729 | rc = msm_dss_get_clk(&pdev->dev, mp->clk_config, mp->num_clk); |
| 730 | if (rc) { |
| 731 | pr_err("clock get failed rc=%d\n", rc); |
| 732 | goto clk_err; |
| 733 | } |
| 734 | |
| 735 | rc = msm_dss_clk_set_rate(mp->clk_config, mp->num_clk); |
| 736 | if (rc) { |
| 737 | pr_err("clock set rate failed rc=%d\n", rc); |
| 738 | goto bus_err; |
| 739 | } |
| 740 | |
| 741 | rc = sde_power_reg_bus_parse(pdev, phandle); |
| 742 | if (rc) { |
| 743 | pr_err("register bus parse failed rc=%d\n", rc); |
| 744 | goto bus_err; |
| 745 | } |
| 746 | |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 747 | for (i = SDE_POWER_HANDLE_DBUS_ID_MNOC; |
| 748 | i < SDE_POWER_HANDLE_DBUS_ID_MAX; i++) { |
| 749 | rc = sde_power_data_bus_parse(pdev, |
| 750 | &phandle->data_bus_handle[i], |
| 751 | data_bus_name[i]); |
| 752 | if (rc) { |
| 753 | pr_err("register data bus parse failed id=%d rc=%d\n", |
| 754 | i, rc); |
| 755 | goto data_bus_err; |
| 756 | } |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 757 | } |
| 758 | |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 759 | INIT_LIST_HEAD(&phandle->power_client_clist); |
Veera Sundaram Sankaran | 410d156 | 2017-03-24 14:48:13 -0700 | [diff] [blame] | 760 | INIT_LIST_HEAD(&phandle->event_list); |
| 761 | |
Veera Sundaram Sankaran | 38318f1 | 2017-03-24 15:54:21 -0700 | [diff] [blame] | 762 | phandle->rsc_client = NULL; |
| 763 | phandle->rsc_client_init = false; |
| 764 | |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 765 | mutex_init(&phandle->phandle_lock); |
| 766 | |
| 767 | return rc; |
| 768 | |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 769 | data_bus_err: |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 770 | for (i--; i >= 0; i--) |
| 771 | sde_power_data_bus_unregister(&phandle->data_bus_handle[i]); |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 772 | sde_power_reg_bus_unregister(phandle->reg_bus_hdl); |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 773 | bus_err: |
| 774 | msm_dss_put_clk(mp->clk_config, mp->num_clk); |
| 775 | clk_err: |
| 776 | msm_dss_config_vreg(&pdev->dev, mp->vreg_config, mp->num_vreg, 0); |
| 777 | vreg_err: |
Veera Sundaram Sankaran | 410d156 | 2017-03-24 14:48:13 -0700 | [diff] [blame] | 778 | if (mp->vreg_config) |
| 779 | devm_kfree(&pdev->dev, mp->vreg_config); |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 780 | mp->num_vreg = 0; |
| 781 | parse_vreg_err: |
Veera Sundaram Sankaran | 410d156 | 2017-03-24 14:48:13 -0700 | [diff] [blame] | 782 | if (mp->clk_config) |
| 783 | devm_kfree(&pdev->dev, mp->clk_config); |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 784 | mp->num_clk = 0; |
| 785 | end: |
| 786 | return rc; |
| 787 | } |
| 788 | |
| 789 | void sde_power_resource_deinit(struct platform_device *pdev, |
| 790 | struct sde_power_handle *phandle) |
| 791 | { |
| 792 | struct dss_module_power *mp; |
Veera Sundaram Sankaran | 410d156 | 2017-03-24 14:48:13 -0700 | [diff] [blame] | 793 | struct sde_power_client *curr_client, *next_client; |
| 794 | struct sde_power_event *curr_event, *next_event; |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 795 | int i; |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 796 | |
Dhaval Patel | cd78b8a | 2016-10-11 10:26:07 -0700 | [diff] [blame] | 797 | if (!phandle || !pdev) { |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 798 | pr_err("invalid input param\n"); |
| 799 | return; |
| 800 | } |
| 801 | mp = &phandle->mp; |
| 802 | |
Veera Sundaram Sankaran | 410d156 | 2017-03-24 14:48:13 -0700 | [diff] [blame] | 803 | mutex_lock(&phandle->phandle_lock); |
| 804 | list_for_each_entry_safe(curr_client, next_client, |
| 805 | &phandle->power_client_clist, list) { |
| 806 | pr_err("cliend:%s-%d still registered with refcount:%d\n", |
| 807 | curr_client->name, curr_client->id, |
| 808 | curr_client->refcount); |
| 809 | curr_client->active = false; |
| 810 | list_del(&curr_client->list); |
| 811 | } |
| 812 | |
| 813 | list_for_each_entry_safe(curr_event, next_event, |
| 814 | &phandle->event_list, list) { |
| 815 | pr_err("event:%d, client:%s still registered\n", |
| 816 | curr_event->event_type, |
| 817 | curr_event->client_name); |
| 818 | curr_event->active = false; |
| 819 | list_del(&curr_event->list); |
| 820 | } |
| 821 | mutex_unlock(&phandle->phandle_lock); |
| 822 | |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 823 | for (i = 0; i < SDE_POWER_HANDLE_DBUS_ID_MAX; i++) |
| 824 | sde_power_data_bus_unregister(&phandle->data_bus_handle[i]); |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 825 | |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 826 | sde_power_reg_bus_unregister(phandle->reg_bus_hdl); |
| 827 | |
| 828 | msm_dss_put_clk(mp->clk_config, mp->num_clk); |
| 829 | |
| 830 | msm_dss_config_vreg(&pdev->dev, mp->vreg_config, mp->num_vreg, 0); |
| 831 | |
Dhaval Patel | cd78b8a | 2016-10-11 10:26:07 -0700 | [diff] [blame] | 832 | if (mp->clk_config) |
| 833 | devm_kfree(&pdev->dev, mp->clk_config); |
| 834 | |
| 835 | if (mp->vreg_config) |
| 836 | devm_kfree(&pdev->dev, mp->vreg_config); |
| 837 | |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 838 | mp->num_vreg = 0; |
| 839 | mp->num_clk = 0; |
Veera Sundaram Sankaran | 38318f1 | 2017-03-24 15:54:21 -0700 | [diff] [blame] | 840 | |
| 841 | if (phandle->rsc_client) |
| 842 | sde_rsc_client_destroy(phandle->rsc_client); |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 843 | } |
| 844 | |
| 845 | int sde_power_resource_enable(struct sde_power_handle *phandle, |
| 846 | struct sde_power_client *pclient, bool enable) |
| 847 | { |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 848 | int rc = 0, i; |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 849 | bool changed = false; |
| 850 | u32 max_usecase_ndx = VOTE_INDEX_DISABLE, prev_usecase_ndx; |
| 851 | struct sde_power_client *client; |
| 852 | struct dss_module_power *mp; |
| 853 | |
| 854 | if (!phandle || !pclient) { |
| 855 | pr_err("invalid input argument\n"); |
| 856 | return -EINVAL; |
| 857 | } |
| 858 | |
| 859 | mp = &phandle->mp; |
| 860 | |
| 861 | mutex_lock(&phandle->phandle_lock); |
| 862 | if (enable) |
| 863 | pclient->refcount++; |
| 864 | else if (pclient->refcount) |
| 865 | pclient->refcount--; |
| 866 | |
| 867 | if (pclient->refcount) |
| 868 | pclient->usecase_ndx = VOTE_INDEX_LOW; |
| 869 | else |
| 870 | pclient->usecase_ndx = VOTE_INDEX_DISABLE; |
| 871 | |
| 872 | list_for_each_entry(client, &phandle->power_client_clist, list) { |
| 873 | if (client->usecase_ndx < VOTE_INDEX_MAX && |
| 874 | client->usecase_ndx > max_usecase_ndx) |
| 875 | max_usecase_ndx = client->usecase_ndx; |
| 876 | } |
| 877 | |
| 878 | if (phandle->current_usecase_ndx != max_usecase_ndx) { |
| 879 | changed = true; |
| 880 | prev_usecase_ndx = phandle->current_usecase_ndx; |
| 881 | phandle->current_usecase_ndx = max_usecase_ndx; |
| 882 | } |
| 883 | |
| 884 | pr_debug("%pS: changed=%d current idx=%d request client %s id:%u enable:%d refcount:%d\n", |
| 885 | __builtin_return_address(0), changed, max_usecase_ndx, |
| 886 | pclient->name, pclient->id, enable, pclient->refcount); |
| 887 | |
| 888 | if (!changed) |
| 889 | goto end; |
| 890 | |
| 891 | if (enable) { |
Veera Sundaram Sankaran | 410d156 | 2017-03-24 14:48:13 -0700 | [diff] [blame] | 892 | sde_power_event_trigger_locked(phandle, |
| 893 | SDE_POWER_EVENT_PRE_ENABLE); |
| 894 | |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 895 | for (i = 0; i < SDE_POWER_HANDLE_DBUS_ID_MAX; i++) { |
| 896 | rc = sde_power_data_bus_update( |
| 897 | &phandle->data_bus_handle[i], enable); |
| 898 | if (rc) { |
| 899 | pr_err("failed to set data bus vote id=%d rc=%d\n", |
| 900 | i, rc); |
| 901 | goto data_bus_hdl_err; |
| 902 | } |
Dhaval Patel | 60c2506 | 2017-02-21 17:44:05 -0800 | [diff] [blame] | 903 | } |
Veera Sundaram Sankaran | 9aa24e9 | 2017-05-01 17:04:10 -0700 | [diff] [blame] | 904 | /* |
| 905 | * - When the target is RSCC enabled, regulator should |
| 906 | * be enabled by the s/w only for the first time during |
| 907 | * bootup. After that, RSCC hardware takes care of enabling/ |
| 908 | * disabling it. |
| 909 | * - When the target is not RSCC enabled, regulator should |
| 910 | * be totally handled by the software. |
| 911 | */ |
| 912 | if (!phandle->rsc_client) { |
Veera Sundaram Sankaran | 38318f1 | 2017-03-24 15:54:21 -0700 | [diff] [blame] | 913 | rc = msm_dss_enable_vreg(mp->vreg_config, mp->num_vreg, |
| 914 | enable); |
| 915 | if (rc) { |
| 916 | pr_err("failed to enable vregs rc=%d\n", rc); |
| 917 | goto vreg_err; |
| 918 | } |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 919 | } |
| 920 | |
| 921 | rc = sde_power_reg_bus_update(phandle->reg_bus_hdl, |
| 922 | max_usecase_ndx); |
| 923 | if (rc) { |
| 924 | pr_err("failed to set reg bus vote rc=%d\n", rc); |
| 925 | goto reg_bus_hdl_err; |
| 926 | } |
| 927 | |
Veera Sundaram Sankaran | 38318f1 | 2017-03-24 15:54:21 -0700 | [diff] [blame] | 928 | rc = sde_power_rsc_update(phandle, true); |
| 929 | if (rc) { |
| 930 | pr_err("failed to update rsc\n"); |
| 931 | goto rsc_err; |
| 932 | } |
| 933 | |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 934 | rc = msm_dss_enable_clk(mp->clk_config, mp->num_clk, enable); |
| 935 | if (rc) { |
| 936 | pr_err("clock enable failed rc:%d\n", rc); |
| 937 | goto clk_err; |
| 938 | } |
Veera Sundaram Sankaran | 410d156 | 2017-03-24 14:48:13 -0700 | [diff] [blame] | 939 | |
| 940 | sde_power_event_trigger_locked(phandle, |
| 941 | SDE_POWER_EVENT_POST_ENABLE); |
| 942 | |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 943 | } else { |
Veera Sundaram Sankaran | 410d156 | 2017-03-24 14:48:13 -0700 | [diff] [blame] | 944 | sde_power_event_trigger_locked(phandle, |
| 945 | SDE_POWER_EVENT_PRE_DISABLE); |
| 946 | |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 947 | msm_dss_enable_clk(mp->clk_config, mp->num_clk, enable); |
| 948 | |
Veera Sundaram Sankaran | 38318f1 | 2017-03-24 15:54:21 -0700 | [diff] [blame] | 949 | sde_power_rsc_update(phandle, false); |
| 950 | |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 951 | sde_power_reg_bus_update(phandle->reg_bus_hdl, |
| 952 | max_usecase_ndx); |
| 953 | |
Veera Sundaram Sankaran | 9aa24e9 | 2017-05-01 17:04:10 -0700 | [diff] [blame] | 954 | if (!phandle->rsc_client) |
Veera Sundaram Sankaran | 38318f1 | 2017-03-24 15:54:21 -0700 | [diff] [blame] | 955 | msm_dss_enable_vreg(mp->vreg_config, mp->num_vreg, |
| 956 | enable); |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 957 | for (i = 0 ; i < SDE_POWER_HANDLE_DBUS_ID_MAX; i++) |
| 958 | sde_power_data_bus_update(&phandle->data_bus_handle[i], |
| 959 | enable); |
Veera Sundaram Sankaran | 410d156 | 2017-03-24 14:48:13 -0700 | [diff] [blame] | 960 | |
| 961 | sde_power_event_trigger_locked(phandle, |
| 962 | SDE_POWER_EVENT_POST_DISABLE); |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 963 | } |
| 964 | |
| 965 | end: |
| 966 | mutex_unlock(&phandle->phandle_lock); |
| 967 | return rc; |
| 968 | |
| 969 | clk_err: |
Veera Sundaram Sankaran | 38318f1 | 2017-03-24 15:54:21 -0700 | [diff] [blame] | 970 | sde_power_rsc_update(phandle, false); |
| 971 | rsc_err: |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 972 | sde_power_reg_bus_update(phandle->reg_bus_hdl, prev_usecase_ndx); |
| 973 | reg_bus_hdl_err: |
Veera Sundaram Sankaran | 9aa24e9 | 2017-05-01 17:04:10 -0700 | [diff] [blame] | 974 | if (!phandle->rsc_client) |
Veera Sundaram Sankaran | 38318f1 | 2017-03-24 15:54:21 -0700 | [diff] [blame] | 975 | msm_dss_enable_vreg(mp->vreg_config, mp->num_vreg, 0); |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 976 | vreg_err: |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 977 | for (i = 0 ; i < SDE_POWER_HANDLE_DBUS_ID_MAX; i++) |
| 978 | sde_power_data_bus_update(&phandle->data_bus_handle[i], 0); |
Dhaval Patel | 60c2506 | 2017-02-21 17:44:05 -0800 | [diff] [blame] | 979 | data_bus_hdl_err: |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 980 | phandle->current_usecase_ndx = prev_usecase_ndx; |
| 981 | mutex_unlock(&phandle->phandle_lock); |
| 982 | return rc; |
| 983 | } |
| 984 | |
| 985 | int sde_power_clk_set_rate(struct sde_power_handle *phandle, char *clock_name, |
| 986 | u64 rate) |
| 987 | { |
| 988 | int i, rc = -EINVAL; |
| 989 | struct dss_module_power *mp; |
| 990 | |
| 991 | if (!phandle) { |
| 992 | pr_err("invalid input power handle\n"); |
| 993 | return -EINVAL; |
| 994 | } |
| 995 | mp = &phandle->mp; |
| 996 | |
| 997 | for (i = 0; i < mp->num_clk; i++) { |
| 998 | if (!strcmp(mp->clk_config[i].clk_name, clock_name)) { |
Alan Kwong | 83b6cbe | 2016-09-17 20:08:37 -0400 | [diff] [blame] | 999 | if (mp->clk_config[i].max_rate && |
| 1000 | (rate > mp->clk_config[i].max_rate)) |
| 1001 | rate = mp->clk_config[i].max_rate; |
| 1002 | |
Dhaval Patel | 480dc52 | 2016-07-27 18:36:59 -0700 | [diff] [blame] | 1003 | mp->clk_config[i].rate = rate; |
| 1004 | rc = msm_dss_clk_set_rate(mp->clk_config, mp->num_clk); |
| 1005 | break; |
| 1006 | } |
| 1007 | } |
| 1008 | |
| 1009 | return rc; |
| 1010 | } |
| 1011 | |
| 1012 | u64 sde_power_clk_get_rate(struct sde_power_handle *phandle, char *clock_name) |
| 1013 | { |
| 1014 | int i; |
| 1015 | struct dss_module_power *mp; |
| 1016 | u64 rate = -EINVAL; |
| 1017 | |
| 1018 | if (!phandle) { |
| 1019 | pr_err("invalid input power handle\n"); |
| 1020 | return -EINVAL; |
| 1021 | } |
| 1022 | mp = &phandle->mp; |
| 1023 | |
| 1024 | for (i = 0; i < mp->num_clk; i++) { |
| 1025 | if (!strcmp(mp->clk_config[i].clk_name, clock_name)) { |
| 1026 | rate = clk_get_rate(mp->clk_config[i].clk); |
| 1027 | break; |
| 1028 | } |
| 1029 | } |
| 1030 | |
| 1031 | return rate; |
| 1032 | } |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 1033 | |
| 1034 | u64 sde_power_clk_get_max_rate(struct sde_power_handle *phandle, |
| 1035 | char *clock_name) |
| 1036 | { |
| 1037 | int i; |
| 1038 | struct dss_module_power *mp; |
| 1039 | u64 rate = 0; |
| 1040 | |
| 1041 | if (!phandle) { |
| 1042 | pr_err("invalid input power handle\n"); |
| 1043 | return 0; |
| 1044 | } |
| 1045 | mp = &phandle->mp; |
| 1046 | |
| 1047 | for (i = 0; i < mp->num_clk; i++) { |
| 1048 | if (!strcmp(mp->clk_config[i].clk_name, clock_name)) { |
| 1049 | rate = mp->clk_config[i].max_rate; |
| 1050 | break; |
| 1051 | } |
| 1052 | } |
| 1053 | |
| 1054 | return rate; |
| 1055 | } |
| 1056 | |
| 1057 | struct clk *sde_power_clk_get_clk(struct sde_power_handle *phandle, |
| 1058 | char *clock_name) |
| 1059 | { |
| 1060 | int i; |
| 1061 | struct dss_module_power *mp; |
| 1062 | struct clk *clk = NULL; |
| 1063 | |
| 1064 | if (!phandle) { |
| 1065 | pr_err("invalid input power handle\n"); |
| 1066 | return 0; |
| 1067 | } |
| 1068 | mp = &phandle->mp; |
| 1069 | |
| 1070 | for (i = 0; i < mp->num_clk; i++) { |
| 1071 | if (!strcmp(mp->clk_config[i].clk_name, clock_name)) { |
| 1072 | clk = mp->clk_config[i].clk; |
| 1073 | break; |
| 1074 | } |
| 1075 | } |
| 1076 | |
| 1077 | return clk; |
| 1078 | } |
Veera Sundaram Sankaran | 410d156 | 2017-03-24 14:48:13 -0700 | [diff] [blame] | 1079 | |
| 1080 | struct sde_power_event *sde_power_handle_register_event( |
| 1081 | struct sde_power_handle *phandle, |
| 1082 | u32 event_type, void (*cb_fnc)(u32 event_type, void *usr), |
| 1083 | void *usr, char *client_name) |
| 1084 | { |
| 1085 | struct sde_power_event *event; |
| 1086 | |
| 1087 | if (!phandle) { |
| 1088 | pr_err("invalid power handle\n"); |
| 1089 | return ERR_PTR(-EINVAL); |
| 1090 | } else if (!cb_fnc || !event_type) { |
| 1091 | pr_err("no callback fnc or event type\n"); |
| 1092 | return ERR_PTR(-EINVAL); |
| 1093 | } |
| 1094 | |
| 1095 | event = kzalloc(sizeof(struct sde_power_event), GFP_KERNEL); |
| 1096 | if (!event) |
| 1097 | return ERR_PTR(-ENOMEM); |
| 1098 | |
| 1099 | event->event_type = event_type; |
| 1100 | event->cb_fnc = cb_fnc; |
| 1101 | event->usr = usr; |
| 1102 | strlcpy(event->client_name, client_name, MAX_CLIENT_NAME_LEN); |
| 1103 | event->active = true; |
| 1104 | |
| 1105 | mutex_lock(&phandle->phandle_lock); |
| 1106 | list_add(&event->list, &phandle->event_list); |
| 1107 | mutex_unlock(&phandle->phandle_lock); |
| 1108 | |
| 1109 | return event; |
| 1110 | } |
| 1111 | |
| 1112 | void sde_power_handle_unregister_event( |
| 1113 | struct sde_power_handle *phandle, |
| 1114 | struct sde_power_event *event) |
| 1115 | { |
| 1116 | if (!phandle || !event) { |
| 1117 | pr_err("invalid phandle or event\n"); |
| 1118 | } else if (!event->active) { |
| 1119 | pr_err("power handle deinit already done\n"); |
| 1120 | kfree(event); |
| 1121 | } else { |
| 1122 | mutex_lock(&phandle->phandle_lock); |
| 1123 | list_del_init(&event->list); |
| 1124 | mutex_unlock(&phandle->phandle_lock); |
| 1125 | kfree(event); |
| 1126 | } |
| 1127 | } |