2 * Driver for simple i2c audio chips.
4 * Copyright (c) 2000 Gerd Knorr
6 * Eric Sandeen (eric_sandeen@bigfoot.com)
7 * Steve VanDeBogart (vandebo@uclink.berkeley.edu)
8 * Greg Alexander (galexand@acm.org)
10 * For the TDA9875 part:
11 * Copyright (c) 2000 Guillaume Delvit based on Gerd Knorr source
14 * Copyright(c) 2005-2008 Mauro Carvalho Chehab
15 * - Some cleanups, code fixes, etc
16 * - Convert it to V4L2 API
18 * This code is placed under the terms of the GNU General Public License
21 * debug - set to 1 if you'd like to see debug messages
25 #include <linux/module.h>
26 #include <linux/kernel.h>
27 #include <linux/sched.h>
28 #include <linux/string.h>
29 #include <linux/timer.h>
30 #include <linux/delay.h>
31 #include <linux/errno.h>
32 #include <linux/slab.h>
33 #include <linux/videodev2.h>
34 #include <linux/i2c.h>
35 #include <linux/init.h>
36 #include <linux/kthread.h>
37 #include <linux/freezer.h>
39 #include <media/i2c/tvaudio.h>
40 #include <media/v4l2-device.h>
41 #include <media/v4l2-ctrls.h>
43 /* ---------------------------------------------------------------------- */
46 static int debug
; /* insmod parameter */
47 module_param(debug
, int, 0644);
49 MODULE_DESCRIPTION("device driver for various i2c TV sound decoder / audiomux chips");
50 MODULE_AUTHOR("Eric Sandeen, Steve VanDeBogart, Greg Alexander, Gerd Knorr");
51 MODULE_LICENSE("GPL");
55 /* ---------------------------------------------------------------------- */
61 typedef int (*getvalue
)(int);
62 typedef int (*checkit
)(struct CHIPSTATE
*);
63 typedef int (*initialize
)(struct CHIPSTATE
*);
64 typedef int (*getrxsubchans
)(struct CHIPSTATE
*);
65 typedef void (*setaudmode
)(struct CHIPSTATE
*, int mode
);
68 typedef struct AUDIOCMD
{
69 int count
; /* # of bytes to send */
70 unsigned char bytes
[MAXREGS
+1]; /* addr, data, data, ... */
73 /* chip description */
75 char *name
; /* chip name */
76 int addr_lo
, addr_hi
; /* i2c address range */
77 int registers
; /* # of registers */
81 initialize initialize
;
83 #define CHIP_HAS_VOLUME 1
84 #define CHIP_HAS_BASSTREBLE 2
85 #define CHIP_HAS_INPUTSEL 4
86 #define CHIP_NEED_CHECKMODE 8
88 /* various i2c command sequences */
91 /* which register has which value */
92 int leftreg
, rightreg
, treblereg
, bassreg
;
94 /* initialize with (defaults to 65535/32768/32768 */
95 int volinit
, trebleinit
, bassinit
;
97 /* functions to convert the values (v4l -> chip) */
98 getvalue volfunc
, treblefunc
, bassfunc
;
101 getrxsubchans getrxsubchans
;
102 setaudmode setaudmode
;
104 /* input switch register + values for v4l inputs */
111 /* current state of the chip */
113 struct v4l2_subdev sd
;
114 struct v4l2_ctrl_handler hdl
;
116 /* volume/balance cluster */
117 struct v4l2_ctrl
*volume
;
118 struct v4l2_ctrl
*balance
;
121 /* chip-specific description - should point to
122 an entry at CHIPDESC table */
123 struct CHIPDESC
*desc
;
125 /* shadow register set */
128 /* current settings */
135 struct task_struct
*thread
;
136 struct timer_list wt
;
140 static inline struct CHIPSTATE
*to_state(struct v4l2_subdev
*sd
)
142 return container_of(sd
, struct CHIPSTATE
, sd
);
145 static inline struct v4l2_subdev
*to_sd(struct v4l2_ctrl
*ctrl
)
147 return &container_of(ctrl
->handler
, struct CHIPSTATE
, hdl
)->sd
;
151 /* ---------------------------------------------------------------------- */
152 /* i2c I/O functions */
154 static int chip_write(struct CHIPSTATE
*chip
, int subaddr
, int val
)
156 struct v4l2_subdev
*sd
= &chip
->sd
;
157 struct i2c_client
*c
= v4l2_get_subdevdata(sd
);
158 unsigned char buffer
[2];
161 v4l2_dbg(1, debug
, sd
, "chip_write: 0x%x\n", val
);
162 chip
->shadow
.bytes
[1] = val
;
164 if (1 != i2c_master_send(c
, buffer
, 1)) {
165 v4l2_warn(sd
, "I/O error (write 0x%x)\n", val
);
169 if (subaddr
+ 1 >= ARRAY_SIZE(chip
->shadow
.bytes
)) {
171 "Tried to access a non-existent register: %d\n",
176 v4l2_dbg(1, debug
, sd
, "chip_write: reg%d=0x%x\n",
178 chip
->shadow
.bytes
[subaddr
+1] = val
;
181 if (2 != i2c_master_send(c
, buffer
, 2)) {
182 v4l2_warn(sd
, "I/O error (write reg%d=0x%x)\n",
190 static int chip_write_masked(struct CHIPSTATE
*chip
,
191 int subaddr
, int val
, int mask
)
193 struct v4l2_subdev
*sd
= &chip
->sd
;
197 val
= (chip
->shadow
.bytes
[1] & ~mask
) | (val
& mask
);
199 if (subaddr
+ 1 >= ARRAY_SIZE(chip
->shadow
.bytes
)) {
201 "Tried to access a non-existent register: %d\n",
206 val
= (chip
->shadow
.bytes
[subaddr
+1] & ~mask
) | (val
& mask
);
209 return chip_write(chip
, subaddr
, val
);
212 static int chip_read(struct CHIPSTATE
*chip
)
214 struct v4l2_subdev
*sd
= &chip
->sd
;
215 struct i2c_client
*c
= v4l2_get_subdevdata(sd
);
216 unsigned char buffer
;
218 if (1 != i2c_master_recv(c
, &buffer
, 1)) {
219 v4l2_warn(sd
, "I/O error (read)\n");
222 v4l2_dbg(1, debug
, sd
, "chip_read: 0x%x\n", buffer
);
226 static int chip_read2(struct CHIPSTATE
*chip
, int subaddr
)
228 struct v4l2_subdev
*sd
= &chip
->sd
;
229 struct i2c_client
*c
= v4l2_get_subdevdata(sd
);
230 unsigned char write
[1];
231 unsigned char read
[1];
232 struct i2c_msg msgs
[2] = {
248 if (2 != i2c_transfer(c
->adapter
, msgs
, 2)) {
249 v4l2_warn(sd
, "I/O error (read2)\n");
252 v4l2_dbg(1, debug
, sd
, "chip_read2: reg%d=0x%x\n",
257 static int chip_cmd(struct CHIPSTATE
*chip
, char *name
, audiocmd
*cmd
)
259 struct v4l2_subdev
*sd
= &chip
->sd
;
260 struct i2c_client
*c
= v4l2_get_subdevdata(sd
);
266 if (cmd
->count
+ cmd
->bytes
[0] - 1 >= ARRAY_SIZE(chip
->shadow
.bytes
)) {
268 "Tried to access a non-existent register range: %d to %d\n",
269 cmd
->bytes
[0] + 1, cmd
->bytes
[0] + cmd
->count
- 1);
273 /* FIXME: it seems that the shadow bytes are wrong below !*/
275 /* update our shadow register set; print bytes if (debug > 0) */
276 v4l2_dbg(1, debug
, sd
, "chip_cmd(%s): reg=%d, data:",
277 name
, cmd
->bytes
[0]);
278 for (i
= 1; i
< cmd
->count
; i
++) {
280 printk(KERN_CONT
" 0x%x", cmd
->bytes
[i
]);
281 chip
->shadow
.bytes
[i
+cmd
->bytes
[0]] = cmd
->bytes
[i
];
284 printk(KERN_CONT
"\n");
286 /* send data to the chip */
287 if (cmd
->count
!= i2c_master_send(c
, cmd
->bytes
, cmd
->count
)) {
288 v4l2_warn(sd
, "I/O error (%s)\n", name
);
294 /* ---------------------------------------------------------------------- */
295 /* kernel thread for doing i2c stuff asyncronly
296 * right now it is used only to check the audio mode (mono/stereo/whatever)
297 * some time after switching to another TV channel, then turn on stereo
301 static void chip_thread_wake(struct timer_list
*t
)
303 struct CHIPSTATE
*chip
= from_timer(chip
, t
, wt
);
304 wake_up_process(chip
->thread
);
307 static int chip_thread(void *data
)
309 struct CHIPSTATE
*chip
= data
;
310 struct CHIPDESC
*desc
= chip
->desc
;
311 struct v4l2_subdev
*sd
= &chip
->sd
;
314 v4l2_dbg(1, debug
, sd
, "thread started\n");
317 set_current_state(TASK_INTERRUPTIBLE
);
318 if (!kthread_should_stop())
320 set_current_state(TASK_RUNNING
);
322 if (kthread_should_stop())
324 v4l2_dbg(1, debug
, sd
, "thread wakeup\n");
326 /* don't do anything for radio */
330 /* have a look what's going on */
331 mode
= desc
->getrxsubchans(chip
);
332 if (mode
== chip
->prevmode
)
335 /* chip detected a new audio mode - set it */
336 v4l2_dbg(1, debug
, sd
, "thread checkmode\n");
338 chip
->prevmode
= mode
;
340 selected
= V4L2_TUNER_MODE_MONO
;
341 switch (chip
->audmode
) {
342 case V4L2_TUNER_MODE_MONO
:
343 if (mode
& V4L2_TUNER_SUB_LANG1
)
344 selected
= V4L2_TUNER_MODE_LANG1
;
346 case V4L2_TUNER_MODE_STEREO
:
347 case V4L2_TUNER_MODE_LANG1
:
348 if (mode
& V4L2_TUNER_SUB_LANG1
)
349 selected
= V4L2_TUNER_MODE_LANG1
;
350 else if (mode
& V4L2_TUNER_SUB_STEREO
)
351 selected
= V4L2_TUNER_MODE_STEREO
;
353 case V4L2_TUNER_MODE_LANG2
:
354 if (mode
& V4L2_TUNER_SUB_LANG2
)
355 selected
= V4L2_TUNER_MODE_LANG2
;
356 else if (mode
& V4L2_TUNER_SUB_STEREO
)
357 selected
= V4L2_TUNER_MODE_STEREO
;
359 case V4L2_TUNER_MODE_LANG1_LANG2
:
360 if (mode
& V4L2_TUNER_SUB_LANG2
)
361 selected
= V4L2_TUNER_MODE_LANG1_LANG2
;
362 else if (mode
& V4L2_TUNER_SUB_STEREO
)
363 selected
= V4L2_TUNER_MODE_STEREO
;
365 desc
->setaudmode(chip
, selected
);
367 /* schedule next check */
368 mod_timer(&chip
->wt
, jiffies
+msecs_to_jiffies(2000));
371 v4l2_dbg(1, debug
, sd
, "thread exiting\n");
375 /* ---------------------------------------------------------------------- */
376 /* audio chip descriptions - defines+functions for tda9840 */
378 #define TDA9840_SW 0x00
379 #define TDA9840_LVADJ 0x02
380 #define TDA9840_STADJ 0x03
381 #define TDA9840_TEST 0x04
383 #define TDA9840_MONO 0x10
384 #define TDA9840_STEREO 0x2a
385 #define TDA9840_DUALA 0x12
386 #define TDA9840_DUALB 0x1e
387 #define TDA9840_DUALAB 0x1a
388 #define TDA9840_DUALBA 0x16
389 #define TDA9840_EXTERNAL 0x7a
391 #define TDA9840_DS_DUAL 0x20 /* Dual sound identified */
392 #define TDA9840_ST_STEREO 0x40 /* Stereo sound identified */
393 #define TDA9840_PONRES 0x80 /* Power-on reset detected if = 1 */
395 #define TDA9840_TEST_INT1SN 0x1 /* Integration time 0.5s when set */
396 #define TDA9840_TEST_INTFU 0x02 /* Disables integrator function */
398 static int tda9840_getrxsubchans(struct CHIPSTATE
*chip
)
400 struct v4l2_subdev
*sd
= &chip
->sd
;
403 val
= chip_read(chip
);
404 mode
= V4L2_TUNER_SUB_MONO
;
405 if (val
& TDA9840_DS_DUAL
)
406 mode
|= V4L2_TUNER_SUB_LANG1
| V4L2_TUNER_SUB_LANG2
;
407 if (val
& TDA9840_ST_STEREO
)
408 mode
= V4L2_TUNER_SUB_STEREO
;
410 v4l2_dbg(1, debug
, sd
,
411 "tda9840_getrxsubchans(): raw chip read: %d, return: %d\n",
416 static void tda9840_setaudmode(struct CHIPSTATE
*chip
, int mode
)
419 int t
= chip
->shadow
.bytes
[TDA9840_SW
+ 1] & ~0x7e;
422 case V4L2_TUNER_MODE_MONO
:
425 case V4L2_TUNER_MODE_STEREO
:
428 case V4L2_TUNER_MODE_LANG1
:
431 case V4L2_TUNER_MODE_LANG2
:
434 case V4L2_TUNER_MODE_LANG1_LANG2
:
442 chip_write(chip
, TDA9840_SW
, t
);
445 static int tda9840_checkit(struct CHIPSTATE
*chip
)
448 rc
= chip_read(chip
);
449 /* lower 5 bits should be 0 */
450 return ((rc
& 0x1f) == 0) ? 1 : 0;
453 /* ---------------------------------------------------------------------- */
454 /* audio chip descriptions - defines+functions for tda985x */
456 /* subaddresses for TDA9855 */
457 #define TDA9855_VR 0x00 /* Volume, right */
458 #define TDA9855_VL 0x01 /* Volume, left */
459 #define TDA9855_BA 0x02 /* Bass */
460 #define TDA9855_TR 0x03 /* Treble */
461 #define TDA9855_SW 0x04 /* Subwoofer - not connected on DTV2000 */
463 /* subaddresses for TDA9850 */
464 #define TDA9850_C4 0x04 /* Control 1 for TDA9850 */
466 /* subaddesses for both chips */
467 #define TDA985x_C5 0x05 /* Control 2 for TDA9850, Control 1 for TDA9855 */
468 #define TDA985x_C6 0x06 /* Control 3 for TDA9850, Control 2 for TDA9855 */
469 #define TDA985x_C7 0x07 /* Control 4 for TDA9850, Control 3 for TDA9855 */
470 #define TDA985x_A1 0x08 /* Alignment 1 for both chips */
471 #define TDA985x_A2 0x09 /* Alignment 2 for both chips */
472 #define TDA985x_A3 0x0a /* Alignment 3 for both chips */
474 /* Masks for bits in TDA9855 subaddresses */
475 /* 0x00 - VR in TDA9855 */
476 /* 0x01 - VL in TDA9855 */
477 /* lower 7 bits control gain from -71dB (0x28) to 16dB (0x7f)
478 * in 1dB steps - mute is 0x27 */
481 /* 0x02 - BA in TDA9855 */
482 /* lower 5 bits control bass gain from -12dB (0x06) to 16.5dB (0x19)
483 * in .5dB steps - 0 is 0x0E */
486 /* 0x03 - TR in TDA9855 */
487 /* 4 bits << 1 control treble gain from -12dB (0x3) to 12dB (0xb)
488 * in 3dB steps - 0 is 0x7 */
490 /* Masks for bits in both chips' subaddresses */
491 /* 0x04 - SW in TDA9855, C4/Control 1 in TDA9850 */
492 /* Unique to TDA9855: */
493 /* 4 bits << 2 control subwoofer/surround gain from -14db (0x1) to 14db (0xf)
494 * in 3dB steps - mute is 0x0 */
496 /* Unique to TDA9850: */
497 /* lower 4 bits control stereo noise threshold, over which stereo turns off
498 * set to values of 0x00 through 0x0f for Ster1 through Ster16 */
501 /* 0x05 - C5 - Control 1 in TDA9855 , Control 2 in TDA9850*/
502 /* Unique to TDA9855: */
503 #define TDA9855_MUTE 1<<7 /* GMU, Mute at outputs */
504 #define TDA9855_AVL 1<<6 /* AVL, Automatic Volume Level */
505 #define TDA9855_LOUD 1<<5 /* Loudness, 1==off */
506 #define TDA9855_SUR 1<<3 /* Surround / Subwoofer 1==.5(L-R) 0==.5(L+R) */
507 /* Bits 0 to 3 select various combinations
508 * of line in and line out, only the
509 * interesting ones are defined */
510 #define TDA9855_EXT 1<<2 /* Selects inputs LIR and LIL. Pins 41 & 12 */
511 #define TDA9855_INT 0 /* Selects inputs LOR and LOL. (internal) */
513 /* Unique to TDA9850: */
514 /* lower 4 bits contol SAP noise threshold, over which SAP turns off
515 * set to values of 0x00 through 0x0f for SAP1 through SAP16 */
518 /* 0x06 - C6 - Control 2 in TDA9855, Control 3 in TDA9850 */
519 /* Common to TDA9855 and TDA9850: */
520 #define TDA985x_SAP 3<<6 /* Selects SAP output, mute if not received */
521 #define TDA985x_MONOSAP 2<<6 /* Selects Mono on left, SAP on right */
522 #define TDA985x_STEREO 1<<6 /* Selects Stereo ouput, mono if not received */
523 #define TDA985x_MONO 0 /* Forces Mono output */
524 #define TDA985x_LMU 1<<3 /* Mute (LOR/LOL for 9855, OUTL/OUTR for 9850) */
526 /* Unique to TDA9855: */
527 #define TDA9855_TZCM 1<<5 /* If set, don't mute till zero crossing */
528 #define TDA9855_VZCM 1<<4 /* If set, don't change volume till zero crossing*/
529 #define TDA9855_LINEAR 0 /* Linear Stereo */
530 #define TDA9855_PSEUDO 1 /* Pseudo Stereo */
531 #define TDA9855_SPAT_30 2 /* Spatial Stereo, 30% anti-phase crosstalk */
532 #define TDA9855_SPAT_50 3 /* Spatial Stereo, 52% anti-phase crosstalk */
533 #define TDA9855_E_MONO 7 /* Forced mono - mono select elseware, so useless*/
535 /* 0x07 - C7 - Control 3 in TDA9855, Control 4 in TDA9850 */
536 /* Common to both TDA9855 and TDA9850: */
537 /* lower 4 bits control input gain from -3.5dB (0x0) to 4dB (0xF)
538 * in .5dB steps - 0dB is 0x7 */
540 /* 0x08, 0x09 - A1 and A2 (read/write) */
541 /* Common to both TDA9855 and TDA9850: */
542 /* lower 5 bites are wideband and spectral expander alignment
543 * from 0x00 to 0x1f - nominal at 0x0f and 0x10 (read/write) */
544 #define TDA985x_STP 1<<5 /* Stereo Pilot/detect (read-only) */
545 #define TDA985x_SAPP 1<<6 /* SAP Pilot/detect (read-only) */
546 #define TDA985x_STS 1<<7 /* Stereo trigger 1= <35mV 0= <30mV (write-only)*/
549 /* Common to both TDA9855 and TDA9850: */
550 /* lower 3 bits control timing current for alignment: -30% (0x0), -20% (0x1),
551 * -10% (0x2), nominal (0x3), +10% (0x6), +20% (0x5), +30% (0x4) */
552 #define TDA985x_ADJ 1<<7 /* Stereo adjust on/off (wideband and spectral */
554 static int tda9855_volume(int val
) { return val
/0x2e8+0x27; }
555 static int tda9855_bass(int val
) { return val
/0xccc+0x06; }
556 static int tda9855_treble(int val
) { return (val
/0x1c71+0x3)<<1; }
558 static int tda985x_getrxsubchans(struct CHIPSTATE
*chip
)
562 /* Add mono mode regardless of SAP and stereo */
563 /* Allows forced mono */
564 mode
= V4L2_TUNER_SUB_MONO
;
565 val
= chip_read(chip
);
566 if (val
& TDA985x_STP
)
567 mode
= V4L2_TUNER_SUB_STEREO
;
568 if (val
& TDA985x_SAPP
)
569 mode
|= V4L2_TUNER_SUB_SAP
;
573 static void tda985x_setaudmode(struct CHIPSTATE
*chip
, int mode
)
576 int c6
= chip
->shadow
.bytes
[TDA985x_C6
+1] & 0x3f;
579 case V4L2_TUNER_MODE_MONO
:
582 case V4L2_TUNER_MODE_STEREO
:
583 case V4L2_TUNER_MODE_LANG1
:
584 c6
|= TDA985x_STEREO
;
586 case V4L2_TUNER_MODE_SAP
:
589 case V4L2_TUNER_MODE_LANG1_LANG2
:
590 c6
|= TDA985x_MONOSAP
;
596 chip_write(chip
,TDA985x_C6
,c6
);
600 /* ---------------------------------------------------------------------- */
601 /* audio chip descriptions - defines+functions for tda9873h */
603 /* Subaddresses for TDA9873H */
605 #define TDA9873_SW 0x00 /* Switching */
606 #define TDA9873_AD 0x01 /* Adjust */
607 #define TDA9873_PT 0x02 /* Port */
609 /* Subaddress 0x00: Switching Data
612 * B1, B0: Input source selection
614 * 1, 0 external stereo
617 #define TDA9873_INP_MASK 3
618 #define TDA9873_INTERNAL 0
619 #define TDA9873_EXT_STEREO 2
620 #define TDA9873_EXT_MONO 1
622 /* B3, B2: output signal select
623 * B4 : transmission mode
626 * 1, 1, 1 Stereo (reversed channel)
633 #define TDA9873_TR_MASK (7 << 2)
634 #define TDA9873_TR_MONO 4
635 #define TDA9873_TR_STEREO 1 << 4
636 #define TDA9873_TR_REVERSE ((1 << 3) | (1 << 2))
637 #define TDA9873_TR_DUALA 1 << 2
638 #define TDA9873_TR_DUALB 1 << 3
639 #define TDA9873_TR_DUALAB 0
641 /* output level controls
642 * B5: output level switch (0 = reduced gain, 1 = normal gain)
643 * B6: mute (1 = muted)
644 * B7: auto-mute (1 = auto-mute enabled)
647 #define TDA9873_GAIN_NORMAL 1 << 5
648 #define TDA9873_MUTE 1 << 6
649 #define TDA9873_AUTOMUTE 1 << 7
651 /* Subaddress 0x01: Adjust/standard */
653 /* Lower 4 bits (C3..C0) control stereo adjustment on R channel (-0.6 - +0.7 dB)
654 * Recommended value is +0 dB
657 #define TDA9873_STEREO_ADJ 0x06 /* 0dB gain */
659 /* Bits C6..C4 control FM stantard
661 * 0, 0, 0 B/G (PAL FM)
670 #define TDA9873_DK1 2
671 #define TDA9873_DK2 3
672 #define TDA9873_DK3 4
675 /* C7 controls identification response time (1=fast/0=normal)
677 #define TDA9873_IDR_NORM 0
678 #define TDA9873_IDR_FAST 1 << 7
681 /* Subaddress 0x02: Port data */
683 /* E1, E0 free programmable ports P1/P2
690 #define TDA9873_PORTS 3
693 #define TDA9873_TST_PORT 1 << 2
695 /* E5..E3 control mono output channel (together with transmission mode bit B4)
700 * 0 1 0 1 mono (from stereo decoder)
702 #define TDA9873_MOUT_MONO 0
703 #define TDA9873_MOUT_FMONO 0
704 #define TDA9873_MOUT_DUALA 0
705 #define TDA9873_MOUT_DUALB 1 << 3
706 #define TDA9873_MOUT_ST 1 << 4
707 #define TDA9873_MOUT_EXTM ((1 << 4) | (1 << 3))
708 #define TDA9873_MOUT_EXTL 1 << 5
709 #define TDA9873_MOUT_EXTR ((1 << 5) | (1 << 3))
710 #define TDA9873_MOUT_EXTLR ((1 << 5) | (1 << 4))
711 #define TDA9873_MOUT_MUTE ((1 << 5) | (1 << 4) | (1 << 3))
713 /* Status bits: (chip read) */
714 #define TDA9873_PONR 0 /* Power-on reset detected if = 1 */
715 #define TDA9873_STEREO 2 /* Stereo sound is identified */
716 #define TDA9873_DUAL 4 /* Dual sound is identified */
718 static int tda9873_getrxsubchans(struct CHIPSTATE
*chip
)
720 struct v4l2_subdev
*sd
= &chip
->sd
;
723 val
= chip_read(chip
);
724 mode
= V4L2_TUNER_SUB_MONO
;
725 if (val
& TDA9873_STEREO
)
726 mode
= V4L2_TUNER_SUB_STEREO
;
727 if (val
& TDA9873_DUAL
)
728 mode
|= V4L2_TUNER_SUB_LANG1
| V4L2_TUNER_SUB_LANG2
;
729 v4l2_dbg(1, debug
, sd
,
730 "tda9873_getrxsubchans(): raw chip read: %d, return: %d\n",
735 static void tda9873_setaudmode(struct CHIPSTATE
*chip
, int mode
)
737 struct v4l2_subdev
*sd
= &chip
->sd
;
738 int sw_data
= chip
->shadow
.bytes
[TDA9873_SW
+1] & ~ TDA9873_TR_MASK
;
739 /* int adj_data = chip->shadow.bytes[TDA9873_AD+1] ; */
741 if ((sw_data
& TDA9873_INP_MASK
) != TDA9873_INTERNAL
) {
742 v4l2_dbg(1, debug
, sd
,
743 "tda9873_setaudmode(): external input\n");
747 v4l2_dbg(1, debug
, sd
,
748 "tda9873_setaudmode(): chip->shadow.bytes[%d] = %d\n",
749 TDA9873_SW
+1, chip
->shadow
.bytes
[TDA9873_SW
+1]);
750 v4l2_dbg(1, debug
, sd
, "tda9873_setaudmode(): sw_data = %d\n",
754 case V4L2_TUNER_MODE_MONO
:
755 sw_data
|= TDA9873_TR_MONO
;
757 case V4L2_TUNER_MODE_STEREO
:
758 sw_data
|= TDA9873_TR_STEREO
;
760 case V4L2_TUNER_MODE_LANG1
:
761 sw_data
|= TDA9873_TR_DUALA
;
763 case V4L2_TUNER_MODE_LANG2
:
764 sw_data
|= TDA9873_TR_DUALB
;
766 case V4L2_TUNER_MODE_LANG1_LANG2
:
767 sw_data
|= TDA9873_TR_DUALAB
;
773 chip_write(chip
, TDA9873_SW
, sw_data
);
774 v4l2_dbg(1, debug
, sd
,
775 "tda9873_setaudmode(): req. mode %d; chip_write: %d\n",
779 static int tda9873_checkit(struct CHIPSTATE
*chip
)
783 if (-1 == (rc
= chip_read2(chip
,254)))
785 return (rc
& ~0x1f) == 0x80;
789 /* ---------------------------------------------------------------------- */
790 /* audio chip description - defines+functions for tda9874h and tda9874a */
791 /* Dariusz Kowalewski <darekk@automex.pl> */
793 /* Subaddresses for TDA9874H and TDA9874A (slave rx) */
794 #define TDA9874A_AGCGR 0x00 /* AGC gain */
795 #define TDA9874A_GCONR 0x01 /* general config */
796 #define TDA9874A_MSR 0x02 /* monitor select */
797 #define TDA9874A_C1FRA 0x03 /* carrier 1 freq. */
798 #define TDA9874A_C1FRB 0x04 /* carrier 1 freq. */
799 #define TDA9874A_C1FRC 0x05 /* carrier 1 freq. */
800 #define TDA9874A_C2FRA 0x06 /* carrier 2 freq. */
801 #define TDA9874A_C2FRB 0x07 /* carrier 2 freq. */
802 #define TDA9874A_C2FRC 0x08 /* carrier 2 freq. */
803 #define TDA9874A_DCR 0x09 /* demodulator config */
804 #define TDA9874A_FMER 0x0a /* FM de-emphasis */
805 #define TDA9874A_FMMR 0x0b /* FM dematrix */
806 #define TDA9874A_C1OLAR 0x0c /* ch.1 output level adj. */
807 #define TDA9874A_C2OLAR 0x0d /* ch.2 output level adj. */
808 #define TDA9874A_NCONR 0x0e /* NICAM config */
809 #define TDA9874A_NOLAR 0x0f /* NICAM output level adj. */
810 #define TDA9874A_NLELR 0x10 /* NICAM lower error limit */
811 #define TDA9874A_NUELR 0x11 /* NICAM upper error limit */
812 #define TDA9874A_AMCONR 0x12 /* audio mute control */
813 #define TDA9874A_SDACOSR 0x13 /* stereo DAC output select */
814 #define TDA9874A_AOSR 0x14 /* analog output select */
815 #define TDA9874A_DAICONR 0x15 /* digital audio interface config */
816 #define TDA9874A_I2SOSR 0x16 /* I2S-bus output select */
817 #define TDA9874A_I2SOLAR 0x17 /* I2S-bus output level adj. */
818 #define TDA9874A_MDACOSR 0x18 /* mono DAC output select (tda9874a) */
819 #define TDA9874A_ESP 0xFF /* easy standard progr. (tda9874a) */
821 /* Subaddresses for TDA9874H and TDA9874A (slave tx) */
822 #define TDA9874A_DSR 0x00 /* device status */
823 #define TDA9874A_NSR 0x01 /* NICAM status */
824 #define TDA9874A_NECR 0x02 /* NICAM error count */
825 #define TDA9874A_DR1 0x03 /* add. data LSB */
826 #define TDA9874A_DR2 0x04 /* add. data MSB */
827 #define TDA9874A_LLRA 0x05 /* monitor level read-out LSB */
828 #define TDA9874A_LLRB 0x06 /* monitor level read-out MSB */
829 #define TDA9874A_SIFLR 0x07 /* SIF level */
830 #define TDA9874A_TR2 252 /* test reg. 2 */
831 #define TDA9874A_TR1 253 /* test reg. 1 */
832 #define TDA9874A_DIC 254 /* device id. code */
833 #define TDA9874A_SIC 255 /* software id. code */
836 static int tda9874a_mode
= 1; /* 0: A2, 1: NICAM */
837 static int tda9874a_GCONR
= 0xc0; /* default config. input pin: SIFSEL=0 */
838 static int tda9874a_NCONR
= 0x01; /* default NICAM config.: AMSEL=0,AMUTE=1 */
839 static int tda9874a_ESP
= 0x07; /* default standard: NICAM D/K */
840 static int tda9874a_dic
= -1; /* device id. code */
842 /* insmod options for tda9874a */
843 static unsigned int tda9874a_SIF
= UNSET
;
844 static unsigned int tda9874a_AMSEL
= UNSET
;
845 static unsigned int tda9874a_STD
= UNSET
;
846 module_param(tda9874a_SIF
, int, 0444);
847 module_param(tda9874a_AMSEL
, int, 0444);
848 module_param(tda9874a_STD
, int, 0444);
851 * initialization table for tda9874 decoder:
852 * - carrier 1 freq. registers (3 bytes)
853 * - carrier 2 freq. registers (3 bytes)
854 * - demudulator config register
855 * - FM de-emphasis register (slow identification mode)
856 * Note: frequency registers must be written in single i2c transfer.
858 static struct tda9874a_MODES
{
861 } tda9874a_modelist
[9] = {
862 { "A2, B/G", /* default */
863 { 9, { TDA9874A_C1FRA
, 0x72,0x95,0x55, 0x77,0xA0,0x00, 0x00,0x00 }} },
865 { 9, { TDA9874A_C1FRA
, 0x5D,0xC0,0x00, 0x62,0x6A,0xAA, 0x20,0x22 }} },
867 { 9, { TDA9874A_C1FRA
, 0x87,0x6A,0xAA, 0x82,0x60,0x00, 0x00,0x00 }} },
869 { 9, { TDA9874A_C1FRA
, 0x87,0x6A,0xAA, 0x8C,0x75,0x55, 0x00,0x00 }} },
871 { 9, { TDA9874A_C1FRA
, 0x87,0x6A,0xAA, 0x77,0xA0,0x00, 0x00,0x00 }} },
873 { 9, { TDA9874A_C1FRA
, 0x7D,0x00,0x00, 0x88,0x8A,0xAA, 0x08,0x33 }} },
875 { 9, { TDA9874A_C1FRA
, 0x72,0x95,0x55, 0x79,0xEA,0xAA, 0x08,0x33 }} },
877 { 9, { TDA9874A_C1FRA
, 0x87,0x6A,0xAA, 0x79,0xEA,0xAA, 0x08,0x33 }} },
879 { 9, { TDA9874A_C1FRA
, 0x87,0x6A,0xAA, 0x79,0xEA,0xAA, 0x09,0x33 }} }
882 static int tda9874a_setup(struct CHIPSTATE
*chip
)
884 struct v4l2_subdev
*sd
= &chip
->sd
;
886 chip_write(chip
, TDA9874A_AGCGR
, 0x00); /* 0 dB */
887 chip_write(chip
, TDA9874A_GCONR
, tda9874a_GCONR
);
888 chip_write(chip
, TDA9874A_MSR
, (tda9874a_mode
) ? 0x03:0x02);
889 if(tda9874a_dic
== 0x11) {
890 chip_write(chip
, TDA9874A_FMMR
, 0x80);
891 } else { /* dic == 0x07 */
892 chip_cmd(chip
,"tda9874_modelist",&tda9874a_modelist
[tda9874a_STD
].cmd
);
893 chip_write(chip
, TDA9874A_FMMR
, 0x00);
895 chip_write(chip
, TDA9874A_C1OLAR
, 0x00); /* 0 dB */
896 chip_write(chip
, TDA9874A_C2OLAR
, 0x00); /* 0 dB */
897 chip_write(chip
, TDA9874A_NCONR
, tda9874a_NCONR
);
898 chip_write(chip
, TDA9874A_NOLAR
, 0x00); /* 0 dB */
899 /* Note: If signal quality is poor you may want to change NICAM */
900 /* error limit registers (NLELR and NUELR) to some greater values. */
901 /* Then the sound would remain stereo, but won't be so clear. */
902 chip_write(chip
, TDA9874A_NLELR
, 0x14); /* default */
903 chip_write(chip
, TDA9874A_NUELR
, 0x50); /* default */
905 if(tda9874a_dic
== 0x11) {
906 chip_write(chip
, TDA9874A_AMCONR
, 0xf9);
907 chip_write(chip
, TDA9874A_SDACOSR
, (tda9874a_mode
) ? 0x81:0x80);
908 chip_write(chip
, TDA9874A_AOSR
, 0x80);
909 chip_write(chip
, TDA9874A_MDACOSR
, (tda9874a_mode
) ? 0x82:0x80);
910 chip_write(chip
, TDA9874A_ESP
, tda9874a_ESP
);
911 } else { /* dic == 0x07 */
912 chip_write(chip
, TDA9874A_AMCONR
, 0xfb);
913 chip_write(chip
, TDA9874A_SDACOSR
, (tda9874a_mode
) ? 0x81:0x80);
914 chip_write(chip
, TDA9874A_AOSR
, 0x00); /* or 0x10 */
916 v4l2_dbg(1, debug
, sd
, "tda9874a_setup(): %s [0x%02X].\n",
917 tda9874a_modelist
[tda9874a_STD
].name
,tda9874a_STD
);
921 static int tda9874a_getrxsubchans(struct CHIPSTATE
*chip
)
923 struct v4l2_subdev
*sd
= &chip
->sd
;
925 int necr
; /* just for debugging */
927 mode
= V4L2_TUNER_SUB_MONO
;
929 if(-1 == (dsr
= chip_read2(chip
,TDA9874A_DSR
)))
931 if(-1 == (nsr
= chip_read2(chip
,TDA9874A_NSR
)))
933 if(-1 == (necr
= chip_read2(chip
,TDA9874A_NECR
)))
936 /* need to store dsr/nsr somewhere */
937 chip
->shadow
.bytes
[MAXREGS
-2] = dsr
;
938 chip
->shadow
.bytes
[MAXREGS
-1] = nsr
;
941 /* Note: DSR.RSSF and DSR.AMSTAT bits are also checked.
942 * If NICAM auto-muting is enabled, DSR.AMSTAT=1 indicates
943 * that sound has (temporarily) switched from NICAM to
944 * mono FM (or AM) on 1st sound carrier due to high NICAM bit
945 * error count. So in fact there is no stereo in this case :-(
946 * But changing the mode to V4L2_TUNER_MODE_MONO would switch
947 * external 4052 multiplexer in audio_hook().
949 if(nsr
& 0x02) /* NSR.S/MB=1 */
950 mode
= V4L2_TUNER_SUB_STEREO
;
951 if(nsr
& 0x01) /* NSR.D/SB=1 */
952 mode
|= V4L2_TUNER_SUB_LANG1
| V4L2_TUNER_SUB_LANG2
;
954 if(dsr
& 0x02) /* DSR.IDSTE=1 */
955 mode
= V4L2_TUNER_SUB_STEREO
;
956 if(dsr
& 0x04) /* DSR.IDDUA=1 */
957 mode
|= V4L2_TUNER_SUB_LANG1
| V4L2_TUNER_SUB_LANG2
;
960 v4l2_dbg(1, debug
, sd
,
961 "tda9874a_getrxsubchans(): DSR=0x%X, NSR=0x%X, NECR=0x%X, return: %d.\n",
962 dsr
, nsr
, necr
, mode
);
966 static void tda9874a_setaudmode(struct CHIPSTATE
*chip
, int mode
)
968 struct v4l2_subdev
*sd
= &chip
->sd
;
970 /* Disable/enable NICAM auto-muting (based on DSR.RSSF status bit). */
971 /* If auto-muting is disabled, we can hear a signal of degrading quality. */
973 if(chip
->shadow
.bytes
[MAXREGS
-2] & 0x20) /* DSR.RSSF=1 */
974 tda9874a_NCONR
&= 0xfe; /* enable */
976 tda9874a_NCONR
|= 0x01; /* disable */
977 chip_write(chip
, TDA9874A_NCONR
, tda9874a_NCONR
);
980 /* Note: TDA9874A supports automatic FM dematrixing (FMMR register)
981 * and has auto-select function for audio output (AOSR register).
982 * Old TDA9874H doesn't support these features.
983 * TDA9874A also has additional mono output pin (OUTM), which
984 * on same (all?) tv-cards is not used, anyway (as well as MONOIN).
986 if(tda9874a_dic
== 0x11) {
988 int mdacosr
= (tda9874a_mode
) ? 0x82:0x80;
991 case V4L2_TUNER_MODE_MONO
:
992 case V4L2_TUNER_MODE_STEREO
:
994 case V4L2_TUNER_MODE_LANG1
:
995 aosr
= 0x80; /* auto-select, dual A/A */
996 mdacosr
= (tda9874a_mode
) ? 0x82:0x80;
998 case V4L2_TUNER_MODE_LANG2
:
999 aosr
= 0xa0; /* auto-select, dual B/B */
1000 mdacosr
= (tda9874a_mode
) ? 0x83:0x81;
1002 case V4L2_TUNER_MODE_LANG1_LANG2
:
1003 aosr
= 0x00; /* always route L to L and R to R */
1004 mdacosr
= (tda9874a_mode
) ? 0x82:0x80;
1009 chip_write(chip
, TDA9874A_AOSR
, aosr
);
1010 chip_write(chip
, TDA9874A_MDACOSR
, mdacosr
);
1012 v4l2_dbg(1, debug
, sd
,
1013 "tda9874a_setaudmode(): req. mode %d; AOSR=0x%X, MDACOSR=0x%X.\n",
1014 mode
, aosr
, mdacosr
);
1016 } else { /* dic == 0x07 */
1020 case V4L2_TUNER_MODE_MONO
:
1021 fmmr
= 0x00; /* mono */
1022 aosr
= 0x10; /* A/A */
1024 case V4L2_TUNER_MODE_STEREO
:
1027 aosr
= 0x00; /* handled by NICAM auto-mute */
1029 fmmr
= (tda9874a_ESP
== 1) ? 0x05 : 0x04; /* stereo */
1033 case V4L2_TUNER_MODE_LANG1
:
1034 fmmr
= 0x02; /* dual */
1035 aosr
= 0x10; /* dual A/A */
1037 case V4L2_TUNER_MODE_LANG2
:
1038 fmmr
= 0x02; /* dual */
1039 aosr
= 0x20; /* dual B/B */
1041 case V4L2_TUNER_MODE_LANG1_LANG2
:
1042 fmmr
= 0x02; /* dual */
1043 aosr
= 0x00; /* dual A/B */
1048 chip_write(chip
, TDA9874A_FMMR
, fmmr
);
1049 chip_write(chip
, TDA9874A_AOSR
, aosr
);
1051 v4l2_dbg(1, debug
, sd
,
1052 "tda9874a_setaudmode(): req. mode %d; FMMR=0x%X, AOSR=0x%X.\n",
1057 static int tda9874a_checkit(struct CHIPSTATE
*chip
)
1059 struct v4l2_subdev
*sd
= &chip
->sd
;
1060 int dic
,sic
; /* device id. and software id. codes */
1062 if(-1 == (dic
= chip_read2(chip
,TDA9874A_DIC
)))
1064 if(-1 == (sic
= chip_read2(chip
,TDA9874A_SIC
)))
1067 v4l2_dbg(1, debug
, sd
, "tda9874a_checkit(): DIC=0x%X, SIC=0x%X.\n", dic
, sic
);
1069 if((dic
== 0x11)||(dic
== 0x07)) {
1070 v4l2_info(sd
, "found tda9874%s.\n", (dic
== 0x11) ? "a" : "h");
1071 tda9874a_dic
= dic
; /* remember device id. */
1074 return 0; /* not found */
1077 static int tda9874a_initialize(struct CHIPSTATE
*chip
)
1079 if (tda9874a_SIF
> 2)
1081 if (tda9874a_STD
>= ARRAY_SIZE(tda9874a_modelist
))
1083 if(tda9874a_AMSEL
> 1)
1086 if(tda9874a_SIF
== 1)
1087 tda9874a_GCONR
= 0xc0; /* sound IF input 1 */
1089 tda9874a_GCONR
= 0xc1; /* sound IF input 2 */
1091 tda9874a_ESP
= tda9874a_STD
;
1092 tda9874a_mode
= (tda9874a_STD
< 5) ? 0 : 1;
1094 if(tda9874a_AMSEL
== 0)
1095 tda9874a_NCONR
= 0x01; /* auto-mute: analog mono input */
1097 tda9874a_NCONR
= 0x05; /* auto-mute: 1st carrier FM or AM */
1099 tda9874a_setup(chip
);
1103 /* ---------------------------------------------------------------------- */
1104 /* audio chip description - defines+functions for tda9875 */
1105 /* The TDA9875 is made by Philips Semiconductor
1106 * http://www.semiconductors.philips.com
1107 * TDA9875: I2C-bus controlled DSP audio processor, FM demodulator
1111 /* subaddresses for TDA9875 */
1112 #define TDA9875_MUT 0x12 /*General mute (value --> 0b11001100*/
1113 #define TDA9875_CFG 0x01 /* Config register (value --> 0b00000000 */
1114 #define TDA9875_DACOS 0x13 /*DAC i/o select (ADC) 0b0000100*/
1115 #define TDA9875_LOSR 0x16 /*Line output select regirter 0b0100 0001*/
1117 #define TDA9875_CH1V 0x0c /*Channel 1 volume (mute)*/
1118 #define TDA9875_CH2V 0x0d /*Channel 2 volume (mute)*/
1119 #define TDA9875_SC1 0x14 /*SCART 1 in (mono)*/
1120 #define TDA9875_SC2 0x15 /*SCART 2 in (mono)*/
1122 #define TDA9875_ADCIS 0x17 /*ADC input select (mono) 0b0110 000*/
1123 #define TDA9875_AER 0x19 /*Audio effect (AVL+Pseudo) 0b0000 0110*/
1124 #define TDA9875_MCS 0x18 /*Main channel select (DAC) 0b0000100*/
1125 #define TDA9875_MVL 0x1a /* Main volume gauche */
1126 #define TDA9875_MVR 0x1b /* Main volume droite */
1127 #define TDA9875_MBA 0x1d /* Main Basse */
1128 #define TDA9875_MTR 0x1e /* Main treble */
1129 #define TDA9875_ACS 0x1f /* Auxiliary channel select (FM) 0b0000000*/
1130 #define TDA9875_AVL 0x20 /* Auxiliary volume gauche */
1131 #define TDA9875_AVR 0x21 /* Auxiliary volume droite */
1132 #define TDA9875_ABA 0x22 /* Auxiliary Basse */
1133 #define TDA9875_ATR 0x23 /* Auxiliary treble */
1135 #define TDA9875_MSR 0x02 /* Monitor select register */
1136 #define TDA9875_C1MSB 0x03 /* Carrier 1 (FM) frequency register MSB */
1137 #define TDA9875_C1MIB 0x04 /* Carrier 1 (FM) frequency register (16-8]b */
1138 #define TDA9875_C1LSB 0x05 /* Carrier 1 (FM) frequency register LSB */
1139 #define TDA9875_C2MSB 0x06 /* Carrier 2 (nicam) frequency register MSB */
1140 #define TDA9875_C2MIB 0x07 /* Carrier 2 (nicam) frequency register (16-8]b */
1141 #define TDA9875_C2LSB 0x08 /* Carrier 2 (nicam) frequency register LSB */
1142 #define TDA9875_DCR 0x09 /* Demodulateur configuration regirter*/
1143 #define TDA9875_DEEM 0x0a /* FM de-emphasis regirter*/
1144 #define TDA9875_FMAT 0x0b /* FM Matrix regirter*/
1147 #define TDA9875_MUTE_ON 0xff /* general mute */
1148 #define TDA9875_MUTE_OFF 0xcc /* general no mute */
1150 static int tda9875_initialize(struct CHIPSTATE
*chip
)
1152 chip_write(chip
, TDA9875_CFG
, 0xd0); /*reg de config 0 (reset)*/
1153 chip_write(chip
, TDA9875_MSR
, 0x03); /* Monitor 0b00000XXX*/
1154 chip_write(chip
, TDA9875_C1MSB
, 0x00); /*Car1(FM) MSB XMHz*/
1155 chip_write(chip
, TDA9875_C1MIB
, 0x00); /*Car1(FM) MIB XMHz*/
1156 chip_write(chip
, TDA9875_C1LSB
, 0x00); /*Car1(FM) LSB XMHz*/
1157 chip_write(chip
, TDA9875_C2MSB
, 0x00); /*Car2(NICAM) MSB XMHz*/
1158 chip_write(chip
, TDA9875_C2MIB
, 0x00); /*Car2(NICAM) MIB XMHz*/
1159 chip_write(chip
, TDA9875_C2LSB
, 0x00); /*Car2(NICAM) LSB XMHz*/
1160 chip_write(chip
, TDA9875_DCR
, 0x00); /*Demod config 0x00*/
1161 chip_write(chip
, TDA9875_DEEM
, 0x44); /*DE-Emph 0b0100 0100*/
1162 chip_write(chip
, TDA9875_FMAT
, 0x00); /*FM Matrix reg 0x00*/
1163 chip_write(chip
, TDA9875_SC1
, 0x00); /* SCART 1 (SC1)*/
1164 chip_write(chip
, TDA9875_SC2
, 0x01); /* SCART 2 (sc2)*/
1166 chip_write(chip
, TDA9875_CH1V
, 0x10); /* Channel volume 1 mute*/
1167 chip_write(chip
, TDA9875_CH2V
, 0x10); /* Channel volume 2 mute */
1168 chip_write(chip
, TDA9875_DACOS
, 0x02); /* sig DAC i/o(in:nicam)*/
1169 chip_write(chip
, TDA9875_ADCIS
, 0x6f); /* sig ADC input(in:mono)*/
1170 chip_write(chip
, TDA9875_LOSR
, 0x00); /* line out (in:mono)*/
1171 chip_write(chip
, TDA9875_AER
, 0x00); /*06 Effect (AVL+PSEUDO) */
1172 chip_write(chip
, TDA9875_MCS
, 0x44); /* Main ch select (DAC) */
1173 chip_write(chip
, TDA9875_MVL
, 0x03); /* Vol Main left 10dB */
1174 chip_write(chip
, TDA9875_MVR
, 0x03); /* Vol Main right 10dB*/
1175 chip_write(chip
, TDA9875_MBA
, 0x00); /* Main Bass Main 0dB*/
1176 chip_write(chip
, TDA9875_MTR
, 0x00); /* Main Treble Main 0dB*/
1177 chip_write(chip
, TDA9875_ACS
, 0x44); /* Aux chan select (dac)*/
1178 chip_write(chip
, TDA9875_AVL
, 0x00); /* Vol Aux left 0dB*/
1179 chip_write(chip
, TDA9875_AVR
, 0x00); /* Vol Aux right 0dB*/
1180 chip_write(chip
, TDA9875_ABA
, 0x00); /* Aux Bass Main 0dB*/
1181 chip_write(chip
, TDA9875_ATR
, 0x00); /* Aux Aigus Main 0dB*/
1183 chip_write(chip
, TDA9875_MUT
, 0xcc); /* General mute */
1187 static int tda9875_volume(int val
) { return (unsigned char)(val
/ 602 - 84); }
1188 static int tda9875_bass(int val
) { return (unsigned char)(max(-12, val
/ 2115 - 15)); }
1189 static int tda9875_treble(int val
) { return (unsigned char)(val
/ 2622 - 12); }
1191 /* ----------------------------------------------------------------------- */
1194 /* *********************** *
1195 * i2c interface functions *
1196 * *********************** */
1198 static int tda9875_checkit(struct CHIPSTATE
*chip
)
1200 struct v4l2_subdev
*sd
= &chip
->sd
;
1203 dic
= chip_read2(chip
, 254);
1204 rev
= chip_read2(chip
, 255);
1206 if (dic
== 0 || dic
== 2) { /* tda9875 and tda9875A */
1207 v4l2_info(sd
, "found tda9875%s rev. %d.\n",
1208 dic
== 0 ? "" : "A", rev
);
1214 /* ---------------------------------------------------------------------- */
1215 /* audio chip descriptions - defines+functions for tea6420 */
1217 #define TEA6300_VL 0x00 /* volume left */
1218 #define TEA6300_VR 0x01 /* volume right */
1219 #define TEA6300_BA 0x02 /* bass */
1220 #define TEA6300_TR 0x03 /* treble */
1221 #define TEA6300_FA 0x04 /* fader control */
1222 #define TEA6300_S 0x05 /* switch register */
1223 /* values for those registers: */
1224 #define TEA6300_S_SA 0x01 /* stereo A input */
1225 #define TEA6300_S_SB 0x02 /* stereo B */
1226 #define TEA6300_S_SC 0x04 /* stereo C */
1227 #define TEA6300_S_GMU 0x80 /* general mute */
1229 #define TEA6320_V 0x00 /* volume (0-5)/loudness off (6)/zero crossing mute(7) */
1230 #define TEA6320_FFR 0x01 /* fader front right (0-5) */
1231 #define TEA6320_FFL 0x02 /* fader front left (0-5) */
1232 #define TEA6320_FRR 0x03 /* fader rear right (0-5) */
1233 #define TEA6320_FRL 0x04 /* fader rear left (0-5) */
1234 #define TEA6320_BA 0x05 /* bass (0-4) */
1235 #define TEA6320_TR 0x06 /* treble (0-4) */
1236 #define TEA6320_S 0x07 /* switch register */
1237 /* values for those registers: */
1238 #define TEA6320_S_SA 0x07 /* stereo A input */
1239 #define TEA6320_S_SB 0x06 /* stereo B */
1240 #define TEA6320_S_SC 0x05 /* stereo C */
1241 #define TEA6320_S_SD 0x04 /* stereo D */
1242 #define TEA6320_S_GMU 0x80 /* general mute */
1244 #define TEA6420_S_SA 0x00 /* stereo A input */
1245 #define TEA6420_S_SB 0x01 /* stereo B */
1246 #define TEA6420_S_SC 0x02 /* stereo C */
1247 #define TEA6420_S_SD 0x03 /* stereo D */
1248 #define TEA6420_S_SE 0x04 /* stereo E */
1249 #define TEA6420_S_GMU 0x05 /* general mute */
1251 static int tea6300_shift10(int val
) { return val
>> 10; }
1252 static int tea6300_shift12(int val
) { return val
>> 12; }
1254 /* Assumes 16bit input (values 0x3f to 0x0c are unique, values less than */
1255 /* 0x0c mirror those immediately higher) */
1256 static int tea6320_volume(int val
) { return (val
/ (65535/(63-12)) + 12) & 0x3f; }
1257 static int tea6320_shift11(int val
) { return val
>> 11; }
1258 static int tea6320_initialize(struct CHIPSTATE
* chip
)
1260 chip_write(chip
, TEA6320_FFR
, 0x3f);
1261 chip_write(chip
, TEA6320_FFL
, 0x3f);
1262 chip_write(chip
, TEA6320_FRR
, 0x3f);
1263 chip_write(chip
, TEA6320_FRL
, 0x3f);
1269 /* ---------------------------------------------------------------------- */
1270 /* audio chip descriptions - defines+functions for tda8425 */
1272 #define TDA8425_VL 0x00 /* volume left */
1273 #define TDA8425_VR 0x01 /* volume right */
1274 #define TDA8425_BA 0x02 /* bass */
1275 #define TDA8425_TR 0x03 /* treble */
1276 #define TDA8425_S1 0x08 /* switch functions */
1277 /* values for those registers: */
1278 #define TDA8425_S1_OFF 0xEE /* audio off (mute on) */
1279 #define TDA8425_S1_CH1 0xCE /* audio channel 1 (mute off) - "linear stereo" mode */
1280 #define TDA8425_S1_CH2 0xCF /* audio channel 2 (mute off) - "linear stereo" mode */
1281 #define TDA8425_S1_MU 0x20 /* mute bit */
1282 #define TDA8425_S1_STEREO 0x18 /* stereo bits */
1283 #define TDA8425_S1_STEREO_SPATIAL 0x18 /* spatial stereo */
1284 #define TDA8425_S1_STEREO_LINEAR 0x08 /* linear stereo */
1285 #define TDA8425_S1_STEREO_PSEUDO 0x10 /* pseudo stereo */
1286 #define TDA8425_S1_STEREO_MONO 0x00 /* forced mono */
1287 #define TDA8425_S1_ML 0x06 /* language selector */
1288 #define TDA8425_S1_ML_SOUND_A 0x02 /* sound a */
1289 #define TDA8425_S1_ML_SOUND_B 0x04 /* sound b */
1290 #define TDA8425_S1_ML_STEREO 0x06 /* stereo */
1291 #define TDA8425_S1_IS 0x01 /* channel selector */
1294 static int tda8425_shift10(int val
) { return (val
>> 10) | 0xc0; }
1295 static int tda8425_shift12(int val
) { return (val
>> 12) | 0xf0; }
1297 static void tda8425_setaudmode(struct CHIPSTATE
*chip
, int mode
)
1299 int s1
= chip
->shadow
.bytes
[TDA8425_S1
+1] & 0xe1;
1302 case V4L2_TUNER_MODE_LANG1
:
1303 s1
|= TDA8425_S1_ML_SOUND_A
;
1304 s1
|= TDA8425_S1_STEREO_PSEUDO
;
1306 case V4L2_TUNER_MODE_LANG2
:
1307 s1
|= TDA8425_S1_ML_SOUND_B
;
1308 s1
|= TDA8425_S1_STEREO_PSEUDO
;
1310 case V4L2_TUNER_MODE_LANG1_LANG2
:
1311 s1
|= TDA8425_S1_ML_STEREO
;
1312 s1
|= TDA8425_S1_STEREO_LINEAR
;
1314 case V4L2_TUNER_MODE_MONO
:
1315 s1
|= TDA8425_S1_ML_STEREO
;
1316 s1
|= TDA8425_S1_STEREO_MONO
;
1318 case V4L2_TUNER_MODE_STEREO
:
1319 s1
|= TDA8425_S1_ML_STEREO
;
1320 s1
|= TDA8425_S1_STEREO_SPATIAL
;
1325 chip_write(chip
,TDA8425_S1
,s1
);
1329 /* ---------------------------------------------------------------------- */
1330 /* audio chip descriptions - defines+functions for pic16c54 (PV951) */
1332 /* the registers of 16C54, I2C sub address. */
1333 #define PIC16C54_REG_KEY_CODE 0x01 /* Not use. */
1334 #define PIC16C54_REG_MISC 0x02
1336 /* bit definition of the RESET register, I2C data. */
1337 #define PIC16C54_MISC_RESET_REMOTE_CTL 0x01 /* bit 0, Reset to receive the key */
1338 /* code of remote controller */
1339 #define PIC16C54_MISC_MTS_MAIN 0x02 /* bit 1 */
1340 #define PIC16C54_MISC_MTS_SAP 0x04 /* bit 2 */
1341 #define PIC16C54_MISC_MTS_BOTH 0x08 /* bit 3 */
1342 #define PIC16C54_MISC_SND_MUTE 0x10 /* bit 4, Mute Audio(Line-in and Tuner) */
1343 #define PIC16C54_MISC_SND_NOTMUTE 0x20 /* bit 5 */
1344 #define PIC16C54_MISC_SWITCH_TUNER 0x40 /* bit 6 , Switch to Line-in */
1345 #define PIC16C54_MISC_SWITCH_LINE 0x80 /* bit 7 , Switch to Tuner */
1347 /* ---------------------------------------------------------------------- */
1348 /* audio chip descriptions - defines+functions for TA8874Z */
1350 /* write 1st byte */
1351 #define TA8874Z_LED_STE 0x80
1352 #define TA8874Z_LED_BIL 0x40
1353 #define TA8874Z_LED_EXT 0x20
1354 #define TA8874Z_MONO_SET 0x10
1355 #define TA8874Z_MUTE 0x08
1356 #define TA8874Z_F_MONO 0x04
1357 #define TA8874Z_MODE_SUB 0x02
1358 #define TA8874Z_MODE_MAIN 0x01
1360 /* write 2nd byte */
1361 /*#define TA8874Z_TI 0x80 */ /* test mode */
1362 #define TA8874Z_SEPARATION 0x3f
1363 #define TA8874Z_SEPARATION_DEFAULT 0x10
1366 #define TA8874Z_B1 0x80
1367 #define TA8874Z_B0 0x40
1368 #define TA8874Z_CHAG_FLAG 0x20
1376 static int ta8874z_getrxsubchans(struct CHIPSTATE
*chip
)
1380 val
= chip_read(chip
);
1381 mode
= V4L2_TUNER_SUB_MONO
;
1382 if (val
& TA8874Z_B1
){
1383 mode
|= V4L2_TUNER_SUB_LANG1
| V4L2_TUNER_SUB_LANG2
;
1384 }else if (!(val
& TA8874Z_B0
)){
1385 mode
= V4L2_TUNER_SUB_STEREO
;
1387 /* v4l2_dbg(1, debug, &chip->sd,
1388 "ta8874z_getrxsubchans(): raw chip read: 0x%02x, return: 0x%02x\n",
1393 static audiocmd ta8874z_stereo
= { 2, {0, TA8874Z_SEPARATION_DEFAULT
}};
1394 static audiocmd ta8874z_mono
= {2, { TA8874Z_MONO_SET
, TA8874Z_SEPARATION_DEFAULT
}};
1395 static audiocmd ta8874z_main
= {2, { 0, TA8874Z_SEPARATION_DEFAULT
}};
1396 static audiocmd ta8874z_sub
= {2, { TA8874Z_MODE_SUB
, TA8874Z_SEPARATION_DEFAULT
}};
1397 static audiocmd ta8874z_both
= {2, { TA8874Z_MODE_MAIN
| TA8874Z_MODE_SUB
, TA8874Z_SEPARATION_DEFAULT
}};
1399 static void ta8874z_setaudmode(struct CHIPSTATE
*chip
, int mode
)
1401 struct v4l2_subdev
*sd
= &chip
->sd
;
1405 v4l2_dbg(1, debug
, sd
, "ta8874z_setaudmode(): mode: 0x%02x\n", mode
);
1408 case V4L2_TUNER_MODE_MONO
:
1411 case V4L2_TUNER_MODE_STEREO
:
1412 t
= &ta8874z_stereo
;
1414 case V4L2_TUNER_MODE_LANG1
:
1417 case V4L2_TUNER_MODE_LANG2
:
1420 case V4L2_TUNER_MODE_LANG1_LANG2
:
1428 chip_cmd(chip
, "TA8874Z", t
);
1431 static int ta8874z_checkit(struct CHIPSTATE
*chip
)
1434 rc
= chip_read(chip
);
1435 return ((rc
& 0x1f) == 0x1f) ? 1 : 0;
1438 /* ---------------------------------------------------------------------- */
1439 /* audio chip descriptions - struct CHIPDESC */
1441 /* insmod options to enable/disable individual audio chips */
1442 static int tda8425
= 1;
1443 static int tda9840
= 1;
1444 static int tda9850
= 1;
1445 static int tda9855
= 1;
1446 static int tda9873
= 1;
1447 static int tda9874a
= 1;
1448 static int tda9875
= 1;
1449 static int tea6300
; /* default 0 - address clash with msp34xx */
1450 static int tea6320
; /* default 0 - address clash with msp34xx */
1451 static int tea6420
= 1;
1452 static int pic16c54
= 1;
1453 static int ta8874z
; /* default 0 - address clash with tda9840 */
1455 module_param(tda8425
, int, 0444);
1456 module_param(tda9840
, int, 0444);
1457 module_param(tda9850
, int, 0444);
1458 module_param(tda9855
, int, 0444);
1459 module_param(tda9873
, int, 0444);
1460 module_param(tda9874a
, int, 0444);
1461 module_param(tda9875
, int, 0444);
1462 module_param(tea6300
, int, 0444);
1463 module_param(tea6320
, int, 0444);
1464 module_param(tea6420
, int, 0444);
1465 module_param(pic16c54
, int, 0444);
1466 module_param(ta8874z
, int, 0444);
1468 static struct CHIPDESC chiplist
[] = {
1471 .insmodopt
= &tda9840
,
1472 .addr_lo
= I2C_ADDR_TDA9840
>> 1,
1473 .addr_hi
= I2C_ADDR_TDA9840
>> 1,
1475 .flags
= CHIP_NEED_CHECKMODE
,
1478 .checkit
= tda9840_checkit
,
1479 .getrxsubchans
= tda9840_getrxsubchans
,
1480 .setaudmode
= tda9840_setaudmode
,
1482 .init
= { 2, { TDA9840_TEST
, TDA9840_TEST_INT1SN
1483 /* ,TDA9840_SW, TDA9840_MONO */} }
1487 .insmodopt
= &tda9873
,
1488 .addr_lo
= I2C_ADDR_TDA985x_L
>> 1,
1489 .addr_hi
= I2C_ADDR_TDA985x_H
>> 1,
1491 .flags
= CHIP_HAS_INPUTSEL
| CHIP_NEED_CHECKMODE
,
1494 .checkit
= tda9873_checkit
,
1495 .getrxsubchans
= tda9873_getrxsubchans
,
1496 .setaudmode
= tda9873_setaudmode
,
1498 .init
= { 4, { TDA9873_SW
, 0xa4, 0x06, 0x03 } },
1499 .inputreg
= TDA9873_SW
,
1500 .inputmute
= TDA9873_MUTE
| TDA9873_AUTOMUTE
,
1501 .inputmap
= {0xa0, 0xa2, 0xa0, 0xa0},
1502 .inputmask
= TDA9873_INP_MASK
|TDA9873_MUTE
|TDA9873_AUTOMUTE
,
1506 .name
= "tda9874h/a",
1507 .insmodopt
= &tda9874a
,
1508 .addr_lo
= I2C_ADDR_TDA9874
>> 1,
1509 .addr_hi
= I2C_ADDR_TDA9874
>> 1,
1510 .flags
= CHIP_NEED_CHECKMODE
,
1513 .initialize
= tda9874a_initialize
,
1514 .checkit
= tda9874a_checkit
,
1515 .getrxsubchans
= tda9874a_getrxsubchans
,
1516 .setaudmode
= tda9874a_setaudmode
,
1520 .insmodopt
= &tda9875
,
1521 .addr_lo
= I2C_ADDR_TDA9875
>> 1,
1522 .addr_hi
= I2C_ADDR_TDA9875
>> 1,
1523 .flags
= CHIP_HAS_VOLUME
| CHIP_HAS_BASSTREBLE
,
1526 .initialize
= tda9875_initialize
,
1527 .checkit
= tda9875_checkit
,
1528 .volfunc
= tda9875_volume
,
1529 .bassfunc
= tda9875_bass
,
1530 .treblefunc
= tda9875_treble
,
1531 .leftreg
= TDA9875_MVL
,
1532 .rightreg
= TDA9875_MVR
,
1533 .bassreg
= TDA9875_MBA
,
1534 .treblereg
= TDA9875_MTR
,
1539 .insmodopt
= &tda9850
,
1540 .addr_lo
= I2C_ADDR_TDA985x_L
>> 1,
1541 .addr_hi
= I2C_ADDR_TDA985x_H
>> 1,
1544 .getrxsubchans
= tda985x_getrxsubchans
,
1545 .setaudmode
= tda985x_setaudmode
,
1547 .init
= { 8, { TDA9850_C4
, 0x08, 0x08, TDA985x_STEREO
, 0x07, 0x10, 0x10, 0x03 } }
1551 .insmodopt
= &tda9855
,
1552 .addr_lo
= I2C_ADDR_TDA985x_L
>> 1,
1553 .addr_hi
= I2C_ADDR_TDA985x_H
>> 1,
1555 .flags
= CHIP_HAS_VOLUME
| CHIP_HAS_BASSTREBLE
,
1557 .leftreg
= TDA9855_VL
,
1558 .rightreg
= TDA9855_VR
,
1559 .bassreg
= TDA9855_BA
,
1560 .treblereg
= TDA9855_TR
,
1563 .volfunc
= tda9855_volume
,
1564 .bassfunc
= tda9855_bass
,
1565 .treblefunc
= tda9855_treble
,
1566 .getrxsubchans
= tda985x_getrxsubchans
,
1567 .setaudmode
= tda985x_setaudmode
,
1569 .init
= { 12, { 0, 0x6f, 0x6f, 0x0e, 0x07<<1, 0x8<<2,
1570 TDA9855_MUTE
| TDA9855_AVL
| TDA9855_LOUD
| TDA9855_INT
,
1571 TDA985x_STEREO
| TDA9855_LINEAR
| TDA9855_TZCM
| TDA9855_VZCM
,
1572 0x07, 0x10, 0x10, 0x03 }}
1576 .insmodopt
= &tea6300
,
1577 .addr_lo
= I2C_ADDR_TEA6300
>> 1,
1578 .addr_hi
= I2C_ADDR_TEA6300
>> 1,
1580 .flags
= CHIP_HAS_VOLUME
| CHIP_HAS_BASSTREBLE
| CHIP_HAS_INPUTSEL
,
1582 .leftreg
= TEA6300_VR
,
1583 .rightreg
= TEA6300_VL
,
1584 .bassreg
= TEA6300_BA
,
1585 .treblereg
= TEA6300_TR
,
1588 .volfunc
= tea6300_shift10
,
1589 .bassfunc
= tea6300_shift12
,
1590 .treblefunc
= tea6300_shift12
,
1592 .inputreg
= TEA6300_S
,
1593 .inputmap
= { TEA6300_S_SA
, TEA6300_S_SB
, TEA6300_S_SC
},
1594 .inputmute
= TEA6300_S_GMU
,
1598 .insmodopt
= &tea6320
,
1599 .addr_lo
= I2C_ADDR_TEA6300
>> 1,
1600 .addr_hi
= I2C_ADDR_TEA6300
>> 1,
1602 .flags
= CHIP_HAS_VOLUME
| CHIP_HAS_BASSTREBLE
| CHIP_HAS_INPUTSEL
,
1604 .leftreg
= TEA6320_V
,
1605 .rightreg
= TEA6320_V
,
1606 .bassreg
= TEA6320_BA
,
1607 .treblereg
= TEA6320_TR
,
1610 .initialize
= tea6320_initialize
,
1611 .volfunc
= tea6320_volume
,
1612 .bassfunc
= tea6320_shift11
,
1613 .treblefunc
= tea6320_shift11
,
1615 .inputreg
= TEA6320_S
,
1616 .inputmap
= { TEA6320_S_SA
, TEA6420_S_SB
, TEA6300_S_SC
, TEA6320_S_SD
},
1617 .inputmute
= TEA6300_S_GMU
,
1621 .insmodopt
= &tea6420
,
1622 .addr_lo
= I2C_ADDR_TEA6420
>> 1,
1623 .addr_hi
= I2C_ADDR_TEA6420
>> 1,
1625 .flags
= CHIP_HAS_INPUTSEL
,
1628 .inputmap
= { TEA6420_S_SA
, TEA6420_S_SB
, TEA6420_S_SC
},
1629 .inputmute
= TEA6420_S_GMU
,
1634 .insmodopt
= &tda8425
,
1635 .addr_lo
= I2C_ADDR_TDA8425
>> 1,
1636 .addr_hi
= I2C_ADDR_TDA8425
>> 1,
1638 .flags
= CHIP_HAS_VOLUME
| CHIP_HAS_BASSTREBLE
| CHIP_HAS_INPUTSEL
,
1640 .leftreg
= TDA8425_VL
,
1641 .rightreg
= TDA8425_VR
,
1642 .bassreg
= TDA8425_BA
,
1643 .treblereg
= TDA8425_TR
,
1646 .volfunc
= tda8425_shift10
,
1647 .bassfunc
= tda8425_shift12
,
1648 .treblefunc
= tda8425_shift12
,
1649 .setaudmode
= tda8425_setaudmode
,
1651 .inputreg
= TDA8425_S1
,
1652 .inputmap
= { TDA8425_S1_CH1
, TDA8425_S1_CH1
, TDA8425_S1_CH1
},
1653 .inputmute
= TDA8425_S1_OFF
,
1657 .name
= "pic16c54 (PV951)",
1658 .insmodopt
= &pic16c54
,
1659 .addr_lo
= I2C_ADDR_PIC16C54
>> 1,
1660 .addr_hi
= I2C_ADDR_PIC16C54
>> 1,
1662 .flags
= CHIP_HAS_INPUTSEL
,
1664 .inputreg
= PIC16C54_REG_MISC
,
1665 .inputmap
= {PIC16C54_MISC_SND_NOTMUTE
|PIC16C54_MISC_SWITCH_TUNER
,
1666 PIC16C54_MISC_SND_NOTMUTE
|PIC16C54_MISC_SWITCH_LINE
,
1667 PIC16C54_MISC_SND_NOTMUTE
|PIC16C54_MISC_SWITCH_LINE
,
1668 PIC16C54_MISC_SND_MUTE
},
1669 .inputmute
= PIC16C54_MISC_SND_MUTE
,
1673 .checkit
= ta8874z_checkit
,
1674 .insmodopt
= &ta8874z
,
1675 .addr_lo
= I2C_ADDR_TDA9840
>> 1,
1676 .addr_hi
= I2C_ADDR_TDA9840
>> 1,
1680 .getrxsubchans
= ta8874z_getrxsubchans
,
1681 .setaudmode
= ta8874z_setaudmode
,
1683 .init
= {2, { TA8874Z_MONO_SET
, TA8874Z_SEPARATION_DEFAULT
}},
1685 { .name
= NULL
} /* EOF */
1689 /* ---------------------------------------------------------------------- */
1691 static int tvaudio_s_ctrl(struct v4l2_ctrl
*ctrl
)
1693 struct v4l2_subdev
*sd
= to_sd(ctrl
);
1694 struct CHIPSTATE
*chip
= to_state(sd
);
1695 struct CHIPDESC
*desc
= chip
->desc
;
1698 case V4L2_CID_AUDIO_MUTE
:
1699 chip
->muted
= ctrl
->val
;
1701 chip_write_masked(chip
,desc
->inputreg
,desc
->inputmute
,desc
->inputmask
);
1703 chip_write_masked(chip
,desc
->inputreg
,
1704 desc
->inputmap
[chip
->input
],desc
->inputmask
);
1706 case V4L2_CID_AUDIO_VOLUME
: {
1707 u32 volume
, balance
;
1710 volume
= chip
->volume
->val
;
1711 balance
= chip
->balance
->val
;
1712 left
= (min(65536U - balance
, 32768U) * volume
) / 32768U;
1713 right
= (min(balance
, 32768U) * volume
) / 32768U;
1715 chip_write(chip
, desc
->leftreg
, desc
->volfunc(left
));
1716 chip_write(chip
, desc
->rightreg
, desc
->volfunc(right
));
1719 case V4L2_CID_AUDIO_BASS
:
1720 chip_write(chip
, desc
->bassreg
, desc
->bassfunc(ctrl
->val
));
1722 case V4L2_CID_AUDIO_TREBLE
:
1723 chip_write(chip
, desc
->treblereg
, desc
->treblefunc(ctrl
->val
));
1730 /* ---------------------------------------------------------------------- */
1731 /* video4linux interface */
1733 static int tvaudio_s_radio(struct v4l2_subdev
*sd
)
1735 struct CHIPSTATE
*chip
= to_state(sd
);
1738 /* del_timer(&chip->wt); */
1742 static int tvaudio_s_routing(struct v4l2_subdev
*sd
,
1743 u32 input
, u32 output
, u32 config
)
1745 struct CHIPSTATE
*chip
= to_state(sd
);
1746 struct CHIPDESC
*desc
= chip
->desc
;
1748 if (!(desc
->flags
& CHIP_HAS_INPUTSEL
))
1752 /* There are four inputs: tuner, radio, extern and intern. */
1753 chip
->input
= input
;
1756 chip_write_masked(chip
, desc
->inputreg
,
1757 desc
->inputmap
[chip
->input
], desc
->inputmask
);
1761 static int tvaudio_s_tuner(struct v4l2_subdev
*sd
, const struct v4l2_tuner
*vt
)
1763 struct CHIPSTATE
*chip
= to_state(sd
);
1764 struct CHIPDESC
*desc
= chip
->desc
;
1766 if (!desc
->setaudmode
)
1771 switch (vt
->audmode
) {
1772 case V4L2_TUNER_MODE_MONO
:
1773 case V4L2_TUNER_MODE_STEREO
:
1774 case V4L2_TUNER_MODE_LANG1
:
1775 case V4L2_TUNER_MODE_LANG2
:
1776 case V4L2_TUNER_MODE_LANG1_LANG2
:
1781 chip
->audmode
= vt
->audmode
;
1784 wake_up_process(chip
->thread
);
1786 desc
->setaudmode(chip
, vt
->audmode
);
1791 static int tvaudio_g_tuner(struct v4l2_subdev
*sd
, struct v4l2_tuner
*vt
)
1793 struct CHIPSTATE
*chip
= to_state(sd
);
1794 struct CHIPDESC
*desc
= chip
->desc
;
1796 if (!desc
->getrxsubchans
)
1801 vt
->audmode
= chip
->audmode
;
1802 vt
->rxsubchans
= desc
->getrxsubchans(chip
);
1803 vt
->capability
|= V4L2_TUNER_CAP_STEREO
|
1804 V4L2_TUNER_CAP_LANG1
| V4L2_TUNER_CAP_LANG2
;
1809 static int tvaudio_s_std(struct v4l2_subdev
*sd
, v4l2_std_id std
)
1811 struct CHIPSTATE
*chip
= to_state(sd
);
1817 static int tvaudio_s_frequency(struct v4l2_subdev
*sd
, const struct v4l2_frequency
*freq
)
1819 struct CHIPSTATE
*chip
= to_state(sd
);
1820 struct CHIPDESC
*desc
= chip
->desc
;
1822 /* For chips that provide getrxsubchans and setaudmode, and doesn't
1823 automatically follows the stereo carrier, a kthread is
1824 created to set the audio standard. In this case, when then
1825 the video channel is changed, tvaudio starts on MONO mode.
1826 After waiting for 2 seconds, the kernel thread is called,
1827 to follow whatever audio standard is pointed by the
1831 desc
->setaudmode(chip
, V4L2_TUNER_MODE_MONO
);
1832 chip
->prevmode
= -1; /* reset previous mode */
1833 mod_timer(&chip
->wt
, jiffies
+msecs_to_jiffies(2000));
1838 static int tvaudio_log_status(struct v4l2_subdev
*sd
)
1840 struct CHIPSTATE
*chip
= to_state(sd
);
1841 struct CHIPDESC
*desc
= chip
->desc
;
1843 v4l2_info(sd
, "Chip: %s\n", desc
->name
);
1844 v4l2_ctrl_handler_log_status(&chip
->hdl
, sd
->name
);
1848 /* ----------------------------------------------------------------------- */
1850 static const struct v4l2_ctrl_ops tvaudio_ctrl_ops
= {
1851 .s_ctrl
= tvaudio_s_ctrl
,
1854 static const struct v4l2_subdev_core_ops tvaudio_core_ops
= {
1855 .log_status
= tvaudio_log_status
,
1858 static const struct v4l2_subdev_tuner_ops tvaudio_tuner_ops
= {
1859 .s_radio
= tvaudio_s_radio
,
1860 .s_frequency
= tvaudio_s_frequency
,
1861 .s_tuner
= tvaudio_s_tuner
,
1862 .g_tuner
= tvaudio_g_tuner
,
1865 static const struct v4l2_subdev_audio_ops tvaudio_audio_ops
= {
1866 .s_routing
= tvaudio_s_routing
,
1869 static const struct v4l2_subdev_video_ops tvaudio_video_ops
= {
1870 .s_std
= tvaudio_s_std
,
1873 static const struct v4l2_subdev_ops tvaudio_ops
= {
1874 .core
= &tvaudio_core_ops
,
1875 .tuner
= &tvaudio_tuner_ops
,
1876 .audio
= &tvaudio_audio_ops
,
1877 .video
= &tvaudio_video_ops
,
1880 /* ----------------------------------------------------------------------- */
1883 /* i2c registration */
1885 static int tvaudio_probe(struct i2c_client
*client
, const struct i2c_device_id
*id
)
1887 struct CHIPSTATE
*chip
;
1888 struct CHIPDESC
*desc
;
1889 struct v4l2_subdev
*sd
;
1892 printk(KERN_INFO
"tvaudio: TV audio decoder + audio/video mux driver\n");
1893 printk(KERN_INFO
"tvaudio: known chips: ");
1894 for (desc
= chiplist
; desc
->name
!= NULL
; desc
++)
1895 printk(KERN_CONT
"%s%s",
1896 (desc
== chiplist
) ? "" : ", ", desc
->name
);
1897 printk(KERN_CONT
"\n");
1900 chip
= devm_kzalloc(&client
->dev
, sizeof(*chip
), GFP_KERNEL
);
1904 v4l2_i2c_subdev_init(sd
, client
, &tvaudio_ops
);
1906 /* find description for the chip */
1907 v4l2_dbg(1, debug
, sd
, "chip found @ 0x%x\n", client
->addr
<<1);
1908 for (desc
= chiplist
; desc
->name
!= NULL
; desc
++) {
1909 if (0 == *(desc
->insmodopt
))
1911 if (client
->addr
< desc
->addr_lo
||
1912 client
->addr
> desc
->addr_hi
)
1914 if (desc
->checkit
&& !desc
->checkit(chip
))
1918 if (desc
->name
== NULL
) {
1919 v4l2_dbg(1, debug
, sd
, "no matching chip description found\n");
1922 v4l2_info(sd
, "%s found @ 0x%x (%s)\n", desc
->name
, client
->addr
<<1, client
->adapter
->name
);
1924 v4l2_dbg(1, debug
, sd
, "matches:%s%s%s.\n",
1925 (desc
->flags
& CHIP_HAS_VOLUME
) ? " volume" : "",
1926 (desc
->flags
& CHIP_HAS_BASSTREBLE
) ? " bass/treble" : "",
1927 (desc
->flags
& CHIP_HAS_INPUTSEL
) ? " audiomux" : "");
1930 /* fill required data structures */
1932 strlcpy(client
->name
, desc
->name
, I2C_NAME_SIZE
);
1934 chip
->shadow
.count
= desc
->registers
+1;
1935 chip
->prevmode
= -1;
1936 chip
->audmode
= V4L2_TUNER_MODE_LANG1
;
1938 /* initialization */
1939 if (desc
->initialize
!= NULL
)
1940 desc
->initialize(chip
);
1942 chip_cmd(chip
, "init", &desc
->init
);
1944 v4l2_ctrl_handler_init(&chip
->hdl
, 5);
1945 if (desc
->flags
& CHIP_HAS_INPUTSEL
)
1946 v4l2_ctrl_new_std(&chip
->hdl
, &tvaudio_ctrl_ops
,
1947 V4L2_CID_AUDIO_MUTE
, 0, 1, 1, 0);
1948 if (desc
->flags
& CHIP_HAS_VOLUME
) {
1949 if (!desc
->volfunc
) {
1950 /* This shouldn't be happen. Warn user, but keep working
1951 without volume controls
1953 v4l2_info(sd
, "volume callback undefined!\n");
1954 desc
->flags
&= ~CHIP_HAS_VOLUME
;
1956 chip
->volume
= v4l2_ctrl_new_std(&chip
->hdl
,
1957 &tvaudio_ctrl_ops
, V4L2_CID_AUDIO_VOLUME
,
1958 0, 65535, 65535 / 100,
1959 desc
->volinit
? desc
->volinit
: 65535);
1960 chip
->balance
= v4l2_ctrl_new_std(&chip
->hdl
,
1961 &tvaudio_ctrl_ops
, V4L2_CID_AUDIO_BALANCE
,
1962 0, 65535, 65535 / 100, 32768);
1963 v4l2_ctrl_cluster(2, &chip
->volume
);
1966 if (desc
->flags
& CHIP_HAS_BASSTREBLE
) {
1967 if (!desc
->bassfunc
|| !desc
->treblefunc
) {
1968 /* This shouldn't be happen. Warn user, but keep working
1969 without bass/treble controls
1971 v4l2_info(sd
, "bass/treble callbacks undefined!\n");
1972 desc
->flags
&= ~CHIP_HAS_BASSTREBLE
;
1974 v4l2_ctrl_new_std(&chip
->hdl
,
1975 &tvaudio_ctrl_ops
, V4L2_CID_AUDIO_BASS
,
1976 0, 65535, 65535 / 100,
1977 desc
->bassinit
? desc
->bassinit
: 32768);
1978 v4l2_ctrl_new_std(&chip
->hdl
,
1979 &tvaudio_ctrl_ops
, V4L2_CID_AUDIO_TREBLE
,
1980 0, 65535, 65535 / 100,
1981 desc
->trebleinit
? desc
->trebleinit
: 32768);
1985 sd
->ctrl_handler
= &chip
->hdl
;
1986 if (chip
->hdl
.error
) {
1987 int err
= chip
->hdl
.error
;
1989 v4l2_ctrl_handler_free(&chip
->hdl
);
1992 /* set controls to the default values */
1993 v4l2_ctrl_handler_setup(&chip
->hdl
);
1995 chip
->thread
= NULL
;
1996 timer_setup(&chip
->wt
, chip_thread_wake
, 0);
1997 if (desc
->flags
& CHIP_NEED_CHECKMODE
) {
1998 if (!desc
->getrxsubchans
|| !desc
->setaudmode
) {
1999 /* This shouldn't be happen. Warn user, but keep working
2002 v4l2_info(sd
, "set/get mode callbacks undefined!\n");
2005 /* start async thread */
2006 chip
->thread
= kthread_run(chip_thread
, chip
, "%s",
2008 if (IS_ERR(chip
->thread
)) {
2009 v4l2_warn(sd
, "failed to create kthread\n");
2010 chip
->thread
= NULL
;
2016 static int tvaudio_remove(struct i2c_client
*client
)
2018 struct v4l2_subdev
*sd
= i2c_get_clientdata(client
);
2019 struct CHIPSTATE
*chip
= to_state(sd
);
2021 del_timer_sync(&chip
->wt
);
2023 /* shutdown async thread */
2024 kthread_stop(chip
->thread
);
2025 chip
->thread
= NULL
;
2028 v4l2_device_unregister_subdev(sd
);
2029 v4l2_ctrl_handler_free(&chip
->hdl
);
2033 /* This driver supports many devices and the idea is to let the driver
2034 detect which device is present. So rather than listing all supported
2035 devices here, we pretend to support a single, fake device type. */
2036 static const struct i2c_device_id tvaudio_id
[] = {
2040 MODULE_DEVICE_TABLE(i2c
, tvaudio_id
);
2042 static struct i2c_driver tvaudio_driver
= {
2046 .probe
= tvaudio_probe
,
2047 .remove
= tvaudio_remove
,
2048 .id_table
= tvaudio_id
,
2051 module_i2c_driver(tvaudio_driver
);