bttv-audio-hook.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. /*
  2. * Handlers for board audio hooks, splitted from bttv-cards
  3. *
  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. */
  7. #include "bttv-audio-hook.h"
  8. #include <linux/delay.h>
  9. /* ----------------------------------------------------------------------- */
  10. /* winview */
  11. void winview_volume(struct bttv *btv, __u16 volume)
  12. {
  13. /* PT2254A programming Jon Tombs, jon@gte.esi.us.es */
  14. int bits_out, loops, vol, data;
  15. /* 32 levels logarithmic */
  16. vol = 32 - ((volume>>11));
  17. /* units */
  18. bits_out = (PT2254_DBS_IN_2>>(vol%5));
  19. /* tens */
  20. bits_out |= (PT2254_DBS_IN_10>>(vol/5));
  21. bits_out |= PT2254_L_CHANNEL | PT2254_R_CHANNEL;
  22. data = gpio_read();
  23. data &= ~(WINVIEW_PT2254_CLK| WINVIEW_PT2254_DATA|
  24. WINVIEW_PT2254_STROBE);
  25. for (loops = 17; loops >= 0 ; loops--) {
  26. if (bits_out & (1<<loops))
  27. data |= WINVIEW_PT2254_DATA;
  28. else
  29. data &= ~WINVIEW_PT2254_DATA;
  30. gpio_write(data);
  31. udelay(5);
  32. data |= WINVIEW_PT2254_CLK;
  33. gpio_write(data);
  34. udelay(5);
  35. data &= ~WINVIEW_PT2254_CLK;
  36. gpio_write(data);
  37. }
  38. data |= WINVIEW_PT2254_STROBE;
  39. data &= ~WINVIEW_PT2254_DATA;
  40. gpio_write(data);
  41. udelay(10);
  42. data &= ~WINVIEW_PT2254_STROBE;
  43. gpio_write(data);
  44. }
  45. /* ----------------------------------------------------------------------- */
  46. /* mono/stereo control for various cards (which don't use i2c chips but */
  47. /* connect something to the GPIO pins */
  48. void gvbctv3pci_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
  49. {
  50. unsigned int con = 0;
  51. if (set) {
  52. gpio_inout(0x300, 0x300);
  53. if (t->audmode & V4L2_TUNER_MODE_LANG1)
  54. con = 0x000;
  55. if (t->audmode & V4L2_TUNER_MODE_LANG2)
  56. con = 0x300;
  57. if (t->audmode & V4L2_TUNER_MODE_STEREO)
  58. con = 0x200;
  59. /* if (t->audmode & V4L2_TUNER_MODE_MONO)
  60. * con = 0x100; */
  61. gpio_bits(0x300, con);
  62. } else {
  63. t->audmode = V4L2_TUNER_MODE_STEREO |
  64. V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
  65. }
  66. }
  67. void gvbctv5pci_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
  68. {
  69. unsigned int val, con;
  70. if (btv->radio_user)
  71. return;
  72. val = gpio_read();
  73. if (set) {
  74. con = 0x000;
  75. if (t->audmode & V4L2_TUNER_MODE_LANG2) {
  76. if (t->audmode & V4L2_TUNER_MODE_LANG1) {
  77. /* LANG1 + LANG2 */
  78. con = 0x100;
  79. }
  80. else {
  81. /* LANG2 */
  82. con = 0x300;
  83. }
  84. }
  85. if (con != (val & 0x300)) {
  86. gpio_bits(0x300, con);
  87. if (bttv_gpio)
  88. bttv_gpio_tracking(btv,"gvbctv5pci");
  89. }
  90. } else {
  91. switch (val & 0x70) {
  92. case 0x10:
  93. t->rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
  94. break;
  95. case 0x30:
  96. t->rxsubchans = V4L2_TUNER_SUB_LANG2;
  97. break;
  98. case 0x50:
  99. t->rxsubchans = V4L2_TUNER_SUB_LANG1;
  100. break;
  101. case 0x60:
  102. t->rxsubchans = V4L2_TUNER_SUB_STEREO;
  103. break;
  104. case 0x70:
  105. t->rxsubchans = V4L2_TUNER_SUB_MONO;
  106. break;
  107. default:
  108. t->rxsubchans = V4L2_TUNER_SUB_MONO |
  109. V4L2_TUNER_SUB_STEREO |
  110. V4L2_TUNER_SUB_LANG1 |
  111. V4L2_TUNER_SUB_LANG2;
  112. }
  113. t->audmode = V4L2_TUNER_MODE_STEREO |
  114. V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
  115. }
  116. }
  117. /*
  118. * Mario Medina Nussbaum <medisoft@alohabbs.org.mx>
  119. * I discover that on BT848_GPIO_DATA address a byte 0xcce enable stereo,
  120. * 0xdde enables mono and 0xccd enables sap
  121. *
  122. * Petr Vandrovec <VANDROVE@vc.cvut.cz>
  123. * P.S.: At least mask in line above is wrong - GPIO pins 3,2 select
  124. * input/output sound connection, so both must be set for output mode.
  125. *
  126. * Looks like it's needed only for the "tvphone", the "tvphone 98"
  127. * handles this with a tda9840
  128. *
  129. */
  130. void avermedia_tvphone_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
  131. {
  132. int val = 0;
  133. if (set) {
  134. if (t->audmode & V4L2_TUNER_MODE_LANG2) /* SAP */
  135. val = 0x02;
  136. if (t->audmode & V4L2_TUNER_MODE_STEREO)
  137. val = 0x01;
  138. if (val) {
  139. gpio_bits(0x03,val);
  140. if (bttv_gpio)
  141. bttv_gpio_tracking(btv,"avermedia");
  142. }
  143. } else {
  144. t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
  145. V4L2_TUNER_MODE_LANG1;
  146. return;
  147. }
  148. }
  149. void avermedia_tv_stereo_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
  150. {
  151. int val = 0;
  152. if (set) {
  153. if (t->audmode & V4L2_TUNER_MODE_LANG2) /* SAP */
  154. val = 0x01;
  155. if (t->audmode & V4L2_TUNER_MODE_STEREO) /* STEREO */
  156. val = 0x02;
  157. btaor(val, ~0x03, BT848_GPIO_DATA);
  158. if (bttv_gpio)
  159. bttv_gpio_tracking(btv,"avermedia");
  160. } else {
  161. t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
  162. V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
  163. return;
  164. }
  165. }
  166. /* Lifetec 9415 handling */
  167. void lt9415_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
  168. {
  169. int val = 0;
  170. if (gpio_read() & 0x4000) {
  171. t->audmode = V4L2_TUNER_MODE_MONO;
  172. return;
  173. }
  174. if (set) {
  175. if (t->audmode & V4L2_TUNER_MODE_LANG2) /* A2 SAP */
  176. val = 0x0080;
  177. if (t->audmode & V4L2_TUNER_MODE_STEREO) /* A2 stereo */
  178. val = 0x0880;
  179. if ((t->audmode & V4L2_TUNER_MODE_LANG1) ||
  180. (t->audmode & V4L2_TUNER_MODE_MONO))
  181. val = 0;
  182. gpio_bits(0x0880, val);
  183. if (bttv_gpio)
  184. bttv_gpio_tracking(btv,"lt9415");
  185. } else {
  186. /* autodetect doesn't work with this card :-( */
  187. t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
  188. V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
  189. return;
  190. }
  191. }
  192. /* TDA9821 on TerraTV+ Bt848, Bt878 */
  193. void terratv_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
  194. {
  195. unsigned int con = 0;
  196. if (set) {
  197. gpio_inout(0x180000,0x180000);
  198. if (t->audmode & V4L2_TUNER_MODE_LANG2)
  199. con = 0x080000;
  200. if (t->audmode & V4L2_TUNER_MODE_STEREO)
  201. con = 0x180000;
  202. gpio_bits(0x180000, con);
  203. if (bttv_gpio)
  204. bttv_gpio_tracking(btv,"terratv");
  205. } else {
  206. t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
  207. V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
  208. }
  209. }
  210. void winfast2000_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
  211. {
  212. unsigned long val = 0;
  213. if (set) {
  214. /*btor (0xc32000, BT848_GPIO_OUT_EN);*/
  215. if (t->audmode & V4L2_TUNER_MODE_MONO) /* Mono */
  216. val = 0x420000;
  217. if (t->audmode & V4L2_TUNER_MODE_LANG1) /* Mono */
  218. val = 0x420000;
  219. if (t->audmode & V4L2_TUNER_MODE_LANG2) /* SAP */
  220. val = 0x410000;
  221. if (t->audmode & V4L2_TUNER_MODE_STEREO) /* Stereo */
  222. val = 0x020000;
  223. if (val) {
  224. gpio_bits(0x430000, val);
  225. if (bttv_gpio)
  226. bttv_gpio_tracking(btv,"winfast2000");
  227. }
  228. } else {
  229. t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
  230. V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
  231. }
  232. }
  233. /*
  234. * Dariusz Kowalewski <darekk@automex.pl>
  235. * sound control for Prolink PV-BT878P+9B (PixelView PlayTV Pro FM+NICAM
  236. * revision 9B has on-board TDA9874A sound decoder).
  237. *
  238. * Note: There are card variants without tda9874a. Forcing the "stereo sound route"
  239. * will mute this cards.
  240. */
  241. void pvbt878p9b_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
  242. {
  243. unsigned int val = 0;
  244. if (btv->radio_user)
  245. return;
  246. if (set) {
  247. if (t->audmode & V4L2_TUNER_MODE_MONO) {
  248. val = 0x01;
  249. }
  250. if ((t->audmode & (V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2))
  251. || (t->audmode & V4L2_TUNER_MODE_STEREO)) {
  252. val = 0x02;
  253. }
  254. if (val) {
  255. gpio_bits(0x03,val);
  256. if (bttv_gpio)
  257. bttv_gpio_tracking(btv,"pvbt878p9b");
  258. }
  259. } else {
  260. t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
  261. V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
  262. }
  263. }
  264. /*
  265. * Dariusz Kowalewski <darekk@automex.pl>
  266. * sound control for FlyVideo 2000S (with tda9874 decoder)
  267. * based on pvbt878p9b_audio() - this is not tested, please fix!!!
  268. */
  269. void fv2000s_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
  270. {
  271. unsigned int val = 0xffff;
  272. if (btv->radio_user)
  273. return;
  274. if (set) {
  275. if (t->audmode & V4L2_TUNER_MODE_MONO) {
  276. val = 0x0000;
  277. }
  278. if ((t->audmode & (V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2))
  279. || (t->audmode & V4L2_TUNER_MODE_STEREO)) {
  280. val = 0x1080; /*-dk-???: 0x0880, 0x0080, 0x1800 ... */
  281. }
  282. if (val != 0xffff) {
  283. gpio_bits(0x1800, val);
  284. if (bttv_gpio)
  285. bttv_gpio_tracking(btv,"fv2000s");
  286. }
  287. } else {
  288. t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
  289. V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
  290. }
  291. }
  292. /*
  293. * sound control for Canopus WinDVR PCI
  294. * Masaki Suzuki <masaki@btree.org>
  295. */
  296. void windvr_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
  297. {
  298. unsigned long val = 0;
  299. if (set) {
  300. if (t->audmode & V4L2_TUNER_MODE_MONO)
  301. val = 0x040000;
  302. if (t->audmode & V4L2_TUNER_MODE_LANG1)
  303. val = 0;
  304. if (t->audmode & V4L2_TUNER_MODE_LANG2)
  305. val = 0x100000;
  306. if (t->audmode & V4L2_TUNER_MODE_STEREO)
  307. val = 0;
  308. if (val) {
  309. gpio_bits(0x140000, val);
  310. if (bttv_gpio)
  311. bttv_gpio_tracking(btv,"windvr");
  312. }
  313. } else {
  314. t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
  315. V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
  316. }
  317. }
  318. /*
  319. * sound control for AD-TVK503
  320. * Hiroshi Takekawa <sian@big.or.jp>
  321. */
  322. void adtvk503_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
  323. {
  324. unsigned int con = 0xffffff;
  325. /* btaor(0x1e0000, ~0x1e0000, BT848_GPIO_OUT_EN); */
  326. if (set) {
  327. /* btor(***, BT848_GPIO_OUT_EN); */
  328. if (t->audmode & V4L2_TUNER_MODE_LANG1)
  329. con = 0x00000000;
  330. if (t->audmode & V4L2_TUNER_MODE_LANG2)
  331. con = 0x00180000;
  332. if (t->audmode & V4L2_TUNER_MODE_STEREO)
  333. con = 0x00000000;
  334. if (t->audmode & V4L2_TUNER_MODE_MONO)
  335. con = 0x00060000;
  336. if (con != 0xffffff) {
  337. gpio_bits(0x1e0000,con);
  338. if (bttv_gpio)
  339. bttv_gpio_tracking(btv, "adtvk503");
  340. }
  341. } else {
  342. t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
  343. V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
  344. }
  345. }