1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
|
/*
cx88x-audio.c - Conexant CX23880/23881 audio downstream driver driver
(c) 2001 Michael Eskin, Tom Zakrajsek [Windows version]
(c) 2002 Yurij Sysoev <yurij@naturesoft.net>
(c) 2003 Gerd Knorr <kraxel@bytesex.org>
-----------------------------------------------------------------------
Lot of voodoo here. Even the data sheet doesn't help to
understand what is going on here, the documentation for the audio
part of the cx2388x chip is *very* bad.
Some of this comes from party done linux driver sources I got from
[undocumented].
Some comes from the dscaler sources, the dscaler driver guy works
for Conexant ...
-----------------------------------------------------------------------
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <linux/module.h>
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/mm.h>
#include <linux/poll.h>
#include <linux/pci.h>
#include <linux/signal.h>
#include <linux/ioport.h>
#include <linux/sched.h>
#include <linux/types.h>
#include <linux/interrupt.h>
#include <linux/vmalloc.h>
#include <linux/init.h>
#include "cx88.h"
static unsigned int audio_debug = UNSET;
MODULE_PARM(audio_debug,"i");
MODULE_PARM_DESC(audio_debug,"enable debug messages [audio]");
#define dprintk(fmt, arg...) if (audio_debug) \
printk(KERN_DEBUG "%s: " fmt, dev->name , ## arg)
/* ----------------------------------------------------------- */
struct rlist {
u32 reg;
u32 val;
};
static void set_audio_registers(struct cx8800_dev *dev,
const struct rlist *l)
{
int i;
for (i = 0; l[i].reg; i++)
cx_write(l[i].reg, l[i].val);
}
static void set_audio_standard_BTSC(struct cx8800_dev *dev, unsigned int sap)
{
dprintk("set_audio_standard_BTSC() [TODO]\n");
}
static void set_audio_standard_NICAM(struct cx8800_dev *dev)
{
static const struct rlist nicam[] = {
// increase level of input by 12dB
{ AUD_AFE_12DB_EN, 0x00000001 },
// initialize NICAM
{ AUD_INIT, 0x00000010 },
{ AUD_INIT_LD, 0x00000001 },
{ AUD_SOFT_RESET, 0x00000001 },
// WARNING!!!! Stereo mode is FORCED!!!!
{ AUD_CTL, EN_DAC_ENABLE | EN_DMTRX_LR | EN_NICAM_FORCE_STEREO },
{ AUD_SOFT_RESET, 0x00000001 },
{ AUD_RATE_ADJ1, 0x00000010 },
{ AUD_RATE_ADJ2, 0x00000040 },
{ AUD_RATE_ADJ3, 0x00000100 },
{ AUD_RATE_ADJ4, 0x00000400 },
{ AUD_RATE_ADJ5, 0x00001000 },
// { AUD_DMD_RA_DDS, 0x00c0d5ce },
{ /* end of list */ },
};
printk("set_audio_standard_NICAM()\n");
set_audio_registers(dev, nicam);
// setup QAM registers
cx_write(0x320d01, 0x06);
cx_write(0x320d02, 0x82);
cx_write(0x320d03, 0x16);
cx_write(0x320d04, 0x05);
cx_write(0x320d2a, 0x34);
cx_write(0x320d2b, 0x4c);
// setup Audio PLL
//cx_write(AUD_PLL_PRESCALE, 0x0002);
//cx_write(AUD_PLL_INT, 0x001f);
// de-assert Audio soft reset
cx_write(AUD_SOFT_RESET, 0x00000000); // Causes a pop every time
}
static void set_audio_standard_A2(struct cx8800_dev *dev)
{
static const struct rlist a2[] = {
// increase level of input by 12dB
{ AUD_AFE_12DB_EN, 0x00000001 },
// initialize A2
{ AUD_INIT, 0x00000004 },
{ AUD_INIT_LD, 0x00000001 },
{ AUD_SOFT_RESET, 0x00000001 },
// ; WARNING!!! A2 STEREO DEMATRIX HAS TO BE
// ; SET MANUALLY!!! Value sould be 0x100c
{ AUD_CTL, EN_DAC_ENABLE | EN_DMTRX_SUMR | EN_A2_AUTO_STEREO },
{ AUD_DN0_FREQ, 0x0000312b },
{ AUD_POLY0_DDS_CONSTANT, 0x000a62b4 },
{ AUD_IIR1_0_SEL, 0x00000000 },
{ AUD_IIR1_1_SEL, 0x00000001 },
{ AUD_IIR1_2_SEL, 0x0000001f },
{ AUD_IIR1_3_SEL, 0x00000020 },
{ AUD_IIR1_4_SEL, 0x00000023 },
{ AUD_IIR1_5_SEL, 0x00000007 },
{ AUD_IIR1_0_SHIFT, 0x00000000 },
{ AUD_IIR1_1_SHIFT, 0x00000000 },
{ AUD_IIR1_2_SHIFT, 0x00000007 },
{ AUD_IIR1_3_SHIFT, 0x00000007 },
{ AUD_IIR1_4_SHIFT, 0x00000007 },
{ AUD_IIR1_5_SHIFT, 0x00000000 },
{ AUD_IIR2_0_SEL, 0x00000002 },
{ AUD_IIR2_1_SEL, 0x00000003 },
{ AUD_IIR2_2_SEL, 0x00000004 },
{ AUD_IIR2_3_SEL, 0x00000005 },
{ AUD_IIR3_0_SEL, 0x00000021 },
{ AUD_IIR3_1_SEL, 0x00000023 },
{ AUD_IIR3_2_SEL, 0x00000016 },
{ AUD_IIR3_0_SHIFT, 0x00000000 },
{ AUD_IIR3_1_SHIFT, 0x00000000 },
{ AUD_IIR3_2_SHIFT, 0x00000000 },
{ AUD_IIR4_0_SEL, 0x0000001d },
{ AUD_IIR4_1_SEL, 0x00000019 },
{ AUD_IIR4_2_SEL, 0x00000008 },
{ AUD_IIR4_0_SHIFT, 0x00000000 },
{ AUD_IIR4_1_SHIFT, 0x00000000 },
{ AUD_IIR4_2_SHIFT, 0x00000001 },
{ AUD_IIR4_0_CA0, 0x0003e57e },
{ AUD_IIR4_0_CA1, 0x00005e11 },
{ AUD_IIR4_0_CA2, 0x0003a7cf },
{ AUD_IIR4_0_CB0, 0x00002368 },
{ AUD_IIR4_0_CB1, 0x0003bf1b },
{ AUD_IIR4_1_CA0, 0x00006349 },
{ AUD_IIR4_1_CA1, 0x00006f27 },
{ AUD_IIR4_1_CA2, 0x0000e7a3 },
{ AUD_IIR4_1_CB0, 0x00005653 },
{ AUD_IIR4_1_CB1, 0x0000cf97 },
{ AUD_IIR4_2_CA0, 0x00006349 },
{ AUD_IIR4_2_CA1, 0x00006f27 },
{ AUD_IIR4_2_CA2, 0x0000e7a3 },
{ AUD_IIR4_2_CB0, 0x00005653 },
{ AUD_IIR4_2_CB1, 0x0000cf97 },
{ AUD_HP_MD_IIR4_1, 0x00000001 },
{ AUD_HP_PROG_IIR4_1, 0x00000017 },
{ AUD_DN1_FREQ, 0x00003618 },
{ AUD_DN1_SRC_SEL, 0x00000017 },
{ AUD_DN1_SHFT, 0x00000007 },
{ AUD_DN1_AFC, 0x00000000 },
{ AUD_DN1_FREQ_SHIFT, 0x00000000 },
{ AUD_DN2_SRC_SEL, 0x00000040 },
{ AUD_DN2_SHFT, 0x00000000 },
{ AUD_DN2_AFC, 0x00000002 },
{ AUD_DN2_FREQ, 0x0000caaf },
{ AUD_DN2_FREQ_SHIFT, 0x00000000 },
{ AUD_PDET_SRC, 0x00000014 },
{ AUD_PDET_SHIFT, 0x00000000 },
{ AUD_DEEMPH0_SRC_SEL, 0x00000011 },
{ AUD_DEEMPH1_SRC_SEL, 0x00000013 },
{ AUD_DEEMPH0_SHIFT, 0x00000000 },
{ AUD_DEEMPH1_SHIFT, 0x00000000 },
{ AUD_DEEMPH0_G0, 0x000004da },
{ AUD_DEEMPH0_A0, 0x0000777a },
{ AUD_DEEMPH0_B0, 0x00000000 },
{ AUD_DEEMPH0_A1, 0x0003f062 },
{ AUD_DEEMPH0_B1, 0x00000000 },
{ AUD_DEEMPH1_G0, 0x000004da },
{ AUD_DEEMPH1_A0, 0x0000777a },
{ AUD_DEEMPH1_B0, 0x00000000 },
{ AUD_DEEMPH1_A1, 0x0003f062 },
{ AUD_DEEMPH1_B1, 0x00000000 },
{ AUD_PLL_EN, 0x00000000 },
{ AUD_DMD_RA_DDS, 0x002a4efb },
{ AUD_RATE_ADJ1, 0x00001000 },
{ AUD_RATE_ADJ2, 0x00002000 },
{ AUD_RATE_ADJ3, 0x00003000 },
{ AUD_RATE_ADJ4, 0x00004000 },
{ AUD_RATE_ADJ5, 0x00005000 },
{ AUD_C2_UP_THR, 0x0000ffff },
{ AUD_C2_LO_THR, 0x0000e800 },
{ AUD_C1_UP_THR, 0x00008c00 },
{ AUD_C1_LO_THR, 0x00006c00 },
// ; Completely ditch AFC feedback
{ AUD_DCOC_0_SRC, 0x00000021 },
{ AUD_DCOC_1_SRC, 0x0000001a },
{ AUD_DCOC1_SHIFT, 0x00000000 },
{ AUD_DCOC_1_SHIFT_IN0, 0x0000000a },
{ AUD_DCOC_1_SHIFT_IN1, 0x00000008 },
{ AUD_DCOC_PASS_IN, 0x00000000 },
{ AUD_IIR4_0_SEL, 0x00000023 },
// ; Completely ditc FM-2 AFC feedback
{ AUD_DN1_AFC, 0x00000000 },
{ AUD_DCOC_2_SRC, 0x0000001b },
{ AUD_IIR4_1_SEL, 0x00000025 },
// ; WARNING!!! THIS CHANGE WAS NOT EXPECTED!!!
// ; Swap I & Q inputs into second rotator
// ; to reverse frequency and therefor invert
// ; phase from the cordic FM demodulator
// ; (frequency rotation must also be reversed
{ AUD_DN2_SRC_SEL, 0x00000001 },
{ AUD_DN2_FREQ, 0x00003551 },
// setup Audio PLL
{ AUD_PLL_PRESCALE, 0x00000002 },
{ AUD_PLL_INT, 0x0000001f },
// de-assert Audio soft reset
{ AUD_SOFT_RESET, 0x00000000 },
{ /* end of list */ },
};
dprintk("set_audio_standard_A2()\n");
set_audio_registers(dev, a2);
}
static void set_audio_standard_EIAJ(struct cx8800_dev *dev)
{
dprintk("set_audio_standard_EIAJ() [TODO]\n");
}
static void set_audio_standard_FM(struct cx8800_dev *dev)
{
dprintk("set_audio_standard_FM\n");
// initialize FM Radio
cx_write(AUD_INIT,0x0020);
cx_write(AUD_INIT_LD,0x0001);
cx_write(AUD_SOFT_RESET,0x0001);
#if 0 /* FIXME */
switch (dev->audio_properties.FM_deemphasis)
{
case WW_FM_DEEMPH_50:
//Set De-emphasis filter coefficients for 50 usec
cx_write(AUD_DEEMPH0_G0, 0x0C45);
cx_write(AUD_DEEMPH0_A0, 0x6262);
cx_write(AUD_DEEMPH0_B0, 0x1C29);
cx_write(AUD_DEEMPH0_A1, 0x3FC66);
cx_write(AUD_DEEMPH0_B1, 0x399A);
cx_write(AUD_DEEMPH1_G0, 0x0D80);
cx_write(AUD_DEEMPH1_A0, 0x6262);
cx_write(AUD_DEEMPH1_B0, 0x1C29);
cx_write(AUD_DEEMPH1_A1, 0x3FC66);
cx_write(AUD_DEEMPH1_B1, 0x399A);
break;
case WW_FM_DEEMPH_75:
//Set De-emphasis filter coefficients for 75 usec
cx_write(AUD_DEEMPH0_G0, 0x91B );
cx_write(AUD_DEEMPH0_A0, 0x6B68);
cx_write(AUD_DEEMPH0_B0, 0x11EC);
cx_write(AUD_DEEMPH0_A1, 0x3FC66);
cx_write(AUD_DEEMPH0_B1, 0x399A);
cx_write(AUD_DEEMPH1_G0, 0xAA0 );
cx_write(AUD_DEEMPH1_A0, 0x6B68);
cx_write(AUD_DEEMPH1_B0, 0x11EC);
cx_write(AUD_DEEMPH1_A1, 0x3FC66);
cx_write(AUD_DEEMPH1_B1, 0x399A);
break;
}
#endif
// de-assert Audio soft reset
cx_write(AUD_SOFT_RESET,0x0000);
// AB: 10/2/01: this register is not being reset appropriately on occasion.
cx_write(AUD_POLYPH80SCALEFAC,3);
}
/* ----------------------------------------------------------- */
void cx88_set_tvaudio(struct cx8800_dev *dev)
{
cx_write(AUD_CTL, 0x00);
switch (dev->tvaudio) {
case WW_BTSC:
set_audio_standard_BTSC(dev,0);
break;
case WW_NICAM_I:
case WW_NICAM_BGDKL:
set_audio_standard_NICAM(dev);
break;
case WW_A2_BG:
case WW_A2_DK:
case WW_A2_M:
set_audio_standard_A2(dev);
break;
case WW_EIAJ:
set_audio_standard_EIAJ(dev);
break;
case WW_FM:
set_audio_standard_FM(dev);
break;
case WW_NONE:
default:
printk("%s: unknown tv audio mode [%d]\n",
dev->name, dev->tvaudio);
break;
}
// unmute
cx_set(AUD_CTL, EN_DAC_ENABLE);
cx_swrite(SHADOW_AUD_VOL_CTL, AUD_VOL_CTL, 0x00);
return;
}
void cx88_get_stereo(struct cx8800_dev *dev, struct v4l2_tuner *t)
{
static char *m[] = {"stereo", "dual mono", "mono", "sap"};
static char *p[] = {"no pilot", "pilot c1", "pilot c2", "?"};
u32 reg,mode,pilot;
reg = cx_read(AUD_STATUS);
mode = reg & 0x03;
pilot = (reg >> 2) & 0x03;
dprintk("AUD_STATUS: %s / %s [status=0x%x,ctl=0x%x,vol=0x%x]\n",
m[mode], p[pilot], reg,
cx_read(AUD_CTL), cx_sread(SHADOW_AUD_VOL_CTL));
t->capability = V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_SAP |
V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2;
t->rxsubchans = V4L2_TUNER_SUB_MONO;
t->audmode = V4L2_TUNER_MODE_MONO;
switch (dev->tvaudio) {
case WW_A2_BG:
if (1 == pilot) {
/* stereo */
t->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO;
if (0 == mode)
t->audmode = V4L2_TUNER_MODE_STEREO;
}
if (2 == pilot) {
/* dual language -- FIXME */
t->rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
t->audmode = V4L2_TUNER_MODE_LANG1;
}
break;
case WW_NICAM_BGDKL:
if (0 == mode)
t->audmode = V4L2_TUNER_MODE_STEREO;
break;
default:
t->rxsubchans = V4L2_TUNER_SUB_MONO;
t->audmode = V4L2_TUNER_MODE_MONO;
break;
}
return;
}
void cx88_set_stereo(struct cx8800_dev *dev, u32 mode)
{
u32 ctl = UNSET;
u32 mask = UNSET;
switch (dev->tvaudio) {
case WW_A2_BG:
switch (mode) {
case V4L2_TUNER_MODE_MONO:
case V4L2_TUNER_MODE_LANG1:
ctl = EN_A2_FORCE_MONO1;
mask = 0x3f;
break;
case V4L2_TUNER_MODE_LANG2:
ctl = EN_A2_AUTO_MONO2;
mask = 0x3f;
break;
case V4L2_TUNER_MODE_STEREO:
ctl = EN_A2_AUTO_STEREO | EN_DMTRX_SUMR;
mask = 0x8bf;
break;
}
break;
case WW_NICAM_BGDKL:
switch (mode) {
case V4L2_TUNER_MODE_MONO:
ctl = EN_NICAM_FORCE_MONO1;
mask = 0x3f;
break;
case V4L2_TUNER_MODE_LANG1:
ctl = EN_NICAM_AUTO_MONO2;
mask = 0x3f;
break;
case V4L2_TUNER_MODE_STEREO:
ctl = EN_NICAM_FORCE_STEREO | EN_DMTRX_LR;
mask = 0x93f;
break;
}
break;
case WW_FM:
switch (mode) {
case V4L2_TUNER_MODE_MONO:
ctl = EN_FMRADIO_FORCE_MONO;
mask = 0x3f;
break;
case V4L2_TUNER_MODE_STEREO:
ctl = EN_FMRADIO_AUTO_STEREO;
mask = 0x3f;
break;
}
break;
}
if (UNSET != ctl) {
cx_write(AUD_SOFT_RESET, 0x0001);
cx_andor(AUD_CTL, mask, ctl);
cx_write(AUD_SOFT_RESET, 0x0000);
dprintk("cx88_set_stereo: mask 0x%x, ctl 0x%x "
"[status=0x%x,ctl=0x%x,vol=0x%x]\n",
mask, ctl, cx_read(AUD_STATUS),
cx_read(AUD_CTL), cx_sread(SHADOW_AUD_VOL_CTL));
}
return;
}
/*
* Local variables:
* c-basic-offset: 8
* End:
*/
|