Benjamin Chan | 1b94f95 | 2017-01-23 17:42:30 -0500 | [diff] [blame^] | 1 | /* Copyright (c) 2012, 2015-2017, The Linux Foundation. All rights reserved. |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -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 | #define pr_fmt(fmt) "%s: " fmt, __func__ |
| 14 | |
| 15 | #include <linux/errno.h> |
| 16 | #include <linux/file.h> |
| 17 | #include <linux/spinlock.h> |
| 18 | #include <linux/types.h> |
| 19 | #include <linux/major.h> |
| 20 | #include <linux/debugfs.h> |
| 21 | #include <linux/clk.h> |
| 22 | #include <linux/slab.h> |
| 23 | #include <linux/io.h> |
| 24 | #include <linux/iopoll.h> |
| 25 | #include <linux/msm-bus.h> |
| 26 | #include <linux/msm-bus-board.h> |
| 27 | #include <linux/regulator/consumer.h> |
| 28 | |
| 29 | #define CREATE_TRACE_POINTS |
| 30 | #include "sde_rotator_base.h" |
| 31 | #include "sde_rotator_util.h" |
| 32 | #include "sde_rotator_trace.h" |
Benjamin Chan | 1b94f95 | 2017-01-23 17:42:30 -0500 | [diff] [blame^] | 33 | #include "sde_rotator_debug.h" |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 34 | |
| 35 | static inline u64 fudge_factor(u64 val, u32 numer, u32 denom) |
| 36 | { |
| 37 | u64 result = (val * (u64)numer); |
| 38 | |
| 39 | do_div(result, denom); |
| 40 | return result; |
| 41 | } |
| 42 | |
| 43 | static inline u64 apply_fudge_factor(u64 val, |
| 44 | struct sde_mult_factor *factor) |
| 45 | { |
| 46 | return fudge_factor(val, factor->numer, factor->denom); |
| 47 | } |
| 48 | |
| 49 | static inline u64 apply_inverse_fudge_factor(u64 val, |
| 50 | struct sde_mult_factor *factor) |
| 51 | { |
| 52 | return fudge_factor(val, factor->denom, factor->numer); |
| 53 | } |
| 54 | |
| 55 | static inline bool validate_comp_ratio(struct sde_mult_factor *factor) |
| 56 | { |
| 57 | return factor->numer && factor->denom; |
| 58 | } |
| 59 | |
| 60 | u32 sde_apply_comp_ratio_factor(u32 quota, |
| 61 | struct sde_mdp_format_params *fmt, |
| 62 | struct sde_mult_factor *factor) |
| 63 | { |
| 64 | struct sde_rot_data_type *mdata = sde_rot_get_mdata(); |
| 65 | |
| 66 | if (!mdata || !test_bit(SDE_QOS_OVERHEAD_FACTOR, |
| 67 | mdata->sde_qos_map)) |
| 68 | return quota; |
| 69 | |
| 70 | /* apply compression ratio, only for compressed formats */ |
| 71 | if (sde_mdp_is_ubwc_format(fmt) && |
| 72 | validate_comp_ratio(factor)) |
| 73 | quota = apply_inverse_fudge_factor(quota, factor); |
| 74 | |
| 75 | return quota; |
| 76 | } |
| 77 | |
| 78 | #define RES_1080p (1088*1920) |
| 79 | #define RES_UHD (3840*2160) |
| 80 | #define XIN_HALT_TIMEOUT_US 0x4000 |
| 81 | |
| 82 | static int sde_mdp_wait_for_xin_halt(u32 xin_id) |
| 83 | { |
| 84 | void __iomem *vbif_base; |
| 85 | u32 status; |
| 86 | struct sde_rot_data_type *mdata = sde_rot_get_mdata(); |
| 87 | u32 idle_mask = BIT(xin_id); |
| 88 | int rc; |
| 89 | |
| 90 | vbif_base = mdata->vbif_nrt_io.base; |
| 91 | |
| 92 | rc = readl_poll_timeout(vbif_base + MMSS_VBIF_XIN_HALT_CTRL1, |
| 93 | status, (status & idle_mask), |
| 94 | 1000, XIN_HALT_TIMEOUT_US); |
| 95 | if (rc == -ETIMEDOUT) { |
| 96 | SDEROT_ERR("VBIF client %d not halting. TIMEDOUT.\n", |
| 97 | xin_id); |
| 98 | } else { |
| 99 | SDEROT_DBG("VBIF client %d is halted\n", xin_id); |
| 100 | } |
| 101 | |
| 102 | return rc; |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * force_on_xin_clk() - enable/disable the force-on for the pipe clock |
| 107 | * @bit_off: offset of the bit to enable/disable the force-on. |
| 108 | * @reg_off: register offset for the clock control. |
| 109 | * @enable: boolean to indicate if the force-on of the clock needs to be |
| 110 | * enabled or disabled. |
| 111 | * |
| 112 | * This function returns: |
| 113 | * true - if the clock is forced-on by this function |
| 114 | * false - if the clock was already forced on |
| 115 | * It is the caller responsibility to check if this function is forcing |
| 116 | * the clock on; if so, it will need to remove the force of the clock, |
| 117 | * otherwise it should avoid to remove the force-on. |
| 118 | * Clocks must be on when calling this function. |
| 119 | */ |
| 120 | static bool force_on_xin_clk(u32 bit_off, u32 clk_ctl_reg_off, bool enable) |
| 121 | { |
| 122 | u32 val; |
| 123 | u32 force_on_mask; |
| 124 | struct sde_rot_data_type *mdata = sde_rot_get_mdata(); |
| 125 | bool clk_forced_on = false; |
| 126 | |
| 127 | force_on_mask = BIT(bit_off); |
| 128 | val = readl_relaxed(mdata->mdp_base + clk_ctl_reg_off); |
| 129 | |
| 130 | clk_forced_on = !(force_on_mask & val); |
| 131 | |
| 132 | if (true == enable) |
| 133 | val |= force_on_mask; |
| 134 | else |
| 135 | val &= ~force_on_mask; |
| 136 | |
| 137 | writel_relaxed(val, mdata->mdp_base + clk_ctl_reg_off); |
| 138 | |
| 139 | return clk_forced_on; |
| 140 | } |
| 141 | |
Alan Kwong | effb5ee | 2016-03-12 19:47:45 -0500 | [diff] [blame] | 142 | u32 sde_mdp_get_ot_limit(u32 width, u32 height, u32 pixfmt, u32 fps, u32 is_rd) |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 143 | { |
| 144 | struct sde_rot_data_type *mdata = sde_rot_get_mdata(); |
Alan Kwong | effb5ee | 2016-03-12 19:47:45 -0500 | [diff] [blame] | 145 | struct sde_mdp_format_params *fmt; |
| 146 | u32 ot_lim; |
| 147 | u32 is_yuv; |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 148 | u32 res; |
| 149 | |
Alan Kwong | effb5ee | 2016-03-12 19:47:45 -0500 | [diff] [blame] | 150 | ot_lim = (is_rd) ? mdata->default_ot_rd_limit : |
| 151 | mdata->default_ot_wr_limit; |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 152 | |
| 153 | /* |
| 154 | * If default ot is not set from dt, |
| 155 | * then do not configure it. |
| 156 | */ |
| 157 | if (ot_lim == 0) |
| 158 | goto exit; |
| 159 | |
| 160 | /* Modify the limits if the target and the use case requires it */ |
Alan Kwong | effb5ee | 2016-03-12 19:47:45 -0500 | [diff] [blame] | 161 | if (false == test_bit(SDE_QOS_OTLIM, mdata->sde_qos_map)) |
| 162 | goto exit; |
| 163 | |
| 164 | res = width * height; |
| 165 | |
| 166 | fmt = sde_get_format_params(pixfmt); |
| 167 | |
| 168 | if (!fmt) { |
| 169 | SDEROT_WARN("invalid format %8.8x\n", pixfmt); |
| 170 | goto exit; |
| 171 | } |
| 172 | |
| 173 | is_yuv = sde_mdp_is_yuv_format(fmt); |
| 174 | |
| 175 | SDEROT_DBG("w:%d h:%d fps:%d pixfmt:%8.8x yuv:%d res:%d rd:%d\n", |
| 176 | width, height, fps, pixfmt, is_yuv, res, is_rd); |
| 177 | |
| 178 | if (!is_yuv) |
| 179 | goto exit; |
| 180 | |
| 181 | if ((res <= RES_1080p) && (fps <= 30)) |
| 182 | ot_lim = 2; |
| 183 | else if ((res <= RES_1080p) && (fps <= 60)) |
| 184 | ot_lim = 4; |
| 185 | else if ((res <= RES_UHD) && (fps <= 30)) |
| 186 | ot_lim = 8; |
| 187 | |
| 188 | exit: |
| 189 | SDEROT_DBG("ot_lim=%d\n", ot_lim); |
| 190 | return ot_lim; |
| 191 | } |
| 192 | |
| 193 | static u32 get_ot_limit(u32 reg_off, u32 bit_off, |
| 194 | struct sde_mdp_set_ot_params *params) |
| 195 | { |
| 196 | struct sde_rot_data_type *mdata = sde_rot_get_mdata(); |
| 197 | u32 ot_lim; |
| 198 | u32 val; |
| 199 | |
| 200 | ot_lim = sde_mdp_get_ot_limit( |
| 201 | params->width, params->height, |
| 202 | params->fmt, params->fps, |
| 203 | params->reg_off_vbif_lim_conf == MMSS_VBIF_RD_LIM_CONF); |
| 204 | |
| 205 | /* |
| 206 | * If default ot is not set from dt, |
| 207 | * then do not configure it. |
| 208 | */ |
| 209 | if (ot_lim == 0) |
| 210 | goto exit; |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 211 | |
| 212 | val = SDE_VBIF_READ(mdata, reg_off); |
| 213 | val &= (0xFF << bit_off); |
| 214 | val = val >> bit_off; |
| 215 | |
| 216 | if (val == ot_lim) |
| 217 | ot_lim = 0; |
| 218 | |
| 219 | exit: |
| 220 | SDEROT_DBG("ot_lim=%d\n", ot_lim); |
Benjamin Chan | 1b94f95 | 2017-01-23 17:42:30 -0500 | [diff] [blame^] | 221 | SDEROT_EVTLOG(params->width, params->height, params->fmt, params->fps, |
| 222 | ot_lim); |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 223 | return ot_lim; |
| 224 | } |
| 225 | |
| 226 | void sde_mdp_set_ot_limit(struct sde_mdp_set_ot_params *params) |
| 227 | { |
| 228 | struct sde_rot_data_type *mdata = sde_rot_get_mdata(); |
| 229 | u32 ot_lim; |
| 230 | u32 reg_off_vbif_lim_conf = (params->xin_id / 4) * 4 + |
| 231 | params->reg_off_vbif_lim_conf; |
| 232 | u32 bit_off_vbif_lim_conf = (params->xin_id % 4) * 8; |
| 233 | u32 reg_val; |
Benjamin Chan | 1b94f95 | 2017-01-23 17:42:30 -0500 | [diff] [blame^] | 234 | u32 sts; |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 235 | bool forced_on; |
| 236 | |
| 237 | ot_lim = get_ot_limit( |
| 238 | reg_off_vbif_lim_conf, |
| 239 | bit_off_vbif_lim_conf, |
| 240 | params) & 0xFF; |
| 241 | |
| 242 | if (ot_lim == 0) |
| 243 | goto exit; |
| 244 | |
Benjamin Chan | 1b94f95 | 2017-01-23 17:42:30 -0500 | [diff] [blame^] | 245 | if (params->rotsts_base && params->rotsts_busy_mask) { |
| 246 | sts = readl_relaxed(params->rotsts_base); |
| 247 | if (sts & params->rotsts_busy_mask) { |
| 248 | SDEROT_ERR( |
| 249 | "Rotator still busy, should not modify VBIF\n"); |
| 250 | SDEROT_EVTLOG_TOUT_HANDLER( |
| 251 | "rot", "vbif_dbg_bus", "panic"); |
| 252 | } |
| 253 | } |
| 254 | |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 255 | trace_rot_perf_set_ot(params->num, params->xin_id, ot_lim); |
| 256 | |
| 257 | forced_on = force_on_xin_clk(params->bit_off_mdp_clk_ctrl, |
| 258 | params->reg_off_mdp_clk_ctrl, true); |
| 259 | |
| 260 | reg_val = SDE_VBIF_READ(mdata, reg_off_vbif_lim_conf); |
| 261 | reg_val &= ~(0xFF << bit_off_vbif_lim_conf); |
| 262 | reg_val |= (ot_lim) << bit_off_vbif_lim_conf; |
| 263 | SDE_VBIF_WRITE(mdata, reg_off_vbif_lim_conf, reg_val); |
| 264 | |
| 265 | reg_val = SDE_VBIF_READ(mdata, MMSS_VBIF_XIN_HALT_CTRL0); |
| 266 | SDE_VBIF_WRITE(mdata, MMSS_VBIF_XIN_HALT_CTRL0, |
| 267 | reg_val | BIT(params->xin_id)); |
| 268 | |
| 269 | /* this is a polling operation */ |
| 270 | sde_mdp_wait_for_xin_halt(params->xin_id); |
| 271 | |
| 272 | reg_val = SDE_VBIF_READ(mdata, MMSS_VBIF_XIN_HALT_CTRL0); |
| 273 | SDE_VBIF_WRITE(mdata, MMSS_VBIF_XIN_HALT_CTRL0, |
| 274 | reg_val & ~BIT(params->xin_id)); |
| 275 | |
| 276 | if (forced_on) |
| 277 | force_on_xin_clk(params->bit_off_mdp_clk_ctrl, |
| 278 | params->reg_off_mdp_clk_ctrl, false); |
| 279 | |
Benjamin Chan | 1b94f95 | 2017-01-23 17:42:30 -0500 | [diff] [blame^] | 280 | SDEROT_EVTLOG(params->num, params->xin_id, ot_lim); |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 281 | exit: |
| 282 | return; |
| 283 | } |
| 284 | |
| 285 | struct reg_bus_client *sde_reg_bus_vote_client_create(char *client_name) |
| 286 | { |
| 287 | struct reg_bus_client *client; |
| 288 | struct sde_rot_data_type *sde_res = sde_rot_get_mdata(); |
| 289 | static u32 id; |
| 290 | |
| 291 | if (client_name == NULL) { |
| 292 | SDEROT_ERR("client name is null\n"); |
| 293 | return ERR_PTR(-EINVAL); |
| 294 | } |
| 295 | |
| 296 | client = kzalloc(sizeof(struct reg_bus_client), GFP_KERNEL); |
| 297 | if (!client) |
| 298 | return ERR_PTR(-ENOMEM); |
| 299 | |
| 300 | mutex_lock(&sde_res->reg_bus_lock); |
| 301 | strlcpy(client->name, client_name, MAX_CLIENT_NAME_LEN); |
| 302 | client->usecase_ndx = VOTE_INDEX_DISABLE; |
| 303 | client->id = id; |
| 304 | SDEROT_DBG("bus vote client %s created:%p id :%d\n", client_name, |
| 305 | client, id); |
| 306 | id++; |
| 307 | list_add(&client->list, &sde_res->reg_bus_clist); |
| 308 | mutex_unlock(&sde_res->reg_bus_lock); |
| 309 | |
| 310 | return client; |
| 311 | } |
| 312 | |
| 313 | void sde_reg_bus_vote_client_destroy(struct reg_bus_client *client) |
| 314 | { |
| 315 | struct sde_rot_data_type *sde_res = sde_rot_get_mdata(); |
| 316 | |
| 317 | if (!client) { |
| 318 | SDEROT_ERR("reg bus vote: invalid client handle\n"); |
| 319 | } else { |
| 320 | SDEROT_DBG("bus vote client %s destroyed:%p id:%u\n", |
| 321 | client->name, client, client->id); |
| 322 | mutex_lock(&sde_res->reg_bus_lock); |
| 323 | list_del_init(&client->list); |
| 324 | mutex_unlock(&sde_res->reg_bus_lock); |
| 325 | kfree(client); |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | int sde_update_reg_bus_vote(struct reg_bus_client *bus_client, u32 usecase_ndx) |
| 330 | { |
| 331 | int ret = 0; |
| 332 | bool changed = false; |
| 333 | u32 max_usecase_ndx = VOTE_INDEX_DISABLE; |
| 334 | struct reg_bus_client *client, *temp_client; |
| 335 | struct sde_rot_data_type *sde_res = sde_rot_get_mdata(); |
| 336 | |
| 337 | if (!sde_res || !sde_res->reg_bus_hdl || !bus_client) |
| 338 | return 0; |
| 339 | |
| 340 | mutex_lock(&sde_res->reg_bus_lock); |
| 341 | bus_client->usecase_ndx = usecase_ndx; |
| 342 | list_for_each_entry_safe(client, temp_client, &sde_res->reg_bus_clist, |
| 343 | list) { |
| 344 | |
| 345 | if (client->usecase_ndx < VOTE_INDEX_MAX && |
| 346 | client->usecase_ndx > max_usecase_ndx) |
| 347 | max_usecase_ndx = client->usecase_ndx; |
| 348 | } |
| 349 | |
| 350 | if (sde_res->reg_bus_usecase_ndx != max_usecase_ndx) { |
| 351 | changed = true; |
| 352 | sde_res->reg_bus_usecase_ndx = max_usecase_ndx; |
| 353 | } |
| 354 | |
| 355 | SDEROT_DBG( |
| 356 | "%pS: changed=%d current idx=%d request client %s id:%u idx:%d\n", |
| 357 | __builtin_return_address(0), changed, max_usecase_ndx, |
| 358 | bus_client->name, bus_client->id, usecase_ndx); |
| 359 | if (changed) |
| 360 | ret = msm_bus_scale_client_update_request(sde_res->reg_bus_hdl, |
| 361 | max_usecase_ndx); |
| 362 | |
| 363 | mutex_unlock(&sde_res->reg_bus_lock); |
| 364 | return ret; |
| 365 | } |
| 366 | |
| 367 | static int sde_mdp_parse_dt_handler(struct platform_device *pdev, |
| 368 | char *prop_name, u32 *offsets, int len) |
| 369 | { |
| 370 | int rc; |
| 371 | |
| 372 | rc = of_property_read_u32_array(pdev->dev.of_node, prop_name, |
| 373 | offsets, len); |
| 374 | if (rc) { |
| 375 | SDEROT_ERR("Error from prop %s : u32 array read\n", prop_name); |
| 376 | return -EINVAL; |
| 377 | } |
| 378 | |
| 379 | return 0; |
| 380 | } |
| 381 | |
| 382 | static int sde_mdp_parse_dt_prop_len(struct platform_device *pdev, |
| 383 | char *prop_name) |
| 384 | { |
| 385 | int len = 0; |
| 386 | |
| 387 | of_find_property(pdev->dev.of_node, prop_name, &len); |
| 388 | |
| 389 | if (len < 1) { |
| 390 | SDEROT_INFO("prop %s : doesn't exist in device tree\n", |
| 391 | prop_name); |
| 392 | return 0; |
| 393 | } |
| 394 | |
| 395 | len = len/sizeof(u32); |
| 396 | |
| 397 | return len; |
| 398 | } |
| 399 | |
| 400 | static void sde_mdp_parse_vbif_qos(struct platform_device *pdev, |
| 401 | struct sde_rot_data_type *mdata) |
| 402 | { |
| 403 | int rc; |
| 404 | |
| 405 | mdata->vbif_rt_qos = NULL; |
| 406 | |
| 407 | mdata->npriority_lvl = sde_mdp_parse_dt_prop_len(pdev, |
| 408 | "qcom,mdss-rot-vbif-qos-setting"); |
| 409 | mdata->vbif_nrt_qos = kzalloc(sizeof(u32) * |
| 410 | mdata->npriority_lvl, GFP_KERNEL); |
| 411 | if (!mdata->vbif_nrt_qos) |
| 412 | return; |
| 413 | |
| 414 | rc = sde_mdp_parse_dt_handler(pdev, |
| 415 | "qcom,mdss-rot-vbif-qos-setting", mdata->vbif_nrt_qos, |
| 416 | mdata->npriority_lvl); |
| 417 | if (rc) { |
| 418 | SDEROT_DBG("vbif setting not found\n"); |
| 419 | return; |
| 420 | } |
| 421 | } |
| 422 | |
| 423 | static int sde_mdp_parse_dt_misc(struct platform_device *pdev, |
| 424 | struct sde_rot_data_type *mdata) |
| 425 | { |
| 426 | int rc; |
| 427 | u32 data; |
| 428 | |
| 429 | rc = of_property_read_u32(pdev->dev.of_node, "qcom,mdss-rot-block-size", |
| 430 | &data); |
| 431 | mdata->rot_block_size = (!rc ? data : 128); |
| 432 | |
| 433 | rc = of_property_read_u32(pdev->dev.of_node, |
| 434 | "qcom,mdss-default-ot-rd-limit", &data); |
| 435 | mdata->default_ot_rd_limit = (!rc ? data : 0); |
| 436 | |
| 437 | rc = of_property_read_u32(pdev->dev.of_node, |
| 438 | "qcom,mdss-default-ot-wr-limit", &data); |
| 439 | mdata->default_ot_wr_limit = (!rc ? data : 0); |
| 440 | |
| 441 | rc = of_property_read_u32(pdev->dev.of_node, |
| 442 | "qcom,mdss-highest-bank-bit", &(mdata->highest_bank_bit)); |
| 443 | if (rc) |
| 444 | SDEROT_DBG( |
| 445 | "Could not read optional property: highest bank bit\n"); |
| 446 | |
| 447 | sde_mdp_parse_vbif_qos(pdev, mdata); |
| 448 | |
| 449 | mdata->mdp_base = mdata->sde_io.base + SDE_MDP_OFFSET; |
| 450 | |
| 451 | return 0; |
| 452 | } |
| 453 | |
| 454 | #define MDP_REG_BUS_VECTOR_ENTRY(ab_val, ib_val) \ |
| 455 | { \ |
| 456 | .src = MSM_BUS_MASTER_AMPSS_M0, \ |
| 457 | .dst = MSM_BUS_SLAVE_DISPLAY_CFG, \ |
| 458 | .ab = (ab_val), \ |
| 459 | .ib = (ib_val), \ |
| 460 | } |
| 461 | |
| 462 | #define BUS_VOTE_19_MHZ 153600000 |
| 463 | #define BUS_VOTE_40_MHZ 320000000 |
| 464 | #define BUS_VOTE_80_MHZ 640000000 |
| 465 | |
| 466 | static struct msm_bus_vectors mdp_reg_bus_vectors[] = { |
| 467 | MDP_REG_BUS_VECTOR_ENTRY(0, 0), |
| 468 | MDP_REG_BUS_VECTOR_ENTRY(0, BUS_VOTE_19_MHZ), |
| 469 | MDP_REG_BUS_VECTOR_ENTRY(0, BUS_VOTE_40_MHZ), |
| 470 | MDP_REG_BUS_VECTOR_ENTRY(0, BUS_VOTE_80_MHZ), |
| 471 | }; |
| 472 | static struct msm_bus_paths mdp_reg_bus_usecases[ARRAY_SIZE( |
| 473 | mdp_reg_bus_vectors)]; |
| 474 | static struct msm_bus_scale_pdata mdp_reg_bus_scale_table = { |
| 475 | .usecase = mdp_reg_bus_usecases, |
| 476 | .num_usecases = ARRAY_SIZE(mdp_reg_bus_usecases), |
| 477 | .name = "sde_reg", |
| 478 | .active_only = true, |
| 479 | }; |
| 480 | |
| 481 | static int sde_mdp_bus_scale_register(struct sde_rot_data_type *mdata) |
| 482 | { |
| 483 | struct msm_bus_scale_pdata *reg_bus_pdata; |
| 484 | int i; |
| 485 | |
| 486 | if (!mdata->reg_bus_hdl) { |
| 487 | reg_bus_pdata = &mdp_reg_bus_scale_table; |
| 488 | for (i = 0; i < reg_bus_pdata->num_usecases; i++) { |
| 489 | mdp_reg_bus_usecases[i].num_paths = 1; |
| 490 | mdp_reg_bus_usecases[i].vectors = |
| 491 | &mdp_reg_bus_vectors[i]; |
| 492 | } |
| 493 | |
| 494 | mdata->reg_bus_hdl = |
| 495 | msm_bus_scale_register_client(reg_bus_pdata); |
| 496 | if (!mdata->reg_bus_hdl) { |
| 497 | /* Continue without reg_bus scaling */ |
| 498 | SDEROT_WARN("reg_bus_client register failed\n"); |
| 499 | } else |
| 500 | SDEROT_DBG("register reg_bus_hdl=%x\n", |
| 501 | mdata->reg_bus_hdl); |
| 502 | } |
| 503 | |
| 504 | return 0; |
| 505 | } |
| 506 | |
| 507 | static void sde_mdp_bus_scale_unregister(struct sde_rot_data_type *mdata) |
| 508 | { |
| 509 | SDEROT_DBG("unregister reg_bus_hdl=%x\n", mdata->reg_bus_hdl); |
| 510 | |
| 511 | if (mdata->reg_bus_hdl) { |
| 512 | msm_bus_scale_unregister_client(mdata->reg_bus_hdl); |
| 513 | mdata->reg_bus_hdl = 0; |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | static struct sde_rot_data_type *sde_rot_res; |
| 518 | |
| 519 | struct sde_rot_data_type *sde_rot_get_mdata(void) |
| 520 | { |
| 521 | return sde_rot_res; |
| 522 | } |
| 523 | |
| 524 | /* |
| 525 | * sde_rotator_base_init - initialize base rotator data/resource |
| 526 | */ |
| 527 | int sde_rotator_base_init(struct sde_rot_data_type **pmdata, |
| 528 | struct platform_device *pdev, |
| 529 | const void *drvdata) |
| 530 | { |
| 531 | int rc; |
| 532 | struct sde_rot_data_type *mdata; |
| 533 | |
| 534 | mdata = devm_kzalloc(&pdev->dev, sizeof(*mdata), GFP_KERNEL); |
| 535 | if (mdata == NULL) |
| 536 | return -ENOMEM; |
| 537 | |
| 538 | mdata->pdev = pdev; |
| 539 | sde_rot_res = mdata; |
| 540 | mutex_init(&mdata->reg_bus_lock); |
| 541 | INIT_LIST_HEAD(&mdata->reg_bus_clist); |
| 542 | |
| 543 | rc = sde_rot_ioremap_byname(pdev, &mdata->sde_io, "mdp_phys"); |
| 544 | if (rc) { |
| 545 | SDEROT_ERR("unable to map SDE base\n"); |
| 546 | goto probe_done; |
| 547 | } |
| 548 | SDEROT_DBG("SDE ROT HW Base addr=0x%x len=0x%x\n", |
| 549 | (int) (unsigned long) mdata->sde_io.base, |
| 550 | mdata->sde_io.len); |
| 551 | |
| 552 | rc = sde_rot_ioremap_byname(pdev, &mdata->vbif_nrt_io, "rot_vbif_phys"); |
| 553 | if (rc) { |
| 554 | SDEROT_ERR("unable to map SDE ROT VBIF base\n"); |
| 555 | goto probe_done; |
| 556 | } |
| 557 | SDEROT_DBG("SDE ROT VBIF HW Base addr=%p len=0x%x\n", |
| 558 | mdata->vbif_nrt_io.base, mdata->vbif_nrt_io.len); |
| 559 | |
| 560 | rc = sde_mdp_parse_dt_misc(pdev, mdata); |
| 561 | if (rc) { |
| 562 | SDEROT_ERR("Error in device tree : misc\n"); |
| 563 | goto probe_done; |
| 564 | } |
| 565 | |
| 566 | rc = sde_mdp_bus_scale_register(mdata); |
| 567 | if (rc) { |
| 568 | SDEROT_ERR("unable to register bus scaling\n"); |
| 569 | goto probe_done; |
| 570 | } |
| 571 | |
| 572 | rc = sde_smmu_init(&pdev->dev); |
| 573 | if (rc) { |
| 574 | SDEROT_ERR("sde smmu init failed %d\n", rc); |
| 575 | goto probe_done; |
| 576 | } |
| 577 | |
Abhijit Kulkarni | 298c823 | 2016-09-26 22:32:10 -0700 | [diff] [blame] | 578 | mdata->iclient = msm_ion_client_create(mdata->pdev->name); |
| 579 | if (IS_ERR_OR_NULL(mdata->iclient)) { |
| 580 | SDEROT_ERR("msm_ion_client_create() return error (%pK)\n", |
| 581 | mdata->iclient); |
| 582 | mdata->iclient = NULL; |
| 583 | rc = -EFAULT; |
| 584 | goto probe_done; |
| 585 | } |
| 586 | |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 587 | *pmdata = mdata; |
| 588 | |
| 589 | return 0; |
| 590 | probe_done: |
| 591 | return rc; |
| 592 | } |
| 593 | |
| 594 | /* |
| 595 | * sde_rotator_base_destroy - clean up base rotator data/resource |
| 596 | */ |
| 597 | void sde_rotator_base_destroy(struct sde_rot_data_type *mdata) |
| 598 | { |
| 599 | struct platform_device *pdev; |
| 600 | |
| 601 | if (!mdata || !mdata->pdev) |
| 602 | return; |
| 603 | |
| 604 | pdev = mdata->pdev; |
| 605 | |
| 606 | sde_rot_res = NULL; |
| 607 | sde_mdp_bus_scale_unregister(mdata); |
| 608 | sde_rot_iounmap(&mdata->vbif_nrt_io); |
| 609 | sde_rot_iounmap(&mdata->sde_io); |
| 610 | devm_kfree(&pdev->dev, mdata); |
| 611 | } |