From patchwork Wed Dec 14 18:54:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Amadeusz_S=C5=82awi=C5=84ski?= X-Patchwork-Id: 634219 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EFD8AC4332F for ; Wed, 14 Dec 2022 10:55:59 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 2380B18DB; Wed, 14 Dec 2022 11:55:08 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 2380B18DB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1671015358; bh=0wVKU8uuvOU19AOoBiJh83abrnwnKYpxFSdlGj+Hezo=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: Cc:From; b=eo4y2KrNuCKat+ej5UycztcaVGSKzOSnw5a2UaDHLik6ZKSjseqbSBFY4v6mr7E1C qU5qBRV8aYdqVG3OFUImFpLjdDY25z6TTNuCwL4Bc7ezIawRU6qNItPqJBsLM2J8A2 XH3tL6FPRq0VRbUTBc79pOGP+gl86KGV+3FmlYgQ= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 72BD9F80519; Wed, 14 Dec 2022 11:54:20 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 61EAEF804FF; Wed, 14 Dec 2022 11:54:18 +0100 (CET) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 24ADFF80310 for ; Wed, 14 Dec 2022 11:54:15 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 24ADFF80310 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=P2zUjNQu DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1671015257; x=1702551257; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0wVKU8uuvOU19AOoBiJh83abrnwnKYpxFSdlGj+Hezo=; b=P2zUjNQu2wULl3udyZ6vi+M50YilO8AxBCaNfK41EUPC823axJguvjLc Fcn7GRKERERdrs3E8TIZAOfzfGsW6ipIb5l6vIXM/wBHpM5NvuIykWpAI sgoZSag12Z72B9Ev1p+YsvDpzsgWkVbDtJwEpSzu7wCuP/s3gS1ZuyGBs +0sD5bcmdSlb/X/pAJbOkP2EiHmCQH4mxk5eHUI0tor+o/uuGJUlWilQb NP9fObYGdOxqJdWSIcuhtPFUotDIPOCdZWT8lPEzetX0uYNDmZ4ClaLFJ kZaA2etBEI9PsLZLFYwYv5/89jvOqY23yfWjSFjBhb0KtVbGlWB8Y1WU8 A==; X-IronPort-AV: E=McAfee;i="6500,9779,10560"; a="318412895" X-IronPort-AV: E=Sophos;i="5.96,244,1665471600"; d="scan'208";a="318412895" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2022 02:54:15 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10560"; a="679653318" X-IronPort-AV: E=Sophos;i="5.96,244,1665471600"; d="scan'208";a="679653318" Received: from dev2 (HELO DEV2.igk.intel.com) ([10.237.148.94]) by orsmga008.jf.intel.com with ESMTP; 14 Dec 2022 02:54:13 -0800 From: =?utf-8?q?Amadeusz_S=C5=82awi=C5=84ski?= To: Mark Brown Subject: [PATCH 2/4] ASoC: Intel: avs: Add control volume operations Date: Wed, 14 Dec 2022 19:54:58 +0100 Message-Id: <20221214185500.3896902-3-amadeuszx.slawinski@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221214185500.3896902-1-amadeuszx.slawinski@linux.intel.com> References: <20221214185500.3896902-1-amadeuszx.slawinski@linux.intel.com> MIME-Version: 1.0 X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cezary Rojewski , alsa-devel@alsa-project.org, Takashi Iwai , Pierre-Louis Bossart , =?utf-8?q?Amad?= =?utf-8?q?eusz_S=C5=82awi=C5=84ski?= Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" To make introduced peakvol module useful from userspace perspective, expose ALSA controls allowing DSP volume modification. These provide even more granular control over volume but are also the only way to modify volume for devices devoid of codec kcontrols e.g.: DMIC. Co-authored-by: Cezary Rojewski Signed-off-by: Amadeusz Sławiński --- sound/soc/intel/avs/Makefile | 2 +- sound/soc/intel/avs/control.c | 95 +++++++++++++++++++++++++++++++++++ sound/soc/intel/avs/control.h | 23 +++++++++ 3 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 sound/soc/intel/avs/control.c create mode 100644 sound/soc/intel/avs/control.h diff --git a/sound/soc/intel/avs/Makefile b/sound/soc/intel/avs/Makefile index 1c6924a1ebca..460ee6599daf 100644 --- a/sound/soc/intel/avs/Makefile +++ b/sound/soc/intel/avs/Makefile @@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only snd-soc-avs-objs := dsp.o ipc.o messages.o utils.o core.o loader.o \ - topology.o path.o pcm.o board_selection.o + topology.o path.o pcm.o board_selection.o control.o snd-soc-avs-objs += cldma.o snd-soc-avs-objs += skl.o apl.o diff --git a/sound/soc/intel/avs/control.c b/sound/soc/intel/avs/control.c new file mode 100644 index 000000000000..92b3aad0baca --- /dev/null +++ b/sound/soc/intel/avs/control.c @@ -0,0 +1,95 @@ +// SPDX-License-Identifier: GPL-2.0-only +// +// Copyright(c) 2021-2022 Intel Corporation. All rights reserved. +// +// Authors: Amadeusz Slawinski +// Cezary Rojewski +// + +#include +#include "avs.h" +#include "control.h" +#include "messages.h" +#include "path.h" + +static struct avs_dev *avs_get_kcontrol_adev(struct snd_kcontrol *kcontrol) +{ + struct snd_soc_dapm_widget *w; + + w = snd_soc_dapm_kcontrol_widget(kcontrol); + + return to_avs_dev(w->dapm->component->dev); +} + +static struct avs_path_module *avs_get_kcontrol_module(struct avs_dev *adev, u32 id) +{ + return NULL; +} + +int avs_control_volume_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) +{ + struct soc_mixer_control *mc = (struct soc_mixer_control *)kcontrol->private_value; + struct avs_control_data *ctl_data = (struct avs_control_data *)mc->dobj.private; + struct avs_dev *adev = avs_get_kcontrol_adev(kcontrol); + struct avs_volume_cfg *dspvols = NULL; + struct avs_path_module *active_module; + size_t num_dspvols; + int ret = 0; + + /* prevent access to modules while path is being constructed */ + mutex_lock(&adev->path_mutex); + + active_module = avs_get_kcontrol_module(adev, ctl_data->id); + if (active_module) { + ret = avs_ipc_peakvol_get_volume(adev, active_module->module_id, + active_module->instance_id, &dspvols, + &num_dspvols); + if (!ret) + ucontrol->value.integer.value[0] = dspvols[0].target_volume; + + ret = AVS_IPC_RET(ret); + kfree(dspvols); + } else { + ucontrol->value.integer.value[0] = ctl_data->volume; + } + + mutex_unlock(&adev->path_mutex); + return ret; +} + +int avs_control_volume_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) +{ + struct soc_mixer_control *mc = (struct soc_mixer_control *)kcontrol->private_value; + struct avs_control_data *ctl_data = (struct avs_control_data *)mc->dobj.private; + struct avs_dev *adev = avs_get_kcontrol_adev(kcontrol); + long *volume = &ctl_data->volume; + struct avs_path_module *active_module; + struct avs_volume_cfg dspvol = {0}; + long ctlvol = ucontrol->value.integer.value[0]; + int ret = 0, changed = 0; + + if (ctlvol < 0 || ctlvol > mc->max) + return -EINVAL; + + /* prevent access to modules while path is being constructed */ + mutex_lock(&adev->path_mutex); + + if (*volume != ctlvol) { + *volume = ctlvol; + changed = 1; + } + + active_module = avs_get_kcontrol_module(adev, ctl_data->id); + if (active_module) { + dspvol.channel_id = AVS_ALL_CHANNELS_MASK; + dspvol.target_volume = *volume; + + ret = avs_ipc_peakvol_set_volume(adev, active_module->module_id, + active_module->instance_id, &dspvol); + ret = AVS_IPC_RET(ret); + } + + mutex_unlock(&adev->path_mutex); + + return ret ? ret : changed; +} diff --git a/sound/soc/intel/avs/control.h b/sound/soc/intel/avs/control.h new file mode 100644 index 000000000000..08631bde13c3 --- /dev/null +++ b/sound/soc/intel/avs/control.h @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright(c) 2021-2022 Intel Corporation. All rights reserved. + * + * Authors: Amadeusz Slawinski + * Cezary Rojewski + */ + +#ifndef __SOUND_SOC_INTEL_AVS_CTRL_H +#define __SOUND_SOC_INTEL_AVS_CTRL_H + +#include + +struct avs_control_data { + u32 id; + + long volume; +}; + +int avs_control_volume_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol); +int avs_control_volume_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol); + +#endif From patchwork Wed Dec 14 18:55:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Amadeusz_S=C5=82awi=C5=84ski?= X-Patchwork-Id: 634218 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A6B9CC4332F for ; Wed, 14 Dec 2022 10:56:19 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id CE9341779; Wed, 14 Dec 2022 11:55:27 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz CE9341779 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1671015377; bh=6JEYjmlO8GpFQU6HVFpOchv0XxLl56GvpklqDYSp7zE=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: Cc:From; b=RY6Q9QlYm48VAwVU7aErdBcS7499kfNg9eriSr/AHcHZ16DXwqc4M5WFvU03QFlvu bMKINLfFj99uK3H/46DWiZ2Z06ERqjLglqEmKoau/bVfgj7BJxGAsLIeV1BzvdUr9K blogSriOl1XIMDRcKWxy0oDnKeyuFHkn0ZUpuU70= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 2E917F80544; Wed, 14 Dec 2022 11:54:26 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id A484EF80544; Wed, 14 Dec 2022 11:54:23 +0100 (CET) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id AEC87F80535 for ; Wed, 14 Dec 2022 11:54:21 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz AEC87F80535 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=fmwqoV74 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1671015262; x=1702551262; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6JEYjmlO8GpFQU6HVFpOchv0XxLl56GvpklqDYSp7zE=; b=fmwqoV74G0PZIW8JMPDcf3T2EA8Bw/EVAgN75Ra/IzQF7c3OKWiue2cy +o1uEs0TTnsVJ6hGKwekFwKH0MQtTPhmIcqOWx9t/YVdTjp+yYf1nyn70 MowjqZRJRMCJHy4jr5OMW8g+2Ye0fa1REdLX/5yrZJaxjYAJtRLNFuix1 Kw1m5uU+KmVW96yOFXXoFPcgxxIYruf3HiamVMUtE9lL7Sf8QRISJEHvz sqrgayAUtX8/bvwSPPbjLENb7CGAStfnWF+rf7TQEvbO2mUjs988g/Q7a wLLVVmXDfRWVsrKvAYGgqO+SempZ/+Y6Rf4vx/18A4FWQxIXjWkNqi2in g==; X-IronPort-AV: E=McAfee;i="6500,9779,10560"; a="318412930" X-IronPort-AV: E=Sophos;i="5.96,244,1665471600"; d="scan'208";a="318412930" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2022 02:54:19 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10560"; a="679653335" X-IronPort-AV: E=Sophos;i="5.96,244,1665471600"; d="scan'208";a="679653335" Received: from dev2 (HELO DEV2.igk.intel.com) ([10.237.148.94]) by orsmga008.jf.intel.com with ESMTP; 14 Dec 2022 02:54:17 -0800 From: =?utf-8?q?Amadeusz_S=C5=82awi=C5=84ski?= To: Mark Brown Subject: [PATCH 4/4] ASoC: Intel: avs: Peakvol module configuration Date: Wed, 14 Dec 2022 19:55:00 +0100 Message-Id: <20221214185500.3896902-5-amadeuszx.slawinski@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221214185500.3896902-1-amadeuszx.slawinski@linux.intel.com> References: <20221214185500.3896902-1-amadeuszx.slawinski@linux.intel.com> MIME-Version: 1.0 X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cezary Rojewski , alsa-devel@alsa-project.org, Takashi Iwai , Pierre-Louis Bossart , =?utf-8?q?Amad?= =?utf-8?q?eusz_S=C5=82awi=C5=84ski?= Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" Handle creation of peakvol module in FW. When peakvol module is created it retrieves actual value from kcontrol and sends it to FW as part of configuration data. Co-authored-by: Cezary Rojewski Signed-off-by: Amadeusz Sławiński --- sound/soc/intel/avs/path.c | 62 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/sound/soc/intel/avs/path.c b/sound/soc/intel/avs/path.c index ce157a8d6552..05302ab705ae 100644 --- a/sound/soc/intel/avs/path.c +++ b/sound/soc/intel/avs/path.c @@ -10,6 +10,7 @@ #include #include #include "avs.h" +#include "control.h" #include "path.h" #include "topology.h" @@ -264,6 +265,65 @@ static int avs_copier_create(struct avs_dev *adev, struct avs_path_module *mod) return ret; } +static struct avs_control_data *avs_get_module_control(struct avs_path_module *mod) +{ + struct avs_tplg_module *t = mod->template; + struct avs_tplg_path_template *path_tmpl; + struct snd_soc_dapm_widget *w; + int i; + + path_tmpl = t->owner->owner->owner; + w = path_tmpl->w; + + for (i = 0; i < w->num_kcontrols; i++) { + struct avs_control_data *ctl_data; + struct soc_mixer_control *mc; + + mc = (struct soc_mixer_control *)w->kcontrols[i]->private_value; + ctl_data = (struct avs_control_data *)mc->dobj.private; + if (ctl_data->id == t->ctl_id) + return ctl_data; + } + + return NULL; +} + +static int avs_peakvol_create(struct avs_dev *adev, struct avs_path_module *mod) +{ + struct avs_tplg_module *t = mod->template; + struct avs_control_data *ctl_data; + struct avs_peakvol_cfg *cfg; + int volume = S32_MAX; + size_t size; + int ret; + + ctl_data = avs_get_module_control(mod); + if (ctl_data) + volume = ctl_data->volume; + + /* As 2+ channels controls are unsupported, have a single block for all channels. */ + size = struct_size(cfg, vols, 1); + cfg = kzalloc(size, GFP_KERNEL); + if (!cfg) + return -ENOMEM; + + cfg->base.cpc = t->cfg_base->cpc; + cfg->base.ibs = t->cfg_base->ibs; + cfg->base.obs = t->cfg_base->obs; + cfg->base.is_pages = t->cfg_base->is_pages; + cfg->base.audio_fmt = *t->in_fmt; + cfg->vols[0].target_volume = volume; + cfg->vols[0].channel_id = AVS_ALL_CHANNELS_MASK; + cfg->vols[0].curve_type = AVS_AUDIO_CURVE_NONE; + cfg->vols[0].curve_duration = 0; + + ret = avs_dsp_init_module(adev, mod->module_id, mod->owner->instance_id, t->core_id, + t->domain, cfg, size, &mod->instance_id); + + kfree(cfg); + return ret; +} + static int avs_updown_mix_create(struct avs_dev *adev, struct avs_path_module *mod) { struct avs_tplg_module *t = mod->template; @@ -465,6 +525,8 @@ static struct avs_module_create avs_module_create[] = { { &AVS_MIXOUT_MOD_UUID, avs_modbase_create }, { &AVS_KPBUFF_MOD_UUID, avs_modbase_create }, { &AVS_COPIER_MOD_UUID, avs_copier_create }, + { &AVS_PEAKVOL_MOD_UUID, avs_peakvol_create }, + { &AVS_GAIN_MOD_UUID, avs_peakvol_create }, { &AVS_MICSEL_MOD_UUID, avs_micsel_create }, { &AVS_MUX_MOD_UUID, avs_mux_create }, { &AVS_UPDWMIX_MOD_UUID, avs_updown_mix_create },