1*fbb6c848SEzequiel Garcia // SPDX-License-Identifier: GPL-2.0
2*fbb6c848SEzequiel Garcia /*
3*fbb6c848SEzequiel Garcia * Hantro VPU codec driver
4*fbb6c848SEzequiel Garcia *
5*fbb6c848SEzequiel Garcia * Copyright (C) 2018 Rockchip Electronics Co., Ltd.
6*fbb6c848SEzequiel Garcia */
7*fbb6c848SEzequiel Garcia
8*fbb6c848SEzequiel Garcia #include "hantro.h"
9*fbb6c848SEzequiel Garcia
10*fbb6c848SEzequiel Garcia static const u8 zigzag[64] = {
11*fbb6c848SEzequiel Garcia 0, 1, 8, 16, 9, 2, 3, 10,
12*fbb6c848SEzequiel Garcia 17, 24, 32, 25, 18, 11, 4, 5,
13*fbb6c848SEzequiel Garcia 12, 19, 26, 33, 40, 48, 41, 34,
14*fbb6c848SEzequiel Garcia 27, 20, 13, 6, 7, 14, 21, 28,
15*fbb6c848SEzequiel Garcia 35, 42, 49, 56, 57, 50, 43, 36,
16*fbb6c848SEzequiel Garcia 29, 22, 15, 23, 30, 37, 44, 51,
17*fbb6c848SEzequiel Garcia 58, 59, 52, 45, 38, 31, 39, 46,
18*fbb6c848SEzequiel Garcia 53, 60, 61, 54, 47, 55, 62, 63
19*fbb6c848SEzequiel Garcia };
20*fbb6c848SEzequiel Garcia
hantro_mpeg2_dec_copy_qtable(u8 * qtable,const struct v4l2_ctrl_mpeg2_quantisation * ctrl)21*fbb6c848SEzequiel Garcia void hantro_mpeg2_dec_copy_qtable(u8 *qtable,
22*fbb6c848SEzequiel Garcia const struct v4l2_ctrl_mpeg2_quantisation *ctrl)
23*fbb6c848SEzequiel Garcia {
24*fbb6c848SEzequiel Garcia int i, n;
25*fbb6c848SEzequiel Garcia
26*fbb6c848SEzequiel Garcia if (!qtable || !ctrl)
27*fbb6c848SEzequiel Garcia return;
28*fbb6c848SEzequiel Garcia
29*fbb6c848SEzequiel Garcia for (i = 0; i < ARRAY_SIZE(zigzag); i++) {
30*fbb6c848SEzequiel Garcia n = zigzag[i];
31*fbb6c848SEzequiel Garcia qtable[n + 0] = ctrl->intra_quantiser_matrix[i];
32*fbb6c848SEzequiel Garcia qtable[n + 64] = ctrl->non_intra_quantiser_matrix[i];
33*fbb6c848SEzequiel Garcia qtable[n + 128] = ctrl->chroma_intra_quantiser_matrix[i];
34*fbb6c848SEzequiel Garcia qtable[n + 192] = ctrl->chroma_non_intra_quantiser_matrix[i];
35*fbb6c848SEzequiel Garcia }
36*fbb6c848SEzequiel Garcia }
37*fbb6c848SEzequiel Garcia
hantro_mpeg2_dec_init(struct hantro_ctx * ctx)38*fbb6c848SEzequiel Garcia int hantro_mpeg2_dec_init(struct hantro_ctx *ctx)
39*fbb6c848SEzequiel Garcia {
40*fbb6c848SEzequiel Garcia struct hantro_dev *vpu = ctx->dev;
41*fbb6c848SEzequiel Garcia
42*fbb6c848SEzequiel Garcia ctx->mpeg2_dec.qtable.size = ARRAY_SIZE(zigzag) * 4;
43*fbb6c848SEzequiel Garcia ctx->mpeg2_dec.qtable.cpu =
44*fbb6c848SEzequiel Garcia dma_alloc_coherent(vpu->dev,
45*fbb6c848SEzequiel Garcia ctx->mpeg2_dec.qtable.size,
46*fbb6c848SEzequiel Garcia &ctx->mpeg2_dec.qtable.dma,
47*fbb6c848SEzequiel Garcia GFP_KERNEL);
48*fbb6c848SEzequiel Garcia if (!ctx->mpeg2_dec.qtable.cpu)
49*fbb6c848SEzequiel Garcia return -ENOMEM;
50*fbb6c848SEzequiel Garcia return 0;
51*fbb6c848SEzequiel Garcia }
52*fbb6c848SEzequiel Garcia
hantro_mpeg2_dec_exit(struct hantro_ctx * ctx)53*fbb6c848SEzequiel Garcia void hantro_mpeg2_dec_exit(struct hantro_ctx *ctx)
54*fbb6c848SEzequiel Garcia {
55*fbb6c848SEzequiel Garcia struct hantro_dev *vpu = ctx->dev;
56*fbb6c848SEzequiel Garcia
57*fbb6c848SEzequiel Garcia dma_free_coherent(vpu->dev,
58*fbb6c848SEzequiel Garcia ctx->mpeg2_dec.qtable.size,
59*fbb6c848SEzequiel Garcia ctx->mpeg2_dec.qtable.cpu,
60*fbb6c848SEzequiel Garcia ctx->mpeg2_dec.qtable.dma);
61*fbb6c848SEzequiel Garcia }
62