Skip to contentSkip to conversation

ASoC: add CS42L84 codec driver

PATCH Superseded James Calligeros 4 participants 9 messages Oct 16, 2024 – Oct 18, 2024

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover ASoC: add CS42L84 codec driver

Hi all,

This patch set adds a driver for the Cirrus Logic CS42L84 codec. This chip is (so far) found only on Apple Silicon Macs. In keeping with proud Apple tradition, the CS42L84 is essentially just a CS42L42 with a different regmap and no publicly available datasheet. It may also be missing its parent's S/PDIF capabilities as none of Apple's devices support S/PDIF out, however this cannot be positively confirmed.

This driver has lived in the downstream Asahi tree for quite a while now, and gained some refinements along the way. I have squashed most of these into the initial driver commit as they were small changes like tweaking msleep()s or filling out TLVs, but left seperate a larger change to tip/ring sense IRQ handling as it differs significantly from what is found in the CS42L42 driver.

---
James Calligeros (1):
ASoC: cs42l84: leverage ring sense IRQs to correctly detect headsets

Martin Povišer (2):
dt-bindings: sound: Add CS42L84 codec
ASoC: cs42l84: Add new codec driver

 Documentation/devicetree/bindings/sound/cirrus,cs42l84.yaml |   60 +++++++
 MAINTAINERS                                                 |    2 +
 sound/soc/codecs/Kconfig                                    |    7 +
 sound/soc/codecs/Makefile                                   |    2 +
 sound/soc/codecs/cs42l84.c                                  | 1110 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 sound/soc/codecs/cs42l84.h                                  |  210 +++++++++++++++++++++++++
 6 files changed, 1391 insertions(+)

---
base-commit: 469819cc17368702a6f68cec2148f518d3f3679b
change-id: 20241016-cs42l84-f38348d21c88

Best regards,

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

PATCH 1/3 dt-bindings: sound: Add CS42L84 codec

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

CS42L84 is a headphone jack codec made by Cirrus Logic and seen in Apple computer models starting with 2021 Macbook Pros. It is not a publicly documented part. To a degree the part is similar to the public CS42L42. (The L84 superseded L83 seen in earlier Apple models, and the L83 was pretty much the same as L42.)

---
 Documentation/devicetree/bindings/sound/cirrus,cs42l84.yaml | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 MAINTAINERS                                                 |  1 +
 2 files changed, 61 insertions(+)
Documentation/devicetree/bindings/sound/cirrus,cs42l84.yaml new file +60 -0
new file mode 100644
index 0000000000000000000000000000000000000000..12bc6dbeeddfaccf9dd00deb2676deac25f28c9e
@@ -0,0 +1,60 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/cirrus,cs42l84.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Cirrus Logic CS42L84 audio CODEC
+
+maintainers:
+  - [email protected]
+
+description:
+  The CS42L84 is a headphone jack codec made by Cirrus Logic and embedded
+  in personal computers sold by Apple. It was first seen in 2021 Macbook Pro
+  models.
+
+  It has stereo DAC for playback, mono ADC for capture, and is somewhat
+  similar to CS42L42 but with a different regmap.
+
+properties:
+  compatible:
+    enum:
+      - cirrus,cs42l84
+
+  reg:
+    description:
+      I2C address of the device
+    maxItems: 1
+
+  reset-gpios:
+    description:
+      Reset pin, asserted to reset the device, deasserted to bring
+      the device online
+    maxItems: 1
+
+  interrupts:
+    description:
+      Interrupt for the IRQ output line of the device
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+    i2c {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      jack_codec: codec@4b {
+          compatible = "cirrus,cs42l84";
+          reg = <0x4b>;
+          reset-gpios = <&pinctrl_nub 4 GPIO_ACTIVE_LOW>;
+          interrupts-extended = <&pinctrl_ap 180 IRQ_TYPE_LEVEL_LOW>;
+          #sound-dai-cells = <0>;
+      };
+    };
MAINTAINERS +1 -0
index c1a2c296446c0724a0c6e70c845e5e5e1e693fd5..f5f85714dc4e8ca9c60b3f6963b2cec1ea33fdd0 100644
@@ -2132,6 +2132,7 @@ L:	[email protected]
 L:	[email protected]
 S:	Maintained
 F:	Documentation/devicetree/bindings/sound/adi,ssm3515.yaml
