Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / media / platform / rockchip / rga / rga.h
blob5fa9d2f366dc46bbc10b551076104bd2b932d28c
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * Copyright (C) Fuzhou Rockchip Electronics Co.Ltd
4 * Author: Jacob Chen <jacob-chen@iotwrt.com>
5 */
6 #ifndef __RGA_H__
7 #define __RGA_H__
9 #include <linux/platform_device.h>
10 #include <media/videobuf2-v4l2.h>
11 #include <media/v4l2-ctrls.h>
12 #include <media/v4l2-device.h>
14 #define RGA_NAME "rockchip-rga"
16 struct rga_fmt {
17 u32 fourcc;
18 int depth;
19 u8 uv_factor;
20 u8 y_div;
21 u8 x_div;
22 u8 color_swap;
23 u8 hw_format;
26 struct rga_frame {
27 /* Original dimensions */
28 u32 width;
29 u32 height;
30 u32 colorspace;
32 /* Crop */
33 struct v4l2_rect crop;
35 /* Image format */
36 struct rga_fmt *fmt;
38 /* Variables that can calculated once and reused */
39 u32 stride;
40 u32 size;
43 struct rockchip_rga_version {
44 u32 major;
45 u32 minor;
48 struct rga_ctx {
49 struct v4l2_fh fh;
50 struct rockchip_rga *rga;
51 struct rga_frame in;
52 struct rga_frame out;
53 struct v4l2_ctrl_handler ctrl_handler;
55 /* Control values */
56 u32 op;
57 u32 hflip;
58 u32 vflip;
59 u32 rotate;
60 u32 fill_color;
63 struct rockchip_rga {
64 struct v4l2_device v4l2_dev;
65 struct v4l2_m2m_dev *m2m_dev;
66 struct video_device *vfd;
68 struct device *dev;
69 struct regmap *grf;
70 void __iomem *regs;
71 struct clk *sclk;
72 struct clk *aclk;
73 struct clk *hclk;
74 struct rockchip_rga_version version;
76 /* vfd lock */
77 struct mutex mutex;
78 /* ctrl parm lock */
79 spinlock_t ctrl_lock;
81 struct rga_ctx *curr;
82 dma_addr_t cmdbuf_phy;
83 void *cmdbuf_virt;
84 unsigned int *src_mmu_pages;
85 unsigned int *dst_mmu_pages;
88 struct rga_frame *rga_get_frame(struct rga_ctx *ctx, enum v4l2_buf_type type);
90 /* RGA Buffers Manage */
91 extern const struct vb2_ops rga_qops;
92 void rga_buf_map(struct vb2_buffer *vb);
94 /* RGA Hardware */
95 static inline void rga_write(struct rockchip_rga *rga, u32 reg, u32 value)
97 writel(value, rga->regs + reg);
100 static inline u32 rga_read(struct rockchip_rga *rga, u32 reg)
102 return readl(rga->regs + reg);
105 static inline void rga_mod(struct rockchip_rga *rga, u32 reg, u32 val, u32 mask)
107 u32 temp = rga_read(rga, reg) & ~(mask);
109 temp |= val & mask;
110 rga_write(rga, reg, temp);
113 void rga_hw_start(struct rockchip_rga *rga);
115 #endif