Skip to contentSkip to conversation

Add speaker and headset jack support for Apple Silicon Macs

PATCH Superseded James Calligeros 7 participants 60 messages Oct 4 – Oct 19

Subsystems (7)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover Add speaker and headset jack support for Apple Silicon Macs

Hi folks,

This series adds the machine driver and related bindings for the primary audio subsystem on Apple Silicon Macs. The macaudio machine driver 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 and 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. Every machine also includes a headset jack, and some also have their own builtin microphones which are handled by a separate coprocessor with its own driver.

Many functions which are handled by firmware on other platforms must be handled by the kernel or by userspace. Most notably, speaker protection is handled by speakersafetyd[2], a userspace daemon. Speaker protection is handled in userspace due to the expensive floating point calculations and amount of per-machine configuration data required.

The 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 significantly attenuate and lock the gains of every connected speaker unless speakersafetyd is running.

Version 2 of this series drops numerous fixes and semi-related patches that are not strictly necessary for the machine driver to function correctly. These will be resubmitted at a later date.

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

---
Changes in v2:
- Drop patches that are only tangentially related (will be submitted later)
- Drop wildcard-matching API for kctls
- Relabel J473 sound model to Mac mini
- Align Devicetree changes with upstream bindings
- Relax Cirrus CS42L42 required properties to keep DT style checker happy
- Define missing properties in CS42L{42,84} bindings
- Fix mistyped DT properties
- Improve macaudio DT binding description
- Drop generic fallback compatible for apple,macaudio
- Drop now-redundant descriptions from other compatibles
- Constrain DAI link link-name property with an enum of valid values
- Drop MCA node from macaudio binding example
- Fix heading comment style in macaudio
- Drop obsolete module parameter
- Replace string functions with safer variants
- Replace dropped wildcard API with searching for full kctl name
- Rework idle props parsing to better surface errors/invalid Devicetree entries
- Add additional locking to backend setup
- Take controls_rwsem when safety functions are called from workqueues
- Replace all mutex{,un}lock calls with guard/scoped_guard
- Fix incorrect amp gain value for j37x config struct
- static const-ify all config structs
- Cancel control lock update workqueue on teardown
- Drop unused DAPM widget
- Fix commented-out safe volume calculations
- Drop speaker lock kcontrol ownership checks and related core API extension
- Link to v1: https://patch.msgid.link/[email protected]

To: David Rhodes <[email protected]>
To: Richard Fitzgerald <[email protected]>
To: Martin Povišer <[email protected]>
To: Liam Girdwood <[email protected]>
To: Mark Brown <[email protected]>
To: Rob Herring <[email protected]>
To: Krzysztof Kozlowski <[email protected]>
To: Conor Dooley <[email protected]>
To: James Calligeros <[email protected]>
To: Jaroslav Kysela <[email protected]>
To: Takashi Iwai <[email protected]>
To: Matthias Brugger <[email protected]>
To: AngeloGioacchino Del Regno <[email protected]>
To: Shenghao Ding <[email protected]>
To: Kevin Lu <[email protected]>
To: Baojun Xu <[email protected]>
To: Sen Wang <[email protected]>
To: Sven Peter <[email protected]>
To: Janne Grunau <[email protected]>
To: Neal Gompa <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

---
James Calligeros (16):
ASoC: dt-bindings: cs42l84: Document sound-name-prefix property
ASoC: dt-bindings: cs42l42: Do not require chip power supplies
ASoC: dt-bindings: cs42l42: Document #sound-dai-cells property
ASoC: dt-bindings: cs42l42: Document sound-name-prefix property
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 (5):
ASoC: dt-bindings: Add binding for Apple Silicon Mac audio
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   |  210 +++
 .../bindings/sound/cirrus,cs42l42.yaml   |   11 +-
 .../bindings/sound/cirrus,cs42l84.yaml   |    3 +
 .../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  |  135 ++
 .../arm64/boot/dts/apple/t600x-j375.dtsi |   65 +
 .../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 |   67 +
 arch/arm64/boot/dts/apple/t8103-j293.dts |  111 ++
 arch/arm64/boot/dts/apple/t8103-j313.dts |   82 ++
 arch/arm64/boot/dts/apple/t8103-j456.dts |   38 +
 arch/arm64/boot/dts/apple/t8103-j457.dts |   38 +
 arch/arm64/boot/dts/apple/t8112-j413.dts |  108 ++
 arch/arm64/boot/dts/apple/t8112-j415.dts |  132 ++
 arch/arm64/boot/dts/apple/t8112-j473.dts |   62 +
 arch/arm64/boot/dts/apple/t8112-j493.dts |  108 ++
 include/sound/soc-card.h                 |    2 +-
 include/sound/soc.h                      |    6 +-
 sound/soc/apple/Kconfig                  |   18 +
 sound/soc/apple/Makefile                 |    4 +
 sound/soc/apple/macaudio.c               | 1699 +++++++++++++++++++++++++
 .../soc/mediatek/mt8188/mt8188-mt6359.c  |    4 +-
 sound/soc/soc-card.c                     |   12 +-
 sound/soc/soc-core.c                     |    5 +-
 sound/soc/soc-ops.c                      |  103 ++
 38 files changed, 3121 insertions(+), 12 deletions(-)

---
base-commit: 74612d0b448fe745e80cda87fe49ac3c102ccc1f
change-id: 20260915-macaudio-33c1c4f304da

Best regards,

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

PATCH v2 1/21 ASoC: dt-bindings: cs42l84: Document sound-name-prefix property

Some consumers may wish to prepend the codec's name with a known value to identify a specific codec among many. Enable this with the common sound-name-prefix property.

---
 .../bindings/sound/cirrus,cs42l84.yaml   | 3 +++
 1 file changed, 3 insertions(+)
Documentation/devicetree/bindings/sound/cirrus,cs42l84.yaml +3 -0
index 94062c1d9d45..2637aa5f4326 100644
@@ -32,6 +32,9 @@ properties:
   '#sound-dai-cells':
     const: 0
 
+  sound-name-prefix:
+    $ref: component-common.yaml#/properties/sound-name-prefix
+
 required:
   - compatible
   - reg
Signature · 1 line
2.55.0
#3 lore raw

PATCH v2 2/21 ASoC: dt-bindings: cs42l42: Do not require chip power supplies

In reply to James Calligeros

Some integrators do not expose the power rails connected to the codec in a way that can be expressed in the Devicetree. Do not require them to be specified on such platforms.

---
 .../bindings/sound/cirrus,cs42l42.yaml   | 5 -----
 1 file changed, 5 deletions(-)
Documentation/devicetree/bindings/sound/cirrus,cs42l42.yaml +0 -5
index ab4c7d22dc0e..6c100cb36699 100644
@@ -187,11 +187,6 @@ properties:
 required:
   - compatible
   - reg
-  - VP-supply
-  - VCP-supply
-  - VD_FILT-supply
-  - VL-supply
-  - VA-supply
 
 additionalProperties: false
 
Signature · 1 line
2.55.0
#7 lore raw

PATCH v2 3/21 ASoC: dt-bindings: cs42l42: Document #sound-dai-cells property

In reply to James Calligeros

We may need to define #sound-dai-cells on some machines where this codec is part of a simple DAI. Document this property to keep the style checker happy.

---
 .../bindings/sound/cirrus,cs42l42.yaml   | 3 +++
 1 file changed, 3 insertions(+)
Documentation/devicetree/bindings/sound/cirrus,cs42l42.yaml +3 -0
index 6c100cb36699..bc759eaadeca 100644
@@ -26,6 +26,9 @@ properties:
       The I2C address of the CS42L42.
     maxItems: 1
 
+  '#sound-dai-cells':
+    const: 0
+
   VP-supply:
     description:
       VP power supply.
Signature · 1 line
2.55.0
#9 lore raw

PATCH v2 4/21 ASoC: dt-bindings: cs42l42: Document sound-name-prefix property

In reply to James Calligeros

Some consumers may wish to prepend the codec's name with a known value to identify a specific codec among many. Enable this with the common sound-name-prefix property.

---
 .../bindings/sound/cirrus,cs42l42.yaml   | 3 +++
 1 file changed, 3 insertions(+)
Documentation/devicetree/bindings/sound/cirrus,cs42l42.yaml +3 -0
index bc759eaadeca..035463be1456 100644
@@ -29,6 +29,9 @@ properties:
   '#sound-dai-cells':
     const: 0
 
+  sound-name-prefix:
+    $ref: component-common.yaml#/properties/sound-name-prefix
+
   VP-supply:
     description:
       VP power supply.
Signature · 1 line
2.55.0
#11 lore raw

PATCH v2 5/21 ASoC: dt-bindings: Add binding for Apple Silicon Mac audio

In reply to James Calligeros

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

Add a binding for the primary audio subsystem found on Apple Silicon Macs. This binding integrates the codecs and SoC I2S peripheral used for driving the headset jack and speaker arrays on all Apple Silicon Macs. The internal microphones on this platform are connected to a distinct coprocessor and are not part of this "main" audio subsystem.

---
 .../bindings/sound/apple,macaudio.yaml   | 210 +++++++++++++++++++++++++
 1 file changed, 210 insertions(+)
Documentation/devicetree/bindings/sound/apple,macaudio.yaml new file +210 -0
new file mode 100644
index 000000000000..c0a04fab82d3
@@ -0,0 +1,210 @@
+# 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:
+  The speakers and headphone jack on Apple Silicon Macs are
+  part of an integrated audio subsystem comprising of Apple's
+  I2S peripheral (MCA) and a series of codecs. The machines
+  have a wide variety of topologies ranging from a simple
+  mono speaker in the desktops to complex stereo arrays with
+  dual-opposed woofers and tweeters all driven by their own
+  mono amplifiers. This arrangement can be expressed as a
+  set of DAI links, where the MCA ports each codec is connected
+  to are represented by the CPU side of the link.
+
+maintainers:
+  - James Calligeros <[email protected]>
+
+properties:
+  compatible:
+    oneOf:
+      - 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
+      - items:
+          - enum:
+              - apple,j493-macaudio
+          - const: apple,j293-macaudio
+      - items:
+          - enum:
+              - apple,j414-macaudio
+              - apple,j504-macaudio
+              - apple,j514-macaudio
+          - const: apple,j314-macaudio
+      - items:
+          - enum:
+              - apple,j416-macaudio
+              - apple,j516-macaudio
+          - const: apple,j316-macaudio
+      - items:
+          - enum:
+              - apple,j475-macaudio
+              - apple,j575-macaudio
+          - const: apple,j375-macaudio
+      - items:
+          - enum:
+              - apple,j613-macaudio
+          - const: apple,j413-macaudio
+      - items:
+          - enum:
+              - apple,j615-macaudio
+          - const: apple,j415-macaudio
+      - items:
+          - enum:
+              - apple,j474-macaudio
+          - const: apple,j473-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
+        enum: [ Headphone Jack, Speaker, Speakers ]
+        $ref: /schemas/types.yaml#/definitions/string
+
+      codec:
+        type: object
+
+        additionalProperties: false
+
+        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
+
+      cpu:
+        type: object
+
+        additionalProperties: false
+
+        properties:
+          sound-dai:
+            minItems: 1
+            maxItems: 2
+            description: |
+              DAI list with CPU-side I2S ports involved in this peripheral.
+
+        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
+      - codec
+      - cpu
+
+required:
+  - compatible
+  - model
+
+additionalProperties: false
+
+examples:
+  - |
+    sound {
+      compatible = "apple,j416-macaudio", "apple,j316-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>;
+
+        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 {
+        reg = <1>;
+        link-name = "Headphone Jack";
+
+        codec {
+          sound-dai = <&jack_codec>;
+        };
+
+        cpu {
+          sound-dai = <&mca 2>;
+        };
+      };
+    };
Signature · 1 line
2.55.0
#17 lore raw

PATCH v2 6/21 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. It is something a machine driver may call in fixup_controls.

---
 include/sound/soc.h |  2 ++
 sound/soc/soc-ops.c | 34 +++++++++++++++++++++++++
 2 files changed, 36 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 +34 -0
