Commit 5eba3571 authored by Mauro Carvalho Chehab's avatar Mauro Carvalho Chehab

V4L/DVB (6420): V4L2 conversion for tda9875 from V4L1 API

Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@infradead.org>
parent 7a00d45c
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
* *
* Copyright (c) 2000 Guillaume Delvit based on Gerd Knorr source and * Copyright (c) 2000 Guillaume Delvit based on Gerd Knorr source and
* Eric Sandeen * Eric Sandeen
* Copyright (c) 2006 Mauro Carvalho Chehab <mchehab@infradead.org>
* This code is placed under the terms of the GNU General Public License * This code is placed under the terms of the GNU General Public License
* Based on tda9855.c by Steve VanDeBogart (vandebo@uclink.berkeley.edu) * Based on tda9855.c by Steve VanDeBogart (vandebo@uclink.berkeley.edu)
* Which was based on tda8425.c by Greg Alexander (c) 1998 * Which was based on tda8425.c by Greg Alexander (c) 1998
...@@ -268,53 +269,95 @@ static int tda9875_detach(struct i2c_client *client) ...@@ -268,53 +269,95 @@ static int tda9875_detach(struct i2c_client *client)
return 0; return 0;
} }
static int tda9875_command(struct i2c_client *client, static int tda9875_get_ctrl(struct i2c_client *client,
unsigned int cmd, void *arg) struct v4l2_control *ctrl)
{ {
struct tda9875 *t = i2c_get_clientdata(client); struct tda9875 *t = i2c_get_clientdata(client);
dprintk("In tda9875_command...\n"); switch (ctrl->id) {
case V4L2_CID_AUDIO_VOLUME:
{
int left = (t->lvol+84)*606;
int right = (t->rvol+84)*606;
switch (cmd) { ctrl->value=max(left,right);
/* --- v4l ioctls --- */ return 0;
/* take care: bttv does userspace copying, we'll get a }
kernel pointer here... */ case V4L2_CID_AUDIO_BALANCE:
case VIDIOCGAUDIO:
{ {
struct video_audio *va = arg; int left = (t->lvol+84)*606;
int left,right; int right = (t->rvol+84)*606;
int volume = max(left,right);
int balance = (32768*min(left,right))/
(volume ? volume : 1);
ctrl->value=(left<right)?
(65535-balance) : balance;
return 0;
}
case V4L2_CID_AUDIO_BASS:
ctrl->value = (t->bass+12)*2427; /* min -12 max +15 */
return 0;
case V4L2_CID_AUDIO_TREBLE:
ctrl->value = (t->treble+12)*2730;/* min -12 max +12 */
return 0;
}
return -EINVAL;
}
static int tda9875_set_ctrl(struct i2c_client *client,
struct v4l2_control *ctrl)
{
struct tda9875 *t = i2c_get_clientdata(client);
int chvol=0, volume, balance, left, right;
switch (ctrl->id) {
case V4L2_CID_AUDIO_VOLUME:
left = (t->lvol+84)*606;
right = (t->rvol+84)*606;
dprintk("VIDIOCGAUDIO\n"); volume = max(left,right);
balance = (32768*min(left,right))/
(volume ? volume : 1);
balance =(left<right)?
(65535-balance) : balance;
va->flags |= VIDEO_AUDIO_VOLUME | volume = ctrl->value;
VIDEO_AUDIO_BASS |
VIDEO_AUDIO_TREBLE;
/* min is -84 max is 24 */ chvol=1;
break;
case V4L2_CID_AUDIO_BALANCE:
left = (t->lvol+84)*606; left = (t->lvol+84)*606;
right = (t->rvol+84)*606; right = (t->rvol+84)*606;
va->volume=max(left,right);
va->balance=(32768*min(left,right))/ volume=max(left,right);
(va->volume ? va->volume : 1);
va->balance=(left<right)? balance = ctrl->value;
(65535-va->balance) : va->balance;
va->bass = (t->bass+12)*2427; /* min -12 max +15 */ chvol=1;
va->treble = (t->treble+12)*2730;/* min -12 max +12 */ break;
va->mode |= VIDEO_SOUND_MONO; case V4L2_CID_AUDIO_BASS:
t->bass = ((ctrl->value/2400)-12) & 0xff;
break; /* VIDIOCGAUDIO case */ if (t->bass > 15)
t->bass = 15;
if (t->bass < -12)
t->bass = -12 & 0xff;
break;
case V4L2_CID_AUDIO_TREBLE:
t->treble = ((ctrl->value/2700)-12) & 0xff;
if (t->treble > 12)
t->treble = 12;
if (t->treble < -12)
t->treble = -12 & 0xff;
break;
default:
return -EINVAL;
} }
case VIDIOCSAUDIO: if (chvol) {
{ left = (min(65536 - balance,32768) *
struct video_audio *va = arg; volume) / 32768;
int left,right; right = (min(balance,32768) *
volume) / 32768;
dprintk("VIDEOCSAUDIO...\n");
left = (min(65536 - va->balance,32768) *
va->volume) / 32768;
right = (min(va->balance,(__u16)32768) *
va->volume) / 32768;
t->lvol = ((left/606)-84) & 0xff; t->lvol = ((left/606)-84) & 0xff;
if (t->lvol > 24) if (t->lvol > 24)
t->lvol = 24; t->lvol = 24;
...@@ -326,29 +369,43 @@ static int tda9875_command(struct i2c_client *client, ...@@ -326,29 +369,43 @@ static int tda9875_command(struct i2c_client *client,
t->rvol = 24; t->rvol = 24;
if (t->rvol < -84) if (t->rvol < -84)
t->rvol = -84 & 0xff; t->rvol = -84 & 0xff;
}
t->bass = ((va->bass/2400)-12) & 0xff; //printk("tda9875 bal:%04x vol:%04x bass:%04x treble:%04x\n",va->balance,va->volume,va->bass,va->treble);
if (t->bass > 15)
t->bass = 15;
if (t->bass < -12)
t->bass = -12 & 0xff;
t->treble = ((va->treble/2700)-12) & 0xff;
if (t->treble > 12)
t->treble = 12;
if (t->treble < -12)
t->treble = -12 & 0xff;
tda9875_set(client);
//printk("tda9875 bal:%04x vol:%04x bass:%04x treble:%04x\n",va->balance,va->volume,va->bass,va->treble); return 0;
}
tda9875_set(client); static int tda9875_command(struct i2c_client *client,
unsigned int cmd, void *arg)
{
dprintk("In tda9875_command...\n");
break; switch (cmd) {
/* --- v4l ioctls --- */
/* take care: bttv does userspace copying, we'll get a
kernel pointer here... */
case VIDIOC_QUERYCTRL:
{
struct v4l2_queryctrl *qc = arg;
switch (qc->id) {
case V4L2_CID_AUDIO_VOLUME:
case V4L2_CID_AUDIO_BASS:
case V4L2_CID_AUDIO_TREBLE:
default:
return -EINVAL;
}
return v4l2_ctrl_query_fill_std(qc);
}
case VIDIOC_S_CTRL:
return tda9875_set_ctrl(client, arg);
} /* end of VIDEOCSAUDIO case */ case VIDIOC_G_CTRL:
return tda9875_get_ctrl(client, arg);
default: /* Not VIDEOCGAUDIO or VIDEOCSAUDIO */ default: /* Not VIDEOCGAUDIO or VIDEOCSAUDIO */
......
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