Commit 046b3492 authored by lamikr's avatar lamikr Committed by Tony Lindgren

[PATCH 4/5] omap-alsa-tsc2101-mixer: merge similar looking methods together

omap-alsa-tsc2101-mixer: merge similar looking methods together
Signed-off-by: default avatarlamikr <lamikr@cc.jyu.fi>
parent da9cc862
...@@ -50,20 +50,15 @@ ...@@ -50,20 +50,15 @@
//#define M_DPRINTK(ARGS...) printk(KERN_INFO "<%s>: ",__FUNCTION__);printk(ARGS) //#define M_DPRINTK(ARGS...) printk(KERN_INFO "<%s>: ",__FUNCTION__);printk(ARGS)
#define M_DPRINTK(ARGS...) /* nop */ #define M_DPRINTK(ARGS...) /* nop */
#define CHECK_BIT(INDX, ARG) (((ARG) & TSC2101_BIT(INDX)) >> INDX)
#define IS_UNMUTED(INDX, ARG) (((CHECK_BIT(INDX, ARG)) == 0))
#define DGC_DALVL_EXTRACT(ARG) ((ARG & 0x7f00) >> 8) #define DGC_DALVL_EXTRACT(ARG) ((ARG & 0x7f00) >> 8)
#define DGC_DARVL_EXTRACT(ARG) ((ARG & 0x007f)) #define DGC_DARVL_EXTRACT(ARG) ((ARG & 0x007f))
#define GET_DGC_DALMU_BIT_VALUE(ARG) (((ARG) & TSC2101_BIT(15)) >> 15)
#define GET_DGC_DARMU_BIT_VALUE(ARG) (((ARG) & TSC2101_BIT(7)) >> 7)
#define IS_DGC_DALMU_UNMUTED(ARG) (((GET_DGC_DALMU_BIT_VALUE(ARG)) == 0))
#define IS_DGC_DARMU_UNMUTED(ARG) (((GET_DGC_DARMU_BIT_VALUE(ARG)) == 0))
#define HGC_ADPGA_HED_EXTRACT(ARG) ((ARG & 0x7f00) >> 8) #define HGC_ADPGA_HED_EXTRACT(ARG) ((ARG & 0x7f00) >> 8)
#define GET_DGC_HGCMU_BIT_VALUE(ARG) (((ARG) & TSC2101_BIT(15)) >> 15)
#define IS_DGC_HGCMU_UNMUTED(ARG) (((GET_DGC_HGCMU_BIT_VALUE(ARG)) == 0))
#define HNGC_ADPGA_HND_EXTRACT(ARG) ((ARG & 0x7f00) >> 8) #define HNGC_ADPGA_HND_EXTRACT(ARG) ((ARG & 0x7f00) >> 8)
#define GET_DGC_HNGCMU_BIT_VALUE(ARG) (((ARG) & TSC2101_BIT(15)) >> 15) #define BGC_ADPGA_BGC_EXTRACT(ARG) ((ARG & 0x7f00) >> 8)
#define IS_DGC_HNGCMU_UNMUTED(ARG) (((GET_DGC_HNGCMU_BIT_VALUE(ARG)) == 0))
static int current_playback_target = PLAYBACK_TARGET_LOUDSPEAKER; static int current_playback_target = PLAYBACK_TARGET_LOUDSPEAKER;
static int current_rec_src = REC_SRC_SINGLE_ENDED_MICIN_HED; static int current_rec_src = REC_SRC_SINGLE_ENDED_MICIN_HED;
...@@ -171,7 +166,11 @@ int set_mixer_volume_as_dac_gain_control_volume(int mixerVolL, int mixerVolR) ...@@ -171,7 +166,11 @@ int set_mixer_volume_as_dac_gain_control_volume(int mixerVolL, int mixerVolR)
return retVal; return retVal;
} }
int dac_gain_control_unmute_control(int muteLeft, int muteRight) /**
* If unmuteLeft/unmuteRight == 0 --> mute
* If unmuteLeft/unmuteRight == 1 --> unmute
*/
int dac_gain_control_unmute(int unmuteLeft, int unmuteRight)
{ {
u16 val; u16 val;
int count; int count;
...@@ -181,8 +180,8 @@ int dac_gain_control_unmute_control(int muteLeft, int muteRight) ...@@ -181,8 +180,8 @@ int dac_gain_control_unmute_control(int muteLeft, int muteRight)
/* in alsa mixer 1 --> on, 0 == off. In tsc2101 registry 1 --> off, 0 --> on /* in alsa mixer 1 --> on, 0 == off. In tsc2101 registry 1 --> off, 0 --> on
* so if values are same, it's time to change the registry value. * so if values are same, it's time to change the registry value.
*/ */
if (muteLeft == GET_DGC_DALMU_BIT_VALUE(val)) { if (unmuteLeft != IS_UNMUTED(15, val)) {
if (muteLeft == 0) { if (unmuteLeft == 0) {
/* mute --> turn bit on */ /* mute --> turn bit on */
val = val | DGC_DALMU; val = val | DGC_DALMU;
} }
...@@ -192,8 +191,8 @@ int dac_gain_control_unmute_control(int muteLeft, int muteRight) ...@@ -192,8 +191,8 @@ int dac_gain_control_unmute_control(int muteLeft, int muteRight)
} }
count++; count++;
} /* L */ } /* L */
if (muteRight == GET_DGC_DARMU_BIT_VALUE(val)) { if (unmuteRight != IS_UNMUTED(7, val)) {
if (muteRight == 0) { if (unmuteRight == 0) {
/* mute --> turn bit on */ /* mute --> turn bit on */
val = val | DGC_DARMU; val = val | DGC_DARMU;
} }
...@@ -206,8 +205,41 @@ int dac_gain_control_unmute_control(int muteLeft, int muteRight) ...@@ -206,8 +205,41 @@ int dac_gain_control_unmute_control(int muteLeft, int muteRight)
if (count) { if (count) {
omap_tsc2101_audio_write(TSC2101_DAC_GAIN_CTRL, val); omap_tsc2101_audio_write(TSC2101_DAC_GAIN_CTRL, val);
M_DPRINTK("changed value, is_unmuted left = %d, right = %d\n", M_DPRINTK("changed value, is_unmuted left = %d, right = %d\n",
IS_DGC_DALMU_UNMUTED(val), IS_UNMUTED(15, val),
IS_DGC_DARMU_UNMUTED(val)); IS_UNMUTED(7, val));
}
return count;
}
/**
* unmute: 0 --> mute, 1 --> unmute
* page2RegIndx: Registry index in tsc2101 page2.
* muteBitIndx: Index number for the bit in registry that indicates whether muted or unmuted.
*/
int adc_pga_unmute_control(int unmute, int page2regIndx, int muteBitIndx)
{
int count;
u16 val;
count = 0;
val = omap_tsc2101_audio_read(page2regIndx);
/* in alsa mixer 1 --> on, 0 == off. In tsc2101 registry 1 --> off, 0 --> on
* so if the values are same, it's time to change the registry value...
*/
if (unmute != IS_UNMUTED(muteBitIndx, val)) {
if (unmute == 0) {
/* mute --> turn bit on */
val = val | TSC2101_BIT(muteBitIndx);
}
else {
/* unmute --> turn bit off */
val = val & ~TSC2101_BIT(muteBitIndx);
}
M_DPRINTK("changed value, is_unmuted = %d\n", IS_UNMUTED(muteBitIndx, val));
count++;
}
if (count) {
omap_tsc2101_audio_write(page2regIndx, val);
} }
return count; return count;
} }
...@@ -442,7 +474,7 @@ void init_playback_targets(void) ...@@ -442,7 +474,7 @@ void init_playback_targets(void)
*/ */
set_mixer_volume_as_dac_gain_control_volume(DEFAULT_OUTPUT_VOLUME, DEFAULT_OUTPUT_VOLUME); set_mixer_volume_as_dac_gain_control_volume(DEFAULT_OUTPUT_VOLUME, DEFAULT_OUTPUT_VOLUME);
/* unmute */ /* unmute */
dac_gain_control_unmute_control(1, 1); dac_gain_control_unmute(1, 1);
} }
/* /*
...@@ -568,14 +600,14 @@ static int __pcm_playback_switch_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_valu ...@@ -568,14 +600,14 @@ static int __pcm_playback_switch_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_valu
{ {
u16 val = omap_tsc2101_audio_read(TSC2101_DAC_GAIN_CTRL); u16 val = omap_tsc2101_audio_read(TSC2101_DAC_GAIN_CTRL);
ucontrol->value.integer.value[0] = IS_DGC_DALMU_UNMUTED(val); ucontrol->value.integer.value[0] = IS_UNMUTED(15, val); // left
ucontrol->value.integer.value[1] = IS_DGC_DARMU_UNMUTED(val); ucontrol->value.integer.value[1] = IS_UNMUTED(7, val); // right
return 0; return 0;
} }
static int __pcm_playback_switch_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) static int __pcm_playback_switch_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
{ {
return dac_gain_control_unmute_control(ucontrol->value.integer.value[0], return dac_gain_control_unmute(ucontrol->value.integer.value[0],
ucontrol->value.integer.value[1]); ucontrol->value.integer.value[1]);
} }
...@@ -625,33 +657,16 @@ static int __headset_playback_switch_info(snd_kcontrol_t *kcontrol, snd_ctl_elem ...@@ -625,33 +657,16 @@ static int __headset_playback_switch_info(snd_kcontrol_t *kcontrol, snd_ctl_elem
static int __headset_playback_switch_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) static int __headset_playback_switch_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
{ {
u16 val = omap_tsc2101_audio_read(TSC2101_HEADSET_GAIN_CTRL); u16 val = omap_tsc2101_audio_read(TSC2101_HEADSET_GAIN_CTRL);
ucontrol->value.integer.value[0] = IS_DGC_HGCMU_UNMUTED(val); ucontrol->value.integer.value[0] = IS_UNMUTED(15, val);
return 0; return 0;
} }
static int __headset_playback_switch_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) static int __headset_playback_switch_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
{ {
int count = 0; // mute/unmute headset
u16 val = omap_tsc2101_audio_read(TSC2101_HEADSET_GAIN_CTRL); return adc_pga_unmute_control(ucontrol->value.integer.value[0],
/* in alsa mixer 1 --> on, 0 == off. In tsc2101 registry 1 --> off, 0 --> on TSC2101_HEADSET_GAIN_CTRL,
* so if values are same, it's time to change the registry value... 15);
*/
if (ucontrol->value.integer.value[0] == GET_DGC_HGCMU_BIT_VALUE(val)) {
if (ucontrol->value.integer.value[0] == 0) {
/* mute --> turn bit on */
val = val | HGC_ADMUT_HED;
}
else {
/* unmute --> turn bit off */
val = val & ~HGC_ADMUT_HED;
}
count++;
M_DPRINTK("changed value, is_unmuted = %d\n", IS_DGC_HGCMU_UNMUTED(val));
}
if (count) {
omap_tsc2101_audio_write(TSC2101_HEADSET_GAIN_CTRL, val);
}
return count;
} }
static int __handset_playback_volume_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo) static int __handset_playback_volume_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
...@@ -699,34 +714,16 @@ static int __handset_playback_switch_info(snd_kcontrol_t *kcontrol, snd_ctl_elem ...@@ -699,34 +714,16 @@ static int __handset_playback_switch_info(snd_kcontrol_t *kcontrol, snd_ctl_elem
static int __handset_playback_switch_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) static int __handset_playback_switch_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
{ {
u16 val = omap_tsc2101_audio_read(TSC2101_HANDSET_GAIN_CTRL); u16 val = omap_tsc2101_audio_read(TSC2101_HANDSET_GAIN_CTRL);
ucontrol->value.integer.value[0] = IS_DGC_HNGCMU_UNMUTED(val); ucontrol->value.integer.value[0] = IS_UNMUTED(15, val);
return 0; return 0;
} }
static int __handset_playback_switch_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) static int __handset_playback_switch_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
{ {
int count = 0; // handset mute/unmute
u16 val = omap_tsc2101_audio_read(TSC2101_HANDSET_GAIN_CTRL); return adc_pga_unmute_control(ucontrol->value.integer.value[0],
TSC2101_HANDSET_GAIN_CTRL,
/* in alsa mixer 1 --> on, 0 == off. In tsc2101 registry 1 --> off, 0 --> on 15);
* so if values are same, it's time to change the registry value...
*/
if (ucontrol->value.integer.value[0] == GET_DGC_HNGCMU_BIT_VALUE(val)) {
if (ucontrol->value.integer.value[0] == 0) {
/* mute --> turn bit on */
val = val | HNGC_ADMUT_HND;
}
else {
/* unmute --> turn bit off */
val = val & ~HNGC_ADMUT_HND;
}
M_DPRINTK("changed value, is_unmuted = %d\n", IS_DGC_HNGCMU_UNMUTED(val));
count++;
}
if (count) {
omap_tsc2101_audio_write(TSC2101_HANDSET_GAIN_CTRL, val);
}
return count;
} }
static snd_kcontrol_new_t tsc2101_control[] __devinitdata = { static snd_kcontrol_new_t tsc2101_control[] __devinitdata = {
......
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