From: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
To: Vinod Koul <vkoul@kernel.org>
Cc: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>,
alsa-devel@alsa-project.org,
Kai Vehmanen <kai.vehmanen@linux.intel.com>,
tiwai@suse.de, gregkh@linuxfoundation.org,
open list <linux-kernel@vger.kernel.org>,
broonie@kernel.org, Sanyog Kale <sanyog.r.kale@intel.com>,
Bard liao <yung-chuan.liao@linux.intel.com>,
Rander Wang <rander.wang@linux.intel.com>
Subject: Re: [PATCH v2 2/3] soundwire: SDCA: add helper macro to access controls
Date: Wed, 16 Sep 2020 08:11:34 -0500 [thread overview]
Message-ID: <d717f109-7ffd-11cb-f44d-f6c0b48d4985@linux.intel.com> (raw)
In-Reply-To: <20200916123545.GK2968@vkoul-mobl>
On 9/16/20 7:35 AM, Vinod Koul wrote:
> On 14-09-20, 09:44, Pierre-Louis Bossart wrote:
>>> For LSB bits, I dont think this is an issue. I expect it to work, for example:
>>> #define CONTROL_LSB_MASK GENMASK(2, 0)
>>> foo |= u32_encode_bits(control, CONTROL_LSB_MASK);
>>>
>>> would mask the control value and program that in specific bitfeild.
>>>
>>> But for MSB bits, I am not sure above will work so, you may need to extract
>>> the bits and then use, for example:
>>> #define CONTROL_MSB_BITS GENMASK(5, 3)
>>> #define CONTROL_MSB_MASK GENMASK(17, 15)
>>>
>>> control = FIELD_GET(CONTROL_MSB_BITS, control);
>>> foo |= u32_encode_bits(control, CONTROL_MSB_MASK);
>>>
>>>> If you have a better suggestion that the FIELD_PREP/FIELD_GET use, I am all
>>>> ears. At the end of the day, the mapping is pre-defined and we don't have
>>>> any degree of freedom. What I do want is that this macro/inline function is
>>>> shared by all codec drivers so that we don't have different interpretations
>>>> of how the address is constructed.
>>>
>>> Absolutely, this need to be defined here and used by everyone else.
>>
>> Compare:
>>
>> #define SDCA_CONTROL_MSB_BITS GENMASK(5, 3)
>> #define SDCA_CONTROL_MSB_MASK GENMASK(17, 15)
>> #define SDCA_CONTROL_LSB_MASK GENMASK(2, 0)
>>
>> foo |= u32_encode_bits(control, SDCA_CONTROL_LSB_MASK);
>> control = FIELD_GET(SDCA_CONTROL_MSB_BITS, control);
>> foo |= u32_encode_bits(control, SDCA_CONTROL_MSB_MASK);
>>
>> with the original proposal:
>>
>> foo |= FIELD_GET(GENMASK(2, 0), control))
>> foo |= FIELD_PREP(GENMASK(17, 15), FIELD_GET(GENMASK(5, 3), control))
>>
>> it gets worse when the LSB positions don't match, you need another variable
>> and an additional mask.
>>
>> I don't see how this improves readability? I get that hard-coding magic
>> numbers is a bad thing in general, but in this case there are limited
>> benefits to the use of additional defines.
>
> I think it would be prudent to define the masks and use them rather than
> magic values. Also it makes it future proof
I don't see your point at all. The values cannot be modified, a
different macro would be needed for a standard change.
Anyways, I am not going to argue further, I'll use your code example as
is and move on.
next prev parent reply other threads:[~2020-09-16 13:13 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-01 16:22 [PATCH v2 0/3] regmap: add SoundWire 1.2 MBQ support Pierre-Louis Bossart
2020-09-01 16:22 ` [PATCH v2 1/3] regmap: sdw: add required header files Pierre-Louis Bossart
2020-09-01 16:22 ` [PATCH v2 2/3] soundwire: SDCA: add helper macro to access controls Pierre-Louis Bossart
2020-09-04 5:02 ` Vinod Koul
2020-09-08 13:33 ` Pierre-Louis Bossart
2020-09-09 7:55 ` Vinod Koul
2020-09-09 13:48 ` Pierre-Louis Bossart
2020-09-10 6:22 ` Vinod Koul
2020-09-10 13:53 ` Pierre-Louis Bossart
2020-09-11 7:06 ` Vinod Koul
2020-09-11 14:50 ` Pierre-Louis Bossart
2020-09-14 5:08 ` Vinod Koul
2020-09-14 14:44 ` Pierre-Louis Bossart
2020-09-16 12:35 ` Vinod Koul
2020-09-16 13:11 ` Pierre-Louis Bossart [this message]
2020-09-01 16:22 ` [PATCH v2 3/3] regmap: sdw: add support for SoundWire 1.2 MBQ Pierre-Louis Bossart
2020-09-03 10:36 ` [PATCH v2 0/3] regmap: add SoundWire 1.2 MBQ support Vinod Koul
2020-09-03 13:51 ` Pierre-Louis Bossart
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=d717f109-7ffd-11cb-f44d-f6c0b48d4985@linux.intel.com \
--to=pierre-louis.bossart@linux.intel.com \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=guennadi.liakhovetski@linux.intel.com \
--cc=kai.vehmanen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rander.wang@linux.intel.com \
--cc=sanyog.r.kale@intel.com \
--cc=tiwai@suse.de \
--cc=vkoul@kernel.org \
--cc=yung-chuan.liao@linux.intel.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;
as well as URLs for NNTP newsgroup(s).