#include <linux/version.h>
#include <linux/mm.h>
#include <linux/mutex.h>
+#include <linux/slab.h>
#include <media/v4l2-common.h>
#include <media/v4l2-ioctl.h>
bytes_parsed = 0;
if (dma_q->is_partial_line) {
- /* Handle the case where we were working on a partial line */
+ /* Handle the case of a partial line */
sav_eav = dma_q->last_sav;
} else {
- /* Check for a SAV/EAV overlapping the buffer boundary */
+ /* Check for a SAV/EAV overlapping
+ the buffer boundary */
sav_eav =
cx231xx_find_boundary_SAV_EAV(p_buffer,
dma_q->partial_buf,
the last buffer or a partial line */
if (sav_eav) {
bytes_parsed += cx231xx_get_video_line(dev, dma_q,
- sav_eav, /* SAV/EAV */
- p_buffer + bytes_parsed, /* p_buffer */
- buffer_size - bytes_parsed); /* buffer size */
+ sav_eav, /* SAV/EAV */
+ p_buffer + bytes_parsed, /* p_buffer */
+ buffer_size - bytes_parsed);/* buf size */
}
/* Now parse data that is completely in this buffer */
while (bytes_parsed < buffer_size) {
u32 bytes_used = 0;
- sav_eav = cx231xx_find_next_SAV_EAV(p_buffer + bytes_parsed, /* p_buffer */
- buffer_size - bytes_parsed, /* buffer size */
- &bytes_used); /* Receives bytes used to get SAV/EAV */
+ sav_eav = cx231xx_find_next_SAV_EAV(
+ p_buffer + bytes_parsed, /* p_buffer */
+ buffer_size - bytes_parsed, /* buf size */
+ &bytes_used);/* bytes used to get SAV/EAV */
bytes_parsed += bytes_used;
sav_eav &= 0xF0;
if (sav_eav && (bytes_parsed < buffer_size)) {
bytes_parsed += cx231xx_get_video_line(dev,
- dma_q, sav_eav, /* SAV/EAV */
- p_buffer + bytes_parsed, /* p_buffer */
- buffer_size - bytes_parsed); /* buffer size */
+ dma_q, sav_eav, /* SAV/EAV */
+ p_buffer + bytes_parsed,/* p_buffer */
+ buffer_size - bytes_parsed);/*buf size*/
}
}
f.frequency = dev->ctl_freq;
f.type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
- cx231xx_i2c_call_clients(&dev->i2c_bus[1], VIDIOC_S_FREQUENCY, &f);
+ call_all(dev, tuner, s_frequency, &f);
return 0;
}
void video_mux(struct cx231xx *dev, int index)
{
-
- struct v4l2_routing route;
-
- route.input = INPUT(index)->vmux;
- route.output = 0;
dev->video_input = index;
dev->ctl_ainput = INPUT(index)->amux;
cx231xx_set_video_input_mux(dev, index);
- cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_INT_S_VIDEO_ROUTING,
- &route);
+ cx25840_call(dev, video, s_routing, INPUT(index)->vmux, 0, 0);
cx231xx_set_audio_input(dev, dev->ctl_ainput);
return 0;
}
-void get_scale(struct cx231xx *dev,
- unsigned int width, unsigned int height,
- unsigned int *hscale, unsigned int *vscale)
+static void get_scale(struct cx231xx *dev,
+ unsigned int width, unsigned int height,
+ unsigned int *hscale, unsigned int *vscale)
{
unsigned int maxw = norm_maxw(dev);
unsigned int maxh = norm_maxh(dev);
*vscale = (((unsigned long)maxh) << 12) / height - 4096L;
if (*vscale >= 0x4000)
*vscale = 0x3fff;
-
- dev->hscale = *hscale;
- dev->vscale = *vscale;
-
}
/* ------------------------------------------------------------------
f->fmt.pix.width = dev->width;
f->fmt.pix.height = dev->height;
- f->fmt.pix.pixelformat = dev->format->fourcc;;
- f->fmt.pix.bytesperline = (dev->width * dev->format->depth + 7) >> 3;;
+ f->fmt.pix.pixelformat = dev->format->fourcc;
+ f->fmt.pix.bytesperline = (dev->width * dev->format->depth + 7) >> 3;
f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * dev->height;
f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
{
struct cx231xx_fh *fh = priv;
struct cx231xx *dev = fh->dev;
- int width = f->fmt.pix.width;
- int height = f->fmt.pix.height;
+ unsigned int width = f->fmt.pix.width;
+ unsigned int height = f->fmt.pix.height;
unsigned int maxw = norm_maxw(dev);
unsigned int maxh = norm_maxh(dev);
unsigned int hscale, vscale;
/* width must even because of the YUYV format
height must be even because of interlacing */
- height &= 0xfffe;
- width &= 0xfffe;
-
- if (unlikely(height < 32))
- height = 32;
- if (unlikely(height > maxh))
- height = maxh;
- if (unlikely(width < 48))
- width = 48;
- if (unlikely(width > maxw))
- width = maxw;
+ v4l_bound_align_image(&width, 48, maxw, 1, &height, 32, maxh, 1, 0);
get_scale(dev, width, height, &hscale, &vscale);
dev->format = fmt;
get_scale(dev, dev->width, dev->height, &dev->hscale, &dev->vscale);
- cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_S_FMT, f);
+ call_all(dev, video, s_fmt, f);
/* Set the correct alternate setting for this resolution */
cx231xx_resolution_set(dev);
return 0;
}
-static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id * norm)
+static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *norm)
{
struct cx231xx_fh *fh = priv;
struct cx231xx *dev = fh->dev;
dev->height = f.fmt.pix.height;
get_scale(dev, dev->width, dev->height, &dev->hscale, &dev->vscale);
- cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_S_STD, &dev->norm);
+ call_all(dev, core, s_std, dev->norm);
mutex_unlock(&dev->lock);
*qc = cx231xx_ctls[i].v;
mutex_lock(&dev->lock);
- cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_QUERYCTRL, qc);
+ call_all(dev, core, queryctrl, qc);
mutex_unlock(&dev->lock);
if (qc->type)
return rc;
mutex_lock(&dev->lock);
-
- cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_G_CTRL, ctrl);
-
+ call_all(dev, core, g_ctrl, ctrl);
mutex_unlock(&dev->lock);
return rc;
}
return rc;
mutex_lock(&dev->lock);
-
- cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_S_CTRL, ctrl);
-
+ call_all(dev, core, s_ctrl, ctrl);
mutex_unlock(&dev->lock);
return rc;
}
return -EINVAL;
#if 0
mutex_lock(&dev->lock);
-
- cx231xx_i2c_call_clients(&dev->i2c_bus[1], VIDIOC_S_TUNER, t);
-
+ call_all(dev, tuner, s_tuner, t);
mutex_unlock(&dev->lock);
#endif
return 0;
f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
f->frequency = dev->ctl_freq;
- cx231xx_i2c_call_clients(&dev->i2c_bus[1], VIDIOC_G_FREQUENCY, f);
+ call_all(dev, tuner, g_frequency, f);
mutex_unlock(&dev->lock);
if (dev->tuner_type == TUNER_XC5000) {
if (dev->cx231xx_set_analog_freq != NULL)
dev->cx231xx_set_analog_freq(dev, f->frequency);
- } else {
- cx231xx_i2c_call_clients(&dev->i2c_bus[1],
- VIDIOC_S_FREQUENCY, f);
- }
+ } else
+ call_all(dev, tuner, s_frequency, f);
mutex_unlock(&dev->lock);
#ifdef CONFIG_VIDEO_ADV_DEBUG
/*
- -R, --list-registers=type=<host/i2cdrv/i2caddr>,chip=<chip>[,min=<addr>,max=<addr>]
+ -R, --list-registers=type=<host/i2cdrv/i2caddr>,
+ chip=<chip>[,min=<addr>,max=<addr>]
dump registers from <min> to <max> [VIDIOC_DBG_G_REGISTER]
- -r, --set-register=type=<host/i2cdrv/i2caddr>,chip=<chip>,reg=<addr>,val=<val>
+ -r, --set-register=type=<host/i2cdrv/i2caddr>,
+ chip=<chip>,reg=<addr>,val=<val>
set the register [VIDIOC_DBG_S_REGISTER]
if type == host, then <chip> is the hosts chip ID (default 0)
reg->val = value[0] | value[1] << 8 |
value[2] << 16 | value[3] << 24;
break;
- case 1: /* Colibri - read byte */
- ret = cx231xx_read_i2c_data(dev, Colibri_DEVICE_ADDRESS,
+ case 1: /* AFE - read byte */
+ ret = cx231xx_read_i2c_data(dev, AFE_DEVICE_ADDRESS,
(u16)reg->reg, 2, &data, 1);
reg->val = le32_to_cpu(data & 0xff);
break;
- case 14: /* Colibri - read dword */
- ret = cx231xx_read_i2c_data(dev, Colibri_DEVICE_ADDRESS,
+ case 14: /* AFE - read dword */
+ ret = cx231xx_read_i2c_data(dev, AFE_DEVICE_ADDRESS,
(u16)reg->reg, 2, &data, 4);
reg->val = le32_to_cpu(data);
break;
- case 2: /* Hammerhead - read byte */
- ret = cx231xx_read_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS,
+ case 2: /* Video Block - read byte */
+ ret = cx231xx_read_i2c_data(dev, VID_BLK_I2C_ADDRESS,
(u16)reg->reg, 2, &data, 1);
reg->val = le32_to_cpu(data & 0xff);
break;
- case 24: /* Hammerhead - read dword */
- ret = cx231xx_read_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS,
+ case 24: /* Video Block - read dword */
+ ret = cx231xx_read_i2c_data(dev, VID_BLK_I2C_ADDRESS,
(u16)reg->reg, 2, &data, 4);
reg->val = le32_to_cpu(data);
break;
- case 3: /* flatiron - read byte */
+ case 3: /* I2S block - read byte */
ret = cx231xx_read_i2c_data(dev,
- Flatrion_DEVICE_ADDRESS,
+ I2S_BLK_DEVICE_ADDRESS,
(u16)reg->reg, 1,
&data, 1);
reg->val = le32_to_cpu(data & 0xff);
break;
- case 34: /* flatiron - read dword */
+ case 34: /* I2S Block - read dword */
ret =
- cx231xx_read_i2c_data(dev, Flatrion_DEVICE_ADDRESS,
+ cx231xx_read_i2c_data(dev, I2S_BLK_DEVICE_ADDRESS,
(u16)reg->reg, 1, &data, 4);
reg->val = le32_to_cpu(data);
break;
return ret < 0 ? ret : 0;
case V4L2_CHIP_MATCH_I2C_DRIVER:
- cx231xx_i2c_call_clients(&dev->i2c_bus[0],
- VIDIOC_DBG_G_REGISTER, reg);
+ call_all(dev, core, g_register, reg);
return 0;
case V4L2_CHIP_MATCH_I2C_ADDR:
/* Not supported yet */
}
mutex_lock(&dev->lock);
- cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_DBG_G_REGISTER, reg);
+ call_all(dev, core, g_register, reg);
mutex_unlock(&dev->lock);
return ret;
(u16)reg->reg, data,
4);
break;
- case 1: /* Colibri - read byte */
+ case 1: /* AFE - read byte */
ret = cx231xx_write_i2c_data(dev,
- Colibri_DEVICE_ADDRESS,
+ AFE_DEVICE_ADDRESS,
(u16)reg->reg, 2,
value, 1);
break;
- case 14: /* Colibri - read dword */
+ case 14: /* AFE - read dword */
ret = cx231xx_write_i2c_data(dev,
- Colibri_DEVICE_ADDRESS,
+ AFE_DEVICE_ADDRESS,
(u16)reg->reg, 2,
value, 4);
break;
- case 2: /* Hammerhead - read byte */
+ case 2: /* Video Block - read byte */
ret =
cx231xx_write_i2c_data(dev,
- HAMMERHEAD_I2C_ADDRESS,
+ VID_BLK_I2C_ADDRESS,
(u16)reg->reg, 2,
value, 1);
break;
- case 24: /* Hammerhead - read dword */
+ case 24: /* Video Block - read dword */
ret =
cx231xx_write_i2c_data(dev,
- HAMMERHEAD_I2C_ADDRESS,
+ VID_BLK_I2C_ADDRESS,
(u16)reg->reg, 2,
value, 4);
break;
- case 3: /* flatiron - read byte */
+ case 3: /* I2S block - read byte */
ret =
cx231xx_write_i2c_data(dev,
- Flatrion_DEVICE_ADDRESS,
+ I2S_BLK_DEVICE_ADDRESS,
(u16)reg->reg, 1,
value, 1);
break;
- case 34: /* flatiron - read dword */
+ case 34: /* I2S block - read dword */
ret =
cx231xx_write_i2c_data(dev,
- Flatrion_DEVICE_ADDRESS,
+ I2S_BLK_DEVICE_ADDRESS,
(u16)reg->reg, 1,
value, 4);
break;
}
mutex_lock(&dev->lock);
-
- cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_DBG_S_REGISTER, reg);
-
+ call_all(dev, core, s_register, reg);
mutex_unlock(&dev->lock);
return ret;
if (likely(rc >= 0))
rc = videobuf_streamon(&fh->vb_vidq);
+ call_all(dev, video, s_stream, 1);
+
mutex_unlock(&dev->lock);
return rc;
if (rc < 0)
return rc;
- if ((fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) ||
+ if ((fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) &&
(fh->type != V4L2_BUF_TYPE_VBI_CAPTURE))
return -EINVAL;
if (type != fh->type)
mutex_lock(&dev->lock);
+ cx25840_call(dev, video, s_stream, 0);
+
videobuf_streamoff(&fh->vb_vidq);
res_free(fh);
strlcpy(cap->driver, "cx231xx", sizeof(cap->driver));
strlcpy(cap->card, cx231xx_boards[dev->model].name, sizeof(cap->card));
- strlcpy(cap->bus_info, dev_name(&dev->udev->dev),
- sizeof(cap->bus_info));
+ usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info));
cap->version = CX231XX_VERSION_CODE;
cap->capabilities = V4L2_CAP_VBI_CAPTURE |
#if 0
- V4L2_CAP_SLICED_VBI_CAPTURE |
+ V4L2_CAP_SLICED_VBI_CAPTURE |
#endif
- V4L2_CAP_VIDEO_CAPTURE |
- V4L2_CAP_AUDIO | V4L2_CAP_READWRITE | V4L2_CAP_STREAMING;
+ V4L2_CAP_VIDEO_CAPTURE |
+ V4L2_CAP_AUDIO |
+ V4L2_CAP_READWRITE |
+ V4L2_CAP_STREAMING;
if (dev->tuner_type != TUNER_ABSENT)
cap->capabilities |= V4L2_CAP_TUNER;
f->fmt.sliced.service_set = 0;
- cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_G_FMT, f);
+ call_all(dev, video, g_fmt, f);
if (f->fmt.sliced.service_set == 0)
rc = -EINVAL;
return rc;
mutex_lock(&dev->lock);
- cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_G_FMT, f);
+ call_all(dev, video, g_fmt, f);
mutex_unlock(&dev->lock);
if (f->fmt.sliced.service_set == 0)
t->type = V4L2_TUNER_RADIO;
mutex_lock(&dev->lock);
- cx231xx_i2c_call_clients(&dev->i2c_bus[1], VIDIOC_G_TUNER, t);
+ call_all(dev, tuner, s_tuner, t);
mutex_unlock(&dev->lock);
return 0;
return -EINVAL;
mutex_lock(&dev->lock);
- cx231xx_i2c_call_clients(&dev->i2c_bus[1], VIDIOC_S_TUNER, t);
+ call_all(dev, tuner, s_tuner, t);
mutex_unlock(&dev->lock);
return 0;
*/
static int cx231xx_v4l2_open(struct file *filp)
{
- int minor = video_devdata(filp)->minor;
int errCode = 0, radio = 0;
- struct cx231xx *dev = NULL;
+ struct video_device *vdev = video_devdata(filp);
+ struct cx231xx *dev = video_drvdata(filp);
struct cx231xx_fh *fh;
enum v4l2_buf_type fh_type = 0;
- dev = cx231xx_get_device(minor, &fh_type, &radio);
- if (NULL == dev)
- return -ENODEV;
+ switch (vdev->vfl_type) {
+ case VFL_TYPE_GRABBER:
+ fh_type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ break;
+ case VFL_TYPE_VBI:
+ fh_type = V4L2_BUF_TYPE_VBI_CAPTURE;
+ break;
+ case VFL_TYPE_RADIO:
+ radio = 1;
+ break;
+ }
mutex_lock(&dev->lock);
- cx231xx_videodbg("open minor=%d type=%s users=%d\n",
- minor, v4l2_type_names[fh_type], dev->users);
+ cx231xx_videodbg("open dev=%s type=%s users=%d\n",
+ video_device_node_name(vdev), v4l2_type_names[fh_type],
+ dev->users);
#if 0
errCode = cx231xx_set_mode(dev, CX231XX_ANALOG_MODE);
/* cx231xx_start_radio(dev); */
- cx231xx_i2c_call_clients(&dev->i2c_bus[1], AUDC_SET_RADIO,
- NULL);
+ call_all(dev, tuner, s_radio);
}
dev->users++;
/*FIXME: I2C IR should be disconnected */
if (dev->radio_dev) {
- if (-1 != dev->radio_dev->minor)
+ if (video_is_registered(dev->radio_dev))
video_unregister_device(dev->radio_dev);
else
video_device_release(dev->radio_dev);
dev->radio_dev = NULL;
}
if (dev->vbi_dev) {
- cx231xx_info("V4L2 device /dev/vbi%d deregistered\n",
- dev->vbi_dev->num);
- if (-1 != dev->vbi_dev->minor)
+ cx231xx_info("V4L2 device %s deregistered\n",
+ video_device_node_name(dev->vbi_dev));
+ if (video_is_registered(dev->vbi_dev))
video_unregister_device(dev->vbi_dev);
else
video_device_release(dev->vbi_dev);
dev->vbi_dev = NULL;
}
if (dev->vdev) {
- cx231xx_info("V4L2 device /dev/video%d deregistered\n",
- dev->vdev->num);
- if (-1 != dev->vdev->minor)
+ cx231xx_info("V4L2 device %s deregistered\n",
+ video_device_node_name(dev->vdev));
+ if (video_is_registered(dev->vdev))
video_unregister_device(dev->vdev);
else
video_device_release(dev->vdev);
}
/* Save some power by putting tuner to sleep */
- cx231xx_i2c_call_clients(&dev->i2c_bus[1], TUNER_SET_STANDBY,
- NULL);
+ call_all(dev, core, s_power, 0);
/* do this before setting alternate! */
cx231xx_uninit_isoc(dev);
.fops = &cx231xx_v4l_fops,
.release = video_device_release,
.ioctl_ops = &video_ioctl_ops,
- .minor = -1,
.tvnorms = V4L2_STD_ALL,
.current_norm = V4L2_STD_PAL,
};
.name = "cx231xx-radio",
.fops = &radio_fops,
.ioctl_ops = &radio_ioctl_ops,
- .minor = -1,
};
/******************************** usb interface ******************************/
-static struct video_device *cx231xx_vdev_init(struct cx231xx *dev, const struct video_device
- *template, const char *type_name)
+static struct video_device *cx231xx_vdev_init(struct cx231xx *dev,
+ const struct video_device
+ *template, const char *type_name)
{
struct video_device *vfd;
return NULL;
*vfd = *template;
- vfd->minor = -1;
- vfd->parent = &dev->udev->dev;
+ vfd->v4l2_dev = &dev->v4l2_dev;
vfd->release = video_device_release;
vfd->debug = video_debug;
snprintf(vfd->name, sizeof(vfd->name), "%s %s", dev->name, type_name);
+ video_set_drvdata(vfd, dev);
return vfd;
}
{
int ret;
- cx231xx_info("%s()\n", __func__);
-
cx231xx_info("%s: v4l2 driver version %d.%d.%d\n",
dev->name,
(CX231XX_VERSION_CODE >> 16) & 0xff,
return ret;
}
- cx231xx_info("%s/0: registered device video%d [v4l2]\n",
- dev->name, dev->vdev->num);
+ cx231xx_info("%s/0: registered device %s [v4l2]\n",
+ dev->name, video_device_node_name(dev->vdev));
/* Initialize VBI template */
memcpy(&cx231xx_vbi_template, &cx231xx_video_template,
return ret;
}
- cx231xx_info("%s/0: registered device vbi%d\n",
- dev->name, dev->vbi_dev->num);
+ cx231xx_info("%s/0: registered device %s\n",
+ dev->name, video_device_node_name(dev->vbi_dev));
if (cx231xx_boards[dev->model].radio.type == CX231XX_RADIO) {
dev->radio_dev = cx231xx_vdev_init(dev, &cx231xx_radio_template,
cx231xx_errdev("can't register radio device\n");
return ret;
}
- cx231xx_info("Registered radio device as /dev/radio%d\n",
- dev->radio_dev->num);
+ cx231xx_info("Registered radio device as %s\n",
+ video_device_node_name(dev->radio_dev));
}
- cx231xx_info("V4L2 device registered as /dev/video%d and /dev/vbi%d\n",
- dev->vdev->num, dev->vbi_dev->num);
+ cx231xx_info("V4L2 device registered as %s and %s\n",
+ video_device_node_name(dev->vdev),
+ video_device_node_name(dev->vbi_dev));
return 0;
}