Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ASoC: SOF: topology: set default values to volume control #258

Merged
merged 1 commit into from
Nov 8, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions sound/soc/sof/topology.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@
/* 40th root of 10 in Q1.16 fixed-point notation*/
#define VOL_FORTIETH_ROOT_OF_TEN 69419
/* Volume fractional word length */
/* Define to 16 sets the volume linear gain value to use Qx.16 format */
#define VOLUME_FWL 16
/* 0.5 dB step value in topology TLV */
#define VOL_HALF_DB_STEP 50
/* Full volume for default values */
#define VOL_ZERO_DB BIT(VOLUME_FWL)

/* TLV data items */
#define TLV_ITEMS 3
Expand Down Expand Up @@ -1193,8 +1196,10 @@ static int sof_widget_load_pga(struct snd_soc_component *scomp, int index,
const struct snd_kcontrol_new *kc = NULL;
struct soc_mixer_control *sm;
struct snd_sof_control *scontrol;
struct sof_ipc_ctrl_data *cdata;
const unsigned int *p;
int ret, tlv[TLV_ITEMS];
unsigned int i;

volume = kzalloc(sizeof(*volume), GFP_KERNEL);
if (!volume)
Expand Down Expand Up @@ -1258,6 +1263,13 @@ static int sof_widget_load_pga(struct snd_soc_component *scomp, int index,
goto err;
}

/* set default volume values to 0dB in control */
cdata = scontrol->control_data;
for (i = 0; i < scontrol->num_channels; i++) {
cdata->chanv[i].channel = i;
cdata->chanv[i].value = VOL_ZERO_DB;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you happen to know how this will work or interfere with alsactrl trying to restore previous values?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should work, because this is topology loading, and I guess any alsactl command should not come in the middle (?). Not sure what happens if control is called in the middle of topology loading. PM is caching the stuff and in reload this part is never called. However, good point, I'll re-enable my alsactl and give it a try anyway.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@plbossart I tested with following scenario in my ubuntu:

  1. alsactl removed, so "first boot" set both pga channels to 0db
  2. I changed manually from alsamixer the pga volumes and re-enabled alsactl
  3. after boot the pga volumes are still in positions I set in 2

So I can't still guarantee fully all use cases, but this basic one is working.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

works for me as well, I took the code and all the settings were moved to 0dB on all PGAs. I changed one of the gains, rebooted and the values were kept, so it looks functional to me. Will merge, thanks Jaska!

sof_dbg_comp_config(scomp, &volume->config);

swidget->private = (void *)volume;
Expand Down