diff options
author | Amaury Pouly <amaury.pouly@gmail.com> | 2013-06-18 16:11:51 +0200 |
---|---|---|
committer | Amaury Pouly <amaury.pouly@gmail.com> | 2013-06-18 16:11:51 +0200 |
commit | e735ce4693f85dc2ecb5d7290d1298f8b12c1e27 (patch) | |
tree | 891a0e103fcfa8aa01970d70a7c09961f2a26f34 /firmware | |
parent | d8368d58b0bd073ef6bed6a7b7d51c671b8ea4ae (diff) | |
download | rockbox-e735ce4693f85dc2ecb5d7290d1298f8b12c1e27.tar.gz rockbox-e735ce4693f85dc2ecb5d7290d1298f8b12c1e27.zip |
imx233: introduce generic audio routing driver
Change-Id: Icd439e02dd9835778d2733fc01a9306552b36966
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/target/arm/imx233/audio-imx233.c | 130 | ||||
-rw-r--r-- | firmware/target/arm/imx233/audio-imx233.h | 48 |
2 files changed, 178 insertions, 0 deletions
diff --git a/firmware/target/arm/imx233/audio-imx233.c b/firmware/target/arm/imx233/audio-imx233.c new file mode 100644 index 0000000000..54b1784cfa --- /dev/null +++ b/firmware/target/arm/imx233/audio-imx233.c | |||
@@ -0,0 +1,130 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2013 by Amaury Pouly | ||
11 | * | ||
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. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | #include "audiohw.h" | ||
22 | #include "audio-imx233.h" | ||
23 | #include "pinctrl-imx233.h" | ||
24 | |||
25 | void __attribute__((weak)) imx233_audio_preinit(void) | ||
26 | { | ||
27 | #ifdef IMX233_AUDIO_HP_GATE_BANK | ||
28 | imx233_pinctrl_acquire(IMX233_AUDIO_HP_GATE_BANK, IMX233_AUDIO_HP_GATE_PIN, "hp_gate"); | ||
29 | imx233_pinctrl_set_function(IMX233_AUDIO_HP_GATE_BANK, IMX233_AUDIO_HP_GATE_PIN, PINCTRL_FUNCTION_GPIO); | ||
30 | imx233_pinctrl_enable_gpio(IMX233_AUDIO_HP_GATE_BANK, IMX233_AUDIO_HP_GATE_PIN, true); | ||
31 | imx233_audio_enable_hp(false); | ||
32 | #endif | ||
33 | #ifdef IMX233_AUDIO_SPKR_GATE_BANK | ||
34 | imx233_pinctrl_acquire(IMX233_AUDIO_SPKR_GATE_BANK, IMX233_AUDIO_SPKR_GATE_PIN, "spkr_gate"); | ||
35 | imx233_pinctrl_set_function(IMX233_AUDIO_SPKR_GATE_BANK, IMX233_AUDIO_SPKR_GATE_PIN, PINCTRL_FUNCTION_GPIO); | ||
36 | imx233_pinctrl_enable_gpio(IMX233_AUDIO_SPKR_GATE_BANK, IMX233_AUDIO_SPKR_GATE_PIN, true); | ||
37 | imx233_audio_enable_spkr(false); | ||
38 | #endif | ||
39 | } | ||
40 | |||
41 | void __attribute__((weak)) imx233_audio_postinit(void) | ||
42 | { | ||
43 | imx233_audio_enable_hp(true); | ||
44 | } | ||
45 | // enable/disable the HP audio gate (typically using a GPIO) | ||
46 | void __attribute__((weak)) imx233_audio_enable_hp(bool en) | ||
47 | { | ||
48 | #ifdef IMX233_AUDIO_HP_GATE_BANK | ||
49 | # ifdef IMX233_AUDIO_HP_GATE_INVERTED | ||
50 | en = !en; | ||
51 | # endif | ||
52 | imx233_pinctrl_set_gpio(IMX233_AUDIO_HP_GATE_BANK, IMX233_AUDIO_HP_GATE_PIN, en); | ||
53 | #else | ||
54 | (void) en; | ||
55 | #endif | ||
56 | } | ||
57 | // enable/disable the speaker audio gate (typically using a GPIO) | ||
58 | void __attribute__((weak)) imx233_audio_enable_spkr(bool en) | ||
59 | { | ||
60 | #ifdef IMX233_AUDIO_SPKR_GATE_BANK | ||
61 | # ifdef IMX233_AUDIO_SPKR_GATE_INVERTED | ||
62 | en = !en; | ||
63 | # endif | ||
64 | imx233_pinctrl_set_gpio(IMX233_AUDIO_SPKR_GATE_BANK, IMX233_AUDIO_SPKR_GATE_PIN, en); | ||
65 | #else | ||
66 | (void) en; | ||
67 | #endif | ||
68 | } | ||
69 | |||
70 | static int input_source = AUDIO_SRC_PLAYBACK; | ||
71 | static unsigned input_flags = 0; | ||
72 | static int output_source = AUDIO_SRC_PLAYBACK; | ||
73 | |||
74 | static void select_audio_path(void) | ||
75 | { | ||
76 | #if defined(HAVE_RECORDING) | ||
77 | const bool recording = input_flags & SRCF_RECORDING; | ||
78 | #else | ||
79 | const bool recording = false; | ||
80 | #endif | ||
81 | |||
82 | switch(input_source) | ||
83 | { | ||
84 | default: | ||
85 | /* playback and no recording */ | ||
86 | input_source = AUDIO_SRC_PLAYBACK; | ||
87 | /* fallthrough */ | ||
88 | case AUDIO_SRC_PLAYBACK: | ||
89 | audiohw_set_monitor(false); | ||
90 | audiohw_disable_recording(); | ||
91 | break; | ||
92 | |||
93 | #if defined(HAVE_RECORDING) && (INPUT_SRC_CAPS & SRC_CAP_MIC) | ||
94 | /* recording only */ | ||
95 | case AUDIO_SRC_MIC: | ||
96 | audiohw_set_monitor(false); | ||
97 | audiohw_enable_recording(true); | ||
98 | break; | ||
99 | #endif | ||
100 | |||
101 | #if (INPUT_SRC_CAPS & SRC_CAP_FMRADIO) | ||
102 | /* recording and playback */ | ||
103 | case AUDIO_SRC_FMRADIO: | ||
104 | if (recording) | ||
105 | { | ||
106 | audiohw_set_monitor(false); | ||
107 | audiohw_enable_recording(false); | ||
108 | } | ||
109 | else | ||
110 | { | ||
111 | audiohw_disable_recording(); | ||
112 | audiohw_set_monitor(true); /* line 2 analog audio path */ | ||
113 | } | ||
114 | break; | ||
115 | #endif /* (INPUT_SRC_CAPS & SRC_CAP_FMRADIO) */ | ||
116 | } | ||
117 | } | ||
118 | |||
119 | void __attribute__((weak)) audio_input_mux(int source, unsigned flags) | ||
120 | { | ||
121 | input_source = source; | ||
122 | input_flags = flags; | ||
123 | select_audio_path(); | ||
124 | } | ||
125 | |||
126 | void __attribute__((weak)) audio_set_output_source(int source) | ||
127 | { | ||
128 | output_source = source; | ||
129 | select_audio_path(); | ||
130 | } | ||
diff --git a/firmware/target/arm/imx233/audio-imx233.h b/firmware/target/arm/imx233/audio-imx233.h new file mode 100644 index 0000000000..dd0cdeb63a --- /dev/null +++ b/firmware/target/arm/imx233/audio-imx233.h | |||
@@ -0,0 +1,48 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2013 by Amaury Pouly | ||
11 | * | ||
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. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | #ifndef __audio_imx233__ | ||
22 | #define __audio_imx233__ | ||
23 | |||
24 | #include "audio.h" | ||
25 | #include "audio-target.h" | ||
26 | |||
27 | /* target can override those functions to provide hooks to the audio code | ||
28 | * alternativelly, the default implementation provide support for GPIO | ||
29 | * controlled gates using the following defines | ||
30 | * NOTE by default gates are enabled by setting GPIO to 1 (except if inverted) | ||
31 | * | ||
32 | * IMX233_AUDIO_HP_GATE_BANK (gpio bank) | ||
33 | * IMX233_AUDIO_HP_GATE_PIN (gpio pin) | ||
34 | * IMX233_AUDIO_HP_GATE_INVERTED (define if inverted) | ||
35 | * | ||
36 | * IMX233_AUDIO_SPKR_GATE_BANK (gpio bank) | ||
37 | * IMX233_AUDIO_SPKR_GATE_PIN (gpio pin) | ||
38 | * IMX233_AUDIO_SPKR_GATE_INVERTED (define if inverted) | ||
39 | */ | ||
40 | // do some initialisation related to next functions | ||
41 | void imx233_audio_preinit(void); | ||
42 | void imx233_audio_postinit(void); | ||
43 | // enable/disable the HP audio gate (typically using a GPIO) | ||
44 | void imx233_audio_enable_hp(bool en); | ||
45 | // enable/disable the speaker audio gate (typically using a GPIO) | ||
46 | void imx233_audio_enable_spkr(bool en); | ||
47 | |||
48 | #endif /* __audio_imx233__ */ \ No newline at end of file | ||