BPI R64 MT7622 I2S iis support

Hello, I see that MT7622 supports I2S, but there is currently no related application or code. I need to use I2S for audio development. I have read the manual pdf and only this information is available. If I want to do this application, if I2S direct drive DAC chip, where will I get a quicker development method instead of making wheels. Hope to get some support!

Looks like pins 38/40 have i2s function

https://www.fw-web.de/dokuwiki/doku.php?id=en:bpi-r64:gpio

There are some pinctl defined you need to set

But afair there is no definition in dts. So you need to add it and map to driver

Seems like the pinctrl is already defined,but no i2s node itself

So you need something like this (you need to create new node instead of changing existing,because in mt7622 there is no i2s-node…i guess you need to add clocks/reg,interrupts too

i2s1 {
    pinctrl-names = "default";
    pinctrl-0 = <&i2s1_pins>;
    status = "okay";
    codec {
        compatible="your drivers compatible";
        //some other options
    };
};

What you are talking about is IO configuration and clock configuration. In fact, what I want to know is the I2S driver of MTK. The location is in sound/soc/mediatek/ and no mt7622 is found, which means there is no related register configuration.

-rw-r--r-- 1 root root 4588 Sep 19 11:45 Kconfig
-rw-r--r-- 1 root root  237 Sep 19 11:45 Makefile
drwxr-xr-x 2 root root 4096 Sep 19 11:45 common
drwxr-xr-x 2 root root 4096 Sep 19 11:45 mt2701
drwxr-xr-x 2 root root 4096 Sep 19 11:45 mt6797
drwxr-xr-x 2 root root 4096 Sep 19 11:45 mt8173
drwxr-xr-x 2 root root 4096 Sep 19 11:45 mt8183

You could try 8173 as mt7622.dtsi uses nor-driver as fallback from this chip

please use mt2701 and can buy raspberry wm8960 dtb for the test.

https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c

 static const struct of_device_id mt2701_afe_pcm_dt_match[] = {
{ .compatible = "mediatek,mt2701-audio", .data = &mt2701_soc_v1 },
{ .compatible = "mediatek,mt7622-audio", .data = &mt2701_soc_v2 },
{},

https://www.waveshare.com/wm8960-audio-hat.htm

can you give full dts example for this? how to connect the audio hat to r64 (using pins 38/40)?

This is my configuration, but without wm8960, there is no way to test it. I tried to use an audio decoder DAC that does not require I2C so that the waveform can be observed through an oscilloscope. But I want to fully utilize the 4 inputs and 4 outputs of I2S, so the IO configuration will affect SD, right?

sound: sound {
	compatible = "mediatek,mt2701-wm8960-machine";
	mediatek,platform = <&afe>;
	audio-routing =
		"Headphone", "HP_L",
		"Headphone", "HP_R",
		"LINPUT1", "AMIC",
		"RINPUT1", "AMIC";
	mediatek,audio-codec = <&wm8960>;
	pinctrl-names = "default";
	pinctrl-0 = <&i2s1_pins>;
};

&i2c1 {
	pinctrl-names = "default";
	pinctrl-0 = <&i2c1_pins>;
	status = "okay";
	wm8960: [email protected] {
		compatible = "wlf,wm8960";
		reg = <0x1a>;
	};
};
--- a/mt7622-bananapi-bpi-r64.dts
+++ b/mt7622-bananapi-bpi-r64.dts
@@ -80,6 +80,20 @@
 		reg = <0 0x40000000 0 0x40000000>;
 	};
 
+	sound: sound {
+		compatible = "mediatek,mt2701-wm8960-machine";
+		mediatek,platform = <&afe>;
+		audio-routing =
+				"Headphone", "HP_L",
+				"Headphone", "HP_R",
+				"LINPUT2", "AMIC",
+				"RINPUT2", "AMIC";
+		mediatek,audio-codec = <&wm8960>;
+		pinctrl-names = "default";
+		pinctrl-0 = <&aud_pins_default>;
+		status = "okay";
+	};
+
 	reg_1p8v: regulator-1p8v {
 		compatible = "regulator-fixed";
 		regulator-name = "fixed-1.8V";
@@ -237,6 +251,11 @@
 	pinctrl-names = "default";
 	pinctrl-0 = <&i2c1_pins>;
 	status = "okay";
+
+	wm8960: [email protected] {
+		compatible = "wlf,wm8960";
+		reg = <0x1a>;
+	};
 };
 
 &i2c2 {
@@ -316,6 +335,18 @@
 		output-high;
 	};
 
+	aud_pins_default: audiodefault {
+		mux {
+			function = "i2s";
+			groups =  "i2s_out_mclk_bclk_ws",
+				  "i2s1_in_data",
+				  "i2s1_out_data";
+		};
+		conf {
+			drive-strength = <12>;
+			bias-pull-down;
+		};
+	};
 	/* eMMC is shared pin with parallel NAND */
 	emmc_pins_default: emmc-pins-default {
 		mux {
@@ -375,6 +406,9 @@
 			function = "i2c";
 			groups =  "i2c1_0";
 		};
+		conf {
+			bias-disable;
+		};
 	};

I purchased the wm8960 decoder board, the device tree is configured as above, and the program operation error is as follows:

[email protected]:~# dmesg | grep wm8960
[    1.220583] i2c i2c-0: of_i2c: register /[email protected]/[email protected]
[    1.226569] i2c i2c-0: client [wm8960] registered with bus id 0-001a
[    1.336831] wm8960 0-001a: probe
[    1.340219] i2c-core: driver [wm8960] registered
[    1.346268] debugfs: Directory '11220000.clock-controller:audio' with parent 'mt2701-wm8960' already present!
[    1.357058] mt2701-wm8960 sound: snd-soc-dummy-dai <-> PCMO0 mapping ok
[    1.364226] mt2701-wm8960 sound: snd-soc-dummy-dai <-> PCM0 mapping ok
[    1.382991] mt2701-wm8960 sound: wm8960-hifi <-> I2S0 mapping ok
[    2.208777]   #0: mt2701-wm8960
[  130.681243]  wm8960-playback: ASoC: no backend DAIs enabled for wm8960-playback
[  201.551278]  wm8960-playback: ASoC: no backend DAIs enabled for wm8960-playback
[email protected]:~# 

test the sound card:

[email protected]:~# 
[email protected]:~# aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: mt2701wm8960 [mt2701-wm8960], device 0: wm8960-playback (*) []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
[email protected]:~# aplay /usr/share/sounds/alsa/*
[  201.551278]  wm8960-playback: ASoC: no backend DAIs enabled for wm8960-playback
Playing WAVE '/usr/share/sounds/alsa/Front_Center.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Mono
aplay: set_params:1403: Unable to install hw params:
ACCESS:  RW_INTERLEAVED
FORMAT:  S16_LE
SUBFORMAT:  STD
SAMPLE_BITS: 16
FRAME_BITS: 16
CHANNELS: 1
RATE: 48000
PERIOD_TIME: 125000
PERIOD_SIZE: 6000
PERIOD_BYTES: 12000
PERIODS: 4
BUFFER_TIME: 500000
BUFFER_SIZE: 24000
BUFFER_BYTES: 48000
TICK_TIME: 0
[email protected]:~# 

wm8960-playback: ASoC: no backend DAIs enabled for wm8960-playback

can you help me see if the problem is the Driver or Device Tree or the software Configuration?

Maybe @moore can help here…i guess you need to add your card to dts with right parameters

I found that the problem is that I2S does not start, how do I need to configure I2S to start?

please make sure below kernel options are enabled, thanks.

CONFIG_SND_SOC_MT2701=y CONFIG_SND_SOC_MT2701_WM8960=y

yes it has been activated.

   +------------------------------ Search Results -------------------------------+
      | Symbol: SND_SOC_MT2701 [=y]                                                 |  
      | Type  : tristate                                                            |  
      | Prompt: ASoC support for Mediatek MT2701 chip                               |  
      |   Location:                                                                 |  
      |     -> Device Drivers                                                       |  
      |       -> Sound card support (SOUND [=y])                                    |  
      |         -> Advanced Linux Sound Architecture (SND [=y])                     |  
      | (1)       -> ALSA for SoC audio support (SND_SOC [=y])                      |  
      |   Defined at sound/soc/mediatek/Kconfig:5                                   |  
      |   Depends on: SOUND [=y] && !UML && SND [=y] && SND_SOC [=y] && ARCH_MEDIAT |  
      |   Selects: SND_SOC_MEDIATEK [=y]                                            |  
      |                                                                             |  
      |                                                                             |  
      | Symbol: SND_SOC_MT2701_CS42448 [=n]                                         |  
      | Type  : tristate                                                            |  
      | Prompt: ASoc Audio driver for MT2701 with CS42448 codec                     |  
      |   Location:                                                                 |  
      |     -> Device Drivers                                                       |  
      |       -> Sound card support (SOUND [=y])                                    |  
      |         -> Advanced Linux Sound Architecture (SND [=y])                     |  
      |           -> ALSA for SoC audio support (SND_SOC [=y])                      |  
      | (2)         -> ASoC support for Mediatek MT2701 chip (SND_SOC_MT2701 [=y])  |  
      |   Defined at sound/soc/mediatek/Kconfig:15                                  |  
      |   Depends on: SOUND [=y] && !UML && SND [=y] && SND_SOC [=y] && SND_SOC_MT2 |  
      |   Selects: SND_SOC_CS42XX8_I2C [=n] && SND_SOC_BT_SCO [=n]                  |  
      |                                                                             |  
      |                                                                             |  
      | Symbol: SND_SOC_MT2701_PCM5102A [=n]                                        |  
      | Type  : tristate                                                            |  
      | Prompt: ASoc Audio driver for MT2701 with PCM5102A codec                    |  
      |   Location:                                                                 |  
      |     -> Device Drivers                                                       |  
      |       -> Sound card support (SOUND [=y])                                    |  
      |         -> Advanced Linux Sound Architecture (SND [=y])                     |  
      |           -> ALSA for SoC audio support (SND_SOC [=y])                      |  
      | (3)         -> ASoC support for Mediatek MT2701 chip (SND_SOC_MT2701 [=y])  |  
      |   Defined at sound/soc/mediatek/Kconfig:36                                  |  
      |   Depends on: SOUND [=y] && !UML && SND [=y] && SND_SOC [=y] && SND_SOC_MT2 |  
      |   Selects: SND_SOC_PCM5102A [=n]                                            |  
      |                                                                             |  
      |                                                                             |  
      | Symbol: SND_SOC_MT2701_WM8960 [=y]                                          |  
      | Type  : tristate                                                            |  
      | Prompt: ASoc Audio driver for MT2701 with WM8960 codec                      |  
      |   Location:                                                                 |  
      |     -> Device Drivers                                                       |  
      |       -> Sound card support (SOUND [=y])                                    |  
      |         -> Advanced Linux Sound Architecture (SND [=y])                     |  
      |           -> ALSA for SoC audio support (SND_SOC [=y])                      |  
      | (4)         -> ASoC support for Mediatek MT2701 chip (SND_SOC_MT2701 [=y])  |  
      |   Defined at sound/soc/mediatek/Kconfig:26                                  |  
      |   Depends on: SOUND [=y] && !UML && SND [=y] && SND_SOC [=y] && SND_SOC_MT2 |  
      |   Selects: SND_SOC_WM8960 [=y]                                              |  
  |                                                                 

the configuration is as follows:

  ---------------------------------------------------------------------+ |  
      | |    --- ALSA for SoC audio support                                       | |  
      | |    < >   AMD Audio Coprocessor support                                  | |  
      | |    < >   SoC Audio for the Atmel System-on-Chip                         | |  
      | |    < >   Synopsys I2S Device Driver                                     | |  
      | |          SoC Audio for Freescale CPUs  --->                             | |  
      | |    < >   Hisilicon I2S controller                                       | |  
      | |    [ ]   Audio support for Imagination Technologies designs             | |  
      | |    <*>   ASoC support for Mediatek MT2701 chip                          | |  
      | |    < >     ASoc Audio driver for MT2701 with CS42448 codec              | |  
      | |    <*>     ASoc Audio driver for MT2701 with WM8960 codec               | |  
      | |    < >   ASoC support for Mediatek MT6797 chip                          | |  
      | |    < >   ASoC support for Mediatek MT8173 chip                          | |  
      | |    < >   ASoC support for Mediatek MT8183 chip                          | |  
      | |    < >   ALSA BT SCO CVSD/MSBC Driver                                   | |  
      | |    [ ]   Sound Open Firmware Support                                    | |  
      | |          STMicroelectronics STM32 SOC audio support  ----               | |  
      | |    < >   Audio support for the Xilinx I2S                               | |  
      | |    < >   Audio support for the the Xilinx audio formatter               | |  
      | |    < >   Audio support for the the Xilinx SPDIF                         | |  
      | |    < >   XTFPGA I2S master                                              | |  
      | |    < >   ZTE ZX TDM Driver Support                                      | |  
      | |          CODEC drivers  --->                                            | |  
      | |    < >   ASoC Simple sound card support                                 | |  
      | |    < >   ASoC Audio Graph sound card support                            | |  
      | |                                                     

is the device tree configuration problem?

please provide below console log result, thanks.

cat /sys/kernel/debug/pinctrl/10211000.pinctrl-pinctrl_moore/pinmux-pins
cat /proc/asound/cards

seems the same as yours

[email protected]:~# 
[email protected]:~# cat /sys/kernel/debug/pinctrl/10211000.pinctrl-pinctrl_moore/pinmux-pins
Pinmux settings per pin
Format: pin (name): mux_owner|gpio_owner (strict) hog?
pin 0 (GPIO_A): GPIO pinctrl_moore:409
pin 1 (I2S1_IN): device sound function i2s group i2s1_in_data
pin 2 (I2S1_OUT): device sound function i2s group i2s1_out_data
pin 3 (I2S_BCLK): device sound function i2s group i2s_out_mclk_bclk_ws
pin 4 (I2S_WS): device sound function i2s group i2s_out_mclk_bclk_ws
pin 5 (I2S_MCLK): device sound function i2s group i2s_out_mclk_bclk_ws
pin 6 (TXD0): device 11002000.serial function uart group uart0_0_tx_rx
pin 7 (RXD0): device 11002000.serial function uart group uart0_0_tx_rx
pin 8 (SPI_WP): UNCLAIMED
pin 9 (SPI_HOLD): UNCLAIMED
pin 10 (SPI_CLK): UNCLAIMED
pin 11 (SPI_MOSI): UNCLAIMED
pin 12 (SPI_MISO): UNCLAIMED
pin 13 (SPI_CS): UNCLAIMED
pin 14 (I2C_SDA): device 1a145000.pcie function pcie group pcie1_0_waken
pin 15 (I2C_SCL): device 1a145000.pcie function pcie group pcie1_0_clkreq
pin 16 (I2S2_IN): device 11240000.mmc function sd group sd_0
pin 17 (I2S3_IN): device 11240000.mmc function sd group sd_0
pin 18 (I2S4_IN): device 11240000.mmc function sd group sd_0
pin 19 (I2S2_OUT): device 11240000.mmc function sd group sd_0
pin 20 (I2S3_OUT): device 11240000.mmc function sd group sd_0
pin 21 (I2S4_OUT): device 11240000.mmc function sd group sd_0
pin 22 (GPIO_B): UNCLAIMED
pin 23 (MDC): UNCLAIMED
pin 24 (MDIO): UNCLAIMED
pin 25 (G2_TXD0): UNCLAIMED
pin 26 (G2_TXD1): UNCLAIMED
pin 27 (G2_TXD2): UNCLAIMED
pin 28 (G2_TXD3): UNCLAIMED
pin 29 (G2_TXEN): UNCLAIMED
pin 30 (G2_TXC): UNCLAIMED
pin 31 (G2_RXD0): UNCLAIMED
pin 32 (G2_RXD1): UNCLAIMED
pin 33 (G2_RXD2): UNCLAIMED
pin 34 (G2_RXD3): UNCLAIMED
pin 35 (G2_RXDV): UNCLAIMED
pin 36 (G2_RXC): UNCLAIMED
pin 37 (NCEB): UNCLAIMED
pin 38 (NWEB): UNCLAIMED
pin 39 (NREB): UNCLAIMED
pin 40 (NDL4): device 11230000.mmc function emmc group emmc
pin 41 (NDL5): device 11230000.mmc function emmc group emmc
pin 42 (NDL6): device 11230000.mmc function emmc group emmc
pin 43 (NDL7): device 11230000.mmc function emmc group emmc
pin 44 (NRB): device 11230000.mmc function emmc group emmc
pin 45 (NCLE): device 11230000.mmc function emmc group emmc
pin 46 (NALE): UNCLAIMED
pin 47 (NDL0): device 11230000.mmc function emmc group emmc
pin 48 (NDL1): device 11230000.mmc function emmc group emmc
pin 49 (NDL2): device 11230000.mmc function emmc group emmc
pin 50 (NDL3): device 11230000.mmc function emmc group emmc
pin 51 (MDI_TP_P0): device 11004000.serial function uart group uart2_1_tx_rx
pin 52 (MDI_TN_P0): device 11004000.serial function uart group uart2_1_tx_rx
pin 53 (MDI_RP_P0): UNCLAIMED
pin 54 (MDI_RN_P0): GPIO pinctrl_moore:463
pin 55 (MDI_TP_P1): device 11008000.i2c function i2c group i2c1_0
pin 56 (MDI_TN_P1): device 11008000.i2c function i2c group i2c1_0
pin 57 (MDI_RP_P1): device 11009000.i2c function i2c group i2c2_0
pin 58 (MDI_RN_P1): device 11009000.i2c function i2c group i2c2_0
pin 59 (MDI_RP_P2): UNCLAIMED
pin 60 (MDI_RN_P2): UNCLAIMED
pin 61 (MDI_TP_P2): UNCLAIMED
pin 62 (MDI_TN_P2): UNCLAIMED
pin 63 (MDI_TP_P3): device 1100a000.spi function spi group spic0_0
pin 64 (MDI_TN_P3): device 1100a000.spi function spi group spic0_0
pin 65 (MDI_RP_P3): device 1100a000.spi function spi group spic0_0
pin 66 (MDI_RN_P3): device 1100a000.spi function spi group spic0_0
pin 67 (MDI_RP_P4): device 11016000.spi function spi group spic1_0
pin 68 (MDI_RN_P4): device 11016000.spi function spi group spic1_0
pin 69 (MDI_TP_P4): device 11016000.spi function spi group spic1_0
pin 70 (MDI_TN_P4): device 11016000.spi function spi group spic1_0
pin 71 (PMIC_SCL): device 10001000.pwrap function pmic group pmic_bus
pin 72 (PMIC_SDA): device 10001000.pwrap function pmic group pmic_bus
pin 73 (SPIC1_CLK): UNCLAIMED
pin 74 (SPIC1_MOSI): UNCLAIMED
pin 75 (SPIC1_MISO): UNCLAIMED
pin 76 (SPIC1_CS): UNCLAIMED
pin 77 (GPIO_D): UNCLAIMED
pin 78 (WATCHDOG): device 10212000.watchdog function watchdog group watchdog
pin 79 (RTS3_N): device 1a143000.pcie function pcie group pcie0_1_waken
pin 80 (CTS3_N): device 1a143000.pcie function pcie group pcie0_1_clkreq
pin 81 (TXD3): GPIO pinctrl_moore:490
pin 82 (RXD3): UNCLAIMED
pin 83 (PERST0_N): device 1a143000.pcie function pcie group pcie0_pad_perst
pin 84 (PERST1_N): device 1a145000.pcie function pcie group pcie1_pad_perst
pin 85 (WLED_N): GPIO pinctrl_moore:494
pin 86 (EPHY_LED0_N): UNCLAIMED
pin 87 (AUXIN0): UNCLAIMED
pin 88 (AUXIN1): GPIO pinctrl_moore:497
pin 89 (AUXIN2): GPIO pinctrl_moore:498
pin 90 (AUXIN3): GPIO pinctrl_moore:499
pin 91 (TXD4): UNCLAIMED
pin 92 (RXD4): UNCLAIMED
pin 93 (RTS4_N): UNCLAIMED
pin 94 (CTS4_N): UNCLAIMED
pin 95 (PWM1): UNCLAIMED
pin 96 (PWM2): UNCLAIMED
pin 97 (PWM3): UNCLAIMED
pin 98 (PWM4): UNCLAIMED
pin 99 (PWM5): UNCLAIMED
pin 100 (PWM6): UNCLAIMED
pin 101 (PWM7): device 11006000.pwm function pwm group pwm_ch7_2
pin 102 (GPIO_E): GPIO pinctrl_moore:511
[email protected]:~# 

and

[email protected]:~# 
[email protected]:~# cat /proc/asound/cards
 0 [mt2701wm8960   ]: mt2701-wm8960 - mt2701-wm8960
                      mt2701-wm8960
[email protected]:~#

I’ve no idea because it looks like ok. please provide the following log, thanks.

amixer -c 0 cset numid=51 on
amixer -c 0 cset numid=52 on
amixer -c 0 cset numid=78 on
amixer -c 0 cset numid=75 on
amixer -c 0 cset numid=41 on
amixer -c 0 cset numid=10 90% 90%
amixer -c 0 cset numid=11 90% 90%
aplay -M -D plughw:0,0 /usr/share/sounds/alsa/Rear_Left.wav

I follow your settings, now it can be played, and the I2S output has a signal:

[email protected]:~# amixer -c 0 cset numid=10 90% 90%
amixer -c 0 cset numid=11 90% 90%numid=10,iface=MIXER,name='O16 I13 Switch'
  ; type=BOOLEAN,access=rw------,values=1
  : values=on
[email protected]:~# amixer -c 0 cset numid=11 90% 90%
numid=11,iface=MIXER,name='O17 I14 Switch'
  ; type=BOOLEAN,access=rw------,values=1
  : values=on

what is the reason for this?

We use amixer to configure wm8960 module, and you can refer to below discussion in detail.

Thank you very much, just turn on “O15 I12 Switch” or “O16 I13 Switch” to output:

numid=8,iface=MIXER,name='O15 I12 Switch'; type=BOOLEAN,access=rw------,values=1
  : values=on
numid=9,iface=MIXER,name='O16 I13 Switch' ; type=BOOLEAN,access=rw------,values=1
  : values=on

it seems that have to look at the afe structure code, which is although it is troublesome.