diff options
Diffstat (limited to 'firmware/drivers/audio')
-rw-r--r-- | firmware/drivers/audio/tsc2100.c | 141 |
1 files changed, 141 insertions, 0 deletions
diff --git a/firmware/drivers/audio/tsc2100.c b/firmware/drivers/audio/tsc2100.c new file mode 100644 index 0000000000..4b3bf56bd8 --- /dev/null +++ b/firmware/drivers/audio/tsc2100.c | |||
@@ -0,0 +1,141 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Driver for TSC2100 audio codec | ||
11 | * | ||
12 | * Copyright (c) 2008 Jonathan Gordon | ||
13 | * | ||
14 | * All files in this archive are subject to the GNU General Public License. | ||
15 | * See the file COPYING in the source tree root for full license agreement. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | #include "cpu.h" | ||
22 | #include "debug.h" | ||
23 | #include "system.h" | ||
24 | #include "audio.h" | ||
25 | |||
26 | #include "audiohw.h" | ||
27 | #include "tsc2100.h" | ||
28 | |||
29 | const struct sound_settings_info audiohw_settings[] = { | ||
30 | [SOUND_VOLUME] = {"dB", 0, 1, -63, 0, -25}, | ||
31 | #if 0 | ||
32 | /* HAVE_SW_TONE_CONTROLS */ | ||
33 | [SOUND_BASS] = {"dB", 0, 1, -24, 24, 0}, | ||
34 | [SOUND_TREBLE] = {"dB", 0, 1, -24, 24, 0}, | ||
35 | [SOUND_BALANCE] = {"%", 0, 1,-100, 100, 0}, | ||
36 | [SOUND_CHANNELS] = {"", 0, 1, 0, 5, 0}, | ||
37 | [SOUND_STEREO_WIDTH] = {"%", 0, 5, 0, 250, 100}, | ||
38 | [SOUND_MIC_GAIN] = {"dB", 1, 1, 0, 39, 23}, | ||
39 | [SOUND_LEFT_GAIN] = {"dB", 1, 1, 0, 31, 23}, | ||
40 | [SOUND_RIGHT_GAIN] = {"dB", 1, 1, 0, 31, 23}, | ||
41 | #endif | ||
42 | }; | ||
43 | static bool is_muted = false; | ||
44 | /* convert tenth of dB volume to master volume register value */ | ||
45 | int tenthdb2master(int db) | ||
46 | { | ||
47 | /* 0 to -63.0dB in 1dB steps, tsc2100 can goto -63.5 in 0.5dB steps */ | ||
48 | if (db < VOLUME_MIN) { | ||
49 | return 0x0; | ||
50 | } else if (db >= VOLUME_MAX) { | ||
51 | return 0x1f; | ||
52 | } else { | ||
53 | return((db-VOLUME_MIN)/10); /* VOLUME_MIN is negative */ | ||
54 | } | ||
55 | } | ||
56 | |||
57 | int sound_val2phys(int setting, int value) | ||
58 | { | ||
59 | int result; | ||
60 | |||
61 | switch(setting) | ||
62 | { | ||
63 | #if 0 | ||
64 | case SOUND_LEFT_GAIN: | ||
65 | case SOUND_RIGHT_GAIN: | ||
66 | case SOUND_MIC_GAIN: | ||
67 | result = (value - 23) * 15; | ||
68 | break; | ||
69 | #endif | ||
70 | default: | ||
71 | result = value; | ||
72 | break; | ||
73 | } | ||
74 | |||
75 | return result; | ||
76 | } | ||
77 | |||
78 | void audiohw_init(void) | ||
79 | { | ||
80 | short val = tsc2100_readreg(TSAC4_PAGE, TSAC4_ADDRESS); | ||
81 | /* disable DAC PGA soft-stepping */ | ||
82 | val |= TSAC4_DASTDP; | ||
83 | |||
84 | tsc2100_writereg(TSAC4_PAGE, TSAC4_ADDRESS, val); | ||
85 | } | ||
86 | |||
87 | void audiohw_postinit(void) | ||
88 | { | ||
89 | } | ||
90 | |||
91 | /* Silently enable / disable audio output */ | ||
92 | void audiohw_enable_output(bool enable) | ||
93 | { | ||
94 | if (enable) { | ||
95 | audiohw_mute(0); | ||
96 | } else { | ||
97 | audiohw_mute(1); | ||
98 | } | ||
99 | } | ||
100 | |||
101 | void audiohw_set_master_vol(int vol_l, int vol_r) | ||
102 | { | ||
103 | short vol = (vol_l<<14)|(vol_r); | ||
104 | if (is_muted) | ||
105 | vol |= (1<<15)|(1<<7); | ||
106 | tsc2100_writereg(TSDACGAIN_PAGE, TSDACGAIN_ADDRESS, vol); | ||
107 | } | ||
108 | |||
109 | void audiohw_set_lineout_vol(int vol_l, int vol_r) | ||
110 | { | ||
111 | audiohw_set_lineout_vol(vol_l, vol_r); | ||
112 | } | ||
113 | |||
114 | void audiohw_mute(bool mute) | ||
115 | { | ||
116 | short vol = tsc2100_readreg(TSDACGAIN_PAGE, TSDACGAIN_ADDRESS); | ||
117 | /* left mute bit == 1<<15 | ||
118 | right mute bit == 1<<7 | ||
119 | */ | ||
120 | if (mute) | ||
121 | { | ||
122 | vol |= (1<<15)|(1<<7); | ||
123 | } else | ||
124 | { | ||
125 | vol &= ~((1<<15)|(1<<7)); | ||
126 | } | ||
127 | is_muted = mute; | ||
128 | tsc2100_writereg(TSDACGAIN_PAGE, TSDACGAIN_ADDRESS, vol); | ||
129 | } | ||
130 | |||
131 | void audiohw_close(void) | ||
132 | { | ||
133 | /* mute headphones */ | ||
134 | audiohw_mute(true); | ||
135 | |||
136 | } | ||
137 | |||
138 | void audiohw_set_sample_rate(int sampling_control) | ||
139 | { | ||
140 | (void)sampling_control; | ||
141 | } | ||