2 * Handlers for board audio hooks, splitted from bttv-cards
4 * Copyright (c) 2006 Mauro Carvalho Chehab (mchehab@infradead.org)
5 * This code is placed under the terms of the GNU General Public License
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 gpio_inout(0x300, 0x300);
61 if (t->audmode & V4L2_TUNER_MODE_LANG1)
63 if (t->audmode & V4L2_TUNER_MODE_LANG2)
65 if (t->audmode & V4L2_TUNER_MODE_STEREO)
67 /* if (t->audmode & V4L2_TUNER_MODE_MONO)
69 gpio_bits(0x300, con);
71 t->audmode = V4L2_TUNER_MODE_STEREO |
72 V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
76 void gvbctv5pci_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
78 unsigned int val, con;
86 if (t->audmode & V4L2_TUNER_MODE_LANG2) {
87 if (t->audmode & V4L2_TUNER_MODE_LANG1) {
96 if (con != (val & 0x300)) {
97 gpio_bits(0x300, con);
99 bttv_gpio_tracking(btv,"gvbctv5pci");
102 switch (val & 0x70) {
104 t->rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
107 t->rxsubchans = V4L2_TUNER_SUB_LANG2;
110 t->rxsubchans = V4L2_TUNER_SUB_LANG1;
113 t->rxsubchans = V4L2_TUNER_SUB_STEREO;
116 t->rxsubchans = V4L2_TUNER_SUB_MONO;
119 t->rxsubchans = V4L2_TUNER_SUB_MONO |
120 V4L2_TUNER_SUB_STEREO |
121 V4L2_TUNER_SUB_LANG1 |
122 V4L2_TUNER_SUB_LANG2;
124 t->audmode = V4L2_TUNER_MODE_STEREO |
125 V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
130 * Mario Medina Nussbaum <medisoft@alohabbs.org.mx>
131 * I discover that on BT848_GPIO_DATA address a byte 0xcce enable stereo,
132 * 0xdde enables mono and 0xccd enables sap
134 * Petr Vandrovec <VANDROVE@vc.cvut.cz>
135 * P.S.: At least mask in line above is wrong - GPIO pins 3,2 select
136 * input/output sound connection, so both must be set for output mode.
138 * Looks like it's needed only for the "tvphone", the "tvphone 98"
139 * handles this with a tda9840
143 void avermedia_tvphone_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
148 if (t->audmode & V4L2_TUNER_MODE_LANG2) /* SAP */
150 if (t->audmode & V4L2_TUNER_MODE_STEREO)
155 bttv_gpio_tracking(btv,"avermedia");
158 t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
159 V4L2_TUNER_MODE_LANG1;
165 void avermedia_tv_stereo_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
170 if (t->audmode & V4L2_TUNER_MODE_LANG2) /* SAP */
172 if (t->audmode & V4L2_TUNER_MODE_STEREO) /* STEREO */
174 btaor(val, ~0x03, BT848_GPIO_DATA);
176 bttv_gpio_tracking(btv,"avermedia");
178 t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
179 V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
184 /* Lifetec 9415 handling */
186 void lt9415_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
190 if (gpio_read() & 0x4000) {
191 t->audmode = V4L2_TUNER_MODE_MONO;
196 if (t->audmode & V4L2_TUNER_MODE_LANG2) /* A2 SAP */
198 if (t->audmode & V4L2_TUNER_MODE_STEREO) /* A2 stereo */
200 if ((t->audmode & V4L2_TUNER_MODE_LANG1) ||
201 (t->audmode & V4L2_TUNER_MODE_MONO))
203 gpio_bits(0x0880, val);
205 bttv_gpio_tracking(btv,"lt9415");
207 /* autodetect doesn't work with this card :-( */
208 t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
209 V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
214 /* TDA9821 on TerraTV+ Bt848, Bt878 */
215 void terratv_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
217 unsigned int con = 0;
220 gpio_inout(0x180000,0x180000);
221 if (t->audmode & V4L2_TUNER_MODE_LANG2)
223 if (t->audmode & V4L2_TUNER_MODE_STEREO)
225 gpio_bits(0x180000, con);
227 bttv_gpio_tracking(btv,"terratv");
229 t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
230 V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
235 void winfast2000_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
237 unsigned long val = 0;
240 /*btor (0xc32000, BT848_GPIO_OUT_EN);*/
241 if (t->audmode & V4L2_TUNER_MODE_MONO) /* Mono */
243 if (t->audmode & V4L2_TUNER_MODE_LANG1) /* Mono */
245 if (t->audmode & V4L2_TUNER_MODE_LANG2) /* SAP */
247 if (t->audmode & V4L2_TUNER_MODE_STEREO) /* Stereo */
250 gpio_bits(0x430000, val);
252 bttv_gpio_tracking(btv,"winfast2000");
255 t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
256 V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
261 * Dariusz Kowalewski <darekk@automex.pl>
262 * sound control for Prolink PV-BT878P+9B (PixelView PlayTV Pro FM+NICAM
263 * revision 9B has on-board TDA9874A sound decoder).
265 * Note: There are card variants without tda9874a. Forcing the "stereo sound route"
266 * will mute this cards.
268 void pvbt878p9b_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
270 unsigned int val = 0;
276 if (t->audmode & V4L2_TUNER_MODE_MONO) {
279 if ((t->audmode & (V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2))
280 || (t->audmode & V4L2_TUNER_MODE_STEREO)) {
286 bttv_gpio_tracking(btv,"pvbt878p9b");
289 t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
290 V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
295 * Dariusz Kowalewski <darekk@automex.pl>
296 * sound control for FlyVideo 2000S (with tda9874 decoder)
297 * based on pvbt878p9b_audio() - this is not tested, please fix!!!
299 void fv2000s_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
301 unsigned int val = 0xffff;
307 if (t->audmode & V4L2_TUNER_MODE_MONO) {
310 if ((t->audmode & (V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2))
311 || (t->audmode & V4L2_TUNER_MODE_STEREO)) {
312 val = 0x1080; /*-dk-???: 0x0880, 0x0080, 0x1800 ... */
315 gpio_bits(0x1800, val);
317 bttv_gpio_tracking(btv,"fv2000s");
320 t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
321 V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
326 * sound control for Canopus WinDVR PCI
327 * Masaki Suzuki <masaki@btree.org>
329 void windvr_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
331 unsigned long val = 0;
334 if (t->audmode & V4L2_TUNER_MODE_MONO)
336 if (t->audmode & V4L2_TUNER_MODE_LANG1)
338 if (t->audmode & V4L2_TUNER_MODE_LANG2)
340 if (t->audmode & V4L2_TUNER_MODE_STEREO)
343 gpio_bits(0x140000, val);
345 bttv_gpio_tracking(btv,"windvr");
348 t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
349 V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
354 * sound control for AD-TVK503
355 * Hiroshi Takekawa <sian@big.or.jp>
357 void adtvk503_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
359 unsigned int con = 0xffffff;
361 /* btaor(0x1e0000, ~0x1e0000, BT848_GPIO_OUT_EN); */
364 /* btor(***, BT848_GPIO_OUT_EN); */
365 if (t->audmode & V4L2_TUNER_MODE_LANG1)
367 if (t->audmode & V4L2_TUNER_MODE_LANG2)
369 if (t->audmode & V4L2_TUNER_MODE_STEREO)
371 if (t->audmode & V4L2_TUNER_MODE_MONO)
373 if (con != 0xffffff) {
374 gpio_bits(0x1e0000,con);
376 bttv_gpio_tracking(btv, "adtvk503");
379 t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
380 V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;