cx88-tvaudio.c 27.0 KB
Newer Older
L
Linus Torvalds 已提交
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
/*

    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, one of 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/moduleparam.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 <linux/smp_lock.h>
#include <linux/delay.h>
#include <linux/kthread.h>

#include "cx88.h"

static unsigned int audio_debug = 0;
60 61
module_param(audio_debug, int, 0644);
MODULE_PARM_DESC(audio_debug, "enable debug messages [audio]");
L
Linus Torvalds 已提交
62 63 64 65 66 67

#define dprintk(fmt, arg...)	if (audio_debug) \
	printk(KERN_DEBUG "%s/0: " fmt, core->name , ## arg)

/* ----------------------------------------------------------- */

68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
static char *aud_ctl_names[64] = {
	[EN_BTSC_FORCE_MONO] = "BTSC_FORCE_MONO",
	[EN_BTSC_FORCE_STEREO] = "BTSC_FORCE_STEREO",
	[EN_BTSC_FORCE_SAP] = "BTSC_FORCE_SAP",
	[EN_BTSC_AUTO_STEREO] = "BTSC_AUTO_STEREO",
	[EN_BTSC_AUTO_SAP] = "BTSC_AUTO_SAP",
	[EN_A2_FORCE_MONO1] = "A2_FORCE_MONO1",
	[EN_A2_FORCE_MONO2] = "A2_FORCE_MONO2",
	[EN_A2_FORCE_STEREO] = "A2_FORCE_STEREO",
	[EN_A2_AUTO_MONO2] = "A2_AUTO_MONO2",
	[EN_A2_AUTO_STEREO] = "A2_AUTO_STEREO",
	[EN_EIAJ_FORCE_MONO1] = "EIAJ_FORCE_MONO1",
	[EN_EIAJ_FORCE_MONO2] = "EIAJ_FORCE_MONO2",
	[EN_EIAJ_FORCE_STEREO] = "EIAJ_FORCE_STEREO",
	[EN_EIAJ_AUTO_MONO2] = "EIAJ_AUTO_MONO2",
	[EN_EIAJ_AUTO_STEREO] = "EIAJ_AUTO_STEREO",
	[EN_NICAM_FORCE_MONO1] = "NICAM_FORCE_MONO1",
	[EN_NICAM_FORCE_MONO2] = "NICAM_FORCE_MONO2",
	[EN_NICAM_FORCE_STEREO] = "NICAM_FORCE_STEREO",
	[EN_NICAM_AUTO_MONO2] = "NICAM_AUTO_MONO2",
	[EN_NICAM_AUTO_STEREO] = "NICAM_AUTO_STEREO",
	[EN_FMRADIO_FORCE_MONO] = "FMRADIO_FORCE_MONO",
	[EN_FMRADIO_FORCE_STEREO] = "FMRADIO_FORCE_STEREO",
	[EN_FMRADIO_AUTO_STEREO] = "FMRADIO_AUTO_STEREO",
L
Linus Torvalds 已提交
92 93 94 95 96 97 98
};

struct rlist {
	u32 reg;
	u32 val;
};

99
static void set_audio_registers(struct cx88_core *core, const struct rlist *l)
L
Linus Torvalds 已提交
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
{
	int i;

	for (i = 0; l[i].reg; i++) {
		switch (l[i].reg) {
		case AUD_PDF_DDS_CNST_BYTE2:
		case AUD_PDF_DDS_CNST_BYTE1:
		case AUD_PDF_DDS_CNST_BYTE0:
		case AUD_QAM_MODE:
		case AUD_PHACC_FREQ_8MSB:
		case AUD_PHACC_FREQ_8LSB:
			cx_writeb(l[i].reg, l[i].val);
			break;
		default:
			cx_write(l[i].reg, l[i].val);
			break;
		}
	}
}

120
static void set_audio_start(struct cx88_core *core, u32 mode)
L
Linus Torvalds 已提交
121
{
122
	/* mute */
123
	cx_write(AUD_VOL_CTL, (1 << 6));
L
Linus Torvalds 已提交
124

125
	/* start programming */
126 127 128
	cx_write(AUD_INIT, mode);
	cx_write(AUD_INIT_LD, 0x0001);
	cx_write(AUD_SOFT_RESET, 0x0001);
L
Linus Torvalds 已提交
129 130
}

131
static void set_audio_finish(struct cx88_core *core, u32 ctl)
L
Linus Torvalds 已提交
132 133 134
{
	u32 volume;

135 136
	cx_write(AUD_RATE_THRES_DMD, 0x000000C0);

L
Linus Torvalds 已提交
137
	if (cx88_boards[core->board].blackbird) {
138
		/* sets sound input from external adc */
139 140 141
		cx_set(AUD_CTL, EN_I2SIN_ENABLE);
		cx_write(AUD_I2SINPUTCNTL, 4);
		cx_write(AUD_BAUDRATE, 1);
142
		/* 'pass-thru mode': this enables the i2s output to the mpeg encoder */
143
		cx_set(AUD_CTL, EN_I2SOUT_ENABLE);
L
Linus Torvalds 已提交
144
		cx_write(AUD_I2SOUTPUTCNTL, 1);
145
		cx_write(AUD_I2SCNTL, 0);
146
		/* cx_write(AUD_APB_IN_RATE_ADJ, 0); */
147
	} else {
148 149
		ctl |= EN_DAC_ENABLE;
		cx_write(AUD_CTL, ctl);
L
Linus Torvalds 已提交
150 151
	}

152
	/* finish programming */
L
Linus Torvalds 已提交
153 154
	cx_write(AUD_SOFT_RESET, 0x0000);

155
	/* unmute */
L
Linus Torvalds 已提交
156 157 158 159 160 161
	volume = cx_sread(SHADOW_AUD_VOL_CTL);
	cx_swrite(SHADOW_AUD_VOL_CTL, AUD_VOL_CTL, volume);
}

/* ----------------------------------------------------------- */

162 163
static void set_audio_standard_BTSC(struct cx88_core *core, unsigned int sap,
				    u32 mode)
