public inbox for devicetree@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/7] ASoC: spacemit: bug fixes, refactoring, and K3 SoC support
@ 2026-04-29  1:38 Troy Mitchell
  2026-04-29  1:38 ` [PATCH 1/7] ASoC: spacemit: fix RX DMA params not set when TX is running Troy Mitchell
                   ` (8 more replies)
  0 siblings, 9 replies; 18+ messages in thread
From: Troy Mitchell @ 2026-04-29  1:38 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	Yixun Lan, Jinmei Wei, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley
  Cc: linux-sound, linux-riscv, spacemit, linux-kernel, devicetree,
	Troy Mitchell

This series fixes bugs and adds K3 SoC support for the SpacemiT I2S
controller driver (sound/soc/spacemit/).

Patches 1-3 are bug fixes and refactoring for the existing K1 I2S driver:
  - Fix RX DMA params not being set when TX is already running
  - Move hw constraints from hw_params to startup where they belong
  - Adjust FIFO trigger threshold to half FIFO size for better DMA
    efficiency

Patches 4-5 add dt-bindings for the spacemit,k3-i2s compatible and the
spacemit,fixed-sample-rate property. The K3 SoC uses the same I2S IP as
K1 but requires additional clocks (sysclk_div, common_sysclk,
common_bclk) that are shared across multiple I2S controllers.

Patches 6-7 add driver support for the fixed-sample-rate constraint and
K3 SoC with additional clocks. When multiple I2S controllers share a
common bclk, they must all use the same sample rate.

Signed-off-by: Troy Mitchell <troy.mitchell@linux.spacemit.com>
---
Troy Mitchell (7):
      ASoC: spacemit: fix RX DMA params not set when TX is running
      ASoC: spacemit: move hw constraints from hw_params to startup
      ASoC: spacemit: adjust FIFO trigger threshold to half FIFO size
      ASoC: dt-bindings: add SpacemiT K3 SoC compatible
      ASoC: dt-bindings: add fixed-sample-rate property for SpacemiT K1/K3
      ASoC: spacemit: add fixed-sample-rate constraint support
      ASoC: spacemit: add K3 SoC support with additional clocks

 .../devicetree/bindings/sound/spacemit,k1-i2s.yaml |  39 +++++++-
 sound/soc/spacemit/k1_i2s.c                        | 106 +++++++++++++++++----
 2 files changed, 123 insertions(+), 22 deletions(-)
---
base-commit: 02f694bcc20c664d9f4754229a3be28683c2a3f8
change-id: 20260427-k3-i2s-52ae21807466

Best regards,
--  
Troy Mitchell <troy.mitchell@linux.spacemit.com>


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH 1/7] ASoC: spacemit: fix RX DMA params not set when TX is running
  2026-04-29  1:38 [PATCH 0/7] ASoC: spacemit: bug fixes, refactoring, and K3 SoC support Troy Mitchell
@ 2026-04-29  1:38 ` Troy Mitchell
  2026-04-29  2:28   ` Mark Brown
  2026-04-29  2:35   ` Mark Brown
  2026-04-29  1:38 ` [PATCH 2/7] ASoC: spacemit: move hw constraints from hw_params to startup Troy Mitchell
                   ` (7 subsequent siblings)
  8 siblings, 2 replies; 18+ messages in thread
From: Troy Mitchell @ 2026-04-29  1:38 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	Yixun Lan, Jinmei Wei, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley
  Cc: linux-sound, linux-riscv, spacemit, linux-kernel, devicetree,
	Troy Mitchell

When TX is already running (SSCR_SSE is set), the hw_params callback
returns early before setting up DMA parameters for the RX stream. This
prevents the capture path from configuring its DMA data properly.

Move the SSCR_SSE check after DMA parameter setup and format
constraints, so both TX and RX streams get their DMA configuration
regardless of whether the hardware is already enabled. The early return
now only skips the register writes that would disrupt an active stream.

Fixes: 955f7b46873e ("ASoC: spacemit: add i2s support for K1 SoC")
Signed-off-by: Troy Mitchell <troy.mitchell@linux.spacemit.com>
---
 sound/soc/spacemit/k1_i2s.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/sound/soc/spacemit/k1_i2s.c b/sound/soc/spacemit/k1_i2s.c
index 1cb99f1abc7c..5c878f02cc93 100644
--- a/sound/soc/spacemit/k1_i2s.c
+++ b/sound/soc/spacemit/k1_i2s.c
@@ -117,10 +117,6 @@ static int spacemit_i2s_hw_params(struct snd_pcm_substream *substream,
 	u32 val;
 	int ret;
 
-	val = readl(i2s->base + SSCR);
-	if (val & SSCR_SSE)
-		return 0;
-
 	dma_data = &i2s->playback_dma_data;
 
 	if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
@@ -180,6 +176,10 @@ static int spacemit_i2s_hw_params(struct snd_pcm_substream *substream,
 
 	}
 
+	val = readl(i2s->base + SSCR);
+	if (val & SSCR_SSE)
+		return 0;
+
 	val = readl(i2s->base + SSCR);
 	val &= ~SSCR_DW_32BYTE;
 	val |= data_width;

-- 
2.54.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 2/7] ASoC: spacemit: move hw constraints from hw_params to startup
  2026-04-29  1:38 [PATCH 0/7] ASoC: spacemit: bug fixes, refactoring, and K3 SoC support Troy Mitchell
  2026-04-29  1:38 ` [PATCH 1/7] ASoC: spacemit: fix RX DMA params not set when TX is running Troy Mitchell
