bttv-audio-hook.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. /*
  2. * Handlers for board audio hooks, splitted from bttv-cards
  3. *
  4. * Copyright (c) 2006 Mauro Carvalho Chehab <mchehab@kernel.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;
  51. if (!set) {
  52. /* Not much to do here */
  53. t->audmode = V4L2_TUNER_MODE_LANG1;
  54. t->rxsubchans = V4L2_TUNER_SUB_MONO |
  55. V4L2_TUNER_SUB_STEREO |
  56. V4L2_TUNER_SUB_LANG1 |
  57. V4L2_TUNER_SUB_LANG2;
  58. return;
  59. }
  60. gpio_inout(0x300, 0x300);
  61. switch (t->audmode) {
  62. case V4L2_TUNER_MODE_LANG1:
  63. default:
  64. con = 0x000;
  65. break;
  66. case V4L2_TUNER_MODE_LANG2:
  67. con = 0x300;
  68. break;
  69. case V4L2_TUNER_MODE_STEREO:
  70. con = 0x200;
  71. break;
  72. }
  73. gpio_bits(0x300, con);
  74. }
  75. void gvbctv5pci_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
  76. {
  77. unsigned int val, con;
  78. if (btv->radio_user)
  79. return;
  80. val = gpio_read();
  81. if (set) {
  82. switch (t->audmode) {
  83. case V4L2_TUNER_MODE_LANG2:
  84. con = 0x300;
  85. break;
  86. case V4L2_TUNER_MODE_LANG1_LANG2:
  87. con = 0x100;
  88. break;
  89. default:
  90. con = 0x000;
  91. break;
  92. }
  93. if (con != (val & 0x300)) {
  94. gpio_bits(0x300, con);
  95. if (bttv_gpio)
  96. bttv_gpio_tracking(btv, "gvbctv5pci");
  97. }
  98. } else {
  99. switch (val & 0x70) {
  100. case 0x10:
  101. t->rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
  102. t->audmode = V4L2_TUNER_MODE_LANG1_LANG2;
  103. break;
  104. case 0x30:
  105. t->rxsubchans = V4L2_TUNER_SUB_LANG2;
  106. t->audmode = V4L2_TUNER_MODE_LANG1_LANG2;
  107. break;
  108. case 0x50:
  109. t->rxsubchans = V4L2_TUNER_SUB_LANG1;
  110. t->audmode = V4L2_TUNER_MODE_LANG1_LANG2;
  111. break;
  112. case 0x60:
  113. t->rxsubchans = V4L2_TUNER_SUB_STEREO;
  114. t->audmode = V4L2_TUNER_MODE_STEREO;
  115. break;
  116. case 0x70:
  117. t->rxsubchans = V4L2_TUNER_SUB_MONO;
  118. t->audmode = V4L2_TUNER_MODE_MONO;
  119. break;
  120. default:
  121. t->rxsubchans = V4L2_TUNER_SUB_MONO |
  122. V4L2_TUNER_SUB_STEREO |
  123. V4L2_TUNER_SUB_LANG1 |
  124. V4L2_TUNER_SUB_LANG2;
  125. t->audmode = V4L2_TUNER_MODE_LANG1;
  126. }
  127. }
  128. }
  129. /*
  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
  133. *
  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.
  137. *
  138. * Looks like it's needed only for the "tvphone", the "tvphone 98"
  139. * handles this with a tda9840
  140. *
  141. */
  142. void avermedia_tvphone_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
  143. {
  144. int val;
  145. if (!set) {
  146. /* Not much to do here */
  147. t->audmode = V4L2_TUNER_MODE_LANG1;
  148. t->rxsubchans = V4L2_TUNER_SUB_MONO |
  149. V4L2_TUNER_SUB_STEREO |
  150. V4L2_TUNER_SUB_LANG1 |
  151. V4L2_TUNER_SUB_LANG2;
  152. return;
  153. }
  154. switch (t->audmode) {
  155. case V4L2_TUNER_MODE_LANG2: /* SAP */
  156. val = 0x02;
  157. break;
  158. case V4L2_TUNER_MODE_STEREO:
  159. val = 0x01;
  160. break;
  161. default:
  162. return;
  163. }
  164. gpio_bits(0x03, val);
  165. if (bttv_gpio)
  166. bttv_gpio_tracking(btv, "avermedia");
  167. }
  168. void avermedia_tv_stereo_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
  169. {
  170. int val = 0;
  171. if (!set) {
  172. /* Not much to do here */
  173. t->audmode = V4L2_TUNER_MODE_LANG1;
  174. t->rxsubchans = V4L2_TUNER_SUB_MONO |
  175. V4L2_TUNER_SUB_STEREO |
  176. V4L2_TUNER_SUB_LANG1 |
  177. V4L2_TUNER_SUB_LANG2;
  178. return;
  179. }
  180. switch (t->audmode) {
  181. case V4L2_TUNER_MODE_LANG2: /* SAP */
  182. val = 0x01;
  183. break;
  184. case V4L2_TUNER_MODE_STEREO:
  185. val = 0x02;
  186. break;
  187. default:
  188. val = 0;
  189. break;
  190. }
  191. btaor(val, ~0x03, BT848_GPIO_DATA);
  192. if (bttv_gpio)
  193. bttv_gpio_tracking(btv, "avermedia");
  194. }
  195. /* Lifetec 9415 handling */
  196. void lt9415_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
  197. {
  198. int val = 0;
  199. if (gpio_read() & 0x4000) {
  200. t->audmode = V4L2_TUNER_MODE_MONO;
  201. return;
  202. }
  203. if (!set) {
  204. /* Not much to do here */
  205. t->audmode = V4L2_TUNER_MODE_LANG1;
  206. t->rxsubchans = V4L2_TUNER_SUB_MONO |
  207. V4L2_TUNER_SUB_STEREO |
  208. V4L2_TUNER_SUB_LANG1 |
  209. V4L2_TUNER_SUB_LANG2;
  210. return;
  211. }
  212. switch (t->audmode) {
  213. case V4L2_TUNER_MODE_LANG2: /* A2 SAP */
  214. val = 0x0080;
  215. break;
  216. case V4L2_TUNER_MODE_STEREO: /* A2 stereo */
  217. val = 0x0880;
  218. break;
  219. default:
  220. val = 0;
  221. break;
  222. }
  223. gpio_bits(0x0880, val);
  224. if (bttv_gpio)
  225. bttv_gpio_tracking(btv, "lt9415");
  226. }
  227. /* TDA9821 on TerraTV+ Bt848, Bt878 */
  228. void terratv_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
  229. {
  230. unsigned int con = 0;
  231. if (!set) {
  232. /* Not much to do here */
  233. t->audmode = V4L2_TUNER_MODE_LANG1;
  234. t->rxsubchans = V4L2_TUNER_SUB_MONO |
  235. V4L2_TUNER_SUB_STEREO |
  236. V4L2_TUNER_SUB_LANG1 |
  237. V4L2_TUNER_SUB_LANG2;
  238. return;
  239. }
  240. gpio_inout(0x180000, 0x180000);
  241. switch (t->audmode) {
  242. case V4L2_TUNER_MODE_LANG2:
  243. con = 0x080000;
  244. break;
  245. case V4L2_TUNER_MODE_STEREO:
  246. con = 0x180000;
  247. break;
  248. default:
  249. con = 0;
  250. break;
  251. }
  252. gpio_bits(0x180000, con);
  253. if (bttv_gpio)
  254. bttv_gpio_tracking(btv, "terratv");
  255. }
  256. void winfast2000_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
  257. {
  258. unsigned long val;
  259. if (!set) {
  260. /* Not much to do here */
  261. t->audmode = V4L2_TUNER_MODE_LANG1;
  262. t->rxsubchans = V4L2_TUNER_SUB_MONO |
  263. V4L2_TUNER_SUB_STEREO |
  264. V4L2_TUNER_SUB_LANG1 |
  265. V4L2_TUNER_SUB_LANG2;
  266. return;
  267. }
  268. /*btor (0xc32000, BT848_GPIO_OUT_EN);*/
  269. switch (t->audmode) {
  270. case V4L2_TUNER_MODE_MONO:
  271. case V4L2_TUNER_MODE_LANG1:
  272. val = 0x420000;
  273. break;
  274. case V4L2_TUNER_MODE_LANG2: /* SAP */
  275. val = 0x410000;
  276. break;
  277. case V4L2_TUNER_MODE_STEREO:
  278. val = 0x020000;
  279. break;
  280. default:
  281. return;
  282. }
  283. gpio_bits(0x430000, val);
  284. if (bttv_gpio)
  285. bttv_gpio_tracking(btv, "winfast2000");
  286. }
  287. /*
  288. * Dariusz Kowalewski <darekk@automex.pl>
  289. * sound control for Prolink PV-BT878P+9B (PixelView PlayTV Pro FM+NICAM
  290. * revision 9B has on-board TDA9874A sound decoder).
  291. *
  292. * Note: There are card variants without tda9874a. Forcing the "stereo sound route"
  293. * will mute this cards.
  294. */
  295. void pvbt878p9b_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
  296. {
  297. unsigned int val = 0;
  298. if (btv->radio_user)
  299. return;
  300. if (!set) {
  301. /* Not much to do here */
  302. t->audmode = V4L2_TUNER_MODE_LANG1;
  303. t->rxsubchans = V4L2_TUNER_SUB_MONO |
  304. V4L2_TUNER_SUB_STEREO |
  305. V4L2_TUNER_SUB_LANG1 |
  306. V4L2_TUNER_SUB_LANG2;
  307. return;
  308. }
  309. switch (t->audmode) {
  310. case V4L2_TUNER_MODE_MONO:
  311. val = 0x01;
  312. break;
  313. case V4L2_TUNER_MODE_LANG1:
  314. case V4L2_TUNER_MODE_LANG2:
  315. case V4L2_TUNER_MODE_STEREO:
  316. val = 0x02;
  317. break;
  318. default:
  319. return;
  320. }
  321. gpio_bits(0x03, val);
  322. if (bttv_gpio)
  323. bttv_gpio_tracking(btv, "pvbt878p9b");
  324. }
  325. /*
  326. * Dariusz Kowalewski <darekk@automex.pl>
  327. * sound control for FlyVideo 2000S (with tda9874 decoder)
  328. * based on pvbt878p9b_audio() - this is not tested, please fix!!!
  329. */
  330. void fv2000s_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
  331. {
  332. unsigned int val;
  333. if (btv->radio_user)
  334. return;
  335. if (!set) {
  336. /* Not much to do here */
  337. t->audmode = V4L2_TUNER_MODE_LANG1;
  338. t->rxsubchans = V4L2_TUNER_SUB_MONO |
  339. V4L2_TUNER_SUB_STEREO |
  340. V4L2_TUNER_SUB_LANG1 |
  341. V4L2_TUNER_SUB_LANG2;
  342. return;
  343. }
  344. switch (t->audmode) {
  345. case V4L2_TUNER_MODE_MONO:
  346. val = 0x0000;
  347. break;
  348. case V4L2_TUNER_MODE_LANG1:
  349. case V4L2_TUNER_MODE_LANG2:
  350. case V4L2_TUNER_MODE_STEREO:
  351. val = 0x1080; /*-dk-???: 0x0880, 0x0080, 0x1800 ... */
  352. break;
  353. default:
  354. return;
  355. }
  356. gpio_bits(0x1800, val);
  357. if (bttv_gpio)
  358. bttv_gpio_tracking(btv, "fv2000s");
  359. }
  360. /*
  361. * sound control for Canopus WinDVR PCI
  362. * Masaki Suzuki <masaki@btree.org>
  363. */
  364. void windvr_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
  365. {
  366. unsigned long val;
  367. if (!set) {
  368. /* Not much to do here */
  369. t->audmode = V4L2_TUNER_MODE_LANG1;
  370. t->rxsubchans = V4L2_TUNER_SUB_MONO |
  371. V4L2_TUNER_SUB_STEREO |
  372. V4L2_TUNER_SUB_LANG1 |
  373. V4L2_TUNER_SUB_LANG2;
  374. return;
  375. }
  376. switch (t->audmode) {
  377. case V4L2_TUNER_MODE_MONO:
  378. val = 0x040000;
  379. break;
  380. case V4L2_TUNER_MODE_LANG2:
  381. val = 0x100000;
  382. break;
  383. default:
  384. return;
  385. }
  386. gpio_bits(0x140000, val);
  387. if (bttv_gpio)
  388. bttv_gpio_tracking(btv, "windvr");
  389. }
  390. /*
  391. * sound control for AD-TVK503
  392. * Hiroshi Takekawa <sian@big.or.jp>
  393. */
  394. void adtvk503_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
  395. {
  396. unsigned int con = 0xffffff;
  397. /* btaor(0x1e0000, ~0x1e0000, BT848_GPIO_OUT_EN); */
  398. if (!set) {
  399. /* Not much to do here */
  400. t->audmode = V4L2_TUNER_MODE_LANG1;
  401. t->rxsubchans = V4L2_TUNER_SUB_MONO |
  402. V4L2_TUNER_SUB_STEREO |
  403. V4L2_TUNER_SUB_LANG1 |
  404. V4L2_TUNER_SUB_LANG2;
  405. return;
  406. }
  407. /* btor(***, BT848_GPIO_OUT_EN); */
  408. switch (t->audmode) {
  409. case V4L2_TUNER_MODE_LANG1:
  410. con = 0x00000000;
  411. break;
  412. case V4L2_TUNER_MODE_LANG2:
  413. con = 0x00180000;
  414. break;
  415. case V4L2_TUNER_MODE_STEREO:
  416. con = 0x00000000;
  417. break;
  418. case V4L2_TUNER_MODE_MONO:
  419. con = 0x00060000;
  420. break;
  421. default:
  422. return;
  423. }
  424. gpio_bits(0x1e0000, con);
  425. if (bttv_gpio)
  426. bttv_gpio_tracking(btv, "adtvk503");
  427. }