diff mbox series

[RFC,5/7] ASoC: sunxi: sun4i-i2s: Detect TDM slots based on channel slots

Message ID 20230811201406.4096210-6-contact@jookia.org (mailing list archive)
State New, archived
Headers show
Series sun4i-i2s: Support channel remapping | expand

Commit Message

John Watts Aug. 11, 2023, 8:14 p.m. UTC
The current controller code assumes a 1:1 relationship between audio
channel and TDM slot. This may not be the case when slots are set
explicitly. Instead figure out how many slots we need based on the
number of slots used in the channel map.

This allows the case of reading multiple data pins on a single slot.

Signed-off-by: John Watts <contact@jookia.org>
---
 sound/soc/sunxi/sun4i-i2s.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
diff mbox series

Patch

diff --git a/sound/soc/sunxi/sun4i-i2s.c b/sound/soc/sunxi/sun4i-i2s.c
index 019a4856c90b..6347aaaed016 100644
--- a/sound/soc/sunxi/sun4i-i2s.c
+++ b/sound/soc/sunxi/sun4i-i2s.c
@@ -271,6 +271,7 @@  static int sun4i_i2s_read_channel_slots(struct device *dev, struct sun4i_i2s *i2
 {
 	struct device_node *np = dev->of_node;
 	int max_channels = ARRAY_SIZE(i2s->channel_dins);
+	int slot_max;
 	int ret;
 
 	/* Use a 1:1 mapping by default */
@@ -290,6 +291,16 @@  static int sun4i_i2s_read_channel_slots(struct device *dev, struct sun4i_i2s *i2
 	if (ret < 0)
 		return ret;
 
+	for (int i = 0; i < ret; ++i) {
+		int slot = i2s->channel_slots[i];
+
+		if (slot_max < slot)
+			slot_max = slot;
+	}
+
+	/* Add 1 to be inclusive of slot 0 */
+	i2s->slots = slot_max + 1;
+
 	return 0;
 }