Fix no-backlight colours for H100 series and M3.
[kugel-rb.git] / firmware / drivers / audio / tsc2100.c
blobca7f22d0975a640aa41eb9882aa80b51ca4a1d0c
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, -63, 0, -25},
33 #if 0
34 /* HAVE_SW_TONE_CONTROLS */
35 [SOUND_BASS] = {"dB", 0, 1, -24, 24, 0},
36 [SOUND_TREBLE] = {"dB", 0, 1, -24, 24, 0},
37 [SOUND_BALANCE] = {"%", 0, 1,-100, 100, 0},
38 [SOUND_CHANNELS] = {"", 0, 1, 0, 5, 0},
39 [SOUND_STEREO_WIDTH] = {"%", 0, 5, 0, 250, 100},
40 #ifdef HAVE_RECORDING
41 [SOUND_MIC_GAIN] = {"dB", 1, 1, 0, 39, 23},
42 [SOUND_LEFT_GAIN] = {"dB", 1, 1, 0, 31, 23},
43 [SOUND_RIGHT_GAIN] = {"dB", 1, 1, 0, 31, 23},
44 #endif
45 #endif
47 static bool is_muted = false;
48 /* convert tenth of dB volume to master volume register value */
49 int tenthdb2master(int db)
51 /* 0 to -63.0dB in 1dB steps, tsc2100 can goto -63.5 in 0.5dB steps */
52 if (db < VOLUME_MIN) {
53 return 0x0;
54 } else if (db >= VOLUME_MAX) {
55 return 0x1f;
56 } else {
57 return((db-VOLUME_MIN)/10); /* VOLUME_MIN is negative */
61 int sound_val2phys(int setting, int value)
63 int result;
65 switch(setting)
67 #if 0
68 case SOUND_LEFT_GAIN:
69 case SOUND_RIGHT_GAIN:
70 case SOUND_MIC_GAIN:
71 result = (value - 23) * 15;
72 break;
73 #endif
74 default:
75 result = value;
76 break;
79 return result;
82 void audiohw_init(void)
84 short val = tsc2100_readreg(TSAC4_PAGE, TSAC4_ADDRESS);
85 /* disable DAC PGA soft-stepping */
86 val |= TSAC4_DASTDP;
88 tsc2100_writereg(TSAC4_PAGE, TSAC4_ADDRESS, val);
91 void audiohw_postinit(void)
93 audiohw_mute(0);
96 void audiohw_set_master_vol(int vol_l, int vol_r)
98 short vol = (vol_l<<14)|(vol_r);
99 if (is_muted)
100 vol |= (1<<15)|(1<<7);
101 tsc2100_writereg(TSDACGAIN_PAGE, TSDACGAIN_ADDRESS, vol);
104 void audiohw_set_lineout_vol(int vol_l, int vol_r)
106 audiohw_set_master_vol(vol_l, vol_r);
109 void audiohw_mute(bool mute)
111 short vol = tsc2100_readreg(TSDACGAIN_PAGE, TSDACGAIN_ADDRESS);
112 /* left mute bit == 1<<15
113 right mute bit == 1<<7
115 if (mute)
117 vol |= (1<<15)|(1<<7);
118 } else
120 vol &= ~((1<<15)|(1<<7));
122 is_muted = mute;
123 tsc2100_writereg(TSDACGAIN_PAGE, TSDACGAIN_ADDRESS, vol);
126 void audiohw_close(void)
128 /* mute headphones */
129 audiohw_mute(true);
133 void audiohw_set_frequency(int fsel)
135 (void)fsel;