cx88-tvaudio.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056
  1. /*
  2. * cx88x-audio.c - Conexant CX23880/23881 audio downstream driver driver
  3. *
  4. * (c) 2001 Michael Eskin, Tom Zakrajsek [Windows version]
  5. * (c) 2002 Yurij Sysoev <yurij@naturesoft.net>
  6. * (c) 2003 Gerd Knorr <kraxel@bytesex.org>
  7. *
  8. * -----------------------------------------------------------------------
  9. *
  10. * Lot of voodoo here. Even the data sheet doesn't help to
  11. * understand what is going on here, the documentation for the audio
  12. * part of the cx2388x chip is *very* bad.
  13. *
  14. * Some of this comes from party done linux driver sources I got from
  15. * [undocumented].
  16. *
  17. * Some comes from the dscaler sources, one of the dscaler driver guy works
  18. * for Conexant ...
  19. *
  20. * -----------------------------------------------------------------------
  21. *
  22. * This program is free software; you can redistribute it and/or modify
  23. * it under the terms of the GNU General Public License as published by
  24. * the Free Software Foundation; either version 2 of the License, or
  25. * (at your option) any later version.
  26. *
  27. * This program is distributed in the hope that it will be useful,
  28. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  29. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  30. * GNU General Public License for more details.
  31. */
  32. #include "cx88.h"
  33. #include <linux/module.h>
  34. #include <linux/errno.h>
  35. #include <linux/freezer.h>
  36. #include <linux/kernel.h>
  37. #include <linux/mm.h>
  38. #include <linux/poll.h>
  39. #include <linux/signal.h>
  40. #include <linux/ioport.h>
  41. #include <linux/types.h>
  42. #include <linux/interrupt.h>
  43. #include <linux/vmalloc.h>
  44. #include <linux/init.h>
  45. #include <linux/delay.h>
  46. #include <linux/kthread.h>
  47. static unsigned int audio_debug;
  48. module_param(audio_debug, int, 0644);
  49. MODULE_PARM_DESC(audio_debug, "enable debug messages [audio]");
  50. static unsigned int always_analog;
  51. module_param(always_analog, int, 0644);
  52. MODULE_PARM_DESC(always_analog, "force analog audio out");
  53. static unsigned int radio_deemphasis;
  54. module_param(radio_deemphasis, int, 0644);
  55. MODULE_PARM_DESC(radio_deemphasis,
  56. "Radio deemphasis time constant, 0=None, 1=50us (elsewhere), 2=75us (USA)");
  57. #define dprintk(fmt, arg...) do { \
  58. if (audio_debug) \
  59. printk(KERN_DEBUG pr_fmt("%s: tvaudio:" fmt), \
  60. __func__, ##arg); \
  61. } while (0)
  62. /* ----------------------------------------------------------- */
  63. static const char * const aud_ctl_names[64] = {
  64. [EN_BTSC_FORCE_MONO] = "BTSC_FORCE_MONO",
  65. [EN_BTSC_FORCE_STEREO] = "BTSC_FORCE_STEREO",
  66. [EN_BTSC_FORCE_SAP] = "BTSC_FORCE_SAP",
  67. [EN_BTSC_AUTO_STEREO] = "BTSC_AUTO_STEREO",
  68. [EN_BTSC_AUTO_SAP] = "BTSC_AUTO_SAP",
  69. [EN_A2_FORCE_MONO1] = "A2_FORCE_MONO1",
  70. [EN_A2_FORCE_MONO2] = "A2_FORCE_MONO2",
  71. [EN_A2_FORCE_STEREO] = "A2_FORCE_STEREO",
  72. [EN_A2_AUTO_MONO2] = "A2_AUTO_MONO2",
  73. [EN_A2_AUTO_STEREO] = "A2_AUTO_STEREO",
  74. [EN_EIAJ_FORCE_MONO1] = "EIAJ_FORCE_MONO1",
  75. [EN_EIAJ_FORCE_MONO2] = "EIAJ_FORCE_MONO2",
  76. [EN_EIAJ_FORCE_STEREO] = "EIAJ_FORCE_STEREO",
  77. [EN_EIAJ_AUTO_MONO2] = "EIAJ_AUTO_MONO2",
  78. [EN_EIAJ_AUTO_STEREO] = "EIAJ_AUTO_STEREO",
  79. [EN_NICAM_FORCE_MONO1] = "NICAM_FORCE_MONO1",
  80. [EN_NICAM_FORCE_MONO2] = "NICAM_FORCE_MONO2",
  81. [EN_NICAM_FORCE_STEREO] = "NICAM_FORCE_STEREO",
  82. [EN_NICAM_AUTO_MONO2] = "NICAM_AUTO_MONO2",
  83. [EN_NICAM_AUTO_STEREO] = "NICAM_AUTO_STEREO",
  84. [EN_FMRADIO_FORCE_MONO] = "FMRADIO_FORCE_MONO",
  85. [EN_FMRADIO_FORCE_STEREO] = "FMRADIO_FORCE_STEREO",
  86. [EN_FMRADIO_AUTO_STEREO] = "FMRADIO_AUTO_STEREO",
  87. };
  88. struct rlist {
  89. u32 reg;
  90. u32 val;
  91. };
  92. static void set_audio_registers(struct cx88_core *core, const struct rlist *l)
  93. {
  94. int i;
  95. for (i = 0; l[i].reg; i++) {
  96. switch (l[i].reg) {
  97. case AUD_PDF_DDS_CNST_BYTE2:
  98. case AUD_PDF_DDS_CNST_BYTE1:
  99. case AUD_PDF_DDS_CNST_BYTE0:
  100. case AUD_QAM_MODE:
  101. case AUD_PHACC_FREQ_8MSB:
  102. case AUD_PHACC_FREQ_8LSB:
  103. cx_writeb(l[i].reg, l[i].val);
  104. break;
  105. default:
  106. cx_write(l[i].reg, l[i].val);
  107. break;
  108. }
  109. }
  110. }
  111. static void set_audio_start(struct cx88_core *core, u32 mode)
  112. {
  113. /* mute */
  114. cx_write(AUD_VOL_CTL, (1 << 6));
  115. /* start programming */
  116. cx_write(AUD_INIT, mode);
  117. cx_write(AUD_INIT_LD, 0x0001);
  118. cx_write(AUD_SOFT_RESET, 0x0001);
  119. }
  120. static void set_audio_finish(struct cx88_core *core, u32 ctl)
  121. {
  122. u32 volume;
  123. /* restart dma; This avoids buzz in NICAM and is good in others */
  124. cx88_stop_audio_dma(core);
  125. cx_write(AUD_RATE_THRES_DMD, 0x000000C0);
  126. cx88_start_audio_dma(core);
  127. if (core->board.mpeg & CX88_MPEG_BLACKBIRD) {
  128. cx_write(AUD_I2SINPUTCNTL, 4);
  129. cx_write(AUD_BAUDRATE, 1);
  130. /*
  131. * 'pass-thru mode': this enables the i2s
  132. * output to the mpeg encoder
  133. */
  134. cx_set(AUD_CTL, EN_I2SOUT_ENABLE);
  135. cx_write(AUD_I2SOUTPUTCNTL, 1);
  136. cx_write(AUD_I2SCNTL, 0);
  137. /* cx_write(AUD_APB_IN_RATE_ADJ, 0); */
  138. }
  139. if ((always_analog) || (!(core->board.mpeg & CX88_MPEG_BLACKBIRD))) {
  140. ctl |= EN_DAC_ENABLE;
  141. cx_write(AUD_CTL, ctl);
  142. }
  143. /* finish programming */
  144. cx_write(AUD_SOFT_RESET, 0x0000);
  145. /* unmute */
  146. volume = cx_sread(SHADOW_AUD_VOL_CTL);
  147. cx_swrite(SHADOW_AUD_VOL_CTL, AUD_VOL_CTL, volume);
  148. core->last_change = jiffies;
  149. }
  150. /* ----------------------------------------------------------- */
  151. static void set_audio_standard_BTSC(struct cx88_core *core, unsigned int sap,
  152. u32 mode)
  153. {
  154. static const struct rlist btsc[] = {
  155. {AUD_AFE_12DB_EN, 0x00000001},
  156. {AUD_OUT1_SEL, 0x00000013},
  157. {AUD_OUT1_SHIFT, 0x00000000},
  158. {AUD_POLY0_DDS_CONSTANT, 0x0012010c},
  159. {AUD_DMD_RA_DDS, 0x00c3e7aa},
  160. {AUD_DBX_IN_GAIN, 0x00004734},
  161. {AUD_DBX_WBE_GAIN, 0x00004640},
  162. {AUD_DBX_SE_GAIN, 0x00008d31},
  163. {AUD_DCOC_0_SRC, 0x0000001a},
  164. {AUD_IIR1_4_SEL, 0x00000021},
  165. {AUD_DCOC_PASS_IN, 0x00000003},
  166. {AUD_DCOC_0_SHIFT_IN0, 0x0000000a},
  167. {AUD_DCOC_0_SHIFT_IN1, 0x00000008},
  168. {AUD_DCOC_1_SHIFT_IN0, 0x0000000a},
  169. {AUD_DCOC_1_SHIFT_IN1, 0x00000008},
  170. {AUD_DN0_FREQ, 0x0000283b},
  171. {AUD_DN2_SRC_SEL, 0x00000008},
  172. {AUD_DN2_FREQ, 0x00003000},
  173. {AUD_DN2_AFC, 0x00000002},
  174. {AUD_DN2_SHFT, 0x00000000},
  175. {AUD_IIR2_2_SEL, 0x00000020},
  176. {AUD_IIR2_2_SHIFT, 0x00000000},
  177. {AUD_IIR2_3_SEL, 0x0000001f},
  178. {AUD_IIR2_3_SHIFT, 0x00000000},
  179. {AUD_CRDC1_SRC_SEL, 0x000003ce},
  180. {AUD_CRDC1_SHIFT, 0x00000000},
  181. {AUD_CORDIC_SHIFT_1, 0x00000007},
  182. {AUD_DCOC_1_SRC, 0x0000001b},
  183. {AUD_DCOC1_SHIFT, 0x00000000},
  184. {AUD_RDSI_SEL, 0x00000008},
  185. {AUD_RDSQ_SEL, 0x00000008},
  186. {AUD_RDSI_SHIFT, 0x00000000},
  187. {AUD_RDSQ_SHIFT, 0x00000000},
  188. {AUD_POLYPH80SCALEFAC, 0x00000003},
  189. { /* end of list */ },
  190. };
  191. static const struct rlist btsc_sap[] = {
  192. {AUD_AFE_12DB_EN, 0x00000001},
  193. {AUD_DBX_IN_GAIN, 0x00007200},
  194. {AUD_DBX_WBE_GAIN, 0x00006200},
  195. {AUD_DBX_SE_GAIN, 0x00006200},
  196. {AUD_IIR1_1_SEL, 0x00000000},
  197. {AUD_IIR1_3_SEL, 0x00000001},
  198. {AUD_DN1_SRC_SEL, 0x00000007},
  199. {AUD_IIR1_4_SHIFT, 0x00000006},
  200. {AUD_IIR2_1_SHIFT, 0x00000000},
  201. {AUD_IIR2_2_SHIFT, 0x00000000},
  202. {AUD_IIR3_0_SHIFT, 0x00000000},
  203. {AUD_IIR3_1_SHIFT, 0x00000000},
  204. {AUD_IIR3_0_SEL, 0x0000000d},
  205. {AUD_IIR3_1_SEL, 0x0000000e},
  206. {AUD_DEEMPH1_SRC_SEL, 0x00000014},
  207. {AUD_DEEMPH1_SHIFT, 0x00000000},
  208. {AUD_DEEMPH1_G0, 0x00004000},
  209. {AUD_DEEMPH1_A0, 0x00000000},
  210. {AUD_DEEMPH1_B0, 0x00000000},
  211. {AUD_DEEMPH1_A1, 0x00000000},
  212. {AUD_DEEMPH1_B1, 0x00000000},
  213. {AUD_OUT0_SEL, 0x0000003f},
  214. {AUD_OUT1_SEL, 0x0000003f},
  215. {AUD_DN1_AFC, 0x00000002},
  216. {AUD_DCOC_0_SHIFT_IN0, 0x0000000a},
  217. {AUD_DCOC_0_SHIFT_IN1, 0x00000008},
  218. {AUD_DCOC_1_SHIFT_IN0, 0x0000000a},
  219. {AUD_DCOC_1_SHIFT_IN1, 0x00000008},
  220. {AUD_IIR1_0_SEL, 0x0000001d},
  221. {AUD_IIR1_2_SEL, 0x0000001e},
  222. {AUD_IIR2_1_SEL, 0x00000002},
  223. {AUD_IIR2_2_SEL, 0x00000004},
  224. {AUD_IIR3_2_SEL, 0x0000000f},
  225. {AUD_DCOC2_SHIFT, 0x00000001},
  226. {AUD_IIR3_2_SHIFT, 0x00000001},
  227. {AUD_DEEMPH0_SRC_SEL, 0x00000014},
  228. {AUD_CORDIC_SHIFT_1, 0x00000006},
  229. {AUD_POLY0_DDS_CONSTANT, 0x000e4db2},
  230. {AUD_DMD_RA_DDS, 0x00f696e6},
  231. {AUD_IIR2_3_SEL, 0x00000025},
  232. {AUD_IIR1_4_SEL, 0x00000021},
  233. {AUD_DN1_FREQ, 0x0000c965},
  234. {AUD_DCOC_PASS_IN, 0x00000003},
  235. {AUD_DCOC_0_SRC, 0x0000001a},
  236. {AUD_DCOC_1_SRC, 0x0000001b},
  237. {AUD_DCOC1_SHIFT, 0x00000000},
  238. {AUD_RDSI_SEL, 0x00000009},
  239. {AUD_RDSQ_SEL, 0x00000009},
  240. {AUD_RDSI_SHIFT, 0x00000000},
  241. {AUD_RDSQ_SHIFT, 0x00000000},
  242. {AUD_POLYPH80SCALEFAC, 0x00000003},
  243. { /* end of list */ },
  244. };
  245. mode |= EN_FMRADIO_EN_RDS;
  246. if (sap) {
  247. dprintk("%s SAP (status: unknown)\n", __func__);
  248. set_audio_start(core, SEL_SAP);
  249. set_audio_registers(core, btsc_sap);
  250. set_audio_finish(core, mode);
  251. } else {
  252. dprintk("%s (status: known-good)\n", __func__);
  253. set_audio_start(core, SEL_BTSC);
  254. set_audio_registers(core, btsc);
  255. set_audio_finish(core, mode);
  256. }
  257. }
  258. static void set_audio_standard_NICAM(struct cx88_core *core, u32 mode)
  259. {
  260. static const struct rlist nicam_l[] = {
  261. {AUD_AFE_12DB_EN, 0x00000001},
  262. {AUD_RATE_ADJ1, 0x00000060},
  263. {AUD_RATE_ADJ2, 0x000000F9},
  264. {AUD_RATE_ADJ3, 0x000001CC},
  265. {AUD_RATE_ADJ4, 0x000002B3},
  266. {AUD_RATE_ADJ5, 0x00000726},
  267. {AUD_DEEMPHDENOM1_R, 0x0000F3D0},
  268. {AUD_DEEMPHDENOM2_R, 0x00000000},
  269. {AUD_ERRLOGPERIOD_R, 0x00000064},
  270. {AUD_ERRINTRPTTHSHLD1_R, 0x00000FFF},
  271. {AUD_ERRINTRPTTHSHLD2_R, 0x0000001F},
  272. {AUD_ERRINTRPTTHSHLD3_R, 0x0000000F},
  273. {AUD_POLYPH80SCALEFAC, 0x00000003},
  274. {AUD_DMD_RA_DDS, 0x00C00000},
  275. {AUD_PLL_INT, 0x0000001E},
  276. {AUD_PLL_DDS, 0x00000000},
  277. {AUD_PLL_FRAC, 0x0000E542},
  278. {AUD_START_TIMER, 0x00000000},
  279. {AUD_DEEMPHNUMER1_R, 0x000353DE},
  280. {AUD_DEEMPHNUMER2_R, 0x000001B1},
  281. {AUD_PDF_DDS_CNST_BYTE2, 0x06},
  282. {AUD_PDF_DDS_CNST_BYTE1, 0x82},
  283. {AUD_PDF_DDS_CNST_BYTE0, 0x12},
  284. {AUD_QAM_MODE, 0x05},
  285. {AUD_PHACC_FREQ_8MSB, 0x34},
  286. {AUD_PHACC_FREQ_8LSB, 0x4C},
  287. {AUD_DEEMPHGAIN_R, 0x00006680},
  288. {AUD_RATE_THRES_DMD, 0x000000C0},
  289. { /* end of list */ },
  290. };
  291. static const struct rlist nicam_bgdki_common[] = {
  292. {AUD_AFE_12DB_EN, 0x00000001},
  293. {AUD_RATE_ADJ1, 0x00000010},
  294. {AUD_RATE_ADJ2, 0x00000040},
  295. {AUD_RATE_ADJ3, 0x00000100},
  296. {AUD_RATE_ADJ4, 0x00000400},
  297. {AUD_RATE_ADJ5, 0x00001000},
  298. {AUD_ERRLOGPERIOD_R, 0x00000fff},
  299. {AUD_ERRINTRPTTHSHLD1_R, 0x000003ff},
  300. {AUD_ERRINTRPTTHSHLD2_R, 0x000000ff},
  301. {AUD_ERRINTRPTTHSHLD3_R, 0x0000003f},
  302. {AUD_POLYPH80SCALEFAC, 0x00000003},
  303. {AUD_DEEMPHGAIN_R, 0x000023c2},
  304. {AUD_DEEMPHNUMER1_R, 0x0002a7bc},
  305. {AUD_DEEMPHNUMER2_R, 0x0003023e},
  306. {AUD_DEEMPHDENOM1_R, 0x0000f3d0},
  307. {AUD_DEEMPHDENOM2_R, 0x00000000},
  308. {AUD_PDF_DDS_CNST_BYTE2, 0x06},
  309. {AUD_PDF_DDS_CNST_BYTE1, 0x82},
  310. {AUD_QAM_MODE, 0x05},
  311. { /* end of list */ },
  312. };
  313. static const struct rlist nicam_i[] = {
  314. {AUD_PDF_DDS_CNST_BYTE0, 0x12},
  315. {AUD_PHACC_FREQ_8MSB, 0x3a},
  316. {AUD_PHACC_FREQ_8LSB, 0x93},
  317. { /* end of list */ },
  318. };
  319. static const struct rlist nicam_default[] = {
  320. {AUD_PDF_DDS_CNST_BYTE0, 0x16},
  321. {AUD_PHACC_FREQ_8MSB, 0x34},
  322. {AUD_PHACC_FREQ_8LSB, 0x4c},
  323. { /* end of list */ },
  324. };
  325. set_audio_start(core, SEL_NICAM);
  326. switch (core->tvaudio) {
  327. case WW_L:
  328. dprintk("%s SECAM-L NICAM (status: devel)\n", __func__);
  329. set_audio_registers(core, nicam_l);
  330. break;
  331. case WW_I:
  332. dprintk("%s PAL-I NICAM (status: known-good)\n", __func__);
  333. set_audio_registers(core, nicam_bgdki_common);
  334. set_audio_registers(core, nicam_i);
  335. break;
  336. case WW_NONE:
  337. case WW_BTSC:
  338. case WW_BG:
  339. case WW_DK:
  340. case WW_EIAJ:
  341. case WW_I2SPT:
  342. case WW_FM:
  343. case WW_I2SADC:
  344. case WW_M:
  345. dprintk("%s PAL-BGDK NICAM (status: known-good)\n", __func__);
  346. set_audio_registers(core, nicam_bgdki_common);
  347. set_audio_registers(core, nicam_default);
  348. break;
  349. }
  350. mode |= EN_DMTRX_LR | EN_DMTRX_BYPASS;
  351. set_audio_finish(core, mode);
  352. }
  353. static void set_audio_standard_A2(struct cx88_core *core, u32 mode)
  354. {
  355. static const struct rlist a2_bgdk_common[] = {
  356. {AUD_ERRLOGPERIOD_R, 0x00000064},
  357. {AUD_ERRINTRPTTHSHLD1_R, 0x00000fff},
  358. {AUD_ERRINTRPTTHSHLD2_R, 0x0000001f},
  359. {AUD_ERRINTRPTTHSHLD3_R, 0x0000000f},
  360. {AUD_PDF_DDS_CNST_BYTE2, 0x06},
  361. {AUD_PDF_DDS_CNST_BYTE1, 0x82},
  362. {AUD_PDF_DDS_CNST_BYTE0, 0x12},
  363. {AUD_QAM_MODE, 0x05},
  364. {AUD_PHACC_FREQ_8MSB, 0x34},
  365. {AUD_PHACC_FREQ_8LSB, 0x4c},
  366. {AUD_RATE_ADJ1, 0x00000100},
  367. {AUD_RATE_ADJ2, 0x00000200},
  368. {AUD_RATE_ADJ3, 0x00000300},
  369. {AUD_RATE_ADJ4, 0x00000400},
  370. {AUD_RATE_ADJ5, 0x00000500},
  371. {AUD_THR_FR, 0x00000000},
  372. {AAGC_HYST, 0x0000001a},
  373. {AUD_PILOT_BQD_1_K0, 0x0000755b},
  374. {AUD_PILOT_BQD_1_K1, 0x00551340},
  375. {AUD_PILOT_BQD_1_K2, 0x006d30be},
  376. {AUD_PILOT_BQD_1_K3, 0xffd394af},
  377. {AUD_PILOT_BQD_1_K4, 0x00400000},
  378. {AUD_PILOT_BQD_2_K0, 0x00040000},
  379. {AUD_PILOT_BQD_2_K1, 0x002a4841},
  380. {AUD_PILOT_BQD_2_K2, 0x00400000},
  381. {AUD_PILOT_BQD_2_K3, 0x00000000},
  382. {AUD_PILOT_BQD_2_K4, 0x00000000},
  383. {AUD_MODE_CHG_TIMER, 0x00000040},
  384. {AUD_AFE_12DB_EN, 0x00000001},
  385. {AUD_CORDIC_SHIFT_0, 0x00000007},
  386. {AUD_CORDIC_SHIFT_1, 0x00000007},
  387. {AUD_DEEMPH0_G0, 0x00000380},
  388. {AUD_DEEMPH1_G0, 0x00000380},
  389. {AUD_DCOC_0_SRC, 0x0000001a},
  390. {AUD_DCOC0_SHIFT, 0x00000000},
  391. {AUD_DCOC_0_SHIFT_IN0, 0x0000000a},
  392. {AUD_DCOC_0_SHIFT_IN1, 0x00000008},
  393. {AUD_DCOC_PASS_IN, 0x00000003},
  394. {AUD_IIR3_0_SEL, 0x00000021},
  395. {AUD_DN2_AFC, 0x00000002},
  396. {AUD_DCOC_1_SRC, 0x0000001b},
  397. {AUD_DCOC1_SHIFT, 0x00000000},
  398. {AUD_DCOC_1_SHIFT_IN0, 0x0000000a},
  399. {AUD_DCOC_1_SHIFT_IN1, 0x00000008},
  400. {AUD_IIR3_1_SEL, 0x00000023},
  401. {AUD_RDSI_SEL, 0x00000017},
  402. {AUD_RDSI_SHIFT, 0x00000000},
  403. {AUD_RDSQ_SEL, 0x00000017},
  404. {AUD_RDSQ_SHIFT, 0x00000000},
  405. {AUD_PLL_INT, 0x0000001e},
  406. {AUD_PLL_DDS, 0x00000000},
  407. {AUD_PLL_FRAC, 0x0000e542},
  408. {AUD_POLYPH80SCALEFAC, 0x00000001},
  409. {AUD_START_TIMER, 0x00000000},
  410. { /* end of list */ },
  411. };
  412. static const struct rlist a2_bg[] = {
  413. {AUD_DMD_RA_DDS, 0x002a4f2f},
  414. {AUD_C1_UP_THR, 0x00007000},
  415. {AUD_C1_LO_THR, 0x00005400},
  416. {AUD_C2_UP_THR, 0x00005400},
  417. {AUD_C2_LO_THR, 0x00003000},
  418. { /* end of list */ },
  419. };
  420. static const struct rlist a2_dk[] = {
  421. {AUD_DMD_RA_DDS, 0x002a4f2f},
  422. {AUD_C1_UP_THR, 0x00007000},
  423. {AUD_C1_LO_THR, 0x00005400},
  424. {AUD_C2_UP_THR, 0x00005400},
  425. {AUD_C2_LO_THR, 0x00003000},
  426. {AUD_DN0_FREQ, 0x00003a1c},
  427. {AUD_DN2_FREQ, 0x0000d2e0},
  428. { /* end of list */ },
  429. };
  430. static const struct rlist a1_i[] = {
  431. {AUD_ERRLOGPERIOD_R, 0x00000064},
  432. {AUD_ERRINTRPTTHSHLD1_R, 0x00000fff},
  433. {AUD_ERRINTRPTTHSHLD2_R, 0x0000001f},
  434. {AUD_ERRINTRPTTHSHLD3_R, 0x0000000f},
  435. {AUD_PDF_DDS_CNST_BYTE2, 0x06},
  436. {AUD_PDF_DDS_CNST_BYTE1, 0x82},
  437. {AUD_PDF_DDS_CNST_BYTE0, 0x12},
  438. {AUD_QAM_MODE, 0x05},
  439. {AUD_PHACC_FREQ_8MSB, 0x3a},
  440. {AUD_PHACC_FREQ_8LSB, 0x93},
  441. {AUD_DMD_RA_DDS, 0x002a4f2f},
  442. {AUD_PLL_INT, 0x0000001e},
  443. {AUD_PLL_DDS, 0x00000004},
  444. {AUD_PLL_FRAC, 0x0000e542},
  445. {AUD_RATE_ADJ1, 0x00000100},
  446. {AUD_RATE_ADJ2, 0x00000200},
  447. {AUD_RATE_ADJ3, 0x00000300},
  448. {AUD_RATE_ADJ4, 0x00000400},
  449. {AUD_RATE_ADJ5, 0x00000500},
  450. {AUD_THR_FR, 0x00000000},
  451. {AUD_PILOT_BQD_1_K0, 0x0000755b},
  452. {AUD_PILOT_BQD_1_K1, 0x00551340},
  453. {AUD_PILOT_BQD_1_K2, 0x006d30be},
  454. {AUD_PILOT_BQD_1_K3, 0xffd394af},
  455. {AUD_PILOT_BQD_1_K4, 0x00400000},
  456. {AUD_PILOT_BQD_2_K0, 0x00040000},
  457. {AUD_PILOT_BQD_2_K1, 0x002a4841},
  458. {AUD_PILOT_BQD_2_K2, 0x00400000},
  459. {AUD_PILOT_BQD_2_K3, 0x00000000},
  460. {AUD_PILOT_BQD_2_K4, 0x00000000},
  461. {AUD_MODE_CHG_TIMER, 0x00000060},
  462. {AUD_AFE_12DB_EN, 0x00000001},
  463. {AAGC_HYST, 0x0000000a},
  464. {AUD_CORDIC_SHIFT_0, 0x00000007},
  465. {AUD_CORDIC_SHIFT_1, 0x00000007},
  466. {AUD_C1_UP_THR, 0x00007000},
  467. {AUD_C1_LO_THR, 0x00005400},
  468. {AUD_C2_UP_THR, 0x00005400},
  469. {AUD_C2_LO_THR, 0x00003000},
  470. {AUD_DCOC_0_SRC, 0x0000001a},
  471. {AUD_DCOC0_SHIFT, 0x00000000},
  472. {AUD_DCOC_0_SHIFT_IN0, 0x0000000a},
  473. {AUD_DCOC_0_SHIFT_IN1, 0x00000008},
  474. {AUD_DCOC_PASS_IN, 0x00000003},
  475. {AUD_IIR3_0_SEL, 0x00000021},
  476. {AUD_DN2_AFC, 0x00000002},
  477. {AUD_DCOC_1_SRC, 0x0000001b},
  478. {AUD_DCOC1_SHIFT, 0x00000000},
  479. {AUD_DCOC_1_SHIFT_IN0, 0x0000000a},
  480. {AUD_DCOC_1_SHIFT_IN1, 0x00000008},
  481. {AUD_IIR3_1_SEL, 0x00000023},
  482. {AUD_DN0_FREQ, 0x000035a3},
  483. {AUD_DN2_FREQ, 0x000029c7},
  484. {AUD_CRDC0_SRC_SEL, 0x00000511},
  485. {AUD_IIR1_0_SEL, 0x00000001},
  486. {AUD_IIR1_1_SEL, 0x00000000},
  487. {AUD_IIR3_2_SEL, 0x00000003},
  488. {AUD_IIR3_2_SHIFT, 0x00000000},
  489. {AUD_IIR3_0_SEL, 0x00000002},
  490. {AUD_IIR2_0_SEL, 0x00000021},
  491. {AUD_IIR2_0_SHIFT, 0x00000002},
  492. {AUD_DEEMPH0_SRC_SEL, 0x0000000b},
  493. {AUD_DEEMPH1_SRC_SEL, 0x0000000b},
  494. {AUD_POLYPH80SCALEFAC, 0x00000001},
  495. {AUD_START_TIMER, 0x00000000},
  496. { /* end of list */ },
  497. };
  498. static const struct rlist am_l[] = {
  499. {AUD_ERRLOGPERIOD_R, 0x00000064},
  500. {AUD_ERRINTRPTTHSHLD1_R, 0x00000FFF},
  501. {AUD_ERRINTRPTTHSHLD2_R, 0x0000001F},
  502. {AUD_ERRINTRPTTHSHLD3_R, 0x0000000F},
  503. {AUD_PDF_DDS_CNST_BYTE2, 0x48},
  504. {AUD_PDF_DDS_CNST_BYTE1, 0x3D},
  505. {AUD_QAM_MODE, 0x00},
  506. {AUD_PDF_DDS_CNST_BYTE0, 0xf5},
  507. {AUD_PHACC_FREQ_8MSB, 0x3a},
  508. {AUD_PHACC_FREQ_8LSB, 0x4a},
  509. {AUD_DEEMPHGAIN_R, 0x00006680},
  510. {AUD_DEEMPHNUMER1_R, 0x000353DE},
  511. {AUD_DEEMPHNUMER2_R, 0x000001B1},
  512. {AUD_DEEMPHDENOM1_R, 0x0000F3D0},
  513. {AUD_DEEMPHDENOM2_R, 0x00000000},
  514. {AUD_FM_MODE_ENABLE, 0x00000007},
  515. {AUD_POLYPH80SCALEFAC, 0x00000003},
  516. {AUD_AFE_12DB_EN, 0x00000001},
  517. {AAGC_GAIN, 0x00000000},
  518. {AAGC_HYST, 0x00000018},
  519. {AAGC_DEF, 0x00000020},
  520. {AUD_DN0_FREQ, 0x00000000},
  521. {AUD_POLY0_DDS_CONSTANT, 0x000E4DB2},
  522. {AUD_DCOC_0_SRC, 0x00000021},
  523. {AUD_IIR1_0_SEL, 0x00000000},
  524. {AUD_IIR1_0_SHIFT, 0x00000007},
  525. {AUD_IIR1_1_SEL, 0x00000002},
  526. {AUD_IIR1_1_SHIFT, 0x00000000},
  527. {AUD_DCOC_1_SRC, 0x00000003},
  528. {AUD_DCOC1_SHIFT, 0x00000000},
  529. {AUD_DCOC_PASS_IN, 0x00000000},
  530. {AUD_IIR1_2_SEL, 0x00000023},
  531. {AUD_IIR1_2_SHIFT, 0x00000000},
  532. {AUD_IIR1_3_SEL, 0x00000004},
  533. {AUD_IIR1_3_SHIFT, 0x00000007},
  534. {AUD_IIR1_4_SEL, 0x00000005},
  535. {AUD_IIR1_4_SHIFT, 0x00000007},
  536. {AUD_IIR3_0_SEL, 0x00000007},
  537. {AUD_IIR3_0_SHIFT, 0x00000000},
  538. {AUD_DEEMPH0_SRC_SEL, 0x00000011},
  539. {AUD_DEEMPH0_SHIFT, 0x00000000},
  540. {AUD_DEEMPH0_G0, 0x00007000},
  541. {AUD_DEEMPH0_A0, 0x00000000},
  542. {AUD_DEEMPH0_B0, 0x00000000},
  543. {AUD_DEEMPH0_A1, 0x00000000},
  544. {AUD_DEEMPH0_B1, 0x00000000},
  545. {AUD_DEEMPH1_SRC_SEL, 0x00000011},
  546. {AUD_DEEMPH1_SHIFT, 0x00000000},
  547. {AUD_DEEMPH1_G0, 0x00007000},
  548. {AUD_DEEMPH1_A0, 0x00000000},
  549. {AUD_DEEMPH1_B0, 0x00000000},
  550. {AUD_DEEMPH1_A1, 0x00000000},
  551. {AUD_DEEMPH1_B1, 0x00000000},
  552. {AUD_OUT0_SEL, 0x0000003F},
  553. {AUD_OUT1_SEL, 0x0000003F},
  554. {AUD_DMD_RA_DDS, 0x00F5C285},
  555. {AUD_PLL_INT, 0x0000001E},
  556. {AUD_PLL_DDS, 0x00000000},
  557. {AUD_PLL_FRAC, 0x0000E542},
  558. {AUD_RATE_ADJ1, 0x00000100},
  559. {AUD_RATE_ADJ2, 0x00000200},
  560. {AUD_RATE_ADJ3, 0x00000300},
  561. {AUD_RATE_ADJ4, 0x00000400},
  562. {AUD_RATE_ADJ5, 0x00000500},
  563. {AUD_RATE_THRES_DMD, 0x000000C0},
  564. { /* end of list */ },
  565. };
  566. static const struct rlist a2_deemph50[] = {
  567. {AUD_DEEMPH0_G0, 0x00000380},
  568. {AUD_DEEMPH1_G0, 0x00000380},
  569. {AUD_DEEMPHGAIN_R, 0x000011e1},
  570. {AUD_DEEMPHNUMER1_R, 0x0002a7bc},
  571. {AUD_DEEMPHNUMER2_R, 0x0003023c},
  572. { /* end of list */ },
  573. };
  574. set_audio_start(core, SEL_A2);
  575. switch (core->tvaudio) {
  576. case WW_BG:
  577. dprintk("%s PAL-BG A1/2 (status: known-good)\n", __func__);
  578. set_audio_registers(core, a2_bgdk_common);
  579. set_audio_registers(core, a2_bg);
  580. set_audio_registers(core, a2_deemph50);
  581. break;
  582. case WW_DK:
  583. dprintk("%s PAL-DK A1/2 (status: known-good)\n", __func__);
  584. set_audio_registers(core, a2_bgdk_common);
  585. set_audio_registers(core, a2_dk);
  586. set_audio_registers(core, a2_deemph50);
  587. break;
  588. case WW_I:
  589. dprintk("%s PAL-I A1 (status: known-good)\n", __func__);
  590. set_audio_registers(core, a1_i);
  591. set_audio_registers(core, a2_deemph50);
  592. break;
  593. case WW_L:
  594. dprintk("%s AM-L (status: devel)\n", __func__);
  595. set_audio_registers(core, am_l);
  596. break;
  597. case WW_NONE:
  598. case WW_BTSC:
  599. case WW_EIAJ:
  600. case WW_I2SPT:
  601. case WW_FM:
  602. case WW_I2SADC:
  603. case WW_M:
  604. dprintk("%s Warning: wrong value\n", __func__);
  605. return;
  606. }
  607. mode |= EN_FMRADIO_EN_RDS | EN_DMTRX_SUMDIFF;
  608. set_audio_finish(core, mode);
  609. }
  610. static void set_audio_standard_EIAJ(struct cx88_core *core)
  611. {
  612. static const struct rlist eiaj[] = {
  613. /* TODO: eiaj register settings are not there yet ... */
  614. { /* end of list */ },
  615. };
  616. dprintk("%s (status: unknown)\n", __func__);
  617. set_audio_start(core, SEL_EIAJ);
  618. set_audio_registers(core, eiaj);
  619. set_audio_finish(core, EN_EIAJ_AUTO_STEREO);
  620. }
  621. static void set_audio_standard_FM(struct cx88_core *core,
  622. enum cx88_deemph_type deemph)
  623. {
  624. static const struct rlist fm_deemph_50[] = {
  625. {AUD_DEEMPH0_G0, 0x0C45},
  626. {AUD_DEEMPH0_A0, 0x6262},
  627. {AUD_DEEMPH0_B0, 0x1C29},
  628. {AUD_DEEMPH0_A1, 0x3FC66},
  629. {AUD_DEEMPH0_B1, 0x399A},
  630. {AUD_DEEMPH1_G0, 0x0D80},
  631. {AUD_DEEMPH1_A0, 0x6262},
  632. {AUD_DEEMPH1_B0, 0x1C29},
  633. {AUD_DEEMPH1_A1, 0x3FC66},
  634. {AUD_DEEMPH1_B1, 0x399A},
  635. {AUD_POLYPH80SCALEFAC, 0x0003},
  636. { /* end of list */ },
  637. };
  638. static const struct rlist fm_deemph_75[] = {
  639. {AUD_DEEMPH0_G0, 0x091B},
  640. {AUD_DEEMPH0_A0, 0x6B68},
  641. {AUD_DEEMPH0_B0, 0x11EC},
  642. {AUD_DEEMPH0_A1, 0x3FC66},
  643. {AUD_DEEMPH0_B1, 0x399A},
  644. {AUD_DEEMPH1_G0, 0x0AA0},
  645. {AUD_DEEMPH1_A0, 0x6B68},
  646. {AUD_DEEMPH1_B0, 0x11EC},
  647. {AUD_DEEMPH1_A1, 0x3FC66},
  648. {AUD_DEEMPH1_B1, 0x399A},
  649. {AUD_POLYPH80SCALEFAC, 0x0003},
  650. { /* end of list */ },
  651. };
  652. /*
  653. * It is enough to leave default values?
  654. *
  655. * No, it's not! The deemphasis registers are reset to the 75us
  656. * values by default. Analyzing the spectrum of the decoded audio
  657. * reveals that "no deemphasis" is the same as 75 us, while the 50 us
  658. * setting results in less deemphasis.
  659. */
  660. static const struct rlist fm_no_deemph[] = {
  661. {AUD_POLYPH80SCALEFAC, 0x0003},
  662. { /* end of list */ },
  663. };
  664. dprintk("%s (status: unknown)\n", __func__);
  665. set_audio_start(core, SEL_FMRADIO);
  666. switch (deemph) {
  667. default:
  668. case FM_NO_DEEMPH:
  669. set_audio_registers(core, fm_no_deemph);
  670. break;
  671. case FM_DEEMPH_50:
  672. set_audio_registers(core, fm_deemph_50);
  673. break;
  674. case FM_DEEMPH_75:
  675. set_audio_registers(core, fm_deemph_75);
  676. break;
  677. }
  678. set_audio_finish(core, EN_FMRADIO_AUTO_STEREO);
  679. }
  680. /* ----------------------------------------------------------- */
  681. static int cx88_detect_nicam(struct cx88_core *core)
  682. {
  683. int i, j = 0;
  684. dprintk("start nicam autodetect.\n");
  685. for (i = 0; i < 6; i++) {
  686. /* if bit1=1 then nicam is detected */
  687. j += ((cx_read(AUD_NICAM_STATUS2) & 0x02) >> 1);
  688. if (j == 1) {
  689. dprintk("nicam is detected.\n");
  690. return 1;
  691. }
  692. /* wait a little bit for next reading status */
  693. usleep_range(10000, 20000);
  694. }
  695. dprintk("nicam is not detected.\n");
  696. return 0;
  697. }
  698. void cx88_set_tvaudio(struct cx88_core *core)
  699. {
  700. switch (core->tvaudio) {
  701. case WW_BTSC:
  702. set_audio_standard_BTSC(core, 0, EN_BTSC_AUTO_STEREO);
  703. break;
  704. case WW_BG:
  705. case WW_DK:
  706. case WW_M:
  707. case WW_I:
  708. case WW_L:
  709. /* prepare all dsp registers */
  710. set_audio_standard_A2(core, EN_A2_FORCE_MONO1);
  711. /*
  712. * set nicam mode - otherwise
  713. * AUD_NICAM_STATUS2 contains wrong values
  714. */
  715. set_audio_standard_NICAM(core, EN_NICAM_AUTO_STEREO);
  716. if (cx88_detect_nicam(core) == 0) {
  717. /* fall back to fm / am mono */
  718. set_audio_standard_A2(core, EN_A2_FORCE_MONO1);
  719. core->audiomode_current = V4L2_TUNER_MODE_MONO;
  720. core->use_nicam = 0;
  721. } else {
  722. core->use_nicam = 1;
  723. }
  724. break;
  725. case WW_EIAJ:
  726. set_audio_standard_EIAJ(core);
  727. break;
  728. case WW_FM:
  729. set_audio_standard_FM(core, radio_deemphasis);
  730. break;
  731. case WW_I2SADC:
  732. set_audio_start(core, 0x01);
  733. /*
  734. * Slave/Philips/Autobaud
  735. * NB on Nova-S bit1 NPhilipsSony appears to be inverted:
  736. * 0= Sony, 1=Philips
  737. */
  738. cx_write(AUD_I2SINPUTCNTL, core->board.i2sinputcntl);
  739. /* Switch to "I2S ADC mode" */
  740. cx_write(AUD_I2SCNTL, 0x1);
  741. set_audio_finish(core, EN_I2SIN_ENABLE);
  742. break;
  743. case WW_NONE:
  744. case WW_I2SPT:
  745. pr_info("unknown tv audio mode [%d]\n", core->tvaudio);
  746. break;
  747. }
  748. }
  749. EXPORT_SYMBOL(cx88_set_tvaudio);
  750. void cx88_newstation(struct cx88_core *core)
  751. {
  752. core->audiomode_manual = UNSET;
  753. core->last_change = jiffies;
  754. }
  755. EXPORT_SYMBOL(cx88_newstation);
  756. void cx88_get_stereo(struct cx88_core *core, struct v4l2_tuner *t)
  757. {
  758. static const char * const m[] = { "stereo", "dual mono",
  759. "mono", "sap" };
  760. static const char * const p[] = { "no pilot", "pilot c1",
  761. "pilot c2", "?" };
  762. u32 reg, mode, pilot;
  763. reg = cx_read(AUD_STATUS);
  764. mode = reg & 0x03;
  765. pilot = (reg >> 2) & 0x03;
  766. if (core->astat != reg)
  767. dprintk("AUD_STATUS: 0x%x [%s/%s] ctl=%s\n",
  768. reg, m[mode], p[pilot],
  769. aud_ctl_names[cx_read(AUD_CTL) & 63]);
  770. core->astat = reg;
  771. t->capability = V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_SAP |
  772. V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2;
  773. t->rxsubchans = UNSET;
  774. t->audmode = V4L2_TUNER_MODE_MONO;
  775. switch (mode) {
  776. case 0:
  777. t->audmode = V4L2_TUNER_MODE_STEREO;
  778. break;
  779. case 1:
  780. t->audmode = V4L2_TUNER_MODE_LANG2;
  781. break;
  782. case 2:
  783. t->audmode = V4L2_TUNER_MODE_MONO;
  784. break;
  785. case 3:
  786. t->audmode = V4L2_TUNER_MODE_SAP;
  787. break;
  788. }
  789. switch (core->tvaudio) {
  790. case WW_BTSC:
  791. case WW_BG:
  792. case WW_DK:
  793. case WW_M:
  794. case WW_EIAJ:
  795. if (!core->use_nicam) {
  796. t->rxsubchans = cx88_dsp_detect_stereo_sap(core);
  797. break;
  798. }
  799. break;
  800. case WW_NONE:
  801. case WW_I:
  802. case WW_L:
  803. case WW_I2SPT:
  804. case WW_FM:
  805. case WW_I2SADC:
  806. /* nothing */
  807. break;
  808. }
  809. /* If software stereo detection is not supported... */
  810. if (t->rxsubchans == UNSET) {
  811. t->rxsubchans = V4L2_TUNER_SUB_MONO;
  812. /*
  813. * If the hardware itself detected stereo, also return
  814. * stereo as an available subchannel
  815. */
  816. if (t->audmode == V4L2_TUNER_MODE_STEREO)
  817. t->rxsubchans |= V4L2_TUNER_SUB_STEREO;
  818. }
  819. }
  820. EXPORT_SYMBOL(cx88_get_stereo);
  821. void cx88_set_stereo(struct cx88_core *core, u32 mode, int manual)
  822. {
  823. u32 ctl = UNSET;
  824. u32 mask = UNSET;
  825. if (manual) {
  826. core->audiomode_manual = mode;
  827. } else {
  828. if (core->audiomode_manual != UNSET)
  829. return;
  830. }
  831. core->audiomode_current = mode;
  832. switch (core->tvaudio) {
  833. case WW_BTSC:
  834. switch (mode) {
  835. case V4L2_TUNER_MODE_MONO:
  836. set_audio_standard_BTSC(core, 0, EN_BTSC_FORCE_MONO);
  837. break;
  838. case V4L2_TUNER_MODE_LANG1:
  839. set_audio_standard_BTSC(core, 0, EN_BTSC_AUTO_STEREO);
  840. break;
  841. case V4L2_TUNER_MODE_LANG2:
  842. set_audio_standard_BTSC(core, 1, EN_BTSC_FORCE_SAP);
  843. break;
  844. case V4L2_TUNER_MODE_STEREO:
  845. case V4L2_TUNER_MODE_LANG1_LANG2:
  846. set_audio_standard_BTSC(core, 0, EN_BTSC_FORCE_STEREO);
  847. break;
  848. }
  849. break;
  850. case WW_BG:
  851. case WW_DK:
  852. case WW_M:
  853. case WW_I:
  854. case WW_L:
  855. if (core->use_nicam == 1) {
  856. switch (mode) {
  857. case V4L2_TUNER_MODE_MONO:
  858. case V4L2_TUNER_MODE_LANG1:
  859. set_audio_standard_NICAM(core,
  860. EN_NICAM_FORCE_MONO1);
  861. break;
  862. case V4L2_TUNER_MODE_LANG2:
  863. set_audio_standard_NICAM(core,
  864. EN_NICAM_FORCE_MONO2);
  865. break;
  866. case V4L2_TUNER_MODE_STEREO:
  867. case V4L2_TUNER_MODE_LANG1_LANG2:
  868. set_audio_standard_NICAM(core,
  869. EN_NICAM_FORCE_STEREO);
  870. break;
  871. }
  872. } else {
  873. if ((core->tvaudio == WW_I) ||
  874. (core->tvaudio == WW_L)) {
  875. /* fall back to fm / am mono */
  876. set_audio_standard_A2(core, EN_A2_FORCE_MONO1);
  877. } else {
  878. /* TODO: Add A2 autodection */
  879. mask = 0x3f;
  880. switch (mode) {
  881. case V4L2_TUNER_MODE_MONO:
  882. case V4L2_TUNER_MODE_LANG1:
  883. ctl = EN_A2_FORCE_MONO1;
  884. break;
  885. case V4L2_TUNER_MODE_LANG2:
  886. ctl = EN_A2_FORCE_MONO2;
  887. break;
  888. case V4L2_TUNER_MODE_STEREO:
  889. case V4L2_TUNER_MODE_LANG1_LANG2:
  890. ctl = EN_A2_FORCE_STEREO;
  891. break;
  892. }
  893. }
  894. }
  895. break;
  896. case WW_FM:
  897. switch (mode) {
  898. case V4L2_TUNER_MODE_MONO:
  899. ctl = EN_FMRADIO_FORCE_MONO;
  900. mask = 0x3f;
  901. break;
  902. case V4L2_TUNER_MODE_STEREO:
  903. ctl = EN_FMRADIO_AUTO_STEREO;
  904. mask = 0x3f;
  905. break;
  906. }
  907. break;
  908. case WW_I2SADC:
  909. case WW_NONE:
  910. case WW_EIAJ:
  911. case WW_I2SPT:
  912. /* DO NOTHING */
  913. break;
  914. }
  915. if (ctl != UNSET) {
  916. dprintk("cx88_set_stereo: mask 0x%x, ctl 0x%x [status=0x%x,ctl=0x%x,vol=0x%x]\n",
  917. mask, ctl, cx_read(AUD_STATUS),
  918. cx_read(AUD_CTL), cx_sread(SHADOW_AUD_VOL_CTL));
  919. cx_andor(AUD_CTL, mask, ctl);
  920. }
  921. }
  922. EXPORT_SYMBOL(cx88_set_stereo);
  923. int cx88_audio_thread(void *data)
  924. {
  925. struct cx88_core *core = data;
  926. struct v4l2_tuner t;
  927. u32 mode = 0;
  928. dprintk("cx88: tvaudio thread started\n");
  929. set_freezable();
  930. for (;;) {
  931. msleep_interruptible(1000);
  932. if (kthread_should_stop())
  933. break;
  934. try_to_freeze();
  935. switch (core->tvaudio) {
  936. case WW_BG:
  937. case WW_DK:
  938. case WW_M:
  939. case WW_I:
  940. case WW_L:
  941. if (core->use_nicam)
  942. goto hw_autodetect;
  943. /* just monitor the audio status for now ... */
  944. memset(&t, 0, sizeof(t));
  945. cx88_get_stereo(core, &t);
  946. if (core->audiomode_manual != UNSET)
  947. /* manually set, don't do anything. */
  948. continue;
  949. /* monitor signal and set stereo if available */
  950. if (t.rxsubchans & V4L2_TUNER_SUB_STEREO)
  951. mode = V4L2_TUNER_MODE_STEREO;
  952. else
  953. mode = V4L2_TUNER_MODE_MONO;
  954. if (mode == core->audiomode_current)
  955. continue;
  956. /* automatically switch to best available mode */
  957. cx88_set_stereo(core, mode, 0);
  958. break;
  959. case WW_NONE:
  960. case WW_BTSC:
  961. case WW_EIAJ:
  962. case WW_I2SPT:
  963. case WW_FM:
  964. case WW_I2SADC:
  965. hw_autodetect:
  966. /*
  967. * stereo autodetection is supported by hardware so
  968. * we don't need to do it manually. Do nothing.
  969. */
  970. break;
  971. }
  972. }
  973. dprintk("cx88: tvaudio thread exiting\n");
  974. return 0;
  975. }
  976. EXPORT_SYMBOL(cx88_audio_thread);