Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved. |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/interrupt.h> |
| 16 | #include <linux/spinlock.h> |
| 17 | #include <linux/delay.h> |
| 18 | #include <linux/io.h> |
| 19 | #include <linux/of_device.h> |
| 20 | #include <linux/of_gpio.h> |
| 21 | #include <linux/gpio.h> |
| 22 | #include <linux/err.h> |
| 23 | #include <linux/regulator/consumer.h> |
| 24 | #include <linux/leds-qpnp-wled.h> |
| 25 | #include <linux/clk.h> |
| 26 | #include <linux/uaccess.h> |
| 27 | #include <linux/msm-bus.h> |
| 28 | #include <linux/pm_qos.h> |
Sachin Bhayare | 3d3767e | 2018-01-02 21:10:57 +0530 | [diff] [blame] | 29 | #include <linux/mdss_io_util.h> |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 30 | |
| 31 | #include "mdss.h" |
| 32 | #include "mdss_panel.h" |
| 33 | #include "mdss_dsi.h" |
| 34 | #include "mdss_debug.h" |
| 35 | #include "mdss_dsi_phy.h" |
| 36 | #include "mdss_dba_utils.h" |
| 37 | |
| 38 | #define XO_CLK_RATE 19200000 |
| 39 | #define CMDLINE_DSI_CTL_NUM_STRING_LEN 2 |
| 40 | |
| 41 | /* Master structure to hold all the information about the DSI/panel */ |
| 42 | static struct mdss_dsi_data *mdss_dsi_res; |
| 43 | |
| 44 | #define DSI_DISABLE_PC_LATENCY 100 |
| 45 | #define DSI_ENABLE_PC_LATENCY PM_QOS_DEFAULT_VALUE |
| 46 | |
| 47 | static struct pm_qos_request mdss_dsi_pm_qos_request; |
| 48 | |
| 49 | static void mdss_dsi_pm_qos_add_request(struct mdss_dsi_ctrl_pdata *ctrl_pdata) |
| 50 | { |
| 51 | struct irq_info *irq_info; |
| 52 | |
| 53 | if (!ctrl_pdata || !ctrl_pdata->shared_data) |
| 54 | return; |
| 55 | |
| 56 | irq_info = ctrl_pdata->dsi_hw->irq_info; |
| 57 | |
| 58 | if (!irq_info) |
| 59 | return; |
| 60 | |
| 61 | mutex_lock(&ctrl_pdata->shared_data->pm_qos_lock); |
| 62 | if (!ctrl_pdata->shared_data->pm_qos_req_cnt) { |
| 63 | pr_debug("%s: add request irq\n", __func__); |
| 64 | |
| 65 | mdss_dsi_pm_qos_request.type = PM_QOS_REQ_AFFINE_IRQ; |
| 66 | mdss_dsi_pm_qos_request.irq = irq_info->irq; |
| 67 | pm_qos_add_request(&mdss_dsi_pm_qos_request, |
| 68 | PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE); |
| 69 | } |
| 70 | ctrl_pdata->shared_data->pm_qos_req_cnt++; |
| 71 | mutex_unlock(&ctrl_pdata->shared_data->pm_qos_lock); |
| 72 | } |
| 73 | |
| 74 | static void mdss_dsi_pm_qos_remove_request(struct dsi_shared_data *sdata) |
| 75 | { |
| 76 | if (!sdata) |
| 77 | return; |
| 78 | |
| 79 | mutex_lock(&sdata->pm_qos_lock); |
| 80 | if (sdata->pm_qos_req_cnt) { |
| 81 | sdata->pm_qos_req_cnt--; |
| 82 | if (!sdata->pm_qos_req_cnt) { |
| 83 | pr_debug("%s: remove request", __func__); |
| 84 | pm_qos_remove_request(&mdss_dsi_pm_qos_request); |
| 85 | } |
| 86 | } else { |
| 87 | pr_warn("%s: unbalanced pm_qos ref count\n", __func__); |
| 88 | } |
| 89 | mutex_unlock(&sdata->pm_qos_lock); |
| 90 | } |
| 91 | |
| 92 | static void mdss_dsi_pm_qos_update_request(int val) |
| 93 | { |
| 94 | pr_debug("%s: update request %d", __func__, val); |
| 95 | pm_qos_update_request(&mdss_dsi_pm_qos_request, val); |
| 96 | } |
| 97 | |
| 98 | static int mdss_dsi_pinctrl_set_state(struct mdss_dsi_ctrl_pdata *ctrl_pdata, |
| 99 | bool active); |
| 100 | |
| 101 | static struct mdss_dsi_ctrl_pdata *mdss_dsi_get_ctrl(u32 ctrl_id) |
| 102 | { |
| 103 | if (ctrl_id >= DSI_CTRL_MAX || !mdss_dsi_res) |
| 104 | return NULL; |
| 105 | |
| 106 | return mdss_dsi_res->ctrl_pdata[ctrl_id]; |
| 107 | } |
| 108 | |
| 109 | static void mdss_dsi_config_clk_src(struct platform_device *pdev) |
| 110 | { |
| 111 | struct mdss_dsi_data *dsi_res = platform_get_drvdata(pdev); |
| 112 | struct dsi_shared_data *sdata = dsi_res->shared_data; |
| 113 | |
| 114 | if (!sdata->ext_byte0_clk || !sdata->ext_pixel0_clk) { |
| 115 | pr_debug("%s: DSI-0 ext. clocks not present\n", __func__); |
| 116 | return; |
| 117 | } |
| 118 | |
| 119 | if (mdss_dsi_is_pll_src_default(sdata)) { |
| 120 | /* |
| 121 | * Default Mapping: |
| 122 | * 1. dual-dsi/single-dsi: |
| 123 | * DSI0 <--> PLL0 |
| 124 | * DSI1 <--> PLL1 |
| 125 | * 2. split-dsi: |
| 126 | * DSI0 <--> PLL0 |
| 127 | * DSI1 <--> PLL0 |
| 128 | */ |
| 129 | sdata->byte0_parent = sdata->ext_byte0_clk; |
| 130 | sdata->pixel0_parent = sdata->ext_pixel0_clk; |
| 131 | |
| 132 | if (mdss_dsi_is_hw_config_split(sdata)) { |
| 133 | sdata->byte1_parent = sdata->byte0_parent; |
| 134 | sdata->pixel1_parent = sdata->pixel0_parent; |
| 135 | } else if (sdata->ext_byte1_clk && sdata->ext_pixel1_clk) { |
| 136 | sdata->byte1_parent = sdata->ext_byte1_clk; |
| 137 | sdata->pixel1_parent = sdata->ext_pixel1_clk; |
| 138 | } else { |
| 139 | pr_debug("%s: DSI-1 external clocks not present\n", |
| 140 | __func__); |
| 141 | return; |
| 142 | } |
| 143 | |
| 144 | pr_debug("%s: default: DSI0 <--> PLL0, DSI1 <--> %s", __func__, |
| 145 | mdss_dsi_is_hw_config_split(sdata) ? "PLL0" : "PLL1"); |
| 146 | } else { |
| 147 | /* |
| 148 | * For split-dsi and single-dsi use cases, map the PLL source |
| 149 | * based on the pll source configuration. It is possible that |
| 150 | * for split-dsi case, the only supported config is to source |
| 151 | * the clocks from PLL0. This is not explicitly checked here as |
| 152 | * it should have been already enforced when validating the |
| 153 | * board configuration. |
| 154 | */ |
| 155 | if (mdss_dsi_is_pll_src_pll0(sdata)) { |
| 156 | pr_debug("%s: single source: PLL0", __func__); |
| 157 | sdata->byte0_parent = sdata->ext_byte0_clk; |
| 158 | sdata->pixel0_parent = sdata->ext_pixel0_clk; |
| 159 | } else if (mdss_dsi_is_pll_src_pll1(sdata)) { |
| 160 | if (sdata->ext_byte1_clk && sdata->ext_pixel1_clk) { |
| 161 | pr_debug("%s: single source: PLL1", __func__); |
| 162 | sdata->byte0_parent = sdata->ext_byte1_clk; |
| 163 | sdata->pixel0_parent = sdata->ext_pixel1_clk; |
| 164 | } else { |
| 165 | pr_err("%s: DSI-1 external clocks not present\n", |
| 166 | __func__); |
| 167 | return; |
| 168 | } |
| 169 | } |
| 170 | sdata->byte1_parent = sdata->byte0_parent; |
| 171 | sdata->pixel1_parent = sdata->pixel0_parent; |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | static char const *mdss_dsi_get_clk_src(struct mdss_dsi_ctrl_pdata *ctrl) |
| 176 | { |
| 177 | struct dsi_shared_data *sdata; |
| 178 | |
| 179 | if (!ctrl) { |
| 180 | pr_err("%s: Invalid input data\n", __func__); |
| 181 | return "????"; |
| 182 | } |
| 183 | |
| 184 | sdata = ctrl->shared_data; |
| 185 | |
| 186 | if (mdss_dsi_is_left_ctrl(ctrl)) { |
| 187 | if (sdata->byte0_parent == sdata->ext_byte0_clk) |
| 188 | return "PLL0"; |
| 189 | else |
| 190 | return "PLL1"; |
| 191 | } else { |
| 192 | if (sdata->byte1_parent == sdata->ext_byte0_clk) |
| 193 | return "PLL0"; |
| 194 | else |
| 195 | return "PLL1"; |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | static int mdss_dsi_set_clk_src(struct mdss_dsi_ctrl_pdata *ctrl) |
| 200 | { |
| 201 | int rc; |
| 202 | struct dsi_shared_data *sdata; |
| 203 | struct clk *byte_parent, *pixel_parent; |
| 204 | |
| 205 | if (!ctrl) { |
| 206 | pr_err("%s: Invalid input data\n", __func__); |
| 207 | return -EINVAL; |
| 208 | } |
| 209 | |
| 210 | sdata = ctrl->shared_data; |
| 211 | |
| 212 | if (!ctrl->byte_clk_rcg || !ctrl->pixel_clk_rcg) { |
| 213 | pr_debug("%s: set_clk_src not needed\n", __func__); |
| 214 | return 0; |
| 215 | } |
| 216 | |
| 217 | if (mdss_dsi_is_left_ctrl(ctrl)) { |
| 218 | byte_parent = sdata->byte0_parent; |
| 219 | pixel_parent = sdata->pixel0_parent; |
| 220 | } else { |
| 221 | byte_parent = sdata->byte1_parent; |
| 222 | pixel_parent = sdata->pixel1_parent; |
| 223 | } |
| 224 | |
| 225 | rc = clk_set_parent(ctrl->byte_clk_rcg, byte_parent); |
| 226 | if (rc) { |
| 227 | pr_err("%s: failed to set parent for byte clk for ctrl%d. rc=%d\n", |
| 228 | __func__, ctrl->ndx, rc); |
| 229 | goto error; |
| 230 | } |
| 231 | |
| 232 | rc = clk_set_parent(ctrl->pixel_clk_rcg, pixel_parent); |
| 233 | if (rc) { |
| 234 | pr_err("%s: failed to set parent for pixel clk for ctrl%d. rc=%d\n", |
| 235 | __func__, ctrl->ndx, rc); |
| 236 | goto error; |
| 237 | } |
| 238 | |
| 239 | pr_debug("%s: ctrl%d clock source set to %s", __func__, ctrl->ndx, |
| 240 | mdss_dsi_get_clk_src(ctrl)); |
| 241 | |
| 242 | error: |
| 243 | return rc; |
| 244 | } |
| 245 | |
| 246 | static int mdss_dsi_regulator_init(struct platform_device *pdev, |
| 247 | struct dsi_shared_data *sdata) |
| 248 | { |
| 249 | int rc = 0, i = 0, j = 0; |
| 250 | |
| 251 | if (!pdev || !sdata) { |
| 252 | pr_err("%s: invalid input\n", __func__); |
| 253 | return -EINVAL; |
| 254 | } |
| 255 | |
| 256 | for (i = DSI_CORE_PM; !rc && (i < DSI_MAX_PM); i++) { |
Sachin Bhayare | 5076e25 | 2018-01-18 14:56:45 +0530 | [diff] [blame] | 257 | rc = msm_mdss_config_vreg(&pdev->dev, |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 258 | sdata->power_data[i].vreg_config, |
| 259 | sdata->power_data[i].num_vreg, 1); |
| 260 | if (rc) { |
| 261 | pr_err("%s: failed to init vregs for %s\n", |
| 262 | __func__, __mdss_dsi_pm_name(i)); |
| 263 | for (j = i-1; j >= DSI_CORE_PM; j--) { |
Sachin Bhayare | 5076e25 | 2018-01-18 14:56:45 +0530 | [diff] [blame] | 264 | msm_mdss_config_vreg(&pdev->dev, |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 265 | sdata->power_data[j].vreg_config, |
| 266 | sdata->power_data[j].num_vreg, 0); |
| 267 | } |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | return rc; |
| 272 | } |
| 273 | |
| 274 | static int mdss_dsi_panel_power_off(struct mdss_panel_data *pdata) |
| 275 | { |
| 276 | int ret = 0; |
| 277 | struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL; |
| 278 | |
| 279 | if (pdata == NULL) { |
| 280 | pr_err("%s: Invalid input data\n", __func__); |
| 281 | ret = -EINVAL; |
| 282 | goto end; |
| 283 | } |
| 284 | |
| 285 | ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata, |
| 286 | panel_data); |
| 287 | |
| 288 | ret = mdss_dsi_panel_reset(pdata, 0); |
| 289 | if (ret) { |
| 290 | pr_warn("%s: Panel reset failed. rc=%d\n", __func__, ret); |
| 291 | ret = 0; |
| 292 | } |
| 293 | |
| 294 | if (mdss_dsi_pinctrl_set_state(ctrl_pdata, false)) |
| 295 | pr_debug("reset disable: pinctrl not enabled\n"); |
| 296 | |
Sachin Bhayare | 5076e25 | 2018-01-18 14:56:45 +0530 | [diff] [blame] | 297 | ret = msm_mdss_enable_vreg( |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 298 | ctrl_pdata->panel_power_data.vreg_config, |
| 299 | ctrl_pdata->panel_power_data.num_vreg, 0); |
| 300 | if (ret) |
| 301 | pr_err("%s: failed to disable vregs for %s\n", |
| 302 | __func__, __mdss_dsi_pm_name(DSI_PANEL_PM)); |
| 303 | |
| 304 | end: |
| 305 | return ret; |
| 306 | } |
| 307 | |
| 308 | static int mdss_dsi_panel_power_on(struct mdss_panel_data *pdata) |
| 309 | { |
| 310 | int ret = 0; |
| 311 | struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL; |
| 312 | |
| 313 | if (pdata == NULL) { |
| 314 | pr_err("%s: Invalid input data\n", __func__); |
| 315 | return -EINVAL; |
| 316 | } |
| 317 | |
| 318 | ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata, |
| 319 | panel_data); |
| 320 | |
Sachin Bhayare | 5076e25 | 2018-01-18 14:56:45 +0530 | [diff] [blame] | 321 | ret = msm_mdss_enable_vreg( |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 322 | ctrl_pdata->panel_power_data.vreg_config, |
| 323 | ctrl_pdata->panel_power_data.num_vreg, 1); |
| 324 | if (ret) { |
| 325 | pr_err("%s: failed to enable vregs for %s\n", |
| 326 | __func__, __mdss_dsi_pm_name(DSI_PANEL_PM)); |
| 327 | return ret; |
| 328 | } |
| 329 | |
| 330 | /* |
| 331 | * If continuous splash screen feature is enabled, then we need to |
| 332 | * request all the GPIOs that have already been configured in the |
| 333 | * bootloader. This needs to be done irresepective of whether |
| 334 | * the lp11_init flag is set or not. |
| 335 | */ |
| 336 | if (pdata->panel_info.cont_splash_enabled || |
| 337 | !pdata->panel_info.mipi.lp11_init) { |
| 338 | if (mdss_dsi_pinctrl_set_state(ctrl_pdata, true)) |
| 339 | pr_debug("reset enable: pinctrl not enabled\n"); |
| 340 | |
| 341 | ret = mdss_dsi_panel_reset(pdata, 1); |
| 342 | if (ret) |
| 343 | pr_err("%s: Panel reset failed. rc=%d\n", |
| 344 | __func__, ret); |
| 345 | } |
| 346 | |
| 347 | return ret; |
| 348 | } |
| 349 | |
| 350 | static int mdss_dsi_panel_power_lp(struct mdss_panel_data *pdata, int enable) |
| 351 | { |
| 352 | /* Panel power control when entering/exiting lp mode */ |
| 353 | return 0; |
| 354 | } |
| 355 | |
| 356 | static int mdss_dsi_panel_power_ulp(struct mdss_panel_data *pdata, |
| 357 | int enable) |
| 358 | { |
| 359 | int ret = 0, i; |
| 360 | struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL; |
| 361 | u32 mode = enable ? DSS_REG_MODE_ULP : DSS_REG_MODE_ENABLE; |
| 362 | struct dsi_shared_data *sdata; |
| 363 | |
| 364 | pr_debug("%s: +\n", __func__); |
| 365 | if (pdata == NULL) { |
| 366 | pr_err("%s: Invalid input data\n", __func__); |
| 367 | return -EINVAL; |
| 368 | } |
| 369 | |
| 370 | ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata, |
| 371 | panel_data); |
| 372 | sdata = ctrl_pdata->shared_data; |
| 373 | |
| 374 | for (i = 0; i < DSI_MAX_PM; i++) { |
| 375 | /* |
| 376 | * Core power module need to be controlled along with |
| 377 | * DSI core clocks. |
| 378 | */ |
| 379 | if (i == DSI_CORE_PM) |
| 380 | continue; |
| 381 | if (i == DSI_PANEL_PM) |
Sachin Bhayare | 5076e25 | 2018-01-18 14:56:45 +0530 | [diff] [blame] | 382 | ret = msm_mdss_config_vreg_opt_mode( |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 383 | ctrl_pdata->panel_power_data.vreg_config, |
| 384 | ctrl_pdata->panel_power_data.num_vreg, mode); |
| 385 | else |
Sachin Bhayare | 5076e25 | 2018-01-18 14:56:45 +0530 | [diff] [blame] | 386 | ret = msm_mdss_config_vreg_opt_mode( |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 387 | sdata->power_data[i].vreg_config, |
| 388 | sdata->power_data[i].num_vreg, mode); |
| 389 | if (ret) { |
| 390 | pr_err("%s: failed to config ulp opt mode for %s.rc=%d\n", |
| 391 | __func__, __mdss_dsi_pm_name(i), ret); |
| 392 | break; |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | if (ret) { |
| 397 | mode = enable ? DSS_REG_MODE_ENABLE : DSS_REG_MODE_ULP; |
| 398 | for (; i >= 0; i--) |
Sachin Bhayare | 5076e25 | 2018-01-18 14:56:45 +0530 | [diff] [blame] | 399 | msm_mdss_config_vreg_opt_mode( |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 400 | ctrl_pdata->power_data[i].vreg_config, |
| 401 | ctrl_pdata->power_data[i].num_vreg, mode); |
| 402 | } |
| 403 | return ret; |
| 404 | } |
| 405 | |
| 406 | int mdss_dsi_panel_power_ctrl(struct mdss_panel_data *pdata, |
| 407 | int power_state) |
| 408 | { |
Sachin Bhayare | 3d3767e | 2018-01-02 21:10:57 +0530 | [diff] [blame] | 409 | int ret = 0; |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 410 | struct mdss_panel_info *pinfo; |
| 411 | struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL; |
| 412 | |
| 413 | if (pdata == NULL) { |
| 414 | pr_err("%s: Invalid input data\n", __func__); |
| 415 | return -EINVAL; |
| 416 | } |
| 417 | |
| 418 | pinfo = &pdata->panel_info; |
| 419 | pr_debug("%pS-->%s: cur_power_state=%d req_power_state=%d\n", |
| 420 | __builtin_return_address(0), __func__, |
| 421 | pinfo->panel_power_state, power_state); |
| 422 | |
| 423 | if (pinfo->panel_power_state == power_state) { |
| 424 | pr_debug("%s: no change needed\n", __func__); |
| 425 | return 0; |
| 426 | } |
| 427 | |
| 428 | ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata, |
| 429 | panel_data); |
| 430 | |
| 431 | /* |
| 432 | * If a dynamic mode switch is pending, the regulators should not |
| 433 | * be turned off or on. |
| 434 | */ |
| 435 | if (pdata->panel_info.dynamic_switch_pending) |
| 436 | return 0; |
| 437 | |
| 438 | switch (power_state) { |
| 439 | case MDSS_PANEL_POWER_OFF: |
| 440 | ret = mdss_dsi_panel_power_off(pdata); |
| 441 | break; |
| 442 | case MDSS_PANEL_POWER_ON: |
| 443 | if (mdss_dsi_is_panel_on_ulp(pdata)) { |
| 444 | ret = mdss_dsi_panel_power_ulp(pdata, false); |
| 445 | goto end; |
| 446 | } else if (mdss_dsi_is_panel_on_lp(pdata)) { |
| 447 | ret = mdss_dsi_panel_power_lp(pdata, false); |
| 448 | goto end; |
| 449 | } else { |
| 450 | ret = mdss_dsi_panel_power_on(pdata); |
| 451 | } |
| 452 | break; |
| 453 | case MDSS_PANEL_POWER_LP1: |
| 454 | if (mdss_dsi_is_panel_on_ulp(pdata)) |
| 455 | ret = mdss_dsi_panel_power_ulp(pdata, false); |
| 456 | else |
| 457 | ret = mdss_dsi_panel_power_lp(pdata, true); |
| 458 | /* |
| 459 | * temp workaround until framework issues pertaining to LP2 |
| 460 | * power state transitions are fixed. For now, we internally |
| 461 | * transition to LP2 state whenever core power is turned off |
| 462 | * in LP1 state |
| 463 | */ |
| 464 | break; |
| 465 | case MDSS_PANEL_POWER_LP2: |
| 466 | if (!ctrl_pdata->core_power) |
| 467 | ret = mdss_dsi_panel_power_ulp(pdata, true); |
| 468 | break; |
| 469 | default: |
| 470 | pr_err("%s: unknown panel power state requested (%d)\n", |
| 471 | __func__, power_state); |
| 472 | ret = -EINVAL; |
| 473 | } |
| 474 | |
| 475 | if (!ret) |
| 476 | pinfo->panel_power_state = power_state; |
| 477 | end: |
| 478 | return ret; |
| 479 | } |
| 480 | |
| 481 | static void mdss_dsi_put_dt_vreg_data(struct device *dev, |
Sachin Bhayare | 5076e25 | 2018-01-18 14:56:45 +0530 | [diff] [blame] | 482 | struct mdss_module_power *module_power) |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 483 | { |
| 484 | if (!module_power) { |
| 485 | pr_err("%s: invalid input\n", __func__); |
| 486 | return; |
| 487 | } |
| 488 | |
| 489 | if (module_power->vreg_config) { |
| 490 | devm_kfree(dev, module_power->vreg_config); |
| 491 | module_power->vreg_config = NULL; |
| 492 | } |
| 493 | module_power->num_vreg = 0; |
| 494 | } |
| 495 | |
| 496 | static int mdss_dsi_get_dt_vreg_data(struct device *dev, |
Sachin Bhayare | 5076e25 | 2018-01-18 14:56:45 +0530 | [diff] [blame] | 497 | struct device_node *of_node, struct mdss_module_power *mp, |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 498 | enum dsi_pm_type module) |
| 499 | { |
| 500 | int i = 0, rc = 0; |
| 501 | u32 tmp = 0; |
| 502 | struct device_node *supply_node = NULL; |
| 503 | const char *pm_supply_name = NULL; |
| 504 | struct device_node *supply_root_node = NULL; |
| 505 | |
| 506 | if (!dev || !mp) { |
| 507 | pr_err("%s: invalid input\n", __func__); |
| 508 | rc = -EINVAL; |
| 509 | return rc; |
| 510 | } |
| 511 | |
| 512 | mp->num_vreg = 0; |
| 513 | pm_supply_name = __mdss_dsi_pm_supply_node_name(module); |
| 514 | supply_root_node = of_get_child_by_name(of_node, pm_supply_name); |
| 515 | if (!supply_root_node) { |
| 516 | /* |
| 517 | * Try to get the root node for panel power supply using |
| 518 | * of_parse_phandle() API if of_get_child_by_name() API fails. |
| 519 | */ |
| 520 | supply_root_node = of_parse_phandle(of_node, pm_supply_name, 0); |
| 521 | if (!supply_root_node) { |
| 522 | pr_err("no supply entry present: %s\n", pm_supply_name); |
| 523 | goto novreg; |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | |
| 528 | for_each_child_of_node(supply_root_node, supply_node) { |
| 529 | mp->num_vreg++; |
| 530 | } |
| 531 | |
| 532 | if (mp->num_vreg == 0) { |
| 533 | pr_debug("%s: no vreg\n", __func__); |
| 534 | goto novreg; |
| 535 | } else { |
| 536 | pr_debug("%s: vreg found. count=%d\n", __func__, mp->num_vreg); |
| 537 | } |
| 538 | |
Sachin Bhayare | 5076e25 | 2018-01-18 14:56:45 +0530 | [diff] [blame] | 539 | mp->vreg_config = devm_kzalloc(dev, sizeof(struct mdss_vreg) * |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 540 | mp->num_vreg, GFP_KERNEL); |
| 541 | if (!mp->vreg_config) { |
| 542 | rc = -ENOMEM; |
| 543 | goto error; |
| 544 | } |
| 545 | |
| 546 | for_each_child_of_node(supply_root_node, supply_node) { |
| 547 | const char *st = NULL; |
| 548 | /* vreg-name */ |
| 549 | rc = of_property_read_string(supply_node, |
| 550 | "qcom,supply-name", &st); |
| 551 | if (rc) { |
| 552 | pr_err("%s: error reading name. rc=%d\n", |
| 553 | __func__, rc); |
| 554 | goto error; |
| 555 | } |
| 556 | snprintf(mp->vreg_config[i].vreg_name, |
| 557 | ARRAY_SIZE((mp->vreg_config[i].vreg_name)), "%s", st); |
| 558 | /* vreg-min-voltage */ |
| 559 | rc = of_property_read_u32(supply_node, |
| 560 | "qcom,supply-min-voltage", &tmp); |
| 561 | if (rc) { |
| 562 | pr_err("%s: error reading min volt. rc=%d\n", |
| 563 | __func__, rc); |
| 564 | goto error; |
| 565 | } |
| 566 | mp->vreg_config[i].min_voltage = tmp; |
| 567 | |
| 568 | /* vreg-max-voltage */ |
| 569 | rc = of_property_read_u32(supply_node, |
| 570 | "qcom,supply-max-voltage", &tmp); |
| 571 | if (rc) { |
| 572 | pr_err("%s: error reading max volt. rc=%d\n", |
| 573 | __func__, rc); |
| 574 | goto error; |
| 575 | } |
| 576 | mp->vreg_config[i].max_voltage = tmp; |
| 577 | |
| 578 | /* enable-load */ |
| 579 | rc = of_property_read_u32(supply_node, |
| 580 | "qcom,supply-enable-load", &tmp); |
| 581 | if (rc) { |
| 582 | pr_err("%s: error reading enable load. rc=%d\n", |
| 583 | __func__, rc); |
| 584 | goto error; |
| 585 | } |
| 586 | mp->vreg_config[i].load[DSS_REG_MODE_ENABLE] = tmp; |
| 587 | |
| 588 | /* disable-load */ |
| 589 | rc = of_property_read_u32(supply_node, |
| 590 | "qcom,supply-disable-load", &tmp); |
| 591 | if (rc) { |
| 592 | pr_err("%s: error reading disable load. rc=%d\n", |
| 593 | __func__, rc); |
| 594 | goto error; |
| 595 | } |
| 596 | mp->vreg_config[i].load[DSS_REG_MODE_DISABLE] = tmp; |
| 597 | |
| 598 | /* ulp-load */ |
| 599 | rc = of_property_read_u32(supply_node, |
| 600 | "qcom,supply-ulp-load", &tmp); |
| 601 | if (rc) { |
| 602 | pr_warn("%s: error reading ulp load. rc=%d\n", |
| 603 | __func__, rc); |
| 604 | rc = 0; |
| 605 | } |
| 606 | mp->vreg_config[i].load[DSS_REG_MODE_ULP] = (!rc ? tmp : |
| 607 | mp->vreg_config[i].load[DSS_REG_MODE_ENABLE]); |
| 608 | |
| 609 | /* pre-sleep */ |
| 610 | rc = of_property_read_u32(supply_node, |
| 611 | "qcom,supply-pre-on-sleep", &tmp); |
| 612 | if (rc) { |
| 613 | pr_debug("%s: error reading supply pre sleep value. rc=%d\n", |
| 614 | __func__, rc); |
| 615 | rc = 0; |
| 616 | } else { |
| 617 | mp->vreg_config[i].pre_on_sleep = tmp; |
| 618 | } |
| 619 | |
| 620 | rc = of_property_read_u32(supply_node, |
| 621 | "qcom,supply-pre-off-sleep", &tmp); |
| 622 | if (rc) { |
| 623 | pr_debug("%s: error reading supply pre sleep value. rc=%d\n", |
| 624 | __func__, rc); |
| 625 | rc = 0; |
| 626 | } else { |
| 627 | mp->vreg_config[i].pre_off_sleep = tmp; |
| 628 | } |
| 629 | |
| 630 | /* post-sleep */ |
| 631 | rc = of_property_read_u32(supply_node, |
| 632 | "qcom,supply-post-on-sleep", &tmp); |
| 633 | if (rc) { |
| 634 | pr_debug("%s: error reading supply post sleep value. rc=%d\n", |
| 635 | __func__, rc); |
| 636 | rc = 0; |
| 637 | } else { |
| 638 | mp->vreg_config[i].post_on_sleep = tmp; |
| 639 | } |
| 640 | |
| 641 | rc = of_property_read_u32(supply_node, |
| 642 | "qcom,supply-post-off-sleep", &tmp); |
| 643 | if (rc) { |
| 644 | pr_debug("%s: error reading supply post sleep value. rc=%d\n", |
| 645 | __func__, rc); |
| 646 | rc = 0; |
| 647 | } else { |
| 648 | mp->vreg_config[i].post_off_sleep = tmp; |
| 649 | } |
| 650 | |
| 651 | pr_debug("%s: %s min=%d, max=%d, enable=%d, disable=%d, ulp_load=%d preonsleep=%d, postonsleep=%d, preoffsleep=%d, postoffsleep=%d\n", |
| 652 | __func__, |
| 653 | mp->vreg_config[i].vreg_name, |
| 654 | mp->vreg_config[i].min_voltage, |
| 655 | mp->vreg_config[i].max_voltage, |
| 656 | mp->vreg_config[i].load[DSS_REG_MODE_ENABLE], |
| 657 | mp->vreg_config[i].load[DSS_REG_MODE_DISABLE], |
| 658 | mp->vreg_config[i].load[DSS_REG_MODE_ULP], |
| 659 | mp->vreg_config[i].pre_on_sleep, |
| 660 | mp->vreg_config[i].post_on_sleep, |
| 661 | mp->vreg_config[i].pre_off_sleep, |
| 662 | mp->vreg_config[i].post_off_sleep |
| 663 | ); |
| 664 | ++i; |
| 665 | } |
| 666 | |
| 667 | return rc; |
| 668 | |
| 669 | error: |
| 670 | if (mp->vreg_config) { |
| 671 | devm_kfree(dev, mp->vreg_config); |
| 672 | mp->vreg_config = NULL; |
| 673 | } |
| 674 | novreg: |
| 675 | mp->num_vreg = 0; |
| 676 | |
| 677 | return rc; |
| 678 | } |
| 679 | |
| 680 | static int mdss_dsi_get_panel_cfg(char *panel_cfg, |
| 681 | struct mdss_dsi_ctrl_pdata *ctrl) |
| 682 | { |
| 683 | int rc; |
| 684 | struct mdss_panel_cfg *pan_cfg = NULL; |
| 685 | |
| 686 | if (!panel_cfg) |
| 687 | return MDSS_PANEL_INTF_INVALID; |
| 688 | |
| 689 | pan_cfg = ctrl->mdss_util->panel_intf_type(MDSS_PANEL_INTF_DSI); |
| 690 | if (IS_ERR(pan_cfg)) { |
| 691 | return PTR_ERR(pan_cfg); |
| 692 | } else if (!pan_cfg) { |
| 693 | panel_cfg[0] = 0; |
| 694 | return 0; |
| 695 | } |
| 696 | |
| 697 | pr_debug("%s:%d: cfg:[%s]\n", __func__, __LINE__, |
| 698 | pan_cfg->arg_cfg); |
| 699 | rc = strlcpy(panel_cfg, pan_cfg->arg_cfg, |
| 700 | sizeof(pan_cfg->arg_cfg)); |
| 701 | return rc; |
| 702 | } |
| 703 | |
| 704 | struct buf_data { |
| 705 | char *buf; /* cmd buf */ |
| 706 | int blen; /* cmd buf length */ |
| 707 | char *string_buf; /* cmd buf as string, 3 bytes per number */ |
| 708 | int sblen; /* string buffer length */ |
| 709 | int sync_flag; |
| 710 | struct mutex dbg_mutex; /* mutex to synchronize read/write/flush */ |
| 711 | }; |
| 712 | |
| 713 | struct mdss_dsi_debugfs_info { |
| 714 | struct dentry *root; |
| 715 | struct mdss_dsi_ctrl_pdata ctrl_pdata; |
| 716 | struct buf_data on_cmd; |
| 717 | struct buf_data off_cmd; |
| 718 | u32 override_flag; |
| 719 | }; |
| 720 | |
| 721 | static int mdss_dsi_cmd_state_open(struct inode *inode, struct file *file) |
| 722 | { |
| 723 | /* non-seekable */ |
| 724 | file->private_data = inode->i_private; |
| 725 | return nonseekable_open(inode, file); |
| 726 | } |
| 727 | |
| 728 | static ssize_t mdss_dsi_cmd_state_read(struct file *file, char __user *buf, |
| 729 | size_t count, loff_t *ppos) |
| 730 | { |
| 731 | int *link_state = file->private_data; |
| 732 | char buffer[32]; |
| 733 | int blen = 0; |
| 734 | |
| 735 | if (*ppos) |
| 736 | return 0; |
| 737 | |
| 738 | if ((*link_state) == DSI_HS_MODE) |
| 739 | blen = snprintf(buffer, sizeof(buffer), "dsi_hs_mode\n"); |
| 740 | else |
| 741 | blen = snprintf(buffer, sizeof(buffer), "dsi_lp_mode\n"); |
| 742 | |
| 743 | if (blen < 0) |
| 744 | return 0; |
| 745 | |
Rashi Bindra | 1dba452 | 2018-04-04 17:58:15 +0530 | [diff] [blame] | 746 | if (copy_to_user(buf, buffer, min(count, (size_t)blen+1))) |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 747 | return -EFAULT; |
| 748 | |
| 749 | *ppos += blen; |
| 750 | return blen; |
| 751 | } |
| 752 | |
| 753 | static ssize_t mdss_dsi_cmd_state_write(struct file *file, |
| 754 | const char __user *p, size_t count, loff_t *ppos) |
| 755 | { |
| 756 | int *link_state = file->private_data; |
| 757 | char *input; |
| 758 | |
| 759 | if (!count) { |
| 760 | pr_err("%s: Zero bytes to be written\n", __func__); |
| 761 | return -EINVAL; |
| 762 | } |
| 763 | |
| 764 | input = kmalloc(count, GFP_KERNEL); |
| 765 | if (!input) |
| 766 | return -ENOMEM; |
| 767 | |
| 768 | if (copy_from_user(input, p, count)) { |
| 769 | kfree(input); |
| 770 | return -EFAULT; |
| 771 | } |
| 772 | input[count-1] = '\0'; |
| 773 | |
| 774 | if (strnstr(input, "dsi_hs_mode", strlen("dsi_hs_mode"))) |
| 775 | *link_state = DSI_HS_MODE; |
| 776 | else |
| 777 | *link_state = DSI_LP_MODE; |
| 778 | |
| 779 | kfree(input); |
| 780 | return count; |
| 781 | } |
| 782 | |
| 783 | static const struct file_operations mdss_dsi_cmd_state_fop = { |
| 784 | .open = mdss_dsi_cmd_state_open, |
| 785 | .read = mdss_dsi_cmd_state_read, |
| 786 | .write = mdss_dsi_cmd_state_write, |
| 787 | }; |
| 788 | |
| 789 | static int mdss_dsi_cmd_open(struct inode *inode, struct file *file) |
| 790 | { |
| 791 | /* non-seekable */ |
| 792 | file->private_data = inode->i_private; |
| 793 | return nonseekable_open(inode, file); |
| 794 | } |
| 795 | |
| 796 | static ssize_t mdss_dsi_cmd_read(struct file *file, char __user *buf, |
| 797 | size_t count, loff_t *ppos) |
| 798 | { |
| 799 | struct buf_data *pcmds = file->private_data; |
| 800 | char *bp; |
| 801 | ssize_t ret = 0; |
| 802 | |
| 803 | mutex_lock(&pcmds->dbg_mutex); |
| 804 | if (*ppos == 0) { |
| 805 | kfree(pcmds->string_buf); |
| 806 | pcmds->string_buf = NULL; |
| 807 | pcmds->sblen = 0; |
| 808 | } |
| 809 | |
| 810 | if (!pcmds->string_buf) { |
| 811 | /* |
| 812 | * Buffer size is the sum of cmd length (3 bytes per number) |
| 813 | * with NULL terminater |
| 814 | */ |
| 815 | int bsize = ((pcmds->blen)*3 + 1); |
| 816 | int blen = 0; |
| 817 | char *buffer; |
| 818 | |
| 819 | buffer = kmalloc(bsize, GFP_KERNEL); |
| 820 | if (!buffer) { |
| 821 | mutex_unlock(&pcmds->dbg_mutex); |
| 822 | return -ENOMEM; |
| 823 | } |
| 824 | |
| 825 | bp = pcmds->buf; |
| 826 | while ((blen < (bsize-1)) && |
| 827 | (bp < ((pcmds->buf) + (pcmds->blen)))) { |
| 828 | struct dsi_ctrl_hdr dchdr = |
| 829 | *((struct dsi_ctrl_hdr *)bp); |
| 830 | int dhrlen = sizeof(dchdr), dlen; |
| 831 | char *tmp = (char *)(&dchdr); |
| 832 | |
| 833 | dlen = dchdr.dlen; |
| 834 | dchdr.dlen = htons(dchdr.dlen); |
| 835 | while (dhrlen--) |
| 836 | blen += snprintf(buffer+blen, bsize-blen, |
| 837 | "%02x ", (*tmp++)); |
| 838 | |
| 839 | bp += sizeof(dchdr); |
| 840 | while (dlen--) |
| 841 | blen += snprintf(buffer+blen, bsize-blen, |
| 842 | "%02x ", (*bp++)); |
| 843 | buffer[blen-1] = '\n'; |
| 844 | } |
| 845 | buffer[blen] = '\0'; |
| 846 | pcmds->string_buf = buffer; |
| 847 | pcmds->sblen = blen; |
| 848 | } |
| 849 | |
| 850 | /* |
| 851 | * The max value of count is PAGE_SIZE(4096). |
| 852 | * It may need multiple times of reading if string buf is too large |
| 853 | */ |
| 854 | if (*ppos >= (pcmds->sblen)) { |
| 855 | kfree(pcmds->string_buf); |
| 856 | pcmds->string_buf = NULL; |
| 857 | pcmds->sblen = 0; |
| 858 | mutex_unlock(&pcmds->dbg_mutex); |
| 859 | return 0; /* the end */ |
| 860 | } |
| 861 | ret = simple_read_from_buffer(buf, count, ppos, pcmds->string_buf, |
| 862 | pcmds->sblen); |
| 863 | mutex_unlock(&pcmds->dbg_mutex); |
| 864 | return ret; |
| 865 | } |
| 866 | |
| 867 | static ssize_t mdss_dsi_cmd_write(struct file *file, const char __user *p, |
| 868 | size_t count, loff_t *ppos) |
| 869 | { |
| 870 | struct buf_data *pcmds = file->private_data; |
| 871 | ssize_t ret = 0; |
| 872 | int blen = 0; |
| 873 | char *string_buf; |
| 874 | |
| 875 | mutex_lock(&pcmds->dbg_mutex); |
| 876 | if (*ppos == 0) { |
| 877 | kfree(pcmds->string_buf); |
| 878 | pcmds->string_buf = NULL; |
| 879 | pcmds->sblen = 0; |
| 880 | } |
| 881 | |
| 882 | /* Allocate memory for the received string */ |
| 883 | blen = count + (pcmds->sblen); |
| 884 | string_buf = krealloc(pcmds->string_buf, blen + 1, GFP_KERNEL); |
| 885 | if (!string_buf) { |
| 886 | pr_err("%s: Failed to allocate memory\n", __func__); |
| 887 | mutex_unlock(&pcmds->dbg_mutex); |
| 888 | return -ENOMEM; |
| 889 | } |
| 890 | |
| 891 | /* Writing in batches is possible */ |
| 892 | ret = simple_write_to_buffer(string_buf, blen, ppos, p, count); |
| 893 | if (ret < 0) { |
| 894 | pr_err("%s: Failed to copy data\n", __func__); |
| 895 | mutex_unlock(&pcmds->dbg_mutex); |
| 896 | return -EINVAL; |
| 897 | } |
| 898 | |
| 899 | string_buf[ret] = '\0'; |
| 900 | pcmds->string_buf = string_buf; |
| 901 | pcmds->sblen = count; |
| 902 | mutex_unlock(&pcmds->dbg_mutex); |
| 903 | return ret; |
| 904 | } |
| 905 | |
| 906 | static int mdss_dsi_cmd_flush(struct file *file, fl_owner_t id) |
| 907 | { |
| 908 | struct buf_data *pcmds = file->private_data; |
| 909 | int blen, len, i; |
| 910 | char *buf, *bufp, *bp; |
| 911 | struct dsi_ctrl_hdr *dchdr; |
| 912 | |
| 913 | mutex_lock(&pcmds->dbg_mutex); |
| 914 | |
| 915 | if (!pcmds->string_buf) { |
| 916 | mutex_unlock(&pcmds->dbg_mutex); |
| 917 | return 0; |
| 918 | } |
| 919 | |
| 920 | /* |
| 921 | * Allocate memory for command buffer |
| 922 | * 3 bytes per number, and 2 bytes for the last one |
| 923 | */ |
| 924 | blen = ((pcmds->sblen) + 2) / 3; |
| 925 | buf = kcalloc(1, blen, GFP_KERNEL); |
| 926 | if (!buf) { |
| 927 | pr_err("%s: Failed to allocate memory\n", __func__); |
| 928 | kfree(pcmds->string_buf); |
| 929 | pcmds->string_buf = NULL; |
| 930 | pcmds->sblen = 0; |
| 931 | mutex_unlock(&pcmds->dbg_mutex); |
| 932 | return -ENOMEM; |
| 933 | } |
| 934 | |
| 935 | /* Translate the input string to command array */ |
| 936 | bufp = pcmds->string_buf; |
| 937 | for (i = 0; i < blen; i++) { |
| 938 | uint32_t value = 0; |
| 939 | int step = 0; |
| 940 | |
| 941 | if (sscanf(bufp, "%02x%n", &value, &step) > 0) { |
| 942 | *(buf+i) = (char)value; |
| 943 | bufp += step; |
| 944 | } |
| 945 | } |
| 946 | |
| 947 | /* Scan dcs commands */ |
| 948 | bp = buf; |
| 949 | len = blen; |
| 950 | while (len >= sizeof(*dchdr)) { |
| 951 | dchdr = (struct dsi_ctrl_hdr *)bp; |
| 952 | dchdr->dlen = ntohs(dchdr->dlen); |
| 953 | if (dchdr->dlen > len || dchdr->dlen < 0) { |
| 954 | pr_err("%s: dtsi cmd=%x error, len=%d\n", |
| 955 | __func__, dchdr->dtype, dchdr->dlen); |
| 956 | kfree(buf); |
| 957 | mutex_unlock(&pcmds->dbg_mutex); |
| 958 | return -EINVAL; |
| 959 | } |
| 960 | bp += sizeof(*dchdr); |
| 961 | len -= sizeof(*dchdr); |
| 962 | bp += dchdr->dlen; |
| 963 | len -= dchdr->dlen; |
| 964 | } |
| 965 | if (len != 0) { |
| 966 | pr_err("%s: dcs_cmd=%x len=%d error!\n", __func__, |
| 967 | bp[0], len); |
| 968 | kfree(buf); |
| 969 | mutex_unlock(&pcmds->dbg_mutex); |
| 970 | return -EINVAL; |
| 971 | } |
| 972 | |
| 973 | if (pcmds->sync_flag) { |
| 974 | pcmds->buf = buf; |
| 975 | pcmds->blen = blen; |
| 976 | pcmds->sync_flag = 0; |
| 977 | } else { |
| 978 | kfree(pcmds->buf); |
| 979 | pcmds->buf = buf; |
| 980 | pcmds->blen = blen; |
| 981 | } |
| 982 | mutex_unlock(&pcmds->dbg_mutex); |
| 983 | return 0; |
| 984 | } |
| 985 | |
| 986 | static const struct file_operations mdss_dsi_cmd_fop = { |
| 987 | .open = mdss_dsi_cmd_open, |
| 988 | .read = mdss_dsi_cmd_read, |
| 989 | .write = mdss_dsi_cmd_write, |
| 990 | .flush = mdss_dsi_cmd_flush, |
| 991 | }; |
| 992 | |
| 993 | struct dentry *dsi_debugfs_create_dcs_cmd(const char *name, umode_t mode, |
| 994 | struct dentry *parent, struct buf_data *cmd, |
| 995 | struct dsi_panel_cmds ctrl_cmds) |
| 996 | { |
| 997 | mutex_init(&cmd->dbg_mutex); |
| 998 | cmd->buf = ctrl_cmds.buf; |
| 999 | cmd->blen = ctrl_cmds.blen; |
| 1000 | cmd->string_buf = NULL; |
| 1001 | cmd->sblen = 0; |
| 1002 | cmd->sync_flag = 1; |
| 1003 | |
| 1004 | return debugfs_create_file(name, mode, parent, |
| 1005 | cmd, &mdss_dsi_cmd_fop); |
| 1006 | } |
| 1007 | |
| 1008 | #define DEBUGFS_CREATE_DCS_CMD(name, node, cmd, ctrl_cmd) \ |
| 1009 | dsi_debugfs_create_dcs_cmd(name, 0644, node, cmd, ctrl_cmd) |
| 1010 | |
| 1011 | static int mdss_dsi_debugfs_setup(struct mdss_panel_data *pdata, |
| 1012 | struct dentry *parent) |
| 1013 | { |
| 1014 | struct mdss_dsi_ctrl_pdata *ctrl_pdata, *dfs_ctrl; |
| 1015 | struct mdss_dsi_debugfs_info *dfs; |
| 1016 | |
| 1017 | ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata, |
| 1018 | panel_data); |
| 1019 | |
| 1020 | dfs = kcalloc(1, sizeof(*dfs), GFP_KERNEL); |
| 1021 | if (!dfs) |
| 1022 | return -ENOMEM; |
| 1023 | |
| 1024 | dfs->root = debugfs_create_dir("dsi_ctrl_pdata", parent); |
| 1025 | if (IS_ERR_OR_NULL(dfs->root)) { |
| 1026 | pr_err("%s: debugfs_create_dir dsi fail, error %ld\n", |
| 1027 | __func__, PTR_ERR(dfs->root)); |
| 1028 | kfree(dfs); |
| 1029 | return -ENODEV; |
| 1030 | } |
| 1031 | |
| 1032 | dfs_ctrl = &dfs->ctrl_pdata; |
| 1033 | debugfs_create_u32("override_flag", 0644, dfs->root, |
| 1034 | &dfs->override_flag); |
| 1035 | |
| 1036 | debugfs_create_bool("cmd_sync_wait_broadcast", 0644, dfs->root, |
Sachin Bhayare | 3d3767e | 2018-01-02 21:10:57 +0530 | [diff] [blame] | 1037 | &dfs_ctrl->cmd_sync_wait_broadcast); |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 1038 | debugfs_create_bool("cmd_sync_wait_trigger", 0644, dfs->root, |
Sachin Bhayare | 3d3767e | 2018-01-02 21:10:57 +0530 | [diff] [blame] | 1039 | &dfs_ctrl->cmd_sync_wait_trigger); |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 1040 | |
| 1041 | debugfs_create_file("dsi_on_cmd_state", 0644, dfs->root, |
| 1042 | &dfs_ctrl->on_cmds.link_state, &mdss_dsi_cmd_state_fop); |
| 1043 | debugfs_create_file("dsi_off_cmd_state", 0644, dfs->root, |
| 1044 | &dfs_ctrl->off_cmds.link_state, &mdss_dsi_cmd_state_fop); |
| 1045 | |
| 1046 | DEBUGFS_CREATE_DCS_CMD("dsi_on_cmd", dfs->root, &dfs->on_cmd, |
| 1047 | ctrl_pdata->on_cmds); |
| 1048 | DEBUGFS_CREATE_DCS_CMD("dsi_off_cmd", dfs->root, &dfs->off_cmd, |
| 1049 | ctrl_pdata->off_cmds); |
| 1050 | |
| 1051 | debugfs_create_u32("dsi_err_counter", 0644, dfs->root, |
| 1052 | &dfs_ctrl->err_cont.max_err_index); |
| 1053 | debugfs_create_u32("dsi_err_time_delta", 0644, dfs->root, |
| 1054 | &dfs_ctrl->err_cont.err_time_delta); |
| 1055 | |
| 1056 | dfs->override_flag = 0; |
| 1057 | dfs->ctrl_pdata = *ctrl_pdata; |
| 1058 | ctrl_pdata->debugfs_info = dfs; |
| 1059 | return 0; |
| 1060 | } |
| 1061 | |
| 1062 | static int mdss_dsi_debugfs_init(struct mdss_dsi_ctrl_pdata *ctrl_pdata) |
| 1063 | { |
| 1064 | int rc; |
| 1065 | struct mdss_panel_data *pdata; |
| 1066 | struct mdss_panel_info panel_info; |
| 1067 | |
| 1068 | if (!ctrl_pdata) { |
| 1069 | pr_warn_once("%s: Invalid pdata!\n", __func__); |
| 1070 | return -EINVAL; |
| 1071 | } |
| 1072 | |
| 1073 | pdata = &ctrl_pdata->panel_data; |
| 1074 | if (!pdata) |
| 1075 | return -EINVAL; |
| 1076 | |
| 1077 | panel_info = pdata->panel_info; |
| 1078 | rc = mdss_dsi_debugfs_setup(pdata, panel_info.debugfs_info->root); |
| 1079 | if (rc) { |
| 1080 | pr_err("%s: Error in initilizing dsi ctrl debugfs\n", |
| 1081 | __func__); |
| 1082 | return rc; |
| 1083 | } |
| 1084 | |
| 1085 | pr_debug("%s: Initialized mdss_dsi_debugfs_init\n", __func__); |
| 1086 | return 0; |
| 1087 | } |
| 1088 | |
| 1089 | static void mdss_dsi_debugfs_cleanup(struct mdss_dsi_ctrl_pdata *ctrl_pdata) |
| 1090 | { |
| 1091 | struct mdss_panel_data *pdata = &ctrl_pdata->panel_data; |
| 1092 | |
| 1093 | do { |
| 1094 | struct mdss_dsi_ctrl_pdata *ctrl = container_of(pdata, |
| 1095 | struct mdss_dsi_ctrl_pdata, panel_data); |
| 1096 | struct mdss_dsi_debugfs_info *dfs = ctrl->debugfs_info; |
| 1097 | |
| 1098 | if (dfs && dfs->root) |
| 1099 | debugfs_remove_recursive(dfs->root); |
| 1100 | kfree(dfs); |
| 1101 | pdata = pdata->next; |
| 1102 | } while (pdata); |
| 1103 | pr_debug("%s: Cleaned up mdss_dsi_debugfs_info\n", __func__); |
| 1104 | } |
| 1105 | |
| 1106 | static int _mdss_dsi_refresh_cmd(struct buf_data *new_cmds, |
| 1107 | struct dsi_panel_cmds *original_pcmds) |
| 1108 | { |
| 1109 | char *bp; |
| 1110 | int len, cnt, i; |
| 1111 | struct dsi_ctrl_hdr *dchdr; |
| 1112 | struct dsi_cmd_desc *cmds; |
| 1113 | |
| 1114 | if (new_cmds->sync_flag) |
| 1115 | return 0; |
| 1116 | |
| 1117 | bp = new_cmds->buf; |
| 1118 | len = new_cmds->blen; |
| 1119 | cnt = 0; |
| 1120 | /* Scan dcs commands and get dcs command count */ |
| 1121 | while (len >= sizeof(*dchdr)) { |
| 1122 | dchdr = (struct dsi_ctrl_hdr *)bp; |
| 1123 | if (dchdr->dlen > len) { |
| 1124 | pr_err("%s: dtsi cmd=%x error, len=%d\n", |
| 1125 | __func__, dchdr->dtype, dchdr->dlen); |
| 1126 | return -EINVAL; |
| 1127 | } |
| 1128 | bp += sizeof(*dchdr) + dchdr->dlen; |
| 1129 | len -= sizeof(*dchdr) + dchdr->dlen; |
| 1130 | cnt++; |
| 1131 | } |
| 1132 | |
| 1133 | if (len != 0) { |
| 1134 | pr_err("%s: dcs_cmd=%x len=%d error!\n", __func__, |
| 1135 | bp[0], len); |
| 1136 | return -EINVAL; |
| 1137 | } |
| 1138 | |
| 1139 | /* Reallocate space for dcs commands */ |
| 1140 | cmds = kcalloc(cnt, sizeof(struct dsi_cmd_desc), GFP_KERNEL); |
| 1141 | if (!cmds) |
| 1142 | return -ENOMEM; |
| 1143 | |
| 1144 | kfree(original_pcmds->buf); |
| 1145 | kfree(original_pcmds->cmds); |
| 1146 | original_pcmds->cmd_cnt = cnt; |
| 1147 | original_pcmds->cmds = cmds; |
| 1148 | original_pcmds->buf = new_cmds->buf; |
| 1149 | original_pcmds->blen = new_cmds->blen; |
| 1150 | |
| 1151 | bp = original_pcmds->buf; |
| 1152 | len = original_pcmds->blen; |
| 1153 | for (i = 0; i < cnt; i++) { |
| 1154 | dchdr = (struct dsi_ctrl_hdr *)bp; |
| 1155 | len -= sizeof(*dchdr); |
| 1156 | bp += sizeof(*dchdr); |
| 1157 | original_pcmds->cmds[i].dchdr = *dchdr; |
| 1158 | original_pcmds->cmds[i].payload = bp; |
| 1159 | bp += dchdr->dlen; |
| 1160 | len -= dchdr->dlen; |
| 1161 | } |
| 1162 | |
| 1163 | new_cmds->sync_flag = 1; |
| 1164 | return 0; |
| 1165 | } |
| 1166 | |
| 1167 | static void mdss_dsi_debugfsinfo_to_dsictrl_info( |
| 1168 | struct mdss_dsi_ctrl_pdata *ctrl_pdata) |
| 1169 | { |
| 1170 | struct mdss_dsi_debugfs_info *dfs = ctrl_pdata->debugfs_info; |
| 1171 | struct dsi_err_container *dfs_err_cont = &dfs->ctrl_pdata.err_cont; |
| 1172 | struct dsi_err_container *err_cont = &ctrl_pdata->err_cont; |
| 1173 | |
| 1174 | ctrl_pdata->cmd_sync_wait_broadcast = |
| 1175 | dfs->ctrl_pdata.cmd_sync_wait_broadcast; |
| 1176 | ctrl_pdata->cmd_sync_wait_trigger = |
| 1177 | dfs->ctrl_pdata.cmd_sync_wait_trigger; |
| 1178 | |
| 1179 | _mdss_dsi_refresh_cmd(&dfs->on_cmd, &ctrl_pdata->on_cmds); |
| 1180 | _mdss_dsi_refresh_cmd(&dfs->off_cmd, &ctrl_pdata->off_cmds); |
| 1181 | |
| 1182 | ctrl_pdata->on_cmds.link_state = |
| 1183 | dfs->ctrl_pdata.on_cmds.link_state; |
| 1184 | ctrl_pdata->off_cmds.link_state = |
| 1185 | dfs->ctrl_pdata.off_cmds.link_state; |
| 1186 | |
| 1187 | /* keep error counter between 2 to 10 */ |
| 1188 | if (dfs_err_cont->max_err_index >= 2 && |
| 1189 | dfs_err_cont->max_err_index <= MAX_ERR_INDEX) { |
| 1190 | err_cont->max_err_index = dfs_err_cont->max_err_index; |
| 1191 | } else { |
| 1192 | dfs_err_cont->max_err_index = err_cont->max_err_index; |
| 1193 | pr_warn("resetting the dsi error counter to %d\n", |
| 1194 | err_cont->max_err_index); |
| 1195 | } |
| 1196 | |
| 1197 | /* keep error duration between 16 ms to 100 seconds */ |
| 1198 | if (dfs_err_cont->err_time_delta >= 16 && |
| 1199 | dfs_err_cont->err_time_delta <= 100000) { |
| 1200 | err_cont->err_time_delta = dfs_err_cont->err_time_delta; |
| 1201 | } else { |
| 1202 | dfs_err_cont->err_time_delta = err_cont->err_time_delta; |
| 1203 | pr_warn("resetting the dsi error time delta to %d ms\n", |
| 1204 | err_cont->err_time_delta); |
| 1205 | } |
| 1206 | } |
| 1207 | |
| 1208 | static void mdss_dsi_validate_debugfs_info( |
| 1209 | struct mdss_dsi_ctrl_pdata *ctrl_pdata) |
| 1210 | { |
| 1211 | struct mdss_dsi_debugfs_info *dfs = ctrl_pdata->debugfs_info; |
| 1212 | |
| 1213 | if (dfs->override_flag) { |
| 1214 | pr_debug("%s: Overriding dsi ctrl_pdata with debugfs data\n", |
| 1215 | __func__); |
| 1216 | dfs->override_flag = 0; |
| 1217 | mdss_dsi_debugfsinfo_to_dsictrl_info(ctrl_pdata); |
| 1218 | } |
| 1219 | } |
| 1220 | |
| 1221 | static int mdss_dsi_off(struct mdss_panel_data *pdata, int power_state) |
| 1222 | { |
| 1223 | int ret = 0; |
| 1224 | struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL; |
| 1225 | struct mdss_panel_info *panel_info = NULL; |
| 1226 | |
| 1227 | if (pdata == NULL) { |
| 1228 | pr_err("%s: Invalid input data\n", __func__); |
| 1229 | return -EINVAL; |
| 1230 | } |
| 1231 | |
| 1232 | ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata, |
| 1233 | panel_data); |
| 1234 | |
| 1235 | panel_info = &ctrl_pdata->panel_data.panel_info; |
| 1236 | |
| 1237 | pr_debug("%s+: ctrl=%pK ndx=%d power_state=%d\n", |
| 1238 | __func__, ctrl_pdata, ctrl_pdata->ndx, power_state); |
| 1239 | |
| 1240 | if (power_state == panel_info->panel_power_state) { |
| 1241 | pr_debug("%s: No change in power state %d -> %d\n", __func__, |
| 1242 | panel_info->panel_power_state, power_state); |
| 1243 | goto end; |
| 1244 | } |
| 1245 | |
| 1246 | if (mdss_panel_is_power_on(power_state)) { |
| 1247 | pr_debug("%s: dsi_off with panel always on\n", __func__); |
| 1248 | goto panel_power_ctrl; |
| 1249 | } |
| 1250 | |
| 1251 | /* |
| 1252 | * Link clocks should be turned off before PHY can be disabled. |
| 1253 | * For command mode panels, all clocks are turned off prior to reaching |
| 1254 | * here, so core clocks should be turned on before accessing hardware |
| 1255 | * registers. For video mode panel, turn off link clocks and then |
| 1256 | * disable PHY |
| 1257 | */ |
| 1258 | if (pdata->panel_info.type == MIPI_CMD_PANEL) |
| 1259 | mdss_dsi_clk_ctrl(ctrl_pdata, ctrl_pdata->dsi_clk_handle, |
| 1260 | MDSS_DSI_CORE_CLK, MDSS_DSI_CLK_ON); |
| 1261 | else |
| 1262 | mdss_dsi_clk_ctrl(ctrl_pdata, ctrl_pdata->dsi_clk_handle, |
| 1263 | MDSS_DSI_LINK_CLK, MDSS_DSI_CLK_OFF); |
| 1264 | |
| 1265 | if (!pdata->panel_info.ulps_suspend_enabled) { |
| 1266 | /* disable DSI controller */ |
| 1267 | mdss_dsi_controller_cfg(0, pdata); |
| 1268 | |
| 1269 | /* disable DSI phy */ |
| 1270 | mdss_dsi_phy_disable(ctrl_pdata); |
| 1271 | } |
| 1272 | ctrl_pdata->ctrl_state &= ~CTRL_STATE_DSI_ACTIVE; |
| 1273 | |
| 1274 | mdss_dsi_clk_ctrl(ctrl_pdata, ctrl_pdata->dsi_clk_handle, |
| 1275 | MDSS_DSI_CORE_CLK, MDSS_DSI_CLK_OFF); |
| 1276 | |
| 1277 | panel_power_ctrl: |
| 1278 | ret = mdss_dsi_panel_power_ctrl(pdata, power_state); |
| 1279 | if (ret) { |
| 1280 | pr_err("%s: Panel power off failed\n", __func__); |
| 1281 | goto end; |
| 1282 | } |
| 1283 | |
| 1284 | if (panel_info->dynamic_fps |
| 1285 | && (panel_info->dfps_update == DFPS_SUSPEND_RESUME_MODE) |
| 1286 | && (panel_info->new_fps != panel_info->mipi.frame_rate)) |
| 1287 | panel_info->mipi.frame_rate = panel_info->new_fps; |
| 1288 | |
| 1289 | /* Initialize Max Packet size for DCS reads */ |
| 1290 | ctrl_pdata->cur_max_pkt_size = 0; |
| 1291 | end: |
| 1292 | pr_debug("%s-:\n", __func__); |
| 1293 | |
| 1294 | return ret; |
| 1295 | } |
| 1296 | |
| 1297 | int mdss_dsi_switch_mode(struct mdss_panel_data *pdata, int mode) |
| 1298 | { |
| 1299 | struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL; |
| 1300 | struct mipi_panel_info *pinfo; |
| 1301 | bool dsi_ctrl_setup_needed = false; |
| 1302 | |
| 1303 | if (!pdata) { |
| 1304 | pr_err("%s: Invalid input data\n", __func__); |
| 1305 | return -EINVAL; |
| 1306 | } |
| 1307 | pr_debug("%s, start\n", __func__); |
| 1308 | |
| 1309 | pinfo = &pdata->panel_info.mipi; |
| 1310 | ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata, |
| 1311 | panel_data); |
| 1312 | |
| 1313 | if ((pinfo->dms_mode != DYNAMIC_MODE_RESOLUTION_SWITCH_IMMEDIATE) && |
| 1314 | (pinfo->dms_mode != DYNAMIC_MODE_SWITCH_IMMEDIATE)) { |
| 1315 | pr_debug("%s: Dynamic mode switch not enabled.\n", __func__); |
| 1316 | return -EPERM; |
| 1317 | } |
| 1318 | |
| 1319 | if (mode == MIPI_VIDEO_PANEL) { |
| 1320 | mode = SWITCH_TO_VIDEO_MODE; |
| 1321 | } else if (mode == MIPI_CMD_PANEL) { |
| 1322 | mode = SWITCH_TO_CMD_MODE; |
| 1323 | } else if (mode == SWITCH_RESOLUTION) { |
| 1324 | dsi_ctrl_setup_needed = true; |
| 1325 | pr_debug("Resolution switch mode selected\n"); |
| 1326 | } else { |
| 1327 | pr_err("Invalid mode selected, mode=%d\n", mode); |
| 1328 | return -EINVAL; |
| 1329 | } |
| 1330 | |
| 1331 | mdss_dsi_clk_ctrl(ctrl_pdata, ctrl_pdata->dsi_clk_handle, |
| 1332 | MDSS_DSI_ALL_CLKS, MDSS_DSI_CLK_ON); |
| 1333 | if (dsi_ctrl_setup_needed) |
| 1334 | mdss_dsi_ctrl_setup(ctrl_pdata); |
| 1335 | ctrl_pdata->switch_mode(pdata, mode); |
| 1336 | mdss_dsi_clk_ctrl(ctrl_pdata, ctrl_pdata->dsi_clk_handle, |
| 1337 | MDSS_DSI_ALL_CLKS, MDSS_DSI_CLK_OFF); |
| 1338 | |
| 1339 | pr_debug("%s, end\n", __func__); |
| 1340 | return 0; |
| 1341 | } |
| 1342 | |
| 1343 | static int mdss_dsi_reconfig(struct mdss_panel_data *pdata, int mode) |
| 1344 | { |
| 1345 | struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL; |
| 1346 | struct mipi_panel_info *pinfo; |
| 1347 | |
| 1348 | if (!pdata) { |
| 1349 | pr_err("%s: Invalid input data\n", __func__); |
| 1350 | return -EINVAL; |
| 1351 | } |
| 1352 | pr_debug("%s, start\n", __func__); |
| 1353 | |
| 1354 | ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata, |
| 1355 | panel_data); |
| 1356 | pinfo = &pdata->panel_info.mipi; |
| 1357 | |
| 1358 | if (pinfo->dms_mode == DYNAMIC_MODE_SWITCH_IMMEDIATE) { |
| 1359 | /* reset DSI */ |
| 1360 | mdss_dsi_clk_ctrl(ctrl_pdata, ctrl_pdata->dsi_clk_handle, |
| 1361 | MDSS_DSI_ALL_CLKS, MDSS_DSI_CLK_ON); |
| 1362 | mdss_dsi_sw_reset(ctrl_pdata, true); |
| 1363 | mdss_dsi_ctrl_setup(ctrl_pdata); |
| 1364 | mdss_dsi_controller_cfg(true, pdata); |
| 1365 | mdss_dsi_clk_ctrl(ctrl_pdata, ctrl_pdata->dsi_clk_handle, |
| 1366 | MDSS_DSI_ALL_CLKS, MDSS_DSI_CLK_OFF); |
| 1367 | } |
| 1368 | |
| 1369 | pr_debug("%s, end\n", __func__); |
| 1370 | return 0; |
| 1371 | } |
| 1372 | static int mdss_dsi_update_panel_config(struct mdss_dsi_ctrl_pdata *ctrl_pdata, |
| 1373 | int mode) |
| 1374 | { |
| 1375 | int ret = 0; |
| 1376 | struct mdss_panel_info *pinfo = &(ctrl_pdata->panel_data.panel_info); |
| 1377 | |
| 1378 | if (mode == DSI_CMD_MODE) { |
| 1379 | pinfo->mipi.mode = DSI_CMD_MODE; |
| 1380 | pinfo->type = MIPI_CMD_PANEL; |
| 1381 | pinfo->mipi.vsync_enable = 1; |
| 1382 | pinfo->mipi.hw_vsync_mode = 1; |
| 1383 | pinfo->partial_update_enabled = pinfo->partial_update_supported; |
| 1384 | } else { /*video mode*/ |
| 1385 | pinfo->mipi.mode = DSI_VIDEO_MODE; |
| 1386 | pinfo->type = MIPI_VIDEO_PANEL; |
| 1387 | pinfo->mipi.vsync_enable = 0; |
| 1388 | pinfo->mipi.hw_vsync_mode = 0; |
| 1389 | pinfo->partial_update_enabled = 0; |
| 1390 | } |
| 1391 | |
| 1392 | ctrl_pdata->panel_mode = pinfo->mipi.mode; |
| 1393 | mdss_panel_get_dst_fmt(pinfo->bpp, pinfo->mipi.mode, |
| 1394 | pinfo->mipi.pixel_packing, &(pinfo->mipi.dst_format)); |
| 1395 | return ret; |
| 1396 | } |
| 1397 | |
| 1398 | int mdss_dsi_on(struct mdss_panel_data *pdata) |
| 1399 | { |
| 1400 | int ret = 0; |
| 1401 | struct mdss_panel_info *pinfo; |
| 1402 | struct mipi_panel_info *mipi; |
| 1403 | struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL; |
| 1404 | int cur_power_state; |
| 1405 | |
| 1406 | if (pdata == NULL) { |
| 1407 | pr_err("%s: Invalid input data\n", __func__); |
| 1408 | return -EINVAL; |
| 1409 | } |
| 1410 | |
| 1411 | ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata, |
| 1412 | panel_data); |
| 1413 | |
| 1414 | if (ctrl_pdata->debugfs_info) |
| 1415 | mdss_dsi_validate_debugfs_info(ctrl_pdata); |
| 1416 | |
| 1417 | cur_power_state = pdata->panel_info.panel_power_state; |
| 1418 | pr_debug("%s+: ctrl=%pK ndx=%d cur_power_state=%d\n", __func__, |
| 1419 | ctrl_pdata, ctrl_pdata->ndx, cur_power_state); |
| 1420 | |
| 1421 | pinfo = &pdata->panel_info; |
| 1422 | mipi = &pdata->panel_info.mipi; |
| 1423 | |
| 1424 | if (mdss_dsi_is_panel_on_interactive(pdata)) { |
| 1425 | /* |
| 1426 | * all interrupts are disabled at LK |
| 1427 | * for cont_splash case, intr mask bits need |
| 1428 | * to be restored to allow dcs command be |
| 1429 | * sent to panel |
| 1430 | */ |
| 1431 | mdss_dsi_restore_intr_mask(ctrl_pdata); |
| 1432 | pr_debug("%s: panel already on\n", __func__); |
| 1433 | goto end; |
| 1434 | } |
| 1435 | |
| 1436 | ret = mdss_dsi_panel_power_ctrl(pdata, MDSS_PANEL_POWER_ON); |
| 1437 | if (ret) { |
| 1438 | pr_err("%s:Panel power on failed. rc=%d\n", __func__, ret); |
| 1439 | goto end; |
| 1440 | } |
| 1441 | |
| 1442 | if (mdss_panel_is_power_on(cur_power_state)) { |
| 1443 | pr_debug("%s: dsi_on from panel low power state\n", __func__); |
| 1444 | goto end; |
| 1445 | } |
| 1446 | |
| 1447 | ret = mdss_dsi_set_clk_src(ctrl_pdata); |
| 1448 | if (ret) { |
| 1449 | pr_err("%s: failed to set clk src. rc=%d\n", __func__, ret); |
| 1450 | goto end; |
| 1451 | } |
| 1452 | |
| 1453 | /* |
| 1454 | * Enable DSI core clocks prior to resetting and initializing DSI |
| 1455 | * Phy. Phy and ctrl setup need to be done before enabling the link |
| 1456 | * clocks. |
| 1457 | */ |
| 1458 | mdss_dsi_clk_ctrl(ctrl_pdata, ctrl_pdata->dsi_clk_handle, |
| 1459 | MDSS_DSI_CORE_CLK, MDSS_DSI_CLK_ON); |
| 1460 | |
| 1461 | /* |
| 1462 | * If ULPS during suspend feature is enabled, then DSI PHY was |
| 1463 | * left on during suspend. In this case, we do not need to reset/init |
| 1464 | * PHY. This would have already been done when the CORE clocks are |
| 1465 | * turned on. However, if cont splash is disabled, the first time DSI |
| 1466 | * is powered on, phy init needs to be done unconditionally. |
| 1467 | */ |
| 1468 | if (!pdata->panel_info.ulps_suspend_enabled || !ctrl_pdata->ulps) { |
| 1469 | mdss_dsi_phy_sw_reset(ctrl_pdata); |
| 1470 | mdss_dsi_phy_init(ctrl_pdata); |
| 1471 | mdss_dsi_ctrl_setup(ctrl_pdata); |
| 1472 | } |
| 1473 | ctrl_pdata->ctrl_state |= CTRL_STATE_DSI_ACTIVE; |
| 1474 | |
| 1475 | /* DSI link clocks need to be on prior to ctrl sw reset */ |
| 1476 | mdss_dsi_clk_ctrl(ctrl_pdata, ctrl_pdata->dsi_clk_handle, |
| 1477 | MDSS_DSI_LINK_CLK, MDSS_DSI_CLK_ON); |
| 1478 | mdss_dsi_sw_reset(ctrl_pdata, true); |
| 1479 | |
| 1480 | /* |
| 1481 | * Issue hardware reset line after enabling the DSI clocks and data |
| 1482 | * data lanes for LP11 init |
| 1483 | */ |
| 1484 | if (mipi->lp11_init) { |
| 1485 | if (mdss_dsi_pinctrl_set_state(ctrl_pdata, true)) |
| 1486 | pr_debug("reset enable: pinctrl not enabled\n"); |
| 1487 | mdss_dsi_panel_reset(pdata, 1); |
| 1488 | } |
| 1489 | |
| 1490 | if (mipi->init_delay) |
| 1491 | usleep_range(mipi->init_delay, mipi->init_delay + 10); |
| 1492 | |
| 1493 | if (mipi->force_clk_lane_hs) { |
| 1494 | u32 tmp; |
| 1495 | |
| 1496 | tmp = MIPI_INP((ctrl_pdata->ctrl_base) + 0xac); |
| 1497 | tmp |= (1<<28); |
| 1498 | MIPI_OUTP((ctrl_pdata->ctrl_base) + 0xac, tmp); |
| 1499 | wmb(); /* ensure write is finished before progressing */ |
| 1500 | } |
| 1501 | |
| 1502 | if (pdata->panel_info.type == MIPI_CMD_PANEL) |
| 1503 | mdss_dsi_clk_ctrl(ctrl_pdata, ctrl_pdata->dsi_clk_handle, |
| 1504 | MDSS_DSI_ALL_CLKS, MDSS_DSI_CLK_OFF); |
| 1505 | |
| 1506 | end: |
| 1507 | pr_debug("%s-:\n", __func__); |
| 1508 | return ret; |
| 1509 | } |
| 1510 | |
| 1511 | static int mdss_dsi_pinctrl_set_state( |
| 1512 | struct mdss_dsi_ctrl_pdata *ctrl_pdata, |
| 1513 | bool active) |
| 1514 | { |
| 1515 | struct pinctrl_state *pin_state; |
| 1516 | struct mdss_panel_info *pinfo = NULL; |
| 1517 | int rc = -EFAULT; |
| 1518 | |
| 1519 | if (IS_ERR_OR_NULL(ctrl_pdata->pin_res.pinctrl)) |
| 1520 | return PTR_ERR(ctrl_pdata->pin_res.pinctrl); |
| 1521 | |
| 1522 | pinfo = &ctrl_pdata->panel_data.panel_info; |
| 1523 | if ((mdss_dsi_is_right_ctrl(ctrl_pdata) && |
| 1524 | mdss_dsi_is_hw_config_split(ctrl_pdata->shared_data)) || |
| 1525 | pinfo->is_dba_panel) { |
| 1526 | pr_debug("%s:%d, right ctrl pinctrl config not needed\n", |
| 1527 | __func__, __LINE__); |
| 1528 | return 0; |
| 1529 | } |
| 1530 | |
| 1531 | pin_state = active ? ctrl_pdata->pin_res.gpio_state_active |
| 1532 | : ctrl_pdata->pin_res.gpio_state_suspend; |
| 1533 | if (!IS_ERR_OR_NULL(pin_state)) { |
| 1534 | rc = pinctrl_select_state(ctrl_pdata->pin_res.pinctrl, |
| 1535 | pin_state); |
| 1536 | if (rc) |
| 1537 | pr_err("%s: can not set %s pins\n", __func__, |
| 1538 | active ? MDSS_PINCTRL_STATE_DEFAULT |
| 1539 | : MDSS_PINCTRL_STATE_SLEEP); |
| 1540 | } else { |
| 1541 | pr_err("%s: invalid '%s' pinstate\n", __func__, |
| 1542 | active ? MDSS_PINCTRL_STATE_DEFAULT |
| 1543 | : MDSS_PINCTRL_STATE_SLEEP); |
| 1544 | } |
| 1545 | return rc; |
| 1546 | } |
| 1547 | |
| 1548 | static int mdss_dsi_pinctrl_init(struct platform_device *pdev) |
| 1549 | { |
| 1550 | struct mdss_dsi_ctrl_pdata *ctrl_pdata; |
| 1551 | |
| 1552 | ctrl_pdata = platform_get_drvdata(pdev); |
| 1553 | ctrl_pdata->pin_res.pinctrl = devm_pinctrl_get(&pdev->dev); |
| 1554 | if (IS_ERR_OR_NULL(ctrl_pdata->pin_res.pinctrl)) { |
| 1555 | pr_err("%s: failed to get pinctrl\n", __func__); |
| 1556 | return PTR_ERR(ctrl_pdata->pin_res.pinctrl); |
| 1557 | } |
| 1558 | |
| 1559 | ctrl_pdata->pin_res.gpio_state_active |
| 1560 | = pinctrl_lookup_state(ctrl_pdata->pin_res.pinctrl, |
| 1561 | MDSS_PINCTRL_STATE_DEFAULT); |
| 1562 | if (IS_ERR_OR_NULL(ctrl_pdata->pin_res.gpio_state_active)) |
| 1563 | pr_warn("%s: can not get default pinstate\n", __func__); |
| 1564 | |
| 1565 | ctrl_pdata->pin_res.gpio_state_suspend |
| 1566 | = pinctrl_lookup_state(ctrl_pdata->pin_res.pinctrl, |
| 1567 | MDSS_PINCTRL_STATE_SLEEP); |
| 1568 | if (IS_ERR_OR_NULL(ctrl_pdata->pin_res.gpio_state_suspend)) |
| 1569 | pr_warn("%s: can not get sleep pinstate\n", __func__); |
| 1570 | |
| 1571 | return 0; |
| 1572 | } |
| 1573 | |
| 1574 | static int mdss_dsi_unblank(struct mdss_panel_data *pdata) |
| 1575 | { |
| 1576 | int ret = 0; |
| 1577 | struct mipi_panel_info *mipi; |
| 1578 | struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL; |
| 1579 | struct mdss_dsi_ctrl_pdata *sctrl = NULL; |
| 1580 | |
| 1581 | if (pdata == NULL) { |
| 1582 | pr_err("%s: Invalid input data\n", __func__); |
| 1583 | return -EINVAL; |
| 1584 | } |
| 1585 | |
| 1586 | ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata, |
| 1587 | panel_data); |
| 1588 | mipi = &pdata->panel_info.mipi; |
| 1589 | |
| 1590 | pr_debug("%s+: ctrl=%pK ndx=%d cur_power_state=%d ctrl_state=%x\n", |
| 1591 | __func__, ctrl_pdata, ctrl_pdata->ndx, |
| 1592 | pdata->panel_info.panel_power_state, ctrl_pdata->ctrl_state); |
| 1593 | |
| 1594 | mdss_dsi_pm_qos_update_request(DSI_DISABLE_PC_LATENCY); |
| 1595 | |
| 1596 | if (mdss_dsi_is_ctrl_clk_master(ctrl_pdata)) |
| 1597 | sctrl = mdss_dsi_get_ctrl_clk_slave(); |
| 1598 | |
| 1599 | mdss_dsi_clk_ctrl(ctrl_pdata, ctrl_pdata->dsi_clk_handle, |
| 1600 | MDSS_DSI_ALL_CLKS, MDSS_DSI_CLK_ON); |
| 1601 | if (sctrl) |
| 1602 | mdss_dsi_clk_ctrl(sctrl, sctrl->dsi_clk_handle, |
| 1603 | MDSS_DSI_ALL_CLKS, MDSS_DSI_CLK_ON); |
| 1604 | |
| 1605 | if (ctrl_pdata->ctrl_state & CTRL_STATE_PANEL_LP) { |
| 1606 | pr_debug("%s: dsi_unblank with panel always on\n", __func__); |
| 1607 | if (ctrl_pdata->low_power_config) |
| 1608 | ret = ctrl_pdata->low_power_config(pdata, false); |
| 1609 | if (!ret) |
| 1610 | ctrl_pdata->ctrl_state &= ~CTRL_STATE_PANEL_LP; |
| 1611 | goto error; |
| 1612 | } |
| 1613 | |
| 1614 | if (!(ctrl_pdata->ctrl_state & CTRL_STATE_PANEL_INIT)) { |
| 1615 | if (!pdata->panel_info.dynamic_switch_pending) { |
| 1616 | ATRACE_BEGIN("dsi_panel_on"); |
| 1617 | ret = ctrl_pdata->on(pdata); |
| 1618 | if (ret) { |
| 1619 | pr_err("%s: unable to initialize the panel\n", |
| 1620 | __func__); |
| 1621 | goto error; |
| 1622 | } |
| 1623 | ATRACE_END("dsi_panel_on"); |
| 1624 | } |
| 1625 | } |
| 1626 | |
| 1627 | if ((pdata->panel_info.type == MIPI_CMD_PANEL) && |
| 1628 | mipi->vsync_enable && mipi->hw_vsync_mode) { |
| 1629 | mdss_dsi_set_tear_on(ctrl_pdata); |
| 1630 | } |
| 1631 | |
| 1632 | ctrl_pdata->ctrl_state |= CTRL_STATE_PANEL_INIT; |
| 1633 | |
| 1634 | error: |
| 1635 | mdss_dsi_clk_ctrl(ctrl_pdata, ctrl_pdata->dsi_clk_handle, |
| 1636 | MDSS_DSI_ALL_CLKS, MDSS_DSI_CLK_OFF); |
| 1637 | if (sctrl) |
| 1638 | mdss_dsi_clk_ctrl(sctrl, sctrl->dsi_clk_handle, |
| 1639 | MDSS_DSI_ALL_CLKS, MDSS_DSI_CLK_OFF); |
| 1640 | |
| 1641 | mdss_dsi_pm_qos_update_request(DSI_ENABLE_PC_LATENCY); |
| 1642 | |
| 1643 | pr_debug("%s-:\n", __func__); |
| 1644 | |
| 1645 | return ret; |
| 1646 | } |
| 1647 | |
| 1648 | static int mdss_dsi_blank(struct mdss_panel_data *pdata, int power_state) |
| 1649 | { |
| 1650 | int ret = 0; |
| 1651 | struct mipi_panel_info *mipi; |
| 1652 | struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL; |
| 1653 | |
| 1654 | if (pdata == NULL) { |
| 1655 | pr_err("%s: Invalid input data\n", __func__); |
| 1656 | return -EINVAL; |
| 1657 | } |
| 1658 | |
| 1659 | ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata, |
| 1660 | panel_data); |
| 1661 | mipi = &pdata->panel_info.mipi; |
| 1662 | |
| 1663 | pr_debug("%s+: ctrl=%pK ndx=%d power_state=%d\n", |
| 1664 | __func__, ctrl_pdata, ctrl_pdata->ndx, power_state); |
| 1665 | |
| 1666 | mdss_dsi_clk_ctrl(ctrl_pdata, ctrl_pdata->dsi_clk_handle, |
| 1667 | MDSS_DSI_ALL_CLKS, MDSS_DSI_CLK_ON); |
| 1668 | |
| 1669 | if (mdss_panel_is_power_on_lp(power_state)) { |
| 1670 | pr_debug("%s: low power state requested\n", __func__); |
| 1671 | if (ctrl_pdata->low_power_config) |
| 1672 | ret = ctrl_pdata->low_power_config(pdata, true); |
| 1673 | if (!ret) |
| 1674 | ctrl_pdata->ctrl_state |= CTRL_STATE_PANEL_LP; |
| 1675 | goto error; |
| 1676 | } |
| 1677 | |
| 1678 | if (pdata->panel_info.type == MIPI_VIDEO_PANEL && |
| 1679 | ctrl_pdata->off_cmds.link_state == DSI_LP_MODE) { |
| 1680 | mdss_dsi_sw_reset(ctrl_pdata, false); |
| 1681 | mdss_dsi_host_init(pdata); |
| 1682 | } |
| 1683 | |
| 1684 | mdss_dsi_op_mode_config(DSI_CMD_MODE, pdata); |
| 1685 | |
| 1686 | if (pdata->panel_info.dynamic_switch_pending) { |
| 1687 | pr_info("%s: switching to %s mode\n", __func__, |
| 1688 | (pdata->panel_info.mipi.mode ? "video" : "command")); |
| 1689 | if (pdata->panel_info.type == MIPI_CMD_PANEL) { |
| 1690 | ctrl_pdata->switch_mode(pdata, SWITCH_TO_VIDEO_MODE); |
| 1691 | } else if (pdata->panel_info.type == MIPI_VIDEO_PANEL) { |
| 1692 | ctrl_pdata->switch_mode(pdata, SWITCH_TO_CMD_MODE); |
| 1693 | mdss_dsi_set_tear_off(ctrl_pdata); |
| 1694 | } |
| 1695 | } |
| 1696 | |
| 1697 | if ((pdata->panel_info.type == MIPI_CMD_PANEL) && |
| 1698 | mipi->vsync_enable && mipi->hw_vsync_mode) { |
| 1699 | mdss_dsi_set_tear_off(ctrl_pdata); |
| 1700 | } |
| 1701 | |
| 1702 | if (ctrl_pdata->ctrl_state & CTRL_STATE_PANEL_INIT) { |
| 1703 | if (!pdata->panel_info.dynamic_switch_pending) { |
| 1704 | ATRACE_BEGIN("dsi_panel_off"); |
| 1705 | ret = ctrl_pdata->off(pdata); |
| 1706 | if (ret) { |
| 1707 | pr_err("%s: Panel OFF failed\n", __func__); |
| 1708 | goto error; |
| 1709 | } |
| 1710 | ATRACE_END("dsi_panel_off"); |
| 1711 | } |
| 1712 | ctrl_pdata->ctrl_state &= ~(CTRL_STATE_PANEL_INIT | |
| 1713 | CTRL_STATE_PANEL_LP); |
| 1714 | } |
| 1715 | |
| 1716 | error: |
| 1717 | mdss_dsi_clk_ctrl(ctrl_pdata, ctrl_pdata->dsi_clk_handle, |
| 1718 | MDSS_DSI_ALL_CLKS, MDSS_DSI_CLK_OFF); |
| 1719 | pr_debug("%s-:End\n", __func__); |
| 1720 | return ret; |
| 1721 | } |
| 1722 | |
| 1723 | static int mdss_dsi_post_panel_on(struct mdss_panel_data *pdata) |
| 1724 | { |
| 1725 | struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL; |
| 1726 | |
| 1727 | if (pdata == NULL) { |
| 1728 | pr_err("%s: Invalid input data\n", __func__); |
| 1729 | return -EINVAL; |
| 1730 | } |
| 1731 | |
| 1732 | ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata, |
| 1733 | panel_data); |
| 1734 | |
| 1735 | pr_debug("%s+: ctrl=%pK ndx=%d\n", __func__, |
| 1736 | ctrl_pdata, ctrl_pdata->ndx); |
| 1737 | |
| 1738 | mdss_dsi_clk_ctrl(ctrl_pdata, ctrl_pdata->dsi_clk_handle, |
| 1739 | MDSS_DSI_ALL_CLKS, MDSS_DSI_CLK_ON); |
| 1740 | |
| 1741 | if (ctrl_pdata->post_panel_on) |
| 1742 | ctrl_pdata->post_panel_on(pdata); |
| 1743 | |
| 1744 | mdss_dsi_clk_ctrl(ctrl_pdata, ctrl_pdata->dsi_clk_handle, |
| 1745 | MDSS_DSI_ALL_CLKS, MDSS_DSI_CLK_OFF); |
| 1746 | pr_debug("%s-:\n", __func__); |
| 1747 | |
| 1748 | return 0; |
| 1749 | } |
| 1750 | |
| 1751 | static irqreturn_t test_hw_vsync_handler(int irq, void *data) |
| 1752 | { |
| 1753 | struct mdss_panel_data *pdata = (struct mdss_panel_data *)data; |
| 1754 | |
| 1755 | pr_debug("HW VSYNC\n"); |
| 1756 | MDSS_XLOG(0xaaa, irq); |
| 1757 | complete_all(&pdata->te_done); |
| 1758 | if (pdata->next) |
| 1759 | complete_all(&pdata->next->te_done); |
| 1760 | return IRQ_HANDLED; |
| 1761 | } |
| 1762 | |
| 1763 | int mdss_dsi_cont_splash_on(struct mdss_panel_data *pdata) |
| 1764 | { |
| 1765 | int ret = 0; |
| 1766 | struct mipi_panel_info *mipi; |
| 1767 | struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL; |
| 1768 | |
| 1769 | pr_info("%s:%d DSI on for continuous splash.\n", __func__, __LINE__); |
| 1770 | |
| 1771 | if (pdata == NULL) { |
| 1772 | pr_err("%s: Invalid input data\n", __func__); |
| 1773 | return -EINVAL; |
| 1774 | } |
| 1775 | |
| 1776 | mipi = &pdata->panel_info.mipi; |
| 1777 | |
| 1778 | ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata, |
| 1779 | panel_data); |
| 1780 | |
| 1781 | pr_debug("%s+: ctrl=%pK ndx=%d\n", __func__, |
| 1782 | ctrl_pdata, ctrl_pdata->ndx); |
| 1783 | |
| 1784 | WARN((ctrl_pdata->ctrl_state & CTRL_STATE_PANEL_INIT), |
| 1785 | "Incorrect Ctrl state=0x%x\n", ctrl_pdata->ctrl_state); |
| 1786 | |
| 1787 | mdss_dsi_ctrl_setup(ctrl_pdata); |
| 1788 | mdss_dsi_sw_reset(ctrl_pdata, true); |
| 1789 | pr_debug("%s-:End\n", __func__); |
| 1790 | return ret; |
| 1791 | } |
| 1792 | |
| 1793 | static void __mdss_dsi_mask_dfps_errors(struct mdss_dsi_ctrl_pdata *ctrl, |
| 1794 | bool mask) |
| 1795 | { |
| 1796 | u32 data = 0; |
| 1797 | |
| 1798 | /* |
| 1799 | * Assumption is that the DSI clocks will be enabled |
| 1800 | * when this API is called from dfps thread |
| 1801 | */ |
| 1802 | if (mask) { |
| 1803 | /* mask FIFO underflow and PLL unlock bits */ |
| 1804 | mdss_dsi_set_reg(ctrl, 0x10c, 0x7c000000, 0x7c000000); |
| 1805 | } else { |
| 1806 | data = MIPI_INP((ctrl->ctrl_base) + 0x0120); |
| 1807 | if (data & BIT(16)) { |
| 1808 | pr_debug("pll unlocked: 0x%x\n", data); |
| 1809 | /* clear PLL unlock bit */ |
| 1810 | MIPI_OUTP((ctrl->ctrl_base) + 0x120, BIT(16)); |
| 1811 | } |
| 1812 | |
| 1813 | data = MIPI_INP((ctrl->ctrl_base) + 0x00c); |
| 1814 | if (data & 0x88880000) { |
| 1815 | pr_debug("dsi fifo underflow: 0x%x\n", data); |
| 1816 | /* clear DSI FIFO underflow and empty */ |
| 1817 | MIPI_OUTP((ctrl->ctrl_base) + 0x00c, 0x99990000); |
| 1818 | } |
| 1819 | |
| 1820 | /* restore FIFO underflow and PLL unlock bits */ |
| 1821 | mdss_dsi_set_reg(ctrl, 0x10c, 0x7c000000, 0x0); |
| 1822 | } |
| 1823 | } |
| 1824 | |
| 1825 | static void __mdss_dsi_update_video_mode_total(struct mdss_panel_data *pdata, |
| 1826 | int new_fps) |
| 1827 | { |
| 1828 | u32 hsync_period, vsync_period; |
| 1829 | u32 new_dsi_v_total, current_dsi_v_total; |
| 1830 | struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL; |
| 1831 | |
| 1832 | if (pdata == NULL) { |
| 1833 | pr_err("%s Invalid pdata\n", __func__); |
| 1834 | return; |
| 1835 | } |
| 1836 | |
| 1837 | ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata, |
| 1838 | panel_data); |
| 1839 | if (ctrl_pdata == NULL) { |
| 1840 | pr_err("%s Invalid ctrl_pdata\n", __func__); |
| 1841 | return; |
| 1842 | } |
| 1843 | |
| 1844 | vsync_period = |
| 1845 | mdss_panel_get_vtotal(&pdata->panel_info); |
| 1846 | hsync_period = |
| 1847 | mdss_panel_get_htotal(&pdata->panel_info, true); |
| 1848 | current_dsi_v_total = |
| 1849 | MIPI_INP((ctrl_pdata->ctrl_base) + 0x2C); |
| 1850 | new_dsi_v_total = |
| 1851 | ((vsync_period - 1) << 16) | (hsync_period - 1); |
| 1852 | |
| 1853 | MIPI_OUTP((ctrl_pdata->ctrl_base) + 0x2C, |
| 1854 | (current_dsi_v_total | 0x8000000)); |
| 1855 | if (new_dsi_v_total & 0x8000000) { |
| 1856 | MIPI_OUTP((ctrl_pdata->ctrl_base) + 0x2C, |
| 1857 | new_dsi_v_total); |
| 1858 | } else { |
| 1859 | MIPI_OUTP((ctrl_pdata->ctrl_base) + 0x2C, |
| 1860 | (new_dsi_v_total | 0x8000000)); |
| 1861 | MIPI_OUTP((ctrl_pdata->ctrl_base) + 0x2C, |
| 1862 | (new_dsi_v_total & 0x7ffffff)); |
| 1863 | } |
| 1864 | |
| 1865 | if (ctrl_pdata->timing_db_mode) |
| 1866 | MIPI_OUTP((ctrl_pdata->ctrl_base) + 0x1e4, 0x1); |
| 1867 | |
| 1868 | pr_debug("%s new_fps:%d vsync:%d hsync:%d frame_rate:%d\n", |
| 1869 | __func__, new_fps, vsync_period, hsync_period, |
| 1870 | ctrl_pdata->panel_data.panel_info.mipi.frame_rate); |
| 1871 | |
| 1872 | ctrl_pdata->panel_data.panel_info.current_fps = new_fps; |
| 1873 | MDSS_XLOG(current_dsi_v_total, new_dsi_v_total, new_fps, |
| 1874 | ctrl_pdata->timing_db_mode); |
| 1875 | |
| 1876 | } |
| 1877 | |
| 1878 | static void __mdss_dsi_dyn_refresh_config( |
| 1879 | struct mdss_dsi_ctrl_pdata *ctrl_pdata) |
| 1880 | { |
| 1881 | int reg_data = 0; |
| 1882 | u32 phy_rev = ctrl_pdata->shared_data->phy_rev; |
| 1883 | |
| 1884 | /* configure only for master control in split display */ |
| 1885 | if (mdss_dsi_is_hw_config_split(ctrl_pdata->shared_data) && |
| 1886 | mdss_dsi_is_ctrl_clk_slave(ctrl_pdata)) |
| 1887 | return; |
| 1888 | |
| 1889 | switch (phy_rev) { |
| 1890 | case DSI_PHY_REV_10: |
| 1891 | reg_data = MIPI_INP((ctrl_pdata->ctrl_base) + |
| 1892 | DSI_DYNAMIC_REFRESH_CTRL); |
| 1893 | reg_data &= ~BIT(12); |
| 1894 | MIPI_OUTP((ctrl_pdata->ctrl_base) |
| 1895 | + DSI_DYNAMIC_REFRESH_CTRL, reg_data); |
| 1896 | break; |
| 1897 | case DSI_PHY_REV_20: |
| 1898 | reg_data = BIT(13); |
| 1899 | MIPI_OUTP((ctrl_pdata->ctrl_base) |
| 1900 | + DSI_DYNAMIC_REFRESH_CTRL, reg_data); |
| 1901 | break; |
| 1902 | default: |
| 1903 | pr_err("Phy rev %d unsupported\n", phy_rev); |
| 1904 | break; |
| 1905 | } |
| 1906 | |
| 1907 | pr_debug("Dynamic fps ctrl = 0x%x\n", reg_data); |
| 1908 | } |
| 1909 | |
| 1910 | static void __mdss_dsi_calc_dfps_delay(struct mdss_panel_data *pdata) |
| 1911 | { |
| 1912 | u32 esc_clk_rate = XO_CLK_RATE; |
| 1913 | u32 pipe_delay, pipe_delay2 = 0, pll_delay; |
| 1914 | u32 hsync_period = 0; |
| 1915 | u32 pclk_to_esc_ratio, byte_to_esc_ratio, hr_bit_to_esc_ratio; |
| 1916 | struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL; |
| 1917 | struct mdss_panel_info *pinfo = NULL; |
| 1918 | struct mdss_dsi_phy_ctrl *pd = NULL; |
| 1919 | |
| 1920 | if (pdata == NULL) { |
| 1921 | pr_err("%s Invalid pdata\n", __func__); |
| 1922 | return; |
| 1923 | } |
| 1924 | |
| 1925 | ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata, |
| 1926 | panel_data); |
| 1927 | if (ctrl_pdata == NULL) { |
| 1928 | pr_err("%s Invalid ctrl_pdata\n", __func__); |
| 1929 | return; |
| 1930 | } |
| 1931 | |
| 1932 | if (mdss_dsi_is_hw_config_split(ctrl_pdata->shared_data) && |
| 1933 | mdss_dsi_is_ctrl_clk_slave(ctrl_pdata)) |
| 1934 | return; |
| 1935 | |
| 1936 | pinfo = &pdata->panel_info; |
| 1937 | pd = &(pinfo->mipi.dsi_phy_db); |
| 1938 | |
| 1939 | pclk_to_esc_ratio = (ctrl_pdata->pclk_rate / esc_clk_rate); |
| 1940 | byte_to_esc_ratio = (ctrl_pdata->byte_clk_rate / esc_clk_rate); |
| 1941 | hr_bit_to_esc_ratio = ((ctrl_pdata->byte_clk_rate * 4) / esc_clk_rate); |
| 1942 | |
| 1943 | hsync_period = mdss_panel_get_htotal(pinfo, true); |
| 1944 | pipe_delay = (hsync_period + 1) / pclk_to_esc_ratio; |
| 1945 | if (pinfo->mipi.eof_bllp_power_stop == 0) |
| 1946 | pipe_delay += (17 / pclk_to_esc_ratio) + |
| 1947 | ((21 + (pinfo->mipi.t_clk_pre + 1) + |
| 1948 | (pinfo->mipi.t_clk_post + 1)) / |
| 1949 | byte_to_esc_ratio) + |
| 1950 | ((((pd->timing[8] >> 1) + 1) + |
| 1951 | ((pd->timing[6] >> 1) + 1) + |
| 1952 | ((pd->timing[3] * 4) + (pd->timing[5] >> 1) + 1) + |
| 1953 | ((pd->timing[7] >> 1) + 1) + |
| 1954 | ((pd->timing[1] >> 1) + 1) + |
| 1955 | ((pd->timing[4] >> 1) + 1)) / hr_bit_to_esc_ratio); |
| 1956 | |
| 1957 | if (pinfo->mipi.force_clk_lane_hs) |
| 1958 | pipe_delay2 = (6 / byte_to_esc_ratio) + |
| 1959 | ((((pd->timing[1] >> 1) + 1) + |
| 1960 | ((pd->timing[4] >> 1) + 1)) / hr_bit_to_esc_ratio); |
| 1961 | |
| 1962 | /* 130 us pll delay recommended by h/w doc */ |
| 1963 | pll_delay = ((130 * esc_clk_rate) / 1000000) * 2; |
| 1964 | |
| 1965 | MIPI_OUTP((ctrl_pdata->ctrl_base) + DSI_DYNAMIC_REFRESH_PIPE_DELAY, |
| 1966 | pipe_delay); |
| 1967 | MIPI_OUTP((ctrl_pdata->ctrl_base) + DSI_DYNAMIC_REFRESH_PIPE_DELAY2, |
| 1968 | pipe_delay2); |
| 1969 | MIPI_OUTP((ctrl_pdata->ctrl_base) + DSI_DYNAMIC_REFRESH_PLL_DELAY, |
| 1970 | pll_delay); |
| 1971 | } |
| 1972 | |
| 1973 | static int __mdss_dsi_dfps_calc_clks(struct mdss_panel_data *pdata, |
| 1974 | int new_fps) |
| 1975 | { |
| 1976 | int rc = 0; |
| 1977 | u64 clk_rate; |
| 1978 | struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL; |
| 1979 | struct mdss_panel_info *pinfo; |
| 1980 | u32 phy_rev; |
| 1981 | |
| 1982 | if (pdata == NULL) { |
| 1983 | pr_err("%s Invalid pdata\n", __func__); |
| 1984 | return -EINVAL; |
| 1985 | } |
| 1986 | |
| 1987 | ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata, |
| 1988 | panel_data); |
| 1989 | if (ctrl_pdata == NULL) { |
| 1990 | pr_err("%s Invalid ctrl_pdata\n", __func__); |
| 1991 | return -EINVAL; |
| 1992 | } |
| 1993 | |
| 1994 | pinfo = &pdata->panel_info; |
| 1995 | phy_rev = ctrl_pdata->shared_data->phy_rev; |
| 1996 | |
| 1997 | rc = mdss_dsi_clk_div_config |
| 1998 | (&ctrl_pdata->panel_data.panel_info, new_fps); |
| 1999 | if (rc) { |
| 2000 | pr_err("%s: unable to initialize the clk dividers\n", |
| 2001 | __func__); |
| 2002 | return rc; |
| 2003 | } |
| 2004 | |
| 2005 | __mdss_dsi_dyn_refresh_config(ctrl_pdata); |
| 2006 | |
| 2007 | if (phy_rev == DSI_PHY_REV_20) |
| 2008 | mdss_dsi_dfps_config_8996(ctrl_pdata); |
| 2009 | |
| 2010 | __mdss_dsi_calc_dfps_delay(pdata); |
| 2011 | |
| 2012 | /* take a backup of current clk rates */ |
| 2013 | ctrl_pdata->pclk_rate_bkp = ctrl_pdata->pclk_rate; |
| 2014 | ctrl_pdata->byte_clk_rate_bkp = ctrl_pdata->byte_clk_rate; |
| 2015 | |
| 2016 | ctrl_pdata->pclk_rate = pinfo->mipi.dsi_pclk_rate; |
| 2017 | clk_rate = pinfo->clk_rate; |
| 2018 | do_div(clk_rate, 8U); |
| 2019 | ctrl_pdata->byte_clk_rate = (u32) clk_rate; |
| 2020 | |
| 2021 | pr_debug("byte_rate=%i\n", ctrl_pdata->byte_clk_rate); |
| 2022 | pr_debug("pclk_rate=%i\n", ctrl_pdata->pclk_rate); |
| 2023 | |
| 2024 | return rc; |
| 2025 | } |
| 2026 | |
| 2027 | static int __mdss_dsi_dfps_update_clks(struct mdss_panel_data *pdata, |
| 2028 | int new_fps) |
| 2029 | { |
| 2030 | struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL; |
| 2031 | struct mdss_dsi_ctrl_pdata *sctrl_pdata = NULL; |
Sachin Bhayare | 3d3767e | 2018-01-02 21:10:57 +0530 | [diff] [blame] | 2032 | struct mdss_panel_info *pinfo, *spinfo = NULL; |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 2033 | int rc = 0; |
| 2034 | |
| 2035 | if (pdata == NULL) { |
| 2036 | pr_err("%s Invalid pdata\n", __func__); |
| 2037 | return -EINVAL; |
| 2038 | } |
| 2039 | |
| 2040 | ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata, |
| 2041 | panel_data); |
| 2042 | if (IS_ERR_OR_NULL(ctrl_pdata)) { |
| 2043 | pr_err("Invalid sctrl_pdata = %lu\n", PTR_ERR(ctrl_pdata)); |
| 2044 | return PTR_ERR(ctrl_pdata); |
| 2045 | } |
| 2046 | |
| 2047 | pinfo = &ctrl_pdata->panel_data.panel_info; |
| 2048 | |
| 2049 | /* |
| 2050 | * In split display case, configure and enable dynamic refresh |
| 2051 | * register only after both the ctrl data is programmed. So, |
| 2052 | * ignore enabling dynamic refresh for the master control and |
| 2053 | * configure only when it is slave control. |
| 2054 | */ |
| 2055 | if (mdss_dsi_is_hw_config_split(ctrl_pdata->shared_data) && |
| 2056 | mdss_dsi_is_ctrl_clk_master(ctrl_pdata)) |
| 2057 | return 0; |
| 2058 | |
| 2059 | if (mdss_dsi_is_hw_config_split(ctrl_pdata->shared_data) && |
| 2060 | mdss_dsi_is_ctrl_clk_slave(ctrl_pdata)) { |
| 2061 | sctrl_pdata = ctrl_pdata; |
| 2062 | spinfo = pinfo; |
| 2063 | ctrl_pdata = mdss_dsi_get_ctrl_clk_master(); |
| 2064 | if (IS_ERR_OR_NULL(ctrl_pdata)) { |
| 2065 | pr_err("Invalid ctrl_pdata = %lu\n", |
| 2066 | PTR_ERR(ctrl_pdata)); |
| 2067 | return PTR_ERR(ctrl_pdata); |
| 2068 | } |
| 2069 | |
| 2070 | pinfo = &ctrl_pdata->panel_data.panel_info; |
| 2071 | } |
| 2072 | |
| 2073 | /* |
| 2074 | * For programming dynamic refresh registers, we need to change |
| 2075 | * the parent to shadow clocks for the software byte and pixel mux. |
| 2076 | * After switching to shadow clocks, if there is no ref count on |
| 2077 | * main byte and pixel clocks, clock driver may shutdown those |
| 2078 | * unreferenced byte and pixel clocks. Hence add an extra reference |
| 2079 | * count to avoid shutting down the main byte and pixel clocks. |
| 2080 | */ |
| 2081 | rc = clk_prepare_enable(ctrl_pdata->pll_byte_clk); |
| 2082 | if (rc) { |
| 2083 | pr_err("Unable to add extra refcnt for byte clock\n"); |
| 2084 | goto error_byte; |
| 2085 | } |
| 2086 | |
| 2087 | rc = clk_prepare_enable(ctrl_pdata->pll_pixel_clk); |
| 2088 | if (rc) { |
| 2089 | pr_err("Unable to add extra refcnt for pixel clock\n"); |
| 2090 | goto error_pixel; |
| 2091 | } |
| 2092 | |
| 2093 | /* change the parent to shadow clocks*/ |
| 2094 | rc = clk_set_parent(ctrl_pdata->mux_byte_clk, |
| 2095 | ctrl_pdata->shadow_byte_clk); |
| 2096 | if (rc) { |
| 2097 | pr_err("Unable to set parent to shadow byte clock\n"); |
| 2098 | goto error_shadow_byte; |
| 2099 | } |
| 2100 | |
| 2101 | rc = clk_set_parent(ctrl_pdata->mux_pixel_clk, |
| 2102 | ctrl_pdata->shadow_pixel_clk); |
| 2103 | if (rc) { |
| 2104 | pr_err("Unable to set parent to shadow pixel clock\n"); |
| 2105 | goto error_shadow_pixel; |
| 2106 | } |
| 2107 | |
| 2108 | rc = mdss_dsi_clk_set_link_rate(ctrl_pdata->dsi_clk_handle, |
| 2109 | MDSS_DSI_LINK_BYTE_CLK, ctrl_pdata->byte_clk_rate, 0); |
| 2110 | if (rc) { |
| 2111 | pr_err("%s: dsi_byte_clk - clk_set_rate failed\n", |
| 2112 | __func__); |
| 2113 | goto error_byte_link; |
| 2114 | } |
| 2115 | |
| 2116 | rc = mdss_dsi_clk_set_link_rate(ctrl_pdata->dsi_clk_handle, |
| 2117 | MDSS_DSI_LINK_PIX_CLK, ctrl_pdata->pclk_rate, 0); |
| 2118 | if (rc) { |
| 2119 | pr_err("%s: dsi_pixel_clk - clk_set_rate failed\n", |
| 2120 | __func__); |
| 2121 | goto error_pixel_link; |
| 2122 | } |
| 2123 | |
| 2124 | if (sctrl_pdata) { |
| 2125 | rc = mdss_dsi_clk_set_link_rate(sctrl_pdata->dsi_clk_handle, |
| 2126 | MDSS_DSI_LINK_BYTE_CLK, sctrl_pdata->byte_clk_rate, 0); |
| 2127 | if (rc) { |
| 2128 | pr_err("%s: slv dsi_byte_clk - clk_set_rate failed\n", |
| 2129 | __func__); |
| 2130 | goto error_sbyte_link; |
| 2131 | } |
| 2132 | |
| 2133 | rc = mdss_dsi_clk_set_link_rate(sctrl_pdata->dsi_clk_handle, |
| 2134 | MDSS_DSI_LINK_PIX_CLK, sctrl_pdata->pclk_rate, 0); |
| 2135 | if (rc) { |
| 2136 | pr_err("%s: slv dsi_pixel_clk - clk_set_rate failed\n", |
| 2137 | __func__); |
| 2138 | goto error_spixel_link; |
| 2139 | } |
| 2140 | } |
| 2141 | |
| 2142 | rc = mdss_dsi_en_wait4dynamic_done(ctrl_pdata); |
| 2143 | if (rc < 0) { |
| 2144 | pr_err("Unsuccessful dynamic fps change"); |
| 2145 | goto dfps_timeout; |
| 2146 | } |
| 2147 | |
| 2148 | MIPI_OUTP((ctrl_pdata->ctrl_base) + DSI_DYNAMIC_REFRESH_CTRL, 0x00); |
| 2149 | if (sctrl_pdata) |
| 2150 | MIPI_OUTP((sctrl_pdata->ctrl_base) + DSI_DYNAMIC_REFRESH_CTRL, |
| 2151 | 0x00); |
| 2152 | |
| 2153 | rc = mdss_dsi_phy_pll_reset_status(ctrl_pdata); |
| 2154 | if (rc) { |
| 2155 | pr_err("%s: pll cannot be locked reset core ready failed %d\n", |
| 2156 | __func__, rc); |
| 2157 | goto dfps_timeout; |
| 2158 | } |
| 2159 | |
| 2160 | __mdss_dsi_mask_dfps_errors(ctrl_pdata, false); |
| 2161 | if (sctrl_pdata) |
| 2162 | __mdss_dsi_mask_dfps_errors(sctrl_pdata, false); |
| 2163 | |
| 2164 | /* Move the mux clocks to main byte and pixel clocks */ |
| 2165 | rc = clk_set_parent(ctrl_pdata->mux_byte_clk, |
| 2166 | ctrl_pdata->pll_byte_clk); |
| 2167 | if (rc) |
| 2168 | pr_err("Unable to set parent back to main byte clock\n"); |
| 2169 | |
| 2170 | rc = clk_set_parent(ctrl_pdata->mux_pixel_clk, |
| 2171 | ctrl_pdata->pll_pixel_clk); |
| 2172 | if (rc) |
| 2173 | pr_err("Unable to set parent back to main pixel clock\n"); |
| 2174 | |
| 2175 | /* Remove extra ref count on parent clocks */ |
| 2176 | clk_disable_unprepare(ctrl_pdata->pll_byte_clk); |
| 2177 | clk_disable_unprepare(ctrl_pdata->pll_pixel_clk); |
| 2178 | |
| 2179 | /* update new fps that at this point is already updated in hw */ |
| 2180 | pinfo->current_fps = new_fps; |
| 2181 | if (sctrl_pdata) |
| 2182 | spinfo->current_fps = new_fps; |
| 2183 | |
| 2184 | return rc; |
| 2185 | |
| 2186 | dfps_timeout: |
| 2187 | if (sctrl_pdata) |
| 2188 | mdss_dsi_clk_set_link_rate(sctrl_pdata->dsi_clk_handle, |
| 2189 | MDSS_DSI_LINK_PIX_CLK, |
| 2190 | sctrl_pdata->pclk_rate_bkp, 0); |
| 2191 | error_spixel_link: |
| 2192 | if (sctrl_pdata) |
| 2193 | mdss_dsi_clk_set_link_rate(sctrl_pdata->dsi_clk_handle, |
| 2194 | MDSS_DSI_LINK_BYTE_CLK, |
| 2195 | sctrl_pdata->byte_clk_rate_bkp, 0); |
| 2196 | error_sbyte_link: |
| 2197 | mdss_dsi_clk_set_link_rate(ctrl_pdata->dsi_clk_handle, |
| 2198 | MDSS_DSI_LINK_PIX_CLK, ctrl_pdata->pclk_rate_bkp, 0); |
| 2199 | error_pixel_link: |
| 2200 | mdss_dsi_clk_set_link_rate(ctrl_pdata->dsi_clk_handle, |
| 2201 | MDSS_DSI_LINK_BYTE_CLK, ctrl_pdata->byte_clk_rate_bkp, 0); |
| 2202 | error_byte_link: |
| 2203 | clk_set_parent(ctrl_pdata->mux_pixel_clk, ctrl_pdata->pll_pixel_clk); |
| 2204 | error_shadow_pixel: |
| 2205 | clk_set_parent(ctrl_pdata->mux_byte_clk, ctrl_pdata->pll_byte_clk); |
| 2206 | error_shadow_byte: |
| 2207 | clk_disable_unprepare(ctrl_pdata->pll_pixel_clk); |
| 2208 | error_pixel: |
| 2209 | clk_disable_unprepare(ctrl_pdata->pll_byte_clk); |
| 2210 | error_byte: |
| 2211 | return rc; |
| 2212 | } |
| 2213 | |
| 2214 | static int mdss_dsi_check_params(struct mdss_dsi_ctrl_pdata *ctrl, void *arg) |
| 2215 | { |
| 2216 | struct mdss_panel_info *var_pinfo, *pinfo; |
| 2217 | int rc = 0; |
| 2218 | |
| 2219 | if (!ctrl || !arg) |
| 2220 | return 0; |
| 2221 | |
| 2222 | pinfo = &ctrl->panel_data.panel_info; |
| 2223 | if (!pinfo->is_pluggable) |
| 2224 | return 0; |
| 2225 | |
| 2226 | var_pinfo = (struct mdss_panel_info *)arg; |
| 2227 | |
| 2228 | pr_debug("%s: reconfig xres: %d yres: %d, current xres: %d yres: %d\n", |
| 2229 | __func__, var_pinfo->xres, var_pinfo->yres, |
| 2230 | pinfo->xres, pinfo->yres); |
| 2231 | if ((var_pinfo->xres != pinfo->xres) || |
| 2232 | (var_pinfo->yres != pinfo->yres) || |
| 2233 | (var_pinfo->lcdc.h_back_porch != pinfo->lcdc.h_back_porch) || |
| 2234 | (var_pinfo->lcdc.h_front_porch != pinfo->lcdc.h_front_porch) || |
| 2235 | (var_pinfo->lcdc.h_pulse_width != pinfo->lcdc.h_pulse_width) || |
| 2236 | (var_pinfo->lcdc.v_back_porch != pinfo->lcdc.v_back_porch) || |
| 2237 | (var_pinfo->lcdc.v_front_porch != pinfo->lcdc.v_front_porch) || |
| 2238 | (var_pinfo->lcdc.v_pulse_width != pinfo->lcdc.v_pulse_width) |
| 2239 | ) |
| 2240 | rc = 1; |
| 2241 | |
| 2242 | return rc; |
| 2243 | } |
| 2244 | |
| 2245 | #ifdef TARGET_HW_MDSS_HDMI |
| 2246 | static void mdss_dsi_update_params(struct mdss_dsi_ctrl_pdata *ctrl, void *arg) |
| 2247 | { |
| 2248 | struct mdss_panel_info *pinfo; |
| 2249 | |
| 2250 | if (!ctrl || !arg) |
| 2251 | return; |
| 2252 | |
| 2253 | pinfo = &ctrl->panel_data.panel_info; |
| 2254 | mdss_dba_update_lane_cfg(pinfo); |
| 2255 | } |
| 2256 | #else |
| 2257 | static void mdss_dsi_update_params(struct mdss_dsi_ctrl_pdata *ctrl, void *arg) |
| 2258 | { |
| 2259 | } |
| 2260 | #endif |
| 2261 | |
| 2262 | static int mdss_dsi_dfps_config(struct mdss_panel_data *pdata, int new_fps) |
| 2263 | { |
| 2264 | int rc = 0; |
| 2265 | struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL; |
| 2266 | struct mdss_panel_info *pinfo; |
| 2267 | u32 phy_rev; |
| 2268 | u32 frame_rate_bkp; |
| 2269 | |
| 2270 | pr_debug("%s+:\n", __func__); |
| 2271 | |
| 2272 | if (pdata == NULL) { |
| 2273 | pr_err("%s: Invalid input data\n", __func__); |
| 2274 | return -EINVAL; |
| 2275 | } |
| 2276 | |
| 2277 | ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata, |
| 2278 | panel_data); |
| 2279 | |
| 2280 | if (!ctrl_pdata->panel_data.panel_info.dynamic_fps) { |
| 2281 | pr_err("Dynamic fps not enabled for this panel\n"); |
| 2282 | return -EINVAL; |
| 2283 | } |
| 2284 | |
| 2285 | phy_rev = ctrl_pdata->shared_data->phy_rev; |
| 2286 | pinfo = &pdata->panel_info; |
| 2287 | |
| 2288 | /* get the fps configured in HW */ |
| 2289 | frame_rate_bkp = pinfo->current_fps; |
| 2290 | |
| 2291 | if (new_fps == pinfo->current_fps) { |
| 2292 | /* |
| 2293 | * This is unlikely as mdss driver checks for previously |
| 2294 | * configured frame rate. |
| 2295 | */ |
| 2296 | pr_debug("Panel is already at this FPS\n"); |
| 2297 | goto end_update; |
| 2298 | } |
| 2299 | |
| 2300 | if (pinfo->dfps_update == DFPS_IMMEDIATE_PORCH_UPDATE_MODE_HFP || |
| 2301 | pinfo->dfps_update == DFPS_IMMEDIATE_PORCH_UPDATE_MODE_VFP) { |
| 2302 | /* Porch method */ |
| 2303 | __mdss_dsi_update_video_mode_total(pdata, new_fps); |
| 2304 | } else if (pinfo->dfps_update == DFPS_IMMEDIATE_CLK_UPDATE_MODE) { |
| 2305 | /* Clock update method */ |
| 2306 | |
| 2307 | __mdss_dsi_mask_dfps_errors(ctrl_pdata, true); |
| 2308 | |
| 2309 | if (phy_rev == DSI_PHY_REV_20) { |
| 2310 | rc = mdss_dsi_phy_calc_timing_param(pinfo, phy_rev, |
| 2311 | new_fps); |
| 2312 | if (rc) { |
| 2313 | pr_err("PHY calculations failed-%d\n", new_fps); |
| 2314 | goto end_update; |
| 2315 | } |
| 2316 | } |
| 2317 | |
| 2318 | rc = __mdss_dsi_dfps_calc_clks(pdata, new_fps); |
| 2319 | if (rc) { |
| 2320 | pr_err("error calculating clocks for %d\n", new_fps); |
| 2321 | goto error_clks; |
| 2322 | } |
| 2323 | |
| 2324 | rc = __mdss_dsi_dfps_update_clks(pdata, new_fps); |
| 2325 | if (rc) { |
| 2326 | pr_err("Dynamic refresh failed-%d\n", new_fps); |
| 2327 | goto error_dfps; |
| 2328 | } |
| 2329 | } |
| 2330 | |
| 2331 | return rc; |
| 2332 | error_dfps: |
| 2333 | if (__mdss_dsi_dfps_calc_clks(pdata, frame_rate_bkp)) |
| 2334 | pr_err("error reverting clock calculations for %d\n", |
| 2335 | frame_rate_bkp); |
| 2336 | error_clks: |
| 2337 | if (mdss_dsi_phy_calc_timing_param(pinfo, phy_rev, frame_rate_bkp)) |
| 2338 | pr_err("Unable to revert phy timing-%d\n", frame_rate_bkp); |
| 2339 | end_update: |
| 2340 | return rc; |
| 2341 | } |
| 2342 | |
| 2343 | static int mdss_dsi_ctl_partial_roi(struct mdss_panel_data *pdata) |
| 2344 | { |
| 2345 | struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL; |
| 2346 | int rc = -EINVAL; |
| 2347 | |
| 2348 | if (pdata == NULL) { |
| 2349 | pr_err("%s: Invalid input data\n", __func__); |
| 2350 | return -EINVAL; |
| 2351 | } |
| 2352 | |
| 2353 | if (!pdata->panel_info.partial_update_enabled) |
| 2354 | return 0; |
| 2355 | |
| 2356 | ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata, |
| 2357 | panel_data); |
| 2358 | |
| 2359 | if (ctrl_pdata->set_col_page_addr) |
| 2360 | rc = ctrl_pdata->set_col_page_addr(pdata, false); |
| 2361 | |
| 2362 | return rc; |
| 2363 | } |
| 2364 | |
| 2365 | static int mdss_dsi_set_stream_size(struct mdss_panel_data *pdata) |
| 2366 | { |
| 2367 | u32 stream_ctrl, stream_total, idle; |
| 2368 | struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL; |
| 2369 | struct mdss_panel_info *pinfo; |
| 2370 | struct dsc_desc *dsc = NULL; |
| 2371 | struct mdss_rect *roi; |
| 2372 | struct panel_horizontal_idle *pidle; |
| 2373 | int i; |
| 2374 | |
| 2375 | if (pdata == NULL) { |
| 2376 | pr_err("%s: Invalid input data\n", __func__); |
| 2377 | return -EINVAL; |
| 2378 | } |
| 2379 | |
| 2380 | ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata, |
| 2381 | panel_data); |
| 2382 | |
| 2383 | pinfo = &pdata->panel_info; |
| 2384 | |
| 2385 | if (!pinfo->partial_update_supported) |
| 2386 | return -EINVAL; |
| 2387 | |
| 2388 | if (pinfo->compression_mode == COMPRESSION_DSC) |
| 2389 | dsc = &pinfo->dsc; |
| 2390 | |
| 2391 | roi = &pinfo->roi; |
| 2392 | |
| 2393 | /* DSI_COMMAND_MODE_MDP_STREAM_CTRL */ |
| 2394 | if (dsc) { |
| 2395 | u16 byte_num = dsc->bytes_per_pkt; |
| 2396 | |
| 2397 | if (pinfo->mipi.insert_dcs_cmd) |
| 2398 | byte_num++; |
| 2399 | |
| 2400 | stream_ctrl = (byte_num << 16) | (pinfo->mipi.vc << 8) | |
| 2401 | DTYPE_DCS_LWRITE; |
| 2402 | stream_total = dsc->pic_height << 16 | dsc->pclk_per_line; |
| 2403 | } else { |
| 2404 | |
| 2405 | stream_ctrl = (((roi->w * 3) + 1) << 16) | |
| 2406 | (pdata->panel_info.mipi.vc << 8) | DTYPE_DCS_LWRITE; |
| 2407 | stream_total = roi->h << 16 | roi->w; |
| 2408 | } |
| 2409 | MIPI_OUTP((ctrl_pdata->ctrl_base) + 0x60, stream_ctrl); |
| 2410 | MIPI_OUTP((ctrl_pdata->ctrl_base) + 0x58, stream_ctrl); |
| 2411 | |
| 2412 | /* DSI_COMMAND_MODE_MDP_STREAM_TOTAL */ |
| 2413 | MIPI_OUTP((ctrl_pdata->ctrl_base) + 0x64, stream_total); |
| 2414 | MIPI_OUTP((ctrl_pdata->ctrl_base) + 0x5C, stream_total); |
| 2415 | |
| 2416 | /* set idle control -- dsi clk cycle */ |
| 2417 | idle = 0; |
| 2418 | pidle = ctrl_pdata->line_idle; |
| 2419 | for (i = 0; i < ctrl_pdata->horizontal_idle_cnt; i++) { |
| 2420 | if (roi->w > pidle->min && roi->w <= pidle->max) { |
| 2421 | idle = pidle->idle; |
| 2422 | pr_debug("%s: ndx=%d w=%d range=%d-%d idle=%d\n", |
| 2423 | __func__, ctrl_pdata->ndx, roi->w, |
| 2424 | pidle->min, pidle->max, pidle->idle); |
| 2425 | break; |
| 2426 | } |
| 2427 | pidle++; |
| 2428 | } |
| 2429 | |
| 2430 | if (idle) |
| 2431 | idle |= BIT(12); /* enable */ |
| 2432 | |
| 2433 | MIPI_OUTP((ctrl_pdata->ctrl_base) + 0x194, idle); |
| 2434 | |
| 2435 | if (dsc) |
| 2436 | mdss_dsi_dsc_config(ctrl_pdata, dsc); |
| 2437 | |
| 2438 | return 0; |
| 2439 | } |
| 2440 | |
| 2441 | #ifdef TARGET_HW_MDSS_HDMI |
| 2442 | static void mdss_dsi_dba_work(struct work_struct *work) |
| 2443 | { |
| 2444 | struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL; |
| 2445 | struct delayed_work *dw = to_delayed_work(work); |
| 2446 | struct mdss_dba_utils_init_data utils_init_data; |
| 2447 | struct mdss_panel_info *pinfo; |
| 2448 | |
| 2449 | ctrl_pdata = container_of(dw, struct mdss_dsi_ctrl_pdata, dba_work); |
| 2450 | if (!ctrl_pdata) { |
| 2451 | pr_err("%s: invalid ctrl data\n", __func__); |
| 2452 | return; |
| 2453 | } |
| 2454 | |
| 2455 | pinfo = &ctrl_pdata->panel_data.panel_info; |
| 2456 | if (!pinfo) { |
| 2457 | pr_err("%s: invalid ctrl data\n", __func__); |
| 2458 | return; |
| 2459 | } |
| 2460 | |
| 2461 | memset(&utils_init_data, 0, sizeof(utils_init_data)); |
| 2462 | |
| 2463 | utils_init_data.chip_name = ctrl_pdata->bridge_name; |
| 2464 | utils_init_data.client_name = "dsi"; |
| 2465 | utils_init_data.instance_id = ctrl_pdata->bridge_index; |
| 2466 | utils_init_data.fb_node = ctrl_pdata->fb_node; |
| 2467 | utils_init_data.kobj = ctrl_pdata->kobj; |
| 2468 | utils_init_data.pinfo = pinfo; |
| 2469 | if (ctrl_pdata->mdss_util) |
| 2470 | utils_init_data.cont_splash_enabled = |
| 2471 | ctrl_pdata->mdss_util->panel_intf_status( |
| 2472 | ctrl_pdata->panel_data.panel_info.pdest, |
| 2473 | MDSS_PANEL_INTF_DSI) ? true : false; |
| 2474 | else |
| 2475 | utils_init_data.cont_splash_enabled = false; |
| 2476 | |
| 2477 | pinfo->dba_data = mdss_dba_utils_init(&utils_init_data); |
| 2478 | |
| 2479 | if (!IS_ERR_OR_NULL(pinfo->dba_data)) { |
| 2480 | ctrl_pdata->ds_registered = true; |
| 2481 | } else { |
| 2482 | pr_debug("%s: dba device not ready, queue again\n", __func__); |
| 2483 | queue_delayed_work(ctrl_pdata->workq, |
| 2484 | &ctrl_pdata->dba_work, HZ); |
| 2485 | } |
| 2486 | } |
| 2487 | #else |
| 2488 | static void mdss_dsi_dba_work(struct work_struct *work) |
| 2489 | { |
| 2490 | (void)(*work); |
| 2491 | } |
| 2492 | #endif |
| 2493 | static int mdss_dsi_reset_write_ptr(struct mdss_panel_data *pdata) |
| 2494 | { |
| 2495 | |
| 2496 | struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL; |
| 2497 | struct mdss_panel_info *pinfo; |
| 2498 | int rc = 0; |
| 2499 | |
| 2500 | if (pdata == NULL) { |
| 2501 | pr_err("%s: Invalid input data\n", __func__); |
| 2502 | return -EINVAL; |
| 2503 | } |
| 2504 | |
| 2505 | ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata, |
| 2506 | panel_data); |
| 2507 | |
| 2508 | pinfo = &ctrl_pdata->panel_data.panel_info; |
| 2509 | mdss_dsi_clk_ctrl(ctrl_pdata, ctrl_pdata->dsi_clk_handle, |
| 2510 | MDSS_DSI_ALL_CLKS, MDSS_DSI_CLK_ON); |
| 2511 | /* Need to reset the DSI core since the pixel stream was stopped. */ |
| 2512 | mdss_dsi_sw_reset(ctrl_pdata, true); |
| 2513 | |
| 2514 | /* |
| 2515 | * Reset the partial update co-ordinates to the panel height and |
| 2516 | * width |
| 2517 | */ |
| 2518 | if (pinfo->dcs_cmd_by_left && (ctrl_pdata->ndx == 1)) |
| 2519 | goto skip_cmd_send; |
| 2520 | |
| 2521 | pinfo->roi.x = 0; |
| 2522 | pinfo->roi.y = 0; |
| 2523 | pinfo->roi.w = pinfo->xres; |
| 2524 | if (pinfo->dcs_cmd_by_left) |
| 2525 | pinfo->roi.w = pinfo->xres; |
| 2526 | if (pdata->next) |
| 2527 | pinfo->roi.w += pdata->next->panel_info.xres; |
| 2528 | pinfo->roi.h = pinfo->yres; |
| 2529 | |
| 2530 | mdss_dsi_set_stream_size(pdata); |
| 2531 | |
| 2532 | if (ctrl_pdata->set_col_page_addr) |
| 2533 | rc = ctrl_pdata->set_col_page_addr(pdata, true); |
| 2534 | |
| 2535 | skip_cmd_send: |
| 2536 | mdss_dsi_clk_ctrl(ctrl_pdata, ctrl_pdata->dsi_clk_handle, |
| 2537 | MDSS_DSI_ALL_CLKS, MDSS_DSI_CLK_OFF); |
| 2538 | |
| 2539 | pr_debug("%s: DSI%d write ptr reset finished\n", __func__, |
| 2540 | ctrl_pdata->ndx); |
| 2541 | |
| 2542 | return rc; |
| 2543 | } |
| 2544 | |
| 2545 | int mdss_dsi_register_recovery_handler(struct mdss_dsi_ctrl_pdata *ctrl, |
| 2546 | struct mdss_intf_recovery *recovery) |
| 2547 | { |
| 2548 | mutex_lock(&ctrl->mutex); |
| 2549 | ctrl->recovery = recovery; |
| 2550 | mutex_unlock(&ctrl->mutex); |
| 2551 | return 0; |
| 2552 | } |
| 2553 | |
| 2554 | static int mdss_dsi_register_mdp_callback(struct mdss_dsi_ctrl_pdata *ctrl, |
| 2555 | struct mdss_intf_recovery *mdp_callback) |
| 2556 | { |
| 2557 | mutex_lock(&ctrl->mutex); |
| 2558 | ctrl->mdp_callback = mdp_callback; |
| 2559 | mutex_unlock(&ctrl->mutex); |
| 2560 | return 0; |
| 2561 | } |
| 2562 | |
| 2563 | static struct device_node *mdss_dsi_get_fb_node_cb(struct platform_device *pdev) |
| 2564 | { |
| 2565 | struct device_node *fb_node; |
| 2566 | struct platform_device *dsi_dev; |
| 2567 | struct mdss_dsi_ctrl_pdata *ctrl_pdata; |
| 2568 | |
| 2569 | if (pdev == NULL) { |
| 2570 | pr_err("%s: Invalid input data\n", __func__); |
| 2571 | return NULL; |
| 2572 | } |
| 2573 | |
| 2574 | ctrl_pdata = platform_get_drvdata(pdev); |
| 2575 | dsi_dev = of_find_device_by_node(pdev->dev.of_node->parent); |
| 2576 | if (!dsi_dev) { |
| 2577 | pr_err("Unable to find dsi master device: %s\n", |
| 2578 | pdev->dev.of_node->full_name); |
| 2579 | return NULL; |
| 2580 | } |
| 2581 | |
| 2582 | fb_node = of_parse_phandle(dsi_dev->dev.of_node, |
| 2583 | mdss_dsi_get_fb_name(ctrl_pdata), 0); |
| 2584 | if (!fb_node) { |
| 2585 | pr_err("Unable to find fb node for device: %s\n", pdev->name); |
| 2586 | return NULL; |
| 2587 | } |
| 2588 | |
| 2589 | return fb_node; |
| 2590 | } |
| 2591 | |
| 2592 | static int mdss_dsi_event_handler(struct mdss_panel_data *pdata, |
| 2593 | int event, void *arg) |
| 2594 | { |
| 2595 | int rc = 0; |
| 2596 | struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL; |
| 2597 | struct fb_info *fbi; |
| 2598 | int power_state; |
| 2599 | u32 mode; |
| 2600 | struct mdss_panel_info *pinfo; |
| 2601 | |
| 2602 | if (pdata == NULL) { |
| 2603 | pr_err("%s: Invalid input data\n", __func__); |
| 2604 | return -EINVAL; |
| 2605 | } |
| 2606 | pinfo = &pdata->panel_info; |
| 2607 | ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata, |
| 2608 | panel_data); |
| 2609 | pr_debug("%s+: ctrl=%d event=%d\n", __func__, ctrl_pdata->ndx, event); |
| 2610 | |
| 2611 | MDSS_XLOG(event, arg, ctrl_pdata->ndx, 0x3333); |
| 2612 | |
| 2613 | switch (event) { |
| 2614 | case MDSS_EVENT_UPDATE_PARAMS: |
| 2615 | pr_debug("%s:Entered Case MDSS_EVENT_UPDATE_PARAMS\n", |
| 2616 | __func__); |
| 2617 | mdss_dsi_update_params(ctrl_pdata, arg); |
| 2618 | break; |
| 2619 | case MDSS_EVENT_CHECK_PARAMS: |
| 2620 | pr_debug("%s:Entered Case MDSS_EVENT_CHECK_PARAMS\n", __func__); |
| 2621 | if (mdss_dsi_check_params(ctrl_pdata, arg)) { |
| 2622 | ctrl_pdata->update_phy_timing = true; |
| 2623 | /* |
| 2624 | * Call to MDSS_EVENT_CHECK_PARAMS expects |
| 2625 | * the return value of 1, if there is a change |
| 2626 | * in panel timing parameters. |
| 2627 | */ |
| 2628 | rc = 1; |
| 2629 | } |
| 2630 | ctrl_pdata->refresh_clk_rate = true; |
| 2631 | break; |
| 2632 | case MDSS_EVENT_LINK_READY: |
| 2633 | if (ctrl_pdata->refresh_clk_rate) |
| 2634 | rc = mdss_dsi_clk_refresh(pdata, |
| 2635 | ctrl_pdata->update_phy_timing); |
| 2636 | |
| 2637 | rc = mdss_dsi_on(pdata); |
| 2638 | mdss_dsi_op_mode_config(pdata->panel_info.mipi.mode, |
| 2639 | pdata); |
| 2640 | break; |
| 2641 | case MDSS_EVENT_UNBLANK: |
| 2642 | if (ctrl_pdata->on_cmds.link_state == DSI_LP_MODE) |
| 2643 | rc = mdss_dsi_unblank(pdata); |
| 2644 | break; |
| 2645 | case MDSS_EVENT_POST_PANEL_ON: |
| 2646 | rc = mdss_dsi_post_panel_on(pdata); |
| 2647 | break; |
| 2648 | case MDSS_EVENT_PANEL_ON: |
| 2649 | ctrl_pdata->ctrl_state |= CTRL_STATE_MDP_ACTIVE; |
| 2650 | if (ctrl_pdata->on_cmds.link_state == DSI_HS_MODE) |
| 2651 | rc = mdss_dsi_unblank(pdata); |
| 2652 | pdata->panel_info.esd_rdy = true; |
| 2653 | break; |
| 2654 | case MDSS_EVENT_BLANK: |
| 2655 | power_state = (int) (unsigned long) arg; |
| 2656 | if (ctrl_pdata->off_cmds.link_state == DSI_HS_MODE) |
| 2657 | rc = mdss_dsi_blank(pdata, power_state); |
| 2658 | break; |
| 2659 | case MDSS_EVENT_PANEL_OFF: |
| 2660 | power_state = (int) (unsigned long) arg; |
| 2661 | disable_esd_thread(); |
| 2662 | ctrl_pdata->ctrl_state &= ~CTRL_STATE_MDP_ACTIVE; |
| 2663 | if (ctrl_pdata->off_cmds.link_state == DSI_LP_MODE) |
| 2664 | rc = mdss_dsi_blank(pdata, power_state); |
| 2665 | rc = mdss_dsi_off(pdata, power_state); |
| 2666 | break; |
| 2667 | case MDSS_EVENT_CONT_SPLASH_FINISH: |
| 2668 | if (ctrl_pdata->off_cmds.link_state == DSI_LP_MODE) |
| 2669 | rc = mdss_dsi_blank(pdata, MDSS_PANEL_POWER_OFF); |
| 2670 | ctrl_pdata->ctrl_state &= ~CTRL_STATE_MDP_ACTIVE; |
| 2671 | rc = mdss_dsi_cont_splash_on(pdata); |
| 2672 | break; |
| 2673 | case MDSS_EVENT_PANEL_CLK_CTRL: |
| 2674 | mdss_dsi_clk_req(ctrl_pdata, |
| 2675 | (struct dsi_panel_clk_ctrl *) arg); |
| 2676 | break; |
| 2677 | case MDSS_EVENT_DSI_CMDLIST_KOFF: |
| 2678 | mdss_dsi_cmdlist_commit(ctrl_pdata, 1); |
| 2679 | break; |
| 2680 | case MDSS_EVENT_PANEL_UPDATE_FPS: |
| 2681 | if (arg != NULL) { |
| 2682 | rc = mdss_dsi_dfps_config(pdata, |
| 2683 | (int) (unsigned long) arg); |
| 2684 | if (rc) |
| 2685 | pr_err("unable to change fps-%d, error-%d\n", |
| 2686 | (int) (unsigned long) arg, rc); |
| 2687 | else |
| 2688 | pr_debug("panel frame rate changed to %d\n", |
| 2689 | (int) (unsigned long) arg); |
| 2690 | } |
| 2691 | break; |
| 2692 | case MDSS_EVENT_CONT_SPLASH_BEGIN: |
| 2693 | if (ctrl_pdata->off_cmds.link_state == DSI_HS_MODE) { |
| 2694 | /* Panel is Enabled in Bootloader */ |
| 2695 | rc = mdss_dsi_blank(pdata, MDSS_PANEL_POWER_OFF); |
| 2696 | } |
| 2697 | break; |
| 2698 | case MDSS_EVENT_DSC_PPS_SEND: |
| 2699 | if (pinfo->compression_mode == COMPRESSION_DSC) |
| 2700 | mdss_dsi_panel_dsc_pps_send(ctrl_pdata, pinfo); |
| 2701 | break; |
| 2702 | case MDSS_EVENT_ENABLE_PARTIAL_ROI: |
| 2703 | rc = mdss_dsi_ctl_partial_roi(pdata); |
| 2704 | break; |
| 2705 | case MDSS_EVENT_DSI_RESET_WRITE_PTR: |
| 2706 | rc = mdss_dsi_reset_write_ptr(pdata); |
| 2707 | break; |
| 2708 | case MDSS_EVENT_DSI_STREAM_SIZE: |
| 2709 | rc = mdss_dsi_set_stream_size(pdata); |
| 2710 | break; |
| 2711 | case MDSS_EVENT_DSI_UPDATE_PANEL_DATA: |
| 2712 | rc = mdss_dsi_update_panel_config(ctrl_pdata, |
| 2713 | (int)(unsigned long) arg); |
| 2714 | break; |
| 2715 | case MDSS_EVENT_REGISTER_RECOVERY_HANDLER: |
| 2716 | rc = mdss_dsi_register_recovery_handler(ctrl_pdata, |
| 2717 | (struct mdss_intf_recovery *)arg); |
| 2718 | break; |
| 2719 | case MDSS_EVENT_REGISTER_MDP_CALLBACK: |
| 2720 | rc = mdss_dsi_register_mdp_callback(ctrl_pdata, |
| 2721 | (struct mdss_intf_recovery *)arg); |
| 2722 | break; |
| 2723 | case MDSS_EVENT_DSI_DYNAMIC_SWITCH: |
| 2724 | mode = (u32)(unsigned long) arg; |
| 2725 | mdss_dsi_switch_mode(pdata, mode); |
| 2726 | break; |
| 2727 | case MDSS_EVENT_DSI_RECONFIG_CMD: |
| 2728 | mode = (u32)(unsigned long) arg; |
| 2729 | rc = mdss_dsi_reconfig(pdata, mode); |
| 2730 | break; |
| 2731 | case MDSS_EVENT_DSI_PANEL_STATUS: |
| 2732 | if (ctrl_pdata->check_status) |
| 2733 | rc = ctrl_pdata->check_status(ctrl_pdata); |
| 2734 | else |
| 2735 | rc = true; |
| 2736 | break; |
| 2737 | case MDSS_EVENT_PANEL_TIMING_SWITCH: |
| 2738 | rc = mdss_dsi_panel_timing_switch(ctrl_pdata, arg); |
| 2739 | break; |
| 2740 | case MDSS_EVENT_FB_REGISTERED: |
| 2741 | mdss_dsi_debugfs_init(ctrl_pdata); |
| 2742 | |
| 2743 | fbi = (struct fb_info *)arg; |
| 2744 | if (!fbi || !fbi->dev) |
| 2745 | break; |
| 2746 | |
| 2747 | ctrl_pdata->kobj = &fbi->dev->kobj; |
| 2748 | ctrl_pdata->fb_node = fbi->node; |
| 2749 | |
| 2750 | if (IS_ENABLED(CONFIG_MSM_DBA) && |
| 2751 | pdata->panel_info.is_dba_panel) { |
| 2752 | queue_delayed_work(ctrl_pdata->workq, |
| 2753 | &ctrl_pdata->dba_work, HZ); |
| 2754 | } |
| 2755 | break; |
| 2756 | default: |
| 2757 | pr_debug("%s: unhandled event=%d\n", __func__, event); |
| 2758 | break; |
| 2759 | } |
| 2760 | pr_debug("%s-:event=%d, rc=%d\n", __func__, event, rc); |
| 2761 | return rc; |
| 2762 | } |
| 2763 | |
| 2764 | static int mdss_dsi_set_override_cfg(char *override_cfg, |
| 2765 | struct mdss_dsi_ctrl_pdata *ctrl_pdata, char *panel_cfg) |
| 2766 | { |
| 2767 | struct mdss_panel_info *pinfo = &ctrl_pdata->panel_data.panel_info; |
| 2768 | char *token = NULL; |
| 2769 | |
| 2770 | pr_debug("%s: override config:%s\n", __func__, override_cfg); |
| 2771 | while ((token = strsep(&override_cfg, ":"))) { |
| 2772 | if (!strcmp(token, OVERRIDE_CFG)) { |
| 2773 | continue; |
| 2774 | } else if (!strcmp(token, SIM_HW_TE_PANEL)) { |
| 2775 | pinfo->sim_panel_mode = SIM_HW_TE_MODE; |
| 2776 | } else if (!strcmp(token, SIM_SW_TE_PANEL)) { |
| 2777 | pinfo->sim_panel_mode = SIM_SW_TE_MODE; |
| 2778 | } else if (!strcmp(token, SIM_PANEL)) { |
| 2779 | pinfo->sim_panel_mode = SIM_MODE; |
| 2780 | } else { |
| 2781 | pr_err("%s: invalid override_cfg token: %s\n", |
| 2782 | __func__, token); |
| 2783 | return -EINVAL; |
| 2784 | } |
| 2785 | } |
| 2786 | pr_debug("%s:sim_panel_mode:%d\n", __func__, pinfo->sim_panel_mode); |
| 2787 | |
| 2788 | return 0; |
| 2789 | } |
| 2790 | |
| 2791 | static struct device_node *mdss_dsi_pref_prim_panel( |
| 2792 | struct platform_device *pdev) |
| 2793 | { |
| 2794 | struct device_node *dsi_pan_node = NULL; |
| 2795 | |
| 2796 | pr_debug("%s:%d: Select primary panel from dt\n", |
| 2797 | __func__, __LINE__); |
| 2798 | dsi_pan_node = of_parse_phandle(pdev->dev.of_node, |
| 2799 | "qcom,dsi-pref-prim-pan", 0); |
| 2800 | if (!dsi_pan_node) |
| 2801 | pr_err("%s:can't find panel phandle\n", __func__); |
| 2802 | |
| 2803 | return dsi_pan_node; |
| 2804 | } |
| 2805 | |
| 2806 | /** |
| 2807 | * mdss_dsi_find_panel_of_node(): find device node of dsi panel |
| 2808 | * @pdev: platform_device of the dsi ctrl node |
| 2809 | * @panel_cfg: string containing intf specific config data |
| 2810 | * |
| 2811 | * Function finds the panel device node using the interface |
| 2812 | * specific configuration data. This configuration data is |
| 2813 | * could be derived from the result of bootloader's GCDB |
| 2814 | * panel detection mechanism. If such config data doesn't |
| 2815 | * exist then this panel returns the default panel configured |
| 2816 | * in the device tree. |
| 2817 | * |
| 2818 | * returns pointer to panel node on success, NULL on error. |
| 2819 | */ |
| 2820 | static struct device_node *mdss_dsi_find_panel_of_node( |
| 2821 | struct platform_device *pdev, char *panel_cfg) |
| 2822 | { |
| 2823 | int len, i = 0; |
| 2824 | int ctrl_id = pdev->id - 1; |
| 2825 | char panel_name[MDSS_MAX_PANEL_LEN] = ""; |
| 2826 | char ctrl_id_stream[3] = "0:"; |
| 2827 | char *str1 = NULL, *str2 = NULL, *override_cfg = NULL; |
| 2828 | char cfg_np_name[MDSS_MAX_PANEL_LEN] = ""; |
| 2829 | struct device_node *dsi_pan_node = NULL, *mdss_node = NULL; |
| 2830 | struct mdss_dsi_ctrl_pdata *ctrl_pdata = platform_get_drvdata(pdev); |
| 2831 | struct mdss_panel_info *pinfo = &ctrl_pdata->panel_data.panel_info; |
| 2832 | |
| 2833 | len = strlen(panel_cfg); |
| 2834 | ctrl_pdata->panel_data.dsc_cfg_np_name[0] = '\0'; |
| 2835 | if (!len) { |
| 2836 | /* no panel cfg chg, parse dt */ |
| 2837 | pr_debug("%s:%d: no cmd line cfg present\n", |
| 2838 | __func__, __LINE__); |
| 2839 | goto end; |
| 2840 | } else { |
| 2841 | /* check if any override parameters are set */ |
| 2842 | pinfo->sim_panel_mode = 0; |
| 2843 | override_cfg = strnstr(panel_cfg, "#" OVERRIDE_CFG, len); |
| 2844 | if (override_cfg) { |
| 2845 | *override_cfg = '\0'; |
| 2846 | if (mdss_dsi_set_override_cfg(override_cfg + 1, |
| 2847 | ctrl_pdata, panel_cfg)) |
| 2848 | return NULL; |
| 2849 | len = strlen(panel_cfg); |
| 2850 | } |
| 2851 | |
| 2852 | if (ctrl_id == 1) |
| 2853 | strlcpy(ctrl_id_stream, "1:", 3); |
| 2854 | |
| 2855 | /* get controller number */ |
| 2856 | str1 = strnstr(panel_cfg, ctrl_id_stream, len); |
| 2857 | if (!str1) { |
| 2858 | pr_err("%s: controller %s is not present in %s\n", |
| 2859 | __func__, ctrl_id_stream, panel_cfg); |
| 2860 | goto end; |
| 2861 | } |
| 2862 | if ((str1 != panel_cfg) && (*(str1-1) != ':')) { |
| 2863 | str1 += CMDLINE_DSI_CTL_NUM_STRING_LEN; |
| 2864 | pr_debug("false match with config node name in \"%s\". search again in \"%s\"\n", |
| 2865 | panel_cfg, str1); |
| 2866 | str1 = strnstr(str1, ctrl_id_stream, len); |
| 2867 | if (!str1) { |
| 2868 | pr_err("%s: 2. controller %s is not present in %s\n", |
| 2869 | __func__, ctrl_id_stream, str1); |
| 2870 | goto end; |
| 2871 | } |
| 2872 | } |
| 2873 | str1 += CMDLINE_DSI_CTL_NUM_STRING_LEN; |
| 2874 | |
| 2875 | /* get panel name */ |
| 2876 | str2 = strnchr(str1, strlen(str1), ':'); |
| 2877 | if (!str2) { |
| 2878 | strlcpy(panel_name, str1, MDSS_MAX_PANEL_LEN); |
| 2879 | } else { |
| 2880 | for (i = 0; (str1 + i) < str2; i++) |
| 2881 | panel_name[i] = *(str1 + i); |
| 2882 | panel_name[i] = 0; |
| 2883 | } |
| 2884 | pr_info("%s: cmdline:%s panel_name:%s\n", |
| 2885 | __func__, panel_cfg, panel_name); |
| 2886 | if (!strcmp(panel_name, NONE_PANEL)) |
| 2887 | goto exit; |
| 2888 | |
| 2889 | mdss_node = of_parse_phandle(pdev->dev.of_node, |
| 2890 | "qcom,mdss-mdp", 0); |
| 2891 | if (!mdss_node) { |
| 2892 | pr_err("%s: %d: mdss_node null\n", |
| 2893 | __func__, __LINE__); |
| 2894 | return NULL; |
| 2895 | } |
| 2896 | dsi_pan_node = of_find_node_by_name(mdss_node, panel_name); |
| 2897 | if (!dsi_pan_node) { |
| 2898 | pr_err("%s: invalid pan node \"%s\"\n", |
| 2899 | __func__, panel_name); |
| 2900 | goto end; |
| 2901 | } else { |
| 2902 | /* extract config node name if present */ |
| 2903 | str1 += i; |
| 2904 | str2 = strnstr(str1, "config", strlen(str1)); |
| 2905 | if (str2) { |
| 2906 | str1 = strnchr(str2, strlen(str2), ':'); |
| 2907 | if (str1) { |
| 2908 | for (i = 0; ((str2 + i) < str1) && |
| 2909 | i < (MDSS_MAX_PANEL_LEN - 1); i++) |
| 2910 | cfg_np_name[i] = *(str2 + i); |
| 2911 | if ((i >= 0) |
| 2912 | && (i < MDSS_MAX_PANEL_LEN)) |
| 2913 | cfg_np_name[i] = 0; |
| 2914 | } else { |
| 2915 | strlcpy(cfg_np_name, str2, |
| 2916 | MDSS_MAX_PANEL_LEN); |
| 2917 | } |
| 2918 | strlcpy(ctrl_pdata->panel_data.dsc_cfg_np_name, |
| 2919 | cfg_np_name, MDSS_MAX_PANEL_LEN); |
| 2920 | } |
| 2921 | } |
| 2922 | |
| 2923 | return dsi_pan_node; |
| 2924 | } |
| 2925 | end: |
| 2926 | if (strcmp(panel_name, NONE_PANEL)) |
| 2927 | dsi_pan_node = mdss_dsi_pref_prim_panel(pdev); |
| 2928 | exit: |
| 2929 | return dsi_pan_node; |
| 2930 | } |
| 2931 | |
| 2932 | static struct device_node *mdss_dsi_config_panel(struct platform_device *pdev, |
| 2933 | int ndx) |
| 2934 | { |
| 2935 | struct mdss_dsi_ctrl_pdata *ctrl_pdata = platform_get_drvdata(pdev); |
| 2936 | char panel_cfg[MDSS_MAX_PANEL_LEN]; |
| 2937 | struct device_node *dsi_pan_node = NULL; |
| 2938 | int rc = 0; |
| 2939 | |
| 2940 | if (!ctrl_pdata) { |
| 2941 | pr_err("%s: Unable to get the ctrl_pdata\n", __func__); |
| 2942 | return NULL; |
| 2943 | } |
| 2944 | |
| 2945 | /* DSI panels can be different between controllers */ |
| 2946 | rc = mdss_dsi_get_panel_cfg(panel_cfg, ctrl_pdata); |
| 2947 | if (!rc) |
| 2948 | /* dsi panel cfg not present */ |
| 2949 | pr_warn("%s:%d:dsi specific cfg not present\n", |
| 2950 | __func__, __LINE__); |
| 2951 | |
| 2952 | /* find panel device node */ |
| 2953 | dsi_pan_node = mdss_dsi_find_panel_of_node(pdev, panel_cfg); |
| 2954 | if (!dsi_pan_node) { |
| 2955 | pr_err("%s: can't find panel node %s\n", __func__, panel_cfg); |
| 2956 | of_node_put(dsi_pan_node); |
| 2957 | return NULL; |
| 2958 | } |
| 2959 | |
| 2960 | rc = mdss_dsi_panel_init(dsi_pan_node, ctrl_pdata, ndx); |
| 2961 | if (rc) { |
| 2962 | pr_err("%s: dsi panel init failed\n", __func__); |
| 2963 | of_node_put(dsi_pan_node); |
| 2964 | return NULL; |
| 2965 | } |
| 2966 | |
| 2967 | return dsi_pan_node; |
| 2968 | } |
| 2969 | |
| 2970 | static int mdss_dsi_ctrl_clock_init(struct platform_device *ctrl_pdev, |
| 2971 | struct mdss_dsi_ctrl_pdata *ctrl_pdata) |
| 2972 | { |
| 2973 | int rc = 0; |
| 2974 | struct mdss_dsi_clk_info info; |
| 2975 | struct mdss_dsi_clk_client client1 = {"dsi_clk_client"}; |
| 2976 | struct mdss_dsi_clk_client client2 = {"mdp_event_client"}; |
| 2977 | void *handle; |
| 2978 | |
| 2979 | if (mdss_dsi_link_clk_init(ctrl_pdev, ctrl_pdata)) { |
| 2980 | pr_err("%s: unable to initialize Dsi ctrl clks\n", __func__); |
| 2981 | return -EPERM; |
| 2982 | } |
| 2983 | |
| 2984 | memset(&info, 0x0, sizeof(info)); |
| 2985 | |
| 2986 | info.core_clks.mdp_core_clk = ctrl_pdata->shared_data->mdp_core_clk; |
| 2987 | info.core_clks.ahb_clk = ctrl_pdata->shared_data->ahb_clk; |
| 2988 | info.core_clks.axi_clk = ctrl_pdata->shared_data->axi_clk; |
| 2989 | info.core_clks.mmss_misc_ahb_clk = |
| 2990 | ctrl_pdata->shared_data->mmss_misc_ahb_clk; |
| 2991 | |
Padmanabhan Komanduru | b0008fd | 2018-04-12 16:25:43 +0530 | [diff] [blame] | 2992 | info.link_lp_clks.esc_clk = ctrl_pdata->esc_clk; |
| 2993 | info.link_hs_clks.byte_clk = ctrl_pdata->byte_clk; |
| 2994 | info.link_hs_clks.pixel_clk = ctrl_pdata->pixel_clk; |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 2995 | |
| 2996 | info.pre_clkoff_cb = mdss_dsi_pre_clkoff_cb; |
| 2997 | info.post_clkon_cb = mdss_dsi_post_clkon_cb; |
| 2998 | info.pre_clkon_cb = mdss_dsi_pre_clkon_cb; |
| 2999 | info.post_clkoff_cb = mdss_dsi_post_clkoff_cb; |
| 3000 | info.priv_data = ctrl_pdata; |
| 3001 | snprintf(info.name, DSI_CLK_NAME_LEN, "DSI%d", ctrl_pdata->ndx); |
| 3002 | ctrl_pdata->clk_mngr = mdss_dsi_clk_init(&info); |
| 3003 | if (IS_ERR_OR_NULL(ctrl_pdata->clk_mngr)) { |
| 3004 | rc = PTR_ERR(ctrl_pdata->clk_mngr); |
| 3005 | ctrl_pdata->clk_mngr = NULL; |
| 3006 | pr_err("dsi clock registration failed, rc = %d\n", rc); |
| 3007 | goto error_link_clk_deinit; |
| 3008 | } |
| 3009 | |
| 3010 | /* |
| 3011 | * There are two clients that control dsi clocks. MDP driver controls |
| 3012 | * the clock through MDSS_PANEL_EVENT_CLK_CTRL event and dsi driver |
| 3013 | * through clock interface. To differentiate between the votes from the |
| 3014 | * two clients, dsi driver will use two different handles to vote for |
| 3015 | * clock states from dsi and mdp driver. |
| 3016 | */ |
| 3017 | handle = mdss_dsi_clk_register(ctrl_pdata->clk_mngr, &client1); |
| 3018 | if (IS_ERR_OR_NULL(handle)) { |
| 3019 | rc = PTR_ERR(handle); |
| 3020 | pr_err("failed to register %s client, rc = %d\n", |
| 3021 | client1.client_name, rc); |
| 3022 | goto error_clk_deinit; |
| 3023 | } else { |
| 3024 | ctrl_pdata->dsi_clk_handle = handle; |
| 3025 | } |
| 3026 | |
| 3027 | handle = mdss_dsi_clk_register(ctrl_pdata->clk_mngr, &client2); |
| 3028 | if (IS_ERR_OR_NULL(handle)) { |
| 3029 | rc = PTR_ERR(handle); |
| 3030 | pr_err("failed to register %s client, rc = %d\n", |
| 3031 | client2.client_name, rc); |
| 3032 | goto error_clk_client_deregister; |
| 3033 | } else { |
| 3034 | ctrl_pdata->mdp_clk_handle = handle; |
| 3035 | } |
| 3036 | |
| 3037 | return rc; |
| 3038 | error_clk_client_deregister: |
| 3039 | mdss_dsi_clk_deregister(ctrl_pdata->dsi_clk_handle); |
| 3040 | error_clk_deinit: |
| 3041 | mdss_dsi_clk_deinit(ctrl_pdata->clk_mngr); |
| 3042 | error_link_clk_deinit: |
| 3043 | mdss_dsi_link_clk_deinit(&ctrl_pdev->dev, ctrl_pdata); |
| 3044 | return rc; |
| 3045 | } |
| 3046 | |
| 3047 | static int mdss_dsi_set_clk_rates(struct mdss_dsi_ctrl_pdata *ctrl_pdata) |
| 3048 | { |
| 3049 | int rc = 0; |
| 3050 | |
| 3051 | rc = mdss_dsi_clk_set_link_rate(ctrl_pdata->dsi_clk_handle, |
| 3052 | MDSS_DSI_LINK_BYTE_CLK, |
| 3053 | ctrl_pdata->byte_clk_rate, |
| 3054 | MDSS_DSI_CLK_UPDATE_CLK_RATE_AT_ON); |
| 3055 | if (rc) { |
| 3056 | pr_err("%s: dsi_byte_clk - clk_set_rate failed\n", |
| 3057 | __func__); |
| 3058 | return rc; |
| 3059 | } |
| 3060 | |
| 3061 | rc = mdss_dsi_clk_set_link_rate(ctrl_pdata->dsi_clk_handle, |
| 3062 | MDSS_DSI_LINK_PIX_CLK, |
| 3063 | ctrl_pdata->pclk_rate, |
| 3064 | MDSS_DSI_CLK_UPDATE_CLK_RATE_AT_ON); |
| 3065 | if (rc) { |
| 3066 | pr_err("%s: dsi_pixel_clk - clk_set_rate failed\n", |
| 3067 | __func__); |
| 3068 | return rc; |
| 3069 | } |
| 3070 | |
| 3071 | rc = mdss_dsi_clk_set_link_rate(ctrl_pdata->dsi_clk_handle, |
| 3072 | MDSS_DSI_LINK_ESC_CLK, |
| 3073 | 19200000, |
| 3074 | MDSS_DSI_CLK_UPDATE_CLK_RATE_AT_ON); |
| 3075 | if (rc) { |
| 3076 | pr_err("%s: dsi_esc_clk - clk_set_rate failed\n", |
| 3077 | __func__); |
| 3078 | return rc; |
| 3079 | } |
| 3080 | |
| 3081 | return rc; |
| 3082 | } |
| 3083 | |
| 3084 | static int mdss_dsi_cont_splash_config(struct mdss_panel_info *pinfo, |
| 3085 | struct mdss_dsi_ctrl_pdata *ctrl_pdata) |
| 3086 | { |
| 3087 | void *clk_handle; |
| 3088 | int rc = 0; |
| 3089 | |
| 3090 | if (pinfo->cont_splash_enabled) { |
| 3091 | rc = mdss_dsi_panel_power_ctrl(&(ctrl_pdata->panel_data), |
| 3092 | MDSS_PANEL_POWER_ON); |
| 3093 | if (rc) { |
| 3094 | pr_err("%s: Panel power on failed\n", __func__); |
| 3095 | return rc; |
| 3096 | } |
| 3097 | if (ctrl_pdata->bklt_ctrl == BL_PWM) |
| 3098 | mdss_dsi_panel_pwm_enable(ctrl_pdata); |
| 3099 | ctrl_pdata->ctrl_state |= (CTRL_STATE_PANEL_INIT | |
| 3100 | CTRL_STATE_MDP_ACTIVE | CTRL_STATE_DSI_ACTIVE); |
| 3101 | |
| 3102 | /* |
| 3103 | * MDP client removes this extra vote during splash reconfigure |
| 3104 | * for command mode panel from interface. DSI removes the vote |
| 3105 | * during suspend-resume for video mode panel. |
| 3106 | */ |
| 3107 | if (ctrl_pdata->panel_data.panel_info.type == MIPI_CMD_PANEL) |
| 3108 | clk_handle = ctrl_pdata->mdp_clk_handle; |
| 3109 | else |
| 3110 | clk_handle = ctrl_pdata->dsi_clk_handle; |
| 3111 | |
| 3112 | mdss_dsi_clk_ctrl(ctrl_pdata, clk_handle, |
| 3113 | MDSS_DSI_ALL_CLKS, MDSS_DSI_CLK_ON); |
| 3114 | mdss_dsi_read_hw_revision(ctrl_pdata); |
| 3115 | mdss_dsi_read_phy_revision(ctrl_pdata); |
| 3116 | ctrl_pdata->is_phyreg_enabled = 1; |
| 3117 | if (pinfo->type == MIPI_CMD_PANEL) |
| 3118 | mdss_dsi_set_burst_mode(ctrl_pdata); |
| 3119 | } else { |
| 3120 | /* Turn on the clocks to read the DSI and PHY revision */ |
| 3121 | mdss_dsi_clk_ctrl(ctrl_pdata, ctrl_pdata->dsi_clk_handle, |
| 3122 | MDSS_DSI_CORE_CLK, MDSS_DSI_CLK_ON); |
| 3123 | mdss_dsi_read_hw_revision(ctrl_pdata); |
| 3124 | mdss_dsi_read_phy_revision(ctrl_pdata); |
| 3125 | mdss_dsi_clk_ctrl(ctrl_pdata, ctrl_pdata->dsi_clk_handle, |
| 3126 | MDSS_DSI_CORE_CLK, MDSS_DSI_CLK_OFF); |
| 3127 | pinfo->panel_power_state = MDSS_PANEL_POWER_OFF; |
| 3128 | } |
| 3129 | |
| 3130 | return rc; |
| 3131 | } |
| 3132 | |
| 3133 | static int mdss_dsi_get_bridge_chip_params(struct mdss_panel_info *pinfo, |
| 3134 | struct mdss_dsi_ctrl_pdata *ctrl_pdata, |
| 3135 | struct platform_device *pdev) |
| 3136 | { |
| 3137 | int rc = 0; |
| 3138 | u32 temp_val = 0; |
| 3139 | |
| 3140 | if (!ctrl_pdata || !pdev || !pinfo) { |
| 3141 | pr_err("%s: Invalid Params ctrl_pdata=%pK, pdev=%pK\n", |
| 3142 | __func__, ctrl_pdata, pdev); |
| 3143 | rc = -EINVAL; |
| 3144 | goto end; |
| 3145 | } |
| 3146 | |
| 3147 | if (pinfo->is_dba_panel) { |
| 3148 | rc = of_property_read_u32(pdev->dev.of_node, |
| 3149 | "qcom,bridge-index", &temp_val); |
| 3150 | if (rc) { |
| 3151 | pr_err("%s:%d Unable to read qcom,bridge-index, ret=%d\n", |
| 3152 | __func__, __LINE__, rc); |
| 3153 | goto end; |
| 3154 | } |
| 3155 | pr_debug("%s: DT property %s is %X\n", __func__, |
| 3156 | "qcom,bridge-index", temp_val); |
| 3157 | ctrl_pdata->bridge_index = temp_val; |
| 3158 | } |
| 3159 | end: |
| 3160 | return rc; |
| 3161 | } |
| 3162 | |
| 3163 | static int mdss_dsi_ctrl_probe(struct platform_device *pdev) |
| 3164 | { |
| 3165 | int rc = 0; |
| 3166 | u32 index; |
| 3167 | struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL; |
| 3168 | struct mdss_panel_info *pinfo = NULL; |
| 3169 | struct device_node *dsi_pan_node = NULL; |
| 3170 | const char *ctrl_name; |
| 3171 | struct mdss_util_intf *util; |
| 3172 | static int te_irq_registered; |
| 3173 | struct mdss_panel_data *pdata; |
| 3174 | |
| 3175 | if (!pdev || !pdev->dev.of_node) { |
| 3176 | pr_err("%s: pdev not found for DSI controller\n", __func__); |
| 3177 | return -ENODEV; |
| 3178 | } |
| 3179 | rc = of_property_read_u32(pdev->dev.of_node, |
| 3180 | "cell-index", &index); |
| 3181 | if (rc) { |
| 3182 | dev_err(&pdev->dev, "%s: Cell-index not specified, rc=%d\n", |
| 3183 | __func__, rc); |
| 3184 | return rc; |
| 3185 | } |
| 3186 | |
| 3187 | if (index == 0) |
| 3188 | pdev->id = 1; |
| 3189 | else |
| 3190 | pdev->id = 2; |
| 3191 | |
| 3192 | ctrl_pdata = mdss_dsi_get_ctrl(index); |
| 3193 | if (!ctrl_pdata) { |
| 3194 | pr_err("%s: Unable to get the ctrl_pdata\n", __func__); |
| 3195 | return -EINVAL; |
| 3196 | } |
| 3197 | |
| 3198 | platform_set_drvdata(pdev, ctrl_pdata); |
| 3199 | |
| 3200 | util = mdss_get_util_intf(); |
| 3201 | if (util == NULL) { |
| 3202 | pr_err("Failed to get mdss utility functions\n"); |
| 3203 | return -ENODEV; |
| 3204 | } |
| 3205 | |
| 3206 | ctrl_pdata->mdss_util = util; |
| 3207 | atomic_set(&ctrl_pdata->te_irq_ready, 0); |
| 3208 | |
| 3209 | ctrl_name = of_get_property(pdev->dev.of_node, "label", NULL); |
| 3210 | if (!ctrl_name) |
| 3211 | pr_info("%s:%d, DSI Ctrl name not specified\n", |
| 3212 | __func__, __LINE__); |
| 3213 | else |
| 3214 | pr_info("%s: DSI Ctrl name = %s\n", |
| 3215 | __func__, ctrl_name); |
| 3216 | |
| 3217 | rc = mdss_dsi_pinctrl_init(pdev); |
| 3218 | if (rc) |
| 3219 | pr_warn("%s: failed to get pin resources\n", __func__); |
| 3220 | |
| 3221 | if (index == 0) { |
| 3222 | ctrl_pdata->panel_data.panel_info.pdest = DISPLAY_1; |
| 3223 | ctrl_pdata->ndx = DSI_CTRL_0; |
| 3224 | } else { |
| 3225 | ctrl_pdata->panel_data.panel_info.pdest = DISPLAY_2; |
| 3226 | ctrl_pdata->ndx = DSI_CTRL_1; |
| 3227 | } |
| 3228 | |
| 3229 | if (mdss_dsi_ctrl_clock_init(pdev, ctrl_pdata)) { |
| 3230 | pr_err("%s: unable to initialize dsi clk manager\n", __func__); |
| 3231 | return -EPERM; |
| 3232 | } |
| 3233 | |
| 3234 | dsi_pan_node = mdss_dsi_config_panel(pdev, index); |
| 3235 | if (!dsi_pan_node) { |
| 3236 | pr_err("%s: panel configuration failed\n", __func__); |
| 3237 | return -EINVAL; |
| 3238 | } |
| 3239 | |
| 3240 | if (!mdss_dsi_is_hw_config_split(ctrl_pdata->shared_data) || |
| 3241 | (mdss_dsi_is_hw_config_split(ctrl_pdata->shared_data) && |
| 3242 | (ctrl_pdata->panel_data.panel_info.pdest == DISPLAY_1))) { |
| 3243 | rc = mdss_panel_parse_bl_settings(dsi_pan_node, ctrl_pdata); |
| 3244 | if (rc) { |
| 3245 | pr_warn("%s: dsi bl settings parse failed\n", __func__); |
| 3246 | /* Panels like AMOLED and dsi2hdmi chip |
| 3247 | * does not need backlight control. |
| 3248 | * So we should not fail probe here. |
| 3249 | */ |
| 3250 | ctrl_pdata->bklt_ctrl = UNKNOWN_CTRL; |
| 3251 | } |
| 3252 | } else { |
| 3253 | ctrl_pdata->bklt_ctrl = UNKNOWN_CTRL; |
| 3254 | } |
| 3255 | |
| 3256 | rc = dsi_panel_device_register(pdev, dsi_pan_node, ctrl_pdata); |
| 3257 | if (rc) { |
| 3258 | pr_err("%s: dsi panel dev reg failed\n", __func__); |
| 3259 | goto error_pan_node; |
| 3260 | } |
| 3261 | |
| 3262 | pinfo = &(ctrl_pdata->panel_data.panel_info); |
| 3263 | if (!(mdss_dsi_is_hw_config_split(ctrl_pdata->shared_data) && |
| 3264 | mdss_dsi_is_ctrl_clk_slave(ctrl_pdata)) && |
| 3265 | pinfo->dynamic_fps) { |
| 3266 | rc = mdss_dsi_shadow_clk_init(pdev, ctrl_pdata); |
| 3267 | |
| 3268 | if (rc) { |
| 3269 | pr_err("%s: unable to initialize shadow ctrl clks\n", |
| 3270 | __func__); |
| 3271 | rc = -EPERM; |
| 3272 | } |
| 3273 | } |
| 3274 | |
| 3275 | rc = mdss_dsi_set_clk_rates(ctrl_pdata); |
| 3276 | if (rc) { |
| 3277 | pr_err("%s: Failed to set dsi clk rates\n", __func__); |
| 3278 | return rc; |
| 3279 | } |
| 3280 | |
| 3281 | rc = mdss_dsi_cont_splash_config(pinfo, ctrl_pdata); |
| 3282 | if (rc) { |
| 3283 | pr_err("%s: Failed to set dsi splash config\n", __func__); |
| 3284 | return rc; |
| 3285 | } |
| 3286 | |
| 3287 | if (mdss_dsi_is_te_based_esd(ctrl_pdata)) { |
| 3288 | init_completion(&ctrl_pdata->te_irq_comp); |
| 3289 | rc = devm_request_irq(&pdev->dev, |
| 3290 | gpio_to_irq(ctrl_pdata->disp_te_gpio), |
| 3291 | hw_vsync_handler, IRQF_TRIGGER_FALLING, |
| 3292 | "VSYNC_GPIO", ctrl_pdata); |
| 3293 | if (rc) { |
| 3294 | pr_err("%s: TE request_irq failed for ESD\n", __func__); |
| 3295 | goto error_shadow_clk_deinit; |
| 3296 | } |
| 3297 | te_irq_registered = 1; |
| 3298 | disable_irq(gpio_to_irq(ctrl_pdata->disp_te_gpio)); |
| 3299 | } |
| 3300 | |
| 3301 | pdata = &ctrl_pdata->panel_data; |
| 3302 | init_completion(&pdata->te_done); |
| 3303 | if (pdata->panel_info.type == MIPI_CMD_PANEL) { |
| 3304 | if (!te_irq_registered) { |
| 3305 | rc = devm_request_irq(&pdev->dev, |
| 3306 | gpio_to_irq(pdata->panel_te_gpio), |
| 3307 | test_hw_vsync_handler, IRQF_TRIGGER_FALLING, |
| 3308 | "VSYNC_GPIO", &ctrl_pdata->panel_data); |
| 3309 | if (rc) { |
| 3310 | pr_err("%s: TE request_irq failed\n", __func__); |
| 3311 | goto error_shadow_clk_deinit; |
| 3312 | } |
| 3313 | te_irq_registered = 1; |
| 3314 | disable_irq_nosync(gpio_to_irq(pdata->panel_te_gpio)); |
| 3315 | } |
| 3316 | } |
| 3317 | |
| 3318 | rc = mdss_dsi_get_bridge_chip_params(pinfo, ctrl_pdata, pdev); |
| 3319 | if (rc) { |
| 3320 | pr_err("%s: Failed to get bridge params\n", __func__); |
| 3321 | goto error_shadow_clk_deinit; |
| 3322 | } |
| 3323 | |
| 3324 | ctrl_pdata->workq = create_workqueue("mdss_dsi_dba"); |
| 3325 | if (!ctrl_pdata->workq) { |
| 3326 | pr_err("%s: Error creating workqueue\n", __func__); |
| 3327 | rc = -EPERM; |
| 3328 | goto error_pan_node; |
| 3329 | } |
| 3330 | |
| 3331 | INIT_DELAYED_WORK(&ctrl_pdata->dba_work, mdss_dsi_dba_work); |
| 3332 | |
| 3333 | pr_info("%s: Dsi Ctrl->%d initialized, DSI rev:0x%x, PHY rev:0x%x\n", |
| 3334 | __func__, index, ctrl_pdata->shared_data->hw_rev, |
| 3335 | ctrl_pdata->shared_data->phy_rev); |
| 3336 | mdss_dsi_pm_qos_add_request(ctrl_pdata); |
| 3337 | |
| 3338 | if (index == 0) |
| 3339 | ctrl_pdata->shared_data->dsi0_active = true; |
| 3340 | else |
| 3341 | ctrl_pdata->shared_data->dsi1_active = true; |
| 3342 | |
| 3343 | return 0; |
| 3344 | |
| 3345 | error_shadow_clk_deinit: |
| 3346 | mdss_dsi_shadow_clk_deinit(&pdev->dev, ctrl_pdata); |
| 3347 | error_pan_node: |
| 3348 | mdss_dsi_unregister_bl_settings(ctrl_pdata); |
| 3349 | of_node_put(dsi_pan_node); |
| 3350 | return rc; |
| 3351 | } |
| 3352 | |
| 3353 | static int mdss_dsi_bus_scale_init(struct platform_device *pdev, |
| 3354 | struct dsi_shared_data *sdata) |
| 3355 | { |
| 3356 | int rc = 0; |
| 3357 | |
| 3358 | sdata->bus_scale_table = msm_bus_cl_get_pdata(pdev); |
| 3359 | if (IS_ERR_OR_NULL(sdata->bus_scale_table)) { |
| 3360 | rc = PTR_ERR(sdata->bus_scale_table); |
| 3361 | pr_err("%s: msm_bus_cl_get_pdata() failed, rc=%d\n", __func__, |
| 3362 | rc); |
| 3363 | return rc; |
| 3364 | sdata->bus_scale_table = NULL; |
| 3365 | } |
| 3366 | |
| 3367 | sdata->bus_handle = |
| 3368 | msm_bus_scale_register_client(sdata->bus_scale_table); |
| 3369 | |
| 3370 | if (!sdata->bus_handle) { |
| 3371 | rc = -EINVAL; |
| 3372 | pr_err("%sbus_client register failed\n", __func__); |
| 3373 | } |
| 3374 | |
| 3375 | return rc; |
| 3376 | } |
| 3377 | |
| 3378 | static void mdss_dsi_bus_scale_deinit(struct dsi_shared_data *sdata) |
| 3379 | { |
| 3380 | if (sdata->bus_handle) { |
| 3381 | if (sdata->bus_refcount) |
| 3382 | msm_bus_scale_client_update_request(sdata->bus_handle, |
| 3383 | 0); |
| 3384 | |
| 3385 | sdata->bus_refcount = 0; |
| 3386 | msm_bus_scale_unregister_client(sdata->bus_handle); |
| 3387 | sdata->bus_handle = 0; |
| 3388 | } |
| 3389 | } |
| 3390 | |
| 3391 | static int mdss_dsi_parse_dt_params(struct platform_device *pdev, |
| 3392 | struct dsi_shared_data *sdata) |
| 3393 | { |
| 3394 | int rc = 0; |
| 3395 | |
| 3396 | rc = of_property_read_u32(pdev->dev.of_node, |
| 3397 | "qcom,mmss-ulp-clamp-ctrl-offset", |
| 3398 | &sdata->ulps_clamp_ctrl_off); |
| 3399 | if (!rc) { |
| 3400 | rc = of_property_read_u32(pdev->dev.of_node, |
| 3401 | "qcom,mmss-phyreset-ctrl-offset", |
| 3402 | &sdata->ulps_phyrst_ctrl_off); |
| 3403 | } |
| 3404 | |
| 3405 | sdata->cmd_clk_ln_recovery_en = |
| 3406 | of_property_read_bool(pdev->dev.of_node, |
| 3407 | "qcom,dsi-clk-ln-recovery"); |
| 3408 | |
| 3409 | return 0; |
| 3410 | } |
| 3411 | |
| 3412 | #ifdef TARGET_HW_MDSS_HDMI |
| 3413 | static void mdss_dsi_res_deinit_hdmi(struct platform_device *pdev, int val) |
| 3414 | { |
| 3415 | struct mdss_dsi_data *dsi_res = platform_get_drvdata(pdev); |
| 3416 | |
| 3417 | if (dsi_res->ctrl_pdata[val]->ds_registered) { |
| 3418 | struct mdss_panel_info *pinfo = |
| 3419 | &dsi_res->ctrl_pdata[val]-> |
| 3420 | panel_data.panel_info; |
| 3421 | if (pinfo) |
| 3422 | mdss_dba_utils_deinit(pinfo->dba_data); |
| 3423 | } |
| 3424 | } |
| 3425 | #else |
| 3426 | static void mdss_dsi_res_deinit_hdmi(struct platform_device *pdev, int val) |
| 3427 | { |
| 3428 | (void)(*pdev); |
| 3429 | (void)(val); |
| 3430 | } |
| 3431 | #endif |
| 3432 | |
| 3433 | static void mdss_dsi_res_deinit(struct platform_device *pdev) |
| 3434 | { |
| 3435 | int i; |
| 3436 | struct mdss_dsi_data *dsi_res = platform_get_drvdata(pdev); |
| 3437 | struct dsi_shared_data *sdata; |
| 3438 | |
| 3439 | if (!dsi_res) { |
| 3440 | pr_err("%s: DSI root device drvdata not found\n", __func__); |
| 3441 | return; |
| 3442 | } |
| 3443 | |
| 3444 | for (i = 0; i < DSI_CTRL_MAX; i++) { |
| 3445 | if (dsi_res->ctrl_pdata[i]) { |
| 3446 | mdss_dsi_res_deinit_hdmi(pdev, i); |
| 3447 | devm_kfree(&pdev->dev, dsi_res->ctrl_pdata[i]); |
| 3448 | } |
| 3449 | } |
| 3450 | |
| 3451 | sdata = dsi_res->shared_data; |
| 3452 | if (!sdata) |
| 3453 | goto res_release; |
| 3454 | |
| 3455 | for (i = (DSI_MAX_PM - 1); i >= DSI_CORE_PM; i--) { |
Sachin Bhayare | 5076e25 | 2018-01-18 14:56:45 +0530 | [diff] [blame] | 3456 | if (msm_mdss_config_vreg(&pdev->dev, |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 3457 | sdata->power_data[i].vreg_config, |
| 3458 | sdata->power_data[i].num_vreg, 1) < 0) |
| 3459 | pr_err("%s: failed to de-init vregs for %s\n", |
| 3460 | __func__, __mdss_dsi_pm_name(i)); |
| 3461 | mdss_dsi_put_dt_vreg_data(&pdev->dev, |
| 3462 | &sdata->power_data[i]); |
| 3463 | } |
| 3464 | |
| 3465 | mdss_dsi_bus_scale_deinit(sdata); |
| 3466 | mdss_dsi_core_clk_deinit(&pdev->dev, sdata); |
| 3467 | |
| 3468 | if (sdata) |
| 3469 | devm_kfree(&pdev->dev, sdata); |
| 3470 | |
| 3471 | res_release: |
| 3472 | if (dsi_res) |
| 3473 | devm_kfree(&pdev->dev, dsi_res); |
| 3474 | |
| 3475 | } |
| 3476 | |
| 3477 | static int mdss_dsi_res_init(struct platform_device *pdev) |
| 3478 | { |
| 3479 | int rc = 0, i; |
| 3480 | struct dsi_shared_data *sdata; |
| 3481 | |
| 3482 | mdss_dsi_res = platform_get_drvdata(pdev); |
| 3483 | if (!mdss_dsi_res) { |
| 3484 | mdss_dsi_res = devm_kzalloc(&pdev->dev, |
| 3485 | sizeof(struct mdss_dsi_data), |
| 3486 | GFP_KERNEL); |
| 3487 | if (!mdss_dsi_res) { |
| 3488 | pr_err("%s: FAILED: cannot alloc dsi data\n", |
| 3489 | __func__); |
| 3490 | rc = -ENOMEM; |
| 3491 | goto mem_fail; |
| 3492 | } |
| 3493 | |
| 3494 | mdss_dsi_res->shared_data = devm_kzalloc(&pdev->dev, |
| 3495 | sizeof(struct dsi_shared_data), |
| 3496 | GFP_KERNEL); |
| 3497 | pr_debug("%s Allocated shared_data=%pK\n", __func__, |
| 3498 | mdss_dsi_res->shared_data); |
| 3499 | if (!mdss_dsi_res->shared_data) { |
| 3500 | pr_err("%s Unable to alloc mem for shared_data\n", |
| 3501 | __func__); |
| 3502 | rc = -ENOMEM; |
| 3503 | goto mem_fail; |
| 3504 | } |
| 3505 | |
| 3506 | sdata = mdss_dsi_res->shared_data; |
| 3507 | |
| 3508 | rc = mdss_dsi_parse_dt_params(pdev, sdata); |
| 3509 | if (rc) { |
| 3510 | pr_err("%s: failed to parse mdss dsi DT params\n", |
| 3511 | __func__); |
| 3512 | goto mem_fail; |
| 3513 | } |
| 3514 | |
| 3515 | rc = mdss_dsi_core_clk_init(pdev, sdata); |
| 3516 | if (rc) { |
| 3517 | pr_err("%s: failed to initialize DSI core clocks\n", |
| 3518 | __func__); |
| 3519 | goto mem_fail; |
| 3520 | } |
| 3521 | |
| 3522 | /* Parse the regulator information */ |
| 3523 | for (i = DSI_CORE_PM; i < DSI_MAX_PM; i++) { |
| 3524 | rc = mdss_dsi_get_dt_vreg_data(&pdev->dev, |
| 3525 | pdev->dev.of_node, &sdata->power_data[i], i); |
| 3526 | if (rc) { |
| 3527 | pr_err("%s: '%s' get_dt_vreg_data failed.rc=%d\n", |
| 3528 | __func__, __mdss_dsi_pm_name(i), rc); |
| 3529 | i--; |
| 3530 | for (; i >= DSI_CORE_PM; i--) |
| 3531 | mdss_dsi_put_dt_vreg_data(&pdev->dev, |
| 3532 | &sdata->power_data[i]); |
| 3533 | goto mem_fail; |
| 3534 | } |
| 3535 | } |
| 3536 | rc = mdss_dsi_regulator_init(pdev, sdata); |
| 3537 | if (rc) { |
| 3538 | pr_err("%s: failed to init regulator, rc=%d\n", |
| 3539 | __func__, rc); |
| 3540 | goto mem_fail; |
| 3541 | } |
| 3542 | |
| 3543 | rc = mdss_dsi_bus_scale_init(pdev, sdata); |
| 3544 | if (rc) { |
| 3545 | pr_err("%s: failed to init bus scale settings, rc=%d\n", |
| 3546 | __func__, rc); |
| 3547 | goto mem_fail; |
| 3548 | } |
| 3549 | |
| 3550 | mutex_init(&sdata->phy_reg_lock); |
| 3551 | mutex_init(&sdata->pm_qos_lock); |
| 3552 | |
| 3553 | for (i = 0; i < DSI_CTRL_MAX; i++) { |
| 3554 | mdss_dsi_res->ctrl_pdata[i] = devm_kzalloc(&pdev->dev, |
| 3555 | sizeof(struct mdss_dsi_ctrl_pdata), |
| 3556 | GFP_KERNEL); |
| 3557 | if (!mdss_dsi_res->ctrl_pdata[i]) { |
| 3558 | pr_err("%s Unable to alloc mem for ctrl=%d\n", |
| 3559 | __func__, i); |
| 3560 | rc = -ENOMEM; |
| 3561 | goto mem_fail; |
| 3562 | } |
| 3563 | pr_debug("%s Allocated ctrl_pdata[%d]=%pK\n", |
| 3564 | __func__, i, mdss_dsi_res->ctrl_pdata[i]); |
| 3565 | mdss_dsi_res->ctrl_pdata[i]->shared_data = |
| 3566 | mdss_dsi_res->shared_data; |
| 3567 | } |
| 3568 | |
| 3569 | platform_set_drvdata(pdev, mdss_dsi_res); |
| 3570 | } |
| 3571 | |
| 3572 | mdss_dsi_res->pdev = pdev; |
| 3573 | pr_debug("%s: Setting up mdss_dsi_res=%pK\n", __func__, mdss_dsi_res); |
| 3574 | |
| 3575 | return 0; |
| 3576 | |
| 3577 | mem_fail: |
| 3578 | mdss_dsi_res_deinit(pdev); |
| 3579 | return rc; |
| 3580 | } |
| 3581 | |
| 3582 | static int mdss_dsi_parse_hw_cfg(struct platform_device *pdev, char *pan_cfg) |
| 3583 | { |
| 3584 | const char *data; |
| 3585 | struct mdss_dsi_data *dsi_res = platform_get_drvdata(pdev); |
| 3586 | struct dsi_shared_data *sdata; |
| 3587 | char dsi_cfg[20]; |
| 3588 | char *cfg_prim = NULL, *cfg_sec = NULL, *ch = NULL; |
| 3589 | int i = 0; |
| 3590 | |
| 3591 | if (!dsi_res) { |
| 3592 | pr_err("%s: DSI root device drvdata not found\n", __func__); |
| 3593 | return -EINVAL; |
| 3594 | } |
| 3595 | |
| 3596 | sdata = mdss_dsi_res->shared_data; |
| 3597 | if (!sdata) { |
| 3598 | pr_err("%s: DSI shared data not found\n", __func__); |
| 3599 | return -EINVAL; |
| 3600 | } |
| 3601 | |
| 3602 | sdata->hw_config = SINGLE_DSI; |
| 3603 | |
| 3604 | if (pan_cfg) |
| 3605 | cfg_prim = strnstr(pan_cfg, "cfg:", strlen(pan_cfg)); |
| 3606 | if (cfg_prim) { |
| 3607 | cfg_prim += 4; |
| 3608 | |
| 3609 | cfg_sec = strnchr(cfg_prim, strlen(cfg_prim), ':'); |
| 3610 | if (!cfg_sec) |
| 3611 | cfg_sec = cfg_prim + strlen(cfg_prim); |
| 3612 | |
| 3613 | for (i = 0; ((cfg_prim + i) < cfg_sec) && |
| 3614 | (*(cfg_prim+i) != '#'); i++) |
| 3615 | dsi_cfg[i] = *(cfg_prim + i); |
| 3616 | |
| 3617 | dsi_cfg[i] = '\0'; |
| 3618 | data = dsi_cfg; |
| 3619 | } else { |
| 3620 | data = of_get_property(pdev->dev.of_node, |
| 3621 | "hw-config", NULL); |
| 3622 | } |
| 3623 | |
| 3624 | if (data) { |
| 3625 | /* |
| 3626 | * To handle the override parameter (#override:sim) |
| 3627 | * passed for simulator panels |
| 3628 | */ |
| 3629 | ch = strnstr(data, "#", strlen(data)); |
| 3630 | ch ? *ch = '\0' : false; |
| 3631 | |
| 3632 | if (!strcmp(data, "dual_dsi")) |
| 3633 | sdata->hw_config = DUAL_DSI; |
| 3634 | else if (!strcmp(data, "split_dsi")) |
| 3635 | sdata->hw_config = SPLIT_DSI; |
| 3636 | else if (!strcmp(data, "single_dsi")) |
| 3637 | sdata->hw_config = SINGLE_DSI; |
| 3638 | else |
| 3639 | pr_err("%s: Incorrect string for DSI config:%s. Setting default as SINGLE_DSI\n", |
| 3640 | __func__, data); |
| 3641 | } else { |
| 3642 | pr_err("%s: Error: No DSI HW config found\n", |
| 3643 | __func__); |
| 3644 | return -EINVAL; |
| 3645 | } |
| 3646 | |
| 3647 | pr_debug("%s: DSI h/w configuration is %d\n", __func__, |
| 3648 | sdata->hw_config); |
| 3649 | |
| 3650 | return 0; |
| 3651 | } |
| 3652 | |
| 3653 | static void mdss_dsi_parse_pll_src_cfg(struct platform_device *pdev, |
| 3654 | char *pan_cfg) |
| 3655 | { |
| 3656 | const char *data; |
| 3657 | char *pll_ptr, pll_cfg[10] = {'\0'}; |
| 3658 | struct dsi_shared_data *sdata = mdss_dsi_res->shared_data; |
| 3659 | |
| 3660 | sdata->pll_src_config = PLL_SRC_DEFAULT; |
| 3661 | |
| 3662 | if (pan_cfg) { |
| 3663 | pll_ptr = strnstr(pan_cfg, ":pll0", strlen(pan_cfg)); |
| 3664 | if (!pll_ptr) { |
| 3665 | pll_ptr = strnstr(pan_cfg, ":pll1", strlen(pan_cfg)); |
| 3666 | if (pll_ptr) |
| 3667 | strlcpy(pll_cfg, "PLL1", strlen(pll_cfg)); |
| 3668 | } else { |
| 3669 | strlcpy(pll_cfg, "PLL0", strlen(pll_cfg)); |
| 3670 | } |
| 3671 | } |
| 3672 | data = pll_cfg; |
| 3673 | |
| 3674 | if (!data || !strcmp(data, "")) |
| 3675 | data = of_get_property(pdev->dev.of_node, |
| 3676 | "pll-src-config", NULL); |
| 3677 | if (data) { |
| 3678 | if (!strcmp(data, "PLL0")) |
| 3679 | sdata->pll_src_config = PLL_SRC_0; |
| 3680 | else if (!strcmp(data, "PLL1")) |
| 3681 | sdata->pll_src_config = PLL_SRC_1; |
| 3682 | else |
| 3683 | pr_err("%s: invalid pll src config %s\n", |
| 3684 | __func__, data); |
| 3685 | } else { |
| 3686 | pr_debug("%s: PLL src config not specified\n", __func__); |
| 3687 | } |
| 3688 | |
| 3689 | pr_debug("%s: pll_src_config = %d", __func__, sdata->pll_src_config); |
| 3690 | } |
| 3691 | |
| 3692 | static int mdss_dsi_validate_pll_src_config(struct dsi_shared_data *sdata) |
| 3693 | { |
| 3694 | int rc = 0; |
| 3695 | |
| 3696 | /* |
| 3697 | * DSI PLL1 can only drive DSI PHY1. As such: |
| 3698 | * - For split dsi config, only PLL0 is supported |
| 3699 | * - For dual dsi config, DSI0-PLL0 and DSI1-PLL1 is the only |
| 3700 | * possible configuration |
| 3701 | */ |
| 3702 | if (mdss_dsi_is_hw_config_split(sdata) && |
| 3703 | mdss_dsi_is_pll_src_pll1(sdata)) { |
| 3704 | pr_err("%s: unsupported PLL config: using PLL1 for split-dsi\n", |
| 3705 | __func__); |
| 3706 | rc = -EINVAL; |
| 3707 | goto error; |
| 3708 | } |
| 3709 | |
| 3710 | if (mdss_dsi_is_hw_config_dual(sdata) && |
| 3711 | !mdss_dsi_is_pll_src_default(sdata)) { |
| 3712 | pr_debug("%s: pll src config not applicable for dual-dsi\n", |
| 3713 | __func__); |
| 3714 | sdata->pll_src_config = PLL_SRC_DEFAULT; |
| 3715 | } |
| 3716 | |
| 3717 | error: |
| 3718 | return rc; |
| 3719 | } |
| 3720 | |
| 3721 | static int mdss_dsi_validate_config(struct platform_device *pdev) |
| 3722 | { |
| 3723 | struct dsi_shared_data *sdata = mdss_dsi_res->shared_data; |
| 3724 | |
| 3725 | return mdss_dsi_validate_pll_src_config(sdata); |
| 3726 | } |
| 3727 | |
| 3728 | static const struct of_device_id mdss_dsi_ctrl_dt_match[] = { |
| 3729 | {.compatible = "qcom,mdss-dsi-ctrl"}, |
| 3730 | {} |
| 3731 | }; |
| 3732 | MODULE_DEVICE_TABLE(of, mdss_dsi_ctrl_dt_match); |
| 3733 | |
| 3734 | static int mdss_dsi_probe(struct platform_device *pdev) |
| 3735 | { |
| 3736 | struct mdss_panel_cfg *pan_cfg = NULL; |
| 3737 | struct mdss_util_intf *util; |
| 3738 | char *panel_cfg; |
| 3739 | int rc = 0; |
| 3740 | |
| 3741 | util = mdss_get_util_intf(); |
| 3742 | if (util == NULL) { |
| 3743 | pr_err("%s: Failed to get mdss utility functions\n", __func__); |
| 3744 | return -ENODEV; |
| 3745 | } |
| 3746 | |
| 3747 | if (!util->mdp_probe_done) { |
| 3748 | pr_err("%s: MDP not probed yet!\n", __func__); |
| 3749 | return -EPROBE_DEFER; |
| 3750 | } |
| 3751 | |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 3752 | if (!pdev || !pdev->dev.of_node) { |
| 3753 | pr_err("%s: DSI driver only supports device tree probe\n", |
| 3754 | __func__); |
| 3755 | return -ENOTSUPP; |
| 3756 | } |
| 3757 | |
| 3758 | pan_cfg = util->panel_intf_type(MDSS_PANEL_INTF_HDMI); |
| 3759 | if (IS_ERR(pan_cfg)) { |
| 3760 | return PTR_ERR(pan_cfg); |
| 3761 | } else if (pan_cfg) { |
| 3762 | pr_debug("%s: HDMI is primary\n", __func__); |
| 3763 | return -ENODEV; |
| 3764 | } |
| 3765 | |
| 3766 | pan_cfg = util->panel_intf_type(MDSS_PANEL_INTF_DSI); |
| 3767 | if (IS_ERR_OR_NULL(pan_cfg)) { |
| 3768 | rc = PTR_ERR(pan_cfg); |
| 3769 | goto error; |
| 3770 | } else { |
| 3771 | panel_cfg = pan_cfg->arg_cfg; |
| 3772 | } |
| 3773 | |
| 3774 | rc = mdss_dsi_res_init(pdev); |
| 3775 | if (rc) { |
| 3776 | pr_err("%s Unable to set dsi res\n", __func__); |
| 3777 | return rc; |
| 3778 | } |
| 3779 | |
| 3780 | rc = mdss_dsi_parse_hw_cfg(pdev, panel_cfg); |
| 3781 | if (rc) { |
| 3782 | pr_err("%s Unable to parse dsi h/w config\n", __func__); |
| 3783 | mdss_dsi_res_deinit(pdev); |
| 3784 | return rc; |
| 3785 | } |
| 3786 | |
| 3787 | mdss_dsi_parse_pll_src_cfg(pdev, panel_cfg); |
| 3788 | |
| 3789 | of_platform_populate(pdev->dev.of_node, mdss_dsi_ctrl_dt_match, |
| 3790 | NULL, &pdev->dev); |
| 3791 | |
| 3792 | rc = mdss_dsi_validate_config(pdev); |
| 3793 | if (rc) { |
| 3794 | pr_err("%s: Invalid DSI hw configuration\n", __func__); |
| 3795 | goto error; |
| 3796 | } |
| 3797 | |
| 3798 | mdss_dsi_config_clk_src(pdev); |
| 3799 | |
| 3800 | error: |
| 3801 | return rc; |
| 3802 | } |
| 3803 | |
| 3804 | static int mdss_dsi_remove(struct platform_device *pdev) |
| 3805 | { |
| 3806 | mdss_dsi_res_deinit(pdev); |
| 3807 | return 0; |
| 3808 | } |
| 3809 | |
| 3810 | static int mdss_dsi_ctrl_remove(struct platform_device *pdev) |
| 3811 | { |
| 3812 | struct msm_fb_data_type *mfd; |
| 3813 | struct mdss_dsi_ctrl_pdata *ctrl_pdata = platform_get_drvdata(pdev); |
| 3814 | |
| 3815 | if (!ctrl_pdata) { |
| 3816 | pr_err("%s: no driver data\n", __func__); |
| 3817 | return -ENODEV; |
| 3818 | } |
| 3819 | |
| 3820 | mdss_dsi_pm_qos_remove_request(ctrl_pdata->shared_data); |
| 3821 | |
Sachin Bhayare | 5076e25 | 2018-01-18 14:56:45 +0530 | [diff] [blame] | 3822 | if (msm_mdss_config_vreg(&pdev->dev, |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 3823 | ctrl_pdata->panel_power_data.vreg_config, |
| 3824 | ctrl_pdata->panel_power_data.num_vreg, 1) < 0) |
| 3825 | pr_err("%s: failed to de-init vregs for %s\n", |
| 3826 | __func__, __mdss_dsi_pm_name(DSI_PANEL_PM)); |
| 3827 | mdss_dsi_put_dt_vreg_data(&pdev->dev, &ctrl_pdata->panel_power_data); |
| 3828 | |
| 3829 | mfd = platform_get_drvdata(pdev); |
Sachin Bhayare | 5076e25 | 2018-01-18 14:56:45 +0530 | [diff] [blame] | 3830 | msm_mdss_iounmap(&ctrl_pdata->mmss_misc_io); |
| 3831 | msm_mdss_iounmap(&ctrl_pdata->phy_io); |
| 3832 | msm_mdss_iounmap(&ctrl_pdata->ctrl_io); |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 3833 | mdss_dsi_debugfs_cleanup(ctrl_pdata); |
| 3834 | |
| 3835 | if (ctrl_pdata->workq) |
| 3836 | destroy_workqueue(ctrl_pdata->workq); |
| 3837 | |
| 3838 | return 0; |
| 3839 | } |
| 3840 | |
| 3841 | struct device dsi_dev; |
| 3842 | |
| 3843 | int mdss_dsi_retrieve_ctrl_resources(struct platform_device *pdev, int mode, |
| 3844 | struct mdss_dsi_ctrl_pdata *ctrl) |
| 3845 | { |
| 3846 | int rc = 0; |
| 3847 | u32 index; |
| 3848 | |
| 3849 | rc = of_property_read_u32(pdev->dev.of_node, "cell-index", &index); |
| 3850 | if (rc) { |
| 3851 | dev_err(&pdev->dev, |
| 3852 | "%s: Cell-index not specified, rc=%d\n", |
| 3853 | __func__, rc); |
| 3854 | return rc; |
| 3855 | } |
| 3856 | |
| 3857 | if (index == 0) { |
| 3858 | if (mode != DISPLAY_1) { |
| 3859 | pr_err("%s:%d Panel->Ctrl mapping is wrong\n", |
| 3860 | __func__, __LINE__); |
| 3861 | return -EPERM; |
| 3862 | } |
| 3863 | } else if (index == 1) { |
| 3864 | if (mode != DISPLAY_2) { |
| 3865 | pr_err("%s:%d Panel->Ctrl mapping is wrong\n", |
| 3866 | __func__, __LINE__); |
| 3867 | return -EPERM; |
| 3868 | } |
| 3869 | } else { |
| 3870 | pr_err("%s:%d Unknown Ctrl mapped to panel\n", |
| 3871 | __func__, __LINE__); |
| 3872 | return -EPERM; |
| 3873 | } |
| 3874 | |
Sachin Bhayare | 5076e25 | 2018-01-18 14:56:45 +0530 | [diff] [blame] | 3875 | rc = msm_mdss_ioremap_byname(pdev, &ctrl->ctrl_io, "dsi_ctrl"); |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 3876 | if (rc) { |
| 3877 | pr_err("%s:%d unable to remap dsi ctrl resources\n", |
| 3878 | __func__, __LINE__); |
| 3879 | return rc; |
| 3880 | } |
| 3881 | |
| 3882 | ctrl->ctrl_base = ctrl->ctrl_io.base; |
| 3883 | ctrl->reg_size = ctrl->ctrl_io.len; |
| 3884 | |
Sachin Bhayare | 5076e25 | 2018-01-18 14:56:45 +0530 | [diff] [blame] | 3885 | rc = msm_mdss_ioremap_byname(pdev, &ctrl->phy_io, "dsi_phy"); |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 3886 | if (rc) { |
| 3887 | pr_err("%s:%d unable to remap dsi phy resources\n", |
| 3888 | __func__, __LINE__); |
| 3889 | return rc; |
| 3890 | } |
| 3891 | |
Sachin Bhayare | 5076e25 | 2018-01-18 14:56:45 +0530 | [diff] [blame] | 3892 | rc = msm_mdss_ioremap_byname(pdev, &ctrl->phy_regulator_io, |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 3893 | "dsi_phy_regulator"); |
| 3894 | if (rc) |
| 3895 | pr_debug("%s:%d unable to remap dsi phy regulator resources\n", |
| 3896 | __func__, __LINE__); |
| 3897 | else |
| 3898 | pr_info("%s: phy_regulator_base=%pK phy_regulator_size=%x\n", |
| 3899 | __func__, ctrl->phy_regulator_io.base, |
| 3900 | ctrl->phy_regulator_io.len); |
| 3901 | |
| 3902 | pr_info("%s: ctrl_base=%pK ctrl_size=%x phy_base=%pK phy_size=%x\n", |
| 3903 | __func__, ctrl->ctrl_base, ctrl->reg_size, ctrl->phy_io.base, |
| 3904 | ctrl->phy_io.len); |
| 3905 | |
Sachin Bhayare | 5076e25 | 2018-01-18 14:56:45 +0530 | [diff] [blame] | 3906 | rc = msm_mdss_ioremap_byname(pdev, &ctrl->mmss_misc_io, |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 3907 | "mmss_misc_phys"); |
| 3908 | if (rc) { |
| 3909 | pr_debug("%s:%d mmss_misc IO remap failed\n", |
| 3910 | __func__, __LINE__); |
| 3911 | } |
| 3912 | |
| 3913 | return 0; |
| 3914 | } |
| 3915 | |
| 3916 | static int mdss_dsi_irq_init(struct device *dev, int irq_no, |
| 3917 | struct mdss_dsi_ctrl_pdata *ctrl) |
| 3918 | { |
| 3919 | int ret; |
| 3920 | |
| 3921 | ret = devm_request_irq(dev, irq_no, mdss_dsi_isr, |
Sachin Bhayare | 3d3767e | 2018-01-02 21:10:57 +0530 | [diff] [blame] | 3922 | 0, "DSI", ctrl); |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 3923 | if (ret) { |
| 3924 | pr_err("msm_dsi_irq_init request_irq() failed!\n"); |
| 3925 | return ret; |
| 3926 | } |
| 3927 | |
| 3928 | disable_irq(irq_no); |
| 3929 | ctrl->dsi_hw->irq_info = kcalloc(1, sizeof(struct irq_info), |
| 3930 | GFP_KERNEL); |
| 3931 | if (!ctrl->dsi_hw->irq_info) |
| 3932 | return -ENOMEM; |
| 3933 | |
| 3934 | ctrl->dsi_hw->irq_info->irq = irq_no; |
| 3935 | ctrl->dsi_hw->irq_info->irq_ena = false; |
| 3936 | |
| 3937 | return ret; |
| 3938 | } |
| 3939 | |
| 3940 | static void mdss_dsi_parse_lane_swap(struct device_node *np, char *dlane_swap) |
| 3941 | { |
| 3942 | const char *data; |
| 3943 | |
| 3944 | *dlane_swap = DSI_LANE_MAP_0123; |
| 3945 | data = of_get_property(np, "qcom,lane-map", NULL); |
| 3946 | if (data) { |
| 3947 | if (!strcmp(data, "lane_map_3012")) |
| 3948 | *dlane_swap = DSI_LANE_MAP_3012; |
| 3949 | else if (!strcmp(data, "lane_map_2301")) |
| 3950 | *dlane_swap = DSI_LANE_MAP_2301; |
| 3951 | else if (!strcmp(data, "lane_map_1230")) |
| 3952 | *dlane_swap = DSI_LANE_MAP_1230; |
| 3953 | else if (!strcmp(data, "lane_map_0321")) |
| 3954 | *dlane_swap = DSI_LANE_MAP_0321; |
| 3955 | else if (!strcmp(data, "lane_map_1032")) |
| 3956 | *dlane_swap = DSI_LANE_MAP_1032; |
| 3957 | else if (!strcmp(data, "lane_map_2103")) |
| 3958 | *dlane_swap = DSI_LANE_MAP_2103; |
| 3959 | else if (!strcmp(data, "lane_map_3210")) |
| 3960 | *dlane_swap = DSI_LANE_MAP_3210; |
| 3961 | } |
| 3962 | } |
| 3963 | |
| 3964 | static int mdss_dsi_parse_ctrl_params(struct platform_device *ctrl_pdev, |
| 3965 | struct device_node *pan_node, struct mdss_dsi_ctrl_pdata *ctrl_pdata) |
| 3966 | { |
| 3967 | int i, len; |
| 3968 | struct mdss_panel_info *pinfo = &(ctrl_pdata->panel_data.panel_info); |
| 3969 | const char *data; |
| 3970 | |
| 3971 | ctrl_pdata->null_insert_enabled = of_property_read_bool( |
| 3972 | ctrl_pdev->dev.of_node, "qcom,null-insertion-enabled"); |
| 3973 | |
| 3974 | data = of_get_property(ctrl_pdev->dev.of_node, |
| 3975 | "qcom,platform-strength-ctrl", &len); |
| 3976 | if (!data) { |
| 3977 | pr_err("%s:%d, Unable to read Phy Strength ctrl settings\n", |
| 3978 | __func__, __LINE__); |
Padmanabhan Komanduru | 81d8dc52 | 2018-03-22 20:00:58 +0530 | [diff] [blame^] | 3979 | } else { |
| 3980 | pinfo->mipi.dsi_phy_db.strength_len = len; |
| 3981 | for (i = 0; i < len; i++) |
| 3982 | pinfo->mipi.dsi_phy_db.strength[i] = data[i]; |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 3983 | } |
| 3984 | |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 3985 | pinfo->mipi.dsi_phy_db.reg_ldo_mode = of_property_read_bool( |
| 3986 | ctrl_pdev->dev.of_node, "qcom,regulator-ldo-mode"); |
| 3987 | |
| 3988 | data = of_get_property(ctrl_pdev->dev.of_node, |
| 3989 | "qcom,platform-regulator-settings", &len); |
| 3990 | if (!data) { |
| 3991 | pr_err("%s:%d, Unable to read Phy regulator settings\n", |
| 3992 | __func__, __LINE__); |
Padmanabhan Komanduru | 81d8dc52 | 2018-03-22 20:00:58 +0530 | [diff] [blame^] | 3993 | } else { |
| 3994 | pinfo->mipi.dsi_phy_db.regulator_len = len; |
| 3995 | for (i = 0; i < len; i++) |
| 3996 | pinfo->mipi.dsi_phy_db.regulator[i] = data[i]; |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 3997 | } |
| 3998 | |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 3999 | data = of_get_property(ctrl_pdev->dev.of_node, |
| 4000 | "qcom,platform-bist-ctrl", &len); |
| 4001 | if ((!data) || (len != 6)) |
| 4002 | pr_debug("%s:%d, Unable to read Phy Bist Ctrl settings\n", |
| 4003 | __func__, __LINE__); |
| 4004 | else |
| 4005 | for (i = 0; i < len; i++) |
| 4006 | pinfo->mipi.dsi_phy_db.bistctrl[i] = data[i]; |
| 4007 | |
| 4008 | data = of_get_property(ctrl_pdev->dev.of_node, |
| 4009 | "qcom,platform-lane-config", &len); |
| 4010 | if (!data) { |
| 4011 | pr_err("%s:%d, Unable to read Phy lane configure settings\n", |
| 4012 | __func__, __LINE__); |
Padmanabhan Komanduru | 81d8dc52 | 2018-03-22 20:00:58 +0530 | [diff] [blame^] | 4013 | } else { |
| 4014 | pinfo->mipi.dsi_phy_db.lanecfg_len = len; |
| 4015 | for (i = 0; i < len; i++) |
| 4016 | pinfo->mipi.dsi_phy_db.lanecfg[i] = data[i]; |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 4017 | } |
| 4018 | |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 4019 | ctrl_pdata->timing_db_mode = of_property_read_bool( |
| 4020 | ctrl_pdev->dev.of_node, "qcom,timing-db-mode"); |
| 4021 | |
| 4022 | ctrl_pdata->cmd_sync_wait_broadcast = of_property_read_bool( |
| 4023 | pan_node, "qcom,cmd-sync-wait-broadcast"); |
| 4024 | |
| 4025 | if (ctrl_pdata->cmd_sync_wait_broadcast && |
| 4026 | mdss_dsi_is_hw_config_split(ctrl_pdata->shared_data) && |
| 4027 | (pinfo->pdest == DISPLAY_2)) |
| 4028 | ctrl_pdata->cmd_sync_wait_trigger = true; |
| 4029 | |
| 4030 | pr_debug("%s: cmd_sync_wait_enable=%d trigger=%d\n", __func__, |
| 4031 | ctrl_pdata->cmd_sync_wait_broadcast, |
| 4032 | ctrl_pdata->cmd_sync_wait_trigger); |
| 4033 | |
| 4034 | mdss_dsi_parse_lane_swap(ctrl_pdev->dev.of_node, |
| 4035 | &(ctrl_pdata->dlane_swap)); |
| 4036 | |
| 4037 | pinfo->is_pluggable = of_property_read_bool(ctrl_pdev->dev.of_node, |
| 4038 | "qcom,pluggable"); |
| 4039 | |
| 4040 | data = of_get_property(ctrl_pdev->dev.of_node, |
| 4041 | "qcom,display-id", &len); |
| 4042 | if (!data || len <= 0) |
| 4043 | pr_err("%s:%d Unable to read qcom,display-id, data=%pK,len=%d\n", |
| 4044 | __func__, __LINE__, data, len); |
| 4045 | else |
| 4046 | snprintf(ctrl_pdata->panel_data.panel_info.display_id, |
| 4047 | MDSS_DISPLAY_ID_MAX_LEN, "%s", data); |
| 4048 | |
| 4049 | return 0; |
| 4050 | |
| 4051 | |
| 4052 | } |
| 4053 | |
| 4054 | static int mdss_dsi_parse_gpio_params(struct platform_device *ctrl_pdev, |
| 4055 | struct mdss_dsi_ctrl_pdata *ctrl_pdata) |
| 4056 | { |
| 4057 | struct mdss_panel_info *pinfo = &(ctrl_pdata->panel_data.panel_info); |
| 4058 | struct mdss_panel_data *pdata = &ctrl_pdata->panel_data; |
| 4059 | |
| 4060 | /* |
| 4061 | * If disp_en_gpio has been set previously (disp_en_gpio > 0) |
| 4062 | * while parsing the panel node, then do not override it |
| 4063 | */ |
| 4064 | if (ctrl_pdata->disp_en_gpio <= 0) { |
| 4065 | ctrl_pdata->disp_en_gpio = of_get_named_gpio( |
| 4066 | ctrl_pdev->dev.of_node, |
| 4067 | "qcom,platform-enable-gpio", 0); |
| 4068 | |
| 4069 | if (!gpio_is_valid(ctrl_pdata->disp_en_gpio)) |
| 4070 | pr_debug("%s:%d, Disp_en gpio not specified\n", |
| 4071 | __func__, __LINE__); |
| 4072 | } |
| 4073 | |
| 4074 | ctrl_pdata->disp_te_gpio = of_get_named_gpio(ctrl_pdev->dev.of_node, |
| 4075 | "qcom,platform-te-gpio", 0); |
| 4076 | |
| 4077 | if (!gpio_is_valid(ctrl_pdata->disp_te_gpio)) |
| 4078 | pr_err("%s:%d, TE gpio not specified\n", |
| 4079 | __func__, __LINE__); |
| 4080 | pdata->panel_te_gpio = ctrl_pdata->disp_te_gpio; |
| 4081 | |
| 4082 | ctrl_pdata->bklt_en_gpio = of_get_named_gpio(ctrl_pdev->dev.of_node, |
| 4083 | "qcom,platform-bklight-en-gpio", 0); |
| 4084 | if (!gpio_is_valid(ctrl_pdata->bklt_en_gpio)) |
| 4085 | pr_info("%s: bklt_en gpio not specified\n", __func__); |
| 4086 | |
| 4087 | ctrl_pdata->rst_gpio = of_get_named_gpio(ctrl_pdev->dev.of_node, |
| 4088 | "qcom,platform-reset-gpio", 0); |
| 4089 | if (!gpio_is_valid(ctrl_pdata->rst_gpio)) |
| 4090 | pr_err("%s:%d, reset gpio not specified\n", |
| 4091 | __func__, __LINE__); |
| 4092 | |
| 4093 | if (pinfo->mode_gpio_state != MODE_GPIO_NOT_VALID) { |
| 4094 | |
| 4095 | ctrl_pdata->mode_gpio = of_get_named_gpio( |
| 4096 | ctrl_pdev->dev.of_node, |
| 4097 | "qcom,platform-mode-gpio", 0); |
| 4098 | if (!gpio_is_valid(ctrl_pdata->mode_gpio)) |
| 4099 | pr_info("%s:%d, mode gpio not specified\n", |
| 4100 | __func__, __LINE__); |
| 4101 | } else { |
| 4102 | ctrl_pdata->mode_gpio = -EINVAL; |
| 4103 | } |
| 4104 | |
| 4105 | ctrl_pdata->intf_mux_gpio = of_get_named_gpio(ctrl_pdev->dev.of_node, |
| 4106 | "qcom,platform-intf-mux-gpio", 0); |
| 4107 | if (!gpio_is_valid(ctrl_pdata->intf_mux_gpio)) |
| 4108 | pr_debug("%s:%d, intf mux gpio not specified\n", |
| 4109 | __func__, __LINE__); |
| 4110 | |
| 4111 | return 0; |
| 4112 | } |
| 4113 | |
| 4114 | static void mdss_dsi_set_prim_panel(struct mdss_dsi_ctrl_pdata *ctrl_pdata) |
| 4115 | { |
| 4116 | struct mdss_dsi_ctrl_pdata *octrl = NULL; |
| 4117 | struct mdss_panel_info *pinfo; |
| 4118 | |
| 4119 | pinfo = &ctrl_pdata->panel_data.panel_info; |
| 4120 | |
| 4121 | /* |
| 4122 | * for Split and Single DSI case default is always primary |
| 4123 | * and for Dual dsi case below assumptions are made. |
| 4124 | * 1. DSI controller with bridge chip is always secondary |
| 4125 | * 2. When there is no brigde chip, DSI1 is secondary |
| 4126 | */ |
| 4127 | pinfo->is_prim_panel = true; |
| 4128 | if (mdss_dsi_is_hw_config_dual(ctrl_pdata->shared_data)) { |
| 4129 | if (mdss_dsi_is_right_ctrl(ctrl_pdata)) { |
| 4130 | octrl = mdss_dsi_get_other_ctrl(ctrl_pdata); |
| 4131 | if (octrl && octrl->panel_data.panel_info.is_prim_panel) |
| 4132 | pinfo->is_prim_panel = false; |
| 4133 | else |
| 4134 | pinfo->is_prim_panel = true; |
| 4135 | } |
| 4136 | } |
| 4137 | } |
| 4138 | |
| 4139 | int dsi_panel_device_register(struct platform_device *ctrl_pdev, |
| 4140 | struct device_node *pan_node, struct mdss_dsi_ctrl_pdata *ctrl_pdata) |
| 4141 | { |
| 4142 | struct mipi_panel_info *mipi; |
| 4143 | int rc; |
| 4144 | struct dsi_shared_data *sdata; |
| 4145 | struct mdss_panel_info *pinfo = &(ctrl_pdata->panel_data.panel_info); |
| 4146 | struct resource *res; |
| 4147 | u64 clk_rate; |
| 4148 | |
| 4149 | mipi = &(pinfo->mipi); |
| 4150 | |
| 4151 | pinfo->type = |
| 4152 | ((mipi->mode == DSI_VIDEO_MODE) |
| 4153 | ? MIPI_VIDEO_PANEL : MIPI_CMD_PANEL); |
| 4154 | |
| 4155 | rc = mdss_dsi_clk_div_config(pinfo, mipi->frame_rate); |
| 4156 | if (rc) { |
| 4157 | pr_err("%s: unable to initialize the clk dividers\n", __func__); |
| 4158 | return rc; |
| 4159 | } |
| 4160 | ctrl_pdata->pclk_rate = mipi->dsi_pclk_rate; |
| 4161 | clk_rate = pinfo->clk_rate; |
| 4162 | do_div(clk_rate, 8U); |
| 4163 | ctrl_pdata->byte_clk_rate = (u32)clk_rate; |
| 4164 | pr_debug("%s: pclk=%d, bclk=%d\n", __func__, |
| 4165 | ctrl_pdata->pclk_rate, ctrl_pdata->byte_clk_rate); |
| 4166 | |
| 4167 | |
| 4168 | rc = mdss_dsi_get_dt_vreg_data(&ctrl_pdev->dev, pan_node, |
| 4169 | &ctrl_pdata->panel_power_data, DSI_PANEL_PM); |
| 4170 | if (rc) { |
| 4171 | DEV_ERR("%s: '%s' get_dt_vreg_data failed.rc=%d\n", |
| 4172 | __func__, __mdss_dsi_pm_name(DSI_PANEL_PM), rc); |
| 4173 | return rc; |
| 4174 | } |
| 4175 | |
Sachin Bhayare | 5076e25 | 2018-01-18 14:56:45 +0530 | [diff] [blame] | 4176 | rc = msm_mdss_config_vreg(&ctrl_pdev->dev, |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 4177 | ctrl_pdata->panel_power_data.vreg_config, |
| 4178 | ctrl_pdata->panel_power_data.num_vreg, 1); |
| 4179 | if (rc) { |
| 4180 | pr_err("%s: failed to init regulator, rc=%d\n", |
| 4181 | __func__, rc); |
| 4182 | return rc; |
| 4183 | } |
| 4184 | |
| 4185 | rc = mdss_dsi_parse_ctrl_params(ctrl_pdev, pan_node, ctrl_pdata); |
| 4186 | if (rc) { |
| 4187 | pr_err("%s: failed to parse ctrl settings, rc=%d\n", |
| 4188 | __func__, rc); |
| 4189 | return rc; |
| 4190 | } |
| 4191 | |
| 4192 | pinfo->panel_max_fps = mdss_panel_get_framerate(pinfo, |
| 4193 | FPS_RESOLUTION_HZ); |
| 4194 | pinfo->panel_max_vtotal = mdss_panel_get_vtotal(pinfo); |
| 4195 | |
| 4196 | rc = mdss_dsi_parse_gpio_params(ctrl_pdev, ctrl_pdata); |
| 4197 | if (rc) { |
| 4198 | pr_err("%s: failed to parse gpio params, rc=%d\n", |
| 4199 | __func__, rc); |
| 4200 | return rc; |
| 4201 | } |
| 4202 | |
| 4203 | if (mdss_dsi_retrieve_ctrl_resources(ctrl_pdev, |
| 4204 | pinfo->pdest, |
| 4205 | ctrl_pdata)) { |
| 4206 | pr_err("%s: unable to get Dsi controller res\n", __func__); |
| 4207 | return -EPERM; |
| 4208 | } |
| 4209 | |
| 4210 | ctrl_pdata->panel_data.event_handler = mdss_dsi_event_handler; |
| 4211 | ctrl_pdata->panel_data.get_fb_node = mdss_dsi_get_fb_node_cb; |
| 4212 | |
| 4213 | if (ctrl_pdata->status_mode == ESD_REG || |
| 4214 | ctrl_pdata->status_mode == ESD_REG_NT35596) |
| 4215 | ctrl_pdata->check_status = mdss_dsi_reg_status_check; |
| 4216 | else if (ctrl_pdata->status_mode == ESD_BTA) |
| 4217 | ctrl_pdata->check_status = mdss_dsi_bta_status_check; |
| 4218 | |
| 4219 | if (ctrl_pdata->status_mode == ESD_MAX) { |
| 4220 | pr_err("%s: Using default BTA for ESD check\n", __func__); |
| 4221 | ctrl_pdata->check_status = mdss_dsi_bta_status_check; |
| 4222 | } |
| 4223 | if (ctrl_pdata->bklt_ctrl == BL_PWM) |
| 4224 | mdss_dsi_panel_pwm_cfg(ctrl_pdata); |
| 4225 | |
| 4226 | mdss_dsi_ctrl_init(&ctrl_pdev->dev, ctrl_pdata); |
| 4227 | mdss_dsi_set_prim_panel(ctrl_pdata); |
| 4228 | |
| 4229 | ctrl_pdata->dsi_irq_line = of_property_read_bool( |
| 4230 | ctrl_pdev->dev.of_node, "qcom,dsi-irq-line"); |
| 4231 | |
| 4232 | if (ctrl_pdata->dsi_irq_line) { |
| 4233 | /* DSI has it's own irq line */ |
| 4234 | res = platform_get_resource(ctrl_pdev, IORESOURCE_IRQ, 0); |
| 4235 | if (!res || res->start == 0) { |
| 4236 | pr_err("%s:%d unable to get the MDSS irq resources\n", |
| 4237 | __func__, __LINE__); |
| 4238 | return -ENODEV; |
| 4239 | } |
| 4240 | rc = mdss_dsi_irq_init(&ctrl_pdev->dev, res->start, ctrl_pdata); |
| 4241 | if (rc) { |
| 4242 | dev_err(&ctrl_pdev->dev, "%s: failed to init irq\n", |
| 4243 | __func__); |
| 4244 | return rc; |
| 4245 | } |
| 4246 | } |
| 4247 | ctrl_pdata->ctrl_state = CTRL_STATE_UNKNOWN; |
| 4248 | |
| 4249 | /* |
| 4250 | * If ULPS during suspend is enabled, add an extra vote for the |
| 4251 | * DSI CTRL power module. This keeps the regulator always enabled. |
| 4252 | * This is needed for the DSI PHY to maintain ULPS state during |
| 4253 | * suspend also. |
| 4254 | */ |
| 4255 | sdata = ctrl_pdata->shared_data; |
| 4256 | |
| 4257 | if (pinfo->ulps_suspend_enabled) { |
Sachin Bhayare | 5076e25 | 2018-01-18 14:56:45 +0530 | [diff] [blame] | 4258 | rc = msm_mdss_enable_vreg( |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 4259 | sdata->power_data[DSI_PHY_PM].vreg_config, |
| 4260 | sdata->power_data[DSI_PHY_PM].num_vreg, 1); |
| 4261 | if (rc) { |
| 4262 | pr_err("%s: failed to enable vregs for DSI_CTRL_PM\n", |
| 4263 | __func__); |
| 4264 | return rc; |
| 4265 | } |
| 4266 | } |
| 4267 | |
| 4268 | pinfo->cont_splash_enabled = |
| 4269 | ctrl_pdata->mdss_util->panel_intf_status(pinfo->pdest, |
| 4270 | MDSS_PANEL_INTF_DSI) ? true : false; |
| 4271 | |
| 4272 | pr_info("%s: Continuous splash %s\n", __func__, |
| 4273 | pinfo->cont_splash_enabled ? "enabled" : "disabled"); |
| 4274 | |
| 4275 | rc = mdss_register_panel(ctrl_pdev, &(ctrl_pdata->panel_data)); |
| 4276 | if (rc) { |
| 4277 | pr_err("%s: unable to register MIPI DSI panel\n", __func__); |
| 4278 | return rc; |
| 4279 | } |
| 4280 | |
| 4281 | if (pinfo->pdest == DISPLAY_1) { |
| 4282 | mdss_debug_register_io("dsi0_ctrl", &ctrl_pdata->ctrl_io, NULL); |
| 4283 | mdss_debug_register_io("dsi0_phy", &ctrl_pdata->phy_io, NULL); |
| 4284 | if (ctrl_pdata->phy_regulator_io.len) |
| 4285 | mdss_debug_register_io("dsi0_phy_regulator", |
| 4286 | &ctrl_pdata->phy_regulator_io, NULL); |
| 4287 | } else { |
| 4288 | mdss_debug_register_io("dsi1_ctrl", &ctrl_pdata->ctrl_io, NULL); |
| 4289 | mdss_debug_register_io("dsi1_phy", &ctrl_pdata->phy_io, NULL); |
| 4290 | if (ctrl_pdata->phy_regulator_io.len) |
| 4291 | mdss_debug_register_io("dsi1_phy_regulator", |
| 4292 | &ctrl_pdata->phy_regulator_io, NULL); |
| 4293 | } |
| 4294 | |
| 4295 | panel_debug_register_base("panel", |
| 4296 | ctrl_pdata->ctrl_base, ctrl_pdata->reg_size); |
| 4297 | |
| 4298 | pr_debug("%s: Panel data initialized\n", __func__); |
| 4299 | return 0; |
| 4300 | } |
| 4301 | |
| 4302 | static const struct of_device_id mdss_dsi_dt_match[] = { |
| 4303 | {.compatible = "qcom,mdss-dsi"}, |
| 4304 | {} |
| 4305 | }; |
| 4306 | MODULE_DEVICE_TABLE(of, mdss_dsi_dt_match); |
| 4307 | |
| 4308 | static struct platform_driver mdss_dsi_driver = { |
| 4309 | .probe = mdss_dsi_probe, |
| 4310 | .remove = mdss_dsi_remove, |
| 4311 | .shutdown = NULL, |
| 4312 | .driver = { |
| 4313 | .name = "mdss_dsi", |
| 4314 | .of_match_table = mdss_dsi_dt_match, |
| 4315 | }, |
| 4316 | }; |
| 4317 | |
| 4318 | static struct platform_driver mdss_dsi_ctrl_driver = { |
| 4319 | .probe = mdss_dsi_ctrl_probe, |
| 4320 | .remove = mdss_dsi_ctrl_remove, |
| 4321 | .shutdown = NULL, |
| 4322 | .driver = { |
| 4323 | .name = "mdss_dsi_ctrl", |
| 4324 | .of_match_table = mdss_dsi_ctrl_dt_match, |
| 4325 | }, |
| 4326 | }; |
| 4327 | |
| 4328 | static int mdss_dsi_register_driver(void) |
| 4329 | { |
| 4330 | return platform_driver_register(&mdss_dsi_driver); |
| 4331 | } |
| 4332 | |
| 4333 | static int __init mdss_dsi_driver_init(void) |
| 4334 | { |
| 4335 | int ret; |
| 4336 | |
| 4337 | ret = mdss_dsi_register_driver(); |
| 4338 | if (ret) { |
| 4339 | pr_err("mdss_dsi_register_driver() failed!\n"); |
| 4340 | return ret; |
| 4341 | } |
| 4342 | |
| 4343 | return ret; |
| 4344 | } |
| 4345 | module_init(mdss_dsi_driver_init); |
| 4346 | |
| 4347 | |
| 4348 | static int mdss_dsi_ctrl_register_driver(void) |
| 4349 | { |
| 4350 | return platform_driver_register(&mdss_dsi_ctrl_driver); |
| 4351 | } |
| 4352 | |
| 4353 | static int __init mdss_dsi_ctrl_driver_init(void) |
| 4354 | { |
| 4355 | int ret; |
| 4356 | |
| 4357 | ret = mdss_dsi_ctrl_register_driver(); |
| 4358 | if (ret) { |
| 4359 | pr_err("mdss_dsi_ctrl_register_driver() failed!\n"); |
| 4360 | return ret; |
| 4361 | } |
| 4362 | |
| 4363 | return ret; |
| 4364 | } |
| 4365 | module_init(mdss_dsi_ctrl_driver_init); |
| 4366 | |
| 4367 | static void __exit mdss_dsi_driver_cleanup(void) |
| 4368 | { |
| 4369 | platform_driver_unregister(&mdss_dsi_ctrl_driver); |
| 4370 | } |
| 4371 | module_exit(mdss_dsi_driver_cleanup); |
| 4372 | |
| 4373 | MODULE_LICENSE("GPL v2"); |
| 4374 | MODULE_DESCRIPTION("DSI controller driver"); |