Skip to content

iPad 6 and 7: headphone jack (CS42L83 on MCA4) - #131

Open
jerricky26 wants to merge 1 commit into
OrchardLinux:mainfrom
jerricky26:j171-headphones
Open

jerricky26 wants to merge 1 commit into
OrchardLinux:mainfrom
jerricky26:j171-headphones

Conversation

@jerricky26

Copy link
Copy Markdown
Contributor

This adds the headphone jack to the shared iPad 6 and 7 card: a CS42L83 on i2c0, fed by MCA4 in I2S. Rebased onto main 71502a0 (Release 0.3.0).

Changes

  • kernel/patches/devices/t8010/0022: shared t8010-ipad6.dtsi, and MCA4 in t8010.dtsi. The codec is at i2c0 0x48, reset on AP GPIO 25, jack IRQ on AP GPIO 71. A second dai-link in i2s uses MCA4 as clock provider, and the codec is an aux-dev so simple-audio-card creates its jack. The speaker link stays dai-link 0 / PCM 0; the headphones are PCM 1. cirrus,ts-inv = 1, as on Apple's other CS42L83 boards. The ADT's AOP MCLK (AOP GPIO 36) is left unused; the codec runs its PLL from SCLK.

  • devices/t8010/0023: the AOP i2s-switch and pad output-enable syscons, and apple,aop-i2s-route on MCA4. The CS42L83 sits on AOP pads 32-35. The words come from the ADT (function-i2s_route_aop mca1 to pin0, oe 0xf) and were checked live on J171: 0x00010101, 0x00080818, 0xf. Without this route the PLL does not lock, because SCLK never reaches the codec.

  • drivers/sound/0010, 0011: T8010 I2S variant of the MCA driver (apple,t8010-mca-i2s) and its bindings.

  • drivers/soc-apple/0014: expose MCA4's SmartIO TX endpoint 0x30 as a DMA channel. Without it, MCA4's DMA request fails with -ENODEV and the whole card fails to probe.

  • drivers/sound/0012: CS42L42-family jack type, so simple-audio-card creates the codec's jack.

  • drivers/sound/0013, 0015: MCA4 only drives SCLK while TX is enabled, so the I2S variant starts the frame and TX at prepare and keeps both until hw_free, after the codec has left SCLK. These flags are only on t8010_i2s_mca_hw; the speaker TDM path is unchanged.

  • drivers/sound/0014: CS42L42 stays on the oscillator if the PLL does not lock.

  • drivers/sound/0016: MCA can program an apple,aop-i2s-route. It is a no-op on links that lack the property.

  • CONFIG_SND_SOC_CS42L83=m (and CONFIG_SND_SOC_CS42L42_CORE=m).

  • UCM Orchard/ipad6/HiFi.conf: a Headphones device on PCM 1, jack control cs42l83.0-0048-jack Jack, Jack Mixer Volume 43, PlaybackPriority 200, wrapped in If.headphones / ControlExists so a kernel without the link still gets the speakers only.

devices/j171/device.toml is already audio_output = "working" from the speakers work. audio_input stays "missing". This PR does not change the catalog.

ADT evidence

I compared the IPSW ADTs of J71b, J72b, J171 and J172. Everything this uses matches (only phandle numbers differ):

  • CS42L83 at /arm-io/i2c0/audio-codec, address 0x48
  • reset on AP GPIO 25, interrupt on AP GPIO 71
  • MCA4 at 0x20a0b0000/0x4000, MCLK word at 0x20a002010, IRQ 231, clock gate ps_mca4
  • NCO channel 4
  • SmartIO TX endpoint 0x30
  • i2s route aud4 → pin4
  • AOP i2s-switch at 0x210540000 and pad output enable at 0x210000600
  • function-i2s_route_aop mca1 to pin0, aop_i2s_oe_reg_val 0xf
  • function-aop_mclk on AOP GPIO 36 (not used; the PLL is from SCLK)

The AOP route words were also read back from a running J171: MCA1 node 0x00010101, pin0 node 0x00080818, output enable 0xf.

Hardware test (one J171)

I tested this series on official Omarchy A 0.3.0, with a side-by-side boot entry for a kernel built from this branch (a local CONFIG_LOCALVERSION=-hp was used only to keep the stock 0.3.0 kernel as a fallback; it is not in this PR).

  • The card is still "J171 Speakers". PCM 0 is the four-channel speaker TDM (dsp_a, S16_LE). PCM 1 is the headphone I2S link (i2s, S32_LE, 2ch, 48 kHz). The CS42L83 probes as "Cirrus Logic CS42L83, Revision: B0".
  • Plugging wired headphones sets the codec jack (evdev SW_HEADPHONE_INSERT, the ALSA jack control, and the UCM Headphones port). Unplugging clears it. cirrus,ts-inv = 1 is consistent with this plug on J171.
  • A 440 Hz tone through alsa_output.platform-sound.HiFi__Headphones__sink was heard in the headphones. The DAPM playback path (SDIN, MIXER, DAC, HP, ASP DAI0, SCLK) was On, and there was no PLL failed to lock in dmesg. After unplug, a 440 Hz tone was heard on the built-in speakers; PCM 0 and SD_MODE were live. The T8010 I2S clock flags did not break the speaker TDM path.
  • Userspace notes, not part of this PR: official omarchy-a 61-omarchy-a-ipad7-speakers.conf matches alsa.card_name = "J171 Speakers" and forces S16LE/4ch on the whole card, so PipeWire could not open PCM 1 (spa.alsa: hw:Speakers,1p: no format found ... formats:S32_LE). A live override that matches only the Speaker node, plus S32LE/2ch on the headphones node, created the sink. WirePlumber also ranks PCM 0 above PCM 1 by device number, so the default stayed on the speakers until a headphones priority.session of 1100. I'll send those as an omarchy-a follow-up, following the placement from J171: enable the speakers (J71b's TDM link) #100. Official new-sink volume is very low, and the UCM mixer value of 43 is about -20 dB, so a quiet test tone can be inaudible even when the path is running.

Untested: J71b, J72b, and J172; headphone capture / the headset mic; Bluetooth audio at the same time as the jack. A user-saved default (a Bluetooth sink) still wins while it is connected.

Checks

Describe the CS42L83 headphone codec and its MCA4 I2S link as a second
link of the shared iPad 6/7 card (devices/t8010/0022), with a T8010 I2S
variant of the MCA driver (drivers/sound/0010, 0011) and a jack type for
the CS42L42-family driver so simple-audio-card creates the codec's jack
(drivers/sound/0012), and expose MCA4's SmartIO transmit endpoint
0x30 as a T8010 DMA channel (drivers/soc-apple/0014). Enable CONFIG_SND_SOC_CS42L83 as a module.

The UCM gains a Headphones device on PCM 1 with the codec's jack and
mixer volume, at a higher priority than the speakers.

Tested on J171: without the SmartIO endpoint the MCA4 DMA request
fails with -ENODEV and the whole card fails to probe.

Two more pieces get SCLK to the codec (drivers/sound/0015, 0016,
devices/t8010/0023): MCA4 only drives SCLK while TX is enabled, so the
I2S variant enables TX with the frame at prepare and keeps both until
hw_free, after the codec has left SCLK; and the codec sits on AOP pads,
so MCA4 also programs the AOP i2s-switch route the ADT lists
(function-i2s_route_aop 'mca1' to 'pin0', output enable 0xf). On J171
the PLL now locks within a millisecond at prepare and the codec runs
from SCLK for the whole stream, also across an XRUN.

Assisted-by: LLM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant