aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/i2c/tvaudio.c
diff options
context:
space:
mode:
authorHans Verkuil <hans.verkuil@cisco.com>2013-02-02 03:57:37 -0500
committerMauro Carvalho Chehab <mchehab@redhat.com>2013-02-05 15:03:23 -0500
commita346caacf31907085e8425bdab7cf5147545439e (patch)
tree8f6cea50605dd28bb1a1fa70050f02e354a39d71 /drivers/media/i2c/tvaudio.c
parentea01a83d5c88a3e0bb124ec4b3abf3aefcf0d719 (diff)
[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>
Diffstat (limited to 'drivers/media/i2c/tvaudio.c')
-rw-r--r--drivers/media/i2c/tvaudio.c65
1 files changed, 27 insertions, 38 deletions
diff --git a/drivers/media/i2c/tvaudio.c b/drivers/media/i2c/tvaudio.c
index 3b24d3fc1866..d5cd2eb95558 100644
--- a/drivers/media/i2c/tvaudio.c
+++ b/drivers/media/i2c/tvaudio.c
@@ -93,8 +93,8 @@ struct CHIPDESC {
93 /* which register has which value */ 93 /* which register has which value */
94 int leftreg,rightreg,treblereg,bassreg; 94 int leftreg,rightreg,treblereg,bassreg;
95 95
96 /* initialize with (defaults to 65535/65535/32768/32768 */ 96 /* initialize with (defaults to 65535/32768/32768 */
97 int leftinit,rightinit,trebleinit,bassinit; 97 int volinit, trebleinit, bassinit;
98 98
99 /* functions to convert the values (v4l -> chip) */ 99 /* functions to convert the values (v4l -> chip) */
100 getvalue volfunc,treblefunc,bassfunc; 100 getvalue volfunc,treblefunc,bassfunc;
@@ -122,7 +122,7 @@ struct CHIPSTATE {
122 audiocmd shadow; 122 audiocmd shadow;
123 123
124 /* current settings */ 124 /* current settings */
125 __u16 left, right, treble, bass, muted; 125 u16 volume, balance, treble, bass, muted;
126 int prevmode; 126 int prevmode;
127 int radio; 127 int radio;
128 int input; 128 int input;
@@ -1523,8 +1523,7 @@ static struct CHIPDESC chiplist[] = {
1523 .rightreg = TDA9875_MVR, 1523 .rightreg = TDA9875_MVR,
1524 .bassreg = TDA9875_MBA, 1524 .bassreg = TDA9875_MBA,
1525 .treblereg = TDA9875_MTR, 1525 .treblereg = TDA9875_MTR,
1526 .leftinit = 58880, 1526 .volinit = 58880,
1527 .rightinit = 58880,
1528 }, 1527 },
1529 { 1528 {
1530 .name = "tda9850", 1529 .name = "tda9850",
@@ -1694,20 +1693,13 @@ static int tvaudio_g_ctrl(struct v4l2_subdev *sd,
1694 case V4L2_CID_AUDIO_VOLUME: 1693 case V4L2_CID_AUDIO_VOLUME:
1695 if (!(desc->flags & CHIP_HAS_VOLUME)) 1694 if (!(desc->flags & CHIP_HAS_VOLUME))
1696 break; 1695 break;
1697 ctrl->value = max(chip->left,chip->right); 1696 ctrl->value = chip->volume;
1698 return 0; 1697 return 0;
1699 case V4L2_CID_AUDIO_BALANCE: 1698 case V4L2_CID_AUDIO_BALANCE:
1700 {
1701 int volume;
1702 if (!(desc->flags & CHIP_HAS_VOLUME)) 1699 if (!(desc->flags & CHIP_HAS_VOLUME))
1703 break; 1700 break;
1704 volume = max(chip->left,chip->right); 1701 ctrl->value = chip->balance;
1705 if (volume)
1706 ctrl->value=(32768*min(chip->left,chip->right))/volume;
1707 else
1708 ctrl->value=32768;
1709 return 0; 1702 return 0;
1710 }
1711 case V4L2_CID_AUDIO_BASS: 1703 case V4L2_CID_AUDIO_BASS:
1712 if (!(desc->flags & CHIP_HAS_BASSTREBLE)) 1704 if (!(desc->flags & CHIP_HAS_BASSTREBLE))
1713 break; 1705 break;
@@ -1744,41 +1736,38 @@ static int tvaudio_s_ctrl(struct v4l2_subdev *sd,
1744 return 0; 1736 return 0;
1745 case V4L2_CID_AUDIO_VOLUME: 1737 case V4L2_CID_AUDIO_VOLUME:
1746 { 1738 {
1747 int volume,balance; 1739 u32 volume, balance;
1740 u32 left, right;
1748 1741
1749 if (!(desc->flags & CHIP_HAS_VOLUME)) 1742 if (!(desc->flags & CHIP_HAS_VOLUME))
1750 break; 1743 break;
1751 1744
1752 volume = max(chip->left,chip->right); 1745 volume = ctrl->value;
1753 if (volume) 1746 chip->volume = volume;
1754 balance=(32768*min(chip->left,chip->right))/volume; 1747 balance = chip->balance;
1755 else 1748 left = (min(65536U - balance, 32768U) * volume) / 32768U;
1756 balance=32768; 1749 right = (min(balance, 32768U) * volume) / 32768U;
1757
1758 volume=ctrl->value;
1759 chip->left = (min(65536 - balance,32768) * volume) / 32768;
1760 chip->right = (min(balance,volume *(__u16)32768)) / 32768;
1761
1762 chip_write(chip,desc->leftreg,desc->volfunc(chip->left));
1763 chip_write(chip,desc->rightreg,desc->volfunc(chip->right));
1764 1750
1751 chip_write(chip, desc->leftreg, desc->volfunc(left));
1752 chip_write(chip, desc->rightreg, desc->volfunc(right));
1765 return 0; 1753 return 0;
1766 } 1754 }
1767 case V4L2_CID_AUDIO_BALANCE: 1755 case V4L2_CID_AUDIO_BALANCE:
1768 { 1756 {
1769 int volume, balance; 1757 u32 volume, balance;
1758 u32 left, right;
1770 1759
1771 if (!(desc->flags & CHIP_HAS_VOLUME)) 1760 if (!(desc->flags & CHIP_HAS_VOLUME))
1772 break; 1761 break;
1773 1762
1774 volume = max(chip->left, chip->right);
1775 balance = ctrl->value; 1763 balance = ctrl->value;
1776 chip->left = (min(65536 - balance, 32768) * volume) / 32768; 1764 chip->balance = balance;
1777 chip->right = (min(balance, volume * (__u16)32768)) / 32768; 1765 volume = chip->volume;
1778 1766 left = (min(65536U - balance, 32768U) * volume) / 32768U;
1779 chip_write(chip, desc->leftreg, desc->volfunc(chip->left)); 1767 right = (min(balance, 32768U) * volume) / 32768U;
1780 chip_write(chip, desc->rightreg, desc->volfunc(chip->right));
1781 1768
1769 chip_write(chip, desc->leftreg, desc->volfunc(left));
1770 chip_write(chip, desc->rightreg, desc->volfunc(right));
1782 return 0; 1771 return 0;
1783 } 1772 }
1784 case V4L2_CID_AUDIO_BASS: 1773 case V4L2_CID_AUDIO_BASS:
@@ -2043,12 +2032,12 @@ static int tvaudio_probe(struct i2c_client *client, const struct i2c_device_id *
2043 v4l2_info(sd, "volume callback undefined!\n"); 2032 v4l2_info(sd, "volume callback undefined!\n");
2044 desc->flags &= ~CHIP_HAS_VOLUME; 2033 desc->flags &= ~CHIP_HAS_VOLUME;
2045 } else { 2034 } else {
2046 chip->left = desc->leftinit ? desc->leftinit : 65535; 2035 chip->volume = desc->volinit ? desc->volinit : 65535;
2047 chip->right = desc->rightinit ? desc->rightinit : 65535; 2036 chip->balance = 32768;
2048 chip_write(chip, desc->leftreg, 2037 chip_write(chip, desc->leftreg,
2049 desc->volfunc(chip->left)); 2038 desc->volfunc(chip->volume));
2050 chip_write(chip, desc->rightreg, 2039 chip_write(chip, desc->rightreg,
2051 desc->volfunc(chip->right)); 2040 desc->volfunc(chip->volume));
2052 } 2041 }
2053 } 2042 }
2054 if (desc->flags & CHIP_HAS_BASSTREBLE) { 2043 if (desc->flags & CHIP_HAS_BASSTREBLE) {