From: Charles Keepax <ckeepax@opensource.cirrus.com>
To: <broonie@kernel.org>
Cc: <andy.shevchenko@gmail.com>, <lgirdwood@gmail.com>,
<alsa-devel@alsa-project.org>, <patches@opensource.cirrus.com>,
<linux-sound@vger.kernel.org>
Subject: [PATCH v2 6/7] ASoC: cs42l43: Refactor to use for_each_set_bit()
Date: Thu, 25 Jan 2024 10:31:16 +0000 [thread overview]
Message-ID: <20240125103117.2622095-6-ckeepax@opensource.cirrus.com> (raw)
In-Reply-To: <20240125103117.2622095-1-ckeepax@opensource.cirrus.com>
Refactor the code in cs42l43_mask_to_slots() to use for_each_set_bit().
Suggested-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
---
Changes since v1:
- Added () after funcs in commit message
- Use BITS_PER_TYPE
- Pass size into cs42l43_mask_to_slots()
Thanks,
Charles
sound/soc/codecs/cs42l43.c | 35 ++++++++++++++++++++---------------
1 file changed, 20 insertions(+), 15 deletions(-)
diff --git a/sound/soc/codecs/cs42l43.c b/sound/soc/codecs/cs42l43.c
index 1852cb072bd0e..23e9557494afa 100644
--- a/sound/soc/codecs/cs42l43.c
+++ b/sound/soc/codecs/cs42l43.c
@@ -6,10 +6,12 @@
// Cirrus Logic International Semiconductor Ltd.
#include <linux/bitops.h>
+#include <linux/bits.h>
#include <linux/clk.h>
#include <linux/device.h>
#include <linux/err.h>
#include <linux/errno.h>
+#include <linux/find.h>
#include <linux/gcd.h>
#include <linux/irq.h>
#include <linux/irqdomain.h>
@@ -547,23 +549,22 @@ static int cs42l43_asp_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
return 0;
}
-static void cs42l43_mask_to_slots(struct cs42l43_codec *priv, unsigned int mask, int *slots)
+static void cs42l43_mask_to_slots(struct cs42l43_codec *priv, unsigned long mask,
+ int *slots, unsigned int nslots)
{
- int i;
+ int i = 0;
+ int slot;
- for (i = 0; i < CS42L43_ASP_MAX_CHANNELS; ++i) {
- int slot = ffs(mask) - 1;
-
- if (slot < 0)
+ for_each_set_bit(slot, &mask, BITS_PER_TYPE(mask)) {
+ if (i == nslots) {
+ dev_warn(priv->dev, "Too many channels in TDM mask: %lx\n",
+ mask);
return;
+ }
- slots[i] = slot;
-
- mask &= ~(1 << slot);
+ slots[i++] = slot;
}
- if (mask)
- dev_warn(priv->dev, "Too many channels in TDM mask\n");
}
static int cs42l43_asp_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask,
@@ -580,8 +581,10 @@ static int cs42l43_asp_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mas
rx_mask = CS42L43_DEFAULT_SLOTS;
}
- cs42l43_mask_to_slots(priv, tx_mask, priv->tx_slots);
- cs42l43_mask_to_slots(priv, rx_mask, priv->rx_slots);
+ cs42l43_mask_to_slots(priv, tx_mask, priv->tx_slots,
+ ARRAY_SIZE(priv->tx_slots));
+ cs42l43_mask_to_slots(priv, rx_mask, priv->rx_slots,
+ ARRAY_SIZE(priv->rx_slots));
return 0;
}
@@ -2098,8 +2101,10 @@ static int cs42l43_component_probe(struct snd_soc_component *component)
snd_soc_component_init_regmap(component, cs42l43->regmap);
- cs42l43_mask_to_slots(priv, CS42L43_DEFAULT_SLOTS, priv->tx_slots);
- cs42l43_mask_to_slots(priv, CS42L43_DEFAULT_SLOTS, priv->rx_slots);
+ cs42l43_mask_to_slots(priv, CS42L43_DEFAULT_SLOTS, priv->tx_slots,
+ ARRAY_SIZE(priv->tx_slots));
+ cs42l43_mask_to_slots(priv, CS42L43_DEFAULT_SLOTS, priv->rx_slots,
+ ARRAY_SIZE(priv->rx_slots));
priv->component = component;
priv->constraint = cs42l43_constraint;
--
2.30.2
next prev parent reply other threads:[~2024-01-25 10:31 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-25 10:31 [PATCH v2 1/7] ASoC: cs42l43: Tidy up header includes Charles Keepax
2024-01-25 10:31 ` [PATCH v2 2/7] ASoC: cs42l43: Minor code tidy ups Charles Keepax
2024-01-25 10:31 ` [PATCH v2 3/7] ASoC: cs42l43: Check error from device_property_read_u32_array() Charles Keepax
2024-01-25 10:31 ` [PATCH v2 4/7] ASoC: cs42l43: Add pm_ptr around the power ops Charles Keepax
2024-01-25 19:00 ` Andy Shevchenko
2024-01-25 10:31 ` [PATCH v2 5/7] ASoC: cs42l43: Use USEC_PER_MSEC rather than hard coding Charles Keepax
2024-01-25 10:31 ` Charles Keepax [this message]
2024-01-25 19:11 ` [PATCH v2 6/7] ASoC: cs42l43: Refactor to use for_each_set_bit() Andy Shevchenko
2024-01-29 16:27 ` Charles Keepax
2024-01-29 23:45 ` Andy Shevchenko
2024-01-25 10:31 ` [PATCH v2 7/7] ASoC: cs42l43: Use fls to calculate the pre-divider for the PLL Charles Keepax
2024-01-25 19:13 ` [PATCH v2 1/7] ASoC: cs42l43: Tidy up header includes Andy Shevchenko
2024-01-26 21:38 ` 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=20240125103117.2622095-6-ckeepax@opensource.cirrus.com \
--to=ckeepax@opensource.cirrus.com \
--cc=alsa-devel@alsa-project.org \
--cc=andy.shevchenko@gmail.com \
--cc=broonie@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-sound@vger.kernel.org \
--cc=patches@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