From b8577dd5828b962238569277f96fe1a09321d813 Mon Sep 17 00:00:00 2001 From: Linus Nielsen Feltzing Date: Fri, 18 Mar 2005 11:35:11 +0000 Subject: iRiver UDA1380 driver by Andy Young git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6204 a1c6a512-1295-4272-9138-f99709370657 --- firmware/drivers/uda1380.c | 145 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 firmware/drivers/uda1380.c (limited to 'firmware/drivers/uda1380.c') diff --git a/firmware/drivers/uda1380.c b/firmware/drivers/uda1380.c new file mode 100644 index 0000000000..e8b8c14399 --- /dev/null +++ b/firmware/drivers/uda1380.c @@ -0,0 +1,145 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2005 by Andy Young + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * 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 "i2c-h100.h" +#include "uda1380.h" + +/* ------------------------------------------------- */ +/* Local functions and variables */ +/* ------------------------------------------------- */ + +int uda1380_write_reg(unsigned char reg, unsigned short value); +unsigned short uda1380_regs[0x30]; + +/* Definition of a good (?) configuration to start with */ +/* Not enabling ADC for now.. */ + +#define NUM_DEFAULT_REGS 13 +unsigned short uda1380_defaults[2*NUM_DEFAULT_REGS] = +{ + REG_0, EN_DAC | EN_INT | EN_DEC | SYSCLK_256FS | WSPLL_25_50, + REG_I2S, I2S_IFMT_IIS, + REG_PWR, PON_PLL | PON_HP | PON_DAC | EN_AVC | PON_AVC | PON_BIAS, + REG_AMIX, AMIX_RIGHT(0x10) | AMIX_LEFT(0x10), /* 00=max, 3f=mute */ + REG_MASTER_VOL, MASTER_VOL_LEFT(0x7f) | MASTER_VOL_RIGHT(0x7f), /* 00=max, ff=mute */ + REG_MIX_VOL, MIX_VOL_CHANNEL_1(0) | MIX_VOL_CHANNEL_2(0xff), /* 00=max, ff=mute */ + REG_EQ, 0, + REG_MUTE, MUTE_CH2, /* Mute channel 2 (digital decimation filter) */ + REG_MIX_CTL, 0, + REG_DEC_VOL, 0, + REG_PGA, MUTE_ADC, + REG_ADC, SKIP_DCFIL, + REG_AGC, 0 +}; + +/* Returns 0 if register was written or -1 if write failed */ +int uda1380_write_reg(unsigned char reg, unsigned short value) +{ + unsigned char data[4]; + + data[0] = UDA1380_ADDR; + data[1] = reg; + data[2] = value >> 8; + data[3] = value & 0xff; + + if (i2c_write(1, data, 4) != 4) + { + DEBUGF("uda1380 error reg=0x%x", reg); + return -1; + } + + uda1380_regs[reg] = value; + + return 0; +} + +/** + * Sets the master volume + * + * \param vol Range [0..255] 0=max, 255=mute + * + */ +int uda1380_setvol(int vol) +{ + return uda1380_write_reg(REG_MASTER_VOL, + MASTER_VOL_LEFT(vol) | MASTER_VOL_RIGHT(vol)); +} + +/** + * Mute (mute=1) or enable sound (mute=0) + * + */ +int uda1380_mute(int mute) +{ + unsigned int value = uda1380_regs[REG_MUTE]; + + if (mute) + value = value | MUTE_MASTER; + else + value = value & ~MUTE_MASTER; + + return uda1380_write_reg(REG_MUTE, value); +} + +/* Returns 0 if successful or -1 if some register failed */ +int uda1380_set_regs(void) +{ + int i; + memset(uda1380_regs, 0, sizeof(uda1380_regs)); + + /* Initialize all registers */ + for (i=0; i