Nicholas Sudsgaard has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/80332?usp=email )
Change subject: device/azalia: Cleanup codec initialization code ......................................................................
device/azalia: Cleanup codec initialization code
azalia_codec_init() was doing too much in one function.
This also changes how debug messages will be printed. I focused on reducing clutter on the screen and made the style of the messages consistent.
Before: azalia_audio: Initializing codec #5 codec not ready. azalia_audio: Initializing codec #4 codec not valid. azalia_audio: Initializing codec #3 azalia_audio: viddid: ffffffff azalia_audio: verb_size: 4 azalia_audio: verb loaded.
After: azalia_audio: codec #5 not ready azalia_audio: codec #4 not valid azalia_audio: initializing codec #3... azalia_audio: - vendor/device id: 0xffffffff azalia_audio: - verb size: 4 azalia_audio: - verb loaded
Change-Id: I92b6d184abccdbe0e1bfce98a2c959a97a618a29 Signed-off-by: Nicholas Sudsgaard devel+coreboot@nsudsgaard.com --- M src/device/azalia_device.c M src/include/device/azalia_device.h 2 files changed, 51 insertions(+), 37 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/32/80332/1
diff --git a/src/device/azalia_device.c b/src/device/azalia_device.c index 4ac585d..298ceb2 100644 --- a/src/device/azalia_device.c +++ b/src/device/azalia_device.c @@ -6,6 +6,7 @@ #include <device/azalia_device.h> #include <device/mmio.h> #include <delay.h> +#include <stdbool.h> #include <timer.h>
int azalia_set_bits(void *port, u32 mask, u32 val) @@ -97,7 +98,7 @@ /* Codec Not found */ /* Put HDA back in reset (BAR + 0x8) [0] */ azalia_set_bits(base + HDA_GCTL_REG, 1, 0); - printk(BIOS_DEBUG, "azalia_audio: No codec!\n"); + printk(BIOS_DEBUG, "azalia_audio: no codec!\n"); return 0; }
@@ -226,56 +227,67 @@ { }
-void azalia_codec_init(u8 *base, int addr, const u32 *verb_table, u32 verb_table_bytes) +static bool codec_is_operative(u8 *base, const int addr) { - u32 reg32; - const u32 *verb; - u32 verb_size; - - printk(BIOS_DEBUG, "azalia_audio: Initializing codec #%d\n", addr); - - /* 1 */ if (wait_for_ready(base) < 0) { - printk(BIOS_DEBUG, " codec not ready.\n"); - return; + printk(BIOS_DEBUG, "azalia_audio: codec #%d not ready\n", addr); + return false; }
- reg32 = (addr << 28) | 0x000f0000; + const u32 reg32 = (addr << 28) | 0x000f0000; write32(base + HDA_IC_REG, reg32);
if (wait_for_valid(base) < 0) { - printk(BIOS_DEBUG, " codec not valid.\n"); - return; + printk(BIOS_DEBUG, "azalia_audio: codec #%d not valid\n", addr); + return false; } + return true; +}
- /* 2 */ - reg32 = read32(base + HDA_IR_REG); - printk(BIOS_DEBUG, "azalia_audio: codec viddid: %08x\n", reg32); - verb_size = azalia_find_verb(verb_table, verb_table_bytes, reg32, &verb); +static u32 get_verb(const u32 *verb_table, u32 verb_table_bytes, const u32 viddid, const u32 **verb) +{ + const u32 verb_size = azalia_find_verb(verb_table, verb_table_bytes, viddid, verb);
- if (!verb_size) { - printk(BIOS_DEBUG, "azalia_audio: No verb!\n"); - return; + if (verb_size == 0) { + printk(BIOS_DEBUG, "azalia_audio: - no verb!\n"); + return 0; } - printk(BIOS_DEBUG, "azalia_audio: verb_size: %u\n", verb_size); + printk(BIOS_DEBUG, "azalia_audio: - verb size: %u\n", verb_size); + return verb_size; +}
- /* 3 */ - const int rc = azalia_program_verb_table(base, verb, verb_size); - if (rc < 0) - printk(BIOS_DEBUG, "azalia_audio: verb not loaded.\n"); - else - printk(BIOS_DEBUG, "azalia_audio: verb loaded.\n"); +static void load_verb(u8 *base, const u32 *verb, const u32 verb_size) +{ + if (azalia_program_verb_table(base, verb, verb_size) < 0) { + printk(BIOS_DEBUG, "azalia_audio: - verb not loaded\n"); + } else { + printk(BIOS_DEBUG, "azalia_audio: - verb loaded\n"); + } +}
- mainboard_azalia_program_runtime_verbs(base, reg32); +void azalia_codec_init(u8 *base, int addr, const u32 *verb_table, u32 verb_table_bytes) +{ + const u32 viddid = read32(base + HDA_IR_REG); + const u32 *verb; + u32 verb_size; + + printk(BIOS_DEBUG, "azalia_audio: initializing codec #%d...\n", addr); + printk(BIOS_DEBUG, "azalia_audio: - vendor/device id: 0x%08x\n", viddid); + + verb_size = get_verb(verb_table, verb_table_bytes, viddid, &verb); + if (verb_size == 0) return; + load_verb(base, verb, verb_size); + + mainboard_azalia_program_runtime_verbs(base, viddid); }
void azalia_codecs_init(u8 *base, u16 codec_mask) { - int i; - - for (i = 14; i >= 0; i--) { - if (codec_mask & (1 << i)) + for (int i = AZALIA_MAX_CODECS - 1; i >= 0; i--) { + if (codec_mask & (1 << i)) { + if (!codec_is_operative(base, i)) continue; azalia_codec_init(base, i, cim_verb_data, cim_verb_data_size); + } }
azalia_program_verb_table(base, pc_beep_verbs, pc_beep_verbs_size); @@ -298,7 +310,7 @@ codec_mask = codec_detect(base);
if (codec_mask) { - printk(BIOS_DEBUG, "azalia_audio: codec_mask = %02x\n", codec_mask); + printk(BIOS_DEBUG, "azalia_audio: codec_mask = 0x%02x\n", codec_mask); azalia_codecs_init(base, codec_mask); } } diff --git a/src/include/device/azalia_device.h b/src/include/device/azalia_device.h index 1562e25..24e2644 100644 --- a/src/include/device/azalia_device.h +++ b/src/include/device/azalia_device.h @@ -10,13 +10,15 @@
#define HDA_GCAP_REG 0x00 #define HDA_GCTL_REG 0x08 -#define HDA_GCTL_CRST (1 << 0) +#define HDA_GCTL_CRST (1 << 0) #define HDA_STATESTS_REG 0x0e #define HDA_IC_REG 0x60 #define HDA_IR_REG 0x64 #define HDA_ICII_REG 0x68 -#define HDA_ICII_BUSY (1 << 0) -#define HDA_ICII_VALID (1 << 1) +#define HDA_ICII_BUSY (1 << 0) +#define HDA_ICII_VALID (1 << 1) + +#define AZALIA_MAX_CODECS 15
int azalia_set_bits(void *port, u32 mask, u32 val); int azalia_enter_reset(u8 *base);