From: James Calligeros <jcalligeros99@gmail.com>
To: Liam Girdwood <lgirdwood@gmail.com>,
Mark Brown <broonie@kernel.org>,
Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
Shenghao Ding <shenghao-ding@ti.com>, Kevin Lu <kevin-lu@ti.com>,
Baojun Xu <baojun.xu@ti.com>, Dan Murphy <dmurphy@ti.com>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Shi Fu <shifu0704@thundersoft.com>
Cc: "Alyssa Rosenzweig" <alyssa@rosenzweig.io>,
"Martin Povišer" <povik+lin@cutebit.org>,
"Hector Martin" <marcan@marcan.st>,
linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
devicetree@vger.kernel.org, asahi@lists.linux.dev,
"James Calligeros" <jcalligeros99@gmail.com>
Subject: [PATCH 09/27] ASoC: tas2764: Apply Apple quirks
Date: Sat, 15 Feb 2025 10:02:42 +1000 [thread overview]
Message-ID: <20250215-apple-codec-changes-v1-9-723569b21b19@gmail.com> (raw)
In-Reply-To: <20250215-apple-codec-changes-v1-0-723569b21b19@gmail.com>
From: Martin Povišer <povik+lin@cutebit.org>
Apple's SN012776 driver has some peculiar aspects to its behavior that
are suspected to work around issues in the codec part. Add a module
parameter for enabling individual quirks that should be imitated after
the Apple driver.
Setting some of these by default seems to be required. For example,
setting 0xf fixes an issue with transient overcurrent errors which
can crash the chip until the next system reboot. To be safe, let's
enable all of them by default.
Co-developed-by: Hector Martin <marcan@marcan.st>
Signed-off-by: Hector Martin <marcan@marcan.st>
Signed-off-by: Martin Povišer <povik+lin@cutebit.org>
Co-developed-by: James Calligeros <jcalligeros99@gmail.com>
Signed-off-by: James Calligeros <jcalligeros99@gmail.com>
---
sound/soc/codecs/tas2764-quirks.h | 188 +++++++++++++++++++++++++
sound/soc/codecs/tas2764.c | 38 +++++
2 files changed, 226 insertions(+)
diff --git a/sound/soc/codecs/tas2764-quirks.h b/sound/soc/codecs/tas2764-quirks.h
new file mode 100644
index 0000000000000000000000000000000000000000..67cdae90b766a9180dac375478060223f6c4e6b4
--- /dev/null
+++ b/sound/soc/codecs/tas2764-quirks.h
@@ -0,0 +1,188 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __TAS2764_QUIRKS__
+#define __TAS2764_QUIRKS__
+
+#include <linux/regmap.h>
+
+#include "tas2764.h"
+
+/* Bitmask of enabled Apple quirks */
+#define ENABLED_APPLE_QUIRKS 0x3f
+
+/*
+ * Disable noise gate and flip down reserved bit in NS_CFG0
+ */
+#define TAS2764_NOISE_GATE_DISABLE BIT(0)
+
+static const struct reg_sequence tas2764_noise_gate_dis_seq[] = {
+ REG_SEQ0(TAS2764_REG(0x0, 0x35), 0xb0)
+};
+
+/*
+ * CONV_VBAT_PVDD_MODE=1
+ */
+#define TAS2764_CONV_VBAT_PVDD_MODE BIT(1)
+
+static const struct reg_sequence tas2764_conv_vbat_pvdd_mode_seq[] = {
+ REG_SEQ0(TAS2764_REG(0x0, 0x6b), 0x41)
+};
+
+/*
+ * Reset of DAC modulator when DSP is OFF
+ */
+#define TAS2764_DMOD_RST BIT(2)
+
+static const struct reg_sequence tas2764_dmod_rst_seq[] = {
+ REG_SEQ0(TAS2764_REG(0x0, 0x76), 0x0)
+};
+
+/*
+ * Unknown 0x133/0x137 writes (maybe TDM related)
+ */
+#define TAS2764_UNK_SEQ0 BIT(3)
+
+static const struct reg_sequence tas2764_unk_seq0[] = {
+ REG_SEQ0(TAS2764_REG(0x1, 0x33), 0x80),
+ REG_SEQ0(TAS2764_REG(0x1, 0x37), 0x3a),
+};
+
+/*
+ * Unknown 0x614 - 0x61f writes
+ */
+#define TAS2764_APPLE_UNK_SEQ1 BIT(4)
+
+static const struct reg_sequence tas2764_unk_seq1[] = {
+ REG_SEQ0(TAS2764_REG(0x6, 0x14), 0x0),
+ REG_SEQ0(TAS2764_REG(0x6, 0x15), 0x13),
+ REG_SEQ0(TAS2764_REG(0x6, 0x16), 0x52),
+ REG_SEQ0(TAS2764_REG(0x6, 0x17), 0x0),
+ REG_SEQ0(TAS2764_REG(0x6, 0x18), 0xe4),
+ REG_SEQ0(TAS2764_REG(0x6, 0x19), 0xc),
+ REG_SEQ0(TAS2764_REG(0x6, 0x16), 0xaa),
+ REG_SEQ0(TAS2764_REG(0x6, 0x1b), 0x0),
+ REG_SEQ0(TAS2764_REG(0x6, 0x1c), 0x12),
+ REG_SEQ0(TAS2764_REG(0x6, 0x1d), 0xa0),
+ REG_SEQ0(TAS2764_REG(0x6, 0x1e), 0xd8),
+ REG_SEQ0(TAS2764_REG(0x6, 0x1f), 0x0),
+};
+
+/*
+ * Unknown writes in the 0xfd page (with secondary paging inside)
+ */
+#define TAS2764_APPLE_UNK_SEQ2 BIT(5)
+
+static const struct reg_sequence tas2764_unk_seq2[] = {
+ REG_SEQ0(TAS2764_REG(0xfd, 0x0d), 0xd),
+ REG_SEQ0(TAS2764_REG(0xfd, 0x6c), 0x2),
+ REG_SEQ0(TAS2764_REG(0xfd, 0x6d), 0xf),
+ REG_SEQ0(TAS2764_REG(0xfd, 0x0d), 0x0),
+};
+
+/*
+ * Disable 'Thermal Threshold 1'
+ */
+#define TAS2764_THERMAL_TH1_DISABLE BIT(6)
+
+static const struct reg_sequence tas2764_thermal_th1_dis_seq[] = {
+ REG_SEQ0(TAS2764_REG(0x1, 0x47), 0x2),
+};
+
+/*
+ * Imitate Apple's shutdown dance
+ */
+#define TAS2764_SHUTDOWN_DANCE BIT(7)
+
+static const struct reg_sequence tas2764_shutdown_dance_init_seq[] = {
+ /*
+ * SDZ_MODE=01 (immediate)
+ *
+ * We want the shutdown to happen under the influence of
+ * the magic writes in the 0xfdXX region, so make sure
+ * the shutdown is immediate and there's no grace period
+ * followed by the codec part.
+ */
+ REG_SEQ0(TAS2764_REG(0x0, 0x7), 0x60),
+};
+
+static const struct reg_sequence tas2764_pre_shutdown_seq[] = {
+ REG_SEQ0(TAS2764_REG(0xfd, 0x0d), 0xd), /* switch hidden page */
+ REG_SEQ0(TAS2764_REG(0xfd, 0x64), 0x4), /* do write (unknown semantics) */
+ REG_SEQ0(TAS2764_REG(0xfd, 0x0d), 0x0), /* switch hidden page back */
+};
+
+static const struct reg_sequence tas2764_post_shutdown_seq[] = {
+ REG_SEQ0(TAS2764_REG(0xfd, 0x0d), 0xd),
+ REG_SEQ0(TAS2764_REG(0xfd, 0x64), 0x0), /* revert write from pre sequence */
+ REG_SEQ0(TAS2764_REG(0xfd, 0x0d), 0x0),
+};
+
+static int tas2764_do_quirky_pwr_ctrl_change(struct tas2764_priv *tas2764,
+ unsigned int target)
+{
+ unsigned int curr;
+ int ret;
+
+ curr = snd_soc_component_read_field(tas2764->component,
+ TAS2764_PWR_CTRL,
+ TAS2764_PWR_CTRL_MASK);
+
+ if (target == curr)
+ return 0;
+
+#define TRANSITION(new, old) ((new) << 8 | (old))
+ switch (TRANSITION(target, curr)) {
+ case TRANSITION(TAS2764_PWR_CTRL_SHUTDOWN, TAS2764_PWR_CTRL_MUTE):
+ case TRANSITION(TAS2764_PWR_CTRL_SHUTDOWN, TAS2764_PWR_CTRL_ACTIVE):
+ ret = regmap_multi_reg_write(tas2764->regmap, tas2764_pre_shutdown_seq,
+ ARRAY_SIZE(tas2764_pre_shutdown_seq));
+ if (ret < 0)
+ break;
+
+ ret = snd_soc_component_update_bits(tas2764->component,
+ TAS2764_PWR_CTRL,
+ TAS2764_PWR_CTRL_MASK,
+ TAS2764_PWR_CTRL_SHUTDOWN);
+ if (ret > 0)
+ break;
+
+ ret = regmap_multi_reg_write(tas2764->regmap, tas2764_post_shutdown_seq,
+ ARRAY_SIZE(tas2764_post_shutdown_seq));
+ fallthrough;
+ default:
+ ret = snd_soc_component_update_bits(tas2764->component, TAS2764_PWR_CTRL,
+ TAS2764_PWR_CTRL_MASK, target);
+ }
+#undef TRANSITION
+
+ if (ret < 0)
+ return ret;
+ return 0;
+}
+
+/*
+ * Via devicetree (TODO):
+ * - switch from spread spectrum to class-D switching
+ * - disable edge control
+ * - set BOP settings (the BOP config bits *and* BOP_SRC)
+ */
+
+/*
+ * Other setup TODOs:
+ * - DVC ramp rate
+ */
+
+static const struct tas2764_quirk_init_sequence {
+ const struct reg_sequence *seq;
+ int len;
+} tas2764_quirk_init_sequences[] = {
+ { tas2764_noise_gate_dis_seq, ARRAY_SIZE(tas2764_noise_gate_dis_seq) },
+ { tas2764_dmod_rst_seq, ARRAY_SIZE(tas2764_dmod_rst_seq) },
+ { tas2764_conv_vbat_pvdd_mode_seq, ARRAY_SIZE(tas2764_conv_vbat_pvdd_mode_seq) },
+ { tas2764_unk_seq0, ARRAY_SIZE(tas2764_unk_seq0) },
+ { tas2764_unk_seq1, ARRAY_SIZE(tas2764_unk_seq1) },
+ { tas2764_unk_seq2, ARRAY_SIZE(tas2764_unk_seq2) },
+ { tas2764_thermal_th1_dis_seq, ARRAY_SIZE(tas2764_thermal_th1_dis_seq) },
+ { tas2764_shutdown_dance_init_seq, ARRAY_SIZE(tas2764_shutdown_dance_init_seq) },
+};
+
+#endif /* __TAS2764_QUIRKS__ */
diff --git a/sound/soc/codecs/tas2764.c b/sound/soc/codecs/tas2764.c
index 811f4f54cc26bee05d717552c360fa50e7d6c7fe..4923291e7a62bd33f0f8a934599c527033feb971 100644
--- a/sound/soc/codecs/tas2764.c
+++ b/sound/soc/codecs/tas2764.c
@@ -46,6 +46,8 @@ struct tas2764_priv {
bool unmuted;
};
+#include "tas2764-quirks.h"
+
static const char *tas2764_int_ltch0_msgs[8] = {
"fault: over temperature", /* INT_LTCH0 & BIT(0) */
"fault: over current",
@@ -123,6 +125,9 @@ static int tas2764_update_pwr_ctrl(struct tas2764_priv *tas2764)
else
val = TAS2764_PWR_CTRL_SHUTDOWN;
+ if (ENABLED_APPLE_QUIRKS & TAS2764_SHUTDOWN_DANCE)
+ return tas2764_do_quirky_pwr_ctrl_change(tas2764, val);
+
ret = snd_soc_component_update_bits(component, TAS2764_PWR_CTRL,
TAS2764_PWR_CTRL_MASK, val);
if (ret < 0)
@@ -542,6 +547,30 @@ static uint8_t sn012776_bop_presets[] = {
static const struct regmap_config tas2764_i2c_regmap;
+static int tas2764_apply_init_quirks(struct tas2764_priv *tas2764)
+{
+ int ret, i;
+
+ for (i = 0; i < ARRAY_SIZE(tas2764_quirk_init_sequences); i++) {
+ const struct tas2764_quirk_init_sequence *init_seq =
+ &tas2764_quirk_init_sequences[i];
+
+ if (!init_seq->seq)
+ continue;
+
+ if (!(BIT(i) & ENABLED_APPLE_QUIRKS))
+ continue;
+
+ ret = regmap_multi_reg_write(tas2764->regmap, init_seq->seq,
+ init_seq->len);
+
+ if (ret < 0)
+ return ret;
+ }
+
+ return 0;
+}
+
static int tas2764_codec_probe(struct snd_soc_component *component)
{
struct tas2764_priv *tas2764 = snd_soc_component_get_drvdata(component);
@@ -627,6 +656,12 @@ static int tas2764_codec_probe(struct snd_soc_component *component)
if (ret < 0)
return ret;
}
+
+ /* Apply all enabled Apple quirks */
+ ret = tas2764_apply_init_quirks(tas2764);
+
+ if (ret < 0)
+ return ret;
}
return 0;
@@ -706,6 +741,9 @@ static bool tas2764_volatile_register(struct device *dev, unsigned int reg)
case TAS2764_INT_LTCH0 ... TAS2764_INT_LTCH4:
case TAS2764_INT_CLK_CFG:
return true;
+ case TAS2764_REG(0xf0, 0x0) ... TAS2764_REG(0xff, 0x0):
+ /* TI's undocumented registers for the application of quirks */
+ return true;
default:
return false;
}
--
2.48.1
next prev parent reply other threads:[~2025-02-15 0:04 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-15 0:02 [PATCH 00/27] ASoC: tas27{64,70}: improve support for Apple codec variants James Calligeros
2025-02-15 0:02 ` [PATCH 01/27] ASoC: dt-bindings: tas27xx: add compatible for SN012776 James Calligeros
2025-02-15 0:02 ` [PATCH 02/27] ASoC: dt-bindings: tas2770: add compatible for TAS5770L James Calligeros
2025-02-15 0:02 ` [PATCH 03/27] ASoC: tas2764: Extend driver to SN012776 James Calligeros
2025-02-16 22:58 ` Alyssa Rosenzweig
2025-02-16 23:54 ` Mark Brown
2025-02-15 0:02 ` [PATCH 04/27] ASoC: tas2764: Add control concerning overcurrent events James Calligeros
2025-02-15 0:16 ` Martin Povišer
2025-02-15 0:02 ` [PATCH 05/27] ASoC: tas2770: Factor out set_ivsense_slots James Calligeros
2025-02-15 0:02 ` [PATCH 06/27] ASoC: tas2770: Fix and redo I/V sense TDM slot setting logic James Calligeros
2025-02-15 0:02 ` [PATCH 07/27] ASoC: tas2764: Reinit cache on part reset James Calligeros
2025-02-15 0:02 ` [PATCH 08/27] ASoC: tas2764: Configure zeroing of SDOUT slots James Calligeros
2025-02-15 0:02 ` James Calligeros [this message]
2025-02-16 23:01 ` [PATCH 09/27] ASoC: tas2764: Apply Apple quirks Alyssa Rosenzweig
2025-02-15 0:02 ` [PATCH 10/27] ASoC: tas2764: Raise regmap range maximum James Calligeros
2025-02-15 0:02 ` [PATCH 11/27] ASoC: tas2770: Export 'die_temp' to sysfs James Calligeros
2025-02-16 23:56 ` Mark Brown
2025-02-15 0:02 ` [PATCH 12/27] ASoC: tas2764: " James Calligeros
2025-02-15 0:02 ` [PATCH 13/27] ASoC: tas2764: Crop SDOUT zero-out mask based on BCLK ratio James Calligeros
2025-02-15 0:02 ` [PATCH 14/27] ASoC: tas2764: Enable main IRQs James Calligeros
2025-02-15 0:02 ` [PATCH 15/27] ASoC: tas2764: Power up/down amp on mute ops James Calligeros
2025-02-15 0:02 ` [PATCH 16/27] ASoC: tas2764: Add SDZ regulator James Calligeros
2025-02-15 0:02 ` [PATCH 17/27] ASoC: tas2764: Add reg defaults for TAS2764_INT_CLK_CFG James Calligeros
2025-02-15 0:02 ` [PATCH 18/27] ASoC: tas2764: Mark SW_RESET as volatile James Calligeros
2025-02-15 0:02 ` [PATCH 19/27] ASoC: tas2764: Fix power control mask James Calligeros
2025-02-16 23:58 ` Mark Brown
2025-02-15 0:02 ` [PATCH 20/27] ASoC: tas2764: Wait for ramp-down after shutdown James Calligeros
2025-02-15 0:02 ` [PATCH 21/27] ASoC: tas2770: Add SDZ regulator James Calligeros
2025-02-15 0:02 ` [PATCH 22/27] ASoC: tas2770: Power cycle amp on ISENSE/VSENSE change James Calligeros
2025-02-15 0:02 ` [PATCH 23/27] ASoC: tas2770: Add zero-fill and pull-down controls James Calligeros
2025-02-15 0:02 ` [PATCH 24/27] ASoC: tas2770: Support setting the PDM TX slot James Calligeros
2025-02-15 0:02 ` [PATCH 25/27] ASoC: tas2770: Fix volume scale James Calligeros
2025-02-17 0:00 ` Mark Brown
2025-02-15 0:02 ` [PATCH 26/27] ASoC: tas2764: Set the SDOUT polarity correctly James Calligeros
2025-02-15 0:03 ` [PATCH 27/27] ASoC: tas2770: " James Calligeros
2025-02-15 0:39 ` [PATCH 00/27] ASoC: tas27{64,70}: improve support for Apple codec variants Neal Gompa
2025-02-16 23:03 ` Alyssa Rosenzweig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250215-apple-codec-changes-v1-9-723569b21b19@gmail.com \
--to=jcalligeros99@gmail.com \
--cc=alyssa@rosenzweig.io \
--cc=asahi@lists.linux.dev \
--cc=baojun.xu@ti.com \
--cc=broonie@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dmurphy@ti.com \
--cc=kevin-lu@ti.com \
--cc=krzk+dt@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=marcan@marcan.st \
--cc=perex@perex.cz \
--cc=povik+lin@cutebit.org \
--cc=robh@kernel.org \
--cc=shenghao-ding@ti.com \
--cc=shifu0704@thundersoft.com \
--cc=tiwai@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).