mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00
[media] tvaudio: fix broken volume/balance calculations
The balance control did not do what it is supposed to do due to wrong calculations. Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
This commit is contained in:
parent
ea01a83d5c
commit
a346caacf3
1 changed files with 27 additions and 38 deletions
|
@ -93,8 +93,8 @@ struct CHIPDESC {
|
||||||
/* which register has which value */
|
/* which register has which value */
|
||||||
int leftreg,rightreg,treblereg,bassreg;
|
int leftreg,rightreg,treblereg,bassreg;
|
||||||
|
|
||||||
/* initialize with (defaults to 65535/65535/32768/32768 */
|
/* initialize with (defaults to 65535/32768/32768 */
|
||||||
int leftinit,rightinit,trebleinit,bassinit;
|
int volinit, trebleinit, bassinit;
|
||||||
|
|
||||||
/* functions to convert the values (v4l -> chip) */
|
/* functions to convert the values (v4l -> chip) */
|
||||||
getvalue volfunc,treblefunc,bassfunc;
|
getvalue volfunc,treblefunc,bassfunc;
|
||||||
|
@ -122,7 +122,7 @@ struct CHIPSTATE {
|
||||||
audiocmd shadow;
|
audiocmd shadow;
|
||||||
|
|
||||||
/* current settings */
|
/* current settings */
|
||||||
__u16 left, right, treble, bass, muted;
|
u16 volume, balance, treble, bass, muted;
|
||||||
int prevmode;
|
int prevmode;
|
||||||
int radio;
|
int radio;
|
||||||
int input;
|
int input;
|
||||||
|
@ -1523,8 +1523,7 @@ static struct CHIPDESC chiplist[] = {
|
||||||
.rightreg = TDA9875_MVR,
|
.rightreg = TDA9875_MVR,
|
||||||
.bassreg = TDA9875_MBA,
|
.bassreg = TDA9875_MBA,
|
||||||
.treblereg = TDA9875_MTR,
|
.treblereg = TDA9875_MTR,
|
||||||
.leftinit = 58880,
|
.volinit = 58880,
|
||||||
.rightinit = 58880,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
.name = "tda9850",
|
.name = "tda9850",
|
||||||
|
@ -1694,20 +1693,13 @@ static int tvaudio_g_ctrl(struct v4l2_subdev *sd,
|
||||||
case V4L2_CID_AUDIO_VOLUME:
|
case V4L2_CID_AUDIO_VOLUME:
|
||||||
if (!(desc->flags & CHIP_HAS_VOLUME))
|
if (!(desc->flags & CHIP_HAS_VOLUME))
|
||||||
break;
|
break;
|
||||||
ctrl->value = max(chip->left,chip->right);
|
ctrl->value = chip->volume;
|
||||||
return 0;
|
return 0;
|
||||||
case V4L2_CID_AUDIO_BALANCE:
|
case V4L2_CID_AUDIO_BALANCE:
|
||||||
{
|
|
||||||
int volume;
|
|
||||||
if (!(desc->flags & CHIP_HAS_VOLUME))
|
if (!(desc->flags & CHIP_HAS_VOLUME))
|
||||||
break;
|
break;
|
||||||
volume = max(chip->left,chip->right);
|
ctrl->value = chip->balance;
|
||||||
if (volume)
|
|
||||||
ctrl->value=(32768*min(chip->left,chip->right))/volume;
|
|
||||||
else
|
|
||||||
ctrl->value=32768;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
case V4L2_CID_AUDIO_BASS:
|
case V4L2_CID_AUDIO_BASS:
|
||||||
if (!(desc->flags & CHIP_HAS_BASSTREBLE))
|
if (!(desc->flags & CHIP_HAS_BASSTREBLE))
|
||||||
break;
|
break;
|
||||||
|
@ -1744,41 +1736,38 @@ static int tvaudio_s_ctrl(struct v4l2_subdev *sd,
|
||||||
return 0;
|
return 0;
|
||||||
case V4L2_CID_AUDIO_VOLUME:
|
case V4L2_CID_AUDIO_VOLUME:
|
||||||
{
|
{
|
||||||
int volume,balance;
|
u32 volume, balance;
|
||||||
|
u32 left, right;
|
||||||
|
|
||||||
if (!(desc->flags & CHIP_HAS_VOLUME))
|
if (!(desc->flags & CHIP_HAS_VOLUME))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
volume = max(chip->left,chip->right);
|
volume = ctrl->value;
|
||||||
if (volume)
|
chip->volume = volume;
|
||||||
balance=(32768*min(chip->left,chip->right))/volume;
|
balance = chip->balance;
|
||||||
else
|
left = (min(65536U - balance, 32768U) * volume) / 32768U;
|
||||||
balance=32768;
|
right = (min(balance, 32768U) * volume) / 32768U;
|
||||||
|
|
||||||
volume=ctrl->value;
|
|
||||||
chip->left = (min(65536 - balance,32768) * volume) / 32768;
|
|
||||||
chip->right = (min(balance,volume *(__u16)32768)) / 32768;
|
|
||||||
|
|
||||||
chip_write(chip,desc->leftreg,desc->volfunc(chip->left));
|
|
||||||
chip_write(chip,desc->rightreg,desc->volfunc(chip->right));
|
|
||||||
|
|
||||||
|
chip_write(chip, desc->leftreg, desc->volfunc(left));
|
||||||
|
chip_write(chip, desc->rightreg, desc->volfunc(right));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
case V4L2_CID_AUDIO_BALANCE:
|
case V4L2_CID_AUDIO_BALANCE:
|
||||||
{
|
{
|
||||||
int volume, balance;
|
u32 volume, balance;
|
||||||
|
u32 left, right;
|
||||||
|
|
||||||
if (!(desc->flags & CHIP_HAS_VOLUME))
|
if (!(desc->flags & CHIP_HAS_VOLUME))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
volume = max(chip->left, chip->right);
|
|
||||||
balance = ctrl->value;
|
balance = ctrl->value;
|
||||||
chip->left = (min(65536 - balance, 32768) * volume) / 32768;
|
chip->balance = balance;
|
||||||
chip->right = (min(balance, volume * (__u16)32768)) / 32768;
|
volume = chip->volume;
|
||||||
|
left = (min(65536U - balance, 32768U) * volume) / 32768U;
|
||||||
chip_write(chip, desc->leftreg, desc->volfunc(chip->left));
|
right = (min(balance, 32768U) * volume) / 32768U;
|
||||||
chip_write(chip, desc->rightreg, desc->volfunc(chip->right));
|
|
||||||
|
|
||||||
|
chip_write(chip, desc->leftreg, desc->volfunc(left));
|
||||||
|
chip_write(chip, desc->rightreg, desc->volfunc(right));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
case V4L2_CID_AUDIO_BASS:
|
case V4L2_CID_AUDIO_BASS:
|
||||||
|
@ -2043,12 +2032,12 @@ static int tvaudio_probe(struct i2c_client *client, const struct i2c_device_id *
|
||||||
v4l2_info(sd, "volume callback undefined!\n");
|
v4l2_info(sd, "volume callback undefined!\n");
|
||||||
desc->flags &= ~CHIP_HAS_VOLUME;
|
desc->flags &= ~CHIP_HAS_VOLUME;
|
||||||
} else {
|
} else {
|
||||||
chip->left = desc->leftinit ? desc->leftinit : 65535;
|
chip->volume = desc->volinit ? desc->volinit : 65535;
|
||||||
chip->right = desc->rightinit ? desc->rightinit : 65535;
|
chip->balance = 32768;
|
||||||
chip_write(chip, desc->leftreg,
|
chip_write(chip, desc->leftreg,
|
||||||
desc->volfunc(chip->left));
|
desc->volfunc(chip->volume));
|
||||||
chip_write(chip, desc->rightreg,
|
chip_write(chip, desc->rightreg,
|
||||||
desc->volfunc(chip->right));
|
desc->volfunc(chip->volume));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (desc->flags & CHIP_HAS_BASSTREBLE) {
|
if (desc->flags & CHIP_HAS_BASSTREBLE) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue