1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 #ifndef __SOUND_CS8403_H
3 #define __SOUND_CS8403_H
6 * Routines for Cirrus Logic CS8403/CS8404A IEC958 (S/PDIF) Transmitter
7 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>,
8 * Takashi Iwai <tiwai@suse.de>
13 #ifndef SND_CS8403_DECL
14 #define SND_CS8403_DECL static
16 #ifndef SND_CS8403_DECODE
17 #define SND_CS8403_DECODE snd_cs8403_decode_spdif_bits
19 #ifndef SND_CS8403_ENCODE
20 #define SND_CS8403_ENCODE snd_cs8403_encode_spdif_bits
24 SND_CS8403_DECL
void SND_CS8403_DECODE(struct snd_aes_iec958
*diga
, unsigned char bits
)
26 if (bits
& 0x01) { /* consumer */
28 diga
->status
[0] |= IEC958_AES0_NONAUDIO
;
30 diga
->status
[0] |= IEC958_AES0_CON_NOT_COPYRIGHT
;
31 switch (bits
& 0x10) {
32 case 0x10: diga
->status
[0] |= IEC958_AES0_CON_EMPHASIS_NONE
; break;
33 case 0x00: diga
->status
[0] |= IEC958_AES0_CON_EMPHASIS_5015
; break;
36 diga
->status
[1] |= IEC958_AES1_CON_ORIGINAL
;
37 switch (bits
& 0x60) {
38 case 0x00: diga
->status
[1] |= IEC958_AES1_CON_MAGNETIC_ID
; break;
39 case 0x20: diga
->status
[1] |= IEC958_AES1_CON_DIGDIGCONV_ID
; break;
40 case 0x40: diga
->status
[1] |= IEC958_AES1_CON_LASEROPT_ID
; break;
41 case 0x60: diga
->status
[1] |= IEC958_AES1_CON_GENERAL
; break;
43 switch (bits
& 0x06) {
44 case 0x00: diga
->status
[3] |= IEC958_AES3_CON_FS_44100
; break;
45 case 0x02: diga
->status
[3] |= IEC958_AES3_CON_FS_48000
; break;
46 case 0x04: diga
->status
[3] |= IEC958_AES3_CON_FS_32000
; break;
49 diga
->status
[0] = IEC958_AES0_PROFESSIONAL
;
50 switch (bits
& 0x18) {
51 case 0x00: diga
->status
[0] |= IEC958_AES0_PRO_FS_32000
; break;
52 case 0x10: diga
->status
[0] |= IEC958_AES0_PRO_FS_44100
; break;
53 case 0x08: diga
->status
[0] |= IEC958_AES0_PRO_FS_48000
; break;
54 case 0x18: diga
->status
[0] |= IEC958_AES0_PRO_FS_NOTID
; break;
56 switch (bits
& 0x60) {
57 case 0x20: diga
->status
[0] |= IEC958_AES0_PRO_EMPHASIS_NONE
; break;
58 case 0x40: diga
->status
[0] |= IEC958_AES0_PRO_EMPHASIS_5015
; break;
59 case 0x00: diga
->status
[0] |= IEC958_AES0_PRO_EMPHASIS_CCITT
; break;
60 case 0x60: diga
->status
[0] |= IEC958_AES0_PRO_EMPHASIS_NOTID
; break;
63 diga
->status
[1] |= IEC958_AES1_PRO_MODE_STEREOPHONIC
;
67 SND_CS8403_DECL
unsigned char SND_CS8403_ENCODE(struct snd_aes_iec958
*diga
)
71 if (!(diga
->status
[0] & IEC958_AES0_PROFESSIONAL
)) {
72 bits
= 0x01; /* consumer mode */
73 if (diga
->status
[0] & IEC958_AES0_NONAUDIO
)
77 if (diga
->status
[0] & IEC958_AES0_CON_NOT_COPYRIGHT
)
81 switch (diga
->status
[0] & IEC958_AES0_CON_EMPHASIS
) {
83 case IEC958_AES0_CON_EMPHASIS_NONE
: bits
|= 0x10; break;
84 case IEC958_AES0_CON_EMPHASIS_5015
: bits
|= 0x00; break;
86 if (diga
->status
[1] & IEC958_AES1_CON_ORIGINAL
)
90 if ((diga
->status
[1] & IEC958_AES1_CON_CATEGORY
) == IEC958_AES1_CON_GENERAL
)
93 switch(diga
->status
[1] & IEC958_AES1_CON_MAGNETIC_MASK
) {
94 case IEC958_AES1_CON_MAGNETIC_ID
:
96 case IEC958_AES1_CON_DIGDIGCONV_ID
:
99 case IEC958_AES1_CON_LASEROPT_ID
:
103 switch (diga
->status
[3] & IEC958_AES3_CON_FS
) {
105 case IEC958_AES3_CON_FS_44100
: bits
|= 0x00; break;
106 case IEC958_AES3_CON_FS_48000
: bits
|= 0x02; break;
107 case IEC958_AES3_CON_FS_32000
: bits
|= 0x04; break;
110 bits
= 0x00; /* professional mode */
111 if (diga
->status
[0] & IEC958_AES0_NONAUDIO
)
115 /* CHECKME: I'm not sure about the bit order in val here */
116 switch (diga
->status
[0] & IEC958_AES0_PRO_FS
) {
117 case IEC958_AES0_PRO_FS_32000
: bits
|= 0x00; break;
118 case IEC958_AES0_PRO_FS_44100
: bits
|= 0x10; break; /* 44.1kHz */
119 case IEC958_AES0_PRO_FS_48000
: bits
|= 0x08; break; /* 48kHz */
121 case IEC958_AES0_PRO_FS_NOTID
: bits
|= 0x18; break;
123 switch (diga
->status
[0] & IEC958_AES0_PRO_EMPHASIS
) {
124 case IEC958_AES0_PRO_EMPHASIS_NONE
: bits
|= 0x20; break;
125 case IEC958_AES0_PRO_EMPHASIS_5015
: bits
|= 0x40; break;
126 case IEC958_AES0_PRO_EMPHASIS_CCITT
: bits
|= 0x00; break;
128 case IEC958_AES0_PRO_EMPHASIS_NOTID
: bits
|= 0x60; break;
130 switch (diga
->status
[1] & IEC958_AES1_PRO_MODE
) {
131 case IEC958_AES1_PRO_MODE_TWO
:
132 case IEC958_AES1_PRO_MODE_STEREOPHONIC
: bits
|= 0x00; break;
133 default: bits
|= 0x80; break;
139 #endif /* SND_CS8403 */
143 #ifndef SND_CS8404_DECL
144 #define SND_CS8404_DECL static
146 #ifndef SND_CS8404_DECODE
147 #define SND_CS8404_DECODE snd_cs8404_decode_spdif_bits
149 #ifndef SND_CS8404_ENCODE
150 #define SND_CS8404_ENCODE snd_cs8404_encode_spdif_bits
154 SND_CS8404_DECL
void SND_CS8404_DECODE(struct snd_aes_iec958
*diga
, unsigned char bits
)
156 if (bits
& 0x10) { /* consumer */
158 diga
->status
[0] |= IEC958_AES0_CON_NOT_COPYRIGHT
;
160 diga
->status
[0] |= IEC958_AES0_CON_EMPHASIS_5015
;
162 diga
->status
[1] |= IEC958_AES1_CON_ORIGINAL
;
163 switch (bits
& 0x03) {
164 case 0x00: diga
->status
[1] |= IEC958_AES1_CON_DAT
; break;
165 case 0x03: diga
->status
[1] |= IEC958_AES1_CON_GENERAL
; break;
167 switch (bits
& 0x06) {
168 case 0x02: diga
->status
[3] |= IEC958_AES3_CON_FS_32000
; break;
169 case 0x04: diga
->status
[3] |= IEC958_AES3_CON_FS_48000
; break;
170 case 0x06: diga
->status
[3] |= IEC958_AES3_CON_FS_44100
; break;
173 diga
->status
[0] = IEC958_AES0_PROFESSIONAL
;
175 diga
->status
[0] |= IEC958_AES0_NONAUDIO
;
176 switch (bits
& 0x60) {
177 case 0x00: diga
->status
[0] |= IEC958_AES0_PRO_FS_32000
; break;
178 case 0x40: diga
->status
[0] |= IEC958_AES0_PRO_FS_44100
; break;
179 case 0x20: diga
->status
[0] |= IEC958_AES0_PRO_FS_48000
; break;
180 case 0x60: diga
->status
[0] |= IEC958_AES0_PRO_FS_NOTID
; break;
182 switch (bits
& 0x03) {
183 case 0x02: diga
->status
[0] |= IEC958_AES0_PRO_EMPHASIS_NONE
; break;
184 case 0x01: diga
->status
[0] |= IEC958_AES0_PRO_EMPHASIS_5015
; break;
185 case 0x00: diga
->status
[0] |= IEC958_AES0_PRO_EMPHASIS_CCITT
; break;
186 case 0x03: diga
->status
[0] |= IEC958_AES0_PRO_EMPHASIS_NOTID
; break;
189 diga
->status
[1] |= IEC958_AES1_PRO_MODE_STEREOPHONIC
;
193 SND_CS8404_DECL
unsigned char SND_CS8404_ENCODE(struct snd_aes_iec958
*diga
)
197 if (!(diga
->status
[0] & IEC958_AES0_PROFESSIONAL
)) {
198 bits
= 0x10; /* consumer mode */
199 if (!(diga
->status
[0] & IEC958_AES0_CON_NOT_COPYRIGHT
))
201 if ((diga
->status
[0] & IEC958_AES0_CON_EMPHASIS
) == IEC958_AES0_CON_EMPHASIS_NONE
)
203 if (!(diga
->status
[1] & IEC958_AES1_CON_ORIGINAL
))
205 if ((diga
->status
[1] & IEC958_AES1_CON_CATEGORY
) == IEC958_AES1_CON_GENERAL
)
207 switch (diga
->status
[3] & IEC958_AES3_CON_FS
) {
209 case IEC958_AES3_CON_FS_44100
: bits
|= 0x06; break;
210 case IEC958_AES3_CON_FS_48000
: bits
|= 0x04; break;
211 case IEC958_AES3_CON_FS_32000
: bits
|= 0x02; break;
214 bits
= 0x00; /* professional mode */
215 if (!(diga
->status
[0] & IEC958_AES0_NONAUDIO
))
217 switch (diga
->status
[0] & IEC958_AES0_PRO_FS
) {
218 case IEC958_AES0_PRO_FS_32000
: bits
|= 0x00; break;
219 case IEC958_AES0_PRO_FS_44100
: bits
|= 0x40; break; /* 44.1kHz */
220 case IEC958_AES0_PRO_FS_48000
: bits
|= 0x20; break; /* 48kHz */
222 case IEC958_AES0_PRO_FS_NOTID
: bits
|= 0x00; break;
224 switch (diga
->status
[0] & IEC958_AES0_PRO_EMPHASIS
) {
225 case IEC958_AES0_PRO_EMPHASIS_NONE
: bits
|= 0x02; break;
226 case IEC958_AES0_PRO_EMPHASIS_5015
: bits
|= 0x01; break;
227 case IEC958_AES0_PRO_EMPHASIS_CCITT
: bits
|= 0x00; break;
229 case IEC958_AES0_PRO_EMPHASIS_NOTID
: bits
|= 0x03; break;
231 switch (diga
->status
[1] & IEC958_AES1_PRO_MODE
) {
232 case IEC958_AES1_PRO_MODE_TWO
:
233 case IEC958_AES1_PRO_MODE_STEREOPHONIC
: bits
|= 0x00; break;
234 default: bits
|= 0x80; break;
240 #endif /* SND_CS8404 */
242 #endif /* __SOUND_CS8403_H */