{soc/intel/common,sb/intel/lynxpoint}/hda_verb.c: Reduce differences

Change-Id: Ie63d7671eb19f0d4c4f67dfe242193e7949afdea
Signed-off-by: Elyes HAOUAS <ehaouas@noos.fr>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/44392
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Patrick Rudolph <siro@das-labor.org>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
This commit is contained in:
Elyes HAOUAS 2020-08-11 16:47:47 +02:00 committed by Patrick Georgi
parent 6ea24ffa8f
commit a3022056a2
2 changed files with 25 additions and 64 deletions

View File

@ -7,9 +7,6 @@
#include "hda_verb.h" #include "hda_verb.h"
/*
* Set bits in a register and wait for status
*/
static int set_bits(void *port, u32 mask, u32 val) static int set_bits(void *port, u32 mask, u32 val)
{ {
u32 reg32; u32 reg32;
@ -22,9 +19,7 @@ static int set_bits(void *port, u32 mask, u32 val)
reg32 |= val; reg32 |= val;
write32(port, reg32); write32(port, reg32);
/* Wait for readback of register to /* Wait for readback of register to match what was just written to it */
* match what was just written to it
*/
count = 50; count = 50;
do { do {
/* Wait 1ms based on BKDG wait time */ /* Wait 1ms based on BKDG wait time */
@ -39,9 +34,6 @@ static int set_bits(void *port, u32 mask, u32 val)
return 0; return 0;
} }
/*
* Probe for supported codecs
*/
int hda_codec_detect(u8 *base) int hda_codec_detect(u8 *base)
{ {
u8 reg8; u8 reg8;
@ -83,18 +75,16 @@ no_codec:
} }
/* /*
* Wait 50usec for the codec to indicate it is ready * Wait 50usec for the codec to indicate it is ready.
* no response would imply that the codec is non-operative * No response would imply that the codec is non-operative.
*/ */
static int hda_wait_for_ready(u8 *base) static int hda_wait_for_ready(u8 *base)
{ {
/* Use a 50 usec timeout - the Linux kernel uses the /* Use a 50 usec timeout - the Linux kernel uses the same duration */
* same duration */
int timeout = 50; int timeout = 50;
while (timeout--) { while (timeout--) {
u32 reg32 = read32(base + HDA_ICII_REG); u32 reg32 = read32(base + HDA_ICII_REG);
if (!(reg32 & HDA_ICII_BUSY)) if (!(reg32 & HDA_ICII_BUSY))
return 0; return 0;
udelay(1); udelay(1);
@ -104,27 +94,23 @@ static int hda_wait_for_ready(u8 *base)
} }
/* /*
* Wait 50usec for the codec to indicate that it accepted * Wait 50usec for the codec to indicate that it accepted the previous command.
* the previous command. No response would imply that the code * No response would imply that the code is non-operative.
* is non-operative
*/ */
static int hda_wait_for_valid(u8 *base) static int hda_wait_for_valid(u8 *base)
{ {
u32 reg32; u32 reg32;
/* Use a 50 usec timeout - the Linux kernel uses the same duration */
int timeout = 50;
/* Send the verb to the codec */ /* Send the verb to the codec */
reg32 = read32(base + HDA_ICII_REG); reg32 = read32(base + HDA_ICII_REG);
reg32 |= HDA_ICII_BUSY | HDA_ICII_VALID; reg32 |= HDA_ICII_BUSY | HDA_ICII_VALID;
write32(base + HDA_ICII_REG, reg32); write32(base + HDA_ICII_REG, reg32);
/* Use a 50 usec timeout - the Linux kernel uses the
* same duration */
int timeout = 50;
while (timeout--) { while (timeout--) {
reg32 = read32(base + HDA_ICII_REG); reg32 = read32(base + HDA_ICII_REG);
if ((reg32 & (HDA_ICII_VALID | HDA_ICII_BUSY)) == if ((reg32 & (HDA_ICII_VALID | HDA_ICII_BUSY)) == HDA_ICII_VALID)
HDA_ICII_VALID)
return 0; return 0;
udelay(1); udelay(1);
} }
@ -177,9 +163,6 @@ static u32 hda_find_verb(u32 verb_table_bytes,
return 0; return 0;
} }
/*
* Write a supplied verb table
*/
int hda_codec_write(u8 *base, u32 size, const u32 *data) int hda_codec_write(u8 *base, u32 size, const u32 *data)
{ {
int i; int i;
@ -197,9 +180,6 @@ int hda_codec_write(u8 *base, u32 size, const u32 *data)
return 0; return 0;
} }
/*
* Initialize codec, then find the verb table and write it
*/
int hda_codec_init(u8 *base, int addr, int verb_size, const u32 *verb_data) int hda_codec_init(u8 *base, int addr, int verb_size, const u32 *verb_data)
{ {
const u32 *verb; const u32 *verb;

View File

@ -4,12 +4,10 @@
#include <device/azalia_device.h> #include <device/azalia_device.h>
#include <device/mmio.h> #include <device/mmio.h>
#include <delay.h> #include <delay.h>
#include "pch.h" #include "pch.h"
#include "hda_verb.h" #include "hda_verb.h"
/**
* Set bits in a register and wait for status
*/
static int set_bits(void *port, u32 mask, u32 val) static int set_bits(void *port, u32 mask, u32 val)
{ {
u32 reg32; u32 reg32;
@ -22,9 +20,7 @@ static int set_bits(void *port, u32 mask, u32 val)
reg32 |= val; reg32 |= val;
write32(port, reg32); write32(port, reg32);
/* Wait for readback of register to /* Wait for readback of register to match what was just written to it */
* match what was just written to it
*/
count = 50; count = 50;
do { do {
/* Wait 1ms based on BKDG wait time */ /* Wait 1ms based on BKDG wait time */
@ -39,9 +35,6 @@ static int set_bits(void *port, u32 mask, u32 val)
return 0; return 0;
} }
/**
* Probe for supported codecs
*/
int hda_codec_detect(u8 *base) int hda_codec_detect(u8 *base)
{ {
u8 reg8; u8 reg8;
@ -69,19 +62,17 @@ no_codec:
return 0; return 0;
} }
/** /*
* Wait 50usec for the codec to indicate it is ready * Wait 50usec for the codec to indicate it is ready.
* no response would imply that the codec is non-operative * No response would imply that the codec is non-operative.
*/ */
static int hda_wait_for_ready(u8 *base) static int hda_wait_for_ready(u8 *base)
{ {
/* Use a 50 usec timeout - the Linux kernel uses the /* Use a 50 usec timeout - the Linux kernel uses the same duration */
* same duration */
int timeout = 50; int timeout = 50;
while (timeout--) { while (timeout--) {
u32 reg32 = read32(base + HDA_ICII_REG); u32 reg32 = read32(base + HDA_ICII_REG);
if (!(reg32 & HDA_ICII_BUSY)) if (!(reg32 & HDA_ICII_BUSY))
return 0; return 0;
udelay(1); udelay(1);
@ -90,28 +81,24 @@ static int hda_wait_for_ready(u8 *base)
return -1; return -1;
} }
/** /*
* Wait 50usec for the codec to indicate that it accepted * Wait 50usec for the codec to indicate that it accepted the previous command.
* the previous command. No response would imply that the code * No response would imply that the code is non-operative.
* is non-operative
*/ */
static int hda_wait_for_valid(u8 *base) static int hda_wait_for_valid(u8 *base)
{ {
u32 reg32; u32 reg32;
/* Use a 50 usec timeout - the Linux kernel uses the same duration */
int timeout = 50;
/* Send the verb to the codec */ /* Send the verb to the codec */
reg32 = read32(base + HDA_ICII_REG); reg32 = read32(base + HDA_ICII_REG);
reg32 |= HDA_ICII_BUSY | HDA_ICII_VALID; reg32 |= HDA_ICII_BUSY | HDA_ICII_VALID;
write32(base + HDA_ICII_REG, reg32); write32(base + HDA_ICII_REG, reg32);
/* Use a 50 usec timeout - the Linux kernel uses the
* same duration */
int timeout = 50;
while (timeout--) { while (timeout--) {
reg32 = read32(base + HDA_ICII_REG); reg32 = read32(base + HDA_ICII_REG);
if ((reg32 & (HDA_ICII_VALID | HDA_ICII_BUSY)) == if ((reg32 & (HDA_ICII_VALID | HDA_ICII_BUSY)) == HDA_ICII_VALID)
HDA_ICII_VALID)
return 0; return 0;
udelay(1); udelay(1);
} }
@ -119,7 +106,7 @@ static int hda_wait_for_valid(u8 *base)
return -1; return -1;
} }
/** /*
* Find a specific entry within a verb table * Find a specific entry within a verb table
* *
* @param verb_table_bytes: verb table size in bytes * @param verb_table_bytes: verb table size in bytes
@ -148,7 +135,7 @@ static u32 hda_find_verb(u32 verb_table_bytes,
const u32 *verb_table_data, const u32 *verb_table_data,
u32 viddid, const u32 **verb) u32 viddid, const u32 **verb)
{ {
int idx=0; int idx = 0;
while (idx < (verb_table_bytes / sizeof(u32))) { while (idx < (verb_table_bytes / sizeof(u32))) {
u32 verb_size = 4 * verb_table_data[idx+2]; // in u32 u32 verb_size = 4 * verb_table_data[idx+2]; // in u32
@ -164,9 +151,6 @@ static u32 hda_find_verb(u32 verb_table_bytes,
return 0; return 0;
} }
/**
* Write a supplied verb table
*/
int hda_codec_write(u8 *base, u32 size, const u32 *data) int hda_codec_write(u8 *base, u32 size, const u32 *data)
{ {
int i; int i;
@ -184,9 +168,6 @@ int hda_codec_write(u8 *base, u32 size, const u32 *data)
return 0; return 0;
} }
/**
* Initialize codec, then find the verb table and write it
*/
int hda_codec_init(u8 *base, int addr, int verb_size, const u32 *verb_data) int hda_codec_init(u8 *base, int addr, int verb_size, const u32 *verb_data)
{ {
const u32 *verb; const u32 *verb;