@ 2026-04-29  1:38 ` Troy Mitchell
  2026-04-29  1:38 ` [PATCH 3/7] ASoC: spacemit: adjust FIFO trigger threshold to half FIFO size Troy Mitchell
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 18+ messages in thread
From: Troy Mitchell @ 2026-04-29  1:38 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	Yixun Lan, Jinmei Wei, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley
  Cc: linux-sound, linux-riscv, spacemit, linux-kernel, devicetree,
	Troy Mitchell

Hardware constraints should be applied in the startup callback rather
than hw_params, as hw_params may be called too late for the constraints
to take effect properly.

Move the channel count and format constraints for I2S and DSP_A/DSP_B
modes into a new startup callback. This also tightens the I2S mode
channel constraint from 1-2 to exactly 2, matching the actual hardware
behavior.

Signed-off-by: Troy Mitchell <troy.mitchell@linux.spacemit.com>
---
 sound/soc/spacemit/k1_i2s.c | 45 ++++++++++++++++++++++++++++++++-------------
 1 file changed, 32 insertions(+), 13 deletions(-)

diff --git a/sound/soc/spacemit/k1_i2s.c b/sound/soc/spacemit/k1_i2s.c
index 5c878f02cc93..e59624b2e23a 100644
--- a/sound/soc/spacemit/k1_i2s.c
+++ b/sound/soc/spacemit/k1_i2s.c
@@ -106,6 +106,37 @@ static void spacemit_i2s_init(struct spacemit_i2s_dev *i2s)
 	writel(0, i2s->base + SSINTEN);
 }
 