L
Linus Torvalds 已提交
164 165
{
	static const struct rlist btsc[] = {
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
		{AUD_AFE_12DB_EN, 0x00000001},
		{AUD_OUT1_SEL, 0x00000013},
		{AUD_OUT1_SHIFT, 0x00000000},
		{AUD_POLY0_DDS_CONSTANT, 0x0012010c},
		{AUD_DMD_RA_DDS, 0x00c3e7aa},
		{AUD_DBX_IN_GAIN, 0x00004734},
		{AUD_DBX_WBE_GAIN, 0x00004640},
		{AUD_DBX_SE_GAIN, 0x00008d31},
		{AUD_DCOC_0_SRC, 0x0000001a},
		{AUD_IIR1_4_SEL, 0x00000021},
		{AUD_DCOC_PASS_IN, 0x00000003},
		{AUD_DCOC_0_SHIFT_IN0, 0x0000000a},
		{AUD_DCOC_0_SHIFT_IN1, 0x00000008},
		{AUD_DCOC_1_SHIFT_IN0, 0x0000000a},
		{AUD_DCOC_1_SHIFT_IN1, 0x00000008},
		{AUD_DN0_FREQ, 0x0000283b},
		{AUD_DN2_SRC_SEL, 0x00000008},
		{AUD_DN2_FREQ, 0x00003000},
		{AUD_DN2_AFC, 0x00000002},
		{AUD_DN2_SHFT, 0x00000000},
		{AUD_IIR2_2_SEL, 0x00000020},
		{AUD_IIR2_2_SHIFT, 0x00000000},
		{AUD_IIR2_3_SEL, 0x0000001f},
		{AUD_IIR2_3_SHIFT, 0x00000000},
		{AUD_CRDC1_SRC_SEL, 0x000003ce},
		{AUD_CRDC1_SHIFT, 0x00000000},
		{AUD_CORDIC_SHIFT_1, 0x00000007},
		{AUD_DCOC_1_SRC, 0x0000001b},
		{AUD_DCOC1_SHIFT, 0x00000000},
		{AUD_RDSI_SEL, 0x00000008},
		{AUD_RDSQ_SEL, 0x00000008},
		{AUD_RDSI_SHIFT, 0x00000000},
		{AUD_RDSQ_SHIFT, 0x00000000},
		{AUD_POLYPH80SCALEFAC, 0x00000003},
200
		{ /* end of list */ },
L
Linus Torvalds 已提交
201 202
	};
	static const struct rlist btsc_sap[] = {
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
		{AUD_AFE_12DB_EN, 0x00000001},
		{AUD_DBX_IN_GAIN, 0x00007200},
		{AUD_DBX_WBE_GAIN, 0x00006200},
		{AUD_DBX_SE_GAIN, 0x00006200},
		{AUD_IIR1_1_SEL, 0x00000000},
		{AUD_IIR1_3_SEL, 0x00000001},
		{AUD_DN1_SRC_SEL, 0x00000007},
		{AUD_IIR1_4_SHIFT, 0x00000006},
		{AUD_IIR2_1_SHIFT, 0x00000000},
		{AUD_IIR2_2_SHIFT, 0x00000000},
		{AUD_IIR3_0_SHIFT, 0x00000000},
		{AUD_IIR3_1_SHIFT, 0x00000000},
		{AUD_IIR3_0_SEL, 0x0000000d},
		{AUD_IIR3_1_SEL, 0x0000000e},
		{AUD_DEEMPH1_SRC_SEL, 0x00000014},
		{AUD_DEEMPH1_SHIFT, 0x00000000},
		{AUD_DEEMPH1_G0, 0x00004000},
		{AUD_DEEMPH1_A0, 0x00000000},
		{AUD_DEEMPH1_B0, 0x00000000},
		{AUD_DEEMPH1_A1, 0x00000000},
		{AUD_DEEMPH1_B1, 0x00000000},
		{AUD_OUT0_SEL, 0x0000003f},
		{AUD_OUT1_SEL, 0x0000003f},
		{AUD_DN1_AFC, 0x00000002},
		{AUD_DCOC_0_SHIFT_IN0, 0x0000000a},
		{AUD_DCOC_0_SHIFT_IN1, 0x00000008},
		{AUD_DCOC_1_SHIFT_IN0, 0x0000000a},
		{AUD_DCOC_1_SHIFT_IN1, 0x00000008},
		{AUD_IIR1_0_SEL, 0x0000001d},
		{AUD_IIR1_2_SEL, 0x0000001e},
		{AUD_IIR2_1_SEL, 0x00000002},
		{AUD_IIR2_2_SEL, 0x00000004},
		{AUD_IIR3_2_SEL, 0x0000000f},
		{AUD_DCOC2_SHIFT, 0x00000001},
		{AUD_IIR3_2_SHIFT, 0x00000001},
		{AUD_DEEMPH0_SRC_SEL, 0x00000014},
		{AUD_CORDIC_SHIFT_1, 0x00000006},
		{AUD_POLY0_DDS_CONSTANT, 0x000e4db2},
		{AUD_DMD_RA_DDS, 0x00f696e6},
		{AUD_IIR2_3_SEL, 0x00000025},
		{AUD_IIR1_4_SEL, 0x00000021},
		{AUD_DN1_FREQ, 0x0000c965},
		{AUD_DCOC_PASS_IN, 0x00000003},
		{AUD_DCOC_0_SRC, 0x0000001a},
		{AUD_DCOC_1_SRC, 0x0000001b},
		{AUD_DCOC1_SHIFT, 0x00000000},
		{AUD_RDSI_SEL, 0x00000009},
		{AUD_RDSQ_SEL, 0x00000009},
		{AUD_RDSI_SHIFT, 0x00000000},
		{AUD_RDSQ_SHIFT, 0x00000000},
		{AUD_POLYPH80SCALEFAC, 0x00000003},
254
		{ /* end of list */ },
L
Linus Torvalds 已提交
255 256
	};

257 258
	mode |= EN_FMRADIO_EN_RDS;

L
Linus Torvalds 已提交
259
	if (sap) {
260 261
		dprintk("%s SAP (status: unknown)\n", __FUNCTION__);
		set_audio_start(core, SEL_SAP);
L
Linus Torvalds 已提交
262
		set_audio_registers(core, btsc_sap);
263
		set_audio_finish(core, mode);
L
Linus Torvalds 已提交
264
	} else {
265 266
		dprintk("%s (status: known-good)\n", __FUNCTION__);
		set_audio_start(core, SEL_BTSC);
L
Linus Torvalds 已提交
267
		set_audio_registers(core, btsc);
268
		set_audio_finish(core, mode);
L
Linus Torvalds 已提交
269 270 271
	}
}

272
static void set_audio_standard_NICAM(struct cx88_core *core, u32 mode)
L
Linus Torvalds 已提交
273
{
274
	static const struct rlist nicam_l[] = {
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
		{AUD_AFE_12DB_EN, 0x00000001},
		{AUD_RATE_ADJ1, 0x00000060},
		{AUD_RATE_ADJ2, 0x000000F9},
		{AUD_RATE_ADJ3, 0x000001CC},
		{AUD_RATE_ADJ4, 0x000002B3},
		{AUD_RATE_ADJ5, 0x00000726},
		{AUD_DEEMPHDENOM1_R, 0x0000F3D0},
		{AUD_DEEMPHDENOM2_R, 0x00000000},
		{AUD_ERRLOGPERIOD_R, 0x00000064},
		{AUD_ERRINTRPTTHSHLD1_R, 0x00000FFF},
		{AUD_ERRINTRPTTHSHLD2_R, 0x0000001F},
		{AUD_ERRINTRPTTHSHLD3_R, 0x0000000F},
		{AUD_POLYPH80SCALEFAC, 0x00000003},
		{AUD_DMD_RA_DDS, 0x00C00000},
		{AUD_PLL_INT, 0x0000001E},
		{AUD_PLL_DDS, 0x00000000},
		{AUD_PLL_FRAC, 0x0000E542},
		{AUD_START_TIMER, 0x00000000},
		{AUD_DEEMPHNUMER1_R, 0x000353DE},
		{AUD_DEEMPHNUMER2_R, 0x000001B1},
		{AUD_PDF_DDS_CNST_BYTE2, 0x06},
		{AUD_PDF_DDS_CNST_BYTE1, 0x82},
		{AUD_PDF_DDS_CNST_BYTE0, 0x12},
		{AUD_QAM_MODE, 0x05},
		{AUD_PHACC_FREQ_8MSB, 0x34},
		{AUD_PHACC_FREQ_8LSB, 0x4C},
		{AUD_DEEMPHGAIN_R, 0x00006680},
		{AUD_RATE_THRES_DMD, 0x000000C0},
		{ /* end of list */ },
	};
L
Linus Torvalds 已提交
305

306
	static const struct rlist nicam_bgdki_common[] = {
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
		{AUD_AFE_12DB_EN, 0x00000001},
		{AUD_RATE_ADJ1, 0x00000010},
		{AUD_RATE_ADJ2, 0x00000040},
		{AUD_RATE_ADJ3, 0x00000100},
		{AUD_RATE_ADJ4, 0x00000400},
		{AUD_RATE_ADJ5, 0x00001000},
		{AUD_ERRLOGPERIOD_R, 0x00000fff},
		{AUD_ERRINTRPTTHSHLD1_R, 0x000003ff},
		{AUD_ERRINTRPTTHSHLD2_R, 0x000000ff},
		{AUD_ERRINTRPTTHSHLD3_R, 0x0000003f},
		{AUD_POLYPH80SCALEFAC, 0x00000003},
		{AUD_DEEMPHGAIN_R, 0x000023c2},
		{AUD_DEEMPHNUMER1_R, 0x0002a7bc},
		{AUD_DEEMPHNUMER2_R, 0x0003023e},
		{AUD_DEEMPHDENOM1_R, 0x0000f3d0},
		{AUD_DEEMPHDENOM2_R, 0x00000000},
323
		{AUD_PDF_DDS_CNST_BYTE2, 0x06},
324 325 326
		{AUD_PDF_DDS_CNST_BYTE1, 0x82},
		{AUD_QAM_MODE, 0x05},
		{ /* end of list */ },
327 328 329
	};

	static const struct rlist nicam_i[] = {
330 331 332 333
		{AUD_PDF_DDS_CNST_BYTE0, 0x12},
		{AUD_PHACC_FREQ_8MSB, 0x3a},
		{AUD_PHACC_FREQ_8LSB, 0x93},
		{ /* end of list */ },
334 335
	};

336
	static const struct rlist nicam_default[] = {
337 338 339 340
		{AUD_PDF_DDS_CNST_BYTE0, 0x16},
		{AUD_PHACC_FREQ_8MSB, 0x34},
		{AUD_PHACC_FREQ_8LSB, 0x4c},
		{ /* end of list */ },
341
	};
342

343
	set_audio_start(core,SEL_NICAM);
344 345
	switch (core->tvaudio) {
	case WW_L:
346
		dprintk("%s SECAM-L NICAM (status: devel)\n", __FUNCTION__);
347 348 349
		set_audio_registers(core, nicam_l);
		break;
	case WW_I:
350
		dprintk("%s PAL-I NICAM (status: known-good)\n", __FUNCTION__);
351 352 353 354
		set_audio_registers(core, nicam_bgdki_common);
		set_audio_registers(core, nicam_i);
		break;
	default:
355
		dprintk("%s PAL-BGDK NICAM (status: known-good)\n", __FUNCTION__);
356 357 358 359 360 361 362
		set_audio_registers(core, nicam_bgdki_common);
		set_audio_registers(core, nicam_default);
		break;
	};

	mode |= EN_DMTRX_LR | EN_DMTRX_BYPASS;
	set_audio_finish(core, mode);
L
Linus Torvalds 已提交
363 364
}

