From f62d7e764e2996e2dfdbcde1db2c09874310892a Mon Sep 17 00:00:00 2001 From: Bill Richardson Date: Thu, 19 Jan 2012 15:20:12 -0800 Subject: Enable frequency selection in VbExBeep(). BUG=none TEST=manual In dev-mode, press "Ctrl-U" with no USB stick inserted. If "crossystem dev_boot_usb" is 0, you'll hear two 400Hz beeps. If "crossystem dev_boot_usb" is 1, you'll hear one 200Hz beep. Signed-off-by: Bill Richardson Change-Id: Ifd45a067ec8b922863331f13f3f4525ef40f7346 Reviewed-on: https://gerrit.chromium.org/gerrit/14529 Tested-by: Bill Richardson Reviewed-by: Stefan Reinauer Commit-Ready: Bill Richardson --- board/chromebook-x86/chromeos/hda_codec.c | 33 +++++++++++++++++++++---------- include/chromeos/hda_codec.h | 2 +- lib/vbexport/utility.c | 2 +- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/board/chromebook-x86/chromeos/hda_codec.c b/board/chromebook-x86/chromeos/hda_codec.c index 21a0db5a56..e6f597fd84 100644 --- a/board/chromebook-x86/chromeos/hda_codec.c +++ b/board/chromebook-x86/chromeos/hda_codec.c @@ -10,17 +10,20 @@ /* Implementation of per-board codec beeping */ -#include #include #include #include #include +#include #define HDA_CMD_REG 0x5C #define HDA_ICII_REG 0x64 #define HDA_ICII_BUSY (1 << 0) #define HDA_ICII_VALID (1 << 1) +#define BEEP_FREQ_MAGIC 0x00C70A00 +#define BEEP_FREQ_BASE 12000 + /** * Wait 50usec for the codec to indicate it is ready * no response would imply that the codec is non-operative @@ -116,24 +119,34 @@ static u32 get_hda_base(void) } static const u32 beep_cmd[] = { - 0x00170500, /* power up codec */ - 0x00270500, /* power up DAC */ - 0x00670500, /* power up speaker */ - 0x00670740, /* enable speaker output */ - 0x0023B04B, /* set DAC gain */ - 0x00C70A0C, /* enable beep generator 1 kHz */ -}; - -void enable_beep(void) + 0x00170500, /* power up codec */ + 0x00270500, /* power up DAC */ + 0x00670500, /* power up speaker */ + 0x00670740, /* enable speaker output */ + 0x0023B04B, /* set DAC gain */ +}; /* and follow with BEEP_FREQ_MAGIC */ + +void enable_beep(uint32_t frequency) { uint32_t base; + uint8_t divider_val; int i; + if (0 == frequency) + divider_val = 0; /* off */ + else if (frequency > BEEP_FREQ_BASE) + divider_val = 1; + else if (frequency < BEEP_FREQ_BASE / 0xFF) + divider_val = 0xff; + else + divider_val = (uint8_t)(0xFF & (BEEP_FREQ_BASE / frequency)); + base = get_hda_base(); for (i = 0; i < sizeof(beep_cmd)/sizeof(beep_cmd[0]); i++) { if (write_one_verb(base, beep_cmd[i])) return; } + write_one_verb(base, BEEP_FREQ_MAGIC|divider_val); } void disable_beep(void) diff --git a/include/chromeos/hda_codec.h b/include/chromeos/hda_codec.h index e10a097469..3e223a4b90 100644 --- a/include/chromeos/hda_codec.h +++ b/include/chromeos/hda_codec.h @@ -14,7 +14,7 @@ #define CHROMEOS_HDA_CODEC_H_ /* Beep control */ -void enable_beep(void); +void enable_beep(uint32_t frequency); void disable_beep(void); #endif /* CHROMEOS_PHDA_CODEC_H_ */ diff --git a/lib/vbexport/utility.c b/lib/vbexport/utility.c index ace70b8a1c..715a1c3d9d 100644 --- a/lib/vbexport/utility.c +++ b/lib/vbexport/utility.c @@ -92,7 +92,7 @@ VbError_t VbExBeep(uint32_t msec, uint32_t frequency) { #if defined(CONFIG_SYS_COREBOOT) if (frequency) - enable_beep(); + enable_beep(frequency); else disable_beep(); -- cgit v1.2.3