(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);
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
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 */
*/
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,
--- /dev/null
+#include <stdint.h>
+#include <fcntl.h>
+#include <alsa/asoundlib.h>
+#include <alsa/hwdep.h>
+#include <stdio.h>
+
+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;
+}