index 142f407e3939..4d799c5e44f1 100644
@@ -471,6 +471,40 @@ 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 control matching a name
+ *
+ * @card: where to look for the controls
+ * @name: name
+ * @active: non-zero to activate, zero to deactivate
+ *
+ * Return 0 for success, else error.
+ */
+int snd_soc_deactivate_kctl(struct snd_soc_card *card,
+	const char *name, int active)
+{
+	struct snd_kcontrol *kctl;
+	int ret = -EINVAL;
+
+	/* Sanity check for name */
+	if (unlikely(!name))
+		return -EINVAL;
+
+	kctl = snd_soc_card_get_kcontrol(card, name);
+
+	if (kctl) {
+		ret = snd_ctl_activate_id(card->snd_card, &kctl->id, active);
+		if (ret < 0)
+			return ret;
+	} else {
+		dev_dbg(card->dev, "Tried to de/activate unknown control '%s'\n",
+			name);
+	}
+
+	return ret;
+}
+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
#20 lore raw

PATCH v2 7/21 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. It is something a machine driver may call in fixup_controls.

---
 include/sound/soc.h |  2 +
 sound/soc/soc-ops.c | 69 +++++++++++++++++++++++++
 2 files changed, 71 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 +69 -0

75 lines not on this page · raw message

Signature · 1 line
2.55.0
#24 lore raw

PATCH v2 8/21 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
#29 lore raw

PATCH v2 9/21 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    |   18 +
 sound/soc/apple/Makefile   |    4 +
 sound/soc/apple/macaudio.c | 1699 +++++++++++++++++++++++++
 3 files changed, 1721 insertions(+)
sound/soc/apple/Kconfig +18 -0
index f1d071a99fbf..549a5f4906c5 100644
@@ -9,4 +9,22 @@ 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 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..90ad83adc588 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-y	:= macaudio.o
+
+obj-$(CONFIG_SND_SOC_APPLE_MACAUDIO)	+= snd-soc-macaudio.o
sound/soc/apple/macaudio.c new file +1699 -0

1,699 lines not on this page · raw message

Signature · 1 line
2.55.0
#36 lore raw

PATCH v2 10/21 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 | 67 +++++++++++++++++++++++++
 1 file changed, 67 insertions(+)
arch/arm64/boot/dts/apple/t8103-j274.dts +67 -0
index 1212852251e0..6121e3a89a0f 100644
@@ -75,4 +75,71 @@ &i2c2 {
 	status = "okay";
 };
 
