summaryrefslogtreecommitdiff
path: root/firmware/target/coldfire/iriver/h100/spdif-h100.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/coldfire/iriver/h100/spdif-h100.c')
-rw-r--r--firmware/target/coldfire/iriver/h100/spdif-h100.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/firmware/target/coldfire/iriver/h100/spdif-h100.c b/firmware/target/coldfire/iriver/h100/spdif-h100.c
new file mode 100644
index 0000000000..20e5bc3c45
--- /dev/null
+++ b/firmware/target/coldfire/iriver/h100/spdif-h100.c
@@ -0,0 +1,83 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 by Michal Sevakis
11 * Based on the work of Thom Johansen
12 *
13 * All files in this archive are subject to the GNU General Public License.
14 * See the file COPYING in the source tree root for full license agreement.
15 *
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
18 *
19 ****************************************************************************/
20#include <stdbool.h>
21#include "config.h"
22#include "cpu.h"
23#include "power.h"
24#include "system.h"
25#include "audio.h"
26#include "spdif.h"
27
28static int spdif_source = AUDIO_SRC_PLAYBACK;
29static int spdif_on = false;
30
31/* Initialize the S/PDIF driver */
32void spdif_init(void)
33{
34 /* PHASECONFIG setup: gain = 3*2^13, source = EBUIN */
35 PHASECONFIG = (6 << 3) | (4 << 0);
36 spdif_set_output_source(AUDIO_SRC_PLAYBACK, true);
37}
38
39/* Return the S/PDIF frequency in herz - unrounded */
40unsigned long spdif_measure_frequency(void)
41{
42 /* The following formula is specified in MCF5249 user's manual section
43 * 17.6.1. The 128 divide is because of the fact that the SPDIF clock is
44 * the sample rate times 128.
45 */
46 return (unsigned long)((unsigned long long)FREQMEAS*CPU_FREQ /
47 ((1 << 15)*3*(1 << 13))/128);
48} /* spdif_measure_frequency */
49
50/* Set the S/PDIF audio feed */
51void spdif_set_output_source(int source, bool src_on)
52{
53 static const unsigned short ebu1_config[] =
54 {
55 /* SCLK2, TXSRC = PDOR3, validity, normal operation */
56 [AUDIO_SRC_PLAYBACK+1] = (7 << 12) | (3 << 8) | (1 << 5) | (5 << 2),
57 /* Input source is EBUin1, Feed-through monitoring */
58 [AUDIO_SRC_SPDIF+1] = (1 << 2),
59 /* SCLK2, TXSRC = IIS1recv, validity, normal operation */
60 [AUDIO_SRC_MIC+1] = (7 << 12) | (4 << 8) | (1 << 5) | (5 << 2),
61 [AUDIO_SRC_LINEIN+1] = (7 << 12) | (4 << 8) | (1 << 5) | (5 << 2),
62 [AUDIO_SRC_FMRADIO+1] = (7 << 12) | (4 << 8) | (1 << 5) | (5 << 2),
63 };
64
65 if ((unsigned)source >= ARRAYLEN(ebu1_config))
66 source = AUDIO_SRC_PLAYBACK;
67
68 EBU1CONFIG = 0x800; /* Reset before reprogram */
69
70 spdif_source = source;
71 spdif_on = spdif_powered() && src_on;
72
73 /* Tranceiver must be powered or else monitoring will be disabled */
74 EBU1CONFIG = spdif_on ? ebu1_config[source + 1] : 0;
75} /* spdif_set_output_source */
76
77/* Return the last set S/PDIF audio source */
78int spdif_get_output_source(bool *src_on)
79{
80 if (src_on != NULL)
81 *src_on = spdif_on;
82 return spdif_source;
83} /* spdif_get_output_source */