Resguardo inicial

This commit is contained in:
lastdragon
2026-09-06 12:53:21 -06:00
parent 662efe3c2a
commit ad2088d178
94853 changed files with 43200404 additions and 0 deletions
@@ -0,0 +1,84 @@
# SPDX-License-Identifier: GPL-2.0-only
config VIDEO_EM28XX
tristate "Empia EM28xx USB devices support"
depends on VIDEO_DEV && I2C
select VIDEO_TUNER
select VIDEO_TVEEPROM
config VIDEO_EM28XX_V4L2
tristate "Empia EM28xx analog TV, video capture and/or webcam support"
depends on VIDEO_EM28XX
select VIDEOBUF2_VMALLOC
select VIDEO_SAA711X if MEDIA_SUBDRV_AUTOSELECT
select VIDEO_TVP5150 if MEDIA_SUBDRV_AUTOSELECT
select VIDEO_MSP3400 if MEDIA_SUBDRV_AUTOSELECT
select VIDEO_MT9V011 if MEDIA_SUBDRV_AUTOSELECT && VIDEO_CAMERA_SENSOR
select VIDEO_OV2640 if MEDIA_SUBDRV_AUTOSELECT && VIDEO_CAMERA_SENSOR
help
This is a video4linux driver for Empia 28xx based TV cards.
To compile this driver as a module, choose M here: the
module will be called em28xx
config VIDEO_EM28XX_ALSA
depends on VIDEO_EM28XX && SND
select SND_PCM
tristate "Empia EM28xx ALSA audio module"
help
This is an ALSA driver for some Empia 28xx based TV cards.
This is not required for em2800/em2820/em2821 boards. However,
newer em28xx devices uses Vendor Class for audio, instead of
implementing the USB Audio Class. For those chips, this module
will enable digital audio.
To compile this driver as a module, choose M here: the
module will be called em28xx-alsa
config VIDEO_EM28XX_DVB
tristate "DVB/ATSC Support for em28xx based TV cards"
depends on VIDEO_EM28XX && DVB_CORE
select DVB_LGDT330X if MEDIA_SUBDRV_AUTOSELECT
select DVB_LGDT3305 if MEDIA_SUBDRV_AUTOSELECT
select DVB_LGDT3306A if MEDIA_SUBDRV_AUTOSELECT
select DVB_ZL10353 if MEDIA_SUBDRV_AUTOSELECT
select DVB_TDA10023 if MEDIA_SUBDRV_AUTOSELECT
select DVB_S921 if MEDIA_SUBDRV_AUTOSELECT
select DVB_DRXD if MEDIA_SUBDRV_AUTOSELECT
select DVB_CXD2820R if MEDIA_SUBDRV_AUTOSELECT
select DVB_DRXK if MEDIA_SUBDRV_AUTOSELECT
select DVB_TDA18271C2DD if MEDIA_SUBDRV_AUTOSELECT
select DVB_TDA10071 if MEDIA_SUBDRV_AUTOSELECT
select DVB_A8293 if MEDIA_SUBDRV_AUTOSELECT
select DVB_MT352 if MEDIA_SUBDRV_AUTOSELECT
select DVB_S5H1409 if MEDIA_SUBDRV_AUTOSELECT
select DVB_MB86A20S if MEDIA_SUBDRV_AUTOSELECT
select MEDIA_TUNER_QT1010 if MEDIA_SUBDRV_AUTOSELECT
select MEDIA_TUNER_TDA18271 if MEDIA_SUBDRV_AUTOSELECT
select MEDIA_TUNER_TDA18212 if MEDIA_SUBDRV_AUTOSELECT
select DVB_M88DS3103 if MEDIA_SUBDRV_AUTOSELECT
select DVB_TS2020 if MEDIA_SUBDRV_AUTOSELECT
select DVB_DRX39XYJ if MEDIA_SUBDRV_AUTOSELECT
select DVB_SI2168 if MEDIA_SUBDRV_AUTOSELECT
select MEDIA_TUNER_SI2157 if MEDIA_SUBDRV_AUTOSELECT
select DVB_TC90522 if MEDIA_SUBDRV_AUTOSELECT
select MEDIA_TUNER_QM1D1C0042 if MEDIA_SUBDRV_AUTOSELECT
select MEDIA_TUNER_SIMPLE if MEDIA_SUBDRV_AUTOSELECT
select MEDIA_TUNER_XC2028 if MEDIA_SUBDRV_AUTOSELECT
select MEDIA_TUNER_XC5000 if MEDIA_SUBDRV_AUTOSELECT
select MEDIA_TUNER_MT2060 if MEDIA_SUBDRV_AUTOSELECT
select DVB_MXL692 if MEDIA_SUBDRV_AUTOSELECT
select GPIOLIB_LEGACY if GPIOLIB && DVB_CXD2820R
help
This adds support for DVB cards based on the
Empiatech em28xx chips.
config VIDEO_EM28XX_RC
tristate "EM28XX Remote Controller support"
depends on RC_CORE
depends on VIDEO_EM28XX
depends on !(RC_CORE=m && VIDEO_EM28XX=y)
default VIDEO_EM28XX
select BITREVERSE
help
Enables Remote Controller support on em28xx driver.
@@ -0,0 +1,15 @@
# SPDX-License-Identifier: GPL-2.0
em28xx-y += em28xx-core.o em28xx-i2c.o em28xx-cards.o em28xx-camera.o
em28xx-v4l-objs := em28xx-video.o em28xx-vbi.o
em28xx-alsa-objs := em28xx-audio.o
em28xx-rc-objs := em28xx-input.o
obj-$(CONFIG_VIDEO_EM28XX) += em28xx.o
obj-$(CONFIG_VIDEO_EM28XX_V4L2) += em28xx-v4l.o
obj-$(CONFIG_VIDEO_EM28XX_ALSA) += em28xx-alsa.o
obj-$(CONFIG_VIDEO_EM28XX_DVB) += em28xx-dvb.o
obj-$(CONFIG_VIDEO_EM28XX_RC) += em28xx-rc.o
ccflags-y += -I $(srctree)/drivers/media/tuners
ccflags-y += -I $(srctree)/drivers/media/dvb-frontends
@@ -0,0 +1,975 @@
// SPDX-License-Identifier: GPL-2.0+
//
// Empiatech em28x1 audio extension
//
// Copyright (C) 2006 Markus Rechberger <mrechberger@gmail.com>
//
// Copyright (C) 2007-2016 Mauro Carvalho Chehab
// - Port to work with the in-kernel driver
// - Cleanups, fixes, alsa-controls, etc.
//
// This driver is based on my previous au600 usb pstn audio driver
// and inherits all the copyrights
#include "em28xx.h"
#include <linux/kernel.h>
#include <linux/usb.h>
#include <linux/init.h>
#include <linux/sound.h>
#include <linux/spinlock.h>
#include <linux/soundcard.h>
#include <linux/slab.h>
#include <linux/module.h>
#include <sound/core.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
#include <sound/info.h>
#include <sound/initval.h>
#include <sound/control.h>
#include <sound/tlv.h>
#include <sound/ac97_codec.h>
#include <media/v4l2-common.h>
static int debug;
module_param(debug, int, 0644);
MODULE_PARM_DESC(debug, "activates debug info");
#define EM28XX_MAX_AUDIO_BUFS 5
#define EM28XX_MIN_AUDIO_PACKETS 64
#define dprintk(fmt, arg...) do { \
if (debug) \
dev_printk(KERN_DEBUG, &dev->intf->dev, \
"video: %s: " fmt, __func__, ## arg); \
} while (0)
static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
static int em28xx_deinit_isoc_audio(struct em28xx *dev)
{
int i;
dprintk("Stopping isoc\n");
for (i = 0; i < dev->adev.num_urb; i++) {
struct urb *urb = dev->adev.urb[i];
if (!irqs_disabled())
usb_kill_urb(urb);
else
usb_unlink_urb(urb);
}
return 0;
}
static void em28xx_audio_isocirq(struct urb *urb)
{
struct em28xx *dev = urb->context;
int i;
unsigned int oldptr;
int period_elapsed = 0;
int status;
unsigned char *cp;
unsigned int stride;
struct snd_pcm_substream *substream;
struct snd_pcm_runtime *runtime;
if (dev->disconnected) {
dprintk("device disconnected while streaming. URB status=%d.\n",
urb->status);
atomic_set(&dev->adev.stream_started, 0);
return;
}
switch (urb->status) {
case 0: /* success */
case -ETIMEDOUT: /* NAK */
break;
case -ECONNRESET: /* kill */
case -ENOENT:
case -ESHUTDOWN:
return;
default: /* error */
dprintk("urb completion error %d.\n", urb->status);
break;
}
if (atomic_read(&dev->adev.stream_started) == 0)
return;
if (dev->adev.capture_pcm_substream) {
substream = dev->adev.capture_pcm_substream;
runtime = substream->runtime;
stride = runtime->frame_bits >> 3;
for (i = 0; i < urb->number_of_packets; i++) {
unsigned long flags;
int length =
urb->iso_frame_desc[i].actual_length / stride;
cp = (unsigned char *)urb->transfer_buffer +
urb->iso_frame_desc[i].offset;
if (!length)
continue;
oldptr = dev->adev.hwptr_done_capture;
if (oldptr + length >= runtime->buffer_size) {
unsigned int cnt =
runtime->buffer_size - oldptr;
memcpy(runtime->dma_area + oldptr * stride, cp,
cnt * stride);
memcpy(runtime->dma_area, cp + cnt * stride,
length * stride - cnt * stride);
} else {
memcpy(runtime->dma_area + oldptr * stride, cp,
length * stride);
}
snd_pcm_stream_lock_irqsave(substream, flags);
dev->adev.hwptr_done_capture += length;
if (dev->adev.hwptr_done_capture >=
runtime->buffer_size)
dev->adev.hwptr_done_capture -=
runtime->buffer_size;
dev->adev.capture_transfer_done += length;
if (dev->adev.capture_transfer_done >=
runtime->period_size) {
dev->adev.capture_transfer_done -=
runtime->period_size;
period_elapsed = 1;
}
snd_pcm_stream_unlock_irqrestore(substream, flags);
}
if (period_elapsed)
snd_pcm_period_elapsed(substream);
}
urb->status = 0;
status = usb_submit_urb(urb, GFP_ATOMIC);
if (status < 0)
dev_err(&dev->intf->dev,
"resubmit of audio urb failed (error=%i)\n",
status);
}
static int em28xx_init_audio_isoc(struct em28xx *dev)
{
int i, err;
dprintk("Starting isoc transfers\n");
/* Start streaming */
for (i = 0; i < dev->adev.num_urb; i++) {
memset(dev->adev.transfer_buffer[i], 0x80,
dev->adev.urb[i]->transfer_buffer_length);
err = usb_submit_urb(dev->adev.urb[i], GFP_ATOMIC);
if (err) {
dev_err(&dev->intf->dev,
"submit of audio urb failed (error=%i)\n",
err);
em28xx_deinit_isoc_audio(dev);
atomic_set(&dev->adev.stream_started, 0);
return err;
}
}
return 0;
}
static const struct snd_pcm_hardware snd_em28xx_hw_capture = {
.info = SNDRV_PCM_INFO_BLOCK_TRANSFER |
SNDRV_PCM_INFO_MMAP |
SNDRV_PCM_INFO_INTERLEAVED |
SNDRV_PCM_INFO_BATCH |
SNDRV_PCM_INFO_MMAP_VALID,
.formats = SNDRV_PCM_FMTBIT_S16_LE,
.rates = SNDRV_PCM_RATE_48000,
.rate_min = 48000,
.rate_max = 48000,
.channels_min = 2,
.channels_max = 2,
.buffer_bytes_max = 62720 * 8, /* just about the value in usbaudio.c */
/*
* The period is 12.288 bytes. Allow a 10% of variation along its
* value, in order to avoid overruns/underruns due to some clock
* drift.
*
* FIXME: This period assumes 64 packets, and a 48000 PCM rate.
* Calculate it dynamically.
*/
.period_bytes_min = 11059,
.period_bytes_max = 13516,
.periods_min = 2,
.periods_max = 98, /* 12544, */
};
static int snd_em28xx_capture_open(struct snd_pcm_substream *substream)
{
struct em28xx *dev = snd_pcm_substream_chip(substream);
struct snd_pcm_runtime *runtime = substream->runtime;
int nonblock, ret = 0;
if (!dev) {
pr_err("em28xx-audio: BUG: em28xx can't find device struct. Can't proceed with open\n");
return -ENODEV;
}
if (dev->disconnected)
return -ENODEV;
dprintk("opening device and trying to acquire exclusive lock\n");
nonblock = !!(substream->f_flags & O_NONBLOCK);
if (nonblock) {
if (!mutex_trylock(&dev->lock))
return -EAGAIN;
} else {
mutex_lock(&dev->lock);
}
runtime->hw = snd_em28xx_hw_capture;
if (dev->adev.users == 0) {
if (!dev->alt || dev->is_audio_only) {
struct usb_device *udev;
udev = interface_to_usbdev(dev->intf);
if (dev->is_audio_only)
/* audio is on a separate interface */
dev->alt = 1;
else
/* audio is on the same interface as video */
dev->alt = 7;
/*
* FIXME: The intention seems to be to select
* the alt setting with the largest
* wMaxPacketSize for the video endpoint.
* At least dev->alt should be used instead, but
* we should probably not touch it at all if it
* is already >0, because wMaxPacketSize of the
* audio endpoints seems to be the same for all.
*/
dprintk("changing alternate number on interface %d to %d\n",
dev->ifnum, dev->alt);
usb_set_interface(udev, dev->ifnum, dev->alt);
}
/* Sets volume, mute, etc */
dev->mute = 0;
ret = em28xx_audio_analog_set(dev);
if (ret < 0)
goto err;
}
kref_get(&dev->ref);
dev->adev.users++;
mutex_unlock(&dev->lock);
/* Dynamically adjust the period size */
snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
dev->adev.period * 95 / 100,
dev->adev.period * 105 / 100);
dev->adev.capture_pcm_substream = substream;
return 0;
err:
mutex_unlock(&dev->lock);
dev_err(&dev->intf->dev,
"Error while configuring em28xx mixer\n");
return ret;
}
static int snd_em28xx_pcm_close(struct snd_pcm_substream *substream)
{
struct em28xx *dev = snd_pcm_substream_chip(substream);
dprintk("closing device\n");
dev->mute = 1;
mutex_lock(&dev->lock);
dev->adev.users--;
if (atomic_read(&dev->adev.stream_started) > 0) {
atomic_set(&dev->adev.stream_started, 0);
schedule_work(&dev->adev.wq_trigger);
}
em28xx_audio_analog_set(dev);
mutex_unlock(&dev->lock);
kref_put(&dev->ref, em28xx_free_device);
return 0;
}
static int snd_em28xx_prepare(struct snd_pcm_substream *substream)
{
struct em28xx *dev = snd_pcm_substream_chip(substream);
if (dev->disconnected)
return -ENODEV;
dev->adev.hwptr_done_capture = 0;
dev->adev.capture_transfer_done = 0;
return 0;
}
static void audio_trigger(struct work_struct *work)
{
struct em28xx_audio *adev =
container_of(work, struct em28xx_audio, wq_trigger);
struct em28xx *dev = container_of(adev, struct em28xx, adev);
if (atomic_read(&adev->stream_started)) {
dprintk("starting capture");
em28xx_init_audio_isoc(dev);
} else {
dprintk("stopping capture");
em28xx_deinit_isoc_audio(dev);
}
}
static int snd_em28xx_capture_trigger(struct snd_pcm_substream *substream,
int cmd)
{
struct em28xx *dev = snd_pcm_substream_chip(substream);
int retval = 0;
if (dev->disconnected)
return -ENODEV;
switch (cmd) {
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
case SNDRV_PCM_TRIGGER_RESUME:
case SNDRV_PCM_TRIGGER_START:
atomic_set(&dev->adev.stream_started, 1);
break;
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
case SNDRV_PCM_TRIGGER_SUSPEND:
case SNDRV_PCM_TRIGGER_STOP:
atomic_set(&dev->adev.stream_started, 0);
break;
default:
retval = -EINVAL;
}
schedule_work(&dev->adev.wq_trigger);
return retval;
}
static snd_pcm_uframes_t snd_em28xx_capture_pointer(struct snd_pcm_substream
*substream)
{
unsigned long flags;
struct em28xx *dev;
snd_pcm_uframes_t hwptr_done;
dev = snd_pcm_substream_chip(substream);
if (dev->disconnected)
return SNDRV_PCM_POS_XRUN;
spin_lock_irqsave(&dev->adev.slock, flags);
hwptr_done = dev->adev.hwptr_done_capture;
spin_unlock_irqrestore(&dev->adev.slock, flags);
return hwptr_done;
}
/*
* AC97 volume control support
*/
static int em28xx_vol_info(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_info *info)
{
struct em28xx *dev = snd_kcontrol_chip(kcontrol);
if (dev->disconnected)
return -ENODEV;
info->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
info->count = 2;
info->value.integer.min = 0;
info->value.integer.max = 0x1f;
return 0;
}
static int em28xx_vol_put(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *value)
{
struct em28xx *dev = snd_kcontrol_chip(kcontrol);
struct snd_pcm_substream *substream = dev->adev.capture_pcm_substream;
u16 val = (0x1f - (value->value.integer.value[0] & 0x1f)) |
(0x1f - (value->value.integer.value[1] & 0x1f)) << 8;
int nonblock = 0;
int rc;
if (dev->disconnected)
return -ENODEV;
if (substream)
nonblock = !!(substream->f_flags & O_NONBLOCK);
if (nonblock) {
if (!mutex_trylock(&dev->lock))
return -EAGAIN;
} else {
mutex_lock(&dev->lock);
}
rc = em28xx_read_ac97(dev, kcontrol->private_value);
if (rc < 0)
goto err;
val |= rc & 0x8000; /* Preserve the mute flag */
rc = em28xx_write_ac97(dev, kcontrol->private_value, val);
if (rc < 0)
goto err;
dprintk("%sleft vol %d, right vol %d (0x%04x) to ac97 volume control 0x%04x\n",
(val & 0x8000) ? "muted " : "",
0x1f - ((val >> 8) & 0x1f), 0x1f - (val & 0x1f),
val, (int)kcontrol->private_value);
err:
mutex_unlock(&dev->lock);
return rc;
}
static int em28xx_vol_get(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *value)
{
struct em28xx *dev = snd_kcontrol_chip(kcontrol);
struct snd_pcm_substream *substream = dev->adev.capture_pcm_substream;
int nonblock = 0;
int val;
if (dev->disconnected)
return -ENODEV;
if (substream)
nonblock = !!(substream->f_flags & O_NONBLOCK);
if (nonblock) {
if (!mutex_trylock(&dev->lock))
return -EAGAIN;
} else {
mutex_lock(&dev->lock);
}
val = em28xx_read_ac97(dev, kcontrol->private_value);
mutex_unlock(&dev->lock);
if (val < 0)
return val;
dprintk("%sleft vol %d, right vol %d (0x%04x) from ac97 volume control 0x%04x\n",
(val & 0x8000) ? "muted " : "",
0x1f - ((val >> 8) & 0x1f), 0x1f - (val & 0x1f),
val, (int)kcontrol->private_value);
value->value.integer.value[0] = 0x1f - (val & 0x1f);
value->value.integer.value[1] = 0x1f - ((val >> 8) & 0x1f);
return 0;
}
static int em28xx_vol_put_mute(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *value)
{
struct em28xx *dev = snd_kcontrol_chip(kcontrol);
u16 val = value->value.integer.value[0];
struct snd_pcm_substream *substream = dev->adev.capture_pcm_substream;
int nonblock = 0;
int rc;
if (dev->disconnected)
return -ENODEV;
if (substream)
nonblock = !!(substream->f_flags & O_NONBLOCK);
if (nonblock) {
if (!mutex_trylock(&dev->lock))
return -EAGAIN;
} else {
mutex_lock(&dev->lock);
}
rc = em28xx_read_ac97(dev, kcontrol->private_value);
if (rc < 0)
goto err;
if (val)
rc &= 0x1f1f;
else
rc |= 0x8000;
rc = em28xx_write_ac97(dev, kcontrol->private_value, rc);
if (rc < 0)
goto err;
dprintk("%sleft vol %d, right vol %d (0x%04x) to ac97 volume control 0x%04x\n",
(val & 0x8000) ? "muted " : "",
0x1f - ((val >> 8) & 0x1f), 0x1f - (val & 0x1f),
val, (int)kcontrol->private_value);
err:
mutex_unlock(&dev->lock);
return rc;
}
static int em28xx_vol_get_mute(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *value)
{
struct em28xx *dev = snd_kcontrol_chip(kcontrol);
struct snd_pcm_substream *substream = dev->adev.capture_pcm_substream;
int nonblock = 0;
int val;
if (dev->disconnected)
return -ENODEV;
if (substream)
nonblock = !!(substream->f_flags & O_NONBLOCK);
if (nonblock) {
if (!mutex_trylock(&dev->lock))
return -EAGAIN;
} else {
mutex_lock(&dev->lock);
}
val = em28xx_read_ac97(dev, kcontrol->private_value);
mutex_unlock(&dev->lock);
if (val < 0)
return val;
if (val & 0x8000)
value->value.integer.value[0] = 0;
else
value->value.integer.value[0] = 1;
dprintk("%sleft vol %d, right vol %d (0x%04x) from ac97 volume control 0x%04x\n",
(val & 0x8000) ? "muted " : "",
0x1f - ((val >> 8) & 0x1f), 0x1f - (val & 0x1f),
val, (int)kcontrol->private_value);
return 0;
}
static const DECLARE_TLV_DB_SCALE(em28xx_db_scale, -3450, 150, 0);
static int em28xx_cvol_new(struct snd_card *card, struct em28xx *dev,
char *name, int id)
{
int err;
char ctl_name[44];
struct snd_kcontrol *kctl;
struct snd_kcontrol_new tmp;
memset(&tmp, 0, sizeof(tmp));
tmp.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
tmp.private_value = id;
tmp.name = ctl_name;
/* Add Mute Control */
sprintf(ctl_name, "%s Switch", name);
tmp.get = em28xx_vol_get_mute;
tmp.put = em28xx_vol_put_mute;
tmp.info = snd_ctl_boolean_mono_info;
kctl = snd_ctl_new1(&tmp, dev);
err = snd_ctl_add(card, kctl);
if (err < 0)
return err;
dprintk("Added control %s for ac97 volume control 0x%04x\n",
ctl_name, id);
memset(&tmp, 0, sizeof(tmp));
tmp.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
tmp.private_value = id;
tmp.name = ctl_name;
/* Add Volume Control */
sprintf(ctl_name, "%s Volume", name);
tmp.get = em28xx_vol_get;
tmp.put = em28xx_vol_put;
tmp.info = em28xx_vol_info;
tmp.tlv.p = em28xx_db_scale;
kctl = snd_ctl_new1(&tmp, dev);
err = snd_ctl_add(card, kctl);
if (err < 0)
return err;
dprintk("Added control %s for ac97 volume control 0x%04x\n",
ctl_name, id);
return 0;
}
/*
* register/unregister code and data
*/
static const struct snd_pcm_ops snd_em28xx_pcm_capture = {
.open = snd_em28xx_capture_open,
.close = snd_em28xx_pcm_close,
.prepare = snd_em28xx_prepare,
.trigger = snd_em28xx_capture_trigger,
.pointer = snd_em28xx_capture_pointer,
};
static void em28xx_audio_free_urb(struct em28xx *dev)
{
struct usb_device *udev = interface_to_usbdev(dev->intf);
int i;
for (i = 0; i < dev->adev.num_urb; i++) {
struct urb *urb = dev->adev.urb[i];
if (!urb)
continue;
usb_free_coherent(udev, urb->transfer_buffer_length,
dev->adev.transfer_buffer[i],
urb->transfer_dma);
usb_free_urb(urb);
}
kfree(dev->adev.urb);
kfree(dev->adev.transfer_buffer);
dev->adev.num_urb = 0;
}
/* high bandwidth multiplier, as encoded in highspeed endpoint descriptors */
static int em28xx_audio_ep_packet_size(struct usb_device *udev,
struct usb_endpoint_descriptor *e)
{
int size = le16_to_cpu(e->wMaxPacketSize);
if (udev->speed == USB_SPEED_HIGH)
return (size & 0x7ff) * (1 + (((size) >> 11) & 0x03));
return size & 0x7ff;
}
static int em28xx_audio_urb_init(struct em28xx *dev)
{
struct usb_interface *intf;
struct usb_endpoint_descriptor *e, *ep = NULL;
struct usb_device *udev = interface_to_usbdev(dev->intf);
int i, ep_size, interval, num_urb, npackets;
int urb_size, bytes_per_transfer;
u8 alt;
if (dev->ifnum)
alt = 1;
else
alt = 7;
intf = usb_ifnum_to_if(udev, dev->ifnum);
if (intf->num_altsetting <= alt) {
dev_err(&dev->intf->dev, "alt %d doesn't exist on interface %d\n",
dev->ifnum, alt);
return -ENODEV;
}
for (i = 0; i < intf->altsetting[alt].desc.bNumEndpoints; i++) {
e = &intf->altsetting[alt].endpoint[i].desc;
if (!usb_endpoint_dir_in(e))
continue;
if (e->bEndpointAddress == EM28XX_EP_AUDIO) {
ep = e;
break;
}
}
if (!ep) {
dev_err(&dev->intf->dev, "Couldn't find an audio endpoint");
return -ENODEV;
}
ep_size = em28xx_audio_ep_packet_size(udev, ep);
interval = 1 << (ep->bInterval - 1);
dev_info(&dev->intf->dev,
"Endpoint 0x%02x %s on intf %d alt %d interval = %d, size %d\n",
EM28XX_EP_AUDIO, usb_speed_string(udev->speed),
dev->ifnum, alt, interval, ep_size);
/* Calculate the number and size of URBs to better fit the audio samples */
/*
* Estimate the number of bytes per DMA transfer.
*
* This is given by the bit rate (for now, only 48000 Hz) multiplied
* by 2 channels and 2 bytes/sample divided by the number of microframe
* intervals and by the microframe rate (125 us)
*/
bytes_per_transfer = DIV_ROUND_UP(48000 * 2 * 2, 125 * interval);
/*
* Estimate the number of transfer URBs. Don't let it go past the
* maximum number of URBs that is known to be supported by the device.
*/
num_urb = DIV_ROUND_UP(bytes_per_transfer, ep_size);
if (num_urb > EM28XX_MAX_AUDIO_BUFS)
num_urb = EM28XX_MAX_AUDIO_BUFS;
/*
* Now that we know the number of bytes per transfer and the number of
* URBs, estimate the typical size of an URB, in order to adjust the
* minimal number of packets.
*/
urb_size = bytes_per_transfer / num_urb;
/*
* Now, calculate the amount of audio packets to be filled on each
* URB. In order to preserve the old behaviour, use a minimal
* threshold for this value.
*/
npackets = EM28XX_MIN_AUDIO_PACKETS;
if (urb_size > ep_size * npackets)
npackets = DIV_ROUND_UP(urb_size, ep_size);
dev_info(&dev->intf->dev,
"Number of URBs: %d, with %d packets and %d size\n",
num_urb, npackets, urb_size);
/* Estimate the bytes per period */
dev->adev.period = urb_size * npackets;
/* Allocate space to store the number of URBs to be used */
dev->adev.transfer_buffer = kcalloc(num_urb,
sizeof(*dev->adev.transfer_buffer),
GFP_KERNEL);
if (!dev->adev.transfer_buffer)
return -ENOMEM;
dev->adev.urb = kzalloc_objs(*dev->adev.urb, num_urb);
if (!dev->adev.urb) {
kfree(dev->adev.transfer_buffer);
return -ENOMEM;
}
/* Alloc memory for each URB and for each transfer buffer */
dev->adev.num_urb = num_urb;
for (i = 0; i < num_urb; i++) {
struct urb *urb;
int j, k;
void *buf;
urb = usb_alloc_urb(npackets, GFP_KERNEL);
if (!urb) {
em28xx_audio_free_urb(dev);
return -ENOMEM;
}
dev->adev.urb[i] = urb;
buf = usb_alloc_coherent(udev, npackets * ep_size, GFP_KERNEL,
&urb->transfer_dma);
if (!buf) {
dev_err(&dev->intf->dev,
"usb_alloc_coherent failed!\n");
em28xx_audio_free_urb(dev);
return -ENOMEM;
}
dev->adev.transfer_buffer[i] = buf;
urb->dev = udev;
urb->context = dev;
urb->pipe = usb_rcvisocpipe(udev, EM28XX_EP_AUDIO);
urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
urb->transfer_buffer = buf;
urb->interval = interval;
urb->complete = em28xx_audio_isocirq;
urb->number_of_packets = npackets;
urb->transfer_buffer_length = ep_size * npackets;
for (j = k = 0; j < npackets; j++, k += ep_size) {
urb->iso_frame_desc[j].offset = k;
urb->iso_frame_desc[j].length = ep_size;
}
}
return 0;
}
static int em28xx_audio_init(struct em28xx *dev)
{
struct em28xx_audio *adev = &dev->adev;
struct usb_device *udev = interface_to_usbdev(dev->intf);
struct snd_pcm *pcm;
struct snd_card *card;
static int devnr;
int err;
if (dev->usb_audio_type != EM28XX_USB_AUDIO_VENDOR) {
/*
* This device does not support the extension (in this case
* the device is expecting the snd-usb-audio module or
* doesn't have analog audio support at all)
*/
return 0;
}
dev_info(&dev->intf->dev, "Binding audio extension\n");
kref_get(&dev->ref);
dev_info(&dev->intf->dev,
"em28xx-audio.c: Copyright (C) 2006 Markus Rechberger\n");
dev_info(&dev->intf->dev,
"em28xx-audio.c: Copyright (C) 2007-2016 Mauro Carvalho Chehab\n");
err = snd_card_new(&dev->intf->dev, index[devnr], "Em28xx Audio",
THIS_MODULE, 0, &card);
if (err < 0)
return err;
spin_lock_init(&adev->slock);
adev->sndcard = card;
adev->udev = udev;
err = snd_pcm_new(card, "Em28xx Audio", 0, 0, 1, &pcm);
if (err < 0)
goto card_free;
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_em28xx_pcm_capture);
snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_VMALLOC, NULL, 0, 0);
pcm->info_flags = 0;
pcm->private_data = dev;
strscpy(pcm->name, "Empia 28xx Capture", sizeof(pcm->name));
strscpy(card->driver, "Em28xx-Audio", sizeof(card->driver));
strscpy(card->shortname, "Em28xx Audio", sizeof(card->shortname));
strscpy(card->longname, "Empia Em28xx Audio", sizeof(card->longname));
INIT_WORK(&adev->wq_trigger, audio_trigger);
if (dev->audio_mode.ac97 != EM28XX_NO_AC97) {
em28xx_cvol_new(card, dev, "Video", AC97_VIDEO);
em28xx_cvol_new(card, dev, "Line In", AC97_LINE);
em28xx_cvol_new(card, dev, "Phone", AC97_PHONE);
em28xx_cvol_new(card, dev, "Microphone", AC97_MIC);
em28xx_cvol_new(card, dev, "CD", AC97_CD);
em28xx_cvol_new(card, dev, "AUX", AC97_AUX);
em28xx_cvol_new(card, dev, "PCM", AC97_PCM);
em28xx_cvol_new(card, dev, "Master", AC97_MASTER);
em28xx_cvol_new(card, dev, "Line", AC97_HEADPHONE);
em28xx_cvol_new(card, dev, "Mono", AC97_MASTER_MONO);
em28xx_cvol_new(card, dev, "LFE", AC97_CENTER_LFE_MASTER);
em28xx_cvol_new(card, dev, "Surround", AC97_SURROUND_MASTER);
}
err = em28xx_audio_urb_init(dev);
if (err)
goto card_free;
err = snd_card_register(card);
if (err < 0)
goto urb_free;
dev_info(&dev->intf->dev, "Audio extension successfully initialized\n");
return 0;
urb_free:
em28xx_audio_free_urb(dev);
card_free:
snd_card_free(card);
adev->sndcard = NULL;
return err;
}
static int em28xx_audio_fini(struct em28xx *dev)
{
if (!dev)
return 0;
if (dev->usb_audio_type != EM28XX_USB_AUDIO_VENDOR) {
/*
* This device does not support the extension (in this case
* the device is expecting the snd-usb-audio module or
* doesn't have analog audio support at all)
*/
return 0;
}
dev_info(&dev->intf->dev, "Closing audio extension\n");
if (dev->adev.sndcard) {
snd_card_disconnect(dev->adev.sndcard);
flush_work(&dev->adev.wq_trigger);
em28xx_audio_free_urb(dev);
snd_card_free(dev->adev.sndcard);
dev->adev.sndcard = NULL;
}
kref_put(&dev->ref, em28xx_free_device);
return 0;
}
static int em28xx_audio_suspend(struct em28xx *dev)
{
if (!dev)
return 0;
if (dev->usb_audio_type != EM28XX_USB_AUDIO_VENDOR)
return 0;
dev_info(&dev->intf->dev, "Suspending audio extension\n");
em28xx_deinit_isoc_audio(dev);
atomic_set(&dev->adev.stream_started, 0);
return 0;
}
static int em28xx_audio_resume(struct em28xx *dev)
{
if (!dev)
return 0;
if (dev->usb_audio_type != EM28XX_USB_AUDIO_VENDOR)
return 0;
dev_info(&dev->intf->dev, "Resuming audio extension\n");
/* Nothing to do other than schedule_work() ?? */
schedule_work(&dev->adev.wq_trigger);
return 0;
}
static struct em28xx_ops audio_ops = {
.id = EM28XX_AUDIO,
.name = "Em28xx Audio Extension",
.init = em28xx_audio_init,
.fini = em28xx_audio_fini,
.suspend = em28xx_audio_suspend,
.resume = em28xx_audio_resume,
};
static int __init em28xx_alsa_register(void)
{
return em28xx_register_extension(&audio_ops);
}
static void __exit em28xx_alsa_unregister(void)
{
em28xx_unregister_extension(&audio_ops);
}
MODULE_LICENSE("GPL v2");
MODULE_AUTHOR("Markus Rechberger <mrechberger@gmail.com>");
MODULE_AUTHOR("Mauro Carvalho Chehab");
MODULE_DESCRIPTION(DRIVER_DESC " - audio interface");
MODULE_VERSION(EM28XX_VERSION);
module_init(em28xx_alsa_register);
module_exit(em28xx_alsa_unregister);
@@ -0,0 +1,412 @@
// SPDX-License-Identifier: GPL-2.0+
//
// em28xx-camera.c - driver for Empia EM25xx/27xx/28xx USB video capture devices
//
// Copyright (C) 2009 Mauro Carvalho Chehab <mchehab@kernel.org>
// Copyright (C) 2013 Frank Schäfer <fschaefer.oss@googlemail.com>
#include "em28xx.h"
#include <linux/i2c.h>
#include <linux/usb.h>
#include <media/i2c/mt9v011.h>
#include <media/v4l2-common.h>
/* Possible i2c addresses of Micron sensors */
static unsigned short micron_sensor_addrs[] = {
0xb8 >> 1, /* MT9V111, MT9V403 */
0xba >> 1, /* MT9M001/011/111/112, MT9V011/012/112, MT9D011 */
0x90 >> 1, /* MT9V012/112, MT9D011 (alternative address) */
I2C_CLIENT_END
};
/* Possible i2c addresses of Omnivision sensors */
static unsigned short omnivision_sensor_addrs[] = {
0x42 >> 1, /* OV7725, OV7670/60/48 */
0x60 >> 1, /* OV2640, OV9650/53/55 */
I2C_CLIENT_END
};
/* FIXME: Should be replaced by a proper mt9m111 driver */
static int em28xx_initialize_mt9m111(struct em28xx *dev)
{
int i;
unsigned char regs[][3] = {
{ 0x0d, 0x00, 0x01, }, /* reset and use defaults */
{ 0x0d, 0x00, 0x00, },
{ 0x0a, 0x00, 0x21, },
{ 0x21, 0x04, 0x00, }, /* full readout spd, no row/col skip */
};
for (i = 0; i < ARRAY_SIZE(regs); i++)
i2c_master_send(&dev->i2c_client[dev->def_i2c_bus],
&regs[i][0], 3);
/* FIXME: This won't be creating a sensor at the media graph */
return 0;
}
/* FIXME: Should be replaced by a proper mt9m001 driver */
static int em28xx_initialize_mt9m001(struct em28xx *dev)
{
int i;
unsigned char regs[][3] = {
{ 0x0d, 0x00, 0x01, },
{ 0x0d, 0x00, 0x00, },
{ 0x04, 0x05, 0x00, }, /* hres = 1280 */
{ 0x03, 0x04, 0x00, }, /* vres = 1024 */
{ 0x20, 0x11, 0x00, },
{ 0x06, 0x00, 0x10, },
{ 0x2b, 0x00, 0x24, },
{ 0x2e, 0x00, 0x24, },
{ 0x35, 0x00, 0x24, },
{ 0x2d, 0x00, 0x20, },
{ 0x2c, 0x00, 0x20, },
{ 0x09, 0x0a, 0xd4, },
{ 0x35, 0x00, 0x57, },
};
for (i = 0; i < ARRAY_SIZE(regs); i++)
i2c_master_send(&dev->i2c_client[dev->def_i2c_bus],
&regs[i][0], 3);
/* FIXME: This won't be creating a sensor at the media graph */
return 0;
}
/*
* Probes Micron sensors with 8 bit address and 16 bit register width
*/
static int em28xx_probe_sensor_micron(struct em28xx *dev)
{
int ret, i;
char *name;
u16 id;
struct i2c_client *client = &dev->i2c_client[dev->def_i2c_bus];
dev->em28xx_sensor = EM28XX_NOSENSOR;
for (i = 0; micron_sensor_addrs[i] != I2C_CLIENT_END; i++) {
client->addr = micron_sensor_addrs[i];
/* Read chip ID from register 0x00 */
ret = i2c_smbus_read_word_data(client, 0x00); /* assumes LE */
if (ret < 0) {
if (ret != -ENXIO)
dev_err(&dev->intf->dev,
"couldn't read from i2c device 0x%02x: error %i\n",
client->addr << 1, ret);
continue;
}
id = swab16(ret); /* LE -> BE */
/* Read chip ID from register 0xff */
ret = i2c_smbus_read_word_data(client, 0xff);
if (ret < 0) {
dev_err(&dev->intf->dev,
"couldn't read from i2c device 0x%02x: error %i\n",
client->addr << 1, ret);
continue;
}
/* Validate chip ID to be sure we have a Micron device */
if (id != swab16(ret))
continue;
/* Check chip ID */
switch (id) {
case 0x1222:
name = "MT9V012"; /* MI370 */ /* 640x480 */
break;
case 0x1229:
name = "MT9V112"; /* 640x480 */
break;
case 0x1433:
name = "MT9M011"; /* 1280x1024 */
break;
case 0x143a: /* found in the ECS G200 */
name = "MT9M111"; /* MI1310 */ /* 1280x1024 */
dev->em28xx_sensor = EM28XX_MT9M111;
break;
case 0x148c:
name = "MT9M112"; /* MI1320 */ /* 1280x1024 */
break;
case 0x1511:
name = "MT9D011"; /* MI2010 */ /* 1600x1200 */
break;
case 0x8232:
case 0x8243: /* rev B */
name = "MT9V011"; /* MI360 */ /* 640x480 */
dev->em28xx_sensor = EM28XX_MT9V011;
break;
case 0x8431:
name = "MT9M001"; /* 1280x1024 */
dev->em28xx_sensor = EM28XX_MT9M001;
break;
default:
dev_info(&dev->intf->dev,
"unknown Micron sensor detected: 0x%04x\n",
id);
return 0;
}
if (dev->em28xx_sensor == EM28XX_NOSENSOR)
dev_info(&dev->intf->dev,
"unsupported sensor detected: %s\n", name);
else
dev_info(&dev->intf->dev,
"sensor %s detected\n", name);
return 0;
}
return -ENODEV;
}
/*
* Probes Omnivision sensors with 8 bit address and register width
*/
static int em28xx_probe_sensor_omnivision(struct em28xx *dev)
{
int ret, i;
char *name;
u8 reg;
u16 id;
struct i2c_client *client = &dev->i2c_client[dev->def_i2c_bus];
dev->em28xx_sensor = EM28XX_NOSENSOR;
/*
* NOTE: these devices have the register auto incrementation disabled
* by default, so we have to use single byte reads !
*/
for (i = 0; omnivision_sensor_addrs[i] != I2C_CLIENT_END; i++) {
client->addr = omnivision_sensor_addrs[i];
/* Read manufacturer ID from registers 0x1c-0x1d (BE) */
reg = 0x1c;
ret = i2c_smbus_read_byte_data(client, reg);
if (ret < 0) {
if (ret != -ENXIO)
dev_err(&dev->intf->dev,
"couldn't read from i2c device 0x%02x: error %i\n",
client->addr << 1, ret);
continue;
}
id = ret << 8;
reg = 0x1d;
ret = i2c_smbus_read_byte_data(client, reg);
if (ret < 0) {
dev_err(&dev->intf->dev,
"couldn't read from i2c device 0x%02x: error %i\n",
client->addr << 1, ret);
continue;
}
id += ret;
/* Check manufacturer ID */
if (id != 0x7fa2)
continue;
/* Read product ID from registers 0x0a-0x0b (BE) */
reg = 0x0a;
ret = i2c_smbus_read_byte_data(client, reg);
if (ret < 0) {
dev_err(&dev->intf->dev,
"couldn't read from i2c device 0x%02x: error %i\n",
client->addr << 1, ret);
continue;
}
id = ret << 8;
reg = 0x0b;
ret = i2c_smbus_read_byte_data(client, reg);
if (ret < 0) {
dev_err(&dev->intf->dev,
"couldn't read from i2c device 0x%02x: error %i\n",
client->addr << 1, ret);
continue;
}
id += ret;
/* Check product ID */
switch (id) {
case 0x2642:
name = "OV2640";
dev->em28xx_sensor = EM28XX_OV2640;
break;
case 0x7648:
name = "OV7648";
break;
case 0x7660:
name = "OV7660";
break;
case 0x7673:
name = "OV7670";
break;
case 0x7720:
name = "OV7720";
break;
case 0x7721:
name = "OV7725";
break;
case 0x9648: /* Rev 2 */
case 0x9649: /* Rev 3 */
name = "OV9640";
break;
case 0x9650:
case 0x9652: /* OV9653 */
name = "OV9650";
break;
case 0x9656: /* Rev 4 */
case 0x9657: /* Rev 5 */
name = "OV9655";
break;
default:
dev_info(&dev->intf->dev,
"unknown OmniVision sensor detected: 0x%04x\n",
id);
return 0;
}
if (dev->em28xx_sensor == EM28XX_NOSENSOR)
dev_info(&dev->intf->dev,
"unsupported sensor detected: %s\n", name);
else
dev_info(&dev->intf->dev,
"sensor %s detected\n", name);
return 0;
}
return -ENODEV;
}
int em28xx_detect_sensor(struct em28xx *dev)
{
int ret;
ret = em28xx_probe_sensor_micron(dev);
if (dev->em28xx_sensor == EM28XX_NOSENSOR && ret < 0)
ret = em28xx_probe_sensor_omnivision(dev);
/*
* NOTE: the Windows driver also probes i2c addresses
* 0x22 (Samsung ?) and 0x66 (Kodak ?)
*/
if (dev->em28xx_sensor == EM28XX_NOSENSOR && ret < 0) {
dev_info(&dev->intf->dev,
"No sensor detected\n");
return -ENODEV;
}
return 0;
}
int em28xx_init_camera(struct em28xx *dev)
{
struct i2c_client *client = &dev->i2c_client[dev->def_i2c_bus];
struct i2c_adapter *adap = &dev->i2c_adap[dev->def_i2c_bus];
struct em28xx_v4l2 *v4l2 = dev->v4l2;
switch (dev->em28xx_sensor) {
case EM28XX_MT9V011:
{
struct mt9v011_platform_data pdata;
struct i2c_board_info mt9v011_info = {
.type = "mt9v011",
.addr = client->addr,
.platform_data = &pdata,
};
v4l2->sensor_xres = 640;
v4l2->sensor_yres = 480;
/*
* FIXME: mt9v011 uses I2S speed as xtal clk - at least with
* the Silvercrest cam I have here for testing - for higher
* resolutions, a high clock cause horizontal artifacts, so we
* need to use a lower xclk frequency.
* Yet, it would be possible to adjust xclk depending on the
* desired resolution, since this affects directly the
* frame rate.
*/
dev->board.xclk = EM28XX_XCLK_FREQUENCY_4_3MHZ;
em28xx_write_reg(dev, EM28XX_R0F_XCLK, dev->board.xclk);
v4l2->sensor_xtal = 4300000;
pdata.xtal = v4l2->sensor_xtal;
if (NULL ==
v4l2_i2c_new_subdev_board(&v4l2->v4l2_dev, adap,
&mt9v011_info, NULL))
return -ENODEV;
v4l2->vinmode = EM28XX_VINMODE_RGB8_GRBG;
v4l2->vinctl = 0x00;
break;
}
case EM28XX_MT9M001:
v4l2->sensor_xres = 1280;
v4l2->sensor_yres = 1024;
em28xx_initialize_mt9m001(dev);
v4l2->vinmode = EM28XX_VINMODE_RGB8_BGGR;
v4l2->vinctl = 0x00;
break;
case EM28XX_MT9M111:
v4l2->sensor_xres = 640;
v4l2->sensor_yres = 512;
dev->board.xclk = EM28XX_XCLK_FREQUENCY_48MHZ;
em28xx_write_reg(dev, EM28XX_R0F_XCLK, dev->board.xclk);
em28xx_initialize_mt9m111(dev);
v4l2->vinmode = EM28XX_VINMODE_YUV422_UYVY;
v4l2->vinctl = 0x00;
break;
case EM28XX_OV2640:
{
struct v4l2_subdev *subdev;
struct i2c_board_info ov2640_info = {
.type = "ov2640",
.flags = I2C_CLIENT_SCCB,
.addr = client->addr,
};
struct v4l2_subdev_format format = {
.which = V4L2_SUBDEV_FORMAT_ACTIVE,
};
/*
* FIXME: sensor supports resolutions up to 1600x1200, but
* resolution setting/switching needs to be modified to
* - switch sensor output resolution (including further
* configuration changes)
* - adjust bridge xclk
* - disable 16 bit (12 bit) output formats on high resolutions
*/
v4l2->sensor_xres = 640;
v4l2->sensor_yres = 480;
subdev =
v4l2_i2c_new_subdev_board(&v4l2->v4l2_dev, adap,
&ov2640_info, NULL);
if (!subdev)
return -ENODEV;
format.format.code = MEDIA_BUS_FMT_YUYV8_2X8;
format.format.width = 640;
format.format.height = 480;
v4l2_subdev_call(subdev, pad, set_fmt, NULL, &format);
/* NOTE: for UXGA=1600x1200 switch to 12MHz */
dev->board.xclk = EM28XX_XCLK_FREQUENCY_24MHZ;
em28xx_write_reg(dev, EM28XX_R0F_XCLK, dev->board.xclk);
v4l2->vinmode = EM28XX_VINMODE_YUV422_YUYV;
v4l2->vinctl = 0x00;
break;
}
case EM28XX_NOSENSOR:
default:
return -EINVAL;
}
return 0;
}
EXPORT_SYMBOL_GPL(em28xx_init_camera);
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,934 @@
// SPDX-License-Identifier: GPL-2.0+
//
// handle em28xx IR remotes via linux kernel input layer.
//
// Copyright (C) 2005 Ludovico Cavedon <cavedon@sssup.it>
// Markus Rechberger <mrechberger@gmail.com>
// Mauro Carvalho Chehab <mchehab@kernel.org>
// Sascha Sommer <saschasommer@freenet.de>
#include "em28xx.h"
#include <linux/module.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/interrupt.h>
#include <linux/usb.h>
#include <linux/usb/input.h>
#include <linux/slab.h>
#include <linux/bitrev.h>
#define EM28XX_SNAPSHOT_KEY KEY_CAMERA
#define EM28XX_BUTTONS_DEBOUNCED_QUERY_INTERVAL 500 /* [ms] */
#define EM28XX_BUTTONS_VOLATILE_QUERY_INTERVAL 100 /* [ms] */
static unsigned int ir_debug;
module_param(ir_debug, int, 0644);
MODULE_PARM_DESC(ir_debug, "enable debug messages [IR]");
#define MODULE_NAME "em28xx"
#define dprintk(fmt, arg...) do { \
if (ir_debug) \
dev_printk(KERN_DEBUG, &ir->dev->intf->dev, \
"input: %s: " fmt, __func__, ## arg); \
} while (0)
/*
* Polling structure used by em28xx IR's
*/
struct em28xx_ir_poll_result {
unsigned int toggle_bit:1;
unsigned int read_count:7;
enum rc_proto protocol;
u32 scancode;
};
struct em28xx_IR {
struct em28xx *dev;
struct rc_dev *rc;
char phys[32];
/* poll decoder */
int polling;
struct delayed_work work;
unsigned int full_code:1;
unsigned int last_readcount;
u64 rc_proto;
struct i2c_client *i2c_client;
int (*get_key_i2c)(struct i2c_client *ir, enum rc_proto *protocol,
u32 *scancode);
int (*get_key)(struct em28xx_IR *ir, struct em28xx_ir_poll_result *r);
};
/*
* I2C IR based get keycodes - should be used with ir-kbd-i2c
*/
static int em28xx_get_key_terratec(struct i2c_client *i2c_dev,
enum rc_proto *protocol, u32 *scancode)
{
int rc;
unsigned char b;
/* poll IR chip */
rc = i2c_master_recv(i2c_dev, &b, 1);
if (rc != 1) {
if (rc < 0)
return rc;
return -EIO;
}
/*
* it seems that 0xFE indicates that a button is still hold
* down, while 0xff indicates that no button is hold down.
*/
if (b == 0xff)
return 0;
if (b == 0xfe)
/* keep old data */
return 1;
*protocol = RC_PROTO_UNKNOWN;
*scancode = b;
return 1;
}
static int em28xx_get_key_em_haup(struct i2c_client *i2c_dev,
enum rc_proto *protocol, u32 *scancode)
{
unsigned char buf[2];
int size;
/* poll IR chip */
size = i2c_master_recv(i2c_dev, buf, sizeof(buf));
if (size != 2)
return -EIO;
/* Does eliminate repeated parity code */
if (buf[1] == 0xff)
return 0;
/*
* Rearranges bits to the right order.
* The bit order were determined experimentally by using
* The original Hauppauge Grey IR and another RC5 that uses addr=0x08
* The RC5 code has 14 bits, but we've experimentally determined
* the meaning for only 11 bits.
* So, the code translation is not complete. Yet, it is enough to
* work with the provided RC5 IR.
*/
*protocol = RC_PROTO_RC5;
*scancode = (bitrev8(buf[1]) & 0x1f) << 8 | bitrev8(buf[0]) >> 2;
return 1;
}
static int em28xx_get_key_pinnacle_usb_grey(struct i2c_client *i2c_dev,
enum rc_proto *protocol,
u32 *scancode)
{
unsigned char buf[3];
/* poll IR chip */
if (i2c_master_recv(i2c_dev, buf, 3) != 3)
return -EIO;
if (buf[0] != 0x00)
return 0;
*protocol = RC_PROTO_UNKNOWN;
*scancode = buf[2] & 0x3f;
return 1;
}
static int em28xx_get_key_winfast_usbii_deluxe(struct i2c_client *i2c_dev,
enum rc_proto *protocol,
u32 *scancode)
{
unsigned char subaddr, keydetect, key;
struct i2c_msg msg[] = {
{
.addr = i2c_dev->addr,
.flags = 0,
.buf = &subaddr, .len = 1
}, {
.addr = i2c_dev->addr,
.flags = I2C_M_RD,
.buf = &keydetect,
.len = 1
}
};
subaddr = 0x10;
if (i2c_transfer(i2c_dev->adapter, msg, 2) != 2)
return -EIO;
if (keydetect == 0x00)
return 0;
subaddr = 0x00;
msg[1].buf = &key;
if (i2c_transfer(i2c_dev->adapter, msg, 2) != 2)
return -EIO;
if (key == 0x00)
return 0;
*protocol = RC_PROTO_UNKNOWN;
*scancode = key;
return 1;
}
/*
* Poll based get keycode functions
*/
/* This is for the em2860/em2880 */
static int default_polling_getkey(struct em28xx_IR *ir,
struct em28xx_ir_poll_result *poll_result)
{
struct em28xx *dev = ir->dev;
int rc;
u8 msg[3] = { 0, 0, 0 };
/*
* Read key toggle, brand, and key code
* on registers 0x45, 0x46 and 0x47
*/
rc = dev->em28xx_read_reg_req_len(dev, 0, EM28XX_R45_IR,
msg, sizeof(msg));
if (rc < 0)
return rc;
/* Infrared toggle (Reg 0x45[7]) */
poll_result->toggle_bit = (msg[0] >> 7);
/* Infrared read count (Reg 0x45[6:0] */
poll_result->read_count = (msg[0] & 0x7f);
/* Remote Control Address/Data (Regs 0x46/0x47) */
switch (ir->rc_proto) {
case RC_PROTO_BIT_RC5:
poll_result->protocol = RC_PROTO_RC5;
poll_result->scancode = RC_SCANCODE_RC5(msg[1], msg[2]);
break;
case RC_PROTO_BIT_NEC:
poll_result->protocol = RC_PROTO_NEC;
poll_result->scancode = RC_SCANCODE_NEC(msg[1], msg[2]);
break;
default:
poll_result->protocol = RC_PROTO_UNKNOWN;
poll_result->scancode = msg[1] << 8 | msg[2];
break;
}
return 0;
}
static int em2874_polling_getkey(struct em28xx_IR *ir,
struct em28xx_ir_poll_result *poll_result)
{
struct em28xx *dev = ir->dev;
int rc;
u8 msg[5] = { 0, 0, 0, 0, 0 };
/*
* Read key toggle, brand, and key code
* on registers 0x51-55
*/
rc = dev->em28xx_read_reg_req_len(dev, 0, EM2874_R51_IR,
msg, sizeof(msg));
if (rc < 0)
return rc;
/* Infrared toggle (Reg 0x51[7]) */
poll_result->toggle_bit = (msg[0] >> 7);
/* Infrared read count (Reg 0x51[6:0] */
poll_result->read_count = (msg[0] & 0x7f);
/*
* Remote Control Address (Reg 0x52)
* Remote Control Data (Reg 0x53-0x55)
*/
switch (ir->rc_proto) {
case RC_PROTO_BIT_RC5:
poll_result->protocol = RC_PROTO_RC5;
poll_result->scancode = RC_SCANCODE_RC5(msg[1], msg[2]);
break;
case RC_PROTO_BIT_NEC:
poll_result->scancode = ir_nec_bytes_to_scancode(msg[1], msg[2], msg[3], msg[4],
&poll_result->protocol);
break;
case RC_PROTO_BIT_RC6_0:
poll_result->protocol = RC_PROTO_RC6_0;
poll_result->scancode = RC_SCANCODE_RC6_0(msg[1], msg[2]);
break;
default:
poll_result->protocol = RC_PROTO_UNKNOWN;
poll_result->scancode = (msg[1] << 24) | (msg[2] << 16) |
(msg[3] << 8) | msg[4];
break;
}
return 0;
}
/*
* Polling code for em28xx
*/
static int em28xx_i2c_ir_handle_key(struct em28xx_IR *ir)
{
static u32 scancode;
enum rc_proto protocol;
int rc;
rc = ir->get_key_i2c(ir->i2c_client, &protocol, &scancode);
if (rc < 0) {
dprintk("ir->get_key_i2c() failed: %d\n", rc);
return rc;
}
if (rc) {
dprintk("%s: proto = 0x%04x, scancode = 0x%04x\n",
__func__, protocol, scancode);
rc_keydown(ir->rc, protocol, scancode, 0);
}
return 0;
}
static void em28xx_ir_handle_key(struct em28xx_IR *ir)
{
int result;
struct em28xx_ir_poll_result poll_result;
/* read the registers containing the IR status */
result = ir->get_key(ir, &poll_result);
if (unlikely(result < 0)) {
dprintk("ir->get_key() failed: %d\n", result);
return;
}
if (unlikely(poll_result.read_count != ir->last_readcount)) {
dprintk("%s: toggle: %d, count: %d, key 0x%04x\n", __func__,
poll_result.toggle_bit, poll_result.read_count,
poll_result.scancode);
if (ir->full_code)
rc_keydown(ir->rc,
poll_result.protocol,
poll_result.scancode,
poll_result.toggle_bit);
else
rc_keydown(ir->rc,
RC_PROTO_UNKNOWN,
poll_result.scancode & 0xff,
poll_result.toggle_bit);
if (ir->dev->chip_id == CHIP_ID_EM2874 ||
ir->dev->chip_id == CHIP_ID_EM2884)
/*
* The em2874 clears the readcount field every time the
* register is read. The em2860/2880 datasheet says
* that it is supposed to clear the readcount, but it
* doesn't. So with the em2874, we are looking for a
* non-zero read count as opposed to a readcount
* that is incrementing
*/
ir->last_readcount = 0;
else
ir->last_readcount = poll_result.read_count;
}
}
static void em28xx_ir_work(struct work_struct *work)
{
struct em28xx_IR *ir = container_of(work, struct em28xx_IR, work.work);
if (ir->i2c_client) /* external i2c device */
em28xx_i2c_ir_handle_key(ir);
else /* internal device */
em28xx_ir_handle_key(ir);
schedule_delayed_work(&ir->work, msecs_to_jiffies(ir->polling));
}
static int em28xx_ir_start(struct rc_dev *rc)
{
struct em28xx_IR *ir = rc->priv;
INIT_DELAYED_WORK(&ir->work, em28xx_ir_work);
schedule_delayed_work(&ir->work, 0);
return 0;
}
static void em28xx_ir_stop(struct rc_dev *rc)
{
struct em28xx_IR *ir = rc->priv;
cancel_delayed_work_sync(&ir->work);
}
static int em2860_ir_change_protocol(struct rc_dev *rc_dev, u64 *rc_proto)
{
struct em28xx_IR *ir = rc_dev->priv;
struct em28xx *dev = ir->dev;
/* Adjust xclk based on IR table for RC5/NEC tables */
if (*rc_proto & RC_PROTO_BIT_RC5) {
dev->board.xclk |= EM28XX_XCLK_IR_RC5_MODE;
ir->full_code = 1;
*rc_proto = RC_PROTO_BIT_RC5;
} else if (*rc_proto & RC_PROTO_BIT_NEC) {
dev->board.xclk &= ~EM28XX_XCLK_IR_RC5_MODE;
ir->full_code = 1;
*rc_proto = RC_PROTO_BIT_NEC;
} else if (*rc_proto & RC_PROTO_BIT_UNKNOWN) {
*rc_proto = RC_PROTO_BIT_UNKNOWN;
} else {
*rc_proto = ir->rc_proto;
return -EINVAL;
}
em28xx_write_reg_bits(dev, EM28XX_R0F_XCLK, dev->board.xclk,
EM28XX_XCLK_IR_RC5_MODE);
ir->rc_proto = *rc_proto;
return 0;
}
static int em2874_ir_change_protocol(struct rc_dev *rc_dev, u64 *rc_proto)
{
struct em28xx_IR *ir = rc_dev->priv;
struct em28xx *dev = ir->dev;
u8 ir_config = EM2874_IR_RC5;
/* Adjust xclk and set type based on IR table for RC5/NEC/RC6 tables */
if (*rc_proto & RC_PROTO_BIT_RC5) {
dev->board.xclk |= EM28XX_XCLK_IR_RC5_MODE;
ir->full_code = 1;
*rc_proto = RC_PROTO_BIT_RC5;
} else if (*rc_proto & RC_PROTO_BIT_NEC) {
dev->board.xclk &= ~EM28XX_XCLK_IR_RC5_MODE;
ir_config = EM2874_IR_NEC | EM2874_IR_NEC_NO_PARITY;
ir->full_code = 1;
*rc_proto = RC_PROTO_BIT_NEC;
} else if (*rc_proto & RC_PROTO_BIT_RC6_0) {
dev->board.xclk |= EM28XX_XCLK_IR_RC5_MODE;
ir_config = EM2874_IR_RC6_MODE_0;
ir->full_code = 1;
*rc_proto = RC_PROTO_BIT_RC6_0;
} else if (*rc_proto & RC_PROTO_BIT_UNKNOWN) {
*rc_proto = RC_PROTO_BIT_UNKNOWN;
} else {
*rc_proto = ir->rc_proto;
return -EINVAL;
}
em28xx_write_regs(dev, EM2874_R50_IR_CONFIG, &ir_config, 1);
em28xx_write_reg_bits(dev, EM28XX_R0F_XCLK, dev->board.xclk,
EM28XX_XCLK_IR_RC5_MODE);
ir->rc_proto = *rc_proto;
return 0;
}
static int em28xx_ir_change_protocol(struct rc_dev *rc_dev, u64 *rc_proto)
{
struct em28xx_IR *ir = rc_dev->priv;
struct em28xx *dev = ir->dev;
/* Setup the proper handler based on the chip */
switch (dev->chip_id) {
case CHIP_ID_EM2860:
case CHIP_ID_EM2883:
return em2860_ir_change_protocol(rc_dev, rc_proto);
case CHIP_ID_EM2884:
case CHIP_ID_EM2874:
case CHIP_ID_EM28174:
case CHIP_ID_EM28178:
return em2874_ir_change_protocol(rc_dev, rc_proto);
default:
dev_err(&ir->dev->intf->dev,
"Unrecognized em28xx chip id 0x%02x: IR not supported\n",
dev->chip_id);
return -EINVAL;
}
}
static int em28xx_probe_i2c_ir(struct em28xx *dev)
{
int i = 0;
/*
* Leadtek winfast tv USBII deluxe can find a non working IR-device
* at address 0x18, so if that address is needed for another board in
* the future, please put it after 0x1f.
*/
static const unsigned short addr_list[] = {
0x1f, 0x30, 0x47, I2C_CLIENT_END
};
while (addr_list[i] != I2C_CLIENT_END) {
if (i2c_probe_func_quick_read(&dev->i2c_adap[dev->def_i2c_bus],
addr_list[i]) == 1)
return addr_list[i];
i++;
}
return -ENODEV;
}
/*
* Handle buttons
*/
static void em28xx_query_buttons(struct work_struct *work)
{
struct em28xx *dev =
container_of(work, struct em28xx, buttons_query_work.work);
u8 i, j;
int regval;
bool is_pressed, was_pressed;
const struct em28xx_led *led;
/* Poll and evaluate all addresses */
for (i = 0; i < dev->num_button_polling_addresses; i++) {
/* Read value from register */
regval = em28xx_read_reg(dev, dev->button_polling_addresses[i]);
if (regval < 0)
continue;
/* Check states of the buttons and act */
j = 0;
while (dev->board.buttons[j].role >= 0 &&
dev->board.buttons[j].role < EM28XX_NUM_BUTTON_ROLES) {
const struct em28xx_button *button;
button = &dev->board.buttons[j];
/* Check if button uses the current address */
if (button->reg_r != dev->button_polling_addresses[i]) {
j++;
continue;
}
/* Determine if button is and was pressed last time */
is_pressed = regval & button->mask;
was_pressed = dev->button_polling_last_values[i]
& button->mask;
if (button->inverted) {
is_pressed = !is_pressed;
was_pressed = !was_pressed;
}
/* Clear button state (if needed) */
if (is_pressed && button->reg_clearing)
em28xx_write_reg(dev, button->reg_clearing,
(~regval & button->mask)
| (regval & ~button->mask));
/* Handle button state */
if (!is_pressed || was_pressed) {
j++;
continue;
}
switch (button->role) {
case EM28XX_BUTTON_SNAPSHOT:
/* Emulate the keypress */
input_report_key(dev->sbutton_input_dev,
EM28XX_SNAPSHOT_KEY, 1);
/* Unpress the key */
input_report_key(dev->sbutton_input_dev,
EM28XX_SNAPSHOT_KEY, 0);
break;
case EM28XX_BUTTON_ILLUMINATION:
led = em28xx_find_led(dev,
EM28XX_LED_ILLUMINATION);
/* Switch illumination LED on/off */
if (led)
em28xx_toggle_reg_bits(dev,
led->gpio_reg,
led->gpio_mask);
break;
default:
WARN_ONCE(1, "BUG: unhandled button role.");
}
/* Next button */
j++;
}
/* Save current value for comparison during the next polling */
dev->button_polling_last_values[i] = regval;
}
/* Schedule next poll */
schedule_delayed_work(&dev->buttons_query_work,
msecs_to_jiffies(dev->button_polling_interval));
}
static int em28xx_register_snapshot_button(struct em28xx *dev)
{
struct usb_device *udev = interface_to_usbdev(dev->intf);
struct input_dev *input_dev;
int err;
dev_info(&dev->intf->dev, "Registering snapshot button...\n");
input_dev = input_allocate_device();
if (!input_dev)
return -ENOMEM;
usb_make_path(udev, dev->snapshot_button_path,
sizeof(dev->snapshot_button_path));
strlcat(dev->snapshot_button_path, "/sbutton",
sizeof(dev->snapshot_button_path));
input_dev->name = "em28xx snapshot button";
input_dev->phys = dev->snapshot_button_path;
input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
set_bit(EM28XX_SNAPSHOT_KEY, input_dev->keybit);
input_dev->keycodesize = 0;
input_dev->keycodemax = 0;
usb_to_input_id(udev, &input_dev->id);
input_dev->dev.parent = &dev->intf->dev;
err = input_register_device(input_dev);
if (err) {
dev_err(&dev->intf->dev, "input_register_device failed\n");
input_free_device(input_dev);
return err;
}
dev->sbutton_input_dev = input_dev;
return 0;
}
static void em28xx_init_buttons(struct em28xx *dev)
{
u8 i = 0, j = 0;
bool addr_new = false;
dev->button_polling_interval = EM28XX_BUTTONS_DEBOUNCED_QUERY_INTERVAL;
while (dev->board.buttons[i].role >= 0 &&
dev->board.buttons[i].role < EM28XX_NUM_BUTTON_ROLES) {
const struct em28xx_button *button = &dev->board.buttons[i];
/* Check if polling address is already on the list */
addr_new = true;
for (j = 0; j < dev->num_button_polling_addresses; j++) {
if (button->reg_r == dev->button_polling_addresses[j]) {
addr_new = false;
break;
}
}
/* Check if max. number of polling addresses is exceeded */
if (addr_new && dev->num_button_polling_addresses
>= EM28XX_NUM_BUTTON_ADDRESSES_MAX) {
WARN_ONCE(1, "BUG: maximum number of button polling addresses exceeded.");
goto next_button;
}
/* Button role specific checks and actions */
if (button->role == EM28XX_BUTTON_SNAPSHOT) {
/* Register input device */
if (em28xx_register_snapshot_button(dev) < 0)
goto next_button;
} else if (button->role == EM28XX_BUTTON_ILLUMINATION) {
/* Check sanity */
if (!em28xx_find_led(dev, EM28XX_LED_ILLUMINATION)) {
dev_err(&dev->intf->dev,
"BUG: illumination button defined, but no illumination LED.\n");
goto next_button;
}
}
/* Add read address to list of polling addresses */
if (addr_new) {
unsigned int index = dev->num_button_polling_addresses;
dev->button_polling_addresses[index] = button->reg_r;
dev->num_button_polling_addresses++;
}
/* Reduce polling interval if necessary */
if (!button->reg_clearing)
dev->button_polling_interval =
EM28XX_BUTTONS_VOLATILE_QUERY_INTERVAL;
next_button:
/* Next button */
i++;
}
/* Start polling */
if (dev->num_button_polling_addresses) {
memset(dev->button_polling_last_values, 0,
EM28XX_NUM_BUTTON_ADDRESSES_MAX);
schedule_delayed_work(&dev->buttons_query_work,
msecs_to_jiffies(dev->button_polling_interval));
}
}
static void em28xx_shutdown_buttons(struct em28xx *dev)
{
/* Cancel polling */
cancel_delayed_work_sync(&dev->buttons_query_work);
/* Clear polling addresses list */
dev->num_button_polling_addresses = 0;
/* Deregister input devices */
if (dev->sbutton_input_dev) {
dev_info(&dev->intf->dev, "Deregistering snapshot button\n");
input_unregister_device(dev->sbutton_input_dev);
dev->sbutton_input_dev = NULL;
}
}
static int em28xx_ir_init(struct em28xx *dev)
{
struct usb_device *udev = interface_to_usbdev(dev->intf);
struct em28xx_IR *ir;
struct rc_dev *rc;
int err = -ENOMEM;
u64 rc_proto;
u16 i2c_rc_dev_addr = 0;
if (dev->is_audio_only) {
/* Shouldn't initialize IR for this interface */
return 0;
}
kref_get(&dev->ref);
INIT_DELAYED_WORK(&dev->buttons_query_work, em28xx_query_buttons);
if (dev->board.buttons)
em28xx_init_buttons(dev);
if (dev->board.has_ir_i2c) {
i2c_rc_dev_addr = em28xx_probe_i2c_ir(dev);
if (!i2c_rc_dev_addr) {
dev->board.has_ir_i2c = 0;
dev_warn(&dev->intf->dev,
"No i2c IR remote control device found.\n");
err = -ENODEV;
goto ref_put;
}
}
if (!dev->board.ir_codes && !dev->board.has_ir_i2c) {
/* No remote control support */
dev_warn(&dev->intf->dev,
"Remote control support is not available for this card.\n");
return 0;
}
dev_info(&dev->intf->dev, "Registering input extension\n");
ir = kzalloc_obj(*ir);
if (!ir)
goto ref_put;
rc = rc_allocate_device(RC_DRIVER_SCANCODE);
if (!rc)
goto error;
/* record handles to ourself */
ir->dev = dev;
dev->ir = ir;
ir->rc = rc;
rc->priv = ir;
rc->open = em28xx_ir_start;
rc->close = em28xx_ir_stop;
if (dev->board.has_ir_i2c) { /* external i2c device */
switch (dev->model) {
case EM2800_BOARD_TERRATEC_CINERGY_200:
case EM2820_BOARD_TERRATEC_CINERGY_250:
rc->map_name = RC_MAP_EM_TERRATEC;
ir->get_key_i2c = em28xx_get_key_terratec;
break;
case EM2820_BOARD_PINNACLE_USB_2:
rc->map_name = RC_MAP_PINNACLE_GREY;
ir->get_key_i2c = em28xx_get_key_pinnacle_usb_grey;
break;
case EM2820_BOARD_HAUPPAUGE_WINTV_USB_2:
rc->map_name = RC_MAP_HAUPPAUGE;
ir->get_key_i2c = em28xx_get_key_em_haup;
rc->allowed_protocols = RC_PROTO_BIT_RC5;
break;
case EM2820_BOARD_LEADTEK_WINFAST_USBII_DELUXE:
rc->map_name = RC_MAP_WINFAST_USBII_DELUXE;
ir->get_key_i2c = em28xx_get_key_winfast_usbii_deluxe;
break;
default:
err = -ENODEV;
goto error;
}
ir->i2c_client = kzalloc_obj(*ir->i2c_client);
if (!ir->i2c_client)
goto error;
ir->i2c_client->adapter = &ir->dev->i2c_adap[dev->def_i2c_bus];
ir->i2c_client->addr = i2c_rc_dev_addr;
ir->i2c_client->flags = 0;
/* NOTE: all other fields of i2c_client are unused */
} else { /* internal device */
switch (dev->chip_id) {
case CHIP_ID_EM2860:
case CHIP_ID_EM2883:
rc->allowed_protocols = RC_PROTO_BIT_RC5 |
RC_PROTO_BIT_NEC;
ir->get_key = default_polling_getkey;
break;
case CHIP_ID_EM2884:
case CHIP_ID_EM2874:
case CHIP_ID_EM28174:
case CHIP_ID_EM28178:
ir->get_key = em2874_polling_getkey;
rc->allowed_protocols = RC_PROTO_BIT_RC5 |
RC_PROTO_BIT_NEC | RC_PROTO_BIT_NECX |
RC_PROTO_BIT_NEC32 | RC_PROTO_BIT_RC6_0;
break;
default:
err = -ENODEV;
goto error;
}
rc->change_protocol = em28xx_ir_change_protocol;
rc->map_name = dev->board.ir_codes;
/* By default, keep protocol field untouched */
rc_proto = RC_PROTO_BIT_UNKNOWN;
err = em28xx_ir_change_protocol(rc, &rc_proto);
if (err)
goto error;
}
/* This is how often we ask the chip for IR information */
ir->polling = 100; /* ms */
usb_make_path(udev, ir->phys, sizeof(ir->phys));
strlcat(ir->phys, "/input0", sizeof(ir->phys));
rc->device_name = em28xx_boards[dev->model].name;
rc->input_phys = ir->phys;
usb_to_input_id(udev, &rc->input_id);
rc->dev.parent = &dev->intf->dev;
rc->driver_name = MODULE_NAME;
/* all done */
err = rc_register_device(rc);
if (err)
goto error;
dev_info(&dev->intf->dev, "Input extension successfully initialized\n");
return 0;
error:
kfree(ir->i2c_client);
dev->ir = NULL;
rc_free_device(rc);
kfree(ir);
ref_put:
em28xx_shutdown_buttons(dev);
return err;
}
static int em28xx_ir_fini(struct em28xx *dev)
{
struct em28xx_IR *ir = dev->ir;
if (dev->is_audio_only) {
/* Shouldn't initialize IR for this interface */
return 0;
}
dev_info(&dev->intf->dev, "Closing input extension\n");
em28xx_shutdown_buttons(dev);
/* skip detach on non attached boards */
if (!ir)
goto ref_put;
rc_unregister_device(ir->rc);
rc_free_device(ir->rc);
kfree(ir->i2c_client);
/* done */
kfree(ir);
dev->ir = NULL;
ref_put:
kref_put(&dev->ref, em28xx_free_device);
return 0;
}
static int em28xx_ir_suspend(struct em28xx *dev)
{
struct em28xx_IR *ir = dev->ir;
if (dev->is_audio_only)
return 0;
dev_info(&dev->intf->dev, "Suspending input extension\n");
if (ir)
cancel_delayed_work_sync(&ir->work);
cancel_delayed_work_sync(&dev->buttons_query_work);
/*
* is canceling delayed work sufficient or does the rc event
* kthread needs stopping? kthread is stopped in
* ir_raw_event_unregister()
*/
return 0;
}
static int em28xx_ir_resume(struct em28xx *dev)
{
struct em28xx_IR *ir = dev->ir;
if (dev->is_audio_only)
return 0;
dev_info(&dev->intf->dev, "Resuming input extension\n");
/*
* if suspend calls ir_raw_event_unregister(), the should call
* ir_raw_event_register()
*/
if (ir)
schedule_delayed_work(&ir->work, msecs_to_jiffies(ir->polling));
if (dev->num_button_polling_addresses)
schedule_delayed_work(&dev->buttons_query_work,
msecs_to_jiffies(dev->button_polling_interval));
return 0;
}
static struct em28xx_ops rc_ops = {
.id = EM28XX_RC,
.name = "Em28xx Input Extension",
.init = em28xx_ir_init,
.fini = em28xx_ir_fini,
.suspend = em28xx_ir_suspend,
.resume = em28xx_ir_resume,
};
static int __init em28xx_rc_register(void)
{
return em28xx_register_extension(&rc_ops);
}
static void __exit em28xx_rc_unregister(void)
{
em28xx_unregister_extension(&rc_ops);
}
MODULE_LICENSE("GPL v2");
MODULE_AUTHOR("Mauro Carvalho Chehab");
MODULE_DESCRIPTION(DRIVER_DESC " - input interface");
MODULE_VERSION(EM28XX_VERSION);
module_init(em28xx_rc_register);
module_exit(em28xx_rc_unregister);
@@ -0,0 +1,302 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* em28xx-reg.h - Register definitions for em28xx driver
*/
#define EM_GPIO_0 ((unsigned char)BIT(0))
#define EM_GPIO_1 ((unsigned char)BIT(1))
#define EM_GPIO_2 ((unsigned char)BIT(2))
#define EM_GPIO_3 ((unsigned char)BIT(3))
#define EM_GPIO_4 ((unsigned char)BIT(4))
#define EM_GPIO_5 ((unsigned char)BIT(5))
#define EM_GPIO_6 ((unsigned char)BIT(6))
#define EM_GPIO_7 ((unsigned char)BIT(7))
#define EM_GPO_0 ((unsigned char)BIT(0))
#define EM_GPO_1 ((unsigned char)BIT(1))
#define EM_GPO_2 ((unsigned char)BIT(2))
#define EM_GPO_3 ((unsigned char)BIT(3))
/* em28xx endpoints */
/* 0x82: (always ?) analog */
#define EM28XX_EP_AUDIO 0x83
/* 0x84: digital or analog */
/* em2800 registers */
#define EM2800_R08_AUDIOSRC 0x08
/* em28xx registers */
#define EM28XX_R00_CHIPCFG 0x00
/* em28xx Chip Configuration 0x00 */
#define EM2860_CHIPCFG_VENDOR_AUDIO 0x80
#define EM2860_CHIPCFG_I2S_VOLUME_CAPABLE 0x40
#define EM2820_CHIPCFG_I2S_3_SAMPRATES 0x30
#define EM2860_CHIPCFG_I2S_5_SAMPRATES 0x30
#define EM2820_CHIPCFG_I2S_1_SAMPRATE 0x20
#define EM2860_CHIPCFG_I2S_3_SAMPRATES 0x20
#define EM28XX_CHIPCFG_AC97 0x10
#define EM28XX_CHIPCFG_AUDIOMASK 0x30
#define EM28XX_R01_CHIPCFG2 0x01
/* em28xx Chip Configuration 2 0x01 */
#define EM28XX_CHIPCFG2_TS_PRESENT 0x10
#define EM28XX_CHIPCFG2_TS_REQ_INTERVAL_MASK 0x0c /* bits 3-2 */
#define EM28XX_CHIPCFG2_TS_REQ_INTERVAL_1MF 0x00
#define EM28XX_CHIPCFG2_TS_REQ_INTERVAL_2MF 0x04
#define EM28XX_CHIPCFG2_TS_REQ_INTERVAL_4MF 0x08
#define EM28XX_CHIPCFG2_TS_REQ_INTERVAL_8MF 0x0c
#define EM28XX_CHIPCFG2_TS_PACKETSIZE_MASK 0x03 /* bits 0-1 */
#define EM28XX_CHIPCFG2_TS_PACKETSIZE_188 0x00
#define EM28XX_CHIPCFG2_TS_PACKETSIZE_376 0x01
#define EM28XX_CHIPCFG2_TS_PACKETSIZE_564 0x02
#define EM28XX_CHIPCFG2_TS_PACKETSIZE_752 0x03
/* GPIO/GPO registers */
#define EM2880_R04_GPO 0x04 /* em2880-em2883 only */
#define EM2820_R08_GPIO_CTRL 0x08 /* em2820-em2873/83 only */
#define EM2820_R09_GPIO_STATE 0x09 /* em2820-em2873/83 only */
#define EM28XX_R06_I2C_CLK 0x06
/* em28xx I2C Clock Register (0x06) */
#define EM28XX_I2C_CLK_ACK_LAST_READ 0x80
#define EM28XX_I2C_CLK_WAIT_ENABLE 0x40
#define EM28XX_I2C_EEPROM_ON_BOARD 0x08
#define EM28XX_I2C_EEPROM_KEY_VALID 0x04
#define EM2874_I2C_SECONDARY_BUS_SELECT 0x04 /* em2874 has two i2c buses */
#define EM28XX_I2C_FREQ_1_5_MHZ 0x03 /* bus frequency (bits [1-0]) */
#define EM28XX_I2C_FREQ_25_KHZ 0x02
#define EM28XX_I2C_FREQ_400_KHZ 0x01
#define EM28XX_I2C_FREQ_100_KHZ 0x00
#define EM28XX_R0A_CHIPID 0x0a
#define EM28XX_R0C_USBSUSP 0x0c
#define EM28XX_R0C_USBSUSP_SNAPSHOT 0x20 /* 1=button pressed, needs reset */
#define EM28XX_R0E_AUDIOSRC 0x0e
#define EM28XX_R0F_XCLK 0x0f
/* em28xx XCLK Register (0x0f) */
#define EM28XX_XCLK_AUDIO_UNMUTE 0x80 /* otherwise audio muted */
#define EM28XX_XCLK_I2S_MSB_TIMING 0x40 /* otherwise standard timing */
#define EM28XX_XCLK_IR_RC5_MODE 0x20 /* otherwise NEC mode */
#define EM28XX_XCLK_IR_NEC_CHK_PARITY 0x10
#define EM28XX_XCLK_FREQUENCY_30MHZ 0x00 /* Freq. select (bits [3-0]) */
#define EM28XX_XCLK_FREQUENCY_15MHZ 0x01
#define EM28XX_XCLK_FREQUENCY_10MHZ 0x02
#define EM28XX_XCLK_FREQUENCY_7_5MHZ 0x03
#define EM28XX_XCLK_FREQUENCY_6MHZ 0x04
#define EM28XX_XCLK_FREQUENCY_5MHZ 0x05
#define EM28XX_XCLK_FREQUENCY_4_3MHZ 0x06
#define EM28XX_XCLK_FREQUENCY_12MHZ 0x07
#define EM28XX_XCLK_FREQUENCY_20MHZ 0x08
#define EM28XX_XCLK_FREQUENCY_20MHZ_2 0x09
#define EM28XX_XCLK_FREQUENCY_48MHZ 0x0a
#define EM28XX_XCLK_FREQUENCY_24MHZ 0x0b
#define EM28XX_R10_VINMODE 0x10
/* used by all non-camera devices: */
#define EM28XX_VINMODE_YUV422_CbYCrY 0x10
/* used by camera devices: */
#define EM28XX_VINMODE_YUV422_YUYV 0x08
#define EM28XX_VINMODE_YUV422_YVYU 0x09
#define EM28XX_VINMODE_YUV422_UYVY 0x0a
#define EM28XX_VINMODE_YUV422_VYUY 0x0b
#define EM28XX_VINMODE_RGB8_BGGR 0x0c
#define EM28XX_VINMODE_RGB8_GRBG 0x0d
#define EM28XX_VINMODE_RGB8_GBRG 0x0e
#define EM28XX_VINMODE_RGB8_RGGB 0x0f
/*
* apparently:
* bit 0: swap component 1+2 with 3+4
* => e.g.: YUYV => YVYU, BGGR => GRBG
* bit 1: swap component 1 with 2 and 3 with 4
* => e.g.: YUYV => UYVY, BGGR => GBRG
*/
#define EM28XX_R11_VINCTRL 0x11
/* em28xx Video Input Control Register 0x11 */
#define EM28XX_VINCTRL_VBI_SLICED 0x80
#define EM28XX_VINCTRL_VBI_RAW 0x40
#define EM28XX_VINCTRL_VOUT_MODE_IN 0x20 /* HREF,VREF,VACT in output */
#define EM28XX_VINCTRL_CCIR656_ENABLE 0x10
#define EM28XX_VINCTRL_VBI_16BIT_RAW 0x08 /* otherwise 8-bit raw */
#define EM28XX_VINCTRL_FID_ON_HREF 0x04
#define EM28XX_VINCTRL_DUAL_EDGE_STROBE 0x02
#define EM28XX_VINCTRL_INTERLACED 0x01
#define EM28XX_R12_VINENABLE 0x12 /* */
#define EM28XX_R14_GAMMA 0x14
#define EM28XX_R15_RGAIN 0x15
#define EM28XX_R16_GGAIN 0x16
#define EM28XX_R17_BGAIN 0x17
#define EM28XX_R18_ROFFSET 0x18
#define EM28XX_R19_GOFFSET 0x19
#define EM28XX_R1A_BOFFSET 0x1a
#define EM28XX_R1B_OFLOW 0x1b
#define EM28XX_R1C_HSTART 0x1c
#define EM28XX_R1D_VSTART 0x1d
#define EM28XX_R1E_CWIDTH 0x1e
#define EM28XX_R1F_CHEIGHT 0x1f
#define EM28XX_R20_YGAIN 0x20 /* contrast [0:4] */
#define CONTRAST_DEFAULT 0x10
#define EM28XX_R21_YOFFSET 0x21 /* brightness */ /* signed */
#define BRIGHTNESS_DEFAULT 0x00
#define EM28XX_R22_UVGAIN 0x22 /* saturation [0:4] */
#define SATURATION_DEFAULT 0x10
#define EM28XX_R23_UOFFSET 0x23 /* blue balance */ /* signed */
#define BLUE_BALANCE_DEFAULT 0x00
#define EM28XX_R24_VOFFSET 0x24 /* red balance */ /* signed */
#define RED_BALANCE_DEFAULT 0x00
#define EM28XX_R25_SHARPNESS 0x25 /* sharpness [0:4] */
#define SHARPNESS_DEFAULT 0x00
#define EM28XX_R26_COMPR 0x26
#define EM28XX_R27_OUTFMT 0x27
/* em28xx Output Format Register (0x27) */
#define EM28XX_OUTFMT_RGB_8_RGRG 0x00
#define EM28XX_OUTFMT_RGB_8_GRGR 0x01
#define EM28XX_OUTFMT_RGB_8_GBGB 0x02
#define EM28XX_OUTFMT_RGB_8_BGBG 0x03
#define EM28XX_OUTFMT_RGB_16_656 0x04
#define EM28XX_OUTFMT_RGB_8_BAYER 0x08 /* Pattern in Reg 0x10[1-0] */
#define EM28XX_OUTFMT_YUV211 0x10
#define EM28XX_OUTFMT_YUV422_Y0UY1V 0x14
#define EM28XX_OUTFMT_YUV422_Y1UY0V 0x15
#define EM28XX_OUTFMT_YUV411 0x18
#define EM28XX_R28_XMIN 0x28
#define EM28XX_R29_XMAX 0x29
#define EM28XX_R2A_YMIN 0x2a
#define EM28XX_R2B_YMAX 0x2b
#define EM28XX_R30_HSCALELOW 0x30
#define EM28XX_R31_HSCALEHIGH 0x31
#define EM28XX_R32_VSCALELOW 0x32
#define EM28XX_R33_VSCALEHIGH 0x33
#define EM28XX_HVSCALE_MAX 0x3fff /* => 20% */
#define EM28XX_R34_VBI_START_H 0x34
#define EM28XX_R35_VBI_START_V 0x35
/*
* NOTE: the EM276x (and EM25xx, EM277x/8x ?) (camera bridges) use these
* registers for a different unknown purpose.
* => register 0x34 is set to capture width / 16
* => register 0x35 is set to capture height / 16
*/
#define EM28XX_R36_VBI_WIDTH 0x36
#define EM28XX_R37_VBI_HEIGHT 0x37
#define EM28XX_R40_AC97LSB 0x40
#define EM28XX_R41_AC97MSB 0x41
#define EM28XX_R42_AC97ADDR 0x42
#define EM28XX_R43_AC97BUSY 0x43
#define EM28XX_R45_IR 0x45
/*
* 0x45 bit 7 - parity bit
* bits 6-0 - count
* 0x46 IR brand
* 0x47 IR data
*/
/* em2874 registers */
#define EM2874_R50_IR_CONFIG 0x50
#define EM2874_R51_IR 0x51
#define EM2874_R5D_TS1_PKT_SIZE 0x5d
#define EM2874_R5E_TS2_PKT_SIZE 0x5e
/*
* For both TS1 and TS2, In isochronous mode:
* 0x01 188 bytes
* 0x02 376 bytes
* 0x03 564 bytes
* 0x04 752 bytes
* 0x05 940 bytes
* In bulk mode:
* 0x01..0xff total packet count in 188-byte
*/
#define EM2874_R5F_TS_ENABLE 0x5f
/* em2874/174/84, em25xx, em276x/7x/8x GPIO registers */
/*
* NOTE: not all ports are bonded out;
* Some ports are multiplexed with special function I/O
*/
#define EM2874_R80_GPIO_P0_CTRL 0x80
#define EM2874_R81_GPIO_P1_CTRL 0x81
#define EM2874_R82_GPIO_P2_CTRL 0x82
#define EM2874_R83_GPIO_P3_CTRL 0x83
#define EM2874_R84_GPIO_P0_STATE 0x84
#define EM2874_R85_GPIO_P1_STATE 0x85
#define EM2874_R86_GPIO_P2_STATE 0x86
#define EM2874_R87_GPIO_P3_STATE 0x87
/* em2874 IR config register (0x50) */
#define EM2874_IR_NEC 0x00
#define EM2874_IR_NEC_NO_PARITY 0x01
#define EM2874_IR_RC5 0x04
#define EM2874_IR_RC6_MODE_0 0x08
#define EM2874_IR_RC6_MODE_6A 0x0b
/* em2874 Transport Stream Enable Register (0x5f) */
#define EM2874_TS1_CAPTURE_ENABLE ((unsigned char)BIT(0))
#define EM2874_TS1_FILTER_ENABLE ((unsigned char)BIT(1))
#define EM2874_TS1_NULL_DISCARD ((unsigned char)BIT(2))
#define EM2874_TS2_CAPTURE_ENABLE ((unsigned char)BIT(4))
#define EM2874_TS2_FILTER_ENABLE ((unsigned char)BIT(5))
#define EM2874_TS2_NULL_DISCARD ((unsigned char)BIT(6))
/* register settings */
#define EM2800_AUDIO_SRC_TUNER 0x0d
#define EM2800_AUDIO_SRC_LINE 0x0c
#define EM28XX_AUDIO_SRC_TUNER 0xc0
#define EM28XX_AUDIO_SRC_LINE 0x80
/* FIXME: Need to be populated with the other chip ID's */
enum em28xx_chip_id {
CHIP_ID_EM2800 = 7,
CHIP_ID_EM2710 = 17,
CHIP_ID_EM2820 = 18, /* Also used by some em2710 */
CHIP_ID_EM2840 = 20,
CHIP_ID_EM2750 = 33,
CHIP_ID_EM2860 = 34,
CHIP_ID_EM2870 = 35,
CHIP_ID_EM2883 = 36,
CHIP_ID_EM2765 = 54,
CHIP_ID_EM2874 = 65,
CHIP_ID_EM2884 = 68,
CHIP_ID_EM28174 = 113,
CHIP_ID_EM28178 = 114,
CHIP_ID_EM2828X = 148,
};
/*
* Registers used by em202
*/
/* EMP202 vendor registers */
#define EM202_EXT_MODEM_CTRL 0x3e
#define EM202_GPIO_CONF 0x4c
#define EM202_GPIO_POLARITY 0x4e
#define EM202_GPIO_STICKY 0x50
#define EM202_GPIO_MASK 0x52
#define EM202_GPIO_STATUS 0x54
#define EM202_SPDIF_OUT_SEL 0x6a
#define EM202_ANTIPOP 0x72
#define EM202_EAPD_GPIO_ACCESS 0x74
@@ -0,0 +1,11 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* em28xx-video.c - driver for Empia EM2800/EM2820/2840 USB
* video capture devices
*
* Copyright (C) 2013-2014 Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
*/
int em28xx_start_analog_streaming(struct vb2_queue *vq, unsigned int count);
void em28xx_stop_vbi_streaming(struct vb2_queue *vq);
extern const struct vb2_ops em28xx_vbi_qops;
@@ -0,0 +1,87 @@
// SPDX-License-Identifier: GPL-2.0+
//
// em28xx-vbi.c - VBI driver for em28xx
//
// Copyright (C) 2009 Devin Heitmueller <dheitmueller@kernellabs.com>
//
// This work was sponsored by EyeMagnet Limited.
#include "em28xx.h"
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/hardirq.h>
#include <linux/init.h>
#include <linux/usb.h>
#include "em28xx-v4l.h"
/* ------------------------------------------------------------------ */
static int vbi_queue_setup(struct vb2_queue *vq,
unsigned int *nbuffers, unsigned int *nplanes,
unsigned int sizes[], struct device *alloc_devs[])
{
struct em28xx *dev = vb2_get_drv_priv(vq);
struct em28xx_v4l2 *v4l2 = dev->v4l2;
unsigned long size = v4l2->vbi_width * v4l2->vbi_height * 2;
if (*nbuffers < 2)
*nbuffers = 2;
if (*nplanes) {
if (sizes[0] < size)
return -EINVAL;
size = sizes[0];
}
*nplanes = 1;
sizes[0] = size;
return 0;
}
static int vbi_buffer_prepare(struct vb2_buffer *vb)
{
struct em28xx *dev = vb2_get_drv_priv(vb->vb2_queue);
struct em28xx_v4l2 *v4l2 = dev->v4l2;
unsigned long size;
size = v4l2->vbi_width * v4l2->vbi_height * 2;
if (vb2_plane_size(vb, 0) < size) {
dev_info(&dev->intf->dev,
"%s data will not fit into plane (%lu < %lu)\n",
__func__, vb2_plane_size(vb, 0), size);
return -EINVAL;
}
vb2_set_plane_payload(vb, 0, size);
return 0;
}
static void
vbi_buffer_queue(struct vb2_buffer *vb)
{
struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
struct em28xx *dev = vb2_get_drv_priv(vb->vb2_queue);
struct em28xx_buffer *buf =
container_of(vbuf, struct em28xx_buffer, vb);
struct em28xx_dmaqueue *vbiq = &dev->vbiq;
unsigned long flags = 0;
buf->mem = vb2_plane_vaddr(vb, 0);
buf->length = vb2_plane_size(vb, 0);
spin_lock_irqsave(&dev->slock, flags);
list_add_tail(&buf->list, &vbiq->active);
spin_unlock_irqrestore(&dev->slock, flags);
}
const struct vb2_ops em28xx_vbi_qops = {
.queue_setup = vbi_queue_setup,
.buf_prepare = vbi_buffer_prepare,
.buf_queue = vbi_buffer_queue,
.start_streaming = em28xx_start_analog_streaming,
.stop_streaming = em28xx_stop_vbi_streaming,
};
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,870 @@
/* SPDX-License-Identifier: GPL-2.0+ */
/*
* em28xx.h - driver for Empia EM2800/EM2820/2840 USB video capture devices
*
* Copyright (C) 2005 Markus Rechberger <mrechberger@gmail.com>
* Ludovico Cavedon <cavedon@sssup.it>
* Mauro Carvalho Chehab <mchehab@kernel.org>
* Copyright (C) 2012 Frank Schäfer <fschaefer.oss@googlemail.com>
*
* Based on the em2800 driver from Sascha Sommer <saschasommer@freenet.de>
*/
#ifndef _EM28XX_H
#define _EM28XX_H
#include <linux/bitfield.h>
#define EM28XX_VERSION "0.2.2"
#define DRIVER_DESC "Empia em28xx device driver"
#include <linux/workqueue.h>
#include <linux/i2c.h>
#include <linux/mutex.h>
#include <linux/kref.h>
#include <linux/videodev2.h>
#include <linux/device-id/usb.h>
#include <media/videobuf2-v4l2.h>
#include <media/videobuf2-vmalloc.h>
#include <media/v4l2-device.h>
#include <media/v4l2-ctrls.h>
#include <media/v4l2-fh.h>
#include <media/i2c/ir-kbd-i2c.h>
#include <media/rc-core.h>
#include "xc2028.h"
#include "xc5000.h"
#include "em28xx-reg.h"
/* Boards supported by driver */
#define EM2800_BOARD_UNKNOWN 0
#define EM2820_BOARD_UNKNOWN 1
#define EM2820_BOARD_TERRATEC_CINERGY_250 2
#define EM2820_BOARD_PINNACLE_USB_2 3
#define EM2820_BOARD_HAUPPAUGE_WINTV_USB_2 4
#define EM2820_BOARD_MSI_VOX_USB_2 5
#define EM2800_BOARD_TERRATEC_CINERGY_200 6
#define EM2800_BOARD_LEADTEK_WINFAST_USBII 7
#define EM2800_BOARD_KWORLD_USB2800 8
#define EM2820_BOARD_PINNACLE_DVC_90 9
#define EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900 10
#define EM2880_BOARD_TERRATEC_HYBRID_XS 11
#define EM2820_BOARD_KWORLD_PVRTV2800RF 12
#define EM2880_BOARD_TERRATEC_PRODIGY_XS 13
#define EM2820_BOARD_PROLINK_PLAYTV_USB2 14
#define EM2800_BOARD_VGEAR_POCKETTV 15
#define EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950 16
#define EM2880_BOARD_PINNACLE_PCTV_HD_PRO 17
#define EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2 18
#define EM2860_BOARD_SAA711X_REFERENCE_DESIGN 19
#define EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600 20
#define EM2800_BOARD_GRABBEEX_USB2800 21
#define EM2750_BOARD_UNKNOWN 22
#define EM2750_BOARD_DLCW_130 23
#define EM2820_BOARD_DLINK_USB_TV 24
#define EM2820_BOARD_GADMEI_UTV310 25
#define EM2820_BOARD_HERCULES_SMART_TV_USB2 26
#define EM2820_BOARD_PINNACLE_USB_2_FM1216ME 27
#define EM2820_BOARD_LEADTEK_WINFAST_USBII_DELUXE 28
#define EM2860_BOARD_TVP5150_REFERENCE_DESIGN 29
#define EM2820_BOARD_VIDEOLOGY_20K14XUSB 30
#define EM2821_BOARD_USBGEAR_VD204 31
#define EM2821_BOARD_SUPERCOMP_USB_2 32
#define EM2860_BOARD_ELGATO_VIDEO_CAPTURE 33
#define EM2860_BOARD_TERRATEC_HYBRID_XS 34
#define EM2860_BOARD_TYPHOON_DVD_MAKER 35
#define EM2860_BOARD_NETGMBH_CAM 36
#define EM2860_BOARD_GADMEI_UTV330 37
#define EM2861_BOARD_YAKUMO_MOVIE_MIXER 38
#define EM2861_BOARD_KWORLD_PVRTV_300U 39
#define EM2861_BOARD_PLEXTOR_PX_TV100U 40
#define EM2870_BOARD_KWORLD_350U 41
#define EM2870_BOARD_KWORLD_355U 42
#define EM2870_BOARD_TERRATEC_XS 43
#define EM2870_BOARD_TERRATEC_XS_MT2060 44
#define EM2870_BOARD_PINNACLE_PCTV_DVB 45
#define EM2870_BOARD_COMPRO_VIDEOMATE 46
#define EM2880_BOARD_KWORLD_DVB_305U 47
#define EM2880_BOARD_KWORLD_DVB_310U 48
#define EM2880_BOARD_MSI_DIGIVOX_AD 49
#define EM2880_BOARD_MSI_DIGIVOX_AD_II 50
#define EM2880_BOARD_TERRATEC_HYBRID_XS_FR 51
#define EM2881_BOARD_DNT_DA2_HYBRID 52
#define EM2881_BOARD_PINNACLE_HYBRID_PRO 53
#define EM2882_BOARD_KWORLD_VS_DVBT 54
#define EM2882_BOARD_TERRATEC_HYBRID_XS 55
#define EM2882_BOARD_PINNACLE_HYBRID_PRO_330E 56
#define EM2883_BOARD_KWORLD_HYBRID_330U 57
#define EM2820_BOARD_COMPRO_VIDEOMATE_FORYOU 58
#define EM2874_BOARD_PCTV_HD_MINI_80E 59
#define EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850 60
#define EM2820_BOARD_PROLINK_PLAYTV_BOX4_USB2 61
#define EM2820_BOARD_GADMEI_TVR200 62
#define EM2860_BOARD_KAIOMY_TVNPC_U2 63
#define EM2860_BOARD_EASYCAP 64
#define EM2820_BOARD_IODATA_GVMVP_SZ 65
#define EM2880_BOARD_EMPIRE_DUAL_TV 66
#define EM2860_BOARD_TERRATEC_GRABBY 67
#define EM2860_BOARD_TERRATEC_AV350 68
#define EM2882_BOARD_KWORLD_ATSC_315U 69
#define EM2882_BOARD_EVGA_INDTUBE 70
#define EM2820_BOARD_SILVERCREST_WEBCAM 71
#define EM2861_BOARD_GADMEI_UTV330PLUS 72
#define EM2870_BOARD_REDDO_DVB_C_USB_BOX 73
#define EM2800_BOARD_VC211A 74
#define EM2882_BOARD_DIKOM_DK300 75
#define EM2870_BOARD_KWORLD_A340 76
#define EM2874_BOARD_LEADERSHIP_ISDBT 77
#define EM28174_BOARD_PCTV_290E 78
#define EM2884_BOARD_TERRATEC_H5 79
#define EM28174_BOARD_PCTV_460E 80
#define EM2884_BOARD_HAUPPAUGE_WINTV_HVR_930C 81
#define EM2884_BOARD_CINERGY_HTC_STICK 82
#define EM2860_BOARD_HT_VIDBOX_NW03 83
#define EM2874_BOARD_MAXMEDIA_UB425_TC 84
#define EM2884_BOARD_PCTV_510E 85
#define EM2884_BOARD_PCTV_520E 86
#define EM2884_BOARD_TERRATEC_HTC_USB_XS 87
#define EM2884_BOARD_C3TECH_DIGITAL_DUO 88
#define EM2874_BOARD_DELOCK_61959 89
#define EM2874_BOARD_KWORLD_UB435Q_V2 90
#define EM2765_BOARD_SPEEDLINK_VAD_LAPLACE 91
#define EM28178_BOARD_PCTV_461E 92
#define EM2874_BOARD_KWORLD_UB435Q_V3 93
#define EM28178_BOARD_PCTV_292E 94
#define EM2861_BOARD_LEADTEK_VC100 95
#define EM28178_BOARD_TERRATEC_T2_STICK_HD 96
#define EM2884_BOARD_ELGATO_EYETV_HYBRID_2008 97
#define EM28178_BOARD_PLEX_PX_BCUD 98
#define EM28174_BOARD_HAUPPAUGE_WINTV_DUALHD_DVB 99
#define EM28174_BOARD_HAUPPAUGE_WINTV_DUALHD_01595 100
#define EM2884_BOARD_TERRATEC_H6 101
#define EM2882_BOARD_ZOLID_HYBRID_TV_STICK 102
#define EM2861_BOARD_MAGIX_VIDEOWANDLER2 103
#define EM28178_BOARD_PCTV_461E_V2 104
#define EM2860_BOARD_MYGICA_IGRABBER 105
#define EM2874_BOARD_HAUPPAUGE_USB_QUADHD 106
#define EM2860_BOARD_MYGICA_UTV3 107
#define EM2828X_BOARD_HAUPPAUGE_USB_LIVE2 108
#define EM2828X_BOARD_HAUPPAUGE_935_V2 109
#define EM2828X_BOARD_HAUPPAUGE_955_V2 110
#define EM2828X_BOARD_HAUPPAUGE_975_V2 111
#define EM28178_BOARD_PCTV_461E_V3 112
/* Limits minimum and default number of buffers */
#define EM28XX_MIN_BUF 4
#define EM28XX_DEF_BUF 8
/*Limits the max URB message size */
#define URB_MAX_CTRL_SIZE 80
/* Params for validated field */
#define EM28XX_BOARD_NOT_VALIDATED 1
#define EM28XX_BOARD_VALIDATED 0
/* Params for em28xx_cmd() audio */
#define EM28XX_START_AUDIO 1
#define EM28XX_STOP_AUDIO 0
/* maximum number of em28xx boards */
#define EM28XX_MAXBOARDS DVB_MAX_ADAPTERS /* All adapters could be em28xx */
/* maximum number of frames that can be queued */
#define EM28XX_NUM_FRAMES 5
/* number of frames that get used for v4l2_read() */
#define EM28XX_NUM_READ_FRAMES 2
/* number of buffers for isoc transfers */
#define EM28XX_NUM_BUFS 5
#define EM28XX_DVB_NUM_BUFS 5
/* max number of I2C buses on em28xx devices */
#define NUM_I2C_BUSES 2
/*
* isoc transfers: number of packets for each buffer
* windows requests only 64 packets .. so we better do the same
* this is what I found out for all alternate numbers there!
*/
#define EM28XX_NUM_ISOC_PACKETS 64
#define EM28XX_DVB_NUM_ISOC_PACKETS 64
/*
* bulk transfers: transfer buffer size = packet size * packet multiplier
* USB 2.0 spec says bulk packet size is always 512 bytes
*/
#define EM28XX_BULK_PACKET_MULTIPLIER 384
#define EM28XX_DVB_BULK_PACKET_MULTIPLIER 94
#define EM28XX_INTERLACED_DEFAULT 1
/* time in msecs to wait for AC97 xfers to finish */
#define EM28XX_AC97_XFER_TIMEOUT 100
/* max. number of button state polling addresses */
#define EM28XX_NUM_BUTTON_ADDRESSES_MAX 5
#define PRIMARY_TS 0
#define SECONDARY_TS 1
enum em28xx_mode {
EM28XX_SUSPEND,
EM28XX_ANALOG_MODE,
EM28XX_DIGITAL_MODE,
};
struct em28xx;
/**
* struct em28xx_usb_bufs - Contains URB-related buffer data
*
* @max_pkt_size: max packet size of isoc transaction
* @num_packets: number of packets in each buffer
* @num_bufs: number of allocated urb
* @urb: urb for isoc/bulk transfers
* @buf: transfer buffers for isoc/bulk transfer
*/
struct em28xx_usb_bufs {
int max_pkt_size;
int num_packets;
int num_bufs;
struct urb **urb;
char **buf;
};
/**
* struct em28xx_usb_ctl - Contains URB-related buffer data
*
* @analog_bufs: isoc/bulk transfer buffers for analog mode
* @digital_bufs: isoc/bulk transfer buffers for digital mode
* @vid_buf: Stores already requested video buffers
* @vbi_buf: Stores already requested VBI buffers
* @urb_data_copy: copy data from URB
*/
struct em28xx_usb_ctl {
struct em28xx_usb_bufs analog_bufs;
struct em28xx_usb_bufs digital_bufs;
struct em28xx_buffer *vid_buf;
struct em28xx_buffer *vbi_buf;
int (*urb_data_copy)(struct em28xx *dev, struct urb *urb);
};
/**
* struct em28xx_fmt - Struct to enumberate video formats
*
* @fourcc: v4l2 format id
* @depth: mean number of bits to represent a pixel
* @reg: em28xx register value to set it
*/
struct em28xx_fmt {
u32 fourcc;
int depth;
int reg;
};
/**
* struct em28xx_buffer- buffer for storing one video frame
*
* @vb: common v4l buffer stuff
* @list: List to associate it with the other buffers
* @mem: pointer to the buffer, as returned by vb2_plane_vaddr()
* @length: length of the buffer, as returned by vb2_plane_size()
* @top_field: If non-zero, indicate that the buffer is the top field
* @pos: Indicate the next position of the buffer to be filled.
* @vb_buf: pointer to vmalloc memory address in vb
*
* .. note::
*
* in interlaced mode, @pos is reset to zero at the start of each new
* field (not frame !)
*/
struct em28xx_buffer {
struct vb2_v4l2_buffer vb; /* must be first */
struct list_head list;
void *mem;
unsigned int length;
int top_field;
unsigned int pos;
char *vb_buf;
};
struct em28xx_dmaqueue {
struct list_head active;
wait_queue_head_t wq;
};
/* inputs */
#define MAX_EM28XX_INPUT 4
enum enum28xx_itype {
EM28XX_VMUX_COMPOSITE = 1,
EM28XX_VMUX_SVIDEO,
EM28XX_VMUX_TELEVISION,
EM28XX_RADIO,
};
enum em28xx_ac97_mode {
EM28XX_NO_AC97 = 0,
EM28XX_AC97_EM202,
EM28XX_AC97_SIGMATEL,
EM28XX_AC97_OTHER,
};
struct em28xx_audio_mode {
enum em28xx_ac97_mode ac97;
};
enum em28xx_int_audio_type {
EM28XX_INT_AUDIO_NONE = 0,
EM28XX_INT_AUDIO_AC97,
EM28XX_INT_AUDIO_I2S,
};
enum em28xx_usb_audio_type {
EM28XX_USB_AUDIO_NONE = 0,
EM28XX_USB_AUDIO_CLASS,
EM28XX_USB_AUDIO_VENDOR,
};
/**
* enum em28xx_amux - describes the type of audio input used by em28xx
*
* @EM28XX_AMUX_UNUSED:
* Used only on em28xx dev->map field, in order to mark an entry
* as unused.
* @EM28XX_AMUX_VIDEO:
* On devices without AC97, this is the only value that it is currently
* allowed.
* On devices with AC97, it corresponds to the AC97 mixer "Video" control.
* @EM28XX_AMUX_LINE_IN:
* Only for devices with AC97. Corresponds to AC97 mixer "Line In".
* @EM28XX_AMUX_VIDEO2:
* Only for devices with AC97. It means that em28xx should use "Line In"
* And AC97 should use the "Video" mixer control.
* @EM28XX_AMUX_PHONE:
* Only for devices with AC97. Corresponds to AC97 mixer "Phone".
* @EM28XX_AMUX_MIC:
* Only for devices with AC97. Corresponds to AC97 mixer "Mic".
* @EM28XX_AMUX_CD:
* Only for devices with AC97. Corresponds to AC97 mixer "CD".
* @EM28XX_AMUX_AUX:
* Only for devices with AC97. Corresponds to AC97 mixer "Aux".
* @EM28XX_AMUX_PCM_OUT:
* Only for devices with AC97. Corresponds to AC97 mixer "PCM out".
*
* The em28xx chip itself has only two audio inputs: tuner and line in.
* On almost all devices, only the tuner input is used.
*
* However, on most devices, an auxiliary AC97 codec device is used,
* usually connected to the em28xx tuner input (except for
* @EM28XX_AMUX_LINE_IN).
*
* The AC97 device typically have several different inputs and outputs.
* The exact number and description depends on their model.
*
* It is possible to AC97 to mixer more than one different entries at the
* same time, via the alsa mux.
*/
enum em28xx_amux {
EM28XX_AMUX_UNUSED = -1,
EM28XX_AMUX_VIDEO = 0,
EM28XX_AMUX_LINE_IN,
/* Some less-common mixer setups */
EM28XX_AMUX_VIDEO2,
EM28XX_AMUX_PHONE,
EM28XX_AMUX_MIC,
EM28XX_AMUX_CD,
EM28XX_AMUX_AUX,
EM28XX_AMUX_PCM_OUT,
};
enum em28xx_aout {
/* AC97 outputs */
EM28XX_AOUT_MASTER = BIT(0),
EM28XX_AOUT_LINE = BIT(1),
EM28XX_AOUT_MONO = BIT(2),
EM28XX_AOUT_LFE = BIT(3),
EM28XX_AOUT_SURR = BIT(4),
/* PCM IN Mixer - used by AC97_RECORD_SELECT register */
EM28XX_AOUT_PCM_IN = BIT(7),
/* Bits 10-8 are used to indicate the PCM IN record select */
EM28XX_AOUT_PCM_MIC_PCM = 0 << 8,
EM28XX_AOUT_PCM_CD = 1 << 8,
EM28XX_AOUT_PCM_VIDEO = 2 << 8,
EM28XX_AOUT_PCM_AUX = 3 << 8,
EM28XX_AOUT_PCM_LINE = 4 << 8,
EM28XX_AOUT_PCM_STEREO = 5 << 8,
EM28XX_AOUT_PCM_MONO = 6 << 8,
EM28XX_AOUT_PCM_PHONE = 7 << 8,
};
static inline int ac97_return_record_select(int a_out)
{
return (a_out & 0x700) >> 8;
}
struct em28xx_reg_seq {
int reg;
unsigned char val, mask;
int sleep;
};
struct em28xx_input {
enum enum28xx_itype type;
unsigned int vmux;
enum em28xx_amux amux;
enum em28xx_aout aout;
const struct em28xx_reg_seq *gpio;
};
#define INPUT(nr) (&em28xx_boards[dev->model].input[nr])
enum em28xx_decoder {
EM28XX_NODECODER = 0,
EM28XX_TVP5150,
EM28XX_SAA711X,
EM28XX_BUILTIN,
};
/* Built in decoder capture options */
#define EM2828X_COMPOSITE 0
#define EM2828X_SVIDEO 1
#define EM2828X_TELEVISION 2
enum em28xx_sensor {
EM28XX_NOSENSOR = 0,
EM28XX_MT9V011,
EM28XX_MT9M001,
EM28XX_MT9M111,
EM28XX_OV2640,
};
enum em28xx_adecoder {
EM28XX_NOADECODER = 0,
EM28XX_TVAUDIO,
};
enum em28xx_led_role {
EM28XX_LED_ANALOG_CAPTURING = 0,
EM28XX_LED_DIGITAL_CAPTURING,
EM28XX_LED_DIGITAL_CAPTURING_TS2,
EM28XX_LED_ILLUMINATION,
EM28XX_NUM_LED_ROLES, /* must be the last */
};
struct em28xx_led {
enum em28xx_led_role role;
u8 gpio_reg;
u8 gpio_mask;
bool inverted;
};
enum em28xx_button_role {
EM28XX_BUTTON_SNAPSHOT = 0,
EM28XX_BUTTON_ILLUMINATION,
EM28XX_NUM_BUTTON_ROLES, /* must be the last */
};
struct em28xx_button {
enum em28xx_button_role role;
u8 reg_r;
u8 reg_clearing;
u8 mask;
bool inverted;
};
enum em2828x_media_pads {
EM2828X_PAD_INPUT,
EM2828X_PAD_VID_OUT,
EM2828X_NUM_PADS
};
struct em28xx_board {
char *name;
int vchannels;
int tuner_type;
int tuner_addr;
unsigned int def_i2c_bus; /* Default I2C bus */
/* i2c flags */
unsigned int tda9887_conf;
/* GPIO sequences */
const struct em28xx_reg_seq *dvb_gpio;
const struct em28xx_reg_seq *suspend_gpio;
const struct em28xx_reg_seq *tuner_gpio;
const struct em28xx_reg_seq *mute_gpio;
unsigned int is_em2800:1;
unsigned int has_msp34xx:1;
unsigned int mts_firmware:1;
unsigned int max_range_640_480:1;
unsigned int has_dvb:1;
unsigned int has_dual_ts:1;
unsigned int is_webcam:1;
unsigned int valid:1;
unsigned int has_ir_i2c:1;
unsigned char xclk, i2c_speed;
unsigned char radio_addr;
unsigned short tvaudio_addr;
enum em28xx_decoder decoder;
enum em28xx_adecoder adecoder;
struct em28xx_input input[MAX_EM28XX_INPUT];
struct em28xx_input radio;
char *ir_codes;
/* LEDs that need to be controlled explicitly */
struct em28xx_led *leds;
/* Buttons */
const struct em28xx_button *buttons;
};
struct em28xx_eeprom {
u8 id[4]; /* 1a eb 67 95 */
__le16 vendor_ID;
__le16 product_ID;
__le16 chip_conf;
__le16 board_conf;
__le16 string1, string2, string3;
u8 string_idx_table;
};
#define EM28XX_CAPTURE_STREAM_EN 1
/* em28xx extensions */
#define EM28XX_AUDIO 0x10
#define EM28XX_DVB 0x20
#define EM28XX_RC 0x30
#define EM28XX_V4L2 0x40
/* em28xx resource types (used for res_get/res_lock etc */
#define EM28XX_RESOURCE_VIDEO 0x01
#define EM28XX_RESOURCE_VBI 0x02
struct em28xx_v4l2 {
struct kref ref;
struct em28xx *dev;
struct v4l2_device v4l2_dev;
struct v4l2_ctrl_handler ctrl_handler;
struct video_device vdev;
struct video_device vbi_dev;
struct video_device radio_dev;
/* Videobuf2 */
struct vb2_queue vb_vidq;
struct vb2_queue vb_vbiq;
struct mutex vb_queue_lock; /* Protects vb_vidq */
struct mutex vb_vbi_queue_lock; /* Protects vb_vbiq */
u8 vinmode;
u8 vinctl;
/* Camera specific fields */
int sensor_xres;
int sensor_yres;
int sensor_xtal;
int users; /* user count for exclusive use */
int streaming_users; /* number of actively streaming users */
u32 frequency; /* selected tuner frequency */
struct em28xx_fmt *format;
v4l2_std_id norm; /* selected tv norm */
/* Progressive/interlaced mode */
bool progressive;
int interlaced_fieldmode; /* 1=interlaced fields, 0=just top fields */
/* FIXME: everything else than interlaced_fieldmode=1 doesn't work */
/* Frame properties */
int width; /* current frame width */
int height; /* current frame height */
unsigned int hscale; /* horizontal scale factor (see datasheet) */
unsigned int vscale; /* vertical scale factor (see datasheet) */
unsigned int vbi_width;
unsigned int vbi_height; /* lines per field */
/* Capture state tracking */
int capture_type;
bool top_field;
int vbi_read;
unsigned int field_count;
#ifdef CONFIG_MEDIA_CONTROLLER
struct media_pad video_pad, vbi_pad;
struct media_pad decoder_pads[EM2828X_NUM_PADS];
struct media_entity *decoder;
#endif
};
struct em28xx_audio {
char name[50];
unsigned int num_urb;
char **transfer_buffer;
struct urb **urb;
struct usb_device *udev;
unsigned int capture_transfer_done;
struct snd_pcm_substream *capture_pcm_substream;
unsigned int hwptr_done_capture;
struct snd_card *sndcard;
size_t period;
int users;
spinlock_t slock; /* Protects struct em28xx_audio */
/* Controls streaming */
struct work_struct wq_trigger; /* trigger to start/stop audio */
atomic_t stream_started; /* stream should be running if true */
};
enum em28xx_i2c_algo_type {
EM28XX_I2C_ALGO_EM28XX = 0,
EM28XX_I2C_ALGO_EM2800,
EM28XX_I2C_ALGO_EM25XX_BUS_B,
};
struct em28xx_i2c_bus {
struct em28xx *dev;
unsigned int bus;
enum em28xx_i2c_algo_type algo_type;
};
/* main device struct */
struct em28xx {
struct kref ref;
// Sub-module data
struct em28xx_v4l2 *v4l2;
struct em28xx_dvb *dvb;
struct em28xx_audio adev;
struct em28xx_IR *ir;
// generic device properties
int model; // index in the device_data struct
int devno; // marks the number of this device
enum em28xx_chip_id chip_id;
unsigned int is_em25xx:1; // em25xx/em276x/7x/8x family bridge
unsigned int disconnected:1; // device has been disconnected
unsigned int has_video:1;
unsigned int is_audio_only:1;
unsigned int is_webcam:1;
unsigned int has_msp34xx:1;
unsigned int i2c_speed:2;
enum em28xx_int_audio_type int_audio_type;
enum em28xx_usb_audio_type usb_audio_type;
unsigned char name[32];
struct em28xx_board board;
enum em28xx_sensor em28xx_sensor; // camera specific
// Some older em28xx chips needs a waiting time after writing
unsigned int wait_after_write;
struct list_head devlist;
u32 i2s_speed; // I2S speed for audio digital stream
struct em28xx_audio_mode audio_mode;
int tuner_type; // type of the tuner
// i2c i/o
struct i2c_adapter i2c_adap[NUM_I2C_BUSES];
struct i2c_client i2c_client[NUM_I2C_BUSES];
struct em28xx_i2c_bus i2c_bus[NUM_I2C_BUSES];
unsigned char eeprom_addrwidth_16bit:1;
unsigned int def_i2c_bus; // Default I2C bus
unsigned int cur_i2c_bus; // Current I2C bus
struct rt_mutex i2c_bus_lock;
// video for linux
unsigned int ctl_input; // selected input
unsigned int ctl_ainput;// selected audio input
unsigned int ctl_aoutput;// selected audio output
enum em28xx_amux amux_map[MAX_EM28XX_INPUT];
int mute;
int volume;
unsigned long hash; // eeprom hash - for boards with generic ID
unsigned long i2c_hash; // i2c devicelist hash -
// for boards with generic ID
struct work_struct request_module_wk;
// locks
struct mutex lock; /* protects em28xx struct */
struct mutex ctrl_urb_lock; /* protects urb_buf */
// resources in use
unsigned int resources;
// eeprom content
u8 *eedata;
u16 eedata_len;
// Isoc control struct
struct em28xx_dmaqueue vidq;
struct em28xx_dmaqueue vbiq;
struct em28xx_usb_ctl usb_ctl;
spinlock_t slock; /* Protects em28xx video/vbi/dvb IRQ stream data */
// usb transfer
struct usb_interface *intf; // the usb interface
u8 ifnum; // number of the assigned usb interface
u8 analog_ep_isoc; // address of isoc endpoint for analog
u8 analog_ep_bulk; // address of bulk endpoint for analog
u8 dvb_ep_isoc_ts2; // address of isoc endpoint for DVB TS2
u8 dvb_ep_bulk_ts2; // address of bulk endpoint for DVB TS2
u8 dvb_ep_isoc; // address of isoc endpoint for DVB
u8 dvb_ep_bulk; // address of bulk endpoint for DVB
int alt; // alternate setting
int max_pkt_size; // max packet size of the selected ep at alt
int packet_multiplier; // multiplier for wMaxPacketSize, used for
// URB buffer size definition
int num_alt; // number of alternative settings
unsigned int *alt_max_pkt_size_isoc; // array of isoc wMaxPacketSize
unsigned int analog_xfer_bulk:1; // use bulk instead of isoc
// transfers for analog
int dvb_alt_isoc; // alternate setting for DVB isoc transfers
unsigned int dvb_max_pkt_size_isoc; // isoc max packet size of the
// selected DVB ep at dvb_alt
unsigned int dvb_max_pkt_size_isoc_ts2; // isoc max packet size of the
// selected DVB ep at dvb_alt
unsigned int dvb_xfer_bulk:1; // use bulk instead of isoc
// transfers for DVB
char urb_buf[URB_MAX_CTRL_SIZE]; // urb control msg buffer
// helper funcs that call usb_control_msg
int (*em28xx_write_regs)(struct em28xx *dev, u16 reg,
char *buf, int len);
int (*em28xx_read_reg)(struct em28xx *dev, u16 reg);
int (*em28xx_read_reg_req_len)(struct em28xx *dev, u8 req, u16 reg,
char *buf, int len);
int (*em28xx_write_regs_req)(struct em28xx *dev, u8 req, u16 reg,
char *buf, int len);
int (*em28xx_read_reg_req)(struct em28xx *dev, u8 req, u16 reg);
int (*em28xx_set_analog_freq)(struct em28xx *dev, u32 freq);
enum em28xx_mode mode;
// Button state polling
struct delayed_work buttons_query_work;
u8 button_polling_addresses[EM28XX_NUM_BUTTON_ADDRESSES_MAX];
u8 button_polling_last_values[EM28XX_NUM_BUTTON_ADDRESSES_MAX];
u8 num_button_polling_addresses;
u16 button_polling_interval; // [ms]
// Snapshot button input device
char snapshot_button_path[30]; // path of the input dev
struct input_dev *sbutton_input_dev;
int analog_xfer_mode;
#ifdef CONFIG_MEDIA_CONTROLLER
struct media_device *media_dev;
struct media_entity input_ent[MAX_EM28XX_INPUT];
struct media_pad input_pad[MAX_EM28XX_INPUT];
#endif
struct em28xx *dev_next;
int ts;
};
#define kref_to_dev(d) container_of(d, struct em28xx, ref)
struct em28xx_ops {
struct list_head next;
char *name;
int id;
int (*init)(struct em28xx *dev);
int (*fini)(struct em28xx *dev);
int (*suspend)(struct em28xx *dev);
int (*resume)(struct em28xx *dev);
};
/* Provided by em28xx-i2c.c */
void em28xx_do_i2c_scan(struct em28xx *dev, unsigned int bus);
int em28xx_i2c_register(struct em28xx *dev, unsigned int bus,
enum em28xx_i2c_algo_type algo_type);
int em28xx_i2c_unregister(struct em28xx *dev, unsigned int bus);
/* Provided by em28xx-core.c */
int em28xx_read_reg_req_len(struct em28xx *dev, u8 req, u16 reg,
char *buf, int len);
int em28xx_read_reg_req(struct em28xx *dev, u8 req, u16 reg);
int em28xx_read_reg(struct em28xx *dev, u16 reg);
int em28xx_write_regs_req(struct em28xx *dev, u8 req, u16 reg, char *buf,
int len);
int em28xx_write_regs(struct em28xx *dev, u16 reg, char *buf, int len);
int em28xx_write_reg(struct em28xx *dev, u16 reg, u8 val);
int em28xx_write_reg_bits(struct em28xx *dev, u16 reg, u8 val,
u8 bitmask);
int em28xx_toggle_reg_bits(struct em28xx *dev, u16 reg, u8 bitmask);
int em28xx_read_ac97(struct em28xx *dev, u8 reg);
int em28xx_write_ac97(struct em28xx *dev, u8 reg, u16 val);
int em28xx_audio_analog_set(struct em28xx *dev);
int em28xx_audio_setup(struct em28xx *dev);
void em2828X_decoder_vmux(struct em28xx *dev, unsigned int vin);
const struct em28xx_led *em28xx_find_led(struct em28xx *dev,
enum em28xx_led_role role);
int em28xx_capture_start(struct em28xx *dev, int start);
int em28xx_alloc_urbs(struct em28xx *dev, enum em28xx_mode mode, int xfer_bulk,
int num_bufs, int max_pkt_size, int packet_multiplier);
int em28xx_init_usb_xfer(struct em28xx *dev, enum em28xx_mode mode,
int xfer_bulk,
int num_bufs, int max_pkt_size, int packet_multiplier,
int (*urb_data_copy)
(struct em28xx *dev, struct urb *urb));
void em28xx_uninit_usb_xfer(struct em28xx *dev, enum em28xx_mode mode);
void em28xx_stop_urbs(struct em28xx *dev);
int em28xx_set_mode(struct em28xx *dev, enum em28xx_mode set_mode);
int em28xx_gpio_set(struct em28xx *dev, const struct em28xx_reg_seq *gpio);
int em28xx_register_extension(struct em28xx_ops *dev);
void em28xx_unregister_extension(struct em28xx_ops *dev);
void em28xx_init_extension(struct em28xx *dev);
void em28xx_close_extension(struct em28xx *dev);
int em28xx_suspend_extension(struct em28xx *dev);
int em28xx_resume_extension(struct em28xx *dev);
/* Provided by em28xx-cards.c */
extern const struct em28xx_board em28xx_boards[];
extern struct usb_device_id em28xx_id_table[];
int em28xx_tuner_callback(void *ptr, int component, int command, int arg);
void em28xx_setup_xc3028(struct em28xx *dev, struct xc2028_ctrl *ctl);
void em28xx_free_device(struct kref *ref);
/* Provided by em28xx-camera.c */
int em28xx_detect_sensor(struct em28xx *dev);
int em28xx_init_camera(struct em28xx *dev);
#endif