+static int spacemit_i2s_startup(struct snd_pcm_substream *substream,
+	struct snd_soc_dai *dai)
+{
+	struct spacemit_i2s_dev *i2s = snd_soc_dai_get_drvdata(dai);
+
+	switch (i2s->dai_fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
+	case SND_SOC_DAIFMT_I2S:
+		snd_pcm_hw_constraint_minmax(substream->runtime,
+					     SNDRV_PCM_HW_PARAM_CHANNELS,
+					     2, 2);
+		snd_pcm_hw_constraint_mask64(substream->runtime,
+					     SNDRV_PCM_HW_PARAM_FORMAT,
+					     SNDRV_PCM_FMTBIT_S16_LE);
+		break;
+	case SND_SOC_DAIFMT_DSP_A:
+	case SND_SOC_DAIFMT_DSP_B:
+		snd_pcm_hw_constraint_minmax(substream->runtime,
+					     SNDRV_PCM_HW_PARAM_CHANNELS,
+					     1, 1);
+		snd_pcm_hw_constraint_mask64(substream->runtime,
+					     SNDRV_PCM_HW_PARAM_FORMAT,
+					     SNDRV_PCM_FMTBIT_S32_LE);
+		break;
+	default:
+		dev_dbg(i2s->dev, "unexpected format type");
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
 static int spacemit_i2s_hw_params(struct snd_pcm_substream *substream,
 				  struct snd_pcm_hw_params *params,
 				  struct snd_soc_dai *dai)
@@ -153,22 +184,9 @@ static int spacemit_i2s_hw_params(struct snd_pcm_substream *substream,
 			dma_data->maxburst = 32;
 			dma_data->addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
 		}
-
-		snd_pcm_hw_constraint_minmax(substream->runtime,
-					     SNDRV_PCM_HW_PARAM_CHANNELS,
-					     1, 2);
-		snd_pcm_hw_constraint_mask64(substream->runtime,
-					     SNDRV_PCM_HW_PARAM_FORMAT,
-					     SNDRV_PCM_FMTBIT_S16_LE);
 		break;
 	case SND_SOC_DAIFMT_DSP_A:
 	case SND_SOC_DAIFMT_DSP_B:
-		snd_pcm_hw_constraint_minmax(substream->runtime,
-					     SNDRV_PCM_HW_PARAM_CHANNELS,
-					     1, 1);
-		snd_pcm_hw_constraint_mask64(substream->runtime,
-					     SNDRV_PCM_HW_PARAM_FORMAT,
-					     SNDRV_PCM_FMTBIT_S32_LE);
 		break;
 	default:
 		dev_dbg(i2s->dev, "unexpected format type");
@@ -303,6 +321,7 @@ static int spacemit_i2s_dai_remove(struct snd_soc_dai *dai)
 static const struct snd_soc_dai_ops spacemit_i2s_dai_ops = {
 	.probe = spacemit_i2s_dai_probe,
 	.remove = spacemit_i2s_dai_remove,
+	.startup = spacemit_i2s_startup,
 	.hw_params = spacemit_i2s_hw_params,
 	.set_sysclk = spacemit_i2s_set_sysclk,
 	.set_fmt = spacemit_i2s_set_fmt,

-- 
2.54.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 3/7] ASoC: spacemit: adjust FIFO trigger threshold to half FIFO size
  2026-04-29  1:38 [PATCH 0/7] ASoC: spacemit: bug fixes, refactoring, and K3 SoC support Troy Mitchell
  2026-04-29  1:38 ` [PATCH 1/7] ASoC: spacemit: fix RX DMA params not set when TX is running Troy Mitchell
  2026-04-29  1:38 ` [PATCH 2/7] ASoC: spacemit: move hw constraints from hw_params to startup Troy Mitchell
@ 2026-04-29  1:38 ` Troy Mitchell
  2026-04-29  1:38 ` [PATCH 4/7] ASoC: dt-bindings: add SpacemiT K3 SoC compatible Troy Mitchell
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 18+ messages in thread
From: Troy Mitchell @ 2026-04-29  1:38 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	Yixun Lan, Jinmei Wei, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley
  Cc: linux-sound, linux-riscv, spacemit, linux-kernel, devicetree,
	Troy Mitchell

Set both TX and RX FIFO trigger thresholds (TFT/RFT) to 0xF (half of
the 32-entry FIFO) instead of 5. This provides better DMA efficiency
by allowing more data to accumulate before triggering a DMA request,
reducing the number of DMA transactions needed.

Signed-off-by: Troy Mitchell <troy.mitchell@linux.spacemit.com>
---
 sound/soc/spacemit/k1_i2s.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sound/soc/spacemit/k1_i2s.c b/sound/soc/spacemit/k1_i2s.c
index e59624b2e23a..cef883ba4de9 100644
--- a/sound/soc/spacemit/k1_i2s.c
+++ b/sound/soc/spacemit/k1_i2s.c
@@ -93,8 +93,8 @@ static void spacemit_i2s_init(struct spacemit_i2s_dev *i2s)
 	u32 sscr_val, sspsp_val, ssfcr_val, ssrwt_val;
 
 	sscr_val = SSCR_TRAIL | SSCR_FRF_PSP;
-	ssfcr_val = FIELD_PREP(SSFCR_FIELD_TFT, 5) |
-		    FIELD_PREP(SSFCR_FIELD_RFT, 5) |
+	ssfcr_val = FIELD_PREP(SSFCR_FIELD_TFT, 0xF) |
+		    FIELD_PREP(SSFCR_FIELD_RFT, 0xF) |
 		    SSFCR_RSRE | SSFCR_TSRE;
 	ssrwt_val = SSRWT_RWOT;
 	sspsp_val = SSPSP_SFRMP;

-- 
2.54.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 4/7] ASoC: dt-bindings: add SpacemiT K3 SoC compatible
  2026-04-29  1:38 [PATCH 0/7] ASoC: spacemit: bug fixes, refactoring, and K3 SoC support Troy Mitchell
                   ` (2 preceding siblings ...)
  2026-04-29  1:38 ` [PATCH 3/7] ASoC: spacemit: adjust FIFO trigger threshold to half FIFO size Troy Mitchell
@ 2026-04-29  1:38 ` Troy Mitchell
  2026-05-06  1:40   ` Rob Herring (Arm)
  2026-04-29  1:38 ` [PATCH 5/7] ASoC: dt-bindings: add fixed-sample-rate property for SpacemiT K1/K3 Troy Mitchell
                   ` (4 subsequent siblings)
  8 siblings, 1 reply; 18+ messages in thread
From: Troy Mitchell @ 2026-04-29  1:38 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	Yixun Lan, Jinmei Wei, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley
  Cc: linux-sound, linux-riscv, spacemit, linux-kernel, devicetree,
	Troy Mitchell

Add the spacemit,k3-i2s compatible string for the K3 SoC I2S
controller. The K3 I2S IP is the same as K1 but requires additional
clocks: sysclk_div, common_sysclk, and common_bclk. These common
clocks are shared across multiple I2S controllers on K3.

Also add the spacemit,fixed-sample-rate property which constrains
the sample rate when multiple I2S controllers share a common bclk.

Signed-off-by: Troy Mitchell <troy.mitchell@linux.spacemit.com>
---
 .../devicetree/bindings/sound/spacemit,k1-i2s.yaml | 31 ++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/sound/spacemit,k1-i2s.yaml b/Documentation/devicetree/bindings/sound/spacemit,k1-i2s.yaml
index 55bd0b307d22..240d90402e4f 100644
--- a/Documentation/devicetree/bindings/sound/spacemit,k1-i2s.yaml
+++ b/Documentation/devicetree/bindings/sound/spacemit,k1-i2s.yaml
@@ -4,7 +4,7 @@
 $id: http://devicetree.org/schemas/sound/spacemit,k1-i2s.yaml#
 $schema: http://devicetree.org/meta-schemas/core.yaml#
 
-title: K1 I2S controller
+title: SpacemiT K1/K3 I2S controller
 
 description:
   The I2S bus (Inter-IC sound bus) is a serial link for digital
@@ -15,27 +15,54 @@ maintainers:
 
 allOf:
   - $ref: dai-common.yaml#
+  - if:
+      properties:
+        compatible:
+          contains:
+            const: spacemit,k3-i2s
+    then:
+      properties:
+        clocks:
+          minItems: 7
+        clock-names:
+          minItems: 7
+    else:
+      properties:
+        clocks:
+          maxItems: 4
+        clock-names:
+          maxItems: 4
 
 properties:
   compatible:
-    const: spacemit,k1-i2s
+    enum:
+      - spacemit,k1-i2s
+      - spacemit,k3-i2s
 
   reg:
     maxItems: 1
 
   clocks:
+    minItems: 4
     items:
       - description: clock for I2S sysclk
       - description: clock for I2S bclk
       - description: clock for I2S bus
       - description: clock for I2S controller
+      - description: clock for I2S sysclk divider
+      - description: clock for I2S common sysclk
+      - description: clock for I2S common bclk
 
   clock-names:
+    minItems: 4
     items:
       - const: sysclk
       - const: bclk
       - const: bus
       - const: func
+      - const: sysclk_div
+      - const: c_sysclk
+      - const: c_bclk
 
   dmas:
     minItems: 1

-- 
2.54.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 5/7] ASoC: dt-bindings: add fixed-sample-rate property for SpacemiT K1/K3
  2026-04-29  1:38 [PATCH 0/7] ASoC: spacemit: bug fixes, refactoring, and K3 SoC support Troy Mitchell
                   ` (3 preceding siblings ...)
  2026-04-29  1:38 ` [PATCH 4/7] ASoC: dt-bindings: add SpacemiT K3 SoC compatible Troy Mitchell
