blob: a65b3cc4bf03ff00bd2cf991ccc88abc632adc88 [file] [log] [blame]
Hans Verkuilbd985162005-11-13 16:07:56 -08001/* cx25840 - Conexant CX25840 audio/video decoder driver
2 *
3 * Copyright (C) 2004 Ulf Eklund
4 *
5 * Based on the saa7115 driver and on the first verison of Chris Kennedy's
6 * cx25840 driver.
7 *
8 * Changes by Tyler Trafford <tatrafford@comcast.net>
9 * - cleanup/rewrite for V4L2 API (2005)
10 *
11 * VBI support by Hans Verkuil <hverkuil@xs4all.nl>.
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 */
27
28
29#include <linux/kernel.h>
30#include <linux/module.h>
31#include <linux/slab.h>
32#include <linux/videodev2.h>
33#include <linux/i2c.h>
Hans Verkuilbd985162005-11-13 16:07:56 -080034#include <media/v4l2-common.h>
35
36#include "cx25840.h"
37
38MODULE_DESCRIPTION("Conexant CX25840 audio/video decoder driver");
Hans Verkuil1f4b3362005-11-13 16:08:05 -080039MODULE_AUTHOR("Ulf Eklund, Chris Kennedy, Hans Verkuil, Tyler Trafford");
Hans Verkuilbd985162005-11-13 16:07:56 -080040MODULE_LICENSE("GPL");
41
42static unsigned short normal_i2c[] = { 0x88 >> 1, I2C_CLIENT_END };
43
44
Adrian Bunka9cff902006-01-15 06:56:15 -020045static int cx25840_debug;
Hans Verkuilbd985162005-11-13 16:07:56 -080046
Hans Verkuilb5fc7142006-01-11 22:41:36 -020047module_param_named(debug,cx25840_debug, int, 0644);
Hans Verkuilbd985162005-11-13 16:07:56 -080048
Hans Verkuilfac9e892006-01-09 15:32:40 -020049MODULE_PARM_DESC(debug, "Debugging messages [0=Off (default) 1=On]");
Hans Verkuilbd985162005-11-13 16:07:56 -080050
51I2C_CLIENT_INSMOD;
52
53/* ----------------------------------------------------------------------- */
54
55int cx25840_write(struct i2c_client *client, u16 addr, u8 value)
56{
57 u8 buffer[3];
58 buffer[0] = addr >> 8;
59 buffer[1] = addr & 0xff;
60 buffer[2] = value;
61 return i2c_master_send(client, buffer, 3);
62}
63
64int cx25840_write4(struct i2c_client *client, u16 addr, u32 value)
65{
66 u8 buffer[6];
67 buffer[0] = addr >> 8;
68 buffer[1] = addr & 0xff;
69 buffer[2] = value >> 24;
70 buffer[3] = (value >> 16) & 0xff;
71 buffer[4] = (value >> 8) & 0xff;
72 buffer[5] = value & 0xff;
73 return i2c_master_send(client, buffer, 6);
74}
75
76u8 cx25840_read(struct i2c_client * client, u16 addr)
77{
78 u8 buffer[2];
79 buffer[0] = addr >> 8;
80 buffer[1] = addr & 0xff;
81
82 if (i2c_master_send(client, buffer, 2) < 2)
83 return 0;
84
85 if (i2c_master_recv(client, buffer, 1) < 1)
86 return 0;
87
88 return buffer[0];
89}
90
91u32 cx25840_read4(struct i2c_client * client, u16 addr)
92{
93 u8 buffer[4];
94 buffer[0] = addr >> 8;
95 buffer[1] = addr & 0xff;
96
97 if (i2c_master_send(client, buffer, 2) < 2)
98 return 0;
99
100 if (i2c_master_recv(client, buffer, 4) < 4)
101 return 0;
102
103 return (buffer[0] << 24) | (buffer[1] << 16) |
104 (buffer[2] << 8) | buffer[3];
105}
106
107int cx25840_and_or(struct i2c_client *client, u16 addr, u8 and_mask,
108 u8 or_value)
109{
110 return cx25840_write(client, addr,
111 (cx25840_read(client, addr) & and_mask) |
112 or_value);
113}
114
115/* ----------------------------------------------------------------------- */
116
Hans Verkuila8bbf122006-01-09 15:25:42 -0200117static int set_input(struct i2c_client *client, enum cx25840_video_input vid_input,
118 enum cx25840_audio_input aud_input);
Hans Verkuilbd985162005-11-13 16:07:56 -0800119static void log_status(struct i2c_client *client);
120
121/* ----------------------------------------------------------------------- */
122
Hans Verkuild92c20e2006-01-09 15:32:41 -0200123static void init_dll1(struct i2c_client *client)
Hans Verkuilbd985162005-11-13 16:07:56 -0800124{
125 /* This is the Hauppauge sequence used to
126 * initialize the Delay Lock Loop 1 (ADC DLL). */
127 cx25840_write(client, 0x159, 0x23);
128 cx25840_write(client, 0x15a, 0x87);
129 cx25840_write(client, 0x15b, 0x06);
130 cx25840_write(client, 0x159, 0xe1);
131 cx25840_write(client, 0x15a, 0x86);
132 cx25840_write(client, 0x159, 0xe0);
133 cx25840_write(client, 0x159, 0xe1);
134 cx25840_write(client, 0x15b, 0x10);
135}
136
Hans Verkuild92c20e2006-01-09 15:32:41 -0200137static void init_dll2(struct i2c_client *client)
Hans Verkuilbd985162005-11-13 16:07:56 -0800138{
139 /* This is the Hauppauge sequence used to
140 * initialize the Delay Lock Loop 2 (ADC DLL). */
141 cx25840_write(client, 0x15d, 0xe3);
142 cx25840_write(client, 0x15e, 0x86);
143 cx25840_write(client, 0x15f, 0x06);
144 cx25840_write(client, 0x15d, 0xe1);
145 cx25840_write(client, 0x15d, 0xe0);
146 cx25840_write(client, 0x15d, 0xe1);
147}
148
149static void cx25840_initialize(struct i2c_client *client, int loadfw)
150{
151 struct cx25840_state *state = i2c_get_clientdata(client);
152
153 /* datasheet startup in numbered steps, refer to page 3-77 */
154 /* 2. */
155 cx25840_and_or(client, 0x803, ~0x10, 0x00);
156 /* The default of this register should be 4, but I get 0 instead.
157 * Set this register to 4 manually. */
158 cx25840_write(client, 0x000, 0x04);
159 /* 3. */
160 init_dll1(client);
161 init_dll2(client);
162 cx25840_write(client, 0x136, 0x0a);
163 /* 4. */
164 cx25840_write(client, 0x13c, 0x01);
165 cx25840_write(client, 0x13c, 0x00);
166 /* 5. */
167 if (loadfw)
168 cx25840_loadfw(client);
169 /* 6. */
170 cx25840_write(client, 0x115, 0x8c);
171 cx25840_write(client, 0x116, 0x07);
172 cx25840_write(client, 0x118, 0x02);
173 /* 7. */
174 cx25840_write(client, 0x4a5, 0x80);
175 cx25840_write(client, 0x4a5, 0x00);
176 cx25840_write(client, 0x402, 0x00);
177 /* 8. */
Hans Verkuil73dcddc2006-03-16 20:23:47 -0300178 cx25840_and_or(client, 0x401, ~0x18, 0);
179 cx25840_and_or(client, 0x4a2, ~0x10, 0x10);
180 /* steps 8c and 8d are done in change_input() */
Hans Verkuilbd985162005-11-13 16:07:56 -0800181 /* 10. */
182 cx25840_write(client, 0x8d3, 0x1f);
183 cx25840_write(client, 0x8e3, 0x03);
184
185 cx25840_vbi_setup(client);
186
187 /* trial and error says these are needed to get audio */
188 cx25840_write(client, 0x914, 0xa0);
189 cx25840_write(client, 0x918, 0xa0);
190 cx25840_write(client, 0x919, 0x01);
191
192 /* stereo prefered */
193 cx25840_write(client, 0x809, 0x04);
194 /* AC97 shift */
195 cx25840_write(client, 0x8cf, 0x0f);
196
Hans Verkuila8bbf122006-01-09 15:25:42 -0200197 /* (re)set input */
198 set_input(client, state->vid_input, state->aud_input);
Hans Verkuilbd985162005-11-13 16:07:56 -0800199
200 /* start microcontroller */
201 cx25840_and_or(client, 0x803, ~0x10, 0x10);
202}
203
204/* ----------------------------------------------------------------------- */
205
206static void input_change(struct i2c_client *client)
207{
Hans Verkuilf95006f2005-12-01 00:51:42 -0800208 struct cx25840_state *state = i2c_get_clientdata(client);
Hans Verkuilbd985162005-11-13 16:07:56 -0800209 v4l2_std_id std = cx25840_get_v4lstd(client);
210
Hans Verkuil73dcddc2006-03-16 20:23:47 -0300211 /* Follow step 8c and 8d of section 3.16 in the cx25840 datasheet */
212 if (std & V4L2_STD_SECAM) {
213 cx25840_write(client, 0x402, 0);
214 }
215 else {
216 cx25840_write(client, 0x402, 0x04);
217 cx25840_write(client, 0x49f, (std & V4L2_STD_NTSC) ? 0x14 : 0x11);
218 }
219 cx25840_and_or(client, 0x401, ~0x60, 0);
220 cx25840_and_or(client, 0x401, ~0x60, 0x60);
221
Hans Verkuilf95006f2005-12-01 00:51:42 -0800222 /* Note: perhaps V4L2_STD_PAL_M should be handled as V4L2_STD_NTSC
223 instead of V4L2_STD_PAL. Someone needs to test this. */
Hans Verkuilbd985162005-11-13 16:07:56 -0800224 if (std & V4L2_STD_PAL) {
225 /* Follow tuner change procedure for PAL */
226 cx25840_write(client, 0x808, 0xff);
227 cx25840_write(client, 0x80b, 0x10);
228 } else if (std & V4L2_STD_SECAM) {
229 /* Select autodetect for SECAM */
230 cx25840_write(client, 0x808, 0xff);
231 cx25840_write(client, 0x80b, 0x10);
232 } else if (std & V4L2_STD_NTSC) {
Hans Verkuild97a11e2006-02-07 06:48:40 -0200233 /* Certain Hauppauge PVR150 models have a hardware bug
234 that causes audio to drop out. For these models the
235 audio standard must be set explicitly.
236 To be precise: it affects cards with tuner models
237 85, 99 and 112 (model numbers from tveeprom). */
238 int hw_fix = state->pvr150_workaround;
239
240 if (std == V4L2_STD_NTSC_M_JP) {
Hans Verkuilf95006f2005-12-01 00:51:42 -0800241 /* Japan uses EIAJ audio standard */
Hans Verkuild97a11e2006-02-07 06:48:40 -0200242 cx25840_write(client, 0x808, hw_fix ? 0x2f : 0xf7);
243 } else if (std == V4L2_STD_NTSC_M_KR) {
244 /* South Korea uses A2 audio standard */
245 cx25840_write(client, 0x808, hw_fix ? 0x3f : 0xf8);
Hans Verkuilf95006f2005-12-01 00:51:42 -0800246 } else {
247 /* Others use the BTSC audio standard */
Hans Verkuild97a11e2006-02-07 06:48:40 -0200248 cx25840_write(client, 0x808, hw_fix ? 0x1f : 0xf6);
Hans Verkuilf95006f2005-12-01 00:51:42 -0800249 }
Hans Verkuilbd985162005-11-13 16:07:56 -0800250 cx25840_write(client, 0x80b, 0x00);
251 }
252
253 if (cx25840_read(client, 0x803) & 0x10) {
254 /* restart audio decoder microcontroller */
255 cx25840_and_or(client, 0x803, ~0x10, 0x00);
256 cx25840_and_or(client, 0x803, ~0x10, 0x10);
257 }
258}
259
Hans Verkuila8bbf122006-01-09 15:25:42 -0200260static int set_input(struct i2c_client *client, enum cx25840_video_input vid_input,
261 enum cx25840_audio_input aud_input)
Hans Verkuilbd985162005-11-13 16:07:56 -0800262{
263 struct cx25840_state *state = i2c_get_clientdata(client);
Hans Verkuila8bbf122006-01-09 15:25:42 -0200264 u8 is_composite = (vid_input >= CX25840_COMPOSITE1 &&
265 vid_input <= CX25840_COMPOSITE8);
266 u8 reg;
Hans Verkuilbd985162005-11-13 16:07:56 -0800267
Hans Verkuilb5fc7142006-01-11 22:41:36 -0200268 v4l_dbg(1, cx25840_debug, client, "decoder set video input %d, audio input %d\n",
Hans Verkuila8bbf122006-01-09 15:25:42 -0200269 vid_input, aud_input);
Hans Verkuilbd985162005-11-13 16:07:56 -0800270
Hans Verkuila8bbf122006-01-09 15:25:42 -0200271 if (is_composite) {
272 reg = 0xf0 + (vid_input - CX25840_COMPOSITE1);
273 } else {
274 int luma = vid_input & 0xf0;
275 int chroma = vid_input & 0xf00;
Hans Verkuilbd985162005-11-13 16:07:56 -0800276
Hans Verkuila8bbf122006-01-09 15:25:42 -0200277 if ((vid_input & ~0xff0) ||
278 luma < CX25840_SVIDEO_LUMA1 || luma > CX25840_SVIDEO_LUMA4 ||
279 chroma < CX25840_SVIDEO_CHROMA4 || chroma > CX25840_SVIDEO_CHROMA8) {
Hans Verkuilfac9e892006-01-09 15:32:40 -0200280 v4l_err(client, "0x%04x is not a valid video input!\n", vid_input);
Hans Verkuila8bbf122006-01-09 15:25:42 -0200281 return -EINVAL;
Hans Verkuilbd985162005-11-13 16:07:56 -0800282 }
Hans Verkuila8bbf122006-01-09 15:25:42 -0200283 reg = 0xf0 + ((luma - CX25840_SVIDEO_LUMA1) >> 4);
284 if (chroma >= CX25840_SVIDEO_CHROMA7) {
285 reg &= 0x3f;
286 reg |= (chroma - CX25840_SVIDEO_CHROMA7) >> 2;
Hans Verkuilbd985162005-11-13 16:07:56 -0800287 } else {
Hans Verkuila8bbf122006-01-09 15:25:42 -0200288 reg &= 0xcf;
289 reg |= (chroma - CX25840_SVIDEO_CHROMA4) >> 4;
Hans Verkuilbd985162005-11-13 16:07:56 -0800290 }
Hans Verkuila8bbf122006-01-09 15:25:42 -0200291 }
Hans Verkuilbd985162005-11-13 16:07:56 -0800292
Hans Verkuila8bbf122006-01-09 15:25:42 -0200293 switch (aud_input) {
294 case CX25840_AUDIO_SERIAL:
295 /* do nothing, use serial audio input */
Hans Verkuilbd985162005-11-13 16:07:56 -0800296 break;
Hans Verkuila8bbf122006-01-09 15:25:42 -0200297 case CX25840_AUDIO4: reg &= ~0x30; break;
298 case CX25840_AUDIO5: reg &= ~0x30; reg |= 0x10; break;
299 case CX25840_AUDIO6: reg &= ~0x30; reg |= 0x20; break;
300 case CX25840_AUDIO7: reg &= ~0xc0; break;
301 case CX25840_AUDIO8: reg &= ~0xc0; reg |= 0x40; break;
Hans Verkuilbd985162005-11-13 16:07:56 -0800302
303 default:
Hans Verkuilfac9e892006-01-09 15:32:40 -0200304 v4l_err(client, "0x%04x is not a valid audio input!\n", aud_input);
Hans Verkuilbd985162005-11-13 16:07:56 -0800305 return -EINVAL;
306 }
307
Hans Verkuila8bbf122006-01-09 15:25:42 -0200308 cx25840_write(client, 0x103, reg);
309 /* Set INPUT_MODE to Composite (0) or S-Video (1) */
310 cx25840_and_or(client, 0x401, ~0x6, is_composite ? 0 : 0x02);
311 /* Set CH_SEL_ADC2 to 1 if input comes from CH3 */
312 cx25840_and_or(client, 0x102, ~0x2, (reg & 0x80) == 0 ? 2 : 0);
313 /* Set DUAL_MODE_ADC2 to 1 if input comes from both CH2 and CH3 */
314 if ((reg & 0xc0) != 0xc0 && (reg & 0x30) != 0x30)
315 cx25840_and_or(client, 0x102, ~0x4, 4);
316 else
317 cx25840_and_or(client, 0x102, ~0x4, 0);
318
319 state->vid_input = vid_input;
320 state->aud_input = aud_input;
321 cx25840_audio_set_path(client);
Hans Verkuilbd985162005-11-13 16:07:56 -0800322 input_change(client);
323 return 0;
324}
325
326/* ----------------------------------------------------------------------- */
327
328static int set_v4lstd(struct i2c_client *client, v4l2_std_id std)
329{
Mauro Carvalho Chehab468a0a52005-12-19 08:54:11 -0200330 u8 fmt=0; /* zero is autodetect */
Hans Verkuilbd985162005-11-13 16:07:56 -0800331
Mauro Carvalho Chehab468a0a52005-12-19 08:54:11 -0200332 /* First tests should be against specific std */
Hans Verkuild97a11e2006-02-07 06:48:40 -0200333 if (std == V4L2_STD_NTSC_M_JP) {
Mauro Carvalho Chehab468a0a52005-12-19 08:54:11 -0200334 fmt=0x2;
Hans Verkuild97a11e2006-02-07 06:48:40 -0200335 } else if (std == V4L2_STD_NTSC_443) {
Mauro Carvalho Chehab468a0a52005-12-19 08:54:11 -0200336 fmt=0x3;
Hans Verkuild97a11e2006-02-07 06:48:40 -0200337 } else if (std == V4L2_STD_PAL_M) {
Mauro Carvalho Chehab468a0a52005-12-19 08:54:11 -0200338 fmt=0x5;
Hans Verkuild97a11e2006-02-07 06:48:40 -0200339 } else if (std == V4L2_STD_PAL_N) {
Mauro Carvalho Chehab468a0a52005-12-19 08:54:11 -0200340 fmt=0x6;
Hans Verkuild97a11e2006-02-07 06:48:40 -0200341 } else if (std == V4L2_STD_PAL_Nc) {
Mauro Carvalho Chehab468a0a52005-12-19 08:54:11 -0200342 fmt=0x7;
Hans Verkuild97a11e2006-02-07 06:48:40 -0200343 } else if (std == V4L2_STD_PAL_60) {
Mauro Carvalho Chehab468a0a52005-12-19 08:54:11 -0200344 fmt=0x8;
345 } else {
346 /* Then, test against generic ones */
347 if (std & V4L2_STD_NTSC) {
348 fmt=0x1;
349 } else if (std & V4L2_STD_PAL) {
350 fmt=0x4;
351 } else if (std & V4L2_STD_SECAM) {
352 fmt=0xc;
353 }
Hans Verkuilbd985162005-11-13 16:07:56 -0800354 }
355
Hans Verkuil73dcddc2006-03-16 20:23:47 -0300356 /* Follow step 9 of section 3.16 in the cx25840 datasheet.
357 Without this PAL may display a vertical ghosting effect.
358 This happens for example with the Yuan MPC622. */
359 if (fmt >= 4 && fmt < 8) {
360 /* Set format to NTSC-M */
361 cx25840_and_or(client, 0x400, ~0xf, 1);
362 /* Turn off LCOMB */
363 cx25840_and_or(client, 0x47b, ~6, 0);
364 }
Hans Verkuilbd985162005-11-13 16:07:56 -0800365 cx25840_and_or(client, 0x400, ~0xf, fmt);
366 cx25840_vbi_setup(client);
367 return 0;
368}
369
370v4l2_std_id cx25840_get_v4lstd(struct i2c_client * client)
371{
372 /* check VID_FMT_SEL first */
373 u8 fmt = cx25840_read(client, 0x400) & 0xf;
374
375 if (!fmt) {
376 /* check AFD_FMT_STAT if set to autodetect */
377 fmt = cx25840_read(client, 0x40d) & 0xf;
378 }
379
380 switch (fmt) {
Hans Verkuil73dcddc2006-03-16 20:23:47 -0300381 case 0x1:
382 {
383 /* if the audio std is A2-M, then this is the South Korean
384 NTSC standard */
385 if (cx25840_read(client, 0x805) == 2)
386 return V4L2_STD_NTSC_M_KR;
387 return V4L2_STD_NTSC_M;
388 }
Hans Verkuilbd985162005-11-13 16:07:56 -0800389 case 0x2: return V4L2_STD_NTSC_M_JP;
390 case 0x3: return V4L2_STD_NTSC_443;
391 case 0x4: return V4L2_STD_PAL;
392 case 0x5: return V4L2_STD_PAL_M;
393 case 0x6: return V4L2_STD_PAL_N;
394 case 0x7: return V4L2_STD_PAL_Nc;
395 case 0x8: return V4L2_STD_PAL_60;
396 case 0xc: return V4L2_STD_SECAM;
397 default: return V4L2_STD_UNKNOWN;
398 }
399}
400
401/* ----------------------------------------------------------------------- */
402
403static int set_v4lctrl(struct i2c_client *client, struct v4l2_control *ctrl)
404{
405 struct cx25840_state *state = i2c_get_clientdata(client);
406
407 switch (ctrl->id) {
Hans Verkuila8bbf122006-01-09 15:25:42 -0200408 case CX25840_CID_ENABLE_PVR150_WORKAROUND:
409 state->pvr150_workaround = ctrl->value;
410 set_input(client, state->vid_input, state->aud_input);
Hans Verkuilbd985162005-11-13 16:07:56 -0800411 break;
412
413 case V4L2_CID_BRIGHTNESS:
414 if (ctrl->value < 0 || ctrl->value > 255) {
Hans Verkuilfac9e892006-01-09 15:32:40 -0200415 v4l_err(client, "invalid brightness setting %d\n",
Hans Verkuilbd985162005-11-13 16:07:56 -0800416 ctrl->value);
417 return -ERANGE;
418 }
419
420 cx25840_write(client, 0x414, ctrl->value - 128);
421 break;
422
423 case V4L2_CID_CONTRAST:
424 if (ctrl->value < 0 || ctrl->value > 127) {
Hans Verkuilfac9e892006-01-09 15:32:40 -0200425 v4l_err(client, "invalid contrast setting %d\n",
Hans Verkuilbd985162005-11-13 16:07:56 -0800426 ctrl->value);
427 return -ERANGE;
428 }
429
430 cx25840_write(client, 0x415, ctrl->value << 1);
431 break;
432
433 case V4L2_CID_SATURATION:
434 if (ctrl->value < 0 || ctrl->value > 127) {
Hans Verkuilfac9e892006-01-09 15:32:40 -0200435 v4l_err(client, "invalid saturation setting %d\n",
Hans Verkuilbd985162005-11-13 16:07:56 -0800436 ctrl->value);
437 return -ERANGE;
438 }
439
440 cx25840_write(client, 0x420, ctrl->value << 1);
441 cx25840_write(client, 0x421, ctrl->value << 1);
442 break;
443
444 case V4L2_CID_HUE:
445 if (ctrl->value < -127 || ctrl->value > 127) {
Hans Verkuilfac9e892006-01-09 15:32:40 -0200446 v4l_err(client, "invalid hue setting %d\n", ctrl->value);
Hans Verkuilbd985162005-11-13 16:07:56 -0800447 return -ERANGE;
448 }
449
450 cx25840_write(client, 0x422, ctrl->value);
451 break;
452
453 case V4L2_CID_AUDIO_VOLUME:
454 case V4L2_CID_AUDIO_BASS:
455 case V4L2_CID_AUDIO_TREBLE:
456 case V4L2_CID_AUDIO_BALANCE:
457 case V4L2_CID_AUDIO_MUTE:
458 return cx25840_audio(client, VIDIOC_S_CTRL, ctrl);
Hans Verkuil3faeeae2006-01-09 15:25:44 -0200459
460 default:
461 return -EINVAL;
Hans Verkuilbd985162005-11-13 16:07:56 -0800462 }
463
464 return 0;
465}
466
467static int get_v4lctrl(struct i2c_client *client, struct v4l2_control *ctrl)
468{
469 struct cx25840_state *state = i2c_get_clientdata(client);
470
471 switch (ctrl->id) {
Hans Verkuila8bbf122006-01-09 15:25:42 -0200472 case CX25840_CID_ENABLE_PVR150_WORKAROUND:
473 ctrl->value = state->pvr150_workaround;
Hans Verkuilbd985162005-11-13 16:07:56 -0800474 break;
475 case V4L2_CID_BRIGHTNESS:
Hans Verkuil0de71222006-01-09 15:32:44 -0200476 ctrl->value = (s8)cx25840_read(client, 0x414) + 128;
Hans Verkuilbd985162005-11-13 16:07:56 -0800477 break;
478 case V4L2_CID_CONTRAST:
479 ctrl->value = cx25840_read(client, 0x415) >> 1;
480 break;
481 case V4L2_CID_SATURATION:
482 ctrl->value = cx25840_read(client, 0x420) >> 1;
483 break;
484 case V4L2_CID_HUE:
Hans Verkuilc5099a62006-01-09 15:32:43 -0200485 ctrl->value = (s8)cx25840_read(client, 0x422);
Hans Verkuilbd985162005-11-13 16:07:56 -0800486 break;
487 case V4L2_CID_AUDIO_VOLUME:
488 case V4L2_CID_AUDIO_BASS:
489 case V4L2_CID_AUDIO_TREBLE:
490 case V4L2_CID_AUDIO_BALANCE:
491 case V4L2_CID_AUDIO_MUTE:
492 return cx25840_audio(client, VIDIOC_G_CTRL, ctrl);
493 default:
494 return -EINVAL;
495 }
496
497 return 0;
498}
499
500/* ----------------------------------------------------------------------- */
501
502static int get_v4lfmt(struct i2c_client *client, struct v4l2_format *fmt)
503{
504 switch (fmt->type) {
505 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
506 return cx25840_vbi(client, VIDIOC_G_FMT, fmt);
507 default:
508 return -EINVAL;
509 }
510
511 return 0;
512}
513
514static int set_v4lfmt(struct i2c_client *client, struct v4l2_format *fmt)
515{
516 struct v4l2_pix_format *pix;
517 int HSC, VSC, Vsrc, Hsrc, filter, Vlines;
518 int is_pal = !(cx25840_get_v4lstd(client) & V4L2_STD_NTSC);
519
520 switch (fmt->type) {
521 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
522 pix = &(fmt->fmt.pix);
523
524 Vsrc = (cx25840_read(client, 0x476) & 0x3f) << 4;
525 Vsrc |= (cx25840_read(client, 0x475) & 0xf0) >> 4;
526
527 Hsrc = (cx25840_read(client, 0x472) & 0x3f) << 4;
528 Hsrc |= (cx25840_read(client, 0x471) & 0xf0) >> 4;
529
530 Vlines = pix->height + (is_pal ? 4 : 7);
531
532 if ((pix->width * 16 < Hsrc) || (Hsrc < pix->width) ||
533 (Vlines * 8 < Vsrc) || (Vsrc < Vlines)) {
Hans Verkuilfac9e892006-01-09 15:32:40 -0200534 v4l_err(client, "%dx%d is not a valid size!\n",
Hans Verkuilbd985162005-11-13 16:07:56 -0800535 pix->width, pix->height);
536 return -ERANGE;
537 }
538
539 HSC = (Hsrc * (1 << 20)) / pix->width - (1 << 20);
540 VSC = (1 << 16) - (Vsrc * (1 << 9) / Vlines - (1 << 9));
541 VSC &= 0x1fff;
542
543 if (pix->width >= 385)
544 filter = 0;
545 else if (pix->width > 192)
546 filter = 1;
547 else if (pix->width > 96)
548 filter = 2;
549 else
550 filter = 3;
551
Hans Verkuilb5fc7142006-01-11 22:41:36 -0200552 v4l_dbg(1, cx25840_debug, client, "decoder set size %dx%d -> scale %ux%u\n",
Hans Verkuilbd985162005-11-13 16:07:56 -0800553 pix->width, pix->height, HSC, VSC);
554
555 /* HSCALE=HSC */
556 cx25840_write(client, 0x418, HSC & 0xff);
557 cx25840_write(client, 0x419, (HSC >> 8) & 0xff);
558 cx25840_write(client, 0x41a, HSC >> 16);
559 /* VSCALE=VSC */
560 cx25840_write(client, 0x41c, VSC & 0xff);
561 cx25840_write(client, 0x41d, VSC >> 8);
562 /* VS_INTRLACE=1 VFILT=filter */
563 cx25840_write(client, 0x41e, 0x8 | filter);
564 break;
565
566 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
567 return cx25840_vbi(client, VIDIOC_S_FMT, fmt);
568
569 case V4L2_BUF_TYPE_VBI_CAPTURE:
570 return cx25840_vbi(client, VIDIOC_S_FMT, fmt);
571
572 default:
573 return -EINVAL;
574 }
575
576 return 0;
577}
578
579/* ----------------------------------------------------------------------- */
580
Hans Verkuild92c20e2006-01-09 15:32:41 -0200581static struct v4l2_queryctrl cx25840_qctrl[] = {
582 {
583 .id = V4L2_CID_BRIGHTNESS,
584 .type = V4L2_CTRL_TYPE_INTEGER,
585 .name = "Brightness",
586 .minimum = 0,
587 .maximum = 255,
588 .step = 1,
589 .default_value = 128,
590 .flags = 0,
591 }, {
592 .id = V4L2_CID_CONTRAST,
593 .type = V4L2_CTRL_TYPE_INTEGER,
594 .name = "Contrast",
595 .minimum = 0,
Hans Verkuilecc0b942006-02-27 00:08:20 -0300596 .maximum = 127,
Hans Verkuild92c20e2006-01-09 15:32:41 -0200597 .step = 1,
598 .default_value = 64,
599 .flags = 0,
600 }, {
601 .id = V4L2_CID_SATURATION,
602 .type = V4L2_CTRL_TYPE_INTEGER,
603 .name = "Saturation",
604 .minimum = 0,
Hans Verkuilecc0b942006-02-27 00:08:20 -0300605 .maximum = 127,
Hans Verkuild92c20e2006-01-09 15:32:41 -0200606 .step = 1,
607 .default_value = 64,
608 .flags = 0,
609 }, {
610 .id = V4L2_CID_HUE,
611 .type = V4L2_CTRL_TYPE_INTEGER,
612 .name = "Hue",
613 .minimum = -128,
614 .maximum = 127,
615 .step = 1,
616 .default_value = 0,
617 .flags = 0,
618 }, {
619 .id = V4L2_CID_AUDIO_VOLUME,
620 .type = V4L2_CTRL_TYPE_INTEGER,
621 .name = "Volume",
622 .minimum = 0,
623 .maximum = 65535,
624 .step = 65535/100,
625 .default_value = 58880,
626 .flags = 0,
627 }, {
628 .id = V4L2_CID_AUDIO_BALANCE,
629 .type = V4L2_CTRL_TYPE_INTEGER,
630 .name = "Balance",
631 .minimum = 0,
632 .maximum = 65535,
633 .step = 65535/100,
634 .default_value = 32768,
635 .flags = 0,
636 }, {
637 .id = V4L2_CID_AUDIO_MUTE,
638 .type = V4L2_CTRL_TYPE_BOOLEAN,
639 .name = "Mute",
640 .minimum = 0,
641 .maximum = 1,
642 .step = 1,
643 .default_value = 1,
644 .flags = 0,
645 }, {
646 .id = V4L2_CID_AUDIO_BASS,
647 .type = V4L2_CTRL_TYPE_INTEGER,
648 .name = "Bass",
649 .minimum = 0,
650 .maximum = 65535,
651 .step = 65535/100,
652 .default_value = 32768,
653 }, {
654 .id = V4L2_CID_AUDIO_TREBLE,
655 .type = V4L2_CTRL_TYPE_INTEGER,
656 .name = "Treble",
657 .minimum = 0,
658 .maximum = 65535,
659 .step = 65535/100,
660 .default_value = 32768,
661 },
662};
663
664/* ----------------------------------------------------------------------- */
665
Hans Verkuilbd985162005-11-13 16:07:56 -0800666static int cx25840_command(struct i2c_client *client, unsigned int cmd,
667 void *arg)
668{
669 struct cx25840_state *state = i2c_get_clientdata(client);
670 struct v4l2_tuner *vt = arg;
Hans Verkuilbd985162005-11-13 16:07:56 -0800671
672 switch (cmd) {
Hans Verkuilbd985162005-11-13 16:07:56 -0800673#ifdef CONFIG_VIDEO_ADV_DEBUG
674 /* ioctls to allow direct access to the
675 * cx25840 registers for testing */
676 case VIDIOC_INT_G_REGISTER:
677 {
678 struct v4l2_register *reg = arg;
679
680 if (reg->i2c_id != I2C_DRIVERID_CX25840)
681 return -EINVAL;
682 reg->val = cx25840_read(client, reg->reg & 0x0fff);
683 break;
684 }
685
686 case VIDIOC_INT_S_REGISTER:
687 {
688 struct v4l2_register *reg = arg;
689
690 if (reg->i2c_id != I2C_DRIVERID_CX25840)
691 return -EINVAL;
692 if (!capable(CAP_SYS_ADMIN))
693 return -EPERM;
694 cx25840_write(client, reg->reg & 0x0fff, reg->val & 0xff);
695 break;
696 }
697#endif
698
699 case VIDIOC_INT_DECODE_VBI_LINE:
700 return cx25840_vbi(client, cmd, arg);
701
702 case VIDIOC_INT_AUDIO_CLOCK_FREQ:
Hans Verkuil3faeeae2006-01-09 15:25:44 -0200703 return cx25840_audio(client, cmd, arg);
Hans Verkuilbd985162005-11-13 16:07:56 -0800704
705 case VIDIOC_STREAMON:
Hans Verkuilb5fc7142006-01-11 22:41:36 -0200706 v4l_dbg(1, cx25840_debug, client, "enable output\n");
Hans Verkuilbd985162005-11-13 16:07:56 -0800707 cx25840_write(client, 0x115, 0x8c);
708 cx25840_write(client, 0x116, 0x07);
709 break;
710
711 case VIDIOC_STREAMOFF:
Hans Verkuilb5fc7142006-01-11 22:41:36 -0200712 v4l_dbg(1, cx25840_debug, client, "disable output\n");
Hans Verkuilbd985162005-11-13 16:07:56 -0800713 cx25840_write(client, 0x115, 0x00);
714 cx25840_write(client, 0x116, 0x00);
715 break;
716
717 case VIDIOC_LOG_STATUS:
718 log_status(client);
719 break;
720
721 case VIDIOC_G_CTRL:
Hans Verkuil3faeeae2006-01-09 15:25:44 -0200722 return get_v4lctrl(client, (struct v4l2_control *)arg);
Hans Verkuilbd985162005-11-13 16:07:56 -0800723
724 case VIDIOC_S_CTRL:
Hans Verkuil3faeeae2006-01-09 15:25:44 -0200725 return set_v4lctrl(client, (struct v4l2_control *)arg);
Hans Verkuilbd985162005-11-13 16:07:56 -0800726
Hans Verkuild92c20e2006-01-09 15:32:41 -0200727 case VIDIOC_QUERYCTRL:
728 {
729 struct v4l2_queryctrl *qc = arg;
730 int i;
731
732 for (i = 0; i < ARRAY_SIZE(cx25840_qctrl); i++)
733 if (qc->id && qc->id == cx25840_qctrl[i].id) {
734 memcpy(qc, &cx25840_qctrl[i], sizeof(*qc));
735 return 0;
736 }
737 return -EINVAL;
738 }
739
Hans Verkuilbd985162005-11-13 16:07:56 -0800740 case VIDIOC_G_STD:
741 *(v4l2_std_id *)arg = cx25840_get_v4lstd(client);
742 break;
743
744 case VIDIOC_S_STD:
Hans Verkuil3faeeae2006-01-09 15:25:44 -0200745 state->radio = 0;
746 return set_v4lstd(client, *(v4l2_std_id *)arg);
747
748 case AUDC_SET_RADIO:
749 state->radio = 1;
Hans Verkuilbd985162005-11-13 16:07:56 -0800750 break;
751
752 case VIDIOC_G_INPUT:
Hans Verkuila8bbf122006-01-09 15:25:42 -0200753 *(int *)arg = state->vid_input;
Hans Verkuilbd985162005-11-13 16:07:56 -0800754 break;
755
756 case VIDIOC_S_INPUT:
Hans Verkuil3faeeae2006-01-09 15:25:44 -0200757 return set_input(client, *(enum cx25840_video_input *)arg, state->aud_input);
Hans Verkuilbd985162005-11-13 16:07:56 -0800758
Hans Verkuila8bbf122006-01-09 15:25:42 -0200759 case VIDIOC_S_AUDIO:
760 {
761 struct v4l2_audio *input = arg;
762
Hans Verkuil3faeeae2006-01-09 15:25:44 -0200763 return set_input(client, state->vid_input, input->index);
Hans Verkuila8bbf122006-01-09 15:25:42 -0200764 }
765
Hans Verkuilbd985162005-11-13 16:07:56 -0800766 case VIDIOC_S_FREQUENCY:
767 input_change(client);
768 break;
769
770 case VIDIOC_G_TUNER:
771 {
772 u8 mode = cx25840_read(client, 0x804);
Hans Verkuilbd985162005-11-13 16:07:56 -0800773 u8 vpres = cx25840_read(client, 0x80a) & 0x10;
774 int val = 0;
775
Hans Verkuil3faeeae2006-01-09 15:25:44 -0200776 if (state->radio)
777 break;
778
Hans Verkuilbd985162005-11-13 16:07:56 -0800779 vt->capability |=
780 V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_LANG1 |
781 V4L2_TUNER_CAP_LANG2 | V4L2_TUNER_CAP_SAP;
782
783 vt->signal = vpres ? 0xffff : 0x0;
784
785 /* get rxsubchans and audmode */
786 if ((mode & 0xf) == 1)
787 val |= V4L2_TUNER_SUB_STEREO;
788 else
789 val |= V4L2_TUNER_SUB_MONO;
790
791 if (mode == 2 || mode == 4)
Hans Verkuil8a4b2752006-01-23 17:11:09 -0200792 val = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
Hans Verkuilbd985162005-11-13 16:07:56 -0800793
794 if (mode & 0x10)
795 val |= V4L2_TUNER_SUB_SAP;
796
797 vt->rxsubchans = val;
Hans Verkuil8a4b2752006-01-23 17:11:09 -0200798 vt->audmode = state->audmode;
Hans Verkuilbd985162005-11-13 16:07:56 -0800799 break;
800 }
801
802 case VIDIOC_S_TUNER:
Hans Verkuil8a4b2752006-01-23 17:11:09 -0200803 if (state->radio)
804 break;
805
Hans Verkuilbd985162005-11-13 16:07:56 -0800806 switch (vt->audmode) {
807 case V4L2_TUNER_MODE_MONO:
Hans Verkuil8a4b2752006-01-23 17:11:09 -0200808 /* mono -> mono
809 stereo -> mono
810 bilingual -> lang1 */
Hans Verkuilbd985162005-11-13 16:07:56 -0800811 cx25840_and_or(client, 0x809, ~0xf, 0x00);
812 break;
Hans Verkuil301e22d2006-03-18 17:15:00 -0300813 case V4L2_TUNER_MODE_STEREO:
Hans Verkuil8a4b2752006-01-23 17:11:09 -0200814 case V4L2_TUNER_MODE_LANG1:
815 /* mono -> mono
816 stereo -> stereo
817 bilingual -> lang1 */
Hans Verkuilbd985162005-11-13 16:07:56 -0800818 cx25840_and_or(client, 0x809, ~0xf, 0x04);
819 break;
Hans Verkuil301e22d2006-03-18 17:15:00 -0300820 case V4L2_TUNER_MODE_LANG1_LANG2:
Hans Verkuil8a4b2752006-01-23 17:11:09 -0200821 /* mono -> mono
822 stereo -> stereo
823 bilingual -> lang1/lang2 */
824 cx25840_and_or(client, 0x809, ~0xf, 0x07);
825 break;
Hans Verkuilbd985162005-11-13 16:07:56 -0800826 case V4L2_TUNER_MODE_LANG2:
Hans Verkuil8a4b2752006-01-23 17:11:09 -0200827 /* mono -> mono
Hans Verkuil301e22d2006-03-18 17:15:00 -0300828 stereo -> stereo
Hans Verkuil8a4b2752006-01-23 17:11:09 -0200829 bilingual -> lang2 */
Hans Verkuilbd985162005-11-13 16:07:56 -0800830 cx25840_and_or(client, 0x809, ~0xf, 0x01);
831 break;
Hans Verkuil8a4b2752006-01-23 17:11:09 -0200832 default:
833 return -EINVAL;
Hans Verkuilbd985162005-11-13 16:07:56 -0800834 }
Hans Verkuil8a4b2752006-01-23 17:11:09 -0200835 state->audmode = vt->audmode;
Hans Verkuilbd985162005-11-13 16:07:56 -0800836 break;
837
838 case VIDIOC_G_FMT:
Hans Verkuil3faeeae2006-01-09 15:25:44 -0200839 return get_v4lfmt(client, (struct v4l2_format *)arg);
Hans Verkuilbd985162005-11-13 16:07:56 -0800840
841 case VIDIOC_S_FMT:
Hans Verkuil3faeeae2006-01-09 15:25:44 -0200842 return set_v4lfmt(client, (struct v4l2_format *)arg);
Hans Verkuilbd985162005-11-13 16:07:56 -0800843
844 case VIDIOC_INT_RESET:
845 cx25840_initialize(client, 0);
846 break;
847
848 case VIDIOC_INT_G_CHIP_IDENT:
849 *(enum v4l2_chip_ident *)arg =
850 V4L2_IDENT_CX25840 + ((cx25840_read(client, 0x100) >> 4) & 0xf);
851 break;
852
853 default:
Hans Verkuilbd985162005-11-13 16:07:56 -0800854 return -EINVAL;
855 }
856
Hans Verkuil3faeeae2006-01-09 15:25:44 -0200857 return 0;
Hans Verkuilbd985162005-11-13 16:07:56 -0800858}
859
860/* ----------------------------------------------------------------------- */
861
Mauro Carvalho Chehab769e2432005-12-01 00:51:35 -0800862static struct i2c_driver i2c_driver_cx25840;
Hans Verkuilbd985162005-11-13 16:07:56 -0800863
864static int cx25840_detect_client(struct i2c_adapter *adapter, int address,
865 int kind)
866{
867 struct i2c_client *client;
868 struct cx25840_state *state;
869 u16 device_id;
870
871 /* Check if the adapter supports the needed features
872 * Not until kernel version 2.6.11 did the bit-algo
873 * correctly report that it would do an I2C-level xfer */
874 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C))
875 return 0;
876
Panagiotis Issaris74081872006-01-11 19:40:56 -0200877 client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
Hans Verkuilbd985162005-11-13 16:07:56 -0800878 if (client == 0)
879 return -ENOMEM;
880
Hans Verkuilbd985162005-11-13 16:07:56 -0800881 client->addr = address;
882 client->adapter = adapter;
883 client->driver = &i2c_driver_cx25840;
Hans Verkuilbd985162005-11-13 16:07:56 -0800884 snprintf(client->name, sizeof(client->name) - 1, "cx25840");
885
Hans Verkuilb5fc7142006-01-11 22:41:36 -0200886 v4l_dbg(1, cx25840_debug, client, "detecting cx25840 client on address 0x%x\n", address << 1);
Hans Verkuilbd985162005-11-13 16:07:56 -0800887
888 device_id = cx25840_read(client, 0x101) << 8;
889 device_id |= cx25840_read(client, 0x100);
890
891 /* The high byte of the device ID should be
892 * 0x84 if chip is present */
893 if ((device_id & 0xff00) != 0x8400) {
Hans Verkuilb5fc7142006-01-11 22:41:36 -0200894 v4l_dbg(1, cx25840_debug, client, "cx25840 not found\n");
Hans Verkuilbd985162005-11-13 16:07:56 -0800895 kfree(client);
896 return 0;
897 }
898
Hans Verkuilfac9e892006-01-09 15:32:40 -0200899 v4l_info(client, "cx25%3x-2%x found @ 0x%x (%s)\n",
Hans Verkuilbd985162005-11-13 16:07:56 -0800900 (device_id & 0xfff0) >> 4,
901 (device_id & 0x0f) < 3 ? (device_id & 0x0f) + 1 : 3,
902 address << 1, adapter->name);
903
904 state = kmalloc(sizeof(struct cx25840_state), GFP_KERNEL);
905 if (state == NULL) {
906 kfree(client);
907 return -ENOMEM;
908 }
909
910 i2c_set_clientdata(client, state);
911 memset(state, 0, sizeof(struct cx25840_state));
Hans Verkuila8bbf122006-01-09 15:25:42 -0200912 state->vid_input = CX25840_COMPOSITE7;
913 state->aud_input = CX25840_AUDIO8;
Hans Verkuil3578d3d2006-01-09 15:25:41 -0200914 state->audclk_freq = 48000;
Hans Verkuila8bbf122006-01-09 15:25:42 -0200915 state->pvr150_workaround = 0;
Hans Verkuil8a4b2752006-01-23 17:11:09 -0200916 state->audmode = V4L2_TUNER_MODE_LANG1;
Hans Verkuilbd985162005-11-13 16:07:56 -0800917
918 cx25840_initialize(client, 1);
919
920 i2c_attach_client(client);
921
922 return 0;
923}
924
925static int cx25840_attach_adapter(struct i2c_adapter *adapter)
926{
Hans Verkuilbd985162005-11-13 16:07:56 -0800927 if (adapter->class & I2C_CLASS_TV_ANALOG)
Hans Verkuilbd985162005-11-13 16:07:56 -0800928 return i2c_probe(adapter, &addr_data, &cx25840_detect_client);
929 return 0;
930}
931
932static int cx25840_detach_client(struct i2c_client *client)
933{
934 struct cx25840_state *state = i2c_get_clientdata(client);
935 int err;
936
937 err = i2c_detach_client(client);
938 if (err) {
939 return err;
940 }
941
942 kfree(state);
943 kfree(client);
944
945 return 0;
946}
947
948/* ----------------------------------------------------------------------- */
949
Mauro Carvalho Chehab769e2432005-12-01 00:51:35 -0800950static struct i2c_driver i2c_driver_cx25840 = {
Laurent Riffard604f28e2005-11-26 20:43:39 +0100951 .driver = {
Laurent Riffard604f28e2005-11-26 20:43:39 +0100952 .name = "cx25840",
953 },
Hans Verkuilbd985162005-11-13 16:07:56 -0800954 .id = I2C_DRIVERID_CX25840,
Hans Verkuilbd985162005-11-13 16:07:56 -0800955 .attach_adapter = cx25840_attach_adapter,
956 .detach_client = cx25840_detach_client,
957 .command = cx25840_command,
Hans Verkuilbd985162005-11-13 16:07:56 -0800958};
959
960
961static int __init m__init(void)
962{
963 return i2c_add_driver(&i2c_driver_cx25840);
964}
965
966static void __exit m__exit(void)
967{
968 i2c_del_driver(&i2c_driver_cx25840);
969}
970
971module_init(m__init);
972module_exit(m__exit);
973
974/* ----------------------------------------------------------------------- */
975
976static void log_status(struct i2c_client *client)
977{
978 static const char *const fmt_strs[] = {
979 "0x0",
980 "NTSC-M", "NTSC-J", "NTSC-4.43",
981 "PAL-BDGHI", "PAL-M", "PAL-N", "PAL-Nc", "PAL-60",
982 "0x9", "0xA", "0xB",
983 "SECAM",
984 "0xD", "0xE", "0xF"
985 };
986
987 struct cx25840_state *state = i2c_get_clientdata(client);
988 u8 microctrl_vidfmt = cx25840_read(client, 0x80a);
989 u8 vidfmt_sel = cx25840_read(client, 0x400) & 0xf;
990 u8 gen_stat1 = cx25840_read(client, 0x40d);
991 u8 download_ctl = cx25840_read(client, 0x803);
992 u8 mod_det_stat0 = cx25840_read(client, 0x804);
993 u8 mod_det_stat1 = cx25840_read(client, 0x805);
994 u8 audio_config = cx25840_read(client, 0x808);
995 u8 pref_mode = cx25840_read(client, 0x809);
996 u8 afc0 = cx25840_read(client, 0x80b);
997 u8 mute_ctl = cx25840_read(client, 0x8d3);
Hans Verkuila8bbf122006-01-09 15:25:42 -0200998 int vid_input = state->vid_input;
999 int aud_input = state->aud_input;
Hans Verkuilbd985162005-11-13 16:07:56 -08001000 char *p;
1001
Hans Verkuilfac9e892006-01-09 15:32:40 -02001002 v4l_info(client, "Video signal: %spresent\n",
Hans Verkuilbd985162005-11-13 16:07:56 -08001003 (microctrl_vidfmt & 0x10) ? "" : "not ");
Hans Verkuilfac9e892006-01-09 15:32:40 -02001004 v4l_info(client, "Detected format: %s\n",
Hans Verkuilbd985162005-11-13 16:07:56 -08001005 fmt_strs[gen_stat1 & 0xf]);
1006
1007 switch (mod_det_stat0) {
1008 case 0x00: p = "mono"; break;
1009 case 0x01: p = "stereo"; break;
1010 case 0x02: p = "dual"; break;
1011 case 0x04: p = "tri"; break;
1012 case 0x10: p = "mono with SAP"; break;
1013 case 0x11: p = "stereo with SAP"; break;
1014 case 0x12: p = "dual with SAP"; break;
1015 case 0x14: p = "tri with SAP"; break;
1016 case 0xfe: p = "forced mode"; break;
1017 default: p = "not defined";
1018 }
Hans Verkuilfac9e892006-01-09 15:32:40 -02001019 v4l_info(client, "Detected audio mode: %s\n", p);
Hans Verkuilbd985162005-11-13 16:07:56 -08001020
1021 switch (mod_det_stat1) {
1022 case 0x00: p = "not defined"; break;
1023 case 0x01: p = "EIAJ"; break;
1024 case 0x02: p = "A2-M"; break;
1025 case 0x03: p = "A2-BG"; break;
1026 case 0x04: p = "A2-DK1"; break;
1027 case 0x05: p = "A2-DK2"; break;
1028 case 0x06: p = "A2-DK3"; break;
1029 case 0x07: p = "A1 (6.0 MHz FM Mono)"; break;
1030 case 0x08: p = "AM-L"; break;
1031 case 0x09: p = "NICAM-BG"; break;
1032 case 0x0a: p = "NICAM-DK"; break;
1033 case 0x0b: p = "NICAM-I"; break;
1034 case 0x0c: p = "NICAM-L"; break;
1035 case 0x0d: p = "BTSC/EIAJ/A2-M Mono (4.5 MHz FMMono)"; break;
1036 case 0x0e: p = "IF FM Radio"; break;
1037 case 0x0f: p = "BTSC"; break;
1038 case 0x10: p = "high-deviation FM"; break;
1039 case 0x11: p = "very high-deviation FM"; break;
1040 case 0xfd: p = "unknown audio standard"; break;
1041 case 0xfe: p = "forced audio standard"; break;
1042 case 0xff: p = "no detected audio standard"; break;
1043 default: p = "not defined";
1044 }
Hans Verkuilfac9e892006-01-09 15:32:40 -02001045 v4l_info(client, "Detected audio standard: %s\n", p);
1046 v4l_info(client, "Audio muted: %s\n",
Hans Verkuilbd985162005-11-13 16:07:56 -08001047 (mute_ctl & 0x2) ? "yes" : "no");
Hans Verkuilfac9e892006-01-09 15:32:40 -02001048 v4l_info(client, "Audio microcontroller: %s\n",
Hans Verkuilbd985162005-11-13 16:07:56 -08001049 (download_ctl & 0x10) ? "running" : "stopped");
1050
1051 switch (audio_config >> 4) {
1052 case 0x00: p = "undefined"; break;
1053 case 0x01: p = "BTSC"; break;
1054 case 0x02: p = "EIAJ"; break;
1055 case 0x03: p = "A2-M"; break;
1056 case 0x04: p = "A2-BG"; break;
1057 case 0x05: p = "A2-DK1"; break;
1058 case 0x06: p = "A2-DK2"; break;
1059 case 0x07: p = "A2-DK3"; break;
1060 case 0x08: p = "A1 (6.0 MHz FM Mono)"; break;
1061 case 0x09: p = "AM-L"; break;
1062 case 0x0a: p = "NICAM-BG"; break;
1063 case 0x0b: p = "NICAM-DK"; break;
1064 case 0x0c: p = "NICAM-I"; break;
1065 case 0x0d: p = "NICAM-L"; break;
1066 case 0x0e: p = "FM radio"; break;
1067 case 0x0f: p = "automatic detection"; break;
1068 default: p = "undefined";
1069 }
Hans Verkuilfac9e892006-01-09 15:32:40 -02001070 v4l_info(client, "Configured audio standard: %s\n", p);
Hans Verkuilbd985162005-11-13 16:07:56 -08001071
1072 if ((audio_config >> 4) < 0xF) {
1073 switch (audio_config & 0xF) {
1074 case 0x00: p = "MONO1 (LANGUAGE A/Mono L+R channel for BTSC, EIAJ, A2)"; break;
1075 case 0x01: p = "MONO2 (LANGUAGE B)"; break;
1076 case 0x02: p = "MONO3 (STEREO forced MONO)"; break;
1077 case 0x03: p = "MONO4 (NICAM ANALOG-Language C/Analog Fallback)"; break;
1078 case 0x04: p = "STEREO"; break;
1079 case 0x05: p = "DUAL1 (AB)"; break;
1080 case 0x06: p = "DUAL2 (AC) (FM)"; break;
1081 case 0x07: p = "DUAL3 (BC) (FM)"; break;
1082 case 0x08: p = "DUAL4 (AC) (AM)"; break;
1083 case 0x09: p = "DUAL5 (BC) (AM)"; break;
1084 case 0x0a: p = "SAP"; break;
1085 default: p = "undefined";
1086 }
Hans Verkuilfac9e892006-01-09 15:32:40 -02001087 v4l_info(client, "Configured audio mode: %s\n", p);
Hans Verkuilbd985162005-11-13 16:07:56 -08001088 } else {
1089 switch (audio_config & 0xF) {
1090 case 0x00: p = "BG"; break;
1091 case 0x01: p = "DK1"; break;
1092 case 0x02: p = "DK2"; break;
1093 case 0x03: p = "DK3"; break;
1094 case 0x04: p = "I"; break;
1095 case 0x05: p = "L"; break;
1096 case 0x06: p = "BTSC"; break;
1097 case 0x07: p = "EIAJ"; break;
1098 case 0x08: p = "A2-M"; break;
1099 case 0x09: p = "FM Radio"; break;
1100 case 0x0f: p = "automatic standard and mode detection"; break;
1101 default: p = "undefined";
1102 }
Hans Verkuilfac9e892006-01-09 15:32:40 -02001103 v4l_info(client, "Configured audio system: %s\n", p);
Hans Verkuilbd985162005-11-13 16:07:56 -08001104 }
1105
Hans Verkuilfac9e892006-01-09 15:32:40 -02001106 v4l_info(client, "Specified standard: %s\n",
Hans Verkuilbd985162005-11-13 16:07:56 -08001107 vidfmt_sel ? fmt_strs[vidfmt_sel] : "automatic detection");
1108
Hans Verkuila8bbf122006-01-09 15:25:42 -02001109 if (vid_input >= CX25840_COMPOSITE1 &&
1110 vid_input <= CX25840_COMPOSITE8) {
Hans Verkuilfac9e892006-01-09 15:32:40 -02001111 v4l_info(client, "Specified video input: Composite %d\n",
Hans Verkuila8bbf122006-01-09 15:25:42 -02001112 vid_input - CX25840_COMPOSITE1 + 1);
1113 } else {
Hans Verkuilfac9e892006-01-09 15:32:40 -02001114 v4l_info(client, "Specified video input: S-Video (Luma In%d, Chroma In%d)\n",
Hans Verkuila8bbf122006-01-09 15:25:42 -02001115 (vid_input & 0xf0) >> 4, (vid_input & 0xf00) >> 8);
Hans Verkuilbd985162005-11-13 16:07:56 -08001116 }
Hans Verkuila8bbf122006-01-09 15:25:42 -02001117 if (aud_input) {
Hans Verkuilfac9e892006-01-09 15:32:40 -02001118 v4l_info(client, "Specified audio input: Tuner (In%d)\n", aud_input);
Hans Verkuila8bbf122006-01-09 15:25:42 -02001119 } else {
Hans Verkuilfac9e892006-01-09 15:32:40 -02001120 v4l_info(client, "Specified audio input: External\n");
Hans Verkuila8bbf122006-01-09 15:25:42 -02001121 }
Hans Verkuilbd985162005-11-13 16:07:56 -08001122
Hans Verkuilfac9e892006-01-09 15:32:40 -02001123 v4l_info(client, "Specified audioclock freq: %d Hz\n", state->audclk_freq);
Hans Verkuilbd985162005-11-13 16:07:56 -08001124
1125 switch (pref_mode & 0xf) {
1126 case 0: p = "mono/language A"; break;
1127 case 1: p = "language B"; break;
1128 case 2: p = "language C"; break;
1129 case 3: p = "analog fallback"; break;
1130 case 4: p = "stereo"; break;
1131 case 5: p = "language AC"; break;
1132 case 6: p = "language BC"; break;
1133 case 7: p = "language AB"; break;
1134 default: p = "undefined";
1135 }
Hans Verkuilfac9e892006-01-09 15:32:40 -02001136 v4l_info(client, "Preferred audio mode: %s\n", p);
Hans Verkuilbd985162005-11-13 16:07:56 -08001137
1138 if ((audio_config & 0xf) == 0xf) {
1139 switch ((afc0 >> 3) & 0x3) {
1140 case 0: p = "system DK"; break;
1141 case 1: p = "system L"; break;
1142 case 2: p = "autodetect"; break;
1143 default: p = "undefined";
1144 }
Hans Verkuilfac9e892006-01-09 15:32:40 -02001145 v4l_info(client, "Selected 65 MHz format: %s\n", p);
Hans Verkuilbd985162005-11-13 16:07:56 -08001146
1147 switch (afc0 & 0x7) {
1148 case 0: p = "chroma"; break;
1149 case 1: p = "BTSC"; break;
1150 case 2: p = "EIAJ"; break;
1151 case 3: p = "A2-M"; break;
1152 case 4: p = "autodetect"; break;
1153 default: p = "undefined";
1154 }
Hans Verkuilfac9e892006-01-09 15:32:40 -02001155 v4l_info(client, "Selected 45 MHz format: %s\n", p);
Hans Verkuilbd985162005-11-13 16:07:56 -08001156 }
1157}