1 // SPDX-License-Identifier: GPL-2.0-only
5 #include <linux/export.h>
6 #include <linux/types.h>
7 #include <sound/asoundef.h>
9 #include <sound/pcm_params.h>
10 #include <sound/pcm_iec958.h>
12 static int create_iec958_consumer(uint rate, uint sample_width,
22 fs = IEC958_AES3_CON_FS_32000;
25 fs = IEC958_AES3_CON_FS_44100;
28 fs = IEC958_AES3_CON_FS_48000;
31 fs = IEC958_AES3_CON_FS_88200;
34 fs = IEC958_AES3_CON_FS_96000;
37 fs = IEC958_AES3_CON_FS_176400;
40 fs = IEC958_AES3_CON_FS_192000;
47 switch (sample_width) {
49 ws = IEC958_AES4_CON_WORDLEN_20_16;
52 ws = IEC958_AES4_CON_WORDLEN_22_18;
55 ws = IEC958_AES4_CON_WORDLEN_20_16 |
56 IEC958_AES4_CON_MAX_WORDLEN_24;
59 case 32: /* Assume 24-bit width for 32-bit samples. */
60 ws = IEC958_AES4_CON_WORDLEN_24_20 |
61 IEC958_AES4_CON_MAX_WORDLEN_24;
71 cs[0] = IEC958_AES0_CON_NOT_COPYRIGHT | IEC958_AES0_CON_EMPHASIS_NONE;
72 cs[1] = IEC958_AES1_CON_GENERAL;
73 cs[2] = IEC958_AES2_CON_SOURCE_UNSPEC | IEC958_AES2_CON_CHANNEL_UNSPEC;
74 cs[3] = IEC958_AES3_CON_CLOCK_1000PPM | fs;
83 * snd_pcm_create_iec958_consumer - create consumer format IEC958 channel status
84 * @runtime: pcm runtime structure with ->rate filled in
85 * @cs: channel status buffer, at least four bytes
86 * @len: length of channel status buffer
88 * Create the consumer format channel status data in @cs of maximum size
89 * @len corresponding to the parameters of the PCM runtime @runtime.
91 * Drivers may wish to tweak the contents of the buffer after creation.
93 * Returns: length of buffer, or negative error code if something failed.
95 int snd_pcm_create_iec958_consumer(struct snd_pcm_runtime *runtime, u8 *cs,
98 return create_iec958_consumer(runtime->rate,
99 snd_pcm_format_width(runtime->format),
102 EXPORT_SYMBOL(snd_pcm_create_iec958_consumer);
105 * snd_pcm_create_iec958_consumer_hw_params - create IEC958 channel status
106 * @hw_params: the hw_params instance for extracting rate and sample format
107 * @cs: channel status buffer, at least four bytes
108 * @len: length of channel status buffer
110 * Create the consumer format channel status data in @cs of maximum size
111 * @len corresponding to the parameters of the PCM runtime @runtime.
113 * Drivers may wish to tweak the contents of the buffer after creation.
115 * Returns: length of buffer, or negative error code if something failed.
117 int snd_pcm_create_iec958_consumer_hw_params(struct snd_pcm_hw_params *params,
120 return create_iec958_consumer(params_rate(params), params_width(params),
123 EXPORT_SYMBOL(snd_pcm_create_iec958_consumer_hw_params);