Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / media / platform / xilinx / xilinx-vip.h
bloba528a32ea1dc5aec26c5d5dcdbc991a1584cecf5
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * Xilinx Video IP Core
5 * Copyright (C) 2013-2015 Ideas on Board
6 * Copyright (C) 2013-2015 Xilinx, Inc.
8 * Contacts: Hyun Kwon <hyun.kwon@xilinx.com>
9 * Laurent Pinchart <laurent.pinchart@ideasonboard.com>
12 #ifndef __XILINX_VIP_H__
13 #define __XILINX_VIP_H__
15 #include <linux/bitops.h>
16 #include <linux/io.h>
17 #include <media/v4l2-subdev.h>
19 struct clk;
22 * Minimum and maximum width and height common to most video IP cores. IP
23 * cores with different requirements must define their own values.
25 #define XVIP_MIN_WIDTH 32
26 #define XVIP_MAX_WIDTH 7680
27 #define XVIP_MIN_HEIGHT 32
28 #define XVIP_MAX_HEIGHT 7680
31 * Pad IDs. IP cores with with multiple inputs or outputs should define
32 * their own values.
34 #define XVIP_PAD_SINK 0
35 #define XVIP_PAD_SOURCE 1
37 /* Xilinx Video IP Control Registers */
38 #define XVIP_CTRL_CONTROL 0x0000
39 #define XVIP_CTRL_CONTROL_SW_ENABLE BIT(0)
40 #define XVIP_CTRL_CONTROL_REG_UPDATE BIT(1)
41 #define XVIP_CTRL_CONTROL_BYPASS BIT(4)
42 #define XVIP_CTRL_CONTROL_TEST_PATTERN BIT(5)
43 #define XVIP_CTRL_CONTROL_FRAME_SYNC_RESET BIT(30)
44 #define XVIP_CTRL_CONTROL_SW_RESET BIT(31)
45 #define XVIP_CTRL_STATUS 0x0004
46 #define XVIP_CTRL_STATUS_PROC_STARTED BIT(0)
47 #define XVIP_CTRL_STATUS_EOF BIT(1)
48 #define XVIP_CTRL_ERROR 0x0008
49 #define XVIP_CTRL_ERROR_SLAVE_EOL_EARLY BIT(0)
50 #define XVIP_CTRL_ERROR_SLAVE_EOL_LATE BIT(1)
51 #define XVIP_CTRL_ERROR_SLAVE_SOF_EARLY BIT(2)
52 #define XVIP_CTRL_ERROR_SLAVE_SOF_LATE BIT(3)
53 #define XVIP_CTRL_IRQ_ENABLE 0x000c
54 #define XVIP_CTRL_IRQ_ENABLE_PROC_STARTED BIT(0)
55 #define XVIP_CTRL_IRQ_EOF BIT(1)
56 #define XVIP_CTRL_VERSION 0x0010
57 #define XVIP_CTRL_VERSION_MAJOR_MASK (0xff << 24)
58 #define XVIP_CTRL_VERSION_MAJOR_SHIFT 24
59 #define XVIP_CTRL_VERSION_MINOR_MASK (0xff << 16)
60 #define XVIP_CTRL_VERSION_MINOR_SHIFT 16
61 #define XVIP_CTRL_VERSION_REVISION_MASK (0xf << 12)
62 #define XVIP_CTRL_VERSION_REVISION_SHIFT 12
63 #define XVIP_CTRL_VERSION_PATCH_MASK (0xf << 8)
64 #define XVIP_CTRL_VERSION_PATCH_SHIFT 8
65 #define XVIP_CTRL_VERSION_INTERNAL_MASK (0xff << 0)
66 #define XVIP_CTRL_VERSION_INTERNAL_SHIFT 0
68 /* Xilinx Video IP Timing Registers */
69 #define XVIP_ACTIVE_SIZE 0x0020
70 #define XVIP_ACTIVE_VSIZE_MASK (0x7ff << 16)
71 #define XVIP_ACTIVE_VSIZE_SHIFT 16
72 #define XVIP_ACTIVE_HSIZE_MASK (0x7ff << 0)
73 #define XVIP_ACTIVE_HSIZE_SHIFT 0
74 #define XVIP_ENCODING 0x0028
75 #define XVIP_ENCODING_NBITS_8 (0 << 4)
76 #define XVIP_ENCODING_NBITS_10 (1 << 4)
77 #define XVIP_ENCODING_NBITS_12 (2 << 4)
78 #define XVIP_ENCODING_NBITS_16 (3 << 4)
79 #define XVIP_ENCODING_NBITS_MASK (3 << 4)
80 #define XVIP_ENCODING_NBITS_SHIFT 4
81 #define XVIP_ENCODING_VIDEO_FORMAT_YUV422 (0 << 0)
82 #define XVIP_ENCODING_VIDEO_FORMAT_YUV444 (1 << 0)
83 #define XVIP_ENCODING_VIDEO_FORMAT_RGB (2 << 0)
84 #define XVIP_ENCODING_VIDEO_FORMAT_YUV420 (3 << 0)
85 #define XVIP_ENCODING_VIDEO_FORMAT_MASK (3 << 0)
86 #define XVIP_ENCODING_VIDEO_FORMAT_SHIFT 0
88 /**
89 * struct xvip_device - Xilinx Video IP device structure
90 * @subdev: V4L2 subdevice
91 * @dev: (OF) device
92 * @iomem: device I/O register space remapped to kernel virtual memory
93 * @clk: video core clock
94 * @saved_ctrl: saved control register for resume / suspend
96 struct xvip_device {
97 struct v4l2_subdev subdev;
98 struct device *dev;
99 void __iomem *iomem;
100 struct clk *clk;
101 u32 saved_ctrl;
105 * struct xvip_video_format - Xilinx Video IP video format description
106 * @vf_code: AXI4 video format code
107 * @width: AXI4 format width in bits per component
108 * @pattern: CFA pattern for Mono/Sensor formats
109 * @code: media bus format code
110 * @bpp: bytes per pixel (when stored in memory)
111 * @fourcc: V4L2 pixel format FCC identifier
113 struct xvip_video_format {
114 unsigned int vf_code;
115 unsigned int width;
116 const char *pattern;
117 unsigned int code;
118 unsigned int bpp;
119 u32 fourcc;
122 const struct xvip_video_format *xvip_get_format_by_code(unsigned int code);
123 const struct xvip_video_format *xvip_get_format_by_fourcc(u32 fourcc);
124 const struct xvip_video_format *xvip_of_get_format(struct device_node *node);
125 void xvip_set_format_size(struct v4l2_mbus_framefmt *format,
126 const struct v4l2_subdev_format *fmt);
127 int xvip_enum_mbus_code(struct v4l2_subdev *subdev,
128 struct v4l2_subdev_pad_config *cfg,
129 struct v4l2_subdev_mbus_code_enum *code);
130 int xvip_enum_frame_size(struct v4l2_subdev *subdev,
131 struct v4l2_subdev_pad_config *cfg,
132 struct v4l2_subdev_frame_size_enum *fse);
134 static inline u32 xvip_read(struct xvip_device *xvip, u32 addr)
136 return ioread32(xvip->iomem + addr);
139 static inline void xvip_write(struct xvip_device *xvip, u32 addr, u32 value)
141 iowrite32(value, xvip->iomem + addr);
144 static inline void xvip_clr(struct xvip_device *xvip, u32 addr, u32 clr)
146 xvip_write(xvip, addr, xvip_read(xvip, addr) & ~clr);
149 static inline void xvip_set(struct xvip_device *xvip, u32 addr, u32 set)
151 xvip_write(xvip, addr, xvip_read(xvip, addr) | set);
154 void xvip_clr_or_set(struct xvip_device *xvip, u32 addr, u32 mask, bool set);
155 void xvip_clr_and_set(struct xvip_device *xvip, u32 addr, u32 clr, u32 set);
157 int xvip_init_resources(struct xvip_device *xvip);
158 void xvip_cleanup_resources(struct xvip_device *xvip);
160 static inline void xvip_reset(struct xvip_device *xvip)
162 xvip_write(xvip, XVIP_CTRL_CONTROL, XVIP_CTRL_CONTROL_SW_RESET);
165 static inline void xvip_start(struct xvip_device *xvip)
167 xvip_set(xvip, XVIP_CTRL_CONTROL,
168 XVIP_CTRL_CONTROL_SW_ENABLE | XVIP_CTRL_CONTROL_REG_UPDATE);
171 static inline void xvip_stop(struct xvip_device *xvip)
173 xvip_clr(xvip, XVIP_CTRL_CONTROL, XVIP_CTRL_CONTROL_SW_ENABLE);
176 static inline void xvip_resume(struct xvip_device *xvip)
178 xvip_write(xvip, XVIP_CTRL_CONTROL,
179 xvip->saved_ctrl | XVIP_CTRL_CONTROL_SW_ENABLE);
182 static inline void xvip_suspend(struct xvip_device *xvip)
184 xvip->saved_ctrl = xvip_read(xvip, XVIP_CTRL_CONTROL);
185 xvip_write(xvip, XVIP_CTRL_CONTROL,
186 xvip->saved_ctrl & ~XVIP_CTRL_CONTROL_SW_ENABLE);
189 static inline void xvip_set_frame_size(struct xvip_device *xvip,
190 const struct v4l2_mbus_framefmt *format)
192 xvip_write(xvip, XVIP_ACTIVE_SIZE,
193 (format->height << XVIP_ACTIVE_VSIZE_SHIFT) |
194 (format->width << XVIP_ACTIVE_HSIZE_SHIFT));
197 static inline void xvip_get_frame_size(struct xvip_device *xvip,
198 struct v4l2_mbus_framefmt *format)
200 u32 reg;
202 reg = xvip_read(xvip, XVIP_ACTIVE_SIZE);
203 format->width = (reg & XVIP_ACTIVE_HSIZE_MASK) >>
204 XVIP_ACTIVE_HSIZE_SHIFT;
205 format->height = (reg & XVIP_ACTIVE_VSIZE_MASK) >>
206 XVIP_ACTIVE_VSIZE_SHIFT;
209 static inline void xvip_enable_reg_update(struct xvip_device *xvip)
211 xvip_set(xvip, XVIP_CTRL_CONTROL, XVIP_CTRL_CONTROL_REG_UPDATE);
214 static inline void xvip_disable_reg_update(struct xvip_device *xvip)
216 xvip_clr(xvip, XVIP_CTRL_CONTROL, XVIP_CTRL_CONTROL_REG_UPDATE);
219 static inline void xvip_print_version(struct xvip_device *xvip)
221 u32 version;
223 version = xvip_read(xvip, XVIP_CTRL_VERSION);
225 dev_info(xvip->dev, "device found, version %u.%02x%x\n",
226 ((version & XVIP_CTRL_VERSION_MAJOR_MASK) >>
227 XVIP_CTRL_VERSION_MAJOR_SHIFT),
228 ((version & XVIP_CTRL_VERSION_MINOR_MASK) >>
229 XVIP_CTRL_VERSION_MINOR_SHIFT),
230 ((version & XVIP_CTRL_VERSION_REVISION_MASK) >>
231 XVIP_CTRL_VERSION_REVISION_SHIFT));
234 #endif /* __XILINX_VIP_H__ */