Commit 6e65ca94 authored by Hans Verkuil's avatar Hans Verkuil Committed by Mauro Carvalho Chehab

[media] mxb/saa7146: first round of cleanups

Convert to the control framework, fix the easy v4l2-compliance failures.
Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 5becbc58
...@@ -429,8 +429,13 @@ static void vv_callback(struct saa7146_dev *dev, unsigned long status) ...@@ -429,8 +429,13 @@ static void vv_callback(struct saa7146_dev *dev, unsigned long status)
} }
} }
static const struct v4l2_ctrl_ops saa7146_ctrl_ops = {
.s_ctrl = saa7146_s_ctrl,
};
int saa7146_vv_init(struct saa7146_dev* dev, struct saa7146_ext_vv *ext_vv) int saa7146_vv_init(struct saa7146_dev* dev, struct saa7146_ext_vv *ext_vv)
{ {
struct v4l2_ctrl_handler *hdl = &dev->ctrl_handler;
struct saa7146_vv *vv; struct saa7146_vv *vv;
int err; int err;
...@@ -438,9 +443,28 @@ int saa7146_vv_init(struct saa7146_dev* dev, struct saa7146_ext_vv *ext_vv) ...@@ -438,9 +443,28 @@ int saa7146_vv_init(struct saa7146_dev* dev, struct saa7146_ext_vv *ext_vv)
if (err) if (err)
return err; return err;
v4l2_ctrl_handler_init(hdl, 6);
v4l2_ctrl_new_std(hdl, &saa7146_ctrl_ops,
V4L2_CID_BRIGHTNESS, 0, 255, 1, 128);
v4l2_ctrl_new_std(hdl, &saa7146_ctrl_ops,
V4L2_CID_CONTRAST, 0, 127, 1, 64);
v4l2_ctrl_new_std(hdl, &saa7146_ctrl_ops,
V4L2_CID_SATURATION, 0, 127, 1, 64);
v4l2_ctrl_new_std(hdl, &saa7146_ctrl_ops,
V4L2_CID_VFLIP, 0, 1, 1, 0);
v4l2_ctrl_new_std(hdl, &saa7146_ctrl_ops,
V4L2_CID_HFLIP, 0, 1, 1, 0);
if (hdl->error) {
err = hdl->error;
v4l2_ctrl_handler_free(hdl);
return err;
}
dev->v4l2_dev.ctrl_handler = hdl;
vv = kzalloc(sizeof(struct saa7146_vv), GFP_KERNEL); vv = kzalloc(sizeof(struct saa7146_vv), GFP_KERNEL);
if (vv == NULL) { if (vv == NULL) {
ERR("out of memory. aborting.\n"); ERR("out of memory. aborting.\n");
v4l2_ctrl_handler_free(hdl);
return -ENOMEM; return -ENOMEM;
} }
ext_vv->ops = saa7146_video_ioctl_ops; ext_vv->ops = saa7146_video_ioctl_ops;
...@@ -463,6 +487,7 @@ int saa7146_vv_init(struct saa7146_dev* dev, struct saa7146_ext_vv *ext_vv) ...@@ -463,6 +487,7 @@ int saa7146_vv_init(struct saa7146_dev* dev, struct saa7146_ext_vv *ext_vv)
if( NULL == vv->d_clipping.cpu_addr ) { if( NULL == vv->d_clipping.cpu_addr ) {
ERR("out of memory. aborting.\n"); ERR("out of memory. aborting.\n");
kfree(vv); kfree(vv);
v4l2_ctrl_handler_free(hdl);
return -1; return -1;
} }
memset(vv->d_clipping.cpu_addr, 0x0, SAA7146_CLIPPING_MEM); memset(vv->d_clipping.cpu_addr, 0x0, SAA7146_CLIPPING_MEM);
...@@ -486,6 +511,7 @@ int saa7146_vv_release(struct saa7146_dev* dev) ...@@ -486,6 +511,7 @@ int saa7146_vv_release(struct saa7146_dev* dev)
v4l2_device_unregister(&dev->v4l2_dev); v4l2_device_unregister(&dev->v4l2_dev);
pci_free_consistent(dev->pci, SAA7146_CLIPPING_MEM, vv->d_clipping.cpu_addr, vv->d_clipping.dma_handle); pci_free_consistent(dev->pci, SAA7146_CLIPPING_MEM, vv->d_clipping.cpu_addr, vv->d_clipping.dma_handle);
v4l2_ctrl_handler_free(&dev->ctrl_handler);
kfree(vv); kfree(vv);
dev->vv_data = NULL; dev->vv_data = NULL;
dev->vv_callback = NULL; dev->vv_callback = NULL;
...@@ -516,6 +542,7 @@ int saa7146_register_device(struct video_device **vid, struct saa7146_dev* dev, ...@@ -516,6 +542,7 @@ int saa7146_register_device(struct video_device **vid, struct saa7146_dev* dev,
This driver needs auditing so that this flag can be removed. */ This driver needs auditing so that this flag can be removed. */
set_bit(V4L2_FL_LOCK_ALL_FOPS, &vfd->flags); set_bit(V4L2_FL_LOCK_ALL_FOPS, &vfd->flags);
vfd->lock = &dev->v4l2_lock; vfd->lock = &dev->v4l2_lock;
vfd->v4l2_dev = &dev->v4l2_dev;
vfd->tvnorms = 0; vfd->tvnorms = 0;
for (i = 0; i < dev->ext_vv_data->num_stds; i++) for (i = 0; i < dev->ext_vv_data->num_stds; i++)
vfd->tvnorms |= dev->ext_vv_data->stds[i].id; vfd->tvnorms |= dev->ext_vv_data->stds[i].id;
......
...@@ -201,65 +201,6 @@ int saa7146_stop_preview(struct saa7146_fh *fh) ...@@ -201,65 +201,6 @@ int saa7146_stop_preview(struct saa7146_fh *fh)
} }
EXPORT_SYMBOL_GPL(saa7146_stop_preview); EXPORT_SYMBOL_GPL(saa7146_stop_preview);
/********************************************************************************/
/* device controls */
static struct v4l2_queryctrl controls[] = {
{
.id = V4L2_CID_BRIGHTNESS,
.name = "Brightness",
.minimum = 0,
.maximum = 255,
.step = 1,
.default_value = 128,
.type = V4L2_CTRL_TYPE_INTEGER,
.flags = V4L2_CTRL_FLAG_SLIDER,
},{
.id = V4L2_CID_CONTRAST,
.name = "Contrast",
.minimum = 0,
.maximum = 127,
.step = 1,
.default_value = 64,
.type = V4L2_CTRL_TYPE_INTEGER,
.flags = V4L2_CTRL_FLAG_SLIDER,
},{
.id = V4L2_CID_SATURATION,
.name = "Saturation",
.minimum = 0,
.maximum = 127,
.step = 1,
.default_value = 64,
.type = V4L2_CTRL_TYPE_INTEGER,
.flags = V4L2_CTRL_FLAG_SLIDER,
},{
.id = V4L2_CID_VFLIP,
.name = "Vertical Flip",
.minimum = 0,
.maximum = 1,
.type = V4L2_CTRL_TYPE_BOOLEAN,
},{
.id = V4L2_CID_HFLIP,
.name = "Horizontal Flip",
.minimum = 0,
.maximum = 1,
.type = V4L2_CTRL_TYPE_BOOLEAN,
},
};
static int NUM_CONTROLS = sizeof(controls)/sizeof(struct v4l2_queryctrl);
#define V4L2_CID_PRIVATE_LASTP1 (V4L2_CID_PRIVATE_BASE + 0)
static struct v4l2_queryctrl* ctrl_by_id(int id)
{
int i;
for (i = 0; i < NUM_CONTROLS; i++)
if (controls[i].id == id)
return controls+i;
return NULL;
}
/********************************************************************************/ /********************************************************************************/
/* common pagetable functions */ /* common pagetable functions */
...@@ -510,12 +451,13 @@ static int vidioc_querycap(struct file *file, void *fh, struct v4l2_capability * ...@@ -510,12 +451,13 @@ static int vidioc_querycap(struct file *file, void *fh, struct v4l2_capability *
strlcpy((char *)cap->card, dev->ext->name, sizeof(cap->card)); strlcpy((char *)cap->card, dev->ext->name, sizeof(cap->card));
sprintf((char *)cap->bus_info, "PCI:%s", pci_name(dev->pci)); sprintf((char *)cap->bus_info, "PCI:%s", pci_name(dev->pci));
cap->version = SAA7146_VERSION_CODE; cap->version = SAA7146_VERSION_CODE;
cap->capabilities = cap->device_caps =
V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_CAPTURE |
V4L2_CAP_VIDEO_OVERLAY | V4L2_CAP_VIDEO_OVERLAY |
V4L2_CAP_READWRITE | V4L2_CAP_READWRITE |
V4L2_CAP_STREAMING; V4L2_CAP_STREAMING;
cap->capabilities |= dev->ext_vv_data->capabilities; cap->device_caps |= dev->ext_vv_data->capabilities;
cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
return 0; return 0;
} }
...@@ -579,135 +521,58 @@ static int vidioc_enum_fmt_vid_cap(struct file *file, void *fh, struct v4l2_fmtd ...@@ -579,135 +521,58 @@ static int vidioc_enum_fmt_vid_cap(struct file *file, void *fh, struct v4l2_fmtd
return 0; return 0;
} }
static int vidioc_queryctrl(struct file *file, void *fh, struct v4l2_queryctrl *c) int saa7146_s_ctrl(struct v4l2_ctrl *ctrl)
{
const struct v4l2_queryctrl *ctrl;
if ((c->id < V4L2_CID_BASE ||
c->id >= V4L2_CID_LASTP1) &&
(c->id < V4L2_CID_PRIVATE_BASE ||
c->id >= V4L2_CID_PRIVATE_LASTP1))
return -EINVAL;
ctrl = ctrl_by_id(c->id);
if (ctrl == NULL)
return -EINVAL;
DEB_EE("VIDIOC_QUERYCTRL: id:%d\n", c->id);
*c = *ctrl;
return 0;
}
static int vidioc_g_ctrl(struct file *file, void *fh, struct v4l2_control *c)
{ {
struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev; struct saa7146_dev *dev = container_of(ctrl->handler,
struct saa7146_dev, ctrl_handler);
struct saa7146_vv *vv = dev->vv_data; struct saa7146_vv *vv = dev->vv_data;
const struct v4l2_queryctrl *ctrl; u32 val;
u32 value = 0;
ctrl = ctrl_by_id(c->id); switch (ctrl->id) {
if (NULL == ctrl)
return -EINVAL;
switch (c->id) {
case V4L2_CID_BRIGHTNESS: case V4L2_CID_BRIGHTNESS:
value = saa7146_read(dev, BCS_CTRL); val = saa7146_read(dev, BCS_CTRL);
c->value = 0xff & (value >> 24); val &= 0x00ffffff;
DEB_D("V4L2_CID_BRIGHTNESS: %d\n", c->value); val |= (ctrl->val << 24);
break; saa7146_write(dev, BCS_CTRL, val);
case V4L2_CID_CONTRAST:
value = saa7146_read(dev, BCS_CTRL);
c->value = 0x7f & (value >> 16);
DEB_D("V4L2_CID_CONTRAST: %d\n", c->value);
break;
case V4L2_CID_SATURATION:
value = saa7146_read(dev, BCS_CTRL);
c->value = 0x7f & (value >> 0);
DEB_D("V4L2_CID_SATURATION: %d\n", c->value);
break;
case V4L2_CID_VFLIP:
c->value = vv->vflip;
DEB_D("V4L2_CID_VFLIP: %d\n", c->value);
break;
case V4L2_CID_HFLIP:
c->value = vv->hflip;
DEB_D("V4L2_CID_HFLIP: %d\n", c->value);
break;
default:
return -EINVAL;
}
return 0;
}
static int vidioc_s_ctrl(struct file *file, void *fh, struct v4l2_control *c)
{
struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
struct saa7146_vv *vv = dev->vv_data;
const struct v4l2_queryctrl *ctrl;
ctrl = ctrl_by_id(c->id);
if (NULL == ctrl) {
DEB_D("unknown control %d\n", c->id);
return -EINVAL;
}
switch (ctrl->type) {
case V4L2_CTRL_TYPE_BOOLEAN:
case V4L2_CTRL_TYPE_MENU:
case V4L2_CTRL_TYPE_INTEGER:
if (c->value < ctrl->minimum)
c->value = ctrl->minimum;
if (c->value > ctrl->maximum)
c->value = ctrl->maximum;
break;
default:
/* nothing */;
}
switch (c->id) {
case V4L2_CID_BRIGHTNESS: {
u32 value = saa7146_read(dev, BCS_CTRL);
value &= 0x00ffffff;
value |= (c->value << 24);
saa7146_write(dev, BCS_CTRL, value);
saa7146_write(dev, MC2, MASK_22 | MASK_06); saa7146_write(dev, MC2, MASK_22 | MASK_06);
break; break;
}
case V4L2_CID_CONTRAST: { case V4L2_CID_CONTRAST:
u32 value = saa7146_read(dev, BCS_CTRL); val = saa7146_read(dev, BCS_CTRL);
value &= 0xff00ffff; val &= 0xff00ffff;
value |= (c->value << 16); val |= (ctrl->val << 16);
saa7146_write(dev, BCS_CTRL, value); saa7146_write(dev, BCS_CTRL, val);
saa7146_write(dev, MC2, MASK_22 | MASK_06); saa7146_write(dev, MC2, MASK_22 | MASK_06);
break; break;
}
case V4L2_CID_SATURATION: { case V4L2_CID_SATURATION:
u32 value = saa7146_read(dev, BCS_CTRL); val = saa7146_read(dev, BCS_CTRL);
value &= 0xffffff00; val &= 0xffffff00;
value |= (c->value << 0); val |= (ctrl->val << 0);
saa7146_write(dev, BCS_CTRL, value); saa7146_write(dev, BCS_CTRL, val);
saa7146_write(dev, MC2, MASK_22 | MASK_06); saa7146_write(dev, MC2, MASK_22 | MASK_06);
break; break;
}
case V4L2_CID_HFLIP: case V4L2_CID_HFLIP:
/* fixme: we can support changing VFLIP and HFLIP here... */ /* fixme: we can support changing VFLIP and HFLIP here... */
if (IS_CAPTURE_ACTIVE(fh) != 0) { if ((vv->video_status & STATUS_CAPTURE))
DEB_D("V4L2_CID_HFLIP while active capture\n");
return -EBUSY; return -EBUSY;
} vv->hflip = ctrl->val;
vv->hflip = c->value;
break; break;
case V4L2_CID_VFLIP: case V4L2_CID_VFLIP:
if (IS_CAPTURE_ACTIVE(fh) != 0) { if ((vv->video_status & STATUS_CAPTURE))
DEB_D("V4L2_CID_VFLIP while active capture\n");
return -EBUSY; return -EBUSY;
} vv->vflip = ctrl->val;
vv->vflip = c->value;
break; break;
default: default:
return -EINVAL; return -EINVAL;
} }
if (IS_OVERLAY_ACTIVE(fh) != 0) { if ((vv->video_status & STATUS_OVERLAY) != 0) { /* CHECK: && (vv->video_fh == fh)) */
struct saa7146_fh *fh = vv->video_fh;
saa7146_stop_preview(fh); saa7146_stop_preview(fh);
saa7146_start_preview(fh); saa7146_start_preview(fh);
} }
...@@ -720,6 +585,8 @@ static int vidioc_g_parm(struct file *file, void *fh, ...@@ -720,6 +585,8 @@ static int vidioc_g_parm(struct file *file, void *fh,
struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev; struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
struct saa7146_vv *vv = dev->vv_data; struct saa7146_vv *vv = dev->vv_data;
if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
return -EINVAL;
parm->parm.capture.readbuffers = 1; parm->parm.capture.readbuffers = 1;
v4l2_video_std_frame_period(vv->standard->id, v4l2_video_std_frame_period(vv->standard->id,
&parm->parm.capture.timeperframe); &parm->parm.capture.timeperframe);
...@@ -787,6 +654,7 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *fh, struct v4l2_forma ...@@ -787,6 +654,7 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *fh, struct v4l2_forma
} }
f->fmt.pix.field = field; f->fmt.pix.field = field;
f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
if (f->fmt.pix.width > maxw) if (f->fmt.pix.width > maxw)
f->fmt.pix.width = maxw; f->fmt.pix.width = maxw;
if (f->fmt.pix.height > maxh) if (f->fmt.pix.height > maxh)
...@@ -1141,9 +1009,6 @@ const struct v4l2_ioctl_ops saa7146_video_ioctl_ops = { ...@@ -1141,9 +1009,6 @@ const struct v4l2_ioctl_ops saa7146_video_ioctl_ops = {
.vidioc_dqbuf = vidioc_dqbuf, .vidioc_dqbuf = vidioc_dqbuf,
.vidioc_g_std = vidioc_g_std, .vidioc_g_std = vidioc_g_std,
.vidioc_s_std = vidioc_s_std, .vidioc_s_std = vidioc_s_std,
.vidioc_queryctrl = vidioc_queryctrl,
.vidioc_g_ctrl = vidioc_g_ctrl,
.vidioc_s_ctrl = vidioc_s_ctrl,
.vidioc_streamon = vidioc_streamon, .vidioc_streamon = vidioc_streamon,
.vidioc_streamoff = vidioc_streamoff, .vidioc_streamoff = vidioc_streamoff,
.vidioc_g_parm = vidioc_g_parm, .vidioc_g_parm = vidioc_g_parm,
...@@ -1338,6 +1203,7 @@ static int video_open(struct saa7146_dev *dev, struct file *file) ...@@ -1338,6 +1203,7 @@ static int video_open(struct saa7146_dev *dev, struct file *file)
fh->video_fmt.pixelformat = V4L2_PIX_FMT_BGR24; fh->video_fmt.pixelformat = V4L2_PIX_FMT_BGR24;
fh->video_fmt.bytesperline = 0; fh->video_fmt.bytesperline = 0;
fh->video_fmt.field = V4L2_FIELD_ANY; fh->video_fmt.field = V4L2_FIELD_ANY;
fh->video_fmt.colorspace = V4L2_COLORSPACE_SMPTE170M;
sfmt = saa7146_format_by_fourcc(dev,fh->video_fmt.pixelformat); sfmt = saa7146_format_by_fourcc(dev,fh->video_fmt.pixelformat);
fh->video_fmt.sizeimage = (fh->video_fmt.width * fh->video_fmt.height * sfmt->depth)/8; fh->video_fmt.sizeimage = (fh->video_fmt.width * fh->video_fmt.height * sfmt->depth)/8;
......
...@@ -64,8 +64,8 @@ enum { TUNER, AUX1, AUX3, AUX3_YC }; ...@@ -64,8 +64,8 @@ enum { TUNER, AUX1, AUX3, AUX3_YC };
static struct v4l2_input mxb_inputs[MXB_INPUTS] = { static struct v4l2_input mxb_inputs[MXB_INPUTS] = {
{ TUNER, "Tuner", V4L2_INPUT_TYPE_TUNER, 1, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0, V4L2_IN_CAP_STD }, { TUNER, "Tuner", V4L2_INPUT_TYPE_TUNER, 1, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0, V4L2_IN_CAP_STD },
{ AUX1, "AUX1", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0, V4L2_IN_CAP_STD }, { AUX1, "AUX1", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0, V4L2_IN_CAP_STD },
{ AUX3, "AUX3 Composite", V4L2_INPUT_TYPE_CAMERA, 4, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0, V4L2_IN_CAP_STD }, { AUX3, "AUX3 Composite", V4L2_INPUT_TYPE_CAMERA, 8, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0, V4L2_IN_CAP_STD },
{ AUX3_YC, "AUX3 S-Video", V4L2_INPUT_TYPE_CAMERA, 4, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0, V4L2_IN_CAP_STD }, { AUX3_YC, "AUX3 S-Video", V4L2_INPUT_TYPE_CAMERA, 8, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0, V4L2_IN_CAP_STD },
}; };
/* this array holds the information, which port of the saa7146 each /* this array holds the information, which port of the saa7146 each
...@@ -90,6 +90,36 @@ struct mxb_routing { ...@@ -90,6 +90,36 @@ struct mxb_routing {
u32 output; u32 output;
}; };
/* these are the available audio sources, which can switched
to the line- and cd-output individually */
static struct v4l2_audio mxb_audios[MXB_AUDIOS] = {
{
.index = 0,
.name = "Tuner",
.capability = V4L2_AUDCAP_STEREO,
} , {
.index = 1,
.name = "AUX1",
.capability = V4L2_AUDCAP_STEREO,
} , {
.index = 2,
.name = "AUX2",
.capability = V4L2_AUDCAP_STEREO,
} , {
.index = 3,
.name = "AUX3",
.capability = V4L2_AUDCAP_STEREO,
} , {
.index = 4,
.name = "Radio (X9)",
.capability = V4L2_AUDCAP_STEREO,
} , {
.index = 5,
.name = "CD-ROM (X10)",
.capability = V4L2_AUDCAP_STEREO,
}
};
/* These are the necessary input-output-pins for bringing one audio source /* These are the necessary input-output-pins for bringing one audio source
(see above) to the CD-output. Note that gain is set to 0 in this table. */ (see above) to the CD-output. Note that gain is set to 0 in this table. */
static struct mxb_routing TEA6420_cd[MXB_AUDIOS + 1][2] = { static struct mxb_routing TEA6420_cd[MXB_AUDIOS + 1][2] = {
...@@ -114,11 +144,6 @@ static struct mxb_routing TEA6420_line[MXB_AUDIOS + 1][2] = { ...@@ -114,11 +144,6 @@ static struct mxb_routing TEA6420_line[MXB_AUDIOS + 1][2] = {
{ { 6, 3 }, { 6, 2 } } /* Mute */ { { 6, 3 }, { 6, 2 } } /* Mute */
}; };
#define MAXCONTROLS 1
static struct v4l2_queryctrl mxb_controls[] = {
{ V4L2_CID_AUDIO_MUTE, V4L2_CTRL_TYPE_BOOLEAN, "Mute", 0, 1, 1, 0, 0 },
};
struct mxb struct mxb
{ {
struct video_device *video_dev; struct video_device *video_dev;
...@@ -168,16 +193,45 @@ static inline void tea6420_route_line(struct mxb *mxb, int idx) ...@@ -168,16 +193,45 @@ static inline void tea6420_route_line(struct mxb *mxb, int idx)
static struct saa7146_extension extension; static struct saa7146_extension extension;
static int mxb_s_ctrl(struct v4l2_ctrl *ctrl)
{
struct saa7146_dev *dev = container_of(ctrl->handler,
struct saa7146_dev, ctrl_handler);
struct mxb *mxb = dev->ext_priv;
switch (ctrl->id) {
case V4L2_CID_AUDIO_MUTE:
mxb->cur_mute = ctrl->val;
/* switch the audio-source */
tea6420_route_line(mxb, ctrl->val ? 6 :
video_audio_connect[mxb->cur_input]);
break;
default:
return -EINVAL;
}
return 0;
}
static const struct v4l2_ctrl_ops mxb_ctrl_ops = {
.s_ctrl = mxb_s_ctrl,
};
static int mxb_probe(struct saa7146_dev *dev) static int mxb_probe(struct saa7146_dev *dev)
{ {
struct v4l2_ctrl_handler *hdl = &dev->ctrl_handler;
struct mxb *mxb = NULL; struct mxb *mxb = NULL;
v4l2_ctrl_new_std(hdl, &mxb_ctrl_ops,
V4L2_CID_AUDIO_MUTE, 0, 1, 1, 0);
if (hdl->error)
return hdl->error;
mxb = kzalloc(sizeof(struct mxb), GFP_KERNEL); mxb = kzalloc(sizeof(struct mxb), GFP_KERNEL);
if (mxb == NULL) { if (mxb == NULL) {
DEB_D("not enough kernel memory\n"); DEB_D("not enough kernel memory\n");
return -ENOMEM; return -ENOMEM;
} }
snprintf(mxb->i2c_adapter.name, sizeof(mxb->i2c_adapter.name), "mxb%d", mxb_num); snprintf(mxb->i2c_adapter.name, sizeof(mxb->i2c_adapter.name), "mxb%d", mxb_num);
saa7146_i2c_adapter_prepare(dev, &mxb->i2c_adapter, SAA7146_I2C_BUS_BIT_RATE_480); saa7146_i2c_adapter_prepare(dev, &mxb->i2c_adapter, SAA7146_I2C_BUS_BIT_RATE_480);
...@@ -385,69 +439,6 @@ void mxb_irq_bh(struct saa7146_dev* dev, u32* irq_mask) ...@@ -385,69 +439,6 @@ void mxb_irq_bh(struct saa7146_dev* dev, u32* irq_mask)
} }
*/ */
static int vidioc_queryctrl(struct file *file, void *fh, struct v4l2_queryctrl *qc)
{
struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
int i;
for (i = MAXCONTROLS - 1; i >= 0; i--) {
if (mxb_controls[i].id == qc->id) {
*qc = mxb_controls[i];
DEB_D("VIDIOC_QUERYCTRL %d\n", qc->id);
return 0;
}
}
return dev->ext_vv_data->core_ops->vidioc_queryctrl(file, fh, qc);
}
static int vidioc_g_ctrl(struct file *file, void *fh, struct v4l2_control *vc)
{
struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
struct mxb *mxb = (struct mxb *)dev->ext_priv;
int i;
for (i = MAXCONTROLS - 1; i >= 0; i--) {
if (mxb_controls[i].id == vc->id)
break;
}
if (i < 0)
return dev->ext_vv_data->core_ops->vidioc_g_ctrl(file, fh, vc);
if (vc->id == V4L2_CID_AUDIO_MUTE) {
vc->value = mxb->cur_mute;
DEB_D("VIDIOC_G_CTRL V4L2_CID_AUDIO_MUTE:%d\n", vc->value);
return 0;
}
DEB_EE("VIDIOC_G_CTRL V4L2_CID_AUDIO_MUTE:%d\n", vc->value);
return 0;
}
static int vidioc_s_ctrl(struct file *file, void *fh, struct v4l2_control *vc)
{
struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
struct mxb *mxb = (struct mxb *)dev->ext_priv;
int i = 0;
for (i = MAXCONTROLS - 1; i >= 0; i--) {
if (mxb_controls[i].id == vc->id)
break;
}
if (i < 0)
return dev->ext_vv_data->core_ops->vidioc_s_ctrl(file, fh, vc);
if (vc->id == V4L2_CID_AUDIO_MUTE) {
mxb->cur_mute = vc->value;
/* switch the audio-source */
tea6420_route_line(mxb, vc->value ? 6 :
video_audio_connect[mxb->cur_input]);
DEB_EE("VIDIOC_S_CTRL, V4L2_CID_AUDIO_MUTE: %d\n", vc->value);
}
return 0;
}
static int vidioc_enum_input(struct file *file, void *fh, struct v4l2_input *i) static int vidioc_enum_input(struct file *file, void *fh, struct v4l2_input *i)
{ {
DEB_EE("VIDIOC_ENUMINPUT %d\n", i->index); DEB_EE("VIDIOC_ENUMINPUT %d\n", i->index);
...@@ -568,12 +559,8 @@ static int vidioc_g_frequency(struct file *file, void *fh, struct v4l2_frequency ...@@ -568,12 +559,8 @@ static int vidioc_g_frequency(struct file *file, void *fh, struct v4l2_frequency
struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev; struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
struct mxb *mxb = (struct mxb *)dev->ext_priv; struct mxb *mxb = (struct mxb *)dev->ext_priv;
if (mxb->cur_input) { if (f->tuner)
DEB_D("VIDIOC_G_FREQ: channel %d does not have a tuner!\n",
mxb->cur_input);
return -EINVAL; return -EINVAL;
}
*f = mxb->cur_freq; *f = mxb->cur_freq;
DEB_EE("VIDIOC_G_FREQ: freq:0x%08x\n", mxb->cur_freq.frequency); DEB_EE("VIDIOC_G_FREQ: freq:0x%08x\n", mxb->cur_freq.frequency);
...@@ -592,17 +579,16 @@ static int vidioc_s_frequency(struct file *file, void *fh, struct v4l2_frequency ...@@ -592,17 +579,16 @@ static int vidioc_s_frequency(struct file *file, void *fh, struct v4l2_frequency
if (V4L2_TUNER_ANALOG_TV != f->type) if (V4L2_TUNER_ANALOG_TV != f->type)
return -EINVAL; return -EINVAL;
if (mxb->cur_input) {
DEB_D("VIDIOC_S_FREQ: channel %d does not have a tuner!\n",
mxb->cur_input);
return -EINVAL;
}
mxb->cur_freq = *f;
DEB_EE("VIDIOC_S_FREQUENCY: freq:0x%08x\n", mxb->cur_freq.frequency); DEB_EE("VIDIOC_S_FREQUENCY: freq:0x%08x\n", mxb->cur_freq.frequency);
/* tune in desired frequency */ /* tune in desired frequency */
tuner_call(mxb, tuner, s_frequency, &mxb->cur_freq); tuner_call(mxb, tuner, s_frequency, f);
/* let the tuner subdev clamp the frequency to the tuner range */
tuner_call(mxb, tuner, g_frequency, f);
mxb->cur_freq = *f;
if (mxb->cur_input)
return 0;
/* hack: changing the frequency should invalidate the vbi-counter (=> alevt) */ /* hack: changing the frequency should invalidate the vbi-counter (=> alevt) */
spin_lock(&dev->slock); spin_lock(&dev->slock);
...@@ -612,6 +598,14 @@ static int vidioc_s_frequency(struct file *file, void *fh, struct v4l2_frequency ...@@ -612,6 +598,14 @@ static int vidioc_s_frequency(struct file *file, void *fh, struct v4l2_frequency
return 0; return 0;
} }
static int vidioc_enumaudio(struct file *file, void *fh, struct v4l2_audio *a)
{
if (a->index >= MXB_AUDIOS)
return -EINVAL;
*a = mxb_audios[a->index];
return 0;
}
static int vidioc_g_audio(struct file *file, void *fh, struct v4l2_audio *a) static int vidioc_g_audio(struct file *file, void *fh, struct v4l2_audio *a)
{ {
struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev; struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
...@@ -629,8 +623,13 @@ static int vidioc_g_audio(struct file *file, void *fh, struct v4l2_audio *a) ...@@ -629,8 +623,13 @@ static int vidioc_g_audio(struct file *file, void *fh, struct v4l2_audio *a)
static int vidioc_s_audio(struct file *file, void *fh, struct v4l2_audio *a) static int vidioc_s_audio(struct file *file, void *fh, struct v4l2_audio *a)
{ {
struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
struct mxb *mxb = (struct mxb *)dev->ext_priv;
DEB_D("VIDIOC_S_AUDIO %d\n", a->index); DEB_D("VIDIOC_S_AUDIO %d\n", a->index);
return 0; if (mxb_inputs[mxb->cur_input].audioset & (1 << a->index))
return 0;
return -EINVAL;
} }
#ifdef CONFIG_VIDEO_ADV_DEBUG #ifdef CONFIG_VIDEO_ADV_DEBUG
...@@ -709,9 +708,6 @@ static int mxb_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_data ...@@ -709,9 +708,6 @@ static int mxb_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_data
} }
mxb = (struct mxb *)dev->ext_priv; mxb = (struct mxb *)dev->ext_priv;
vv_data.ops.vidioc_queryctrl = vidioc_queryctrl;
vv_data.ops.vidioc_g_ctrl = vidioc_g_ctrl;
vv_data.ops.vidioc_s_ctrl = vidioc_s_ctrl;
vv_data.ops.vidioc_enum_input = vidioc_enum_input; vv_data.ops.vidioc_enum_input = vidioc_enum_input;
vv_data.ops.vidioc_g_input = vidioc_g_input; vv_data.ops.vidioc_g_input = vidioc_g_input;
vv_data.ops.vidioc_s_input = vidioc_s_input; vv_data.ops.vidioc_s_input = vidioc_s_input;
...@@ -719,6 +715,7 @@ static int mxb_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_data ...@@ -719,6 +715,7 @@ static int mxb_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_data
vv_data.ops.vidioc_s_tuner = vidioc_s_tuner; vv_data.ops.vidioc_s_tuner = vidioc_s_tuner;
vv_data.ops.vidioc_g_frequency = vidioc_g_frequency; vv_data.ops.vidioc_g_frequency = vidioc_g_frequency;
vv_data.ops.vidioc_s_frequency = vidioc_s_frequency; vv_data.ops.vidioc_s_frequency = vidioc_s_frequency;
vv_data.ops.vidioc_enumaudio = vidioc_enumaudio;
vv_data.ops.vidioc_g_audio = vidioc_g_audio; vv_data.ops.vidioc_g_audio = vidioc_g_audio;
vv_data.ops.vidioc_s_audio = vidioc_s_audio; vv_data.ops.vidioc_s_audio = vidioc_s_audio;
#ifdef CONFIG_VIDEO_ADV_DEBUG #ifdef CONFIG_VIDEO_ADV_DEBUG
...@@ -836,7 +833,7 @@ MODULE_DEVICE_TABLE(pci, pci_tbl); ...@@ -836,7 +833,7 @@ MODULE_DEVICE_TABLE(pci, pci_tbl);
static struct saa7146_ext_vv vv_data = { static struct saa7146_ext_vv vv_data = {
.inputs = MXB_INPUTS, .inputs = MXB_INPUTS,
.capabilities = V4L2_CAP_TUNER | V4L2_CAP_VBI_CAPTURE, .capabilities = V4L2_CAP_TUNER | V4L2_CAP_VBI_CAPTURE | V4L2_CAP_AUDIO,
.stds = &standard[0], .stds = &standard[0],
.num_stds = sizeof(standard)/sizeof(struct saa7146_standard), .num_stds = sizeof(standard)/sizeof(struct saa7146_standard),
.std_callback = &std_callback, .std_callback = &std_callback,
......
...@@ -10,33 +10,4 @@ ...@@ -10,33 +10,4 @@
#define MXB_AUDIOS 6 #define MXB_AUDIOS 6
/* these are the available audio sources, which can switched
to the line- and cd-output individually */
static struct v4l2_audio mxb_audios[MXB_AUDIOS] = {
{
.index = 0,
.name = "Tuner",
.capability = V4L2_AUDCAP_STEREO,
} , {
.index = 1,
.name = "AUX1",
.capability = V4L2_AUDCAP_STEREO,
} , {
.index = 2,
.name = "AUX2",
.capability = V4L2_AUDCAP_STEREO,
} , {
.index = 3,
.name = "AUX3",
.capability = V4L2_AUDCAP_STEREO,
} , {
.index = 4,
.name = "Radio (X9)",
.capability = V4L2_AUDCAP_STEREO,
} , {
.index = 5,
.name = "CD-ROM (X10)",
.capability = V4L2_AUDCAP_STEREO,
}
};
#endif #endif
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/scatterlist.h> #include <linux/scatterlist.h>
#include <media/v4l2-device.h> #include <media/v4l2-device.h>
#include <media/v4l2-ctrls.h>
#include <linux/vmalloc.h> /* for vmalloc() */ #include <linux/vmalloc.h> /* for vmalloc() */
#include <linux/mm.h> /* for vmalloc_to_page() */ #include <linux/mm.h> /* for vmalloc_to_page() */
...@@ -121,6 +122,7 @@ struct saa7146_dev ...@@ -121,6 +122,7 @@ struct saa7146_dev
struct list_head item; struct list_head item;
struct v4l2_device v4l2_dev; struct v4l2_device v4l2_dev;
struct v4l2_ctrl_handler ctrl_handler;
/* different device locks */ /* different device locks */
spinlock_t slock; spinlock_t slock;
......
...@@ -206,6 +206,7 @@ extern struct saa7146_use_ops saa7146_video_uops; ...@@ -206,6 +206,7 @@ extern struct saa7146_use_ops saa7146_video_uops;
int saa7146_start_preview(struct saa7146_fh *fh); int saa7146_start_preview(struct saa7146_fh *fh);
int saa7146_stop_preview(struct saa7146_fh *fh); int saa7146_stop_preview(struct saa7146_fh *fh);
long saa7146_video_do_ioctl(struct file *file, unsigned int cmd, void *arg); long saa7146_video_do_ioctl(struct file *file, unsigned int cmd, void *arg);
int saa7146_s_ctrl(struct v4l2_ctrl *ctrl);
/* from saa7146_vbi.c */ /* from saa7146_vbi.c */
extern struct saa7146_use_ops saa7146_vbi_uops; extern struct saa7146_use_ops saa7146_vbi_uops;
......
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