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->audmode = V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
107 t->audmode = V4L2_TUNER_MODE_LANG2;
110 t->audmode = V4L2_TUNER_MODE_LANG1;
113 t->audmode = V4L2_TUNER_MODE_STEREO;
116 t->audmode = V4L2_TUNER_MODE_MONO;
119 t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
120 V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
126 * Mario Medina Nussbaum <medisoft@alohabbs.org.mx>
127 * I discover that on BT848_GPIO_DATA address a byte 0xcce enable stereo,
128 * 0xdde enables mono and 0xccd enables sap
130 * Petr Vandrovec <VANDROVE@vc.cvut.cz>
131 * P.S.: At least mask in line above is wrong - GPIO pins 3,2 select
132 * input/output sound connection, so both must be set for output mode.
134 * Looks like it's needed only for the "tvphone", the "tvphone 98"
135 * handles this with a tda9840
139 void avermedia_tvphone_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
144 if (t->audmode & V4L2_TUNER_MODE_LANG2) /* SAP */
146 if (t->audmode & V4L2_TUNER_MODE_STEREO)
151 bttv_gpio_tracking(btv,"avermedia");
154 t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
155 V4L2_TUNER_MODE_LANG1;
161 void avermedia_tv_stereo_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
166 if (t->audmode & V4L2_TUNER_MODE_LANG2) /* SAP */
168 if (t->audmode & V4L2_TUNER_MODE_STEREO) /* STEREO */
170 btaor(val, ~0x03, BT848_GPIO_DATA);
172 bttv_gpio_tracking(btv,"avermedia");
174 t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
175 V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
180 /* Lifetec 9415 handling */
182 void lt9415_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
186 if (gpio_read() & 0x4000) {
187 t->audmode = V4L2_TUNER_MODE_MONO;
192 if (t->audmode & V4L2_TUNER_MODE_LANG2) /* A2 SAP */
194 if (t->audmode & V4L2_TUNER_MODE_STEREO) /* A2 stereo */
196 if ((t->audmode & V4L2_TUNER_MODE_LANG1) ||
197 (t->audmode & V4L2_TUNER_MODE_MONO))
199 gpio_bits(0x0880, val);
201 bttv_gpio_tracking(btv,"lt9415");
203 /* autodetect doesn't work with this card :-( */
204 t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
205 V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
210 /* TDA9821 on TerraTV+ Bt848, Bt878 */
211 void terratv_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
213 unsigned int con = 0;
216 gpio_inout(0x180000,0x180000);
217 if (t->audmode & V4L2_TUNER_MODE_LANG2)
219 if (t->audmode & V4L2_TUNER_MODE_STEREO)
221 gpio_bits(0x180000, con);
223 bttv_gpio_tracking(btv,"terratv");
225 t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
226 V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
231 void winfast2000_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
233 unsigned long val = 0;
236 /*btor (0xc32000, BT848_GPIO_OUT_EN);*/
237 if (t->audmode & V4L2_TUNER_MODE_MONO) /* Mono */
239 if (t->audmode & V4L2_TUNER_MODE_LANG1) /* Mono */
241 if (t->audmode & V4L2_TUNER_MODE_LANG2) /* SAP */
243 if (t->audmode & V4L2_TUNER_MODE_STEREO) /* Stereo */
246 gpio_bits(0x430000, val);
248 bttv_gpio_tracking(btv,"winfast2000");
251 t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
252 V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
257 * Dariusz Kowalewski <darekk@automex.pl>
258 * sound control for Prolink PV-BT878P+9B (PixelView PlayTV Pro FM+NICAM
259 * revision 9B has on-board TDA9874A sound decoder).
261 * Note: There are card variants without tda9874a. Forcing the "stereo sound route"
262 * will mute this cards.
264 void pvbt878p9b_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
266 unsigned int val = 0;
272 if (t->audmode & V4L2_TUNER_MODE_MONO) {
275 if ((t->audmode & (V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2))
276 || (t->audmode & V4L2_TUNER_MODE_STEREO)) {
282 bttv_gpio_tracking(btv,"pvbt878p9b");
285 t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
286 V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
291 * Dariusz Kowalewski <darekk@automex.pl>
292 * sound control for FlyVideo 2000S (with tda9874 decoder)
293 * based on pvbt878p9b_audio() - this is not tested, please fix!!!
295 void fv2000s_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
297 unsigned int val = 0xffff;
303 if (t->audmode & V4L2_TUNER_MODE_MONO) {
306 if ((t->audmode & (V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2))
307 || (t->audmode & V4L2_TUNER_MODE_STEREO)) {
308 val = 0x1080; /*-dk-???: 0x0880, 0x0080, 0x1800 ... */
311 gpio_bits(0x1800, val);
313 bttv_gpio_tracking(btv,"fv2000s");
316 t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
317 V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
322 * sound control for Canopus WinDVR PCI
323 * Masaki Suzuki <masaki@btree.org>
325 void windvr_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
327 unsigned long val = 0;
330 if (t->audmode & V4L2_TUNER_MODE_MONO)
332 if (t->audmode & V4L2_TUNER_MODE_LANG1)
334 if (t->audmode & V4L2_TUNER_MODE_LANG2)
336 if (t->audmode & V4L2_TUNER_MODE_STEREO)
339 gpio_bits(0x140000, val);
341 bttv_gpio_tracking(btv,"windvr");
344 t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
345 V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
350 * sound control for AD-TVK503
351 * Hiroshi Takekawa <sian@big.or.jp>
353 void adtvk503_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
355 unsigned int con = 0xffffff;
357 /* btaor(0x1e0000, ~0x1e0000, BT848_GPIO_OUT_EN); */
360 /* btor(***, BT848_GPIO_OUT_EN); */
361 if (t->audmode & V4L2_TUNER_MODE_LANG1)
363 if (t->audmode & V4L2_TUNER_MODE_LANG2)
365 if (t->audmode & V4L2_TUNER_MODE_STEREO)
367 if (t->audmode & V4L2_TUNER_MODE_MONO)
369 if (con != 0xffffff) {
370 gpio_bits(0x1e0000,con);
372 bttv_gpio_tracking(btv, "adtvk503");
375 t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
376 V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;