Skip to contentSkip to conversation

Add speaker and headset jack support for Apple Silicon Macs

PATCH Superseded James Calligeros 7 participants 73 messages Sep 20 – Oct 3

Subsystems (9)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover Add speaker and headset jack support for Apple Silicon Macs

Hi folks,

This series finalises support for the main
audio subsystem on Apple Silicon Macs. It adds a machine driver called macaudio, which is based on an RFC sent many years ago by Martin Povišer[1]. The driver uses the DPCM model to dynamically glue a backend DAI (combination of MCA ports and codecs) to a frontend PCM. While this theoretically allows us to route any backend to any frontend, this is not used in practice; the "Primary" frontend is always used for the headset codec and the "Secondary" is always used for the speakers.

The audio subsystem on Apple Silicon Macs is rather complicated. The speaker arrangement is highly variable; some machines have a single mono woofer while others pull together multiple woofers and tweeters into a single stereo pair. The driver also exposes the headset jack's capture PCM. The builtin microphones on equipped Apple Silicon Macs are not handled by this driver as they are connected to the Always-On Processor (not actually always on).

Many functions which are handled by firmware on other platforms must be handled by the kernel or userspace. Most notably, speaker protection is handled by speakersafetyd[2], a userspace daemon. The macaudio machine driver facilitates this by exposing a capture PCM from which the voltage and current across each speaker's voice coil can be read. Given that there are absolutely no hardware or firmware level failsafes preventing permanent damage to the fragile speakers found on these machines, the driver also implements a failsafe that will mute and lock the kcontrol of every speaker unless speakersafetyd is running.

This (rather large, sorry) series is split up into logical sections:

1. Devicetree binding for the macaudio driver;
2. Minor ALSA/ASoC fixes required to drive the audio subsystem on these machines correctly;
3. Minor ALSA/ASoC API additions to facilitate the driver's integration with speakersafetyd and the insane combinatorics required to cater for such a wide array of possible setups;
4. The machine driver itself; and
5. Devicetree updates for M1 and M2 series machines.

Adding the required Devicetree updates for M3 series devices would have bloated this series to an unreasonable size as they are still missing most prerequisite hardware nodes. They will be added in a future series.

Regards,
James

[1] https://lore.kernel.org/asahi/[email protected]/
[2] https://github.com/AsahiLinux/speakersafetyd

---
Hector Martin (6):
ASoC: cs42l42: Set a faster digital ramp-up rate
ASoC: apple: mca: Fix PD link double-frees
alsa: pcm: Remove the qos request only if active
ALSA: dmaengine: Always terminate DMA when a PCM is closed
ALSA: control: Add kcontrol callbacks for lock/unlock
ASoC: ops: Export snd_soc_control_matches()

James Calligeros (13):
ASoC: tas2764: Set up V/ISENSE on codec probe
arm64: dts: apple: t8103-j274: Add speaker/headset jack nodes
arm64: dts: apple: t8103-j313: Add speaker/headset jack nodes
arm64: dts: apple: t8103-j293: Add speaker/headset jack nodes
arm64: dts: apple: t8103-j45x: Add headset jack nodes
arm64: dts: apple: t8112-j413: Add speaker/headset jack nodes
arm64: dts: apple: t8112-j415: Add speaker/headset jack nodes
arm64: dts: apple: t8112-j473: Add speaker/headset jack nodes
arm64: dts: apple: t8112-j493: Add speaker/headset jack nodes
arm64: dts: apple: t600x-j31x: Add speaker/headset jack nodes
arm64: dts: apple: t600x-j375: Add speaker/headset jack nodes
arm64: dts: apple: t602x-j41x: Add speaker/headset jack nodes
arm64: dts: apple: t602x-j47x: Add speaker/headset jack nodes

Martin Povišer (9):
dt-bindings: sound: Add Apple Macs sound peripherals
ASoC: cs42l42: Fix typo
ALSA: Support nonatomic dmaengine PCMs
ASoC: ops: Move guts out of snd_soc_limit_volume
ASoC: ops: Accept patterns in snd_soc_limit_volume
ASoC: ops: Introduce 'snd_soc_deactivate_kctl'
ASoC: ops: Introduce 'soc_set_enum_kctl'
ASoC: card: Let 'fixup_controls' return errors
ASoC: apple: Add macaudio machine driver

 .../bindings/sound/apple,macaudio.yaml   |  235 ++++
 .../arm64/boot/dts/apple/t6000-j314s.dts |    5 +
 .../arm64/boot/dts/apple/t6000-j316s.dts |    5 +
 .../arm64/boot/dts/apple/t6001-j314c.dts |    5 +
 .../arm64/boot/dts/apple/t6001-j316c.dts |    5 +
 .../arm64/boot/dts/apple/t6001-j375c.dts |    5 +
 .../arm64/boot/dts/apple/t6002-j375d.dts |    5 +
 .../boot/dts/apple/t600x-j314-j316.dtsi  |  128 ++
 .../arm64/boot/dts/apple/t600x-j375.dtsi |   58 +
 .../arm64/boot/dts/apple/t6020-j414s.dts |    5 +
 .../arm64/boot/dts/apple/t6020-j416s.dts |    5 +
 .../arm64/boot/dts/apple/t6020-j474s.dts |    5 +
 .../arm64/boot/dts/apple/t6021-j414c.dts |    5 +
 .../arm64/boot/dts/apple/t6021-j416c.dts |    5 +
 .../arm64/boot/dts/apple/t6021-j475c.dts |    5 +
 .../arm64/boot/dts/apple/t6022-j475d.dts |    5 +
 .../boot/dts/apple/t602x-j414-j416.dtsi  |   35 +
 .../boot/dts/apple/t602x-j474-j475.dtsi  |   10 +
 arch/arm64/boot/dts/apple/t8103-j274.dts |   60 +
 arch/arm64/boot/dts/apple/t8103-j293.dts |  104 ++
 arch/arm64/boot/dts/apple/t8103-j313.dts |   75 ++
 arch/arm64/boot/dts/apple/t8103-j456.dts |   33 +
 arch/arm64/boot/dts/apple/t8103-j457.dts |   33 +
 arch/arm64/boot/dts/apple/t8112-j413.dts |  101 ++
 arch/arm64/boot/dts/apple/t8112-j415.dts |  125 ++
 arch/arm64/boot/dts/apple/t8112-j473.dts |   55 +
 arch/arm64/boot/dts/apple/t8112-j493.dts |  101 ++
 include/sound/control.h                  |    7 +
 include/sound/cs42l42.h                  |    4 +
 include/sound/soc-card.h                 |    2 +-
 include/sound/soc.h                      |    8 +-
 sound/core/control.c                     |   16 +-
 sound/core/pcm_dmaengine.c               |   37 +-
 sound/core/pcm_native.c                  |    5 +-
 sound/soc/apple/Kconfig                  |   19 +
 sound/soc/apple/Makefile                 |    4 +
 sound/soc/apple/macaudio.c               | 1729 +++++++++++++++++++++++++
 sound/soc/apple/mca.c                    |   16 +-
 sound/soc/codecs/cs42l42.c               |   12 +-
 sound/soc/codecs/tas2764.c               |   61 +-
 .../soc/mediatek/mt8188/mt8188-mt6359.c  |    4 +-
 sound/soc/soc-card.c                     |   12 +-
 sound/soc/soc-core.c                     |    5 +-
 sound/soc/soc-ops.c                      |  182 ++-
 44 files changed, 3268 insertions(+), 73 deletions(-)

---
base-commit: 0e5a521109e0d2fb7ac226bd6301ec1facca1c26
change-id: 20260915-macaudio-33c1c4f304da

Best regards,

Signature · 1 line
James Calligeros <[email protected]>
#1 lore raw

PATCH 1/28 dt-bindings: sound: Add Apple Macs sound peripherals

From: Martin Povišer <[email protected]>

Add binding for Apple Silicon Macs machine-level integration of sound peripherals.

---
 .../bindings/sound/apple,macaudio.yaml   | 235 +++++++++++++++++++++++++
 1 file changed, 235 insertions(+)
Documentation/devicetree/bindings/sound/apple,macaudio.yaml new file +235 -0
new file mode 100644
index 000000000000..bd844c9928c9
@@ -0,0 +1,235 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/apple,macaudio.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Sound peripheral integration for Apple Silicon Macs
+
+description:
+  This binding represents the overall machine-level integration of sound
+  peripherals on Apple Silicon Macs, starting with the M1 series.
+
+maintainers:
+  - James Calligeros <[email protected]>
+
+properties:
+  compatible:
+    oneOf:
+      - description: First-of-their-kind machines
+        items:
+          - enum:
+              - apple,j180-macaudio
+              - apple,j274-macaudio
+              - apple,j293-macaudio
+              - apple,j313-macaudio
+              - apple,j314-macaudio
+              - apple,j316-macaudio
+              - apple,j375-macaudio
+              - apple,j413-macaudio
+              - apple,j415-macaudio
+              - apple,j473-macaudio
+              - apple,j456-macaudio
+              - apple,j457-macaudio
+          - const: apple,macaudio
+      - description: Machines compatible with J293
+        items:
+          - enum:
+              - apple,j493-macaudio
+          - const: apple,j293-macaudio
+          - const: apple,macaudio
+      - description: Machines compatible with J314
+        items:
+          - enum:
+              - apple,j414-macaudio
+              - apple,j504-macaudio
+              - apple,j514-macaudio
+          - const: apple,j314-macaudio
+          - const: apple,macaudio
+      - description: Machines compatible with J316
+        items:
+          - enum:
+              - apple,j416-macaudio
+              - apple,j516-macaudio
+          - const: apple,j316-macaudio
+          - const: apple,macaudio
+      - description: Machines compatible with J375
+        items:
+          - enum:
+              - apple,j475-macaudio
+              - apple,j575-macaudio
+          - const: apple,j375-macaudio
+          - const: apple,macaudio
+      - description: Machines compatible with J413
+        items:
+          - enum:
+              - apple,j613-macaudio
+          - const: apple,j413-macaudio
+          - const: apple,macaudio
+      - description: Machines compatible with J415
+        items:
+          - enum:
+              - apple,j615-macaudio
+          - const: apple,j415-macaudio
+          - const: apple,macaudio
+      - description: Machines compatible with J473
+        items:
+          - enum:
+              - apple,j474-macaudio
+          - const: apple,j473-macaudio
+          - const: apple,macaudio
+
+  "#address-cells":
+    const: 1
+
+  "#size-cells":
+    const: 0
+
+  model:
+    description:
+      Model name for presentation to users
+    $ref: /schemas/types.yaml#/definitions/string
+
+patternProperties:
+  "^dai-link(@[0-9a-f]+)?$":
+    description: |
+      Node for each sound peripheral such as the speaker array, headphones jack,
+      or microphone.
+    type: object
+    $ref: tdm-slot.yaml#
+
+    additionalProperties: false
+
+    properties:
+      reg:
+        maxItems: 1
+
+      link-name:
+        description: |
+          Name for the peripheral, expecting 'Speaker' or 'Speakers' if this is
+          the speaker array.
+        $ref: /schemas/types.yaml#/definitions/string
+
+      cpu:
+        type: object
+
+        properties:
+          sound-dai:
+            description: |
+              DAI list with CPU-side I2S ports involved in this peripheral.
+            minItems: 1
+            maxItems: 2
+
+        required:
+          - sound-dai
+
+      codec:
+        type: object
+
+        properties:
+          sound-dai:
+            minItems: 1
+            maxItems: 8
+            description: |
+              DAI list with the CODEC-side DAIs connected to the above CPU-side
+              DAIs and involved in this sound peripheral.
+
+              The list is in left/right order if applicable. If there are more
+              than one CPU-side DAIs (there can be two), the CODECs must be
+              listed first those connected to the first CPU, then those
+              connected to the second.
+
+              In addition, on some machines with many speaker codecs, the CODECs
+              are listed in this fixed order:
+
+              Four speakers: Left Front, Left Rear, Right Front, Right Rear
+              Six speakers: Left Woofer 1, Left Tweeter, Left Woofer 2,
+                            Right Woofer 1, Right Tweeter, Right Woofer 2
+
+        required:
+          - sound-dai
+
+    patternProperties:
+      "^dai-tdm-idle-mode-[0-9]$":
+        $ref: tdm-slot.yaml#/properties/dai-tdm-idle-mode
+
+      "^dai-tdm-slot-tx-idle-mask-[0-9]$":
+        $ref: /schemas/types.yaml#/definitions/uint32
+        description: Idle slot mask. A bit being set to 1 indicates
+          that the corresponding TDM slot is inactive/idle.
+
+    required:
+      - reg
+      - cpu
+      - codec
+
+required:
+  - compatible
+  - model
+
+additionalProperties: false
+
+examples:
+  - |
+    mca: mca@9b600000 {
+      compatible = "apple,t6000-mca", "apple,mca";
+      reg = <0x9b600000 0x10000>,
+            <0x9b500000 0x20000>;
+
+      clocks = <&nco 0>, <&nco 1>, <&nco 2>, <&nco 3>;
+      power-domains = <&ps_audio_p>, <&ps_mca0>, <&ps_mca1>,
+                      <&ps_mca2>, <&ps_mca3>;
+      dmas = <&admac 0>, <&admac 1>, <&admac 2>, <&admac 3>,
+             <&admac 4>, <&admac 5>, <&admac 6>, <&admac 7>,
+             <&admac 8>, <&admac 9>, <&admac 10>, <&admac 11>,
+             <&admac 12>, <&admac 13>, <&admac 14>, <&admac 15>;
+      dma-names = "tx0a", "rx0a", "tx0b", "rx0b",
+                  "tx1a", "rx1a", "tx1b", "rx1b",
+                  "tx2a", "rx2a", "tx2b", "rx2b",
+                  "tx3a", "rx3a", "tx3b", "rx3b";
+
+      #sound-dai-cells = <1>;
+    };
+
+    sound {
+      compatible = "apple,j416-macaudio", "apple,j316-macaudio", "apple,macaudio";
+      model = "MacBook Pro J416";
+
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      dai-link@0 {
+        reg = <0>;
+        link-name = "Speakers";
+
+        dai-tdm-idle-mode-0 = "zero";
+        dai-tdm-idle-mode-3 = "zero";
+        dai-tdm-slot-tx-idle-mask-0 = <0xf0f0f0>;
+        dai-tdm-slot-tx-idle-mask-3 = <0x0f0f0f>;
+
+        cpu {
+          sound-dai = <&mca 0>, <&mca 1>;
+        };
+
+        codec {
+          sound-dai = <&speaker_left_woof1>,
+                      <&speaker_left_tweet>,
+                      <&speaker_left_woof2>,
+                      <&speaker_right_woof1>,
+                      <&speaker_right_tweet>,
+                      <&speaker_right_woof2>;
+        };
+      };
+
+      dai-link@1 {
+        reg = <1>;
+        link-name = "Headphones Jack";
+
+        cpu {
+          sound-dai = <&mca 2>;
+        };
+        codec {
+          sound-dai = <&jack_codec>;
+        };
+      };
+    };
Signature · 1 line
2.55.0
#7 lore raw

PATCH 2/28 ASoC: cs42l42: Fix typo

In reply to James Calligeros

From: Martin Povišer <[email protected]>

Fixes 2c394ca79604 ("ASoC: Add support for CS42L42 codec")
---
 sound/soc/codecs/cs42l42.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/codecs/cs42l42.c +1 -1
index 9e40c03ada4e..b5d69d5516a6 100644
@@ -1682,7 +1682,7 @@ irqreturn_t cs42l42_irq_thread(int irq, void *data)
 	if (cs42l42->suspended || !cs42l42->init_done)
 		return IRQ_NONE;
 
-	/* Read sticky registers to clear interurpt */
+	/* Read sticky registers to clear interrupt */
 	for (i = 0; i < ARRAY_SIZE(stickies); i++) {
 		regmap_read(cs42l42->regmap, irq_params_table[i].status_addr,
 				&(stickies[i]));
Signature · 1 line
2.55.0
#9 lore raw

PATCH 3/28 ASoC: cs42l42: Set a faster digital ramp-up rate

In reply to James Calligeros

From: Hector Martin <[email protected]>

With the default ramp-up rate, there is a noticeable fade-in when streams start. This can be undesirable with aggressive muting for power saving, since the beginning of the stream is lost.

Lower the digital output ramp-up time from 8 samples per period to 2 samples per period. This still leaves some fade-in to avoid pops, but it is a lot less noticeable and no longer feels like the stream is fading in.

Fixes 2c394ca79604 ("ASoC: Add support for CS42L42 codec")
---
 include/sound/cs42l42.h    |  4 ++++
 sound/soc/codecs/cs42l42.c | 10 ++++++++++
 2 files changed, 14 insertions(+)
include/sound/cs42l42.h +4 -0
index 1bd8eee54f66..b3657965d491 100644
@@ -62,6 +62,10 @@
 #define CS42L42_INTERNAL_FS_MASK	(1 << CS42L42_INTERNAL_FS_SHIFT)
 
 #define CS42L42_SFTRAMP_RATE		(CS42L42_PAGE_10 + 0x0A)
+#define CS42L42_SFTRAMP_ASR_RATE_MASK	GENMASK(7, 4)
+#define CS42L42_SFTRAMP_ASR_RATE_SHIFT	4
+#define CS42L42_SFTRAMP_DSR_RATE_MASK	GENMASK(3, 0)
+#define CS42L42_SFTRAMP_DSR_RATE_SHIFT	0
 #define CS42L42_SLOW_START_ENABLE	(CS42L42_PAGE_10 + 0x0B)
 #define CS42L42_SLOW_START_EN_MASK	GENMASK(6, 4)
 #define CS42L42_SLOW_START_EN_SHIFT	4
sound/soc/codecs/cs42l42.c +10 -0
index b5d69d5516a6..c40e8da8f6eb 100644
@@ -2422,6 +2422,16 @@ int cs42l42_init(struct cs42l42_private *cs42l42)
 			(1 << CS42L42_ADC_PDN_SHIFT) |
 			(0 << CS42L42_PDN_ALL_SHIFT));
 
+	/*
+	 * Configure a faster digital ramp time, to avoid an audible
+	 * fade-in when streams start.
+	 */
+	regmap_update_bits(cs42l42->regmap, CS42L42_SFTRAMP_RATE,
+			   CS42L42_SFTRAMP_ASR_RATE_MASK |
+			   CS42L42_SFTRAMP_DSR_RATE_MASK,
+			   (10 << CS42L42_SFTRAMP_ASR_RATE_SHIFT) |
+			   (1 << CS42L42_SFTRAMP_DSR_RATE_SHIFT));
+
 	ret = cs42l42_handle_device_data(cs42l42->dev, cs42l42);
 	if (ret != 0)
 		goto err_shutdown;
Signature · 1 line
2.55.0
#10 lore raw

PATCH 4/28 ASoC: apple: mca: Fix PD link double-frees

In reply to James Calligeros

From: Hector Martin <[email protected]>

Add additional checks to ensure MCA PD links are not double freed.

Fixes 3df5d0d97289 ("ASoC: apple: mca: Start new platform driver")
---
 sound/soc/apple/mca.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
sound/soc/apple/mca.c +13 -3
index be702b2942a5..66196c6a9273 100644
@@ -303,6 +303,7 @@ static int mca_fe_enable_clocks(struct mca_cluster *cl)
 	 * the power state driver would error out on seeing the device
 	 * as clock-gated.
 	 */
+	WARN_ON(cl->pd_link);
 	cl->pd_link = device_link_add(mca->dev, cl->pd_dev,
 				      DL_FLAG_STATELESS | DL_FLAG_PM_RUNTIME |
 					      DL_FLAG_RPM_ACTIVE);
@@ -326,7 +327,11 @@ static void mca_fe_disable_clocks(struct mca_cluster *cl)
 	mca_modify(cl, REG_SYNCGEN_STATUS, SYNCGEN_STATUS_EN, 0);
 	mca_modify(cl, REG_STATUS, STATUS_MCLK_EN, 0);
 
-	device_link_del(cl->pd_link);
+	if (cl->pd_link) {
+		device_link_del(cl->pd_link);
+		cl->pd_link = NULL;
+	}
+
 	clk_disable_unprepare(cl->clk_parent);
 }
 
@@ -392,6 +397,7 @@ static int mca_fe_prepare(struct snd_pcm_substream *substream,
 	if (!cl->syncgen_in_use) {
 		int port = ffs(mca_fe_get_portmask(substream));
 
+		WARN_ON(cl->pd_link);
 		cl->pd_link = device_link_add(mca->dev, cl->pd_dev,
 					      DL_FLAG_STATELESS | DL_FLAG_PM_RUNTIME |
 						DL_FLAG_RPM_ACTIVE);
@@ -423,8 +429,10 @@ static int mca_fe_hw_free(struct snd_pcm_substream *substream,
 		return 0;
 
 	mca_modify(cl, REG_SYNCGEN_STATUS, SYNCGEN_STATUS_EN, 0);
-	if (cl->pd_link)
+	if (cl->pd_link) {
 		device_link_del(cl->pd_link);
+		cl->pd_link = NULL;
+	}
 
 	return 0;
 }
@@ -1145,8 +1153,10 @@ static void apple_mca_release(struct mca_data *mca)
 			dev_pm_domain_detach(cl->pd_dev, true);
 	}
 
-	if (mca->pd_link)
+	if (mca->pd_link) {
 		device_link_del(mca->pd_link);
+		mca->pd_link = NULL;
+	}
 
 	if (!IS_ERR_OR_NULL(mca->pd_dev))
 		dev_pm_domain_detach(mca->pd_dev, true);
Signature · 1 line
2.55.0
#11 lore raw

PATCH 5/28 alsa: pcm: Remove the qos request only if active

In reply to James Calligeros

From: Hector Martin <[email protected]>

Fixes warning:

[    8.502802] ------------[ cut here ]------------
[    8.503445] cpu_latency_qos_remove_request called for unknown object
[    8.504269] WARNING: CPU: 5 PID: 2790 at kernel/power/qos.c:322 cpu_latency_qos_remove_request+0x48/0x98
[    8.505499] CPU: 5 PID: 2790 Comm: wireplumber Tainted: G        W          6.5.0-asahi-00708-gb9b88240f7ae #2291
[    8.506777] Hardware name: Apple MacBook Air (13-inch, M2, 2022) (DT)
<snip regs>
[    8.519099] Call trace:
[    8.519402]  cpu_latency_qos_remove_request+0x48/0x98
[    8.520027]  snd_pcm_ioctl+0x86c/0x182c
[    8.520519]  __arm64_sys_ioctl+0xf8/0xbd0
[    8.521020]  invoke_syscall.constprop.0+0x78/0xc8
[    8.521604]  do_el0_svc+0x58/0x154
[    8.522026]  el0_svc+0x34/0xe4
[    8.522409]  el0t_64_sync_handler+0x120/0x12c
[    8.522951]  el0t_64_sync+0x190/0x194
[    8.523408] ---[ end trace 0000000000000000 ]---
Fixes 5371a79be97c ("sound: Call cpu_latency_qos_*() instead of pm_qos_*()")
---
 sound/core/pcm_native.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
sound/core/pcm_native.c +3 -2
index 6d32c12fb79b..88c83e5fd6cf 100644
@@ -971,8 +971,9 @@ static int snd_pcm_hw_free(struct snd_pcm_substream *substream)
 		goto unlock;
 	result = do_hw_free(substream);
 	snd_pcm_set_state(substream, SNDRV_PCM_STATE_OPEN);
-	cpu_latency_qos_remove_request(&substream->latency_pm_qos_req);
- unlock:
+	if (cpu_latency_qos_request_active(&substream->latency_pm_qos_req))
+		cpu_latency_qos_remove_request(&substream->latency_pm_qos_req);
+unlock:
 	snd_pcm_buffer_access_unlock(runtime);
 	return result;
 }
Signature · 1 line
2.55.0
#14 lore raw

PATCH 6/28 ALSA: dmaengine: Always terminate DMA when a PCM is closed

In reply to James Calligeros

From: Hector Martin <[email protected]>

When a PCM is suspended, we pause the DMA. If the PCM is then closed while in this state, it does not receive the STOP trigger (as it is not running). In this case, we fail to properly terminate the DMA, calling dmaengine_synchronize() nonetheless, which is undefined behavior.

Make sure we always call dmaengine_terminate_async() on PCM close, regardless of whether it has been called previously or not in the trigger callbacks.

Fixes bc0e7345168c ("ALSA: pcm_dmaengine: Properly synchronize DMA on shutdown")
---
 sound/core/pcm_dmaengine.c | 5 +++++
 1 file changed, 5 insertions(+)
sound/core/pcm_dmaengine.c +5 -0
index 1306b04be171..e59b561b849d 100644
@@ -355,6 +355,11 @@ static void __snd_dmaengine_pcm_close(struct snd_pcm_substream *substream,
 	if (status == DMA_PAUSED)
 		dmaengine_terminate_async(prtd->dma_chan);
 
+	/*
+	 * The PCM might have been closed while suspended, which would
+	 * skip the STOP trigger. Make sure we terminate.
+	 */
+	dmaengine_terminate_async(prtd->dma_chan);
 	dmaengine_synchronize(prtd->dma_chan);
 	if (release_channel)
 		dma_release_channel(prtd->dma_chan);
Signature · 1 line
2.55.0
#17 lore raw

PATCH 7/28 ALSA: Support nonatomic dmaengine PCMs

In reply to James Calligeros

From: Martin Povišer <[email protected]>

Add support for nonatomic dmaengine PCMs.

---
 sound/core/pcm_dmaengine.c | 32 ++++++++++++++++++++++++-
 1 file changed, 31 insertions(+), 1 deletion(-)
sound/core/pcm_dmaengine.c +31 -1
index e59b561b849d..839ff2711f5e 100644
@@ -22,6 +22,8 @@
 struct dmaengine_pcm_runtime_data {
 	struct dma_chan *dma_chan;
 	dma_cookie_t cookie;
+	struct work_struct complete_wq; /* for nonatomic PCM */
+	struct snd_pcm_substream *substream;
 
 	unsigned int pos;
 };
@@ -147,6 +149,24 @@ static void dmaengine_pcm_dma_complete(void *arg)
 	snd_pcm_period_elapsed(substream);
 }
 
+static void dmaengine_pcm_dma_complete_nonatomic(struct work_struct *wq)
+{
+	struct dmaengine_pcm_runtime_data *prtd = container_of(wq,
+							       struct dmaengine_pcm_runtime_data,
+							       complete_wq);
+	struct snd_pcm_substream *substream = prtd->substream;
+
+	dmaengine_pcm_dma_complete(substream);
+}
+
+static void dmaengine_pcm_dma_complete_nonatomic_callback(void *arg)
+{
+	struct snd_pcm_substream *substream = arg;
+	struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream);
+
+	schedule_work(&prtd->complete_wq);
+}
+
 static int dmaengine_pcm_prepare_and_submit(struct snd_pcm_substream *substream)
 {
 	struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream);
