blob: 4a575cb8acf48cba5d0a4d757a2ea8d5fe2051b3 [file] [log] [blame]
Dhaval Patelc68cba92016-03-30 17:34:55 -07001/* Copyright (c) 2015-2106, The Linux Foundation. All rights reserved.
Kuogee Hsiehd58c8092015-07-07 10:31:34 -07002 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are met:
5 * * Redistributions of source code must retain the above copyright
6 * notice, this list of conditions and the following disclaimer.
7 * * Redistributions in binary form must reproduce the above copyright
8 * notice, this list of conditions and the following disclaimer in the
9 * documentation and/or other materials provided with the distribution.
10 * * Neither the name of The Linux Foundation nor
11 * the names of its contributors may be used to endorse or promote
12 * products derived from this software without specific prior written
13 * permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include <debug.h>
29#include <mdp5.h>
30#include <reg.h>
31#include <bits.h>
32#include <msm_panel.h>
33#include <panel.h>
34#include <platform/iomap.h>
35#include <mipi_dsi.h>
36
37/*
38 * rc_buf_thresh = {896, 1792, 2688, 3548, 4480, 5376, 6272, 6720,
39 * 7168, 7616, 7744, 7872, 8000, 8064, 8192};
40 * (x >> 6) & 0x0ff)
41 */
42static char dsc_rc_buf_thresh[] = {0x0e, 0x1c, 0x2a, 0x38, 0x46, 0x54,
43 0x62, 0x69, 0x70, 0x77, 0x79, 0x7b, 0x7d, 0x7e};
44static char dsc_rc_range_min_qp[] = {0, 0, 1, 1, 3, 3, 3, 3, 3, 3, 5,
45 5, 5, 7, 13};
46static char dsc_rc_range_max_qp[] = {4, 4, 5, 6, 7, 7, 7, 8, 9, 10, 11,
47 12, 13, 13, 15};
48static char dsc_rc_range_bpg_offset[] = {2, 0, 0, -2, -4, -6, -8, -8,
49 -8, -10, -10, -12, -12, -12, -12};
50
51#define CEIL(x, y) (((x) + ((y)-1)) / (y))
52
53int mdss_dsc_to_buf(struct msm_panel_info *pinfo)
54{
55 struct dsc_desc *dsc;
56 char *bp;
57 char data;
58 int i, bpp;
59
60 dsc = &pinfo->dsc;
61 bp = dsc->pps_buf;
62
63 *bp++ = 128; /* pps length */
64 *bp++ = 0;
65 *bp++ = 0x0a; /* PPS data type */
66 *bp++ = 0xc0; /* last + long pkt */
67
68 /* pps payload */
Dhaval Patelc68cba92016-03-30 17:34:55 -070069 *bp++ = (((dsc->major & 0xf) << 4) | (dsc->minor & 0xf)); /* pps0 */
70 *bp++ = (dsc->pps_id & 0xff); /* pps1 */
Kuogee Hsiehd58c8092015-07-07 10:31:34 -070071 bp++; /* pps2, reserved */
72
73 data = dsc->line_buf_depth & 0x0f;
Dhaval Patelc68cba92016-03-30 17:34:55 -070074 data |= ((dsc->bpc & 0xf) << 4);
Kuogee Hsiehd58c8092015-07-07 10:31:34 -070075 *bp++ = data; /* pps3 */
76
77 bpp = dsc->bpp;
78 bpp <<= 4; /* 4 fraction bits */
79 data = (bpp >> 8);
80 data &= 0x03; /* upper two bits */
Dhaval Patelc68cba92016-03-30 17:34:55 -070081 data |= ((dsc->block_pred_enable & 0x1) << 5);
82 data |= ((dsc->convert_rgb & 0x1) << 4);
83 data |= ((dsc->enable_422 & 0x1) << 3);
84 data |= ((dsc->vbr_enable & 0x1) << 2);
Kuogee Hsiehd58c8092015-07-07 10:31:34 -070085 *bp++ = data; /* pps4 */
86 *bp++ = bpp; /* pps5 */
87
Dhaval Patelc68cba92016-03-30 17:34:55 -070088 *bp++ = ((dsc->pic_height >> 8) & 0xff); /* pps6 */
Kuogee Hsiehd58c8092015-07-07 10:31:34 -070089 *bp++ = (dsc->pic_height & 0x0ff); /* pps7 */
Dhaval Patelc68cba92016-03-30 17:34:55 -070090 *bp++ = ((dsc->pic_width >> 8) & 0xff); /* pps8 */
Kuogee Hsiehd58c8092015-07-07 10:31:34 -070091 *bp++ = (dsc->pic_width & 0x0ff); /* pps9 */
92
Dhaval Patelc68cba92016-03-30 17:34:55 -070093 *bp++ = ((dsc->slice_height >> 8) & 0xff);/* pps10 */
Kuogee Hsiehd58c8092015-07-07 10:31:34 -070094 *bp++ = (dsc->slice_height & 0x0ff); /* pps11 */
Dhaval Patelc68cba92016-03-30 17:34:55 -070095 *bp++ = ((dsc->slice_width >> 8) & 0xff); /* pps12 */
Kuogee Hsiehd58c8092015-07-07 10:31:34 -070096 *bp++ = (dsc->slice_width & 0x0ff); /* pps13 */
97
Dhaval Patelc68cba92016-03-30 17:34:55 -070098 *bp++ = ((dsc->chunk_size >> 8) & 0xff);/* pps14 */
Kuogee Hsiehd58c8092015-07-07 10:31:34 -070099 *bp++ = (dsc->chunk_size & 0x0ff); /* pps15 */
100
Dhaval Patelc68cba92016-03-30 17:34:55 -0700101 *bp++ = (dsc->initial_xmit_delay >> 8) & 0x3; /* pps16, bit 0, 1 */
102 *bp++ = (dsc->initial_xmit_delay & 0xff);/* pps17 */
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700103
Dhaval Patelc68cba92016-03-30 17:34:55 -0700104 *bp++ = ((dsc->initial_dec_delay >> 8) & 0xff); /* pps18 */
105 *bp++ = (dsc->initial_dec_delay & 0xff);/* pps19 */
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700106
107 bp++; /* pps20, reserved */
108
109 *bp++ = (dsc->initial_scale_value & 0x3f); /* pps21 */
110
Dhaval Patelc68cba92016-03-30 17:34:55 -0700111 *bp++ = ((dsc->scale_increment_interval >> 8) & 0xff); /* pps22 */
112 *bp++ = (dsc->scale_increment_interval & 0xff); /* pps23 */
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700113
Dhaval Patelc68cba92016-03-30 17:34:55 -0700114 *bp++ = ((dsc->scale_decrement_interval >> 8) & 0xf); /* pps24 */
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700115 *bp++ = (dsc->scale_decrement_interval & 0x0ff);/* pps25 */
116
117 bp++; /* pps26, reserved */
118
119 *bp++ = (dsc->first_line_bpg_offset & 0x1f);/* pps27 */
120
Dhaval Patelc68cba92016-03-30 17:34:55 -0700121 *bp++ = ((dsc->nfl_bpg_offset >> 8) & 0xff);/* pps28 */
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700122 *bp++ = (dsc->nfl_bpg_offset & 0x0ff); /* pps29 */
Dhaval Patelc68cba92016-03-30 17:34:55 -0700123 *bp++ = ((dsc->slice_bpg_offset >> 8) & 0xff);/* pps30 */
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700124 *bp++ = (dsc->slice_bpg_offset & 0x0ff);/* pps31 */
125
Dhaval Patelc68cba92016-03-30 17:34:55 -0700126 *bp++ = ((dsc->initial_offset >> 8) & 0xff);/* pps32 */
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700127 *bp++ = (dsc->initial_offset & 0x0ff); /* pps33 */
128
Dhaval Patelc68cba92016-03-30 17:34:55 -0700129 *bp++ = ((dsc->final_offset >> 8) & 0xff);/* pps34 */
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700130 *bp++ = (dsc->final_offset & 0x0ff); /* pps35 */
131
132 *bp++ = (dsc->min_qp_flatness & 0x1f); /* pps36 */
133 *bp++ = (dsc->max_qp_flatness & 0x1f); /* pps37 */
134
Dhaval Patelc68cba92016-03-30 17:34:55 -0700135 *bp++ = ((dsc->rc_model_size >> 8) & 0xff);/* pps38 */
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700136 *bp++ = (dsc->rc_model_size & 0x0ff); /* pps39 */
137
138 *bp++ = (dsc->edge_factor & 0x0f); /* pps40 */
139
140 *bp++ = (dsc->quant_incr_limit0 & 0x1f); /* pps41 */
141 *bp++ = (dsc->quant_incr_limit1 & 0x1f); /* pps42 */
142
Dhaval Patelc68cba92016-03-30 17:34:55 -0700143 data = ((dsc->tgt_offset_hi & 0xf) << 4);
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700144 data |= (dsc->tgt_offset_lo & 0x0f);
145 *bp++ = data; /* pps43 */
146
147 for (i = 0; i < 14; i++)
Dhaval Patelc68cba92016-03-30 17:34:55 -0700148 *bp++ = (dsc->buf_thresh[i] & 0xff);/* pps44 - pps57 */
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700149
150 for (i = 0; i < 15; i++) { /* pps58 - pps87 */
151 data = (dsc->range_min_qp[i] & 0x1f); /* 5 bits */
152 data <<= 3;
153 data |= ((dsc->range_max_qp[i] >> 2) & 0x07); /* 3 bits */
154 *bp++ = data;
155 data = (dsc->range_max_qp[i] & 0x03); /* 2 bits */
156 data <<= 6;
157 data |= (dsc->range_bpg_offset[i] & 0x3f); /* 6 bits */
158 *bp++ = data;
159 }
160
161 /* pps88 to pps127 are reserved */
162
163 return 128;
164}
165
166static int mdss_dsc_initial_line_calc(int bpc, int xmit_delay,
167 int slice_width, int slice_per_line)
168{
169 int ssm_delay;
170 int total_pixels;
171
172 ssm_delay = ((bpc < 10) ? 83 : 91);
173 total_pixels = ssm_delay * 3 + 30 + xmit_delay + 6;
174 total_pixels += ((slice_per_line > 1) ? (ssm_delay * 3) : 0);
175
176 return CEIL(total_pixels, slice_width);
177}
178
179void mdss_dsc_parameters_calc(struct msm_panel_info *pinfo)
180{
181 struct dsc_desc *dsc;
182 int bpp, bpc;
183 int mux_words_size;
184 int groups_per_line, groups_total;
185 int min_rate_buffer_size;
186 int hrd_delay;
187 int pre_num_extra_mux_bits, num_extra_mux_bits;
188 int slice_bits;
189 int target_bpp_x16;
190 int data;
191 int final_value, final_scale;
192 int slice_per_line, bytes_in_slice, total_bytes;
193
194 dsc = &pinfo->dsc;
195 dsc->rc_model_size = 8192; /* rate_buffer_size */
196 dsc->first_line_bpg_offset = 12;
197 dsc->min_qp_flatness = 3;
198 dsc->max_qp_flatness = 12;
199 dsc->line_buf_depth = 9;
200
201 dsc->edge_factor = 6;
202 dsc->quant_incr_limit0 = 11;
203 dsc->quant_incr_limit1 = 11;
204 dsc->tgt_offset_hi = 3;
205 dsc->tgt_offset_lo = 3;
206
207 dsc->buf_thresh = dsc_rc_buf_thresh;
208 dsc->range_min_qp = dsc_rc_range_min_qp;
209 dsc->range_max_qp = dsc_rc_range_max_qp;
210 dsc->range_bpg_offset = dsc_rc_range_bpg_offset;
211
212 dsc->pic_width = pinfo->xres;
213 dsc->pic_height = pinfo->yres;
214
215 bpp = dsc->bpp;
216 bpc = dsc->bpc;
217
218 if (bpp == 8)
219 dsc->initial_offset = 6144;
220 else
221 dsc->initial_offset = 2048; /* bpp = 12 */
222
223 if (bpc == 8)
224 mux_words_size = 48;
225 else
226 mux_words_size = 64; /* bpc == 12 */
227
228 slice_per_line = CEIL(dsc->pic_width, dsc->slice_width);
229
230 dsc->pkt_per_line = slice_per_line / dsc->slice_per_pkt;
231 if (slice_per_line % dsc->slice_per_pkt)
232 dsc->pkt_per_line = 1; /* default*/
233
234 bytes_in_slice = CEIL(dsc->pic_width, slice_per_line);
235
236 bytes_in_slice *= dsc->bpp; /* bites per compressed pixel */
237 bytes_in_slice = CEIL(bytes_in_slice, 8);
238
239 dsc->bytes_in_slice = bytes_in_slice;
240
241 dprintf(SPEW, "%s: slice_per_line=%d pkt_per_line=%d bytes_in_slice=%d\n",
242 __func__, slice_per_line, dsc->pkt_per_line, bytes_in_slice);
243
244 total_bytes = bytes_in_slice * slice_per_line;
245 dsc->eol_byte_num = total_bytes % 3;
246 dsc->pclk_per_line = CEIL(total_bytes, 3);
247
248 dsc->slice_last_group_size = 3 - dsc->eol_byte_num;
249
250 dprintf(SPEW, "%s: pclk_per_line=%d total_bytes=%d eol_byte_num=%d\n",
251 __func__, dsc->pclk_per_line, total_bytes, dsc->eol_byte_num);
252
253 dsc->bytes_per_pkt = bytes_in_slice * dsc->slice_per_pkt;
254
255 dsc->det_thresh_flatness = 7 + (bpc - 8);
256
257 dsc->initial_xmit_delay = dsc->rc_model_size / (2 * bpp);
258
259 dsc->initial_lines = mdss_dsc_initial_line_calc(bpc,
260 dsc->initial_xmit_delay, dsc->slice_width, slice_per_line);
261
262 groups_per_line = CEIL(dsc->slice_width, 3);
263
264 dsc->chunk_size = dsc->slice_width * bpp / 8;
265 if ((dsc->slice_width * bpp) % 8)
266 dsc->chunk_size++;
267
268
269 /* rbs-min */
270 min_rate_buffer_size = dsc->rc_model_size - dsc->initial_offset +
271 dsc->initial_xmit_delay * bpp +
272 groups_per_line * dsc->first_line_bpg_offset;
273
274 hrd_delay = CEIL(min_rate_buffer_size, bpp);
275
276 dsc->initial_dec_delay = hrd_delay - dsc->initial_xmit_delay;
277
278 dsc->initial_scale_value = 8 * dsc->rc_model_size /
279 (dsc->rc_model_size - dsc->initial_offset);
280
281 slice_bits = 8 * dsc->chunk_size * dsc->slice_height;
282
283 groups_total = groups_per_line * dsc->slice_height;
284
285 data = dsc->first_line_bpg_offset * 2048;
286
287 dsc->nfl_bpg_offset = CEIL(data, (dsc->slice_height - 1));
288
289 pre_num_extra_mux_bits = 3 * (mux_words_size + (4 * bpc + 4) - 2);
290
291 num_extra_mux_bits = pre_num_extra_mux_bits - (mux_words_size -
292 ((slice_bits - pre_num_extra_mux_bits) % mux_words_size));
293
294 data = 2048 * (dsc->rc_model_size - dsc->initial_offset
295 + num_extra_mux_bits);
296 dsc->slice_bpg_offset = CEIL(data, groups_total);
297
298 /* bpp * 16 + 0.5 */
299 data = bpp * 16;
300 data *= 2;
301 data++;
302 data /= 2;
303 target_bpp_x16 = data;
304
305 data = (dsc->initial_xmit_delay * target_bpp_x16) / 16;
306 final_value = dsc->rc_model_size - data + num_extra_mux_bits;
307
308 final_scale = 8 * dsc->rc_model_size /
309 (dsc->rc_model_size - final_value);
310
311 dsc->final_offset = final_value;
312
313 data = (final_scale - 9) * (dsc->nfl_bpg_offset +
314 dsc->slice_bpg_offset);
315 dsc->scale_increment_interval = (2048 * dsc->final_offset) / data;
316
317 dsc->scale_decrement_interval = groups_per_line /
318 (dsc->initial_scale_value - 8);
319
320 dprintf(SPEW, "%s: initial_xmit_delay=%d\n", __func__,
321 dsc->initial_xmit_delay);
322
323 dprintf(SPEW, "%s: bpg_offset, nfl=%d slice=%d\n", __func__,
324 dsc->nfl_bpg_offset, dsc->slice_bpg_offset);
325
326 dprintf(SPEW, "%s: groups_per_line=%d chunk_size=%d\n", __func__,
327 groups_per_line, dsc->chunk_size);
328 dprintf(SPEW, "%s:min_rate_buffer_size=%d hrd_delay=%d\n", __func__,
329 min_rate_buffer_size, hrd_delay);
330 dprintf(SPEW, "%s:initial_dec_delay=%d initial_scale_value=%d\n", __func__,
331 dsc->initial_dec_delay, dsc->initial_scale_value);
332 dprintf(SPEW, "%s:slice_bits=%d, groups_total=%d\n", __func__,
333 slice_bits, groups_total);
334 dprintf(SPEW, "%s: first_line_bgp_offset=%d slice_height=%d\n", __func__,
335 dsc->first_line_bpg_offset, dsc->slice_height);
336 dprintf(SPEW, "%s:final_value=%d final_scale=%d\n", __func__,
337 final_value, final_scale);
338 dprintf(SPEW, "%s: sacle_increment_interval=%d scale_decrement_interval=%d\n",
339 __func__, dsc->scale_increment_interval,
340 dsc->scale_decrement_interval);
341}
342
Ujwal Patel41a665a2015-07-17 13:51:30 -0700343void mdss_dsc_mdp_config(struct msm_panel_info *pinfo,
344 unsigned int pp_base, unsigned int dsc_base,
345 bool mux, bool split_mode)
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700346{
347 unsigned int data;
348 unsigned int offset, off;
349 struct dsc_desc *dsc;
350 char *lp;
351 char *cp;
352 int i, bpp, lsb;
353
354 /* dce0_sel->pp0, dce1_sel->pp1 */
355 writel(0x0, MDSS_MDP_REG_DCE_SEL);
356
357 /* dsc enable */
Ujwal Patel41a665a2015-07-17 13:51:30 -0700358 writel(1, pp_base + MDSS_MDP_PP_DSC_MODE);
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700359
Ujwal Patel41a665a2015-07-17 13:51:30 -0700360 data = readl(pp_base + MDSS_MDP_PP_DCE_DATA_OUT_SWAP);
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700361 data |= BIT(18); /* endian flip */
Ujwal Patel41a665a2015-07-17 13:51:30 -0700362 writel(data, pp_base + MDSS_MDP_PP_DCE_DATA_OUT_SWAP);
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700363
Ujwal Patel41a665a2015-07-17 13:51:30 -0700364 offset = dsc_base;
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700365
366 data = 0;
367 dsc = &pinfo->dsc;
368 if (pinfo->type == MIPI_VIDEO_PANEL)
369 data = BIT(2); /* video mode */
370
Ujwal Patel41a665a2015-07-17 13:51:30 -0700371 if (split_mode)
372 data |= BIT(0);
373 if (mux)
374 data |= BIT(1);
375
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700376 writel(data, offset + MDSS_MDP_DSC_COMMON_MODE);
377
Ujwal Patel1a897a22015-10-01 18:25:52 -0700378 data = (dsc->initial_lines << 20);
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700379 data |= ((dsc->slice_last_group_size - 1) << 18);
380
381 /* bpp is 6.4 format, 4 LSBs bits are for fractional part */
382 lsb = dsc->bpp % 4;
383 bpp = dsc->bpp / 4;
384 bpp *= 4; /* either 8 or 12 */
385 bpp <<= 4;
386 bpp |= lsb;
387 data |= (bpp << 8);
388 data |= (dsc->block_pred_enable << 7);
389 data |= (dsc->line_buf_depth << 3);
390 data |= (dsc->enable_422 << 2);
391 data |= (dsc->convert_rgb << 1);
392 data |= dsc->input_10_bits;
393
Ujwal Patel1a897a22015-10-01 18:25:52 -0700394 dprintf(SPEW, "%s: %d %d %d %d %d %d %d %d, data=%x\n",
395 __func__,
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700396 dsc->initial_lines , dsc->slice_last_group_size,
397 dsc->bpp, dsc->block_pred_enable, dsc->line_buf_depth,
398 dsc->enable_422, dsc->convert_rgb, dsc->input_10_bits, data);
399
400 writel(data, offset + MDSS_MDP_DSC_ENC);
401
402 data = dsc->pic_width << 16;
403 data |= dsc->pic_height;
404 writel(data, offset + MDSS_MDP_DSC_PICTURE);
405
406 data = dsc->slice_width << 16;
407 data |= dsc->slice_height;
408 writel(data, offset + MDSS_MDP_DSC_SLICE);
409
410 data = dsc->chunk_size << 16;
411 writel(data, offset + MDSS_MDP_DSC_CHUNK_SIZE);
412
413 dprintf(SPEW, "%s: pic_w=%d pic_h=%d, slice_h=%d slice_w=%d, chunk=%d\n",
414 __func__, dsc->pic_width, dsc->pic_height,
415 dsc->slice_width, dsc->slice_height, dsc->chunk_size);
416
417 data = dsc->initial_dec_delay << 16;
418 data |= dsc->initial_xmit_delay;
419 writel(data, offset + MDSS_MDP_DSC_DELAY);
420
421 data = dsc->initial_scale_value;
422 writel(data, offset + MDSS_MDP_DSC_SCALE_INITIAL);
423
424 data = dsc->scale_decrement_interval;
425 writel(data, offset + MDSS_MDP_DSC_SCALE_DEC_INTERVAL);
426
427 data = dsc->scale_increment_interval;
428 writel(data, offset + MDSS_MDP_DSC_SCALE_INC_INTERVAL);
429
430 data = dsc->first_line_bpg_offset;
431 writel(data, offset + MDSS_MDP_DSC_FIRST_LINE_BPG_OFFSET);
432
433 data = dsc->nfl_bpg_offset << 16;
434 data |= dsc->slice_bpg_offset;
435 writel(data, offset + MDSS_MDP_DSC_BPG_OFFSET);
436
437 data = dsc->initial_offset << 16;
438 data |= dsc->final_offset;
439 writel(data, offset + MDSS_MDP_DSC_DSC_OFFSET);
440
441 data = dsc->det_thresh_flatness << 10;
442 data |= dsc->max_qp_flatness << 5;
443 data |= dsc->min_qp_flatness;
444 writel(data, offset + MDSS_MDP_DSC_FLATNESS);
445
446 data = dsc->rc_model_size; /* rate_buffer_size */
447 writel(data, offset + MDSS_MDP_DSC_RC_MODEL_SIZE);
448
449 data = dsc->tgt_offset_lo << 18;
450 data |= dsc->tgt_offset_hi << 14;
451 data |= dsc->quant_incr_limit1 << 9;
452 data |= dsc->quant_incr_limit0 << 4;
453 data |= dsc->edge_factor;
454 writel(data, offset + MDSS_MDP_DSC_RC);
455
456 lp = dsc->buf_thresh;
457 off = offset + MDSS_MDP_DSC_RC_BUF_THRESH;
458 for (i = 0; i < 14; i++) {
459 writel(*lp++, off);
460 off += 4;
461 }
462
463 cp = dsc->range_min_qp;
464 off = offset + MDSS_MDP_DSC_RANGE_MIN_QP;
465 for (i = 0; i < 15; i++) {
466 writel(*cp++, off);
467 off += 4;
468 }
469
470 cp = dsc->range_max_qp;
471 off = offset + MDSS_MDP_DSC_RANGE_MAX_QP;
472 for (i = 0; i < 15; i++) {
473 writel(*cp++, off);
474 off += 4;
475 }
476
477 cp = dsc->range_bpg_offset;
478 off = offset + MDSS_MDP_DSC_RANGE_BPG_OFFSET;
479 for (i = 0; i < 15; i++) {
480 writel(*cp++, off);
481 off += 4;
482 }
483}
484
485void mdss_dsc_dsi_config(uint32_t ctl_base, int mode,
486 struct dsc_desc *dsc)
487{
488 unsigned int data;
489
490 if (mode == DSI_VIDEO_MODE) {
491 writel(0, ctl_base + VIDEO_COMPRESSION_MODE_CTRL_2);
492 data = dsc->bytes_per_pkt << 16;
493 data |= (0x0b << 8); /* dtype of compressed image */
494 data |= (dsc->pkt_per_line - 1) << 6;
495 data |= dsc->eol_byte_num << 4;
496 data |= 1; /* enable */
497
498 writel(data, ctl_base + VIDEO_COMPRESSION_MODE_CTRL);
499 } else {
500 /* strem 0 */
501 writel(0, ctl_base + CMD_COMPRESSION_MODE_CTRL_3);
502
503 data = dsc->bytes_in_slice;
504 writel(data, ctl_base + CMD_COMPRESSION_MODE_CTRL_2);
505
506 data = 0x39 << 8;
507 data |= (dsc->pkt_per_line - 1) << 6;
508 data |= dsc->eol_byte_num << 4;
509 data |= 1; /* enable */
510 writel(data, ctl_base + CMD_COMPRESSION_MODE_CTRL);
511 }
512}