1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Allwinner Hantro G2 VPU codec driver
4  *
5  * Copyright (C) 2021 Jernej Skrabec <jernej.skrabec@gmail.com>
6  */
7 
8 #include <linux/clk.h>
9 
10 #include "hantro.h"
11 
12 static const struct hantro_fmt sunxi_vpu_postproc_fmts[] = {
13 	{
14 		.fourcc = V4L2_PIX_FMT_NV12,
15 		.codec_mode = HANTRO_MODE_NONE,
16 		.postprocessed = true,
17 		.frmsize = {
18 			.min_width = FMT_MIN_WIDTH,
19 			.max_width = FMT_UHD_WIDTH,
20 			.step_width = 32,
21 			.min_height = FMT_MIN_HEIGHT,
22 			.max_height = FMT_UHD_HEIGHT,
23 			.step_height = 32,
24 		},
25 	},
26 };
27 
28 static const struct hantro_fmt sunxi_vpu_dec_fmts[] = {
29 	{
30 		.fourcc = V4L2_PIX_FMT_NV12_4L4,
31 		.codec_mode = HANTRO_MODE_NONE,
32 		.frmsize = {
33 			.min_width = FMT_MIN_WIDTH,
34 			.max_width = FMT_UHD_WIDTH,
35 			.step_width = 32,
36 			.min_height = FMT_MIN_HEIGHT,
37 			.max_height = FMT_UHD_HEIGHT,
38 			.step_height = 32,
39 		},
40 	},
41 	{
42 		.fourcc = V4L2_PIX_FMT_VP9_FRAME,
43 		.codec_mode = HANTRO_MODE_VP9_DEC,
44 		.max_depth = 2,
45 		.frmsize = {
46 			.min_width = FMT_MIN_WIDTH,
47 			.max_width = FMT_UHD_WIDTH,
48 			.step_width = 32,
49 			.min_height = FMT_MIN_HEIGHT,
50 			.max_height = FMT_UHD_HEIGHT,
51 			.step_height = 32,
52 		},
53 	},
54 };
55 
sunxi_vpu_hw_init(struct hantro_dev * vpu)56 static int sunxi_vpu_hw_init(struct hantro_dev *vpu)
57 {
58 	clk_set_rate(vpu->clocks[0].clk, 300000000);
59 
60 	return 0;
61 }
62 
sunxi_vpu_reset(struct hantro_ctx * ctx)63 static void sunxi_vpu_reset(struct hantro_ctx *ctx)
64 {
65 	struct hantro_dev *vpu = ctx->dev;
66 
67 	reset_control_reset(vpu->resets);
68 }
69 
70 static const struct hantro_codec_ops sunxi_vpu_codec_ops[] = {
71 	[HANTRO_MODE_VP9_DEC] = {
72 		.run = hantro_g2_vp9_dec_run,
73 		.done = hantro_g2_vp9_dec_done,
74 		.reset = sunxi_vpu_reset,
75 		.init = hantro_vp9_dec_init,
76 		.exit = hantro_vp9_dec_exit,
77 	},
78 };
79 
80 static const struct hantro_irq sunxi_irqs[] = {
81 	{ NULL, hantro_g2_irq },
82 };
83 
84 static const char * const sunxi_clk_names[] = { "mod", "bus" };
85 
86 const struct hantro_variant sunxi_vpu_variant = {
87 	.dec_fmts = sunxi_vpu_dec_fmts,
88 	.num_dec_fmts = ARRAY_SIZE(sunxi_vpu_dec_fmts),
89 	.postproc_fmts = sunxi_vpu_postproc_fmts,
90 	.num_postproc_fmts = ARRAY_SIZE(sunxi_vpu_postproc_fmts),
91 	.postproc_ops = &hantro_g2_postproc_ops,
92 	.codec = HANTRO_VP9_DECODER,
93 	.codec_ops = sunxi_vpu_codec_ops,
94 	.init = sunxi_vpu_hw_init,
95 	.irqs = sunxi_irqs,
96 	.num_irqs = ARRAY_SIZE(sunxi_irqs),
97 	.clk_names = sunxi_clk_names,
98 	.num_clocks = ARRAY_SIZE(sunxi_clk_names),
99 	.double_buffer = 1,
100 	.legacy_regs = 1,
101 	.late_postproc = 1,
102 };
103