1 /* Copyright (c) 2015-2018, The Linux Foundation. All rights reserved.
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
13 #include <linux/iopoll.h>
15 #include "dpu_hw_mdss.h"
17 #include "dpu_hw_catalog.h"
18 #include "dpu_hw_pingpong.h"
20 #include "dpu_trace.h"
22 #define PP_TEAR_CHECK_EN 0x000
23 #define PP_SYNC_CONFIG_VSYNC 0x004
24 #define PP_SYNC_CONFIG_HEIGHT 0x008
25 #define PP_SYNC_WRCOUNT 0x00C
26 #define PP_VSYNC_INIT_VAL 0x010
27 #define PP_INT_COUNT_VAL 0x014
28 #define PP_SYNC_THRESH 0x018
29 #define PP_START_POS 0x01C
30 #define PP_RD_PTR_IRQ 0x020
31 #define PP_WR_PTR_IRQ 0x024
32 #define PP_OUT_LINE_COUNT 0x028
33 #define PP_LINE_COUNT 0x02C
35 #define PP_FBC_MODE 0x034
36 #define PP_FBC_BUDGET_CTL 0x038
37 #define PP_FBC_LOSSY_MODE 0x03C
39 static struct dpu_pingpong_cfg *_pingpong_offset(enum dpu_pingpong pp,
40 struct dpu_mdss_cfg *m,
42 struct dpu_hw_blk_reg_map *b)
46 for (i = 0; i < m->pingpong_count; i++) {
47 if (pp == m->pingpong[i].id) {
49 b->blk_off = m->pingpong[i].base;
50 b->length = m->pingpong[i].len;
51 b->hwversion = m->hwversion;
52 b->log_mask = DPU_DBG_MASK_PINGPONG;
53 return &m->pingpong[i];
57 return ERR_PTR(-EINVAL);
60 static int dpu_hw_pp_setup_te_config(struct dpu_hw_pingpong *pp,
61 struct dpu_hw_tear_check *te)
63 struct dpu_hw_blk_reg_map *c;
70 cfg = BIT(19); /*VSYNC_COUNTER_EN */
71 if (te->hw_vsync_mode)
74 cfg |= te->vsync_count;
76 DPU_REG_WRITE(c, PP_SYNC_CONFIG_VSYNC, cfg);
77 DPU_REG_WRITE(c, PP_SYNC_CONFIG_HEIGHT, te->sync_cfg_height);
78 DPU_REG_WRITE(c, PP_VSYNC_INIT_VAL, te->vsync_init_val);
79 DPU_REG_WRITE(c, PP_RD_PTR_IRQ, te->rd_ptr_irq);
80 DPU_REG_WRITE(c, PP_START_POS, te->start_pos);
81 DPU_REG_WRITE(c, PP_SYNC_THRESH,
82 ((te->sync_threshold_continue << 16) |
83 te->sync_threshold_start));
84 DPU_REG_WRITE(c, PP_SYNC_WRCOUNT,
85 (te->start_pos + te->sync_threshold_start + 1));
90 static int dpu_hw_pp_poll_timeout_wr_ptr(struct dpu_hw_pingpong *pp,
93 struct dpu_hw_blk_reg_map *c;
101 rc = readl_poll_timeout(c->base_off + c->blk_off + PP_LINE_COUNT,
102 val, (val & 0xffff) >= 1, 10, timeout_us);
107 static int dpu_hw_pp_enable_te(struct dpu_hw_pingpong *pp, bool enable)
109 struct dpu_hw_blk_reg_map *c;
115 DPU_REG_WRITE(c, PP_TEAR_CHECK_EN, enable);
119 static int dpu_hw_pp_connect_external_te(struct dpu_hw_pingpong *pp,
120 bool enable_external_te)
122 struct dpu_hw_blk_reg_map *c = &pp->hw;
130 cfg = DPU_REG_READ(c, PP_SYNC_CONFIG_VSYNC);
131 orig = (bool)(cfg & BIT(20));
132 if (enable_external_te)
136 DPU_REG_WRITE(c, PP_SYNC_CONFIG_VSYNC, cfg);
137 trace_dpu_pp_connect_ext_te(pp->idx - PINGPONG_0, cfg);
142 static int dpu_hw_pp_get_vsync_info(struct dpu_hw_pingpong *pp,
143 struct dpu_hw_pp_vsync_info *info)
145 struct dpu_hw_blk_reg_map *c;
152 val = DPU_REG_READ(c, PP_VSYNC_INIT_VAL);
153 info->rd_ptr_init_val = val & 0xffff;
155 val = DPU_REG_READ(c, PP_INT_COUNT_VAL);
156 info->rd_ptr_frame_count = (val & 0xffff0000) >> 16;
157 info->rd_ptr_line_count = val & 0xffff;
159 val = DPU_REG_READ(c, PP_LINE_COUNT);
160 info->wr_ptr_line_count = val & 0xffff;
165 static u32 dpu_hw_pp_get_line_count(struct dpu_hw_pingpong *pp)
167 struct dpu_hw_blk_reg_map *c = &pp->hw;
175 init = DPU_REG_READ(c, PP_VSYNC_INIT_VAL) & 0xFFFF;
176 height = DPU_REG_READ(c, PP_SYNC_CONFIG_HEIGHT) & 0xFFFF;
181 line = DPU_REG_READ(c, PP_INT_COUNT_VAL) & 0xFFFF;
184 line += (0xFFFF - init);
191 static void _setup_pingpong_ops(struct dpu_hw_pingpong_ops *ops,
192 const struct dpu_pingpong_cfg *hw_cap)
194 ops->setup_tearcheck = dpu_hw_pp_setup_te_config;
195 ops->enable_tearcheck = dpu_hw_pp_enable_te;
196 ops->connect_external_te = dpu_hw_pp_connect_external_te;
197 ops->get_vsync_info = dpu_hw_pp_get_vsync_info;
198 ops->poll_timeout_wr_ptr = dpu_hw_pp_poll_timeout_wr_ptr;
199 ops->get_line_count = dpu_hw_pp_get_line_count;
202 static struct dpu_hw_blk_ops dpu_hw_ops;
204 struct dpu_hw_pingpong *dpu_hw_pingpong_init(enum dpu_pingpong idx,
206 struct dpu_mdss_cfg *m)
208 struct dpu_hw_pingpong *c;
209 struct dpu_pingpong_cfg *cfg;
211 c = kzalloc(sizeof(*c), GFP_KERNEL);
213 return ERR_PTR(-ENOMEM);
215 cfg = _pingpong_offset(idx, m, addr, &c->hw);
216 if (IS_ERR_OR_NULL(cfg)) {
218 return ERR_PTR(-EINVAL);
223 _setup_pingpong_ops(&c->ops, c->caps);
225 dpu_hw_blk_init(&c->base, DPU_HW_BLK_PINGPONG, idx, &dpu_hw_ops);
230 void dpu_hw_pingpong_destroy(struct dpu_hw_pingpong *pp)
233 dpu_hw_blk_destroy(&pp->base);