Linus Nielsen Feltzing | a2b0490 | 2002-05-16 21:03:57 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2002 by Linus Nielsen Feltzing |
| 11 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame^] | 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. |
Linus Nielsen Feltzing | a2b0490 | 2002-05-16 21:03:57 +0000 | [diff] [blame] | 16 | * |
| 17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 18 | * KIND, either express or implied. |
| 19 | * |
| 20 | ****************************************************************************/ |
Linus Nielsen Feltzing | bd7fc37 | 2002-08-16 07:16:52 +0000 | [diff] [blame] | 21 | #include "config.h" |
Linus Nielsen Feltzing | a8f1419 | 2002-06-27 08:28:51 +0000 | [diff] [blame] | 22 | #include "stdbool.h" |
Linus Nielsen Feltzing | a2b0490 | 2002-05-16 21:03:57 +0000 | [diff] [blame] | 23 | #include "i2c.h" |
| 24 | #include "debug.h" |
| 25 | #include "dac.h" |
| 26 | |
Linus Nielsen Feltzing | bd7fc37 | 2002-08-16 07:16:52 +0000 | [diff] [blame] | 27 | #ifdef HAVE_DAC3550A |
| 28 | |
Linus Nielsen Feltzing | c22b411 | 2003-11-03 23:36:36 +0000 | [diff] [blame] | 29 | static bool line_in_enabled = false; |
| 30 | static bool dac_enabled = false; |
| 31 | |
| 32 | |
Linus Nielsen Feltzing | a8f1419 | 2002-06-27 08:28:51 +0000 | [diff] [blame] | 33 | int dac_volume(unsigned int left, unsigned int right, bool deemph) |
Linus Nielsen Feltzing | a2b0490 | 2002-05-16 21:03:57 +0000 | [diff] [blame] | 34 | { |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 35 | int ret = 0; |
| 36 | unsigned char buf[3]; |
| 37 | |
| 38 | i2c_begin(); |
Linus Nielsen Feltzing | a2b0490 | 2002-05-16 21:03:57 +0000 | [diff] [blame] | 39 | |
Linus Nielsen Feltzing | a8f1419 | 2002-06-27 08:28:51 +0000 | [diff] [blame] | 40 | if (left > 0x38) |
| 41 | left = 0x38; |
| 42 | if (right > 0x38) |
| 43 | right = 0x38; |
Linus Nielsen Feltzing | a2b0490 | 2002-05-16 21:03:57 +0000 | [diff] [blame] | 44 | |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 45 | buf[0] = DAC_REG_WRITE | DAC_AVOL; |
Linus Nielsen Feltzing | a8f1419 | 2002-06-27 08:28:51 +0000 | [diff] [blame] | 46 | buf[1] = (left & 0x3f) | (deemph ? 0x40 : 0); |
| 47 | buf[2] = right & 0x3f; |
Linus Nielsen Feltzing | a2b0490 | 2002-05-16 21:03:57 +0000 | [diff] [blame] | 48 | |
Linus Nielsen Feltzing | 5407edc | 2002-08-14 12:54:38 +0000 | [diff] [blame] | 49 | /* send write command */ |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 50 | if (i2c_write(DAC_DEV_WRITE,buf,3)) |
Linus Nielsen Feltzing | a2b0490 | 2002-05-16 21:03:57 +0000 | [diff] [blame] | 51 | { |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 52 | ret = -1; |
Linus Nielsen Feltzing | a2b0490 | 2002-05-16 21:03:57 +0000 | [diff] [blame] | 53 | } |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 54 | |
| 55 | i2c_end(); |
| 56 | return ret; |
Linus Nielsen Feltzing | a2b0490 | 2002-05-16 21:03:57 +0000 | [diff] [blame] | 57 | } |
| 58 | |
Linus Nielsen Feltzing | afd30bb | 2002-05-16 21:32:04 +0000 | [diff] [blame] | 59 | /****************************************************************** |
| 60 | ** Bit6: 0 = 3V 1 = 5V |
| 61 | ** Bit5: 0 = normal 1 = low power |
| 62 | ** Bit4: 0 = AUX2 off 1 = AUX2 on |
Linus Nielsen Feltzing | c22b411 | 2003-11-03 23:36:36 +0000 | [diff] [blame] | 63 | ** Bit3: 0 = AUX1 off 1 = AUX1 on |
Linus Nielsen Feltzing | afd30bb | 2002-05-16 21:32:04 +0000 | [diff] [blame] | 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 | ******************************************************************/ |
Linus Nielsen Feltzing | c22b411 | 2003-11-03 23:36:36 +0000 | [diff] [blame] | 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 |
| 71 | */ |
| 72 | static int dac_config(void) |
Linus Nielsen Feltzing | a2b0490 | 2002-05-16 21:03:57 +0000 | [diff] [blame] | 73 | { |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 74 | int ret = 0; |
| 75 | unsigned char buf[2]; |
Linus Nielsen Feltzing | a2b0490 | 2002-05-16 21:03:57 +0000 | [diff] [blame] | 76 | |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 77 | i2c_begin(); |
| 78 | |
| 79 | buf[0] = DAC_REG_WRITE | DAC_GCFG; |
Linus Nielsen Feltzing | c22b411 | 2003-11-03 23:36:36 +0000 | [diff] [blame] | 80 | buf[1] = (dac_enabled ? 0x04 : 0) | |
| 81 | (line_in_enabled ? 0x08 : 0); |
Linus Nielsen Feltzing | a2b0490 | 2002-05-16 21:03:57 +0000 | [diff] [blame] | 82 | |
Linus Nielsen Feltzing | 5407edc | 2002-08-14 12:54:38 +0000 | [diff] [blame] | 83 | /* send write command */ |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 84 | if (i2c_write(DAC_DEV_WRITE,buf,2)) |
Linus Nielsen Feltzing | a2b0490 | 2002-05-16 21:03:57 +0000 | [diff] [blame] | 85 | { |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 86 | ret = -1; |
Linus Nielsen Feltzing | a2b0490 | 2002-05-16 21:03:57 +0000 | [diff] [blame] | 87 | } |
Linus Nielsen Feltzing | e1cb054 | 2002-06-24 12:35:37 +0000 | [diff] [blame] | 88 | |
| 89 | i2c_end(); |
Linus Nielsen Feltzing | 6dc368a | 2002-06-25 11:22:53 +0000 | [diff] [blame] | 90 | return ret; |
Linus Nielsen Feltzing | a2b0490 | 2002-05-16 21:03:57 +0000 | [diff] [blame] | 91 | } |
Linus Nielsen Feltzing | 5407edc | 2002-08-14 12:54:38 +0000 | [diff] [blame] | 92 | |
Linus Nielsen Feltzing | c22b411 | 2003-11-03 23:36:36 +0000 | [diff] [blame] | 93 | void dac_enable(bool enable) |
| 94 | { |
| 95 | dac_enabled = enable; |
| 96 | dac_config(); |
| 97 | } |
| 98 | |
| 99 | void dac_line_in(bool enable) |
| 100 | { |
| 101 | line_in_enabled = enable; |
| 102 | dac_config(); |
| 103 | } |
| 104 | |
Linus Nielsen Feltzing | 5407edc | 2002-08-14 12:54:38 +0000 | [diff] [blame] | 105 | void 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 Feltzing | bd7fc37 | 2002-08-16 07:16:52 +0000 | [diff] [blame] | 118 | |
| 119 | #endif |