@ 2026-04-29  1:38 ` Troy Mitchell
  2026-04-29  2:18   ` Mark Brown
  2026-04-29  1:38 ` [PATCH 6/7] ASoC: spacemit: add fixed-sample-rate constraint support Troy Mitchell
                   ` (3 subsequent siblings)
  8 siblings, 1 reply; 18+ messages in thread
From: Troy Mitchell @ 2026-04-29  1:38 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	Yixun Lan, Jinmei Wei, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley
  Cc: linux-sound, linux-riscv, spacemit, linux-kernel, devicetree,
	Troy Mitchell

Add the optional spacemit,fixed-sample-rate property. When multiple I2S
controllers share a common bclk, this property constrains all
controllers to the same sample rate. This applies to both K1 and K3
SoCs and is only needed when two or more I2S controllers are active
simultaneously.

Signed-off-by: Troy Mitchell <troy.mitchell@linux.spacemit.com>
---
 Documentation/devicetree/bindings/sound/spacemit,k1-i2s.yaml | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/Documentation/devicetree/bindings/sound/spacemit,k1-i2s.yaml b/Documentation/devicetree/bindings/sound/spacemit,k1-i2s.yaml
index 240d90402e4f..137070ad9eba 100644
--- a/Documentation/devicetree/bindings/sound/spacemit,k1-i2s.yaml
+++ b/Documentation/devicetree/bindings/sound/spacemit,k1-i2s.yaml
@@ -84,6 +84,14 @@ properties:
   "#sound-dai-cells":
     const: 0
 
+  spacemit,fixed-sample-rate:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description:
+      Fixed sample rate in Hz. When multiple I2S controllers share a
+      common bclk, this property constrains all controllers to the same
+      sample rate. Only needed when two or more I2S controllers are
+      active simultaneously.
+
 required:
   - compatible
   - reg

-- 
2.54.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 6/7] ASoC: spacemit: add fixed-sample-rate constraint support
  2026-04-29  1:38 [PATCH 0/7] ASoC: spacemit: bug fixes, refactoring, and K3 SoC support Troy Mitchell
                   ` (4 preceding siblings ...)
  2026-04-29  1:38 ` [PATCH 5/7] ASoC: dt-bindings: add fixed-sample-rate property for SpacemiT K1/K3 Troy Mitchell
@ 2026-04-29  1:38 ` Troy Mitchell
  2026-04-29  1:38 ` [PATCH 7/7] ASoC: spacemit: add K3 SoC support with additional clocks Troy Mitchell
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 18+ messages in thread
From: Troy Mitchell @ 2026-04-29  1:38 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	Yixun Lan, Jinmei Wei, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley
  Cc: linux-sound, linux-riscv, spacemit, linux-kernel, devicetree,
	Troy Mitchell

When multiple I2S controllers share a common bclk, they must all use
the same sample rate. Read the optional spacemit,fixed-sample-rate DT
property and apply it as a hardware constraint in the startup callback,
restricting the PCM rate to the specified value.

This applies to both K1 and K3 SoCs and is only needed when two or
more I2S controllers are active simultaneously.

Signed-off-by: Troy Mitchell <troy.mitchell@linux.spacemit.com>
---
 sound/soc/spacemit/k1_i2s.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/sound/soc/spacemit/k1_i2s.c b/sound/soc/spacemit/k1_i2s.c
index cef883ba4de9..7d0794d21ea6 100644
--- a/sound/soc/spacemit/k1_i2s.c
+++ b/sound/soc/spacemit/k1_i2s.c
@@ -3,6 +3,7 @@
 
 #include <linux/bitfield.h>
 #include <linux/clk.h>
+#include <linux/of.h>
 #include <linux/reset.h>
 #include <sound/dmaengine_pcm.h>
 #include <sound/pcm.h>
