Fix include problem
[kugel-rb.git] / firmware / drivers / dac.c
blobf21ef9a80299c91fea8719dcc8ae5fda57ff9d52
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 by Linus Nielsen Feltzing
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #include "config.h"
22 #include "stdbool.h"
23 #include "i2c.h"
24 #include "debug.h"
25 #include "dac.h"
27 #ifdef HAVE_DAC3550A
29 static bool line_in_enabled = false;
30 static bool dac_enabled = false;
33 int dac_volume(unsigned int left, unsigned int right, bool deemph)
35 int ret = 0;
36 unsigned char buf[3];
38 i2c_begin();
40 if (left > 0x38)
41 left = 0x38;
42 if (right > 0x38)
43 right = 0x38;
45 buf[0] = DAC_REG_WRITE | DAC_AVOL;
46 buf[1] = (left & 0x3f) | (deemph ? 0x40 : 0);
47 buf[2] = right & 0x3f;
49 /* send write command */
50 if (i2c_write(DAC_DEV_WRITE,buf,3))
52 ret = -1;
55 i2c_end();
56 return ret;
59 /******************************************************************
60 ** Bit6: 0 = 3V 1 = 5V
61 ** Bit5: 0 = normal 1 = low power
62 ** Bit4: 0 = AUX2 off 1 = AUX2 on
63 ** Bit3: 0 = AUX1 off 1 = AUX1 on
64 ** Bit2: 0 = DAC off 1 = DAC on
65 ** Bit1: 0 = stereo 1 = mono
66 ** Bit0: 0 = normal right amp 1 = inverted right amp
67 ******************************************************************/
68 /* dac_config is called once to initialize it. we will apply
69 our static settings because of the init flow.
70 dac_init -> dac_line_in -> mpeg_init -> dac_config
72 static int dac_config(void)
74 int ret = 0;
75 unsigned char buf[2];
77 i2c_begin();
79 buf[0] = DAC_REG_WRITE | DAC_GCFG;
80 buf[1] = (dac_enabled ? 0x04 : 0) |
81 (line_in_enabled ? 0x08 : 0);
83 /* send write command */
84 if (i2c_write(DAC_DEV_WRITE,buf,2))
86 ret = -1;
89 i2c_end();
90 return ret;
93 void dac_enable(bool enable)
95 dac_enabled = enable;
96 dac_config();
99 void dac_line_in(bool enable)
101 line_in_enabled = enable;
102 dac_config();
105 void dac_init(void)
107 unsigned char buf[2];
109 i2c_begin();
111 buf[0] = DAC_REG_WRITE | DAC_SR_REG;
112 buf[1] = 0x07;
114 /* send write command */
115 i2c_write(DAC_DEV_WRITE,buf,2);
116 i2c_end();
119 #endif