1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (C) 2018 Intel Corporation */
7 #include <linux/iova.h>
10 #include <media/v4l2-ctrls.h>
11 #include <media/v4l2-device.h>
12 #include <media/videobuf2-dma-sg.h>
16 #define IMGU_NAME "ipu3-imgu"
19 * The semantics of the driver is that whenever there is a buffer available in
20 * master queue, the driver queues a buffer also to all other active nodes.
21 * If user space hasn't provided a buffer to all other video nodes first,
22 * the driver gets an internal dummy buffer and queues it.
24 #define IMGU_QUEUE_MASTER IPU3_CSS_QUEUE_IN
25 #define IMGU_QUEUE_FIRST_INPUT IPU3_CSS_QUEUE_OUT
26 #define IMGU_MAX_QUEUE_DEPTH (2 + 2)
28 #define IMGU_NODE_IN 0 /* Input RAW image */
29 #define IMGU_NODE_PARAMS 1 /* Input parameters */
30 #define IMGU_NODE_OUT 2 /* Main output for still or video */
31 #define IMGU_NODE_VF 3 /* Preview */
32 #define IMGU_NODE_STAT_3A 4 /* 3A statistics */
33 #define IMGU_NODE_NUM 5
35 #define file_to_intel_imgu_node(__file) \
36 container_of(video_devdata(__file), struct imgu_video_device, vdev)
38 #define IPU3_INPUT_MIN_WIDTH 0U
39 #define IPU3_INPUT_MIN_HEIGHT 0U
40 #define IPU3_INPUT_MAX_WIDTH 5120U
41 #define IPU3_INPUT_MAX_HEIGHT 38404U
42 #define IPU3_OUTPUT_MIN_WIDTH 2U
43 #define IPU3_OUTPUT_MIN_HEIGHT 2U
44 #define IPU3_OUTPUT_MAX_WIDTH 4480U
45 #define IPU3_OUTPUT_MAX_HEIGHT 34004U
47 struct imgu_vb2_buffer {
49 struct vb2_v4l2_buffer vbb; /* Must be the first field */
52 struct list_head list;
56 struct imgu_vb2_buffer vid_buf; /* Must be the first field */
57 struct imgu_css_buffer css_buf;
58 struct imgu_css_map map;
61 struct imgu_node_mapping {
62 unsigned int css_queue;
67 * struct imgu_video_device
68 * each node registers as video device and maintains its
71 struct imgu_video_device {
75 struct v4l2_format vdev_fmt; /* Currently set format */
78 struct video_device vdev;
79 struct media_pad vdev_pad;
80 struct v4l2_mbus_framefmt pad_fmt;
82 struct list_head buffers;
83 /* Protect vb2_queue and vdev structs*/
90 struct imgu_v4l2_subdev {
92 struct v4l2_subdev subdev;
93 struct media_pad subdev_pads[IMGU_NODE_NUM];
95 struct v4l2_rect eff; /* effective resolution */
96 struct v4l2_rect bds; /* bayer-domain scaled resolution*/
97 struct v4l2_rect gdc; /* gdc output resolution */
99 struct v4l2_ctrl_handler ctrl_handler;
100 struct v4l2_ctrl *ctrl;
101 atomic_t running_mode;
105 struct imgu_media_pipe {
108 /* Internally enabled queues */
110 struct imgu_css_map dmap;
111 struct imgu_css_buffer dummybufs[IMGU_MAX_QUEUE_DEPTH];
112 } queues[IPU3_CSS_QUEUES];
113 struct imgu_video_device nodes[IMGU_NODE_NUM];
114 bool queue_enabled[IMGU_NODE_NUM];
115 struct media_pipeline pipeline;
116 struct imgu_v4l2_subdev imgu_sd;
120 * imgu_device -- ImgU (Imaging Unit) driver
123 struct pci_dev *pci_dev;
126 /* Public fields, fill before registering */
127 unsigned int buf_struct_size;
128 bool streaming; /* Public read only */
130 struct imgu_media_pipe imgu_pipe[IMGU_MAX_PIPE_NUM];
133 struct v4l2_device v4l2_dev;
134 struct media_device media_dev;
135 struct v4l2_file_operations v4l2_file_ops;
137 /* MMU driver for css */
138 struct imgu_mmu_info *mmu;
139 struct iova_domain iova_domain;
141 /* css - Camera Sub-System */
145 * Coarse-grained lock to protect
146 * vid_buf.list and css->queue
150 /* Lock to protect writes to streaming flag in this struct */
151 struct mutex streaming_lock;
153 /* Forbid streaming and buffer queuing during system suspend. */
154 atomic_t qbuf_barrier;
155 /* Indicate if system suspend take place while imgu is streaming. */
156 bool suspend_in_stream;
157 /* Used to wait for FW buffer queue drain. */
158 wait_queue_head_t buf_drain_wq;
161 unsigned int imgu_node_to_queue(unsigned int node);
162 unsigned int imgu_map_node(struct imgu_device *imgu, unsigned int css_queue);
163 int imgu_queue_buffers(struct imgu_device *imgu, bool initial,
166 int imgu_v4l2_register(struct imgu_device *dev);
167 int imgu_v4l2_unregister(struct imgu_device *dev);
168 void imgu_v4l2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state);
170 int imgu_s_stream(struct imgu_device *imgu, int enable);