Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Amadeusz Sławiński" <amadeuszx.slawinski@linux.intel.com>
To: Vitaly Rodionov <vitalyr@opensource.cirrus.com>,
	Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
	Mark Brown <broonie@kernel.org>
Cc: patches@opensource.cirrus.com, alsa-devel@alsa-project.org,
	linux-kernel@vger.kernel.org,
	Stefan Binding <sbinding@opensource.cirrus.com>
Subject: Re: [PATCH v7 01/14] ALSA: hda: hda_cs_dsp_ctl: Add Library to support CS_DSP ALSA controls
Date: Wed, 22 Jun 2022 10:40:20 +0200	[thread overview]
Message-ID: <d05c292e-f955-48df-50e3-55e36a956775@linux.intel.com> (raw)
In-Reply-To: <20220622074653.179078-2-vitalyr@opensource.cirrus.com>

On 6/22/2022 9:46 AM, Vitaly Rodionov wrote:
> From: Stefan Binding <sbinding@opensource.cirrus.com>
> 
> The cs35l41 part contains a DSP which is able to run firmware.
> The cs_dsp library can be used to control the DSP.
> These controls can be exposed to userspace using ALSA controls.
> This library adds apis to be able to interface between
> cs_dsp and hda drivers and expose the relevant controls as
> ALSA controls.
> 
> Signed-off-by: Stefan Binding <sbinding@opensource.cirrus.com>
> Signed-off-by: Vitaly Rodionov <vitalyr@opensource.cirrus.com>
> ---
>   MAINTAINERS                    |   1 +
>   sound/pci/hda/Kconfig          |   4 +
>   sound/pci/hda/Makefile         |   2 +
>   sound/pci/hda/hda_cs_dsp_ctl.c | 207 +++++++++++++++++++++++++++++++++
>   sound/pci/hda/hda_cs_dsp_ctl.h |  33 ++++++
>   5 files changed, 247 insertions(+)
>   create mode 100644 sound/pci/hda/hda_cs_dsp_ctl.c
>   create mode 100644 sound/pci/hda/hda_cs_dsp_ctl.h
> 

...

> +
> +static unsigned int wmfw_convert_flags(unsigned int in)
> +{
> +	unsigned int out, rd, wr, vol;
> +
> +	rd = SNDRV_CTL_ELEM_ACCESS_READ;
> +	wr = SNDRV_CTL_ELEM_ACCESS_WRITE;
> +	vol = SNDRV_CTL_ELEM_ACCESS_VOLATILE;
> +
> +	out = 0;
> +
> +	if (in) {
> +		out |= rd;
> +		if (in & WMFW_CTL_FLAG_WRITEABLE)
> +			out |= wr;
> +		if (in & WMFW_CTL_FLAG_VOLATILE)
> +			out |= vol;
> +	} else {
> +		out |= rd | wr | vol;
> +	}
> +
> +	return out;
> +}

This is more question of preference, so you can leave above function as 
is, but you could also do something like the following, which is bit 
shorter:
static unsigned int wmfw_convert_flags(unsigned int in)
{
	unsigned int out = SNDRV_CTL_ELEM_ACCESS_READ;

	if (!in)
		return SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_VOLATILE;

	if (in & WMFW_CTL_FLAG_WRITEABLE)
		out |= SNDRV_CTL_ELEM_ACCESS_WRITE;
	if (in & WMFW_CTL_FLAG_VOLATILE)
		out |= SNDRV_CTL_ELEM_ACCESS_VOLATILE;

	return out;
}

