| /* |
| * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved. |
| * |
| * This program is free software; you can redistribute it and/or modify |
| * it under the terms of the GNU General Public License version 2 and |
| * only version 2 as published by the Free Software Foundation. |
| * |
| * This program is distributed in the hope that it will be useful, |
| * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| * GNU General Public License for more details. |
| * |
| */ |
| |
| #include <linux/delay.h> |
| #include <linux/slab.h> |
| #include <linux/gpio.h> |
| #include <linux/of_gpio.h> |
| |
| #include "dsi_panel.h" |
| #include "dsi_ctrl_hw.h" |
| |
| #define DSI_PANEL_DEFAULT_LABEL "Default dsi panel" |
| |
| #define DEFAULT_MDP_TRANSFER_TIME 14000 |
| |
| #define DEFAULT_PANEL_JITTER 5 |
| #define MAX_PANEL_JITTER 25 |
| #define DEFAULT_PANEL_PREFILL_LINES 16 |
| |
| static u32 dsi_dsc_rc_buf_thresh[] = {0x0e, 0x1c, 0x2a, 0x38, 0x46, 0x54, |
| 0x62, 0x69, 0x70, 0x77, 0x79, 0x7b, 0x7d, 0x7e}; |
| static char dsi_dsc_rc_range_min_qp_1_1[] = {0, 0, 1, 1, 3, 3, 3, 3, 3, 3, 5, |
| 5, 5, 7, 13}; |
| static char dsi_dsc_rc_range_min_qp_1_1_scr1[] = {0, 0, 1, 1, 3, 3, 3, 3, 3, 3, |
| 5, 5, 5, 9, 12}; |
| static char dsi_dsc_rc_range_max_qp_1_1[] = {4, 4, 5, 6, 7, 7, 7, 8, 9, 10, 11, |
| 12, 13, 13, 15}; |
| static char dsi_dsc_rc_range_max_qp_1_1_scr1[] = {4, 4, 5, 6, 7, 7, 7, 8, 9, 10, |
| 11, 11, 12, 13}; |
| static char dsi_dsc_rc_range_bpg_offset[] = {2, 0, 0, -2, -4, -6, -8, -8, |
| -8, -10, -10, -12, -12, -12, -12}; |
| |
| int dsi_dsc_create_pps_buf_cmd(struct msm_display_dsc_info *dsc, char *buf, |
| int pps_id) |
| { |
| char *bp; |
| char data; |
| int i, bpp; |
| char *dbgbp; |
| |
| dbgbp = buf; |
| bp = buf; |
| /* First 7 bytes are cmd header */ |
| *bp++ = 0x0A; |
| *bp++ = 1; |
| *bp++ = 0; |
| *bp++ = 0; |
| *bp++ = 10; |
| *bp++ = 0; |
| *bp++ = 128; |
| |
| *bp++ = (dsc->version & 0xff); /* pps0 */ |
| *bp++ = (pps_id & 0xff); /* pps1 */ |
| bp++; /* pps2, reserved */ |
| |
| data = dsc->line_buf_depth & 0x0f; |
| data |= ((dsc->bpc & 0xf) << 4); |
| *bp++ = data; /* pps3 */ |
| |
| bpp = dsc->bpp; |
| bpp <<= 4; /* 4 fraction bits */ |
| data = (bpp >> 8); |
| data &= 0x03; /* upper two bits */ |
| data |= ((dsc->block_pred_enable & 0x1) << 5); |
| data |= ((dsc->convert_rgb & 0x1) << 4); |
| data |= ((dsc->enable_422 & 0x1) << 3); |
| data |= ((dsc->vbr_enable & 0x1) << 2); |
| *bp++ = data; /* pps4 */ |
| *bp++ = (bpp & 0xff); /* pps5 */ |
| |
| *bp++ = ((dsc->pic_height >> 8) & 0xff); /* pps6 */ |
| *bp++ = (dsc->pic_height & 0x0ff); /* pps7 */ |
| *bp++ = ((dsc->pic_width >> 8) & 0xff); /* pps8 */ |
| *bp++ = (dsc->pic_width & 0x0ff); /* pps9 */ |
| |
| *bp++ = ((dsc->slice_height >> 8) & 0xff);/* pps10 */ |
| *bp++ = (dsc->slice_height & 0x0ff); /* pps11 */ |
| *bp++ = ((dsc->slice_width >> 8) & 0xff); /* pps12 */ |
| *bp++ = (dsc->slice_width & 0x0ff); /* pps13 */ |
| |
| *bp++ = ((dsc->chunk_size >> 8) & 0xff);/* pps14 */ |
| *bp++ = (dsc->chunk_size & 0x0ff); /* pps15 */ |
| |
| *bp++ = (dsc->initial_xmit_delay >> 8) & 0x3; /* pps16, bit 0, 1 */ |
| *bp++ = (dsc->initial_xmit_delay & 0xff);/* pps17 */ |
| |
| *bp++ = ((dsc->initial_dec_delay >> 8) & 0xff); /* pps18 */ |
| *bp++ = (dsc->initial_dec_delay & 0xff);/* pps19 */ |
| |
| bp++; /* pps20, reserved */ |
| |
| *bp++ = (dsc->initial_scale_value & 0x3f); /* pps21 */ |
| |
| *bp++ = ((dsc->scale_increment_interval >> 8) & 0xff); /* pps22 */ |
| *bp++ = (dsc->scale_increment_interval & 0xff); /* pps23 */ |
| |
| *bp++ = ((dsc->scale_decrement_interval >> 8) & 0xf); /* pps24 */ |
| *bp++ = (dsc->scale_decrement_interval & 0x0ff);/* pps25 */ |
| |
| bp++; /* pps26, reserved */ |
| |
| *bp++ = (dsc->first_line_bpg_offset & 0x1f);/* pps27 */ |
| |
| *bp++ = ((dsc->nfl_bpg_offset >> 8) & 0xff);/* pps28 */ |
| *bp++ = (dsc->nfl_bpg_offset & 0x0ff); /* pps29 */ |
| *bp++ = ((dsc->slice_bpg_offset >> 8) & 0xff);/* pps30 */ |
| *bp++ = (dsc->slice_bpg_offset & 0x0ff);/* pps31 */ |
| |
| *bp++ = ((dsc->initial_offset >> 8) & 0xff);/* pps32 */ |
| *bp++ = (dsc->initial_offset & 0x0ff); /* pps33 */ |
| |
| *bp++ = ((dsc->final_offset >> 8) & 0xff);/* pps34 */ |
| *bp++ = (dsc->final_offset & 0x0ff); /* pps35 */ |
| |
| *bp++ = (dsc->min_qp_flatness & 0x1f); /* pps36 */ |
| *bp++ = (dsc->max_qp_flatness & 0x1f); /* pps37 */ |
| |
| *bp++ = ((dsc->rc_model_size >> 8) & 0xff);/* pps38 */ |
| *bp++ = (dsc->rc_model_size & 0x0ff); /* pps39 */ |
| |
| *bp++ = (dsc->edge_factor & 0x0f); /* pps40 */ |
| |
| *bp++ = (dsc->quant_incr_limit0 & 0x1f); /* pps41 */ |
| *bp++ = (dsc->quant_incr_limit1 & 0x1f); /* pps42 */ |
| |
| data = ((dsc->tgt_offset_hi & 0xf) << 4); |
| data |= (dsc->tgt_offset_lo & 0x0f); |
| *bp++ = data; /* pps43 */ |
| |
| for (i = 0; i < 14; i++) |
| *bp++ = (dsc->buf_thresh[i] & 0xff); /* pps44 - pps57 */ |
| |
| for (i = 0; i < 15; i++) { /* pps58 - pps87 */ |
| data = (dsc->range_min_qp[i] & 0x1f); |
| data <<= 3; |
| data |= ((dsc->range_max_qp[i] >> 2) & 0x07); |
| *bp++ = data; |
| data = (dsc->range_max_qp[i] & 0x03); |
| data <<= 6; |
| data |= (dsc->range_bpg_offset[i] & 0x3f); |
| *bp++ = data; |
| } |
| |
| return 128; |
| } |
| |
| static int dsi_panel_vreg_get(struct dsi_panel *panel) |
| { |
| int rc = 0; |
| int i; |
| struct regulator *vreg = NULL; |
| |
| for (i = 0; i < panel->power_info.count; i++) { |
| vreg = devm_regulator_get(panel->parent, |
| panel->power_info.vregs[i].vreg_name); |
| rc = PTR_RET(vreg); |
| if (rc) { |
| pr_err("failed to get %s regulator\n", |
| panel->power_info.vregs[i].vreg_name); |
| goto error_put; |
| } |
| panel->power_info.vregs[i].vreg = vreg; |
| } |
| |
| return rc; |
| error_put: |
| for (i = i - 1; i >= 0; i--) { |
| devm_regulator_put(panel->power_info.vregs[i].vreg); |
| panel->power_info.vregs[i].vreg = NULL; |
| } |
| return rc; |
| } |
| |
| static int dsi_panel_vreg_put(struct dsi_panel *panel) |
| { |
| int rc = 0; |
| int i; |
| |
| for (i = panel->power_info.count - 1; i >= 0; i--) |
| devm_regulator_put(panel->power_info.vregs[i].vreg); |
| |
| return rc; |
| } |
| |
| static int dsi_panel_gpio_request(struct dsi_panel *panel) |
| { |
| int rc = 0; |
| struct dsi_panel_reset_config *r_config = &panel->reset_config; |
| |
| if (gpio_is_valid(r_config->reset_gpio)) { |
| rc = gpio_request(r_config->reset_gpio, "reset_gpio"); |
| if (rc) { |
| pr_err("request for reset_gpio failed, rc=%d\n", rc); |
| goto error; |
| } |
| } |
| |
| if (gpio_is_valid(r_config->disp_en_gpio)) { |
| rc = gpio_request(r_config->disp_en_gpio, "disp_en_gpio"); |
| if (rc) { |
| pr_err("request for disp_en_gpio failed, rc=%d\n", rc); |
| goto error_release_reset; |
| } |
| } |
| |
| if (gpio_is_valid(panel->bl_config.en_gpio)) { |
| rc = gpio_request(panel->bl_config.en_gpio, "bklt_en_gpio"); |
| if (rc) { |
| pr_err("request for bklt_en_gpio failed, rc=%d\n", rc); |
| goto error_release_disp_en; |
| } |
| } |
| |
| if (gpio_is_valid(r_config->lcd_mode_sel_gpio)) { |
| rc = gpio_request(r_config->lcd_mode_sel_gpio, "mode_gpio"); |
| if (rc) { |
| pr_err("request for mode_gpio failed, rc=%d\n", rc); |
| goto error_release_mode_sel; |
| } |
| } |
| |
| goto error; |
| error_release_mode_sel: |
| if (gpio_is_valid(panel->bl_config.en_gpio)) |
| gpio_free(panel->bl_config.en_gpio); |
| error_release_disp_en: |
| if (gpio_is_valid(r_config->disp_en_gpio)) |
| gpio_free(r_config->disp_en_gpio); |
| error_release_reset: |
| if (gpio_is_valid(r_config->reset_gpio)) |
| gpio_free(r_config->reset_gpio); |
| error: |
| return rc; |
| } |
| |
| static int dsi_panel_gpio_release(struct dsi_panel *panel) |
| { |
| int rc = 0; |
| struct dsi_panel_reset_config *r_config = &panel->reset_config; |
| |
| if (gpio_is_valid(r_config->reset_gpio)) |
| gpio_free(r_config->reset_gpio); |
| |
| if (gpio_is_valid(r_config->disp_en_gpio)) |
| gpio_free(r_config->disp_en_gpio); |
| |
| if (gpio_is_valid(panel->bl_config.en_gpio)) |
| gpio_free(panel->bl_config.en_gpio); |
| |
| if (gpio_is_valid(panel->reset_config.lcd_mode_sel_gpio)) |
| gpio_free(panel->reset_config.lcd_mode_sel_gpio); |
| |
| return rc; |
| } |
| |
| static int dsi_panel_reset(struct dsi_panel *panel) |
| { |
| int rc = 0; |
| struct dsi_panel_reset_config *r_config = &panel->reset_config; |
| int i; |
| |
| if (gpio_is_valid(panel->reset_config.disp_en_gpio)) { |
| rc = gpio_direction_output(panel->reset_config.disp_en_gpio, 1); |
| if (rc) { |
| pr_err("unable to set dir for disp gpio rc=%d\n", rc); |
| goto exit; |
| } |
| } |
| |
| if (r_config->count) { |
| rc = gpio_direction_output(r_config->reset_gpio, |
| r_config->sequence[0].level); |
| if (rc) { |
| pr_err("unable to set dir for rst gpio rc=%d\n", rc); |
| goto exit; |
| } |
| } |
| |
| for (i = 0; i < r_config->count; i++) { |
| gpio_set_value(r_config->reset_gpio, |
| r_config->sequence[i].level); |
| |
| |
| if (r_config->sequence[i].sleep_ms) |
| usleep_range(r_config->sequence[i].sleep_ms * 1000, |
| r_config->sequence[i].sleep_ms * 1000); |
| } |
| |
| if (gpio_is_valid(panel->bl_config.en_gpio)) { |
| rc = gpio_direction_output(panel->bl_config.en_gpio, 1); |
| if (rc) |
| pr_err("unable to set dir for bklt gpio rc=%d\n", rc); |
| } |
| |
| if (gpio_is_valid(panel->reset_config.lcd_mode_sel_gpio)) { |
| bool out = true; |
| |
| if ((panel->reset_config.mode_sel_state == MODE_SEL_DUAL_PORT) |
| || (panel->reset_config.mode_sel_state |
| == MODE_GPIO_LOW)) |
| out = false; |
| else if ((panel->reset_config.mode_sel_state |
| == MODE_SEL_SINGLE_PORT) || |
| (panel->reset_config.mode_sel_state |
| == MODE_GPIO_HIGH)) |
| out = true; |
| |
| rc = gpio_direction_output( |
| panel->reset_config.lcd_mode_sel_gpio, out); |
| if (rc) |
| pr_err("unable to set dir for mode gpio rc=%d\n", rc); |
| } |
| exit: |
| return rc; |
| } |
| |
| static int dsi_panel_set_pinctrl_state(struct dsi_panel *panel, bool enable) |
| { |
| int rc = 0; |
| struct pinctrl_state *state; |
| |
| if (enable) |
| state = panel->pinctrl.active; |
| else |
| state = panel->pinctrl.suspend; |
| |
| rc = pinctrl_select_state(panel->pinctrl.pinctrl, state); |
| if (rc) |
| pr_err("[%s] failed to set pin state, rc=%d\n", panel->name, |
| rc); |
| |
| return rc; |
| } |
| |
| |
| static int dsi_panel_power_on(struct dsi_panel *panel) |
| { |
| int rc = 0; |
| |
| rc = dsi_pwr_enable_regulator(&panel->power_info, true); |
| if (rc) { |
| pr_err("[%s] failed to enable vregs, rc=%d\n", panel->name, rc); |
| goto exit; |
| } |
| |
| rc = dsi_panel_set_pinctrl_state(panel, true); |
| if (rc) { |
| pr_err("[%s] failed to set pinctrl, rc=%d\n", panel->name, rc); |
| goto error_disable_vregs; |
| } |
| |
| rc = dsi_panel_reset(panel); |
| if (rc) { |
| pr_err("[%s] failed to reset panel, rc=%d\n", panel->name, rc); |
| goto error_disable_gpio; |
| } |
| |
| goto exit; |
| |
| error_disable_gpio: |
| if (gpio_is_valid(panel->reset_config.disp_en_gpio)) |
| gpio_set_value(panel->reset_config.disp_en_gpio, 0); |
| |
| if (gpio_is_valid(panel->bl_config.en_gpio)) |
| gpio_set_value(panel->bl_config.en_gpio, 0); |
| |
| (void)dsi_panel_set_pinctrl_state(panel, false); |
| |
| error_disable_vregs: |
| (void)dsi_pwr_enable_regulator(&panel->power_info, false); |
| |
| exit: |
| return rc; |
| } |
| |
| static int dsi_panel_power_off(struct dsi_panel *panel) |
| { |
| int rc = 0; |
| |
| if (gpio_is_valid(panel->reset_config.disp_en_gpio)) |
| gpio_set_value(panel->reset_config.disp_en_gpio, 0); |
| |
| if (gpio_is_valid(panel->reset_config.reset_gpio)) |
| gpio_set_value(panel->reset_config.reset_gpio, 0); |
| |
| if (gpio_is_valid(panel->reset_config.lcd_mode_sel_gpio)) |
| gpio_set_value(panel->reset_config.lcd_mode_sel_gpio, 0); |
| |
| rc = dsi_panel_set_pinctrl_state(panel, false); |
| if (rc) { |
| pr_err("[%s] failed set pinctrl state, rc=%d\n", panel->name, |
| rc); |
| } |
| |
| rc = dsi_pwr_enable_regulator(&panel->power_info, false); |
| if (rc) |
| pr_err("[%s] failed to enable vregs, rc=%d\n", panel->name, rc); |
| |
| return rc; |
| } |
| static int dsi_panel_tx_cmd_set(struct dsi_panel *panel, |
| enum dsi_cmd_set_type type) |
| { |
| int rc = 0, i = 0; |
| ssize_t len; |
| struct dsi_cmd_desc *cmds = panel->cmd_sets[type].cmds; |
| u32 count = panel->cmd_sets[type].count; |
| enum dsi_cmd_set_state state = panel->cmd_sets[type].state; |
| const struct mipi_dsi_host_ops *ops = panel->host->ops; |
| |
| if (count == 0) { |
| pr_debug("[%s] No commands to be sent for state(%d)\n", |
| panel->name, type); |
| goto error; |
| } |
| |
| for (i = 0; i < count; i++) { |
| /* TODO: handle last command */ |
| if (state == DSI_CMD_SET_STATE_LP) |
| cmds->msg.flags |= MIPI_DSI_MSG_USE_LPM; |
| |
| len = ops->transfer(panel->host, &cmds->msg); |
| if (len < 0) { |
| rc = len; |
| pr_err("failed to set cmds(%d), rc=%d\n", type, rc); |
| goto error; |
| } |
| if (cmds->post_wait_ms) |
| msleep(cmds->post_wait_ms); |
| cmds++; |
| } |
| error: |
| return rc; |
| } |
| |
| static int dsi_panel_pinctrl_deinit(struct dsi_panel *panel) |
| { |
| int rc = 0; |
| |
| devm_pinctrl_put(panel->pinctrl.pinctrl); |
| |
| return rc; |
| } |
| |
| static int dsi_panel_pinctrl_init(struct dsi_panel *panel) |
| { |
| int rc = 0; |
| |
| /* TODO: pinctrl is defined in dsi dt node */ |
| panel->pinctrl.pinctrl = devm_pinctrl_get(panel->parent); |
| if (IS_ERR_OR_NULL(panel->pinctrl.pinctrl)) { |
| rc = PTR_ERR(panel->pinctrl.pinctrl); |
| pr_err("failed to get pinctrl, rc=%d\n", rc); |
| goto error; |
| } |
| |
| panel->pinctrl.active = pinctrl_lookup_state(panel->pinctrl.pinctrl, |
| "panel_active"); |
| if (IS_ERR_OR_NULL(panel->pinctrl.active)) { |
| rc = PTR_ERR(panel->pinctrl.active); |
| pr_err("failed to get pinctrl active state, rc=%d\n", rc); |
| goto error; |
| } |
| |
| panel->pinctrl.suspend = |
| pinctrl_lookup_state(panel->pinctrl.pinctrl, "panel_suspend"); |
| |
| if (IS_ERR_OR_NULL(panel->pinctrl.suspend)) { |
| rc = PTR_ERR(panel->pinctrl.suspend); |
| pr_err("failed to get pinctrl suspend state, rc=%d\n", rc); |
| goto error; |
| } |
| |
| error: |
| return rc; |
| } |
| |
| #ifdef CONFIG_LEDS_TRIGGERS |
| static int dsi_panel_led_bl_register(struct dsi_panel *panel, |
| struct dsi_backlight_config *bl) |
| { |
| int rc = 0; |
| |
| led_trigger_register_simple("bkl-trigger", &bl->wled); |
| |
| /* LED APIs don't tell us directly whether a classdev has yet |
| * been registered to service this trigger. Until classdev is |
| * registered, calling led_trigger has no effect, and doesn't |
| * fail. Classdevs are associated with any registered triggers |
| * when they do register, but that is too late for FBCon. |
| * Check the cdev list directly and defer if appropriate. |
| */ |
| if (!bl->wled) { |
| pr_err("[%s] backlight registration failed\n", panel->name); |
| rc = -EINVAL; |
| } else { |
| read_lock(&bl->wled->leddev_list_lock); |
| if (list_empty(&bl->wled->led_cdevs)) |
| rc = -EPROBE_DEFER; |
| read_unlock(&bl->wled->leddev_list_lock); |
| |
| if (rc) { |
| pr_info("[%s] backlight %s not ready, defer probe\n", |
| panel->name, bl->wled->name); |
| led_trigger_unregister_simple(bl->wled); |
| } |
| } |
| |
| return rc; |
| } |
| #else |
| static int dsi_panel_led_bl_register(struct dsi_panel *panel, |
| struct dsi_backlight_config *bl) |
| { |
| return 0; |
| } |
| #endif |
| |
| int dsi_panel_set_backlight(struct dsi_panel *panel, u32 bl_lvl) |
| { |
| int rc = 0; |
| struct dsi_backlight_config *bl = &panel->bl_config; |
| |
| switch (bl->type) { |
| case DSI_BACKLIGHT_WLED: |
| led_trigger_event(bl->wled, bl_lvl); |
| break; |
| default: |
| pr_err("Backlight type(%d) not supported\n", bl->type); |
| rc = -ENOTSUPP; |
| } |
| |
| return rc; |
| } |
| |
| static int dsi_panel_bl_register(struct dsi_panel *panel) |
| { |
| int rc = 0; |
| struct dsi_backlight_config *bl = &panel->bl_config; |
| |
| switch (bl->type) { |
| case DSI_BACKLIGHT_WLED: |
| rc = dsi_panel_led_bl_register(panel, bl); |
| break; |
| default: |
| pr_err("Backlight type(%d) not supported\n", bl->type); |
| rc = -ENOTSUPP; |
| goto error; |
| } |
| |
| error: |
| return rc; |
| } |
| |
| static int dsi_panel_bl_unregister(struct dsi_panel *panel) |
| { |
| int rc = 0; |
| struct dsi_backlight_config *bl = &panel->bl_config; |
| |
| switch (bl->type) { |
| case DSI_BACKLIGHT_WLED: |
| led_trigger_unregister_simple(bl->wled); |
| break; |
| default: |
| pr_err("Backlight type(%d) not supported\n", bl->type); |
| rc = -ENOTSUPP; |
| goto error; |
| } |
| |
| error: |
| return rc; |
| } |
| static int dsi_panel_parse_timing(struct dsi_mode_info *mode, |
| struct device_node *of_node) |
| { |
| int rc = 0; |
| |
| rc = of_property_read_u32(of_node, "qcom,mdss-dsi-panel-framerate", |
| &mode->refresh_rate); |
| if (rc) { |
| pr_err("failed to read qcom,mdss-dsi-panel-framerate, rc=%d\n", |
| rc); |
| goto error; |
| } |
| |
| rc = of_property_read_u32(of_node, "qcom,mdss-dsi-panel-width", |
| &mode->h_active); |
| if (rc) { |
| pr_err("failed to read qcom,mdss-dsi-panel-width, rc=%d\n", rc); |
| goto error; |
| } |
| |
| rc = of_property_read_u32(of_node, "qcom,mdss-dsi-h-front-porch", |
| &mode->h_front_porch); |
| if (rc) { |
| pr_err("failed to read qcom,mdss-dsi-h-front-porch, rc=%d\n", |
| rc); |
| goto error; |
| } |
| |
| rc = of_property_read_u32(of_node, "qcom,mdss-dsi-h-back-porch", |
| &mode->h_back_porch); |
| if (rc) { |
| pr_err("failed to read qcom,mdss-dsi-h-back-porch, rc=%d\n", |
| rc); |
| goto error; |
| } |
| |
| rc = of_property_read_u32(of_node, "qcom,mdss-dsi-h-pulse-width", |
| &mode->h_sync_width); |
| if (rc) { |
| pr_err("failed to read qcom,mdss-dsi-h-pulse-width, rc=%d\n", |
| rc); |
| goto error; |
| } |
| |
| rc = of_property_read_u32(of_node, "qcom,mdss-dsi-h-sync-skew", |
| &mode->h_skew); |
| if (rc) |
| pr_err("qcom,mdss-dsi-h-sync-skew is not defined, rc=%d\n", rc); |
| |
| rc = of_property_read_u32(of_node, "qcom,mdss-dsi-panel-height", |
| &mode->v_active); |
| if (rc) { |
| pr_err("failed to read qcom,mdss-dsi-panel-height, rc=%d\n", |
| rc); |
| goto error; |
| } |
| |
| rc = of_property_read_u32(of_node, "qcom,mdss-dsi-v-back-porch", |
| &mode->v_back_porch); |
| if (rc) { |
| pr_err("failed to read qcom,mdss-dsi-v-back-porch, rc=%d\n", |
| rc); |
| goto error; |
| } |
| |
| rc = of_property_read_u32(of_node, "qcom,mdss-dsi-v-front-porch", |
| &mode->v_front_porch); |
| if (rc) { |
| pr_err("failed to read qcom,mdss-dsi-v-back-porch, rc=%d\n", |
| rc); |
| goto error; |
| } |
| |
| rc = of_property_read_u32(of_node, "qcom,mdss-dsi-v-pulse-width", |
| &mode->v_sync_width); |
| if (rc) { |
| pr_err("failed to read qcom,mdss-dsi-v-pulse-width, rc=%d\n", |
| rc); |
| goto error; |
| } |
| |
| error: |
| return rc; |
| } |
| |
| static int dsi_panel_parse_pixel_format(struct dsi_host_common_cfg *host, |
| struct device_node *of_node, |
| const char *name) |
| { |
| int rc = 0; |
| u32 bpp = 0; |
| enum dsi_pixel_format fmt; |
| const char *packing; |
| |
| rc = of_property_read_u32(of_node, "qcom,mdss-dsi-bpp", &bpp); |
| if (rc) { |
| pr_err("[%s] failed to read qcom,mdss-dsi-bpp, rc=%d\n", |
| name, rc); |
| return rc; |
| } |
| |
| switch (bpp) { |
| case 3: |
| fmt = DSI_PIXEL_FORMAT_RGB111; |
| break; |
| case 8: |
| fmt = DSI_PIXEL_FORMAT_RGB332; |
| break; |
| case 12: |
| fmt = DSI_PIXEL_FORMAT_RGB444; |
| break; |
| case 16: |
| fmt = DSI_PIXEL_FORMAT_RGB565; |
| break; |
| case 18: |
| fmt = DSI_PIXEL_FORMAT_RGB666; |
| break; |
| case 24: |
| default: |
| fmt = DSI_PIXEL_FORMAT_RGB888; |
| break; |
| } |
| |
| if (fmt == DSI_PIXEL_FORMAT_RGB666) { |
| packing = of_get_property(of_node, |
| "qcom,mdss-dsi-pixel-packing", |
| NULL); |
| if (packing && !strcmp(packing, "loose")) |
| fmt = DSI_PIXEL_FORMAT_RGB666_LOOSE; |
| } |
| |
| host->dst_format = fmt; |
| return rc; |
| } |
| |
| static int dsi_panel_parse_lane_states(struct dsi_host_common_cfg *host, |
| struct device_node *of_node, |
| const char *name) |
| { |
| int rc = 0; |
| bool lane_enabled; |
| |
| lane_enabled = of_property_read_bool(of_node, |
| "qcom,mdss-dsi-lane-0-state"); |
| host->data_lanes |= (lane_enabled ? DSI_DATA_LANE_0 : 0); |
| |
| lane_enabled = of_property_read_bool(of_node, |
| "qcom,mdss-dsi-lane-1-state"); |
| host->data_lanes |= (lane_enabled ? DSI_DATA_LANE_1 : 0); |
| |
| lane_enabled = of_property_read_bool(of_node, |
| "qcom,mdss-dsi-lane-2-state"); |
| host->data_lanes |= (lane_enabled ? DSI_DATA_LANE_2 : 0); |
| |
| lane_enabled = of_property_read_bool(of_node, |
| "qcom,mdss-dsi-lane-3-state"); |
| host->data_lanes |= (lane_enabled ? DSI_DATA_LANE_3 : 0); |
| |
| if (host->data_lanes == 0) { |
| pr_err("[%s] No data lanes are enabled, rc=%d\n", name, rc); |
| rc = -EINVAL; |
| } |
| |
| return rc; |
| } |
| |
| static int dsi_panel_parse_color_swap(struct dsi_host_common_cfg *host, |
| struct device_node *of_node, |
| const char *name) |
| { |
| int rc = 0; |
| const char *swap_mode; |
| |
| swap_mode = of_get_property(of_node, "qcom,mdss-dsi-color-order", NULL); |
| if (swap_mode) { |
| if (!strcmp(swap_mode, "rgb_swap_rgb")) { |
| host->swap_mode = DSI_COLOR_SWAP_RGB; |
| } else if (!strcmp(swap_mode, "rgb_swap_rbg")) { |
| host->swap_mode = DSI_COLOR_SWAP_RBG; |
| } else if (!strcmp(swap_mode, "rgb_swap_brg")) { |
| host->swap_mode = DSI_COLOR_SWAP_BRG; |
| } else if (!strcmp(swap_mode, "rgb_swap_grb")) { |
| host->swap_mode = DSI_COLOR_SWAP_GRB; |
| } else if (!strcmp(swap_mode, "rgb_swap_gbr")) { |
| host->swap_mode = DSI_COLOR_SWAP_GBR; |
| } else { |
| pr_err("[%s] Unrecognized color order-%s\n", |
| name, swap_mode); |
| rc = -EINVAL; |
| } |
| } else { |
| pr_debug("[%s] Falling back to default color order\n", name); |
| host->swap_mode = DSI_COLOR_SWAP_RGB; |
| } |
| |
| /* bit swap on color channel is not defined in dt */ |
| host->bit_swap_red = false; |
| host->bit_swap_green = false; |
| host->bit_swap_blue = false; |
| return rc; |
| } |
| |
| static int dsi_panel_parse_triggers(struct dsi_host_common_cfg *host, |
| struct device_node *of_node, |
| const char *name) |
| { |
| const char *trig; |
| int rc = 0; |
| |
| trig = of_get_property(of_node, "qcom,mdss-dsi-mdp-trigger", NULL); |
| if (trig) { |
| if (!strcmp(trig, "none")) { |
| host->mdp_cmd_trigger = DSI_TRIGGER_NONE; |
| } else if (!strcmp(trig, "trigger_te")) { |
| host->mdp_cmd_trigger = DSI_TRIGGER_TE; |
| } else if (!strcmp(trig, "trigger_sw")) { |
| host->mdp_cmd_trigger = DSI_TRIGGER_SW; |
| } else if (!strcmp(trig, "trigger_sw_te")) { |
| host->mdp_cmd_trigger = DSI_TRIGGER_SW_TE; |
| } else { |
| pr_err("[%s] Unrecognized mdp trigger type (%s)\n", |
| name, trig); |
| rc = -EINVAL; |
| } |
| |
| } else { |
| pr_debug("[%s] Falling back to default MDP trigger\n", |
| name); |
| host->mdp_cmd_trigger = DSI_TRIGGER_SW; |
| } |
| |
| trig = of_get_property(of_node, "qcom,mdss-dsi-dma-trigger", NULL); |
| if (trig) { |
| if (!strcmp(trig, "none")) { |
| host->dma_cmd_trigger = DSI_TRIGGER_NONE; |
| } else if (!strcmp(trig, "trigger_te")) { |
| host->dma_cmd_trigger = DSI_TRIGGER_TE; |
| } else if (!strcmp(trig, "trigger_sw")) { |
| host->dma_cmd_trigger = DSI_TRIGGER_SW; |
| } else if (!strcmp(trig, "trigger_sw_seof")) { |
| host->dma_cmd_trigger = DSI_TRIGGER_SW_SEOF; |
| } else if (!strcmp(trig, "trigger_sw_te")) { |
| host->dma_cmd_trigger = DSI_TRIGGER_SW_TE; |
| } else { |
| pr_err("[%s] Unrecognized mdp trigger type (%s)\n", |
| name, trig); |
| rc = -EINVAL; |
| } |
| |
| } else { |
| pr_debug("[%s] Falling back to default MDP trigger\n", name); |
| host->dma_cmd_trigger = DSI_TRIGGER_SW; |
| } |
| |
| |
| return rc; |
| } |
| |
| static int dsi_panel_parse_misc_host_config(struct dsi_host_common_cfg *host, |
| struct device_node *of_node, |
| const char *name) |
| { |
| u32 val = 0; |
| int rc = 0; |
| |
| rc = of_property_read_u32(of_node, "qcom,mdss-dsi-t-clk-post", &val); |
| if (rc) { |
| pr_debug("[%s] Fallback to default t_clk_post value\n", name); |
| host->t_clk_post = 0x03; |
| } else { |
| host->t_clk_post = val; |
| pr_debug("[%s] t_clk_post = %d\n", name, val); |
| } |
| |
| val = 0; |
| rc = of_property_read_u32(of_node, "qcom,mdss-dsi-t-clk-pre", &val); |
| if (rc) { |
| pr_debug("[%s] Fallback to default t_clk_pre value\n", name); |
| host->t_clk_pre = 0x24; |
| } else { |
| host->t_clk_pre = val; |
| pr_debug("[%s] t_clk_pre = %d\n", name, val); |
| } |
| |
| host->ignore_rx_eot = of_property_read_bool(of_node, |
| "qcom,mdss-dsi-rx-eot-ignore"); |
| |
| host->append_tx_eot = of_property_read_bool(of_node, |
| "qcom,mdss-dsi-tx-eot-append"); |
| |
| return 0; |
| } |
| |
| static int dsi_panel_parse_host_config(struct dsi_panel *panel, |
| struct device_node *of_node) |
| { |
| int rc = 0; |
| |
| rc = dsi_panel_parse_pixel_format(&panel->host_config, of_node, |
| panel->name); |
| if (rc) { |
| pr_err("[%s] failed to get pixel format, rc=%d\n", |
| panel->name, rc); |
| goto error; |
| } |
| |
| rc = dsi_panel_parse_lane_states(&panel->host_config, of_node, |
| panel->name); |
| if (rc) { |
| pr_err("[%s] failed to parse lane states, rc=%d\n", |
| panel->name, rc); |
| goto error; |
| } |
| |
| rc = dsi_panel_parse_color_swap(&panel->host_config, of_node, |
| panel->name); |
| if (rc) { |
| pr_err("[%s] failed to parse color swap config, rc=%d\n", |
| panel->name, rc); |
| goto error; |
| } |
| |
| rc = dsi_panel_parse_triggers(&panel->host_config, of_node, |
| panel->name); |
| if (rc) { |
| pr_err("[%s] failed to parse triggers, rc=%d\n", |
| panel->name, rc); |
| goto error; |
| } |
| |
| rc = dsi_panel_parse_misc_host_config(&panel->host_config, of_node, |
| panel->name); |
| if (rc) { |
| pr_err("[%s] failed to parse misc host config, rc=%d\n", |
| panel->name, rc); |
| goto error; |
| } |
| |
| error: |
| return rc; |
| } |
| |
| static int dsi_panel_parse_dfps_caps(struct dsi_dfps_capabilities *dfps_caps, |
| struct device_node *of_node, |
| const char *name) |
| { |
| int rc = 0; |
| bool supported = false; |
| const char *type; |
| u32 val = 0; |
| |
| supported = of_property_read_bool(of_node, |
| "qcom,mdss-dsi-pan-enable-dynamic-fps"); |
| |
| if (!supported) { |
| pr_debug("[%s] DFPS is not supported\n", name); |
| dfps_caps->dfps_support = false; |
| } else { |
| |
| type = of_get_property(of_node, |
| "qcom,mdss-dsi-pan-fps-update", |
| NULL); |
| if (!type) { |
| pr_err("[%s] dfps type not defined\n", name); |
| rc = -EINVAL; |
| goto error; |
| } else if (!strcmp(type, "dfps_suspend_resume_mode")) { |
| dfps_caps->type = DSI_DFPS_SUSPEND_RESUME; |
| } else if (!strcmp(type, "dfps_immediate_clk_mode")) { |
| dfps_caps->type = DSI_DFPS_IMMEDIATE_CLK; |
| } else if (!strcmp(type, "dfps_immediate_porch_mode_hfp")) { |
| dfps_caps->type = DSI_DFPS_IMMEDIATE_HFP; |
| } else if (!strcmp(type, "dfps_immediate_porch_mode_vfp")) { |
| dfps_caps->type = DSI_DFPS_IMMEDIATE_VFP; |
| } else { |
| pr_err("[%s] dfps type is not recognized\n", name); |
| rc = -EINVAL; |
| goto error; |
| } |
| |
| rc = of_property_read_u32(of_node, |
| "qcom,mdss-dsi-min-refresh-rate", |
| &val); |
| if (rc) { |
| pr_err("[%s] Min refresh rate is not defined\n", name); |
| rc = -EINVAL; |
| goto error; |
| } |
| dfps_caps->min_refresh_rate = val; |
| |
| rc = of_property_read_u32(of_node, |
| "qcom,mdss-dsi-max-refresh-rate", |
| &val); |
| if (rc) { |
| pr_debug("[%s] Using default refresh rate\n", name); |
| rc = of_property_read_u32(of_node, |
| "qcom,mdss-dsi-panel-framerate", |
| &val); |
| if (rc) { |
| pr_err("[%s] max refresh rate is not defined\n", |
| name); |
| rc = -EINVAL; |
| goto error; |
| } |
| } |
| dfps_caps->max_refresh_rate = val; |
| |
| if (dfps_caps->min_refresh_rate > dfps_caps->max_refresh_rate) { |
| pr_err("[%s] min rate > max rate\n", name); |
| rc = -EINVAL; |
| } |
| |
| pr_debug("[%s] DFPS is supported %d-%d, mode %d\n", name, |
| dfps_caps->min_refresh_rate, |
| dfps_caps->max_refresh_rate, |
| dfps_caps->type); |
| dfps_caps->dfps_support = true; |
| } |
| |
| error: |
| return rc; |
| } |
| |
| static int dsi_panel_parse_video_host_config(struct dsi_video_engine_cfg *cfg, |
| struct device_node *of_node, |
| const char *name) |
| { |
| int rc = 0; |
| const char *traffic_mode; |
| u32 vc_id = 0; |
| u32 val = 0; |
| |
| rc = of_property_read_u32(of_node, "qcom,mdss-dsi-h-sync-pulse", &val); |
| if (rc) { |
| pr_debug("[%s] fallback to default h-sync-pulse\n", name); |
| cfg->pulse_mode_hsa_he = false; |
| } else if (val == 1) { |
| cfg->pulse_mode_hsa_he = true; |
| } else if (val == 0) { |
| cfg->pulse_mode_hsa_he = false; |
| } else { |
| pr_err("[%s] Unrecognized value for mdss-dsi-h-sync-pulse\n", |
| name); |
| rc = -EINVAL; |
| goto error; |
| } |
| |
| cfg->hfp_lp11_en = of_property_read_bool(of_node, |
| "qcom,mdss-dsi-hfp-power-mode"); |
| |
| cfg->hbp_lp11_en = of_property_read_bool(of_node, |
| "qcom,mdss-dsi-hbp-power-mode"); |
| |
| cfg->hsa_lp11_en = of_property_read_bool(of_node, |
| "qcom,mdss-dsi-hsa-power-mode"); |
| |
| cfg->last_line_interleave_en = of_property_read_bool(of_node, |
| "qcom,mdss-dsi-last-line-interleave"); |
| |
| cfg->eof_bllp_lp11_en = of_property_read_bool(of_node, |
| "qcom,mdss-dsi-bllp-eof-power-mode"); |
| |
| cfg->bllp_lp11_en = of_property_read_bool(of_node, |
| "qcom,mdss-dsi-bllp-power-mode"); |
| |
| traffic_mode = of_get_property(of_node, |
| "qcom,mdss-dsi-traffic-mode", |
| NULL); |
| if (!traffic_mode) { |
| pr_debug("[%s] Falling back to default traffic mode\n", name); |
| cfg->traffic_mode = DSI_VIDEO_TRAFFIC_SYNC_PULSES; |
| } else if (!strcmp(traffic_mode, "non_burst_sync_pulse")) { |
| cfg->traffic_mode = DSI_VIDEO_TRAFFIC_SYNC_PULSES; |
| } else if (!strcmp(traffic_mode, "non_burst_sync_event")) { |
| cfg->traffic_mode = DSI_VIDEO_TRAFFIC_SYNC_START_EVENTS; |
| } else if (!strcmp(traffic_mode, "burst_mode")) { |
| cfg->traffic_mode = DSI_VIDEO_TRAFFIC_BURST_MODE; |
| } else { |
| pr_err("[%s] Unrecognized traffic mode-%s\n", name, |
| traffic_mode); |
| rc = -EINVAL; |
| goto error; |
| } |
| |
| rc = of_property_read_u32(of_node, "qcom,mdss-dsi-virtual-channel-id", |
| &vc_id); |
| if (rc) { |
| pr_debug("[%s] Fallback to default vc id\n", name); |
| cfg->vc_id = 0; |
| } else { |
| cfg->vc_id = vc_id; |
| } |
| |
| error: |
| return rc; |
| } |
| |
| static int dsi_panel_parse_cmd_host_config(struct dsi_cmd_engine_cfg *cfg, |
| struct device_node *of_node, |
| const char *name) |
| { |
| u32 val = 0; |
| int rc = 0; |
| |
| rc = of_property_read_u32(of_node, "qcom,mdss-dsi-wr-mem-start", &val); |
| if (rc) { |
| pr_debug("[%s] Fallback to default wr-mem-start\n", name); |
| cfg->wr_mem_start = 0x2C; |
| } else { |
| cfg->wr_mem_start = val; |
| } |
| |
| val = 0; |
| rc = of_property_read_u32(of_node, "qcom,mdss-dsi-wr-mem-continue", |
| &val); |
| if (rc) { |
| pr_debug("[%s] Fallback to default wr-mem-continue\n", name); |
| cfg->wr_mem_continue = 0x3C; |
| } else { |
| cfg->wr_mem_continue = val; |
| } |
| |
| /* TODO: fix following */ |
| cfg->max_cmd_packets_interleave = 0; |
| |
| val = 0; |
| rc = of_property_read_u32(of_node, "qcom,mdss-dsi-te-dcs-command", |
| &val); |
| if (rc) { |
| pr_debug("[%s] fallback to default te-dcs-cmd\n", name); |
| cfg->insert_dcs_command = true; |
| } else if (val == 1) { |
| cfg->insert_dcs_command = true; |
| } else if (val == 0) { |
| cfg->insert_dcs_command = false; |
| } else { |
| pr_err("[%s] Unrecognized value for mdss-dsi-te-dcs-command\n", |
| name); |
| rc = -EINVAL; |
| goto error; |
| } |
| |
| if (of_property_read_u32(of_node, "qcom,mdss-mdp-transfer-time-us", |
| &val)) { |
| pr_debug("[%s] Fallback to default transfer-time-us\n", name); |
| cfg->mdp_transfer_time_us = DEFAULT_MDP_TRANSFER_TIME; |
| } else { |
| cfg->mdp_transfer_time_us = val; |
| } |
| |
| error: |
| return rc; |
| } |
| |
| static int dsi_panel_parse_panel_mode(struct dsi_panel *panel, |
| struct device_node *of_node) |
| { |
| int rc = 0; |
| enum dsi_op_mode panel_mode; |
| const char *mode; |
| |
| mode = of_get_property(of_node, "qcom,mdss-dsi-panel-type", NULL); |
| if (!mode) { |
| pr_debug("[%s] Fallback to default panel mode\n", panel->name); |
| panel_mode = DSI_OP_VIDEO_MODE; |
| } else if (!strcmp(mode, "dsi_video_mode")) { |
| panel_mode = DSI_OP_VIDEO_MODE; |
| } else if (!strcmp(mode, "dsi_cmd_mode")) { |
| panel_mode = DSI_OP_CMD_MODE; |
| } else { |
| pr_err("[%s] Unrecognized panel type-%s\n", panel->name, mode); |
| rc = -EINVAL; |
| goto error; |
| } |
| |
| if (panel_mode == DSI_OP_VIDEO_MODE) { |
| rc = dsi_panel_parse_video_host_config(&panel->video_config, |
| of_node, |
| panel->name); |
| if (rc) { |
| pr_err("[%s] Failed to parse video host cfg, rc=%d\n", |
| panel->name, rc); |
| goto error; |
| } |
| } |
| |
| if (panel_mode == DSI_OP_CMD_MODE) { |
| rc = dsi_panel_parse_cmd_host_config(&panel->cmd_config, |
| of_node, |
| panel->name); |
| if (rc) { |
| pr_err("[%s] Failed to parse cmd host config, rc=%d\n", |
| panel->name, rc); |
| goto error; |
| } |
| } |
| |
| panel->mode.panel_mode = panel_mode; |
| error: |
| return rc; |
| } |
| |
| static int dsi_panel_parse_phy_props(struct dsi_panel_phy_props *props, |
| struct device_node *of_node, |
| const char *name) |
| { |
| int rc = 0; |
| u32 val = 0; |
| const char *str; |
| |
| rc = of_property_read_u32(of_node, |
| "qcom,mdss-pan-physical-width-dimension", |
| &val); |
| if (rc) { |
| pr_debug("[%s] Physical panel width is not defined\n", name); |
| props->panel_width_mm = 0; |
| rc = 0; |
| } else { |
| props->panel_width_mm = val; |
| } |
| |
| rc = of_property_read_u32(of_node, |
| "qcom,mdss-pan-physical-height-dimension", |
| &val); |
| if (rc) { |
| pr_debug("[%s] Physical panel height is not defined\n", name); |
| props->panel_height_mm = 0; |
| rc = 0; |
| } else { |
| props->panel_height_mm = val; |
| } |
| |
| str = of_get_property(of_node, "qcom,mdss-dsi-panel-orientation", NULL); |
| if (!str) { |
| props->rotation = DSI_PANEL_ROTATE_NONE; |
| } else if (!strcmp(str, "180")) { |
| props->rotation = DSI_PANEL_ROTATE_HV_FLIP; |
| } else if (!strcmp(str, "hflip")) { |
| props->rotation = DSI_PANEL_ROTATE_H_FLIP; |
| } else if (!strcmp(str, "vflip")) { |
| props->rotation = DSI_PANEL_ROTATE_V_FLIP; |
| } else { |
| pr_err("[%s] Unrecognized panel rotation-%s\n", name, str); |
| rc = -EINVAL; |
| goto error; |
| } |
| error: |
| return rc; |
| } |
| const char *cmd_set_prop_map[DSI_CMD_SET_MAX] = { |
| "qcom,mdss-dsi-pre-on-command", |
| "qcom,mdss-dsi-on-command", |
| "qcom,mdss-dsi-post-panel-on-command", |
| "qcom,mdss-dsi-pre-off-command", |
| "qcom,mdss-dsi-off-command", |
| "qcom,mdss-dsi-post-off-command", |
| "qcom,mdss-dsi-pre-res-switch", |
| "qcom,mdss-dsi-res-switch", |
| "qcom,mdss-dsi-post-res-switch", |
| "qcom,cmd-to-video-mode-switch-commands", |
| "qcom,cmd-to-video-mode-post-switch-commands", |
| "qcom,video-to-cmd-mode-switch-commands", |
| "qcom,video-to-cmd-mode-post-switch-commands", |
| "qcom,mdss-dsi-panel-status-command", |
| }; |
| |
| const char *cmd_set_state_map[DSI_CMD_SET_MAX] = { |
| "qcom,mdss-dsi-pre-on-command-state", |
| "qcom,mdss-dsi-on-command-state", |
| "qcom,mdss-dsi-post-on-command-state", |
| "qcom,mdss-dsi-pre-off-command-state", |
| "qcom,mdss-dsi-off-command-state", |
| "qcom,mdss-dsi-post-off-command-state", |
| "qcom,mdss-dsi-pre-res-switch-state", |
| "qcom,mdss-dsi-res-switch-state", |
| "qcom,mdss-dsi-post-res-switch-state", |
| "qcom,cmd-to-video-mode-switch-commands-state", |
| "qcom,cmd-to-video-mode-post-switch-commands-state", |
| "qcom,video-to-cmd-mode-switch-commands-state", |
| "qcom,video-to-cmd-mode-post-switch-commands-state", |
| "qcom,mdss-dsi-panel-status-command-state", |
| }; |
| |
| static int dsi_panel_get_cmd_pkt_count(const char *data, u32 length, u32 *cnt) |
| { |
| const u32 cmd_set_min_size = 7; |
| u32 count = 0; |
| u32 packet_length; |
| u32 tmp; |
| |
| while (length >= cmd_set_min_size) { |
| packet_length = cmd_set_min_size; |
| tmp = ((data[5] << 8) | (data[6])); |
| packet_length += tmp; |
| if (packet_length > length) { |
| pr_err("format error\n"); |
| return -EINVAL; |
| } |
| length -= packet_length; |
| data += packet_length; |
| count++; |
| }; |
| |
| *cnt = count; |
| return 0; |
| } |
| |
| static int dsi_panel_create_cmd_packets(const char *data, |
| u32 length, |
| u32 count, |
| struct dsi_cmd_desc *cmd) |
| { |
| int rc = 0; |
| int i, j; |
| u8 *payload; |
| |
| for (i = 0; i < count; i++) { |
| u32 size; |
| |
| cmd[i].msg.type = data[0]; |
| cmd[i].last_command = (data[1] == 1 ? true : false); |
| cmd[i].msg.channel = data[2]; |
| cmd[i].msg.flags |= (data[3] == 1 ? MIPI_DSI_MSG_REQ_ACK : 0); |
| cmd[i].post_wait_ms = data[4]; |
| cmd[i].msg.tx_len = ((data[5] << 8) | (data[6])); |
| |
| size = cmd[i].msg.tx_len * sizeof(u8); |
| |
| payload = kzalloc(size, GFP_KERNEL); |
| if (!payload) { |
| rc = -ENOMEM; |
| goto error_free_payloads; |
| } |
| |
| for (j = 0; j < cmd[i].msg.tx_len; j++) |
| payload[j] = data[7 + j]; |
| |
| cmd[i].msg.tx_buf = payload; |
| data += (7 + cmd[i].msg.tx_len); |
| } |
| |
| return rc; |
| error_free_payloads: |
| for (i = i - 1; i >= 0; i--) { |
| cmd--; |
| kfree(cmd->msg.tx_buf); |
| } |
| |
| return rc; |
| } |
| |
| static void dsi_panel_destroy_cmd_packets(struct dsi_panel_cmd_set *set) |
| { |
| u32 i = 0; |
| struct dsi_cmd_desc *cmd; |
| |
| for (i = 0; i < set->count; i++) { |
| cmd = &set->cmds[i]; |
| kfree(cmd->msg.tx_buf); |
| } |
| |
| kfree(set->cmds); |
| } |
| |
| static int dsi_panel_alloc_cmd_packets(struct dsi_panel_cmd_set *cmd, |
| u32 packet_count) |
| { |
| u32 size; |
| |
| size = packet_count * sizeof(*cmd->cmds); |
| cmd->cmds = kzalloc(size, GFP_KERNEL); |
| if (!cmd->cmds) |
| return -ENOMEM; |
| |
| cmd->count = packet_count; |
| return 0; |
| } |
| |
| static int dsi_panel_parse_cmd_sets_sub(struct dsi_panel_cmd_set *cmd, |
| enum dsi_cmd_set_type type, |
| struct device_node *of_node) |
| { |
| int rc = 0; |
| u32 length = 0; |
| const char *data; |
| const char *state; |
| u32 packet_count = 0; |
| |
| data = of_get_property(of_node, cmd_set_prop_map[type], &length); |
| if (!data) { |
| pr_err("%s commands not defined\n", cmd_set_prop_map[type]); |
| rc = -ENOTSUPP; |
| goto error; |
| } |
| |
| rc = dsi_panel_get_cmd_pkt_count(data, length, &packet_count); |
| if (rc) { |
| pr_err("commands failed, rc=%d\n", rc); |
| goto error; |
| } |
| pr_debug("[%s] packet-count=%d, %d\n", cmd_set_prop_map[type], |
| packet_count, length); |
| |
| rc = dsi_panel_alloc_cmd_packets(cmd, packet_count); |
| if (rc) { |
| pr_err("failed to allocate cmd packets, rc=%d\n", rc); |
| goto error; |
| } |
| |
| rc = dsi_panel_create_cmd_packets(data, length, packet_count, |
| cmd->cmds); |
| if (rc) { |
| pr_err("failed to create cmd packets, rc=%d\n", rc); |
| goto error_free_mem; |
| } |
| |
| state = of_get_property(of_node, cmd_set_state_map[type], NULL); |
| if (!state || !strcmp(state, "dsi_lp_mode")) { |
| cmd->state = DSI_CMD_SET_STATE_LP; |
| } else if (!strcmp(state, "dsi_hs_mode")) { |
| cmd->state = DSI_CMD_SET_STATE_HS; |
| } else { |
| pr_err("[%s] command state unrecognized-%s\n", |
| cmd_set_state_map[type], state); |
| goto error_free_mem; |
| } |
| |
| return rc; |
| error_free_mem: |
| kfree(cmd->cmds); |
| cmd->cmds = NULL; |
| error: |
| return rc; |
| |
| } |
| |
| static int dsi_panel_parse_cmd_sets(struct dsi_panel *panel, |
| struct device_node *of_node) |
| { |
| int rc = 0; |
| struct dsi_panel_cmd_set *set; |
| u32 i; |
| |
| for (i = DSI_CMD_SET_PRE_ON; i < DSI_CMD_SET_MAX; i++) { |
| set = &panel->cmd_sets[i]; |
| set->type = i; |
| if (i == DSI_CMD_SET_PPS) { |
| rc = dsi_panel_alloc_cmd_packets(set, 1); |
| if (rc) |
| pr_err("[%s] failed to allocate cmd set %d, rc = %d\n", |
| panel->name, i, rc); |
| set->state = DSI_CMD_SET_STATE_LP; |
| } else { |
| rc = dsi_panel_parse_cmd_sets_sub(set, i, of_node); |
| if (rc) |
| pr_err("[%s] failed to parse set %d\n", |
| panel->name, i); |
| } |
| } |
| |
| rc = 0; |
| return rc; |
| } |
| |
| static int dsi_panel_parse_reset_sequence(struct dsi_panel *panel, |
| struct device_node *of_node) |
| { |
| int rc = 0; |
| int i; |
| u32 length = 0; |
| u32 count = 0; |
| u32 size = 0; |
| u32 *arr_32 = NULL; |
| const u32 *arr; |
| struct dsi_reset_seq *seq; |
| |
| arr = of_get_property(of_node, "qcom,mdss-dsi-reset-sequence", &length); |
| if (!arr) { |
| pr_err("[%s] dsi-reset-sequence not found\n", panel->name); |
| rc = -EINVAL; |
| goto error; |
| } |
| if (length & 0x1) { |
| pr_err("[%s] syntax error for dsi-reset-sequence\n", |
| panel->name); |
| rc = -EINVAL; |
| goto error; |
| } |
| |
| pr_err("RESET SEQ LENGTH = %d\n", length); |
| length = length / sizeof(u32); |
| |
| size = length * sizeof(u32); |
| |
| arr_32 = kzalloc(size, GFP_KERNEL); |
| if (!arr_32) { |
| rc = -ENOMEM; |
| goto error; |
| } |
| |
| rc = of_property_read_u32_array(of_node, "qcom,mdss-dsi-reset-sequence", |
| arr_32, length); |
| if (rc) { |
| pr_err("[%s] cannot read dso-reset-seqience\n", panel->name); |
| goto error_free_arr_32; |
| } |
| |
| count = length / 2; |
| size = count * sizeof(*seq); |
| seq = kzalloc(size, GFP_KERNEL); |
| if (!seq) { |
| rc = -ENOMEM; |
| goto error_free_arr_32; |
| } |
| |
| panel->reset_config.sequence = seq; |
| panel->reset_config.count = count; |
| |
| for (i = 0; i < length; i += 2) { |
| seq->level = arr_32[i]; |
| seq->sleep_ms = arr_32[i + 1]; |
| seq++; |
| } |
| |
| |
| error_free_arr_32: |
| kfree(arr_32); |
| error: |
| return rc; |
| } |
| |
| static int dsi_panel_parse_jitter_config(struct dsi_panel *panel, |
| struct device_node *of_node) |
| { |
| int rc; |
| |
| rc = of_property_read_u32(of_node, "qcom,mdss-dsi-panel-jitter", |
| &panel->panel_jitter); |
| if (rc) { |
| pr_debug("panel jitter is not defined rc=%d\n", rc); |
| panel->panel_jitter = DEFAULT_PANEL_JITTER; |
| } else if (panel->panel_jitter > MAX_PANEL_JITTER) { |
| pr_debug("invalid jitter config=%d setting to:%d\n", |
| panel->panel_jitter, DEFAULT_PANEL_JITTER); |
| panel->panel_jitter = DEFAULT_PANEL_JITTER; |
| } |
| |
| rc = of_property_read_u32(of_node, "qcom,mdss-dsi-panel-prefill-lines", |
| &panel->panel_prefill_lines); |
| if (rc) { |
| pr_debug("panel prefill lines are not defined rc=%d\n", rc); |
| panel->panel_prefill_lines = DEFAULT_PANEL_PREFILL_LINES; |
| } else if (panel->panel_prefill_lines >= |
| DSI_V_TOTAL(&panel->mode.timing)) { |
| pr_debug("invalid prefill lines config=%d setting to:%d\n", |
| panel->panel_prefill_lines, DEFAULT_PANEL_PREFILL_LINES); |
| panel->panel_prefill_lines = DEFAULT_PANEL_PREFILL_LINES; |
| } |
| |
| return 0; |
| } |
| |
| static int dsi_panel_parse_power_cfg(struct device *parent, |
| struct dsi_panel *panel, |
| struct device_node *of_node) |
| { |
| int rc = 0; |
| |
| rc = dsi_pwr_of_get_vreg_data(of_node, |
| &panel->power_info, |
| "qcom,panel-supply-entries"); |
| if (rc) { |
| pr_err("[%s] failed to parse vregs\n", panel->name); |
| goto error; |
| } |
| |
| error: |
| return rc; |
| } |
| |
| static int dsi_panel_parse_gpios(struct dsi_panel *panel, |
| struct device_node *of_node) |
| { |
| int rc = 0; |
| const char *data; |
| |
| panel->reset_config.reset_gpio = of_get_named_gpio(of_node, |
| "qcom,platform-reset-gpio", |
| 0); |
| if (!gpio_is_valid(panel->reset_config.reset_gpio)) { |
| pr_err("[%s] failed get reset gpio, rc=%d\n", panel->name, rc); |
| rc = -EINVAL; |
| goto error; |
| } |
| |
| panel->reset_config.disp_en_gpio = of_get_named_gpio(of_node, |
| "qcom,5v-boost-gpio", |
| 0); |
| if (!gpio_is_valid(panel->reset_config.disp_en_gpio)) { |
| pr_debug("[%s] 5v-boot-gpio is not set, rc=%d\n", |
| panel->name, rc); |
| panel->reset_config.disp_en_gpio = of_get_named_gpio(of_node, |
| "qcom,platform-en-gpio", |
| 0); |
| if (!gpio_is_valid(panel->reset_config.disp_en_gpio)) { |
| pr_debug("[%s] platform-en-gpio is not set, rc=%d\n", |
| panel->name, rc); |
| } |
| } |
| |
| panel->reset_config.lcd_mode_sel_gpio = of_get_named_gpio(of_node, |
| "qcom,panel-mode-gpio", 0); |
| if (!gpio_is_valid(panel->reset_config.lcd_mode_sel_gpio)) |
| pr_debug("%s:%d mode gpio not specified\n", __func__, __LINE__); |
| |
| data = of_get_property(of_node, |
| "qcom,mdss-dsi-mode-sel-gpio-state", NULL); |
| if (data) { |
| if (!strcmp(data, "single_port")) |
| panel->reset_config.mode_sel_state = |
| MODE_SEL_SINGLE_PORT; |
| else if (!strcmp(data, "dual_port")) |
| panel->reset_config.mode_sel_state = |
| MODE_SEL_DUAL_PORT; |
| else if (!strcmp(data, "high")) |
| panel->reset_config.mode_sel_state = |
| MODE_GPIO_HIGH; |
| else if (!strcmp(data, "low")) |
| panel->reset_config.mode_sel_state = |
| MODE_GPIO_LOW; |
| } else { |
| /* Set default mode as SPLIT mode */ |
| panel->reset_config.mode_sel_state = MODE_SEL_DUAL_PORT; |
| } |
| |
| /* TODO: release memory */ |
| rc = dsi_panel_parse_reset_sequence(panel, of_node); |
| if (rc) { |
| pr_err("[%s] failed to parse reset sequence, rc=%d\n", |
| panel->name, rc); |
| goto error; |
| } |
| |
| error: |
| return rc; |
| } |
| |
| static int dsi_panel_parse_bl_pwm_config(struct dsi_backlight_config *config, |
| struct device_node *of_node) |
| { |
| int rc = 0; |
| u32 val; |
| |
| rc = of_property_read_u32(of_node, "qcom,dsi-bl-pmic-bank-select", |
| &val); |
| if (rc) { |
| pr_err("bl-pmic-bank-select is not defined, rc=%d\n", rc); |
| goto error; |
| } |
| config->pwm_pmic_bank = val; |
| |
| rc = of_property_read_u32(of_node, "qcom,dsi-bl-pmic-pwm-frequency", |
| &val); |
| if (rc) { |
| pr_err("bl-pmic-bank-select is not defined, rc=%d\n", rc); |
| goto error; |
| } |
| config->pwm_period_usecs = val; |
| |
| config->pwm_pmi_control = of_property_read_bool(of_node, |
| "qcom,mdss-dsi-bl-pwm-pmi"); |
| |
| config->pwm_gpio = of_get_named_gpio(of_node, |
| "qcom,mdss-dsi-pwm-gpio", |
| 0); |
| if (!gpio_is_valid(config->pwm_gpio)) { |
| pr_err("pwm gpio is invalid\n"); |
| rc = -EINVAL; |
| goto error; |
| } |
| |
| error: |
| return rc; |
| } |
| |
| static int dsi_panel_parse_bl_config(struct dsi_panel *panel, |
| struct device_node *of_node) |
| { |
| int rc = 0; |
| const char *bl_type; |
| u32 val = 0; |
| |
| bl_type = of_get_property(of_node, |
| "qcom,mdss-dsi-bl-pmic-control-type", |
| NULL); |
| if (!bl_type) { |
| panel->bl_config.type = DSI_BACKLIGHT_UNKNOWN; |
| } else if (!strcmp(bl_type, "bl_ctrl_pwm")) { |
| panel->bl_config.type = DSI_BACKLIGHT_PWM; |
| } else if (!strcmp(bl_type, "bl_ctrl_wled")) { |
| panel->bl_config.type = DSI_BACKLIGHT_WLED; |
| } else if (!strcmp(bl_type, "bl_ctrl_dcs")) { |
| panel->bl_config.type = DSI_BACKLIGHT_DCS; |
| } else { |
| pr_debug("[%s] bl-pmic-control-type unknown-%s\n", |
| panel->name, bl_type); |
| panel->bl_config.type = DSI_BACKLIGHT_UNKNOWN; |
| } |
| |
| rc = of_property_read_u32(of_node, "qcom,mdss-dsi-bl-min-level", &val); |
| if (rc) { |
| pr_debug("[%s] bl-min-level unspecified, defaulting to zero\n", |
| panel->name); |
| panel->bl_config.bl_min_level = 0; |
| } else { |
| panel->bl_config.bl_min_level = val; |
| } |
| |
| rc = of_property_read_u32(of_node, "qcom,mdss-dsi-bl-max-level", &val); |
| if (rc) { |
| pr_debug("[%s] bl-max-level unspecified, defaulting to max level\n", |
| panel->name); |
| panel->bl_config.bl_max_level = MAX_BL_LEVEL; |
| } else { |
| panel->bl_config.bl_max_level = val; |
| } |
| |
| rc = of_property_read_u32(of_node, "qcom,mdss-brightness-max-level", |
| &val); |
| if (rc) { |
| pr_debug("[%s] brigheness-max-level unspecified, defaulting to 255\n", |
| panel->name); |
| panel->bl_config.brightness_max_level = 255; |
| } else { |
| panel->bl_config.brightness_max_level = val; |
| } |
| |
| if (panel->bl_config.type == DSI_BACKLIGHT_PWM) { |
| rc = dsi_panel_parse_bl_pwm_config(&panel->bl_config, of_node); |
| if (rc) { |
| pr_err("[%s] failed to parse pwm config, rc=%d\n", |
| panel->name, rc); |
| goto error; |
| } |
| } |
| |
| panel->bl_config.en_gpio = of_get_named_gpio(of_node, |
| "qcom,platform-bklight-en-gpio", |
| 0); |
| if (!gpio_is_valid(panel->bl_config.en_gpio)) { |
| pr_err("[%s] failed get bklt gpio, rc=%d\n", panel->name, rc); |
| rc = -EINVAL; |
| goto error; |
| } |
| |
| error: |
| return rc; |
| } |
| |
| void dsi_dsc_pclk_param_calc(struct msm_display_dsc_info *dsc, int intf_width) |
| { |
| int slice_per_pkt, slice_per_intf; |
| int bytes_in_slice, total_bytes_per_intf; |
| |
| if (!dsc || !dsc->slice_width || !dsc->slice_per_pkt || |
| (intf_width < dsc->slice_width)) { |
| pr_err("invalid input, intf_width=%d slice_width=%d\n", |
| intf_width, dsc ? dsc->slice_width : -1); |
| return; |
| } |
| |
| slice_per_pkt = dsc->slice_per_pkt; |
| slice_per_intf = DIV_ROUND_UP(intf_width, dsc->slice_width); |
| |
| /* |
| * If slice_per_pkt is greater than slice_per_intf then default to 1. |
| * This can happen during partial update. |
| */ |
| if (slice_per_pkt > slice_per_intf) |
| slice_per_pkt = 1; |
| |
| bytes_in_slice = DIV_ROUND_UP(dsc->slice_width * dsc->bpp, 8); |
| total_bytes_per_intf = bytes_in_slice * slice_per_intf; |
| |
| dsc->eol_byte_num = total_bytes_per_intf % 3; |
| dsc->pclk_per_line = DIV_ROUND_UP(total_bytes_per_intf, 3); |
| dsc->bytes_in_slice = bytes_in_slice; |
| dsc->bytes_per_pkt = bytes_in_slice * slice_per_pkt; |
| dsc->pkt_per_line = slice_per_intf / slice_per_pkt; |
| } |
| |
| |
| int dsi_dsc_populate_static_param(struct msm_display_dsc_info *dsc) |
| { |
| int bpp, bpc; |
| int mux_words_size; |
| int groups_per_line, groups_total; |
| int min_rate_buffer_size; |
| int hrd_delay; |
| int pre_num_extra_mux_bits, num_extra_mux_bits; |
| int slice_bits; |
| int target_bpp_x16; |
| int data; |
| int final_value, final_scale; |
| |
| dsc->version = 0x11; |
| dsc->scr_rev = 0; |
| dsc->rc_model_size = 8192; |
| if (dsc->version == 0x11 && dsc->scr_rev == 0x1) |
| dsc->first_line_bpg_offset = 15; |
| else |
| dsc->first_line_bpg_offset = 12; |
| |
| dsc->min_qp_flatness = 3; |
| dsc->max_qp_flatness = 12; |
| dsc->line_buf_depth = 9; |
| dsc->edge_factor = 6; |
| dsc->quant_incr_limit0 = 11; |
| dsc->quant_incr_limit1 = 11; |
| dsc->tgt_offset_hi = 3; |
| dsc->tgt_offset_lo = 3; |
| dsc->enable_422 = 0; |
| dsc->convert_rgb = 1; |
| dsc->vbr_enable = 0; |
| |
| dsc->buf_thresh = dsi_dsc_rc_buf_thresh; |
| if (dsc->version == 0x11 && dsc->scr_rev == 0x1) { |
| dsc->range_min_qp = dsi_dsc_rc_range_min_qp_1_1_scr1; |
| dsc->range_max_qp = dsi_dsc_rc_range_max_qp_1_1_scr1; |
| } else { |
| dsc->range_min_qp = dsi_dsc_rc_range_min_qp_1_1; |
| dsc->range_max_qp = dsi_dsc_rc_range_max_qp_1_1; |
| } |
| dsc->range_bpg_offset = dsi_dsc_rc_range_bpg_offset; |
| |
| bpp = dsc->bpp; |
| bpc = dsc->bpc; |
| |
| if (bpp == 8) |
| dsc->initial_offset = 6144; |
| else |
| dsc->initial_offset = 2048; /* bpp = 12 */ |
| |
| if (bpc <= 8) |
| mux_words_size = 48; |
| else |
| mux_words_size = 64; /* bpc == 12 */ |
| |
| dsc->slice_last_group_size = 3 - (dsc->slice_width % 3); |
| |
| dsc->det_thresh_flatness = 7 + 2*(bpc - 8); |
| |
| dsc->initial_xmit_delay = dsc->rc_model_size / (2 * bpp); |
| |
| groups_per_line = DIV_ROUND_UP(dsc->slice_width, 3); |
| |
| dsc->chunk_size = dsc->slice_width * bpp / 8; |
| if ((dsc->slice_width * bpp) % 8) |
| dsc->chunk_size++; |
| |
| /* rbs-min */ |
| min_rate_buffer_size = dsc->rc_model_size - dsc->initial_offset + |
| dsc->initial_xmit_delay * bpp + |
| groups_per_line * dsc->first_line_bpg_offset; |
| |
| hrd_delay = DIV_ROUND_UP(min_rate_buffer_size, bpp); |
| |
| dsc->initial_dec_delay = hrd_delay - dsc->initial_xmit_delay; |
| |
| dsc->initial_scale_value = 8 * dsc->rc_model_size / |
| (dsc->rc_model_size - dsc->initial_offset); |
| |
| slice_bits = 8 * dsc->chunk_size * dsc->slice_height; |
| |
| groups_total = groups_per_line * dsc->slice_height; |
| |
| data = dsc->first_line_bpg_offset * 2048; |
| |
| dsc->nfl_bpg_offset = DIV_ROUND_UP(data, (dsc->slice_height - 1)); |
| |
| pre_num_extra_mux_bits = 3 * (mux_words_size + (4 * bpc + 4) - 2); |
| |
| num_extra_mux_bits = pre_num_extra_mux_bits - (mux_words_size - |
| ((slice_bits - pre_num_extra_mux_bits) % mux_words_size)); |
| |
| data = 2048 * (dsc->rc_model_size - dsc->initial_offset |
| + num_extra_mux_bits); |
| dsc->slice_bpg_offset = DIV_ROUND_UP(data, groups_total); |
| |
| /* bpp * 16 + 0.5 */ |
| data = bpp * 16; |
| data *= 2; |
| data++; |
| data /= 2; |
| target_bpp_x16 = data; |
| |
| data = (dsc->initial_xmit_delay * target_bpp_x16) / 16; |
| final_value = dsc->rc_model_size - data + num_extra_mux_bits; |
| |
| final_scale = 8 * dsc->rc_model_size / |
| (dsc->rc_model_size - final_value); |
| |
| dsc->final_offset = final_value; |
| |
| data = (final_scale - 9) * (dsc->nfl_bpg_offset + |
| dsc->slice_bpg_offset); |
| dsc->scale_increment_interval = (2048 * dsc->final_offset) / data; |
| |
| dsc->scale_decrement_interval = groups_per_line / |
| (dsc->initial_scale_value - 8); |
| |
| return 0; |
| } |
| |
| int dsi_panel_parse_dsc_params(struct dsi_panel *panel, |
| struct device_node *of_node) |
| { |
| u32 data; |
| int rc = -EINVAL; |
| int intf_width; |
| struct device_node *dsc_np = NULL; |
| |
| if (!panel->dsc_enabled) |
| return 0; |
| |
| dsc_np = of_parse_phandle(of_node, "qcom,config-select", 0); |
| if (!dsc_np) { |
| pr_err("no dsc config found\n"); |
| goto error; |
| } |
| |
| rc = of_property_read_u32(dsc_np, "qcom,mdss-dsc-slice-height", &data); |
| if (rc) { |
| pr_err("failed to parse qcom,mdss-dsc-slice-height\n"); |
| goto error; |
| } |
| panel->dsc.slice_height = data; |
| |
| rc = of_property_read_u32(dsc_np, "qcom,mdss-dsc-slice-width", &data); |
| if (rc) { |
| pr_err("failed to parse qcom,mdss-dsc-slice-width\n"); |
| goto error; |
| } |
| panel->dsc.slice_width = data; |
| |
| intf_width = panel->mode.timing.h_active; |
| if (intf_width % panel->dsc.slice_width) { |
| pr_err("invalid slice width for the panel\n"); |
| goto error; |
| } |
| |
| panel->dsc.pic_width = panel->mode.timing.h_active; |
| panel->dsc.pic_height = panel->mode.timing.v_active; |
| |
| rc = of_property_read_u32(dsc_np, "qcom,mdss-dsc-slice-per-pkt", &data); |
| if (rc) { |
| pr_err("failed to parse qcom,mdss-dsc-slice-per-pkt\n"); |
| goto error; |
| } |
| panel->dsc.slice_per_pkt = data; |
| |
| rc = of_property_read_u32(dsc_np, "qcom,mdss-dsc-bit-per-component", |
| &data); |
| if (rc) { |
| pr_err("failed to parse qcom,mdss-dsc-bit-per-component\n"); |
| goto error; |
| } |
| panel->dsc.bpc = data; |
| |
| rc = of_property_read_u32(dsc_np, "qcom,mdss-dsc-bit-per-pixel", &data); |
| if (rc) { |
| pr_err("failed to parse qcom,mdss-dsc-bit-per-pixel\n"); |
| goto error; |
| } |
| panel->dsc.bpp = data; |
| |
| panel->dsc.block_pred_enable = of_property_read_bool(dsc_np, |
| "qcom,mdss-dsc-block-prediction-enable"); |
| |
| panel->dsc.full_frame_slices = DIV_ROUND_UP(intf_width, |
| panel->dsc.slice_width); |
| |
| dsi_dsc_populate_static_param(&panel->dsc); |
| dsi_dsc_pclk_param_calc(&panel->dsc, intf_width); |
| |
| error: |
| return rc; |
| } |
| |
| static int dsi_panel_parse_hdr_config(struct dsi_panel *panel, |
| struct device_node *of_node) |
| { |
| |
| int rc = 0; |
| struct drm_panel_hdr_properties *hdr_prop; |
| |
| hdr_prop = &panel->hdr_props; |
| hdr_prop->hdr_enabled = of_property_read_bool(of_node, |
| "qcom,mdss-dsi-panel-hdr-enabled"); |
| |
| if (hdr_prop->hdr_enabled) { |
| rc = of_property_read_u32_array(of_node, |
| "qcom,mdss-dsi-panel-hdr-color-primaries", |
| hdr_prop->display_primaries, |
| DISPLAY_PRIMARIES_MAX); |
| if (rc) { |
| pr_err("%s:%d, Unable to read color primaries,rc:%u", |
| __func__, __LINE__, rc); |
| hdr_prop->hdr_enabled = false; |
| return rc; |
| } |
| |
| rc = of_property_read_u32(of_node, |
| "qcom,mdss-dsi-panel-peak-brightness", |
| &(hdr_prop->peak_brightness)); |
| if (rc) { |
| pr_err("%s:%d, Unable to read hdr brightness, rc:%u", |
| __func__, __LINE__, rc); |
| hdr_prop->hdr_enabled = false; |
| return rc; |
| } |
| |
| rc = of_property_read_u32(of_node, |
| "qcom,mdss-dsi-panel-blackness-level", |
| &(hdr_prop->blackness_level)); |
| if (rc) { |
| pr_err("%s:%d, Unable to read hdr brightness, rc:%u", |
| __func__, __LINE__, rc); |
| hdr_prop->hdr_enabled = false; |
| return rc; |
| } |
| } |
| return 0; |
| } |
| |
| struct dsi_panel *dsi_panel_get(struct device *parent, |
| struct device_node *of_node) |
| { |
| struct dsi_panel *panel; |
| const char *data; |
| const char *compression; |
| u32 len = 0; |
| int rc = 0; |
| |
| panel = kzalloc(sizeof(*panel), GFP_KERNEL); |
| if (!panel) |
| return ERR_PTR(-ENOMEM); |
| |
| panel->name = of_get_property(of_node, "qcom,mdss-dsi-panel-name", |
| NULL); |
| if (!panel->name) |
| panel->name = DSI_PANEL_DEFAULT_LABEL; |
| |
| panel->dsc_enabled = false; |
| compression = of_get_property(of_node, "qcom,compression-mode", NULL); |
| if (compression && !strcmp(compression, "dsc")) |
| panel->dsc_enabled = true; |
| |
| rc = dsi_panel_parse_timing(&panel->mode.timing, of_node); |
| if (rc) { |
| pr_err("failed to parse panel timing, rc=%d\n", rc); |
| goto error; |
| } |
| |
| rc = dsi_panel_parse_dsc_params(panel, of_node); |
| if (rc) { |
| pr_err("failed to parse dsc params, rc=%d\n", rc); |
| goto error; |
| } |
| |
| data = of_get_property(of_node, |
| "qcom,mdss-dsi-panel-phy-timings", &len); |
| if (!data) { |
| pr_debug("%s:%d, Unable to read Phy timing settings", |
| __func__, __LINE__); |
| } else { |
| int i = 0; |
| |
| panel->phy_timing_val = kzalloc((sizeof(u32) * len), |
| GFP_KERNEL); |
| if (!panel->phy_timing_val) { |
| kfree(panel); |
| return ERR_PTR(-ENOMEM); |
| } |
| for (i = 0; i < len; i++) |
| panel->phy_timing_val[i] = data[i]; |
| } |
| panel->phy_timing_len = len; |
| |
| panel->mode.pixel_clk_khz = (DSI_H_TOTAL(&panel->mode.timing) * |
| DSI_V_TOTAL(&panel->mode.timing) * |
| panel->mode.timing.refresh_rate) / 1000; |
| rc = dsi_panel_parse_host_config(panel, of_node); |
| if (rc) { |
| pr_err("failed to parse host configuration, rc=%d\n", rc); |
| goto error; |
| } |
| |
| rc = dsi_panel_parse_panel_mode(panel, of_node); |
| if (rc) { |
| pr_err("failed to parse panel mode configuration, rc=%d\n", rc); |
| goto error; |
| } |
| |
| rc = dsi_panel_parse_dfps_caps(&panel->dfps_caps, of_node, panel->name); |
| if (rc) |
| pr_err("failed to parse dfps configuration, rc=%d\n", rc); |
| |
| rc = dsi_panel_parse_phy_props(&panel->phy_props, of_node, panel->name); |
| if (rc) { |
| pr_err("failed to parse panel physical dimension, rc=%d\n", rc); |
| goto error; |
| } |
| |
| rc = dsi_panel_parse_cmd_sets(panel, of_node); |
| if (rc) { |
| pr_err("failed to parse command sets, rc=%d\n", rc); |
| goto error; |
| } |
| |
| rc = dsi_panel_parse_power_cfg(parent, panel, of_node); |
| if (rc) |
| pr_err("failed to parse power config, rc=%d\n", rc); |
| |
| rc = dsi_panel_parse_gpios(panel, of_node); |
| if (rc) |
| pr_err("failed to parse panel gpios, rc=%d\n", rc); |
| |
| rc = dsi_panel_parse_bl_config(panel, of_node); |
| if (rc) |
| pr_err("failed to parse backlight config, rc=%d\n", rc); |
| |
| rc = dsi_panel_parse_jitter_config(panel, of_node); |
| if (rc) |
| pr_err("failed to parse panel jitter config, rc=%d\n", rc); |
| |
| rc = dsi_panel_parse_hdr_config(panel, of_node); |
| if (rc) |
| pr_err("failed to parse hdr config, rc=%d\n", rc); |
| |
| panel->panel_of_node = of_node; |
| drm_panel_init(&panel->drm_panel); |
| mutex_init(&panel->panel_lock); |
| panel->parent = parent; |
| return panel; |
| error: |
| kfree(panel); |
| return ERR_PTR(rc); |
| } |
| |
| void dsi_panel_put(struct dsi_panel *panel) |
| { |
| u32 i; |
| |
| for (i = 0; i < DSI_CMD_SET_MAX; i++) |
| dsi_panel_destroy_cmd_packets(&panel->cmd_sets[i]); |
| |
| /* TODO: more free */ |
| kfree(panel); |
| } |
| |
| int dsi_panel_drv_init(struct dsi_panel *panel, |
| struct mipi_dsi_host *host) |
| { |
| int rc = 0; |
| struct mipi_dsi_device *dev; |
| |
| if (!panel || !host) { |
| pr_err("invalid params\n"); |
| return -EINVAL; |
| } |
| |
| mutex_lock(&panel->panel_lock); |
| |
| dev = &panel->mipi_device; |
| |
| dev->host = host; |
| /* |
| * We dont have device structure since panel is not a device node. |
| * When using drm panel framework, the device is probed when the host is |
| * create. |
| */ |
| dev->channel = 0; |
| dev->lanes = 4; |
| |
| panel->host = host; |
| rc = dsi_panel_vreg_get(panel); |
| if (rc) { |
| pr_err("[%s] failed to get panel regulators, rc=%d\n", |
| panel->name, rc); |
| goto exit; |
| } |
| |
| rc = dsi_panel_pinctrl_init(panel); |
| if (rc) { |
| pr_err("[%s] failed to init pinctrl, rc=%d\n", panel->name, rc); |
| goto error_vreg_put; |
| } |
| |
| rc = dsi_panel_gpio_request(panel); |
| if (rc) { |
| pr_err("[%s] failed to request gpios, rc=%d\n", panel->name, |
| rc); |
| goto error_pinctrl_deinit; |
| } |
| |
| rc = dsi_panel_bl_register(panel); |
| if (rc) { |
| if (rc != -EPROBE_DEFER) |
| pr_err("[%s] failed to register backlight, rc=%d\n", |
| panel->name, rc); |
| goto error_gpio_release; |
| } |
| |
| goto exit; |
| |
| error_gpio_release: |
| (void)dsi_panel_gpio_release(panel); |
| error_pinctrl_deinit: |
| (void)dsi_panel_pinctrl_deinit(panel); |
| error_vreg_put: |
| (void)dsi_panel_vreg_put(panel); |
| exit: |
| mutex_unlock(&panel->panel_lock); |
| return rc; |
| } |
| |
| int dsi_panel_drv_deinit(struct dsi_panel *panel) |
| { |
| int rc = 0; |
| |
| if (!panel) { |
| pr_err("invalid params\n"); |
| return -EINVAL; |
| } |
| |
| mutex_lock(&panel->panel_lock); |
| |
| rc = dsi_panel_bl_unregister(panel); |
| if (rc) |
| pr_err("[%s] failed to unregister backlight, rc=%d\n", |
| panel->name, rc); |
| |
| rc = dsi_panel_gpio_release(panel); |
| if (rc) |
| pr_err("[%s] failed to release gpios, rc=%d\n", panel->name, |
| rc); |
| |
| rc = dsi_panel_pinctrl_deinit(panel); |
| if (rc) |
| pr_err("[%s] failed to deinit gpios, rc=%d\n", panel->name, |
| rc); |
| |
| rc = dsi_panel_vreg_put(panel); |
| if (rc) |
| pr_err("[%s] failed to put regs, rc=%d\n", panel->name, rc); |
| |
| panel->host = NULL; |
| memset(&panel->mipi_device, 0x0, sizeof(panel->mipi_device)); |
| |
| mutex_unlock(&panel->panel_lock); |
| return rc; |
| } |
| |
| int dsi_panel_validate_mode(struct dsi_panel *panel, |
| struct dsi_display_mode *mode) |
| { |
| return 0; |
| } |
| |
| int dsi_panel_get_mode_count(struct dsi_panel *panel, u32 *count) |
| { |
| int rc = 0; |
| |
| if (!panel || !count) { |
| pr_err("invalid params\n"); |
| return -EINVAL; |
| } |
| |
| mutex_lock(&panel->panel_lock); |
| /* TODO: DT format has not been decided for multiple modes. */ |
| *count = 1; |
| |
| mutex_unlock(&panel->panel_lock); |
| return rc; |
| } |
| |
| int dsi_panel_get_phy_props(struct dsi_panel *panel, |
| struct dsi_panel_phy_props *phy_props) |
| { |
| int rc = 0; |
| |
| if (!panel || !phy_props) { |
| pr_err("invalid params\n"); |
| return -EINVAL; |
| } |
| |
| mutex_lock(&panel->panel_lock); |
| |
| memcpy(phy_props, &panel->phy_props, sizeof(*phy_props)); |
| |
| mutex_unlock(&panel->panel_lock); |
| return rc; |
| } |
| |
| int dsi_panel_get_dfps_caps(struct dsi_panel *panel, |
| struct dsi_dfps_capabilities *dfps_caps) |
| { |
| int rc = 0; |
| |
| if (!panel || !dfps_caps) { |
| pr_err("invalid params\n"); |
| return -EINVAL; |
| } |
| |
| mutex_lock(&panel->panel_lock); |
| |
| memcpy(dfps_caps, &panel->dfps_caps, sizeof(*dfps_caps)); |
| |
| mutex_unlock(&panel->panel_lock); |
| return rc; |
| } |
| |
| int dsi_panel_get_mode(struct dsi_panel *panel, |
| u32 index, |
| struct dsi_display_mode *mode) |
| { |
| int rc = 0; |
| |
| if (!panel || !mode) { |
| pr_err("invalid params\n"); |
| return -EINVAL; |
| } |
| |
| mutex_lock(&panel->panel_lock); |
| if (index != 0) |
| rc = -ENOTSUPP; /* TODO: Support more than one mode */ |
| else |
| memcpy(mode, &panel->mode, sizeof(*mode)); |
| |
| mutex_unlock(&panel->panel_lock); |
| return rc; |
| } |
| |
| int dsi_panel_get_host_cfg_for_mode(struct dsi_panel *panel, |
| struct dsi_display_mode *mode, |
| struct dsi_host_config *config) |
| { |
| int rc = 0; |
| |
| if (!panel || !mode || !config) { |
| pr_err("invalid params\n"); |
| return -EINVAL; |
| } |
| |
| mutex_lock(&panel->panel_lock); |
| |
| config->panel_mode = panel->mode.panel_mode; |
| memcpy(&config->common_config, &panel->host_config, |
| sizeof(config->common_config)); |
| |
| if (mode->panel_mode == DSI_OP_VIDEO_MODE) { |
| memcpy(&config->u.video_engine, &panel->video_config, |
| sizeof(config->u.video_engine)); |
| } else { |
| memcpy(&config->u.cmd_engine, &panel->cmd_config, |
| sizeof(config->u.cmd_engine)); |
| } |
| |
| memcpy(&config->video_timing, &mode->timing, |
| sizeof(config->video_timing)); |
| config->video_timing.dsc_enabled = panel->dsc_enabled; |
| config->video_timing.dsc = &panel->dsc; |
| |
| config->esc_clk_rate_hz = 19200000; |
| mutex_unlock(&panel->panel_lock); |
| return rc; |
| } |
| |
| int dsi_panel_pre_prepare(struct dsi_panel *panel) |
| { |
| int rc = 0; |
| |
| if (!panel) { |
| pr_err("invalid params\n"); |
| return -EINVAL; |
| } |
| |
| mutex_lock(&panel->panel_lock); |
| |
| /* If LP11_INIT is set, panel will be powered up during prepare() */ |
| if (panel->lp11_init) |
| goto error; |
| |
| rc = dsi_panel_power_on(panel); |
| if (rc) { |
| pr_err("[%s] panel power on failed, rc=%d\n", panel->name, rc); |
| goto error; |
| } |
| |
| error: |
| mutex_unlock(&panel->panel_lock); |
| return rc; |
| } |
| |
| int dsi_panel_update_pps(struct dsi_panel *panel) |
| { |
| int rc = 0; |
| struct dsi_panel_cmd_set *set = NULL; |
| |
| if (!panel) { |
| pr_err("invalid params\n"); |
| return -EINVAL; |
| } |
| |
| mutex_lock(&panel->panel_lock); |
| |
| set = &panel->cmd_sets[DSI_CMD_SET_PPS]; |
| |
| dsi_dsc_create_pps_buf_cmd(&panel->dsc, panel->dsc_pps_cmd, 0); |
| rc = dsi_panel_create_cmd_packets(panel->dsc_pps_cmd, |
| DSI_CMD_PPS_SIZE, 1, set->cmds); |
| if (rc) { |
| pr_err("failed to create cmd packets, rc=%d\n", rc); |
| goto error; |
| } |
| |
| rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_PPS); |
| if (rc) { |
| pr_err("[%s] failed to send DSI_CMD_SET_PPS cmds, rc=%d\n", |
| panel->name, rc); |
| goto error; |
| } |
| |
| error: |
| mutex_unlock(&panel->panel_lock); |
| return rc; |
| } |
| |
| int dsi_panel_prepare(struct dsi_panel *panel) |
| { |
| int rc = 0; |
| |
| if (!panel) { |
| pr_err("invalid params\n"); |
| return -EINVAL; |
| } |
| |
| mutex_lock(&panel->panel_lock); |
| |
| if (panel->lp11_init) { |
| rc = dsi_panel_power_on(panel); |
| if (rc) { |
| pr_err("[%s] panel power on failed, rc=%d\n", |
| panel->name, rc); |
| goto error; |
| } |
| } |
| |
| rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_PRE_ON); |
| if (rc) { |
| pr_err("[%s] failed to send DSI_CMD_SET_PRE_ON cmds, rc=%d\n", |
| panel->name, rc); |
| goto error; |
| } |
| |
| error: |
| mutex_unlock(&panel->panel_lock); |
| return rc; |
| } |
| |
| int dsi_panel_enable(struct dsi_panel *panel) |
| { |
| int rc = 0; |
| |
| if (!panel) { |
| pr_err("Invalid params\n"); |
| return -EINVAL; |
| } |
| |
| mutex_lock(&panel->panel_lock); |
| |
| rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_ON); |
| if (rc) { |
| pr_err("[%s] failed to send DSI_CMD_SET_ON cmds, rc=%d\n", |
| panel->name, rc); |
| } |
| panel->panel_initialized = true; |
| mutex_unlock(&panel->panel_lock); |
| return rc; |
| } |
| |
| int dsi_panel_post_enable(struct dsi_panel *panel) |
| { |
| int rc = 0; |
| |
| if (!panel) { |
| pr_err("invalid params\n"); |
| return -EINVAL; |
| } |
| |
| mutex_lock(&panel->panel_lock); |
| |
| rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_POST_ON); |
| if (rc) { |
| pr_err("[%s] failed to send DSI_CMD_SET_POST_ON cmds, rc=%d\n", |
| panel->name, rc); |
| goto error; |
| } |
| error: |
| mutex_unlock(&panel->panel_lock); |
| return rc; |
| } |
| |
| int dsi_panel_pre_disable(struct dsi_panel *panel) |
| { |
| int rc = 0; |
| |
| if (!panel) { |
| pr_err("invalid params\n"); |
| return -EINVAL; |
| } |
| |
| mutex_lock(&panel->panel_lock); |
| |
| rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_PRE_OFF); |
| if (rc) { |
| pr_err("[%s] failed to send DSI_CMD_SET_PRE_OFF cmds, rc=%d\n", |
| panel->name, rc); |
| goto error; |
| } |
| |
| error: |
| mutex_unlock(&panel->panel_lock); |
| return rc; |
| } |
| |
| int dsi_panel_disable(struct dsi_panel *panel) |
| { |
| int rc = 0; |
| |
| if (!panel) { |
| pr_err("invalid params\n"); |
| return -EINVAL; |
| } |
| |
| mutex_lock(&panel->panel_lock); |
| |
| rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_OFF); |
| if (rc) { |
| pr_err("[%s] failed to send DSI_CMD_SET_OFF cmds, rc=%d\n", |
| panel->name, rc); |
| goto error; |
| } |
| panel->panel_initialized = false; |
| |
| error: |
| mutex_unlock(&panel->panel_lock); |
| return rc; |
| } |
| |
| int dsi_panel_unprepare(struct dsi_panel *panel) |
| { |
| int rc = 0; |
| |
| if (!panel) { |
| pr_err("invalid params\n"); |
| return -EINVAL; |
| } |
| |
| mutex_lock(&panel->panel_lock); |
| |
| rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_POST_OFF); |
| if (rc) { |
| pr_err("[%s] failed to send DSI_CMD_SET_POST_OFF cmds, rc=%d\n", |
| panel->name, rc); |
| goto error; |
| } |
| |
| if (panel->lp11_init) { |
| rc = dsi_panel_power_off(panel); |
| if (rc) { |
| pr_err("[%s] panel power_Off failed, rc=%d\n", |
| panel->name, rc); |
| goto error; |
| } |
| } |
| error: |
| mutex_unlock(&panel->panel_lock); |
| return rc; |
| } |
| |
| int dsi_panel_post_unprepare(struct dsi_panel *panel) |
| { |
| int rc = 0; |
| |
| if (!panel) { |
| pr_err("invalid params\n"); |
| return -EINVAL; |
| } |
| |
| mutex_lock(&panel->panel_lock); |
| |
| if (!panel->lp11_init) { |
| rc = dsi_panel_power_off(panel); |
| if (rc) { |
| pr_err("[%s] panel power_Off failed, rc=%d\n", |
| panel->name, rc); |
| goto error; |
| } |
| } |
| error: |
| mutex_unlock(&panel->panel_lock); |
| return rc; |
| } |