@@ -54,6 +55,8 @@ struct spacemit_i2s_dev {
 	struct clk *bclk;
 	struct clk *sspa_clk;
 
+	unsigned int fixed_sample_rate;
+
 	struct snd_dmaengine_dai_dma_data capture_dma_data;
 	struct snd_dmaengine_dai_dma_data playback_dma_data;
 
@@ -111,6 +114,13 @@ static int spacemit_i2s_startup(struct snd_pcm_substream *substream,
 {
 	struct spacemit_i2s_dev *i2s = snd_soc_dai_get_drvdata(dai);
 
+	if (i2s->fixed_sample_rate) {
+		snd_pcm_hw_constraint_minmax(substream->runtime,
+					     SNDRV_PCM_HW_PARAM_RATE,
+					     i2s->fixed_sample_rate,
+					     i2s->fixed_sample_rate);
+	}
+
 	switch (i2s->dai_fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
 	case SND_SOC_DAIFMT_I2S:
 		snd_pcm_hw_constraint_minmax(substream->runtime,
@@ -437,6 +447,9 @@ static int spacemit_i2s_probe(struct platform_device *pdev)
 		return dev_err_probe(i2s->dev, PTR_ERR(i2s->sspa_clk),
 				     "failed to enable sspa clock\n");
 
+	of_property_read_u32(i2s->dev->of_node, "spacemit,fixed-sample-rate",
+			     &i2s->fixed_sample_rate);
+
 	i2s->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
 	if (IS_ERR(i2s->base))
 		return dev_err_probe(i2s->dev, PTR_ERR(i2s->base), "failed to map registers\n");

-- 
2.54.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 7/7] ASoC: spacemit: add K3 SoC support with additional clocks
  2026-04-29  1:38 [PATCH 0/7] ASoC: spacemit: bug fixes, refactoring, and K3 SoC support Troy Mitchell
                   ` (5 preceding siblings ...)
  2026-04-29  1:38 ` [PATCH 6/7] ASoC: spacemit: add fixed-sample-rate constraint support Troy Mitchell
@ 2026-04-29  1:38 ` Troy Mitchell
  2026-04-29  2:32 ` [PATCH 0/7] ASoC: spacemit: bug fixes, refactoring, and K3 SoC support Mark Brown
  2026-04-29  2:41 ` (subset) " Mark Brown
  8 siblings, 0 replies; 18+ messages in thread
From: Troy Mitchell @ 2026-04-29  1:38 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	Yixun Lan, Jinmei Wei, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley
  Cc: linux-sound, linux-riscv, spacemit, linux-kernel, devicetree,
	Troy Mitchell

Add support for the SpacemiT K3 SoC I2S controller, which shares the
same IP as K1 but requires additional clocks: sysclk_div, c_sysclk,
and c_bclk. These clocks only exist on K3 and are not present on K1.
The sysclk_div clock is present on most K3 I2S controllers except I2S1.
The c_sysclk and c_bclk clocks are shared across multiple I2S
controllers on K3.

Use devm_clk_get_optional_enabled() to acquire these clocks so that
the driver works on both K1 (where they are absent) and K3 without
needing SoC-specific match data. For K3, the sysclk_div rate is set
before sysclk in set_sysclk, and the common clock rates are configured
in hw_params based on the sample rate.

Signed-off-by: Troy Mitchell <troy.mitchell@linux.spacemit.com>
---
 sound/soc/spacemit/k1_i2s.c | 36 +++++++++++++++++++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/sound/soc/spacemit/k1_i2s.c b/sound/soc/spacemit/k1_i2s.c
index 7d0794d21ea6..c2a2b99d91f8 100644
--- a/sound/soc/spacemit/k1_i2s.c
+++ b/sound/soc/spacemit/k1_i2s.c
@@ -54,6 +54,9 @@ struct spacemit_i2s_dev {
 	struct clk *sysclk;
 	struct clk *bclk;
 	struct clk *sspa_clk;
+	struct clk *sysclk_div;
+	struct clk *c_sysclk;
+	struct clk *c_bclk;
 
 	unsigned int fixed_sample_rate;
 
@@ -217,6 +220,14 @@ static int spacemit_i2s_hw_params(struct snd_pcm_substream *substream,
 		    params_rate(params) *
 		    data_bits;
 
+	ret = clk_set_rate(i2s->c_sysclk, bclk_rate * 2);
+	if (ret)
+		return ret;
+
+	ret = clk_set_rate(i2s->c_bclk, bclk_rate);
+	if (ret)
+		return ret;
+
 	ret = clk_set_rate(i2s->bclk, bclk_rate);
 	if (ret)
 		return ret;
@@ -228,10 +239,17 @@ static int spacemit_i2s_set_sysclk(struct snd_soc_dai *cpu_dai, int clk_id,
 				   unsigned int freq, int dir)
 {
 	struct spacemit_i2s_dev *i2s = dev_get_drvdata(cpu_dai->dev);
+	int ret;
 
 	if (freq == 0)
 		return 0;
 
+	if (i2s->sysclk_div) {
+		ret = clk_set_rate(i2s->sysclk_div, freq);
+		if (ret)
+			return ret;
+	}
+
 	return clk_set_rate(i2s->sysclk, freq);
 }
 
@@ -450,6 +468,21 @@ static int spacemit_i2s_probe(struct platform_device *pdev)
 	of_property_read_u32(i2s->dev->of_node, "spacemit,fixed-sample-rate",
 			     &i2s->fixed_sample_rate);
 
+	i2s->sysclk_div = devm_clk_get_optional_enabled(i2s->dev, "sysclk_div");
+	if (IS_ERR(i2s->sysclk_div))
+		return dev_err_probe(i2s->dev, PTR_ERR(i2s->sysclk_div),
+				     "failed to enable sysclk_div clock\n");
+
+	i2s->c_sysclk = devm_clk_get_optional_enabled(i2s->dev, "c_sysclk");
+	if (IS_ERR(i2s->c_sysclk))
+		return dev_err_probe(i2s->dev, PTR_ERR(i2s->c_sysclk),
+				     "failed to enable c_sysclk clock\n");
+
+	i2s->c_bclk = devm_clk_get_optional_enabled(i2s->dev, "c_bclk");
+	if (IS_ERR(i2s->c_bclk))
+		return dev_err_probe(i2s->dev, PTR_ERR(i2s->c_bclk),
+				     "failed to enable c_bclk clock\n");
+
 	i2s->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
 	if (IS_ERR(i2s->base))
 		return dev_err_probe(i2s->dev, PTR_ERR(i2s->base), "failed to map registers\n");
@@ -476,6 +509,7 @@ static int spacemit_i2s_probe(struct platform_device *pdev)
 
 static const struct of_device_id spacemit_i2s_of_match[] = {
 	{ .compatible = "spacemit,k1-i2s", },
+	{ .compatible = "spacemit,k3-i2s", },
 	{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, spacemit_i2s_of_match);
@@ -490,4 +524,4 @@ static struct platform_driver spacemit_i2s_driver = {
 module_platform_driver(spacemit_i2s_driver);
 
 MODULE_LICENSE("GPL");
-MODULE_DESCRIPTION("I2S bus driver for SpacemiT K1 SoC");
+MODULE_DESCRIPTION("I2S bus driver for SpacemiT K1/K3 SoC");

-- 
2.54.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH 5/7] ASoC: dt-bindings: add fixed-sample-rate property for SpacemiT K1/K3
  2026-04-29  1:38 ` [PATCH 5/7] ASoC: dt-bindings: add fixed-sample-rate property for SpacemiT K1/K3 Troy Mitchell
@ 2026-04-29  2:18   ` Mark Brown
  2026-04-29  8:06     ` Troy Mitchell
  0 siblings, 1 reply; 18+ messages in thread
From: Mark Brown @ 2026-04-29  2:18 UTC (permalink / raw)
  To: Troy Mitchell
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Yixun Lan,
	Jinmei Wei, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	linux-sound, linux-riscv, spacemit, linux-kernel, devicetree

[-- Attachment #1: Type: text/plain, Size: 499 bytes --]

On Wed, Apr 29, 2026 at 09:38:50AM +0800, Troy Mitchell wrote:
> Add the optional spacemit,fixed-sample-rate property. When multiple I2S
> controllers share a common bclk, this property constrains all
> controllers to the same sample rate. This applies to both K1 and K3
> SoCs and is only needed when two or more I2S controllers are active
> simultaneously.

This doesn't seem controller specific, it should be factored out into
the core - the same issue will apply with any system sharing a BCLK.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 1/7] ASoC: spacemit: fix RX DMA params not set when TX is running
  2026-04-29  1:38 ` [PATCH 1/7] ASoC: spacemit: fix RX DMA params not set when TX is running Troy Mitchell
@ 2026-04-29  2:28   ` Mark Brown
  2026-04-29  7:56     ` Troy Mitchell
  2026-04-29  2:35   ` Mark Brown
  1 sibling, 1 reply; 18+ messages in thread
From: Mark Brown @ 2026-04-29  2:28 UTC (permalink / raw)
  To: Troy Mitchell
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Yixun Lan,
	Jinmei Wei, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	linux-sound, linux-riscv, spacemit, linux-kernel, devicetree

[-- Attachment #1: Type: text/plain, Size: 297 bytes --]

On Wed, Apr 29, 2026 at 09:38:46AM +0800, Troy Mitchell wrote:

> +	val = readl(i2s->base + SSCR);
> +	if (val & SSCR_SSE)
> +		return 0;
> +
>  	val = readl(i2s->base + SSCR);
>  	val &= ~SSCR_DW_32BYTE;
>  	val |= data_width;

Very minor optimisation but those two SSCR reads could be combined.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 0/7] ASoC: spacemit: bug fixes, refactoring, and K3 SoC support
  2026-04-29  1:38 [PATCH 0/7] ASoC: spacemit: bug fixes, refactoring, and K3 SoC support Troy Mitchell
                   ` (6 preceding siblings ...)
  2026-04-29  1:38 ` [PATCH 7/7] ASoC: spacemit: add K3 SoC support with additional clocks Troy Mitchell
@ 2026-04-29  2:32 ` Mark Brown
  2026-04-29  7:58   ` Troy Mitchell
  2026-04-29  2:41 ` (subset) " Mark Brown
  8 siblings, 1 reply; 18+ messages in thread
From: Mark Brown @ 2026-04-29  2:32 UTC (permalink / raw)
  To: Troy Mitchell
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Yixun Lan,
	Jinmei Wei, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	linux-sound, linux-riscv, spacemit, linux-kernel, devicetree

[-- Attachment #1: Type: text/plain, Size: 761 bytes --]

On Wed, Apr 29, 2026 at 09:38:45AM +0800, Troy Mitchell wrote:
> This series fixes bugs and adds K3 SoC support for the SpacemiT I2S
> controller driver (sound/soc/spacemit/).
> 
> Patches 1-3 are bug fixes and refactoring for the existing K1 I2S driver:
>   - Fix RX DMA params not being set when TX is already running
>   - Move hw constraints from hw_params to startup where they belong
>   - Adjust FIFO trigger threshold to half FIFO size for better DMA
>     efficiency

Just as a general thing there doesn't seem to be any textual overlap
between the fixes and the new features, it makes life easier to split
things up - the individual serieses are smaller and it's easier to avoid
dependencies that cause issues getting the fixes applied.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 1/7] ASoC: spacemit: fix RX DMA params not set when TX is running
  2026-04-29  1:38 ` [PATCH 1/7] ASoC: spacemit: fix RX DMA params not set when TX is running Troy Mitchell
  2026-04-29  2:28   ` Mark Brown
@ 2026-04-29  2:35   ` Mark Brown
  2026-04-29  8:03     ` Troy Mitchell
  1 sibling, 1 reply; 18+ messages in thread
From: Mark Brown @ 2026-04-29  2:35 UTC (permalink / raw)
  To: Troy Mitchell
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Yixun Lan,
	Jinmei Wei, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	linux-sound, linux-riscv, spacemit, linux-kernel, devicetree

[-- Attachment #1: Type: text/plain, Size: 267 bytes --]

On Wed, Apr 29, 2026 at 09:38:46AM +0800, Troy Mitchell wrote:

> Fixes: 955f7b46873e ("ASoC: spacemit: add i2s support for K1 SoC")

	Fixes tag: Fixes: 955f7b46873e ("ASoC: spacemit: add i2s support for K1 SoC")
	Has these problem(s):
		- Target SHA1 does not exist

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: (subset) [PATCH 0/7] ASoC: spacemit: bug fixes, refactoring, and K3 SoC support
  2026-04-29  1:38 [PATCH 0/7] ASoC: spacemit: bug fixes, refactoring, and K3 SoC support Troy Mitchell
                   ` (7 preceding siblings ...)
  2026-04-29  2:32 ` [PATCH 0/7] ASoC: spacemit: bug fixes, refactoring, and K3 SoC support Mark Brown
@ 2026-04-29  2:41 ` Mark Brown
  8 siblings, 0 replies; 18+ messages in thread
From: Mark Brown @ 2026-04-29  2:41 UTC (permalink / raw)
  To: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Yixun Lan,
	Jinmei Wei, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Troy Mitchell
  Cc: linux-sound, linux-riscv, spacemit, linux-kernel, devicetree

On Wed, 29 Apr 2026 09:38:45 +0800, Troy Mitchell wrote:
> ASoC: spacemit: bug fixes, refactoring, and K3 SoC support
> 
> This series fixes bugs and adds K3 SoC support for the SpacemiT I2S
> controller driver (sound/soc/spacemit/).
> 
> Patches 1-3 are bug fixes and refactoring for the existing K1 I2S driver:
>   - Fix RX DMA params not being set when TX is already running
>   - Move hw constraints from hw_params to startup where they belong
>   - Adjust FIFO trigger threshold to half FIFO size for better DMA
>     efficiency
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-7.1

Thanks!

[2/7] ASoC: spacemit: move hw constraints from hw_params to startup
      https://git.kernel.org/broonie/sound/c/6b4afbaaa342
[3/7] ASoC: spacemit: adjust FIFO trigger threshold to half FIFO size
      https://git.kernel.org/broonie/sound/c/03dcb5b68a96

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 1/7] ASoC: spacemit: fix RX DMA params not set when TX is running
  2026-04-29  2:28   ` Mark Brown
@ 2026-04-29  7:56     ` Troy Mitchell
  0 siblings, 0 replies; 18+ messages in thread
From: Troy Mitchell @ 2026-04-29  7:56 UTC (permalink / raw)
  To: Mark Brown, Troy Mitchell
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Yixun Lan,
	Jinmei Wei, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	linux-sound, linux-riscv, spacemit, linux-kernel, devicetree

On Wed Apr 29, 2026 at 10:28 AM CST, Mark Brown wrote:
> On Wed, Apr 29, 2026 at 09:38:46AM +0800, Troy Mitchell wrote:
>
>> +	val = readl(i2s->base + SSCR);
>> +	if (val & SSCR_SSE)
>> +		return 0;
>> +
>>  	val = readl(i2s->base + SSCR);
>>  	val &= ~SSCR_DW_32BYTE;
>>  	val |= data_width;
>
> Very minor optimisation but those two SSCR reads could be combined.
Thanks. I'll fix it.

                   - Troy


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 0/7] ASoC: spacemit: bug fixes, refactoring, and K3 SoC support
  2026-04-29  2:32 ` [PATCH 0/7] ASoC: spacemit: bug fixes, refactoring, and K3 SoC support Mark Brown
@ 2026-04-29  7:58   ` Troy Mitchell
  0 siblings, 0 replies; 18+ messages in thread
From: Troy Mitchell @ 2026-04-29  7:58 UTC (permalink / raw)
  To: Mark Brown, Troy Mitchell
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Yixun Lan,
	Jinmei Wei, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	linux-sound, linux-riscv, spacemit, linux-kernel, devicetree

On Wed Apr 29, 2026 at 10:32 AM CST, Mark Brown wrote:
> On Wed, Apr 29, 2026 at 09:38:45AM +0800, Troy Mitchell wrote:
>> This series fixes bugs and adds K3 SoC support for the SpacemiT I2S
>> controller driver (sound/soc/spacemit/).
>> 
>> Patches 1-3 are bug fixes and refactoring for the existing K1 I2S driver:
>>   - Fix RX DMA params not being set when TX is already running
>>   - Move hw constraints from hw_params to startup where they belong
>>   - Adjust FIFO trigger threshold to half FIFO size for better DMA
>>     efficiency
>
> Just as a general thing there doesn't seem to be any textual overlap
> between the fixes and the new features, it makes life easier to split
> things up - the individual serieses are smaller and it's easier to avoid
> dependencies that cause issues getting the fixes applied.

Since patches 2/7 and 3/7 have already been applied, and 1/7 is a
small standalone fix, I'll send a v2 shortly as an independent series.

                                - Troy

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 1/7] ASoC: spacemit: fix RX DMA params not set when TX is running
  2026-04-29  2:35   ` Mark Brown
@ 2026-04-29  8:03     ` Troy Mitchell
  0 siblings, 0 replies; 18+ messages in thread
From: Troy Mitchell @ 2026-04-29  8:03 UTC (permalink / raw)
  To: Mark Brown, Troy Mitchell
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Yixun Lan,
	Jinmei Wei, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	linux-sound, linux-riscv, spacemit, linux-kernel, devicetree

On Wed Apr 29, 2026 at 10:35 AM CST, Mark Brown wrote:
> On Wed, Apr 29, 2026 at 09:38:46AM +0800, Troy Mitchell wrote:
>
>> Fixes: 955f7b46873e ("ASoC: spacemit: add i2s support for K1 SoC")
>
> 	Fixes tag: Fixes: 955f7b46873e ("ASoC: spacemit: add i2s support for K1 SoC")
> 	Has these problem(s):
> 		- Target SHA1 does not exist
should be fce217449075 ("ASoC: spacemit: add i2s support for K1 SoC")

                          - Troy


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 5/7] ASoC: dt-bindings: add fixed-sample-rate property for SpacemiT K1/K3
  2026-04-29  2:18   ` Mark Brown
@ 2026-04-29  8:06     ` Troy Mitchell
  0 siblings, 0 replies; 18+ messages in thread
