From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=82.195.75.108 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796139159; b=wtus9crgBWvdcl1PDlZHR3w0KJRlJO4goqmfRUjSuEZqXtNmdIvp9PufG6RNbUBktfjt cNSlouLEdyfjrwKRCOtOmaVm3w/su68VdW+9PY289+qxGtJmYnMDsfzrNqMR1JYEpjiUR b2oNAEEk4UhMJdF3wLdrWco+Q3uxtBfADHt8vEIHZojXcY4Y+0RxFRYaqpS9YiQLB3taR TEWEV0DDNM6AIz8kxy5/HQV/CQskiM6VSq02JVJ/08pdZwKYHAR0QPN4VWLiYRSZvKnAU QovQSYZfscSnIuqOSh4DOfp044oaAEdq10uLCpA0lGshivMbMv0x+bAyM3oEg+Nx1IQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796139159; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-Id:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-Debian-User; bh=BSYoroLn12NuJCz2pEdNedgmnc1AGveRmGDyJ/JezPU=; b=ZtmTCsISxBB3L5ao9AQPE8TT6tXCPej4TIOEu9U++hLQKt46ReRqggrFU14quojBF6Z+ R70tEC3ddGVLO80bqXPFUwKBvhsDNifHjw8DCljcStKXz2WQwuz10i9ikdJXytddFH1x4 DKj25uJQCwRbdZdssEmAoeNpHAE/QBMu5KvUgvmjFB2UW8ZKysMS+7LwA1z5WRcFziOt6 1GKZnYsb4MeKU0p352I3fWK4r2IrKrzKX5op1+NiXCYNi1a0kTcAhbZ2jHu5riIWi8Iha aboVwQzb2ez6mXugX811Ofqgzxm3r/7q0Xi3OSWYa3e/aLXYTUv7nIkj5eaNtJKt0cQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=debian.org; spf=pass smtp.mailfrom=debian.org; dkim=pass header.d=debian.org header.i=@debian.org header.a=rsa-sha256 header.s=smtpauto.stravinsky header.b=I6usKCjV; arc=none smtp.remote-ip=82.195.75.108 Received: from stravinsky.debian.org (stravinsky.debian.org [82.195.75.108]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 767CB606A320; Tue, 1 Dec 2026 15:32:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 767CB606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=debian.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.a=rsa-sha256 header.s=smtpauto.stravinsky header.b=I6usKCjV DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debian.org; s=smtpauto.stravinsky; h=X-Debian-User:Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Reply-To: Content-Type:Content-ID:Content-Description; bh=BSYoroLn12NuJCz2pEdNedgmnc1AGveRmGDyJ/JezPU=; b=I6usKCjVxdQtj3kLMS2Jd6B2S5 GapXrspZ7WL6q/FHHOstdCMwqmcED0i8j7YVkZKyeYzVFVtqbMwk5+6r9JfdYKQLZgfeTdyFuxe+g gjdxzRMNGU+WvGcUDk4iszsqlhs49M+dPmg9KfVelWtfkabZk2oXYYd9YpeMab3UZ4njI9q0Q4ZZU F7vgfH55AZpw4G/8sdlxJ8JgwuUsmWQP3HGbwDjfizCxeUz6/ObUPi/OiHKg5vc+kj58bHHwgmAjB vmUAvK31eNP6q4+q0Of6jyMAjs9FcERhwlunAXhdyZq6GpNDXQxWMSXyhl99rUfP2GLlHoxw7NiTz Tux6TBnw==; Received: from authenticated-user by stravinsky.debian.org with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.96) (envelope-from ) id 1xYPqN-000q8r-13; Tue, 01 Dec 2026 15:32:36 +0000 From: Shih-Yuan Lee To: Takashi Iwai , Jaroslav Kysela Cc: Shih-Yuan Lee , linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 1/2] ALSA: hda/cs420x: Add CS4208 TDM speaker fixup for MacBook8,1 Date: Tue, 1 Dec 2026 23:32:12 +0800 Message-Id: <20261201153214.25157-2-fourdollars@debian.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20261201153214.25157-1-fourdollars@debian.org> References: <20261201153214.25157-1-fourdollars@debian.org> X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Debian-User: fourdollars The 12-inch MacBook (MacBook8,1, codec SSID 0x106b:0x6400) drives four Maxim MAX98357B Class-D TDM digital speaker amplifiers via CS4208 digital pin 0x1d (converter 0x0a) enabled through codec GPIO0. The two left amplifiers latch TDM slot 4 (ch 0) and the two right amplifiers latch slot 12 (ch 1), while slots 0 and 16 (ch 2/ch 3) are unused. Add a CS4208_MB81 fixup that: - Applies explicit MacBook8,1 pin defaults with pin 0x1d retasked as a fixed internal digital output (0x904600f0). - Constrains the digital playback PCM (paired with ALSA UCM2 SplitPCM for stereo speaker routing) to the 4-channel, 44.1 kHz, S16_LE TDM frame format (0x4013) with a { FL, FR, NA, NA } channel map so userspace does not treat it as 4.0 surround. - Programs the Boot Camp CONF_0807 NID 0x24 TDM and A1 combo-jack coefficients directly on init/resume (instead of cs4208_coef_init_verbs) and sets the converter channel count (AC_VERB_SET_CVT_CHAN_COUNT) on stream prepare. - Enables the parsed digital speaker converter before control creation so IEC958 starts unmuted, and disables analog-to-SPDIF stream sharing so analog headphone playback cannot cross-route onto or clamp against the 4ch TDM converter. - Serializes GPIO0 speaker amplifier power updates under gpio_mutex across init, resume, and headphone jack plug/unplug events. Link: https://bugzilla.kernel.org/show_bug.cgi?id=110561 Signed-off-by: Shih-Yuan Lee --- Documentation/sound/hd-audio/models.rst | 2 + sound/hda/codecs/cirrus/cs420x.c | 273 +++++++++++++++++++++++- 2 files changed, 270 insertions(+), 5 deletions(-) diff --git a/Documentation/sound/hd-audio/models.rst b/Documentation/sound/hd-audio/models.rst index 120430450014..edcc71f9b956 100644 --- a/Documentation/sound/hd-audio/models.rst +++ b/Documentation/sound/hd-audio/models.rst @@ -800,6 +800,8 @@ mbp11 MacBookPro 11,2 macmini MacMini 7,1 +mb81 + MacBook 8,1 (12-inch Retina) auto BIOS setup (default) diff --git a/sound/hda/codecs/cirrus/cs420x.c b/sound/hda/codecs/cirrus/cs420x.c index 85c2ecf46d38..236a624735ed 100644 --- a/sound/hda/codecs/cirrus/cs420x.c +++ b/sound/hda/codecs/cirrus/cs420x.c @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -17,6 +18,10 @@ #include "hda_jack.h" #include "../generic.h" +struct cs4208_mb81_data { + struct mutex gpio_mutex; /* serializes jack-to-GPIO updates */ +}; + struct cs_spec { struct hda_gen_spec gen; @@ -31,6 +36,9 @@ struct cs_spec { /* for MBP SPDIF control */ int (*spdif_sw_put)(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol); + + /* for MacBook 8,1 TDM digital speakers (NULL on other models) */ + struct cs4208_mb81_data *mb81; }; /* available models with CS420x */ @@ -118,12 +126,55 @@ static inline void cs_vendor_coef_set(struct hda_codec *codec, unsigned int idx, * HP/SPK/SPDIF */ +static hda_nid_t cs4208_mb81_hp_pin(struct hda_codec *codec) +{ + struct cs_spec *spec = codec->spec; + const struct auto_pin_cfg *cfg = &spec->gen.autocfg; + + if (cfg->hp_outs) + return cfg->hp_pins[0]; + if (cfg->line_outs && cfg->line_out_type == AUTO_PIN_HP_OUT) + return cfg->line_out_pins[0]; + return 0; +} + +static bool cs4208_mb81_hp_present(struct hda_codec *codec) +{ + hda_nid_t hp_pin = cs4208_mb81_hp_pin(codec); + + return hp_pin && snd_hda_jack_detect(codec, hp_pin); +} + +static void cs4208_mb81_update_gpio(struct hda_codec *codec, bool write_mask) +{ + struct cs_spec *spec = codec->spec; + struct cs4208_mb81_data *mb81 = spec->mb81; + bool hp_present; + + mutex_lock(&mb81->gpio_mutex); + hp_present = cs4208_mb81_hp_present(codec); + spec->gpio_data = hp_present ? + spec->gpio_eapd_hp : spec->gpio_eapd_speaker; + if (write_mask) + snd_hda_codec_set_gpio(codec, spec->gpio_mask, spec->gpio_dir, + spec->gpio_data, 0); + else + snd_hda_codec_write(codec, 0x01, 0, + AC_VERB_SET_GPIO_DATA, spec->gpio_data); + mutex_unlock(&mb81->gpio_mutex); +} + static void cs_automute(struct hda_codec *codec) { struct cs_spec *spec = codec->spec; snd_hda_gen_update_outputs(codec); + if (spec->mb81) { + cs4208_mb81_update_gpio(codec, false); + return; + } + if (spec->gpio_eapd_hp || spec->gpio_eapd_speaker) { if (spec->gen.automute_speaker) spec->gpio_data = spec->gen.hp_jack_present ? @@ -193,6 +244,34 @@ static const struct hda_verb cs4208_coef_init_verbs[] = { {} /* terminator */ }; +/* + * MacBook 8,1 NID 0x24 vendor coefficients (from Apple Boot Camp CONF_0807): + * configures the 4-channel TDM speaker link on TX1 (CIR 0x00/0x03/0x04/0x05/ + * 0x1f/0x36) and board-specific A1 combo-jack sense parameters (CIR 0x33/0x34) + * in place of the generic cs4208_coef_init_verbs sequence. + */ +static const struct hda_verb cs4208_mb81_coef_verbs[] = { + {0x01, AC_VERB_SET_POWER_STATE, 0x00}, /* AFG: D0 */ + {0x24, AC_VERB_SET_PROC_STATE, 0x01}, /* VPW: processing on */ + {0x24, AC_VERB_SET_COEF_INDEX, 0x0000}, + {0x24, AC_VERB_SET_PROC_COEF, 0x00c4}, /* ASP/TDM master & frame config */ + {0x24, AC_VERB_SET_COEF_INDEX, 0x0003}, + {0x24, AC_VERB_SET_PROC_COEF, 0x0baa}, /* TX1/RX1 TDM slot format */ + {0x24, AC_VERB_SET_COEF_INDEX, 0x0004}, + {0x24, AC_VERB_SET_PROC_COEF, 0x0c04}, /* TX1 ch 0: slot 4, ch 1: slot 12 */ + {0x24, AC_VERB_SET_COEF_INDEX, 0x0005}, + {0x24, AC_VERB_SET_PROC_COEF, 0x1000}, /* TX1 ch 2: slot 0, ch 3: slot 16 */ + {0x24, AC_VERB_SET_COEF_INDEX, 0x001f}, + {0x24, AC_VERB_SET_PROC_COEF, 0x0000}, /* ASP/digital routing control */ + {0x24, AC_VERB_SET_COEF_INDEX, 0x0033}, + {0x24, AC_VERB_SET_PROC_COEF, 0x0821}, /* A1 ICS (MB8,1 combo jack) */ + {0x24, AC_VERB_SET_COEF_INDEX, 0x0034}, + {0x24, AC_VERB_SET_PROC_COEF, 0x3b21}, /* A1 Enable/threshold (MB8,1) */ + {0x24, AC_VERB_SET_COEF_INDEX, 0x0036}, + {0x24, AC_VERB_SET_PROC_COEF, 0x0034}, /* ASP clock/interface config */ + {} /* terminator */ +}; + /* Errata: CS4207 rev C0/C1/C2 Silicon * * http://www.cirrus.com/en/pubs/errata/ER880C3.pdf @@ -259,12 +338,17 @@ static int cs_init(struct hda_codec *codec) snd_hda_sequence_write(codec, cs_errata_init_verbs); snd_hda_sequence_write(codec, cs_coef_init_verbs); } else if (spec->vendor_nid == CS4208_VENDOR_NID) { - snd_hda_sequence_write(codec, cs4208_coef_init_verbs); + if (spec->mb81) + snd_hda_sequence_write(codec, cs4208_mb81_coef_verbs); + else + snd_hda_sequence_write(codec, cs4208_coef_init_verbs); } snd_hda_gen_init(codec); - if (spec->gpio_mask) + if (spec->mb81) + cs4208_mb81_update_gpio(codec, true); + else if (spec->gpio_mask) snd_hda_codec_set_gpio(codec, spec->gpio_mask, spec->gpio_dir, spec->gpio_data, 0); @@ -558,6 +642,7 @@ enum { CS4208_MBA6, CS4208_MBP11, CS4208_MACMINI, + CS4208_MB81, CS4208_GPIO0, }; @@ -566,6 +651,7 @@ static const struct hda_model_fixup cs4208_models[] = { { .id = CS4208_MBA6, .name = "mba6" }, { .id = CS4208_MBP11, .name = "mbp11" }, { .id = CS4208_MACMINI, .name = "macmini" }, + { .id = CS4208_MB81, .name = "mb81" }, {} }; @@ -577,6 +663,7 @@ static const struct hda_quirk cs4208_fixup_tbl[] = { /* codec SSID matching */ static const struct hda_quirk cs4208_mac_fixup_tbl[] = { SND_PCI_QUIRK(0x106b, 0x5e00, "MacBookPro 11,2", CS4208_MBP11), + SND_PCI_QUIRK(0x106b, 0x6400, "MacBook 8,1", CS4208_MB81), SND_PCI_QUIRK(0x106b, 0x6c00, "MacMini 7,1", CS4208_MACMINI), SND_PCI_QUIRK(0x106b, 0x7100, "MacBookAir 6,1", CS4208_MBA6), SND_PCI_QUIRK(0x106b, 0x7200, "MacBookAir 6,2", CS4208_MBA6), @@ -663,6 +750,167 @@ static void cs4208_fixup_spdif_switch(struct hda_codec *codec, } } +static const struct hda_pcm_stream cs4208_mb81_dig_playback = { + .channels_min = 4, + .channels_max = 4, + .rates = SNDRV_PCM_RATE_44100, + .formats = SNDRV_PCM_FMTBIT_S16_LE, + .maxbps = 16, +}; + +/* + * Although the TDM frame carries 4 slots, the two left-side MAX98357B amps + * both latch slot 4 (ch 0 = FL) and the two right-side amps latch slot 12 + * (ch 1 = FR); slots 0 and 16 (ch 2/ch 3) are unused. Mark ch 2/ch 3 NA so + * userspace treats the speakers as stereo rather than 4.0 surround. + */ +static const struct snd_pcm_chmap_elem cs4208_mb81_chmaps[] = { + { .channels = 4, + .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, + SNDRV_CHMAP_NA, SNDRV_CHMAP_NA } }, + { } +}; + +static int cs4208_mb81_dig_playback_prepare(struct hda_pcm_stream *hinfo, + struct hda_codec *codec, + unsigned int stream_tag, + unsigned int format, + struct snd_pcm_substream *substream) +{ + struct cs_spec *spec = codec->spec; + int err; + + err = snd_hda_multi_out_dig_prepare(codec, &spec->gen.multiout, + stream_tag, format, substream); + if (err < 0) + return err; + + snd_hda_codec_write(codec, hinfo->nid, 0, AC_VERB_SET_CVT_CHAN_COUNT, + substream->runtime->channels - 1); + return 0; +} + +static void cs4208_mb81_hp_cb(struct hda_codec *codec, + struct hda_jack_callback *cb) +{ + cs_automute(codec); +} + +/* + * MacBook 8,1 drives 4x MAX98357B TDM digital speaker amplifiers via + * digital pin 0x1d (converter 0x0a) enabled by GPIO0. + */ +static void cs4208_fixup_mb81(struct hda_codec *codec, + const struct hda_fixup *fix, int action) +{ + static const struct hda_pintbl pincfgs[] = { + { 0x10, 0x002b4020 }, /* Headphone */ + { 0x11, 0x400000f0 }, + { 0x12, 0x400000f0 }, + { 0x13, 0x400000f0 }, + { 0x14, 0x400000f0 }, + { 0x15, 0x400000f0 }, + { 0x16, 0x400000f0 }, + { 0x17, 0x400000f0 }, + { 0x18, 0x00ab9030 }, /* Headset Mic */ + { 0x19, 0x90a60100 }, /* Internal Mic */ + { 0x1a, 0x400000f0 }, + { 0x1b, 0x400000f0 }, + { 0x1c, 0x400000f0 }, + { 0x1d, 0x904600f0 }, /* Internal TDM speaker digital out */ + { 0x1e, 0x400000f0 }, + { 0x1f, 0x400000f0 }, + { 0x20, 0x400000f0 }, + { 0x21, 0x400000f0 }, + { 0x22, 0x400000f0 }, + { } + }; + struct cs_spec *spec = codec->spec; + struct cs4208_mb81_data *mb81; + struct hda_jack_callback *cb; + struct snd_kcontrol *kctl; + hda_nid_t hp_pin, dig_nid; + + switch (action) { + case HDA_FIXUP_ACT_PRE_PROBE: + mb81 = kzalloc_obj(*mb81); + if (!mb81) { + codec_err(codec, + "Failed to allocate MacBook 8,1 fixup data\n"); + return; + } + mutex_init(&mb81->gpio_mutex); + spec->mb81 = mb81; + snd_hda_apply_pincfgs(codec, pincfgs); + spec->gen.stream_digital_playback = &cs4208_mb81_dig_playback; + spec->gpio_eapd_hp = 0; + spec->gpio_eapd_speaker = 1; + spec->gpio_mask = 0x01; /* GPIO0 (speaker amp enable) */ + spec->gpio_dir = 0x01; /* GPIO0 output */ + spec->gpio_data = spec->gpio_eapd_speaker; + break; + case HDA_FIXUP_ACT_PROBE: + if (!spec->mb81) + return; + hp_pin = cs4208_mb81_hp_pin(codec); + if (hp_pin) { + cb = snd_hda_jack_detect_enable_callback(codec, hp_pin, + cs4208_mb81_hp_cb); + if (IS_ERR(cb)) + codec_warn(codec, + "Failed to register HP jack callback: %pe\n", + cb); + } + /* + * Enable the digital speaker converter before control build so + * IEC958 starts unmuted; upper byte sets DIGI_CONVERT_2 (0x01) + * matching Apple firmware. + */ + dig_nid = spec->gen.multiout.dig_out_nid; + if (dig_nid) + snd_hda_codec_write_cache(codec, dig_nid, 0, + AC_VERB_SET_DIGI_CONVERT_1, + AC_DIG1_ENABLE | + AC_DIG1_COPYRIGHT | + (0x01 << 8)); + break; + case HDA_FIXUP_ACT_BUILD: + if (!spec->mb81) + return; + /* + * Never mirror 2-channel analog HP playback onto the 4-channel + * TDM speaker converter or clamp HP stream capabilities to it. + */ + spec->gen.multiout.share_spdif = 0; + kctl = snd_hda_find_mixer_ctl(codec, + "IEC958 Default PCM Playback Switch"); + if (kctl) + kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_WRITE; + break; + } +} + +static int cs_build_pcms(struct hda_codec *codec) +{ + struct cs_spec *spec = codec->spec; + int err; + + err = snd_hda_gen_build_pcms(codec); + if (err < 0) + return err; + + if (spec->mb81 && spec->gen.pcm_rec[1] && + spec->gen.multiout.dig_out_nid) { + struct hda_pcm_stream *hinfo = + &spec->gen.pcm_rec[1]->stream[SNDRV_PCM_STREAM_PLAYBACK]; + + hinfo->chmap = cs4208_mb81_chmaps; + hinfo->ops.prepare = cs4208_mb81_dig_playback_prepare; + } + + return 0; +} + static const struct hda_fixup cs4208_fixups[] = { [CS4208_MBA6] = { .type = HDA_FIXUP_PINS, @@ -682,6 +930,10 @@ static const struct hda_fixup cs4208_fixups[] = { .chained = true, .chain_id = CS4208_GPIO0, }, + [CS4208_MB81] = { + .type = HDA_FIXUP_FUNC, + .v.func = cs4208_fixup_mb81, + }, [CS4208_GPIO0] = { .type = HDA_FIXUP_FUNC, .v.func = cs4208_fixup_gpio0, @@ -730,6 +982,17 @@ static int cs4208_probe(struct hda_codec *codec) return 0; } +static void cs_remove(struct hda_codec *codec) +{ + struct cs_spec *spec = codec->spec; + + if (spec) { + kfree(spec->mb81); + spec->mb81 = NULL; + } + snd_hda_gen_remove(codec); +} + static int cs_codec_probe(struct hda_codec *codec, const struct hda_device_id *id) { @@ -746,15 +1009,15 @@ static int cs_codec_probe(struct hda_codec *codec, else err = cs420x_probe(codec); if (err < 0) - snd_hda_gen_remove(codec); + cs_remove(codec); return err; } static const struct hda_codec_ops cs_codec_ops = { .probe = cs_codec_probe, - .remove = snd_hda_gen_remove, + .remove = cs_remove, .build_controls = cs_build_controls, - .build_pcms = snd_hda_gen_build_pcms, + .build_pcms = cs_build_pcms, .init = cs_init, .unsol_event = snd_hda_jack_unsol_event, .stream_pm = snd_hda_gen_stream_pm, -- 2.39.5