History log of /linux-master/drivers/media/usb/em28xx/em28xx-video.c
Revision Date Author Comments
# 287fe160 13-Dec-2023 Laurent Pinchart <laurent.pinchart@ideasonboard.com>

media: v4l2-subdev: Turn .[gs]_frame_interval into pad operations

The subdev .[gs]_frame_interval are video operations, but they operate
on pads (and even on streams). Not only is this confusing, it causes
practical issues for drivers as the operations don't receive a subdev
state pointer, requiring manual state handling.

To improve the situation, turn the operations into pad operations, and
extend them to receive a state pointer like other pad operations.

While at it, rename the operations to .[gs]et_frame_interval at the same
time to match the naming scheme of other pad operations. This isn't
strictly necessary, but given that all drivers using those operations
need to be modified, handling the rename separately would generate more
churn for very little gain (if at all).

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de> # for imx-media
Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com> # for tegra-video
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>


# f068a6ce 10-Aug-2022 Hans Verkuil <hverkuil-cisco@xs4all.nl>

media: avoid use of 'videobuf'

The term 'videobuf' typically refers to the old videobuf version 1
framework. Avoid using this word in drivers that are converted to
vb2.

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>


# c1b21785 11-Jun-2022 Christophe JAILLET <christophe.jaillet@wanadoo.fr>

media: em28xx: Remove useless license text when SPDX-License-Identifier is already used

An SPDX-License-Identifier is already in place. There is no need to
duplicate part of the corresponding license.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>


# 7fbbbc78 02-Feb-2020 Hans Verkuil <hverkuil-cisco@xs4all.nl>

media: media/usb: rename VFL_TYPE_GRABBER to _VIDEO

'GRABBER' is a weird name, all other types map to the /dev
device names. Rename to 'VIDEO' to be consistent with the
other types.

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>


# 6b338c72 14-Aug-2019 Geert Uytterhoeven <geert+renesas@glider.be>

media: Fix various misspellings of disconnected

Fix typos.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>


# b61789f5 26-Jun-2019 Hans Verkuil <hverkuil@xs4all.nl>

media: drivers/media: don't set pix->priv = 0

The priv field of struct v4l2_pix_format shouldn't be set by drivers,
it's set by the v4l2 core instead to V4L2_PIX_FMT_PRIV_MAGIC.

Drop this from the few media drivers that still do this.

Note that the gspca patch is slightly more involved since some of the
sub-gspca drivers use the priv field internally.

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
[hverkuil-cisco@xs4all.nl: fix clash in gspca between priv arg and priv variable]
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>


# 009cb7d5 11-Jun-2019 Hans Verkuil <hverkuil-cisco@xs4all.nl>

media: media/usb: don't set description in ENUM_FMT

The V4L2 core sets the description for the driver in order to ensure
consistent naming.

So drop the strscpy of the description in drivers. Also remove any
description strings in driver-internal structures since those are
no longer needed.

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>


# 8c3854d0 04-Jun-2019 Hans Verkuil <hverkuil-cisco@xs4all.nl>

media: media/usb: set device_caps in struct video_device

Instead of filling in the struct v4l2_capability device_caps
field, fill in the struct video_device device_caps field.

That way the V4L2 core knows what the capabilities of the
video device are.

But this only really works if all drivers use this, so convert
all usb drivers in this patch.

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>


# afeaade9 13-Sep-2018 Mauro Carvalho Chehab <mchehab+samsung@kernel.org>

media: em28xx: make v4l2-compliance happier by starting sequence on zero

The v4l2-compliance tool complains if a video doesn't start
with a zero sequence number.

While this shouldn't cause any real problem for apps, let's
make it happier, in order to better check the v4l2-compliance
differences before and after patchsets.

