2 * vivid-core.c - A Virtual Video Test Driver, core initialization
4 * Copyright 2014 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
6 * This program is free software; you may redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
10 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
11 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
12 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
13 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
14 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
15 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
16 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 #include <linux/module.h>
21 #include <linux/errno.h>
22 #include <linux/kernel.h>
23 #include <linux/init.h>
24 #include <linux/sched.h>
25 #include <linux/slab.h>
26 #include <linux/vmalloc.h>
27 #include <linux/font.h>
28 #include <linux/mutex.h>
29 #include <linux/platform_device.h>
30 #include <linux/videodev2.h>
31 #include <linux/v4l2-dv-timings.h>
32 #include <media/videobuf2-vmalloc.h>
33 #include <media/videobuf2-dma-contig.h>
34 #include <media/v4l2-dv-timings.h>
35 #include <media/v4l2-ioctl.h>
36 #include <media/v4l2-fh.h>
37 #include <media/v4l2-event.h>
39 #include "vivid-core.h"
40 #include "vivid-vid-common.h"
41 #include "vivid-vid-cap.h"
42 #include "vivid-vid-out.h"
43 #include "vivid-radio-common.h"
44 #include "vivid-radio-rx.h"
45 #include "vivid-radio-tx.h"
46 #include "vivid-sdr-cap.h"
47 #include "vivid-vbi-cap.h"
48 #include "vivid-vbi-out.h"
49 #include "vivid-osd.h"
50 #include "vivid-cec.h"
51 #include "vivid-ctrls.h"
53 #define VIVID_MODULE_NAME "vivid"
55 /* The maximum number of vivid devices */
56 #define VIVID_MAX_DEVS CONFIG_VIDEO_VIVID_MAX_DEVS
58 MODULE_DESCRIPTION("Virtual Video Test Driver");
59 MODULE_AUTHOR("Hans Verkuil");
60 MODULE_LICENSE("GPL");
62 static unsigned n_devs
= 1;
63 module_param(n_devs
, uint
, 0444);
64 MODULE_PARM_DESC(n_devs
, " number of driver instances to create");
66 static int vid_cap_nr
[VIVID_MAX_DEVS
] = { [0 ... (VIVID_MAX_DEVS
- 1)] = -1 };
67 module_param_array(vid_cap_nr
, int, NULL
, 0444);
68 MODULE_PARM_DESC(vid_cap_nr
, " videoX start number, -1 is autodetect");
70 static int vid_out_nr
[VIVID_MAX_DEVS
] = { [0 ... (VIVID_MAX_DEVS
- 1)] = -1 };
71 module_param_array(vid_out_nr
, int, NULL
, 0444);
72 MODULE_PARM_DESC(vid_out_nr
, " videoX start number, -1 is autodetect");
74 static int vbi_cap_nr
[VIVID_MAX_DEVS
] = { [0 ... (VIVID_MAX_DEVS
- 1)] = -1 };
75 module_param_array(vbi_cap_nr
, int, NULL
, 0444);
76 MODULE_PARM_DESC(vbi_cap_nr
, " vbiX start number, -1 is autodetect");
78 static int vbi_out_nr
[VIVID_MAX_DEVS
] = { [0 ... (VIVID_MAX_DEVS
- 1)] = -1 };
79 module_param_array(vbi_out_nr
, int, NULL
, 0444);
80 MODULE_PARM_DESC(vbi_out_nr
, " vbiX start number, -1 is autodetect");
82 static int sdr_cap_nr
[VIVID_MAX_DEVS
] = { [0 ... (VIVID_MAX_DEVS
- 1)] = -1 };
83 module_param_array(sdr_cap_nr
, int, NULL
, 0444);
84 MODULE_PARM_DESC(sdr_cap_nr
, " swradioX start number, -1 is autodetect");
86 static int radio_rx_nr
[VIVID_MAX_DEVS
] = { [0 ... (VIVID_MAX_DEVS
- 1)] = -1 };
87 module_param_array(radio_rx_nr
, int, NULL
, 0444);
88 MODULE_PARM_DESC(radio_rx_nr
, " radioX start number, -1 is autodetect");
90 static int radio_tx_nr
[VIVID_MAX_DEVS
] = { [0 ... (VIVID_MAX_DEVS
- 1)] = -1 };
91 module_param_array(radio_tx_nr
, int, NULL
, 0444);
92 MODULE_PARM_DESC(radio_tx_nr
, " radioX start number, -1 is autodetect");
94 static int ccs_cap_mode
[VIVID_MAX_DEVS
] = { [0 ... (VIVID_MAX_DEVS
- 1)] = -1 };
95 module_param_array(ccs_cap_mode
, int, NULL
, 0444);
96 MODULE_PARM_DESC(ccs_cap_mode
, " capture crop/compose/scale mode:\n"
97 "\t\t bit 0=crop, 1=compose, 2=scale,\n"
98 "\t\t -1=user-controlled (default)");
100 static int ccs_out_mode
[VIVID_MAX_DEVS
] = { [0 ... (VIVID_MAX_DEVS
- 1)] = -1 };
101 module_param_array(ccs_out_mode
, int, NULL
, 0444);
102 MODULE_PARM_DESC(ccs_out_mode
, " output crop/compose/scale mode:\n"
103 "\t\t bit 0=crop, 1=compose, 2=scale,\n"
104 "\t\t -1=user-controlled (default)");
106 static unsigned multiplanar
[VIVID_MAX_DEVS
] = { [0 ... (VIVID_MAX_DEVS
- 1)] = 1 };
107 module_param_array(multiplanar
, uint
, NULL
, 0444);
108 MODULE_PARM_DESC(multiplanar
, " 1 (default) creates a single planar device, 2 creates a multiplanar device.");
110 /* Default: video + vbi-cap (raw and sliced) + radio rx + radio tx + sdr + vbi-out + vid-out */
111 static unsigned node_types
[VIVID_MAX_DEVS
] = { [0 ... (VIVID_MAX_DEVS
- 1)] = 0x1d3d };
112 module_param_array(node_types
, uint
, NULL
, 0444);
113 MODULE_PARM_DESC(node_types
, " node types, default is 0x1d3d. Bitmask with the following meaning:\n"
114 "\t\t bit 0: Video Capture node\n"
115 "\t\t bit 2-3: VBI Capture node: 0 = none, 1 = raw vbi, 2 = sliced vbi, 3 = both\n"
116 "\t\t bit 4: Radio Receiver node\n"
117 "\t\t bit 5: Software Defined Radio Receiver node\n"
118 "\t\t bit 8: Video Output node\n"
119 "\t\t bit 10-11: VBI Output node: 0 = none, 1 = raw vbi, 2 = sliced vbi, 3 = both\n"
120 "\t\t bit 12: Radio Transmitter node\n"
121 "\t\t bit 16: Framebuffer for testing overlays");
123 /* Default: 4 inputs */
124 static unsigned num_inputs
[VIVID_MAX_DEVS
] = { [0 ... (VIVID_MAX_DEVS
- 1)] = 4 };
125 module_param_array(num_inputs
, uint
, NULL
, 0444);
126 MODULE_PARM_DESC(num_inputs
, " number of inputs, default is 4");
128 /* Default: input 0 = WEBCAM, 1 = TV, 2 = SVID, 3 = HDMI */
129 static unsigned input_types
[VIVID_MAX_DEVS
] = { [0 ... (VIVID_MAX_DEVS
- 1)] = 0xe4 };
130 module_param_array(input_types
, uint
, NULL
, 0444);
131 MODULE_PARM_DESC(input_types
, " input types, default is 0xe4. Two bits per input,\n"
132 "\t\t bits 0-1 == input 0, bits 31-30 == input 15.\n"
133 "\t\t Type 0 == webcam, 1 == TV, 2 == S-Video, 3 == HDMI");
135 /* Default: 2 outputs */
136 static unsigned num_outputs
[VIVID_MAX_DEVS
] = { [0 ... (VIVID_MAX_DEVS
- 1)] = 2 };
137 module_param_array(num_outputs
, uint
, NULL
, 0444);
138 MODULE_PARM_DESC(num_outputs
, " number of outputs, default is 2");
140 /* Default: output 0 = SVID, 1 = HDMI */
141 static unsigned output_types
[VIVID_MAX_DEVS
] = { [0 ... (VIVID_MAX_DEVS
- 1)] = 2 };
142 module_param_array(output_types
, uint
, NULL
, 0444);
143 MODULE_PARM_DESC(output_types
, " output types, default is 0x02. One bit per output,\n"
144 "\t\t bit 0 == output 0, bit 15 == output 15.\n"
145 "\t\t Type 0 == S-Video, 1 == HDMI");
147 unsigned vivid_debug
;
148 module_param(vivid_debug
, uint
, 0644);
149 MODULE_PARM_DESC(vivid_debug
, " activates debug info");
151 static bool no_error_inj
;
152 module_param(no_error_inj
, bool, 0444);
153 MODULE_PARM_DESC(no_error_inj
, " if set disable the error injecting controls");
155 static unsigned int allocators
[VIVID_MAX_DEVS
] = { [0 ... (VIVID_MAX_DEVS
- 1)] = 0 };
156 module_param_array(allocators
, uint
, NULL
, 0444);
157 MODULE_PARM_DESC(allocators
, " memory allocator selection, default is 0.\n"
158 "\t\t 0 == vmalloc\n"
159 "\t\t 1 == dma-contig");
161 static struct vivid_dev
*vivid_devs
[VIVID_MAX_DEVS
];
163 const struct v4l2_rect vivid_min_rect
= {
164 0, 0, MIN_WIDTH
, MIN_HEIGHT
167 const struct v4l2_rect vivid_max_rect
= {
168 0, 0, MAX_WIDTH
* MAX_ZOOM
, MAX_HEIGHT
* MAX_ZOOM
171 static const u8 vivid_hdmi_edid
[256] = {
172 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00,
173 0x31, 0xd8, 0x34, 0x12, 0x00, 0x00, 0x00, 0x00,
174 0x22, 0x1a, 0x01, 0x03, 0x80, 0x60, 0x36, 0x78,
175 0x0f, 0xee, 0x91, 0xa3, 0x54, 0x4c, 0x99, 0x26,
176 0x0f, 0x50, 0x54, 0x2f, 0xcf, 0x00, 0x31, 0x59,
177 0x45, 0x59, 0x81, 0x80, 0x81, 0x40, 0x90, 0x40,
178 0x95, 0x00, 0xa9, 0x40, 0xb3, 0x00, 0x08, 0xe8,
179 0x00, 0x30, 0xf2, 0x70, 0x5a, 0x80, 0xb0, 0x58,
180 0x8a, 0x00, 0xc0, 0x1c, 0x32, 0x00, 0x00, 0x1e,
181 0x00, 0x00, 0x00, 0xfd, 0x00, 0x18, 0x55, 0x18,
182 0x87, 0x3c, 0x00, 0x0a, 0x20, 0x20, 0x20, 0x20,
183 0x20, 0x20, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x76,
184 0x69, 0x76, 0x69, 0x64, 0x0a, 0x20, 0x20, 0x20,
185 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x10,
186 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
187 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x7b,
189 0x02, 0x03, 0x3f, 0xf0, 0x51, 0x61, 0x60, 0x5f,
190 0x5e, 0x5d, 0x10, 0x1f, 0x04, 0x13, 0x22, 0x21,
191 0x20, 0x05, 0x14, 0x02, 0x11, 0x01, 0x23, 0x09,
192 0x07, 0x07, 0x83, 0x01, 0x00, 0x00, 0x6d, 0x03,
193 0x0c, 0x00, 0x10, 0x00, 0x00, 0x3c, 0x21, 0x00,
194 0x60, 0x01, 0x02, 0x03, 0x67, 0xd8, 0x5d, 0xc4,
195 0x01, 0x78, 0x00, 0x00, 0xe2, 0x00, 0xea, 0xe3,
196 0x05, 0x00, 0x00, 0xe3, 0x06, 0x01, 0x00, 0x4d,
197 0xd0, 0x00, 0xa0, 0xf0, 0x70, 0x3e, 0x80, 0x30,
198 0x20, 0x35, 0x00, 0xc0, 0x1c, 0x32, 0x00, 0x00,
199 0x1e, 0x1a, 0x36, 0x80, 0xa0, 0x70, 0x38, 0x1f,
200 0x40, 0x30, 0x20, 0x35, 0x00, 0xc0, 0x1c, 0x32,
201 0x00, 0x00, 0x1a, 0x1a, 0x1d, 0x00, 0x80, 0x51,
202 0xd0, 0x1c, 0x20, 0x40, 0x80, 0x35, 0x00, 0xc0,
203 0x1c, 0x32, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00,
204 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63,
207 static int vidioc_querycap(struct file
*file
, void *priv
,
208 struct v4l2_capability
*cap
)
210 struct vivid_dev
*dev
= video_drvdata(file
);
212 strcpy(cap
->driver
, "vivid");
213 strcpy(cap
->card
, "vivid");
214 snprintf(cap
->bus_info
, sizeof(cap
->bus_info
),
215 "platform:%s", dev
->v4l2_dev
.name
);
217 cap
->capabilities
= dev
->vid_cap_caps
| dev
->vid_out_caps
|
218 dev
->vbi_cap_caps
| dev
->vbi_out_caps
|
219 dev
->radio_rx_caps
| dev
->radio_tx_caps
|
220 dev
->sdr_cap_caps
| V4L2_CAP_DEVICE_CAPS
;
224 static int vidioc_s_hw_freq_seek(struct file
*file
, void *fh
, const struct v4l2_hw_freq_seek
*a
)
226 struct video_device
*vdev
= video_devdata(file
);
228 if (vdev
->vfl_type
== VFL_TYPE_RADIO
)
229 return vivid_radio_rx_s_hw_freq_seek(file
, fh
, a
);
233 static int vidioc_enum_freq_bands(struct file
*file
, void *fh
, struct v4l2_frequency_band
*band
)
235 struct video_device
*vdev
= video_devdata(file
);
237 if (vdev
->vfl_type
== VFL_TYPE_RADIO
)
238 return vivid_radio_rx_enum_freq_bands(file
, fh
, band
);
239 if (vdev
->vfl_type
== VFL_TYPE_SDR
)
240 return vivid_sdr_enum_freq_bands(file
, fh
, band
);
244 static int vidioc_g_tuner(struct file
*file
, void *fh
, struct v4l2_tuner
*vt
)
246 struct video_device
*vdev
= video_devdata(file
);
248 if (vdev
->vfl_type
== VFL_TYPE_RADIO
)
249 return vivid_radio_rx_g_tuner(file
, fh
, vt
);
250 if (vdev
->vfl_type
== VFL_TYPE_SDR
)
251 return vivid_sdr_g_tuner(file
, fh
, vt
);
252 return vivid_video_g_tuner(file
, fh
, vt
);
255 static int vidioc_s_tuner(struct file
*file
, void *fh
, const struct v4l2_tuner
*vt
)
257 struct video_device
*vdev
= video_devdata(file
);
259 if (vdev
->vfl_type
== VFL_TYPE_RADIO
)
260 return vivid_radio_rx_s_tuner(file
, fh
, vt
);
261 if (vdev
->vfl_type
== VFL_TYPE_SDR
)
262 return vivid_sdr_s_tuner(file
, fh
, vt
);
263 return vivid_video_s_tuner(file
, fh
, vt
);
266 static int vidioc_g_frequency(struct file
*file
, void *fh
, struct v4l2_frequency
*vf
)
268 struct vivid_dev
*dev
= video_drvdata(file
);
269 struct video_device
*vdev
= video_devdata(file
);
271 if (vdev
->vfl_type
== VFL_TYPE_RADIO
)
272 return vivid_radio_g_frequency(file
,
273 vdev
->vfl_dir
== VFL_DIR_RX
?
274 &dev
->radio_rx_freq
: &dev
->radio_tx_freq
, vf
);
275 if (vdev
->vfl_type
== VFL_TYPE_SDR
)
276 return vivid_sdr_g_frequency(file
, fh
, vf
);
277 return vivid_video_g_frequency(file
, fh
, vf
);
280 static int vidioc_s_frequency(struct file
*file
, void *fh
, const struct v4l2_frequency
*vf
)
282 struct vivid_dev
*dev
= video_drvdata(file
);
283 struct video_device
*vdev
= video_devdata(file
);
285 if (vdev
->vfl_type
== VFL_TYPE_RADIO
)
286 return vivid_radio_s_frequency(file
,
287 vdev
->vfl_dir
== VFL_DIR_RX
?
288 &dev
->radio_rx_freq
: &dev
->radio_tx_freq
, vf
);
289 if (vdev
->vfl_type
== VFL_TYPE_SDR
)
290 return vivid_sdr_s_frequency(file
, fh
, vf
);
291 return vivid_video_s_frequency(file
, fh
, vf
);
294 static int vidioc_overlay(struct file
*file
, void *fh
, unsigned i
)
296 struct video_device
*vdev
= video_devdata(file
);
298 if (vdev
->vfl_dir
== VFL_DIR_RX
)
299 return vivid_vid_cap_overlay(file
, fh
, i
);
300 return vivid_vid_out_overlay(file
, fh
, i
);
303 static int vidioc_g_fbuf(struct file
*file
, void *fh
, struct v4l2_framebuffer
*a
)
305 struct video_device
*vdev
= video_devdata(file
);
307 if (vdev
->vfl_dir
== VFL_DIR_RX
)
308 return vivid_vid_cap_g_fbuf(file
, fh
, a
);
309 return vivid_vid_out_g_fbuf(file
, fh
, a
);
312 static int vidioc_s_fbuf(struct file
*file
, void *fh
, const struct v4l2_framebuffer
*a
)
314 struct video_device
*vdev
= video_devdata(file
);
316 if (vdev
->vfl_dir
== VFL_DIR_RX
)
317 return vivid_vid_cap_s_fbuf(file
, fh
, a
);
318 return vivid_vid_out_s_fbuf(file
, fh
, a
);
321 static int vidioc_s_std(struct file
*file
, void *fh
, v4l2_std_id id
)
323 struct video_device
*vdev
= video_devdata(file
);
325 if (vdev
->vfl_dir
== VFL_DIR_RX
)
326 return vivid_vid_cap_s_std(file
, fh
, id
);
327 return vivid_vid_out_s_std(file
, fh
, id
);
330 static int vidioc_s_dv_timings(struct file
*file
, void *fh
, struct v4l2_dv_timings
*timings
)
332 struct video_device
*vdev
= video_devdata(file
);
334 if (vdev
->vfl_dir
== VFL_DIR_RX
)
335 return vivid_vid_cap_s_dv_timings(file
, fh
, timings
);
336 return vivid_vid_out_s_dv_timings(file
, fh
, timings
);
339 static int vidioc_cropcap(struct file
*file
, void *fh
, struct v4l2_cropcap
*cc
)
341 struct video_device
*vdev
= video_devdata(file
);
343 if (vdev
->vfl_dir
== VFL_DIR_RX
)
344 return vivid_vid_cap_cropcap(file
, fh
, cc
);
345 return vivid_vid_out_cropcap(file
, fh
, cc
);
348 static int vidioc_g_selection(struct file
*file
, void *fh
,
349 struct v4l2_selection
*sel
)
351 struct video_device
*vdev
= video_devdata(file
);
353 if (vdev
->vfl_dir
== VFL_DIR_RX
)
354 return vivid_vid_cap_g_selection(file
, fh
, sel
);
355 return vivid_vid_out_g_selection(file
, fh
, sel
);
358 static int vidioc_s_selection(struct file
*file
, void *fh
,
359 struct v4l2_selection
*sel
)
361 struct video_device
*vdev
= video_devdata(file
);
363 if (vdev
->vfl_dir
== VFL_DIR_RX
)
364 return vivid_vid_cap_s_selection(file
, fh
, sel
);
365 return vivid_vid_out_s_selection(file
, fh
, sel
);
368 static int vidioc_g_parm(struct file
*file
, void *fh
,
369 struct v4l2_streamparm
*parm
)
371 struct video_device
*vdev
= video_devdata(file
);
373 if (vdev
->vfl_dir
== VFL_DIR_RX
)
374 return vivid_vid_cap_g_parm(file
, fh
, parm
);
375 return vivid_vid_out_g_parm(file
, fh
, parm
);
378 static int vidioc_s_parm(struct file
*file
, void *fh
,
379 struct v4l2_streamparm
*parm
)
381 struct video_device
*vdev
= video_devdata(file
);
383 if (vdev
->vfl_dir
== VFL_DIR_RX
)
384 return vivid_vid_cap_s_parm(file
, fh
, parm
);
385 return vivid_vid_out_g_parm(file
, fh
, parm
);
388 static int vidioc_log_status(struct file
*file
, void *fh
)
390 struct vivid_dev
*dev
= video_drvdata(file
);
391 struct video_device
*vdev
= video_devdata(file
);
393 v4l2_ctrl_log_status(file
, fh
);
394 if (vdev
->vfl_dir
== VFL_DIR_RX
&& vdev
->vfl_type
== VFL_TYPE_GRABBER
)
395 tpg_log_status(&dev
->tpg
);
399 static ssize_t
vivid_radio_read(struct file
*file
, char __user
*buf
,
400 size_t size
, loff_t
*offset
)
402 struct video_device
*vdev
= video_devdata(file
);
404 if (vdev
->vfl_dir
== VFL_DIR_TX
)
406 return vivid_radio_rx_read(file
, buf
, size
, offset
);
409 static ssize_t
vivid_radio_write(struct file
*file
, const char __user
*buf
,
410 size_t size
, loff_t
*offset
)
412 struct video_device
*vdev
= video_devdata(file
);
414 if (vdev
->vfl_dir
== VFL_DIR_RX
)
416 return vivid_radio_tx_write(file
, buf
, size
, offset
);
419 static __poll_t
vivid_radio_poll(struct file
*file
, struct poll_table_struct
*wait
)
421 struct video_device
*vdev
= video_devdata(file
);
423 if (vdev
->vfl_dir
== VFL_DIR_RX
)
424 return vivid_radio_rx_poll(file
, wait
);
425 return vivid_radio_tx_poll(file
, wait
);
428 static bool vivid_is_in_use(struct video_device
*vdev
)
433 spin_lock_irqsave(&vdev
->fh_lock
, flags
);
434 res
= !list_empty(&vdev
->fh_list
);
435 spin_unlock_irqrestore(&vdev
->fh_lock
, flags
);
439 static bool vivid_is_last_user(struct vivid_dev
*dev
)
441 unsigned uses
= vivid_is_in_use(&dev
->vid_cap_dev
) +
442 vivid_is_in_use(&dev
->vid_out_dev
) +
443 vivid_is_in_use(&dev
->vbi_cap_dev
) +
444 vivid_is_in_use(&dev
->vbi_out_dev
) +
445 vivid_is_in_use(&dev
->sdr_cap_dev
) +
446 vivid_is_in_use(&dev
->radio_rx_dev
) +
447 vivid_is_in_use(&dev
->radio_tx_dev
);
452 static int vivid_fop_release(struct file
*file
)
454 struct vivid_dev
*dev
= video_drvdata(file
);
455 struct video_device
*vdev
= video_devdata(file
);
457 mutex_lock(&dev
->mutex
);
458 if (!no_error_inj
&& v4l2_fh_is_singular_file(file
) &&
459 !video_is_registered(vdev
) && vivid_is_last_user(dev
)) {
461 * I am the last user of this driver, and a disconnect
462 * was forced (since this video_device is unregistered),
463 * so re-register all video_device's again.
465 v4l2_info(&dev
->v4l2_dev
, "reconnect\n");
466 set_bit(V4L2_FL_REGISTERED
, &dev
->vid_cap_dev
.flags
);
467 set_bit(V4L2_FL_REGISTERED
, &dev
->vid_out_dev
.flags
);
468 set_bit(V4L2_FL_REGISTERED
, &dev
->vbi_cap_dev
.flags
);
469 set_bit(V4L2_FL_REGISTERED
, &dev
->vbi_out_dev
.flags
);
470 set_bit(V4L2_FL_REGISTERED
, &dev
->sdr_cap_dev
.flags
);
471 set_bit(V4L2_FL_REGISTERED
, &dev
->radio_rx_dev
.flags
);
472 set_bit(V4L2_FL_REGISTERED
, &dev
->radio_tx_dev
.flags
);
474 mutex_unlock(&dev
->mutex
);
475 if (file
->private_data
== dev
->overlay_cap_owner
)
476 dev
->overlay_cap_owner
= NULL
;
477 if (file
->private_data
== dev
->radio_rx_rds_owner
) {
478 dev
->radio_rx_rds_last_block
= 0;
479 dev
->radio_rx_rds_owner
= NULL
;
481 if (file
->private_data
== dev
->radio_tx_rds_owner
) {
482 dev
->radio_tx_rds_last_block
= 0;
483 dev
->radio_tx_rds_owner
= NULL
;
486 return vb2_fop_release(file
);
487 return v4l2_fh_release(file
);
490 static const struct v4l2_file_operations vivid_fops
= {
491 .owner
= THIS_MODULE
,
492 .open
= v4l2_fh_open
,
493 .release
= vivid_fop_release
,
494 .read
= vb2_fop_read
,
495 .write
= vb2_fop_write
,
496 .poll
= vb2_fop_poll
,
497 .unlocked_ioctl
= video_ioctl2
,
498 .mmap
= vb2_fop_mmap
,
501 static const struct v4l2_file_operations vivid_radio_fops
= {
502 .owner
= THIS_MODULE
,
503 .open
= v4l2_fh_open
,
504 .release
= vivid_fop_release
,
505 .read
= vivid_radio_read
,
506 .write
= vivid_radio_write
,
507 .poll
= vivid_radio_poll
,
508 .unlocked_ioctl
= video_ioctl2
,
511 static const struct v4l2_ioctl_ops vivid_ioctl_ops
= {
512 .vidioc_querycap
= vidioc_querycap
,
514 .vidioc_enum_fmt_vid_cap
= vidioc_enum_fmt_vid
,
515 .vidioc_g_fmt_vid_cap
= vidioc_g_fmt_vid_cap
,
516 .vidioc_try_fmt_vid_cap
= vidioc_try_fmt_vid_cap
,
517 .vidioc_s_fmt_vid_cap
= vidioc_s_fmt_vid_cap
,
518 .vidioc_enum_fmt_vid_cap_mplane
= vidioc_enum_fmt_vid_mplane
,
519 .vidioc_g_fmt_vid_cap_mplane
= vidioc_g_fmt_vid_cap_mplane
,
520 .vidioc_try_fmt_vid_cap_mplane
= vidioc_try_fmt_vid_cap_mplane
,
521 .vidioc_s_fmt_vid_cap_mplane
= vidioc_s_fmt_vid_cap_mplane
,
523 .vidioc_enum_fmt_vid_out
= vidioc_enum_fmt_vid
,
524 .vidioc_g_fmt_vid_out
= vidioc_g_fmt_vid_out
,
525 .vidioc_try_fmt_vid_out
= vidioc_try_fmt_vid_out
,
526 .vidioc_s_fmt_vid_out
= vidioc_s_fmt_vid_out
,
527 .vidioc_enum_fmt_vid_out_mplane
= vidioc_enum_fmt_vid_mplane
,
528 .vidioc_g_fmt_vid_out_mplane
= vidioc_g_fmt_vid_out_mplane
,
529 .vidioc_try_fmt_vid_out_mplane
= vidioc_try_fmt_vid_out_mplane
,
530 .vidioc_s_fmt_vid_out_mplane
= vidioc_s_fmt_vid_out_mplane
,
532 .vidioc_g_selection
= vidioc_g_selection
,
533 .vidioc_s_selection
= vidioc_s_selection
,
534 .vidioc_cropcap
= vidioc_cropcap
,
536 .vidioc_g_fmt_vbi_cap
= vidioc_g_fmt_vbi_cap
,
537 .vidioc_try_fmt_vbi_cap
= vidioc_g_fmt_vbi_cap
,
538 .vidioc_s_fmt_vbi_cap
= vidioc_s_fmt_vbi_cap
,
540 .vidioc_g_fmt_sliced_vbi_cap
= vidioc_g_fmt_sliced_vbi_cap
,
541 .vidioc_try_fmt_sliced_vbi_cap
= vidioc_try_fmt_sliced_vbi_cap
,
542 .vidioc_s_fmt_sliced_vbi_cap
= vidioc_s_fmt_sliced_vbi_cap
,
543 .vidioc_g_sliced_vbi_cap
= vidioc_g_sliced_vbi_cap
,
545 .vidioc_g_fmt_vbi_out
= vidioc_g_fmt_vbi_out
,
546 .vidioc_try_fmt_vbi_out
= vidioc_g_fmt_vbi_out
,
547 .vidioc_s_fmt_vbi_out
= vidioc_s_fmt_vbi_out
,
549 .vidioc_g_fmt_sliced_vbi_out
= vidioc_g_fmt_sliced_vbi_out
,
550 .vidioc_try_fmt_sliced_vbi_out
= vidioc_try_fmt_sliced_vbi_out
,
551 .vidioc_s_fmt_sliced_vbi_out
= vidioc_s_fmt_sliced_vbi_out
,
553 .vidioc_enum_fmt_sdr_cap
= vidioc_enum_fmt_sdr_cap
,
554 .vidioc_g_fmt_sdr_cap
= vidioc_g_fmt_sdr_cap
,
555 .vidioc_try_fmt_sdr_cap
= vidioc_try_fmt_sdr_cap
,
556 .vidioc_s_fmt_sdr_cap
= vidioc_s_fmt_sdr_cap
,
558 .vidioc_overlay
= vidioc_overlay
,
559 .vidioc_enum_framesizes
= vidioc_enum_framesizes
,
560 .vidioc_enum_frameintervals
= vidioc_enum_frameintervals
,
561 .vidioc_g_parm
= vidioc_g_parm
,
562 .vidioc_s_parm
= vidioc_s_parm
,
564 .vidioc_enum_fmt_vid_overlay
= vidioc_enum_fmt_vid_overlay
,
565 .vidioc_g_fmt_vid_overlay
= vidioc_g_fmt_vid_overlay
,
566 .vidioc_try_fmt_vid_overlay
= vidioc_try_fmt_vid_overlay
,
567 .vidioc_s_fmt_vid_overlay
= vidioc_s_fmt_vid_overlay
,
568 .vidioc_g_fmt_vid_out_overlay
= vidioc_g_fmt_vid_out_overlay
,
569 .vidioc_try_fmt_vid_out_overlay
= vidioc_try_fmt_vid_out_overlay
,
570 .vidioc_s_fmt_vid_out_overlay
= vidioc_s_fmt_vid_out_overlay
,
571 .vidioc_g_fbuf
= vidioc_g_fbuf
,
572 .vidioc_s_fbuf
= vidioc_s_fbuf
,
574 .vidioc_reqbufs
= vb2_ioctl_reqbufs
,
575 .vidioc_create_bufs
= vb2_ioctl_create_bufs
,
576 .vidioc_prepare_buf
= vb2_ioctl_prepare_buf
,
577 .vidioc_querybuf
= vb2_ioctl_querybuf
,
578 .vidioc_qbuf
= vb2_ioctl_qbuf
,
579 .vidioc_dqbuf
= vb2_ioctl_dqbuf
,
580 .vidioc_expbuf
= vb2_ioctl_expbuf
,
581 .vidioc_streamon
= vb2_ioctl_streamon
,
582 .vidioc_streamoff
= vb2_ioctl_streamoff
,
584 .vidioc_enum_input
= vidioc_enum_input
,
585 .vidioc_g_input
= vidioc_g_input
,
586 .vidioc_s_input
= vidioc_s_input
,
587 .vidioc_s_audio
= vidioc_s_audio
,
588 .vidioc_g_audio
= vidioc_g_audio
,
589 .vidioc_enumaudio
= vidioc_enumaudio
,
590 .vidioc_s_frequency
= vidioc_s_frequency
,
591 .vidioc_g_frequency
= vidioc_g_frequency
,
592 .vidioc_s_tuner
= vidioc_s_tuner
,
593 .vidioc_g_tuner
= vidioc_g_tuner
,
594 .vidioc_s_modulator
= vidioc_s_modulator
,
595 .vidioc_g_modulator
= vidioc_g_modulator
,
596 .vidioc_s_hw_freq_seek
= vidioc_s_hw_freq_seek
,
597 .vidioc_enum_freq_bands
= vidioc_enum_freq_bands
,
599 .vidioc_enum_output
= vidioc_enum_output
,
600 .vidioc_g_output
= vidioc_g_output
,
601 .vidioc_s_output
= vidioc_s_output
,
602 .vidioc_s_audout
= vidioc_s_audout
,
603 .vidioc_g_audout
= vidioc_g_audout
,
604 .vidioc_enumaudout
= vidioc_enumaudout
,
606 .vidioc_querystd
= vidioc_querystd
,
607 .vidioc_g_std
= vidioc_g_std
,
608 .vidioc_s_std
= vidioc_s_std
,
609 .vidioc_s_dv_timings
= vidioc_s_dv_timings
,
610 .vidioc_g_dv_timings
= vidioc_g_dv_timings
,
611 .vidioc_query_dv_timings
= vidioc_query_dv_timings
,
612 .vidioc_enum_dv_timings
= vidioc_enum_dv_timings
,
613 .vidioc_dv_timings_cap
= vidioc_dv_timings_cap
,
614 .vidioc_g_edid
= vidioc_g_edid
,
615 .vidioc_s_edid
= vidioc_s_edid
,
617 .vidioc_log_status
= vidioc_log_status
,
618 .vidioc_subscribe_event
= vidioc_subscribe_event
,
619 .vidioc_unsubscribe_event
= v4l2_event_unsubscribe
,
622 /* -----------------------------------------------------------------
623 Initialization and module stuff
624 ------------------------------------------------------------------*/
626 static void vivid_dev_release(struct v4l2_device
*v4l2_dev
)
628 struct vivid_dev
*dev
= container_of(v4l2_dev
, struct vivid_dev
, v4l2_dev
);
630 vivid_free_controls(dev
);
631 v4l2_device_unregister(&dev
->v4l2_dev
);
632 vfree(dev
->scaled_line
);
633 vfree(dev
->blended_line
);
635 vfree(dev
->bitmap_cap
);
636 vfree(dev
->bitmap_out
);
638 kfree(dev
->query_dv_timings_qmenu
);
642 static int vivid_create_instance(struct platform_device
*pdev
, int inst
)
644 static const struct v4l2_dv_timings def_dv_timings
=
645 V4L2_DV_BT_CEA_1280X720P60
;
646 static const struct vb2_mem_ops
* const vivid_mem_ops
[2] = {
648 &vb2_dma_contig_memops
,
650 unsigned in_type_counter
[4] = { 0, 0, 0, 0 };
651 unsigned out_type_counter
[4] = { 0, 0, 0, 0 };
652 int ccs_cap
= ccs_cap_mode
[inst
];
653 int ccs_out
= ccs_out_mode
[inst
];
656 struct vivid_dev
*dev
;
657 struct video_device
*vfd
;
659 unsigned node_type
= node_types
[inst
];
660 unsigned int allocator
= allocators
[inst
];
661 v4l2_std_id tvnorms_cap
= 0, tvnorms_out
= 0;
665 /* allocate main vivid state structure */
666 dev
= kzalloc(sizeof(*dev
), GFP_KERNEL
);
672 /* register v4l2_device */
673 snprintf(dev
->v4l2_dev
.name
, sizeof(dev
->v4l2_dev
.name
),
674 "%s-%03d", VIVID_MODULE_NAME
, inst
);
675 ret
= v4l2_device_register(&pdev
->dev
, &dev
->v4l2_dev
);
680 dev
->v4l2_dev
.release
= vivid_dev_release
;
682 /* start detecting feature set */
684 /* do we use single- or multi-planar? */
685 dev
->multiplanar
= multiplanar
[inst
] > 1;
686 v4l2_info(&dev
->v4l2_dev
, "using %splanar format API\n",
687 dev
->multiplanar
? "multi" : "single ");
689 /* how many inputs do we have and of what type? */
690 dev
->num_inputs
= num_inputs
[inst
];
691 if (dev
->num_inputs
< 1)
693 if (dev
->num_inputs
>= MAX_INPUTS
)
694 dev
->num_inputs
= MAX_INPUTS
;
695 for (i
= 0; i
< dev
->num_inputs
; i
++) {
696 dev
->input_type
[i
] = (input_types
[inst
] >> (i
* 2)) & 0x3;
697 dev
->input_name_counter
[i
] = in_type_counter
[dev
->input_type
[i
]]++;
699 dev
->has_audio_inputs
= in_type_counter
[TV
] && in_type_counter
[SVID
];
700 if (in_type_counter
[HDMI
] == 16) {
701 /* The CEC physical address only allows for max 15 inputs */
702 in_type_counter
[HDMI
]--;
706 /* how many outputs do we have and of what type? */
707 dev
->num_outputs
= num_outputs
[inst
];
708 if (dev
->num_outputs
< 1)
709 dev
->num_outputs
= 1;
710 if (dev
->num_outputs
>= MAX_OUTPUTS
)
711 dev
->num_outputs
= MAX_OUTPUTS
;
712 for (i
= 0; i
< dev
->num_outputs
; i
++) {
713 dev
->output_type
[i
] = ((output_types
[inst
] >> i
) & 1) ? HDMI
: SVID
;
714 dev
->output_name_counter
[i
] = out_type_counter
[dev
->output_type
[i
]]++;
716 dev
->has_audio_outputs
= out_type_counter
[SVID
];
717 if (out_type_counter
[HDMI
] == 16) {
719 * The CEC physical address only allows for max 15 inputs,
720 * so outputs are also limited to 15 to allow for easy
721 * CEC output to input mapping.
723 out_type_counter
[HDMI
]--;
727 /* do we create a video capture device? */
728 dev
->has_vid_cap
= node_type
& 0x0001;
730 /* do we create a vbi capture device? */
731 if (in_type_counter
[TV
] || in_type_counter
[SVID
]) {
732 dev
->has_raw_vbi_cap
= node_type
& 0x0004;
733 dev
->has_sliced_vbi_cap
= node_type
& 0x0008;
734 dev
->has_vbi_cap
= dev
->has_raw_vbi_cap
| dev
->has_sliced_vbi_cap
;
737 /* do we create a video output device? */
738 dev
->has_vid_out
= node_type
& 0x0100;
740 /* do we create a vbi output device? */
741 if (out_type_counter
[SVID
]) {
742 dev
->has_raw_vbi_out
= node_type
& 0x0400;
743 dev
->has_sliced_vbi_out
= node_type
& 0x0800;
744 dev
->has_vbi_out
= dev
->has_raw_vbi_out
| dev
->has_sliced_vbi_out
;
747 /* do we create a radio receiver device? */
748 dev
->has_radio_rx
= node_type
& 0x0010;
750 /* do we create a radio transmitter device? */
751 dev
->has_radio_tx
= node_type
& 0x1000;
753 /* do we create a software defined radio capture device? */
754 dev
->has_sdr_cap
= node_type
& 0x0020;
756 /* do we have a tuner? */
757 has_tuner
= ((dev
->has_vid_cap
|| dev
->has_vbi_cap
) && in_type_counter
[TV
]) ||
758 dev
->has_radio_rx
|| dev
->has_sdr_cap
;
760 /* do we have a modulator? */
761 has_modulator
= dev
->has_radio_tx
;
763 if (dev
->has_vid_cap
)
764 /* do we have a framebuffer for overlay testing? */
765 dev
->has_fb
= node_type
& 0x10000;
767 /* can we do crop/compose/scaling while capturing? */
768 if (no_error_inj
&& ccs_cap
== -1)
771 /* if ccs_cap == -1, then the use can select it using controls */
773 dev
->has_crop_cap
= ccs_cap
& 1;
774 dev
->has_compose_cap
= ccs_cap
& 2;
775 dev
->has_scaler_cap
= ccs_cap
& 4;
776 v4l2_info(&dev
->v4l2_dev
, "Capture Crop: %c Compose: %c Scaler: %c\n",
777 dev
->has_crop_cap
? 'Y' : 'N',
778 dev
->has_compose_cap
? 'Y' : 'N',
779 dev
->has_scaler_cap
? 'Y' : 'N');
782 /* can we do crop/compose/scaling with video output? */
783 if (no_error_inj
&& ccs_out
== -1)
786 /* if ccs_out == -1, then the use can select it using controls */
788 dev
->has_crop_out
= ccs_out
& 1;
789 dev
->has_compose_out
= ccs_out
& 2;
790 dev
->has_scaler_out
= ccs_out
& 4;
791 v4l2_info(&dev
->v4l2_dev
, "Output Crop: %c Compose: %c Scaler: %c\n",
792 dev
->has_crop_out
? 'Y' : 'N',
793 dev
->has_compose_out
? 'Y' : 'N',
794 dev
->has_scaler_out
? 'Y' : 'N');
797 /* end detecting feature set */
799 if (dev
->has_vid_cap
) {
800 /* set up the capabilities of the video capture device */
801 dev
->vid_cap_caps
= dev
->multiplanar
?
802 V4L2_CAP_VIDEO_CAPTURE_MPLANE
:
803 V4L2_CAP_VIDEO_CAPTURE
| V4L2_CAP_VIDEO_OVERLAY
;
804 dev
->vid_cap_caps
|= V4L2_CAP_STREAMING
| V4L2_CAP_READWRITE
;
805 if (dev
->has_audio_inputs
)
806 dev
->vid_cap_caps
|= V4L2_CAP_AUDIO
;
807 if (in_type_counter
[TV
])
808 dev
->vid_cap_caps
|= V4L2_CAP_TUNER
;
810 if (dev
->has_vid_out
) {
811 /* set up the capabilities of the video output device */
812 dev
->vid_out_caps
= dev
->multiplanar
?
813 V4L2_CAP_VIDEO_OUTPUT_MPLANE
:
814 V4L2_CAP_VIDEO_OUTPUT
;
816 dev
->vid_out_caps
|= V4L2_CAP_VIDEO_OUTPUT_OVERLAY
;
817 dev
->vid_out_caps
|= V4L2_CAP_STREAMING
| V4L2_CAP_READWRITE
;
818 if (dev
->has_audio_outputs
)
819 dev
->vid_out_caps
|= V4L2_CAP_AUDIO
;
821 if (dev
->has_vbi_cap
) {
822 /* set up the capabilities of the vbi capture device */
823 dev
->vbi_cap_caps
= (dev
->has_raw_vbi_cap
? V4L2_CAP_VBI_CAPTURE
: 0) |
824 (dev
->has_sliced_vbi_cap
? V4L2_CAP_SLICED_VBI_CAPTURE
: 0);
825 dev
->vbi_cap_caps
|= V4L2_CAP_STREAMING
| V4L2_CAP_READWRITE
;
826 if (dev
->has_audio_inputs
)
827 dev
->vbi_cap_caps
|= V4L2_CAP_AUDIO
;
828 if (in_type_counter
[TV
])
829 dev
->vbi_cap_caps
|= V4L2_CAP_TUNER
;
831 if (dev
->has_vbi_out
) {
832 /* set up the capabilities of the vbi output device */
833 dev
->vbi_out_caps
= (dev
->has_raw_vbi_out
? V4L2_CAP_VBI_OUTPUT
: 0) |
834 (dev
->has_sliced_vbi_out
? V4L2_CAP_SLICED_VBI_OUTPUT
: 0);
835 dev
->vbi_out_caps
|= V4L2_CAP_STREAMING
| V4L2_CAP_READWRITE
;
836 if (dev
->has_audio_outputs
)
837 dev
->vbi_out_caps
|= V4L2_CAP_AUDIO
;
839 if (dev
->has_sdr_cap
) {
840 /* set up the capabilities of the sdr capture device */
841 dev
->sdr_cap_caps
= V4L2_CAP_SDR_CAPTURE
| V4L2_CAP_TUNER
;
842 dev
->sdr_cap_caps
|= V4L2_CAP_STREAMING
| V4L2_CAP_READWRITE
;
844 /* set up the capabilities of the radio receiver device */
845 if (dev
->has_radio_rx
)
846 dev
->radio_rx_caps
= V4L2_CAP_RADIO
| V4L2_CAP_RDS_CAPTURE
|
847 V4L2_CAP_HW_FREQ_SEEK
| V4L2_CAP_TUNER
|
849 /* set up the capabilities of the radio transmitter device */
850 if (dev
->has_radio_tx
)
851 dev
->radio_tx_caps
= V4L2_CAP_RDS_OUTPUT
| V4L2_CAP_MODULATOR
|
855 /* initialize the test pattern generator */
856 tpg_init(&dev
->tpg
, 640, 360);
857 if (tpg_alloc(&dev
->tpg
, MAX_ZOOM
* MAX_WIDTH
))
859 dev
->scaled_line
= vzalloc(MAX_ZOOM
* MAX_WIDTH
);
860 if (!dev
->scaled_line
)
862 dev
->blended_line
= vzalloc(MAX_ZOOM
* MAX_WIDTH
);
863 if (!dev
->blended_line
)
867 dev
->edid
= vmalloc(256 * 128);
871 /* create a string array containing the names of all the preset timings */
872 while (v4l2_dv_timings_presets
[dev
->query_dv_timings_size
].bt
.width
)
873 dev
->query_dv_timings_size
++;
874 dev
->query_dv_timings_qmenu
= kmalloc(dev
->query_dv_timings_size
*
875 (sizeof(void *) + 32), GFP_KERNEL
);
876 if (dev
->query_dv_timings_qmenu
== NULL
)
878 for (i
= 0; i
< dev
->query_dv_timings_size
; i
++) {
879 const struct v4l2_bt_timings
*bt
= &v4l2_dv_timings_presets
[i
].bt
;
880 char *p
= (char *)&dev
->query_dv_timings_qmenu
[dev
->query_dv_timings_size
];
884 dev
->query_dv_timings_qmenu
[i
] = p
;
886 htot
= V4L2_DV_BT_FRAME_WIDTH(bt
);
887 vtot
= V4L2_DV_BT_FRAME_HEIGHT(bt
);
888 snprintf(p
, 32, "%ux%u%s%u",
889 bt
->width
, bt
->height
, bt
->interlaced
? "i" : "p",
890 (u32
)bt
->pixelclock
/ (htot
* vtot
));
893 /* disable invalid ioctls based on the feature set */
894 if (!dev
->has_audio_inputs
) {
895 v4l2_disable_ioctl(&dev
->vid_cap_dev
, VIDIOC_S_AUDIO
);
896 v4l2_disable_ioctl(&dev
->vid_cap_dev
, VIDIOC_G_AUDIO
);
897 v4l2_disable_ioctl(&dev
->vid_cap_dev
, VIDIOC_ENUMAUDIO
);
898 v4l2_disable_ioctl(&dev
->vbi_cap_dev
, VIDIOC_S_AUDIO
);
899 v4l2_disable_ioctl(&dev
->vbi_cap_dev
, VIDIOC_G_AUDIO
);
900 v4l2_disable_ioctl(&dev
->vbi_cap_dev
, VIDIOC_ENUMAUDIO
);
902 if (!dev
->has_audio_outputs
) {
903 v4l2_disable_ioctl(&dev
->vid_out_dev
, VIDIOC_S_AUDOUT
);
904 v4l2_disable_ioctl(&dev
->vid_out_dev
, VIDIOC_G_AUDOUT
);
905 v4l2_disable_ioctl(&dev
->vid_out_dev
, VIDIOC_ENUMAUDOUT
);
906 v4l2_disable_ioctl(&dev
->vbi_out_dev
, VIDIOC_S_AUDOUT
);
907 v4l2_disable_ioctl(&dev
->vbi_out_dev
, VIDIOC_G_AUDOUT
);
908 v4l2_disable_ioctl(&dev
->vbi_out_dev
, VIDIOC_ENUMAUDOUT
);
910 if (!in_type_counter
[TV
] && !in_type_counter
[SVID
]) {
911 v4l2_disable_ioctl(&dev
->vid_cap_dev
, VIDIOC_S_STD
);
912 v4l2_disable_ioctl(&dev
->vid_cap_dev
, VIDIOC_G_STD
);
913 v4l2_disable_ioctl(&dev
->vid_cap_dev
, VIDIOC_ENUMSTD
);
914 v4l2_disable_ioctl(&dev
->vid_cap_dev
, VIDIOC_QUERYSTD
);
916 if (!out_type_counter
[SVID
]) {
917 v4l2_disable_ioctl(&dev
->vid_out_dev
, VIDIOC_S_STD
);
918 v4l2_disable_ioctl(&dev
->vid_out_dev
, VIDIOC_G_STD
);
919 v4l2_disable_ioctl(&dev
->vid_out_dev
, VIDIOC_ENUMSTD
);
921 if (!has_tuner
&& !has_modulator
) {
922 v4l2_disable_ioctl(&dev
->vid_cap_dev
, VIDIOC_S_FREQUENCY
);
923 v4l2_disable_ioctl(&dev
->vid_cap_dev
, VIDIOC_G_FREQUENCY
);
924 v4l2_disable_ioctl(&dev
->vbi_cap_dev
, VIDIOC_S_FREQUENCY
);
925 v4l2_disable_ioctl(&dev
->vbi_cap_dev
, VIDIOC_G_FREQUENCY
);
928 v4l2_disable_ioctl(&dev
->vid_cap_dev
, VIDIOC_S_TUNER
);
929 v4l2_disable_ioctl(&dev
->vid_cap_dev
, VIDIOC_G_TUNER
);
930 v4l2_disable_ioctl(&dev
->vbi_cap_dev
, VIDIOC_S_TUNER
);
931 v4l2_disable_ioctl(&dev
->vbi_cap_dev
, VIDIOC_G_TUNER
);
933 if (in_type_counter
[HDMI
] == 0) {
934 v4l2_disable_ioctl(&dev
->vid_cap_dev
, VIDIOC_S_EDID
);
935 v4l2_disable_ioctl(&dev
->vid_cap_dev
, VIDIOC_G_EDID
);
936 v4l2_disable_ioctl(&dev
->vid_cap_dev
, VIDIOC_DV_TIMINGS_CAP
);
937 v4l2_disable_ioctl(&dev
->vid_cap_dev
, VIDIOC_G_DV_TIMINGS
);
938 v4l2_disable_ioctl(&dev
->vid_cap_dev
, VIDIOC_S_DV_TIMINGS
);
939 v4l2_disable_ioctl(&dev
->vid_cap_dev
, VIDIOC_ENUM_DV_TIMINGS
);
940 v4l2_disable_ioctl(&dev
->vid_cap_dev
, VIDIOC_QUERY_DV_TIMINGS
);
942 if (out_type_counter
[HDMI
] == 0) {
943 v4l2_disable_ioctl(&dev
->vid_out_dev
, VIDIOC_G_EDID
);
944 v4l2_disable_ioctl(&dev
->vid_out_dev
, VIDIOC_DV_TIMINGS_CAP
);
945 v4l2_disable_ioctl(&dev
->vid_out_dev
, VIDIOC_G_DV_TIMINGS
);
946 v4l2_disable_ioctl(&dev
->vid_out_dev
, VIDIOC_S_DV_TIMINGS
);
947 v4l2_disable_ioctl(&dev
->vid_out_dev
, VIDIOC_ENUM_DV_TIMINGS
);
950 v4l2_disable_ioctl(&dev
->vid_out_dev
, VIDIOC_G_FBUF
);
951 v4l2_disable_ioctl(&dev
->vid_out_dev
, VIDIOC_S_FBUF
);
952 v4l2_disable_ioctl(&dev
->vid_out_dev
, VIDIOC_OVERLAY
);
954 v4l2_disable_ioctl(&dev
->vid_cap_dev
, VIDIOC_S_HW_FREQ_SEEK
);
955 v4l2_disable_ioctl(&dev
->vbi_cap_dev
, VIDIOC_S_HW_FREQ_SEEK
);
956 v4l2_disable_ioctl(&dev
->sdr_cap_dev
, VIDIOC_S_HW_FREQ_SEEK
);
957 v4l2_disable_ioctl(&dev
->vid_out_dev
, VIDIOC_S_FREQUENCY
);
958 v4l2_disable_ioctl(&dev
->vid_out_dev
, VIDIOC_G_FREQUENCY
);
959 v4l2_disable_ioctl(&dev
->vid_out_dev
, VIDIOC_ENUM_FRAMESIZES
);
960 v4l2_disable_ioctl(&dev
->vid_out_dev
, VIDIOC_ENUM_FRAMEINTERVALS
);
961 v4l2_disable_ioctl(&dev
->vbi_out_dev
, VIDIOC_S_FREQUENCY
);
962 v4l2_disable_ioctl(&dev
->vbi_out_dev
, VIDIOC_G_FREQUENCY
);
964 /* configure internal data */
965 dev
->fmt_cap
= &vivid_formats
[0];
966 dev
->fmt_out
= &vivid_formats
[0];
967 if (!dev
->multiplanar
)
968 vivid_formats
[0].data_offset
[0] = 0;
969 dev
->webcam_size_idx
= 1;
970 dev
->webcam_ival_idx
= 3;
971 tpg_s_fourcc(&dev
->tpg
, dev
->fmt_cap
->fourcc
);
972 dev
->std_cap
= V4L2_STD_PAL
;
973 dev
->std_out
= V4L2_STD_PAL
;
974 if (dev
->input_type
[0] == TV
|| dev
->input_type
[0] == SVID
)
975 tvnorms_cap
= V4L2_STD_ALL
;
976 if (dev
->output_type
[0] == SVID
)
977 tvnorms_out
= V4L2_STD_ALL
;
978 dev
->dv_timings_cap
= def_dv_timings
;
979 dev
->dv_timings_out
= def_dv_timings
;
980 dev
->tv_freq
= 2804 /* 175.25 * 16 */;
981 dev
->tv_audmode
= V4L2_TUNER_MODE_STEREO
;
982 dev
->tv_field_cap
= V4L2_FIELD_INTERLACED
;
983 dev
->tv_field_out
= V4L2_FIELD_INTERLACED
;
984 dev
->radio_rx_freq
= 95000 * 16;
985 dev
->radio_rx_audmode
= V4L2_TUNER_MODE_STEREO
;
986 if (dev
->has_radio_tx
) {
987 dev
->radio_tx_freq
= 95500 * 16;
988 dev
->radio_rds_loop
= false;
990 dev
->radio_tx_subchans
= V4L2_TUNER_SUB_STEREO
| V4L2_TUNER_SUB_RDS
;
991 dev
->sdr_adc_freq
= 300000;
992 dev
->sdr_fm_freq
= 50000000;
993 dev
->sdr_pixelformat
= V4L2_SDR_FMT_CU8
;
994 dev
->sdr_buffersize
= SDR_CAP_SAMPLES_PER_BUF
* 2;
996 dev
->edid_max_blocks
= dev
->edid_blocks
= 2;
997 memcpy(dev
->edid
, vivid_hdmi_edid
, sizeof(vivid_hdmi_edid
));
998 dev
->radio_rds_init_time
= ktime_get();
1000 /* create all controls */
1001 ret
= vivid_create_controls(dev
, ccs_cap
== -1, ccs_out
== -1, no_error_inj
,
1002 in_type_counter
[TV
] || in_type_counter
[SVID
] ||
1003 out_type_counter
[SVID
],
1004 in_type_counter
[HDMI
] || out_type_counter
[HDMI
]);
1009 * update the capture and output formats to do a proper initial
1012 vivid_update_format_cap(dev
, false);
1013 vivid_update_format_out(dev
);
1015 v4l2_ctrl_handler_setup(&dev
->ctrl_hdl_vid_cap
);
1016 v4l2_ctrl_handler_setup(&dev
->ctrl_hdl_vid_out
);
1017 v4l2_ctrl_handler_setup(&dev
->ctrl_hdl_vbi_cap
);
1018 v4l2_ctrl_handler_setup(&dev
->ctrl_hdl_vbi_out
);
1019 v4l2_ctrl_handler_setup(&dev
->ctrl_hdl_radio_rx
);
1020 v4l2_ctrl_handler_setup(&dev
->ctrl_hdl_radio_tx
);
1021 v4l2_ctrl_handler_setup(&dev
->ctrl_hdl_sdr_cap
);
1023 /* initialize overlay */
1024 dev
->fb_cap
.fmt
.width
= dev
->src_rect
.width
;
1025 dev
->fb_cap
.fmt
.height
= dev
->src_rect
.height
;
1026 dev
->fb_cap
.fmt
.pixelformat
= dev
->fmt_cap
->fourcc
;
1027 dev
->fb_cap
.fmt
.bytesperline
= dev
->src_rect
.width
* tpg_g_twopixelsize(&dev
->tpg
, 0) / 2;
1028 dev
->fb_cap
.fmt
.sizeimage
= dev
->src_rect
.height
* dev
->fb_cap
.fmt
.bytesperline
;
1030 /* initialize locks */
1031 spin_lock_init(&dev
->slock
);
1032 mutex_init(&dev
->mutex
);
1034 /* init dma queues */
1035 INIT_LIST_HEAD(&dev
->vid_cap_active
);
1036 INIT_LIST_HEAD(&dev
->vid_out_active
);
1037 INIT_LIST_HEAD(&dev
->vbi_cap_active
);
1038 INIT_LIST_HEAD(&dev
->vbi_out_active
);
1039 INIT_LIST_HEAD(&dev
->sdr_cap_active
);
1041 INIT_LIST_HEAD(&dev
->cec_work_list
);
1042 spin_lock_init(&dev
->cec_slock
);
1044 * Same as create_singlethread_workqueue, but now I can use the
1045 * string formatting of alloc_ordered_workqueue.
1047 dev
->cec_workqueue
=
1048 alloc_ordered_workqueue("vivid-%03d-cec", WQ_MEM_RECLAIM
, inst
);
1049 if (!dev
->cec_workqueue
) {
1055 dma_coerce_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(32));
1056 else if (allocator
>= ARRAY_SIZE(vivid_mem_ops
))
1059 /* start creating the vb2 queues */
1060 if (dev
->has_vid_cap
) {
1061 /* initialize vid_cap queue */
1062 q
= &dev
->vb_vid_cap_q
;
1063 q
->type
= dev
->multiplanar
? V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
:
1064 V4L2_BUF_TYPE_VIDEO_CAPTURE
;
1065 q
->io_modes
= VB2_MMAP
| VB2_USERPTR
| VB2_DMABUF
| VB2_READ
;
1067 q
->buf_struct_size
= sizeof(struct vivid_buffer
);
1068 q
->ops
= &vivid_vid_cap_qops
;
1069 q
->mem_ops
= vivid_mem_ops
[allocator
];
1070 q
->timestamp_flags
= V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC
;
1071 q
->min_buffers_needed
= 2;
1072 q
->lock
= &dev
->mutex
;
1073 q
->dev
= dev
->v4l2_dev
.dev
;
1075 ret
= vb2_queue_init(q
);
1080 if (dev
->has_vid_out
) {
1081 /* initialize vid_out queue */
1082 q
= &dev
->vb_vid_out_q
;
1083 q
->type
= dev
->multiplanar
? V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
:
1084 V4L2_BUF_TYPE_VIDEO_OUTPUT
;
1085 q
->io_modes
= VB2_MMAP
| VB2_USERPTR
| VB2_DMABUF
| VB2_WRITE
;
1087 q
->buf_struct_size
= sizeof(struct vivid_buffer
);
1088 q
->ops
= &vivid_vid_out_qops
;
1089 q
->mem_ops
= vivid_mem_ops
[allocator
];
1090 q
->timestamp_flags
= V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC
;
1091 q
->min_buffers_needed
= 2;
1092 q
->lock
= &dev
->mutex
;
1093 q
->dev
= dev
->v4l2_dev
.dev
;
1095 ret
= vb2_queue_init(q
);
1100 if (dev
->has_vbi_cap
) {
1101 /* initialize vbi_cap queue */
1102 q
= &dev
->vb_vbi_cap_q
;
1103 q
->type
= dev
->has_raw_vbi_cap
? V4L2_BUF_TYPE_VBI_CAPTURE
:
1104 V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
;
1105 q
->io_modes
= VB2_MMAP
| VB2_USERPTR
| VB2_DMABUF
| VB2_READ
;
1107 q
->buf_struct_size
= sizeof(struct vivid_buffer
);
1108 q
->ops
= &vivid_vbi_cap_qops
;
1109 q
->mem_ops
= vivid_mem_ops
[allocator
];
1110 q
->timestamp_flags
= V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC
;
1111 q
->min_buffers_needed
= 2;
1112 q
->lock
= &dev
->mutex
;
1113 q
->dev
= dev
->v4l2_dev
.dev
;
1115 ret
= vb2_queue_init(q
);
1120 if (dev
->has_vbi_out
) {
1121 /* initialize vbi_out queue */
1122 q
= &dev
->vb_vbi_out_q
;
1123 q
->type
= dev
->has_raw_vbi_out
? V4L2_BUF_TYPE_VBI_OUTPUT
:
1124 V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
;
1125 q
->io_modes
= VB2_MMAP
| VB2_USERPTR
| VB2_DMABUF
| VB2_WRITE
;
1127 q
->buf_struct_size
= sizeof(struct vivid_buffer
);
1128 q
->ops
= &vivid_vbi_out_qops
;
1129 q
->mem_ops
= vivid_mem_ops
[allocator
];
1130 q
->timestamp_flags
= V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC
;
1131 q
->min_buffers_needed
= 2;
1132 q
->lock
= &dev
->mutex
;
1133 q
->dev
= dev
->v4l2_dev
.dev
;
1135 ret
= vb2_queue_init(q
);
1140 if (dev
->has_sdr_cap
) {
1141 /* initialize sdr_cap queue */
1142 q
= &dev
->vb_sdr_cap_q
;
1143 q
->type
= V4L2_BUF_TYPE_SDR_CAPTURE
;
1144 q
->io_modes
= VB2_MMAP
| VB2_USERPTR
| VB2_DMABUF
| VB2_READ
;
1146 q
->buf_struct_size
= sizeof(struct vivid_buffer
);
1147 q
->ops
= &vivid_sdr_cap_qops
;
1148 q
->mem_ops
= vivid_mem_ops
[allocator
];
1149 q
->timestamp_flags
= V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC
;
1150 q
->min_buffers_needed
= 8;
1151 q
->lock
= &dev
->mutex
;
1152 q
->dev
= dev
->v4l2_dev
.dev
;
1154 ret
= vb2_queue_init(q
);
1160 /* Create framebuffer for testing capture/output overlay */
1161 ret
= vivid_fb_init(dev
);
1164 v4l2_info(&dev
->v4l2_dev
, "Framebuffer device registered as fb%d\n",
1168 /* finally start creating the device nodes */
1169 if (dev
->has_vid_cap
) {
1170 vfd
= &dev
->vid_cap_dev
;
1171 snprintf(vfd
->name
, sizeof(vfd
->name
),
1172 "vivid-%03d-vid-cap", inst
);
1173 vfd
->fops
= &vivid_fops
;
1174 vfd
->ioctl_ops
= &vivid_ioctl_ops
;
1175 vfd
->device_caps
= dev
->vid_cap_caps
;
1176 vfd
->release
= video_device_release_empty
;
1177 vfd
->v4l2_dev
= &dev
->v4l2_dev
;
1178 vfd
->queue
= &dev
->vb_vid_cap_q
;
1179 vfd
->tvnorms
= tvnorms_cap
;
1182 * Provide a mutex to v4l2 core. It will be used to protect
1183 * all fops and v4l2 ioctls.
1185 vfd
->lock
= &dev
->mutex
;
1186 video_set_drvdata(vfd
, dev
);
1188 #ifdef CONFIG_VIDEO_VIVID_CEC
1189 if (in_type_counter
[HDMI
]) {
1190 struct cec_adapter
*adap
;
1192 adap
= vivid_cec_alloc_adap(dev
, 0, false);
1193 ret
= PTR_ERR_OR_ZERO(adap
);
1196 dev
->cec_rx_adap
= adap
;
1197 ret
= cec_register_adapter(adap
, &pdev
->dev
);
1199 cec_delete_adapter(adap
);
1200 dev
->cec_rx_adap
= NULL
;
1203 cec_s_phys_addr(adap
, 0, false);
1204 v4l2_info(&dev
->v4l2_dev
, "CEC adapter %s registered for HDMI input 0\n",
1205 dev_name(&adap
->devnode
.dev
));
1209 ret
= video_register_device(vfd
, VFL_TYPE_GRABBER
, vid_cap_nr
[inst
]);
1212 v4l2_info(&dev
->v4l2_dev
, "V4L2 capture device registered as %s\n",
1213 video_device_node_name(vfd
));
1216 if (dev
->has_vid_out
) {
1217 #ifdef CONFIG_VIDEO_VIVID_CEC
1218 unsigned int bus_cnt
= 0;
1221 vfd
= &dev
->vid_out_dev
;
1222 snprintf(vfd
->name
, sizeof(vfd
->name
),
1223 "vivid-%03d-vid-out", inst
);
1224 vfd
->vfl_dir
= VFL_DIR_TX
;
1225 vfd
->fops
= &vivid_fops
;
1226 vfd
->ioctl_ops
= &vivid_ioctl_ops
;
1227 vfd
->device_caps
= dev
->vid_out_caps
;
1228 vfd
->release
= video_device_release_empty
;
1229 vfd
->v4l2_dev
= &dev
->v4l2_dev
;
1230 vfd
->queue
= &dev
->vb_vid_out_q
;
1231 vfd
->tvnorms
= tvnorms_out
;
1234 * Provide a mutex to v4l2 core. It will be used to protect
1235 * all fops and v4l2 ioctls.
1237 vfd
->lock
= &dev
->mutex
;
1238 video_set_drvdata(vfd
, dev
);
1240 #ifdef CONFIG_VIDEO_VIVID_CEC
1241 for (i
= 0; i
< dev
->num_outputs
; i
++) {
1242 struct cec_adapter
*adap
;
1244 if (dev
->output_type
[i
] != HDMI
)
1246 dev
->cec_output2bus_map
[i
] = bus_cnt
;
1247 adap
= vivid_cec_alloc_adap(dev
, bus_cnt
, true);
1248 ret
= PTR_ERR_OR_ZERO(adap
);
1251 dev
->cec_tx_adap
[bus_cnt
] = adap
;
1252 ret
= cec_register_adapter(adap
, &pdev
->dev
);
1254 cec_delete_adapter(adap
);
1255 dev
->cec_tx_adap
[bus_cnt
] = NULL
;
1258 v4l2_info(&dev
->v4l2_dev
, "CEC adapter %s registered for HDMI output %d\n",
1259 dev_name(&adap
->devnode
.dev
), bus_cnt
);
1261 if (bus_cnt
<= out_type_counter
[HDMI
])
1262 cec_s_phys_addr(adap
, bus_cnt
<< 12, false);
1264 cec_s_phys_addr(adap
, 0x1000, false);
1268 ret
= video_register_device(vfd
, VFL_TYPE_GRABBER
, vid_out_nr
[inst
]);
1271 v4l2_info(&dev
->v4l2_dev
, "V4L2 output device registered as %s\n",
1272 video_device_node_name(vfd
));
1275 if (dev
->has_vbi_cap
) {
1276 vfd
= &dev
->vbi_cap_dev
;
1277 snprintf(vfd
->name
, sizeof(vfd
->name
),
1278 "vivid-%03d-vbi-cap", inst
);
1279 vfd
->fops
= &vivid_fops
;
1280 vfd
->ioctl_ops
= &vivid_ioctl_ops
;
1281 vfd
->device_caps
= dev
->vbi_cap_caps
;
1282 vfd
->release
= video_device_release_empty
;
1283 vfd
->v4l2_dev
= &dev
->v4l2_dev
;
1284 vfd
->queue
= &dev
->vb_vbi_cap_q
;
1285 vfd
->lock
= &dev
->mutex
;
1286 vfd
->tvnorms
= tvnorms_cap
;
1287 video_set_drvdata(vfd
, dev
);
1289 ret
= video_register_device(vfd
, VFL_TYPE_VBI
, vbi_cap_nr
[inst
]);
1292 v4l2_info(&dev
->v4l2_dev
, "V4L2 capture device registered as %s, supports %s VBI\n",
1293 video_device_node_name(vfd
),
1294 (dev
->has_raw_vbi_cap
&& dev
->has_sliced_vbi_cap
) ?
1296 (dev
->has_raw_vbi_cap
? "raw" : "sliced"));
1299 if (dev
->has_vbi_out
) {
1300 vfd
= &dev
->vbi_out_dev
;
1301 snprintf(vfd
->name
, sizeof(vfd
->name
),
1302 "vivid-%03d-vbi-out", inst
);
1303 vfd
->vfl_dir
= VFL_DIR_TX
;
1304 vfd
->fops
= &vivid_fops
;
1305 vfd
->ioctl_ops
= &vivid_ioctl_ops
;
1306 vfd
->device_caps
= dev
->vbi_out_caps
;
1307 vfd
->release
= video_device_release_empty
;
1308 vfd
->v4l2_dev
= &dev
->v4l2_dev
;
1309 vfd
->queue
= &dev
->vb_vbi_out_q
;
1310 vfd
->lock
= &dev
->mutex
;
1311 vfd
->tvnorms
= tvnorms_out
;
1312 video_set_drvdata(vfd
, dev
);
1314 ret
= video_register_device(vfd
, VFL_TYPE_VBI
, vbi_out_nr
[inst
]);
1317 v4l2_info(&dev
->v4l2_dev
, "V4L2 output device registered as %s, supports %s VBI\n",
1318 video_device_node_name(vfd
),
1319 (dev
->has_raw_vbi_out
&& dev
->has_sliced_vbi_out
) ?
1321 (dev
->has_raw_vbi_out
? "raw" : "sliced"));
1324 if (dev
->has_sdr_cap
) {
1325 vfd
= &dev
->sdr_cap_dev
;
1326 snprintf(vfd
->name
, sizeof(vfd
->name
),
1327 "vivid-%03d-sdr-cap", inst
);
1328 vfd
->fops
= &vivid_fops
;
1329 vfd
->ioctl_ops
= &vivid_ioctl_ops
;
1330 vfd
->device_caps
= dev
->sdr_cap_caps
;
1331 vfd
->release
= video_device_release_empty
;
1332 vfd
->v4l2_dev
= &dev
->v4l2_dev
;
1333 vfd
->queue
= &dev
->vb_sdr_cap_q
;
1334 vfd
->lock
= &dev
->mutex
;
1335 video_set_drvdata(vfd
, dev
);
1337 ret
= video_register_device(vfd
, VFL_TYPE_SDR
, sdr_cap_nr
[inst
]);
1340 v4l2_info(&dev
->v4l2_dev
, "V4L2 capture device registered as %s\n",
1341 video_device_node_name(vfd
));
1344 if (dev
->has_radio_rx
) {
1345 vfd
= &dev
->radio_rx_dev
;
1346 snprintf(vfd
->name
, sizeof(vfd
->name
),
1347 "vivid-%03d-rad-rx", inst
);
1348 vfd
->fops
= &vivid_radio_fops
;
1349 vfd
->ioctl_ops
= &vivid_ioctl_ops
;
1350 vfd
->device_caps
= dev
->radio_rx_caps
;
1351 vfd
->release
= video_device_release_empty
;
1352 vfd
->v4l2_dev
= &dev
->v4l2_dev
;
1353 vfd
->lock
= &dev
->mutex
;
1354 video_set_drvdata(vfd
, dev
);
1356 ret
= video_register_device(vfd
, VFL_TYPE_RADIO
, radio_rx_nr
[inst
]);
1359 v4l2_info(&dev
->v4l2_dev
, "V4L2 receiver device registered as %s\n",
1360 video_device_node_name(vfd
));
1363 if (dev
->has_radio_tx
) {
1364 vfd
= &dev
->radio_tx_dev
;
1365 snprintf(vfd
->name
, sizeof(vfd
->name
),
1366 "vivid-%03d-rad-tx", inst
);
1367 vfd
->vfl_dir
= VFL_DIR_TX
;
1368 vfd
->fops
= &vivid_radio_fops
;
1369 vfd
->ioctl_ops
= &vivid_ioctl_ops
;
1370 vfd
->device_caps
= dev
->radio_tx_caps
;
1371 vfd
->release
= video_device_release_empty
;
1372 vfd
->v4l2_dev
= &dev
->v4l2_dev
;
1373 vfd
->lock
= &dev
->mutex
;
1374 video_set_drvdata(vfd
, dev
);
1376 ret
= video_register_device(vfd
, VFL_TYPE_RADIO
, radio_tx_nr
[inst
]);
1379 v4l2_info(&dev
->v4l2_dev
, "V4L2 transmitter device registered as %s\n",
1380 video_device_node_name(vfd
));
1383 /* Now that everything is fine, let's add it to device list */
1384 vivid_devs
[inst
] = dev
;
1389 video_unregister_device(&dev
->radio_tx_dev
);
1390 video_unregister_device(&dev
->radio_rx_dev
);
1391 video_unregister_device(&dev
->sdr_cap_dev
);
1392 video_unregister_device(&dev
->vbi_out_dev
);
1393 video_unregister_device(&dev
->vbi_cap_dev
);
1394 video_unregister_device(&dev
->vid_out_dev
);
1395 video_unregister_device(&dev
->vid_cap_dev
);
1396 cec_unregister_adapter(dev
->cec_rx_adap
);
1397 for (i
= 0; i
< MAX_OUTPUTS
; i
++)
1398 cec_unregister_adapter(dev
->cec_tx_adap
[i
]);
1399 if (dev
->cec_workqueue
) {
1400 vivid_cec_bus_free_work(dev
);
1401 destroy_workqueue(dev
->cec_workqueue
);
1404 v4l2_device_put(&dev
->v4l2_dev
);
1408 /* This routine allocates from 1 to n_devs virtual drivers.
1410 The real maximum number of virtual drivers will depend on how many drivers
1411 will succeed. This is limited to the maximum number of devices that
1412 videodev supports, which is equal to VIDEO_NUM_DEVICES.
1414 static int vivid_probe(struct platform_device
*pdev
)
1416 const struct font_desc
*font
= find_font("VGA8x16");
1420 pr_err("vivid: could not find font\n");
1424 tpg_set_font(font
->data
);
1426 n_devs
= clamp_t(unsigned, n_devs
, 1, VIVID_MAX_DEVS
);
1428 for (i
= 0; i
< n_devs
; i
++) {
1429 ret
= vivid_create_instance(pdev
, i
);
1431 /* If some instantiations succeeded, keep driver */
1439 pr_err("vivid: error %d while loading driver\n", ret
);
1443 /* n_devs will reflect the actual number of allocated devices */
1449 static int vivid_remove(struct platform_device
*pdev
)
1451 struct vivid_dev
*dev
;
1454 for (i
= 0; i
< n_devs
; i
++) {
1455 dev
= vivid_devs
[i
];
1459 if (dev
->has_vid_cap
) {
1460 v4l2_info(&dev
->v4l2_dev
, "unregistering %s\n",
1461 video_device_node_name(&dev
->vid_cap_dev
));
1462 video_unregister_device(&dev
->vid_cap_dev
);
1464 if (dev
->has_vid_out
) {
1465 v4l2_info(&dev
->v4l2_dev
, "unregistering %s\n",
1466 video_device_node_name(&dev
->vid_out_dev
));
1467 video_unregister_device(&dev
->vid_out_dev
);
1469 if (dev
->has_vbi_cap
) {
1470 v4l2_info(&dev
->v4l2_dev
, "unregistering %s\n",
1471 video_device_node_name(&dev
->vbi_cap_dev
));
1472 video_unregister_device(&dev
->vbi_cap_dev
);
1474 if (dev
->has_vbi_out
) {
1475 v4l2_info(&dev
->v4l2_dev
, "unregistering %s\n",
1476 video_device_node_name(&dev
->vbi_out_dev
));
1477 video_unregister_device(&dev
->vbi_out_dev
);
1479 if (dev
->has_sdr_cap
) {
1480 v4l2_info(&dev
->v4l2_dev
, "unregistering %s\n",
1481 video_device_node_name(&dev
->sdr_cap_dev
));
1482 video_unregister_device(&dev
->sdr_cap_dev
);
1484 if (dev
->has_radio_rx
) {
1485 v4l2_info(&dev
->v4l2_dev
, "unregistering %s\n",
1486 video_device_node_name(&dev
->radio_rx_dev
));
1487 video_unregister_device(&dev
->radio_rx_dev
);
1489 if (dev
->has_radio_tx
) {
1490 v4l2_info(&dev
->v4l2_dev
, "unregistering %s\n",
1491 video_device_node_name(&dev
->radio_tx_dev
));
1492 video_unregister_device(&dev
->radio_tx_dev
);
1495 v4l2_info(&dev
->v4l2_dev
, "unregistering fb%d\n",
1497 unregister_framebuffer(&dev
->fb_info
);
1498 vivid_fb_release_buffers(dev
);
1500 cec_unregister_adapter(dev
->cec_rx_adap
);
1501 for (j
= 0; j
< MAX_OUTPUTS
; j
++)
1502 cec_unregister_adapter(dev
->cec_tx_adap
[j
]);
1503 if (dev
->cec_workqueue
) {
1504 vivid_cec_bus_free_work(dev
);
1505 destroy_workqueue(dev
->cec_workqueue
);
1507 v4l2_device_put(&dev
->v4l2_dev
);
1508 vivid_devs
[i
] = NULL
;
1513 static void vivid_pdev_release(struct device
*dev
)
1517 static struct platform_device vivid_pdev
= {
1519 .dev
.release
= vivid_pdev_release
,
1522 static struct platform_driver vivid_pdrv
= {
1523 .probe
= vivid_probe
,
1524 .remove
= vivid_remove
,
1530 static int __init
vivid_init(void)
1534 ret
= platform_device_register(&vivid_pdev
);
1538 ret
= platform_driver_register(&vivid_pdrv
);
1540 platform_device_unregister(&vivid_pdev
);
1545 static void __exit
vivid_exit(void)
1547 platform_driver_unregister(&vivid_pdrv
);
1548 platform_device_unregister(&vivid_pdev
);
1551 module_init(vivid_init
);
1552 module_exit(vivid_exit
);