aboutsummaryrefslogtreecommitdiffstats
path: root/sound/core
diff options
context:
space:
mode:
authorJyri Sarha <jsarha@ti.com>2016-03-31 09:35:58 -0400
committerMark Brown <broonie@kernel.org>2016-04-06 14:47:48 -0400
commit4a4436573a6669516f73bac25016683d396ed4c4 (patch)
treea776d721808873a645baba6f25a0f973c7995c24 /sound/core
parentf55532a0c0b8bb6148f4e07853b876ef73bc69ca (diff)
ALSA: pcm: add IEC958 channel status helper for hw_params
Add IEC958 channel status helper that gets the audio properties from snd_pcm_hw_params instead of snd_pcm_runtime. This is needed to produce the channel status bits already in audio stream configuration phase. Signed-off-by: Jyri Sarha <jsarha@ti.com> Reviewed-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'sound/core')
-rw-r--r--sound/core/pcm_iec958.c64
1 files changed, 47 insertions, 17 deletions
diff --git a/sound/core/pcm_iec958.c b/sound/core/pcm_iec958.c
index 36b2d7aca1bd..e016871a978f 100644
--- a/sound/core/pcm_iec958.c
+++ b/sound/core/pcm_iec958.c
@@ -9,30 +9,18 @@
9#include <linux/types.h> 9#include <linux/types.h>
10#include <sound/asoundef.h> 10#include <sound/asoundef.h>
11#include <sound/pcm.h> 11#include <sound/pcm.h>
12#include <sound/pcm_params.h>
12#include <sound/pcm_iec958.h> 13#include <sound/pcm_iec958.h>
13 14
14/** 15static int create_iec958_consumer(uint rate, uint sample_width,
15 * snd_pcm_create_iec958_consumer - create consumer format IEC958 channel status 16 u8 *cs, size_t len)
16 * @runtime: pcm runtime structure with ->rate filled in
17 * @cs: channel status buffer, at least four bytes
18 * @len: length of channel status buffer
19 *
20 * Create the consumer format channel status data in @cs of maximum size
21 * @len corresponding to the parameters of the PCM runtime @runtime.
22 *
23 * Drivers may wish to tweak the contents of the buffer after creation.
24 *
25 * Returns: length of buffer, or negative error code if something failed.
26 */
27int snd_pcm_create_iec958_consumer(struct snd_pcm_runtime *runtime, u8 *cs,
28 size_t len)
29{ 17{
30 unsigned int fs, ws; 18 unsigned int fs, ws;
31 19
32 if (len < 4) 20 if (len < 4)
33 return -EINVAL; 21 return -EINVAL;
34 22
35 switch (runtime->rate) { 23 switch (rate) {
36 case 32000: 24 case 32000:
37 fs = IEC958_AES3_CON_FS_32000; 25 fs = IEC958_AES3_CON_FS_32000;
38 break; 26 break;
@@ -59,7 +47,7 @@ int snd_pcm_create_iec958_consumer(struct snd_pcm_runtime *runtime, u8 *cs,
59 } 47 }
60 48
61 if (len > 4) { 49 if (len > 4) {
62 switch (snd_pcm_format_width(runtime->format)) { 50 switch (sample_width) {
63 case 16: 51 case 16:
64 ws = IEC958_AES4_CON_WORDLEN_20_16; 52 ws = IEC958_AES4_CON_WORDLEN_20_16;
65 break; 53 break;
@@ -92,4 +80,46 @@ int snd_pcm_create_iec958_consumer(struct snd_pcm_runtime *runtime, u8 *cs,
92 80
93 return len; 81 return len;
94} 82}
83
84/**
85 * snd_pcm_create_iec958_consumer - create consumer format IEC958 channel status
86 * @runtime: pcm runtime structure with ->rate filled in
87 * @cs: channel status buffer, at least four bytes
88 * @len: length of channel status buffer
89 *
90 * Create the consumer format channel status data in @cs of maximum size
91 * @len corresponding to the parameters of the PCM runtime @runtime.
92 *
93 * Drivers may wish to tweak the contents of the buffer after creation.
94 *
95 * Returns: length of buffer, or negative error code if something failed.
96 */
97int snd_pcm_create_iec958_consumer(struct snd_pcm_runtime *runtime, u8 *cs,
98 size_t len)
99{
100 return create_iec958_consumer(runtime->rate,
101 snd_pcm_format_width(runtime->format),
102 cs, len);
103}
95EXPORT_SYMBOL(snd_pcm_create_iec958_consumer); 104EXPORT_SYMBOL(snd_pcm_create_iec958_consumer);
105
106/**
107 * snd_pcm_create_iec958_consumer_hw_params - create IEC958 channel status
108 * @hw_params: the hw_params instance for extracting rate and sample format
109 * @cs: channel status buffer, at least four bytes
110 * @len: length of channel status buffer
111 *
112 * Create the consumer format channel status data in @cs of maximum size
113 * @len corresponding to the parameters of the PCM runtime @runtime.
114 *
115 * Drivers may wish to tweak the contents of the buffer after creation.
116 *
117 * Returns: length of buffer, or negative error code if something failed.
118 */
119int snd_pcm_create_iec958_consumer_hw_params(struct snd_pcm_hw_params *params,
120 u8 *cs, size_t len)
121{
122 return create_iec958_consumer(params_rate(params), params_width(params),
123 cs, len);
124}
125EXPORT_SYMBOL(snd_pcm_create_iec958_consumer_hw_params);