+F:	Documentation/devicetree/bindings/sound/cirrus,cs42l84.yaml
 F:	Documentation/devicetree/bindings/sound/apple,*
 F:	sound/soc/apple/*
 F:	sound/soc/codecs/cs42l83-i2c.c
Signature · 1 line
2.47.0
#4 lore raw

PATCH 2/3 ASoC: cs42l84: Add new codec driver

In reply to James Calligeros

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

The CS42L84 is a codec from Cirrus Logic found in Apple Silicon Macs. The chip continues Apple's long tradition of compelling vendors to spin out bespoke SKUs that are based on existing IP but made subtly incompatible with the publicly available part. CS42L84 is very similar to CS42L42, but has a different regmap.

---
 MAINTAINERS                |    1 +
 sound/soc/codecs/Kconfig   |    7 ++
 sound/soc/codecs/Makefile  |    2 +
 sound/soc/codecs/cs42l84.c | 1081 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 sound/soc/codecs/cs42l84.h |  210 ++++++++++++++++++++++++++++++++
 5 files changed, 1301 insertions(+)
MAINTAINERS +1 -0
index f5f85714dc4e8ca9c60b3f6963b2cec1ea33fdd0..fc321f5ac579ed01a66523430e0e8b9afaf4cb7a 100644
@@ -2136,6 +2136,7 @@ F:	Documentation/devicetree/bindings/sound/cirrus,cs42l84.yaml
 F:	Documentation/devicetree/bindings/sound/apple,*
 F:	sound/soc/apple/*
 F:	sound/soc/codecs/cs42l83-i2c.c
+F:	sound/soc/codecs/cs42l84.*
 F:	sound/soc/codecs/ssm3515.c
 
 ARM/APPLE MACHINE SUPPORT
sound/soc/codecs/Kconfig +7 -0
index 6a6125e94d2dc094b10c6f2fb53dd447e831f23d..f5a9e596632c970eef7a385e09a55355ac41fbfc 100644
@@ -85,6 +85,7 @@ config SND_SOC_ALL_CODECS
 	imply SND_SOC_CS42L52
 	imply SND_SOC_CS42L56
 	imply SND_SOC_CS42L73
+	imply SND_SOC_CS42L84
 	imply SND_SOC_CS4234
 	imply SND_SOC_CS4265
 	imply SND_SOC_CS4270
@@ -929,6 +930,12 @@ config SND_SOC_CS42L83
 	select REGMAP_I2C
 	select SND_SOC_CS42L42_CORE
 
+config SND_SOC_CS42L84
+	tristate "Cirrus Logic CS42L84 CODEC"
+	depends on I2C
+	select REGMAP
+	select REGMAP_I2C
+
 config SND_SOC_CS4234
 	tristate "Cirrus Logic CS4234 CODEC"
 	depends on I2C
sound/soc/codecs/Makefile +2 -0
index ac7d8b71b32b19a41366966065de450b947c9178..2c69df06677e54e149ca848ccaf412e4b9c0f2c2 100644
@@ -91,6 +91,7 @@ snd-soc-cs42l52-y := cs42l52.o
 snd-soc-cs42l56-y := cs42l56.o
 snd-soc-cs42l73-y := cs42l73.o
 snd-soc-cs42l83-i2c-y := cs42l83-i2c.o
+snd-soc-cs42l84-objs := cs42l84.o
 snd-soc-cs4234-y := cs4234.o
 snd-soc-cs4265-y := cs4265.o
 snd-soc-cs4270-y := cs4270.o
@@ -505,6 +506,7 @@ obj-$(CONFIG_SND_SOC_CS42L52)	+= snd-soc-cs42l52.o
 obj-$(CONFIG_SND_SOC_CS42L56)	+= snd-soc-cs42l56.o
 obj-$(CONFIG_SND_SOC_CS42L73)	+= snd-soc-cs42l73.o
 obj-$(CONFIG_SND_SOC_CS42L83)	+= snd-soc-cs42l83-i2c.o
+obj-$(CONFIG_SND_SOC_CS42L84)	+= snd-soc-cs42l84.o
 obj-$(CONFIG_SND_SOC_CS4234)	+= snd-soc-cs4234.o
 obj-$(CONFIG_SND_SOC_CS4265)	+= snd-soc-cs4265.o
 obj-$(CONFIG_SND_SOC_CS4270)	+= snd-soc-cs4270.o
sound/soc/codecs/cs42l84.c new file +1081 -0

1,081 lines not on this page · raw message

sound/soc/codecs/cs42l84.h new file +210 -0

210 lines not on this page · raw message

Signature · 1 line
2.47.0
#7 lore raw

PATCH 3/3 ASoC: cs42l84: leverage ring sense IRQs to correctly detect headsets

In reply to James Calligeros

Some jacks integrated on devices with this codec, such as certain Apple Silicon Macs, have quite trigger-happy tip sense switches that cause a tip sense IRQ before the plug is fully seated. If users are unfortunate with their timing, this can lead to headsets being detected as mic-less headphones among other issues with the codec's device detection routines.

Introduce some rudimentary ring sense interrupt handling so that we can re-trigger the codec's detection routines when we are certain that the plug is fully seated.

This seems to differ from what other Cirrus drivers do, but is necessary for devices to be reliably detected properly here.

---
 sound/soc/codecs/cs42l84.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------
 1 file changed, 59 insertions(+), 30 deletions(-)
sound/soc/codecs/cs42l84.c +59 -30
index dbbc76f41ccb958b068848426d1891b16aa84866..8711968a38e24de221e32066739cc4d60964fdef 100644
@@ -44,7 +44,8 @@ struct cs42l84_private {
 	struct gpio_desc *reset_gpio;
 	struct snd_soc_jack *jack;
 	struct mutex irq_lock;
-	u8 plug_state;
+	u8 tip_state;
+	u8 ring_state;
 	int pll_config;
 	int bclk;
 	u8 pll_mclk_f;
@@ -797,13 +798,23 @@ static void cs42l84_revert_hs(struct cs42l84_private *cs42l84)
 		FIELD_PREP(CS42L84_HS_DET_CTL2_SET, 2));
 }
 
+static void cs42l84_set_interrupt_masks(struct cs42l84_private *cs42l84,
+					unsigned int val)
+{
+	regmap_update_bits(cs42l84->regmap, CS42L84_TSRS_PLUG_INT_MASK,
+			CS42L84_RS_PLUG | CS42L84_RS_UNPLUG |
+			CS42L84_TS_PLUG | CS42L84_TS_UNPLUG,
+			val);
+}
+
 static irqreturn_t cs42l84_irq_thread(int irq, void *data)
 {
 	struct cs42l84_private *cs42l84 = (struct cs42l84_private *)data;
 	unsigned int stickies[1];
 	unsigned int masks[1];
 	unsigned int reg;
-	u8 current_plug_status;
+	u8 current_tip_state;
+	u8 current_ring_state;
 	int i;
 
 	mutex_lock(&cs42l84->irq_lock);
@@ -817,16 +828,24 @@ static irqreturn_t cs42l84_irq_thread(int irq, void *data)
 				irq_params_table[i].mask;
 	}
 
+	/* When handling plug sene IRQs, we only care about EITHER tip OR ring.
+	 * Ring is useless on remove, and is only useful on insert for
+	 * detecting if the plug state has changed AFTER we have handled the
+	 * tip sense IRQ, e.g. if the plug was not fully seated within the tip
+	 * sense debounce time.
+	 */
+
 	if ((~masks[0]) & irq_params_table[0].mask) {
 		regmap_read(cs42l84->regmap, CS42L84_TSRS_PLUG_STATUS, &reg);
-		current_plug_status = (((char) reg) &
+
+		current_tip_state = (((char) reg) &
 		      (CS42L84_TS_PLUG | CS42L84_TS_UNPLUG)) >>
 		      CS42L84_TS_PLUG_SHIFT;
 
-		switch (current_plug_status) {
-		case CS42L84_PLUG:
-			if (cs42l84->plug_state != CS42L84_PLUG) {
-				cs42l84->plug_state = CS42L84_PLUG;
+		if (current_tip_state != cs42l84->tip_state) {
+			cs42l84->tip_state = current_tip_state;
+			switch (current_tip_state) {
+			case CS42L84_PLUG:
 				dev_dbg(cs42l84->dev, "Plug event\n");
 
 				cs42l84_detect_hs(cs42l84);
@@ -839,47 +858,57 @@ static irqreturn_t cs42l84_irq_thread(int irq, void *data)
 				 * was disconnected at any point during the detection procedure.
 				 */
 				regmap_read(cs42l84->regmap, CS42L84_TSRS_PLUG_STATUS, &reg);
-				current_plug_status = (((char) reg) &
+				current_tip_state = (((char) reg) &
 				      (CS42L84_TS_PLUG | CS42L84_TS_UNPLUG)) >>
 				      CS42L84_TS_PLUG_SHIFT;
-				if (current_plug_status != CS42L84_PLUG) {
+				if (current_tip_state != CS42L84_PLUG) {
 					dev_dbg(cs42l84->dev, "Wobbly connection, detection invalidated\n");
-					cs42l84->plug_state = CS42L84_UNPLUG;
+					cs42l84->tip_state = CS42L84_UNPLUG;
 					cs42l84_revert_hs(cs42l84);
 				}
-			}
-			break;
 
-		case CS42L84_UNPLUG:
-			if (cs42l84->plug_state != CS42L84_UNPLUG) {
-				cs42l84->plug_state = CS42L84_UNPLUG;
+				/* Unmask ring sense interrupts */
+				cs42l84_set_interrupt_masks(cs42l84, 0);
+				break;
+			case CS42L84_UNPLUG:
+				cs42l84->ring_state = CS42L84_UNPLUG;
 				dev_dbg(cs42l84->dev, "Unplug event\n");
 
 				cs42l84_revert_hs(cs42l84);
 				cs42l84->hs_type = 0;
 				snd_soc_jack_report(cs42l84->jack, 0,
 						    SND_JACK_HEADSET);
+
+				/* Mask ring sense interrupts */
+				cs42l84_set_interrupt_masks(cs42l84,
+							    CS42L84_RS_PLUG | CS42L84_RS_UNPLUG);
+				break;
+			default:
+				cs42l84->ring_state = CS42L84_TRANS;
 			}
-			break;
 
-		default:
-			if (cs42l84->plug_state != CS42L84_TRANS)
-				cs42l84->plug_state = CS42L84_TRANS;
+			mutex_unlock(&cs42l84->irq_lock);
+
+			return IRQ_HANDLED;
+		}
+
+		/* Tip state didn't change, we must've got a ring sense IRQ */
+		current_ring_state = (((char) reg) &
+		      (CS42L84_RS_PLUG | CS42L84_RS_UNPLUG)) >>
+		      CS42L84_RS_PLUG_SHIFT;
+
+		if (current_ring_state != cs42l84->ring_state) {
+			cs42l84->ring_state = current_ring_state;
+			if (current_ring_state == CS42L84_PLUG)
+				cs42l84_detect_hs(cs42l84);
 		}
 	}
+
 	mutex_unlock(&cs42l84->irq_lock);
 
 	return IRQ_HANDLED;
 }
 
-static void cs42l84_set_interrupt_masks(struct cs42l84_private *cs42l84)
-{
-	regmap_update_bits(cs42l84->regmap, CS42L84_TSRS_PLUG_INT_MASK,
-			CS42L84_RS_PLUG | CS42L84_RS_UNPLUG |
-			CS42L84_TS_PLUG | CS42L84_TS_UNPLUG,
-			CS42L84_RS_PLUG | CS42L84_RS_UNPLUG);
-}
-
 static void cs42l84_setup_plug_detect(struct cs42l84_private *cs42l84)
 {
 	unsigned int reg;
@@ -909,7 +938,7 @@ static void cs42l84_setup_plug_detect(struct cs42l84_private *cs42l84)
 
 	/* Save the initial status of the tip sense */
 	regmap_read(cs42l84->regmap, CS42L84_TSRS_PLUG_STATUS, &reg);
-	cs42l84->plug_state = (((char) reg) &
+	cs42l84->tip_state = (((char) reg) &
 		      (CS42L84_TS_PLUG | CS42L84_TS_UNPLUG)) >>
 		      CS42L84_TS_PLUG_SHIFT;
 
@@ -1016,8 +1045,8 @@ static int cs42l84_i2c_probe(struct i2c_client *i2c_client)
 	/* Setup plug detection */
 	cs42l84_setup_plug_detect(cs42l84);
 
-	/* Mask/Unmask Interrupts */
-	cs42l84_set_interrupt_masks(cs42l84);
+	/* Mask ring sense interrupts */
+	cs42l84_set_interrupt_masks(cs42l84, CS42L84_RS_PLUG | CS42L84_RS_UNPLUG);
 
 	/* Register codec for machine driver */
 	ret = devm_snd_soc_register_component(&i2c_client->dev,
Signature · 1 line
2.47.0
#2 lore raw

Re: [PATCH 1/3] dt-bindings: sound: Add CS42L84 codec

In reply to James Calligeros
Quoted 8 lines · James Calligeros

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

CS42L84 is a headphone jack codec made by Cirrus Logic and seen in Apple computer models starting with 2021 Macbook Pros. It is not a publicly documented part. To a degree the part is similar to the public CS42L42. (The L84 superseded L83 seen in earlier Apple models, and the L83 was pretty much the same as L42.)

Quoted 7 lines
---
 Documentation/devicetree/bindings/sound/cirrus,cs42l84.yaml | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 MAINTAINERS                                                 |  1 +
 2 files changed, 61 insertions(+)

My bot found errors running 'make dt_binding_check' on your patch:

yamllint warnings/errors:

dtschema/dtc warnings/errors:
Error: Documentation/devicetree/bindings/sound/cirrus,cs42l84.example.dts:25.45-46 syntax error FATAL ERROR: Unable to parse input tree
make[2]: *** [scripts/Makefile.dtbs:129: Documentation/devicetree/bindings/sound/cirrus,cs42l84.example.dtb] Error 1 make[2]: *** Waiting for unfinished jobs....
make[1]: *** [/builds/robherring/dt-review-ci/linux/Makefile:1442: dt_binding_check] Error 2
make: *** [Makefile:224: __sub-make] Error 2

doc reference errors (make refcheckdocs):

See https://patchwork.ozlabs.org/project/devicetree-bindings/patch/[email protected]

The base for the series is generally the latest rc1. A different dependency should be noted in *this* patch.

If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:

pip3 install dtschema --upgrade

Please check and re-submit after running the above command yourself. Note that DT_SCHEMA_FILES can be set to your schema file to speed up checking your schema. However, it must be unset to test all examples with your schema.

maintainer
#5 lore raw

Re: [PATCH 2/3] ASoC: cs42l84: Add new codec driver

In reply to James Calligeros
Quoted 9 lines · James Calligeros

The CS42L84 is a codec from Cirrus Logic found in Apple Silicon Macs. The chip continues Apple's long tradition of compelling vendors to spin out bespoke SKUs that are based on existing IP but made subtly incompatible with the publicly available part. CS42L84 is very similar to CS42L42, but has a different regmap.

 sound/soc/codecs/Makefile  |    2 +
 sound/soc/codecs/cs42l84.c | 1081 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 sound/soc/codecs/cs42l84.h |  210 ++++++++++++++++++++++++++++++++

Something's wrong with your formatting here...

sound/soc/codecs/cs42l84.c line 4

Quoted 5 lines
sound/soc/codecs/cs42l84.c new file +4 -0
@@ -0,0 +1,1081 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * cs42l84.c -- CS42L84 ALSA SoC audio driver
+ *

Please make the entire comment a C++ one so it's more clearly intentional.

sound/soc/codecs/cs42l84.c line 76

Quoted 7 lines
sound/soc/codecs/cs42l84.c new file +7 -0
+static const struct regmap_config cs42l84_regmap = {
+	.reg_bits = 16,
+	.val_bits = 8,
+
+	.volatile_reg = cs42l84_volatile_register,
+
+	.max_register = 0xffff,

Does that register actually exist?

sound/soc/codecs/cs42l84.c line 78

Quoted 1 line
sound/soc/codecs/cs42l84.c new file +1 -0
+	.cache_type = REGCACHE_RBTREE,

Unless you've got a particular reason to use something else new drivers should use _MAPLE.

Quoted 5 lines
sound/soc/codecs/cs42l84.c new file +5 -0
+static int cs42l84_mute_stream(struct snd_soc_dai *dai, int mute, int stream)
+{
+	struct snd_soc_component *component = dai->component;
+	struct cs42l84_private *cs42l84 = snd_soc_component_get_drvdata(component);
+	unsigned int regval;

sound/soc/codecs/cs42l84.c line 623

Quoted 10 lines
sound/soc/codecs/cs42l84.c new file +9 -0
+	int ret;
 
+				ret = regmap_read_poll_timeout(cs42l84->regmap,
+							       CS42L84_PLL_LOCK_STATUS,
+							       regval,
+							       (regval & CS42L84_PLL_LOCK_STATUS_LOCKED),
+							       CS42L84_PLL_LOCK_POLL_US,
+							       CS42L84_PLL_LOCK_TIMEOUT_US);
+				if (ret < 0)
+					dev_warn(component->dev, "PLL failed to lock: %d\n", ret);

This is too heavyweight for a mute operation, do you really need one?

sound/soc/codecs/cs42l84.c line 773

Quoted 10 lines
sound/soc/codecs/cs42l84.c new file +10 -0
+	case 0b00: /* open */
+		dev_dbg(cs42l84->dev, "Detected open circuit on HS4\n");
+		fallthrough;
+	case 0b11: /* shorted */
+	default:
+		snd_soc_jack_report(cs42l84->jack, SND_JACK_HEADPHONE,
+				SND_JACK_HEADSET);
+		cs42l84->hs_type = SND_JACK_HEADPHONE;
+		dev_dbg(cs42l84->dev, "Detected bare headphone (no mic)\n");
+	}

For coding style we should have a break at the end of the case.

sound/soc/codecs/cs42l84.c line 868

Quoted 4 lines
sound/soc/codecs/cs42l84.c new file +4 -0
+		default:
+			if (cs42l84->plug_state != CS42L84_TRANS)
+				cs42l84->plug_state = CS42L84_TRANS;
+		}

Here too.

maintainer
#3 lore raw

Re: [PATCH 1/3] dt-bindings: sound: Add CS42L84 codec

In reply to James Calligeros
Quoted 21 lines · James Calligeros

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

CS42L84 is a headphone jack codec made by Cirrus Logic and seen in Apple computer models starting with 2021 Macbook Pros. It is not a publicly documented part. To a degree the part is similar to the public CS42L42. (The L84 superseded L83 seen in earlier Apple models, and the L83 was pretty much the same as L42.)

---
 Documentation/devicetree/bindings/sound/cirrus,cs42l84.yaml | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 MAINTAINERS                                                 |  1 +
 2 files changed, 61 insertions(+)
Documentation/devicetree/bindings/sound/cirrus,cs42l84.yaml new file +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..12bc6dbeeddfaccf9dd00deb2676deac25f28c9e

Documentation/devicetree/bindings/sound/cirrus,cs42l84.yaml line 10

Quoted 10 lines
Documentation/devicetree/bindings/sound/cirrus,cs42l84.yaml new file +10 -0
@@ -0,0 +1,60 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/cirrus,cs42l84.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Cirrus Logic CS42L84 audio CODEC
+
+maintainers:
+  - [email protected]

Name too please.

Documentation/devicetree/bindings/sound/cirrus,cs42l84.yaml line 12

Quoted 2 lines
Documentation/devicetree/bindings/sound/cirrus,cs42l84.yaml new file +2 -0
+
+description:

Needs a '>' if you want to maintain paragraphs.

Quoted 5 lines
Documentation/devicetree/bindings/sound/cirrus,cs42l84.yaml new file +5 -0
+  The CS42L84 is a headphone jack codec made by Cirrus Logic and embedded
+  in personal computers sold by Apple. It was first seen in 2021 Macbook Pro
+  models.
+
+  It has stereo DAC for playback, mono ADC for capture, and is somewhat

Documentation/devicetree/bindings/sound/cirrus,cs42l84.yaml line 27

Quoted 10 lines
Documentation/devicetree/bindings/sound/cirrus,cs42l84.yaml new file +10 -0
+  similar to CS42L42 but with a different regmap.
+
+properties:
+  compatible:
+    enum:
+      - cirrus,cs42l84
+
+  reg:
+    description:
+      I2C address of the device

Drop. That's every device.

Documentation/devicetree/bindings/sound/cirrus,cs42l84.yaml line 33

Quoted 6 lines
Documentation/devicetree/bindings/sound/cirrus,cs42l84.yaml new file +6 -0
+    maxItems: 1
+
+  reset-gpios:
+    description:
+      Reset pin, asserted to reset the device, deasserted to bring
+      the device online

Drop. That's every reset-gpios.

Documentation/devicetree/bindings/sound/cirrus,cs42l84.yaml line 38

Quoted 5 lines
Documentation/devicetree/bindings/sound/cirrus,cs42l84.yaml new file +5 -0
+    maxItems: 1
+
+  interrupts:
+    description:
+      Interrupt for the IRQ output line of the device

Drop.

Quoted 10 lines
Documentation/devicetree/bindings/sound/cirrus,cs42l84.yaml new file +10 -0
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |

Documentation/devicetree/bindings/sound/cirrus,cs42l84.yaml line 58

Quoted 10 lines
Documentation/devicetree/bindings/sound/cirrus,cs42l84.yaml new file +10 -0
+    i2c {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      jack_codec: codec@4b {
+          compatible = "cirrus,cs42l84";
+          reg = <0x4b>;
+          reset-gpios = <&pinctrl_nub 4 GPIO_ACTIVE_LOW>;
+          interrupts-extended = <&pinctrl_ap 180 IRQ_TYPE_LEVEL_LOW>;
+          #sound-dai-cells = <0>;

Not documented.

Quoted 18 lines
Documentation/devicetree/bindings/sound/cirrus,cs42l84.yaml new file +2 -0
+      };
+    };
MAINTAINERS +1 -0
index c1a2c296446c0724a0c6e70c845e5e5e1e693fd5..f5f85714dc4e8ca9c60b3f6963b2cec1ea33fdd0 100644
@@ -2132,6 +2132,7 @@ L:	[email protected]
 L:	[email protected]
 S:	Maintained
 F:	Documentation/devicetree/bindings/sound/adi,ssm3515.yaml
+F:	Documentation/devicetree/bindings/sound/cirrus,cs42l84.yaml
 F:	Documentation/devicetree/bindings/sound/apple,*
 F:	sound/soc/apple/*
 F:	sound/soc/codecs/cs42l83-i2c.c
Signature · 2 lines
-- 
2.47.0
Reviewed-by on the v1 series
#8 lore raw
In reply to James Calligeros
Quoted 32 lines · James Calligeros

Hi all,

This patch set adds a driver for the Cirrus Logic CS42L84 codec. This chip is (so far) found only on Apple Silicon Macs. In keeping with proud Apple tradition, the CS42L84 is essentially just a CS42L42 with a different regmap and no publicly available datasheet. It may also be missing its parent's S/PDIF capabilities as none of Apple's devices support S/PDIF out, however this cannot be positively confirmed.

This driver has lived in the downstream Asahi tree for quite a while now, and gained some refinements along the way. I have squashed most of these into the initial driver commit as they were small changes like tweaking msleep()s or filling out TLVs, but left seperate a larger change to tip/ring sense IRQ handling as it differs significantly from what is found in the CS42L42 driver.

---
James Calligeros (1):
ASoC: cs42l84: leverage ring sense IRQs to correctly detect headsets

Martin Povišer (2):
dt-bindings: sound: Add CS42L84 codec
ASoC: cs42l84: Add new codec driver

 Documentation/devicetree/bindings/sound/cirrus,cs42l84.yaml |   60 +++++++
 MAINTAINERS                                                 |    2 +
 sound/soc/codecs/Kconfig                                    |    7 +
 sound/soc/codecs/Makefile                                   |    2 +
 sound/soc/codecs/cs42l84.c                                  | 1110 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 sound/soc/codecs/cs42l84.h                                  |  210 +++++++++++++++++++++++++
 6 files changed, 1391 insertions(+)
Quoted 9 lines

---
base-commit: 469819cc17368702a6f68cec2148f518d3f3679b
change-id: 20241016-cs42l84-f38348d21c88

Best regards,
--
James Calligeros <[email protected]>

Used and reviewed over multiple revisions in Fedora Asahi Remix. :)

Signature · 1 line
真実はいつも一つ!/ Always, there's only one truth!
#6 lore raw

Re: [PATCH 2/3] ASoC: cs42l84: Add new codec driver

In reply to Mark Brown

Hi Mark,

Quoted 9 lines · Mark Brown

sound/soc/codecs/cs42l84.c line 76

Quoted 7 lines
sound/soc/codecs/cs42l84.c new file +7 -0
+static const struct regmap_config cs42l84_regmap = {
+     .reg_bits = 16,
+     .val_bits = 8,
+
+     .volatile_reg = cs42l84_volatile_register,
+
+     .max_register = 0xffff,

Does that register actually exist?

It is likely that the highest register is the ID register, which would match CS42L42. Setting that here does not break anything.

Quoted 16 lines
Quoted 5 lines
sound/soc/codecs/cs42l84.c new file +5 -0
+static int cs42l84_mute_stream(struct snd_soc_dai *dai, int mute, int stream)
+{
+     struct snd_soc_component *component = dai->component;
+     struct cs42l84_private *cs42l84 = snd_soc_component_get_drvdata(component);
+     unsigned int regval;

sound/soc/codecs/cs42l84.c line 623

Quoted 10 lines
sound/soc/codecs/cs42l84.c new file +9 -0
+     int ret;
 
+                             ret = regmap_read_poll_timeout(cs42l84->regmap,
+                                                            CS42L84_PLL_LOCK_STATUS,
+                                                            regval,
+                                                            (regval & CS42L84_PLL_LOCK_STATUS_LOCKED),
+                                                            CS42L84_PLL_LOCK_POLL_US,
+                                                            CS42L84_PLL_LOCK_TIMEOUT_US);
+                             if (ret < 0)
+                                     dev_warn(component->dev, "PLL failed to lock: %d\n", ret);
Quoted 1 line

This is too heavyweight for a mute operation, do you really need one?

Unfortunately it seems that way. This was carried over directly from CS42L42, and as the comment in the function states, the internal power supply will discharge
itself and crash the chip if the PLL is set up before any of the interfaces are fully enabled. This is corroborrated by the CS42L42 datasheet. I've spent some time today trying to work around this, but trying to sequence and enable the PLL anywhere more sensible either causes the chip to crash or causes audible clock jitter artefacts.

Regards,
James