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 @@ ...@@ -5,6 +5,11 @@
* *
* (c) 2003 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs] * (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 * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
...@@ -631,22 +636,22 @@ int cx88_reset(struct cx88_core *core) ...@@ -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; 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; 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; 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) if (norm->id & V4L2_STD_PAL_M)
return 28604892; // 3.575611 MHz return 28604892; // 3.575611 MHz
...@@ -666,7 +671,7 @@ static unsigned int inline norm_fsc8(struct cx88_tvnorm *norm) ...@@ -666,7 +671,7 @@ static unsigned int inline norm_fsc8(struct cx88_tvnorm *norm)
return 35468950; // 4.43361875 MHz +/- 5 Hz 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; unsigned int fsc4=norm_fsc8(norm)/2;
...@@ -677,7 +682,7 @@ static unsigned int inline norm_htotal(struct cx88_tvnorm *norm) ...@@ -677,7 +682,7 @@ static unsigned int inline norm_htotal(struct cx88_tvnorm *norm)
((fsc4+262)/525*1001+15000)/30000; ((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; return (norm->id & V4L2_STD_625_50) ? 511 : 400;
} }
...@@ -826,7 +831,7 @@ int cx88_stop_audio_dma(struct cx88_core *core) ...@@ -826,7 +831,7 @@ int cx88_stop_audio_dma(struct cx88_core *core)
static int set_tvaudio(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) if (CX88_VMUX_TELEVISION != INPUT(core->input)->type)
return 0; return 0;
...@@ -874,7 +879,7 @@ static int set_tvaudio(struct cx88_core *core) ...@@ -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 fsc8;
u32 adc_clock; u32 adc_clock;
...@@ -882,6 +887,7 @@ int cx88_set_tvnorm(struct cx88_core *core, struct cx88_tvnorm *norm) ...@@ -882,6 +887,7 @@ int cx88_set_tvnorm(struct cx88_core *core, struct cx88_tvnorm *norm)
u32 step_db,step_dr; u32 step_db,step_dr;
u64 tmp64; u64 tmp64;
u32 bdelay,agcdelay,htotal; u32 bdelay,agcdelay,htotal;
u32 cxiformat, cxoformat;
core->tvnorm = norm; core->tvnorm = norm;
fsc8 = norm_fsc8(norm); fsc8 = norm_fsc8(norm);
...@@ -890,9 +896,32 @@ int cx88_set_tvnorm(struct cx88_core *core, struct cx88_tvnorm *norm) ...@@ -890,9 +896,32 @@ int cx88_set_tvnorm(struct cx88_core *core, struct cx88_tvnorm *norm)
step_db = fsc8; step_db = fsc8;
step_dr = 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_db = 4250000 * 8;
step_dr = 4406250 * 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", 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) ...@@ -900,13 +929,13 @@ int cx88_set_tvnorm(struct cx88_core *core, struct cx88_tvnorm *norm)
set_pll(core,2,vdec_clock); set_pll(core,2,vdec_clock);
dprintk(1,"set_tvnorm: MO_INPUT_FORMAT 0x%08x [old=0x%08x]\n", dprintk(1,"set_tvnorm: MO_INPUT_FORMAT 0x%08x [old=0x%08x]\n",
norm->cxiformat, cx_read(MO_INPUT_FORMAT) & 0x0f); cxiformat, cx_read(MO_INPUT_FORMAT) & 0x0f);
cx_andor(MO_INPUT_FORMAT, 0xf, norm->cxiformat); cx_andor(MO_INPUT_FORMAT, 0xf, cxiformat);
// FIXME: as-is from DScaler // FIXME: as-is from DScaler
dprintk(1,"set_tvnorm: MO_OUTPUT_FORMAT 0x%08x [old=0x%08x]\n", dprintk(1,"set_tvnorm: MO_OUTPUT_FORMAT 0x%08x [old=0x%08x]\n",
norm->cxoformat, cx_read(MO_OUTPUT_FORMAT)); cxoformat, cx_read(MO_OUTPUT_FORMAT));
cx_write(MO_OUTPUT_FORMAT, norm->cxoformat); cx_write(MO_OUTPUT_FORMAT, cxoformat);
// MO_SCONV_REG = adc clock / video dec clock * 2^17 // MO_SCONV_REG = adc clock / video dec clock * 2^17
tmp64 = adc_clock * (u64)(1 << 17); tmp64 = adc_clock * (u64)(1 << 17);
......
...@@ -21,9 +21,11 @@ MODULE_PARM_DESC(vbi_debug,"enable debug messages [vbi]"); ...@@ -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.samples_per_line = VBI_LINE_LENGTH;
f->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY; 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) ...@@ -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[0] = 7 -1;
f->fmt.vbi.start[1] = 319 -1; f->fmt.vbi.start[1] = 319 -1;
} }
return 0;
} }
static int cx8800_start_vbi_dma(struct cx8800_dev *dev, static int cx8800_start_vbi_dma(struct cx8800_dev *dev,
......
/* /*
* *
* device driver for Conexant 2388x based TV cards * device driver for Conexant 2388x based TV cards
...@@ -5,6 +6,11 @@ ...@@ -5,6 +6,11 @@
* *
* (c) 2003-04 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs] * (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 * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
...@@ -80,62 +86,47 @@ static LIST_HEAD(cx8800_devlist); ...@@ -80,62 +86,47 @@ static LIST_HEAD(cx8800_devlist);
/* ------------------------------------------------------------------- */ /* ------------------------------------------------------------------- */
/* static data */ /* static data */
static struct cx88_tvnorm tvnorms[] = { static struct v4l2_tvnorm tvnorms[] = {
{ {
.name = "NTSC-M", .name = "NTSC-M",
.id = V4L2_STD_NTSC_M, .id = V4L2_STD_NTSC_M,
.cxiformat = VideoFormatNTSC,
.cxoformat = 0x181f0008,
},{ },{
.name = "NTSC-JP", .name = "NTSC-JP",
.id = V4L2_STD_NTSC_M_JP, .id = V4L2_STD_NTSC_M_JP,
.cxiformat = VideoFormatNTSCJapan,
.cxoformat = 0x181f0008,
},{ },{
.name = "PAL-BG", .name = "PAL-BG",
.id = V4L2_STD_PAL_BG, .id = V4L2_STD_PAL_BG,
.cxiformat = VideoFormatPAL,
.cxoformat = 0x181f0008,
},{ },{
.name = "PAL-DK", .name = "PAL-DK",
.id = V4L2_STD_PAL_DK, .id = V4L2_STD_PAL_DK,
.cxiformat = VideoFormatPAL,
.cxoformat = 0x181f0008,
},{ },{
.name = "PAL-I", .name = "PAL-I",
.id = V4L2_STD_PAL_I, .id = V4L2_STD_PAL_I,
.cxiformat = VideoFormatPAL,
.cxoformat = 0x181f0008,
},{ },{
.name = "PAL-M", .name = "PAL-M",
.id = V4L2_STD_PAL_M, .id = V4L2_STD_PAL_M,
.cxiformat = VideoFormatPALM,
.cxoformat = 0x1c1f0008,
},{ },{
.name = "PAL-N", .name = "PAL-N",
.id = V4L2_STD_PAL_N, .id = V4L2_STD_PAL_N,
.cxiformat = VideoFormatPALN,
.cxoformat = 0x1c1f0008,
},{ },{
.name = "PAL-Nc", .name = "PAL-Nc",
.id = V4L2_STD_PAL_Nc, .id = V4L2_STD_PAL_Nc,
.cxiformat = VideoFormatPALNC,
.cxoformat = 0x1c1f0008,
},{ },{
.name = "PAL-60", .name = "PAL-60",
.id = V4L2_STD_PAL_60, .id = V4L2_STD_PAL_60,
.cxiformat = VideoFormatPAL60,
.cxoformat = 0x181f0008,
},{ },{
.name = "SECAM-L", .name = "SECAM-L",
.id = V4L2_STD_SECAM_L, .id = V4L2_STD_SECAM_L,
.cxiformat = VideoFormatSECAM,
.cxoformat = 0x181f0008,
},{ },{
.name = "SECAM-DK", .name = "SECAM-DK",
.id = V4L2_STD_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) ...@@ -364,14 +355,6 @@ int cx8800_ctrl_query(struct v4l2_queryctrl *qctrl)
} }
EXPORT_SYMBOL(cx8800_ctrl_query); 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 */ /* resource management */
...@@ -944,19 +927,20 @@ video_mmap(struct file *file, struct vm_area_struct * vma) ...@@ -944,19 +927,20 @@ 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 vidioc_g_ctrl (struct file *file, void *priv,
static int get_control(struct cx88_core *core, struct v4l2_control *ctl) 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; struct cx88_ctrl *c = NULL;
u32 value; u32 value;
int i; int i;
for (i = 0; i < CX8800_CTLS; i++) for (i = 0; i < CX8800_CTLS; i++)
if (cx8800_ctls[i].v.id == ctl->id) if (cx8800_ctls[i].v.id == ctl->id)
c = &cx8800_ctls[i]; c = &cx8800_ctls[i];
if (NULL == c) if (unlikely(NULL == c))
return -EINVAL; return -EINVAL;
value = c->sreg ? cx_sread(c->sreg) : cx_read(c->reg); 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) ...@@ -978,19 +962,18 @@ static int get_control(struct cx88_core *core, struct v4l2_control *ctl)
return 0; 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) static int set_control(struct cx88_core *core, struct v4l2_control *ctl)
{ {
/* struct cx88_core *core = dev->core; */
struct cx88_ctrl *c = NULL; struct cx88_ctrl *c = NULL;
u32 value,mask; u32 value,mask;
int i; int i;
for (i = 0; i < CX8800_CTLS; i++) { for (i = 0; i < CX8800_CTLS; i++) {
if (cx8800_ctls[i].v.id == ctl->id) { if (cx8800_ctls[i].v.id == ctl->id) {
c = &cx8800_ctls[i]; c = &cx8800_ctls[i];
} }
} }
if (NULL == c) if (unlikely(NULL == c))
return -EINVAL; return -EINVAL;
if (ctl->value < c->v.minimum) if (ctl->value < c->v.minimum)
...@@ -1042,648 +1025,483 @@ static void init_controls(struct cx88_core *core) ...@@ -1042,648 +1025,483 @@ static void init_controls(struct cx88_core *core)
for (i = 0; i < CX8800_CTLS; i++) { for (i = 0; i < CX8800_CTLS; i++) {
ctrl.id=cx8800_ctls[i].v.id; ctrl.id=cx8800_ctls[i].v.id;
ctrl.value=cx8800_ctls[i].v.default_value; ctrl.value=cx8800_ctls[i].v.default_value;
set_control(core, &ctrl); set_control(core, &ctrl);
} }
} }
/* ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ */
/* VIDEO IOCTLS */
static int vidioc_g_fmt_cap (struct file *file, void *priv,
struct v4l2_format *f)
{
struct cx8800_fh *fh = priv;
f->fmt.pix.width = fh->width;
f->fmt.pix.height = fh->height;
f->fmt.pix.field = fh->vidq.field;
f->fmt.pix.pixelformat = fh->fmt->fourcc;
f->fmt.pix.bytesperline =
(f->fmt.pix.width * fh->fmt->depth) >> 3;
f->fmt.pix.sizeimage =
f->fmt.pix.height * f->fmt.pix.bytesperline;
return 0;
}
static int cx8800_g_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 v4l2_format *f)
{ {
switch (f->type) { struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
case V4L2_BUF_TYPE_VIDEO_CAPTURE: struct cx8800_fmt *fmt;
memset(&f->fmt.pix,0,sizeof(f->fmt.pix)); enum v4l2_field field;
f->fmt.pix.width = fh->width; unsigned int maxw, maxh;
f->fmt.pix.height = fh->height;
f->fmt.pix.field = fh->vidq.field; fmt = format_by_fourcc(f->fmt.pix.pixelformat);
f->fmt.pix.pixelformat = fh->fmt->fourcc; if (NULL == fmt)
f->fmt.pix.bytesperline = return -EINVAL;
(f->fmt.pix.width * fh->fmt->depth) >> 3;
f->fmt.pix.sizeimage = field = f->fmt.pix.field;
f->fmt.pix.height * f->fmt.pix.bytesperline; maxw = norm_maxw(core->tvnorm);
return 0; maxh = norm_maxh(core->tvnorm);
case V4L2_BUF_TYPE_VBI_CAPTURE:
cx8800_vbi_fmt(dev, f); if (V4L2_FIELD_ANY == field) {
return 0; field = (f->fmt.pix.height > maxh/2)
? V4L2_FIELD_INTERLACED
: V4L2_FIELD_BOTTOM;
}
switch (field) {
case V4L2_FIELD_TOP:
case V4L2_FIELD_BOTTOM:
maxh = maxh / 2;
break;
case V4L2_FIELD_INTERLACED:
break;
default: default:
return -EINVAL; return -EINVAL;
} }
f->fmt.pix.field = field;
if (f->fmt.pix.height < 32)
f->fmt.pix.height = 32;
if (f->fmt.pix.height > maxh)
f->fmt.pix.height = maxh;
if (f->fmt.pix.width < 48)
f->fmt.pix.width = 48;
if (f->fmt.pix.width > maxw)
f->fmt.pix.width = maxw;
f->fmt.pix.width &= ~0x03;
f->fmt.pix.bytesperline =
(f->fmt.pix.width * fmt->depth) >> 3;
f->fmt.pix.sizeimage =
f->fmt.pix.height * f->fmt.pix.bytesperline;
return 0;
} }
static int cx8800_try_fmt(struct cx8800_dev *dev, struct cx8800_fh *fh, static int vidioc_s_fmt_cap (struct file *file, void *priv,
struct v4l2_format *f) struct v4l2_format *f)
{ {
struct cx88_core *core = dev->core; struct cx8800_fh *fh = priv;
int err = vidioc_try_fmt_cap (file,priv,f);
switch (f->type) { if (0 != err)
case V4L2_BUF_TYPE_VIDEO_CAPTURE: return err;
{ fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat);
struct cx8800_fmt *fmt; fh->width = f->fmt.pix.width;
enum v4l2_field field; fh->height = f->fmt.pix.height;
unsigned int maxw, maxh; fh->vidq.field = f->fmt.pix.field;
return 0;
fmt = format_by_fourcc(f->fmt.pix.pixelformat); }
if (NULL == fmt)
return -EINVAL;
field = f->fmt.pix.field;
maxw = norm_maxw(core->tvnorm);
maxh = norm_maxh(core->tvnorm);
if (V4L2_FIELD_ANY == field) {
field = (f->fmt.pix.height > maxh/2)
? V4L2_FIELD_INTERLACED
: V4L2_FIELD_BOTTOM;
}
switch (field) { static int vidioc_querycap (struct file *file, void *priv,
case V4L2_FIELD_TOP: struct v4l2_capability *cap)
case V4L2_FIELD_BOTTOM: {
maxh = maxh / 2; struct cx8800_dev *dev = ((struct cx8800_fh *)priv)->dev;
break; struct cx88_core *core = dev->core;
case V4L2_FIELD_INTERLACED:
break;
default:
return -EINVAL;
}
f->fmt.pix.field = field; strcpy(cap->driver, "cx8800");
if (f->fmt.pix.height < 32) strlcpy(cap->card, cx88_boards[core->board].name,
f->fmt.pix.height = 32; sizeof(cap->card));
if (f->fmt.pix.height > maxh) sprintf(cap->bus_info,"PCI:%s",pci_name(dev->pci));
f->fmt.pix.height = maxh; cap->version = CX88_VERSION_CODE;
if (f->fmt.pix.width < 48) cap->capabilities =
f->fmt.pix.width = 48; V4L2_CAP_VIDEO_CAPTURE |
if (f->fmt.pix.width > maxw) V4L2_CAP_READWRITE |
f->fmt.pix.width = maxw; V4L2_CAP_STREAMING |
f->fmt.pix.width &= ~0x03; V4L2_CAP_VBI_CAPTURE;
f->fmt.pix.bytesperline = if (UNSET != core->tuner_type)
(f->fmt.pix.width * fmt->depth) >> 3; cap->capabilities |= V4L2_CAP_TUNER;
f->fmt.pix.sizeimage = return 0;
f->fmt.pix.height * f->fmt.pix.bytesperline; }
return 0; static int vidioc_enum_fmt_cap (struct file *file, void *priv,
} struct v4l2_fmtdesc *f)
case V4L2_BUF_TYPE_VBI_CAPTURE: {
cx8800_vbi_fmt(dev, f); if (unlikely(f->index >= ARRAY_SIZE(formats)))
return 0;
default:
return -EINVAL; return -EINVAL;
}
strlcpy(f->description,formats[f->index].name,sizeof(f->description));
f->pixelformat = formats[f->index].fourcc;
return 0;
} }
static int cx8800_s_fmt(struct cx8800_dev *dev, struct cx8800_fh *fh, #ifdef CONFIG_VIDEO_V4L1_COMPAT
struct v4l2_format *f) 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; int err;
switch (f->type) { q = get_queue(fh);
case V4L2_BUF_TYPE_VIDEO_CAPTURE: memset(&req,0,sizeof(req));
err = cx8800_try_fmt(dev,fh,f); req.type = q->type;
if (0 != err) req.count = 8;
return err; req.memory = V4L2_MEMORY_MMAP;
err = videobuf_reqbufs(q,&req);
if (err < 0)
return err;
fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat); mbuf->frames = req.count;
fh->width = f->fmt.pix.width; mbuf->size = 0;
fh->height = f->fmt.pix.height; for (i = 0; i < mbuf->frames; i++) {
fh->vidq.field = f->fmt.pix.field; mbuf->offsets[i] = q->bufs[i]->boff;
return 0; mbuf->size += q->bufs[i]->bsize;
case V4L2_BUF_TYPE_VBI_CAPTURE:
cx8800_vbi_fmt(dev, f);
return 0;
default:
return -EINVAL;
} }
return 0;
} }
#endif
/*
* This function is _not_ called directly, but from static int vidioc_reqbufs (struct file *file, void *priv, struct v4l2_requestbuffers *p)
* 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)
{ {
struct cx8800_fh *fh = file->private_data; struct cx8800_fh *fh = priv;
struct cx8800_dev *dev = fh->dev; return (videobuf_reqbufs(get_queue(fh), p));
struct cx88_core *core = dev->core; }
int err;
if (video_debug > 1) static int vidioc_querybuf (struct file *file, void *priv, struct v4l2_buffer *p)
v4l_print_ioctl(core->name,cmd); {
switch (cmd) { struct cx8800_fh *fh = priv;
return (videobuf_querybuf(get_queue(fh), p));
}
/* --- capabilities ------------------------------------------ */ static int vidioc_qbuf (struct file *file, void *priv, struct v4l2_buffer *p)
case VIDIOC_QUERYCAP: {
{ struct cx8800_fh *fh = priv;
struct v4l2_capability *cap = arg; return (videobuf_qbuf(get_queue(fh), p));
}
memset(cap,0,sizeof(*cap));
strcpy(cap->driver, "cx8800");
strlcpy(cap->card, cx88_boards[core->board].name,
sizeof(cap->card));
sprintf(cap->bus_info,"PCI:%s",pci_name(dev->pci));
cap->version = CX88_VERSION_CODE;
cap->capabilities =
V4L2_CAP_VIDEO_CAPTURE |
V4L2_CAP_READWRITE |
V4L2_CAP_STREAMING |
V4L2_CAP_VBI_CAPTURE |
0;
if (UNSET != core->tuner_type)
cap->capabilities |= V4L2_CAP_TUNER;
return 0;
}
/* --- capture ioctls ---------------------------------------- */ static int vidioc_dqbuf (struct file *file, void *priv, struct v4l2_buffer *p)
case VIDIOC_ENUM_FMT: {
{ struct cx8800_fh *fh = priv;
struct v4l2_fmtdesc *f = arg; return (videobuf_dqbuf(get_queue(fh), p,
enum v4l2_buf_type type; file->f_flags & O_NONBLOCK));
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:
return -EINVAL;
}
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;
struct videobuf_queue *q;
struct v4l2_requestbuffers req;
unsigned int i;
q = get_queue(fh);
memset(&req,0,sizeof(req));
req.type = q->type;
req.count = 8;
req.memory = V4L2_MEMORY_MMAP;
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++) {
mbuf->offsets[i] = q->bufs[i]->boff;
mbuf->size += q->bufs[i]->bsize;
}
return 0;
}
#endif
case VIDIOC_REQBUFS:
return videobuf_reqbufs(get_queue(fh), arg);
case VIDIOC_QUERYBUF: static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
return videobuf_querybuf(get_queue(fh), arg); {
struct cx8800_fh *fh = priv;
struct cx8800_dev *dev = fh->dev;
case VIDIOC_QBUF: if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE))
return videobuf_qbuf(get_queue(fh), arg); return -EINVAL;
if (unlikely(i != fh->type))
return -EINVAL;
case VIDIOC_DQBUF: if (unlikely(!res_get(dev,fh,get_ressource(fh))))
return videobuf_dqbuf(get_queue(fh), arg, return -EBUSY;
file->f_flags & O_NONBLOCK); return videobuf_streamon(get_queue(fh));
}
case VIDIOC_STREAMON: static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
{ {
int res = get_ressource(fh); struct cx8800_fh *fh = priv;
struct cx8800_dev *dev = fh->dev;
int err, res;
if (!res_get(dev,fh,res)) if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
return -EBUSY; return -EINVAL;
return videobuf_streamon(get_queue(fh)); if (i != fh->type)
} return -EINVAL;
case VIDIOC_STREAMOFF:
{
int res = get_ressource(fh);
err = videobuf_streamoff(get_queue(fh)); res = get_ressource(fh);
if (err < 0) err = videobuf_streamoff(get_queue(fh));
return err; if (err < 0)
res_free(dev,fh,res); return err;
return 0; res_free(dev,fh,res);
}
default:
return cx88_do_ioctl( inode, file, fh->radio, core, cmd, arg, video_do_ioctl );
}
return 0; return 0;
} }
int cx88_do_ioctl(struct inode *inode, struct file *file, int radio, static int vidioc_s_std (struct file *file, void *priv, unsigned int i)
struct cx88_core *core, unsigned int cmd, void *arg, v4l2_kioctl driver_ioctl)
{ {
int err; struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
if (video_debug) { mutex_lock(&core->lock);
if (video_debug > 1) { cx88_set_tvnorm(core,&tvnorms[i]);
if (_IOC_DIR(cmd) & _IOC_WRITE) mutex_unlock(&core->lock);
v4l_printk_ioctl_arg("cx88(w)",cmd, arg); return 0;
else if (!_IOC_DIR(cmd) & _IOC_READ) { }
v4l_print_ioctl("cx88", cmd);
}
} else
v4l_print_ioctl(core->name,cmd);
}
switch (cmd) {
/* ---------- tv norms ---------- */
case VIDIOC_ENUMSTD:
{
struct v4l2_standard *e = arg;
unsigned int i;
i = e->index;
if (i >= ARRAY_SIZE(tvnorms))
return -EINVAL;
err = v4l2_video_std_construct(e, tvnorms[e->index].id,
tvnorms[e->index].name);
e->index = i;
if (err < 0)
return err;
return 0;
}
case VIDIOC_G_STD:
{
v4l2_std_id *id = arg;
*id = core->tvnorm->id; /* only one input in this sample driver */
return 0; static int vidioc_enum_input (struct file *file, void *priv,
} struct v4l2_input *i)
case VIDIOC_S_STD: {
{ struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
v4l2_std_id *id = arg;
unsigned int i; static const char *iname[] = {
[ CX88_VMUX_COMPOSITE1 ] = "Composite1",
[ CX88_VMUX_COMPOSITE2 ] = "Composite2",
[ CX88_VMUX_COMPOSITE3 ] = "Composite3",
[ CX88_VMUX_COMPOSITE4 ] = "Composite4",
[ CX88_VMUX_SVIDEO ] = "S-Video",
[ CX88_VMUX_TELEVISION ] = "Television",
[ CX88_VMUX_CABLE ] = "Cable TV",
[ CX88_VMUX_DVB ] = "DVB",
[ CX88_VMUX_DEBUG ] = "for debug only",
};
unsigned int n;
for(i = 0; i < ARRAY_SIZE(tvnorms); i++) n = i->index;
if (*id & tvnorms[i].id) if (n >= 4)
break; return -EINVAL;
if (i == ARRAY_SIZE(tvnorms)) if (0 == INPUT(n)->type)
return -EINVAL; return -EINVAL;
memset(i,0,sizeof(*i));
i->index = n;
i->type = V4L2_INPUT_TYPE_CAMERA;
strcpy(i->name,iname[INPUT(n)->type]);
if ((CX88_VMUX_TELEVISION == INPUT(n)->type) ||
(CX88_VMUX_CABLE == INPUT(n)->type))
i->type = V4L2_INPUT_TYPE_TUNER;
for (n = 0; n < ARRAY_SIZE(tvnorms); n++)
i->std |= tvnorms[n].id;
return 0;
}
mutex_lock(&core->lock); static int vidioc_g_input (struct file *file, void *priv, unsigned int *i)
cx88_set_tvnorm(core,&tvnorms[i]); {
mutex_unlock(&core->lock); struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
return 0;
}
/* ------ input switching ---------- */ *i = core->input;
case VIDIOC_ENUMINPUT: return 0;
{ }
static const char *iname[] = {
[ CX88_VMUX_COMPOSITE1 ] = "Composite1",
[ CX88_VMUX_COMPOSITE2 ] = "Composite2",
[ CX88_VMUX_COMPOSITE3 ] = "Composite3",
[ CX88_VMUX_COMPOSITE4 ] = "Composite4",
[ CX88_VMUX_SVIDEO ] = "S-Video",
[ CX88_VMUX_TELEVISION ] = "Television",
[ CX88_VMUX_CABLE ] = "Cable TV",
[ CX88_VMUX_DVB ] = "DVB",
[ CX88_VMUX_DEBUG ] = "for debug only",
};
struct v4l2_input *i = arg;
unsigned int n;
n = i->index;
if (n >= 4)
return -EINVAL;
if (0 == INPUT(n)->type)
return -EINVAL;
memset(i,0,sizeof(*i));
i->index = n;
i->type = V4L2_INPUT_TYPE_CAMERA;
strcpy(i->name,iname[INPUT(n)->type]);
if ((CX88_VMUX_TELEVISION == INPUT(n)->type) ||
(CX88_VMUX_CABLE == INPUT(n)->type))
i->type = V4L2_INPUT_TYPE_TUNER;
for (n = 0; n < ARRAY_SIZE(tvnorms); n++)
i->std |= tvnorms[n].id;
return 0;
}
case VIDIOC_G_INPUT:
{
unsigned int *i = arg;
*i = core->input; static int vidioc_s_input (struct file *file, void *priv, unsigned int i)
return 0; {
} struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
case VIDIOC_S_INPUT:
{
unsigned int *i = arg;
if (*i >= 4) if (i >= 4)
return -EINVAL; return -EINVAL;
mutex_lock(&core->lock);
cx88_newstation(core);
video_mux(core,*i);
mutex_unlock(&core->lock);
return 0;
}
mutex_lock(&core->lock);
cx88_newstation(core);
video_mux(core,i);
mutex_unlock(&core->lock);
return 0;
}
/* --- controls ---------------------------------------------- */
case VIDIOC_QUERYCTRL:
{
struct v4l2_queryctrl *c = arg;
return cx88_queryctrl(c); static int vidioc_queryctrl (struct file *file, void *priv,
} struct v4l2_queryctrl *qctrl)
case VIDIOC_G_CTRL: {
return get_control(core,arg); qctrl->id = v4l2_ctrl_next(ctrl_classes, qctrl->id);
case VIDIOC_S_CTRL: if (unlikely(qctrl->id == 0))
return set_control(core,arg); return -EINVAL;
return cx8800_ctrl_query(qctrl);
}
/* --- tuner ioctls ------------------------------------------ */ static int vidioc_s_ctrl (struct file *file, void *priv,
case VIDIOC_G_TUNER: struct v4l2_control *ctl)
{ {
struct v4l2_tuner *t = arg; struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
u32 reg;
if (UNSET == core->tuner_type)
return -EINVAL;
if (0 != t->index)
return -EINVAL;
memset(t,0,sizeof(*t));
strcpy(t->name, "Television");
t->type = V4L2_TUNER_ANALOG_TV;
t->capability = V4L2_TUNER_CAP_NORM;
t->rangehigh = 0xffffffffUL;
cx88_get_stereo(core ,t);
reg = cx_read(MO_DEVICE_STATUS);
t->signal = (reg & (1<<5)) ? 0xffff : 0x0000;
return 0;
}
case VIDIOC_S_TUNER:
{
struct v4l2_tuner *t = arg;
if (UNSET == core->tuner_type) return
return -EINVAL; set_control(core,ctl);
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_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) if (unlikely(UNSET == core->tuner_type))
return -EINVAL; return -EINVAL;
/* f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; */ strcpy(t->name, "Television");
f->type = radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; t->type = V4L2_TUNER_ANALOG_TV;
f->frequency = core->freq; t->capability = V4L2_TUNER_CAP_NORM;
t->rangehigh = 0xffffffffUL;
cx88_call_i2c_clients(core,VIDIOC_G_FREQUENCY,f); cx88_get_stereo(core ,t);
reg = cx_read(MO_DEVICE_STATUS);
t->signal = (reg & (1<<5)) ? 0xffff : 0x0000;
return 0;
}
return 0; static int vidioc_s_tuner (struct file *file, void *priv,
} struct v4l2_tuner *t)
case VIDIOC_S_FREQUENCY: {
{ struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
struct v4l2_frequency *f = arg;
if (UNSET == core->tuner_type)
return -EINVAL;
if (f->tuner != 0)
return -EINVAL;
if (0 == radio && f->type != V4L2_TUNER_ANALOG_TV)
return -EINVAL;
if (1 == radio && f->type != V4L2_TUNER_RADIO)
return -EINVAL;
mutex_lock(&core->lock);
core->freq = f->frequency;
cx88_newstation(core);
cx88_call_i2c_clients(core,VIDIOC_S_FREQUENCY,f);
/* When changing channels it is required to reset TVAUDIO */
msleep (10);
cx88_set_tvaudio(core);
mutex_unlock(&core->lock); if (UNSET == core->tuner_type)
return 0; return -EINVAL;
} if (0 != t->index)
#ifdef CONFIG_VIDEO_ADV_DEBUG return -EINVAL;
/* ioctls to allow direct acces to the cx2388x registers */
case VIDIOC_INT_G_REGISTER:
{
struct v4l2_register *reg = arg;
if (reg->i2c_id != 0) cx88_set_stereo(core, t->audmode, 1);
return -EINVAL; return 0;
/* 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) static int vidioc_g_frequency (struct file *file, void *priv,
return -EINVAL; struct v4l2_frequency *f)
if (!capable(CAP_SYS_ADMIN)) {
return -EPERM; struct cx8800_fh *fh = priv;
cx_write(reg->reg&0xffffff, reg->val); struct cx88_core *core = fh->dev->core;
return 0;
} if (unlikely(UNSET == core->tuner_type))
#endif return -EINVAL;
/* f->type = fh->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);
default:
return v4l_compat_translate_ioctl(inode,file,cmd,arg,
driver_ioctl);
}
return 0; return 0;
} }
static int video_ioctl(struct inode *inode, struct file *file, static int vidioc_s_frequency (struct file *file, void *priv,
unsigned int cmd, unsigned long arg) struct v4l2_frequency *f)
{ {
int retval; struct cx8800_fh *fh = priv;
struct cx88_core *core = fh->dev->core;
retval=video_usercopy(inode, file, cmd, arg, video_do_ioctl); if (unlikely(UNSET == core->tuner_type))
return -EINVAL;
if (unlikely(f->tuner != 0))
return -EINVAL;
if (unlikely(0 == fh->radio && f->type != V4L2_TUNER_ANALOG_TV))
return -EINVAL;
if (unlikely(1 == fh->radio && f->type != V4L2_TUNER_RADIO))
return -EINVAL;
mutex_lock(&core->lock);
core->freq = f->frequency;
cx88_newstation(core);
cx88_call_i2c_clients(core,VIDIOC_S_FREQUENCY,f);
if (video_debug > 1) { /* When changing channels it is required to reset TVAUDIO */
if (retval < 0) { msleep (10);
v4l_print_ioctl("cx88(err)", cmd); cx88_set_tvaudio(core);
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; mutex_unlock(&core->lock);
return 0;
} }
/* ----------------------------------------------------------- */
/* RADIO ESPECIFIC IOCTLS */
/* ----------------------------------------------------------- */ /* ----------------------------------------------------------- */
static int radio_do_ioctl(struct inode *inode, struct file *file, static int radio_querycap (struct file *file, void *priv,
unsigned int cmd, void *arg) struct v4l2_capability *cap)
{ {
struct cx8800_fh *fh = file->private_data; struct cx8800_dev *dev = ((struct cx8800_fh *)priv)->dev;
struct cx8800_dev *dev = fh->dev;
struct cx88_core *core = dev->core; struct cx88_core *core = dev->core;
if (video_debug > 1) strcpy(cap->driver, "cx8800");
v4l_print_ioctl(core->name,cmd); strlcpy(cap->card, cx88_boards[core->board].name,
sizeof(cap->card));
switch (cmd) { sprintf(cap->bus_info,"PCI:%s", pci_name(dev->pci));
case VIDIOC_QUERYCAP: cap->version = CX88_VERSION_CODE;
{ cap->capabilities = V4L2_CAP_TUNER;
struct v4l2_capability *cap = arg; return 0;
}
memset(cap,0,sizeof(*cap));
strcpy(cap->driver, "cx8800");
strlcpy(cap->card, cx88_boards[core->board].name,
sizeof(cap->card));
sprintf(cap->bus_info,"PCI:%s", pci_name(dev->pci));
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,
return -EINVAL; struct v4l2_tuner *t)
{
struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
memset(t,0,sizeof(*t)); if (unlikely(t->index > 0))
strcpy(t->name, "Radio"); return -EINVAL;
t->type = V4L2_TUNER_RADIO;
cx88_call_i2c_clients(core,VIDIOC_G_TUNER,t); strcpy(t->name, "Radio");
return 0; t->type = V4L2_TUNER_RADIO;
}
case VIDIOC_ENUMINPUT:
{
struct v4l2_input *i = arg;
if (i->index != 0) cx88_call_i2c_clients(core,VIDIOC_G_TUNER,t);
return -EINVAL; return 0;
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;
memset(a,0,sizeof(*a)); static int radio_enum_input (struct file *file, void *priv,
strcpy(a->name,"Radio"); struct v4l2_input *i)
return 0; {
} if (i->index != 0)
case VIDIOC_G_STD: return -EINVAL;
{ strcpy(i->name,"Radio");
v4l2_std_id *id = arg; i->type = V4L2_INPUT_TYPE_TUNER;
*id = 0;
return 0;
}
#ifdef CONFIG_VIDEO_V4L1_COMPAT
case VIDIOCSTUNER:
{
struct video_tuner *v = arg;
if (v->tuner) /* Only tuner 0 */ return 0;
return -EINVAL; }
cx88_call_i2c_clients(core,VIDIOCSTUNER,v); static int radio_g_audio (struct file *file, void *priv, struct v4l2_audio *a)
return 0; {
} if (unlikely(a->index))
#endif return -EINVAL;
case VIDIOC_S_TUNER:
{
struct v4l2_tuner *t = arg;
if (0 != t->index) memset(a,0,sizeof(*a));
return -EINVAL; strcpy(a->name,"Radio");
return 0;
}
cx88_call_i2c_clients(core,VIDIOC_S_TUNER,t); /* FIXME: Should add a standard for radio */
return 0; static int radio_s_tuner (struct file *file, void *priv,
} struct v4l2_tuner *t)
{
struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
case VIDIOC_S_AUDIO: if (0 != t->index)
case VIDIOC_S_INPUT: return -EINVAL;
case VIDIOC_S_STD:
return 0;
case VIDIOC_QUERYCTRL: cx88_call_i2c_clients(core,VIDIOC_S_TUNER,t);
{
struct v4l2_queryctrl *c = arg;
int i;
if (c->id < V4L2_CID_BASE ||
c->id >= V4L2_CID_LASTP1)
return -EINVAL;
if (c->id == V4L2_CID_AUDIO_MUTE) {
for (i = 0; i < CX8800_CTLS; i++)
if (cx8800_ctls[i].v.id == c->id)
break;
*c = cx8800_ctls[i].v;
} else
*c = no_ctl;
return 0;
}
return 0;
}
case VIDIOC_G_CTRL: static int radio_s_audio (struct file *file, void *fh,
case VIDIOC_S_CTRL: struct v4l2_audio *a)
case VIDIOC_G_FREQUENCY: {
case VIDIOC_S_FREQUENCY: return 0;
return video_do_ioctl(inode,file,cmd,arg); }
default: static int radio_s_input (struct file *file, void *fh, unsigned int i)
return v4l_compat_translate_ioctl(inode,file,cmd,arg, {
radio_do_ioctl);
}
return 0; return 0;
}; }
static int radio_ioctl(struct inode *inode, struct file *file, static int radio_queryctrl (struct file *file, void *priv,
unsigned int cmd, unsigned long arg) struct v4l2_queryctrl *c)
{ {
return video_usercopy(inode, file, cmd, arg, radio_do_ioctl); int i;
};
if (c->id < V4L2_CID_BASE ||
c->id >= V4L2_CID_LASTP1)
return -EINVAL;
if (c->id == V4L2_CID_AUDIO_MUTE) {
for (i = 0; i < CX8800_CTLS; i++)
if (cx8800_ctls[i].v.id == c->id)
break;
*c = cx8800_ctls[i].v;
} else
*c = no_ctl;
return 0;
}
/* ----------------------------------------------------------- */ /* ----------------------------------------------------------- */
...@@ -1816,27 +1634,48 @@ static const struct file_operations video_fops = ...@@ -1816,27 +1634,48 @@ static const struct file_operations video_fops =
.read = video_read, .read = video_read,
.poll = video_poll, .poll = video_poll,
.mmap = video_mmap, .mmap = video_mmap,
.ioctl = video_ioctl, .ioctl = video_ioctl2,
.compat_ioctl = v4l_compat_ioctl32, .compat_ioctl = v4l_compat_ioctl32,
.llseek = no_llseek, .llseek = no_llseek,
}; };
static struct video_device cx8800_vbi_template;
static struct video_device cx8800_video_template = static struct video_device cx8800_video_template =
{ {
.name = "cx8800-video", .name = "cx8800-video",
.type = VID_TYPE_CAPTURE|VID_TYPE_TUNER|VID_TYPE_SCALES, .type = VID_TYPE_CAPTURE|VID_TYPE_TUNER|VID_TYPE_SCALES,
.hardware = 0, .fops = &video_fops,
.fops = &video_fops, .minor = -1,
.minor = -1, .vidioc_querycap = vidioc_querycap,
}; .vidioc_enum_fmt_cap = vidioc_enum_fmt_cap,
.vidioc_g_fmt_cap = vidioc_g_fmt_cap,
static struct video_device cx8800_vbi_template = .vidioc_try_fmt_cap = vidioc_try_fmt_cap,
{ .vidioc_s_fmt_cap = vidioc_s_fmt_cap,
.name = "cx8800-vbi", .vidioc_g_fmt_vbi = cx8800_vbi_fmt,
.type = VID_TYPE_TELETEXT|VID_TYPE_TUNER, .vidioc_try_fmt_vbi = cx8800_vbi_fmt,
.hardware = 0, .vidioc_s_fmt_vbi = cx8800_vbi_fmt,
.fops = &video_fops, .vidioc_reqbufs = vidioc_reqbufs,
.minor = -1, .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 = static const struct file_operations radio_fops =
...@@ -1844,18 +1683,32 @@ static const struct file_operations radio_fops = ...@@ -1844,18 +1683,32 @@ static const struct file_operations radio_fops =
.owner = THIS_MODULE, .owner = THIS_MODULE,
.open = video_open, .open = video_open,
.release = video_release, .release = video_release,
.ioctl = radio_ioctl, .ioctl = video_ioctl2,
.compat_ioctl = v4l_compat_ioctl32, .compat_ioctl = v4l_compat_ioctl32,
.llseek = no_llseek, .llseek = no_llseek,
}; };
static struct video_device cx8800_radio_template = static struct video_device cx8800_radio_template =
{ {
.name = "cx8800-radio", .name = "cx8800-radio",
.type = VID_TYPE_TUNER, .type = VID_TYPE_TUNER,
.hardware = 0, .hardware = 0,
.fops = &radio_fops, .fops = &radio_fops,
.minor = -1, .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, ...@@ -1890,6 +1743,7 @@ static int __devinit cx8800_initdev(struct pci_dev *pci_dev,
{ {
struct cx8800_dev *dev; struct cx8800_dev *dev;
struct cx88_core *core; struct cx88_core *core;
int err; int err;
dev = kzalloc(sizeof(*dev),GFP_KERNEL); dev = kzalloc(sizeof(*dev),GFP_KERNEL);
...@@ -1924,6 +1778,12 @@ static int __devinit cx8800_initdev(struct pci_dev *pci_dev, ...@@ -1924,6 +1778,12 @@ static int __devinit cx8800_initdev(struct pci_dev *pci_dev,
goto fail_core; 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 */ /* initialize driver struct */
spin_lock_init(&dev->slock); spin_lock_init(&dev->slock);
core->tvnorm = tvnorms; core->tvnorm = tvnorms;
......
...@@ -82,20 +82,13 @@ enum cx8802_board_access { ...@@ -82,20 +82,13 @@ enum cx8802_board_access {
/* ----------------------------------------------------------- */ /* ----------------------------------------------------------- */
/* tv norms */ /* tv norms */
struct cx88_tvnorm { static unsigned int inline norm_maxw(struct v4l2_tvnorm *norm)
char *name;
v4l2_std_id id;
u32 cxiformat;
u32 cxoformat;
};
static unsigned int inline norm_maxw(struct cx88_tvnorm *norm)
{ {
return (norm->id & (V4L2_STD_MN & ~V4L2_STD_PAL_Nc)) ? 720 : 768; 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; return (norm->id & V4L2_STD_625_50) ? 576 : 480;
} }
...@@ -319,7 +312,7 @@ struct cx88_core { ...@@ -319,7 +312,7 @@ struct cx88_core {
/* state info */ /* state info */
struct task_struct *kthread; struct task_struct *kthread;
struct cx88_tvnorm *tvnorm; struct v4l2_tvnorm *tvnorm;
u32 tvaudio; u32 tvaudio;
u32 audiomode_manual; u32 audiomode_manual;
u32 audiomode_current; u32 audiomode_current;
...@@ -536,7 +529,7 @@ extern void cx88_sram_channel_dump(struct cx88_core *core, ...@@ -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, extern int cx88_set_scale(struct cx88_core *core, unsigned int width,
unsigned int height, enum v4l2_field field); 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, extern struct video_device *cx88_vdev_init(struct cx88_core *core,
struct pci_dev *pci, struct pci_dev *pci,
...@@ -553,7 +546,10 @@ extern int cx88_stop_audio_dma(struct cx88_core *core); ...@@ -553,7 +546,10 @@ extern int cx88_stop_audio_dma(struct cx88_core *core);
/* ----------------------------------------------------------- */ /* ----------------------------------------------------------- */
/* cx88-vbi.c */ /* 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, int cx8800_start_vbi_dma(struct cx8800_dev *dev,
struct cx88_dmaqueue *q, 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