blob: f21ef9a80299c91fea8719dcc8ae5fda57ff9d52 [file] [log] [blame]
Linus Nielsen Feltzinga2b04902002-05-16 21:03:57 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Linus Nielsen Feltzing
11 *
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000012 * 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.
Linus Nielsen Feltzinga2b04902002-05-16 21:03:57 +000016 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
Linus Nielsen Feltzingbd7fc372002-08-16 07:16:52 +000021#include "config.h"
Linus Nielsen Feltzinga8f14192002-06-27 08:28:51 +000022#include "stdbool.h"
Linus Nielsen Feltzinga2b04902002-05-16 21:03:57 +000023#include "i2c.h"
24#include "debug.h"
25#include "dac.h"
26
Linus Nielsen Feltzingbd7fc372002-08-16 07:16:52 +000027#ifdef HAVE_DAC3550A
28
Linus Nielsen Feltzingc22b4112003-11-03 23:36:36 +000029static bool line_in_enabled = false;
30static bool dac_enabled = false;
31
32
Linus Nielsen Feltzinga8f14192002-06-27 08:28:51 +000033int dac_volume(unsigned int left, unsigned int right, bool deemph)
Linus Nielsen Feltzinga2b04902002-05-16 21:03:57 +000034{
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +000035 int ret = 0;
36 unsigned char buf[3];
37
38 i2c_begin();
Linus Nielsen Feltzinga2b04902002-05-16 21:03:57 +000039
Linus Nielsen Feltzinga8f14192002-06-27 08:28:51 +000040 if (left > 0x38)
41 left = 0x38;
42 if (right > 0x38)
43 right = 0x38;
Linus Nielsen Feltzinga2b04902002-05-16 21:03:57 +000044
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +000045 buf[0] = DAC_REG_WRITE | DAC_AVOL;
Linus Nielsen Feltzinga8f14192002-06-27 08:28:51 +000046 buf[1] = (left & 0x3f) | (deemph ? 0x40 : 0);
47 buf[2] = right & 0x3f;
Linus Nielsen Feltzinga2b04902002-05-16 21:03:57 +000048
Linus Nielsen Feltzing5407edc2002-08-14 12:54:38 +000049 /* send write command */
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +000050 if (i2c_write(DAC_DEV_WRITE,buf,3))
Linus Nielsen Feltzinga2b04902002-05-16 21:03:57 +000051 {
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +000052 ret = -1;
Linus Nielsen Feltzinga2b04902002-05-16 21:03:57 +000053 }
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +000054
55 i2c_end();
56 return ret;
Linus Nielsen Feltzinga2b04902002-05-16 21:03:57 +000057}
58
Linus Nielsen Feltzingafd30bb2002-05-16 21:32:04 +000059/******************************************************************
60** Bit6: 0 = 3V 1 = 5V
61** Bit5: 0 = normal 1 = low power
62** Bit4: 0 = AUX2 off 1 = AUX2 on
Linus Nielsen Feltzingc22b4112003-11-03 23:36:36 +000063** Bit3: 0 = AUX1 off 1 = AUX1 on
Linus Nielsen Feltzingafd30bb2002-05-16 21:32:04 +000064** Bit2: 0 = DAC off 1 = DAC on
65** Bit1: 0 = stereo 1 = mono
66** Bit0: 0 = normal right amp 1 = inverted right amp
67******************************************************************/
Linus Nielsen Feltzingc22b4112003-11-03 23:36:36 +000068/* 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
71*/
72static int dac_config(void)
Linus Nielsen Feltzinga2b04902002-05-16 21:03:57 +000073{
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +000074 int ret = 0;
75 unsigned char buf[2];
Linus Nielsen Feltzinga2b04902002-05-16 21:03:57 +000076
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +000077 i2c_begin();
78
79 buf[0] = DAC_REG_WRITE | DAC_GCFG;
Linus Nielsen Feltzingc22b4112003-11-03 23:36:36 +000080 buf[1] = (dac_enabled ? 0x04 : 0) |
81 (line_in_enabled ? 0x08 : 0);
Linus Nielsen Feltzinga2b04902002-05-16 21:03:57 +000082
Linus Nielsen Feltzing5407edc2002-08-14 12:54:38 +000083 /* send write command */
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +000084 if (i2c_write(DAC_DEV_WRITE,buf,2))
Linus Nielsen Feltzinga2b04902002-05-16 21:03:57 +000085 {
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +000086 ret = -1;
Linus Nielsen Feltzinga2b04902002-05-16 21:03:57 +000087 }
Linus Nielsen Feltzinge1cb0542002-06-24 12:35:37 +000088
89 i2c_end();
Linus Nielsen Feltzing6dc368a2002-06-25 11:22:53 +000090 return ret;
Linus Nielsen Feltzinga2b04902002-05-16 21:03:57 +000091}
Linus Nielsen Feltzing5407edc2002-08-14 12:54:38 +000092
Linus Nielsen Feltzingc22b4112003-11-03 23:36:36 +000093void dac_enable(bool enable)
94{
95 dac_enabled = enable;
96 dac_config();
97}
98
99void dac_line_in(bool enable)
100{
101 line_in_enabled = enable;
102 dac_config();
103}
104
Linus Nielsen Feltzing5407edc2002-08-14 12:54:38 +0000105void dac_init(void)
106{
107 unsigned char buf[2];
108
109 i2c_begin();
110
111 buf[0] = DAC_REG_WRITE | DAC_SR_REG;
112 buf[1] = 0x07;
113
114 /* send write command */
115 i2c_write(DAC_DEV_WRITE,buf,2);
116 i2c_end();
117}
Linus Nielsen Feltzingbd7fc372002-08-16 07:16:52 +0000118
119#endif