From: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
To: Mark Brown <broonie@kernel.org>
Cc: lgirdwood@gmail.com, alsa-devel@alsa-project.org, perex@perex.cz,
tiwai@suse.com, linux-kernel@vger.kernel.org, vkoul@kernel.org
Subject: Re: [RFC PATCH 1/2] ASoC: soc-component: add snd_soc_component_read/write_field()
Date: Tue, 26 Jan 2021 14:03:29 +0000 [thread overview]
Message-ID: <6816a9fe-9b71-6a39-485e-1b6ce2b732ed@linaro.org> (raw)
In-Reply-To: <20210126133612.GB4839@sirena.org.uk>
On 26/01/2021 13:36, Mark Brown wrote:
> On Tue, Jan 26, 2021 at 12:20:19PM +0000, Srinivas Kandagatla wrote:
>
>> +#define __soc_component_field_shift(x) (__builtin_ffs(x) - 1)
>
> Why not have this be a static inline?
Sure, that makes it even better to validate the mask aswell!
>
>> +unsigned int snd_soc_component_read_field(struct snd_soc_component *component,
>> + unsigned int reg, unsigned int mask)
>> +{
>> + unsigned int val;
>> +
>> + mutex_lock(&component->io_mutex);
>> + val = soc_component_read_no_lock(component, reg);
>> + if (mask)
>> + val = (val & mask) >> __soc_component_field_shift(mask);
>
> I don't understand why this is open coding the locking when it's just a
> simple read and then shift?
I agree! something like this should be good I guess:
unsigned int snd_soc_component_read_field(...)
{
unsigned int val;
val = snd_soc_component_read(component, reg);
val = (val & mask) >> __soc_component_field_shift(mask);
return val;
}
>
>> + mutex_lock(&component->io_mutex);
>> +
>> + old = soc_component_read_no_lock(component, reg);
>> +
>> + val = val << __soc_component_field_shift(mask);
>> +
>> + new = (old & ~mask) | (val & mask);
>> +
>> + change = old != new;
>> + if (change)
>> + ret = soc_component_write_no_lock(component, reg, new);
>> +
>> + mutex_unlock(&component->io_mutex);
>
> This needs the lock as it's a read/modify/write but could also be
> implemented in terms of the existing update_bits() operation rather than
> open coding it.
True!, we could simplify this to :
int snd_soc_component_write_field(struct snd_soc_component *component,
unsigned int reg, unsigned int mask,
unsigned int val)
{
val = (val << __soc_component_field_shift(mask)) & mask;
return snd_soc_component_update_bits(component, reg, mask, val);
}
Does that look okay to you?
--srini
>
next prev parent reply other threads:[~2021-01-26 14:05 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-26 12:20 Srinivas Kandagatla
2021-01-26 12:20 ` [RFC PATCH 2/2] ASoC: codecs: lpass-wsa-macro: make use of snd_soc_component_read_field() Srinivas Kandagatla
2021-01-26 13:36 ` [RFC PATCH 1/2] ASoC: soc-component: add snd_soc_component_read/write_field() Mark Brown
2021-01-26 14:03 ` Srinivas Kandagatla [this message]
2021-01-26 16:33 ` 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=6816a9fe-9b71-6a39-485e-1b6ce2b732ed@linaro.org \
--to=srinivas.kandagatla@linaro.org \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=perex@perex.cz \
--cc=tiwai@suse.com \
--cc=vkoul@kernel.org \
/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®