• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Copyright (c) 2015-2018, The Linux Foundation. All rights reserved.
3  */
4 
5 #include "dpu_hwio.h"
6 #include "dpu_hw_catalog.h"
7 #include "dpu_hw_intf.h"
8 #include "dpu_kms.h"
9 
10 #define INTF_TIMING_ENGINE_EN           0x000
11 #define INTF_CONFIG                     0x004
12 #define INTF_HSYNC_CTL                  0x008
13 #define INTF_VSYNC_PERIOD_F0            0x00C
14 #define INTF_VSYNC_PERIOD_F1            0x010
15 #define INTF_VSYNC_PULSE_WIDTH_F0       0x014
16 #define INTF_VSYNC_PULSE_WIDTH_F1       0x018
17 #define INTF_DISPLAY_V_START_F0         0x01C
18 #define INTF_DISPLAY_V_START_F1         0x020
19 #define INTF_DISPLAY_V_END_F0           0x024
20 #define INTF_DISPLAY_V_END_F1           0x028
21 #define INTF_ACTIVE_V_START_F0          0x02C
22 #define INTF_ACTIVE_V_START_F1          0x030
23 #define INTF_ACTIVE_V_END_F0            0x034
24 #define INTF_ACTIVE_V_END_F1            0x038
25 #define INTF_DISPLAY_HCTL               0x03C
26 #define INTF_ACTIVE_HCTL                0x040
27 #define INTF_BORDER_COLOR               0x044
28 #define INTF_UNDERFLOW_COLOR            0x048
29 #define INTF_HSYNC_SKEW                 0x04C
30 #define INTF_POLARITY_CTL               0x050
31 #define INTF_TEST_CTL                   0x054
32 #define INTF_TP_COLOR0                  0x058
33 #define INTF_TP_COLOR1                  0x05C
34 #define INTF_FRAME_LINE_COUNT_EN        0x0A8
35 #define INTF_FRAME_COUNT                0x0AC
36 #define   INTF_LINE_COUNT               0x0B0
37 
38 #define   INTF_DEFLICKER_CONFIG         0x0F0
39 #define   INTF_DEFLICKER_STRNG_COEFF    0x0F4
40 #define   INTF_DEFLICKER_WEAK_COEFF     0x0F8
41 
42 #define   INTF_DSI_CMD_MODE_TRIGGER_EN  0x084
43 #define   INTF_PANEL_FORMAT             0x090
44 #define   INTF_TPG_ENABLE               0x100
45 #define   INTF_TPG_MAIN_CONTROL         0x104
46 #define   INTF_TPG_VIDEO_CONFIG         0x108
47 #define   INTF_TPG_COMPONENT_LIMITS     0x10C
48 #define   INTF_TPG_RECTANGLE            0x110
49 #define   INTF_TPG_INITIAL_VALUE        0x114
50 #define   INTF_TPG_BLK_WHITE_PATTERN_FRAMES   0x118
51 #define   INTF_TPG_RGB_MAPPING          0x11C
52 #define   INTF_PROG_FETCH_START         0x170
53 #define   INTF_PROG_ROT_START           0x174
54 
55 #define   INTF_FRAME_LINE_COUNT_EN      0x0A8
56 #define   INTF_FRAME_COUNT              0x0AC
57 #define   INTF_LINE_COUNT               0x0B0
58 
59 #define   INTF_MUX                      0x25C
60 
_intf_offset(enum dpu_intf intf,const struct dpu_mdss_cfg * m,void __iomem * addr,struct dpu_hw_blk_reg_map * b)61 static const struct dpu_intf_cfg *_intf_offset(enum dpu_intf intf,
62 		const struct dpu_mdss_cfg *m,
63 		void __iomem *addr,
64 		struct dpu_hw_blk_reg_map *b)
65 {
66 	int i;
67 
68 	for (i = 0; i < m->intf_count; i++) {
69 		if ((intf == m->intf[i].id) &&
70 		(m->intf[i].type != INTF_NONE)) {
71 			b->base_off = addr;
72 			b->blk_off = m->intf[i].base;
73 			b->length = m->intf[i].len;
74 			b->hwversion = m->hwversion;
75 			b->log_mask = DPU_DBG_MASK_INTF;
76 			return &m->intf[i];
77 		}
78 	}
79 
80 	return ERR_PTR(-EINVAL);
81 }
82 
dpu_hw_intf_setup_timing_engine(struct dpu_hw_intf * ctx,const struct intf_timing_params * p,const struct dpu_format * fmt)83 static void dpu_hw_intf_setup_timing_engine(struct dpu_hw_intf *ctx,
84 		const struct intf_timing_params *p,
85 		const struct dpu_format *fmt)
86 {
87 	struct dpu_hw_blk_reg_map *c = &ctx->hw;
88 	u32 hsync_period, vsync_period;
89 	u32 display_v_start, display_v_end;
90 	u32 hsync_start_x, hsync_end_x;
91 	u32 active_h_start, active_h_end;
92 	u32 active_v_start, active_v_end;
93 	u32 active_hctl, display_hctl, hsync_ctl;
94 	u32 polarity_ctl, den_polarity, hsync_polarity, vsync_polarity;
95 	u32 panel_format;
96 	u32 intf_cfg;
97 
98 	/* read interface_cfg */
99 	intf_cfg = DPU_REG_READ(c, INTF_CONFIG);
100 	hsync_period = p->hsync_pulse_width + p->h_back_porch + p->width +
101 	p->h_front_porch;
102 	vsync_period = p->vsync_pulse_width + p->v_back_porch + p->height +
103 	p->v_front_porch;
104 
105 	display_v_start = ((p->vsync_pulse_width + p->v_back_porch) *
106 	hsync_period) + p->hsync_skew;
107 	display_v_end = ((vsync_period - p->v_front_porch) * hsync_period) +
108 	p->hsync_skew - 1;
109 
110 	hsync_start_x = p->h_back_porch + p->hsync_pulse_width;
111 	hsync_end_x = hsync_period - p->h_front_porch - 1;
112 
113 	if (p->width != p->xres) {
114 		active_h_start = hsync_start_x;
115 		active_h_end = active_h_start + p->xres - 1;
116 	} else {
117 		active_h_start = 0;
118 		active_h_end = 0;
119 	}
120 
121 	if (p->height != p->yres) {
122 		active_v_start = display_v_start;
123 		active_v_end = active_v_start + (p->yres * hsync_period) - 1;
124 	} else {
125 		active_v_start = 0;
126 		active_v_end = 0;
127 	}
128 
129 	if (active_h_end) {
130 		active_hctl = (active_h_end << 16) | active_h_start;
131 		intf_cfg |= BIT(29);	/* ACTIVE_H_ENABLE */
132 	} else {
133 		active_hctl = 0;
134 	}
135 
136 	if (active_v_end)
137 		intf_cfg |= BIT(30); /* ACTIVE_V_ENABLE */
138 
139 	hsync_ctl = (hsync_period << 16) | p->hsync_pulse_width;
140 	display_hctl = (hsync_end_x << 16) | hsync_start_x;
141 
142 	if (ctx->cap->type == INTF_EDP || ctx->cap->type == INTF_DP) {
143 		active_h_start = hsync_start_x;
144 		active_h_end = active_h_start + p->xres - 1;
145 		active_v_start = display_v_start;
146 		active_v_end = active_v_start + (p->yres * hsync_period) - 1;
147 
148 		display_v_start += p->hsync_pulse_width + p->h_back_porch;
149 		display_v_end   -= p->h_front_porch;
150 
151 		active_hctl = (active_h_end << 16) | active_h_start;
152 		display_hctl = active_hctl;
153 	}
154 
155 	den_polarity = 0;
156 	if (ctx->cap->type == INTF_HDMI) {
157 		hsync_polarity = p->yres >= 720 ? 0 : 1;
158 		vsync_polarity = p->yres >= 720 ? 0 : 1;
159 	} else if (ctx->cap->type == INTF_DP) {
160 		hsync_polarity = p->hsync_polarity;
161 		vsync_polarity = p->vsync_polarity;
162 	} else {
163 		hsync_polarity = 0;
164 		vsync_polarity = 0;
165 	}
166 	polarity_ctl = (den_polarity << 2) | /*  DEN Polarity  */
167 		(vsync_polarity << 1) | /* VSYNC Polarity */
168 		(hsync_polarity << 0);  /* HSYNC Polarity */
169 
170 	if (!DPU_FORMAT_IS_YUV(fmt))
171 		panel_format = (fmt->bits[C0_G_Y] |
172 				(fmt->bits[C1_B_Cb] << 2) |
173 				(fmt->bits[C2_R_Cr] << 4) |
174 				(0x21 << 8));
175 	else
176 		/* Interface treats all the pixel data in RGB888 format */
177 		panel_format = (COLOR_8BIT |
178 				(COLOR_8BIT << 2) |
179 				(COLOR_8BIT << 4) |
180 				(0x21 << 8));
181 
182 	DPU_REG_WRITE(c, INTF_HSYNC_CTL, hsync_ctl);
183 	DPU_REG_WRITE(c, INTF_VSYNC_PERIOD_F0, vsync_period * hsync_period);
184 	DPU_REG_WRITE(c, INTF_VSYNC_PULSE_WIDTH_F0,
185 			p->vsync_pulse_width * hsync_period);
186 	DPU_REG_WRITE(c, INTF_DISPLAY_HCTL, display_hctl);
187 	DPU_REG_WRITE(c, INTF_DISPLAY_V_START_F0, display_v_start);
188 	DPU_REG_WRITE(c, INTF_DISPLAY_V_END_F0, display_v_end);
189 	DPU_REG_WRITE(c, INTF_ACTIVE_HCTL,  active_hctl);
190 	DPU_REG_WRITE(c, INTF_ACTIVE_V_START_F0, active_v_start);
191 	DPU_REG_WRITE(c, INTF_ACTIVE_V_END_F0, active_v_end);
192 	DPU_REG_WRITE(c, INTF_BORDER_COLOR, p->border_clr);
193 	DPU_REG_WRITE(c, INTF_UNDERFLOW_COLOR, p->underflow_clr);
194 	DPU_REG_WRITE(c, INTF_HSYNC_SKEW, p->hsync_skew);
195 	DPU_REG_WRITE(c, INTF_POLARITY_CTL, polarity_ctl);
196 	DPU_REG_WRITE(c, INTF_FRAME_LINE_COUNT_EN, 0x3);
197 	DPU_REG_WRITE(c, INTF_CONFIG, intf_cfg);
198 	DPU_REG_WRITE(c, INTF_PANEL_FORMAT, panel_format);
199 }
200 
dpu_hw_intf_enable_timing_engine(struct dpu_hw_intf * intf,u8 enable)201 static void dpu_hw_intf_enable_timing_engine(
202 		struct dpu_hw_intf *intf,
203 		u8 enable)
204 {
205 	struct dpu_hw_blk_reg_map *c = &intf->hw;
206 	/* Note: Display interface select is handled in top block hw layer */
207 	DPU_REG_WRITE(c, INTF_TIMING_ENGINE_EN, enable != 0);
208 }
209 
dpu_hw_intf_setup_prg_fetch(struct dpu_hw_intf * intf,const struct intf_prog_fetch * fetch)210 static void dpu_hw_intf_setup_prg_fetch(
211 		struct dpu_hw_intf *intf,
212 		const struct intf_prog_fetch *fetch)
213 {
214 	struct dpu_hw_blk_reg_map *c = &intf->hw;
215 	int fetch_enable;
216 
217 	/*
218 	 * Fetch should always be outside the active lines. If the fetching
219 	 * is programmed within active region, hardware behavior is unknown.
220 	 */
221 
222 	fetch_enable = DPU_REG_READ(c, INTF_CONFIG);
223 	if (fetch->enable) {
224 		fetch_enable |= BIT(31);
225 		DPU_REG_WRITE(c, INTF_PROG_FETCH_START,
226 				fetch->fetch_start);
227 	} else {
228 		fetch_enable &= ~BIT(31);
229 	}
230 
231 	DPU_REG_WRITE(c, INTF_CONFIG, fetch_enable);
232 }
233 
dpu_hw_intf_bind_pingpong_blk(struct dpu_hw_intf * intf,bool enable,const enum dpu_pingpong pp)234 static void dpu_hw_intf_bind_pingpong_blk(
235 		struct dpu_hw_intf *intf,
236 		bool enable,
237 		const enum dpu_pingpong pp)
238 {
239 	struct dpu_hw_blk_reg_map *c = &intf->hw;
240 	u32 mux_cfg;
241 
242 	mux_cfg = DPU_REG_READ(c, INTF_MUX);
243 	mux_cfg &= ~0xf;
244 
245 	if (enable)
246 		mux_cfg |= (pp - PINGPONG_0) & 0x7;
247 	else
248 		mux_cfg |= 0xf;
249 
250 	DPU_REG_WRITE(c, INTF_MUX, mux_cfg);
251 }
252 
dpu_hw_intf_get_status(struct dpu_hw_intf * intf,struct intf_status * s)253 static void dpu_hw_intf_get_status(
254 		struct dpu_hw_intf *intf,
255 		struct intf_status *s)
256 {
257 	struct dpu_hw_blk_reg_map *c = &intf->hw;
258 
259 	s->is_en = DPU_REG_READ(c, INTF_TIMING_ENGINE_EN);
260 	if (s->is_en) {
261 		s->frame_count = DPU_REG_READ(c, INTF_FRAME_COUNT);
262 		s->line_count = DPU_REG_READ(c, INTF_LINE_COUNT);
263 	} else {
264 		s->line_count = 0;
265 		s->frame_count = 0;
266 	}
267 }
268 
dpu_hw_intf_get_line_count(struct dpu_hw_intf * intf)269 static u32 dpu_hw_intf_get_line_count(struct dpu_hw_intf *intf)
270 {
271 	struct dpu_hw_blk_reg_map *c;
272 
273 	if (!intf)
274 		return 0;
275 
276 	c = &intf->hw;
277 
278 	return DPU_REG_READ(c, INTF_LINE_COUNT);
279 }
280 
_setup_intf_ops(struct dpu_hw_intf_ops * ops,unsigned long cap)281 static void _setup_intf_ops(struct dpu_hw_intf_ops *ops,
282 		unsigned long cap)
283 {
284 	ops->setup_timing_gen = dpu_hw_intf_setup_timing_engine;
285 	ops->setup_prg_fetch  = dpu_hw_intf_setup_prg_fetch;
286 	ops->get_status = dpu_hw_intf_get_status;
287 	ops->enable_timing = dpu_hw_intf_enable_timing_engine;
288 	ops->get_line_count = dpu_hw_intf_get_line_count;
289 	if (cap & BIT(DPU_INTF_INPUT_CTRL))
290 		ops->bind_pingpong_blk = dpu_hw_intf_bind_pingpong_blk;
291 }
292 
293 static struct dpu_hw_blk_ops dpu_hw_ops;
294 
dpu_hw_intf_init(enum dpu_intf idx,void __iomem * addr,const struct dpu_mdss_cfg * m)295 struct dpu_hw_intf *dpu_hw_intf_init(enum dpu_intf idx,
296 		void __iomem *addr,
297 		const struct dpu_mdss_cfg *m)
298 {
299 	struct dpu_hw_intf *c;
300 	const struct dpu_intf_cfg *cfg;
301 
302 	c = kzalloc(sizeof(*c), GFP_KERNEL);
303 	if (!c)
304 		return ERR_PTR(-ENOMEM);
305 
306 	cfg = _intf_offset(idx, m, addr, &c->hw);
307 	if (IS_ERR_OR_NULL(cfg)) {
308 		kfree(c);
309 		pr_err("failed to create dpu_hw_intf %d\n", idx);
310 		return ERR_PTR(-EINVAL);
311 	}
312 
313 	/*
314 	 * Assign ops
315 	 */
316 	c->idx = idx;
317 	c->cap = cfg;
318 	c->mdss = m;
319 	_setup_intf_ops(&c->ops, c->cap->features);
320 
321 	dpu_hw_blk_init(&c->base, DPU_HW_BLK_INTF, idx, &dpu_hw_ops);
322 
323 	return c;
324 }
325 
dpu_hw_intf_destroy(struct dpu_hw_intf * intf)326 void dpu_hw_intf_destroy(struct dpu_hw_intf *intf)
327 {
328 	if (intf)
329 		dpu_hw_blk_destroy(&intf->base);
330 	kfree(intf);
331 }
332 
333