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"
21 #include "dpu_trace.h"
23 #define PP_TEAR_CHECK_EN 0x000
24 #define PP_SYNC_CONFIG_VSYNC 0x004
25 #define PP_SYNC_CONFIG_HEIGHT 0x008
26 #define PP_SYNC_WRCOUNT 0x00C
27 #define PP_VSYNC_INIT_VAL 0x010
28 #define PP_INT_COUNT_VAL 0x014
29 #define PP_SYNC_THRESH 0x018
30 #define PP_START_POS 0x01C
31 #define PP_RD_PTR_IRQ 0x020
32 #define PP_WR_PTR_IRQ 0x024
33 #define PP_OUT_LINE_COUNT 0x028
34 #define PP_LINE_COUNT 0x02C
36 #define PP_FBC_MODE 0x034
37 #define PP_FBC_BUDGET_CTL 0x038
38 #define PP_FBC_LOSSY_MODE 0x03C
40 static struct dpu_pingpong_cfg *_pingpong_offset(enum dpu_pingpong pp,
41 struct dpu_mdss_cfg *m,
43 struct dpu_hw_blk_reg_map *b)
47 for (i = 0; i < m->pingpong_count; i++) {
48 if (pp == m->pingpong[i].id) {
50 b->blk_off = m->pingpong[i].base;
51 b->length = m->pingpong[i].len;
52 b->hwversion = m->hwversion;
53 b->log_mask = DPU_DBG_MASK_PINGPONG;
54 return &m->pingpong[i];
58 return ERR_PTR(-EINVAL);
61 static int dpu_hw_pp_setup_te_config(struct dpu_hw_pingpong *pp,
62 struct dpu_hw_tear_check *te)
64 struct dpu_hw_blk_reg_map *c;
71 cfg = BIT(19); /*VSYNC_COUNTER_EN */
72 if (te->hw_vsync_mode)
75 cfg |= te->vsync_count;
77 DPU_REG_WRITE(c, PP_SYNC_CONFIG_VSYNC, cfg);
78 DPU_REG_WRITE(c, PP_SYNC_CONFIG_HEIGHT, te->sync_cfg_height);
79 DPU_REG_WRITE(c, PP_VSYNC_INIT_VAL, te->vsync_init_val);
80 DPU_REG_WRITE(c, PP_RD_PTR_IRQ, te->rd_ptr_irq);
81 DPU_REG_WRITE(c, PP_START_POS, te->start_pos);
82 DPU_REG_WRITE(c, PP_SYNC_THRESH,
83 ((te->sync_threshold_continue << 16) |
84 te->sync_threshold_start));
85 DPU_REG_WRITE(c, PP_SYNC_WRCOUNT,
86 (te->start_pos + te->sync_threshold_start + 1));
91 static int dpu_hw_pp_poll_timeout_wr_ptr(struct dpu_hw_pingpong *pp,
94 struct dpu_hw_blk_reg_map *c;
102 rc = readl_poll_timeout(c->base_off + c->blk_off + PP_LINE_COUNT,
103 val, (val & 0xffff) >= 1, 10, timeout_us);
108 static int dpu_hw_pp_enable_te(struct dpu_hw_pingpong *pp, bool enable)
110 struct dpu_hw_blk_reg_map *c;
116 DPU_REG_WRITE(c, PP_TEAR_CHECK_EN, enable);
120 static int dpu_hw_pp_connect_external_te(struct dpu_hw_pingpong *pp,
121 bool enable_external_te)
123 struct dpu_hw_blk_reg_map *c = &pp->hw;
131 cfg = DPU_REG_READ(c, PP_SYNC_CONFIG_VSYNC);
132 orig = (bool)(cfg & BIT(20));
133 if (enable_external_te)
137 DPU_REG_WRITE(c, PP_SYNC_CONFIG_VSYNC, cfg);
138 trace_dpu_pp_connect_ext_te(pp->idx - PINGPONG_0, cfg);
143 static int dpu_hw_pp_get_vsync_info(struct dpu_hw_pingpong *pp,
144 struct dpu_hw_pp_vsync_info *info)
146 struct dpu_hw_blk_reg_map *c;
153 val = DPU_REG_READ(c, PP_VSYNC_INIT_VAL);
154 info->rd_ptr_init_val = val & 0xffff;
156 val = DPU_REG_READ(c, PP_INT_COUNT_VAL);
157 info->rd_ptr_frame_count = (val & 0xffff0000) >> 16;
158 info->rd_ptr_line_count = val & 0xffff;
160 val = DPU_REG_READ(c, PP_LINE_COUNT);
161 info->wr_ptr_line_count = val & 0xffff;
166 static u32 dpu_hw_pp_get_line_count(struct dpu_hw_pingpong *pp)
168 struct dpu_hw_blk_reg_map *c = &pp->hw;
176 init = DPU_REG_READ(c, PP_VSYNC_INIT_VAL) & 0xFFFF;
177 height = DPU_REG_READ(c, PP_SYNC_CONFIG_HEIGHT) & 0xFFFF;
180 goto line_count_exit;
182 line = DPU_REG_READ(c, PP_INT_COUNT_VAL) & 0xFFFF;
185 line += (0xFFFF - init);
193 static void _setup_pingpong_ops(struct dpu_hw_pingpong_ops *ops,
194 const struct dpu_pingpong_cfg *hw_cap)
196 ops->setup_tearcheck = dpu_hw_pp_setup_te_config;
197 ops->enable_tearcheck = dpu_hw_pp_enable_te;
198 ops->connect_external_te = dpu_hw_pp_connect_external_te;
199 ops->get_vsync_info = dpu_hw_pp_get_vsync_info;
200 ops->poll_timeout_wr_ptr = dpu_hw_pp_poll_timeout_wr_ptr;
201 ops->get_line_count = dpu_hw_pp_get_line_count;
204 static struct dpu_hw_blk_ops dpu_hw_ops = {
209 struct dpu_hw_pingpong *dpu_hw_pingpong_init(enum dpu_pingpong idx,
211 struct dpu_mdss_cfg *m)
213 struct dpu_hw_pingpong *c;
214 struct dpu_pingpong_cfg *cfg;
217 c = kzalloc(sizeof(*c), GFP_KERNEL);
219 return ERR_PTR(-ENOMEM);
221 cfg = _pingpong_offset(idx, m, addr, &c->hw);
222 if (IS_ERR_OR_NULL(cfg)) {
224 return ERR_PTR(-EINVAL);
229 _setup_pingpong_ops(&c->ops, c->caps);
231 rc = dpu_hw_blk_init(&c->base, DPU_HW_BLK_PINGPONG, idx, &dpu_hw_ops);
233 DPU_ERROR("failed to init hw blk %d\n", rc);
245 void dpu_hw_pingpong_destroy(struct dpu_hw_pingpong *pp)
248 dpu_hw_blk_destroy(&pp->base);