From: mnzaki Date: Thu, 16 Sep 2010 22:15:25 +0000 (+0300) Subject: Fixed ioctl code and added coeff setting example code X-Git-Url: http://git.maemo.org/git/?p=aic34-eq;a=commitdiff_plain;h=HEAD Fixed ioctl code and added coeff setting example code --- diff --git a/kernel-2.6.28/sound/soc/codecs/tlv320aic3x.c b/kernel-2.6.28/sound/soc/codecs/tlv320aic3x.c index 944daaf..ec84be5 100644 --- a/kernel-2.6.28/sound/soc/codecs/tlv320aic3x.c +++ b/kernel-2.6.28/sound/soc/codecs/tlv320aic3x.c @@ -478,7 +478,6 @@ static int aic3x_dacfilter_write_coeffs (struct snd_soc_codec *codec, struct aic3x_iir_coeffs *coeffs) { printk("MNZ: dacfilter_write_coeffs\n"); - snd_soc_update_bits(codec, AIC3X_CODEC_DFILT_CTRL, EFFECTS_ON, 0); aic3x_write_coeff(codec, EFFECTS_LEFT_N0, coeffs->N0); aic3x_write_coeff(codec, EFFECTS_LEFT_N1, coeffs->N1); aic3x_write_coeff(codec, EFFECTS_LEFT_N2, coeffs->N2); @@ -501,7 +500,7 @@ static int aic3x_dacfilter_write_coeffs aic3x_write_coeff(codec, EFFECTS_RIGHT_D4, coeffs->D4); aic3x_write_coeff(codec, EFFECTS_RIGHT_D5, coeffs->D5); - return 0; + return 1; } int aic3x_dacfilter_set_coeffs @@ -510,31 +509,39 @@ int aic3x_dacfilter_set_coeffs struct aic3x_priv *aic3x = codec->private_data; memcpy((void*)&aic3x->dacfilter.coeffs, (void*)coeffs, sizeof(struct aic3x_iir_coeffs)); + if(aic3x->dacfilter.state == 2) + aic3x_dacfilter_set_state(codec, 0); return 0; } EXPORT_SYMBOL_GPL(aic3x_dacfilter_set_coeffs); int aic3x_dacfilter_set_state(struct snd_soc_codec *codec, int state) { + printk("MNZ: dacfilter_set_state to %i\n", state); struct aic3x_priv *aic3x = codec->private_data; - + int ret = 0; if(aic3x->dacfilter.state == state) return 0; - - aic3x->dacfilter.state = state; - if(state == 0) - snd_soc_update_bits(codec, AIC3X_CODEC_DFILT_CTRL, + snd_soc_update_bits(codec, AIC3X_CODEC_DFILT_CTRL, EFFECTS_ON, 0); - else if(state == 1) {} + + if(state == 0) + ret = 1; + else if(state == 1) + ret = 1; /* FIXME MNZ. Set preset from current chosen preset */ else if (state == 2){ - aic3x_dacfilter_write_coeffs(codec, &aic3x->dacfilter.coeffs); - snd_soc_update_bits(codec, AIC3X_CODEC_DFILT_CTRL, + ret = aic3x_dacfilter_write_coeffs(codec, + &aic3x->dacfilter.coeffs); + if(ret) snd_soc_update_bits(codec, AIC3X_CODEC_DFILT_CTRL, EFFECTS_ON, EFFECTS_ON); } + else ret = 0; - return 0; + if(ret) aic3x->dacfilter.state = state; + return ret; } + EXPORT_SYMBOL_GPL(aic3x_dacfilter_set_state); /* DAC Filter hwdep device callbacks */ @@ -554,8 +561,8 @@ static int snd_hwdep_dacfilter_ioctl_aic3x(struct snd_hwdep *hw, */ struct snd_soc_codec *codec = hw->private_data; if (cmd != 1) return -EINVAL; + printk("MNZ: IOCTL: cmd = %i, arg = %i\n", cmd, *((int*)arg)); return aic3x_dacfilter_set_state(codec, *((int*)arg)); - return 0; } static long snd_hwdep_dacfilter_read_aic3x(struct snd_hwdep *hw, diff --git a/setcoeffs.c b/setcoeffs.c new file mode 100644 index 0000000..1ea5b10 --- /dev/null +++ b/setcoeffs.c @@ -0,0 +1,34 @@ +#include +#include +#include +#include +#include + +struct iir_coeffs { + int16_t N0, N1, N2, D1, D2; + int16_t N3, N4, N5, D4, D5; +}; + +int main(){ + struct iir_coeffs coeffs = { + .N0 = 32767, .N1 = 4265, .N2 = -10472, .D1 = -6269, .D2 = 0, + .N3 = 32027, .N4 = -31187, .N5 = 30352, .D4 = 31187, .D5 = -29613 + }; + + snd_hwdep_t *hwdep; + int ret; int arg; + + ret = snd_hwdep_open(&hwdep, "hw:0,0", SND_HWDEP_OPEN_DUPLEX); + printf("open: %i\n", ret); + if(ret) return 1; + + ret = snd_hwdep_write(hwdep, (void*)&coeffs, sizeof(coeffs)); + printf("write: %i\n", ret); + + /* Set state to 2, which is 'Custom'. This writes coeffs to hardware + * and enables filter */ + arg = 2; + ret = snd_hwdep_ioctl(hwdep, 1, &arg); + printf("ioctl: %i\n", ret); + return 0; +}