From: Joonyoung Shim <jy0922.shim@samsung.com>
To: alsa-devel@alsa-project.org
Cc: kyungmin.park@samsung.com, broonie@opensource.wolfsonmicro.com
Subject: [PATCH] ASoC: MAX9877: separate callback functions
Date: Wed, 22 Jul 2009 14:09:08 +0900 [thread overview]
Message-ID: <4A669EF4.2070504@samsung.com> (raw)
The callback function to control register was used by whole controls in
MAX9877 driver, but this causes using many if statement for double
register control or invert.
So, the callback function for double register control is separate
differently, and the code for invert is added in the callback function.
Signed-off-by: Joonyoung Shim <jy0922.shim@samsung.com>
---
sound/soc/codecs/max9877.c | 96 +++++++++++++++++++++++++++++---------------
1 files changed, 63 insertions(+), 33 deletions(-)
diff --git a/sound/soc/codecs/max9877.c b/sound/soc/codecs/max9877.c
index 7df9a7c..a1f1119 100644
--- a/sound/soc/codecs/max9877.c
+++ b/sound/soc/codecs/max9877.c
@@ -34,16 +34,16 @@ static int max9877_get_reg(struct snd_kcontrol *kcontrol,
{
struct soc_mixer_control *mc =
(struct soc_mixer_control *)kcontrol->private_value;
- int reg = mc->reg;
- int reg2 = mc->rreg;
- int shift = mc->shift;
- int mask = mc->max;
+ unsigned int reg = mc->reg;
+ unsigned int shift = mc->shift;
+ unsigned int mask = mc->max;
+ unsigned int invert = mc->invert;
ucontrol->value.integer.value[0] = (max9877_regs[reg] >> shift) & mask;
- if (reg2)
- ucontrol->value.integer.value[1] =
- (max9877_regs[reg2] >> shift) & mask;
+ if (invert)
+ ucontrol->value.integer.value[0] =
+ mask - ucontrol->value.integer.value[0];
return 0;
}
@@ -53,39 +53,69 @@ static int max9877_set_reg(struct snd_kcontrol *kcontrol,
{
struct soc_mixer_control *mc =
(struct soc_mixer_control *)kcontrol->private_value;
- int reg = mc->reg;
- int reg2 = mc->rreg;
- int shift = mc->shift;
- int mask = mc->max;
- int change = 1;
- int change2 = 1;
- int ret = 0;
-
- if (((max9877_regs[reg] >> shift) & mask) ==
- ucontrol->value.integer.value[0])
+ unsigned int reg = mc->reg;
+ unsigned int shift = mc->shift;
+ unsigned int mask = mc->max;
+ unsigned int invert = mc->invert;
+ unsigned int val = (ucontrol->value.integer.value[0] & mask);
+
+ if (invert)
+ val = mask - val;
+
+ if (((max9877_regs[reg] >> shift) & mask) == val)
+ return 0;
+
+ max9877_regs[reg] &= ~(mask << shift);
+ max9877_regs[reg] |= val << shift;
+ max9877_write_regs();
+
+ return 1;
+}
+
+static int max9877_get_2reg(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct soc_mixer_control *mc =
+ (struct soc_mixer_control *)kcontrol->private_value;
+ unsigned int reg = mc->reg;
+ unsigned int reg2 = mc->rreg;
+ unsigned int shift = mc->shift;
+ unsigned int mask = mc->max;
+
+ ucontrol->value.integer.value[0] = (max9877_regs[reg] >> shift) & mask;
+ ucontrol->value.integer.value[1] = (max9877_regs[reg2] >> shift) & mask;
+
+ return 0;
+}
+
+static int max9877_set_2reg(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct soc_mixer_control *mc =
+ (struct soc_mixer_control *)kcontrol->private_value;
+ unsigned int reg = mc->reg;
+ unsigned int reg2 = mc->rreg;
+ unsigned int shift = mc->shift;
+ unsigned int mask = mc->max;
+ unsigned int val = (ucontrol->value.integer.value[0] & mask);
+ unsigned int val2 = (ucontrol->value.integer.value[1] & mask);
+ unsigned int change = 1;
+
+ if (((max9877_regs[reg] >> shift) & mask) == val)
change = 0;
- if (reg2)
- if (((max9877_regs[reg2] >> shift) & mask) ==
- ucontrol->value.integer.value[1])
- change2 = 0;
+ if (((max9877_regs[reg2] >> shift) & mask) == val2)
+ change = 0;
if (change) {
max9877_regs[reg] &= ~(mask << shift);
- max9877_regs[reg] |= ucontrol->value.integer.value[0] << shift;
- ret = change;
- }
-
- if (reg2 && change2) {
+ max9877_regs[reg] |= val << shift;
max9877_regs[reg2] &= ~(mask << shift);
- max9877_regs[reg2] |= ucontrol->value.integer.value[1] << shift;
- ret = change2;
- }
-
- if (ret)
+ max9877_regs[reg2] |= val2 << shift;
max9877_write_regs();
+ }
- return ret;
+ return change;
}
static int max9877_get_out_mode(struct snd_kcontrol *kcontrol,
@@ -190,7 +220,7 @@ static const struct snd_kcontrol_new max9877_controls[] = {
max9877_get_reg, max9877_set_reg, max9877_output_tlv),
SOC_DOUBLE_R_EXT_TLV("MAX9877 Amp HP Playback Volume",
MAX9877_HPL_VOLUME, MAX9877_HPR_VOLUME, 0, 31, 0,
- max9877_get_reg, max9877_set_reg, max9877_output_tlv),
+ max9877_get_2reg, max9877_set_2reg, max9877_output_tlv),
SOC_SINGLE_EXT("MAX9877 INB Stereo Switch",
MAX9877_INPUT_MODE, 4, 1, 1,
max9877_get_reg, max9877_set_reg),
--
1.6.0.4
next reply other threads:[~2009-07-22 5:09 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-22 5:09 Joonyoung Shim [this message]
2009-07-22 9:41 ` [PATCH] ASoC: MAX9877: separate callback functions Mark Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4A669EF4.2070504@samsung.com \
--to=jy0922.shim@samsung.com \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@opensource.wolfsonmicro.com \
--cc=kyungmin.park@samsung.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.