summaryrefslogtreecommitdiff
path: root/firmware/drivers/audio/dac3550a.c
diff options
context:
space:
mode:
authorMarcin Bukat <marcin.bukat@gmail.com>2010-10-31 21:09:34 +0000
committerMarcin Bukat <marcin.bukat@gmail.com>2010-10-31 21:09:34 +0000
commit56c4e9fa600557242d8b78f5fd8e32c2245b76fc (patch)
treef8558778a302f89c3e819e66e86577a5e37c3660 /firmware/drivers/audio/dac3550a.c
parent40ed5f57d9be61f1200026e9b0f944a9718111c1 (diff)
downloadrockbox-56c4e9fa600557242d8b78f5fd8e32c2245b76fc.tar.gz
rockbox-56c4e9fa600557242d8b78f5fd8e32c2245b76fc.zip
Separate mas35xx lowlevel stuff. Move SH specific bits to target tree. FS#11189 by me.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28425 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/drivers/audio/dac3550a.c')
-rw-r--r--firmware/drivers/audio/dac3550a.c124
1 files changed, 124 insertions, 0 deletions
diff --git a/firmware/drivers/audio/dac3550a.c b/firmware/drivers/audio/dac3550a.c
new file mode 100644
index 0000000000..e13602e481
--- /dev/null
+++ b/firmware/drivers/audio/dac3550a.c
@@ -0,0 +1,124 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: dac.c 17847 2008-06-28 18:10:04Z bagder $
9 *
10 * Copyright (C) 2002 by Linus Nielsen Feltzing
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
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 "config.h"
22#include "stdbool.h"
23#include "i2c.h"
24#include "debug.h"
25#include "dac3550a.h"
26
27static bool line_in_enabled = false;
28static bool dac_enabled = false;
29
30/* convert tenth of dB volume (-780..+180) to dac3550 register value */
31int tenthdb2reg(int db)
32{
33 if (db < -540) /* 3 dB steps */
34 return (db + 780) / 30;
35 else /* 1.5 dB steps */
36 return (db + 660) / 15;
37}
38
39int dac_volume(unsigned int left, unsigned int right, bool deemph)
40{
41 int ret = 0;
42 unsigned char buf[3];
43
44 i2c_begin();
45
46 if (left > 0x38)
47 left = 0x38;
48 if (right > 0x38)
49 right = 0x38;
50
51 buf[0] = DAC_REG_WRITE | DAC_AVOL;
52 buf[1] = (left & 0x3f) | (deemph ? 0x40 : 0);
53 buf[2] = right & 0x3f;
54
55 /* send write command */
56 if (i2c_write(DAC_DEV_WRITE,buf,3))
57 {
58 ret = -1;
59 }
60
61 i2c_end();
62 return ret;
63}
64
65/******************************************************************
66** Bit6: 0 = 3V 1 = 5V
67** Bit5: 0 = normal 1 = low power
68** Bit4: 0 = AUX2 off 1 = AUX2 on
69** Bit3: 0 = AUX1 off 1 = AUX1 on
70** Bit2: 0 = DAC off 1 = DAC on
71** Bit1: 0 = stereo 1 = mono
72** Bit0: 0 = normal right amp 1 = inverted right amp
73******************************************************************/
74/* dac_config is called once to initialize it. we will apply
75 our static settings because of the init flow.
76 dac_init -> dac_line_in -> mpeg_init -> dac_config
77*/
78static int dac_config(void)
79{
80 int ret = 0;
81 unsigned char buf[2];
82
83 i2c_begin();
84
85 buf[0] = DAC_REG_WRITE | DAC_GCFG;
86 buf[1] = (dac_enabled ? 0x04 : 0) |
87 (line_in_enabled ? 0x08 : 0);
88
89 /* send write command */
90 if (i2c_write(DAC_DEV_WRITE,buf,2))
91 {
92 ret = -1;
93 }
94
95 i2c_end();
96 return ret;
97}
98
99void dac_enable(bool enable)
100{
101 dac_enabled = enable;
102 dac_config();
103}
104
105void dac_line_in(bool enable)
106{
107 line_in_enabled = enable;
108 dac_config();
109}
110
111void dac_init(void)
112{
113 unsigned char buf[2];
114
115 i2c_begin();
116
117 buf[0] = DAC_REG_WRITE | DAC_SR_REG;
118 buf[1] = 0x07;
119
120 /* send write command */
121 i2c_write(DAC_DEV_WRITE,buf,2);
122 i2c_end();
123}
124