Merge branch 'fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux...
[linux/fpc-iii.git] / drivers / media / pci / bt8xx / bttv-audio-hook.c
blob9f1f9169fb5b4e2f7716e1940547350872dc39fa
1 /*
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
6 */
8 #include "bttv-audio-hook.h"
10 #include <linux/delay.h>
12 /* ----------------------------------------------------------------------- */
13 /* winview */
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));
22 /* units */
23 bits_out = (PT2254_DBS_IN_2>>(vol%5));
24 /* tens */
25 bits_out |= (PT2254_DBS_IN_10>>(vol/5));
26 bits_out |= PT2254_L_CHANNEL | PT2254_R_CHANNEL;
27 data = gpio_read();
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;
33 else
34 data &= ~WINVIEW_PT2254_DATA;
35 gpio_write(data);
36 udelay(5);
37 data |= WINVIEW_PT2254_CLK;
38 gpio_write(data);
39 udelay(5);
40 data &= ~WINVIEW_PT2254_CLK;
41 gpio_write(data);
43 data |= WINVIEW_PT2254_STROBE;
44 data &= ~WINVIEW_PT2254_DATA;
45 gpio_write(data);
46 udelay(10);
47 data &= ~WINVIEW_PT2254_STROBE;
48 gpio_write(data);
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)
57 unsigned int con;
59 if (!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 |
65 V4L2_TUNER_SUB_LANG2;
67 return;
70 gpio_inout(0x300, 0x300);
71 switch (t->audmode) {
72 case V4L2_TUNER_MODE_LANG1:
73 default:
74 con = 0x000;
75 break;
76 case V4L2_TUNER_MODE_LANG2:
77 con = 0x300;
78 break;
79 case V4L2_TUNER_MODE_STEREO:
80 con = 0x200;
81 break;
83 gpio_bits(0x300, con);
86 void gvbctv5pci_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
88 unsigned int val, con;
90 if (btv->radio_user)
91 return;
93 val = gpio_read();
94 if (set) {
95 switch (t->audmode) {
96 case V4L2_TUNER_MODE_LANG2:
97 con = 0x300;
98 break;
99 case V4L2_TUNER_MODE_LANG1_LANG2:
100 con = 0x100;
101 break;
102 default:
103 con = 0x000;
104 break;
106 if (con != (val & 0x300)) {
107 gpio_bits(0x300, con);
108 if (bttv_gpio)
109 bttv_gpio_tracking(btv, "gvbctv5pci");
111 } else {
112 switch (val & 0x70) {
113 case 0x10:
114 t->rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
115 t->audmode = V4L2_TUNER_MODE_LANG1_LANG2;
116 break;
117 case 0x30:
118 t->rxsubchans = V4L2_TUNER_SUB_LANG2;
119 t->audmode = V4L2_TUNER_MODE_LANG1_LANG2;
120 break;
121 case 0x50:
122 t->rxsubchans = V4L2_TUNER_SUB_LANG1;
123 t->audmode = V4L2_TUNER_MODE_LANG1_LANG2;
124 break;
125 case 0x60:
126 t->rxsubchans = V4L2_TUNER_SUB_STEREO;
127 t->audmode = V4L2_TUNER_MODE_STEREO;
128 break;
129 case 0x70:
130 t->rxsubchans = V4L2_TUNER_SUB_MONO;
131 t->audmode = V4L2_TUNER_MODE_MONO;
132 break;
133 default:
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)
159 int val;
161 if (!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;
169 return;
172 switch (t->audmode) {
173 case V4L2_TUNER_MODE_LANG2: /* SAP */
174 val = 0x02;
175 break;
176 case V4L2_TUNER_MODE_STEREO:
177 val = 0x01;
178 break;
179 default:
180 return;
182 gpio_bits(0x03, val);
183 if (bttv_gpio)
184 bttv_gpio_tracking(btv, "avermedia");
188 void avermedia_tv_stereo_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
190 int val = 0;
192 if (!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;
200 return;
203 switch (t->audmode) {
204 case V4L2_TUNER_MODE_LANG2: /* SAP */
205 val = 0x01;
206 break;
207 case V4L2_TUNER_MODE_STEREO:
208 val = 0x02;
209 break;
210 default:
211 val = 0;
212 break;
214 btaor(val, ~0x03, BT848_GPIO_DATA);
215 if (bttv_gpio)
216 bttv_gpio_tracking(btv, "avermedia");
219 /* Lifetec 9415 handling */
221 void lt9415_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
223 int val = 0;
225 if (gpio_read() & 0x4000) {
226 t->audmode = V4L2_TUNER_MODE_MONO;
227 return;
230 if (!set) {
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;
238 return;
241 switch (t->audmode) {
242 case V4L2_TUNER_MODE_LANG2: /* A2 SAP */
243 val = 0x0080;
244 break;
245 case V4L2_TUNER_MODE_STEREO: /* A2 stereo */
246 val = 0x0880;
247 break;
248 default:
249 val = 0;
250 break;
253 gpio_bits(0x0880, val);
254 if (bttv_gpio)
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;
263 if (!set) {
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;
271 return;
274 gpio_inout(0x180000, 0x180000);
275 switch (t->audmode) {
276 case V4L2_TUNER_MODE_LANG2:
277 con = 0x080000;
278 break;
279 case V4L2_TUNER_MODE_STEREO:
280 con = 0x180000;
281 break;
282 default:
283 con = 0;
284 break;
286 gpio_bits(0x180000, con);
287 if (bttv_gpio)
288 bttv_gpio_tracking(btv, "terratv");
292 void winfast2000_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
294 unsigned long val;
296 if (!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;
304 return;
307 /*btor (0xc32000, BT848_GPIO_OUT_EN);*/
308 switch (t->audmode) {
309 case V4L2_TUNER_MODE_MONO:
310 case V4L2_TUNER_MODE_LANG1:
311 val = 0x420000;
312 break;
313 case V4L2_TUNER_MODE_LANG2: /* SAP */
314 val = 0x410000;
315 break;
316 case V4L2_TUNER_MODE_STEREO:
317 val = 0x020000;
318 break;
319 default:
320 return;
323 gpio_bits(0x430000, val);
324 if (bttv_gpio)
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;
340 if (btv->radio_user)
341 return;
343 if (!set) {
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;
351 return;
354 switch (t->audmode) {
355 case V4L2_TUNER_MODE_MONO:
356 val = 0x01;
357 break;
358 case V4L2_TUNER_MODE_LANG1:
359 case V4L2_TUNER_MODE_LANG2:
360 case V4L2_TUNER_MODE_STEREO:
361 val = 0x02;
362 break;
363 default:
364 return;
367 gpio_bits(0x03, val);
368 if (bttv_gpio)
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)
379 unsigned int val;
381 if (btv->radio_user)
382 return;
384 if (!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;
392 return;
395 switch (t->audmode) {
396 case V4L2_TUNER_MODE_MONO:
397 val = 0x0000;
398 break;
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 ... */
403 break;
404 default:
405 return;
407 gpio_bits(0x1800, val);
408 if (bttv_gpio)
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)
418 unsigned long val;
420 if (!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;
428 return;
431 switch (t->audmode) {
432 case V4L2_TUNER_MODE_MONO:
433 val = 0x040000;
434 break;
435 case V4L2_TUNER_MODE_LANG2:
436 val = 0x100000;
437 break;
438 default:
439 return;
442 gpio_bits(0x140000, val);
443 if (bttv_gpio)
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); */
457 if (!set) {
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;
465 return;
468 /* btor(***, BT848_GPIO_OUT_EN); */
469 switch (t->audmode) {
470 case V4L2_TUNER_MODE_LANG1:
471 con = 0x00000000;
472 break;
473 case V4L2_TUNER_MODE_LANG2:
474 con = 0x00180000;
475 break;
476 case V4L2_TUNER_MODE_STEREO:
477 con = 0x00000000;
478 break;
479 case V4L2_TUNER_MODE_MONO:
480 con = 0x00060000;
481 break;
482 default:
483 return;
486 gpio_bits(0x1e0000, con);
487 if (bttv_gpio)
488 bttv_gpio_tracking(btv, "adtvk503");