365
static void set_audio_standard_A2(struct cx88_core *core, u32 mode)
L
Linus Torvalds 已提交
366
{
367
	static const struct rlist a2_bgdk_common[] = {
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
		{AUD_ERRLOGPERIOD_R, 0x00000064},
		{AUD_ERRINTRPTTHSHLD1_R, 0x00000fff},
		{AUD_ERRINTRPTTHSHLD2_R, 0x0000001f},
		{AUD_ERRINTRPTTHSHLD3_R, 0x0000000f},
		{AUD_PDF_DDS_CNST_BYTE2, 0x06},
		{AUD_PDF_DDS_CNST_BYTE1, 0x82},
		{AUD_PDF_DDS_CNST_BYTE0, 0x12},
		{AUD_QAM_MODE, 0x05},
		{AUD_PHACC_FREQ_8MSB, 0x34},
		{AUD_PHACC_FREQ_8LSB, 0x4c},
		{AUD_RATE_ADJ1, 0x00000100},
		{AUD_RATE_ADJ2, 0x00000200},
		{AUD_RATE_ADJ3, 0x00000300},
		{AUD_RATE_ADJ4, 0x00000400},
		{AUD_RATE_ADJ5, 0x00000500},
		{AUD_THR_FR, 0x00000000},
		{AAGC_HYST, 0x0000001a},
		{AUD_PILOT_BQD_1_K0, 0x0000755b},
		{AUD_PILOT_BQD_1_K1, 0x00551340},
		{AUD_PILOT_BQD_1_K2, 0x006d30be},
		{AUD_PILOT_BQD_1_K3, 0xffd394af},
		{AUD_PILOT_BQD_1_K4, 0x00400000},
		{AUD_PILOT_BQD_2_K0, 0x00040000},
		{AUD_PILOT_BQD_2_K1, 0x002a4841},
		{AUD_PILOT_BQD_2_K2, 0x00400000},
		{AUD_PILOT_BQD_2_K3, 0x00000000},
		{AUD_PILOT_BQD_2_K4, 0x00000000},
		{AUD_MODE_CHG_TIMER, 0x00000040},
		{AUD_AFE_12DB_EN, 0x00000001},
		{AUD_CORDIC_SHIFT_0, 0x00000007},
		{AUD_CORDIC_SHIFT_1, 0x00000007},
		{AUD_DEEMPH0_G0, 0x00000380},
		{AUD_DEEMPH1_G0, 0x00000380},
		{AUD_DCOC_0_SRC, 0x0000001a},
		{AUD_DCOC0_SHIFT, 0x00000000},
		{AUD_DCOC_0_SHIFT_IN0, 0x0000000a},
		{AUD_DCOC_0_SHIFT_IN1, 0x00000008},
		{AUD_DCOC_PASS_IN, 0x00000003},
		{AUD_IIR3_0_SEL, 0x00000021},
		{AUD_DN2_AFC, 0x00000002},
		{AUD_DCOC_1_SRC, 0x0000001b},
		{AUD_DCOC1_SHIFT, 0x00000000},
		{AUD_DCOC_1_SHIFT_IN0, 0x0000000a},
		{AUD_DCOC_1_SHIFT_IN1, 0x00000008},
		{AUD_IIR3_1_SEL, 0x00000023},
		{AUD_RDSI_SEL, 0x00000017},
		{AUD_RDSI_SHIFT, 0x00000000},
		{AUD_RDSQ_SEL, 0x00000017},
		{AUD_RDSQ_SHIFT, 0x00000000},
		{AUD_PLL_INT, 0x0000001e},
		{AUD_PLL_DDS, 0x00000000},
		{AUD_PLL_FRAC, 0x0000e542},
		{AUD_POLYPH80SCALEFAC, 0x00000001},
		{AUD_START_TIMER, 0x00000000},
		{ /* end of list */ },
423
	};
L
Linus Torvalds 已提交
424

425
	static const struct rlist a2_bg[] = {
426 427 428 429 430 431
		{AUD_DMD_RA_DDS, 0x002a4f2f},
		{AUD_C1_UP_THR, 0x00007000},
		{AUD_C1_LO_THR, 0x00005400},
		{AUD_C2_UP_THR, 0x00005400},
		{AUD_C2_LO_THR, 0x00003000},
		{ /* end of list */ },
L
Linus Torvalds 已提交
432 433
	};

434
	static const struct rlist a2_dk[] = {
435 436 437 438 439 440 441 442
		{AUD_DMD_RA_DDS, 0x002a4f2f},
		{AUD_C1_UP_THR, 0x00007000},
		{AUD_C1_LO_THR, 0x00005400},
		{AUD_C2_UP_THR, 0x00005400},
		{AUD_C2_LO_THR, 0x00003000},
		{AUD_DN0_FREQ, 0x00003a1c},
		{AUD_DN2_FREQ, 0x0000d2e0},
		{ /* end of list */ },
L
Linus Torvalds 已提交
443
	};
444 445

	static const struct rlist a1_i[] = {
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 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511
		{AUD_ERRLOGPERIOD_R, 0x00000064},
		{AUD_ERRINTRPTTHSHLD1_R, 0x00000fff},
		{AUD_ERRINTRPTTHSHLD2_R, 0x0000001f},
		{AUD_ERRINTRPTTHSHLD3_R, 0x0000000f},
		{AUD_PDF_DDS_CNST_BYTE2, 0x06},
		{AUD_PDF_DDS_CNST_BYTE1, 0x82},
		{AUD_PDF_DDS_CNST_BYTE0, 0x12},
		{AUD_QAM_MODE, 0x05},
		{AUD_PHACC_FREQ_8MSB, 0x3a},
		{AUD_PHACC_FREQ_8LSB, 0x93},
		{AUD_DMD_RA_DDS, 0x002a4f2f},
		{AUD_PLL_INT, 0x0000001e},
		{AUD_PLL_DDS, 0x00000004},
		{AUD_PLL_FRAC, 0x0000e542},
		{AUD_RATE_ADJ1, 0x00000100},
		{AUD_RATE_ADJ2, 0x00000200},
		{AUD_RATE_ADJ3, 0x00000300},
		{AUD_RATE_ADJ4, 0x00000400},
		{AUD_RATE_ADJ5, 0x00000500},
		{AUD_THR_FR, 0x00000000},
		{AUD_PILOT_BQD_1_K0, 0x0000755b},
		{AUD_PILOT_BQD_1_K1, 0x00551340},
		{AUD_PILOT_BQD_1_K2, 0x006d30be},
		{AUD_PILOT_BQD_1_K3, 0xffd394af},
		{AUD_PILOT_BQD_1_K4, 0x00400000},
		{AUD_PILOT_BQD_2_K0, 0x00040000},
		{AUD_PILOT_BQD_2_K1, 0x002a4841},
		{AUD_PILOT_BQD_2_K2, 0x00400000},
		{AUD_PILOT_BQD_2_K3, 0x00000000},
		{AUD_PILOT_BQD_2_K4, 0x00000000},
		{AUD_MODE_CHG_TIMER, 0x00000060},
		{AUD_AFE_12DB_EN, 0x00000001},
		{AAGC_HYST, 0x0000000a},
		{AUD_CORDIC_SHIFT_0, 0x00000007},
		{AUD_CORDIC_SHIFT_1, 0x00000007},
		{AUD_C1_UP_THR, 0x00007000},
		{AUD_C1_LO_THR, 0x00005400},
		{AUD_C2_UP_THR, 0x00005400},
		{AUD_C2_LO_THR, 0x00003000},
		{AUD_DCOC_0_SRC, 0x0000001a},
		{AUD_DCOC0_SHIFT, 0x00000000},
		{AUD_DCOC_0_SHIFT_IN0, 0x0000000a},
		{AUD_DCOC_0_SHIFT_IN1, 0x00000008},
		{AUD_DCOC_PASS_IN, 0x00000003},
		{AUD_IIR3_0_SEL, 0x00000021},
		{AUD_DN2_AFC, 0x00000002},
		{AUD_DCOC_1_SRC, 0x0000001b},
		{AUD_DCOC1_SHIFT, 0x00000000},
		{AUD_DCOC_1_SHIFT_IN0, 0x0000000a},
		{AUD_DCOC_1_SHIFT_IN1, 0x00000008},
		{AUD_IIR3_1_SEL, 0x00000023},
		{AUD_DN0_FREQ, 0x000035a3},
		{AUD_DN2_FREQ, 0x000029c7},
		{AUD_CRDC0_SRC_SEL, 0x00000511},
		{AUD_IIR1_0_SEL, 0x00000001},
		{AUD_IIR1_1_SEL, 0x00000000},
		{AUD_IIR3_2_SEL, 0x00000003},
		{AUD_IIR3_2_SHIFT, 0x00000000},
		{AUD_IIR3_0_SEL, 0x00000002},
		{AUD_IIR2_0_SEL, 0x00000021},
		{AUD_IIR2_0_SHIFT, 0x00000002},
		{AUD_DEEMPH0_SRC_SEL, 0x0000000b},
		{AUD_DEEMPH1_SRC_SEL, 0x0000000b},
		{AUD_POLYPH80SCALEFAC, 0x00000001},
		{AUD_START_TIMER, 0x00000000},
		{ /* end of list */ },
512 513 514
	};

	static const struct rlist am_l[] = {
515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580
		{AUD_ERRLOGPERIOD_R, 0x00000064},
		{AUD_ERRINTRPTTHSHLD1_R, 0x00000FFF},
		{AUD_ERRINTRPTTHSHLD2_R, 0x0000001F},
		{AUD_ERRINTRPTTHSHLD3_R, 0x0000000F},
		{AUD_PDF_DDS_CNST_BYTE2, 0x48},
		{AUD_PDF_DDS_CNST_BYTE1, 0x3D},
		{AUD_QAM_MODE, 0x00},
		{AUD_PDF_DDS_CNST_BYTE0, 0xf5},
		{AUD_PHACC_FREQ_8MSB, 0x3a},
		{AUD_PHACC_FREQ_8LSB, 0x4a},
		{AUD_DEEMPHGAIN_R, 0x00006680},
		{AUD_DEEMPHNUMER1_R, 0x000353DE},
		{AUD_DEEMPHNUMER2_R, 0x000001B1},
		{AUD_DEEMPHDENOM1_R, 0x0000F3D0},
		{AUD_DEEMPHDENOM2_R, 0x00000000},
		{AUD_FM_MODE_ENABLE, 0x00000007},
		{AUD_POLYPH80SCALEFAC, 0x00000003},
		{AUD_AFE_12DB_EN, 0x00000001},
		{AAGC_GAIN, 0x00000000},
		{AAGC_HYST, 0x00000018},
		{AAGC_DEF, 0x00000020},
		{AUD_DN0_FREQ, 0x00000000},
		{AUD_POLY0_DDS_CONSTANT, 0x000E4DB2},
		{AUD_DCOC_0_SRC, 0x00000021},
		{AUD_IIR1_0_SEL, 0x00000000},
		{AUD_IIR1_0_SHIFT, 0x00000007},
		{AUD_IIR1_1_SEL, 0x00000002},
		{AUD_IIR1_1_SHIFT, 0x00000000},
		{AUD_DCOC_1_SRC, 0x00000003},
		{AUD_DCOC1_SHIFT, 0x00000000},
		{AUD_DCOC_PASS_IN, 0x00000000},
		{AUD_IIR1_2_SEL, 0x00000023},
		{AUD_IIR1_2_SHIFT, 0x00000000},
		{AUD_IIR1_3_SEL, 0x00000004},
		{AUD_IIR1_3_SHIFT, 0x00000007},
		{AUD_IIR1_4_SEL, 0x00000005},
		{AUD_IIR1_4_SHIFT, 0x00000007},
		{AUD_IIR3_0_SEL, 0x00000007},
		{AUD_IIR3_0_SHIFT, 0x00000000},
		{AUD_DEEMPH0_SRC_SEL, 0x00000011},
		{AUD_DEEMPH0_SHIFT, 0x00000000},
		{AUD_DEEMPH0_G0, 0x00007000},
		{AUD_DEEMPH0_A0, 0x00000000},
		{AUD_DEEMPH0_B0, 0x00000000},
		{AUD_DEEMPH0_A1, 0x00000000},
		{AUD_DEEMPH0_B1, 0x00000000},
		{AUD_DEEMPH1_SRC_SEL, 0x00000011},
		{AUD_DEEMPH1_SHIFT, 0x00000000},
		{AUD_DEEMPH1_G0, 0x00007000},
		{AUD_DEEMPH1_A0, 0x00000000},
		{AUD_DEEMPH1_B0, 0x00000000},
		{AUD_DEEMPH1_A1, 0x00000000},
		{AUD_DEEMPH1_B1, 0x00000000},
		{AUD_OUT0_SEL, 0x0000003F},
		{AUD_OUT1_SEL, 0x0000003F},
		{AUD_DMD_RA_DDS, 0x00F5C285},
		{AUD_PLL_INT, 0x0000001E},
		{AUD_PLL_DDS, 0x00000000},
		{AUD_PLL_FRAC, 0x0000E542},
		{AUD_RATE_ADJ1, 0x00000100},
		{AUD_RATE_ADJ2, 0x00000200},
		{AUD_RATE_ADJ3, 0x00000300},
		{AUD_RATE_ADJ4, 0x00000400},
		{AUD_RATE_ADJ5, 0x00000500},
		{AUD_RATE_THRES_DMD, 0x000000C0},
		{ /* end of list */ },
L
Linus Torvalds 已提交
581
	};
582 583

	static const struct rlist a2_deemph50[] = {
584 585 586 587 588 589
		{AUD_DEEMPH0_G0, 0x00000380},
		{AUD_DEEMPH1_G0, 0x00000380},
		{AUD_DEEMPHGAIN_R, 0x000011e1},
		{AUD_DEEMPHNUMER1_R, 0x0002a7bc},
		{AUD_DEEMPHNUMER2_R, 0x0003023c},
		{ /* end of list */ },
590 591 592
	};

	set_audio_start(core, SEL_A2);
L
Linus Torvalds 已提交
593
	switch (core->tvaudio) {
594
	case WW_BG:
595
		dprintk("%s PAL-BG A1/2 (status: known-good)\n", __FUNCTION__);
596 597 598
		set_audio_registers(core, a2_bgdk_common);
		set_audio_registers(core, a2_bg);
		set_audio_registers(core, a2_deemph50);
L
Linus Torvalds 已提交
599
		break;
600
	case WW_DK:
601
		dprintk("%s PAL-DK A1/2 (status: known-good)\n", __FUNCTION__);
602 603 604
		set_audio_registers(core, a2_bgdk_common);
		set_audio_registers(core, a2_dk);
		set_audio_registers(core, a2_deemph50);
L
Linus Torvalds 已提交
605
		break;
606
	case WW_I:
607
		dprintk("%s PAL-I A1 (status: known-good)\n", __FUNCTION__);
608 609 610 611
		set_audio_registers(core, a1_i);
		set_audio_registers(core, a2_deemph50);
		break;
	case WW_L:
612
		dprintk("%s AM-L (status: devel)\n", __FUNCTION__);
613 614 615
		set_audio_registers(core, am_l);
		break;
	default:
616
		dprintk("%s Warning: wrong value\n", __FUNCTION__);
617
		return;
L
Linus Torvalds 已提交
618 619
		break;
	};
620 621 622

	mode |= EN_FMRADIO_EN_RDS | EN_DMTRX_SUMDIFF;
	set_audio_finish(core, mode);
L
Linus Torvalds 已提交
623 624 625 626 627 628 629 630 631
}