From: Troy Mitchell @ 2026-04-29  8:06 UTC (permalink / raw)
  To: Mark Brown, Troy Mitchell
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Yixun Lan,
	Jinmei Wei, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	linux-sound, linux-riscv, spacemit, linux-kernel, devicetree

On Wed Apr 29, 2026 at 10:18 AM CST, Mark Brown wrote:
> On Wed, Apr 29, 2026 at 09:38:50AM +0800, Troy Mitchell wrote:
>> Add the optional spacemit,fixed-sample-rate property. When multiple I2S
>> controllers share a common bclk, this property constrains all
>> controllers to the same sample rate. This applies to both K1 and K3
>> SoCs and is only needed when two or more I2S controllers are active
>> simultaneously.
>
> This doesn't seem controller specific, it should be factored out into
> the core - the same issue will apply with any system sharing a BCLK.

Agreed, this isn't SpacemiT-specific. I'll drop the fixed-sample-rate
patches (5/7 and 6/7) from the K3 series to keep things moving, and
follow up with a separate series that addresses the shared BCLK
constraint at the core level.

                              - Troy

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 4/7] ASoC: dt-bindings: add SpacemiT K3 SoC compatible
  2026-04-29  1:38 ` [PATCH 4/7] ASoC: dt-bindings: add SpacemiT K3 SoC compatible Troy Mitchell
@ 2026-05-06  1:40   ` Rob Herring (Arm)
  0 siblings, 0 replies; 18+ messages in thread