+/* Audio codecs */
+&i2c1 {
+	status = "okay";
+
+	speaker: codec@31 {
+		compatible = "ti,tas5770l";
+		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";
+		model = "Mac mini J274";
+
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		dai-link@0 {
+			reg = <0>;
+
+			link-name = "Speaker";
+
+			codec {
+				sound-dai = <&speaker>;
+			};
+
+			cpu {
+				sound-dai = <&mca 0>;
+			};
+		};
+
+		dai-link@1 {
+			reg = <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
#39 lore raw

PATCH v2 11/21 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 | 82 +++++++++++++++++++++++++
 1 file changed, 82 insertions(+)
arch/arm64/boot/dts/apple/t8103-j313.dts +82 -0
index f8b2b1637b9d..cdda63ca8b34 100644
@@ -55,4 +55,86 @@ &typec1 {
 	label = "USB-C Left-front";
 };
 
+/* Audio codecs */
+&i2c1 {
+	status = "okay";
+
+	speaker_left: codec@31 {
+		compatible = "ti,tas5770l";
+		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";
+		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";
+		model = "MacBook Air J313";
+
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		dai-link@0 {
+			reg = <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 {
+			reg = <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
#44 lore raw

PATCH v2 12/21 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 | 111 +++++++++++++++++++++++++
 1 file changed, 111 insertions(+)
arch/arm64/boot/dts/apple/t8103-j293.dts +111 -0
index 1d074b9e6018..42f1127151fa 100644
@@ -133,5 +133,116 @@ &displaydfr_dart {
 	status = "okay";
 };
 
+/* Audio codecs */
+&i2c1 {
+	status = "okay";
+
+	speaker_left_rear: codec@31 {
+		compatible = "ti,tas5770l";
+		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";
+		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";
+		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";
+		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";
+		model = "MacBook Pro J293";
+
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		dai-link@0 {
+			reg = <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 {
+			reg = <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
#46 lore raw

PATCH v2 13/21 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 | 38 +++++++++++++++++++++++++
 arch/arm64/boot/dts/apple/t8103-j457.dts | 38 +++++++++++++++++++++++++
 2 files changed, 76 insertions(+)
arch/arm64/boot/dts/apple/t8103-j456.dts +38 -0
index 090c97bb781b..1fc74ebf9ab2 100644
@@ -88,3 +88,41 @@ &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";
+		model = "iMac J456";
+
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		dai-link@1 {
+			reg = <1>;
+
+			link-name = "Headphone Jack";
+
+			codec {
+				sound-dai = <&jack_codec>;
+			};
+
+			cpu {
+				sound-dai = <&mca 2>;
+			};
+		};
+	};
+};
arch/arm64/boot/dts/apple/t8103-j457.dts +38 -0
index ebddde75455c..d8ea6bb53b3f 100644
@@ -69,3 +69,41 @@ 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";
+		model = "iMac J457";
+
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		dai-link@1 {
+			reg = <1>;
+
+			link-name = "Headphone Jack";
+
+			codec {
+				sound-dai = <&jack_codec>;
+			};
+
+			cpu {
+				sound-dai = <&mca 2>;
+			};
+		};
+	};
+};
Signature · 1 line
2.55.0
#49 lore raw

PATCH v2 14/21 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 | 108 +++++++++++++++++++++++++
 1 file changed, 108 insertions(+)
arch/arm64/boot/dts/apple/t8112-j413.dts +108 -0
index 7ccfceb08093..5f8768832e1e 100644
@@ -92,4 +92,112 @@ &fpwm1 {
 	status = "okay";
 };
 
+/* Audio codecs */
+&i2c1 {
+	status = "okay";
+
+	speaker_left_woof: codec@38 {
+		compatible = "ti,sn012776";
+		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";
+		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";
+		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";
+		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 Tweeter";
+		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";
+		model = "MacBook Air J413";
+
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		dai-link@0 {
+			reg = <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 {
+			reg = <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
#50 lore raw

PATCH v2 15/21 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 | 132 +++++++++++++++++++++++++
 1 file changed, 132 insertions(+)
arch/arm64/boot/dts/apple/t8112-j415.dts +132 -0
index fdc3409d2e07..4f3db2a93db0 100644
@@ -92,4 +92,136 @@ &fpwm1 {
 	status = "okay";
 };
 
+/* Audio codecs */
+&i2c1 {
+	status = "okay";
+
+	speaker_left_woof1: codec@38 {
+		compatible = "ti,sn012776";
+		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";
+		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";
+		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";
+		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";
+		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";
+		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";
+		model = "MacBook Air J415";
+
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		dai-link@0 {
+			reg = <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 {
+			reg = <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
#52 lore raw

PATCH v2 16/21 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 | 62 +++++++++++++++++++++++++
 1 file changed, 62 insertions(+)
arch/arm64/boot/dts/apple/t8112-j473.dts +62 -0
index 105a9d118980..36f06c6e385d 100644
@@ -85,4 +85,66 @@ &typec1 {
 	label = "USB-C Back-right";
 };
 
+/* Audio codecs */
+&i2c1 {
+	status = "okay";
+
+	speaker: codec@38 {
+		compatible = "ti,sn012776";
+		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";
+		model = "Mac mini J473";
+
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		dai-link@0 {
+			reg = <0>;
+
+			link-name = "Speakers";
+
+			codec {
+				sound-dai = <&speaker>;
+			};
+
+			cpu {
+				sound-dai = <&mca 0>;
+			};
+		};
+
+		dai-link@1 {
+			reg = <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 v2 17/21 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 | 108 +++++++++++++++++++++++++
 1 file changed, 108 insertions(+)
arch/arm64/boot/dts/apple/t8112-j493.dts +108 -0
index 7cea5c594810..8993775da9ab 100644
@@ -147,5 +147,113 @@ touchbar0: touchbar@0 {
 	};
 };
 
+/* Audio codecs */
+&i2c1 {
+	status = "okay";
+
+	speaker_left_rear: codec@38 {
+		compatible = "ti,sn012776";
+		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";
+		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";
+		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";
+		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,j293-macaudio";
+		model = "MacBook Pro J493";
+
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		dai-link@0 {
+			reg = <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 {
+			reg = <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
#54 lore raw

PATCH v2 18/21 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  | 135 +++++++++++++++++++++++++
 5 files changed, 155 insertions(+)
arch/arm64/boot/dts/apple/t6000-j314s.dts +5 -0
index 1430b91ff1b1..63ae47ea46e6 100644
@@ -24,3 +24,8 @@ &wifi0 {
 &bluetooth0 {
 	brcm,board-type = "apple,maldives";
 };
+
+&sound {
+	compatible = "apple,j314-macaudio";
+	model = "MacBook Pro J314";
+};
arch/arm64/boot/dts/apple/t6000-j316s.dts +5 -0
index da0cbe7d9673..c8428fbf9244 100644
@@ -24,3 +24,8 @@ &wifi0 {
 &bluetooth0 {
 	brcm,board-type = "apple,madagascar";
 };
+
+&sound {
+	compatible = "apple,j316-macaudio";
+	model = "MacBook Pro J316";
+};
arch/arm64/boot/dts/apple/t6001-j314c.dts +5 -0
index c37097dcfdb3..05066cbde96b 100644
@@ -24,3 +24,8 @@ &wifi0 {
 &bluetooth0 {
 	brcm,board-type = "apple,maldives";
 };
+
+&sound {
+	compatible = "apple,j314-macaudio";
+	model = "MacBook Pro J314";
+};
arch/arm64/boot/dts/apple/t6001-j316c.dts +5 -0
index 3bc6e0c3294c..ee0339b61713 100644
@@ -24,3 +24,8 @@ &wifi0 {
 &bluetooth0 {
 	brcm,board-type = "apple,madagascar";
 };
+
+&sound {
+	compatible = "apple,j316-macaudio";
+	model = "MacBook Pro J316";
+};
arch/arm64/boot/dts/apple/t600x-j314-j316.dtsi +135 -0

147 lines not on this page · raw message

Signature · 1 line
2.55.0
#56 lore raw

PATCH v2 19/21 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 | 65 +++++++++++++++++++++++++
 3 files changed, 75 insertions(+)
arch/arm64/boot/dts/apple/t6001-j375c.dts +5 -0
index 08276114c1d8..2e544f43b085 100644
@@ -25,4 +25,9 @@ &bluetooth0 {
 	brcm,board-type = "apple,okinawa";
 };
 
+&sound {
+	compatible = "apple,j375-macaudio";
+	model = "Mac Studio J375";
+};
+
 #include "hwmon-fan-dual.dtsi"
arch/arm64/boot/dts/apple/t6002-j375d.dts +5 -0
index e6eb6b6c386d..dfdf90fb1825 100644
@@ -184,6 +184,11 @@ atcphy5_usb3: endpoint {
 	};
 };
 
+&sound {
+	compatible = "apple,j375-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 +65 -0

75 lines not on this page · raw message

Signature · 1 line
2.55.0
#57 lore raw

PATCH v2 20/21 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..2df6a39c719d 100644
@@ -24,3 +24,8 @@ &wifi0 {
 &bluetooth0 {
 	brcm,board-type = "apple,tokara";
 };
+
+&sound {
+	compatible = "apple,j414-macaudio", "apple,j314-macaudio";
+	model = "MacBook Pro J414";
+};
arch/arm64/boot/dts/apple/t6020-j416s.dts +5 -0
index c277ed5889a2..7f3f0d6eee87 100644
@@ -24,3 +24,8 @@ &wifi0 {
 &bluetooth0 {
 	brcm,board-type = "apple,amami";
 };
+
+&sound {
+	compatible = "apple,j416-macaudio", "apple,j316-macaudio";
+	model = "MacBook Pro J416";
+};
arch/arm64/boot/dts/apple/t6021-j414c.dts +5 -0
index cdcf0740714d..ec4050ec0ecf 100644
@@ -24,3 +24,8 @@ &wifi0 {
 &bluetooth0 {
 	brcm,board-type = "apple,tokara";
 };
+
+&sound {
+	compatible = "apple,j414-macaudio", "apple,j314-macaudio";
+	model = "MacBook Pro J414";
+};
arch/arm64/boot/dts/apple/t6021-j416c.dts +5 -0
index 6d8146b94170..0037346959a5 100644
@@ -24,3 +24,8 @@ &wifi0 {
 &bluetooth0 {
 	brcm,board-type = "apple,amami";
 };
+
+&sound {
+	compatible = "apple,j416-macaudio", "apple,j316-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
#58 lore raw

PATCH v2 21/21 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..7b4c4ef471be 100644
@@ -46,4 +46,9 @@ &pcie0 {
 			<0x300 &pcie0_dart_3 1 1>;
 };
 
+&sound {
+	compatible = "apple,j474-macaudio", "apple,j473-macaudio";
+	model = "Mac mini J473";
+};
+
 #include "hwmon-mini.dtsi"
arch/arm64/boot/dts/apple/t6021-j475c.dts +5 -0
index 9fe17f1f7f59..f8f776f9eb1e 100644
@@ -36,4 +36,9 @@ &pcie0_dart_1 {
 	status = "okay";
 };
 
+&sound {
+	compatible = "apple,j475-macaudio", "apple,j375-macaudio";
+	model = "Mac Studio J475";
+};
+
 #include "hwmon-fan-dual.dtsi"
arch/arm64/boot/dts/apple/t6022-j475d.dts +5 -0
index 32938a3bf96a..153899f1569b 100644
@@ -73,3 +73,8 @@ &bluetooth0 {
 	compatible = "pci14e4,5f72";
 	brcm,board-type = "apple,canary";
 };
+
+&sound {
+	compatible = "apple,j475-macaudio", "apple,j375-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
#12 lore raw

Re: [PATCH v2 05/21] ASoC: dt-bindings: Add binding for Apple Silicon Mac audio

In reply to James Calligeros
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [Low] dt-bindings: conflicting additionalProperties alongside $ref - [Low] dt-bindings: dynamic…

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Low] dt-bindings: conflicting additionalProperties alongside $ref
- [Low] dt-bindings: dynamic index-suffixed property names for TDM configs
- [Low] dt-bindings: missing #address-cells and #size-cells in required list --

commit e0246be35f768471da65ec0d3bc4f036e14c8598
Author: Martin Povišer <[email protected]>
ASoC: dt-bindings: Add binding for Apple Silicon Mac audio

This commit adds a binding for the primary audio subsystem found on Apple Silicon Macs. It integrates the codecs and SoC I2S peripheral used for driving the headset jack and speaker arrays.

Quoted 5 lines
Documentation/devicetree/bindings/sound/apple,macaudio.yaml new file +0 -0
new file mode 100644
index 0000000000000..c0a04fab82d31

[ ... ]

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

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 the use of additionalProperties: false alongside a top-level $ref import block standard properties defined in the referenced schema from being validated?

In JSON Schema, additionalProperties only evaluates properties explicitly defined in the local schema. If standard properties from tdm-slot.yaml were intended to be allowed, they will be erroneously rejected, requiring
unevaluatedProperties: false instead.

If they were meant to be rejected, is the top-level $ref dead code that should be removed?

[ ... ]

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

Quoted 6 lines
Documentation/devicetree/bindings/sound/apple,macaudio.yaml new file +6 -0
+    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

[Severity: Low]
Does appending dynamic integer indices to property names fragment standard Devicetree design and circumvent generic TDM parsing utilities?

Property names are typically static. Could configuration values intended for multiple codecs on a single DAI link either be defined as an array property or configured directly inside discrete child nodes representing each codec context?

[ ... ]

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

Quoted 10 lines
Documentation/devicetree/bindings/sound/apple,macaudio.yaml new file +10 -0
+    required:
+      - reg
+      - codec
+      - cpu
+
+required:
+  - compatible
+  - model
+
+additionalProperties: false

[Severity: Low]
Because the dai-link child nodes unconditionally require a reg property, do #address-cells and #size-cells need to be mandated in the required list?

Omitting them from the parent's required list allows an incomplete Device Tree node to silently pass dt_binding_check schema validation while remaining invalid per the core DT specification.

[ ... ]

Quoted 7 lines
Documentation/devicetree/bindings/sound/apple,macaudio.yaml new file +7 -0
+examples:
+  - |
+    sound {
+      compatible = "apple,j416-macaudio", "apple,j316-macaudio";
+      model = "MacBook Pro J416";
+
+      #address-cells = <1>;

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

Quoted 10 lines
Documentation/devicetree/bindings/sound/apple,macaudio.yaml new file +10 -0
+      #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>;

[Severity: Low]
This isn't a functional bug, but the examples showcase the usage of hardcoded suffix indices on property keys mentioned above. Should these be refactored to use static arrays or discrete child nodes?

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

Re: [PATCH v2 10/21] arm64: dts: apple: t8103-j274: Add speaker/headset jack nodes

In reply to James Calligeros
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] dts: codec ti,tas5770l is unprobeable due to missing driver binding - [Low] dts: duplicate &i2c2…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] dts: codec ti,tas5770l is unprobeable due to missing driver binding
- [Low] dts: duplicate &i2c2 node definition
--

commit 880aa6b0e6df0b9fa5a017a1a3c706d5c89c5508
Author: James Calligeros <[email protected]>

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

This commit adds speaker and headset jack nodes for the M1 Mac mini. It integrates Apple-specific variants of the TI TAS2770 and Cirrus CS42L42 by advertising them to the machine driver via the sound node.

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

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

[Severity: High]
Will this codec successfully probe? The intended codec driver's match table in sound/soc/codecs/tas2770.c does not appear to include this compatible string:

sound/soc/codecs/tas2770.c:tas2770_of_match[] {
	{ .compatible = "ti,tas2770" },
	{},
};

Without a matching driver binding or a generic fallback string like "ti,tas2770" in the DTS, the kernel's I2C core and OF matching will fail to bind a driver. Does this leave the codec component permanently in deferred probe and prevent the sound card from initializing?

Quoted 2 lines
arch/arm64/boot/dts/apple/t8103-j274.dts +2 -0
+		reg = <0x31>;
+		interrupts-extended = <&pinctrl_ap 182 IRQ_TYPE_LEVEL_LOW>;

[ ... ]

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

Quoted 4 lines
arch/arm64/boot/dts/apple/t8103-j274.dts +4 -0
+	};
+};
+
+&i2c2 {

[Severity: Low]
Does this file already have an &i2c2 node defined right above this hunk? While the Device Tree Compiler safely merges duplicate nodes into a single block during compilation, is it preferred to nest the new jack_codec node inside the existing &i2c2 block to avoid redundant top-level references?

Quoted 4 lines
arch/arm64/boot/dts/apple/t8103-j274.dts +4 -0
+	status = "okay";
+
+	jack_codec: codec@48 {
+		compatible = "cirrus,cs42l83";
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
#40 lore raw

Re: [PATCH v2 11/21] arm64: dts: apple: t8103-j313: Add speaker/headset jack nodes

In reply to James Calligeros
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] sound: missing tas5770l driver binding prevents audio probe - [High] sound: shared shutdown-gpios…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] sound: missing tas5770l driver binding prevents audio probe
- [High] sound: shared shutdown-gpios cause power desynchronization and suspend failure --

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

arm64: dts: apple: t8103-j313: 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 on the M1 MacBook Air. It connects them to the machine driver via the sound node.

Quoted 4 lines
arch/arm64/boot/dts/apple/t8103-j313.dts +0 -0
index f8b2b1637b9dc..cdda63ca8b349 100644

[ ... ]

arch/arm64/boot/dts/apple/t8103-j313.dts &typec1 { · line 63

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

[Severity: High]
Will this node fail to probe because the driver lacks a binding for ti,tas5770l?

Looking at the driver in sound/soc/codecs/tas2770.c, tas2770_of_match[] only includes the ti,tas2770 string:

sound/soc/codecs/tas2770.c:tas2770_of_match[] = {
	{ .compatible = "ti,tas2770" },
	{ }
};

Since there is no fallback string provided in the device tree for either speaker_left or speaker_right, will the ALSA machine driver defer indefinitely waiting for these speaker codecs to bind?

arch/arm64/boot/dts/apple/t8103-j313.dts &typec1 { · line 66

Quoted 3 lines
arch/arm64/boot/dts/apple/t8103-j313.dts +3 -0
+		reg = <0x31>;
+		interrupts-extended = <&pinctrl_ap 182 IRQ_TYPE_LEVEL_LOW>;
+		shutdown-gpios = <&pinctrl_ap 181 GPIO_ACTIVE_HIGH>;

[Severity: High]
Can this shared shutdown-gpios configuration cause a system suspend failure?

Since both speaker_left and speaker_right map to the exact same physical shutdown-gpios line, the second codec to probe will fail to acquire it. Looking at tas2770_parse_dt() in sound/soc/codecs/tas2770.c, the driver requests the GPIO exclusively:

sound/soc/codecs/tas2770.c:tas2770_parse_dt() {
    ...
	tas2770->sdz_gpio = devm_gpiod_get_optional(dev, "shutdown", GPIOD_OUT_LOW);
	if (IS_ERR(tas2770->sdz_gpio)) {
		if (PTR_ERR(tas2770->sdz_gpio) == -EPROBE_DEFER)
			return -EPROBE_DEFER;

		tas2770->sdz_gpio = NULL;
	}
    ...
}

The second codec will get -EBUSY and silently fall back to sdz_gpio = NULL, leaving it without control of its power state.

During system suspend, the first codec will pull the physical GPIO low, cutting power to both chips. When the second codec's suspend callback subsequently runs, it will attempt an I2C write (TAS2770_PWR_CTRL_SHUTDOWN) to a chip that is already physically powered off.

Could this I2C timeout or NACK return an error that fails the component suspend, thereby aborting the overall system sleep transition?

[ ... ]

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

Re: [PATCH v2 13/21] arm64: dts: apple: t8103-j45x: Add 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: missing compatible fallback for j457 macaudio --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] dts: missing compatible fallback for j457 macaudio
--

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

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

This commit adds headset jack nodes for the M1 iMacs and advertises them to the machine driver via the sound node.

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

[ ... ]

Quoted 1 line
arch/arm64/boot/dts/apple/t8103-j457.dts +0 -0
@@ -69,3 +69,41 @@ ethernet0: ethernet@0,0 {

[ ... ]

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";

[Severity: Medium]
Does this compatible string need "apple,j456-macaudio" as a fallback?

The ASoC driver sound/soc/apple/macaudio.c does not contain "apple,j457-macaudio" in its of_device_id match table, and appears to expect j457 to use j456 as a fallback. Without the fallback string in the device tree (such as "apple,j457-macaudio", "apple,j456-macaudio"), the platform bus will not bind the driver, which could leave the J457 iMac without functional audio.

Quoted 6 lines
arch/arm64/boot/dts/apple/t8103-j457.dts +6 -0
+		model = "iMac J457";
+
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		dai-link@1 {

[ ... ]

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

Re: [PATCH v2 15/21] arm64: dts: apple: t8112-j415: Add speaker/headset jack nodes

In reply to James Calligeros
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] sound: shared shutdown-gpios exclusive access breaks codec probe - [Low] sound: typo in…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] sound: shared shutdown-gpios exclusive access breaks codec probe
- [Low] sound: typo in sound-name-prefix for right tweeter
--

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

arm64: dts: apple: t8112-j415: 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 7 lines
arch/arm64/boot/dts/apple/t8112-j415.dts +0 -0
index fdc3409d2e079..4f3db2a93db03 100644
@@ -92,4 +92,136 @@ &fpwm1 {
 	status = "okay";
 };

arch/arm64/boot/dts/apple/t8112-j415.dts &fpwm1 { · line 103

Quoted 10 lines
arch/arm64/boot/dts/apple/t8112-j415.dts +9 -0
 
+/* Audio codecs */
+&i2c1 {
+	status = "okay";
+
+	speaker_left_woof1: codec@38 {
+		compatible = "ti,sn012776";
+		reg = <0x38>;
+		interrupts-extended = <&pinctrl_ap 11 IRQ_TYPE_LEVEL_LOW>;
+		shutdown-gpios = <&pinctrl_ap 88 GPIO_ACTIVE_HIGH>;

[Severity: High]
Does sharing the same shutdown-gpios across all 6 speaker codecs break the probe sequence?

The tas2764 driver requests the GPIO exclusively:

sound/soc/codecs/tas2764.c:tas2764_parse_dt() {
	...
	tas2764->sdz_gpio = devm_gpiod_get_optional(dev, "shutdown", GPIOD_OUT_LOW);
	if (IS_ERR(tas2764->sdz_gpio)) {
		if (PTR_ERR(tas2764->sdz_gpio) == -EPROBE_DEFER)
			return -EPROBE_DEFER;

		tas2764->sdz_gpio = NULL;
	}
	...
}

Because devm_gpiod_get_optional() requests the GPIO exclusively, the first codec to bind on the I2C bus will get the GPIO and drive it LOW.

The other 5 codecs will receive -EBUSY and silently fall back to NULL.

Later, when ALSA probes the codecs in the order defined by the sound-dai property, the physical shutdown pin might still be LOW. This causes the first codec attempting I2C initialization to fail with -EREMOTEIO, rendering audio unusable.

[ ... ]

arch/arm64/boot/dts/apple/t8112-j415.dts &fpwm1 { · line 153

Quoted 7 lines
arch/arm64/boot/dts/apple/t8112-j415.dts +7 -0
+	speaker_right_tweet: codec@3c {
+		compatible = "ti,sn012776";
+		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: Low]
Is this sound-name-prefix correct, or should it be "Right Tweeter"?

The left tweeter uses "Left Tweeter", so naming the right one "Right Tweet" might cause ALSA UCM profiles that rely on string matching "Tweeter" to fail to match the right channel, potentially causing broken or asymmetric mixer routing.

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

Re: [PATCH v2 07/21] ASoC: ops: Introduce 'soc_set_enum_kctl'

In reply to James Calligeros
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] ASoC: snd_soc_set_enum_kctl passes uninitialized control ID to callbacks - [Low] ASoC…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] ASoC: snd_soc_set_enum_kctl passes uninitialized control ID to callbacks
- [Low] ASoC: soc_set_enum_kctl allocates massive ALSA structures on kernel stack --

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

ASoC: ops: Introduce 'soc_set_enum_kctl'

The new function is to be used to set enumerated controls to desired values. It is something a machine driver may call in fixup_controls.

Quoted 4 lines
sound/soc/soc-ops.c +0 -0
index 4d799c5e44f1b..b1eb74e241932 100644

[ ... ]

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

Quoted 8 lines
sound/soc/soc-ops.c +4 -0
@@ -505,6 +505,75 @@ 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 *value)
+{
+	struct snd_ctl_elem_value evalue = { 0 };
+	struct snd_ctl_elem_info info = { 0 };

[Severity: Low]
Are these ALSA structures too large to be allocated on the stack here?

struct snd_ctl_elem_value is typically around 1220 bytes on 64-bit architectures since it contains unions with large fixed-size arrays. With struct snd_ctl_elem_info adding another 272 bytes, allocating both on the stack consumes approximately 1.5 KB of stack space.

Could this exceed the 1024-byte FRAME_WARN threshold on some architectures and increase the risk of a kernel stack overflow?

The ALSA core usually relies on heap allocation for these large structures to avoid exhausting the stack.

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

[ ... ]

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

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

[Severity: High]
Does this pass an uninitialized control ID to the put callback?

The evalue and info structures are zero-initialized above, which leaves their id fields completely empty. The kctl->id is never copied into them before being passed to kctl->info() or kctl->put().

The core ALSA API guarantees that ucontrol->id is fully populated before invoking control callbacks. Some drivers rely on this contract. For example, rt700_mux_put() uses the control name to identify which specific control is being accessed:

sound/soc/codecs/rt700.c:rt700_mux_put() {
    ...
    if (strstr(ucontrol->id.name, "HPO Mux"))
        ...
}

Because evalue.id.name is an empty string here, will such callbacks fail or execute incorrect logic?

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

Re: [PATCH v2 09/21] ASoC: apple: Add macaudio machine driver

In reply to James Calligeros
Thank you for your contribution! Sashiko AI review found 10 potential issue(s) to consider: - [High] ALSA: macaudio: UAF in workqueues due to devres and remove cleanup ordering - [High] ALSA…

Thank you for your contribution! Sashiko AI review found 10 potential issue(s) to consider:
- [High] ALSA: macaudio: UAF in workqueues due to devres and remove cleanup ordering
- [High] ALSA: macaudio: OOB memory read in macaudio_vlimit_unlock due to pointer underflow
- [High] ALSA: macaudio: ABBA deadlock between controls_rwsem and volume_lock_mutex
- [High] ALSA: macaudio: sleeping in atomic context in macaudio_be_trigger
- [High] ALSA: macaudio: invalid hardware state from mutating params in macaudio_dpcm_hw_params
- [Medium] ALSA: macaudio: spurious speaker volume lock due to race condition in macaudio_slk_put
- [Medium] ALSA: macaudio: OF node reference leak in probe error paths and driver unbind
- [Medium] ALSA: macaudio: NULL pointer dereference of DAI widget streams on malformed DT
- [Low] ALSA: macaudio: missing NULL check before pointer dereference in macaudio_vlimit_unlock
- [Low] ALSA: macaudio: data race on ma->bes_active read
--

commit 5727989ecaf382b9e8427180fda0eb828623fffb
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 5 lines
sound/soc/apple/macaudio.c new file +0 -0
index 0000000000000..36a62d88bb18b
@@ -0,0 +1,1699 @@

[ ... ]

sound/soc/apple/macaudio.c line 235

Quoted 11 lines
sound/soc/apple/macaudio.c new file +11 -0
+static void macaudio_vlimit_unlock(struct macaudio_snd_data *ma, bool unlock)
+{
+	int ret, max;
+	struct snd_kcontrol *kctl;
+	const char *name = volume_control_names[ma->cfg->amp];
+	int namelen = strlen(name);
+
+	if (!name) {
+		WARN_ON_ONCE(1);
+		return;
+	}

[Severity: Low]
Does this code dereference name before checking if it is NULL? The call to strlen(name) happens just before if (!name).

[ ... ]

sound/soc/apple/macaudio.c line 266

Quoted 6 lines
sound/soc/apple/macaudio.c new file +6 -0
+	/* The caller has already taken the rw semaphore as necessary */
+	list_for_each_entry(kctl, &ma->card.snd_card->controls, list) {
+		const char *suffix = kctl->id.name + strlen(kctl->id.name) - namelen;
+
+		if (strncmp(suffix, name, namelen))
+			continue;

[Severity: High]
Can this arithmetic underflow if the kcontrol name is shorter than namelen? Since strlen() returns an unsigned size_t, subtracting a larger namelen would result in a very large positive offset, leading to an out-of-bounds memory read in strncmp().

[ ... ]

Quoted 2 lines
sound/soc/apple/macaudio.c new file +2 -0
+static void macaudio_vlimit_update(struct macaudio_snd_data *ma, bool take_rwsem)
+{

[ ... ]

sound/soc/apple/macaudio.c line 297

Quoted 8 lines
sound/soc/apple/macaudio.c new file +8 -0
+	/*
+	 * If this has been called from either of the safety interlock
+	 * workqueues, the core API has not taken controls_rwsem for us.
+	 * Take the write semaphore since macaudio_vlimit_unlock writes
+	 * to the kcontrols.
+	 */
+	if (take_rwsem)
+		down_write(&ma->card.snd_card->controls_rwsem);

[Severity: High]
Could this lead to an ABBA deadlock? When a user interacts with the "Speaker Volume Unlock" kcontrol, the ALSA core takes controls_rwsem before calling macaudio_slk_put(), which then acquires volume_lock_mutex.

Here, the worker thread macaudio_vlimit_timeout_work acquires volume_lock_mutex first and then attempts to acquire controls_rwsem via macaudio_vlimit_update().

[ ... ]

sound/soc/apple/macaudio.c line 373

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);
+
+	guard(mutex)(&ma->volume_lock_mutex);
+	ma->speaker_lock_remain = 0;
+	macaudio_vlimit_update(ma, true);
+}

[Severity: Medium]
Will this blindly zeroize the timeout if it executes concurrently with a userspace ping? If macaudio_slk_put() is actively updating the timeout but the worker has already fired and is waiting on volume_lock_mutex, the non-synchronous cancel_delayed_work() in macaudio_slk_put() won't stop it. The worker will then wake up, set ma->speaker_lock_remain = 0, and lock the volume.

[ ... ]

sound/soc/apple/macaudio.c line 380

Quoted 6 lines
sound/soc/apple/macaudio.c new file +6 -0
+static void macaudio_vlimit_update_work(struct work_struct *wrk)
+{
+	struct macaudio_snd_data *ma = container_of(wrk,
+						    struct macaudio_snd_data, lock_update_work);
+
+	if (ma->bes_active)

[Severity: Low]
Is this a data race? ma->bes_active is read here without any locking or READ_ONCE(), while macaudio_be_trigger() concurrently modifies it.

[ ... ]

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

[ ... ]

Quoted 10 lines
sound/soc/apple/macaudio.c new file +10 -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);

sound/soc/apple/macaudio.c line 688

Quoted 10 lines
sound/soc/apple/macaudio.c new file +10 -0
+			if (ret)
+				goto err_free;
+
+			link_props->is_speakers = speakers;
+			link_props->is_headphones = !speakers;
+
+			link_props->codecs = devm_kcalloc(dev, ncodecs_per_cpu,
+							  sizeof(struct ma_codec_idle), GFP_KERNEL);
+			if (!link_props->codecs)
+				return -ENOMEM;

[Severity: Medium]
Does this directly return without cleaning up the OF node references? Bypassing the err_free label here skips the cleanup logic, leaving the references acquired in macaudio_parse_of_component() leaked.

Additionally, when taking the err_free path from within this loop, num_links hasn't been incremented yet for the current iteration, so the nodes for the currently failing link might not be released.

[ ... ]

Quoted 3 lines
sound/soc/apple/macaudio.c new file +3 -0
+static int macaudio_dpcm_hw_params(struct snd_pcm_substream *substream,
+				   struct snd_pcm_hw_params *params)
+{

[ ... ]

Quoted 10 lines
sound/soc/apple/macaudio.c new file +10 -0
+	if (props->is_sense) {
+		/*
+		 * The sense FE is opened exclusively by speakersafetyd in blocking
+		 * mode. At the time of opening, this sample rate may be 0 if the
+		 * speaker BE is not running. This does not matter, as speakersafetyd
+		 * only cares about the active sample rate exported to the virtual
+		 * sample rate kcontrol below.
+		 */
+		rate->min = rate->max = cpu_dai->symmetric_rate;
+		return 0;

sound/soc/apple/macaudio.c line 810

Quoted 10 lines
sound/soc/apple/macaudio.c new file +10 -0
+	}
+
+	/* Speakers BE */
+	if (props->is_speakers) {
+		if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
+			/* Sense PCM: keep the existing BE rate (0 if not already running) */
+			rate->min = rate->max = cpu_dai->symmetric_rate;
+
+			return 0;
+		}

[Severity: High]
Does setting rate->min = rate->max = cpu_dai->symmetric_rate mutate the hardware parameters structure directly during the hw_params phase? If the speaker BE is not running and symmetric_rate is 0, this forces the rate to 0 Hz, which may cause downstream hardware drivers to reject it with -EINVAL and break the stream initialization. Should constraints like this be applied in the startup callback instead?

[ ... ]

sound/soc/apple/macaudio.c line 941

Quoted 7 lines
sound/soc/apple/macaudio.c new file +7 -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];
+
+	guard(mutex)(&ma->be_link_mutex);

[Severity: High]
Can this attempt to acquire a sleeping lock while in an atomic context? Because these DAI links are not marked with nonatomic = 1, the ASoC and ALSA cores invoke the .trigger callback with the PCM substream spinlock held and IRQs disabled.

[ ... ]

Quoted 8 lines
sound/soc/apple/macaudio.c new file +8 -0
+static int macaudio_add_backend_dai_route(struct snd_soc_card *card, struct snd_soc_dai *dai,
+					  bool is_speakers)
+{
+	struct snd_soc_dapm_route routes[2];
+	struct snd_soc_dapm_route *r;
+	int nroutes = 0;
+	int ret;
+

sound/soc/apple/macaudio.c line 1123

Quoted 10 lines
sound/soc/apple/macaudio.c new file +10 -0
+	memset(routes, 0, sizeof(routes));
+
+	dev_dbg(card->dev, "adding routes for '%s'\n", dai->name);
+
+	r = &routes[nroutes++];
+	if (is_speakers)
+		r->source = "Speaker Playback";
+	else
+		r->source = "Headphone Playback";
+	r->sink = dai->stream[SNDRV_PCM_STREAM_PLAYBACK].widget->name;

[Severity: Medium]
What happens if the configured device tree specifies a capture-only DAI? Without verifying that the playback stream widget is non-NULL before dereferencing its name, a malformed device tree could trigger a kernel panic during device probe.

[ ... ]

sound/soc/apple/macaudio.c line 1418

Quoted 6 lines
sound/soc/apple/macaudio.c new file +6 -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);
+
+	guard(mutex)(&ma->volume_lock_mutex);

[Severity: High]
Could this result in an ABBA deadlock? As mentioned earlier, this function is called with controls_rwsem held by the core, and takes volume_lock_mutex. The background worker acquires volume_lock_mutex first and then attempts to acquire controls_rwsem.

[ ... ]

sound/soc/apple/macaudio.c line 1434

Quoted 5 lines
sound/soc/apple/macaudio.c new file +5 -0
+	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, false);

[Severity: Medium]
Will this non-synchronous cancel_delayed_work() fail to stop the worker if it is already running and waiting on volume_lock_mutex? This ties into the race condition discussed in macaudio_vlimit_timeout_work().

[ ... ]

Quoted 2 lines
sound/soc/apple/macaudio.c new file +2 -0
+static int macaudio_snd_platform_probe(struct platform_device *pdev)
+{

[ ... ]

sound/soc/apple/macaudio.c line 1676

Quoted 5 lines
sound/soc/apple/macaudio.c new file +5 -0
+	INIT_WORK(&data->lock_update_work, macaudio_vlimit_update_work);
+	INIT_DELAYED_WORK(&data->lock_timeout_work, macaudio_vlimit_timeout_work);
+
+	return devm_snd_soc_register_card(dev, card);
+}

[Severity: High]
Does registering the card via devres create a use-after-free window during unbind? The devres cleanup (including unregistering the card) runs after macaudio_snd_platform_remove() completes. This leaves a window where ALSA callbacks can still fire and re-queue workitems on the workqueues that were cancelled during remove.

[ ... ]

sound/soc/apple/macaudio.c line 1684

Quoted 7 lines
sound/soc/apple/macaudio.c new file +7 -0
+static void macaudio_snd_platform_remove(struct platform_device *pdev)
+{
+	struct macaudio_snd_data *ma = dev_get_drvdata(&pdev->dev);
+
+	cancel_work_sync(&ma->lock_update_work);
+	cancel_delayed_work_sync(&ma->lock_timeout_work);
+}

[Severity: High]
Since the sound card is still fully active here (due to devres), can the work items get re-queued by ongoing ALSA callbacks right after these sync cancels? When devres later frees macaudio_snd_data, any re-queued work would execute on freed memory.

[Severity: Medium]
Does this remove handler also leak the OF node references acquired during probe? It appears to omit the necessary calls to snd_soc_of_put_dai_link_codecs() and snd_soc_of_put_dai_link_cpus().

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

Re: [PATCH v2 18/21] 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: - [High] dts: resource conflict on shared shutdown-gpios for multiple codecs --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] dts: resource conflict on shared shutdown-gpios for multiple codecs --

commit 9045c7a2c2a0f6174f098238d3400d7d5ed2d1f8
Author: James Calligeros <[email protected]>

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

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.

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

[ ... ]

arch/arm64/boot/dts/apple/t600x-j314-j316.dtsi hpm5: usb-pd@3a { · line 180

Quoted 13 lines
arch/arm64/boot/dts/apple/t600x-j314-j316.dtsi +9 -0
@@ -169,6 +169,94 @@ hpm5: usb-pd@3a {
 	};
 };
 
+/* Audio codecs */
+&i2c1 {
+	status = "okay";
+
+	speaker_left_woof1: codec@38 {
+		compatible = "ti,sn012776";
+		reg = <0x38>;
+		interrupts-extended = <&pinctrl_ap 179 IRQ_TYPE_LEVEL_LOW>;
+		shutdown-gpios = <&pinctrl_ap 178 GPIO_ACTIVE_HIGH>;

[Severity: High]
Does sharing the shutdown-gpios line identically across all six codec nodes cause a resource conflict during probe?

When probing the ti,sn012776 codecs, the tas2764 driver uses an exclusive request for shutdown-gpios. The first codec successfully acquires the GPIO, but the remaining five codecs will receive an -EBUSY error. They silently ignore the error, set their GPIO descriptor to NULL, and continue.

If the system or audio card later suspends, the first probed codec will unilaterally assert the shared shutdown-gpios line. This physically powers down the remaining active codecs while they are still awaiting their own suspend sequence.

Will the subsequent I2C writes during the suspend callbacks of those powered down codecs fail due to NACK timeouts, potentially delaying or aborting the entire system suspend process?

Quoted 11 lines
arch/arm64/boot/dts/apple/t600x-j314-j316.dtsi +11 -0
+		#sound-dai-cells = <0>;
+		sound-name-prefix = "Left Woofer 1";
+		ti,imon-slot-no = <0>;
+		ti,vmon-slot-no = <2>;
+	};
+
+	speaker_left_woof2: codec@39 {
+		compatible = "ti,sn012776";
+		reg = <0x39>;
+		interrupts-extended = <&pinctrl_ap 179 IRQ_TYPE_LEVEL_LOW>;
+		shutdown-gpios = <&pinctrl_ap 178 GPIO_ACTIVE_HIGH>;

[ ... ]

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

Re: [PATCH v2 12/21] arm64: dts: apple: t8103-j293: 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: missing driver binding for ti,tas5770l codec --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] dts: apple: missing driver binding for ti,tas5770l codec
--

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

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

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.

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

[ ... ]

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

Quoted 10 lines
arch/arm64/boot/dts/apple/t8103-j293.dts +6 -0
@@ -133,5 +133,116 @@ &displaydfr_dart {
 	status = "okay";
 };
 
+/* Audio codecs */
+&i2c1 {
+	status = "okay";
+
+	speaker_left_rear: codec@31 {
+		compatible = "ti,tas5770l";

[Severity: Medium]
Will this device node successfully bind to a driver?

This declares a compatible string that lacks driver support in the kernel, and has no fallback. Looking at the codec driver's OF match table in sound/soc/codecs/tas2770.c:

static const struct of_device_id tas2770_of_match[] = {
	{ .compatible = "ti,tas2770" },
	{},
};

The match table does not include ti,tas5770l, causing binding to fail. As a result, the ASoC sound card apple,j293-macaudio will indefinitely defer probing because no codec driver binds to the ti,tas5770l I2C devices, leaving the machine without sound.

Could the codec driver be updated to match this compatible string, or should a fallback compatible string be added here?

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

Re: [PATCH v2 08/21] ASoC: card: Let 'fixup_controls' return errors

In reply to James Calligeros
Quoted 5 lines · 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.

Quoted 8 lines
---
 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 ++++-

Fixup is missing here for sound/soc/sdca/sdca_class_function.c

Thanks,
Charles

#22 lore raw

Re: [PATCH v2 07/21] ASoC: ops: Introduce 'soc_set_enum_kctl'

In reply to James Calligeros
Quoted 14 lines · James Calligeros

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

The new function is to be used to set enumerated controls to desired values. It is something a machine driver may call in fixup_controls.

sound/soc/soc-ops.c +0 -0
@@ -505,6 +505,75 @@ int snd_soc_deactivate_kctl(struct snd_soc_card *card,
  }
  EXPORT_SYMBOL_GPL(snd_soc_deactivate_kctl);
 

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

Quoted 10 lines
sound/soc/soc-ops.c +10 -0
+static int soc_set_enum_kctl(struct snd_kcontrol *kctl, const char *value)
+{
+	struct snd_ctl_elem_value evalue = { 0 };
+	struct snd_ctl_elem_info info = { 0 };
+	int sel, i, ret;
+
+	ret = kctl->info(kctl, &info);
+	if (ret < 0)
+		return ret;
+

Could this initialize the control IDs before calling the control callbacks?

The normal ALSA write path does not call put() with an empty ID: snd_ctl_elem_write() resolves the control and then calls snd_ctl_build_ioff(&control->id, kctl, index_offset) before invoking the control's put() callback. This helper builds a zeroed struct snd_ctl_elem_value and passes it directly to kctl->put(), so callbacks that inspect ucontrol->id.name see an empty name.

There are existing enum/mux callbacks that branch on ucontrol->id.name, for example rt700_mux_put() and similar SoundWire codec mux callbacks. So this helper should probably initialize the callback objects from the target control before calling into them, e.g. set info.id = kctl->id and evalue.id = kctl->id before the info() / put() calls.

While touching this, it may also be worth heap-allocating struct snd_ctl_elem_value, matching the nearby snd_soc_clip_to_platform_max() pattern, since the ALSA control value struct is fairly large for stack use.

Quoted 63 lines
sound/soc/soc-ops.c +59 -0
+	if (info.type != SNDRV_CTL_ELEM_TYPE_ENUMERATED)
+		return -EINVAL;
+
+	for (sel = 0; sel < info.value.enumerated.items; sel++) {
+		info.value.enumerated.item = sel;
+		ret = kctl->info(kctl, &info);
+		if (ret < 0)
+			return ret;
+
+		if (!strcmp(value, info.value.enumerated.name))
+			break;
+	}
+
+	if (sel == info.value.enumerated.items)
+		return -EINVAL;
+
+	for (i = 0; i < info.count; i++)
+		evalue.value.enumerated.item[i] = sel;
+
+	if (kctl->put)
+		return kctl->put(kctl, &evalue);
+	else
+		return -EINVAL;
+}
+
+/**
+ * snd_soc_set_enum_kctl - Set enumerated control matching a name
+ *
+ * @card: where to look for the controls
+ * @name: name
+ * @value: string value to set the controls to
+ *
+ * Return 0 on success, else error.
+ */
+int snd_soc_set_enum_kctl(struct snd_soc_card *card,
+	const char *name, const char *value)
+{
+	struct snd_kcontrol *kctl;
+	int ret = -EINVAL;
+
+	/* Sanity check for name */
+	if (unlikely(!name))
+		return -EINVAL;
+
+	kctl = snd_soc_card_get_kcontrol(card, name);
+
+	if (kctl) {
+		ret = soc_set_enum_kctl(kctl, value);
+		if (ret)
+			return ret;
+	} else {
+		dev_dbg(card->dev, "Tried to set unknown control '%s' to '%s'\n",
+			name, value);
+	}
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(snd_soc_set_enum_kctl);
+
  int snd_soc_bytes_info(struct snd_kcontrol *kcontrol,
  		       struct snd_ctl_elem_info *uinfo)
  {
#31 lore raw

Re: [PATCH v2 09/21] ASoC: apple: Add macaudio machine driver

In reply to James Calligeros
Quoted 35 lines · 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    |   18 +
  sound/soc/apple/Makefile   |    4 +
  sound/soc/apple/macaudio.c | 1699 +++++++++++++++++++++++++
  3 files changed, 1721 insertions(+)

sound/soc/apple/macaudio.c line 942

Quoted 9 lines
sound/soc/apple/macaudio.c new file +9 -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];
+
+	guard(mutex)(&ma->be_link_mutex);
+

This is in the DAI link .trigger callback, but I don't see the macaudio links being marked .nonatomic = 1.

The default PCM trigger path can run with the stream lock held and IRQs disabled, so taking a normal mutex here can sleep in atomic context. If this state really needs a sleeping lock, should the affected links be marked nonatomic, or should the trigger path avoid the mutex?

Quoted 22 lines
sound/soc/apple/macaudio.c new file +22 -0
+	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);
+			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;
+		default:
+			return -EINVAL;
+		}
+
+		schedule_work(&ma->lock_update_work);
+	}
+
+	return 0;
+}
+
#38 lore raw

Re: [PATCH v2 10/21] arm64: dts: apple: t8103-j274: Add speaker/headset jack nodes

In reply to James Calligeros
Quoted 14 lines · 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 | 67 +++++++++++++++++++++++++
  1 file changed, 67 insertions(+)
arch/arm64/boot/dts/apple/t8103-j274.dts +0 -0
index 1212852251e0..6121e3a89a0f 100644

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

Quoted 10 lines
arch/arm64/boot/dts/apple/t8103-j274.dts +7 -0
@@ -75,4 +75,71 @@ &i2c2 {
  	status = "okay";
  };
 
+/* Audio codecs */
+&i2c1 {
+	status = "okay";
+
+	speaker: codec@31 {
+		compatible = "ti,tas5770l";
+		reg = <0x31>;

The binding documents "ti,tas5770l" in 'Documentation/devicetree/bindings/sound/ti,tas2770.yaml', but I only see 'ti,tas2770' in the OF match table in 'sound/soc/codecs/tas2770.c'.

Is the expectation that this node should bind through the TAS2770 driver? If so, should this either use a generic fallback compatible, for example:

compatible = "ti,tas5770l", "ti,tas2770";

or add ti,tas5770l to the driver's OF match table?

Quoted 4 lines
arch/arm64/boot/dts/apple/t8103-j274.dts +4 -0
+		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>;
#41 lore raw

Re: [PATCH v2 11/21] arm64: dts: apple: t8103-j313: Add speaker/headset jack nodes

In reply to James Calligeros
Quoted 32 lines · 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 | 82 +++++++++++++++++++++++++
  1 file changed, 82 insertions(+)
arch/arm64/boot/dts/apple/t8103-j313.dts +15 -0
index f8b2b1637b9d..cdda63ca8b34 100644
@@ -55,4 +55,86 @@ &typec1 {
  	label = "USB-C Left-front";
  };
 
+/* Audio codecs */
+&i2c1 {
+	status = "okay";
+
+	speaker_left: codec@31 {
+		compatible = "ti,tas5770l";
+		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>;
+	};
+};

arch/arm64/boot/dts/apple/t8103-j313.dts &typec1 { · line 82

Quoted 10 lines
arch/arm64/boot/dts/apple/t8103-j313.dts +10 -0
+
+&i2c3 {
+	status = "okay";
+
+	speaker_right: codec@34 {
+		compatible = "ti,tas5770l";
+		reg = <0x34>;
+		interrupts-extended = <&pinctrl_ap 182 IRQ_TYPE_LEVEL_LOW>;
+		shutdown-gpios = <&pinctrl_ap 181 GPIO_ACTIVE_HIGH>;
+		#sound-dai-cells = <0>;

Both speaker codec nodes reference the same shutdown GPIO. Is that intentional for this board?

The TAS2770 driver requests 'shutdown-gpios' per codec instance, and GPIO requests are exclusive by default. So I would expect only one codec instance to own this line, while the other appears to fall back to the register-only path after the GPIO request fails.

If GPIO181 is a shared physical shutdown line for both amps, how is the
power/reset ordering expected to work across probe, suspend, and resume when only one of the two codec driver instances controls that line?

Thanks
Ajay Kumar Nandam

Quoted 59 lines
arch/arm64/boot/dts/apple/t8103-j313.dts +57 -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";
+		model = "MacBook Air J313";
+
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		dai-link@0 {
+			reg = <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 {
+			reg = <1>;
+
+			link-name = "Headphone Jack";
+
+			codec {
+				sound-dai = <&jack_codec>;
+			};
+
+			cpu {
+				sound-dai = <&mca 2>;
+			};
+		};
+	};
+};
+
  #include "hwmon-laptop.dtsi"
#48 lore raw

Re: [PATCH v2 13/21] arm64: dts: apple: t8103-j45x: Add headset jack nodes

In reply to James Calligeros
Quoted 75 lines · 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 | 38 +++++++++++++++++++++++++
  arch/arm64/boot/dts/apple/t8103-j457.dts | 38 +++++++++++++++++++++++++
  2 files changed, 76 insertions(+)
arch/arm64/boot/dts/apple/t8103-j456.dts +38 -0
index 090c97bb781b..1fc74ebf9ab2 100644
@@ -88,3 +88,41 @@ &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";
+		model = "iMac J456";
+
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		dai-link@1 {
+			reg = <1>;
+
+			link-name = "Headphone Jack";
+
+			codec {
+				sound-dai = <&jack_codec>;
+			};
+
+			cpu {
+				sound-dai = <&mca 2>;
+			};
+		};
+	};
+};
arch/arm64/boot/dts/apple/t8103-j457.dts +10 -0
index ebddde75455c..d8ea6bb53b3f 100644
@@ -69,3 +69,41 @@ 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>;

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

Quoted 10 lines
arch/arm64/boot/dts/apple/t8103-j457.dts +10 -0
+		sound-name-prefix = "Jack";
+		cirrus,ts-inv = <1>;
+	};
+};
+
+/ {
+	sound: sound {
+		compatible = "apple,j457-macaudio";
+		model = "iMac J457";
+

I don't see 'apple,j457-macaudio' in the macaudio driver's OF match table.The driver comment instead says J457 is compatible with 'apple,j456-macaudio'.

Should this node use a fallback compatible,

e.g.
compatible = "apple,j457-macaudio", "apple,j456-macaudio";

or should the driver add an explicit apple,j457-macaudio match entry?

Thanks
Ajay Kumar Nandam

Quoted 19 lines
arch/arm64/boot/dts/apple/t8103-j457.dts +18 -0
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		dai-link@1 {
+			reg = <1>;
+
+			link-name = "Headphone Jack";
+
+			codec {
+				sound-dai = <&jack_codec>;
+			};
+
+			cpu {
+				sound-dai = <&mca 2>;
+			};
+		};
+	};
+};
#42 lore raw

Re: [PATCH v2 11/21] arm64: dts: apple: t8103-j313: Add speaker/headset jack nodes

In reply to Ajay Kumar Nandam
Quoted 17 lines · Ajay Kumar Nandam

arch/arm64/boot/dts/apple/t8103-j313.dts &typec1 { · line 82

Quoted 9 lines · James Calligeros

+&i2c3 {

arch/arm64/boot/dts/apple/t8103-j313.dts +8 -0
+     status = "okay";
+
+     speaker_right: codec@34 {
+             compatible = "ti,tas5770l";
+             reg = <0x34>;
+             interrupts-extended = <&pinctrl_ap 182 IRQ_TYPE_LEVEL_LOW>;
+             shutdown-gpios = <&pinctrl_ap 181 GPIO_ACTIVE_HIGH>;
+             #sound-dai-cells = <0>;

Both speaker codec nodes reference the same shutdown GPIO. Is that intentional for this board?

Quoted 8 lines

The TAS2770 driver requests 'shutdown-gpios' per codec instance, and GPIO requests are exclusive by default. So I would expect only one codec instance to own this line, while the other appears to fall back to the register-only path after the GPIO request fails.

If GPIO181 is a shared physical shutdown line for both amps, how is the power/reset ordering expected to work across probe, suspend, and resume when only one of the two codec driver instances controls that line?

We use the new(ish) shared GPIO proxy stuff[1] and it all Just Works.

[1] https://lore.kernel.org/asahi/[email protected]/

#59 lore raw

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

In reply to James Calligeros
Quoted 17 lines · 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 +0 -0
index e3c2635d84fa..7b4c4ef471be 100644

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

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

Should this be "Mac mini J474"? The board file is t6020-j474s.dts and the root node identifies this machine as the M2 Pro Mac mini / J474s.

The fallback compatible to apple,j473-macaudio looks fine, but the sound
card model string should probably describe the actual machine rather than the fallback model.

Thanks
Ajay Kumar Nandam

Quoted 49 lines
arch/arm64/boot/dts/apple/t6020-j474s.dts +2 -0
+};
+
  #include "hwmon-mini.dtsi"
arch/arm64/boot/dts/apple/t6021-j475c.dts +5 -0
index 9fe17f1f7f59..f8f776f9eb1e 100644
@@ -36,4 +36,9 @@ &pcie0_dart_1 {
  	status = "okay";
  };
 
+&sound {
+	compatible = "apple,j475-macaudio", "apple,j375-macaudio";
+	model = "Mac Studio J475";
+};
+
  #include "hwmon-fan-dual.dtsi"
arch/arm64/boot/dts/apple/t6022-j475d.dts +5 -0
index 32938a3bf96a..153899f1569b 100644
@@ -73,3 +73,8 @@ &bluetooth0 {
  	compatible = "pci14e4,5f72";
  	brcm,board-type = "apple,canary";
  };
+
+&sound {
+	compatible = "apple,j475-macaudio", "apple,j375-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>;
+};
#43 lore raw

Re: [PATCH v2 11/21] arm64: dts: apple: t8103-j313: Add speaker/headset jack nodes

In reply to James Calligeros
Quoted 24 lines · James Calligeros
Quoted 22 lines · Ajay Kumar Nandam

arch/arm64/boot/dts/apple/t8103-j313.dts &typec1 { · line 82

Quoted 9 lines · James Calligeros

+&i2c3 {

arch/arm64/boot/dts/apple/t8103-j313.dts +8 -0
+     status = "okay";
+
+     speaker_right: codec@34 {
+             compatible = "ti,tas5770l";
+             reg = <0x34>;
+             interrupts-extended = <&pinctrl_ap 182 IRQ_TYPE_LEVEL_LOW>;
+             shutdown-gpios = <&pinctrl_ap 181 GPIO_ACTIVE_HIGH>;
+             #sound-dai-cells = <0>;

Both speaker codec nodes reference the same shutdown GPIO. Is that intentional for this board?

The TAS2770 driver requests 'shutdown-gpios' per codec instance, and GPIO requests are exclusive by default. So I would expect only one codec instance to own this line, while the other appears to fall back to the register-only path after the GPIO request fails.

Quoted 7 lines
Quoted 3 lines

If GPIO181 is a shared physical shutdown line for both amps, how is the power/reset ordering expected to work across probe, suspend, and resume when only one of the two codec driver instances controls that line?

We use the new(ish) shared GPIO proxy stuff[1] and it all Just Works.

[1] https://lore.kernel.org/asahi/[email protected]/

Thanks for pointing that out. I missed the shared GPIO proxy dependency when looking at the DTS nodes.

That addresses my concern about the shared shutdown line.

Thanks
Ajay Kumar Nandam

#2 lore raw

Re: [PATCH v2 01/21] ASoC: dt-bindings: cs42l84: Document sound-name-prefix property

In reply to James Calligeros
Quoted 14 lines · James Calligeros

Some consumers may wish to prepend the codec's name with a known value to identify a specific codec among many. Enable this with the common sound-name-prefix property.

---
 .../bindings/sound/cirrus,cs42l84.yaml   | 3 +++
 1 file changed, 3 insertions(+)
Documentation/devicetree/bindings/sound/cirrus,cs42l84.yaml +0 -0
index 94062c1d9d45..2637aa5f4326 100644

Documentation/devicetree/bindings/sound/cirrus,cs42l84.yaml properties: · line 36

Quoted 5 lines
Documentation/devicetree/bindings/sound/cirrus,cs42l84.yaml +2 -0
@@ -32,6 +32,9 @@ properties:
   '#sound-dai-cells':
     const: 0
 
+  sound-name-prefix:
+    $ref: component-common.yaml#/properties/sound-name-prefix

That's a codec device, so why aren't you just using dai-common.yaml ($ref) like others?

Best regards,
Krzysztof

#4 lore raw

Re: [PATCH v2 02/21] ASoC: dt-bindings: cs42l42: Do not require chip power supplies

In reply to James Calligeros
Quoted 3 lines · James Calligeros

Some integrators do not expose the power rails connected to the codec in a way that can be expressed in the Devicetree. Do not require them to be specified on such platforms.

I don't understand how these cannot be expressed in Devicetree. What are we missing?

Best regards,
Krzysztof

#8 lore raw

Re: [PATCH v2 03/21] ASoC: dt-bindings: cs42l42: Document #sound-dai-cells property

In reply to James Calligeros
Quoted 14 lines · James Calligeros

We may need to define #sound-dai-cells on some machines where this codec is part of a simple DAI. Document this property to keep the style checker happy.

---
 .../bindings/sound/cirrus,cs42l42.yaml   | 3 +++
 1 file changed, 3 insertions(+)
Documentation/devicetree/bindings/sound/cirrus,cs42l42.yaml +0 -0
index 6c100cb36699..bc759eaadeca 100644

Documentation/devicetree/bindings/sound/cirrus,cs42l42.yaml properties: · line 30

Quoted 5 lines
Documentation/devicetree/bindings/sound/cirrus,cs42l42.yaml +2 -0
@@ -26,6 +26,9 @@ properties:
       The I2C address of the CS42L42.
     maxItems: 1
 
+  '#sound-dai-cells':
+    const: 0

So a DAI? Then just like for every codec you need dai-common.yaml.

Best regards,
Krzysztof

#10 lore raw

Re: [PATCH v2 04/21] ASoC: dt-bindings: cs42l42: Document sound-name-prefix property

In reply to James Calligeros
Quoted 14 lines · James Calligeros

Some consumers may wish to prepend the codec's name with a known value to identify a specific codec among many. Enable this with the common sound-name-prefix property.

---
 .../bindings/sound/cirrus,cs42l42.yaml   | 3 +++
 1 file changed, 3 insertions(+)
Documentation/devicetree/bindings/sound/cirrus,cs42l42.yaml +0 -0
index bc759eaadeca..035463be1456 100644

Documentation/devicetree/bindings/sound/cirrus,cs42l42.yaml properties: · line 32

Quoted 4 lines
Documentation/devicetree/bindings/sound/cirrus,cs42l42.yaml +1 -0
@@ -29,6 +29,9 @@ properties:
   '#sound-dai-cells':
     const: 0
 
+  sound-name-prefix:

No. You reference respective schemas.

Documentation/devicetree/bindings/sound/cirrus,cs42l42.yaml properties: · line 33

Quoted 1 line
Documentation/devicetree/bindings/sound/cirrus,cs42l42.yaml +1 -0
+    $ref: component-common.yaml#/properties/sound-name-prefix

git grep 'properties/sound-name-prefix'

You cannot find such code. This should give you a hint, that you are doing something odd.

Best regards,
Krzysztof

#13 lore raw

Re: [PATCH v2 05/21] ASoC: dt-bindings: Add binding for Apple Silicon Mac audio

In reply to James Calligeros
Quoted 7 lines · James Calligeros
Documentation/devicetree/bindings/sound/apple,macaudio.yaml new file +7 -0
+properties:
+  compatible:
+    oneOf:
+      - items:
+          - enum:
+              - apple,j180-macaudio
+              - apple,j274-macaudio

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

Quoted 10 lines
Documentation/devicetree/bindings/sound/apple,macaudio.yaml new file +10 -0
+              - 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

Keep this list sorted.

Quoted 4 lines
Documentation/devicetree/bindings/sound/apple,macaudio.yaml new file +4 -0
+      - items:
+          - enum:
+              - apple,j493-macaudio
+          - const: apple,j293-macaudio

...

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

Quoted 13 lines
Documentation/devicetree/bindings/sound/apple,macaudio.yaml new file +13 -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#
+

Drop blank line

Quoted 4 lines
Documentation/devicetree/bindings/sound/apple,macaudio.yaml new file +4 -0
+    additionalProperties: false
+
+    properties:
+      reg:

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

Quoted 10 lines
Documentation/devicetree/bindings/sound/apple,macaudio.yaml new file +10 -0
+        maxItems: 1
+
+      link-name:
+        description: Name for the peripheral
+        enum: [ Headphone Jack, Speaker, Speakers ]
+        $ref: /schemas/types.yaml#/definitions/string
+
+      codec:
+        type: object
+

Drop blank line

Quoted 18 lines
Documentation/devicetree/bindings/sound/apple,macaudio.yaml new file +18 -0
+        additionalProperties: false
+
+        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:
+

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

Quoted 10 lines
Documentation/devicetree/bindings/sound/apple,macaudio.yaml new file +10 -0
+              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
+
+      cpu:
+        type: object
+

Drop blank line

Quoted 5 lines
Documentation/devicetree/bindings/sound/apple,macaudio.yaml new file +5 -0
+        additionalProperties: false
+
+        properties:
+          sound-dai:
+            minItems: 1

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

Quoted 10 lines
Documentation/devicetree/bindings/sound/apple,macaudio.yaml new file +10 -0
+            maxItems: 2
+            description: |
+              DAI list with CPU-side I2S ports involved in this peripheral.
+
+        required:
+          - sound-dai
+
+    patternProperties:
+      "^dai-tdm-idle-mode-[0-9]$":
+        $ref: tdm-slot.yaml#/properties/dai-tdm-idle-mode

This looks like you put several slots into one. TDM slot is for one slot, no?

Quoted 49 lines
Documentation/devicetree/bindings/sound/apple,macaudio.yaml new file +49 -0
+
+      "^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
+      - codec
+      - cpu
+
+required:
+  - compatible
+  - model
+
+additionalProperties: false
+
+examples:
+  - |
+    sound {
+      compatible = "apple,j416-macaudio", "apple,j316-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>;
+
+        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>;
+        };
+      };
+

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

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

Example looks incomplete, you miss TDM slot properties.

Quoted 7 lines
Documentation/devicetree/bindings/sound/apple,macaudio.yaml new file +3 -0
+        };
+      };
+    };
Signature · 2 lines
-- 
2.55.0
#14 lore raw

Re: [PATCH v2 05/21] ASoC: dt-bindings: Add binding for Apple Silicon Mac audio

Quoted 37 lines · Australian Eastern Standard Time Krzysztof Kozlowski
Quoted 36 lines · James Calligeros
Documentation/devicetree/bindings/sound/apple,macaudio.yaml new file +36 -0
+examples:
+  - |
+    sound {
+      compatible = "apple,j416-macaudio", "apple,j316-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>;
+
+        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 {
+        reg = <1>;
+        link-name = "Headphone Jack";
+
Quoted 8 lines

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

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

Example looks incomplete, you miss TDM slot properties.

The machine driver generates the TDM slot assignments for the DAIs and sets them at runtime.

#15 lore raw

Re: [PATCH v2 05/21] ASoC: dt-bindings: Add binding for Apple Silicon Mac audio

Quoted 48 lines · James Calligeros
Quoted 37 lines · Australian Eastern Standard Time Krzysztof Kozlowski
Quoted 36 lines · James Calligeros
Documentation/devicetree/bindings/sound/apple,macaudio.yaml new file +36 -0
+examples:
+  - |
+    sound {
+      compatible = "apple,j416-macaudio", "apple,j316-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>;
+
+        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 {
+        reg = <1>;
+        link-name = "Headphone Jack";
+
Quoted 8 lines

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

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

Example looks incomplete, you miss TDM slot properties.

Quoted 2 lines

The machine driver generates the TDM slot assignments for the DAIs and sets them at runtime.

Ah, I found them in dai-link node, one level up.

Best regards,
Krzysztof

#18 lore raw

Re: [PATCH v2 06/21] ASoC: ops: Introduce 'snd_soc_deactivate_kctl'

In reply to James Calligeros
Quoted 5 lines · James Calligeros

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

The new function can be used to deactivate controls. It is something a machine driver may call in fixup_controls.

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

Quoted 10 lines
sound/soc/soc-ops.c +10 -0
+/**
+ * snd_soc_deactivate_kctl - Activate/deactivate control matching a name
+ *
+ * @card: where to look for the controls
+ * @name: name
+ * @active: non-zero to activate, zero to deactivate
+ *
+ * Return 0 for success, else error.
+ */
+int snd_soc_deactivate_kctl(struct snd_soc_card *card,

The name sounds weird with 'int active' in its parameter list. Either pair of wrappers:
snd_soc_ctl_activate()
snd_soc_ctl_deactivate()

or something of snd_soc_ctl_set_status() sort. I see that sound/core
uses: snd_ctl_activate_id(). Perhaps snd_soc_ctl_activate() is winner here by being cohesive with sound/core even with some confusion around 'int activate' part.

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

Quoted 8 lines
sound/soc/soc-ops.c +8 -0
+	const char *name, int active)
+{
+	struct snd_kcontrol *kctl;
+	int ret = -EINVAL;
+
+	/* Sanity check for name */
+	if (unlikely(!name))
+		return -EINVAL;

Not a fan of unlikely() in not performance-critical code.

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

Quoted 7 lines
sound/soc/soc-ops.c +7 -0
+
+	kctl = snd_soc_card_get_kcontrol(card, name);
+
+	if (kctl) {
+		ret = snd_ctl_activate_id(card->snd_card, &kctl->id, active);
+		if (ret < 0)
+			return ret;

The if-statement can be dropped.

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

Quoted 3 lines
sound/soc/soc-ops.c +3 -0
+	} else {
+		dev_dbg(card->dev, "Tried to de/activate unknown control '%s'\n",
+			name);

One line.

Quoted 6 lines
sound/soc/soc-ops.c +6 -0
+	}
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(snd_soc_deactivate_kctl);
+
#23 lore raw

Re: [PATCH v2 07/21] ASoC: ops: Introduce 'soc_set_enum_kctl'

In reply to James Calligeros
Quoted 25 lines · James Calligeros

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

The new function is to be used to set enumerated controls to desired values. It is something a machine driver may call in fixup_controls.

+++ b/sound/soc/soc-ops.c

sound/soc/soc-ops.c +15 -0
@@ -505,6 +505,75 @@ 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 *value)
+{
+	struct snd_ctl_elem_value evalue = { 0 };
+	struct snd_ctl_elem_info info = { 0 };
+	int sel, i, ret;
+
+	ret = kctl->info(kctl, &info);
+	if (ret < 0)
+		return ret;
+
+	if (info.type != SNDRV_CTL_ELEM_TYPE_ENUMERATED)
+		return -EINVAL;
+
+	for (sel = 0; sel < info.value.enumerated.items; sel++) {
+		info.value.enumerated.item = sel;

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

Quoted 10 lines
sound/soc/soc-ops.c +10 -0
+		ret = kctl->info(kctl, &info);
+		if (ret < 0)
+			return ret;
+
+		if (!strcmp(value, info.value.enumerated.name))
+			break;
+	}
+
+	if (sel == info.value.enumerated.items)
+		return -EINVAL;

ENOENT may be a better candidate.

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

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

The if-else statement is redundant here, drop the 'else' part. If fact, it would be better to check for ->put() upfront rather than when all of this iterating is done.

Quoted 10 lines
sound/soc/soc-ops.c +10 -0
+}
+
+/**
+ * snd_soc_set_enum_kctl - Set enumerated control matching a name
+ *
+ * @card: where to look for the controls
+ * @name: name
+ * @value: string value to set the controls to
+ *
+ * Return 0 on success, else error.

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

Quoted 10 lines
sound/soc/soc-ops.c +10 -0
+ */
+int snd_soc_set_enum_kctl(struct snd_soc_card *card,
+	const char *name, const char *value)
+{
+	struct snd_kcontrol *kctl;
+	int ret = -EINVAL;
+
+	/* Sanity check for name */
+	if (unlikely(!name))
+		return -EINVAL;

I'd leave the validation job to snd_soc_card_get_kcontrol().

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

Quoted 7 lines
sound/soc/soc-ops.c +7 -0
+
+	kctl = snd_soc_card_get_kcontrol(card, name);
+
+	if (kctl) {
+		ret = soc_set_enum_kctl(kctl, value);
+		if (ret)
+			return ret;

The if-statement is redundant.

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

Quoted 3 lines
sound/soc/soc-ops.c +3 -0
+	} else {
+		dev_dbg(card->dev, "Tried to set unknown control '%s' to '%s'\n",
+			name, value);

One line.

Maybe just refactor the entire block:

	kctl = snd_soc_card_get_kcontrol(..)
	if (!kctl) {
		dev_dbg(...);
		return -EINVAL;
	}

	return snd_set_enum_kctl(...);

With that, drop the assignment for 'ret' in the declaration block.

Quoted 10 lines
sound/soc/soc-ops.c +6 -0
+	}
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(snd_soc_set_enum_kctl);
+
 int snd_soc_bytes_info(struct snd_kcontrol *kcontrol,
 		       struct snd_ctl_elem_info *uinfo)
 {
#32 lore raw

Re: [PATCH v2 09/21] ASoC: apple: Add macaudio machine driver

In reply to James Calligeros
Quoted 13 lines · 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.

sound/soc/apple/macaudio.c line 105

Quoted 8 lines
sound/soc/apple/macaudio.c new file +8 -0
+struct ma_codec_idle {
+	int idle_mode;
+	u32 idle_mask;
+};
+
+struct macaudio_snd_data {
+	struct snd_soc_card card;
+	struct snd_soc_jack jack;

Hi,

Typically storing both card and jack heralds that the design is off. Especially when stored as fields. Looks to me as if you've made a one structure to catch them all.

Let's start with the card. Below are the users - I'll skip dev_xxx()s as that's an easy fix:

macaudio_dpcm_hw_params()
macaudio_be_hw_free()
both can access the card from the substream/dai without relying on the ma-context

macaudio_parse_of() macaudio_parse_of_be_dai_link()
called in context which creates the very card

macaudio_vlimit_enable_timeout() macaudio_vlimit_disable_timeout() macaudio_vlimit_update()
called in context of delayed part of the trigger() callback. I'd need more information on the trigger() implementation of yours to present a solution. See the comments below.

Skipped macaudio_vlimit_unlock() as it's called in context of macaudio_vlimit_update() and macaudio_late_probe(). The latter has direct access to the card while the former is mentioned above.

Quoted 35 lines
sound/soc/apple/macaudio.c new file +35 -0
+	int jack_plugin_state;
+
+	const struct macaudio_platform_cfg *cfg;
+	bool has_speakers;
+	bool has_sense;
+	bool has_safety;
+	unsigned int max_channels;
+
+	struct macaudio_link_props {
+		/* frontend props */
+		unsigned int bclk_ratio;
+		bool is_sense;
+
+		/* backend props */
+		bool is_speakers;
+		bool is_headphones;
+		unsigned int tdm_mask;
+		struct ma_codec_idle *codecs;
+	} *link_props;
+
+	int speaker_sample_rate;
+	struct snd_kcontrol *speaker_sample_rate_kctl;
+
+	struct mutex be_link_mutex;
+
+	struct mutex volume_lock_mutex;
+	bool speaker_volume_unlocked;
+	bool speaker_volume_was_locked;
+	struct snd_kcontrol *speaker_lock_kctl;
+	u64 bes_active;
+	bool speaker_lock_timeout_enabled;
+	ktime_t speaker_lock_timeout;
+	ktime_t speaker_lock_remain;
+	struct delayed_work lock_timeout_work;
+	struct work_struct lock_update_work;

sound/soc/apple/macaudio.c

Quoted 10 lines
sound/soc/apple/macaudio.c new file +9 -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];
+
+	guard(mutex)(&ma->be_link_mutex);

As already pointed out by Ajay, there is no 'nonatomic' flag set and without such, you will hit a problem, eventually.

Quoted 7 lines
sound/soc/apple/macaudio.c new file +7 -0
+	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);
+			break;

sound/soc/apple/macaudio.c line 959

Quoted 10 lines
sound/soc/apple/macaudio.c new file +10 -0
+		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;
+		default:
+			return -EINVAL;
+		}
+
+		schedule_work(&ma->lock_update_work);

trigger() should enable DMA work and/or signal other components participating in the streaming to start their tasks too.

Please correct me if I'm wrong but it seems the scheduled work does speaker-volume operations only. Moreover, it seems that ->lock_update_work may schedule a follow up work in form of ->lock_timeout_work. Are you sure trigger() is the right place to do volume-control in delayed manner?

Once we clear the mist around the main structure and the trigger() callback, I can happily review the "easier" parts of the patch.

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

Re: [PATCH v2 02/21] ASoC: dt-bindings: cs42l42: Do not require chip power supplies

In reply to Krzysztof Kozlowski
Quoted 7 lines · Australian Eastern Standard Time Krzysztof Kozlowski
Quoted 3 lines · James Calligeros

Some integrators do not expose the power rails connected to the codec in a way that can be expressed in the Devicetree. Do not require them to be specified on such platforms.

I don't understand how these cannot be expressed in Devicetree. What are we missing?

On Apple devices, the regulator(s) driving these pins are completely opaque. They are not exposed via the Apple Devicetree or any other discoverable interface, and they are not controllable. As far as we can tell, the pins in question are powered whenever the machine is powered on.

#16 lore raw

Re: [PATCH v2 05/21] ASoC: dt-bindings: Add binding for Apple Silicon Mac audio

In reply to Krzysztof Kozlowski
Quoted 7 lines · Australian Eastern Standard Time Krzysztof Kozlowski

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

Quoted 3 lines · James Calligeros
Documentation/devicetree/bindings/sound/apple,macaudio.yaml new file +3 -0
+    patternProperties:
+      "^dai-tdm-idle-mode-[0-9]$":
+        $ref: tdm-slot.yaml#/properties/dai-tdm-idle-mode

This looks like you put several slots into one. TDM slot is for one slot, no?

The codec bus keepers (which these properties exist to support) only need to be configured on one codec for the left and one codec for the right. We use the "main" L and R woofer codecs for this purpose, so the extension of the properties like this allows us to specify which codec's bus keeper should be set up, as we need to support machines with 6, 4, 2 and 1 speaker(s).

#33 lore raw

Re: [PATCH v2 09/21] ASoC: apple: Add macaudio machine driver

In reply to Cezary Rojewski

Hi,

Quoted 8 lines · Australian Eastern Standard Time Cezary Rojewski

macaudio_dpcm_hw_params()
macaudio_be_hw_free()
both can access the card from the substream/dai without relying on the ma-context

macaudio_parse_of() macaudio_parse_of_be_dai_link()
called in context which creates the very card

I have fixed all of these by copying what rockchip/rockchip_max98090.c does to initialise the card, however

Quoted 6 lines

macaudio_vlimit_enable_timeout() macaudio_vlimit_disable_timeout() macaudio_vlimit_update()
called in context of delayed part of the trigger() callback. I'd need more information on the trigger() implementation of yours to present a solution. See the comments below.

are slightly more difficult to deal with. These are called from workqueues which only have reference to the driver data struct. Other than keeping a pointer to the card around, I'm not sure how else to deal with this other than keeping a pointer to card around in the driver data struct.

Quoted 5 lines

Please correct me if I'm wrong but it seems the scheduled work does speaker-volume operations only. Moreover, it seems that ->lock_update_work may schedule a follow up work in form of ->lock_timeout_work. Are you sure trigger() is the right place to do volume-control in delayed manner?

The intention here is to activate the timeout when the stream starts so that if speakersafetyd dies at any point during playback, the speaker volume(s) are limited to prevent damage. We only want this running when speaker playback starts and we need to disable it when that playback stops, so trigger() seems like the natural place for this.

James

#34 lore raw

Re: [PATCH v2 09/21] ASoC: apple: Add macaudio machine driver

Quoted 18 lines · James Calligeros
Quoted 6 lines

macaudio_vlimit_enable_timeout() macaudio_vlimit_disable_timeout() macaudio_vlimit_update()
called in context of delayed part of the trigger() callback. I'd need more information on the trigger() implementation of yours to present a solution. See the comments below.

are slightly more difficult to deal with. These are called from workqueues which only have reference to the driver data struct. Other than keeping a pointer to the card around, I'm not sure how else to deal with this other than keeping a pointer to card around in the driver data struct.

Quoted 5 lines

Please correct me if I'm wrong but it seems the scheduled work does speaker-volume operations only. Moreover, it seems that ->lock_update_work may schedule a follow up work in form of ->lock_timeout_work. Are you sure trigger() is the right place to do volume-control in delayed manner?

Quoted 5 lines

The intention here is to activate the timeout when the stream starts so that if speakersafetyd dies at any point during playback, the speaker volume(s) are limited to prevent damage. We only want this running when speaker playback starts and we need to disable it when that playback stops, so trigger() seems like the natural place for this.

How does one know the speaker died? Is there some kind of signal, event or an interrupt we could depend on? As delayed-work is a mechanism of choice here for handling the case, I believe there is still a gap and a chance for bad things to happen.

Czarek

#35 lore raw

Re: [PATCH v2 09/21] ASoC: apple: Add macaudio machine driver

Quoted 4 lines · Cezary Rojewski

How does one know the speaker died? Is there some kind of signal, event or an interrupt we could depend on? As delayed-work is a mechanism of choice here for handling the case, I believe there is still a gap and a chance for bad things to happen.

speakersafetyd is a userspace daemon, not hardware. It cannot generate interrupts. The daemon puts a magic value into a kctl every run of its safety model to signal to the driver that it is alive. The driver checks every time this kctl is put (see macaudio_slk_put) and schedules delayed work for the timeout, resetting the timeout if the correct value is put. If the kctl is not put within the timeout (e.g. if the daemon crashes), it locks the speaker amp volumes to a safe level that will not cause damage.

We do not want these checks running when the PCM is idle however, so when there are no longer any active DAI BEs, we disable the timeout.

Quoted 1 line

Czarek

James

maintainer
#6 lore raw

Re: [PATCH v2 02/21] ASoC: dt-bindings: cs42l42: Do not require chip power supplies

In reply to James Calligeros
Quoted 7 lines · James Calligeros
Quoted 5 lines · Krzysztof Kozlowski
Quoted 3 lines · James Calligeros

Some integrators do not expose the power rails connected to the codec in a way that can be expressed in the Devicetree. Do not require them to be specified on such platforms.

Quoted 7 lines
Quoted 2 lines

I don't understand how these cannot be expressed in Devicetree. What are we missing?

On Apple devices, the regulator(s) driving these pins are completely opaque. They are not exposed via the Apple Devicetree or any other discoverable interface, and they are not controllable. As far as we can tell, the pins in question are powered whenever the machine is powered on.

So just put some fixed regulators in your DT if that's what you have? They must physically exist.

maintainer
#19 lore raw

Re: [PATCH v2 06/21] ASoC: ops: Introduce 'snd_soc_deactivate_kctl'

In reply to James Calligeros

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

Quoted 10 lines · James Calligeros

+ * Return 0 for success, else error.
+ */

sound/soc/soc-ops.c +7 -0
+int snd_soc_deactivate_kctl(struct snd_soc_card *card,
+	const char *name, int active)
+{
 
+	if (kctl) {
+		ret = snd_ctl_activate_id(card->snd_card, &kctl->id, active);
+		if (ret < 0)
+			return ret;

snd_ctl_activate_id() returns 1 on change, 0 on no change, which doesn't match the documentation there.

#26 lore raw

Re: [PATCH v2 08/21] ASoC: card: Let 'fixup_controls' return errors

In reply to Charles Keepax
Quoted 10 lines · Australian Eastern Standard Time Charles Keepax
Quoted 9 lines · 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.

---

Quoted 7 lines
Quoted 5 lines
 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 ++++-

Fixup is missing here for sound/soc/sdca/sdca_class_function.c

Unless I'm missing something, that one calls the .fixup_controls on snd_soc_component_driver, which is not the snd_soc_card callback modified by this commit. That callback already expected an int, and class_function_component_fixup_controls already returns one per b8f71f16134f ("ASoC: SDCA: Switch to fixup_controls callback for IRQ registration").

Regards,
James

#27 lore raw

Re: [PATCH v2 08/21] ASoC: card: Let 'fixup_controls' return errors

In reply to Charles Keepax
Quoted 10 lines · Australian Eastern Standard Time Charles Keepax
Quoted 9 lines · 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.

---

Quoted 7 lines
Quoted 5 lines
 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 ++++-

Fixup is missing here for sound/soc/sdca/sdca_class_function.c

Unless I'm missing something, that one calls the .fixup_controls on snd_soc_component_driver, which is not the snd_soc_card callback modified by this commit. That callback already expected an int, and class_function_component_fixup_controls already returns one per b8f71f16134f ("ASoC: SDCA: Switch to fixup_controls callback for IRQ registration").

Regards,
James

#28 lore raw

Re: [PATCH v2 08/21] ASoC: card: Let 'fixup_controls' return errors

Quoted 18 lines · James Calligeros
Quoted 16 lines · Australian Eastern Standard Time Charles Keepax
Quoted 14 lines · 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 ++++-
Quoted 8 lines
Quoted 1 line

Fixup is missing here for sound/soc/sdca/sdca_class_function.c

Unless I'm missing something, that one calls the .fixup_controls on snd_soc_component_driver, which is not the snd_soc_card callback modified by this commit. That callback already expected an int, and class_function_component_fixup_controls already returns one per b8f71f16134f ("ASoC: SDCA: Switch to fixup_controls callback for IRQ registration").

Yeah my bad, apologies for the noise.

Thanks,
Charles