aboutsummaryrefslogtreecommitdiff
path: root/drivers/staging
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-09-05 11:55:59 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2013-09-05 11:55:59 -0700
commit27c053aa8d18d1fa7b83041e36bad20bcdf55514 (patch)
treec59dce17a248dd8f4757eca3823032334c626dcd /drivers/staging
parenta09e9a7a4b907f2dfa9bdb2b98a1828ab4b340b2 (diff)
parentf66b2a1c7f2ae3fb0d5b67d07ab4f5055fd3cf16 (diff)
Merge branch 'v4l_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media
Pull media updates from Mauro Carvalho Chehab: "This series contains: - Exynos s5p-mfc driver got support for VP8 encoder - Some SoC drivers gained support for asynchronous registration (needed for DT) - The RC subsystem gained support for RC activity LED; - New drivers added: a video decoder(adv7842), a video encoder (adv7511), a new GSPCA driver (stk1135) and support for Renesas R-Car (vsp1) - the first SDR kernel driver: mirics msi3101. Due to some troubles with the driver, and because the API is still under discussion, it will be merged at staging for 3.12. Need to rework on it - usual new boards additions, fixes, cleanups and driver improvements" * 'v4l_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media: (242 commits) [media] cx88: Fix regression: CX88_AUDIO_WM8775 can't be 0 [media] exynos4-is: Fix entity unregistration on error path [media] exynos-gsc: Register v4l2 device [media] exynos4-is: Fix fimc-lite bayer formats [media] em28xx: fix assignment of the eeprom data [media] hdpvr: fix iteration over uninitialized lists in hdpvr_probe() [media] usbtv: Throw corrupted frames away [media] usbtv: Fix deinterlacing [media] v4l2: added missing mutex.h include to v4l2-ctrls.h [media] DocBook: upgrade media_api DocBook version to 4.2 [media] ml86v7667: fix compile warning: 'ret' set but not used [media] s5p-g2d: Fix registration failure [media] media: coda: Fix DT driver data pointer for i.MX27 [media] s5p-mfc: Fix input/output format reporting [media] v4l: vsp1: Fix mutex double lock at streamon time [media] v4l: vsp1: Add support for RT clock [media] v4l: vsp1: Initialize media device bus_info field [media] davinci: vpif_capture: fix error return code in vpif_probe() [media] davinci: vpif_display: fix error return code in vpif_probe() [media] MAINTAINERS: add entries for adv7511 and adv7842 ...
Diffstat (limited to 'drivers/staging')
-rw-r--r--drivers/staging/media/Kconfig2
-rw-r--r--drivers/staging/media/Makefile1
-rw-r--r--drivers/staging/media/lirc/lirc_igorplugusb.c56
-rw-r--r--drivers/staging/media/msi3101/Kconfig3
-rw-r--r--drivers/staging/media/msi3101/Makefile1
-rw-r--r--drivers/staging/media/msi3101/sdr-msi3101.c1931
6 files changed, 1952 insertions, 42 deletions
diff --git a/drivers/staging/media/Kconfig b/drivers/staging/media/Kconfig
index ae0abc350e3..46f1e619cbd 100644
--- a/drivers/staging/media/Kconfig
+++ b/drivers/staging/media/Kconfig
@@ -29,6 +29,8 @@ source "drivers/staging/media/dt3155v4l/Kconfig"
source "drivers/staging/media/go7007/Kconfig"
+source "drivers/staging/media/msi3101/Kconfig"
+
source "drivers/staging/media/solo6x10/Kconfig"
# Keep LIRC at the end, as it has sub-menus
diff --git a/drivers/staging/media/Makefile b/drivers/staging/media/Makefile
index 2b97cae9949..eb7f30b1ccd 100644
--- a/drivers/staging/media/Makefile
+++ b/drivers/staging/media/Makefile
@@ -4,4 +4,5 @@ obj-$(CONFIG_LIRC_STAGING) += lirc/
obj-$(CONFIG_SOLO6X10) += solo6x10/
obj-$(CONFIG_VIDEO_DT3155) += dt3155v4l/
obj-$(CONFIG_VIDEO_GO7007) += go7007/
+obj-$(CONFIG_USB_MSI3101) += msi3101/
obj-$(CONFIG_VIDEO_DM365_VPFE) += davinci_vpfe/
diff --git a/drivers/staging/media/lirc/lirc_igorplugusb.c b/drivers/staging/media/lirc/lirc_igorplugusb.c
index 2faa391006d..28c8b0bcf5b 100644
--- a/drivers/staging/media/lirc/lirc_igorplugusb.c
+++ b/drivers/staging/media/lirc/lirc_igorplugusb.c
@@ -240,10 +240,6 @@ static int unregister_from_lirc(struct igorplug *ir)
dprintk(DRIVER_NAME "[%d]: calling lirc_unregister_driver\n", devnum);
lirc_unregister_driver(d->minor);
- kfree(d);
- ir->d = NULL;
- kfree(ir);
-
return devnum;
}
@@ -377,20 +373,16 @@ static int igorplugusb_remote_poll(void *data, struct lirc_buffer *buf)
return -ENODATA;
}
-
-
static int igorplugusb_remote_probe(struct usb_interface *intf,
const struct usb_device_id *id)
{
- struct usb_device *dev = NULL;
+ struct usb_device *dev;
struct usb_host_interface *idesc = NULL;
struct usb_endpoint_descriptor *ep;
struct igorplug *ir = NULL;
struct lirc_driver *driver = NULL;
int devnum, pipe, maxp;
- int minor = 0;
char buf[63], name[128] = "";
- int mem_failure = 0;
int ret;
dprintk(DRIVER_NAME ": usb probe called.\n");
@@ -416,24 +408,18 @@ static int igorplugusb_remote_probe(struct usb_interface *intf,
dprintk(DRIVER_NAME "[%d]: bytes_in_key=%zu maxp=%d\n",
devnum, CODE_LENGTH, maxp);
- mem_failure = 0;
- ir = kzalloc(sizeof(struct igorplug), GFP_KERNEL);
- if (!ir) {
- mem_failure = 1;
- goto mem_failure_switch;
- }
- driver = kzalloc(sizeof(struct lirc_driver), GFP_KERNEL);
- if (!driver) {
- mem_failure = 2;
- goto mem_failure_switch;
- }
+ ir = devm_kzalloc(&intf->dev, sizeof(*ir), GFP_KERNEL);
+ if (!ir)
+ return -ENOMEM;
+
+ driver = devm_kzalloc(&intf->dev, sizeof(*driver), GFP_KERNEL);
+ if (!driver)
+ return -ENOMEM;
ir->buf_in = usb_alloc_coherent(dev, DEVICE_BUFLEN + DEVICE_HEADERLEN,
GFP_ATOMIC, &ir->dma_in);
- if (!ir->buf_in) {
- mem_failure = 3;
- goto mem_failure_switch;
- }
+ if (!ir->buf_in)
+ return -ENOMEM;
strcpy(driver->name, DRIVER_NAME " ");
driver->minor = -1;
@@ -449,27 +435,14 @@ static int igorplugusb_remote_probe(struct usb_interface *intf,
driver->dev = &intf->dev;
driver->owner = THIS_MODULE;
- minor = lirc_register_driver(driver);
- if (minor < 0)
- mem_failure = 9;
-
-mem_failure_switch:
-
- switch (mem_failure) {
- case 9:
+ ret = lirc_register_driver(driver);
+ if (ret < 0) {
usb_free_coherent(dev, DEVICE_BUFLEN + DEVICE_HEADERLEN,
ir->buf_in, ir->dma_in);
- case 3:
- kfree(driver);
- case 2:
- kfree(ir);
- case 1:
- printk(DRIVER_NAME "[%d]: out of memory (code=%d)\n",
- devnum, mem_failure);
- return -ENOMEM;
+ return ret;
}
- driver->minor = minor;
+ driver->minor = ret;
ir->d = driver;
ir->devnum = devnum;
ir->usbdev = dev;
@@ -502,7 +475,6 @@ mem_failure_switch:
return 0;
}
-
static void igorplugusb_remote_disconnect(struct usb_interface *intf)
{
struct usb_device *usbdev = interface_to_usbdev(intf);
diff --git a/drivers/staging/media/msi3101/Kconfig b/drivers/staging/media/msi3101/Kconfig
new file mode 100644
index 00000000000..b94a95a597d
--- /dev/null
+++ b/drivers/staging/media/msi3101/Kconfig
@@ -0,0 +1,3 @@
+config USB_MSI3101
+ tristate "Mirics MSi3101 SDR Dongle"
+ depends on USB && VIDEO_DEV && VIDEO_V4L2
diff --git a/drivers/staging/media/msi3101/Makefile b/drivers/staging/media/msi3101/Makefile
new file mode 100644
index 00000000000..3730654b0eb
--- /dev/null
+++ b/drivers/staging/media/msi3101/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_USB_MSI3101) += sdr-msi3101.o
diff --git a/drivers/staging/media/msi3101/sdr-msi3101.c b/drivers/staging/media/msi3101/sdr-msi3101.c
new file mode 100644
index 00000000000..24c7b70a6cb
--- /dev/null
+++ b/drivers/staging/media/msi3101/sdr-msi3101.c
@@ -0,0 +1,1931 @@
+/*
+ * Mirics MSi3101 SDR Dongle driver
+ *
+ * Copyright (C) 2013 Antti Palosaari <crope@iki.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * That driver is somehow based of pwc driver:
+ * (C) 1999-2004 Nemosoft Unv.
+ * (C) 2004-2006 Luc Saillard (luc@saillard.org)
+ * (C) 2011 Hans de Goede <hdegoede@redhat.com>
+ *
+ * Development tree of that driver will be on:
+ * http://git.linuxtv.org/anttip/media_tree.git/shortlog/refs/heads/mirics
+ *
+ * GNU Radio plugin "gr-kernel" for device usage will be on:
+ * http://git.linuxtv.org/anttip/gr-kernel.git
+ *
+ * TODO:
+ * Help is very highly welcome for these + all the others you could imagine:
+ * - split USB ADC interface and RF tuner to own drivers (msi2500 and msi001)
+ * - move controls to V4L2 API
+ * - use libv4l2 for stream format conversions
+ * - gr-kernel: switch to v4l2_mmap (current read eats a lot of cpu)
+ * - SDRSharp support
+ */
+
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/gcd.h>
+#include <asm/div64.h>
+#include <media/v4l2-device.h>
+#include <media/v4l2-ioctl.h>
+#include <media/v4l2-ctrls.h>
+#include <media/v4l2-event.h>
+#include <linux/usb.h>
+#include <media/videobuf2-vmalloc.h>
+
+struct msi3101_gain {
+ u8 tot:7;
+ u8 baseband:6;
+ bool lna:1;
+ bool mixer:1;
+};
+
+/* 60 – 120 MHz band, lna 24dB, mixer 19dB */
+static const struct msi3101_gain msi3101_gain_lut_120[] = {
+ { 0, 0, 0, 0},
+ { 1, 1, 0, 0},
+ { 2, 2, 0, 0},
+ { 3, 3, 0, 0},
+ { 4, 4, 0, 0},
+ { 5, 5, 0, 0},
+ { 6, 6, 0, 0},
+ { 7, 7, 0, 0},
+ { 8, 8, 0, 0},
+ { 9, 9, 0, 0},
+ { 10, 10, 0, 0},
+ { 11, 11, 0, 0},
+ { 12, 12, 0, 0},
+ { 13, 13, 0, 0},
+ { 14, 14, 0, 0},
+ { 15, 15, 0, 0},
+ { 16, 16, 0, 0},
+ { 17, 17, 0, 0},
+ { 18, 18, 0, 0},
+ { 19, 19, 0, 0},
+ { 20, 20, 0, 0},
+ { 21, 21, 0, 0},
+ { 22, 22, 0, 0},
+ { 23, 23, 0, 0},
+ { 24, 24, 0, 0},
+ { 25, 25, 0, 0},
+ { 26, 26, 0, 0},
+ { 27, 27, 0, 0},
+ { 28, 28, 0, 0},
+ { 29, 5, 1, 0},
+ { 30, 6, 1, 0},
+ { 31, 7, 1, 0},
+ { 32, 8, 1, 0},
+ { 33, 9, 1, 0},
+ { 34, 10, 1, 0},
+ { 35, 11, 1, 0},
+ { 36, 12, 1, 0},
+ { 37, 13, 1, 0},
+ { 38, 14, 1, 0},
+ { 39, 15, 1, 0},
+ { 40, 16, 1, 0},
+ { 41, 17, 1, 0},
+ { 42, 18, 1, 0},
+ { 43, 19, 1, 0},
+ { 44, 20, 1, 0},
+ { 45, 21, 1, 0},
+ { 46, 22, 1, 0},
+ { 47, 23, 1, 0},
+ { 48, 24, 1, 0},
+ { 49, 25, 1, 0},
+ { 50, 26, 1, 0},
+ { 51, 27, 1, 0},
+ { 52, 28, 1, 0},
+ { 53, 29, 1, 0},
+ { 54, 30, 1, 0},
+ { 55, 31, 1, 0},
+ { 56, 32, 1, 0},
+ { 57, 33, 1, 0},
+ { 58, 34, 1, 0},
+ { 59, 35, 1, 0},
+ { 60, 36, 1, 0},
+ { 61, 37, 1, 0},
+ { 62, 38, 1, 0},
+ { 63, 39, 1, 0},
+ { 64, 40, 1, 0},
+ { 65, 41, 1, 0},
+ { 66, 42, 1, 0},
+ { 67, 43, 1, 0},
+ { 68, 44, 1, 0},
+ { 69, 45, 1, 0},
+ { 70, 46, 1, 0},
+ { 71, 47, 1, 0},
+ { 72, 48, 1, 0},
+ { 73, 49, 1, 0},
+ { 74, 50, 1, 0},
+ { 75, 51, 1, 0},
+ { 76, 52, 1, 0},
+ { 77, 53, 1, 0},
+ { 78, 54, 1, 0},
+ { 79, 55, 1, 0},
+ { 80, 56, 1, 0},
+ { 81, 57, 1, 0},
+ { 82, 58, 1, 0},
+ { 83, 40, 1, 1},
+ { 84, 41, 1, 1},
+ { 85, 42, 1, 1},
+ { 86, 43, 1, 1},
+ { 87, 44, 1, 1},
+ { 88, 45, 1, 1},
+ { 89, 46, 1, 1},
+ { 90, 47, 1, 1},
+ { 91, 48, 1, 1},
+ { 92, 49, 1, 1},
+ { 93, 50, 1, 1},
+ { 94, 51, 1, 1},
+ { 95, 52, 1, 1},
+ { 96, 53, 1, 1},
+ { 97, 54, 1, 1},
+ { 98, 55, 1, 1},
+ { 99, 56, 1, 1},
+ {100, 57, 1, 1},
+ {101, 58, 1, 1},
+ {102, 59, 1, 1},
+};
+
+/* 120 – 245 MHz band, lna 24dB, mixer 19dB */
+static const struct msi3101_gain msi3101_gain_lut_245[] = {
+ { 0, 0, 0, 0},
+ { 1, 1, 0, 0},
+ { 2, 2, 0, 0},
+ { 3, 3, 0, 0},
+ { 4, 4, 0, 0},
+ { 5, 5, 0, 0},
+ { 6, 6, 0, 0},
+ { 7, 7, 0, 0},
+ { 8, 8, 0, 0},
+ { 9, 9, 0, 0},
+ { 10, 10, 0, 0},
+ { 11, 11, 0, 0},
+ { 12, 12, 0, 0},
+ { 13, 13, 0, 0},
+ { 14, 14, 0, 0},
+ { 15, 15, 0, 0},
+ { 16, 16, 0, 0},
+ { 17, 17, 0, 0},
+ { 18, 18, 0, 0},
+ { 19, 19, 0, 0},
+ { 20, 20, 0, 0},
+ { 21, 21, 0, 0},
+ { 22, 22, 0, 0},
+ { 23, 23, 0, 0},
+ { 24, 24, 0, 0},
+ { 25, 25, 0, 0},
+ { 26, 26, 0, 0},
+ { 27, 27, 0, 0},
+ { 28, 28, 0, 0},
+ { 29, 5, 1, 0},
+ { 30, 6, 1, 0},
+ { 31, 7, 1, 0},
+ { 32, 8, 1, 0},
+ { 33, 9, 1, 0},
+ { 34, 10, 1, 0},
+ { 35, 11, 1, 0},
+ { 36, 12, 1, 0},
+ { 37, 13, 1, 0},
+ { 38, 14, 1, 0},
+ { 39, 15, 1, 0},
+ { 40, 16, 1, 0},
+ { 41, 17, 1, 0},
+ { 42, 18, 1, 0},
+ { 43, 19, 1, 0},
+ { 44, 20, 1, 0},
+ { 45, 21, 1, 0},
+ { 46, 22, 1, 0},
+ { 47, 23, 1, 0},
+ { 48, 24, 1, 0},
+ { 49, 25, 1, 0},
+ { 50, 26, 1, 0},
+ { 51, 27, 1, 0},
+ { 52, 28, 1, 0},
+ { 53, 29, 1, 0},
+ { 54, 30, 1, 0},
+ { 55, 31, 1, 0},
+ { 56, 32, 1, 0},
+ { 57, 33, 1, 0},
+ { 58, 34, 1, 0},
+ { 59, 35, 1, 0},
+ { 60, 36, 1, 0},
+ { 61, 37, 1, 0},
+ { 62, 38, 1, 0},
+ { 63, 39, 1, 0},
+ { 64, 40, 1, 0},
+ { 65, 41, 1, 0},
+ { 66, 42, 1, 0},
+ { 67, 43, 1, 0},
+ { 68, 44, 1, 0},
+ { 69, 45, 1, 0},
+ { 70, 46, 1, 0},
+ { 71, 47, 1, 0},
+ { 72, 48, 1, 0},
+ { 73, 49, 1, 0},
+ { 74, 50, 1, 0},
+ { 75, 51, 1, 0},
+ { 76, 52, 1, 0},
+ { 77, 53, 1, 0},
+ { 78, 54, 1, 0},
+ { 79, 55, 1, 0},
+ { 80, 56, 1, 0},
+ { 81, 57, 1, 0},
+ { 82, 58, 1, 0},
+ { 83, 40, 1, 1},
+ { 84, 41, 1, 1},
+ { 85, 42, 1, 1},
+ { 86, 43, 1, 1},
+ { 87, 44, 1, 1},
+ { 88, 45, 1, 1},
+ { 89, 46, 1, 1},
+ { 90, 47, 1, 1},
+ { 91, 48, 1, 1},
+ { 92, 49, 1, 1},
+ { 93, 50, 1, 1},
+ { 94, 51, 1, 1},
+ { 95, 52, 1, 1},
+ { 96, 53, 1, 1},
+ { 97, 54, 1, 1},
+ { 98, 55, 1, 1},
+ { 99, 56, 1, 1},
+ {100, 57, 1, 1},
+ {101, 58, 1, 1},
+ {102, 59, 1, 1},
+};
+
+/* 420 – 1000 MHz band, lna 7dB, mixer 19dB */
+static const struct msi3101_gain msi3101_gain_lut_1000[] = {
+ { 0, 0, 0, 0},
+ { 1, 1, 0, 0},
+ { 2, 2, 0, 0},
+ { 3, 3, 0, 0},
+ { 4, 4, 0, 0},
+ { 5, 5, 0, 0},
+ { 6, 6, 0, 0},
+ { 7, 7, 0, 0},
+ { 8, 8, 0, 0},
+ { 9, 9, 0, 0},
+ { 10, 10, 0, 0},
+ { 11, 11, 0, 0},
+ { 12, 5, 1, 0},
+ { 13, 6, 1, 0},
+ { 14, 7, 1, 0},
+ { 15, 8, 1, 0},
+ { 16, 9, 1, 0},
+ { 17, 10, 1, 0},
+ { 18, 11, 1, 0},
+ { 19, 12, 1, 0},
+ { 20, 13, 1, 0},
+ { 21, 14, 1, 0},
+ { 22, 15, 1, 0},
+ { 23, 16, 1, 0},
+ { 24, 17, 1, 0},
+ { 25, 18, 1, 0},
+ { 26, 19, 1, 0},
+ { 27, 20, 1, 0},
+ { 28, 21, 1, 0},
+ { 29, 22, 1, 0},
+ { 30, 23, 1, 0},
+ { 31, 24, 1, 0},
+ { 32, 25, 1, 0},
+ { 33, 26, 1, 0},
+ { 34, 27, 1, 0},
+ { 35, 28, 1, 0},
+ { 36, 29, 1, 0},
+ { 37, 30, 1, 0},
+ { 38, 31, 1, 0},
+ { 39, 32, 1, 0},
+ { 40, 33, 1, 0},
+ { 41, 34, 1, 0},
+ { 42, 35, 1, 0},
+ { 43, 36, 1, 0},
+ { 44, 37, 1, 0},
+ { 45, 38, 1, 0},
+ { 46, 39, 1, 0},
+ { 47, 40, 1, 0},
+ { 48, 41, 1, 0},
+ { 49, 42, 1, 0},
+ { 50, 43, 1, 0},
+ { 51, 44, 1, 0},
+ { 52, 45, 1, 0},
+ { 53, 46, 1, 0},
+ { 54, 47, 1, 0},
+ { 55, 48, 1, 0},
+ { 56, 49, 1, 0},
+ { 57, 50, 1, 0},
+ { 58, 51, 1, 0},
+ { 59, 52, 1, 0},
+ { 60, 53, 1, 0},
+ { 61, 54, 1, 0},
+ { 62, 55, 1, 0},
+ { 63, 56, 1, 0},
+ { 64, 57, 1, 0},
+ { 65, 58, 1, 0},
+ { 66, 40, 1, 1},
+ { 67, 41, 1, 1},
+ { 68, 42, 1, 1},
+ { 69, 43, 1, 1},
+ { 70, 44, 1, 1},
+ { 71, 45, 1, 1},
+ { 72, 46, 1, 1},
+ { 73, 47, 1, 1},
+ { 74, 48, 1, 1},
+ { 75, 49, 1, 1},
+ { 76, 50, 1, 1},
+ { 77, 51, 1, 1},
+ { 78, 52, 1, 1},
+ { 79, 53, 1, 1},
+ { 80, 54, 1, 1},
+ { 81, 55, 1, 1},
+ { 82, 56, 1, 1},
+ { 83, 57, 1, 1},
+ { 84, 58, 1, 1},
+ { 85, 59, 1, 1},
+};
+
+/*
+ * iConfiguration 0
+ * bInterfaceNumber 0
+ * bAlternateSetting 1
+ * bNumEndpoints 1
+ * bEndpointAddress 0x81 EP 1 IN
+ * bmAttributes 1
+ * Transfer Type Isochronous
+ * wMaxPacketSize 0x1400 3x 1024 bytes
+ * bInterval 1
+ */
+#define MAX_ISO_BUFS (8)
+#define ISO_FRAMES_PER_DESC (8)
+#define ISO_MAX_FRAME_SIZE (3 * 1024)
+#define ISO_BUFFER_SIZE (ISO_FRAMES_PER_DESC * ISO_MAX_FRAME_SIZE)
+#define MAX_ISOC_ERRORS 20
+
+/* TODO: These should be moved to V4L2 API */
+#define MSI3101_CID_SAMPLING_MODE ((V4L2_CID_USER_BASE | 0xf000) + 0)
+#define MSI3101_CID_SAMPLING_RATE ((V4L2_CID_USER_BASE | 0xf000) + 1)
+#define MSI3101_CID_SAMPLING_RESOLUTION ((V4L2_CID_USER_BASE | 0xf000) + 2)
+#define MSI3101_CID_TUNER_RF ((V4L2_CID_USER_BASE | 0xf000) + 10)
+#define MSI3101_CID_TUNER_BW ((V4L2_CID_USER_BASE | 0xf000) + 11)
+#define MSI3101_CID_TUNER_IF ((V4L2_CID_USER_BASE | 0xf000) + 12)
+#define MSI3101_CID_TUNER_GAIN ((V4L2_CID_USER_BASE | 0xf000) + 13)
+
+/* intermediate buffers with raw data from the USB device */
+struct msi3101_frame_buf {
+ struct vb2_buffer vb; /* common v4l buffer stuff -- must be first */
+ struct list_head list;
+};
+
+struct msi3101_state {
+ struct video_device vdev;
+ struct v4l2_device v4l2_dev;
+
+ /* videobuf2 queue and queued buffers list */
+ struct vb2_queue vb_queue;
+ struct list_head queued_bufs;
+ spinlock_t queued_bufs_lock; /* Protects queued_bufs */
+
+ /* Note if taking both locks v4l2_lock must always be locked first! */
+ struct mutex v4l2_lock; /* Protects everything else */
+ struct mutex vb_queue_lock; /* Protects vb_queue and capt_file */
+
+ /* Pointer to our usb_device, will be NULL after unplug */
+ struct usb_device *udev; /* Both mutexes most be hold when setting! */
+
+ unsigned int isoc_errors; /* number of contiguous ISOC errors */
+ unsigned int vb_full; /* vb is full and packets dropped */
+
+ struct urb *urbs[MAX_ISO_BUFS];
+ int (*convert_stream) (struct msi3101_state *s, u32 *dst, u8 *src,
+ unsigned int src_len);
+
+ /* Controls */
+ struct v4l2_ctrl_handler ctrl_handler;
+ struct v4l2_ctrl *ctrl_sampling_rate;
+ struct v4l2_ctrl *ctrl_tuner_rf;
+ struct v4l2_ctrl *ctrl_tuner_bw;
+ struct v4l2_ctrl *ctrl_tuner_if;
+ struct v4l2_ctrl *ctrl_tuner_gain;
+
+ u32 next_sample; /* for track lost packets */
+ u32 sample; /* for sample rate calc */
+ unsigned long jiffies;
+ unsigned int sample_ctrl_bit[4];
+};
+
+/* Private functions */
+static struct msi3101_frame_buf *msi3101_get_next_fill_buf(
+ struct msi3101_state *s)
+{
+ unsigned long flags = 0;
+ struct msi3101_frame_buf *buf = NULL;
+
+ spin_lock_irqsave(&s->queued_bufs_lock, flags);
+ if (list_empty(&s->queued_bufs))
+ goto leave;
+
+ buf = list_entry(s->queued_bufs.next, struct msi3101_frame_buf, list);
+ list_del(&buf->list);
+leave:
+ spin_unlock_irqrestore(&s->queued_bufs_lock, flags);
+ return buf;
+}
+
+/*
+ * +===========================================================================
+ * | 00-1023 | USB packet type '384'
+ * +===========================================================================
+ * | 00- 03 | sequence number of first sample in that USB packet
+ * +---------------------------------------------------------------------------
+ * | 04- 15 | garbage
+ * +---------------------------------------------------------------------------
+ * | 16- 175 | samples
+ * +---------------------------------------------------------------------------
+ * | 176- 179 | control bits for previous samples
+ * +---------------------------------------------------------------------------
+ * | 180- 339 | samples
+ * +---------------------------------------------------------------------------
+ * | 340- 343 | control bits for previous samples
+ * +---------------------------------------------------------------------------
+ * | 344- 503 | samples
+ * +---------------------------------------------------------------------------
+ * | 504- 507 | control bits for previous samples
+ * +---------------------------------------------------------------------------
+ * | 508- 667 | samples
+ * +---------------------------------------------------------------------------
+ * | 668- 671 | control bits for previous samples
+ * +---------------------------------------------------------------------------
+ * | 672- 831 | samples
+ * +---------------------------------------------------------------------------
+ * | 832- 835 | control bits for previous samples
+ * +---------------------------------------------------------------------------
+ * | 836- 995 | samples
+ * +---------------------------------------------------------------------------
+ * | 996- 999 | control bits for previous samples
+ * +---------------------------------------------------------------------------
+ * | 1000-1023 | garbage
+ * +---------------------------------------------------------------------------
+ *
+ * Bytes 4 - 7 could have some meaning?
+ *
+ * Control bits for previous samples is 32-bit field, containing 16 x 2-bit
+ * numbers. This results one 2-bit number for 8 samples. It is likely used for
+ * for bit shifting sample by given bits, increasing actual sampling resolution.
+ * Number 2 (0b10) was never seen.
+ *
+ * 6 * 16 * 2 * 4 = 768 samples. 768 * 4 = 3072 bytes
+ */
+
+/*
+ * Integer to 32-bit IEEE floating point representation routine is taken
+ * from Radeon R600 driver (drivers/gpu/drm/radeon/r600_blit_kms.c).
+ *
+ * TODO: Currently we do conversion here in Kernel, but in future that will
+ * be moved to the libv4l2 library as video format conversions are.
+ */
+#define I2F_FRAC_BITS 23
+#define I2F_MASK ((1 << I2F_FRAC_BITS) - 1)
+
+/*
+ * Converts signed 8-bit integer into 32-bit IEEE floating point
+ * representation.
+ */
+static u32 msi3101_convert_sample_504(struct msi3101_state *s, u16 x)
+{
+ u32 msb, exponent, fraction, sign;
+
+ /* Zero is special */
+ if (!x)
+ return 0;
+
+ /* Negative / positive value */
+ if (x & (1 << 7)) {
+ x = -x;
+ x &= 0x7f; /* result is 7 bit ... + sign */
+ sign = 1 << 31;
+ } else {
+ sign = 0 << 31;
+ }
+
+ /* Get location of the most significant bit */
+ msb = __fls(x);
+
+ fraction = ror32(x, (msb - I2F_FRAC_BITS) & 0x1f) & I2F_MASK;
+ exponent = (127 + msb) << I2F_FRAC_BITS;
+
+ return (fraction + exponent) | sign;
+}
+
+static int msi3101_convert_stream_504(struct msi3101_state *s, u32 *dst,
+ u8 *src, unsigned int src_len)
+{
+ int i, j, i_max, dst_len = 0;
+ u16 sample[2];
+ u32 sample_num[3];
+
+ /* There could be 1-3 1024 bytes URB frames */
+ i_max = src_len / 1024;
+
+ for (i = 0; i < i_max; i++) {
+ sample_num[i] = src[3] << 24 | src[2] << 16 | src[1] << 8 | src[0] << 0;
+ if (i == 0 && s->next_sample != sample_num[0]) {
+ dev_dbg_ratelimited(&s->udev->dev,
+ "%d samples lost, %d %08x:%08x\n",
+ sample_num[0] - s->next_sample,
+ src_len, s->next_sample, sample_num[0]);
+ }
+
+ /*
+ * Dump all unknown 'garbage' data - maybe we will discover
+ * someday if there is something rational...
+ */
+ dev_dbg_ratelimited(&s->udev->dev, "%*ph\n", 12, &src[4]);
+
+ src += 16;
+ for (j = 0; j < 1008; j += 2) {
+ sample[0] = src[j + 0];
+ sample[1] = src[j + 1];
+
+ *dst++ = msi3101_convert_sample_504(s, sample[0]);
+ *dst++ = msi3101_convert_sample_504(s, sample[1]);
+ }
+ /* 504 x I+Q 32bit float samples */
+ dst_len += 504 * 2 * 4;
+ src += 1008;
+ }
+
+ /* calculate samping rate and output it in 10 seconds intervals */
+ if ((s->jiffies + msecs_to_jiffies(10000)) <= jiffies) {
+ unsigned long jiffies_now = jiffies;
+ unsigned long msecs = jiffies_to_msecs(jiffies_now) - jiffies_to_msecs(s->jiffies);
+ unsigned int samples = sample_num[i_max - 1] - s->sample;
+ s->jiffies = jiffies_now;
+ s->sample = sample_num[i_max - 1];
+ dev_dbg(&s->udev->dev,
+ "slen=%d samples=%u msecs=%lu sampling rate=%lu\n",
+ src_len, samples, msecs,
+ samples * 1000UL / msecs);
+ }
+
+ /* next sample (sample = sample + i * 504) */
+ s->next_sample = sample_num[i_max - 1] + 504;
+
+ return dst_len;
+}
+
+/*
+ * Converts signed ~10+2-bit integer into 32-bit IEEE floating point
+ * representation.
+ */
+static u32 msi3101_convert_sample_384(struct msi3101_state *s, u16 x, int shift)
+{
+ u32 msb, exponent, fraction, sign;
+ s->sample_ctrl_bit[shift]++;
+
+ /* Zero is special */
+ if (!x)
+ return 0;
+
+ if (shift == 3)
+ shift = 2;
+
+ /* Convert 10-bit two's complement to 12-bit */
+ if (x & (1 << 9)) {
+ x |= ~0U << 10; /* set all the rest bits to one */
+ x <<= shift;
+ x = -x;
+ x &= 0x7ff; /* result is 11 bit ... + sign */
+ sign = 1 << 31;
+ } else {
+ x <<= shift;
+ sign = 0 << 31;
+ }
+
+ /* Get location of the most significant bit */
+ msb = __fls(x);
+
+ fraction = ror32(x, (msb - I2F_FRAC_BITS) & 0x1f) & I2F_MASK;
+ exponent = (127 + msb) << I2F_FRAC_BITS;
+
+ return (fraction + exponent) | sign;
+}
+
+static int msi3101_convert_stream_384(struct msi3101_state *s, u32 *dst,
+ u8 *src, unsigned int src_len)
+{
+ int i, j, k, l, i_max, dst_len = 0;
+ u16 sample[4];
+ u32 bits;
+ u32 sample_num[3];
+
+ /* There could be 1-3 1024 bytes URB frames */
+ i_max = src_len / 1024;
+ for (i = 0; i < i_max; i++) {
+ sample_num[i] = src[3] << 24 | src[2] << 16 | src[1] << 8 | src[0] << 0;
+ if (i == 0 && s->next_sample != sample_num[0]) {
+ dev_dbg_ratelimited(&s->udev->dev,
+ "%d samples lost, %d %08x:%08x\n",
+ sample_num[0] - s->next_sample,
+ src_len, s->next_sample, sample_num[0]);
+ }
+
+ /*
+ * Dump all unknown 'garbage' data - maybe we will discover
+ * someday if there is something rational...
+ */
+ dev_dbg_ratelimited(&s->udev->dev,
+ "%*ph %*ph\n", 12, &src[4], 24, &src[1000]);
+
+ src += 16;
+ for (j = 0; j < 6; j++) {
+ bits = src[160 + 3] << 24 | src[160 + 2] << 16 | src[160 + 1] << 8 | src[160 + 0] << 0;
+ for (k = 0; k < 16; k++) {
+ for (l = 0; l < 10; l += 5) {
+ sample[0] = (src[l + 0] & 0xff) >> 0 | (src[l + 1] & 0x03) << 8;
+ sample[1] = (src[l + 1] & 0xfc) >> 2 | (src[l + 2] & 0x0f) << 6;
+ sample[2] = (src[l + 2] & 0xf0) >> 4 | (src[l + 3] & 0x3f) << 4;
+ sample[3] = (src[l + 3] & 0xc0) >> 6 | (src[l + 4] & 0xff) << 2;
+
+ *dst++ = msi3101_convert_sample_384(s, sample[0], (bits >> (2 * k)) & 0x3);
+ *dst++ = msi3101_convert_sample_384(s, sample[1], (bits >> (2 * k)) & 0x3);
+ *dst++ = msi3101_convert_sample_384(s, sample[2], (bits >> (2 * k)) & 0x3);
+ *dst++ = msi3101_convert_sample_384(s, sample[3], (bits >> (2 * k)) & 0x3);
+ }
+ src += 10;
+ }
+ dev_dbg_ratelimited(&s->udev->dev,
+ "sample control bits %08x\n", bits);
+ src += 4;
+ }
+ /* 384 x I+Q 32bit float samples */
+ dst_len += 384 * 2 * 4;
+ src += 24;
+ }
+
+ /* calculate samping rate and output it in 10 seconds intervals */
+ if ((s->jiffies + msecs_to_jiffies(10000)) <= jiffies) {
+ unsigned long jiffies_now = jiffies;
+ unsigned long msecs = jiffies_to_msecs(jiffies_now) - jiffies_to_msecs(s->jiffies);
+ unsigned int samples = sample_num[i_max - 1] - s->sample;
+ s->jiffies = jiffies_now;
+ s->sample = sample_num[i_max - 1];
+ dev_dbg(&s->udev->dev,
+ "slen=%d samples=%u msecs=%lu sampling rate=%lu bits=%d.%d.%d.%d\n",
+ src_len, samples, msecs,
+ samples * 1000UL / msecs,
+ s->sample_ctrl_bit[0], s->sample_ctrl_bit[1],
+ s->sample_ctrl_bit[2], s->sample_ctrl_bit[3]);
+ }
+
+ /* next sample (sample = sample + i * 384) */
+ s->next_sample = sample_num[i_max - 1] + 384;
+
+ return dst_len;
+}
+
+/*
+ * Converts signed 12-bit integer into 32-bit IEEE floating point
+ * representation.
+ */
+static u32 msi3101_convert_sample_336(struct msi3101_state *s, u16 x)
+{
+ u32 msb, exponent, fraction, sign;
+
+ /* Zero is special */
+ if (!x)
+ return 0;
+
+ /* Negative / positive value */
+ if (x & (1 << 11)) {
+ x = -x;
+ x &= 0x7ff; /* result is 11 bit ... + sign */
+ sign = 1 << 31;
+ } else {
+ sign = 0 << 31;
+ }
+
+ /* Get location of the most significant bit */
+ msb = __fls(x);
+
+ fraction = ror32(x, (msb - I2F_FRAC_BITS) & 0x1f) & I2F_MASK;
+ exponent = (127 + msb) << I2F_FRAC_BITS;
+
+ return (fraction + exponent) | sign;
+}
+
+static int msi3101_convert_stream_336(struct msi3101_state *s, u32 *dst,
+ u8 *src, unsigned int src_len)
+{
+ int i, j, i_max, dst_len = 0;
+ u16 sample[2];
+ u32 sample_num[3];
+
+ /* There could be 1-3 1024 bytes URB frames */
+ i_max = src_len / 1024;
+
+ for (i = 0; i < i_max; i++) {
+ sample_num[i] = src[3] << 24 | src[2] << 16 | src[1] << 8 | src[0] << 0;
+ if (i == 0 && s->next_sample != sample_num[0]) {
+ dev_dbg_ratelimited(&s->udev->dev,
+ "%d samples lost, %d %08x:%08x\n",
+ sample_num[0] - s->next_sample,
+ src_len, s->next_sample, sample_num[0]);
+ }
+
+ /*
+ * Dump all unknown 'garbage' data - maybe we will discover
+ * someday if there is something rational...
+ */
+ dev_dbg_ratelimited(&s->udev->dev, "%*ph\n", 12, &src[4]);
+
+ src += 16;
+ for (j = 0; j < 1008; j += 3) {
+ sample[0] = (src[j + 0] & 0xff) >> 0 | (src[j + 1] & 0x0f) << 8;
+ sample[1] = (src[j + 1] & 0xf0) >> 4 | (src[j + 2] & 0xff) << 4;
+
+ *dst++ = msi3101_convert_sample_336(s, sample[0]);
+ *dst++ = msi3101_convert_sample_336(s, sample[1]);
+ }
+ /* 336 x I+Q 32bit float samples */
+ dst_len += 336 * 2 * 4;
+ src += 1008;
+ }
+
+ /* calculate samping rate and output it in 10 seconds intervals */
+ if ((s->jiffies + msecs_to_jiffies(10000)) <= jiffies) {
+ unsigned long jiffies_now = jiffies;
+ unsigned long msecs = jiffies_to_msecs(jiffies_now) - jiffies_to_msecs(s->jiffies);
+ unsigned int samples = sample_num[i_max - 1] - s->sample;
+ s->jiffies = jiffies_now;
+ s->sample = sample_num[i_max - 1];
+ dev_dbg(&s->udev->dev,
+ "slen=%d samples=%u msecs=%lu sampling rate=%lu\n",
+ src_len, samples, msecs,
+ samples * 1000UL / msecs);
+ }
+
+ /* next sample (sample = sample + i * 336) */
+ s->next_sample = sample_num[i_max - 1] + 336;
+
+ return dst_len;
+}
+
+/*
+ * Converts signed 14-bit integer into 32-bit IEEE floating point
+ * representation.
+ */
+static u32 msi3101_convert_sample_252(struct msi3101_state *s, u16 x)
+{
+ u32 msb, exponent, fraction, sign;
+
+ /* Zero is special */
+ if (!x)
+ return 0;
+
+ /* Negative / positive value */
+ if (x & (1 << 13)) {
+ x = -x;
+ x &= 0x1fff; /* result is 13 bit ... + sign */
+ sign = 1 << 31;
+ } else {
+ sign = 0 << 31;
+ }
+
+ /* Get location of the most significant bit */
+ msb = __fls(x);
+
+ fraction = ror32(x, (msb - I2F_FRAC_BITS) & 0x1f) & I2F_MASK;
+ exponent = (127 + msb) << I2F_FRAC_BITS;
+
+ return (fraction + exponent) | sign;
+}
+
+static int msi3101_convert_stream_252(struct msi3101_state *s, u32 *dst,
+ u8 *src, unsigned int src_len)
+{
+ int i, j, i_max, dst_len = 0;
+ u16 sample[2];
+ u32 sample_num[3];
+
+ /* There could be 1-3 1024 bytes URB frames */
+ i_max = src_len / 1024;
+
+ for (i = 0; i < i_max; i++) {
+ sample_num[i] = src[3] << 24 | src[2] << 16 | src[1] << 8 | src[0] << 0;
+ if (i == 0 && s->next_sample != sample_num[0]) {
+ dev_dbg_ratelimited(&s->udev->dev,
+ "%d samples lost, %d %08x:%08x\n",
+ sample_num[0] - s->next_sample,
+ src_len, s->next_sample, sample_num[0]);
+ }
+
+ /*
+ * Dump all unknown 'garbage' data - maybe we will discover
+ * someday if there is something rational...
+ */
+ dev_dbg_ratelimited(&s->udev->dev, "%*ph\n", 12, &src[4]);
+
+ src += 16;
+ for (j = 0; j < 1008; j += 4) {
+ sample[0] = src[j + 0] >> 0 | src[j + 1] << 8;
+ sample[1] = src[j + 2] >> 0 | src[j + 3] << 8;
+
+ *dst++ = msi3101_convert_sample_252(s, sample[0]);
+ *dst++ = msi3101_convert_sample_252(s, sample[1]);
+ }
+ /* 252 x I+Q 32bit float samples */
+ dst_len += 252 * 2 * 4;
+ src += 1008;
+ }
+
+ /* calculate samping rate and output it in 10 seconds intervals */
+ if ((s->jiffies + msecs_to_jiffies(10000)) <= jiffies) {
+ unsigned long jiffies_now = jiffies;
+ unsigned long msecs = jiffies_to_msecs(jiffies_now) - jiffies_to_msecs(s->jiffies);
+ unsigned int samples = sample_num[i_max - 1] - s->sample;
+ s->jiffies = jiffies_now;
+ s->sample = sample_num[i_max - 1];
+ dev_dbg(&s->udev->dev,
+ "slen=%d samples=%u msecs=%lu sampling rate=%lu\n",
+ src_len, samples, msecs,
+ samples * 1000UL / msecs);
+ }
+
+ /* next sample (sample = sample + i * 252) */
+ s->next_sample = sample_num[i_max - 1] + 252;
+
+ return dst_len;
+}
+
+/*
+ * This gets called for the Isochronous pipe (stream). This is done in interrupt
+ * time, so it has to be fast, not crash, and not stall. Neat.
+ */
+static void msi3101_isoc_handler(struct urb *urb)