static void set_audio_standard_EIAJ(struct cx88_core *core)
{
	static const struct rlist eiaj[] = {
		/* TODO: eiaj register settings are not there yet ... */

		{ /* end of list */ },
	};
632
	dprintk("%s (status: unknown)\n", __FUNCTION__);
L
Linus Torvalds 已提交
633

634
	set_audio_start(core, SEL_EIAJ);
L
Linus Torvalds 已提交
635
	set_audio_registers(core, eiaj);
636
	set_audio_finish(core, EN_EIAJ_AUTO_STEREO);
L
Linus Torvalds 已提交
637 638
}

639 640
static void set_audio_standard_FM(struct cx88_core *core,
				  enum cx88_deemph_type deemph)
L
Linus Torvalds 已提交
641
{
642
	static const struct rlist fm_deemph_50[] = {
643 644 645 646 647 648 649 650 651 652 653 654 655
		{AUD_DEEMPH0_G0, 0x0C45},
		{AUD_DEEMPH0_A0, 0x6262},
		{AUD_DEEMPH0_B0, 0x1C29},
		{AUD_DEEMPH0_A1, 0x3FC66},
		{AUD_DEEMPH0_B1, 0x399A},

		{AUD_DEEMPH1_G0, 0x0D80},
		{AUD_DEEMPH1_A0, 0x6262},
		{AUD_DEEMPH1_B0, 0x1C29},
		{AUD_DEEMPH1_A1, 0x3FC66},
		{AUD_DEEMPH1_B1, 0x399A},

		{AUD_POLYPH80SCALEFAC, 0x0003},
656 657 658
		{ /* end of list */ },
	};
	static const struct rlist fm_deemph_75[] = {
659 660 661 662 663 664 665 666 667 668 669 670 671
		{AUD_DEEMPH0_G0, 0x091B},
		{AUD_DEEMPH0_A0, 0x6B68},
		{AUD_DEEMPH0_B0, 0x11EC},
		{AUD_DEEMPH0_A1, 0x3FC66},
		{AUD_DEEMPH0_B1, 0x399A},

		{AUD_DEEMPH1_G0, 0x0AA0},
		{AUD_DEEMPH1_A0, 0x6B68},
		{AUD_DEEMPH1_B0, 0x11EC},
		{AUD_DEEMPH1_A1, 0x3FC66},
		{AUD_DEEMPH1_B1, 0x399A},

		{AUD_POLYPH80SCALEFAC, 0x0003},
672 673
		{ /* end of list */ },
	};
L
Linus Torvalds 已提交
674

675 676
	/* It is enough to leave default values? */
	static const struct rlist fm_no_deemph[] = {
L
Linus Torvalds 已提交
677

678
		{AUD_POLYPH80SCALEFAC, 0x0003},
679 680
		{ /* end of list */ },
	};
L
Linus Torvalds 已提交
681

682
	dprintk("%s (status: unknown)\n", __FUNCTION__);
683
	set_audio_start(core, SEL_FMRADIO);
L
Linus Torvalds 已提交
684

685 686 687 688
	switch (deemph) {
	case FM_NO_DEEMPH:
		set_audio_registers(core, fm_no_deemph);
		break;
L
Linus Torvalds 已提交
689

690 691 692
	case FM_DEEMPH_50:
		set_audio_registers(core, fm_deemph_50);
		break;
L
Linus Torvalds 已提交
693

694 695 696
	case FM_DEEMPH_75:
		set_audio_registers(core, fm_deemph_75);
		break;
697
	}
L
Linus Torvalds 已提交
698

699
	set_audio_finish(core, EN_FMRADIO_AUTO_STEREO);
L
Linus Torvalds 已提交
700 701 702 703
}