From: Rob Herring (Arm) @ 2026-05-06  1:40 UTC (permalink / raw)
  To: Troy Mitchell
  Cc: Takashi Iwai, Jinmei Wei, Jaroslav Kysela, Mark Brown, spacemit,
	Conor Dooley, devicetree, linux-kernel, Liam Girdwood,
	linux-sound, Yixun Lan, Krzysztof Kozlowski, linux-riscv


On Wed, 29 Apr 2026 09:38:49 +0800, Troy Mitchell wrote:
> Add the spacemit,k3-i2s compatible string for the K3 SoC I2S
> controller. The K3 I2S IP is the same as K1 but requires additional
> clocks: sysclk_div, common_sysclk, and common_bclk. These common
> clocks are shared across multiple I2S controllers on K3.
> 
> Also add the spacemit,fixed-sample-rate property which constrains
> the sample rate when multiple I2S controllers share a common bclk.
> 
> Signed-off-by: Troy Mitchell <troy.mitchell@linux.spacemit.com>
> ---
>  .../devicetree/bindings/sound/spacemit,k1-i2s.yaml | 31 ++++++++++++++++++++--
>  1 file changed, 29 insertions(+), 2 deletions(-)
> 

Acked-by: Rob Herring (Arm) <robh@kernel.org>


