Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Mirics MSi3101 SDR Dongle driver |
| 3 | * |
| 4 | * Copyright (C) 2013 Antti Palosaari <crope@iki.fi> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along |
| 17 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
Antti Palosaari | 00e049b | 2013-08-07 15:06:29 -0300 | [diff] [blame] | 19 | * |
| 20 | * That driver is somehow based of pwc driver: |
| 21 | * (C) 1999-2004 Nemosoft Unv. |
| 22 | * (C) 2004-2006 Luc Saillard (luc@saillard.org) |
| 23 | * (C) 2011 Hans de Goede <hdegoede@redhat.com> |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 24 | */ |
| 25 | |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 26 | #include <linux/module.h> |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 27 | #include <linux/slab.h> |
Mauro Carvalho Chehab | 04e40bd | 2013-08-24 13:35:14 -0300 | [diff] [blame] | 28 | #include <asm/div64.h> |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 29 | #include <media/v4l2-device.h> |
| 30 | #include <media/v4l2-ioctl.h> |
| 31 | #include <media/v4l2-ctrls.h> |
| 32 | #include <media/v4l2-event.h> |
| 33 | #include <linux/usb.h> |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 34 | #include <media/videobuf2-vmalloc.h> |
Antti Palosaari | 2e68f84 | 2014-02-02 23:42:00 -0300 | [diff] [blame] | 35 | #include <linux/spi/spi.h> |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 36 | |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 37 | static bool msi2500_emulated_fmt; |
| 38 | module_param_named(emulated_formats, msi2500_emulated_fmt, bool, 0644); |
Antti Palosaari | 3912eb6 | 2014-07-13 22:27:21 -0300 | [diff] [blame] | 39 | MODULE_PARM_DESC(emulated_formats, "enable emulated formats (disappears in future)"); |
| 40 | |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 41 | /* |
| 42 | * iConfiguration 0 |
| 43 | * bInterfaceNumber 0 |
| 44 | * bAlternateSetting 1 |
| 45 | * bNumEndpoints 1 |
| 46 | * bEndpointAddress 0x81 EP 1 IN |
| 47 | * bmAttributes 1 |
| 48 | * Transfer Type Isochronous |
| 49 | * wMaxPacketSize 0x1400 3x 1024 bytes |
| 50 | * bInterval 1 |
| 51 | */ |
| 52 | #define MAX_ISO_BUFS (8) |
| 53 | #define ISO_FRAMES_PER_DESC (8) |
| 54 | #define ISO_MAX_FRAME_SIZE (3 * 1024) |
| 55 | #define ISO_BUFFER_SIZE (ISO_FRAMES_PER_DESC * ISO_MAX_FRAME_SIZE) |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 56 | #define MAX_ISOC_ERRORS 20 |
| 57 | |
Antti Palosaari | c08de62 | 2014-07-22 02:44:12 -0300 | [diff] [blame] | 58 | /* |
| 59 | * TODO: These formats should be moved to V4L2 API. Formats are currently |
| 60 | * disabled from formats[] table, not visible to userspace. |
| 61 | */ |
| 62 | /* signed 12-bit */ |
| 63 | #define MSI2500_PIX_FMT_SDR_S12 v4l2_fourcc('D', 'S', '1', '2') |
| 64 | /* Mirics MSi2500 format 384 */ |
| 65 | #define MSI2500_PIX_FMT_SDR_MSI2500_384 v4l2_fourcc('M', '3', '8', '4') |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 66 | |
Antti Palosaari | 2e68f84 | 2014-02-02 23:42:00 -0300 | [diff] [blame] | 67 | static const struct v4l2_frequency_band bands[] = { |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 68 | { |
| 69 | .tuner = 0, |
| 70 | .type = V4L2_TUNER_ADC, |
| 71 | .index = 0, |
| 72 | .capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS, |
| 73 | .rangelow = 1200000, |
| 74 | .rangehigh = 15000000, |
| 75 | }, |
| 76 | }; |
| 77 | |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 78 | /* stream formats */ |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 79 | struct msi2500_format { |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 80 | char *name; |
| 81 | u32 pixelformat; |
Antti Palosaari | a54e0fe | 2014-07-18 20:56:01 -0300 | [diff] [blame] | 82 | u32 buffersize; |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | /* format descriptions for capture and preview */ |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 86 | static struct msi2500_format formats[] = { |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 87 | { |
Antti Palosaari | 3912eb6 | 2014-07-13 22:27:21 -0300 | [diff] [blame] | 88 | .name = "Complex S8", |
| 89 | .pixelformat = V4L2_SDR_FMT_CS8, |
Antti Palosaari | a54e0fe | 2014-07-18 20:56:01 -0300 | [diff] [blame] | 90 | .buffersize = 3 * 1008, |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 91 | #if 0 |
| 92 | }, { |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 93 | .name = "10+2-bit signed", |
Antti Palosaari | c08de62 | 2014-07-22 02:44:12 -0300 | [diff] [blame] | 94 | .pixelformat = MSI2500_PIX_FMT_SDR_MSI2500_384, |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 95 | }, { |
| 96 | .name = "12-bit signed", |
Antti Palosaari | c08de62 | 2014-07-22 02:44:12 -0300 | [diff] [blame] | 97 | .pixelformat = MSI2500_PIX_FMT_SDR_S12, |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 98 | #endif |
Antti Palosaari | 3912eb6 | 2014-07-13 22:27:21 -0300 | [diff] [blame] | 99 | }, { |
| 100 | .name = "Complex S14LE", |
| 101 | .pixelformat = V4L2_SDR_FMT_CS14LE, |
Antti Palosaari | a54e0fe | 2014-07-18 20:56:01 -0300 | [diff] [blame] | 102 | .buffersize = 3 * 1008, |
Antti Palosaari | 3912eb6 | 2014-07-13 22:27:21 -0300 | [diff] [blame] | 103 | }, { |
| 104 | .name = "Complex U8 (emulated)", |
| 105 | .pixelformat = V4L2_SDR_FMT_CU8, |
Antti Palosaari | a54e0fe | 2014-07-18 20:56:01 -0300 | [diff] [blame] | 106 | .buffersize = 3 * 1008, |
Antti Palosaari | 3912eb6 | 2014-07-13 22:27:21 -0300 | [diff] [blame] | 107 | }, { |
| 108 | .name = "Complex U16LE (emulated)", |
| 109 | .pixelformat = V4L2_SDR_FMT_CU16LE, |
Antti Palosaari | a54e0fe | 2014-07-18 20:56:01 -0300 | [diff] [blame] | 110 | .buffersize = 3 * 1008, |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 111 | }, |
| 112 | }; |
| 113 | |
| 114 | static const unsigned int NUM_FORMATS = ARRAY_SIZE(formats); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 115 | |
| 116 | /* intermediate buffers with raw data from the USB device */ |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 117 | struct msi2500_frame_buf { |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 118 | struct vb2_buffer vb; /* common v4l buffer stuff -- must be first */ |
| 119 | struct list_head list; |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 120 | }; |
| 121 | |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 122 | struct msi2500_state { |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 123 | struct device *dev; |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 124 | struct video_device vdev; |
| 125 | struct v4l2_device v4l2_dev; |
Antti Palosaari | 2e68f84 | 2014-02-02 23:42:00 -0300 | [diff] [blame] | 126 | struct v4l2_subdev *v4l2_subdev; |
| 127 | struct spi_master *master; |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 128 | |
| 129 | /* videobuf2 queue and queued buffers list */ |
| 130 | struct vb2_queue vb_queue; |
| 131 | struct list_head queued_bufs; |
| 132 | spinlock_t queued_bufs_lock; /* Protects queued_bufs */ |
| 133 | |
| 134 | /* Note if taking both locks v4l2_lock must always be locked first! */ |
| 135 | struct mutex v4l2_lock; /* Protects everything else */ |
| 136 | struct mutex vb_queue_lock; /* Protects vb_queue and capt_file */ |
| 137 | |
| 138 | /* Pointer to our usb_device, will be NULL after unplug */ |
| 139 | struct usb_device *udev; /* Both mutexes most be hold when setting! */ |
| 140 | |
Antti Palosaari | 2e68f84 | 2014-02-02 23:42:00 -0300 | [diff] [blame] | 141 | unsigned int f_adc; |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 142 | u32 pixelformat; |
Antti Palosaari | a54e0fe | 2014-07-18 20:56:01 -0300 | [diff] [blame] | 143 | u32 buffersize; |
Antti Palosaari | 3912eb6 | 2014-07-13 22:27:21 -0300 | [diff] [blame] | 144 | unsigned int num_formats; |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 145 | |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 146 | unsigned int isoc_errors; /* number of contiguous ISOC errors */ |
| 147 | unsigned int vb_full; /* vb is full and packets dropped */ |
| 148 | |
| 149 | struct urb *urbs[MAX_ISO_BUFS]; |
| 150 | |
| 151 | /* Controls */ |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 152 | struct v4l2_ctrl_handler hdl; |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 153 | |
Antti Palosaari | 34599b9 | 2013-07-08 22:31:47 -0300 | [diff] [blame] | 154 | u32 next_sample; /* for track lost packets */ |
| 155 | u32 sample; /* for sample rate calc */ |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 156 | unsigned long jiffies_next; |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 157 | }; |
| 158 | |
| 159 | /* Private functions */ |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 160 | static struct msi2500_frame_buf *msi2500_get_next_fill_buf( |
| 161 | struct msi2500_state *s) |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 162 | { |
Antti Palosaari | b63ab6b | 2014-08-24 23:26:23 -0300 | [diff] [blame] | 163 | unsigned long flags; |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 164 | struct msi2500_frame_buf *buf = NULL; |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 165 | |
| 166 | spin_lock_irqsave(&s->queued_bufs_lock, flags); |
| 167 | if (list_empty(&s->queued_bufs)) |
| 168 | goto leave; |
| 169 | |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 170 | buf = list_entry(s->queued_bufs.next, struct msi2500_frame_buf, list); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 171 | list_del(&buf->list); |
| 172 | leave: |
| 173 | spin_unlock_irqrestore(&s->queued_bufs_lock, flags); |
| 174 | return buf; |
| 175 | } |
| 176 | |
| 177 | /* |
Antti Palosaari | 0200468 | 2013-07-10 21:59:58 -0300 | [diff] [blame] | 178 | * +=========================================================================== |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 179 | * | 00-1023 | USB packet type '504' |
| 180 | * +=========================================================================== |
| 181 | * | 00- 03 | sequence number of first sample in that USB packet |
| 182 | * +--------------------------------------------------------------------------- |
| 183 | * | 04- 15 | garbage |
| 184 | * +--------------------------------------------------------------------------- |
| 185 | * | 16-1023 | samples |
| 186 | * +--------------------------------------------------------------------------- |
| 187 | * signed 8-bit sample |
| 188 | * 504 * 2 = 1008 samples |
Antti Palosaari | 8591f70 | 2014-07-22 05:29:57 -0300 | [diff] [blame] | 189 | * |
| 190 | * |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 191 | * +=========================================================================== |
Antti Palosaari | 61198df | 2013-08-08 15:39:33 -0300 | [diff] [blame] | 192 | * | 00-1023 | USB packet type '384' |
Antti Palosaari | 0200468 | 2013-07-10 21:59:58 -0300 | [diff] [blame] | 193 | * +=========================================================================== |
| 194 | * | 00- 03 | sequence number of first sample in that USB packet |
| 195 | * +--------------------------------------------------------------------------- |
| 196 | * | 04- 15 | garbage |
| 197 | * +--------------------------------------------------------------------------- |
| 198 | * | 16- 175 | samples |
| 199 | * +--------------------------------------------------------------------------- |
| 200 | * | 176- 179 | control bits for previous samples |
| 201 | * +--------------------------------------------------------------------------- |
| 202 | * | 180- 339 | samples |
| 203 | * +--------------------------------------------------------------------------- |
| 204 | * | 340- 343 | control bits for previous samples |
| 205 | * +--------------------------------------------------------------------------- |
| 206 | * | 344- 503 | samples |
| 207 | * +--------------------------------------------------------------------------- |
| 208 | * | 504- 507 | control bits for previous samples |
| 209 | * +--------------------------------------------------------------------------- |
| 210 | * | 508- 667 | samples |
| 211 | * +--------------------------------------------------------------------------- |
| 212 | * | 668- 671 | control bits for previous samples |
| 213 | * +--------------------------------------------------------------------------- |
| 214 | * | 672- 831 | samples |
| 215 | * +--------------------------------------------------------------------------- |
| 216 | * | 832- 835 | control bits for previous samples |
| 217 | * +--------------------------------------------------------------------------- |
| 218 | * | 836- 995 | samples |
| 219 | * +--------------------------------------------------------------------------- |
| 220 | * | 996- 999 | control bits for previous samples |
| 221 | * +--------------------------------------------------------------------------- |
Antti Palosaari | 6450e50 | 2013-07-31 19:58:12 -0300 | [diff] [blame] | 222 | * | 1000-1023 | garbage |
Antti Palosaari | 0200468 | 2013-07-10 21:59:58 -0300 | [diff] [blame] | 223 | * +--------------------------------------------------------------------------- |
| 224 | * |
| 225 | * Bytes 4 - 7 could have some meaning? |
| 226 | * |
| 227 | * Control bits for previous samples is 32-bit field, containing 16 x 2-bit |
| 228 | * numbers. This results one 2-bit number for 8 samples. It is likely used for |
| 229 | * for bit shifting sample by given bits, increasing actual sampling resolution. |
| 230 | * Number 2 (0b10) was never seen. |
| 231 | * |
| 232 | * 6 * 16 * 2 * 4 = 768 samples. 768 * 4 = 3072 bytes |
Antti Palosaari | 8591f70 | 2014-07-22 05:29:57 -0300 | [diff] [blame] | 233 | * |
| 234 | * |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 235 | * +=========================================================================== |
| 236 | * | 00-1023 | USB packet type '336' |
| 237 | * +=========================================================================== |
| 238 | * | 00- 03 | sequence number of first sample in that USB packet |
| 239 | * +--------------------------------------------------------------------------- |
| 240 | * | 04- 15 | garbage |
| 241 | * +--------------------------------------------------------------------------- |
| 242 | * | 16-1023 | samples |
| 243 | * +--------------------------------------------------------------------------- |
| 244 | * signed 12-bit sample |
Antti Palosaari | 8591f70 | 2014-07-22 05:29:57 -0300 | [diff] [blame] | 245 | * |
| 246 | * |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 247 | * +=========================================================================== |
| 248 | * | 00-1023 | USB packet type '252' |
| 249 | * +=========================================================================== |
| 250 | * | 00- 03 | sequence number of first sample in that USB packet |
| 251 | * +--------------------------------------------------------------------------- |
| 252 | * | 04- 15 | garbage |
| 253 | * +--------------------------------------------------------------------------- |
| 254 | * | 16-1023 | samples |
| 255 | * +--------------------------------------------------------------------------- |
| 256 | * signed 14-bit sample |
Antti Palosaari | 554cbfb | 2013-08-05 20:43:36 -0300 | [diff] [blame] | 257 | */ |
Antti Palosaari | 8591f70 | 2014-07-22 05:29:57 -0300 | [diff] [blame] | 258 | |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 259 | static int msi2500_convert_stream(struct msi2500_state *s, u8 *dst, u8 *src, |
Antti Palosaari | 8591f70 | 2014-07-22 05:29:57 -0300 | [diff] [blame] | 260 | unsigned int src_len) |
Antti Palosaari | 554cbfb | 2013-08-05 20:43:36 -0300 | [diff] [blame] | 261 | { |
Antti Palosaari | 8591f70 | 2014-07-22 05:29:57 -0300 | [diff] [blame] | 262 | unsigned int i, j, transactions, dst_len = 0; |
| 263 | u32 sample[3]; |
Antti Palosaari | 554cbfb | 2013-08-05 20:43:36 -0300 | [diff] [blame] | 264 | |
Antti Palosaari | 8591f70 | 2014-07-22 05:29:57 -0300 | [diff] [blame] | 265 | /* There could be 1-3 1024 byte transactions per packet */ |
| 266 | transactions = src_len / 1024; |
Antti Palosaari | 554cbfb | 2013-08-05 20:43:36 -0300 | [diff] [blame] | 267 | |
Antti Palosaari | 8591f70 | 2014-07-22 05:29:57 -0300 | [diff] [blame] | 268 | for (i = 0; i < transactions; i++) { |
| 269 | sample[i] = src[3] << 24 | src[2] << 16 | src[1] << 8 | |
| 270 | src[0] << 0; |
| 271 | if (i == 0 && s->next_sample != sample[0]) { |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 272 | dev_dbg_ratelimited(s->dev, |
Antti Palosaari | 554cbfb | 2013-08-05 20:43:36 -0300 | [diff] [blame] | 273 | "%d samples lost, %d %08x:%08x\n", |
Antti Palosaari | 8591f70 | 2014-07-22 05:29:57 -0300 | [diff] [blame] | 274 | sample[0] - s->next_sample, |
| 275 | src_len, s->next_sample, sample[0]); |
Antti Palosaari | 554cbfb | 2013-08-05 20:43:36 -0300 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | /* |
| 279 | * Dump all unknown 'garbage' data - maybe we will discover |
| 280 | * someday if there is something rational... |
| 281 | */ |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 282 | dev_dbg_ratelimited(s->dev, "%*ph\n", 12, &src[4]); |
Antti Palosaari | 554cbfb | 2013-08-05 20:43:36 -0300 | [diff] [blame] | 283 | |
Antti Palosaari | 8591f70 | 2014-07-22 05:29:57 -0300 | [diff] [blame] | 284 | src += 16; /* skip header */ |
| 285 | |
| 286 | switch (s->pixelformat) { |
| 287 | case V4L2_SDR_FMT_CU8: /* 504 x IQ samples */ |
| 288 | { |
| 289 | s8 *s8src = (s8 *) src; |
| 290 | u8 *u8dst = (u8 *) dst; |
| 291 | |
| 292 | for (j = 0; j < 1008; j++) |
| 293 | *u8dst++ = *s8src++ + 128; |
| 294 | |
| 295 | src += 1008; |
| 296 | dst += 1008; |
| 297 | dst_len += 1008; |
| 298 | s->next_sample = sample[i] + 504; |
| 299 | break; |
| 300 | } |
| 301 | case V4L2_SDR_FMT_CU16LE: /* 252 x IQ samples */ |
| 302 | { |
| 303 | s16 *s16src = (s16 *) src; |
| 304 | u16 *u16dst = (u16 *) dst; |
| 305 | struct {signed int x:14; } se; /* sign extension */ |
| 306 | unsigned int utmp; |
| 307 | |
| 308 | for (j = 0; j < 1008; j += 2) { |
| 309 | /* sign extension from 14-bit to signed int */ |
| 310 | se.x = *s16src++; |
| 311 | /* from signed int to unsigned int */ |
| 312 | utmp = se.x + 8192; |
| 313 | /* from 14-bit to 16-bit */ |
| 314 | *u16dst++ = utmp << 2 | utmp >> 12; |
| 315 | } |
| 316 | |
| 317 | src += 1008; |
| 318 | dst += 1008; |
| 319 | dst_len += 1008; |
| 320 | s->next_sample = sample[i] + 252; |
| 321 | break; |
| 322 | } |
| 323 | case MSI2500_PIX_FMT_SDR_MSI2500_384: /* 384 x IQ samples */ |
| 324 | /* Dump unknown 'garbage' data */ |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 325 | dev_dbg_ratelimited(s->dev, "%*ph\n", 24, &src[1000]); |
Antti Palosaari | 8591f70 | 2014-07-22 05:29:57 -0300 | [diff] [blame] | 326 | memcpy(dst, src, 984); |
| 327 | src += 984 + 24; |
| 328 | dst += 984; |
| 329 | dst_len += 984; |
| 330 | s->next_sample = sample[i] + 384; |
| 331 | break; |
| 332 | case V4L2_SDR_FMT_CS8: /* 504 x IQ samples */ |
| 333 | memcpy(dst, src, 1008); |
| 334 | src += 1008; |
| 335 | dst += 1008; |
| 336 | dst_len += 1008; |
| 337 | s->next_sample = sample[i] + 504; |
| 338 | break; |
| 339 | case MSI2500_PIX_FMT_SDR_S12: /* 336 x IQ samples */ |
| 340 | memcpy(dst, src, 1008); |
| 341 | src += 1008; |
| 342 | dst += 1008; |
| 343 | dst_len += 1008; |
| 344 | s->next_sample = sample[i] + 336; |
| 345 | break; |
| 346 | case V4L2_SDR_FMT_CS14LE: /* 252 x IQ samples */ |
| 347 | memcpy(dst, src, 1008); |
| 348 | src += 1008; |
| 349 | dst += 1008; |
| 350 | dst_len += 1008; |
| 351 | s->next_sample = sample[i] + 252; |
| 352 | break; |
| 353 | default: |
| 354 | break; |
| 355 | } |
Antti Palosaari | 554cbfb | 2013-08-05 20:43:36 -0300 | [diff] [blame] | 356 | } |
| 357 | |
Antti Palosaari | 8591f70 | 2014-07-22 05:29:57 -0300 | [diff] [blame] | 358 | /* calculate sample rate and output it in 10 seconds intervals */ |
| 359 | if (unlikely(time_is_before_jiffies(s->jiffies_next))) { |
| 360 | #define MSECS 10000UL |
| 361 | unsigned int msecs = jiffies_to_msecs(jiffies - |
| 362 | s->jiffies_next + msecs_to_jiffies(MSECS)); |
| 363 | unsigned int samples = s->next_sample - s->sample; |
Antti Palosaari | c08de62 | 2014-07-22 02:44:12 -0300 | [diff] [blame] | 364 | |
Antti Palosaari | 8591f70 | 2014-07-22 05:29:57 -0300 | [diff] [blame] | 365 | s->jiffies_next = jiffies + msecs_to_jiffies(MSECS); |
| 366 | s->sample = s->next_sample; |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 367 | dev_dbg(s->dev, "size=%u samples=%u msecs=%u sample rate=%lu\n", |
Antti Palosaari | 554cbfb | 2013-08-05 20:43:36 -0300 | [diff] [blame] | 368 | src_len, samples, msecs, |
| 369 | samples * 1000UL / msecs); |
| 370 | } |
| 371 | |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 372 | return dst_len; |
| 373 | } |
| 374 | |
Antti Palosaari | 554cbfb | 2013-08-05 20:43:36 -0300 | [diff] [blame] | 375 | /* |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 376 | * This gets called for the Isochronous pipe (stream). This is done in interrupt |
| 377 | * time, so it has to be fast, not crash, and not stall. Neat. |
| 378 | */ |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 379 | static void msi2500_isoc_handler(struct urb *urb) |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 380 | { |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 381 | struct msi2500_state *s = (struct msi2500_state *)urb->context; |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 382 | int i, flen, fstatus; |
| 383 | unsigned char *iso_buf = NULL; |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 384 | struct msi2500_frame_buf *fbuf; |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 385 | |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 386 | if (unlikely(urb->status == -ENOENT || urb->status == -ECONNRESET || |
| 387 | urb->status == -ESHUTDOWN)) { |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 388 | dev_dbg(s->dev, "URB (%p) unlinked %ssynchronuously\n", |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 389 | urb, urb->status == -ENOENT ? "" : "a"); |
| 390 | return; |
| 391 | } |
| 392 | |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 393 | if (unlikely(urb->status != 0)) { |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 394 | dev_dbg(s->dev, "called with status %d\n", urb->status); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 395 | /* Give up after a number of contiguous errors */ |
| 396 | if (++s->isoc_errors > MAX_ISOC_ERRORS) |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 397 | dev_dbg(s->dev, "Too many ISOC errors, bailing out\n"); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 398 | goto handler_end; |
| 399 | } else { |
| 400 | /* Reset ISOC error counter. We did get here, after all. */ |
| 401 | s->isoc_errors = 0; |
| 402 | } |
| 403 | |
| 404 | /* Compact data */ |
| 405 | for (i = 0; i < urb->number_of_packets; i++) { |
Antti Palosaari | 554cbfb | 2013-08-05 20:43:36 -0300 | [diff] [blame] | 406 | void *ptr; |
| 407 | |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 408 | /* Check frame error */ |
| 409 | fstatus = urb->iso_frame_desc[i].status; |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 410 | if (unlikely(fstatus)) { |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 411 | dev_dbg_ratelimited(s->dev, |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 412 | "frame=%d/%d has error %d skipping\n", |
| 413 | i, urb->number_of_packets, fstatus); |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 414 | continue; |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | /* Check if that frame contains data */ |
| 418 | flen = urb->iso_frame_desc[i].actual_length; |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 419 | if (unlikely(flen == 0)) |
| 420 | continue; |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 421 | |
| 422 | iso_buf = urb->transfer_buffer + urb->iso_frame_desc[i].offset; |
| 423 | |
| 424 | /* Get free framebuffer */ |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 425 | fbuf = msi2500_get_next_fill_buf(s); |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 426 | if (unlikely(fbuf == NULL)) { |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 427 | s->vb_full++; |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 428 | dev_dbg_ratelimited(s->dev, |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 429 | "videobuf is full, %d packets dropped\n", |
| 430 | s->vb_full); |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 431 | continue; |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | /* fill framebuffer */ |
Antti Palosaari | 554cbfb | 2013-08-05 20:43:36 -0300 | [diff] [blame] | 435 | ptr = vb2_plane_vaddr(&fbuf->vb, 0); |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 436 | flen = msi2500_convert_stream(s, ptr, iso_buf, flen); |
Antti Palosaari | 554cbfb | 2013-08-05 20:43:36 -0300 | [diff] [blame] | 437 | vb2_set_plane_payload(&fbuf->vb, 0, flen); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 438 | vb2_buffer_done(&fbuf->vb, VB2_BUF_STATE_DONE); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | handler_end: |
| 442 | i = usb_submit_urb(urb, GFP_ATOMIC); |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 443 | if (unlikely(i != 0)) |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 444 | dev_dbg(s->dev, "Error (%d) re-submitting urb\n", i); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 445 | } |
| 446 | |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 447 | static void msi2500_iso_stop(struct msi2500_state *s) |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 448 | { |
| 449 | int i; |
Antti Palosaari | c08de62 | 2014-07-22 02:44:12 -0300 | [diff] [blame] | 450 | |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 451 | dev_dbg(s->dev, "\n"); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 452 | |
| 453 | /* Unlinking ISOC buffers one by one */ |
| 454 | for (i = 0; i < MAX_ISO_BUFS; i++) { |
| 455 | if (s->urbs[i]) { |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 456 | dev_dbg(s->dev, "Unlinking URB %p\n", s->urbs[i]); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 457 | usb_kill_urb(s->urbs[i]); |
| 458 | } |
| 459 | } |
| 460 | } |
| 461 | |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 462 | static void msi2500_iso_free(struct msi2500_state *s) |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 463 | { |
| 464 | int i; |
Antti Palosaari | c08de62 | 2014-07-22 02:44:12 -0300 | [diff] [blame] | 465 | |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 466 | dev_dbg(s->dev, "\n"); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 467 | |
| 468 | /* Freeing ISOC buffers one by one */ |
| 469 | for (i = 0; i < MAX_ISO_BUFS; i++) { |
| 470 | if (s->urbs[i]) { |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 471 | dev_dbg(s->dev, "Freeing URB\n"); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 472 | if (s->urbs[i]->transfer_buffer) { |
| 473 | usb_free_coherent(s->udev, |
| 474 | s->urbs[i]->transfer_buffer_length, |
| 475 | s->urbs[i]->transfer_buffer, |
| 476 | s->urbs[i]->transfer_dma); |
| 477 | } |
| 478 | usb_free_urb(s->urbs[i]); |
| 479 | s->urbs[i] = NULL; |
| 480 | } |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | /* Both v4l2_lock and vb_queue_lock should be locked when calling this */ |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 485 | static void msi2500_isoc_cleanup(struct msi2500_state *s) |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 486 | { |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 487 | dev_dbg(s->dev, "\n"); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 488 | |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 489 | msi2500_iso_stop(s); |
| 490 | msi2500_iso_free(s); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | /* Both v4l2_lock and vb_queue_lock should be locked when calling this */ |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 494 | static int msi2500_isoc_init(struct msi2500_state *s) |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 495 | { |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 496 | struct urb *urb; |
| 497 | int i, j, ret; |
Antti Palosaari | c08de62 | 2014-07-22 02:44:12 -0300 | [diff] [blame] | 498 | |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 499 | dev_dbg(s->dev, "\n"); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 500 | |
| 501 | s->isoc_errors = 0; |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 502 | |
| 503 | ret = usb_set_interface(s->udev, 0, 1); |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 504 | if (ret) |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 505 | return ret; |
| 506 | |
| 507 | /* Allocate and init Isochronuous urbs */ |
| 508 | for (i = 0; i < MAX_ISO_BUFS; i++) { |
| 509 | urb = usb_alloc_urb(ISO_FRAMES_PER_DESC, GFP_KERNEL); |
| 510 | if (urb == NULL) { |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 511 | dev_err(s->dev, "Failed to allocate urb %d\n", i); |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 512 | msi2500_isoc_cleanup(s); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 513 | return -ENOMEM; |
| 514 | } |
| 515 | s->urbs[i] = urb; |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 516 | dev_dbg(s->dev, "Allocated URB at 0x%p\n", urb); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 517 | |
| 518 | urb->interval = 1; |
Antti Palosaari | de3f2e2 | 2014-08-21 12:03:58 -0300 | [diff] [blame] | 519 | urb->dev = s->udev; |
| 520 | urb->pipe = usb_rcvisocpipe(s->udev, 0x81); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 521 | urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP; |
Antti Palosaari | de3f2e2 | 2014-08-21 12:03:58 -0300 | [diff] [blame] | 522 | urb->transfer_buffer = usb_alloc_coherent(s->udev, |
| 523 | ISO_BUFFER_SIZE, |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 524 | GFP_KERNEL, &urb->transfer_dma); |
| 525 | if (urb->transfer_buffer == NULL) { |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 526 | dev_err(s->dev, "Failed to allocate urb buffer %d\n", |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 527 | i); |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 528 | msi2500_isoc_cleanup(s); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 529 | return -ENOMEM; |
| 530 | } |
| 531 | urb->transfer_buffer_length = ISO_BUFFER_SIZE; |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 532 | urb->complete = msi2500_isoc_handler; |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 533 | urb->context = s; |
| 534 | urb->start_frame = 0; |
| 535 | urb->number_of_packets = ISO_FRAMES_PER_DESC; |
| 536 | for (j = 0; j < ISO_FRAMES_PER_DESC; j++) { |
| 537 | urb->iso_frame_desc[j].offset = j * ISO_MAX_FRAME_SIZE; |
| 538 | urb->iso_frame_desc[j].length = ISO_MAX_FRAME_SIZE; |
| 539 | } |
| 540 | } |
| 541 | |
| 542 | /* link */ |
| 543 | for (i = 0; i < MAX_ISO_BUFS; i++) { |
| 544 | ret = usb_submit_urb(s->urbs[i], GFP_KERNEL); |
| 545 | if (ret) { |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 546 | dev_err(s->dev, "usb_submit_urb %d failed with error %d\n", |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 547 | i, ret); |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 548 | msi2500_isoc_cleanup(s); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 549 | return ret; |
| 550 | } |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 551 | dev_dbg(s->dev, "URB 0x%p submitted.\n", s->urbs[i]); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | /* All is done... */ |
| 555 | return 0; |
| 556 | } |
| 557 | |
| 558 | /* Must be called with vb_queue_lock hold */ |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 559 | static void msi2500_cleanup_queued_bufs(struct msi2500_state *s) |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 560 | { |
Antti Palosaari | b63ab6b | 2014-08-24 23:26:23 -0300 | [diff] [blame] | 561 | unsigned long flags; |
Antti Palosaari | c08de62 | 2014-07-22 02:44:12 -0300 | [diff] [blame] | 562 | |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 563 | dev_dbg(s->dev, "\n"); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 564 | |
| 565 | spin_lock_irqsave(&s->queued_bufs_lock, flags); |
| 566 | while (!list_empty(&s->queued_bufs)) { |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 567 | struct msi2500_frame_buf *buf; |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 568 | |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 569 | buf = list_entry(s->queued_bufs.next, struct msi2500_frame_buf, |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 570 | list); |
| 571 | list_del(&buf->list); |
| 572 | vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR); |
| 573 | } |
| 574 | spin_unlock_irqrestore(&s->queued_bufs_lock, flags); |
| 575 | } |
| 576 | |
| 577 | /* The user yanked out the cable... */ |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 578 | static void msi2500_disconnect(struct usb_interface *intf) |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 579 | { |
| 580 | struct v4l2_device *v = usb_get_intfdata(intf); |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 581 | struct msi2500_state *s = |
| 582 | container_of(v, struct msi2500_state, v4l2_dev); |
Antti Palosaari | c08de62 | 2014-07-22 02:44:12 -0300 | [diff] [blame] | 583 | |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 584 | dev_dbg(s->dev, "\n"); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 585 | |
| 586 | mutex_lock(&s->vb_queue_lock); |
| 587 | mutex_lock(&s->v4l2_lock); |
| 588 | /* No need to keep the urbs around after disconnection */ |
| 589 | s->udev = NULL; |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 590 | v4l2_device_disconnect(&s->v4l2_dev); |
| 591 | video_unregister_device(&s->vdev); |
Antti Palosaari | 2e68f84 | 2014-02-02 23:42:00 -0300 | [diff] [blame] | 592 | spi_unregister_master(s->master); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 593 | mutex_unlock(&s->v4l2_lock); |
| 594 | mutex_unlock(&s->vb_queue_lock); |
| 595 | |
| 596 | v4l2_device_put(&s->v4l2_dev); |
| 597 | } |
| 598 | |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 599 | static int msi2500_querycap(struct file *file, void *fh, |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 600 | struct v4l2_capability *cap) |
| 601 | { |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 602 | struct msi2500_state *s = video_drvdata(file); |
Antti Palosaari | c08de62 | 2014-07-22 02:44:12 -0300 | [diff] [blame] | 603 | |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 604 | dev_dbg(s->dev, "\n"); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 605 | |
| 606 | strlcpy(cap->driver, KBUILD_MODNAME, sizeof(cap->driver)); |
| 607 | strlcpy(cap->card, s->vdev.name, sizeof(cap->card)); |
| 608 | usb_make_path(s->udev, cap->bus_info, sizeof(cap->bus_info)); |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 609 | cap->device_caps = V4L2_CAP_SDR_CAPTURE | V4L2_CAP_STREAMING | |
| 610 | V4L2_CAP_READWRITE | V4L2_CAP_TUNER; |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 611 | cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS; |
| 612 | return 0; |
| 613 | } |
| 614 | |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 615 | /* Videobuf2 operations */ |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 616 | static int msi2500_queue_setup(struct vb2_queue *vq, |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 617 | const struct v4l2_format *fmt, unsigned int *nbuffers, |
| 618 | unsigned int *nplanes, unsigned int sizes[], void *alloc_ctxs[]) |
| 619 | { |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 620 | struct msi2500_state *s = vb2_get_drv_priv(vq); |
Antti Palosaari | c08de62 | 2014-07-22 02:44:12 -0300 | [diff] [blame] | 621 | |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 622 | dev_dbg(s->dev, "nbuffers=%d\n", *nbuffers); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 623 | |
| 624 | /* Absolute min and max number of buffers available for mmap() */ |
Antti Palosaari | d287e4e | 2014-02-26 20:48:23 -0300 | [diff] [blame] | 625 | *nbuffers = clamp_t(unsigned int, *nbuffers, 8, 32); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 626 | *nplanes = 1; |
Antti Palosaari | a54e0fe | 2014-07-18 20:56:01 -0300 | [diff] [blame] | 627 | sizes[0] = PAGE_ALIGN(s->buffersize); |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 628 | dev_dbg(s->dev, "nbuffers=%d sizes[0]=%d\n", *nbuffers, sizes[0]); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 629 | return 0; |
| 630 | } |
| 631 | |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 632 | static void msi2500_buf_queue(struct vb2_buffer *vb) |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 633 | { |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 634 | struct msi2500_state *s = vb2_get_drv_priv(vb->vb2_queue); |
| 635 | struct msi2500_frame_buf *buf = |
| 636 | container_of(vb, struct msi2500_frame_buf, vb); |
Antti Palosaari | b63ab6b | 2014-08-24 23:26:23 -0300 | [diff] [blame] | 637 | unsigned long flags; |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 638 | |
| 639 | /* Check the device has not disconnected between prep and queuing */ |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 640 | if (unlikely(!s->udev)) { |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 641 | vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR); |
| 642 | return; |
| 643 | } |
| 644 | |
| 645 | spin_lock_irqsave(&s->queued_bufs_lock, flags); |
| 646 | list_add_tail(&buf->list, &s->queued_bufs); |
| 647 | spin_unlock_irqrestore(&s->queued_bufs_lock, flags); |
| 648 | } |
| 649 | |
| 650 | #define CMD_WREG 0x41 |
| 651 | #define CMD_START_STREAMING 0x43 |
| 652 | #define CMD_STOP_STREAMING 0x45 |
| 653 | #define CMD_READ_UNKNOW 0x48 |
| 654 | |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 655 | #define msi2500_dbg_usb_control_msg(_dev, _r, _t, _v, _i, _b, _l) { \ |
Antti Palosaari | c08de62 | 2014-07-22 02:44:12 -0300 | [diff] [blame] | 656 | char *_direction; \ |
| 657 | if (_t & USB_DIR_IN) \ |
| 658 | _direction = "<<<"; \ |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 659 | else \ |
Antti Palosaari | c08de62 | 2014-07-22 02:44:12 -0300 | [diff] [blame] | 660 | _direction = ">>>"; \ |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 661 | dev_dbg(_dev, "%02x %02x %02x %02x %02x %02x %02x %02x %s %*ph\n", \ |
| 662 | _t, _r, _v & 0xff, _v >> 8, _i & 0xff, _i >> 8, \ |
| 663 | _l & 0xff, _l >> 8, _direction, _l, _b); \ |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 664 | } |
| 665 | |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 666 | static int msi2500_ctrl_msg(struct msi2500_state *s, u8 cmd, u32 data) |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 667 | { |
| 668 | int ret; |
| 669 | u8 request = cmd; |
| 670 | u8 requesttype = USB_DIR_OUT | USB_TYPE_VENDOR; |
| 671 | u16 value = (data >> 0) & 0xffff; |
| 672 | u16 index = (data >> 16) & 0xffff; |
| 673 | |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 674 | msi2500_dbg_usb_control_msg(s->dev, |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 675 | request, requesttype, value, index, NULL, 0); |
Antti Palosaari | d0fadf4 | 2013-07-11 12:19:32 -0300 | [diff] [blame] | 676 | ret = usb_control_msg(s->udev, usb_sndctrlpipe(s->udev, 0), |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 677 | request, requesttype, value, index, NULL, 0, 2000); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 678 | if (ret) |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 679 | dev_err(s->dev, "failed %d, cmd %02x, data %04x\n", |
| 680 | ret, cmd, data); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 681 | |
| 682 | return ret; |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 683 | } |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 684 | |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 685 | #define F_REF 24000000 |
Antti Palosaari | b152085 | 2013-07-09 02:44:56 -0300 | [diff] [blame] | 686 | #define DIV_R_IN 2 |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 687 | static int msi2500_set_usb_adc(struct msi2500_state *s) |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 688 | { |
Antti Palosaari | 22ca680 | 2013-07-31 21:48:51 -0300 | [diff] [blame] | 689 | int ret, div_n, div_m, div_r_out, f_sr, f_vco, fract; |
Antti Palosaari | 554cbfb | 2013-08-05 20:43:36 -0300 | [diff] [blame] | 690 | u32 reg3, reg4, reg7; |
Antti Palosaari | 2e68f84 | 2014-02-02 23:42:00 -0300 | [diff] [blame] | 691 | struct v4l2_ctrl *bandwidth_auto; |
| 692 | struct v4l2_ctrl *bandwidth; |
Antti Palosaari | 554cbfb | 2013-08-05 20:43:36 -0300 | [diff] [blame] | 693 | |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 694 | f_sr = s->f_adc; |
Antti Palosaari | 554cbfb | 2013-08-05 20:43:36 -0300 | [diff] [blame] | 695 | |
Antti Palosaari | 2e68f84 | 2014-02-02 23:42:00 -0300 | [diff] [blame] | 696 | /* set tuner, subdev, filters according to sampling rate */ |
Antti Palosaari | c08de62 | 2014-07-22 02:44:12 -0300 | [diff] [blame] | 697 | bandwidth_auto = v4l2_ctrl_find(&s->hdl, |
| 698 | V4L2_CID_RF_TUNER_BANDWIDTH_AUTO); |
Antti Palosaari | 2e68f84 | 2014-02-02 23:42:00 -0300 | [diff] [blame] | 699 | if (v4l2_ctrl_g_ctrl(bandwidth_auto)) { |
Antti Palosaari | c08de62 | 2014-07-22 02:44:12 -0300 | [diff] [blame] | 700 | bandwidth = v4l2_ctrl_find(&s->hdl, |
| 701 | V4L2_CID_RF_TUNER_BANDWIDTH); |
Antti Palosaari | 2e68f84 | 2014-02-02 23:42:00 -0300 | [diff] [blame] | 702 | v4l2_ctrl_s_ctrl(bandwidth, s->f_adc); |
| 703 | } |
Antti Palosaari | 554cbfb | 2013-08-05 20:43:36 -0300 | [diff] [blame] | 704 | |
| 705 | /* select stream format */ |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 706 | switch (s->pixelformat) { |
| 707 | case V4L2_SDR_FMT_CU8: |
Antti Palosaari | 8591f70 | 2014-07-22 05:29:57 -0300 | [diff] [blame] | 708 | reg7 = 0x000c9407; /* 504 */ |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 709 | break; |
| 710 | case V4L2_SDR_FMT_CU16LE: |
Antti Palosaari | 8591f70 | 2014-07-22 05:29:57 -0300 | [diff] [blame] | 711 | reg7 = 0x00009407; /* 252 */ |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 712 | break; |
Antti Palosaari | 3912eb6 | 2014-07-13 22:27:21 -0300 | [diff] [blame] | 713 | case V4L2_SDR_FMT_CS8: |
Antti Palosaari | 8591f70 | 2014-07-22 05:29:57 -0300 | [diff] [blame] | 714 | reg7 = 0x000c9407; /* 504 */ |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 715 | break; |
Antti Palosaari | c08de62 | 2014-07-22 02:44:12 -0300 | [diff] [blame] | 716 | case MSI2500_PIX_FMT_SDR_MSI2500_384: |
Antti Palosaari | 8591f70 | 2014-07-22 05:29:57 -0300 | [diff] [blame] | 717 | reg7 = 0x0000a507; /* 384 */ |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 718 | break; |
Antti Palosaari | c08de62 | 2014-07-22 02:44:12 -0300 | [diff] [blame] | 719 | case MSI2500_PIX_FMT_SDR_S12: |
Antti Palosaari | 8591f70 | 2014-07-22 05:29:57 -0300 | [diff] [blame] | 720 | reg7 = 0x00008507; /* 336 */ |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 721 | break; |
Antti Palosaari | 3912eb6 | 2014-07-13 22:27:21 -0300 | [diff] [blame] | 722 | case V4L2_SDR_FMT_CS14LE: |
Antti Palosaari | 8591f70 | 2014-07-22 05:29:57 -0300 | [diff] [blame] | 723 | reg7 = 0x00009407; /* 252 */ |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 724 | break; |
| 725 | default: |
Antti Palosaari | 8591f70 | 2014-07-22 05:29:57 -0300 | [diff] [blame] | 726 | reg7 = 0x000c9407; /* 504 */ |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 727 | break; |
Antti Palosaari | 554cbfb | 2013-08-05 20:43:36 -0300 | [diff] [blame] | 728 | } |
| 729 | |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 730 | /* |
Antti Palosaari | b152085 | 2013-07-09 02:44:56 -0300 | [diff] [blame] | 731 | * Synthesizer config is just a educated guess... |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 732 | * |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 733 | * [7:0] 0x03, register address |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 734 | * [8] 1, power control |
| 735 | * [9] ?, power control |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 736 | * [12:10] output divider |
| 737 | * [13] 0 ? |
| 738 | * [14] 0 ? |
Antti Palosaari | 22ca680 | 2013-07-31 21:48:51 -0300 | [diff] [blame] | 739 | * [15] fractional MSB, bit 20 |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 740 | * [16:19] N |
| 741 | * [23:20] ? |
| 742 | * [24:31] 0x01 |
| 743 | * |
| 744 | * output divider |
| 745 | * val div |
| 746 | * 0 - (invalid) |
Antti Palosaari | b152085 | 2013-07-09 02:44:56 -0300 | [diff] [blame] | 747 | * 1 4 |
| 748 | * 2 6 |
| 749 | * 3 8 |
| 750 | * 4 10 |
| 751 | * 5 12 |
| 752 | * 6 14 |
| 753 | * 7 16 |
| 754 | * |
| 755 | * VCO 202000000 - 720000000++ |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 756 | */ |
Antti Palosaari | c5a431d | 2013-08-05 21:33:31 -0300 | [diff] [blame] | 757 | reg3 = 0x01000303; |
Antti Palosaari | 22ca680 | 2013-07-31 21:48:51 -0300 | [diff] [blame] | 758 | reg4 = 0x00000004; |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 759 | |
Antti Palosaari | c5a431d | 2013-08-05 21:33:31 -0300 | [diff] [blame] | 760 | /* XXX: Filters? AGC? */ |
| 761 | if (f_sr < 6000000) |
| 762 | reg3 |= 0x1 << 20; |
| 763 | else if (f_sr < 7000000) |
| 764 | reg3 |= 0x5 << 20; |
| 765 | else if (f_sr < 8500000) |
| 766 | reg3 |= 0x9 << 20; |
| 767 | else |
| 768 | reg3 |= 0xd << 20; |
| 769 | |
Antti Palosaari | b152085 | 2013-07-09 02:44:56 -0300 | [diff] [blame] | 770 | for (div_r_out = 4; div_r_out < 16; div_r_out += 2) { |
| 771 | f_vco = f_sr * div_r_out * 12; |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 772 | dev_dbg(s->dev, "div_r_out=%d f_vco=%d\n", div_r_out, f_vco); |
Antti Palosaari | b152085 | 2013-07-09 02:44:56 -0300 | [diff] [blame] | 773 | if (f_vco >= 202000000) |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 774 | break; |
| 775 | } |
| 776 | |
Antti Palosaari | b152085 | 2013-07-09 02:44:56 -0300 | [diff] [blame] | 777 | div_n = f_vco / (F_REF * DIV_R_IN); |
| 778 | div_m = f_vco % (F_REF * DIV_R_IN); |
Antti Palosaari | 22ca680 | 2013-07-31 21:48:51 -0300 | [diff] [blame] | 779 | fract = 0x200000ul * div_m / (F_REF * DIV_R_IN); |
Antti Palosaari | b152085 | 2013-07-09 02:44:56 -0300 | [diff] [blame] | 780 | |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 781 | reg3 |= div_n << 16; |
Antti Palosaari | b152085 | 2013-07-09 02:44:56 -0300 | [diff] [blame] | 782 | reg3 |= (div_r_out / 2 - 1) << 10; |
Antti Palosaari | 22ca680 | 2013-07-31 21:48:51 -0300 | [diff] [blame] | 783 | reg3 |= ((fract >> 20) & 0x000001) << 15; /* [20] */ |
| 784 | reg4 |= ((fract >> 0) & 0x0fffff) << 8; /* [19:0] */ |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 785 | |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 786 | dev_dbg(s->dev, "f_sr=%d f_vco=%d div_n=%d div_m=%d div_r_out=%d reg3=%08x reg4=%08x\n", |
| 787 | f_sr, f_vco, div_n, div_m, div_r_out, reg3, reg4); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 788 | |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 789 | ret = msi2500_ctrl_msg(s, CMD_WREG, 0x00608008); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 790 | if (ret) |
| 791 | goto err; |
| 792 | |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 793 | ret = msi2500_ctrl_msg(s, CMD_WREG, 0x00000c05); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 794 | if (ret) |
| 795 | goto err; |
| 796 | |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 797 | ret = msi2500_ctrl_msg(s, CMD_WREG, 0x00020000); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 798 | if (ret) |
| 799 | goto err; |
| 800 | |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 801 | ret = msi2500_ctrl_msg(s, CMD_WREG, 0x00480102); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 802 | if (ret) |
| 803 | goto err; |
| 804 | |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 805 | ret = msi2500_ctrl_msg(s, CMD_WREG, 0x00f38008); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 806 | if (ret) |
| 807 | goto err; |
| 808 | |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 809 | ret = msi2500_ctrl_msg(s, CMD_WREG, reg7); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 810 | if (ret) |
| 811 | goto err; |
| 812 | |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 813 | ret = msi2500_ctrl_msg(s, CMD_WREG, reg4); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 814 | if (ret) |
| 815 | goto err; |
| 816 | |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 817 | ret = msi2500_ctrl_msg(s, CMD_WREG, reg3); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 818 | if (ret) |
| 819 | goto err; |
| 820 | err: |
| 821 | return ret; |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 822 | } |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 823 | |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 824 | static int msi2500_start_streaming(struct vb2_queue *vq, unsigned int count) |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 825 | { |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 826 | struct msi2500_state *s = vb2_get_drv_priv(vq); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 827 | int ret; |
Antti Palosaari | c08de62 | 2014-07-22 02:44:12 -0300 | [diff] [blame] | 828 | |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 829 | dev_dbg(s->dev, "\n"); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 830 | |
| 831 | if (!s->udev) |
| 832 | return -ENODEV; |
| 833 | |
| 834 | if (mutex_lock_interruptible(&s->v4l2_lock)) |
| 835 | return -ERESTARTSYS; |
| 836 | |
Antti Palosaari | 2e68f84 | 2014-02-02 23:42:00 -0300 | [diff] [blame] | 837 | /* wake-up tuner */ |
| 838 | v4l2_subdev_call(s->v4l2_subdev, core, s_power, 1); |
| 839 | |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 840 | ret = msi2500_set_usb_adc(s); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 841 | |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 842 | ret = msi2500_isoc_init(s); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 843 | if (ret) |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 844 | msi2500_cleanup_queued_bufs(s); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 845 | |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 846 | ret = msi2500_ctrl_msg(s, CMD_START_STREAMING, 0); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 847 | |
| 848 | mutex_unlock(&s->v4l2_lock); |
| 849 | |
| 850 | return ret; |
| 851 | } |
| 852 | |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 853 | static void msi2500_stop_streaming(struct vb2_queue *vq) |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 854 | { |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 855 | struct msi2500_state *s = vb2_get_drv_priv(vq); |
Hans Verkuil | e37559b | 2014-04-17 02:47:21 -0300 | [diff] [blame] | 856 | |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 857 | dev_dbg(s->dev, "\n"); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 858 | |
Hans Verkuil | e37559b | 2014-04-17 02:47:21 -0300 | [diff] [blame] | 859 | mutex_lock(&s->v4l2_lock); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 860 | |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 861 | if (s->udev) |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 862 | msi2500_isoc_cleanup(s); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 863 | |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 864 | msi2500_cleanup_queued_bufs(s); |
Antti Palosaari | d0fadf4 | 2013-07-11 12:19:32 -0300 | [diff] [blame] | 865 | |
| 866 | /* according to tests, at least 700us delay is required */ |
| 867 | msleep(20); |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 868 | if (!msi2500_ctrl_msg(s, CMD_STOP_STREAMING, 0)) { |
Hans Verkuil | e37559b | 2014-04-17 02:47:21 -0300 | [diff] [blame] | 869 | /* sleep USB IF / ADC */ |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 870 | msi2500_ctrl_msg(s, CMD_WREG, 0x01000003); |
Hans Verkuil | e37559b | 2014-04-17 02:47:21 -0300 | [diff] [blame] | 871 | } |
Antti Palosaari | d0fadf4 | 2013-07-11 12:19:32 -0300 | [diff] [blame] | 872 | |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 873 | /* sleep tuner */ |
Hans Verkuil | e37559b | 2014-04-17 02:47:21 -0300 | [diff] [blame] | 874 | v4l2_subdev_call(s->v4l2_subdev, core, s_power, 0); |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 875 | |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 876 | mutex_unlock(&s->v4l2_lock); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 877 | } |
| 878 | |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 879 | static struct vb2_ops msi2500_vb2_ops = { |
| 880 | .queue_setup = msi2500_queue_setup, |
| 881 | .buf_queue = msi2500_buf_queue, |
| 882 | .start_streaming = msi2500_start_streaming, |
| 883 | .stop_streaming = msi2500_stop_streaming, |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 884 | .wait_prepare = vb2_ops_wait_prepare, |
| 885 | .wait_finish = vb2_ops_wait_finish, |
| 886 | }; |
| 887 | |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 888 | static int msi2500_enum_fmt_sdr_cap(struct file *file, void *priv, |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 889 | struct v4l2_fmtdesc *f) |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 890 | { |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 891 | struct msi2500_state *s = video_drvdata(file); |
Antti Palosaari | c08de62 | 2014-07-22 02:44:12 -0300 | [diff] [blame] | 892 | |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 893 | dev_dbg(s->dev, "index=%d\n", f->index); |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 894 | |
Antti Palosaari | 3912eb6 | 2014-07-13 22:27:21 -0300 | [diff] [blame] | 895 | if (f->index >= s->num_formats) |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 896 | return -EINVAL; |
| 897 | |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 898 | strlcpy(f->description, formats[f->index].name, sizeof(f->description)); |
| 899 | f->pixelformat = formats[f->index].pixelformat; |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 900 | |
| 901 | return 0; |
| 902 | } |
| 903 | |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 904 | static int msi2500_g_fmt_sdr_cap(struct file *file, void *priv, |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 905 | struct v4l2_format *f) |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 906 | { |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 907 | struct msi2500_state *s = video_drvdata(file); |
Antti Palosaari | c08de62 | 2014-07-22 02:44:12 -0300 | [diff] [blame] | 908 | |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 909 | dev_dbg(s->dev, "pixelformat fourcc %4.4s\n", |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 910 | (char *)&s->pixelformat); |
| 911 | |
| 912 | f->fmt.sdr.pixelformat = s->pixelformat; |
Antti Palosaari | a54e0fe | 2014-07-18 20:56:01 -0300 | [diff] [blame] | 913 | f->fmt.sdr.buffersize = s->buffersize; |
| 914 | memset(f->fmt.sdr.reserved, 0, sizeof(f->fmt.sdr.reserved)); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 915 | |
| 916 | return 0; |
| 917 | } |
| 918 | |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 919 | static int msi2500_s_fmt_sdr_cap(struct file *file, void *priv, |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 920 | struct v4l2_format *f) |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 921 | { |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 922 | struct msi2500_state *s = video_drvdata(file); |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 923 | struct vb2_queue *q = &s->vb_queue; |
| 924 | int i; |
Antti Palosaari | c08de62 | 2014-07-22 02:44:12 -0300 | [diff] [blame] | 925 | |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 926 | dev_dbg(s->dev, "pixelformat fourcc %4.4s\n", |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 927 | (char *)&f->fmt.sdr.pixelformat); |
| 928 | |
| 929 | if (vb2_is_busy(q)) |
| 930 | return -EBUSY; |
| 931 | |
Antti Palosaari | c350912 | 2014-03-10 16:30:44 -0300 | [diff] [blame] | 932 | memset(f->fmt.sdr.reserved, 0, sizeof(f->fmt.sdr.reserved)); |
Antti Palosaari | 3912eb6 | 2014-07-13 22:27:21 -0300 | [diff] [blame] | 933 | for (i = 0; i < s->num_formats; i++) { |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 934 | if (formats[i].pixelformat == f->fmt.sdr.pixelformat) { |
Antti Palosaari | a54e0fe | 2014-07-18 20:56:01 -0300 | [diff] [blame] | 935 | s->pixelformat = formats[i].pixelformat; |
| 936 | s->buffersize = formats[i].buffersize; |
| 937 | f->fmt.sdr.buffersize = formats[i].buffersize; |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 938 | return 0; |
| 939 | } |
| 940 | } |
| 941 | |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 942 | s->pixelformat = formats[0].pixelformat; |
Antti Palosaari | a54e0fe | 2014-07-18 20:56:01 -0300 | [diff] [blame] | 943 | s->buffersize = formats[0].buffersize; |
| 944 | f->fmt.sdr.pixelformat = formats[0].pixelformat; |
| 945 | f->fmt.sdr.buffersize = formats[0].buffersize; |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 946 | |
| 947 | return 0; |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 948 | } |
| 949 | |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 950 | static int msi2500_try_fmt_sdr_cap(struct file *file, void *priv, |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 951 | struct v4l2_format *f) |
| 952 | { |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 953 | struct msi2500_state *s = video_drvdata(file); |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 954 | int i; |
Antti Palosaari | c08de62 | 2014-07-22 02:44:12 -0300 | [diff] [blame] | 955 | |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 956 | dev_dbg(s->dev, "pixelformat fourcc %4.4s\n", |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 957 | (char *)&f->fmt.sdr.pixelformat); |
| 958 | |
Antti Palosaari | c350912 | 2014-03-10 16:30:44 -0300 | [diff] [blame] | 959 | memset(f->fmt.sdr.reserved, 0, sizeof(f->fmt.sdr.reserved)); |
Antti Palosaari | 3912eb6 | 2014-07-13 22:27:21 -0300 | [diff] [blame] | 960 | for (i = 0; i < s->num_formats; i++) { |
Antti Palosaari | a54e0fe | 2014-07-18 20:56:01 -0300 | [diff] [blame] | 961 | if (formats[i].pixelformat == f->fmt.sdr.pixelformat) { |
| 962 | f->fmt.sdr.buffersize = formats[i].buffersize; |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 963 | return 0; |
Antti Palosaari | a54e0fe | 2014-07-18 20:56:01 -0300 | [diff] [blame] | 964 | } |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | f->fmt.sdr.pixelformat = formats[0].pixelformat; |
Antti Palosaari | a54e0fe | 2014-07-18 20:56:01 -0300 | [diff] [blame] | 968 | f->fmt.sdr.buffersize = formats[0].buffersize; |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 969 | |
| 970 | return 0; |
| 971 | } |
| 972 | |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 973 | static int msi2500_s_tuner(struct file *file, void *priv, |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 974 | const struct v4l2_tuner *v) |
| 975 | { |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 976 | struct msi2500_state *s = video_drvdata(file); |
Antti Palosaari | 2e68f84 | 2014-02-02 23:42:00 -0300 | [diff] [blame] | 977 | int ret; |
Antti Palosaari | c08de62 | 2014-07-22 02:44:12 -0300 | [diff] [blame] | 978 | |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 979 | dev_dbg(s->dev, "index=%d\n", v->index); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 980 | |
Antti Palosaari | 2e68f84 | 2014-02-02 23:42:00 -0300 | [diff] [blame] | 981 | if (v->index == 0) |
| 982 | ret = 0; |
| 983 | else if (v->index == 1) |
| 984 | ret = v4l2_subdev_call(s->v4l2_subdev, tuner, s_tuner, v); |
| 985 | else |
| 986 | ret = -EINVAL; |
| 987 | |
| 988 | return ret; |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 989 | } |
| 990 | |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 991 | static int msi2500_g_tuner(struct file *file, void *priv, struct v4l2_tuner *v) |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 992 | { |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 993 | struct msi2500_state *s = video_drvdata(file); |
Antti Palosaari | 2e68f84 | 2014-02-02 23:42:00 -0300 | [diff] [blame] | 994 | int ret; |
Antti Palosaari | c08de62 | 2014-07-22 02:44:12 -0300 | [diff] [blame] | 995 | |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 996 | dev_dbg(s->dev, "index=%d\n", v->index); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 997 | |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 998 | if (v->index == 0) { |
Antti Palosaari | 2e68f84 | 2014-02-02 23:42:00 -0300 | [diff] [blame] | 999 | strlcpy(v->name, "Mirics MSi2500", sizeof(v->name)); |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 1000 | v->type = V4L2_TUNER_ADC; |
| 1001 | v->capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS; |
| 1002 | v->rangelow = 1200000; |
| 1003 | v->rangehigh = 15000000; |
Antti Palosaari | 2e68f84 | 2014-02-02 23:42:00 -0300 | [diff] [blame] | 1004 | ret = 0; |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 1005 | } else if (v->index == 1) { |
Antti Palosaari | 2e68f84 | 2014-02-02 23:42:00 -0300 | [diff] [blame] | 1006 | ret = v4l2_subdev_call(s->v4l2_subdev, tuner, g_tuner, v); |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 1007 | } else { |
Antti Palosaari | 2e68f84 | 2014-02-02 23:42:00 -0300 | [diff] [blame] | 1008 | ret = -EINVAL; |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 1009 | } |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 1010 | |
Antti Palosaari | 2e68f84 | 2014-02-02 23:42:00 -0300 | [diff] [blame] | 1011 | return ret; |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 1012 | } |
| 1013 | |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 1014 | static int msi2500_g_frequency(struct file *file, void *priv, |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 1015 | struct v4l2_frequency *f) |
| 1016 | { |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 1017 | struct msi2500_state *s = video_drvdata(file); |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 1018 | int ret = 0; |
Antti Palosaari | c08de62 | 2014-07-22 02:44:12 -0300 | [diff] [blame] | 1019 | |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 1020 | dev_dbg(s->dev, "tuner=%d type=%d\n", f->tuner, f->type); |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 1021 | |
Antti Palosaari | 2e68f84 | 2014-02-02 23:42:00 -0300 | [diff] [blame] | 1022 | if (f->tuner == 0) { |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 1023 | f->frequency = s->f_adc; |
Antti Palosaari | 2e68f84 | 2014-02-02 23:42:00 -0300 | [diff] [blame] | 1024 | ret = 0; |
| 1025 | } else if (f->tuner == 1) { |
Antti Palosaari | c350912 | 2014-03-10 16:30:44 -0300 | [diff] [blame] | 1026 | f->type = V4L2_TUNER_RF; |
Antti Palosaari | 2e68f84 | 2014-02-02 23:42:00 -0300 | [diff] [blame] | 1027 | ret = v4l2_subdev_call(s->v4l2_subdev, tuner, g_frequency, f); |
| 1028 | } else { |
| 1029 | ret = -EINVAL; |
| 1030 | } |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 1031 | |
| 1032 | return ret; |
| 1033 | } |
| 1034 | |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 1035 | static int msi2500_s_frequency(struct file *file, void *priv, |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 1036 | const struct v4l2_frequency *f) |
| 1037 | { |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 1038 | struct msi2500_state *s = video_drvdata(file); |
Antti Palosaari | 2e68f84 | 2014-02-02 23:42:00 -0300 | [diff] [blame] | 1039 | int ret; |
Antti Palosaari | c08de62 | 2014-07-22 02:44:12 -0300 | [diff] [blame] | 1040 | |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 1041 | dev_dbg(s->dev, "tuner=%d type=%d frequency=%u\n", |
| 1042 | f->tuner, f->type, f->frequency); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 1043 | |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 1044 | if (f->tuner == 0) { |
| 1045 | s->f_adc = clamp_t(unsigned int, f->frequency, |
Antti Palosaari | 2e68f84 | 2014-02-02 23:42:00 -0300 | [diff] [blame] | 1046 | bands[0].rangelow, |
| 1047 | bands[0].rangehigh); |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 1048 | dev_dbg(s->dev, "ADC frequency=%u Hz\n", s->f_adc); |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 1049 | ret = msi2500_set_usb_adc(s); |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 1050 | } else if (f->tuner == 1) { |
Antti Palosaari | 2e68f84 | 2014-02-02 23:42:00 -0300 | [diff] [blame] | 1051 | ret = v4l2_subdev_call(s->v4l2_subdev, tuner, s_frequency, f); |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 1052 | } else { |
Antti Palosaari | 2e68f84 | 2014-02-02 23:42:00 -0300 | [diff] [blame] | 1053 | ret = -EINVAL; |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 1054 | } |
| 1055 | |
| 1056 | return ret; |
| 1057 | } |
| 1058 | |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 1059 | static int msi2500_enum_freq_bands(struct file *file, void *priv, |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 1060 | struct v4l2_frequency_band *band) |
| 1061 | { |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 1062 | struct msi2500_state *s = video_drvdata(file); |
Antti Palosaari | 2e68f84 | 2014-02-02 23:42:00 -0300 | [diff] [blame] | 1063 | int ret; |
Antti Palosaari | c08de62 | 2014-07-22 02:44:12 -0300 | [diff] [blame] | 1064 | |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 1065 | dev_dbg(s->dev, "tuner=%d type=%d index=%d\n", |
| 1066 | band->tuner, band->type, band->index); |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 1067 | |
| 1068 | if (band->tuner == 0) { |
Antti Palosaari | 2e68f84 | 2014-02-02 23:42:00 -0300 | [diff] [blame] | 1069 | if (band->index >= ARRAY_SIZE(bands)) { |
| 1070 | ret = -EINVAL; |
| 1071 | } else { |
| 1072 | *band = bands[band->index]; |
| 1073 | ret = 0; |
| 1074 | } |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 1075 | } else if (band->tuner == 1) { |
Antti Palosaari | 2e68f84 | 2014-02-02 23:42:00 -0300 | [diff] [blame] | 1076 | ret = v4l2_subdev_call(s->v4l2_subdev, tuner, |
| 1077 | enum_freq_bands, band); |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 1078 | } else { |
Antti Palosaari | 2e68f84 | 2014-02-02 23:42:00 -0300 | [diff] [blame] | 1079 | ret = -EINVAL; |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 1080 | } |
| 1081 | |
Antti Palosaari | 2e68f84 | 2014-02-02 23:42:00 -0300 | [diff] [blame] | 1082 | return ret; |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 1083 | } |
| 1084 | |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 1085 | static const struct v4l2_ioctl_ops msi2500_ioctl_ops = { |
| 1086 | .vidioc_querycap = msi2500_querycap, |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 1087 | |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 1088 | .vidioc_enum_fmt_sdr_cap = msi2500_enum_fmt_sdr_cap, |
| 1089 | .vidioc_g_fmt_sdr_cap = msi2500_g_fmt_sdr_cap, |
| 1090 | .vidioc_s_fmt_sdr_cap = msi2500_s_fmt_sdr_cap, |
| 1091 | .vidioc_try_fmt_sdr_cap = msi2500_try_fmt_sdr_cap, |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 1092 | |
| 1093 | .vidioc_reqbufs = vb2_ioctl_reqbufs, |
| 1094 | .vidioc_create_bufs = vb2_ioctl_create_bufs, |
| 1095 | .vidioc_prepare_buf = vb2_ioctl_prepare_buf, |
| 1096 | .vidioc_querybuf = vb2_ioctl_querybuf, |
| 1097 | .vidioc_qbuf = vb2_ioctl_qbuf, |
| 1098 | .vidioc_dqbuf = vb2_ioctl_dqbuf, |
| 1099 | |
| 1100 | .vidioc_streamon = vb2_ioctl_streamon, |
| 1101 | .vidioc_streamoff = vb2_ioctl_streamoff, |
| 1102 | |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 1103 | .vidioc_g_tuner = msi2500_g_tuner, |
| 1104 | .vidioc_s_tuner = msi2500_s_tuner, |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 1105 | |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 1106 | .vidioc_g_frequency = msi2500_g_frequency, |
| 1107 | .vidioc_s_frequency = msi2500_s_frequency, |
| 1108 | .vidioc_enum_freq_bands = msi2500_enum_freq_bands, |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 1109 | |
| 1110 | .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, |
| 1111 | .vidioc_unsubscribe_event = v4l2_event_unsubscribe, |
| 1112 | .vidioc_log_status = v4l2_ctrl_log_status, |
| 1113 | }; |
| 1114 | |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 1115 | static const struct v4l2_file_operations msi2500_fops = { |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 1116 | .owner = THIS_MODULE, |
| 1117 | .open = v4l2_fh_open, |
| 1118 | .release = vb2_fop_release, |
| 1119 | .read = vb2_fop_read, |
| 1120 | .poll = vb2_fop_poll, |
| 1121 | .mmap = vb2_fop_mmap, |
| 1122 | .unlocked_ioctl = video_ioctl2, |
| 1123 | }; |
| 1124 | |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 1125 | static struct video_device msi2500_template = { |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 1126 | .name = "Mirics MSi3101 SDR Dongle", |
| 1127 | .release = video_device_release_empty, |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 1128 | .fops = &msi2500_fops, |
| 1129 | .ioctl_ops = &msi2500_ioctl_ops, |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 1130 | }; |
| 1131 | |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 1132 | static void msi2500_video_release(struct v4l2_device *v) |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 1133 | { |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 1134 | struct msi2500_state *s = |
| 1135 | container_of(v, struct msi2500_state, v4l2_dev); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 1136 | |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 1137 | v4l2_ctrl_handler_free(&s->hdl); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 1138 | v4l2_device_unregister(&s->v4l2_dev); |
| 1139 | kfree(s); |
| 1140 | } |
| 1141 | |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 1142 | static int msi2500_transfer_one_message(struct spi_master *master, |
Antti Palosaari | 2e68f84 | 2014-02-02 23:42:00 -0300 | [diff] [blame] | 1143 | struct spi_message *m) |
| 1144 | { |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 1145 | struct msi2500_state *s = spi_master_get_devdata(master); |
Antti Palosaari | 2e68f84 | 2014-02-02 23:42:00 -0300 | [diff] [blame] | 1146 | struct spi_transfer *t; |
| 1147 | int ret = 0; |
| 1148 | u32 data; |
| 1149 | |
| 1150 | list_for_each_entry(t, &m->transfers, transfer_list) { |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 1151 | dev_dbg(s->dev, "msg=%*ph\n", t->len, t->tx_buf); |
Antti Palosaari | 2e68f84 | 2014-02-02 23:42:00 -0300 | [diff] [blame] | 1152 | data = 0x09; /* reg 9 is SPI adapter */ |
| 1153 | data |= ((u8 *)t->tx_buf)[0] << 8; |
| 1154 | data |= ((u8 *)t->tx_buf)[1] << 16; |
| 1155 | data |= ((u8 *)t->tx_buf)[2] << 24; |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 1156 | ret = msi2500_ctrl_msg(s, CMD_WREG, data); |
Antti Palosaari | 2e68f84 | 2014-02-02 23:42:00 -0300 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | m->status = ret; |
| 1160 | spi_finalize_current_message(master); |
| 1161 | return ret; |
| 1162 | } |
| 1163 | |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 1164 | static int msi2500_probe(struct usb_interface *intf, |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 1165 | const struct usb_device_id *id) |
| 1166 | { |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 1167 | struct msi2500_state *s; |
Antti Palosaari | 2e68f84 | 2014-02-02 23:42:00 -0300 | [diff] [blame] | 1168 | struct v4l2_subdev *sd; |
| 1169 | struct spi_master *master; |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 1170 | int ret; |
Antti Palosaari | 2e68f84 | 2014-02-02 23:42:00 -0300 | [diff] [blame] | 1171 | static struct spi_board_info board_info = { |
| 1172 | .modalias = "msi001", |
| 1173 | .bus_num = 0, |
| 1174 | .chip_select = 0, |
| 1175 | .max_speed_hz = 12000000, |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 1176 | }; |
| 1177 | |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 1178 | s = kzalloc(sizeof(struct msi2500_state), GFP_KERNEL); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 1179 | if (s == NULL) { |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 1180 | dev_err(&intf->dev, "Could not allocate memory for state\n"); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 1181 | return -ENOMEM; |
| 1182 | } |
| 1183 | |
| 1184 | mutex_init(&s->v4l2_lock); |
| 1185 | mutex_init(&s->vb_queue_lock); |
| 1186 | spin_lock_init(&s->queued_bufs_lock); |
| 1187 | INIT_LIST_HEAD(&s->queued_bufs); |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 1188 | s->dev = &intf->dev; |
| 1189 | s->udev = interface_to_usbdev(intf); |
Antti Palosaari | 2e68f84 | 2014-02-02 23:42:00 -0300 | [diff] [blame] | 1190 | s->f_adc = bands[0].rangelow; |
Antti Palosaari | 3912eb6 | 2014-07-13 22:27:21 -0300 | [diff] [blame] | 1191 | s->pixelformat = formats[0].pixelformat; |
Antti Palosaari | a54e0fe | 2014-07-18 20:56:01 -0300 | [diff] [blame] | 1192 | s->buffersize = formats[0].buffersize; |
Antti Palosaari | 3912eb6 | 2014-07-13 22:27:21 -0300 | [diff] [blame] | 1193 | s->num_formats = NUM_FORMATS; |
Mauro Carvalho Chehab | ad7b8c0 | 2014-09-03 16:19:29 -0300 | [diff] [blame] | 1194 | if (!msi2500_emulated_fmt) |
Antti Palosaari | 3912eb6 | 2014-07-13 22:27:21 -0300 | [diff] [blame] | 1195 | s->num_formats -= 2; |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 1196 | |
| 1197 | /* Init videobuf2 queue structure */ |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 1198 | s->vb_queue.type = V4L2_BUF_TYPE_SDR_CAPTURE; |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 1199 | s->vb_queue.io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ; |
| 1200 | s->vb_queue.drv_priv = s; |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 1201 | s->vb_queue.buf_struct_size = sizeof(struct msi2500_frame_buf); |
| 1202 | s->vb_queue.ops = &msi2500_vb2_ops; |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 1203 | s->vb_queue.mem_ops = &vb2_vmalloc_memops; |
Sakari Ailus | ade4868 | 2014-02-25 19:12:19 -0300 | [diff] [blame] | 1204 | s->vb_queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 1205 | ret = vb2_queue_init(&s->vb_queue); |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 1206 | if (ret) { |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 1207 | dev_err(s->dev, "Could not initialize vb2 queue\n"); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 1208 | goto err_free_mem; |
| 1209 | } |
| 1210 | |
| 1211 | /* Init video_device structure */ |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 1212 | s->vdev = msi2500_template; |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 1213 | s->vdev.queue = &s->vb_queue; |
| 1214 | s->vdev.queue->lock = &s->vb_queue_lock; |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 1215 | video_set_drvdata(&s->vdev, s); |
| 1216 | |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 1217 | /* Register the v4l2_device structure */ |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 1218 | s->v4l2_dev.release = msi2500_video_release; |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 1219 | ret = v4l2_device_register(&intf->dev, &s->v4l2_dev); |
| 1220 | if (ret) { |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 1221 | dev_err(s->dev, "Failed to register v4l2-device (%d)\n", ret); |
Antti Palosaari | 2e68f84 | 2014-02-02 23:42:00 -0300 | [diff] [blame] | 1222 | goto err_free_mem; |
| 1223 | } |
| 1224 | |
| 1225 | /* SPI master adapter */ |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 1226 | master = spi_alloc_master(s->dev, 0); |
Antti Palosaari | 2e68f84 | 2014-02-02 23:42:00 -0300 | [diff] [blame] | 1227 | if (master == NULL) { |
| 1228 | ret = -ENOMEM; |
| 1229 | goto err_unregister_v4l2_dev; |
| 1230 | } |
| 1231 | |
| 1232 | s->master = master; |
| 1233 | master->bus_num = 0; |
| 1234 | master->num_chipselect = 1; |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 1235 | master->transfer_one_message = msi2500_transfer_one_message; |
Antti Palosaari | 2e68f84 | 2014-02-02 23:42:00 -0300 | [diff] [blame] | 1236 | spi_master_set_devdata(master, s); |
| 1237 | ret = spi_register_master(master); |
| 1238 | if (ret) { |
| 1239 | spi_master_put(master); |
| 1240 | goto err_unregister_v4l2_dev; |
| 1241 | } |
| 1242 | |
| 1243 | /* load v4l2 subdevice */ |
| 1244 | sd = v4l2_spi_new_subdev(&s->v4l2_dev, master, &board_info); |
| 1245 | s->v4l2_subdev = sd; |
| 1246 | if (sd == NULL) { |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 1247 | dev_err(s->dev, "cannot get v4l2 subdevice\n"); |
Antti Palosaari | 2e68f84 | 2014-02-02 23:42:00 -0300 | [diff] [blame] | 1248 | ret = -ENODEV; |
| 1249 | goto err_unregister_master; |
| 1250 | } |
| 1251 | |
| 1252 | /* Register controls */ |
| 1253 | v4l2_ctrl_handler_init(&s->hdl, 0); |
| 1254 | if (s->hdl.error) { |
| 1255 | ret = s->hdl.error; |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 1256 | dev_err(s->dev, "Could not initialize controls\n"); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 1257 | goto err_free_controls; |
| 1258 | } |
| 1259 | |
Antti Palosaari | 2e68f84 | 2014-02-02 23:42:00 -0300 | [diff] [blame] | 1260 | /* currently all controls are from subdev */ |
| 1261 | v4l2_ctrl_add_handler(&s->hdl, sd->ctrl_handler, NULL); |
| 1262 | |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 1263 | s->v4l2_dev.ctrl_handler = &s->hdl; |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 1264 | s->vdev.v4l2_dev = &s->v4l2_dev; |
| 1265 | s->vdev.lock = &s->v4l2_lock; |
| 1266 | |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 1267 | ret = video_register_device(&s->vdev, VFL_TYPE_SDR, -1); |
| 1268 | if (ret) { |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 1269 | dev_err(s->dev, "Failed to register as video device (%d)\n", |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 1270 | ret); |
| 1271 | goto err_unregister_v4l2_dev; |
| 1272 | } |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 1273 | dev_info(s->dev, "Registered as %s\n", |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 1274 | video_device_node_name(&s->vdev)); |
Antti Palosaari | 100b7931 | 2014-08-24 22:54:06 -0300 | [diff] [blame] | 1275 | dev_notice(s->dev, "SDR API is still slightly experimental and functionality changes may follow\n"); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 1276 | |
| 1277 | return 0; |
| 1278 | |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 1279 | err_free_controls: |
Antti Palosaari | 3d0c8fa | 2013-11-17 03:04:51 -0300 | [diff] [blame] | 1280 | v4l2_ctrl_handler_free(&s->hdl); |
Antti Palosaari | 2e68f84 | 2014-02-02 23:42:00 -0300 | [diff] [blame] | 1281 | err_unregister_master: |
| 1282 | spi_unregister_master(s->master); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 1283 | err_unregister_v4l2_dev: |
| 1284 | v4l2_device_unregister(&s->v4l2_dev); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 1285 | err_free_mem: |
| 1286 | kfree(s); |
| 1287 | return ret; |
| 1288 | } |
| 1289 | |
| 1290 | /* USB device ID list */ |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 1291 | static struct usb_device_id msi2500_id_table[] = { |
Antti Palosaari | 00e049b | 2013-08-07 15:06:29 -0300 | [diff] [blame] | 1292 | { USB_DEVICE(0x1df7, 0x2500) }, /* Mirics MSi3101 SDR Dongle */ |
Antti Palosaari | 42fc5b4 | 2013-07-17 15:05:27 -0300 | [diff] [blame] | 1293 | { USB_DEVICE(0x2040, 0xd300) }, /* Hauppauge WinTV 133559 LF */ |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 1294 | { } |
| 1295 | }; |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 1296 | MODULE_DEVICE_TABLE(usb, msi2500_id_table); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 1297 | |
| 1298 | /* USB subsystem interface */ |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 1299 | static struct usb_driver msi2500_driver = { |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 1300 | .name = KBUILD_MODNAME, |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 1301 | .probe = msi2500_probe, |
| 1302 | .disconnect = msi2500_disconnect, |
| 1303 | .id_table = msi2500_id_table, |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 1304 | }; |
| 1305 | |
Antti Palosaari | 06ce32c | 2014-07-22 05:43:06 -0300 | [diff] [blame] | 1306 | module_usb_driver(msi2500_driver); |
Antti Palosaari | 977e444 | 2013-07-05 00:24:08 -0300 | [diff] [blame] | 1307 | |
| 1308 | MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); |
| 1309 | MODULE_DESCRIPTION("Mirics MSi3101 SDR Dongle"); |
| 1310 | MODULE_LICENSE("GPL"); |