27 #include <linux/sched.h>
28 #include <linux/errno.h>
49 ad1843_PDNO = { 0, 14, 1 },
50 ad1843_INIT = { 0, 15, 1 },
51 ad1843_RIG = { 2, 0, 4 },
52 ad1843_RMGE = { 2, 4, 1 },
53 ad1843_RSS = { 2, 5, 3 },
54 ad1843_LIG = { 2, 8, 4 },
55 ad1843_LMGE = { 2, 12, 1 },
56 ad1843_LSS = { 2, 13, 3 },
57 ad1843_RD2M = { 3, 0, 5 },
58 ad1843_RD2MM = { 3, 7, 1 },
59 ad1843_LD2M = { 3, 8, 5 },
60 ad1843_LD2MM = { 3, 15, 1 },
61 ad1843_RX1M = { 4, 0, 5 },
62 ad1843_RX1MM = { 4, 7, 1 },
63 ad1843_LX1M = { 4, 8, 5 },
64 ad1843_LX1MM = { 4, 15, 1 },
65 ad1843_RX2M = { 5, 0, 5 },
66 ad1843_RX2MM = { 5, 7, 1 },
67 ad1843_LX2M = { 5, 8, 5 },
68 ad1843_LX2MM = { 5, 15, 1 },
69 ad1843_RMCM = { 7, 0, 5 },
70 ad1843_RMCMM = { 7, 7, 1 },
71 ad1843_LMCM = { 7, 8, 5 },
72 ad1843_LMCMM = { 7, 15, 1 },
73 ad1843_HPOS = { 8, 4, 1 },
74 ad1843_HPOM = { 8, 5, 1 },
75 ad1843_MPOM = { 8, 6, 1 },
76 ad1843_RDA1G = { 9, 0, 6 },
77 ad1843_RDA1GM = { 9, 7, 1 },
78 ad1843_LDA1G = { 9, 8, 6 },
79 ad1843_LDA1GM = { 9, 15, 1 },
80 ad1843_RDA2G = { 10, 0, 6 },
81 ad1843_RDA2GM = { 10, 7, 1 },
82 ad1843_LDA2G = { 10, 8, 6 },
83 ad1843_LDA2GM = { 10, 15, 1 },
84 ad1843_RDA1AM = { 11, 7, 1 },
85 ad1843_LDA1AM = { 11, 15, 1 },
86 ad1843_RDA2AM = { 12, 7, 1 },
87 ad1843_LDA2AM = { 12, 15, 1 },
88 ad1843_ADLC = { 15, 0, 2 },
89 ad1843_ADRC = { 15, 2, 2 },
90 ad1843_DA1C = { 15, 8, 2 },
91 ad1843_DA2C = { 15, 10, 2 },
92 ad1843_C1C = { 17, 0, 16 },
93 ad1843_C2C = { 20, 0, 16 },
94 ad1843_C3C = { 23, 0, 16 },
95 ad1843_DAADL = { 25, 4, 2 },
96 ad1843_DAADR = { 25, 6, 2 },
97 ad1843_DAMIX = { 25, 14, 1 },
98 ad1843_DRSFLT = { 25, 15, 1 },
99 ad1843_ADLF = { 26, 0, 2 },
100 ad1843_ADRF = { 26, 2, 2 },
101 ad1843_ADTLK = { 26, 4, 1 },
102 ad1843_SCF = { 26, 7, 1 },
103 ad1843_DA1F = { 26, 8, 2 },
104 ad1843_DA2F = { 26, 10, 2 },
105 ad1843_DA1SM = { 26, 14, 1 },
106 ad1843_DA2SM = { 26, 15, 1 },
107 ad1843_ADLEN = { 27, 0, 1 },
108 ad1843_ADREN = { 27, 1, 1 },
109 ad1843_AAMEN = { 27, 4, 1 },
110 ad1843_ANAEN = { 27, 7, 1 },
111 ad1843_DA1EN = { 27, 8, 1 },
112 ad1843_DA2EN = { 27, 9, 1 },
113 ad1843_DDMEN = { 27, 12, 1 },
114 ad1843_C1EN = { 28, 11, 1 },
115 ad1843_C2EN = { 28, 12, 1 },
116 ad1843_C3EN = { 28, 13, 1 },
117 ad1843_PDNI = { 28, 15, 1 };
133 static const struct ad1843_gain ad1843_gain_RECLEV = {
135 .lfield = &ad1843_LIG,
136 .rfield = &ad1843_RIG
138 static const struct ad1843_gain ad1843_gain_LINE = {
140 .lfield = &ad1843_LX1M,
141 .rfield = &ad1843_RX1M,
142 .lmute = &ad1843_LX1MM,
143 .rmute = &ad1843_RX1MM
145 static const struct ad1843_gain ad1843_gain_LINE_2 = {
147 .lfield = &ad1843_LDA2G,
148 .rfield = &ad1843_RDA2G,
149 .lmute = &ad1843_LDA2GM,
150 .rmute = &ad1843_RDA2GM
152 static const struct ad1843_gain ad1843_gain_MIC = {
154 .lfield = &ad1843_LMCM,
155 .rfield = &ad1843_RMCM,
156 .lmute = &ad1843_LMCMM,
157 .rmute = &ad1843_RMCMM
159 static const struct ad1843_gain ad1843_gain_PCM_0 = {
161 .lfield = &ad1843_LDA1G,
162 .rfield = &ad1843_RDA1G,
163 .lmute = &ad1843_LDA1GM,
164 .rmute = &ad1843_RDA1GM
166 static const struct ad1843_gain ad1843_gain_PCM_1 = {
168 .lfield = &ad1843_LD2M,
169 .rfield = &ad1843_RD2M,
170 .lmute = &ad1843_LD2MM,
171 .rmute = &ad1843_RD2MM
186 static int ad1843_read_bits(
struct snd_ad1843 *ad1843,
192 return w >> field->
lo_bit & ((1 << field->
nbits) - 1);
199 static int ad1843_write_bits(
struct snd_ad1843 *ad1843,
203 int w,
mask, oldval, newbits;
209 w = (w & ~mask) | newbits;
228 static void ad1843_read_multi(
struct snd_ad1843 *ad1843,
int argcount, ...)
235 while (--argcount >= 0) {
237 value =
va_arg(ap,
int *);
240 w = ad1843->
read(ad1843->
chip, reg);
243 mask = (1 << fp->
nbits) - 1;
260 static void ad1843_write_multi(
struct snd_ad1843 *ad1843,
int argcount, ...)
273 while (--argcount >= 0) {
282 bits |= (value << fp->
lo_bit) & m;
287 w = ad1843->
read(ad1843->
chip, reg);
290 w = (w & ~mask) | bits;
296 const struct ad1843_gain *
gp = ad1843_gain[
id];
299 ret = (1 << gp->
lfield->nbits);
313 const struct ad1843_gain *
gp = ad1843_gain[
id];
314 unsigned short mask = (1 << gp->
lfield->nbits) - 1;
316 ad1843_read_multi(ad1843, 2, gp->
lfield, &lg, gp->
rfield, &rg);
322 ad1843_read_multi(ad1843, 2, gp->
lmute, &lm, gp->
rmute, &rm);
328 return lg << 0 | rg << 8;
339 const struct ad1843_gain *
gp = ad1843_gain[
id];
340 unsigned short mask = (1 << gp->
lfield->nbits) - 1;
342 int lg = (newval >> 0) & mask;
343 int rg = (newval >> 8) & mask;
344 int lm = (lg == 0) ? 1 : 0;
345 int rm = (rg == 0) ? 1 : 0;
352 ad1843_write_multi(ad1843, 2, gp->
lmute, lm, gp->
rmute, rm);
353 ad1843_write_multi(ad1843, 2, gp->
lfield, lg, gp->
rfield, rg);
361 int val = ad1843_read_bits(ad1843, &ad1843_LSS);
363 if (val < 0 || val > 2) {
365 ad1843_write_multi(ad1843, 2,
366 &ad1843_LSS, val, &ad1843_RSS, val);
379 if (newsrc < 0 || newsrc > 2)
382 ad1843_write_multi(ad1843, 2, &ad1843_LSS, newsrc, &ad1843_RSS, newsrc);
390 unsigned int framerate,
394 int ad_fmt = 0, ad_mode = 0;
428 ad1843_write_bits(ad1843, &ad1843_C2C, framerate);
429 ad1843_write_multi(ad1843, 2,
430 &ad1843_DA2SM, ad_mode,
431 &ad1843_DA2F, ad_fmt);
433 ad1843_write_bits(ad1843, &ad1843_C1C, framerate);
434 ad1843_write_multi(ad1843, 2,
435 &ad1843_DA1SM, ad_mode,
436 &ad1843_DA1F, ad_fmt);
443 ad1843_write_bits(ad1843, &ad1843_DA2F, 1);
445 ad1843_write_bits(ad1843, &ad1843_DA1F, 1);
449 unsigned int framerate,
464 ad1843_write_bits(ad1843, &ad1843_C3C, framerate);
465 ad1843_write_multi(ad1843, 2,
466 &ad1843_ADLF, da_fmt, &ad1843_ADRF, da_fmt);
486 if (ad1843_read_bits(ad1843, &ad1843_INIT) != 0) {
491 ad1843_write_bits(ad1843, &ad1843_SCF, 1);
494 ad1843_write_bits(ad1843, &ad1843_PDNI, 0);
497 while (ad1843_read_bits(ad1843, &ad1843_PDNO)) {
500 "ad1843: AD1843 won't power up\n");
507 ad1843_write_multi(ad1843, 3,
515 ad1843_write_multi(ad1843, 4,
522 ad1843_write_bits(ad1843, &ad1843_ADTLK, 1);
523 ad1843_write_multi(ad1843, 7,
544 ad1843_write_multi(ad1843, 2, &ad1843_LDA1GM, 0, &ad1843_RDA1GM, 0);
546 ad1843_write_multi(ad1843, 2, &ad1843_LDA2GM, 0, &ad1843_RDA2GM, 0);
552 ad1843_write_multi(ad1843, 2, &ad1843_LMGE, 1, &ad1843_RMGE, 1);
555 ad1843_write_multi(ad1843, 3,