1 // SPDX-License-Identifier: GPL-2.0
3 * Handlers for board audio hooks, split from bttv-cards
5 * Copyright (c) 2006 Mauro Carvalho Chehab <mchehab@kernel.org>
8 #include "bttv-audio-hook.h"
10 #include <linux/delay.h>
12 /* ----------------------------------------------------------------------- */
15 void winview_volume(struct bttv
*btv
, __u16 volume
)
17 /* PT2254A programming Jon Tombs, jon@gte.esi.us.es */
18 int bits_out
, loops
, vol
, data
;
20 /* 32 levels logarithmic */
21 vol
= 32 - ((volume
>>11));
23 bits_out
= (PT2254_DBS_IN_2
>>(vol
%5));
25 bits_out
|= (PT2254_DBS_IN_10
>>(vol
/5));
26 bits_out
|= PT2254_L_CHANNEL
| PT2254_R_CHANNEL
;
28 data
&= ~(WINVIEW_PT2254_CLK
| WINVIEW_PT2254_DATA
|
29 WINVIEW_PT2254_STROBE
);
30 for (loops
= 17; loops
>= 0 ; loops
--) {
31 if (bits_out
& (1<<loops
))
32 data
|= WINVIEW_PT2254_DATA
;
34 data
&= ~WINVIEW_PT2254_DATA
;
37 data
|= WINVIEW_PT2254_CLK
;
40 data
&= ~WINVIEW_PT2254_CLK
;
43 data
|= WINVIEW_PT2254_STROBE
;
44 data
&= ~WINVIEW_PT2254_DATA
;
47 data
&= ~WINVIEW_PT2254_STROBE
;
51 /* ----------------------------------------------------------------------- */
52 /* mono/stereo control for various cards (which don't use i2c chips but */
53 /* connect something to the GPIO pins */
55 void gvbctv3pci_audio(struct bttv
*btv
, struct v4l2_tuner
*t
, int set
)
60 /* Not much to do here */
61 t
->audmode
= V4L2_TUNER_MODE_LANG1
;
62 t
->rxsubchans
= V4L2_TUNER_SUB_MONO
|
63 V4L2_TUNER_SUB_STEREO
|
64 V4L2_TUNER_SUB_LANG1
|
70 gpio_inout(0x300, 0x300);
72 case V4L2_TUNER_MODE_LANG1
:
76 case V4L2_TUNER_MODE_LANG2
:
79 case V4L2_TUNER_MODE_STEREO
:
83 gpio_bits(0x300, con
);
86 void gvbctv5pci_audio(struct bttv
*btv
, struct v4l2_tuner
*t
, int set
)
88 unsigned int val
, con
;
96 case V4L2_TUNER_MODE_LANG2
:
99 case V4L2_TUNER_MODE_LANG1_LANG2
:
106 if (con
!= (val
& 0x300)) {
107 gpio_bits(0x300, con
);
109 bttv_gpio_tracking(btv
, "gvbctv5pci");
112 switch (val
& 0x70) {
114 t
->rxsubchans
= V4L2_TUNER_SUB_LANG1
| V4L2_TUNER_SUB_LANG2
;
115 t
->audmode
= V4L2_TUNER_MODE_LANG1_LANG2
;
118 t
->rxsubchans
= V4L2_TUNER_SUB_LANG2
;
119 t
->audmode
= V4L2_TUNER_MODE_LANG1_LANG2
;
122 t
->rxsubchans
= V4L2_TUNER_SUB_LANG1
;
123 t
->audmode
= V4L2_TUNER_MODE_LANG1_LANG2
;
126 t
->rxsubchans
= V4L2_TUNER_SUB_STEREO
;
127 t
->audmode
= V4L2_TUNER_MODE_STEREO
;
130 t
->rxsubchans
= V4L2_TUNER_SUB_MONO
;
131 t
->audmode
= V4L2_TUNER_MODE_MONO
;
134 t
->rxsubchans
= V4L2_TUNER_SUB_MONO
|
135 V4L2_TUNER_SUB_STEREO
|
136 V4L2_TUNER_SUB_LANG1
|
137 V4L2_TUNER_SUB_LANG2
;
138 t
->audmode
= V4L2_TUNER_MODE_LANG1
;
144 * Mario Medina Nussbaum <medisoft@alohabbs.org.mx>
145 * I discover that on BT848_GPIO_DATA address a byte 0xcce enable stereo,
146 * 0xdde enables mono and 0xccd enables sap
148 * Petr Vandrovec <VANDROVE@vc.cvut.cz>
149 * P.S.: At least mask in line above is wrong - GPIO pins 3,2 select
150 * input/output sound connection, so both must be set for output mode.
152 * Looks like it's needed only for the "tvphone", the "tvphone 98"
153 * handles this with a tda9840
157 void avermedia_tvphone_audio(struct bttv
*btv
, struct v4l2_tuner
*t
, int set
)
162 /* Not much to do here */
163 t
->audmode
= V4L2_TUNER_MODE_LANG1
;
164 t
->rxsubchans
= V4L2_TUNER_SUB_MONO
|
165 V4L2_TUNER_SUB_STEREO
|
166 V4L2_TUNER_SUB_LANG1
|
167 V4L2_TUNER_SUB_LANG2
;
172 switch (t
->audmode
) {
173 case V4L2_TUNER_MODE_LANG2
: /* SAP */
176 case V4L2_TUNER_MODE_STEREO
:
182 gpio_bits(0x03, val
);
184 bttv_gpio_tracking(btv
, "avermedia");
188 void avermedia_tv_stereo_audio(struct bttv
*btv
, struct v4l2_tuner
*t
, int set
)
193 /* Not much to do here */
194 t
->audmode
= V4L2_TUNER_MODE_LANG1
;
195 t
->rxsubchans
= V4L2_TUNER_SUB_MONO
|
196 V4L2_TUNER_SUB_STEREO
|
197 V4L2_TUNER_SUB_LANG1
|
198 V4L2_TUNER_SUB_LANG2
;
203 switch (t
->audmode
) {
204 case V4L2_TUNER_MODE_LANG2
: /* SAP */
207 case V4L2_TUNER_MODE_STEREO
:
214 btaor(val
, ~0x03, BT848_GPIO_DATA
);
216 bttv_gpio_tracking(btv
, "avermedia");
219 /* Lifetec 9415 handling */
221 void lt9415_audio(struct bttv
*btv
, struct v4l2_tuner
*t
, int set
)
225 if (gpio_read() & 0x4000) {
226 t
->audmode
= V4L2_TUNER_MODE_MONO
;
231 /* Not much to do here */
232 t
->audmode
= V4L2_TUNER_MODE_LANG1
;
233 t
->rxsubchans
= V4L2_TUNER_SUB_MONO
|
234 V4L2_TUNER_SUB_STEREO
|
235 V4L2_TUNER_SUB_LANG1
|
236 V4L2_TUNER_SUB_LANG2
;
241 switch (t
->audmode
) {
242 case V4L2_TUNER_MODE_LANG2
: /* A2 SAP */
245 case V4L2_TUNER_MODE_STEREO
: /* A2 stereo */
253 gpio_bits(0x0880, val
);
255 bttv_gpio_tracking(btv
, "lt9415");
258 /* TDA9821 on TerraTV+ Bt848, Bt878 */
259 void terratv_audio(struct bttv
*btv
, struct v4l2_tuner
*t
, int set
)
261 unsigned int con
= 0;
264 /* Not much to do here */
265 t
->audmode
= V4L2_TUNER_MODE_LANG1
;
266 t
->rxsubchans
= V4L2_TUNER_SUB_MONO
|
267 V4L2_TUNER_SUB_STEREO
|
268 V4L2_TUNER_SUB_LANG1
|
269 V4L2_TUNER_SUB_LANG2
;
274 gpio_inout(0x180000, 0x180000);
275 switch (t
->audmode
) {
276 case V4L2_TUNER_MODE_LANG2
:
279 case V4L2_TUNER_MODE_STEREO
:
286 gpio_bits(0x180000, con
);
288 bttv_gpio_tracking(btv
, "terratv");
292 void winfast2000_audio(struct bttv
*btv
, struct v4l2_tuner
*t
, int set
)
297 /* Not much to do here */
298 t
->audmode
= V4L2_TUNER_MODE_LANG1
;
299 t
->rxsubchans
= V4L2_TUNER_SUB_MONO
|
300 V4L2_TUNER_SUB_STEREO
|
301 V4L2_TUNER_SUB_LANG1
|
302 V4L2_TUNER_SUB_LANG2
;
307 /*btor (0xc32000, BT848_GPIO_OUT_EN);*/
308 switch (t
->audmode
) {
309 case V4L2_TUNER_MODE_MONO
:
310 case V4L2_TUNER_MODE_LANG1
:
313 case V4L2_TUNER_MODE_LANG2
: /* SAP */
316 case V4L2_TUNER_MODE_STEREO
:
323 gpio_bits(0x430000, val
);
325 bttv_gpio_tracking(btv
, "winfast2000");
329 * Dariusz Kowalewski <darekk@automex.pl>
330 * sound control for Prolink PV-BT878P+9B (PixelView PlayTV Pro FM+NICAM
331 * revision 9B has on-board TDA9874A sound decoder).
333 * Note: There are card variants without tda9874a. Forcing the "stereo sound route"
334 * will mute this cards.
336 void pvbt878p9b_audio(struct bttv
*btv
, struct v4l2_tuner
*t
, int set
)
338 unsigned int val
= 0;
344 /* Not much to do here */
345 t
->audmode
= V4L2_TUNER_MODE_LANG1
;
346 t
->rxsubchans
= V4L2_TUNER_SUB_MONO
|
347 V4L2_TUNER_SUB_STEREO
|
348 V4L2_TUNER_SUB_LANG1
|
349 V4L2_TUNER_SUB_LANG2
;
354 switch (t
->audmode
) {
355 case V4L2_TUNER_MODE_MONO
:
358 case V4L2_TUNER_MODE_LANG1
:
359 case V4L2_TUNER_MODE_LANG2
:
360 case V4L2_TUNER_MODE_STEREO
:
367 gpio_bits(0x03, val
);
369 bttv_gpio_tracking(btv
, "pvbt878p9b");
373 * Dariusz Kowalewski <darekk@automex.pl>
374 * sound control for FlyVideo 2000S (with tda9874 decoder)
375 * based on pvbt878p9b_audio() - this is not tested, please fix!!!
377 void fv2000s_audio(struct bttv
*btv
, struct v4l2_tuner
*t
, int set
)
385 /* Not much to do here */
386 t
->audmode
= V4L2_TUNER_MODE_LANG1
;
387 t
->rxsubchans
= V4L2_TUNER_SUB_MONO
|
388 V4L2_TUNER_SUB_STEREO
|
389 V4L2_TUNER_SUB_LANG1
|
390 V4L2_TUNER_SUB_LANG2
;
395 switch (t
->audmode
) {
396 case V4L2_TUNER_MODE_MONO
:
399 case V4L2_TUNER_MODE_LANG1
:
400 case V4L2_TUNER_MODE_LANG2
:
401 case V4L2_TUNER_MODE_STEREO
:
402 val
= 0x1080; /*-dk-???: 0x0880, 0x0080, 0x1800 ... */
407 gpio_bits(0x1800, val
);
409 bttv_gpio_tracking(btv
, "fv2000s");
413 * sound control for Canopus WinDVR PCI
414 * Masaki Suzuki <masaki@btree.org>
416 void windvr_audio(struct bttv
*btv
, struct v4l2_tuner
*t
, int set
)
421 /* Not much to do here */
422 t
->audmode
= V4L2_TUNER_MODE_LANG1
;
423 t
->rxsubchans
= V4L2_TUNER_SUB_MONO
|
424 V4L2_TUNER_SUB_STEREO
|
425 V4L2_TUNER_SUB_LANG1
|
426 V4L2_TUNER_SUB_LANG2
;
431 switch (t
->audmode
) {
432 case V4L2_TUNER_MODE_MONO
:
435 case V4L2_TUNER_MODE_LANG2
:
442 gpio_bits(0x140000, val
);
444 bttv_gpio_tracking(btv
, "windvr");
448 * sound control for AD-TVK503
449 * Hiroshi Takekawa <sian@big.or.jp>
451 void adtvk503_audio(struct bttv
*btv
, struct v4l2_tuner
*t
, int set
)
453 unsigned int con
= 0xffffff;
455 /* btaor(0x1e0000, ~0x1e0000, BT848_GPIO_OUT_EN); */
458 /* Not much to do here */
459 t
->audmode
= V4L2_TUNER_MODE_LANG1
;
460 t
->rxsubchans
= V4L2_TUNER_SUB_MONO
|
461 V4L2_TUNER_SUB_STEREO
|
462 V4L2_TUNER_SUB_LANG1
|
463 V4L2_TUNER_SUB_LANG2
;
468 /* btor(***, BT848_GPIO_OUT_EN); */
469 switch (t
->audmode
) {
470 case V4L2_TUNER_MODE_LANG1
:
473 case V4L2_TUNER_MODE_LANG2
:
476 case V4L2_TUNER_MODE_STEREO
:
479 case V4L2_TUNER_MODE_MONO
:
486 gpio_bits(0x1e0000, con
);
488 bttv_gpio_tracking(btv
, "adtvk503");