V4L/DVB (4005): Add support for the cx25836/7 video decoder.
[powerpc.git] / drivers / media / video / cx25840 / cx25840-core.c
1 /* 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>
34 #include <media/v4l2-common.h>
35 #include <media/cx25840.h>
36
37 #include "cx25840-core.h"
38
39 MODULE_DESCRIPTION("Conexant CX25840 audio/video decoder driver");
40 MODULE_AUTHOR("Ulf Eklund, Chris Kennedy, Hans Verkuil, Tyler Trafford");
41 MODULE_LICENSE("GPL");
42
43 static unsigned short normal_i2c[] = { 0x88 >> 1, I2C_CLIENT_END };
44
45
46 static int cx25840_debug;
47
48 module_param_named(debug,cx25840_debug, int, 0644);
49
50 MODULE_PARM_DESC(debug, "Debugging messages [0=Off (default) 1=On]");
51
52 I2C_CLIENT_INSMOD;
53
54 /* ----------------------------------------------------------------------- */
55
56 int cx25840_write(struct i2c_client *client, u16 addr, u8 value)
57 {
58         u8 buffer[3];
59         buffer[0] = addr >> 8;
60         buffer[1] = addr & 0xff;
61         buffer[2] = value;
62         return i2c_master_send(client, buffer, 3);
63 }
64
65 int cx25840_write4(struct i2c_client *client, u16 addr, u32 value)
66 {
67         u8 buffer[6];
68         buffer[0] = addr >> 8;
69         buffer[1] = addr & 0xff;
70         buffer[2] = value >> 24;
71         buffer[3] = (value >> 16) & 0xff;
72         buffer[4] = (value >> 8) & 0xff;
73         buffer[5] = value & 0xff;
74         return i2c_master_send(client, buffer, 6);
75 }
76
77 u8 cx25840_read(struct i2c_client * client, u16 addr)
78 {
79         u8 buffer[2];
80         buffer[0] = addr >> 8;
81         buffer[1] = addr & 0xff;
82
83         if (i2c_master_send(client, buffer, 2) < 2)
84                 return 0;
85
86         if (i2c_master_recv(client, buffer, 1) < 1)
87                 return 0;
88
89         return buffer[0];
90 }
91
92 u32 cx25840_read4(struct i2c_client * client, u16 addr)
93 {
94         u8 buffer[4];
95         buffer[0] = addr >> 8;
96         buffer[1] = addr & 0xff;
97
98         if (i2c_master_send(client, buffer, 2) < 2)
99                 return 0;
100
101         if (i2c_master_recv(client, buffer, 4) < 4)
102                 return 0;
103
104         return (buffer[0] << 24) | (buffer[1] << 16) |
105             (buffer[2] << 8) | buffer[3];
106 }
107
108 int cx25840_and_or(struct i2c_client *client, u16 addr, unsigned and_mask,
109                    u8 or_value)
110 {
111         return cx25840_write(client, addr,
112                              (cx25840_read(client, addr) & and_mask) |
113                              or_value);
114 }
115
116 /* ----------------------------------------------------------------------- */
117
118 static int set_input(struct i2c_client *client, enum cx25840_video_input vid_input,
119                                                 enum cx25840_audio_input aud_input);
120 static void log_audio_status(struct i2c_client *client);
121 static void log_video_status(struct i2c_client *client);
122
123 /* ----------------------------------------------------------------------- */
124
125 static void init_dll1(struct i2c_client *client)
126 {
127         /* This is the Hauppauge sequence used to
128          * initialize the Delay Lock Loop 1 (ADC DLL). */
129         cx25840_write(client, 0x159, 0x23);
130         cx25840_write(client, 0x15a, 0x87);
131         cx25840_write(client, 0x15b, 0x06);
132         cx25840_write(client, 0x159, 0xe1);
133         cx25840_write(client, 0x15a, 0x86);
134         cx25840_write(client, 0x159, 0xe0);
135         cx25840_write(client, 0x159, 0xe1);
136         cx25840_write(client, 0x15b, 0x10);
137 }
138
139 static void init_dll2(struct i2c_client *client)
140 {
141         /* This is the Hauppauge sequence used to
142          * initialize the Delay Lock Loop 2 (ADC DLL). */
143         cx25840_write(client, 0x15d, 0xe3);
144         cx25840_write(client, 0x15e, 0x86);
145         cx25840_write(client, 0x15f, 0x06);
146         cx25840_write(client, 0x15d, 0xe1);
147         cx25840_write(client, 0x15d, 0xe0);
148         cx25840_write(client, 0x15d, 0xe1);
149 }
150
151 static void cx25836_initialize(struct i2c_client *client)
152 {
153         /* reset configuration is described on page 3-77 of the CX25836 datasheet */
154         /* 2. */
155         cx25840_and_or(client, 0x000, ~0x01, 0x01);
156         cx25840_and_or(client, 0x000, ~0x01, 0x00);
157         /* 3a. */
158         cx25840_and_or(client, 0x15a, ~0x70, 0x00);
159         /* 3b. */
160         cx25840_and_or(client, 0x15b, ~0x1e, 0x06);
161         /* 3c. */
162         cx25840_and_or(client, 0x159, ~0x02, 0x02);
163         /* 3d. */
164         /* There should be a 10-us delay here, but since the
165            i2c bus already has a 10-us delay we don't need to do
166            anything */
167         /* 3e. */
168         cx25840_and_or(client, 0x159, ~0x02, 0x00);
169         /* 3f. */
170         cx25840_and_or(client, 0x159, ~0xc0, 0xc0);
171         /* 3g. */
172         cx25840_and_or(client, 0x159, ~0x01, 0x00);
173         cx25840_and_or(client, 0x159, ~0x01, 0x01);
174         /* 3h. */
175         cx25840_and_or(client, 0x15b, ~0x1e, 0x10);
176 }
177
178 static void cx25840_initialize(struct i2c_client *client, int loadfw)
179 {
180         struct cx25840_state *state = i2c_get_clientdata(client);
181
182         /* datasheet startup in numbered steps, refer to page 3-77 */
183         /* 2. */
184         cx25840_and_or(client, 0x803, ~0x10, 0x00);
185         /* The default of this register should be 4, but I get 0 instead.
186          * Set this register to 4 manually. */
187         cx25840_write(client, 0x000, 0x04);
188         /* 3. */
189         init_dll1(client);
190         init_dll2(client);
191         cx25840_write(client, 0x136, 0x0a);
192         /* 4. */
193         cx25840_write(client, 0x13c, 0x01);
194         cx25840_write(client, 0x13c, 0x00);
195         /* 5. */
196         if (loadfw)
197                 cx25840_loadfw(client);
198         /* 6. */
199         cx25840_write(client, 0x115, 0x8c);
200         cx25840_write(client, 0x116, 0x07);
201         cx25840_write(client, 0x118, 0x02);
202         /* 7. */
203         cx25840_write(client, 0x4a5, 0x80);
204         cx25840_write(client, 0x4a5, 0x00);
205         cx25840_write(client, 0x402, 0x00);
206         /* 8. */
207         cx25840_and_or(client, 0x401, ~0x18, 0);
208         cx25840_and_or(client, 0x4a2, ~0x10, 0x10);
209         /* steps 8c and 8d are done in change_input() */
210         /* 10. */
211         cx25840_write(client, 0x8d3, 0x1f);
212         cx25840_write(client, 0x8e3, 0x03);
213
214         cx25840_vbi_setup(client);
215
216         /* trial and error says these are needed to get audio */
217         cx25840_write(client, 0x914, 0xa0);
218         cx25840_write(client, 0x918, 0xa0);
219         cx25840_write(client, 0x919, 0x01);
220
221         /* stereo prefered */
222         cx25840_write(client, 0x809, 0x04);
223         /* AC97 shift */
224         cx25840_write(client, 0x8cf, 0x0f);
225
226         /* (re)set input */
227         set_input(client, state->vid_input, state->aud_input);
228
229         /* start microcontroller */
230         cx25840_and_or(client, 0x803, ~0x10, 0x10);
231 }
232
233 /* ----------------------------------------------------------------------- */
234
235 static void input_change(struct i2c_client *client)
236 {
237         struct cx25840_state *state = i2c_get_clientdata(client);
238         v4l2_std_id std = cx25840_get_v4lstd(client);
239
240         /* Follow step 8c and 8d of section 3.16 in the cx25840 datasheet */
241         if (std & V4L2_STD_SECAM) {
242                 cx25840_write(client, 0x402, 0);
243         }
244         else {
245                 cx25840_write(client, 0x402, 0x04);
246                 cx25840_write(client, 0x49f, (std & V4L2_STD_NTSC) ? 0x14 : 0x11);
247         }
248         cx25840_and_or(client, 0x401, ~0x60, 0);
249         cx25840_and_or(client, 0x401, ~0x60, 0x60);
250
251         /* Note: perhaps V4L2_STD_PAL_M should be handled as V4L2_STD_NTSC
252            instead of V4L2_STD_PAL. Someone needs to test this. */
253         if (std & V4L2_STD_PAL) {
254                 /* Follow tuner change procedure for PAL */
255                 cx25840_write(client, 0x808, 0xff);
256                 cx25840_write(client, 0x80b, 0x10);
257         } else if (std & V4L2_STD_SECAM) {
258                 /* Select autodetect for SECAM */
259                 cx25840_write(client, 0x808, 0xff);
260                 cx25840_write(client, 0x80b, 0x10);
261         } else if (std & V4L2_STD_NTSC) {
262                 /* Certain Hauppauge PVR150 models have a hardware bug
263                    that causes audio to drop out. For these models the
264                    audio standard must be set explicitly.
265                    To be precise: it affects cards with tuner models
266                    85, 99 and 112 (model numbers from tveeprom). */
267                 int hw_fix = state->pvr150_workaround;
268
269                 if (std == V4L2_STD_NTSC_M_JP) {
270                         /* Japan uses EIAJ audio standard */
271                         cx25840_write(client, 0x808, hw_fix ? 0x2f : 0xf7);
272                 } else if (std == V4L2_STD_NTSC_M_KR) {
273                         /* South Korea uses A2 audio standard */
274                         cx25840_write(client, 0x808, hw_fix ? 0x3f : 0xf8);
275                 } else {
276                         /* Others use the BTSC audio standard */
277                         cx25840_write(client, 0x808, hw_fix ? 0x1f : 0xf6);
278                 }
279                 cx25840_write(client, 0x80b, 0x00);
280         }
281
282         if (cx25840_read(client, 0x803) & 0x10) {
283                 /* restart audio decoder microcontroller */
284                 cx25840_and_or(client, 0x803, ~0x10, 0x00);
285                 cx25840_and_or(client, 0x803, ~0x10, 0x10);
286         }
287 }
288
289 static int set_input(struct i2c_client *client, enum cx25840_video_input vid_input,
290                                                 enum cx25840_audio_input aud_input)
291 {
292         struct cx25840_state *state = i2c_get_clientdata(client);
293         u8 is_composite = (vid_input >= CX25840_COMPOSITE1 &&
294                            vid_input <= CX25840_COMPOSITE8);
295         u8 reg;
296
297         v4l_dbg(1, cx25840_debug, client, "decoder set video input %d, audio input %d\n",
298                         vid_input, aud_input);
299
300         if (is_composite) {
301                 reg = 0xf0 + (vid_input - CX25840_COMPOSITE1);
302         } else {
303                 int luma = vid_input & 0xf0;
304                 int chroma = vid_input & 0xf00;
305
306                 if ((vid_input & ~0xff0) ||
307                     luma < CX25840_SVIDEO_LUMA1 || luma > CX25840_SVIDEO_LUMA4 ||
308                     chroma < CX25840_SVIDEO_CHROMA4 || chroma > CX25840_SVIDEO_CHROMA8) {
309                         v4l_err(client, "0x%04x is not a valid video input!\n", vid_input);
310                         return -EINVAL;
311                 }
312                 reg = 0xf0 + ((luma - CX25840_SVIDEO_LUMA1) >> 4);
313                 if (chroma >= CX25840_SVIDEO_CHROMA7) {
314                         reg &= 0x3f;
315                         reg |= (chroma - CX25840_SVIDEO_CHROMA7) >> 2;
316                 } else {
317                         reg &= 0xcf;
318                         reg |= (chroma - CX25840_SVIDEO_CHROMA4) >> 4;
319                 }
320         }
321
322         switch (aud_input) {
323         case CX25840_AUDIO_SERIAL:
324                 /* do nothing, use serial audio input */
325                 break;
326         case CX25840_AUDIO4: reg &= ~0x30; break;
327         case CX25840_AUDIO5: reg &= ~0x30; reg |= 0x10; break;
328         case CX25840_AUDIO6: reg &= ~0x30; reg |= 0x20; break;
329         case CX25840_AUDIO7: reg &= ~0xc0; break;
330         case CX25840_AUDIO8: reg &= ~0xc0; reg |= 0x40; break;
331
332         default:
333                 v4l_err(client, "0x%04x is not a valid audio input!\n", aud_input);
334                 return -EINVAL;
335         }
336
337         cx25840_write(client, 0x103, reg);
338         /* Set INPUT_MODE to Composite (0) or S-Video (1) */
339         cx25840_and_or(client, 0x401, ~0x6, is_composite ? 0 : 0x02);
340         /* Set CH_SEL_ADC2 to 1 if input comes from CH3 */
341         cx25840_and_or(client, 0x102, ~0x2, (reg & 0x80) == 0 ? 2 : 0);
342         /* Set DUAL_MODE_ADC2 to 1 if input comes from both CH2 and CH3 */
343         if ((reg & 0xc0) != 0xc0 && (reg & 0x30) != 0x30)
344                 cx25840_and_or(client, 0x102, ~0x4, 4);
345         else
346                 cx25840_and_or(client, 0x102, ~0x4, 0);
347
348         state->vid_input = vid_input;
349         state->aud_input = aud_input;
350         if (!state->is_cx25836) {
351                 cx25840_audio_set_path(client);
352                 input_change(client);
353         }
354         return 0;
355 }
356
357 /* ----------------------------------------------------------------------- */
358
359 static int set_v4lstd(struct i2c_client *client, v4l2_std_id std)
360 {
361         u8 fmt=0;       /* zero is autodetect */
362
363         /* First tests should be against specific std */
364         if (std == V4L2_STD_NTSC_M_JP) {
365                 fmt=0x2;
366         } else if (std == V4L2_STD_NTSC_443) {
367                 fmt=0x3;
368         } else if (std == V4L2_STD_PAL_M) {
369                 fmt=0x5;
370         } else if (std == V4L2_STD_PAL_N) {
371                 fmt=0x6;
372         } else if (std == V4L2_STD_PAL_Nc) {
373                 fmt=0x7;
374         } else if (std == V4L2_STD_PAL_60) {
375                 fmt=0x8;
376         } else {
377                 /* Then, test against generic ones */
378                 if (std & V4L2_STD_NTSC) {
379                         fmt=0x1;
380                 } else if (std & V4L2_STD_PAL) {
381                         fmt=0x4;
382                 } else if (std & V4L2_STD_SECAM) {
383                         fmt=0xc;
384                 }
385         }
386
387         /* Follow step 9 of section 3.16 in the cx25840 datasheet.
388            Without this PAL may display a vertical ghosting effect.
389            This happens for example with the Yuan MPC622. */
390         if (fmt >= 4 && fmt < 8) {
391                 /* Set format to NTSC-M */
392                 cx25840_and_or(client, 0x400, ~0xf, 1);
393                 /* Turn off LCOMB */
394                 cx25840_and_or(client, 0x47b, ~6, 0);
395         }
396         cx25840_and_or(client, 0x400, ~0xf, fmt);
397         cx25840_vbi_setup(client);
398         return 0;
399 }
400
401 v4l2_std_id cx25840_get_v4lstd(struct i2c_client * client)
402 {
403         struct cx25840_state *state = i2c_get_clientdata(client);
404         /* check VID_FMT_SEL first */
405         u8 fmt = cx25840_read(client, 0x400) & 0xf;
406
407         if (!fmt) {
408                 /* check AFD_FMT_STAT if set to autodetect */
409                 fmt = cx25840_read(client, 0x40d) & 0xf;
410         }
411
412         switch (fmt) {
413         case 0x1:
414         {
415                 /* if the audio std is A2-M, then this is the South Korean
416                    NTSC standard */
417                 if (!state->is_cx25836 && cx25840_read(client, 0x805) == 2)
418                         return V4L2_STD_NTSC_M_KR;
419                 return V4L2_STD_NTSC_M;
420         }
421         case 0x2: return V4L2_STD_NTSC_M_JP;
422         case 0x3: return V4L2_STD_NTSC_443;
423         case 0x4: return V4L2_STD_PAL;
424         case 0x5: return V4L2_STD_PAL_M;
425         case 0x6: return V4L2_STD_PAL_N;
426         case 0x7: return V4L2_STD_PAL_Nc;
427         case 0x8: return V4L2_STD_PAL_60;
428         case 0xc: return V4L2_STD_SECAM;
429         default: return V4L2_STD_UNKNOWN;
430         }
431 }
432
433 /* ----------------------------------------------------------------------- */
434
435 static int set_v4lctrl(struct i2c_client *client, struct v4l2_control *ctrl)
436 {
437         struct cx25840_state *state = i2c_get_clientdata(client);
438
439         switch (ctrl->id) {
440         case CX25840_CID_ENABLE_PVR150_WORKAROUND:
441                 state->pvr150_workaround = ctrl->value;
442                 set_input(client, state->vid_input, state->aud_input);
443                 break;
444
445         case V4L2_CID_BRIGHTNESS:
446                 if (ctrl->value < 0 || ctrl->value > 255) {
447                         v4l_err(client, "invalid brightness setting %d\n",
448                                     ctrl->value);
449                         return -ERANGE;
450                 }
451
452                 cx25840_write(client, 0x414, ctrl->value - 128);
453                 break;
454
455         case V4L2_CID_CONTRAST:
456                 if (ctrl->value < 0 || ctrl->value > 127) {
457                         v4l_err(client, "invalid contrast setting %d\n",
458                                     ctrl->value);
459                         return -ERANGE;
460                 }
461
462                 cx25840_write(client, 0x415, ctrl->value << 1);
463                 break;
464
465         case V4L2_CID_SATURATION:
466                 if (ctrl->value < 0 || ctrl->value > 127) {
467                         v4l_err(client, "invalid saturation setting %d\n",
468                                     ctrl->value);
469                         return -ERANGE;
470                 }
471
472                 cx25840_write(client, 0x420, ctrl->value << 1);
473                 cx25840_write(client, 0x421, ctrl->value << 1);
474                 break;
475
476         case V4L2_CID_HUE:
477                 if (ctrl->value < -127 || ctrl->value > 127) {
478                         v4l_err(client, "invalid hue setting %d\n", ctrl->value);
479                         return -ERANGE;
480                 }
481
482                 cx25840_write(client, 0x422, ctrl->value);
483                 break;
484
485         case V4L2_CID_AUDIO_VOLUME:
486         case V4L2_CID_AUDIO_BASS:
487         case V4L2_CID_AUDIO_TREBLE:
488         case V4L2_CID_AUDIO_BALANCE:
489         case V4L2_CID_AUDIO_MUTE:
490                 if (state->is_cx25836)
491                         return -EINVAL;
492                 return cx25840_audio(client, VIDIOC_S_CTRL, ctrl);
493
494         default:
495                 return -EINVAL;
496         }
497
498         return 0;
499 }
500
501 static int get_v4lctrl(struct i2c_client *client, struct v4l2_control *ctrl)
502 {
503         struct cx25840_state *state = i2c_get_clientdata(client);
504
505         switch (ctrl->id) {
506         case CX25840_CID_ENABLE_PVR150_WORKAROUND:
507                 ctrl->value = state->pvr150_workaround;
508                 break;
509         case V4L2_CID_BRIGHTNESS:
510                 ctrl->value = (s8)cx25840_read(client, 0x414) + 128;
511                 break;
512         case V4L2_CID_CONTRAST:
513                 ctrl->value = cx25840_read(client, 0x415) >> 1;
514                 break;
515         case V4L2_CID_SATURATION:
516                 ctrl->value = cx25840_read(client, 0x420) >> 1;
517                 break;
518         case V4L2_CID_HUE:
519                 ctrl->value = (s8)cx25840_read(client, 0x422);
520                 break;
521         case V4L2_CID_AUDIO_VOLUME:
522         case V4L2_CID_AUDIO_BASS:
523         case V4L2_CID_AUDIO_TREBLE:
524         case V4L2_CID_AUDIO_BALANCE:
525         case V4L2_CID_AUDIO_MUTE:
526                 if (state->is_cx25836)
527                         return -EINVAL;
528                 return cx25840_audio(client, VIDIOC_G_CTRL, ctrl);
529         default:
530                 return -EINVAL;
531         }
532
533         return 0;
534 }
535
536 /* ----------------------------------------------------------------------- */
537
538 static int get_v4lfmt(struct i2c_client *client, struct v4l2_format *fmt)
539 {
540         switch (fmt->type) {
541         case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
542                 return cx25840_vbi(client, VIDIOC_G_FMT, fmt);
543         default:
544                 return -EINVAL;
545         }
546
547         return 0;
548 }
549
550 static int set_v4lfmt(struct i2c_client *client, struct v4l2_format *fmt)
551 {
552         struct v4l2_pix_format *pix;
553         int HSC, VSC, Vsrc, Hsrc, filter, Vlines;
554         int is_pal = !(cx25840_get_v4lstd(client) & V4L2_STD_NTSC);
555
556         switch (fmt->type) {
557         case V4L2_BUF_TYPE_VIDEO_CAPTURE:
558                 pix = &(fmt->fmt.pix);
559
560                 Vsrc = (cx25840_read(client, 0x476) & 0x3f) << 4;
561                 Vsrc |= (cx25840_read(client, 0x475) & 0xf0) >> 4;
562
563                 Hsrc = (cx25840_read(client, 0x472) & 0x3f) << 4;
564                 Hsrc |= (cx25840_read(client, 0x471) & 0xf0) >> 4;
565
566                 Vlines = pix->height + (is_pal ? 4 : 7);
567
568                 if ((pix->width * 16 < Hsrc) || (Hsrc < pix->width) ||
569                     (Vlines * 8 < Vsrc) || (Vsrc < Vlines)) {
570                         v4l_err(client, "%dx%d is not a valid size!\n",
571                                     pix->width, pix->height);
572                         return -ERANGE;
573                 }
574
575                 HSC = (Hsrc * (1 << 20)) / pix->width - (1 << 20);
576                 VSC = (1 << 16) - (Vsrc * (1 << 9) / Vlines - (1 << 9));
577                 VSC &= 0x1fff;
578
579                 if (pix->width >= 385)
580                         filter = 0;
581                 else if (pix->width > 192)
582                         filter = 1;
583                 else if (pix->width > 96)
584                         filter = 2;
585                 else
586                         filter = 3;
587
588                 v4l_dbg(1, cx25840_debug, client, "decoder set size %dx%d -> scale  %ux%u\n",
589                             pix->width, pix->height, HSC, VSC);
590
591                 /* HSCALE=HSC */
592                 cx25840_write(client, 0x418, HSC & 0xff);
593                 cx25840_write(client, 0x419, (HSC >> 8) & 0xff);
594                 cx25840_write(client, 0x41a, HSC >> 16);
595                 /* VSCALE=VSC */
596                 cx25840_write(client, 0x41c, VSC & 0xff);
597                 cx25840_write(client, 0x41d, VSC >> 8);
598                 /* VS_INTRLACE=1 VFILT=filter */
599                 cx25840_write(client, 0x41e, 0x8 | filter);
600                 break;
601
602         case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
603                 return cx25840_vbi(client, VIDIOC_S_FMT, fmt);
604
605         case V4L2_BUF_TYPE_VBI_CAPTURE:
606                 return cx25840_vbi(client, VIDIOC_S_FMT, fmt);
607
608         default:
609                 return -EINVAL;
610         }
611
612         return 0;
613 }
614
615 /* ----------------------------------------------------------------------- */
616
617 static struct v4l2_queryctrl cx25836_qctrl[] = {
618         {
619                 .id            = V4L2_CID_BRIGHTNESS,
620                 .type          = V4L2_CTRL_TYPE_INTEGER,
621                 .name          = "Brightness",
622                 .minimum       = 0,
623                 .maximum       = 255,
624                 .step          = 1,
625                 .default_value = 128,
626                 .flags         = 0,
627         }, {
628                 .id            = V4L2_CID_CONTRAST,
629                 .type          = V4L2_CTRL_TYPE_INTEGER,
630                 .name          = "Contrast",
631                 .minimum       = 0,
632                 .maximum       = 127,
633                 .step          = 1,
634                 .default_value = 64,
635                 .flags         = 0,
636         }, {
637                 .id            = V4L2_CID_SATURATION,
638                 .type          = V4L2_CTRL_TYPE_INTEGER,
639                 .name          = "Saturation",
640                 .minimum       = 0,
641                 .maximum       = 127,
642                 .step          = 1,
643                 .default_value = 64,
644                 .flags         = 0,
645         }, {
646                 .id            = V4L2_CID_HUE,
647                 .type          = V4L2_CTRL_TYPE_INTEGER,
648                 .name          = "Hue",
649                 .minimum       = -128,
650                 .maximum       = 127,
651                 .step          = 1,
652                 .default_value = 0,
653                 .flags         = 0,
654         },
655 };
656
657 static struct v4l2_queryctrl cx25840_qctrl[] = {
658         {
659                 .id            = V4L2_CID_AUDIO_VOLUME,
660                 .type          = V4L2_CTRL_TYPE_INTEGER,
661                 .name          = "Volume",
662                 .minimum       = 0,
663                 .maximum       = 65535,
664                 .step          = 65535/100,
665                 .default_value = 58880,
666                 .flags         = 0,
667         }, {
668                 .id            = V4L2_CID_AUDIO_BALANCE,
669                 .type          = V4L2_CTRL_TYPE_INTEGER,
670                 .name          = "Balance",
671                 .minimum       = 0,
672                 .maximum       = 65535,
673                 .step          = 65535/100,
674                 .default_value = 32768,
675                 .flags         = 0,
676         }, {
677                 .id            = V4L2_CID_AUDIO_MUTE,
678                 .type          = V4L2_CTRL_TYPE_BOOLEAN,
679                 .name          = "Mute",
680                 .minimum       = 0,
681                 .maximum       = 1,
682                 .step          = 1,
683                 .default_value = 1,
684                 .flags         = 0,
685         }, {
686                 .id            = V4L2_CID_AUDIO_BASS,
687                 .type          = V4L2_CTRL_TYPE_INTEGER,
688                 .name          = "Bass",
689                 .minimum       = 0,
690                 .maximum       = 65535,
691                 .step          = 65535/100,
692                 .default_value = 32768,
693         }, {
694                 .id            = V4L2_CID_AUDIO_TREBLE,
695                 .type          = V4L2_CTRL_TYPE_INTEGER,
696                 .name          = "Treble",
697                 .minimum       = 0,
698                 .maximum       = 65535,
699                 .step          = 65535/100,
700                 .default_value = 32768,
701         },
702 };
703
704 /* ----------------------------------------------------------------------- */
705
706 static int cx25840_command(struct i2c_client *client, unsigned int cmd,
707                            void *arg)
708 {
709         struct cx25840_state *state = i2c_get_clientdata(client);
710         struct v4l2_tuner *vt = arg;
711         struct v4l2_routing *route = arg;
712
713         switch (cmd) {
714 #ifdef CONFIG_VIDEO_ADV_DEBUG
715         /* ioctls to allow direct access to the
716          * cx25840 registers for testing */
717         case VIDIOC_INT_G_REGISTER:
718         {
719                 struct v4l2_register *reg = arg;
720
721                 if (reg->i2c_id != I2C_DRIVERID_CX25840)
722                         return -EINVAL;
723                 reg->val = cx25840_read(client, reg->reg & 0x0fff);
724                 break;
725         }
726
727         case VIDIOC_INT_S_REGISTER:
728         {
729                 struct v4l2_register *reg = arg;
730
731                 if (reg->i2c_id != I2C_DRIVERID_CX25840)
732                         return -EINVAL;
733                 if (!capable(CAP_SYS_ADMIN))
734                         return -EPERM;
735                 cx25840_write(client, reg->reg & 0x0fff, reg->val & 0xff);
736                 break;
737         }
738 #endif
739
740         case VIDIOC_INT_DECODE_VBI_LINE:
741                 return cx25840_vbi(client, cmd, arg);
742
743         case VIDIOC_INT_AUDIO_CLOCK_FREQ:
744                 return cx25840_audio(client, cmd, arg);
745
746         case VIDIOC_STREAMON:
747                 v4l_dbg(1, cx25840_debug, client, "enable output\n");
748                 cx25840_write(client, 0x115, state->is_cx25836 ? 0x0c : 0x8c);
749                 cx25840_write(client, 0x116, state->is_cx25836 ? 0x04 : 0x07);
750                 break;
751
752         case VIDIOC_STREAMOFF:
753                 v4l_dbg(1, cx25840_debug, client, "disable output\n");
754                 cx25840_write(client, 0x115, 0x00);
755                 cx25840_write(client, 0x116, 0x00);
756                 break;
757
758         case VIDIOC_LOG_STATUS:
759                 log_video_status(client);
760                 if (!state->is_cx25836)
761                         log_audio_status(client);
762                 break;
763
764         case VIDIOC_G_CTRL:
765                 return get_v4lctrl(client, (struct v4l2_control *)arg);
766
767         case VIDIOC_S_CTRL:
768                 return set_v4lctrl(client, (struct v4l2_control *)arg);
769
770         case VIDIOC_QUERYCTRL:
771         {
772                 struct v4l2_queryctrl *qc = arg;
773                 int i;
774
775                 for (i = 0; i < ARRAY_SIZE(cx25836_qctrl); i++)
776                         if (qc->id && qc->id == cx25836_qctrl[i].id) {
777                                 memcpy(qc, &cx25836_qctrl[i], sizeof(*qc));
778                                 return 0;
779                         }
780                 if (state->is_cx25836)
781                         return -EINVAL;
782
783                 for (i = 0; i < ARRAY_SIZE(cx25840_qctrl); i++)
784                         if (qc->id && qc->id == cx25840_qctrl[i].id) {
785                                 memcpy(qc, &cx25840_qctrl[i], sizeof(*qc));
786                                 return 0;
787                         }
788                 return -EINVAL;
789         }
790
791         case VIDIOC_G_STD:
792                 *(v4l2_std_id *)arg = cx25840_get_v4lstd(client);
793                 break;
794
795         case VIDIOC_S_STD:
796                 state->radio = 0;
797                 return set_v4lstd(client, *(v4l2_std_id *)arg);
798
799         case AUDC_SET_RADIO:
800                 state->radio = 1;
801                 break;
802
803         case VIDIOC_INT_G_VIDEO_ROUTING:
804                 route->input = state->vid_input;
805                 route->output = 0;
806                 break;
807
808         case VIDIOC_INT_S_VIDEO_ROUTING:
809                 return set_input(client, route->input, state->aud_input);
810
811         case VIDIOC_INT_G_AUDIO_ROUTING:
812                 if (state->is_cx25836)
813                         return -EINVAL;
814                 route->input = state->aud_input;
815                 route->output = 0;
816                 break;
817
818         case VIDIOC_INT_S_AUDIO_ROUTING:
819                 if (state->is_cx25836)
820                         return -EINVAL;
821                 return set_input(client, state->vid_input, route->input);
822
823         case VIDIOC_S_FREQUENCY:
824                 if (!state->is_cx25836) {
825                         input_change(client);
826                 }
827                 break;
828
829         case VIDIOC_G_TUNER:
830         {
831                 u8 vpres = cx25840_read(client, 0x40e) & 0x20;
832                 u8 mode;
833                 int val = 0;
834
835                 if (state->radio)
836                         break;
837
838                 vt->signal = vpres ? 0xffff : 0x0;
839                 if (state->is_cx25836)
840                         break;
841
842                 vt->capability |=
843                     V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_LANG1 |
844                     V4L2_TUNER_CAP_LANG2 | V4L2_TUNER_CAP_SAP;
845
846                 mode = cx25840_read(client, 0x804);
847
848                 /* get rxsubchans and audmode */
849                 if ((mode & 0xf) == 1)
850                         val |= V4L2_TUNER_SUB_STEREO;
851                 else
852                         val |= V4L2_TUNER_SUB_MONO;
853
854                 if (mode == 2 || mode == 4)
855                         val = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
856
857                 if (mode & 0x10)
858                         val |= V4L2_TUNER_SUB_SAP;
859
860                 vt->rxsubchans = val;
861                 vt->audmode = state->audmode;
862                 break;
863         }
864
865         case VIDIOC_S_TUNER:
866                 if (state->radio || state->is_cx25836)
867                         break;
868
869                 switch (vt->audmode) {
870                 case V4L2_TUNER_MODE_MONO:
871                         /* mono      -> mono
872                            stereo    -> mono
873                            bilingual -> lang1 */
874                         cx25840_and_or(client, 0x809, ~0xf, 0x00);
875                         break;
876                 case V4L2_TUNER_MODE_STEREO:
877                 case V4L2_TUNER_MODE_LANG1:
878                         /* mono      -> mono
879                            stereo    -> stereo
880                            bilingual -> lang1 */
881                         cx25840_and_or(client, 0x809, ~0xf, 0x04);
882                         break;
883                 case V4L2_TUNER_MODE_LANG1_LANG2:
884                         /* mono      -> mono
885                            stereo    -> stereo
886                            bilingual -> lang1/lang2 */
887                         cx25840_and_or(client, 0x809, ~0xf, 0x07);
888                         break;
889                 case V4L2_TUNER_MODE_LANG2:
890                         /* mono      -> mono
891                            stereo    -> stereo
892                            bilingual -> lang2 */
893                         cx25840_and_or(client, 0x809, ~0xf, 0x01);
894                         break;
895                 default:
896                         return -EINVAL;
897                 }
898                 state->audmode = vt->audmode;
899                 break;
900
901         case VIDIOC_G_FMT:
902                 return get_v4lfmt(client, (struct v4l2_format *)arg);
903
904         case VIDIOC_S_FMT:
905                 return set_v4lfmt(client, (struct v4l2_format *)arg);
906
907         case VIDIOC_INT_RESET:
908                 if (state->is_cx25836)
909                         cx25836_initialize(client);
910                 else
911                         cx25840_initialize(client, 0);
912                 break;
913
914         case VIDIOC_INT_G_CHIP_IDENT:
915                 *(enum v4l2_chip_ident *)arg = state->id;
916                 break;
917
918         default:
919                 return -EINVAL;
920         }
921
922         return 0;
923 }
924
925 /* ----------------------------------------------------------------------- */
926
927 static struct i2c_driver i2c_driver_cx25840;
928
929 static int cx25840_detect_client(struct i2c_adapter *adapter, int address,
930                                  int kind)
931 {
932         struct i2c_client *client;
933         struct cx25840_state *state;
934         enum v4l2_chip_ident id;
935         u16 device_id;
936
937         /* Check if the adapter supports the needed features
938          * Not until kernel version 2.6.11 did the bit-algo
939          * correctly report that it would do an I2C-level xfer */
940         if (!i2c_check_functionality(adapter, I2C_FUNC_I2C))
941                 return 0;
942
943         state = kzalloc(sizeof(struct cx25840_state), GFP_KERNEL);
944         if (state == 0)
945                 return -ENOMEM;
946
947         client = &state->c;
948         client->addr = address;
949         client->adapter = adapter;
950         client->driver = &i2c_driver_cx25840;
951         snprintf(client->name, sizeof(client->name) - 1, "cx25840");
952
953         v4l_dbg(1, cx25840_debug, client, "detecting cx25840 client on address 0x%x\n", address << 1);
954
955         device_id = cx25840_read(client, 0x101) << 8;
956         device_id |= cx25840_read(client, 0x100);
957
958         /* The high byte of the device ID should be
959          * 0x83 for the cx2583x and 0x84 for the cx2584x */
960         if ((device_id & 0xff00) == 0x8300) {
961                 id = V4L2_IDENT_CX25836 + ((device_id >> 4) & 0xf) - 6;
962                 state->is_cx25836 = 1;
963         }
964         else if ((device_id & 0xff00) == 0x8400) {
965                 id = V4L2_IDENT_CX25840 + ((device_id >> 4) & 0xf);
966                 state->is_cx25836 = 0;
967         }
968         else {
969                 v4l_dbg(1, cx25840_debug, client, "cx25840 not found\n");
970                 kfree(state);
971                 return 0;
972         }
973
974         v4l_info(client, "cx25%3x-2%x found @ 0x%x (%s)\n",
975                     (device_id & 0xfff0) >> 4,
976                     (device_id & 0x0f) < 3 ? (device_id & 0x0f) + 1 : 3,
977                     address << 1, adapter->name);
978
979         i2c_set_clientdata(client, state);
980         state->vid_input = CX25840_COMPOSITE7;
981         state->aud_input = CX25840_AUDIO8;
982         state->audclk_freq = 48000;
983         state->pvr150_workaround = 0;
984         state->audmode = V4L2_TUNER_MODE_LANG1;
985         state->id = id;
986
987         if (state->is_cx25836)
988                 cx25836_initialize(client);
989         else
990                 cx25840_initialize(client, 1);
991
992         i2c_attach_client(client);
993
994         return 0;
995 }
996
997 static int cx25840_attach_adapter(struct i2c_adapter *adapter)
998 {
999         if (adapter->class & I2C_CLASS_TV_ANALOG)
1000                 return i2c_probe(adapter, &addr_data, &cx25840_detect_client);
1001         return 0;
1002 }
1003
1004 static int cx25840_detach_client(struct i2c_client *client)
1005 {
1006         struct cx25840_state *state = i2c_get_clientdata(client);
1007         int err;
1008
1009         err = i2c_detach_client(client);
1010         if (err) {
1011                 return err;
1012         }
1013
1014         kfree(state);
1015
1016         return 0;
1017 }
1018
1019 /* ----------------------------------------------------------------------- */
1020
1021 static struct i2c_driver i2c_driver_cx25840 = {
1022         .driver = {
1023                 .name = "cx25840",
1024         },
1025         .id = I2C_DRIVERID_CX25840,
1026         .attach_adapter = cx25840_attach_adapter,
1027         .detach_client = cx25840_detach_client,
1028         .command = cx25840_command,
1029 };
1030
1031
1032 static int __init m__init(void)
1033 {
1034         return i2c_add_driver(&i2c_driver_cx25840);
1035 }
1036
1037 static void __exit m__exit(void)
1038 {
1039         i2c_del_driver(&i2c_driver_cx25840);
1040 }
1041
1042 module_init(m__init);
1043 module_exit(m__exit);
1044
1045 /* ----------------------------------------------------------------------- */
1046
1047 static void log_video_status(struct i2c_client *client)
1048 {
1049         static const char *const fmt_strs[] = {
1050                 "0x0",
1051                 "NTSC-M", "NTSC-J", "NTSC-4.43",
1052                 "PAL-BDGHI", "PAL-M", "PAL-N", "PAL-Nc", "PAL-60",
1053                 "0x9", "0xA", "0xB",
1054                 "SECAM",
1055                 "0xD", "0xE", "0xF"
1056         };
1057
1058         struct cx25840_state *state = i2c_get_clientdata(client);
1059         u8 vidfmt_sel = cx25840_read(client, 0x400) & 0xf;
1060         u8 gen_stat1 = cx25840_read(client, 0x40d);
1061         u8 gen_stat2 = cx25840_read(client, 0x40e);
1062         int vid_input = state->vid_input;
1063
1064         v4l_info(client, "Video signal:              %spresent\n",
1065                     (gen_stat2 & 0x20) ? "" : "not ");
1066         v4l_info(client, "Detected format:           %s\n",
1067                     fmt_strs[gen_stat1 & 0xf]);
1068
1069         v4l_info(client, "Specified standard:        %s\n",
1070                     vidfmt_sel ? fmt_strs[vidfmt_sel] : "automatic detection");
1071
1072         if (vid_input >= CX25840_COMPOSITE1 &&
1073             vid_input <= CX25840_COMPOSITE8) {
1074                 v4l_info(client, "Specified video input:     Composite %d\n",
1075                         vid_input - CX25840_COMPOSITE1 + 1);
1076         } else {
1077                 v4l_info(client, "Specified video input:     S-Video (Luma In%d, Chroma In%d)\n",
1078                         (vid_input & 0xf0) >> 4, (vid_input & 0xf00) >> 8);
1079         }
1080
1081         v4l_info(client, "Specified audioclock freq: %d Hz\n", state->audclk_freq);
1082 }
1083
1084 /* ----------------------------------------------------------------------- */
1085
1086 static void log_audio_status(struct i2c_client *client)
1087 {
1088         struct cx25840_state *state = i2c_get_clientdata(client);
1089         u8 download_ctl = cx25840_read(client, 0x803);
1090         u8 mod_det_stat0 = cx25840_read(client, 0x804);
1091         u8 mod_det_stat1 = cx25840_read(client, 0x805);
1092         u8 audio_config = cx25840_read(client, 0x808);
1093         u8 pref_mode = cx25840_read(client, 0x809);
1094         u8 afc0 = cx25840_read(client, 0x80b);
1095         u8 mute_ctl = cx25840_read(client, 0x8d3);
1096         int aud_input = state->aud_input;
1097         char *p;
1098
1099         switch (mod_det_stat0) {
1100         case 0x00: p = "mono"; break;
1101         case 0x01: p = "stereo"; break;
1102         case 0x02: p = "dual"; break;
1103         case 0x04: p = "tri"; break;
1104         case 0x10: p = "mono with SAP"; break;
1105         case 0x11: p = "stereo with SAP"; break;
1106         case 0x12: p = "dual with SAP"; break;
1107         case 0x14: p = "tri with SAP"; break;
1108         case 0xfe: p = "forced mode"; break;
1109         default: p = "not defined";
1110         }
1111         v4l_info(client, "Detected audio mode:       %s\n", p);
1112
1113         switch (mod_det_stat1) {
1114         case 0x00: p = "not defined"; break;
1115         case 0x01: p = "EIAJ"; break;
1116         case 0x02: p = "A2-M"; break;
1117         case 0x03: p = "A2-BG"; break;
1118         case 0x04: p = "A2-DK1"; break;
1119         case 0x05: p = "A2-DK2"; break;
1120         case 0x06: p = "A2-DK3"; break;
1121         case 0x07: p = "A1 (6.0 MHz FM Mono)"; break;
1122         case 0x08: p = "AM-L"; break;
1123         case 0x09: p = "NICAM-BG"; break;
1124         case 0x0a: p = "NICAM-DK"; break;
1125         case 0x0b: p = "NICAM-I"; break;
1126         case 0x0c: p = "NICAM-L"; break;
1127         case 0x0d: p = "BTSC/EIAJ/A2-M Mono (4.5 MHz FMMono)"; break;
1128         case 0x0e: p = "IF FM Radio"; break;
1129         case 0x0f: p = "BTSC"; break;
1130         case 0x10: p = "high-deviation FM"; break;
1131         case 0x11: p = "very high-deviation FM"; break;
1132         case 0xfd: p = "unknown audio standard"; break;
1133         case 0xfe: p = "forced audio standard"; break;
1134         case 0xff: p = "no detected audio standard"; break;
1135         default: p = "not defined";
1136         }
1137         v4l_info(client, "Detected audio standard:   %s\n", p);
1138         v4l_info(client, "Audio muted:               %s\n",
1139                     (mute_ctl & 0x2) ? "yes" : "no");
1140         v4l_info(client, "Audio microcontroller:     %s\n",
1141                     (download_ctl & 0x10) ? "running" : "stopped");
1142
1143         switch (audio_config >> 4) {
1144         case 0x00: p = "undefined"; break;
1145         case 0x01: p = "BTSC"; break;
1146         case 0x02: p = "EIAJ"; break;
1147         case 0x03: p = "A2-M"; break;
1148         case 0x04: p = "A2-BG"; break;
1149         case 0x05: p = "A2-DK1"; break;
1150         case 0x06: p = "A2-DK2"; break;
1151         case 0x07: p = "A2-DK3"; break;
1152         case 0x08: p = "A1 (6.0 MHz FM Mono)"; break;
1153         case 0x09: p = "AM-L"; break;
1154         case 0x0a: p = "NICAM-BG"; break;
1155         case 0x0b: p = "NICAM-DK"; break;
1156         case 0x0c: p = "NICAM-I"; break;
1157         case 0x0d: p = "NICAM-L"; break;
1158         case 0x0e: p = "FM radio"; break;
1159         case 0x0f: p = "automatic detection"; break;
1160         default: p = "undefined";
1161         }
1162         v4l_info(client, "Configured audio standard: %s\n", p);
1163
1164         if ((audio_config >> 4) < 0xF) {
1165                 switch (audio_config & 0xF) {
1166                 case 0x00: p = "MONO1 (LANGUAGE A/Mono L+R channel for BTSC, EIAJ, A2)"; break;
1167                 case 0x01: p = "MONO2 (LANGUAGE B)"; break;
1168                 case 0x02: p = "MONO3 (STEREO forced MONO)"; break;
1169                 case 0x03: p = "MONO4 (NICAM ANALOG-Language C/Analog Fallback)"; break;
1170                 case 0x04: p = "STEREO"; break;
1171                 case 0x05: p = "DUAL1 (AB)"; break;
1172                 case 0x06: p = "DUAL2 (AC) (FM)"; break;
1173                 case 0x07: p = "DUAL3 (BC) (FM)"; break;
1174                 case 0x08: p = "DUAL4 (AC) (AM)"; break;
1175                 case 0x09: p = "DUAL5 (BC) (AM)"; break;
1176                 case 0x0a: p = "SAP"; break;
1177                 default: p = "undefined";
1178                 }
1179                 v4l_info(client, "Configured audio mode:     %s\n", p);
1180         } else {
1181                 switch (audio_config & 0xF) {
1182                 case 0x00: p = "BG"; break;
1183                 case 0x01: p = "DK1"; break;
1184                 case 0x02: p = "DK2"; break;
1185                 case 0x03: p = "DK3"; break;
1186                 case 0x04: p = "I"; break;
1187                 case 0x05: p = "L"; break;
1188                 case 0x06: p = "BTSC"; break;
1189                 case 0x07: p = "EIAJ"; break;
1190                 case 0x08: p = "A2-M"; break;
1191                 case 0x09: p = "FM Radio"; break;
1192                 case 0x0f: p = "automatic standard and mode detection"; break;
1193                 default: p = "undefined";
1194                 }
1195                 v4l_info(client, "Configured audio system:   %s\n", p);
1196         }
1197
1198         if (aud_input) {
1199                 v4l_info(client, "Specified audio input:     Tuner (In%d)\n", aud_input);
1200         } else {
1201                 v4l_info(client, "Specified audio input:     External\n");
1202         }
1203
1204         switch (pref_mode & 0xf) {
1205         case 0: p = "mono/language A"; break;
1206         case 1: p = "language B"; break;
1207         case 2: p = "language C"; break;
1208         case 3: p = "analog fallback"; break;
1209         case 4: p = "stereo"; break;
1210         case 5: p = "language AC"; break;
1211         case 6: p = "language BC"; break;
1212         case 7: p = "language AB"; break;
1213         default: p = "undefined";
1214         }
1215         v4l_info(client, "Preferred audio mode:      %s\n", p);
1216
1217         if ((audio_config & 0xf) == 0xf) {
1218                 switch ((afc0 >> 3) & 0x3) {
1219                 case 0: p = "system DK"; break;
1220                 case 1: p = "system L"; break;
1221                 case 2: p = "autodetect"; break;
1222                 default: p = "undefined";
1223                 }
1224                 v4l_info(client, "Selected 65 MHz format:    %s\n", p);
1225
1226                 switch (afc0 & 0x7) {
1227                 case 0: p = "chroma"; break;
1228                 case 1: p = "BTSC"; break;
1229                 case 2: p = "EIAJ"; break;
1230                 case 3: p = "A2-M"; break;
1231                 case 4: p = "autodetect"; break;
1232                 default: p = "undefined";
1233                 }
1234                 v4l_info(client, "Selected 45 MHz format:    %s\n", p);
1235         }
1236 }