blob: 296788c3bf0ecc6ddc14301fb10bf198216e155a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
3 * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20#include <linux/init.h>
21#include <linux/list.h>
22#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/kernel.h>
24#include <linux/slab.h>
Alexey Dobriyan405f5572009-07-11 22:08:37 +040025#include <linux/smp_lock.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/delay.h>
27
28#include "saa7134-reg.h"
29#include "saa7134.h"
30
31#include <media/saa6752hs.h>
Michael Krufky5e453dc2006-01-09 15:32:31 -020032#include <media/v4l2-common.h>
Hans Verkuile281db582008-08-08 12:43:59 -030033#include <media/v4l2-chip-ident.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
35/* ------------------------------------------------------------------ */
36
37MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
38MODULE_LICENSE("GPL");
39
40static unsigned int empress_nr[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET };
Mauro Carvalho Chehab674434c2005-12-12 00:37:28 -080041
Linus Torvalds1da177e2005-04-16 15:20:36 -070042module_param_array(empress_nr, int, NULL, 0444);
43MODULE_PARM_DESC(empress_nr,"ts device number");
44
Douglas Schilling Landgrafff699e62008-04-22 14:41:48 -030045static unsigned int debug;
Linus Torvalds1da177e2005-04-16 15:20:36 -070046module_param(debug, int, 0644);
47MODULE_PARM_DESC(debug,"enable debug messages");
48
49#define dprintk(fmt, arg...) if (debug) \
50 printk(KERN_DEBUG "%s/empress: " fmt, dev->name , ## arg)
51
52/* ------------------------------------------------------------------ */
53
54static void ts_reset_encoder(struct saa7134_dev* dev)
55{
56 if (!dev->empress_started)
57 return;
58
59 saa_writeb(SAA7134_SPECIAL_MODE, 0x00);
60 msleep(10);
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -080061 saa_writeb(SAA7134_SPECIAL_MODE, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 msleep(100);
63 dev->empress_started = 0;
64}
65
66static int ts_init_encoder(struct saa7134_dev* dev)
67{
Dmitry Belimovf03813e2008-08-26 13:44:40 -030068 u32 leading_null_bytes = 0;
Hans Verkuil86b79d62006-06-18 16:40:10 -030069
Dmitry Belimovf03813e2008-08-26 13:44:40 -030070 /* If more cards start to need this, then this
71 should probably be added to the card definitions. */
72 switch (dev->board) {
73 case SAA7134_BOARD_BEHOLD_M6:
74 case SAA7134_BOARD_BEHOLD_M63:
75 case SAA7134_BOARD_BEHOLD_M6_EXTRA:
76 leading_null_bytes = 1;
77 break;
78 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 ts_reset_encoder(dev);
Hans Verkuilfac69862009-01-17 12:17:14 -030080 saa_call_all(dev, core, init, leading_null_bytes);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 dev->empress_started = 1;
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -080082 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083}
84
85/* ------------------------------------------------------------------ */
86
Hans Verkuilbec43662008-12-30 06:58:20 -030087static int ts_open(struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -070088{
Hans Verkuilbec43662008-12-30 06:58:20 -030089 int minor = video_devdata(file)->minor;
Trent Piepho6d28e982007-10-10 05:37:42 -030090 struct saa7134_dev *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 int err;
92
Hans Verkuild56dc612008-07-30 08:43:36 -030093 lock_kernel();
Trent Piepho6d28e982007-10-10 05:37:42 -030094 list_for_each_entry(dev, &saa7134_devlist, devlist)
95 if (dev->empress_dev && dev->empress_dev->minor == minor)
96 goto found;
Hans Verkuild56dc612008-07-30 08:43:36 -030097 unlock_kernel();
Trent Piepho6d28e982007-10-10 05:37:42 -030098 return -ENODEV;
99 found:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
101 dprintk("open minor=%d\n",minor);
102 err = -EBUSY;
Mauro Carvalho Chehab64f94772008-01-31 13:57:53 -0300103 if (!mutex_trylock(&dev->empress_tsq.vb_lock))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 goto done;
Hans Verkuil1052efe2008-07-26 09:01:24 -0300105 if (atomic_read(&dev->empress_users))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 goto done_up;
107
Rafael Bilskib784e522007-06-20 05:37:27 -0300108 /* Unmute audio */
109 saa_writeb(SAA7134_AUDIO_MUTE_CTRL,
110 saa_readb(SAA7134_AUDIO_MUTE_CTRL) & ~(1 << 6));
111
Hans Verkuil1052efe2008-07-26 09:01:24 -0300112 atomic_inc(&dev->empress_users);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 file->private_data = dev;
114 err = 0;
115
116done_up:
Mauro Carvalho Chehab64f94772008-01-31 13:57:53 -0300117 mutex_unlock(&dev->empress_tsq.vb_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118done:
Hans Verkuild56dc612008-07-30 08:43:36 -0300119 unlock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 return err;
121}
122
Hans Verkuilbec43662008-12-30 06:58:20 -0300123static int ts_release(struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124{
125 struct saa7134_dev *dev = file->private_data;
126
Brandon Philips053fcb62007-11-13 20:11:26 -0300127 videobuf_stop(&dev->empress_tsq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 videobuf_mmap_free(&dev->empress_tsq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
130 /* stop the encoder */
131 ts_reset_encoder(dev);
132
Rafael Bilskib784e522007-06-20 05:37:27 -0300133 /* Mute audio */
134 saa_writeb(SAA7134_AUDIO_MUTE_CTRL,
135 saa_readb(SAA7134_AUDIO_MUTE_CTRL) | (1 << 6));
136
Hans Verkuil1052efe2008-07-26 09:01:24 -0300137 atomic_dec(&dev->empress_users);
Arjan van de Vena1789872008-06-22 17:03:02 -0300138
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 return 0;
140}
141
142static ssize_t
143ts_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
144{
145 struct saa7134_dev *dev = file->private_data;
146
147 if (!dev->empress_started)
148 ts_init_encoder(dev);
149
150 return videobuf_read_stream(&dev->empress_tsq,
151 data, count, ppos, 0,
152 file->f_flags & O_NONBLOCK);
153}
154
155static unsigned int
156ts_poll(struct file *file, struct poll_table_struct *wait)
157{
158 struct saa7134_dev *dev = file->private_data;
159
160 return videobuf_poll_stream(file, &dev->empress_tsq, wait);
161}
162
163
164static int
165ts_mmap(struct file *file, struct vm_area_struct * vma)
166{
167 struct saa7134_dev *dev = file->private_data;
168
169 return videobuf_mmap_mapper(&dev->empress_tsq, vma);
170}
171
172/*
173 * This function is _not_ called directly, but from
174 * video_generic_ioctl (and maybe others). userspace
175 * copying is done already, arg is a kernel pointer.
176 */
Mauro Carvalho Chehab2c10e8a2007-12-11 12:56:23 -0300177
178static int empress_querycap(struct file *file, void *priv,
179 struct v4l2_capability *cap)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180{
Dmitri Belimov388748e2008-05-21 01:20:34 -0300181 struct saa7134_dev *dev = file->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
Mauro Carvalho Chehab2c10e8a2007-12-11 12:56:23 -0300183 strcpy(cap->driver, "saa7134");
184 strlcpy(cap->card, saa7134_boards[dev->board].name,
185 sizeof(cap->card));
186 sprintf(cap->bus_info, "PCI:%s", pci_name(dev->pci));
187 cap->version = SAA7134_VERSION_CODE;
188 cap->capabilities =
189 V4L2_CAP_VIDEO_CAPTURE |
190 V4L2_CAP_READWRITE |
191 V4L2_CAP_STREAMING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 return 0;
193}
194
Mauro Carvalho Chehab2c10e8a2007-12-11 12:56:23 -0300195static int empress_enum_input(struct file *file, void *priv,
196 struct v4l2_input *i)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197{
Mauro Carvalho Chehab2c10e8a2007-12-11 12:56:23 -0300198 if (i->index != 0)
199 return -EINVAL;
200
201 i->type = V4L2_INPUT_TYPE_CAMERA;
202 strcpy(i->name, "CCIR656");
203
204 return 0;
205}
206
207static int empress_g_input(struct file *file, void *priv, unsigned int *i)
208{
209 *i = 0;
210 return 0;
211}
212
213static int empress_s_input(struct file *file, void *priv, unsigned int i)
214{
215 if (i != 0)
216 return -EINVAL;
217
218 return 0;
219}
220
Hans Verkuil78b526a2008-05-28 12:16:41 -0300221static int empress_enum_fmt_vid_cap(struct file *file, void *priv,
Mauro Carvalho Chehab2c10e8a2007-12-11 12:56:23 -0300222 struct v4l2_fmtdesc *f)
223{
224 if (f->index != 0)
225 return -EINVAL;
226
227 strlcpy(f->description, "MPEG TS", sizeof(f->description));
228 f->pixelformat = V4L2_PIX_FMT_MPEG;
229
230 return 0;
231}
232
Hans Verkuil78b526a2008-05-28 12:16:41 -0300233static int empress_g_fmt_vid_cap(struct file *file, void *priv,
Mauro Carvalho Chehab2c10e8a2007-12-11 12:56:23 -0300234 struct v4l2_format *f)
235{
Dmitri Belimova14fe962008-06-10 14:19:31 -0300236 struct saa7134_dev *dev = file->private_data;
Mauro Carvalho Chehab2c10e8a2007-12-11 12:56:23 -0300237
Hans Verkuilfac69862009-01-17 12:17:14 -0300238 saa_call_all(dev, video, g_fmt, f);
Mauro Carvalho Chehab2c10e8a2007-12-11 12:56:23 -0300239
240 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
241 f->fmt.pix.sizeimage = TS_PACKET_SIZE * dev->ts.nr_packets;
242
243 return 0;
244}
245
Hans Verkuil78b526a2008-05-28 12:16:41 -0300246static int empress_s_fmt_vid_cap(struct file *file, void *priv,
Mauro Carvalho Chehab2c10e8a2007-12-11 12:56:23 -0300247 struct v4l2_format *f)
248{
Dmitri Belimova14fe962008-06-10 14:19:31 -0300249 struct saa7134_dev *dev = file->private_data;
Mauro Carvalho Chehab2c10e8a2007-12-11 12:56:23 -0300250
Hans Verkuilfac69862009-01-17 12:17:14 -0300251 saa_call_all(dev, video, s_fmt, f);
Mauro Carvalho Chehab2c10e8a2007-12-11 12:56:23 -0300252
253 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
254 f->fmt.pix.sizeimage = TS_PACKET_SIZE * dev->ts.nr_packets;
255
256 return 0;
257}
258
Dmitri Belimov6b6b7542009-05-28 01:58:57 -0300259static int empress_try_fmt_vid_cap(struct file *file, void *priv,
260 struct v4l2_format *f)
261{
262 struct saa7134_dev *dev = file->private_data;
263
264 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
265 f->fmt.pix.sizeimage = TS_PACKET_SIZE * dev->ts.nr_packets;
266
267 return 0;
268}
Mauro Carvalho Chehab2c10e8a2007-12-11 12:56:23 -0300269
270static int empress_reqbufs(struct file *file, void *priv,
271 struct v4l2_requestbuffers *p)
272{
Dmitri Belimova14fe962008-06-10 14:19:31 -0300273 struct saa7134_dev *dev = file->private_data;
Mauro Carvalho Chehab2c10e8a2007-12-11 12:56:23 -0300274
275 return videobuf_reqbufs(&dev->empress_tsq, p);
276}
277
278static int empress_querybuf(struct file *file, void *priv,
279 struct v4l2_buffer *b)
280{
Dmitri Belimova14fe962008-06-10 14:19:31 -0300281 struct saa7134_dev *dev = file->private_data;
Mauro Carvalho Chehab2c10e8a2007-12-11 12:56:23 -0300282
283 return videobuf_querybuf(&dev->empress_tsq, b);
284}
285
286static int empress_qbuf(struct file *file, void *priv, struct v4l2_buffer *b)
287{
Dmitri Belimova14fe962008-06-10 14:19:31 -0300288 struct saa7134_dev *dev = file->private_data;
Mauro Carvalho Chehab2c10e8a2007-12-11 12:56:23 -0300289
290 return videobuf_qbuf(&dev->empress_tsq, b);
291}
292
293static int empress_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b)
294{
Dmitri Belimova14fe962008-06-10 14:19:31 -0300295 struct saa7134_dev *dev = file->private_data;
Mauro Carvalho Chehab2c10e8a2007-12-11 12:56:23 -0300296
297 return videobuf_dqbuf(&dev->empress_tsq, b,
298 file->f_flags & O_NONBLOCK);
299}
300
301static int empress_streamon(struct file *file, void *priv,
302 enum v4l2_buf_type type)
303{
Dmitri Belimova14fe962008-06-10 14:19:31 -0300304 struct saa7134_dev *dev = file->private_data;
Mauro Carvalho Chehab2c10e8a2007-12-11 12:56:23 -0300305
306 return videobuf_streamon(&dev->empress_tsq);
307}
308
309static int empress_streamoff(struct file *file, void *priv,
310 enum v4l2_buf_type type)
311{
Dmitri Belimova14fe962008-06-10 14:19:31 -0300312 struct saa7134_dev *dev = file->private_data;
Mauro Carvalho Chehab2c10e8a2007-12-11 12:56:23 -0300313
314 return videobuf_streamoff(&dev->empress_tsq);
315}
316
317static int empress_s_ext_ctrls(struct file *file, void *priv,
318 struct v4l2_ext_controls *ctrls)
319{
Dmitri Belimova14fe962008-06-10 14:19:31 -0300320 struct saa7134_dev *dev = file->private_data;
Hans Verkuil8b53b392008-06-27 21:18:15 -0300321 int err;
Mauro Carvalho Chehab2c10e8a2007-12-11 12:56:23 -0300322
323 /* count == 0 is abused in saa6752hs.c, so that special
324 case is handled here explicitly. */
325 if (ctrls->count == 0)
326 return 0;
327
328 if (ctrls->ctrl_class != V4L2_CTRL_CLASS_MPEG)
329 return -EINVAL;
330
Hans Verkuilfac69862009-01-17 12:17:14 -0300331 err = saa_call_empress(dev, core, s_ext_ctrls, ctrls);
Mauro Carvalho Chehab2c10e8a2007-12-11 12:56:23 -0300332 ts_init_encoder(dev);
333
Hans Verkuil8b53b392008-06-27 21:18:15 -0300334 return err;
Mauro Carvalho Chehab2c10e8a2007-12-11 12:56:23 -0300335}
336
337static int empress_g_ext_ctrls(struct file *file, void *priv,
338 struct v4l2_ext_controls *ctrls)
339{
Dmitri Belimova14fe962008-06-10 14:19:31 -0300340 struct saa7134_dev *dev = file->private_data;
Mauro Carvalho Chehab2c10e8a2007-12-11 12:56:23 -0300341
342 if (ctrls->ctrl_class != V4L2_CTRL_CLASS_MPEG)
343 return -EINVAL;
Hans Verkuilfac69862009-01-17 12:17:14 -0300344 return saa_call_empress(dev, core, g_ext_ctrls, ctrls);
Hans Verkuil8b53b392008-06-27 21:18:15 -0300345}
Mauro Carvalho Chehab2c10e8a2007-12-11 12:56:23 -0300346
Hans Verkuil531d83a2008-07-26 09:04:06 -0300347static int empress_g_ctrl(struct file *file, void *priv,
348 struct v4l2_control *c)
349{
350 struct saa7134_dev *dev = file->private_data;
351
352 return saa7134_g_ctrl_internal(dev, NULL, c);
353}
354
355static int empress_s_ctrl(struct file *file, void *priv,
356 struct v4l2_control *c)
357{
358 struct saa7134_dev *dev = file->private_data;
359
360 return saa7134_s_ctrl_internal(dev, NULL, c);
361}
362
Hans Verkuil8b53b392008-06-27 21:18:15 -0300363static int empress_queryctrl(struct file *file, void *priv,
364 struct v4l2_queryctrl *c)
365{
Hans Verkuil2ba58892009-02-13 10:57:48 -0300366 /* Must be sorted from low to high control ID! */
Hans Verkuil8b53b392008-06-27 21:18:15 -0300367 static const u32 user_ctrls[] = {
368 V4L2_CID_USER_CLASS,
369 V4L2_CID_BRIGHTNESS,
370 V4L2_CID_CONTRAST,
371 V4L2_CID_SATURATION,
372 V4L2_CID_HUE,
373 V4L2_CID_AUDIO_VOLUME,
374 V4L2_CID_AUDIO_MUTE,
375 V4L2_CID_HFLIP,
376 0
377 };
378
Hans Verkuil2ba58892009-02-13 10:57:48 -0300379 /* Must be sorted from low to high control ID! */
Hans Verkuil8b53b392008-06-27 21:18:15 -0300380 static const u32 mpeg_ctrls[] = {
381 V4L2_CID_MPEG_CLASS,
382 V4L2_CID_MPEG_STREAM_TYPE,
383 V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ,
384 V4L2_CID_MPEG_AUDIO_ENCODING,
385 V4L2_CID_MPEG_AUDIO_L2_BITRATE,
386 V4L2_CID_MPEG_VIDEO_ENCODING,
387 V4L2_CID_MPEG_VIDEO_ASPECT,
388 V4L2_CID_MPEG_VIDEO_BITRATE_MODE,
389 V4L2_CID_MPEG_VIDEO_BITRATE,
390 V4L2_CID_MPEG_VIDEO_BITRATE_PEAK,
391 0
392 };
393 static const u32 *ctrl_classes[] = {
394 user_ctrls,
395 mpeg_ctrls,
396 NULL
397 };
398 struct saa7134_dev *dev = file->private_data;
399
400 c->id = v4l2_ctrl_next(ctrl_classes, c->id);
401 if (c->id == 0)
402 return -EINVAL;
403 if (c->id == V4L2_CID_USER_CLASS || c->id == V4L2_CID_MPEG_CLASS)
Hans Verkuil10afbef2009-02-21 18:47:24 -0300404 return v4l2_ctrl_query_fill(c, 0, 0, 0, 0);
Hans Verkuil8b53b392008-06-27 21:18:15 -0300405 if (V4L2_CTRL_ID2CLASS(c->id) != V4L2_CTRL_CLASS_MPEG)
406 return saa7134_queryctrl(file, priv, c);
Hans Verkuilfac69862009-01-17 12:17:14 -0300407 return saa_call_empress(dev, core, queryctrl, c);
Hans Verkuil8b53b392008-06-27 21:18:15 -0300408}
409
410static int empress_querymenu(struct file *file, void *priv,
411 struct v4l2_querymenu *c)
412{
413 struct saa7134_dev *dev = file->private_data;
414
415 if (V4L2_CTRL_ID2CLASS(c->id) != V4L2_CTRL_CLASS_MPEG)
416 return -EINVAL;
Hans Verkuilfac69862009-01-17 12:17:14 -0300417 return saa_call_empress(dev, core, querymenu, c);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418}
419
Hans Verkuile281db582008-08-08 12:43:59 -0300420static int empress_g_chip_ident(struct file *file, void *fh,
Hans Verkuilaecde8b2008-12-30 07:14:19 -0300421 struct v4l2_dbg_chip_ident *chip)
Hans Verkuile281db582008-08-08 12:43:59 -0300422{
423 struct saa7134_dev *dev = file->private_data;
424
425 chip->ident = V4L2_IDENT_NONE;
426 chip->revision = 0;
Hans Verkuilaecde8b2008-12-30 07:14:19 -0300427 if (chip->match.type == V4L2_CHIP_MATCH_I2C_DRIVER &&
428 !strcmp(chip->match.name, "saa6752hs"))
Hans Verkuilfac69862009-01-17 12:17:14 -0300429 return saa_call_empress(dev, core, g_chip_ident, chip);
Hans Verkuil195784b2009-03-28 09:27:02 -0300430 if (chip->match.type == V4L2_CHIP_MATCH_I2C_ADDR)
Hans Verkuilfac69862009-01-17 12:17:14 -0300431 return saa_call_empress(dev, core, g_chip_ident, chip);
Hans Verkuile281db582008-08-08 12:43:59 -0300432 return -EINVAL;
433}
434
Hans Verkuil9afb7372008-09-06 06:34:44 -0300435static int empress_s_std(struct file *file, void *priv, v4l2_std_id *id)
436{
437 struct saa7134_dev *dev = file->private_data;
438
439 return saa7134_s_std_internal(dev, NULL, id);
440}
441
442static int empress_g_std(struct file *file, void *priv, v4l2_std_id *id)
443{
444 struct saa7134_dev *dev = file->private_data;
445
446 *id = dev->tvnorm->id;
447 return 0;
448}
Hans Verkuile281db582008-08-08 12:43:59 -0300449
Hans Verkuilbec43662008-12-30 06:58:20 -0300450static const struct v4l2_file_operations ts_fops =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451{
452 .owner = THIS_MODULE,
453 .open = ts_open,
454 .release = ts_release,
455 .read = ts_read,
456 .poll = ts_poll,
457 .mmap = ts_mmap,
Mauro Carvalho Chehab2c10e8a2007-12-11 12:56:23 -0300458 .ioctl = video_ioctl2,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459};
460
Hans Verkuila3998102008-07-21 02:57:38 -0300461static const struct v4l2_ioctl_ops ts_ioctl_ops = {
Mauro Carvalho Chehab2c10e8a2007-12-11 12:56:23 -0300462 .vidioc_querycap = empress_querycap,
Hans Verkuil78b526a2008-05-28 12:16:41 -0300463 .vidioc_enum_fmt_vid_cap = empress_enum_fmt_vid_cap,
Dmitri Belimov6b6b7542009-05-28 01:58:57 -0300464 .vidioc_try_fmt_vid_cap = empress_try_fmt_vid_cap,
Hans Verkuil78b526a2008-05-28 12:16:41 -0300465 .vidioc_s_fmt_vid_cap = empress_s_fmt_vid_cap,
466 .vidioc_g_fmt_vid_cap = empress_g_fmt_vid_cap,
Mauro Carvalho Chehab2c10e8a2007-12-11 12:56:23 -0300467 .vidioc_reqbufs = empress_reqbufs,
468 .vidioc_querybuf = empress_querybuf,
469 .vidioc_qbuf = empress_qbuf,
470 .vidioc_dqbuf = empress_dqbuf,
471 .vidioc_streamon = empress_streamon,
472 .vidioc_streamoff = empress_streamoff,
473 .vidioc_s_ext_ctrls = empress_s_ext_ctrls,
474 .vidioc_g_ext_ctrls = empress_g_ext_ctrls,
475 .vidioc_enum_input = empress_enum_input,
476 .vidioc_g_input = empress_g_input,
477 .vidioc_s_input = empress_s_input,
Hans Verkuil8b53b392008-06-27 21:18:15 -0300478 .vidioc_queryctrl = empress_queryctrl,
479 .vidioc_querymenu = empress_querymenu,
Hans Verkuil531d83a2008-07-26 09:04:06 -0300480 .vidioc_g_ctrl = empress_g_ctrl,
481 .vidioc_s_ctrl = empress_s_ctrl,
Hans Verkuile281db582008-08-08 12:43:59 -0300482 .vidioc_g_chip_ident = empress_g_chip_ident,
Hans Verkuil9afb7372008-09-06 06:34:44 -0300483 .vidioc_s_std = empress_s_std,
484 .vidioc_g_std = empress_g_std,
Hans Verkuila3998102008-07-21 02:57:38 -0300485};
486
487/* ----------------------------------------------------------- */
488
489static struct video_device saa7134_empress_template = {
490 .name = "saa7134-empress",
Hans Verkuila3998102008-07-21 02:57:38 -0300491 .fops = &ts_fops,
492 .minor = -1,
493 .ioctl_ops = &ts_ioctl_ops,
Mauro Carvalho Chehab2c10e8a2007-12-11 12:56:23 -0300494
495 .tvnorms = SAA7134_NORMS,
496 .current_norm = V4L2_STD_PAL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497};
498
David Howellsc4028952006-11-22 14:57:56 +0000499static void empress_signal_update(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500{
David Howellsc4028952006-11-22 14:57:56 +0000501 struct saa7134_dev* dev =
502 container_of(work, struct saa7134_dev, empress_workqueue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503
504 if (dev->nosignal) {
505 dprintk("no video signal\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 } else {
507 dprintk("video signal acquired\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 }
509}
510
511static void empress_signal_change(struct saa7134_dev *dev)
512{
513 schedule_work(&dev->empress_workqueue);
514}
515
516
517static int empress_init(struct saa7134_dev *dev)
518{
519 int err;
520
Harvey Harrison50163812008-04-08 23:20:00 -0300521 dprintk("%s: %s\n",dev->name,__func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 dev->empress_dev = video_device_alloc();
523 if (NULL == dev->empress_dev)
524 return -ENOMEM;
525 *(dev->empress_dev) = saa7134_empress_template;
Hans Verkuil5e85e732008-07-20 06:31:39 -0300526 dev->empress_dev->parent = &dev->pci->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 dev->empress_dev->release = video_device_release;
528 snprintf(dev->empress_dev->name, sizeof(dev->empress_dev->name),
529 "%s empress (%s)", dev->name,
530 saa7134_boards[dev->board].name);
531
David Howellsc4028952006-11-22 14:57:56 +0000532 INIT_WORK(&dev->empress_workqueue, empress_signal_update);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533
534 err = video_register_device(dev->empress_dev,VFL_TYPE_GRABBER,
535 empress_nr[dev->nr]);
536 if (err < 0) {
537 printk(KERN_INFO "%s: can't register video device\n",
538 dev->name);
539 video_device_release(dev->empress_dev);
540 dev->empress_dev = NULL;
541 return err;
542 }
543 printk(KERN_INFO "%s: registered device video%d [mpeg]\n",
Hans Verkuilc6330fb2008-10-19 18:54:26 -0300544 dev->name, dev->empress_dev->num);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
Guennadi Liakhovetski07051352008-04-22 14:42:13 -0300546 videobuf_queue_sg_init(&dev->empress_tsq, &saa7134_ts_qops,
547 &dev->pci->dev, &dev->slock,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 V4L2_BUF_TYPE_VIDEO_CAPTURE,
549 V4L2_FIELD_ALTERNATE,
550 sizeof(struct saa7134_buf),
551 dev);
552
David Howellsc4028952006-11-22 14:57:56 +0000553 empress_signal_update(&dev->empress_workqueue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 return 0;
555}
556
557static int empress_fini(struct saa7134_dev *dev)
558{
Harvey Harrison50163812008-04-08 23:20:00 -0300559 dprintk("%s: %s\n",dev->name,__func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560
561 if (NULL == dev->empress_dev)
562 return 0;
563 flush_scheduled_work();
564 video_unregister_device(dev->empress_dev);
565 dev->empress_dev = NULL;
566 return 0;
567}
568
569static struct saa7134_mpeg_ops empress_ops = {
570 .type = SAA7134_MPEG_EMPRESS,
571 .init = empress_init,
572 .fini = empress_fini,
573 .signal_change = empress_signal_change,
574};
575
576static int __init empress_register(void)
577{
578 return saa7134_ts_register(&empress_ops);
579}
580
581static void __exit empress_unregister(void)
582{
583 saa7134_ts_unregister(&empress_ops);
584}
585
586module_init(empress_register);
587module_exit(empress_unregister);
588
589/* ----------------------------------------------------------- */
590/*
591 * Local variables:
592 * c-basic-offset: 8
593 * End:
594 */