Commit 8d87cb9f authored by Mauro Carvalho Chehab's avatar Mauro Carvalho Chehab

V4L/DVB (5097): Convert cx8800 driver to video_ioctl2 handler

video_ioctl2 handler provides V4L2 API parsing.
Using it makes the driver simpler, and isolates API parsing.
This allows future reusage of driver controls using other ways, like sysfs
and/or procfs and increases isolation of driver-specific handling from the
generic common ioctl processing.
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@infradead.org>
parent fd694964
......@@ -5,6 +5,11 @@
*
* (c) 2003 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
*
* (c) 2005-2006 Mauro Carvalho Chehab <mchehab@infradead.org>
* - Multituner support
* - video_ioctl2 conversion
* - PAL/M fixes
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
......@@ -631,22 +636,22 @@ int cx88_reset(struct cx88_core *core)
/* ------------------------------------------------------------------ */
static unsigned int inline norm_swidth(struct cx88_tvnorm *norm)
static unsigned int inline norm_swidth(struct v4l2_tvnorm *norm)
{
return (norm->id & (V4L2_STD_MN & ~V4L2_STD_PAL_Nc)) ? 754 : 922;
}
static unsigned int inline norm_hdelay(struct cx88_tvnorm *norm)
static unsigned int inline norm_hdelay(struct v4l2_tvnorm *norm)
{
return (norm->id & (V4L2_STD_MN & ~V4L2_STD_PAL_Nc)) ? 135 : 186;
}
static unsigned int inline norm_vdelay(struct cx88_tvnorm *norm)
static unsigned int inline norm_vdelay(struct v4l2_tvnorm *norm)
{
return (norm->id & V4L2_STD_625_50) ? 0x24 : 0x18;
}
static unsigned int inline norm_fsc8(struct cx88_tvnorm *norm)
static unsigned int inline norm_fsc8(struct v4l2_tvnorm *norm)
{
if (norm->id & V4L2_STD_PAL_M)
return 28604892; // 3.575611 MHz
......@@ -666,7 +671,7 @@ static unsigned int inline norm_fsc8(struct cx88_tvnorm *norm)
return 35468950; // 4.43361875 MHz +/- 5 Hz
}
static unsigned int inline norm_htotal(struct cx88_tvnorm *norm)
static unsigned int inline norm_htotal(struct v4l2_tvnorm *norm)
{
unsigned int fsc4=norm_fsc8(norm)/2;
......@@ -677,7 +682,7 @@ static unsigned int inline norm_htotal(struct cx88_tvnorm *norm)
((fsc4+262)/525*1001+15000)/30000;
}
static unsigned int inline norm_vbipack(struct cx88_tvnorm *norm)
static unsigned int inline norm_vbipack(struct v4l2_tvnorm *norm)
{
return (norm->id & V4L2_STD_625_50) ? 511 : 400;
}
......@@ -826,7 +831,7 @@ int cx88_stop_audio_dma(struct cx88_core *core)
static int set_tvaudio(struct cx88_core *core)
{
struct cx88_tvnorm *norm = core->tvnorm;
struct v4l2_tvnorm *norm = core->tvnorm;
if (CX88_VMUX_TELEVISION != INPUT(core->input)->type)
return 0;
......@@ -874,7 +879,7 @@ static int set_tvaudio(struct cx88_core *core)
int cx88_set_tvnorm(struct cx88_core *core, struct cx88_tvnorm *norm)
int cx88_set_tvnorm(struct cx88_core *core, struct v4l2_tvnorm *norm)
{
u32 fsc8;
u32 adc_clock;
......@@ -882,6 +887,7 @@ int cx88_set_tvnorm(struct cx88_core *core, struct cx88_tvnorm *norm)
u32 step_db,step_dr;
u64 tmp64;
u32 bdelay,agcdelay,htotal;
u32 cxiformat, cxoformat;
core->tvnorm = norm;
fsc8 = norm_fsc8(norm);
......@@ -890,9 +896,32 @@ int cx88_set_tvnorm(struct cx88_core *core, struct cx88_tvnorm *norm)
step_db = fsc8;
step_dr = fsc8;
if (norm->id & V4L2_STD_SECAM) {
if (norm->id & V4L2_STD_NTSC_M_JP) {
cxiformat = VideoFormatNTSCJapan;
cxoformat = 0x181f0008;
} else if (norm->id & V4L2_STD_PAL_M) {
cxiformat = VideoFormatPALM;
cxoformat = 0x1c1f0008;
} else if (norm->id & V4L2_STD_PAL_N) {
cxiformat = VideoFormatPALN;
cxoformat = 0x1c1f0008;
} else if (norm->id & V4L2_STD_PAL_Nc) {
cxiformat = VideoFormatPALNC;
cxoformat = 0x1c1f0008;
} else if (norm->id & V4L2_STD_PAL_60) {
cxiformat = VideoFormatPAL60;
cxoformat = 0x181f0008;
} else if (norm->id & V4L2_STD_NTSC) {
cxiformat = VideoFormatNTSC;
cxoformat = 0x181f0008;
} else if (norm->id & V4L2_STD_SECAM) {
cxiformat = VideoFormatSECAM;
cxoformat = 0x181f0008;
step_db = 4250000 * 8;
step_dr = 4406250 * 8;
} else { /* PAL */
cxiformat = VideoFormatPAL;
cxoformat = 0x181f0008;
}
dprintk(1,"set_tvnorm: \"%s\" fsc8=%d adc=%d vdec=%d db/dr=%d/%d\n",
......@@ -900,13 +929,13 @@ int cx88_set_tvnorm(struct cx88_core *core, struct cx88_tvnorm *norm)
set_pll(core,2,vdec_clock);
dprintk(1,"set_tvnorm: MO_INPUT_FORMAT 0x%08x [old=0x%08x]\n",
norm->cxiformat, cx_read(MO_INPUT_FORMAT) & 0x0f);
cx_andor(MO_INPUT_FORMAT, 0xf, norm->cxiformat);
cxiformat, cx_read(MO_INPUT_FORMAT) & 0x0f);
cx_andor(MO_INPUT_FORMAT, 0xf, cxiformat);
// FIXME: as-is from DScaler
dprintk(1,"set_tvnorm: MO_OUTPUT_FORMAT 0x%08x [old=0x%08x]\n",
norm->cxoformat, cx_read(MO_OUTPUT_FORMAT));
cx_write(MO_OUTPUT_FORMAT, norm->cxoformat);
cxoformat, cx_read(MO_OUTPUT_FORMAT));
cx_write(MO_OUTPUT_FORMAT, cxoformat);
// MO_SCONV_REG = adc clock / video dec clock * 2^17
tmp64 = adc_clock * (u64)(1 << 17);
......
......@@ -21,9 +21,11 @@ MODULE_PARM_DESC(vbi_debug,"enable debug messages [vbi]");
/* ------------------------------------------------------------------ */
void cx8800_vbi_fmt(struct cx8800_dev *dev, struct v4l2_format *f)
int cx8800_vbi_fmt (struct file *file, void *priv,
struct v4l2_format *f)
{
memset(&f->fmt.vbi,0,sizeof(f->fmt.vbi));
struct cx8800_fh *fh = priv;
struct cx8800_dev *dev = fh->dev;
f->fmt.vbi.samples_per_line = VBI_LINE_LENGTH;
f->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
......@@ -43,6 +45,7 @@ void cx8800_vbi_fmt(struct cx8800_dev *dev, struct v4l2_format *f)
f->fmt.vbi.start[0] = 7 -1;
f->fmt.vbi.start[1] = 319 -1;
}
return 0;
}
static int cx8800_start_vbi_dma(struct cx8800_dev *dev,
......
/*
*
* device driver for Conexant 2388x based TV cards
......@@ -5,6 +6,11 @@
*
* (c) 2003-04 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
*
* (c) 2005-2006 Mauro Carvalho Chehab <mchehab@infradead.org>
* - Multituner support
* - video_ioctl2 conversion
* - PAL/M fixes
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
......@@ -80,62 +86,47 @@ static LIST_HEAD(cx8800_devlist);
/* ------------------------------------------------------------------- */
/* static data */
static struct cx88_tvnorm tvnorms[] = {
static struct v4l2_tvnorm tvnorms[] = {
{
.name = "NTSC-M",
.id = V4L2_STD_NTSC_M,
.cxiformat = VideoFormatNTSC,
.cxoformat = 0x181f0008,
},{
.name = "NTSC-JP",
.id = V4L2_STD_NTSC_M_JP,
.cxiformat = VideoFormatNTSCJapan,
.cxoformat = 0x181f0008,
},{
.name = "PAL-BG",
.id = V4L2_STD_PAL_BG,
.cxiformat = VideoFormatPAL,
.cxoformat = 0x181f0008,
},{
.name = "PAL-DK",
.id = V4L2_STD_PAL_DK,
.cxiformat = VideoFormatPAL,
.cxoformat = 0x181f0008,
},{
.name = "PAL-I",
.id = V4L2_STD_PAL_I,
.cxiformat = VideoFormatPAL,
.cxoformat = 0x181f0008,
},{
.name = "PAL-M",
.id = V4L2_STD_PAL_M,
.cxiformat = VideoFormatPALM,
.cxoformat = 0x1c1f0008,
},{
.name = "PAL-N",
.id = V4L2_STD_PAL_N,
.cxiformat = VideoFormatPALN,
.cxoformat = 0x1c1f0008,
},{
.name = "PAL-Nc",
.id = V4L2_STD_PAL_Nc,
.cxiformat = VideoFormatPALNC,
.cxoformat = 0x1c1f0008,
},{
.name = "PAL-60",
.id = V4L2_STD_PAL_60,
.cxiformat = VideoFormatPAL60,
.cxoformat = 0x181f0008,
},{
.name = "SECAM-L",
.id = V4L2_STD_SECAM_L,
.cxiformat = VideoFormatSECAM,
.cxoformat = 0x181f0008,
},{
.name = "SECAM-DK",
.id = V4L2_STD_SECAM_DK,
.cxiformat = VideoFormatSECAM,
.cxoformat = 0x181f0008,
}
};
static struct v4l2_tvnorm radionorms[] = {
{
.name = "RADIO",
.id = 0,
}
};
......@@ -364,14 +355,6 @@ int cx8800_ctrl_query(struct v4l2_queryctrl *qctrl)
}
EXPORT_SYMBOL(cx8800_ctrl_query);
static int cx88_queryctrl(struct v4l2_queryctrl *qctrl)
{
qctrl->id = v4l2_ctrl_next(ctrl_classes, qctrl->id);
if (qctrl->id == 0)
return -EINVAL;
return cx8800_ctrl_query(qctrl);
}
/* ------------------------------------------------------------------- */
/* resource management */
......@@ -944,11 +927,12 @@ video_mmap(struct file *file, struct vm_area_struct * vma)
}
/* ------------------------------------------------------------------ */
/* VIDEO CTRL IOCTLS */
/* static int get_control(struct cx8800_dev *dev, struct v4l2_control *ctl) */
static int get_control(struct cx88_core *core, struct v4l2_control *ctl)
static int vidioc_g_ctrl (struct file *file, void *priv,
struct v4l2_control *ctl)
{
/* struct cx88_core *core = dev->core; */
struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
struct cx88_ctrl *c = NULL;
u32 value;
int i;
......@@ -956,7 +940,7 @@ static int get_control(struct cx88_core *core, struct v4l2_control *ctl)
for (i = 0; i < CX8800_CTLS; i++)
if (cx8800_ctls[i].v.id == ctl->id)
c = &cx8800_ctls[i];
if (NULL == c)
if (unlikely(NULL == c))
return -EINVAL;
value = c->sreg ? cx_sread(c->sreg) : cx_read(c->reg);
......@@ -978,19 +962,18 @@ static int get_control(struct cx88_core *core, struct v4l2_control *ctl)
return 0;
}
/* static int set_control(struct cx8800_dev *dev, struct v4l2_control *ctl) */
static int set_control(struct cx88_core *core, struct v4l2_control *ctl)
{
/* struct cx88_core *core = dev->core; */
struct cx88_ctrl *c = NULL;
u32 value,mask;
int i;
for (i = 0; i < CX8800_CTLS; i++) {
if (cx8800_ctls[i].v.id == ctl->id) {
c = &cx8800_ctls[i];
}
}
if (NULL == c)
if (unlikely(NULL == c))
return -EINVAL;
if (ctl->value < c->v.minimum)
......@@ -1042,18 +1025,19 @@ static void init_controls(struct cx88_core *core)
for (i = 0; i < CX8800_CTLS; i++) {
ctrl.id=cx8800_ctls[i].v.id;
ctrl.value=cx8800_ctls[i].v.default_value;
set_control(core, &ctrl);
}
}
/* ------------------------------------------------------------------ */
/* VIDEO IOCTLS */
static int cx8800_g_fmt(struct cx8800_dev *dev, struct cx8800_fh *fh,
static int vidioc_g_fmt_cap (struct file *file, void *priv,
struct v4l2_format *f)
{
switch (f->type) {
case V4L2_BUF_TYPE_VIDEO_CAPTURE:
memset(&f->fmt.pix,0,sizeof(f->fmt.pix));
struct cx8800_fh *fh = priv;
f->fmt.pix.width = fh->width;
f->fmt.pix.height = fh->height;
f->fmt.pix.field = fh->vidq.field;
......@@ -1063,22 +1047,12 @@ static int cx8800_g_fmt(struct cx8800_dev *dev, struct cx8800_fh *fh,
f->fmt.pix.sizeimage =
f->fmt.pix.height * f->fmt.pix.bytesperline;
return 0;
case V4L2_BUF_TYPE_VBI_CAPTURE:
cx8800_vbi_fmt(dev, f);
return 0;
default:
return -EINVAL;
}
}
static int cx8800_try_fmt(struct cx8800_dev *dev, struct cx8800_fh *fh,
static int vidioc_try_fmt_cap (struct file *file, void *priv,
struct v4l2_format *f)
{
struct cx88_core *core = dev->core;
switch (f->type) {
case V4L2_BUF_TYPE_VIDEO_CAPTURE:
{
struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
struct cx8800_fmt *fmt;
enum v4l2_field field;
unsigned int maxw, maxh;
......@@ -1124,62 +1098,29 @@ static int cx8800_try_fmt(struct cx8800_dev *dev, struct cx8800_fh *fh,
f->fmt.pix.height * f->fmt.pix.bytesperline;
return 0;
}
case V4L2_BUF_TYPE_VBI_CAPTURE:
cx8800_vbi_fmt(dev, f);
return 0;
default:
return -EINVAL;
}
}
static int cx8800_s_fmt(struct cx8800_dev *dev, struct cx8800_fh *fh,
static int vidioc_s_fmt_cap (struct file *file, void *priv,
struct v4l2_format *f)
{
int err;
struct cx8800_fh *fh = priv;
int err = vidioc_try_fmt_cap (file,priv,f);
switch (f->type) {
case V4L2_BUF_TYPE_VIDEO_CAPTURE:
err = cx8800_try_fmt(dev,fh,f);
if (0 != err)
return err;
fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat);
fh->width = f->fmt.pix.width;
fh->height = f->fmt.pix.height;
fh->vidq.field = f->fmt.pix.field;
return 0;
case V4L2_BUF_TYPE_VBI_CAPTURE:
cx8800_vbi_fmt(dev, f);
return 0;
default:
return -EINVAL;
}
}
/*
* This function is _not_ called directly, but from
* video_generic_ioctl (and maybe others). userspace
* copying is done already, arg is a kernel pointer.
*/
static int video_do_ioctl(struct inode *inode, struct file *file,
unsigned int cmd, void *arg)
static int vidioc_querycap (struct file *file, void *priv,
struct v4l2_capability *cap)
{
struct cx8800_fh *fh = file->private_data;
struct cx8800_dev *dev = fh->dev;
struct cx8800_dev *dev = ((struct cx8800_fh *)priv)->dev;
struct cx88_core *core = dev->core;
int err;
if (video_debug > 1)
v4l_print_ioctl(core->name,cmd);
switch (cmd) {
/* --- capabilities ------------------------------------------ */
case VIDIOC_QUERYCAP:
{
struct v4l2_capability *cap = arg;
memset(cap,0,sizeof(*cap));
strcpy(cap->driver, "cx8800");
strlcpy(cap->card, cx88_boards[core->board].name,
sizeof(cap->card));
......@@ -1189,60 +1130,32 @@ static int video_do_ioctl(struct inode *inode, struct file *file,
V4L2_CAP_VIDEO_CAPTURE |
V4L2_CAP_READWRITE |
V4L2_CAP_STREAMING |
V4L2_CAP_VBI_CAPTURE |
0;
V4L2_CAP_VBI_CAPTURE;
if (UNSET != core->tuner_type)
cap->capabilities |= V4L2_CAP_TUNER;
return 0;
}
/* --- capture ioctls ---------------------------------------- */
case VIDIOC_ENUM_FMT:
{
struct v4l2_fmtdesc *f = arg;
enum v4l2_buf_type type;
unsigned int index;
}
index = f->index;
type = f->type;
switch (type) {
case V4L2_BUF_TYPE_VIDEO_CAPTURE:
if (index >= ARRAY_SIZE(formats))
return -EINVAL;
memset(f,0,sizeof(*f));
f->index = index;
f->type = type;
strlcpy(f->description,formats[index].name,sizeof(f->description));
f->pixelformat = formats[index].fourcc;
break;
default:
static int vidioc_enum_fmt_cap (struct file *file, void *priv,
struct v4l2_fmtdesc *f)
{
if (unlikely(f->index >= ARRAY_SIZE(formats)))
return -EINVAL;
}
strlcpy(f->description,formats[f->index].name,sizeof(f->description));
f->pixelformat = formats[f->index].fourcc;
return 0;
}
case VIDIOC_G_FMT:
{
struct v4l2_format *f = arg;
return cx8800_g_fmt(dev,fh,f);
}
case VIDIOC_S_FMT:
{
struct v4l2_format *f = arg;
return cx8800_s_fmt(dev,fh,f);
}
case VIDIOC_TRY_FMT:
{
struct v4l2_format *f = arg;
return cx8800_try_fmt(dev,fh,f);
}
}
#ifdef CONFIG_VIDEO_V4L1_COMPAT
/* --- streaming capture ------------------------------------- */
case VIDIOCGMBUF:
{
struct video_mbuf *mbuf = arg;
static int vidiocgmbuf (struct file *file, void *priv, struct video_mbuf *mbuf)
{
struct cx8800_fh *fh = priv;
struct videobuf_queue *q;
struct v4l2_requestbuffers req;
unsigned int i;
int err;
q = get_queue(fh);
memset(&req,0,sizeof(req));
......@@ -1252,7 +1165,7 @@ static int video_do_ioctl(struct inode *inode, struct file *file,
err = videobuf_reqbufs(q,&req);
if (err < 0)
return err;
memset(mbuf,0,sizeof(*mbuf));
mbuf->frames = req.count;
mbuf->size = 0;
for (i = 0; i < mbuf->frames; i++) {
......@@ -1260,106 +1173,85 @@ static int video_do_ioctl(struct inode *inode, struct file *file,
mbuf->size += q->bufs[i]->bsize;
}
return 0;
}
}
#endif
case VIDIOC_REQBUFS:
return videobuf_reqbufs(get_queue(fh), arg);
case VIDIOC_QUERYBUF:
return videobuf_querybuf(get_queue(fh), arg);
case VIDIOC_QBUF:
return videobuf_qbuf(get_queue(fh), arg);
case VIDIOC_DQBUF:
return videobuf_dqbuf(get_queue(fh), arg,
file->f_flags & O_NONBLOCK);
static int vidioc_reqbufs (struct file *file, void *priv, struct v4l2_requestbuffers *p)
{
struct cx8800_fh *fh = priv;
return (videobuf_reqbufs(get_queue(fh), p));
}
case VIDIOC_STREAMON:
{
int res = get_ressource(fh);
static int vidioc_querybuf (struct file *file, void *priv, struct v4l2_buffer *p)
{
struct cx8800_fh *fh = priv;
return (videobuf_querybuf(get_queue(fh), p));
}
if (!res_get(dev,fh,res))
return -EBUSY;
return videobuf_streamon(get_queue(fh));
}
case VIDIOC_STREAMOFF:
{
int res = get_ressource(fh);
static int vidioc_qbuf (struct file *file, void *priv, struct v4l2_buffer *p)
{
struct cx8800_fh *fh = priv;
return (videobuf_qbuf(get_queue(fh), p));
}
err = videobuf_streamoff(get_queue(fh));
if (err < 0)
return err;
res_free(dev,fh,res);
return 0;
}
default:
return cx88_do_ioctl( inode, file, fh->radio, core, cmd, arg, video_do_ioctl );
}
return 0;
static int vidioc_dqbuf (struct file *file, void *priv, struct v4l2_buffer *p)
{
struct cx8800_fh *fh = priv;
return (videobuf_dqbuf(get_queue(fh), p,
file->f_flags & O_NONBLOCK));
}
int cx88_do_ioctl(struct inode *inode, struct file *file, int radio,
struct cx88_core *core, unsigned int cmd, void *arg, v4l2_kioctl driver_ioctl)
static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
{
int err;
struct cx8800_fh *fh = priv;
struct cx8800_dev *dev = fh->dev;
if (video_debug) {
if (video_debug > 1) {
if (_IOC_DIR(cmd) & _IOC_WRITE)
v4l_printk_ioctl_arg("cx88(w)",cmd, arg);
else if (!_IOC_DIR(cmd) & _IOC_READ) {
v4l_print_ioctl("cx88", cmd);
}
} else
v4l_print_ioctl(core->name,cmd);
if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE))
return -EINVAL;
if (unlikely(i != fh->type))
return -EINVAL;
}
if (unlikely(!res_get(dev,fh,get_ressource(fh))))
return -EBUSY;
return videobuf_streamon(get_queue(fh));
}
switch (cmd) {
/* ---------- tv norms ---------- */
case VIDIOC_ENUMSTD:
{
struct v4l2_standard *e = arg;
unsigned int i;
static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
{
struct cx8800_fh *fh = priv;
struct cx8800_dev *dev = fh->dev;
int err, res;
i = e->index;
if (i >= ARRAY_SIZE(tvnorms))
if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
return -EINVAL;
err = v4l2_video_std_construct(e, tvnorms[e->index].id,
tvnorms[e->index].name);
e->index = i;
if (i != fh->type)
return -EINVAL;
res = get_ressource(fh);
err = videobuf_streamoff(get_queue(fh));
if (err < 0)
return err;
res_free(dev,fh,res);
return 0;
}
case VIDIOC_G_STD:
{
v4l2_std_id *id = arg;
*id = core->tvnorm->id;
return 0;
}
case VIDIOC_S_STD:
{
v4l2_std_id *id = arg;
unsigned int i;
}
for(i = 0; i < ARRAY_SIZE(tvnorms); i++)
if (*id & tvnorms[i].id)
break;
if (i == ARRAY_SIZE(tvnorms))
return -EINVAL;
static int vidioc_s_std (struct file *file, void *priv, unsigned int i)
{
struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
mutex_lock(&core->lock);
cx88_set_tvnorm(core,&tvnorms[i]);
mutex_unlock(&core->lock);
return 0;
}
}
/* only one input in this sample driver */
static int vidioc_enum_input (struct file *file, void *priv,
struct v4l2_input *i)
{
struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
/* ------ input switching ---------- */
case VIDIOC_ENUMINPUT:
{
static const char *iname[] = {
[ CX88_VMUX_COMPOSITE1 ] = "Composite1",
[ CX88_VMUX_COMPOSITE2 ] = "Composite2",
......@@ -1371,7 +1263,6 @@ int cx88_do_ioctl(struct inode *inode, struct file *file, int radio,
[ CX88_VMUX_DVB ] = "DVB",
[ CX88_VMUX_DEBUG ] = "for debug only",
};
struct v4l2_input *i = arg;
unsigned int n;
n = i->index;
......@@ -1389,53 +1280,59 @@ int cx88_do_ioctl(struct inode *inode, struct file *file, int radio,
for (n = 0; n < ARRAY_SIZE(tvnorms); n++)
i->std |= tvnorms[n].id;
return 0;
}
case VIDIOC_G_INPUT:
{
unsigned int *i = arg;
}
static int vidioc_g_input (struct file *file, void *priv, unsigned int *i)
{
struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
*i = core->input;
return 0;
}
case VIDIOC_S_INPUT:
{
unsigned int *i = arg;
}
if (*i >= 4)
static int vidioc_s_input (struct file *file, void *priv, unsigned int i)
{
struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
if (i >= 4)
return -EINVAL;
mutex_lock(&core->lock);
cx88_newstation(core);
video_mux(core,*i);
video_mux(core,i);
mutex_unlock(&core->lock);
return 0;
}
}
/* --- controls ---------------------------------------------- */
case VIDIOC_QUERYCTRL:
{
struct v4l2_queryctrl *c = arg;
static int vidioc_queryctrl (struct file *file, void *priv,
struct v4l2_queryctrl *qctrl)
{
qctrl->id = v4l2_ctrl_next(ctrl_classes, qctrl->id);
if (unlikely(qctrl->id == 0))
return -EINVAL;
return cx8800_ctrl_query(qctrl);
}
return cx88_queryctrl(c);
}
case VIDIOC_G_CTRL:
return get_control(core,arg);
case VIDIOC_S_CTRL:
return set_control(core,arg);
static int vidioc_s_ctrl (struct file *file, void *priv,
struct v4l2_control *ctl)
{
struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
/* --- tuner ioctls ------------------------------------------ */
case VIDIOC_G_TUNER:
{
struct v4l2_tuner *t = arg;
return
set_control(core,ctl);
}
static int vidioc_g_tuner (struct file *file, void *priv,
struct v4l2_tuner *t)
{
struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
u32 reg;
if (UNSET == core->tuner_type)
return -EINVAL;
if (0 != t->index)
if (unlikely(UNSET == core->tuner_type))
return -EINVAL;
memset(t,0,sizeof(*t));
strcpy(t->name, "Television");
t->type = V4L2_TUNER_ANALOG_TV;
t->capability = V4L2_TUNER_CAP_NORM;
......@@ -1445,46 +1342,53 @@ int cx88_do_ioctl(struct inode *inode, struct file *file, int radio,
reg = cx_read(MO_DEVICE_STATUS);
t->signal = (reg & (1<<5)) ? 0xffff : 0x0000;
return 0;
}
case VIDIOC_S_TUNER:
{
struct v4l2_tuner *t = arg;
}
static int vidioc_s_tuner (struct file *file, void *priv,
struct v4l2_tuner *t)
{
struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
if (UNSET == core->tuner_type)
return -EINVAL;
if (0 != t->index)
return -EINVAL;
cx88_set_stereo(core, t->audmode, 1);
return 0;
}
case VIDIOC_G_FREQUENCY:
{
struct v4l2_frequency *f = arg;
}
memset(f,0,sizeof(*f));
static int vidioc_g_frequency (struct file *file, void *priv,
struct v4l2_frequency *f)
{
struct cx8800_fh *fh = priv;
struct cx88_core *core = fh->dev->core;
if (UNSET == core->tuner_type)
if (unlikely(UNSET == core->tuner_type))
return -EINVAL;
/* f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; */
f->type = radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
f->frequency = core->freq;
cx88_call_i2c_clients(core,VIDIOC_G_FREQUENCY,f);
return 0;
}
case VIDIOC_S_FREQUENCY:
{
struct v4l2_frequency *f = arg;
}
if (UNSET == core->tuner_type)
static int vidioc_s_frequency (struct file *file, void *priv,
struct v4l2_frequency *f)
{
struct cx8800_fh *fh = priv;
struct cx88_core *core = fh->dev->core;
if (unlikely(UNSET == core->tuner_type))
return -EINVAL;
if (f->tuner != 0)
if (unlikely(f->tuner != 0))
return -EINVAL;
if (0 == radio && f->type != V4L2_TUNER_ANALOG_TV)
if (unlikely(0 == fh->radio && f->type != V4L2_TUNER_ANALOG_TV))
return -EINVAL;
if (1 == radio && f->type != V4L2_TUNER_RADIO)
if (unlikely(1 == fh->radio && f->type != V4L2_TUNER_RADIO))
return -EINVAL;
mutex_lock(&core->lock);
core->freq = f->frequency;
......@@ -1497,75 +1401,19 @@ int cx88_do_ioctl(struct inode *inode, struct file *file, int radio,
mutex_unlock(&core->lock);
return 0;
}
#ifdef CONFIG_VIDEO_ADV_DEBUG
/* ioctls to allow direct acces to the cx2388x registers */
case VIDIOC_INT_G_REGISTER:
{
struct v4l2_register *reg = arg;
if (reg->i2c_id != 0)
return -EINVAL;
/* cx2388x has a 24-bit register space */
reg->val = cx_read(reg->reg&0xffffff);
return 0;
}
case VIDIOC_INT_S_REGISTER:
{
struct v4l2_register *reg = arg;
if (reg->i2c_id != 0)
return -EINVAL;
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
cx_write(reg->reg&0xffffff, reg->val);
return 0;
}
#endif
default:
return v4l_compat_translate_ioctl(inode,file,cmd,arg,
driver_ioctl);
}
return 0;
}
static int video_ioctl(struct inode *inode, struct file *file,
unsigned int cmd, unsigned long arg)
{
int retval;
retval=video_usercopy(inode, file, cmd, arg, video_do_ioctl);
if (video_debug > 1) {
if (retval < 0) {
v4l_print_ioctl("cx88(err)", cmd);
printk(KERN_DEBUG "cx88(err): errcode=%d\n",retval);
} else if (_IOC_DIR(cmd) & _IOC_READ)
v4l_printk_ioctl_arg("cx88(r)",cmd, (void *)arg);
}
return retval;
}
/* ----------------------------------------------------------- */
/* RADIO ESPECIFIC IOCTLS */
/* ----------------------------------------------------------- */
static int radio_do_ioctl(struct inode *inode, struct file *file,
unsigned int cmd, void *arg)
static int radio_querycap (struct file *file, void *priv,
struct v4l2_capability *cap)
{
struct cx8800_fh *fh = file->private_data;
struct cx8800_dev *dev = fh->dev;
struct cx8800_dev *dev = ((struct cx8800_fh *)priv)->dev;
struct cx88_core *core = dev->core;
if (video_debug > 1)
v4l_print_ioctl(core->name,cmd);
switch (cmd) {
case VIDIOC_QUERYCAP:
{
struct v4l2_capability *cap = arg;
memset(cap,0,sizeof(*cap));
strcpy(cap->driver, "cx8800");
strlcpy(cap->card, cx88_boards[core->board].name,
sizeof(cap->card));
......@@ -1573,66 +1421,50 @@ static int radio_do_ioctl(struct inode *inode, struct file *file,
cap->version = CX88_VERSION_CODE;
cap->capabilities = V4L2_CAP_TUNER;
return 0;
}
case VIDIOC_G_TUNER:
{
struct v4l2_tuner *t = arg;
}
if (t->index > 0)
static int radio_g_tuner (struct file *file, void *priv,
struct v4l2_tuner *t)
{
struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
if (unlikely(t->index > 0))
return -EINVAL;
memset(t,0,sizeof(*t));
strcpy(t->name, "Radio");
t->type = V4L2_TUNER_RADIO;
cx88_call_i2c_clients(core,VIDIOC_G_TUNER,t);
return 0;
}
case VIDIOC_ENUMINPUT:
{
struct v4l2_input *i = arg;
}
static int radio_enum_input (struct file *file, void *priv,
struct v4l2_input *i)
{
if (i->index != 0)
return -EINVAL;
strcpy(i->name,"Radio");
i->type = V4L2_INPUT_TYPE_TUNER;
return 0;
}
case VIDIOC_G_INPUT:
{
int *i = arg;
*i = 0;
return 0;
}
case VIDIOC_G_AUDIO:
{
struct v4l2_audio *a = arg;
}
static int radio_g_audio (struct file *file, void *priv, struct v4l2_audio *a)
{
if (unlikely(a->index))
return -EINVAL;
memset(a,0,sizeof(*a));
strcpy(a->name,"Radio");
return 0;
}
case VIDIOC_G_STD:
{
v4l2_std_id *id = arg;
*id = 0;
return 0;
}
#ifdef CONFIG_VIDEO_V4L1_COMPAT
case VIDIOCSTUNER:
{
struct video_tuner *v = arg;
}
if (v->tuner) /* Only tuner 0 */
return -EINVAL;
/* FIXME: Should add a standard for radio */
cx88_call_i2c_clients(core,VIDIOCSTUNER,v);
return 0;
}
#endif
case VIDIOC_S_TUNER:
{
struct v4l2_tuner *t = arg;
static int radio_s_tuner (struct file *file, void *priv,
struct v4l2_tuner *t)
{
struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
if (0 != t->index)
return -EINVAL;
......@@ -1640,16 +1472,22 @@ static int radio_do_ioctl(struct inode *inode, struct file *file,
cx88_call_i2c_clients(core,VIDIOC_S_TUNER,t);
return 0;
}
}
case VIDIOC_S_AUDIO:
case VIDIOC_S_INPUT:
case VIDIOC_S_STD:
static int radio_s_audio (struct file *file, void *fh,
struct v4l2_audio *a)
{
return 0;
}
case VIDIOC_QUERYCTRL:
{
struct v4l2_queryctrl *c = arg;
static int radio_s_input (struct file *file, void *fh, unsigned int i)
{
return 0;
}
static int radio_queryctrl (struct file *file, void *priv,
struct v4l2_queryctrl *c)
{
int i;
if (c->id < V4L2_CID_BASE ||
......@@ -1663,27 +1501,7 @@ static int radio_do_ioctl(struct inode *inode, struct file *file,
} else
*c = no_ctl;
return 0;
}
case VIDIOC_G_CTRL:
case VIDIOC_S_CTRL:
case VIDIOC_G_FREQUENCY:
case VIDIOC_S_FREQUENCY:
return video_do_ioctl(inode,file,cmd,arg);
default:
return v4l_compat_translate_ioctl(inode,file,cmd,arg,
radio_do_ioctl);
}
return 0;
};
static int radio_ioctl(struct inode *inode, struct file *file,
unsigned int cmd, unsigned long arg)
{
return video_usercopy(inode, file, cmd, arg, radio_do_ioctl);
};
}
/* ----------------------------------------------------------- */
......@@ -1816,27 +1634,48 @@ static const struct file_operations video_fops =
.read = video_read,
.poll = video_poll,
.mmap = video_mmap,
.ioctl = video_ioctl,
.ioctl = video_ioctl2,
.compat_ioctl = v4l_compat_ioctl32,
.llseek = no_llseek,
};
static struct video_device cx8800_vbi_template;
static struct video_device cx8800_video_template =
{
.name = "cx8800-video",
.type = VID_TYPE_CAPTURE|VID_TYPE_TUNER|VID_TYPE_SCALES,
.hardware = 0,
.fops = &video_fops,
.minor = -1,
};
static struct video_device cx8800_vbi_template =
{
.name = "cx8800-vbi",
.type = VID_TYPE_TELETEXT|VID_TYPE_TUNER,
.hardware = 0,
.fops = &video_fops,
.minor = -1,
.vidioc_querycap = vidioc_querycap,
.vidioc_enum_fmt_cap = vidioc_enum_fmt_cap,
.vidioc_g_fmt_cap = vidioc_g_fmt_cap,
.vidioc_try_fmt_cap = vidioc_try_fmt_cap,
.vidioc_s_fmt_cap = vidioc_s_fmt_cap,
.vidioc_g_fmt_vbi = cx8800_vbi_fmt,
.vidioc_try_fmt_vbi = cx8800_vbi_fmt,
.vidioc_s_fmt_vbi = cx8800_vbi_fmt,
.vidioc_reqbufs = vidioc_reqbufs,
.vidioc_querybuf = vidioc_querybuf,
.vidioc_qbuf = vidioc_qbuf,
.vidioc_dqbuf = vidioc_dqbuf,
.vidioc_s_std = vidioc_s_std,
.vidioc_enum_input = vidioc_enum_input,
.vidioc_g_input = vidioc_g_input,
.vidioc_s_input = vidioc_s_input,
.vidioc_queryctrl = vidioc_queryctrl,
.vidioc_g_ctrl = vidioc_g_ctrl,
.vidioc_s_ctrl = vidioc_s_ctrl,
.vidioc_streamon = vidioc_streamon,
.vidioc_streamoff = vidioc_streamoff,
#ifdef CONFIG_VIDEO_V4L1_COMPAT
.vidiocgmbuf = vidiocgmbuf,
#endif
.vidioc_g_tuner = vidioc_g_tuner,
.vidioc_s_tuner = vidioc_s_tuner,
.vidioc_g_frequency = vidioc_g_frequency,
.vidioc_s_frequency = vidioc_s_frequency,
.tvnorms = tvnorms,
.tvnormsize = ARRAY_SIZE(tvnorms),
};
static const struct file_operations radio_fops =
......@@ -1844,7 +1683,7 @@ static const struct file_operations radio_fops =
.owner = THIS_MODULE,
.open = video_open,
.release = video_release,
.ioctl = radio_ioctl,
.ioctl = video_ioctl2,
.compat_ioctl = v4l_compat_ioctl32,
.llseek = no_llseek,
};
......@@ -1856,6 +1695,20 @@ static struct video_device cx8800_radio_template =
.hardware = 0,
.fops = &radio_fops,
.minor = -1,
.vidioc_querycap = radio_querycap,
.vidioc_g_tuner = radio_g_tuner,
.vidioc_enum_input = radio_enum_input,
.vidioc_g_audio = radio_g_audio,
.vidioc_s_tuner = radio_s_tuner,
.vidioc_s_audio = radio_s_audio,
.vidioc_s_input = radio_s_input,
.vidioc_queryctrl = radio_queryctrl,
.vidioc_g_ctrl = vidioc_g_ctrl,
.vidioc_s_ctrl = vidioc_s_ctrl,
.vidioc_g_frequency = vidioc_g_frequency,
.vidioc_s_frequency = vidioc_s_frequency,
.tvnorms = radionorms,
.tvnormsize = ARRAY_SIZE(radionorms),
};
/* ----------------------------------------------------------- */
......@@ -1890,6 +1743,7 @@ static int __devinit cx8800_initdev(struct pci_dev *pci_dev,
{
struct cx8800_dev *dev;
struct cx88_core *core;
int err;
dev = kzalloc(sizeof(*dev),GFP_KERNEL);
......@@ -1924,6 +1778,12 @@ static int __devinit cx8800_initdev(struct pci_dev *pci_dev,
goto fail_core;
}
/* Initialize VBI template */
memcpy( &cx8800_vbi_template, &cx8800_video_template,
sizeof(cx8800_vbi_template) );
strcpy(cx8800_vbi_template.name,"cx8800-vbi");
cx8800_vbi_template.type = VID_TYPE_TELETEXT|VID_TYPE_TUNER;
/* initialize driver struct */
spin_lock_init(&dev->slock);
core->tvnorm = tvnorms;
......
......@@ -82,20 +82,13 @@ enum cx8802_board_access {
/* ----------------------------------------------------------- */
/* tv norms */
struct cx88_tvnorm {
char *name;
v4l2_std_id id;
u32 cxiformat;
u32 cxoformat;
};
static unsigned int inline norm_maxw(struct cx88_tvnorm *norm)
static unsigned int inline norm_maxw(struct v4l2_tvnorm *norm)
{
return (norm->id & (V4L2_STD_MN & ~V4L2_STD_PAL_Nc)) ? 720 : 768;
}
static unsigned int inline norm_maxh(struct cx88_tvnorm *norm)
static unsigned int inline norm_maxh(struct v4l2_tvnorm *norm)
{
return (norm->id & V4L2_STD_625_50) ? 576 : 480;
}
......@@ -319,7 +312,7 @@ struct cx88_core {
/* state info */
struct task_struct *kthread;
struct cx88_tvnorm *tvnorm;
struct v4l2_tvnorm *tvnorm;
u32 tvaudio;
u32 audiomode_manual;
u32 audiomode_current;
......@@ -536,7 +529,7 @@ extern void cx88_sram_channel_dump(struct cx88_core *core,
extern int cx88_set_scale(struct cx88_core *core, unsigned int width,
unsigned int height, enum v4l2_field field);
extern int cx88_set_tvnorm(struct cx88_core *core, struct cx88_tvnorm *norm);
extern int cx88_set_tvnorm(struct cx88_core *core, struct v4l2_tvnorm *norm);
extern struct video_device *cx88_vdev_init(struct cx88_core *core,
struct pci_dev *pci,
......@@ -553,7 +546,10 @@ extern int cx88_stop_audio_dma(struct cx88_core *core);
/* ----------------------------------------------------------- */
/* cx88-vbi.c */
void cx8800_vbi_fmt(struct cx8800_dev *dev, struct v4l2_format *f);
/* Can be used as g_vbi_fmt, try_vbi_fmt and s_vbi_fmt */
int cx8800_vbi_fmt (struct file *file, void *priv,
struct v4l2_format *f);
/*
int cx8800_start_vbi_dma(struct cx8800_dev *dev,
struct cx88_dmaqueue *q,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment