diff options
author | Andrew Ryabinin <ryabinin.a.a@gmail.com> | 2013-06-02 23:03:26 +0400 |
---|---|---|
committer | Andrew Ryabinin <ryabinin.a.a@gmail.com> | 2013-11-05 09:59:45 +0400 |
commit | 3a97e12fc58bd413c81d827c7b32a8cfd08b4d2b (patch) | |
tree | 4a827d570ab32161783d9327a748d87f601605c5 /firmware/drivers/audio | |
parent | a170c99170589488531f7f576ad5e248b1c7c589 (diff) |
Introduce HiFi E.T. MA8/MA8C ports.
HiFi E.T. MA8 is almost the same as MA9 except
another DAC(pcm1792 in ma8, df1704 in ma9).
MA8 has ILI9342 lcd, MA8C has ILI9342C lcd.
Change-Id: If2ac04f5a3382590b2a392c46286559f54b2ed6a
Diffstat (limited to 'firmware/drivers/audio')
-rw-r--r-- | firmware/drivers/audio/pcm1792.c | 133 |
1 files changed, 133 insertions, 0 deletions
diff --git a/firmware/drivers/audio/pcm1792.c b/firmware/drivers/audio/pcm1792.c new file mode 100644 index 0000000000..67237a920a --- /dev/null +++ b/firmware/drivers/audio/pcm1792.c @@ -0,0 +1,133 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2013 Andrew Ryabinin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "system.h" +#include "pcm1792.h" +#include "config.h" +#include "audio.h" +#include "audiohw.h" + +/* pcm1792 registers initial values */ +#define REG18_INIT_VALUE (PCM1792_ATLD_OFF|PCM1792_FMT_16_I2S| \ + PCM1792_DMF_DISABLE|PCM1792_DME_OFF) + +#define REG19_INIT_VALUE (PCM1792_REV_ON|PCM1792_ATS_DIV1| \ + PCM1792_OPE_ON|PCM1792_DFMS_MONO| \ + PCM1792_FLT_SHARP|PCM1792_INZD_OFF) + +#define REG20_INIT_VALUE (PCM1792_SRST_NORMAL|PCM1792_DSD_OFF|\ + PCM1792_DFTH_ENABLE|PCM1792_STEREO|\ + PCM1792_OS_64) + +#define REG21_INIT_VALUE (PCM1792_DZ_DISABLE|PCM1792_PCMZ_ON) + + +static void pcm1792_write_reg(const int reg, const unsigned int value) +{ + int i; + + pcm1792_set_ml_dir(0); + pcm1792_set_md(1); + pcm1792_set_mc(0); + pcm1792_set_ml(0); + + for (i = (1<<15); i; i >>= 1) { + udelay(40); + pcm1792_set_mc(0); + + if ((reg|value) & i) { + pcm1792_set_md(1); + } else { + pcm1792_set_md(0); + } + + udelay(40); + pcm1792_set_mc(1); + } + + udelay(40); + pcm1792_set_ml(1); + pcm1792_set_mc(0); + udelay(130); + pcm1792_set_md(1); +} + +static int vol_tenthdb2hw(const int tdb) +{ + if (tdb < PCM1792_VOLUME_MIN) { + return 0; + } else if (tdb > PCM1792_VOLUME_MAX) { + return 0xff; + } else { + return (tdb/5+0xff); + } +} + + +void audiohw_init(void) +{ + pcm1792_write_reg(PCM1792_REG(18), REG18_INIT_VALUE); + pcm1792_write_reg(PCM1792_REG(19), REG19_INIT_VALUE); + pcm1792_write_reg(PCM1792_REG(20), REG20_INIT_VALUE); + pcm1792_write_reg(PCM1792_REG(21), REG21_INIT_VALUE); + + /* Left & Right volumes */ + pcm1792_write_reg(PCM1792_REG(16), 0xff); + pcm1792_write_reg(PCM1792_REG(17), 0xff); +} + +void audiohw_mute(void) +{ + pcm1792_write_reg(PCM1792_REG(18), REG18_INIT_VALUE|PCM1792_MUTE_ON); +} + +void audiohw_unmute(void) +{ + pcm1792_write_reg(PCM1792_REG(18), REG18_INIT_VALUE); +} + +void audiohw_preinit(void) +{ +} + +void audiohw_set_frequency(int fsel) +{ + (void)fsel; +} + +void audiohw_set_volume(int vol_l, int vol_r) +{ + pcm1792_write_reg(PCM1792_REG(16), vol_tenthdb2hw(vol_l)); + pcm1792_write_reg(PCM1792_REG(17), vol_tenthdb2hw(vol_r)); +} + +void audiohw_set_filter_roll_off(int value) +{ + if (value == 0) { + pcm1792_write_reg(PCM1792_REG(19), + REG19_INIT_VALUE + |PCM1792_FLT_SHARP); + } else { + pcm1792_write_reg(PCM1792_REG(19), + REG19_INIT_VALUE + |PCM1792_FLT_SLOW); + } +} |