blob: c1578df13722e374b2daeba8b179fb817e6437fa [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};
Dhaval Patelc4135d82016-03-30 17:40:53 -070044static char dsc_rc_range_min_qp_1_1[] = {0, 0, 1, 1, 3, 3, 3, 3, 3, 3, 5,
Kuogee Hsiehd58c8092015-07-07 10:31:34 -070045 5, 5, 7, 13};
Dhaval Patelc4135d82016-03-30 17:40:53 -070046static char dsc_rc_range_min_qp_1_1_scr1[] = {0, 0, 1, 1, 3, 3, 3, 3, 3, 3, 5,
47 5, 5, 9, 12};
48static char dsc_rc_range_max_qp_1_1[] = {4, 4, 5, 6, 7, 7, 7, 8, 9, 10, 11,
Kuogee Hsiehd58c8092015-07-07 10:31:34 -070049 12, 13, 13, 15};
Dhaval Patelc4135d82016-03-30 17:40:53 -070050static char dsc_rc_range_max_qp_1_1_scr1[] = {4, 4, 5, 6, 7, 7, 7, 8, 9, 10, 10,
51 11, 11, 12, 13};
Kuogee Hsiehd58c8092015-07-07 10:31:34 -070052static char dsc_rc_range_bpg_offset[] = {2, 0, 0, -2, -4, -6, -8, -8,
53 -8, -10, -10, -12, -12, -12, -12};
54
55#define CEIL(x, y) (((x) + ((y)-1)) / (y))
56
57int mdss_dsc_to_buf(struct msm_panel_info *pinfo)
58{
59 struct dsc_desc *dsc;
60 char *bp;
61 char data;
62 int i, bpp;
63
64 dsc = &pinfo->dsc;
65 bp = dsc->pps_buf;
66
67 *bp++ = 128; /* pps length */
68 *bp++ = 0;
69 *bp++ = 0x0a; /* PPS data type */
70 *bp++ = 0xc0; /* last + long pkt */
71
72 /* pps payload */
Dhaval Patelc68cba92016-03-30 17:34:55 -070073 *bp++ = (((dsc->major & 0xf) << 4) | (dsc->minor & 0xf)); /* pps0 */
74 *bp++ = (dsc->pps_id & 0xff); /* pps1 */
Kuogee Hsiehd58c8092015-07-07 10:31:34 -070075 bp++; /* pps2, reserved */
76
77 data = dsc->line_buf_depth & 0x0f;
Dhaval Patelc68cba92016-03-30 17:34:55 -070078 data |= ((dsc->bpc & 0xf) << 4);
Kuogee Hsiehd58c8092015-07-07 10:31:34 -070079 *bp++ = data; /* pps3 */
80
81 bpp = dsc->bpp;
82 bpp <<= 4; /* 4 fraction bits */
83 data = (bpp >> 8);
84 data &= 0x03; /* upper two bits */
Dhaval Patelc68cba92016-03-30 17:34:55 -070085 data |= ((dsc->block_pred_enable & 0x1) << 5);
86 data |= ((dsc->convert_rgb & 0x1) << 4);
87 data |= ((dsc->enable_422 & 0x1) << 3);
88 data |= ((dsc->vbr_enable & 0x1) << 2);
Kuogee Hsiehd58c8092015-07-07 10:31:34 -070089 *bp++ = data; /* pps4 */
90 *bp++ = bpp; /* pps5 */
91
Dhaval Patelc68cba92016-03-30 17:34:55 -070092 *bp++ = ((dsc->pic_height >> 8) & 0xff); /* pps6 */
Kuogee Hsiehd58c8092015-07-07 10:31:34 -070093 *bp++ = (dsc->pic_height & 0x0ff); /* pps7 */
Dhaval Patelc68cba92016-03-30 17:34:55 -070094 *bp++ = ((dsc->pic_width >> 8) & 0xff); /* pps8 */
Kuogee Hsiehd58c8092015-07-07 10:31:34 -070095 *bp++ = (dsc->pic_width & 0x0ff); /* pps9 */
96
Dhaval Patelc68cba92016-03-30 17:34:55 -070097 *bp++ = ((dsc->slice_height >> 8) & 0xff);/* pps10 */
Kuogee Hsiehd58c8092015-07-07 10:31:34 -070098 *bp++ = (dsc->slice_height & 0x0ff); /* pps11 */
Dhaval Patelc68cba92016-03-30 17:34:55 -070099 *bp++ = ((dsc->slice_width >> 8) & 0xff); /* pps12 */
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700100 *bp++ = (dsc->slice_width & 0x0ff); /* pps13 */
101
Dhaval Patelc68cba92016-03-30 17:34:55 -0700102 *bp++ = ((dsc->chunk_size >> 8) & 0xff);/* pps14 */
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700103 *bp++ = (dsc->chunk_size & 0x0ff); /* pps15 */
104
Dhaval Patelc68cba92016-03-30 17:34:55 -0700105 *bp++ = (dsc->initial_xmit_delay >> 8) & 0x3; /* pps16, bit 0, 1 */
106 *bp++ = (dsc->initial_xmit_delay & 0xff);/* pps17 */
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700107
Dhaval Patelc68cba92016-03-30 17:34:55 -0700108 *bp++ = ((dsc->initial_dec_delay >> 8) & 0xff); /* pps18 */
109 *bp++ = (dsc->initial_dec_delay & 0xff);/* pps19 */
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700110
111 bp++; /* pps20, reserved */
112
113 *bp++ = (dsc->initial_scale_value & 0x3f); /* pps21 */
114
Dhaval Patelc68cba92016-03-30 17:34:55 -0700115 *bp++ = ((dsc->scale_increment_interval >> 8) & 0xff); /* pps22 */
116 *bp++ = (dsc->scale_increment_interval & 0xff); /* pps23 */
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700117
Dhaval Patelc68cba92016-03-30 17:34:55 -0700118 *bp++ = ((dsc->scale_decrement_interval >> 8) & 0xf); /* pps24 */
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700119 *bp++ = (dsc->scale_decrement_interval & 0x0ff);/* pps25 */
120
121 bp++; /* pps26, reserved */
122
123 *bp++ = (dsc->first_line_bpg_offset & 0x1f);/* pps27 */
124
Dhaval Patelc68cba92016-03-30 17:34:55 -0700125 *bp++ = ((dsc->nfl_bpg_offset >> 8) & 0xff);/* pps28 */
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700126 *bp++ = (dsc->nfl_bpg_offset & 0x0ff); /* pps29 */
Dhaval Patelc68cba92016-03-30 17:34:55 -0700127 *bp++ = ((dsc->slice_bpg_offset >> 8) & 0xff);/* pps30 */
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700128 *bp++ = (dsc->slice_bpg_offset & 0x0ff);/* pps31 */
129
Dhaval Patelc68cba92016-03-30 17:34:55 -0700130 *bp++ = ((dsc->initial_offset >> 8) & 0xff);/* pps32 */
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700131 *bp++ = (dsc->initial_offset & 0x0ff); /* pps33 */
132
Dhaval Patelc68cba92016-03-30 17:34:55 -0700133 *bp++ = ((dsc->final_offset >> 8) & 0xff);/* pps34 */
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700134 *bp++ = (dsc->final_offset & 0x0ff); /* pps35 */
135
136 *bp++ = (dsc->min_qp_flatness & 0x1f); /* pps36 */
137 *bp++ = (dsc->max_qp_flatness & 0x1f); /* pps37 */
138
Dhaval Patelc68cba92016-03-30 17:34:55 -0700139 *bp++ = ((dsc->rc_model_size >> 8) & 0xff);/* pps38 */
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700140 *bp++ = (dsc->rc_model_size & 0x0ff); /* pps39 */
141
142 *bp++ = (dsc->edge_factor & 0x0f); /* pps40 */
143
144 *bp++ = (dsc->quant_incr_limit0 & 0x1f); /* pps41 */
145 *bp++ = (dsc->quant_incr_limit1 & 0x1f); /* pps42 */
146
Dhaval Patelc68cba92016-03-30 17:34:55 -0700147 data = ((dsc->tgt_offset_hi & 0xf) << 4);
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700148 data |= (dsc->tgt_offset_lo & 0x0f);
149 *bp++ = data; /* pps43 */
150
151 for (i = 0; i < 14; i++)
Dhaval Patelc68cba92016-03-30 17:34:55 -0700152 *bp++ = (dsc->buf_thresh[i] & 0xff);/* pps44 - pps57 */
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700153
154 for (i = 0; i < 15; i++) { /* pps58 - pps87 */
155 data = (dsc->range_min_qp[i] & 0x1f); /* 5 bits */
156 data <<= 3;
157 data |= ((dsc->range_max_qp[i] >> 2) & 0x07); /* 3 bits */
158 *bp++ = data;
159 data = (dsc->range_max_qp[i] & 0x03); /* 2 bits */
160 data <<= 6;
161 data |= (dsc->range_bpg_offset[i] & 0x3f); /* 6 bits */
162 *bp++ = data;
163 }
164
165 /* pps88 to pps127 are reserved */
166
167 return 128;
168}
169
170static int mdss_dsc_initial_line_calc(int bpc, int xmit_delay,
171 int slice_width, int slice_per_line)
172{
173 int ssm_delay;
174 int total_pixels;
175
176 ssm_delay = ((bpc < 10) ? 83 : 91);
177 total_pixels = ssm_delay * 3 + 30 + xmit_delay + 6;
178 total_pixels += ((slice_per_line > 1) ? (ssm_delay * 3) : 0);
179
180 return CEIL(total_pixels, slice_width);
181}
182
183void mdss_dsc_parameters_calc(struct msm_panel_info *pinfo)
184{
185 struct dsc_desc *dsc;
186 int bpp, bpc;
187 int mux_words_size;
188 int groups_per_line, groups_total;
189 int min_rate_buffer_size;
190 int hrd_delay;
191 int pre_num_extra_mux_bits, num_extra_mux_bits;
192 int slice_bits;
193 int target_bpp_x16;
194 int data;
195 int final_value, final_scale;
196 int slice_per_line, bytes_in_slice, total_bytes;
Dhaval Patelc4135d82016-03-30 17:40:53 -0700197 int version;
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700198
199 dsc = &pinfo->dsc;
Dhaval Patelc4135d82016-03-30 17:40:53 -0700200 version = (((dsc->major & 0xf) << 4) | (dsc->minor & 0xf));
201
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700202 dsc->rc_model_size = 8192; /* rate_buffer_size */
Dhaval Patelc4135d82016-03-30 17:40:53 -0700203 if (version == 0x11 && dsc->scr_rev == 0x1)
204 dsc->first_line_bpg_offset = 15;
205 else
206 dsc->first_line_bpg_offset = 12;
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700207 dsc->min_qp_flatness = 3;
208 dsc->max_qp_flatness = 12;
209 dsc->line_buf_depth = 9;
210
211 dsc->edge_factor = 6;
212 dsc->quant_incr_limit0 = 11;
213 dsc->quant_incr_limit1 = 11;
214 dsc->tgt_offset_hi = 3;
215 dsc->tgt_offset_lo = 3;
216
217 dsc->buf_thresh = dsc_rc_buf_thresh;
Dhaval Patelc4135d82016-03-30 17:40:53 -0700218 if (version == 0x11 && dsc->scr_rev == 0x1) {
219 dsc->range_min_qp = dsc_rc_range_min_qp_1_1_scr1;
220 dsc->range_max_qp = dsc_rc_range_max_qp_1_1_scr1;
221 } else {
222 dsc->range_min_qp = dsc_rc_range_min_qp_1_1;
223 dsc->range_max_qp = dsc_rc_range_max_qp_1_1;
224 }
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700225 dsc->range_bpg_offset = dsc_rc_range_bpg_offset;
226
Veera Sundaram Sankaran35f8ff32016-06-30 14:41:17 -0700227 if (pinfo->mipi.dual_dsi)
228 dsc->pic_width = pinfo->xres / 2;
229 else
230 dsc->pic_width = pinfo->xres;
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700231 dsc->pic_height = pinfo->yres;
232
233 bpp = dsc->bpp;
234 bpc = dsc->bpc;
235
236 if (bpp == 8)
237 dsc->initial_offset = 6144;
238 else
239 dsc->initial_offset = 2048; /* bpp = 12 */
240
241 if (bpc == 8)
242 mux_words_size = 48;
243 else
244 mux_words_size = 64; /* bpc == 12 */
245
246 slice_per_line = CEIL(dsc->pic_width, dsc->slice_width);
247
248 dsc->pkt_per_line = slice_per_line / dsc->slice_per_pkt;
249 if (slice_per_line % dsc->slice_per_pkt)
250 dsc->pkt_per_line = 1; /* default*/
251
252 bytes_in_slice = CEIL(dsc->pic_width, slice_per_line);
253
254 bytes_in_slice *= dsc->bpp; /* bites per compressed pixel */
255 bytes_in_slice = CEIL(bytes_in_slice, 8);
256
257 dsc->bytes_in_slice = bytes_in_slice;
258
259 dprintf(SPEW, "%s: slice_per_line=%d pkt_per_line=%d bytes_in_slice=%d\n",
260 __func__, slice_per_line, dsc->pkt_per_line, bytes_in_slice);
261
262 total_bytes = bytes_in_slice * slice_per_line;
263 dsc->eol_byte_num = total_bytes % 3;
264 dsc->pclk_per_line = CEIL(total_bytes, 3);
265
266 dsc->slice_last_group_size = 3 - dsc->eol_byte_num;
267
268 dprintf(SPEW, "%s: pclk_per_line=%d total_bytes=%d eol_byte_num=%d\n",
269 __func__, dsc->pclk_per_line, total_bytes, dsc->eol_byte_num);
270
271 dsc->bytes_per_pkt = bytes_in_slice * dsc->slice_per_pkt;
272
273 dsc->det_thresh_flatness = 7 + (bpc - 8);
274
275 dsc->initial_xmit_delay = dsc->rc_model_size / (2 * bpp);
276
277 dsc->initial_lines = mdss_dsc_initial_line_calc(bpc,
278 dsc->initial_xmit_delay, dsc->slice_width, slice_per_line);
279
280 groups_per_line = CEIL(dsc->slice_width, 3);
281
282 dsc->chunk_size = dsc->slice_width * bpp / 8;
283 if ((dsc->slice_width * bpp) % 8)
284 dsc->chunk_size++;
285
286
287 /* rbs-min */
288 min_rate_buffer_size = dsc->rc_model_size - dsc->initial_offset +
289 dsc->initial_xmit_delay * bpp +
290 groups_per_line * dsc->first_line_bpg_offset;
291
292 hrd_delay = CEIL(min_rate_buffer_size, bpp);
293
294 dsc->initial_dec_delay = hrd_delay - dsc->initial_xmit_delay;
295
296 dsc->initial_scale_value = 8 * dsc->rc_model_size /
297 (dsc->rc_model_size - dsc->initial_offset);
298
299 slice_bits = 8 * dsc->chunk_size * dsc->slice_height;
300
301 groups_total = groups_per_line * dsc->slice_height;
302
303 data = dsc->first_line_bpg_offset * 2048;
304
305 dsc->nfl_bpg_offset = CEIL(data, (dsc->slice_height - 1));
306
307 pre_num_extra_mux_bits = 3 * (mux_words_size + (4 * bpc + 4) - 2);
308
309 num_extra_mux_bits = pre_num_extra_mux_bits - (mux_words_size -
310 ((slice_bits - pre_num_extra_mux_bits) % mux_words_size));
311
312 data = 2048 * (dsc->rc_model_size - dsc->initial_offset
313 + num_extra_mux_bits);
314 dsc->slice_bpg_offset = CEIL(data, groups_total);
315
316 /* bpp * 16 + 0.5 */
317 data = bpp * 16;
318 data *= 2;
319 data++;
320 data /= 2;
321 target_bpp_x16 = data;
322
323 data = (dsc->initial_xmit_delay * target_bpp_x16) / 16;
324 final_value = dsc->rc_model_size - data + num_extra_mux_bits;
325
326 final_scale = 8 * dsc->rc_model_size /
327 (dsc->rc_model_size - final_value);
328
329 dsc->final_offset = final_value;
330
331 data = (final_scale - 9) * (dsc->nfl_bpg_offset +
332 dsc->slice_bpg_offset);
333 dsc->scale_increment_interval = (2048 * dsc->final_offset) / data;
334
335 dsc->scale_decrement_interval = groups_per_line /
336 (dsc->initial_scale_value - 8);
337
338 dprintf(SPEW, "%s: initial_xmit_delay=%d\n", __func__,
339 dsc->initial_xmit_delay);
340
341 dprintf(SPEW, "%s: bpg_offset, nfl=%d slice=%d\n", __func__,
342 dsc->nfl_bpg_offset, dsc->slice_bpg_offset);
343
344 dprintf(SPEW, "%s: groups_per_line=%d chunk_size=%d\n", __func__,
345 groups_per_line, dsc->chunk_size);
346 dprintf(SPEW, "%s:min_rate_buffer_size=%d hrd_delay=%d\n", __func__,
347 min_rate_buffer_size, hrd_delay);
348 dprintf(SPEW, "%s:initial_dec_delay=%d initial_scale_value=%d\n", __func__,
349 dsc->initial_dec_delay, dsc->initial_scale_value);
350 dprintf(SPEW, "%s:slice_bits=%d, groups_total=%d\n", __func__,
351 slice_bits, groups_total);
352 dprintf(SPEW, "%s: first_line_bgp_offset=%d slice_height=%d\n", __func__,
353 dsc->first_line_bpg_offset, dsc->slice_height);
354 dprintf(SPEW, "%s:final_value=%d final_scale=%d\n", __func__,
355 final_value, final_scale);
356 dprintf(SPEW, "%s: sacle_increment_interval=%d scale_decrement_interval=%d\n",
357 __func__, dsc->scale_increment_interval,
358 dsc->scale_decrement_interval);
359}
360
Ujwal Patel41a665a2015-07-17 13:51:30 -0700361void mdss_dsc_mdp_config(struct msm_panel_info *pinfo,
362 unsigned int pp_base, unsigned int dsc_base,
363 bool mux, bool split_mode)
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700364{
365 unsigned int data;
366 unsigned int offset, off;
367 struct dsc_desc *dsc;
368 char *lp;
369 char *cp;
370 int i, bpp, lsb;
371
372 /* dce0_sel->pp0, dce1_sel->pp1 */
373 writel(0x0, MDSS_MDP_REG_DCE_SEL);
374
375 /* dsc enable */
Ujwal Patel41a665a2015-07-17 13:51:30 -0700376 writel(1, pp_base + MDSS_MDP_PP_DSC_MODE);
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700377
Ujwal Patel41a665a2015-07-17 13:51:30 -0700378 data = readl(pp_base + MDSS_MDP_PP_DCE_DATA_OUT_SWAP);
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700379 data |= BIT(18); /* endian flip */
Ujwal Patel41a665a2015-07-17 13:51:30 -0700380 writel(data, pp_base + MDSS_MDP_PP_DCE_DATA_OUT_SWAP);
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700381
Ujwal Patel41a665a2015-07-17 13:51:30 -0700382 offset = dsc_base;
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700383
384 data = 0;
385 dsc = &pinfo->dsc;
386 if (pinfo->type == MIPI_VIDEO_PANEL)
387 data = BIT(2); /* video mode */
388
Ujwal Patel41a665a2015-07-17 13:51:30 -0700389 if (split_mode)
390 data |= BIT(0);
391 if (mux)
392 data |= BIT(1);
393
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700394 writel(data, offset + MDSS_MDP_DSC_COMMON_MODE);
395
Ujwal Patel1a897a22015-10-01 18:25:52 -0700396 data = (dsc->initial_lines << 20);
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700397 data |= ((dsc->slice_last_group_size - 1) << 18);
398
399 /* bpp is 6.4 format, 4 LSBs bits are for fractional part */
400 lsb = dsc->bpp % 4;
401 bpp = dsc->bpp / 4;
402 bpp *= 4; /* either 8 or 12 */
403 bpp <<= 4;
404 bpp |= lsb;
405 data |= (bpp << 8);
406 data |= (dsc->block_pred_enable << 7);
407 data |= (dsc->line_buf_depth << 3);
408 data |= (dsc->enable_422 << 2);
409 data |= (dsc->convert_rgb << 1);
410 data |= dsc->input_10_bits;
411
Ujwal Patel1a897a22015-10-01 18:25:52 -0700412 dprintf(SPEW, "%s: %d %d %d %d %d %d %d %d, data=%x\n",
413 __func__,
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700414 dsc->initial_lines , dsc->slice_last_group_size,
415 dsc->bpp, dsc->block_pred_enable, dsc->line_buf_depth,
416 dsc->enable_422, dsc->convert_rgb, dsc->input_10_bits, data);
417
418 writel(data, offset + MDSS_MDP_DSC_ENC);
419
420 data = dsc->pic_width << 16;
421 data |= dsc->pic_height;
422 writel(data, offset + MDSS_MDP_DSC_PICTURE);
423
424 data = dsc->slice_width << 16;
425 data |= dsc->slice_height;
426 writel(data, offset + MDSS_MDP_DSC_SLICE);
427
428 data = dsc->chunk_size << 16;
429 writel(data, offset + MDSS_MDP_DSC_CHUNK_SIZE);
430
431 dprintf(SPEW, "%s: pic_w=%d pic_h=%d, slice_h=%d slice_w=%d, chunk=%d\n",
432 __func__, dsc->pic_width, dsc->pic_height,
433 dsc->slice_width, dsc->slice_height, dsc->chunk_size);
434
435 data = dsc->initial_dec_delay << 16;
436 data |= dsc->initial_xmit_delay;
437 writel(data, offset + MDSS_MDP_DSC_DELAY);
438
439 data = dsc->initial_scale_value;
440 writel(data, offset + MDSS_MDP_DSC_SCALE_INITIAL);
441
442 data = dsc->scale_decrement_interval;
443 writel(data, offset + MDSS_MDP_DSC_SCALE_DEC_INTERVAL);
444
445 data = dsc->scale_increment_interval;
446 writel(data, offset + MDSS_MDP_DSC_SCALE_INC_INTERVAL);
447
448 data = dsc->first_line_bpg_offset;
449 writel(data, offset + MDSS_MDP_DSC_FIRST_LINE_BPG_OFFSET);
450
451 data = dsc->nfl_bpg_offset << 16;
452 data |= dsc->slice_bpg_offset;
453 writel(data, offset + MDSS_MDP_DSC_BPG_OFFSET);
454
455 data = dsc->initial_offset << 16;
456 data |= dsc->final_offset;
457 writel(data, offset + MDSS_MDP_DSC_DSC_OFFSET);
458
459 data = dsc->det_thresh_flatness << 10;
460 data |= dsc->max_qp_flatness << 5;
461 data |= dsc->min_qp_flatness;
462 writel(data, offset + MDSS_MDP_DSC_FLATNESS);
463
464 data = dsc->rc_model_size; /* rate_buffer_size */
465 writel(data, offset + MDSS_MDP_DSC_RC_MODEL_SIZE);
466
467 data = dsc->tgt_offset_lo << 18;
468 data |= dsc->tgt_offset_hi << 14;
469 data |= dsc->quant_incr_limit1 << 9;
470 data |= dsc->quant_incr_limit0 << 4;
471 data |= dsc->edge_factor;
472 writel(data, offset + MDSS_MDP_DSC_RC);
473
474 lp = dsc->buf_thresh;
475 off = offset + MDSS_MDP_DSC_RC_BUF_THRESH;
476 for (i = 0; i < 14; i++) {
477 writel(*lp++, off);
478 off += 4;
479 }
480
481 cp = dsc->range_min_qp;
482 off = offset + MDSS_MDP_DSC_RANGE_MIN_QP;
483 for (i = 0; i < 15; i++) {
484 writel(*cp++, off);
485 off += 4;
486 }
487
488 cp = dsc->range_max_qp;
489 off = offset + MDSS_MDP_DSC_RANGE_MAX_QP;
490 for (i = 0; i < 15; i++) {
491 writel(*cp++, off);
492 off += 4;
493 }
494
495 cp = dsc->range_bpg_offset;
496 off = offset + MDSS_MDP_DSC_RANGE_BPG_OFFSET;
497 for (i = 0; i < 15; i++) {
498 writel(*cp++, off);
499 off += 4;
500 }
501}
502
503void mdss_dsc_dsi_config(uint32_t ctl_base, int mode,
504 struct dsc_desc *dsc)
505{
506 unsigned int data;
507
508 if (mode == DSI_VIDEO_MODE) {
509 writel(0, ctl_base + VIDEO_COMPRESSION_MODE_CTRL_2);
510 data = dsc->bytes_per_pkt << 16;
511 data |= (0x0b << 8); /* dtype of compressed image */
512 data |= (dsc->pkt_per_line - 1) << 6;
513 data |= dsc->eol_byte_num << 4;
514 data |= 1; /* enable */
515
516 writel(data, ctl_base + VIDEO_COMPRESSION_MODE_CTRL);
517 } else {
518 /* strem 0 */
519 writel(0, ctl_base + CMD_COMPRESSION_MODE_CTRL_3);
520
521 data = dsc->bytes_in_slice;
522 writel(data, ctl_base + CMD_COMPRESSION_MODE_CTRL_2);
523
524 data = 0x39 << 8;
525 data |= (dsc->pkt_per_line - 1) << 6;
526 data |= dsc->eol_byte_num << 4;
527 data |= 1; /* enable */
528 writel(data, ctl_base + CMD_COMPRESSION_MODE_CTRL);
529 }
530}