/* ----------------------------------------------------------- */

704 705
int cx88_detect_nicam(struct cx88_core *core)
{
706
	int i, j = 0;
707 708 709

	dprintk("start nicam autodetect.\n");

710 711 712
	for (i = 0; i < 6; i++) {
		/* if bit1=1 then nicam is detected */
		j += ((cx_read(AUD_NICAM_STATUS2) & 0x02) >> 1);
713

714
		if (j == 1) {
715 716 717 718 719
			dprintk("nicam is detected.\n");
			return 1;
		}

		/* wait a little bit for next reading status */
720
		msleep(10);
721 722 723 724 725 726
	}

	dprintk("nicam is not detected.\n");
	return 0;
}

L
Linus Torvalds 已提交
727 728 729 730
void cx88_set_tvaudio(struct cx88_core *core)
{
	switch (core->tvaudio) {
	case WW_BTSC:
731
		set_audio_standard_BTSC(core, 0, EN_BTSC_AUTO_STEREO);
L
Linus Torvalds 已提交
732
		break;
733 734 735 736 737 738 739 740 741
	case WW_BG:
	case WW_DK:
	case WW_I:
	case WW_L:
		/* prepare all dsp registers */
		set_audio_standard_A2(core, EN_A2_FORCE_MONO1);

		/* set nicam mode - otherwise
		   AUD_NICAM_STATUS2 contains wrong values */
742
		set_audio_standard_NICAM(core, EN_NICAM_AUTO_STEREO);
743
		if (0 == cx88_detect_nicam(core)) {
744 745 746
			/* fall back to fm / am mono */
			set_audio_standard_A2(core, EN_A2_FORCE_MONO1);
			core->use_nicam = 0;
747
		} else {
748
			core->use_nicam = 1;
749
		}
L
Linus Torvalds 已提交
750 751 752 753 754
		break;
	case WW_EIAJ:
		set_audio_standard_EIAJ(core);
		break;
	case WW_FM:
755
		set_audio_standard_FM(core, FM_NO_DEEMPH);
L
Linus Torvalds 已提交
756 757 758 759
		break;
	case WW_NONE:
	default:
		printk("%s/0: unknown tv audio mode [%d]\n",
760
		       core->name, core->tvaudio);
L
Linus Torvalds 已提交
761 762 763 764 765 766 767 768 769 770 771 772
		break;
	}
	return;
}

