Skip to content

Latest commit

 

History

History
168 lines (130 loc) · 9.5 KB

cs4216.md

File metadata and controls

168 lines (130 loc) · 9.5 KB

Crystal CS4216 Stereo Audio Codec — Hardware Reference and HAL2 Wiring

The SGI Indy (IP24) and Indigo2 (IP22/IP26/IP28) audio subsystem uses two Crystal Semiconductor CS4216 16-bit stereo Multimedia Audio Codecs (Codec A and Codec B) connected to the HAL2 ASIC, paired with an external 8-bit Multiplying DAC (MDAC) for speaker and headphone volume control.


Key Architectural Facts

  1. No $I^2C$ or Host Microprocessor Bus (Mode 3, PB/SB = 1): Although the CS4216 supports a parallel microprocessor port (PB/SB = 0) and a serial command port (CCLK/CDIN/CDOUT), the Indy and Indigo2 audio section hardwires the codecs to Serial Mode 3 Slave (SM3-Slave): PB/SB = 1 (serial control), CM0 = 1, CM1 = 1 (Mode 3), MS/SL = 0 (Slave). All codec control and status words travel in-band inside the 64-bit time-division multiplexed (TDM) serial audio frame between HAL2 and the CS4216 (SDIN and SDOUT).

  2. Clocking is Driven by HAL2, Not by the Codec: In SM3-Slave mode, the CS4216's CLKIN (master oversampling clock, $256 \times F_s$), SCLK (serial bit clock, $64 \times F_s$), and SSYNC (frame sync, $1 \times F_s$) pins are all inputs driven by HAL2's Bresenham clock generators (BRES1–BRES3). Two crystal oscillators on the board (24.576 MHz = $512 \times 48,\text{kHz}$ and 22.5792 MHz = $512 \times 44.1,\text{kHz}$) plus the recovered AES receiver clock feed HAL2, which synthesizes the codec clocks.

  3. Two-Stage Output Volume Architecture:

    • Line Out is driven directly by the CS4216 DAC outputs. The CS4216 has an internal 5-bit digital attenuator (LA4:0 and RA4:0 in Control Word 1, $1.5,\text{dB}$ per step from $0.0,\text{dB}$ to $-46.5,\text{dB}$) and a MUTE bit (Control Word 0 bit 10). Under IRIX (a2_dd.o), Line Out has a fixed $0.0,\text{dB}$ gain range and leaves LA = 0, RA = 0, MUTE = 0.
    • Headphone and Internal Speaker Out pass through an external 8-bit Multiplying DAC (MDAC) mapped directly on HPC3 PBUS PIO Channel 2 at 0x1FBD8800 (VOLUME_RIGHT) and 0x1FBD8804 (VOLUME_LEFT). The IP22/IP28 PROM startup chime, the IRIX kernel audio driver (a2_dd.o), the front-panel volume buttons, and NetBSD (haltwo) all control output volume through these two 8-bit registers.

Serial Mode 3 (SM3) 64-Bit Frame Format

Each sample period ($1 / F_s$) consists of 64 SCLK cycles divided into eight 8-bit time slots (Slot 1 through Slot 8) following the rising edge of SSYNC:

Bits Time Slot SDIN (HAL2 $\to$ CS4216 DAC + Control) SDOUT (CS4216 ADC + Status $\to$ HAL2)
63:48 Slots 1–2 Left DAC PCM (16-bit signed, MSB first) Left ADC PCM (16-bit signed, MSB first)
47:40 Slot 3 Low 8 bits of 24-bit Left PCM (ignored by 16-bit CS4216) 0x00 (stuffing bits)
39:32 Slot 4 Control Word 0 upper byte (IDR0[15:8]) Status Word upper byte (ER3:0, REV3:0)
31:16 Slots 5–6 Right DAC PCM (16-bit signed, MSB first) Right ADC PCM (16-bit signed, MSB first)
15:8 Slot 7 Control Word 0 lower byte (IDR0[7:0]) Status Word lower byte (ADV, LCL, RCL)
7:0 Slot 8 Control Word 1 (IDR1) 0x00 (stuffing bits)

HAL2 packs the 28-bit CS4216 control payload across two 16-bit indirect data registers (IDR0 and IDR1) committed via HAL2_CODECA_CTRL2_W (0x1408) or HAL2_CODECB_CTRL2_W (0x1508), and transmits those control bits in every serial frame alongside the DMA audio samples.


Control Registers (HAL2_CODECx_CTRL2_W: 0x1408 / 0x1508)

Control Word 0 (IDR0, 16 bits)

Bits Field Description
15:11 0 Reserved (written as 0)
10 MUTE DAC Output Mute: 1 = mute both Left and Right DAC outputs; 0 = normal operation
9:8 ISL1:0 (ISR1:0) ADC Input Mux Select (Left and Right tied together in HAL2):
0 = Line 1
1 = Line 2 / Synth (Indigo2 MAUI synthesizer feed)
2 = Line 3
3 = Line 4 / Microphone
7:4 LG3:0 Left ADC Input Gain: 4-bit unsigned (0..15), $+1.5,\text{dB}$ per step ($0.0,\text{dB}$ to $+22.5,\text{dB}$)
3:0 RG3:0 Right ADC Input Gain: 4-bit unsigned (0..15), $+1.5,\text{dB}$ per step ($0.0,\text{dB}$ to $+22.5,\text{dB}$)

Control Word 1 (IDR1, 12 active bits [11:0])

