From: Mark Brown <broonie@kernel.org>
To: cy_huang@richtek.com
Cc: Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>, Rob Herring <robh@kernel.org>,
Liam Girdwood <lgirdwood@gmail.com>,
Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
Otto lin <otto_lin@richtek.com>,
Allen Lin <allen_lin@richtek.com>,
devicetree@vger.kernel.org, linux-sound@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/4] ASoC: codecs: Add support for Richtek rt9123
Date: Fri, 4 Apr 2025 16:03:57 +0100 [thread overview]
Message-ID: <4e966f68-527e-4e2c-9043-0795ff094031@sirena.org.uk> (raw)
In-Reply-To: <cff65757c4665a81397ef5f559b277f96d4236c3.1743774849.git.cy_huang@richtek.com>
[-- Attachment #1: Type: text/plain, Size: 3307 bytes --]
On Fri, Apr 04, 2025 at 10:22:12PM +0800, cy_huang@richtek.com wrote:
> +static int rt9123_enable_event(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol,
> + int event)
> +{
> + ret = pm_runtime_resume_and_get(dev);
> + if (ret)
> + return ret;
> +
> + snd_soc_component_write_field(comp, RT9123_REG_AMPCTRL, RT9123_MASK_AMPON, enable);
> +
> + pm_runtime_mark_last_busy(dev);
> + pm_runtime_put_autosuspend(dev);
What's going on with the runtime PM stuff here? Especially for the DAPM
widget usually the ASoC core will be able to keep devices runtime PM
enabled so long as they are in use so I'd expect this not to have any
impact. Why not just use a normal DAPM widget?
> +static int rt9123_xhandler_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
> +{
> + struct snd_soc_component *comp = snd_soc_kcontrol_component(kcontrol);
> + struct device *dev = comp->dev;
> + int ret;
> +
> + ret = pm_runtime_resume_and_get(dev);
> + if (ret)
> + return ret;
> +
> + if (rt9123_kcontrol_name_comp(kcontrol, "SPK Gain Volume") == 0)
> + ret = snd_soc_get_volsw(kcontrol, ucontrol);
> + else
> + ret = snd_soc_get_enum_double(kcontrol, ucontrol);
This is even more unusual - it'll runtime PM enable the device every
time we write to a control, even if the device is idle. The driver does
implement a register cache so it's especially confusing, we'll power up
the device, resync the cache, write to the hardware then power the
device off again. Usually you'd just use the standard operations and
then let the register writes get synced to the cache whenever it gets
enabled for actual use. Again, why not just use standard controls?
> +static const struct snd_kcontrol_new rt9123_controls[] = {
> + SOC_SINGLE_TLV("Master Volume", RT9123_REG_VOLGAIN, 2, 511, 1, dig_tlv),
> + SOC_SINGLE_EXT_TLV("SPK Gain Volume", RT9123_REG_AMPCTRL, 0, 10, 0, rt9123_xhandler_get,
> + rt9123_xhandler_put, ana_tlv),
Speaker Volume.
> +static const struct regmap_config rt9123_regmap_config = {
> + .name = "rt9123",
> + .reg_bits = 8,
> + .val_bits = 16,
> + .val_format_endian = REGMAP_ENDIAN_BIG,
> + .readable_reg = rt9123_readable_reg,
> + .writeable_reg = rt9123_writeable_reg,
> + .volatile_reg = rt9123_volatile_reg,
> + .cache_type = REGCACHE_RBTREE,
> + .num_reg_defaults_raw = RT9123_REG_COMBOID + 1,
> +};
Generally _MAPLE is a better cache type for most devices - unless you
have a strong reason to use _RBTREE it's preferred.
> + /* Trigger RG reset before regmap init cache */
> + ret = i2c_smbus_write_word_data(i2c, RT9123_REG_AMPCTRL, RT9123_MASK_SWRST);
> + if (ret)
> + return dev_err_probe(dev, ret, "Failed to trigger RG reset\n");
> +
> + regmap = devm_regmap_init_i2c(i2c, &rt9123_regmap_config);
> + if (IS_ERR(regmap))
> + return dev_err_probe(dev, PTR_ERR(regmap), "Failed to init regmap\n");
> +
> + ret = regmap_read(regmap, RT9123_REG_COMBOID, &venid);
> + if (ret)
> + return dev_err_probe(dev, ret, "Failed to read vendor-id\n");
> +
> + if ((venid & RT9123_MASK_VENID) != RT9123_FIXED_VENID)
> + return dev_err_probe(dev, -ENODEV, "Incorrect vendor-id 0x%04x\n", venid);
It seems nicer to verify the device ID before doing the reset in case
anything went wrong. Who knows what some other device did with the
reset?
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2025-04-04 15:04 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-04 14:22 [PATCH 0/4] ASoC: Add Richtek rt9123 and rt9123p support cy_huang
2025-04-04 14:22 ` [PATCH 1/4] ASoC: dt-bindings: Add bindings for Richtek rt9123 cy_huang
2025-04-04 14:22 ` [PATCH 2/4] ASoC: codecs: Add support " cy_huang
2025-04-04 15:03 ` Mark Brown [this message]
2025-04-07 0:44 ` ChiYuan Huang
2025-04-07 12:34 ` Mark Brown
2025-04-08 3:53 ` ChiYuan Huang
2025-04-05 14:21 ` kernel test robot
2025-04-05 15:13 ` kernel test robot
2025-04-04 14:22 ` [PATCH 3/4] ASoC: dt-bindings: Add bindings for Richtek rt9123p cy_huang
2025-04-04 20:07 ` Rob Herring
2025-04-04 14:22 ` [PATCH 4/4] ASoC: codecs: Add support " cy_huang
2025-04-04 20:05 ` Rob Herring
2025-04-07 0:53 ` ChiYuan Huang
2025-04-09 1:06 ` ChiYuan Huang
2025-04-09 12:29 ` Mark Brown
2025-04-14 13:56 ` (subset) [PATCH 0/4] ASoC: Add Richtek rt9123 and rt9123p support Mark Brown
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=4e966f68-527e-4e2c-9043-0795ff094031@sirena.org.uk \
--to=broonie@kernel.org \
--cc=allen_lin@richtek.com \
--cc=conor+dt@kernel.org \
--cc=cy_huang@richtek.com \
--cc=devicetree@vger.kernel.org \
--cc=krzk+dt@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=otto_lin@richtek.com \
--cc=perex@perex.cz \
--cc=robh@kernel.org \
--cc=tiwai@suse.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
all inboxes | Powered by JetHome®