From d64ac3782ae91b3f3e2b737526b994cc63aa3b00 Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Tue, 24 Nov 2026 01:27:27 -0500 Subject: [PATCH 1/7] ASoC: apple: macaudio: add v2-only speaker ownership and the J716 (16-inch M5 Max) Add a v2-only speaker ownership capability (spk_v2_only) to macaudio and wire the J716 (16-inch M5 Pro/Max) compatible ("apple,j716-macaudio") to it: - Expose only "Speaker Protection" (v2 lease) and "Speaker Sample Rate"; omit the legacy "Speaker Volume Unlock" and "Speaker Protection Interface" controls. Bind directly in MACAUDIO_SPK_IFACE_LEASE at hardware mute (0) with each amp's gain fixed at its boot-loader limit in macaudio_fixup_controls(), refuse PCM start without an active lease, reject legacy unlock/interface transitions with -EOPNOTSUPP, and never revert to unlock mode after owner loss. - Reset per-bind speaker protection state and control arrays on card removal and rebind so ASoC component rebind does not reuse stale counts or skip the cold-bind mute floor. - Do not require a dummy safe_vol on v2-only digital-gain amps whose ungranted floor is hardware mute (0), and require per-amp apple,amp-dcblocker-config (>= 2 bytes) from the boot loader alongside apple,speaker-config before admitting speakers (leaving the headphone jack available if speaker admission fails). - Derive the tweeter safe high-pass corner from the codec's advertised "HPF Corner Frequency" enum items (highest " Hz" corner) instead of hardcoding a frequency literal. - Extend the apple-speaker KUnit suites to cover v2-only admission, DC-blocker admission checks, permanent lease-only ownership, component rebind mute floor, and codec-derived safe HPF selection. Signed-off-by: Erik Bourget --- .../bindings/sound/apple,macaudio.yaml | 1 + sound/soc/apple/macaudio-admission-test.h | 20 +- sound/soc/apple/macaudio-amp-level-test.h | 22 +- sound/soc/apple/macaudio-hpf-test.h | 32 ++ sound/soc/apple/macaudio-iface-test.h | 110 ++++++ sound/soc/apple/macaudio-kunit.dtso | 26 ++ sound/soc/apple/macaudio-protection-test.h | 1 + sound/soc/apple/macaudio.c | 330 ++++++++++++++---- 8 files changed, 479 insertions(+), 63 deletions(-) diff --git a/Documentation/devicetree/bindings/sound/apple,macaudio.yaml b/Documentation/devicetree/bindings/sound/apple,macaudio.yaml index c9880a39e9b29..d0124bb2d6b2f 100644 --- a/Documentation/devicetree/bindings/sound/apple,macaudio.yaml +++ b/Documentation/devicetree/bindings/sound/apple,macaudio.yaml @@ -51,6 +51,7 @@ properties: - apple,j714-macaudio - apple,j715-macaudio - apple,j715-macaudio-jack + - apple,j716-macaudio - apple,j773-macaudio - apple,j773-macaudio-jack - apple,j813-macaudio diff --git a/sound/soc/apple/macaudio-admission-test.h b/sound/soc/apple/macaudio-admission-test.h index 17c7f19c9cd98..c6556c4500b3d 100644 --- a/sound/soc/apple/macaudio-admission-test.h +++ b/sound/soc/apple/macaudio-admission-test.h @@ -11,8 +11,10 @@ static void macaudio_admission_needs_a_safe_level(struct kunit *test) KUNIT_EXPECT_FALSE(test, macaudio_speakers_allowed(&macaudio_j45x_cfg)); KUNIT_EXPECT_TRUE(test, macaudio_speakers_allowed(&macaudio_j413_cfg)); KUNIT_EXPECT_TRUE(test, macaudio_speakers_allowed(&macaudio_j700_cfg)); - /* The AOP-fed machines: J714 and J813 with their safe level, J873 without one */ + /* The AOP-fed machines: J714, J716 (v2-only) and J813 admitted, J873 without protection */ KUNIT_EXPECT_TRUE(test, macaudio_speakers_allowed(&macaudio_j714_cfg)); + KUNIT_EXPECT_TRUE(test, macaudio_speakers_allowed(&macaudio_j716_cfg)); + KUNIT_EXPECT_EQ(test, macaudio_j716_cfg.safe_vol, 0); KUNIT_EXPECT_TRUE(test, macaudio_speakers_allowed(&macaudio_j813_cfg)); KUNIT_EXPECT_FALSE(test, macaudio_speakers_allowed(&macaudio_j873_cfg)); /* The Mac Studio M5: no sense and no protection owner yet, speaker off */ @@ -20,6 +22,14 @@ static void macaudio_admission_needs_a_safe_level(struct kunit *test) cfg = macaudio_j413_cfg; cfg.safe_vol = 0; KUNIT_EXPECT_FALSE(test, macaudio_speakers_allowed(&cfg)); + /* v2-only without safe_vol requires a digital mute-floor amp without fixed ceiling */ + cfg = macaudio_j700_cfg; + cfg.safe_vol = 0; + cfg.spk_v2_only = true; + KUNIT_EXPECT_FALSE(test, macaudio_speakers_allowed(&cfg)); + cfg = macaudio_j716_cfg; + cfg.spk_fixed_ceiling = true; + KUNIT_EXPECT_FALSE(test, macaudio_speakers_allowed(&cfg)); cfg = macaudio_j413_cfg; cfg.speakers = SPKR_NONE; KUNIT_EXPECT_FALSE(test, macaudio_speakers_allowed(&cfg)); @@ -49,6 +59,14 @@ static void macaudio_admission_fixed_ceiling_is_lease_only(struct kunit *test) KUNIT_EXPECT_EQ(test, macaudio_sn012776_vlimit(&cfg, true, false), 1); KUNIT_EXPECT_EQ(test, macaudio_sn012776_vlimit(&cfg, false, true), 1); KUNIT_EXPECT_EQ(test, macaudio_sn012776_vlimit(&cfg, true, true), SN012776_DB(-16)); + + /* v2-only with sense: only a lease lifts the amps, to 0 dB */ + KUNIT_EXPECT_TRUE(test, macaudio_spk_lease_only(&macaudio_j716_cfg)); + KUNIT_EXPECT_EQ(test, macaudio_sn012776_vlimit(&macaudio_j716_cfg, false, false), 1); + KUNIT_EXPECT_EQ(test, macaudio_sn012776_vlimit(&macaudio_j716_cfg, true, false), 1); + KUNIT_EXPECT_EQ(test, macaudio_sn012776_vlimit(&macaudio_j716_cfg, false, true), 1); + KUNIT_EXPECT_EQ(test, macaudio_sn012776_vlimit(&macaudio_j716_cfg, true, true), + SN012776_0DB); } static struct kunit_case macaudio_admission_cases[] = { diff --git a/sound/soc/apple/macaudio-amp-level-test.h b/sound/soc/apple/macaudio-amp-level-test.h index a684c616b4a62..7a6511c7c15ee 100644 --- a/sound/soc/apple/macaudio-amp-level-test.h +++ b/sound/soc/apple/macaudio-amp-level-test.h @@ -87,6 +87,23 @@ static void macaudio_levels_fixed_ceiling(struct kunit *test) KUNIT_EXPECT_FALSE(test, macaudio_sn012776_level_allowed(cfg, 16)); } +/* A v2-only SN012776 machine also requires DC-blocker config from the boot loader */ +static void macaudio_levels_v2_only_requires_dcblocker(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_j716_cfg, + "macaudio-kunit-codec-v2-good")); + KUNIT_EXPECT_FALSE(test, macaudio_level_test_present(test, dev, &macaudio_j716_cfg, + "macaudio-kunit-codec-v2-no-dcblk")); + KUNIT_EXPECT_FALSE(test, macaudio_level_test_present(test, dev, &macaudio_j716_cfg, + "macaudio-kunit-codec-v2-short-dcblk")); + /* Non-v2-only boards keep compatibility with older boot loaders */ + KUNIT_EXPECT_TRUE(test, macaudio_level_test_present(test, dev, &macaudio_j316_cfg, + "macaudio-kunit-codec-v2-no-dcblk")); +} + /* No board table carries an SN012776 gain any more */ static void macaudio_level_no_table(struct kunit *test) { @@ -95,8 +112,8 @@ static void macaudio_level_no_table(struct kunit *test) &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_j714_cfg, &macaudio_j715_cfg, &macaudio_j716_cfg, + &macaudio_j813_cfg, &macaudio_j775_cfg, &macaudio_j873_cfg, }; unsigned int i; @@ -116,6 +133,7 @@ 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_levels_v2_only_requires_dcblocker), KUNIT_CASE(macaudio_level_no_table), {} }; diff --git a/sound/soc/apple/macaudio-hpf-test.h b/sound/soc/apple/macaudio-hpf-test.h index 500c2545abe63..93cacf1ddbc2a 100644 --- a/sound/soc/apple/macaudio-hpf-test.h +++ b/sound/soc/apple/macaudio-hpf-test.h @@ -385,6 +385,37 @@ static void macaudio_hpf_restores_each_dt_corner(struct kunit *test) macaudio_test_expect_hpf(test, &h, MACAUDIO_TEST_HPF_800HZ); } +static const char * const macaudio_test_hpf_unordered[] = { + "800 Hz", "Disabled", "1600 Hz", "50 Hz", +}; + +static const char * const macaudio_test_hpf_no_hz[] = { + "Disabled", "Off", +}; + +static int macaudio_test_hpf_unordered_info(struct snd_kcontrol *kctl, + struct snd_ctl_elem_info *uinfo) +{ + return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(macaudio_test_hpf_unordered), + macaudio_test_hpf_unordered); +} + +static int macaudio_test_hpf_no_hz_info(struct snd_kcontrol *kctl, + struct snd_ctl_elem_info *uinfo) +{ + return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(macaudio_test_hpf_no_hz), + macaudio_test_hpf_no_hz); +} + +static void macaudio_hpf_safe_item_picks_highest_hz(struct kunit *test) +{ + struct snd_kcontrol kctl_unordered = { .info = macaudio_test_hpf_unordered_info }; + struct snd_kcontrol kctl_no_hz = { .info = macaudio_test_hpf_no_hz_info }; + + KUNIT_EXPECT_EQ(test, macaudio_hpf_safe_item(&kctl_unordered), 2); + KUNIT_EXPECT_EQ(test, macaudio_hpf_safe_item(&kctl_no_hz), -ENOENT); +} + static struct kunit_case macaudio_hpf_cases[] = { KUNIT_CASE(macaudio_hpf_grant_opens_the_tweeters), KUNIT_CASE(macaudio_hpf_release_restores_800hz), @@ -397,6 +428,7 @@ static struct kunit_case macaudio_hpf_cases[] = { KUNIT_CASE(macaudio_hpf_crossover_latched_by_grant), KUNIT_CASE(macaudio_hpf_crossover_is_the_owners), KUNIT_CASE(macaudio_hpf_crossover_cleared_with_the_owner), + KUNIT_CASE(macaudio_hpf_safe_item_picks_highest_hz), {} }; diff --git a/sound/soc/apple/macaudio-iface-test.h b/sound/soc/apple/macaudio-iface-test.h index 6d54f87fcd5fb..0085ca6228801 100644 --- a/sound/soc/apple/macaudio-iface-test.h +++ b/sound/soc/apple/macaudio-iface-test.h @@ -290,6 +290,114 @@ static void macaudio_iface_j813_speakers_protected(struct kunit *test) macaudio_test_expect_limit(test, &f, 0, SN012776_0DB); } +/* + * J716 (v2-only): binds directly in lease mode at the hardware floor, refuses + * legacy unlock and interface revert, and never schedules the unowned fallback + * when the owner leaves. + */ +static void macaudio_iface_v2_only_never_leaves_lease(struct kunit *test) +{ + struct macaudio_test_iface f; + + KUNIT_ASSERT_TRUE(test, macaudio_speakers_allowed(&macaudio_j716_cfg)); + macaudio_test_spk_card(test, &f.t, &macaudio_j716_cfg, SN012776_0DB); + f.t.ma->has_safety = true; + { + struct snd_kcontrol_new slk = macaudio_test_control("Speaker Volume Unlock"); + struct snd_kcontrol_new iface = macaudio_test_control("Speaker Protection Interface"); + + f.daemon = kunit_kzalloc(test, sizeof(*f.daemon), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, f.daemon); + f.slk = macaudio_test_add_kctl(test, f.t.ma->card.snd_card, &slk, &f.t.ma->card); + f.iface = macaudio_test_add_kctl(test, f.t.ma->card.snd_card, &iface, &f.t.ma->card); + } + + /* Cold bind: already leased, muted at floor 0, userspace writes refused */ + KUNIT_EXPECT_TRUE(test, macaudio_spk_leased(f.t.ma)); + KUNIT_EXPECT_FALSE(test, macaudio_spk_admitted(f.t.ma)); + KUNIT_EXPECT_EQ(test, f.t.vols[0]->write_check(f.t.vols[0], NULL), -EPERM); + KUNIT_EXPECT_EQ(test, macaudio_test_write(test, &f.t, 50), -EPERM); + + /* Legacy unlock and switching back to unlock are refused */ + KUNIT_EXPECT_EQ(test, macaudio_test_iface_write(test, &f, MACAUDIO_SPK_IFACE_UNLOCK), + -EOPNOTSUPP); + KUNIT_EXPECT_TRUE(test, macaudio_spk_leased(f.t.ma)); + macaudio_test_daemon_take(test, &f); + KUNIT_EXPECT_EQ(test, macaudio_test_daemon_ping(test, &f), -EOPNOTSUPP); + KUNIT_EXPECT_FALSE(test, f.t.ma->speaker_volume_unlocked); + + /* Owner takes lease, grants operating gain, then leaves */ + macaudio_test_take(test, &f.t); + KUNIT_EXPECT_EQ(test, macaudio_test_write(test, &f.t, 50), 0); + KUNIT_EXPECT_TRUE(test, macaudio_spk_admitted(f.t.ma)); + macaudio_test_expect_vols(test, &f.t, SN012776_0DB); + + macaudio_spk_unlock(f.t.spk); + macaudio_test_settle(f.t.ma); + KUNIT_EXPECT_TRUE(test, macaudio_spk_leased(f.t.ma)); + KUNIT_EXPECT_FALSE(test, macaudio_spk_admitted(f.t.ma)); + macaudio_test_expect_vols(test, &f.t, 0); + /* No revert timer is armed on a v2-only card */ + KUNIT_EXPECT_FALSE(test, delayed_work_pending(&f.t.ma->spk_unowned_work)); + + /* Even an explicit leave-lease call cannot exit lease mode */ + mutex_lock(&f.t.ma->spk_mutex); + macaudio_spk_leave_lease(f.t.ma, "test"); + mutex_unlock(&f.t.ma->spk_mutex); + KUNIT_EXPECT_TRUE(test, macaudio_spk_leased(f.t.ma)); + KUNIT_EXPECT_FALSE(test, macaudio_spk_admitted(f.t.ma)); +} + +/* + * Component unbind and rebind reuse macaudio_snd_data: removal clears per-bind + * control state and marks spk_dead, and the next bind clears spk_dead, retakes + * volumes without overflowing spk_vols, and reapplies the cold-bind mute floor. + */ +static void macaudio_iface_v2_only_rebind_resets_floor(struct kunit *test) +{ + struct macaudio_test_spk t; + unsigned int i; + + macaudio_test_spk_card(test, &t, &macaudio_j716_cfg, SN012776_0DB); + t.ma->has_safety = true; + macaudio_test_take(test, &t); + KUNIT_EXPECT_EQ(test, macaudio_test_write(test, &t, 50), 0); + KUNIT_EXPECT_TRUE(test, macaudio_spk_admitted(t.ma)); + macaudio_test_expect_vols(test, &t, SN012776_0DB); + + /* Simulate ASoC card unbind */ + KUNIT_EXPECT_EQ(test, macaudio_card_remove(&t.ma->card), 0); + KUNIT_EXPECT_TRUE(test, t.ma->spk_dead); + KUNIT_EXPECT_EQ(test, t.ma->spk_nr_vols, 0U); + KUNIT_EXPECT_NULL(test, t.ma->spk_vols); + KUNIT_EXPECT_NULL(test, t.ma->spk_owner); + + /* Simulate rebind with stale non-zero codec volumes before cold-bind floor */ + for (i = 0; i < MACAUDIO_TEST_NR_SPK; i++) + macaudio_test_vol(t.vols[i])->value = MACAUDIO_TEST_START_VOL; + + mutex_lock(&t.ma->spk_mutex); + t.ma->spk_dead = false; + t.ma->spk_owner = NULL; + t.ma->spk_active = false; + t.ma->spk_lapsed = false; + WRITE_ONCE(t.ma->spk_granted, false); + WRITE_ONCE(t.ma->spk_xover, false); + WRITE_ONCE(t.ma->spk_iface, MACAUDIO_SPK_IFACE_LEASE); + mutex_unlock(&t.ma->spk_mutex); + + KUNIT_ASSERT_EQ(test, macaudio_spk_take_volumes(t.ma), 0); + KUNIT_EXPECT_EQ(test, t.ma->spk_nr_vols, (unsigned int)MACAUDIO_TEST_NR_SPK); + + mutex_lock(&t.ma->spk_mutex); + macaudio_spk_floor(t.ma, "card bound"); + mutex_unlock(&t.ma->spk_mutex); + + KUNIT_EXPECT_TRUE(test, macaudio_spk_leased(t.ma)); + KUNIT_EXPECT_FALSE(test, macaudio_spk_admitted(t.ma)); + macaudio_test_expect_vols(test, &t, 0); +} + /* The switch is no mixer setting: alsactl neither saves nor restores it */ static void macaudio_iface_control_is_inactive(struct kunit *test) { @@ -307,6 +415,8 @@ static struct kunit_case macaudio_iface_cases[] = { KUNIT_CASE(macaudio_iface_needs_cap_sys_admin), KUNIT_CASE(macaudio_iface_control_is_inactive), KUNIT_CASE(macaudio_iface_j813_speakers_protected), + KUNIT_CASE(macaudio_iface_v2_only_never_leaves_lease), + KUNIT_CASE(macaudio_iface_v2_only_rebind_resets_floor), {} }; diff --git a/sound/soc/apple/macaudio-kunit.dtso b/sound/soc/apple/macaudio-kunit.dtso index 724cf4fb965d2..14ff3a9f14135 100644 --- a/sound/soc/apple/macaudio-kunit.dtso +++ b/sound/soc/apple/macaudio-kunit.dtso @@ -36,6 +36,20 @@ #sound-dai-cells = <0>; }; + ma_amp_dcblk_a: macaudio-kunit-amp-dcblk-a { + compatible = "test,macaudio-kunit"; + #sound-dai-cells = <0>; + apple,speaker-config = [00 0f 00 02]; + apple,amp-dcblocker-config = [01 41 00 00]; + }; + + ma_amp_dcblk_short: macaudio-kunit-amp-dcblk-short { + compatible = "test,macaudio-kunit"; + #sound-dai-cells = <0>; + apple,speaker-config = [01 0f 04 06]; + apple,amp-dcblocker-config = [01]; + }; + macaudio-kunit-codec-good { sound-dai = <&ma_amp_a>, <&ma_amp_b>; }; @@ -51,4 +65,16 @@ macaudio-kunit-codec-level-15 { sound-dai = <&ma_amp_a>; }; + + macaudio-kunit-codec-v2-good { + sound-dai = <&ma_amp_dcblk_a>; + }; + + macaudio-kunit-codec-v2-no-dcblk { + sound-dai = <&ma_amp_dcblk_a>, <&ma_amp_a>; + }; + + macaudio-kunit-codec-v2-short-dcblk { + sound-dai = <&ma_amp_dcblk_a>, <&ma_amp_dcblk_short>; + }; }; diff --git a/sound/soc/apple/macaudio-protection-test.h b/sound/soc/apple/macaudio-protection-test.h index 1f6cd5ddb987d..cbf9d6c1ef311 100644 --- a/sound/soc/apple/macaudio-protection-test.h +++ b/sound/soc/apple/macaudio-protection-test.h @@ -164,6 +164,7 @@ static void macaudio_test_spk_card(struct kunit *test, struct macaudio_test_spk ma->has_speakers = true; mutex_init(&ma->spk_mutex); mutex_init(&ma->volume_lock_mutex); + INIT_WORK(&ma->lock_update_work, macaudio_vlimit_update_work); INIT_DELAYED_WORK(&ma->lock_timeout_work, macaudio_vlimit_timeout_work); INIT_WORK(&ma->lock_fail_work, macaudio_lock_fail_work); INIT_WORK(&ma->sw_gain_stop_work, macaudio_sw_gain_stop_work); diff --git a/sound/soc/apple/macaudio.c b/sound/soc/apple/macaudio.c index ae4c96a816fe4..39416f324b459 100644 --- a/sound/soc/apple/macaudio.c +++ b/sound/soc/apple/macaudio.c @@ -198,6 +198,14 @@ struct macaudio_platform_cfg { * the speakers stay off. */ int spk_ceiling_level; + /* + * Only the "Speaker Protection" lease may own the speakers: legacy + * "Speaker Volume Unlock" and "Speaker Protection Interface" are not + * exposed, the card binds directly in lease mode (muted at the hardware + * floor until an owner grants a lease), and losing the owner never + * reverts to the legacy interface. + */ + bool spk_v2_only; }; static const char *volume_control_names[] = { @@ -416,21 +424,24 @@ static bool macaudio_spk_leased(const struct macaudio_snd_data *ma) return READ_ONCE(ma->spk_iface) == MACAUDIO_SPK_IFACE_LEASE; } -/* Only a "Speaker Protection" lease may lift these speakers (spk_fixed_ceiling) */ +/* Only a "Speaker Protection" lease may lift these speakers */ static bool macaudio_spk_lease_only(const struct macaudio_platform_cfg *cfg) { - return cfg->spk_fixed_ceiling; + return cfg->spk_fixed_ceiling || cfg->spk_v2_only; } /* * The SN012776 volumes' limit: the floor while locked; unlocked, 0 dB, or - * on a lease-only machine safe_vol, and there only under the lease. + * on a fixed-ceiling machine safe_vol, and on a lease-only machine only + * under the lease. */ static int macaudio_sn012776_vlimit(const struct macaudio_platform_cfg *cfg, bool unlock, bool leased) { - if (macaudio_spk_lease_only(cfg)) + if (cfg->spk_fixed_ceiling) return unlock && leased ? SN012776_DB(cfg->safe_vol) : 1; + if (cfg->spk_v2_only) + return unlock && leased ? SN012776_0DB : 1; if (unlock) return SN012776_0DB; return 1; //SN012776_DB(cfg->safe_vol); @@ -852,8 +863,9 @@ static void macaudio_vlimit_update(struct macaudio_snd_data *ma) schedule_work(&ma->sw_gain_stop_work); } ma->speaker_volume_unlocked = unlock; - snd_ctl_notify(ma->card.snd_card, SNDRV_CTL_EVENT_MASK_VALUE, - &ma->speaker_lock_kctl->id); + if (ma->speaker_lock_kctl) + snd_ctl_notify(ma->card.snd_card, SNDRV_CTL_EVENT_MASK_VALUE, + &ma->speaker_lock_kctl->id); } } @@ -1074,7 +1086,6 @@ static long macaudio_spk_gain(const struct macaudio_snd_data *ma, bool granted) } } -#define MACAUDIO_TWEETER_HPF_SAFE "800 Hz" #define MACAUDIO_TWEETER_HPF_NAME "* Tweeter HPF Corner Frequency" /* @@ -1814,7 +1825,7 @@ static void macaudio_spk_leave_lease(struct macaudio_snd_data *ma, const char *w { lockdep_assert_held(&ma->spk_mutex); - if (!macaudio_spk_leased(ma)) + if (ma->cfg->spk_v2_only || !macaudio_spk_leased(ma)) return; cancel_delayed_work(&ma->spk_unowned_work); @@ -1896,6 +1907,8 @@ static int macaudio_spk_iface_put(struct snd_kcontrol *kcontrol, if (item >= ARRAY_SIZE(macaudio_spk_iface_texts)) return -EINVAL; + if (ma->cfg->spk_v2_only && item != MACAUDIO_SPK_IFACE_LEASE) + return -EOPNOTSUPP; /* The speakers are not a seat user's to hand over */ if (!capable(CAP_SYS_ADMIN)) return -EPERM; @@ -2056,7 +2069,7 @@ static void macaudio_spk_unlock(struct snd_kcontrol *kcontrol) if (macaudio_spk_leased(ma)) { macaudio_spk_floor_ramped(ma, "owner gone"); /* A restarting engine takes it back in time; a dead one does not */ - if (!ma->spk_dead) + if (!ma->spk_dead && !ma->cfg->spk_v2_only) mod_delayed_work(system_percpu_wq, &ma->spk_unowned_work, msecs_to_jiffies(SPEAKER_LEASE_UNOWNED_MS)); } @@ -2233,6 +2246,7 @@ static int macaudio_spk_take_volumes(struct macaudio_snd_data *ma) if (!nr) return -ENOENT; + ma->spk_nr_vols = 0; ma->spk_vols = devm_kcalloc(dev, nr, sizeof(*ma->spk_vols), GFP_KERNEL); ma->spk_uval = devm_kzalloc(dev, sizeof(*ma->spk_uval), GFP_KERNEL); if (!ma->spk_vols || !ma->spk_uval) @@ -2274,6 +2288,7 @@ static int macaudio_spk_take_amp_gains(struct macaudio_snd_data *ma) if (!nr) return 0; + ma->spk_nr_amp_gains = 0; ma->spk_amp_gains = devm_kcalloc(dev, nr, sizeof(*ma->spk_amp_gains), GFP_KERNEL); if (!ma->spk_amp_gains) return -ENOMEM; @@ -2286,11 +2301,17 @@ static int macaudio_spk_take_amp_gains(struct macaudio_snd_data *ma) return 0; } -/* The item of enum control @kctl named @text, or a negative error */ -static int macaudio_enum_item(struct snd_kcontrol *kctl, const char *text) +/* + * The highest corner frequency (" Hz") of a codec's playback high-pass enum, + * derived from the codec control's advertised items rather than a hard-coded + * frequency string. + */ +static int macaudio_hpf_safe_item(struct snd_kcontrol *kctl) { struct snd_ctl_elem_info *uinfo; unsigned int i, items; + unsigned long hz, best_hz = 0; + int best = -ENOENT; int ret; uinfo = kzalloc_obj(*uinfo); @@ -2301,18 +2322,28 @@ static int macaudio_enum_item(struct snd_kcontrol *kctl, const char *text) if (!ret && uinfo->type != SNDRV_CTL_ELEM_TYPE_ENUMERATED) ret = -EINVAL; items = ret ? 0 : uinfo->value.enumerated.items; - ret = -ENOENT; for (i = 0; i < items; i++) { + const char *name; + char *end; + uinfo->value.enumerated.item = i; - if (kctl->info(kctl, uinfo)) - break; - if (!strcmp(uinfo->value.enumerated.name, text)) { - ret = i; + if (kctl->info(kctl, uinfo)) { + ret = -EIO; break; } + name = uinfo->value.enumerated.name; + if (name[0] < '0' || name[0] > '9') + continue; + hz = simple_strtoul(name, &end, 10); + if (!hz || strcmp(end, " Hz")) + continue; + if (hz > best_hz) { + best_hz = hz; + best = i; + } } kfree(uinfo); - return ret; + return ret ?: best; } /* @@ -2338,6 +2369,7 @@ static int macaudio_spk_take_hpfs(struct macaudio_snd_data *ma) if (!nr) return -ENOENT; + ma->spk_nr_hpfs = 0; ma->spk_hpfs = devm_kcalloc(dev, nr, sizeof(*ma->spk_hpfs), GFP_KERNEL); ma->spk_hpf_granted = devm_kcalloc(dev, nr, sizeof(*ma->spk_hpf_granted), GFP_KERNEL); if (!ma->spk_hpfs || !ma->spk_hpf_granted) @@ -2350,7 +2382,7 @@ static int macaudio_spk_take_hpfs(struct macaudio_snd_data *ma) list_for_each_entry(kctl, &ma->card.snd_card->controls, list) { if (!snd_soc_control_matches(kctl, MACAUDIO_TWEETER_HPF_NAME)) continue; - safe = macaudio_enum_item(kctl, MACAUDIO_TWEETER_HPF_SAFE); + safe = macaudio_hpf_safe_item(kctl); if (safe < 0) { ret = safe; goto out; @@ -2401,8 +2433,17 @@ static int macaudio_copy_link(struct device *dev, struct snd_soc_dai_link *targe /* A Speaker DT link alone does not establish a protected backend. */ static bool macaudio_speakers_allowed(const struct macaudio_platform_cfg *cfg) { - /* Every admitted backend must have a configured, enforced safe level. */ - return cfg->enable_speakers && cfg->safe_vol < 0 && + /* + * Every admitted backend must have a configured, enforced safe floor: + * either an explicit negative safe_vol, or a v2-only digital-gain amp + * whose ungranted floor is hardware mute (0) and which never unlocks + * without an active protection lease. + */ + bool has_safe_floor = cfg->safe_vol < 0 || + (cfg->spk_v2_only && !cfg->spk_fixed_ceiling && + (cfg->amp == AMP_TAS5770 || cfg->amp == AMP_SN012776)); + + return cfg->enable_speakers && has_safe_floor && cfg->speakers != SPKR_NONE && (cfg->amp == AMP_TAS5770 || cfg->amp == AMP_SN012776 || cfg->amp == AMP_MAX98360A); @@ -2444,7 +2485,9 @@ static bool macaudio_sn012776_level_allowed(const struct macaudio_platform_cfg * /* * 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. + * for; on a v2-only machine every amp also requires its DC-blocker setting + * from the boot loader. Otherwise the speakers stay off while the jack stays + * available. */ static bool macaudio_sn012776_levels_present(struct device *dev, const struct macaudio_platform_cfg *cfg, @@ -2455,20 +2498,27 @@ static bool macaudio_sn012776_levels_present(struct device *dev, n = of_count_phandle_with_args(codec, "sound-dai", "#sound-dai-cells"); for (i = 0; i < n; i++) { + bool ok; + if (of_parse_phandle_with_args(codec, "sound-dai", "#sound-dai-cells", i, &args)) return false; level = macaudio_sn012776_level(args.np); + ok = macaudio_sn012776_level_allowed(cfg, level); 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)) + else if (!ok) 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) + else if (cfg->spk_v2_only && + of_property_count_u8_elems(args.np, "apple,amp-dcblocker-config") < 2) { + dev_err(dev, "%pOF: no DC blocker config from the boot loader\n", args.np); + ok = false; + } 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)) + if (!ok) return false; } return n > 0; @@ -2713,12 +2763,13 @@ static int macaudio_parse_of(struct macaudio_snd_data *ma) of_node_put(spk_codec); if (!levels) { - dev_err(card->dev, "no usable amp levels from the boot loader, disabling speakers\n"); + dev_err(card->dev, "no usable amp configuration from the boot loader, disabling speakers\n"); continue; } } ma->has_speakers = 1; - if (ma->cfg->amp != AMP_SSM3515 && ma->cfg->safe_vol != 0 && + if (ma->cfg->amp != AMP_SSM3515 && + (ma->cfg->safe_vol != 0 || ma->cfg->spk_v2_only) && !ma->cfg->spk_fixed_ceiling) ma->has_sense = 1; } @@ -3514,19 +3565,38 @@ static int macaudio_late_probe(struct snd_soc_card *card) } /* - * The volume lock's floor holds from here on, before userspace sees the - * card: "Speaker Volume Unlock" is in charge at every bind. + * Put the speakers at the hardware floor before userspace sees the card: + * on dual-interface cards "Speaker Volume Unlock" starts in charge; on + * v2-only cards "Speaker Protection" starts in charge directly. */ if (ma->has_speakers) { + /* Reset per-bind protection state so ASoC component rebind starts clean. */ + mutex_lock(&ma->spk_mutex); + ma->spk_dead = false; + ma->spk_owner = NULL; + ma->spk_active = false; + ma->spk_lapsed = false; + WRITE_ONCE(ma->spk_granted, false); + WRITE_ONCE(ma->spk_xover, false); + WRITE_ONCE(ma->spk_iface, ma->cfg->spk_v2_only ? + MACAUDIO_SPK_IFACE_LEASE : MACAUDIO_SPK_IFACE_UNLOCK); + ma->sw_gain_component = NULL; + ma->speaker_lock_kctl = NULL; + ma->spk_iface_kctl = NULL; + ma->spk_xover_kctl = NULL; + mutex_unlock(&ma->spk_mutex); + ma->speaker_sample_rate_kctl = snd_soc_card_get_kcontrol(card, "Speaker Sample Rate"); - ma->speaker_lock_kctl = snd_soc_card_get_kcontrol(card, - "Speaker Volume Unlock"); ma->spk_kctl = snd_soc_card_get_kcontrol(card, "Speaker Protection"); - ma->spk_iface_kctl = snd_soc_card_get_kcontrol(card, - "Speaker Protection Interface"); - if (!ma->speaker_sample_rate_kctl || !ma->speaker_lock_kctl || - !ma->spk_kctl || !ma->spk_iface_kctl) + if (!ma->cfg->spk_v2_only) { + ma->speaker_lock_kctl = snd_soc_card_get_kcontrol(card, + "Speaker Volume Unlock"); + ma->spk_iface_kctl = snd_soc_card_get_kcontrol(card, + "Speaker Protection Interface"); + } + if (!ma->speaker_sample_rate_kctl || !ma->spk_kctl || + (!ma->cfg->spk_v2_only && (!ma->speaker_lock_kctl || !ma->spk_iface_kctl))) return -EINVAL; ret = macaudio_spk_take_volumes(ma); if (ret) @@ -3544,17 +3614,36 @@ static int macaudio_late_probe(struct snd_soc_card *card) ma->link_props[rtd->dai_link->id].sw_gain) ma->sw_gain_component = snd_soc_rtd_to_cpu(rtd, 0)->component; } - /* The volume table's top under the lock: the legacy ceiling */ - ret = macaudio_sw_gain_full_scale(ma, false); - if (ret < 0) - return dev_err_probe(card->dev, ret, "software gain ceiling not set\n"); - - mutex_lock(&ma->volume_lock_mutex); - macaudio_vlimit_unlock(ma, false); - ret = READ_ONCE(ma->speaker_lock_failed) ? -EIO : 0; - mutex_unlock(&ma->volume_lock_mutex); - if (ret) - return dev_err_probe(card->dev, ret, "speaker volume lock not set\n"); + if (ma->cfg->spk_v2_only) { + ret = macaudio_sw_gain_full_scale(ma, true); + if (ret < 0) + return dev_err_probe(card->dev, ret, + "software gain full scale not set\n"); + mutex_lock(&ma->spk_mutex); + macaudio_spk_floor(ma, "card bound"); + ret = READ_ONCE(ma->spk_floor_failed) ? -EIO : 0; + mutex_unlock(&ma->spk_mutex); + if (ret) + return dev_err_probe(card->dev, ret, + "speaker protection floor not set\n"); + mutex_lock(&ma->volume_lock_mutex); + macaudio_vlimit_unlock(ma, true); + mutex_unlock(&ma->volume_lock_mutex); + } else { + /* The volume table's top under the lock: the legacy ceiling */ + ret = macaudio_sw_gain_full_scale(ma, false); + if (ret < 0) + return dev_err_probe(card->dev, ret, + "software gain ceiling not set\n"); + + mutex_lock(&ma->volume_lock_mutex); + macaudio_vlimit_unlock(ma, false); + ret = READ_ONCE(ma->speaker_lock_failed) ? -EIO : 0; + mutex_unlock(&ma->volume_lock_mutex); + if (ret) + return dev_err_probe(card->dev, ret, + "speaker volume lock not set\n"); + } #ifdef CONFIG_DEBUG_FS debugfs_create_atomic_t("speaker_starts_refused", 0444, card->debugfs_card_root, &ma->spk_refused); @@ -3613,6 +3702,28 @@ static int macaudio_card_remove(struct snd_soc_card *card) mutex_lock(&ma->volume_lock_mutex); macaudio_pm_volumes_drop(ma); mutex_unlock(&ma->volume_lock_mutex); + + /* Clear per-bind control references before any subsequent ASoC rebind. */ + mutex_lock(&ma->spk_mutex); + ma->spk_owner = NULL; + ma->spk_active = false; + ma->spk_lapsed = false; + WRITE_ONCE(ma->spk_xover, false); + ma->spk_vols = NULL; + ma->spk_nr_vols = 0; + ma->spk_hpfs = NULL; + ma->spk_hpf_granted = NULL; + ma->spk_nr_hpfs = 0; + ma->spk_amp_gains = NULL; + ma->spk_nr_amp_gains = 0; + ma->spk_uval = NULL; + ma->sw_gain_component = NULL; + ma->speaker_sample_rate_kctl = NULL; + ma->speaker_lock_kctl = NULL; + ma->spk_kctl = NULL; + ma->spk_iface_kctl = NULL; + ma->spk_xover_kctl = NULL; + mutex_unlock(&ma->spk_mutex); return 0; } @@ -3652,6 +3763,54 @@ static int macaudio_set_fixed_enum(struct snd_soc_card *card, const char *name, return ret; } +/* + * Called during control fixup, before the card is exposed to userspace. + * When @set_safe is true, sets each matching HPF enum control to its highest + * frequency corner before deactivating it and denying userspace writes. + */ +static int macaudio_set_fixed_hpf(struct snd_soc_card *card, const char *name, + bool set_safe) +{ + struct snd_ctl_elem_value *uval = NULL; + struct snd_kcontrol *kctl; + int hits = 0, ret = 0; + + if (set_safe) { + uval = kzalloc_obj(*uval); + if (!uval) + return -ENOMEM; + } + + list_for_each_entry(kctl, &card->snd_card->controls, list) { + if (!snd_soc_control_matches(kctl, name)) + continue; + if (set_safe) { + int safe = macaudio_hpf_safe_item(kctl); + + if (safe < 0) { + ret = safe; + goto out; + } + memset(uval, 0, sizeof(*uval)); + uval->id = kctl->id; + uval->value.enumerated.item[0] = safe; + ret = kctl->put(kctl, uval); + if (ret < 0) + goto out; + } + hits++; + } + + ret = snd_soc_deactivate_kctl(card, name, 0); + if (ret < 0) + goto out; + macaudio_deny_write(card, name); + ret = hits; +out: + kfree(uval); + return ret; +} + #define CHECK(call, pattern, value, min) \ { \ int ret = call(card, pattern, value); \ @@ -3694,11 +3853,10 @@ 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 - * high-pass starts at the protection floor; the woofers keep - * the corner the amps were given from the ADT. + * high-pass starts at the codec's highest corner frequency; + * the woofers keep the corner the amps were given from the ADT. */ - CHECK_CONCAT(macaudio_set_fixed_enum, "HPF Corner Frequency", - tweeter ? MACAUDIO_TWEETER_HPF_SAFE : NULL); + CHECK_CONCAT(macaudio_set_fixed_hpf, "HPF Corner Frequency", tweeter); CHECK_CONCAT(macaudio_set_fixed_enum, "OCE Handling", "Retry"); break; @@ -3788,6 +3946,23 @@ static int macaudio_fixup_controls(struct snd_soc_card *card) break; } + /* + * On a v2-only card the amps start in lease mode: fix their operating + * gains at the ADT-derived limits just installed above before the card + * is exposed to userspace. + */ + if (ma->cfg->spk_v2_only) { + int ret; + + mutex_lock(&ma->spk_mutex); + ret = macaudio_spk_fix_amp_gains(ma); + if (ret) + WRITE_ONCE(ma->spk_floor_failed, true); + mutex_unlock(&ma->spk_mutex); + if (ret) + return ret; + } + return 0; } @@ -3868,6 +4043,9 @@ static int macaudio_slk_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_v struct macaudio_snd_data *ma = snd_soc_card_get_drvdata(card); long val = uvalue->value.integer.value[0]; + if (ma->cfg->spk_v2_only) + return -EOPNOTSUPP; + /* * Reads return the lock state (0 or 1), so a saved mixer state holds * one of those. Writing it back changes nothing: only the lock owner's @@ -3981,8 +4159,12 @@ static void macaudio_slk_unlock(struct snd_kcontrol *kcontrol) mutex_unlock(&ma->volume_lock_mutex); } -/* The speaker controls go last: a card without speakers drops them. */ +/* + * The speaker controls go last: a card without speakers drops all four, and a + * v2-only card drops the final two legacy controls. + */ #define MACAUDIO_NUM_SPEAKER_CONTROLS 4 +#define MACAUDIO_NUM_LEGACY_SPEAKER_CONTROLS 2 static const struct snd_kcontrol_new macaudio_controls[] = { SOC_DAPM_PIN_SWITCH("Speaker"), @@ -3995,6 +4177,14 @@ static const struct snd_kcontrol_new macaudio_controls[] = { .name = "Speaker Sample Rate", .info = macaudio_sss_info, .get = macaudio_sss_get, }, + { + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, + .access = MACAUDIO_SPK_OWNERSHIP_ACCESS, + .name = "Speaker Protection", + .info = macaudio_spk_info, + .put = macaudio_spk_put, .get = macaudio_spk_get, + .lock = macaudio_spk_lock, .unlock = macaudio_spk_unlock, + }, { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .access = SNDRV_CTL_ELEM_ACCESS_READ | @@ -4005,14 +4195,6 @@ static const struct snd_kcontrol_new macaudio_controls[] = { .put = macaudio_slk_put, .get = macaudio_slk_get, .lock = macaudio_slk_lock, .unlock = macaudio_slk_unlock, }, - { - .iface = SNDRV_CTL_ELEM_IFACE_MIXER, - .access = MACAUDIO_SPK_OWNERSHIP_ACCESS, - .name = "Speaker Protection", - .info = macaudio_spk_info, - .put = macaudio_spk_put, .get = macaudio_spk_get, - .lock = macaudio_spk_lock, .unlock = macaudio_spk_unlock, - }, { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .access = MACAUDIO_SPK_OWNERSHIP_ACCESS, @@ -4191,6 +4373,29 @@ struct macaudio_platform_cfg macaudio_j714_cfg = { .tweeter_hpf_granted = true, }; +/* + * J716 (T6050, MacBook Pro 16" M5 Pro/Max): AOP-fed CS42L84 jack and six + * SN012776 speaker amps (two woofers and a tweeter per side) with twelve V/I + * sense slots in the 250-BCLK 12 MHz frame. All per-amp operating levels and + * DC-blocker settings come from the boot loader's DT properties, and speakers + * run behind the v2 "Speaker Protection" lease only (spk_v2_only): without a + * live lease owner, volumes stay locked at the hardware mute floor and speaker + * PCM starts are refused, with no legacy unlock fallback or guessed safe_vol. + */ +struct macaudio_platform_cfg macaudio_j716_cfg = { + .enable_speakers = true, + .amp = AMP_SN012776, + .speakers = SPKR_2W1T, + .stereo = true, + .fe_dai_names = { "j873-pcm-0", "j873-pcm-1", "j873-pcm-2" }, + .dai_fmt = SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_CBC_CFC | SND_SOC_DAIFMT_IB_NF, + .spk_dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBC_CFC | + SND_SOC_DAIFMT_GATED | SND_SOC_DAIFMT_NB_IF, + .spk_secondary_only = true, + .tweeter_hpf_granted = true, + .spk_v2_only = true, +}; + /* * J815 (T8142, MacBook Air M5 15"): J813's AOP-fed card with six SN012776, * two woofers and a tweeter per side, in ADT speaker-config order (left @@ -4500,6 +4705,8 @@ static const struct of_device_id macaudio_snd_device_id[] = { { .compatible = "apple,j700-macaudio", .data = &macaudio_j700_cfg }, /* j714 - sn012776 15 2x 2W+1T (AOP-fed, V/I sense) */ { .compatible = "apple,j714-macaudio", .data = &macaudio_j714_cfg }, + /* j716 AID41 sn012776 - 2x 2W+1T (AOP-fed, V/I sense, v2 lease only) */ + { .compatible = "apple,j716-macaudio", .data = &macaudio_j716_cfg }, /* k116 - sn012776 15 2x 2W+1T (AOP-fed, V/I sense; the 16" PROLED chassis, J714's amps and frame) */ { .compatible = "apple,k116-macaudio", .data = &macaudio_j714_cfg }, /* j713 - sn012776 15 2x 1W+1T (AOP-fed, one serializer) */ @@ -4596,10 +4803,12 @@ static int macaudio_snd_platform_probe(struct platform_device *pdev) if (!data->has_sense) card->num_dapm_routes--; - /* Admitted speakers always have a safe level (macaudio_speakers_allowed()) */ + /* Admitted speakers always have a safe floor (macaudio_speakers_allowed()) */ if (!data->has_speakers) { card->num_controls -= MACAUDIO_NUM_SPEAKER_CONTROLS; } else { + if (data->cfg->spk_v2_only) + card->num_controls -= MACAUDIO_NUM_LEGACY_SPEAKER_CONTROLS; data->has_safety = true; macaudio_quiet_refusals(card); } @@ -4622,7 +4831,8 @@ static int macaudio_snd_platform_probe(struct platform_device *pdev) atomic_set(&data->sw_gain_lock_epoch, 0); atomic_set(&data->sw_gain_prepared_epoch, -1); atomic_set(&data->sw_gain_limit_failed, 0); - data->spk_iface = MACAUDIO_SPK_IFACE_UNLOCK; + data->spk_iface = data->cfg->spk_v2_only ? + MACAUDIO_SPK_IFACE_LEASE : MACAUDIO_SPK_IFACE_UNLOCK; ret = macaudio_spk_init(data); if (ret) From 830c90c8f223400d5901d1d0f8c3eb733b727878 Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Tue, 24 Nov 2026 10:31:26 -0500 Subject: [PATCH 2/7] pmdomain: apple: pmc: probe without PMP when supplier lacks loader properties When a board DT leaves PMP calibration and identity properties (apple,board-id, apple,dram-vendor-id) to the boot loader and references that PMP from PMC via apple,pmp, booting under an older loader causes apple_pmp to fail probe permanently with -EINVAL. Deferring PMC on that supplier would keep PMC and its CLPC child (cpufreq) from probing at all. Check that an apple,pmp supplier carries apple,board-id and apple,dram-vendor-id before linking and deferring on it. When they are absent, log once, skip the PMP supplier link and omit PMP agent 0 from static_agents so PMC and CLPC keep running as before. Signed-off-by: Erik Bourget --- drivers/pmdomain/apple/pmc.c | 40 +++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/drivers/pmdomain/apple/pmc.c b/drivers/pmdomain/apple/pmc.c index e93dc40bc10c1..1c89389f046f7 100644 --- a/drivers/pmdomain/apple/pmc.c +++ b/drivers/pmdomain/apple/pmc.c @@ -1313,19 +1313,37 @@ static int apple_pmc_probe(struct platform_device *pdev) struct device_node *pmp_node; struct platform_device *pmp; struct device_link *link; + bool pmp_unavailable = false; pmp_node = of_parse_phandle(np, "apple,pmp", 0); if (pmp_node) { - pmp = of_find_device_by_node(pmp_node); - of_node_put(pmp_node); - if (!pmp) - return -EPROBE_DEFER; - link = device_link_add(dev, &pmp->dev, DL_FLAG_AUTOREMOVE_CONSUMER); - put_device(&pmp->dev); - if (!link) - return -EINVAL; - if (link->supplier->links.status != DL_DEV_DRIVER_BOUND) - return -EPROBE_DEFER; + /* + * A DT whose PMP relies on boot-loader ADT handoff leaves + * apple,board-id and apple,dram-vendor-id absent when booted + * by an older loader. In that case apple_pmp fails permanently, + * so keep PMC (and its CLPC child) running without the PMP + * static voter instead of deferring forever. + */ + if (of_device_is_available(pmp_node) && + of_property_present(pmp_node, "apple,board-id") && + of_property_present(pmp_node, "apple,dram-vendor-id")) { + pmp = of_find_device_by_node(pmp_node); + of_node_put(pmp_node); + if (!pmp) + return -EPROBE_DEFER; + link = device_link_add(dev, &pmp->dev, DL_FLAG_AUTOREMOVE_CONSUMER); + put_device(&pmp->dev); + if (!link) + return -EINVAL; + if (link->supplier->links.status != DL_DEV_DRIVER_BOUND) + return -EPROBE_DEFER; + } else { + dev_info(dev, + "PMP supplier %pOF lacks boot-loader properties; probing PMC without PMP\n", + pmp_node); + of_node_put(pmp_node); + pmp_unavailable = true; + } } pmc = devm_kzalloc(dev, sizeof(*pmc), GFP_KERNEL); @@ -1384,6 +1402,8 @@ static int apple_pmc_probe(struct platform_device *pdev) agents[i]); pmc->static_agents |= BIT(agents[i]); } + if (pmp_unavailable) + pmc->static_agents &= ~BIT(0); } platform_set_drvdata(pdev, pmc); From a0f72aa063055491ed1f6e6ab300cab5db610eb0 Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Tue, 24 Nov 2026 01:27:27 -0500 Subject: [PATCH 3/7] arm64: dts: apple: t6050-j716c: enable the PMP Enable pmp0, pmp0_report, pmp0_dart, pmp0_mbox, their power domains, and the PMC static voters on J716c. Leave apple,board-id, apple,dram-vendor-id, apple,pmc, apple,pmc-pmgr, and apple,tunable-* to the boot loader so every unit runs on its own ADT values rather than compiled-in tunables. The AOP audio firmware requires the PMP to bring up its LEAP power domains so the audio controller reaches systemReady. Signed-off-by: Erik Bourget --- arch/arm64/boot/dts/apple/t6050-j716c.dts | 42 +++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t6050-j716c.dts b/arch/arm64/boot/dts/apple/t6050-j716c.dts index acc1034a340e7..e68aa0886b4be 100644 --- a/arch/arm64/boot/dts/apple/t6050-j716c.dts +++ b/arch/arm64/boot/dts/apple/t6050-j716c.dts @@ -332,3 +332,45 @@ &hpm5 { apple,sleep-ssps-rules; }; + +/* + * The PMP (ADT pmp0): iBoot loads its firmware and the boot loader fills + * apple,board-id, apple,dram-vendor-id, apple,pmc, apple,pmc-pmgr, and + * apple,tunable-* from the running machine's ADT onto pmp0. The AOP's audio + * firmware requires the PMP to bring up its LEAP power domains so the audio + * controller reaches systemReady. + */ +&ps_pms { + status = "okay"; +}; + +&ps_pmp { + status = "okay"; +}; + +&ps_pms_sram { + status = "okay"; +}; + +&pmp0_dart { + status = "okay"; +}; + +&pmp0_mbox { + status = "okay"; +}; + +&pmp0 { + status = "okay"; +}; + +&pmp0_report { + status = "okay"; +}; + +&pmc { + /* PMP, CLPC and AP agents, once the PMP runs */ + apple,static-voters = <0 1 3>; + apple,pmp = <&pmp0>; +}; + From 31a8aca833050357290695dccb3b2ba88e681ee6 Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Tue, 24 Nov 2026 01:27:27 -0500 Subject: [PATCH 4/7] arm64: dts: apple: t6050-j716c: enable AOP audio, speakers, jack and mic array Enable i2c1, i2c2, i2c3, the audio GPIOs on pinctrl_ap, the AOP, admac-base-ns, admac-ec-proxy, aop_audio, six SN012776 speaker amplifiers (shared SDZ regulator on AP pin 107 with apple,sdz-group-fail-closed, shared fault IRQ on AP pin 106, ti,bclk-ratio 250, V/I sense slots 0/2 through 20/22), the CS42L84 headphone jack codec, and the apple,j716-macaudio sound card with speaker-id GPIOs on AP pins 136 and 137. Signed-off-by: Erik Bourget --- arch/arm64/boot/dts/apple/t6050-j716c.dts | 244 +++++++++++++++++++++- 1 file changed, 233 insertions(+), 11 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t6050-j716c.dts b/arch/arm64/boot/dts/apple/t6050-j716c.dts index e68aa0886b4be..8d283ab0ff78d 100644 --- a/arch/arm64/boot/dts/apple/t6050-j716c.dts +++ b/arch/arm64/boot/dts/apple/t6050-j716c.dts @@ -166,22 +166,16 @@ status = "disabled"; }; -&i2c1 { - status = "disabled"; -}; - -&i2c2 { - status = "disabled"; -}; - /* * Pin 112's register (0x29c0001c0) takes an SError when read, so only the pins a node - * here names are exposed: 80 (PCIe port 0's PERST#, ADT pci-bridge0 function-perst) and - * 138 (the Touch ID sensor's data-ready line). + * here names are exposed: 80 (PCIe port 0's PERST#, ADT pci-bridge0 function-perst), + * 106 and 107 (the speaker amps' fault interrupt and shutdown line), 134 and 139 (the + * jack codec's interrupt and reset), 136 and 137 (speaker ID) and 138 (the Touch ID + * sensor's data-ready line). * A reserved line cannot be requested, so a node that names a new pin opens it here too. */ &pinctrl_ap { - gpio-reserved-ranges = <0 80>, <81 57>, <139 82>; + gpio-reserved-ranges = <0 80>, <81 25>, <108 26>, <135 1>, <140 81>; }; /* This board's SMC fan and power keys are not yet checked */ @@ -374,3 +368,231 @@ apple,pmp = <&pmp0>; }; +/* + * Sound through the AOP, as on J714s: its audio service runs the serializers, the + * CS42L84 headphone jack on admac-base-ns TX2/RX2 and the six SN012776 speaker amps + * on TX0, their voltage and current sense on RX0 (ADT iop-audio-controller). + * + * The amps (ADT /arm-io/i2c1/audio-speaker* and /arm-io/i2c3/audio-speaker*) share + * one shutdown line, AP pin 107 (function-reset of the first), and one fault + * interrupt, pin 106. The ADT's speaker-config gives amp N playback slot N, its + * voltage sense in slot 4N and current sense in 4N+2, in the order of the first + * amp's speakerN: left woofer 1, right woofer 1, left woofer 2, right woofer 2, + * left tweeter, right tweeter. The firmware's speaker frame is 250 BCLKs of 12 MHz + * (ADT audio-speaker stream), which the amps' ratio detection rejects. + */ +/ { + speaker_sdz: regulator-sn012776-sdz { + compatible = "regulator-fixed"; + regulator-name = "sn012776-sdz"; + gpios = <&pinctrl_ap 107 GPIO_ACTIVE_HIGH>; + enable-active-high; + }; +}; + +&i2c1 { + status = "okay"; + + speaker_left_woof1: codec@38 { + compatible = "ti,sn012776", "ti,tas2764"; + reg = <0x38>; + SDZ-supply = <&speaker_sdz>; + apple,sdz-group-fail-closed; + #sound-dai-cells = <0>; + sound-name-prefix = "Left Woofer 1"; + interrupts-extended = <&pinctrl_ap 106 IRQ_TYPE_LEVEL_LOW>; + ti,imon-slot-no = <2>; + ti,vmon-slot-no = <0>; + ti,bclk-ratio = <250>; + }; + + speaker_left_woof2: codec@39 { + compatible = "ti,sn012776", "ti,tas2764"; + reg = <0x39>; + SDZ-supply = <&speaker_sdz>; + apple,sdz-group-fail-closed; + #sound-dai-cells = <0>; + sound-name-prefix = "Left Woofer 2"; + interrupts-extended = <&pinctrl_ap 106 IRQ_TYPE_LEVEL_LOW>; + ti,imon-slot-no = <10>; + ti,vmon-slot-no = <8>; + ti,bclk-ratio = <250>; + }; + + speaker_left_tweet: codec@3a { + compatible = "ti,sn012776", "ti,tas2764"; + reg = <0x3a>; + SDZ-supply = <&speaker_sdz>; + apple,sdz-group-fail-closed; + #sound-dai-cells = <0>; + sound-name-prefix = "Left Tweeter"; + interrupts-extended = <&pinctrl_ap 106 IRQ_TYPE_LEVEL_LOW>; + ti,imon-slot-no = <18>; + ti,vmon-slot-no = <16>; + ti,bclk-ratio = <250>; + }; +}; + +/* The I2C power states have no described parent (SIO), as for i2c1 and i2c2 */ +&ps_i2c3 { + /delete-property/ power-domains; + status = "okay"; +}; + +&i2c3 { + /* The ADT gives i2c1, i2c2 and i2c3 the same clock-ids (4) */ + clocks = <&clkref>; + status = "okay"; + + speaker_right_woof1: codec@3b { + compatible = "ti,sn012776", "ti,tas2764"; + reg = <0x3b>; + SDZ-supply = <&speaker_sdz>; + apple,sdz-group-fail-closed; + #sound-dai-cells = <0>; + sound-name-prefix = "Right Woofer 1"; + interrupts-extended = <&pinctrl_ap 106 IRQ_TYPE_LEVEL_LOW>; + ti,imon-slot-no = <6>; + ti,vmon-slot-no = <4>; + ti,bclk-ratio = <250>; + }; + + speaker_right_woof2: codec@3c { + compatible = "ti,sn012776", "ti,tas2764"; + reg = <0x3c>; + SDZ-supply = <&speaker_sdz>; + apple,sdz-group-fail-closed; + #sound-dai-cells = <0>; + sound-name-prefix = "Right Woofer 2"; + interrupts-extended = <&pinctrl_ap 106 IRQ_TYPE_LEVEL_LOW>; + ti,imon-slot-no = <14>; + ti,vmon-slot-no = <12>; + ti,bclk-ratio = <250>; + }; + + speaker_right_tweet: codec@3d { + compatible = "ti,sn012776", "ti,tas2764"; + reg = <0x3d>; + SDZ-supply = <&speaker_sdz>; + apple,sdz-group-fail-closed; + #sound-dai-cells = <0>; + sound-name-prefix = "Right Tweeter"; + interrupts-extended = <&pinctrl_ap 106 IRQ_TYPE_LEVEL_LOW>; + ti,imon-slot-no = <22>; + ti,vmon-slot-no = <20>; + ti,bclk-ratio = <250>; + }; +}; + +/* + * The CS42L84 headphone codec (ADT /arm-io/i2c2/audio-codec-output): its reset line + * is AP pin 139, driven high to run the codec, and its interrupt AP pin 134, level + * low. + */ +&i2c2 { + status = "okay"; + + jack_codec: codec@4b { + compatible = "cirrus,cs42l84"; + reg = <0x4b>; + reset-gpios = <&pinctrl_ap 139 GPIO_ACTIVE_HIGH>; + interrupts-extended = <&pinctrl_ap 134 IRQ_TYPE_LEVEL_LOW>; + #sound-dai-cells = <0>; + sound-name-prefix = "Jack"; + }; +}; + +/ { + sound { + compatible = "apple,j716-macaudio", "apple,macaudio"; + model = "MacBook Pro J716"; + /* ADT audio-speaker function-speaker-id0 and -id1 */ + speaker-id-gpios = <&pinctrl_ap 136 GPIO_ACTIVE_HIGH>, + <&pinctrl_ap 137 GPIO_ACTIVE_HIGH>; + #address-cells = <1>; + #size-cells = <0>; + + dai-link@0 { + reg = <0>; + link-name = "Headphone Jack"; + + cpu { + sound-dai = <&aop_audio 0>; + }; + + codec { + sound-dai = <&jack_codec>; + }; + }; + + dai-link@1 { + reg = <1>; + link-name = "Speaker"; + /* + * Codecs in ADT speaker-config order so macaudio assigns + * playback slots 0-5 (left channels in slots 0, 2 and 4, + * right in 1, 3 and 5). Each side's first amp drives zeros + * on the opposite side's active sense byte slots (0..23) + * and both include the unused upper bytes (24..31) of the + * 32-byte TDM frame: left woofer 1 drives zeros on right + * slots 4..7, 12..15, 20..23 and upper bytes 24..31 + * (0xfff0f0f0); right woofer 1 drives zeros on left slots + * 0..3, 8..11, 16..19 and upper bytes 24..31 (0xff0f0f0f). + * Active V/I slots 0..23 remain disjoint even without a + * loader apple,amp-tx-zd-config override. + */ + dai-tdm-idle-mode-0 = "zero"; + dai-tdm-slot-tx-idle-mask-0 = <0xfff0f0f0>; + dai-tdm-idle-mode-1 = "zero"; + dai-tdm-slot-tx-idle-mask-1 = <0xff0f0f0f>; + + cpu { + sound-dai = <&aop_audio 3>; + }; + + codec { + sound-dai = <&speaker_left_woof1>, <&speaker_right_woof1>, + <&speaker_left_woof2>, <&speaker_right_woof2>, + <&speaker_left_tweet>, <&speaker_right_tweet>; + }; + }; + }; +}; + +/* The AOP, booted through its setup port, with its sensor and audio services. */ +&aop_mbox { + status = "okay"; +}; + +&aop_setup_mbox { + status = "okay"; +}; + +&aop_dart { + status = "okay"; +}; + +&aop { + status = "okay"; +}; + +/* + * The microphone array: ADT audio-hp-mic, three microphones on leap-s RX0 through the + * proxy ADMAC (Linux channel 1, as on J714s), captured by the AOP audio service's own card. + */ +&admac_base_ns { + status = "okay"; +}; + +&admac_ec_proxy { + status = "okay"; +}; + +&aop_audio { + apple,chassis-name = "J716"; + apple,machine-kind = "MacBook Pro"; + dmas = <&admac_base_ns 4>, <&admac_base_ns 5>, + <&admac_base_ns 0>, <&admac_base_ns 1>, + <&admac_ec_proxy 1>; + dma-names = "cout", "cin", "spkr", "sense", "hpai"; +}; From d5f374213e9fe21e7328260978421e60ffc069dd Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Fri, 27 Nov 2026 13:02:03 -0500 Subject: [PATCH 5/7] Revert "pmdomain: apple: pmc: probe without PMP when supplier lacks loader properties" This reverts commit 830c90c8f223400d5901d1d0f8c3eb733b727878. Signed-off-by: Erik Bourget --- drivers/pmdomain/apple/pmc.c | 40 +++++++++--------------------------- 1 file changed, 10 insertions(+), 30 deletions(-) diff --git a/drivers/pmdomain/apple/pmc.c b/drivers/pmdomain/apple/pmc.c index 73daaddbc3fc7..7949216808a76 100644 --- a/drivers/pmdomain/apple/pmc.c +++ b/drivers/pmdomain/apple/pmc.c @@ -1330,37 +1330,19 @@ static int apple_pmc_probe(struct platform_device *pdev) struct device_node *pmp_node; struct platform_device *pmp; struct device_link *link; - bool pmp_unavailable = false; pmp_node = of_parse_phandle(np, "apple,pmp", 0); if (pmp_node) { - /* - * A DT whose PMP relies on boot-loader ADT handoff leaves - * apple,board-id and apple,dram-vendor-id absent when booted - * by an older loader. In that case apple_pmp fails permanently, - * so keep PMC (and its CLPC child) running without the PMP - * static voter instead of deferring forever. - */ - if (of_device_is_available(pmp_node) && - of_property_present(pmp_node, "apple,board-id") && - of_property_present(pmp_node, "apple,dram-vendor-id")) { - pmp = of_find_device_by_node(pmp_node); - of_node_put(pmp_node); - if (!pmp) - return -EPROBE_DEFER; - link = device_link_add(dev, &pmp->dev, DL_FLAG_AUTOREMOVE_CONSUMER); - put_device(&pmp->dev); - if (!link) - return -EINVAL; - if (link->supplier->links.status != DL_DEV_DRIVER_BOUND) - return -EPROBE_DEFER; - } else { - dev_info(dev, - "PMP supplier %pOF lacks boot-loader properties; probing PMC without PMP\n", - pmp_node); - of_node_put(pmp_node); - pmp_unavailable = true; - } + pmp = of_find_device_by_node(pmp_node); + of_node_put(pmp_node); + if (!pmp) + return -EPROBE_DEFER; + link = device_link_add(dev, &pmp->dev, DL_FLAG_AUTOREMOVE_CONSUMER); + put_device(&pmp->dev); + if (!link) + return -EINVAL; + if (link->supplier->links.status != DL_DEV_DRIVER_BOUND) + return -EPROBE_DEFER; } pmc = devm_kzalloc(dev, sizeof(*pmc), GFP_KERNEL); @@ -1419,8 +1401,6 @@ static int apple_pmc_probe(struct platform_device *pdev) agents[i]); pmc->static_agents |= BIT(agents[i]); } - if (pmp_unavailable) - pmc->static_agents &= ~BIT(0); } platform_set_drvdata(pdev, pmc); From 952e45d7f622d7e68adcae1cd2b690512367a7db Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Fri, 27 Nov 2026 13:29:01 -0500 Subject: [PATCH 6/7] Revert "arm64: dts: apple: t6050-j716c: enable the PMP" This reverts commit a0f72aa063055491ed1f6e6ab300cab5db610eb0. Signed-off-by: Erik Bourget # Conflicts: # arch/arm64/boot/dts/apple/t6050-j716c.dts --- arch/arm64/boot/dts/apple/t6050-j716c.dts | 41 ----------------------- 1 file changed, 41 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t6050-j716c.dts b/arch/arm64/boot/dts/apple/t6050-j716c.dts index 0aaf5ee87435c..77ded5889352d 100644 --- a/arch/arm64/boot/dts/apple/t6050-j716c.dts +++ b/arch/arm64/boot/dts/apple/t6050-j716c.dts @@ -347,47 +347,6 @@ apple,sleep-ssps-rules; }; -/* - * The PMP (ADT pmp0): iBoot loads its firmware and the boot loader fills - * apple,board-id, apple,dram-vendor-id, apple,pmc, apple,pmc-pmgr, and - * apple,tunable-* from the running machine's ADT onto pmp0. The AOP's audio - * firmware requires the PMP to bring up its LEAP power domains so the audio - * controller reaches systemReady. - */ -&ps_pms { - status = "okay"; -}; - -&ps_pmp { - status = "okay"; -}; - -&ps_pms_sram { - status = "okay"; -}; - -&pmp0_dart { - status = "okay"; -}; - -&pmp0_mbox { - status = "okay"; -}; - -&pmp0 { - status = "okay"; -}; - -&pmp0_report { - status = "okay"; -}; - -&pmc { - /* PMP, CLPC and AP agents, once the PMP runs */ - apple,static-voters = <0 1 3>; - apple,pmp = <&pmp0>; -}; - /* * Sound through the AOP, as on J714s: its audio service runs the serializers, the * CS42L84 headphone jack on admac-base-ns TX2/RX2 and the six SN012776 speaker amps From 823c2aa35eb6a49d6fbbd6246f9465ec45fa7334 Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Sat, 28 Nov 2026 18:25:03 -0500 Subject: [PATCH 7/7] selftests: alsa: update macaudio-fixed-controls for dynamic HPF selection Signed-off-by: Erik Bourget --- .../selftests/alsa/macaudio-fixed-controls.py | 44 +++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/alsa/macaudio-fixed-controls.py b/tools/testing/selftests/alsa/macaudio-fixed-controls.py index 5ca87d990c11f..05f9602bb923a 100644 --- a/tools/testing/selftests/alsa/macaudio-fixed-controls.py +++ b/tools/testing/selftests/alsa/macaudio-fixed-controls.py @@ -82,6 +82,7 @@ def function(source, name): #define devm_kcalloc(d, n, s, g) calloc(n, s) #define kzalloc_obj(o) calloc(1, sizeof(o)) #define kfree free +#define simple_strtoul strtoul #define lockdep_assert_held(p) ((void)0) #define smp_load_acquire(p) __atomic_load_n(p, __ATOMIC_ACQUIRE) static void snd_ctl_notify(struct snd_card *c, int e, struct snd_ctl_elem_id *i) {} @@ -286,6 +287,40 @@ def function(source, name): for (i = 0; i < 2; i++) check(regs[i].reg == (initial + i) % 7, "restore each amp DT corner", "HPF"); free(ma.spk_hpfs); free(ma.spk_hpf_granted); } +#ifdef HAVE_DYNAMIC_HPF_SAFE_ITEM + /* Dynamic safe-corner selection picks the highest " Hz" item, regardless of order. */ + { + const char * const dyn_texts[] = { "Disabled", "1600 Hz", "400 Hz", "800 Hz", "800 Hz!", "200 Hz", "0 Hz" }; + struct snd_soc_card soc = { .snd_card = &card, .data = &ma }; + ma.card = soc; + ma.spk_nr_hpfs = 0; + for (i = 0; i < 2; i++) { + snprintf(controls[i].id.name, sizeof(controls[i].id.name), "%s Tweeter HPF Corner Frequency", i ? "Right" : "Left"); + controls[i].count = 1; controls[i].vd[0].access = 3; + controls[i].info = enum_info; controls[i].get = enum_get; controls[i].put = snd_soc_put_enum_double; + controls[i].private_value = (unsigned long)&e; controls[i].component = ®s[i]; controls[i].texts = dyn_texts; + controls[i].next = i ? NULL : &controls[1]; regs[i].reg = 2; + } + check(macaudio_spk_take_hpfs(&ma) == 0, "capture dynamic DT corner", "HPF"); + check(macaudio_spk_set_hpf(&ma, false) == 0, "dynamic floor", "HPF"); + check(regs[0].reg == 1 && regs[1].reg == 1, "safe highest Hz (1600 Hz)", "HPF"); + check(macaudio_spk_set_hpf(&ma, true) == 0, "dynamic grant", "HPF"); + check(regs[0].reg == 2 && regs[1].reg == 2, "restore dynamic DT corner", "HPF"); + free(ma.spk_hpfs); free(ma.spk_hpf_granted); +#ifdef HAVE_SET_FIXED_HPF + check(macaudio_set_fixed_hpf(&soc, "* Tweeter HPF Corner Frequency", true) == 2, "fixed dynamic HPF", "HPF"); + check(regs[0].reg == 1 && regs[1].reg == 1, "fixed safe highest Hz (1600 Hz)", "HPF"); + { + struct snd_ctl_file ordinary = {0}; + for (i = 0; i < 2; i++) { + struct snd_ctl_elem_value v = { .id = controls[i].id }; + check(snd_ctl_elem_write(&card, &ordinary, &v) == -EPERM, "fixed dynamic HPF denies write", "HPF"); + check(regs[i].reg == 1, "fixed dynamic HPF keeps safe corner", "HPF"); + } + } +#endif + } +#endif } int main(void) { @@ -328,18 +363,21 @@ def main(): parts.append(function(ma, "macaudio_deny_write")) if "static int macaudio_set_fixed_enum(" in ma: parts.append(function(ma, "macaudio_set_fixed_enum")) + parts += re.findall(r"^#define MACAUDIO_\w*HPF\w*\s.*$", ma, re.M) if "static const char *macaudio_speaker_hpf(" in ma: - parts += re.findall(r"^#define MACAUDIO_\w*HPF\w*\s.*$", ma, re.M) parts.append(function(ma, "macaudio_speaker_hpf")) - parts += re.findall(r"^#define MACAUDIO_\w*HPF\w*\s.*$", ma, re.M) + has_dyn_hpf = "static int macaudio_hpf_safe_item(" in ma parts += [function(ma, "macaudio_sense_owner_check"), function(ma, "macaudio_sense_write_check"), *([function(ma, "macaudio_route_check"), function(ma, "macaudio_route_write_check")] if "static int macaudio_route_write_check(" in ma else []), function(ma, "macaudio_protect_sense"), - function(ma, "macaudio_enum_item"), + *(["#define HAVE_DYNAMIC_HPF_SAFE_ITEM 1", function(ma, "macaudio_hpf_safe_item")] + if has_dyn_hpf else [function(ma, "macaudio_enum_item")]), function(ma, "macaudio_spk_take_hpfs"), function(ma, "macaudio_spk_set_hpf")] + if "static int macaudio_set_fixed_hpf(" in ma: + parts += ["#define HAVE_SET_FIXED_HPF 1", function(ma, "macaudio_set_fixed_hpf")] parts += [ma[ma.index("#define CHECK(call,"):ma.index("static int macaudio_set_speaker(")], function(ma, "macaudio_set_speaker"), MAIN] with tempfile.TemporaryDirectory(prefix="macaudio-fixed-") as temp: