blob: a77b8d317b48de7f69479b3c59eb1f9ac9a9b2dc [file] [log] [blame]
Lloyd Atkinson77158732016-10-23 13:02:00 -04001/* Copyright (c) 2015-2017, The Linux Foundation. All rights reserved.
Narendra Muppalla1b0b3352015-09-29 10:16:51 -07002 *
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.
6 *
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.
11 */
12
13#include "sde_hw_mdss.h"
14#include "sde_hwio.h"
15#include "sde_hw_catalog.h"
16#include "sde_hw_pingpong.h"
Lloyd Atkinson113aefd2016-10-23 13:15:18 -040017#include "sde_dbg.h"
Narendra Muppalla1b0b3352015-09-29 10:16:51 -070018
19#define PP_TEAR_CHECK_EN 0x000
20#define PP_SYNC_CONFIG_VSYNC 0x004
21#define PP_SYNC_CONFIG_HEIGHT 0x008
22#define PP_SYNC_WRCOUNT 0x00C
23#define PP_VSYNC_INIT_VAL 0x010
24#define PP_INT_COUNT_VAL 0x014
25#define PP_SYNC_THRESH 0x018
26#define PP_START_POS 0x01C
27#define PP_RD_PTR_IRQ 0x020
28#define PP_WR_PTR_IRQ 0x024
29#define PP_OUT_LINE_COUNT 0x028
30#define PP_LINE_COUNT 0x02C
31#define PP_AUTOREFRESH_CONFIG 0x030
32
33#define PP_FBC_MODE 0x034
34#define PP_FBC_BUDGET_CTL 0x038
35#define PP_FBC_LOSSY_MODE 0x03C
36#define PP_DSC_MODE 0x0a0
37#define PP_DCE_DATA_IN_SWAP 0x0ac
38#define PP_DCE_DATA_OUT_SWAP 0x0c8
39
40static struct sde_pingpong_cfg *_pingpong_offset(enum sde_pingpong pp,
41 struct sde_mdss_cfg *m,
42 void __iomem *addr,
43 struct sde_hw_blk_reg_map *b)
44{
45 int i;
46
47 for (i = 0; i < m->pingpong_count; i++) {
48 if (pp == m->pingpong[i].id) {
49 b->base_off = addr;
50 b->blk_off = m->pingpong[i].base;
Lloyd Atkinson77158732016-10-23 13:02:00 -040051 b->length = m->pingpong[i].len;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -070052 b->hwversion = m->hwversion;
Clarence Ip4ce59322016-06-26 22:27:51 -040053 b->log_mask = SDE_DBG_MASK_PINGPONG;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -070054 return &m->pingpong[i];
55 }
56 }
57
58 return ERR_PTR(-EINVAL);
59}
60
61static int sde_hw_pp_setup_te_config(struct sde_hw_pingpong *pp,
62 struct sde_hw_tear_check *te)
63{
64 struct sde_hw_blk_reg_map *c = &pp->hw;
65 int cfg;
66
67 cfg = BIT(19); /*VSYNC_COUNTER_EN */
68 if (te->hw_vsync_mode)
69 cfg |= BIT(20);
70
71 cfg |= te->vsync_count;
72
73 SDE_REG_WRITE(c, PP_SYNC_CONFIG_VSYNC, cfg);
74 SDE_REG_WRITE(c, PP_SYNC_CONFIG_HEIGHT, te->sync_cfg_height);
75 SDE_REG_WRITE(c, PP_VSYNC_INIT_VAL, te->vsync_init_val);
76 SDE_REG_WRITE(c, PP_RD_PTR_IRQ, te->rd_ptr_irq);
77 SDE_REG_WRITE(c, PP_START_POS, te->start_pos);
78 SDE_REG_WRITE(c, PP_SYNC_THRESH,
79 ((te->sync_threshold_continue << 16) |
80 te->sync_threshold_start));
81 SDE_REG_WRITE(c, PP_SYNC_WRCOUNT,
82 (te->start_pos + te->sync_threshold_start + 1));
83
84 return 0;
85}
86
87int sde_hw_pp_setup_autorefresh_config(struct sde_hw_pingpong *pp,
88 struct sde_hw_autorefresh *cfg)
89{
90 struct sde_hw_blk_reg_map *c = &pp->hw;
91 u32 refresh_cfg;
92
93 if (cfg->enable)
94 refresh_cfg = BIT(31) | cfg->frame_count;
95 else
96 refresh_cfg = 0;
97
98 SDE_REG_WRITE(c, PP_AUTOREFRESH_CONFIG,
99 refresh_cfg);
100
101 return 0;
102}
103
Jeykumar Sankaran5c2f0702017-03-09 18:03:15 -0800104void sde_hw_pp_dsc_enable(struct sde_hw_pingpong *pp)
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700105{
Jeykumar Sankaran5c2f0702017-03-09 18:03:15 -0800106 struct sde_hw_blk_reg_map *c = &pp->hw;
107
108 SDE_REG_WRITE(c, PP_DSC_MODE, 1);
109}
110
111void sde_hw_pp_dsc_disable(struct sde_hw_pingpong *pp)
112{
113 struct sde_hw_blk_reg_map *c = &pp->hw;
114
115 SDE_REG_WRITE(c, PP_DSC_MODE, 0);
116}
117
118int sde_hw_pp_setup_dsc(struct sde_hw_pingpong *pp)
119{
120 struct sde_hw_blk_reg_map *pp_c = &pp->hw;
121 int data;
122
123 data = SDE_REG_READ(pp_c, PP_DCE_DATA_OUT_SWAP);
124 data |= BIT(18); /* endian flip */
125 SDE_REG_WRITE(pp_c, PP_DCE_DATA_OUT_SWAP, data);
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700126 return 0;
127}
Jeykumar Sankaran5c2f0702017-03-09 18:03:15 -0800128
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700129int sde_hw_pp_enable_te(struct sde_hw_pingpong *pp, bool enable)
130{
131 struct sde_hw_blk_reg_map *c = &pp->hw;
132
133 SDE_REG_WRITE(c, PP_TEAR_CHECK_EN, enable);
134 return 0;
135}
136
137int sde_hw_pp_get_vsync_info(struct sde_hw_pingpong *pp,
138 struct sde_hw_pp_vsync_info *info)
139{
140 struct sde_hw_blk_reg_map *c = &pp->hw;
Lloyd Atkinson3127a092016-05-30 13:46:55 -0400141 u32 val;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700142
Lloyd Atkinson3127a092016-05-30 13:46:55 -0400143 val = SDE_REG_READ(c, PP_VSYNC_INIT_VAL);
144 info->init_val = val & 0xffff;
145
146 val = SDE_REG_READ(c, PP_INT_COUNT_VAL);
147 info->vsync_count = (val & 0xffff0000) >> 16;
148 info->line_count = val & 0xffff;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700149
150 return 0;
151}
152
153static void _setup_pingpong_ops(struct sde_hw_pingpong_ops *ops,
154 unsigned long cap)
155{
156 ops->setup_tearcheck = sde_hw_pp_setup_te_config;
157 ops->enable_tearcheck = sde_hw_pp_enable_te;
158 ops->get_vsync_info = sde_hw_pp_get_vsync_info;
159 ops->setup_autorefresh = sde_hw_pp_setup_autorefresh_config;
Jeykumar Sankaran5c2f0702017-03-09 18:03:15 -0800160 ops->setup_dsc = sde_hw_pp_setup_dsc;
161 ops->enable_dsc = sde_hw_pp_dsc_enable;
162 ops->disable_dsc = sde_hw_pp_dsc_disable;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700163};
164
165struct sde_hw_pingpong *sde_hw_pingpong_init(enum sde_pingpong idx,
166 void __iomem *addr,
167 struct sde_mdss_cfg *m)
168{
169 struct sde_hw_pingpong *c;
170 struct sde_pingpong_cfg *cfg;
171
172 c = kzalloc(sizeof(*c), GFP_KERNEL);
173 if (!c)
174 return ERR_PTR(-ENOMEM);
175
176 cfg = _pingpong_offset(idx, m, addr, &c->hw);
177 if (IS_ERR_OR_NULL(cfg)) {
178 kfree(c);
179 return ERR_PTR(-EINVAL);
180 }
181
182 c->idx = idx;
183 c->pingpong_hw_cap = cfg;
184 _setup_pingpong_ops(&c->ops, c->pingpong_hw_cap->features);
185
Lloyd Atkinson113aefd2016-10-23 13:15:18 -0400186 sde_dbg_reg_register_dump_range(SDE_DBG_NAME, cfg->name, c->hw.blk_off,
187 c->hw.blk_off + c->hw.length, c->hw.xin_id);
188
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700189 return c;
190}
191
Lloyd Atkinson3127a092016-05-30 13:46:55 -0400192void sde_hw_pingpong_destroy(struct sde_hw_pingpong *pp)
193{
194 kfree(pp);
195}