> +
> +static int hda_cs_dsp_add_kcontrol(struct hda_cs_dsp_coeff_ctl *ctl)
> +{
> +	struct cs_dsp_coeff_ctl *cs_ctl = ctl->cs_ctl;
> +	struct snd_kcontrol_new *kcontrol;
> +	struct snd_kcontrol *kctl;
> +	int ret = 0;
> +
> +	if (cs_ctl->len > ADSP_MAX_STD_CTRL_SIZE) {
> +		dev_err(cs_ctl->dsp->dev, "Control %s: length %zu exceeds maximum %d\n", ctl->name,
> +			cs_ctl->len, ADSP_MAX_STD_CTRL_SIZE);
> +		return -EINVAL;
> +	}
> +
> +	kcontrol = kzalloc(sizeof(*kcontrol), GFP_KERNEL);
> +	if (!kcontrol)
> +		return -ENOMEM;
> +
> +	kcontrol->name = ctl->name;
> +	kcontrol->info = hda_cs_dsp_coeff_info;
> +	kcontrol->iface = SNDRV_CTL_ELEM_IFACE_MIXER;
> +	kcontrol->private_value = (unsigned long)ctl;
> +	kcontrol->access = wmfw_convert_flags(cs_ctl->flags);
> +
> +	kcontrol->get = hda_cs_dsp_coeff_get;
> +	kcontrol->put = hda_cs_dsp_coeff_put;
> +
> +	kctl = snd_ctl_new1(kcontrol, NULL);

Wouldn't
kctl = snd_ctl_new1(kcontrol, ctl);
work instead of
kcontrol->private_value = (unsigned long)ctl;
...
kctl = snd_ctl_new1(kcontrol, NULL);
?

You can then get the value using  snd_kcontrol_chip()  macro, so instead 
of doing quite long lines with casts like:
struct hda_cs_dsp_coeff_ctl *ctl = (struct hda_cs_dsp_coeff_ctl 
*)kctl->private_value;
you could do
struct hda_cs_dsp_coeff_ctl *ctl = snd_kcontrol_chip(kctl);



  reply	other threads:[~2022-06-22  8:41 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-22  7:46 [PATCH v7 00/14] ALSA: hda: cirrus: Add initial DSP support and firmware loading Vitaly Rodionov
2022-06-22  7:46 ` [PATCH v7 01/14] ALSA: hda: hda_cs_dsp_ctl: Add Library to support CS_DSP ALSA controls Vitaly Rodionov
2022-06-22  8:40   ` Amadeusz Sławiński [this message]
2022-06-22 13:10     ` Takashi Iwai
2022-06-22 13:34   ` Takashi Iwai
2022-06-22  7:46 ` [PATCH v7 02/14] ALSA: hda: hda_cs_dsp_ctl: Add apis to write the controls directly Vitaly Rodionov
2022-06-22  7:46 ` [PATCH v7 03/14] ALSA: hda: cs35l41: Save codec object inside component struct Vitaly Rodionov
2022-06-22  7:46 ` [PATCH v7 04/14] ALSA: hda: cs35l41: Add initial DSP support and firmware loading Vitaly Rodionov
2022-06-22  7:46 ` [PATCH v7 05/14] ALSA: hda: cs35l41: Save Subsystem ID inside CS35L41 Driver Vitaly Rodionov
2022-06-22  8:40   ` Amadeusz Sławiński
2022-06-22  7:46 ` [PATCH v7 06/14] ALSA: hda: cs35l41: Support reading subsystem id from ACPI Vitaly Rodionov
2022-06-22  7:46 ` [PATCH v7 07/14] ALSA: hda: cs35l41: Support multiple load paths for firmware Vitaly Rodionov
2022-06-22  8:40   ` Amadeusz Sławiński
2022-06-22  7:46 ` [PATCH v7 08/14] ALSA: hda: cs35l41: Support Speaker ID for laptops Vitaly Rodionov
2022-06-22  7:46 ` [PATCH v7 09/14] ALSA: hda: cs35l41: Support Hibernation during Suspend Vitaly Rodionov
2022-06-22  7:46 ` [PATCH v7 10/14] ALSA: hda: cs35l41: Read Speaker Calibration data from UEFI variables Vitaly Rodionov
2022-06-22  7:46 ` [PATCH v7 11/14] ALSA: hda: hda_cs_dsp_ctl: Add fw id strings Vitaly Rodionov
2022-06-22  7:46 ` [PATCH v7 12/14] ALSA: hda: cs35l41: Add defaulted values into dsp bypass config sequence Vitaly Rodionov
2022-06-22  7:46 ` [PATCH v7 13/14] ALSA: hda: cs35l41: Support Firmware switching and reloading Vitaly Rodionov
2022-06-22  7:46 ` [PATCH v7 14/14] ALSA: hda: cs35l41: Add module parameter to control firmware load Vitaly Rodionov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d05c292e-f955-48df-50e3-55e36a956775@linux.intel.com \
    --to=amadeuszx.slawinski@linux.intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=patches@opensource.cirrus.com \
    --cc=perex@perex.cz \
    --cc=sbinding@opensource.cirrus.com \
    --cc=tiwai@suse.com \
    --cc=vitalyr@opensource.cirrus.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox