From d989f19eda42aa0fbd2430400faace2a51df4e98 Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Thu, 3 May 2007 18:08:00 +0000 Subject: No more ear doctor visits after powering/unpowering the Gigabeat. Cleanup a little too. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13312 a1c6a512-1295-4272-9138-f99709370657 --- firmware/drivers/audio/wm8751.c | 84 ++++++++++------------ firmware/export/wm8751.h | 1 + firmware/powermgmt.c | 21 +----- .../target/arm/s3c2440/gigabeat-fx/pcm-meg-fx.c | 10 +-- .../arm/s3c2440/gigabeat-fx/wmcodec-meg-fx.c | 31 ++------ 5 files changed, 52 insertions(+), 95 deletions(-) (limited to 'firmware') diff --git a/firmware/drivers/audio/wm8751.c b/firmware/drivers/audio/wm8751.c index 21ff4728b3..2f79f27c7c 100644 --- a/firmware/drivers/audio/wm8751.c +++ b/firmware/drivers/audio/wm8751.c @@ -78,53 +78,45 @@ static int tone_tenthdb2hw(int value) void audiohw_reset(void); -/* Silently enable / disable audio output */ -void audiohw_enable_output(bool enable) +/* Reset and power up the WM8751 */ +void audiohw_preinit(void) { - if (enable) - { - /* reset the I2S controller into known state */ - i2s_reset(); - - /* - * 1. Switch on power supplies. - * By default the WM87551L is in Standby Mode, the DAC is - * digitally muted and the Audio Interface, Line outputs - * and Headphone outputs are all OFF (DACMU = 1 Power - * Management registers 1 and 2 are all zeros). - */ - wmcodec_write(RESET, RESET_RESET); /*Reset*/ - - /* 2. Enable Vmid and VREF. */ - wmcodec_write(PWRMGMT1, PWRMGMT1_VREF | PWRMGMT1_VMIDSEL_500K); - - /* From app notes: allow Vref to stabilize to reduce clicks */ - sleep(HZ/2); - - /* 3. Enable DACs as required. */ - wmcodec_write(PWRMGMT2, PWRMGMT2_DACL | PWRMGMT2_DACR); - - /* 4. Enable line and / or headphone output buffers as required. */ - wmcodec_write(PWRMGMT2, PWRMGMT2_DACL | PWRMGMT2_DACR | - PWRMGMT2_LOUT1 | PWRMGMT2_ROUT1 | PWRMGMT2_LOUT2 | - PWRMGMT2_ROUT2); - - /* BCLKINV=0(Dont invert BCLK) MS=1(Enable Master) LRSWAP=0 LRP=0 */ - /* IWL=00(16 bit) FORMAT=10(I2S format) */ - wmcodec_write(AINTFCE, AINTFCE_MS | AINTFCE_WL_16 | - AINTFCE_FORMAT_I2S); - - /* Keep it quiet */ - wmcodec_write(LOUT1, LOUT1_BITS | OUTPUT_MUTED); - wmcodec_write(ROUT1, ROUT1_BITS | OUTPUT_MUTED); - wmcodec_write(LOUT2, LOUT2_BITS | OUTPUT_MUTED); - wmcodec_write(ROUT2, ROUT2_BITS | OUTPUT_MUTED); - - wmcodec_write(LEFTMIX1, LEFTMIX1_LD2LO | LEFTMIX1_LI2LO_DEFAULT); - wmcodec_write(RIGHTMIX2, RIGHTMIX2_RD2RO | RIGHTMIX2_RI2RO_DEFAULT); - } - - audiohw_mute(!enable); + /* + * 1. Switch on power supplies. + * By default the WM8751 is in Standby Mode, the DAC is + * digitally muted and the Audio Interface, Line outputs + * and Headphone outputs are all OFF (DACMU = 1 Power + * Management registers 1 and 2 are all zeros). + */ + wmcodec_write(RESET, RESET_RESET); /*Reset*/ + + /* 2. Enable Vmid and VREF. */ + wmcodec_write(PWRMGMT1, PWRMGMT1_VREF | PWRMGMT1_VMIDSEL_5K); + + /* BCLKINV=0(Dont invert BCLK) MS=1(Enable Master) LRSWAP=0 LRP=0 */ + /* IWL=00(16 bit) FORMAT=10(I2S format) */ + wmcodec_write(AINTFCE, AINTFCE_MS | AINTFCE_WL_16 | + AINTFCE_FORMAT_I2S); +} + +/* Enable DACs and audio output after a short delay */ +void audiohw_postinit(void) +{ + /* From app notes: allow Vref to stabilize to reduce clicks */ + sleep(HZ); + + /* 3. Enable DACs as required. */ + wmcodec_write(PWRMGMT2, PWRMGMT2_DACL | PWRMGMT2_DACR); + + /* 4. Enable line and / or headphone output buffers as required. */ + wmcodec_write(PWRMGMT2, PWRMGMT2_DACL | PWRMGMT2_DACR | + PWRMGMT2_LOUT1 | PWRMGMT2_ROUT1 | PWRMGMT2_LOUT2 | + PWRMGMT2_ROUT2); + + wmcodec_write(LEFTMIX1, LEFTMIX1_LD2LO | LEFTMIX1_LI2LO_DEFAULT); + wmcodec_write(RIGHTMIX2, RIGHTMIX2_RD2RO | RIGHTMIX2_RI2RO_DEFAULT); + + audiohw_mute(false); } int audiohw_set_master_vol(int vol_l, int vol_r) diff --git a/firmware/export/wm8751.h b/firmware/export/wm8751.h index 244d378b26..efeaa3609d 100644 --- a/firmware/export/wm8751.h +++ b/firmware/export/wm8751.h @@ -28,6 +28,7 @@ extern int tenthdb2mixer(int db); extern void audiohw_reset(void); extern int audiohw_init(void); +extern void audiohw_preinit(void); extern void audiohw_enable_output(bool enable); extern int audiohw_set_master_vol(int vol_l, int vol_r); extern int audiohw_set_lineout_vol(int vol_l, int vol_r); diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c index 3d87773394..000a8bb2ec 100644 --- a/firmware/powermgmt.c +++ b/firmware/powermgmt.c @@ -40,17 +40,7 @@ #if CONFIG_TUNER #include "fmradio.h" #endif -#ifdef HAVE_UDA1380 -#include "uda1380.h" -#elif defined(HAVE_TLV320) -#include "tlv320.h" -#elif defined(HAVE_WM8758) -#include "wm8758.h" -#elif defined(HAVE_WM8975) -#include "wm8975.h" -#elif defined(HAVE_WM8731) -#include "wm8731l.h" -#endif +#include "sound.h" #ifdef HAVE_LCD_BITMAP #include "font.h" #endif @@ -1323,15 +1313,10 @@ void shutdown_hw(void) #if CONFIG_CODEC != SWCODEC mp3_shutdown(); -#endif - -#ifdef HAVE_UDA1380 - audiohw_close(); -#elif defined(HAVE_TLV320) - audiohw_close(); -#elif defined(HAVE_WM8758) || defined(HAVE_WM8975) | defined(HAVE_WM8731) +#else audiohw_close(); #endif + /* If HD is still active we try to wait for spindown, otherwise the shutdown_timeout in power_thread_sleep will force a power off */ while(ata_disk_is_active()) diff --git a/firmware/target/arm/s3c2440/gigabeat-fx/pcm-meg-fx.c b/firmware/target/arm/s3c2440/gigabeat-fx/pcm-meg-fx.c index 45558767d3..09f846d645 100644 --- a/firmware/target/arm/s3c2440/gigabeat-fx/pcm-meg-fx.c +++ b/firmware/target/arm/s3c2440/gigabeat-fx/pcm-meg-fx.c @@ -31,8 +31,8 @@ #define GIGABEAT_44100HZ (0x11 << 1) #define GIGABEAT_88200HZ (0x1f << 1) -static int pcm_freq = HW_SAMPR_DEFAULT; /* 44.1 is default */ -static int sr_ctrl = GIGABEAT_44100HZ; +static int pcm_freq = 0; /* 44.1 is default */ +static int sr_ctrl = 0; #define FIFO_COUNT ((IISFCON >> 6) & 0x01F) /* number of bytes in FIFO */ @@ -71,11 +71,10 @@ void pcm_init(void) pcm_paused = false; pcm_callback_for_more = NULL; - audiohw_init(); - audiohw_enable_output(true); - pcm_set_frequency(SAMPR_44); + audiohw_init(); + /* init GPIO */ GPCCON = (GPCCON & ~(3<<14)) | (1<<14); GPCDAT |= 1<<7; @@ -92,6 +91,7 @@ void pcm_init(void) void pcm_postinit(void) { audiohw_postinit(); + pcm_apply_settings(); } void pcm_play_dma_start(const void *addr, size_t size) diff --git a/firmware/target/arm/s3c2440/gigabeat-fx/wmcodec-meg-fx.c b/firmware/target/arm/s3c2440/gigabeat-fx/wmcodec-meg-fx.c index fe42b7527a..be23fa1783 100644 --- a/firmware/target/arm/s3c2440/gigabeat-fx/wmcodec-meg-fx.c +++ b/firmware/target/arm/s3c2440/gigabeat-fx/wmcodec-meg-fx.c @@ -23,33 +23,14 @@ * KIND, either express or implied. * ****************************************************************************/ -#include "lcd.h" #include "cpu.h" #include "kernel.h" -#include "thread.h" -#include "power.h" -#include "debug.h" -#include "system.h" -#include "sprintf.h" -#include "button.h" -#include "string.h" -#include "file.h" -#include "buffer.h" -#include "audio.h" +#include "sound.h" #include "i2c.h" #include "i2c-meg-fx.h" -/* - * Reset the I2S BIT.FORMAT I2S, 16bit, FIFO.FORMAT 32bit - */ -void i2s_reset(void) -{ -} -/* - * Initialise the WM8975 for playback via headphone and line out. - * Note, I'm using the WM8750 datasheet as its apparently close. - */ -int audiohw_init(void) { +int audiohw_init(void) +{ /* reset I2C */ i2c_init(); @@ -58,11 +39,9 @@ int audiohw_init(void) { GPCCON |= (1 << 10); GPCDAT |= (1 << 5); - return 0; -} + audiohw_preinit(); -void audiohw_postinit(void) -{ + return 0; } void wmcodec_write(int reg, int data) -- cgit v1.2.3