1 /* cx25840 - Conexant CX25840 audio/video decoder driver
3 * Copyright (C) 2004 Ulf Eklund
5 * Based on the saa7115 driver and on the first verison of Chris Kennedy's
8 * Changes by Tyler Trafford <tatrafford@comcast.net>
9 * - cleanup/rewrite for V4L2 API (2005)
11 * VBI support by Hans Verkuil <hverkuil@xs4all.nl>.
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.
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.
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.
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/audiochip.h>
35 #include <media/v4l2-common.h>
39 MODULE_DESCRIPTION("Conexant CX25840 audio/video decoder driver");
40 MODULE_AUTHOR("Ulf Eklund, Chris Kennedy, Hans Verkuil, Tyler Trafford");
41 MODULE_LICENSE("GPL");
43 static unsigned short normal_i2c
[] = { 0x88 >> 1, I2C_CLIENT_END
};
46 int cx25840_debug
= 0;
48 module_param(cx25840_debug
, bool, 0644);
50 MODULE_PARM_DESC(cx25840_debug
, "Debugging messages [0=Off (default) 1=On]");
54 /* ----------------------------------------------------------------------- */
56 int cx25840_write(struct i2c_client
*client
, u16 addr
, u8 value
)
59 buffer
[0] = addr
>> 8;
60 buffer
[1] = addr
& 0xff;
62 return i2c_master_send(client
, buffer
, 3);
65 int cx25840_write4(struct i2c_client
*client
, u16 addr
, u32 value
)
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);
77 u8
cx25840_read(struct i2c_client
* client
, u16 addr
)
80 buffer
[0] = addr
>> 8;
81 buffer
[1] = addr
& 0xff;
83 if (i2c_master_send(client
, buffer
, 2) < 2)
86 if (i2c_master_recv(client
, buffer
, 1) < 1)
92 u32
cx25840_read4(struct i2c_client
* client
, u16 addr
)
95 buffer
[0] = addr
>> 8;
96 buffer
[1] = addr
& 0xff;
98 if (i2c_master_send(client
, buffer
, 2) < 2)
101 if (i2c_master_recv(client
, buffer
, 4) < 4)
104 return (buffer
[0] << 24) | (buffer
[1] << 16) |
105 (buffer
[2] << 8) | buffer
[3];
108 int cx25840_and_or(struct i2c_client
*client
, u16 addr
, u8 and_mask
,
111 return cx25840_write(client
, addr
,
112 (cx25840_read(client
, addr
) & and_mask
) |
116 /* ----------------------------------------------------------------------- */
118 static int set_input(struct i2c_client
*, enum cx25840_input
);
119 static void input_change(struct i2c_client
*);
120 static void log_status(struct i2c_client
*client
);
122 /* ----------------------------------------------------------------------- */
124 static inline void init_dll1(struct i2c_client
*client
)
126 /* This is the Hauppauge sequence used to
127 * initialize the Delay Lock Loop 1 (ADC DLL). */
128 cx25840_write(client
, 0x159, 0x23);
129 cx25840_write(client
, 0x15a, 0x87);
130 cx25840_write(client
, 0x15b, 0x06);
131 cx25840_write(client
, 0x159, 0xe1);
132 cx25840_write(client
, 0x15a, 0x86);
133 cx25840_write(client
, 0x159, 0xe0);
134 cx25840_write(client
, 0x159, 0xe1);
135 cx25840_write(client
, 0x15b, 0x10);
138 static inline void init_dll2(struct i2c_client
*client
)
140 /* This is the Hauppauge sequence used to
141 * initialize the Delay Lock Loop 2 (ADC DLL). */
142 cx25840_write(client
, 0x15d, 0xe3);
143 cx25840_write(client
, 0x15e, 0x86);
144 cx25840_write(client
, 0x15f, 0x06);
145 cx25840_write(client
, 0x15d, 0xe1);
146 cx25840_write(client
, 0x15d, 0xe0);
147 cx25840_write(client
, 0x15d, 0xe1);
150 static void cx25840_initialize(struct i2c_client
*client
, int loadfw
)
152 struct cx25840_state
*state
= i2c_get_clientdata(client
);
154 /* datasheet startup in numbered steps, refer to page 3-77 */
156 cx25840_and_or(client
, 0x803, ~0x10, 0x00);
157 /* The default of this register should be 4, but I get 0 instead.
158 * Set this register to 4 manually. */
159 cx25840_write(client
, 0x000, 0x04);
163 cx25840_write(client
, 0x136, 0x0a);
165 cx25840_write(client
, 0x13c, 0x01);
166 cx25840_write(client
, 0x13c, 0x00);
169 cx25840_loadfw(client
);
171 cx25840_write(client
, 0x115, 0x8c);
172 cx25840_write(client
, 0x116, 0x07);
173 cx25840_write(client
, 0x118, 0x02);
175 cx25840_write(client
, 0x4a5, 0x80);
176 cx25840_write(client
, 0x4a5, 0x00);
177 cx25840_write(client
, 0x402, 0x00);
179 cx25840_write(client
, 0x401, 0x18);
180 cx25840_write(client
, 0x4a2, 0x10);
181 cx25840_write(client
, 0x402, 0x04);
183 cx25840_write(client
, 0x8d3, 0x1f);
184 cx25840_write(client
, 0x8e3, 0x03);
186 cx25840_vbi_setup(client
);
188 /* trial and error says these are needed to get audio */
189 cx25840_write(client
, 0x914, 0xa0);
190 cx25840_write(client
, 0x918, 0xa0);
191 cx25840_write(client
, 0x919, 0x01);
193 /* stereo prefered */
194 cx25840_write(client
, 0x809, 0x04);
196 cx25840_write(client
, 0x8cf, 0x0f);
198 /* (re)set video input */
199 set_input(client
, state
->input
);
200 /* (re)set audio input */
201 cx25840_audio(client
, AUDC_SET_INPUT
, &state
->audio_input
);
203 /* start microcontroller */
204 cx25840_and_or(client
, 0x803, ~0x10, 0x10);
207 /* ----------------------------------------------------------------------- */
209 static void input_change(struct i2c_client
*client
)
211 struct cx25840_state
*state
= i2c_get_clientdata(client
);
212 v4l2_std_id std
= cx25840_get_v4lstd(client
);
214 /* Note: perhaps V4L2_STD_PAL_M should be handled as V4L2_STD_NTSC
215 instead of V4L2_STD_PAL. Someone needs to test this. */
216 if (std
& V4L2_STD_PAL
) {
217 /* Follow tuner change procedure for PAL */
218 cx25840_write(client
, 0x808, 0xff);
219 cx25840_write(client
, 0x80b, 0x10);
220 } else if (std
& V4L2_STD_SECAM
) {
221 /* Select autodetect for SECAM */
222 cx25840_write(client
, 0x808, 0xff);
223 cx25840_write(client
, 0x80b, 0x10);
224 } else if (std
& V4L2_STD_NTSC
) {
226 if (state
->cardtype
== CARDTYPE_PVR150_WORKAROUND
) {
227 /* Certain Hauppauge PVR150 models have a hardware bug
228 that causes audio to drop out. For these models the
229 audio standard must be set explicitly.
230 To be precise: it affects cards with tuner models
231 85, 99 and 112 (model numbers from tveeprom). */
232 if (std
== V4L2_STD_NTSC_M_JP
) {
233 /* Japan uses EIAJ audio standard */
234 cx25840_write(client
, 0x808, 0x2f);
236 /* Others use the BTSC audio standard */
237 cx25840_write(client
, 0x808, 0x1f);
239 /* South Korea uses the A2-M (aka Zweiton M) audio
240 standard, and should set 0x808 to 0x3f, but I don't
241 know how to detect this. */
242 } else if (std
== V4L2_STD_NTSC_M_JP
) {
243 /* Japan uses EIAJ audio standard */
244 cx25840_write(client
, 0x808, 0xf7);
246 /* Others use the BTSC audio standard */
247 cx25840_write(client
, 0x808, 0xf6);
249 /* South Korea uses the A2-M (aka Zweiton M) audio standard,
250 and should set 0x808 to 0xf8, but I don't know how to
252 cx25840_write(client
, 0x80b, 0x00);
255 if (cx25840_read(client
, 0x803) & 0x10) {
256 /* restart audio decoder microcontroller */
257 cx25840_and_or(client
, 0x803, ~0x10, 0x00);
258 cx25840_and_or(client
, 0x803, ~0x10, 0x10);
262 static int set_input(struct i2c_client
*client
, enum cx25840_input input
)
264 struct cx25840_state
*state
= i2c_get_clientdata(client
);
266 cx25840_dbg("decoder set input (%d)\n", input
);
270 cx25840_dbg("now setting Tuner input\n");
272 if (state
->cardtype
== CARDTYPE_PVR150
||
273 state
->cardtype
== CARDTYPE_PVR150_WORKAROUND
) {
275 cx25840_and_or(client
, 0x102, ~0x2, 0x02);
278 /* Video Input Control */
279 if (state
->cardtype
== CARDTYPE_PG600
) {
280 cx25840_write(client
, 0x103, 0x11);
282 cx25840_write(client
, 0x103, 0x46);
286 cx25840_and_or(client
, 0x401, ~0x6, 0x00);
289 case CX25840_COMPOSITE0
:
290 case CX25840_COMPOSITE1
:
291 cx25840_dbg("now setting Composite input\n");
293 /* Video Input Control */
294 if (state
->cardtype
== CARDTYPE_PG600
) {
295 cx25840_write(client
, 0x103, 0x00);
297 cx25840_write(client
, 0x103, 0x02);
301 cx25840_and_or(client
, 0x401, ~0x6, 0x00);
304 case CX25840_SVIDEO0
:
305 case CX25840_SVIDEO1
:
306 cx25840_dbg("now setting S-Video input\n");
309 cx25840_and_or(client
, 0x102, ~0x2, 0x00);
311 /* Video Input Control */
312 if (state
->cardtype
== CARDTYPE_PG600
) {
313 cx25840_write(client
, 0x103, 0x02);
315 cx25840_write(client
, 0x103, 0x10);
319 cx25840_and_or(client
, 0x401, ~0x6, 0x02);
323 cx25840_err("%d is not a valid input!\n", input
);
327 state
->input
= input
;
328 input_change(client
);
332 /* ----------------------------------------------------------------------- */
334 static int set_v4lstd(struct i2c_client
*client
, v4l2_std_id std
)
336 u8 fmt
=0; /* zero is autodetect */
338 /* First tests should be against specific std */
339 if (std
& V4L2_STD_NTSC_M_JP
) {
341 } else if (std
& V4L2_STD_NTSC_443
) {
343 } else if (std
& V4L2_STD_PAL_M
) {
345 } else if (std
& V4L2_STD_PAL_N
) {
347 } else if (std
& V4L2_STD_PAL_Nc
) {
349 } else if (std
& V4L2_STD_PAL_60
) {
352 /* Then, test against generic ones */
353 if (std
& V4L2_STD_NTSC
) {
355 } else if (std
& V4L2_STD_PAL
) {
357 } else if (std
& V4L2_STD_SECAM
) {
362 cx25840_and_or(client
, 0x400, ~0xf, fmt
);
363 cx25840_vbi_setup(client
);
367 v4l2_std_id
cx25840_get_v4lstd(struct i2c_client
* client
)
369 /* check VID_FMT_SEL first */
370 u8 fmt
= cx25840_read(client
, 0x400) & 0xf;
373 /* check AFD_FMT_STAT if set to autodetect */
374 fmt
= cx25840_read(client
, 0x40d) & 0xf;
378 case 0x1: return V4L2_STD_NTSC_M
;
379 case 0x2: return V4L2_STD_NTSC_M_JP
;
380 case 0x3: return V4L2_STD_NTSC_443
;
381 case 0x4: return V4L2_STD_PAL
;
382 case 0x5: return V4L2_STD_PAL_M
;
383 case 0x6: return V4L2_STD_PAL_N
;
384 case 0x7: return V4L2_STD_PAL_Nc
;
385 case 0x8: return V4L2_STD_PAL_60
;
386 case 0xc: return V4L2_STD_SECAM
;
387 default: return V4L2_STD_UNKNOWN
;
391 /* ----------------------------------------------------------------------- */
393 static int set_v4lctrl(struct i2c_client
*client
, struct v4l2_control
*ctrl
)
395 struct cx25840_state
*state
= i2c_get_clientdata(client
);
398 case CX25840_CID_CARDTYPE
:
399 switch (ctrl
->value
) {
400 case CARDTYPE_PVR150
:
401 case CARDTYPE_PVR150_WORKAROUND
:
403 state
->cardtype
= ctrl
->value
;
409 set_input(client
, state
->input
);
412 case V4L2_CID_BRIGHTNESS
:
413 if (ctrl
->value
< 0 || ctrl
->value
> 255) {
414 cx25840_err("invalid brightness setting %d\n",
419 cx25840_write(client
, 0x414, ctrl
->value
- 128);
422 case V4L2_CID_CONTRAST
:
423 if (ctrl
->value
< 0 || ctrl
->value
> 127) {
424 cx25840_err("invalid contrast setting %d\n",
429 cx25840_write(client
, 0x415, ctrl
->value
<< 1);
432 case V4L2_CID_SATURATION
:
433 if (ctrl
->value
< 0 || ctrl
->value
> 127) {
434 cx25840_err("invalid saturation setting %d\n",
439 cx25840_write(client
, 0x420, ctrl
->value
<< 1);
440 cx25840_write(client
, 0x421, ctrl
->value
<< 1);
444 if (ctrl
->value
< -127 || ctrl
->value
> 127) {
445 cx25840_err("invalid hue setting %d\n", ctrl
->value
);
449 cx25840_write(client
, 0x422, ctrl
->value
);
452 case V4L2_CID_AUDIO_VOLUME
:
453 case V4L2_CID_AUDIO_BASS
:
454 case V4L2_CID_AUDIO_TREBLE
:
455 case V4L2_CID_AUDIO_BALANCE
:
456 case V4L2_CID_AUDIO_MUTE
:
457 return cx25840_audio(client
, VIDIOC_S_CTRL
, ctrl
);
463 static int get_v4lctrl(struct i2c_client
*client
, struct v4l2_control
*ctrl
)
465 struct cx25840_state
*state
= i2c_get_clientdata(client
);
468 case CX25840_CID_CARDTYPE
:
469 ctrl
->value
= state
->cardtype
;
471 case V4L2_CID_BRIGHTNESS
:
472 ctrl
->value
= cx25840_read(client
, 0x414) + 128;
474 case V4L2_CID_CONTRAST
:
475 ctrl
->value
= cx25840_read(client
, 0x415) >> 1;
477 case V4L2_CID_SATURATION
:
478 ctrl
->value
= cx25840_read(client
, 0x420) >> 1;
481 ctrl
->value
= cx25840_read(client
, 0x422);
483 case V4L2_CID_AUDIO_VOLUME
:
484 case V4L2_CID_AUDIO_BASS
:
485 case V4L2_CID_AUDIO_TREBLE
:
486 case V4L2_CID_AUDIO_BALANCE
:
487 case V4L2_CID_AUDIO_MUTE
:
488 return cx25840_audio(client
, VIDIOC_G_CTRL
, ctrl
);
496 /* ----------------------------------------------------------------------- */
498 static int get_v4lfmt(struct i2c_client
*client
, struct v4l2_format
*fmt
)
501 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
502 return cx25840_vbi(client
, VIDIOC_G_FMT
, fmt
);
510 static int set_v4lfmt(struct i2c_client
*client
, struct v4l2_format
*fmt
)
512 struct v4l2_pix_format
*pix
;
513 int HSC
, VSC
, Vsrc
, Hsrc
, filter
, Vlines
;
514 int is_pal
= !(cx25840_get_v4lstd(client
) & V4L2_STD_NTSC
);
517 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
518 pix
= &(fmt
->fmt
.pix
);
520 Vsrc
= (cx25840_read(client
, 0x476) & 0x3f) << 4;
521 Vsrc
|= (cx25840_read(client
, 0x475) & 0xf0) >> 4;
523 Hsrc
= (cx25840_read(client
, 0x472) & 0x3f) << 4;
524 Hsrc
|= (cx25840_read(client
, 0x471) & 0xf0) >> 4;
526 Vlines
= pix
->height
+ (is_pal
? 4 : 7);
528 if ((pix
->width
* 16 < Hsrc
) || (Hsrc
< pix
->width
) ||
529 (Vlines
* 8 < Vsrc
) || (Vsrc
< Vlines
)) {
530 cx25840_err("%dx%d is not a valid size!\n",
531 pix
->width
, pix
->height
);
535 HSC
= (Hsrc
* (1 << 20)) / pix
->width
- (1 << 20);
536 VSC
= (1 << 16) - (Vsrc
* (1 << 9) / Vlines
- (1 << 9));
539 if (pix
->width
>= 385)
541 else if (pix
->width
> 192)
543 else if (pix
->width
> 96)
548 cx25840_dbg("decoder set size %dx%d -> scale %ux%u\n",
549 pix
->width
, pix
->height
, HSC
, VSC
);
552 cx25840_write(client
, 0x418, HSC
& 0xff);
553 cx25840_write(client
, 0x419, (HSC
>> 8) & 0xff);
554 cx25840_write(client
, 0x41a, HSC
>> 16);
556 cx25840_write(client
, 0x41c, VSC
& 0xff);
557 cx25840_write(client
, 0x41d, VSC
>> 8);
558 /* VS_INTRLACE=1 VFILT=filter */
559 cx25840_write(client
, 0x41e, 0x8 | filter
);
562 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
563 return cx25840_vbi(client
, VIDIOC_S_FMT
, fmt
);
565 case V4L2_BUF_TYPE_VBI_CAPTURE
:
566 return cx25840_vbi(client
, VIDIOC_S_FMT
, fmt
);
575 /* ----------------------------------------------------------------------- */
577 static int cx25840_command(struct i2c_client
*client
, unsigned int cmd
,
580 struct cx25840_state
*state
= i2c_get_clientdata(client
);
581 struct v4l2_tuner
*vt
= arg
;
588 #ifdef CONFIG_VIDEO_ADV_DEBUG
589 /* ioctls to allow direct access to the
590 * cx25840 registers for testing */
591 case VIDIOC_INT_G_REGISTER
:
593 struct v4l2_register
*reg
= arg
;
595 if (reg
->i2c_id
!= I2C_DRIVERID_CX25840
)
597 reg
->val
= cx25840_read(client
, reg
->reg
& 0x0fff);
601 case VIDIOC_INT_S_REGISTER
:
603 struct v4l2_register
*reg
= arg
;
605 if (reg
->i2c_id
!= I2C_DRIVERID_CX25840
)
607 if (!capable(CAP_SYS_ADMIN
))
609 cx25840_write(client
, reg
->reg
& 0x0fff, reg
->val
& 0xff);
614 case VIDIOC_INT_DECODE_VBI_LINE
:
615 return cx25840_vbi(client
, cmd
, arg
);
617 case VIDIOC_INT_AUDIO_CLOCK_FREQ
:
619 result
= cx25840_audio(client
, cmd
, arg
);
622 case VIDIOC_STREAMON
:
623 cx25840_dbg("enable output\n");
624 cx25840_write(client
, 0x115, 0x8c);
625 cx25840_write(client
, 0x116, 0x07);
628 case VIDIOC_STREAMOFF
:
629 cx25840_dbg("disable output\n");
630 cx25840_write(client
, 0x115, 0x00);
631 cx25840_write(client
, 0x116, 0x00);
634 case VIDIOC_LOG_STATUS
:
639 result
= get_v4lctrl(client
, (struct v4l2_control
*)arg
);
643 result
= set_v4lctrl(client
, (struct v4l2_control
*)arg
);
647 *(v4l2_std_id
*)arg
= cx25840_get_v4lstd(client
);
651 result
= set_v4lstd(client
, *(v4l2_std_id
*)arg
);
655 *(int *)arg
= state
->input
;
659 result
= set_input(client
, *(int *)arg
);
662 case VIDIOC_S_FREQUENCY
:
663 input_change(client
);
668 u8 mode
= cx25840_read(client
, 0x804);
669 u8 pref
= cx25840_read(client
, 0x809) & 0xf;
670 u8 vpres
= cx25840_read(client
, 0x80a) & 0x10;
674 V4L2_TUNER_CAP_STEREO
| V4L2_TUNER_CAP_LANG1
|
675 V4L2_TUNER_CAP_LANG2
| V4L2_TUNER_CAP_SAP
;
677 vt
->signal
= vpres
? 0xffff : 0x0;
679 /* get rxsubchans and audmode */
680 if ((mode
& 0xf) == 1)
681 val
|= V4L2_TUNER_SUB_STEREO
;
683 val
|= V4L2_TUNER_SUB_MONO
;
685 if (mode
== 2 || mode
== 4)
686 val
|= V4L2_TUNER_SUB_LANG1
| V4L2_TUNER_SUB_LANG2
;
689 val
|= V4L2_TUNER_SUB_SAP
;
691 vt
->rxsubchans
= val
;
695 vt
->audmode
= V4L2_TUNER_MODE_MONO
;
699 vt
->audmode
= V4L2_TUNER_MODE_LANG2
;
703 vt
->audmode
= V4L2_TUNER_MODE_STEREO
;
709 switch (vt
->audmode
) {
710 case V4L2_TUNER_MODE_MONO
:
711 case V4L2_TUNER_MODE_LANG1
:
712 /* Force PREF_MODE to MONO */
713 cx25840_and_or(client
, 0x809, ~0xf, 0x00);
715 case V4L2_TUNER_MODE_STEREO
:
716 /* Force PREF_MODE to STEREO */
717 cx25840_and_or(client
, 0x809, ~0xf, 0x04);
719 case V4L2_TUNER_MODE_LANG2
:
720 /* Force PREF_MODE to LANG2 */
721 cx25840_and_or(client
, 0x809, ~0xf, 0x01);
727 result
= get_v4lfmt(client
, (struct v4l2_format
*)arg
);
731 result
= set_v4lfmt(client
, (struct v4l2_format
*)arg
);
734 case VIDIOC_INT_RESET
:
735 cx25840_initialize(client
, 0);
738 case VIDIOC_INT_G_CHIP_IDENT
:
739 *(enum v4l2_chip_ident
*)arg
=
740 V4L2_IDENT_CX25840
+ ((cx25840_read(client
, 0x100) >> 4) & 0xf);
744 cx25840_err("invalid ioctl %x\n", cmd
);
751 /* ----------------------------------------------------------------------- */
753 static struct i2c_driver i2c_driver_cx25840
;
755 static int cx25840_detect_client(struct i2c_adapter
*adapter
, int address
,
758 struct i2c_client
*client
;
759 struct cx25840_state
*state
;
762 /* Check if the adapter supports the needed features
763 * Not until kernel version 2.6.11 did the bit-algo
764 * correctly report that it would do an I2C-level xfer */
765 if (!i2c_check_functionality(adapter
, I2C_FUNC_I2C
))
768 client
= kmalloc(sizeof(struct i2c_client
), GFP_KERNEL
);
772 memset(client
, 0, sizeof(struct i2c_client
));
773 client
->addr
= address
;
774 client
->adapter
= adapter
;
775 client
->driver
= &i2c_driver_cx25840
;
776 snprintf(client
->name
, sizeof(client
->name
) - 1, "cx25840");
778 cx25840_dbg("detecting cx25840 client on address 0x%x\n", address
<< 1);
780 device_id
= cx25840_read(client
, 0x101) << 8;
781 device_id
|= cx25840_read(client
, 0x100);
783 /* The high byte of the device ID should be
784 * 0x84 if chip is present */
785 if ((device_id
& 0xff00) != 0x8400) {
786 cx25840_dbg("cx25840 not found\n");
791 cx25840_info("cx25%3x-2%x found @ 0x%x (%s)\n",
792 (device_id
& 0xfff0) >> 4,
793 (device_id
& 0x0f) < 3 ? (device_id
& 0x0f) + 1 : 3,
794 address
<< 1, adapter
->name
);
796 state
= kmalloc(sizeof(struct cx25840_state
), GFP_KERNEL
);
802 i2c_set_clientdata(client
, state
);
803 memset(state
, 0, sizeof(struct cx25840_state
));
804 state
->input
= CX25840_TUNER
;
805 state
->audclk_freq
= V4L2_AUDCLK_48_KHZ
;
806 state
->audio_input
= AUDIO_TUNER
;
807 state
->cardtype
= CARDTYPE_PVR150
;
809 cx25840_initialize(client
, 1);
811 i2c_attach_client(client
);
816 static int cx25840_attach_adapter(struct i2c_adapter
*adapter
)
818 #ifdef I2C_CLASS_TV_ANALOG
819 if (adapter
->class & I2C_CLASS_TV_ANALOG
)
821 if (adapter
->id
== I2C_HW_B_BT848
)
823 return i2c_probe(adapter
, &addr_data
, &cx25840_detect_client
);
827 static int cx25840_detach_client(struct i2c_client
*client
)
829 struct cx25840_state
*state
= i2c_get_clientdata(client
);
832 err
= i2c_detach_client(client
);
843 /* ----------------------------------------------------------------------- */
845 static struct i2c_driver i2c_driver_cx25840
= {
848 .id
= I2C_DRIVERID_CX25840
,
850 .attach_adapter
= cx25840_attach_adapter
,
851 .detach_client
= cx25840_detach_client
,
852 .command
= cx25840_command
,
853 .owner
= THIS_MODULE
,
857 static int __init
m__init(void)
859 return i2c_add_driver(&i2c_driver_cx25840
);
862 static void __exit
m__exit(void)
864 i2c_del_driver(&i2c_driver_cx25840
);
867 module_init(m__init
);
868 module_exit(m__exit
);
870 /* ----------------------------------------------------------------------- */
872 static void log_status(struct i2c_client
*client
)
874 static const char *const fmt_strs
[] = {
876 "NTSC-M", "NTSC-J", "NTSC-4.43",
877 "PAL-BDGHI", "PAL-M", "PAL-N", "PAL-Nc", "PAL-60",
883 struct cx25840_state
*state
= i2c_get_clientdata(client
);
884 u8 microctrl_vidfmt
= cx25840_read(client
, 0x80a);
885 u8 vidfmt_sel
= cx25840_read(client
, 0x400) & 0xf;
886 u8 gen_stat1
= cx25840_read(client
, 0x40d);
887 u8 download_ctl
= cx25840_read(client
, 0x803);
888 u8 mod_det_stat0
= cx25840_read(client
, 0x804);
889 u8 mod_det_stat1
= cx25840_read(client
, 0x805);
890 u8 audio_config
= cx25840_read(client
, 0x808);
891 u8 pref_mode
= cx25840_read(client
, 0x809);
892 u8 afc0
= cx25840_read(client
, 0x80b);
893 u8 mute_ctl
= cx25840_read(client
, 0x8d3);
896 cx25840_info("Video signal: %spresent\n",
897 (microctrl_vidfmt
& 0x10) ? "" : "not ");
898 cx25840_info("Detected format: %s\n",
899 fmt_strs
[gen_stat1
& 0xf]);
901 switch (mod_det_stat0
) {
902 case 0x00: p
= "mono"; break;
903 case 0x01: p
= "stereo"; break;
904 case 0x02: p
= "dual"; break;
905 case 0x04: p
= "tri"; break;
906 case 0x10: p
= "mono with SAP"; break;
907 case 0x11: p
= "stereo with SAP"; break;
908 case 0x12: p
= "dual with SAP"; break;
909 case 0x14: p
= "tri with SAP"; break;
910 case 0xfe: p
= "forced mode"; break;
911 default: p
= "not defined";
913 cx25840_info("Detected audio mode: %s\n", p
);
915 switch (mod_det_stat1
) {
916 case 0x00: p
= "not defined"; break;
917 case 0x01: p
= "EIAJ"; break;
918 case 0x02: p
= "A2-M"; break;
919 case 0x03: p
= "A2-BG"; break;
920 case 0x04: p
= "A2-DK1"; break;
921 case 0x05: p
= "A2-DK2"; break;
922 case 0x06: p
= "A2-DK3"; break;
923 case 0x07: p
= "A1 (6.0 MHz FM Mono)"; break;
924 case 0x08: p
= "AM-L"; break;
925 case 0x09: p
= "NICAM-BG"; break;
926 case 0x0a: p
= "NICAM-DK"; break;
927 case 0x0b: p
= "NICAM-I"; break;
928 case 0x0c: p
= "NICAM-L"; break;
929 case 0x0d: p
= "BTSC/EIAJ/A2-M Mono (4.5 MHz FMMono)"; break;
930 case 0x0e: p
= "IF FM Radio"; break;
931 case 0x0f: p
= "BTSC"; break;
932 case 0x10: p
= "high-deviation FM"; break;
933 case 0x11: p
= "very high-deviation FM"; break;
934 case 0xfd: p
= "unknown audio standard"; break;
935 case 0xfe: p
= "forced audio standard"; break;
936 case 0xff: p
= "no detected audio standard"; break;
937 default: p
= "not defined";
939 cx25840_info("Detected audio standard: %s\n", p
);
940 cx25840_info("Audio muted: %s\n",
941 (mute_ctl
& 0x2) ? "yes" : "no");
942 cx25840_info("Audio microcontroller: %s\n",
943 (download_ctl
& 0x10) ? "running" : "stopped");
945 switch (audio_config
>> 4) {
946 case 0x00: p
= "undefined"; break;
947 case 0x01: p
= "BTSC"; break;
948 case 0x02: p
= "EIAJ"; break;
949 case 0x03: p
= "A2-M"; break;
950 case 0x04: p
= "A2-BG"; break;
951 case 0x05: p
= "A2-DK1"; break;
952 case 0x06: p
= "A2-DK2"; break;
953 case 0x07: p
= "A2-DK3"; break;
954 case 0x08: p
= "A1 (6.0 MHz FM Mono)"; break;
955 case 0x09: p
= "AM-L"; break;
956 case 0x0a: p
= "NICAM-BG"; break;
957 case 0x0b: p
= "NICAM-DK"; break;
958 case 0x0c: p
= "NICAM-I"; break;
959 case 0x0d: p
= "NICAM-L"; break;
960 case 0x0e: p
= "FM radio"; break;
961 case 0x0f: p
= "automatic detection"; break;
962 default: p
= "undefined";
964 cx25840_info("Configured audio standard: %s\n", p
);
966 if ((audio_config
>> 4) < 0xF) {
967 switch (audio_config
& 0xF) {
968 case 0x00: p
= "MONO1 (LANGUAGE A/Mono L+R channel for BTSC, EIAJ, A2)"; break;
969 case 0x01: p
= "MONO2 (LANGUAGE B)"; break;
970 case 0x02: p
= "MONO3 (STEREO forced MONO)"; break;
971 case 0x03: p
= "MONO4 (NICAM ANALOG-Language C/Analog Fallback)"; break;
972 case 0x04: p
= "STEREO"; break;
973 case 0x05: p
= "DUAL1 (AB)"; break;
974 case 0x06: p
= "DUAL2 (AC) (FM)"; break;
975 case 0x07: p
= "DUAL3 (BC) (FM)"; break;
976 case 0x08: p
= "DUAL4 (AC) (AM)"; break;
977 case 0x09: p
= "DUAL5 (BC) (AM)"; break;
978 case 0x0a: p
= "SAP"; break;
979 default: p
= "undefined";
981 cx25840_info("Configured audio mode: %s\n", p
);
983 switch (audio_config
& 0xF) {
984 case 0x00: p
= "BG"; break;
985 case 0x01: p
= "DK1"; break;
986 case 0x02: p
= "DK2"; break;
987 case 0x03: p
= "DK3"; break;
988 case 0x04: p
= "I"; break;
989 case 0x05: p
= "L"; break;
990 case 0x06: p
= "BTSC"; break;
991 case 0x07: p
= "EIAJ"; break;
992 case 0x08: p
= "A2-M"; break;
993 case 0x09: p
= "FM Radio"; break;
994 case 0x0f: p
= "automatic standard and mode detection"; break;
995 default: p
= "undefined";
997 cx25840_info("Configured audio system: %s\n", p
);
1000 cx25840_info("Specified standard: %s\n",
1001 vidfmt_sel
? fmt_strs
[vidfmt_sel
] : "automatic detection");
1003 switch (state
->input
) {
1004 case CX25840_COMPOSITE0
: p
= "Composite 0"; break;
1005 case CX25840_COMPOSITE1
: p
= "Composite 1"; break;
1006 case CX25840_SVIDEO0
: p
= "S-Video 0"; break;
1007 case CX25840_SVIDEO1
: p
= "S-Video 1"; break;
1008 case CX25840_TUNER
: p
= "Tuner"; break;
1010 cx25840_info("Specified input: %s\n", p
);
1011 cx25840_info("Specified audio input: %s\n",
1012 state
->audio_input
== 0 ? "Tuner" : "External");
1014 switch (state
->audclk_freq
) {
1015 case V4L2_AUDCLK_441_KHZ
: p
= "44.1 kHz"; break;
1016 case V4L2_AUDCLK_48_KHZ
: p
= "48 kHz"; break;
1017 case V4L2_AUDCLK_32_KHZ
: p
= "32 kHz"; break;
1018 default: p
= "undefined";
1020 cx25840_info("Specified audioclock freq: %s\n", p
);
1022 switch (pref_mode
& 0xf) {
1023 case 0: p
= "mono/language A"; break;
1024 case 1: p
= "language B"; break;
1025 case 2: p
= "language C"; break;
1026 case 3: p
= "analog fallback"; break;
1027 case 4: p
= "stereo"; break;
1028 case 5: p
= "language AC"; break;
1029 case 6: p
= "language BC"; break;
1030 case 7: p
= "language AB"; break;
1031 default: p
= "undefined";
1033 cx25840_info("Preferred audio mode: %s\n", p
);
1035 if ((audio_config
& 0xf) == 0xf) {
1036 switch ((afc0
>> 3) & 0x3) {
1037 case 0: p
= "system DK"; break;
1038 case 1: p
= "system L"; break;
1039 case 2: p
= "autodetect"; break;
1040 default: p
= "undefined";
1042 cx25840_info("Selected 65 MHz format: %s\n", p
);
1044 switch (afc0
& 0x7) {
1045 case 0: p
= "chroma"; break;
1046 case 1: p
= "BTSC"; break;
1047 case 2: p
= "EIAJ"; break;
1048 case 3: p
= "A2-M"; break;
1049 case 4: p
= "autodetect"; break;
1050 default: p
= "undefined";
1052 cx25840_info("Selected 45 MHz format: %s\n", p
);