File Index
Files and directories
Sign in
FILE

c3-isp-common.h

File preview with syntax highlighting.

linux-6.19.14/drivers/media/platform/amlogic/c3/isp/c3-isp-common.h C
  1/* SPDX-License-Identifier: (GPL-2.0-only OR MIT) */
  2/*
  3 * Copyright (C) 2024 Amlogic, Inc. All rights reserved
  4 */
  5
  6#ifndef __C3_ISP_COMMON_H__
  7#define __C3_ISP_COMMON_H__
  8
  9#include <linux/clk.h>
 10
 11#include <media/media-device.h>
 12#include <media/videobuf2-core.h>
 13#include <media/v4l2-device.h>
 14#include <media/v4l2-subdev.h>
 15#include <media/videobuf2-v4l2.h>
 16
 17#define C3_ISP_DRIVER_NAME		"c3-isp"
 18#define C3_ISP_CLOCK_NUM_MAX		3
 19
 20#define C3_ISP_DEFAULT_WIDTH		1920
 21#define C3_ISP_DEFAULT_HEIGHT		1080
 22#define C3_ISP_MAX_WIDTH		2888
 23#define C3_ISP_MAX_HEIGHT		2240
 24#define C3_ISP_MIN_WIDTH		160
 25#define C3_ISP_MIN_HEIGHT		120
 26
 27#define C3_ISP_DMA_SIZE_ALIGN_BYTES	16
 28
 29enum c3_isp_core_pads {
 30	C3_ISP_CORE_PAD_SINK_VIDEO,
 31	C3_ISP_CORE_PAD_SINK_PARAMS,
 32	C3_ISP_CORE_PAD_SOURCE_STATS,
 33	C3_ISP_CORE_PAD_SOURCE_VIDEO_0,
 34	C3_ISP_CORE_PAD_SOURCE_VIDEO_1,
 35	C3_ISP_CORE_PAD_SOURCE_VIDEO_2,
 36	C3_ISP_CORE_PAD_MAX
 37};
 38
 39enum c3_isp_resizer_ids {
 40	C3_ISP_RSZ_0,
 41	C3_ISP_RSZ_1,
 42	C3_ISP_RSZ_2,
 43	C3_ISP_NUM_RSZ
 44};
 45
 46enum c3_isp_resizer_pads {
 47	C3_ISP_RSZ_PAD_SINK,
 48	C3_ISP_RSZ_PAD_SOURCE,
 49	C3_ISP_RSZ_PAD_MAX
 50};
 51
 52enum c3_isp_cap_devs {
 53	C3_ISP_CAP_DEV_0,
 54	C3_ISP_CAP_DEV_1,
 55	C3_ISP_CAP_DEV_2,
 56	C3_ISP_NUM_CAP_DEVS
 57};
 58
 59enum c3_isp_planes {
 60	C3_ISP_PLANE_Y,
 61	C3_ISP_PLANE_UV,
 62	C3_ISP_NUM_PLANES
 63};
 64
 65/*
 66 * struct c3_isp_cap_format_info - The image format of capture device
 67 *
 68 * @mbus_code: the mbus code
 69 * @fourcc: the pixel format
 70 * @format: defines the output format of hardware
 71 * @planes: defines the mutil plane of hardware
 72 * @ch0_pix_bits: defines the channel 0 pixel bits mode of hardware
 73 * @uv_swap: defines the uv swap flag of hardware
 74 * @in_bits: defines the input bits of hardware
 75 * @hdiv: horizontal chroma subsampling factor of hardware
 76 * @vdiv: vertical chroma subsampling factor of hardware
 77 */
 78struct c3_isp_cap_format_info {
 79	u32 mbus_code;
 80	u32 fourcc;
 81	u32 format;
 82	u32 planes;
 83	u32 ch0_pix_bits;
 84	u8 uv_swap;
 85	u8 in_bits;
 86	u8 hdiv;
 87	u8 vdiv;
 88};
 89
 90/*
 91 * struct c3_isp_cap_buffer - A container of vb2 buffer used by the video
 92 *                            devices: capture video devices
 93 *
 94 * @vb: vb2 buffer
 95 * @dma_addr: buffer physical address
 96 * @list: entry of the buffer in the queue
 97 */
 98struct c3_isp_cap_buffer {
 99	struct vb2_v4l2_buffer vb;
100	dma_addr_t dma_addr[C3_ISP_NUM_PLANES];
101	struct list_head list;
102};
103
104/*
105 * struct c3_isp_stats_dma_buffer - A container of vb2 buffer used by the video
106 *                                  devices: stats video devices
107 *
108 * @vb: vb2 buffer
109 * @dma_addr: buffer physical address
110 * @list: entry of the buffer in the queue
111 */
112struct c3_isp_stats_buffer {
113	struct vb2_v4l2_buffer vb;
114	dma_addr_t dma_addr;
115	struct list_head list;
116};
117
118/*
119 * struct c3_isp_params_buffer - A container of vb2 buffer used by the
120 *                               params video device
121 *
122 * @vb: vb2 buffer
123 * @cfg: scratch buffer used for caching the ISP configuration parameters
124 * @list: entry of the buffer in the queue
125 */
126struct c3_isp_params_buffer {
127	struct vb2_v4l2_buffer vb;
128	void *cfg;
129	struct list_head list;
130};
131
132/*
133 * struct c3_isp_dummy_buffer - A buffer to write the next frame to in case
134 *				there are no vb2 buffers available.
135 *
136 * @vaddr:	return value of call to dma_alloc_attrs
137 * @dma_addr:	dma address of the buffer
138 * @size:	size of the buffer
139 */
140struct c3_isp_dummy_buffer {
141	void *vaddr;
142	dma_addr_t dma_addr;
143	u32 size;
144};
145
146/*
147 * struct c3_isp_core - ISP core subdev
148 *
149 * @sd: ISP sub-device
150 * @pads: ISP sub-device pads
151 * @src_pad: source sub-device pad
152 * @isp: pointer to c3_isp_device
153 */
154struct c3_isp_core {
155	struct v4l2_subdev sd;
156	struct media_pad pads[C3_ISP_CORE_PAD_MAX];
157	struct media_pad *src_pad;
158	struct c3_isp_device *isp;
159};
160
161/*
162 * struct c3_isp_resizer - ISP resizer subdev
163 *
164 * @id: resizer id
165 * @sd: resizer sub-device
166 * @pads: resizer sub-device pads
167 * @src_sd: source sub-device
168 * @isp: pointer to c3_isp_device
169 * @src_pad: the pad of source sub-device
170 */
171struct c3_isp_resizer {
172	enum c3_isp_resizer_ids id;
173	struct v4l2_subdev sd;
174	struct media_pad pads[C3_ISP_RSZ_PAD_MAX];
175	struct v4l2_subdev *src_sd;
176	struct c3_isp_device *isp;
177	u32 src_pad;
178};
179
180/*
181 * struct c3_isp_stats - ISP statistics device
182 *
183 * @vb2_q: vb2 buffer queue
184 * @vdev: video node
185 * @vfmt: v4l2_format of the metadata format
186 * @pad: media pad
187 * @lock: protects vb2_q, vdev
188 * @isp: pointer to c3_isp_device
189 * @buff: in use buffer
190 * @buff_lock: protects stats buffer
191 * @pending: stats buffer list head
192 */
193struct c3_isp_stats {
194	struct vb2_queue vb2_q;
195	struct video_device vdev;
196	struct v4l2_format vfmt;
197	struct media_pad pad;
198
199	struct mutex lock; /* Protects vb2_q, vdev */
200	struct c3_isp_device *isp;
201
202	struct c3_isp_stats_buffer *buff;
203	spinlock_t buff_lock; /* Protects stats buffer */
204	struct list_head pending;
205};
206
207/*
208 * struct c3_isp_params - ISP parameters device
209 *
210 * @vb2_q: vb2 buffer queue
211 * @vdev: video node
212 * @vfmt: v4l2_format of the metadata format
213 * @pad: media pad
214 * @lock: protects vb2_q, vdev
215 * @isp: pointer to c3_isp_device
216 * @buff: in use buffer
217 * @buff_lock: protects stats buffer
218 * @pending: stats buffer list head
219 */
220struct c3_isp_params {
221	struct vb2_queue vb2_q;
222	struct video_device vdev;
223	struct v4l2_format vfmt;
224	struct media_pad pad;
225
226	struct mutex lock; /* Protects vb2_q, vdev */
227	struct c3_isp_device *isp;
228
229	struct c3_isp_params_buffer *buff;
230	spinlock_t buff_lock; /* Protects params buffer */
231	struct list_head pending;
232};
233
234/*
235 * struct c3_isp_capture - ISP capture device
236 *
237 * @id: capture device ID
238 * @vb2_q: vb2 buffer queue
239 * @vdev: video node
240 * @pad: media pad
241 * @lock: protects vb2_q, vdev
242 * @isp: pointer to c3_isp_device
243 * @rsz: pointer to c3_isp_resizer
244 * @buff: in use buffer
245 * @buff_lock: protects capture buffer
246 * @pending: capture buffer list head
247 * @format.info: a pointer to the c3_isp_capture_format of the pixel format
248 * @format.fmt: buffer format
249 */
250struct c3_isp_capture {
251	enum c3_isp_cap_devs id;
252	struct vb2_queue vb2_q;
253	struct video_device vdev;
254	struct media_pad pad;
255
256	struct mutex lock; /* Protects vb2_q, vdev */
257	struct c3_isp_device *isp;
258	struct c3_isp_resizer *rsz;
259
260	struct c3_isp_dummy_buffer dummy_buff;
261	struct c3_isp_cap_buffer *buff;
262	spinlock_t buff_lock; /* Protects stream buffer */
263	struct list_head pending;
264	struct {
265		const struct c3_isp_cap_format_info *info;
266		struct v4l2_pix_format_mplane pix_mp;
267	} format;
268};
269
270/**
271 * struct c3_isp_info - ISP information
272 *
273 * @clocks: array of ISP clock names
274 * @clock_num: actual clock number
275 */
276struct c3_isp_info {
277	char *clocks[C3_ISP_CLOCK_NUM_MAX];
278	u32 clock_num;
279};
280
281/**
282 * struct c3_isp_device - ISP platform device
283 *
284 * @dev: pointer to the struct device
285 * @base: base register address
286 * @clks: array of clocks
287 * @notifier: notifier to register on the v4l2-async API
288 * @v4l2_dev: v4l2_device variable
289 * @media_dev: media device variable
290 * @pipe: media pipeline
291 * @core: ISP core subdev
292 * @resizers: ISP resizer subdev
293 * @stats: ISP stats device
294 * @params: ISP params device
295 * @caps: array of ISP capture device
296 * @frm_sequence: used to record frame id
297 * @info: version-specific ISP information
298 */
299struct c3_isp_device {
300	struct device *dev;
301	void __iomem *base;
302	struct clk_bulk_data clks[C3_ISP_CLOCK_NUM_MAX];
303
304	struct v4l2_async_notifier notifier;
305	struct v4l2_device v4l2_dev;
306	struct media_device media_dev;
307	struct media_pipeline pipe;
308
309	struct c3_isp_core core;
310	struct c3_isp_resizer resizers[C3_ISP_NUM_RSZ];
311	struct c3_isp_stats stats;
312	struct c3_isp_params params;
313	struct c3_isp_capture caps[C3_ISP_NUM_CAP_DEVS];
314
315	u32 frm_sequence;
316	const struct c3_isp_info *info;
317};
318
319u32 c3_isp_read(struct c3_isp_device *isp, u32 reg);
320void c3_isp_write(struct c3_isp_device *isp, u32 reg, u32 val);
321void c3_isp_update_bits(struct c3_isp_device *isp, u32 reg, u32 mask, u32 val);
322
323void c3_isp_core_queue_sof(struct c3_isp_device *isp);
324int c3_isp_core_register(struct c3_isp_device *isp);
325void c3_isp_core_unregister(struct c3_isp_device *isp);
326int c3_isp_resizers_register(struct c3_isp_device *isp);
327void c3_isp_resizers_unregister(struct c3_isp_device *isp);
328int c3_isp_captures_register(struct c3_isp_device *isp);
329void c3_isp_captures_unregister(struct c3_isp_device *isp);
330void c3_isp_captures_isr(struct c3_isp_device *isp);
331void c3_isp_stats_pre_cfg(struct c3_isp_device *isp);
332int c3_isp_stats_register(struct c3_isp_device *isp);
333void c3_isp_stats_unregister(struct c3_isp_device *isp);
334void c3_isp_stats_isr(struct c3_isp_device *isp);
335void c3_isp_params_pre_cfg(struct c3_isp_device *isp);
336int c3_isp_params_register(struct c3_isp_device *isp);
337void c3_isp_params_unregister(struct c3_isp_device *isp);
338void c3_isp_params_isr(struct c3_isp_device *isp);
339
340#endif
~/ Read-only file preview.