^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2026-05-06  1:41 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-29  1:38 [PATCH 0/7] ASoC: spacemit: bug fixes, refactoring, and K3 SoC support Troy Mitchell
2026-04-29  1:38 ` [PATCH 1/7] ASoC: spacemit: fix RX DMA params not set when TX is running Troy Mitchell
2026-04-29  2:28   ` Mark Brown
2026-04-29  7:56     ` Troy Mitchell
2026-04-29  2:35   ` Mark Brown
2026-04-29  8:03     ` Troy Mitchell
2026-04-29  1:38 ` [PATCH 2/7] ASoC: spacemit: move hw constraints from hw_params to startup Troy Mitchell
2026-04-29  1:38 ` [PATCH 3/7] ASoC: spacemit: adjust FIFO trigger threshold to half FIFO size Troy Mitchell
2026-04-29  1:38 ` [PATCH 4/7] ASoC: dt-bindings: add SpacemiT K3 SoC compatible Troy Mitchell
2026-05-06  1:40   ` Rob Herring (Arm)
2026-04-29  1:38 ` [PATCH 5/7] ASoC: dt-bindings: add fixed-sample-rate property for SpacemiT K1/K3 Troy Mitchell
2026-04-29  2:18   ` Mark Brown
2026-04-29  8:06     ` Troy Mitchell
2026-04-29  1:38 ` [PATCH 6/7] ASoC: spacemit: add fixed-sample-rate constraint support Troy Mitchell
2026-04-29  1:38 ` [PATCH 7/7] ASoC: spacemit: add K3 SoC support with additional clocks Troy Mitchell
2026-04-29  2:32 ` [PATCH 0/7] ASoC: spacemit: bug fixes, refactoring, and K3 SoC support Mark Brown
2026-04-29  7:58   ` Troy Mitchell
2026-04-29  2:41 ` (subset) " Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox