forked from Minki/linux
ASoC: Intel: mrfld: add the gain controls
The DSP has various gain modules in the path, add these as ALSA gain controls Signed-off-by: Vinod Koul <vinod.koul@intel.com> Signed-off-by: Subhransu S. Prusty <subhransu.s.prusty@intel.com> Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
parent
f114040e3e
commit
4fa805738e
@ -1,6 +1,6 @@
|
||||
config SND_MFLD_MACHINE
|
||||
tristate "SOC Machine Audio driver for Intel Medfield MID platform"
|
||||
depends on INTEL_SCU_IPC
|
||||
depends on INTEL_SCU_IPC || COMPILE_TEST
|
||||
select SND_SOC_SN95031
|
||||
select SND_SST_MFLD_PLATFORM
|
||||
help
|
||||
|
@ -162,6 +162,190 @@ static int sst_algo_control_set(struct snd_kcontrol *kcontrol,
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int sst_gain_ctl_info(struct snd_kcontrol *kcontrol,
|
||||
struct snd_ctl_elem_info *uinfo)
|
||||
{
|
||||
struct sst_gain_mixer_control *mc = (void *)kcontrol->private_value;
|
||||
|
||||
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
|
||||
uinfo->count = mc->stereo ? 2 : 1;
|
||||
uinfo->value.integer.min = mc->min;
|
||||
uinfo->value.integer.max = mc->max;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* sst_send_gain_cmd - send the gain algorithm IPC to the FW
|
||||
* @gv: the stored value of gain (also contains rampduration)
|
||||
* @mute: flag that indicates whether this was called from the
|
||||
* digital_mute callback or directly. If called from the
|
||||
* digital_mute callback, module will be muted/unmuted based on this
|
||||
* flag. The flag is always 0 if called directly.
|
||||
*
|
||||
* Called with sst_data.lock held
|
||||
*
|
||||
* The user-set gain value is sent only if the user-controllable 'mute' control
|
||||
* is OFF (indicated by gv->mute). Otherwise, the mute value (MIN value) is
|
||||
* sent.
|
||||
*/
|
||||
static int sst_send_gain_cmd(struct sst_data *drv, struct sst_gain_value *gv,
|
||||
u16 task_id, u16 loc_id, u16 module_id, int mute)
|
||||
{
|
||||
struct sst_cmd_set_gain_dual cmd;
|
||||
|
||||
dev_dbg(&drv->pdev->dev, "Enter\n");
|
||||
|
||||
cmd.header.command_id = MMX_SET_GAIN;
|
||||
SST_FILL_DEFAULT_DESTINATION(cmd.header.dst);
|
||||
cmd.gain_cell_num = 1;
|
||||
|
||||
if (mute || gv->mute) {
|
||||
cmd.cell_gains[0].cell_gain_left = SST_GAIN_MIN_VALUE;
|
||||
cmd.cell_gains[0].cell_gain_right = SST_GAIN_MIN_VALUE;
|
||||
} else {
|
||||
cmd.cell_gains[0].cell_gain_left = gv->l_gain;
|
||||
cmd.cell_gains[0].cell_gain_right = gv->r_gain;
|
||||
}
|
||||
|
||||
SST_FILL_DESTINATION(2, cmd.cell_gains[0].dest,
|
||||
loc_id, module_id);
|
||||
cmd.cell_gains[0].gain_time_constant = gv->ramp_duration;
|
||||
|
||||
cmd.header.length = sizeof(struct sst_cmd_set_gain_dual)
|
||||
- sizeof(struct sst_dsp_header);
|
||||
|
||||
/* we are with lock held, so call the unlocked api to send */
|
||||
return sst_fill_and_send_cmd_unlocked(drv, SST_IPC_IA_SET_PARAMS,
|
||||
SST_FLAG_BLOCKED, task_id, 0, &cmd,
|
||||
sizeof(cmd.header) + cmd.header.length);
|
||||
}
|
||||
|
||||
static int sst_gain_get(struct snd_kcontrol *kcontrol,
|
||||
struct snd_ctl_elem_value *ucontrol)
|
||||
{
|
||||
struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
|
||||
struct sst_gain_mixer_control *mc = (void *)kcontrol->private_value;
|
||||
struct sst_gain_value *gv = mc->gain_val;
|
||||
|
||||
switch (mc->type) {
|
||||
case SST_GAIN_TLV:
|
||||
ucontrol->value.integer.value[0] = gv->l_gain;
|
||||
ucontrol->value.integer.value[1] = gv->r_gain;
|
||||
break;
|
||||
|
||||
case SST_GAIN_MUTE:
|
||||
ucontrol->value.integer.value[0] = gv->mute ? 1 : 0;
|
||||
break;
|
||||
|
||||
case SST_GAIN_RAMP_DURATION:
|
||||
ucontrol->value.integer.value[0] = gv->ramp_duration;
|
||||
break;
|
||||
|
||||
default:
|
||||
dev_err(component->dev, "Invalid Input- gain type:%d\n",
|
||||
mc->type);
|
||||
return -EINVAL;
|
||||
};
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int sst_gain_put(struct snd_kcontrol *kcontrol,
|
||||
struct snd_ctl_elem_value *ucontrol)
|
||||
{
|
||||
int ret = 0;
|
||||
struct snd_soc_component *cmpnt = snd_soc_kcontrol_component(kcontrol);
|
||||
struct sst_data *drv = snd_soc_component_get_drvdata(cmpnt);
|
||||
struct sst_gain_mixer_control *mc = (void *)kcontrol->private_value;
|
||||
struct sst_gain_value *gv = mc->gain_val;
|
||||
|
||||
mutex_lock(&drv->lock);
|
||||
|
||||
switch (mc->type) {
|
||||
case SST_GAIN_TLV:
|
||||
gv->l_gain = ucontrol->value.integer.value[0];
|
||||
gv->r_gain = ucontrol->value.integer.value[1];
|
||||
dev_dbg(cmpnt->dev, "%s: Volume %d, %d\n",
|
||||
mc->pname, gv->l_gain, gv->r_gain);
|
||||
break;
|
||||
|
||||
case SST_GAIN_MUTE:
|
||||
gv->mute = !!ucontrol->value.integer.value[0];
|
||||
dev_dbg(cmpnt->dev, "%s: Mute %d\n", mc->pname, gv->mute);
|
||||
break;
|
||||
|
||||
case SST_GAIN_RAMP_DURATION:
|
||||
gv->ramp_duration = ucontrol->value.integer.value[0];
|
||||
dev_dbg(cmpnt->dev, "%s: Ramp Delay%d\n",
|
||||
mc->pname, gv->ramp_duration);
|
||||
break;
|
||||
|
||||
default:
|
||||
mutex_unlock(&drv->lock);
|
||||
dev_err(cmpnt->dev, "Invalid Input- gain type:%d\n",
|
||||
mc->type);
|
||||
return -EINVAL;
|
||||
};
|
||||
|
||||
if (mc->w && mc->w->power)
|
||||
ret = sst_send_gain_cmd(drv, gv, mc->task_id,
|
||||
mc->pipe_id | mc->instance_id, mc->module_id, 0);
|
||||
mutex_unlock(&drv->lock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const DECLARE_TLV_DB_SCALE(sst_gain_tlv_common, SST_GAIN_MIN_VALUE * 10, 10, 0);
|
||||
|
||||
/* Gain helper with min/max set */
|
||||
#define SST_GAIN(name, path_id, task_id, instance, gain_var) \
|
||||
SST_GAIN_KCONTROLS(name, "Gain", SST_GAIN_MIN_VALUE, SST_GAIN_MAX_VALUE, \
|
||||
SST_GAIN_TC_MIN, SST_GAIN_TC_MAX, \
|
||||
sst_gain_get, sst_gain_put, \
|
||||
SST_MODULE_ID_GAIN_CELL, path_id, instance, task_id, \
|
||||
sst_gain_tlv_common, gain_var)
|
||||
|
||||
#define SST_VOLUME(name, path_id, task_id, instance, gain_var) \
|
||||
SST_GAIN_KCONTROLS(name, "Volume", SST_GAIN_MIN_VALUE, SST_GAIN_MAX_VALUE, \
|
||||
SST_GAIN_TC_MIN, SST_GAIN_TC_MAX, \
|
||||
sst_gain_get, sst_gain_put, \
|
||||
SST_MODULE_ID_VOLUME, path_id, instance, task_id, \
|
||||
sst_gain_tlv_common, gain_var)
|
||||
|
||||
static struct sst_gain_value sst_gains[];
|
||||
|
||||
static const struct snd_kcontrol_new sst_gain_controls[] = {
|
||||
SST_GAIN("media0_in", SST_PATH_INDEX_MEDIA0_IN, SST_TASK_MMX, 0, &sst_gains[0]),
|
||||
SST_GAIN("media1_in", SST_PATH_INDEX_MEDIA1_IN, SST_TASK_MMX, 0, &sst_gains[1]),
|
||||
SST_GAIN("media2_in", SST_PATH_INDEX_MEDIA2_IN, SST_TASK_MMX, 0, &sst_gains[2]),
|
||||
SST_GAIN("media3_in", SST_PATH_INDEX_MEDIA3_IN, SST_TASK_MMX, 0, &sst_gains[3]),
|
||||
|
||||
SST_GAIN("pcm0_in", SST_PATH_INDEX_PCM0_IN, SST_TASK_SBA, 0, &sst_gains[4]),
|
||||
SST_GAIN("pcm1_in", SST_PATH_INDEX_PCM1_IN, SST_TASK_SBA, 0, &sst_gains[5]),
|
||||
SST_GAIN("pcm1_out", SST_PATH_INDEX_PCM1_OUT, SST_TASK_SBA, 0, &sst_gains[6]),
|
||||
SST_GAIN("pcm2_out", SST_PATH_INDEX_PCM2_OUT, SST_TASK_SBA, 0, &sst_gains[7]),
|
||||
|
||||
SST_GAIN("codec_in0", SST_PATH_INDEX_CODEC_IN0, SST_TASK_SBA, 0, &sst_gains[8]),
|
||||
SST_GAIN("codec_in1", SST_PATH_INDEX_CODEC_IN1, SST_TASK_SBA, 0, &sst_gains[9]),
|
||||
SST_GAIN("codec_out0", SST_PATH_INDEX_CODEC_OUT0, SST_TASK_SBA, 0, &sst_gains[10]),
|
||||
SST_GAIN("codec_out1", SST_PATH_INDEX_CODEC_OUT1, SST_TASK_SBA, 0, &sst_gains[11]),
|
||||
SST_GAIN("media_loop1_out", SST_PATH_INDEX_MEDIA_LOOP1_OUT, SST_TASK_SBA, 0, &sst_gains[12]),
|
||||
SST_GAIN("media_loop2_out", SST_PATH_INDEX_MEDIA_LOOP2_OUT, SST_TASK_SBA, 0, &sst_gains[13]),
|
||||
SST_GAIN("sprot_loop_out", SST_PATH_INDEX_SPROT_LOOP_OUT, SST_TASK_SBA, 0, &sst_gains[14]),
|
||||
SST_VOLUME("media0_in", SST_PATH_INDEX_MEDIA0_IN, SST_TASK_MMX, 0, &sst_gains[15]),
|
||||
};
|
||||
|
||||
#define SST_GAIN_NUM_CONTROLS 3
|
||||
/* the SST_GAIN macro above will create three alsa controls for each
|
||||
* instance invoked, gain, mute and ramp duration, which use the same gain
|
||||
* cell sst_gain to keep track of data
|
||||
* To calculate number of gain cell instances we need to device by 3 in
|
||||
* below caulcation for gain cell memory.
|
||||
* This gets rid of static number and issues while adding new controls
|
||||
*/
|
||||
static struct sst_gain_value sst_gains[ARRAY_SIZE(sst_gain_controls)/SST_GAIN_NUM_CONTROLS];
|
||||
|
||||
static const struct snd_kcontrol_new sst_algo_controls[] = {
|
||||
SST_ALGO_KCONTROL_BYTES("media_loop1_out", "fir", 272, SST_MODULE_ID_FIR_24,
|
||||
SST_PATH_INDEX_MEDIA_LOOP1_OUT, 0, SST_TASK_SBA, SBA_VB_SET_FIR),
|
||||
@ -200,19 +384,33 @@ static int sst_algo_control_init(struct device *dev)
|
||||
|
||||
int sst_dsp_init_v2_dpcm(struct snd_soc_platform *platform)
|
||||
{
|
||||
int ret = 0;
|
||||
int i, ret = 0;
|
||||
struct sst_data *drv = snd_soc_platform_get_drvdata(platform);
|
||||
unsigned int gains = ARRAY_SIZE(sst_gain_controls)/3;
|
||||
|
||||
drv->byte_stream = devm_kzalloc(platform->dev,
|
||||
SST_MAX_BIN_BYTES, GFP_KERNEL);
|
||||
if (!drv->byte_stream)
|
||||
return -ENOMEM;
|
||||
|
||||
/*Initialize algo control params*/
|
||||
for (i = 0; i < gains; i++) {
|
||||
sst_gains[i].mute = SST_GAIN_MUTE_DEFAULT;
|
||||
sst_gains[i].l_gain = SST_GAIN_VOLUME_DEFAULT;
|
||||
sst_gains[i].r_gain = SST_GAIN_VOLUME_DEFAULT;
|
||||
sst_gains[i].ramp_duration = SST_GAIN_RAMP_DURATION_DEFAULT;
|
||||
}
|
||||
|
||||
ret = snd_soc_add_platform_controls(platform, sst_gain_controls,
|
||||
ARRAY_SIZE(sst_gain_controls));
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
/* Initialize algo control params */
|
||||
ret = sst_algo_control_init(platform->dev);
|
||||
if (ret)
|
||||
return ret;
|
||||
ret = snd_soc_add_platform_controls(platform, sst_algo_controls,
|
||||
ARRAY_SIZE(sst_algo_controls));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -23,6 +23,9 @@
|
||||
#ifndef __SST_ATOM_CONTROLS_H__
|
||||
#define __SST_ATOM_CONTROLS_H__
|
||||
|
||||
#include <sound/soc.h>
|
||||
#include <sound/tlv.h>
|
||||
|
||||
enum {
|
||||
MERR_DPCM_AUDIO = 0,
|
||||
MERR_DPCM_COMPR,
|
||||
@ -360,16 +363,134 @@ struct sst_dsp_header {
|
||||
struct sst_cmd_generic {
|
||||
struct sst_dsp_header header;
|
||||
} __packed;
|
||||
|
||||
struct gain_cell {
|
||||
struct sst_destination_id dest;
|
||||
s16 cell_gain_left;
|
||||
s16 cell_gain_right;
|
||||
u16 gain_time_constant;
|
||||
} __packed;
|
||||
|
||||
#define NUM_GAIN_CELLS 1
|
||||
struct sst_cmd_set_gain_dual {
|
||||
struct sst_dsp_header header;
|
||||
u16 gain_cell_num;
|
||||
struct gain_cell cell_gains[NUM_GAIN_CELLS];
|
||||
} __packed;
|
||||
struct sst_cmd_set_params {
|
||||
struct sst_destination_id dst;
|
||||
u16 command_id;
|
||||
char params[0];
|
||||
} __packed;
|
||||
|
||||
/**** widget defines *****/
|
||||
|
||||
struct sst_ids {
|
||||
u16 location_id;
|
||||
u16 module_id;
|
||||
u8 task_id;
|
||||
u8 format;
|
||||
u8 reg;
|
||||
const char *parent_wname;
|
||||
struct snd_soc_dapm_widget *parent_w;
|
||||
struct list_head algo_list;
|
||||
struct list_head gain_list;
|
||||
const struct sst_pcm_format *pcm_fmt;
|
||||
};
|
||||
enum sst_gain_kcontrol_type {
|
||||
SST_GAIN_TLV,
|
||||
SST_GAIN_MUTE,
|
||||
SST_GAIN_RAMP_DURATION,
|
||||
};
|
||||
|
||||
struct sst_gain_mixer_control {
|
||||
bool stereo;
|
||||
enum sst_gain_kcontrol_type type;
|
||||
struct sst_gain_value *gain_val;
|
||||
int max;
|
||||
int min;
|
||||
u16 instance_id;
|
||||
u16 module_id;
|
||||
u16 pipe_id;
|
||||
u16 task_id;
|
||||
char pname[44];
|
||||
struct snd_soc_dapm_widget *w;
|
||||
};
|
||||
|
||||
struct sst_gain_value {
|
||||
u16 ramp_duration;
|
||||
s16 l_gain;
|
||||
s16 r_gain;
|
||||
bool mute;
|
||||
};
|
||||
#define SST_GAIN_VOLUME_DEFAULT (-1440)
|
||||
#define SST_GAIN_RAMP_DURATION_DEFAULT 5 /* timeconstant */
|
||||
#define SST_GAIN_MUTE_DEFAULT true
|
||||
|
||||
#define SST_GAIN_KCONTROL_TLV(xname, xhandler_get, xhandler_put, \
|
||||
xmod, xpipe, xinstance, xtask, tlv_array, xgain_val, \
|
||||
xmin, xmax, xpname) \
|
||||
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
|
||||
.access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
|
||||
SNDRV_CTL_ELEM_ACCESS_READWRITE, \
|
||||
.tlv.p = (tlv_array), \
|
||||
.info = sst_gain_ctl_info,\
|
||||
.get = xhandler_get, .put = xhandler_put, \
|
||||
.private_value = (unsigned long)&(struct sst_gain_mixer_control) \
|
||||
{ .stereo = true, .max = xmax, .min = xmin, .type = SST_GAIN_TLV, \
|
||||
.module_id = xmod, .pipe_id = xpipe, .task_id = xtask,\
|
||||
.instance_id = xinstance, .gain_val = xgain_val, .pname = xpname}
|
||||
|
||||
#define SST_GAIN_KCONTROL_INT(xname, xhandler_get, xhandler_put, \
|
||||
xmod, xpipe, xinstance, xtask, xtype, xgain_val, \
|
||||
xmin, xmax, xpname) \
|
||||
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
|
||||
.info = sst_gain_ctl_info, \
|
||||
.get = xhandler_get, .put = xhandler_put, \
|
||||
.private_value = (unsigned long)&(struct sst_gain_mixer_control) \
|
||||
{ .stereo = false, .max = xmax, .min = xmin, .type = xtype, \
|
||||
.module_id = xmod, .pipe_id = xpipe, .task_id = xtask,\
|
||||
.instance_id = xinstance, .gain_val = xgain_val, .pname = xpname}
|
||||
|
||||
#define SST_GAIN_KCONTROL_BOOL(xname, xhandler_get, xhandler_put,\
|
||||
xmod, xpipe, xinstance, xtask, xgain_val, xpname) \
|
||||
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
|
||||
.info = snd_soc_info_bool_ext, \
|
||||
.get = xhandler_get, .put = xhandler_put, \
|
||||
.private_value = (unsigned long)&(struct sst_gain_mixer_control) \
|
||||
{ .stereo = false, .type = SST_GAIN_MUTE, \
|
||||
.module_id = xmod, .pipe_id = xpipe, .task_id = xtask,\
|
||||
.instance_id = xinstance, .gain_val = xgain_val, .pname = xpname}
|
||||
#define SST_CONTROL_NAME(xpname, xmname, xinstance, xtype) \
|
||||
xpname " " xmname " " #xinstance " " xtype
|
||||
|
||||
#define SST_COMBO_CONTROL_NAME(xpname, xmname, xinstance, xtype, xsubmodule) \
|
||||
xpname " " xmname " " #xinstance " " xtype " " xsubmodule
|
||||
|
||||
/*
|
||||
* 3 Controls for each Gain module
|
||||
* e.g. - pcm0_in Gain 0 Volume
|
||||
* - pcm0_in Gain 0 Ramp Delay
|
||||
* - pcm0_in Gain 0 Switch
|
||||
*/
|
||||
#define SST_GAIN_KCONTROLS(xpname, xmname, xmin_gain, xmax_gain, xmin_tc, xmax_tc, \
|
||||
xhandler_get, xhandler_put, \
|
||||
xmod, xpipe, xinstance, xtask, tlv_array, xgain_val) \
|
||||
{ SST_GAIN_KCONTROL_INT(SST_CONTROL_NAME(xpname, xmname, xinstance, "Ramp Delay"), \
|
||||
xhandler_get, xhandler_put, xmod, xpipe, xinstance, xtask, SST_GAIN_RAMP_DURATION, \
|
||||
xgain_val, xmin_tc, xmax_tc, xpname) }, \
|
||||
{ SST_GAIN_KCONTROL_BOOL(SST_CONTROL_NAME(xpname, xmname, xinstance, "Switch"), \
|
||||
xhandler_get, xhandler_put, xmod, xpipe, xinstance, xtask, \
|
||||
xgain_val, xpname) } ,\
|
||||
{ SST_GAIN_KCONTROL_TLV(SST_CONTROL_NAME(xpname, xmname, xinstance, "Volume"), \
|
||||
xhandler_get, xhandler_put, xmod, xpipe, xinstance, xtask, tlv_array, \
|
||||
xgain_val, xmin_gain, xmax_gain, xpname) }
|
||||
|
||||
#define SST_GAIN_TC_MIN 5
|
||||
#define SST_GAIN_TC_MAX 5000
|
||||
#define SST_GAIN_MIN_VALUE -1440 /* in 0.1 DB units */
|
||||
#define SST_GAIN_MAX_VALUE 360
|
||||
|
||||
enum sst_algo_kcontrol_type {
|
||||
SST_ALGO_PARAMS,
|
||||
SST_ALGO_BYPASS,
|
||||
|
Loading…
Reference in New Issue
Block a user