blob: e6780033490d4e98aaa438d701b8e489c565fbda [file] [log] [blame]
Narendra Muppalla1b0b3352015-09-29 10:16:51 -07001/* Copyright (c) 2015-2016, The Linux Foundation. All rights reserved.
2 *
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"
17
18#define PP_TEAR_CHECK_EN 0x000
19#define PP_SYNC_CONFIG_VSYNC 0x004
20#define PP_SYNC_CONFIG_HEIGHT 0x008
21#define PP_SYNC_WRCOUNT 0x00C
22#define PP_VSYNC_INIT_VAL 0x010
23#define PP_INT_COUNT_VAL 0x014
24#define PP_SYNC_THRESH 0x018
25#define PP_START_POS 0x01C
26#define PP_RD_PTR_IRQ 0x020
27#define PP_WR_PTR_IRQ 0x024
28#define PP_OUT_LINE_COUNT 0x028
29#define PP_LINE_COUNT 0x02C
30#define PP_AUTOREFRESH_CONFIG 0x030
31
32#define PP_FBC_MODE 0x034
33#define PP_FBC_BUDGET_CTL 0x038
34#define PP_FBC_LOSSY_MODE 0x03C
35#define PP_DSC_MODE 0x0a0
36#define PP_DCE_DATA_IN_SWAP 0x0ac
37#define PP_DCE_DATA_OUT_SWAP 0x0c8
38
39static struct sde_pingpong_cfg *_pingpong_offset(enum sde_pingpong pp,
40 struct sde_mdss_cfg *m,
41 void __iomem *addr,
42 struct sde_hw_blk_reg_map *b)
43{
44 int i;
45
46 for (i = 0; i < m->pingpong_count; i++) {
47 if (pp == m->pingpong[i].id) {
48 b->base_off = addr;
49 b->blk_off = m->pingpong[i].base;
50 b->hwversion = m->hwversion;
51 return &m->pingpong[i];
52 }
53 }
54
55 return ERR_PTR(-EINVAL);
56}
57
58static int sde_hw_pp_setup_te_config(struct sde_hw_pingpong *pp,
59 struct sde_hw_tear_check *te)
60{
61 struct sde_hw_blk_reg_map *c = &pp->hw;
62 int cfg;
63
64 cfg = BIT(19); /*VSYNC_COUNTER_EN */
65 if (te->hw_vsync_mode)
66 cfg |= BIT(20);
67
68 cfg |= te->vsync_count;
69
70 SDE_REG_WRITE(c, PP_SYNC_CONFIG_VSYNC, cfg);
71 SDE_REG_WRITE(c, PP_SYNC_CONFIG_HEIGHT, te->sync_cfg_height);
72 SDE_REG_WRITE(c, PP_VSYNC_INIT_VAL, te->vsync_init_val);
73 SDE_REG_WRITE(c, PP_RD_PTR_IRQ, te->rd_ptr_irq);
74 SDE_REG_WRITE(c, PP_START_POS, te->start_pos);
75 SDE_REG_WRITE(c, PP_SYNC_THRESH,
76 ((te->sync_threshold_continue << 16) |
77 te->sync_threshold_start));
78 SDE_REG_WRITE(c, PP_SYNC_WRCOUNT,
79 (te->start_pos + te->sync_threshold_start + 1));
80
81 return 0;
82}
83
84int sde_hw_pp_setup_autorefresh_config(struct sde_hw_pingpong *pp,
85 struct sde_hw_autorefresh *cfg)
86{
87 struct sde_hw_blk_reg_map *c = &pp->hw;
88 u32 refresh_cfg;
89
90 if (cfg->enable)
91 refresh_cfg = BIT(31) | cfg->frame_count;
92 else
93 refresh_cfg = 0;
94
95 SDE_REG_WRITE(c, PP_AUTOREFRESH_CONFIG,
96 refresh_cfg);
97
98 return 0;
99}
100
101int sde_hw_pp_setup_dsc_compression(struct sde_hw_pingpong *pp,
102 struct sde_hw_dsc_cfg *cfg)
103{
104 return 0;
105}
106int sde_hw_pp_enable_te(struct sde_hw_pingpong *pp, bool enable)
107{
108 struct sde_hw_blk_reg_map *c = &pp->hw;
109
110 SDE_REG_WRITE(c, PP_TEAR_CHECK_EN, enable);
111 return 0;
112}
113
114int sde_hw_pp_get_vsync_info(struct sde_hw_pingpong *pp,
115 struct sde_hw_pp_vsync_info *info)
116{
117 struct sde_hw_blk_reg_map *c = &pp->hw;
118
119 info->init_val = SDE_REG_READ(c, PP_VSYNC_INIT_VAL) & 0xffff;
120 info->vsync_count = SDE_REG_READ(c, PP_SYNC_CONFIG_HEIGHT) & 0xffff;
121 info->line_count = SDE_REG_READ(c, PP_INT_COUNT_VAL) & 0xffff;
122
123 return 0;
124}
125
126static void _setup_pingpong_ops(struct sde_hw_pingpong_ops *ops,
127 unsigned long cap)
128{
129 ops->setup_tearcheck = sde_hw_pp_setup_te_config;
130 ops->enable_tearcheck = sde_hw_pp_enable_te;
131 ops->get_vsync_info = sde_hw_pp_get_vsync_info;
132 ops->setup_autorefresh = sde_hw_pp_setup_autorefresh_config;
133 ops->setup_dsc = sde_hw_pp_setup_dsc_compression;
134};
135
136struct sde_hw_pingpong *sde_hw_pingpong_init(enum sde_pingpong idx,
137 void __iomem *addr,
138 struct sde_mdss_cfg *m)
139{
140 struct sde_hw_pingpong *c;
141 struct sde_pingpong_cfg *cfg;
142
143 c = kzalloc(sizeof(*c), GFP_KERNEL);
144 if (!c)
145 return ERR_PTR(-ENOMEM);
146
147 cfg = _pingpong_offset(idx, m, addr, &c->hw);
148 if (IS_ERR_OR_NULL(cfg)) {
149 kfree(c);
150 return ERR_PTR(-EINVAL);
151 }
152
153 c->idx = idx;
154 c->pingpong_hw_cap = cfg;
155 _setup_pingpong_ops(&c->ops, c->pingpong_hw_cap->features);
156
157 return c;
158}
159