blob: 3482e0114d43ec4cba7bbedf643824a26c9bcd20 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002
3 cx88x-audio.c - Conexant CX23880/23881 audio downstream driver driver
4
5 (c) 2001 Michael Eskin, Tom Zakrajsek [Windows version]
6 (c) 2002 Yurij Sysoev <yurij@naturesoft.net>
7 (c) 2003 Gerd Knorr <kraxel@bytesex.org>
8
9 -----------------------------------------------------------------------
10
11 Lot of voodoo here. Even the data sheet doesn't help to
12 understand what is going on here, the documentation for the audio
13 part of the cx2388x chip is *very* bad.
14
15 Some of this comes from party done linux driver sources I got from
16 [undocumented].
17
18 Some comes from the dscaler sources, one of the dscaler driver guy works
19 for Conexant ...
20
21 -----------------------------------------------------------------------
22
23 This program is free software; you can redistribute it and/or modify
24 it under the terms of the GNU General Public License as published by
25 the Free Software Foundation; either version 2 of the License, or
26 (at your option) any later version.
27
28 This program is distributed in the hope that it will be useful,
29 but WITHOUT ANY WARRANTY; without even the implied warranty of
30 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 GNU General Public License for more details.
32
33 You should have received a copy of the GNU General Public License
34 along with this program; if not, write to the Free Software
35 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
36*/
37
38#include <linux/module.h>
39#include <linux/moduleparam.h>
40#include <linux/errno.h>
41#include <linux/kernel.h>
42#include <linux/slab.h>
43#include <linux/mm.h>
44#include <linux/poll.h>
45#include <linux/pci.h>
46#include <linux/signal.h>
47#include <linux/ioport.h>
48#include <linux/sched.h>
49#include <linux/types.h>
50#include <linux/interrupt.h>
51#include <linux/vmalloc.h>
52#include <linux/init.h>
53#include <linux/smp_lock.h>
54#include <linux/delay.h>
55#include <linux/kthread.h>
56
57#include "cx88.h"
58
59static unsigned int audio_debug = 0;
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -080060module_param(audio_debug, int, 0644);
61MODULE_PARM_DESC(audio_debug, "enable debug messages [audio]");
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Panagiotis Christeas7d83e842006-01-15 07:01:54 -020063static unsigned int always_analog = 0;
64module_param(always_analog,int,0644);
65MODULE_PARM_DESC(always_analog,"force analog audio out");
66
67
Linus Torvalds1da177e2005-04-16 15:20:36 -070068#define dprintk(fmt, arg...) if (audio_debug) \
69 printk(KERN_DEBUG "%s/0: " fmt, core->name , ## arg)
70
71/* ----------------------------------------------------------- */
72
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -080073static char *aud_ctl_names[64] = {
74 [EN_BTSC_FORCE_MONO] = "BTSC_FORCE_MONO",
75 [EN_BTSC_FORCE_STEREO] = "BTSC_FORCE_STEREO",
76 [EN_BTSC_FORCE_SAP] = "BTSC_FORCE_SAP",
77 [EN_BTSC_AUTO_STEREO] = "BTSC_AUTO_STEREO",
78 [EN_BTSC_AUTO_SAP] = "BTSC_AUTO_SAP",
79 [EN_A2_FORCE_MONO1] = "A2_FORCE_MONO1",
80 [EN_A2_FORCE_MONO2] = "A2_FORCE_MONO2",
81 [EN_A2_FORCE_STEREO] = "A2_FORCE_STEREO",
82 [EN_A2_AUTO_MONO2] = "A2_AUTO_MONO2",
83 [EN_A2_AUTO_STEREO] = "A2_AUTO_STEREO",
84 [EN_EIAJ_FORCE_MONO1] = "EIAJ_FORCE_MONO1",
85 [EN_EIAJ_FORCE_MONO2] = "EIAJ_FORCE_MONO2",
86 [EN_EIAJ_FORCE_STEREO] = "EIAJ_FORCE_STEREO",
87 [EN_EIAJ_AUTO_MONO2] = "EIAJ_AUTO_MONO2",
88 [EN_EIAJ_AUTO_STEREO] = "EIAJ_AUTO_STEREO",
89 [EN_NICAM_FORCE_MONO1] = "NICAM_FORCE_MONO1",
90 [EN_NICAM_FORCE_MONO2] = "NICAM_FORCE_MONO2",
91 [EN_NICAM_FORCE_STEREO] = "NICAM_FORCE_STEREO",
92 [EN_NICAM_AUTO_MONO2] = "NICAM_AUTO_MONO2",
93 [EN_NICAM_AUTO_STEREO] = "NICAM_AUTO_STEREO",
94 [EN_FMRADIO_FORCE_MONO] = "FMRADIO_FORCE_MONO",
95 [EN_FMRADIO_FORCE_STEREO] = "FMRADIO_FORCE_STEREO",
96 [EN_FMRADIO_AUTO_STEREO] = "FMRADIO_AUTO_STEREO",
Linus Torvalds1da177e2005-04-16 15:20:36 -070097};
98
99struct rlist {
100 u32 reg;
101 u32 val;
102};
103
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800104static void set_audio_registers(struct cx88_core *core, const struct rlist *l)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105{
106 int i;
107
108 for (i = 0; l[i].reg; i++) {
109 switch (l[i].reg) {
110 case AUD_PDF_DDS_CNST_BYTE2:
111 case AUD_PDF_DDS_CNST_BYTE1:
112 case AUD_PDF_DDS_CNST_BYTE0:
113 case AUD_QAM_MODE:
114 case AUD_PHACC_FREQ_8MSB:
115 case AUD_PHACC_FREQ_8LSB:
116 cx_writeb(l[i].reg, l[i].val);
117 break;
118 default:
119 cx_write(l[i].reg, l[i].val);
120 break;
121 }
122 }
123}
124
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800125static void set_audio_start(struct cx88_core *core, u32 mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126{
Ian Pickworth53a73382005-12-01 00:51:28 -0800127 /* mute */
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800128 cx_write(AUD_VOL_CTL, (1 << 6));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
Ian Pickworth53a73382005-12-01 00:51:28 -0800130 /* start programming */
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800131 cx_write(AUD_INIT, mode);
132 cx_write(AUD_INIT_LD, 0x0001);
133 cx_write(AUD_SOFT_RESET, 0x0001);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134}
135
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700136static void set_audio_finish(struct cx88_core *core, u32 ctl)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137{
138 u32 volume;
139
Mauro Carvalho Chehab6f502b82005-12-01 00:51:34 -0800140 /* restart dma; This avoids buzz in NICAM and is good in others */
141 cx88_stop_audio_dma(core);
Ian Pickworth53a73382005-12-01 00:51:28 -0800142 cx_write(AUD_RATE_THRES_DMD, 0x000000C0);
Mauro Carvalho Chehab6f502b82005-12-01 00:51:34 -0800143 cx88_start_audio_dma(core);
Ian Pickworth53a73382005-12-01 00:51:28 -0800144
Michael Krufky48d5e802006-09-25 14:09:10 -0300145 if (cx88_boards[core->board].mpeg & CX88_MPEG_BLACKBIRD) {
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -0700146 cx_write(AUD_I2SINPUTCNTL, 4);
147 cx_write(AUD_BAUDRATE, 1);
Ian Pickworth53a73382005-12-01 00:51:28 -0800148 /* 'pass-thru mode': this enables the i2s output to the mpeg encoder */
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -0700149 cx_set(AUD_CTL, EN_I2SOUT_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 cx_write(AUD_I2SOUTPUTCNTL, 1);
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -0700151 cx_write(AUD_I2SCNTL, 0);
Ian Pickworth53a73382005-12-01 00:51:28 -0800152 /* cx_write(AUD_APB_IN_RATE_ADJ, 0); */
Panagiotis Christeas7d83e842006-01-15 07:01:54 -0200153 }
Michael Krufky48d5e802006-09-25 14:09:10 -0300154 if ((always_analog) || (!(cx88_boards[core->board].mpeg & CX88_MPEG_BLACKBIRD))) {
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800155 ctl |= EN_DAC_ENABLE;
156 cx_write(AUD_CTL, ctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 }
158
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700159 /* finish programming */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 cx_write(AUD_SOFT_RESET, 0x0000);
161
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700162 /* unmute */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 volume = cx_sread(SHADOW_AUD_VOL_CTL);
164 cx_swrite(SHADOW_AUD_VOL_CTL, AUD_VOL_CTL, volume);
165}
166
167/* ----------------------------------------------------------- */
168
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800169static void set_audio_standard_BTSC(struct cx88_core *core, unsigned int sap,
170 u32 mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171{
172 static const struct rlist btsc[] = {
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800173 {AUD_AFE_12DB_EN, 0x00000001},
174 {AUD_OUT1_SEL, 0x00000013},
175 {AUD_OUT1_SHIFT, 0x00000000},
176 {AUD_POLY0_DDS_CONSTANT, 0x0012010c},
177 {AUD_DMD_RA_DDS, 0x00c3e7aa},
178 {AUD_DBX_IN_GAIN, 0x00004734},
179 {AUD_DBX_WBE_GAIN, 0x00004640},
180 {AUD_DBX_SE_GAIN, 0x00008d31},
181 {AUD_DCOC_0_SRC, 0x0000001a},
182 {AUD_IIR1_4_SEL, 0x00000021},
183 {AUD_DCOC_PASS_IN, 0x00000003},
184 {AUD_DCOC_0_SHIFT_IN0, 0x0000000a},
185 {AUD_DCOC_0_SHIFT_IN1, 0x00000008},
186 {AUD_DCOC_1_SHIFT_IN0, 0x0000000a},
187 {AUD_DCOC_1_SHIFT_IN1, 0x00000008},
188 {AUD_DN0_FREQ, 0x0000283b},
189 {AUD_DN2_SRC_SEL, 0x00000008},
190 {AUD_DN2_FREQ, 0x00003000},
191 {AUD_DN2_AFC, 0x00000002},
192 {AUD_DN2_SHFT, 0x00000000},
193 {AUD_IIR2_2_SEL, 0x00000020},
194 {AUD_IIR2_2_SHIFT, 0x00000000},
195 {AUD_IIR2_3_SEL, 0x0000001f},
196 {AUD_IIR2_3_SHIFT, 0x00000000},
197 {AUD_CRDC1_SRC_SEL, 0x000003ce},
198 {AUD_CRDC1_SHIFT, 0x00000000},
199 {AUD_CORDIC_SHIFT_1, 0x00000007},
200 {AUD_DCOC_1_SRC, 0x0000001b},
201 {AUD_DCOC1_SHIFT, 0x00000000},
202 {AUD_RDSI_SEL, 0x00000008},
203 {AUD_RDSQ_SEL, 0x00000008},
204 {AUD_RDSI_SHIFT, 0x00000000},
205 {AUD_RDSQ_SHIFT, 0x00000000},
206 {AUD_POLYPH80SCALEFAC, 0x00000003},
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700207 { /* end of list */ },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 };
209 static const struct rlist btsc_sap[] = {
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800210 {AUD_AFE_12DB_EN, 0x00000001},
211 {AUD_DBX_IN_GAIN, 0x00007200},
212 {AUD_DBX_WBE_GAIN, 0x00006200},
213 {AUD_DBX_SE_GAIN, 0x00006200},
214 {AUD_IIR1_1_SEL, 0x00000000},
215 {AUD_IIR1_3_SEL, 0x00000001},
216 {AUD_DN1_SRC_SEL, 0x00000007},
217 {AUD_IIR1_4_SHIFT, 0x00000006},
218 {AUD_IIR2_1_SHIFT, 0x00000000},
219 {AUD_IIR2_2_SHIFT, 0x00000000},
220 {AUD_IIR3_0_SHIFT, 0x00000000},
221 {AUD_IIR3_1_SHIFT, 0x00000000},
222 {AUD_IIR3_0_SEL, 0x0000000d},
223 {AUD_IIR3_1_SEL, 0x0000000e},
224 {AUD_DEEMPH1_SRC_SEL, 0x00000014},
225 {AUD_DEEMPH1_SHIFT, 0x00000000},
226 {AUD_DEEMPH1_G0, 0x00004000},
227 {AUD_DEEMPH1_A0, 0x00000000},
228 {AUD_DEEMPH1_B0, 0x00000000},
229 {AUD_DEEMPH1_A1, 0x00000000},
230 {AUD_DEEMPH1_B1, 0x00000000},
231 {AUD_OUT0_SEL, 0x0000003f},
232 {AUD_OUT1_SEL, 0x0000003f},
233 {AUD_DN1_AFC, 0x00000002},
234 {AUD_DCOC_0_SHIFT_IN0, 0x0000000a},
235 {AUD_DCOC_0_SHIFT_IN1, 0x00000008},
236 {AUD_DCOC_1_SHIFT_IN0, 0x0000000a},
237 {AUD_DCOC_1_SHIFT_IN1, 0x00000008},
238 {AUD_IIR1_0_SEL, 0x0000001d},
239 {AUD_IIR1_2_SEL, 0x0000001e},
240 {AUD_IIR2_1_SEL, 0x00000002},
241 {AUD_IIR2_2_SEL, 0x00000004},
242 {AUD_IIR3_2_SEL, 0x0000000f},
243 {AUD_DCOC2_SHIFT, 0x00000001},
244 {AUD_IIR3_2_SHIFT, 0x00000001},
245 {AUD_DEEMPH0_SRC_SEL, 0x00000014},
246 {AUD_CORDIC_SHIFT_1, 0x00000006},
247 {AUD_POLY0_DDS_CONSTANT, 0x000e4db2},
248 {AUD_DMD_RA_DDS, 0x00f696e6},
249 {AUD_IIR2_3_SEL, 0x00000025},
250 {AUD_IIR1_4_SEL, 0x00000021},
251 {AUD_DN1_FREQ, 0x0000c965},
252 {AUD_DCOC_PASS_IN, 0x00000003},
253 {AUD_DCOC_0_SRC, 0x0000001a},
254 {AUD_DCOC_1_SRC, 0x0000001b},
255 {AUD_DCOC1_SHIFT, 0x00000000},
256 {AUD_RDSI_SEL, 0x00000009},
257 {AUD_RDSQ_SEL, 0x00000009},
258 {AUD_RDSI_SHIFT, 0x00000000},
259 {AUD_RDSQ_SHIFT, 0x00000000},
260 {AUD_POLYPH80SCALEFAC, 0x00000003},
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700261 { /* end of list */ },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 };
263
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700264 mode |= EN_FMRADIO_EN_RDS;
265
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 if (sap) {
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800267 dprintk("%s SAP (status: unknown)\n", __FUNCTION__);
268 set_audio_start(core, SEL_SAP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 set_audio_registers(core, btsc_sap);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700270 set_audio_finish(core, mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 } else {
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800272 dprintk("%s (status: known-good)\n", __FUNCTION__);
273 set_audio_start(core, SEL_BTSC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 set_audio_registers(core, btsc);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700275 set_audio_finish(core, mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277}
278
Torsten Seebothb1706b92005-11-08 21:36:27 -0800279static void set_audio_standard_NICAM(struct cx88_core *core, u32 mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280{
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700281 static const struct rlist nicam_l[] = {
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800282 {AUD_AFE_12DB_EN, 0x00000001},
283 {AUD_RATE_ADJ1, 0x00000060},
284 {AUD_RATE_ADJ2, 0x000000F9},
285 {AUD_RATE_ADJ3, 0x000001CC},
286 {AUD_RATE_ADJ4, 0x000002B3},
287 {AUD_RATE_ADJ5, 0x00000726},
288 {AUD_DEEMPHDENOM1_R, 0x0000F3D0},
289 {AUD_DEEMPHDENOM2_R, 0x00000000},
290 {AUD_ERRLOGPERIOD_R, 0x00000064},
291 {AUD_ERRINTRPTTHSHLD1_R, 0x00000FFF},
292 {AUD_ERRINTRPTTHSHLD2_R, 0x0000001F},
293 {AUD_ERRINTRPTTHSHLD3_R, 0x0000000F},
294 {AUD_POLYPH80SCALEFAC, 0x00000003},
295 {AUD_DMD_RA_DDS, 0x00C00000},
296 {AUD_PLL_INT, 0x0000001E},
297 {AUD_PLL_DDS, 0x00000000},
298 {AUD_PLL_FRAC, 0x0000E542},
299 {AUD_START_TIMER, 0x00000000},
300 {AUD_DEEMPHNUMER1_R, 0x000353DE},
301 {AUD_DEEMPHNUMER2_R, 0x000001B1},
302 {AUD_PDF_DDS_CNST_BYTE2, 0x06},
303 {AUD_PDF_DDS_CNST_BYTE1, 0x82},
304 {AUD_PDF_DDS_CNST_BYTE0, 0x12},
305 {AUD_QAM_MODE, 0x05},
306 {AUD_PHACC_FREQ_8MSB, 0x34},
307 {AUD_PHACC_FREQ_8LSB, 0x4C},
308 {AUD_DEEMPHGAIN_R, 0x00006680},
309 {AUD_RATE_THRES_DMD, 0x000000C0},
310 { /* end of list */ },
311 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
Torsten Seebothb1706b92005-11-08 21:36:27 -0800313 static const struct rlist nicam_bgdki_common[] = {
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800314 {AUD_AFE_12DB_EN, 0x00000001},
315 {AUD_RATE_ADJ1, 0x00000010},
316 {AUD_RATE_ADJ2, 0x00000040},
317 {AUD_RATE_ADJ3, 0x00000100},
318 {AUD_RATE_ADJ4, 0x00000400},
319 {AUD_RATE_ADJ5, 0x00001000},
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800320 {AUD_ERRLOGPERIOD_R, 0x00000fff},
321 {AUD_ERRINTRPTTHSHLD1_R, 0x000003ff},
322 {AUD_ERRINTRPTTHSHLD2_R, 0x000000ff},
323 {AUD_ERRINTRPTTHSHLD3_R, 0x0000003f},
324 {AUD_POLYPH80SCALEFAC, 0x00000003},
325 {AUD_DEEMPHGAIN_R, 0x000023c2},
326 {AUD_DEEMPHNUMER1_R, 0x0002a7bc},
327 {AUD_DEEMPHNUMER2_R, 0x0003023e},
328 {AUD_DEEMPHDENOM1_R, 0x0000f3d0},
329 {AUD_DEEMPHDENOM2_R, 0x00000000},
Michael Krufkyd0fcdd72005-11-08 21:38:32 -0800330 {AUD_PDF_DDS_CNST_BYTE2, 0x06},
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800331 {AUD_PDF_DDS_CNST_BYTE1, 0x82},
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800332 {AUD_QAM_MODE, 0x05},
333 { /* end of list */ },
Torsten Seebothb1706b92005-11-08 21:36:27 -0800334 };
335
336 static const struct rlist nicam_i[] = {
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800337 {AUD_PDF_DDS_CNST_BYTE0, 0x12},
338 {AUD_PHACC_FREQ_8MSB, 0x3a},
339 {AUD_PHACC_FREQ_8LSB, 0x93},
340 { /* end of list */ },
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700341 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
Torsten Seebothb1706b92005-11-08 21:36:27 -0800343 static const struct rlist nicam_default[] = {
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800344 {AUD_PDF_DDS_CNST_BYTE0, 0x16},
345 {AUD_PHACC_FREQ_8MSB, 0x34},
346 {AUD_PHACC_FREQ_8LSB, 0x4c},
347 { /* end of list */ },
Torsten Seebothb1706b92005-11-08 21:36:27 -0800348 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349
Torsten Seeboth7f7e8462005-11-08 21:38:51 -0800350 set_audio_start(core,SEL_NICAM);
Torsten Seebothb1706b92005-11-08 21:36:27 -0800351 switch (core->tvaudio) {
352 case WW_L:
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800353 dprintk("%s SECAM-L NICAM (status: devel)\n", __FUNCTION__);
Torsten Seebothb1706b92005-11-08 21:36:27 -0800354 set_audio_registers(core, nicam_l);
355 break;
356 case WW_I:
Ian Pickworth53a73382005-12-01 00:51:28 -0800357 dprintk("%s PAL-I NICAM (status: known-good)\n", __FUNCTION__);
Torsten Seebothb1706b92005-11-08 21:36:27 -0800358 set_audio_registers(core, nicam_bgdki_common);
359 set_audio_registers(core, nicam_i);
360 break;
361 default:
Ian Pickworth53a73382005-12-01 00:51:28 -0800362 dprintk("%s PAL-BGDK NICAM (status: known-good)\n", __FUNCTION__);
Torsten Seebothb1706b92005-11-08 21:36:27 -0800363 set_audio_registers(core, nicam_bgdki_common);
364 set_audio_registers(core, nicam_default);
365 break;
366 };
367
368 mode |= EN_DMTRX_LR | EN_DMTRX_BYPASS;
369 set_audio_finish(core, mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370}
371
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700372static void set_audio_standard_A2(struct cx88_core *core, u32 mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373{
Torsten Seebothb1706b92005-11-08 21:36:27 -0800374 static const struct rlist a2_bgdk_common[] = {
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800375 {AUD_ERRLOGPERIOD_R, 0x00000064},
376 {AUD_ERRINTRPTTHSHLD1_R, 0x00000fff},
377 {AUD_ERRINTRPTTHSHLD2_R, 0x0000001f},
378 {AUD_ERRINTRPTTHSHLD3_R, 0x0000000f},
379 {AUD_PDF_DDS_CNST_BYTE2, 0x06},
380 {AUD_PDF_DDS_CNST_BYTE1, 0x82},
381 {AUD_PDF_DDS_CNST_BYTE0, 0x12},
382 {AUD_QAM_MODE, 0x05},
383 {AUD_PHACC_FREQ_8MSB, 0x34},
384 {AUD_PHACC_FREQ_8LSB, 0x4c},
385 {AUD_RATE_ADJ1, 0x00000100},
386 {AUD_RATE_ADJ2, 0x00000200},
387 {AUD_RATE_ADJ3, 0x00000300},
388 {AUD_RATE_ADJ4, 0x00000400},
389 {AUD_RATE_ADJ5, 0x00000500},
390 {AUD_THR_FR, 0x00000000},
391 {AAGC_HYST, 0x0000001a},
392 {AUD_PILOT_BQD_1_K0, 0x0000755b},
393 {AUD_PILOT_BQD_1_K1, 0x00551340},
394 {AUD_PILOT_BQD_1_K2, 0x006d30be},
395 {AUD_PILOT_BQD_1_K3, 0xffd394af},
396 {AUD_PILOT_BQD_1_K4, 0x00400000},
397 {AUD_PILOT_BQD_2_K0, 0x00040000},
398 {AUD_PILOT_BQD_2_K1, 0x002a4841},
399 {AUD_PILOT_BQD_2_K2, 0x00400000},
400 {AUD_PILOT_BQD_2_K3, 0x00000000},
401 {AUD_PILOT_BQD_2_K4, 0x00000000},
402 {AUD_MODE_CHG_TIMER, 0x00000040},
403 {AUD_AFE_12DB_EN, 0x00000001},
404 {AUD_CORDIC_SHIFT_0, 0x00000007},
405 {AUD_CORDIC_SHIFT_1, 0x00000007},
406 {AUD_DEEMPH0_G0, 0x00000380},
407 {AUD_DEEMPH1_G0, 0x00000380},
408 {AUD_DCOC_0_SRC, 0x0000001a},
409 {AUD_DCOC0_SHIFT, 0x00000000},
410 {AUD_DCOC_0_SHIFT_IN0, 0x0000000a},
411 {AUD_DCOC_0_SHIFT_IN1, 0x00000008},
412 {AUD_DCOC_PASS_IN, 0x00000003},
413 {AUD_IIR3_0_SEL, 0x00000021},
414 {AUD_DN2_AFC, 0x00000002},
415 {AUD_DCOC_1_SRC, 0x0000001b},
416 {AUD_DCOC1_SHIFT, 0x00000000},
417 {AUD_DCOC_1_SHIFT_IN0, 0x0000000a},
418 {AUD_DCOC_1_SHIFT_IN1, 0x00000008},
419 {AUD_IIR3_1_SEL, 0x00000023},
420 {AUD_RDSI_SEL, 0x00000017},
421 {AUD_RDSI_SHIFT, 0x00000000},
422 {AUD_RDSQ_SEL, 0x00000017},
423 {AUD_RDSQ_SHIFT, 0x00000000},
424 {AUD_PLL_INT, 0x0000001e},
425 {AUD_PLL_DDS, 0x00000000},
426 {AUD_PLL_FRAC, 0x0000e542},
427 {AUD_POLYPH80SCALEFAC, 0x00000001},
428 {AUD_START_TIMER, 0x00000000},
429 { /* end of list */ },
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700430 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700432 static const struct rlist a2_bg[] = {
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800433 {AUD_DMD_RA_DDS, 0x002a4f2f},
434 {AUD_C1_UP_THR, 0x00007000},
435 {AUD_C1_LO_THR, 0x00005400},
436 {AUD_C2_UP_THR, 0x00005400},
437 {AUD_C2_LO_THR, 0x00003000},
438 { /* end of list */ },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 };
440
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700441 static const struct rlist a2_dk[] = {
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800442 {AUD_DMD_RA_DDS, 0x002a4f2f},
443 {AUD_C1_UP_THR, 0x00007000},
444 {AUD_C1_LO_THR, 0x00005400},
445 {AUD_C2_UP_THR, 0x00005400},
446 {AUD_C2_LO_THR, 0x00003000},
447 {AUD_DN0_FREQ, 0x00003a1c},
448 {AUD_DN2_FREQ, 0x0000d2e0},
449 { /* end of list */ },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 };
Torsten Seebothb1706b92005-11-08 21:36:27 -0800451
452 static const struct rlist a1_i[] = {
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800453 {AUD_ERRLOGPERIOD_R, 0x00000064},
454 {AUD_ERRINTRPTTHSHLD1_R, 0x00000fff},
455 {AUD_ERRINTRPTTHSHLD2_R, 0x0000001f},
456 {AUD_ERRINTRPTTHSHLD3_R, 0x0000000f},
457 {AUD_PDF_DDS_CNST_BYTE2, 0x06},
458 {AUD_PDF_DDS_CNST_BYTE1, 0x82},
459 {AUD_PDF_DDS_CNST_BYTE0, 0x12},
460 {AUD_QAM_MODE, 0x05},
461 {AUD_PHACC_FREQ_8MSB, 0x3a},
462 {AUD_PHACC_FREQ_8LSB, 0x93},
463 {AUD_DMD_RA_DDS, 0x002a4f2f},
464 {AUD_PLL_INT, 0x0000001e},
465 {AUD_PLL_DDS, 0x00000004},
466 {AUD_PLL_FRAC, 0x0000e542},
467 {AUD_RATE_ADJ1, 0x00000100},
468 {AUD_RATE_ADJ2, 0x00000200},
469 {AUD_RATE_ADJ3, 0x00000300},
470 {AUD_RATE_ADJ4, 0x00000400},
471 {AUD_RATE_ADJ5, 0x00000500},
472 {AUD_THR_FR, 0x00000000},
473 {AUD_PILOT_BQD_1_K0, 0x0000755b},
474 {AUD_PILOT_BQD_1_K1, 0x00551340},
475 {AUD_PILOT_BQD_1_K2, 0x006d30be},
476 {AUD_PILOT_BQD_1_K3, 0xffd394af},
477 {AUD_PILOT_BQD_1_K4, 0x00400000},
478 {AUD_PILOT_BQD_2_K0, 0x00040000},
479 {AUD_PILOT_BQD_2_K1, 0x002a4841},
480 {AUD_PILOT_BQD_2_K2, 0x00400000},
481 {AUD_PILOT_BQD_2_K3, 0x00000000},
482 {AUD_PILOT_BQD_2_K4, 0x00000000},
483 {AUD_MODE_CHG_TIMER, 0x00000060},
484 {AUD_AFE_12DB_EN, 0x00000001},
485 {AAGC_HYST, 0x0000000a},
486 {AUD_CORDIC_SHIFT_0, 0x00000007},
487 {AUD_CORDIC_SHIFT_1, 0x00000007},
488 {AUD_C1_UP_THR, 0x00007000},
489 {AUD_C1_LO_THR, 0x00005400},
490 {AUD_C2_UP_THR, 0x00005400},
491 {AUD_C2_LO_THR, 0x00003000},
492 {AUD_DCOC_0_SRC, 0x0000001a},
493 {AUD_DCOC0_SHIFT, 0x00000000},
494 {AUD_DCOC_0_SHIFT_IN0, 0x0000000a},
495 {AUD_DCOC_0_SHIFT_IN1, 0x00000008},
496 {AUD_DCOC_PASS_IN, 0x00000003},
497 {AUD_IIR3_0_SEL, 0x00000021},
498 {AUD_DN2_AFC, 0x00000002},
499 {AUD_DCOC_1_SRC, 0x0000001b},
500 {AUD_DCOC1_SHIFT, 0x00000000},
501 {AUD_DCOC_1_SHIFT_IN0, 0x0000000a},
502 {AUD_DCOC_1_SHIFT_IN1, 0x00000008},
503 {AUD_IIR3_1_SEL, 0x00000023},
504 {AUD_DN0_FREQ, 0x000035a3},
505 {AUD_DN2_FREQ, 0x000029c7},
506 {AUD_CRDC0_SRC_SEL, 0x00000511},
507 {AUD_IIR1_0_SEL, 0x00000001},
508 {AUD_IIR1_1_SEL, 0x00000000},
509 {AUD_IIR3_2_SEL, 0x00000003},
510 {AUD_IIR3_2_SHIFT, 0x00000000},
511 {AUD_IIR3_0_SEL, 0x00000002},
512 {AUD_IIR2_0_SEL, 0x00000021},
513 {AUD_IIR2_0_SHIFT, 0x00000002},
514 {AUD_DEEMPH0_SRC_SEL, 0x0000000b},
515 {AUD_DEEMPH1_SRC_SEL, 0x0000000b},
516 {AUD_POLYPH80SCALEFAC, 0x00000001},
517 {AUD_START_TIMER, 0x00000000},
518 { /* end of list */ },
Torsten Seebothb1706b92005-11-08 21:36:27 -0800519 };
520
521 static const struct rlist am_l[] = {
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800522 {AUD_ERRLOGPERIOD_R, 0x00000064},
523 {AUD_ERRINTRPTTHSHLD1_R, 0x00000FFF},
524 {AUD_ERRINTRPTTHSHLD2_R, 0x0000001F},
525 {AUD_ERRINTRPTTHSHLD3_R, 0x0000000F},
526 {AUD_PDF_DDS_CNST_BYTE2, 0x48},
527 {AUD_PDF_DDS_CNST_BYTE1, 0x3D},
528 {AUD_QAM_MODE, 0x00},
529 {AUD_PDF_DDS_CNST_BYTE0, 0xf5},
530 {AUD_PHACC_FREQ_8MSB, 0x3a},
531 {AUD_PHACC_FREQ_8LSB, 0x4a},
532 {AUD_DEEMPHGAIN_R, 0x00006680},
533 {AUD_DEEMPHNUMER1_R, 0x000353DE},
534 {AUD_DEEMPHNUMER2_R, 0x000001B1},
535 {AUD_DEEMPHDENOM1_R, 0x0000F3D0},
536 {AUD_DEEMPHDENOM2_R, 0x00000000},
537 {AUD_FM_MODE_ENABLE, 0x00000007},
538 {AUD_POLYPH80SCALEFAC, 0x00000003},
539 {AUD_AFE_12DB_EN, 0x00000001},
540 {AAGC_GAIN, 0x00000000},
541 {AAGC_HYST, 0x00000018},
542 {AAGC_DEF, 0x00000020},
543 {AUD_DN0_FREQ, 0x00000000},
544 {AUD_POLY0_DDS_CONSTANT, 0x000E4DB2},
545 {AUD_DCOC_0_SRC, 0x00000021},
546 {AUD_IIR1_0_SEL, 0x00000000},
547 {AUD_IIR1_0_SHIFT, 0x00000007},
548 {AUD_IIR1_1_SEL, 0x00000002},
549 {AUD_IIR1_1_SHIFT, 0x00000000},
550 {AUD_DCOC_1_SRC, 0x00000003},
551 {AUD_DCOC1_SHIFT, 0x00000000},
552 {AUD_DCOC_PASS_IN, 0x00000000},
553 {AUD_IIR1_2_SEL, 0x00000023},
554 {AUD_IIR1_2_SHIFT, 0x00000000},
555 {AUD_IIR1_3_SEL, 0x00000004},
556 {AUD_IIR1_3_SHIFT, 0x00000007},
557 {AUD_IIR1_4_SEL, 0x00000005},
558 {AUD_IIR1_4_SHIFT, 0x00000007},
559 {AUD_IIR3_0_SEL, 0x00000007},
560 {AUD_IIR3_0_SHIFT, 0x00000000},
561 {AUD_DEEMPH0_SRC_SEL, 0x00000011},
562 {AUD_DEEMPH0_SHIFT, 0x00000000},
563 {AUD_DEEMPH0_G0, 0x00007000},
564 {AUD_DEEMPH0_A0, 0x00000000},
565 {AUD_DEEMPH0_B0, 0x00000000},
566 {AUD_DEEMPH0_A1, 0x00000000},
567 {AUD_DEEMPH0_B1, 0x00000000},
568 {AUD_DEEMPH1_SRC_SEL, 0x00000011},
569 {AUD_DEEMPH1_SHIFT, 0x00000000},
570 {AUD_DEEMPH1_G0, 0x00007000},
571 {AUD_DEEMPH1_A0, 0x00000000},
572 {AUD_DEEMPH1_B0, 0x00000000},
573 {AUD_DEEMPH1_A1, 0x00000000},
574 {AUD_DEEMPH1_B1, 0x00000000},
575 {AUD_OUT0_SEL, 0x0000003F},
576 {AUD_OUT1_SEL, 0x0000003F},
577 {AUD_DMD_RA_DDS, 0x00F5C285},
578 {AUD_PLL_INT, 0x0000001E},
579 {AUD_PLL_DDS, 0x00000000},
580 {AUD_PLL_FRAC, 0x0000E542},
581 {AUD_RATE_ADJ1, 0x00000100},
582 {AUD_RATE_ADJ2, 0x00000200},
583 {AUD_RATE_ADJ3, 0x00000300},
584 {AUD_RATE_ADJ4, 0x00000400},
585 {AUD_RATE_ADJ5, 0x00000500},
586 {AUD_RATE_THRES_DMD, 0x000000C0},
587 { /* end of list */ },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 };
589
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700590 static const struct rlist a2_deemph50[] = {
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800591 {AUD_DEEMPH0_G0, 0x00000380},
592 {AUD_DEEMPH1_G0, 0x00000380},
593 {AUD_DEEMPHGAIN_R, 0x000011e1},
594 {AUD_DEEMPHNUMER1_R, 0x0002a7bc},
595 {AUD_DEEMPHNUMER2_R, 0x0003023c},
596 { /* end of list */ },
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700597 };
598
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700599 set_audio_start(core, SEL_A2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 switch (core->tvaudio) {
Torsten Seebothb1706b92005-11-08 21:36:27 -0800601 case WW_BG:
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800602 dprintk("%s PAL-BG A1/2 (status: known-good)\n", __FUNCTION__);
Torsten Seebothb1706b92005-11-08 21:36:27 -0800603 set_audio_registers(core, a2_bgdk_common);
604 set_audio_registers(core, a2_bg);
605 set_audio_registers(core, a2_deemph50);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 break;
Torsten Seebothb1706b92005-11-08 21:36:27 -0800607 case WW_DK:
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800608 dprintk("%s PAL-DK A1/2 (status: known-good)\n", __FUNCTION__);
Torsten Seebothb1706b92005-11-08 21:36:27 -0800609 set_audio_registers(core, a2_bgdk_common);
610 set_audio_registers(core, a2_dk);
611 set_audio_registers(core, a2_deemph50);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 break;
Torsten Seebothb1706b92005-11-08 21:36:27 -0800613 case WW_I:
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800614 dprintk("%s PAL-I A1 (status: known-good)\n", __FUNCTION__);
Torsten Seebothb1706b92005-11-08 21:36:27 -0800615 set_audio_registers(core, a1_i);
616 set_audio_registers(core, a2_deemph50);
617 break;
618 case WW_L:
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800619 dprintk("%s AM-L (status: devel)\n", __FUNCTION__);
Torsten Seebothb1706b92005-11-08 21:36:27 -0800620 set_audio_registers(core, am_l);
621 break;
622 default:
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800623 dprintk("%s Warning: wrong value\n", __FUNCTION__);
Torsten Seebothb1706b92005-11-08 21:36:27 -0800624 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 break;
626 };
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700627
628 mode |= EN_FMRADIO_EN_RDS | EN_DMTRX_SUMDIFF;
629 set_audio_finish(core, mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630}
631
632static void set_audio_standard_EIAJ(struct cx88_core *core)
633{
634 static const struct rlist eiaj[] = {
635 /* TODO: eiaj register settings are not there yet ... */
636
637 { /* end of list */ },
638 };
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800639 dprintk("%s (status: unknown)\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700641 set_audio_start(core, SEL_EIAJ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 set_audio_registers(core, eiaj);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700643 set_audio_finish(core, EN_EIAJ_AUTO_STEREO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644}
645
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800646static void set_audio_standard_FM(struct cx88_core *core,
647 enum cx88_deemph_type deemph)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648{
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -0700649 static const struct rlist fm_deemph_50[] = {
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800650 {AUD_DEEMPH0_G0, 0x0C45},
651 {AUD_DEEMPH0_A0, 0x6262},
652 {AUD_DEEMPH0_B0, 0x1C29},
653 {AUD_DEEMPH0_A1, 0x3FC66},
654 {AUD_DEEMPH0_B1, 0x399A},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800656 {AUD_DEEMPH1_G0, 0x0D80},
657 {AUD_DEEMPH1_A0, 0x6262},
658 {AUD_DEEMPH1_B0, 0x1C29},
659 {AUD_DEEMPH1_A1, 0x3FC66},
660 {AUD_DEEMPH1_B1, 0x399A},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800662 {AUD_POLYPH80SCALEFAC, 0x0003},
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -0700663 { /* end of list */ },
664 };
665 static const struct rlist fm_deemph_75[] = {
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800666 {AUD_DEEMPH0_G0, 0x091B},
667 {AUD_DEEMPH0_A0, 0x6B68},
668 {AUD_DEEMPH0_B0, 0x11EC},
669 {AUD_DEEMPH0_A1, 0x3FC66},
670 {AUD_DEEMPH0_B1, 0x399A},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800672 {AUD_DEEMPH1_G0, 0x0AA0},
673 {AUD_DEEMPH1_A0, 0x6B68},
674 {AUD_DEEMPH1_B0, 0x11EC},
675 {AUD_DEEMPH1_A1, 0x3FC66},
676 {AUD_DEEMPH1_B1, 0x399A},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800678 {AUD_POLYPH80SCALEFAC, 0x0003},
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -0700679 { /* end of list */ },
680 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -0700682 /* It is enough to leave default values? */
683 static const struct rlist fm_no_deemph[] = {
684
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800685 {AUD_POLYPH80SCALEFAC, 0x0003},
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -0700686 { /* end of list */ },
687 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800689 dprintk("%s (status: unknown)\n", __FUNCTION__);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700690 set_audio_start(core, SEL_FMRADIO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800692 switch (deemph) {
693 case FM_NO_DEEMPH:
694 set_audio_registers(core, fm_no_deemph);
695 break;
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -0700696
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800697 case FM_DEEMPH_50:
698 set_audio_registers(core, fm_deemph_50);
699 break;
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -0700700
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800701 case FM_DEEMPH_75:
702 set_audio_registers(core, fm_deemph_75);
703 break;
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -0700704 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700706 set_audio_finish(core, EN_FMRADIO_AUTO_STEREO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707}
708
709/* ----------------------------------------------------------- */
710
Adrian Bunkdff47bf2006-06-24 19:25:43 -0300711static int cx88_detect_nicam(struct cx88_core *core)
Torsten Seebothb1706b92005-11-08 21:36:27 -0800712{
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800713 int i, j = 0;
Torsten Seebothb1706b92005-11-08 21:36:27 -0800714
715 dprintk("start nicam autodetect.\n");
716
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800717 for (i = 0; i < 6; i++) {
718 /* if bit1=1 then nicam is detected */
719 j += ((cx_read(AUD_NICAM_STATUS2) & 0x02) >> 1);
Torsten Seebothb1706b92005-11-08 21:36:27 -0800720
Ian Pickworth53a73382005-12-01 00:51:28 -0800721 if (j == 1) {
Torsten Seebothb1706b92005-11-08 21:36:27 -0800722 dprintk("nicam is detected.\n");
723 return 1;
724 }
725
726 /* wait a little bit for next reading status */
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800727 msleep(10);
Torsten Seebothb1706b92005-11-08 21:36:27 -0800728 }
729
730 dprintk("nicam is not detected.\n");
731 return 0;
732}
733
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734void cx88_set_tvaudio(struct cx88_core *core)
735{
736 switch (core->tvaudio) {
737 case WW_BTSC:
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700738 set_audio_standard_BTSC(core, 0, EN_BTSC_AUTO_STEREO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 break;
Torsten Seebothb1706b92005-11-08 21:36:27 -0800740 case WW_BG:
741 case WW_DK:
742 case WW_I:
743 case WW_L:
744 /* prepare all dsp registers */
745 set_audio_standard_A2(core, EN_A2_FORCE_MONO1);
746
747 /* set nicam mode - otherwise
748 AUD_NICAM_STATUS2 contains wrong values */
Torsten Seeboth7f7e8462005-11-08 21:38:51 -0800749 set_audio_standard_NICAM(core, EN_NICAM_AUTO_STEREO);
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800750 if (0 == cx88_detect_nicam(core)) {
Torsten Seebothb1706b92005-11-08 21:36:27 -0800751 /* fall back to fm / am mono */
752 set_audio_standard_A2(core, EN_A2_FORCE_MONO1);
753 core->use_nicam = 0;
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800754 } else {
Torsten Seebothb1706b92005-11-08 21:36:27 -0800755 core->use_nicam = 1;
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800756 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 break;
758 case WW_EIAJ:
759 set_audio_standard_EIAJ(core);
760 break;
761 case WW_FM:
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800762 set_audio_standard_FM(core, FM_NO_DEEMPH);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 case WW_NONE:
765 default:
766 printk("%s/0: unknown tv audio mode [%d]\n",
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800767 core->name, core->tvaudio);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 break;
769 }
770 return;
771}
772
773void cx88_newstation(struct cx88_core *core)
774{
775 core->audiomode_manual = UNSET;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776}
777
778void cx88_get_stereo(struct cx88_core *core, struct v4l2_tuner *t)
779{
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800780 static char *m[] = { "stereo", "dual mono", "mono", "sap" };
781 static char *p[] = { "no pilot", "pilot c1", "pilot c2", "?" };
782 u32 reg, mode, pilot;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800784 reg = cx_read(AUD_STATUS);
785 mode = reg & 0x03;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 pilot = (reg >> 2) & 0x03;
787
788 if (core->astat != reg)
789 dprintk("AUD_STATUS: 0x%x [%s/%s] ctl=%s\n",
790 reg, m[mode], p[pilot],
791 aud_ctl_names[cx_read(AUD_CTL) & 63]);
792 core->astat = reg;
793
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700794/* TODO
795 Reading from AUD_STATUS is not enough
796 for auto-detecting sap/dual-fm/nicam.
797 Add some code here later.
798*/
799
800# if 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 t->capability = V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_SAP |
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800802 V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 t->rxsubchans = V4L2_TUNER_SUB_MONO;
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800804 t->audmode = V4L2_TUNER_MODE_MONO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805
806 switch (core->tvaudio) {
807 case WW_BTSC:
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800808 t->capability = V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_SAP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 t->rxsubchans = V4L2_TUNER_SUB_STEREO;
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700810 if (1 == pilot) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 /* SAP */
812 t->rxsubchans |= V4L2_TUNER_SUB_SAP;
813 }
814 break;
815 case WW_A2_BG:
816 case WW_A2_DK:
817 case WW_A2_M:
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700818 if (1 == pilot) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 /* stereo */
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800820 t->rxsubchans =
821 V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 if (0 == mode)
823 t->audmode = V4L2_TUNER_MODE_STEREO;
824 }
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700825 if (2 == pilot) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 /* dual language -- FIXME */
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800827 t->rxsubchans =
828 V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 t->audmode = V4L2_TUNER_MODE_LANG1;
830 }
831 break;
832 case WW_NICAM_BGDKL:
833 if (0 == mode) {
834 t->audmode = V4L2_TUNER_MODE_STEREO;
835 t->rxsubchans |= V4L2_TUNER_SUB_STEREO;
836 }
837 break;
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700838 case WW_SYSTEM_L_AM:
839 if (0x0 == mode && !(cx_read(AUD_INIT) & 0x04)) {
840 t->audmode = V4L2_TUNER_MODE_STEREO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 t->rxsubchans |= V4L2_TUNER_SUB_STEREO;
842 }
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800843 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 default:
845 /* nothing */
846 break;
847 }
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700848# endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 return;
850}
851
852void cx88_set_stereo(struct cx88_core *core, u32 mode, int manual)
853{
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800854 u32 ctl = UNSET;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 u32 mask = UNSET;
856
857 if (manual) {
858 core->audiomode_manual = mode;
859 } else {
860 if (UNSET != core->audiomode_manual)
861 return;
862 }
863 core->audiomode_current = mode;
864
865 switch (core->tvaudio) {
866 case WW_BTSC:
867 switch (mode) {
868 case V4L2_TUNER_MODE_MONO:
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700869 set_audio_standard_BTSC(core, 0, EN_BTSC_FORCE_MONO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 break;
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700871 case V4L2_TUNER_MODE_LANG1:
872 set_audio_standard_BTSC(core, 0, EN_BTSC_AUTO_STEREO);
873 break;
874 case V4L2_TUNER_MODE_LANG2:
875 set_audio_standard_BTSC(core, 1, EN_BTSC_FORCE_SAP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 break;
877 case V4L2_TUNER_MODE_STEREO:
Hans Verkuil301e22d2006-03-18 17:15:00 -0300878 case V4L2_TUNER_MODE_LANG1_LANG2:
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700879 set_audio_standard_BTSC(core, 0, EN_BTSC_FORCE_STEREO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 break;
881 }
882 break;
Torsten Seebothb1706b92005-11-08 21:36:27 -0800883 case WW_BG:
884 case WW_DK:
885 case WW_I:
886 case WW_L:
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800887 if (1 == core->use_nicam) {
Torsten Seebothb1706b92005-11-08 21:36:27 -0800888 switch (mode) {
889 case V4L2_TUNER_MODE_MONO:
890 case V4L2_TUNER_MODE_LANG1:
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800891 set_audio_standard_NICAM(core,
892 EN_NICAM_FORCE_MONO1);
Torsten Seebothb1706b92005-11-08 21:36:27 -0800893 break;
894 case V4L2_TUNER_MODE_LANG2:
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800895 set_audio_standard_NICAM(core,
896 EN_NICAM_FORCE_MONO2);
Torsten Seebothb1706b92005-11-08 21:36:27 -0800897 break;
898 case V4L2_TUNER_MODE_STEREO:
Hans Verkuil301e22d2006-03-18 17:15:00 -0300899 case V4L2_TUNER_MODE_LANG1_LANG2:
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800900 set_audio_standard_NICAM(core,
901 EN_NICAM_FORCE_STEREO);
Torsten Seebothb1706b92005-11-08 21:36:27 -0800902 break;
903 }
904 } else {
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800905 if ((core->tvaudio == WW_I) || (core->tvaudio == WW_L)) {
Torsten Seebothb1706b92005-11-08 21:36:27 -0800906 /* fall back to fm / am mono */
907 set_audio_standard_A2(core, EN_A2_FORCE_MONO1);
908 } else {
909 /* TODO: Add A2 autodection */
910 switch (mode) {
911 case V4L2_TUNER_MODE_MONO:
912 case V4L2_TUNER_MODE_LANG1:
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800913 set_audio_standard_A2(core,
914 EN_A2_FORCE_MONO1);
Torsten Seebothb1706b92005-11-08 21:36:27 -0800915 break;
916 case V4L2_TUNER_MODE_LANG2:
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800917 set_audio_standard_A2(core,
918 EN_A2_FORCE_MONO2);
Torsten Seebothb1706b92005-11-08 21:36:27 -0800919 break;
920 case V4L2_TUNER_MODE_STEREO:
Hans Verkuil301e22d2006-03-18 17:15:00 -0300921 case V4L2_TUNER_MODE_LANG1_LANG2:
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800922 set_audio_standard_A2(core,
923 EN_A2_FORCE_STEREO);
Torsten Seebothb1706b92005-11-08 21:36:27 -0800924 break;
925 }
926 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 }
928 break;
929 case WW_FM:
930 switch (mode) {
931 case V4L2_TUNER_MODE_MONO:
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800932 ctl = EN_FMRADIO_FORCE_MONO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 mask = 0x3f;
934 break;
935 case V4L2_TUNER_MODE_STEREO:
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800936 ctl = EN_FMRADIO_AUTO_STEREO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 mask = 0x3f;
938 break;
939 }
940 break;
941 }
942
943 if (UNSET != ctl) {
944 dprintk("cx88_set_stereo: mask 0x%x, ctl 0x%x "
945 "[status=0x%x,ctl=0x%x,vol=0x%x]\n",
946 mask, ctl, cx_read(AUD_STATUS),
947 cx_read(AUD_CTL), cx_sread(SHADOW_AUD_VOL_CTL));
948 cx_andor(AUD_CTL, mask, ctl);
949 }
950 return;
951}
952
953int cx88_audio_thread(void *data)
954{
955 struct cx88_core *core = data;
956 struct v4l2_tuner t;
957 u32 mode = 0;
958
959 dprintk("cx88: tvaudio thread started\n");
960 for (;;) {
961 msleep_interruptible(1000);
962 if (kthread_should_stop())
963 break;
964
965 /* just monitor the audio status for now ... */
Nickolay V. Shmyrev7b3c6d62005-11-08 21:36:59 -0800966 memset(&t, 0, sizeof(t));
967 cx88_get_stereo(core, &t);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968
969 if (UNSET != core->audiomode_manual)
970 /* manually set, don't do anything. */
971 continue;
972
973 /* monitor signal */
974 if (t.rxsubchans & V4L2_TUNER_SUB_STEREO)
975 mode = V4L2_TUNER_MODE_STEREO;
976 else
977 mode = V4L2_TUNER_MODE_MONO;
978 if (mode == core->audiomode_current)
979 continue;
980
981 /* automatically switch to best available mode */
982 cx88_set_stereo(core, mode, 0);
983 }
984
985 dprintk("cx88: tvaudio thread exiting\n");
986 return 0;
987}
988
989/* ----------------------------------------------------------- */
990
991EXPORT_SYMBOL(cx88_set_tvaudio);
992EXPORT_SYMBOL(cx88_newstation);
993EXPORT_SYMBOL(cx88_set_stereo);
994EXPORT_SYMBOL(cx88_get_stereo);
995EXPORT_SYMBOL(cx88_audio_thread);
996
997/*
998 * Local variables:
999 * c-basic-offset: 8
1000 * End:
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -07001001 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002 */