1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (C) STMicroelectronics SA 2014
4 * Authors: Fabien Dessenne <fabien.dessenne@st.com> for STMicroelectronics.
8 #include <linux/ktime.h>
9 #include <linux/platform_device.h>
10 #include <linux/spinlock.h>
12 #include <media/v4l2-ctrls.h>
13 #include <media/v4l2-device.h>
14 #include <media/v4l2-mem2mem.h>
16 #include <media/videobuf2-dma-contig.h>
18 #define BDISP_NAME "bdisp"
21 * Max nb of nodes in node-list:
22 * - 2 nodes to handle wide 4K pictures
23 * - 2 nodes to handle two planes (Y & CbCr) */
24 #define MAX_OUTPUT_PLANES 2
25 #define MAX_VERTICAL_STRIDES 2
26 #define MAX_NB_NODE (MAX_OUTPUT_PLANES * MAX_VERTICAL_STRIDES)
28 /* struct bdisp_ctrls - bdisp control set
29 * @hflip: horizontal flip
30 * @vflip: vertical flip
33 struct v4l2_ctrl
*hflip
;
34 struct v4l2_ctrl
*vflip
;
38 * struct bdisp_fmt - driver's internal color format data
39 * @pixelformat:fourcc code for this format
40 * @nb_planes: number of planes (ex: [0]=RGB/Y - [1]=Cb/Cr, ...)
41 * @bpp: bits per pixel (general)
42 * @bpp_plane0: byte per pixel for the 1st plane
43 * @w_align: width alignment in pixel (multiple of)
44 * @h_align: height alignment in pixel (multiple of)
56 * struct bdisp_frame - frame properties
58 * @width: frame width (including padding)
59 * @height: frame height (including padding)
60 * @fmt: pointer to frame format descriptor
61 * @field: frame / field type
62 * @bytesperline: stride of the 1st plane
63 * @sizeimage: image size in bytes
64 * @colorspace: colorspace
66 * @paddr: image physical addresses per plane ([0]=RGB/Y - [1]=Cb/Cr, ...)
71 const struct bdisp_fmt
*fmt
;
72 enum v4l2_field field
;
75 enum v4l2_colorspace colorspace
;
76 struct v4l2_rect crop
;
81 * struct bdisp_request - bdisp request
83 * @src: source frame properties
84 * @dst: destination frame properties
85 * @hflip: horizontal flip
86 * @vflip: vertical flip
87 * @nb_req: number of run request
89 struct bdisp_request
{
90 struct bdisp_frame src
;
91 struct bdisp_frame dst
;
98 * struct bdisp_ctx - device context data
100 * @src: source frame properties
101 * @dst: destination frame properties
102 * @state: flags to keep track of user configuration
103 * @hflip: horizontal flip
104 * @vflip: vertical flip
105 * @bdisp_dev: the device this context applies to
107 * @node_paddr: node physical address array
108 * @fh: v4l2 file handle
109 * @ctrl_handler: v4l2 controls handler
110 * @bdisp_ctrls: bdisp control set
111 * @ctrls_rdy: true if the control handler is initialized
114 struct bdisp_frame src
;
115 struct bdisp_frame dst
;
117 unsigned int hflip
:1;
118 unsigned int vflip
:1;
119 struct bdisp_dev
*bdisp_dev
;
120 struct bdisp_node
*node
[MAX_NB_NODE
];
121 dma_addr_t node_paddr
[MAX_NB_NODE
];
123 struct v4l2_ctrl_handler ctrl_handler
;
124 struct bdisp_ctrls bdisp_ctrls
;
129 * struct bdisp_m2m_device - v4l2 memory-to-memory device data
131 * @vdev: video device node for v4l2 m2m mode
132 * @m2m_dev: v4l2 m2m device data
133 * @ctx: hardware context data
134 * @refcnt: reference counter
136 struct bdisp_m2m_device
{
137 struct video_device
*vdev
;
138 struct v4l2_m2m_dev
*m2m_dev
;
139 struct bdisp_ctx
*ctx
;
144 * struct bdisp_dbg - debug info
146 * @debugfs_entry: debugfs
147 * @copy_node: array of last used nodes
148 * @copy_request: last bdisp request
149 * @hw_start: start time of last HW request
150 * @last_duration: last HW processing duration in microsecs
151 * @min_duration: min HW processing duration in microsecs
152 * @max_duration: max HW processing duration in microsecs
153 * @tot_duration: total HW processing duration in microsecs
156 struct dentry
*debugfs_entry
;
157 struct bdisp_node
*copy_node
[MAX_NB_NODE
];
158 struct bdisp_request copy_request
;
167 * struct bdisp_dev - abstraction for bdisp entity
169 * @v4l2_dev: v4l2 device
170 * @vdev: video device
171 * @pdev: platform device
173 * @lock: mutex protecting this data structure
174 * @slock: spinlock protecting this data structure
176 * @m2m: memory-to-memory V4L2 device information
177 * @state: flags used to synchronize m2m and capture mode operation
180 * @irq_queue: interrupt handler waitqueue
181 * @work_queue: workqueue to handle timeouts
182 * @timeout_work: IRQ timeout structure
186 struct v4l2_device v4l2_dev
;
187 struct video_device vdev
;
188 struct platform_device
*pdev
;
193 struct bdisp_m2m_device m2m
;
197 wait_queue_head_t irq_queue
;
198 struct workqueue_struct
*work_queue
;
199 struct delayed_work timeout_work
;
200 struct bdisp_dbg dbg
;
203 void bdisp_hw_free_nodes(struct bdisp_ctx
*ctx
);
204 int bdisp_hw_alloc_nodes(struct bdisp_ctx
*ctx
);
205 void bdisp_hw_free_filters(struct device
*dev
);
206 int bdisp_hw_alloc_filters(struct device
*dev
);
207 int bdisp_hw_reset(struct bdisp_dev
*bdisp
);
208 int bdisp_hw_get_and_clear_irq(struct bdisp_dev
*bdisp
);
209 int bdisp_hw_update(struct bdisp_ctx
*ctx
);
211 void bdisp_debugfs_remove(struct bdisp_dev
*bdisp
);
212 int bdisp_debugfs_create(struct bdisp_dev
*bdisp
);
213 void bdisp_dbg_perf_begin(struct bdisp_dev
*bdisp
);
214 void bdisp_dbg_perf_end(struct bdisp_dev
*bdisp
);