1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Hantro VDEC driver
4  *
5  * Copyright (C) 2021 Collabora Ltd, Emil Velikov <emil.velikov@collabora.com>
6  */
7 
8 #include "hantro.h"
9 
10 /*
11  * Supported formats.
12  */
13 
14 static const struct hantro_fmt sama5d4_vdec_postproc_fmts[] = {
15 	{
16 		.fourcc = V4L2_PIX_FMT_YUYV,
17 		.codec_mode = HANTRO_MODE_NONE,
18 	},
19 };
20 
21 static const struct hantro_fmt sama5d4_vdec_fmts[] = {
22 	{
23 		.fourcc = V4L2_PIX_FMT_NV12,
24 		.codec_mode = HANTRO_MODE_NONE,
25 	},
26 	{
27 		.fourcc = V4L2_PIX_FMT_MPEG2_SLICE,
28 		.codec_mode = HANTRO_MODE_MPEG2_DEC,
29 		.max_depth = 2,
30 		.frmsize = {
31 			.min_width = 48,
32 			.max_width = 1280,
33 			.step_width = MB_DIM,
34 			.min_height = 48,
35 			.max_height = 720,
36 			.step_height = MB_DIM,
37 		},
38 	},
39 	{
40 		.fourcc = V4L2_PIX_FMT_VP8_FRAME,
41 		.codec_mode = HANTRO_MODE_VP8_DEC,
42 		.max_depth = 2,
43 		.frmsize = {
44 			.min_width = 48,
45 			.max_width = 1280,
46 			.step_width = MB_DIM,
47 			.min_height = 48,
48 			.max_height = 720,
49 			.step_height = MB_DIM,
50 		},
51 	},
52 	{
53 		.fourcc = V4L2_PIX_FMT_H264_SLICE,
54 		.codec_mode = HANTRO_MODE_H264_DEC,
55 		.max_depth = 2,
56 		.frmsize = {
57 			.min_width = 48,
58 			.max_width = 1280,
59 			.step_width = MB_DIM,
60 			.min_height = 48,
61 			.max_height = 720,
62 			.step_height = MB_DIM,
63 		},
64 	},
65 };
66 
67 /*
68  * Supported codec ops.
69  */
70 
71 static const struct hantro_codec_ops sama5d4_vdec_codec_ops[] = {
72 	[HANTRO_MODE_MPEG2_DEC] = {
73 		.run = hantro_g1_mpeg2_dec_run,
74 		.reset = hantro_g1_reset,
75 		.init = hantro_mpeg2_dec_init,
76 		.exit = hantro_mpeg2_dec_exit,
77 	},
78 	[HANTRO_MODE_VP8_DEC] = {
79 		.run = hantro_g1_vp8_dec_run,
80 		.reset = hantro_g1_reset,
81 		.init = hantro_vp8_dec_init,
82 		.exit = hantro_vp8_dec_exit,
83 	},
84 	[HANTRO_MODE_H264_DEC] = {
85 		.run = hantro_g1_h264_dec_run,
86 		.reset = hantro_g1_reset,
87 		.init = hantro_h264_dec_init,
88 		.exit = hantro_h264_dec_exit,
89 	},
90 };
91 
92 static const struct hantro_irq sama5d4_irqs[] = {
93 	{ "vdec", hantro_g1_irq },
94 };
95 
96 static const char * const sama5d4_clk_names[] = { "vdec_clk" };
97 
98 const struct hantro_variant sama5d4_vdec_variant = {
99 	.dec_fmts = sama5d4_vdec_fmts,
100 	.num_dec_fmts = ARRAY_SIZE(sama5d4_vdec_fmts),
101 	.postproc_fmts = sama5d4_vdec_postproc_fmts,
102 	.num_postproc_fmts = ARRAY_SIZE(sama5d4_vdec_postproc_fmts),
103 	.postproc_regs = &hantro_g1_postproc_regs,
104 	.codec = HANTRO_MPEG2_DECODER | HANTRO_VP8_DECODER |
105 		 HANTRO_H264_DECODER,
106 	.codec_ops = sama5d4_vdec_codec_ops,
107 	.irqs = sama5d4_irqs,
108 	.num_irqs = ARRAY_SIZE(sama5d4_irqs),
109 	.clk_names = sama5d4_clk_names,
110 	.num_clocks = ARRAY_SIZE(sama5d4_clk_names),
111 };
112