void cx88_newstation(struct cx88_core *core)
{
	core->audiomode_manual = UNSET;
}

void cx88_get_stereo(struct cx88_core *core, struct v4l2_tuner *t)
{
773 774 775
	static char *m[] = { "stereo", "dual mono", "mono", "sap" };
	static char *p[] = { "no pilot", "pilot c1", "pilot c2", "?" };
	u32 reg, mode, pilot;
L
Linus Torvalds 已提交
776

777 778
	reg = cx_read(AUD_STATUS);
	mode = reg & 0x03;
L
Linus Torvalds 已提交
779 780 781 782 783 784 785 786
	pilot = (reg >> 2) & 0x03;

	if (core->astat != reg)
		dprintk("AUD_STATUS: 0x%x [%s/%s] ctl=%s\n",
			reg, m[mode], p[pilot],
			aud_ctl_names[cx_read(AUD_CTL) & 63]);
	core->astat = reg;

787 788 789 790 791 792 793
/* TODO
       Reading from AUD_STATUS is not enough
       for auto-detecting sap/dual-fm/nicam.
       Add some code here later.
*/

# if 0
L
Linus Torvalds 已提交
794
	t->capability = V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_SAP |
795
	    V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2;
L
Linus Torvalds 已提交
796
	t->rxsubchans = V4L2_TUNER_SUB_MONO;
797
	t->audmode = V4L2_TUNER_MODE_MONO;
L
Linus Torvalds 已提交
798 799 800

	switch (core->tvaudio) {
	case WW_BTSC:
801
		t->capability = V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_SAP;
L
Linus Torvalds 已提交
802
		t->rxsubchans = V4L2_TUNER_SUB_STEREO;
803
		if (1 == pilot) {
L
Linus Torvalds 已提交
804 805 806 807 808 809 810
			/* SAP */
			t->rxsubchans |= V4L2_TUNER_SUB_SAP;
		}
		break;
	case WW_A2_BG:
	case WW_A2_DK:
	case WW_A2_M:
811
		if (1 == pilot) {
L
Linus Torvalds 已提交
812
			/* stereo */
813 814
			t->rxsubchans =
			    V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO;
L
Linus Torvalds 已提交
815 816 817
			if (0 == mode)
				t->audmode = V4L2_TUNER_MODE_STEREO;
		}
818
		if (2 == pilot) {
L
Linus Torvalds 已提交
819
			/* dual language -- FIXME */
820 821
			t->rxsubchans =
			    V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
L
Linus Torvalds 已提交
822 823 824 825 826 827 828 829 830
			t->audmode = V4L2_TUNER_MODE_LANG1;
		}
		break;
	case WW_NICAM_BGDKL:
		if (0 == mode) {
			t->audmode = V4L2_TUNER_MODE_STEREO;
			t->rxsubchans |= V4L2_TUNER_SUB_STEREO;
		}
		break;
831 832 833
	case WW_SYSTEM_L_AM:
		if (0x0 == mode && !(cx_read(AUD_INIT) & 0x04)) {
			t->audmode = V4L2_TUNER_MODE_STEREO;
L
Linus Torvalds 已提交
834 835
			t->rxsubchans |= V4L2_TUNER_SUB_STEREO;
		}
836
		break;
L
Linus Torvalds 已提交
837 838 839 840
	default:
		/* nothing */
		break;
	}
841
# endif
L
Linus Torvalds 已提交
842 843 844 845 846
	return;
}

