include Car Adapter Mode description on all players that have it. Fixes FS#7431.
[Rockbox.git] / firmware / drivers / dac.c
blob4212b322f0d16002b974f449f68c6ef1e05c544f
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 by Linus Nielsen Feltzing
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
19 #include "config.h"
20 #include "stdbool.h"
21 #include "i2c.h"
22 #include "debug.h"
23 #include "dac.h"
25 #ifdef HAVE_DAC3550A
27 static bool line_in_enabled = false;
28 static bool dac_enabled = false;
31 int dac_volume(unsigned int left, unsigned int right, bool deemph)
33 int ret = 0;
34 unsigned char buf[3];
36 i2c_begin();
38 if (left > 0x38)
39 left = 0x38;
40 if (right > 0x38)
41 right = 0x38;
43 buf[0] = DAC_REG_WRITE | DAC_AVOL;
44 buf[1] = (left & 0x3f) | (deemph ? 0x40 : 0);
45 buf[2] = right & 0x3f;
47 /* send write command */
48 if (i2c_write(DAC_DEV_WRITE,buf,3))
50 ret = -1;
53 i2c_end();
54 return ret;
57 /******************************************************************
58 ** Bit6: 0 = 3V 1 = 5V
59 ** Bit5: 0 = normal 1 = low power
60 ** Bit4: 0 = AUX2 off 1 = AUX2 on
61 ** Bit3: 0 = AUX1 off 1 = AUX1 on
62 ** Bit2: 0 = DAC off 1 = DAC on
63 ** Bit1: 0 = stereo 1 = mono
64 ** Bit0: 0 = normal right amp 1 = inverted right amp
65 ******************************************************************/
66 /* dac_config is called once to initialize it. we will apply
67 our static settings because of the init flow.
68 dac_init -> dac_line_in -> mpeg_init -> dac_config
70 static int dac_config(void)
72 int ret = 0;
73 unsigned char buf[2];
75 i2c_begin();
77 buf[0] = DAC_REG_WRITE | DAC_GCFG;
78 buf[1] = (dac_enabled ? 0x04 : 0) |
79 (line_in_enabled ? 0x08 : 0);
81 /* send write command */
82 if (i2c_write(DAC_DEV_WRITE,buf,2))
84 ret = -1;
87 i2c_end();
88 return ret;
91 void dac_enable(bool enable)
93 dac_enabled = enable;
94 dac_config();
97 void dac_line_in(bool enable)
99 line_in_enabled = enable;
100 dac_config();
103 void dac_init(void)
105 unsigned char buf[2];
107 i2c_begin();
109 buf[0] = DAC_REG_WRITE | DAC_SR_REG;
110 buf[1] = 0x07;
112 /* send write command */
113 i2c_write(DAC_DEV_WRITE,buf,2);
114 i2c_end();
117 #endif