Skip to content

Commit 3bc3e3d

Browse files
Lucas Tanurebroonie
authored andcommitted
ASoC: cs35l41: Create shared function for setting channels
ASoC and HDA will use the same register to set channels for the device Signed-off-by: Lucas Tanure <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 8b22786 commit 3bc3e3d

File tree

3 files changed

+38
-27
lines changed

3 files changed

+38
-27
lines changed

include/sound/cs35l41.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,5 +764,8 @@ extern struct regmap_config cs35l41_regmap_spi;
764764

765765
int cs35l41_otp_unpack(struct device *dev, struct regmap *regmap);
766766
int cs35l41_register_errata_patch(struct device *dev, struct regmap *reg, unsigned int reg_revid);
767+
int cs35l41_set_channels(struct device *dev, struct regmap *reg,
768+
unsigned int tx_num, unsigned int *tx_slot,
769+
unsigned int rx_num, unsigned int *rx_slot);
767770

768771
#endif /* __CS35L41_H */

sound/soc/codecs/cs35l41-lib.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,38 @@ int cs35l41_register_errata_patch(struct device *dev, struct regmap *reg, unsign
934934
}
935935
EXPORT_SYMBOL_GPL(cs35l41_register_errata_patch);
936936

937+
int cs35l41_set_channels(struct device *dev, struct regmap *reg,
938+
unsigned int tx_num, unsigned int *tx_slot,
939+
unsigned int rx_num, unsigned int *rx_slot)
940+
{
941+
unsigned int val, mask;
942+
int i;
943+
944+
if (tx_num > 4 || rx_num > 2)
945+
return -EINVAL;
946+
947+
val = 0;
948+
mask = 0;
949+
for (i = 0; i < rx_num; i++) {
950+
dev_dbg(dev, "rx slot %d position = %d\n", i, rx_slot[i]);
951+
val |= rx_slot[i] << (i * 8);
952+
mask |= 0x3F << (i * 8);
953+
}
954+
regmap_update_bits(reg, CS35L41_SP_FRAME_RX_SLOT, mask, val);
955+
956+
val = 0;
957+
mask = 0;
958+
for (i = 0; i < tx_num; i++) {
959+
dev_dbg(dev, "tx slot %d position = %d\n", i, tx_slot[i]);
960+
val |= tx_slot[i] << (i * 8);
961+
mask |= 0x3F << (i * 8);
962+
}
963+
regmap_update_bits(reg, CS35L41_SP_FRAME_TX_SLOT, mask, val);
964+
965+
return 0;
966+
}
967+
EXPORT_SYMBOL_GPL(cs35l41_set_channels);
968+
937969
MODULE_DESCRIPTION("CS35L41 library");
938970
MODULE_AUTHOR("David Rhodes, Cirrus Logic Inc, <[email protected]>");
939971
MODULE_AUTHOR("Lucas Tanure, Cirrus Logic Inc, <[email protected]>");

sound/soc/codecs/cs35l41.c

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -751,36 +751,12 @@ static const struct cs_dsp_region cs35l41_dsp1_regions[] = {
751751
{. type = WMFW_ADSP2_YM, .base = CS35L41_DSP1_YMEM_UNPACK24_0},
752752
};
753753

754-
static int cs35l41_set_channel_map(struct snd_soc_dai *dai, unsigned int tx_num,
755-
unsigned int *tx_slot, unsigned int rx_num,
756-
unsigned int *rx_slot)
754+
static int cs35l41_set_channel_map(struct snd_soc_dai *dai, unsigned int tx_n,
755+
unsigned int *tx_slot, unsigned int rx_n, unsigned int *rx_slot)
757756
{
758757
struct cs35l41_private *cs35l41 = snd_soc_component_get_drvdata(dai->component);
759-
unsigned int val, mask;
760-
int i;
761-
762-
if (tx_num > 4 || rx_num > 2)
763-
return -EINVAL;
764758

765-
val = 0;
766-
mask = 0;
767-
for (i = 0; i < rx_num; i++) {
768-
dev_dbg(cs35l41->dev, "rx slot %d position = %d\n", i, rx_slot[i]);
769-
val |= rx_slot[i] << (i * 8);
770-
mask |= 0x3F << (i * 8);
771-
}
772-
regmap_update_bits(cs35l41->regmap, CS35L41_SP_FRAME_RX_SLOT, mask, val);
773-
774-
val = 0;
775-
mask = 0;
776-
for (i = 0; i < tx_num; i++) {
777-
dev_dbg(cs35l41->dev, "tx slot %d position = %d\n", i, tx_slot[i]);
778-
val |= tx_slot[i] << (i * 8);
779-
mask |= 0x3F << (i * 8);
780-
}
781-
regmap_update_bits(cs35l41->regmap, CS35L41_SP_FRAME_TX_SLOT, mask, val);
782-
783-
return 0;
759+
return cs35l41_set_channels(cs35l41->dev, cs35l41->regmap, tx_n, tx_slot, rx_n, rx_slot);
784760
}
785761

786762
static int cs35l41_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)

0 commit comments

Comments
 (0)