1 // SPDX-License-Identifier: GPL-2.0-only
3 * vivid-core.c - A Virtual Video Test Driver, core initialization
5 * Copyright 2014 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
8 #include <linux/module.h>
9 #include <linux/errno.h>
10 #include <linux/kernel.h>
11 #include <linux/init.h>
12 #include <linux/sched.h>
13 #include <linux/slab.h>
14 #include <linux/vmalloc.h>
15 #include <linux/font.h>
16 #include <linux/mutex.h>
17 #include <linux/platform_device.h>
18 #include <linux/videodev2.h>
19 #include <linux/v4l2-dv-timings.h>
20 #include <media/videobuf2-vmalloc.h>
21 #include <media/videobuf2-dma-contig.h>
22 #include <media/v4l2-dv-timings.h>
23 #include <media/v4l2-ioctl.h>
24 #include <media/v4l2-fh.h>
25 #include <media/v4l2-event.h>
27 #include "vivid-core.h"
28 #include "vivid-vid-common.h"
29 #include "vivid-vid-cap.h"
30 #include "vivid-vid-out.h"
31 #include "vivid-radio-common.h"
32 #include "vivid-radio-rx.h"
33 #include "vivid-radio-tx.h"
34 #include "vivid-sdr-cap.h"
35 #include "vivid-vbi-cap.h"
36 #include "vivid-vbi-out.h"
37 #include "vivid-osd.h"
38 #include "vivid-cec.h"
39 #include "vivid-ctrls.h"
40 #include "vivid-meta-cap.h"
41 #include "vivid-meta-out.h"
42 #include "vivid-touch-cap.h"
44 #define VIVID_MODULE_NAME "vivid"
46 /* The maximum number of vivid devices */
47 #define VIVID_MAX_DEVS CONFIG_VIDEO_VIVID_MAX_DEVS
49 MODULE_DESCRIPTION("Virtual Video Test Driver");
50 MODULE_AUTHOR("Hans Verkuil");
51 MODULE_LICENSE("GPL");
53 static unsigned n_devs
= 1;
54 module_param(n_devs
, uint
, 0444);
55 MODULE_PARM_DESC(n_devs
, " number of driver instances to create");
57 static int vid_cap_nr
[VIVID_MAX_DEVS
] = { [0 ... (VIVID_MAX_DEVS
- 1)] = -1 };
58 module_param_array(vid_cap_nr
, int, NULL
, 0444);
59 MODULE_PARM_DESC(vid_cap_nr
, " videoX start number, -1 is autodetect");
61 static int vid_out_nr
[VIVID_MAX_DEVS
] = { [0 ... (VIVID_MAX_DEVS
- 1)] = -1 };
62 module_param_array(vid_out_nr
, int, NULL
, 0444);
63 MODULE_PARM_DESC(vid_out_nr
, " videoX start number, -1 is autodetect");
65 static int vbi_cap_nr
[VIVID_MAX_DEVS
] = { [0 ... (VIVID_MAX_DEVS
- 1)] = -1 };
66 module_param_array(vbi_cap_nr
, int, NULL
, 0444);
67 MODULE_PARM_DESC(vbi_cap_nr
, " vbiX start number, -1 is autodetect");
69 static int vbi_out_nr
[VIVID_MAX_DEVS
] = { [0 ... (VIVID_MAX_DEVS
- 1)] = -1 };
70 module_param_array(vbi_out_nr
, int, NULL
, 0444);
71 MODULE_PARM_DESC(vbi_out_nr
, " vbiX start number, -1 is autodetect");
73 static int sdr_cap_nr
[VIVID_MAX_DEVS
] = { [0 ... (VIVID_MAX_DEVS
- 1)] = -1 };
74 module_param_array(sdr_cap_nr
, int, NULL
, 0444);
75 MODULE_PARM_DESC(sdr_cap_nr
, " swradioX start number, -1 is autodetect");
77 static int radio_rx_nr
[VIVID_MAX_DEVS
] = { [0 ... (VIVID_MAX_DEVS
- 1)] = -1 };
78 module_param_array(radio_rx_nr
, int, NULL
, 0444);
79 MODULE_PARM_DESC(radio_rx_nr
, " radioX start number, -1 is autodetect");
81 static int radio_tx_nr
[VIVID_MAX_DEVS
] = { [0 ... (VIVID_MAX_DEVS
- 1)] = -1 };
82 module_param_array(radio_tx_nr
, int, NULL
, 0444);
83 MODULE_PARM_DESC(radio_tx_nr
, " radioX start number, -1 is autodetect");
85 static int meta_cap_nr
[VIVID_MAX_DEVS
] = { [0 ... (VIVID_MAX_DEVS
- 1)] = -1 };
86 module_param_array(meta_cap_nr
, int, NULL
, 0444);
87 MODULE_PARM_DESC(meta_cap_nr
, " videoX start number, -1 is autodetect");
89 static int meta_out_nr
[VIVID_MAX_DEVS
] = { [0 ... (VIVID_MAX_DEVS
- 1)] = -1 };
90 module_param_array(meta_out_nr
, int, NULL
, 0444);
91 MODULE_PARM_DESC(meta_out_nr
, " videoX start number, -1 is autodetect");
93 static int touch_cap_nr
[VIVID_MAX_DEVS
] = { [0 ... (VIVID_MAX_DEVS
- 1)] = -1 };
94 module_param_array(touch_cap_nr
, int, NULL
, 0444);
95 MODULE_PARM_DESC(touch_cap_nr
, " v4l-touchX start number, -1 is autodetect");
97 static int ccs_cap_mode
[VIVID_MAX_DEVS
] = { [0 ... (VIVID_MAX_DEVS
- 1)] = -1 };
98 module_param_array(ccs_cap_mode
, int, NULL
, 0444);
99 MODULE_PARM_DESC(ccs_cap_mode
, " capture crop/compose/scale mode:\n"
100 "\t\t bit 0=crop, 1=compose, 2=scale,\n"
101 "\t\t -1=user-controlled (default)");
103 static int ccs_out_mode
[VIVID_MAX_DEVS
] = { [0 ... (VIVID_MAX_DEVS
- 1)] = -1 };
104 module_param_array(ccs_out_mode
, int, NULL
, 0444);
105 MODULE_PARM_DESC(ccs_out_mode
, " output crop/compose/scale mode:\n"
106 "\t\t bit 0=crop, 1=compose, 2=scale,\n"
107 "\t\t -1=user-controlled (default)");
109 static unsigned multiplanar
[VIVID_MAX_DEVS
] = { [0 ... (VIVID_MAX_DEVS
- 1)] = 1 };
110 module_param_array(multiplanar
, uint
, NULL
, 0444);
111 MODULE_PARM_DESC(multiplanar
, " 1 (default) creates a single planar device, 2 creates a multiplanar device.");
114 * Default: video + vbi-cap (raw and sliced) + radio rx + radio tx + sdr +
115 * vbi-out + vid-out + meta-cap
117 static unsigned int node_types
[VIVID_MAX_DEVS
] = {
118 [0 ... (VIVID_MAX_DEVS
- 1)] = 0xe1d3d
120 module_param_array(node_types
, uint
, NULL
, 0444);
121 MODULE_PARM_DESC(node_types
, " node types, default is 0xe1d3d. Bitmask with the following meaning:\n"
122 "\t\t bit 0: Video Capture node\n"
123 "\t\t bit 2-3: VBI Capture node: 0 = none, 1 = raw vbi, 2 = sliced vbi, 3 = both\n"
124 "\t\t bit 4: Radio Receiver node\n"
125 "\t\t bit 5: Software Defined Radio Receiver node\n"
126 "\t\t bit 8: Video Output node\n"
127 "\t\t bit 10-11: VBI Output node: 0 = none, 1 = raw vbi, 2 = sliced vbi, 3 = both\n"
128 "\t\t bit 12: Radio Transmitter node\n"
129 "\t\t bit 16: Framebuffer for testing overlays\n"
130 "\t\t bit 17: Metadata Capture node\n"
131 "\t\t bit 18: Metadata Output node\n"
132 "\t\t bit 19: Touch Capture node\n");
134 /* Default: 4 inputs */
135 static unsigned num_inputs
[VIVID_MAX_DEVS
] = { [0 ... (VIVID_MAX_DEVS
- 1)] = 4 };
136 module_param_array(num_inputs
, uint
, NULL
, 0444);
137 MODULE_PARM_DESC(num_inputs
, " number of inputs, default is 4");
139 /* Default: input 0 = WEBCAM, 1 = TV, 2 = SVID, 3 = HDMI */
140 static unsigned input_types
[VIVID_MAX_DEVS
] = { [0 ... (VIVID_MAX_DEVS
- 1)] = 0xe4 };
141 module_param_array(input_types
, uint
, NULL
, 0444);
142 MODULE_PARM_DESC(input_types
, " input types, default is 0xe4. Two bits per input,\n"
143 "\t\t bits 0-1 == input 0, bits 31-30 == input 15.\n"
144 "\t\t Type 0 == webcam, 1 == TV, 2 == S-Video, 3 == HDMI");
146 /* Default: 2 outputs */
147 static unsigned num_outputs
[VIVID_MAX_DEVS
] = { [0 ... (VIVID_MAX_DEVS
- 1)] = 2 };
148 module_param_array(num_outputs
, uint
, NULL
, 0444);
149 MODULE_PARM_DESC(num_outputs
, " number of outputs, default is 2");
151 /* Default: output 0 = SVID, 1 = HDMI */
152 static unsigned output_types
[VIVID_MAX_DEVS
] = { [0 ... (VIVID_MAX_DEVS
- 1)] = 2 };
153 module_param_array(output_types
, uint
, NULL
, 0444);
154 MODULE_PARM_DESC(output_types
, " output types, default is 0x02. One bit per output,\n"
155 "\t\t bit 0 == output 0, bit 15 == output 15.\n"
156 "\t\t Type 0 == S-Video, 1 == HDMI");
158 unsigned vivid_debug
;
159 module_param(vivid_debug
, uint
, 0644);
160 MODULE_PARM_DESC(vivid_debug
, " activates debug info");
162 static bool no_error_inj
;
163 module_param(no_error_inj
, bool, 0444);
164 MODULE_PARM_DESC(no_error_inj
, " if set disable the error injecting controls");
166 static unsigned int allocators
[VIVID_MAX_DEVS
] = { [0 ... (VIVID_MAX_DEVS
- 1)] = 0 };
167 module_param_array(allocators
, uint
, NULL
, 0444);
168 MODULE_PARM_DESC(allocators
, " memory allocator selection, default is 0.\n"
169 "\t\t 0 == vmalloc\n"
170 "\t\t 1 == dma-contig");
172 static struct vivid_dev
*vivid_devs
[VIVID_MAX_DEVS
];
174 const struct v4l2_rect vivid_min_rect
= {
175 0, 0, MIN_WIDTH
, MIN_HEIGHT
178 const struct v4l2_rect vivid_max_rect
= {
179 0, 0, MAX_WIDTH
* MAX_ZOOM
, MAX_HEIGHT
* MAX_ZOOM
182 static const u8 vivid_hdmi_edid
[256] = {
183 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00,
184 0x31, 0xd8, 0x34, 0x12, 0x00, 0x00, 0x00, 0x00,
185 0x22, 0x1a, 0x01, 0x03, 0x80, 0x60, 0x36, 0x78,
186 0x0f, 0xee, 0x91, 0xa3, 0x54, 0x4c, 0x99, 0x26,
187 0x0f, 0x50, 0x54, 0x2f, 0xcf, 0x00, 0x31, 0x59,
188 0x45, 0x59, 0x81, 0x80, 0x81, 0x40, 0x90, 0x40,
189 0x95, 0x00, 0xa9, 0x40, 0xb3, 0x00, 0x08, 0xe8,
190 0x00, 0x30, 0xf2, 0x70, 0x5a, 0x80, 0xb0, 0x58,
191 0x8a, 0x00, 0xc0, 0x1c, 0x32, 0x00, 0x00, 0x1e,
192 0x00, 0x00, 0x00, 0xfd, 0x00, 0x18, 0x55, 0x18,
193 0x87, 0x3c, 0x00, 0x0a, 0x20, 0x20, 0x20, 0x20,
194 0x20, 0x20, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x76,
195 0x69, 0x76, 0x69, 0x64, 0x0a, 0x20, 0x20, 0x20,
196 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x10,
197 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
198 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x7b,
200 0x02, 0x03, 0x3f, 0xf0, 0x51, 0x61, 0x60, 0x5f,
201 0x5e, 0x5d, 0x10, 0x1f, 0x04, 0x13, 0x22, 0x21,
202 0x20, 0x05, 0x14, 0x02, 0x11, 0x01, 0x23, 0x09,
203 0x07, 0x07, 0x83, 0x01, 0x00, 0x00, 0x6d, 0x03,
204 0x0c, 0x00, 0x10, 0x00, 0x00, 0x3c, 0x21, 0x00,
205 0x60, 0x01, 0x02, 0x03, 0x67, 0xd8, 0x5d, 0xc4,
206 0x01, 0x78, 0x00, 0x00, 0xe2, 0x00, 0xea, 0xe3,
207 0x05, 0x00, 0x00, 0xe3, 0x06, 0x01, 0x00, 0x4d,
208 0xd0, 0x00, 0xa0, 0xf0, 0x70, 0x3e, 0x80, 0x30,
209 0x20, 0x35, 0x00, 0xc0, 0x1c, 0x32, 0x00, 0x00,
210 0x1e, 0x1a, 0x36, 0x80, 0xa0, 0x70, 0x38, 0x1f,
211 0x40, 0x30, 0x20, 0x35, 0x00, 0xc0, 0x1c, 0x32,
212 0x00, 0x00, 0x1a, 0x1a, 0x1d, 0x00, 0x80, 0x51,
213 0xd0, 0x1c, 0x20, 0x40, 0x80, 0x35, 0x00, 0xc0,
214 0x1c, 0x32, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00,
215 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63,
218 static int vidioc_querycap(struct file
*file
, void *priv
,
219 struct v4l2_capability
*cap
)
221 struct vivid_dev
*dev
= video_drvdata(file
);
223 strscpy(cap
->driver
, "vivid", sizeof(cap
->driver
));
224 strscpy(cap
->card
, "vivid", sizeof(cap
->card
));
225 snprintf(cap
->bus_info
, sizeof(cap
->bus_info
),
226 "platform:%s", dev
->v4l2_dev
.name
);
228 cap
->capabilities
= dev
->vid_cap_caps
| dev
->vid_out_caps
|
229 dev
->vbi_cap_caps
| dev
->vbi_out_caps
|
230 dev
->radio_rx_caps
| dev
->radio_tx_caps
|
231 dev
->sdr_cap_caps
| dev
->meta_cap_caps
|
232 dev
->meta_out_caps
| dev
->touch_cap_caps
|
233 V4L2_CAP_DEVICE_CAPS
;
237 static int vidioc_s_hw_freq_seek(struct file
*file
, void *fh
, const struct v4l2_hw_freq_seek
*a
)
239 struct video_device
*vdev
= video_devdata(file
);
241 if (vdev
->vfl_type
== VFL_TYPE_RADIO
)
242 return vivid_radio_rx_s_hw_freq_seek(file
, fh
, a
);
246 static int vidioc_enum_freq_bands(struct file
*file
, void *fh
, struct v4l2_frequency_band
*band
)
248 struct video_device
*vdev
= video_devdata(file
);
250 if (vdev
->vfl_type
== VFL_TYPE_RADIO
)
251 return vivid_radio_rx_enum_freq_bands(file
, fh
, band
);
252 if (vdev
->vfl_type
== VFL_TYPE_SDR
)
253 return vivid_sdr_enum_freq_bands(file
, fh
, band
);
257 static int vidioc_g_tuner(struct file
*file
, void *fh
, struct v4l2_tuner
*vt
)
259 struct video_device
*vdev
= video_devdata(file
);
261 if (vdev
->vfl_type
== VFL_TYPE_RADIO
)
262 return vivid_radio_rx_g_tuner(file
, fh
, vt
);
263 if (vdev
->vfl_type
== VFL_TYPE_SDR
)
264 return vivid_sdr_g_tuner(file
, fh
, vt
);
265 return vivid_video_g_tuner(file
, fh
, vt
);
268 static int vidioc_s_tuner(struct file
*file
, void *fh
, const struct v4l2_tuner
*vt
)
270 struct video_device
*vdev
= video_devdata(file
);
272 if (vdev
->vfl_type
== VFL_TYPE_RADIO
)
273 return vivid_radio_rx_s_tuner(file
, fh
, vt
);
274 if (vdev
->vfl_type
== VFL_TYPE_SDR
)
275 return vivid_sdr_s_tuner(file
, fh
, vt
);
276 return vivid_video_s_tuner(file
, fh
, vt
);
279 static int vidioc_g_frequency(struct file
*file
, void *fh
, struct v4l2_frequency
*vf
)
281 struct vivid_dev
*dev
= video_drvdata(file
);
282 struct video_device
*vdev
= video_devdata(file
);
284 if (vdev
->vfl_type
== VFL_TYPE_RADIO
)
285 return vivid_radio_g_frequency(file
,
286 vdev
->vfl_dir
== VFL_DIR_RX
?
287 &dev
->radio_rx_freq
: &dev
->radio_tx_freq
, vf
);
288 if (vdev
->vfl_type
== VFL_TYPE_SDR
)
289 return vivid_sdr_g_frequency(file
, fh
, vf
);
290 return vivid_video_g_frequency(file
, fh
, vf
);
293 static int vidioc_s_frequency(struct file
*file
, void *fh
, const struct v4l2_frequency
*vf
)
295 struct vivid_dev
*dev
= video_drvdata(file
);
296 struct video_device
*vdev
= video_devdata(file
);
298 if (vdev
->vfl_type
== VFL_TYPE_RADIO
)
299 return vivid_radio_s_frequency(file
,
300 vdev
->vfl_dir
== VFL_DIR_RX
?
301 &dev
->radio_rx_freq
: &dev
->radio_tx_freq
, vf
);
302 if (vdev
->vfl_type
== VFL_TYPE_SDR
)
303 return vivid_sdr_s_frequency(file
, fh
, vf
);
304 return vivid_video_s_frequency(file
, fh
, vf
);
307 static int vidioc_overlay(struct file
*file
, void *fh
, unsigned i
)
309 struct video_device
*vdev
= video_devdata(file
);
311 if (vdev
->vfl_dir
== VFL_DIR_RX
)
312 return vivid_vid_cap_overlay(file
, fh
, i
);
313 return vivid_vid_out_overlay(file
, fh
, i
);
316 static int vidioc_g_fbuf(struct file
*file
, void *fh
, struct v4l2_framebuffer
*a
)
318 struct video_device
*vdev
= video_devdata(file
);
320 if (vdev
->vfl_dir
== VFL_DIR_RX
)
321 return vivid_vid_cap_g_fbuf(file
, fh
, a
);
322 return vivid_vid_out_g_fbuf(file
, fh
, a
);
325 static int vidioc_s_fbuf(struct file
*file
, void *fh
, const struct v4l2_framebuffer
*a
)
327 struct video_device
*vdev
= video_devdata(file
);
329 if (vdev
->vfl_dir
== VFL_DIR_RX
)
330 return vivid_vid_cap_s_fbuf(file
, fh
, a
);
331 return vivid_vid_out_s_fbuf(file
, fh
, a
);
334 static int vidioc_s_std(struct file
*file
, void *fh
, v4l2_std_id id
)
336 struct video_device
*vdev
= video_devdata(file
);
338 if (vdev
->vfl_dir
== VFL_DIR_RX
)
339 return vivid_vid_cap_s_std(file
, fh
, id
);
340 return vivid_vid_out_s_std(file
, fh
, id
);
343 static int vidioc_s_dv_timings(struct file
*file
, void *fh
, struct v4l2_dv_timings
*timings
)
345 struct video_device
*vdev
= video_devdata(file
);
347 if (vdev
->vfl_dir
== VFL_DIR_RX
)
348 return vivid_vid_cap_s_dv_timings(file
, fh
, timings
);
349 return vivid_vid_out_s_dv_timings(file
, fh
, timings
);
352 static int vidioc_g_pixelaspect(struct file
*file
, void *fh
,
353 int type
, struct v4l2_fract
*f
)
355 struct video_device
*vdev
= video_devdata(file
);
357 if (vdev
->vfl_dir
== VFL_DIR_RX
)
358 return vivid_vid_cap_g_pixelaspect(file
, fh
, type
, f
);
359 return vivid_vid_out_g_pixelaspect(file
, fh
, type
, f
);
362 static int vidioc_g_selection(struct file
*file
, void *fh
,
363 struct v4l2_selection
*sel
)
365 struct video_device
*vdev
= video_devdata(file
);
367 if (vdev
->vfl_dir
== VFL_DIR_RX
)
368 return vivid_vid_cap_g_selection(file
, fh
, sel
);
369 return vivid_vid_out_g_selection(file
, fh
, sel
);
372 static int vidioc_s_selection(struct file
*file
, void *fh
,
373 struct v4l2_selection
*sel
)
375 struct video_device
*vdev
= video_devdata(file
);
377 if (vdev
->vfl_dir
== VFL_DIR_RX
)
378 return vivid_vid_cap_s_selection(file
, fh
, sel
);
379 return vivid_vid_out_s_selection(file
, fh
, sel
);
382 static int vidioc_g_parm(struct file
*file
, void *fh
,
383 struct v4l2_streamparm
*parm
)
385 struct video_device
*vdev
= video_devdata(file
);
387 if (vdev
->vfl_type
== VFL_TYPE_TOUCH
)
388 return vivid_g_parm_tch(file
, fh
, parm
);
389 if (vdev
->vfl_dir
== VFL_DIR_RX
)
390 return vivid_vid_cap_g_parm(file
, fh
, parm
);
391 return vivid_vid_out_g_parm(file
, fh
, parm
);
394 static int vidioc_s_parm(struct file
*file
, void *fh
,
395 struct v4l2_streamparm
*parm
)
397 struct video_device
*vdev
= video_devdata(file
);
399 if (vdev
->vfl_dir
== VFL_DIR_RX
)
400 return vivid_vid_cap_s_parm(file
, fh
, parm
);
404 static int vidioc_log_status(struct file
*file
, void *fh
)
406 struct vivid_dev
*dev
= video_drvdata(file
);
407 struct video_device
*vdev
= video_devdata(file
);
409 v4l2_ctrl_log_status(file
, fh
);
410 if (vdev
->vfl_dir
== VFL_DIR_RX
&& vdev
->vfl_type
== VFL_TYPE_GRABBER
)
411 tpg_log_status(&dev
->tpg
);
415 static ssize_t
vivid_radio_read(struct file
*file
, char __user
*buf
,
416 size_t size
, loff_t
*offset
)
418 struct video_device
*vdev
= video_devdata(file
);
420 if (vdev
->vfl_dir
== VFL_DIR_TX
)
422 return vivid_radio_rx_read(file
, buf
, size
, offset
);
425 static ssize_t
vivid_radio_write(struct file
*file
, const char __user
*buf
,
426 size_t size
, loff_t
*offset
)
428 struct video_device
*vdev
= video_devdata(file
);
430 if (vdev
->vfl_dir
== VFL_DIR_RX
)
432 return vivid_radio_tx_write(file
, buf
, size
, offset
);
435 static __poll_t
vivid_radio_poll(struct file
*file
, struct poll_table_struct
*wait
)
437 struct video_device
*vdev
= video_devdata(file
);
439 if (vdev
->vfl_dir
== VFL_DIR_RX
)
440 return vivid_radio_rx_poll(file
, wait
);
441 return vivid_radio_tx_poll(file
, wait
);
444 static int vivid_enum_input(struct file
*file
, void *priv
,
445 struct v4l2_input
*inp
)
447 struct video_device
*vdev
= video_devdata(file
);
449 if (vdev
->vfl_type
== VFL_TYPE_TOUCH
)
450 return vivid_enum_input_tch(file
, priv
, inp
);
451 return vidioc_enum_input(file
, priv
, inp
);
454 static int vivid_g_input(struct file
*file
, void *priv
, unsigned int *i
)
456 struct video_device
*vdev
= video_devdata(file
);
458 if (vdev
->vfl_type
== VFL_TYPE_TOUCH
)
459 return vivid_g_input_tch(file
, priv
, i
);
460 return vidioc_g_input(file
, priv
, i
);
463 static int vivid_s_input(struct file
*file
, void *priv
, unsigned int i
)
465 struct video_device
*vdev
= video_devdata(file
);
467 if (vdev
->vfl_type
== VFL_TYPE_TOUCH
)
468 return vivid_s_input_tch(file
, priv
, i
);
469 return vidioc_s_input(file
, priv
, i
);
472 static int vivid_enum_fmt_cap(struct file
*file
, void *priv
,
473 struct v4l2_fmtdesc
*f
)
475 struct video_device
*vdev
= video_devdata(file
);
477 if (vdev
->vfl_type
== VFL_TYPE_TOUCH
)
478 return vivid_enum_fmt_tch(file
, priv
, f
);
479 return vivid_enum_fmt_vid(file
, priv
, f
);
482 static int vivid_g_fmt_cap(struct file
*file
, void *priv
,
483 struct v4l2_format
*f
)
485 struct video_device
*vdev
= video_devdata(file
);
487 if (vdev
->vfl_type
== VFL_TYPE_TOUCH
)
488 return vivid_g_fmt_tch(file
, priv
, f
);
489 return vidioc_g_fmt_vid_cap(file
, priv
, f
);
492 static int vivid_try_fmt_cap(struct file
*file
, void *priv
,
493 struct v4l2_format
*f
)
495 struct video_device
*vdev
= video_devdata(file
);
497 if (vdev
->vfl_type
== VFL_TYPE_TOUCH
)
498 return vivid_g_fmt_tch(file
, priv
, f
);
499 return vidioc_try_fmt_vid_cap(file
, priv
, f
);
502 static int vivid_s_fmt_cap(struct file
*file
, void *priv
,
503 struct v4l2_format
*f
)
505 struct video_device
*vdev
= video_devdata(file
);
507 if (vdev
->vfl_type
== VFL_TYPE_TOUCH
)
508 return vivid_g_fmt_tch(file
, priv
, f
);
509 return vidioc_s_fmt_vid_cap(file
, priv
, f
);
512 static int vivid_g_fmt_cap_mplane(struct file
*file
, void *priv
,
513 struct v4l2_format
*f
)
515 struct video_device
*vdev
= video_devdata(file
);
517 if (vdev
->vfl_type
== VFL_TYPE_TOUCH
)
518 return vivid_g_fmt_tch_mplane(file
, priv
, f
);
519 return vidioc_g_fmt_vid_cap_mplane(file
, priv
, f
);
522 static int vivid_try_fmt_cap_mplane(struct file
*file
, void *priv
,
523 struct v4l2_format
*f
)
525 struct video_device
*vdev
= video_devdata(file
);
527 if (vdev
->vfl_type
== VFL_TYPE_TOUCH
)
528 return vivid_g_fmt_tch_mplane(file
, priv
, f
);
529 return vidioc_try_fmt_vid_cap_mplane(file
, priv
, f
);
532 static int vivid_s_fmt_cap_mplane(struct file
*file
, void *priv
,
533 struct v4l2_format
*f
)
535 struct video_device
*vdev
= video_devdata(file
);
537 if (vdev
->vfl_type
== VFL_TYPE_TOUCH
)
538 return vivid_g_fmt_tch_mplane(file
, priv
, f
);
539 return vidioc_s_fmt_vid_cap_mplane(file
, priv
, f
);
542 static bool vivid_is_in_use(struct video_device
*vdev
)
547 spin_lock_irqsave(&vdev
->fh_lock
, flags
);
548 res
= !list_empty(&vdev
->fh_list
);
549 spin_unlock_irqrestore(&vdev
->fh_lock
, flags
);
553 static bool vivid_is_last_user(struct vivid_dev
*dev
)
555 unsigned uses
= vivid_is_in_use(&dev
->vid_cap_dev
) +
556 vivid_is_in_use(&dev
->vid_out_dev
) +
557 vivid_is_in_use(&dev
->vbi_cap_dev
) +
558 vivid_is_in_use(&dev
->vbi_out_dev
) +
559 vivid_is_in_use(&dev
->sdr_cap_dev
) +
560 vivid_is_in_use(&dev
->radio_rx_dev
) +
561 vivid_is_in_use(&dev
->radio_tx_dev
) +
562 vivid_is_in_use(&dev
->meta_cap_dev
) +
563 vivid_is_in_use(&dev
->meta_out_dev
) +
564 vivid_is_in_use(&dev
->touch_cap_dev
);
569 static int vivid_fop_release(struct file
*file
)
571 struct vivid_dev
*dev
= video_drvdata(file
);
572 struct video_device
*vdev
= video_devdata(file
);
574 mutex_lock(&dev
->mutex
);
575 if (!no_error_inj
&& v4l2_fh_is_singular_file(file
) &&
576 !video_is_registered(vdev
) && vivid_is_last_user(dev
)) {
578 * I am the last user of this driver, and a disconnect
579 * was forced (since this video_device is unregistered),
580 * so re-register all video_device's again.
582 v4l2_info(&dev
->v4l2_dev
, "reconnect\n");
583 set_bit(V4L2_FL_REGISTERED
, &dev
->vid_cap_dev
.flags
);
584 set_bit(V4L2_FL_REGISTERED
, &dev
->vid_out_dev
.flags
);
585 set_bit(V4L2_FL_REGISTERED
, &dev
->vbi_cap_dev
.flags
);
586 set_bit(V4L2_FL_REGISTERED
, &dev
->vbi_out_dev
.flags
);
587 set_bit(V4L2_FL_REGISTERED
, &dev
->sdr_cap_dev
.flags
);
588 set_bit(V4L2_FL_REGISTERED
, &dev
->radio_rx_dev
.flags
);
589 set_bit(V4L2_FL_REGISTERED
, &dev
->radio_tx_dev
.flags
);
590 set_bit(V4L2_FL_REGISTERED
, &dev
->meta_cap_dev
.flags
);
591 set_bit(V4L2_FL_REGISTERED
, &dev
->meta_out_dev
.flags
);
592 set_bit(V4L2_FL_REGISTERED
, &dev
->touch_cap_dev
.flags
);
594 mutex_unlock(&dev
->mutex
);
595 if (file
->private_data
== dev
->overlay_cap_owner
)
596 dev
->overlay_cap_owner
= NULL
;
597 if (file
->private_data
== dev
->radio_rx_rds_owner
) {
598 dev
->radio_rx_rds_last_block
= 0;
599 dev
->radio_rx_rds_owner
= NULL
;
601 if (file
->private_data
== dev
->radio_tx_rds_owner
) {
602 dev
->radio_tx_rds_last_block
= 0;
603 dev
->radio_tx_rds_owner
= NULL
;
606 return vb2_fop_release(file
);
607 return v4l2_fh_release(file
);
610 static const struct v4l2_file_operations vivid_fops
= {
611 .owner
= THIS_MODULE
,
612 .open
= v4l2_fh_open
,
613 .release
= vivid_fop_release
,
614 .read
= vb2_fop_read
,
615 .write
= vb2_fop_write
,
616 .poll
= vb2_fop_poll
,
617 .unlocked_ioctl
= video_ioctl2
,
618 .mmap
= vb2_fop_mmap
,
621 static const struct v4l2_file_operations vivid_radio_fops
= {
622 .owner
= THIS_MODULE
,
623 .open
= v4l2_fh_open
,
624 .release
= vivid_fop_release
,
625 .read
= vivid_radio_read
,
626 .write
= vivid_radio_write
,
627 .poll
= vivid_radio_poll
,
628 .unlocked_ioctl
= video_ioctl2
,
631 static const struct v4l2_ioctl_ops vivid_ioctl_ops
= {
632 .vidioc_querycap
= vidioc_querycap
,
634 .vidioc_enum_fmt_vid_cap
= vivid_enum_fmt_cap
,
635 .vidioc_g_fmt_vid_cap
= vivid_g_fmt_cap
,
636 .vidioc_try_fmt_vid_cap
= vivid_try_fmt_cap
,
637 .vidioc_s_fmt_vid_cap
= vivid_s_fmt_cap
,
638 .vidioc_g_fmt_vid_cap_mplane
= vivid_g_fmt_cap_mplane
,
639 .vidioc_try_fmt_vid_cap_mplane
= vivid_try_fmt_cap_mplane
,
640 .vidioc_s_fmt_vid_cap_mplane
= vivid_s_fmt_cap_mplane
,
642 .vidioc_enum_fmt_vid_out
= vivid_enum_fmt_vid
,
643 .vidioc_g_fmt_vid_out
= vidioc_g_fmt_vid_out
,
644 .vidioc_try_fmt_vid_out
= vidioc_try_fmt_vid_out
,
645 .vidioc_s_fmt_vid_out
= vidioc_s_fmt_vid_out
,
646 .vidioc_g_fmt_vid_out_mplane
= vidioc_g_fmt_vid_out_mplane
,
647 .vidioc_try_fmt_vid_out_mplane
= vidioc_try_fmt_vid_out_mplane
,
648 .vidioc_s_fmt_vid_out_mplane
= vidioc_s_fmt_vid_out_mplane
,
650 .vidioc_g_selection
= vidioc_g_selection
,
651 .vidioc_s_selection
= vidioc_s_selection
,
652 .vidioc_g_pixelaspect
= vidioc_g_pixelaspect
,
654 .vidioc_g_fmt_vbi_cap
= vidioc_g_fmt_vbi_cap
,
655 .vidioc_try_fmt_vbi_cap
= vidioc_g_fmt_vbi_cap
,
656 .vidioc_s_fmt_vbi_cap
= vidioc_s_fmt_vbi_cap
,
658 .vidioc_g_fmt_sliced_vbi_cap
= vidioc_g_fmt_sliced_vbi_cap
,
659 .vidioc_try_fmt_sliced_vbi_cap
= vidioc_try_fmt_sliced_vbi_cap
,
660 .vidioc_s_fmt_sliced_vbi_cap
= vidioc_s_fmt_sliced_vbi_cap
,
661 .vidioc_g_sliced_vbi_cap
= vidioc_g_sliced_vbi_cap
,
663 .vidioc_g_fmt_vbi_out
= vidioc_g_fmt_vbi_out
,
664 .vidioc_try_fmt_vbi_out
= vidioc_g_fmt_vbi_out
,
665 .vidioc_s_fmt_vbi_out
= vidioc_s_fmt_vbi_out
,
667 .vidioc_g_fmt_sliced_vbi_out
= vidioc_g_fmt_sliced_vbi_out
,
668 .vidioc_try_fmt_sliced_vbi_out
= vidioc_try_fmt_sliced_vbi_out
,
669 .vidioc_s_fmt_sliced_vbi_out
= vidioc_s_fmt_sliced_vbi_out
,
671 .vidioc_enum_fmt_sdr_cap
= vidioc_enum_fmt_sdr_cap
,
672 .vidioc_g_fmt_sdr_cap
= vidioc_g_fmt_sdr_cap
,
673 .vidioc_try_fmt_sdr_cap
= vidioc_try_fmt_sdr_cap
,
674 .vidioc_s_fmt_sdr_cap
= vidioc_s_fmt_sdr_cap
,
676 .vidioc_overlay
= vidioc_overlay
,
677 .vidioc_enum_framesizes
= vidioc_enum_framesizes
,
678 .vidioc_enum_frameintervals
= vidioc_enum_frameintervals
,
679 .vidioc_g_parm
= vidioc_g_parm
,
680 .vidioc_s_parm
= vidioc_s_parm
,
682 .vidioc_enum_fmt_vid_overlay
= vidioc_enum_fmt_vid_overlay
,
683 .vidioc_g_fmt_vid_overlay
= vidioc_g_fmt_vid_overlay
,
684 .vidioc_try_fmt_vid_overlay
= vidioc_try_fmt_vid_overlay
,
685 .vidioc_s_fmt_vid_overlay
= vidioc_s_fmt_vid_overlay
,
686 .vidioc_g_fmt_vid_out_overlay
= vidioc_g_fmt_vid_out_overlay
,
687 .vidioc_try_fmt_vid_out_overlay
= vidioc_try_fmt_vid_out_overlay
,
688 .vidioc_s_fmt_vid_out_overlay
= vidioc_s_fmt_vid_out_overlay
,
689 .vidioc_g_fbuf
= vidioc_g_fbuf
,
690 .vidioc_s_fbuf
= vidioc_s_fbuf
,
692 .vidioc_reqbufs
= vb2_ioctl_reqbufs
,
693 .vidioc_create_bufs
= vb2_ioctl_create_bufs
,
694 .vidioc_prepare_buf
= vb2_ioctl_prepare_buf
,
695 .vidioc_querybuf
= vb2_ioctl_querybuf
,
696 .vidioc_qbuf
= vb2_ioctl_qbuf
,
697 .vidioc_dqbuf
= vb2_ioctl_dqbuf
,
698 .vidioc_expbuf
= vb2_ioctl_expbuf
,
699 .vidioc_streamon
= vb2_ioctl_streamon
,
700 .vidioc_streamoff
= vb2_ioctl_streamoff
,
702 .vidioc_enum_input
= vivid_enum_input
,
703 .vidioc_g_input
= vivid_g_input
,
704 .vidioc_s_input
= vivid_s_input
,
705 .vidioc_s_audio
= vidioc_s_audio
,
706 .vidioc_g_audio
= vidioc_g_audio
,
707 .vidioc_enumaudio
= vidioc_enumaudio
,
708 .vidioc_s_frequency
= vidioc_s_frequency
,
709 .vidioc_g_frequency
= vidioc_g_frequency
,
710 .vidioc_s_tuner
= vidioc_s_tuner
,
711 .vidioc_g_tuner
= vidioc_g_tuner
,
712 .vidioc_s_modulator
= vidioc_s_modulator
,
713 .vidioc_g_modulator
= vidioc_g_modulator
,
714 .vidioc_s_hw_freq_seek
= vidioc_s_hw_freq_seek
,
715 .vidioc_enum_freq_bands
= vidioc_enum_freq_bands
,
717 .vidioc_enum_output
= vidioc_enum_output
,
718 .vidioc_g_output
= vidioc_g_output
,
719 .vidioc_s_output
= vidioc_s_output
,
720 .vidioc_s_audout
= vidioc_s_audout
,
721 .vidioc_g_audout
= vidioc_g_audout
,
722 .vidioc_enumaudout
= vidioc_enumaudout
,
724 .vidioc_querystd
= vidioc_querystd
,
725 .vidioc_g_std
= vidioc_g_std
,
726 .vidioc_s_std
= vidioc_s_std
,
727 .vidioc_s_dv_timings
= vidioc_s_dv_timings
,
728 .vidioc_g_dv_timings
= vidioc_g_dv_timings
,
729 .vidioc_query_dv_timings
= vidioc_query_dv_timings
,
730 .vidioc_enum_dv_timings
= vidioc_enum_dv_timings
,
731 .vidioc_dv_timings_cap
= vidioc_dv_timings_cap
,
732 .vidioc_g_edid
= vidioc_g_edid
,
733 .vidioc_s_edid
= vidioc_s_edid
,
735 .vidioc_log_status
= vidioc_log_status
,
736 .vidioc_subscribe_event
= vidioc_subscribe_event
,
737 .vidioc_unsubscribe_event
= v4l2_event_unsubscribe
,
739 .vidioc_enum_fmt_meta_cap
= vidioc_enum_fmt_meta_cap
,
740 .vidioc_g_fmt_meta_cap
= vidioc_g_fmt_meta_cap
,
741 .vidioc_s_fmt_meta_cap
= vidioc_g_fmt_meta_cap
,
742 .vidioc_try_fmt_meta_cap
= vidioc_g_fmt_meta_cap
,
744 .vidioc_enum_fmt_meta_out
= vidioc_enum_fmt_meta_out
,
745 .vidioc_g_fmt_meta_out
= vidioc_g_fmt_meta_out
,
746 .vidioc_s_fmt_meta_out
= vidioc_g_fmt_meta_out
,
747 .vidioc_try_fmt_meta_out
= vidioc_g_fmt_meta_out
,
750 /* -----------------------------------------------------------------
751 Initialization and module stuff
752 ------------------------------------------------------------------*/
754 static void vivid_dev_release(struct v4l2_device
*v4l2_dev
)
756 struct vivid_dev
*dev
= container_of(v4l2_dev
, struct vivid_dev
, v4l2_dev
);
758 vivid_free_controls(dev
);
759 v4l2_device_unregister(&dev
->v4l2_dev
);
760 #ifdef CONFIG_MEDIA_CONTROLLER
761 media_device_cleanup(&dev
->mdev
);
763 vfree(dev
->scaled_line
);
764 vfree(dev
->blended_line
);
766 vfree(dev
->bitmap_cap
);
767 vfree(dev
->bitmap_out
);
769 kfree(dev
->query_dv_timings_qmenu
);
770 kfree(dev
->query_dv_timings_qmenu_strings
);
774 #ifdef CONFIG_MEDIA_CONTROLLER
775 static int vivid_req_validate(struct media_request
*req
)
777 struct vivid_dev
*dev
= container_of(req
->mdev
, struct vivid_dev
, mdev
);
779 if (dev
->req_validate_error
) {
780 dev
->req_validate_error
= false;
783 return vb2_request_validate(req
);
786 static const struct media_device_ops vivid_media_ops
= {
787 .req_validate
= vivid_req_validate
,
788 .req_queue
= vb2_request_queue
,
792 static int vivid_create_queue(struct vivid_dev
*dev
,
795 unsigned int min_buffers_needed
,
796 const struct vb2_ops
*ops
)
798 if (buf_type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
&& dev
->multiplanar
)
799 buf_type
= V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
;
800 else if (buf_type
== V4L2_BUF_TYPE_VIDEO_OUTPUT
&& dev
->multiplanar
)
801 buf_type
= V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
;
802 else if (buf_type
== V4L2_BUF_TYPE_VBI_CAPTURE
&& !dev
->has_raw_vbi_cap
)
803 buf_type
= V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
;
804 else if (buf_type
== V4L2_BUF_TYPE_VBI_OUTPUT
&& !dev
->has_raw_vbi_out
)
805 buf_type
= V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
;
808 q
->io_modes
= VB2_MMAP
| VB2_DMABUF
;
809 q
->io_modes
|= V4L2_TYPE_IS_OUTPUT(buf_type
) ? VB2_WRITE
: VB2_READ
;
810 if (allocators
[dev
->inst
] != 1)
811 q
->io_modes
|= VB2_USERPTR
;
813 q
->buf_struct_size
= sizeof(struct vivid_buffer
);
815 q
->mem_ops
= allocators
[dev
->inst
] == 1 ? &vb2_dma_contig_memops
:
817 q
->timestamp_flags
= V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC
;
818 q
->min_buffers_needed
= min_buffers_needed
;
819 q
->lock
= &dev
->mutex
;
820 q
->dev
= dev
->v4l2_dev
.dev
;
821 q
->supports_requests
= true;
823 return vb2_queue_init(q
);
826 static int vivid_create_instance(struct platform_device
*pdev
, int inst
)
828 static const struct v4l2_dv_timings def_dv_timings
=
829 V4L2_DV_BT_CEA_1280X720P60
;
830 unsigned in_type_counter
[4] = { 0, 0, 0, 0 };
831 unsigned out_type_counter
[4] = { 0, 0, 0, 0 };
832 int ccs_cap
= ccs_cap_mode
[inst
];
833 int ccs_out
= ccs_out_mode
[inst
];
836 struct vivid_dev
*dev
;
837 struct video_device
*vfd
;
838 unsigned node_type
= node_types
[inst
];
839 v4l2_std_id tvnorms_cap
= 0, tvnorms_out
= 0;
842 #ifdef CONFIG_VIDEO_VIVID_CEC
843 unsigned int cec_tx_bus_cnt
= 0;
846 /* allocate main vivid state structure */
847 dev
= kzalloc(sizeof(*dev
), GFP_KERNEL
);
853 #ifdef CONFIG_MEDIA_CONTROLLER
854 dev
->v4l2_dev
.mdev
= &dev
->mdev
;
856 /* Initialize media device */
857 strscpy(dev
->mdev
.model
, VIVID_MODULE_NAME
, sizeof(dev
->mdev
.model
));
858 snprintf(dev
->mdev
.bus_info
, sizeof(dev
->mdev
.bus_info
),
859 "platform:%s-%03d", VIVID_MODULE_NAME
, inst
);
860 dev
->mdev
.dev
= &pdev
->dev
;
861 media_device_init(&dev
->mdev
);
862 dev
->mdev
.ops
= &vivid_media_ops
;
865 /* register v4l2_device */
866 snprintf(dev
->v4l2_dev
.name
, sizeof(dev
->v4l2_dev
.name
),
867 "%s-%03d", VIVID_MODULE_NAME
, inst
);
868 ret
= v4l2_device_register(&pdev
->dev
, &dev
->v4l2_dev
);
873 dev
->v4l2_dev
.release
= vivid_dev_release
;
875 /* start detecting feature set */
877 /* do we use single- or multi-planar? */
878 dev
->multiplanar
= multiplanar
[inst
] > 1;
879 v4l2_info(&dev
->v4l2_dev
, "using %splanar format API\n",
880 dev
->multiplanar
? "multi" : "single ");
882 /* how many inputs do we have and of what type? */
883 dev
->num_inputs
= num_inputs
[inst
];
884 if (dev
->num_inputs
< 1)
886 if (dev
->num_inputs
>= MAX_INPUTS
)
887 dev
->num_inputs
= MAX_INPUTS
;
888 for (i
= 0; i
< dev
->num_inputs
; i
++) {
889 dev
->input_type
[i
] = (input_types
[inst
] >> (i
* 2)) & 0x3;
890 dev
->input_name_counter
[i
] = in_type_counter
[dev
->input_type
[i
]]++;
892 dev
->has_audio_inputs
= in_type_counter
[TV
] && in_type_counter
[SVID
];
893 if (in_type_counter
[HDMI
] == 16) {
894 /* The CEC physical address only allows for max 15 inputs */
895 in_type_counter
[HDMI
]--;
898 dev
->num_hdmi_inputs
= in_type_counter
[HDMI
];
900 /* how many outputs do we have and of what type? */
901 dev
->num_outputs
= num_outputs
[inst
];
902 if (dev
->num_outputs
< 1)
903 dev
->num_outputs
= 1;
904 if (dev
->num_outputs
>= MAX_OUTPUTS
)
905 dev
->num_outputs
= MAX_OUTPUTS
;
906 for (i
= 0; i
< dev
->num_outputs
; i
++) {
907 dev
->output_type
[i
] = ((output_types
[inst
] >> i
) & 1) ? HDMI
: SVID
;
908 dev
->output_name_counter
[i
] = out_type_counter
[dev
->output_type
[i
]]++;
909 dev
->display_present
[i
] = true;
911 dev
->has_audio_outputs
= out_type_counter
[SVID
];
912 if (out_type_counter
[HDMI
] == 16) {
914 * The CEC physical address only allows for max 15 inputs,
915 * so outputs are also limited to 15 to allow for easy
916 * CEC output to input mapping.
918 out_type_counter
[HDMI
]--;
921 dev
->num_hdmi_outputs
= out_type_counter
[HDMI
];
923 /* do we create a video capture device? */
924 dev
->has_vid_cap
= node_type
& 0x0001;
926 /* do we create a vbi capture device? */
927 if (in_type_counter
[TV
] || in_type_counter
[SVID
]) {
928 dev
->has_raw_vbi_cap
= node_type
& 0x0004;
929 dev
->has_sliced_vbi_cap
= node_type
& 0x0008;
930 dev
->has_vbi_cap
= dev
->has_raw_vbi_cap
| dev
->has_sliced_vbi_cap
;
933 /* do we create a meta capture device */
934 dev
->has_meta_cap
= node_type
& 0x20000;
937 if ((in_type_counter
[WEBCAM
] || in_type_counter
[HDMI
]) &&
938 !dev
->has_vid_cap
&& !dev
->has_meta_cap
) {
939 v4l2_warn(&dev
->v4l2_dev
,
940 "Webcam or HDMI input without video or metadata nodes\n");
944 if ((in_type_counter
[TV
] || in_type_counter
[SVID
]) &&
945 !dev
->has_vid_cap
&& !dev
->has_vbi_cap
&& !dev
->has_meta_cap
) {
946 v4l2_warn(&dev
->v4l2_dev
,
947 "TV or S-Video input without video, VBI or metadata nodes\n");
952 /* do we create a video output device? */
953 dev
->has_vid_out
= node_type
& 0x0100;
955 /* do we create a vbi output device? */
956 if (out_type_counter
[SVID
]) {
957 dev
->has_raw_vbi_out
= node_type
& 0x0400;
958 dev
->has_sliced_vbi_out
= node_type
& 0x0800;
959 dev
->has_vbi_out
= dev
->has_raw_vbi_out
| dev
->has_sliced_vbi_out
;
962 /* do we create a metadata output device */
963 dev
->has_meta_out
= node_type
& 0x40000;
966 if (out_type_counter
[SVID
] &&
967 !dev
->has_vid_out
&& !dev
->has_vbi_out
&& !dev
->has_meta_out
) {
968 v4l2_warn(&dev
->v4l2_dev
,
969 "S-Video output without video, VBI or metadata nodes\n");
973 if (out_type_counter
[HDMI
] && !dev
->has_vid_out
&& !dev
->has_meta_out
) {
974 v4l2_warn(&dev
->v4l2_dev
,
975 "HDMI output without video or metadata nodes\n");
980 /* do we create a radio receiver device? */
981 dev
->has_radio_rx
= node_type
& 0x0010;
983 /* do we create a radio transmitter device? */
984 dev
->has_radio_tx
= node_type
& 0x1000;
986 /* do we create a software defined radio capture device? */
987 dev
->has_sdr_cap
= node_type
& 0x0020;
989 /* do we have a TV tuner? */
990 dev
->has_tv_tuner
= in_type_counter
[TV
];
992 /* do we have a tuner? */
993 has_tuner
= ((dev
->has_vid_cap
|| dev
->has_vbi_cap
) && in_type_counter
[TV
]) ||
994 dev
->has_radio_rx
|| dev
->has_sdr_cap
;
996 /* do we have a modulator? */
997 has_modulator
= dev
->has_radio_tx
;
999 if (dev
->has_vid_cap
)
1000 /* do we have a framebuffer for overlay testing? */
1001 dev
->has_fb
= node_type
& 0x10000;
1003 /* can we do crop/compose/scaling while capturing? */
1004 if (no_error_inj
&& ccs_cap
== -1)
1007 /* if ccs_cap == -1, then the user can select it using controls */
1008 if (ccs_cap
!= -1) {
1009 dev
->has_crop_cap
= ccs_cap
& 1;
1010 dev
->has_compose_cap
= ccs_cap
& 2;
1011 dev
->has_scaler_cap
= ccs_cap
& 4;
1012 v4l2_info(&dev
->v4l2_dev
, "Capture Crop: %c Compose: %c Scaler: %c\n",
1013 dev
->has_crop_cap
? 'Y' : 'N',
1014 dev
->has_compose_cap
? 'Y' : 'N',
1015 dev
->has_scaler_cap
? 'Y' : 'N');
1018 /* can we do crop/compose/scaling with video output? */
1019 if (no_error_inj
&& ccs_out
== -1)
1022 /* if ccs_out == -1, then the user can select it using controls */
1023 if (ccs_out
!= -1) {
1024 dev
->has_crop_out
= ccs_out
& 1;
1025 dev
->has_compose_out
= ccs_out
& 2;
1026 dev
->has_scaler_out
= ccs_out
& 4;
1027 v4l2_info(&dev
->v4l2_dev
, "Output Crop: %c Compose: %c Scaler: %c\n",
1028 dev
->has_crop_out
? 'Y' : 'N',
1029 dev
->has_compose_out
? 'Y' : 'N',
1030 dev
->has_scaler_out
? 'Y' : 'N');
1033 /* do we create a touch capture device */
1034 dev
->has_touch_cap
= node_type
& 0x80000;
1036 /* end detecting feature set */
1038 if (dev
->has_vid_cap
) {
1039 /* set up the capabilities of the video capture device */
1040 dev
->vid_cap_caps
= dev
->multiplanar
?
1041 V4L2_CAP_VIDEO_CAPTURE_MPLANE
:
1042 V4L2_CAP_VIDEO_CAPTURE
| V4L2_CAP_VIDEO_OVERLAY
;
1043 dev
->vid_cap_caps
|= V4L2_CAP_STREAMING
| V4L2_CAP_READWRITE
;
1044 if (dev
->has_audio_inputs
)
1045 dev
->vid_cap_caps
|= V4L2_CAP_AUDIO
;
1046 if (dev
->has_tv_tuner
)
1047 dev
->vid_cap_caps
|= V4L2_CAP_TUNER
;
1049 if (dev
->has_vid_out
) {
1050 /* set up the capabilities of the video output device */
1051 dev
->vid_out_caps
= dev
->multiplanar
?
1052 V4L2_CAP_VIDEO_OUTPUT_MPLANE
:
1053 V4L2_CAP_VIDEO_OUTPUT
;
1055 dev
->vid_out_caps
|= V4L2_CAP_VIDEO_OUTPUT_OVERLAY
;
1056 dev
->vid_out_caps
|= V4L2_CAP_STREAMING
| V4L2_CAP_READWRITE
;
1057 if (dev
->has_audio_outputs
)
1058 dev
->vid_out_caps
|= V4L2_CAP_AUDIO
;
1060 if (dev
->has_vbi_cap
) {
1061 /* set up the capabilities of the vbi capture device */
1062 dev
->vbi_cap_caps
= (dev
->has_raw_vbi_cap
? V4L2_CAP_VBI_CAPTURE
: 0) |
1063 (dev
->has_sliced_vbi_cap
? V4L2_CAP_SLICED_VBI_CAPTURE
: 0);
1064 dev
->vbi_cap_caps
|= V4L2_CAP_STREAMING
| V4L2_CAP_READWRITE
;
1065 if (dev
->has_audio_inputs
)
1066 dev
->vbi_cap_caps
|= V4L2_CAP_AUDIO
;
1067 if (dev
->has_tv_tuner
)
1068 dev
->vbi_cap_caps
|= V4L2_CAP_TUNER
;
1070 if (dev
->has_vbi_out
) {
1071 /* set up the capabilities of the vbi output device */
1072 dev
->vbi_out_caps
= (dev
->has_raw_vbi_out
? V4L2_CAP_VBI_OUTPUT
: 0) |
1073 (dev
->has_sliced_vbi_out
? V4L2_CAP_SLICED_VBI_OUTPUT
: 0);
1074 dev
->vbi_out_caps
|= V4L2_CAP_STREAMING
| V4L2_CAP_READWRITE
;
1075 if (dev
->has_audio_outputs
)
1076 dev
->vbi_out_caps
|= V4L2_CAP_AUDIO
;
1078 if (dev
->has_sdr_cap
) {
1079 /* set up the capabilities of the sdr capture device */
1080 dev
->sdr_cap_caps
= V4L2_CAP_SDR_CAPTURE
| V4L2_CAP_TUNER
;
1081 dev
->sdr_cap_caps
|= V4L2_CAP_STREAMING
| V4L2_CAP_READWRITE
;
1083 /* set up the capabilities of the radio receiver device */
1084 if (dev
->has_radio_rx
)
1085 dev
->radio_rx_caps
= V4L2_CAP_RADIO
| V4L2_CAP_RDS_CAPTURE
|
1086 V4L2_CAP_HW_FREQ_SEEK
| V4L2_CAP_TUNER
|
1088 /* set up the capabilities of the radio transmitter device */
1089 if (dev
->has_radio_tx
)
1090 dev
->radio_tx_caps
= V4L2_CAP_RDS_OUTPUT
| V4L2_CAP_MODULATOR
|
1093 /* set up the capabilities of meta capture device */
1094 if (dev
->has_meta_cap
) {
1095 dev
->meta_cap_caps
= V4L2_CAP_META_CAPTURE
|
1096 V4L2_CAP_STREAMING
| V4L2_CAP_READWRITE
;
1097 if (dev
->has_audio_inputs
)
1098 dev
->meta_cap_caps
|= V4L2_CAP_AUDIO
;
1099 if (dev
->has_tv_tuner
)
1100 dev
->meta_cap_caps
|= V4L2_CAP_TUNER
;
1102 /* set up the capabilities of meta output device */
1103 if (dev
->has_meta_out
) {
1104 dev
->meta_out_caps
= V4L2_CAP_META_OUTPUT
|
1105 V4L2_CAP_STREAMING
| V4L2_CAP_READWRITE
;
1106 if (dev
->has_audio_outputs
)
1107 dev
->meta_out_caps
|= V4L2_CAP_AUDIO
;
1109 /* set up the capabilities of the touch capture device */
1110 if (dev
->has_touch_cap
) {
1111 dev
->touch_cap_caps
= V4L2_CAP_TOUCH
| V4L2_CAP_STREAMING
|
1113 dev
->touch_cap_caps
|= dev
->multiplanar
?
1114 V4L2_CAP_VIDEO_CAPTURE_MPLANE
: V4L2_CAP_VIDEO_CAPTURE
;
1118 /* initialize the test pattern generator */
1119 tpg_init(&dev
->tpg
, 640, 360);
1120 if (tpg_alloc(&dev
->tpg
, MAX_ZOOM
* MAX_WIDTH
))
1122 dev
->scaled_line
= vzalloc(array_size(MAX_WIDTH
, MAX_ZOOM
));
1123 if (!dev
->scaled_line
)
1125 dev
->blended_line
= vzalloc(array_size(MAX_WIDTH
, MAX_ZOOM
));
1126 if (!dev
->blended_line
)
1130 dev
->edid
= vmalloc(256 * 128);
1134 while (v4l2_dv_timings_presets
[dev
->query_dv_timings_size
].bt
.width
)
1135 dev
->query_dv_timings_size
++;
1138 * Create a char pointer array that points to the names of all the
1141 dev
->query_dv_timings_qmenu
= kmalloc_array(dev
->query_dv_timings_size
,
1142 sizeof(char *), GFP_KERNEL
);
1144 * Create a string array containing the names of all the preset
1145 * timings. Each name is max 31 chars long (+ terminating 0).
1147 dev
->query_dv_timings_qmenu_strings
=
1148 kmalloc_array(dev
->query_dv_timings_size
, 32, GFP_KERNEL
);
1150 if (!dev
->query_dv_timings_qmenu
||
1151 !dev
->query_dv_timings_qmenu_strings
)
1154 for (i
= 0; i
< dev
->query_dv_timings_size
; i
++) {
1155 const struct v4l2_bt_timings
*bt
= &v4l2_dv_timings_presets
[i
].bt
;
1156 char *p
= dev
->query_dv_timings_qmenu_strings
+ i
* 32;
1159 dev
->query_dv_timings_qmenu
[i
] = p
;
1161 htot
= V4L2_DV_BT_FRAME_WIDTH(bt
);
1162 vtot
= V4L2_DV_BT_FRAME_HEIGHT(bt
);
1163 snprintf(p
, 32, "%ux%u%s%u",
1164 bt
->width
, bt
->height
, bt
->interlaced
? "i" : "p",
1165 (u32
)bt
->pixelclock
/ (htot
* vtot
));
1168 /* disable invalid ioctls based on the feature set */
1169 if (!dev
->has_audio_inputs
) {
1170 v4l2_disable_ioctl(&dev
->vid_cap_dev
, VIDIOC_S_AUDIO
);
1171 v4l2_disable_ioctl(&dev
->vid_cap_dev
, VIDIOC_G_AUDIO
);
1172 v4l2_disable_ioctl(&dev
->vid_cap_dev
, VIDIOC_ENUMAUDIO
);
1173 v4l2_disable_ioctl(&dev
->vbi_cap_dev
, VIDIOC_S_AUDIO
);
1174 v4l2_disable_ioctl(&dev
->vbi_cap_dev
, VIDIOC_G_AUDIO
);
1175 v4l2_disable_ioctl(&dev
->vbi_cap_dev
, VIDIOC_ENUMAUDIO
);
1176 v4l2_disable_ioctl(&dev
->meta_cap_dev
, VIDIOC_S_AUDIO
);
1177 v4l2_disable_ioctl(&dev
->meta_cap_dev
, VIDIOC_G_AUDIO
);
1178 v4l2_disable_ioctl(&dev
->meta_cap_dev
, VIDIOC_ENUMAUDIO
);
1180 if (!dev
->has_audio_outputs
) {
1181 v4l2_disable_ioctl(&dev
->vid_out_dev
, VIDIOC_S_AUDOUT
);
1182 v4l2_disable_ioctl(&dev
->vid_out_dev
, VIDIOC_G_AUDOUT
);
1183 v4l2_disable_ioctl(&dev
->vid_out_dev
, VIDIOC_ENUMAUDOUT
);
1184 v4l2_disable_ioctl(&dev
->vbi_out_dev
, VIDIOC_S_AUDOUT
);
1185 v4l2_disable_ioctl(&dev
->vbi_out_dev
, VIDIOC_G_AUDOUT
);
1186 v4l2_disable_ioctl(&dev
->vbi_out_dev
, VIDIOC_ENUMAUDOUT
);
1187 v4l2_disable_ioctl(&dev
->meta_out_dev
, VIDIOC_S_AUDOUT
);
1188 v4l2_disable_ioctl(&dev
->meta_out_dev
, VIDIOC_G_AUDOUT
);
1189 v4l2_disable_ioctl(&dev
->meta_out_dev
, VIDIOC_ENUMAUDOUT
);
1191 if (!in_type_counter
[TV
] && !in_type_counter
[SVID
]) {
1192 v4l2_disable_ioctl(&dev
->vid_cap_dev
, VIDIOC_S_STD
);
1193 v4l2_disable_ioctl(&dev
->vid_cap_dev
, VIDIOC_G_STD
);
1194 v4l2_disable_ioctl(&dev
->vid_cap_dev
, VIDIOC_ENUMSTD
);
1195 v4l2_disable_ioctl(&dev
->vid_cap_dev
, VIDIOC_QUERYSTD
);
1197 if (!out_type_counter
[SVID
]) {
1198 v4l2_disable_ioctl(&dev
->vid_out_dev
, VIDIOC_S_STD
);
1199 v4l2_disable_ioctl(&dev
->vid_out_dev
, VIDIOC_G_STD
);
1200 v4l2_disable_ioctl(&dev
->vid_out_dev
, VIDIOC_ENUMSTD
);
1202 if (!has_tuner
&& !has_modulator
) {
1203 v4l2_disable_ioctl(&dev
->vid_cap_dev
, VIDIOC_S_FREQUENCY
);
1204 v4l2_disable_ioctl(&dev
->vid_cap_dev
, VIDIOC_G_FREQUENCY
);
1205 v4l2_disable_ioctl(&dev
->vbi_cap_dev
, VIDIOC_S_FREQUENCY
);
1206 v4l2_disable_ioctl(&dev
->vbi_cap_dev
, VIDIOC_G_FREQUENCY
);
1207 v4l2_disable_ioctl(&dev
->meta_cap_dev
, VIDIOC_S_FREQUENCY
);
1208 v4l2_disable_ioctl(&dev
->meta_cap_dev
, VIDIOC_G_FREQUENCY
);
1211 v4l2_disable_ioctl(&dev
->vid_cap_dev
, VIDIOC_S_TUNER
);
1212 v4l2_disable_ioctl(&dev
->vid_cap_dev
, VIDIOC_G_TUNER
);
1213 v4l2_disable_ioctl(&dev
->vbi_cap_dev
, VIDIOC_S_TUNER
);
1214 v4l2_disable_ioctl(&dev
->vbi_cap_dev
, VIDIOC_G_TUNER
);
1215 v4l2_disable_ioctl(&dev
->meta_cap_dev
, VIDIOC_S_TUNER
);
1216 v4l2_disable_ioctl(&dev
->meta_cap_dev
, VIDIOC_G_TUNER
);
1218 if (in_type_counter
[HDMI
] == 0) {
1219 v4l2_disable_ioctl(&dev
->vid_cap_dev
, VIDIOC_S_EDID
);
1220 v4l2_disable_ioctl(&dev
->vid_cap_dev
, VIDIOC_G_EDID
);
1221 v4l2_disable_ioctl(&dev
->vid_cap_dev
, VIDIOC_DV_TIMINGS_CAP
);
1222 v4l2_disable_ioctl(&dev
->vid_cap_dev
, VIDIOC_G_DV_TIMINGS
);
1223 v4l2_disable_ioctl(&dev
->vid_cap_dev
, VIDIOC_S_DV_TIMINGS
);
1224 v4l2_disable_ioctl(&dev
->vid_cap_dev
, VIDIOC_ENUM_DV_TIMINGS
);
1225 v4l2_disable_ioctl(&dev
->vid_cap_dev
, VIDIOC_QUERY_DV_TIMINGS
);
1227 if (out_type_counter
[HDMI
] == 0) {
1228 v4l2_disable_ioctl(&dev
->vid_out_dev
, VIDIOC_G_EDID
);
1229 v4l2_disable_ioctl(&dev
->vid_out_dev
, VIDIOC_DV_TIMINGS_CAP
);
1230 v4l2_disable_ioctl(&dev
->vid_out_dev
, VIDIOC_G_DV_TIMINGS
);
1231 v4l2_disable_ioctl(&dev
->vid_out_dev
, VIDIOC_S_DV_TIMINGS
);
1232 v4l2_disable_ioctl(&dev
->vid_out_dev
, VIDIOC_ENUM_DV_TIMINGS
);
1235 v4l2_disable_ioctl(&dev
->vid_out_dev
, VIDIOC_G_FBUF
);
1236 v4l2_disable_ioctl(&dev
->vid_out_dev
, VIDIOC_S_FBUF
);
1237 v4l2_disable_ioctl(&dev
->vid_out_dev
, VIDIOC_OVERLAY
);
1239 v4l2_disable_ioctl(&dev
->vid_cap_dev
, VIDIOC_S_HW_FREQ_SEEK
);
1240 v4l2_disable_ioctl(&dev
->vbi_cap_dev
, VIDIOC_S_HW_FREQ_SEEK
);
1241 v4l2_disable_ioctl(&dev
->sdr_cap_dev
, VIDIOC_S_HW_FREQ_SEEK
);
1242 v4l2_disable_ioctl(&dev
->meta_cap_dev
, VIDIOC_S_HW_FREQ_SEEK
);
1243 v4l2_disable_ioctl(&dev
->vid_out_dev
, VIDIOC_S_FREQUENCY
);
1244 v4l2_disable_ioctl(&dev
->vid_out_dev
, VIDIOC_G_FREQUENCY
);
1245 v4l2_disable_ioctl(&dev
->vid_out_dev
, VIDIOC_ENUM_FRAMESIZES
);
1246 v4l2_disable_ioctl(&dev
->vid_out_dev
, VIDIOC_ENUM_FRAMEINTERVALS
);
1247 v4l2_disable_ioctl(&dev
->vbi_out_dev
, VIDIOC_S_FREQUENCY
);
1248 v4l2_disable_ioctl(&dev
->vbi_out_dev
, VIDIOC_G_FREQUENCY
);
1249 v4l2_disable_ioctl(&dev
->meta_out_dev
, VIDIOC_S_FREQUENCY
);
1250 v4l2_disable_ioctl(&dev
->meta_out_dev
, VIDIOC_G_FREQUENCY
);
1251 v4l2_disable_ioctl(&dev
->touch_cap_dev
, VIDIOC_S_PARM
);
1252 v4l2_disable_ioctl(&dev
->touch_cap_dev
, VIDIOC_ENUM_FRAMESIZES
);
1253 v4l2_disable_ioctl(&dev
->touch_cap_dev
, VIDIOC_ENUM_FRAMEINTERVALS
);
1255 /* configure internal data */
1256 dev
->fmt_cap
= &vivid_formats
[0];
1257 dev
->fmt_out
= &vivid_formats
[0];
1258 if (!dev
->multiplanar
)
1259 vivid_formats
[0].data_offset
[0] = 0;
1260 dev
->webcam_size_idx
= 1;
1261 dev
->webcam_ival_idx
= 3;
1262 tpg_s_fourcc(&dev
->tpg
, dev
->fmt_cap
->fourcc
);
1263 dev
->std_out
= V4L2_STD_PAL
;
1264 if (dev
->input_type
[0] == TV
|| dev
->input_type
[0] == SVID
)
1265 tvnorms_cap
= V4L2_STD_ALL
;
1266 if (dev
->output_type
[0] == SVID
)
1267 tvnorms_out
= V4L2_STD_ALL
;
1268 for (i
= 0; i
< MAX_INPUTS
; i
++) {
1269 dev
->dv_timings_cap
[i
] = def_dv_timings
;
1270 dev
->std_cap
[i
] = V4L2_STD_PAL
;
1272 dev
->dv_timings_out
= def_dv_timings
;
1273 dev
->tv_freq
= 2804 /* 175.25 * 16 */;
1274 dev
->tv_audmode
= V4L2_TUNER_MODE_STEREO
;
1275 dev
->tv_field_cap
= V4L2_FIELD_INTERLACED
;
1276 dev
->tv_field_out
= V4L2_FIELD_INTERLACED
;
1277 dev
->radio_rx_freq
= 95000 * 16;
1278 dev
->radio_rx_audmode
= V4L2_TUNER_MODE_STEREO
;
1279 if (dev
->has_radio_tx
) {
1280 dev
->radio_tx_freq
= 95500 * 16;
1281 dev
->radio_rds_loop
= false;
1283 dev
->radio_tx_subchans
= V4L2_TUNER_SUB_STEREO
| V4L2_TUNER_SUB_RDS
;
1284 dev
->sdr_adc_freq
= 300000;
1285 dev
->sdr_fm_freq
= 50000000;
1286 dev
->sdr_pixelformat
= V4L2_SDR_FMT_CU8
;
1287 dev
->sdr_buffersize
= SDR_CAP_SAMPLES_PER_BUF
* 2;
1289 dev
->edid_max_blocks
= dev
->edid_blocks
= 2;
1290 memcpy(dev
->edid
, vivid_hdmi_edid
, sizeof(vivid_hdmi_edid
));
1291 dev
->radio_rds_init_time
= ktime_get();
1293 /* create all controls */
1294 ret
= vivid_create_controls(dev
, ccs_cap
== -1, ccs_out
== -1, no_error_inj
,
1295 in_type_counter
[TV
] || in_type_counter
[SVID
] ||
1296 out_type_counter
[SVID
],
1297 in_type_counter
[HDMI
] || out_type_counter
[HDMI
]);
1301 /* enable/disable interface specific controls */
1302 if (dev
->num_outputs
&& dev
->output_type
[0] != HDMI
)
1303 v4l2_ctrl_activate(dev
->ctrl_display_present
, false);
1304 if (dev
->num_inputs
&& dev
->input_type
[0] != HDMI
) {
1305 v4l2_ctrl_activate(dev
->ctrl_dv_timings_signal_mode
, false);
1306 v4l2_ctrl_activate(dev
->ctrl_dv_timings
, false);
1307 } else if (dev
->num_inputs
&& dev
->input_type
[0] == HDMI
) {
1308 v4l2_ctrl_activate(dev
->ctrl_std_signal_mode
, false);
1309 v4l2_ctrl_activate(dev
->ctrl_standard
, false);
1313 * update the capture and output formats to do a proper initial
1316 vivid_update_format_cap(dev
, false);
1317 vivid_update_format_out(dev
);
1319 /* initialize overlay */
1320 dev
->fb_cap
.fmt
.width
= dev
->src_rect
.width
;
1321 dev
->fb_cap
.fmt
.height
= dev
->src_rect
.height
;
1322 dev
->fb_cap
.fmt
.pixelformat
= dev
->fmt_cap
->fourcc
;
1323 dev
->fb_cap
.fmt
.bytesperline
= dev
->src_rect
.width
* tpg_g_twopixelsize(&dev
->tpg
, 0) / 2;
1324 dev
->fb_cap
.fmt
.sizeimage
= dev
->src_rect
.height
* dev
->fb_cap
.fmt
.bytesperline
;
1326 /* update touch configuration */
1327 dev
->timeperframe_tch_cap
.numerator
= 1;
1328 dev
->timeperframe_tch_cap
.denominator
= 10;
1329 vivid_set_touch(dev
, 0);
1331 /* initialize locks */
1332 spin_lock_init(&dev
->slock
);
1333 mutex_init(&dev
->mutex
);
1335 /* init dma queues */
1336 INIT_LIST_HEAD(&dev
->vid_cap_active
);
1337 INIT_LIST_HEAD(&dev
->vid_out_active
);
1338 INIT_LIST_HEAD(&dev
->vbi_cap_active
);
1339 INIT_LIST_HEAD(&dev
->vbi_out_active
);
1340 INIT_LIST_HEAD(&dev
->sdr_cap_active
);
1341 INIT_LIST_HEAD(&dev
->meta_cap_active
);
1342 INIT_LIST_HEAD(&dev
->meta_out_active
);
1343 INIT_LIST_HEAD(&dev
->touch_cap_active
);
1345 INIT_LIST_HEAD(&dev
->cec_work_list
);
1346 spin_lock_init(&dev
->cec_slock
);
1348 * Same as create_singlethread_workqueue, but now I can use the
1349 * string formatting of alloc_ordered_workqueue.
1351 dev
->cec_workqueue
=
1352 alloc_ordered_workqueue("vivid-%03d-cec", WQ_MEM_RECLAIM
, inst
);
1353 if (!dev
->cec_workqueue
) {
1358 if (allocators
[inst
] == 1)
1359 dma_coerce_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(32));
1361 /* start creating the vb2 queues */
1362 if (dev
->has_vid_cap
) {
1363 /* initialize vid_cap queue */
1364 ret
= vivid_create_queue(dev
, &dev
->vb_vid_cap_q
,
1365 V4L2_BUF_TYPE_VIDEO_CAPTURE
, 2,
1366 &vivid_vid_cap_qops
);
1371 if (dev
->has_vid_out
) {
1372 /* initialize vid_out queue */
1373 ret
= vivid_create_queue(dev
, &dev
->vb_vid_out_q
,
1374 V4L2_BUF_TYPE_VIDEO_OUTPUT
, 2,
1375 &vivid_vid_out_qops
);
1380 if (dev
->has_vbi_cap
) {
1381 /* initialize vbi_cap queue */
1382 ret
= vivid_create_queue(dev
, &dev
->vb_vbi_cap_q
,
1383 V4L2_BUF_TYPE_VBI_CAPTURE
, 2,
1384 &vivid_vbi_cap_qops
);
1389 if (dev
->has_vbi_out
) {
1390 /* initialize vbi_out queue */
1391 ret
= vivid_create_queue(dev
, &dev
->vb_vbi_out_q
,
1392 V4L2_BUF_TYPE_VBI_OUTPUT
, 2,
1393 &vivid_vbi_out_qops
);
1398 if (dev
->has_sdr_cap
) {
1399 /* initialize sdr_cap queue */
1400 ret
= vivid_create_queue(dev
, &dev
->vb_sdr_cap_q
,
1401 V4L2_BUF_TYPE_SDR_CAPTURE
, 8,
1402 &vivid_sdr_cap_qops
);
1407 if (dev
->has_meta_cap
) {
1408 /* initialize meta_cap queue */
1409 ret
= vivid_create_queue(dev
, &dev
->vb_meta_cap_q
,
1410 V4L2_BUF_TYPE_META_CAPTURE
, 2,
1411 &vivid_meta_cap_qops
);
1416 if (dev
->has_meta_out
) {
1417 /* initialize meta_out queue */
1418 ret
= vivid_create_queue(dev
, &dev
->vb_meta_out_q
,
1419 V4L2_BUF_TYPE_META_OUTPUT
, 1,
1420 &vivid_meta_out_qops
);
1425 if (dev
->has_touch_cap
) {
1426 /* initialize touch_cap queue */
1427 ret
= vivid_create_queue(dev
, &dev
->vb_touch_cap_q
,
1428 V4L2_BUF_TYPE_VIDEO_CAPTURE
, 1,
1429 &vivid_touch_cap_qops
);
1435 /* Create framebuffer for testing capture/output overlay */
1436 ret
= vivid_fb_init(dev
);
1439 v4l2_info(&dev
->v4l2_dev
, "Framebuffer device registered as fb%d\n",
1443 #ifdef CONFIG_VIDEO_VIVID_CEC
1444 if (dev
->has_vid_cap
&& in_type_counter
[HDMI
]) {
1445 struct cec_adapter
*adap
;
1447 adap
= vivid_cec_alloc_adap(dev
, 0, false);
1448 ret
= PTR_ERR_OR_ZERO(adap
);
1451 dev
->cec_rx_adap
= adap
;
1454 if (dev
->has_vid_out
) {
1455 for (i
= 0; i
< dev
->num_outputs
; i
++) {
1456 struct cec_adapter
*adap
;
1458 if (dev
->output_type
[i
] != HDMI
)
1461 dev
->cec_output2bus_map
[i
] = cec_tx_bus_cnt
;
1462 adap
= vivid_cec_alloc_adap(dev
, cec_tx_bus_cnt
, true);
1463 ret
= PTR_ERR_OR_ZERO(adap
);
1465 for (i
= 0; i
< dev
->num_outputs
; i
++)
1466 cec_delete_adapter(dev
->cec_tx_adap
[i
]);
1470 dev
->cec_tx_adap
[cec_tx_bus_cnt
] = adap
;
1476 v4l2_ctrl_handler_setup(&dev
->ctrl_hdl_vid_cap
);
1477 v4l2_ctrl_handler_setup(&dev
->ctrl_hdl_vid_out
);
1478 v4l2_ctrl_handler_setup(&dev
->ctrl_hdl_vbi_cap
);
1479 v4l2_ctrl_handler_setup(&dev
->ctrl_hdl_vbi_out
);
1480 v4l2_ctrl_handler_setup(&dev
->ctrl_hdl_radio_rx
);
1481 v4l2_ctrl_handler_setup(&dev
->ctrl_hdl_radio_tx
);
1482 v4l2_ctrl_handler_setup(&dev
->ctrl_hdl_sdr_cap
);
1483 v4l2_ctrl_handler_setup(&dev
->ctrl_hdl_meta_cap
);
1484 v4l2_ctrl_handler_setup(&dev
->ctrl_hdl_meta_out
);
1485 v4l2_ctrl_handler_setup(&dev
->ctrl_hdl_touch_cap
);
1487 /* finally start creating the device nodes */
1488 if (dev
->has_vid_cap
) {
1489 vfd
= &dev
->vid_cap_dev
;
1490 snprintf(vfd
->name
, sizeof(vfd
->name
),
1491 "vivid-%03d-vid-cap", inst
);
1492 vfd
->fops
= &vivid_fops
;
1493 vfd
->ioctl_ops
= &vivid_ioctl_ops
;
1494 vfd
->device_caps
= dev
->vid_cap_caps
;
1495 vfd
->release
= video_device_release_empty
;
1496 vfd
->v4l2_dev
= &dev
->v4l2_dev
;
1497 vfd
->queue
= &dev
->vb_vid_cap_q
;
1498 vfd
->tvnorms
= tvnorms_cap
;
1501 * Provide a mutex to v4l2 core. It will be used to protect
1502 * all fops and v4l2 ioctls.
1504 vfd
->lock
= &dev
->mutex
;
1505 video_set_drvdata(vfd
, dev
);
1507 #ifdef CONFIG_MEDIA_CONTROLLER
1508 dev
->vid_cap_pad
.flags
= MEDIA_PAD_FL_SINK
;
1509 ret
= media_entity_pads_init(&vfd
->entity
, 1, &dev
->vid_cap_pad
);
1514 #ifdef CONFIG_VIDEO_VIVID_CEC
1515 if (in_type_counter
[HDMI
]) {
1516 ret
= cec_register_adapter(dev
->cec_rx_adap
, &pdev
->dev
);
1518 cec_delete_adapter(dev
->cec_rx_adap
);
1519 dev
->cec_rx_adap
= NULL
;
1522 cec_s_phys_addr(dev
->cec_rx_adap
, 0, false);
1523 v4l2_info(&dev
->v4l2_dev
, "CEC adapter %s registered for HDMI input 0\n",
1524 dev_name(&dev
->cec_rx_adap
->devnode
.dev
));
1528 ret
= video_register_device(vfd
, VFL_TYPE_GRABBER
, vid_cap_nr
[inst
]);
1531 v4l2_info(&dev
->v4l2_dev
, "V4L2 capture device registered as %s\n",
1532 video_device_node_name(vfd
));
1535 if (dev
->has_vid_out
) {
1536 vfd
= &dev
->vid_out_dev
;
1537 snprintf(vfd
->name
, sizeof(vfd
->name
),
1538 "vivid-%03d-vid-out", inst
);
1539 vfd
->vfl_dir
= VFL_DIR_TX
;
1540 vfd
->fops
= &vivid_fops
;
1541 vfd
->ioctl_ops
= &vivid_ioctl_ops
;
1542 vfd
->device_caps
= dev
->vid_out_caps
;
1543 vfd
->release
= video_device_release_empty
;
1544 vfd
->v4l2_dev
= &dev
->v4l2_dev
;
1545 vfd
->queue
= &dev
->vb_vid_out_q
;
1546 vfd
->tvnorms
= tvnorms_out
;
1549 * Provide a mutex to v4l2 core. It will be used to protect
1550 * all fops and v4l2 ioctls.
1552 vfd
->lock
= &dev
->mutex
;
1553 video_set_drvdata(vfd
, dev
);
1555 #ifdef CONFIG_MEDIA_CONTROLLER
1556 dev
->vid_out_pad
.flags
= MEDIA_PAD_FL_SOURCE
;
1557 ret
= media_entity_pads_init(&vfd
->entity
, 1, &dev
->vid_out_pad
);
1562 #ifdef CONFIG_VIDEO_VIVID_CEC
1563 for (i
= 0; i
< cec_tx_bus_cnt
; i
++) {
1564 ret
= cec_register_adapter(dev
->cec_tx_adap
[i
], &pdev
->dev
);
1566 for (; i
< cec_tx_bus_cnt
; i
++) {
1567 cec_delete_adapter(dev
->cec_tx_adap
[i
]);
1568 dev
->cec_tx_adap
[i
] = NULL
;
1572 v4l2_info(&dev
->v4l2_dev
, "CEC adapter %s registered for HDMI output %d\n",
1573 dev_name(&dev
->cec_tx_adap
[i
]->devnode
.dev
), i
);
1574 if (i
<= out_type_counter
[HDMI
])
1575 cec_s_phys_addr(dev
->cec_tx_adap
[i
], i
<< 12, false);
1577 cec_s_phys_addr(dev
->cec_tx_adap
[i
], 0x1000, false);
1581 ret
= video_register_device(vfd
, VFL_TYPE_GRABBER
, vid_out_nr
[inst
]);
1584 v4l2_info(&dev
->v4l2_dev
, "V4L2 output device registered as %s\n",
1585 video_device_node_name(vfd
));
1588 if (dev
->has_vbi_cap
) {
1589 vfd
= &dev
->vbi_cap_dev
;
1590 snprintf(vfd
->name
, sizeof(vfd
->name
),
1591 "vivid-%03d-vbi-cap", inst
);
1592 vfd
->fops
= &vivid_fops
;
1593 vfd
->ioctl_ops
= &vivid_ioctl_ops
;
1594 vfd
->device_caps
= dev
->vbi_cap_caps
;
1595 vfd
->release
= video_device_release_empty
;
1596 vfd
->v4l2_dev
= &dev
->v4l2_dev
;
1597 vfd
->queue
= &dev
->vb_vbi_cap_q
;
1598 vfd
->lock
= &dev
->mutex
;
1599 vfd
->tvnorms
= tvnorms_cap
;
1600 video_set_drvdata(vfd
, dev
);
1602 #ifdef CONFIG_MEDIA_CONTROLLER
1603 dev
->vbi_cap_pad
.flags
= MEDIA_PAD_FL_SINK
;
1604 ret
= media_entity_pads_init(&vfd
->entity
, 1, &dev
->vbi_cap_pad
);
1609 ret
= video_register_device(vfd
, VFL_TYPE_VBI
, vbi_cap_nr
[inst
]);
1612 v4l2_info(&dev
->v4l2_dev
, "V4L2 capture device registered as %s, supports %s VBI\n",
1613 video_device_node_name(vfd
),
1614 (dev
->has_raw_vbi_cap
&& dev
->has_sliced_vbi_cap
) ?
1616 (dev
->has_raw_vbi_cap
? "raw" : "sliced"));
1619 if (dev
->has_vbi_out
) {
1620 vfd
= &dev
->vbi_out_dev
;
1621 snprintf(vfd
->name
, sizeof(vfd
->name
),
1622 "vivid-%03d-vbi-out", inst
);
1623 vfd
->vfl_dir
= VFL_DIR_TX
;
1624 vfd
->fops
= &vivid_fops
;
1625 vfd
->ioctl_ops
= &vivid_ioctl_ops
;
1626 vfd
->device_caps
= dev
->vbi_out_caps
;
1627 vfd
->release
= video_device_release_empty
;
1628 vfd
->v4l2_dev
= &dev
->v4l2_dev
;
1629 vfd
->queue
= &dev
->vb_vbi_out_q
;
1630 vfd
->lock
= &dev
->mutex
;
1631 vfd
->tvnorms
= tvnorms_out
;
1632 video_set_drvdata(vfd
, dev
);
1634 #ifdef CONFIG_MEDIA_CONTROLLER
1635 dev
->vbi_out_pad
.flags
= MEDIA_PAD_FL_SOURCE
;
1636 ret
= media_entity_pads_init(&vfd
->entity
, 1, &dev
->vbi_out_pad
);
1641 ret
= video_register_device(vfd
, VFL_TYPE_VBI
, vbi_out_nr
[inst
]);
1644 v4l2_info(&dev
->v4l2_dev
, "V4L2 output device registered as %s, supports %s VBI\n",
1645 video_device_node_name(vfd
),
1646 (dev
->has_raw_vbi_out
&& dev
->has_sliced_vbi_out
) ?
1648 (dev
->has_raw_vbi_out
? "raw" : "sliced"));
1651 if (dev
->has_sdr_cap
) {
1652 vfd
= &dev
->sdr_cap_dev
;
1653 snprintf(vfd
->name
, sizeof(vfd
->name
),
1654 "vivid-%03d-sdr-cap", inst
);
1655 vfd
->fops
= &vivid_fops
;
1656 vfd
->ioctl_ops
= &vivid_ioctl_ops
;
1657 vfd
->device_caps
= dev
->sdr_cap_caps
;
1658 vfd
->release
= video_device_release_empty
;
1659 vfd
->v4l2_dev
= &dev
->v4l2_dev
;
1660 vfd
->queue
= &dev
->vb_sdr_cap_q
;
1661 vfd
->lock
= &dev
->mutex
;
1662 video_set_drvdata(vfd
, dev
);
1664 #ifdef CONFIG_MEDIA_CONTROLLER
1665 dev
->sdr_cap_pad
.flags
= MEDIA_PAD_FL_SINK
;
1666 ret
= media_entity_pads_init(&vfd
->entity
, 1, &dev
->sdr_cap_pad
);
1671 ret
= video_register_device(vfd
, VFL_TYPE_SDR
, sdr_cap_nr
[inst
]);
1674 v4l2_info(&dev
->v4l2_dev
, "V4L2 capture device registered as %s\n",
1675 video_device_node_name(vfd
));
1678 if (dev
->has_radio_rx
) {
1679 vfd
= &dev
->radio_rx_dev
;
1680 snprintf(vfd
->name
, sizeof(vfd
->name
),
1681 "vivid-%03d-rad-rx", inst
);
1682 vfd
->fops
= &vivid_radio_fops
;
1683 vfd
->ioctl_ops
= &vivid_ioctl_ops
;
1684 vfd
->device_caps
= dev
->radio_rx_caps
;
1685 vfd
->release
= video_device_release_empty
;
1686 vfd
->v4l2_dev
= &dev
->v4l2_dev
;
1687 vfd
->lock
= &dev
->mutex
;
1688 video_set_drvdata(vfd
, dev
);
1690 ret
= video_register_device(vfd
, VFL_TYPE_RADIO
, radio_rx_nr
[inst
]);
1693 v4l2_info(&dev
->v4l2_dev
, "V4L2 receiver device registered as %s\n",
1694 video_device_node_name(vfd
));
1697 if (dev
->has_radio_tx
) {
1698 vfd
= &dev
->radio_tx_dev
;
1699 snprintf(vfd
->name
, sizeof(vfd
->name
),
1700 "vivid-%03d-rad-tx", inst
);
1701 vfd
->vfl_dir
= VFL_DIR_TX
;
1702 vfd
->fops
= &vivid_radio_fops
;
1703 vfd
->ioctl_ops
= &vivid_ioctl_ops
;
1704 vfd
->device_caps
= dev
->radio_tx_caps
;
1705 vfd
->release
= video_device_release_empty
;
1706 vfd
->v4l2_dev
= &dev
->v4l2_dev
;
1707 vfd
->lock
= &dev
->mutex
;
1708 video_set_drvdata(vfd
, dev
);
1710 ret
= video_register_device(vfd
, VFL_TYPE_RADIO
, radio_tx_nr
[inst
]);
1713 v4l2_info(&dev
->v4l2_dev
, "V4L2 transmitter device registered as %s\n",
1714 video_device_node_name(vfd
));
1717 if (dev
->has_meta_cap
) {
1718 vfd
= &dev
->meta_cap_dev
;
1719 snprintf(vfd
->name
, sizeof(vfd
->name
),
1720 "vivid-%03d-meta-cap", inst
);
1721 vfd
->fops
= &vivid_fops
;
1722 vfd
->ioctl_ops
= &vivid_ioctl_ops
;
1723 vfd
->device_caps
= dev
->meta_cap_caps
;
1724 vfd
->release
= video_device_release_empty
;
1725 vfd
->v4l2_dev
= &dev
->v4l2_dev
;
1726 vfd
->queue
= &dev
->vb_meta_cap_q
;
1727 vfd
->lock
= &dev
->mutex
;
1728 vfd
->tvnorms
= tvnorms_cap
;
1729 video_set_drvdata(vfd
, dev
);
1730 #ifdef CONFIG_MEDIA_CONTROLLER
1731 dev
->meta_cap_pad
.flags
= MEDIA_PAD_FL_SINK
;
1732 ret
= media_entity_pads_init(&vfd
->entity
, 1,
1733 &dev
->meta_cap_pad
);
1737 ret
= video_register_device(vfd
, VFL_TYPE_GRABBER
,
1741 v4l2_info(&dev
->v4l2_dev
,
1742 "V4L2 metadata capture device registered as %s\n",
1743 video_device_node_name(vfd
));
1746 if (dev
->has_meta_out
) {
1747 vfd
= &dev
->meta_out_dev
;
1748 snprintf(vfd
->name
, sizeof(vfd
->name
),
1749 "vivid-%03d-meta-out", inst
);
1750 vfd
->vfl_dir
= VFL_DIR_TX
;
1751 vfd
->fops
= &vivid_fops
;
1752 vfd
->ioctl_ops
= &vivid_ioctl_ops
;
1753 vfd
->device_caps
= dev
->meta_out_caps
;
1754 vfd
->release
= video_device_release_empty
;
1755 vfd
->v4l2_dev
= &dev
->v4l2_dev
;
1756 vfd
->queue
= &dev
->vb_meta_out_q
;
1757 vfd
->lock
= &dev
->mutex
;
1758 vfd
->tvnorms
= tvnorms_out
;
1759 video_set_drvdata(vfd
, dev
);
1760 #ifdef CONFIG_MEDIA_CONTROLLER
1761 dev
->meta_out_pad
.flags
= MEDIA_PAD_FL_SOURCE
;
1762 ret
= media_entity_pads_init(&vfd
->entity
, 1,
1763 &dev
->meta_out_pad
);
1767 ret
= video_register_device(vfd
, VFL_TYPE_GRABBER
,
1771 v4l2_info(&dev
->v4l2_dev
,
1772 "V4L2 metadata output device registered as %s\n",
1773 video_device_node_name(vfd
));
1776 if (dev
->has_touch_cap
) {
1777 vfd
= &dev
->touch_cap_dev
;
1778 snprintf(vfd
->name
, sizeof(vfd
->name
),
1779 "vivid-%03d-touch-cap", inst
);
1780 vfd
->fops
= &vivid_fops
;
1781 vfd
->ioctl_ops
= &vivid_ioctl_ops
;
1782 vfd
->device_caps
= dev
->touch_cap_caps
;
1783 vfd
->release
= video_device_release_empty
;
1784 vfd
->v4l2_dev
= &dev
->v4l2_dev
;
1785 vfd
->queue
= &dev
->vb_touch_cap_q
;
1786 vfd
->tvnorms
= tvnorms_cap
;
1787 vfd
->lock
= &dev
->mutex
;
1788 video_set_drvdata(vfd
, dev
);
1789 #ifdef CONFIG_MEDIA_CONTROLLER
1790 dev
->touch_cap_pad
.flags
= MEDIA_PAD_FL_SINK
;
1791 ret
= media_entity_pads_init(&vfd
->entity
, 1,
1792 &dev
->touch_cap_pad
);
1796 ret
= video_register_device(vfd
, VFL_TYPE_TOUCH
,
1797 touch_cap_nr
[inst
]);
1800 v4l2_info(&dev
->v4l2_dev
,
1801 "V4L2 touch capture device registered as %s\n",
1802 video_device_node_name(vfd
));
1805 #ifdef CONFIG_MEDIA_CONTROLLER
1806 /* Register the media device */
1807 ret
= media_device_register(&dev
->mdev
);
1809 dev_err(dev
->mdev
.dev
,
1810 "media device register failed (err=%d)\n", ret
);
1815 /* Now that everything is fine, let's add it to device list */
1816 vivid_devs
[inst
] = dev
;
1821 video_unregister_device(&dev
->touch_cap_dev
);
1822 video_unregister_device(&dev
->meta_out_dev
);
1823 video_unregister_device(&dev
->meta_cap_dev
);
1824 video_unregister_device(&dev
->radio_tx_dev
);
1825 video_unregister_device(&dev
->radio_rx_dev
);
1826 video_unregister_device(&dev
->sdr_cap_dev
);
1827 video_unregister_device(&dev
->vbi_out_dev
);
1828 video_unregister_device(&dev
->vbi_cap_dev
);
1829 video_unregister_device(&dev
->vid_out_dev
);
1830 video_unregister_device(&dev
->vid_cap_dev
);
1831 cec_unregister_adapter(dev
->cec_rx_adap
);
1832 for (i
= 0; i
< MAX_OUTPUTS
; i
++)
1833 cec_unregister_adapter(dev
->cec_tx_adap
[i
]);
1834 if (dev
->cec_workqueue
) {
1835 vivid_cec_bus_free_work(dev
);
1836 destroy_workqueue(dev
->cec_workqueue
);
1839 v4l2_device_put(&dev
->v4l2_dev
);
1843 /* This routine allocates from 1 to n_devs virtual drivers.
1845 The real maximum number of virtual drivers will depend on how many drivers
1846 will succeed. This is limited to the maximum number of devices that
1847 videodev supports, which is equal to VIDEO_NUM_DEVICES.
1849 static int vivid_probe(struct platform_device
*pdev
)
1851 const struct font_desc
*font
= find_font("VGA8x16");
1855 pr_err("vivid: could not find font\n");
1859 tpg_set_font(font
->data
);
1861 n_devs
= clamp_t(unsigned, n_devs
, 1, VIVID_MAX_DEVS
);
1863 for (i
= 0; i
< n_devs
; i
++) {
1864 ret
= vivid_create_instance(pdev
, i
);
1866 /* If some instantiations succeeded, keep driver */
1874 pr_err("vivid: error %d while loading driver\n", ret
);
1878 /* n_devs will reflect the actual number of allocated devices */
1884 static int vivid_remove(struct platform_device
*pdev
)
1886 struct vivid_dev
*dev
;
1889 for (i
= 0; i
< n_devs
; i
++) {
1890 dev
= vivid_devs
[i
];
1894 #ifdef CONFIG_MEDIA_CONTROLLER
1895 media_device_unregister(&dev
->mdev
);
1898 if (dev
->has_vid_cap
) {
1899 v4l2_info(&dev
->v4l2_dev
, "unregistering %s\n",
1900 video_device_node_name(&dev
->vid_cap_dev
));
1901 video_unregister_device(&dev
->vid_cap_dev
);
1903 if (dev
->has_vid_out
) {
1904 v4l2_info(&dev
->v4l2_dev
, "unregistering %s\n",
1905 video_device_node_name(&dev
->vid_out_dev
));
1906 video_unregister_device(&dev
->vid_out_dev
);
1908 if (dev
->has_vbi_cap
) {
1909 v4l2_info(&dev
->v4l2_dev
, "unregistering %s\n",
1910 video_device_node_name(&dev
->vbi_cap_dev
));
1911 video_unregister_device(&dev
->vbi_cap_dev
);
1913 if (dev
->has_vbi_out
) {
1914 v4l2_info(&dev
->v4l2_dev
, "unregistering %s\n",
1915 video_device_node_name(&dev
->vbi_out_dev
));
1916 video_unregister_device(&dev
->vbi_out_dev
);
1918 if (dev
->has_sdr_cap
) {
1919 v4l2_info(&dev
->v4l2_dev
, "unregistering %s\n",
1920 video_device_node_name(&dev
->sdr_cap_dev
));
1921 video_unregister_device(&dev
->sdr_cap_dev
);
1923 if (dev
->has_radio_rx
) {
1924 v4l2_info(&dev
->v4l2_dev
, "unregistering %s\n",
1925 video_device_node_name(&dev
->radio_rx_dev
));
1926 video_unregister_device(&dev
->radio_rx_dev
);
1928 if (dev
->has_radio_tx
) {
1929 v4l2_info(&dev
->v4l2_dev
, "unregistering %s\n",
1930 video_device_node_name(&dev
->radio_tx_dev
));
1931 video_unregister_device(&dev
->radio_tx_dev
);
1934 v4l2_info(&dev
->v4l2_dev
, "unregistering fb%d\n",
1936 unregister_framebuffer(&dev
->fb_info
);
1937 vivid_fb_release_buffers(dev
);
1939 if (dev
->has_meta_cap
) {
1940 v4l2_info(&dev
->v4l2_dev
, "unregistering %s\n",
1941 video_device_node_name(&dev
->meta_cap_dev
));
1942 video_unregister_device(&dev
->meta_cap_dev
);
1944 if (dev
->has_meta_out
) {
1945 v4l2_info(&dev
->v4l2_dev
, "unregistering %s\n",
1946 video_device_node_name(&dev
->meta_out_dev
));
1947 video_unregister_device(&dev
->meta_out_dev
);
1949 if (dev
->has_touch_cap
) {
1950 v4l2_info(&dev
->v4l2_dev
, "unregistering %s\n",
1951 video_device_node_name(&dev
->touch_cap_dev
));
1952 video_unregister_device(&dev
->touch_cap_dev
);
1954 cec_unregister_adapter(dev
->cec_rx_adap
);
1955 for (j
= 0; j
< MAX_OUTPUTS
; j
++)
1956 cec_unregister_adapter(dev
->cec_tx_adap
[j
]);
1957 if (dev
->cec_workqueue
) {
1958 vivid_cec_bus_free_work(dev
);
1959 destroy_workqueue(dev
->cec_workqueue
);
1961 v4l2_device_put(&dev
->v4l2_dev
);
1962 vivid_devs
[i
] = NULL
;
1967 static void vivid_pdev_release(struct device
*dev
)
1971 static struct platform_device vivid_pdev
= {
1973 .dev
.release
= vivid_pdev_release
,
1976 static struct platform_driver vivid_pdrv
= {
1977 .probe
= vivid_probe
,
1978 .remove
= vivid_remove
,
1984 static int __init
vivid_init(void)
1988 ret
= platform_device_register(&vivid_pdev
);
1992 ret
= platform_driver_register(&vivid_pdrv
);
1994 platform_device_unregister(&vivid_pdev
);
1999 static void __exit
vivid_exit(void)
2001 platform_driver_unregister(&vivid_pdrv
);
2002 platform_device_unregister(&vivid_pdev
);
2005 module_init(vivid_init
);
2006 module_exit(vivid_exit
);