Thomas Gleixner | c942fdd | 2019-05-27 08:55:06 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
| 4 | * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs] |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
Mauro Carvalho Chehab | 9a12ccf | 2015-04-30 06:44:56 -0300 | [diff] [blame] | 7 | #include "saa7134.h" |
| 8 | #include "saa7134-reg.h" |
| 9 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/init.h> |
| 11 | #include <linux/list.h> |
| 12 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/delay.h> |
| 15 | |
Michael Krufky | 5e453dc | 2006-01-09 15:32:31 -0200 | [diff] [blame] | 16 | #include <media/v4l2-common.h> |
Hans Verkuil | a200450 | 2013-12-14 08:28:28 -0300 | [diff] [blame] | 17 | #include <media/v4l2-event.h> |
| 18 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | /* ------------------------------------------------------------------ */ |
| 20 | |
| 21 | MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]"); |
| 22 | MODULE_LICENSE("GPL"); |
| 23 | |
| 24 | static unsigned int empress_nr[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET }; |
Mauro Carvalho Chehab | 674434c | 2005-12-12 00:37:28 -0800 | [diff] [blame] | 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | module_param_array(empress_nr, int, NULL, 0444); |
| 27 | MODULE_PARM_DESC(empress_nr,"ts device number"); |
| 28 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | /* ------------------------------------------------------------------ */ |
| 30 | |
Hans Verkuil | 2ada815 | 2014-04-17 07:30:53 -0300 | [diff] [blame] | 31 | static int start_streaming(struct vb2_queue *vq, unsigned int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | { |
Hans Verkuil | 2ada815 | 2014-04-17 07:30:53 -0300 | [diff] [blame] | 33 | struct saa7134_dmaqueue *dmaq = vq->drv_priv; |
| 34 | struct saa7134_dev *dev = dmaq->dev; |
Dmitry Belimov | f03813e | 2008-08-26 13:44:40 -0300 | [diff] [blame] | 35 | u32 leading_null_bytes = 0; |
Hans Verkuil | 2ada815 | 2014-04-17 07:30:53 -0300 | [diff] [blame] | 36 | int err; |
| 37 | |
| 38 | err = saa7134_ts_start_streaming(vq, count); |
| 39 | if (err) |
| 40 | return err; |
Hans Verkuil | 86b79d66 | 2006-06-18 16:40:10 -0300 | [diff] [blame] | 41 | |
Dmitry Belimov | f03813e | 2008-08-26 13:44:40 -0300 | [diff] [blame] | 42 | /* If more cards start to need this, then this |
| 43 | should probably be added to the card definitions. */ |
| 44 | switch (dev->board) { |
| 45 | case SAA7134_BOARD_BEHOLD_M6: |
| 46 | case SAA7134_BOARD_BEHOLD_M63: |
| 47 | case SAA7134_BOARD_BEHOLD_M6_EXTRA: |
| 48 | leading_null_bytes = 1; |
| 49 | break; |
| 50 | } |
Hans Verkuil | fac6986c | 2009-01-17 12:17:14 -0300 | [diff] [blame] | 51 | saa_call_all(dev, core, init, leading_null_bytes); |
Hans Verkuil | 2ada815 | 2014-04-17 07:30:53 -0300 | [diff] [blame] | 52 | /* Unmute audio */ |
| 53 | saa_writeb(SAA7134_AUDIO_MUTE_CTRL, |
| 54 | saa_readb(SAA7134_AUDIO_MUTE_CTRL) & ~(1 << 6)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | dev->empress_started = 1; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 56 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Hans Verkuil | 2ada815 | 2014-04-17 07:30:53 -0300 | [diff] [blame] | 59 | static void stop_streaming(struct vb2_queue *vq) |
Hans Verkuil | 51aefd7 | 2014-04-17 04:23:07 -0300 | [diff] [blame] | 60 | { |
Hans Verkuil | 2ada815 | 2014-04-17 07:30:53 -0300 | [diff] [blame] | 61 | struct saa7134_dmaqueue *dmaq = vq->drv_priv; |
| 62 | struct saa7134_dev *dev = dmaq->dev; |
Hans Verkuil | 51aefd7 | 2014-04-17 04:23:07 -0300 | [diff] [blame] | 63 | |
Hans Verkuil | 2ada815 | 2014-04-17 07:30:53 -0300 | [diff] [blame] | 64 | saa7134_ts_stop_streaming(vq); |
Hans Verkuil | 51aefd7 | 2014-04-17 04:23:07 -0300 | [diff] [blame] | 65 | saa_writeb(SAA7134_SPECIAL_MODE, 0x00); |
Hans Verkuil | 2ada815 | 2014-04-17 07:30:53 -0300 | [diff] [blame] | 66 | msleep(20); |
Hans Verkuil | 51aefd7 | 2014-04-17 04:23:07 -0300 | [diff] [blame] | 67 | saa_writeb(SAA7134_SPECIAL_MODE, 0x01); |
| 68 | msleep(100); |
Hans Verkuil | 2ada815 | 2014-04-17 07:30:53 -0300 | [diff] [blame] | 69 | /* Mute audio */ |
| 70 | saa_writeb(SAA7134_AUDIO_MUTE_CTRL, |
| 71 | saa_readb(SAA7134_AUDIO_MUTE_CTRL) | (1 << 6)); |
Hans Verkuil | 51aefd7 | 2014-04-17 04:23:07 -0300 | [diff] [blame] | 72 | dev->empress_started = 0; |
| 73 | } |
| 74 | |
Julia Lawall | 10accd2 | 2016-09-08 20:59:18 -0300 | [diff] [blame] | 75 | static const struct vb2_ops saa7134_empress_qops = { |
Hans Verkuil | 2ada815 | 2014-04-17 07:30:53 -0300 | [diff] [blame] | 76 | .queue_setup = saa7134_ts_queue_setup, |
| 77 | .buf_init = saa7134_ts_buffer_init, |
| 78 | .buf_prepare = saa7134_ts_buffer_prepare, |
Hans Verkuil | 2ada815 | 2014-04-17 07:30:53 -0300 | [diff] [blame] | 79 | .buf_queue = saa7134_vb2_buffer_queue, |
| 80 | .wait_prepare = vb2_ops_wait_prepare, |
| 81 | .wait_finish = vb2_ops_wait_finish, |
| 82 | .start_streaming = start_streaming, |
| 83 | .stop_streaming = stop_streaming, |
| 84 | }; |
| 85 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | /* ------------------------------------------------------------------ */ |
| 87 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 88 | 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] | 89 | struct v4l2_fmtdesc *f) |
| 90 | { |
| 91 | if (f->index != 0) |
| 92 | return -EINVAL; |
| 93 | |
Mauro Carvalho Chehab | 2c10e8a | 2007-12-11 12:56:23 -0300 | [diff] [blame] | 94 | f->pixelformat = V4L2_PIX_FMT_MPEG; |
Mauro Carvalho Chehab | 2c10e8a | 2007-12-11 12:56:23 -0300 | [diff] [blame] | 95 | return 0; |
| 96 | } |
| 97 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 98 | 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] | 99 | struct v4l2_format *f) |
| 100 | { |
Hans Verkuil | b9f63b2 | 2013-12-14 08:28:26 -0300 | [diff] [blame] | 101 | struct saa7134_dev *dev = video_drvdata(file); |
Hans Verkuil | da298c6 | 2015-04-09 04:02:34 -0300 | [diff] [blame] | 102 | struct v4l2_subdev_format fmt = { |
| 103 | .which = V4L2_SUBDEV_FORMAT_ACTIVE, |
| 104 | }; |
| 105 | struct v4l2_mbus_framefmt *mbus_fmt = &fmt.format; |
Mauro Carvalho Chehab | 2c10e8a | 2007-12-11 12:56:23 -0300 | [diff] [blame] | 106 | |
Hans Verkuil | da298c6 | 2015-04-09 04:02:34 -0300 | [diff] [blame] | 107 | saa_call_all(dev, pad, get_fmt, NULL, &fmt); |
Mauro Carvalho Chehab | 2c10e8a | 2007-12-11 12:56:23 -0300 | [diff] [blame] | 108 | |
Hans Verkuil | da298c6 | 2015-04-09 04:02:34 -0300 | [diff] [blame] | 109 | v4l2_fill_pix_format(&f->fmt.pix, mbus_fmt); |
Mauro Carvalho Chehab | 2c10e8a | 2007-12-11 12:56:23 -0300 | [diff] [blame] | 110 | f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG; |
| 111 | f->fmt.pix.sizeimage = TS_PACKET_SIZE * dev->ts.nr_packets; |
Hans Verkuil | cabc650 | 2013-06-01 10:02:38 -0300 | [diff] [blame] | 112 | f->fmt.pix.bytesperline = 0; |
Mauro Carvalho Chehab | 2c10e8a | 2007-12-11 12:56:23 -0300 | [diff] [blame] | 113 | |
| 114 | return 0; |
| 115 | } |
| 116 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 117 | 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] | 118 | struct v4l2_format *f) |
| 119 | { |
Hans Verkuil | b9f63b2 | 2013-12-14 08:28:26 -0300 | [diff] [blame] | 120 | struct saa7134_dev *dev = video_drvdata(file); |
Hans Verkuil | ebf984b | 2015-04-09 04:05:59 -0300 | [diff] [blame] | 121 | struct v4l2_subdev_format format = { |
| 122 | .which = V4L2_SUBDEV_FORMAT_ACTIVE, |
| 123 | }; |
Mauro Carvalho Chehab | 2c10e8a | 2007-12-11 12:56:23 -0300 | [diff] [blame] | 124 | |
Hans Verkuil | ebf984b | 2015-04-09 04:05:59 -0300 | [diff] [blame] | 125 | v4l2_fill_mbus_format(&format.format, &f->fmt.pix, MEDIA_BUS_FMT_FIXED); |
| 126 | saa_call_all(dev, pad, set_fmt, NULL, &format); |
| 127 | v4l2_fill_pix_format(&f->fmt.pix, &format.format); |
Mauro Carvalho Chehab | 2c10e8a | 2007-12-11 12:56:23 -0300 | [diff] [blame] | 128 | |
| 129 | f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG; |
| 130 | f->fmt.pix.sizeimage = TS_PACKET_SIZE * dev->ts.nr_packets; |
Hans Verkuil | cabc650 | 2013-06-01 10:02:38 -0300 | [diff] [blame] | 131 | f->fmt.pix.bytesperline = 0; |
Mauro Carvalho Chehab | 2c10e8a | 2007-12-11 12:56:23 -0300 | [diff] [blame] | 132 | |
| 133 | return 0; |
| 134 | } |
| 135 | |
Dmitri Belimov | 6b6b754 | 2009-05-28 01:58:57 -0300 | [diff] [blame] | 136 | static int empress_try_fmt_vid_cap(struct file *file, void *priv, |
| 137 | struct v4l2_format *f) |
| 138 | { |
Hans Verkuil | b9f63b2 | 2013-12-14 08:28:26 -0300 | [diff] [blame] | 139 | struct saa7134_dev *dev = video_drvdata(file); |
Hans Verkuil | 5eab498 | 2015-04-09 04:05:35 -0300 | [diff] [blame] | 140 | struct v4l2_subdev_pad_config pad_cfg; |
Tomi Valkeinen | 0d346d2 | 2021-06-10 17:55:58 +0300 | [diff] [blame] | 141 | struct v4l2_subdev_state pad_state = { |
| 142 | .pads = &pad_cfg |
| 143 | }; |
Hans Verkuil | 5eab498 | 2015-04-09 04:05:35 -0300 | [diff] [blame] | 144 | struct v4l2_subdev_format format = { |
| 145 | .which = V4L2_SUBDEV_FORMAT_TRY, |
| 146 | }; |
Hans Verkuil | cabc650 | 2013-06-01 10:02:38 -0300 | [diff] [blame] | 147 | |
Hans Verkuil | 5eab498 | 2015-04-09 04:05:35 -0300 | [diff] [blame] | 148 | v4l2_fill_mbus_format(&format.format, &f->fmt.pix, MEDIA_BUS_FMT_FIXED); |
Tomi Valkeinen | 0d346d2 | 2021-06-10 17:55:58 +0300 | [diff] [blame] | 149 | saa_call_all(dev, pad, set_fmt, &pad_state, &format); |
Hans Verkuil | 5eab498 | 2015-04-09 04:05:35 -0300 | [diff] [blame] | 150 | v4l2_fill_pix_format(&f->fmt.pix, &format.format); |
Dmitri Belimov | 6b6b754 | 2009-05-28 01:58:57 -0300 | [diff] [blame] | 151 | |
| 152 | f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG; |
| 153 | f->fmt.pix.sizeimage = TS_PACKET_SIZE * dev->ts.nr_packets; |
Hans Verkuil | cabc650 | 2013-06-01 10:02:38 -0300 | [diff] [blame] | 154 | f->fmt.pix.bytesperline = 0; |
Dmitri Belimov | 6b6b754 | 2009-05-28 01:58:57 -0300 | [diff] [blame] | 155 | |
| 156 | return 0; |
| 157 | } |
Mauro Carvalho Chehab | 2c10e8a | 2007-12-11 12:56:23 -0300 | [diff] [blame] | 158 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 159 | static const struct v4l2_file_operations ts_fops = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | { |
| 161 | .owner = THIS_MODULE, |
Hans Verkuil | 2ada815 | 2014-04-17 07:30:53 -0300 | [diff] [blame] | 162 | .open = v4l2_fh_open, |
| 163 | .release = vb2_fop_release, |
| 164 | .read = vb2_fop_read, |
| 165 | .poll = vb2_fop_poll, |
| 166 | .mmap = vb2_fop_mmap, |
Hans Verkuil | 13936af | 2014-06-16 04:32:37 -0300 | [diff] [blame] | 167 | .unlocked_ioctl = video_ioctl2, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | }; |
| 169 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 170 | static const struct v4l2_ioctl_ops ts_ioctl_ops = { |
Hans Verkuil | b93a18d | 2013-12-14 08:28:25 -0300 | [diff] [blame] | 171 | .vidioc_querycap = saa7134_querycap, |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 172 | .vidioc_enum_fmt_vid_cap = empress_enum_fmt_vid_cap, |
Dmitri Belimov | 6b6b754 | 2009-05-28 01:58:57 -0300 | [diff] [blame] | 173 | .vidioc_try_fmt_vid_cap = empress_try_fmt_vid_cap, |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 174 | .vidioc_s_fmt_vid_cap = empress_s_fmt_vid_cap, |
| 175 | .vidioc_g_fmt_vid_cap = empress_g_fmt_vid_cap, |
Hans Verkuil | 2ada815 | 2014-04-17 07:30:53 -0300 | [diff] [blame] | 176 | .vidioc_reqbufs = vb2_ioctl_reqbufs, |
| 177 | .vidioc_querybuf = vb2_ioctl_querybuf, |
| 178 | .vidioc_qbuf = vb2_ioctl_qbuf, |
| 179 | .vidioc_dqbuf = vb2_ioctl_dqbuf, |
Hans Verkuil | 9f18302 | 2015-12-14 08:17:00 -0200 | [diff] [blame] | 180 | .vidioc_expbuf = vb2_ioctl_expbuf, |
Hans Verkuil | 2ada815 | 2014-04-17 07:30:53 -0300 | [diff] [blame] | 181 | .vidioc_streamon = vb2_ioctl_streamon, |
| 182 | .vidioc_streamoff = vb2_ioctl_streamoff, |
Hans Verkuil | b93a18d | 2013-12-14 08:28:25 -0300 | [diff] [blame] | 183 | .vidioc_g_frequency = saa7134_g_frequency, |
| 184 | .vidioc_s_frequency = saa7134_s_frequency, |
| 185 | .vidioc_g_tuner = saa7134_g_tuner, |
| 186 | .vidioc_s_tuner = saa7134_s_tuner, |
| 187 | .vidioc_enum_input = saa7134_enum_input, |
| 188 | .vidioc_g_input = saa7134_g_input, |
| 189 | .vidioc_s_input = saa7134_s_input, |
| 190 | .vidioc_s_std = saa7134_s_std, |
| 191 | .vidioc_g_std = saa7134_g_std, |
Mikhail Domrachev | 707b7f8 | 2014-04-01 09:28:17 -0300 | [diff] [blame] | 192 | .vidioc_querystd = saa7134_querystd, |
Hans Verkuil | a200450 | 2013-12-14 08:28:28 -0300 | [diff] [blame] | 193 | .vidioc_log_status = v4l2_ctrl_log_status, |
| 194 | .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, |
| 195 | .vidioc_unsubscribe_event = v4l2_event_unsubscribe, |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 196 | }; |
| 197 | |
| 198 | /* ----------------------------------------------------------- */ |
| 199 | |
Bhumika Goyal | 507e190 | 2017-08-26 09:08:11 -0400 | [diff] [blame] | 200 | static const struct video_device saa7134_empress_template = { |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 201 | .name = "saa7134-empress", |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 202 | .fops = &ts_fops, |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 203 | .ioctl_ops = &ts_ioctl_ops, |
Mauro Carvalho Chehab | 2c10e8a | 2007-12-11 12:56:23 -0300 | [diff] [blame] | 204 | |
| 205 | .tvnorms = SAA7134_NORMS, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | }; |
| 207 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 208 | static void empress_signal_update(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 210 | struct saa7134_dev* dev = |
| 211 | container_of(work, struct saa7134_dev, empress_workqueue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | |
| 213 | if (dev->nosignal) { |
Mauro Carvalho Chehab | e43c173 | 2015-04-30 07:12:19 -0300 | [diff] [blame] | 214 | pr_debug("no video signal\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | } else { |
Mauro Carvalho Chehab | e43c173 | 2015-04-30 07:12:19 -0300 | [diff] [blame] | 216 | pr_debug("video signal acquired\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | } |
| 218 | } |
| 219 | |
| 220 | static void empress_signal_change(struct saa7134_dev *dev) |
| 221 | { |
| 222 | schedule_work(&dev->empress_workqueue); |
| 223 | } |
| 224 | |
Hans Verkuil | 718bde1 | 2013-12-14 08:28:24 -0300 | [diff] [blame] | 225 | static bool empress_ctrl_filter(const struct v4l2_ctrl *ctrl) |
| 226 | { |
| 227 | switch (ctrl->id) { |
| 228 | case V4L2_CID_BRIGHTNESS: |
| 229 | case V4L2_CID_HUE: |
| 230 | case V4L2_CID_CONTRAST: |
| 231 | case V4L2_CID_SATURATION: |
| 232 | case V4L2_CID_AUDIO_MUTE: |
| 233 | case V4L2_CID_AUDIO_VOLUME: |
| 234 | case V4L2_CID_PRIVATE_INVERT: |
| 235 | case V4L2_CID_PRIVATE_AUTOMUTE: |
| 236 | return true; |
| 237 | default: |
| 238 | return false; |
| 239 | } |
| 240 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | |
| 242 | static int empress_init(struct saa7134_dev *dev) |
| 243 | { |
Hans Verkuil | 718bde1 | 2013-12-14 08:28:24 -0300 | [diff] [blame] | 244 | struct v4l2_ctrl_handler *hdl = &dev->empress_ctrl_handler; |
Hans Verkuil | 2ada815 | 2014-04-17 07:30:53 -0300 | [diff] [blame] | 245 | struct vb2_queue *q; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | int err; |
| 247 | |
Mauro Carvalho Chehab | 6139ebc | 2015-05-13 14:09:42 -0300 | [diff] [blame] | 248 | pr_debug("%s: %s\n", dev->name, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | dev->empress_dev = video_device_alloc(); |
| 250 | if (NULL == dev->empress_dev) |
| 251 | return -ENOMEM; |
| 252 | *(dev->empress_dev) = saa7134_empress_template; |
Hans Verkuil | d481c58 | 2013-06-20 10:57:10 -0300 | [diff] [blame] | 253 | dev->empress_dev->v4l2_dev = &dev->v4l2_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | dev->empress_dev->release = video_device_release; |
Hans Verkuil | 2ada815 | 2014-04-17 07:30:53 -0300 | [diff] [blame] | 255 | dev->empress_dev->lock = &dev->lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | snprintf(dev->empress_dev->name, sizeof(dev->empress_dev->name), |
| 257 | "%s empress (%s)", dev->name, |
| 258 | saa7134_boards[dev->board].name); |
Hans Verkuil | 718bde1 | 2013-12-14 08:28:24 -0300 | [diff] [blame] | 259 | v4l2_ctrl_handler_init(hdl, 21); |
Hans Verkuil | da1b1ae | 2018-05-21 04:54:36 -0400 | [diff] [blame] | 260 | v4l2_ctrl_add_handler(hdl, &dev->ctrl_handler, empress_ctrl_filter, false); |
Hans Verkuil | 718bde1 | 2013-12-14 08:28:24 -0300 | [diff] [blame] | 261 | if (dev->empress_sd) |
Hans Verkuil | da1b1ae | 2018-05-21 04:54:36 -0400 | [diff] [blame] | 262 | v4l2_ctrl_add_handler(hdl, dev->empress_sd->ctrl_handler, NULL, true); |
Hans Verkuil | 718bde1 | 2013-12-14 08:28:24 -0300 | [diff] [blame] | 263 | if (hdl->error) { |
| 264 | video_device_release(dev->empress_dev); |
| 265 | return hdl->error; |
| 266 | } |
| 267 | dev->empress_dev->ctrl_handler = hdl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 269 | INIT_WORK(&dev->empress_workqueue, empress_signal_update); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | |
Hans Verkuil | 2ada815 | 2014-04-17 07:30:53 -0300 | [diff] [blame] | 271 | q = &dev->empress_vbq; |
| 272 | q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 273 | /* |
| 274 | * Do not add VB2_USERPTR: the saa7134 DMA engine cannot handle |
| 275 | * transfers that do not start at the beginning of a page. A USERPTR |
| 276 | * can start anywhere in a page, so USERPTR support is a no-go. |
| 277 | */ |
Hans Verkuil | 9f18302 | 2015-12-14 08:17:00 -0200 | [diff] [blame] | 278 | q->io_modes = VB2_MMAP | VB2_DMABUF | VB2_READ; |
Hans Verkuil | 2ada815 | 2014-04-17 07:30:53 -0300 | [diff] [blame] | 279 | q->drv_priv = &dev->ts_q; |
| 280 | q->ops = &saa7134_empress_qops; |
| 281 | q->gfp_flags = GFP_DMA32; |
| 282 | q->mem_ops = &vb2_dma_sg_memops; |
| 283 | q->buf_struct_size = sizeof(struct saa7134_buf); |
| 284 | q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; |
| 285 | q->lock = &dev->lock; |
Hans Verkuil | d8feef9 | 2016-09-18 11:24:50 -0300 | [diff] [blame] | 286 | q->dev = &dev->pci->dev; |
Hans Verkuil | 2ada815 | 2014-04-17 07:30:53 -0300 | [diff] [blame] | 287 | err = vb2_queue_init(q); |
Dinghao Liu | 15d0c52 | 2021-01-02 07:27:22 +0100 | [diff] [blame] | 288 | if (err) { |
| 289 | video_device_release(dev->empress_dev); |
| 290 | dev->empress_dev = NULL; |
Hans Verkuil | 2ada815 | 2014-04-17 07:30:53 -0300 | [diff] [blame] | 291 | return err; |
Dinghao Liu | 15d0c52 | 2021-01-02 07:27:22 +0100 | [diff] [blame] | 292 | } |
Hans Verkuil | 2ada815 | 2014-04-17 07:30:53 -0300 | [diff] [blame] | 293 | dev->empress_dev->queue = q; |
Hans Verkuil | 2161536 | 2019-06-17 05:36:16 -0400 | [diff] [blame] | 294 | dev->empress_dev->device_caps = V4L2_CAP_READWRITE | V4L2_CAP_STREAMING | |
| 295 | V4L2_CAP_VIDEO_CAPTURE; |
| 296 | if (dev->tuner_type != TUNER_ABSENT && dev->tuner_type != UNSET) |
| 297 | dev->empress_dev->device_caps |= V4L2_CAP_TUNER; |
Hans Verkuil | 2ada815 | 2014-04-17 07:30:53 -0300 | [diff] [blame] | 298 | |
Laurent Pinchart | 63b0d5a | 2009-12-10 11:44:04 -0200 | [diff] [blame] | 299 | video_set_drvdata(dev->empress_dev, dev); |
Hans Verkuil | 3e30a92 | 2020-02-03 12:41:17 +0100 | [diff] [blame] | 300 | err = video_register_device(dev->empress_dev,VFL_TYPE_VIDEO, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | empress_nr[dev->nr]); |
| 302 | if (err < 0) { |
Mauro Carvalho Chehab | 8358200 | 2015-04-30 06:46:34 -0300 | [diff] [blame] | 303 | pr_info("%s: can't register video device\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | dev->name); |
| 305 | video_device_release(dev->empress_dev); |
| 306 | dev->empress_dev = NULL; |
| 307 | return err; |
| 308 | } |
Mauro Carvalho Chehab | 8358200 | 2015-04-30 06:46:34 -0300 | [diff] [blame] | 309 | pr_info("%s: registered device %s [mpeg]\n", |
Laurent Pinchart | 38c7c03 | 2009-11-27 13:57:15 -0300 | [diff] [blame] | 310 | dev->name, video_device_node_name(dev->empress_dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 312 | empress_signal_update(&dev->empress_workqueue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | return 0; |
| 314 | } |
| 315 | |
| 316 | static int empress_fini(struct saa7134_dev *dev) |
| 317 | { |
Mauro Carvalho Chehab | 6139ebc | 2015-05-13 14:09:42 -0300 | [diff] [blame] | 318 | pr_debug("%s: %s\n", dev->name, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | |
| 320 | if (NULL == dev->empress_dev) |
| 321 | return 0; |
Tejun Heo | 4382973 | 2012-08-20 14:51:24 -0700 | [diff] [blame] | 322 | flush_work(&dev->empress_workqueue); |
Hans Verkuil | 11788d9 | 2020-07-13 13:30:44 +0200 | [diff] [blame] | 323 | vb2_video_unregister_device(dev->empress_dev); |
Hans Verkuil | 718bde1 | 2013-12-14 08:28:24 -0300 | [diff] [blame] | 324 | v4l2_ctrl_handler_free(&dev->empress_ctrl_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | dev->empress_dev = NULL; |
| 326 | return 0; |
| 327 | } |
| 328 | |
| 329 | static struct saa7134_mpeg_ops empress_ops = { |
| 330 | .type = SAA7134_MPEG_EMPRESS, |
| 331 | .init = empress_init, |
| 332 | .fini = empress_fini, |
| 333 | .signal_change = empress_signal_change, |
| 334 | }; |
| 335 | |
| 336 | static int __init empress_register(void) |
| 337 | { |
| 338 | return saa7134_ts_register(&empress_ops); |
| 339 | } |
| 340 | |
| 341 | static void __exit empress_unregister(void) |
| 342 | { |
| 343 | saa7134_ts_unregister(&empress_ops); |
| 344 | } |
| 345 | |
| 346 | module_init(empress_register); |
| 347 | module_exit(empress_unregister); |