2015-03-27 07:25:17 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015, 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.
|
|
|
|
*/
|
|
|
|
|
2017-04-24 12:50:28 +08:00
|
|
|
#include <drm/drm_crtc.h>
|
2019-01-18 05:03:34 +08:00
|
|
|
#include <drm/drm_probe_helper.h>
|
2015-03-27 07:25:17 +08:00
|
|
|
|
2017-04-24 12:50:28 +08:00
|
|
|
#include "mdp5_kms.h"
|
2015-03-27 07:25:17 +08:00
|
|
|
|
|
|
|
static struct mdp5_kms *get_kms(struct drm_encoder *encoder)
|
|
|
|
{
|
|
|
|
struct msm_drm_private *priv = encoder->dev->dev_private;
|
|
|
|
return to_mdp5_kms(to_mdp_kms(priv->kms));
|
|
|
|
}
|
|
|
|
|
2015-06-04 22:26:37 +08:00
|
|
|
#ifdef DOWNSTREAM_CONFIG_MSM_BUS_SCALING
|
2015-03-27 07:25:17 +08:00
|
|
|
#include <mach/board.h>
|
|
|
|
#include <linux/msm-bus.h>
|
|
|
|
#include <linux/msm-bus-board.h>
|
|
|
|
|
2017-01-16 13:55:38 +08:00
|
|
|
static void bs_set(struct mdp5_encoder *mdp5_cmd_enc, int idx)
|
2015-03-27 07:25:17 +08:00
|
|
|
{
|
|
|
|
if (mdp5_cmd_enc->bsc) {
|
|
|
|
DBG("set bus scaling: %d", idx);
|
|
|
|
/* HACK: scaling down, and then immediately back up
|
|
|
|
* seems to leave things broken (underflow).. so
|
|
|
|
* never disable:
|
|
|
|
*/
|
|
|
|
idx = 1;
|
|
|
|
msm_bus_scale_client_update_request(mdp5_cmd_enc->bsc, idx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
2017-01-16 13:55:38 +08:00
|
|
|
static void bs_set(struct mdp5_encoder *mdp5_cmd_enc, int idx) {}
|
2015-03-27 07:25:17 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define VSYNC_CLK_RATE 19200000
|
|
|
|
static int pingpong_tearcheck_setup(struct drm_encoder *encoder,
|
2017-01-16 13:55:38 +08:00
|
|
|
struct drm_display_mode *mode)
|
2015-03-27 07:25:17 +08:00
|
|
|
{
|
|
|
|
struct mdp5_kms *mdp5_kms = get_kms(encoder);
|
|
|
|
struct device *dev = encoder->dev->dev;
|
|
|
|
u32 total_lines_x100, vclks_line, cfg;
|
|
|
|
long vsync_clk_speed;
|
2017-03-23 18:27:57 +08:00
|
|
|
struct mdp5_hw_mixer *mixer = mdp5_crtc_get_mixer(encoder->crtc);
|
2017-03-23 18:27:58 +08:00
|
|
|
int pp_id = mixer->pp;
|
2015-03-27 07:25:17 +08:00
|
|
|
|
|
|
|
if (IS_ERR_OR_NULL(mdp5_kms->vsync_clk)) {
|
2018-10-21 01:49:26 +08:00
|
|
|
DRM_DEV_ERROR(dev, "vsync_clk is not initialized\n");
|
2015-03-27 07:25:17 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2019-01-29 04:42:48 +08:00
|
|
|
total_lines_x100 = mode->vtotal * drm_mode_vrefresh(mode);
|
2015-03-27 07:25:17 +08:00
|
|
|
if (!total_lines_x100) {
|
2018-10-21 01:49:26 +08:00
|
|
|
DRM_DEV_ERROR(dev, "%s: vtotal(%d) or vrefresh(%d) is 0\n",
|
2019-01-29 04:42:48 +08:00
|
|
|
__func__, mode->vtotal, drm_mode_vrefresh(mode));
|
2015-03-27 07:25:17 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
vsync_clk_speed = clk_round_rate(mdp5_kms->vsync_clk, VSYNC_CLK_RATE);
|
|
|
|
if (vsync_clk_speed <= 0) {
|
2018-10-21 01:49:26 +08:00
|
|
|
DRM_DEV_ERROR(dev, "vsync_clk round rate failed %ld\n",
|
2015-03-27 07:25:17 +08:00
|
|
|
vsync_clk_speed);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
vclks_line = vsync_clk_speed * 100 / total_lines_x100;
|
|
|
|
|
|
|
|
cfg = MDP5_PP_SYNC_CONFIG_VSYNC_COUNTER_EN
|
|
|
|
| MDP5_PP_SYNC_CONFIG_VSYNC_IN_EN;
|
|
|
|
cfg |= MDP5_PP_SYNC_CONFIG_VSYNC_COUNT(vclks_line);
|
|
|
|
|
|
|
|
mdp5_write(mdp5_kms, REG_MDP5_PP_SYNC_CONFIG_VSYNC(pp_id), cfg);
|
|
|
|
mdp5_write(mdp5_kms,
|
|
|
|
REG_MDP5_PP_SYNC_CONFIG_HEIGHT(pp_id), 0xfff0);
|
|
|
|
mdp5_write(mdp5_kms,
|
|
|
|
REG_MDP5_PP_VSYNC_INIT_VAL(pp_id), mode->vdisplay);
|
|
|
|
mdp5_write(mdp5_kms, REG_MDP5_PP_RD_PTR_IRQ(pp_id), mode->vdisplay + 1);
|
|
|
|
mdp5_write(mdp5_kms, REG_MDP5_PP_START_POS(pp_id), mode->vdisplay);
|
|
|
|
mdp5_write(mdp5_kms, REG_MDP5_PP_SYNC_THRESH(pp_id),
|
|
|
|
MDP5_PP_SYNC_THRESH_START(4) |
|
|
|
|
MDP5_PP_SYNC_THRESH_CONTINUE(4));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pingpong_tearcheck_enable(struct drm_encoder *encoder)
|
|
|
|
{
|
|
|
|
struct mdp5_kms *mdp5_kms = get_kms(encoder);
|
2017-03-23 18:27:57 +08:00
|
|
|
struct mdp5_hw_mixer *mixer = mdp5_crtc_get_mixer(encoder->crtc);
|
2017-03-23 18:27:58 +08:00
|
|
|
int pp_id = mixer->pp;
|
2015-03-27 07:25:17 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = clk_set_rate(mdp5_kms->vsync_clk,
|
|
|
|
clk_round_rate(mdp5_kms->vsync_clk, VSYNC_CLK_RATE));
|
|
|
|
if (ret) {
|
2018-10-21 01:49:26 +08:00
|
|
|
DRM_DEV_ERROR(encoder->dev->dev,
|
2015-03-27 07:25:17 +08:00
|
|
|
"vsync_clk clk_set_rate failed, %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
ret = clk_prepare_enable(mdp5_kms->vsync_clk);
|
|
|
|
if (ret) {
|
2018-10-21 01:49:26 +08:00
|
|
|
DRM_DEV_ERROR(encoder->dev->dev,
|
2015-03-27 07:25:17 +08:00
|
|
|
"vsync_clk clk_prepare_enable failed, %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
mdp5_write(mdp5_kms, REG_MDP5_PP_TEAR_CHECK_EN(pp_id), 1);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pingpong_tearcheck_disable(struct drm_encoder *encoder)
|
|
|
|
{
|
|
|
|
struct mdp5_kms *mdp5_kms = get_kms(encoder);
|
2017-03-23 18:27:57 +08:00
|
|
|
struct mdp5_hw_mixer *mixer = mdp5_crtc_get_mixer(encoder->crtc);
|
2017-03-23 18:27:58 +08:00
|
|
|
int pp_id = mixer->pp;
|
2015-03-27 07:25:17 +08:00
|
|
|
|
|
|
|
mdp5_write(mdp5_kms, REG_MDP5_PP_TEAR_CHECK_EN(pp_id), 0);
|
|
|
|
clk_disable_unprepare(mdp5_kms->vsync_clk);
|
|
|
|
}
|
|
|
|
|
2017-01-16 13:55:38 +08:00
|
|
|
void mdp5_cmd_encoder_mode_set(struct drm_encoder *encoder,
|
|
|
|
struct drm_display_mode *mode,
|
|
|
|
struct drm_display_mode *adjusted_mode)
|
2015-03-27 07:25:17 +08:00
|
|
|
{
|
|
|
|
mode = adjusted_mode;
|
|
|
|
|
2019-01-11 02:13:01 +08:00
|
|
|
DBG("set mode: " DRM_MODE_FMT, DRM_MODE_ARG(mode));
|
2015-03-27 07:25:17 +08:00
|
|
|
pingpong_tearcheck_setup(encoder, mode);
|
2017-03-23 18:28:06 +08:00
|
|
|
mdp5_crtc_set_pipeline(encoder->crtc);
|
2015-03-27 07:25:17 +08:00
|
|
|
}
|
|
|
|
|
2017-01-16 13:55:38 +08:00
|
|
|
void mdp5_cmd_encoder_disable(struct drm_encoder *encoder)
|
2015-03-27 07:25:17 +08:00
|
|
|
{
|
2017-01-16 13:55:38 +08:00
|
|
|
struct mdp5_encoder *mdp5_cmd_enc = to_mdp5_encoder(encoder);
|
2015-06-27 04:03:25 +08:00
|
|
|
struct mdp5_ctl *ctl = mdp5_cmd_enc->ctl;
|
2017-03-23 18:27:59 +08:00
|
|
|
struct mdp5_interface *intf = mdp5_cmd_enc->intf;
|
2017-03-23 18:28:06 +08:00
|
|
|
struct mdp5_pipeline *pipeline = mdp5_crtc_get_pipeline(encoder->crtc);
|
2015-03-27 07:25:17 +08:00
|
|
|
|
|
|
|
if (WARN_ON(!mdp5_cmd_enc->enabled))
|
|
|
|
return;
|
|
|
|
|
|
|
|
pingpong_tearcheck_disable(encoder);
|
|
|
|
|
2017-03-23 18:28:06 +08:00
|
|
|
mdp5_ctl_set_encoder_state(ctl, pipeline, false);
|
2018-02-19 21:17:06 +08:00
|
|
|
mdp5_ctl_commit(ctl, pipeline, mdp_ctl_flush_mask_encoder(intf), true);
|
2015-03-27 07:25:17 +08:00
|
|
|
|
|
|
|
bs_set(mdp5_cmd_enc, 0);
|
|
|
|
|
|
|
|
mdp5_cmd_enc->enabled = false;
|
|
|
|
}
|
|
|
|
|
2017-01-16 13:55:38 +08:00
|
|
|
void mdp5_cmd_encoder_enable(struct drm_encoder *encoder)
|
2015-03-27 07:25:17 +08:00
|
|
|
{
|
2017-01-16 13:55:38 +08:00
|
|
|
struct mdp5_encoder *mdp5_cmd_enc = to_mdp5_encoder(encoder);
|
2015-06-27 04:03:25 +08:00
|
|
|
struct mdp5_ctl *ctl = mdp5_cmd_enc->ctl;
|
2017-03-23 18:27:59 +08:00
|
|
|
struct mdp5_interface *intf = mdp5_cmd_enc->intf;
|
2017-03-23 18:28:06 +08:00
|
|
|
struct mdp5_pipeline *pipeline = mdp5_crtc_get_pipeline(encoder->crtc);
|
2015-03-27 07:25:17 +08:00
|
|
|
|
|
|
|
if (WARN_ON(mdp5_cmd_enc->enabled))
|
|
|
|
return;
|
|
|
|
|
|
|
|
bs_set(mdp5_cmd_enc, 1);
|
|
|
|
if (pingpong_tearcheck_enable(encoder))
|
|
|
|
return;
|
|
|
|
|
2018-02-19 21:17:06 +08:00
|
|
|
mdp5_ctl_commit(ctl, pipeline, mdp_ctl_flush_mask_encoder(intf), true);
|
2015-03-27 07:25:17 +08:00
|
|
|
|
2017-03-23 18:28:06 +08:00
|
|
|
mdp5_ctl_set_encoder_state(ctl, pipeline, true);
|
2015-03-27 07:25:17 +08:00
|
|
|
|
|
|
|
mdp5_cmd_enc->enabled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int mdp5_cmd_encoder_set_split_display(struct drm_encoder *encoder,
|
2017-01-16 13:55:38 +08:00
|
|
|
struct drm_encoder *slave_encoder)
|
2015-03-27 07:25:17 +08:00
|
|
|
{
|
2017-01-16 13:55:38 +08:00
|
|
|
struct mdp5_encoder *mdp5_cmd_enc = to_mdp5_encoder(encoder);
|
2015-03-27 07:25:17 +08:00
|
|
|
struct mdp5_kms *mdp5_kms;
|
2017-07-28 18:47:01 +08:00
|
|
|
struct device *dev;
|
2015-03-27 07:25:17 +08:00
|
|
|
int intf_num;
|
|
|
|
u32 data = 0;
|
|
|
|
|
|
|
|
if (!encoder || !slave_encoder)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
mdp5_kms = get_kms(encoder);
|
2017-03-23 18:27:59 +08:00
|
|
|
intf_num = mdp5_cmd_enc->intf->num;
|
2015-03-27 07:25:17 +08:00
|
|
|
|
|
|
|
/* Switch slave encoder's trigger MUX, to use the master's
|
|
|
|
* start signal for the slave encoder
|
|
|
|
*/
|
|
|
|
if (intf_num == 1)
|
2016-05-10 13:35:58 +08:00
|
|
|
data |= MDP5_SPLIT_DPL_UPPER_INTF2_SW_TRG_MUX;
|
2015-03-27 07:25:17 +08:00
|
|
|
else if (intf_num == 2)
|
2016-05-10 13:35:58 +08:00
|
|
|
data |= MDP5_SPLIT_DPL_UPPER_INTF1_SW_TRG_MUX;
|
2015-03-27 07:25:17 +08:00
|
|
|
else
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* Smart Panel, Sync mode */
|
2016-05-10 13:35:58 +08:00
|
|
|
data |= MDP5_SPLIT_DPL_UPPER_SMART_PANEL;
|
2015-03-27 07:25:17 +08:00
|
|
|
|
2017-07-28 18:47:01 +08:00
|
|
|
dev = &mdp5_kms->pdev->dev;
|
|
|
|
|
2015-03-27 07:25:17 +08:00
|
|
|
/* Make sure clocks are on when connectors calling this function. */
|
2017-07-28 18:47:01 +08:00
|
|
|
pm_runtime_get_sync(dev);
|
2016-05-10 13:35:58 +08:00
|
|
|
mdp5_write(mdp5_kms, REG_MDP5_SPLIT_DPL_UPPER, data);
|
2015-03-27 07:25:17 +08:00
|
|
|
|
2016-05-10 13:35:58 +08:00
|
|
|
mdp5_write(mdp5_kms, REG_MDP5_SPLIT_DPL_LOWER,
|
|
|
|
MDP5_SPLIT_DPL_LOWER_SMART_PANEL);
|
|
|
|
mdp5_write(mdp5_kms, REG_MDP5_SPLIT_DPL_EN, 1);
|
2017-10-20 20:17:43 +08:00
|
|
|
pm_runtime_put_sync(dev);
|
2015-03-27 07:25:17 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|