From 1112743ef90f89846f5a24b81ba5fe6ebd6512a1 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Sat, 28 Nov 2026 00:24:13 +1100 Subject: [PATCH 1/3] ASoC: dt-bindings: describe the TAS5770L speaker config row Document the optional row copied by the Apple bootloader for each TAS5770L speaker amplifier. The row describes the analog operating gain and names the source format's slot fields. Signed-off-by: Ryan Murray --- .../devicetree/bindings/sound/ti,tas2770.yaml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Documentation/devicetree/bindings/sound/ti,tas2770.yaml b/Documentation/devicetree/bindings/sound/ti,tas2770.yaml index 48639192c075b..a5ed3dfdb2b34 100644 --- a/Documentation/devicetree/bindings/sound/ti,tas2770.yaml +++ b/Documentation/devicetree/bindings/sound/ti,tas2770.yaml @@ -18,6 +18,15 @@ description: | allOf: - $ref: dai-common.yaml# + - if: + properties: + compatible: + not: + contains: + const: ti,tas5770l + then: + properties: + apple,speaker-config: false properties: compatible: @@ -45,6 +54,16 @@ properties: interrupts: maxItems: 1 + apple,speaker-config: + $ref: /schemas/types.yaml#/definitions/uint8-array + minItems: 4 + maxItems: 4 + description: + This amplifier's speaker-config row from Apple's device tree, copied + by the bootloader. The second byte specifies the analog operating + gain. The other bytes are RX and sense slot selections in the source + format. Linux uses its own DAI and sense-slot properties for routing. + ti,imon-slot-no: $ref: /schemas/types.yaml#/definitions/uint32 description: TDM TX current sense time slot. From 37cf59636c5149c769404c647cbe3c8fa0b7ed47 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Sat, 28 Nov 2026 00:24:15 +1100 Subject: [PATCH 2/3] ASoC: apple: use the TAS5770L operating gain from DT The bootloader can hand the machine's speaker-config row to each amp. Read that row before adding the speaker backend and apply the decoded gain to its mixer control through the existing per-amp volume limiter. Skip the TAS speaker backend if any row is absent or unusable. Share the codec register range with the driver. Reject zero because the ASoC volume platform limit uses zero to indicate no limit. Keep the SN012776 fixed-ceiling check and Linux's TAS sense layout. Signed-off-by: Ryan Murray --- sound/soc/apple/macaudio-amp-level-test.h | 58 +++++---- sound/soc/apple/macaudio-kunit.dtso | 47 +++++++ sound/soc/apple/macaudio.c | 147 +++++++++++++--------- sound/soc/codecs/tas2770.c | 2 +- sound/soc/codecs/tas2770.h | 1 + 5 files changed, 175 insertions(+), 80 deletions(-) diff --git a/sound/soc/apple/macaudio-amp-level-test.h b/sound/soc/apple/macaudio-amp-level-test.h index b97939e10c672..68bb752e47012 100644 --- a/sound/soc/apple/macaudio-amp-level-test.h +++ b/sound/soc/apple/macaudio-amp-level-test.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-only */ /* - * KUnit tests of the SN012776 amp levels: each amp's level is the second byte + * KUnit tests of the SN012776 and TAS5770L amp levels: each amp's level is the second byte * of its apple,speaker-config, which the boot loader copies from the Mac's * ADT, and the speakers stay off when any amp lacks it, or under a fixed * ceiling when any amp has another level than the ceiling was computed for. @@ -22,7 +22,7 @@ static bool macaudio_level_test_present(struct kunit *test, struct device *dev, const struct macaudio_platform_cfg *cfg, const char *name) { - return macaudio_sn012776_levels_present(dev, cfg, macaudio_level_test_node(test, name)); + return macaudio_amp_level_count(dev, cfg, macaudio_level_test_node(test, name)) > 0; } /* The level is the row's second byte, its low five bits */ @@ -83,27 +83,41 @@ static void macaudio_levels_fixed_ceiling(struct kunit *test) "macaudio-kunit-codec-good")); KUNIT_EXPECT_FALSE(test, macaudio_level_test_present(test, dev, cfg, "macaudio-kunit-codec-one-missing")); - KUNIT_EXPECT_FALSE(test, macaudio_sn012776_level_allowed(cfg, 14)); - KUNIT_EXPECT_FALSE(test, macaudio_sn012776_level_allowed(cfg, 16)); + KUNIT_EXPECT_FALSE(test, macaudio_amp_level_allowed(cfg, 14)); + KUNIT_EXPECT_FALSE(test, macaudio_amp_level_allowed(cfg, 16)); } -/* No board table carries an SN012776 gain any more */ -static void macaudio_level_no_table(struct kunit *test) +static void macaudio_tas_level_from_row(struct kunit *test) { - const struct macaudio_platform_cfg *cfgs[] = { - &macaudio_j180_cfg, &macaudio_j314_cfg, &macaudio_j316_cfg, - &macaudio_j37x_j47x_cfg, &macaudio_j413_cfg, &macaudio_j415_cfg, - &macaudio_j493_cfg, &macaudio_j575c_j773_cfg, &macaudio_j604_cfg, - &macaudio_j614_cfg, &macaudio_j616_cfg, &macaudio_j713_cfg, - &macaudio_j714_cfg, &macaudio_j715_cfg, &macaudio_j813_cfg, - &macaudio_j775_cfg, &macaudio_j873_cfg, &macaudio_k114_cfg, - }; - unsigned int i; - - for (i = 0; i < ARRAY_SIZE(cfgs); i++) { - KUNIT_EXPECT_EQ(test, cfgs[i]->amp, AMP_SN012776); - KUNIT_EXPECT_EQ(test, cfgs[i]->amp_gain, 0); - } + KUNIT_EXPECT_EQ(test, macaudio_tas5770_level( + macaudio_level_test_node(test, "macaudio-kunit-tas-a")), 4); + KUNIT_EXPECT_EQ(test, macaudio_tas5770_level( + macaudio_level_test_node(test, "macaudio-kunit-tas-b")), 14); +} + +static void macaudio_tas_level_rejects(struct kunit *test) +{ + KUNIT_EXPECT_EQ(test, macaudio_tas5770_level( + macaudio_level_test_node(test, "macaudio-kunit-tas-zero")), -ERANGE); + KUNIT_EXPECT_EQ(test, macaudio_tas5770_level( + macaudio_level_test_node(test, "macaudio-kunit-tas-high")), -ERANGE); + KUNIT_EXPECT_EQ(test, macaudio_tas5770_level( + macaudio_level_test_node(test, "macaudio-kunit-tas-short")), -ENOENT); + KUNIT_EXPECT_EQ(test, macaudio_tas5770_level( + macaudio_level_test_node(test, "macaudio-kunit-tas-none")), -ENOENT); +} + +static void macaudio_tas_levels_every_amp(struct kunit *test) +{ + struct device *dev = kunit_kzalloc(test, sizeof(*dev), GFP_KERNEL); + + KUNIT_ASSERT_NOT_NULL(test, dev); + KUNIT_EXPECT_TRUE(test, macaudio_level_test_present(test, dev, &macaudio_j313_cfg, + "macaudio-kunit-tas-codec-good")); + KUNIT_EXPECT_FALSE(test, macaudio_level_test_present(test, dev, &macaudio_j313_cfg, + "macaudio-kunit-tas-codec-missing")); + KUNIT_EXPECT_FALSE(test, macaudio_level_test_present(test, dev, &macaudio_j313_cfg, + "macaudio-kunit-tas-codec-wrong")); } static int macaudio_level_test_init(struct kunit *test) @@ -116,7 +130,9 @@ static struct kunit_case macaudio_level_cases[] = { KUNIT_CASE(macaudio_level_rejects), KUNIT_CASE(macaudio_levels_every_amp), KUNIT_CASE(macaudio_levels_fixed_ceiling), - KUNIT_CASE(macaudio_level_no_table), + KUNIT_CASE(macaudio_tas_level_from_row), + KUNIT_CASE(macaudio_tas_level_rejects), + KUNIT_CASE(macaudio_tas_levels_every_amp), {} }; diff --git a/sound/soc/apple/macaudio-kunit.dtso b/sound/soc/apple/macaudio-kunit.dtso index 724cf4fb965d2..57db4a3f867ba 100644 --- a/sound/soc/apple/macaudio-kunit.dtso +++ b/sound/soc/apple/macaudio-kunit.dtso @@ -51,4 +51,51 @@ macaudio-kunit-codec-level-15 { sound-dai = <&ma_amp_a>; }; + + ma_tas_a: macaudio-kunit-tas-a { + compatible = "ti,tas5770l", "ti,tas2770"; + #sound-dai-cells = <0>; + apple,speaker-config = [00 04 00 00]; + }; + + ma_tas_b: macaudio-kunit-tas-b { + compatible = "ti,tas5770l", "ti,tas2770"; + #sound-dai-cells = <0>; + apple,speaker-config = [01 0e 00 00]; + }; + + ma_tas_zero: macaudio-kunit-tas-zero { + compatible = "ti,tas5770l", "ti,tas2770"; + #sound-dai-cells = <0>; + apple,speaker-config = [00 00 00 00]; + }; + + ma_tas_high: macaudio-kunit-tas-high { + compatible = "ti,tas5770l", "ti,tas2770"; + #sound-dai-cells = <0>; + apple,speaker-config = [00 1f 00 00]; + }; + + ma_tas_short: macaudio-kunit-tas-short { + compatible = "ti,tas5770l", "ti,tas2770"; + #sound-dai-cells = <0>; + apple,speaker-config = [00 04 00]; + }; + + ma_tas_none: macaudio-kunit-tas-none { + compatible = "ti,tas5770l", "ti,tas2770"; + #sound-dai-cells = <0>; + }; + + macaudio-kunit-tas-codec-good { + sound-dai = <&ma_tas_a>, <&ma_tas_b>; + }; + + macaudio-kunit-tas-codec-missing { + sound-dai = <&ma_tas_a>, <&ma_tas_none>; + }; + + macaudio-kunit-tas-codec-wrong { + sound-dai = <&ma_tas_a>, <&ma_amp_a>; + }; }; diff --git a/sound/soc/apple/macaudio.c b/sound/soc/apple/macaudio.c index b641b455dd7f4..92838bd19b0b1 100644 --- a/sound/soc/apple/macaudio.c +++ b/sound/soc/apple/macaudio.c @@ -44,6 +44,8 @@ #include #include +#include "../codecs/tas2770.h" + #define DRIVER_NAME "snd-soc-macaudio" /* @@ -122,8 +124,6 @@ struct macaudio_platform_cfg { enum macaudio_amp_type amp; enum macaudio_spkr_config speakers; bool stereo; - /* The amps' highest gain ("Amp Gain Volume"); not for the SN012776 */ - int amp_gain; int safe_vol; /* * The speaker codec's output widget, "OUT" (the TAS and SSM @@ -262,6 +262,7 @@ struct macaudio_snd_data { bool has_speakers; bool has_sense; bool has_safety; + int tas_amp_count; unsigned int max_channels; struct gpio_descs *speaker_id_gpios; @@ -2409,46 +2410,68 @@ static bool macaudio_speakers_allowed(const struct macaudio_platform_cfg *cfg) } /* - * An SN012776's operating level: the second byte of its apple,speaker-config, - * the amp's row of its group's speaker-config in the Mac's ADT, which the - * boot loader copies to the amp's node. Only its low five bits are the level. + * The loader exports each amp's four-byte row of the Mac's ADT + * speaker-config. The row's second byte carries the operating gain. */ -#define SN012776_ROW_LEN 4 -#define SN012776_ROW_LEVEL 1 +#define MACAUDIO_AMP_ROW_LEN 4 +#define MACAUDIO_AMP_ROW_LEVEL 1 #define SN012776_LEVEL_MASK 0x1f /* The highest level the amp's "Amp Gain Volume" takes */ #define SN012776_LEVEL_MAX 0x14 -static int macaudio_sn012776_level(struct device_node *amp) +static int macaudio_amp_level_byte(struct device_node *amp) { - u8 row[SN012776_ROW_LEN]; - int level; + u8 row[MACAUDIO_AMP_ROW_LEN]; - if (of_property_count_u8_elems(amp, "apple,speaker-config") != SN012776_ROW_LEN || - of_property_read_u8_array(amp, "apple,speaker-config", row, SN012776_ROW_LEN)) + if (of_property_count_u8_elems(amp, "apple,speaker-config") != MACAUDIO_AMP_ROW_LEN || + of_property_read_u8_array(amp, "apple,speaker-config", row, sizeof(row))) return -ENOENT; - level = row[SN012776_ROW_LEVEL] & SN012776_LEVEL_MASK; + return row[MACAUDIO_AMP_ROW_LEVEL]; +} + +static int macaudio_sn012776_level(struct device_node *amp) +{ + int level = macaudio_amp_level_byte(amp); + + if (level < 0) + return level; + + level &= SN012776_LEVEL_MASK; return level <= SN012776_LEVEL_MAX ? level : -ERANGE; } +static int macaudio_tas5770_level(struct device_node *amp) +{ + int level; + + if (!of_device_is_compatible(amp, "ti,tas5770l")) + return -EINVAL; + + level = macaudio_amp_level_byte(amp); + if (level < 0) + return level; + + /* ASoC uses a zero platform maximum to mean no limit. */ + return level > 0 && level <= TAS2770_AMP_GAIN_MAX ? level : -ERANGE; +} + /* * A fixed ceiling holds only at the amp level it was computed for. */ -static bool macaudio_sn012776_level_allowed(const struct macaudio_platform_cfg *cfg, - int level) +static bool macaudio_amp_level_allowed(const struct macaudio_platform_cfg *cfg, int level) { return level >= 0 && (!cfg->spk_fixed_ceiling || level == cfg->spk_ceiling_level); } /* - * Speakers on SN012776 amps run only when every amp has its level from the - * Mac, and under a fixed ceiling only at the level that ceiling was computed - * for; otherwise they stay off. + * Speakers on SN012776 or TAS5770L amps run only when every amp has its + * level from the Mac. A fixed ceiling also requires the level it was + * computed for. */ -static bool macaudio_sn012776_levels_present(struct device *dev, - const struct macaudio_platform_cfg *cfg, - struct device_node *codec) +static int macaudio_amp_level_count(struct device *dev, + const struct macaudio_platform_cfg *cfg, + struct device_node *codec) { struct of_phandle_args args; int i, n, level; @@ -2457,39 +2480,43 @@ static bool macaudio_sn012776_levels_present(struct device *dev, for (i = 0; i < n; i++) { if (of_parse_phandle_with_args(codec, "sound-dai", "#sound-dai-cells", i, &args)) - return false; - level = macaudio_sn012776_level(args.np); + return 0; + level = cfg->amp == AMP_TAS5770 ? macaudio_tas5770_level(args.np) : + macaudio_sn012776_level(args.np); if (level < 0) dev_err(dev, "%pOF: %s amp level from the boot loader\n", args.np, - level == -ENOENT ? "no" : "out-of-range"); - else if (!macaudio_sn012776_level_allowed(cfg, level)) + level == -ENOENT ? "no" : "invalid"); + else if (!macaudio_amp_level_allowed(cfg, level)) dev_err(dev, "%pOF: amp level %d, the fixed ceiling holds only at %d\n", args.np, level, cfg->spk_ceiling_level); else if (cfg->spk_fixed_ceiling) dev_info(dev, "%pOF: amp level %d from the boot loader\n", args.np, level); of_node_put(args.np); - if (!macaudio_sn012776_level_allowed(cfg, level)) - return false; + if (!macaudio_amp_level_allowed(cfg, level)) + return 0; } - return n > 0; + return n > 0 ? n : 0; } /* - * Every SN012776's "Amp Gain Volume" ends at its own level; the lease fixes - * it there (macaudio_spk_fix_amp_gains()). + * Each amp's "Amp Gain Volume" ends at its own level from the ADT. The + * lease fixes it there (macaudio_spk_fix_amp_gains()). */ -static int macaudio_limit_sn012776_levels(struct snd_soc_card *card) +static int macaudio_limit_amp_levels(struct snd_soc_card *card) { + struct macaudio_snd_data *ma = snd_soc_card_get_drvdata(card); struct snd_soc_component *component; char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; - int level, ret; + bool tas = ma->cfg->amp == AMP_TAS5770; + const char *compatible = tas ? "ti,tas5770l" : "ti,sn012776"; + int count = 0, level, ret; for_each_card_components(card, component) { struct device_node *np = component->dev->of_node; - if (!np || !of_device_is_compatible(np, "ti,sn012776")) + if (!np || !of_device_is_compatible(np, compatible)) continue; - level = macaudio_sn012776_level(np); + level = tas ? macaudio_tas5770_level(np) : macaudio_sn012776_level(np); if (level < 0) return dev_err_probe(card->dev, level, "%pOF: no amp level\n", np); snprintf(name, sizeof(name), "%s%sAmp Gain Volume", @@ -2499,7 +2526,12 @@ static int macaudio_limit_sn012776_levels(struct snd_soc_card *card) if (ret != 1) return dev_err_probe(card->dev, ret < 0 ? ret : -EINVAL, "limit on '%s': %d\n", name, ret); + count++; } + if (tas && count != ma->tas_amp_count) + return dev_err_probe(card->dev, -EINVAL, + "restricted %d of %d TAS amp gains\n", + count, ma->tas_amp_count); return 0; } @@ -2705,17 +2737,18 @@ static int macaudio_parse_of(struct macaudio_snd_data *ma) dev_err(card->dev, "driver can't assure safety on this model, disabling speakers\n"); continue; } - if (ma->cfg->amp == AMP_SN012776) { + if (ma->cfg->amp == AMP_SN012776 || ma->cfg->amp == AMP_TAS5770) { struct device_node *spk_codec = of_get_child_by_name(np, "codec"); - bool levels = spk_codec && - macaudio_sn012776_levels_present(card->dev, ma->cfg, - spk_codec); + int levels = spk_codec ? + macaudio_amp_level_count(card->dev, ma->cfg, spk_codec) : 0; of_node_put(spk_codec); if (!levels) { dev_err(card->dev, "no usable amp levels from the boot loader, disabling speakers\n"); continue; } + if (ma->cfg->amp == AMP_TAS5770) + ma->tas_amp_count = levels; } ma->has_speakers = 1; if (ma->cfg->amp != AMP_SSM3515 && ma->cfg->safe_vol != 0 && @@ -3684,8 +3717,6 @@ static int macaudio_set_speaker(struct snd_soc_card *card, const char *prefix, b case AMP_TAS5770: if (ma->cfg->stereo) CHECK_CONCAT(macaudio_set_fixed_enum, "ASI1 Sel", "Left"); - - CHECK_CONCAT(snd_soc_limit_volume, "Amp Gain Volume", ma->cfg->amp_gain); break; case AMP_SN012776: if (ma->cfg->stereo) @@ -3693,7 +3724,7 @@ static int macaudio_set_speaker(struct snd_soc_card *card, const char *prefix, b /* * Each amp's gain ends at its level from the Mac's ADT - * (macaudio_limit_sn012776_levels()). The tweeters' playback + * (macaudio_limit_amp_levels()). The tweeters' playback * high-pass starts at the protection floor; the woofers keep * the corner the amps were given from the ADT. */ @@ -3748,8 +3779,8 @@ static int macaudio_fixup_controls(struct snd_soc_card *card) macaudio_protect_sense(card); - if (ma->cfg->amp == AMP_SN012776) { - int ret = macaudio_limit_sn012776_levels(card); + if (ma->cfg->amp == AMP_SN012776 || ma->cfg->amp == AMP_TAS5770) { + int ret = macaudio_limit_amp_levels(card); if (ret) return ret; @@ -4043,24 +4074,24 @@ static const struct snd_soc_dapm_route macaudio_dapm_routes[] = { }; /* - * enable amp speakers stereo gain safe_vol + * enable amp speakers stereo safe_vol * - * An SN012776's gain is not here: each amp's operating level comes from the - * Mac's ADT, through the amp's apple,speaker-config. + * Each SN012776 or TAS5770L operating gain comes from the Mac's ADT, + * through the amp's apple,speaker-config. */ struct macaudio_platform_cfg macaudio_j180_cfg = { - false, AMP_SN012776, SPKR_1W1T, false, 0, -20, + false, AMP_SN012776, SPKR_1W1T, false, -20, }; struct macaudio_platform_cfg macaudio_j274_cfg = { - true, AMP_TAS5770, SPKR_1W, false, 20, -20, + true, AMP_TAS5770, SPKR_1W, false, -20, }; struct macaudio_platform_cfg macaudio_j293_cfg = { - true, AMP_TAS5770, SPKR_2W, true, 15, -20, + true, AMP_TAS5770, SPKR_2W, true, -20, }; struct macaudio_platform_cfg macaudio_j313_cfg = { - true, AMP_TAS5770, SPKR_1W, true, 10, -20, + true, AMP_TAS5770, SPKR_1W, true, -20, }; /* @@ -4256,35 +4287,35 @@ struct macaudio_platform_cfg macaudio_j815_cfg = { }; struct macaudio_platform_cfg macaudio_j314_cfg = { - true, AMP_SN012776, SPKR_2W1T, true, 0, -20, + true, AMP_SN012776, SPKR_2W1T, true, -20, }; /* Granted, the tweeters restore their DT corner (see tweeter_hpf_granted) */ struct macaudio_platform_cfg macaudio_j316_cfg = { - true, AMP_SN012776, SPKR_2W1T, true, 0, -20, + true, AMP_SN012776, SPKR_2W1T, true, -20, .tweeter_hpf_granted = true, }; struct macaudio_platform_cfg macaudio_j37x_j47x_cfg = { - true, AMP_SN012776, SPKR_1W, false, 0, -20, + true, AMP_SN012776, SPKR_1W, false, -20, }; /* Granted, the tweeters restore their DT corner (see tweeter_hpf_granted) */ struct macaudio_platform_cfg macaudio_j413_cfg = { - true, AMP_SN012776, SPKR_1W1T, true, 0, -20, + true, AMP_SN012776, SPKR_1W1T, true, -20, .tweeter_hpf_granted = true, }; struct macaudio_platform_cfg macaudio_j415_cfg = { - true, AMP_SN012776, SPKR_2W1T, true, 0, -20, + true, AMP_SN012776, SPKR_2W1T, true, -20, }; struct macaudio_platform_cfg macaudio_j45x_cfg = { - false, AMP_SSM3515, SPKR_1W1T, true, 9, -20, /* TODO: gain?? */ + false, AMP_SSM3515, SPKR_1W1T, true, -20, }; struct macaudio_platform_cfg macaudio_j493_cfg = { - true, AMP_SN012776, SPKR_2W, true, 0, -20, + true, AMP_SN012776, SPKR_2W, true, -20, }; /* @@ -4460,7 +4491,7 @@ struct macaudio_platform_cfg macaudio_j616_jack_cfg = { }; struct macaudio_platform_cfg macaudio_fallback_cfg = { - false, AMP_NONE, SPKR_NONE, false, 0, 0, + false, AMP_NONE, SPKR_NONE, false, 0, }; /* diff --git a/sound/soc/codecs/tas2770.c b/sound/soc/codecs/tas2770.c index f0dbc2947ecda..6e3bbf0a6d34a 100644 --- a/sound/soc/codecs/tas2770.c +++ b/sound/soc/codecs/tas2770.c @@ -771,7 +771,7 @@ static DECLARE_TLV_DB_SCALE(tas2770_playback_volume, -10050, 50, 0); static const struct snd_kcontrol_new tas2770_snd_controls[] = { SOC_SINGLE_TLV("Speaker Playback Volume", TAS2770_PLAY_CFG_REG2, 0, TAS2770_PLAY_CFG_REG2_VMAX, 1, tas2770_playback_volume), - SOC_SINGLE_TLV("Amp Gain Volume", TAS2770_PLAY_CFG_REG0, 0, 0x14, 0, + SOC_SINGLE_TLV("Amp Gain Volume", TAS2770_PLAY_CFG_REG0, 0, TAS2770_AMP_GAIN_MAX, 0, tas2770_digital_tlv), }; diff --git a/sound/soc/codecs/tas2770.h b/sound/soc/codecs/tas2770.h index f88c5396081be..023fd0e67ad98 100644 --- a/sound/soc/codecs/tas2770.h +++ b/sound/soc/codecs/tas2770.h @@ -25,6 +25,7 @@ #define TAS2770_PWR_CTRL_SHUTDOWN 0x2 /* Playback Configuration Reg0 */ #define TAS2770_PLAY_CFG_REG0 TAS2770_REG(0X0, 0x03) +#define TAS2770_AMP_GAIN_MAX 0x14 /* Playback Configuration Reg1 */ #define TAS2770_PLAY_CFG_REG1 TAS2770_REG(0X0, 0x04) /* Playback Configuration Reg2 */ From 4a7293961eb2f6b5435ab5b54d390771c91d1ac8 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Thu, 3 Dec 2026 07:11:24 -0500 Subject: [PATCH 3/3] ASoC: tas2770: give each amplifier its own gain limit Signed-off-by: DjDeveloperr --- sound/soc/codecs/tas2770.c | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/sound/soc/codecs/tas2770.c b/sound/soc/codecs/tas2770.c index 170bb91c64f1c..f6c4e9a07ac7e 100644 --- a/sound/soc/codecs/tas2770.c +++ b/sound/soc/codecs/tas2770.c @@ -784,11 +784,14 @@ static void tas2770_codec_remove(struct snd_soc_component *component) static DECLARE_TLV_DB_SCALE(tas2770_digital_tlv, 1100, 50, 0); static DECLARE_TLV_DB_SCALE(tas2770_playback_volume, -10050, 50, 0); +enum { TAS2770_AMP_GAIN_CONTROL = 1 }; + static const struct snd_kcontrol_new tas2770_snd_controls[] = { SOC_SINGLE_TLV("Speaker Playback Volume", TAS2770_PLAY_CFG_REG2, 0, TAS2770_PLAY_CFG_REG2_VMAX, 1, tas2770_playback_volume), - SOC_SINGLE_TLV("Amp Gain Volume", TAS2770_PLAY_CFG_REG0, 0, TAS2770_AMP_GAIN_MAX, 0, - tas2770_digital_tlv), + [TAS2770_AMP_GAIN_CONTROL] = SOC_SINGLE_TLV("Amp Gain Volume", TAS2770_PLAY_CFG_REG0, + 0, TAS2770_AMP_GAIN_MAX, 0, + tas2770_digital_tlv), }; static const struct snd_soc_component_driver soc_component_driver_tas2770 = { @@ -808,9 +811,28 @@ static const struct snd_soc_component_driver soc_component_driver_tas2770 = { static int tas2770_register_codec(struct tas2770_priv *tas2770) { - return devm_snd_soc_register_component(tas2770->dev, - &soc_component_driver_tas2770, - tas2770_dai_driver, ARRAY_SIZE(tas2770_dai_driver)); + struct { + struct snd_soc_component_driver driver; + struct snd_kcontrol_new controls[ARRAY_SIZE(tas2770_snd_controls)]; + struct soc_mixer_control amp_gain; + } *instance; + struct snd_kcontrol_new *gain; + + instance = devm_kmalloc(tas2770->dev, sizeof(*instance), GFP_KERNEL); + if (!instance) + return -ENOMEM; + + instance->driver = soc_component_driver_tas2770; + memcpy(instance->controls, tas2770_snd_controls, sizeof(instance->controls)); + gain = &instance->controls[TAS2770_AMP_GAIN_CONTROL]; + + /* ASoC writes platform_max through private_value when limiting gain. */ + instance->amp_gain = *(const struct soc_mixer_control *)gain->private_value; + gain->private_value = (unsigned long)&instance->amp_gain; + instance->driver.controls = instance->controls; + + return devm_snd_soc_register_component(tas2770->dev, &instance->driver, + tas2770_dai_driver, ARRAY_SIZE(tas2770_dai_driver)); } static const struct reg_default tas2770_reg_defaults[] = {