On 1/23/2024 4:28 AM, Mark Brown wrote: On Mon, Jan 22, 2024 at 05:56:50PM +0800, Seven Lee wrote: +++ b/sound/soc/codecs/nau8325.c @@ -0,0 +1,896 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * nau8325.c -- Nuvoton NAU8325 audio codec driver + * Please use a C++ comment for the whole block to make things look more consistent. okay, I will follow C++ comment. +static int nau8325_clkdet_put(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct soc_mixer_control *mc = + (struct soc_mixer_control *)kcontrol->private_value; + struct snd_soc_component *component = + snd_soc_kcontrol_component(kcontrol); + struct nau8325 *nau8325 = snd_soc_component_get_drvdata(component); + unsigned int max = mc->max, min = mc->min, val; + unsigned int mask = (1 << fls(max)) - 1; AFAICT this will only work well if max is 1, just hard code that. You are right, I will modify to hard code for the max is 1. + + val = (ucontrol->value.integer.value[0] + min) & mask; + nau8325->clock_detection = val; + + if (nau8325->clock_detection) + regmap_update_bits(nau8325->regmap, NAU8325_R40_CLK_DET_CTRL, + NAU8325_CLKPWRUP_DIS, 0); + else + regmap_update_bits(nau8325->regmap, NAU8325_R40_CLK_DET_CTRL, + NAU8325_CLKPWRUP_DIS, NAU8325_CLKPWRUP_DIS); + + return nau8325->clock_detection; +} Please use mixer-test to verify that your controls conform to the expected API, the return value here is not what's expected - it should be a negative value for an error, 0 for no change and 1 for change. I think the return value is always 0 and 1, and I will modify the return value for zero. + SOC_SINGLE_EXT("Clock Detection", SND_SOC_NOPM, 0, 1, 0, + nau8325_clkdet_get, nau8325_clkdet_put), Shouldn't this be a Switch? Yes, you are right. I will change it. + SOC_SINGLE("ALC Enable", NAU8325_R2E_ALC_CTRL3, + NAU8325_ALC_EN_SFT, 1, 0), ALC Switch. okay, I will correct the name to "ALC Enable Switch". +static int nau8325_powerup_event(struct snd_soc_dapm_widget *w, + struct snd_kcontrol *kcontrol, int event) +{ + struct snd_soc_component *component = + snd_soc_dapm_to_component(w->dapm); + struct nau8325 *nau8325 = snd_soc_component_get_drvdata(component); + + if (nau8325->clock_detection) + return 0; + What happens if someone enables clock detection while things are powered up? This clock detection switch usually does not turn on/off during execution. If this is the case, there is a chance that unexpected exceptions may occur. So we'll remove the "Clock Detection" switch. The mode is determined during the initialization phase. ________________________________ The privileged confidential information contained in this email is intended for use only by the addressees as indicated by the original sender of this email. If you are not the addressee indicated in this email or are not responsible for delivery of the email to such a person, please kindly reply to the sender indicating this fact and delete all copies of it from your computer and network server immediately. Your cooperation is highly appreciated. It is advised that any unauthorized use of confidential information of Nuvoton is strictly prohibited; and any information in this email irrelevant to the official business of Nuvoton shall be deemed as neither given nor endorsed by Nuvoton.