Rockbox supports not only 1bpp BMPs
[kugel-rb.git] / firmware / drivers / audio / tsc2100.c
blob8a71d57e78fc46c1ce46c4692602a8ad258c10c8
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Driver for TSC2100 audio codec
12 * Copyright (c) 2008 Jonathan Gordon
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
22 ****************************************************************************/
23 #include "cpu.h"
24 #include "debug.h"
25 #include "system.h"
26 #include "audio.h"
28 #include "audiohw.h"
29 #include "tsc2100.h"
31 const struct sound_settings_info audiohw_settings[] = {
32 [SOUND_VOLUME] = {"dB", 0, 1, VOLUME_MIN/10, VOLUME_MAX/10, -25},
33 /* HAVE_SW_TONE_CONTROLS */
34 [SOUND_BASS] = {"dB", 0, 1, -24, 24, 0},
35 [SOUND_TREBLE] = {"dB", 0, 1, -24, 24, 0},
36 [SOUND_BALANCE] = {"%", 0, 1,-100, 100, 0},
37 [SOUND_CHANNELS] = {"", 0, 1, 0, 5, 0},
38 [SOUND_STEREO_WIDTH] = {"%", 0, 5, 0, 250, 100},
40 static bool is_muted = false;
41 /* convert tenth of dB volume to master volume register value */
42 int tenthdb2master(int db)
44 /* 0 to -63.0dB in 1dB steps, tsc2100 can goto -63.5 in 0.5dB steps */
45 if (db < VOLUME_MIN) {
46 return 0x7E;
47 } else if (db >= VOLUME_MAX) {
48 return 0x00;
49 } else {
50 return(-((db)/5)); /* VOLUME_MIN is negative */
54 int sound_val2phys(int setting, int value)
56 int result;
58 switch(setting)
60 #if 0
61 case SOUND_LEFT_GAIN:
62 case SOUND_RIGHT_GAIN:
63 case SOUND_MIC_GAIN:
64 result = (value - 23) * 15;
65 break;
66 #endif
67 default:
68 result = value;
69 break;
72 return result;
75 void audiohw_init(void)
77 short val = tsc2100_readreg(TSAC4_PAGE, TSAC4_ADDRESS);
78 /* disable DAC PGA soft-stepping */
79 val |= TSAC4_DASTDP;
81 tsc2100_writereg(TSAC4_PAGE, TSAC4_ADDRESS, val);
84 void audiohw_postinit(void)
86 audiohw_mute(false);
89 void audiohw_set_master_vol(int vol_l, int vol_r)
91 tsc2100_writereg(TSDACGAIN_PAGE, TSDACGAIN_ADDRESS, (short)((vol_l<<8) | vol_r) );
94 void audiohw_mute(bool mute)
96 short vol = tsc2100_readreg(TSDACGAIN_PAGE, TSDACGAIN_ADDRESS);
97 /* left mute bit == 1<<15
98 right mute bit == 1<<7
100 if (mute)
102 vol |= (1<<15)|(1<<7);
103 } else
105 vol &= ~((1<<15)|(1<<7));
107 is_muted = mute;
108 tsc2100_writereg(TSDACGAIN_PAGE, TSDACGAIN_ADDRESS, vol);
111 void audiohw_close(void)
113 /* mute headphones */
114 audiohw_mute(true);
117 void audiohw_set_frequency(int fsel)
119 (void)fsel;