void cx88_set_stereo(struct cx88_core *core, u32 mode, int manual)
{
847
	u32 ctl = UNSET;
L
Linus Torvalds 已提交
848 849 850 851 852 853 854 855 856 857 858 859 860 861
	u32 mask = UNSET;

	if (manual) {
		core->audiomode_manual = mode;
	} else {
		if (UNSET != core->audiomode_manual)
			return;
	}
	core->audiomode_current = mode;

	switch (core->tvaudio) {
	case WW_BTSC:
		switch (mode) {
		case V4L2_TUNER_MODE_MONO:
862
			set_audio_standard_BTSC(core, 0, EN_BTSC_FORCE_MONO);
L
Linus Torvalds 已提交
863
			break;
864 865 866 867 868
		case V4L2_TUNER_MODE_LANG1:
			set_audio_standard_BTSC(core, 0, EN_BTSC_AUTO_STEREO);
			break;
		case V4L2_TUNER_MODE_LANG2:
			set_audio_standard_BTSC(core, 1, EN_BTSC_FORCE_SAP);
L
Linus Torvalds 已提交
869 870
			break;
		case V4L2_TUNER_MODE_STEREO:
871
			set_audio_standard_BTSC(core, 0, EN_BTSC_FORCE_STEREO);
L
Linus Torvalds 已提交
872 873 874
			break;
		}
		break;
875 876 877 878
	case WW_BG:
	case WW_DK:
	case WW_I:
	case WW_L:
879
		if (1 == core->use_nicam) {
880 881 882
			switch (mode) {
			case V4L2_TUNER_MODE_MONO:
			case V4L2_TUNER_MODE_LANG1:
883 884
				set_audio_standard_NICAM(core,
							 EN_NICAM_FORCE_MONO1);
885 886
				break;
			case V4L2_TUNER_MODE_LANG2:
887 888
				set_audio_standard_NICAM(core,
							 EN_NICAM_FORCE_MONO2);
889 890
				break;
			case V4L2_TUNER_MODE_STEREO:
891 892
				set_audio_standard_NICAM(core,
							 EN_NICAM_FORCE_STEREO);
893 894 895
				break;
			}
		} else {
896
			if ((core->tvaudio == WW_I) || (core->tvaudio == WW_L)) {
897 898 899 900 901 902 903
				/* fall back to fm / am mono */
				set_audio_standard_A2(core, EN_A2_FORCE_MONO1);
			} else {
				/* TODO: Add A2 autodection */
				switch (mode) {
				case V4L2_TUNER_MODE_MONO:
				case V4L2_TUNER_MODE_LANG1:
904 905
					set_audio_standard_A2(core,
							      EN_A2_FORCE_MONO1);
906 907
					break;
				case V4L2_TUNER_MODE_LANG2:
908 909
					set_audio_standard_A2(core,
							      EN_A2_FORCE_MONO2);
910 911
					break;
				case V4L2_TUNER_MODE_STEREO:
912 913
					set_audio_standard_A2(core,
							      EN_A2_FORCE_STEREO);
914 915 916
					break;
				}
			}
L
Linus Torvalds 已提交
917 918 919 920 921
		}
		break;
	case WW_FM:
		switch (mode) {
		case V4L2_TUNER_MODE_MONO:
922
			ctl = EN_FMRADIO_FORCE_MONO;
L
Linus Torvalds 已提交
923 924 925
			mask = 0x3f;
			break;
		case V4L2_TUNER_MODE_STEREO:
926
			ctl = EN_FMRADIO_AUTO_STEREO;
L
Linus Torvalds 已提交
927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955
			mask = 0x3f;
			break;
		}
		break;
	}

	if (UNSET != ctl) {
		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));
		cx_andor(AUD_CTL, mask, ctl);
	}
	return;
}

int cx88_audio_thread(void *data)
{
	struct cx88_core *core = data;
	struct v4l2_tuner t;
	u32 mode = 0;

	dprintk("cx88: tvaudio thread started\n");
	for (;;) {
		msleep_interruptible(1000);
		if (kthread_should_stop())
			break;

		/* just monitor the audio status for now ... */
956 957
		memset(&t, 0, sizeof(t));
		cx88_get_stereo(core, &t);
L
Linus Torvalds 已提交
958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990

		if (UNSET != core->audiomode_manual)
			/* manually set, don't do anything. */
			continue;

		/* monitor signal */
		if (t.rxsubchans & V4L2_TUNER_SUB_STEREO)
			mode = V4L2_TUNER_MODE_STEREO;
		else
			mode = V4L2_TUNER_MODE_MONO;
		if (mode == core->audiomode_current)
			continue;

		/* automatically switch to best available mode */
		cx88_set_stereo(core, mode, 0);
	}

	dprintk("cx88: tvaudio thread exiting\n");
	return 0;
}

/* ----------------------------------------------------------- */

EXPORT_SYMBOL(cx88_set_tvaudio);
EXPORT_SYMBOL(cx88_newstation);
EXPORT_SYMBOL(cx88_set_stereo);
EXPORT_SYMBOL(cx88_get_stereo);
EXPORT_SYMBOL(cx88_audio_thread);

/*
 * Local variables:
 * c-basic-offset: 8
 * End:
991
 * kate: eol "unix"; indent-width 3; remove-trailing-space on; replace-trailing-space-save on; tab-width 8; replace-tabs off; space-indent off; mixed-indent off
L
Linus Torvalds 已提交
992
 */
新手
引导
客服 返回
顶部