Skip to content

Commit

Permalink
UPSTREAM: ASoC: cs42l43: Refactor to use for_each_set_bit()
Browse files Browse the repository at this point in the history
Refactor the code in cs42l43_mask_to_slots() to use for_each_set_bit().

Suggested-by: Andy Shevchenko <[email protected]>
Signed-off-by: Charles Keepax <[email protected]>
Link: https://msgid.link/r/[email protected]
Signed-off-by: Mark Brown <[email protected]>
(cherry picked from commit fe04d1632cb4130fb47d18fe70ac292562a3b9c3)

BUG=b:326869955
TEST=Test Audio use cases.

Change-Id: I00a6fbf11fd6b9912d037fbb69bd75d6d6b23e99
Signed-off-by: Debi sahoo <[email protected]>
  • Loading branch information
charleskeepax authored and terry182 committed Aug 20, 2024
1 parent a1d4529 commit b4a1222
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions sound/soc/codecs/cs42l43.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -548,23 +550,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,
Expand All @@ -581,8 +582,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;
}
Expand Down Expand Up @@ -2099,8 +2102,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;
Expand Down

0 comments on commit b4a1222

Please sign in to comment.