Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Core MDSS framebuffer driver. |
| 3 | * |
| 4 | * Copyright (C) 2007 Google Incorporated |
| 5 | * Copyright (c) 2008-2018, The Linux Foundation. All rights reserved. |
| 6 | * |
| 7 | * This software is licensed under the terms of the GNU General Public |
| 8 | * License version 2, as published by the Free Software Foundation, and |
| 9 | * may be copied, distributed, and modified under those terms. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | */ |
| 16 | |
| 17 | #define pr_fmt(fmt) "%s: " fmt, __func__ |
| 18 | |
| 19 | #include <linux/videodev2.h> |
| 20 | #include <linux/bootmem.h> |
| 21 | #include <linux/console.h> |
| 22 | #include <linux/debugfs.h> |
| 23 | #include <linux/delay.h> |
| 24 | #include <linux/device.h> |
| 25 | #include <linux/dma-mapping.h> |
| 26 | #include <linux/dma-buf.h> |
| 27 | #include <linux/fb.h> |
| 28 | #include <linux/init.h> |
| 29 | #include <linux/ioport.h> |
| 30 | #include <linux/kernel.h> |
| 31 | #include <linux/memory.h> |
| 32 | #include <linux/mm.h> |
| 33 | #include <linux/module.h> |
| 34 | #include <linux/moduleparam.h> |
| 35 | #include <linux/msm_mdp.h> |
| 36 | #include <linux/of.h> |
| 37 | #include <linux/of_address.h> |
| 38 | #include <linux/of_platform.h> |
| 39 | #include <linux/proc_fs.h> |
| 40 | #include <linux/pm_runtime.h> |
| 41 | #include <linux/slab.h> |
| 42 | #include <linux/string.h> |
| 43 | #include <linux/uaccess.h> |
| 44 | #include <linux/version.h> |
| 45 | #include <linux/vmalloc.h> |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 46 | #include <linux/file.h> |
| 47 | #include <linux/kthread.h> |
| 48 | #include <linux/dma-buf.h> |
| 49 | #include "mdss_fb.h" |
| 50 | #include "mdss_mdp_splash_logo.h" |
| 51 | #define CREATE_TRACE_POINTS |
| 52 | #include "mdss_debug.h" |
| 53 | #include "mdss_smmu.h" |
| 54 | #include "mdss_mdp.h" |
| 55 | #include "mdp3_ctrl.h" |
Sachin Bhayare | 2b6d004 | 2018-01-13 19:38:21 +0530 | [diff] [blame] | 56 | #include "mdss_sync.h" |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 57 | |
| 58 | #ifdef CONFIG_FB_MSM_TRIPLE_BUFFER |
| 59 | #define MDSS_FB_NUM 3 |
| 60 | #else |
| 61 | #define MDSS_FB_NUM 2 |
| 62 | #endif |
| 63 | |
| 64 | #ifndef EXPORT_COMPAT |
| 65 | #define EXPORT_COMPAT(x) |
| 66 | #endif |
| 67 | |
| 68 | #define MAX_FBI_LIST 32 |
| 69 | |
| 70 | #ifndef TARGET_HW_MDSS_MDP3 |
| 71 | #define BLANK_FLAG_LP FB_BLANK_NORMAL |
| 72 | #define BLANK_FLAG_ULP FB_BLANK_VSYNC_SUSPEND |
| 73 | #else |
| 74 | #define BLANK_FLAG_LP FB_BLANK_VSYNC_SUSPEND |
| 75 | #define BLANK_FLAG_ULP FB_BLANK_NORMAL |
| 76 | #endif |
| 77 | |
| 78 | /* |
| 79 | * Time period for fps calulation in micro seconds. |
| 80 | * Default value is set to 1 sec. |
| 81 | */ |
| 82 | #define MDP_TIME_PERIOD_CALC_FPS_US 1000000 |
| 83 | |
| 84 | static struct fb_info *fbi_list[MAX_FBI_LIST]; |
| 85 | static int fbi_list_index; |
| 86 | |
| 87 | static u32 mdss_fb_pseudo_palette[16] = { |
| 88 | 0x00000000, 0xffffffff, 0xffffffff, 0xffffffff, |
| 89 | 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, |
| 90 | 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, |
| 91 | 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff |
| 92 | }; |
| 93 | |
| 94 | static struct msm_mdp_interface *mdp_instance; |
| 95 | |
| 96 | static int mdss_fb_register(struct msm_fb_data_type *mfd); |
| 97 | static int mdss_fb_open(struct fb_info *info, int user); |
| 98 | static int mdss_fb_release(struct fb_info *info, int user); |
| 99 | static int mdss_fb_release_all(struct fb_info *info, bool release_all); |
| 100 | static int mdss_fb_pan_display(struct fb_var_screeninfo *var, |
| 101 | struct fb_info *info); |
| 102 | static int mdss_fb_check_var(struct fb_var_screeninfo *var, |
| 103 | struct fb_info *info); |
| 104 | static int mdss_fb_set_par(struct fb_info *info); |
| 105 | static int mdss_fb_blank_sub(int blank_mode, struct fb_info *info, |
| 106 | int op_enable); |
| 107 | static int mdss_fb_suspend_sub(struct msm_fb_data_type *mfd); |
| 108 | static int mdss_fb_ioctl(struct fb_info *info, unsigned int cmd, |
| 109 | unsigned long arg, struct file *file); |
| 110 | static int mdss_fb_fbmem_ion_mmap(struct fb_info *info, |
| 111 | struct vm_area_struct *vma); |
| 112 | static int mdss_fb_alloc_fb_ion_memory(struct msm_fb_data_type *mfd, |
| 113 | size_t size); |
| 114 | static void mdss_fb_release_fences(struct msm_fb_data_type *mfd); |
| 115 | static int __mdss_fb_sync_buf_done_callback(struct notifier_block *p, |
| 116 | unsigned long val, void *data); |
| 117 | |
| 118 | static int __mdss_fb_display_thread(void *data); |
| 119 | static int mdss_fb_pan_idle(struct msm_fb_data_type *mfd); |
| 120 | static int mdss_fb_send_panel_event(struct msm_fb_data_type *mfd, |
| 121 | int event, void *arg); |
| 122 | static void mdss_fb_set_mdp_sync_pt_threshold(struct msm_fb_data_type *mfd, |
| 123 | int type); |
| 124 | void mdss_fb_no_update_notify_timer_cb(unsigned long data) |
| 125 | { |
| 126 | struct msm_fb_data_type *mfd = (struct msm_fb_data_type *)data; |
| 127 | |
| 128 | if (!mfd) { |
| 129 | pr_err("%s mfd NULL\n", __func__); |
| 130 | return; |
| 131 | } |
| 132 | mfd->no_update.value = NOTIFY_TYPE_NO_UPDATE; |
| 133 | complete(&mfd->no_update.comp); |
| 134 | } |
| 135 | |
| 136 | void mdss_fb_bl_update_notify(struct msm_fb_data_type *mfd, |
| 137 | uint32_t notification_type) |
| 138 | { |
| 139 | #ifndef TARGET_HW_MDSS_MDP3 |
| 140 | struct mdss_overlay_private *mdp5_data = NULL; |
| 141 | #endif |
| 142 | #ifdef TARGET_HW_MDSS_MDP3 |
| 143 | struct mdp3_session_data *mdp3_session = NULL; |
| 144 | #endif |
| 145 | if (!mfd) { |
| 146 | pr_err("%s mfd NULL\n", __func__); |
| 147 | return; |
| 148 | } |
| 149 | mutex_lock(&mfd->update.lock); |
| 150 | if (mfd->update.is_suspend) { |
| 151 | mutex_unlock(&mfd->update.lock); |
| 152 | return; |
| 153 | } |
| 154 | if (mfd->update.ref_count > 0) { |
| 155 | mutex_unlock(&mfd->update.lock); |
| 156 | mfd->update.value = notification_type; |
| 157 | complete(&mfd->update.comp); |
| 158 | mutex_lock(&mfd->update.lock); |
| 159 | } |
| 160 | mutex_unlock(&mfd->update.lock); |
| 161 | |
| 162 | mutex_lock(&mfd->no_update.lock); |
| 163 | if (mfd->no_update.ref_count > 0) { |
| 164 | mutex_unlock(&mfd->no_update.lock); |
| 165 | mfd->no_update.value = notification_type; |
| 166 | complete(&mfd->no_update.comp); |
| 167 | mutex_lock(&mfd->no_update.lock); |
| 168 | } |
| 169 | mutex_unlock(&mfd->no_update.lock); |
| 170 | #ifndef TARGET_HW_MDSS_MDP3 |
| 171 | mdp5_data = mfd_to_mdp5_data(mfd); |
| 172 | if (mdp5_data) { |
| 173 | if (notification_type == NOTIFY_TYPE_BL_AD_ATTEN_UPDATE) { |
| 174 | mdp5_data->ad_bl_events++; |
| 175 | sysfs_notify_dirent(mdp5_data->ad_bl_event_sd); |
| 176 | } else if (notification_type == NOTIFY_TYPE_BL_UPDATE) { |
| 177 | mdp5_data->bl_events++; |
| 178 | sysfs_notify_dirent(mdp5_data->bl_event_sd); |
| 179 | } |
| 180 | } |
| 181 | #endif |
| 182 | #ifdef TARGET_HW_MDSS_MDP3 |
| 183 | mdp3_session = (struct mdp3_session_data *)mfd->mdp.private1; |
| 184 | if (mdp3_session) { |
| 185 | mdp3_session->bl_events++; |
| 186 | sysfs_notify_dirent(mdp3_session->bl_event_sd); |
| 187 | pr_debug("bl_event = %u\n", mdp3_session->bl_events); |
| 188 | } |
| 189 | #endif |
| 190 | } |
| 191 | |
| 192 | static int mdss_fb_notify_update(struct msm_fb_data_type *mfd, |
| 193 | unsigned long *argp) |
| 194 | { |
| 195 | int ret; |
| 196 | unsigned int notify = 0x0, to_user = 0x0; |
| 197 | |
| 198 | ret = copy_from_user(¬ify, argp, sizeof(unsigned int)); |
| 199 | if (ret) { |
| 200 | pr_err("%s:ioctl failed\n", __func__); |
| 201 | return ret; |
| 202 | } |
| 203 | |
| 204 | if (notify > NOTIFY_UPDATE_POWER_OFF) |
| 205 | return -EINVAL; |
| 206 | |
| 207 | if (notify == NOTIFY_UPDATE_INIT) { |
| 208 | mutex_lock(&mfd->update.lock); |
| 209 | mfd->update.init_done = true; |
| 210 | mutex_unlock(&mfd->update.lock); |
| 211 | ret = 1; |
| 212 | } else if (notify == NOTIFY_UPDATE_DEINIT) { |
| 213 | mutex_lock(&mfd->update.lock); |
| 214 | mfd->update.init_done = false; |
| 215 | mutex_unlock(&mfd->update.lock); |
| 216 | complete(&mfd->update.comp); |
| 217 | complete(&mfd->no_update.comp); |
| 218 | ret = 1; |
| 219 | } else if (mfd->update.is_suspend) { |
| 220 | to_user = NOTIFY_TYPE_SUSPEND; |
| 221 | mfd->update.is_suspend = 0; |
| 222 | ret = 1; |
| 223 | } else if (notify == NOTIFY_UPDATE_START) { |
| 224 | mutex_lock(&mfd->update.lock); |
| 225 | if (mfd->update.init_done) |
| 226 | reinit_completion(&mfd->update.comp); |
| 227 | else { |
| 228 | mutex_unlock(&mfd->update.lock); |
| 229 | pr_err("notify update start called without init\n"); |
| 230 | return -EINVAL; |
| 231 | } |
| 232 | mfd->update.ref_count++; |
| 233 | mutex_unlock(&mfd->update.lock); |
| 234 | ret = wait_for_completion_interruptible_timeout( |
| 235 | &mfd->update.comp, 4 * HZ); |
| 236 | mutex_lock(&mfd->update.lock); |
| 237 | mfd->update.ref_count--; |
| 238 | mutex_unlock(&mfd->update.lock); |
| 239 | to_user = (unsigned int)mfd->update.value; |
| 240 | if (mfd->update.type == NOTIFY_TYPE_SUSPEND) { |
| 241 | to_user = (unsigned int)mfd->update.type; |
| 242 | ret = 1; |
| 243 | } |
| 244 | } else if (notify == NOTIFY_UPDATE_STOP) { |
| 245 | mutex_lock(&mfd->update.lock); |
| 246 | if (mfd->update.init_done) |
| 247 | reinit_completion(&mfd->no_update.comp); |
| 248 | else { |
| 249 | mutex_unlock(&mfd->update.lock); |
| 250 | pr_err("notify update stop called without init\n"); |
| 251 | return -EINVAL; |
| 252 | } |
| 253 | mfd->no_update.ref_count++; |
| 254 | mutex_unlock(&mfd->no_update.lock); |
| 255 | ret = wait_for_completion_interruptible_timeout( |
| 256 | &mfd->no_update.comp, 4 * HZ); |
| 257 | mutex_lock(&mfd->no_update.lock); |
| 258 | mfd->no_update.ref_count--; |
| 259 | mutex_unlock(&mfd->no_update.lock); |
| 260 | to_user = (unsigned int)mfd->no_update.value; |
| 261 | } else { |
| 262 | if (mdss_fb_is_power_on(mfd)) { |
| 263 | reinit_completion(&mfd->power_off_comp); |
| 264 | ret = wait_for_completion_interruptible_timeout( |
| 265 | &mfd->power_off_comp, 1 * HZ); |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | if (ret == 0) |
| 270 | ret = -ETIMEDOUT; |
| 271 | else if (ret > 0) |
| 272 | ret = copy_to_user(argp, &to_user, sizeof(unsigned int)); |
| 273 | return ret; |
| 274 | } |
| 275 | |
| 276 | static int lcd_backlight_registered; |
| 277 | |
| 278 | static void mdss_fb_set_bl_brightness(struct led_classdev *led_cdev, |
| 279 | enum led_brightness value) |
| 280 | { |
| 281 | struct msm_fb_data_type *mfd = dev_get_drvdata(led_cdev->dev->parent); |
| 282 | int bl_lvl; |
| 283 | |
| 284 | if (mfd->boot_notification_led) { |
| 285 | led_trigger_event(mfd->boot_notification_led, 0); |
| 286 | mfd->boot_notification_led = NULL; |
| 287 | } |
| 288 | |
| 289 | if (value > mfd->panel_info->brightness_max) |
| 290 | value = mfd->panel_info->brightness_max; |
| 291 | |
| 292 | /* This maps android backlight level 0 to 255 into |
| 293 | * driver backlight level 0 to bl_max with rounding |
| 294 | */ |
| 295 | MDSS_BRIGHT_TO_BL(bl_lvl, value, mfd->panel_info->bl_max, |
| 296 | mfd->panel_info->brightness_max); |
| 297 | |
| 298 | if (!bl_lvl && value) |
| 299 | bl_lvl = 1; |
| 300 | |
| 301 | if (!IS_CALIB_MODE_BL(mfd) && (!mfd->ext_bl_ctrl || !value || |
| 302 | !mfd->bl_level)) { |
| 303 | mutex_lock(&mfd->bl_lock); |
| 304 | mdss_fb_set_backlight(mfd, bl_lvl); |
| 305 | mutex_unlock(&mfd->bl_lock); |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | static struct led_classdev backlight_led = { |
| 310 | .name = "lcd-backlight", |
| 311 | .brightness = MDSS_MAX_BL_BRIGHTNESS / 2, |
| 312 | .brightness_set = mdss_fb_set_bl_brightness, |
| 313 | .max_brightness = MDSS_MAX_BL_BRIGHTNESS, |
| 314 | }; |
| 315 | |
| 316 | static ssize_t mdss_fb_get_type(struct device *dev, |
| 317 | struct device_attribute *attr, char *buf) |
| 318 | { |
| 319 | ssize_t ret = 0; |
| 320 | struct fb_info *fbi = dev_get_drvdata(dev); |
| 321 | struct msm_fb_data_type *mfd = (struct msm_fb_data_type *)fbi->par; |
| 322 | |
| 323 | switch (mfd->panel.type) { |
| 324 | case NO_PANEL: |
| 325 | ret = snprintf(buf, PAGE_SIZE, "no panel\n"); |
| 326 | break; |
| 327 | case HDMI_PANEL: |
| 328 | ret = snprintf(buf, PAGE_SIZE, "hdmi panel\n"); |
| 329 | break; |
| 330 | case LVDS_PANEL: |
| 331 | ret = snprintf(buf, PAGE_SIZE, "lvds panel\n"); |
| 332 | break; |
| 333 | case DTV_PANEL: |
| 334 | ret = snprintf(buf, PAGE_SIZE, "dtv panel\n"); |
| 335 | break; |
| 336 | case MIPI_VIDEO_PANEL: |
| 337 | ret = snprintf(buf, PAGE_SIZE, "mipi dsi video panel\n"); |
| 338 | break; |
| 339 | case MIPI_CMD_PANEL: |
| 340 | ret = snprintf(buf, PAGE_SIZE, "mipi dsi cmd panel\n"); |
| 341 | break; |
| 342 | case WRITEBACK_PANEL: |
| 343 | ret = snprintf(buf, PAGE_SIZE, "writeback panel\n"); |
| 344 | break; |
| 345 | case EDP_PANEL: |
| 346 | ret = snprintf(buf, PAGE_SIZE, "edp panel\n"); |
| 347 | break; |
| 348 | default: |
| 349 | ret = snprintf(buf, PAGE_SIZE, "unknown panel\n"); |
| 350 | break; |
| 351 | } |
| 352 | |
| 353 | return ret; |
| 354 | } |
| 355 | |
| 356 | static int mdss_fb_get_panel_xres(struct mdss_panel_info *pinfo) |
| 357 | { |
| 358 | struct mdss_panel_data *pdata; |
| 359 | int xres; |
| 360 | |
| 361 | pdata = container_of(pinfo, struct mdss_panel_data, panel_info); |
| 362 | |
| 363 | xres = pinfo->xres; |
| 364 | if (pdata->next && pdata->next->active) |
| 365 | xres += mdss_fb_get_panel_xres(&pdata->next->panel_info); |
| 366 | |
| 367 | return xres; |
| 368 | } |
| 369 | |
| 370 | static inline int mdss_fb_validate_split(int left, int right, |
| 371 | struct msm_fb_data_type *mfd) |
| 372 | { |
| 373 | int rc = -EINVAL; |
| 374 | u32 panel_xres = mdss_fb_get_panel_xres(mfd->panel_info); |
| 375 | |
| 376 | pr_debug("%pS: split_mode = %d left=%d right=%d panel_xres=%d\n", |
| 377 | __builtin_return_address(0), mfd->split_mode, |
| 378 | left, right, panel_xres); |
| 379 | |
| 380 | /* more validate condition could be added if needed */ |
| 381 | if (left && right) { |
| 382 | if (panel_xres == left + right) { |
| 383 | mfd->split_fb_left = left; |
| 384 | mfd->split_fb_right = right; |
| 385 | rc = 0; |
| 386 | } |
| 387 | } else { |
| 388 | if (mfd->split_mode == MDP_DUAL_LM_DUAL_DISPLAY) { |
| 389 | mfd->split_fb_left = mfd->panel_info->xres; |
| 390 | mfd->split_fb_right = panel_xres - mfd->split_fb_left; |
| 391 | rc = 0; |
| 392 | } else { |
| 393 | mfd->split_fb_left = mfd->split_fb_right = 0; |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | return rc; |
| 398 | } |
| 399 | |
| 400 | static ssize_t mdss_fb_store_split(struct device *dev, |
| 401 | struct device_attribute *attr, const char *buf, size_t len) |
| 402 | { |
| 403 | int data[2] = {0}; |
| 404 | struct fb_info *fbi = dev_get_drvdata(dev); |
| 405 | struct msm_fb_data_type *mfd = (struct msm_fb_data_type *)fbi->par; |
| 406 | |
| 407 | if (sscanf(buf, "%d %d", &data[0], &data[1]) != 2) |
| 408 | pr_debug("Not able to read split values\n"); |
| 409 | else if (!mdss_fb_validate_split(data[0], data[1], mfd)) |
| 410 | pr_debug("split left=%d right=%d\n", data[0], data[1]); |
| 411 | |
| 412 | return len; |
| 413 | } |
| 414 | |
| 415 | static ssize_t mdss_fb_show_split(struct device *dev, |
| 416 | struct device_attribute *attr, char *buf) |
| 417 | { |
| 418 | ssize_t ret = 0; |
| 419 | struct fb_info *fbi = dev_get_drvdata(dev); |
| 420 | struct msm_fb_data_type *mfd = (struct msm_fb_data_type *)fbi->par; |
| 421 | |
| 422 | ret = snprintf(buf, PAGE_SIZE, "%d %d\n", |
| 423 | mfd->split_fb_left, mfd->split_fb_right); |
| 424 | return ret; |
| 425 | } |
| 426 | |
| 427 | static void mdss_fb_get_split(struct msm_fb_data_type *mfd) |
| 428 | { |
| 429 | if ((mfd->split_mode == MDP_SPLIT_MODE_NONE) && |
| 430 | (mfd->split_fb_left && mfd->split_fb_right)) |
| 431 | mfd->split_mode = MDP_DUAL_LM_SINGLE_DISPLAY; |
| 432 | |
| 433 | pr_debug("split fb%d left=%d right=%d mode=%d\n", mfd->index, |
| 434 | mfd->split_fb_left, mfd->split_fb_right, mfd->split_mode); |
| 435 | } |
| 436 | |
| 437 | static ssize_t mdss_fb_get_src_split_info(struct device *dev, |
| 438 | struct device_attribute *attr, char *buf) |
| 439 | { |
| 440 | int ret = 0; |
| 441 | struct fb_info *fbi = dev_get_drvdata(dev); |
| 442 | struct msm_fb_data_type *mfd = fbi->par; |
| 443 | |
| 444 | if (is_split_lm(mfd) && (fbi->var.yres > fbi->var.xres)) { |
| 445 | pr_debug("always split mode enabled\n"); |
| 446 | ret = scnprintf(buf, PAGE_SIZE, |
| 447 | "src_split_always\n"); |
| 448 | } |
| 449 | |
| 450 | return ret; |
| 451 | } |
| 452 | |
| 453 | static ssize_t mdss_fb_get_thermal_level(struct device *dev, |
| 454 | struct device_attribute *attr, char *buf) |
| 455 | { |
| 456 | struct fb_info *fbi = dev_get_drvdata(dev); |
| 457 | struct msm_fb_data_type *mfd = fbi->par; |
| 458 | int ret; |
| 459 | |
| 460 | ret = scnprintf(buf, PAGE_SIZE, "thermal_level=%d\n", |
| 461 | mfd->thermal_level); |
| 462 | |
| 463 | return ret; |
| 464 | } |
| 465 | |
| 466 | static ssize_t mdss_fb_set_thermal_level(struct device *dev, |
| 467 | struct device_attribute *attr, const char *buf, size_t count) |
| 468 | { |
| 469 | struct fb_info *fbi = dev_get_drvdata(dev); |
| 470 | struct msm_fb_data_type *mfd = fbi->par; |
| 471 | int rc = 0; |
| 472 | int thermal_level = 0; |
| 473 | |
| 474 | rc = kstrtoint(buf, 10, &thermal_level); |
| 475 | if (rc) { |
| 476 | pr_err("kstrtoint failed. rc=%d\n", rc); |
| 477 | return rc; |
| 478 | } |
| 479 | |
| 480 | pr_debug("Thermal level set to %d\n", thermal_level); |
| 481 | mfd->thermal_level = thermal_level; |
| 482 | sysfs_notify(&mfd->fbi->dev->kobj, NULL, "msm_fb_thermal_level"); |
| 483 | |
| 484 | return count; |
| 485 | } |
| 486 | |
| 487 | static ssize_t mdss_mdp_show_blank_event(struct device *dev, |
| 488 | struct device_attribute *attr, char *buf) |
| 489 | { |
| 490 | struct fb_info *fbi = dev_get_drvdata(dev); |
| 491 | struct msm_fb_data_type *mfd = (struct msm_fb_data_type *)fbi->par; |
| 492 | int ret; |
| 493 | |
| 494 | pr_debug("fb%d panel_power_state = %d\n", mfd->index, |
| 495 | mfd->panel_power_state); |
| 496 | ret = scnprintf(buf, PAGE_SIZE, "panel_power_on = %d\n", |
| 497 | mfd->panel_power_state); |
| 498 | |
| 499 | return ret; |
| 500 | } |
| 501 | |
| 502 | static void __mdss_fb_idle_notify_work(struct work_struct *work) |
| 503 | { |
| 504 | struct delayed_work *dw = to_delayed_work(work); |
| 505 | struct msm_fb_data_type *mfd = container_of(dw, struct msm_fb_data_type, |
| 506 | idle_notify_work); |
| 507 | |
| 508 | /* Notify idle-ness here */ |
| 509 | pr_debug("Idle timeout %dms expired!\n", mfd->idle_time); |
| 510 | if (mfd->idle_time) |
| 511 | sysfs_notify(&mfd->fbi->dev->kobj, NULL, "idle_notify"); |
| 512 | mfd->idle_state = MDSS_FB_IDLE; |
| 513 | } |
| 514 | |
| 515 | |
| 516 | static ssize_t mdss_fb_get_fps_info(struct device *dev, |
| 517 | struct device_attribute *attr, char *buf) |
| 518 | { |
| 519 | struct fb_info *fbi = dev_get_drvdata(dev); |
| 520 | struct msm_fb_data_type *mfd = fbi->par; |
| 521 | unsigned int fps_int, fps_float; |
| 522 | |
| 523 | if (mfd->panel_power_state != MDSS_PANEL_POWER_ON) |
| 524 | mfd->fps_info.measured_fps = 0; |
| 525 | fps_int = (unsigned int) mfd->fps_info.measured_fps; |
| 526 | fps_float = do_div(fps_int, 10); |
| 527 | return scnprintf(buf, PAGE_SIZE, "%d.%d\n", fps_int, fps_float); |
| 528 | |
| 529 | } |
| 530 | |
| 531 | static ssize_t mdss_fb_get_idle_time(struct device *dev, |
| 532 | struct device_attribute *attr, char *buf) |
| 533 | { |
| 534 | struct fb_info *fbi = dev_get_drvdata(dev); |
| 535 | struct msm_fb_data_type *mfd = fbi->par; |
| 536 | int ret; |
| 537 | |
| 538 | ret = scnprintf(buf, PAGE_SIZE, "%d", mfd->idle_time); |
| 539 | |
| 540 | return ret; |
| 541 | } |
| 542 | |
| 543 | static ssize_t mdss_fb_set_idle_time(struct device *dev, |
| 544 | struct device_attribute *attr, const char *buf, size_t count) |
| 545 | { |
| 546 | struct fb_info *fbi = dev_get_drvdata(dev); |
| 547 | struct msm_fb_data_type *mfd = fbi->par; |
| 548 | int rc = 0; |
| 549 | int idle_time = 0; |
| 550 | |
| 551 | rc = kstrtoint(buf, 10, &idle_time); |
| 552 | if (rc) { |
| 553 | pr_err("kstrtoint failed. rc=%d\n", rc); |
| 554 | return rc; |
| 555 | } |
| 556 | |
| 557 | pr_debug("Idle time = %d\n", idle_time); |
| 558 | mfd->idle_time = idle_time; |
| 559 | |
| 560 | return count; |
| 561 | } |
| 562 | |
| 563 | static ssize_t mdss_fb_get_idle_notify(struct device *dev, |
| 564 | struct device_attribute *attr, char *buf) |
| 565 | { |
| 566 | struct fb_info *fbi = dev_get_drvdata(dev); |
| 567 | struct msm_fb_data_type *mfd = fbi->par; |
| 568 | int ret; |
| 569 | |
| 570 | ret = scnprintf(buf, PAGE_SIZE, "%s", |
| 571 | work_busy(&mfd->idle_notify_work.work) ? "no" : "yes"); |
| 572 | |
| 573 | return ret; |
| 574 | } |
| 575 | |
| 576 | static ssize_t mdss_fb_get_panel_info(struct device *dev, |
| 577 | struct device_attribute *attr, char *buf) |
| 578 | { |
| 579 | struct fb_info *fbi = dev_get_drvdata(dev); |
| 580 | struct msm_fb_data_type *mfd = fbi->par; |
| 581 | struct mdss_panel_info *pinfo = mfd->panel_info; |
| 582 | int ret; |
| 583 | |
| 584 | ret = scnprintf(buf, PAGE_SIZE, |
| 585 | "pu_en=%d\nxstart=%d\nwalign=%d\nystart=%d\nhalign=%d\n" |
| 586 | "min_w=%d\nmin_h=%d\nroi_merge=%d\ndyn_fps_en=%d\n" |
| 587 | "min_fps=%d\nmax_fps=%d\npanel_name=%s\n" |
| 588 | "primary_panel=%d\nis_pluggable=%d\ndisplay_id=%s\n" |
| 589 | "is_cec_supported=%d\nis_pingpong_split=%d\n" |
| 590 | "is_hdr_enabled=%d\n" |
| 591 | "peak_brightness=%d\nblackness_level=%d\n" |
| 592 | "white_chromaticity_x=%d\nwhite_chromaticity_y=%d\n" |
| 593 | "red_chromaticity_x=%d\nred_chromaticity_y=%d\n" |
| 594 | "green_chromaticity_x=%d\ngreen_chromaticity_y=%d\n" |
| 595 | "blue_chromaticity_x=%d\nblue_chromaticity_y=%d\n", |
| 596 | pinfo->partial_update_enabled, |
| 597 | pinfo->roi_alignment.xstart_pix_align, |
| 598 | pinfo->roi_alignment.width_pix_align, |
| 599 | pinfo->roi_alignment.ystart_pix_align, |
| 600 | pinfo->roi_alignment.height_pix_align, |
| 601 | pinfo->roi_alignment.min_width, |
| 602 | pinfo->roi_alignment.min_height, |
| 603 | pinfo->partial_update_roi_merge, |
| 604 | pinfo->dynamic_fps, pinfo->min_fps, pinfo->max_fps, |
| 605 | pinfo->panel_name, pinfo->is_prim_panel, |
| 606 | pinfo->is_pluggable, pinfo->display_id, |
| 607 | pinfo->is_cec_supported, is_pingpong_split(mfd), |
| 608 | pinfo->hdr_properties.hdr_enabled, |
| 609 | pinfo->hdr_properties.peak_brightness, |
| 610 | pinfo->hdr_properties.blackness_level, |
| 611 | pinfo->hdr_properties.display_primaries[0], |
| 612 | pinfo->hdr_properties.display_primaries[1], |
| 613 | pinfo->hdr_properties.display_primaries[2], |
| 614 | pinfo->hdr_properties.display_primaries[3], |
| 615 | pinfo->hdr_properties.display_primaries[4], |
| 616 | pinfo->hdr_properties.display_primaries[5], |
| 617 | pinfo->hdr_properties.display_primaries[6], |
| 618 | pinfo->hdr_properties.display_primaries[7]); |
| 619 | |
| 620 | return ret; |
| 621 | } |
| 622 | |
| 623 | static ssize_t mdss_fb_get_panel_status(struct device *dev, |
| 624 | struct device_attribute *attr, char *buf) |
| 625 | { |
| 626 | struct fb_info *fbi = dev_get_drvdata(dev); |
| 627 | struct msm_fb_data_type *mfd = fbi->par; |
| 628 | int ret; |
| 629 | int panel_status; |
| 630 | |
| 631 | if (mdss_panel_is_power_off(mfd->panel_power_state)) { |
| 632 | ret = scnprintf(buf, PAGE_SIZE, "panel_status=%s\n", "suspend"); |
| 633 | } else { |
| 634 | panel_status = mdss_fb_send_panel_event(mfd, |
| 635 | MDSS_EVENT_DSI_PANEL_STATUS, NULL); |
| 636 | ret = scnprintf(buf, PAGE_SIZE, "panel_status=%s\n", |
| 637 | panel_status > 0 ? "alive" : "dead"); |
| 638 | } |
| 639 | |
| 640 | return ret; |
| 641 | } |
| 642 | |
| 643 | static ssize_t mdss_fb_force_panel_dead(struct device *dev, |
| 644 | struct device_attribute *attr, const char *buf, size_t len) |
| 645 | { |
| 646 | struct fb_info *fbi = dev_get_drvdata(dev); |
| 647 | struct msm_fb_data_type *mfd = (struct msm_fb_data_type *)fbi->par; |
| 648 | struct mdss_panel_data *pdata; |
| 649 | |
| 650 | pdata = dev_get_platdata(&mfd->pdev->dev); |
| 651 | if (!pdata) { |
| 652 | pr_err("no panel connected!\n"); |
| 653 | return len; |
| 654 | } |
| 655 | |
| 656 | if (kstrtouint(buf, 0, &pdata->panel_info.panel_force_dead)) |
| 657 | pr_err("kstrtouint buf error!\n"); |
| 658 | |
| 659 | return len; |
| 660 | } |
| 661 | |
| 662 | /* |
| 663 | * mdss_fb_blanking_mode_switch() - Function triggers dynamic mode switch |
| 664 | * @mfd: Framebuffer data structure for display |
| 665 | * @mode: Enabled/Disable LowPowerMode |
| 666 | * 1: Enter into LowPowerMode |
| 667 | * 0: Exit from LowPowerMode |
| 668 | * |
| 669 | * This Function dynamically switches to and from video mode. This |
| 670 | * swtich involves the panel turning off backlight during trantision. |
| 671 | */ |
| 672 | static int mdss_fb_blanking_mode_switch(struct msm_fb_data_type *mfd, int mode) |
| 673 | { |
| 674 | int ret = 0; |
| 675 | u32 bl_lvl = 0; |
| 676 | struct mdss_panel_info *pinfo = NULL; |
| 677 | struct mdss_panel_data *pdata; |
| 678 | |
| 679 | if (!mfd || !mfd->panel_info) |
| 680 | return -EINVAL; |
| 681 | |
| 682 | pinfo = mfd->panel_info; |
| 683 | |
| 684 | if (!pinfo->mipi.dms_mode) { |
| 685 | pr_warn("Panel does not support dynamic switch!\n"); |
| 686 | return 0; |
| 687 | } |
| 688 | |
| 689 | if (mode == pinfo->mipi.mode) { |
| 690 | pr_debug("Already in requested mode!\n"); |
| 691 | return 0; |
| 692 | } |
| 693 | pr_debug("Enter mode: %d\n", mode); |
| 694 | |
| 695 | pdata = dev_get_platdata(&mfd->pdev->dev); |
| 696 | |
| 697 | pdata->panel_info.dynamic_switch_pending = true; |
| 698 | ret = mdss_fb_pan_idle(mfd); |
| 699 | if (ret) { |
| 700 | pr_err("mdss_fb_pan_idle for fb%d failed. ret=%d\n", |
| 701 | mfd->index, ret); |
| 702 | pdata->panel_info.dynamic_switch_pending = false; |
| 703 | return ret; |
| 704 | } |
| 705 | |
| 706 | mutex_lock(&mfd->bl_lock); |
| 707 | bl_lvl = mfd->bl_level; |
| 708 | mdss_fb_set_backlight(mfd, 0); |
| 709 | mutex_unlock(&mfd->bl_lock); |
| 710 | |
| 711 | lock_fb_info(mfd->fbi); |
| 712 | ret = mdss_fb_blank_sub(FB_BLANK_POWERDOWN, mfd->fbi, |
| 713 | mfd->op_enable); |
| 714 | if (ret) { |
| 715 | pr_err("can't turn off display!\n"); |
| 716 | unlock_fb_info(mfd->fbi); |
| 717 | return ret; |
| 718 | } |
| 719 | |
| 720 | mfd->op_enable = false; |
| 721 | |
| 722 | ret = mfd->mdp.configure_panel(mfd, mode, 1); |
| 723 | mdss_fb_set_mdp_sync_pt_threshold(mfd, mfd->panel.type); |
| 724 | |
| 725 | mfd->op_enable = true; |
| 726 | |
| 727 | ret = mdss_fb_blank_sub(FB_BLANK_UNBLANK, mfd->fbi, |
| 728 | mfd->op_enable); |
| 729 | if (ret) { |
| 730 | pr_err("can't turn on display!\n"); |
| 731 | unlock_fb_info(mfd->fbi); |
| 732 | return ret; |
| 733 | } |
| 734 | unlock_fb_info(mfd->fbi); |
| 735 | |
| 736 | mutex_lock(&mfd->bl_lock); |
| 737 | mfd->allow_bl_update = true; |
| 738 | mdss_fb_set_backlight(mfd, bl_lvl); |
| 739 | mutex_unlock(&mfd->bl_lock); |
| 740 | |
| 741 | pdata->panel_info.dynamic_switch_pending = false; |
| 742 | pdata->panel_info.is_lpm_mode = mode ? 1 : 0; |
| 743 | |
| 744 | if (ret) { |
| 745 | pr_err("can't turn on display!\n"); |
| 746 | return ret; |
| 747 | } |
| 748 | |
| 749 | pr_debug("Exit mode: %d\n", mode); |
| 750 | |
| 751 | return 0; |
| 752 | } |
| 753 | |
| 754 | static ssize_t mdss_fb_change_dfps_mode(struct device *dev, |
| 755 | struct device_attribute *attr, const char *buf, size_t len) |
| 756 | { |
| 757 | struct fb_info *fbi = dev_get_drvdata(dev); |
| 758 | struct msm_fb_data_type *mfd = (struct msm_fb_data_type *)fbi->par; |
| 759 | struct mdss_panel_data *pdata; |
| 760 | struct mdss_panel_info *pinfo; |
| 761 | u32 dfps_mode; |
| 762 | |
| 763 | pdata = dev_get_platdata(&mfd->pdev->dev); |
| 764 | if (!pdata) { |
| 765 | pr_err("no panel connected!\n"); |
| 766 | return len; |
| 767 | } |
| 768 | pinfo = &pdata->panel_info; |
| 769 | |
| 770 | if (kstrtouint(buf, 0, &dfps_mode)) { |
| 771 | pr_err("kstrtouint buf error!\n"); |
| 772 | return len; |
| 773 | } |
| 774 | |
| 775 | if (dfps_mode >= DFPS_MODE_MAX) { |
| 776 | pinfo->dynamic_fps = false; |
| 777 | return len; |
| 778 | } |
| 779 | |
| 780 | if (mfd->idle_time != 0) { |
| 781 | pr_err("ERROR: Idle time is not disabled.\n"); |
| 782 | return len; |
| 783 | } |
| 784 | |
| 785 | if (pinfo->current_fps != pinfo->default_fps) { |
| 786 | pr_err("ERROR: panel not configured to default fps\n"); |
| 787 | return len; |
| 788 | } |
| 789 | |
| 790 | pinfo->dynamic_fps = true; |
| 791 | pinfo->dfps_update = dfps_mode; |
| 792 | |
| 793 | if (pdata->next) |
| 794 | pdata->next->panel_info.dfps_update = dfps_mode; |
| 795 | |
| 796 | return len; |
| 797 | } |
| 798 | |
| 799 | static ssize_t mdss_fb_get_dfps_mode(struct device *dev, |
| 800 | struct device_attribute *attr, char *buf) |
| 801 | { |
| 802 | struct fb_info *fbi = dev_get_drvdata(dev); |
| 803 | struct msm_fb_data_type *mfd = (struct msm_fb_data_type *)fbi->par; |
| 804 | struct mdss_panel_data *pdata; |
| 805 | struct mdss_panel_info *pinfo; |
| 806 | int ret; |
| 807 | |
| 808 | pdata = dev_get_platdata(&mfd->pdev->dev); |
| 809 | if (!pdata) { |
| 810 | pr_err("no panel connected!\n"); |
| 811 | return -EINVAL; |
| 812 | } |
| 813 | pinfo = &pdata->panel_info; |
| 814 | |
| 815 | ret = scnprintf(buf, PAGE_SIZE, "dfps enabled=%d mode=%d\n", |
| 816 | pinfo->dynamic_fps, pinfo->dfps_update); |
| 817 | |
| 818 | return ret; |
| 819 | } |
| 820 | |
| 821 | static ssize_t mdss_fb_change_persist_mode(struct device *dev, |
| 822 | struct device_attribute *attr, const char *buf, size_t len) |
| 823 | { |
| 824 | struct fb_info *fbi = dev_get_drvdata(dev); |
| 825 | struct msm_fb_data_type *mfd = (struct msm_fb_data_type *)fbi->par; |
| 826 | struct mdss_panel_info *pinfo = NULL; |
| 827 | struct mdss_panel_data *pdata; |
| 828 | int ret = 0; |
| 829 | u32 persist_mode; |
| 830 | |
| 831 | if (!mfd || !mfd->panel_info) { |
| 832 | pr_err("%s: Panel info is NULL!\n", __func__); |
| 833 | return len; |
| 834 | } |
| 835 | |
| 836 | pinfo = mfd->panel_info; |
| 837 | |
| 838 | if (kstrtouint(buf, 0, &persist_mode)) { |
| 839 | pr_err("kstrtouint buf error!\n"); |
| 840 | return len; |
| 841 | } |
| 842 | |
| 843 | mutex_lock(&mfd->mdss_sysfs_lock); |
| 844 | if (mdss_panel_is_power_off(mfd->panel_power_state)) { |
| 845 | pinfo->persist_mode = persist_mode; |
| 846 | goto end; |
| 847 | } |
| 848 | |
| 849 | mutex_lock(&mfd->bl_lock); |
| 850 | |
| 851 | pdata = dev_get_platdata(&mfd->pdev->dev); |
| 852 | if ((pdata) && (pdata->apply_display_setting)) |
| 853 | ret = pdata->apply_display_setting(pdata, persist_mode); |
| 854 | |
| 855 | mutex_unlock(&mfd->bl_lock); |
| 856 | |
| 857 | if (!ret) { |
| 858 | pr_debug("%s: Persist mode %d\n", __func__, persist_mode); |
| 859 | pinfo->persist_mode = persist_mode; |
| 860 | } |
| 861 | |
| 862 | end: |
| 863 | mutex_unlock(&mfd->mdss_sysfs_lock); |
| 864 | return len; |
| 865 | } |
| 866 | |
| 867 | static ssize_t mdss_fb_get_persist_mode(struct device *dev, |
| 868 | struct device_attribute *attr, char *buf) |
| 869 | { |
| 870 | struct fb_info *fbi = dev_get_drvdata(dev); |
| 871 | struct msm_fb_data_type *mfd = (struct msm_fb_data_type *)fbi->par; |
| 872 | struct mdss_panel_data *pdata; |
| 873 | struct mdss_panel_info *pinfo; |
| 874 | int ret; |
| 875 | |
| 876 | pdata = dev_get_platdata(&mfd->pdev->dev); |
| 877 | if (!pdata) { |
| 878 | pr_err("no panel connected!\n"); |
| 879 | return -EINVAL; |
| 880 | } |
| 881 | pinfo = &pdata->panel_info; |
| 882 | |
| 883 | ret = scnprintf(buf, PAGE_SIZE, "%d\n", pinfo->persist_mode); |
| 884 | |
| 885 | return ret; |
| 886 | } |
| 887 | |
| 888 | static DEVICE_ATTR(msm_fb_type, 0444, mdss_fb_get_type, NULL); |
| 889 | static DEVICE_ATTR(msm_fb_split, 0644, mdss_fb_show_split, |
| 890 | mdss_fb_store_split); |
| 891 | static DEVICE_ATTR(show_blank_event, 0444, mdss_mdp_show_blank_event, NULL); |
| 892 | static DEVICE_ATTR(idle_time, 0644, |
| 893 | mdss_fb_get_idle_time, mdss_fb_set_idle_time); |
| 894 | static DEVICE_ATTR(idle_notify, 0444, mdss_fb_get_idle_notify, NULL); |
| 895 | static DEVICE_ATTR(msm_fb_panel_info, 0444, mdss_fb_get_panel_info, NULL); |
| 896 | static DEVICE_ATTR(msm_fb_src_split_info, 0444, mdss_fb_get_src_split_info, |
| 897 | NULL); |
| 898 | static DEVICE_ATTR(msm_fb_thermal_level, 0644, |
| 899 | mdss_fb_get_thermal_level, mdss_fb_set_thermal_level); |
| 900 | static DEVICE_ATTR(msm_fb_panel_status, 0644, |
| 901 | mdss_fb_get_panel_status, mdss_fb_force_panel_dead); |
| 902 | static DEVICE_ATTR(msm_fb_dfps_mode, 0644, |
| 903 | mdss_fb_get_dfps_mode, mdss_fb_change_dfps_mode); |
| 904 | static DEVICE_ATTR(measured_fps, 0664, |
| 905 | mdss_fb_get_fps_info, NULL); |
| 906 | static DEVICE_ATTR(msm_fb_persist_mode, 0644, |
| 907 | mdss_fb_get_persist_mode, mdss_fb_change_persist_mode); |
| 908 | static struct attribute *mdss_fb_attrs[] = { |
| 909 | &dev_attr_msm_fb_type.attr, |
| 910 | &dev_attr_msm_fb_split.attr, |
| 911 | &dev_attr_show_blank_event.attr, |
| 912 | &dev_attr_idle_time.attr, |
| 913 | &dev_attr_idle_notify.attr, |
| 914 | &dev_attr_msm_fb_panel_info.attr, |
| 915 | &dev_attr_msm_fb_src_split_info.attr, |
| 916 | &dev_attr_msm_fb_thermal_level.attr, |
| 917 | &dev_attr_msm_fb_panel_status.attr, |
| 918 | &dev_attr_msm_fb_dfps_mode.attr, |
| 919 | &dev_attr_measured_fps.attr, |
| 920 | &dev_attr_msm_fb_persist_mode.attr, |
| 921 | NULL, |
| 922 | }; |
| 923 | |
| 924 | static struct attribute_group mdss_fb_attr_group = { |
| 925 | .attrs = mdss_fb_attrs, |
| 926 | }; |
| 927 | |
| 928 | static int mdss_fb_create_sysfs(struct msm_fb_data_type *mfd) |
| 929 | { |
| 930 | int rc; |
| 931 | |
| 932 | rc = sysfs_create_group(&mfd->fbi->dev->kobj, &mdss_fb_attr_group); |
| 933 | if (rc) |
| 934 | pr_err("sysfs group creation failed, rc=%d\n", rc); |
| 935 | return rc; |
| 936 | } |
| 937 | |
| 938 | static void mdss_fb_remove_sysfs(struct msm_fb_data_type *mfd) |
| 939 | { |
| 940 | sysfs_remove_group(&mfd->fbi->dev->kobj, &mdss_fb_attr_group); |
| 941 | } |
| 942 | |
| 943 | static void mdss_fb_shutdown(struct platform_device *pdev) |
| 944 | { |
| 945 | struct msm_fb_data_type *mfd = platform_get_drvdata(pdev); |
| 946 | |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 947 | mfd->shutdown_pending = true; |
| 948 | |
| 949 | /* wake up threads waiting on idle or kickoff queues */ |
| 950 | wake_up_all(&mfd->idle_wait_q); |
| 951 | wake_up_all(&mfd->kickoff_wait_q); |
| 952 | |
| 953 | lock_fb_info(mfd->fbi); |
| 954 | mdss_fb_release_all(mfd->fbi, true); |
| 955 | sysfs_notify(&mfd->fbi->dev->kobj, NULL, "show_blank_event"); |
| 956 | unlock_fb_info(mfd->fbi); |
| 957 | } |
| 958 | |
| 959 | static void mdss_fb_input_event_handler(struct input_handle *handle, |
| 960 | unsigned int type, |
| 961 | unsigned int code, |
| 962 | int value) |
| 963 | { |
| 964 | struct msm_fb_data_type *mfd = handle->handler->private; |
| 965 | int rc; |
| 966 | |
| 967 | if ((type != EV_ABS) || !mdss_fb_is_power_on(mfd)) |
| 968 | return; |
| 969 | |
| 970 | if (mfd->mdp.input_event_handler) { |
| 971 | rc = mfd->mdp.input_event_handler(mfd); |
| 972 | if (rc) |
| 973 | pr_err("mdp input event handler failed\n"); |
| 974 | } |
| 975 | } |
| 976 | |
| 977 | static int mdss_fb_input_connect(struct input_handler *handler, |
| 978 | struct input_dev *dev, |
| 979 | const struct input_device_id *id) |
| 980 | { |
| 981 | int rc; |
| 982 | struct input_handle *handle; |
| 983 | |
| 984 | handle = kzalloc(sizeof(*handle), GFP_KERNEL); |
| 985 | if (!handle) |
| 986 | return -ENOMEM; |
| 987 | |
| 988 | handle->dev = dev; |
| 989 | handle->handler = handler; |
| 990 | handle->name = handler->name; |
| 991 | |
| 992 | rc = input_register_handle(handle); |
| 993 | if (rc) { |
| 994 | pr_err("failed to register input handle, rc = %d\n", rc); |
| 995 | goto error; |
| 996 | } |
| 997 | |
| 998 | rc = input_open_device(handle); |
| 999 | if (rc) { |
| 1000 | pr_err("failed to open input device, rc = %d\n", rc); |
| 1001 | goto error_unregister; |
| 1002 | } |
| 1003 | |
| 1004 | return 0; |
| 1005 | |
| 1006 | error_unregister: |
| 1007 | input_unregister_handle(handle); |
| 1008 | error: |
| 1009 | kfree(handle); |
| 1010 | return rc; |
| 1011 | } |
| 1012 | |
| 1013 | static void mdss_fb_input_disconnect(struct input_handle *handle) |
| 1014 | { |
| 1015 | input_close_device(handle); |
| 1016 | input_unregister_handle(handle); |
| 1017 | kfree(handle); |
| 1018 | } |
| 1019 | |
| 1020 | /* |
| 1021 | * Structure for specifying event parameters on which to receive callbacks. |
| 1022 | * This structure will trigger a callback in case of a touch event (specified by |
| 1023 | * EV_ABS) where there is a change in X and Y coordinates, |
| 1024 | */ |
| 1025 | static const struct input_device_id mdss_fb_input_ids[] = { |
| 1026 | { |
| 1027 | .flags = INPUT_DEVICE_ID_MATCH_EVBIT, |
| 1028 | .evbit = { BIT_MASK(EV_ABS) }, |
| 1029 | .absbit = { [BIT_WORD(ABS_MT_POSITION_X)] = |
| 1030 | BIT_MASK(ABS_MT_POSITION_X) | |
| 1031 | BIT_MASK(ABS_MT_POSITION_Y) }, |
| 1032 | }, |
| 1033 | { }, |
| 1034 | }; |
| 1035 | |
| 1036 | static int mdss_fb_register_input_handler(struct msm_fb_data_type *mfd) |
| 1037 | { |
| 1038 | int rc; |
| 1039 | struct input_handler *handler; |
| 1040 | |
| 1041 | if (mfd->input_handler) |
| 1042 | return -EINVAL; |
| 1043 | |
| 1044 | handler = kzalloc(sizeof(*handler), GFP_KERNEL); |
| 1045 | if (!handler) |
| 1046 | return -ENOMEM; |
| 1047 | |
| 1048 | handler->event = mdss_fb_input_event_handler; |
| 1049 | handler->connect = mdss_fb_input_connect; |
| 1050 | handler->disconnect = mdss_fb_input_disconnect, |
| 1051 | handler->name = "mdss_fb", |
| 1052 | handler->id_table = mdss_fb_input_ids; |
| 1053 | handler->private = mfd; |
| 1054 | |
| 1055 | rc = input_register_handler(handler); |
| 1056 | if (rc) { |
| 1057 | pr_err("Unable to register the input handler\n"); |
| 1058 | kfree(handler); |
| 1059 | } else { |
| 1060 | mfd->input_handler = handler; |
| 1061 | } |
| 1062 | |
| 1063 | return rc; |
| 1064 | } |
| 1065 | |
| 1066 | static void mdss_fb_unregister_input_handler(struct msm_fb_data_type *mfd) |
| 1067 | { |
| 1068 | if (!mfd->input_handler) |
| 1069 | return; |
| 1070 | |
| 1071 | input_unregister_handler(mfd->input_handler); |
| 1072 | kfree(mfd->input_handler); |
| 1073 | } |
| 1074 | |
| 1075 | static void mdss_fb_videomode_from_panel_timing(struct fb_videomode *videomode, |
| 1076 | struct mdss_panel_timing *pt) |
| 1077 | { |
| 1078 | videomode->name = pt->name; |
| 1079 | videomode->xres = pt->xres; |
| 1080 | videomode->yres = pt->yres; |
| 1081 | videomode->left_margin = pt->h_back_porch; |
| 1082 | videomode->right_margin = pt->h_front_porch; |
| 1083 | videomode->hsync_len = pt->h_pulse_width; |
| 1084 | videomode->upper_margin = pt->v_back_porch; |
| 1085 | videomode->lower_margin = pt->v_front_porch; |
| 1086 | videomode->vsync_len = pt->v_pulse_width; |
| 1087 | videomode->refresh = pt->frame_rate; |
| 1088 | videomode->flag = 0; |
| 1089 | videomode->vmode = 0; |
| 1090 | videomode->sync = 0; |
| 1091 | |
| 1092 | if (videomode->refresh) { |
| 1093 | unsigned long clk_rate, h_total, v_total; |
| 1094 | |
| 1095 | h_total = videomode->xres + videomode->left_margin |
| 1096 | + videomode->right_margin + videomode->hsync_len; |
| 1097 | v_total = videomode->yres + videomode->lower_margin |
| 1098 | + videomode->upper_margin + videomode->vsync_len; |
| 1099 | clk_rate = h_total * v_total * videomode->refresh; |
| 1100 | videomode->pixclock = |
| 1101 | KHZ2PICOS(clk_rate / 1000); |
| 1102 | } else { |
| 1103 | videomode->pixclock = |
| 1104 | KHZ2PICOS((unsigned long)pt->clk_rate / 1000); |
| 1105 | } |
| 1106 | } |
| 1107 | |
| 1108 | static void mdss_fb_set_split_mode(struct msm_fb_data_type *mfd, |
| 1109 | struct mdss_panel_data *pdata) |
| 1110 | { |
| 1111 | if (pdata->panel_info.is_split_display) { |
| 1112 | struct mdss_panel_data *pnext = pdata->next; |
| 1113 | |
| 1114 | mfd->split_fb_left = pdata->panel_info.lm_widths[0]; |
| 1115 | if (pnext) |
| 1116 | mfd->split_fb_right = pnext->panel_info.lm_widths[0]; |
| 1117 | |
| 1118 | if (pdata->panel_info.use_pingpong_split) |
| 1119 | mfd->split_mode = MDP_PINGPONG_SPLIT; |
| 1120 | else |
| 1121 | mfd->split_mode = MDP_DUAL_LM_DUAL_DISPLAY; |
| 1122 | } else if ((pdata->panel_info.lm_widths[0] != 0) |
| 1123 | && (pdata->panel_info.lm_widths[1] != 0)) { |
| 1124 | mfd->split_fb_left = pdata->panel_info.lm_widths[0]; |
| 1125 | mfd->split_fb_right = pdata->panel_info.lm_widths[1]; |
| 1126 | mfd->split_mode = MDP_DUAL_LM_SINGLE_DISPLAY; |
| 1127 | } else { |
| 1128 | mfd->split_mode = MDP_SPLIT_MODE_NONE; |
| 1129 | } |
| 1130 | } |
| 1131 | |
| 1132 | static int mdss_fb_init_panel_modes(struct msm_fb_data_type *mfd, |
| 1133 | struct mdss_panel_data *pdata) |
| 1134 | { |
| 1135 | struct fb_info *fbi = mfd->fbi; |
| 1136 | struct fb_videomode *modedb; |
| 1137 | struct mdss_panel_timing *pt; |
| 1138 | struct list_head *pos; |
| 1139 | int num_timings = 0; |
| 1140 | int i = 0; |
| 1141 | |
| 1142 | /* check if multiple modes are supported */ |
| 1143 | if (!pdata->timings_list.prev || !pdata->timings_list.next) |
| 1144 | INIT_LIST_HEAD(&pdata->timings_list); |
| 1145 | |
| 1146 | if (!fbi || !pdata->current_timing || list_empty(&pdata->timings_list)) |
| 1147 | return 0; |
| 1148 | |
| 1149 | list_for_each(pos, &pdata->timings_list) |
| 1150 | num_timings++; |
| 1151 | |
| 1152 | modedb = devm_kzalloc(fbi->dev, num_timings * sizeof(*modedb), |
| 1153 | GFP_KERNEL); |
| 1154 | if (!modedb) |
| 1155 | return -ENOMEM; |
| 1156 | |
| 1157 | list_for_each_entry(pt, &pdata->timings_list, list) { |
| 1158 | struct mdss_panel_timing *spt = NULL; |
| 1159 | |
| 1160 | mdss_fb_videomode_from_panel_timing(modedb + i, pt); |
| 1161 | if (pdata->next) { |
| 1162 | spt = mdss_panel_get_timing_by_name(pdata->next, |
| 1163 | modedb[i].name); |
| 1164 | if (!IS_ERR_OR_NULL(spt)) |
| 1165 | modedb[i].xres += spt->xres; |
| 1166 | else |
| 1167 | pr_debug("no matching split config for %s\n", |
| 1168 | modedb[i].name); |
| 1169 | |
| 1170 | /* |
| 1171 | * if no panel timing found for current, need to |
| 1172 | * disable it otherwise mark it as active |
| 1173 | */ |
| 1174 | if (pt == pdata->current_timing) |
| 1175 | pdata->next->active = !IS_ERR_OR_NULL(spt); |
| 1176 | } |
| 1177 | |
| 1178 | if (pt == pdata->current_timing) { |
| 1179 | pr_debug("found current mode: %s\n", pt->name); |
| 1180 | fbi->mode = modedb + i; |
| 1181 | } |
| 1182 | i++; |
| 1183 | } |
| 1184 | |
| 1185 | fbi->monspecs.modedb = modedb; |
| 1186 | fbi->monspecs.modedb_len = num_timings; |
| 1187 | |
| 1188 | /* destroy and recreate modelist */ |
| 1189 | fb_destroy_modelist(&fbi->modelist); |
| 1190 | |
| 1191 | if (fbi->mode) |
| 1192 | fb_videomode_to_var(&fbi->var, fbi->mode); |
| 1193 | fb_videomode_to_modelist(modedb, num_timings, &fbi->modelist); |
| 1194 | |
| 1195 | return 0; |
| 1196 | } |
| 1197 | |
| 1198 | static int mdss_fb_probe(struct platform_device *pdev) |
| 1199 | { |
| 1200 | struct msm_fb_data_type *mfd = NULL; |
| 1201 | struct mdss_panel_data *pdata; |
| 1202 | struct fb_info *fbi; |
| 1203 | int rc; |
| 1204 | |
| 1205 | if (fbi_list_index >= MAX_FBI_LIST) |
| 1206 | return -ENOMEM; |
| 1207 | |
| 1208 | pdata = dev_get_platdata(&pdev->dev); |
| 1209 | if (!pdata) |
| 1210 | return -EPROBE_DEFER; |
| 1211 | |
| 1212 | if (!mdp_instance) { |
| 1213 | pr_err("mdss mdp resource not initialized yet\n"); |
| 1214 | return -ENODEV; |
| 1215 | } |
| 1216 | |
| 1217 | /* |
| 1218 | * alloc framebuffer info + par data |
| 1219 | */ |
| 1220 | fbi = framebuffer_alloc(sizeof(struct msm_fb_data_type), NULL); |
| 1221 | if (fbi == NULL) { |
| 1222 | pr_err("can't allocate framebuffer info data!\n"); |
| 1223 | return -ENOMEM; |
| 1224 | } |
| 1225 | |
| 1226 | mfd = (struct msm_fb_data_type *)fbi->par; |
| 1227 | mfd->key = MFD_KEY; |
| 1228 | mfd->fbi = fbi; |
| 1229 | mfd->panel_info = &pdata->panel_info; |
| 1230 | mfd->panel.type = pdata->panel_info.type; |
| 1231 | mfd->panel.id = mfd->index; |
| 1232 | mfd->fb_page = MDSS_FB_NUM; |
| 1233 | mfd->index = fbi_list_index; |
| 1234 | mfd->mdp_fb_page_protection = MDP_FB_PAGE_PROTECTION_WRITECOMBINE; |
| 1235 | |
| 1236 | mfd->ext_ad_ctrl = -1; |
| 1237 | if (mfd->panel_info && mfd->panel_info->brightness_max > 0) |
| 1238 | MDSS_BRIGHT_TO_BL(mfd->bl_level, backlight_led.brightness, |
| 1239 | mfd->panel_info->bl_max, mfd->panel_info->brightness_max); |
| 1240 | else |
| 1241 | mfd->bl_level = 0; |
| 1242 | |
| 1243 | mfd->bl_scale = 1024; |
| 1244 | mfd->bl_min_lvl = 30; |
| 1245 | mfd->ad_bl_level = 0; |
| 1246 | mfd->fb_imgType = MDP_RGBA_8888; |
| 1247 | mfd->calib_mode_bl = 0; |
| 1248 | mfd->unset_bl_level = U32_MAX; |
| 1249 | |
| 1250 | mfd->pdev = pdev; |
| 1251 | |
| 1252 | mfd->split_fb_left = mfd->split_fb_right = 0; |
| 1253 | |
| 1254 | mdss_fb_set_split_mode(mfd, pdata); |
| 1255 | pr_info("fb%d: split_mode:%d left:%d right:%d\n", mfd->index, |
| 1256 | mfd->split_mode, mfd->split_fb_left, mfd->split_fb_right); |
| 1257 | |
| 1258 | mfd->mdp = *mdp_instance; |
| 1259 | |
| 1260 | rc = of_property_read_bool(pdev->dev.of_node, |
| 1261 | "qcom,boot-indication-enabled"); |
| 1262 | |
| 1263 | if (rc) { |
| 1264 | led_trigger_register_simple("boot-indication", |
| 1265 | &(mfd->boot_notification_led)); |
| 1266 | } |
| 1267 | |
| 1268 | INIT_LIST_HEAD(&mfd->file_list); |
| 1269 | |
| 1270 | mutex_init(&mfd->bl_lock); |
| 1271 | mutex_init(&mfd->mdss_sysfs_lock); |
| 1272 | mutex_init(&mfd->switch_lock); |
| 1273 | |
| 1274 | fbi_list[fbi_list_index++] = fbi; |
| 1275 | |
| 1276 | platform_set_drvdata(pdev, mfd); |
| 1277 | |
| 1278 | rc = mdss_fb_register(mfd); |
| 1279 | if (rc) |
| 1280 | return rc; |
| 1281 | |
| 1282 | mdss_fb_create_sysfs(mfd); |
| 1283 | mdss_fb_send_panel_event(mfd, MDSS_EVENT_FB_REGISTERED, fbi); |
| 1284 | |
| 1285 | if (mfd->mdp.init_fnc) { |
| 1286 | rc = mfd->mdp.init_fnc(mfd); |
| 1287 | if (rc) { |
| 1288 | pr_err("init_fnc failed\n"); |
| 1289 | return rc; |
| 1290 | } |
| 1291 | } |
| 1292 | mdss_fb_init_fps_info(mfd); |
| 1293 | |
| 1294 | rc = pm_runtime_set_active(mfd->fbi->dev); |
| 1295 | if (rc < 0) |
| 1296 | pr_err("pm_runtime: fail to set active.\n"); |
| 1297 | pm_runtime_enable(mfd->fbi->dev); |
| 1298 | |
| 1299 | /* android supports only one lcd-backlight/lcd for now */ |
| 1300 | if (!lcd_backlight_registered) { |
| 1301 | backlight_led.brightness = mfd->panel_info->brightness_max; |
| 1302 | backlight_led.max_brightness = mfd->panel_info->brightness_max; |
| 1303 | if (led_classdev_register(&pdev->dev, &backlight_led)) |
| 1304 | pr_err("led_classdev_register failed\n"); |
| 1305 | else |
| 1306 | lcd_backlight_registered = 1; |
| 1307 | } |
| 1308 | |
| 1309 | mdss_fb_init_panel_modes(mfd, pdata); |
| 1310 | |
| 1311 | mfd->mdp_sync_pt_data.fence_name = "mdp-fence"; |
| 1312 | if (mfd->mdp_sync_pt_data.timeline == NULL) { |
Sachin Bhayare | 2b6d004 | 2018-01-13 19:38:21 +0530 | [diff] [blame] | 1313 | char timeline_name[32]; |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 1314 | |
| 1315 | snprintf(timeline_name, sizeof(timeline_name), |
| 1316 | "mdss_fb_%d", mfd->index); |
| 1317 | mfd->mdp_sync_pt_data.timeline = |
Sachin Bhayare | 2b6d004 | 2018-01-13 19:38:21 +0530 | [diff] [blame] | 1318 | mdss_create_timeline(timeline_name); |
| 1319 | if (mfd->mdp_sync_pt_data.timeline == NULL) { |
| 1320 | pr_err("cannot create release fence time line\n"); |
| 1321 | return -ENOMEM; |
| 1322 | } |
| 1323 | snprintf(timeline_name, sizeof(timeline_name), |
| 1324 | "mdss_fb_%d_retire", mfd->index); |
| 1325 | mfd->mdp_sync_pt_data.timeline_retire = |
| 1326 | mdss_create_timeline(timeline_name); |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 1327 | if (mfd->mdp_sync_pt_data.timeline == NULL) { |
| 1328 | pr_err("cannot create release fence time line\n"); |
| 1329 | return -ENOMEM; |
| 1330 | } |
| 1331 | mfd->mdp_sync_pt_data.notifier.notifier_call = |
| 1332 | __mdss_fb_sync_buf_done_callback; |
| 1333 | } |
| 1334 | |
| 1335 | mdss_fb_set_mdp_sync_pt_threshold(mfd, mfd->panel.type); |
| 1336 | |
| 1337 | if (mfd->mdp.splash_init_fnc) |
| 1338 | mfd->mdp.splash_init_fnc(mfd); |
| 1339 | |
| 1340 | /* |
| 1341 | * Register with input driver for a callback for command mode panels. |
| 1342 | * When there is an input event, mdp clocks will be turned on to reduce |
| 1343 | * latency when a frame update happens. |
| 1344 | * For video mode panels, idle timeout will be delayed so that userspace |
| 1345 | * does not get an idle event while new frames are expected. In case of |
| 1346 | * an idle event, user space tries to fall back to GPU composition which |
| 1347 | * can lead to increased load when there are new frames. |
| 1348 | */ |
| 1349 | if (mfd->mdp.input_event_handler && |
| 1350 | ((mfd->panel_info->type == MIPI_CMD_PANEL) || |
| 1351 | (mfd->panel_info->type == MIPI_VIDEO_PANEL))) |
| 1352 | if (mdss_fb_register_input_handler(mfd)) |
| 1353 | pr_err("failed to register input handler\n"); |
| 1354 | |
| 1355 | INIT_DELAYED_WORK(&mfd->idle_notify_work, __mdss_fb_idle_notify_work); |
| 1356 | |
| 1357 | return rc; |
| 1358 | } |
| 1359 | |
| 1360 | static void mdss_fb_set_mdp_sync_pt_threshold(struct msm_fb_data_type *mfd, |
| 1361 | int type) |
| 1362 | { |
| 1363 | if (!mfd) |
| 1364 | return; |
| 1365 | |
| 1366 | switch (type) { |
| 1367 | case WRITEBACK_PANEL: |
| 1368 | mfd->mdp_sync_pt_data.threshold = 1; |
| 1369 | mfd->mdp_sync_pt_data.retire_threshold = 0; |
| 1370 | break; |
| 1371 | case MIPI_CMD_PANEL: |
| 1372 | mfd->mdp_sync_pt_data.threshold = 1; |
| 1373 | mfd->mdp_sync_pt_data.retire_threshold = 1; |
| 1374 | break; |
| 1375 | default: |
| 1376 | mfd->mdp_sync_pt_data.threshold = 2; |
| 1377 | mfd->mdp_sync_pt_data.retire_threshold = 0; |
| 1378 | break; |
| 1379 | } |
| 1380 | } |
| 1381 | |
| 1382 | static int mdss_fb_remove(struct platform_device *pdev) |
| 1383 | { |
| 1384 | struct msm_fb_data_type *mfd; |
| 1385 | |
| 1386 | mfd = (struct msm_fb_data_type *)platform_get_drvdata(pdev); |
| 1387 | |
| 1388 | if (!mfd) |
| 1389 | return -ENODEV; |
| 1390 | |
| 1391 | mdss_fb_remove_sysfs(mfd); |
| 1392 | |
| 1393 | pm_runtime_disable(mfd->fbi->dev); |
| 1394 | |
| 1395 | if (mfd->key != MFD_KEY) |
| 1396 | return -EINVAL; |
| 1397 | |
| 1398 | mdss_fb_unregister_input_handler(mfd); |
| 1399 | mdss_panel_debugfs_cleanup(mfd->panel_info); |
| 1400 | |
| 1401 | if (mdss_fb_suspend_sub(mfd)) |
| 1402 | pr_err("msm_fb_remove: can't stop the device %d\n", |
| 1403 | mfd->index); |
| 1404 | |
| 1405 | /* remove /dev/fb* */ |
| 1406 | unregister_framebuffer(mfd->fbi); |
| 1407 | |
| 1408 | if (lcd_backlight_registered) { |
| 1409 | lcd_backlight_registered = 0; |
| 1410 | led_classdev_unregister(&backlight_led); |
| 1411 | } |
| 1412 | |
| 1413 | return 0; |
| 1414 | } |
| 1415 | |
| 1416 | static int mdss_fb_send_panel_event(struct msm_fb_data_type *mfd, |
| 1417 | int event, void *arg) |
| 1418 | { |
| 1419 | int ret = 0; |
| 1420 | struct mdss_panel_data *pdata; |
| 1421 | |
| 1422 | pdata = dev_get_platdata(&mfd->pdev->dev); |
| 1423 | if (!pdata) { |
| 1424 | pr_err("no panel connected\n"); |
| 1425 | return -ENODEV; |
| 1426 | } |
| 1427 | |
| 1428 | pr_debug("sending event=%d for fb%d\n", event, mfd->index); |
| 1429 | |
| 1430 | do { |
| 1431 | if (pdata->event_handler) |
| 1432 | ret = pdata->event_handler(pdata, event, arg); |
| 1433 | |
| 1434 | pdata = pdata->next; |
| 1435 | } while (!ret && pdata); |
| 1436 | |
| 1437 | return ret; |
| 1438 | } |
| 1439 | |
| 1440 | static int mdss_fb_suspend_sub(struct msm_fb_data_type *mfd) |
| 1441 | { |
| 1442 | int ret = 0; |
| 1443 | |
| 1444 | if ((!mfd) || (mfd->key != MFD_KEY)) |
| 1445 | return 0; |
| 1446 | |
| 1447 | pr_debug("mdss_fb suspend index=%d\n", mfd->index); |
| 1448 | |
| 1449 | ret = mdss_fb_pan_idle(mfd); |
| 1450 | if (ret) { |
| 1451 | pr_warn("mdss_fb_pan_idle for fb%d failed. ret=%d\n", |
| 1452 | mfd->index, ret); |
| 1453 | goto exit; |
| 1454 | } |
| 1455 | |
| 1456 | ret = mdss_fb_send_panel_event(mfd, MDSS_EVENT_SUSPEND, NULL); |
| 1457 | if (ret) { |
| 1458 | pr_warn("unable to suspend fb%d (%d)\n", mfd->index, ret); |
| 1459 | goto exit; |
| 1460 | } |
| 1461 | |
| 1462 | mfd->suspend.op_enable = mfd->op_enable; |
| 1463 | mfd->suspend.panel_power_state = mfd->panel_power_state; |
| 1464 | |
| 1465 | if (mfd->op_enable) { |
| 1466 | /* |
| 1467 | * Ideally, display should have either been blanked by now, or |
| 1468 | * should have transitioned to a low power state. If not, then |
| 1469 | * as a fall back option, enter ulp state to leave the display |
| 1470 | * on, but turn off all interface clocks. |
| 1471 | */ |
| 1472 | if (mdss_fb_is_power_on(mfd)) { |
| 1473 | ret = mdss_fb_blank_sub(BLANK_FLAG_ULP, mfd->fbi, |
| 1474 | mfd->suspend.op_enable); |
| 1475 | if (ret) { |
| 1476 | pr_err("can't turn off display!\n"); |
| 1477 | goto exit; |
| 1478 | } |
| 1479 | } |
| 1480 | mfd->op_enable = false; |
| 1481 | fb_set_suspend(mfd->fbi, FBINFO_STATE_SUSPENDED); |
| 1482 | } |
| 1483 | exit: |
| 1484 | return ret; |
| 1485 | } |
| 1486 | |
| 1487 | static int mdss_fb_resume_sub(struct msm_fb_data_type *mfd) |
| 1488 | { |
| 1489 | int ret = 0; |
| 1490 | |
| 1491 | if ((!mfd) || (mfd->key != MFD_KEY)) |
| 1492 | return 0; |
| 1493 | |
| 1494 | reinit_completion(&mfd->power_set_comp); |
| 1495 | mfd->is_power_setting = true; |
| 1496 | pr_debug("mdss_fb resume index=%d\n", mfd->index); |
| 1497 | |
| 1498 | ret = mdss_fb_pan_idle(mfd); |
| 1499 | if (ret) { |
| 1500 | pr_warn("mdss_fb_pan_idle for fb%d failed. ret=%d\n", |
| 1501 | mfd->index, ret); |
| 1502 | return ret; |
| 1503 | } |
| 1504 | |
| 1505 | ret = mdss_fb_send_panel_event(mfd, MDSS_EVENT_RESUME, NULL); |
| 1506 | if (ret) { |
| 1507 | pr_warn("unable to resume fb%d (%d)\n", mfd->index, ret); |
| 1508 | return ret; |
| 1509 | } |
| 1510 | |
| 1511 | /* resume state var recover */ |
| 1512 | mfd->op_enable = mfd->suspend.op_enable; |
| 1513 | |
| 1514 | /* |
| 1515 | * If the fb was explicitly blanked or transitioned to ulp during |
| 1516 | * suspend, then undo it during resume with the appropriate unblank |
| 1517 | * flag. If fb was in ulp state when entering suspend, then nothing |
| 1518 | * needs to be done. |
| 1519 | */ |
| 1520 | if (mdss_panel_is_power_on(mfd->suspend.panel_power_state) && |
| 1521 | !mdss_panel_is_power_on_ulp(mfd->suspend.panel_power_state)) { |
| 1522 | int unblank_flag = mdss_panel_is_power_on_interactive( |
| 1523 | mfd->suspend.panel_power_state) ? FB_BLANK_UNBLANK : |
| 1524 | BLANK_FLAG_LP; |
| 1525 | |
| 1526 | ret = mdss_fb_blank_sub(unblank_flag, mfd->fbi, mfd->op_enable); |
| 1527 | if (ret) |
| 1528 | pr_warn("can't turn on display!\n"); |
| 1529 | else |
| 1530 | fb_set_suspend(mfd->fbi, FBINFO_STATE_RUNNING); |
| 1531 | } |
| 1532 | mfd->is_power_setting = false; |
| 1533 | complete_all(&mfd->power_set_comp); |
| 1534 | |
| 1535 | return ret; |
| 1536 | } |
| 1537 | |
| 1538 | #if defined(CONFIG_PM) && !defined(CONFIG_PM_SLEEP) |
| 1539 | static int mdss_fb_suspend(struct platform_device *pdev, pm_message_t state) |
| 1540 | { |
| 1541 | struct msm_fb_data_type *mfd = platform_get_drvdata(pdev); |
| 1542 | |
| 1543 | if (!mfd) |
| 1544 | return -ENODEV; |
| 1545 | |
| 1546 | dev_dbg(&pdev->dev, "display suspend\n"); |
| 1547 | |
| 1548 | return mdss_fb_suspend_sub(mfd); |
| 1549 | } |
| 1550 | |
| 1551 | static int mdss_fb_resume(struct platform_device *pdev) |
| 1552 | { |
| 1553 | struct msm_fb_data_type *mfd = platform_get_drvdata(pdev); |
| 1554 | |
| 1555 | if (!mfd) |
| 1556 | return -ENODEV; |
| 1557 | |
| 1558 | dev_dbg(&pdev->dev, "display resume\n"); |
| 1559 | |
| 1560 | return mdss_fb_resume_sub(mfd); |
| 1561 | } |
| 1562 | #else |
| 1563 | #define mdss_fb_suspend NULL |
| 1564 | #define mdss_fb_resume NULL |
| 1565 | #endif |
| 1566 | |
| 1567 | #ifdef CONFIG_PM_SLEEP |
| 1568 | static int mdss_fb_pm_suspend(struct device *dev) |
| 1569 | { |
| 1570 | struct msm_fb_data_type *mfd = dev_get_drvdata(dev); |
| 1571 | |
| 1572 | if (!mfd) |
| 1573 | return -ENODEV; |
| 1574 | |
| 1575 | dev_dbg(dev, "display pm suspend\n"); |
| 1576 | |
| 1577 | return mdss_fb_suspend_sub(mfd); |
| 1578 | } |
| 1579 | |
| 1580 | static int mdss_fb_pm_resume(struct device *dev) |
| 1581 | { |
| 1582 | struct msm_fb_data_type *mfd = dev_get_drvdata(dev); |
| 1583 | |
| 1584 | if (!mfd) |
| 1585 | return -ENODEV; |
| 1586 | |
| 1587 | dev_dbg(dev, "display pm resume\n"); |
| 1588 | |
| 1589 | /* |
| 1590 | * It is possible that the runtime status of the fb device may |
| 1591 | * have been active when the system was suspended. Reset the runtime |
| 1592 | * status to suspended state after a complete system resume. |
| 1593 | */ |
| 1594 | pm_runtime_disable(dev); |
| 1595 | pm_runtime_set_suspended(dev); |
| 1596 | pm_runtime_enable(dev); |
| 1597 | |
| 1598 | return mdss_fb_resume_sub(mfd); |
| 1599 | } |
| 1600 | #endif |
| 1601 | |
| 1602 | static const struct dev_pm_ops mdss_fb_pm_ops = { |
| 1603 | SET_SYSTEM_SLEEP_PM_OPS(mdss_fb_pm_suspend, mdss_fb_pm_resume) |
| 1604 | }; |
| 1605 | |
| 1606 | static const struct of_device_id mdss_fb_dt_match[] = { |
| 1607 | { .compatible = "qcom,mdss-fb",}, |
| 1608 | {} |
| 1609 | }; |
| 1610 | EXPORT_COMPAT("qcom,mdss-fb"); |
| 1611 | |
| 1612 | static struct platform_driver mdss_fb_driver = { |
| 1613 | .probe = mdss_fb_probe, |
| 1614 | .remove = mdss_fb_remove, |
| 1615 | .suspend = mdss_fb_suspend, |
| 1616 | .resume = mdss_fb_resume, |
| 1617 | .shutdown = mdss_fb_shutdown, |
| 1618 | .driver = { |
| 1619 | .name = "mdss_fb", |
| 1620 | .of_match_table = mdss_fb_dt_match, |
| 1621 | .pm = &mdss_fb_pm_ops, |
| 1622 | }, |
| 1623 | }; |
| 1624 | |
| 1625 | static void mdss_fb_scale_bl(struct msm_fb_data_type *mfd, u32 *bl_lvl) |
| 1626 | { |
| 1627 | u32 temp = *bl_lvl; |
| 1628 | |
| 1629 | pr_debug("input = %d, scale = %d\n", temp, mfd->bl_scale); |
| 1630 | if (temp >= mfd->bl_min_lvl) { |
| 1631 | if (temp > mfd->panel_info->bl_max) { |
| 1632 | pr_warn("%s: invalid bl level\n", |
| 1633 | __func__); |
| 1634 | temp = mfd->panel_info->bl_max; |
| 1635 | } |
| 1636 | if (mfd->bl_scale > 1024) { |
| 1637 | pr_warn("%s: invalid bl scale\n", |
| 1638 | __func__); |
| 1639 | mfd->bl_scale = 1024; |
| 1640 | } |
| 1641 | /* |
| 1642 | * bl_scale is the numerator of |
| 1643 | * scaling fraction (x/1024) |
| 1644 | */ |
| 1645 | temp = (temp * mfd->bl_scale) / 1024; |
| 1646 | |
| 1647 | /*if less than minimum level, use min level*/ |
| 1648 | if (temp < mfd->bl_min_lvl) |
| 1649 | temp = mfd->bl_min_lvl; |
| 1650 | } |
| 1651 | pr_debug("output = %d\n", temp); |
| 1652 | |
| 1653 | (*bl_lvl) = temp; |
| 1654 | } |
| 1655 | |
| 1656 | /* must call this function from within mfd->bl_lock */ |
| 1657 | void mdss_fb_set_backlight(struct msm_fb_data_type *mfd, u32 bkl_lvl) |
| 1658 | { |
| 1659 | struct mdss_panel_data *pdata; |
| 1660 | u32 temp = bkl_lvl; |
| 1661 | bool ad_bl_notify_needed = false; |
| 1662 | bool bl_notify_needed = false; |
| 1663 | |
| 1664 | if ((((mdss_fb_is_power_off(mfd) && mfd->dcm_state != DCM_ENTER) |
| 1665 | || !mfd->allow_bl_update) && !IS_CALIB_MODE_BL(mfd)) || |
| 1666 | mfd->panel_info->cont_splash_enabled) { |
| 1667 | mfd->unset_bl_level = bkl_lvl; |
| 1668 | return; |
| 1669 | } else if (mdss_fb_is_power_on(mfd) && mfd->panel_info->panel_dead) { |
| 1670 | mfd->unset_bl_level = mfd->bl_level; |
| 1671 | } else { |
| 1672 | mfd->unset_bl_level = U32_MAX; |
| 1673 | } |
| 1674 | |
| 1675 | pdata = dev_get_platdata(&mfd->pdev->dev); |
| 1676 | |
| 1677 | if ((pdata) && (pdata->set_backlight)) { |
| 1678 | if (mfd->mdp.ad_calc_bl) |
| 1679 | (*mfd->mdp.ad_calc_bl)(mfd, temp, &temp, |
| 1680 | &ad_bl_notify_needed); |
| 1681 | if (!IS_CALIB_MODE_BL(mfd)) |
| 1682 | mdss_fb_scale_bl(mfd, &temp); |
| 1683 | /* |
| 1684 | * Even though backlight has been scaled, want to show that |
| 1685 | * backlight has been set to bkl_lvl to those that read from |
| 1686 | * sysfs node. Thus, need to set bl_level even if it appears |
| 1687 | * the backlight has already been set to the level it is at, |
| 1688 | * as well as setting bl_level to bkl_lvl even though the |
| 1689 | * backlight has been set to the scaled value. |
| 1690 | */ |
| 1691 | if (mfd->bl_level_scaled == temp) { |
| 1692 | mfd->bl_level = bkl_lvl; |
| 1693 | } else { |
| 1694 | if (mfd->bl_level != bkl_lvl) |
| 1695 | bl_notify_needed = true; |
| 1696 | pr_debug("backlight sent to panel :%d\n", temp); |
| 1697 | pdata->set_backlight(pdata, temp); |
| 1698 | mfd->bl_level = bkl_lvl; |
| 1699 | mfd->bl_level_scaled = temp; |
| 1700 | } |
| 1701 | if (ad_bl_notify_needed) |
| 1702 | mdss_fb_bl_update_notify(mfd, |
| 1703 | NOTIFY_TYPE_BL_AD_ATTEN_UPDATE); |
| 1704 | if (bl_notify_needed) |
| 1705 | mdss_fb_bl_update_notify(mfd, |
| 1706 | NOTIFY_TYPE_BL_UPDATE); |
| 1707 | } |
| 1708 | } |
| 1709 | |
| 1710 | void mdss_fb_update_backlight(struct msm_fb_data_type *mfd) |
| 1711 | { |
| 1712 | struct mdss_panel_data *pdata; |
| 1713 | u32 temp; |
| 1714 | bool bl_notify = false; |
| 1715 | |
| 1716 | if (mfd->unset_bl_level == U32_MAX) |
| 1717 | return; |
| 1718 | mutex_lock(&mfd->bl_lock); |
| 1719 | if (!mfd->allow_bl_update) { |
| 1720 | pdata = dev_get_platdata(&mfd->pdev->dev); |
| 1721 | if ((pdata) && (pdata->set_backlight)) { |
| 1722 | mfd->bl_level = mfd->unset_bl_level; |
| 1723 | temp = mfd->bl_level; |
| 1724 | if (mfd->mdp.ad_calc_bl) |
| 1725 | (*mfd->mdp.ad_calc_bl)(mfd, temp, &temp, |
| 1726 | &bl_notify); |
| 1727 | if (bl_notify) |
| 1728 | mdss_fb_bl_update_notify(mfd, |
| 1729 | NOTIFY_TYPE_BL_AD_ATTEN_UPDATE); |
| 1730 | mdss_fb_bl_update_notify(mfd, NOTIFY_TYPE_BL_UPDATE); |
| 1731 | pdata->set_backlight(pdata, temp); |
| 1732 | mfd->bl_level_scaled = mfd->unset_bl_level; |
| 1733 | mfd->allow_bl_update = true; |
| 1734 | } |
| 1735 | } |
| 1736 | mutex_unlock(&mfd->bl_lock); |
| 1737 | } |
| 1738 | |
| 1739 | static int mdss_fb_start_disp_thread(struct msm_fb_data_type *mfd) |
| 1740 | { |
| 1741 | int ret = 0; |
| 1742 | |
| 1743 | pr_debug("%pS: start display thread fb%d\n", |
| 1744 | __builtin_return_address(0), mfd->index); |
| 1745 | |
| 1746 | /* this is needed for new split request from debugfs */ |
| 1747 | mdss_fb_get_split(mfd); |
| 1748 | |
| 1749 | atomic_set(&mfd->commits_pending, 0); |
| 1750 | mfd->disp_thread = kthread_run(__mdss_fb_display_thread, |
| 1751 | mfd, "mdss_fb%d", mfd->index); |
| 1752 | |
| 1753 | if (IS_ERR(mfd->disp_thread)) { |
| 1754 | pr_err("ERROR: unable to start display thread %d\n", |
| 1755 | mfd->index); |
| 1756 | ret = PTR_ERR(mfd->disp_thread); |
| 1757 | mfd->disp_thread = NULL; |
| 1758 | } |
| 1759 | |
| 1760 | return ret; |
| 1761 | } |
| 1762 | |
| 1763 | static void mdss_fb_stop_disp_thread(struct msm_fb_data_type *mfd) |
| 1764 | { |
| 1765 | pr_debug("%pS: stop display thread fb%d\n", |
| 1766 | __builtin_return_address(0), mfd->index); |
| 1767 | |
| 1768 | kthread_stop(mfd->disp_thread); |
| 1769 | mfd->disp_thread = NULL; |
| 1770 | } |
| 1771 | |
| 1772 | static void mdss_panel_validate_debugfs_info(struct msm_fb_data_type *mfd) |
| 1773 | { |
| 1774 | struct mdss_panel_info *panel_info = mfd->panel_info; |
| 1775 | struct fb_info *fbi = mfd->fbi; |
| 1776 | struct fb_var_screeninfo *var = &fbi->var; |
| 1777 | struct mdss_panel_data *pdata = container_of(panel_info, |
| 1778 | struct mdss_panel_data, panel_info); |
| 1779 | |
| 1780 | if (panel_info->debugfs_info->override_flag) { |
| 1781 | if (mfd->mdp.off_fnc) { |
| 1782 | mfd->panel_reconfig = true; |
| 1783 | mfd->mdp.off_fnc(mfd); |
| 1784 | mfd->panel_reconfig = false; |
| 1785 | } |
| 1786 | |
| 1787 | pr_debug("Overriding panel_info with debugfs_info\n"); |
| 1788 | panel_info->debugfs_info->override_flag = 0; |
| 1789 | mdss_panel_debugfsinfo_to_panelinfo(panel_info); |
| 1790 | if (is_panel_split(mfd) && pdata->next) |
| 1791 | mdss_fb_validate_split(pdata->panel_info.xres, |
| 1792 | pdata->next->panel_info.xres, mfd); |
| 1793 | mdss_panelinfo_to_fb_var(panel_info, var); |
| 1794 | if (mdss_fb_send_panel_event(mfd, MDSS_EVENT_CHECK_PARAMS, |
| 1795 | panel_info)) |
| 1796 | pr_err("Failed to send panel event CHECK_PARAMS\n"); |
| 1797 | } |
| 1798 | } |
| 1799 | |
| 1800 | static int mdss_fb_blank_blank(struct msm_fb_data_type *mfd, |
| 1801 | int req_power_state) |
| 1802 | { |
| 1803 | int ret = 0; |
| 1804 | int cur_power_state, current_bl; |
| 1805 | |
| 1806 | if (!mfd) |
| 1807 | return -EINVAL; |
| 1808 | |
| 1809 | if (!mdss_fb_is_power_on(mfd) || !mfd->mdp.off_fnc) |
| 1810 | return 0; |
| 1811 | |
| 1812 | cur_power_state = mfd->panel_power_state; |
| 1813 | |
| 1814 | pr_debug("Transitioning from %d --> %d\n", cur_power_state, |
| 1815 | req_power_state); |
| 1816 | |
| 1817 | if (cur_power_state == req_power_state) { |
| 1818 | pr_debug("No change in power state\n"); |
| 1819 | return 0; |
| 1820 | } |
| 1821 | |
| 1822 | mutex_lock(&mfd->update.lock); |
| 1823 | mfd->update.type = NOTIFY_TYPE_SUSPEND; |
| 1824 | mfd->update.is_suspend = 1; |
| 1825 | mutex_unlock(&mfd->update.lock); |
| 1826 | complete(&mfd->update.comp); |
| 1827 | del_timer(&mfd->no_update.timer); |
| 1828 | mfd->no_update.value = NOTIFY_TYPE_SUSPEND; |
| 1829 | complete(&mfd->no_update.comp); |
| 1830 | |
| 1831 | mfd->op_enable = false; |
| 1832 | if (mdss_panel_is_power_off(req_power_state)) { |
| 1833 | /* Stop Display thread */ |
| 1834 | if (mfd->disp_thread) |
| 1835 | mdss_fb_stop_disp_thread(mfd); |
| 1836 | mutex_lock(&mfd->bl_lock); |
| 1837 | current_bl = mfd->bl_level; |
| 1838 | mfd->allow_bl_update = true; |
| 1839 | mdss_fb_set_backlight(mfd, 0); |
| 1840 | mfd->allow_bl_update = false; |
| 1841 | mfd->unset_bl_level = current_bl; |
| 1842 | mutex_unlock(&mfd->bl_lock); |
| 1843 | } |
| 1844 | mfd->panel_power_state = req_power_state; |
| 1845 | |
| 1846 | ret = mfd->mdp.off_fnc(mfd); |
| 1847 | if (ret) |
| 1848 | mfd->panel_power_state = cur_power_state; |
| 1849 | else if (mdss_panel_is_power_off(req_power_state)) |
| 1850 | mdss_fb_release_fences(mfd); |
| 1851 | mfd->op_enable = true; |
| 1852 | complete(&mfd->power_off_comp); |
| 1853 | |
| 1854 | return ret; |
| 1855 | } |
| 1856 | |
| 1857 | static int mdss_fb_blank_unblank(struct msm_fb_data_type *mfd) |
| 1858 | { |
| 1859 | int ret = 0; |
| 1860 | int cur_power_state; |
| 1861 | |
| 1862 | if (!mfd) |
| 1863 | return -EINVAL; |
| 1864 | |
| 1865 | if (mfd->panel_info->debugfs_info) |
| 1866 | mdss_panel_validate_debugfs_info(mfd); |
| 1867 | |
| 1868 | /* Start Display thread */ |
| 1869 | if (mfd->disp_thread == NULL) { |
| 1870 | ret = mdss_fb_start_disp_thread(mfd); |
Sachin Bhayare | 3d3767e | 2018-01-02 21:10:57 +0530 | [diff] [blame] | 1871 | if (IS_ERR_VALUE((unsigned long)ret)) |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 1872 | return ret; |
| 1873 | } |
| 1874 | |
| 1875 | cur_power_state = mfd->panel_power_state; |
| 1876 | pr_debug("Transitioning from %d --> %d\n", cur_power_state, |
| 1877 | MDSS_PANEL_POWER_ON); |
| 1878 | |
| 1879 | if (mdss_panel_is_power_on_interactive(cur_power_state)) { |
| 1880 | pr_debug("No change in power state\n"); |
| 1881 | return 0; |
| 1882 | } |
| 1883 | |
| 1884 | if (mfd->mdp.on_fnc) { |
| 1885 | struct mdss_panel_info *panel_info = mfd->panel_info; |
| 1886 | struct fb_var_screeninfo *var = &mfd->fbi->var; |
| 1887 | |
| 1888 | ret = mfd->mdp.on_fnc(mfd); |
| 1889 | if (ret) { |
| 1890 | mdss_fb_stop_disp_thread(mfd); |
| 1891 | goto error; |
| 1892 | } |
| 1893 | |
| 1894 | mfd->panel_power_state = MDSS_PANEL_POWER_ON; |
| 1895 | mfd->panel_info->panel_dead = false; |
| 1896 | mutex_lock(&mfd->update.lock); |
| 1897 | mfd->update.type = NOTIFY_TYPE_UPDATE; |
| 1898 | mfd->update.is_suspend = 0; |
| 1899 | mutex_unlock(&mfd->update.lock); |
| 1900 | |
| 1901 | /* |
| 1902 | * Panel info can change depending in the information |
| 1903 | * programmed in the controller. |
| 1904 | * Update this info in the upstream structs. |
| 1905 | */ |
| 1906 | mdss_panelinfo_to_fb_var(panel_info, var); |
| 1907 | |
| 1908 | /* Start the work thread to signal idle time */ |
| 1909 | if (mfd->idle_time) |
| 1910 | schedule_delayed_work(&mfd->idle_notify_work, |
| 1911 | msecs_to_jiffies(mfd->idle_time)); |
| 1912 | } |
| 1913 | |
| 1914 | /* Reset the backlight only if the panel was off */ |
| 1915 | if (mdss_panel_is_power_off(cur_power_state)) { |
| 1916 | mutex_lock(&mfd->bl_lock); |
| 1917 | if (!mfd->allow_bl_update) { |
| 1918 | mfd->allow_bl_update = true; |
| 1919 | /* |
| 1920 | * If in AD calibration mode then frameworks would not |
| 1921 | * be allowed to update backlight hence post unblank |
| 1922 | * the backlight would remain 0 (0 is set in blank). |
| 1923 | * Hence resetting back to calibration mode value |
| 1924 | */ |
| 1925 | if (IS_CALIB_MODE_BL(mfd)) |
| 1926 | mdss_fb_set_backlight(mfd, mfd->calib_mode_bl); |
| 1927 | else if ((!mfd->panel_info->mipi.post_init_delay) && |
| 1928 | (mfd->unset_bl_level != U32_MAX)) |
| 1929 | mdss_fb_set_backlight(mfd, mfd->unset_bl_level); |
| 1930 | |
| 1931 | /* |
| 1932 | * it blocks the backlight update between unblank and |
| 1933 | * first kickoff to avoid backlight turn on before black |
| 1934 | * frame is transferred to panel through unblank call. |
| 1935 | */ |
| 1936 | mfd->allow_bl_update = false; |
| 1937 | } |
| 1938 | mutex_unlock(&mfd->bl_lock); |
| 1939 | } |
| 1940 | |
| 1941 | error: |
| 1942 | return ret; |
| 1943 | } |
| 1944 | |
| 1945 | static int mdss_fb_blank_sub(int blank_mode, struct fb_info *info, |
| 1946 | int op_enable) |
| 1947 | { |
| 1948 | struct msm_fb_data_type *mfd = (struct msm_fb_data_type *)info->par; |
| 1949 | int ret = 0; |
| 1950 | int cur_power_state, req_power_state = MDSS_PANEL_POWER_OFF; |
| 1951 | char trace_buffer[32]; |
| 1952 | |
| 1953 | if (!mfd || !op_enable) |
| 1954 | return -EPERM; |
| 1955 | |
| 1956 | if (mfd->dcm_state == DCM_ENTER) |
| 1957 | return -EPERM; |
| 1958 | |
| 1959 | pr_debug("%pS mode:%d\n", __builtin_return_address(0), |
| 1960 | blank_mode); |
| 1961 | |
| 1962 | snprintf(trace_buffer, sizeof(trace_buffer), "fb%d blank %d", |
| 1963 | mfd->index, blank_mode); |
| 1964 | ATRACE_BEGIN(trace_buffer); |
| 1965 | |
| 1966 | cur_power_state = mfd->panel_power_state; |
| 1967 | |
| 1968 | /* |
| 1969 | * Low power (lp) and ultra low power (ulp) modes are currently only |
| 1970 | * supported for command mode panels. For all other panel, treat lp |
| 1971 | * mode as full unblank and ulp mode as full blank. |
| 1972 | */ |
| 1973 | if (mfd->panel_info->type != MIPI_CMD_PANEL) { |
| 1974 | if (blank_mode == BLANK_FLAG_LP) { |
| 1975 | pr_debug("lp mode only valid for cmd mode panels\n"); |
| 1976 | if (mdss_fb_is_power_on_interactive(mfd)) |
| 1977 | return 0; |
| 1978 | blank_mode = FB_BLANK_UNBLANK; |
| 1979 | } else if (blank_mode == BLANK_FLAG_ULP) { |
| 1980 | pr_debug("ulp mode valid for cmd mode panels\n"); |
| 1981 | if (mdss_fb_is_power_off(mfd)) |
| 1982 | return 0; |
| 1983 | blank_mode = FB_BLANK_POWERDOWN; |
| 1984 | } |
| 1985 | } |
| 1986 | |
| 1987 | switch (blank_mode) { |
| 1988 | case FB_BLANK_UNBLANK: |
| 1989 | pr_debug("unblank called. cur pwr state=%d\n", cur_power_state); |
| 1990 | ret = mdss_fb_blank_unblank(mfd); |
| 1991 | break; |
| 1992 | case BLANK_FLAG_ULP: |
| 1993 | req_power_state = MDSS_PANEL_POWER_LP2; |
| 1994 | pr_debug("ultra low power mode requested\n"); |
| 1995 | if (mdss_fb_is_power_off(mfd)) { |
| 1996 | pr_debug("Unsupp transition: off --> ulp\n"); |
| 1997 | return 0; |
| 1998 | } |
| 1999 | |
| 2000 | ret = mdss_fb_blank_blank(mfd, req_power_state); |
| 2001 | break; |
| 2002 | case BLANK_FLAG_LP: |
| 2003 | req_power_state = MDSS_PANEL_POWER_LP1; |
| 2004 | pr_debug(" power mode requested\n"); |
| 2005 | |
| 2006 | /* |
| 2007 | * If low power mode is requested when panel is already off, |
| 2008 | * then first unblank the panel before entering low power mode |
| 2009 | */ |
| 2010 | if (mdss_fb_is_power_off(mfd) && mfd->mdp.on_fnc) { |
| 2011 | pr_debug("off --> lp. switch to on first\n"); |
| 2012 | ret = mdss_fb_blank_unblank(mfd); |
| 2013 | if (ret) |
| 2014 | break; |
| 2015 | } |
| 2016 | |
| 2017 | ret = mdss_fb_blank_blank(mfd, req_power_state); |
| 2018 | break; |
| 2019 | case FB_BLANK_HSYNC_SUSPEND: |
| 2020 | case FB_BLANK_POWERDOWN: |
| 2021 | default: |
| 2022 | req_power_state = MDSS_PANEL_POWER_OFF; |
| 2023 | pr_debug("blank powerdown called\n"); |
| 2024 | ret = mdss_fb_blank_blank(mfd, req_power_state); |
| 2025 | break; |
| 2026 | } |
| 2027 | |
| 2028 | /* Notify listeners */ |
| 2029 | sysfs_notify(&mfd->fbi->dev->kobj, NULL, "show_blank_event"); |
| 2030 | |
| 2031 | ATRACE_END(trace_buffer); |
| 2032 | |
| 2033 | return ret; |
| 2034 | } |
| 2035 | |
| 2036 | static int mdss_fb_blank(int blank_mode, struct fb_info *info) |
| 2037 | { |
| 2038 | int ret; |
| 2039 | struct mdss_panel_data *pdata; |
| 2040 | struct msm_fb_data_type *mfd = (struct msm_fb_data_type *)info->par; |
| 2041 | |
| 2042 | ret = mdss_fb_pan_idle(mfd); |
| 2043 | if (ret) { |
| 2044 | pr_warn("mdss_fb_pan_idle for fb%d failed. ret=%d\n", |
| 2045 | mfd->index, ret); |
| 2046 | return ret; |
| 2047 | } |
| 2048 | mutex_lock(&mfd->mdss_sysfs_lock); |
| 2049 | if (mfd->op_enable == 0) { |
| 2050 | if (blank_mode == FB_BLANK_UNBLANK) |
| 2051 | mfd->suspend.panel_power_state = MDSS_PANEL_POWER_ON; |
| 2052 | else if (blank_mode == BLANK_FLAG_ULP) |
| 2053 | mfd->suspend.panel_power_state = MDSS_PANEL_POWER_LP2; |
| 2054 | else if (blank_mode == BLANK_FLAG_LP) |
| 2055 | mfd->suspend.panel_power_state = MDSS_PANEL_POWER_LP1; |
| 2056 | else |
| 2057 | mfd->suspend.panel_power_state = MDSS_PANEL_POWER_OFF; |
| 2058 | ret = 0; |
| 2059 | goto end; |
| 2060 | } |
| 2061 | pr_debug("mode: %d\n", blank_mode); |
| 2062 | |
| 2063 | pdata = dev_get_platdata(&mfd->pdev->dev); |
| 2064 | |
| 2065 | if (pdata->panel_info.is_lpm_mode && |
| 2066 | blank_mode == FB_BLANK_UNBLANK) { |
| 2067 | pr_debug("panel is in lpm mode\n"); |
| 2068 | mfd->mdp.configure_panel(mfd, 0, 1); |
| 2069 | mdss_fb_set_mdp_sync_pt_threshold(mfd, mfd->panel.type); |
| 2070 | pdata->panel_info.is_lpm_mode = false; |
| 2071 | } |
| 2072 | |
| 2073 | ret = mdss_fb_blank_sub(blank_mode, info, mfd->op_enable); |
| 2074 | |
| 2075 | end: |
| 2076 | mutex_unlock(&mfd->mdss_sysfs_lock); |
| 2077 | return ret; |
| 2078 | } |
| 2079 | |
| 2080 | static inline int mdss_fb_create_ion_client(struct msm_fb_data_type *mfd) |
| 2081 | { |
| 2082 | mfd->fb_ion_client = msm_ion_client_create("mdss_fb_iclient"); |
| 2083 | if (IS_ERR_OR_NULL(mfd->fb_ion_client)) { |
| 2084 | pr_err("Err:client not created, val %d\n", |
| 2085 | PTR_RET(mfd->fb_ion_client)); |
| 2086 | mfd->fb_ion_client = NULL; |
| 2087 | return PTR_RET(mfd->fb_ion_client); |
| 2088 | } |
| 2089 | return 0; |
| 2090 | } |
| 2091 | |
| 2092 | void mdss_fb_free_fb_ion_memory(struct msm_fb_data_type *mfd) |
| 2093 | { |
| 2094 | if (!mfd) { |
| 2095 | pr_err("no mfd\n"); |
| 2096 | return; |
| 2097 | } |
| 2098 | |
| 2099 | if (!mfd->fbi->screen_base) |
| 2100 | return; |
| 2101 | |
| 2102 | if (!mfd->fb_ion_client || !mfd->fb_ion_handle) { |
| 2103 | pr_err("invalid input parameters for fb%d\n", mfd->index); |
| 2104 | return; |
| 2105 | } |
| 2106 | |
| 2107 | mfd->fbi->screen_base = NULL; |
| 2108 | mfd->fbi->fix.smem_start = 0; |
| 2109 | |
| 2110 | ion_unmap_kernel(mfd->fb_ion_client, mfd->fb_ion_handle); |
| 2111 | |
| 2112 | if (mfd->mdp.fb_mem_get_iommu_domain && !(!mfd->fb_attachment || |
| 2113 | !mfd->fb_attachment->dmabuf || |
| 2114 | !mfd->fb_attachment->dmabuf->ops)) { |
| 2115 | dma_buf_unmap_attachment(mfd->fb_attachment, mfd->fb_table, |
| 2116 | DMA_BIDIRECTIONAL); |
| 2117 | dma_buf_detach(mfd->fbmem_buf, mfd->fb_attachment); |
| 2118 | dma_buf_put(mfd->fbmem_buf); |
| 2119 | } |
| 2120 | |
| 2121 | ion_free(mfd->fb_ion_client, mfd->fb_ion_handle); |
| 2122 | mfd->fb_ion_handle = NULL; |
| 2123 | mfd->fbmem_buf = NULL; |
| 2124 | } |
| 2125 | |
| 2126 | int mdss_fb_alloc_fb_ion_memory(struct msm_fb_data_type *mfd, size_t fb_size) |
| 2127 | { |
| 2128 | int rc = 0; |
| 2129 | void *vaddr; |
| 2130 | int domain; |
| 2131 | |
| 2132 | if (!mfd) { |
| 2133 | pr_err("Invalid input param - no mfd\n"); |
| 2134 | return -EINVAL; |
| 2135 | } |
| 2136 | |
| 2137 | if (!mfd->fb_ion_client) { |
| 2138 | rc = mdss_fb_create_ion_client(mfd); |
| 2139 | if (rc < 0) { |
| 2140 | pr_err("fb ion client couldn't be created - %d\n", rc); |
| 2141 | return rc; |
| 2142 | } |
| 2143 | } |
| 2144 | |
| 2145 | pr_debug("size for mmap = %zu\n", fb_size); |
| 2146 | mfd->fb_ion_handle = ion_alloc(mfd->fb_ion_client, fb_size, SZ_4K, |
| 2147 | ION_HEAP(ION_SYSTEM_HEAP_ID), 0); |
| 2148 | if (IS_ERR_OR_NULL(mfd->fb_ion_handle)) { |
| 2149 | pr_err("unable to alloc fbmem from ion - %ld\n", |
| 2150 | PTR_ERR(mfd->fb_ion_handle)); |
| 2151 | return PTR_ERR(mfd->fb_ion_handle); |
| 2152 | } |
| 2153 | |
| 2154 | if (mfd->mdp.fb_mem_get_iommu_domain) { |
| 2155 | mfd->fbmem_buf = ion_share_dma_buf(mfd->fb_ion_client, |
| 2156 | mfd->fb_ion_handle); |
| 2157 | if (IS_ERR(mfd->fbmem_buf)) { |
| 2158 | rc = PTR_ERR(mfd->fbmem_buf); |
| 2159 | goto fb_mmap_failed; |
| 2160 | } |
| 2161 | |
| 2162 | domain = mfd->mdp.fb_mem_get_iommu_domain(); |
| 2163 | |
| 2164 | mfd->fb_attachment = mdss_smmu_dma_buf_attach(mfd->fbmem_buf, |
| 2165 | &mfd->pdev->dev, domain); |
| 2166 | if (IS_ERR(mfd->fb_attachment)) { |
| 2167 | rc = PTR_ERR(mfd->fb_attachment); |
| 2168 | goto err_put; |
| 2169 | } |
| 2170 | |
| 2171 | mfd->fb_table = dma_buf_map_attachment(mfd->fb_attachment, |
| 2172 | DMA_BIDIRECTIONAL); |
| 2173 | if (IS_ERR(mfd->fb_table)) { |
| 2174 | rc = PTR_ERR(mfd->fb_table); |
| 2175 | goto err_detach; |
| 2176 | } |
| 2177 | } else { |
| 2178 | pr_err("No IOMMU Domain\n"); |
| 2179 | rc = -EINVAL; |
| 2180 | goto fb_mmap_failed; |
| 2181 | } |
| 2182 | |
| 2183 | vaddr = ion_map_kernel(mfd->fb_ion_client, mfd->fb_ion_handle); |
| 2184 | if (IS_ERR_OR_NULL(vaddr)) { |
| 2185 | pr_err("ION memory mapping failed - %ld\n", PTR_ERR(vaddr)); |
| 2186 | rc = PTR_ERR(vaddr); |
| 2187 | goto err_unmap; |
| 2188 | } |
| 2189 | pr_debug("alloc 0x%zxB vaddr = %pK for fb%d\n", fb_size, |
| 2190 | vaddr, mfd->index); |
| 2191 | |
| 2192 | mfd->fbi->screen_base = (char *) vaddr; |
| 2193 | mfd->fbi->fix.smem_len = fb_size; |
| 2194 | |
| 2195 | return rc; |
| 2196 | |
| 2197 | err_unmap: |
| 2198 | dma_buf_unmap_attachment(mfd->fb_attachment, mfd->fb_table, |
| 2199 | DMA_BIDIRECTIONAL); |
| 2200 | err_detach: |
| 2201 | dma_buf_detach(mfd->fbmem_buf, mfd->fb_attachment); |
| 2202 | err_put: |
| 2203 | dma_buf_put(mfd->fbmem_buf); |
| 2204 | fb_mmap_failed: |
| 2205 | ion_free(mfd->fb_ion_client, mfd->fb_ion_handle); |
| 2206 | mfd->fb_attachment = NULL; |
| 2207 | mfd->fb_table = NULL; |
| 2208 | mfd->fb_ion_handle = NULL; |
| 2209 | mfd->fbmem_buf = NULL; |
| 2210 | return rc; |
| 2211 | } |
| 2212 | |
| 2213 | /** |
| 2214 | * mdss_fb_fbmem_ion_mmap() - Custom fb mmap() function for MSM driver. |
| 2215 | * |
| 2216 | * @info - Framebuffer info. |
| 2217 | * @vma - VM area which is part of the process virtual memory. |
| 2218 | * |
| 2219 | * This framebuffer mmap function differs from standard mmap() function by |
| 2220 | * allowing for customized page-protection and dynamically allocate framebuffer |
| 2221 | * memory from system heap and map to iommu virtual address. |
| 2222 | * |
| 2223 | * Return: virtual address is returned through vma |
| 2224 | */ |
| 2225 | static int mdss_fb_fbmem_ion_mmap(struct fb_info *info, |
| 2226 | struct vm_area_struct *vma) |
| 2227 | { |
| 2228 | int rc = 0; |
| 2229 | size_t req_size, fb_size; |
| 2230 | struct msm_fb_data_type *mfd = (struct msm_fb_data_type *)info->par; |
| 2231 | struct sg_table *table; |
| 2232 | unsigned long addr = vma->vm_start; |
| 2233 | unsigned long offset = vma->vm_pgoff * PAGE_SIZE; |
| 2234 | struct scatterlist *sg; |
| 2235 | unsigned int i; |
| 2236 | struct page *page; |
| 2237 | |
| 2238 | if (!mfd || !mfd->pdev || !mfd->pdev->dev.of_node) { |
| 2239 | pr_err("Invalid device node\n"); |
| 2240 | return -ENODEV; |
| 2241 | } |
| 2242 | |
| 2243 | req_size = vma->vm_end - vma->vm_start; |
| 2244 | fb_size = mfd->fbi->fix.smem_len; |
| 2245 | if (req_size > fb_size) { |
| 2246 | pr_warn("requested map is greater than framebuffer\n"); |
| 2247 | return -EOVERFLOW; |
| 2248 | } |
| 2249 | |
| 2250 | if (!mfd->fbi->screen_base) { |
| 2251 | rc = mdss_fb_alloc_fb_ion_memory(mfd, fb_size); |
| 2252 | if (rc < 0) { |
| 2253 | pr_err("fb mmap failed!!!!\n"); |
| 2254 | return rc; |
| 2255 | } |
| 2256 | } |
| 2257 | |
| 2258 | table = mfd->fb_table; |
| 2259 | if (IS_ERR(table)) { |
| 2260 | pr_err("Unable to get sg_table from ion:%ld\n", PTR_ERR(table)); |
| 2261 | mfd->fbi->screen_base = NULL; |
| 2262 | return PTR_ERR(table); |
| 2263 | } else if (!table) { |
| 2264 | pr_err("sg_list is NULL\n"); |
| 2265 | mfd->fbi->screen_base = NULL; |
| 2266 | return -EINVAL; |
| 2267 | } |
| 2268 | |
| 2269 | page = sg_page(table->sgl); |
| 2270 | if (page) { |
| 2271 | for_each_sg(table->sgl, sg, table->nents, i) { |
| 2272 | unsigned long remainder = vma->vm_end - addr; |
| 2273 | unsigned long len = sg->length; |
| 2274 | |
| 2275 | page = sg_page(sg); |
| 2276 | |
| 2277 | if (offset >= sg->length) { |
| 2278 | offset -= sg->length; |
| 2279 | continue; |
| 2280 | } else if (offset) { |
| 2281 | page += offset / PAGE_SIZE; |
| 2282 | len = sg->length - offset; |
| 2283 | offset = 0; |
| 2284 | } |
| 2285 | len = min(len, remainder); |
| 2286 | |
| 2287 | if (mfd->mdp_fb_page_protection == |
| 2288 | MDP_FB_PAGE_PROTECTION_WRITECOMBINE) |
| 2289 | vma->vm_page_prot = |
| 2290 | pgprot_writecombine(vma->vm_page_prot); |
| 2291 | |
| 2292 | pr_debug("vma=%pK, addr=%x len=%ld\n", |
| 2293 | vma, (unsigned int)addr, len); |
| 2294 | pr_debug("vm_start=%x vm_end=%x vm_page_prot=%ld\n", |
| 2295 | (unsigned int)vma->vm_start, |
| 2296 | (unsigned int)vma->vm_end, |
Sachin Bhayare | 3d3767e | 2018-01-02 21:10:57 +0530 | [diff] [blame] | 2297 | (unsigned long int)vma->vm_page_prot.pgprot); |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 2298 | |
| 2299 | io_remap_pfn_range(vma, addr, page_to_pfn(page), len, |
| 2300 | vma->vm_page_prot); |
| 2301 | addr += len; |
| 2302 | if (addr >= vma->vm_end) |
| 2303 | break; |
| 2304 | } |
| 2305 | } else { |
| 2306 | pr_err("PAGE is null\n"); |
| 2307 | mdss_fb_free_fb_ion_memory(mfd); |
| 2308 | return -ENOMEM; |
| 2309 | } |
| 2310 | |
| 2311 | return rc; |
| 2312 | } |
| 2313 | |
| 2314 | /* |
| 2315 | * mdss_fb_physical_mmap() - Custom fb mmap() function for MSM driver. |
| 2316 | * |
| 2317 | * @info - Framebuffer info. |
| 2318 | * @vma - VM area which is part of the process virtual memory. |
| 2319 | * |
| 2320 | * This framebuffer mmap function differs from standard mmap() function as |
| 2321 | * map to framebuffer memory from the CMA memory which is allocated during |
| 2322 | * bootup. |
| 2323 | * |
| 2324 | * Return: virtual address is returned through vma |
| 2325 | */ |
| 2326 | static int mdss_fb_physical_mmap(struct fb_info *info, |
| 2327 | struct vm_area_struct *vma) |
| 2328 | { |
| 2329 | /* Get frame buffer memory range. */ |
| 2330 | unsigned long start = info->fix.smem_start; |
| 2331 | u32 len = PAGE_ALIGN((start & ~PAGE_MASK) + info->fix.smem_len); |
| 2332 | unsigned long off = vma->vm_pgoff << PAGE_SHIFT; |
| 2333 | struct msm_fb_data_type *mfd = (struct msm_fb_data_type *)info->par; |
| 2334 | |
| 2335 | if (!start) { |
| 2336 | pr_warn("No framebuffer memory is allocated\n"); |
| 2337 | return -ENOMEM; |
| 2338 | } |
| 2339 | |
| 2340 | /* Set VM flags. */ |
| 2341 | start &= PAGE_MASK; |
| 2342 | if ((vma->vm_end <= vma->vm_start) || |
| 2343 | (off >= len) || |
| 2344 | ((vma->vm_end - vma->vm_start) > (len - off))) |
| 2345 | return -EINVAL; |
| 2346 | off += start; |
| 2347 | if (off < start) |
| 2348 | return -EINVAL; |
| 2349 | vma->vm_pgoff = off >> PAGE_SHIFT; |
| 2350 | /* This is an IO map - tell maydump to skip this VMA */ |
| 2351 | vma->vm_flags |= VM_IO; |
| 2352 | |
| 2353 | if (mfd->mdp_fb_page_protection == MDP_FB_PAGE_PROTECTION_WRITECOMBINE) |
| 2354 | vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot); |
| 2355 | |
| 2356 | /* Remap the frame buffer I/O range */ |
| 2357 | if (io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT, |
| 2358 | vma->vm_end - vma->vm_start, |
| 2359 | vma->vm_page_prot)) |
| 2360 | return -EAGAIN; |
| 2361 | |
| 2362 | return 0; |
| 2363 | } |
| 2364 | |
| 2365 | static int mdss_fb_mmap(struct fb_info *info, struct vm_area_struct *vma) |
| 2366 | { |
| 2367 | struct msm_fb_data_type *mfd = (struct msm_fb_data_type *)info->par; |
| 2368 | int rc = -EINVAL; |
| 2369 | |
| 2370 | if (mfd->fb_mmap_type == MDP_FB_MMAP_ION_ALLOC) { |
| 2371 | rc = mdss_fb_fbmem_ion_mmap(info, vma); |
| 2372 | } else if (mfd->fb_mmap_type == MDP_FB_MMAP_PHYSICAL_ALLOC) { |
| 2373 | rc = mdss_fb_physical_mmap(info, vma); |
| 2374 | } else { |
| 2375 | if (!info->fix.smem_start && !mfd->fb_ion_handle) { |
| 2376 | rc = mdss_fb_fbmem_ion_mmap(info, vma); |
| 2377 | mfd->fb_mmap_type = MDP_FB_MMAP_ION_ALLOC; |
| 2378 | } else { |
| 2379 | rc = mdss_fb_physical_mmap(info, vma); |
| 2380 | mfd->fb_mmap_type = MDP_FB_MMAP_PHYSICAL_ALLOC; |
| 2381 | } |
| 2382 | } |
| 2383 | if (rc < 0) |
| 2384 | pr_err("fb mmap failed with rc = %d\n", rc); |
| 2385 | |
| 2386 | return rc; |
| 2387 | } |
| 2388 | |
| 2389 | static struct fb_ops mdss_fb_ops = { |
| 2390 | .owner = THIS_MODULE, |
| 2391 | .fb_open = mdss_fb_open, |
| 2392 | .fb_release = mdss_fb_release, |
| 2393 | .fb_check_var = mdss_fb_check_var, /* vinfo check */ |
| 2394 | .fb_set_par = mdss_fb_set_par, /* set the video mode */ |
| 2395 | .fb_blank = mdss_fb_blank, /* blank display */ |
| 2396 | .fb_pan_display = mdss_fb_pan_display, /* pan display */ |
| 2397 | .fb_ioctl_v2 = mdss_fb_ioctl, /* perform fb specific ioctl */ |
| 2398 | #ifdef CONFIG_COMPAT |
| 2399 | .fb_compat_ioctl_v2 = mdss_fb_compat_ioctl, |
| 2400 | #endif |
| 2401 | .fb_mmap = mdss_fb_mmap, |
| 2402 | }; |
| 2403 | |
| 2404 | static int mdss_fb_alloc_fbmem_iommu(struct msm_fb_data_type *mfd, int dom) |
| 2405 | { |
| 2406 | void *virt = NULL; |
| 2407 | phys_addr_t phys = 0; |
| 2408 | size_t size = 0; |
| 2409 | struct platform_device *pdev = mfd->pdev; |
| 2410 | int rc = 0; |
| 2411 | struct device_node *fbmem_pnode = NULL; |
| 2412 | |
| 2413 | if (!pdev || !pdev->dev.of_node) { |
| 2414 | pr_err("Invalid device node\n"); |
| 2415 | return -ENODEV; |
| 2416 | } |
| 2417 | |
| 2418 | fbmem_pnode = of_parse_phandle(pdev->dev.of_node, |
| 2419 | "linux,contiguous-region", 0); |
| 2420 | if (!fbmem_pnode) { |
| 2421 | pr_debug("fbmem is not reserved for %s\n", pdev->name); |
| 2422 | mfd->fbi->screen_base = NULL; |
| 2423 | mfd->fbi->fix.smem_start = 0; |
| 2424 | return 0; |
| 2425 | } |
| 2426 | { |
| 2427 | const u32 *addr; |
| 2428 | u64 len; |
| 2429 | |
| 2430 | addr = of_get_address(fbmem_pnode, 0, &len, NULL); |
| 2431 | if (!addr) { |
| 2432 | pr_err("fbmem size is not specified\n"); |
| 2433 | of_node_put(fbmem_pnode); |
| 2434 | return -EINVAL; |
| 2435 | } |
| 2436 | size = (size_t)len; |
| 2437 | of_node_put(fbmem_pnode); |
| 2438 | } |
| 2439 | |
| 2440 | pr_debug("%s frame buffer reserve_size=0x%zx\n", __func__, size); |
| 2441 | |
| 2442 | if (size < PAGE_ALIGN(mfd->fbi->fix.line_length * |
| 2443 | mfd->fbi->var.yres_virtual)) |
| 2444 | pr_warn("reserve size is smaller than framebuffer size\n"); |
| 2445 | |
| 2446 | rc = mdss_smmu_dma_alloc_coherent(&pdev->dev, size, &phys, &mfd->iova, |
| 2447 | &virt, GFP_KERNEL, dom); |
| 2448 | if (rc) { |
| 2449 | pr_err("unable to alloc fbmem size=%zx\n", size); |
| 2450 | return -ENOMEM; |
| 2451 | } |
| 2452 | |
| 2453 | if (MDSS_LPAE_CHECK(phys)) { |
| 2454 | pr_warn("fb mem phys %pa > 4GB is not supported.\n", &phys); |
| 2455 | mdss_smmu_dma_free_coherent(&pdev->dev, size, &virt, |
| 2456 | phys, mfd->iova, dom); |
| 2457 | return -ERANGE; |
| 2458 | } |
| 2459 | |
| 2460 | pr_debug("alloc 0x%zxB @ (%pa phys) (0x%pK virt) (%pa iova) for fb%d\n", |
| 2461 | size, &phys, virt, &mfd->iova, mfd->index); |
| 2462 | |
| 2463 | mfd->fbi->screen_base = virt; |
| 2464 | mfd->fbi->fix.smem_start = phys; |
| 2465 | mfd->fbi->fix.smem_len = size; |
| 2466 | |
| 2467 | return 0; |
| 2468 | } |
| 2469 | |
| 2470 | static int mdss_fb_alloc_fbmem(struct msm_fb_data_type *mfd) |
| 2471 | { |
| 2472 | |
| 2473 | if (mfd->mdp.fb_mem_alloc_fnc) { |
| 2474 | return mfd->mdp.fb_mem_alloc_fnc(mfd); |
| 2475 | } else if (mfd->mdp.fb_mem_get_iommu_domain) { |
| 2476 | int dom = mfd->mdp.fb_mem_get_iommu_domain(); |
| 2477 | |
| 2478 | if (dom >= 0) |
| 2479 | return mdss_fb_alloc_fbmem_iommu(mfd, dom); |
| 2480 | else |
| 2481 | return -ENOMEM; |
| 2482 | } else { |
| 2483 | pr_err("no fb memory allocator function defined\n"); |
| 2484 | return -ENOMEM; |
| 2485 | } |
| 2486 | } |
| 2487 | |
| 2488 | static int mdss_fb_register(struct msm_fb_data_type *mfd) |
| 2489 | { |
| 2490 | int ret = -ENODEV; |
| 2491 | int bpp; |
| 2492 | char panel_name[20]; |
| 2493 | struct mdss_panel_info *panel_info = mfd->panel_info; |
| 2494 | struct fb_info *fbi = mfd->fbi; |
| 2495 | struct fb_fix_screeninfo *fix; |
| 2496 | struct fb_var_screeninfo *var; |
| 2497 | int *id; |
| 2498 | |
| 2499 | /* |
| 2500 | * fb info initialization |
| 2501 | */ |
| 2502 | fix = &fbi->fix; |
| 2503 | var = &fbi->var; |
| 2504 | |
| 2505 | fix->type_aux = 0; /* if type == FB_TYPE_INTERLEAVED_PLANES */ |
| 2506 | fix->visual = FB_VISUAL_TRUECOLOR; /* True Color */ |
| 2507 | fix->ywrapstep = 0; /* No support */ |
| 2508 | fix->mmio_start = 0; /* No MMIO Address */ |
| 2509 | fix->mmio_len = 0; /* No MMIO Address */ |
| 2510 | fix->accel = FB_ACCEL_NONE;/* FB_ACCEL_MSM needes to be added in fb.h */ |
| 2511 | |
| 2512 | var->xoffset = 0, /* Offset from virtual to visible */ |
| 2513 | var->yoffset = 0, /* resolution */ |
| 2514 | var->grayscale = 0, /* No graylevels */ |
| 2515 | var->nonstd = 0, /* standard pixel format */ |
| 2516 | var->activate = FB_ACTIVATE_VBL, /* activate it at vsync */ |
| 2517 | var->height = -1, /* height of picture in mm */ |
| 2518 | var->width = -1, /* width of picture in mm */ |
| 2519 | var->accel_flags = 0, /* acceleration flags */ |
| 2520 | var->sync = 0, /* see FB_SYNC_* */ |
| 2521 | var->rotate = 0, /* angle we rotate counter clockwise */ |
| 2522 | mfd->op_enable = false; |
| 2523 | |
| 2524 | switch (mfd->fb_imgType) { |
| 2525 | case MDP_RGB_565: |
| 2526 | fix->type = FB_TYPE_PACKED_PIXELS; |
| 2527 | fix->xpanstep = 1; |
| 2528 | fix->ypanstep = 1; |
| 2529 | var->vmode = FB_VMODE_NONINTERLACED; |
| 2530 | var->blue.offset = 0; |
| 2531 | var->green.offset = 5; |
| 2532 | var->red.offset = 11; |
| 2533 | var->blue.length = 5; |
| 2534 | var->green.length = 6; |
| 2535 | var->red.length = 5; |
| 2536 | var->blue.msb_right = 0; |
| 2537 | var->green.msb_right = 0; |
| 2538 | var->red.msb_right = 0; |
| 2539 | var->transp.offset = 0; |
| 2540 | var->transp.length = 0; |
| 2541 | bpp = 2; |
| 2542 | break; |
| 2543 | |
| 2544 | case MDP_RGB_888: |
| 2545 | fix->type = FB_TYPE_PACKED_PIXELS; |
| 2546 | fix->xpanstep = 1; |
| 2547 | fix->ypanstep = 1; |
| 2548 | var->vmode = FB_VMODE_NONINTERLACED; |
| 2549 | var->blue.offset = 0; |
| 2550 | var->green.offset = 8; |
| 2551 | var->red.offset = 16; |
| 2552 | var->blue.length = 8; |
| 2553 | var->green.length = 8; |
| 2554 | var->red.length = 8; |
| 2555 | var->blue.msb_right = 0; |
| 2556 | var->green.msb_right = 0; |
| 2557 | var->red.msb_right = 0; |
| 2558 | var->transp.offset = 0; |
| 2559 | var->transp.length = 0; |
| 2560 | bpp = 3; |
| 2561 | break; |
| 2562 | |
| 2563 | case MDP_ARGB_8888: |
| 2564 | fix->type = FB_TYPE_PACKED_PIXELS; |
| 2565 | fix->xpanstep = 1; |
| 2566 | fix->ypanstep = 1; |
| 2567 | var->vmode = FB_VMODE_NONINTERLACED; |
| 2568 | var->blue.offset = 24; |
| 2569 | var->green.offset = 16; |
| 2570 | var->red.offset = 8; |
| 2571 | var->blue.length = 8; |
| 2572 | var->green.length = 8; |
| 2573 | var->red.length = 8; |
| 2574 | var->blue.msb_right = 0; |
| 2575 | var->green.msb_right = 0; |
| 2576 | var->red.msb_right = 0; |
| 2577 | var->transp.offset = 0; |
| 2578 | var->transp.length = 8; |
| 2579 | bpp = 4; |
| 2580 | break; |
| 2581 | |
| 2582 | case MDP_RGBA_8888: |
| 2583 | fix->type = FB_TYPE_PACKED_PIXELS; |
| 2584 | fix->xpanstep = 1; |
| 2585 | fix->ypanstep = 1; |
| 2586 | var->vmode = FB_VMODE_NONINTERLACED; |
| 2587 | var->blue.offset = 16; |
| 2588 | var->green.offset = 8; |
| 2589 | var->red.offset = 0; |
| 2590 | var->blue.length = 8; |
| 2591 | var->green.length = 8; |
| 2592 | var->red.length = 8; |
| 2593 | var->blue.msb_right = 0; |
| 2594 | var->green.msb_right = 0; |
| 2595 | var->red.msb_right = 0; |
| 2596 | var->transp.offset = 24; |
| 2597 | var->transp.length = 8; |
| 2598 | bpp = 4; |
| 2599 | break; |
| 2600 | |
| 2601 | case MDP_YCRYCB_H2V1: |
| 2602 | fix->type = FB_TYPE_INTERLEAVED_PLANES; |
| 2603 | fix->xpanstep = 2; |
| 2604 | fix->ypanstep = 1; |
| 2605 | var->vmode = FB_VMODE_NONINTERLACED; |
| 2606 | |
| 2607 | /* how about R/G/B offset? */ |
| 2608 | var->blue.offset = 0; |
| 2609 | var->green.offset = 5; |
| 2610 | var->red.offset = 11; |
| 2611 | var->blue.length = 5; |
| 2612 | var->green.length = 6; |
| 2613 | var->red.length = 5; |
| 2614 | var->blue.msb_right = 0; |
| 2615 | var->green.msb_right = 0; |
| 2616 | var->red.msb_right = 0; |
| 2617 | var->transp.offset = 0; |
| 2618 | var->transp.length = 0; |
| 2619 | bpp = 2; |
| 2620 | break; |
| 2621 | |
| 2622 | default: |
| 2623 | pr_err("msm_fb_init: fb %d unknown image type!\n", |
| 2624 | mfd->index); |
| 2625 | return ret; |
| 2626 | } |
| 2627 | |
| 2628 | mdss_panelinfo_to_fb_var(panel_info, var); |
| 2629 | |
| 2630 | fix->type = panel_info->is_3d_panel; |
| 2631 | if (mfd->mdp.fb_stride) |
| 2632 | fix->line_length = mfd->mdp.fb_stride(mfd->index, var->xres, |
| 2633 | bpp); |
| 2634 | else |
| 2635 | fix->line_length = var->xres * bpp; |
| 2636 | |
| 2637 | var->xres_virtual = var->xres; |
| 2638 | var->yres_virtual = panel_info->yres * mfd->fb_page; |
| 2639 | var->bits_per_pixel = bpp * 8; /* FrameBuffer color depth */ |
| 2640 | |
| 2641 | /* |
| 2642 | * Populate smem length here for uspace to get the |
| 2643 | * Framebuffer size when FBIO_FSCREENINFO ioctl is called. |
| 2644 | */ |
| 2645 | fix->smem_len = PAGE_ALIGN(fix->line_length * var->yres) * mfd->fb_page; |
| 2646 | |
| 2647 | /* id field for fb app */ |
| 2648 | id = (int *)&mfd->panel; |
| 2649 | |
| 2650 | snprintf(fix->id, sizeof(fix->id), "mdssfb_%x", (u32) *id); |
| 2651 | |
| 2652 | fbi->fbops = &mdss_fb_ops; |
| 2653 | fbi->flags = FBINFO_FLAG_DEFAULT; |
| 2654 | fbi->pseudo_palette = mdss_fb_pseudo_palette; |
| 2655 | |
| 2656 | mfd->ref_cnt = 0; |
| 2657 | mfd->panel_power_state = MDSS_PANEL_POWER_OFF; |
| 2658 | mfd->dcm_state = DCM_UNINIT; |
| 2659 | |
| 2660 | if (mdss_fb_alloc_fbmem(mfd)) |
| 2661 | pr_warn("unable to allocate fb memory in fb register\n"); |
| 2662 | |
| 2663 | mfd->op_enable = true; |
| 2664 | |
| 2665 | mutex_init(&mfd->update.lock); |
| 2666 | mutex_init(&mfd->no_update.lock); |
| 2667 | mutex_init(&mfd->mdp_sync_pt_data.sync_mutex); |
| 2668 | atomic_set(&mfd->mdp_sync_pt_data.commit_cnt, 0); |
| 2669 | atomic_set(&mfd->commits_pending, 0); |
| 2670 | atomic_set(&mfd->ioctl_ref_cnt, 0); |
| 2671 | atomic_set(&mfd->kickoff_pending, 0); |
| 2672 | |
| 2673 | init_timer(&mfd->no_update.timer); |
| 2674 | mfd->no_update.timer.function = mdss_fb_no_update_notify_timer_cb; |
| 2675 | mfd->no_update.timer.data = (unsigned long)mfd; |
| 2676 | mfd->update.ref_count = 0; |
| 2677 | mfd->no_update.ref_count = 0; |
| 2678 | mfd->update.init_done = false; |
| 2679 | init_completion(&mfd->update.comp); |
| 2680 | init_completion(&mfd->no_update.comp); |
| 2681 | init_completion(&mfd->power_off_comp); |
| 2682 | init_completion(&mfd->power_set_comp); |
| 2683 | init_waitqueue_head(&mfd->commit_wait_q); |
| 2684 | init_waitqueue_head(&mfd->idle_wait_q); |
| 2685 | init_waitqueue_head(&mfd->ioctl_q); |
| 2686 | init_waitqueue_head(&mfd->kickoff_wait_q); |
| 2687 | |
| 2688 | ret = fb_alloc_cmap(&fbi->cmap, 256, 0); |
| 2689 | if (ret) |
| 2690 | pr_err("fb_alloc_cmap() failed!\n"); |
| 2691 | |
| 2692 | if (register_framebuffer(fbi) < 0) { |
| 2693 | fb_dealloc_cmap(&fbi->cmap); |
| 2694 | |
| 2695 | mfd->op_enable = false; |
| 2696 | return -EPERM; |
| 2697 | } |
| 2698 | |
| 2699 | snprintf(panel_name, ARRAY_SIZE(panel_name), "mdss_panel_fb%d", |
| 2700 | mfd->index); |
| 2701 | mdss_panel_debugfs_init(panel_info, panel_name); |
| 2702 | pr_info("FrameBuffer[%d] %dx%d registered successfully!\n", mfd->index, |
| 2703 | fbi->var.xres, fbi->var.yres); |
| 2704 | |
| 2705 | return 0; |
| 2706 | } |
| 2707 | |
| 2708 | static int mdss_fb_open(struct fb_info *info, int user) |
| 2709 | { |
| 2710 | struct msm_fb_data_type *mfd = (struct msm_fb_data_type *)info->par; |
| 2711 | struct mdss_fb_file_info *file_info = NULL; |
| 2712 | int result; |
| 2713 | struct task_struct *task = current->group_leader; |
| 2714 | |
| 2715 | if (mfd->shutdown_pending) { |
| 2716 | pr_err_once("Shutdown pending. Aborting operation. Request from pid:%d name=%s\n", |
| 2717 | current->tgid, task->comm); |
| 2718 | sysfs_notify(&mfd->fbi->dev->kobj, NULL, "show_blank_event"); |
| 2719 | return -ESHUTDOWN; |
| 2720 | } |
| 2721 | |
| 2722 | file_info = kmalloc(sizeof(*file_info), GFP_KERNEL); |
| 2723 | if (!file_info) |
| 2724 | return -ENOMEM; |
| 2725 | |
| 2726 | file_info->file = info->file; |
| 2727 | list_add(&file_info->list, &mfd->file_list); |
| 2728 | |
| 2729 | result = pm_runtime_get_sync(info->dev); |
| 2730 | |
| 2731 | if (result < 0) { |
| 2732 | pr_err("pm_runtime: fail to wake up\n"); |
| 2733 | goto pm_error; |
| 2734 | } |
| 2735 | |
| 2736 | if (!mfd->ref_cnt) { |
| 2737 | result = mdss_fb_blank_sub(FB_BLANK_UNBLANK, info, |
| 2738 | mfd->op_enable); |
| 2739 | if (result) { |
| 2740 | pr_err("can't turn on fb%d! rc=%d\n", mfd->index, |
| 2741 | result); |
| 2742 | goto blank_error; |
| 2743 | } |
| 2744 | } |
| 2745 | |
| 2746 | mfd->ref_cnt++; |
| 2747 | pr_debug("mfd refcount:%d file:%pK\n", mfd->ref_cnt, info->file); |
| 2748 | |
| 2749 | return 0; |
| 2750 | |
| 2751 | blank_error: |
| 2752 | pm_runtime_put(info->dev); |
| 2753 | pm_error: |
| 2754 | list_del(&file_info->list); |
| 2755 | kfree(file_info); |
| 2756 | return result; |
| 2757 | } |
| 2758 | |
| 2759 | static int mdss_fb_release_all(struct fb_info *info, bool release_all) |
| 2760 | { |
| 2761 | struct msm_fb_data_type *mfd = (struct msm_fb_data_type *)info->par; |
| 2762 | struct mdss_fb_file_info *file_info = NULL, *temp_file_info = NULL; |
| 2763 | struct file *file = info->file; |
| 2764 | int ret = 0; |
| 2765 | bool node_found = false; |
| 2766 | struct task_struct *task = current->group_leader; |
| 2767 | |
| 2768 | if (!mfd->ref_cnt) { |
| 2769 | pr_info("try to close unopened fb %d! from pid:%d name:%s\n", |
| 2770 | mfd->index, current->tgid, task->comm); |
| 2771 | return -EINVAL; |
| 2772 | } |
| 2773 | |
| 2774 | if (!wait_event_timeout(mfd->ioctl_q, |
| 2775 | !atomic_read(&mfd->ioctl_ref_cnt) || !release_all, |
| 2776 | msecs_to_jiffies(1000))) |
| 2777 | pr_warn("fb%d ioctl could not finish. waited 1 sec.\n", |
| 2778 | mfd->index); |
| 2779 | |
| 2780 | /* wait only for the last release */ |
| 2781 | if (release_all || (mfd->ref_cnt == 1)) { |
| 2782 | ret = mdss_fb_pan_idle(mfd); |
| 2783 | if (ret && (ret != -ESHUTDOWN)) |
| 2784 | pr_warn("mdss_fb_pan_idle for fb%d failed. ret=%d ignoring.\n", |
| 2785 | mfd->index, ret); |
| 2786 | } |
| 2787 | |
| 2788 | pr_debug("release_all = %s\n", release_all ? "true" : "false"); |
| 2789 | |
| 2790 | list_for_each_entry_safe(file_info, temp_file_info, &mfd->file_list, |
| 2791 | list) { |
| 2792 | if (!release_all && file_info->file != file) |
| 2793 | continue; |
| 2794 | |
| 2795 | pr_debug("found file node mfd->ref=%d\n", mfd->ref_cnt); |
| 2796 | list_del(&file_info->list); |
| 2797 | kfree(file_info); |
| 2798 | |
| 2799 | mfd->ref_cnt--; |
| 2800 | pm_runtime_put(info->dev); |
| 2801 | |
| 2802 | node_found = true; |
| 2803 | |
| 2804 | if (!release_all) |
| 2805 | break; |
| 2806 | } |
| 2807 | |
| 2808 | if (!node_found || (release_all && mfd->ref_cnt)) |
| 2809 | pr_warn("file node not found or wrong ref cnt: release all:%d refcnt:%d\n", |
| 2810 | release_all, mfd->ref_cnt); |
| 2811 | |
| 2812 | pr_debug("current process=%s pid=%d mfd->ref=%d file:%pK\n", |
| 2813 | task->comm, current->tgid, mfd->ref_cnt, info->file); |
| 2814 | |
| 2815 | if (!mfd->ref_cnt || release_all) { |
| 2816 | /* resources (if any) will be released during blank */ |
| 2817 | if (mfd->mdp.release_fnc) |
| 2818 | mfd->mdp.release_fnc(mfd, NULL); |
| 2819 | |
| 2820 | if (mfd->mdp.pp_release_fnc) { |
| 2821 | ret = (*mfd->mdp.pp_release_fnc)(mfd); |
| 2822 | if (ret) |
| 2823 | pr_err("PP release failed ret %d\n", ret); |
| 2824 | } |
| 2825 | |
| 2826 | /* reset backlight before blank to prevent backlight from |
| 2827 | * enabling ahead of unblank. for some special cases like |
| 2828 | * adb shell stop/start. |
| 2829 | */ |
| 2830 | mdss_fb_set_backlight(mfd, 0); |
| 2831 | |
| 2832 | ret = mdss_fb_blank_sub(FB_BLANK_POWERDOWN, info, |
| 2833 | mfd->op_enable); |
| 2834 | if (ret) { |
| 2835 | pr_err("can't turn off fb%d! rc=%d current process=%s pid=%d\n", |
| 2836 | mfd->index, ret, task->comm, current->tgid); |
| 2837 | return ret; |
| 2838 | } |
| 2839 | if (mfd->fb_ion_handle) |
| 2840 | mdss_fb_free_fb_ion_memory(mfd); |
| 2841 | |
| 2842 | atomic_set(&mfd->ioctl_ref_cnt, 0); |
| 2843 | } else { |
| 2844 | if (mfd->mdp.release_fnc) |
| 2845 | ret = mfd->mdp.release_fnc(mfd, file); |
| 2846 | |
| 2847 | /* display commit is needed to release resources */ |
| 2848 | if (ret) |
| 2849 | mdss_fb_pan_display(&mfd->fbi->var, mfd->fbi); |
| 2850 | } |
| 2851 | |
| 2852 | return ret; |
| 2853 | } |
| 2854 | |
| 2855 | static int mdss_fb_release(struct fb_info *info, int user) |
| 2856 | { |
| 2857 | return mdss_fb_release_all(info, false); |
| 2858 | } |
| 2859 | |
| 2860 | static void mdss_fb_power_setting_idle(struct msm_fb_data_type *mfd) |
| 2861 | { |
| 2862 | int ret; |
| 2863 | |
| 2864 | if (mfd->is_power_setting) { |
| 2865 | ret = wait_for_completion_timeout( |
| 2866 | &mfd->power_set_comp, |
| 2867 | msecs_to_jiffies(WAIT_DISP_OP_TIMEOUT)); |
| 2868 | if (ret < 0) |
| 2869 | ret = -ERESTARTSYS; |
| 2870 | else if (!ret) |
| 2871 | pr_err("%s wait for power_set_comp timeout %d %d", |
| 2872 | __func__, ret, mfd->is_power_setting); |
| 2873 | if (ret <= 0) { |
| 2874 | mfd->is_power_setting = false; |
| 2875 | complete_all(&mfd->power_set_comp); |
| 2876 | } |
| 2877 | } |
| 2878 | } |
| 2879 | |
| 2880 | static void __mdss_fb_copy_fence(struct msm_sync_pt_data *sync_pt_data, |
Sachin Bhayare | 2b6d004 | 2018-01-13 19:38:21 +0530 | [diff] [blame] | 2881 | struct mdss_fence **fences, u32 *fence_cnt) |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 2882 | { |
| 2883 | pr_debug("%s: wait for fences\n", sync_pt_data->fence_name); |
| 2884 | |
| 2885 | mutex_lock(&sync_pt_data->sync_mutex); |
| 2886 | /* |
| 2887 | * Assuming that acq_fen_cnt is sanitized in bufsync ioctl |
| 2888 | * to check for sync_pt_data->acq_fen_cnt <= MDP_MAX_FENCE_FD |
| 2889 | */ |
| 2890 | *fence_cnt = sync_pt_data->acq_fen_cnt; |
| 2891 | sync_pt_data->acq_fen_cnt = 0; |
| 2892 | if (*fence_cnt) |
| 2893 | memcpy(fences, sync_pt_data->acq_fen, |
Sachin Bhayare | 2b6d004 | 2018-01-13 19:38:21 +0530 | [diff] [blame] | 2894 | *fence_cnt * sizeof(struct mdss_fence *)); |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 2895 | mutex_unlock(&sync_pt_data->sync_mutex); |
| 2896 | } |
| 2897 | |
| 2898 | static int __mdss_fb_wait_for_fence_sub(struct msm_sync_pt_data *sync_pt_data, |
Sachin Bhayare | 2b6d004 | 2018-01-13 19:38:21 +0530 | [diff] [blame] | 2899 | struct mdss_fence **fences, int fence_cnt) |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 2900 | { |
| 2901 | int i, ret = 0; |
| 2902 | unsigned long max_wait = msecs_to_jiffies(WAIT_MAX_FENCE_TIMEOUT); |
| 2903 | unsigned long timeout = jiffies + max_wait; |
| 2904 | long wait_ms, wait_jf; |
| 2905 | |
| 2906 | /* buf sync */ |
| 2907 | for (i = 0; i < fence_cnt && !ret; i++) { |
| 2908 | wait_jf = timeout - jiffies; |
| 2909 | wait_ms = jiffies_to_msecs(wait_jf); |
| 2910 | |
| 2911 | /* |
| 2912 | * In this loop, if one of the previous fence took long |
| 2913 | * time, give a chance for the next fence to check if |
| 2914 | * fence is already signalled. If not signalled it breaks |
| 2915 | * in the final wait timeout. |
| 2916 | */ |
| 2917 | if (wait_jf < 0) |
| 2918 | wait_ms = WAIT_MIN_FENCE_TIMEOUT; |
| 2919 | else |
| 2920 | wait_ms = min_t(long, WAIT_FENCE_FIRST_TIMEOUT, |
| 2921 | wait_ms); |
| 2922 | |
Sachin Bhayare | 2b6d004 | 2018-01-13 19:38:21 +0530 | [diff] [blame] | 2923 | ret = mdss_wait_sync_fence(fences[i], wait_ms); |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 2924 | |
| 2925 | if (ret == -ETIME) { |
| 2926 | wait_jf = timeout - jiffies; |
| 2927 | wait_ms = jiffies_to_msecs(wait_jf); |
| 2928 | if (wait_jf < 0) |
| 2929 | break; |
| 2930 | |
| 2931 | wait_ms = min_t(long, WAIT_FENCE_FINAL_TIMEOUT, |
| 2932 | wait_ms); |
| 2933 | |
| 2934 | pr_warn("%s: sync_fence_wait timed out! ", |
Sachin Bhayare | 2b6d004 | 2018-01-13 19:38:21 +0530 | [diff] [blame] | 2935 | mdss_get_sync_fence_name(fences[i])); |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 2936 | pr_cont("Waiting %ld.%ld more seconds\n", |
| 2937 | (wait_ms/MSEC_PER_SEC), (wait_ms%MSEC_PER_SEC)); |
| 2938 | MDSS_XLOG(sync_pt_data->timeline_value); |
| 2939 | MDSS_XLOG_TOUT_HANDLER("mdp"); |
Sachin Bhayare | 2b6d004 | 2018-01-13 19:38:21 +0530 | [diff] [blame] | 2940 | ret = mdss_wait_sync_fence(fences[i], wait_ms); |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 2941 | |
| 2942 | if (ret == -ETIME) |
| 2943 | break; |
| 2944 | } |
Sachin Bhayare | 2b6d004 | 2018-01-13 19:38:21 +0530 | [diff] [blame] | 2945 | mdss_put_sync_fence(fences[i]); |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 2946 | } |
| 2947 | |
| 2948 | if (ret < 0) { |
| 2949 | pr_err("%s: sync_fence_wait failed! ret = %x\n", |
| 2950 | sync_pt_data->fence_name, ret); |
| 2951 | for (; i < fence_cnt; i++) |
Sachin Bhayare | 2b6d004 | 2018-01-13 19:38:21 +0530 | [diff] [blame] | 2952 | mdss_put_sync_fence(fences[i]); |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 2953 | } |
| 2954 | return ret; |
| 2955 | } |
| 2956 | |
| 2957 | int mdss_fb_wait_for_fence(struct msm_sync_pt_data *sync_pt_data) |
| 2958 | { |
Sachin Bhayare | 2b6d004 | 2018-01-13 19:38:21 +0530 | [diff] [blame] | 2959 | struct mdss_fence *fences[MDP_MAX_FENCE_FD]; |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 2960 | int fence_cnt = 0; |
| 2961 | |
| 2962 | __mdss_fb_copy_fence(sync_pt_data, fences, &fence_cnt); |
| 2963 | |
| 2964 | if (fence_cnt) |
| 2965 | __mdss_fb_wait_for_fence_sub(sync_pt_data, |
| 2966 | fences, fence_cnt); |
| 2967 | |
| 2968 | return fence_cnt; |
| 2969 | } |
| 2970 | |
| 2971 | /** |
| 2972 | * mdss_fb_signal_timeline() - signal a single release fence |
| 2973 | * @sync_pt_data: Sync point data structure for the timeline which |
| 2974 | * should be signaled. |
| 2975 | * |
| 2976 | * This is called after a frame has been pushed to display. This signals the |
| 2977 | * timeline to release the fences associated with this frame. |
| 2978 | */ |
| 2979 | void mdss_fb_signal_timeline(struct msm_sync_pt_data *sync_pt_data) |
| 2980 | { |
| 2981 | mutex_lock(&sync_pt_data->sync_mutex); |
| 2982 | if (atomic_add_unless(&sync_pt_data->commit_cnt, -1, 0) && |
| 2983 | sync_pt_data->timeline) { |
Sachin Bhayare | 2b6d004 | 2018-01-13 19:38:21 +0530 | [diff] [blame] | 2984 | mdss_inc_timeline(sync_pt_data->timeline, 1); |
| 2985 | mdss_inc_timeline(sync_pt_data->timeline_retire, 1); |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 2986 | MDSS_XLOG(sync_pt_data->timeline_value); |
| 2987 | sync_pt_data->timeline_value++; |
| 2988 | |
| 2989 | pr_debug("%s: buffer signaled! timeline val=%d remaining=%d\n", |
| 2990 | sync_pt_data->fence_name, sync_pt_data->timeline_value, |
| 2991 | atomic_read(&sync_pt_data->commit_cnt)); |
| 2992 | } else { |
| 2993 | pr_debug("%s timeline signaled without commits val=%d\n", |
| 2994 | sync_pt_data->fence_name, sync_pt_data->timeline_value); |
| 2995 | } |
| 2996 | mutex_unlock(&sync_pt_data->sync_mutex); |
| 2997 | } |
| 2998 | |
| 2999 | /** |
| 3000 | * mdss_fb_release_fences() - signal all pending release fences |
| 3001 | * @mfd: Framebuffer data structure for display |
| 3002 | * |
| 3003 | * Release all currently pending release fences, including those that are in |
| 3004 | * the process to be commtted. |
| 3005 | * |
| 3006 | * Note: this should only be called during close or suspend sequence. |
| 3007 | */ |
| 3008 | static void mdss_fb_release_fences(struct msm_fb_data_type *mfd) |
| 3009 | { |
| 3010 | struct msm_sync_pt_data *sync_pt_data = &mfd->mdp_sync_pt_data; |
| 3011 | int val; |
| 3012 | |
| 3013 | mutex_lock(&sync_pt_data->sync_mutex); |
| 3014 | if (sync_pt_data->timeline) { |
| 3015 | val = sync_pt_data->threshold + |
| 3016 | atomic_read(&sync_pt_data->commit_cnt); |
Sachin Bhayare | 2b6d004 | 2018-01-13 19:38:21 +0530 | [diff] [blame] | 3017 | mdss_inc_timeline(sync_pt_data->timeline, val); |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 3018 | sync_pt_data->timeline_value += val; |
| 3019 | atomic_set(&sync_pt_data->commit_cnt, 0); |
| 3020 | } |
| 3021 | mutex_unlock(&sync_pt_data->sync_mutex); |
| 3022 | } |
| 3023 | |
| 3024 | static void mdss_fb_release_kickoff(struct msm_fb_data_type *mfd) |
| 3025 | { |
| 3026 | if (mfd->wait_for_kickoff) { |
| 3027 | atomic_set(&mfd->kickoff_pending, 0); |
| 3028 | wake_up_all(&mfd->kickoff_wait_q); |
| 3029 | } |
| 3030 | } |
| 3031 | |
| 3032 | /** |
| 3033 | * __mdss_fb_sync_buf_done_callback() - process async display events |
| 3034 | * @p: Notifier block registered for async events. |
| 3035 | * @event: Event enum to identify the event. |
| 3036 | * @data: Optional argument provided with the event. |
| 3037 | * |
| 3038 | * See enum mdp_notify_event for events handled. |
| 3039 | */ |
| 3040 | static int __mdss_fb_sync_buf_done_callback(struct notifier_block *p, |
| 3041 | unsigned long event, void *data) |
| 3042 | { |
| 3043 | struct msm_sync_pt_data *sync_pt_data; |
| 3044 | struct msm_fb_data_type *mfd; |
| 3045 | int fence_cnt; |
| 3046 | int ret = NOTIFY_OK; |
| 3047 | |
| 3048 | sync_pt_data = container_of(p, struct msm_sync_pt_data, notifier); |
| 3049 | mfd = container_of(sync_pt_data, struct msm_fb_data_type, |
| 3050 | mdp_sync_pt_data); |
| 3051 | |
| 3052 | switch (event) { |
| 3053 | case MDP_NOTIFY_FRAME_BEGIN: |
| 3054 | if (mfd->idle_time && !mod_delayed_work(system_wq, |
| 3055 | &mfd->idle_notify_work, |
| 3056 | msecs_to_jiffies(WAIT_DISP_OP_TIMEOUT))) |
| 3057 | pr_debug("fb%d: start idle delayed work\n", |
| 3058 | mfd->index); |
| 3059 | |
| 3060 | mfd->idle_state = MDSS_FB_NOT_IDLE; |
| 3061 | break; |
| 3062 | case MDP_NOTIFY_FRAME_READY: |
| 3063 | if (sync_pt_data->async_wait_fences && |
| 3064 | sync_pt_data->temp_fen_cnt) { |
| 3065 | fence_cnt = sync_pt_data->temp_fen_cnt; |
| 3066 | sync_pt_data->temp_fen_cnt = 0; |
| 3067 | ret = __mdss_fb_wait_for_fence_sub(sync_pt_data, |
| 3068 | sync_pt_data->temp_fen, fence_cnt); |
| 3069 | } |
| 3070 | if (mfd->idle_time && !mod_delayed_work(system_wq, |
| 3071 | &mfd->idle_notify_work, |
| 3072 | msecs_to_jiffies(mfd->idle_time))) |
| 3073 | pr_debug("fb%d: restarted idle work\n", |
| 3074 | mfd->index); |
| 3075 | if (ret == -ETIME) |
| 3076 | ret = NOTIFY_BAD; |
| 3077 | mfd->idle_state = MDSS_FB_IDLE_TIMER_RUNNING; |
| 3078 | break; |
| 3079 | case MDP_NOTIFY_FRAME_FLUSHED: |
| 3080 | pr_debug("%s: frame flushed\n", sync_pt_data->fence_name); |
| 3081 | sync_pt_data->flushed = true; |
| 3082 | break; |
| 3083 | case MDP_NOTIFY_FRAME_TIMEOUT: |
| 3084 | pr_err("%s: frame timeout\n", sync_pt_data->fence_name); |
| 3085 | mdss_fb_signal_timeline(sync_pt_data); |
| 3086 | break; |
| 3087 | case MDP_NOTIFY_FRAME_DONE: |
| 3088 | pr_debug("%s: frame done\n", sync_pt_data->fence_name); |
| 3089 | mdss_fb_signal_timeline(sync_pt_data); |
| 3090 | mdss_fb_calc_fps(mfd); |
| 3091 | break; |
| 3092 | case MDP_NOTIFY_FRAME_CFG_DONE: |
| 3093 | if (sync_pt_data->async_wait_fences) |
| 3094 | __mdss_fb_copy_fence(sync_pt_data, |
| 3095 | sync_pt_data->temp_fen, |
| 3096 | &sync_pt_data->temp_fen_cnt); |
| 3097 | break; |
| 3098 | case MDP_NOTIFY_FRAME_CTX_DONE: |
| 3099 | mdss_fb_release_kickoff(mfd); |
| 3100 | break; |
| 3101 | } |
| 3102 | |
| 3103 | return ret; |
| 3104 | } |
| 3105 | |
| 3106 | /** |
| 3107 | * mdss_fb_pan_idle() - wait for panel programming to be idle |
| 3108 | * @mfd: Framebuffer data structure for display |
| 3109 | * |
| 3110 | * Wait for any pending programming to be done if in the process of programming |
| 3111 | * hardware configuration. After this function returns it is safe to perform |
| 3112 | * software updates for next frame. |
| 3113 | */ |
| 3114 | static int mdss_fb_pan_idle(struct msm_fb_data_type *mfd) |
| 3115 | { |
| 3116 | int ret = 0; |
| 3117 | |
| 3118 | ret = wait_event_timeout(mfd->idle_wait_q, |
| 3119 | (!atomic_read(&mfd->commits_pending) || |
| 3120 | mfd->shutdown_pending), |
| 3121 | msecs_to_jiffies(WAIT_DISP_OP_TIMEOUT)); |
| 3122 | if (!ret) { |
| 3123 | pr_err("%pS: wait for idle timeout commits=%d\n", |
| 3124 | __builtin_return_address(0), |
| 3125 | atomic_read(&mfd->commits_pending)); |
| 3126 | MDSS_XLOG_TOUT_HANDLER("mdp", "vbif", "vbif_nrt", |
| 3127 | "dbg_bus", "vbif_dbg_bus"); |
| 3128 | ret = -ETIMEDOUT; |
| 3129 | } else if (mfd->shutdown_pending) { |
| 3130 | pr_debug("Shutdown signalled\n"); |
| 3131 | ret = -ESHUTDOWN; |
| 3132 | } else { |
| 3133 | ret = 0; |
| 3134 | } |
| 3135 | |
| 3136 | return ret; |
| 3137 | } |
| 3138 | |
| 3139 | static int mdss_fb_wait_for_kickoff(struct msm_fb_data_type *mfd) |
| 3140 | { |
| 3141 | int ret = 0; |
| 3142 | |
| 3143 | if (!mfd->wait_for_kickoff) |
| 3144 | return mdss_fb_pan_idle(mfd); |
| 3145 | |
| 3146 | ret = wait_event_timeout(mfd->kickoff_wait_q, |
| 3147 | (!atomic_read(&mfd->kickoff_pending) || |
| 3148 | mfd->shutdown_pending), |
| 3149 | msecs_to_jiffies(WAIT_DISP_OP_TIMEOUT)); |
| 3150 | if (!ret) { |
| 3151 | pr_err("%pS: wait for kickoff timeout koff=%d commits=%d\n", |
| 3152 | __builtin_return_address(0), |
| 3153 | atomic_read(&mfd->kickoff_pending), |
| 3154 | atomic_read(&mfd->commits_pending)); |
| 3155 | MDSS_XLOG_TOUT_HANDLER("mdp", "vbif", "vbif_nrt", |
| 3156 | "dbg_bus", "vbif_dbg_bus"); |
| 3157 | ret = -ETIMEDOUT; |
| 3158 | } else if (mfd->shutdown_pending) { |
| 3159 | pr_debug("Shutdown signalled\n"); |
| 3160 | ret = -ESHUTDOWN; |
| 3161 | } else { |
| 3162 | ret = 0; |
| 3163 | } |
| 3164 | |
| 3165 | return ret; |
| 3166 | } |
| 3167 | |
| 3168 | static int mdss_fb_pan_display_ex(struct fb_info *info, |
| 3169 | struct mdp_display_commit *disp_commit) |
| 3170 | { |
| 3171 | struct msm_fb_data_type *mfd = (struct msm_fb_data_type *)info->par; |
| 3172 | struct fb_var_screeninfo *var = &disp_commit->var; |
| 3173 | u32 wait_for_finish = disp_commit->wait_for_finish; |
| 3174 | int ret = 0; |
| 3175 | |
| 3176 | if (!mfd || (!mfd->op_enable)) |
| 3177 | return -EPERM; |
| 3178 | |
| 3179 | if ((mdss_fb_is_power_off(mfd)) && |
| 3180 | !((mfd->dcm_state == DCM_ENTER) && |
| 3181 | (mfd->panel.type == MIPI_CMD_PANEL))) |
| 3182 | return -EPERM; |
| 3183 | |
| 3184 | if (var->xoffset > (info->var.xres_virtual - info->var.xres)) |
| 3185 | return -EINVAL; |
| 3186 | |
| 3187 | if (var->yoffset > (info->var.yres_virtual - info->var.yres)) |
| 3188 | return -EINVAL; |
| 3189 | |
Sachin Bhayare | 3d3767e | 2018-01-02 21:10:57 +0530 | [diff] [blame] | 3190 | ret = mdss_fb_wait_for_kickoff(mfd); |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 3191 | if (ret) { |
| 3192 | pr_err("wait_for_kick failed. rc=%d\n", ret); |
| 3193 | return ret; |
| 3194 | } |
| 3195 | |
| 3196 | if (mfd->mdp.pre_commit_fnc) { |
| 3197 | ret = mfd->mdp.pre_commit_fnc(mfd); |
| 3198 | if (ret) { |
| 3199 | pr_err("fb%d: pre commit failed %d\n", |
| 3200 | mfd->index, ret); |
| 3201 | return ret; |
| 3202 | } |
| 3203 | } |
| 3204 | |
| 3205 | mutex_lock(&mfd->mdp_sync_pt_data.sync_mutex); |
| 3206 | if (info->fix.xpanstep) |
| 3207 | info->var.xoffset = |
| 3208 | (var->xoffset / info->fix.xpanstep) * info->fix.xpanstep; |
| 3209 | |
| 3210 | if (info->fix.ypanstep) |
| 3211 | info->var.yoffset = |
| 3212 | (var->yoffset / info->fix.ypanstep) * info->fix.ypanstep; |
| 3213 | |
| 3214 | mfd->msm_fb_backup.info = *info; |
| 3215 | mfd->msm_fb_backup.disp_commit = *disp_commit; |
| 3216 | |
| 3217 | atomic_inc(&mfd->mdp_sync_pt_data.commit_cnt); |
| 3218 | atomic_inc(&mfd->commits_pending); |
| 3219 | atomic_inc(&mfd->kickoff_pending); |
| 3220 | wake_up_all(&mfd->commit_wait_q); |
| 3221 | mutex_unlock(&mfd->mdp_sync_pt_data.sync_mutex); |
| 3222 | if (wait_for_finish) { |
| 3223 | ret = mdss_fb_pan_idle(mfd); |
| 3224 | if (ret) |
| 3225 | pr_err("mdss_fb_pan_idle failed. rc=%d\n", ret); |
| 3226 | } |
| 3227 | return ret; |
| 3228 | } |
| 3229 | |
| 3230 | u32 mdss_fb_get_mode_switch(struct msm_fb_data_type *mfd) |
| 3231 | { |
| 3232 | /* If there is no attached mfd then there is no pending mode switch */ |
| 3233 | if (!mfd) |
| 3234 | return 0; |
| 3235 | |
| 3236 | if (mfd->pending_switch) |
| 3237 | return mfd->switch_new_mode; |
| 3238 | |
| 3239 | return 0; |
| 3240 | } |
| 3241 | |
| 3242 | /* |
| 3243 | * __ioctl_transition_dyn_mode_state() - State machine for mode switch |
| 3244 | * @mfd: Framebuffer data structure for display |
| 3245 | * @cmd: ioctl that was called |
| 3246 | * @validate: used with atomic commit when doing validate layers |
| 3247 | * |
| 3248 | * This function assists with dynamic mode switch of DSI panel. States |
| 3249 | * are used to make sure that panel mode switch occurs on next |
| 3250 | * prepare/sync/commit (for legacy) and validate/pre_commit (for |
| 3251 | * atomic commit) pairing. This state machine insure that calculation |
| 3252 | * and return values (such as buffer release fences) are based on the |
| 3253 | * panel mode being switching into. |
| 3254 | */ |
| 3255 | static int __ioctl_transition_dyn_mode_state(struct msm_fb_data_type *mfd, |
| 3256 | unsigned int cmd, bool validate, bool null_commit) |
| 3257 | { |
| 3258 | if (mfd->switch_state == MDSS_MDP_NO_UPDATE_REQUESTED) |
| 3259 | return 0; |
| 3260 | |
| 3261 | mutex_lock(&mfd->switch_lock); |
| 3262 | switch (cmd) { |
| 3263 | case MSMFB_ATOMIC_COMMIT: |
| 3264 | if ((mfd->switch_state == MDSS_MDP_WAIT_FOR_VALIDATE) |
| 3265 | && validate) { |
| 3266 | if (mfd->switch_new_mode != SWITCH_RESOLUTION) |
| 3267 | mfd->pending_switch = true; |
| 3268 | mfd->switch_state = MDSS_MDP_WAIT_FOR_COMMIT; |
| 3269 | } else if (mfd->switch_state == MDSS_MDP_WAIT_FOR_COMMIT) { |
| 3270 | if (mfd->switch_new_mode != SWITCH_RESOLUTION) |
| 3271 | mdss_fb_set_mdp_sync_pt_threshold(mfd, |
| 3272 | mfd->switch_new_mode); |
| 3273 | mfd->switch_state = MDSS_MDP_WAIT_FOR_KICKOFF; |
| 3274 | } else if ((mfd->switch_state == MDSS_MDP_WAIT_FOR_VALIDATE) |
| 3275 | && null_commit) { |
| 3276 | mfd->switch_state = MDSS_MDP_WAIT_FOR_KICKOFF; |
| 3277 | } |
| 3278 | break; |
| 3279 | } |
| 3280 | mutex_unlock(&mfd->switch_lock); |
| 3281 | return 0; |
| 3282 | } |
| 3283 | |
| 3284 | static inline bool mdss_fb_is_wb_config_same(struct msm_fb_data_type *mfd, |
| 3285 | struct mdp_output_layer *output_layer) |
| 3286 | { |
| 3287 | struct mdss_overlay_private *mdp5_data = mfd_to_mdp5_data(mfd); |
| 3288 | struct msm_mdp_interface *mdp5_interface = &mfd->mdp; |
| 3289 | |
| 3290 | if (!mdp5_data->wfd |
| 3291 | || (mdp5_interface->is_config_same |
| 3292 | && !mdp5_interface->is_config_same(mfd, output_layer))) |
| 3293 | return false; |
| 3294 | return true; |
| 3295 | } |
| 3296 | |
| 3297 | /* update pinfo and var for WB on config change */ |
| 3298 | static void mdss_fb_update_resolution(struct msm_fb_data_type *mfd, |
| 3299 | u32 xres, u32 yres, u32 format) |
| 3300 | { |
| 3301 | struct mdss_panel_info *pinfo = mfd->panel_info; |
| 3302 | struct fb_var_screeninfo *var = &mfd->fbi->var; |
| 3303 | struct fb_fix_screeninfo *fix = &mfd->fbi->fix; |
| 3304 | struct mdss_mdp_format_params *fmt = NULL; |
| 3305 | |
| 3306 | pinfo->xres = xres; |
| 3307 | pinfo->yres = yres; |
| 3308 | mfd->fb_imgType = format; |
| 3309 | if (mfd->mdp.get_format_params) { |
| 3310 | fmt = mfd->mdp.get_format_params(format); |
| 3311 | if (fmt) { |
| 3312 | pinfo->bpp = fmt->bpp; |
| 3313 | var->bits_per_pixel = fmt->bpp * 8; |
| 3314 | } |
| 3315 | if (mfd->mdp.fb_stride) |
| 3316 | fix->line_length = mfd->mdp.fb_stride(mfd->index, |
| 3317 | var->xres, |
| 3318 | var->bits_per_pixel / 8); |
| 3319 | else |
| 3320 | fix->line_length = var->xres * var->bits_per_pixel / 8; |
| 3321 | |
| 3322 | } |
| 3323 | var->xres_virtual = var->xres; |
| 3324 | var->yres_virtual = pinfo->yres * mfd->fb_page; |
| 3325 | mdss_panelinfo_to_fb_var(pinfo, var); |
| 3326 | } |
| 3327 | |
| 3328 | int mdss_fb_atomic_commit(struct fb_info *info, |
| 3329 | struct mdp_layer_commit *commit, struct file *file) |
| 3330 | { |
| 3331 | struct msm_fb_data_type *mfd = (struct msm_fb_data_type *)info->par; |
| 3332 | struct mdp_layer_commit_v1 *commit_v1; |
| 3333 | struct mdp_output_layer *output_layer; |
| 3334 | struct mdss_panel_info *pinfo; |
| 3335 | bool wait_for_finish, wb_change = false; |
| 3336 | int ret = -EPERM; |
| 3337 | u32 old_xres, old_yres, old_format; |
| 3338 | |
| 3339 | if (!mfd || (!mfd->op_enable)) { |
| 3340 | pr_err("mfd is NULL or operation not permitted\n"); |
| 3341 | return -EPERM; |
| 3342 | } |
| 3343 | |
| 3344 | if ((mdss_fb_is_power_off(mfd)) && |
| 3345 | !((mfd->dcm_state == DCM_ENTER) && |
| 3346 | (mfd->panel.type == MIPI_CMD_PANEL))) { |
| 3347 | pr_err("commit is not supported when interface is in off state\n"); |
| 3348 | goto end; |
| 3349 | } |
| 3350 | pinfo = mfd->panel_info; |
| 3351 | |
| 3352 | /* only supports version 1.0 */ |
| 3353 | if (commit->version != MDP_COMMIT_VERSION_1_0) { |
| 3354 | pr_err("commit version is not supported\n"); |
| 3355 | goto end; |
| 3356 | } |
| 3357 | |
| 3358 | if (!mfd->mdp.pre_commit || !mfd->mdp.atomic_validate) { |
| 3359 | pr_err("commit callback is not registered\n"); |
| 3360 | goto end; |
| 3361 | } |
| 3362 | |
| 3363 | commit_v1 = &commit->commit_v1; |
| 3364 | if (commit_v1->flags & MDP_VALIDATE_LAYER) { |
| 3365 | ret = mdss_fb_wait_for_kickoff(mfd); |
| 3366 | if (ret) { |
| 3367 | pr_err("wait for kickoff failed\n"); |
| 3368 | } else { |
| 3369 | __ioctl_transition_dyn_mode_state(mfd, |
| 3370 | MSMFB_ATOMIC_COMMIT, true, false); |
| 3371 | if (mfd->panel.type == WRITEBACK_PANEL) { |
| 3372 | output_layer = commit_v1->output_layer; |
| 3373 | if (!output_layer) { |
| 3374 | pr_err("Output layer is null\n"); |
| 3375 | goto end; |
| 3376 | } |
| 3377 | wb_change = !mdss_fb_is_wb_config_same(mfd, |
| 3378 | commit_v1->output_layer); |
| 3379 | if (wb_change) { |
| 3380 | old_xres = pinfo->xres; |
| 3381 | old_yres = pinfo->yres; |
| 3382 | old_format = mfd->fb_imgType; |
| 3383 | mdss_fb_update_resolution(mfd, |
| 3384 | output_layer->buffer.width, |
| 3385 | output_layer->buffer.height, |
| 3386 | output_layer->buffer.format); |
| 3387 | } |
| 3388 | } |
| 3389 | ret = mfd->mdp.atomic_validate(mfd, file, commit_v1); |
| 3390 | if (!ret) |
| 3391 | mfd->atomic_commit_pending = true; |
| 3392 | } |
| 3393 | goto end; |
| 3394 | } else { |
| 3395 | ret = mdss_fb_pan_idle(mfd); |
| 3396 | if (ret) { |
| 3397 | pr_err("pan display idle call failed\n"); |
| 3398 | goto end; |
| 3399 | } |
| 3400 | __ioctl_transition_dyn_mode_state(mfd, |
| 3401 | MSMFB_ATOMIC_COMMIT, false, |
| 3402 | (commit_v1->input_layer_cnt ? 0 : 1)); |
| 3403 | |
| 3404 | ret = mfd->mdp.pre_commit(mfd, file, commit_v1); |
| 3405 | if (ret) { |
| 3406 | pr_err("atomic pre commit failed\n"); |
| 3407 | goto end; |
| 3408 | } |
| 3409 | } |
| 3410 | |
| 3411 | wait_for_finish = commit_v1->flags & MDP_COMMIT_WAIT_FOR_FINISH; |
| 3412 | mfd->msm_fb_backup.atomic_commit = true; |
| 3413 | mfd->msm_fb_backup.disp_commit.l_roi = commit_v1->left_roi; |
| 3414 | mfd->msm_fb_backup.disp_commit.r_roi = commit_v1->right_roi; |
| 3415 | |
| 3416 | mutex_lock(&mfd->mdp_sync_pt_data.sync_mutex); |
| 3417 | atomic_inc(&mfd->mdp_sync_pt_data.commit_cnt); |
| 3418 | atomic_inc(&mfd->commits_pending); |
| 3419 | atomic_inc(&mfd->kickoff_pending); |
| 3420 | wake_up_all(&mfd->commit_wait_q); |
| 3421 | mutex_unlock(&mfd->mdp_sync_pt_data.sync_mutex); |
| 3422 | |
| 3423 | if (wait_for_finish) |
| 3424 | ret = mdss_fb_pan_idle(mfd); |
| 3425 | |
| 3426 | end: |
| 3427 | if (ret && (mfd->panel.type == WRITEBACK_PANEL) && wb_change) |
| 3428 | mdss_fb_update_resolution(mfd, old_xres, old_yres, old_format); |
| 3429 | return ret; |
| 3430 | } |
| 3431 | |
| 3432 | static int mdss_fb_pan_display(struct fb_var_screeninfo *var, |
| 3433 | struct fb_info *info) |
| 3434 | { |
| 3435 | struct mdp_display_commit disp_commit; |
| 3436 | struct msm_fb_data_type *mfd = (struct msm_fb_data_type *)info->par; |
| 3437 | |
| 3438 | /* |
| 3439 | * during mode switch through mode sysfs node, it will trigger a |
| 3440 | * pan_display after switch. This assumes that fb has been adjusted, |
| 3441 | * however when using overlays we may not have the right size at this |
| 3442 | * point, so it needs to go through PREPARE first. Abort pan_display |
| 3443 | * operations until that happens |
| 3444 | */ |
| 3445 | if (mfd->switch_state != MDSS_MDP_NO_UPDATE_REQUESTED) { |
| 3446 | pr_debug("fb%d: pan_display skipped during switch\n", |
| 3447 | mfd->index); |
| 3448 | return 0; |
| 3449 | } |
| 3450 | |
| 3451 | memset(&disp_commit, 0, sizeof(disp_commit)); |
| 3452 | disp_commit.wait_for_finish = true; |
| 3453 | memcpy(&disp_commit.var, var, sizeof(struct fb_var_screeninfo)); |
| 3454 | return mdss_fb_pan_display_ex(info, &disp_commit); |
| 3455 | } |
| 3456 | |
| 3457 | static int mdss_fb_pan_display_sub(struct fb_var_screeninfo *var, |
| 3458 | struct fb_info *info) |
| 3459 | { |
| 3460 | struct msm_fb_data_type *mfd = (struct msm_fb_data_type *)info->par; |
| 3461 | |
| 3462 | if (!mfd->op_enable) |
| 3463 | return -EPERM; |
| 3464 | |
| 3465 | if ((mdss_fb_is_power_off(mfd)) && |
| 3466 | !((mfd->dcm_state == DCM_ENTER) && |
| 3467 | (mfd->panel.type == MIPI_CMD_PANEL))) |
| 3468 | return -EPERM; |
| 3469 | |
| 3470 | if (var->xoffset > (info->var.xres_virtual - info->var.xres)) |
| 3471 | return -EINVAL; |
| 3472 | |
| 3473 | if (var->yoffset > (info->var.yres_virtual - info->var.yres)) |
| 3474 | return -EINVAL; |
| 3475 | |
| 3476 | if (info->fix.xpanstep) |
| 3477 | info->var.xoffset = |
| 3478 | (var->xoffset / info->fix.xpanstep) * info->fix.xpanstep; |
| 3479 | |
| 3480 | if (info->fix.ypanstep) |
| 3481 | info->var.yoffset = |
| 3482 | (var->yoffset / info->fix.ypanstep) * info->fix.ypanstep; |
| 3483 | |
| 3484 | if (mfd->mdp.dma_fnc) |
| 3485 | mfd->mdp.dma_fnc(mfd); |
| 3486 | else |
| 3487 | pr_warn("dma function not set for panel type=%d\n", |
| 3488 | mfd->panel.type); |
| 3489 | |
| 3490 | return 0; |
| 3491 | } |
| 3492 | |
| 3493 | static int mdss_grayscale_to_mdp_format(u32 grayscale) |
| 3494 | { |
| 3495 | switch (grayscale) { |
| 3496 | case V4L2_PIX_FMT_RGB24: |
| 3497 | return MDP_RGB_888; |
| 3498 | case V4L2_PIX_FMT_NV12: |
| 3499 | return MDP_Y_CBCR_H2V2; |
| 3500 | default: |
| 3501 | return -EINVAL; |
| 3502 | } |
| 3503 | } |
| 3504 | |
| 3505 | static void mdss_fb_var_to_panelinfo(struct fb_var_screeninfo *var, |
| 3506 | struct mdss_panel_info *pinfo) |
| 3507 | { |
| 3508 | int format = -EINVAL; |
| 3509 | |
| 3510 | pinfo->xres = var->xres; |
| 3511 | pinfo->yres = var->yres; |
| 3512 | pinfo->lcdc.v_front_porch = var->lower_margin; |
| 3513 | pinfo->lcdc.v_back_porch = var->upper_margin; |
| 3514 | pinfo->lcdc.v_pulse_width = var->vsync_len; |
| 3515 | pinfo->lcdc.h_front_porch = var->right_margin; |
| 3516 | pinfo->lcdc.h_back_porch = var->left_margin; |
| 3517 | pinfo->lcdc.h_pulse_width = var->hsync_len; |
| 3518 | |
| 3519 | if (var->grayscale > 1) { |
| 3520 | format = mdss_grayscale_to_mdp_format(var->grayscale); |
Sachin Bhayare | 3d3767e | 2018-01-02 21:10:57 +0530 | [diff] [blame] | 3521 | if (!IS_ERR_VALUE((unsigned long)format)) |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 3522 | pinfo->out_format = format; |
| 3523 | else |
| 3524 | pr_warn("Failed to map grayscale value (%d) to an MDP format\n", |
| 3525 | var->grayscale); |
| 3526 | } |
| 3527 | |
| 3528 | /* |
| 3529 | * if greater than 1M, then rate would fall below 1mhz which is not |
| 3530 | * even supported. In this case it means clock rate is actually |
| 3531 | * passed directly in hz. |
| 3532 | */ |
| 3533 | if (var->pixclock > SZ_1M) |
| 3534 | pinfo->clk_rate = var->pixclock; |
| 3535 | else |
| 3536 | pinfo->clk_rate = PICOS2KHZ(var->pixclock) * 1000; |
| 3537 | |
| 3538 | /* |
| 3539 | * if it is a DBA panel i.e. HDMI TV connected through |
| 3540 | * DSI interface, then store the pixel clock value in |
| 3541 | * DSI specific variable. |
| 3542 | */ |
| 3543 | if (pinfo->is_dba_panel) |
| 3544 | pinfo->mipi.dsi_pclk_rate = pinfo->clk_rate; |
| 3545 | } |
| 3546 | |
| 3547 | void mdss_panelinfo_to_fb_var(struct mdss_panel_info *pinfo, |
| 3548 | struct fb_var_screeninfo *var) |
| 3549 | { |
| 3550 | u32 frame_rate; |
| 3551 | |
| 3552 | var->xres = mdss_fb_get_panel_xres(pinfo); |
| 3553 | var->yres = pinfo->yres; |
| 3554 | var->lower_margin = pinfo->lcdc.v_front_porch - |
| 3555 | pinfo->prg_fet; |
| 3556 | var->upper_margin = pinfo->lcdc.v_back_porch + |
| 3557 | pinfo->prg_fet; |
| 3558 | var->vsync_len = pinfo->lcdc.v_pulse_width; |
| 3559 | var->right_margin = pinfo->lcdc.h_front_porch; |
| 3560 | var->left_margin = pinfo->lcdc.h_back_porch; |
| 3561 | var->hsync_len = pinfo->lcdc.h_pulse_width; |
| 3562 | |
| 3563 | frame_rate = mdss_panel_get_framerate(pinfo, |
| 3564 | FPS_RESOLUTION_HZ); |
| 3565 | if (frame_rate) { |
| 3566 | unsigned long clk_rate, h_total, v_total; |
| 3567 | |
| 3568 | h_total = var->xres + var->left_margin |
| 3569 | + var->right_margin + var->hsync_len; |
| 3570 | v_total = var->yres + var->lower_margin |
| 3571 | + var->upper_margin + var->vsync_len; |
| 3572 | clk_rate = h_total * v_total * frame_rate; |
| 3573 | var->pixclock = KHZ2PICOS(clk_rate / 1000); |
| 3574 | } else if (pinfo->clk_rate) { |
| 3575 | var->pixclock = KHZ2PICOS( |
| 3576 | (unsigned long int) pinfo->clk_rate / 1000); |
| 3577 | } |
| 3578 | |
| 3579 | if (pinfo->physical_width) |
| 3580 | var->width = pinfo->physical_width; |
| 3581 | if (pinfo->physical_height) |
| 3582 | var->height = pinfo->physical_height; |
| 3583 | |
| 3584 | pr_debug("ScreenInfo: res=%dx%d [%d, %d] [%d, %d]\n", |
| 3585 | var->xres, var->yres, var->left_margin, |
| 3586 | var->right_margin, var->upper_margin, |
| 3587 | var->lower_margin); |
| 3588 | } |
| 3589 | |
| 3590 | /** |
| 3591 | * __mdss_fb_perform_commit() - process a frame to display |
| 3592 | * @mfd: Framebuffer data structure for display |
| 3593 | * |
| 3594 | * Processes all layers and buffers programmed and ensures all pending release |
| 3595 | * fences are signaled once the buffer is transferred to display. |
| 3596 | */ |
| 3597 | static int __mdss_fb_perform_commit(struct msm_fb_data_type *mfd) |
| 3598 | { |
| 3599 | struct msm_sync_pt_data *sync_pt_data = &mfd->mdp_sync_pt_data; |
| 3600 | struct msm_fb_backup_type *fb_backup = &mfd->msm_fb_backup; |
Sachin Bhayare | 3d3767e | 2018-01-02 21:10:57 +0530 | [diff] [blame] | 3601 | int ret = -ENOTSUPP; |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 3602 | u32 new_dsi_mode, dynamic_dsi_switch = 0; |
| 3603 | |
| 3604 | if (!sync_pt_data->async_wait_fences) |
| 3605 | mdss_fb_wait_for_fence(sync_pt_data); |
| 3606 | sync_pt_data->flushed = false; |
| 3607 | |
| 3608 | mutex_lock(&mfd->switch_lock); |
| 3609 | if (mfd->switch_state == MDSS_MDP_WAIT_FOR_KICKOFF) { |
| 3610 | dynamic_dsi_switch = 1; |
| 3611 | new_dsi_mode = mfd->switch_new_mode; |
| 3612 | } else if (mfd->switch_state != MDSS_MDP_NO_UPDATE_REQUESTED) { |
| 3613 | pr_err("invalid commit on fb%d with state = %d\n", |
| 3614 | mfd->index, mfd->switch_state); |
| 3615 | mutex_unlock(&mfd->switch_lock); |
| 3616 | goto skip_commit; |
| 3617 | } |
| 3618 | mutex_unlock(&mfd->switch_lock); |
| 3619 | if (dynamic_dsi_switch) { |
| 3620 | MDSS_XLOG(mfd->index, mfd->split_mode, new_dsi_mode, |
| 3621 | XLOG_FUNC_ENTRY); |
| 3622 | pr_debug("Triggering dyn mode switch to %d\n", new_dsi_mode); |
| 3623 | ret = mfd->mdp.mode_switch(mfd, new_dsi_mode); |
| 3624 | if (ret) |
| 3625 | pr_err("DSI mode switch has failed"); |
| 3626 | else |
| 3627 | mfd->pending_switch = false; |
| 3628 | } |
| 3629 | if (fb_backup->disp_commit.flags & MDP_DISPLAY_COMMIT_OVERLAY) { |
| 3630 | if (mfd->mdp.kickoff_fnc) |
| 3631 | ret = mfd->mdp.kickoff_fnc(mfd, |
| 3632 | &fb_backup->disp_commit); |
| 3633 | else |
| 3634 | pr_warn("no kickoff function setup for fb%d\n", |
| 3635 | mfd->index); |
| 3636 | } else if (fb_backup->atomic_commit) { |
| 3637 | if (mfd->mdp.kickoff_fnc) |
| 3638 | ret = mfd->mdp.kickoff_fnc(mfd, |
| 3639 | &fb_backup->disp_commit); |
| 3640 | else |
| 3641 | pr_warn("no kickoff function setup for fb%d\n", |
| 3642 | mfd->index); |
| 3643 | fb_backup->atomic_commit = false; |
| 3644 | } else { |
| 3645 | ret = mdss_fb_pan_display_sub(&fb_backup->disp_commit.var, |
| 3646 | &fb_backup->info); |
| 3647 | if (ret) |
| 3648 | pr_err("pan display failed %x on fb%d\n", ret, |
| 3649 | mfd->index); |
| 3650 | } |
| 3651 | |
| 3652 | skip_commit: |
| 3653 | if (!ret) |
| 3654 | mdss_fb_update_backlight(mfd); |
| 3655 | |
Sachin Bhayare | 3d3767e | 2018-01-02 21:10:57 +0530 | [diff] [blame] | 3656 | if (IS_ERR_VALUE((unsigned long)ret) || !sync_pt_data->flushed) { |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 3657 | mdss_fb_release_kickoff(mfd); |
| 3658 | mdss_fb_signal_timeline(sync_pt_data); |
| 3659 | if ((mfd->panel.type == MIPI_CMD_PANEL) && |
| 3660 | (mfd->mdp.signal_retire_fence)) |
| 3661 | mfd->mdp.signal_retire_fence(mfd, 1); |
| 3662 | } |
| 3663 | |
| 3664 | if (dynamic_dsi_switch) { |
| 3665 | MDSS_XLOG(mfd->index, mfd->split_mode, new_dsi_mode, |
| 3666 | XLOG_FUNC_EXIT); |
| 3667 | mfd->mdp.mode_switch_post(mfd, new_dsi_mode); |
| 3668 | mutex_lock(&mfd->switch_lock); |
| 3669 | mfd->switch_state = MDSS_MDP_NO_UPDATE_REQUESTED; |
| 3670 | mutex_unlock(&mfd->switch_lock); |
| 3671 | if (new_dsi_mode != SWITCH_RESOLUTION) |
| 3672 | mfd->panel.type = new_dsi_mode; |
| 3673 | pr_debug("Dynamic mode switch completed\n"); |
| 3674 | } |
| 3675 | |
| 3676 | return ret; |
| 3677 | } |
| 3678 | |
| 3679 | static int __mdss_fb_display_thread(void *data) |
| 3680 | { |
| 3681 | struct msm_fb_data_type *mfd = data; |
| 3682 | int ret; |
| 3683 | struct sched_param param; |
| 3684 | |
| 3685 | /* |
| 3686 | * this priority was found during empiric testing to have appropriate |
| 3687 | * realtime scheduling to process display updates and interact with |
| 3688 | * other real time and normal priority tasks |
| 3689 | */ |
| 3690 | param.sched_priority = 16; |
| 3691 | ret = sched_setscheduler(current, SCHED_FIFO, ¶m); |
| 3692 | if (ret) |
| 3693 | pr_warn("set priority failed for fb%d display thread\n", |
| 3694 | mfd->index); |
| 3695 | |
| 3696 | while (1) { |
| 3697 | wait_event(mfd->commit_wait_q, |
| 3698 | (atomic_read(&mfd->commits_pending) || |
| 3699 | kthread_should_stop())); |
| 3700 | |
| 3701 | if (kthread_should_stop()) |
| 3702 | break; |
| 3703 | |
| 3704 | MDSS_XLOG(mfd->index, XLOG_FUNC_ENTRY); |
| 3705 | ret = __mdss_fb_perform_commit(mfd); |
| 3706 | MDSS_XLOG(mfd->index, XLOG_FUNC_EXIT); |
| 3707 | |
| 3708 | atomic_dec(&mfd->commits_pending); |
| 3709 | wake_up_all(&mfd->idle_wait_q); |
| 3710 | } |
| 3711 | |
| 3712 | mdss_fb_release_kickoff(mfd); |
| 3713 | atomic_set(&mfd->commits_pending, 0); |
| 3714 | wake_up_all(&mfd->idle_wait_q); |
| 3715 | |
| 3716 | return ret; |
| 3717 | } |
| 3718 | |
| 3719 | static int mdss_fb_check_var(struct fb_var_screeninfo *var, |
| 3720 | struct fb_info *info) |
| 3721 | { |
| 3722 | struct msm_fb_data_type *mfd = (struct msm_fb_data_type *)info->par; |
| 3723 | |
| 3724 | if (var->rotate != FB_ROTATE_UR && var->rotate != FB_ROTATE_UD) |
| 3725 | return -EINVAL; |
| 3726 | |
| 3727 | switch (var->bits_per_pixel) { |
| 3728 | case 16: |
| 3729 | if ((var->green.offset != 5) || |
| 3730 | !((var->blue.offset == 11) |
| 3731 | || (var->blue.offset == 0)) || |
| 3732 | !((var->red.offset == 11) |
| 3733 | || (var->red.offset == 0)) || |
| 3734 | (var->blue.length != 5) || |
| 3735 | (var->green.length != 6) || |
| 3736 | (var->red.length != 5) || |
| 3737 | (var->blue.msb_right != 0) || |
| 3738 | (var->green.msb_right != 0) || |
| 3739 | (var->red.msb_right != 0) || |
| 3740 | (var->transp.offset != 0) || |
| 3741 | (var->transp.length != 0)) |
| 3742 | return -EINVAL; |
| 3743 | break; |
| 3744 | |
| 3745 | case 24: |
| 3746 | if ((var->blue.offset != 0) || |
| 3747 | (var->green.offset != 8) || |
| 3748 | (var->red.offset != 16) || |
| 3749 | (var->blue.length != 8) || |
| 3750 | (var->green.length != 8) || |
| 3751 | (var->red.length != 8) || |
| 3752 | (var->blue.msb_right != 0) || |
| 3753 | (var->green.msb_right != 0) || |
| 3754 | (var->red.msb_right != 0) || |
| 3755 | !(((var->transp.offset == 0) && |
| 3756 | (var->transp.length == 0)) || |
| 3757 | ((var->transp.offset == 24) && |
| 3758 | (var->transp.length == 8)))) |
| 3759 | return -EINVAL; |
| 3760 | break; |
| 3761 | |
| 3762 | case 32: |
| 3763 | /* |
| 3764 | * Check user specified color format BGRA/ARGB/RGBA |
| 3765 | * and verify the position of the RGB components |
| 3766 | */ |
| 3767 | |
| 3768 | if (!((var->transp.offset == 24) && |
| 3769 | (var->blue.offset == 0) && |
| 3770 | (var->green.offset == 8) && |
| 3771 | (var->red.offset == 16)) && |
| 3772 | !((var->transp.offset == 0) && |
| 3773 | (var->blue.offset == 24) && |
| 3774 | (var->green.offset == 16) && |
| 3775 | (var->red.offset == 8)) && |
| 3776 | !((var->transp.offset == 24) && |
| 3777 | (var->blue.offset == 16) && |
| 3778 | (var->green.offset == 8) && |
| 3779 | (var->red.offset == 0))) |
| 3780 | return -EINVAL; |
| 3781 | |
| 3782 | /* Check the common values for both RGBA and ARGB */ |
| 3783 | |
| 3784 | if ((var->blue.length != 8) || |
| 3785 | (var->green.length != 8) || |
| 3786 | (var->red.length != 8) || |
| 3787 | (var->transp.length != 8) || |
| 3788 | (var->blue.msb_right != 0) || |
| 3789 | (var->green.msb_right != 0) || |
| 3790 | (var->red.msb_right != 0)) |
| 3791 | return -EINVAL; |
| 3792 | |
| 3793 | break; |
| 3794 | |
| 3795 | default: |
| 3796 | return -EINVAL; |
| 3797 | } |
| 3798 | |
| 3799 | if ((var->xres_virtual <= 0) || (var->yres_virtual <= 0)) |
| 3800 | return -EINVAL; |
| 3801 | |
| 3802 | if ((var->xres == 0) || (var->yres == 0)) |
| 3803 | return -EINVAL; |
| 3804 | |
| 3805 | if (var->xoffset > (var->xres_virtual - var->xres)) |
| 3806 | return -EINVAL; |
| 3807 | |
| 3808 | if (var->yoffset > (var->yres_virtual - var->yres)) |
| 3809 | return -EINVAL; |
| 3810 | |
| 3811 | if (info->mode) { |
| 3812 | const struct fb_videomode *mode; |
| 3813 | |
| 3814 | mode = fb_match_mode(var, &info->modelist); |
| 3815 | if (mode == NULL) |
| 3816 | return -EINVAL; |
| 3817 | } else if (mfd->panel_info && !(var->activate & FB_ACTIVATE_TEST)) { |
| 3818 | struct mdss_panel_info *panel_info; |
| 3819 | int rc; |
| 3820 | |
| 3821 | panel_info = kzalloc(sizeof(struct mdss_panel_info), |
| 3822 | GFP_KERNEL); |
| 3823 | if (!panel_info) |
| 3824 | return -ENOMEM; |
| 3825 | |
| 3826 | memcpy(panel_info, mfd->panel_info, |
| 3827 | sizeof(struct mdss_panel_info)); |
| 3828 | mdss_fb_var_to_panelinfo(var, panel_info); |
| 3829 | rc = mdss_fb_send_panel_event(mfd, MDSS_EVENT_CHECK_PARAMS, |
| 3830 | panel_info); |
Sachin Bhayare | 3d3767e | 2018-01-02 21:10:57 +0530 | [diff] [blame] | 3831 | if (IS_ERR_VALUE((unsigned long)rc)) { |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 3832 | kfree(panel_info); |
| 3833 | return rc; |
| 3834 | } |
| 3835 | mfd->panel_reconfig = rc; |
| 3836 | kfree(panel_info); |
| 3837 | } |
| 3838 | |
| 3839 | return 0; |
| 3840 | } |
| 3841 | |
| 3842 | static int mdss_fb_videomode_switch(struct msm_fb_data_type *mfd, |
| 3843 | const struct fb_videomode *mode) |
| 3844 | { |
| 3845 | int ret = 0; |
| 3846 | struct mdss_panel_data *pdata, *tmp; |
| 3847 | struct mdss_panel_timing *timing; |
| 3848 | |
| 3849 | pdata = dev_get_platdata(&mfd->pdev->dev); |
| 3850 | if (!pdata) { |
| 3851 | pr_err("no panel connected\n"); |
| 3852 | return -ENODEV; |
| 3853 | } |
| 3854 | |
| 3855 | /* make sure that we are idle while switching */ |
| 3856 | mdss_fb_wait_for_kickoff(mfd); |
| 3857 | |
| 3858 | pr_debug("fb%d: changing display mode to %s\n", mfd->index, mode->name); |
| 3859 | MDSS_XLOG(mfd->index, mode->name, |
| 3860 | mdss_fb_get_panel_xres(mfd->panel_info), |
| 3861 | mfd->panel_info->yres, mfd->split_mode, |
| 3862 | XLOG_FUNC_ENTRY); |
| 3863 | tmp = pdata; |
| 3864 | do { |
| 3865 | if (!tmp->event_handler) { |
| 3866 | pr_warn("no event handler for panel\n"); |
| 3867 | continue; |
| 3868 | } |
| 3869 | timing = mdss_panel_get_timing_by_name(tmp, mode->name); |
| 3870 | ret = tmp->event_handler(tmp, |
| 3871 | MDSS_EVENT_PANEL_TIMING_SWITCH, timing); |
| 3872 | |
| 3873 | tmp->active = timing != NULL; |
| 3874 | tmp = tmp->next; |
| 3875 | } while (tmp && !ret); |
| 3876 | |
| 3877 | if (!ret) |
| 3878 | mdss_fb_set_split_mode(mfd, pdata); |
| 3879 | |
| 3880 | if (!ret && mfd->mdp.configure_panel) { |
| 3881 | int dest_ctrl = 1; |
| 3882 | |
| 3883 | /* todo: currently assumes no changes in video/cmd mode */ |
| 3884 | if (!mdss_fb_is_power_off(mfd)) { |
| 3885 | mutex_lock(&mfd->switch_lock); |
| 3886 | mfd->switch_state = MDSS_MDP_WAIT_FOR_VALIDATE; |
| 3887 | mfd->switch_new_mode = SWITCH_RESOLUTION; |
| 3888 | mutex_unlock(&mfd->switch_lock); |
| 3889 | dest_ctrl = 0; |
| 3890 | } |
| 3891 | ret = mfd->mdp.configure_panel(mfd, |
| 3892 | pdata->panel_info.mipi.mode, dest_ctrl); |
| 3893 | } |
| 3894 | |
| 3895 | MDSS_XLOG(mfd->index, mode->name, |
| 3896 | mdss_fb_get_panel_xres(mfd->panel_info), |
| 3897 | mfd->panel_info->yres, mfd->split_mode, |
| 3898 | XLOG_FUNC_EXIT); |
| 3899 | pr_debug("fb%d: %s mode change complete\n", mfd->index, mode->name); |
| 3900 | |
| 3901 | return ret; |
| 3902 | } |
| 3903 | |
| 3904 | static int mdss_fb_set_par(struct fb_info *info) |
| 3905 | { |
| 3906 | struct msm_fb_data_type *mfd = (struct msm_fb_data_type *)info->par; |
| 3907 | struct fb_var_screeninfo *var = &info->var; |
| 3908 | int old_imgType, old_format; |
| 3909 | int ret = 0; |
| 3910 | |
| 3911 | ret = mdss_fb_pan_idle(mfd); |
| 3912 | if (ret) { |
| 3913 | pr_err("mdss_fb_pan_idle failed. rc=%d\n", ret); |
| 3914 | return ret; |
| 3915 | } |
| 3916 | |
| 3917 | old_imgType = mfd->fb_imgType; |
| 3918 | switch (var->bits_per_pixel) { |
| 3919 | case 16: |
| 3920 | if (var->red.offset == 0) |
| 3921 | mfd->fb_imgType = MDP_BGR_565; |
| 3922 | else |
| 3923 | mfd->fb_imgType = MDP_RGB_565; |
| 3924 | break; |
| 3925 | |
| 3926 | case 24: |
| 3927 | if ((var->transp.offset == 0) && (var->transp.length == 0)) |
| 3928 | mfd->fb_imgType = MDP_RGB_888; |
| 3929 | else if ((var->transp.offset == 24) && |
| 3930 | (var->transp.length == 8)) { |
| 3931 | mfd->fb_imgType = MDP_ARGB_8888; |
| 3932 | info->var.bits_per_pixel = 32; |
| 3933 | } |
| 3934 | break; |
| 3935 | |
| 3936 | case 32: |
| 3937 | if ((var->red.offset == 0) && |
| 3938 | (var->green.offset == 8) && |
| 3939 | (var->blue.offset == 16) && |
| 3940 | (var->transp.offset == 24)) |
| 3941 | mfd->fb_imgType = MDP_RGBA_8888; |
| 3942 | else if ((var->red.offset == 16) && |
| 3943 | (var->green.offset == 8) && |
| 3944 | (var->blue.offset == 0) && |
| 3945 | (var->transp.offset == 24)) |
| 3946 | mfd->fb_imgType = MDP_BGRA_8888; |
| 3947 | else if ((var->red.offset == 8) && |
| 3948 | (var->green.offset == 16) && |
| 3949 | (var->blue.offset == 24) && |
| 3950 | (var->transp.offset == 0)) |
| 3951 | mfd->fb_imgType = MDP_ARGB_8888; |
| 3952 | else |
| 3953 | mfd->fb_imgType = MDP_RGBA_8888; |
| 3954 | break; |
| 3955 | |
| 3956 | default: |
| 3957 | return -EINVAL; |
| 3958 | } |
| 3959 | |
| 3960 | if (info->mode) { |
| 3961 | const struct fb_videomode *mode; |
| 3962 | |
| 3963 | mode = fb_match_mode(var, &info->modelist); |
| 3964 | if (!mode) |
| 3965 | return -EINVAL; |
| 3966 | |
| 3967 | pr_debug("found mode: %s\n", mode->name); |
| 3968 | |
| 3969 | if (fb_mode_is_equal(mode, info->mode)) { |
| 3970 | pr_debug("mode is equal to current mode\n"); |
| 3971 | return 0; |
| 3972 | } |
| 3973 | |
| 3974 | ret = mdss_fb_videomode_switch(mfd, mode); |
| 3975 | if (ret) |
| 3976 | return ret; |
| 3977 | } |
| 3978 | |
| 3979 | if (mfd->mdp.fb_stride) |
| 3980 | mfd->fbi->fix.line_length = mfd->mdp.fb_stride(mfd->index, |
| 3981 | var->xres, |
| 3982 | var->bits_per_pixel / 8); |
| 3983 | else |
| 3984 | mfd->fbi->fix.line_length = var->xres * var->bits_per_pixel / 8; |
| 3985 | |
| 3986 | /* if memory is not allocated yet, change memory size for fb */ |
| 3987 | if (!info->fix.smem_start) |
| 3988 | mfd->fbi->fix.smem_len = PAGE_ALIGN(mfd->fbi->fix.line_length * |
| 3989 | mfd->fbi->var.yres) * mfd->fb_page; |
| 3990 | |
| 3991 | old_format = mdss_grayscale_to_mdp_format(var->grayscale); |
Sachin Bhayare | 3d3767e | 2018-01-02 21:10:57 +0530 | [diff] [blame] | 3992 | if (!IS_ERR_VALUE((unsigned long)old_format)) { |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 3993 | if (old_format != mfd->panel_info->out_format) |
| 3994 | mfd->panel_reconfig = true; |
| 3995 | } |
| 3996 | |
| 3997 | if (mfd->panel_reconfig || (mfd->fb_imgType != old_imgType)) { |
| 3998 | mdss_fb_blank_sub(FB_BLANK_POWERDOWN, info, mfd->op_enable); |
| 3999 | mdss_fb_var_to_panelinfo(var, mfd->panel_info); |
| 4000 | if (mfd->panel_info->is_dba_panel && |
| 4001 | mdss_fb_send_panel_event(mfd, MDSS_EVENT_UPDATE_PARAMS, |
| 4002 | mfd->panel_info)) |
| 4003 | pr_debug("Failed to send panel event UPDATE_PARAMS\n"); |
| 4004 | mdss_fb_blank_sub(FB_BLANK_UNBLANK, info, mfd->op_enable); |
| 4005 | mfd->panel_reconfig = false; |
| 4006 | } |
| 4007 | |
| 4008 | return ret; |
| 4009 | } |
| 4010 | |
| 4011 | int mdss_fb_dcm(struct msm_fb_data_type *mfd, int req_state) |
| 4012 | { |
| 4013 | int ret = 0; |
| 4014 | |
| 4015 | if (req_state == mfd->dcm_state) { |
| 4016 | pr_warn("Already in correct DCM/DTM state\n"); |
| 4017 | return ret; |
| 4018 | } |
| 4019 | |
| 4020 | switch (req_state) { |
| 4021 | case DCM_UNBLANK: |
| 4022 | if (mfd->dcm_state == DCM_UNINIT && |
| 4023 | mdss_fb_is_power_off(mfd) && mfd->mdp.on_fnc) { |
| 4024 | if (mfd->disp_thread == NULL) { |
| 4025 | ret = mdss_fb_start_disp_thread(mfd); |
| 4026 | if (ret < 0) |
| 4027 | return ret; |
| 4028 | } |
| 4029 | ret = mfd->mdp.on_fnc(mfd); |
| 4030 | if (ret == 0) { |
| 4031 | mfd->panel_power_state = MDSS_PANEL_POWER_ON; |
| 4032 | mfd->dcm_state = DCM_UNBLANK; |
| 4033 | } |
| 4034 | } |
| 4035 | break; |
| 4036 | case DCM_ENTER: |
| 4037 | if (mfd->dcm_state == DCM_UNBLANK) { |
| 4038 | /* |
| 4039 | * Keep unblank path available for only |
| 4040 | * DCM operation |
| 4041 | */ |
| 4042 | mfd->panel_power_state = MDSS_PANEL_POWER_OFF; |
| 4043 | mfd->dcm_state = DCM_ENTER; |
| 4044 | } |
| 4045 | break; |
| 4046 | case DCM_EXIT: |
| 4047 | if (mfd->dcm_state == DCM_ENTER) { |
| 4048 | /* Release the unblank path for exit */ |
| 4049 | mfd->panel_power_state = MDSS_PANEL_POWER_ON; |
| 4050 | mfd->dcm_state = DCM_EXIT; |
| 4051 | } |
| 4052 | break; |
| 4053 | case DCM_BLANK: |
| 4054 | if ((mfd->dcm_state == DCM_EXIT || |
| 4055 | mfd->dcm_state == DCM_UNBLANK) && |
| 4056 | mdss_fb_is_power_on(mfd) && mfd->mdp.off_fnc) { |
| 4057 | mfd->panel_power_state = MDSS_PANEL_POWER_OFF; |
| 4058 | ret = mfd->mdp.off_fnc(mfd); |
| 4059 | if (ret == 0) |
| 4060 | mfd->dcm_state = DCM_UNINIT; |
| 4061 | else |
| 4062 | pr_err("DCM_BLANK failed\n"); |
| 4063 | |
| 4064 | if (mfd->disp_thread) |
| 4065 | mdss_fb_stop_disp_thread(mfd); |
| 4066 | } |
| 4067 | break; |
| 4068 | case DTM_ENTER: |
| 4069 | if (mfd->dcm_state == DCM_UNINIT) |
| 4070 | mfd->dcm_state = DTM_ENTER; |
| 4071 | break; |
| 4072 | case DTM_EXIT: |
| 4073 | if (mfd->dcm_state == DTM_ENTER) |
| 4074 | mfd->dcm_state = DCM_UNINIT; |
| 4075 | break; |
| 4076 | } |
| 4077 | |
| 4078 | return ret; |
| 4079 | } |
| 4080 | |
| 4081 | static int mdss_fb_cursor(struct fb_info *info, void __user *p) |
| 4082 | { |
| 4083 | struct msm_fb_data_type *mfd = (struct msm_fb_data_type *)info->par; |
| 4084 | struct fb_cursor cursor; |
| 4085 | int ret; |
| 4086 | |
| 4087 | if (!mfd->mdp.cursor_update) |
| 4088 | return -ENODEV; |
| 4089 | |
| 4090 | ret = copy_from_user(&cursor, p, sizeof(cursor)); |
| 4091 | if (ret) |
| 4092 | return ret; |
| 4093 | |
| 4094 | return mfd->mdp.cursor_update(mfd, &cursor); |
| 4095 | } |
| 4096 | |
| 4097 | int mdss_fb_async_position_update(struct fb_info *info, |
| 4098 | struct mdp_position_update *update_pos) |
| 4099 | { |
| 4100 | struct msm_fb_data_type *mfd = (struct msm_fb_data_type *)info->par; |
| 4101 | |
| 4102 | if (!update_pos->input_layer_cnt) { |
| 4103 | pr_err("no input layers for position update\n"); |
| 4104 | return -EINVAL; |
| 4105 | } |
| 4106 | return mfd->mdp.async_position_update(mfd, update_pos); |
| 4107 | } |
| 4108 | |
| 4109 | static int mdss_fb_async_position_update_ioctl(struct fb_info *info, |
| 4110 | unsigned long *argp) |
| 4111 | { |
| 4112 | struct msm_fb_data_type *mfd = (struct msm_fb_data_type *)info->par; |
| 4113 | struct mdp_position_update update_pos; |
| 4114 | int ret, rc; |
| 4115 | u32 buffer_size, layer_cnt; |
| 4116 | struct mdp_async_layer *layer_list = NULL; |
| 4117 | struct mdp_async_layer __user *input_layer_list; |
| 4118 | |
| 4119 | if (!mfd->mdp.async_position_update) |
| 4120 | return -ENODEV; |
| 4121 | |
| 4122 | ret = copy_from_user(&update_pos, argp, sizeof(update_pos)); |
| 4123 | if (ret) { |
| 4124 | pr_err("copy from user failed\n"); |
| 4125 | return ret; |
| 4126 | } |
| 4127 | input_layer_list = update_pos.input_layers; |
| 4128 | |
| 4129 | layer_cnt = update_pos.input_layer_cnt; |
| 4130 | if ((!layer_cnt) || (layer_cnt > MAX_LAYER_COUNT)) { |
| 4131 | pr_err("invalid async layers :%d to update\n", layer_cnt); |
| 4132 | return -EINVAL; |
| 4133 | } |
| 4134 | |
| 4135 | buffer_size = sizeof(struct mdp_async_layer) * layer_cnt; |
| 4136 | layer_list = kmalloc(buffer_size, GFP_KERNEL); |
| 4137 | if (!layer_list) { |
| 4138 | pr_err("unable to allocate memory for layers\n"); |
| 4139 | return -ENOMEM; |
| 4140 | } |
| 4141 | |
| 4142 | ret = copy_from_user(layer_list, input_layer_list, buffer_size); |
| 4143 | if (ret) { |
| 4144 | pr_err("layer list copy from user failed\n"); |
| 4145 | goto end; |
| 4146 | } |
| 4147 | update_pos.input_layers = layer_list; |
| 4148 | |
| 4149 | ret = mdss_fb_async_position_update(info, &update_pos); |
| 4150 | if (ret) |
| 4151 | pr_err("async position update failed ret:%d\n", ret); |
| 4152 | |
| 4153 | rc = copy_to_user(input_layer_list, layer_list, buffer_size); |
| 4154 | if (rc) |
| 4155 | pr_err("layer error code copy to user failed\n"); |
| 4156 | |
| 4157 | update_pos.input_layers = input_layer_list; |
| 4158 | rc = copy_to_user(argp, &update_pos, |
| 4159 | sizeof(struct mdp_position_update)); |
| 4160 | if (rc) |
| 4161 | pr_err("copy to user for layers failed"); |
| 4162 | |
| 4163 | end: |
| 4164 | kfree(layer_list); |
| 4165 | return ret; |
| 4166 | } |
| 4167 | |
| 4168 | static int mdss_fb_set_lut(struct fb_info *info, void __user *p) |
| 4169 | { |
| 4170 | struct msm_fb_data_type *mfd = (struct msm_fb_data_type *)info->par; |
| 4171 | struct fb_cmap cmap; |
| 4172 | int ret; |
| 4173 | |
| 4174 | if (!mfd->mdp.lut_update) |
| 4175 | return -ENODEV; |
| 4176 | |
| 4177 | ret = copy_from_user(&cmap, p, sizeof(cmap)); |
| 4178 | if (ret) |
| 4179 | return ret; |
| 4180 | |
| 4181 | mfd->mdp.lut_update(mfd, &cmap); |
| 4182 | return 0; |
| 4183 | } |
| 4184 | |
| 4185 | /** |
| 4186 | * mdss_fb_sync_get_fence() - get fence from timeline |
| 4187 | * @timeline: Timeline to create the fence on |
| 4188 | * @fence_name: Name of the fence that will be created for debugging |
| 4189 | * @val: Timeline value at which the fence will be signaled |
| 4190 | * |
| 4191 | * Function returns a fence on the timeline given with the name provided. |
| 4192 | * The fence created will be signaled when the timeline is advanced. |
| 4193 | */ |
Sachin Bhayare | 2b6d004 | 2018-01-13 19:38:21 +0530 | [diff] [blame] | 4194 | struct mdss_fence *mdss_fb_sync_get_fence(struct mdss_timeline *timeline, |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 4195 | const char *fence_name, int val) |
| 4196 | { |
Sachin Bhayare | 2b6d004 | 2018-01-13 19:38:21 +0530 | [diff] [blame] | 4197 | struct mdss_fence *fence; |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 4198 | |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 4199 | |
Sachin Bhayare | 2b6d004 | 2018-01-13 19:38:21 +0530 | [diff] [blame] | 4200 | fence = mdss_get_sync_fence(timeline, fence_name, NULL, val); |
| 4201 | pr_debug("%s: buf sync fence timeline=%d\n", |
| 4202 | mdss_get_sync_fence_name(fence), val); |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 4203 | if (fence == NULL) { |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 4204 | pr_err("%s: cannot create fence\n", fence_name); |
| 4205 | return NULL; |
| 4206 | } |
| 4207 | |
| 4208 | return fence; |
| 4209 | } |
| 4210 | |
| 4211 | static int mdss_fb_handle_buf_sync_ioctl(struct msm_sync_pt_data *sync_pt_data, |
| 4212 | struct mdp_buf_sync *buf_sync) |
| 4213 | { |
| 4214 | int i, ret = 0; |
| 4215 | int acq_fen_fd[MDP_MAX_FENCE_FD]; |
Sachin Bhayare | 2b6d004 | 2018-01-13 19:38:21 +0530 | [diff] [blame] | 4216 | struct mdss_fence *fence, *rel_fence, *retire_fence; |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 4217 | int rel_fen_fd; |
| 4218 | int retire_fen_fd; |
| 4219 | int val; |
| 4220 | |
| 4221 | if ((buf_sync->acq_fen_fd_cnt > MDP_MAX_FENCE_FD) || |
| 4222 | (sync_pt_data->timeline == NULL)) |
| 4223 | return -EINVAL; |
| 4224 | |
| 4225 | if (buf_sync->acq_fen_fd_cnt) |
| 4226 | ret = copy_from_user(acq_fen_fd, buf_sync->acq_fen_fd, |
| 4227 | buf_sync->acq_fen_fd_cnt * sizeof(int)); |
| 4228 | if (ret) { |
| 4229 | pr_err("%s: copy_from_user failed\n", sync_pt_data->fence_name); |
| 4230 | return ret; |
| 4231 | } |
| 4232 | |
| 4233 | i = mdss_fb_wait_for_fence(sync_pt_data); |
| 4234 | if (i > 0) |
| 4235 | pr_warn("%s: waited on %d active fences\n", |
| 4236 | sync_pt_data->fence_name, i); |
| 4237 | |
| 4238 | mutex_lock(&sync_pt_data->sync_mutex); |
| 4239 | for (i = 0; i < buf_sync->acq_fen_fd_cnt; i++) { |
Sachin Bhayare | 2b6d004 | 2018-01-13 19:38:21 +0530 | [diff] [blame] | 4240 | fence = mdss_get_fd_sync_fence(acq_fen_fd[i]); |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 4241 | if (fence == NULL) { |
| 4242 | pr_err("%s: null fence! i=%d fd=%d\n", |
| 4243 | sync_pt_data->fence_name, i, |
| 4244 | acq_fen_fd[i]); |
| 4245 | ret = -EINVAL; |
| 4246 | break; |
| 4247 | } |
| 4248 | sync_pt_data->acq_fen[i] = fence; |
| 4249 | } |
| 4250 | sync_pt_data->acq_fen_cnt = i; |
| 4251 | if (ret) |
| 4252 | goto buf_sync_err_1; |
| 4253 | |
Sachin Bhayare | 2b6d004 | 2018-01-13 19:38:21 +0530 | [diff] [blame] | 4254 | val = sync_pt_data->threshold + |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 4255 | atomic_read(&sync_pt_data->commit_cnt); |
| 4256 | |
| 4257 | MDSS_XLOG(sync_pt_data->timeline_value, val, |
| 4258 | atomic_read(&sync_pt_data->commit_cnt)); |
| 4259 | pr_debug("%s: fence CTL%d Commit_cnt%d\n", sync_pt_data->fence_name, |
| 4260 | sync_pt_data->timeline_value, |
| 4261 | atomic_read(&sync_pt_data->commit_cnt)); |
| 4262 | /* Set release fence */ |
| 4263 | rel_fence = mdss_fb_sync_get_fence(sync_pt_data->timeline, |
| 4264 | sync_pt_data->fence_name, val); |
| 4265 | if (IS_ERR_OR_NULL(rel_fence)) { |
| 4266 | pr_err("%s: unable to retrieve release fence\n", |
| 4267 | sync_pt_data->fence_name); |
| 4268 | ret = rel_fence ? PTR_ERR(rel_fence) : -ENOMEM; |
| 4269 | goto buf_sync_err_1; |
| 4270 | } |
| 4271 | |
| 4272 | /* create fd */ |
Sachin Bhayare | 2b6d004 | 2018-01-13 19:38:21 +0530 | [diff] [blame] | 4273 | rel_fen_fd = mdss_get_sync_fence_fd(rel_fence); |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 4274 | if (rel_fen_fd < 0) { |
| 4275 | pr_err("%s: get_unused_fd_flags failed error:0x%x\n", |
| 4276 | sync_pt_data->fence_name, rel_fen_fd); |
| 4277 | ret = rel_fen_fd; |
| 4278 | goto buf_sync_err_2; |
| 4279 | } |
| 4280 | |
| 4281 | ret = copy_to_user(buf_sync->rel_fen_fd, &rel_fen_fd, sizeof(int)); |
| 4282 | if (ret) { |
| 4283 | pr_err("%s: copy_to_user failed\n", sync_pt_data->fence_name); |
| 4284 | goto buf_sync_err_3; |
| 4285 | } |
| 4286 | |
| 4287 | if (!(buf_sync->flags & MDP_BUF_SYNC_FLAG_RETIRE_FENCE)) |
| 4288 | goto skip_retire_fence; |
| 4289 | |
| 4290 | if (sync_pt_data->get_retire_fence) |
| 4291 | retire_fence = sync_pt_data->get_retire_fence(sync_pt_data); |
| 4292 | else |
| 4293 | retire_fence = NULL; |
| 4294 | |
| 4295 | if (IS_ERR_OR_NULL(retire_fence)) { |
| 4296 | val += sync_pt_data->retire_threshold; |
| 4297 | retire_fence = mdss_fb_sync_get_fence( |
| 4298 | sync_pt_data->timeline, "mdp-retire", val); |
| 4299 | } |
| 4300 | |
| 4301 | if (IS_ERR_OR_NULL(retire_fence)) { |
| 4302 | pr_err("%s: unable to retrieve retire fence\n", |
| 4303 | sync_pt_data->fence_name); |
| 4304 | ret = retire_fence ? PTR_ERR(rel_fence) : -ENOMEM; |
| 4305 | goto buf_sync_err_3; |
| 4306 | } |
Sachin Bhayare | 2b6d004 | 2018-01-13 19:38:21 +0530 | [diff] [blame] | 4307 | retire_fen_fd = mdss_get_sync_fence_fd(retire_fence); |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 4308 | |
| 4309 | if (retire_fen_fd < 0) { |
| 4310 | pr_err("%s: get_unused_fd_flags failed for retire fence error:0x%x\n", |
| 4311 | sync_pt_data->fence_name, retire_fen_fd); |
| 4312 | ret = retire_fen_fd; |
Sachin Bhayare | 2b6d004 | 2018-01-13 19:38:21 +0530 | [diff] [blame] | 4313 | mdss_put_sync_fence(retire_fence); |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 4314 | goto buf_sync_err_3; |
| 4315 | } |
| 4316 | |
| 4317 | ret = copy_to_user(buf_sync->retire_fen_fd, &retire_fen_fd, |
| 4318 | sizeof(int)); |
| 4319 | if (ret) { |
| 4320 | pr_err("%s: copy_to_user failed for retire fence\n", |
| 4321 | sync_pt_data->fence_name); |
| 4322 | put_unused_fd(retire_fen_fd); |
Sachin Bhayare | 2b6d004 | 2018-01-13 19:38:21 +0530 | [diff] [blame] | 4323 | mdss_put_sync_fence(retire_fence); |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 4324 | goto buf_sync_err_3; |
| 4325 | } |
| 4326 | |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 4327 | skip_retire_fence: |
Sachin Bhayare | 2b6d004 | 2018-01-13 19:38:21 +0530 | [diff] [blame] | 4328 | mdss_get_sync_fence_fd(rel_fence); |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 4329 | mutex_unlock(&sync_pt_data->sync_mutex); |
| 4330 | |
| 4331 | if (buf_sync->flags & MDP_BUF_SYNC_FLAG_WAIT) |
| 4332 | mdss_fb_wait_for_fence(sync_pt_data); |
| 4333 | |
| 4334 | return ret; |
| 4335 | buf_sync_err_3: |
| 4336 | put_unused_fd(rel_fen_fd); |
| 4337 | buf_sync_err_2: |
Sachin Bhayare | 2b6d004 | 2018-01-13 19:38:21 +0530 | [diff] [blame] | 4338 | mdss_put_sync_fence(rel_fence); |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 4339 | buf_sync_err_1: |
| 4340 | for (i = 0; i < sync_pt_data->acq_fen_cnt; i++) |
Sachin Bhayare | 2b6d004 | 2018-01-13 19:38:21 +0530 | [diff] [blame] | 4341 | mdss_put_sync_fence(sync_pt_data->acq_fen[i]); |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 4342 | sync_pt_data->acq_fen_cnt = 0; |
| 4343 | mutex_unlock(&sync_pt_data->sync_mutex); |
| 4344 | return ret; |
| 4345 | } |
| 4346 | static int mdss_fb_display_commit(struct fb_info *info, |
| 4347 | unsigned long *argp) |
| 4348 | { |
| 4349 | int ret; |
| 4350 | struct mdp_display_commit disp_commit; |
| 4351 | |
| 4352 | ret = copy_from_user(&disp_commit, argp, |
| 4353 | sizeof(disp_commit)); |
| 4354 | if (ret) { |
| 4355 | pr_err("%s:copy_from_user failed\n", __func__); |
| 4356 | return ret; |
| 4357 | } |
| 4358 | ret = mdss_fb_pan_display_ex(info, &disp_commit); |
| 4359 | return ret; |
| 4360 | } |
| 4361 | |
| 4362 | /** |
| 4363 | * __mdss_fb_copy_pixel_ext() - copy pixel extension payload |
| 4364 | * @src: pixel extn structure |
| 4365 | * @dest: Qseed3/pixel extn common payload |
| 4366 | * |
| 4367 | * Function copies the pixel extension parameters into the scale data structure, |
| 4368 | * this is required to allow using the scale_v2 data structure for both |
| 4369 | * QSEED2 and QSEED3 |
| 4370 | */ |
| 4371 | static void __mdss_fb_copy_pixel_ext(struct mdp_scale_data *src, |
| 4372 | struct mdp_scale_data_v2 *dest) |
| 4373 | { |
| 4374 | if (!src || !dest) |
| 4375 | return; |
| 4376 | memcpy(dest->init_phase_x, src->init_phase_x, |
| 4377 | sizeof(src->init_phase_x)); |
| 4378 | memcpy(dest->phase_step_x, src->phase_step_x, |
| 4379 | sizeof(src->init_phase_x)); |
| 4380 | memcpy(dest->init_phase_y, src->init_phase_y, |
| 4381 | sizeof(src->init_phase_x)); |
| 4382 | memcpy(dest->phase_step_y, src->phase_step_y, |
| 4383 | sizeof(src->init_phase_x)); |
| 4384 | |
| 4385 | memcpy(dest->num_ext_pxls_left, src->num_ext_pxls_left, |
| 4386 | sizeof(src->num_ext_pxls_left)); |
| 4387 | memcpy(dest->num_ext_pxls_right, src->num_ext_pxls_right, |
| 4388 | sizeof(src->num_ext_pxls_right)); |
| 4389 | memcpy(dest->num_ext_pxls_top, src->num_ext_pxls_top, |
| 4390 | sizeof(src->num_ext_pxls_top)); |
| 4391 | memcpy(dest->num_ext_pxls_btm, src->num_ext_pxls_btm, |
| 4392 | sizeof(src->num_ext_pxls_btm)); |
| 4393 | |
| 4394 | memcpy(dest->left_ftch, src->left_ftch, sizeof(src->left_ftch)); |
| 4395 | memcpy(dest->left_rpt, src->left_rpt, sizeof(src->left_rpt)); |
| 4396 | memcpy(dest->right_ftch, src->right_ftch, sizeof(src->right_ftch)); |
| 4397 | memcpy(dest->right_rpt, src->right_rpt, sizeof(src->right_rpt)); |
| 4398 | |
| 4399 | |
| 4400 | memcpy(dest->top_rpt, src->top_rpt, sizeof(src->top_rpt)); |
| 4401 | memcpy(dest->btm_rpt, src->btm_rpt, sizeof(src->btm_rpt)); |
| 4402 | memcpy(dest->top_ftch, src->top_ftch, sizeof(src->top_ftch)); |
| 4403 | memcpy(dest->btm_ftch, src->btm_ftch, sizeof(src->btm_ftch)); |
| 4404 | |
| 4405 | memcpy(dest->roi_w, src->roi_w, sizeof(src->roi_w)); |
| 4406 | } |
| 4407 | |
| 4408 | static int __mdss_fb_scaler_handler(struct mdp_input_layer *layer) |
| 4409 | { |
| 4410 | int ret = 0; |
| 4411 | struct mdp_scale_data *pixel_ext = NULL; |
| 4412 | struct mdp_scale_data_v2 *scale = NULL; |
| 4413 | |
| 4414 | if ((layer->flags & MDP_LAYER_ENABLE_PIXEL_EXT) && |
| 4415 | (layer->flags & MDP_LAYER_ENABLE_QSEED3_SCALE)) { |
| 4416 | pr_err("Invalid flag configuration for scaler, %x\n", |
| 4417 | layer->flags); |
| 4418 | ret = -EINVAL; |
| 4419 | goto err; |
| 4420 | } |
| 4421 | |
| 4422 | if (layer->flags & MDP_LAYER_ENABLE_PIXEL_EXT) { |
| 4423 | scale = kzalloc(sizeof(struct mdp_scale_data_v2), |
| 4424 | GFP_KERNEL); |
| 4425 | pixel_ext = kzalloc(sizeof(struct mdp_scale_data), |
| 4426 | GFP_KERNEL); |
| 4427 | if (!scale || !pixel_ext) { |
| 4428 | mdss_mdp_free_layer_pp_info(layer); |
| 4429 | ret = -ENOMEM; |
| 4430 | goto err; |
| 4431 | } |
| 4432 | ret = copy_from_user(pixel_ext, layer->scale, |
| 4433 | sizeof(struct mdp_scale_data)); |
| 4434 | if (ret) { |
| 4435 | mdss_mdp_free_layer_pp_info(layer); |
| 4436 | ret = -EFAULT; |
| 4437 | goto err; |
| 4438 | } |
| 4439 | __mdss_fb_copy_pixel_ext(pixel_ext, scale); |
| 4440 | layer->scale = scale; |
| 4441 | } else if (layer->flags & MDP_LAYER_ENABLE_QSEED3_SCALE) { |
| 4442 | scale = kzalloc(sizeof(struct mdp_scale_data_v2), |
| 4443 | GFP_KERNEL); |
| 4444 | if (!scale) { |
| 4445 | mdss_mdp_free_layer_pp_info(layer); |
| 4446 | ret = -ENOMEM; |
| 4447 | goto err; |
| 4448 | } |
| 4449 | |
| 4450 | ret = copy_from_user(scale, layer->scale, |
| 4451 | sizeof(struct mdp_scale_data_v2)); |
| 4452 | if (ret) { |
| 4453 | mdss_mdp_free_layer_pp_info(layer); |
| 4454 | ret = -EFAULT; |
| 4455 | goto err; |
| 4456 | } |
| 4457 | layer->scale = scale; |
| 4458 | } else { |
| 4459 | layer->scale = NULL; |
| 4460 | } |
| 4461 | kfree(pixel_ext); |
| 4462 | return ret; |
| 4463 | err: |
| 4464 | kfree(pixel_ext); |
| 4465 | kfree(scale); |
| 4466 | layer->scale = NULL; |
| 4467 | return ret; |
| 4468 | } |
| 4469 | |
| 4470 | static int mdss_fb_atomic_commit_ioctl(struct fb_info *info, |
| 4471 | unsigned long *argp, struct file *file) |
| 4472 | { |
| 4473 | int ret, i = 0, j = 0, rc; |
| 4474 | struct mdp_layer_commit commit; |
| 4475 | u32 buffer_size, layer_count; |
| 4476 | struct mdp_input_layer *layer, *layer_list = NULL; |
| 4477 | struct mdp_input_layer __user *input_layer_list; |
| 4478 | struct mdp_output_layer *output_layer = NULL; |
| 4479 | struct mdp_output_layer __user *output_layer_user; |
| 4480 | struct mdp_frc_info *frc_info = NULL; |
| 4481 | struct mdp_frc_info __user *frc_info_user; |
| 4482 | struct msm_fb_data_type *mfd; |
| 4483 | struct mdss_overlay_private *mdp5_data = NULL; |
| 4484 | |
| 4485 | ret = copy_from_user(&commit, argp, sizeof(struct mdp_layer_commit)); |
| 4486 | if (ret) { |
| 4487 | pr_err("%s:copy_from_user failed\n", __func__); |
| 4488 | return ret; |
| 4489 | } |
| 4490 | |
| 4491 | mfd = (struct msm_fb_data_type *)info->par; |
| 4492 | if (!mfd) |
| 4493 | return -EINVAL; |
| 4494 | |
| 4495 | mdp5_data = mfd_to_mdp5_data(mfd); |
| 4496 | |
| 4497 | if (mfd->panel_info->panel_dead) { |
| 4498 | pr_debug("early commit return\n"); |
| 4499 | MDSS_XLOG(mfd->panel_info->panel_dead); |
| 4500 | /* |
| 4501 | * In case of an ESD attack, since we early return from the |
| 4502 | * commits, we need to signal the outstanding fences. |
| 4503 | */ |
| 4504 | mdss_fb_release_fences(mfd); |
| 4505 | if ((mfd->panel.type == MIPI_CMD_PANEL) && |
| 4506 | mfd->mdp.signal_retire_fence && mdp5_data) |
| 4507 | mfd->mdp.signal_retire_fence(mfd, |
| 4508 | mdp5_data->retire_cnt); |
| 4509 | return 0; |
| 4510 | } |
| 4511 | |
| 4512 | output_layer_user = commit.commit_v1.output_layer; |
| 4513 | if (output_layer_user) { |
| 4514 | buffer_size = sizeof(struct mdp_output_layer); |
| 4515 | output_layer = kzalloc(buffer_size, GFP_KERNEL); |
| 4516 | if (!output_layer) { |
| 4517 | pr_err("unable to allocate memory for output layer\n"); |
| 4518 | return -ENOMEM; |
| 4519 | } |
| 4520 | |
| 4521 | ret = copy_from_user(output_layer, |
| 4522 | output_layer_user, buffer_size); |
| 4523 | if (ret) { |
| 4524 | pr_err("layer list copy from user failed\n"); |
| 4525 | goto err; |
| 4526 | } |
| 4527 | commit.commit_v1.output_layer = output_layer; |
| 4528 | } |
| 4529 | |
| 4530 | layer_count = commit.commit_v1.input_layer_cnt; |
| 4531 | input_layer_list = commit.commit_v1.input_layers; |
| 4532 | |
| 4533 | if (layer_count > MAX_LAYER_COUNT) { |
| 4534 | ret = -EINVAL; |
| 4535 | goto err; |
| 4536 | } else if (layer_count) { |
| 4537 | buffer_size = sizeof(struct mdp_input_layer) * layer_count; |
| 4538 | layer_list = kzalloc(buffer_size, GFP_KERNEL); |
| 4539 | if (!layer_list) { |
| 4540 | pr_err("unable to allocate memory for layers\n"); |
| 4541 | ret = -ENOMEM; |
| 4542 | goto err; |
| 4543 | } |
| 4544 | |
| 4545 | ret = copy_from_user(layer_list, input_layer_list, buffer_size); |
| 4546 | if (ret) { |
| 4547 | pr_err("layer list copy from user failed\n"); |
| 4548 | goto err; |
| 4549 | } |
| 4550 | |
| 4551 | commit.commit_v1.input_layers = layer_list; |
| 4552 | |
| 4553 | for (i = 0; i < layer_count; i++) { |
| 4554 | layer = &layer_list[i]; |
| 4555 | |
| 4556 | if (!(layer->flags & MDP_LAYER_PP)) { |
| 4557 | layer->pp_info = NULL; |
| 4558 | } else { |
| 4559 | ret = mdss_mdp_copy_layer_pp_info(layer); |
| 4560 | if (ret) { |
| 4561 | pr_err("failure to copy pp_info data for layer %d, ret = %d\n", |
| 4562 | i, ret); |
| 4563 | goto err; |
| 4564 | } |
| 4565 | } |
| 4566 | |
| 4567 | if ((layer->flags & MDP_LAYER_ENABLE_PIXEL_EXT) || |
| 4568 | (layer->flags & |
| 4569 | MDP_LAYER_ENABLE_QSEED3_SCALE)) { |
| 4570 | ret = __mdss_fb_scaler_handler(layer); |
| 4571 | if (ret) { |
| 4572 | pr_err("failure to copy scale params for layer %d, ret = %d\n", |
| 4573 | i, ret); |
| 4574 | goto err; |
| 4575 | } |
| 4576 | } else { |
| 4577 | layer->scale = NULL; |
| 4578 | } |
| 4579 | } |
| 4580 | } |
| 4581 | |
| 4582 | /* Copy Deterministic Frame Rate Control info from userspace */ |
| 4583 | frc_info_user = commit.commit_v1.frc_info; |
| 4584 | if (frc_info_user) { |
| 4585 | frc_info = kzalloc(sizeof(struct mdp_frc_info), GFP_KERNEL); |
| 4586 | if (!frc_info) { |
| 4587 | pr_err("unable to allocate memory for frc\n"); |
| 4588 | ret = -ENOMEM; |
| 4589 | goto err; |
| 4590 | } |
| 4591 | |
| 4592 | ret = copy_from_user(frc_info, frc_info_user, |
| 4593 | sizeof(struct mdp_frc_info)); |
| 4594 | if (ret) { |
| 4595 | pr_err("frc info copy from user failed\n"); |
| 4596 | goto frc_err; |
| 4597 | } |
| 4598 | |
| 4599 | commit.commit_v1.frc_info = frc_info; |
| 4600 | } |
| 4601 | |
| 4602 | ATRACE_BEGIN("ATOMIC_COMMIT"); |
| 4603 | ret = mdss_fb_atomic_commit(info, &commit, file); |
| 4604 | if (ret) |
| 4605 | pr_err("atomic commit failed ret:%d\n", ret); |
| 4606 | ATRACE_END("ATOMIC_COMMIT"); |
| 4607 | |
| 4608 | if (layer_count) { |
| 4609 | for (j = 0; j < layer_count; j++) { |
| 4610 | rc = copy_to_user(&input_layer_list[j].error_code, |
| 4611 | &layer_list[j].error_code, sizeof(int)); |
| 4612 | if (rc) |
| 4613 | pr_err("layer error code copy to user failed\n"); |
| 4614 | } |
| 4615 | |
| 4616 | commit.commit_v1.input_layers = input_layer_list; |
| 4617 | commit.commit_v1.output_layer = output_layer_user; |
| 4618 | commit.commit_v1.frc_info = frc_info_user; |
| 4619 | rc = copy_to_user(argp, &commit, |
| 4620 | sizeof(struct mdp_layer_commit)); |
| 4621 | if (rc) |
| 4622 | pr_err("copy to user for release & retire fence failed\n"); |
| 4623 | } |
| 4624 | |
| 4625 | frc_err: |
| 4626 | kfree(frc_info); |
| 4627 | err: |
| 4628 | for (i--; i >= 0; i--) { |
| 4629 | kfree(layer_list[i].scale); |
| 4630 | layer_list[i].scale = NULL; |
| 4631 | mdss_mdp_free_layer_pp_info(&layer_list[i]); |
| 4632 | } |
| 4633 | kfree(layer_list); |
| 4634 | kfree(output_layer); |
| 4635 | |
| 4636 | return ret; |
| 4637 | } |
| 4638 | |
| 4639 | int mdss_fb_switch_check(struct msm_fb_data_type *mfd, u32 mode) |
| 4640 | { |
| 4641 | struct mdss_panel_info *pinfo = NULL; |
| 4642 | int panel_type; |
| 4643 | |
| 4644 | if (!mfd || !mfd->panel_info) |
| 4645 | return -EINVAL; |
| 4646 | |
| 4647 | pinfo = mfd->panel_info; |
| 4648 | |
| 4649 | if ((!mfd->op_enable) || (mdss_fb_is_power_off(mfd))) |
| 4650 | return -EPERM; |
| 4651 | |
| 4652 | if (pinfo->mipi.dms_mode != DYNAMIC_MODE_SWITCH_IMMEDIATE) { |
| 4653 | pr_warn("Panel does not support immediate dynamic switch!\n"); |
| 4654 | return -EPERM; |
| 4655 | } |
| 4656 | |
| 4657 | if (mfd->dcm_state != DCM_UNINIT) { |
| 4658 | pr_warn("Switch not supported during DCM!\n"); |
| 4659 | return -EPERM; |
| 4660 | } |
| 4661 | |
| 4662 | mutex_lock(&mfd->switch_lock); |
| 4663 | if (mode == pinfo->type) { |
| 4664 | pr_debug("Already in requested mode!\n"); |
| 4665 | mutex_unlock(&mfd->switch_lock); |
| 4666 | return -EPERM; |
| 4667 | } |
| 4668 | mutex_unlock(&mfd->switch_lock); |
| 4669 | |
| 4670 | panel_type = mfd->panel.type; |
| 4671 | if (panel_type != MIPI_VIDEO_PANEL && panel_type != MIPI_CMD_PANEL) { |
| 4672 | pr_debug("Panel not in mipi video or cmd mode, cannot change\n"); |
| 4673 | return -EPERM; |
| 4674 | } |
| 4675 | |
| 4676 | return 0; |
| 4677 | } |
| 4678 | |
| 4679 | static int mdss_fb_immediate_mode_switch(struct msm_fb_data_type *mfd, u32 mode) |
| 4680 | { |
| 4681 | int ret; |
| 4682 | u32 tranlated_mode; |
| 4683 | |
| 4684 | if (mode) |
| 4685 | tranlated_mode = MIPI_CMD_PANEL; |
| 4686 | else |
| 4687 | tranlated_mode = MIPI_VIDEO_PANEL; |
| 4688 | |
| 4689 | pr_debug("%s: Request to switch to %d,", __func__, tranlated_mode); |
| 4690 | |
| 4691 | ret = mdss_fb_switch_check(mfd, tranlated_mode); |
| 4692 | if (ret) |
| 4693 | return ret; |
| 4694 | |
| 4695 | mutex_lock(&mfd->switch_lock); |
| 4696 | if (mfd->switch_state != MDSS_MDP_NO_UPDATE_REQUESTED) { |
| 4697 | pr_err("%s: Mode switch already in progress\n", __func__); |
| 4698 | ret = -EAGAIN; |
| 4699 | goto exit; |
| 4700 | } |
| 4701 | mfd->switch_state = MDSS_MDP_WAIT_FOR_VALIDATE; |
| 4702 | mfd->switch_new_mode = tranlated_mode; |
| 4703 | |
| 4704 | exit: |
| 4705 | mutex_unlock(&mfd->switch_lock); |
| 4706 | return ret; |
| 4707 | } |
| 4708 | |
| 4709 | /* |
| 4710 | * mdss_fb_mode_switch() - Function to change DSI mode |
| 4711 | * @mfd: Framebuffer data structure for display |
| 4712 | * @mode: Enabled/Disable LowPowerMode |
| 4713 | * 1: Switch to Command Mode |
| 4714 | * 0: Switch to video Mode |
| 4715 | * |
| 4716 | * This function is used to change from DSI mode based on the |
| 4717 | * argument @mode on the next frame to be displayed. |
| 4718 | */ |
| 4719 | static int mdss_fb_mode_switch(struct msm_fb_data_type *mfd, u32 mode) |
| 4720 | { |
| 4721 | struct mdss_panel_info *pinfo = NULL; |
| 4722 | int ret = 0; |
| 4723 | |
| 4724 | if (!mfd || !mfd->panel_info) |
| 4725 | return -EINVAL; |
| 4726 | |
| 4727 | pinfo = mfd->panel_info; |
| 4728 | if (pinfo->mipi.dms_mode == DYNAMIC_MODE_SWITCH_SUSPEND_RESUME) { |
| 4729 | ret = mdss_fb_blanking_mode_switch(mfd, mode); |
| 4730 | } else if (pinfo->mipi.dms_mode == DYNAMIC_MODE_SWITCH_IMMEDIATE) { |
| 4731 | ret = mdss_fb_immediate_mode_switch(mfd, mode); |
| 4732 | } else { |
| 4733 | pr_warn("Panel does not support dynamic mode switch!\n"); |
| 4734 | ret = -EPERM; |
| 4735 | } |
| 4736 | |
| 4737 | return ret; |
| 4738 | } |
| 4739 | |
| 4740 | static int __ioctl_wait_idle(struct msm_fb_data_type *mfd, u32 cmd) |
| 4741 | { |
| 4742 | int ret = 0; |
| 4743 | |
| 4744 | if (mfd->wait_for_kickoff && |
| 4745 | ((cmd == MSMFB_OVERLAY_PREPARE) || |
| 4746 | (cmd == MSMFB_BUFFER_SYNC) || |
| 4747 | (cmd == MSMFB_OVERLAY_PLAY) || |
| 4748 | (cmd == MSMFB_CURSOR) || |
| 4749 | (cmd == MSMFB_METADATA_GET) || |
| 4750 | (cmd == MSMFB_METADATA_SET) || |
| 4751 | (cmd == MSMFB_OVERLAY_GET) || |
| 4752 | (cmd == MSMFB_OVERLAY_UNSET) || |
| 4753 | (cmd == MSMFB_OVERLAY_SET))) { |
| 4754 | ret = mdss_fb_wait_for_kickoff(mfd); |
| 4755 | } |
| 4756 | |
| 4757 | if (ret && (ret != -ESHUTDOWN)) |
| 4758 | pr_err("wait_idle failed. cmd=0x%x rc=%d\n", cmd, ret); |
| 4759 | |
| 4760 | return ret; |
| 4761 | } |
| 4762 | |
| 4763 | #ifdef TARGET_HW_MDSS_MDP3 |
| 4764 | static bool check_not_supported_ioctl(u32 cmd) |
| 4765 | { |
| 4766 | return false; |
| 4767 | } |
| 4768 | #else |
| 4769 | static bool check_not_supported_ioctl(u32 cmd) |
| 4770 | { |
| 4771 | return((cmd == MSMFB_OVERLAY_SET) || (cmd == MSMFB_OVERLAY_UNSET) || |
| 4772 | (cmd == MSMFB_OVERLAY_GET) || (cmd == MSMFB_OVERLAY_PREPARE) || |
| 4773 | (cmd == MSMFB_DISPLAY_COMMIT) || (cmd == MSMFB_OVERLAY_PLAY) || |
| 4774 | (cmd == MSMFB_BUFFER_SYNC) || (cmd == MSMFB_OVERLAY_QUEUE) || |
| 4775 | (cmd == MSMFB_NOTIFY_UPDATE)); |
| 4776 | } |
| 4777 | #endif |
| 4778 | |
| 4779 | /* |
| 4780 | * mdss_fb_do_ioctl() - MDSS Framebuffer ioctl function |
| 4781 | * @info: pointer to framebuffer info |
| 4782 | * @cmd: ioctl command |
| 4783 | * @arg: argument to ioctl |
| 4784 | * |
| 4785 | * This function provides an architecture agnostic implementation |
| 4786 | * of the mdss framebuffer ioctl. This function can be called |
| 4787 | * by compat ioctl or regular ioctl to handle the supported commands. |
| 4788 | */ |
| 4789 | int mdss_fb_do_ioctl(struct fb_info *info, unsigned int cmd, |
| 4790 | unsigned long arg, struct file *file) |
| 4791 | { |
| 4792 | struct msm_fb_data_type *mfd; |
| 4793 | void __user *argp = (void __user *)arg; |
Sachin Bhayare | 3d3767e | 2018-01-02 21:10:57 +0530 | [diff] [blame] | 4794 | int ret = -ENOTSUPP; |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 4795 | struct mdp_buf_sync buf_sync; |
| 4796 | unsigned int dsi_mode = 0; |
| 4797 | struct mdss_panel_data *pdata = NULL; |
| 4798 | |
| 4799 | if (!info || !info->par) |
| 4800 | return -EINVAL; |
| 4801 | |
| 4802 | mfd = (struct msm_fb_data_type *)info->par; |
| 4803 | if (!mfd) |
| 4804 | return -EINVAL; |
| 4805 | |
| 4806 | if (mfd->shutdown_pending) |
| 4807 | return -ESHUTDOWN; |
| 4808 | |
| 4809 | pdata = dev_get_platdata(&mfd->pdev->dev); |
| 4810 | if (!pdata || pdata->panel_info.dynamic_switch_pending) |
| 4811 | return -EPERM; |
| 4812 | |
| 4813 | if (check_not_supported_ioctl(cmd)) { |
| 4814 | pr_err("Unsupported ioctl\n"); |
| 4815 | return -EINVAL; |
| 4816 | } |
| 4817 | |
| 4818 | atomic_inc(&mfd->ioctl_ref_cnt); |
| 4819 | |
| 4820 | mdss_fb_power_setting_idle(mfd); |
| 4821 | |
| 4822 | ret = __ioctl_wait_idle(mfd, cmd); |
| 4823 | if (ret) |
| 4824 | goto exit; |
| 4825 | |
| 4826 | switch (cmd) { |
| 4827 | case MSMFB_CURSOR: |
| 4828 | ret = mdss_fb_cursor(info, argp); |
| 4829 | break; |
| 4830 | |
| 4831 | case MSMFB_SET_LUT: |
| 4832 | ret = mdss_fb_set_lut(info, argp); |
| 4833 | break; |
| 4834 | |
| 4835 | case MSMFB_BUFFER_SYNC: |
| 4836 | ret = copy_from_user(&buf_sync, argp, sizeof(buf_sync)); |
| 4837 | if (ret) |
| 4838 | goto exit; |
| 4839 | |
| 4840 | if ((!mfd->op_enable) || (mdss_fb_is_power_off(mfd))) { |
| 4841 | ret = -EPERM; |
| 4842 | goto exit; |
| 4843 | } |
| 4844 | |
| 4845 | ret = mdss_fb_handle_buf_sync_ioctl(&mfd->mdp_sync_pt_data, |
| 4846 | &buf_sync); |
| 4847 | if (!ret) |
| 4848 | ret = copy_to_user(argp, &buf_sync, sizeof(buf_sync)); |
| 4849 | break; |
| 4850 | |
| 4851 | case MSMFB_NOTIFY_UPDATE: |
| 4852 | ret = mdss_fb_notify_update(mfd, argp); |
| 4853 | break; |
| 4854 | |
| 4855 | case MSMFB_DISPLAY_COMMIT: |
| 4856 | ret = mdss_fb_display_commit(info, argp); |
| 4857 | break; |
| 4858 | |
| 4859 | case MSMFB_LPM_ENABLE: |
| 4860 | ret = copy_from_user(&dsi_mode, argp, sizeof(dsi_mode)); |
| 4861 | if (ret) { |
| 4862 | pr_err("%s: MSMFB_LPM_ENABLE ioctl failed\n", __func__); |
| 4863 | goto exit; |
| 4864 | } |
| 4865 | |
| 4866 | ret = mdss_fb_mode_switch(mfd, dsi_mode); |
| 4867 | break; |
| 4868 | case MSMFB_ATOMIC_COMMIT: |
| 4869 | ret = mdss_fb_atomic_commit_ioctl(info, argp, file); |
| 4870 | break; |
| 4871 | |
| 4872 | case MSMFB_ASYNC_POSITION_UPDATE: |
| 4873 | ret = mdss_fb_async_position_update_ioctl(info, argp); |
| 4874 | break; |
| 4875 | |
| 4876 | default: |
| 4877 | if (mfd->mdp.ioctl_handler) |
| 4878 | ret = mfd->mdp.ioctl_handler(mfd, cmd, argp); |
| 4879 | break; |
| 4880 | } |
| 4881 | |
Sachin Bhayare | 3d3767e | 2018-01-02 21:10:57 +0530 | [diff] [blame] | 4882 | if (ret == -ENOTSUPP) |
Sachin Bhayare | eeb8889 | 2018-01-02 16:36:01 +0530 | [diff] [blame] | 4883 | pr_err("unsupported ioctl (%x)\n", cmd); |
| 4884 | |
| 4885 | exit: |
| 4886 | if (!atomic_dec_return(&mfd->ioctl_ref_cnt)) |
| 4887 | wake_up_all(&mfd->ioctl_q); |
| 4888 | |
| 4889 | return ret; |
| 4890 | } |
| 4891 | |
| 4892 | static int mdss_fb_ioctl(struct fb_info *info, unsigned int cmd, |
| 4893 | unsigned long arg, struct file *file) |
| 4894 | { |
| 4895 | if (!info || !info->par) |
| 4896 | return -EINVAL; |
| 4897 | |
| 4898 | return mdss_fb_do_ioctl(info, cmd, arg, file); |
| 4899 | } |
| 4900 | |
| 4901 | static int mdss_fb_register_extra_panel(struct platform_device *pdev, |
| 4902 | struct mdss_panel_data *pdata) |
| 4903 | { |
| 4904 | struct mdss_panel_data *fb_pdata; |
| 4905 | |
| 4906 | fb_pdata = dev_get_platdata(&pdev->dev); |
| 4907 | if (!fb_pdata) { |
| 4908 | pr_err("framebuffer device %s contains invalid panel data\n", |
| 4909 | dev_name(&pdev->dev)); |
| 4910 | return -EINVAL; |
| 4911 | } |
| 4912 | |
| 4913 | if (fb_pdata->next) { |
| 4914 | pr_err("split panel already setup for framebuffer device %s\n", |
| 4915 | dev_name(&pdev->dev)); |
| 4916 | return -EEXIST; |
| 4917 | } |
| 4918 | |
| 4919 | fb_pdata->next = pdata; |
| 4920 | |
| 4921 | return 0; |
| 4922 | } |
| 4923 | |
| 4924 | int mdss_register_panel(struct platform_device *pdev, |
| 4925 | struct mdss_panel_data *pdata) |
| 4926 | { |
| 4927 | struct platform_device *fb_pdev, *mdss_pdev; |
| 4928 | struct device_node *node = NULL; |
| 4929 | int rc = 0; |
| 4930 | bool master_panel = true; |
| 4931 | |
| 4932 | if (!pdev || !pdev->dev.of_node) { |
| 4933 | pr_err("Invalid device node\n"); |
| 4934 | return -ENODEV; |
| 4935 | } |
| 4936 | |
| 4937 | if (!mdp_instance) { |
| 4938 | pr_err("mdss mdp resource not initialized yet\n"); |
| 4939 | return -EPROBE_DEFER; |
| 4940 | } |
| 4941 | |
| 4942 | if (pdata->get_fb_node) |
| 4943 | node = pdata->get_fb_node(pdev); |
| 4944 | |
| 4945 | if (!node) { |
| 4946 | node = of_parse_phandle(pdev->dev.of_node, |
| 4947 | "qcom,mdss-fb-map", 0); |
| 4948 | if (!node) { |
| 4949 | pr_err("Unable to find fb node for device: %s\n", |
| 4950 | pdev->name); |
| 4951 | return -ENODEV; |
| 4952 | } |
| 4953 | } |
| 4954 | mdss_pdev = of_find_device_by_node(node->parent); |
| 4955 | if (!mdss_pdev) { |
| 4956 | pr_err("Unable to find mdss for node: %s\n", node->full_name); |
| 4957 | rc = -ENODEV; |
| 4958 | goto mdss_notfound; |
| 4959 | } |
| 4960 | |
| 4961 | pdata->active = true; |
| 4962 | fb_pdev = of_find_device_by_node(node); |
| 4963 | if (fb_pdev) { |
| 4964 | rc = mdss_fb_register_extra_panel(fb_pdev, pdata); |
| 4965 | if (rc == 0) |
| 4966 | master_panel = false; |
| 4967 | } else { |
| 4968 | pr_info("adding framebuffer device %s\n", dev_name(&pdev->dev)); |
| 4969 | fb_pdev = of_platform_device_create(node, NULL, |
| 4970 | &mdss_pdev->dev); |
| 4971 | if (fb_pdev) |
| 4972 | fb_pdev->dev.platform_data = pdata; |
| 4973 | } |
| 4974 | |
| 4975 | if (master_panel && mdp_instance->panel_register_done) |
| 4976 | mdp_instance->panel_register_done(pdata); |
| 4977 | |
| 4978 | mdss_notfound: |
| 4979 | of_node_put(node); |
| 4980 | return rc; |
| 4981 | } |
| 4982 | EXPORT_SYMBOL(mdss_register_panel); |
| 4983 | |
| 4984 | int mdss_fb_register_mdp_instance(struct msm_mdp_interface *mdp) |
| 4985 | { |
| 4986 | if (mdp_instance) { |
| 4987 | pr_err("multiple MDP instance registration\n"); |
| 4988 | return -EINVAL; |
| 4989 | } |
| 4990 | |
| 4991 | mdp_instance = mdp; |
| 4992 | return 0; |
| 4993 | } |
| 4994 | EXPORT_SYMBOL(mdss_fb_register_mdp_instance); |
| 4995 | |
| 4996 | int mdss_fb_get_phys_info(dma_addr_t *start, unsigned long *len, int fb_num) |
| 4997 | { |
| 4998 | struct fb_info *info; |
| 4999 | struct msm_fb_data_type *mfd; |
| 5000 | |
| 5001 | if (fb_num >= MAX_FBI_LIST) |
| 5002 | return -EINVAL; |
| 5003 | |
| 5004 | info = fbi_list[fb_num]; |
| 5005 | if (!info) |
| 5006 | return -ENOENT; |
| 5007 | |
| 5008 | mfd = (struct msm_fb_data_type *)info->par; |
| 5009 | if (!mfd) |
| 5010 | return -ENODEV; |
| 5011 | |
| 5012 | if (mfd->iova) |
| 5013 | *start = mfd->iova; |
| 5014 | else |
| 5015 | *start = info->fix.smem_start; |
| 5016 | *len = info->fix.smem_len; |
| 5017 | |
| 5018 | return 0; |
| 5019 | } |
| 5020 | EXPORT_SYMBOL(mdss_fb_get_phys_info); |
| 5021 | |
| 5022 | int __init mdss_fb_init(void) |
| 5023 | { |
| 5024 | int rc = -ENODEV; |
| 5025 | |
| 5026 | if (fb_get_options("msmfb", NULL)) |
| 5027 | return rc; |
| 5028 | |
| 5029 | if (platform_driver_register(&mdss_fb_driver)) |
| 5030 | return rc; |
| 5031 | |
| 5032 | return 0; |
| 5033 | } |
| 5034 | |
| 5035 | module_init(mdss_fb_init); |
| 5036 | |
| 5037 | int mdss_fb_suspres_panel(struct device *dev, void *data) |
| 5038 | { |
| 5039 | struct msm_fb_data_type *mfd; |
| 5040 | int rc = 0; |
| 5041 | u32 event; |
| 5042 | |
| 5043 | if (!data) { |
| 5044 | pr_err("Device state not defined\n"); |
| 5045 | return -EINVAL; |
| 5046 | } |
| 5047 | mfd = dev_get_drvdata(dev); |
| 5048 | if (!mfd) |
| 5049 | return 0; |
| 5050 | |
| 5051 | event = *((bool *) data) ? MDSS_EVENT_RESUME : MDSS_EVENT_SUSPEND; |
| 5052 | |
| 5053 | /* Do not send runtime suspend/resume for HDMI primary */ |
| 5054 | if (!mdss_fb_is_hdmi_primary(mfd)) { |
| 5055 | rc = mdss_fb_send_panel_event(mfd, event, NULL); |
| 5056 | if (rc) |
| 5057 | pr_warn("unable to %s fb%d (%d)\n", |
| 5058 | event == MDSS_EVENT_RESUME ? |
| 5059 | "resume" : "suspend", |
| 5060 | mfd->index, rc); |
| 5061 | } |
| 5062 | return rc; |
| 5063 | } |
| 5064 | |
| 5065 | /* |
| 5066 | * mdss_fb_report_panel_dead() - Sends the PANEL_ALIVE=0 status to HAL layer. |
| 5067 | * @mfd : frame buffer structure associated with fb device. |
| 5068 | * |
| 5069 | * This function is called if the panel fails to respond as expected to |
| 5070 | * the register read/BTA or if the TE signal is not coming as expected |
| 5071 | * from the panel. The function sends the PANEL_ALIVE=0 status to HAL |
| 5072 | * layer. |
| 5073 | */ |
| 5074 | void mdss_fb_report_panel_dead(struct msm_fb_data_type *mfd) |
| 5075 | { |
| 5076 | char *envp[2] = {"PANEL_ALIVE=0", NULL}; |
| 5077 | struct mdss_panel_data *pdata = |
| 5078 | dev_get_platdata(&mfd->pdev->dev); |
| 5079 | if (!pdata) { |
| 5080 | pr_err("Panel data not available\n"); |
| 5081 | return; |
| 5082 | } |
| 5083 | |
| 5084 | pdata->panel_info.panel_dead = true; |
| 5085 | kobject_uevent_env(&mfd->fbi->dev->kobj, |
| 5086 | KOBJ_CHANGE, envp); |
| 5087 | pr_err("Panel has gone bad, sending uevent - %s\n", envp[0]); |
| 5088 | } |
| 5089 | |
| 5090 | |
| 5091 | /* |
| 5092 | * mdss_fb_calc_fps() - Calculates fps value. |
| 5093 | * @mfd : frame buffer structure associated with fb device. |
| 5094 | * |
| 5095 | * This function is called at frame done. It counts the number |
| 5096 | * of frames done for every 1 sec. Stores the value in measured_fps. |
| 5097 | * measured_fps value is 10 times the calculated fps value. |
| 5098 | * For example, measured_fps= 594 for calculated fps of 59.4 |
| 5099 | */ |
| 5100 | void mdss_fb_calc_fps(struct msm_fb_data_type *mfd) |
| 5101 | { |
| 5102 | ktime_t current_time_us; |
| 5103 | u64 fps, diff_us; |
| 5104 | |
| 5105 | current_time_us = ktime_get(); |
| 5106 | diff_us = (u64)ktime_us_delta(current_time_us, |
| 5107 | mfd->fps_info.last_sampled_time_us); |
| 5108 | mfd->fps_info.frame_count++; |
| 5109 | |
| 5110 | if (diff_us >= MDP_TIME_PERIOD_CALC_FPS_US) { |
| 5111 | fps = ((u64)mfd->fps_info.frame_count) * 10000000; |
| 5112 | do_div(fps, diff_us); |
| 5113 | mfd->fps_info.measured_fps = (unsigned int)fps; |
| 5114 | pr_debug(" MDP_FPS for fb%d is %d.%d\n", |
| 5115 | mfd->index, (unsigned int)fps/10, (unsigned int)fps%10); |
| 5116 | mfd->fps_info.last_sampled_time_us = current_time_us; |
| 5117 | mfd->fps_info.frame_count = 0; |
| 5118 | } |
| 5119 | } |