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>
13 * snd_pcm_create_iec958_consumer_default - create default consumer format IEC958 channel status
14 * @cs: channel status buffer, at least four bytes
15 * @len: length of channel status buffer
17 * Create the consumer format channel status data in @cs of maximum size
18 * @len. When relevant, the configuration-dependant bits will be set as
21 * Drivers should then call einter snd_pcm_fill_iec958_consumer() or
22 * snd_pcm_fill_iec958_consumer_hw_params() to replace these unspecified
23 * bits by their actual values.
25 * Drivers may wish to tweak the contents of the buffer after creation.
27 * Returns: length of buffer, or negative error code if something failed.
29 int snd_pcm_create_iec958_consumer_default(u8 *cs, size_t len)
36 cs[0] = IEC958_AES0_CON_NOT_COPYRIGHT | IEC958_AES0_CON_EMPHASIS_NONE;
37 cs[1] = IEC958_AES1_CON_GENERAL;
38 cs[2] = IEC958_AES2_CON_SOURCE_UNSPEC | IEC958_AES2_CON_CHANNEL_UNSPEC;
39 cs[3] = IEC958_AES3_CON_CLOCK_1000PPM | IEC958_AES3_CON_FS_NOTID;
42 cs[4] = IEC958_AES4_CON_WORDLEN_NOTID;
46 EXPORT_SYMBOL_GPL(snd_pcm_create_iec958_consumer_default);
48 static int fill_iec958_consumer(uint rate, uint sample_width,
54 if ((cs[3] & IEC958_AES3_CON_FS) == IEC958_AES3_CON_FS_NOTID) {
59 fs = IEC958_AES3_CON_FS_32000;
62 fs = IEC958_AES3_CON_FS_44100;
65 fs = IEC958_AES3_CON_FS_48000;
68 fs = IEC958_AES3_CON_FS_88200;
71 fs = IEC958_AES3_CON_FS_96000;
74 fs = IEC958_AES3_CON_FS_176400;
77 fs = IEC958_AES3_CON_FS_192000;
83 cs[3] &= ~IEC958_AES3_CON_FS;
88 (cs[4] & IEC958_AES4_CON_WORDLEN) == IEC958_AES4_CON_WORDLEN_NOTID) {
91 switch (sample_width) {
93 ws = IEC958_AES4_CON_WORDLEN_20_16;
96 ws = IEC958_AES4_CON_WORDLEN_22_18;
99 ws = IEC958_AES4_CON_WORDLEN_20_16 |
100 IEC958_AES4_CON_MAX_WORDLEN_24;
103 case 32: /* Assume 24-bit width for 32-bit samples. */
104 ws = IEC958_AES4_CON_WORDLEN_24_20 |
105 IEC958_AES4_CON_MAX_WORDLEN_24;
112 cs[4] &= ~IEC958_AES4_CON_WORDLEN;
120 * snd_pcm_fill_iec958_consumer - Fill consumer format IEC958 channel status
121 * @runtime: pcm runtime structure with ->rate filled in
122 * @cs: channel status buffer, at least four bytes
123 * @len: length of channel status buffer
125 * Fill the unspecified bits in an IEC958 status bits array using the
126 * parameters of the PCM runtime @runtime.
128 * Drivers may wish to tweak the contents of the buffer after its been
131 * Returns: length of buffer, or negative error code if something failed.
133 int snd_pcm_fill_iec958_consumer(struct snd_pcm_runtime *runtime,
136 return fill_iec958_consumer(runtime->rate,
137 snd_pcm_format_width(runtime->format),
140 EXPORT_SYMBOL_GPL(snd_pcm_fill_iec958_consumer);
143 * snd_pcm_fill_iec958_consumer_hw_params - Fill consumer format IEC958 channel status
144 * @params: the hw_params instance for extracting rate and sample format
145 * @cs: channel status buffer, at least four bytes
146 * @len: length of channel status buffer
148 * Fill the unspecified bits in an IEC958 status bits array using the
149 * parameters of the PCM hardware parameters @params.
151 * Drivers may wish to tweak the contents of the buffer after its been
154 * Returns: length of buffer, or negative error code if something failed.
156 int snd_pcm_fill_iec958_consumer_hw_params(struct snd_pcm_hw_params *params,
159 return fill_iec958_consumer(params_rate(params), params_width(params), cs, len);
161 EXPORT_SYMBOL_GPL(snd_pcm_fill_iec958_consumer_hw_params);
164 * snd_pcm_create_iec958_consumer - create consumer format IEC958 channel status
165 * @runtime: pcm runtime structure with ->rate filled in
166 * @cs: channel status buffer, at least four bytes
167 * @len: length of channel status buffer
169 * Create the consumer format channel status data in @cs of maximum size
170 * @len corresponding to the parameters of the PCM runtime @runtime.
172 * Drivers may wish to tweak the contents of the buffer after creation.
174 * Returns: length of buffer, or negative error code if something failed.
176 int snd_pcm_create_iec958_consumer(struct snd_pcm_runtime *runtime, u8 *cs,
181 ret = snd_pcm_create_iec958_consumer_default(cs, len);
185 return snd_pcm_fill_iec958_consumer(runtime, cs, len);
187 EXPORT_SYMBOL(snd_pcm_create_iec958_consumer);
190 * snd_pcm_create_iec958_consumer_hw_params - create IEC958 channel status
191 * @params: the hw_params instance for extracting rate and sample format
192 * @cs: channel status buffer, at least four bytes
193 * @len: length of channel status buffer
195 * Create the consumer format channel status data in @cs of maximum size
196 * @len corresponding to the parameters of the PCM runtime @runtime.
198 * Drivers may wish to tweak the contents of the buffer after creation.
200 * Returns: length of buffer, or negative error code if something failed.
202 int snd_pcm_create_iec958_consumer_hw_params(struct snd_pcm_hw_params *params,
207 ret = snd_pcm_create_iec958_consumer_default(cs, len);
211 return fill_iec958_consumer(params_rate(params), params_width(params), cs, len);
213 EXPORT_SYMBOL(snd_pcm_create_iec958_consumer_hw_params);