Bits Field Description
11:7 LA4:0 Left DAC Output Attenuation: 5-bit unsigned (0..31), $-1.5,\text{dB}$ per step ($0.0,\text{dB}$ to $-46.5,\text{dB}$)
6:2 RA4:0 Right DAC Output Attenuation: 5-bit unsigned (0..31), $-1.5,\text{dB}$ per step ($0.0,\text{dB}$ to $-46.5,\text{dB}$)
1 DO2 Digital Output Pin 2 (controls external microphone preamp gain):
1 = $1\times$ ($0,\text{dB}$) preamp gain (Line / standard Mic)
0 = $10\times$ ($+20,\text{dB}$) microphone preamp boost enabled
0 DO1 Digital Output Pin 1 (controls microphone phantom bias):
1 = Microphone bias off (Line input)
0 = Microphone bias on

Common DO2:DO1 (IDR1[1:0]) combinations used by IRIX (a2_dd.o) and ARCS diagnostics (a2diags.c):

  • 0x03 (DO2=1, DO1=1): Line input, $1\times$ preamp, mic bias off.
  • 0x01 (DO2=0, DO1=1): Microphone input, $1\times$ preamp ($0$ to $+22.5,\text{dB}$ via LG/RG).
  • 0x00 (DO2=0, DO1=0): Microphone input with $+20,\text{dB}$ ($10\times$) analog preamp enabled (used by IRIX when requested input gain exceeds $+20.0,\text{dB}$, giving $+20.0,\text{dB}$ to $+42.5,\text{dB}$ total input gain).

Status Word (Non-Audio Mode on HAL2_CODECB_CTRL1_W bit 7)

When bit 7 (0x0080) of HAL2_CODECB_CTRL1_W (0x1504) is set, HAL2 replaces every second 32-bit DMA word on the Codec B record channel with the CS4216 non-audio status word captured from SDOUT Slots 4 and 7:

Bits (32-bit DMA word) Symbol Description
31:28 HAL2_NAB_ERROR (ER3:0) CS4216 framing/clock error code (0 = no error, 1 = SSYNC early, 2 = SSYNC late, 3 = CLKIN/SSYNC ratio error)
27:24 HAL2_NAB_REVISION (REV3:0) CS4216 silicon revision (0x1 = Revision B/C)
3 HAL2_NAB_VALID (ADV) 1 = ADC data valid (calibration complete, not muted)
2 HAL2_NAB_LEFT_CLIP (LCL) 1 = Left ADC clipping detected
1 HAL2_NAB_RIGHT_CLIP (RCL) 1 = Right ADC clipping detected

Dual-Codec Roles and 4-Channel Mode (ISR.CODEC_MODE)

The two CS4216 codecs on the board are wired asymmetrically in normal operation and combined in 4-channel mode:

Mode ISR bit 2 (CODEC_MODE) Codec A Role Codec B Role
Indigo / Stereo Mode (default) 0 DAC (Analog Output: Line Out + Headphone/Speaker Out via MDAC) ADC (Analog Input: Line In / Mic In / Synth In)
Quad / 4-Channel Mode 1 Codec 1 DAC + ADC (Front Left/Right Out + Input pair 1) Codec 2 DAC + ADC (Rear Left/Right Out + Input pair 2)

In 4-channel mode (CODEC_MODE = 1), both CS4216 chips share the same serial frame sync, so IRIX switches the analog input device from BRES1 (cg1) to BRES2 (cg2, the analog output clock generator) to keep both codecs phase-locked to a single sample rate.


External 8-Bit Multiplying DAC (MDAC) Volume Control

Physical addresses on HPC3 PBUS PIO Channel 2:

Physical Address HPC3 Offset Name Description
0x1FBD8800 0x58800 VOLUME_RIGHT 8-bit unsigned Right Headphone/Speaker volume (0x00 = muted, 0xFF = maximum)
0x1FBD8804 0x58804 VOLUME_LEFT 8-bit unsigned Left Headphone/Speaker volume (0x00 = muted, 0xFF = maximum)

Linear-Voltage / Logarithmic-dB Mapping

The MDAC attenuates the analog signal linearly with the 8-bit register value $V \in [0, 255]$:

$$\text{Gain}_{\text{linear}}(V) = \frac{V}{255}, \qquad \text{Gain}_{\text{dB}}(V) = 20 \log_{10}!\left(\frac{V}{240}\right) \text{ for } V \ge 1$$

The linear gain is relative to full scale ($V = 255$), which is what the emulator applies to the samples; the decibel figure is relative to the level IRIX treats as nominal unity ($V = 240$).

  • $V = 0$: $-\infty,\text{dB}$ (completely muted).
  • $V = 1$: $-47.6,\text{dB}$ ($-48.13,\text{dB}$ below $V = 255$).
  • $V = 64$ (0x40): $-11.5,\text{dB}$ (IRIX default speaker volume at driver init).
  • $V = 240$ (0xF0): $0.0,\text{dB}$ nominal unity reference in IRIX AL_GAIN.
  • $V = 255$ (0xFF): $+0.53,\text{dB}$ maximum output.

Dezippering and Front-Panel Volume Buttons in IRIX

In IRIX (a2_dd.o):

  • Setting AL_GAIN or AL_MUTE on the speaker/headphone interface (or pressing the front-panel volume/mute buttons, which invoke hal2_volumectrl from the IP22/IP24 volume button interrupt handler) sets a target 0..255 MDAC level (0 when muted) and marks dezipper_active = 1.
  • On each hal2_update_subsys tick, dezipper_output_atten steps the current left and right register values toward the target using a 256-entry exponential step table (zippertab) and writes the updated bytes to 0x1FBD8804 (VOLUME_LEFT) and 0x1FBD8800 (VOLUME_RIGHT) to prevent audible clicks ("zipper noise").