Skip to content

Commit

Permalink
Added I2S support for Ralink/Mediatek
Browse files Browse the repository at this point in the history
Only 16-bit width LRCLK is supported.

Used SoC audio framework https://reviews.freebsd.org/D27830
DMA is not supported SoC audio framework. I have to patch it.
It is not very good patch but it work for me.

--- sys/dev/sound/fdt/audio_dai_if.m.org	2021-04-28 19:22:24.682040000 +0000
+++ sys/dev/sound/fdt/audio_dai_if.m	2021-05-17 20:38:38.701918000 +0000
@@ -93,3 +93,15 @@
 	struct snd_dbuf	*play_buf;
 	struct snd_dbuf	*rec_buf;
 }
+
+METHOD void * chan_init {
+	device_t	dev;
+	struct snd_dbuf	*buf;
+	struct pcm_channel *channel;
+	int 		pcm_dir;
+}
+
+METHOD int chan_free {
+	device_t	dev;
+	int		pcm_dir;
+}

--- sys/dev/sound/fdt/audio_soc.c.org	2021-04-28 19:23:30.177185000 +0000
+++ sys/dev/sound/fdt/audio_soc.c	2021-05-17 20:12:32.722736000 +0000
@@ -44,7 +44,8 @@
 #include <dev/sound/pcm/sound.h>
 #include "audio_dai_if.h"

-#define	AUDIO_BUFFER_SIZE	48000 * 4
+// #define	AUDIO_BUFFER_SIZE	48000 * 4
+#define	AUDIO_BUFFER_SIZE	131072

 struct audio_soc_aux_node {
 	SLIST_ENTRY(audio_soc_aux_node)	link;
@@ -213,17 +214,22 @@

 	ausoc_chan = devinfo;
 	sc = ausoc_chan->sc;
-	buffer = malloc(AUDIO_BUFFER_SIZE, M_DEVBUF, M_WAITOK | M_ZERO);
-
-	if (sndbuf_setup(b, buffer, AUDIO_BUFFER_SIZE) != 0) {
-		free(buffer, M_DEVBUF);
-		return NULL;
-	}
+	// buffer = malloc(AUDIO_BUFFER_SIZE, M_DEVBUF, M_WAITOK | M_ZERO);
+	// if (sndbuf_setup(b, buffer, AUDIO_BUFFER_SIZE) != 0) {
+	// 	free(buffer, M_DEVBUF);
+	// 	return NULL;
+	// }

 	ausoc_chan->dir = dir;
 	ausoc_chan->buf = b;
 	ausoc_chan->pcm = c;

+	buffer = AUDIO_DAI_CHAN_INIT(sc->cpu_dev, b, c, dir);
+	if(buffer == NULL) {
+		AUDIO_DAI_CHAN_FREE(sc->cpu_dev, dir);
+		return NULL;
+	}
+
 	return (devinfo);
 }

@@ -250,15 +256,16 @@

 	struct audio_soc_softc *sc;
 	struct audio_soc_channel *ausoc_chan;
-	void *buffer;
+	// void *buffer;

 	ausoc_chan = (struct audio_soc_channel *)data;
 	sc = ausoc_chan->sc;

-	buffer = sndbuf_getbuf(ausoc_chan->buf);
-	if (buffer)
-		free(buffer, M_DEVBUF);
+	// buffer = sndbuf_getbuf(ausoc_chan->buf);
+	// if (buffer)
+	// 	free(buffer, M_DEVBUF);

+	AUDIO_DAI_CHAN_FREE(sc->cpu_dev, ausoc_chan->dir);
 	return (0);
 }

Tested with BOJINGnet board with wm8960_codec and
RT5350F-OLinuXino with dummy_codec.
  • Loading branch information
priittrees committed May 18, 2021
1 parent b6be956 commit 17f9656
Show file tree
Hide file tree
Showing 3 changed files with 748 additions and 0 deletions.
6 changes: 6 additions & 0 deletions sys/mips/mediatek/files.mediatek
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ mips/mediatek/mtk_gpio_v1.c optional gpio mtk_gpio_v1
mips/mediatek/mtk_gpio_v2.c optional gpio mtk_gpio_v2
#mips/mediatek/mtk_mmc.c optional mmc

# Ralink/Mediatek sound
dev/sound/fdt/audio_dai_if.m optional sound fdt
dev/sound/fdt/audio_soc.c optional sound fdt
dev/sound/fdt/dummy_codec.c optional sound fdt
mips/mediatek/mtk_i2s.c optional sound

# Ralink/Mediatek Ethernet driver
dev/rt/if_rt.c optional rt

Expand Down

0 comments on commit 17f9656

Please sign in to comment.