summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
Diffstat (limited to 'firmware')
-rw-r--r--firmware/SOURCES1
-rw-r--r--firmware/drivers/audio/tsc2100.c141
-rw-r--r--firmware/export/audiohw.h2
-rw-r--r--firmware/export/tsc2100.h42
4 files changed, 174 insertions, 12 deletions
diff --git a/firmware/SOURCES b/firmware/SOURCES
index 5083357732..0aaf895293 100644
--- a/firmware/SOURCES
+++ b/firmware/SOURCES
@@ -255,6 +255,7 @@ drivers/m5636.c
255/* Other Random Hardware */ 255/* Other Random Hardware */
256#ifdef HAVE_TSC2100 256#ifdef HAVE_TSC2100
257drivers/tsc2100.c 257drivers/tsc2100.c
258drivers/audio/tsc2100.c
258#endif 259#endif
259 260
260/* CPU Specific - By class then particular chip if applicable */ 261/* CPU Specific - By class then particular chip if applicable */
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
29const 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};
43static bool is_muted = false;
44/* convert tenth of dB volume to master volume register value */
45int 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
57int 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
78void 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
87void audiohw_postinit(void)
88{
89}
90
91/* Silently enable / disable audio output */
92void audiohw_enable_output(bool enable)
93{
94 if (enable) {
95 audiohw_mute(0);
96 } else {
97 audiohw_mute(1);
98 }
99}
100
101void 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
109void audiohw_set_lineout_vol(int vol_l, int vol_r)
110{
111 audiohw_set_lineout_vol(vol_l, vol_r);
112}
113
114void 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
131void audiohw_close(void)
132{
133 /* mute headphones */
134 audiohw_mute(true);
135
136}
137
138void audiohw_set_sample_rate(int sampling_control)
139{
140 (void)sampling_control;
141}
diff --git a/firmware/export/audiohw.h b/firmware/export/audiohw.h
index 190fcca7a8..b3493b86d9 100644
--- a/firmware/export/audiohw.h
+++ b/firmware/export/audiohw.h
@@ -45,6 +45,8 @@
45#include "as3514.h" 45#include "as3514.h"
46#elif defined(HAVE_MAS35XX) 46#elif defined(HAVE_MAS35XX)
47#include "mas35xx.h" 47#include "mas35xx.h"
48#elif defined(HAVE_TSC2100)
49#include "tsc2100.h"
48#endif 50#endif
49 51
50enum { 52enum {
diff --git a/firmware/export/tsc2100.h b/firmware/export/tsc2100.h
index 9f3ceadcc9..70b793266f 100644
--- a/firmware/export/tsc2100.h
+++ b/firmware/export/tsc2100.h
@@ -71,12 +71,14 @@ void tsc2100_writereg(int page, int address, short value);
71#define TSRESET_VALUE 0xBB00 71#define TSRESET_VALUE 0xBB00
72 72
73/* ts codec dac gain control */ 73/* ts codec dac gain control */
74#define TSDACGAIN_PAGE 2 74#define TSDACGAIN_PAGE 2
75#define TSDACGAIN_ADDRESS 0x02 75#define TSDACGAIN_ADDRESS 0x02
76#define VOLUME_MAX 0
77#define VOLUME_MIN -630
76 78
77/* ts audio control 1*/ 79/* ts audio control 1*/
78#define TSAC1_PAGE 2 80#define TSAC1_PAGE 2
79#define TSAC1_ADDRESS 0x00 81#define TSAC1_ADDRESS 0x00
80 82
81/* ts audio control 2 */ 83/* ts audio control 2 */
82#define TSAC2_PAGE 2 84#define TSAC2_PAGE 2
@@ -95,19 +97,35 @@ void tsc2100_writereg(int page, int address, short value);
95#define TSAC2_ADGAF (1<<0) /* r only */ 97#define TSAC2_ADGAF (1<<0) /* r only */
96 98
97/* ts codec power control */ 99/* ts codec power control */
98#define TSCPC_PAGE 2 100#define TSCPC_PAGE 2
99#define TSCPC_ADDRESS 0x05 101#define TSCPC_ADDRESS 0x05
100 102
101/* ts audio control 3 */ 103/* ts audio control 3 */
102#define TSAC3_PAGE 2 104#define TSAC3_PAGE 2
103#define TSAC3_ADDRESS 0x06 105#define TSAC3_ADDRESS 0x06
104 106
105/* ts audio control 4 */ 107/* ts audio control 4 */
106#define TSAC4_PAGE 2 108#define TSAC4_PAGE 2
107#define TSAC4_ADDRESS 0x1d 109#define TSAC4_ADDRESS 0x1d
110#define TSAC4_ASTDP (1<<15)
111#define TSAC4_DASTDP (1<<14)
112#define TSAC4_ASSTDP (1<<13)
113#define TSAC4_DSTDP (1<<12)
114#define TSAC4_RESERVEDD11 (1<<11)
115#define TSAC4_AGC_HYST_MASK 0x0c00
116#define TSAC4_AGC_HYST_SHIFT 10
117#define TSAC4_SHCKT_DIS (1<<8)
118#define TSAC4_SHCKT_PD (1<<7)
119#define TSAC4_SHCKT_FLAG (1<<6)
120#define TSAC4_DAC_POP_RED (1<<5)
121#define TSAC4_DAC_POP_RED_SET1 (1<<4)
122#define TSAC4_DAC_POP_RED_SET2_MASK 0x000c
123#define TSAC4_DAC_POP_RED_SET2_SHIFT 3
124#define TSAC4_PGID_MASK 0x0003
125#define TSAC4_PGID_SHIFT 0
108 126
109/* ts audio control 5 */ 127/* ts audio control 5 */
110#define TSAC5_PAGE 2 128#define TSAC5_PAGE 2
111#define TSAC5_ADDRESS 0x1e 129#define TSAC5_ADDRESS 0x1e
112 130
113#endif 131#endif