Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/delay.h> |
| 25 | |
Michael Krufky | 5e453dc | 2006-01-09 15:32:31 -0200 | [diff] [blame] | 26 | #include <media/v4l2-common.h> |
Hans Verkuil | a200450 | 2013-12-14 08:28:28 -0300 | [diff] [blame] | 27 | #include <media/v4l2-event.h> |
| 28 | |
| 29 | #include "saa7134-reg.h" |
| 30 | #include "saa7134.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
| 32 | /* ------------------------------------------------------------------ */ |
| 33 | |
| 34 | MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]"); |
| 35 | MODULE_LICENSE("GPL"); |
| 36 | |
| 37 | static unsigned int empress_nr[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET }; |
Mauro Carvalho Chehab | 674434c | 2005-12-12 00:37:28 -0800 | [diff] [blame] | 38 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | module_param_array(empress_nr, int, NULL, 0444); |
| 40 | MODULE_PARM_DESC(empress_nr,"ts device number"); |
| 41 | |
Douglas Schilling Landgraf | ff699e6 | 2008-04-22 14:41:48 -0300 | [diff] [blame] | 42 | static unsigned int debug; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | module_param(debug, int, 0644); |
| 44 | MODULE_PARM_DESC(debug,"enable debug messages"); |
| 45 | |
| 46 | #define dprintk(fmt, arg...) if (debug) \ |
| 47 | printk(KERN_DEBUG "%s/empress: " fmt, dev->name , ## arg) |
| 48 | |
| 49 | /* ------------------------------------------------------------------ */ |
| 50 | |
| 51 | static void ts_reset_encoder(struct saa7134_dev* dev) |
| 52 | { |
| 53 | if (!dev->empress_started) |
| 54 | return; |
| 55 | |
| 56 | saa_writeb(SAA7134_SPECIAL_MODE, 0x00); |
| 57 | msleep(10); |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 58 | saa_writeb(SAA7134_SPECIAL_MODE, 0x01); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | msleep(100); |
| 60 | dev->empress_started = 0; |
| 61 | } |
| 62 | |
| 63 | static int ts_init_encoder(struct saa7134_dev* dev) |
| 64 | { |
Dmitry Belimov | f03813e | 2008-08-26 13:44:40 -0300 | [diff] [blame] | 65 | u32 leading_null_bytes = 0; |
Hans Verkuil | 86b79d66 | 2006-06-18 16:40:10 -0300 | [diff] [blame] | 66 | |
Dmitry Belimov | f03813e | 2008-08-26 13:44:40 -0300 | [diff] [blame] | 67 | /* If more cards start to need this, then this |
| 68 | should probably be added to the card definitions. */ |
| 69 | switch (dev->board) { |
| 70 | case SAA7134_BOARD_BEHOLD_M6: |
| 71 | case SAA7134_BOARD_BEHOLD_M63: |
| 72 | case SAA7134_BOARD_BEHOLD_M6_EXTRA: |
| 73 | leading_null_bytes = 1; |
| 74 | break; |
| 75 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | ts_reset_encoder(dev); |
Hans Verkuil | fac6986c | 2009-01-17 12:17:14 -0300 | [diff] [blame] | 77 | saa_call_all(dev, core, init, leading_null_bytes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | dev->empress_started = 1; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 79 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | /* ------------------------------------------------------------------ */ |
| 83 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 84 | static int ts_open(struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | { |
Laurent Pinchart | 50462eb | 2009-12-10 11:47:13 -0200 | [diff] [blame] | 86 | struct video_device *vdev = video_devdata(file); |
Laurent Pinchart | 63b0d5a | 2009-12-10 11:44:04 -0200 | [diff] [blame] | 87 | struct saa7134_dev *dev = video_drvdata(file); |
Hans Verkuil | b9f63b2 | 2013-12-14 08:28:26 -0300 | [diff] [blame] | 88 | struct saa7134_fh *fh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
Hans Verkuil | b9f63b2 | 2013-12-14 08:28:26 -0300 | [diff] [blame] | 90 | /* allocate + initialize per filehandle data */ |
| 91 | fh = kzalloc(sizeof(*fh), GFP_KERNEL); |
Hans Verkuil | b9f63b2 | 2013-12-14 08:28:26 -0300 | [diff] [blame] | 92 | if (NULL == fh) |
Hans Verkuil | ce79113 | 2013-12-14 08:28:27 -0300 | [diff] [blame] | 93 | return -ENOMEM; |
Hans Verkuil | b9f63b2 | 2013-12-14 08:28:26 -0300 | [diff] [blame] | 94 | |
| 95 | v4l2_fh_init(&fh->fh, vdev); |
| 96 | file->private_data = fh; |
| 97 | fh->is_empress = true; |
| 98 | v4l2_fh_add(&fh->fh); |
| 99 | |
Rafael Bilski | b784e52 | 2007-06-20 05:37:27 -0300 | [diff] [blame] | 100 | /* Unmute audio */ |
| 101 | saa_writeb(SAA7134_AUDIO_MUTE_CTRL, |
| 102 | saa_readb(SAA7134_AUDIO_MUTE_CTRL) & ~(1 << 6)); |
| 103 | |
Hans Verkuil | ce79113 | 2013-12-14 08:28:27 -0300 | [diff] [blame] | 104 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | } |
| 106 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 107 | static int ts_release(struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | { |
Hans Verkuil | b9f63b2 | 2013-12-14 08:28:26 -0300 | [diff] [blame] | 109 | struct saa7134_dev *dev = video_drvdata(file); |
| 110 | struct saa7134_fh *fh = file->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
Hans Verkuil | ce79113 | 2013-12-14 08:28:27 -0300 | [diff] [blame] | 112 | if (res_check(fh, RESOURCE_EMPRESS)) { |
| 113 | videobuf_stop(&dev->empress_tsq); |
| 114 | videobuf_mmap_free(&dev->empress_tsq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | |
Hans Verkuil | ce79113 | 2013-12-14 08:28:27 -0300 | [diff] [blame] | 116 | /* stop the encoder */ |
| 117 | ts_reset_encoder(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
Hans Verkuil | ce79113 | 2013-12-14 08:28:27 -0300 | [diff] [blame] | 119 | /* Mute audio */ |
| 120 | saa_writeb(SAA7134_AUDIO_MUTE_CTRL, |
| 121 | saa_readb(SAA7134_AUDIO_MUTE_CTRL) | (1 << 6)); |
| 122 | } |
Arjan van de Ven | a178987 | 2008-06-22 17:03:02 -0300 | [diff] [blame] | 123 | |
Hans Verkuil | b9f63b2 | 2013-12-14 08:28:26 -0300 | [diff] [blame] | 124 | v4l2_fh_del(&fh->fh); |
| 125 | v4l2_fh_exit(&fh->fh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | return 0; |
| 127 | } |
| 128 | |
| 129 | static ssize_t |
| 130 | ts_read(struct file *file, char __user *data, size_t count, loff_t *ppos) |
| 131 | { |
Hans Verkuil | b9f63b2 | 2013-12-14 08:28:26 -0300 | [diff] [blame] | 132 | struct saa7134_dev *dev = video_drvdata(file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | |
Hans Verkuil | ce79113 | 2013-12-14 08:28:27 -0300 | [diff] [blame] | 134 | if (res_locked(dev, RESOURCE_EMPRESS)) |
| 135 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | if (!dev->empress_started) |
| 137 | ts_init_encoder(dev); |
| 138 | |
| 139 | return videobuf_read_stream(&dev->empress_tsq, |
| 140 | data, count, ppos, 0, |
| 141 | file->f_flags & O_NONBLOCK); |
| 142 | } |
| 143 | |
| 144 | static unsigned int |
| 145 | ts_poll(struct file *file, struct poll_table_struct *wait) |
| 146 | { |
Hans Verkuil | a200450 | 2013-12-14 08:28:28 -0300 | [diff] [blame] | 147 | unsigned long req_events = poll_requested_events(wait); |
Hans Verkuil | b9f63b2 | 2013-12-14 08:28:26 -0300 | [diff] [blame] | 148 | struct saa7134_dev *dev = video_drvdata(file); |
Hans Verkuil | a200450 | 2013-12-14 08:28:28 -0300 | [diff] [blame] | 149 | struct saa7134_fh *fh = file->private_data; |
| 150 | unsigned int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
Hans Verkuil | a200450 | 2013-12-14 08:28:28 -0300 | [diff] [blame] | 152 | if (v4l2_event_pending(&fh->fh)) |
| 153 | rc = POLLPRI; |
| 154 | else if (req_events & POLLPRI) |
| 155 | poll_wait(file, &fh->fh.wait, wait); |
| 156 | return rc | videobuf_poll_stream(file, &dev->empress_tsq, wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | |
| 160 | static int |
| 161 | ts_mmap(struct file *file, struct vm_area_struct * vma) |
| 162 | { |
Hans Verkuil | b9f63b2 | 2013-12-14 08:28:26 -0300 | [diff] [blame] | 163 | struct saa7134_dev *dev = video_drvdata(file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | |
| 165 | return videobuf_mmap_mapper(&dev->empress_tsq, vma); |
| 166 | } |
| 167 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 168 | static int empress_enum_fmt_vid_cap(struct file *file, void *priv, |
Mauro Carvalho Chehab | 2c10e8a | 2007-12-11 12:56:23 -0300 | [diff] [blame] | 169 | struct v4l2_fmtdesc *f) |
| 170 | { |
| 171 | if (f->index != 0) |
| 172 | return -EINVAL; |
| 173 | |
| 174 | strlcpy(f->description, "MPEG TS", sizeof(f->description)); |
| 175 | f->pixelformat = V4L2_PIX_FMT_MPEG; |
Hans Verkuil | cabc650 | 2013-06-01 10:02:38 -0300 | [diff] [blame] | 176 | f->flags = V4L2_FMT_FLAG_COMPRESSED; |
Mauro Carvalho Chehab | 2c10e8a | 2007-12-11 12:56:23 -0300 | [diff] [blame] | 177 | return 0; |
| 178 | } |
| 179 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 180 | static int empress_g_fmt_vid_cap(struct file *file, void *priv, |
Mauro Carvalho Chehab | 2c10e8a | 2007-12-11 12:56:23 -0300 | [diff] [blame] | 181 | struct v4l2_format *f) |
| 182 | { |
Hans Verkuil | b9f63b2 | 2013-12-14 08:28:26 -0300 | [diff] [blame] | 183 | struct saa7134_dev *dev = video_drvdata(file); |
Hans Verkuil | 31bf95f | 2010-05-09 09:41:41 -0300 | [diff] [blame] | 184 | struct v4l2_mbus_framefmt mbus_fmt; |
Mauro Carvalho Chehab | 2c10e8a | 2007-12-11 12:56:23 -0300 | [diff] [blame] | 185 | |
Hans Verkuil | 31bf95f | 2010-05-09 09:41:41 -0300 | [diff] [blame] | 186 | saa_call_all(dev, video, g_mbus_fmt, &mbus_fmt); |
Mauro Carvalho Chehab | 2c10e8a | 2007-12-11 12:56:23 -0300 | [diff] [blame] | 187 | |
Hans Verkuil | 31bf95f | 2010-05-09 09:41:41 -0300 | [diff] [blame] | 188 | v4l2_fill_pix_format(&f->fmt.pix, &mbus_fmt); |
Mauro Carvalho Chehab | 2c10e8a | 2007-12-11 12:56:23 -0300 | [diff] [blame] | 189 | f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG; |
| 190 | f->fmt.pix.sizeimage = TS_PACKET_SIZE * dev->ts.nr_packets; |
Hans Verkuil | cabc650 | 2013-06-01 10:02:38 -0300 | [diff] [blame] | 191 | f->fmt.pix.bytesperline = 0; |
| 192 | f->fmt.pix.priv = 0; |
Mauro Carvalho Chehab | 2c10e8a | 2007-12-11 12:56:23 -0300 | [diff] [blame] | 193 | |
| 194 | return 0; |
| 195 | } |
| 196 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 197 | static int empress_s_fmt_vid_cap(struct file *file, void *priv, |
Mauro Carvalho Chehab | 2c10e8a | 2007-12-11 12:56:23 -0300 | [diff] [blame] | 198 | struct v4l2_format *f) |
| 199 | { |
Hans Verkuil | b9f63b2 | 2013-12-14 08:28:26 -0300 | [diff] [blame] | 200 | struct saa7134_dev *dev = video_drvdata(file); |
Hans Verkuil | 31bf95f | 2010-05-09 09:41:41 -0300 | [diff] [blame] | 201 | struct v4l2_mbus_framefmt mbus_fmt; |
Mauro Carvalho Chehab | 2c10e8a | 2007-12-11 12:56:23 -0300 | [diff] [blame] | 202 | |
Hans Verkuil | 31bf95f | 2010-05-09 09:41:41 -0300 | [diff] [blame] | 203 | v4l2_fill_mbus_format(&mbus_fmt, &f->fmt.pix, V4L2_MBUS_FMT_FIXED); |
| 204 | saa_call_all(dev, video, s_mbus_fmt, &mbus_fmt); |
| 205 | v4l2_fill_pix_format(&f->fmt.pix, &mbus_fmt); |
Mauro Carvalho Chehab | 2c10e8a | 2007-12-11 12:56:23 -0300 | [diff] [blame] | 206 | |
| 207 | f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG; |
| 208 | f->fmt.pix.sizeimage = TS_PACKET_SIZE * dev->ts.nr_packets; |
Hans Verkuil | cabc650 | 2013-06-01 10:02:38 -0300 | [diff] [blame] | 209 | f->fmt.pix.bytesperline = 0; |
| 210 | f->fmt.pix.priv = 0; |
Mauro Carvalho Chehab | 2c10e8a | 2007-12-11 12:56:23 -0300 | [diff] [blame] | 211 | |
| 212 | return 0; |
| 213 | } |
| 214 | |
Dmitri Belimov | 6b6b754 | 2009-05-28 01:58:57 -0300 | [diff] [blame] | 215 | static int empress_try_fmt_vid_cap(struct file *file, void *priv, |
| 216 | struct v4l2_format *f) |
| 217 | { |
Hans Verkuil | b9f63b2 | 2013-12-14 08:28:26 -0300 | [diff] [blame] | 218 | struct saa7134_dev *dev = video_drvdata(file); |
Hans Verkuil | cabc650 | 2013-06-01 10:02:38 -0300 | [diff] [blame] | 219 | struct v4l2_mbus_framefmt mbus_fmt; |
| 220 | |
| 221 | v4l2_fill_mbus_format(&mbus_fmt, &f->fmt.pix, V4L2_MBUS_FMT_FIXED); |
| 222 | saa_call_all(dev, video, try_mbus_fmt, &mbus_fmt); |
| 223 | v4l2_fill_pix_format(&f->fmt.pix, &mbus_fmt); |
Dmitri Belimov | 6b6b754 | 2009-05-28 01:58:57 -0300 | [diff] [blame] | 224 | |
| 225 | f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG; |
| 226 | f->fmt.pix.sizeimage = TS_PACKET_SIZE * dev->ts.nr_packets; |
Hans Verkuil | cabc650 | 2013-06-01 10:02:38 -0300 | [diff] [blame] | 227 | f->fmt.pix.bytesperline = 0; |
| 228 | f->fmt.pix.priv = 0; |
Dmitri Belimov | 6b6b754 | 2009-05-28 01:58:57 -0300 | [diff] [blame] | 229 | |
| 230 | return 0; |
| 231 | } |
Mauro Carvalho Chehab | 2c10e8a | 2007-12-11 12:56:23 -0300 | [diff] [blame] | 232 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 233 | static const struct v4l2_file_operations ts_fops = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | { |
| 235 | .owner = THIS_MODULE, |
| 236 | .open = ts_open, |
| 237 | .release = ts_release, |
| 238 | .read = ts_read, |
| 239 | .poll = ts_poll, |
| 240 | .mmap = ts_mmap, |
Mauro Carvalho Chehab | 2c10e8a | 2007-12-11 12:56:23 -0300 | [diff] [blame] | 241 | .ioctl = video_ioctl2, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | }; |
| 243 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 244 | static const struct v4l2_ioctl_ops ts_ioctl_ops = { |
Hans Verkuil | b93a18d | 2013-12-14 08:28:25 -0300 | [diff] [blame] | 245 | .vidioc_querycap = saa7134_querycap, |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 246 | .vidioc_enum_fmt_vid_cap = empress_enum_fmt_vid_cap, |
Dmitri Belimov | 6b6b754 | 2009-05-28 01:58:57 -0300 | [diff] [blame] | 247 | .vidioc_try_fmt_vid_cap = empress_try_fmt_vid_cap, |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 248 | .vidioc_s_fmt_vid_cap = empress_s_fmt_vid_cap, |
| 249 | .vidioc_g_fmt_vid_cap = empress_g_fmt_vid_cap, |
Hans Verkuil | ce79113 | 2013-12-14 08:28:27 -0300 | [diff] [blame] | 250 | .vidioc_reqbufs = saa7134_reqbufs, |
| 251 | .vidioc_querybuf = saa7134_querybuf, |
| 252 | .vidioc_qbuf = saa7134_qbuf, |
| 253 | .vidioc_dqbuf = saa7134_dqbuf, |
| 254 | .vidioc_streamon = saa7134_streamon, |
| 255 | .vidioc_streamoff = saa7134_streamoff, |
Hans Verkuil | b93a18d | 2013-12-14 08:28:25 -0300 | [diff] [blame] | 256 | .vidioc_g_frequency = saa7134_g_frequency, |
| 257 | .vidioc_s_frequency = saa7134_s_frequency, |
| 258 | .vidioc_g_tuner = saa7134_g_tuner, |
| 259 | .vidioc_s_tuner = saa7134_s_tuner, |
| 260 | .vidioc_enum_input = saa7134_enum_input, |
| 261 | .vidioc_g_input = saa7134_g_input, |
| 262 | .vidioc_s_input = saa7134_s_input, |
| 263 | .vidioc_s_std = saa7134_s_std, |
| 264 | .vidioc_g_std = saa7134_g_std, |
Hans Verkuil | a200450 | 2013-12-14 08:28:28 -0300 | [diff] [blame] | 265 | .vidioc_log_status = v4l2_ctrl_log_status, |
| 266 | .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, |
| 267 | .vidioc_unsubscribe_event = v4l2_event_unsubscribe, |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 268 | }; |
| 269 | |
| 270 | /* ----------------------------------------------------------- */ |
| 271 | |
| 272 | static struct video_device saa7134_empress_template = { |
| 273 | .name = "saa7134-empress", |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 274 | .fops = &ts_fops, |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 275 | .ioctl_ops = &ts_ioctl_ops, |
Mauro Carvalho Chehab | 2c10e8a | 2007-12-11 12:56:23 -0300 | [diff] [blame] | 276 | |
| 277 | .tvnorms = SAA7134_NORMS, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | }; |
| 279 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 280 | static void empress_signal_update(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 282 | struct saa7134_dev* dev = |
| 283 | container_of(work, struct saa7134_dev, empress_workqueue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | |
| 285 | if (dev->nosignal) { |
| 286 | dprintk("no video signal\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | } else { |
| 288 | dprintk("video signal acquired\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | } |
| 290 | } |
| 291 | |
| 292 | static void empress_signal_change(struct saa7134_dev *dev) |
| 293 | { |
| 294 | schedule_work(&dev->empress_workqueue); |
| 295 | } |
| 296 | |
Hans Verkuil | 718bde1 | 2013-12-14 08:28:24 -0300 | [diff] [blame] | 297 | static bool empress_ctrl_filter(const struct v4l2_ctrl *ctrl) |
| 298 | { |
| 299 | switch (ctrl->id) { |
| 300 | case V4L2_CID_BRIGHTNESS: |
| 301 | case V4L2_CID_HUE: |
| 302 | case V4L2_CID_CONTRAST: |
| 303 | case V4L2_CID_SATURATION: |
| 304 | case V4L2_CID_AUDIO_MUTE: |
| 305 | case V4L2_CID_AUDIO_VOLUME: |
| 306 | case V4L2_CID_PRIVATE_INVERT: |
| 307 | case V4L2_CID_PRIVATE_AUTOMUTE: |
| 308 | return true; |
| 309 | default: |
| 310 | return false; |
| 311 | } |
| 312 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | |
| 314 | static int empress_init(struct saa7134_dev *dev) |
| 315 | { |
Hans Verkuil | 718bde1 | 2013-12-14 08:28:24 -0300 | [diff] [blame] | 316 | struct v4l2_ctrl_handler *hdl = &dev->empress_ctrl_handler; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | int err; |
| 318 | |
Harvey Harrison | 5016381 | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 319 | dprintk("%s: %s\n",dev->name,__func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | dev->empress_dev = video_device_alloc(); |
| 321 | if (NULL == dev->empress_dev) |
| 322 | return -ENOMEM; |
| 323 | *(dev->empress_dev) = saa7134_empress_template; |
Hans Verkuil | d481c58 | 2013-06-20 10:57:10 -0300 | [diff] [blame] | 324 | dev->empress_dev->v4l2_dev = &dev->v4l2_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | dev->empress_dev->release = video_device_release; |
| 326 | snprintf(dev->empress_dev->name, sizeof(dev->empress_dev->name), |
| 327 | "%s empress (%s)", dev->name, |
| 328 | saa7134_boards[dev->board].name); |
Hans Verkuil | ce79113 | 2013-12-14 08:28:27 -0300 | [diff] [blame] | 329 | set_bit(V4L2_FL_USE_FH_PRIO, &dev->empress_dev->flags); |
Hans Verkuil | 718bde1 | 2013-12-14 08:28:24 -0300 | [diff] [blame] | 330 | v4l2_ctrl_handler_init(hdl, 21); |
| 331 | v4l2_ctrl_add_handler(hdl, &dev->ctrl_handler, empress_ctrl_filter); |
| 332 | if (dev->empress_sd) |
| 333 | v4l2_ctrl_add_handler(hdl, dev->empress_sd->ctrl_handler, NULL); |
| 334 | if (hdl->error) { |
| 335 | video_device_release(dev->empress_dev); |
| 336 | return hdl->error; |
| 337 | } |
| 338 | dev->empress_dev->ctrl_handler = hdl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 340 | INIT_WORK(&dev->empress_workqueue, empress_signal_update); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | |
Laurent Pinchart | 63b0d5a | 2009-12-10 11:44:04 -0200 | [diff] [blame] | 342 | video_set_drvdata(dev->empress_dev, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | err = video_register_device(dev->empress_dev,VFL_TYPE_GRABBER, |
| 344 | empress_nr[dev->nr]); |
| 345 | if (err < 0) { |
| 346 | printk(KERN_INFO "%s: can't register video device\n", |
| 347 | dev->name); |
| 348 | video_device_release(dev->empress_dev); |
| 349 | dev->empress_dev = NULL; |
| 350 | return err; |
| 351 | } |
Laurent Pinchart | 38c7c03 | 2009-11-27 13:57:15 -0300 | [diff] [blame] | 352 | printk(KERN_INFO "%s: registered device %s [mpeg]\n", |
| 353 | dev->name, video_device_node_name(dev->empress_dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | |
Guennadi Liakhovetski | 0705135 | 2008-04-22 14:42:13 -0300 | [diff] [blame] | 355 | videobuf_queue_sg_init(&dev->empress_tsq, &saa7134_ts_qops, |
| 356 | &dev->pci->dev, &dev->slock, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | V4L2_BUF_TYPE_VIDEO_CAPTURE, |
| 358 | V4L2_FIELD_ALTERNATE, |
| 359 | sizeof(struct saa7134_buf), |
Hans Verkuil | 08bff03 | 2010-09-20 17:39:46 -0300 | [diff] [blame] | 360 | dev, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 362 | empress_signal_update(&dev->empress_workqueue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | return 0; |
| 364 | } |
| 365 | |
| 366 | static int empress_fini(struct saa7134_dev *dev) |
| 367 | { |
Harvey Harrison | 5016381 | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 368 | dprintk("%s: %s\n",dev->name,__func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | |
| 370 | if (NULL == dev->empress_dev) |
| 371 | return 0; |
Tejun Heo | 4382973 | 2012-08-20 14:51:24 -0700 | [diff] [blame] | 372 | flush_work(&dev->empress_workqueue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | video_unregister_device(dev->empress_dev); |
Hans Verkuil | 718bde1 | 2013-12-14 08:28:24 -0300 | [diff] [blame] | 374 | v4l2_ctrl_handler_free(&dev->empress_ctrl_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | dev->empress_dev = NULL; |
| 376 | return 0; |
| 377 | } |
| 378 | |
| 379 | static struct saa7134_mpeg_ops empress_ops = { |
| 380 | .type = SAA7134_MPEG_EMPRESS, |
| 381 | .init = empress_init, |
| 382 | .fini = empress_fini, |
| 383 | .signal_change = empress_signal_change, |
| 384 | }; |
| 385 | |
| 386 | static int __init empress_register(void) |
| 387 | { |
| 388 | return saa7134_ts_register(&empress_ops); |
| 389 | } |
| 390 | |
| 391 | static void __exit empress_unregister(void) |
| 392 | { |
| 393 | saa7134_ts_unregister(&empress_ops); |
| 394 | } |
| 395 | |
| 396 | module_init(empress_register); |
| 397 | module_exit(empress_unregister); |