wb: wait for the MicPGAs' gain flags too before calling the codec up

SLAA557: the PGA soft-steps from mute after power-up; page 0 register
36 D7/D3 say when it has reached the programmed gain. The bring-up now
waits for them with the ADCs' power flags (200 ms at most), and a test
covers a codec whose MicPGAs never get there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013PRsUCpxazyipPn5UGGkF8
This commit is contained in:
Claude committed 2026-10-27 09:39:00 +00:00
1 parent 6d7a5dcda5
commit bce166e430
3 files changed
+13 -4

No files matched your search

+1
View File
@@ -41,6 +41,7 @@
#define AIC0_BCLK_N 30 // D7 power, D6:0 N (0 means 128)
#define AIC0_ADC_FLAGS 36 // D7 left PGA at gain, D6 left ADC up, D3 right PGA, D2 right ADC up
#define AIC0_ADC_FLAGS_UP 0x44
#define AIC0_ADC_FLAGS_PGA 0x88 // both MicPGAs at their programmed gain
#define AIC0_DAC_FLAGS 37 // D7 left DAC up, D5 HPL up, D3 right DAC up, D1 HPR up
#define AIC0_DAC_FLAGS_UP 0xA2 // left DAC, HPL, HPR (the right DAC stays down)
#define AIC0_STICKY1 42 // overflows since the last read: D7/D6 left/right DAC, D3/D2 left/right ADC
+3 -2
View File
@@ -154,11 +154,12 @@ wb_codec_result_t wb_codec_start(const wb_codec_cfg_t *cfg) {
W(0, AIC0_DAC_SETUP1, AIC0_DAC_LEFT_ON | AIC0_DAC_LEFT_DATA);
W(0, AIC0_DAC_VOL_L, cfg->tx_gain);
W(0, AIC0_DAC_SETUP2, AIC0_DAC_MUTE_R);
// both ADCs up, unmuted, 0 dB digital
// both ADCs up, unmuted, 0 dB digital; then all of it up, and the MicPGAs
// at their gain (soft-stepped from mute)
W(0, AIC0_ADC_SETUP, AIC0_ADC_ON);
W(0, AIC0_ADC_FINE, 0x00);
if (!wait_flags(0, AIC0_DAC_FLAGS, AIC0_DAC_FLAGS_UP, POWER_TIMEOUT_MS) ||
!wait_flags(0, AIC0_ADC_FLAGS, AIC0_ADC_FLAGS_UP, POWER_TIMEOUT_MS))
!wait_flags(0, AIC0_ADC_FLAGS, AIC0_ADC_FLAGS_UP | AIC0_ADC_FLAGS_PGA, POWER_TIMEOUT_MS))
return WB_CODEC_POWER_TIMEOUT;
return WB_CODEC_OK;
}
+9 -2
View File
@@ -37,6 +37,7 @@ static struct {
uint8_t page;
bool answers; // I2C: the codec acks
bool hp_never; // the drivers never reach their gain
bool pga_never; // nor the MicPGAs theirs
int hp_delay, hp_reads; // reads of P1 R63 before its flags show
wr_t log[LOG_MAX];
int nlog;
@@ -71,7 +72,8 @@ static void aic_flags(void) {
uint8_t out = aic.reg[1][AIC1_OUT_POWER], dac = aic.reg[0][AIC0_DAC_SETUP1], adc = aic.reg[0][AIC0_ADC_SETUP];
aic.reg[0][AIC0_DAC_FLAGS] = (uint8_t)((dac & 0x80 ? 0x80 : 0) | (dac & 0x40 ? 0x08 : 0) |
(out & AIC1_OUT_HPL ? 0x20 : 0) | (out & AIC1_OUT_HPR ? 0x02 : 0));
aic.reg[0][AIC0_ADC_FLAGS] = (uint8_t)((adc & 0x80 ? 0xC0 : 0) | (adc & 0x40 ? 0x0C : 0));
uint8_t pga = aic.pga_never ? 0x44 : 0xCC;
aic.reg[0][AIC0_ADC_FLAGS] = (uint8_t)(((adc & 0x80 ? 0xC0 : 0) | (adc & 0x40 ? 0x0C : 0)) & pga);
}
static struct {
@@ -394,7 +396,7 @@ TEST(codec_sequence) {
CHECK(wb_codec_loop(false) && aic.reg[0][AIC0_IFACE3] == AIC0_IFACE3_CLKS_ON);
}
// A codec that doesn't answer, or whose drivers never come up: the bring-up
// A codec that doesn't answer, or whose drivers or MicPGAs never come up: the bring-up
// says so (within its timeouts), and the device's requests still work.
TEST(codec_failures) {
board();
@@ -407,6 +409,11 @@ TEST(codec_failures) {
CHECK(wb_codec_start(&cfg) == WB_CODEC_HP_TIMEOUT);
CHECK(fb.now - t0 >= 500 && fb.now - t0 < 600);
CHECK((aic.reg[0][AIC0_DAC_SETUP1] & 0x80) == 0); // no DAC without its drivers
board();
aic.pga_never = true;
t0 = fb.now;
CHECK(wb_codec_start(&cfg) == WB_CODEC_POWER_TIMEOUT);
CHECK(fb.now - t0 >= 200 && fb.now - t0 < 300);
// the device: no codec, no CODEC state; GET_INFO still answers
board();
aic.answers = false;