@@ -169,7 +189,11 @@ static int dmaengine_pcm_prepare_and_submit(struct snd_pcm_substream *substream)
 	if (!desc)
 		return -ENOMEM;
 
-	desc->callback = dmaengine_pcm_dma_complete;
+	if (substream->pcm->nonatomic)
+		desc->callback = dmaengine_pcm_dma_complete_nonatomic_callback;
+	else
+		desc->callback = dmaengine_pcm_dma_complete;
+
 	desc->callback_param = substream;
 	prtd->cookie = dmaengine_submit(desc);
 
@@ -322,6 +346,10 @@ int snd_dmaengine_pcm_open(struct snd_pcm_substream *substream,
 	if (!prtd)
 		return -ENOMEM;
 
+	if (substream->pcm->nonatomic)
+		INIT_WORK(&prtd->complete_wq, dmaengine_pcm_dma_complete_nonatomic);
+
+	prtd->substream = substream;
 	prtd->dma_chan = chan;
 
 	substream->runtime->private_data = prtd;
@@ -361,6 +389,8 @@ static void __snd_dmaengine_pcm_close(struct snd_pcm_substream *substream,
 	 */
 	dmaengine_terminate_async(prtd->dma_chan);
 	dmaengine_synchronize(prtd->dma_chan);
+	if (substream->pcm->nonatomic)
+		flush_work(&prtd->complete_wq);
 	if (release_channel)
 		dma_release_channel(prtd->dma_chan);
 	kfree(prtd);
Signature · 1 line
2.55.0
#20 lore raw

PATCH 8/28 ALSA: control: Add kcontrol callbacks for lock/unlock

In reply to James Calligeros

From: Hector Martin <[email protected]>

This allows drivers to implement policy around locking/unlocking controls, such as enforcing that a group of controls may only be locked by the same process/file, and taking actions when the controls lock/unlock (such as granting special access on lock and resetting values on unlock).

This is, in particular, useful to implement volume safety controls, such that only a particular process (that locks controls and completes a handshake) may increase volumes above a given safe limit. It also allows the volume to be automatically lowered if that process dies (which will trigger an implicit unlock).

---
 include/sound/control.h |  7 +++++++
 sound/core/control.c    | 16 ++++++++++++++--
 2 files changed, 21 insertions(+), 2 deletions(-)
include/sound/control.h +7 -0
index 909db0d0485d..6b3ef6be5100 100644
@@ -15,9 +15,12 @@
 #define snd_kcontrol_chip(kcontrol) ((kcontrol)->private_data)
 
 struct snd_kcontrol;
+struct snd_ctl_file;
 typedef int (snd_kcontrol_info_t) (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_info * uinfo);
 typedef int (snd_kcontrol_get_t) (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol);
 typedef int (snd_kcontrol_put_t) (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol);
+typedef int (snd_kcontrol_lock_t) (struct snd_kcontrol * kcontrol, struct snd_ctl_file *owner);
+typedef void (snd_kcontrol_unlock_t) (struct snd_kcontrol * kcontrol);
 typedef int (snd_kcontrol_tlv_rw_t)(struct snd_kcontrol *kcontrol,
 				    int op_flag, /* SNDRV_CTL_TLV_OP_XXX */
 				    unsigned int size,
@@ -56,6 +59,8 @@ struct snd_kcontrol_new {
 	snd_kcontrol_info_t *info;
 	snd_kcontrol_get_t *get;
 	snd_kcontrol_put_t *put;
+	snd_kcontrol_lock_t *lock;
+	snd_kcontrol_unlock_t *unlock;
 	union {
 		snd_kcontrol_tlv_rw_t *c;
 		const unsigned int *p;
@@ -75,6 +80,8 @@ struct snd_kcontrol {
 	snd_kcontrol_info_t *info;
 	snd_kcontrol_get_t *get;
 	snd_kcontrol_put_t *put;
+	snd_kcontrol_lock_t *lock;
+	snd_kcontrol_unlock_t *unlock;
 	union {
 		snd_kcontrol_tlv_rw_t *c;
 		const unsigned int *p;
sound/core/control.c +14 -2
index 4199342d4ffe..c8aab9abd306 100644
@@ -126,10 +126,12 @@ static int snd_ctl_release(struct inode *inode, struct file *file)
 	scoped_guard(rwsem_write, &card->controls_rwsem) {
 		list_for_each_entry(control, &card->controls, list)
 			for (idx = 0; idx < control->count; idx++)
-				if (control->vd[idx].owner == ctl)
+				if (control->vd[idx].owner == ctl) {
 					control->vd[idx].owner = NULL;
+					if (control->unlock)
+						control->unlock(control);
+				}
 	}
-
 	snd_fasync_free(ctl->fasync);
 	snd_ctl_empty_read_queue(ctl);
 	put_pid(ctl->pid);
@@ -306,6 +308,8 @@ struct snd_kcontrol *snd_ctl_new1(const struct snd_kcontrol_new *ncontrol,
 	kctl->info = ncontrol->info;
 	kctl->get = ncontrol->get;
 	kctl->put = ncontrol->put;
+	kctl->lock = ncontrol->lock;
+	kctl->unlock = ncontrol->unlock;
 	kctl->tlv.p = ncontrol->tlv.p;
 
 	kctl->private_value = ncontrol->private_value;
@@ -1487,6 +1491,12 @@ static int snd_ctl_elem_lock(struct snd_ctl_file *file,
 	vd = &kctl->vd[snd_ctl_get_ioff(kctl, &id)];
 	if (vd->owner)
 		return -EBUSY;
+
+	if (kctl->lock) {
+		int err = kctl->lock(kctl, file);
+		if (err < 0)
+			return err;
+	}
 	vd->owner = file;
 	return 0;
 }
@@ -1511,6 +1521,8 @@ static int snd_ctl_elem_unlock(struct snd_ctl_file *file,
 	if (vd->owner != file)
 		return -EPERM;
 	vd->owner = NULL;
+	if (kctl->unlock)
+		kctl->unlock(kctl);
 	return 0;
 }
 
Signature · 1 line
2.55.0
#26 lore raw

PATCH 9/28 ASoC: ops: Move guts out of snd_soc_limit_volume

In reply to James Calligeros

From: Martin Povišer <[email protected]>

In advance of other changes, move the modification of the control itself into function of its own.

---
 sound/soc/soc-ops.c | 28 +++++++++++++------------
 1 file changed, 15 insertions(+), 13 deletions(-)
sound/soc/soc-ops.c +15 -13
index 142f407e3939..e572b05840b4 100644
@@ -434,6 +434,16 @@ static int snd_soc_clip_to_platform_max(struct snd_kcontrol *kctl)
 	return ret;
 }
 
+static int soc_limit_volume(struct snd_kcontrol *kctl, int max)
+{
+	struct soc_mixer_control *mc = (struct soc_mixer_control *)kctl->private_value;
+
+	if (max <= 0 || max > mc->max - mc->min)
+		return -EINVAL;
+	mc->platform_max = max;
+	return snd_soc_clip_to_platform_max(kctl);
+}
+
 /**
  * snd_soc_limit_volume - Set new limit to an existing volume control.
  *
@@ -446,28 +456,20 @@ static int snd_soc_clip_to_platform_max(struct snd_kcontrol *kctl)
 int snd_soc_limit_volume(struct snd_soc_card *card, const char *name, int max)
 {
 	struct snd_kcontrol *kctl;
-	int ret = -EINVAL;
 
-	/* Sanity check for name and max */
-	if (unlikely(!name || max <= 0))
+	/* Sanity check for name */
+	if (unlikely(!name))
 		return -EINVAL;
 
 	kctl = snd_soc_card_get_kcontrol(card, name);
-	if (kctl) {
-		struct soc_mixer_control *mc =
-			(struct soc_mixer_control *)kctl->private_value;
-
-		if (max <= mc->max - mc->min) {
-			mc->platform_max = max;
-			ret = snd_soc_clip_to_platform_max(kctl);
-		}
-	} else {
+	if (!kctl) {
 		/* Some cards blindly add limits for multiple variants. */
 		dev_dbg(card->dev, "Volume limit for unknown control '%s'\n",
 			name);
+		return -EINVAL;
 	}
 
-	return ret;
+	return soc_limit_volume(kctl, max);
 }
 EXPORT_SYMBOL_GPL(snd_soc_limit_volume);
 
Signature · 1 line
2.55.0
#27 lore raw

PATCH 10/28 ASoC: ops: Accept patterns in snd_soc_limit_volume

In reply to James Calligeros

From: Martin Povišer <[email protected]>

In snd_soc_limit_volume, instead of looking up a single control by name, also understand wildcard-starting patterns like '* Amp Gain Volume' to touch many controls at one.

---
 sound/soc/soc-ops.c | 51 ++++++++++++++++++++++---
 1 file changed, 45 insertions(+), 6 deletions(-)
sound/soc/soc-ops.c +45 -6
index e572b05840b4..2f91ee7946bb 100644
@@ -403,6 +403,29 @@ int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol,
 }
 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_sx);
 
+static bool soc_control_matches(struct snd_kcontrol *kctl,
+	const char *pattern)
+{
+	const char *name = kctl->id.name;
+
+	if (pattern[0] == '*') {
+		int namelen;
+		int patternlen;
+
+		pattern++;
+		if (pattern[0] == ' ')
+			pattern++;
+
+		namelen = strlen(name);
+		patternlen = strlen(pattern);
+
+		if (namelen > patternlen)
+			name += namelen - patternlen;
+	}
+
+	return !strcmp(name, pattern);
+}
+
 static int snd_soc_clip_to_platform_max(struct snd_kcontrol *kctl)
 {
 	struct soc_mixer_control *mc = (struct soc_mixer_control *)kctl->private_value;
@@ -445,31 +468,47 @@ static int soc_limit_volume(struct snd_kcontrol *kctl, int max)
 }
 
 /**
- * snd_soc_limit_volume - Set new limit to an existing volume control.
+ * snd_soc_limit_volume - Set new limit to existing volume controls.
  *
  * @card: where to look for the control
- * @name: Name of the control
+ * @name: name pattern
  * @max: new maximum limit
  *
- * Return 0 for success, else error.
+ * Finds controls matching the given name (which can be either a name
+ * verbatim, or a pattern starting with the wildcard '*') and sets
+ * a platform volume limit on them.
+ *
+ * Return number of matching controls on success, else error. At least
+ * one control needs to match the pattern.
  */
 int snd_soc_limit_volume(struct snd_soc_card *card, const char *name, int max)
 {
 	struct snd_kcontrol *kctl;
+	int hits = 0;
+	int ret;
 
 	/* Sanity check for name */
 	if (unlikely(!name))
 		return -EINVAL;
 
-	kctl = snd_soc_card_get_kcontrol(card, name);
-	if (!kctl) {
+	list_for_each_entry(kctl, &card->snd_card->controls, list) {
+		if (!soc_control_matches(kctl, name))
+			continue;
+
+		ret = soc_limit_volume(kctl, max);
+		if (ret < 0)
+			return ret;
+		hits++;
+	}
+
+	if (!hits) {
 		/* Some cards blindly add limits for multiple variants. */
 		dev_dbg(card->dev, "Volume limit for unknown control '%s'\n",
 			name);
 		return -EINVAL;
 	}
 
-	return soc_limit_volume(kctl, max);
+	return hits;
 }
 EXPORT_SYMBOL_GPL(snd_soc_limit_volume);
 
Signature · 1 line
2.55.0
#32 lore raw

PATCH 11/28 ASoC: ops: Introduce 'snd_soc_deactivate_kctl'

In reply to James Calligeros

From: Martin Povišer <[email protected]>

The new function can be used to deactivate controls -- either a single one or in bulk by pattern. It is something a machine driver may call in fixup_controls.

---
 include/sound/soc.h |  2 ++
 sound/soc/soc-ops.c | 38 +++++++++++++++++++++++++
 2 files changed, 40 insertions(+)
include/sound/soc.h +2 -0
index 553bb7e2be98..973ffaf6f060 100644
@@ -578,6 +578,8 @@ int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol,
 	struct snd_ctl_elem_value *ucontrol);
 int snd_soc_limit_volume(struct snd_soc_card *card,
 	const char *name, int max);
+int snd_soc_deactivate_kctl(struct snd_soc_card *card,
+	const char *name, int active);
 int snd_soc_bytes_info(struct snd_kcontrol *kcontrol,
 		       struct snd_ctl_elem_info *uinfo);
 int snd_soc_bytes_get(struct snd_kcontrol *kcontrol,
sound/soc/soc-ops.c +38 -0
index 2f91ee7946bb..d35e24df891b 100644
@@ -512,6 +512,44 @@ int snd_soc_limit_volume(struct snd_soc_card *card, const char *name, int max)
 }
 EXPORT_SYMBOL_GPL(snd_soc_limit_volume);
 
+/**
+ * snd_soc_deactivate_kctl - Activate/deactivate controls matching a pattern
+ *
+ * @card: where to look for the controls
+ * @name: name pattern
+ * @active: non-zero to activate, zero to deactivate
+ *
+ * Return number of matching controls on success, else error.
+ * No controls need to match.
+ */
+int snd_soc_deactivate_kctl(struct snd_soc_card *card,
+	const char *name, int active)
+{
+	struct snd_kcontrol *kctl;
+	int hits = 0;
+	int ret;
+
+	/* Sanity check for name */
+	if (unlikely(!name))
+		return -EINVAL;
+
+	list_for_each_entry(kctl, &card->snd_card->controls, list) {
+		if (!soc_control_matches(kctl, name))
+			continue;
+
+		ret = snd_ctl_activate_id(card->snd_card, &kctl->id, active);
+		if (ret < 0)
+			return ret;
+		hits++;
+	}
+
+	if (!hits)
+		return -EINVAL;
+
+	return hits;
+}
+EXPORT_SYMBOL_GPL(snd_soc_deactivate_kctl);
+
 int snd_soc_bytes_info(struct snd_kcontrol *kcontrol,
 		       struct snd_ctl_elem_info *uinfo)
 {
Signature · 1 line
2.55.0
#35 lore raw

PATCH 12/28 ASoC: ops: Introduce 'soc_set_enum_kctl'

In reply to James Calligeros

From: Martin Povišer <[email protected]>

The new function is to be used to set enumerated controls to desired values -- either a single control or many controls in bulk by pattern. It is something a machine driver may call in fixup_controls.

---
 include/sound/soc.h |  2 +
 sound/soc/soc-ops.c | 70 +++++++++++++++++++++++++
 2 files changed, 72 insertions(+)
include/sound/soc.h +2 -0
index 973ffaf6f060..f356b553227d 100644
@@ -580,6 +580,8 @@ int snd_soc_limit_volume(struct snd_soc_card *card,
 	const char *name, int max);
 int snd_soc_deactivate_kctl(struct snd_soc_card *card,
 	const char *name, int active);
+int snd_soc_set_enum_kctl(struct snd_soc_card *card,
+	const char *name, const char *strval);
 int snd_soc_bytes_info(struct snd_kcontrol *kcontrol,
 		       struct snd_ctl_elem_info *uinfo);
 int snd_soc_bytes_get(struct snd_kcontrol *kcontrol,
sound/soc/soc-ops.c +70 -0

76 lines not on this page · raw message

Signature · 1 line
2.55.0
#38 lore raw

PATCH 13/28 ASoC: card: Let 'fixup_controls' return errors

In reply to James Calligeros

From: Martin Povišer <[email protected]>

Let the 'fixup_controls' card method return error values which will roll back the half-done binding of the card.

---
 include/sound/soc-card.h                 |  2 +-
 include/sound/soc.h                      |  2 +-
 .../soc/mediatek/mt8188/mt8188-mt6359.c  |  4 +++-
 sound/soc/soc-card.c                     | 12 +++++++++---
 sound/soc/soc-core.c                     |  5 ++++-
 5 files changed, 18 insertions(+), 7 deletions(-)
include/sound/soc-card.h +1 -1
index 1f1e7d45f553..c392e6c4844b 100644
@@ -44,7 +44,7 @@ int snd_soc_card_resume_post(struct snd_soc_card *card);
 
 int snd_soc_card_probe(struct snd_soc_card *card);
 int snd_soc_card_late_probe(struct snd_soc_card *card);
-void snd_soc_card_fixup_controls(struct snd_soc_card *card);
+int snd_soc_card_fixup_controls(struct snd_soc_card *card);
 int snd_soc_card_remove(struct snd_soc_card *card);
 
 void snd_soc_card_set_topology_name(struct snd_soc_card *card, const char *preifx);
include/sound/soc.h +1 -1
index f356b553227d..d638fc69925c 100644
@@ -1005,7 +1005,7 @@ struct snd_soc_card {
 
 	int (*probe)(struct snd_soc_card *card);
 	int (*late_probe)(struct snd_soc_card *card);
-	void (*fixup_controls)(struct snd_soc_card *card);
+	int (*fixup_controls)(struct snd_soc_card *card);
 	int (*remove)(struct snd_soc_card *card);
 
 	/* the pre and post PM functions are used to do any PM work before and
sound/soc/mediatek/mt8188/mt8188-mt6359.c +3 -1
index 75c90d1d165f..14890af97706 100644
@@ -1280,7 +1280,7 @@ static struct snd_soc_dai_link mt8188_mt6359_dai_links[] = {
 	},
 };
 
-static void mt8188_fixup_controls(struct snd_soc_card *card)
+static int mt8188_fixup_controls(struct snd_soc_card *card)
 {
 	struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(card);
 	struct mtk_platform_card_data *card_data = soc_card_data->card_data;
@@ -1302,6 +1302,8 @@ static void mt8188_fixup_controls(struct snd_soc_card *card)
 		else
 			dev_warn(card->dev, "Cannot find ctl : Headphone Switch\n");
 	}
+
+	return 0;
 }
 
 static struct snd_soc_card mt8188_mt6359_soc_card = {
sound/soc/soc-card.c +9 -3
index 282d666dae9e..e4d81329cde3 100644
@@ -184,10 +184,16 @@ int snd_soc_card_late_probe(struct snd_soc_card *card)
 	return 0;
 }
 
-void snd_soc_card_fixup_controls(struct snd_soc_card *card)
+int snd_soc_card_fixup_controls(struct snd_soc_card *card)
 {
-	if (card->fixup_controls)
-		card->fixup_controls(card);
+	if (card->fixup_controls) {
+		int ret = card->fixup_controls(card);
+
+		if (ret < 0)
+			return soc_card_ret(card, ret);
+	}
+
+	return 0;
 }
 
 int snd_soc_card_remove(struct snd_soc_card *card)
sound/soc/soc-core.c +4 -1
index 06167a198591..2092373698db 100644
@@ -2109,7 +2109,10 @@ static int snd_soc_bind_card(struct snd_soc_card *card)
 		if (ret < 0)
 			goto probe_end;
 	}
-	snd_soc_card_fixup_controls(card);
+
+	ret = snd_soc_card_fixup_controls(card);
+	if (ret < 0)
+		goto probe_end;
 
 	ret = snd_card_register(card->snd_card);
 	if (ret < 0) {
Signature · 1 line
2.55.0
#39 lore raw

PATCH 14/28 ASoC: ops: Export snd_soc_control_matches()

In reply to James Calligeros

From: Hector Martin <[email protected]>

This helper is useful for drivers that want to do their own control lookups and matching as part of more complex logic than the existing operations.

---
 include/sound/soc.h | 2 ++
 sound/soc/soc-ops.c | 9 +++++----
 2 files changed, 7 insertions(+), 4 deletions(-)
include/sound/soc.h +2 -0
index d638fc69925c..6c4689ef8973 100644
@@ -576,6 +576,8 @@ int snd_soc_get_volsw_sx(struct snd_kcontrol *kcontrol,
 	struct snd_ctl_elem_value *ucontrol);
 int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol,
 	struct snd_ctl_elem_value *ucontrol);
+bool snd_soc_control_matches(struct snd_kcontrol *kcontrol,
+	const char *pattern);
 int snd_soc_limit_volume(struct snd_soc_card *card,
 	const char *name, int max);
 int snd_soc_deactivate_kctl(struct snd_soc_card *card,
sound/soc/soc-ops.c +5 -4
index dc27d1c409ab..94d0514be66d 100644
@@ -403,7 +403,7 @@ int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol,
 }
 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_sx);
 
-static bool soc_control_matches(struct snd_kcontrol *kctl,
+bool snd_soc_control_matches(struct snd_kcontrol *kctl,
 	const char *pattern)
 {
 	const char *name = kctl->id.name;
@@ -425,6 +425,7 @@ static bool soc_control_matches(struct snd_kcontrol *kctl,
 
 	return !strcmp(name, pattern);
 }
+EXPORT_SYMBOL_GPL(snd_soc_control_matches);
 
 static int snd_soc_clip_to_platform_max(struct snd_kcontrol *kctl)
 {
@@ -492,7 +493,7 @@ int snd_soc_limit_volume(struct snd_soc_card *card, const char *name, int max)
 		return -EINVAL;
 
 	list_for_each_entry(kctl, &card->snd_card->controls, list) {
-		if (!soc_control_matches(kctl, name))
+		if (!snd_soc_control_matches(kctl, name))
 			continue;
 
 		ret = soc_limit_volume(kctl, max);
@@ -534,7 +535,7 @@ int snd_soc_deactivate_kctl(struct snd_soc_card *card,
 		return -EINVAL;
 
 	list_for_each_entry(kctl, &card->snd_card->controls, list) {
-		if (!soc_control_matches(kctl, name))
+		if (!snd_soc_control_matches(kctl, name))
 			continue;
 
 		ret = snd_ctl_activate_id(card->snd_card, &kctl->id, active);
@@ -604,7 +605,7 @@ int snd_soc_set_enum_kctl(struct snd_soc_card *card,
 		return -EINVAL;
 
 	list_for_each_entry(kctl, &card->snd_card->controls, list) {
-		if (!soc_control_matches(kctl, name))
+		if (!snd_soc_control_matches(kctl, name))
 			continue;
 
 		ret = soc_set_enum_kctl(kctl, value);
Signature · 1 line
2.55.0
#41 lore raw

PATCH 15/28 ASoC: tas2764: Set up V/ISENSE on codec probe

In reply to James Calligeros

Setup V/ISENSE on codec probe rather than doing so on every hw_params or TDM slot call so that it is configured at the same time as the rest of the codec.

---
 sound/soc/codecs/tas2764.c | 61 ++++++++-----------------
 1 file changed, 20 insertions(+), 41 deletions(-)
sound/soc/codecs/tas2764.c +20 -41
index 6654100ac91d..39372d0446d0 100644
@@ -266,8 +266,6 @@ static int tas2764_mute(struct snd_soc_dai *dai, int mute, int direction)
 static int tas2764_set_bitwidth(struct tas2764_priv *tas2764, int bitwidth)
 {
 	struct snd_soc_component *component = tas2764->component;
-	int sense_en;
-	int val;
 	int ret;
 
 	switch (bitwidth) {
@@ -297,32 +295,6 @@ static int tas2764_set_bitwidth(struct tas2764_priv *tas2764, int bitwidth)
 	if (ret < 0)
 		return ret;
 
-	val = snd_soc_component_read(tas2764->component, TAS2764_PWR_CTRL);
-	if (val < 0)
-		return val;
-
-	if (val & (1 << TAS2764_VSENSE_POWER_EN))
-		sense_en = 0;
-	else
-		sense_en = TAS2764_TDM_CFG5_VSNS_ENABLE;
-
-	ret = snd_soc_component_update_bits(tas2764->component, TAS2764_TDM_CFG5,
-					    TAS2764_TDM_CFG5_VSNS_ENABLE,
-					    sense_en);
-	if (ret < 0)
-		return ret;
-
-	if (val & (1 << TAS2764_ISENSE_POWER_EN))
-		sense_en = 0;
-	else
-		sense_en = TAS2764_TDM_CFG6_ISNS_ENABLE;
-
-	ret = snd_soc_component_update_bits(tas2764->component, TAS2764_TDM_CFG6,
-					    TAS2764_TDM_CFG6_ISNS_ENABLE,
-					    sense_en);
-	if (ret < 0)
-		return ret;
-
 	return 0;
 }
 
@@ -452,7 +424,6 @@ static int tas2764_set_dai_tdm_slot(struct snd_soc_dai *dai,
 				int slots, int slot_width)
 {
 	struct snd_soc_component *component = dai->component;
-	struct tas2764_priv *tas2764 = snd_soc_component_get_drvdata(component);
 	int left_slot, right_slot;
 	int slots_cfg;
 	int slot_size;
@@ -499,15 +470,26 @@ static int tas2764_set_dai_tdm_slot(struct snd_soc_dai *dai,
 	if (ret < 0)
 		return ret;
 
-	ret = snd_soc_component_update_bits(component, TAS2764_TDM_CFG5,
+	return 0;
+}
+
+static int tas2764_set_visense(struct tas2764_priv *tas2764, int vslot, int islot)
+{
+	int ret;
+
+	ret = snd_soc_component_update_bits(tas2764->component, TAS2764_TDM_CFG5,
+					    TAS2764_TDM_CFG5_VSNS_ENABLE |
 					    TAS2764_TDM_CFG5_50_MASK,
-					    tas2764->v_sense_slot);
+					    TAS2764_TDM_CFG5_VSNS_ENABLE |
+					    vslot);
 	if (ret < 0)
 		return ret;
 
-	ret = snd_soc_component_update_bits(component, TAS2764_TDM_CFG6,
+	ret = snd_soc_component_update_bits(tas2764->component, TAS2764_TDM_CFG6,
+					    TAS2764_TDM_CFG6_ISNS_ENABLE |
 					    TAS2764_TDM_CFG6_50_MASK,
-					    tas2764->i_sense_slot);
+					    TAS2764_TDM_CFG6_ISNS_ENABLE |
+					    islot);
 	if (ret < 0)
 		return ret;
 
@@ -821,15 +803,12 @@ static int tas2764_codec_probe(struct snd_soc_component *component)
 			dev_warn(tas2764->dev, "failed to request IRQ: %d\n", ret);
 	}
 
-	ret = snd_soc_component_update_bits(tas2764->component, TAS2764_TDM_CFG5,
-					    TAS2764_TDM_CFG5_VSNS_ENABLE, 0);
-	if (ret < 0)
-		return ret;
+	if (tas2764->v_sense_slot != -1 || tas2764->i_sense_slot != -1) {
+		ret = tas2764_set_visense(tas2764, tas2764->v_sense_slot, tas2764->i_sense_slot);
+		if (ret < 0)
+			return ret;
+	}
 
-	ret = snd_soc_component_update_bits(tas2764->component, TAS2764_TDM_CFG6,
-					    TAS2764_TDM_CFG6_ISNS_ENABLE, 0);
-	if (ret < 0)
-		return ret;
 
 	switch (tas2764->devid) {
 	case DEVID_SN012776:
Signature · 1 line
2.55.0
#44 lore raw

PATCH 16/28 ASoC: apple: Add macaudio machine driver

In reply to James Calligeros

From: Martin Povišer <[email protected]>

Apple Silicon Macs have a complex audio subsystem consisting of an I2S peripheral (MCA) and multiple codecs of various models and capabilities. Some machines have a basic mono speaker with hardware downmix, while others have a very intricate stereo system consisting of multiple codecs and drivers per L/R channel. Some machines report voice coil voltage and current information back to the SoC, and others do not. All machines have a headset jack.

Add an ASoC machine driver for this platform.

To express all of this sanely, we initialise the correct combinations of codecs/I2S ports as DAI backends and link them to a synthetic frontend. Each frontend is linked to a PCM, one for the headset codec and one for the speaker system on the target machine.

---
 sound/soc/apple/Kconfig    |   19 +
 sound/soc/apple/Makefile   |    4 +
 sound/soc/apple/macaudio.c | 1729 +++++++++++++++++++++++++
 3 files changed, 1752 insertions(+)
sound/soc/apple/Kconfig +19 -0
index f1d071a99fbf..8cca86dfd8c0 100644
@@ -9,4 +9,23 @@ config SND_SOC_APPLE_MCA
 	  This option enables an ASoC platform driver for MCA peripherals found
 	  on Apple Silicon SoCs.
 
+config SND_SOC_APPLE_MACAUDIO
+	tristate "Sound support for Apple Silicon Macs"
+	depends on ARCH_APPLE || COMPILE_TEST
+	select SND_SOC_APPLE_MCA
+	select SND_SIMPLE_CARD_UTILS
+	select APPLE_ADMAC if DMADEVICES
+	select COMMON_CLK_APPLE_NCO if COMMON_CLK
+	select SND_SOC_TAS2764 if I2C
+	select SND_SOC_TAS2770 if I2C
+	select SND_SOC_CS42L83 if I2C
+	select SND_SOC_CS42L84 if I2C
+	help
+	  This option enables an ASoC machine-level driver for Apple Silicon Macs
+	  and it also enables the required SoC and codec drivers for overall
+	  sound support on these machines. Say Y here if you have an Apple Silicon
+	  Mac.
+
+	  This driver can also be compiled as a module. If so, it will be called
+	  snd-soc-macaudio.
 endmenu
sound/soc/apple/Makefile +4 -0
index 252ba5fc18cb..f1621c03b8ee 100644
@@ -2,3 +2,7 @@
 snd-soc-apple-mca-y	:= mca.o
 
 obj-$(CONFIG_SND_SOC_APPLE_MCA)	+= snd-soc-apple-mca.o
+
+snd-soc-macaudio-objs	:= macaudio.o
+
+obj-$(CONFIG_SND_SOC_APPLE_MACAUDIO)	+= snd-soc-macaudio.o
sound/soc/apple/macaudio.c new file +1729 -0

1,729 lines not on this page · raw message

Signature · 1 line
2.55.0
#51 lore raw

PATCH 17/28 arm64: dts: apple: t8103-j274: Add speaker/headset jack nodes

In reply to James Calligeros

The M1 Mac mini integrates Apple-specific variants of the TI TAS2770 and Cirrus CS42L42. Add these nodes and advertise them to the machine driver via the sound node.

---
 arch/arm64/boot/dts/apple/t8103-j274.dts | 60 +++++++++++++++++++++++++
 1 file changed, 60 insertions(+)
arch/arm64/boot/dts/apple/t8103-j274.dts +60 -0
index 1212852251e0..4b30f08eaac0 100644
@@ -75,4 +75,64 @@ &i2c2 {
 	status = "okay";
 };
 
+/* Audio codecs */
+&i2c1 {
+	status = "okay";
+
+	speaker: codec@31 {
+		compatible = "ti,tas5770l", "ti,tas2770";
+		reg = <0x31>;
+		interrupts-extended = <&pinctrl_ap 182 IRQ_TYPE_LEVEL_LOW>;
+		shutdown-gpios = <&pinctrl_ap 181 GPIO_ACTIVE_HIGH>;
+		#sound-dai-cells = <0>;
+		ti,imon-slot-no = <0>;
+		ti,vmon-slot-no = <2>;
+	};
+};
+
+&i2c2 {
+	status = "okay";
+
+	jack_codec: codec@48 {
+		compatible = "cirrus,cs42l83";
+		reg = <0x48>;
+		interrupts-extended = <&pinctrl_ap 183 IRQ_TYPE_LEVEL_LOW>;
+		reset-gpios = <&pinctrl_nub 11 GPIO_ACTIVE_HIGH>;
+		#sound-dai-cells = <0>;
+		sound-name-prefix = "Jack";
+		cirrus,ts-inv = <1>;
+	};
+};
+
+/ {
+	sound: sound {
+		compatible = "apple,j274-macaudio", "apple,macaudio";
+		model = "Mac mini J274";
+
+		dai-link@0 {
+			link-name = "Speaker";
+
+			codec {
+				sound-dai = <&speaker>;
+			};
+
+			cpu {
+				sound-dai = <&mca 0>;
+			};
+		};
+
+		dai-link@1 {
+			link-name = "Headphone Jack";
+
+			codec {
+				sound-dai = <&jack_codec>;
+			};
+
+			cpu {
+				sound-dai = <&mca 2>;
+			};
+		};
+	};
+};
+
 #include "hwmon-mini.dtsi"
Signature · 1 line
2.55.0
#53 lore raw

PATCH 18/28 arm64: dts: apple: t8103-j313: Add speaker/headset jack nodes

In reply to James Calligeros

The M1 MacBook Air integrates Apple-specific variants of the TI TAS2770 and Cirrus CS42L42. Add these nodes and advertise them to the machine driver via the sound node.

---
 arch/arm64/boot/dts/apple/t8103-j313.dts | 75 +++++++++++++++++++++++++
 1 file changed, 75 insertions(+)
arch/arm64/boot/dts/apple/t8103-j313.dts +75 -0
index f8b2b1637b9d..514dd56bc9f0 100644
@@ -55,4 +55,79 @@ &typec1 {
 	label = "USB-C Left-front";
 };
 
+/* Audio codecs */
+&i2c1 {
+	status = "okay";
+
+	speaker_left: codec@31 {
+		compatible = "ti,tas5770l", "ti,tas2770";
+		reg = <0x31>;
+		interrupts-extended = <&pinctrl_ap 182 IRQ_TYPE_LEVEL_LOW>;
+		shutdown-gpios = <&pinctrl_ap 181 GPIO_ACTIVE_HIGH>;
+		#sound-dai-cells = <0>;
+		sound-name-prefix = "Left";
+		ti,imon-slot-no = <0>;
+		ti,vmon-slot-no = <2>;
+	};
+};
+
+&i2c3 {
+	status = "okay";
+
+	speaker_right: codec@34 {
+		compatible = "ti,tas5770l", "ti,tas2770";
+		reg = <0x34>;
+		interrupts-extended = <&pinctrl_ap 182 IRQ_TYPE_LEVEL_LOW>;
+		shutdown-gpios = <&pinctrl_ap 181 GPIO_ACTIVE_HIGH>;
+		#sound-dai-cells = <0>;
+		sound-name-prefix = "Right";
+		ti,imon-slot-no = <4>;
+		ti,vmon-slot-no = <6>;
+	};
+
+	jack_codec: codec@48 {
+		compatible = "cirrus,cs42l83";
+		reg = <0x48>;
+		interrupts-extended = <&pinctrl_ap 183 IRQ_TYPE_LEVEL_LOW>;
+		reset-gpios = <&pinctrl_nub 11 GPIO_ACTIVE_HIGH>;
+		#sound-dai-cells = <0>;
+		sound-name-prefix = "Jack";
+		cirrus,ts-inv = <1>;
+	};
+};
+
+/ {
+	sound: sound {
+		compatible = "apple,j313-macaudio", "apple,macaudio";
+		model = "MacBook Air J313";
+
+		dai-link@0 {
+			dai-tdm-idle-mode-0 = "zero";
+			dai-tdm-idle-mode-1 = "zero";
+
+			link-name = "Speakers";
+
+			codec {
+				sound-dai = <&speaker_left>, <&speaker_right>;
+			};
+
+			cpu {
+				sound-dai = <&mca 0>, <&mca 1>;
+			};
+		};
+
+		dai-link@1 {
+			link-name = "Headphone Jack";
+
+			codec {
+				sound-dai = <&jack_codec>;
+			};
+
+			cpu {
+				sound-dai = <&mca 2>;
+			};
+		};
+	};
+};
+
 #include "hwmon-laptop.dtsi"
Signature · 1 line
2.55.0
#54 lore raw

PATCH 19/28 arm64: dts: apple: t8103-j293: Add speaker/headset jack nodes

In reply to James Calligeros

The M1 MacBook Pro integrates Apple-specific variants of the TI TAS2770 and Cirrus CS42L42. Add these nodes and advertise them to the machine driver via the sound node.

---
 arch/arm64/boot/dts/apple/t8103-j293.dts | 104 +++++++++++++++++++++++++
 1 file changed, 104 insertions(+)
arch/arm64/boot/dts/apple/t8103-j293.dts +104 -0
index 1d074b9e6018..24d0b512fac4 100644
@@ -133,5 +133,109 @@ &displaydfr_dart {
 	status = "okay";
 };
 
+/* Audio codecs */
+&i2c1 {
+	status = "okay";
+
+	speaker_left_rear: codec@31 {
+		compatible = "ti,tas5770l", "ti,tas2770";
+		reg = <0x31>;
+		interrupts-extended = <&pinctrl_ap 182 IRQ_TYPE_LEVEL_LOW>;
+		shutdown-gpios = <&pinctrl_ap 181 GPIO_ACTIVE_HIGH>;
+		#sound-dai-cells = <0>;
+		sound-name-prefix = "Left Rear";
+		ti,imon-slot-no = <8>;
+		ti,vmon-slot-no = <10>;
+	};
+
+	speaker_left_front: codec@32 {
+		compatible = "ti,tas5770l", "ti,tas2770";
+		reg = <0x32>;
+		interrupts-extended = <&pinctrl_ap 182 IRQ_TYPE_LEVEL_LOW>;
+		shutdown-gpios = <&pinctrl_ap 181 GPIO_ACTIVE_HIGH>;
+		#sound-dai-cells = <0>;
+		sound-name-prefix = "Left Front";
+		ti,imon-slot-no = <0>;
+		ti,vmon-slot-no = <2>;
+	};
+};
+
+&i2c2 {
+	status = "okay";
+
+	jack_codec: codec@48 {
+		compatible = "cirrus,cs42l83";
+		reg = <0x48>;
+		interrupts-extended = <&pinctrl_ap 183 IRQ_TYPE_LEVEL_LOW>;
+		reset-gpios = <&pinctrl_nub 11 GPIO_ACTIVE_HIGH>;
+		#sound-dai-cells = <0>;
+		sound-name-prefix = "Jack";
+		cirrus,ts-inv = <1>;
+	};
+};
+
+&i2c3 {
+	status = "okay";
+
+	speaker_right_rear: codec@34 {
+		compatible = "ti,tas5770l", "ti,tas2770";
+		reg = <0x34>;
+		interrupts-extended = <&pinctrl_ap 182 IRQ_TYPE_LEVEL_LOW>;
+		shutdown-gpios = <&pinctrl_ap 181 GPIO_ACTIVE_HIGH>;
+		#sound-dai-cells = <0>;
+		sound-name-prefix = "Right Rear";
+		ti,imon-slot-no = <12>;
+		ti,vmon-slot-no = <14>;
+	};
+
+	speaker_right_front: codec@35 {
+		compatible = "ti,tas5770l", "ti,tas2770";
+		reg = <0x35>;
+		interrupts-extended = <&pinctrl_ap 182 IRQ_TYPE_LEVEL_LOW>;
+		shutdown-gpios = <&pinctrl_ap 181 GPIO_ACTIVE_HIGH>;
+		#sound-dai-cells = <0>;
+		sound-name-prefix = "Right Front";
+		ti,imon-slot-no = <4>;
+		ti,vmon-slot-no = <6>;
+	};
+};
+
+/ {
+	sound: sound {
+		compatible = "apple,j293-macaudio", "apple,macaudio";
+		model = "MacBook Pro J293";
+
+		dai-link@0 {
+			dai-tdm-idle-mode-0 = "pulldown";
+			dai-tdm-idle-mode-2 = "pulldown";
+
+			link-name = "Speakers";
+
+			codec {
+				sound-dai = <&speaker_left_front>,
+					    <&speaker_left_rear>,
+					    <&speaker_right_front>,
+					    <&speaker_right_rear>;
+			};
+
+			cpu {
+				sound-dai = <&mca 0>, <&mca 1>;
+			};
+		};
+
+		dai-link@1 {
+			link-name = "Headphone Jack";
+
+			codec {
+				sound-dai = <&jack_codec>;
+			};
+
+			cpu {
+				sound-dai = <&mca 2>;
+			};
+		};
+	};
+};
+
 #include "hwmon-laptop.dtsi"
 #include "hwmon-fan.dtsi"
Signature · 1 line
2.55.0
#56 lore raw

PATCH 20/28 arm64: dts: apple: t8103-j45x: Add headset jack nodes

In reply to James Calligeros

The M1 iMacs integrate Apple-specific variants of the TI TAS2770 and Cirrus CS42L42. Since it is not yet safe to expose the speakers on these machines, add the headset jack nodes and advertise them to the machine driver via the sound node.

---
 arch/arm64/boot/dts/apple/t8103-j456.dts | 33 +++++++++++++++++++++++++
 arch/arm64/boot/dts/apple/t8103-j457.dts | 33 +++++++++++++++++++++++++
 2 files changed, 66 insertions(+)
arch/arm64/boot/dts/apple/t8103-j456.dts +33 -0
index 090c97bb781b..41ec1398f981 100644
@@ -88,3 +88,36 @@ &pcie0_dart_1 {
 &pcie0_dart_2 {
 	status = "okay";
 };
+
+&i2c1 {
+	status = "okay";
+
+	jack_codec: codec@48 {
+		compatible = "cirrus,cs42l83";
+		reg = <0x48>;
+		interrupts-extended = <&pinctrl_ap 183 IRQ_TYPE_LEVEL_LOW>;
+		reset-gpios = <&pinctrl_nub 11 GPIO_ACTIVE_HIGH>;
+		#sound-dai-cells = <0>;
+		sound-name-prefix = "Jack";
+		cirrus,ts-inv = <1>;
+	};
+};
+
+/ {
+	sound: sound {
+		compatible = "apple,j456-macaudio", "apple,macaudio";
+		model = "iMac J456";
+
+		dai-link@1 {
+			link-name = "Headphone Jack";
+
+			codec {
+				sound-dai = <&jack_codec>;
+			};
+
+			cpu {
+				sound-dai = <&mca 2>;
+			};
+		};
+	};
+};
arch/arm64/boot/dts/apple/t8103-j457.dts +33 -0
index ebddde75455c..aa2a08cb22cb 100644
@@ -69,3 +69,36 @@ ethernet0: ethernet@0,0 {
 &pcie0_dart_2 {
 	status = "okay";
 };
+
+&i2c1 {
+	status = "okay";
+
+	jack_codec: codec@48 {
+		compatible = "cirrus,cs42l83";
+		reg = <0x48>;
+		interrupts-extended = <&pinctrl_ap 183 IRQ_TYPE_LEVEL_LOW>;
+		reset-gpios = <&pinctrl_nub 11 GPIO_ACTIVE_HIGH>;
+		#sound-dai-cells = <0>;
+		sound-name-prefix = "Jack";
+		cirrus,ts-inv = <1>;
+	};
+};
+
+/ {
+	sound: sound {
+		compatible = "apple,j457-macaudio", "apple,macaudio";
+		model = "iMac J457";
+
+		dai-link@1 {
+			link-name = "Headphone Jack";
+
+			codec {
+				sound-dai = <&jack_codec>;
+			};
+
+			cpu {
+				sound-dai = <&mca 2>;
+			};
+		};
+	};
+};
Signature · 1 line
2.55.0
#58 lore raw

PATCH 21/28 arm64: dts: apple: t8112-j413: Add speaker/headset jack nodes

In reply to James Calligeros

The M2 MacBook Air integrates Apple-specific variants of the TI TAS2764 and Cirrus CS42L42. Add these nodes and advertise them to the machine driver via the sound node.

---
 arch/arm64/boot/dts/apple/t8112-j413.dts | 101 +++++++++++++++++++++++++
 1 file changed, 101 insertions(+)
arch/arm64/boot/dts/apple/t8112-j413.dts +101 -0
index 7ccfceb08093..38d0e33c701c 100644
@@ -92,4 +92,105 @@ &fpwm1 {
 	status = "okay";
 };
 
+/* Audio codecs */
+&i2c1 {
+	status = "okay";
+
+	speaker_left_woof: codec@38 {
+		compatible = "ti,sn012776", "ti,tas2764";
+		reg = <0x38>;
+		interrupts-extended = <&pinctrl_ap 11 IRQ_TYPE_LEVEL_LOW>;
+		shutdown-gpios = <&pinctrl_ap 88 GPIO_ACTIVE_HIGH>;
+		#sound-dai-cells = <0>;
+		sound-name-prefix = "Left Woofer";
+		ti,imon-slot-no = <0>;
+		ti,vmon-slot-no = <2>;
+	};
+
+	speaker_left_tweet: codec@39 {
+		compatible = "ti,sn012776", "ti,tas2764";
+		reg = <0x39>;
+		interrupts-extended = <&pinctrl_ap 11 IRQ_TYPE_LEVEL_LOW>;
+		shutdown-gpios = <&pinctrl_ap 88 GPIO_ACTIVE_HIGH>;
+		#sound-dai-cells = <0>;
+		sound-name-prefix = "Left Tweeter";
+		ti,imon-slot-no = <8>;
+		ti,vmon-slot-no = <10>;
+	};
+};
+
+&i2c3 {
+	status = "okay";
+
+	speaker_right_woof: codec@3b {
+		compatible = "ti,sn012776", "ti,tas2764";
+		reg = <0x3b>;
+		interrupts-extended = <&pinctrl_ap 11 IRQ_TYPE_LEVEL_LOW>;
+		shutdown-gpios = <&pinctrl_ap 88 GPIO_ACTIVE_HIGH>;
+		#sound-dai-cells = <0>;
+		sound-name-prefix = "Right Woofer";
+		ti,imon-slot-no = <4>;
+		ti,vmon-slot-no = <6>;
+	};
+
+	speaker_right_tweet: codec@3c {
+		compatible = "ti,sn012776", "ti,tas2764";
+		reg = <0x3c>;
+		interrupts-extended = <&pinctrl_ap 11 IRQ_TYPE_LEVEL_LOW>;
+		shutdown-gpios = <&pinctrl_ap 88 GPIO_ACTIVE_HIGH>;
+		#sound-dai-cells = <0>;
+		sound-name-prefix = "Right Tweet";
+		ti,imon-slot-no = <12>;
+		ti,vmon-slot-no = <14>;
+	};
+
+	jack_codec: codec@4b {
+		compatible = "cirrus,cs42l84";
+		reg = <0x4b>;
+		interrupts-extended = <&pinctrl_ap 149 IRQ_TYPE_LEVEL_LOW>;
+		reset-gpios = <&pinctrl_nub 12 GPIO_ACTIVE_HIGH>;
+		#sound-dai-cells = <0>;
+		sound-name-prefix = "Jack";
+	};
+};
+
+/ {
+	sound: sound {
+		compatible = "apple,j413-macaudio", "apple,macaudio";
+		model = "MacBook Air J413";
+
+		dai-link@0 {
+			dai-tdm-idle-mode-0 = "zero";
+			dai-tdm-idle-mode-2 = "zero";
+			dai-tdm-slot-tx-idle-mask-0 = <0xf0f0>;
+			dai-tdm-slot-tx-idle-mask-2 = <0x0f0f>;
+
+			link-name = "Speakers";
+
+			codec {
+				sound-dai = <&speaker_left_woof>,
+					    <&speaker_left_tweet>,
+					    <&speaker_right_woof>,
+					    <&speaker_right_tweet>;
+			};
+
+			cpu {
+				sound-dai = <&mca 0>, <&mca 1>;
+			};
+		};
+
+		dai-link@1 {
+			link-name = "Headphone Jack";
+
+			codec {
+				sound-dai = <&jack_codec>;
+			};
+
+			cpu {
+				sound-dai = <&mca 2>;
+			};
+		};
+	};
+};
+
 #include "hwmon-laptop.dtsi"
Signature · 1 line
2.55.0
#60 lore raw

PATCH 22/28 arm64: dts: apple: t8112-j415: Add speaker/headset jack nodes

In reply to James Calligeros

The M2 MacBook Air integrates Apple-specific variants of the TI TAS2764 and Cirrus CS42L42. Add these nodes and advertise them to the machine driver via the sound node.

---
 arch/arm64/boot/dts/apple/t8112-j415.dts | 125 +++++++++++++++++++++++++
 1 file changed, 125 insertions(+)
arch/arm64/boot/dts/apple/t8112-j415.dts +125 -0
index fdc3409d2e07..5f245ef1c4bf 100644
@@ -92,4 +92,129 @@ &fpwm1 {
 	status = "okay";
 };
 
+/* Audio codecs */
+&i2c1 {
+	status = "okay";
+
+	speaker_left_woof1: codec@38 {
+		compatible = "ti,sn012776", "ti,tas2764";
+		reg = <0x38>;
+		interrupts-extended = <&pinctrl_ap 11 IRQ_TYPE_LEVEL_LOW>;
+		shutdown-gpios = <&pinctrl_ap 88 GPIO_ACTIVE_HIGH>;
+		#sound-dai-cells = <0>;
+		sound-name-prefix = "Left Woofer 1";
+		ti,imon-slot-no = <0>;
+		ti,vmon-slot-no = <2>;
+	};
+
+	speaker_left_tweet: codec@39 {
+		compatible = "ti,sn012776", "ti,tas2764";
+		reg = <0x39>;
+		interrupts-extended = <&pinctrl_ap 11 IRQ_TYPE_LEVEL_LOW>;
+		shutdown-gpios = <&pinctrl_ap 88 GPIO_ACTIVE_HIGH>;
+		#sound-dai-cells = <0>;
+		sound-name-prefix = "Left Tweeter";
+		ti,imon-slot-no = <8>;
+		ti,vmon-slot-no = <10>;
+	};
+
+	speaker_left_woof2: codec@3a {
+		compatible = "ti,sn012776", "ti,tas2764";
+		reg = <0x3a>;
+		interrupts-extended = <&pinctrl_ap 11 IRQ_TYPE_LEVEL_LOW>;
+		shutdown-gpios = <&pinctrl_ap 88 GPIO_ACTIVE_HIGH>;
+		#sound-dai-cells = <0>;
+		sound-name-prefix = "Left Woofer 2";
+		ti,imon-slot-no = <16>;
+		ti,vmon-slot-no = <18>;
+	};
+};
+
+&i2c3 {
+	status = "okay";
+
+	speaker_right_woof1: codec@3b {
+		compatible = "ti,sn012776", "ti,tas2764";
+		reg = <0x3b>;
+		interrupts-extended = <&pinctrl_ap 11 IRQ_TYPE_LEVEL_LOW>;
+		shutdown-gpios = <&pinctrl_ap 88 GPIO_ACTIVE_HIGH>;
+		#sound-dai-cells = <0>;
+		sound-name-prefix = "Right Woofer 1";
+		ti,imon-slot-no = <4>;
+		ti,vmon-slot-no = <6>;
+	};
+
+	speaker_right_tweet: codec@3c {
+		compatible = "ti,sn012776", "ti,tas2764";
+		reg = <0x3c>;
+		interrupts-extended = <&pinctrl_ap 11 IRQ_TYPE_LEVEL_LOW>;
+		shutdown-gpios = <&pinctrl_ap 88 GPIO_ACTIVE_HIGH>;
+		#sound-dai-cells = <0>;
+		sound-name-prefix = "Right Tweet";
+		ti,imon-slot-no = <12>;
+		ti,vmon-slot-no = <14>;
+	};
+
+	speaker_right_woof2: codec@3d {
+		compatible = "ti,sn012776", "ti,tas2764";
+		reg = <0x3d>;
+		interrupts-extended = <&pinctrl_ap 11 IRQ_TYPE_LEVEL_LOW>;
+		shutdown-gpios = <&pinctrl_ap 88 GPIO_ACTIVE_HIGH>;
+		#sound-dai-cells = <0>;
+		sound-name-prefix = "Right Woofer 2";
+		ti,imon-slot-no = <20>;
+		ti,vmon-slot-no = <22>;
+	};
+
+	jack_codec: codec@4b {
+		compatible = "cirrus,cs42l84";
+		reg = <0x4b>;
+		interrupts-extended = <&pinctrl_ap 149 IRQ_TYPE_LEVEL_LOW>;
+		reset-gpios = <&pinctrl_nub 12 GPIO_ACTIVE_HIGH>;
+		#sound-dai-cells = <0>;
+		sound-name-prefix = "Jack";
+	};
+};
+
+/ {
+	sound: sound {
+		compatible = "apple,j415-macaudio", "apple,macaudio";
+		model = "MacBook Air J415";
+
+		dai-link@0 {
+			dai-tdm-idle-mode-0 = "zero";
+			dai-tdm-idle-mode-3 = "zero";
+			dai-tdm-slot-tx-idle-mask-0 = <0xf0f0f0>;
+			dai-tdm-slot-tx-idle-mask-3 = <0x0f0f0f>;
+
+			link-name = "Speakers";
+
+			codec {
+				sound-dai = <&speaker_left_woof1>,
+					    <&speaker_left_tweet>,
+					    <&speaker_left_woof2>,
+					    <&speaker_right_woof1>,
+					    <&speaker_right_tweet>,
+					    <&speaker_right_woof2>;
+			};
+
+			cpu {
+				sound-dai = <&mca 0>, <&mca 1>;
+			};
+		};
+
+		dai-link@1 {
+			link-name = "Headphone Jack";
+
+			codec {
+				sound-dai = <&jack_codec>;
+			};
+
+			cpu {
+				sound-dai = <&mca 2>;
+			};
+		};
+	};
+};
+
 #include "hwmon-laptop.dtsi"
Signature · 1 line
2.55.0
#61 lore raw

PATCH 23/28 arm64: dts: apple: t8112-j473: Add speaker/headset jack nodes

In reply to James Calligeros

The M2 Mac mini integrates Apple-specific variants of the TI TAS2764 and Cirrus CS42L42. Add these nodes and advertise them to the machine driver via the sound node.

---
 arch/arm64/boot/dts/apple/t8112-j473.dts | 55 +++++++++++++++++++++++++
 1 file changed, 55 insertions(+)
arch/arm64/boot/dts/apple/t8112-j473.dts +55 -0
index 105a9d118980..50088283f2e8 100644
@@ -85,4 +85,59 @@ &typec1 {
 	label = "USB-C Back-right";
 };
 
+/* Audio codecs */
+&i2c1 {
+	status = "okay";
+
+	speaker: codec@38 {
+		compatible = "ti,sn012776", "ti,tas2764";
+		reg = <0x38>;
+		interrupts-extended = <&pinctrl_ap 11 IRQ_TYPE_LEVEL_LOW>;
+		shutdown-gpios = <&pinctrl_ap 88 GPIO_ACTIVE_HIGH>;
+		#sound-dai-cells = <0>;
+		ti,imon-slot-no = <0>;
+		ti,vmon-slot-no = <2>;
+	};
+
+	jack_codec: codec@4b {
+		compatible = "cirrus,cs42l84";
+		reg = <0x4b>;
+		interrupts-extended = <&pinctrl_ap 149 IRQ_TYPE_LEVEL_LOW>;
+		reset-gpios = <&pinctrl_nub 12 GPIO_ACTIVE_HIGH>;
+		#sound-dai-cells = <0>;
+		sound-name-prefix = "Jack";
+	};
+};
+
+/ {
+	sound: sound {
+		compatible = "apple,j473-macaudio", "apple,macaudio";
+		model = "Mac mini J473";
+
+		dai-link@0 {
+			link-name = "Speakers";
+
+			codec {
+				sound-dai = <&speaker>;
+			};
+
+			cpu {
+				sound-dai = <&mca 0>;
+			};
+		};
+
+		dai-link@1 {
+			link-name = "Headphone Jack";
+
+			codec {
+				sound-dai = <&jack_codec>;
+			};
+
+			cpu {
+				sound-dai = <&mca 2>;
+			};
+		};
+	};
+};
+
 #include "hwmon-mini.dtsi"
Signature · 1 line
2.55.0
#63 lore raw

PATCH 24/28 arm64: dts: apple: t8112-j493: Add speaker/headset jack nodes

In reply to James Calligeros

The M2 MacBook Pro integrates Apple-specific variants of the TI TAS2764 and Cirrus CS42L42. Add these nodes and advertise them to the machine driver via the sound node.

---
 arch/arm64/boot/dts/apple/t8112-j493.dts | 101 +++++++++++++++++++++++++
 1 file changed, 101 insertions(+)
arch/arm64/boot/dts/apple/t8112-j493.dts +101 -0
index 7cea5c594810..eb401ae8773e 100644
@@ -147,5 +147,106 @@ touchbar0: touchbar@0 {
 	};
 };
 
+/* Audio codecs */
+&i2c1 {
+	status = "okay";
+
+	speaker_left_rear: codec@38 {
+		compatible = "ti,sn012776", "ti,tas2764";
+		reg = <0x38>;
+		interrupts-extended = <&pinctrl_ap 11 IRQ_TYPE_LEVEL_LOW>;
+		shutdown-gpios = <&pinctrl_ap 88 GPIO_ACTIVE_HIGH>;
+		#sound-dai-cells = <0>;
+		sound-name-prefix = "Left Rear";
+		ti,imon-slot-no = <8>;
+		ti,vmon-slot-no = <10>;
+	};
+
+	speaker_left_front: codec@39 {
+		compatible = "ti,sn012776", "ti,tas2764";
+		reg = <0x39>;
+		interrupts-extended = <&pinctrl_ap 11 IRQ_TYPE_LEVEL_LOW>;
+		shutdown-gpios = <&pinctrl_ap 88 GPIO_ACTIVE_HIGH>;
+		#sound-dai-cells = <0>;
+		sound-name-prefix = "Left Front";
+		ti,imon-slot-no = <0>;
+		ti,vmon-slot-no = <2>;
+	};
+};
+
+&i2c3 {
+	status = "okay";
+
+	speaker_right_rear: codec@3b {
+		compatible = "ti,sn012776", "ti,tas2764";
+		reg = <0x3b>;
+		interrupts-extended = <&pinctrl_ap 11 IRQ_TYPE_LEVEL_LOW>;
+		shutdown-gpios = <&pinctrl_ap 88 GPIO_ACTIVE_HIGH>;
+		#sound-dai-cells = <0>;
+		sound-name-prefix = "Right Rear";
+		ti,imon-slot-no = <12>;
+		ti,vmon-slot-no = <14>;
+	};
+
+	speaker_right_front: codec@3c {
+		compatible = "ti,sn012776", "ti,tas2764";
+		reg = <0x3c>;
+		interrupts-extended = <&pinctrl_ap 11 IRQ_TYPE_LEVEL_LOW>;
+		shutdown-gpios = <&pinctrl_ap 88 GPIO_ACTIVE_HIGH>;
+		#sound-dai-cells = <0>;
+		sound-name-prefix = "Right Front";
+		ti,imon-slot-no = <4>;
+		ti,vmon-slot-no = <6>;
+	};
+
+	jack_codec: codec@4b {
+		compatible = "cirrus,cs42l84";
+		reg = <0x4b>;
+		interrupts-extended = <&pinctrl_ap 149 IRQ_TYPE_LEVEL_LOW>;
+		reset-gpios = <&pinctrl_nub 12 GPIO_ACTIVE_HIGH>;
+		#sound-dai-cells = <0>;
+		sound-name-prefix = "Jack";
+	};
+};
+
+/ {
+	sound: sound {
+		compatible = "apple,j493-macaudio", "apple,macaudio";
+		model = "MacBook Pro J493";
+
+		dai-link@0 {
+			dai-tdm-idle-mode-0 = "zero";
+			dai-tdm-idle-mode-2 = "zero";
+			dai-tdm-slot-tx-idle-mask-0 = <0xf0f0>;
+			dai-tdm-slot-tx-idle-mask-2 = <0x0f0f>;
+
+			link-name = "Speakers";
+
+			codec {
+				sound-dai = <&speaker_left_front>,
+					    <&speaker_left_rear>,
+					    <&speaker_right_front>,
+					    <&speaker_right_rear>;
+			};
+
+			cpu {
+				sound-dai = <&mca 0>, <&mca 1>;
+			};
+		};
+
+		dai-link@1 {
+			link-name = "Headphone Jack";
+
+			codec {
+				sound-dai = <&jack_codec>;
+			};
+
+			cpu {
+				sound-dai = <&mca 2>;
+			};
+		};
+	};
+};
+
 #include "hwmon-laptop.dtsi"
 #include "hwmon-fan.dtsi"
Signature · 1 line
2.55.0
#65 lore raw

PATCH 25/28 arm64: dts: apple: t600x-j31x: Add speaker/headset jack nodes

In reply to James Calligeros

The M1 Pro/Max MacBooks integrate Apple-specific variants of the TI TAS2764 and Cirrus CS42L42. Add these nodes and advertise them to the machine driver via the sound node.

---
 .../arm64/boot/dts/apple/t6000-j314s.dts |   5 +
 .../arm64/boot/dts/apple/t6000-j316s.dts |   5 +
 .../arm64/boot/dts/apple/t6001-j314c.dts |   5 +
 .../arm64/boot/dts/apple/t6001-j316c.dts |   5 +
 .../boot/dts/apple/t600x-j314-j316.dtsi  | 128 +++++++++++++++++++++++++
 5 files changed, 148 insertions(+)
arch/arm64/boot/dts/apple/t6000-j314s.dts +5 -0
index 1430b91ff1b1..dab8e99fa324 100644
@@ -24,3 +24,8 @@ &wifi0 {
 &bluetooth0 {
 	brcm,board-type = "apple,maldives";
 };
+
+&sound {
+	compatible = "apple,j314-macaudio", "apple,macaudio";
+	model = "MacBook Pro J314";
+};
arch/arm64/boot/dts/apple/t6000-j316s.dts +5 -0
index da0cbe7d9673..2cdfac3c40c8 100644
@@ -24,3 +24,8 @@ &wifi0 {
 &bluetooth0 {
 	brcm,board-type = "apple,madagascar";
 };
+
+&sound {
+	compatible = "apple,j316-macaudio", "apple,macaudio";
+	model = "MacBook Pro J316";
+};
arch/arm64/boot/dts/apple/t6001-j314c.dts +5 -0
index c37097dcfdb3..7495698beb02 100644
@@ -24,3 +24,8 @@ &wifi0 {
 &bluetooth0 {
 	brcm,board-type = "apple,maldives";
 };
+
+&sound {
+	compatible = "apple,j314-macaudio", "apple,macaudio";
+	model = "MacBook Pro J314";
+};
arch/arm64/boot/dts/apple/t6001-j316c.dts +5 -0
index 3bc6e0c3294c..6622b6e225a6 100644
@@ -24,3 +24,8 @@ &wifi0 {
 &bluetooth0 {
 	brcm,board-type = "apple,madagascar";
 };
+
+&sound {
+	compatible = "apple,j316-macaudio", "apple,macaudio";
+	model = "MacBook Pro J316";
+};
arch/arm64/boot/dts/apple/t600x-j314-j316.dtsi +128 -0

140 lines not on this page · raw message

Signature · 1 line
2.55.0
#67 lore raw

PATCH 26/28 arm64: dts: apple: t600x-j375: Add speaker/headset jack nodes

In reply to James Calligeros

The M1 Max/Ultra Mac Studio integrates Apple-specific variants of the TI TAS2764 and Cirrus CS42L42. Add these nodes and advertise them to the machine driver via the sound node.

---
 .../arm64/boot/dts/apple/t6001-j375c.dts |  5 +++
 .../arm64/boot/dts/apple/t6002-j375d.dts |  5 +++
 .../arm64/boot/dts/apple/t600x-j375.dtsi | 58 +++++++++++++++++++++++++
 3 files changed, 68 insertions(+)
arch/arm64/boot/dts/apple/t6001-j375c.dts +5 -0
index 08276114c1d8..bfaafad6f60b 100644
@@ -25,4 +25,9 @@ &bluetooth0 {
 	brcm,board-type = "apple,okinawa";
 };
 
+&sound {
+	compatible = "apple,j375-macaudio", "apple,macaudio";
+	model = "Mac Studio J375";
+};
+
 #include "hwmon-fan-dual.dtsi"
arch/arm64/boot/dts/apple/t6002-j375d.dts +5 -0
index e6eb6b6c386d..2f37784357a8 100644
@@ -184,6 +184,11 @@ atcphy5_usb3: endpoint {
 	};
 };
 
+&sound {
+	compatible = "apple,j375-macaudio", "apple,macaudio";
+	model = "Mac Studio J375";
+};
+
 #include "hwmon-fan-dual.dtsi"
 
 /* delete unused USB nodes on die 1 */
arch/arm64/boot/dts/apple/t600x-j375.dtsi +58 -0

68 lines not on this page · raw message

Signature · 1 line
2.55.0
#69 lore raw

PATCH 27/28 arm64: dts: apple: t602x-j41x: Add speaker/headset jack nodes

In reply to James Calligeros

The M2 Pro/Max MacBooks integrate Apple-specific variants of the TI TAS2764 and Cirrus CS42L42. Add these nodes and advertise them to the machine driver via the sound node.

---
 .../arm64/boot/dts/apple/t6020-j414s.dts |  5 ++++
 .../arm64/boot/dts/apple/t6020-j416s.dts |  5 ++++
 .../arm64/boot/dts/apple/t6021-j414c.dts |  5 ++++
 .../arm64/boot/dts/apple/t6021-j416c.dts |  5 ++++
 .../boot/dts/apple/t602x-j414-j416.dtsi  | 35 +++++++++++++++++++++++++
 5 files changed, 55 insertions(+)
arch/arm64/boot/dts/apple/t6020-j414s.dts +5 -0
index 631c54c5f03d..b42750fc9404 100644
@@ -24,3 +24,8 @@ &wifi0 {
 &bluetooth0 {
 	brcm,board-type = "apple,tokara";
 };
+
+&sound {
+	compatible = "apple,j414-macaudio", "apple,j314-macaudio", "apple,macaudio";
+	model = "MacBook Pro J414";
+};
arch/arm64/boot/dts/apple/t6020-j416s.dts +5 -0
index c277ed5889a2..98caa29e3bdd 100644
@@ -24,3 +24,8 @@ &wifi0 {
 &bluetooth0 {
 	brcm,board-type = "apple,amami";
 };
+
+&sound {
+	compatible = "apple,j416-macaudio", "apple,j316-macaudio", "apple,macaudio";
+	model = "MacBook Pro J416";
+};
arch/arm64/boot/dts/apple/t6021-j414c.dts +5 -0
index cdcf0740714d..b945b75e518c 100644
@@ -24,3 +24,8 @@ &wifi0 {
 &bluetooth0 {
 	brcm,board-type = "apple,tokara";
 };
+
+&sound {
+	compatible = "apple,j414-macaudio", "apple,j314-macaudio", "apple,macaudio";
+	model = "MacBook Pro J414";
+};
arch/arm64/boot/dts/apple/t6021-j416c.dts +5 -0
index 6d8146b94170..0d4a7ef7dcac 100644
@@ -24,3 +24,8 @@ &wifi0 {
 &bluetooth0 {
 	brcm,board-type = "apple,amami";
 };
+
+&sound {
+	compatible = "apple,j416-macaudio", "apple,j316-macaudio", "apple,macaudio";
+	model = "MacBook Pro J416";
+};
arch/arm64/boot/dts/apple/t602x-j414-j416.dtsi +35 -0
index 0e806d8ddf81..852fbcd6277a 100644
@@ -43,3 +43,38 @@ &wifi0 {
 &bluetooth0 {
 	compatible = "pci14e4,5f72";
 };
+
+&speaker_left_tweet {
+	interrupts-extended = <&pinctrl_ap 58 IRQ_TYPE_LEVEL_LOW>;
+	shutdown-gpios = <&pinctrl_ap 57 GPIO_ACTIVE_HIGH>;
+};
+
+&speaker_left_woof1 {
+	interrupts-extended = <&pinctrl_ap 58 IRQ_TYPE_LEVEL_LOW>;
+	shutdown-gpios = <&pinctrl_ap 57 GPIO_ACTIVE_HIGH>;
+};
+
+&speaker_left_woof2 {
+	interrupts-extended = <&pinctrl_ap 58 IRQ_TYPE_LEVEL_LOW>;
+	shutdown-gpios = <&pinctrl_ap 57 GPIO_ACTIVE_HIGH>;
+};
+
+&speaker_right_tweet {
+	interrupts-extended = <&pinctrl_ap 58 IRQ_TYPE_LEVEL_LOW>;
+	shutdown-gpios = <&pinctrl_ap 57 GPIO_ACTIVE_HIGH>;
+};
+
+&speaker_right_woof1 {
+	interrupts-extended = <&pinctrl_ap 58 IRQ_TYPE_LEVEL_LOW>;
+	shutdown-gpios = <&pinctrl_ap 57 GPIO_ACTIVE_HIGH>;
+};
+
+&speaker_right_woof2 {
+	interrupts-extended = <&pinctrl_ap 58 IRQ_TYPE_LEVEL_LOW>;
+	shutdown-gpios = <&pinctrl_ap 57 GPIO_ACTIVE_HIGH>;
+};
+
+&jack_codec {
+	interrupts-extended = <&pinctrl_ap 59 IRQ_TYPE_LEVEL_LOW>;
+	reset-gpios = <&pinctrl_nub 8 GPIO_ACTIVE_HIGH>;
+};
Signature · 1 line
2.55.0
#70 lore raw

PATCH 28/28 arm64: dts: apple: t602x-j47x: Add speaker/headset jack nodes

In reply to James Calligeros

The M2 Pro/Max/Ultra Mac mini and Mac Studio integrate Apple-specific variants of the TI TAS2764 and Cirrus CS42L42. Add these nodes and advertise them to the machine driver via the sound node.

---
 .../arm64/boot/dts/apple/t6020-j474s.dts |  5 +++++
 .../arm64/boot/dts/apple/t6021-j475c.dts |  5 +++++
 .../arm64/boot/dts/apple/t6022-j475d.dts |  5 +++++
 .../boot/dts/apple/t602x-j474-j475.dtsi  | 10 ++++++++++
 4 files changed, 25 insertions(+)
arch/arm64/boot/dts/apple/t6020-j474s.dts +5 -0
index e3c2635d84fa..e79315b15f11 100644
@@ -46,4 +46,9 @@ &pcie0 {
 			<0x300 &pcie0_dart_3 1 1>;
 };
 
+&sound {
+	compatible = "apple,j474-macaudio", "apple,j473-macaudio", "apple,macaudio";
+	model = "Mac Studio J473";
+};
+
 #include "hwmon-mini.dtsi"
arch/arm64/boot/dts/apple/t6021-j475c.dts +5 -0
index 9fe17f1f7f59..8aecd23e0ac3 100644
@@ -36,4 +36,9 @@ &pcie0_dart_1 {
 	status = "okay";
 };
 
+&sound {
+	compatible = "apple,j475-macaudio", "apple,j375-macaudio", "apple,macaudio";
+	model = "Mac Studio J475";
+};
+
 #include "hwmon-fan-dual.dtsi"
arch/arm64/boot/dts/apple/t6022-j475d.dts +5 -0
index 32938a3bf96a..91ba7c1d2612 100644
@@ -73,3 +73,8 @@ &bluetooth0 {
 	compatible = "pci14e4,5f72";
 	brcm,board-type = "apple,canary";
 };
+
+&sound {
+	compatible = "apple,j475-macaudio", "apple,j375-macaudio", "apple,macaudio";
+	model = "Mac Studio J475";
+};
arch/arm64/boot/dts/apple/t602x-j474-j475.dtsi +10 -0
index 926bb4ab77af..7f1faefcf9bb 100644
@@ -36,3 +36,13 @@ &hpm2 {
 &hpm3 {
 	interrupts = <44 IRQ_TYPE_LEVEL_LOW>;
 };
+
+&speaker {
+	interrupts-extended = <&pinctrl_ap 58 IRQ_TYPE_LEVEL_LOW>;
+	shutdown-gpios = <&pinctrl_ap 57 GPIO_ACTIVE_HIGH>;
+};
+
+&jack_codec {
+	interrupts-extended = <&pinctrl_ap 59 IRQ_TYPE_LEVEL_LOW>;
+	reset-gpios = <&pinctrl_nub 8 GPIO_ACTIVE_HIGH>;
+};
Signature · 1 line
2.55.0
#15 lore raw

Re: [PATCH 06/28] ALSA: dmaengine: Always terminate DMA when a PCM is closed

In reply to James Calligeros
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] ALSA: dmaengine: double-termination and dead code in __snd_dmaengine_pcm_close() --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] ALSA: dmaengine: double-termination and dead code in __snd_dmaengine_pcm_close() --

commit 6131d1de92af956678d470a7a7f214c9985a5ad4
Author: Hector Martin <[email protected]>

ALSA: dmaengine: Always terminate DMA when a PCM is closed

This commit updates __snd_dmaengine_pcm_close() to ensure that the DMA channel is properly terminated even if the PCM is closed while suspended.

Quoted 4 lines
sound/core/pcm_dmaengine.c +0 -0
index 1306b04be171a..e59b561b849d2 100644

[ ... ]

sound/core/pcm_dmaengine.c static void __snd_dmaengine_pcm_close(struct snd_pcm_substream *substream, · line 362

Quoted 9 lines
sound/core/pcm_dmaengine.c +5 -0
@@ -355,6 +355,11 @@ static void __snd_dmaengine_pcm_close(struct snd_pcm_substream *substream,
 	if (status == DMA_PAUSED)
 		dmaengine_terminate_async(prtd->dma_chan);
 
+	/*
+	 * The PCM might have been closed while suspended, which would
+	 * skip the STOP trigger. Make sure we terminate.
+	 */
+	dmaengine_terminate_async(prtd->dma_chan);

[Severity: Medium]
Does this result in a double-termination when the DMA status is DMA_PAUSED?

Since dmaengine_terminate_async(prtd->dma_chan) is now called unconditionally, the preceding dmaengine_tx_status() check and the initial termination call appear to be redundant.

Could this double-termination sequence cause unexpected behavior in DMA drivers that do not handle consecutive termination calls gracefully?

Quoted 1 line
sound/core/pcm_dmaengine.c +0 -0
 	dmaengine_synchronize(prtd->dma_chan);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
#2 lore raw

Re: [PATCH 01/28] dt-bindings: sound: Add Apple Macs sound peripherals

In reply to James Calligeros
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Low] dt-bindings: schema rejects tdm-slot properties due to additionalProperties: false - [Low]…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Low] dt-bindings: schema rejects tdm-slot properties due to additionalProperties: false
- [Low] dt-bindings: missing additionalProperties constraint in cpu and codec nodes --

commit 6dde9306ab23cf8705214300b5ab2897b3cef4f7
Author: Martin Povišer <[email protected]>

dt-bindings: sound: Add Apple Macs sound peripherals

This commit adds a device tree binding for Apple Silicon Macs machine-level integration of sound peripherals, starting with the M1 series.

Quoted 6 lines
Documentation/devicetree/bindings/sound/apple,macaudio.yaml new file +0 -0
new file mode 100644
index 0000000000000..bd844c9928c99
@@ -0,0 +1,235 @@

[ ... ]

Documentation/devicetree/bindings/sound/apple,macaudio.yaml line 101

Quoted 9 lines
Documentation/devicetree/bindings/sound/apple,macaudio.yaml new file +9 -0
+patternProperties:
+  "^dai-link(@[0-9a-f]+)?$":
+    description: |
+      Node for each sound peripheral such as the speaker array, headphones jack,
+      or microphone.
+    type: object
+    $ref: tdm-slot.yaml#
+
+    additionalProperties: false

[Severity: Low]
Does this block valid properties from tdm-slot.yaml? additionalProperties: false only evaluates properties explicitly defined in the local schema node. Since the referenced properties from tdm-slot.yaml are not considered evaluated, they will be incorrectly rejected. Should this be unevaluatedProperties: false instead?

Quoted 6 lines
Documentation/devicetree/bindings/sound/apple,macaudio.yaml new file +6 -0
+
+    properties:
+      reg:
+        maxItems: 1
+
+      link-name:

Documentation/devicetree/bindings/sound/apple,macaudio.yaml line 117

Quoted 10 lines
Documentation/devicetree/bindings/sound/apple,macaudio.yaml new file +10 -0
+        description: |
+          Name for the peripheral, expecting 'Speaker' or 'Speakers' if this is
+          the speaker array.
+        $ref: /schemas/types.yaml#/definitions/string
+
+      cpu:
+        type: object
+
+        properties:
+          sound-dai:

[Severity: Low]
Are we missing an additionalProperties: false constraint for the cpu object? Without it, any extraneous invalid properties or typos like sound_dai will silently pass schema validation.

Documentation/devicetree/bindings/sound/apple,macaudio.yaml line 130

Quoted 13 lines
Documentation/devicetree/bindings/sound/apple,macaudio.yaml new file +13 -0
+            description: |
+              DAI list with CPU-side I2S ports involved in this peripheral.
+            minItems: 1
+            maxItems: 2
+
+        required:
+          - sound-dai
+
+      codec:
+        type: object
+
+        properties:
+          sound-dai:

[Severity: Low]
Similar to the cpu object above, does the codec object also need an
additionalProperties: false constraint to catch typos and invalid properties?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#33 lore raw

Re: [PATCH 11/28] ASoC: ops: Introduce 'snd_soc_deactivate_kctl'

In reply to James Calligeros
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] ASoC: ops: snd_soc_deactivate_kctl() API contract violation when no controls match --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] ASoC: ops: snd_soc_deactivate_kctl() API contract violation when no controls match --

commit 5406f895c4457827c28646b6821be67f779d1939
Author: Martin Povišer <[email protected]>

ASoC: ops: Introduce 'snd_soc_deactivate_kctl'

This commit introduces snd_soc_deactivate_kctl() which allows machine drivers to activate or deactivate controls singly or by pattern. It is intended to be useful for driver fixups.

Quoted 4 lines
sound/soc/soc-ops.c +0 -0
index 2f91ee7946bb1..d35e24df891b6 100644

[ ... ]

Quoted 10 lines

+/**
+ * snd_soc_deactivate_kctl - Activate/deactivate controls matching a pattern
+ *
+ * @card: where to look for the controls
+ * @name: name pattern
+ * @active: non-zero to activate, zero to deactivate
+ *
+ * Return number of matching controls on success, else error.
+ * No controls need to match.
+ */

[Severity: Medium]
The kernel-doc explicitly states that no controls need to match, which implies calling this for an optional control shouldn't result in an error.

Quoted 13 lines
sound/soc/soc-ops.c +13 -0
+int snd_soc_deactivate_kctl(struct snd_soc_card *card,
+	const char *name, int active)
+{
+	struct snd_kcontrol *kctl;
+	int hits = 0;
+	int ret;
+
+	/* Sanity check for name */
+	if (unlikely(!name))
+		return -EINVAL;
+
+	list_for_each_entry(kctl, &card->snd_card->controls, list) {
+		if (!soc_control_matches(kctl, name))

sound/soc/soc-ops.c int snd_soc_limit_volume(struct snd_soc_card *card, const char *name, int max) · line 547

Quoted 10 lines
sound/soc/soc-ops.c +10 -0
+			continue;
+
+		ret = snd_ctl_activate_id(card->snd_card, &kctl->id, active);
+		if (ret < 0)
+			return ret;
+		hits++;
+	}
+
+	if (!hits)
+		return -EINVAL;

[Severity: Medium]
Does returning -EINVAL here violate the documentation above?

If a machine driver relies on the documentation to perform best-effort deactivation of optional hardware-variant controls, its initialization sequence could unexpectedly fail and abort the probe.

Should this return 0 instead when there are no matches?

Quoted 3 lines
sound/soc/soc-ops.c +3 -0
+
+	return hits;
+}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11
#18 lore raw

Re: [PATCH 07/28] ALSA: Support nonatomic dmaengine PCMs

In reply to James Calligeros
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] alsa: missing workqueue cancellation on stream stop in dmaengine PCM - [Medium] alsa: workqueue…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] alsa: missing workqueue cancellation on stream stop in dmaengine PCM
- [Medium] alsa: workqueue coalescing drops DMA completions for nonatomic PCMs --

commit 377967383b868c91dc9fcc127ab2f8b8e50a24e6
Author: Martin Povišer <[email protected]>

ALSA: Support nonatomic dmaengine PCMs

Add support for nonatomic dmaengine PCMs.

Quoted 4 lines
sound/core/pcm_dmaengine.c +0 -0
index e59b561b849d2..839ff2711f5e1 100644

[ ... ]

Quoted 10 lines
sound/core/pcm_dmaengine.c +6 -0
@@ -147,6 +149,24 @@ static void dmaengine_pcm_dma_complete(void *arg)
 	snd_pcm_period_elapsed(substream);
 }
 
+static void dmaengine_pcm_dma_complete_nonatomic(struct work_struct *wq)
+{
+	struct dmaengine_pcm_runtime_data *prtd = container_of(wq,
+							       struct dmaengine_pcm_runtime_data,
+							       complete_wq);
+	struct snd_pcm_substream *substream = prtd->substream;

sound/core/pcm_dmaengine.c static void dmaengine_pcm_dma_complete(void *arg) · line 167

Quoted 10 lines
sound/core/pcm_dmaengine.c +10 -0
+
+	dmaengine_pcm_dma_complete(substream);
+}
+
+static void dmaengine_pcm_dma_complete_nonatomic_callback(void *arg)
+{
+	struct snd_pcm_substream *substream = arg;
+	struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream);
+
+	schedule_work(&prtd->complete_wq);

[Severity: Medium]
Will this workqueue coalescing cause dropped DMA completions?

If multiple DMA period interrupts fire in quick succession before the system workqueue thread can run, schedule_work() will coalesce the requests so the work item only runs once.

dmaengine_pcm_dma_complete() blindly increments prtd->pos by exactly one period:

sound/core/pcm_dmaengine.c:dmaengine_pcm_dma_complete() {
	new_pos = prtd->pos + snd_pcm_lib_period_bytes(substream);
	if (new_pos >= snd_pcm_lib_buffer_bytes(substream))
		new_pos = 0;
	prtd->pos = new_pos;
}

Could this cause prtd->pos to permanently lag behind the actual hardware position if events are coalesced?

Quoted 6 lines
sound/core/pcm_dmaengine.c +2 -0
+}
+
 static int dmaengine_pcm_prepare_and_submit(struct snd_pcm_substream *substream)
 {
 	struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream);

sound/core/pcm_dmaengine.c static int dmaengine_pcm_prepare_and_submit(struct snd_pcm_substream *substream) · line 196

Quoted 9 lines
sound/core/pcm_dmaengine.c +5 -1
@@ -169,7 +189,11 @@ static int dmaengine_pcm_prepare_and_submit(struct snd_pcm_substream *substream)
 	if (!desc)
 		return -ENOMEM;
 
-	desc->callback = dmaengine_pcm_dma_complete;
+	if (substream->pcm->nonatomic)
+		desc->callback = dmaengine_pcm_dma_complete_nonatomic_callback;
+	else
+		desc->callback = dmaengine_pcm_dma_complete;
+

[Severity: High]
Is a workqueue cancellation missing when the stream stops?

If a DMA completion interrupt fires just before SNDRV_PCM_TRIGGER_STOP, it will schedule complete_wq.

snd_dmaengine_pcm_sync_stop() waits for DMA callbacks via dmaengine_synchronize(), but doesn't cancel the work item:

sound/core/pcm_dmaengine.c:snd_dmaengine_pcm_sync_stop() {
	status = dmaengine_tx_status(prtd->dma_chan, prtd->cookie, &state);
	if (status != DMA_PAUSED)
		dmaengine_synchronize(prtd->dma_chan);

	return 0;
}

Could this leaked work execute after the stream is prepared or restarted, erroneously advancing prtd->pos and permanently corrupting the position state for the new stream cycle?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
#36 lore raw

Re: [PATCH 12/28] ASoC: ops: Introduce 'soc_set_enum_kctl'

In reply to James Calligeros
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] ALSA: uninitialized struct snd_ctl_elem_value exposes stack memory and triggers OOB access --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] ALSA: uninitialized struct snd_ctl_elem_value exposes stack memory and triggers OOB access --

commit 39b7a1686876eb2be8da2cbd7401a6040c476ac1
Author: Martin Povišer <[email protected]>

ASoC: ops: Introduce 'soc_set_enum_kctl'

This commit introduces a new function to set enumerated controls to desired values. It allows setting either a single control or many controls in bulk by pattern, and is intended for use by machine drivers during fixup_controls.

Quoted 4 lines
sound/soc/soc-ops.c +0 -0
index d35e24df891b6..dc27d1c409abb 100644

[ ... ]

sound/soc/soc-ops.c int snd_soc_deactivate_kctl(struct snd_soc_card *card, · line 556

Quoted 8 lines
sound/soc/soc-ops.c +4 -0
@@ -550,6 +550,76 @@ int snd_soc_deactivate_kctl(struct snd_soc_card *card,
 }
 EXPORT_SYMBOL_GPL(snd_soc_deactivate_kctl);
 
+static int soc_set_enum_kctl(struct snd_kcontrol *kctl, const char *strval)
+{
+	struct snd_ctl_elem_value value;
+	struct snd_ctl_elem_info info;

[Severity: High]
Is it safe to allocate these structures on the stack without zero-initialization?

The value and info structures are roughly 1.5KB in total. While info is typically overwritten by the kctl->info() call below, fields like value.id (which includes numid, index, and name) are left containing uninitialized stack memory.

Quoted 3 lines
sound/soc/soc-ops.c +3 -0
+	int sel, i, ret;
+
+	ret = kctl->info(kctl, &info);

[ ... ]

sound/soc/soc-ops.c int snd_soc_deactivate_kctl(struct snd_soc_card *card, · line 582

Quoted 7 lines
sound/soc/soc-ops.c +7 -0
+	if (sel == info.value.enumerated.items)
+		return -EINVAL;
+
+	for (i = 0; i < info.count; i++)
+		value.value.enumerated.item[i] = sel;
+
+	return kctl->put(kctl, &value);

[Severity: High]
Could passing this uninitialized value structure to the put callback cause out-of-bounds memory accesses?

When kctl->put() is invoked, drivers using ALSA helper macros like snd_ctl_get_ioffidx() or reading id.name via strstr() will use this garbage data as array indices or string matches.

This could directly lead to out-of-bounds memory accesses and kernel panics when machine drivers use this exported API to set enumerated control values during initialization.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=12
#42 lore raw

Re: [PATCH 15/28] ASoC: tas2764: Set up V/ISENSE on codec probe

In reply to James Calligeros
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] ASoC: tas2764: flawed V/I sense disabled logic causes inadvertent enable --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] ASoC: tas2764: flawed V/I sense disabled logic causes inadvertent enable --

commit ff9219a20060d38cf8689dacfe0f48323c8c8566
Author: James Calligeros <[email protected]>

ASoC: tas2764: Set up V/ISENSE on codec probe

This commit moves the setup of V/ISENSE to the codec probe rather than configuring it on every hw_params or TDM slot call. This ensures it is configured at the same time as the rest of the codec.

Quoted 4 lines
sound/soc/codecs/tas2764.c +0 -0
index 6654100ac91d1..39372d0446d06 100644

[ ... ]

Quoted 8 lines
sound/soc/codecs/tas2764.c +3 -1
@@ -499,15 +470,26 @@ static int tas2764_set_dai_tdm_slot(struct snd_soc_dai *dai,
 	if (ret < 0)
 		return ret;
 
-	ret = snd_soc_component_update_bits(component, TAS2764_TDM_CFG5,
+	return 0;
+}
+

sound/soc/codecs/tas2764.c static int tas2764_set_dai_tdm_slot(struct snd_soc_dai *dai, · line 484

Quoted 10 lines
sound/soc/codecs/tas2764.c +8 -1
+static int tas2764_set_visense(struct tas2764_priv *tas2764, int vslot, int islot)
+{
+	int ret;
+
+	ret = snd_soc_component_update_bits(tas2764->component, TAS2764_TDM_CFG5,
+					    TAS2764_TDM_CFG5_VSNS_ENABLE |
 					    TAS2764_TDM_CFG5_50_MASK,
-					    tas2764->v_sense_slot);
+					    TAS2764_TDM_CFG5_VSNS_ENABLE |
+					    vslot);

[Severity: Medium]
Does this code inadvertently enable the sense slot and assign it to the maximum value if vslot is -1?

A bitwise OR with a -1 value yields 0xffffffff. When applied with the bitmask in snd_soc_component_update_bits(), this will turn on the enable bit and set the slot to the maximum value, which can lead to a TDM bus collision and audio corruption.

Quoted 12 lines
sound/soc/codecs/tas2764.c +4 -2
 	if (ret < 0)
 		return ret;
 
-	ret = snd_soc_component_update_bits(component, TAS2764_TDM_CFG6,
+	ret = snd_soc_component_update_bits(tas2764->component, TAS2764_TDM_CFG6,
+					    TAS2764_TDM_CFG6_ISNS_ENABLE |
 					    TAS2764_TDM_CFG6_50_MASK,
-					    tas2764->i_sense_slot);
+					    TAS2764_TDM_CFG6_ISNS_ENABLE |
+					    islot);
 	if (ret < 0)
 		return ret;

[ ... ]

sound/soc/codecs/tas2764.c static int tas2764_codec_probe(struct snd_soc_component *component) · line 807

Quoted 10 lines
sound/soc/codecs/tas2764.c +2 -4
@@ -821,15 +803,12 @@ static int tas2764_codec_probe(struct snd_soc_component *component)
 			dev_warn(tas2764->dev, "failed to request IRQ: %d\n", ret);
 	}
 
-	ret = snd_soc_component_update_bits(tas2764->component, TAS2764_TDM_CFG5,
-					    TAS2764_TDM_CFG5_VSNS_ENABLE, 0);
-	if (ret < 0)
-		return ret;
+	if (tas2764->v_sense_slot != -1 || tas2764->i_sense_slot != -1) {
+		ret = tas2764_set_visense(tas2764, tas2764->v_sense_slot, tas2764->i_sense_slot);

[Severity: Medium]
If a user configures one of the sense slots to -1 in the device tree to disable it while keeping the other enabled, will this logical OR evaluate to true and cause the disabled slot value (-1) to be passed to tas2764_set_visense() above?

Quoted 11 lines
sound/soc/codecs/tas2764.c +3 -4
+		if (ret < 0)
+			return ret;
+	}
 
-	ret = snd_soc_component_update_bits(tas2764->component, TAS2764_TDM_CFG6,
-					    TAS2764_TDM_CFG6_ISNS_ENABLE, 0);
-	if (ret < 0)
-		return ret;
 
 	switch (tas2764->devid) {
 	case DEVID_SN012776:
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=15
#21 lore raw

Re: [PATCH 08/28] ALSA: control: Add kcontrol callbacks for lock/unlock

In reply to James Calligeros
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] ALSA: control: Missing element context in lock/unlock callbacks - [High] ALSA: control: Missing…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] ALSA: control: Missing element context in lock/unlock callbacks
- [High] ALSA: control: Missing unlock callback invocation on control removal --

commit 432b3659bebdece13c2a2b132af2a88df66f8e1d
Author: Hector Martin <[email protected]>

ALSA: control: Add kcontrol callbacks for lock/unlock

This commit introduces lock and unlock callbacks for ALSA kcontrols, allowing drivers to implement custom policy when controls are locked or unlocked. It is primarily intended for implementing volume safety controls where user-space processes must complete a handshake to increase volumes.

Quoted 5 lines
include/sound/control.h +0 -0
index 909db0d0485df..6b3ef6be51003 100644

include/sound/control.h line 23

Quoted 9 lines
include/sound/control.h +3 -0
@@ -15,9 +15,12 @@
 #define snd_kcontrol_chip(kcontrol) ((kcontrol)->private_data)
 
 struct snd_kcontrol;
+struct snd_ctl_file;
 typedef int (snd_kcontrol_info_t) (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_info * uinfo);
 typedef int (snd_kcontrol_get_t) (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol);
 typedef int (snd_kcontrol_put_t) (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol);
+typedef int (snd_kcontrol_lock_t) (struct snd_kcontrol * kcontrol, struct snd_ctl_file *owner);
+typedef void (snd_kcontrol_unlock_t) (struct snd_kcontrol * kcontrol);

[Severity: High]
Does omitting the element index or ID from the callback signatures prevent drivers from applying per-element policy for multi-element controls, as they cannot deduce which specific element is being locked or unlocked?

Quoted 8 lines
include/sound/control.h +0 -0
 typedef int (snd_kcontrol_tlv_rw_t)(struct snd_kcontrol *kcontrol,
 				    int op_flag, /* SNDRV_CTL_TLV_OP_XXX */
[ ... ]
sound/core/control.c +0 -0
index 4199342d4ffe0..c8aab9abd306a 100644

sound/core/control.c static int snd_ctl_release(struct inode *inode, struct file *file) · line 133

Quoted 9 lines
sound/core/control.c +4 -1
@@ -126,10 +126,12 @@ static int snd_ctl_release(struct inode *inode, struct file *file)
 	scoped_guard(rwsem_write, &card->controls_rwsem) {
 		list_for_each_entry(control, &card->controls, list)
 			for (idx = 0; idx < control->count; idx++)
-				if (control->vd[idx].owner == ctl)
+				if (control->vd[idx].owner == ctl) {
 					control->vd[idx].owner = NULL;
+					if (control->unlock)
+						control->unlock(control);
+				}

[Severity: High]
Since this loop does not provide the element index to the unlock callback, does it result in identical, indistinguishable unlock calls being sent to the driver for each locked element within the same control? Could this confuse the driver's internal state machine?

Quoted 5 lines
sound/core/control.c +0 -0
 	}
 	snd_fasync_free(ctl->fasync);
 	snd_ctl_empty_read_queue(ctl);
[ ... ]

sound/core/control.c static int snd_ctl_elem_lock(struct snd_ctl_file *file, · line 1499

Quoted 9 lines
sound/core/control.c +6 -0
@@ -1487,6 +1491,12 @@ static int snd_ctl_elem_lock(struct snd_ctl_file *file,
 	vd = &kctl->vd[snd_ctl_get_ioff(kctl, &id)];
 	if (vd->owner)
 		return -EBUSY;
+
+	if (kctl->lock) {
+		int err = kctl->lock(kctl, file);
+		if (err < 0)
+			return err;
+	}

[Severity: High]
Are drivers able to correctly process this lock request? It invokes the lock callback without passing the idx or id of the specific element being locked.

sound/core/control.c static int snd_ctl_elem_lock(struct snd_ctl_file *file, · line 1502

Quoted 3 lines
sound/core/control.c +0 -0
 	vd->owner = file;
 	return 0;
 }

Additionally, looking at the control removal process in the existing codebase that interacts with the new lock state:

sound/core/control.c:__snd_ctl_remove() {
    ...
	for (idx = 0; idx < kcontrol->count; idx++)
		snd_ctl_notify_one(card, SNDRV_CTL_EVENT_MASK_REMOVE, kcontrol, idx);
	snd_ctl_free_one(kcontrol);
	return 0;
}

[Severity: High]
When a control is dynamically added and then removed, or when a device is hot-unplugged, this function frees the control memory without checking for active locks or invoking the unlock callback for locked elements.

Could this lead to driver resource leaks or hardware state not being properly restored if userspace holds a lock during removal?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
#28 lore raw

Re: [PATCH 10/28] ASoC: ops: Accept patterns in snd_soc_limit_volume

In reply to James Calligeros
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] ASoC: ops: Data race and UAF in snd_soc_limit_volume list traversal - [High] ASoC: ops: Type…

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] ASoC: ops: Data race and UAF in snd_soc_limit_volume list traversal
- [High] ASoC: ops: Type confusion and NULL pointer dereference in soc_limit_volume
- [High] ASoC: ops: snd_soc_limit_volume API breakage causes audio initialization failure --

commit 71061718845772d7571d727c356dc0cbae99856e
Author: Martin Povišer <[email protected]>

ASoC: ops: Accept patterns in snd_soc_limit_volume

This patch modifies snd_soc_limit_volume() to accept wildcard patterns, allowing it to apply limits to multiple matching controls at once. It also returns the number of matching controls on success instead of 0.

Quoted 4 lines
sound/soc/soc-ops.c +0 -0
index e572b05840b48..2f91ee7946bb1 100644

[ ... ]

Quoted 23 lines
sound/soc/soc-ops.c +8 -3
@@ -445,31 +468,47 @@ static int soc_limit_volume(struct snd_kcontrol *kctl, int max)
 }
 
 /**
- * snd_soc_limit_volume - Set new limit to an existing volume control.
+ * snd_soc_limit_volume - Set new limit to existing volume controls.
  *
  * @card: where to look for the control
- * @name: Name of the control
+ * @name: name pattern
  * @max: new maximum limit
  *
- * Return 0 for success, else error.
+ * Finds controls matching the given name (which can be either a name
+ * verbatim, or a pattern starting with the wildcard '*') and sets
+ * a platform volume limit on them.
+ *
+ * Return number of matching controls on success, else error. At least
+ * one control needs to match the pattern.
  */
 int snd_soc_limit_volume(struct snd_soc_card *card, const char *name, int max)
 {
 	struct snd_kcontrol *kctl;

sound/soc/soc-ops.c static int soc_limit_volume(struct snd_kcontrol *kctl, int max) · line 494

Quoted 10 lines
sound/soc/soc-ops.c +3 -2
+	int hits = 0;
+	int ret;
 
 	/* Sanity check for name */
 	if (unlikely(!name))
 		return -EINVAL;
 
-	kctl = snd_soc_card_get_kcontrol(card, name);
-	if (!kctl) {
+	list_for_each_entry(kctl, &card->snd_card->controls, list) {

[Severity: High]
Does this locklessly traverse the ALSA control list?

If a local user dynamically adds or removes ALSA user controls via SNDRV_CTL_IOCTL_ELEM_ADD or SNDRV_CTL_IOCTL_ELEM_REMOVE, couldn't traversing the list here without holding card->controls_rwsem or card->controls_rwlock result in memory corruption and a kernel panic?

sound/soc/soc-ops.c static int soc_limit_volume(struct snd_kcontrol *kctl, int max) · line 498

Quoted 4 lines
sound/soc/soc-ops.c +4 -0
+		if (!soc_control_matches(kctl, name))
+			continue;
+
+		ret = soc_limit_volume(kctl, max);

[Severity: High]
Since the wildcard matching can now match dynamically created user ALSA controls, is it safe to pass kctl directly to soc_limit_volume() without verifying it is actually a mixer control?

For user controls, kctl->private_value is NULL. When soc_limit_volume() unconditionally casts this to a struct soc_mixer_control pointer and accesses mc->max or mc->platform_max:

soc_limit_volume(struct snd_kcontrol *kctl, int max)

{
	struct soc_mixer_control *mc =
		(struct soc_mixer_control *)kctl->private_value;

	if (max <= 0 || max > mc->max - mc->min)
		...

won't this result in a NULL pointer dereference?

Quoted 4 lines
sound/soc/soc-ops.c +4 -0
+		if (ret < 0)
+			return ret;
+		hits++;
+	}

sound/soc/soc-ops.c static int soc_limit_volume(struct snd_kcontrol *kctl, int max) · line 511

Quoted 10 lines
sound/soc/soc-ops.c +3 -1
+
+	if (!hits) {
 		/* Some cards blindly add limits for multiple variants. */
 		dev_dbg(card->dev, "Volume limit for unknown control '%s'\n",
 			name);
 		return -EINVAL;
 	}
 
-	return soc_limit_volume(kctl, max);
+	return hits;

[Severity: High]
Could changing the success return value from 0 to a positive integer break existing callers?

Callers like asoc_sdw_cs35l56_volume_limit() interpret any non-zero return value as an error, propagating it and bypassing further initialization steps like snd_soc_dapm_add_routes().

Quoted 2 lines
sound/soc/soc-ops.c +0 -0
 }
 EXPORT_SYMBOL_GPL(snd_soc_limit_volume);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
#45 lore raw

Re: [PATCH 16/28] ASoC: apple: Add macaudio machine driver

In reply to James Calligeros
Thank you for your contribution! Sashiko AI review found 8 potential issue(s) to consider: - [High] macaudio: UAF due to missing lock_update_work cancellation on driver unbind - [High] macaudio…

Thank you for your contribution! Sashiko AI review found 8 potential issue(s) to consider:
- [High] macaudio: UAF due to missing lock_update_work cancellation on driver unbind
- [High] macaudio: list corruption traversing snd_card->controls without controls_rwsem
- [Medium] macaudio: spurious volume lock due to timeout workqueue race
- [Medium] macaudio: missing mutex lock in macaudio_slk_unlock causes data race
- [Medium] macaudio: non-atomic bitwise operations on bes_active causes lost triggers
- [Medium] macaudio: OF node reference leaks on error paths and driver unbind
- [Medium] macaudio: TOCTOU race on speaker_volume_was_locked outside mutex
- [Low] macaudio: bitwise truncation of u64 bes_active on 32-bit COMPILE_TEST --

commit c31fe439d1e39b1d15e314167ccc57d6863e8d4b
Author: Martin Povišer <[email protected]>

ASoC: apple: Add macaudio machine driver

Apple Silicon Macs have a complex audio subsystem consisting of an I2S peripheral (MCA) and multiple codecs of various models and capabilities. Some machines have a basic mono speaker with hardware downmix, while others have a very intricate stereo system consisting of multiple codecs and drivers per L/R channel. Some machines report voice coil voltage and current information back to the SoC, and others do not. All machines have a headset jack.

Quoted 4 lines
sound/soc/apple/macaudio.c new file +0 -0
new file mode 100644

[ ... ]

Quoted 6 lines
sound/soc/apple/macaudio.c new file +6 -0
+static void macaudio_vlimit_update(struct macaudio_snd_data *ma)
+{
+	int i;
+	bool unlock = true;
+	struct snd_kcontrol *kctl;
+	const char *reason;

[ ... ]

sound/soc/apple/macaudio.c line 293

Quoted 2 lines
sound/soc/apple/macaudio.c new file +2 -0
+	/* Check that *every* limited control is locked by the same owner */
+	list_for_each_entry(kctl, &ma->card.snd_card->controls, list) {

[Severity: High]
Can this list traversal be corrupted by concurrent modifications?

The ALSA sound card controls list (&ma->card.snd_card->controls) is iterated here, but neither this driver nor snd_soc_limit_volume() acquire the ALSA controls_rwsem lock.

Since macaudio_vlimit_update() is called asynchronously from background workqueues, unprivileged userspace could concurrently add or remove controls (e.g., via SNDRV_CTL_IOCTL_ELEM_ADD) under a write lock, mutating the list while it is being traversed here.

Quoted 2 lines
sound/soc/apple/macaudio.c new file +2 -0
+		if (!snd_soc_control_matches(kctl, volume_control_names[ma->cfg->amp]))
+			continue;

[ ... ]

sound/soc/apple/macaudio.c line 382

Quoted 9 lines
sound/soc/apple/macaudio.c new file +9 -0
+static void macaudio_vlimit_timeout_work(struct work_struct *wrk)
+{
+	struct macaudio_snd_data *ma = container_of(to_delayed_work(wrk),
+						    struct macaudio_snd_data, lock_timeout_work);
+
+	mutex_lock(&ma->volume_lock_mutex);
+
+	ma->speaker_lock_remain = 0;
+	macaudio_vlimit_update(ma);

[Severity: Medium]
Could this worker blindly override a valid ping from userspace?

If macaudio_slk_put() executes concurrently, it calls cancel_delayed_work() while holding ma->volume_lock_mutex. If the timeout worker is already waiting for the mutex, cancel_delayed_work() returns false.

Once macaudio_slk_put() extends the timeout and releases the mutex, the blocked worker thread will immediately acquire it and blindly zero the timeout here, overriding the extension and locking the volume prematurely.

Quoted 3 lines
sound/soc/apple/macaudio.c new file +3 -0
+
+	mutex_unlock(&ma->volume_lock_mutex);
+}

[ ... ]

Quoted 2 lines
sound/soc/apple/macaudio.c new file +2 -0
+static int macaudio_parse_of(struct macaudio_snd_data *ma)
+{

[ ... ]

sound/soc/apple/macaudio.c line 685

Quoted 12 lines
sound/soc/apple/macaudio.c new file +12 -0
+		for (be_index = 0; be_index < num_bes; be_index++) {
+			/*
+			 * Set initial link name to be overwritten by a BE-specific
+			 * name later so that we can use at least use the provisional
+			 * name in error messages.
+			 */
+			link->name = link_name;
+
+			ret = macaudio_parse_of_be_dai_link(ma, link, be_index,
+							    ncodecs_per_cpu, cpu, codec);
+			if (ret)
+				goto err_free;

[Severity: Medium]
Does this cleanup path skip partially populated links?

If macaudio_parse_of_be_dai_link() fails, the code jumps to err_free. However, num_links is only incremented after the be_index loop finishes. This means the cleanup loop below will fail to drop references for the codecs and cpus that were already parsed in the current, incomplete batch.

Additionally, macaudio_snd_platform_remove() doesn't seem to release any of these OF node references when the driver is unbound.

Quoted 2 lines
sound/soc/apple/macaudio.c new file +2 -0
+
+			link_props->is_speakers = speakers;

[ ... ]

Quoted 2 lines
sound/soc/apple/macaudio.c new file +2 -0
+		num_links += num_bes;
+	}

[ ... ]

Quoted 19 lines
sound/soc/apple/macaudio.c new file +19 -0
+err_free:
+	of_node_put(codec);
+	of_node_put(cpu);
+	of_node_put(np);
+
+	if (!card->dai_link)
+		return ret;
+
+	for (i = 0; i < num_links; i++) {
+		/*
+		 * TODO: If we don't go through this path are the references
+		 * freed inside ASoC?
+		 */
+		snd_soc_of_put_dai_link_codecs(&card->dai_link[i]);
+		snd_soc_of_put_dai_link_cpus(&card->dai_link[i]);
+	}
+
+	return ret;
+}

[ ... ]

sound/soc/apple/macaudio.c line 944

Quoted 12 lines
sound/soc/apple/macaudio.c new file +12 -0
+static int macaudio_be_trigger(struct snd_pcm_substream *substream, int cmd)
+{
+	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
+	struct macaudio_snd_data *ma = snd_soc_card_get_drvdata(rtd->card);
+	struct macaudio_link_props *props = &ma->link_props[rtd->dai_link->id];
+
+	if (props->is_speakers && substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+		switch (cmd) {
+		case SNDRV_PCM_TRIGGER_START:
+		case SNDRV_PCM_TRIGGER_RESUME:
+		case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+			ma->bes_active |= BIT(rtd->dai_link->id);

[Severity: Medium]
Will these non-atomic bitwise operators drop updates to ma->bes_active?

ALSA DPCM allows different frontend PCMs to concurrently trigger their respective backend DAI links on different CPUs. Using standard bitwise assignment (|= and &= ~) creates a read-modify-write data race between concurrent triggers, which could cause lost updates.

sound/soc/apple/macaudio.c line 949

Quoted 5 lines
sound/soc/apple/macaudio.c new file +5 -0
+			break;
+		case SNDRV_PCM_TRIGGER_SUSPEND:
+		case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+		case SNDRV_PCM_TRIGGER_STOP:
+			ma->bes_active &= ~BIT(rtd->dai_link->id);

[Severity: Low]
Does this bitwise NOT clear the upper 32 bits of ma->bes_active?

On 32-bit architectures, BIT() evaluates to a 32-bit unsigned long, making the inverted mask also 32-bit. When implicitly zero-extended to u64 for the assignment, it would effectively clear bits 32-63 of ma->bes_active.

While this platform is 64-bit, this truncation could still happen when the driver is built under COMPILE_TEST. Using BIT_ULL() would prevent this.

sound/soc/apple/macaudio.c line 955

Quoted 6 lines
sound/soc/apple/macaudio.c new file +6 -0
+			break;
+		default:
+			return -EINVAL;
+		}
+
+		schedule_work(&ma->lock_update_work);

[Severity: High]
Does this code leave ma->lock_update_work unmanaged before devres teardown?

During card unregistration, any running PCM streams are stopped, which invokes macaudio_be_trigger() with SNDRV_PCM_TRIGGER_STOP. That trigger forcefully queues the lock_update_work.

If we don't call cancel_work_sync(&ma->lock_update_work) in the device remove hook, the queued work might execute after the devres-managed ma structure has already been freed, which would lead to a use-after-free.

Quoted 4 lines
sound/soc/apple/macaudio.c new file +4 -0
+	}
+
+	return 0;
+}

[ ... ]

sound/soc/apple/macaudio.c line 1420

Quoted 13 lines
sound/soc/apple/macaudio.c new file +13 -0
+static int macaudio_slk_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *uvalue)
+{
+	struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
+	struct macaudio_snd_data *ma = snd_soc_card_get_drvdata(card);
+
+	if (!ma->speaker_lock_owner)
+		return -EPERM;
+
+	if (uvalue->value.integer.value[0] != SPEAKER_MAGIC_VALUE)
+		return -EINVAL;
+
+	/* Serves as a notification that the lock was lost at some point */
+	if (ma->speaker_volume_was_locked) {

[Severity: Medium]
Can this check race with the timeout worker?

Since ma->speaker_volume_was_locked is checked and reset before acquiring the volume_lock_mutex, a background worker could lock the volume and set this flag to true just after this lockless check finishes.

If that happens, this function will bypass returning -ETIMEDOUT and proceed to blindly reset the timeout, hiding the timeout event from userspace.

Quoted 11 lines
sound/soc/apple/macaudio.c new file +11 -0
+		ma->speaker_volume_was_locked = false;
+		return -ETIMEDOUT;
+	}
+
+	mutex_lock(&ma->volume_lock_mutex);
+
+	cancel_delayed_work(&ma->lock_timeout_work);
+
+	ma->speaker_lock_remain = ms_to_ktime(SPEAKER_LOCK_TIMEOUT);
+	ma->speaker_lock_timeout = ktime_add(ktime_get(), ma->speaker_lock_remain);
+	macaudio_vlimit_update(ma);

[ ... ]

sound/soc/apple/macaudio.c line 1484

Quoted 8 lines
sound/soc/apple/macaudio.c new file +8 -0
+static void macaudio_slk_unlock(struct snd_kcontrol *kcontrol)
+{
+	struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
+	struct macaudio_snd_data *ma = snd_soc_card_get_drvdata(card);
+
+	ma->speaker_lock_owner = NULL;
+	ma->speaker_lock_timeout = 0;
+	macaudio_vlimit_update(ma);

[Severity: Medium]
Should this block be protected by ma->volume_lock_mutex?

This function modifies shared state (ma->speaker_lock_owner and ma->speaker_lock_timeout) and calls macaudio_vlimit_update() without acquiring the mutex. All other functions interacting with this state (such as macaudio_slk_lock or macaudio_vlimit_timeout_work) rely on this mutex for synchronization.

Quoted 1 line

+}

[ ... ]

Quoted 6 lines
sound/soc/apple/macaudio.c new file +6 -0
+static void macaudio_snd_platform_remove(struct platform_device *pdev)
+{
+	struct macaudio_snd_data *ma = dev_get_drvdata(&pdev->dev);
+
+	cancel_delayed_work_sync(&ma->lock_timeout_work);
+}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=16
#59 lore raw

Re: [PATCH 21/28] arm64: dts: apple: t8112-j413: Add speaker/headset jack nodes

In reply to James Calligeros
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Critical] ASoC: macaudio: hardware damage due to missing tweeter safety limits --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Critical] ASoC: macaudio: hardware damage due to missing tweeter safety limits --

commit 9fe19e1d62cebe58a30bdc3d79379ba02c88819c
Author: James Calligeros <[email protected]>

arm64: dts: apple: t8112-j413: Add speaker/headset jack nodes

The M2 MacBook Air integrates Apple-specific variants of the TI TAS2764 and Cirrus CS42L42. Add these nodes and advertise them to the machine driver via the sound node.

Quoted 5 lines
arch/arm64/boot/dts/apple/t8112-j413.dts +0 -0
index 7ccfceb080930..38d0e33c701c5 100644
@@ -92,4 +92,105 @@ &fpwm1 {

[ ... ]

arch/arm64/boot/dts/apple/t8112-j413.dts &fpwm1 { · line 142

Quoted 7 lines
arch/arm64/boot/dts/apple/t8112-j413.dts +7 -0
+	speaker_right_tweet: codec@3c {
+		compatible = "ti,sn012776", "ti,tas2764";
+		reg = <0x3c>;
+		interrupts-extended = <&pinctrl_ap 11 IRQ_TYPE_LEVEL_LOW>;
+		shutdown-gpios = <&pinctrl_ap 88 GPIO_ACTIVE_HIGH>;
+		#sound-dai-cells = <0>;
+		sound-name-prefix = "Right Tweet";

[Severity: Critical]
Does this prefix bypass the mandatory safety limits for the right tweeter?

The machine driver configures an 800 Hz high-pass filter and a -20dB volume limit by passing the "* Tweeter " wildcard pattern to macaudio_set_speaker():

sound/soc/apple/macaudio.c:macaudio_fixup_controls() {
	...
	CHECK(macaudio_set_speaker, "* Tweeter ", true, 0);
	...
}

Since the left tweeter is named "Left Tweeter", the wildcard match returns 1 hit. The driver checks for a minimum of 1 hit, so it does not report an error and the probe succeeds.

However, "Right Tweet" will silently fail to match the "* Tweeter " pattern, leaving its controls unconfigured.

Could this lead to physical hardware damage by allowing unfiltered, full-amplitude bass frequencies to reach the right tweeter during playback?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=21
#52 lore raw

Re: [PATCH 17/28] arm64: dts: apple: t8103-j274: Add speaker/headset jack nodes

In reply to James Calligeros
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider: - [Medium] dts: missing required regulators in cs42l83 node - [Low] dts: duplicate &i2c2 node definition…

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [Medium] dts: missing required regulators in cs42l83 node
- [Low] dts: duplicate &i2c2 node definition
- [Low] dts: invalid compatible string array for tas2770
- [Low] dts: undocumented properties in cs42l83 node
- [Low] dts: missing addressing properties in sound node
--

commit 05517f4fbd6ba283bbb6aac224c8afd505d5bf52
Author: James Calligeros <[email protected]>
arm64: dts: apple: t8103-j274: Add speaker/headset jack nodes

This commit introduces speaker and headset jack nodes for the M1 Mac mini. It defines configurations for the TI TAS2770 and Cirrus CS42L42 audio codecs and links them to the machine driver.

Quoted 4 lines
arch/arm64/boot/dts/apple/t8103-j274.dts +0 -0
index 1212852251e07..4b30f08eaac01 100644

[ ... ]

arch/arm64/boot/dts/apple/t8103-j274.dts &i2c2 { · line 83

Quoted 6 lines
arch/arm64/boot/dts/apple/t8103-j274.dts +6 -0
+/* Audio codecs */
+&i2c1 {
+	status = "okay";
+
+	speaker: codec@31 {
+		compatible = "ti,tas5770l", "ti,tas2770";

[Severity: Low]
Will this compatible string array fail schema validation?

The ti,tas2770.yaml schema restricts the compatible property to a single enum of either "ti,tas2770" or "ti,tas5770l". Providing an array instead of a single string causes a dtbs_check validation error.

arch/arm64/boot/dts/apple/t8103-j274.dts &i2c2 { · line 96

Quoted 13 lines
arch/arm64/boot/dts/apple/t8103-j274.dts +13 -0
+		reg = <0x31>;
+		interrupts-extended = <&pinctrl_ap 182 IRQ_TYPE_LEVEL_LOW>;
+		shutdown-gpios = <&pinctrl_ap 181 GPIO_ACTIVE_HIGH>;
+		#sound-dai-cells = <0>;
+		ti,imon-slot-no = <0>;
+		ti,vmon-slot-no = <2>;
+	};
+};
+
+&i2c2 {
+	status = "okay";
+
+	jack_codec: codec@48 {

[Severity: Low]
Is there a reason to redefine &i2c2 here?

The t8103-j274.dts file already contains an &i2c2 block earlier in the file. Appending another &i2c2 block at the end of the file is redundant; the jack_codec child could be added directly to the existing &i2c2 block.

[Severity: Medium]
Are there missing regulator supplies for this codec?

The cirrus,cs42l42.yaml binding explicitly requires VP-supply, VCP-supply, VD_FILT-supply, VL-supply, and VA-supply. These are absent from this node, which can lead to schema validation failures and driver probe failures if dummy regulators are disabled.

arch/arm64/boot/dts/apple/t8103-j274.dts &i2c2 { · line 102

Quoted 6 lines
arch/arm64/boot/dts/apple/t8103-j274.dts +6 -0
+		compatible = "cirrus,cs42l83";
+		reg = <0x48>;
+		interrupts-extended = <&pinctrl_ap 183 IRQ_TYPE_LEVEL_LOW>;
+		reset-gpios = <&pinctrl_nub 11 GPIO_ACTIVE_HIGH>;
+		#sound-dai-cells = <0>;
+		sound-name-prefix = "Jack";

[Severity: Low]
Do these generic audio properties pass schema checks?

The cirrus,cs42l42.yaml binding specifies additionalProperties: false but does not include #sound-dai-cells or sound-name-prefix, nor does it include a reference to dai-common.yaml. Their presence will trigger validation errors.

arch/arm64/boot/dts/apple/t8103-j274.dts &i2c2 { · line 110

Quoted 8 lines
arch/arm64/boot/dts/apple/t8103-j274.dts +8 -0
+		cirrus,ts-inv = <1>;
+	};
+};
+
+/ {
+	sound: sound {
+		compatible = "apple,j274-macaudio", "apple,macaudio";
+		model = "Mac mini J274";

[Severity: Low]
Should this parent node declare #address-cells and #size-cells?

Since the children dai-link nodes use unit addresses, standard DT syntax and the apple,macaudio.yaml binding require the parent sound node to specify these properties to avoid compiler warnings.

arch/arm64/boot/dts/apple/t8103-j274.dts

Quoted 2 lines
arch/arm64/boot/dts/apple/t8103-j274.dts +2 -0
+
+		dai-link@0 {

[Severity: Low]
Does this node require a reg property?

Using a unit address without a matching reg property violates device tree specification and causes compiler warnings.

arch/arm64/boot/dts/apple/t8103-j274.dts &i2c2 { · line 124

Quoted 12 lines
arch/arm64/boot/dts/apple/t8103-j274.dts +12 -0
+			link-name = "Speaker";
+
+			codec {
+				sound-dai = <&speaker>;
+			};
+
+			cpu {
+				sound-dai = <&mca 0>;
+			};
+		};
+
+		dai-link@1 {

[Severity: Low]
Similarly, does this dai-link need a reg property to match the @1 unit address?

Quoted 14 lines
arch/arm64/boot/dts/apple/t8103-j274.dts +13 -0
+			link-name = "Headphone Jack";
+
+			codec {
+				sound-dai = <&jack_codec>;
+			};
+
+			cpu {
+				sound-dai = <&mca 2>;
+			};
+		};
+	};
+};
+
 #include "hwmon-mini.dtsi"
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=17
#71 lore raw

Re: [PATCH 28/28] arm64: dts: apple: t602x-j47x: Add speaker/headset jack nodes

In reply to James Calligeros
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] dts: apple: incorrect sound card model string for Mac mini J474s --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] dts: apple: incorrect sound card model string for Mac mini J474s --

commit 633b43ef406edcf6e9ee9884c46d686b36ff8900
Author: James Calligeros <[email protected]>

arm64: dts: apple: t602x-j47x: Add speaker/headset jack nodes

The M2 Pro/Max/Ultra Mac mini and Mac Studio integrate Apple-specific variants of the TI TAS2764 and Cirrus CS42L42. Add these nodes and advertise them to the machine driver via the sound node.

arch/arm64/boot/dts/apple/t6020-j474s.dts &pcie0 { · line 51

Quoted 11 lines
arch/arm64/boot/dts/apple/t6020-j474s.dts +3 -0
index e3c2635d84fad..e79315b15f114 100644
@@ -46,4 +46,9 @@ &pcie0 {
 			<0x300 &pcie0_dart_3 1 1>;
 };
 
+&sound {
+	compatible = "apple,j474-macaudio", "apple,j473-macaudio", "apple,macaudio";
+	model = "Mac Studio J473";

[Severity: Medium]
Does this set the correct ALSA sound card name for the M2 Pro Mac mini (J474s)?

The DT model property inside the &sound node defines the card name used by ALSA Use Case Manager (UCM) to load the audio routing profile. Supplying "Mac Studio J473" here means userspace might attempt to load a Mac Studio profile instead of the Mac mini profile, which could break out-of-the-box sound on this device.

Quoted 3 lines
arch/arm64/boot/dts/apple/t6020-j474s.dts +2 -0
+};
+
 #include "hwmon-mini.dtsi"
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=28
#57 lore raw

Re: [PATCH 20/28] arm64: dts: apple: t8103-j45x: Add headset jack nodes

In reply to James Calligeros
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] ASoC: apple: macaudio: J457 silently falls back to generic configuration - [Low] dt-bindings…

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] ASoC: apple: macaudio: J457 silently falls back to generic configuration
- [Low] dt-bindings: apple,macaudio: missing reg and address-cells in DT
- [Low] dt-bindings: cirrus,cs42l42: missing required power supply properties --

commit 5cc5dec336bb9d8d002a9d3bcf32f9e5d5e39879
Author: James Calligeros <[email protected]>

arm64: dts: apple: t8103-j45x: Add headset jack nodes

This commit adds headset jack nodes to the M1 iMacs (t8103-j456 and t8103-j457). It wires up the TI TAS2770 and Cirrus CS42L42 components and advertises them via the sound node.

Quoted 4 lines
arch/arm64/boot/dts/apple/t8103-j456.dts +0 -0
index 090c97bb781b3..41ec1398f981b 100644

[ ... ]

arch/arm64/boot/dts/apple/t8103-j456.dts &pcie0_dart_1 { · line 101

Quoted 10 lines

+&i2c1 {

arch/arm64/boot/dts/apple/t8103-j456.dts +9 -0
+	status = "okay";
+
+	jack_codec: codec@48 {
+		compatible = "cirrus,cs42l83";
+		reg = <0x48>;
+		interrupts-extended = <&pinctrl_ap 183 IRQ_TYPE_LEVEL_LOW>;
+		reset-gpios = <&pinctrl_nub 11 GPIO_ACTIVE_HIGH>;
+		#sound-dai-cells = <0>;
+		sound-name-prefix = "Jack";

[Severity: Low]
Does this codec node miss required power supply properties? The cirrus,cs42l42.yaml schema requires VP-supply, VCP-supply, VD_FILT-supply, VL-supply, and VA-supply. Furthermore, #sound-dai-cells and sound-name-prefix do not appear to be declared in the schema, which causes an "additional properties are not allowed" failure during dtbs_check.

arch/arm64/boot/dts/apple/t8103-j456.dts &pcie0_dart_1 { · line 111

Quoted 10 lines
arch/arm64/boot/dts/apple/t8103-j456.dts +10 -0
+		cirrus,ts-inv = <1>;
+	};
+};
+
+/ {
+	sound: sound {
+		compatible = "apple,j456-macaudio", "apple,macaudio";
+		model = "iMac J456";
+
+		dai-link@1 {

[Severity: Low]
This dai-link node defines a unit address (@1) but lacks a corresponding reg property. Would it be possible to add the reg property here, and also include #address-cells and #size-cells in the parent sound node so the reg property can be parsed correctly? Without these, the device tree compiler will throw unit_address_vs_reg warnings.

[ ... ]

Quoted 4 lines
arch/arm64/boot/dts/apple/t8103-j457.dts +0 -0
index ebddde75455c6..aa2a08cb22cb4 100644

[ ... ]

arch/arm64/boot/dts/apple/t8103-j457.dts ethernet0: ethernet@0,0 { · line 89

Quoted 3 lines
arch/arm64/boot/dts/apple/t8103-j457.dts +3 -0
+/ {
+	sound: sound {
+		compatible = "apple,j457-macaudio", "apple,macaudio";

[Severity: High]
The macaudio driver expects J457 to use "apple,j456-macaudio" as a DT fallback and explicitly omits J457 from its macaudio_snd_device_id match table. Since the "apple,j456-macaudio" compatible string is correctly omitted here to satisfy the schema, won't of_match_device() silently match the generic "apple,macaudio" instead?

If so, this would assign the generic fallback configuration (AMP_NONE, SPKR_NONE) to J457, which might severely misconfigure its amplifier and speaker topology.

[ ... ]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=20
#68 lore raw

Re: [PATCH 26/28] arm64: dts: apple: t600x-j375: Add speaker/headset jack nodes

In reply to James Calligeros
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] dts: unit address used without a reg property in dai-link nodes --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] dts: unit address used without a reg property in dai-link nodes
--

commit 5d066ef5cb7fca6289258dc59c130ce74143e4c4
Author: James Calligeros <[email protected]>

arm64: dts: apple: t600x-j375: Add speaker/headset jack nodes

The M1 Max/Ultra Mac Studio integrates Apple-specific variants of the TI TAS2764 and Cirrus CS42L42. This commit adds these nodes and advertises them to the machine driver via the sound node.

Quoted 4 lines
arch/arm64/boot/dts/apple/t600x-j375.dtsi +0 -0
index 8a1494949e4c5..60aa9a870bd9e 100644

[ ... ]

arch/arm64/boot/dts/apple/t600x-j375.dtsi &pcie0_dart_3 { · line 445

Quoted 5 lines
arch/arm64/boot/dts/apple/t600x-j375.dtsi +5 -0
+/ {
+	sound: sound {
+		/* Compatible is set for each machine */
+
+		dai-link@0 {

[Severity: Low]
Does this node need a reg property, or should the unit address be removed?

The Device Tree specification (section 2.2.1) strictly requires that any node with a unit address (e.g., dai-link@0) must include a corresponding reg property. Omitting the reg property triggers unit_address_vs_reg warnings during make dtbs_check.

arch/arm64/boot/dts/apple/t600x-j375.dtsi &pcie0_dart_3 { · line 457

Quoted 12 lines
arch/arm64/boot/dts/apple/t600x-j375.dtsi +12 -0
+			link-name = "Speaker";
+
+			codec {
+				sound-dai = <&speaker>;
+			};
+
+			cpu {
+				sound-dai = <&mca 0>;
+			};
+		};
+
+		dai-link@1 {

[Severity: Low]
Similarly, does this node need a reg property?

Like the node above, using dai-link@1 without a reg property will introduce a new unit_address_vs_reg dtbs_check warning.

Quoted 5 lines
arch/arm64/boot/dts/apple/t600x-j375.dtsi +5 -0
+			link-name = "Headphone Jack";
+
+			codec {
+				sound-dai = <&jack_codec>;
+			};

[ ... ]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=26
#64 lore raw

Re: [PATCH 24/28] arm64: dts: apple: t8112-j493: Add speaker/headset jack nodes

In reply to James Calligeros
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] dts: unit_address_vs_reg dtc warning in sound dai-link nodes --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] dts: unit_address_vs_reg dtc warning in sound dai-link nodes
--

commit 42436807c12f7cee010fe3350f1045b5d88f9126
Author: James Calligeros <[email protected]>

arm64: dts: apple: t8112-j493: Add speaker/headset jack nodes

The M2 MacBook Pro integrates Apple-specific variants of the TI TAS2764 and Cirrus CS42L42. Add these nodes and advertise them to the machine driver via the sound node.

Quoted 4 lines
arch/arm64/boot/dts/apple/t8112-j493.dts +0 -0
index 7cea5c5948108..eb401ae8773e5 100644

[ ... ]

arch/arm64/boot/dts/apple/t8112-j493.dts touchbar0: touchbar@0 { · line 218

Quoted 7 lines
arch/arm64/boot/dts/apple/t8112-j493.dts +7 -0
+/ {
+	sound: sound {
+		compatible = "apple,j493-macaudio", "apple,macaudio";
+		model = "MacBook Pro J493";
+
+		dai-link@0 {
+			dai-tdm-idle-mode-0 = "zero";

[Severity: Low]
Does the sound node need #address-cells and #size-cells properties, along with a reg property here in dai-link@0? The device tree compiler will emit a unit_address_vs_reg warning during the build because this child node uses a unit address without a reg property.

Quoted 5 lines
arch/arm64/boot/dts/apple/t8112-j493.dts +5 -0
+			dai-tdm-idle-mode-2 = "zero";
+			dai-tdm-slot-tx-idle-mask-0 = <0xf0f0>;
+			dai-tdm-slot-tx-idle-mask-2 = <0x0f0f>;
+
+			link-name = "Speakers";

[ ... ]

arch/arm64/boot/dts/apple/t8112-j493.dts touchbar0: touchbar@0 { · line 238

Quoted 2 lines
arch/arm64/boot/dts/apple/t8112-j493.dts +2 -0
+		dai-link@1 {
+			link-name = "Headphone Jack";

[Severity: Low]
Similarly, does this second dai-link child node need a reg property to match its unit address and prevent a unit_address_vs_reg dtc warning?

Quoted 4 lines
arch/arm64/boot/dts/apple/t8112-j493.dts +4 -0
+
+			codec {
+				sound-dai = <&jack_codec>;
+			};

[ ... ]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=24
#66 lore raw

Re: [PATCH 25/28] arm64: dts: apple: t600x-j31x: Add speaker/headset jack nodes

In reply to James Calligeros
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] dts: typo in dai-tdm-slot-tx-idle-mask property prevents TDM idle configuration --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] dts: typo in dai-tdm-slot-tx-idle-mask property prevents TDM idle configuration --

commit f5c52499a0a647e882ff3e2323a3096d2ee9614e
Author: James Calligeros <[email protected]>

arm64: dts: apple: t600x-j31x: Add speaker/headset jack nodes

This commit adds I2C nodes for the speaker and headset jack audio codecs used in the M1 Pro/Max MacBooks. It also configures the audio routing by adding the sound machine driver node.

Quoted 4 lines
arch/arm64/boot/dts/apple/t600x-j314-j316.dtsi +0 -0
index caded1636f3d2..7afd385ce57dc 100644

[ ... ]

arch/arm64/boot/dts/apple/t600x-j314-j316.dtsi &atcphy3 { · line 465

Quoted 9 lines
arch/arm64/boot/dts/apple/t600x-j314-j316.dtsi +9 -0
+/ {
+	sound: sound {
+		/* Compatible is set for each machine */
+
+		dai-link@0 {
+			dai-tdm-idle-mode-0 = "zero";
+			dai-tdm-idle-mode-3 = "zero";
+			dai-tdm-slot-tx-idle-mode-0 = <0xf0f0f0>;
+			dai-tdm-slot-tx-idle-mode-3 = <0x0f0f0f>;

[Severity: Medium]
Does the ASoC machine driver look for the property with the "-mode" suffix here?

Looking at macaudio_get_codec_idle_props() in sound/soc/apple/macaudio.c, it appears the driver expects dai-tdm-slot-tx-idle-mask-%d to read these bitmasks. Since the device tree spells this as "...-idle-mode-%d", the property is not found and the idle_mask will remain 0.

Could this lead to unused TDM slots remaining unmasked during idle, causing I2S bus noise or zero-stuffing failures?

Quoted 6 lines
arch/arm64/boot/dts/apple/t600x-j314-j316.dtsi +6 -0
+
+			link-name = "Speakers";
+
+			codec {
+				sound-dai = <&speaker_left_woof1>,
+					    <&speaker_left_tweet>,
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=25
#55 lore raw

Re: [PATCH 19/28] arm64: dts: apple: t8103-j293: Add speaker/headset jack nodes

In reply to James Calligeros
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider: - [High] dt-bindings: apple: t8103-j293: ALSA probe failure due to shared shutdown GPIO - [Low]…

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] dt-bindings: apple: t8103-j293: ALSA probe failure due to shared shutdown GPIO
- [Low] dt-bindings: apple: t8103-j293: Missing required regulator supplies for cs42l83
- [Low] dt-bindings: apple: t8103-j293: Unit address used without reg property
- [Low] dt-bindings: apple: t8103-j293: Redundant duplicate &i2c2 node override --

commit beea98820cabe339ebc83e4b7bba334d2303a499
Author: James Calligeros <[email protected]>

arm64: dts: apple: t8103-j293: Add speaker/headset jack nodes

This commit adds device tree nodes for the Apple-specific variants of the TI TAS2770 and Cirrus CS42L42 audio codecs found in the M1 MacBook Pro. It also advertises them to the machine driver via the sound node.

Quoted 4 lines
arch/arm64/boot/dts/apple/t8103-j293.dts +0 -0
index 1d074b9e60183..24d0b512fac4a 100644

[ ... ]

arch/arm64/boot/dts/apple/t8103-j293.dts &displaydfr_dart { · line 144

Quoted 8 lines

+&i2c1 {

arch/arm64/boot/dts/apple/t8103-j293.dts +7 -0
+	status = "okay";
+
+	speaker_left_rear: codec@31 {
+		compatible = "ti,tas5770l", "ti,tas2770";
+		reg = <0x31>;
+		interrupts-extended = <&pinctrl_ap 182 IRQ_TYPE_LEVEL_LOW>;
+		shutdown-gpios = <&pinctrl_ap 181 GPIO_ACTIVE_HIGH>;

[Severity: High]
Does sharing the same shutdown-gpios across all four TAS2770 codecs prevent ALSA from probing?

During I2C enumeration, speaker_left_rear requests the GPIO exclusively and drives it LOW (shutdown state). The subsequent three codecs fail to request it with -EBUSY and silently fall back to a NULL GPIO handle.

When ALSA later probes speaker_left_front first, it skips pulling the hardware out of shutdown due to the NULL handle. It then issues I2C writes which are NAKed because the line is still held in shutdown by speaker_left_rear, causing the entire sound card registration to abort.

Quoted 5 lines
arch/arm64/boot/dts/apple/t8103-j293.dts +5 -0
+		#sound-dai-cells = <0>;
+		sound-name-prefix = "Left Rear";
+		ti,imon-slot-no = <8>;
+		ti,vmon-slot-no = <10>;
+	};

[ ... ]

arch/arm64/boot/dts/apple/t8103-j293.dts

Quoted 2 lines

+&i2c2 {

arch/arm64/boot/dts/apple/t8103-j293.dts +1 -0
+	status = "okay";

[Severity: Low]
Is this &i2c2 override redundant? The base device tree already overrides &i2c2 to set status = "okay" earlier in the file.

arch/arm64/boot/dts/apple/t8103-j293.dts &displaydfr_dart { · line 168

Quoted 4 lines
arch/arm64/boot/dts/apple/t8103-j293.dts +4 -0
+
+	jack_codec: codec@48 {
+		compatible = "cirrus,cs42l83";
+		reg = <0x48>;

[Severity: Low]
Are the required regulator supplies missing for the cs42l83 codec?

The cirrus,cs42l42.yaml bindings require VP-supply, VCP-supply, VD_FILT-supply, VL-supply, and VA-supply, which appear to be entirely omitted here.

Quoted 3 lines
arch/arm64/boot/dts/apple/t8103-j293.dts +3 -0
+		interrupts-extended = <&pinctrl_ap 183 IRQ_TYPE_LEVEL_LOW>;
+		reset-gpios = <&pinctrl_nub 11 GPIO_ACTIVE_HIGH>;
+		#sound-dai-cells = <0>;

[ ... ]

arch/arm64/boot/dts/apple/t8103-j293.dts &displaydfr_dart { · line 208

Quoted 1 line
arch/arm64/boot/dts/apple/t8103-j293.dts +1 -0
+		dai-link@0 {

[Severity: Low]
Should this node include a reg = <0>; property? Per device tree syntax rules, any node with a unit address (@0) must have a matching reg property.

Quoted 4 lines
arch/arm64/boot/dts/apple/t8103-j293.dts +4 -0
+			dai-tdm-idle-mode-0 = "pulldown";
+			dai-tdm-idle-mode-2 = "pulldown";
+
+			link-name = "Speakers";

[ ... ]

arch/arm64/boot/dts/apple/t8103-j293.dts &displaydfr_dart { · line 226

Quoted 1 line
arch/arm64/boot/dts/apple/t8103-j293.dts +1 -0
+		dai-link@1 {

[Severity: Low]
Should this node include a reg = <1>; property?

Quoted 3 lines
arch/arm64/boot/dts/apple/t8103-j293.dts +3 -0
+			link-name = "Headphone Jack";
+
+			codec {
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=19
#62 lore raw

Re: [PATCH 23/28] arm64: dts: apple: t8112-j473: Add speaker/headset jack nodes

In reply to James Calligeros
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] dts: missing reg and address-cells in unit-addressed dai-link nodes --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] dts: missing reg and address-cells in unit-addressed dai-link nodes --

commit 2807e1e10c5e8e2ab5f1a1be50044624cb7a4535
Author: James Calligeros <[email protected]>

arm64: dts: apple: t8112-j473: Add speaker/headset jack nodes

The M2 Mac mini integrates Apple-specific variants of the TI TAS2764 and Cirrus CS42L42. Add these nodes and advertise them to the machine driver via the sound node.

Quoted 4 lines
arch/arm64/boot/dts/apple/t8112-j473.dts +0 -0
index 105a9d118980f..50088283f2e8e 100644

[ ... ]

arch/arm64/boot/dts/apple/t8112-j473.dts &typec1 { · line 115

Quoted 4 lines
arch/arm64/boot/dts/apple/t8112-j473.dts +4 -0
+/ {
+	sound: sound {
+		compatible = "apple,j473-macaudio", "apple,macaudio";
+		model = "Mac mini J473";

[Severity: Low]
Does this node need #address-cells = <1>; and #size-cells = <0>; properties since it has unit-addressed children? Omitting them causes dtc validation warnings (unit_address_vs_reg) and fails the apple,macaudio.yaml schema check.

arch/arm64/boot/dts/apple/t8112-j473.dts

Quoted 2 lines
arch/arm64/boot/dts/apple/t8112-j473.dts +2 -0
+
+		dai-link@0 {

[Severity: Low]
Should this node include a reg = <0>; property to match its unit address?

arch/arm64/boot/dts/apple/t8112-j473.dts &typec1 { · line 129

Quoted 12 lines
arch/arm64/boot/dts/apple/t8112-j473.dts +12 -0
+			link-name = "Speakers";
+
+			codec {
+				sound-dai = <&speaker>;
+			};
+
+			cpu {
+				sound-dai = <&mca 0>;
+			};
+		};
+
+		dai-link@1 {

[Severity: Low]
Should this node include a reg = <1>; property to match its unit address?

Quoted 14 lines
arch/arm64/boot/dts/apple/t8112-j473.dts +13 -0
+			link-name = "Headphone Jack";
+
+			codec {
+				sound-dai = <&jack_codec>;
+			};
+
+			cpu {
+				sound-dai = <&mca 2>;
+			};
+		};
+	};
+};
+
 #include "hwmon-mini.dtsi"
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=23
maintainer
#3 lore raw

Re: [PATCH 01/28] dt-bindings: sound: Add Apple Macs sound peripherals

In reply to James Calligeros

Hi,

Quoted 42 lines · James Calligeros

From: Martin Povišer <[email protected]>

Add binding for Apple Silicon Macs machine-level integration of sound peripherals.

---
  .../bindings/sound/apple,macaudio.yaml   | 235 +++++++++++++++++++++++++
  1 file changed, 235 insertions(+)
Documentation/devicetree/bindings/sound/apple,macaudio.yaml new file +24 -0
new file mode 100644
index 000000000000..bd844c9928c9
@@ -0,0 +1,235 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/apple,macaudio.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Sound peripheral integration for Apple Silicon Macs
+
+description:
+  This binding represents the overall machine-level integration of sound
+  peripherals on Apple Silicon Macs, starting with the M1 series.
+
+maintainers:
+  - James Calligeros <[email protected]>
+
+properties:
+  compatible:
+    oneOf:
+      - description: First-of-their-kind machines
+        items:
+          - enum:
+              - apple,j180-macaudio
+              - apple,j274-macaudio
+              - apple,j293-macaudio

Documentation/devicetree/bindings/sound/apple,macaudio.yaml line 34

Quoted 10 lines
Documentation/devicetree/bindings/sound/apple,macaudio.yaml new file +10 -0
+              - apple,j313-macaudio
+              - apple,j314-macaudio
+              - apple,j316-macaudio
+              - apple,j375-macaudio
+              - apple,j413-macaudio
+              - apple,j415-macaudio
+              - apple,j473-macaudio
+              - apple,j456-macaudio
+              - apple,j457-macaudio
+          - const: apple,macaudio

We've had some not-so-great experiences with these generic compatibles in the past. I'd just drop it.

Sven

maintainer
#4 lore raw

Re: [PATCH 01/28] dt-bindings: sound: Add Apple Macs sound peripherals

In reply to James Calligeros
Quoted 4 lines · James Calligeros

From: Martin Povišer <[email protected]>

Add binding for Apple Silicon Macs machine-level integration of sound peripherals.

Please submit patches using subject lines reflecting the style for the subsystem, this makes it easier for people to identify relevant patches. Look at what existing commits in the area you're changing are doing and make sure your subject lines visually resemble what they're doing. There's no need to resubmit to fix this alone.

maintainer
#12 lore raw

Re: [PATCH 05/28] alsa: pcm: Remove the qos request only if active

In reply to James Calligeros
Quoted 3 lines · James Calligeros

From: Hector Martin <[email protected]>

Fixes warning:

Please submit patches using subject lines reflecting the style for the subsystem, this makes it easier for people to identify relevant patches. Look at what existing commits in the area you're changing are doing and make sure your subject lines visually resemble what they're doing. There's no need to resubmit to fix this alone.

maintainer
#72 lore raw
In reply to James Calligeros
Quoted 11 lines · James Calligeros

Hi folks,

This series finalises support for the main
audio subsystem on Apple Silicon Macs. It adds a machine driver called macaudio, which is based on an RFC sent many years ago by Martin Povišer[1]. The driver uses the DPCM model to dynamically glue a backend DAI (combination of MCA ports and codecs) to a frontend PCM. While this theoretically allows us to route any backend to any frontend, this is not used in practice; the "Primary" frontend is always used for the headset codec and the "Secondary" is always used for the speakers.

This has got a lot of different stuff in it, there's several different sets of fixes, a number of framework features, as well as the new driver and a huge pile of DT updates. It would be a lot more digestable were these things to be split out, especially the fixes.

maintainer
#5 lore raw

Re: [PATCH 01/28] dt-bindings: sound: Add Apple Macs sound peripherals

In reply to James Calligeros

Documentation/devicetree/bindings/sound/apple,macaudio.yaml line 40

Quoted 11 lines · James Calligeros

From: Martin Povišer <[email protected]>

Add binding for Apple Silicon Macs machine-level integration of sound peripherals.

Documentation/devicetree/bindings/sound/apple,macaudio.yaml new file +6 -0
+      - description: Machines compatible with J293
+        items:
+          - enum:
+              - apple,j493-macaudio
+          - const: apple,j293-macaudio
+          - const: apple,macaudio

This doesn't seem to correspond to the DT for j493.

maintainer
#8 lore raw

Re: [PATCH 02/28] ASoC: cs42l42: Fix typo

In reply to James Calligeros
Quoted 3 lines · James Calligeros

From: Martin Povišer <[email protected]>

Fixes 2c394ca79604 ("ASoC: Add support for CS42L42 codec")

This one is a very clear example of something that should have been split out, it's unrelated to the rest of the series.

maintainer
#29 lore raw

Re: [PATCH 10/28] ASoC: ops: Accept patterns in snd_soc_limit_volume

In reply to James Calligeros

sound/soc/soc-ops.c static int soc_limit_volume(struct snd_kcontrol *kctl, int max) · line 513

Quoted 10 lines · James Calligeros

From: Martin Povišer <[email protected]>

In snd_soc_limit_volume, instead of looking up a single control by name, also understand wildcard-starting patterns like '* Amp Gain Volume' to touch many controls at one.

sound/soc/soc-ops.c +1 -1
-	return soc_limit_volume(kctl, max);
+	return hits;
 }
 EXPORT_SYMBOL_GPL(snd_soc_limit_volume);

This will break the existing Cirrus and TI users which treat non-zero values as errors, most users ignore the return value but they check.

#30 lore raw

Re: [PATCH 10/28] ASoC: ops: Accept patterns in snd_soc_limit_volume

In reply to Mark Brown
Quoted 7 lines · Mark Brown
Quoted 5 lines · James Calligeros

From: Martin Povišer <[email protected]>

In snd_soc_limit_volume, instead of looking up a single control by name, also understand wildcard-starting patterns like '* Amp Gain Volume' to touch many controls at one.

Quoted 7 lines

sound/soc/soc-ops.c static int soc_limit_volume(struct snd_kcontrol *kctl, int max) · line 513

Quoted 4 lines
sound/soc/soc-ops.c +1 -1
-	return soc_limit_volume(kctl, max);
+	return hits;
 }
 EXPORT_SYMBOL_GPL(snd_soc_limit_volume);

This will break the existing Cirrus and TI users which treat non-zero values as errors, most users ignore the return value but they check.

Thanks, yeah fixing up the existing users would be greatly appreciated.

Also are we sure this wildcard approach is the way to go? Does make me slightly nervous that you could get stuff like a driver adds a new control and it gets pulled unexpectedly into a wildcarded limit.

Are you using the wildcard mostly to skip the component prefix stuff? I wonder if adding an option to match without that might be more explicit.

Thanks,
Charles

maintainer
#13 lore raw

Re: [PATCH 05/28] alsa: pcm: Remove the qos request only if active

In reply to James Calligeros
Quoted 7 lines · James Calligeros

From: Hector Martin <[email protected]>

Fixes warning:

[    8.502802] ------------[ cut here ]------------
[    8.503445] cpu_latency_qos_remove_request called for unknown object
[    8.504269] WARNING: CPU: 5 PID: 2790 at kernel/power/qos.c:322 cpu_latency_qos_remove_request+0x48/0x98

Do we know why this is being triggered? It makes me a bit nervous to just shut up a warning without an commentary on why whatever the warning is telling us about isn't an issue.

maintainer
#46 lore raw

Re: [PATCH 16/28] ASoC: apple: Add macaudio machine driver

In reply to James Calligeros
Quoted 9 lines · James Calligeros

Apple Silicon Macs have a complex audio subsystem consisting of an I2S peripheral (MCA) and multiple codecs of various models and capabilities. Some machines have a basic mono speaker with hardware downmix, while others have a very intricate stereo system consisting of multiple codecs and drivers per L/R channel. Some machines report voice coil voltage and current information back to the SoC, and others do not. All machines have a headset jack.

sound/soc/apple/Kconfig config SND_SOC_APPLE_MCA · line 16

Quoted 5 lines
sound/soc/apple/Kconfig +5 -0
+config SND_SOC_APPLE_MACAUDIO
+	tristate "Sound support for Apple Silicon Macs"
+	depends on ARCH_APPLE || COMPILE_TEST
+	select SND_SOC_APPLE_MCA
+	select SND_SIMPLE_CARD_UTILS

Do we actually use simple-card?

sound/soc/apple/Makefile line 8

Quoted 10 lines
sound/soc/apple/Makefile +4 -0
@@ -2,3 +2,7 @@
 snd-soc-apple-mca-y	:= mca.o
 
 obj-$(CONFIG_SND_SOC_APPLE_MCA)	+= snd-soc-apple-mca.o
+
+snd-soc-macaudio-objs	:= macaudio.o
+
+obj-$(CONFIG_SND_SOC_APPLE_MACAUDIO)	+= snd-soc-macaudio.o

Note the -y vs -objs style difference here.

sound/soc/apple/Makefile line 4

Quoted 5 lines
sound/soc/apple/Makefile +4 -0
@@ -0,0 +1,1729 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * ASoC machine driver for Apple Silicon Macs
+ *

Please kep the entire comment block C++ so things look more consistent.

Quoted 5 lines
sound/soc/apple/Makefile +4 -0
+static void macaudio_vlimit_unlock(struct macaudio_snd_data *ma, bool unlock)
+{
 
+	case AMP_TAS5770:
+		if (unlock)

sound/soc/apple/Makefile

Quoted 10 lines
sound/soc/apple/Makefile +10 -0
+			max = TAS5770_0DB;
+		else
+			max = 1; //TAS5770_DB(ma->cfg->safe_vol);
+		break;
+	case AMP_SN012776:
+		if (unlock)
+			max = SN012776_0DB;
+		else
+			max = 1; //SN012776_DB(ma->cfg->safe_vol);
+		break;

What's going on with those comments?

sound/soc/apple/Makefile

Quoted 8 lines
sound/soc/apple/Makefile +7 -0
+static void macaudio_vlimit_update(struct macaudio_snd_data *ma)
+{
 
+
+	/* Check that *every* limited control is locked by the same owner */
+	list_for_each_entry(kctl, &ma->card.snd_card->controls, list) {
+		if (!snd_soc_control_matches(kctl, volume_control_names[ma->cfg->amp]))
+			continue;

This is used from the volume limit timeout work which doesn't hold the controls_rwsem, userspace can add or remove user controls which would change the list so the work needs to lock the controls list.

Quoted 4 lines
sound/soc/apple/Makefile +4 -0
+/*
+ * Parse one DPCM backend from the devicetree. This means taking one
+ * of the CPU DAIs and combining it with one or more CODEC DAIs.
+ */

sound/soc/apple/Makefile

Quoted 10 lines
sound/soc/apple/Makefile +9 -0
+static int macaudio_parse_of_be_dai_link(struct macaudio_snd_data *ma,
+				struct snd_soc_dai_link *link,
+				int be_index, int ncodecs_per_be,
+				struct device_node *cpu,
+				struct device_node *codec)
 
+	ret = macaudio_parse_of_component(cpu, be_index, link->cpus);
+	if (ret)
+		return dev_err_probe(ma->card.dev, ret, "parsing CPU DAI of link '%s' at %pOF\n",
+				     link->name, codec);

Cut'n'paste with logging the codec node.

Quoted 13 lines
sound/soc/apple/Makefile +13 -0
+static int macaudio_get_codec_idle_props(struct device_node *np,
+					 struct ma_codec_idle *idle, int i,
+					 int be_index, int ncodecs_per_cpu)
+{
+	char propname[32];
+	int ret, sys_codec;
+
+	/*
+	 * Depending on the BE index on the DAI, we need to offset our i
+	 */
+	sys_codec = i + (be_index * ncodecs_per_cpu);
+
+	snprintf(propname, 32, "dai-tdm-idle-mode-%d", sys_codec);

sound/soc/apple/Makefile

Quoted 10 lines
sound/soc/apple/Makefile +10 -0
+	ret = of_property_match_string(np, propname, "zero");
+	if (!ret) {
+		idle->idle_mode = SND_SOC_DAI_TDM_IDLE_ZERO;
+	} else {
+		ret = of_property_match_string(np, propname, "pulldown");
+		if (!ret)
+			idle->idle_mode = SND_SOC_DAI_TDM_IDLE_PULLDOWN;
+		else
+			return ret;
+	}

Should we warn on unknown values?

Quoted 6 lines
sound/soc/apple/Makefile +6 -0
+static int macaudio_dpcm_hw_params(struct snd_pcm_substream *substream,
+				   struct snd_pcm_hw_params *params)
+{
+	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
+	struct macaudio_snd_data *ma = snd_soc_card_get_drvdata(rtd->card);
+	struct macaudio_link_props *props = &ma->link_props[rtd->dai_link->id];

sound/soc/apple/Makefile

Quoted 10 lines
sound/soc/apple/Makefile +10 -0
+	struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
+	struct snd_interval *rate = hw_param_interval(params,
+						      SNDRV_PCM_HW_PARAM_RATE);
+	int bclk_ratio = macaudio_get_runtime_bclk_ratio(substream);
+	int i;
+
+	if (props->is_sense) {
+		rate->min = rate->max = cpu_dai->symmetric_rate;
+		return 0;
+	}

It feels like this DAI ought to have separate ops... Also, for the sense link will we definitely already have a rate set up?

Quoted 8 lines
sound/soc/apple/Makefile +8 -0
+static int macaudio_be_trigger(struct snd_pcm_substream *substream, int cmd)
+{
+	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
+	struct macaudio_snd_data *ma = snd_soc_card_get_drvdata(rtd->card);
+	struct macaudio_link_props *props = &ma->link_props[rtd->dai_link->id];
+
+	if (props->is_speakers && substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+		switch (cmd) {

sound/soc/apple/Makefile

Quoted 10 lines
sound/soc/apple/Makefile +10 -0
+		case SNDRV_PCM_TRIGGER_START:
+		case SNDRV_PCM_TRIGGER_RESUME:
+		case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+			ma->bes_active |= BIT(rtd->dai_link->id);
+			break;
+		case SNDRV_PCM_TRIGGER_SUSPEND:
+		case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+		case SNDRV_PCM_TRIGGER_STOP:
+			ma->bes_active &= ~BIT(rtd->dai_link->id);
+			break;

Do we have adequate locking here, this is shared between BEs but the BEs have their own locks?

sound/soc/apple/Makefile

Quoted 12 lines
sound/soc/apple/Makefile +10 -0
+static int macaudio_be_assign_tdm(struct snd_soc_pcm_runtime *rtd)
+{
 
+	for_each_rtd_codec_dais(rtd, i, dai) {
 
+		if (props->codecs[i].idle_mode) {
+			ret = snd_soc_dai_set_tdm_idle(dai, props->codecs[i].idle_mask,
+						       0, props->codecs[i].idle_mode, 0);
+		}
+	}
+
+	return 0;

We store ret but don't pay attention to the result.

Quoted 10 lines
sound/soc/apple/Makefile +10 -0
+#define CHECK(call, pattern, value, min)                                       \
+	{                                                                      \
+		int ret = call(card, pattern, value);                          \
+		int err = (ret >= 0 && ret < min) ? -ERANGE : ret;             \
+		if (err < 0) {                                                 \
+			dev_err(card->dev, "%s on '%s': %d\n", #call, pattern, \
+				ret);                                          \
+			if (please_blow_up_my_speakers < 2)                    \
+				return err;                                    \
+		} else {                                                       \

sound/soc/apple/Makefile

Quoted 10 lines
sound/soc/apple/Makefile +10 -0
+			dev_dbg(card->dev, "%s on '%s': %d hits\n", #call,     \
+				pattern, ret);                                 \
+		}                                                              \
+	}
+
+#define CHECK_CONCAT(call, suffix, value) \
+	{ \
+		snprintf(buf, sizeof(buf), "%s%s", prefix, suffix); \
+		CHECK(call, buf, value, 1); \
+	}

This only requires one match, things might go wrong for a stereo setup.

sound/soc/apple/Makefile

Quoted 4 lines
sound/soc/apple/Makefile +3 -0
+static const struct snd_kcontrol_new macaudio_hp_mux =
+	SOC_DAPM_ENUM("Headphones Playback Mux", macaudio_hp_mux_enum);
 
+	SND_SOC_DAPM_SPK("Speaker (Static)", NULL),

Is this used?

sound/soc/apple/Makefile

Quoted 1 line
sound/soc/apple/Makefile +1 -0
+	SND_SOC_DAPM_MUX("Headphone Playback Mux", SND_SOC_NOPM, 0, 0, &macaudio_hp_mux),

Headphone or Headphones?

Quoted 8 lines
sound/soc/apple/Makefile +8 -0
+static int macaudio_slk_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *uvalue)
+{
+	struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
+	struct macaudio_snd_data *ma = snd_soc_card_get_drvdata(card);
+
+	if (!ma->speaker_lock_owner)
+		return -EPERM;
+

sound/soc/apple/Makefile

Quoted 10 lines
sound/soc/apple/Makefile +10 -0
+	if (uvalue->value.integer.value[0] != SPEAKER_MAGIC_VALUE)
+		return -EINVAL;
+
+	/* Serves as a notification that the lock was lost at some point */
+	if (ma->speaker_volume_was_locked) {
+		ma->speaker_volume_was_locked = false;
+		return -ETIMEDOUT;
+	}
+
+	mutex_lock(&ma->volume_lock_mutex);

Shouldn't we take the mutex before checking (and potentially changing) the state? Otherwise we've got TOCTOU issues.

sound/soc/apple/Makefile

Quoted 9 lines
sound/soc/apple/Makefile +9 -0
+static void macaudio_slk_unlock(struct snd_kcontrol *kcontrol)
+{
+	struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
+	struct macaudio_snd_data *ma = snd_soc_card_get_drvdata(card);
+
+	ma->speaker_lock_owner = NULL;
+	ma->speaker_lock_timeout = 0;
+	macaudio_vlimit_update(ma);
+}

This seems to similarly be missing locking.

sound/soc/apple/Makefile

Quoted 4 lines
sound/soc/apple/Makefile +4 -0
+/*	enable	amp		speakers	stereo	gain	safe_vol */
+struct macaudio_platform_cfg macaudio_j180_cfg = {
+	false,	AMP_SN012776,	SPKR_1W1T,	false,	10,	-20,
+};

These should be static, they're not used outside this file. Probably also const.

sound/soc/apple/Makefile

Quoted 4 lines
sound/soc/apple/Makefile +3 -0
+static const struct of_device_id macaudio_snd_device_id[]  = {
 
+	/* j375    AID10   sn012776    15      1× 1W */
+	{ .compatible = "apple,j375-macaudio", .data = &macaudio_j37x_j47x_cfg },

The j47x entries in the table use 20 not 15.

sound/soc/apple/Makefile

Quoted 6 lines
sound/soc/apple/Makefile +6 -0
+static void macaudio_snd_platform_remove(struct platform_device *pdev)
+{
+	struct macaudio_snd_data *ma = dev_get_drvdata(&pdev->dev);
+
+	cancel_delayed_work_sync(&ma->lock_timeout_work);
+}

What ensures that lock_update_work is cancelled?

maintainer
#43 lore raw

Re: [PATCH 15/28] ASoC: tas2764: Set up V/ISENSE on codec probe

In reply to James Calligeros

sound/soc/codecs/tas2764.c static int tas2764_codec_probe(struct snd_soc_component *component) · line 810

Quoted 9 lines · James Calligeros

Setup V/ISENSE on codec probe rather than doing so on every hw_params or TDM slot call so that it is configured at the same time as the rest of the codec.

sound/soc/codecs/tas2764.c +5 -0
+	if (tas2764->v_sense_slot != -1 || tas2764->i_sense_slot != -1) {
+		ret = tas2764_set_visense(tas2764, tas2764->v_sense_slot, tas2764->i_sense_slot);
+		if (ret < 0)
+			return ret;
+	}

What might set the slots to -1?

maintainer
#40 lore raw

Re: [PATCH 14/28] ASoC: ops: Export snd_soc_control_matches()

In reply to James Calligeros
Quoted 14 lines · James Calligeros

From: Hector Martin <[email protected]>

This helper is useful for drivers that want to do their own control lookups and matching as part of more complex logic than the existing operations.

EXPORT_SYMBOL_GPL(snd_soc_put_volsw_sx);

sound/soc/soc-ops.c +1 -1
-static bool soc_control_matches(struct snd_kcontrol *kctl,
+bool snd_soc_control_matches(struct snd_kcontrol *kctl,
 	const char *pattern)
 {
 	const char *name = kctl->id.name;

sound/soc/soc-ops.c static bool soc_control_matches(struct snd_kcontrol *kctl, · line 428

Quoted 4 lines
sound/soc/soc-ops.c +1 -0
@@ -425,6 +425,7 @@ static bool soc_control_matches(struct snd_kcontrol *kctl,
 
 	return !strcmp(name, pattern);
 }
+EXPORT_SYMBOL_GPL(snd_soc_control_matches);

Please document the API now you're exporting it.

maintainer
#37 lore raw

Re: [PATCH 12/28] ASoC: ops: Introduce 'soc_set_enum_kctl'

In reply to James Calligeros

sound/soc/soc-ops.c int snd_soc_deactivate_kctl(struct snd_soc_card *card, · line 556

Quoted 10 lines · James Calligeros

From: Martin Povišer <[email protected]>

The new function is to be used to set enumerated controls to desired values -- either a single control or many controls in bulk by pattern. It is something a machine driver may call in fixup_controls.

sound/soc/soc-ops.c +4 -0
+static int soc_set_enum_kctl(struct snd_kcontrol *kctl, const char *strval)
+{
+	struct snd_ctl_elem_value value;
+	struct snd_ctl_elem_info info;

Probably best to fully initialise the value, in particular while I don't think anything currently does it we can have multiple enums in one control like with stereo volume controls.

sound/soc/soc-ops.c int snd_soc_deactivate_kctl(struct snd_soc_card *card, · line 582

Quoted 4 lines
sound/soc/soc-ops.c +4 -0
+	for (i = 0; i < info.count; i++)
+		value.value.enumerated.item[i] = sel;
+
+	return kctl->put(kctl, &value);

Should check that put exists.

sound/soc/soc-ops.c int snd_soc_deactivate_kctl(struct snd_soc_card *card, · line 596

Quoted 12 lines
sound/soc/soc-ops.c +12 -0
+/**
+ * snd_soc_set_enum_kctl - Set enumerated controls matching a pattern
+ *
+ * @card: where to look for the controls
+ * @name: name pattern
+ * @value: string value to set the controls to
+ *
+ * Return number of matching and set controls on success, else error.
+ * No controls need to match.
+ */
+int snd_soc_set_enum_kctl(struct snd_soc_card *card,
+	const char *name, const char *value)

We have both value and strval in different places.

maintainer
#34 lore raw

Re: [PATCH 11/28] ASoC: ops: Introduce 'snd_soc_deactivate_kctl'

In reply to James Calligeros
Quoted 9 lines · James Calligeros

From: Martin Povišer <[email protected]>

The new function can be used to deactivate controls -- either a single one or in bulk by pattern. It is something a machine driver may call in fixup_controls.

+ * Return number of matching controls on success, else error.
+ * No controls need to match.
+ */

sound/soc/soc-ops.c int snd_soc_limit_volume(struct snd_soc_card *card, const char *name, int max) · line 547

Quoted 5 lines
sound/soc/soc-ops.c +4 -0
+int snd_soc_deactivate_kctl(struct snd_soc_card *card,
+	const char *name, int active)
 
+	if (!hits)
+		return -EINVAL;

The comment says no controls need to match, but we return an error in that case.

maintainer
#16 lore raw

Re: [PATCH 06/28] ALSA: dmaengine: Always terminate DMA when a PCM is closed

In reply to James Calligeros
Quoted 10 lines · James Calligeros

From: Hector Martin <[email protected]>

When a PCM is suspended, we pause the DMA. If the PCM is then closed while in this state, it does not receive the STOP trigger (as it is not running). In this case, we fail to properly terminate the DMA, calling dmaengine_synchronize() nonetheless, which is undefined behavior.

Make sure we always call dmaengine_terminate_async() on PCM close, regardless of whether it has been called previously or not in the trigger callbacks.

See 6a7db25aad8ce (ALSA: dmaengine_pcm: terminate dmaengine before synchronize) - we should already be handling anything that's already saying it's paused.

#31 lore raw

Re: [PATCH 10/28] ASoC: ops: Accept patterns in snd_soc_limit_volume

In reply to Charles Keepax
Quoted 3 lines · Australian Eastern Standard Time Charles Keepax

Are you using the wildcard mostly to skip the component prefix stuff? I wonder if adding an option to match without that might be more explicit.

We use it in two places. The first is as part of the speaker protection system, to ensure that all the relevant kctrls have been locked by the same owner (us). This one just matches without the component prefix. We also use this facility to eliminate duplication across left and right channels, matching partially on the component prefix but without "Left" or "Right" in the string. The second use case is rather superfluous so I am happy to get rid of that. I think at that point it would make more sense to just construct the full kctrl name in the driver and pass that in to the existing API in the one place this actually remains necessary.

Quoted 3 lines

Thanks,
Charles

James

#6 lore raw

Re: [PATCH 01/28] dt-bindings: sound: Add Apple Macs sound peripherals

In reply to James Calligeros
Quoted 4 lines · James Calligeros

index 000000000000..bd844c9928c9

Documentation/devicetree/bindings/sound/apple,macaudio.yaml line 10

Quoted 10 lines
Documentation/devicetree/bindings/sound/apple,macaudio.yaml new file +10 -0
@@ -0,0 +1,235 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/apple,macaudio.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Sound peripheral integration for Apple Silicon Macs
+
+description:
+  This binding represents the overall machine-level integration of sound

Please rephrase to describe not what binding describes (circular) but just say what this device is.

Quoted 14 lines
Documentation/devicetree/bindings/sound/apple,macaudio.yaml new file +14 -0
+  peripherals on Apple Silicon Macs, starting with the M1 series.
+
+maintainers:
+  - James Calligeros <[email protected]>
+
+properties:
+  compatible:
+    oneOf:
+      - description: First-of-their-kind machines
+        items:
+          - enum:
+              - apple,j180-macaudio
+              - apple,j274-macaudio
+              - apple,j293-macaudio

Documentation/devicetree/bindings/sound/apple,macaudio.yaml line 34

Quoted 10 lines
Documentation/devicetree/bindings/sound/apple,macaudio.yaml new file +10 -0
+              - apple,j313-macaudio
+              - apple,j314-macaudio
+              - apple,j316-macaudio
+              - apple,j375-macaudio
+              - apple,j413-macaudio
+              - apple,j415-macaudio
+              - apple,j473-macaudio
+              - apple,j456-macaudio
+              - apple,j457-macaudio
+          - const: apple,macaudio

As pointed out by Sven, please use specific compatible as fallback. Descriptions will be also redundant in such case, since the fllback will tell what is compatible with what.

Quoted 66 lines
Documentation/devicetree/bindings/sound/apple,macaudio.yaml new file +66 -0
+      - description: Machines compatible with J293
+        items:
+          - enum:
+              - apple,j493-macaudio
+          - const: apple,j293-macaudio
+          - const: apple,macaudio
+      - description: Machines compatible with J314
+        items:
+          - enum:
+              - apple,j414-macaudio
+              - apple,j504-macaudio
+              - apple,j514-macaudio
+          - const: apple,j314-macaudio
+          - const: apple,macaudio
+      - description: Machines compatible with J316
+        items:
+          - enum:
+              - apple,j416-macaudio
+              - apple,j516-macaudio
+          - const: apple,j316-macaudio
+          - const: apple,macaudio
+      - description: Machines compatible with J375
+        items:
+          - enum:
+              - apple,j475-macaudio
+              - apple,j575-macaudio
+          - const: apple,j375-macaudio
+          - const: apple,macaudio
+      - description: Machines compatible with J413
+        items:
+          - enum:
+              - apple,j613-macaudio
+          - const: apple,j413-macaudio
+          - const: apple,macaudio
+      - description: Machines compatible with J415
+        items:
+          - enum:
+              - apple,j615-macaudio
+          - const: apple,j415-macaudio
+          - const: apple,macaudio
+      - description: Machines compatible with J473
+        items:
+          - enum:
+              - apple,j474-macaudio
+          - const: apple,j473-macaudio
+          - const: apple,macaudio
+
+  "#address-cells":
+    const: 1
+
+  "#size-cells":
+    const: 0
+
+  model:
+    description:
+      Model name for presentation to users
+    $ref: /schemas/types.yaml#/definitions/string
+
+patternProperties:
+  "^dai-link(@[0-9a-f]+)?$":
+    description: |
+      Node for each sound peripheral such as the speaker array, headphones jack,
+      or microphone.
+    type: object
+    $ref: tdm-slot.yaml#
+

Documentation/devicetree/bindings/sound/apple,macaudio.yaml line 110

Quoted 10 lines
Documentation/devicetree/bindings/sound/apple,macaudio.yaml new file +10 -0
+    additionalProperties: false
+
+    properties:
+      reg:
+        maxItems: 1
+
+      link-name:
+        description: |
+          Name for the peripheral, expecting 'Speaker' or 'Speakers' if this is
+          the speaker array.

If there is actual expectation, please encode it as schema, e.g.

enum: [ Speaker, Speakers ]

You can also drop | from description.

Quoted 73 lines
Documentation/devicetree/bindings/sound/apple,macaudio.yaml new file +73 -0
+        $ref: /schemas/types.yaml#/definitions/string
+
+      cpu:
+        type: object
+
+        properties:
+          sound-dai:
+            description: |
+              DAI list with CPU-side I2S ports involved in this peripheral.
+            minItems: 1
+            maxItems: 2
+
+        required:
+          - sound-dai
+
+      codec:
+        type: object
+
+        properties:
+          sound-dai:
+            minItems: 1
+            maxItems: 8
+            description: |
+              DAI list with the CODEC-side DAIs connected to the above CPU-side
+              DAIs and involved in this sound peripheral.
+
+              The list is in left/right order if applicable. If there are more
+              than one CPU-side DAIs (there can be two), the CODECs must be
+              listed first those connected to the first CPU, then those
+              connected to the second.
+
+              In addition, on some machines with many speaker codecs, the CODECs
+              are listed in this fixed order:
+
+              Four speakers: Left Front, Left Rear, Right Front, Right Rear
+              Six speakers: Left Woofer 1, Left Tweeter, Left Woofer 2,
+                            Right Woofer 1, Right Tweeter, Right Woofer 2
+
+        required:
+          - sound-dai
+
+    patternProperties:
+      "^dai-tdm-idle-mode-[0-9]$":
+        $ref: tdm-slot.yaml#/properties/dai-tdm-idle-mode
+
+      "^dai-tdm-slot-tx-idle-mask-[0-9]$":
+        $ref: /schemas/types.yaml#/definitions/uint32
+        description: Idle slot mask. A bit being set to 1 indicates
+          that the corresponding TDM slot is inactive/idle.
+
+    required:
+      - reg
+      - cpu
+      - codec
+
+required:
+  - compatible
+  - model
+
+additionalProperties: false
+
+examples:
+  - |
+    mca: mca@9b600000 {
+      compatible = "apple,t6000-mca", "apple,mca";
+      reg = <0x9b600000 0x10000>,
+            <0x9b500000 0x20000>;
+
+      clocks = <&nco 0>, <&nco 1>, <&nco 2>, <&nco 3>;
+      power-domains = <&ps_audio_p>, <&ps_mca0>, <&ps_mca1>,
+                      <&ps_mca2>, <&ps_mca3>;
+      dmas = <&admac 0>, <&admac 1>, <&admac 2>, <&admac 3>,
+             <&admac 4>, <&admac 5>, <&admac 6>, <&admac 7>,

Documentation/devicetree/bindings/sound/apple,macaudio.yaml line 193

Quoted 10 lines
Documentation/devicetree/bindings/sound/apple,macaudio.yaml new file +10 -0
+             <&admac 8>, <&admac 9>, <&admac 10>, <&admac 11>,
+             <&admac 12>, <&admac 13>, <&admac 14>, <&admac 15>;
+      dma-names = "tx0a", "rx0a", "tx0b", "rx0b",
+                  "tx1a", "rx1a", "tx1b", "rx1b",
+                  "tx2a", "rx2a", "tx2b", "rx2b",
+                  "tx3a", "rx3a", "tx3b", "rx3b";
+
+      #sound-dai-cells = <1>;
+    };
+

Other nodes rarely need to be in the example. It's not even referenced (although that also does not matter). Please drop.

Quoted 33 lines
Documentation/devicetree/bindings/sound/apple,macaudio.yaml new file +32 -0
+    sound {
+      compatible = "apple,j416-macaudio", "apple,j316-macaudio", "apple,macaudio";
+      model = "MacBook Pro J416";
+
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      dai-link@0 {
+        reg = <0>;
+        link-name = "Speakers";
+
+        dai-tdm-idle-mode-0 = "zero";
+        dai-tdm-idle-mode-3 = "zero";
+        dai-tdm-slot-tx-idle-mask-0 = <0xf0f0f0>;
+        dai-tdm-slot-tx-idle-mask-3 = <0x0f0f0f>;
+
+        cpu {
+          sound-dai = <&mca 0>, <&mca 1>;
+        };
+
+        codec {
+          sound-dai = <&speaker_left_woof1>,
+                      <&speaker_left_tweet>,
+                      <&speaker_left_woof2>,
+                      <&speaker_right_woof1>,
+                      <&speaker_right_tweet>,
+                      <&speaker_right_woof2>;
+        };
+      };
+
+      dai-link@1 {
+        reg = <1>;

Documentation/devicetree/bindings/sound/apple,macaudio.yaml line 235

Quoted 10 lines
Documentation/devicetree/bindings/sound/apple,macaudio.yaml new file +10 -0
+        link-name = "Headphones Jack";
+
+        cpu {
+          sound-dai = <&mca 2>;
+        };
+        codec {
+          sound-dai = <&jack_codec>;
+        };
+      };
+    };

Best regards,
Krzysztof

#47 lore raw

Re: [PATCH 16/28] ASoC: apple: Add macaudio machine driver

In reply to Mark Brown

Hi Mark,

Quoted 13 lines · Australian Eastern Standard Time Mark Brown

sound/soc/apple/macaudio.c line 295

Quoted 8 lines
sound/soc/apple/macaudio.c new file +7 -0
+static void macaudio_vlimit_update(struct macaudio_snd_data *ma)
+{
 
+
+	/* Check that *every* limited control is locked by the same owner */
+	list_for_each_entry(kctl, &ma->card.snd_card->controls, list) {
+		if (!snd_soc_control_matches(kctl, volume_control_names[ma->cfg->amp]))
+			continue;

This is used from the volume limit timeout work which doesn't hold the controls_rwsem, userspace can add or remove user controls which would change the list so the work needs to lock the controls list.

Would it be sufficient to scoped_guard the controls_rwsem wherever we use this pattern?

Quoted 11 lines
Quoted 11 lines
sound/soc/apple/macaudio.c new file +11 -0
+static int macaudio_dpcm_hw_params(struct snd_pcm_substream *substream,
+				   struct snd_pcm_hw_params *params)
+{
+	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
+	struct macaudio_snd_data *ma = snd_soc_card_get_drvdata(rtd->card);
+	struct macaudio_link_props *props = &ma->link_props[rtd->dai_link->id];
+	struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
+	struct snd_interval *rate = hw_param_interval(params,
+						      SNDRV_PCM_HW_PARAM_RATE);
+	int bclk_ratio = macaudio_get_runtime_bclk_ratio(substream);
+	int i;
Quoted 8 lines

sound/soc/apple/macaudio.c line 799

Quoted 5 lines
sound/soc/apple/macaudio.c new file +5 -0
+
+	if (props->is_sense) {
+		rate->min = rate->max = cpu_dai->symmetric_rate;
+		return 0;
+	}

It feels like this DAI ought to have separate ops... Also, for the sense link will we definitely already have a rate set up?

AIUI, the cpu rate should always be set up by the time we hit this path as it is only taken when setting up the VISENSE FE (after the playback stuff is already set up).

maintainer
#48 lore raw

Re: [PATCH 16/28] ASoC: apple: Add macaudio machine driver

Quoted 10 lines · James Calligeros
Quoted 7 lines · Australian Eastern Standard Time Mark Brown

sound/soc/apple/macaudio.c line 295

Quoted 3 lines
sound/soc/apple/macaudio.c new file +3 -0
+	list_for_each_entry(kctl, &ma->card.snd_card->controls, list) {
+		if (!snd_soc_control_matches(kctl, volume_control_names[ma->cfg->amp]))
+			continue;

This is used from the volume limit timeout work which doesn't hold the controls_rwsem, userspace can add or remove user controls which would change the list so the work needs to lock the controls list.

Quoted 2 lines

Would it be sufficient to scoped_guard the controls_rwsem wherever we use this pattern?

I think so, but I didn't properly check.

Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
sound/soc/apple/macaudio.c new file +11 -0
+static int macaudio_dpcm_hw_params(struct snd_pcm_substream *substream,
+				   struct snd_pcm_hw_params *params)
+{
+	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
+	struct macaudio_snd_data *ma = snd_soc_card_get_drvdata(rtd->card);
+	struct macaudio_link_props *props = &ma->link_props[rtd->dai_link->id];
+	struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
+	struct snd_interval *rate = hw_param_interval(params,
+						      SNDRV_PCM_HW_PARAM_RATE);
+	int bclk_ratio = macaudio_get_runtime_bclk_ratio(substream);
+	int i;
Quoted 8 lines

sound/soc/apple/macaudio.c line 799

Quoted 5 lines
sound/soc/apple/macaudio.c new file +5 -0
+
+	if (props->is_sense) {
+		rate->min = rate->max = cpu_dai->symmetric_rate;
+		return 0;
+	}

It feels like this DAI ought to have separate ops... Also, for the sense link will we definitely already have a rate set up?

Quoted 3 lines

AIUI, the cpu rate should always be set up by the time we hit this path as it is only taken when setting up the VISENSE FE (after the playback stuff is already set up).

Is that something we actually enforce or is that just a thing a sensible userspace should do? I can see something racing.

#22 lore raw

Re: [PATCH 08/28] ALSA: control: Add kcontrol callbacks for lock/unlock

In reply to James Calligeros
Quoted 9 lines · James Calligeros

From: Hector Martin <[email protected]>

This allows drivers to implement policy around locking/unlocking controls, such as enforcing that a group of controls may only be locked by the same process/file, and taking actions when the controls lock/unlock (such as granting special access on lock and resetting values on unlock).

Quoted 8 lines

This is, in particular, useful to implement volume safety controls, such that only a particular process (that locks controls and completes a handshake) may increase volumes above a given safe limit. It also allows the volume to be automatically lowered if that process dies (which will trigger an implicit unlock).

This doesn't sound like a good approach to me, and this looks rather irrelevant with the purpose of the series.

thanks,

Takashi

#49 lore raw

Re: [PATCH 16/28] ASoC: apple: Add macaudio machine driver

In reply to Mark Brown
Quoted 2 lines · Australian Eastern Standard Time Mark Brown
Quoted 1 line · James Calligeros

On Tuesday, 22 September 2026 7:38:54 pm Australian Eastern Standard Time

Quoted 9 lines · Mark Brown
Quoted 9 lines
Quoted 8 lines

Review

Quoted 4 lines
(quoted diff) +2 -0
+	list_for_each_entry(kctl, &ma->card.snd_card->controls, list) {
+		if (!snd_soc_control_matches(kctl,

volume_control_names[ma->cfg->amp]))

(quoted diff) +1 -0
+			continue;

This is used from the volume limit timeout work which doesn't hold the controls_rwsem, userspace can add or remove user controls which would change the list so the work needs to lock the controls list.

Quoted 5 lines
Quoted 2 lines

Would it be sufficient to scoped_guard the controls_rwsem wherever we use this pattern?

I think so, but I didn't properly check.

I did some testing of this and it causes deadlocks if we try to take the semaphore from inside the workqueue. I believe it is related to the fact that speakersafetyd has a blocking handle to the controls open at all times. This may be fixable by simply having speakersafetyd take a nonblocking handle instead. I will do some more testing before submitting v2.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

+static int macaudio_dpcm_hw_params(struct snd_pcm_substream *substream,

(quoted diff) +2 -0
+				   struct snd_pcm_hw_params *params)
+{
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

sound/soc/apple/macaudio.c line 795

Quoted 8 lines
(quoted diff) +1 -0
+	struct snd_soc_pcm_runtime *rtd =

snd_soc_substream_to_rtd(substream);

(quoted diff) +2 -0
+	struct macaudio_snd_data *ma = snd_soc_card_get_drvdata(rtd->card);
+	struct macaudio_link_props *props =

&ma->link_props[rtd->dai_link->id];

sound/soc/apple/macaudio.c new file +3 -0
+	struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
+	struct snd_interval *rate = hw_param_interval(params,
+						      

SNDRV_PCM_HW_PARAM_RATE);

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

sound/soc/apple/macaudio.c line 799

Quoted 7 lines
sound/soc/apple/macaudio.c new file +7 -0
+	int bclk_ratio = macaudio_get_runtime_bclk_ratio(substream);
+	int i;
+
+	if (props->is_sense) {
+		rate->min = rate->max = cpu_dai->symmetric_rate;
+		return 0;
+	}

It feels like this DAI ought to have separate ops... Also, for the sense link will we definitely already have a rate set up?

Quoted 6 lines
Quoted 3 lines

AIUI, the cpu rate should always be set up by the time we hit this path as it is only taken when setting up the VISENSE FE (after the playback stuff is already set up).

Is that something we actually enforce or is that just a thing a sensible userspace should do? I can see something racing.

We don't really enforce it. speakersafetyd is the only thing that opens the VISENSE PCM and does a blocking read of samples
which only starts and subsequently completes after the "real" PCM is configured and playback begins. The sample rate is reliably reflected to speakersafetyd via the kcontrol on the VISENSE PCM. We have not experienced any race issues with this arrangement in ~5 years nor has anyone reported any to us. I'm happy to take pointers on how we should be doing this if the current approach won't fly.

maintainer
#50 lore raw

Re: [PATCH 16/28] ASoC: apple: Add macaudio machine driver

Quoted 20 lines · James Calligeros
Quoted 11 lines · Australian Eastern Standard Time Mark Brown
Quoted 9 lines · James Calligeros

On Tuesday, 22 September 2026 7:38:54 pm Australian Eastern Standard Time

Quoted 7 lines

sound/soc/apple/macaudio.c line 799

Quoted 4 lines
sound/soc/apple/macaudio.c new file +4 -0
+	if (props->is_sense) {
+		rate->min = rate->max = cpu_dai->symmetric_rate;
+		return 0;
+	}

It feels like this DAI ought to have separate ops... Also, for the sense link will we definitely already have a rate set up?

Quoted 6 lines
Quoted 3 lines

AIUI, the cpu rate should always be set up by the time we hit this path as it is only taken when setting up the VISENSE FE (after the playback stuff is already set up).

Is that something we actually enforce or is that just a thing a sensible userspace should do? I can see something racing.

Quoted 8 lines

We don't really enforce it. speakersafetyd is the only thing that opens the VISENSE PCM and does a blocking read of samples
which only starts and subsequently completes after the "real" PCM is configured and playback begins. The sample rate is reliably reflected to speakersafetyd via the kcontrol on the VISENSE PCM. We have not experienced any race issues with this arrangement in ~5 years nor has anyone reported any to us. I'm happy to take pointers on how we should be doing this if the current approach won't fly.

You could just return an error if there's no rate set, it sounds like your actual userspace will DTRT anyway.

#23 lore raw

Re: [PATCH 08/28] ALSA: control: Add kcontrol callbacks for lock/unlock

In reply to Takashi Iwai
Quoted 17 lines · Australian Eastern Standard Time Takashi Iwai

On Sun, 20 Sep 2026 06:53:47 +0200,

Quoted 14 lines · James Calligeros

From: Hector Martin <[email protected]>

This allows drivers to implement policy around locking/unlocking controls, such as enforcing that a group of controls may only be locked by the same process/file, and taking actions when the controls lock/unlock (such as granting special access on lock and resetting values on unlock).

This is, in particular, useful to implement volume safety controls, such that only a particular process (that locks controls and completes a handshake) may increase volumes above a given safe limit. It also allows the volume to be automatically lowered if that process dies (which will trigger an implicit unlock).

Quoted 5 lines
Quoted 2 lines

This doesn't sound like a good approach to me, and this looks rather irrelevant with the purpose of the series.

I'm not sure what you mean by it being irrelevant. A significant portion of the machine driver is dedicated to implementing safety interlocks based on the functionality added via this patch. It would be impossible to prevent badly-behaving users{,pace} from defeating the safety guarantees made by speakersafetyd (and thus permanently damaging the machine) without giving speakersafetd exclusive ownership over the safety interlock kcontrol.

Is there something specific about this approach that you do not like?

Quoted 4 lines

thanks,

Takashi

James

#24 lore raw

Re: [PATCH 08/28] ALSA: control: Add kcontrol callbacks for lock/unlock

Quoted 26 lines · James Calligeros
Quoted 17 lines · Australian Eastern Standard Time Takashi Iwai

On Sun, 20 Sep 2026 06:53:47 +0200,

Quoted 14 lines · James Calligeros

From: Hector Martin <[email protected]>

This allows drivers to implement policy around locking/unlocking controls, such as enforcing that a group of controls may only be locked by the same process/file, and taking actions when the controls lock/unlock (such as granting special access on lock and resetting values on unlock).

This is, in particular, useful to implement volume safety controls, such that only a particular process (that locks controls and completes a handshake) may increase volumes above a given safe limit. It also allows the volume to be automatically lowered if that process dies (which will trigger an implicit unlock).

Quoted 5 lines
Quoted 2 lines

This doesn't sound like a good approach to me, and this looks rather irrelevant with the purpose of the series.

Quoted 6 lines

I'm not sure what you mean by it being irrelevant. A significant portion of the machine driver is dedicated to implementing safety interlocks based on the functionality added via this patch. It would be impossible to prevent badly-behaving users{,pace} from defeating the safety guarantees made by speakersafetyd (and thus permanently damaging the machine) without giving speakersafetd exclusive ownership over the safety interlock kcontrol.

Improving the lock/unlock itself can be an interesting idea (but we should do in a different way instead of blindly extending each kernel control ops). OTOH, the whole implementation of the driver and the feature depending on that stuff sounds rather fragile.

thanks,

Takashi

#25 lore raw

Re: [PATCH 08/28] ALSA: control: Add kcontrol callbacks for lock/unlock

Quoted 36 lines · Takashi Iwai
Quoted 26 lines · James Calligeros
Quoted 17 lines · Australian Eastern Standard Time Takashi Iwai

On Sun, 20 Sep 2026 06:53:47 +0200,

Quoted 14 lines · James Calligeros

From: Hector Martin <[email protected]>

This allows drivers to implement policy around locking/unlocking controls, such as enforcing that a group of controls may only be locked by the same process/file, and taking actions when the controls lock/unlock (such as granting special access on lock and resetting values on unlock).

This is, in particular, useful to implement volume safety controls, such that only a particular process (that locks controls and completes a handshake) may increase volumes above a given safe limit. It also allows the volume to be automatically lowered if that process dies (which will trigger an implicit unlock).

Quoted 5 lines
Quoted 2 lines

This doesn't sound like a good approach to me, and this looks rather irrelevant with the purpose of the series.

Quoted 6 lines

I'm not sure what you mean by it being irrelevant. A significant portion of the machine driver is dedicated to implementing safety interlocks based on the functionality added via this patch. It would be impossible to prevent badly-behaving users{,pace} from defeating the safety guarantees made by speakersafetyd (and thus permanently damaging the machine) without giving speakersafetd exclusive ownership over the safety interlock kcontrol.

Quoted 4 lines

Improving the lock/unlock itself can be an interesting idea (but we should do in a different way instead of blindly extending each kernel control ops). OTOH, the whole implementation of the driver and the feature depending on that stuff sounds rather fragile.

Also, if you want a locking by user-space, how about to simply provide a boolean control element for locking, instead of extending the whole API and infrastructure? The control can be taken exclusively for a process, and the driver just blocks the operations from others while the flag is set via that kcontrol.

Takashi