Fix playlist catalog directory manual spelling
[maemo-rb.git] / firmware / drivers / audio / dac3550a.c
blobe13602e48199a35e9cf8fb8c749f5dd44cb8ed0f
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: dac.c 17847 2008-06-28 18:10:04Z bagder $
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 "dac3550a.h"
27 static bool line_in_enabled = false;
28 static bool dac_enabled = false;
30 /* convert tenth of dB volume (-780..+180) to dac3550 register value */
31 int tenthdb2reg(int db)
33 if (db < -540) /* 3 dB steps */
34 return (db + 780) / 30;
35 else /* 1.5 dB steps */
36 return (db + 660) / 15;
39 int dac_volume(unsigned int left, unsigned int right, bool deemph)
41 int ret = 0;
42 unsigned char buf[3];
44 i2c_begin();
46 if (left > 0x38)
47 left = 0x38;
48 if (right > 0x38)
49 right = 0x38;
51 buf[0] = DAC_REG_WRITE | DAC_AVOL;
52 buf[1] = (left & 0x3f) | (deemph ? 0x40 : 0);
53 buf[2] = right & 0x3f;
55 /* send write command */
56 if (i2c_write(DAC_DEV_WRITE,buf,3))
58 ret = -1;
61 i2c_end();
62 return ret;
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
78 static int dac_config(void)
80 int ret = 0;
81 unsigned char buf[2];
83 i2c_begin();
85 buf[0] = DAC_REG_WRITE | DAC_GCFG;
86 buf[1] = (dac_enabled ? 0x04 : 0) |
87 (line_in_enabled ? 0x08 : 0);
89 /* send write command */
90 if (i2c_write(DAC_DEV_WRITE,buf,2))
92 ret = -1;
95 i2c_end();
96 return ret;
99 void dac_enable(bool enable)
101 dac_enabled = enable;
102 dac_config();
105 void dac_line_in(bool enable)
107 line_in_enabled = enable;
108 dac_config();
111 void dac_init(void)
113 unsigned char buf[2];
115 i2c_begin();
117 buf[0] = DAC_REG_WRITE | DAC_SR_REG;
118 buf[1] = 0x07;
120 /* send write command */
121 i2c_write(DAC_DEV_WRITE,buf,2);
122 i2c_end();