This is actually an old issue. It is there since at least its
videobuf2 conversion, e. g. changeset 3829fadc461 ("[media]
em28xx: convert to videobuf2"), if VB1 wouldn't suffer from
the same issue.

Cc: stable@vger.kernel.org
Fixes: d3829fadc461 ("[media] em28xx: convert to videobuf2")
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>


# f823ce2a 13-Sep-2018 Mauro Carvalho Chehab <mchehab+samsung@kernel.org>

media: em28xx: use a default format if TRY_FMT fails

Follow the V4L2 spec, as warned by v4l2-compliance:

warn: v4l2-test-formats.cpp(732): TRY_FMT cannot handle an invalid pixelformat.
warn: v4l2-test-formats.cpp(733): This may or may not be a problem. For more information see:

warn: v4l2-test-formats.cpp(734): http://www.mail-archive.com/linux-media@vger.kernel.org/msg56550.html

Cc: stable@vger.kernel.org
Fixes: bddcf63313c6 ("V4L/DVB (9927): em28xx: use a more standard way to specify video formats")
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>


# 258c4304 14-Sep-2018 Mauro Carvalho Chehab <mchehab+samsung@kernel.org>

media: em28xx: fix handler for vidioc_s_input()

The a->index is not the name of the internal amux entry,
but, instead a value from zero to the maximum number
of audio inputs.

As the actual available inputs depend on each board, build
it dynamically.

This is broken for a really long time. On a quick check,
since at least commit 195a4ef627e1 ("V4L/DVB (6585): Convert
em28xx to video_ioctl2") this was not implemented right.

Fixes: 195a4ef627e1 ("V4L/DVB (6585): Convert em28xx to video_ioctl2")

Cc: stable@vger.kernel.org
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>


# cc1e6315 10-Sep-2018 Mauro Carvalho Chehab <mchehab+samsung@kernel.org>

media: replace strcpy() by strscpy()

The strcpy() function is being deprecated upstream. Replace
it by the safer strscpy().

Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
Reviewed-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>


# c0decac1 10-Sep-2018 Mauro Carvalho Chehab <mchehab+samsung@kernel.org>

media: use strscpy() instead of strlcpy()

The implementation of strscpy() is more robust and safer.

That's now the recommended way to copy NUL terminated strings.

Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
Reviewed-by: Kees Cook <keescook@chromium.org>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>


# 32590819 25-Apr-2018 Mauro Carvalho Chehab <mchehab+samsung@kernel.org>

MAINTAINERS & files: Canonize the e-mails I use at files

From now on, I'll start using my @kernel.org as my development e-mail.

As such, let's remove the entries that point to the old
mchehab@s-opensource.com at MAINTAINERS file.

For the files written with a copyright with mchehab@s-opensource,
let's keep Samsung on their names, using mchehab+samsung@kernel.org,
in order to keep pointing to my employer, with sponsors the work.

For the files written before I join Samsung (on July, 4 2013),
let's just use mchehab@kernel.org.

For bug reports, we can simply point to just kernel.org, as
this will reach my mchehab+samsung inbox anyway.

Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Signed-off-by: Brian Warner <brian.warner@samsung.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>


# 3aab15af 21-Feb-2018 Hans Verkuil <hverkuil@xs4all.nl>

media: add tuner standby op, use where needed

The v4l2_subdev core s_power op was used for two different things: power on/off
sensors or video decoders/encoders and to put a tuner in standby (and only the
tuner!). There is no 'tuner wakeup' op, that's done automatically when the tuner
is accessed.

The danger with calling (s_power, 0) to put a tuner into standby is that it is
usually broadcast for all subdevs. So a video receiver subdev that supports
s_power will also be powered off, and since there is no corresponding (s_power, 1)
they will never be powered on again.

In addition, this is specifically meant for tuners only since they draw the most
current.

This patch adds a new tuner op called 'standby' and replaces all calls to
(core, s_power, 0) by (tuner, standby). This prevents confusion between the two
uses of s_power. Note that there is no overlap: bridge drivers either just want
to put the tuner into standby, or they deal with powering on/off sensors. Never
both.

This also makes it easier to replace s_power for the remaining bridge drivers
with some PM code later.

Whether we want something cleaner for tuners in the future is a separate topic.
There is a lot of legacy code surrounding tuners, and I am very hesitant about
making changes there.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>


# f9fe90a4 03-Mar-2018 Mauro Carvalho Chehab <mchehab@kernel.org>

media: em28xx-video: fix most coding style issues

There are a number of coding style issues at em28xx-video.
Fix most of them, by using checkpatch in strict mode to point
for it.

Automatic fixes were made with --fix-inplace, but those
were complemented by manual work.

Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>


# f22e9e71 03-Mar-2018 Mauro Carvalho Chehab <mchehab@kernel.org>

media: em28xx: Add SPDX license tags where needed

Most of the files there are missing a SPDX license tag. Add.

While here fix some DRIVER_LICENSE macro in order to reflect
the source file license, as some of the headers are GPL v2
only.

Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>


# aa62980b 01-Mar-2018 Mauro Carvalho Chehab <mchehab@kernel.org>

media: em28xx: stop rewriting device's struct

Writing at the device's struct is evil, as two em28xx devices
may be using it. So, stop abusing it, storing the values
inside struct em28xx_dev.

Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>


# 4471109e 22-Jan-2018 Hans Verkuil <hans.verkuil@cisco.com>

media: convert g/s_parm to g/s_frame_interval in subdevs

Convert all g/s_parm calls to g/s_frame_interval. This allows us
to remove the g/s_parm ops since those are a duplicate of
g/s_frame_interval.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>


# b436e26e 02-Nov-2017 Colin Ian King <colin.king@canonical.com>

media: usb: fix spelling mistake: "synchronuously" -> "synchronously"

Trivial fix to spelling mistake in error message text

[mchehab@s-opensource.org: folded all similar patches into one]
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>


# 495ab569 15-Apr-2017 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: add support for V4L2_PIX_FMT_SRGGB8

Adding support for SRGGB8 is as simple as adding a new entry at
struct em28xx_fmt.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>


# a7b8e9a5 15-Apr-2017 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: shed some light on video input formats

CbYCrY has been identified by looking into the tvp5150 driver and the
saa7115 datasheet.
YUV formats have been verified with em2765 + ov2640 (VAD Laplace webcam).
RGB8 formats have been verified with em2710/em2820 + mt9v011 (Silvercrest
webcam 1.3mpix).
I also did some cross-checking with these two camera devices and 0x08-0x0b
are at least 16 bits per pixel formats on em2710/em2820, too, and
0x0c-0x0f are at least 8 bits per pixel formats on em2765, too.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>


# 2437aeb4 15-Apr-2017 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: get rid of the dummy clock source

The v4l2 dummy clock has been added with commit fc5d0f8a8878
("V4L2: em28xx: register a V4L2 clock source") to be able to use the ov2640
soc_camera driver.
Since commit 46796cfcd346 ("ov2640: use standard clk and enable it") it is
no longer required.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>


# c6d48134 07-Dec-2016 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] em28xx: don't store usb_device at struct em28xx

Now that we're storing usb_interface at em28xx struct,
there's no good reason to keep storing usb_device, as we can
get it from usb_interface. So, get rid of it.

Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>


# 29b05e22 07-Dec-2016 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] em28xx: use usb_interface for dev_foo() calls

The usb_device->dev is not the right device for dev_foo() calls.
Instead, it should use usb_interface->dev.

Tested-by: Antti Palosaari <crope@iki.fi>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>


# ce8591ff 20-Oct-2016 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] em28xx: convert it from pr_foo() to dev_foo()

Instead of using pr_foo(), use dev_foo(), with provides a
better output. As this device is a multi-interface one,
we'll set the device name to show the chipset and the driver
used.

While here, get rid of printk continuation messages.

Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>


# 2a96f60e 12-Oct-2016 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] em28xx: convert the remaining printks to pr_foo

There are still several places with printk's called directly.

Convert them to pr_foo() macros, except for the debug printk's,
as those are enabled via modprobe vars.

While here, realign the pr_foo() arguments to match the
recommended CodingStyle.

Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>


# 8314d402 12-Oct-2016 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] em28xx: use pr_foo instead of em28xx-specific printk macros

There's no reason to keep using em28xx-specific printk macros
here. Just use pr_foo().

Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>


# 5ccb197d 12-Oct-2016 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] em28xx: don't break long lines

Due to the 80-cols checkpatch warnings, several strings
were broken into multiple lines. This is not considered
a good practice anymore, as it makes harder to grep for
strings at the source code. So, join those continuation
lines.

Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>


# 1bc17717 08-Sep-2016 Julia Lawall <Julia.Lawall@lip6.fr>

[media] usb: constify vb2_ops structures

Check for vb2_ops structures that are only stored in the ops field of a
vb2_queue structure. That field is declared const, so vb2_ops structures
that have this property can be declared as const also.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@r disable optional_qualifier@
identifier i;
position p;
@@
static struct vb2_ops i@p = { ... };

@ok@
identifier r.i;
struct vb2_queue e;
position p;
@@
e.ops = &i@p;

@bad@
position p != {r.p,ok.p};
identifier r.i;
struct vb2_ops e;
@@
e@i@p

@depends on !bad disable optional_qualifier@
identifier r.i;
@@
static
+const
struct vb2_ops i = { ... };
// </smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>


# 36c0f8b3 15-Apr-2016 Hans Verkuil <hans.verkuil@cisco.com>

[media] vb2: replace void *alloc_ctxs by struct device *alloc_devs

Make this a proper typed array. Drop the old allocate context code since
that is no longer used.

Note that the memops functions now get a struct device pointer instead of
the struct device ** that was there initially (actually a void pointer to
a struct containing only a struct device pointer).

This code is now a lot cleaner.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Sakari Ailus <sakari.ailus@iki.fi>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>


# 0d37ba62 26-Feb-2016 Arnd Bergmann <arnd@arndb.de>

[media] em28xx: restore lost #ifdef

The cleanup that changed the em28xx driver to use v4l2_mc_create_media_graph
instead of its own implementation causes a build error when CONFIG_MEDIA_CONTROLLER
is disabled:

drivers/media/usb/em28xx/em28xx-video.c: In function 'em28xx_v4l2_init':
drivers/media/usb/em28xx/em28xx-video.c:2717:38: error: 'struct em28xx' has no member named 'media_dev'

This puts the new code inside the same #ifdef that controls the presence
of the 'media_dev' member, and that the old code was in.

Fixes: de39078779cb ("[media] em2xx: use v4l2_mc_create_media_graph()")

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>


# e9ef88bd 11-Feb-2016 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] em28xx-dvb: create RF connector on DVB-only mode

When in analog mode, the RF connector will be created by
em28xx-video. However, when the device is in digital mode only,
the RF connector is not shown. In this case, let the DVB
core to create it for us.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>


# de390787 05-Feb-2016 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] em2xx: use v4l2_mc_create_media_graph()

Now that the core has a function to create the media graph,
we can get rid of the specialized code at em28xx.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>


# 37ecc7b1 27-Jan-2016 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] em28xx: add media controller support

Add the needed bits to make em28xx to create a media
controller graph.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>


# 0962a763 29-Jan-2016 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] em28xx: avoid divide by zero error

[ 1841.243670] divide error: 0000 [#1] SMP KASAN
[ 1841.243994] Modules linked in: em28xx_rc rc_core tda18271 drxk em28xx_dvb dvb_core em28xx_alsa mt9v011 em28xx_v4l videobuf2_vmalloc videobuf2_memops videobuf2_v4l2 videobuf2_core em28xx tveeprom v4l2_common videodev media cpufreq_powersave cpufreq_conservative cpufreq_userspace cpufreq_stats parport_pc ppdev lp parport snd_hda_codec_hdmi intel_rapl x86_pkg_temp_thermal intel_powerclamp coretemp kvm_intel kvm iTCO_wdt iTCO_vendor_support irqbypass crct10dif_pclmul crc32_pclmul crc32c_intel ghash_clmulni_intel sha256_ssse3 sha256_generic hmac drbg i915 snd_hda_codec_realtek snd_hda_codec_generic aesni_intel aes_x86_64 lrw gf128mul glue_helper ablk_helper cryptd btusb i2c_algo_bit snd_hda_intel btrtl drm_kms_helper btbcm evdev snd_hda_codec btintel psmouse bluetooth pcspkr snd_hwdep sg drm serio_raw
[ 1841.244845] snd_hda_core snd_pcm mei_me rfkill snd_timer mei snd lpc_ich soundcore shpchp i2c_i801 mfd_core battery dw_dmac i2c_designware_platform i2c_designware_core dw_dmac_core video acpi_pad button tpm_tis tpm ext4 crc16 mbcache jbd2 dm_mod hid_generic usbhid sd_mod ahci libahci libata ehci_pci e1000e xhci_pci ptp scsi_mod ehci_hcd xhci_hcd pps_core fan thermal sdhci_acpi sdhci mmc_core i2c_hid hid [last unloaded: tveeprom]
[ 1841.245342] CPU: 2 PID: 38 Comm: kworker/2:1 Tainted: G W 4.5.0-rc1+ #43
[ 1841.245413] Hardware name: /NUC5i7RYB, BIOS RYBDWi35.86A.0350.2015.0812.1722 08/12/2015
[ 1841.245503] Workqueue: events request_module_async [em28xx]
[ 1841.245557] task: ffff88009df10000 ti: ffff88009df18000 task.ti: ffff88009df18000
[ 1841.245626] RIP: 0010:[<ffffffffa135a0ad>] [<ffffffffa135a0ad>] size_to_scale+0xed/0x2c0 [em28xx_v4l]
[ 1841.245714] RSP: 0018:ffff88009df1faa8 EFLAGS: 00010246
[ 1841.245756] RAX: 0000000000000000 RBX: 0000000000000000 RCX: ffff8803bb933b38
[ 1841.245815] RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffff8803bb933b00
[ 1841.245879] RBP: ffff88009df1fad8 R08: ffff8803bb933b3c R09: 1ffff10077726760
[ 1841.245944] R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000000
[ 1841.246006] R13: 0000000000000000 R14: dffffc0000000000 R15: ffff8803b391a130
[ 1841.246071] FS: 0000000000000000(0000) GS:ffff8803c6900000(0000) knlGS:0000000000000000
[ 1841.246141] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 1841.246194] CR2: 0000000001d97008 CR3: 00000003bdd85000 CR4: 00000000003406e0
[ 1841.246256] Stack:
[ 1841.246278] 0000000000000246 ffff8803bb9321f0 ffff8803bb932270 ffffffffa136f7a0
[ 1841.246359] 0000000000000000 ffff8803bb932130 ffff88009df1fb20 ffffffffa13646a0
[ 1841.246439] ffffffffa127f206 ffff8803bb932130 ffff8803bb932130 ffff8803b391a130
[ 1841.246517] Call Trace:
[ 1841.246548] [<ffffffffa13646a0>] em28xx_set_video_format+0x140/0x1e0 [em28xx_v4l]

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>


# 56a7f515 29-Jan-2016 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] em28xx: unregister devices in case of failure

If something bad happens during device registration, unregister
the already registered devices.

Without that, it will have lots of KASAN errors when udev
would try to open the devices.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>


# d83a96a5 27-Jan-2016 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] em28xx: remove unused input types

The em28xx driver have lots of different input types but
only 4 of such types are actually used. The others are bogus.

Remove them, in order to cleanup the driver.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>


# 13d52fe4 26-Jan-2016 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] em28xx: fix implementation of s_stream

On em28xx driver, s_stream subdev ops was not implemented
properly. It was used only to disable stream, never enabling it.
That was the root cause of the regression when we added support
for s_stream on tvp5150 driver.

With that, we can get rid of the changes on tvp5150 side,
e. g. changeset 47de9bf8931e ('[media] tvp5150: Fix breakage for serial usage').

Tested video output on em2820+tvp5150 on WinTV USB2 and
video and/or vbi output on em288x+tvp5150 on HVR 950.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>


# d6dd645e 03-Nov-2015 Junghak Sung <jh1009.sung@samsung.com>

[media] media: videobuf2: Move timestamp to vb2_buffer

Move timestamp from struct vb2_v4l2_buffer to struct vb2_buffer
for common use, and change its type to u64 in order to handling
y2038 problem. This patch also includes all device drivers' changes related to
this restructuring.

Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com>
Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Acked-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Hans Verkuil <hansverk@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>


# df9ecb0c 27-Oct-2015 Hans Verkuil <hans.verkuil@cisco.com>

[media] vb2: drop v4l2_format argument from queue_setup

The queue_setup callback has a void pointer that is just for V4L2
and is the pointer to the v4l2_format struct that was passed to
VIDIOC_CREATE_BUFS. The idea was that drivers would use the information
from that struct to buffers suitable for the requested format.

After the vb2 split series this pointer is now a void pointer,
which is ugly, and the reality is that all existing drivers will
effectively just look at the sizeimage field of v4l2_format.

To make this more generic the queue_setup callback is changed:
the void pointer is dropped, instead if the *num_planes argument
is 0, then use the current format size, if it is non-zero, then
it contains the number of requested planes and the sizes array
contains the requested sizes. If either is unsupported, then return
-EINVAL, otherwise use the requested size(s).

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>


# d647f0b7 13-Nov-2015 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] include/media: move driver interface headers to a separate dir

Let's not mix headers used by the core with those headers that
are needed by some driver-specific interface header.

The headers used on drivers were manually moved using:
mkdir include/media/drv-intf/
git mv include/media/cx2341x.h include/media/cx25840.h \
include/media/exynos-fimc.h include/media/msp3400.h \
include/media/s3c_camif.h include/media/saa7146.h \
include/media/saa7146_vv.h include/media/sh_mobile_ceu.h \
include/media/sh_mobile_csi2.h include/media/sh_vou.h \
include/media/si476x.h include/media/soc_mediabus.h \
include/media/tea575x.h include/media/drv-intf/

And the references for those headers were corrected using:

MAIN_DIR="media/"
PREV_DIR="media/"
DIRS="drv-intf/"

echo "Checking affected files" >&2
for i in $DIRS; do
for j in $(find include/$MAIN_DIR/$i -type f -name '*.h'); do
n=`basename $j`
git grep -l $n
done
done|sort|uniq >files && (
echo "Handling files..." >&2;
echo "for i in \$(cat files|grep -v Documentation); do cat \$i | \\";
(
cd include/$MAIN_DIR;
for j in $DIRS; do
for i in $(ls $j); do
echo "perl -ne 's,(include [\\\"\\<])$PREV_DIR($i)([\\\"\\>]),\1$MAIN_DIR$j\2\3,; print \$_' |\\";
done;
done;
echo "cat > a && mv a \$i; done";
);
echo "Handling documentation..." >&2;
echo "for i in MAINTAINERS \$(cat files); do cat \$i | \\";
(
cd include/$MAIN_DIR;
for j in $DIRS; do
for i in $(ls $j); do
echo " perl -ne 's,include/$PREV_DIR($i)\b,include/$MAIN_DIR$j\1,; print \$_' |\\";
done;
done;
echo "cat > a && mv a \$i; done"
);
) >script && . ./script

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Acked-by: Arnd Bergmann <arnd@arndb.de>


# 33119e80 06-Oct-2015 Junghak Sung <jh1009.sung@samsung.com>

[media] media: videobuf2: Change queue_setup argument

Replace struct v4l2_format * with void * to make queue_setup()
for common use.
And then, modify all device drivers related with this change.

Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com>
Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Acked-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
[hans.verkuil@cisco.com: fix missing const in fimc-lite.c]

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>


# 2d700715 22-Sep-2015 Junghak Sung <jh1009.sung@samsung.com>

[media] media: videobuf2: Restructure vb2_buffer

Remove v4l2 stuff - v4l2_buf, v4l2_plane - from struct vb2_buffer.

Add new member variables - bytesused, length, offset, userptr, fd,
data_offset - to struct vb2_plane in order to cover all information
of v4l2_plane.
struct vb2_plane {
<snip>
unsigned int bytesused;
unsigned int length;
union {
unsigned int offset;
unsigned long userptr;
int fd;
} m;
unsigned int data_offset;
}

Replace v4l2_buf with new member variables - index, type, memory - which
are common fields for buffer management.
struct vb2_buffer {
<snip>
unsigned int index;
unsigned int type;
unsigned int memory;
unsigned int num_planes;
struct vb2_plane planes[VIDEO_MAX_PLANES];
<snip>
};

v4l2 specific fields - flags, field, timestamp, timecode,
sequence - are moved to vb2_v4l2_buffer in videobuf2-v4l2.c
struct vb2_v4l2_buffer {
struct vb2_buffer vb2_buf;

__u32 flags;
__u32 field;
struct timeval timestamp;
struct v4l2_timecode timecode;
__u32 sequence;
};

Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com>
Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Acked-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>


# 7fdc5561 05-Jun-2015 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] em28xx: remove dead code

As reported by smatch:
drivers/media/usb/em28xx/em28xx-video.c:842 get_ressource() info: ignoring unreachable code.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>


# d4352f36 09-Mar-2015 Hans Verkuil <hans.verkuil@cisco.com>

[media] em28xx: embed video_device

Embed the video_device struct to simplify the error handling and in
order to (eventually) get rid of video_device_alloc/release.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>


# 32e63f03 20-Dec-2014 Russell King <rmk+kernel@arm.linux.org.uk>

[media] em28xx-video: fix missing newlines

Inspection shows that newlines are missing from several kernel messages
in em28xx-video. Fix these.

Fixes: a61f68119af3 ("[media] em28xx-video: implement em28xx_ops: suspend/resume hooks")

Cc: <stable@vger.kernel.org>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Reviewed-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>


# 0418ca60 20-Dec-2014 Russell King <rmk+kernel@arm.linux.org.uk>

[media] em28xx: ensure "closing" messages terminate with a newline

The lockdep splat addressed in a previous commit revealed that at
least one message in em28xx-input.c was missing a new line:

em28178 #0: Closing input extensionINFO: trying to register non-static key.

Further inspection shows several other messages also miss a new line.
These will be fixed in a subsequent patch.

Fixes: aa929ad783c0 ("[media] em28xx: print a message at disconnect")

Cc: <stable@vger.kernel.org>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Reviewed-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>


# 21a7e059 01-Dec-2014 Hans Verkuil <hans.verkuil@cisco.com>

[media] media: drivers shouldn't touch debug field in video_device

The debug field in struct video_device is for internal use only and
drivers should mix that with their own debug module options.

It is handled by the V4L2 core and users can set it using
/sys/class/video4linux/<devX>/debug.

It has been deprecated for some time now, so it is time to remove it
completely from the drivers.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>


# fdf1bc9f 28-Nov-2014 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] em28xx: checkpatch cleanup: whitespaces/new lines cleanups

This patch is basically produced while testing a tool that
Joe Perches sent upstream sometime ago:
https://lkml.org/lkml/2014/7/11/794

I used it with those arguments:
$ reformat_with_checkpatch.sh drivers/media/usb/em28xx/em28xx*.[ch]

It actually produced 24 patches, with is too much, and showed
interesting things: gcc produced different codes on most of the
patches, even with just linespace changes. The total code data
remained the same on all cases I checked though.

Anyway, provided that we fold the resulting patches, this tool
seems useful.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>


# 7983b773 24-Sep-2014 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] usb drivers: use %zu instead of %zd

size_t is unsigned.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>


# 920f1e4a 13-Sep-2014 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: get rid of field has_audio in struct em28xx_audio_mode

Field has_audio in struct em28xx_audio_mode is used together with value
EM28XX_NO_AC97 of field ac97 to determine the internal type of audio
(none/i2s/ac97). This makes the code difficult to understand:

!audio_mode.has_audio && audio_mode.ac97 == EM28XX_NO_AC97 => no audio
!audio_mode.has_audio && audio_mode.ac97 != EM28XX_NO_AC97 => BUG
audio_mode.has_audio && audio_mode.ac97 == EM28XX_NO_AC97 => AC97 audio
audio_mode.has_audio && audio_mode.ac97 != EM28XX_NO_AC97 => I2S audio

Simplify the whole thing by introducing an enum em28xx_int_audio_type
which describes the internal audio type (none, ac97, i2s) and is hooked
directly to the device struct. Then get rid of field has_audio in struct
em28xx_audio_mode.

A follow-up patch will then remove struct em28xx_ac97_mode and finally
the whole struct em28xx_audio_mode.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>


# 8e2c8717 18-Sep-2014 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx-v4l: get rid of field "users" in struct em28xx_v4l2"

This reverts commit 747dba7de2a51a3db58b665ed3bc8c07921546ec.

It breaks concurrent vbi and video capturing:
While v4l2->users is the number of users of the whole device (all device nodes),
v4l2_fh_is_singular() only checks the number of users of a specific device node.
As a result. if one device node is open and a second device node is opened
(closed), the device is reinitialized (streaming is stopped).

Reported-by: Hans Verkuil <hans.verkuil@cisco.com>
Tested-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Cc: stable@vger.kernel.org
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>


# c7854c2c 19-Sep-2014 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] em28xx: fix VBI handling logic

When both VBI and video are streaming, and video stream is stopped,
a subsequent trial to restart it will fail, because S_FMT will
return -EBUSY.

That prevents applications like zvbi to work properly.

Please notice that, while this fix it fully for zvbi, the
best is to get rid of streaming_users and res_get logic as a hole.

However, this single-line patch is better to be merged at -stable.

Cc: stable@vger.kernel.org
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>


# 7e6c8c19 03-Sep-2014 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] em28xx: use true/false for boolean vars

Instead of using 0 or 1 for boolean, use the true/false
defines.

Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 662c97cf 09-Aug-2014 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx-v4l: fix video buffer field order reporting in progressive mode

The correct field order in progressive mode is V4L2_FIELD_NONE, not V4L2_FIELD_INTERLACED.

Cc: <stable@vger.kernel.org>
Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 627530c3 09-Aug-2014 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx-v4l: give back all active video buffers to the vb2 core properly on streaming stop

When a new video frame is started, the driver takes the next video buffer from
the list of active buffers and moves it to dev->usb_ctl.vid_buf / dev->usb_ctl.vbi_buf
for further processing.

On streaming stop we currently only give back the pending buffers from the list
but not the ones which are currently processed.

This causes the following warning from the vb2 core since kernel 3.15:

...
------------[ cut here ]------------
WARNING: CPU: 1 PID: 2284 at drivers/media/v4l2-core/videobuf2-core.c:2115 __vb2_queue_cancel+0xed/0x150 [videobuf2_core]()
[...]
Call Trace:
[<c0769c46>] dump_stack+0x48/0x69
[<c0245b69>] warn_slowpath_common+0x79/0x90
[<f925e4ad>] ? __vb2_queue_cancel+0xed/0x150 [videobuf2_core]
[<f925e4ad>] ? __vb2_queue_cancel+0xed/0x150 [videobuf2_core]
[<c0245bfd>] warn_slowpath_null+0x1d/0x20
[<f925e4ad>] __vb2_queue_cancel+0xed/0x150 [videobuf2_core]
[<f925fa35>] vb2_internal_streamoff+0x35/0x90 [videobuf2_core]
[<f925fac5>] vb2_streamoff+0x35/0x60 [videobuf2_core]
[<f925fb27>] vb2_ioctl_streamoff+0x37/0x40 [videobuf2_core]
[<f8e45895>] v4l_streamoff+0x15/0x20 [videodev]
[<f8e4925d>] __video_do_ioctl+0x23d/0x2d0 [videodev]
[<f8e49020>] ? video_ioctl2+0x20/0x20 [videodev]
[<f8e48c63>] video_usercopy+0x203/0x5a0 [videodev]
[<f8e49020>] ? video_ioctl2+0x20/0x20 [videodev]
[<c039d0e7>] ? fsnotify+0x1e7/0x2b0
[<f8e49012>] video_ioctl2+0x12/0x20 [videodev]
[<f8e49020>] ? video_ioctl2+0x20/0x20 [videodev]
[<f8e4461e>] v4l2_ioctl+0xee/0x130 [videodev]
[<f8e44530>] ? v4l2_open+0xf0/0xf0 [videodev]
[<c0378de2>] do_vfs_ioctl+0x2e2/0x4d0
[<c0368eec>] ? vfs_write+0x13c/0x1c0
[<c0369a8f>] ? vfs_writev+0x2f/0x50
[<c0379028>] SyS_ioctl+0x58/0x80
[<c076fff3>] sysenter_do_call+0x12/0x12
---[ end trace 5545f934409f13f4 ]---
...

Many thanks to Hans Verkuil, whose recently added check in the vb2 core unveiled
this long standing issue and who has investigated it further.

Cc: <stable@vger.kernel.org>
Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 3d3a4109 25-Jul-2014 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx-v4l: fix disabling ioctl VIDIOC_S_PARM for vbi devices

Fixes an old copy+paste bug that has survived all recent code
changes in this code area.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 747dba7d 25-Jul-2014 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx-v4l: get rid of field "users" in struct em28xx_v4l2

Instead of counting the number of opened file handles, use function
v4l2_fh_is_singular_file() in em28xx_v4l2_open() and em28xx_v4l2_close() to
determine if the file handle is the first/last opened one.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 3c0f90e1 25-Jul-2014 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx-v4l: simplify em28xx_v4l2_open() by using v4l2_fh_open()

Instead of calling

...
struct v4l2_fh *fh = kzalloc(sizeof(*fh), GFP_KERNEL);
filp->private_data = fh;
v4l2_fh_init(fh, vdev);
v4l2_fh_add(fh);
...

simply use function v4l2_fh_open() which does all of these calls for us.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 917ba6b0 25-Jul-2014 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx-v4l: get rid of struct em28xx_fh

struct em28xx_fh isn't needed anymore because the only used field which is left is struct v4l2_fh fh.
Use struct v4l2_fh directly and remvove struct em28xx_fh.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 95cd5d5e 19-Jun-2014 Ramakrishnan Muthukrishnan <ramakrmu@cisco.com>

[media] media: remove the setting of the flag V4L2_FL_USE_FH_PRIO

Since all the drivers that use `struct v4l2_fh' use the core
priority checking, the setting of the flag in the drivers can
be removed.

Signed-off-by: Ramakrishnan Muthukrishnan <ramakrmu@cisco.com>
Reviewed-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 8774bed9 28-Apr-2014 Laurent Pinchart <laurent.pinchart@ideasonboard.com>

[media] v4l: subdev: Move [gs]_std operation to video ops

The g_std and s_std operations are video-related, move them to the video
ops where they belong.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Acked-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# f472c0b5 23-May-2014 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] em28xx: make em28xx_free_v4l2 static()

Changeset 95d2608b88 created this function, but declared it as
global, by mistake.

Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 3319e6f8 24-Mar-2014 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: remove field tuner_addr from struct em28xx

The tuner address is only used by the v4l submodule and at tuner setup and
can be obtained from the board data directly (if specified).

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 6867bd5a 24-Mar-2014 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: remove field tda9887_conf from struct em28xx

The tda9887 chipset is part of the analog tuner. Move it out of
em28xx-cards.

Also, it is used only one time by the v4l2 sub-module at tuner setup.

With that, we can get rid of an additional data inside the em28xx
common structure.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 3854b0d8 24-Mar-2014 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: move tuner frequency field from struct em28xx to struct v4l2

Move V4L2-specific frequency cache to struct em28xx_v4l2.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 8139a4d5 11-May-2014 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: move v4l2 user counting fields from struct em28xx to struct v4l2

Despite being at the common em28xx struct, those two fields are
actually taking into account only the usage inside em28xx v4l2
submodule. So, move them out of the common struct.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# f0e38230 24-Mar-2014 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: move capture state tracking fields from struct em28xx to struct v4l2

Move some temporary capture tracking date to the em28xx_v4l2 struct,
as those info are used only by em28xx v4l2 submodule.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# d7dc18da 24-Mar-2014 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: move sensor parameter fields from struct em28xx to struct v4l2

Move camera sensor resolution and xtal out of em28xx common struct,
as thore are used only by the em28xx v4l2 submodule.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 58159171 24-Mar-2014 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: move progressive/interlaced fields from struct em28xx to struct v4l2

The video progressive data fields belong to analog TV. Move them out
of the common em28xx struct.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 06e20672 24-Mar-2014 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: move struct em28xx_fmt *format from struct em28xx to struct v4l2

The analog format struct belongs to analog TV. Move it out of the
common em28xx struct.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 52faaf78 24-Mar-2014 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: move TV norm from struct em28xx to struct v4l2

TV norm is specific to analog TV reception. move it out of the common
em28xx struct.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 9297285e 24-Mar-2014 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: move vinmode and vinctrl data from struct em28xx to struct v4l2

The video input mode and control data also belong only to the
analog side. move them to struct em28xx_v4l.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 753aee77 24-Mar-2014 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: move v4l2 frame resolutions and scale data from struct em28xx to struct v4l2

The em28xx scaler data are used only for analog video. Move them to
struct em28xx_v4l2.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 27a36df6 24-Mar-2014 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: move videobuf2 related data from struct em28xx to struct v4l2

The video and VBI-specific VB2 queue and mutexes are used only by
the v4l2 sub-driver. Move them to the V4L2 struct, preventing
wasting memory if this sub-driver is not used.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# ef74a0b9 24-Mar-2014 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: move video_device structs from struct em28xx to struct v4l2

There are 3 struct video_device at the em28xx common struct,
for video, VBI and radio. They all are used only by the V4L2 driver.
So, move them to the v4l2-specific struct.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 2c52a2fc 24-Mar-2014 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: move struct v4l2_clk *clk from struct em28xx to struct v4l2

The current clock definition applies only to the V4L2 side of the
driver. Move its struct pointer to the v4l2_dev, where it belongs.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# abc1308f 24-Mar-2014 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: move struct v4l2_ctrl_handler ctrl_handler from struct em28xx to struct v4l2

Controls are only applicable to V4L2 module. Move the corresponding
data structs to the proper place.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 95d2608b 24-Mar-2014 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: start moving em28xx-v4l specific data to its own struct

That reduces a little bit the memory footprint when em28xx-video
is not loaded.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# ad298055 24-Mar-2014 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx-video: simplify usage of the pointer to struct v4l2_ctrl_handler in em28xx_v4l2_init()

The local var hdl is already pointing to &dev->ctrl_handler.
Use it, instead of dereferencing it all the time.

Code cleanup. No functional changes.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 25c61e4c 22-Mar-2014 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: move norm_maxw() and norm_maxh() from em28xx.h to em28xx-video.c

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# cba8e9b3 24-Mar-2014 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: remove function em28xx_compression_disable() and its call

em28xx_compression_disable() is a single line function which is called only one
time and this call also isn't needed.
Register 0x26 is always configured as part of the scaler configuration, which
in turn is always done when the resolution changes. And the initial resolution
setting is applied at first device open.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# e37559b2 16-Apr-2014 Hans Verkuil <hans.verkuil@cisco.com>

[media] vb2: stop_streaming should return void

The vb2 core ignores any return code from the stop_streaming op.
And there really isn't anything it can do anyway in case of an error.
So change the return type to void and update any drivers that implement it.

The int return gave drivers the idea that this operation could actually
fail, but that's really not the case.

The pwc amd sdr-msi3101 drivers both had this construction:

if (mutex_lock_interruptible(&s->v4l2_lock))
return -ERESTARTSYS;

This has been updated to just call mutex_lock(). The stop_streaming op
expects this to really stop streaming and I very much doubt this will
work reliably if stop_streaming just returns without really stopping the
DMA.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Acked-by: Pawel Osciak <pawel@osciak.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 47677e51 05-Mar-2014 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] em28xx: Only deallocate struct em28xx after finishing all extensions

We can't free struct em28xx while one of the extensions is still
using it.

So, add a kref() to control it, freeing it only after the
extensions fini calls.

Reviewed-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# ade48681 25-Feb-2014 Sakari Ailus <sakari.ailus@linux.intel.com>

[media] v4l: Rename vb2_queue.timestamp_type as timestamp_flags

The timestamp_type field used to contain only the timestamp type. Soon it
will be used for timestamp source flags as well. Rename the field
accordingly.

[m.chehab@samsung.com: do the change also to drivers/staging/media and at s2255]
Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# a61f6811 21-Feb-2014 Shuah Khan <shuah@kernel.org>

[media] em28xx-video: implement em28xx_ops: suspend/resume hooks

Implement em28xx_ops: suspend/resume hooks. em28xx usb driver will
invoke em28xx_ops: suspend and resume hooks for all its extensions
from its suspend() and resume() interfaces.

Signed-off-by: Shuah Khan <shuah.kh@samsung.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# d86bc65a 17-Jan-2014 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx-v4l: do not call em28xx_init_camera() if the device has no sensor

This avoids the unnecessary temporary registration of a dummy V4L2 clock.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 103f18a2 17-Jan-2014 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx-video: do not unregister the v4l2 dummy clock before v4l2_device_unregister() has been called

Otherwiese the core refuses to unregister the clock and the following warning
appears in the system log:

"WARNING: ... at drivers/media/v4l2-core/v4l2-clk.c:231 v4l2_clk_unregister+0x8a/0x90 [videodev]()
v4l2_clk_unregister(): Refusing to unregister ref-counted 11-0030:mclk clock!"

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 961717b4 13-Jan-2014 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: fix usb alternate setting for analog and digital video endpoints > 0

The current code assumes that the analog + digital video endpoints are always at
interface number 0 when changing the alternate setting.
This seems to work fine for most existing devices.
However, at least the SpeedLink VAD Laplace webcam has the video endpoint on
interface number 3 (which fortunately doesn't cause any trouble because ist uses
bulk transfers only).
We already consider the actual interface number for audio endpoints, so
rename the the audio_ifnum variable and use it for all device types.
Also get get rid of a pointless (ifnum < 0) in em28xx-audio.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 8068eb88 06-Jan-2014 Fengguang Wu <fengguang.wu@intel.com>

[media] em28xx: make 'em28xx_ctrl_ops' static

sparse warnings: (new ones prefixed by >>)

>> drivers/media/usb/em28xx/em28xx-video.c:1151:28: sparse: symbol 'em28xx_ctrl_ops' was not declared. Should it be static?

Signed-off-by: Fengguang Wu <fengguang.wu@intel.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# ebbfbc20 12-Jan-2014 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] em28xx: push mutex down to extensions on .fini callback

Avoid circular mutex lock by pushing the dev->lock to the .fini
callback on each extension.

As em28xx-dvb, em28xx-alsa and em28xx-rc have their own data
structures, and don't touch at the common structure during .fini,
only em28xx-v4l needs to be locked.

[ 90.994317] ======================================================
[ 90.994356] [ INFO: possible circular locking dependency detected ]
[ 90.994395] 3.13.0-rc1+ #24 Not tainted
[ 90.994427] -------------------------------------------------------
[ 90.994458] khubd/54 is trying to acquire lock:
[ 90.994490] (&card->controls_rwsem){++++.+}, at: [<ffffffffa0177b08>] snd_ctl_dev_free+0x28/0x60 [snd]
[ 90.994656]
[ 90.994656] but task is already holding lock:
[ 90.994688] (&dev->lock){+.+.+.}, at: [<ffffffffa040db81>] em28xx_close_extension+0x31/0x90 [em28xx]
[ 90.994843]
[ 90.994843] which lock already depends on the new lock.
[ 90.994843]
[ 90.994874]
[ 90.994874] the existing dependency chain (in reverse order) is:
[ 90.994905]
-> #1 (&dev->lock){+.+.+.}:
[ 90.995057] [<ffffffff810b8fa3>] __lock_acquire+0xb43/0x1330
[ 90.995121] [<ffffffff810b9f82>] lock_acquire+0xa2/0x120
[ 90.995182] [<ffffffff816a5b6c>] mutex_lock_nested+0x5c/0x3c0
[ 90.995245] [<ffffffffa0422cca>] em28xx_vol_put_mute+0x1ba/0x1d0 [em28xx_alsa]
[ 90.995309] [<ffffffffa017813d>] snd_ctl_elem_write+0xfd/0x140 [snd]
[ 90.995376] [<ffffffffa01791c2>] snd_ctl_ioctl+0xe2/0x810 [snd]
[ 90.995442] [<ffffffff811db8b0>] do_vfs_ioctl+0x300/0x520
[ 90.995504] [<ffffffff811dbb51>] SyS_ioctl+0x81/0xa0
[ 90.995568] [<ffffffff816b1929>] system_call_fastpath+0x16/0x1b
[ 90.995630]
-> #0 (&card->controls_rwsem){++++.+}:
[ 90.995780] [<ffffffff810b7a47>] check_prevs_add+0x947/0x950
[ 90.995841] [<ffffffff810b8fa3>] __lock_acquire+0xb43/0x1330
[ 90.995901] [<ffffffff810b9f82>] lock_acquire+0xa2/0x120
[ 90.995962] [<ffffffff816a762b>] down_write+0x3b/0xa0
[ 90.996022] [<ffffffffa0177b08>] snd_ctl_dev_free+0x28/0x60 [snd]
[ 90.996088] [<ffffffffa017a255>] snd_device_free+0x65/0x140 [snd]
[ 90.996154] [<ffffffffa017a751>] snd_device_free_all+0x61/0xa0 [snd]
[ 90.996219] [<ffffffffa0173af4>] snd_card_do_free+0x14/0x130 [snd]
[ 90.996283] [<ffffffffa0173f14>] snd_card_free+0x84/0x90 [snd]
[ 90.996349] [<ffffffffa0423397>] em28xx_audio_fini+0x97/0xb0 [em28xx_alsa]
[ 90.996411] [<ffffffffa040dba6>] em28xx_close_extension+0x56/0x90 [em28xx]
[ 90.996475] [<ffffffffa040f639>] em28xx_usb_disconnect+0x79/0x90 [em28xx]
[ 90.996539] [<ffffffff814a06e7>] usb_unbind_interface+0x67/0x1d0
[ 90.996620] [<ffffffff8142920f>] __device_release_driver+0x7f/0xf0
[ 90.996682] [<ffffffff814292a5>] device_release_driver+0x25/0x40
[ 90.996742] [<ffffffff81428b0c>] bus_remove_device+0x11c/0x1a0
[ 90.996801] [<ffffffff81425536>] device_del+0x136/0x1d0
[ 90.996863] [<ffffffff8149e0c0>] usb_disable_device+0xb0/0x290
[ 90.996923] [<ffffffff814930c5>] usb_disconnect+0xb5/0x1d0
[ 90.996984] [<ffffffff81495ab6>] hub_port_connect_change+0xd6/0xad0
[ 90.997044] [<ffffffff814967c3>] hub_events+0x313/0x9b0
[ 90.997105] [<ffffffff81496e95>] hub_thread+0x35/0x170
[ 90.997165] [<ffffffff8108ea2f>] kthread+0xff/0x120
[ 90.997226] [<ffffffff816b187c>] ret_from_fork+0x7c/0xb0
[ 90.997287]
[ 90.997287] other info that might help us debug this:
[ 90.997287]
[ 90.997318] Possible unsafe locking scenario:
[ 90.997318]
[ 90.997348] CPU0 CPU1
[ 90.997378] ---- ----
[ 90.997408] lock(&dev->lock);
[ 90.997497] lock(&card->controls_rwsem);
[ 90.997607] lock(&dev->lock);
[ 90.997697] lock(&card->controls_rwsem);
[ 90.997786]
[ 90.997786] *** DEADLOCK ***
[ 90.997786]
[ 90.997817] 5 locks held by khubd/54:
[ 90.997847] #0: (&__lockdep_no_validate__){......}, at: [<ffffffff81496564>] hub_events+0xb4/0x9b0
[ 90.998025] #1: (&__lockdep_no_validate__){......}, at: [<ffffffff81493076>] usb_disconnect+0x66/0x1d0
[ 90.998204] #2: (&__lockdep_no_validate__){......}, at: [<ffffffff8142929d>] device_release_driver+0x1d/0x40
[ 90.998383] #3: (em28xx_devlist_mutex){+.+.+.}, at: [<ffffffffa040db77>] em28xx_close_extension+0x27/0x90 [em28xx]
[ 90.998567] #4: (&dev->lock){+.+.+.}, at: [<ffffffffa040db81>] em28xx_close_extension+0x31/0x90 [em28xx]

Reviewed-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Tested-by: Antti Palosaari <crope@iki.fi>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# aa929ad7 12-Jan-2014 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] em28xx: print a message at disconnect

That helps to identify if something fails and explain why em28xx
struct is not freed (if it ever happens).

Reviewed-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Tested-by: Antti Palosaari <crope@iki.fi>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# e847022a 12-Jan-2014 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx-v4l: fix the freeing of the video devices memory

Remove some dead code from em28xx_v4l2_fini() and fix the leaking of the video,
vbi and radio video_device struct memories.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 5a620c7c 12-Jan-2014 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: always call em28xx_release_resources() in the usb disconnect handler

When the usb device is disconnected, the resources are no longer available,
so there is no reason to keep them registered.

This will also fix the various sysfs group removal warnings which we can see
since kernel 3.13.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# f188da43 12-Jan-2014 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx-v4l: move v4l2_ctrl_handler freeing and v4l2_device unregistration to em28xx_v4l2_fini

v4l2_ctrl_handler_free() and v4l2_device_unregister() are currently only called
when the last user closes the device and the device is already disconnected.
But that's wrong, we need to call these functions whenever the em28xx-v4l
extension is closed and we can already do this if the device is still opened
by some users.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 25dd1652 12-Jan-2014 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: move v4l2 dummy clock deregistration from the core to the v4l extension

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 5ad10de6 12-Jan-2014 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: move v4l2_device_disconnect() call from the core to the v4l extension

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 23e8642c 12-Jan-2014 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: move usb transfer uninit on device disconnect from the core to the v4l-extension

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 4e170240 12-Jan-2014 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx-v4l: fix device initialization in em28xx_v4l2_open() for radio and VBI mode

- bail out on unsupported VFL_TYPE
- em28xx_set_mode() needs to be called for VBI and radio mode, too
- em28xx_wake_i2c() needs to be called for VBI and radio mode, too
- em28xx_resolution_set() also needs to be called for VBI

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# ee97207c 12-Jan-2014 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] em28xx: fix xc3028 demod and firmware setup on DVB

Now that em28xx can be compiled without V4L support, we should
call em28xx_setup_xc3028() on both em28xx-v4l and em28xx-dvb
modules.

Reported-by: Chris Lee <updatelee@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 822b8dea 06-Jan-2014 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] em28xx: prevent registering wrong interfaces for audio-only

A few devices (em2860) use a separate interface for audio only
Audio Vendor Class USB. That interface should not be used by
Remote Controller, Analog TV or Digital TV.

Prevents initializing all non-audio extensions for the audio
only interface.

Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# d8992b09 27-Dec-2013 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] em28xx: unify module version

Use the same module version on all em28xx sub-modules, and use
the same naming convention to describe the driver.

Reviewed-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 9634614f 25-Dec-2013 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] em28xx: improve extension information messages

Add a message with consistent prints before and after each
extension initialization, and provide a better text for module
load.

While here, add a missing sanity check for extension finish
code at em28xx-v4l extension.

Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 01c28193 22-Dec-2013 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] em28xx: make em28xx-video to be a separate module

Now that all analog-specific code are at em28xx-video, convert
it into an em28xx extension and load it as a separate module.

Reviewed-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Tested-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# b64f8e9a 22-Dec-2013 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] em28xx: move analog-specific init to em28xx-video

There are several init code inside em28xx-cards that are actually
part of analog initialization. Move the code to em28x-video, in
order to remove part of the mess.

In thesis, no functional changes so far.

Reviewed-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# ce67943e 22-Dec-2013 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] em28xx: some cosmetic changes

In order to make easier for the next patches, do some
cosmetic changes.

No functional changes.

Reviewed-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 0560f337 22-Dec-2013 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] em28xx: move some video-specific functions to em28xx-video

Now that we want to split the video handling to a separate
module, move all video-specific functions to em28xx-video.

No functional changes.

Reviewed-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# bdee6bdb 06-Nov-2013 Ricardo Ribalda <ribalda@kernel.org>

[media] em28xx-video: Swap release order to avoid lock nesting

vb2_fop_release might take the video queue mutex lock.
In order to avoid nesting mutexes the private mutex is taken after the
fop_release has finished.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 98c24dcd 06-Nov-2013 Ricardo Ribalda <ribalda@kernel.org>

[media] em28xx-video: Swap release order to avoid lock nesting

vb2_fop_release might take the video queue mutex lock.
In order to avoid nesting mutexes the private mutex is taken after the
fop_release has finished.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 032f1ddf 10-Oct-2013 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: fix error path in em28xx_start_analog_streaming()

Increase the streaming_users count only if streaming start succeeds.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 51dd4d70 16-Jul-2013 Alban Browaeys <alban.browaeys@gmail.com>

[media] em28xx: Fix vidioc fmt vid cap v4l2 compliance

Set fmt.pix.priv to zero in vidioc_try_fmt_vid_cap.
Catched by v4l2-compliance.

Signed-off-by: Alban Browaeys <prahal@yahoo.com>
[hans.verkuil@cisco.com: dropping unnecessary change to g_fmt_vid_cap]
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>

Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# abca2056 29-May-2013 Hans Verkuil <hans.verkuil@cisco.com>

[media] v4l2: remove g_chip_ident from bridge drivers where it is easy to do so

VIDIOC_DBG_G_CHIP_IDENT has been replaced by VIDIOC_DBG_G_CHIP_INFO. Remove
g_chip_ident support from bridge drivers since it is no longer needed.
This patch takes care of all the trivial cases.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Acked-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
Acked-by: Scott Jiang <scott.jiang.linux@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 430c73fa 16-Apr-2013 Michal Marek <mmarek@suse.cz>

[media] em28xx: Put remaining .vidioc_g_chip_info instance under ADV_DEBUG

Commit cd634f1 ("[media] v4l2: put VIDIOC_DBG_G_CHIP_NAME under
ADV_DEBUG") missed the initializer of radio_ioctl_ops:
drivers/media/usb/em28xx/em28xx-video.c:1830:2: error: unknown field 'vidioc_g_chip_info' specified in initializer
drivers/media/usb/em28xx/em28xx-video.c:1830:26: error: 'vidioc_g_chip_info' undeclared here (not in a function)

Signed-off-by: Michal Marek <mmarek@suse.cz>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 96b03d2a 06-Apr-2013 Hans Verkuil <hans.verkuil@cisco.com>

[media] v4l2: rename VIDIOC_DBG_G_CHIP_NAME to _CHIP_INFO

This ioctl will be extended to return more information than just the name.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# cd634f1b 27-Mar-2013 Hans Verkuil <hans.verkuil@cisco.com>

[media] v4l2: put VIDIOC_DBG_G_CHIP_NAME under ADV_DEBUG

Only enable this ioctl if the VIDEO_ADV_DEBUG config option is set. This
prevents abuse from both userspace and kernelspace (some bridge drivers
abuse DBG_G_CHIP_IDENT, lets prevent that from happening again with this
ioctl).

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 46f85978 30-Mar-2013 Hans Verkuil <hverkuil@xs4all.nl>

[media] em28xx: fix typo in scale_to_size()

em28xx: fix typo in scale_to_size().
The second hscale should be vscale. This bug caused xawtv to fail because it
cannot find a workable image size.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Acked-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# e507e0e5 26-Mar-2013 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: add support for em25xx/em276x/em277x/em278x frame data processing

The em25xx/em276x/em277x/em278x frame data format is different to the one used
by the em2710/em2750/em28xx chips.
With the recent cleanups and reorganization of the frame data processing code it
can be easily extended to support these devices.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 3b2d17b4 17-Mar-2013 Hans Verkuil <hans.verkuil@cisco.com>

[media] em28xx: add support for g_chip_name

Add support for vidioc_g_chip_name, allowing AC97 to be implemented as a
second chip on the bridge with the name "ac97". v4l2-dbg can just match the
name with that string in order to detect a ac97-compliant set of registers.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 977ba3b1 24-Mar-2013 Hans Verkuil <hans.verkuil@cisco.com>

[media] v4l2: add const to argument of write-only s_register ioctl

This ioctl is defined as IOW, so pass the argument as const.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Acked-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Acked-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 314527ac 15-Mar-2013 Hans Verkuil <hans.verkuil@cisco.com>

[media] v4l2: pass std by value to the write-only s_std ioctl

This ioctl is defined as IOW, so pass the argument by value instead of by
reference. I could have chosen to add const instead, but this is 1) easier
to handle in drivers and 2) consistent with the s_std subdev operation.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Jonathan Corbet <corbet@lwn.net>
Acked-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Acked-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 2f73c7c5 15-Mar-2013 Hans Verkuil <hans.verkuil@cisco.com>

[media] v4l2: add const to argument of write-only s_tuner ioctl

This ioctl is defined as IOW, so pass the argument as const.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Alexey Klimov <klimov.linux@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# b530a447 19-Mar-2013 Hans Verkuil <hans.verkuil@cisco.com>

[media] v4l2: add const to argument of write-only s_frequency ioctl

This ioctl is defined as IOW, so pass the argument as const.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 195281d0 09-Mar-2013 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: set the timestamp type for video and vbi vb2_queues

The em28xx driver obtains the timestamps using function v4l2_get_timestamp(),
which produces a montonic timestamp.
Fixes the warnings appearing in the system log since commit 6aa69f99
"[media] vb2: Add support for non monotonic timestamps"

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 43a20d79 11-Feb-2013 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: bump driver version to 0.2.0

The em28xx driver has changed much, especially since kernel 3.8.
So it's time to bump the driver version.
Changes since kernel 3.8:
- converted the driver to videobuf2
- converted the driver to the v4l2-ctrl framework
- added USB bulk transfer support
- use USB bulk transfers by default for webcams (allows streaming from multiple devices at the same time)
- added image quality bridge controls: contrast, brightness, saturation, blue balance, red balance, sharpness
- removed dependency from module ir-kbd-i2c
- cleaned up the frame data processing code
- removed some unused/obsolete code
- made remote controls of devices with external (i2c) receiver/decoder work again
- fixed audio over USB for device "Terratec Cinergy 250"
- several v4l2 compliance fixes and improvements (including fixes for ioctls enabling/disabling)
- lots of further bug fixes and code improvements

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 8f8b113a 15-Feb-2013 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: add image quality bridge controls

Add the image quality bridge controls contrast, brightness, saturation,
blue balance, red balance and sharpness.
These controls are enabled only if no subdevice provides them.
Tested with the following devices:
"Terratec Cinergy 200 USB"
"Hauppauge HVR-900"
"SilverCrest 1.3MPix webcam"
"Hauppauge WinTV USB2"
"Speedlink VAD Laplace webcam"

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 6c3598e6 10-Feb-2013 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: VIDIOC_ENUM_FRAMESIZES: consider the scaler limits when calculating the minimum frame size

Output resolutions <=20% of the input resolution exceed the capabilities of the
scaler.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# b8374138 10-Feb-2013 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: add function scale_to_size()

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 6b09a21c 10-Feb-2013 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: rename function get_scale() to size_to_scale()

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 81685327 10-Feb-2013 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: introduce #define for maximum supported scaling values (register 0x30-0x33)

The maximum supported scaling value for registers 0x30+0x31 (horizontal scaling)
and 0x32+0x33 (vertical scaling) is 0x3fff, which corresponds to 20% of the
input frame size.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# fff459e3 07-Feb-2013 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: make ioctl VIDIOC_DBG_G_CHIP_IDENT available for radio devices

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 35deba32 07-Feb-2013 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: make ioctl VIDIOC_DBG_G_CHIP_IDENT available without CONFIG_VIDEO_ADV_DEBUG selected

VIDIOC_DBG_G_CHIP_IDENT is a "normal" and not an "advanced" debug functionality.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# eb17cee2 07-Feb-2013 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: remove obsolete device state checks from the ioctl functions

v4l2_device_disconnect() is called when the device is disconnected, so that the
v4l2-core rejects all ioctl calls.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 7a92de6a 07-Feb-2013 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: VIDIOC_G_TUNER: remove unneeded setting of tuner type

The tuner type is set by the v4l2-core based on the device type.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# aab34618 07-Feb-2013 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: get rid of duplicate function vidioc_s_fmt_vbi_cap()

vidioc_s_fmt_vbi_cap() is a 100% duplicate of vidioc_g_fmt_vbi_cap() and
therefore can be removed.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 430101bd 07-Feb-2013 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: remove ioctl VIDIOC_CROPCAP

The em28xx driver doesn't support the VIDIOC_G_CROP and VIDIOC_S_CROP ioctls,
so VIDIOC_CROPCAP is useless and has the potential to confuse applications,
because it can be interpreted as indicator for cropping support.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 1fe184a6 07-Feb-2013 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: make ioctls VIDIOC_G/S_PARM working for VBI devices

With the current code V4L2_BUF_TYPE_VIDEO_CAPTURE is accepted only, but for VBI
devices only buffer type V4L2_BUF_TYPE_VBI_CAPTURE is used/valid.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 83c8bcce 07-Feb-2013 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: disable ioctl VIDIOC_S_PARM for VBI devices

VIDIOC_S_PARM doesn't make sense for VBI device nodes, because we don't support
selecting the number of read buffers to use.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 3bc85cce 07-Feb-2013 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: use v4l2_disable_ioctl() to disable ioctl VIDIOC_S_PARM

Instead of checking the device type and returning -ENOTTY inside the ioctl
function, use v4l2_disable_ioctl() to disable the ioctl VIDIOC_S_PARM if the
device is not a camera.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# c2dcef83 07-Feb-2013 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: use v4l2_disable_ioctl() to disable ioctls VIDIOC_G_AUDIO and VIDIOC_S_AUDIO

Instead of checking the device type and returning -EINVAL inside the ioctl
functions, use v4l2_disable_ioctl() to disable the ioctls VIDIOC_G_AUDIO and
VIDIOC_S_AUDIO if the device doesn't support audio.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 66df67b7 07-Feb-2013 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: disable tuner related ioctls for video and VBI devices without tuner

Disable the ioctls VIDIOC_G_TUNER, VIDIOC_S_TUNER, VIDIOC_G_FREQUENCY and
VIDIOC_S_FREQUENCY for video and VBI devices without tuner.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 6e46daba 07-Feb-2013 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: use v4l2_disable_ioctl() to disable ioctls VIDIOC_QUERYSTD, VIDIOC_G/S_STD

Instead of checking the device type and returning -ENOTTY inside the ioctl
functions, use v4l2_disable_ioctl() to disable the ioctls VIDIOC_QUERYSTD,
VIDIOC_G_STD and VIDIOC_S_STD if the device is a camera.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# e6066dba 06-Feb-2013 Hans Verkuil <hans.verkuil@cisco.com>

[media] [REVIEW] em28xx: fix bytesperline calculation in TRY_FMT

The bytesperline calculation was incorrect: it used the old width instead of
the provided width. Fixed.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Acked-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# ef85cd9c 05-Jan-2013 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] em28xx: enable DMABUF

Now that it uses videobuf2, em28xx can support DMABUF.

Tested with an HVR-950 on analog mode and a 2gen i5core machine
with an i915 graphics adapter.

Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 3a799c27 04-Jan-2013 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] em28xx: declare em28xx_stop_streaming as static

That fixes the following warning:
drivers/media/usb/em28xx/em28xx-video.c:611:5: warning: no previous prototype for 'em28xx_stop_streaming' [-Wmissing-prototypes]

Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 2665c299 27-Dec-2012 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: simplify device state tracking

DEV_INITIALIZED of enum em28xx_dev_state state is used nowhere and there is no
need for DEV_MISCONFIGURED, so remove this enum and use a boolean field
'disconnected' in the device struct instead.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# d3829fad 04-Jan-2013 Devin Heitmueller <dheitmueller@kernellabs.com>

[media] em28xx: convert to videobuf2

This patch converts the em28xx driver over to videobuf2. It is
likely that em28xx_fh can go away entirely, but that will come in
a separate patch.

[mchehab@redhat.com: fix a non-trivial merge conflict with some VBI
patches; CodingStyle fixes]

Signed-off-by: Devin Heitmueller <dheitmueller@kernellabs.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 2a221d34 07-Sep-2012 Hans Verkuil <hans.verkuil@cisco.com>

[media] em28xx: zero vbi_format reserved array and add try_vbi_fmt

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Devin Heitmueller <dheitmueller@kernellabs.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 1d179eee 07-Sep-2012 Hans Verkuil <hans.verkuil@cisco.com>

[media] em28xx: remove sliced VBI support

The sliced VBI support in the tvp5150 is completely broken. And there is no
support for the saa7115 sliced VBI implementation in the em28xx driver. So
we remove the sliced VBI support completely.
It should be possible to get it to work with the tvp5150, but that will
require someone to really dig into that driver.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Devin Heitmueller <dheitmueller@kernellabs.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# d8c95c08 07-Sep-2012 Hans Verkuil <hans.verkuil@cisco.com>

[media] em28xx: std fixes: don't implement in webcam mode, and fix std changes

When in webcam mode the STD API shouldn't be implemented.
When changing the standard the resolution wasn't updated, and there was no
check against streaming-in-progress.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Devin Heitmueller <dheitmueller@kernellabs.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 86ff7f1d 07-Sep-2012 Hans Verkuil <hans.verkuil@cisco.com>

[media] em28xx: fill in readbuffers and fix incorrect return code

g/s_parm should fill in readbuffers.
For non-webcams s_parm should return -ENOTTY instead of -EINVAL.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Devin Heitmueller <dheitmueller@kernellabs.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 50fdf40f 07-Sep-2012 Hans Verkuil <hans.verkuil@cisco.com>

[media] em28xx: add support for control events

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Devin Heitmueller <dheitmueller@kernellabs.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 69a61642 07-Sep-2012 Hans Verkuil <hans.verkuil@cisco.com>

[media] em28xx: convert to v4l2_fh, fix priority handling

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Devin Heitmueller <dheitmueller@kernellabs.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 081b945e 07-Sep-2012 Hans Verkuil <hans.verkuil@cisco.com>

[media] em28xx: convert to the control framework

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Devin Heitmueller <dheitmueller@kernellabs.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 20deebfe 06-Sep-2012 Hans Verkuil <hans.verkuil@cisco.com>

[media] em28xx: fix tuner/frequency handling

v4l2-compliance found problems with frequency clamping that wasn't
reported correctly and missing tuner index checks.
Also removed unnecessary tuner type checks (these are now done by the
v4l2 core).

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Devin Heitmueller <dheitmueller@kernellabs.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 319a55fb 06-Sep-2012 Hans Verkuil <hans.verkuil@cisco.com>

[media] em28xx: fix VIDIOC_DBG_G_CHIP_IDENT compliance errors

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Devin Heitmueller <dheitmueller@kernellabs.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# dd5a4363 06-Sep-2012 Hans Verkuil <hans.verkuil@cisco.com>

[media] em28xx: remove bogus input/audio ioctls for the radio device

Radio devices should not implement those ioctls.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Devin Heitmueller <dheitmueller@kernellabs.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# a9d79fe5 06-Sep-2012 Hans Verkuil <hans.verkuil@cisco.com>

[media] em28xx: fix querycap

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Devin Heitmueller <dheitmueller@kernellabs.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 36016a35 08-Dec-2012 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: clean up and unify functions em28xx_copy_vbi() em28xx_copy_video()

The code in em28xx_vbi_copy can be simplified a lot.
Also rename some variables to something more meaningful and fix+add the
function descriptions.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 227b7c90 08-Dec-2012 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: move the em2710/em2750/em28xx specific frame data processing code to a separate function

em28xx_urb_data_copy() actually consists of two parts:
USB urb processing (checks, data extraction) and frame data packet processing.
Move the latter to a separate function and call it from em28xx_urb_data_copy()
for each data packet.
The em25xx, em2760, em2765 (and likely em277x) chip variants are using a
different frame data format, for which support will be added later with
another function.
This reduces the size of em28xx_urb_data_copy() and makes the code much more
readable. While we're at it, clean up the code a bit (rename some variables to
something more meaningful, improve some comments etc.)

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# e04c00d9 08-Dec-2012 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: em28xx_urb_data_copy(): move duplicate code for capture_type=0 and capture_type=2 to a function

Reduce code duplication by moving the duplicate code for dev->capture_type=0
(vbi start) and dev->capture_type=2 (video start) to a function.
The same function will also be called by the (not yet existing) em25xx frame
data processing code.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 4078d625 08-Dec-2012 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: move caching of pointer to vmalloc memory in videobuf to struct em28xx_buffer

In the current code em28xx_urb_data_copy() caches the pointer to the vmalloc
memory in videobuf locally.
The alternative would be to call videobuf_to_vmalloc() for each processed USB
data packet (isoc USB transfers => 64 times per URB) in the em28xx_copy_*()
functions.
With the next commits, the data processing code will be split into functions
for serveral reasons:
- em28xx_urb_data_copy() is generally way to long, making it less readable
- there is code duplication between VBI and video data processing
- support for em25xx data processing (uses a different header and frame
end signaling mechanism) will be added
This would require extensive usage of pointer-pointers, which usually makes the
code less readable and prone to bugs.
The better solution is to cache the pointer in struct em28xx_buffer.
This also improves consistency, because we already track the buffer fill count there.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# a4837015 08-Dec-2012 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: refactor VBI data processing code in em28xx_urb_data_copy()

When a new frame header is detected in em28xx_urb_data_copy() and the data
packet contains both, VBI data and video data, the prevoius VBI buffer doesn't
get finished and is overwritten with the new VBI data.
This bug is not triggered with isochronous USB transfers, because the data
packetes are much smaller than the VBI data size.
But when using USB bulk transfers, the whole data of an URB is treated as
single packet, which is usually much larger then the VBI data size.
Refactor the VBI data processing code to fix this bug, but also to simplify the
code and make it similar to the video data processing code part (which allows
further code abstraction/unification in the future).
The changes have been tested with device "Hauppauge HVR-900".

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 8732533b 08-Dec-2012 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: move field 'pos' from struct em28xx_dmaqueue to struct em28xx_buffer

This field is used to keep track of the current memory position in the buffer,
not in the dma queue, so move it to right place.
This also allows us to get rid of the struct em28xx_dmaqueue pointer parameter
in functions em28xx_copy_video() and em28xx_copy_vbi().

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 948a49aa 08-Dec-2012 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: use common function for video and vbi buffer completion

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 24a6d849 08-Dec-2012 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: refactor get_next_buf() and use it for vbi data, too

get_next_buf() and vbi_get_next_buf() do exactly the same just with a
different dma queue and buffer. Saving the new buffer pointer back to the
device struct in em28xx_urb_data_copy() instead of doing this from inside
these functions makes it possible to get rid of one of them.
Also refactor the function parameters and return type:
- pass a pointer to struct em28xx as parameter (instead of obtaining the
pointer from the dma queue pointer with the container_of macro) like we do
it in all other functions
- instead of using a pointer-pointer, return the pointer to the new buffer
as return value of the function

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 960da93b 25-Nov-2012 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: use common urb data copying function for vbi and non-vbi data streams

em28xx_urb_data_copy_vbi() is actually an extended version of
em28xx_urb_data_copy(). With the preceding fixes and improvements, it works
fine with both, vbi and non-vbi data streams without performance impacts.
So rename em28xx_urb_data_copy_vbi() to em28xx_urb_data_copy(), delete the
the old implementation of em28xx_urb_data_copy() and change the code to use
this function for both data stream types.
Tested with "SilverCrest 1.3 MPix webcam" (progressive, non-vbi) and
"Hauppauge HVR-900 (65008/A1C0)" (interlaced, vbi enabled and disabled).

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 79ff8697 25-Nov-2012 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: em28xx_urb_data_copy_vbi(): calculate vbi_size only if needed

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 0455eebf 25-Nov-2012 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: fix capture type setting in em28xx_urb_data_copy_vbi()

Set capture type to 1 (video start) when the video frame start header is
detected. This bug didn't cause any trouble, because this type of header is
never received in vbi mode.
Fix it, because we want to use this function with disabled vbi in the future.
Also start with capture type -1 to avoid processing of corrupted/incomplete
frame data which is usually received at streaming start (especially when
USB bulk transfers are used).

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 3610f58b 25-Nov-2012 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: make sure the packet size is >= 4 before checking for headers in em28xx_urb_data_copy_vbi()

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# b77e0c08 25-Nov-2012 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: fix video data start position calculation in em28xx_urb_data_copy_vbi()

The header check/removal code at the end of function em28xx_urb_data_copy_vbi()
is obsolete, because this is already done earlier in this function.
In fact it is incomplete (doesn't check for vbi header) and causes trouble
when the first data bytes are the same as header bytes (which is fortunately
very unlikely).

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# c647a91a 08-Nov-2012 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: improve USB endpoint logic, also use bulk transfers

The current enpoint logic ignores all bulk endpoints and uses
a fixed mapping between endpint addresses and the supported
data stream types (analog/audio/DVB):
Ep 0x82, isoc => analog
Ep 0x83, isoc => audio
Ep 0x84, isoc => DVB
Now that the code can also do bulk transfers, the endpoint
logic has to be extended to also consider bulk endpoints.
The new logic preserves backwards compatibility and reflects
the endpoint configurations we have seen so far:
Ep 0x82, isoc => analog
Ep 0x82, bulk => analog
Ep 0x83, isoc* => audio
Ep 0x84, isoc => digital
Ep 0x84, bulk => analog or digital**
(*: audio should always be isoc)
(**: analog, if ep 0x82 is isoc, otherwise digital)

[mchehab@redhat.com: Fix a CodingStyle issue: don't break strings
into separate lines]

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 0cf544a6 08-Nov-2012 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: rename some USB parameter fields in struct em28xx to clarify their role

Also improve the comments.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 4601cc39 08-Nov-2012 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: rename function em28xx_isoc_copy_vbi and extend for USB bulk transfers

The URB data processing for bulk transfers is very similar to what
is done with isoc transfers, so create a common function that works
with both transfer types based on the existing isoc function.

[mchehab@redhat.com: Fix a CodingStyle issue: don't break strings
into separate lines]

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 0fa4a402 08-Nov-2012 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: rename function em28xx_isoc_copy and extend for USB bulk transfers

The URB data processing for bulk transfers is very similar to what
is done with isoc transfers, so create a common function that works
with both transfer types based on the existing isoc function.

[mchehab@redhat.com: Fix a CodingStyle issue: don't break strings
into separate lines]

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 1653cb0c 08-Nov-2012 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: remove double checks for urb->status == -ENOENT in urb_data_copy functions

This check is already done in the URB handler
em28xx_irq_callback before calling these functions.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 057ca0da 08-Nov-2012 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: create a common function for isoc and bulk USB transfer initialization

- rename em28xx_init_isoc to em28xx_init_usb_xfer
- add parameter for isoc/bulk transfer selection which is passed to em28xx_alloc_urbs
- rename local variable isoc_buf to usb_bufs

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# afb177e0 08-Nov-2012 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: rename function em28xx_uninit_isoc to em28xx_uninit_usb_xfer

This function will be used to uninitialize USB bulk transfers, too.
Also rename the local variable isoc_bufs to usb_bufs.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 74209dc0 08-Nov-2012 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: rename struct em28xx_usb_isoc_ctl to em28xx_usb_ctl

Also rename the corresponding field isoc_ctl in struct em28xx
to usb_ctl.
We will use this struct for USB bulk transfers, too.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 515688a8 08-Nov-2012 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: rename isoc packet number constants and parameters

Rename EM28XX_NUM_PACKETS to EM28XX_NUM_ISOC_PACKETS and
EM28XX_DVB_MAX_PACKETS to EM28XX_DVB_NUM_ISOC_PACKETS to
clarify that these values are used only for isoc usb transfers.
Also use the term num_packets instead of max_packets, as this
is how these values are used and called in struct urb.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# c02ec71b 08-Nov-2012 Frank Schaefer <fschaefer.oss@googlemail.com>

[media] em28xx: fix wrong data offset for non-interlaced mode in em28xx_copy_video

em28xx_copy_video uses a wrong offset for the target buffer
when copying the data from an USB isoc packet. This happens
only for the second and all following lines in the packet.
The reason why this bug doesn't cause image corruption with
my test device (SilverCrest Webcam 1.3 MPix) is, that this
device never sends any packets that cross the end of a line.
I don't know if all devices behave like this, so this patch
should be considered for stable.
With the upcoming patches to add support for USB bulk transfers,
em28xx_copy_video will be called once per URB, which will
always trigger this bug.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 8e6057b5 15-Sep-2012 Sakari Ailus <sakari.ailus@linux.intel.com>

[media] v4l: Convert drivers to use monotonic timestamps

Convert drivers using wall clock time (CLOCK_REALTIME) to timestamp from the
monotonic timer (CLOCK_MONOTONIC).

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 0e8025b9 04-Sep-2012 Hans Verkuil <hans.verkuil@cisco.com>

[media] v4l2: make vidioc_s_audio const

Write-only ioctls should have a const argument in the ioctl op.
Do this conversion for vidioc_s_audio.
Adding const for write-only ioctls was decided during the 2012 Media Workshop.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# e36c92fd 13-Aug-2012 Dan Carpenter <dan.carpenter@oracle.com>

[media] em28xx: use after free in em28xx_v4l2_close()

We need to move the unlock before the kfree(dev);

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 0c0d06ca 13-Aug-2012 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] rename most media/video usb drivers to media/usb

Rename all USB drivers with their own directory under
drivers/media/video into drivers/media/usb and update the
building system.

Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>